Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/Assets/Lua/NES/Castlevania.lua
2 views
1
--Author Pasky13
2
local px = 0x38C
3
local py = 0x354
4
local pl = 0x45
5
6
local ex = 0x38C
7
local ey = 0x354
8
9
memory.usememorydomain("PRG ROM")
10
11
local function whip()
12
local box = {0,0,0} -- xoff/yoff/xrad/yrad
13
local wtype = mainmemory.read_u8(0x70)
14
local pos = bit.band(mainmemory.read_u8(0x434),0x7F) -- Simons acting positon (jumping/crouching, etc...)
15
box[1] = memory.read_s8(0x1E45D + wtype)
16
wtype = wtype * 2
17
box[2] = memory.read_s8(0x1E460 + pos)
18
box[3] = memory.read_u8(0x1E464 + wtype)
19
box[4] = memory.read_u8(0x1E465 + wtype)
20
21
if mainmemory.read_u8(0x450) == 1 then -- Simon is facing left
22
box[1] = box[1] * -1
23
box[3] = box[3] * -1
24
end
25
return box
26
end
27
28
local function player()
29
local x = mainmemory.read_u8(px)
30
local y = mainmemory.read_u8(py)
31
local box
32
gui.drawBox(x+4,y+mainmemory.read_u8(0x5F),x-4,y-mainmemory.read_u8(0x5F),0xFF0000FF,0x400000FF)
33
34
if mainmemory.read_u8(0x568) == 0x11 then -- Whip is active
35
box = whip()
36
gui.drawBox(x+box[1]+box[3],y+box[2]+box[4],x+box[1]-box[3],y+box[2]-box[4],0xFFFFFFFF,0x40FFFFFF)
37
end
38
39
end
40
41
local function buildbox(i)
42
local box = {0,0} -- xrad/yrad
43
local offset = mainmemory.read_u8(0x434 + i)
44
local dracform
45
if offset == 0x1D then
46
dracform = mainmemory.read_u8(0x7A)
47
if dracform == 1 then
48
offset = 0x30 * 2
49
else
50
offset = offset * 2
51
end
52
else
53
offset = offset * 2
54
end
55
56
box = { memory.read_u8(0x1E46A + offset),memory.read_u8(0x1E46B + offset) }
57
58
return box
59
end
60
61
local function getcolor(x)
62
local color = {0,0} -- Fill/Outline
63
if x >= 0x28 and x < 0x30 then
64
color = {0x40FFA500,0xFFFFA500}
65
elseif x >= 0x30 and x <= 0x35 then
66
return color
67
elseif x == 0x17 then -- Simon subweapon
68
color = {0x4000FFFF,0xFF00FFFF}
69
elseif x == 0x1D then -- dracula invuln box
70
color = {0x40FF0000,0xFFFFFFFF}
71
else
72
color = {0x40FF0000,0xFFFF0000}
73
end
74
return color
75
end
76
77
local function objects()
78
local x
79
local y
80
local active
81
local box
82
local etype
83
local c
84
local oob
85
86
for i = 3,20,1 do
87
oob = mainmemory.read_u8(0x300 + i)
88
if oob == 0 or oob == 0x80 then
89
box = buildbox(i)
90
etype = mainmemory.read_u8(0x434 + i)
91
c = getcolor(etype)
92
x = mainmemory.read_u8(ex + i)
93
y = mainmemory.read_u8(ey + i)
94
gui.drawBox(x+box[1],y+box[2],x-box[1],y-box[2],c[2],c[1])
95
if etype == 0x1D then -- if dracula's invuln box
96
gui.drawLine(x+box[1],y,x-box[1],y,0xFFFFFFFF)
97
gui.drawLine(x,y+box[2],x,y-box[2],0xFFFFFFFF)
98
end
99
end
100
end
101
end
102
103
104
while true do
105
player()
106
objects()
107
emu.frameadvance()
108
end
109