whatever
This commit is contained in:
@ -26,4 +26,5 @@ target_sources(${DUSK_TARGET_NAME}
|
||||
add_subdirectory(assert)
|
||||
add_subdirectory(display)
|
||||
add_subdirectory(rpg)
|
||||
add_subdirectory(util)
|
||||
add_subdirectory(util)
|
||||
add_subdirectory(ui)
|
@ -9,18 +9,21 @@
|
||||
#include "util/random.h"
|
||||
#include "display/render.h"
|
||||
|
||||
#include "ui/ui.h"
|
||||
#include "rpg/entity/entity.h"
|
||||
#include "rpg/world/maps/testmap.h"
|
||||
|
||||
int32_t main(const int32_t argc, const char **argv) {
|
||||
renderInit();
|
||||
inputInit();
|
||||
randomInit();
|
||||
renderInit();
|
||||
|
||||
|
||||
uiInit();
|
||||
mapSet(TEST_MAP);
|
||||
|
||||
while(1) {
|
||||
inputUpdate();
|
||||
uiUpdate();
|
||||
mapUpdate();
|
||||
if(!renderUpdate()) break;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ target_sources(${DUSK_TARGET_NAME}
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(entity)
|
||||
add_subdirectory(event)
|
||||
add_subdirectory(item)
|
||||
add_subdirectory(quest)
|
||||
add_subdirectory(world)
|
@ -8,6 +8,8 @@
|
||||
#include "entity.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
#include "ui/uitextbox.h"
|
||||
|
||||
void npcInit(entity_t *ent) {
|
||||
assertNotNull(ent, "NPC entity is NULL");
|
||||
assertTrue(ent->type == ENTITY_TYPE_NPC, "Entity is not an NPC");
|
||||
@ -26,6 +28,7 @@ bool_t npcInteract(entity_t *self, entity_t *player) {
|
||||
|
||||
// Look at the player
|
||||
entityTurn(self, entityGetLookDirection(self, player->x, player->y));
|
||||
eventStart(self->npc.event);
|
||||
|
||||
return true;
|
||||
}
|
@ -6,12 +6,12 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
#include "rpg/event/event.h"
|
||||
|
||||
typedef struct _entity_t entity_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t nothing; // Placeholder for NPC-specific data
|
||||
const event_t *event;
|
||||
} npc_t;
|
||||
|
||||
/**
|
||||
|
10
src/dusk/rpg/event/CMakeLists.txt
Normal file
10
src/dusk/rpg/event/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
event.c
|
||||
)
|
33
src/dusk/rpg/event/event.c
Normal file
33
src/dusk/rpg/event/event.c
Normal file
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "event.h"
|
||||
#include "assert/assert.h"
|
||||
#include "ui/uitextbox.h"
|
||||
#include "util/memory.h"
|
||||
|
||||
event_t eventCreate() {
|
||||
event_t event;
|
||||
return event;
|
||||
}
|
||||
|
||||
void eventStart(const event_t *event) {
|
||||
assertNotNull(event, "Event cannot be NULL");
|
||||
assertTrue(event->count <= EVENT_ITEMS_MAX, "Event count exceeds maximum items");
|
||||
assertTrue(event->count > 0, "Event must have at least one item");
|
||||
|
||||
switch(event->type) {
|
||||
case EVENT_TYPE_CONVERSATION: {
|
||||
assertTrue(event->items[0].type == EVENT_ITEM_TYPE_TEXT, "First item in conversation must be text");
|
||||
uiTextboxSetText(event->items[0].text.text);
|
||||
uiTextboxShow();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
assertFalse(true, "Unknown event type");
|
||||
}
|
||||
}
|
@ -8,6 +8,40 @@
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
typedef enum {
|
||||
EVENT_TYPE_CONVERSATION,
|
||||
} eventtype_t;
|
||||
|
||||
typedef enum {
|
||||
EVENT_ITEM_TYPE_TEXT
|
||||
} eventitemtype_t;
|
||||
|
||||
typedef struct {
|
||||
const char_t *text;
|
||||
} eventtext_t;
|
||||
|
||||
typedef struct {
|
||||
eventitemtype_t type;
|
||||
|
||||
} event_t;
|
||||
union {
|
||||
eventtext_t text;
|
||||
};
|
||||
} eventitem_t;
|
||||
|
||||
#define EVENT_ITEMS_MAX 16
|
||||
|
||||
typedef struct {
|
||||
eventtype_t type;
|
||||
uint8_t count;
|
||||
eventitem_t items[EVENT_ITEMS_MAX];
|
||||
} event_t;
|
||||
|
||||
/**
|
||||
* Creates a new event.
|
||||
*/
|
||||
event_t eventCreate();
|
||||
|
||||
/**
|
||||
* Starts a given event.
|
||||
*/
|
||||
void eventStart(const event_t *event);
|
9
src/dusk/rpg/event/eventtext.h
Normal file
9
src/dusk/rpg/event/eventtext.h
Normal file
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
@ -8,10 +8,21 @@
|
||||
#pragma once
|
||||
#include "rpg/entity/entity.h"
|
||||
#include "rpg/world/map.h"
|
||||
#include "rpg/event/event.h"
|
||||
|
||||
const event_t TEST_MAP_NPC_TEST = {
|
||||
.type = EVENT_TYPE_CONVERSATION,
|
||||
.count = 1,
|
||||
.items = {
|
||||
{
|
||||
.type = EVENT_ITEM_TYPE_TEXT,
|
||||
.text = { .text = "Hello, player! How can I help you today?" }
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Initializes the test map.
|
||||
*
|
||||
* This function sets up a test map with predefined dimensions.
|
||||
*/
|
||||
void testMapInit() {
|
||||
@ -23,6 +34,7 @@ void testMapInit() {
|
||||
ent++;
|
||||
entityInit(ent, ENTITY_TYPE_NPC);
|
||||
entityPositionSet(ent, 5, 5);
|
||||
ent->npc.event = &TEST_MAP_NPC_TEST;
|
||||
}
|
||||
|
||||
mapinfo_t TEST_MAP = {
|
||||
|
13
src/dusk/ui/CMakeLists.txt
Normal file
13
src/dusk/ui/CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
ui.c
|
||||
uitextbox.c
|
||||
)
|
||||
|
||||
# Subdirs
|
21
src/dusk/ui/ui.c
Normal file
21
src/dusk/ui/ui.c
Normal file
@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "ui.h"
|
||||
#include "util/memory.h"
|
||||
#include "ui/uitextbox.h"
|
||||
|
||||
ui_t UI;
|
||||
|
||||
void uiInit() {
|
||||
memoryZero(&UI, sizeof(ui_t));
|
||||
uiTextboxInit();
|
||||
}
|
||||
|
||||
void uiUpdate() {
|
||||
uiTextboxUpdate();
|
||||
}
|
30
src/dusk/ui/ui.h
Normal file
30
src/dusk/ui/ui.h
Normal file
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
typedef enum {
|
||||
UI_FOCUS_TEXTBOX
|
||||
} uifocus_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t nothing;
|
||||
} ui_t;
|
||||
|
||||
extern ui_t UI;
|
||||
|
||||
/**
|
||||
* Initializes the UI system.
|
||||
*/
|
||||
void uiInit();
|
||||
|
||||
/**
|
||||
* Updates the UI system.
|
||||
* This function should be called every frame to update the UI state.
|
||||
*/
|
||||
void uiUpdate();
|
43
src/dusk/ui/uitextbox.c
Normal file
43
src/dusk/ui/uitextbox.c
Normal file
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "uitextbox.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "display/render.h"
|
||||
#include "input.h"
|
||||
|
||||
uitextbox_t UI_TEXTBOX;
|
||||
|
||||
void uiTextboxInit() {
|
||||
memoryZero(&UI_TEXTBOX, sizeof(uitextbox_t));
|
||||
|
||||
UI_TEXTBOX.width = RENDER_WIDTH;
|
||||
UI_TEXTBOX.height = 58;
|
||||
UI_TEXTBOX.x = 0;
|
||||
UI_TEXTBOX.y = RENDER_HEIGHT - UI_TEXTBOX.height;
|
||||
}
|
||||
|
||||
void uiTextboxUpdate() {
|
||||
if(!UI_TEXTBOX.visible) return;
|
||||
|
||||
if(inputWasPressed(INPUT_ACTION)) {
|
||||
UI_TEXTBOX.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
void uiTextboxSetText(const char_t *text) {
|
||||
sprintf(UI_TEXTBOX.text, "%s", text);
|
||||
}
|
||||
|
||||
void uiTextboxShow() {
|
||||
UI_TEXTBOX.visible = true;
|
||||
}
|
||||
|
||||
void uiTextboxHide() {
|
||||
UI_TEXTBOX.visible = false;
|
||||
}
|
49
src/dusk/ui/uitextbox.h
Normal file
49
src/dusk/ui/uitextbox.h
Normal file
@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
#define UI_TEXTBOX_TEXT_MAX_LENGTH 1024
|
||||
|
||||
typedef struct {
|
||||
bool_t visible;
|
||||
|
||||
char_t text[UI_TEXTBOX_TEXT_MAX_LENGTH];
|
||||
|
||||
uint16_t width, height;
|
||||
uint16_t x, y;
|
||||
} uitextbox_t;
|
||||
|
||||
extern uitextbox_t UI_TEXTBOX;
|
||||
|
||||
/**
|
||||
* Initializes the UI textbox.
|
||||
*/
|
||||
void uiTextboxInit();
|
||||
|
||||
/**
|
||||
* Updates the UI textbox.
|
||||
*/
|
||||
void uiTextboxUpdate();
|
||||
|
||||
/**
|
||||
* Sets the text of the UI textbox.
|
||||
*
|
||||
* @param text The text to set in the textbox.
|
||||
*/
|
||||
void uiTextboxSetText(const char_t *text);
|
||||
|
||||
/**
|
||||
* Shows the UI textbox.
|
||||
*/
|
||||
void uiTextboxShow();
|
||||
|
||||
/**
|
||||
* Hides the UI textbox.
|
||||
*/
|
||||
void uiTextboxHide();
|
@ -6,5 +6,8 @@
|
||||
# Sources
|
||||
target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
render.c
|
||||
)
|
||||
renderraylib.c
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(draw)
|
11
src/duskraylib/display/draw/CMakeLists.txt
Normal file
11
src/duskraylib/display/draw/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
drawentity.c
|
||||
drawui.c
|
||||
)
|
@ -5,31 +5,13 @@
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "assert/assert.h"
|
||||
#include "display/render.h"
|
||||
#include "raylib.h"
|
||||
#include "drawentity.h"
|
||||
#include "rpg/world/map.h"
|
||||
|
||||
const uint16_t RENDER_WIDTH = 480;
|
||||
const uint16_t RENDER_HEIGHT = 270;
|
||||
|
||||
void renderInit() {
|
||||
InitWindow(RENDER_WIDTH, RENDER_HEIGHT, "Dusk");
|
||||
SetTargetFPS(60);
|
||||
}
|
||||
|
||||
bool_t renderUpdate() {
|
||||
void drawEntities() {
|
||||
uint8_t x, y;
|
||||
char_t buffer[64];
|
||||
|
||||
// End rendering?
|
||||
if(WindowShouldClose()) return false;
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
DrawText("Hello, Dusk!", 10, 10, 20, BLACK);
|
||||
|
||||
entity_t *ent = MAP.entities;
|
||||
|
||||
do {
|
||||
if(ent->type == ENTITY_TYPE_NULL) {
|
||||
ent++;
|
||||
@ -39,12 +21,6 @@ bool_t renderUpdate() {
|
||||
x = ent->x * ENTITY_WIDTH + ent->subX;
|
||||
y = ent->y * ENTITY_HEIGHT + ent->subY;
|
||||
|
||||
// DrawRectangle(
|
||||
// x, y,
|
||||
// ENTITY_WIDTH, ENTITY_HEIGHT,
|
||||
// BLUE
|
||||
// );
|
||||
|
||||
switch(ent->dir) {
|
||||
case ENTITY_DIR_UP:
|
||||
DrawTriangle(
|
||||
@ -79,17 +55,9 @@ bool_t renderUpdate() {
|
||||
);
|
||||
break;
|
||||
default:
|
||||
assertUnreachable("Invalid entity direction");
|
||||
break;
|
||||
}
|
||||
|
||||
ent++;
|
||||
} while(ent < (MAP.entities + MAP_ENTITY_COUNT));
|
||||
|
||||
EndDrawing();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void renderDispose() {
|
||||
CloseWindow();
|
||||
} while(ent->type != ENTITY_TYPE_NULL);
|
||||
}
|
14
src/duskraylib/display/draw/drawentity.h
Normal file
14
src/duskraylib/display/draw/drawentity.h
Normal file
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "display/renderraylib.h"
|
||||
|
||||
/**
|
||||
* Draws all entities on the map.
|
||||
*/
|
||||
void drawEntities();
|
27
src/duskraylib/display/draw/drawui.c
Normal file
27
src/duskraylib/display/draw/drawui.c
Normal file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "drawui.h"
|
||||
#include "ui/ui.h"
|
||||
#include "ui/uitextbox.h"
|
||||
|
||||
void drawUITextbox() {
|
||||
if(!UI_TEXTBOX.visible) return;
|
||||
|
||||
DrawRectangle(
|
||||
UI_TEXTBOX.x, UI_TEXTBOX.y,
|
||||
UI_TEXTBOX.width, UI_TEXTBOX.height,
|
||||
Fade(SKYBLUE, 0.5f)
|
||||
);
|
||||
|
||||
DrawTextEx(
|
||||
FONT,
|
||||
UI_TEXTBOX.text,
|
||||
(Vector2){ UI_TEXTBOX.x + 2, UI_TEXTBOX.y + 2 },
|
||||
FONT.baseSize, 0, BLACK
|
||||
);
|
||||
}
|
14
src/duskraylib/display/draw/drawui.h
Normal file
14
src/duskraylib/display/draw/drawui.h
Normal file
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "display/renderraylib.h"
|
||||
|
||||
/**
|
||||
* Draws the UI textbox.
|
||||
*/
|
||||
void drawUITextbox();
|
49
src/duskraylib/display/renderraylib.c
Normal file
49
src/duskraylib/display/renderraylib.c
Normal file
@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "assert/assert.h"
|
||||
#include "display/render.h"
|
||||
#include <raylib.h>
|
||||
|
||||
#include "display/draw/drawentity.h"
|
||||
#include "display/draw/drawui.h"
|
||||
|
||||
const uint16_t RENDER_WIDTH = 480;
|
||||
const uint16_t RENDER_HEIGHT = 270;
|
||||
Font FONT;
|
||||
|
||||
void renderInit() {
|
||||
InitWindow(RENDER_WIDTH, RENDER_HEIGHT, "Dusk");
|
||||
SetTargetFPS(60);
|
||||
|
||||
FONT = LoadFontEx(
|
||||
"../assets/ark-pixel-font/12px/monospaced/ark-pixel-12px-monospaced-latin.otf",
|
||||
12, NULL, 0
|
||||
);
|
||||
}
|
||||
|
||||
bool_t renderUpdate() {
|
||||
uint8_t x, y;
|
||||
char_t buffer[64];
|
||||
|
||||
// End rendering?
|
||||
if(WindowShouldClose()) return false;
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
drawEntities();
|
||||
drawUITextbox();
|
||||
|
||||
EndDrawing();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void renderDispose() {
|
||||
CloseWindow();
|
||||
}
|
12
src/duskraylib/display/renderraylib.h
Normal file
12
src/duskraylib/display/renderraylib.h
Normal file
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "display/render.h"
|
||||
#include <raylib.h>
|
||||
|
||||
extern Font FONT;
|
Reference in New Issue
Block a user