forked from NotAShelf/rogged
Compare commits
3 commits
notashelf/
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dab3e1554c |
||
|
|
af14fd258b |
||
|
|
5de711cdaf |
8 changed files with 152 additions and 336 deletions
|
|
@ -30,8 +30,6 @@ typedef struct {
|
|||
TileType tiles[MAP_HEIGHT][MAP_WIDTH];
|
||||
Room rooms[MAX_ROOMS];
|
||||
int room_count;
|
||||
unsigned char visible[MAP_HEIGHT][MAP_WIDTH];
|
||||
unsigned char remembered[MAP_HEIGHT][MAP_WIDTH];
|
||||
} Map;
|
||||
|
||||
// Dungeon
|
||||
|
|
@ -100,11 +98,6 @@ typedef struct {
|
|||
int status_chance;
|
||||
int crit_chance; // crit chance percentage (0-100)
|
||||
int crit_mult; // crit damage multiplier percentage (e.g. 150 = 1.5x)
|
||||
// vision
|
||||
int vision_range;
|
||||
int alert; // 1 = aware of player, searching
|
||||
int last_known_x; // last position where enemy saw player
|
||||
int last_known_y;
|
||||
// status effects
|
||||
StatusEffect effects[MAX_EFFECTS];
|
||||
int effect_count;
|
||||
|
|
|
|||
127
src/enemy.c
127
src/enemy.c
|
|
@ -3,7 +3,6 @@
|
|||
#include "common.h"
|
||||
#include "map.h"
|
||||
#include "rng.h"
|
||||
#include "settings.h"
|
||||
#include <string.h>
|
||||
|
||||
// Forward declaration
|
||||
|
|
@ -69,7 +68,6 @@ void enemy_spawn(Enemy enemies[], int *count, Map *map, Player *p, int floor) {
|
|||
e.resistance[DMG_PIERCE] = 0;
|
||||
e.resistance[DMG_FIRE] = -25;
|
||||
e.resistance[DMG_POISON] = 50;
|
||||
e.vision_range = 7;
|
||||
break;
|
||||
case ENEMY_SKELETON:
|
||||
e.max_hp = ENEMY_BASE_HP + floor + 2;
|
||||
|
|
@ -87,7 +85,6 @@ void enemy_spawn(Enemy enemies[], int *count, Map *map, Player *p, int floor) {
|
|||
e.resistance[DMG_PIERCE] = 50;
|
||||
e.resistance[DMG_FIRE] = 25;
|
||||
e.resistance[DMG_POISON] = 75;
|
||||
e.vision_range = 6;
|
||||
break;
|
||||
case ENEMY_ORC:
|
||||
e.max_hp = ENEMY_BASE_HP + floor + 4;
|
||||
|
|
@ -105,7 +102,6 @@ void enemy_spawn(Enemy enemies[], int *count, Map *map, Player *p, int floor) {
|
|||
e.resistance[DMG_PIERCE] = -25;
|
||||
e.resistance[DMG_FIRE] = 0;
|
||||
e.resistance[DMG_POISON] = 0;
|
||||
e.vision_range = 5;
|
||||
break;
|
||||
default:
|
||||
e.max_hp = ENEMY_BASE_HP;
|
||||
|
|
@ -119,7 +115,6 @@ void enemy_spawn(Enemy enemies[], int *count, Map *map, Player *p, int floor) {
|
|||
e.crit_chance = ENEMY_CRIT_CHANCE;
|
||||
e.crit_mult = ENEMY_CRIT_MULT;
|
||||
memset(e.resistance, 0, sizeof(e.resistance));
|
||||
e.vision_range = ENEMY_VIEW_RANGE;
|
||||
break;
|
||||
}
|
||||
e.cooldown = e.speed;
|
||||
|
|
@ -139,9 +134,11 @@ int is_enemy_at(const Enemy *enemies, int count, int x, int y) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Check if enemy can see player (within view range and line of sight)
|
||||
static int can_see_player(Enemy *e, Player *p, Map *map) {
|
||||
return can_see_entity(map, e->x, e->y, p->x, p->y, e->vision_range);
|
||||
// Check if enemy can see player (adjacent)
|
||||
static int can_see_player(Enemy *e, Player *p) {
|
||||
int dx = p->x - e->x;
|
||||
int dy = p->y - e->y;
|
||||
return (dx >= -1 && dx <= 1 && dy >= -1 && dy <= 1);
|
||||
}
|
||||
|
||||
// Check if position is occupied by player
|
||||
|
|
@ -181,88 +178,7 @@ static void enemy_move_toward_player(Enemy *e, Player *p, Map *map, Enemy *all_e
|
|||
}
|
||||
}
|
||||
|
||||
// Move enemy in a random direction (patrol)
|
||||
static void enemy_patrol(Enemy *e, Map *map, Enemy *all_enemies, int enemy_count) {
|
||||
if (rng_int(0, 100) > ENEMY_PATROL_MOVE_CHANCE)
|
||||
return;
|
||||
|
||||
int dx = rng_int(-1, 1);
|
||||
int dy = rng_int(-1, 1);
|
||||
|
||||
if (dx == 0 && dy == 0)
|
||||
return;
|
||||
|
||||
int new_x = e->x + dx;
|
||||
int new_y = e->y + dy;
|
||||
|
||||
if (is_floor(map, new_x, new_y) && !is_enemy_at(all_enemies, enemy_count, new_x, new_y)) {
|
||||
e->x = new_x;
|
||||
e->y = new_y;
|
||||
}
|
||||
}
|
||||
|
||||
// Move enemy toward last known player position
|
||||
static void enemy_move_to_last_known(Enemy *e, Map *map, Enemy *all_enemies, int enemy_count) {
|
||||
int dx = 0, dy = 0;
|
||||
|
||||
if (e->last_known_x > e->x)
|
||||
dx = 1;
|
||||
else if (e->last_known_x < e->x)
|
||||
dx = -1;
|
||||
|
||||
if (e->last_known_y > e->y)
|
||||
dy = 1;
|
||||
else if (e->last_known_y < e->y)
|
||||
dy = -1;
|
||||
|
||||
int new_x = e->x + dx;
|
||||
int new_y = e->y;
|
||||
|
||||
if (dx != 0 && is_floor(map, new_x, new_y) && !is_enemy_at(all_enemies, enemy_count, new_x, new_y)) {
|
||||
e->x = new_x;
|
||||
} else if (dy != 0) {
|
||||
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)) {
|
||||
e->x = new_x;
|
||||
e->y = new_y;
|
||||
}
|
||||
}
|
||||
|
||||
if (e->x == e->last_known_x && e->y == e->last_known_y)
|
||||
e->alert = 0;
|
||||
}
|
||||
|
||||
// Check if position is within alert radius of another enemy
|
||||
static int is_nearby_enemy(const Enemy *enemies, int count, int x, int y, int radius) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (!enemies[i].alive)
|
||||
continue;
|
||||
int dx = enemies[i].x - x;
|
||||
int dy = enemies[i].y - y;
|
||||
if (dx * dx + dy * dy <= radius * radius)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Propagate alert to nearby enemies
|
||||
static void propagate_alert(Enemy *trigger_enemy, Enemy *all_enemies, int enemy_count) {
|
||||
for (int i = 0; i < enemy_count; i++) {
|
||||
Enemy *e = &all_enemies[i];
|
||||
if (!e->alive || e == trigger_enemy)
|
||||
continue;
|
||||
if (e->alert)
|
||||
continue;
|
||||
if (is_nearby_enemy(all_enemies, enemy_count, e->x, e->y, 5)) {
|
||||
e->alert = 1;
|
||||
e->last_known_x = trigger_enemy->last_known_x;
|
||||
e->last_known_y = trigger_enemy->last_known_y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Perform a single action for an enemy (attack if visible, otherwise patrol or search)
|
||||
// Perform a single action for an enemy (attack if adjacent, otherwise move)
|
||||
void enemy_act(Enemy *e, Player *p, Map *map, Enemy *all_enemies, int enemy_count) {
|
||||
if (!e->alive)
|
||||
return;
|
||||
|
|
@ -271,37 +187,14 @@ void enemy_act(Enemy *e, Player *p, Map *map, Enemy *all_enemies, int enemy_coun
|
|||
if (combat_has_effect(e->effects, e->effect_count, EFFECT_STUN))
|
||||
return;
|
||||
|
||||
int can_see = can_see_player(e, p, map);
|
||||
|
||||
// If we can see the player, update alert state and last known position
|
||||
if (can_see) {
|
||||
e->alert = 1;
|
||||
e->last_known_x = p->x;
|
||||
e->last_known_y = p->y;
|
||||
}
|
||||
|
||||
// Attack if adjacent to player
|
||||
if (can_see && can_see_entity(map, e->x, e->y, p->x, p->y, 1)) {
|
||||
// Check if adjacent to player - attack
|
||||
if (can_see_player(e, p)) {
|
||||
combat_enemy_attack(e, p);
|
||||
propagate_alert(e, all_enemies, enemy_count);
|
||||
return;
|
||||
}
|
||||
|
||||
// Move toward player if visible
|
||||
if (can_see) {
|
||||
enemy_move_toward_player(e, p, map, all_enemies, enemy_count);
|
||||
propagate_alert(e, all_enemies, enemy_count);
|
||||
return;
|
||||
}
|
||||
|
||||
// If alert but can't see player, move toward last known position
|
||||
if (e->alert) {
|
||||
enemy_move_to_last_known(e, map, all_enemies, enemy_count);
|
||||
return;
|
||||
}
|
||||
|
||||
// Not alert - patrol randomly
|
||||
enemy_patrol(e, map, all_enemies, enemy_count);
|
||||
// Otherwise, move toward player
|
||||
enemy_move_toward_player(e, p, map, all_enemies, enemy_count);
|
||||
}
|
||||
|
||||
void enemy_update_all(Enemy enemies[], int count, Player *p, Map *map) {
|
||||
|
|
|
|||
11
src/main.c
11
src/main.c
|
|
@ -122,9 +122,6 @@ static void init_floor(GameState *gs, int floor_num) {
|
|||
}
|
||||
gs->player.floor = floor_num;
|
||||
|
||||
// Calculate initial visibility
|
||||
calculate_visibility(&gs->map, gs->player.x, gs->player.y);
|
||||
|
||||
// Spawn enemies
|
||||
enemy_spawn(gs->enemies, &gs->enemy_count, &gs->map, &gs->player, floor_num);
|
||||
|
||||
|
|
@ -218,9 +215,6 @@ static void post_action(GameState *gs, Enemy *attacked_enemy) {
|
|||
}
|
||||
}
|
||||
|
||||
// Update visibility based on player's new position
|
||||
calculate_visibility(&gs->map, gs->player.x, gs->player.y);
|
||||
|
||||
// Enemy turns - uses speed/cooldown system
|
||||
enemy_update_all(gs->enemies, gs->enemy_count, &gs->player, &gs->map);
|
||||
|
||||
|
|
@ -252,7 +246,6 @@ static int handle_stun_turn(GameState *gs) {
|
|||
if (gs->game_over)
|
||||
return 1;
|
||||
enemy_update_all(gs->enemies, gs->enemy_count, &gs->player, &gs->map);
|
||||
calculate_visibility(&gs->map, gs->player.x, gs->player.y);
|
||||
if (gs->player.hp <= 0)
|
||||
gs->game_over = 1;
|
||||
gs->last_message = "You are stunned!";
|
||||
|
|
@ -548,8 +541,8 @@ static void game_loop(void) {
|
|||
cam.offset = (Vector2){(float)gs.shake_x, (float)gs.shake_y};
|
||||
BeginMode2D(cam);
|
||||
render_map(&gs.map);
|
||||
render_items(gs.items, gs.item_count, gs.map.visible);
|
||||
render_enemies(gs.enemies, gs.enemy_count, gs.map.visible);
|
||||
render_items(gs.items, gs.item_count);
|
||||
render_enemies(gs.enemies, gs.enemy_count);
|
||||
render_player(&gs.player);
|
||||
EndMode2D();
|
||||
|
||||
|
|
|
|||
68
src/map.c
68
src/map.c
|
|
@ -1,8 +1,6 @@
|
|||
#include "map.h"
|
||||
#include "rng.h"
|
||||
#include "settings.h"
|
||||
#include "utils.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void map_init(Map *map) {
|
||||
|
|
@ -12,8 +10,6 @@ void map_init(Map *map) {
|
|||
map->tiles[y][x] = TILE_WALL;
|
||||
}
|
||||
}
|
||||
memset(map->visible, 0, sizeof(map->visible));
|
||||
memset(map->remembered, 0, sizeof(map->remembered));
|
||||
map->room_count = 0;
|
||||
}
|
||||
|
||||
|
|
@ -190,67 +186,3 @@ void dungeon_generate(Dungeon *d, Map *map, int floor_num) {
|
|||
d->room_count = map->room_count;
|
||||
memcpy(d->rooms, map->rooms, sizeof(Room) * map->room_count);
|
||||
}
|
||||
|
||||
int is_in_view_range(int x, int y, int view_x, int view_y, int range) {
|
||||
int dx = x - view_x;
|
||||
int dy = y - view_y;
|
||||
return (dx * dx + dy * dy) <= (range * range);
|
||||
}
|
||||
|
||||
static int trace_line_of_sight(const Map *map, int x1, int y1, int x2, int y2) {
|
||||
int dx = abs(x2 - x1);
|
||||
int dy = abs(y2 - y1);
|
||||
int sx = (x1 < x2) ? 1 : -1;
|
||||
int sy = (y1 < y2) ? 1 : -1;
|
||||
int err = dx - dy;
|
||||
int x = x1;
|
||||
int y = y1;
|
||||
|
||||
while (1) {
|
||||
if (!in_bounds(x, y, MAP_WIDTH, MAP_HEIGHT))
|
||||
return 0;
|
||||
|
||||
if (x == x2 && y == y2)
|
||||
return 1;
|
||||
|
||||
if (map->tiles[y][x] == TILE_WALL && !(x == x1 && y == y1))
|
||||
return 0;
|
||||
|
||||
int e2 = 2 * err;
|
||||
if (e2 > -dy) {
|
||||
err -= dy;
|
||||
x += sx;
|
||||
}
|
||||
if (e2 < dx) {
|
||||
err += dx;
|
||||
y += sy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int has_line_of_sight(const Map *map, int x1, int y1, int x2, int y2) {
|
||||
if (!in_bounds(x1, y1, MAP_WIDTH, MAP_HEIGHT) || !in_bounds(x2, y2, MAP_WIDTH, MAP_HEIGHT))
|
||||
return 0;
|
||||
return trace_line_of_sight(map, x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
int can_see_entity(const Map *map, int from_x, int from_y, int to_x, int to_y, int range) {
|
||||
if (!is_in_view_range(to_x, to_y, from_x, from_y, range))
|
||||
return 0;
|
||||
return has_line_of_sight(map, from_x, from_y, to_x, to_y);
|
||||
}
|
||||
|
||||
void calculate_visibility(Map *map, int x, int y) {
|
||||
memset(map->visible, 0, sizeof(map->visible));
|
||||
|
||||
for (int ty = 0; ty < MAP_HEIGHT; ty++) {
|
||||
for (int tx = 0; tx < MAP_WIDTH; tx++) {
|
||||
if (is_in_view_range(tx, ty, x, y, PLAYER_VIEW_RANGE)) {
|
||||
if (has_line_of_sight(map, x, y, tx, ty)) {
|
||||
map->visible[ty][tx] = 1;
|
||||
map->remembered[ty][tx] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,10 +18,4 @@ void map_init(Map *map);
|
|||
// Get a random floor tile position
|
||||
void get_random_floor_tile(Map *map, int *x, int *y, int attempts);
|
||||
|
||||
// Visibility / Fog of War
|
||||
int is_in_view_range(int x, int y, int view_x, int view_y, int range);
|
||||
int has_line_of_sight(const Map *map, int x1, int y1, int x2, int y2);
|
||||
void calculate_visibility(Map *map, int x, int y);
|
||||
int can_see_entity(const Map *map, int from_x, int from_y, int to_x, int to_y, int range);
|
||||
|
||||
#endif // MAP_H
|
||||
|
|
|
|||
250
src/render.c
250
src/render.c
|
|
@ -11,31 +11,18 @@ void render_map(const Map *map) {
|
|||
for (int y = 0; y < MAP_HEIGHT; y++) {
|
||||
for (int x = 0; x < MAP_WIDTH; x++) {
|
||||
Rectangle rect = {(float)(x * TILE_SIZE), (float)(y * TILE_SIZE), (float)TILE_SIZE, (float)TILE_SIZE};
|
||||
int visible = map->visible[y][x];
|
||||
int remembered = map->remembered[y][x];
|
||||
|
||||
if (!visible && !remembered) {
|
||||
DrawRectangleRec(rect, (Color){5, 5, 10, 255});
|
||||
continue;
|
||||
}
|
||||
|
||||
Color wall_color = visible ? DARKGRAY : (Color){25, 25, 30, 255};
|
||||
Color floor_color = visible ? BLACK : (Color){15, 15, 20, 255};
|
||||
Color stairs_color = visible ? (Color){100, 100, 100, 255} : (Color){40, 40, 45, 255};
|
||||
|
||||
switch (map->tiles[y][x]) {
|
||||
case TILE_WALL:
|
||||
DrawRectangleRec(rect, wall_color);
|
||||
DrawRectangleRec(rect, DARKGRAY);
|
||||
break;
|
||||
case TILE_FLOOR:
|
||||
DrawRectangleRec(rect, floor_color);
|
||||
DrawRectangleRec(rect, BLACK);
|
||||
break;
|
||||
case TILE_STAIRS:
|
||||
DrawRectangleRec(rect, stairs_color);
|
||||
if (visible)
|
||||
DrawText(">", x * TILE_SIZE + 4, y * TILE_SIZE + 2, 12, WHITE);
|
||||
else
|
||||
DrawText(">", x * TILE_SIZE + 4, y * TILE_SIZE + 2, 12, (Color){60, 60, 65, 255});
|
||||
DrawRectangleRec(rect, (Color){100, 100, 100, 255});
|
||||
// Draw stairs marker
|
||||
DrawText(">", x * TILE_SIZE + 4, y * TILE_SIZE + 2, 12, WHITE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -47,12 +34,10 @@ void render_player(const Player *p) {
|
|||
DrawRectangleRec(rect, BLUE);
|
||||
}
|
||||
|
||||
void render_enemies(const Enemy *enemies, int count, const unsigned char visible[MAP_HEIGHT][MAP_WIDTH]) {
|
||||
void render_enemies(const Enemy *enemies, int count) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (!enemies[i].alive)
|
||||
continue;
|
||||
if (!visible[enemies[i].y][enemies[i].x])
|
||||
continue;
|
||||
|
||||
Rectangle rect = {(float)(enemies[i].x * TILE_SIZE), (float)(enemies[i].y * TILE_SIZE), (float)TILE_SIZE,
|
||||
(float)TILE_SIZE};
|
||||
|
|
@ -94,12 +79,10 @@ void render_enemies(const Enemy *enemies, int count, const unsigned char visible
|
|||
}
|
||||
}
|
||||
|
||||
void render_items(const Item *items, int count, const unsigned char visible[MAP_HEIGHT][MAP_WIDTH]) {
|
||||
void render_items(const Item *items, int count) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (items[i].picked_up)
|
||||
continue;
|
||||
if (!visible[items[i].y][items[i].x])
|
||||
continue;
|
||||
|
||||
Rectangle rect = {(float)(items[i].x * TILE_SIZE), (float)(items[i].y * TILE_SIZE), (float)TILE_SIZE,
|
||||
(float)TILE_SIZE};
|
||||
|
|
@ -125,36 +108,33 @@ void render_items(const Item *items, int count, const unsigned char visible[MAP_
|
|||
}
|
||||
}
|
||||
|
||||
void render_ui(const Player *p) {
|
||||
// HUD Panel
|
||||
const int hud_y = MAP_HEIGHT * TILE_SIZE;
|
||||
const int hud_height = 60;
|
||||
const Color hud_bg = {25, 20, 15, 255}; // dark parchment
|
||||
const Color hud_border = {139, 119, 89, 255}; // bronze/brown border
|
||||
const Color text_dim = {160, 150, 140, 255}; // dimmed text
|
||||
const Color text_bright = {240, 230, 220, 255}; // bright text
|
||||
static void draw_hud_background(int hud_y, int hud_height, Color hud_bg, Color hud_border, Color magic_a, Color magic_b ) {
|
||||
// Main HUD background with border
|
||||
Rectangle ui_bg = {0, (float)hud_y, (float)SCREEN_WIDTH, (float)hud_height};
|
||||
DrawRectangleRec(ui_bg, hud_bg);
|
||||
DrawRectangleLines(0, hud_y, SCREEN_WIDTH, hud_height, hud_border);
|
||||
DrawLine(0, hud_y + 1, SCREEN_WIDTH, hud_y + 1, magic_a);
|
||||
DrawLine(0, hud_y + hud_height - 2, SCREEN_WIDTH, hud_y + hud_height - 2, magic_b); // Magic number 2, probably offset from window bottom
|
||||
}
|
||||
|
||||
// Main HUD background with border
|
||||
Rectangle ui_bg = {0, (float)hud_y, (float)SCREEN_WIDTH, (float)hud_height};
|
||||
DrawRectangleRec(ui_bg, hud_bg);
|
||||
DrawRectangleLines(0, hud_y, SCREEN_WIDTH, hud_height, hud_border);
|
||||
DrawLine(0, hud_y + 1, SCREEN_WIDTH, hud_y + 1, (Color){60, 55, 50, 255});
|
||||
DrawLine(0, hud_y + hud_height - 2, SCREEN_WIDTH, hud_y + hud_height - 2, (Color){15, 12, 10, 255});
|
||||
|
||||
// Section dividers
|
||||
int section1_end = 180; // after portrait + HP bar
|
||||
int section2_end = 310; // after stats
|
||||
int section3_end = 480; // after equipment
|
||||
|
||||
DrawLine(section1_end, hud_y + 5, section1_end, hud_y + hud_height - 5, (Color){60, 55, 50, 255});
|
||||
DrawLine(section1_end + 1, hud_y + 5, section1_end + 1, hud_y + hud_height - 5, (Color){15, 12, 10, 255});
|
||||
|
||||
DrawLine(section2_end, hud_y + 5, section2_end, hud_y + hud_height - 5, (Color){60, 55, 50, 255});
|
||||
DrawLine(section2_end + 1, hud_y + 5, section2_end + 1, hud_y + hud_height - 5, (Color){15, 12, 10, 255});
|
||||
static void draw_section_divider(int hud_y, int section_x, int border_gap, int hud_height, Color magic_a, Color magic_b) {
|
||||
DrawLine(section_x, hud_y + border_gap, section_x, hud_y + hud_height - border_gap, magic_a);
|
||||
DrawLine(section_x + 1, hud_y + border_gap, section_x + 1, hud_y + hud_height - border_gap, magic_b);
|
||||
}
|
||||
|
||||
static void draw_player_life(
|
||||
const Player *p, int hud_y, Color text_bright, Color text_dim, Color full_health,
|
||||
Color low_health, Color crit_health, Color hp_background, Color hp_outline
|
||||
) {
|
||||
// HP Bar, to the right of portrait
|
||||
int portrait_x = 8;
|
||||
int portrait_y = hud_y + 8;
|
||||
int portrait_size = 44;
|
||||
int bar_x = portrait_x + portrait_size + 8;
|
||||
int bar_y = hud_y + 22;
|
||||
int bar_width = 100;
|
||||
int bar_height = 16;
|
||||
|
||||
|
||||
// FIXME: for now this is just a blue square indicating the player. Once we
|
||||
// model the player, add classes, sprites, etc. this will need to be revisited.
|
||||
|
|
@ -162,29 +142,23 @@ void render_ui(const Player *p) {
|
|||
DrawRectangle(portrait_x + 2, portrait_y + 2, portrait_size - 4, portrait_size - 4, BLUE);
|
||||
DrawRectangleLines(portrait_x, portrait_y, portrait_size, portrait_size, (Color){139, 119, 89, 255});
|
||||
|
||||
// HP Bar, to the right of portrait
|
||||
int bar_x = portrait_x + portrait_size + 8;
|
||||
int bar_y = hud_y + 20;
|
||||
int bar_width = 100;
|
||||
int bar_height = 16;
|
||||
|
||||
// HP Label, above bar
|
||||
DrawText("HP", bar_x, bar_y - 11, 9, text_dim);
|
||||
|
||||
// HP Bar background
|
||||
DrawRectangle(bar_x, bar_y, bar_width, bar_height, (Color){20, 15, 15, 255});
|
||||
DrawRectangleLines(bar_x, bar_y, bar_width, bar_height, (Color){80, 70, 60, 255});
|
||||
DrawRectangle(bar_x, bar_y, bar_width, bar_height, hp_background);
|
||||
DrawRectangleLines(bar_x, bar_y, bar_width, bar_height, hp_outline);
|
||||
|
||||
// HP Bar fill
|
||||
float hp_percent = (float)p->hp / p->max_hp;
|
||||
int fill_width = (int)(bar_width * hp_percent);
|
||||
Color hp_color;
|
||||
if (hp_percent > 0.6f) {
|
||||
hp_color = (Color){60, 180, 60, 255};
|
||||
hp_color = full_health;
|
||||
} else if (hp_percent > 0.3f) {
|
||||
hp_color = (Color){200, 180, 40, 255};
|
||||
hp_color = low_health;
|
||||
} else {
|
||||
hp_color = (Color){200, 60, 60, 255};
|
||||
hp_color = crit_health;
|
||||
}
|
||||
|
||||
if (fill_width > 0) {
|
||||
|
|
@ -195,7 +169,7 @@ void render_ui(const Player *p) {
|
|||
char hp_text[32];
|
||||
snprintf(hp_text, sizeof(hp_text), "%d/%d", p->hp, p->max_hp);
|
||||
int hp_text_w = MeasureText(hp_text, 10);
|
||||
DrawText(hp_text, bar_x + (bar_width - hp_text_w) / 2, bar_y + 2, 10, WHITE);
|
||||
DrawText(hp_text, bar_x + (bar_width - hp_text_w) / 2, bar_y + 3, 10, WHITE);
|
||||
|
||||
// Status effects
|
||||
int effect_x = bar_x;
|
||||
|
|
@ -235,69 +209,110 @@ void render_ui(const Player *p) {
|
|||
}
|
||||
}
|
||||
|
||||
int stats_x = section1_end + 15;
|
||||
int stats_y = hud_y + 12;
|
||||
int stat_spacing = 40;
|
||||
}
|
||||
|
||||
// Floor
|
||||
char floor_text[16];
|
||||
snprintf(floor_text, sizeof(floor_text), "F%d", p->floor);
|
||||
DrawText(floor_text, stats_x, stats_y, 14, text_bright);
|
||||
DrawText("Floor", stats_x, stats_y + 16, 9, text_dim);
|
||||
static void draw_player_stats(
|
||||
const Player *p, int hud_y, int stats_x, Color text_bright, Color text_dim
|
||||
) {
|
||||
int stats_y = hud_y + 12;
|
||||
int stat_spacing = 40;
|
||||
|
||||
// ATK
|
||||
char atk_text[16];
|
||||
snprintf(atk_text, sizeof(atk_text), "%d", p->attack);
|
||||
DrawText(atk_text, stats_x + stat_spacing, stats_y, 14, YELLOW);
|
||||
DrawText("ATK", stats_x + stat_spacing, stats_y + 16, 9, text_dim);
|
||||
char floor_text[16];
|
||||
snprintf(floor_text, sizeof(floor_text), "F%d", p->floor);
|
||||
DrawText(floor_text, stats_x, stats_y, 14, text_bright);
|
||||
DrawText("Floor", stats_x, stats_y + 16, 9, text_dim);
|
||||
|
||||
// DEF
|
||||
char def_text[16];
|
||||
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});
|
||||
DrawText("DEF", stats_x + stat_spacing * 2, stats_y + 16, 9, text_dim);
|
||||
char atk_text[16];
|
||||
snprintf(atk_text, sizeof(atk_text), "%d", p->attack);
|
||||
DrawText(atk_text, stats_x + stat_spacing, stats_y, 14, YELLOW);
|
||||
DrawText("ATK", stats_x + stat_spacing, stats_y + 16, 9, text_dim);
|
||||
|
||||
int equip_x = section2_end + 15;
|
||||
int equip_y = hud_y + 8;
|
||||
char def_text[16];
|
||||
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});
|
||||
DrawText("DEF", stats_x + stat_spacing * 2, stats_y + 16, 9, text_dim);
|
||||
}
|
||||
|
||||
// Weapon slot
|
||||
DrawText("WEAPON", equip_x, equip_y, 9, text_dim);
|
||||
if (p->has_weapon) {
|
||||
const char *weapon_name = item_get_name(&p->equipped_weapon);
|
||||
if (weapon_name) {
|
||||
char weapon_text[64];
|
||||
snprintf(weapon_text, sizeof(weapon_text), "%s +%d [%s]", weapon_name, p->equipped_weapon.power,
|
||||
dmg_class_get_short(p->equipped_weapon.dmg_class));
|
||||
DrawText(weapon_text, equip_x, equip_y + 11, 10, (Color){255, 220, 100, 255});
|
||||
static void draw_equipment(
|
||||
const Player *p, int hud_y, int equip_x, Color text_dim
|
||||
) {
|
||||
int equip_y = hud_y + 8;
|
||||
|
||||
DrawText("WEAPON", equip_x, equip_y, 9, text_dim);
|
||||
if (p->has_weapon) {
|
||||
const char *weapon_name = item_get_name(&p->equipped_weapon);
|
||||
if (weapon_name) {
|
||||
char weapon_text[64];
|
||||
snprintf(weapon_text, sizeof(weapon_text), "%s +%d [%s]",
|
||||
weapon_name, p->equipped_weapon.power,
|
||||
dmg_class_get_short(p->equipped_weapon.dmg_class));
|
||||
DrawText(weapon_text, equip_x, equip_y + 11, 10, (Color){255, 220, 100, 255});
|
||||
}
|
||||
} else {
|
||||
DrawText("None [IMP]", equip_x, equip_y + 11, 10, (Color){80, 75, 70, 255});
|
||||
}
|
||||
} else {
|
||||
DrawText("None [IMP]", equip_x, equip_y + 11, 10, (Color){80, 75, 70, 255});
|
||||
}
|
||||
|
||||
// Armor slot
|
||||
DrawText("ARMOR", equip_x, equip_y + 26, 9, text_dim);
|
||||
if (p->has_armor) {
|
||||
const char *armor_name = item_get_name(&p->equipped_armor);
|
||||
if (armor_name) {
|
||||
char armor_text[48];
|
||||
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});
|
||||
DrawText("ARMOR", equip_x, equip_y + 26, 9, text_dim);
|
||||
if (p->has_armor) {
|
||||
const char *armor_name = item_get_name(&p->equipped_armor);
|
||||
if (armor_name) {
|
||||
char armor_text[48];
|
||||
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});
|
||||
}
|
||||
} else {
|
||||
DrawText("None", equip_x, equip_y + 37, 10, (Color){80, 75, 70, 255});
|
||||
}
|
||||
} else {
|
||||
DrawText("None", equip_x, equip_y + 37, 10, (Color){80, 75, 70, 255});
|
||||
}
|
||||
}
|
||||
|
||||
int ctrl_x = section3_end + 20;
|
||||
int ctrl_y = hud_y + 14;
|
||||
static void draw_controls_inv(const Player *p, int hud_y, int ctrl_x, Color controls_color) {
|
||||
int ctrl_y = hud_y + 14;
|
||||
DrawText("[WASD] Move [G] Pickup [I] Inventory [U] Use",
|
||||
ctrl_x, ctrl_y, 11, controls_color);
|
||||
DrawText("[E] Equip [D] Drop [Q] Quit",
|
||||
ctrl_x, ctrl_y + 16, 11, controls_color);
|
||||
|
||||
DrawText("[WASD] Move [G] Pickup [I] Inventory [U] Use", ctrl_x, ctrl_y, 11, (Color){139, 119, 89, 255});
|
||||
DrawText("[E] Equip [D] Drop [Q] Quit", ctrl_x, ctrl_y + 16, 11, (Color){139, 119, 89, 255});
|
||||
char inv_text[16];
|
||||
snprintf(inv_text, sizeof(inv_text), "INV: %d/%d", p->inventory_count, MAX_INVENTORY);
|
||||
int inv_width = MeasureText(inv_text, 10);
|
||||
DrawText(inv_text, SCREEN_WIDTH - inv_width - 10, hud_y + 5, 10, GREEN);
|
||||
}
|
||||
|
||||
// INV count in top-right corner of HUD
|
||||
char inv_text[16];
|
||||
snprintf(inv_text, sizeof(inv_text), "INV: %d/%d", p->inventory_count, MAX_INVENTORY);
|
||||
int inv_width = MeasureText(inv_text, 10);
|
||||
DrawText(inv_text, SCREEN_WIDTH - inv_width - 10, hud_y + 5, 10, GREEN);
|
||||
void render_ui(const Player *p) {
|
||||
// HUD Panel
|
||||
const int hud_y = MAP_HEIGHT * TILE_SIZE;
|
||||
const int hud_height = 60;
|
||||
const Color hud_bg = {25, 20, 15, 255}; // dark parchment
|
||||
const Color hud_border = {139, 119, 89, 255}; // bronze/brown border
|
||||
const Color text_dim = {160, 150, 140, 255}; // dimmed text
|
||||
const Color text_bright = {240, 230, 220, 255}; // bright text
|
||||
const Color magic_color_a = {60, 55, 50, 255}; // I don't know what exactly this is (may be top/left colouring)
|
||||
const Color magic_color_b = {15, 12, 10, 255}; // See above (may be bottom/right colouring)
|
||||
const Color full_health = {60, 180, 60, 255};
|
||||
const Color low_health = {200, 180, 40, 255};
|
||||
const Color crit_health = {200, 60, 60, 255};
|
||||
const Color health_bar_background = {20, 15, 15, 255};
|
||||
const Color health_bar_outline = {80, 70, 60, 255};
|
||||
|
||||
draw_hud_background(hud_y, hud_height, hud_bg, hud_border, magic_color_a, magic_color_b);
|
||||
|
||||
// Section dividers
|
||||
int section1_end = 180; // after portrait + HP bar
|
||||
int section2_end = 310; // after stats
|
||||
int section3_end = 480; // after equipment
|
||||
|
||||
draw_section_divider(hud_y, section1_end, 5, hud_height, magic_color_a, magic_color_b);
|
||||
draw_section_divider(hud_y, section2_end, 5, hud_height, magic_color_a, magic_color_b);
|
||||
|
||||
draw_player_life(p, hud_y, text_bright, text_dim, full_health, low_health,
|
||||
crit_health, health_bar_background, health_bar_outline);
|
||||
|
||||
draw_player_stats(p, hud_y, section1_end + 15, text_bright, text_dim);
|
||||
|
||||
draw_equipment(p, hud_y, section2_end + 15, text_dim);
|
||||
|
||||
draw_controls_inv(p, hud_y, section3_end + 20, hud_border);
|
||||
}
|
||||
|
||||
void render_action_log(const char log[5][128], int count, int head) {
|
||||
|
|
@ -325,7 +340,7 @@ void render_action_log(const char log[5][128], int count, int head) {
|
|||
DrawText("MESSAGE LOG", log_x + 8, log_y + 6, 10, (Color){180, 160, 130, 255});
|
||||
|
||||
// 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 - 4, log_y + 22, log_border_dark);
|
||||
|
||||
// Log entries
|
||||
int text_x = log_x + 8;
|
||||
|
|
@ -355,7 +370,7 @@ void render_action_log(const char log[5][128], int count, int head) {
|
|||
void render_inventory_overlay(const Player *p, int selected) {
|
||||
// Overlay dimensions
|
||||
int ov_width = 360;
|
||||
int ov_height = 300;
|
||||
int ov_height = 337;
|
||||
Rectangle overlay = {(float)(SCREEN_WIDTH - ov_width) / 2, (float)(SCREEN_HEIGHT - ov_height) / 2 - 60,
|
||||
(float)ov_width, (float)ov_height};
|
||||
DrawRectangleRec(overlay, (Color){12, 12, 12, 252});
|
||||
|
|
@ -379,8 +394,8 @@ void render_inventory_overlay(const Player *p, int selected) {
|
|||
|
||||
// Selection highlight
|
||||
if (i == selected) {
|
||||
DrawRectangle((int)overlay.x + 6, y_pos, (int)overlay.width - 12, row_height - 2, (Color){45, 45, 45, 255});
|
||||
DrawRectangleLines((int)overlay.x + 6, y_pos, (int)overlay.width - 12, row_height - 2,
|
||||
DrawRectangle((int)overlay.x + 6, y_pos - 2, (int)overlay.width - 12, row_height - 2, (Color){45, 45, 45, 255});
|
||||
DrawRectangleLines((int)overlay.x + 6, y_pos - 2, (int)overlay.width - 12, row_height - 2,
|
||||
(Color){180, 160, 80, 255});
|
||||
}
|
||||
|
||||
|
|
@ -600,6 +615,7 @@ void render_end_screen(int is_victory, int kills, int items, int damage_dealt, i
|
|||
}
|
||||
}
|
||||
|
||||
// Floating message popup
|
||||
void render_message(const char *message) {
|
||||
if (message == NULL)
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -80,10 +80,10 @@ void render_map(const Map *map);
|
|||
void render_player(const Player *p);
|
||||
|
||||
// Render all enemies
|
||||
void render_enemies(const Enemy *enemies, int count, const unsigned char visible[MAP_HEIGHT][MAP_WIDTH]);
|
||||
void render_enemies(const Enemy *enemies, int count);
|
||||
|
||||
// Render all items
|
||||
void render_items(const Item *items, int count, const unsigned char visible[MAP_HEIGHT][MAP_WIDTH]);
|
||||
void render_items(const Item *items, int count);
|
||||
|
||||
// Render UI overlay
|
||||
void render_ui(const Player *p);
|
||||
|
|
|
|||
|
|
@ -63,9 +63,4 @@
|
|||
// Message timer
|
||||
#define MESSAGE_TIMER_DURATION 60
|
||||
|
||||
// Visibility / Fog of War
|
||||
#define PLAYER_VIEW_RANGE 8
|
||||
#define ENEMY_VIEW_RANGE 6
|
||||
#define ENEMY_PATROL_MOVE_CHANCE 30
|
||||
|
||||
#endif // SETTINGS_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue