User File #49530161300647551

Upload All User Files

#49530161300647551 - Kuru Kuru Kururin - speed hud v1.2

Kuru Kuru Kururin - speed hud v1.2.lua
797 downloads
Uploaded 8/31/2018 2:06 PM by ThunderAxe31 (see all 109)
Script that displays the following values on screen:
  • X and Y player position
  • X, Y, XY total speed, of which:
    • X, Y, XY movements speed
    • X, Y, XY pushback speed
It does also display an arrow that indicates in which direction the player is heading.
--Kuru Kuru Kururin - hud speed script v1.2 by ThunderAxe31

local speed_low = 0 --when standing still
local speed_mid = 3 --running speed (A+B buttons keept)
local speed_max = 7 --highest speed during horizontal and vertical clips, however diagonal clips can be faster

local pos_x_addr = 0x004544
local pos_y_addr = 0x004548
local push_speed_x_addr = 0x00454C
local push_speed_y_addr = 0x004550

local pos_x_old = 0
local pos_y_old = 0

local framecount = -1

function decide_color(speed)
	if speed == nil then 
		return
	end
	
	speed = math.abs(speed)
	
	if speed > speed_max then --in case we broke the limit, use blue color
		color = 0x000000FF
	elseif speed < speed_mid then --if 0: red; if middle: white
		local value = math.floor(0xFF*(speed/speed_mid))
		color = 0xFF0000 + value*0x101
	else --if speed_mid: white; if speed_max: green
		local value = math.floor(0xFF*(1-(speed-speed_mid)/(speed_max-speed_mid)))
		color = 0x00FF00 + value*0x10001
	end
	return color+0xFF000000
end

if memory.usememorydomain("IWRAM") then
	while true do
		local pos_x = memory.read_s32_le(pos_x_addr)/65536
		local pos_y = memory.read_s32_le(pos_y_addr)/65536
		
		local speed_x  = pos_x - pos_x_old
		local speed_y  = pos_y - pos_y_old
		local speed_xy = math.sqrt( math.pow(speed_x, 2) + math.pow(speed_y, 2) )
		
		local push_speed_x = memory.read_s32_le(push_speed_x_addr)/65536
		local push_speed_y = memory.read_s32_le(push_speed_y_addr)/65536
		local push_speed_xy = math.sqrt( math.pow(push_speed_x, 2) + math.pow(push_speed_y, 2) )
		
		local move_speed_x  = speed_x  - push_speed_x
		local move_speed_y  = speed_y  - push_speed_y
		local move_speed_xy = speed_xy - push_speed_xy
		
		if speed_x > 0 then speed_x = "+" .. speed_x end
		if speed_y > 0 then speed_y = "+" .. speed_y end
		
		if framecount ~= emu.framecount()-1 then
			speed_x = 0
			speed_y = 0
		end
		
		pos_x_old = pos_x
		pos_y_old = pos_y
		
		gui.pixelText(0, 132, "  Position  Speed =  Move +Push\nX  " .. string.format("%7.2f", pos_x) .. string.format("%+7.2f", speed_x) .. " =" .. string.format("%+6.2f", move_speed_x) .. string.format("%+6.2f", push_speed_x) .. "\nY  " .. string.format("%7.2f", pos_y) .. string.format("%+7.2f", speed_y) .. " =" .. string.format("%+6.2f", move_speed_y) .. string.format("%+6.2f", push_speed_y) .. "\nXY        " .. string.format("%+7.2f", speed_xy) .. " =" .. string.format("%+6.2f", move_speed_xy) .. string.format("%+6.2f", push_speed_xy))
		
		local arrow_color = decide_color(speed_xy)
		
		gui.drawLine(119, 79, 119+speed_x*10, 79+speed_y*10, arrow_color)
		gui.drawLine(120, 80, 120+speed_x*10, 80+speed_y*10, arrow_color)
		gui.drawLine(119, 80, 119+speed_x*10, 80+speed_y*10, arrow_color)
		gui.drawLine(120, 79, 120+speed_x*10, 79+speed_y*10, arrow_color)
		
		framecount = emu.framecount()
		
		emu.frameadvance()
	end
end