discovered some bugs in enemy bullets
This commit is contained in:
1 parent
658ed570d5
commit
e1514e8db8
1 file changed
+35
-12
@@ -488,32 +488,49 @@ void enemyMovement(Enemy* enemy) {
|
||||
}
|
||||
|
||||
|
||||
// VIELLEICHT DOCH LIEBER DIREKT DAS BULLET ÜBERGEBEN ????
|
||||
void enemyBullet(Level* lvl, int maxEnemies) {
|
||||
// Enemy soll nach Random Sekunden eine Kugel abschießen
|
||||
for (int i = 0; i < maxEnemies; i++) {
|
||||
if (lvl->basicEnemy[i].isActive) {
|
||||
if (!lvl->basicEnemy[i].shoot) {
|
||||
newTimer(&lvl->basicEnemy[i].timer, GetRandomValue(1, 3));
|
||||
printf("AKTIV\n");
|
||||
lvl->basicEnemy[i].shoot = 1;
|
||||
}
|
||||
|
||||
// Eine neue Kugel erstellen - später auslagern
|
||||
if (lvl->basicEnemy[i].shoot && newTimer(&lvl->basicEnemy[i].timer, 1)) {
|
||||
/*
|
||||
// Speicher reservieren
|
||||
&lvl->basicEnemy[i].bullet = MemRealloc(&lvl->basicEnemy[i].bullet, (&lvl->basicEnemy[i].bulletCount + 1) * sizeof(Bullet));
|
||||
|
||||
&lvl->basicEnemy[i].bulletCount[i].pos = (Vector2){ &lvl->basicEnemy[i].pos.x, &lvl->basicEnemy[i].pos.y };
|
||||
&lvl->basicEnemy[i].bulletCount[i].radius = 2.f;
|
||||
&lvl->basicEnemy[i].bulletCount[i].damage = 10;
|
||||
&lvl->basicEnemy[i].bulletCount[i].color = GREEN;
|
||||
&lvl->basicEnemy[i].bulletCount[i].speed = &lvl->basicEnemy[i].speed + 1.f;
|
||||
&lvl->basicEnemy[i].bulletCount++;
|
||||
*/
|
||||
printf("ENEMY SCHUSS!\n");
|
||||
// Speicher reservieren
|
||||
lvl->basicEnemy[i].bullet = MemRealloc(lvl->basicEnemy[i].bullet, (lvl->basicEnemy[i].bulletCount + 1) * sizeof(Bullet));
|
||||
|
||||
// Bullet erstellen
|
||||
lvl->basicEnemy[i].bullet[lvl->basicEnemy[i].bulletCount].pos = (Vector2){ lvl->basicEnemy[i].pos.x, lvl->basicEnemy[i].pos.y };
|
||||
lvl->basicEnemy[i].bullet[lvl->basicEnemy[i].bulletCount].radius = 2.f;
|
||||
lvl->basicEnemy[i].bullet[lvl->basicEnemy[i].bulletCount].damage = 10;
|
||||
lvl->basicEnemy[i].bullet[lvl->basicEnemy[i].bulletCount].color = GREEN;
|
||||
lvl->basicEnemy[i].bullet[lvl->basicEnemy[i].bulletCount].speed = lvl->basicEnemy[i].speed + 1.f;
|
||||
lvl->basicEnemy[i].bulletCount++; // <- Bullet um 1 hochzählen
|
||||
|
||||
|
||||
printf("ENEMY #%d SCHUSS!\n", i + 1); // Kurz ausgeben wer geschossen hat
|
||||
lvl->basicEnemy[i].shoot = 0;
|
||||
}
|
||||
|
||||
// Alle Kugeln bewegen
|
||||
// Fliegende Kugel wird zerstört wenn der Gegner zerstört wird -> BUG
|
||||
for (int n = 0; n < lvl->basicEnemy[i].bulletCount; n++) {
|
||||
if (lvl->basicEnemy[i].bullet[n].pos.y < HEIGHT) {
|
||||
lvl->basicEnemy[i].bullet[n].pos.y += lvl->basicEnemy[i].bullet[n].speed;
|
||||
}
|
||||
else {
|
||||
lvl->basicEnemy[i].bullet[n] = lvl->basicEnemy[i].bullet[lvl->basicEnemy[i].bulletCount - 1];
|
||||
|
||||
lvl->basicEnemy[i].bulletCount--;
|
||||
|
||||
n--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -553,8 +570,14 @@ void drawLvl1(Level* lvl1) {
|
||||
for (int i = 0; i < LVL1_ENEMIES; i++) {
|
||||
if (lvl1->basicEnemy[i].life > 0)
|
||||
drawEnemy(&lvl1->basicEnemy[i]);
|
||||
|
||||
for (int n = 0; n < lvl1->basicEnemy[i].bulletCount; n++) {
|
||||
DrawCircleV(lvl1->basicEnemy[i].bullet[n].pos, lvl1->basicEnemy[i].bullet[n].radius, lvl1->basicEnemy[i].bullet[n].color);
|
||||
}
|
||||
}
|
||||
DrawText(TextFormat("Gegner: %d", lvl1->enemyCounter), 20, 50, 10, WHITE);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user