Basic NPC loading (half done)
This commit is contained in:
@ -27,6 +27,7 @@ target_include_directories(${DUSK_TARGET_NAME}
|
||||
# Sources
|
||||
target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
input.c
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "world/chunk.h"
|
||||
#include "world/overworld.h"
|
||||
#include "display/render.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
Camera2D DRAW_OVERWORLD_CAMERA = { 0 };
|
||||
|
||||
@ -36,6 +37,7 @@ void drawOverworldDraw(void) {
|
||||
|
||||
BeginMode2D(DRAW_OVERWORLD_CAMERA);
|
||||
|
||||
// Bottom layer
|
||||
chunk_t *chunk = CHUNK_MAP.chunks;
|
||||
do {
|
||||
DrawRectangle(
|
||||
@ -48,5 +50,62 @@ void drawOverworldDraw(void) {
|
||||
chunk++;
|
||||
} while(chunk < CHUNK_MAP.chunks + CHUNK_MAP_COUNT);
|
||||
|
||||
// Entities
|
||||
entity_t *entity = ENTITIES;
|
||||
do {
|
||||
drawOverworldDrawEntity(entity++);
|
||||
} while(entity->type != ENTITY_TYPE_NULL);
|
||||
|
||||
EndMode2D();
|
||||
}
|
||||
|
||||
|
||||
void drawOverworldDrawEntity(const entity_t *entity) {
|
||||
assertNotNull(entity, "Entity pointer cannot be NULL");
|
||||
|
||||
uint32_t x = (uint32_t)floorf(entity->x);
|
||||
uint32_t y = (uint32_t)floorf(entity->y);
|
||||
|
||||
DrawRectangle(
|
||||
x,
|
||||
y,
|
||||
TILE_WIDTH,
|
||||
TILE_HEIGHT,
|
||||
(entity->type == ENTITY_TYPE_PLAYER) ? BLUE : YELLOW
|
||||
);
|
||||
|
||||
switch(entity->dir) {
|
||||
case ENTITY_DIR_NORTH:
|
||||
DrawTriangle(
|
||||
(Vector2){ x + TILE_WIDTH / 2, y },
|
||||
(Vector2){ x, y + TILE_HEIGHT },
|
||||
(Vector2){ x + TILE_WIDTH, y + TILE_HEIGHT },
|
||||
WHITE
|
||||
);
|
||||
break;
|
||||
case ENTITY_DIR_SOUTH:
|
||||
DrawTriangle(
|
||||
(Vector2){ x + TILE_WIDTH / 2, y + TILE_HEIGHT },
|
||||
(Vector2){ x + TILE_WIDTH, y },
|
||||
(Vector2){ x, y },
|
||||
WHITE
|
||||
);
|
||||
break;
|
||||
case ENTITY_DIR_WEST:
|
||||
DrawTriangle(
|
||||
(Vector2){ x, y + TILE_HEIGHT / 2 },
|
||||
(Vector2){ x + TILE_WIDTH, y + TILE_HEIGHT },
|
||||
(Vector2){ x + TILE_WIDTH, y },
|
||||
WHITE
|
||||
);
|
||||
break;
|
||||
case ENTITY_DIR_EAST:
|
||||
DrawTriangle(
|
||||
(Vector2){ x + TILE_WIDTH, y + TILE_HEIGHT / 2 },
|
||||
(Vector2){ x, y },
|
||||
(Vector2){ x, y + TILE_HEIGHT },
|
||||
WHITE
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "duskraylib.h"
|
||||
#include "entity/entity.h"
|
||||
|
||||
/**
|
||||
* Initializes the overworld drawing system.
|
||||
@ -16,4 +17,11 @@ void drawOverworldInit(void);
|
||||
/**
|
||||
* Renders the overworld, including map and characters.
|
||||
*/
|
||||
void drawOverworldDraw(void);
|
||||
void drawOverworldDraw(void);
|
||||
|
||||
/**
|
||||
* Renders a specific entity in the overworld.
|
||||
*
|
||||
* @param entity The entity to render.
|
||||
*/
|
||||
void drawOverworldDrawEntity(const entity_t *entity);
|
45
src/duskraylib/input.c
Normal file
45
src/duskraylib/input.c
Normal file
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "duskraylib.h"
|
||||
#include "input.h"
|
||||
|
||||
typedef struct {
|
||||
int32_t key;
|
||||
uint8_t bind;
|
||||
} inputmap_t;
|
||||
|
||||
inputmap_t INPUT_MAP[] = {
|
||||
{ KEY_UP, INPUT_BIND_UP },
|
||||
{ KEY_W, INPUT_BIND_UP },
|
||||
{ KEY_DOWN, INPUT_BIND_DOWN },
|
||||
{ KEY_S, INPUT_BIND_DOWN },
|
||||
{ KEY_LEFT, INPUT_BIND_LEFT },
|
||||
{ KEY_A, INPUT_BIND_LEFT },
|
||||
{ KEY_RIGHT, INPUT_BIND_RIGHT },
|
||||
{ KEY_D, INPUT_BIND_RIGHT },
|
||||
|
||||
{ KEY_SPACE, INPUT_BIND_ACTION },
|
||||
{ KEY_E, INPUT_BIND_ACTION },
|
||||
{ KEY_ENTER, INPUT_BIND_ACTION },
|
||||
|
||||
{ KEY_ESCAPE, INPUT_BIND_CANCEL },
|
||||
{ KEY_Q, INPUT_BIND_CANCEL },
|
||||
{ KEY_BACKSPACE, INPUT_BIND_CANCEL },
|
||||
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
uint8_t inputStateGet() {
|
||||
uint8_t state = 0;
|
||||
inputmap_t *map = INPUT_MAP;
|
||||
do {
|
||||
if(IsKeyDown(map->key)) state |= map->bind;
|
||||
map++;
|
||||
} while(map->key != 0);
|
||||
return state;
|
||||
}
|
Reference in New Issue
Block a user