User File #37629523200973779

Upload All User Files

#37629523200973779 - Crash Bandicoot Huge Adventure - Speed HUD Spiked.

CrashGBA -Speed HUD (Spiked).lua
998 downloads
Uploaded 3/13/2017 3:19 PM by Spikestuff (see all 287)
--speed hud values v1.1.2 by ThunderAxe31 for GBA Crash Bandicoot - The Huge Adventure (Spiked)

memory.usememorydomain("IWRAM")
local area = memory.readbyte(0x1644)

x_max = 1224
x_middle = 496
y_max = 1536
y_middle = 0

framecount = 0
player_x = 0
player_x_old = 0
speed_x = 0
player_y = 0
player_y_old = 0
speed_y = 0
x = {}
y = {}


if area == 0 or area == 1 or area == 2 or area == 3 or area == 4 or area == 7 then
player_x_addr = 0x010A14
player_y_addr = 0x010A18
else if area == 6 then
player_x_addr = 0x010E2C
player_y_addr = 0x010E30
end end

function round(x)
  if x%2 ~= 0.5 then
    return math.floor(x+0.5)
  end
  return x-0.5
end

function decide_color(speed, middle, maxi)
	if speed == nil then 
		return
	end
	
	speed = math.abs(speed)
	maxi = math.abs(maxi)
	
	if speed > maxi then
		color = 0x000000FF
	elseif speed < middle then --if 0: red; if middle: white
		local value = math.floor(0xFF*(speed/middle))
		color = 0xFF0000 + value*0x101
	else --if middle: white; if maxi: green
		local value = math.floor(0xFF*(1-(speed-middle)/(maxi-middle)))
		color = 0x00FF00 + value*0x10001
	end
	return color+0xFF000000
end

if memory.usememorydomain("EWRAM") then
	
	player_x = memory.read_u32_le(player_x_addr)
	player_y = memory.read_u32_le(player_y_addr)
	console.log("Starting script at frame: " .. emu.framecount() .. " with X: " .. player_x .. ", Y: " .. player_y)
	emu.frameadvance()
	
	while true do
		if framecount > emu.framecount() then
			x = {}
			y = {}
		end
		
		player_x_old = player_x
		player_x = memory.read_u32_le(player_x_addr)
		player_y_old = player_y
		player_y = memory.read_u32_le(player_y_addr)
		
		speed_x = player_x -player_x_old
		speed_y = player_y -player_y_old
		
		for i=25, 1, -1 do
			x[i]=x[i-1]
			y[i]=y[i-1]
			gui.pixelText(0, 0+i*6, x[i], decide_color(x[i], x_middle, x_max))
			gui.pixelText(219, 0+i*6, y[i], decide_color(y[i], y_middle, y_max))
		end
		
		x[0] = speed_x
		y[0] = speed_y
		
		gui.pixelText(0, 0, x[0], decide_color(x[0], x_middle, x_max))
		gui.pixelText(219, 0, y[0], decide_color(y[0], y_middle, y_max))
		
		framecount = emu.framecount()
		
		emu.frameadvance()
	end
else
	console.log("Error: failed to set EWRAM memory domain")
end