diff options
| -rw-r--r-- | res/tileset.tsj | 626 | ||||
| -rwxr-xr-x | src.bin | bin | 2391800 -> 0 bytes | |||
| -rw-r--r-- | src/main.odin | 18 | ||||
| -rw-r--r-- | src/platform.odin | 2 | ||||
| -rw-r--r-- | src/tiled/tiled.odin | 26 |
5 files changed, 658 insertions, 14 deletions
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 Binary files differdeleted file mode 100755 index 8fc5bf1..0000000 --- a/src.bin +++ /dev/null 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)..<len(tmap.tiles) { - tile_set.tiles[j].tile_set = i32(i) + for j in 0..<len(tmap.tiles) { + tmap.tiles[int(tile_set.first_gid) + j].tile_set = i32(i) } } @@ -577,7 +577,7 @@ convert_json_tile_set :: proc( tile_set.properties = convert_json_properties(jtile_set.properties) - tile_set.tiles = make([]Tile, jtile_set.tilecount) + tile_set.tiles = make([]i32, jtile_set.tilecount) // Ignore margin and spacing for now // TODO: account for margin and spacing @@ -587,7 +587,7 @@ convert_json_tile_set :: proc( current_index := 0 for y in 0..<tile_y { for x in 0..<tile_x { - tile := &tile_set.tiles[current_index] + tile: Tile tile.id = i32(current_index) @@ -600,14 +600,24 @@ convert_json_tile_set :: proc( tile_set.tile_height, } + current_index += 1 + tile.gid = i32(len(tmap.tiles)) - append(&tmap.tiles, tile^) + append(&tmap.tiles, tile) - current_index += 1 + tile_set.tiles[current_index - 1] = tile.gid } } - // TODO: here, go through jtile_set.tiles and load in more tile data + for jtile in jtile_set.tiles { + ttile := &tmap.tiles[tile_set.tiles[jtile.id]] + object_group, err := convert_json_layer(jtile.objectgroup) + if err != .NONE { + return {}, err + } + ttile.object_group = object_group + ttile.properties = convert_json_properties(jtile.properties) + } return tile_set, .NONE } |
