Bit more cleanup
This commit is contained in:
		| @@ -67,9 +67,7 @@ void assetMapLoad( | ||||
|     ); | ||||
|  | ||||
|     for(int32_t j = 0; j < width * height; j++) { | ||||
|       map->tiles[j] = (tile_t){ | ||||
|         .id = (uint16_t)tiles->array.value[j]->number | ||||
|       }; | ||||
|       map->tiles[j] = (tile_t)tiles->array.value[j]->number; | ||||
|     } | ||||
|   } | ||||
|  | ||||
| @@ -90,7 +88,9 @@ void assetMapLoad( | ||||
|  | ||||
|       int32_t x = (int32_t)assetJsonGetObjectValue(jEnt, "x")->number; | ||||
|       int32_t y = (int32_t)assetJsonGetObjectValue(jEnt, "y")->number; | ||||
|       uint8_t type = (uint8_t)assetJsonGetObjectValue(jEnt, "type")->number; | ||||
|       entitytype_t type = (entitytype_t)assetJsonGetObjectValue( | ||||
|         jEnt, "type" | ||||
|       )->number; | ||||
|  | ||||
|       entity_t *ent = mapEntityAdd(map); | ||||
|       entityInit(ent, type, map); | ||||
| @@ -118,8 +118,12 @@ void assetMapLoad( | ||||
|       int32_t x = (int32_t)assetJsonGetObjectValue(jTrig, "x")->number; | ||||
|       int32_t y = (int32_t)assetJsonGetObjectValue(jTrig, "y")->number; | ||||
|       int32_t width = (int32_t)assetJsonGetObjectValue(jTrig, "width")->number; | ||||
|       int32_t height = (int32_t)assetJsonGetObjectValue(jTrig, "height")->number; | ||||
|       uint8_t type = (uint8_t)assetJsonGetObjectValue(jTrig, "type")->number; | ||||
|       int32_t height = (int32_t)assetJsonGetObjectValue( | ||||
|         jTrig, "height" | ||||
|       )->number; | ||||
|       triggertype_t type = (triggertype_t)assetJsonGetObjectValue( | ||||
|         jTrig, "type" | ||||
|       )->number; | ||||
|  | ||||
|       trigger_t *trigger = mapTriggerAdd(map); | ||||
|       triggerInit(trigger, type, x, y, width, height); | ||||
|   | ||||
| @@ -23,7 +23,7 @@ char_t symbolGetCharByEntity(const entity_t *ent) { | ||||
| } | ||||
|  | ||||
| char_t symbolGetCharByTile(const tile_t tile) { | ||||
|   switch(tile.id) { | ||||
|   switch(tile) { | ||||
|     case TILE_ID_GRASS: | ||||
|       return '#'; | ||||
|  | ||||
| @@ -56,7 +56,7 @@ uint8_t symbolGetColorByEntity(const entity_t *ent) { | ||||
| } | ||||
|  | ||||
| uint8_t symbolGetColorByTile(const tile_t tile) { | ||||
|   switch(tile.id) { | ||||
|   switch(tile) { | ||||
|     case TILE_ID_GRASS: | ||||
|       return COLOR_GREEN; | ||||
|  | ||||
|   | ||||
| @@ -14,7 +14,7 @@ | ||||
|  | ||||
| void entityInit( | ||||
|   entity_t *entity, | ||||
|   const uint8_t type, | ||||
|   const entitytype_t type, | ||||
|   map_t *map | ||||
| ) { | ||||
|   assertNotNull(entity, "Entity cannot be NULL."); | ||||
|   | ||||
| @@ -8,9 +8,11 @@ | ||||
| #pragma once | ||||
| #include "player.h" | ||||
|  | ||||
| #define ENTITY_TYPE_NULL 0 | ||||
| #define ENTITY_TYPE_PLAYER 1 | ||||
| #define ENTITY_TYPE_NPC 2 | ||||
| typedef enum { | ||||
|   ENTITY_TYPE_NULL = 0, | ||||
|   ENTITY_TYPE_PLAYER = 1, | ||||
|   ENTITY_TYPE_NPC = 2 | ||||
| } entitytype_t; | ||||
|  | ||||
| #define ENTITY_STATE_IDLE 0 | ||||
| #define ENTITY_STATE_WALKING 1 | ||||
| @@ -24,7 +26,7 @@ typedef struct { | ||||
|  | ||||
| typedef struct _entity_t { | ||||
|   map_t *map; | ||||
|   uint8_t type; | ||||
|   entitytype_t type; | ||||
|   uint16_t x; | ||||
|   uint16_t y; | ||||
|   uint8_t layer; | ||||
| @@ -50,7 +52,7 @@ typedef struct _entity_t { | ||||
|  */ | ||||
| void entityInit( | ||||
|   entity_t *entity, | ||||
|   const uint8_t type, | ||||
|   const entitytype_t type, | ||||
|   map_t *map | ||||
| ); | ||||
|  | ||||
|   | ||||
| @@ -8,7 +8,11 @@ | ||||
| #include "entitydirection.h" | ||||
| #include "assert/assert.h" | ||||
|  | ||||
| void entityDirectionOffsetGet(const uint8_t dir, uint16_t *x, uint16_t *y) { | ||||
| void entityDirectionOffsetGet( | ||||
|   const entitydirection_t dir, | ||||
|   uint16_t *x, | ||||
|   uint16_t *y | ||||
| ) { | ||||
|   switch(dir) { | ||||
|     case ENTITY_DIRECTION_SOUTH: | ||||
|       *x = 0; | ||||
| @@ -31,7 +35,11 @@ void entityDirectionOffsetGet(const uint8_t dir, uint16_t *x, uint16_t *y) { | ||||
|   } | ||||
| } | ||||
|  | ||||
| void entityDirectionOffsetAdd(const uint8_t dir, uint16_t *x, uint16_t *y) { | ||||
| void entityDirectionOffsetAdd( | ||||
|   const entitydirection_t dir, | ||||
|   uint16_t *x, | ||||
|   uint16_t *y | ||||
| ) { | ||||
|   switch(dir) { | ||||
|     case ENTITY_DIRECTION_SOUTH: | ||||
|       *y += 1; | ||||
| @@ -50,7 +58,7 @@ void entityDirectionOffsetAdd(const uint8_t dir, uint16_t *x, uint16_t *y) { | ||||
|   } | ||||
| } | ||||
|  | ||||
| uint8_t entityDirectionLookAt( | ||||
| entitydirection_t entityDirectionLookAt( | ||||
|   const uint16_t srcX, const uint16_t srcY, | ||||
|   const uint16_t trgX, const uint16_t trgY | ||||
| ) { | ||||
|   | ||||
| @@ -8,10 +8,12 @@ | ||||
| #pragma once | ||||
| #include "dawn.h" | ||||
|  | ||||
| #define ENTITY_DIRECTION_SOUTH 0 | ||||
| #define ENTITY_DIRECTION_NORTH 1 | ||||
| #define ENTITY_DIRECTION_WEST 2 | ||||
| #define ENTITY_DIRECTION_EAST 3 | ||||
| typedef enum { | ||||
|   ENTITY_DIRECTION_SOUTH = 0, | ||||
|   ENTITY_DIRECTION_NORTH = 1, | ||||
|   ENTITY_DIRECTION_WEST = 2, | ||||
|   ENTITY_DIRECTION_EAST = 3 | ||||
| } entitydirection_t; | ||||
|  | ||||
| /** | ||||
|  * Returns the offset for a given direction. | ||||
| @@ -20,7 +22,11 @@ | ||||
|  * @param x Pointer to store x offset. | ||||
|  * @param y Pointer to store y offset. | ||||
|  */ | ||||
| void entityDirectionOffsetGet(const uint8_t dir, uint16_t *x, uint16_t *y); | ||||
| void entityDirectionOffsetGet( | ||||
|   const entitydirection_t dir, | ||||
|   uint16_t *x, | ||||
|   uint16_t *y | ||||
| ); | ||||
|  | ||||
| /** | ||||
|  * Adds the offset for a given direction to the given x and y. | ||||
| @@ -29,7 +35,11 @@ void entityDirectionOffsetGet(const uint8_t dir, uint16_t *x, uint16_t *y); | ||||
|  * @param x Pointer to add x offset to. | ||||
|  * @param y Pointer to add y offset to. | ||||
|  */ | ||||
| void entityDirectionOffsetAdd(const uint8_t dir, uint16_t *x, uint16_t *y); | ||||
| void entityDirectionOffsetAdd( | ||||
|   const entitydirection_t dir, | ||||
|   uint16_t *x, | ||||
|   uint16_t *y | ||||
| ); | ||||
|  | ||||
| /** | ||||
|  * Returns the direction to look at from one point to another. | ||||
| @@ -40,7 +50,7 @@ void entityDirectionOffsetAdd(const uint8_t dir, uint16_t *x, uint16_t *y); | ||||
|  * @param trgY Target Y position. | ||||
|  * @return Direction to look at. | ||||
|  */ | ||||
| uint8_t entityDirectionLookAt( | ||||
| entitydirection_t entityDirectionLookAt( | ||||
|   const uint16_t srcX, const uint16_t srcY, | ||||
|   const uint16_t trgX, const uint16_t trgY | ||||
| ); | ||||
| @@ -51,7 +51,7 @@ void playerUpdate(entity_t *entity) { | ||||
|     } | ||||
|  | ||||
|     tile_t tile = mapTileGetByPosition(entity->map, x, y, 0); | ||||
|     switch(tile.id) { | ||||
|     switch(tile) { | ||||
|       case TILE_ID_WATER: | ||||
|         textboxSetText(NULL, "You cannot swim."); | ||||
|         entity->state = ENTITY_STATE_TALKING; | ||||
|   | ||||
| @@ -84,7 +84,7 @@ entity_t * mapEntityGetByPosition( | ||||
|  | ||||
| entity_t * mapEntityGetByType( | ||||
|   map_t *map, | ||||
|   const uint8_t type | ||||
|   const entitytype_t type | ||||
| ) { | ||||
|   for(uint8_t i = 0; i < map->entityCount; i++) { | ||||
|     entity_t *entity = &map->entities[i]; | ||||
|   | ||||
| @@ -82,7 +82,7 @@ entity_t * mapEntityGetByPosition( | ||||
|  */ | ||||
| entity_t * mapEntityGetByType( | ||||
|   map_t *map, | ||||
|   const uint8_t type | ||||
|   const entitytype_t type | ||||
| ); | ||||
|  | ||||
| /** | ||||
|   | ||||
| @@ -29,25 +29,25 @@ void testMapInit(map_t *map) { | ||||
|  | ||||
|   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[i] = 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[10] = TILE_ID_WATER; | ||||
|   tiles[11] = TILE_ID_WATER; | ||||
|   tiles[12] = TILE_ID_WATER; | ||||
|   tiles[13] = TILE_ID_WATER; | ||||
|   tiles[14] = 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[26] = TILE_ID_WATER; | ||||
|   tiles[27] = TILE_ID_WATER; | ||||
|   tiles[28] = TILE_ID_WATER; | ||||
|   tiles[29] = 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; | ||||
|   tiles[41] = TILE_ID_WATER; | ||||
|   tiles[42] = TILE_ID_WATER; | ||||
|   tiles[43] = TILE_ID_WATER; | ||||
|   tiles[44] = TILE_ID_WATER; | ||||
|   tiles[45] = TILE_ID_WATER; | ||||
|  | ||||
|   mapTilesSet(map, tiles, 0); | ||||
| } | ||||
| @@ -8,7 +8,7 @@ | ||||
| #include "tile.h" | ||||
|  | ||||
| bool_t tileIsSolid(const tile_t tile) { | ||||
|   switch(tile.id) { | ||||
|   switch(tile) { | ||||
|     case TILE_ID_WATER: | ||||
|       return true; | ||||
|        | ||||
|   | ||||
| @@ -8,12 +8,10 @@ | ||||
| #pragma once | ||||
| #include "dawn.h" | ||||
|  | ||||
| #define TILE_ID_NULL 0 | ||||
| #define TILE_ID_GRASS 1 | ||||
| #define TILE_ID_WATER 2 | ||||
|  | ||||
| typedef struct { | ||||
|   uint8_t id; | ||||
| typedef enum { | ||||
|   TILE_ID_NULL = 0, | ||||
|   TILE_ID_GRASS = 1, | ||||
|   TILE_ID_WATER = 2 | ||||
| } tile_t; | ||||
|  | ||||
| /** | ||||
|   | ||||
| @@ -10,7 +10,7 @@ | ||||
|  | ||||
| void triggerInit( | ||||
|   trigger_t *trigger, | ||||
|   const uint8_t type, | ||||
|   const triggertype_t type, | ||||
|   const uint16_t x, | ||||
|   const uint16_t y, | ||||
|   const uint16_t width, | ||||
|   | ||||
| @@ -8,7 +8,10 @@ | ||||
| #pragma once | ||||
| #include "rpg/entity/entity.h" | ||||
|  | ||||
| #define TRIGGER_TYPE_NULL 0 | ||||
|  | ||||
| typedef enum { | ||||
|   TRIGGER_TYPE_NULL = 0 | ||||
| } triggertype_t; | ||||
|  | ||||
| typedef struct { | ||||
|   uint16_t x, y; | ||||
| @@ -28,7 +31,7 @@ typedef struct { | ||||
|  */ | ||||
| void triggerInit( | ||||
|   trigger_t *trigger, | ||||
|   const uint8_t type, | ||||
|   const triggertype_t type, | ||||
|   const uint16_t x, | ||||
|   const uint16_t y, | ||||
|   const uint16_t width, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user