This commit is contained in:
2024-10-06 23:11:45 -05:00
parent ecb3b9c5d1
commit a1d4b0a1d7
12 changed files with 134 additions and 39 deletions

View File

@ -1,19 +1,25 @@
{ {
"width": 10, "width": 16,
"height": 10, "height": 16,
"layers": [ "layers": [
{ {
"tiles": [ "tiles": [
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 5, 5, 5, 5, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 5, 5, 5, 5, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
] ]
} }
], ],
@ -25,16 +31,21 @@
}, },
{ {
"type": 2, "type": 2,
"x": 3, "x": 9,
"y": 3, "y": 9,
"name": "Bob", "name": "Bob",
"text": "Hello, I am Bob." "text": "Hello, I am Bob."
}, },
{ {
"type": 3, "type": 3,
"x": 6, "x": 3,
"y": 6, "y": 8,
"text": "This is a sign." "text": "This is a sign."
},
{
"type": 4,
"x": 6,
"y": 8
} }
] ]
} }

View File

@ -16,7 +16,9 @@ const color4f_t COLOR4F_COLOR_MAP[COLOR_COUNT] = {
COLOR4F(0.0f, 0.0f, 0.8f, 1.0f), COLOR4F(0.0f, 0.0f, 0.8f, 1.0f),
COLOR4F(0.8f, 0.8f, 0.0f, 1.0f), COLOR4F(0.8f, 0.8f, 0.0f, 1.0f),
COLOR4F(0.8f, 0.0f, 0.8f, 1.0f), COLOR4F(0.8f, 0.0f, 0.8f, 1.0f),
COLOR4F(0.0f, 0.8f, 0.8f, 1.0f) COLOR4F(0.0f, 0.8f, 0.8f, 1.0f),
COLOR4F(0.5f, 0.5f, 0.5f, 1.0f),
COLOR4F(0.5f, 0.25f, 0.0f, 1.0f)
}; };
void color4fCopy(const color4f_t src, color4f_t dest) { void color4fCopy(const color4f_t src, color4f_t dest) {

View File

@ -20,8 +20,10 @@ typedef float_t color4f_t[4];
#define COLOR_YELLOW 0x05 #define COLOR_YELLOW 0x05
#define COLOR_MAGENTA 0x06 #define COLOR_MAGENTA 0x06
#define COLOR_CYAN 0x07 #define COLOR_CYAN 0x07
#define COLOR_GRAY 0x08
#define COLOR_BROWN 0x09
#define COLOR_COUNT COLOR_CYAN+1 #define COLOR_COUNT COLOR_BROWN+1
#define COLOR3F(r,g,b) ((color3f_t){ r, g, b }) #define COLOR3F(r,g,b) ((color3f_t){ r, g, b })
#define COLOR3F_RED COLOR3F(1, 0, 0) #define COLOR3F_RED COLOR3F(1, 0, 0)

View File

@ -12,9 +12,16 @@
char_t symbolGetCharByEntity(const entity_t *ent) { char_t symbolGetCharByEntity(const entity_t *ent) {
assertNotNull(ent, "Entity cannot be NULL."); assertNotNull(ent, "Entity cannot be NULL.");
if(ent->type == ENTITY_TYPE_SIGN) { switch(ent->type) {
return '+'; case ENTITY_TYPE_SIGN:
return '+';
case ENTITY_TYPE_DOOR:
return 'D';
default:
break;
} }
switch(ent->direction) { switch(ent->direction) {
@ -29,10 +36,13 @@ char_t symbolGetCharByEntity(const entity_t *ent) {
char_t symbolGetCharByTile(const tile_t tile) { char_t symbolGetCharByTile(const tile_t tile) {
switch(tile) { switch(tile) {
case TILE_ID_GRASS: case TILE_NULL:
return ' ';
case TILE_GRASS:
return '#'; return '#';
case TILE_ID_WATER: case TILE_WATER:
int32_t j = (int32_t)(TIME.time * 2) % 4; int32_t j = (int32_t)(TIME.time * 2) % 4;
switch(j) { switch(j) {
case 0: return '/'; case 0: return '/';
@ -41,8 +51,14 @@ char_t symbolGetCharByTile(const tile_t tile) {
case 3: return '|'; case 3: return '|';
} }
case TILE_BUILDING_WALL:
return '-';
case TILE_ROOF:
return '/';
default: default:
return ' '; assertUnreachable("Unknown char for tile.");
} }
} }
@ -53,11 +69,14 @@ uint8_t symbolGetColorByEntity(const entity_t *ent) {
return COLOR_RED; return COLOR_RED;
case ENTITY_TYPE_NPC: case ENTITY_TYPE_NPC:
return COLOR_YELLOW; return COLOR_MAGENTA;
case ENTITY_TYPE_SIGN: case ENTITY_TYPE_SIGN:
return COLOR_YELLOW; return COLOR_YELLOW;
case ENTITY_TYPE_DOOR:
return COLOR_BROWN;
default: default:
assertUnreachable("Invalid entity type."); assertUnreachable("Invalid entity type.");
} }
@ -65,13 +84,22 @@ uint8_t symbolGetColorByEntity(const entity_t *ent) {
uint8_t symbolGetColorByTile(const tile_t tile) { uint8_t symbolGetColorByTile(const tile_t tile) {
switch(tile) { switch(tile) {
case TILE_ID_GRASS: case TILE_NULL:
return COLOR_BLACK;
case TILE_GRASS:
return COLOR_GREEN; return COLOR_GREEN;
case TILE_ID_WATER: case TILE_WATER:
return COLOR_BLUE; return COLOR_BLUE;
case TILE_BUILDING_WALL:
return COLOR_GRAY;
case TILE_ROOF:
return COLOR_BROWN;
default: default:
return COLOR_BLACK; assertUnreachable("Unknown color for tile.");
} }
} }

View File

@ -14,4 +14,5 @@ target_sources(${DAWN_TARGET_NAME}
sign.c sign.c
interact.c interact.c
npc.c npc.c
door.c
) )

View File

@ -0,0 +1,14 @@
/**
* Copyright (c) 2024 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "door.h"
#include "assert/assert.h"
void doorInit(door_t *door) {
assertNotNull(door, "Door cannot be NULL.");
door->bruv = 0;
}

View File

@ -0,0 +1,20 @@
/**
* Copyright (c) 2024 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dawn.h"
typedef struct {
uint8_t bruv;
} door_t;
/**
* Initializes a door.
*
* @param door Door to initialize.
*/
void doorInit(door_t *door);

View File

@ -37,6 +37,10 @@ void entityInit(
signInit(&entity->sign); signInit(&entity->sign);
break; break;
case ENTITY_TYPE_DOOR:
doorInit(&entity->door);
break;
case ENTITY_TYPE_PLAYER: case ENTITY_TYPE_PLAYER:
playerInit(entity); playerInit(entity);
break; break;

View File

@ -10,6 +10,7 @@
#include "sign.h" #include "sign.h"
#include "entitydirection.h" #include "entitydirection.h"
#include "npc.h" #include "npc.h"
#include "door.h"
typedef struct _map_t map_t; typedef struct _map_t map_t;
@ -17,7 +18,8 @@ typedef enum {
ENTITY_TYPE_NULL = 0, ENTITY_TYPE_NULL = 0,
ENTITY_TYPE_PLAYER = 1, ENTITY_TYPE_PLAYER = 1,
ENTITY_TYPE_NPC = 2, ENTITY_TYPE_NPC = 2,
ENTITY_TYPE_SIGN = 3 ENTITY_TYPE_SIGN = 3,
ENTITY_TYPE_DOOR = 4
} entitytype_t; } entitytype_t;
typedef enum { typedef enum {
@ -49,6 +51,7 @@ typedef struct _entity_t {
player_t player; player_t player;
npc_t npc; npc_t npc;
sign_t sign; sign_t sign;
door_t door;
}; };
} entity_t; } entity_t;

View File

@ -15,10 +15,11 @@ void entityInteractEntity(
assertNotNull(source, "entityInteractEntity: Source is NULL!"); assertNotNull(source, "entityInteractEntity: Source is NULL!");
assertNotNull(target, "entityInteractEntity: Target is NULL!"); assertNotNull(target, "entityInteractEntity: Target is NULL!");
source->state = ENTITY_STATE_TALKING;
target->state = ENTITY_STATE_TALKING;
switch(target->type) { switch(target->type) {
case ENTITY_TYPE_NPC: case ENTITY_TYPE_NPC:
source->state = ENTITY_STATE_TALKING;
target->state = ENTITY_STATE_TALKING;
target->direction = entityDirectionLookAt( target->direction = entityDirectionLookAt(
target->x, target->y, target->x, target->y,
source->x, source->y source->x, source->y
@ -27,11 +28,13 @@ void entityInteractEntity(
return; return;
case ENTITY_TYPE_SIGN: case ENTITY_TYPE_SIGN:
source->state = ENTITY_STATE_TALKING;
target->state = ENTITY_STATE_TALKING;
textboxSetText("Sign", target->sign.text); textboxSetText("Sign", target->sign.text);
return; return;
case ENTITY_TYPE_DOOR:
textboxSetText("Door", "It's a door.");
return;
default: default:
return; return;
} }
@ -44,10 +47,11 @@ void entityInteractTile(
assertNotNull(source, "entityInteractTile: Source is NULL!"); assertNotNull(source, "entityInteractTile: Source is NULL!");
switch(tile) { switch(tile) {
case TILE_ID_WATER: case TILE_WATER:
textboxSetText(NULL, "You cannot swim."); textboxSetText(NULL, "A refreshing pool of water.");
source->state = ENTITY_STATE_TALKING; source->state = ENTITY_STATE_TALKING;
return; return;
default: default:
break; break;
} }

View File

@ -9,8 +9,11 @@
bool_t tileIsSolid(const tile_t tile) { bool_t tileIsSolid(const tile_t tile) {
switch(tile) { switch(tile) {
case TILE_ID_WATER: case TILE_WATER:
case TILE_BUILDING_WALL:
case TILE_ROOF:
return true; return true;
default: default:
return false; return false;

View File

@ -9,9 +9,12 @@
#include "dawn.h" #include "dawn.h"
typedef enum { typedef enum {
TILE_ID_NULL = 0, TILE_NULL = 0,
TILE_ID_GRASS = 1, TILE_GRASS = 1,
TILE_ID_WATER = 2 TILE_WATER = 2,
// TILE_DOOR = 3,
TILE_BUILDING_WALL = 4,
TILE_ROOF = 5
} tile_t; } tile_t;
/** /**