Commit d255510d authored by Valentin Bartschies's avatar Valentin Bartschies
Browse files

Fixed alien projectiles not spawning from lowest & shooting animation

parent a0f44165
......@@ -83,34 +83,39 @@ void aliensTick(Aliens *aliens) {
aliens->pos.x += LASER_CANON_SPEED * (aliens->movingRight ? 1 : -1);
for (int j = 0; j < ALIEN_COLS; ++j) {
if (aliens->instances[j]) {
for (int k = 0; k < ALIEN_ROWS; k++) {
if (aliens->instances[j][k]->alive) {
int lowestI = ALIEN_ROWS - 1;
Alien* lowest = aliens->instances[j][lowestI];
int lowestI = ALIEN_ROWS - 1;
Alien* lowest = aliens->instances[j][lowestI];
while (!lowest && --lowestI) --lowest; // Side effect: lowestI won't get decremented if lowest is truthy
while (!lowest->alive && lowestI > 0) {
--lowestI;
lowest = aliens->instances[j][lowestI];
}
if (lowest->shooting && (aliens->lastShots[j] / (FRAME_RATE / 2)) % 2) { // Close mouth after projectile has been launched
lowest->shooting = false;
} else if (!lowest->shooting && (aliens->lastShots[j] / (FRAME_RATE * 2)) % 2 && rand() <= RAND_MAX * 0.005f) { // Chance to shoot a projectile
if (lowest->shooting && (aliens->lastShots[j] / (FRAME_RATE / 2)) % 2) { // Close mouth after projectile has been launched
lowest->shooting = false;
} else if (!lowest->shooting && (aliens->lastShots[j] / (FRAME_RATE * 2)) % 2 && rand() <= RAND_MAX * 0.005f) { // Chance to shoot a projectile
for (int i = 0; i < ALIEN_MAX_PROJECTILES; ++i) {
if (!aliens->projectiles[i]) {
lowest->shooting = true;
aliens->lastShots[j] = 0;
for (int i = 0; i < ALIEN_MAX_PROJECTILES; ++i) {
if (!aliens->projectiles[i]) {
lowest->shooting = true;
aliens->lastShots[j] = 0;
Projectile *proj = malloc(sizeof *proj);
proj->movingUp = false;
proj->pos = (Vector2) { aliens->pos.x + j * (ALIEN_SIZE + ALIEN_OFFSET) + (ALIEN_SIZE - PROJECTILE_WIDTH) / 2, aliens->pos.y + lowestI * (ALIEN_SIZE + ALIEN_OFFSET) + ALIEN_SIZE };
Projectile *proj = malloc(sizeof *proj);
proj->movingUp = false;
proj->pos = (Vector2) { aliens->pos.x + j * (ALIEN_SIZE + ALIEN_OFFSET) + (ALIEN_SIZE - PROJECTILE_WIDTH) / 2, aliens->pos.y + lowestI * (ALIEN_SIZE + ALIEN_OFFSET) + ALIEN_SIZE };
aliens->projectiles[i] = proj;
aliens->projectiles[i] = proj;
break;
break;
}
}
}
}
++aliens->lastShots[j];
++aliens->lastShots[j];
}
}
}
}
......
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