Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/Assets/Lua/NES/Megaman 4.lua
2 views
1
--Author Pasky13
2
3
local xbase = 0x330
4
local x_page = 0x348
5
local ybase = 0x378
6
local y_page = 0x390
7
8
local camx = 0xFC
9
local camx_page = 0xF9
10
local cx
11
12
-- Compensation for megaman's projectiles
13
local pcompx = 0
14
local pcompy = 0
15
16
-- Compensation for megaman's hitbox
17
local compx = 2
18
local compy = 2
19
20
local xm
21
local ym
22
23
memory.usememorydomain("PRG ROM")
24
25
local function camera()
26
cx = mainmemory.read_u8(camx) + (mainmemory.read_u8(camx_page) * 256)
27
end
28
29
local function hex(val)
30
val = string.format("%X",val)
31
return val
32
end
33
34
local function megaman()
35
local x = mainmemory.read_u8(xbase) + (mainmemory.read_u8(x_page) * 256) - cx
36
local y = mainmemory.read_u8(ybase)
37
local hp = bit.band(mainmemory.read_u8(0xB0),0x7F)
38
compx = 6
39
compy = 10
40
gui.drawBox(x+compx,y+compy,x-compx,y-compy,0xFF0000FF,0x400000FF)
41
gui.text(23 * xm,15 * ym,hp)
42
gui.drawLine(x,y+2,x,y-2)
43
gui.drawLine(x+2,y,x-2,y)
44
end
45
46
local function megaman_projectiles()
47
local x
48
local y
49
local xrad
50
local yrad
51
local offset
52
local active
53
54
for i = 1,3,1 do
55
active = mainmemory.read_u8(0x300 + i)
56
57
if active > 0 then
58
offset = mainmemory.read_u8(0x408 + i) * 2
59
x = mainmemory.read_u8(xbase + i) + (mainmemory.read_s8(x_page + i) * 256) - cx
60
y = mainmemory.read_u8(ybase + i)
61
xrad = memory.read_u8(0x7FACF + offset)
62
yrad = memory.read_u8(0x7FACE + offset)
63
64
65
-- Compensate the boxes if xrad/yrad is 0 or 1
66
if xrad <= 1 then
67
pcompx = 2 - xrad
68
else
69
pcompx = 0
70
end
71
72
if yrad <= 1 then
73
pcompy = 2 - yrad
74
else
75
pcompy = 0
76
end
77
78
gui.drawBox(x+xrad + pcompx,y+yrad + pcompy,x-xrad - pcompx,y-yrad - pcompy,0xFFFFFFFF,0x40FFFFFF)
79
end
80
end
81
end
82
83
local function objects()
84
local x
85
local y
86
local xrad
87
local yrad
88
local hp
89
local offset
90
local active
91
local otype
92
93
for i = 4,0x17,1 do
94
active = mainmemory.read_u8(0x300 + i)
95
otype = mainmemory.read_s8(0x408 + i)
96
97
if active > 0 then
98
x = mainmemory.read_u8(xbase + i) + (mainmemory.read_s8(x_page + i) * 256) - cx
99
y = mainmemory.read_u8(ybase + i) + (mainmemory.read_s8(y_page + i ) * 256)
100
101
if otype < 0 then -- if it's an enemy/projectile
102
offset = bit.band(mainmemory.read_u8(0x408 + i),0x3F)
103
xrad = memory.read_u8(0x7F9F4 + offset)
104
105
if mainmemory.read_u8(0x558) == 0x10 then -- megaman is sliding
106
yrad = memory.read_u8(0x7F9B4 + offset) - 0x10
107
else
108
yrad = memory.read_u8(0x7F9B4 + offset)
109
end
110
111
hp = mainmemory.read_u8(0x450 + i)
112
113
-- Calculate compensation for megaman
114
xrad = xrad - compx
115
yrad = yrad - compx
116
117
gui.text(x * xm,y * ym,"HP:" .. hp)
118
--gui.text(x,y,hp)
119
gui.drawBox(x-xrad,y-yrad,x+xrad,y+yrad,0xFFFF0000,0x90FF0000)
120
121
-- Projectile vuln box
122
yrad = memory.read_u8(0x7FADC + offset) - pcompx
123
xrad = memory.read_u8(0x7FB1C + offset) - pcompy
124
gui.drawBox(x-xrad,y-yrad,x+xrad,y+yrad,0xFF00FF00,0x5000FF00)
125
end
126
end
127
end
128
end
129
130
local function scaler()
131
xm = client.screenwidth() / 256
132
ym = client.screenheight() / 224
133
end
134
135
while true do
136
scaler()
137
camera()
138
megaman()
139
megaman_projectiles()
140
objects()
141
emu.frameadvance()
142
end
143
144