Cleaned a bit of the tile code. Built train station

This commit is contained in:
2024-10-25 10:30:49 -05:00
parent 39d74cc375
commit ef84c85527
23 changed files with 214 additions and 94 deletions

View File

@ -34,6 +34,7 @@ target_sources(${DAWN_TARGET_NAME}
# Assets
tool_map(testmap maps/testmap.tmx)
tool_map(testmap2 maps/testmap2.tmx)
tool_map(train_station maps/train_station.tmx)
tool_copy(en en.json)
add_dependencies(${DAWN_TARGET_NAME} dawnassets)

View File

@ -84,8 +84,8 @@ void drawMap(
// Tile?
tile = mapTileGetByPosition(map, x - offsetX, y - offsetY, 0);
colorDest[x] = symbolGetColorByTile(tile);
bufferDest[x] = symbolGetCharByTile(tile);
colorDest[x] = tileColorGet(tile);
bufferDest[x] = tileSymbolGet(tile);
}
}
}

View File

@ -34,35 +34,6 @@ char_t symbolGetCharByEntity(const entity_t *ent) {
}
}
char_t symbolGetCharByTile(const tile_t tile) {
switch(tile) {
case TILE_NULL:
case TILE_WALKABLE_NULL:
return ' ';
case TILE_GRASS:
return '#';
case TILE_WATER:
int32_t j = (int32_t)(TIME.time * 2) % 4;
switch(j) {
case 0: return '/';
case 1: return '|';
case 2: return '\\';
case 3: return '|';
}
case TILE_BUILDING_WALL:
return '-';
case TILE_ROOF:
return '/';
default:
assertUnreachable("Unknown char for tile.");
}
}
uint8_t symbolGetColorByEntity(const entity_t *ent) {
assertNotNull(ent, "Entity cannot be NULL.");
switch(ent->type) {
@ -81,27 +52,4 @@ uint8_t symbolGetColorByEntity(const entity_t *ent) {
default:
assertUnreachable("Invalid entity type.");
}
}
uint8_t symbolGetColorByTile(const tile_t tile) {
switch(tile) {
case TILE_NULL:
case TILE_WALKABLE_NULL:
return COLOR_BLACK;
case TILE_GRASS:
return COLOR_GREEN;
case TILE_WATER:
return COLOR_BLUE;
case TILE_BUILDING_WALL:
return COLOR_GRAY;
case TILE_ROOF:
return COLOR_BROWN;
default:
assertUnreachable("Unknown color for tile.");
}
}

View File

@ -7,7 +7,6 @@
#pragma once
#include "rpg/entity/entity.h"
#include "rpg/world/tile.h"
#include "display/color.h"
/**
@ -18,26 +17,10 @@
*/
char_t symbolGetCharByEntity(const entity_t *ent);
/**
* Returns the symbol for the given tile.
*
* @param tile Tile to get the symbol for.
* @return The symbol for the tile.
*/
char_t symbolGetCharByTile(const tile_t tile);
/**
* Returns the color for the given entity.
*
* @param ent Entity to get the color for.
* @return The color for the entity.
*/
uint8_t symbolGetColorByEntity(const entity_t *ent);
/**
* Returns the color for the given tile.
*
* @param tile Tile to get the color for.
* @return The color for the tile.
*/
uint8_t symbolGetColorByTile(const tile_t tile);
uint8_t symbolGetColorByEntity(const entity_t *ent);

View File

@ -72,6 +72,8 @@ gameupdateresult_t gameUpdate(const float_t delta) {
printf("Updating unknown state %d\n", GAME.state);
}
if(inputWasPressed(INPUT_BIND_FORCE_QUIT)) GAME.shouldExit = true;
// Perform render.
displayUpdate();

View File

@ -8,23 +8,29 @@
#include "mapchange.h"
#include "asset/assetmap.h"
#include "game/game.h"
#include "util/memory.h"
void gameStateMapChangeUpdate() {
// First try and find the player object
entity_t *player = NULL;
player_t oldPlayerData;
entitydirection_t dir = ENTITY_DIRECTION_SOUTH;
if(GAME.currentMap != NULL) {
player = mapEntityGetByType(GAME.currentMap, ENTITY_TYPE_PLAYER);
dir = player->direction;
oldPlayerData = player->player;
}
assetMapLoad(MAP_LIST_PATHS[GAME.mapNext], &MAP_MAIN);
GAME.state = GAME_STATE_OVERWORLD;
GAME.currentMap = &MAP_MAIN;
// Do not reference player since its invalid, just check if it DID exist
// Do not reference player since its invalid, just check if it DID exist
if(GAME.currentMap != NULL && player != NULL) {
player = mapEntityGetByType(GAME.currentMap, ENTITY_TYPE_PLAYER);
if(player == NULL) return;
player->player = oldPlayerData;
player->direction = dir;
}
}

View File

@ -18,8 +18,9 @@ typedef bool_t inputstate_t;
#define INPUT_BIND_ACCEPT 0x04
#define INPUT_BIND_CANCEL 0x05
#define INPUT_BIND_PAUSE 0x06
#define INPUT_BIND_FORCE_QUIT 0x07
#define INPUT_BIND_COUNT (INPUT_BIND_PAUSE + 1)
#define INPUT_BIND_COUNT (INPUT_BIND_FORCE_QUIT + 1)
typedef struct {
inputstate_t currentState[INPUT_BIND_COUNT];

View File

@ -11,11 +11,11 @@
#include "rpg/world/trigger.h"
#include "maplist.h"
#define MAP_WIDTH_MAX 2048
#define MAP_HEIGHT_MAX 2048
#define MAP_WIDTH_MAX 512
#define MAP_HEIGHT_MAX 512
#define MAP_LAYERS_MAX 1
#define MAP_ENTITIES_MAX 256
#define MAP_TRIGGERS_MAX 64
#define MAP_ENTITIES_MAX 64
#define MAP_TRIGGERS_MAX 32
typedef struct _map_t {
tile_t tiles[MAP_WIDTH_MAX * MAP_HEIGHT_MAX * MAP_LAYERS_MAX];

View File

@ -10,7 +10,8 @@
const char_t * MAP_LIST_PATHS[] = {
"testmap.map",
"testmap2.map"
"testmap2.map",
"train_station.map"
};
const int32_t MAP_LIST_COUNT = sizeof(MAP_LIST_PATHS) / sizeof(char_t*);

View File

@ -9,7 +9,9 @@
#include "dawn.h"
typedef enum {
MAP_LIST_TEST
MAP_LIST_TEST = 0,
MAP_LIST_TEST2 = 1,
MAP_LIST_TRAIN_STATION = 2,
} maplist_t;
extern const char_t *MAP_LIST_PATHS[];

View File

@ -6,6 +6,67 @@
*/
#include "tile.h"
#include "assert/assert.h"
#include "game/time.h"
const char_t TILE_SYMBOLS[] = {
' ',// NULL
'#',
'/',
' ',
'-',// BUILDING_WALL
'/',
' ',
'#',
'=',// STAIRS
'n',
'I',
'|',
'-',// RAIL_SLEEPER
'#',
'i'
};
const uint8_t TILE_COLORS[] = {
COLOR_BLACK,// NULL
COLOR_GREEN,
COLOR_BLUE,
COLOR_MAGENTA,
COLOR_GRAY,// BUILDING_WALL
COLOR_BROWN,
COLOR_BLACK,
COLOR_GRAY,
COLOR_GRAY, // STAIRS
COLOR_BROWN,
COLOR_WHITE,
COLOR_GRAY,
COLOR_BROWN,// RAIL_SLEEPER
COLOR_RED,
COLOR_YELLOW
};
char_t tileSymbolGet(const tile_t tile) {
switch(tile) {
case TILE_WATER:
int32_t j = (int32_t)(TIME.time * 2) % 4;
switch(j) {
case 0: return '/';
case 1: return '|';
case 2: return '\\';
case 3: return '|';
}
default:
return TILE_SYMBOLS[tile];
}
}
uint8_t tileColorGet(const tile_t tile) {
switch(tile) {
default:
return TILE_COLORS[tile];
}
}
bool_t tileIsSolid(const tile_t tile) {
switch(tile) {

View File

@ -6,18 +6,44 @@
*/
#pragma once
#include "dawn.h"
#include "display/color.h"
typedef enum {
TILE_NULL = 0,
TILE_GRASS = 1,
TILE_WATER = 2,
// TILE_DOOR = 3,
TILE_BUILDING_WALL = 4,
TILE_ROOF = 5,
TILE_WALKABLE_NULL = 6,
TILE_COBBLESTONE = 7,
TILE_STAIRS = 8,
TILE_RAILING = 9,
TILE_COLUMN = 10,
TILE_RAIL_TRACK = 11,
TILE_RAIL_SLEEPER = 12,
TILE_CARPET = 13,
TILE_LAMP = 14
} tile_t;
extern const char_t TILE_SYMBOLS[];
/**
* Returns the symbol used by the given tile.
*
* @param tile Tile to get the symbol of.
* @return The symbol for this tile.
*/
char_t tileSymbolGet(const tile_t tile);
/**
* Returns the color used by a given tile.
*
* @param tile Tile to get the color of.
* @return The color of this tile.
*/
uint8_t tileColorGet(const tile_t tile);
/**
* Returns whether or not the tile is solid.
*

View File

@ -38,7 +38,7 @@ void mainMenuSelectCallback(
) {
// New Game
if(y == 0) {
GAME.mapNext = MAP_LIST_TEST;
GAME.mapNext = MAP_LIST_TRAIN_STATION;
GAME.state = GAME_STATE_MAP_CHANGE;
return;
}

View File

@ -88,6 +88,7 @@ int32_t dawnGlfwStart() {
dawnGlfwInputBind(INPUT_BIND_PAUSE, GLFW_KEY_P);
dawnGlfwInputBind(INPUT_BIND_CANCEL, GLFW_KEY_Q);
dawnGlfwInputBind(INPUT_BIND_CANCEL, GLFW_KEY_BACKSPACE);
dawnGlfwInputBind(INPUT_BIND_FORCE_QUIT, GLFW_KEY_BACKSLASH);
// Event callbacks
glfwSetFramebufferSizeCallback(DAWN_GLFW.window, &dawnGlfwOnResize);

View File

@ -56,6 +56,14 @@ void displayUpdate() {
color = TERM_COLOR_CYAN;
break;
case COLOR_GRAY:
color = TERM_COLOR_GRAY;
break;
case COLOR_BROWN:
color = TERM_COLOR_BROWN;
break;
default:
assertUnreachable("Invalid color.");
}

View File

@ -16,5 +16,7 @@
#define TERM_COLOR_YELLOW "\x1b[33m"
#define TERM_COLOR_MAGENTA "\x1b[35m"
#define TERM_COLOR_CYAN "\x1b[36m"
#define TERM_COLOR_GRAY "\x1b[90m"
#define TERM_COLOR_BROWN "\x1b[33m"
#define TERM_COLOR_RESET "\x1b[0m"

View File

@ -10,7 +10,6 @@
inputstate_t inputGetState(const inputbind_t bind) {
int32_t k = LINUX_TERM_HOST_KEY_PRESS;
if(k == -1) return false;
switch(bind) {
@ -32,6 +31,12 @@ inputstate_t inputGetState(const inputbind_t bind) {
case INPUT_BIND_CANCEL:
return k == 'q';
case INPUT_BIND_PAUSE:
return k == 'p';
case INPUT_BIND_FORCE_QUIT:
return k == '\\';
default:
return false;
}