various: implement fog of war; make enemy AI slightly more intelligent

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I3e22dbc5e10690871255980c52a24c226a6a6964
This commit is contained in:
raf 2026-04-09 09:35:52 +03:00
commit f85d28e932
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
8 changed files with 151 additions and 21 deletions

View file

@ -11,18 +11,31 @@ 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, DARKGRAY);
DrawRectangleRec(rect, wall_color);
break;
case TILE_FLOOR:
DrawRectangleRec(rect, BLACK);
DrawRectangleRec(rect, floor_color);
break;
case TILE_STAIRS:
DrawRectangleRec(rect, (Color){100, 100, 100, 255});
// Draw stairs marker
DrawText(">", x * TILE_SIZE + 4, y * TILE_SIZE + 2, 12, WHITE);
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});
break;
}
}
@ -35,10 +48,12 @@ void render_player(const Player *p) {
DrawRectangleRec(rect, BLUE);
}
void render_enemies(const Enemy *enemies, int count) {
void render_enemies(const Enemy *enemies, int count, const unsigned char visible[MAP_HEIGHT][MAP_WIDTH]) {
for (int i = 0; i < count; i++) {
if (!enemies[i].alive)
continue;
if (!visible[enemies[i].position.y][enemies[i].position.x])
continue;
Rectangle rect = {(float)(enemies[i].position.x * TILE_SIZE), (float)(enemies[i].position.y * TILE_SIZE),
(float)TILE_SIZE, (float)TILE_SIZE};
@ -80,10 +95,12 @@ void render_enemies(const Enemy *enemies, int count) {
}
}
void render_items(const Item *items, int count) {
void render_items(const Item *items, int count, const unsigned char visible[MAP_HEIGHT][MAP_WIDTH]) {
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};