User File #22866809653246006

Upload All User Files

#22866809653246006 - NES R.C. Pro-Am (PRG1) - Lua HUD (v1)

RCproam_v1.lua
Game: R.C. Pro-Am ( NES, see all files )
747 downloads
Uploaded 5/18/2015 7:05 PM by FatRatKnight (see all 245)
Numbers.
... Okay, I'll give more than one word.
Left: Position
Middle: Facing and momentum
Right: Speed and maximum speed
Bottom-left: Checkpoint identifier
And the stuff on the upper-left part of the screen is CPU car speeds.
... I still can't bring myself to be chatty. I'm recovering slow, and it's hard to stretch my mind.
--*****************************************************************************
local Draw= {}
--*****************************************************************************
--Coordinates is the top-left pixel of the 3x5 digit.
--Used for drawing compact, colored numbers.

local Px,Li= gui.pixel, gui.line

Draw[0]= function(x,y,c) -- ###
    Li(x  ,y  ,x  ,y+4,c)-- # #
    Li(x+2,y  ,x+2,y+4,c)-- # #
    Px(x+1,y  ,c)        -- # #
    Px(x+1,y+4,c)        -- ###
end

Draw[1]= function(x,y,c) --  #
    Li(x  ,y+4,x+2,y+4,c)-- ##
    Li(x+1,y  ,x+1,y+3,c)--  #
    Px(x  ,y+1,c)        --  #
end                      -- ###

Draw[2]= function(x,y,c) -- ###
    Li(x  ,y  ,x+2,y  ,c)--   #
    Li(x  ,y+3,x+2,y+1,c)-- ###
    Li(x  ,y+4,x+2,y+4,c)-- #
    Px(x  ,y+2,c)        -- ###
    Px(x+2,y+2,c)
end

Draw[3]= function(x,y,c) -- ###
    Li(x  ,y  ,x+1,y  ,c)--   #
    Li(x  ,y+2,x+1,y+2,c)-- ###
    Li(x  ,y+4,x+1,y+4,c)--   #
    Li(x+2,y  ,x+2,y+4,c)-- ###
end

Draw[4]= function(x,y,c) -- # #
    Li(x  ,y  ,x  ,y+2,c)-- # #
    Li(x+2,y  ,x+2,y+4,c)-- ###
    Px(x+1,y+2,c)        --   #
end                      --   #

Draw[5]= function(x,y,c) -- ###
    Li(x  ,y  ,x+2,y  ,c)-- #
    Li(x  ,y+1,x+2,y+3,c)-- ###
    Li(x  ,y+4,x+2,y+4,c)--   #
    Px(x  ,y+2,c)        -- ###
    Px(x+2,y+2,c)
end

Draw[6]= function(x,y,c) -- ###
    Li(x  ,y  ,x+2,y  ,c)-- #
    Li(x  ,y+1,x  ,y+4,c)-- ###
    Li(x+2,y+2,x+2,y+4,c)-- # #
    Px(x+1,y+2,c)        -- ###
    Px(x+1,y+4,c)
end
                         -- ###
Draw[7]= function(x,y,c) --   #
    Li(x  ,y  ,x+1,y  ,c)--  ##
    Li(x+2,y  ,x+1,y+4,c)--  #
end                      --  #

Draw[8]= function(x,y,c) -- ###
    Li(x  ,y  ,x  ,y+4,c)-- # #
    Li(x+2,y  ,x+2,y+4,c)-- ###
    Px(x+1,y  ,c)        -- # #
    Px(x+1,y+2,c)        -- ###
    Px(x+1,y+4,c)
end

Draw[9]= function(x,y,c) -- ###
    Li(x  ,y  ,x  ,y+2,c)-- # #
    Li(x+2,y  ,x+2,y+3,c)-- ###
    Li(x  ,y+4,x+2,y+4,c)--   #
    Px(x+1,y  ,c)        -- ###
    Px(x+1,y+2,c)
