From dc373b507ca68ada2cbf4c8e0d7949d6bc46ed9b Mon Sep 17 00:00:00 2001 From: Xander Swan <[hidden email]> Date: Tue, 23 Dec 2025 22:21:09 -0500 Subject: Use the tile collisions defined in tiled --- res/tileset.tsj | 626 +++++++++++++++++++++++++++++++++++++++++++++++++++ src.bin | Bin 2391800 -> 0 bytes src/main.odin | 18 +- src/platform.odin | 2 + src/tiled/tiled.odin | 26 ++- 5 files changed, 658 insertions(+), 14 deletions(-) delete mode 100755 src.bin diff --git a/res/tileset.tsj b/res/tileset.tsj index 2f717e9..22fe6c0 100644 --- a/res/tileset.tsj +++ b/res/tileset.tsj @@ -9,6 +9,632 @@ "tilecount":44, "tiledversion":"1.11.2", "tileheight":16, + "tiles":[ + { + "id":4, + "objectgroup": + { + "draworder":"index", + "name":"", + "objects":[ + { + "height":8, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":8, + "x":8, + "y":8 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + } + }, + { + "id":5, + "objectgroup": + { + "draworder":"index", + "name":"", + "objects":[ + { + "height":8, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":8, + "x":0, + "y":8 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + } + }, + { + "id":6, + "objectgroup": + { + "draworder":"index", + "name":"", + "objects":[ + { + "height":16, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":8, + "x":8, + "y":0 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + } + }, + { + "id":7, + "objectgroup": + { + "draworder":"index", + "name":"", + "objects":[ + { + "height":16, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":8, + "x":0, + "y":0 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + } + }, + { + "id":8, + "objectgroup": + { + "draworder":"index", + "name":"", + "objects":[ + { + "height":8, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":16, + "x":0, + "y":8 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + } + }, + { + "id":17, + "objectgroup": + { + "draworder":"index", + "name":"", + "objects":[ + { + "height":8, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":16, + "x":0, + "y":8 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + } + }, + { + "id":18, + "objectgroup": + { + "draworder":"index", + "name":"", + "objects":[ + { + "height":8, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":16, + "x":0, + "y":0 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + } + }, + { + "id":19, + "objectgroup": + { + "draworder":"index", + "name":"", + "objects":[ + { + "height":8, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":16, + "x":0, + "y":8 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + } + }, + { + "id":20, + "objectgroup": + { + "draworder":"index", + "id":2, + "name":"", + "objects":[ + { + "height":8, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":8, + "x":8, + "y":0 + }, + { + "height":8, + "id":2, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":8, + "x":0, + "y":8 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + } + }, + { + "id":21, + "objectgroup": + { + "draworder":"index", + "id":2, + "name":"", + "objects":[ + { + "height":8, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":8, + "x":8, + "y":8 + }, + { + "height":8, + "id":2, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":8, + "x":0, + "y":0 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + } + }, + { + "id":26, + "objectgroup": + { + "draworder":"index", + "id":3, + "name":"", + "objects":[ + { + "height":8, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":8, + "x":8, + "y":0 + }, + { + "height":8, + "id":2, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":8, + "x":0, + "y":8 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + } + }, + { + "id":27, + "objectgroup": + { + "draworder":"index", + "id":2, + "name":"", + "objects":[ + { + "height":8, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":8, + "x":8, + "y":8 + }, + { + "height":8, + "id":2, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":8, + "x":0, + "y":0 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + } + }, + { + "id":28, + "objectgroup": + { + "draworder":"index", + "id":2, + "name":"", + "objects":[ + { + "height":8, + "id":2, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":8, + "x":0, + "y":8 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + } + }, + { + "id":29, + "objectgroup": + { + "draworder":"index", + "id":2, + "name":"", + "objects":[ + { + "height":8, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":8, + "x":8, + "y":8 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + } + }, + { + "id":30, + "objectgroup": + { + "draworder":"index", + "name":"", + "objects":[ + { + "height":8, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":16, + "x":0, + "y":0 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + } + }, + { + "id":31, + "objectgroup": + { + "draworder":"index", + "name":"", + "objects":[ + { + "height":16, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":8, + "x":0, + "y":0 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + } + }, + { + "id":32, + "objectgroup": + { + "draworder":"index", + "name":"", + "objects":[ + { + "height":16, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":8, + "x":8, + "y":0 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + } + }, + { + "id":37, + "objectgroup": + { + "draworder":"index", + "name":"", + "objects":[ + { + "height":8, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":16, + "x":0, + "y":8 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + } + }, + { + "id":38, + "objectgroup": + { + "draworder":"index", + "name":"", + "objects":[ + { + "height":8, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":16, + "x":0, + "y":8 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + } + }, + { + "id":40, + "objectgroup": + { + "draworder":"index", + "name":"", + "objects":[ + { + "height":8, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":8, + "x":8, + "y":8 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + } + }, + { + "id":41, + "objectgroup": + { + "draworder":"index", + "name":"", + "objects":[ + { + "height":8, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":8, + "x":0, + "y":8 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + } + }, + { + "id":42, + "objectgroup": + { + "draworder":"index", + "name":"", + "objects":[ + { + "height":8, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":16, + "x":0, + "y":8 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + } + }, + { + "id":43, + "objectgroup": + { + "draworder":"index", + "name":"", + "objects":[ + { + "height":8, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":16, + "x":0, + "y":8 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + } + }], "tilewidth":16, "type":"tileset", "version":"1.10", diff --git a/src.bin b/src.bin deleted file mode 100755 index 8fc5bf1..0000000 Binary files a/src.bin and /dev/null differ diff --git a/src/main.odin b/src/main.odin index 2e02f3c..ff794f6 100644 --- a/src/main.odin +++ b/src/main.odin @@ -49,10 +49,17 @@ init :: proc() { tile: tiled.Tile, tile_set: tiled.Tile_Set, ) { - make_platform({ - {f32(x), f32(y)}, - {f32(tile_set.tile_width), f32(tile_set.tile_height)}, - }) + objs, is_object_layer := tile.object_group.layer.(tiled.Object_Layer) + if !is_object_layer { + return + } + + for obj in objs { + make_platform({ + Vec2{f32(x), f32(y)} + obj.position, + obj.size, + }) + } } tiled.iterate_map_tiles(state.room, make_map_collisions) @@ -63,10 +70,9 @@ frame :: proc() { draw.new_frame() - draw_platforms() draw_player(state.player) - tiled.draw_map(state.room) + // draw_platforms() fps_text := fmt.caprintf( "FPS: %v", rl.GetFPS(), diff --git a/src/platform.odin b/src/platform.odin index 674e1a3..306df3b 100644 --- a/src/platform.odin +++ b/src/platform.odin @@ -17,8 +17,10 @@ make_platform :: proc(rect: Rect) -> (Entity_Handle, ^Platform) { draw_platforms :: proc() { iter := iter_entity_list(state.platform_list) + draw.renderer.tint = {1, 0, 0, 0.25} for p in entity_list_iter(&iter) { body := phys.get_body(p.body) draw.rect(cast(draw.Rect)body.rect) } + draw.renderer.tint = {1, 1, 1, 1} } diff --git a/src/tiled/tiled.odin b/src/tiled/tiled.odin index e01f6c5..373715a 100644 --- a/src/tiled/tiled.odin +++ b/src/tiled/tiled.odin @@ -138,7 +138,7 @@ Tile_Set :: struct { tile_height: i32, tile_offset: [2]i32, // in pixels - tiles: []Tile, + tiles: []i32, // array of GIDs } Tile :: struct { @@ -336,8 +336,8 @@ convert_json_map :: proc(jmap: Json_Map, tmap: ^Map, path: string) -> Error { } tmap.tile_sets[i] = tile_set - for j in int(tile_set.first_gid)..