Augmented collision detection
This commit is contained in:
24
src/game.c
24
src/game.c
@@ -68,7 +68,7 @@ bool game_check_line_collision(player_t* player, point_t start, point_t end, uin
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool game_player_check_collision(game_t* game, player_t* player, uint8_t pixels){
|
bool game_check_bounding_collision(game_t* game, player_t* player, uint8_t pixels){
|
||||||
|
|
||||||
// Check bounding collision
|
// Check bounding collision
|
||||||
switch(player->direction){
|
switch(player->direction){
|
||||||
@@ -94,7 +94,11 @@ bool game_player_check_collision(game_t* game, player_t* player, uint8_t pixels)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check collision with players (including self)
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool game_check_player_collision(game_t* game, player_t* player, uint8_t pixels){
|
||||||
|
// Check for collisions with players (including self)
|
||||||
for(int i = 0; i < PLAYER_COUNT; i++){
|
for(int i = 0; i < PLAYER_COUNT; i++){
|
||||||
|
|
||||||
player_t* colliding = &(game->player[i]); // pointer to player whose lines we want to check (against opponent or self)
|
player_t* colliding = &(game->player[i]); // pointer to player whose lines we want to check (against opponent or self)
|
||||||
@@ -116,6 +120,20 @@ bool game_player_check_collision(game_t* game, player_t* player, uint8_t pixels)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do all collision checks!
|
||||||
|
bool game_check_collision(game_t* game, player_t* player, uint8_t pixels){
|
||||||
|
|
||||||
|
// Check for collisions with boundings
|
||||||
|
if(game_check_bounding_collision(game, player, pixels)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for collisions with players (including self)
|
||||||
|
if(game_check_player_collision(game, player, pixels)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false; // no collision!
|
return false; // no collision!
|
||||||
}
|
}
|
||||||
@@ -146,7 +164,7 @@ bool game_player_update(game_t* game, player_t* player, uint8_t pixels){
|
|||||||
if(pixels) {
|
if(pixels) {
|
||||||
|
|
||||||
// Check if a collision is about to happen
|
// Check if a collision is about to happen
|
||||||
if(game_player_check_collision(game, player, pixels)){
|
if(game_check_collision(game, player, pixels)){
|
||||||
player->state=dead;
|
player->state=dead;
|
||||||
stateChanged=true;
|
stateChanged=true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user