aboutsummaryrefslogtreecommitdiff
path: root/src/tiled
diff options
context:
space:
mode:
authorXander Swan <[hidden email]>2026-01-01 18:32:20 -0500
committerXander Swan <[hidden email]>2026-01-01 18:32:20 -0500
commit65a2ceda55198dab3bab75c06c0d50adeb0a1101 (patch)
tree2a08400520f60fcd86b381bc840bb5c739ff998a /src/tiled
parentdc373b507ca68ada2cbf4c8e0d7949d6bc46ed9b (diff)
lots of changes + player dash
Diffstat (limited to 'src/tiled')
-rw-r--r--src/tiled/tiled.odin59
-rw-r--r--src/tiled/world.odin84
2 files changed, 116 insertions, 27 deletions
diff --git a/src/tiled/tiled.odin b/src/tiled/tiled.odin
index 373715a..d84c296 100644
--- a/src/tiled/tiled.odin
+++ b/src/tiled/tiled.odin
@@ -183,7 +183,7 @@ load_map :: proc(path: string) -> (Map, Error) {
return {}, .COULD_NOT_LOAD
}
- log.info(jmap)
+ // log.debug(jmap)
tmap: Map
err := convert_json_map(jmap, &tmap, path)
@@ -356,8 +356,8 @@ iterate_map_tiles :: proc(tmap: Map, callback: Map_Iterate_Callback) {
x: i32 = 0
y: i32 = 0
- for cell in tile_layer.data {
- if cell != 0 {
+ for cell, i in tile_layer.data {
+ if cell > 0 {
tile := tmap.tiles[cell - 1]
tile_set := tmap.tile_sets[tile.tile_set]
callback(x, y, tile, tile_set)
@@ -372,7 +372,7 @@ iterate_map_tiles :: proc(tmap: Map, callback: Map_Iterate_Callback) {
}
}
-draw_map :: proc(tmap: Map) {
+test_cells :: proc(tmap: Map) {
for layer in tmap.layers {
tile_layer, ok := layer.layer.(Tile_Layer)
if !ok {
@@ -382,29 +382,9 @@ draw_map :: proc(tmap: Map) {
x: i32 = 0
y: i32 = 0
- for cell in tile_layer.data {
- if cell != 0 {
- tile := tmap.tiles[cell - 1]
- tile_set := tmap.tile_sets[tile.tile_set]
-
- rl.DrawTexturePro(
- tile_set.texture,
- rl.Rectangle{
- x = f32(tile.src_start.x),
- y = f32(tile.src_start.y),
- width = f32(tile.src_size.x),
- height = f32(tile.src_size.y),
- },
- rl.Rectangle{
- x = f32(x),
- y = f32(y),
- width = f32(tile.src_size.x),
- height = f32(tile.src_size.y),
- },
- {0, 0},
- 0,
- rl.WHITE,
- )
+ for cell, i in tile_layer.data {
+ if cell > 0 {
+ log.debug(i, [2]i32{x, y}, cell)
}
x += tmap.tile_width
@@ -416,6 +396,31 @@ draw_map :: proc(tmap: Map) {
}
}
+draw_map :: proc(tmap: Map) {
+ draw_tile :: proc(x: i32, y: i32, tile: Tile, tile_set: Tile_Set) {
+ rl.DrawTexturePro(
+ tile_set.texture,
+ rl.Rectangle{
+ x = f32(tile.src_start.x),
+ y = f32(tile.src_start.y),
+ width = f32(tile.src_size.x),
+ height = f32(tile.src_size.y),
+ },
+ rl.Rectangle{
+ x = f32(x),
+ y = f32(y),
+ width = f32(tile.src_size.x),
+ height = f32(tile.src_size.y),
+ },
+ {0, 0},
+ 0,
+ rl.WHITE,
+ )
+ }
+
+ iterate_map_tiles(tmap, draw_tile)
+}
+
@(private)
load_image :: proc(filename: string, res_dir: string) -> rl.Texture2D {
path := strings.concatenate({res_dir, "/", filename})
diff --git a/src/tiled/world.odin b/src/tiled/world.odin
new file mode 100644
index 0000000..c55097a
--- /dev/null
+++ b/src/tiled/world.odin
@@ -0,0 +1,84 @@
+package tiled
+
+import os "core:os/os2"
+import "core:log"
+import "core:encoding/json"
+import "core:path/filepath"
+import "core:strings"
+
+World_Room :: struct {
+ file_name: string `json:"fileName"`,
+ x: i32,
+ y: i32,
+ width: i32,
+ height: i32,
+}
+
+res_dir: string
+world: []World_Room
+current_room: struct {
+ tmap: Map,
+ using room: World_Room,
+}
+
+load_world :: proc(path: string) -> bool {
+ world_text, read_err := os.read_entire_file(path, context.temp_allocator)
+ if read_err != nil {
+ log.errorf("Failed to read file %v (%v)", path, read_err)
+ return false
+ }
+
+ jworld: struct {
+ maps: []World_Room,
+ }
+ unmarshal_err := json.unmarshal(
+ world_text,
+ &jworld,
+ )
+ if unmarshal_err != nil {
+ log.errorf("Failed to unmarshal file %v (%v)", path, unmarshal_err)
+ return false
+ }
+
+ world = jworld.maps
+ res_dir = filepath.dir(path)
+
+ return true
+}
+
+delete_world :: proc() {
+ delete_map(current_room.tmap)
+ delete(world)
+ delete(res_dir)
+}
+
+open_new_room_at :: proc(pos: [2]i32) -> bool {
+ pos := pos
+ pos += {current_room.room.x, current_room.room.y}
+
+ log.debug("trying to change room...", pos)
+ for room in world {
+ if strings.compare(room.file_name, current_room.room.file_name) == 0 {
+ continue
+ }
+
+ if pos.x >= room.x && pos.x <= room.x + room.width \
+ && pos.y >= room.y && pos.y <= room.y + room.height {
+ delete_map(current_room.tmap)
+
+ path := strings.concatenate(
+ {res_dir, "/", room.file_name},
+ allocator = context.temp_allocator,
+ )
+ new_map, err := load_map(path)
+ if err != .NONE {
+ log.error("could not load new room")
+ return false
+ }
+ current_room.tmap = new_map
+ current_room.room = room
+ return true
+ }
+ }
+ return false
+}