Compare commits
8 commits
4fe03a8952
...
64205e137c
| Author | SHA1 | Date | |
|---|---|---|---|
|
64205e137c |
|||
|
901f063696 |
|||
|
20f8c71fdf |
|||
| 4dfe52ae72 | |||
|
1d738c35d4 |
|||
| eed5c3aff3 | |||
| 3998fb5259 | |||
| 6050083293 |
14 changed files with 417 additions and 249 deletions
BIN
assets/fonts/Royal_Decree.ttf
Normal file
BIN
assets/fonts/Royal_Decree.ttf
Normal file
Binary file not shown.
BIN
assets/fonts/Royal_Decree_Bold.ttf
Normal file
BIN
assets/fonts/Royal_Decree_Bold.ttf
Normal file
Binary file not shown.
|
|
@ -25,6 +25,7 @@ pub fn build(b: *std.Build) void {
|
||||||
"src/main.c",
|
"src/main.c",
|
||||||
"src/map.c",
|
"src/map.c",
|
||||||
"src/player.c",
|
"src/player.c",
|
||||||
|
"src/movement.c",
|
||||||
"src/render.c",
|
"src/render.c",
|
||||||
"src/rng.c",
|
"src/rng.c",
|
||||||
"src/settings.c",
|
"src/settings.c",
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
# Rogged
|
# Rogged
|
||||||
|
|
||||||
Turn-based roguelike dungeon crawler, built in C99 and with a dash of Zig to
|
Turn-based, infinite roguelike dungeon crawler built with C99 and with a dash of
|
||||||
serve as a learning opportunity. Rogged is basically a classic roguelike where
|
Zig. Meant to serve primarily, but not exclusively, as a learning opportunity.
|
||||||
you descend through floors of a procedurally generated dungeon, fighting
|
Rogged is basically a classic roguelike where you descend through floors of a
|
||||||
enemies, managing inventory, and trying to reach the bottom alive.
|
procedurally generated dungeon, fighting enemies, managing inventory, and trying
|
||||||
|
to reach the bottom alive or die chasing a highscore!
|
||||||
|
|
||||||
A non-exhaustive list of its (current) features:
|
The game itself, be it the code or mechanics, is _heavily_ in development. For
|
||||||
|
now, a non-exhaustive list of its (current) features are as follows:
|
||||||
|
|
||||||
- Turn-based combat with damage variance, critical hits, dodge, and block
|
- Turn-based combat with damage variance, critical hits, dodge, and block
|
||||||
mechanics
|
mechanics
|
||||||
|
|
@ -18,33 +20,27 @@ A non-exhaustive list of its (current) features:
|
||||||
- Procedural audio via raylib
|
- Procedural audio via raylib
|
||||||
- ASCII-inspired tile rendering, with HP bars and floating damage text
|
- ASCII-inspired tile rendering, with HP bars and floating damage text
|
||||||
|
|
||||||
**Controls:**
|
There are still some features lacking polish, or lacking _any_ kind of attention
|
||||||
|
to be viable. For a semi-complete list of things that need to be done, see the
|
||||||
| Key | Action |
|
[future plans section](#future-plans).
|
||||||
| ------------- | ----------------------------------- |
|
|
||||||
| WASD / Arrows | Move or attack |
|
|
||||||
| G | Pick up item |
|
|
||||||
| I | Open inventory |
|
|
||||||
| U | Use a potion |
|
|
||||||
| E | Equip item from inventory |
|
|
||||||
| D | Drop item |
|
|
||||||
| Y / N | Confirm / decline descending stairs |
|
|
||||||
| R | Restart (on game over) |
|
|
||||||
| Q | Quit |
|
|
||||||
|
|
||||||
## Build Instructions
|
## Build Instructions
|
||||||
|
|
||||||
Rogged is built with C99 and Zig. Besides `raylib` and `pkg-config` you will
|
Rogged is built on a relatively simple stack. It uses C99 for the main game
|
||||||
need a C compiler and basic Zig tooling. For now, we use C99 and Zig 0.15.2.
|
logic, and Zig for the combat library. Besides `raylib` and `pkg-config`, you
|
||||||
Those might change in the future.
|
only need the core Zig tooling. For now the required Zig version is 0.15.2, but
|
||||||
|
this might change in the future. Additionally, you will need `clang-format` and
|
||||||
Additionally you will need `clang-format` and `just` for the developer workflow
|
`just` for common development tasks in the case you plan to contribute. For
|
||||||
if you plan to contribute.
|
building, Zig is enough.
|
||||||
|
|
||||||
### Using Nix (Recommended)
|
### Using Nix (Recommended)
|
||||||
|
|
||||||
The recommended developer tooling is [Nix](https://nixos.org). This provides a
|
The _recommended_ way of developing this project is using
|
||||||
pure, reproducible devshell across all machines.
|
[Nix](https://nixos.org) and relying on devshells for pure, reproducible
|
||||||
|
developer environment across all machines.
|
||||||
|
|
||||||
|
If you are a [Direnv](https://direnv.net) user, you may simply run
|
||||||
|
`direnv allow` or you may use `nix develop` to enter the default shell.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# Enter the development shell
|
# Enter the development shell
|
||||||
|
|
@ -56,6 +52,9 @@ $ just dev
|
||||||
|
|
||||||
### Manual Build
|
### Manual Build
|
||||||
|
|
||||||
|
If you are allergic to good tooling and would rather use your system Zig, you
|
||||||
|
may simply invoke `zig build` after acquiring Zig 0.15.2.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# Full build
|
# Full build
|
||||||
$ zig build
|
$ zig build
|
||||||
|
|
@ -67,6 +66,8 @@ $ zig build run
|
||||||
$ just dev
|
$ just dev
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The Justfile provides commands that work across both methods.
|
||||||
|
|
||||||
### Task Runner Commands
|
### Task Runner Commands
|
||||||
|
|
||||||
There's a `Justfile` designed to make common tasks somewhat easier. For now,
|
There's a `Justfile` designed to make common tasks somewhat easier. For now,
|
||||||
|
|
@ -84,10 +85,14 @@ If the project gets more complicated, new tasks might be added.
|
||||||
|
|
||||||
## Future Plans
|
## Future Plans
|
||||||
|
|
||||||
The game is currently **playable end-to-end** but it lacks _serious_ polish to
|
The game is currently **playable end-to-end**, but it lacks a fair bit of polish
|
||||||
claim its place as a fun roguelike. Some of the features I'd like to introduce,
|
to claim its place as a fun, engaging roguelike you can just boot up and play.
|
||||||
in no particular order, are as follows:
|
Some of the features that are planned for the future, in no particular order,
|
||||||
|
are as follows:
|
||||||
|
|
||||||
|
- [ ] **Better enemy AI** - The current AI is very simple.
|
||||||
|
- [ ] **Fog of War** - Instead of loading the entire map, let the player
|
||||||
|
discover the rooms
|
||||||
- [ ] **Save / Load system** - Persist and restore game state between sessions
|
- [ ] **Save / Load system** - Persist and restore game state between sessions
|
||||||
- [ ] **More enemy variety** - Additional enemy types with unique abilities
|
- [ ] **More enemy variety** - Additional enemy types with unique abilities
|
||||||
- [ ] **More item variety** - Rings, wands, scrolls, and cursed items
|
- [ ] **More item variety** - Rings, wands, scrolls, and cursed items
|
||||||
|
|
@ -100,8 +105,9 @@ in no particular order, are as follows:
|
||||||
- [ ] **UI polish** - Better message log history, item descriptions, death
|
- [ ] **UI polish** - Better message log history, item descriptions, death
|
||||||
screen
|
screen
|
||||||
|
|
||||||
In addition, it might be interesting to allow customizing the "world state" by
|
Later down the line it might be an interesting choice to provide a scripting
|
||||||
as scripting API. Though, that is for much later.
|
API, likely with Lua, to allow customizing the game state and events. Though,
|
||||||
|
that is for much later.
|
||||||
|
|
||||||
## Attributions
|
## Attributions
|
||||||
|
|
||||||
|
|
@ -118,4 +124,6 @@ Additionally, _huge_ thanks to [Raylib] for how easy it made graphics and audio.
|
||||||
This was perhaps my best experience in developing a graphical application, and
|
This was perhaps my best experience in developing a graphical application, and
|
||||||
CERTAINLY the most ergonomic when it comes to writing a game.
|
CERTAINLY the most ergonomic when it comes to writing a game.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
_I got rogged :/_
|
_I got rogged :/_
|
||||||
12
src/common.h
12
src/common.h
|
|
@ -4,6 +4,10 @@
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int x, y;
|
||||||
|
} Vec2;
|
||||||
|
|
||||||
// Tile types
|
// Tile types
|
||||||
typedef enum { TILE_WALL, TILE_FLOOR, TILE_STAIRS } TileType;
|
typedef enum { TILE_WALL, TILE_FLOOR, TILE_STAIRS } TileType;
|
||||||
|
|
||||||
|
|
@ -57,7 +61,7 @@ typedef struct {
|
||||||
|
|
||||||
// Player
|
// Player
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int x, y;
|
Vec2 position;
|
||||||
int hp, max_hp;
|
int hp, max_hp;
|
||||||
int attack;
|
int attack;
|
||||||
int defense;
|
int defense;
|
||||||
|
|
@ -83,7 +87,7 @@ typedef enum { ENEMY_GOBLIN, ENEMY_SKELETON, ENEMY_ORC } EnemyType;
|
||||||
|
|
||||||
// Enemy
|
// Enemy
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int x, y;
|
Vec2 position;
|
||||||
int hp;
|
int hp;
|
||||||
int max_hp;
|
int max_hp;
|
||||||
int attack;
|
int attack;
|
||||||
|
|
@ -104,12 +108,14 @@ typedef struct {
|
||||||
} Enemy;
|
} Enemy;
|
||||||
|
|
||||||
// Floating damage text
|
// Floating damage text
|
||||||
|
typedef enum { LABEL_NONE = 0, LABEL_DODGE, LABEL_BLOCK, LABEL_CRIT, LABEL_SLAIN, LABEL_PROC } FloatingLabel;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int x, y;
|
int x, y;
|
||||||
int value;
|
int value;
|
||||||
int lifetime; // frames remaining
|
int lifetime; // frames remaining
|
||||||
int is_critical;
|
int is_critical;
|
||||||
char label[8]; // non-empty -> show label instead of numeric value
|
FloatingLabel label; // label type instead of string
|
||||||
StatusEffectType effect_type; // used to pick color for proc labels
|
StatusEffectType effect_type; // used to pick color for proc labels
|
||||||
} FloatingText;
|
} FloatingText;
|
||||||
|
|
||||||
|
|
|
||||||
49
src/enemy.c
49
src/enemy.c
|
|
@ -2,6 +2,7 @@
|
||||||
#include "combat.h"
|
#include "combat.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
|
#include "movement.h"
|
||||||
#include "rng.h"
|
#include "rng.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
@ -29,7 +30,7 @@ void enemy_spawn(Enemy enemies[], int *count, Map *map, Player *p, int floor) {
|
||||||
get_random_floor_tile(map, &ex, &ey, 50);
|
get_random_floor_tile(map, &ex, &ey, 50);
|
||||||
|
|
||||||
// Don't spawn on player position
|
// Don't spawn on player position
|
||||||
if (ex == p->x && ey == p->y) {
|
if (ex == p->position.x && ey == p->position.y) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,8 +42,8 @@ void enemy_spawn(Enemy enemies[], int *count, Map *map, Player *p, int floor) {
|
||||||
// Create enemy
|
// Create enemy
|
||||||
Enemy e;
|
Enemy e;
|
||||||
memset(&e, 0, sizeof(Enemy));
|
memset(&e, 0, sizeof(Enemy));
|
||||||
e.x = ex;
|
e.position.x = ex;
|
||||||
e.y = ey;
|
e.position.y = ey;
|
||||||
e.alive = 1;
|
e.alive = 1;
|
||||||
e.type = rng_int(ENEMY_GOBLIN, max_type);
|
e.type = rng_int(ENEMY_GOBLIN, max_type);
|
||||||
e.effect_count = 0;
|
e.effect_count = 0;
|
||||||
|
|
@ -127,7 +128,7 @@ void enemy_spawn(Enemy enemies[], int *count, Map *map, Player *p, int floor) {
|
||||||
// Check if position has an enemy
|
// Check if position has an enemy
|
||||||
int is_enemy_at(const Enemy *enemies, int count, int x, int y) {
|
int is_enemy_at(const Enemy *enemies, int count, int x, int y) {
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
if (enemies[i].alive && enemies[i].x == x && enemies[i].y == y) {
|
if (enemies[i].alive && enemies[i].position.x == x && enemies[i].position.y == y) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -136,45 +137,37 @@ int is_enemy_at(const Enemy *enemies, int count, int x, int y) {
|
||||||
|
|
||||||
// Check if enemy can see player (adjacent)
|
// Check if enemy can see player (adjacent)
|
||||||
static int can_see_player(Enemy *e, Player *p) {
|
static int can_see_player(Enemy *e, Player *p) {
|
||||||
int dx = p->x - e->x;
|
int dx = p->position.x - e->position.x;
|
||||||
int dy = p->y - e->y;
|
int dy = p->position.y - e->position.y;
|
||||||
return (dx >= -1 && dx <= 1 && dy >= -1 && dy <= 1);
|
return (dx >= -1 && dx <= 1 && dy >= -1 && dy <= 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if position is occupied by player
|
|
||||||
static int is_player_at(Player *p, int x, int y) {
|
|
||||||
return (p->x == x && p->y == y);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move enemy toward player
|
// Move enemy toward player
|
||||||
static void enemy_move_toward_player(Enemy *e, Player *p, Map *map, Enemy *all_enemies, int enemy_count) {
|
static void enemy_move_toward_player(Enemy *e, Player *p, Map *map, Enemy *all_enemies, int enemy_count) {
|
||||||
int dx = 0, dy = 0;
|
int dx = 0, dy = 0;
|
||||||
|
|
||||||
if (p->x > e->x)
|
if (p->position.x > e->position.x)
|
||||||
dx = 1;
|
dx = 1;
|
||||||
else if (p->x < e->x)
|
else if (p->position.x < e->position.x)
|
||||||
dx = -1;
|
dx = -1;
|
||||||
|
|
||||||
if (p->y > e->y)
|
if (p->position.y > e->position.y)
|
||||||
dy = 1;
|
dy = 1;
|
||||||
else if (p->y < e->y)
|
else if (p->position.y < e->position.y)
|
||||||
dy = -1;
|
dy = -1;
|
||||||
|
|
||||||
// Try horizontal first, then vertical
|
Vec2 dir = {dx, 0};
|
||||||
int new_x = e->x + dx;
|
if (dx != 0) {
|
||||||
int new_y = e->y;
|
MoveResult r = try_move_entity(&e->position, dir, map, p, all_enemies, enemy_count, false);
|
||||||
|
if (r == MOVE_RESULT_MOVED)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (dx != 0 && is_floor(map, new_x, new_y) && !is_enemy_at(all_enemies, enemy_count, new_x, new_y) &&
|
dir.x = 0;
|
||||||
!is_player_at(p, new_x, new_y)) {
|
dir.y = dy;
|
||||||
e->x = new_x;
|
if (dy != 0) {
|
||||||
} else if (dy != 0) {
|
try_move_entity(&e->position, dir, map, p, all_enemies, enemy_count, false);
|
||||||
new_x = e->x;
|
|
||||||
new_y = e->y + dy;
|
|
||||||
if (is_floor(map, new_x, new_y) && !is_enemy_at(all_enemies, enemy_count, new_x, new_y) &&
|
|
||||||
!is_player_at(p, new_x, new_y)) {
|
|
||||||
e->x = new_x;
|
|
||||||
e->y = new_y;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
124
src/main.c
124
src/main.c
|
|
@ -4,6 +4,7 @@
|
||||||
#include "enemy.h"
|
#include "enemy.h"
|
||||||
#include "items.h"
|
#include "items.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
|
#include "movement.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
|
|
@ -42,14 +43,14 @@ static void spawn_floating_text(GameState *gs, int x, int y, int value, int is_c
|
||||||
gs->floating_texts[slot].x = x;
|
gs->floating_texts[slot].x = x;
|
||||||
gs->floating_texts[slot].y = y;
|
gs->floating_texts[slot].y = y;
|
||||||
gs->floating_texts[slot].value = value;
|
gs->floating_texts[slot].value = value;
|
||||||
gs->floating_texts[slot].lifetime = 60;
|
gs->floating_texts[slot].lifetime = FLOATING_TEXT_LIFETIME;
|
||||||
gs->floating_texts[slot].is_critical = is_critical;
|
gs->floating_texts[slot].is_critical = is_critical;
|
||||||
gs->floating_texts[slot].label[0] = '\0'; // numeric, no label
|
gs->floating_texts[slot].label = LABEL_NONE;
|
||||||
gs->floating_texts[slot].effect_type = EFFECT_NONE;
|
gs->floating_texts[slot].effect_type = EFFECT_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// spawn floating label text (DODGE, BLOCK, CRIT!, proc names, SLAIN)
|
// spawn floating label text (DODGE, BLOCK, CRIT!, proc names, SLAIN)
|
||||||
static void spawn_floating_label(GameState *gs, int x, int y, const char *label, StatusEffectType effect_type) {
|
static void spawn_floating_label(GameState *gs, int x, int y, FloatingLabel label, StatusEffectType effect_type) {
|
||||||
int slot = float_slot(gs);
|
int slot = float_slot(gs);
|
||||||
if (slot < 0)
|
if (slot < 0)
|
||||||
return;
|
return;
|
||||||
|
|
@ -58,25 +59,24 @@ static void spawn_floating_label(GameState *gs, int x, int y, const char *label,
|
||||||
gs->floating_texts[slot].value = 0;
|
gs->floating_texts[slot].value = 0;
|
||||||
gs->floating_texts[slot].lifetime = 60;
|
gs->floating_texts[slot].lifetime = 60;
|
||||||
gs->floating_texts[slot].is_critical = 0;
|
gs->floating_texts[slot].is_critical = 0;
|
||||||
|
gs->floating_texts[slot].label = label;
|
||||||
gs->floating_texts[slot].effect_type = effect_type;
|
gs->floating_texts[slot].effect_type = effect_type;
|
||||||
strncpy(gs->floating_texts[slot].label, label, 7);
|
|
||||||
gs->floating_texts[slot].label[7] = '\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *proc_label_for(StatusEffectType effect) {
|
static FloatingLabel proc_label_for(StatusEffectType effect) {
|
||||||
switch (effect) {
|
switch (effect) {
|
||||||
case EFFECT_POISON:
|
case EFFECT_POISON:
|
||||||
return "POISON!";
|
return LABEL_PROC;
|
||||||
case EFFECT_BLEED:
|
case EFFECT_BLEED:
|
||||||
return "BLEED!";
|
return LABEL_PROC;
|
||||||
case EFFECT_BURN:
|
case EFFECT_BURN:
|
||||||
return "BURN!";
|
return LABEL_PROC;
|
||||||
case EFFECT_STUN:
|
case EFFECT_STUN:
|
||||||
return "STUN!";
|
return LABEL_PROC;
|
||||||
case EFFECT_WEAKEN:
|
case EFFECT_WEAKEN:
|
||||||
return "WEAKEN!";
|
return LABEL_PROC;
|
||||||
default:
|
default:
|
||||||
return "";
|
return LABEL_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,8 +92,8 @@ static void update_effects(GameState *gs) {
|
||||||
// update screen shake
|
// update screen shake
|
||||||
if (gs->screen_shake > 0) {
|
if (gs->screen_shake > 0) {
|
||||||
gs->screen_shake--;
|
gs->screen_shake--;
|
||||||
gs->shake_x = rng_int(-4, 4);
|
gs->shake_x = rng_int(-SHAKE_MAX_OFFSET, SHAKE_MAX_OFFSET);
|
||||||
gs->shake_y = rng_int(-4, 4);
|
gs->shake_y = rng_int(-SHAKE_MAX_OFFSET, SHAKE_MAX_OFFSET);
|
||||||
} else {
|
} else {
|
||||||
gs->shake_x = 0;
|
gs->shake_x = 0;
|
||||||
gs->shake_y = 0;
|
gs->shake_y = 0;
|
||||||
|
|
@ -118,8 +118,8 @@ static void init_floor(GameState *gs, int floor_num) {
|
||||||
gs->floors_reached = 1;
|
gs->floors_reached = 1;
|
||||||
} else {
|
} else {
|
||||||
// Move player to new floor position
|
// Move player to new floor position
|
||||||
gs->player.x = start_x;
|
gs->player.position.x = start_x;
|
||||||
gs->player.y = start_y;
|
gs->player.position.y = start_y;
|
||||||
}
|
}
|
||||||
gs->player.floor = floor_num;
|
gs->player.floor = floor_num;
|
||||||
|
|
||||||
|
|
@ -138,8 +138,9 @@ static void tick_all_effects(GameState *gs) {
|
||||||
// Player effects
|
// Player effects
|
||||||
int player_effect_dmg = combat_tick_effects(&gs->player);
|
int player_effect_dmg = combat_tick_effects(&gs->player);
|
||||||
if (player_effect_dmg > 0) {
|
if (player_effect_dmg > 0) {
|
||||||
spawn_floating_text(gs, gs->player.x * TILE_SIZE + 8, gs->player.y * TILE_SIZE, player_effect_dmg, 0);
|
spawn_floating_text(gs, gs->player.position.x * TILE_SIZE + 8, gs->player.position.y * TILE_SIZE, player_effect_dmg,
|
||||||
gs->screen_shake = 4;
|
0);
|
||||||
|
gs->screen_shake = SHAKE_EFFECT_DURATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if player died from effects
|
// Check if player died from effects
|
||||||
|
|
@ -156,7 +157,7 @@ static void tick_all_effects(GameState *gs) {
|
||||||
continue;
|
continue;
|
||||||
int enemy_effect_dmg = combat_tick_enemy_effects(e);
|
int enemy_effect_dmg = combat_tick_enemy_effects(e);
|
||||||
if (enemy_effect_dmg > 0) {
|
if (enemy_effect_dmg > 0) {
|
||||||
spawn_floating_text(gs, e->x * TILE_SIZE + 8, e->y * TILE_SIZE, enemy_effect_dmg, 0);
|
spawn_floating_text(gs, e->position.x * TILE_SIZE + 8, e->position.y * TILE_SIZE, enemy_effect_dmg, 0);
|
||||||
}
|
}
|
||||||
if (!e->alive) {
|
if (!e->alive) {
|
||||||
add_log(gs, "Enemy died from effects!");
|
add_log(gs, "Enemy died from effects!");
|
||||||
|
|
@ -174,7 +175,7 @@ static void post_action(GameState *gs, Enemy *attacked_enemy) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Check if stepped on stairs
|
// Check if stepped on stairs
|
||||||
if (gs->map.tiles[gs->player.y][gs->player.x] == TILE_STAIRS) {
|
if (gs->map.tiles[gs->player.position.y][gs->player.position.x] == TILE_STAIRS) {
|
||||||
gs->awaiting_descend = 1;
|
gs->awaiting_descend = 1;
|
||||||
gs->last_message = "Descend to next floor? (Y/N)";
|
gs->last_message = "Descend to next floor? (Y/N)";
|
||||||
gs->message_timer = 120;
|
gs->message_timer = 120;
|
||||||
|
|
@ -183,11 +184,11 @@ static void post_action(GameState *gs, Enemy *attacked_enemy) {
|
||||||
|
|
||||||
// combat feedback - player attacked an enemy this turn
|
// combat feedback - player attacked an enemy this turn
|
||||||
if (attacked_enemy != NULL) {
|
if (attacked_enemy != NULL) {
|
||||||
int ex = attacked_enemy->x * TILE_SIZE + 8;
|
int ex = attacked_enemy->position.x * TILE_SIZE + 8;
|
||||||
int ey = attacked_enemy->y * TILE_SIZE;
|
int ey = attacked_enemy->position.y * TILE_SIZE;
|
||||||
|
|
||||||
if (combat_was_dodged()) {
|
if (combat_was_dodged()) {
|
||||||
spawn_floating_label(gs, ex, ey, "DODGE", EFFECT_NONE);
|
spawn_floating_label(gs, ex, ey, LABEL_DODGE, EFFECT_NONE);
|
||||||
audio_play_dodge(gs);
|
audio_play_dodge(gs);
|
||||||
} else {
|
} else {
|
||||||
if (combat_get_last_damage() > 0)
|
if (combat_get_last_damage() > 0)
|
||||||
|
|
@ -195,21 +196,21 @@ static void post_action(GameState *gs, Enemy *attacked_enemy) {
|
||||||
spawn_floating_text(gs, ex, ey, combat_get_last_damage(), combat_was_critical());
|
spawn_floating_text(gs, ex, ey, combat_get_last_damage(), combat_was_critical());
|
||||||
audio_play_attack(gs);
|
audio_play_attack(gs);
|
||||||
if (combat_was_blocked()) {
|
if (combat_was_blocked()) {
|
||||||
spawn_floating_label(gs, ex, ey - 10, "BLOCK", EFFECT_NONE);
|
spawn_floating_label(gs, ex, ey - 10, LABEL_BLOCK, EFFECT_NONE);
|
||||||
audio_play_block(gs);
|
audio_play_block(gs);
|
||||||
}
|
}
|
||||||
if (combat_was_critical()) {
|
if (combat_was_critical()) {
|
||||||
spawn_floating_label(gs, ex + 8, ey - 10, "CRIT!", EFFECT_NONE);
|
spawn_floating_label(gs, ex + 8, ey - 10, LABEL_CRIT, EFFECT_NONE);
|
||||||
audio_play_crit(gs);
|
audio_play_crit(gs);
|
||||||
gs->crits_landed++;
|
gs->crits_landed++;
|
||||||
}
|
}
|
||||||
StatusEffectType applied = combat_get_applied_effect();
|
StatusEffectType applied = combat_get_applied_effect();
|
||||||
if (applied != EFFECT_NONE) {
|
if (applied != EFFECT_NONE) {
|
||||||
spawn_floating_label(gs, ex, ey - 20, proc_label_for(applied), applied);
|
spawn_floating_label(gs, ex, ey - 20, LABEL_PROC, applied);
|
||||||
audio_play_proc();
|
audio_play_proc();
|
||||||
}
|
}
|
||||||
if (!attacked_enemy->alive) {
|
if (!attacked_enemy->alive) {
|
||||||
spawn_floating_label(gs, ex, ey - 20, "SLAIN", EFFECT_NONE);
|
spawn_floating_label(gs, ex, ey - 20, LABEL_SLAIN, EFFECT_NONE);
|
||||||
audio_play_enemy_death(gs);
|
audio_play_enemy_death(gs);
|
||||||
gs->total_kills++;
|
gs->total_kills++;
|
||||||
}
|
}
|
||||||
|
|
@ -222,11 +223,11 @@ static void post_action(GameState *gs, Enemy *attacked_enemy) {
|
||||||
// Check if player took damage
|
// Check if player took damage
|
||||||
if (combat_was_player_damage() && combat_get_last_damage() > 0) {
|
if (combat_was_player_damage() && combat_get_last_damage() > 0) {
|
||||||
audio_play_player_damage(gs);
|
audio_play_player_damage(gs);
|
||||||
gs->screen_shake = 8;
|
gs->screen_shake = SHAKE_PLAYER_DAMAGE_DURATION;
|
||||||
gs->damage_taken += combat_get_last_damage();
|
gs->damage_taken += combat_get_last_damage();
|
||||||
gs->times_hit++;
|
gs->times_hit++;
|
||||||
spawn_floating_text(gs, gs->player.x * TILE_SIZE + 8, gs->player.y * TILE_SIZE, combat_get_last_damage(),
|
spawn_floating_text(gs, gs->player.position.x * TILE_SIZE + 8, gs->player.position.y * TILE_SIZE,
|
||||||
combat_was_critical());
|
combat_get_last_damage(), combat_was_critical());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set message and check game over
|
// Set message and check game over
|
||||||
|
|
@ -389,7 +390,7 @@ static int handle_movement_input(GameState *gs) {
|
||||||
|
|
||||||
// Check for manual item pickup (G key)
|
// Check for manual item pickup (G key)
|
||||||
if (IsKeyPressed(KEY_G)) {
|
if (IsKeyPressed(KEY_G)) {
|
||||||
Item *item = get_item_at_floor(gs->items, gs->item_count, gs->player.x, gs->player.y);
|
Item *item = get_item_at_floor(gs->items, gs->item_count, gs->player.position.x, gs->player.position.y);
|
||||||
if (item != NULL) {
|
if (item != NULL) {
|
||||||
if (player_pickup(&gs->player, item)) {
|
if (player_pickup(&gs->player, item)) {
|
||||||
gs->items_collected++;
|
gs->items_collected++;
|
||||||
|
|
@ -418,38 +419,45 @@ static int handle_movement_input(GameState *gs) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Movement: use IsKeyDown for held-key repeat
|
|
||||||
int dx = 0, dy = 0;
|
|
||||||
if (IsKeyDown(KEY_W) || IsKeyDown(KEY_UP))
|
|
||||||
dy = -1;
|
|
||||||
else if (IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN))
|
|
||||||
dy = 1;
|
|
||||||
else if (IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT))
|
|
||||||
dx = -1;
|
|
||||||
else if (IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT))
|
|
||||||
dx = 1;
|
|
||||||
|
|
||||||
if (dx == 0 && dy == 0)
|
Vec2 direction = {0, 0};
|
||||||
|
if (IsKeyDown(KEY_W) || IsKeyDown(KEY_UP))
|
||||||
|
direction.y = -1;
|
||||||
|
else if (IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN))
|
||||||
|
direction.y = 1;
|
||||||
|
else if (IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT))
|
||||||
|
direction.x = -1;
|
||||||
|
else if (IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT))
|
||||||
|
direction.x = 1;
|
||||||
|
|
||||||
|
if (direction.x == 0 && direction.y == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// Reset combat event before player acts
|
// Reset combat event before player acts
|
||||||
combat_reset_event();
|
combat_reset_event();
|
||||||
|
|
||||||
int new_x = gs->player.x + dx;
|
|
||||||
int new_y = gs->player.y + dy;
|
int new_x = gs->player.position.x + direction.x;
|
||||||
|
int new_y = gs->player.position.y + direction.y;
|
||||||
|
|
||||||
|
Enemy *target = NULL;
|
||||||
int action = 0;
|
int action = 0;
|
||||||
|
|
||||||
// Attack enemy at target tile, or move into it
|
MoveResult result =
|
||||||
Enemy *target = player_find_enemy_at(gs->enemies, gs->enemy_count, new_x, new_y);
|
try_move_entity(&gs->player.position, direction, &gs->map, &gs->player, gs->enemies, gs->enemy_count, true);
|
||||||
if (target != NULL) {
|
if (result == MOVE_RESULT_MOVED) {
|
||||||
player_attack(&gs->player, target);
|
player_on_move(&gs->player);
|
||||||
action = 1;
|
action = 1;
|
||||||
} else {
|
} else if (result == MOVE_RESULT_BLOCKED_ENEMY) {
|
||||||
action = player_move(&gs->player, dx, dy, &gs->map);
|
target = player_find_enemy_at(gs->enemies, gs->enemy_count, new_x, new_y);
|
||||||
|
if (target != NULL) {
|
||||||
|
player_attack(&gs->player, target);
|
||||||
|
action = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action)
|
if (action)
|
||||||
post_action(gs, target); // target is NULL on move, enemy ptr on attack
|
post_action(gs, target);
|
||||||
|
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
@ -496,7 +504,11 @@ void load_audio_assets(GameState *gs) {
|
||||||
static void game_loop(void) {
|
static void game_loop(void) {
|
||||||
GameState gs;
|
GameState gs;
|
||||||
memset(&gs, 0, sizeof(GameState));
|
memset(&gs, 0, sizeof(GameState));
|
||||||
|
// load external assets
|
||||||
|
// sound
|
||||||
load_audio_assets(&gs);
|
load_audio_assets(&gs);
|
||||||
|
// font
|
||||||
|
Font fontTTF = LoadFontEx("./assets/fonts/Royal_Decree_Bold.ttf", 14, 0, 250);
|
||||||
// Initialize first floor
|
// Initialize first floor
|
||||||
rng_seed(12345);
|
rng_seed(12345);
|
||||||
init_floor(&gs, 1);
|
init_floor(&gs, 1);
|
||||||
|
|
@ -549,19 +561,19 @@ static void game_loop(void) {
|
||||||
|
|
||||||
// Floating texts follow world shake
|
// Floating texts follow world shake
|
||||||
render_floating_texts(gs.floating_texts, gs.floating_count, gs.shake_x, gs.shake_y);
|
render_floating_texts(gs.floating_texts, gs.floating_count, gs.shake_x, gs.shake_y);
|
||||||
render_ui(&gs.player);
|
render_ui(&gs.player, &fontTTF);
|
||||||
|
|
||||||
// Draw action log
|
// Draw action log
|
||||||
render_action_log(gs.action_log, gs.log_count, gs.log_head);
|
render_action_log(gs.action_log, gs.log_count, gs.log_head, &fontTTF);
|
||||||
|
|
||||||
// Draw inventory overlay if active
|
// Draw inventory overlay if active
|
||||||
if (gs.show_inventory) {
|
if (gs.show_inventory) {
|
||||||
render_inventory_overlay(&gs.player, gs.inv_selected);
|
render_inventory_overlay(&gs.player, gs.inv_selected, &fontTTF);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw message if any
|
// Draw message if any
|
||||||
if (gs.last_message != NULL && gs.message_timer > 0) {
|
if (gs.last_message != NULL && gs.message_timer > 0) {
|
||||||
render_message(gs.last_message);
|
render_message(gs.last_message, &fontTTF);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw game over screen
|
// Draw game over screen
|
||||||
|
|
@ -574,7 +586,7 @@ static void game_loop(void) {
|
||||||
}
|
}
|
||||||
render_end_screen(gs.game_won, gs.total_kills, gs.items_collected, gs.damage_dealt, gs.damage_taken,
|
render_end_screen(gs.game_won, gs.total_kills, gs.items_collected, gs.damage_dealt, gs.damage_taken,
|
||||||
gs.crits_landed, gs.times_hit, gs.potions_used, gs.floors_reached, gs.turn_count,
|
gs.crits_landed, gs.times_hit, gs.potions_used, gs.floors_reached, gs.turn_count,
|
||||||
gs.final_score);
|
gs.final_score, &fontTTF);
|
||||||
}
|
}
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
|
||||||
29
src/movement.c
Normal file
29
src/movement.c
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
#include "movement.h"
|
||||||
|
#include "enemy.h"
|
||||||
|
#include "map.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
// Check if position is occupied by player
|
||||||
|
static int is_player_at(Player *p, int x, int y) {
|
||||||
|
return (p->position.x == x && p->position.y == y);
|
||||||
|
}
|
||||||
|
|
||||||
|
MoveResult try_move_entity(Vec2 *p, Vec2 direction, Map *map, Player *player, Enemy *enemies, int enemy_count,
|
||||||
|
bool moving_is_player) {
|
||||||
|
int new_x = p->x + direction.x;
|
||||||
|
int new_y = p->y + direction.y;
|
||||||
|
|
||||||
|
if (!is_floor(map, new_x, new_y))
|
||||||
|
return MOVE_RESULT_BLOCKED_WALL;
|
||||||
|
|
||||||
|
if (is_enemy_at(enemies, enemy_count, new_x, new_y))
|
||||||
|
return MOVE_RESULT_BLOCKED_ENEMY;
|
||||||
|
if (!moving_is_player) {
|
||||||
|
if (is_player_at(player, new_x, new_y))
|
||||||
|
return MOVE_RESULT_BLOCKED_PLAYER;
|
||||||
|
}
|
||||||
|
|
||||||
|
p->x = new_x;
|
||||||
|
p->y = new_y;
|
||||||
|
return MOVE_RESULT_MOVED;
|
||||||
|
}
|
||||||
17
src/movement.h
Normal file
17
src/movement.h
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
#ifndef MOVEMENT_H
|
||||||
|
#define MOVEMENT_H
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
MOVE_RESULT_MOVED,
|
||||||
|
MOVE_RESULT_BLOCKED_WALL,
|
||||||
|
MOVE_RESULT_BLOCKED_PLAYER,
|
||||||
|
MOVE_RESULT_BLOCKED_ENEMY
|
||||||
|
} MoveResult;
|
||||||
|
|
||||||
|
// Attempts to move entity in a given direction. Returns outcome of action.
|
||||||
|
MoveResult try_move_entity(Vec2 *p, Vec2 direction, Map *map, Player *player, Enemy *enemies, int enemy_count,
|
||||||
|
bool moving_is_player);
|
||||||
|
|
||||||
|
#endif // MOVEMENT_H
|
||||||
31
src/player.c
31
src/player.c
|
|
@ -2,15 +2,12 @@
|
||||||
#include "combat.h"
|
#include "combat.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "items.h"
|
#include "items.h"
|
||||||
#include "map.h"
|
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "utils.h"
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
void player_init(Player *p, int x, int y) {
|
void player_init(Player *p, int x, int y) {
|
||||||
p->x = x;
|
p->position.x = x;
|
||||||
p->y = y;
|
p->position.y = y;
|
||||||
p->hp = PLAYER_BASE_HP;
|
p->hp = PLAYER_BASE_HP;
|
||||||
p->max_hp = PLAYER_BASE_HP;
|
p->max_hp = PLAYER_BASE_HP;
|
||||||
p->attack = PLAYER_BASE_ATTACK;
|
p->attack = PLAYER_BASE_ATTACK;
|
||||||
|
|
@ -43,36 +40,20 @@ Enemy *player_find_enemy_at(Enemy *enemies, int count, int x, int y) {
|
||||||
if (count > MAX_ENEMIES)
|
if (count > MAX_ENEMIES)
|
||||||
count = MAX_ENEMIES;
|
count = MAX_ENEMIES;
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
if (enemies[i].alive && enemies[i].x == x && enemies[i].y == y)
|
if (enemies[i].alive && enemies[i].position.x == x && enemies[i].position.y == y)
|
||||||
return &enemies[i];
|
return &enemies[i];
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int player_move(Player *p, int dx, int dy, Map *map) {
|
void player_on_move(Player *p) {
|
||||||
int new_x = p->x + dx;
|
|
||||||
int new_y = p->y + dy;
|
|
||||||
|
|
||||||
// Check bounds
|
|
||||||
if (!in_bounds(new_x, new_y, MAP_WIDTH, MAP_HEIGHT))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
// Check if walkable
|
|
||||||
if (!is_floor(map, new_x, new_y))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
// Move player
|
|
||||||
p->x = new_x;
|
|
||||||
p->y = new_y;
|
|
||||||
p->step_count += 1;
|
p->step_count += 1;
|
||||||
// Regen suppressed while poisoned, bleeding, or burning
|
|
||||||
if (p->step_count % REGEN_STEP_INTERVAL == 0 && p->hp < p->max_hp &&
|
if (p->step_count % REGEN_STEP_INTERVAL == 0 && p->hp < p->max_hp &&
|
||||||
!combat_has_effect(p->effects, p->effect_count, EFFECT_POISON) &&
|
!combat_has_effect(p->effects, p->effect_count, EFFECT_POISON) &&
|
||||||
!combat_has_effect(p->effects, p->effect_count, EFFECT_BLEED) &&
|
!combat_has_effect(p->effects, p->effect_count, EFFECT_BLEED) &&
|
||||||
!combat_has_effect(p->effects, p->effect_count, EFFECT_BURN)) {
|
!combat_has_effect(p->effects, p->effect_count, EFFECT_BURN)) {
|
||||||
p->hp += 1;
|
p->hp += 1;
|
||||||
}
|
}
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void player_attack(Player *p, Enemy *e) {
|
void player_attack(Player *p, Enemy *e) {
|
||||||
|
|
@ -228,8 +209,8 @@ int player_drop_item(Player *p, int inv_index, Item *items, int item_count) {
|
||||||
if (items[i].picked_up) {
|
if (items[i].picked_up) {
|
||||||
// Place dropped item at this position
|
// Place dropped item at this position
|
||||||
items[i] = *item;
|
items[i] = *item;
|
||||||
items[i].x = p->x;
|
items[i].x = p->position.x;
|
||||||
items[i].y = p->y;
|
items[i].y = p->position.y;
|
||||||
items[i].picked_up = 0;
|
items[i].picked_up = 0;
|
||||||
// Remove from inventory
|
// Remove from inventory
|
||||||
player_remove_inventory_item(p, inv_index);
|
player_remove_inventory_item(p, inv_index);
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@
|
||||||
// Initialize player at position
|
// Initialize player at position
|
||||||
void player_init(Player *p, int x, int y);
|
void player_init(Player *p, int x, int y);
|
||||||
|
|
||||||
// Move player to (x+dx, y+dy); returns 1 if moved, 0 if blocked
|
// Apply status effects, healing, etc
|
||||||
int player_move(Player *p, int dx, int dy, Map *map);
|
void player_on_move(Player *p);
|
||||||
|
|
||||||
// Find a living enemy at tile (x, y); returns NULL if none
|
// Find a living enemy at tile (x, y); returns NULL if none
|
||||||
Enemy *player_find_enemy_at(Enemy *enemies, int count, int x, int y);
|
Enemy *player_find_enemy_at(Enemy *enemies, int count, int x, int y);
|
||||||
|
|
|
||||||
238
src/render.c
238
src/render.c
|
|
@ -30,7 +30,8 @@ void render_map(const Map *map) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_player(const Player *p) {
|
void render_player(const Player *p) {
|
||||||
Rectangle rect = {(float)(p->x * TILE_SIZE), (float)(p->y * TILE_SIZE), (float)TILE_SIZE, (float)TILE_SIZE};
|
Rectangle rect = {(float)(p->position.x * TILE_SIZE), (float)(p->position.y * TILE_SIZE), (float)TILE_SIZE,
|
||||||
|
(float)TILE_SIZE};
|
||||||
DrawRectangleRec(rect, BLUE);
|
DrawRectangleRec(rect, BLUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -39,20 +40,20 @@ void render_enemies(const Enemy *enemies, int count) {
|
||||||
if (!enemies[i].alive)
|
if (!enemies[i].alive)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Rectangle rect = {(float)(enemies[i].x * TILE_SIZE), (float)(enemies[i].y * TILE_SIZE), (float)TILE_SIZE,
|
Rectangle rect = {(float)(enemies[i].position.x * TILE_SIZE), (float)(enemies[i].position.y * TILE_SIZE),
|
||||||
(float)TILE_SIZE};
|
(float)TILE_SIZE, (float)TILE_SIZE};
|
||||||
|
|
||||||
// Different colors based on enemy type
|
// Different colors based on enemy type
|
||||||
Color enemy_color;
|
Color enemy_color;
|
||||||
switch (enemies[i].type) {
|
switch (enemies[i].type) {
|
||||||
case ENEMY_GOBLIN:
|
case ENEMY_GOBLIN:
|
||||||
enemy_color = (Color){150, 50, 50, 255}; // dark red
|
enemy_color = COLOR_ENEMY_GOBLIN; // dark red
|
||||||
break;
|
break;
|
||||||
case ENEMY_SKELETON:
|
case ENEMY_SKELETON:
|
||||||
enemy_color = (Color){200, 200, 200, 255}; // light gray
|
enemy_color = COLOR_ENEMY_SKELETON; // light gray
|
||||||
break;
|
break;
|
||||||
case ENEMY_ORC:
|
case ENEMY_ORC:
|
||||||
enemy_color = (Color){50, 150, 50, 255}; // dark green
|
enemy_color = COLOR_ENEMY_ORC; // dark green
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
enemy_color = RED;
|
enemy_color = RED;
|
||||||
|
|
@ -72,8 +73,8 @@ void render_enemies(const Enemy *enemies, int count) {
|
||||||
bar_color = (Color){200, 180, 40, 255}; // yellow
|
bar_color = (Color){200, 180, 40, 255}; // yellow
|
||||||
else
|
else
|
||||||
bar_color = (Color){200, 60, 60, 255}; // red
|
bar_color = (Color){200, 60, 60, 255}; // red
|
||||||
Rectangle hp_bar = {(float)(enemies[i].x * TILE_SIZE), (float)(enemies[i].y * TILE_SIZE - 4), (float)hp_pixels,
|
Rectangle hp_bar = {(float)(enemies[i].position.x * TILE_SIZE), (float)(enemies[i].position.y * TILE_SIZE - 4),
|
||||||
3};
|
(float)hp_pixels, 3};
|
||||||
DrawRectangleRec(hp_bar, bar_color);
|
DrawRectangleRec(hp_bar, bar_color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -91,13 +92,13 @@ void render_items(const Item *items, int count) {
|
||||||
Color item_color;
|
Color item_color;
|
||||||
switch (items[i].type) {
|
switch (items[i].type) {
|
||||||
case ITEM_POTION:
|
case ITEM_POTION:
|
||||||
item_color = (Color){255, 100, 100, 255}; // red/pink
|
item_color = COLOR_ITEM_POTION; // red/pink
|
||||||
break;
|
break;
|
||||||
case ITEM_WEAPON:
|
case ITEM_WEAPON:
|
||||||
item_color = (Color){255, 255, 100, 255}; // yellow
|
item_color = COLOR_ITEM_WEAPON; // yellow
|
||||||
break;
|
break;
|
||||||
case ITEM_ARMOR:
|
case ITEM_ARMOR:
|
||||||
item_color = (Color){100, 100, 255, 255}; // blue
|
item_color = COLOR_ITEM_ARMOR; // blue
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
item_color = GREEN;
|
item_color = GREEN;
|
||||||
|
|
@ -108,7 +109,7 @@ void render_items(const Item *items, int count) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_ui(const Player *p) {
|
void render_ui(const Player *p, Font *font) {
|
||||||
// HUD Panel
|
// HUD Panel
|
||||||
const int hud_y = MAP_HEIGHT * TILE_SIZE;
|
const int hud_y = MAP_HEIGHT * TILE_SIZE;
|
||||||
const int hud_height = 60;
|
const int hud_height = 60;
|
||||||
|
|
@ -152,7 +153,7 @@ void render_ui(const Player *p) {
|
||||||
int bar_height = 16;
|
int bar_height = 16;
|
||||||
|
|
||||||
// HP Label, above bar
|
// HP Label, above bar
|
||||||
DrawText("HP", bar_x, bar_y - 11, 9, text_dim);
|
DrawTextEx(*font, "HP", (Vector2){bar_x, bar_y - 11}, 14, NAR_CHAR_SPACE, text_dim);
|
||||||
|
|
||||||
// HP Bar background
|
// HP Bar background
|
||||||
DrawRectangle(bar_x, bar_y, bar_width, bar_height, (Color){20, 15, 15, 255});
|
DrawRectangle(bar_x, bar_y, bar_width, bar_height, (Color){20, 15, 15, 255});
|
||||||
|
|
@ -177,8 +178,8 @@ void render_ui(const Player *p) {
|
||||||
// HP text, centered in bar
|
// HP text, centered in bar
|
||||||
char hp_text[32];
|
char hp_text[32];
|
||||||
snprintf(hp_text, sizeof(hp_text), "%d/%d", p->hp, p->max_hp);
|
snprintf(hp_text, sizeof(hp_text), "%d/%d", p->hp, p->max_hp);
|
||||||
int hp_text_w = MeasureText(hp_text, 10);
|
int hp_text_w = MeasureText(hp_text, 12);
|
||||||
DrawText(hp_text, bar_x + (bar_width - hp_text_w) / 2, bar_y + 2, 10, WHITE);
|
DrawTextEx(*font, hp_text, (Vector2){bar_x + (bar_width - hp_text_w) / 2.0f, bar_y + 2}, 12, NAR_CHAR_SPACE, WHITE);
|
||||||
|
|
||||||
// Status effects
|
// Status effects
|
||||||
int effect_x = bar_x;
|
int effect_x = bar_x;
|
||||||
|
|
@ -213,7 +214,7 @@ void render_ui(const Player *p) {
|
||||||
if (p->effects[i].duration > 0) {
|
if (p->effects[i].duration > 0) {
|
||||||
char eff_text[16];
|
char eff_text[16];
|
||||||
snprintf(eff_text, sizeof(eff_text), "%s%d", eff_label, p->effects[i].duration);
|
snprintf(eff_text, sizeof(eff_text), "%s%d", eff_label, p->effects[i].duration);
|
||||||
DrawText(eff_text, effect_x, effect_y, 9, eff_color);
|
DrawTextEx(*font, eff_text, (Vector2){effect_x, effect_y}, 9, NAR_CHAR_SPACE, eff_color);
|
||||||
effect_x += 28;
|
effect_x += 28;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -225,65 +226,68 @@ void render_ui(const Player *p) {
|
||||||
// Floor
|
// Floor
|
||||||
char floor_text[16];
|
char floor_text[16];
|
||||||
snprintf(floor_text, sizeof(floor_text), "F%d", p->floor);
|
snprintf(floor_text, sizeof(floor_text), "F%d", p->floor);
|
||||||
DrawText(floor_text, stats_x, stats_y, 14, text_bright);
|
DrawTextEx(*font, floor_text, (Vector2){stats_x, stats_y}, 16, NORM_CHAR_SPACE, text_bright);
|
||||||
DrawText("Floor", stats_x, stats_y + 16, 9, text_dim);
|
DrawTextEx(*font, "Floor", (Vector2){stats_x, stats_y + 16}, 12, NAR_CHAR_SPACE, text_dim);
|
||||||
|
|
||||||
// ATK
|
// ATK
|
||||||
char atk_text[16];
|
char atk_text[16];
|
||||||
snprintf(atk_text, sizeof(atk_text), "%d", p->attack);
|
snprintf(atk_text, sizeof(atk_text), "%d", p->attack);
|
||||||
DrawText(atk_text, stats_x + stat_spacing, stats_y, 14, YELLOW);
|
DrawTextEx(*font, atk_text, (Vector2){stats_x + stat_spacing, stats_y}, 16, NORM_CHAR_SPACE, YELLOW);
|
||||||
DrawText("ATK", stats_x + stat_spacing, stats_y + 16, 9, text_dim);
|
DrawTextEx(*font, "ATK", (Vector2){stats_x + stat_spacing, stats_y + 16}, 12, NAR_CHAR_SPACE, text_dim);
|
||||||
|
|
||||||
// DEF
|
// DEF
|
||||||
char def_text[16];
|
char def_text[16];
|
||||||
snprintf(def_text, sizeof(def_text), "%d", p->defense);
|
snprintf(def_text, sizeof(def_text), "%d", p->defense);
|
||||||
DrawText(def_text, stats_x + stat_spacing * 2, stats_y, 14, (Color){100, 150, 255, 255});
|
DrawTextEx(*font, def_text, (Vector2){stats_x + stat_spacing * 2, stats_y}, 16, NORM_CHAR_SPACE,
|
||||||
DrawText("DEF", stats_x + stat_spacing * 2, stats_y + 16, 9, text_dim);
|
(Color){100, 150, 255, 255});
|
||||||
|
DrawTextEx(*font, "DEF", (Vector2){stats_x + stat_spacing * 2, stats_y + 16}, 12, NAR_CHAR_SPACE, text_dim);
|
||||||
|
|
||||||
int equip_x = section2_end + 15;
|
int equip_x = section2_end + 15;
|
||||||
int equip_y = hud_y + 8;
|
int equip_y = hud_y + 8;
|
||||||
|
|
||||||
// Weapon slot
|
// Weapon slot
|
||||||
DrawText("WEAPON", equip_x, equip_y, 9, text_dim);
|
DrawTextEx(*font, "WEAPON", (Vector2){equip_x, equip_y}, 12, NAR_CHAR_SPACE, text_dim);
|
||||||
if (p->has_weapon) {
|
if (p->has_weapon) {
|
||||||
const char *weapon_name = item_get_name(&p->equipped_weapon);
|
const char *weapon_name = item_get_name(&p->equipped_weapon);
|
||||||
if (weapon_name) {
|
if (weapon_name) {
|
||||||
char weapon_text[64];
|
char weapon_text[64];
|
||||||
snprintf(weapon_text, sizeof(weapon_text), "%s +%d [%s]", weapon_name, p->equipped_weapon.power,
|
snprintf(weapon_text, sizeof(weapon_text), "%s +%d [%s]", weapon_name, p->equipped_weapon.power,
|
||||||
dmg_class_get_short(p->equipped_weapon.dmg_class));
|
dmg_class_get_short(p->equipped_weapon.dmg_class));
|
||||||
DrawText(weapon_text, equip_x, equip_y + 11, 10, (Color){255, 220, 100, 255});
|
DrawTextEx(*font, weapon_text, (Vector2){equip_x, equip_y + 11}, 10, NAR_CHAR_SPACE, (Color){255, 220, 100, 255});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DrawText("None [IMP]", equip_x, equip_y + 11, 10, (Color){80, 75, 70, 255});
|
DrawTextEx(*font, "None [IMP]", (Vector2){equip_x, equip_y + 11}, 10, NAR_CHAR_SPACE, (Color){80, 75, 70, 255});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Armor slot
|
// Armor slot
|
||||||
DrawText("ARMOR", equip_x, equip_y + 26, 9, text_dim);
|
DrawTextEx(*font, "ARMOR", (Vector2){equip_x, equip_y + 26}, 9, NAR_CHAR_SPACE, text_dim);
|
||||||
if (p->has_armor) {
|
if (p->has_armor) {
|
||||||
const char *armor_name = item_get_name(&p->equipped_armor);
|
const char *armor_name = item_get_name(&p->equipped_armor);
|
||||||
if (armor_name) {
|
if (armor_name) {
|
||||||
char armor_text[48];
|
char armor_text[48];
|
||||||
snprintf(armor_text, sizeof(armor_text), "%s +%d", armor_name, p->equipped_armor.power);
|
snprintf(armor_text, sizeof(armor_text), "%s +%d", armor_name, p->equipped_armor.power);
|
||||||
DrawText(armor_text, equip_x, equip_y + 37, 10, (Color){100, 150, 255, 255});
|
DrawTextEx(*font, armor_text, (Vector2){equip_x, equip_y + 37}, 10, NAR_CHAR_SPACE, (Color){100, 150, 255, 255});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DrawText("None", equip_x, equip_y + 37, 10, (Color){80, 75, 70, 255});
|
DrawTextEx(*font, "None", (Vector2){equip_x, equip_y + 37}, 10, NAR_CHAR_SPACE, (Color){80, 75, 70, 255});
|
||||||
}
|
}
|
||||||
|
|
||||||
int ctrl_x = section3_end + 20;
|
int ctrl_x = section3_end + 20;
|
||||||
int ctrl_y = hud_y + 14;
|
int ctrl_y = hud_y + 14;
|
||||||
|
|
||||||
DrawText("[WASD] Move [G] Pickup [I] Inventory [U] Use", ctrl_x, ctrl_y, 11, (Color){139, 119, 89, 255});
|
DrawTextEx(*font, "[WASD] Move [G] Pickup [I] Inventory [U] Use", (Vector2){ctrl_x, ctrl_y}, 11,
|
||||||
DrawText("[E] Equip [D] Drop [Q] Quit", ctrl_x, ctrl_y + 16, 11, (Color){139, 119, 89, 255});
|
NORM_CHAR_SPACE, (Color){139, 119, 89, 255});
|
||||||
|
DrawTextEx(*font, "[E] Equip [D] Drop [Q] Quit", (Vector2){ctrl_x, ctrl_y + 16}, 11, NORM_CHAR_SPACE,
|
||||||
|
(Color){139, 119, 89, 255});
|
||||||
|
|
||||||
// INV count in top-right corner of HUD
|
// INV count in top-right corner of HUD
|
||||||
char inv_text[16];
|
char inv_text[16];
|
||||||
snprintf(inv_text, sizeof(inv_text), "INV: %d/%d", p->inventory_count, MAX_INVENTORY);
|
snprintf(inv_text, sizeof(inv_text), "INV: %d/%d", p->inventory_count, MAX_INVENTORY);
|
||||||
int inv_width = MeasureText(inv_text, 10);
|
int inv_width = MeasureText(inv_text, 10);
|
||||||
DrawText(inv_text, SCREEN_WIDTH - inv_width - 10, hud_y + 5, 10, GREEN);
|
DrawTextEx(*font, inv_text, (Vector2){SCREEN_WIDTH - inv_width - 10, hud_y + 5}, 10, NAR_CHAR_SPACE, GREEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_action_log(const char log[5][128], int count, int head) {
|
void render_action_log(const char log[5][128], int count, int head, Font *font) {
|
||||||
// Roguelike scroll/log panel styling
|
// Roguelike scroll/log panel styling
|
||||||
const int log_width = 250;
|
const int log_width = 250;
|
||||||
const int log_height = 90;
|
const int log_height = 90;
|
||||||
|
|
@ -305,7 +309,7 @@ void render_action_log(const char log[5][128], int count, int head) {
|
||||||
|
|
||||||
// Title bar
|
// Title bar
|
||||||
DrawRectangle(log_x + 4, log_y + 4, log_width - 8, 16, (Color){30, 25, 20, 255});
|
DrawRectangle(log_x + 4, log_y + 4, log_width - 8, 16, (Color){30, 25, 20, 255});
|
||||||
DrawText("MESSAGE LOG", log_x + 8, log_y + 6, 10, (Color){180, 160, 130, 255});
|
DrawTextEx(*font, "MESSAGE LOG", (Vector2){log_x + 8, log_y + 6}, 10, NAR_CHAR_SPACE, (Color){180, 160, 130, 255});
|
||||||
|
|
||||||
// Separator line under title
|
// Separator line under title
|
||||||
DrawLine(log_x + 4, log_y + 22, log_x + log_width - 5, log_y + 22, log_border_dark);
|
DrawLine(log_x + 4, log_y + 22, log_x + log_width - 5, log_y + 22, log_border_dark);
|
||||||
|
|
@ -330,12 +334,12 @@ void render_action_log(const char log[5][128], int count, int head) {
|
||||||
} else {
|
} else {
|
||||||
text_color = (Color){120, 110, 100, 200}; // oldest: dim
|
text_color = (Color){120, 110, 100, 200}; // oldest: dim
|
||||||
}
|
}
|
||||||
DrawText(log[idx], text_x, text_start_y + i * line_height, 10, text_color);
|
DrawTextEx(*font, log[idx], (Vector2){text_x, text_start_y + i * line_height}, 10, NAR_CHAR_SPACE, text_color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_inventory_overlay(const Player *p, int selected) {
|
void render_inventory_overlay(const Player *p, int selected, Font *font) {
|
||||||
// Overlay dimensions
|
// Overlay dimensions
|
||||||
int ov_width = 360;
|
int ov_width = 360;
|
||||||
int ov_height = 300;
|
int ov_height = 300;
|
||||||
|
|
@ -347,7 +351,8 @@ void render_inventory_overlay(const Player *p, int selected) {
|
||||||
// Title
|
// Title
|
||||||
const char *title = "INVENTORY";
|
const char *title = "INVENTORY";
|
||||||
int title_w = MeasureText(title, 24);
|
int title_w = MeasureText(title, 24);
|
||||||
DrawText(title, overlay.x + (overlay.width - title_w) / 2, overlay.y + 12, 24, WHITE);
|
DrawTextEx(*font, title, (Vector2){overlay.x + (overlay.width - title_w) / 2, overlay.y + 12}, 24, NORM_CHAR_SPACE,
|
||||||
|
WHITE);
|
||||||
|
|
||||||
// Draw each inventory slot
|
// Draw each inventory slot
|
||||||
char slot_text[64];
|
char slot_text[64];
|
||||||
|
|
@ -369,68 +374,95 @@ void render_inventory_overlay(const Player *p, int selected) {
|
||||||
|
|
||||||
// Slot number
|
// Slot number
|
||||||
snprintf(slot_text, sizeof(slot_text), "%d.", i + 1);
|
snprintf(slot_text, sizeof(slot_text), "%d.", i + 1);
|
||||||
DrawText(slot_text, overlay.x + 16, y_pos + 4, 14, (Color){80, 80, 80, 255});
|
DrawTextEx(*font, slot_text, (Vector2){overlay.x + 16, y_pos + 4}, 14, NORM_CHAR_SPACE, (Color){80, 80, 80, 255});
|
||||||
|
|
||||||
// Item name
|
// Item name
|
||||||
const char *name = item_get_name(item);
|
const char *name = item_get_name(item);
|
||||||
Color name_color = (item->type == ITEM_POTION) ? (Color){255, 140, 140, 255}
|
if (name) {
|
||||||
|
Color name_color = (item->type == ITEM_POTION) ? (Color){255, 140, 140, 255}
|
||||||
: (item->type == ITEM_WEAPON) ? (Color){255, 255, 140, 255}
|
: (item->type == ITEM_WEAPON) ? (Color){255, 255, 140, 255}
|
||||||
: (Color){140, 140, 255, 255};
|
: (Color){140, 140, 255, 255};
|
||||||
DrawText(name, overlay.x + 45, y_pos + 4, 14, name_color);
|
DrawTextEx(*font, name, (Vector2){overlay.x + 45, y_pos + 4}, 14, NORM_CHAR_SPACE, name_color);
|
||||||
|
}
|
||||||
// Power
|
// Power
|
||||||
snprintf(slot_text, sizeof(slot_text), "+%d", item->power);
|
snprintf(slot_text, sizeof(slot_text), "+%d", item->power);
|
||||||
DrawText(slot_text, overlay.x + 150, y_pos + 4, 14, YELLOW);
|
DrawTextEx(*font, slot_text, (Vector2){overlay.x + 150, y_pos + 4}, 14, NORM_CHAR_SPACE, YELLOW);
|
||||||
|
|
||||||
// Action
|
// Action
|
||||||
if (item->type == ITEM_POTION) {
|
if (item->type == ITEM_POTION) {
|
||||||
DrawText("[U]se", overlay.x + 200, y_pos + 4, 14, GREEN);
|
DrawTextEx(*font, "[U]se", (Vector2){overlay.x + 200, y_pos + 4}, 14, NORM_CHAR_SPACE, GREEN);
|
||||||
} else {
|
} else {
|
||||||
DrawText("[E]quip [D]rop", overlay.x + 200, y_pos + 4, 14, GOLD);
|
DrawTextEx(*font, "[E]quip [D]rop", (Vector2){overlay.x + 200, y_pos + 4}, 14, NORM_CHAR_SPACE, GOLD);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Empty slot
|
// Empty slot
|
||||||
snprintf(slot_text, sizeof(slot_text), "%d.", i + 1);
|
snprintf(slot_text, sizeof(slot_text), "%d.", i + 1);
|
||||||
DrawText(slot_text, overlay.x + 16, y_pos + 4, 14, (Color){40, 40, 40, 255});
|
DrawTextEx(*font, slot_text, (Vector2){overlay.x + 16, y_pos + 4}, 14, NORM_CHAR_SPACE, (Color){40, 40, 40, 255});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Instructions at bottom
|
// Instructions at bottom
|
||||||
const char *hint = "[1-0] Select [E] Equip [U] Use [D] Drop [I/ESC] Close";
|
const char *hint = "[1-0] Select [E] Equip [U] Use [D] Drop [I/ESC] Close";
|
||||||
int hint_w = MeasureText(hint, 12);
|
int hint_w = MeasureText(hint, 12);
|
||||||
DrawText(hint, overlay.x + (overlay.width - hint_w) / 2, overlay.y + overlay.height - 22, 12,
|
DrawTextEx(*font, hint, (Vector2){overlay.x + (overlay.width - hint_w) / 2, overlay.y + overlay.height - 22}, 12,
|
||||||
(Color){65, 65, 65, 255});
|
NORM_CHAR_SPACE, (Color){65, 65, 65, 255});
|
||||||
}
|
}
|
||||||
|
|
||||||
static Color label_color(FloatingText *ft, int alpha) {
|
static Color label_color(FloatingText *ft, int alpha) {
|
||||||
if (ft->label[0] == '\0')
|
if (ft->label == LABEL_NONE)
|
||||||
return (Color){255, 100, 100, alpha}; // numeric damage default
|
return FLOAT_DAMAGE; // numeric damage default
|
||||||
if (strcmp(ft->label, "DODGE") == 0)
|
|
||||||
return (Color){160, 160, 160, alpha};
|
|
||||||
if (strcmp(ft->label, "BLOCK") == 0)
|
|
||||||
return (Color){80, 130, 220, alpha};
|
|
||||||
if (strcmp(ft->label, "CRIT!") == 0)
|
|
||||||
return (Color){255, 200, 50, alpha};
|
|
||||||
if (strcmp(ft->label, "SLAIN") == 0)
|
|
||||||
return (Color){220, 50, 50, alpha};
|
|
||||||
|
|
||||||
// Proc label, color driven by effect_type stored in the struct
|
switch (ft->label) {
|
||||||
switch (ft->effect_type) {
|
case LABEL_DODGE:
|
||||||
case EFFECT_POISON:
|
return FLOAT_DODGE;
|
||||||
return (Color){50, 200, 50, alpha};
|
case LABEL_BLOCK:
|
||||||
case EFFECT_BLEED:
|
return FLOAT_BLOCK;
|
||||||
return (Color){200, 50, 50, alpha};
|
case LABEL_CRIT:
|
||||||
case EFFECT_BURN:
|
return FLOAT_CRIT;
|
||||||
return (Color){230, 130, 30, alpha};
|
case LABEL_SLAIN:
|
||||||
case EFFECT_STUN:
|
return FLOAT_SLAIN;
|
||||||
return (Color){200, 200, 50, alpha};
|
case LABEL_PROC:
|
||||||
case EFFECT_WEAKEN:
|
// Proc label, color driven by effect_type stored in the struct
|
||||||
return (Color){120, 120, 120, alpha};
|
switch (ft->effect_type) {
|
||||||
|
case EFFECT_POISON:
|
||||||
|
return (Color){50, 200, 50, alpha};
|
||||||
|
case EFFECT_BLEED:
|
||||||
|
return (Color){200, 50, 50, alpha};
|
||||||
|
case EFFECT_BURN:
|
||||||
|
return (Color){230, 130, 30, alpha};
|
||||||
|
case EFFECT_STUN:
|
||||||
|
return (Color){200, 200, 50, alpha};
|
||||||
|
case EFFECT_WEAKEN:
|
||||||
|
return (Color){120, 120, 120, alpha};
|
||||||
|
default:
|
||||||
|
return FLOAT_DEFAULT;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return (Color){200, 200, 200, alpha};
|
return FLOAT_DAMAGE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *label_text(FloatingLabel label) {
|
||||||
|
switch (label) {
|
||||||
|
case LABEL_DODGE:
|
||||||
|
return "DODGE";
|
||||||
|
case LABEL_BLOCK:
|
||||||
|
return "BLOCK";
|
||||||
|
case LABEL_CRIT:
|
||||||
|
return "CRIT!";
|
||||||
|
case LABEL_SLAIN:
|
||||||
|
return "SLAIN";
|
||||||
|
case LABEL_PROC:
|
||||||
|
return "PROC";
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int label_font_size(FloatingLabel label) {
|
||||||
|
return (label == LABEL_CRIT) ? FONT_SIZE_FLOAT_CRIT : FONT_SIZE_FLOAT_LABEL;
|
||||||
|
}
|
||||||
|
|
||||||
void render_floating_texts(FloatingText *texts, int count, int shake_x, int shake_y) {
|
void render_floating_texts(FloatingText *texts, int count, int shake_x, int shake_y) {
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
if (texts[i].lifetime <= 0)
|
if (texts[i].lifetime <= 0)
|
||||||
|
|
@ -441,13 +473,14 @@ void render_floating_texts(FloatingText *texts, int count, int shake_x, int shak
|
||||||
float alpha = (float)texts[i].lifetime / 60.0f;
|
float alpha = (float)texts[i].lifetime / 60.0f;
|
||||||
int a = (int)(255 * alpha);
|
int a = (int)(255 * alpha);
|
||||||
|
|
||||||
if (texts[i].label[0] != '\0') {
|
if (texts[i].label != LABEL_NONE) {
|
||||||
// Label text (DODGE, BLOCK, CRIT!, proc name, SLAIN)
|
// Label text (DODGE, BLOCK, CRIT!, SLAIN, or PROC)
|
||||||
// Check for "CRIT!" specifically rather than just 'C' prefix
|
// CRIT! gets larger font size
|
||||||
int font_size = (strcmp(texts[i].label, "CRIT!") == 0) ? 16 : 14;
|
int font_size = label_font_size(texts[i].label);
|
||||||
Color color = label_color(&texts[i], a);
|
Color color = label_color(&texts[i], a);
|
||||||
int text_w = MeasureText(texts[i].label, font_size);
|
const char *text = label_text(texts[i].label);
|
||||||
DrawText(texts[i].label, x - text_w / 2, y, font_size, color);
|
int text_w = MeasureText(text, font_size);
|
||||||
|
DrawText(text, x - text_w / 2, y, font_size, color);
|
||||||
} else {
|
} else {
|
||||||
// Numeric damage
|
// Numeric damage
|
||||||
Color color = texts[i].is_critical ? (Color){255, 200, 50, a} : (Color){255, 100, 100, a};
|
Color color = texts[i].is_critical ? (Color){255, 200, 50, a} : (Color){255, 100, 100, a};
|
||||||
|
|
@ -460,7 +493,7 @@ void render_floating_texts(FloatingText *texts, int count, int shake_x, int shak
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_end_screen(int is_victory, int kills, int items, int damage_dealt, int damage_taken, int crits,
|
void render_end_screen(int is_victory, int kills, int items, int damage_dealt, int damage_taken, int crits,
|
||||||
int times_hit, int potions, int floors, int turns, int score) {
|
int times_hit, int potions, int floors, int turns, int score, Font *font) {
|
||||||
// Semi-transparent overlay
|
// Semi-transparent overlay
|
||||||
Rectangle overlay = {0, 0, (float)SCREEN_WIDTH, (float)SCREEN_HEIGHT};
|
Rectangle overlay = {0, 0, (float)SCREEN_WIDTH, (float)SCREEN_HEIGHT};
|
||||||
DrawRectangleRec(overlay, (Color){0, 0, 0, 210});
|
DrawRectangleRec(overlay, (Color){0, 0, 0, 210});
|
||||||
|
|
@ -470,7 +503,8 @@ void render_end_screen(int is_victory, int kills, int items, int damage_dealt, i
|
||||||
int title_font_size = 60;
|
int title_font_size = 60;
|
||||||
Color title_color = is_victory ? GOLD : RED;
|
Color title_color = is_victory ? GOLD : RED;
|
||||||
int title_width = MeasureText(title, title_font_size);
|
int title_width = MeasureText(title, title_font_size);
|
||||||
DrawText(title, (SCREEN_WIDTH - title_width) / 2, 30, title_font_size, title_color);
|
DrawTextEx(*font, title, (Vector2){(SCREEN_WIDTH - title_width) / 2.0f, 30}, title_font_size, NORM_CHAR_SPACE,
|
||||||
|
title_color);
|
||||||
|
|
||||||
// Stats box
|
// Stats box
|
||||||
int box_x = SCREEN_WIDTH / 2 - 200;
|
int box_x = SCREEN_WIDTH / 2 - 200;
|
||||||
|
|
@ -490,71 +524,73 @@ void render_end_screen(int is_victory, int kills, int items, int damage_dealt, i
|
||||||
Color value_color = WHITE;
|
Color value_color = WHITE;
|
||||||
|
|
||||||
// Column 1
|
// Column 1
|
||||||
DrawText("Kills:", col1_x, row_y, 18, label_color);
|
DrawTextEx(*font, "Kills:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color);
|
||||||
snprintf(line, sizeof(line), "%d", kills);
|
snprintf(line, sizeof(line), "%d", kills);
|
||||||
DrawText(line, col1_x + 80, row_y, 18, value_color);
|
DrawTextEx(*font, line, (Vector2){col1_x + 80, row_y}, 18, NORM_CHAR_SPACE, value_color);
|
||||||
row_y += line_height;
|
row_y += line_height;
|
||||||
|
|
||||||
DrawText("Items:", col1_x, row_y, 18, label_color);
|
DrawTextEx(*font, "Items:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color);
|
||||||
snprintf(line, sizeof(line), "%d", items);
|
snprintf(line, sizeof(line), "%d", items);
|
||||||
DrawText(line, col1_x + 80, row_y, 18, value_color);
|
DrawTextEx(*font, line, (Vector2){col1_x + 80, row_y}, 18, NORM_CHAR_SPACE, value_color);
|
||||||
row_y += line_height;
|
row_y += line_height;
|
||||||
|
|
||||||
DrawText("Damage Dealt:", col1_x, row_y, 18, label_color);
|
DrawTextEx(*font, "Damage Dealt:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color);
|
||||||
snprintf(line, sizeof(line), "%d", damage_dealt);
|
snprintf(line, sizeof(line), "%d", damage_dealt);
|
||||||
DrawText(line, col1_x + 140, row_y, 18, value_color);
|
DrawTextEx(*font, line, (Vector2){col1_x + 140, row_y}, 18, NORM_CHAR_SPACE, value_color);
|
||||||
row_y += line_height;
|
row_y += line_height;
|
||||||
|
|
||||||
DrawText("Damage Taken:", col1_x, row_y, 18, label_color);
|
DrawTextEx(*font, "Damage Taken:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color);
|
||||||
snprintf(line, sizeof(line), "%d", damage_taken);
|
snprintf(line, sizeof(line), "%d", damage_taken);
|
||||||
DrawText(line, col1_x + 140, row_y, 18, value_color);
|
DrawTextEx(*font, line, (Vector2){col1_x + 140, row_y}, 18, NORM_CHAR_SPACE, value_color);
|
||||||
row_y += line_height;
|
row_y += line_height;
|
||||||
|
|
||||||
DrawText("Crits:", col1_x, row_y, 18, label_color);
|
DrawTextEx(*font, "Crits:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color);
|
||||||
snprintf(line, sizeof(line), "%d", crits);
|
snprintf(line, sizeof(line), "%d", crits);
|
||||||
DrawText(line, col1_x + 80, row_y, 18, value_color);
|
DrawTextEx(*font, line, (Vector2){col1_x + 80, row_y}, 18, NORM_CHAR_SPACE, value_color);
|
||||||
row_y += line_height;
|
row_y += line_height;
|
||||||
|
|
||||||
DrawText("Times Hit:", col1_x, row_y, 18, label_color);
|
DrawTextEx(*font, "Times Hit:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color);
|
||||||
snprintf(line, sizeof(line), "%d", times_hit);
|
snprintf(line, sizeof(line), "%d", times_hit);
|
||||||
DrawText(line, col1_x + 80, row_y, 18, value_color);
|
DrawTextEx(*font, line, (Vector2){col1_x + 80, row_y}, 18, NORM_CHAR_SPACE, value_color);
|
||||||
row_y += line_height;
|
row_y += line_height;
|
||||||
|
|
||||||
// Column 2
|
// Column 2
|
||||||
int col2_row_y = box_y + 20;
|
int col2_row_y = box_y + 20;
|
||||||
DrawText("Potions:", col2_x, col2_row_y, 18, label_color);
|
DrawTextEx(*font, "Potions:", (Vector2){col2_x, col2_row_y}, 18, NORM_CHAR_SPACE, label_color);
|
||||||
snprintf(line, sizeof(line), "%d", potions);
|
snprintf(line, sizeof(line), "%d", potions);
|
||||||
DrawText(line, col2_x + 80, col2_row_y, 18, value_color);
|
DrawTextEx(*font, line, (Vector2){col2_x + 80, col2_row_y}, 18, NORM_CHAR_SPACE, value_color);
|
||||||
col2_row_y += line_height;
|
col2_row_y += line_height;
|
||||||
|
|
||||||
DrawText("Floors:", col2_x, col2_row_y, 18, label_color);
|
DrawTextEx(*font, "Floors:", (Vector2){col2_x, col2_row_y}, 18, NORM_CHAR_SPACE, label_color);
|
||||||
snprintf(line, sizeof(line), "%d", floors);
|
snprintf(line, sizeof(line), "%d", floors);
|
||||||
DrawText(line, col2_x + 80, col2_row_y, 18, value_color);
|
DrawTextEx(*font, line, (Vector2){col2_x + 80, col2_row_y}, 18, NORM_CHAR_SPACE, value_color);
|
||||||
col2_row_y += line_height;
|
col2_row_y += line_height;
|
||||||
|
|
||||||
DrawText("Turns:", col2_x, col2_row_y, 18, label_color);
|
DrawTextEx(*font, "Turns:", (Vector2){col2_x, col2_row_y}, 18, NORM_CHAR_SPACE, label_color);
|
||||||
snprintf(line, sizeof(line), "%d", turns);
|
snprintf(line, sizeof(line), "%d", turns);
|
||||||
DrawText(line, col2_x + 80, col2_row_y, 18, value_color);
|
DrawTextEx(*font, line, (Vector2){col2_x + 80, col2_row_y}, 18, NORM_CHAR_SPACE, value_color);
|
||||||
col2_row_y += line_height;
|
col2_row_y += line_height;
|
||||||
|
|
||||||
// Score: placed below the last row of the longer column (6 items, row_y is already there)
|
// Score: placed below the last row of the longer column (6 items, row_y is already there)
|
||||||
row_y += 10;
|
row_y += 10;
|
||||||
DrawText("SCORE:", col1_x, row_y, 22, GOLD);
|
DrawTextEx(*font, "SCORE:", (Vector2){col1_x, row_y}, 22, NORM_CHAR_SPACE, GOLD);
|
||||||
snprintf(line, sizeof(line), "%d", score);
|
snprintf(line, sizeof(line), "%d", score);
|
||||||
DrawText(line, col1_x + 90, row_y, 22, GOLD);
|
DrawTextEx(*font, line, (Vector2){col1_x + 90, col2_row_y}, 22, NORM_CHAR_SPACE, GOLD);
|
||||||
|
|
||||||
if (is_victory) {
|
if (is_victory) {
|
||||||
const char *subtitle = "Press R to play again or Q to quit";
|
const char *subtitle = "Press R to play again or Q to quit";
|
||||||
int sub_width = MeasureText(subtitle, 20);
|
int sub_width = MeasureText(subtitle, 20);
|
||||||
DrawText(subtitle, (SCREEN_WIDTH - sub_width) / 2, SCREEN_HEIGHT - 50, 20, LIGHTGRAY);
|
DrawTextEx(*font, subtitle, (Vector2){(SCREEN_WIDTH - sub_width) / 2.0f, SCREEN_HEIGHT - 50}, 20, NORM_CHAR_SPACE,
|
||||||
|
LIGHTGRAY);
|
||||||
} else {
|
} else {
|
||||||
const char *subtitle = "Press R to restart or Q to quit";
|
const char *subtitle = "Press R to restart or Q to quit";
|
||||||
int sub_width = MeasureText(subtitle, 20);
|
int sub_width = MeasureText(subtitle, 20);
|
||||||
DrawText(subtitle, (SCREEN_WIDTH - sub_width) / 2, SCREEN_HEIGHT - 50, 20, LIGHTGRAY);
|
DrawTextEx(*font, subtitle, (Vector2){(SCREEN_WIDTH - sub_width) / 2.0f, SCREEN_HEIGHT - 50}, 20, NORM_CHAR_SPACE,
|
||||||
|
LIGHTGRAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_message(const char *message) {
|
void render_message(const char *message, Font *font) {
|
||||||
if (message == NULL)
|
if (message == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -623,5 +659,5 @@ void render_message(const char *message) {
|
||||||
text_y = (int)box_y + padding_y;
|
text_y = (int)box_y + padding_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawText(message, text_x, text_y, font_size, WHITE);
|
DrawTextEx(*font, message, (Vector2){text_x, text_y}, font_size, NORM_CHAR_SPACE, WHITE);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
80
src/render.h
80
src/render.h
|
|
@ -3,6 +3,76 @@
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
// HUD colors
|
||||||
|
#define HUD_BG (Color){25, 20, 15, 255}
|
||||||
|
#define HUD_BORDER (Color){139, 119, 89, 255}
|
||||||
|
#define HUD_LIGHT_LINE (Color){60, 55, 50, 255}
|
||||||
|
#define HUD_DARK_LINE (Color){15, 12, 10, 255}
|
||||||
|
#define TEXT_DIM (Color){160, 150, 140, 255}
|
||||||
|
#define TEXT_BRIGHT (Color){240, 230, 220, 255}
|
||||||
|
|
||||||
|
// HP bar colors
|
||||||
|
#define HP_HIGH (Color){60, 180, 60, 255}
|
||||||
|
#define HP_MED (Color){200, 180, 40, 255}
|
||||||
|
#define HP_LOW (Color){200, 60, 60, 255}
|
||||||
|
#define HP_BAR_BG (Color){20, 15, 15, 255}
|
||||||
|
#define HP_BAR_BORDER (Color){80, 70, 60, 255}
|
||||||
|
|
||||||
|
// Enemy type colors
|
||||||
|
#define COLOR_ENEMY_GOBLIN (Color){150, 50, 50, 255}
|
||||||
|
#define COLOR_ENEMY_SKELETON (Color){200, 200, 200, 255}
|
||||||
|
#define COLOR_ENEMY_ORC (Color){50, 150, 50, 255}
|
||||||
|
|
||||||
|
// Item type colors
|
||||||
|
#define COLOR_ITEM_POTION (Color){255, 100, 100, 255}
|
||||||
|
#define COLOR_ITEM_WEAPON (Color){255, 255, 100, 255}
|
||||||
|
#define COLOR_ITEM_ARMOR (Color){100, 100, 255, 255}
|
||||||
|
|
||||||
|
// Action log colors
|
||||||
|
#define LOG_BG (Color){15, 12, 10, 230}
|
||||||
|
#define LOG_BORDER (Color){100, 85, 65, 255}
|
||||||
|
#define LOG_DARK (Color){60, 50, 40, 255}
|
||||||
|
#define LOG_TITLE_BG (Color){30, 25, 20, 255}
|
||||||
|
#define LOG_TEXT (Color){180, 160, 130, 255}
|
||||||
|
#define LOG_NEWEST (Color){220, 210, 200, 255}
|
||||||
|
#define LOG_RECENT (Color){180, 170, 160, 255}
|
||||||
|
#define LOG_OLDER (Color){150, 140, 130, 230}
|
||||||
|
#define LOG_OLDEST (Color){120, 110, 100, 200}
|
||||||
|
|
||||||
|
// Inventory overlay colors
|
||||||
|
#define INV_OVERLAY_BG (Color){12, 12, 12, 252}
|
||||||
|
#define INV_BORDER (Color){70, 70, 70, 255}
|
||||||
|
#define INV_SLOT_BG (Color){45, 45, 45, 255}
|
||||||
|
#define INV_SELECTED (Color){180, 160, 80, 255}
|
||||||
|
#define INV_EMPTY (Color){40, 40, 40, 255}
|
||||||
|
#define INV_HINT (Color){65, 65, 65, 255}
|
||||||
|
|
||||||
|
// Floating text colors
|
||||||
|
#define FLOAT_DAMAGE (Color){255, 100, 100, 255}
|
||||||
|
#define FLOAT_CRIT (Color){255, 200, 50, 255}
|
||||||
|
#define FLOAT_DODGE (Color){160, 160, 160, 255}
|
||||||
|
#define FLOAT_BLOCK (Color){80, 130, 220, 255}
|
||||||
|
#define FLOAT_SLAIN (Color){220, 50, 50, 255}
|
||||||
|
#define FLOAT_DEFAULT (Color){200, 200, 200, 255}
|
||||||
|
|
||||||
|
// Floating label font sizes
|
||||||
|
#define FONT_SIZE_FLOAT_LABEL 14
|
||||||
|
#define FONT_SIZE_FLOAT_CRIT 16
|
||||||
|
#define FONT_SIZE_FLOAT_DMG 18
|
||||||
|
|
||||||
|
// Message box colors
|
||||||
|
#define MSG_BG (Color){45, 45, 45, 235}
|
||||||
|
#define MSG_BORDER (Color){180, 180, 180, 255}
|
||||||
|
|
||||||
|
// End screen colors
|
||||||
|
#define END_OVERLAY (Color){0, 0, 0, 210}
|
||||||
|
#define END_BOX_BG (Color){20, 20, 20, 240}
|
||||||
|
#define END_BOX_BORDER (Color){100, 100, 100, 255}
|
||||||
|
|
||||||
|
// Portrait placeholder
|
||||||
|
// FIXME: remove when player sprites are available
|
||||||
|
#define PORTRAIT_BG (Color){30, 30, 45, 255}
|
||||||
|
|
||||||
// Render the map tiles
|
// Render the map tiles
|
||||||
void render_map(const Map *map);
|
void render_map(const Map *map);
|
||||||
|
|
||||||
|
|
@ -16,22 +86,22 @@ void render_enemies(const Enemy *enemies, int count);
|
||||||
void render_items(const Item *items, int count);
|
void render_items(const Item *items, int count);
|
||||||
|
|
||||||
// Render UI overlay
|
// Render UI overlay
|
||||||
void render_ui(const Player *p);
|
void render_ui(const Player *p, Font *font);
|
||||||
|
|
||||||
// Render action log (bottom left corner)
|
// Render action log (bottom left corner)
|
||||||
void render_action_log(const char log[5][128], int count, int head);
|
void render_action_log(const char log[5][128], int count, int head, Font *font);
|
||||||
|
|
||||||
// Render inventory selection overlay
|
// Render inventory selection overlay
|
||||||
void render_inventory_overlay(const Player *p, int selected);
|
void render_inventory_overlay(const Player *p, int selected, Font *font);
|
||||||
|
|
||||||
// Render floating damage text
|
// Render floating damage text
|
||||||
void render_floating_texts(FloatingText *texts, int count, int shake_x, int shake_y);
|
void render_floating_texts(FloatingText *texts, int count, int shake_x, int shake_y);
|
||||||
|
|
||||||
// Render end screen (victory or death) with stats breakdown
|
// Render end screen (victory or death) with stats breakdown
|
||||||
void render_end_screen(int is_victory, int kills, int items, int damage_dealt, int damage_taken, int crits,
|
void render_end_screen(int is_victory, int kills, int items, int damage_dealt, int damage_taken, int crits,
|
||||||
int times_hit, int potions, int floors, int turns, int score);
|
int times_hit, int potions, int floors, int turns, int score, Font *font);
|
||||||
|
|
||||||
// Render a message popup
|
// Render a message popup
|
||||||
void render_message(const char *message);
|
void render_message(const char *message, Font *font);
|
||||||
|
|
||||||
#endif // RENDER_H
|
#endif // RENDER_H
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,10 @@
|
||||||
#define SCREEN_WIDTH (MAP_WIDTH * TILE_SIZE)
|
#define SCREEN_WIDTH (MAP_WIDTH * TILE_SIZE)
|
||||||
#define SCREEN_HEIGHT (MAP_HEIGHT * TILE_SIZE)
|
#define SCREEN_HEIGHT (MAP_HEIGHT * TILE_SIZE)
|
||||||
|
|
||||||
|
// Font constants
|
||||||
|
#define NORM_CHAR_SPACE 4.0f
|
||||||
|
#define NAR_CHAR_SPACE 1.0f
|
||||||
|
|
||||||
// Game Limits
|
// Game Limits
|
||||||
#define MAX_ENEMIES 64
|
#define MAX_ENEMIES 64
|
||||||
#define MAX_ITEMS 128
|
#define MAX_ITEMS 128
|
||||||
|
|
@ -52,4 +56,15 @@
|
||||||
#define PLAYER_BASE_DODGE 5
|
#define PLAYER_BASE_DODGE 5
|
||||||
#define PLAYER_BASE_BLOCK 0
|
#define PLAYER_BASE_BLOCK 0
|
||||||
|
|
||||||
|
// Screen shake
|
||||||
|
#define SHAKE_EFFECT_DURATION 4
|
||||||
|
#define SHAKE_PLAYER_DAMAGE_DURATION 8
|
||||||
|
#define SHAKE_MAX_OFFSET 4
|
||||||
|
|
||||||
|
// Floating text
|
||||||
|
#define FLOATING_TEXT_LIFETIME 60
|
||||||
|
|
||||||
|
// Message timer
|
||||||
|
#define MESSAGE_TIMER_DURATION 60
|
||||||
|
|
||||||
#endif // SETTINGS_H
|
#endif // SETTINGS_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue