User File #66498135760650053

Upload All User Files

#66498135760650053 - Bugz Enemy Position Script

Bugz Enemy Position Script.lua
Game: Bugz ( Uzebox, see all files )
268 downloads
Uploaded 10/3/2020 5:53 PM by Invariel (see all 16)
Game: Bugz - Uzebox
Draws path lines for the six bugz, as well as displaying their coordinates at the top of the screen.
Change line 26 to alter the path line colours for each of the bugz in order. Change line 28 to alter the information text colour. Change line 29 to adjust how many look behind / look ahead frames to draw positions for. Comment out lines 61 through 68 to remove the information text.
-- Array indices.
local x = 0		-- Actual X position
local y = 1		-- Actual Y position
local dx = 2	-- X speed
local dy = 3	-- Y speed
local sx = 4	-- Screen X position
local sy = 5	-- Screen Y position

MemBugz0X = 0x0EEF
MemBugz0Y = 0x0EF1
MemBugz0dX = 0x0EF3
MemBugz0dY = 0x0EF5
MemOffset = 0x19
NumBugz = 6

PosBugz = { }

-- Because Lua arrays are supposed to start at 1.
PosBugz[1] = { }
PosBugz[2] = { }
PosBugz[3] = { }
PosBugz[4] = { }
PosBugz[5] = { }
PosBugz[6] = { }

BugzColours = { "black", "green", "blue", "red", "yellow", "cyan" }

local defaultTextColour = "white"
local FrameRadius = 25

local line = 0

-- 66

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

local function coordinateToScreen (val)
	return bit.rshift(val + 1, 2)
end

while true do
	line = 0

	currentFrame = emu.framecount()

	if currentFrame > 0 then
		for bugz = 1, NumBugz, 1 do
			PosBugz[bugz][currentFrame] = { }

			PosBugz[bugz][currentFrame][x] = mainmemory.read_u16_le(MemBugz0X + MemOffset * (bugz - 1))
			PosBugz[bugz][currentFrame][y] = mainmemory.read_u16_le(MemBugz0Y + MemOffset * (bugz - 1))
			PosBugz[bugz][currentFrame][dx] = mainmemory.read_s16_le(MemBugz0dX + MemOffset * (bugz - 1))
			PosBugz[bugz][currentFrame][dy] = mainmemory.read_s16_le(MemBugz0dY + MemOffset * (bugz - 1))
			PosBugz[bugz][currentFrame][sx] = coordinateToScreen(PosBugz[bugz][currentFrame][x]) * 3
			PosBugz[bugz][currentFrame][sy] = coordinateToScreen(PosBugz[bugz][currentFrame][y])

			printText (string.format ("Bug %d: (%3d, %3d) Vel: (%4d, %4d) Scr: (%3d, %3d)",
									  bugz,
									  PosBugz[bugz][currentFrame][x],
									  PosBugz[bugz][currentFrame][y],
									  PosBugz[bugz][currentFrame][dx],
									  PosBugz[bugz][currentFrame][dy],
									  PosBugz[bugz][currentFrame][sx],
									  PosBugz[bugz][currentFrame][sy]))
		end

		for i = currentFrame - FrameRadius, currentFrame + FrameRadius, 1 do
			if i > 0 and PosBugz[1][i] ~= nil then
				if PosBugz[1][i - 1] ~= nil then
					for bugz = 1, NumBugz, 1 do
						gui.drawLine(PosBugz[bugz][i - 1][sx], PosBugz[bugz][i - 1][sy], PosBugz[bugz][i][sx], PosBugz[bugz][i][sy], BugzColours[bugz])
					end
				else
					for bugz = 1, NumBugz, 1 do
						gui.drawPixel(PosBugz[bugz][i][sx], PosBugz[bugz][i][sy], BugzColours[bugz])
					end
				end
			end
		end

		for bugz = 1, NumBugz, 1 do
			gui.drawPixel(PosBugz[bugz][currentFrame][sx], PosBugz[bugz][currentFrame][sy], "black")
		end
	end

	emu.frameadvance()
end