Files
dusk/src/duskraylib/display/render.c
2025-06-10 17:24:12 -05:00

95 lines
2.1 KiB
C

/**
* 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 = 480;
const uint16_t RENDER_HEIGHT = 270;
void renderInit() {
InitWindow(RENDER_WIDTH, RENDER_HEIGHT, "Dusk");
SetTargetFPS(60);
}
bool_t renderUpdate() {
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 = ENTITIES;
do {
if(ent->type == ENTITY_TYPE_NULL) {
ent++;
continue;
}
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(
(Vector2){ x, y + ENTITY_HEIGHT },
(Vector2){ x + ENTITY_WIDTH, y + ENTITY_HEIGHT },
(Vector2){ x + ENTITY_WIDTH / 2, y },
RED
);
break;
case ENTITY_DIR_DOWN:
DrawTriangle(
(Vector2){ x, y },
(Vector2){ x + ENTITY_WIDTH / 2, y + ENTITY_HEIGHT },
(Vector2){ x + ENTITY_WIDTH, y },
RED
);
break;
case ENTITY_DIR_LEFT:
DrawTriangle(
(Vector2){ x + ENTITY_WIDTH, y },
(Vector2){ x, y + ENTITY_HEIGHT / 2 },
(Vector2){ x + ENTITY_WIDTH, y + ENTITY_HEIGHT },
RED
);
break;
case ENTITY_DIR_RIGHT:
DrawTriangle(
(Vector2){ x, y },
(Vector2){ x, y + ENTITY_HEIGHT },
(Vector2){ x + ENTITY_WIDTH, y + ENTITY_HEIGHT / 2 },
RED
);
break;
default:
assertUnreachable("Invalid entity direction");
}
ent++;
} while(ent < (ENTITIES + ENTITY_COUNT));
EndDrawing();
return true;
}
void renderDispose() {
CloseWindow();
}