This commit is contained in:
2025-06-11 09:42:20 -05:00
parent d1b1ecf3ca
commit e3438cae77
28 changed files with 451 additions and 375 deletions

View File

@ -6,5 +6,8 @@
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
render.c
)
renderraylib.c
)
# Subdirs
add_subdirectory(draw)

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

View File

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

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

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

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

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

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