Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/Assets/Lua/NES/Ninja Gaiden III.lua
2 views
1
-- Ninja Gaiden 3 (USA) Collision box viewer
2
-- Author: Pasky
3
-- For use with Bizhawk
4
5
local drawn = false -- Used so the player box isn't constantly drawn everytime the collision function is hit
6
memory.usememorydomain("System Bus")
7
8
function axis(x,y,color,xsize,ysize)
9
if xsize == nil then
10
xsize = 2
11
end
12
if ysize == nil then
13
ysize = 2
14
end
15
gui.drawLine(x+xsize,y,x-xsize,y,color)
16
gui.drawLine(x,y+ysize,x,y-ysize,color)
17
gui.drawLine(x,y,x,y,"#000000FF")
18
end
19
20
local function collision() -- Collision between enemies
21
if memory.read_u8(0xA2CA) == 0xBD and memory.read_u8(0xA2CB) == 0x16 and memory.read_u8(0xA2CC) == 0x05 then -- Bank check
22
local xreg = emu.getregister("X")
23
local yreg = emu.getregister("Y")
24
-- Enemy
25
local x = memory.read_u8(0x516 + xreg)
26
local y = memory.read_u8(0x58E + xreg)
27
-- Enemy boxes
28
local xrad = memory.read_u8(0x052E + xreg)
29
local yrad = memory.read_u8(0x05A6 + xreg)
30
gui.drawBox(x-xrad,y-yrad,x+xrad,y+yrad,0xFFFF0000,0x40FF0000)
31
local invuln = bit.bor(memory.read_u8(0x4E6 + xreg),memory.read_u8(0x4CE + xreg))
32
if bit.band(invuln,0x02) == 0x02 then
33
axis(x,y,0xFFFFFFFF,xrad,yrad)
34
end
35
-- Player
36
if drawn == false then
37
x = memory.read_u8(0x516)
38
y = memory.read_u8(0x58E)
39
xrad = 0x06
40
yrad = memory.read_u8(0x8C)
41
gui.drawBox(x-xrad,y-yrad,x+xrad,y+yrad,0xFF0000FF,0x400000FF)
42
axis(x,y)
43
drawn = true
44
end
45
end
46
end
47
48
local function pattack() -- Player attacks
49
if memory.read_u8(0xA050) == 0xBD and memory.read_u8(0xA051) == 0x16 and memory.read_u8(0xA052) == 0x05 then -- Bank check
50
local xreg = emu.getregister("X")
51
local yreg = emu.getregister("Y")
52
local x = memory.read_u8(0x516)
53
if bit.band(memory.read_u8(0x4CE),0x40) == 0x40 then
54
x = x - memory.read_u8(0xAA)
55
else
56
x = x + memory.read_u8(0xAA)
57
end
58
local y = memory.read_u8(0x58E) - 0x08
59
local xrad = memory.read_u8(0xAA)
60
local yrad = memory.read_u8(0xAB)
61
gui.drawBox(x-xrad,y-yrad,x+xrad,y+yrad,0xFFFFFFFF,0x40FFFFFF)
62
63
-- Enemy vulnerability boxes (green)
64
x = memory.read_u8(0x516 + xreg)
65
y = memory.read_u8(0x58E + xreg)
66
xrad = memory.read_u8(0x052E + xreg)
67
yrad = memory.read_u8(0x05A6 + xreg)
68
gui.drawBox(x-xrad,y-yrad,x+xrad,y+yrad,0xFF00FF00,0x4000FF00)
69
local invuln = bit.bor(memory.read_u8(0x4E6 + xreg),memory.read_u8(0x4CE + xreg))
70
if bit.band(invuln,0x02) == 0x02 then
71
axis(x,y,0xFFFFFFFF,xrad,yrad)
72
end
73
end
74
end
75
76
local function subweapon() -- Player sub weapons
77
if memory.read_u8(0xA050) == 0xBD and memory.read_u8(0xA051) == 0x16 and memory.read_u8(0xA052) == 0x05 then -- Bank check
78
local xreg = emu.getregister("X")
79
local yreg = emu.getregister("Y")
80
local x = memory.read_u8(0x51E + yreg)
81
local y = memory.read_u8(0x596 + yreg)
82
local wrad = memory.read_u8(0x9E)
83
gui.drawBox(x-wrad,y-wrad,x+wrad,y+wrad)
84
85
-- Enemy projectile vulnerability boxes (green)
86
x = memory.read_u8(0x516 + xreg)
87
y = memory.read_u8(0x58E + xreg)
88
xrad = memory.read_u8(0x052E + xreg)
89
yrad = memory.read_u8(0x05A6 + xreg)
90
gui.drawBox(x-xrad,y-yrad,x+xrad,y+yrad,0xFF00FF00,0x4000FF00)
91
local invuln = bit.bor(memory.read_u8(0x4E6 + xreg),memory.read_u8(0x4CE + xreg))
92
if bit.band(invuln,0x02) == 0x02 then
93
axis(x,y,0xFFFFFFFF,xrad,yrad)
94
end
95
end
96
end
97
98
event.onmemoryexecute(collision,0xA2CA)
99
event.onmemoryexecute(pattack,0xA050)
100
event.onmemoryexecute(subweapon,0xA1DB)
101
102
while true do
103
emu.frameadvance()
104
drawn = false
105
end
106