User File #66500734480859310

Upload All User Files

#66500734480859310 - Bugz Player Position Script

Bugz Position Script.lua
Game: Bugz ( Uzebox, see all files )
335 downloads
Uploaded 10/3/2020 8:42 PM by Invariel (see all 16)
Game: Bugz - Uzebox
Draws the player's positions for the previous and next X frames, and displays useful position information at the top of the screen.
Change line 21 to alter the text colour.
Change line 22 to alter Player 1's line colour.
Change line 23 to alter Player 2's line colour.
Change line 25 to adjust how many look behind / look ahead frames to draw player positions for.
(Fixes an issue with the previous script where I had mostly removed a piece of information that was unnecessary.)
MemP1X = 0x0F85 
MemP1Y = 0x0F87 
MemP1dX = 0x0F89
MemP1dY = 0x0F8B
MemP1XScreen = 0x388
MemP1YScreen = 0x389

MemP2X = 0x0FA4
MemP2Y = 0x0FA6 
MemP2dX = 0x0FA8
MemP2dY = 0x0FAA
MemP2XScreen = 0x38C
MemP2YScreen = 0x38D

MemCookieCount = 0x0FDA -- I still find it funny that the cookie value goes into FDA.
MemLevel = 0x0FEE

XWidth = 32
YHeight = 32

defaultTextColour = "white"
P1LineColor = "white"
P2LineColor = "blue"

FrameRadius = 25 -- Draw the path for this number of frames into the past and future.

P1Moves = { }
P2Moves = { }

-- Array indices.
x = 0	-- Actual X position
y = 1	-- Actual Y position
dx = 2	-- X speed
dy = 3	-- Y speed
sx = 4	-- Screen X position
sy = 5	-- Screen Y position


function printText (text, fore)
	fore = fore or defaultTextColour
	gui.text (10, line * 12 + 30, text, fore)
	line = line + 1
end

while true do
	line = 0

	P1X = mainmemory.read_u16_le (MemP1X)
	P1Y = mainmemory.read_u16_le (MemP1Y)
	P1XVel = mainmemory.read_s16_le (MemP1dX)
	P1YVel = mainmemory.read_s16_le (MemP1dY)
	P1XScreen = mainmemory.readbyte (MemP1XScreen)
	P1YScreen = mainmemory.readbyte (MemP1YScreen)

	P2X = mainmemory.read_u16_le (MemP2X)
	P2Y = mainmemory.read_u16_le (MemP2Y)
	P2XVel = mainmemory.read_s16_le (MemP2dX)
	P2YVel = mainmemory.read_s16_le (MemP2dY)
	P2XScreen = mainmemory.readbyte (MemP2XScreen)
	P2YScreen = mainmemory.readbyte (MemP2YScreen)

	CookieCount = mainmemory.readbyte (MemCookieCount)
	Level = mainmemory.readbyte (MemLevel)

	currentFrame = emu.framecount()

	if (currentFrame > 0) then
		P1Moves[currentFrame] = { }
		P1Moves[currentFrame][x] = P1X
		P1Moves[currentFrame][y] = P1Y
		P1Moves[currentFrame][dx] = P1XVel
		P1Moves[currentFrame][dy] = P1YVel
		P1Moves[currentFrame][sx] = P1XScreen * 3
		P1Moves[currentFrame][sy] = P1YScreen

		P2Moves[currentFrame] = { }
		P2Moves[currentFrame][x] = P2X
		P2Moves[currentFrame][y] = P2Y
		P2Moves[currentFrame][dx] = P2XVel
		P2Moves[currentFrame][dy] = P2YVel
		P2Moves[currentFrame][sx] = P2XScreen * 3
		P2Moves[currentFrame][sy] = P2YScreen

		for i = currentFrame - FrameRadius, currentFrame + FrameRadius, 1 do
			if i > 0 and P1Moves[i] ~= nil then
				if P1Moves[i - 1] ~= nil then
					gui.drawLine (P1Moves[i - 1][sx], P1Moves[i - 1][sy], P1Moves[i][sx], P1Moves[i][sy], P1LineColor)
					gui.drawLine (P2Moves[i - 1][sx], P2Moves[i - 1][sy], P2Moves[i][sx], P2Moves[i][sy], P2LineColor)
				else
					gui.drawPixel (P1Moves[i][sx], P1Moves[i][sy], P1LineColor)
					gui.drawPixel (P2Moves[i][sx], P2Moves[i][sy], P2LineColor)
				end
			end
		end

		printText (string.format ("P1: Pos: (%3d, %3d) Sub: [%2d, %2d] Vel: (%4d, %4d)%20sP2: Pos: (%3d, %3d) Sub: [%2d, %2d] Vel: (%4d, %4d)",
								  P1X, P1Y, P1X % XWidth, P1Y % YHeight, P1XVel, P1YVel, "",
								  P2X, P2Y, P2X % XWidth, P2Y % YHeight, P2XVel, P2YVel))

		printText (string.format ("    Scr: (%3d, %3d)%56sScr: (%3d, %3d)",
								  P1XScreen, P1YScreen, "",
								  P2XScreen, P2YScreen))

		Cookies = ""
		Remain = ""
		if CookieCount == 1 then
			Cookies = ""
			Remain = "s"
		else
			Cookies = "s"
			Remain = ""
		end

		printText (string.format ("Level %d, %d cookie%s remain%s.",
								  Level,
								  CookieCount, Cookies, Remain))
	end

	emu.frameadvance()
end