Add tile interactions.

This commit is contained in:
2024-10-05 10:29:15 -05:00
parent bdef59bbe1
commit b7829fda5c
2 changed files with 25 additions and 22 deletions

View File

@ -48,5 +48,15 @@ void playerUpdate(entity_t *entity) {
textboxSetText("NPC", "Hello Player"); textboxSetText("NPC", "Hello Player");
return; 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;
}
} }
} }

View File

@ -9,8 +9,8 @@
#include "rpg/world/map.h" #include "rpg/world/map.h"
#include "assert/assert.h" #include "assert/assert.h"
#define TEST_MAP_WIDTH 50 #define TEST_MAP_WIDTH 16
#define TEST_MAP_HEIGHT 50 #define TEST_MAP_HEIGHT 16
#define TEST_MAP_LAYERS 1 #define TEST_MAP_LAYERS 1
void testMapInit(map_t *map) { void testMapInit(map_t *map) {
@ -20,38 +20,31 @@ void testMapInit(map_t *map) {
entityInit(player, ENTITY_TYPE_PLAYER, map); entityInit(player, ENTITY_TYPE_PLAYER, map);
entityPositionSet(player, 5, 5); entityPositionSet(player, 5, 5);
// entity_t *npc = mapEntityAdd(map); entity_t *npc = mapEntityAdd(map);
// entityInit(npc, ENTITY_TYPE_NPC, map); entityInit(npc, ENTITY_TYPE_NPC, map);
// entityPositionSet(npc, 10, 10); entityPositionSet(npc, 10, 10);
tile_t tiles[TEST_MAP_WIDTH * TEST_MAP_HEIGHT]; tile_t tiles[TEST_MAP_WIDTH * TEST_MAP_HEIGHT];
for(uint32_t i = 0; i < TEST_MAP_WIDTH * TEST_MAP_HEIGHT; i++) { for(uint32_t i = 0; i < TEST_MAP_WIDTH * TEST_MAP_HEIGHT; i++) {
tiles[i].id = TILE_ID_GRASS; tiles[i].id = TILE_ID_GRASS;
} }
tiles[10].id = TILE_ID_WATER;
tiles[11].id = TILE_ID_WATER; tiles[11].id = TILE_ID_WATER;
tiles[12].id = TILE_ID_WATER; tiles[12].id = TILE_ID_WATER;
tiles[13].id = TILE_ID_WATER; tiles[13].id = TILE_ID_WATER;
tiles[14].id = TILE_ID_WATER; tiles[14].id = TILE_ID_WATER;
tiles[15].id = TILE_ID_WATER;
// tiles[30].id = TILE_ID_WATER; tiles[26].id = TILE_ID_WATER;
// tiles[31].id = TILE_ID_WATER; tiles[27].id = TILE_ID_WATER;
// tiles[32].id = TILE_ID_WATER; tiles[28].id = TILE_ID_WATER;
// tiles[33].id = TILE_ID_WATER; tiles[29].id = TILE_ID_WATER;
// tiles[34].id = TILE_ID_WATER;
// tiles[35].id = TILE_ID_WATER;
// tiles[50].id = TILE_ID_WATER; tiles[41].id = TILE_ID_WATER;
// tiles[51].id = TILE_ID_WATER; tiles[42].id = TILE_ID_WATER;
// tiles[52].id = TILE_ID_WATER; tiles[43].id = TILE_ID_WATER;
// tiles[53].id = TILE_ID_WATER; tiles[44].id = TILE_ID_WATER;
tiles[45].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;
mapTilesSet(map, tiles, 0); mapTilesSet(map, tiles, 0);
} }