Door and map changing

This commit is contained in:
2024-10-07 00:27:20 -05:00
parent 5334f0944e
commit cb3a58e456
15 changed files with 216 additions and 93 deletions

View File

@ -16,10 +16,12 @@ void doorDestinationSet(
door_t *door,
const int32_t x,
const int32_t y,
const entitydirection_t direction
const entitydirection_t direction,
const maplist_t map
) {
assertNotNull(door, "Door cannot be NULL.");
door->x = x;
door->y = y;
door->direction = direction;
door->map = map;
}

View File

@ -7,11 +7,13 @@
#pragma once
#include "entitydirection.h"
#include "rpg/world/maplist.h"
typedef struct {
int32_t x;
int32_t y;
entitydirection_t direction;
maplist_t map;
} door_t;
/**
@ -28,10 +30,12 @@ void doorInit(door_t *door);
* @param x X coordinate of the destination.
* @param y Y coordinate of the destination.
* @param direction Direction the player should face when they arrive.
* @param map Map the player should arrive in.
*/
void doorDestinationSet(
door_t *door,
const int32_t x,
const int32_t y,
const entitydirection_t direction
const entitydirection_t direction,
const maplist_t map
);

View File

@ -7,6 +7,7 @@
#include "interact.h"
#include "assert/assert.h"
#include "game/game.h"
void entityInteractEntity(
entity_t *source,
@ -34,6 +35,11 @@ void entityInteractEntity(
case ENTITY_TYPE_DOOR:
entityPositionSet(source, target->door.x, target->door.y);
source->direction = target->door.direction;
if(GAME.mapNext != target->door.map) {
GAME.mapNext = target->door.map;
GAME.state = GAME_STATE_MAP_CHANGE;
}
return;
default:

View File

@ -11,4 +11,5 @@ target_sources(${DAWN_TARGET_NAME}
tile.c
map.c
trigger.c
maplist.c
)

View File

@ -8,8 +8,11 @@
#include "map.h"
#include "assert/assert.h"
map_t MAP_MAIN;
void mapInit(
map_t *map,
const maplist_t list,
const uint16_t width,
const uint16_t height,
const uint8_t layers
@ -40,8 +43,9 @@ void mapInit(
"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->height = height;
map->layers = layers;

View File

@ -9,6 +9,7 @@
#include "tile.h"
#include "rpg/entity/entity.h"
#include "rpg/world/trigger.h"
#include "maplist.h"
#define MAP_WIDTH_MAX 2048
#define MAP_HEIGHT_MAX 2048
@ -22,6 +23,8 @@ typedef struct _map_t {
uint16_t height;
uint8_t layers;
maplist_t list;
entity_t entities[MAP_ENTITIES_MAX];
uint8_t entityCount;
@ -29,6 +32,9 @@ typedef struct _map_t {
uint8_t triggerCount;
} map_t;
extern map_t MAP_MAIN;
/**
* Initializes a map.
*
@ -39,6 +45,7 @@ typedef struct _map_t {
*/
void mapInit(
map_t *map,
const maplist_t list,
const uint16_t width,
const uint16_t height,
const uint8_t layers

View 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);
}

View 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);