From 48f1f44b5b589bd3cecf0c902ff078f40aa0e1e1 Mon Sep 17 00:00:00 2001 From: mibi88 <76903855+mibi88@users.noreply.github.com> Date: Wed, 31 Jul 2024 21:57:37 +0200 Subject: [PATCH 1/2] Converting portals. Not tested yet. --- CMakeLists.txt | 2 ++ assets/converters.py | 34 +++++++++++++++++++-- assets/fxconv-metadata.txt | 8 +++++ assets/{interior1-0.tmx => interior1_0.tmx} | 16 +++++----- assets/interior1_0_dialogs.json | 13 ++++++++ assets/level0.tmx | 8 ++++- assets/tinytiled | 2 +- src/game.h | 10 +++--- 8 files changed, 75 insertions(+), 18 deletions(-) rename assets/{interior1-0.tmx => interior1_0.tmx} (74%) create mode 100644 assets/interior1_0_dialogs.json diff --git a/CMakeLists.txt b/CMakeLists.txt index e00662b..e3c55a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,8 @@ set(ASSETS assets/level2.tmx assets/level3.tmx assets/level4.tmx + assets/interior1_0_dialogs.json + assets/interior1_0.tmx # ... ) diff --git a/assets/converters.py b/assets/converters.py index 95d2799..3d97807 100644 --- a/assets/converters.py +++ b/assets/converters.py @@ -69,6 +69,9 @@ def convert_map(input: str, output: str, params: dict, target): npc_paths = {} npcs = {} signs = {} + portals = {} + + name = os.path.splitext(os.path.basename(input))[0] map_struct = fxconv.Structure() @@ -226,6 +229,17 @@ def convert_map(input: str, output: str, params: dict, target): "icon": SIGN_TYPES.index(object.type) } signs[object.id] = data + # Get the portals + for object in ed_objgroup.objects: + if (object.get_data_type() == "rectangle" + and object.type == "PORTAL"): + data = { + "rect": object.get_data(), + "name": object.name, + "dest": object.get_property("dest"), + "destPortal": object.get_property("destPortal") + } + portals[object.id] = data except Exception as e: # Show a simple error message on failure. sys.stderr.write(f"ERROR: Failed to get the extra data.\n" @@ -297,8 +311,23 @@ def convert_map(input: str, output: str, params: dict, target): sign_struct += fxconv.u32(i["needAction"]) map_struct += fxconv.ptr(sign_struct) # Load portals - map_struct += fxconv.u32(0) # TODO: Portal support in-game - map_struct += fxconv.ptr(bytes()) + map_struct += fxconv.u32(len(portals)) + portal_struct = fxconv.Structure() + for i in portals.values(): + dest_file_name = os.path.splitext(os.path.basename(i["dest"]))[0] + dest_portal = i["destPortal"] + portal_name = i["name"] + if VERBOSE: print(f"INFO: Storing portal {name}_{portal_name}") + portal_struct += fxconv.sym(f"{name}_{portal_name}") + # Add the collider + rect = i["rect"] + portal_struct += fxconv.u32(rect[0]) + portal_struct += fxconv.u32(rect[1]) + portal_struct += fxconv.u32(rect[2]) + portal_struct += fxconv.u32(rect[3]) + # Add a reference to the destination portal + portal_struct += fxconv.ref(f"{dest_file_name}_{dest_portal}") + map_struct += fxconv.ptr(portal_struct) map_struct += fxconv.u32(dialog_num) # Get the name of the dialog file and create a reference to it: it is built @@ -319,7 +348,6 @@ def convert_map(input: str, output: str, params: dict, target): map_struct += fxconv.ptr(foreground_data) # Create the fxconv object - name = os.path.splitext(os.path.basename(input))[0] fxconv.elf(map_struct, output, f"_{name}", **target) def convert_dialog(input: str, output: str, params: dict, target): diff --git a/assets/fxconv-metadata.txt b/assets/fxconv-metadata.txt index 423d18e..9a82591 100644 --- a/assets/fxconv-metadata.txt +++ b/assets/fxconv-metadata.txt @@ -37,3 +37,11 @@ level3_dialogs.json: level4_dialogs.json: custom-type: dialog name: level4_dialogs + +interior1_0.tmx: + custom-type: tmx + name: level0 + +interior1_0_dialogs.json: + custom-type: dialog + name: interior1_0_dialogs diff --git a/assets/interior1-0.tmx b/assets/interior1_0.tmx similarity index 74% rename from assets/interior1-0.tmx rename to assets/interior1_0.tmx index 3456a8b..e40d41a 100644 --- a/assets/interior1-0.tmx +++ b/assets/interior1_0.tmx @@ -1,5 +1,10 @@ - + + + + + + @@ -39,14 +44,11 @@ - + - - - - + + - diff --git a/assets/interior1_0_dialogs.json b/assets/interior1_0_dialogs.json new file mode 100644 index 0000000..f503523 --- /dev/null +++ b/assets/interior1_0_dialogs.json @@ -0,0 +1,13 @@ +{ "dialogs":[ + { "ID":0, + "dialog":"_", + "isQuestion":0, + "choice":"_", + "conclusion1":"_", + "next1":-1, + "conclusion2":"_", + "next2":-1, + "nextOther":1 + } + ] +} diff --git a/assets/level0.tmx b/assets/level0.tmx index 0b21923..6bc62a8 100644 --- a/assets/level0.tmx +++ b/assets/level0.tmx @@ -1,5 +1,5 @@ - + @@ -173,5 +173,11 @@ + + + + + + diff --git a/assets/tinytiled b/assets/tinytiled index f426664..b084ecd 160000 --- a/assets/tinytiled +++ b/assets/tinytiled @@ -1 +1 @@ -Subproject commit f426664f4444d4c8a6054bc7b69fb676ed43bcaa +Subproject commit b084ecda91a2352a72a5d1a61b37e0009228ee40 diff --git a/src/game.h b/src/game.h index 992d0bd..3a5f71c 100644 --- a/src/game.h +++ b/src/game.h @@ -12,8 +12,8 @@ typedef enum { D_UP, D_DOWN, D_LEFT, D_RIGHT } Direction; typedef enum { P_LEFTUP = -1, P_CENTER = 0, P_RIGHTDOWN = 1 } Checkpos; typedef struct { - uint32_t x, y; - uint32_t w, h; + uint32_t x1, y1; + uint32_t x2, y2; } Collider; @@ -109,10 +109,8 @@ typedef struct { typedef struct { Collider collider; - /*if the portal tps to an interior or exterior map*/ - uint16_t tp_interior; - /*Id of the interior/exterior map to transport the player to*/ - uint16_t tp_to; + /* The destination portal */ + void *portal; } Portal; typedef struct { From a3d0ca40c1241d4e9214fd1874ede71dccb0c96b Mon Sep 17 00:00:00 2001 From: mibi88 <76903855+mibi88@users.noreply.github.com> Date: Wed, 31 Jul 2024 22:21:34 +0200 Subject: [PATCH 2/2] Added portal support --- assets/converters.py | 1 + assets/interior1_0.tmx | 10 +++++----- src/game.c | 43 +++++++++++++++++++++++++++++++++++++----- src/game.h | 2 ++ 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/assets/converters.py b/assets/converters.py index 3d97807..63d6de5 100644 --- a/assets/converters.py +++ b/assets/converters.py @@ -327,6 +327,7 @@ def convert_map(input: str, output: str, params: dict, target): portal_struct += fxconv.u32(rect[3]) # Add a reference to the destination portal portal_struct += fxconv.ref(f"{dest_file_name}_{dest_portal}") + portal_struct += fxconv.ref(f"{dest_file_name}") map_struct += fxconv.ptr(portal_struct) map_struct += fxconv.u32(dialog_num) diff --git a/assets/interior1_0.tmx b/assets/interior1_0.tmx index e40d41a..cca09fa 100644 --- a/assets/interior1_0.tmx +++ b/assets/interior1_0.tmx @@ -14,9 +14,9 @@ 86,93,94,1,1,1,1,1,9,10,1,92, 110,117,118,1,1,1,1,1,33,34,1,116, 86,1,1,1,1,1,1,1,1,1,1,92, -110,1,1,1,1,1,1,1,1,1,1,116, -110,1,1,1,1,133,2,1,1,1,1,92, -110,1,1,1,1,2,2,1,1,1,1,116 +110,1,1,1,1,133,2,1,1,1,1,116, +110,1,1,1,1,2,2,1,1,1,1,92, +110,114,114,114,114,114,114,114,114,114,114,116 @@ -40,11 +40,11 @@ 410,0,0,0,0,0,0,0,0,0,0,410, 410,0,0,0,0,0,0,0,0,0,0,410, 410,0,0,0,0,0,0,0,0,0,0,410, -410,0,0,0,0,0,0,0,0,0,0,410 +410,410,410,410,410,410,410,410,410,410,410,410 - + diff --git a/src/game.c b/src/game.c index 88686bf..47a6be0 100644 --- a/src/game.c +++ b/src/game.c @@ -82,11 +82,20 @@ void game_logic(Game *game) { void game_render_indicator(Game *game) { /* nothing to do for the player so we quit */ - if(game->player.canDoSomething == false) - return; - - /* else we draw a small indicator on the screen */ - dimage(5, 5, &SignAction_img); + if(game->player.canDoSomething) + dimage(5, 5, &SignAction_img); + int i; + Player *player = &game->player; + for(i=0;imap_level->nbPortal;i++){ + Portal *portal = &game->map_level->portals[i]; + if(player->x >= portal->collider.x1*PXSIZE && + player->x < portal->collider.x2*PXSIZE && + player->y >= portal->collider.y1*PXSIZE && + player->y < portal->collider.y2*PXSIZE){ + dimage(5, 5, &SignAction_img); + break; + } + } } void game_draw(Game *game) { @@ -100,6 +109,7 @@ void game_draw(Game *game) { /*DEBUG*/ dprint(8, 8, C_BLACK, "Lifes: %d", game->player.life); dprint(8, 16, C_BLACK, "Mana: %d", game->mana); + dprint(8, 24, C_BLACK, "X: %d Y: %d", game->player.x, game->player.y); } /* Key management */ @@ -133,6 +143,29 @@ void game_get_inputs(Game *game) { sleep(); } } + Player *player = &game->player; + if(keydown(KEY_SHIFT)){ + int i; + for(i=0;imap_level->nbPortal;i++){ + Portal *portal = &game->map_level->portals[i]; + if(player->x >= portal->collider.x1*PXSIZE && + player->x < portal->collider.x2*PXSIZE && + player->y >= portal->collider.y1*PXSIZE && + player->y < portal->collider.y2*PXSIZE){ + Portal *dest_portal = (Portal*)portal->portal; + Collider dest_collider = dest_portal->collider; + Map *dest_map = (Map*)portal->map; + player->x = (dest_collider.x1+dest_collider.x2)/2*PXSIZE; + player->y = (dest_collider.y1+dest_collider.y2)/2*PXSIZE; + game->map_level = dest_map; + /* TODO: Make something cleaner */ + while(keydown(KEY_SHIFT)) { + clearevents(); + sleep(); + } + } + } + } /* Display Debug Information on screen */ #if DEBUGMODE diff --git a/src/game.h b/src/game.h index 3a5f71c..c1ef0a9 100644 --- a/src/game.h +++ b/src/game.h @@ -111,6 +111,8 @@ typedef struct { Collider collider; /* The destination portal */ void *portal; + /* The destination map */ + void *map; } Portal; typedef struct {