package demonchime import rl "vendor:raylib" Object_Spawner :: proc(Object_Resource) Room_Change_Callback :: proc(Room_Id) current_room: Room_Position_Resource object_spawners := [Object_Type]Object_Spawner{ .PLAYER_SPAWN = object_spawner_player_spawn, .COLLISION = object_spawner_collision, } room_open_cb := []Room_Change_Callback{ on_room_open_platforms, on_room_open_bullets, } room_close_cb := []Room_Change_Callback{ } @(private = "file") _spawn_objects :: proc(room_id: Room_Id) { room := get_room(room_id) for obj in room.objects { spawner := object_spawners[obj.type] if spawner != nil { spawner(obj) } } } @(private = "file") _open_room :: proc(room_pos: Room_Position_Resource) { for cb in room_close_cb { cb(current_room.id) } current_room = room_pos for cb in room_open_cb { cb(current_room.id) } _spawn_objects(current_room.id) } open_room_at :: proc(pos: [2]i32) -> bool { pos := pos pos += {current_room.x, current_room.y} 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 { _open_room(room_pos) return true } } return false } open_room :: proc(id: Room_Id) -> bool { for room_pos in world { if room_pos.id == id { _open_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) } Room_Iterate_Callback :: proc(_: i32, _: i32, _: u32) iterate_room_tiles :: proc(id: Room_Id, callback: Room_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 } } } }