QUOTE: Be the change, make a difference.

feat: Added wall/solid detection for shooting - freezo - A retro platform game

freezo

A retro platform game
git clone git@soophie.de:/srv/git/freezo
log | files | refs | readme

commit 3a75f561ce255d25b51dd4a8128b0c65c6d256ae
parent 4845e8ea4007b452b2b3660902b677cad089d916
Author: Sophie <info@soophie.de>
Date:   Mon, 16 Dec 2024 10:35:18 +0100

feat: Added wall/solid detection for shooting

Diffstat:
Msrc/player.c | 17+++++++++++++++++
1 file changed, 17 insertions(+), 0 deletions(-)

diff --git a/src/player.c b/src/player.c @@ -279,6 +279,23 @@ void player_update(player_t *player, game_t *game) { player->target_entity = NULL; player->shooting_distance = PLAYER_SHOOTING_RANGE; } + // detect shooting wall/solid + for (int i = 0; i < game->tiles_len; i++) { + tile_t *tile = game->tiles[i]; + if (tile_wall(tile) || tile_solid(tile)) { + rect_t tile_rect = { tile->pos.x, tile->pos.y, TILE_WIDTH, TILE_HEIGHT }; + if (rect_collide(shooting_rect, tile_rect)) { + if (player->dir > 0) { + player->shooting_distance = tile->pos.x - (player->pos.x + PLAYER_WIDTH); + player->target_entity = NULL; + } + else { + player->shooting_distance = player->pos.x - (tile->pos.x + TILE_WIDTH); + player->target_entity = NULL; + } + } + } + } } else { player->target_entity = NULL;