aboutsummaryrefslogtreecommitdiff
path: root/src/world.odin
diff options
context:
space:
mode:
authoriamcheeseman <[hidden email]>2026-01-12 20:51:28 -0500
committeriamcheeseman <[hidden email]>2026-01-12 20:51:28 -0500
commit7fb83578b99aa224f7545f4118a46e84b58a9295 (patch)
tree515e294ac7de167c4501cc0a8d375b13213faf36 /src/world.odin
parent2b3a3ea9f4bc902b1b357fd149952d4570b25bf3 (diff)
NEW ASSET SYSTEM WOOOOOOOOHOOOOOOOOOOOOOOOOOOOOOOOOO
Diffstat (limited to 'src/world.odin')
-rw-r--r--src/world.odin87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/world.odin b/src/world.odin
new file mode 100644
index 0000000..d0e6c74
--- /dev/null
+++ b/src/world.odin
@@ -0,0 +1,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
+ }
+ }
+ }
+}