end

Draw[10]=function(x,y,c) --  #
    Li(x  ,y+1,x  ,y+4,c)-- # #
    Li(x+2,y+1,x+2,y+4,c)-- # #
    Px(x+1,y  ,c)        -- ###
    Px(x+1,y+3,c)        -- # #
end

Draw[11]=function(x,y,c) -- ##
    Li(x  ,y  ,x  ,y+4,c)-- # #
    Li(x+1,y  ,x+2,y+1,c)-- ##
    Li(x+1,y+4,x+2,y+3,c)-- # #
    Px(x+1,y+2,c)        -- ##
end

Draw[12]=function(x,y,c) --  #
    Li(x  ,y+1,x  ,y+3,c)-- # #
    Li(x+1,y  ,x+2,y+1,c)-- #
    Li(x+1,y+4,x+2,y+3,c)-- # #
end                      --  #

Draw[13]=function(x,y,c) -- ##
    Li(x  ,y  ,x  ,y+4,c)-- # #
    Li(x+2,y+1,x+2,y+3,c)-- # #
    Px(x+1,y  ,c)        -- # #
    Px(x+1,y+4,c)        -- ##
end

Draw[14]=function(x,y,c) -- ###
    Li(x  ,y  ,x  ,y+4,c)-- #
    Li(x+1,y  ,x+2,y  ,c)-- ##
    Li(x+1,y+4,x+2,y+4,c)-- #
    Px(x+1,y+2,c)        -- ###
end

Draw[15]=function(x,y,c) -- ###
    Li(x  ,y  ,x  ,y+4,c)-- #
    Li(x+1,y  ,x+2,y  ,c)-- ##
    Px(x+1,y+2,c)        -- #
end                      -- #

--*****************************************************************************
local function __DN_AnyBase(right, y, Number, c, bkgnd, div)
--*****************************************************************************
-- Works with any base from 2 to 16. Paints the input number.
-- Returns the x position where it would paint another digit.
-- It only works with integers. Rounds fractions toward zero.

    if div < 2 then return end  -- Prevents the function from never returning.

    local Digit= {}
    local Negative= false
    if Number < 0 then
        Number= -Number
        Negative= true
    end

    Number= math.floor(Number)
    c= c or "white"
    bkgnd= bkgnd or "clear"

    local i= 0
    if Number < 1 then
        Digit[1]= 0
        i= 1
    end

    while (Number >= 1) do
        i= i+1
        Digit[i]= Number % div
        Number= math.floor(Number/div)
    end

    if Negative then  i= i+1  end
    local x= right - i*4
    gui.box(x+1, y-1, right+1, y+5,bkgnd,bkgnd)

    i= 1
    while Draw[Digit[i]] do
        Draw[Digit[i]](right-2,y,c)
        right= right-4
        i=i+1
    end

    if Negative then
        gui.line(right, y+2,right-2,y+2,c)
        right= right-4
    end
    return right
end
--*****************************************************************************
local function DrawNum(right, y, Number, c, bkgnd)
--*****************************************************************************
-- Paints the input number as right-aligned. Decimal version.
    return __DN_AnyBase(right, y, Number, c, bkgnd, 10)
end
--*****************************************************************************
local function DrawNumx(right, y, Number, c, bkgnd)
--*****************************************************************************
-- Paints the input number as right-aligned. Hexadecimal version.
    return __DN_AnyBase(right, y, Number, c, bkgnd, 16)
end

-------------------------------------------------------------------------------
local R1u= memory.readbyte
local R2u= memory.readword

local OldX,OldY= 0,0
--*****************************************************************************
local function d_pos()
--*****************************************************************************
--Bugged; I forget that gui.register is called repeatedly when paused.
--Meaning frame advance will always show 0, but playing shows other numbers.
    local X= R2u(0x049C,0x04EC)*16 + R1u(0x05BC)/16
    local Y= R2u(0x04C4,0x0514)*16 + R1u(0x05C4)/16
    DrawNum( 60,180,X-OldX,"orange","black")
    DrawNum( 60,186,Y-OldY,"orange","black")
    OldX,OldY=X,Y
