Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/Assets/Lua/SNES/Donkey Kong Country 3.lua
2 views
1
--Author pasky13
2
3
local cx
4
local cy
5
local data = 0x3C0000
6
7
local function camera()
8
cx = mainmemory.read_u16_le(0x493)
9
cy = mainmemory.read_u16_le(0x497)
10
end
11
12
function findbit(p)
13
return 2 ^ (p - 1)
14
end
15
16
function hasbit(x, p)
17
return x % (p + p) >= p
18
end
19
20
local function hex(val)
21
val = string.format("%X",val)
22
return val
23
end
24
25
memory.usememorydomain("CARTROM")
26
27
local function player()
28
local pbase = 0x878
29
for i = 0,1,1 do
30
pbase = pbase + (i * 0x6E)
31
if mainmemory.read_u8(pbase + 0x24) > 0 then
32
local point = memory.read_u16_le(mainmemory.read_u16_le(pbase + 0x24) + 0x3C8003)
33
local properties = mainmemory.read_u16_le(pbase + 0x1E)
34
local x = mainmemory.read_u16_le(pbase + 0x12) - cx
35
local y = mainmemory.read_u16_le(pbase + 0x16) - cy
36
local xoff = memory.read_s8(point + data)
37
local yoff = memory.read_s8(point + 2 + data)
38
local xrad = memory.read_u8(point + 4 + data)
39
local yrad = memory.read_u8(point + 6 + data)
40
41
if hasbit(properties,findbit(15)) then -- If facing right
42
xoff = xoff * -1
43
xrad = xrad * -1
44
elseif hasbit(properties,findbit(16)) then -- Upside down?
45
yoff = yoff * -1
46
yrad = yrad * -1
47
end
48
49
50
gui.drawBox(x+xoff,y+yoff,x+xoff+xrad,y+yoff+yrad,0xFF0000FF,0x400000FF)
51
end
52
end
53
end
54
55
local function enemy()
56
local start = 0x954
57
local base
58
local x
59
local y
60
local xoff
61
local yoff
62
local xrad
63
local yrad
64
local properties
65
local point
66
local active
67
for i = 0,15,1 do
68
base = start + (i * 0x6E)
69
active = mainmemory.read_u8(base + 0x30)
70
properties = mainmemory.read_u16_le(base + 0x1E)
71
72
if mainmemory.read_u8(base + 0x24) > 0 then
73
point = memory.read_u16_le(mainmemory.read_u16_le(base + 0x24) + 0x3C8003)
74
properties = mainmemory.read_u16_le(base + 0x1E)
75
x = mainmemory.read_u16_le(base + 0x12) - cx
76
y = mainmemory.read_u16_le(base + 0x16) - cy
77
xoff = memory.read_s8(point + data)
78
yoff = memory.read_s8(point + 2 + data)
79
xrad = memory.read_u8(point + 4 + data)
80
yrad = memory.read_u8(point + 6 + data)
81
82
83
if hasbit(properties,findbit(15)) then -- If facing right
84
xoff = xoff * -1
85
xrad = xrad * -1
86
elseif hasbit(properties,findbit(16)) then -- Upside down?
87
yoff = yoff * -1
88
yrad = yrad * -1
89
end
90
91
gui.drawBox(x+xoff,y+yoff,x+xoff+xrad,y+yoff+yrad,0xFFFF0000,0x40FF0000)
92
end
93
end
94
end
95
96
while true do
97
camera()
98
player()
99
enemy()
100
emu.frameadvance()
101
end
102