User File #40210557291686046

Upload All User Files

#40210557291686046 - Zook Man ZX4 - Casual display script (prototype)

ZMZX4_CasualDisplay.lua
781 downloads
Uploaded 7/7/2017 9:01 PM by FatRatKnight (see all 245)
I'm selecting out things that make sense to read in real-time. Fiddly numbers like when item drops happen is difficult to display appropriately in real-time.
Currently shows barrier, weapons, and size of current segment. I hope it's pretty.
--GBA Zook Man ZX4 - Casual Display script
--The display is intended to make sense for real-time viewing.
--For BizHawk
--FatRatKnight

local R4u,R4s= memory.read_u32_le,memory.read_s32_le
local R2u,R2s= memory.read_u16_le,memory.read_s16_le
local R1u,R1s= memory.read_u8    ,memory.read_s8

--Would stick function inside function. BizHawk seems to hate it.
local function BoxB(x,y,i,bc,fc) gui.drawRectangle(x-1+5*i,y+7,3,3,bc,fc) end
--*****************************************************************************
local function BarrierDisplay(x,y)
--*****************************************************************************
--37x16 - Displays barrier information in a pretty fashion.
--Squares for each HP. Changes color and shows a timer if barrier is hit.

  local BarrierHP = R4u(0x16B4,"IWRAM")
  local BarrierTmr= R4u(0x16B8,"IWRAM")

  local clr= 0xFF808080
  if BarrierHP > 0 then
    clr= 0xFF00FFFF
    if BarrierTmr > 0 then
      BoxB(x,y,BarrierHP,0xFFFF8000,0xFFFFFF00)
      local X,Y= x+6,y+13
      gui.drawLine( X,Y,X+math.floor((BarrierTmr-1)/2),Y,0xFFFFFF00)
      gui.drawPixel(X,Y,0xFFFFFF00) --Because line doesn't draw coord1==coord2

      BarrierHP= BarrierHP-1
    end
    for i= 1, BarrierHP do
      BoxB(x,y,i,0xFF0080FF,0xFF0080FF)
    end
  end
  gui.pixelText(x+ 4,y   ,"Barrier",clr)
  gui.drawLine( x   ,y   ,x   ,y+15,clr)
  gui.drawLine( x+ 1,y+15,x+35,y+15,clr)
  gui.drawLine( x+36,y   ,x+36,y+15,clr)
end

local WpnClr= {
  0xFFFF2000,  --Flame
  0xFF00FF00,  --Whirlwind
  0xFFC08000,  --Dirt
  0xFF0040FF,  --Bubble
  0xFFC0FFFF,  --Missile
  0xFFFFFF00,  --Star
  0xFFFF00FF,  --Spikeball
  0xFF00FFFF   --Laser
}
local function BoxW(x,y,bc,fc) gui.drawRectangle(x,y,6,24,bc,fc) end
--*****************************************************************************
local function WeaponDisplay(x,y,w)
--*****************************************************************************
--6x24 - For a single weapon. Will display negative ammo as well.

  local HaveWpn= R1u(0x1668+w,"IWRAM") ~= 0
  if not HaveWpn then  BoxW(x,y,0xFF606060,0); return  end
  local clr= WpnClr[w] or 0xFFFFFFFF

  local WpnSelect= R4u(0x15E4,"IWRAM")
  if WpnSelect == w then
    local FlashingClr= 0xFF008000 + 0x00FF7FFF * (math.floor(emu.framecount()/2)%2)
    BoxW(x,y,FlashingClr,0)
  else
    BoxW(x,y,clr,0)
  end

  local WpnAmmo= R1s(0x165C+w,"IWRAM")
  if WpnAmmo < 0 then
    WpnAmmo= -WpnAmmo
    for i= 1, WpnAmmo do
      local X,Y= x+2,y+2*i
      gui.drawPixel(X  ,Y,0xFFFF0000)
      gui.drawPixel(X+2,Y,0xFFFF0000)
    end
  else
    for i= 1, WpnAmmo do
      local X,Y= x+2,y+24-2*i
      gui.drawLine(X,Y,X+2,Y,clr)
    end
  end
end

--*****************************************************************************
local function ChargeDisplay(x,y)
--*****************************************************************************
--4x40 - Vertical charge display

  local Charge=    R1s(0x1608,"IWRAM")
  local WpnSelect= R4u(0x15E4,"IWRAM")
  local ArmUpgrade=R1u(0x1650,"IWRAM") ~= 0


end

--*****************************************************************************
local function BossDisplay(x,y)
--*****************************************************************************
end

--*****************************************************************************
local function MinibossDisplay(x,y)
--*****************************************************************************
end

--*****************************************************************************
local function MapDisplay(x,y)
--*****************************************************************************
--38x?? - Intended to be... Really basic. We only have 40 pixels width.
--Segments are as wide as 18 blocks. We ain't got a lot o' room.

  local Width=  R4u(0x153C,"IWRAM")
  local Height= R4u(0x1540,"IWRAM")
  if Width > 18 then return end --Panic
  gui.drawRectangle(x,y,Width*2+1,Height*2+1,0xFFC0C0C0,0)
end


client.SetGameExtraPadding(0,0,40,0)
--*****************************************************************************
while true do
--*****************************************************************************
--Our overhead.

  BarrierDisplay(242,2)
  for i= 1, 8 do
    local X= 245+((i-1)%4)*9
    local Y= 20 + math.floor((i-1)/4)*27
    WeaponDisplay(X,Y,i)
  end
  ChargeDisplay(241,20)
--  if not boss then
    local Segment= R4u(0x1530,"IWRAM")
    gui.pixelText(241,120,"Map " .. Segment)
    MapDisplay(241,128)
--  end
  emu.frameadvance()
end