-
Notifications
You must be signed in to change notification settings - Fork 0
/
bricks.nut
118 lines (105 loc) · 2.45 KB
/
bricks.nut
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* bricks.nut
*
* An isometric example of a minecraft like dungeon system
* (C)2024 elmerucr
*/
dofile("iso_brick.nut")
offset_x <- 136
offset_y <- 81
function init()
{
for (local i=0; i<sprite.size; i++) {
vpoke(0x10000+i, sprite.data[i])
}
for (local i=0; i<sprite.palette.len(); i++) {
poke(0x1100+i, sprite.palette[i])
}
poke16(0x0a14, 16)
poke16(0x0a16, 16)
poke(0x0a19, 0x01)
poke(0x0a1a, 0x00)
poke(0x0a1b, 0x00)
poke(0x0a1c, 0x20)
poke(0x0a1d, 0x00)
poke(0x0a1e, 0x00)
poke(0x0a1f, 0x03)
/*
* Activate frame done interrupt which happens directly after each
* screen refresh and calls the squirrel frame() function.
*/
poke(0x401, 1)
}
function frame()
{
poke(0x805, 0x01) // target color
poke(0x819, 0xff) // max gamma r
poke(0x81a, 0xff) // max gamma g
poke(0x81b, 0xff) // max gamma b
// vpoke(0xf3e800, 0x05);
// vpoke(0xf3e801, 0x00);
// vpoke(0xf3e802, 0xf0);
// vpoke(0xf3e803, 0x00);
poke(0x803, 0x0) // destination surface = 0x0 = screen
poke(0x801, 4) // clear surface command
poke(0x802,0x1) // src surface = 0x1
poke(0x803,0x0) // dest surface = 0x0
if ((peek(0x580 + 0x41) & 1) != 0) {
// cursor left
offset_x +=2
}
if ((peek(0x580 + 0x44) & 1)!= 0) {
// cursor right
offset_x -=2
}
if ((peek(0x580 + 0x42) & 1) != 0) {
// cursor up
offset_y += 1
}
if ((peek(0x580 + 0x43) & 1) != 0) {
// cursor down
offset_y -= 1
}
local offset_z = 0
for (local z=-1; z<2; z++) {
for (local y=-40; y<40; y++) {
for (local x=-40; x<40; x++) {
local dist = (x*x)+(y*y)
local ry = (-(offset_y-81)/8) + ((offset_x-136)/16)
local rx = (-(offset_y-81)/8) + (-(offset_x-136)/16)
local od = (rx-x)*(rx-x)+(ry-y)*(ry-y)
if (od <= 85) {
poke(0x819, 255-(3*od))
poke(0x81a, 255-(3*od))
poke(0x81b, 255-(3*od))
} else {
poke(0x819, 0)
poke(0x81a, 0)
poke(0x81b, 0)
}
if (z == -1) {
poke(0x0a1f, 2) // dirt
if (dist < 400) {
poke16(0x0a10, offset_x + (8 * x) - (8 * y))
poke16(0x0a12, offset_y + (4 * x) + (4 * y) - (8 * z))
poke(0x801, 0x01)
}
} else {
poke(0x0a1f, 3) // stones
if ((dist < 200) && (dist > 50)) {
poke16(0x0a10, offset_x + (8 * x) - (8 * y))
poke16(0x0a12, offset_y + (4 * x) + (4 * y) - (8 * z))
poke(0x801, 0x01)
}
}
}
}
}
poke(0x805,0x33)
poke(0x819, 0xff)
poke(0x81a, 0xff)
poke(0x81b, 0xff)
poke16(0x0808, 160)
poke16(0x080a, 100)
poke(0x801, 0x08)
}