diff --git a/src/game.cpp b/src/game.cpp index 099326e..ab3b8db 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -176,12 +176,24 @@ void game_advance(struct game *game) } } +static bool standable(struct platform const &p) +{ + return p.type != PLATFORM_SEPARATING_WALL + && p.type != PLATFORM_BLOCK + && p.type != PLATFORM_BLOCK_TOP; +} + +static bool collidable(struct platform const &p) +{ + return p.type == PLATFORM_BLOCK_TOP; +} + num game_height_at(struct game *game, num z, int face) { num max_h = -KILL_PLANE_RADIUS; for(auto const &p: game->level.platform_buffer) { - if(p.face == face && z >= p.z && z <= p.z + p.length) + if(standable(p) && p.face == face && z >= p.z && z <= p.z + p.length) max_h = (max_h >= p.height) ? max_h : p.height; } @@ -195,7 +207,20 @@ struct platform *game_platform_under_player(struct game *game, return NULL; for(auto &p: game->level.platform_buffer) { - if(player->platform == p.face + if(standable(p) && player->platform == p.face + && player->z >= p.z && player->z <= p.z + p.length) { + return &p; + } + } + + return NULL; +} + +struct platform *game_block_hitting_player(struct game *game, + struct player const *player) +{ + for(auto &p: game->level.platform_buffer) { + if(collidable(p) && player->platform == p.face && player->z >= p.z && player->z <= p.z + p.length) { return &p; } diff --git a/src/game.h b/src/game.h index ab1c4e0..2a012de 100644 --- a/src/game.h +++ b/src/game.h @@ -134,4 +134,8 @@ num game_height_at(struct game *game, num z, int face); struct platform *game_platform_under_player(struct game *game, struct player const *player); +/* Returns the block platform that the player is hitting, if any. */ +struct platform *game_block_hitting_player(struct game *game, + struct player const *player); + #endif /* __GAME_H__ */ diff --git a/src/main.cpp b/src/main.cpp index 2ef1efd..2a3c3e3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -155,8 +155,10 @@ int play_level(int level_id) level_update(&game.level, player->z, player->platform); camera_track(camera, player); - struct platform *standing_on = game_platform_under_player(&game, - &game.player); + struct platform *standing_on = + game_platform_under_player(&game, &game.player); + struct platform *hitting = + game_block_hitting_player(&game, &game.player); //======= Rendering =======// @@ -297,7 +299,8 @@ int play_level(int level_id) /* Death condition #1/2: inside a platform (hit it in front) */ bool death_1 = (player->height >= floor - PLAYER_HEIGHT && - player->height < floor - STEP_HEIGHT); + player->height < floor - STEP_HEIGHT) + || (hitting != NULL); /* Death condition #2/2: below the kill plane */ bool death_2 = (player->height < LEVEL_RADIUS - KILL_PLANE_RADIUS);