From b7829fda5cca98f7aba8c0db568b7baeedff955c Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sat, 5 Oct 2024 10:29:15 -0500 Subject: [PATCH] Add tile interactions. --- src/dawn/rpg/entity/player.c | 10 +++++++++ src/dawn/rpg/world/maps/testmap.h | 37 +++++++++++++------------------ 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/dawn/rpg/entity/player.c b/src/dawn/rpg/entity/player.c index 96b694c5..5e87f9f3 100644 --- a/src/dawn/rpg/entity/player.c +++ b/src/dawn/rpg/entity/player.c @@ -48,5 +48,15 @@ void playerUpdate(entity_t *entity) { textboxSetText("NPC", "Hello Player"); return; } + + tile_t tile = mapTileGetByPosition(entity->map, x, y, 0); + switch(tile.id) { + case TILE_ID_WATER: + textboxSetText(NULL, "You cannot swim."); + entity->state = ENTITY_STATE_TALKING; + return; + default: + break; + } } } \ No newline at end of file diff --git a/src/dawn/rpg/world/maps/testmap.h b/src/dawn/rpg/world/maps/testmap.h index 8761d6a0..98750844 100644 --- a/src/dawn/rpg/world/maps/testmap.h +++ b/src/dawn/rpg/world/maps/testmap.h @@ -9,8 +9,8 @@ #include "rpg/world/map.h" #include "assert/assert.h" -#define TEST_MAP_WIDTH 50 -#define TEST_MAP_HEIGHT 50 +#define TEST_MAP_WIDTH 16 +#define TEST_MAP_HEIGHT 16 #define TEST_MAP_LAYERS 1 void testMapInit(map_t *map) { @@ -20,38 +20,31 @@ void testMapInit(map_t *map) { entityInit(player, ENTITY_TYPE_PLAYER, map); entityPositionSet(player, 5, 5); - // entity_t *npc = mapEntityAdd(map); - // entityInit(npc, ENTITY_TYPE_NPC, map); - // entityPositionSet(npc, 10, 10); + entity_t *npc = mapEntityAdd(map); + entityInit(npc, ENTITY_TYPE_NPC, map); + entityPositionSet(npc, 10, 10); tile_t tiles[TEST_MAP_WIDTH * TEST_MAP_HEIGHT]; for(uint32_t i = 0; i < TEST_MAP_WIDTH * TEST_MAP_HEIGHT; i++) { tiles[i].id = TILE_ID_GRASS; } + tiles[10].id = TILE_ID_WATER; tiles[11].id = TILE_ID_WATER; tiles[12].id = TILE_ID_WATER; tiles[13].id = TILE_ID_WATER; tiles[14].id = TILE_ID_WATER; - tiles[15].id = TILE_ID_WATER; - // tiles[30].id = TILE_ID_WATER; - // tiles[31].id = TILE_ID_WATER; - // tiles[32].id = TILE_ID_WATER; - // tiles[33].id = TILE_ID_WATER; - // tiles[34].id = TILE_ID_WATER; - // tiles[35].id = TILE_ID_WATER; + tiles[26].id = TILE_ID_WATER; + tiles[27].id = TILE_ID_WATER; + tiles[28].id = TILE_ID_WATER; + tiles[29].id = TILE_ID_WATER; - // tiles[50].id = TILE_ID_WATER; - // tiles[51].id = TILE_ID_WATER; - // tiles[52].id = TILE_ID_WATER; - // tiles[53].id = TILE_ID_WATER; - - // tiles[70].id = TILE_ID_WATER; - // tiles[71].id = TILE_ID_WATER; - // tiles[72].id = TILE_ID_WATER; - // tiles[73].id = TILE_ID_WATER; - + tiles[41].id = TILE_ID_WATER; + tiles[42].id = TILE_ID_WATER; + tiles[43].id = TILE_ID_WATER; + tiles[44].id = TILE_ID_WATER; + tiles[45].id = TILE_ID_WATER; mapTilesSet(map, tiles, 0); } \ No newline at end of file