Commit 1860641a authored by Valentin Bartschies's avatar Valentin Bartschies
Browse files

putting Alien colision detection in a function

parent 22666182
......@@ -44,18 +44,7 @@ void calcGame() {
}
if (playerProj) {
if (playerProj->pos.y > 1.0) {
for (int i = 0; i < ALIEN_ROWS; i++) {
for (int j = 0; j < ALIEN_COLS; j++) {
if (aliens->instances[j][i]->alive) {
if (CheckCollisionPointRec(playerProj->pos, (Rectangle) {aliens->instances[j][i]->pos.x, aliens->instances[j][i]->pos.y, ALIEN_SIZE, ALIEN_SIZE})) {
aliens->instances[j][i]->alive = false;
playerProj->pos.y = 0;
}
}
}
}
}
alienCollisionDetection();
playerProj = projectileTick(playerProj);
} else if (IsKeyPressed(KEY_SPACE)) {
......@@ -96,3 +85,18 @@ void spawnPlayerProjectile() {
playerProj->movingUp = true;
playerProj->pos = (Vector2) { laserCanonPos.x + laserCanon.width / 2 - PROJECTILE_WIDTH / 2, laserCanonPos.y - PROJECTILE_HEIGHT };
}
void alienCollisionDetection() {
if (playerProj->pos.y > 1.0) {
for (int i = 0; i < ALIEN_ROWS; i++) {
for (int j = 0; j < ALIEN_COLS; j++) {
if (aliens->instances[j][i]->alive) {
if (CheckCollisionPointRec(playerProj->pos, (Rectangle) {aliens->instances[j][i]->pos.x, aliens->instances[j][i]->pos.y, ALIEN_SIZE, ALIEN_SIZE})) {
aliens->instances[j][i]->alive = false;
playerProj->pos.y = 0;
}
}
}
}
}
}
......@@ -4,5 +4,6 @@ void initGame();
void drawGame();
void calcGame();
void destructGame();
void alienCollisionDetection();
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