User File #7037646033359209

Upload All User Files

#7037646033359209 - Wolfenstein 3D Lua script

Wolf3d-script.lua
Game: Wolfenstein 3D ( DOS, see all files )
893 downloads
Uploaded 6/4/2013 10:10 PM by Ilari (see all 49)
Lua script that shows some basic info in Wolf3D and bridges Gamepad plugin and emulator core.
Very prelimiary.
dofile("textrender.lua");

mouse_vx = 0;
mouse_vy = 0;
mouse_deadzone = 8192
mouse_ysensitivity = 70;
mouse_xsensitivity = 70;
last_x = 0;
last_y = 0;
last_d = 0;
last_f = 0;
dx = 0;
dy = 0;
dd = 0;

while true do
	a, b = jpcrr.wait_event();
	if a == "lock" then
		jpcrr.hud.top_gap(3, 16);
		x = jpcrr.read_dword(0x004882E);
		y = jpcrr.read_dword(0x0048832);
		d = jpcrr.read_word(0x00048848);
		f = jpcrr.frame_number();
		spd = math.sqrt(dx * dx + dy * dy)
		render_text(3, 0, 0, string.format("(%7d,%7d) %3d [%+5d,%+5d](%f) %+3d", x, y, d, dx, dy, spd, dd),
			false, 0, 255, 0);
		if f ~= last_f then
			dx = x - last_x;
			dy = y - last_y;
			dd = d - last_d;
			last_x = x;
			last_y = y;
			last_d = d;
			last_f = f;
		end
		jpcrr.release_vga();
	end
	if a == "message" then
		c,d,e = string.match(b, "(.*) (.*) (.*)");
		if e and c == "BUTTON" then
			if d == "304" and e == "1" then
				jpcrr.pc_start();
			end
			if d == "304" and e == "0" then
				jpcrr.pc_stop();
			end
			if d == "305" then
				jpcrr.sendevent("org.jpc.emulator.peripheral.Keyboard", "KEYEDGE", "157");
			end
			if d == "307" then
				jpcrr.sendevent("org.jpc.emulator.peripheral.Keyboard", "KEYEDGE", "57");
			end
			if d == "308" then
				jpcrr.sendevent("org.jpc.emulator.peripheral.Keyboard", "KEYEDGE", "184");
			end
		end
		if e and c == "AXIS" then
			mouse_update = false;
			if d == "0" then
				v = tonumber(e);
				if v <= -mouse_deadzone then
					v = (v + mouse_deadzone) / (32768 - mouse_deadzone) * mouse_xsensitivity;
				elseif v >= mouse_deadzone then
					v = (v - mouse_deadzone) / (32768 - mouse_deadzone) * mouse_xsensitivity;
				else
					v = 0;
				end
				mouse_vx = v;
				mouse_update = true;
			end
			if d == "1" then
				v = tonumber(e);
				if v <= -mouse_deadzone then
					v = (v + mouse_deadzone) / (32768 - mouse_deadzone) * mouse_ysensitivity;
				elseif v >= mouse_deadzone then
					v = (v - mouse_deadzone) / (32768 - mouse_deadzone) * mouse_ysensitivity;
				else
					v = 0;
				end
				mouse_vy = -v;	--y axis is reversed.
				mouse_update = true;
			end
			if mouse_update then
				--print("Mouse: X=" .. mouse_vx .. " Y=" .. mouse_vy);
				jpcrr.hold_mouse_motion(mouse_vx, mouse_vy);
			end
		end
		--print(b);
	end
end




-- 0x4882E  U position (dword)
-- 0x48832  V position (dword)
-- 0x48848  Direction (word)