From d084e4dba38fcea5888cb63732d7903a21935fe4 Mon Sep 17 00:00:00 2001 From: Nyeogmi Date: Wed, 28 Feb 2024 13:14:48 -0800 Subject: [PATCH] Player spawn point --- game/BUILD | 1 + game/game.c | 2 + game/game_player.c | 2 + game/map/game_map.h | 2 + game/map/game_map.ldtk | 142 ++++++++++++++++++++++++++++++++++- game/map/game_map_entities.c | 12 +++ pytools/mapdata.py | 23 +++++- 7 files changed, 179 insertions(+), 5 deletions(-) create mode 100644 game/map/game_map_entities.c diff --git a/game/BUILD b/game/BUILD index e6e1b32..ccc0ca6 100644 --- a/game/BUILD +++ b/game/BUILD @@ -6,6 +6,7 @@ cc_library( "art/game_player.c", "art/game_tiles.c", "map/game_map.c", + "map/game_map_entities.c", ], hdrs = glob(["*.h", "art/*.h", "map/*.h"]), visibility = ["//visibility:public"], diff --git a/game/game.c b/game/game.c index 944bdc4..a6ee00c 100644 --- a/game/game.c +++ b/game/game.c @@ -15,6 +15,8 @@ const char* game_title() { void game_init() { sys_init(); + map_game_map_create_entities(); + game_palette_init(); game_player_init(); } diff --git a/game/game_player.c b/game/game_player.c index 67761bd..c10b7e3 100644 --- a/game/game_player.c +++ b/game/game_player.c @@ -33,6 +33,8 @@ void game_player_anim_transition(game_player_anim anim); void game_player_anim_add_progress(uint8_t amt); void game_player_init() { + game_player_bbox.x = game_map_player_start_x; + game_player_bbox.y = game_map_player_start_y; } void game_player_update() { diff --git a/game/map/game_map.h b/game/map/game_map.h index a75e12d..138d0de 100644 --- a/game/map/game_map.h +++ b/game/map/game_map.h @@ -1,11 +1,13 @@ #ifndef CROCPARTY_GAME_MAP_H #define CROCPARTY_GAME_MAP_H +#include "game/game_collision.h" #include "sys/sys.h" extern sys_i32 game_map_player_start_x; extern sys_i32 game_map_player_start_y; extern sys_map map_game_map; +void map_game_map_create_entities(); #endif diff --git a/game/map/game_map.ldtk b/game/map/game_map.ldtk index 0c45a02..2864714 100644 --- a/game/map/game_map.ldtk +++ b/game/map/game_map.ldtk @@ -11,7 +11,7 @@ "iid": "7db5fd20-b0a0-11ee-9688-af2c6adbc1d6", "jsonVersion": "1.5.3", "appBuildId": 473703, - "nextUid": 108, + "nextUid": 110, "identifierStyle": "Lowercase", "toc": [], "worldLayout": "Free", @@ -3301,8 +3301,79 @@ "tilePivotX": 0, "tilePivotY": 0, "biomeFieldUid": null + }, + { + "__type": "Entities", + "identifier": "entities", + "type": "Entities", + "uid": 109, + "doc": null, + "uiColor": null, + "gridSize": 8, + "guideGridWid": 0, + "guideGridHei": 0, + "displayOpacity": 1, + "inactiveOpacity": 0.6, + "hideInList": false, + "hideFieldsWhenInactive": true, + "canSelectWhenInactive": true, + "renderInWorldView": true, + "pxOffsetX": 0, + "pxOffsetY": 0, + "parallaxFactorX": 0, + "parallaxFactorY": 0, + "parallaxScaling": true, + "requiredTags": [], + "excludedTags": [], + "autoTilesKilledByOtherLayerUid": null, + "uiFilterTags": [], + "useAsyncRender": false, + "intGridValues": [], + "intGridValuesGroups": [], + "autoRuleGroups": [], + "autoSourceLayerDefUid": null, + "tilesetDefUid": null, + "tilePivotX": 0, + "tilePivotY": 0, + "biomeFieldUid": null } - ], "entities": [], "tilesets": [ + ], "entities": [ + { + "identifier": "player_spawn", + "uid": 108, + "tags": [], + "exportToToc": false, + "allowOutOfBounds": false, + "doc": null, + "width": 16, + "height": 16, + "resizableX": false, + "resizableY": false, + "minWidth": null, + "maxWidth": null, + "minHeight": null, + "maxHeight": null, + "keepAspectRatio": false, + "tileOpacity": 1, + "fillOpacity": 1, + "lineOpacity": 1, + "hollow": false, + "color": "#BE4A2F", + "renderMode": "Rectangle", + "showName": true, + "tilesetId": null, + "tileRenderMode": "FitInside", + "tileRect": null, + "uiTileRect": null, + "nineSliceBorders": [], + "maxCount": 1, + "limitScope": "PerWorld", + "limitBehavior": "MoveLastOne", + "pivotX": 0, + "pivotY": 0, + "fieldDefs": [] + } + ], "tilesets": [ { "__cWid": 6, "__cHei": 20, @@ -3761,6 +3832,48 @@ "overrideTilesetUid": null, "gridTiles": [], "entityInstances": [] + }, + { + "__identifier": "entities", + "__type": "Entities", + "__cWid": 32, + "__cHei": 18, + "__gridSize": 8, + "__opacity": 1, + "__pxTotalOffsetX": 0, + "__pxTotalOffsetY": 0, + "__tilesetDefUid": null, + "__tilesetRelPath": null, + "iid": "658f1a30-b0a0-11ee-9688-d595f6278eea", + "levelId": 0, + "layerDefUid": 109, + "pxOffsetX": 0, + "pxOffsetY": 0, + "visible": true, + "optionalRules": [], + "intGridCsv": [], + "autoLayerTiles": [], + "seed": 9915028, + "overrideTilesetUid": null, + "gridTiles": [], + "entityInstances": [ + { + "__identifier": "player_spawn", + "__grid": [15,7], + "__pivot": [0,0], + "__tags": [], + "__tile": null, + "__smartColor": "#BE4A2F", + "iid": "86fd73b0-b0a0-11ee-9688-65c9ba3d6485", + "width": 16, + "height": 16, + "defUid": 108, + "px": [120,56], + "fieldInstances": [], + "__worldX": 120, + "__worldY": 56 + } + ] } ], "__neighbours": [{ "levelIid": "bf0dd810-b0a0-11ee-9688-3daed338bb0b", "dir": "e" }] @@ -4097,6 +4210,31 @@ "overrideTilesetUid": null, "gridTiles": [], "entityInstances": [] + }, + { + "__identifier": "entities", + "__type": "Entities", + "__cWid": 32, + "__cHei": 18, + "__gridSize": 8, + "__opacity": 1, + "__pxTotalOffsetX": 0, + "__pxTotalOffsetY": 0, + "__tilesetDefUid": null, + "__tilesetRelPath": null, + "iid": "658f1a31-b0a0-11ee-9688-135042e10920", + "levelId": 107, + "layerDefUid": 109, + "pxOffsetX": 0, + "pxOffsetY": 0, + "visible": true, + "optionalRules": [], + "intGridCsv": [], + "autoLayerTiles": [], + "seed": 8688237, + "overrideTilesetUid": null, + "gridTiles": [], + "entityInstances": [] } ], "__neighbours": [{ "levelIid": "7db5fd22-b0a0-11ee-9688-e77df1dfa284", "dir": "w" }] diff --git a/game/map/game_map_entities.c b/game/map/game_map_entities.c new file mode 100644 index 0000000..7dbfc9c --- /dev/null +++ b/game/map/game_map_entities.c @@ -0,0 +1,12 @@ +#include "sys/sys.h" +#include "game_map.h" + +sys_i32 game_map_player_start_x; +sys_i32 game_map_player_start_y; + +// called by map_game_map_create_entities +void map_game_map_player_spawn_create(sys_i32 x, sys_i32 y) { + // center, because the entity has top-left positioning + game_map_player_start_x = x * TILE_SZ_MICROPIXEL + PIXEL_SZ_MICROPIXEL * 8; + game_map_player_start_y = y * TILE_SZ_MICROPIXEL + PIXEL_SZ_MICROPIXEL * 16; +} diff --git a/pytools/mapdata.py b/pytools/mapdata.py index d941624..e32fa3f 100644 --- a/pytools/mapdata.py +++ b/pytools/mapdata.py @@ -12,10 +12,20 @@ sys_map map_{{map_name}} = { .width={{width}}, .height={{height}}, }; + +{% for entity_type in entity_types %} +void map_{{map_name}}_{{entity_type}}_create(sys_i32 x, sys_i32 y); +{% endfor %} + +void map_{{map_name}}_create_entities() { + {% for entity in entities %} + map_{{map_name}}_{{entity.type}}_create({{entity.x}}, {{entity.y}}); + {% endfor %} +} """.lstrip() def main(map_name, fname_ldtk, fname_c): - width, height, tiles = load_mapdata(fname_ldtk) + width, height, tiles, entities = load_mapdata(fname_ldtk) with open(fname_c, "wt") as output: output.write( @@ -24,6 +34,8 @@ def main(map_name, fname_ldtk, fname_c): tiles=tiles, width=width, height=height, + entity_types=sorted(set(i["type"] for i in entities)), + entities=entities, ) ) @@ -49,7 +61,12 @@ def load_mapdata(fname_ldtk): if layer["__identifier"] == "entities": for e in layer["entityInstances"]: - raise NotImplementedError() + # TODO: Other fields? + entities.append({ + "type": e["__identifier"], + "x": e["__worldX"] // 8, + "y": e["__worldY"] // 8, + }) x_min = 0 y_min = 0 @@ -66,7 +83,7 @@ def load_mapdata(fname_ldtk): else: dense_tiles.append(255) - return width, height, dense_tiles + return width, height, dense_tiles, entities def annot_xy(lst, w, h):