Commit 17df2e4f authored by Valentin Bartschies's avatar Valentin Bartschies
Browse files

Adding player Colision detection

parent dbd0d4c5
......@@ -53,6 +53,17 @@ void calcGame() {
} else if (IsKeyPressed(KEY_SPACE)) {
spawnPlayerProjectile();
}
if (aliens->projectiles[0] || aliens->projectiles[1] || aliens->projectiles[2]) {
for (int i = 0; i < 3; i++)
{
if (playerCollisionDetection(aliens->projectiles[i]))
{
free(aliens->projectiles[i]);
aliens->projectiles[i] = NULL;
}
}
}
if (IsKeyPressed(KEY_K)) { // Placeholder, deleting Aliens one by one with "K"
for (int i = ALIEN_ROWS - 1; i >= 0; i--) {
......@@ -103,3 +114,12 @@ void alienCollisionDetection() {
}
}
}
bool playerCollisionDetection(Projectile *proj) {
if (!proj) return false;
if (CheckCollisionRecs( (Rectangle) { proj->pos.x, proj->pos.y, PROJECTILE_WIDTH, PROJECTILE_HEIGHT}, laserCanon )) {
playerLives--;
return true;
}
}
#pragma once
#include "projectile.h"
void initGame();
void drawGame();
void calcGame();
void destructGame();
void alienCollisionDetection();
bool playerCollisionDetection(Projectile *proj);
void spawnPlayerProjectile();
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment