Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/Assets/Lua/NES/Ninja Gaiden II.lua
2 views
1
-- Ninja Gaiden II (USA) Collision Box Viewer
2
-- Author Pasky
3
-- For use with Bizhawk
4
5
local drawn = false -- Used to draw ryu's vulnaribility box only once per frame
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,0xFF000000)
18
end
19
20
-- Player attacks
21
22
local function pattack()
23
if memory.read_u8(0xCA55) == 0xB9 and memory.read_u8(0xCA56) == 0xF0 and memory.read_u8(0xCA57) == 0x04 then -- Bank check
24
local xreg = emu.getregister("X")
25
local yreg = emu.getregister("Y")
26
-- Sword
27
local x = memory.read_u8(0x550 + yreg)
28
local y = memory.read_u8(0x580 + yreg) - 0x03
29
local xrad = 0x20
30
if bit.band(memory.read_u8(0x4F0 + yreg),0x40) == 0x40 then -- check ryu facing direction
31
xrad = -0x20
32
end
33
-- NOTE: The sword has no yradius, using drawBox() with a duplicate y coordinate does not draw a box, drawLine() is used in its place
34
gui.drawLine(x,y,x+xrad,y,0xFFFFFFFF) -- Draw sword hitbox (line)
35
36
-- Enemy vuln boxes (green)
37
x = memory.read_u8(0x550 + xreg)
38
y = memory.read_u8(0x580 + xreg)
39
xrad = memory.read_u8(0x610 + xreg)
40
local yrad = memory.read_u8(0x628 + xreg)
41
gui.drawBox(x-xrad,y-yrad,x+xrad,y+yrad,0xFF00FF00,0x4000FF00)
42
end
43
end
44
45
-- Touch collision
46
local function collision()
47
if memory.read_u8(0xCC33) == 0xB9 and memory.read_u8(0xCC34) == 0x50 and memory.read_u8(0xCC35) == 0x05 then -- Bank check
48
local xreg = emu.getregister("X")
49
local yreg = emu.getregister("Y")
50
local x = memory.read_u8(0x550 + yreg)
51
local y = memory.read_u8(0x580 + yreg)
52
local xrad = memory.read_u8(0x610 + yreg)
53
local yrad = memory.read_u8(0x628 + yreg)
54
gui.drawBox(x-xrad,y-yrad,x+xrad,y+yrad,0xFFFF0000,0x40FF0000)
55
56
-- Player
57
if drawn == false then
58
local x = memory.read_u8(0x550)
59
local y = memory.read_u8(0x580)
60
local hp = memory.read_u8(0x80)
61
local xrad = 0x06
62
local yrad = 0x10
63
if bit.band(memory.read_u8(0x520),0x02) == 0x02 then -- Check if ryu is crouching
64
yrad = 0x0C
65
end
66
gui.drawBox(x-xrad,y-yrad,x+xrad,y+yrad,0xFF0000FF,0x400000FF)
67
drawn = true
68
end
69
end
70
end
71
72
-- Subweapons
73
local function subweapon()
74
if memory.read_u8(0xCB2F) == 0xBD and memory.read_u8(0xCB30) == 0x50 and memory.read_u8(0xCB31) == 0x05 then -- Bank check
75
-- sub weapon
76
local xreg = emu.getregister("X")
77
local yreg = emu.getregister("Y")
78
local x = memory.read_u8(0x550 + yreg)
79
local y = memory.read_u8(0x580 + yreg)
80
local xrad = memory.read_u8(0xC0)
81
local yrad = memory.read_u8(0xC0)
82
gui.drawBox(x-xrad,y-yrad,x+xrad,y+yrad,0xFFFFFFFF,0x40FFFFFF)
83
84
-- Enemy vuln (green)
85
x = memory.read_u8(0x550 + xreg)
86
y = memory.read_u8(0x580 + xreg)
87
xrad = memory.read_u8(0x610 + xreg)
88
yrad = memory.read_u8(0x628 + xreg)
89
gui.drawBox(x-xrad,y-yrad,x+xrad,y+yrad,0xFF00FF00,0x4000FF00)
90
end
91
end
92
93
event.onmemoryexecute(collision,0xCC33)
94
event.onmemoryexecute(pattack,0xCA55)
95
event.onmemoryexecute(subweapon,0xCB2F)
96
97
while true do
98
emu.frameadvance()
99
drawn = false
100
end
101