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] 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 {