forked from NotAShelf/rogged
various: fixup doors
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Id81f32d86f70a7df99c2ad3d478646416a6a6964
This commit is contained in:
parent
00b3798ae0
commit
d8b49054d5
6 changed files with 345 additions and 87 deletions
38
src/main.c
38
src/main.c
|
|
@ -231,6 +231,19 @@ static void post_action(GameState *gs, Enemy *attacked_enemy) {
|
|||
}
|
||||
}
|
||||
|
||||
// Close doors that the player moved away from before recomputing lighting.
|
||||
for (int dy = 0; dy < MAP_HEIGHT; dy++) {
|
||||
for (int dx = 0; dx < MAP_WIDTH; dx++) {
|
||||
if (gs->map.tiles[dy][dx] == TILE_DOOR_OPEN) {
|
||||
if (gs->player.position.x != dx || gs->player.position.y != dy) {
|
||||
gs->map.tiles[dy][dx] = TILE_DOOR_CLOSED;
|
||||
gs->map.door_anim_target[dy][dx] = 0;
|
||||
gs->map.door_anim_timer[dy][dx] = DOOR_ANIM_FRAMES;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update visibility based on player's new position
|
||||
LightSource p_light = {gs->player.position.x, gs->player.position.y, PLAYER_LIGHT_INTENSITY, PLAYER_LIGHT_RANGE};
|
||||
LightSource srcs[1 + 32];
|
||||
|
|
@ -277,6 +290,18 @@ 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);
|
||||
// Close doors that the player moved away from before recomputing lighting.
|
||||
for (int dy = 0; dy < MAP_HEIGHT; dy++) {
|
||||
for (int dx = 0; dx < MAP_WIDTH; dx++) {
|
||||
if (gs->map.tiles[dy][dx] == TILE_DOOR_OPEN) {
|
||||
if (gs->player.position.x != dx || gs->player.position.y != dy) {
|
||||
gs->map.tiles[dy][dx] = TILE_DOOR_CLOSED;
|
||||
gs->map.door_anim_target[dy][dx] = 0;
|
||||
gs->map.door_anim_timer[dy][dx] = DOOR_ANIM_FRAMES;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
LightSource l = {gs->player.position.x, gs->player.position.y, PLAYER_LIGHT_INTENSITY, PLAYER_LIGHT_RANGE};
|
||||
LightSource s[1 + 32];
|
||||
|
|
@ -639,6 +664,17 @@ static void game_loop(unsigned int run_seed, FontManager *fm) {
|
|||
if (gs.slash_timer > 0)
|
||||
gs.slash_timer--;
|
||||
|
||||
// Door animations are visual, so they tick every rendered frame.
|
||||
for (int y = 0; y < MAP_HEIGHT; y++) {
|
||||
for (int x = 0; x < MAP_WIDTH; x++) {
|
||||
if (gs.map.door_anim_timer[y][x] > 0) {
|
||||
gs.map.door_anim_timer[y][x]--;
|
||||
if (gs.map.door_anim_timer[y][x] == 0 && gs.map.door_anim_target[y][x] == 0)
|
||||
gs.map.door_open_from[y][x] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update player animation
|
||||
if (gs.player.anim_timer > 0) {
|
||||
gs.player.anim_timer--;
|
||||
|
|
@ -787,4 +823,4 @@ int main(int argc, char **argv) {
|
|||
audio_close();
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue