Door and map changing
This commit is contained in:
		@@ -49,7 +49,8 @@
 | 
				
			|||||||
      "door": {
 | 
					      "door": {
 | 
				
			||||||
        "x": 0,
 | 
					        "x": 0,
 | 
				
			||||||
        "y": 0,
 | 
					        "y": 0,
 | 
				
			||||||
        "direction": 3
 | 
					        "direction": 3,
 | 
				
			||||||
 | 
					        "map": "testmap2.json"
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  ]
 | 
					  ]
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										20
									
								
								assets/testmap2.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								assets/testmap2.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "width": 3,
 | 
				
			||||||
 | 
					  "height": 3,
 | 
				
			||||||
 | 
					  "layers": [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "tiles": [
 | 
				
			||||||
 | 
					        1, 1, 1,
 | 
				
			||||||
 | 
					        1, 1, 1,
 | 
				
			||||||
 | 
					        1, 1, 1
 | 
				
			||||||
 | 
					      ]
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "entities": [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "type": 1,
 | 
				
			||||||
 | 
					      "x": 0,
 | 
				
			||||||
 | 
					      "y": 0
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -31,5 +31,6 @@ target_sources(${DAWN_TARGET_NAME}
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# Assets
 | 
					# Assets
 | 
				
			||||||
tool_copy(testmap testmap.json)
 | 
					tool_copy(testmap testmap.json)
 | 
				
			||||||
 | 
					tool_copy(testmap2 testmap2.json)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
add_dependencies(${DAWN_TARGET_NAME} dawnassets)
 | 
					add_dependencies(${DAWN_TARGET_NAME} dawnassets)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,85 +8,11 @@
 | 
				
			|||||||
#include "assetmap.h"
 | 
					#include "assetmap.h"
 | 
				
			||||||
#include "asset/asset.h"
 | 
					#include "asset/asset.h"
 | 
				
			||||||
#include "assert/assert.h"
 | 
					#include "assert/assert.h"
 | 
				
			||||||
#include "asset/assetjson.h"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
void assetMapLoad(
 | 
					void assetMapLoadEntity(
 | 
				
			||||||
  const char_t *path,
 | 
					  assetjson_t *jEnt,
 | 
				
			||||||
  map_t *map
 | 
					  map_t *map
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
  assertNotNull(map, "assetMapLoad: Map is NULL!");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Read in the string data.
 | 
					 | 
				
			||||||
  assetOpen(path);
 | 
					 | 
				
			||||||
  size_t length = assetGetSize();
 | 
					 | 
				
			||||||
  char_t *buffer = malloc(sizeof(char_t) * (length + 1));
 | 
					 | 
				
			||||||
  size_t read = assetRead((uint8_t*)buffer, length);
 | 
					 | 
				
			||||||
  buffer[length] = '\0';
 | 
					 | 
				
			||||||
  assertTrue(read == length, "assetMapLoad: Failed to read map data!");
 | 
					 | 
				
			||||||
  assetClose();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Begin parsing JSON data.
 | 
					 | 
				
			||||||
  assetjson_t *json;
 | 
					 | 
				
			||||||
  read = assetJsonParse(buffer, &json);
 | 
					 | 
				
			||||||
  free(buffer);
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  assertTrue(
 | 
					 | 
				
			||||||
    json->type == ASSET_JSON_DATA_TYPE_OBJECT,
 | 
					 | 
				
			||||||
    "assetMapLoad: Map data is not an object!"
 | 
					 | 
				
			||||||
  );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  int32_t width = (int32_t)assetJsonGetObjectValue(json, "width")->number;
 | 
					 | 
				
			||||||
  int32_t height = (int32_t)assetJsonGetObjectValue(json, "height")->number;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  assetjson_t *layers = assetJsonGetObjectValue(json, "layers");
 | 
					 | 
				
			||||||
  assertTrue(
 | 
					 | 
				
			||||||
    layers->type == ASSET_JSON_DATA_TYPE_ARRAY,
 | 
					 | 
				
			||||||
    "assetMapLoad: Layers is not an array!"
 | 
					 | 
				
			||||||
  );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  int32_t layerCount = layers->array.length;
 | 
					 | 
				
			||||||
  assertTrue(layerCount == MAP_LAYERS_MAX, "assetMapLoad: No layers found!");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  mapInit(map, width, height, layerCount);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Load tile data.
 | 
					 | 
				
			||||||
  for(int32_t i = 0; i < layerCount; i++) {
 | 
					 | 
				
			||||||
    assetjson_t *layer = layers->array.value[i];
 | 
					 | 
				
			||||||
    assertTrue(
 | 
					 | 
				
			||||||
      layer->type == ASSET_JSON_DATA_TYPE_OBJECT,
 | 
					 | 
				
			||||||
      "assetMapLoad: Layer is not an object!"
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    assetjson_t *tiles = assetJsonGetObjectValue(layer, "tiles");
 | 
					 | 
				
			||||||
    assertTrue(
 | 
					 | 
				
			||||||
      tiles->type == ASSET_JSON_DATA_TYPE_ARRAY,
 | 
					 | 
				
			||||||
      "assetMapLoad: Tiles is not an array!"
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
    assertTrue(
 | 
					 | 
				
			||||||
      tiles->array.length == width * height,
 | 
					 | 
				
			||||||
      "assetMapLoad: Tile count does not match map size!"
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for(int32_t j = 0; j < width * height; j++) {
 | 
					 | 
				
			||||||
      map->tiles[j] = (tile_t)tiles->array.value[j]->number;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Load entity data
 | 
					 | 
				
			||||||
  assetjson_t *entities = assetJsonGetObjectValue(json, "entities");
 | 
					 | 
				
			||||||
  if(entities != NULL) {
 | 
					 | 
				
			||||||
    assertTrue(
 | 
					 | 
				
			||||||
      entities->type == ASSET_JSON_DATA_TYPE_ARRAY,
 | 
					 | 
				
			||||||
      "assetMapLoad: Entities is not an array!"
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for(int32_t i = 0; i < entities->array.length; i++) {
 | 
					 | 
				
			||||||
      assetjson_t *jEnt = entities->array.value[i];
 | 
					 | 
				
			||||||
      assertTrue(
 | 
					 | 
				
			||||||
        jEnt->type == ASSET_JSON_DATA_TYPE_OBJECT,
 | 
					 | 
				
			||||||
        "assetMapLoad: Entity is not an object!"
 | 
					 | 
				
			||||||
      );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  int32_t x = (int32_t)assetJsonGetObjectValue(jEnt, "x")->number;
 | 
					  int32_t x = (int32_t)assetJsonGetObjectValue(jEnt, "x")->number;
 | 
				
			||||||
  int32_t y = (int32_t)assetJsonGetObjectValue(jEnt, "y")->number;
 | 
					  int32_t y = (int32_t)assetJsonGetObjectValue(jEnt, "y")->number;
 | 
				
			||||||
  entitytype_t type = (entitytype_t)assetJsonGetObjectValue(
 | 
					  entitytype_t type = (entitytype_t)assetJsonGetObjectValue(
 | 
				
			||||||
@@ -146,18 +72,106 @@ void assetMapLoad(
 | 
				
			|||||||
          door->type == ASSET_JSON_DATA_TYPE_NUMBER,
 | 
					          door->type == ASSET_JSON_DATA_TYPE_NUMBER,
 | 
				
			||||||
          "assetMapLoad: Door y is not a number!"
 | 
					          "assetMapLoad: Door y is not a number!"
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
            entitydirection_t direction = (entitydirection_t)assetJsonGetObjectValue(
 | 
					        entitydirection_t direction = (entitydirection_t)(
 | 
				
			||||||
              val, "direction"
 | 
					          assetJsonGetObjectValue(val, "direction")->number
 | 
				
			||||||
            )->number;
 | 
					        );
 | 
				
			||||||
            doorDestinationSet(&ent->door, x, y, direction);
 | 
					        door = assetJsonGetObjectValue(val, "map");
 | 
				
			||||||
 | 
					        maplist_t list;
 | 
				
			||||||
 | 
					        if(door == NULL) {
 | 
				
			||||||
 | 
					          list = map->list;
 | 
				
			||||||
 | 
					        } else if(door->type == ASSET_JSON_DATA_TYPE_STRING) {
 | 
				
			||||||
 | 
					          list = mapListGet(door->string);
 | 
				
			||||||
 | 
					        } else if(door->type == ASSET_JSON_DATA_TYPE_NUMBER) {
 | 
				
			||||||
 | 
					          list = (maplist_t)door->number;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					          assertUnreachable("assetMapLoad: Door map not string or number!");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        doorDestinationSet(&ent->door, x, y, direction, list);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    default:
 | 
					    default:
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // TODO: Parse any extra data.
 | 
					void assetMapLoad(
 | 
				
			||||||
 | 
					  const char_t *path,
 | 
				
			||||||
 | 
					  map_t *map
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
 | 
					  assertNotNull(map, "assetMapLoad: Map is NULL!");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Read in the string data.
 | 
				
			||||||
 | 
					  assetOpen(path);
 | 
				
			||||||
 | 
					  size_t length = assetGetSize();
 | 
				
			||||||
 | 
					  char_t *buffer = malloc(sizeof(char_t) * (length + 1));
 | 
				
			||||||
 | 
					  size_t read = assetRead((uint8_t*)buffer, length);
 | 
				
			||||||
 | 
					  buffer[length] = '\0';
 | 
				
			||||||
 | 
					  assertTrue(read == length, "assetMapLoad: Failed to read map data!");
 | 
				
			||||||
 | 
					  assetClose();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Begin parsing JSON data.
 | 
				
			||||||
 | 
					  assetjson_t *json;
 | 
				
			||||||
 | 
					  read = assetJsonParse(buffer, &json);
 | 
				
			||||||
 | 
					  free(buffer);
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  assertTrue(
 | 
				
			||||||
 | 
					    json->type == ASSET_JSON_DATA_TYPE_OBJECT,
 | 
				
			||||||
 | 
					    "assetMapLoad: Map data is not an object!"
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  int32_t width = (int32_t)assetJsonGetObjectValue(json, "width")->number;
 | 
				
			||||||
 | 
					  int32_t height = (int32_t)assetJsonGetObjectValue(json, "height")->number;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  assetjson_t *layers = assetJsonGetObjectValue(json, "layers");
 | 
				
			||||||
 | 
					  assertTrue(
 | 
				
			||||||
 | 
					    layers->type == ASSET_JSON_DATA_TYPE_ARRAY,
 | 
				
			||||||
 | 
					    "assetMapLoad: Layers is not an array!"
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  int32_t layerCount = layers->array.length;
 | 
				
			||||||
 | 
					  assertTrue(layerCount == MAP_LAYERS_MAX, "assetMapLoad: No layers found!");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  mapInit(map, mapListGet(path), width, height, layerCount);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Load tile data.
 | 
				
			||||||
 | 
					  for(int32_t i = 0; i < layerCount; i++) {
 | 
				
			||||||
 | 
					    assetjson_t *layer = layers->array.value[i];
 | 
				
			||||||
 | 
					    assertTrue(
 | 
				
			||||||
 | 
					      layer->type == ASSET_JSON_DATA_TYPE_OBJECT,
 | 
				
			||||||
 | 
					      "assetMapLoad: Layer is not an object!"
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    assetjson_t *tiles = assetJsonGetObjectValue(layer, "tiles");
 | 
				
			||||||
 | 
					    assertTrue(
 | 
				
			||||||
 | 
					      tiles->type == ASSET_JSON_DATA_TYPE_ARRAY,
 | 
				
			||||||
 | 
					      "assetMapLoad: Tiles is not an array!"
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    assertTrue(
 | 
				
			||||||
 | 
					      tiles->array.length == width * height,
 | 
				
			||||||
 | 
					      "assetMapLoad: Tile count does not match map size!"
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for(int32_t j = 0; j < width * height; j++) {
 | 
				
			||||||
 | 
					      map->tiles[j] = (tile_t)tiles->array.value[j]->number;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Load entity data
 | 
				
			||||||
 | 
					  assetjson_t *entities = assetJsonGetObjectValue(json, "entities");
 | 
				
			||||||
 | 
					  if(entities != NULL) {
 | 
				
			||||||
 | 
					    assertTrue(
 | 
				
			||||||
 | 
					      entities->type == ASSET_JSON_DATA_TYPE_ARRAY,
 | 
				
			||||||
 | 
					      "assetMapLoad: Entities is not an array!"
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for(int32_t i = 0; i < entities->array.length; i++) {
 | 
				
			||||||
 | 
					      assetjson_t *jEnt = entities->array.value[i];
 | 
				
			||||||
 | 
					      assertTrue(
 | 
				
			||||||
 | 
					        jEnt->type == ASSET_JSON_DATA_TYPE_OBJECT,
 | 
				
			||||||
 | 
					        "assetMapLoad: Entity is not an object!"
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					      assetMapLoadEntity(jEnt, map);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,7 +7,25 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
#include "rpg/world/map.h"
 | 
					#include "rpg/world/map.h"
 | 
				
			||||||
 | 
					#include "asset/assetjson.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Loads an entity from the specified JSON object.
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * @param jEnt JSON object to load the entity from.
 | 
				
			||||||
 | 
					 * @param map Map to load the entity into.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void assetMapLoadEntity(
 | 
				
			||||||
 | 
					  assetjson_t *jEnt,
 | 
				
			||||||
 | 
					  map_t *map
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Loads a map from the specified path.
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * @param path Path to the map file.
 | 
				
			||||||
 | 
					 * @param map Map to load the data into.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
void assetMapLoad(
 | 
					void assetMapLoad(
 | 
				
			||||||
  const char_t *path,
 | 
					  const char_t *path,
 | 
				
			||||||
  map_t *map
 | 
					  map_t *map
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,7 +13,6 @@
 | 
				
			|||||||
#include "asset/asset.h"
 | 
					#include "asset/asset.h"
 | 
				
			||||||
#include "asset/assetmap.h"
 | 
					#include "asset/assetmap.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
map_t MAP;
 | 
					 | 
				
			||||||
game_t GAME;
 | 
					game_t GAME;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void gameInit() {
 | 
					void gameInit() {
 | 
				
			||||||
@@ -25,8 +24,8 @@ void gameInit() {
 | 
				
			|||||||
  assetInit();
 | 
					  assetInit();
 | 
				
			||||||
  textboxInit();
 | 
					  textboxInit();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  assetMapLoad("testmap.json", &MAP);
 | 
					  GAME.mapNext = MAP_LIST_TEST;
 | 
				
			||||||
  gameSetMap(&MAP);
 | 
					  GAME.state = GAME_STATE_MAP_CHANGE;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
gameupdateresult_t gameUpdate(const float_t delta) {
 | 
					gameupdateresult_t gameUpdate(const float_t delta) {
 | 
				
			||||||
@@ -47,6 +46,13 @@ gameupdateresult_t gameUpdate(const float_t delta) {
 | 
				
			|||||||
    case GAME_STATE_PAUSED:
 | 
					    case GAME_STATE_PAUSED:
 | 
				
			||||||
      if(inputWasPressed(INPUT_BIND_PAUSE)) GAME.state = GAME_STATE_OVERWORLD;
 | 
					      if(inputWasPressed(INPUT_BIND_PAUSE)) GAME.state = GAME_STATE_OVERWORLD;
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    case GAME_STATE_MAP_CHANGE:
 | 
				
			||||||
 | 
					      assetMapLoad(MAP_LIST_PATHS[GAME.mapNext], &MAP_MAIN);
 | 
				
			||||||
 | 
					      GAME.state = GAME_STATE_OVERWORLD;
 | 
				
			||||||
 | 
					      GAME.currentMap = &MAP_MAIN;
 | 
				
			||||||
 | 
					      map_t *test = &MAP_MAIN;
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Perform render.
 | 
					  // Perform render.
 | 
				
			||||||
@@ -56,10 +62,6 @@ gameupdateresult_t gameUpdate(const float_t delta) {
 | 
				
			|||||||
  return GAME_UPDATE_RESULT_CONTINUE;
 | 
					  return GAME_UPDATE_RESULT_CONTINUE;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void gameSetMap(map_t *map) {
 | 
					 | 
				
			||||||
  GAME.currentMap = map;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void gameDispose() {
 | 
					void gameDispose() {
 | 
				
			||||||
  assetDispose();
 | 
					  assetDispose();
 | 
				
			||||||
  displayDispose();
 | 
					  displayDispose();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,13 +16,15 @@ typedef enum {
 | 
				
			|||||||
typedef enum {
 | 
					typedef enum {
 | 
				
			||||||
  GAME_STATE_INITIAL = 0,
 | 
					  GAME_STATE_INITIAL = 0,
 | 
				
			||||||
  GAME_STATE_OVERWORLD = 1,
 | 
					  GAME_STATE_OVERWORLD = 1,
 | 
				
			||||||
  GAME_STATE_PAUSED = 2
 | 
					  GAME_STATE_PAUSED = 2,
 | 
				
			||||||
 | 
					  GAME_STATE_MAP_CHANGE = 3
 | 
				
			||||||
} gamestate_t;
 | 
					} gamestate_t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct {
 | 
					typedef struct {
 | 
				
			||||||
  map_t *currentMap;
 | 
					  map_t *currentMap;
 | 
				
			||||||
  gamestate_t state;
 | 
					  gamestate_t state;
 | 
				
			||||||
  bool_t shouldExit;
 | 
					  bool_t shouldExit;
 | 
				
			||||||
 | 
					  maplist_t mapNext;
 | 
				
			||||||
} game_t;
 | 
					} game_t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern game_t GAME;
 | 
					extern game_t GAME;
 | 
				
			||||||
@@ -40,13 +42,6 @@ void gameInit();
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
gameupdateresult_t gameUpdate(const float_t delta);
 | 
					gameupdateresult_t gameUpdate(const float_t delta);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Sets the current map, does not take ownership.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * @param map Map to set.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
void gameSetMap(map_t *map);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Cleans up the game state.
 | 
					 * Cleans up the game state.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,10 +16,12 @@ void doorDestinationSet(
 | 
				
			|||||||
  door_t *door,
 | 
					  door_t *door,
 | 
				
			||||||
  const int32_t x,
 | 
					  const int32_t x,
 | 
				
			||||||
  const int32_t y,
 | 
					  const int32_t y,
 | 
				
			||||||
  const entitydirection_t direction
 | 
					  const entitydirection_t direction,
 | 
				
			||||||
 | 
					  const maplist_t map
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
  assertNotNull(door, "Door cannot be NULL.");
 | 
					  assertNotNull(door, "Door cannot be NULL.");
 | 
				
			||||||
  door->x = x;
 | 
					  door->x = x;
 | 
				
			||||||
  door->y = y;
 | 
					  door->y = y;
 | 
				
			||||||
  door->direction = direction;
 | 
					  door->direction = direction;
 | 
				
			||||||
 | 
					  door->map = map;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -7,11 +7,13 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
#include "entitydirection.h"
 | 
					#include "entitydirection.h"
 | 
				
			||||||
 | 
					#include "rpg/world/maplist.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct {
 | 
					typedef struct {
 | 
				
			||||||
  int32_t x;
 | 
					  int32_t x;
 | 
				
			||||||
  int32_t y;
 | 
					  int32_t y;
 | 
				
			||||||
  entitydirection_t direction;
 | 
					  entitydirection_t direction;
 | 
				
			||||||
 | 
					  maplist_t map;
 | 
				
			||||||
} door_t;
 | 
					} door_t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@@ -28,10 +30,12 @@ void doorInit(door_t *door);
 | 
				
			|||||||
 * @param x X coordinate of the destination.
 | 
					 * @param x X coordinate of the destination.
 | 
				
			||||||
 * @param y Y coordinate of the destination.
 | 
					 * @param y Y coordinate of the destination.
 | 
				
			||||||
 * @param direction Direction the player should face when they arrive.
 | 
					 * @param direction Direction the player should face when they arrive.
 | 
				
			||||||
 | 
					 * @param map Map the player should arrive in.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void doorDestinationSet(
 | 
					void doorDestinationSet(
 | 
				
			||||||
  door_t *door,
 | 
					  door_t *door,
 | 
				
			||||||
  const int32_t x,
 | 
					  const int32_t x,
 | 
				
			||||||
  const int32_t y,
 | 
					  const int32_t y,
 | 
				
			||||||
  const entitydirection_t direction
 | 
					  const entitydirection_t direction,
 | 
				
			||||||
 | 
					  const maplist_t map
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
@@ -7,6 +7,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "interact.h"
 | 
					#include "interact.h"
 | 
				
			||||||
#include "assert/assert.h"
 | 
					#include "assert/assert.h"
 | 
				
			||||||
 | 
					#include "game/game.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void entityInteractEntity(
 | 
					void entityInteractEntity(
 | 
				
			||||||
  entity_t *source,
 | 
					  entity_t *source,
 | 
				
			||||||
@@ -34,6 +35,11 @@ void entityInteractEntity(
 | 
				
			|||||||
    case ENTITY_TYPE_DOOR:
 | 
					    case ENTITY_TYPE_DOOR:
 | 
				
			||||||
      entityPositionSet(source, target->door.x, target->door.y);
 | 
					      entityPositionSet(source, target->door.x, target->door.y);
 | 
				
			||||||
      source->direction = target->door.direction;
 | 
					      source->direction = target->door.direction;
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      if(GAME.mapNext != target->door.map) {
 | 
				
			||||||
 | 
					        GAME.mapNext = target->door.map;
 | 
				
			||||||
 | 
					        GAME.state = GAME_STATE_MAP_CHANGE;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    default:
 | 
					    default:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,4 +11,5 @@ target_sources(${DAWN_TARGET_NAME}
 | 
				
			|||||||
    tile.c
 | 
					    tile.c
 | 
				
			||||||
    map.c
 | 
					    map.c
 | 
				
			||||||
    trigger.c
 | 
					    trigger.c
 | 
				
			||||||
 | 
					    maplist.c
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -8,8 +8,11 @@
 | 
				
			|||||||
#include "map.h"
 | 
					#include "map.h"
 | 
				
			||||||
#include "assert/assert.h"
 | 
					#include "assert/assert.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					map_t MAP_MAIN;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void mapInit(
 | 
					void mapInit(
 | 
				
			||||||
  map_t *map,
 | 
					  map_t *map,
 | 
				
			||||||
 | 
					  const maplist_t list,
 | 
				
			||||||
  const uint16_t width,
 | 
					  const uint16_t width,
 | 
				
			||||||
  const uint16_t height,
 | 
					  const uint16_t height,
 | 
				
			||||||
  const uint8_t layers
 | 
					  const uint8_t layers
 | 
				
			||||||
@@ -40,8 +43,9 @@ void mapInit(
 | 
				
			|||||||
    "Map layers must be less than or equal to MAP_LAYERS_MAX."
 | 
					    "Map layers must be less than or equal to MAP_LAYERS_MAX."
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  memset(map, 0, sizeof(map));
 | 
					  memset(map, 0, sizeof(map_t));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  map->list = list;
 | 
				
			||||||
  map->width = width;
 | 
					  map->width = width;
 | 
				
			||||||
  map->height = height;
 | 
					  map->height = height;
 | 
				
			||||||
  map->layers = layers;
 | 
					  map->layers = layers;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,6 +9,7 @@
 | 
				
			|||||||
#include "tile.h"
 | 
					#include "tile.h"
 | 
				
			||||||
#include "rpg/entity/entity.h"
 | 
					#include "rpg/entity/entity.h"
 | 
				
			||||||
#include "rpg/world/trigger.h"
 | 
					#include "rpg/world/trigger.h"
 | 
				
			||||||
 | 
					#include "maplist.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define MAP_WIDTH_MAX 2048
 | 
					#define MAP_WIDTH_MAX 2048
 | 
				
			||||||
#define MAP_HEIGHT_MAX 2048
 | 
					#define MAP_HEIGHT_MAX 2048
 | 
				
			||||||
@@ -22,6 +23,8 @@ typedef struct _map_t {
 | 
				
			|||||||
  uint16_t height;
 | 
					  uint16_t height;
 | 
				
			||||||
  uint8_t layers;
 | 
					  uint8_t layers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  maplist_t list;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  entity_t entities[MAP_ENTITIES_MAX];
 | 
					  entity_t entities[MAP_ENTITIES_MAX];
 | 
				
			||||||
  uint8_t entityCount;
 | 
					  uint8_t entityCount;
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
@@ -29,6 +32,9 @@ typedef struct _map_t {
 | 
				
			|||||||
  uint8_t triggerCount;
 | 
					  uint8_t triggerCount;
 | 
				
			||||||
} map_t;
 | 
					} map_t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern map_t MAP_MAIN;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Initializes a map.
 | 
					 * Initializes a map.
 | 
				
			||||||
 * 
 | 
					 * 
 | 
				
			||||||
@@ -39,6 +45,7 @@ typedef struct _map_t {
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
void mapInit(
 | 
					void mapInit(
 | 
				
			||||||
  map_t *map,
 | 
					  map_t *map,
 | 
				
			||||||
 | 
					  const maplist_t list,
 | 
				
			||||||
  const uint16_t width,
 | 
					  const uint16_t width,
 | 
				
			||||||
  const uint16_t height,
 | 
					  const uint16_t height,
 | 
				
			||||||
  const uint8_t layers
 | 
					  const uint8_t layers
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										24
									
								
								src/dawn/rpg/world/maplist.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/dawn/rpg/world/maplist.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
				
			|||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Copyright (c) 2024 Dominic Masters
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * This software is released under the MIT License.
 | 
				
			||||||
 | 
					 * https://opensource.org/licenses/MIT
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "maplist.h"
 | 
				
			||||||
 | 
					#include "assert/assert.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const char_t * MAP_LIST_PATHS[] = {
 | 
				
			||||||
 | 
					  "testmap.json",
 | 
				
			||||||
 | 
					  "testmap2.json"
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const int32_t MAP_LIST_COUNT = sizeof(MAP_LIST_PATHS) / sizeof(char_t*);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					maplist_t mapListGet(const char_t *name) {
 | 
				
			||||||
 | 
					  for(int32_t i = 0; i < MAP_LIST_COUNT; i++) {
 | 
				
			||||||
 | 
					    if(strcmp(name, MAP_LIST_PATHS[i]) != 0) continue;
 | 
				
			||||||
 | 
					    return (maplist_t)i;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  assertUnreachable("mapListGet: Map list %s not found!", name);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										24
									
								
								src/dawn/rpg/world/maplist.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/dawn/rpg/world/maplist.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
				
			|||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Copyright (c) 2024 Dominic Masters
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * This software is released under the MIT License.
 | 
				
			||||||
 | 
					 * https://opensource.org/licenses/MIT
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pragma once
 | 
				
			||||||
 | 
					#include "dawn.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef enum {
 | 
				
			||||||
 | 
					  MAP_LIST_TEST,
 | 
				
			||||||
 | 
					  MAP_LIST_TEST2
 | 
				
			||||||
 | 
					} maplist_t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern const char_t *MAP_LIST_PATHS[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Returns the map list for the given name.
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * @param name Name of the map list to get.
 | 
				
			||||||
 | 
					 * @return Map list for the given name.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					maplist_t mapListGet(const char_t *name);
 | 
				
			||||||
		Reference in New Issue
	
	Block a user