end

--*****************************************************************************
local function BasicHUD()
--*****************************************************************************
--    d_pos()

    DrawNum(  80,180,R2u(0x049C,0x04EC),"white" ,"black") -- X pos
    DrawNumx( 88,180,R1u(0x05BC)       ,"grey"  ,"black") -- X sub pos
    DrawNum(  80,186,R2u(0x04C4,0x0514),"white" ,"black") -- Y pos
    DrawNumx( 88,186,R1u(0x05C4)       ,"grey"  ,"black") -- Y sub pos
    DrawNum(  88,224,R1u(0x053C)       ,"green" ,"black") -- Checkpoint
    DrawNum( 184,180,R1u(0x05DC)       ,"green" ,"black") -- Speed
    DrawNumx(192,180,R1u(0x05D8)       ,"grey"  ,"black") -- Speed, sub
    DrawNum( 184,186,R1u(0x0604)       ,"white" ,"black") -- Max speed

    local F,M= R1u(0x05CC),R1u(0x05E8)  --Facing & Momentum
    DrawNumx(110,180,(F-M)%256         ,"orange","black")
    DrawNumx(100,180,F                 ,"white" ,"black") -- Facing
    DrawNumx(120,180,M                 ,"green" ,"black") -- Momentum
    DrawNumx(128,180,R1u(0x05E4)       ,"grey"  ,"black") -- Momentum, sub
    DrawNum( 204,180,R1u(0x0459)       ,"orange","black") -- Ammo
    DrawNum( 160,180,R1u(0x05B8)       ,"white" ,"black") -- Invincibility

--Stuff about CPU cars. Just in case
    DrawNum(  12,  9,R1u(0x05DD)       ,"green" ,"black") -- Speed
    DrawNumx( 20,  9,R1u(0x05D9)       ,"grey"  ,"black") -- Speed, sub
    DrawNum(  12, 15,R1u(0x0605)       ,"green" ,"black") -- Max speed
    DrawNum(  12, 25,R1u(0x05DE)       ,"green" ,"black") -- Speed
    DrawNumx( 20, 25,R1u(0x05DA)       ,"grey"  ,"black") -- Speed, sub
    DrawNum(  12, 31,R1u(0x0606)       ,"orange","black") -- Max speed
    DrawNum(  12, 41,R1u(0x05DF)       ,"green" ,"black") -- Speed
    DrawNumx( 20, 41,R1u(0x05DB)       ,"grey"  ,"black") -- Speed, sub
    DrawNum(  12, 47,R1u(0x0607)       ,"cyan"  ,"black") -- Max speed

--[[  -- Just something to let me look at various addresses in a lua HUD.
    DrawNumx( 12,  8,R1u(0x002B),"green","black")
    DrawNumx( 12, 16,R1u(0x05B0),"green","black")
    DrawNumx( 12, 24,R1u(0x05B4),"green","black")
    DrawNumx( 12, 32,R1u(0x05B8),"green","black")
    DrawNumx( 12, 40,R1u(0x05BC),"green","black")
    DrawNumx( 12, 48,R1u(0x05C0),"green","black")
    DrawNumx( 12, 56,R1u(0x05C4),"green","black")
    DrawNumx( 12, 64,R1u(0x05C8),"green","black")
    DrawNumx( 12, 72,R1u(0x05CC),"green","black")
    DrawNumx( 12, 80,R1u(0x05D0),"green","black")
    DrawNumx( 12, 88,R1u(0x05D4),"green","black")
    DrawNumx( 12, 96,R1u(0x05D8),"green","black")
    DrawNumx( 12,104,R1u(0x05DC),"green","black")
]]--
end
gui.register(BasicHUD)