Render test
This commit is contained in:
34
src/duskraylib/CMakeLists.txt
Normal file
34
src/duskraylib/CMakeLists.txt
Normal file
@ -0,0 +1,34 @@
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
# Libs
|
||||
FetchContent_Declare(
|
||||
raylib
|
||||
URL https://github.com/raysan5/raylib/archive/refs/tags/5.5.tar.gz
|
||||
URL_HASH MD5=61638c4c2c097fbca1d6a71e4da36c16
|
||||
)
|
||||
FetchContent_MakeAvailable(raylib)
|
||||
|
||||
target_link_libraries(${DUSK_TARGET_NAME}
|
||||
PUBLIC
|
||||
raylib
|
||||
)
|
||||
|
||||
# Includes
|
||||
target_include_directories(${DUSK_TARGET_NAME}
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Sources
|
||||
target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
input.c
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(display)
|
10
src/duskraylib/display/CMakeLists.txt
Normal file
10
src/duskraylib/display/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
|
||||
render.c
|
||||
)
|
53
src/duskraylib/display/render.c
Normal file
53
src/duskraylib/display/render.c
Normal file
@ -0,0 +1,53 @@
|
||||
/**
|
||||
* 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 "rpg/entity/entity.h"
|
||||
|
||||
const uint16_t RENDER_WIDTH = 800;
|
||||
const uint16_t RENDER_HEIGHT = 600;
|
||||
|
||||
void renderInit() {
|
||||
InitWindow(RENDER_WIDTH, RENDER_HEIGHT, "Dusk");
|
||||
SetTargetFPS(60);
|
||||
}
|
||||
|
||||
bool_t renderUpdate() {
|
||||
// End rendering?
|
||||
if(WindowShouldClose()) return false;
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
DrawText("Hello, Dusk!", 10, 10, 20, BLACK);
|
||||
|
||||
entity_t *ent = ENTITIES;
|
||||
do {
|
||||
if(ent->type == ENTITY_TYPE_NULL) {
|
||||
ent++;
|
||||
continue;
|
||||
}
|
||||
|
||||
DrawRectangle(
|
||||
(ent->x * ENTITY_WIDTH) + ent->subX,
|
||||
(ent->y * ENTITY_HEIGHT) + ent->subY,
|
||||
ENTITY_WIDTH,
|
||||
ENTITY_HEIGHT,
|
||||
RED
|
||||
);
|
||||
ent++;
|
||||
} while(ent < (ENTITIES + ENTITY_COUNT));
|
||||
|
||||
EndDrawing();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void renderDispose() {
|
||||
CloseWindow();
|
||||
}
|
47
src/duskraylib/input.c
Normal file
47
src/duskraylib/input.c
Normal file
@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "input.h"
|
||||
#include "raylib.h"
|
||||
|
||||
typedef struct {
|
||||
int32_t key;
|
||||
uint8_t flag;
|
||||
} inputmap_t;
|
||||
|
||||
const inputmap_t INPUT_MAP[] = {
|
||||
{ KEY_W, INPUT_UP },
|
||||
{ KEY_S, INPUT_DOWN },
|
||||
{ KEY_A, INPUT_LEFT },
|
||||
{ KEY_D, INPUT_RIGHT },
|
||||
{ KEY_SPACE, INPUT_ACTION },
|
||||
{ KEY_ESCAPE, INPUT_CANCEL },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
void inputInit() {
|
||||
|
||||
}
|
||||
|
||||
void inputUpdate() {
|
||||
uint8_t state = 0;
|
||||
inputmap_t *map = INPUT_MAP;
|
||||
|
||||
do {
|
||||
if(IsKeyDown(map->key)) {
|
||||
state |= map->flag;
|
||||
}
|
||||
map++;
|
||||
} while(map->key != 0);
|
||||
|
||||
INPUT.previous = INPUT.current;
|
||||
INPUT.current = state;
|
||||
}
|
||||
|
||||
void inputDispose() {
|
||||
|
||||
}
|
Reference in New Issue
Block a user