Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/Assets/Lua/NES/Super C.lua
2 views
1
-- Author Pasky13
2
3
--Player
4
local px = 0x54C
5
local py = 0x532
6
7
--Player projectiles
8
local projxbase = 0x588
9
local projybase = 0x578
10
11
--Enemies
12
local ex = 0x53C
13
local ey = 0x522
14
15
local xm
16
local ym
17
18
local function draw_axis(x,y,color)
19
gui.drawLine(x,y-4,x,y+4,color)
20
gui.drawLine(x-4,y,x+4,y,color)
21
end
22
23
local function sign(val)
24
if val > 0x7F then
25
val = 256 + (val * -1)
26
end
27
return val
28
end
29
30
memory.usememorydomain("PRG ROM")
31
32
local function player()
33
-- Player 1
34
if mainmemory.read_u8(0xC6) ~= 0 then
35
local x = mainmemory.read_u8(px)
36
local y = mainmemory.read_u8(py)
37
draw_axis(x,y,0xFF0000FF)
38
end
39
-- Player 2
40
if mainmemory.read_u8(0xC7) ~= 0 then
41
x = mainmemory.read_u8(px+1)
42
y = mainmemory.read_u8(py+1)
43
draw_axis(x,y,0xFF0000FF)
44
end
45
end
46
47
local function bullets()
48
-- P1
49
if mainmemory.read_u8(0xC6) ~= 0 then
50
for i = 0,9,1 do
51
local x = mainmemory.read_u8(projxbase + i)
52
local y = mainmemory.read_u8(projybase + i)
53
54
if mainmemory.read_u8(0x638 + i) > 0 then
55
gui.drawBox(x-2,y-2,x+2,y+2,0xFFFFFFFF,0x40FFFFFF)
56
end
57
end
58
end
59
60
-- P2
61
if mainmemory.read_u8(0xC7) ~= 0 then
62
for i = 0,9,1 do
63
local x = mainmemory.read_u8(0x592 + i)
64
local y = mainmemory.read_u8(0x582 + i)
65
66
if mainmemory.read_u8(0x642 + i) > 0 then
67
gui.drawBox(x-2,y-2,x+2,y+2,0xFFFFFFFF,0x40FFFFFF)
68
end
69
end
70
end
71
end
72
73
74
local function enemies()
75
local active
76
local etype
77
local fill
78
local outl
79
for i = 0,0x0D,1 do
80
active = mainmemory.read_u8(0x508+i) -- sprite frame
81
etype = mainmemory.read_u8(0x73A + i)
82
if etype == 4 or etype == 0x0C then
83
fill = 0xFF00FF00
84
outl = 0x3500FF00
85
else
86
fill = 0xFFFF0000
87
outl = 0x35FF0000
88
end
89
90
local x = mainmemory.read_u8(ex + i)
91
local y = mainmemory.read_u8(ey + i)
92
93
-- Player 1 collision detection
94
if mainmemory.read_u8(0xC6) ~= 0 then
95
if active > 0 then
96
local offset = ((mainmemory.read_u8(0xC6) + etype + 1) % 0x100)
97
local xoff = sign(memory.read_u8(0x6000 + offset + 1)) + 1
98
local xrad = memory.read_u8(0x6000 + offset + 3)
99
local yoff = sign(memory.read_u8(0x6000 + offset)) + 1
100
local yrad = memory.read_u8(0x6000 + offset + 2)
101
gui.drawBox(x-xoff,y-yoff,x-xoff+xrad,y-yoff+yrad,fill,outl)
102
103
end
104
end
105
106
-- Player 2 collision detection
107
if mainmemory.read_u8(0xC7) ~= 0 then
108
if active > 0 then
109
local offset = ((mainmemory.read_u8(0xC7) + etype + 1) % 0x100)
110
local xoff = sign(memory.read_u8(0x6000 + offset + 1)) + 1
111
local xrad = memory.read_u8(0x6000 + offset + 3)
112
local yoff = sign(memory.read_u8(0x6000 + offset)) + 1
113
local yrad = memory.read_u8(0x6000 + offset + 2)
114
gui.drawBox(x-xoff,y-yoff,x-xoff+xrad,y-yoff+yrad,fill,outl)
115
end
116
end
117
118
-- Projectile collision
119
if active > 0 and etype ~= 4 and etype ~= 0x0C then
120
local poffset = etype + 0xA0
121
local pxoff = sign(memory.read_u8(0x6000 + poffset + 1)) + 1
122
local pxrad = memory.read_u8(0x6000 + poffset + 3) - 2
123
local pyoff = sign(memory.read_u8(0x6000 + poffset)) + 1
124
local pyrad = memory.read_u8(0x6000 + poffset + 2) - 2
125
gui.drawBox(x-pxoff,y-pyoff,x-pxoff+pxrad,y-pyoff+pyrad,0xFFFFFF00,0x40FFFF00)
126
end
127
128
end
129
end
130
131
local function scaler()
132
xm = client.screenwidth() / 256
133
ym = client.screenheight() / 224
134
end
135
136
while true do
137
scaler()
138
player()
139
bullets()
140
enemies()
141
emu.frameadvance()
142
end
143