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
|
package demonchime
import "core:log"
import rl "vendor:raylib"
current_room: Room_Position_Resource
open_room_at :: proc(pos: [2]i32) -> bool {
pos := pos
pos += {current_room.x, current_room.y}
log.debug("trying to change room...", pos)
for room_pos in world {
if room_pos.id == current_room.id {
continue
}
if pos.x >= room_pos.x && pos.x <= room_pos.x + room_pos.width \
&& pos.y >= room_pos.y && pos.y <= room_pos.y + room_pos.height {
current_room = room_pos
return true
}
}
return false
}
open_room :: proc(id: Room_Id) -> bool {
for room_pos in world {
if room_pos.id == id {
current_room = room_pos
return true
}
}
return false
}
draw_room :: proc(id: Room_Id) {
draw_tile :: proc(x: i32, y: i32, tile_id: u32) {
tile := tiles[tile_id]
tileset := tilesets[tile.tileset]
rl.DrawTexturePro(
get_image(tileset.image),
rl.Rectangle{
x = f32(tile.rect.start.x),
y = f32(tile.rect.start.y),
width = f32(tile.rect.size.x),
height = f32(tile.rect.size.y),
},
rl.Rectangle{
x = f32(x),
y = f32(y),
width = f32(tile.rect.size.x),
height = f32(tile.rect.size.y),
},
{0, 0},
0,
rl.WHITE,
)
}
iterate_room_tiles(id, draw_tile)
}
Map_Iterate_Callback :: proc(i32, i32, u32)
iterate_room_tiles :: proc(id: Room_Id, callback: Map_Iterate_Callback) {
room := get_room(id)
for layer in room.layers {
x: i32 = 0
y: i32 = 0
for cell, i in layer {
if cell > 0 {
callback(x, y, cell - 1)
}
x += room.tile_width
if x > (room.width - 1) * room.tile_width {
x = 0
y += room.tile_height
}
}
}
}
|