1
0
Fork 0
forked from NotAShelf/rogged

various: sub-tile lighting; nicer visibility calculations

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I0f0a0c12db76cc8e0f4c8ccc72ca4b826a6a6964
This commit is contained in:
raf 2026-04-28 15:57:17 +03:00
commit 00b3798ae0
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
8 changed files with 206 additions and 47 deletions

View file

@ -131,8 +131,12 @@ static void init_floor(GameState *gs, int floor_num) {
}
gs->player.floor = floor_num;
// Calculate initial visibility
calculate_visibility(&gs->map, gs->player.position.x, gs->player.position.y);
// Set initial player light and compute visibility
LightSource player_light = {gs->player.position.x, gs->player.position.y, PLAYER_LIGHT_INTENSITY, PLAYER_LIGHT_RANGE};
LightSource sources[1 + 32];
sources[0] = player_light;
memcpy(sources + 1, gs->static_lights, gs->static_light_count * sizeof(LightSource));
compute_lighting(&gs->map, sources, 1 + gs->static_light_count);
// Spawn enemies
enemy_spawn(gs->enemies, &gs->enemy_count, &gs->map, &gs->player, floor_num);
@ -228,7 +232,11 @@ static void post_action(GameState *gs, Enemy *attacked_enemy) {
}
// Update visibility based on player's new position
calculate_visibility(&gs->map, gs->player.position.x, gs->player.position.y);
LightSource p_light = {gs->player.position.x, gs->player.position.y, PLAYER_LIGHT_INTENSITY, PLAYER_LIGHT_RANGE};
LightSource srcs[1 + 32];
srcs[0] = p_light;
memcpy(srcs + 1, gs->static_lights, gs->static_light_count * sizeof(LightSource));
compute_lighting(&gs->map, srcs, 1 + gs->static_light_count);
// Enemy turns - uses speed/cooldown system
enemy_update_all(gs->enemies, gs->enemy_count, &gs->player, &gs->map);
@ -269,7 +277,13 @@ 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.position.x, gs->player.position.y);
{
LightSource l = {gs->player.position.x, gs->player.position.y, PLAYER_LIGHT_INTENSITY, PLAYER_LIGHT_RANGE};
LightSource s[1 + 32];
s[0] = l;
memcpy(s + 1, gs->static_lights, gs->static_light_count * sizeof(LightSource));
compute_lighting(&gs->map, s, 1 + gs->static_light_count);
}
if (gs->player.hp <= 0)
gs->game_over = 1;
gs->last_message = "You are stunned!";
@ -652,8 +666,8 @@ static void game_loop(unsigned int run_seed, FontManager *fm) {
cam.offset = (Vector2){(float)gs.shake_x, (float)gs.shake_y};
BeginMode2D(cam);
render_map(&gs.map, &gs.tileset);
render_items(gs.items, gs.item_count, gs.map.visible, &gs.tileset);
render_enemies(gs.enemies, gs.enemy_count, gs.map.visible, &gs.tileset, frame_counter);
render_items(gs.items, gs.item_count, &gs.map, &gs.tileset);
render_enemies(gs.enemies, gs.enemy_count, &gs.map, &gs.tileset, frame_counter);
render_player(&gs.player, &gs.tileset, frame_counter);
// Draw slash effect on top of entities
if (gs.slash_timer > 0) {