From 0750aef98086f85591afbcdc68eaabb60ea4dbd3 Mon Sep 17 00:00:00 2001 From: Trevor Boddy Date: Fri, 23 Sep 2022 10:49:04 -0400 Subject: [PATCH] boss movement --- src/stage.h | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/src/stage.h b/src/stage.h index 7b59aca..badc131 100644 --- a/src/stage.h +++ b/src/stage.h @@ -229,6 +229,40 @@ static void waveBig4(bool right, bool second){ // bosses +#define BOSS_MOD_Y FIX16(16) +#define BOSS_MOD_X FIX16(64) +fix16 bossLimitY, bossLimitH, bossLimitX, bossLimitW; + +static void bossIntro(s16 i){ + if(enemies[i].clock > 0 && enemies[i].clock % 30 == 0){ + enemies[i].speed = fix16Sub(enemies[i].speed, FIX16(0.25)); + if(enemies[i].speed <= 0){ + bossLimitY = fix16Sub(enemies[i].pos.y, BOSS_MOD_Y); + bossLimitH = fix16Add(enemies[i].pos.y, BOSS_MOD_Y); + bossLimitX = fix16Sub(enemies[i].pos.x, BOSS_MOD_X); + bossLimitW = fix16Add(enemies[i].pos.x, BOSS_MOD_X); + enemies[i].speed = FIX16(0.4); + enemies[i].angle = 32; + enemies[i].bools[0] = TRUE; + enemies[i].clock = -1; + } + updateEnemyVel(i); + } +} + +static void bossMove(s16 i){ + if(enemies[i].pos.x > bossLimitW || enemies[i].pos.x < bossLimitX){ + enemies[i].pos.x = enemies[i].pos.x > bossLimitW ? bossLimitW : bossLimitX; + enemies[i].angle = 512 - enemies[i].angle; + updateEnemyVel(i); + } + if(enemies[i].pos.y > bossLimitH || enemies[i].pos.y < bossLimitY){ + enemies[i].pos.y = enemies[i].pos.y > bossLimitH ? bossLimitH : bossLimitY; + enemies[i].angle = 1024 - enemies[i].angle; + updateEnemyVel(i); + } +} + static void waveMidboss1(){ struct enemySpawner spawner = { .angle = 256, @@ -242,6 +276,8 @@ static void waveMidboss1(){ void updater(s16 i){ if(enemies[i].bools[0]){ + bossMove(i); + // ring if(enemies[i].clock % 90 == 0){ struct bulletSpawner spawner = { @@ -249,7 +285,7 @@ static void waveMidboss1(){ .y = enemies[i].pos.y, .image = &bigBullet, .big = TRUE, - .speed = FIX16(1), + .speed = FIX16(1.25), .angle = 80 + random() % 32, .light = TRUE }; @@ -274,16 +310,7 @@ static void waveMidboss1(){ spawnBullet(spawner, EMPTY); } - - } else if(!enemies[i].bools[0] && enemies[i].clock > 0 && enemies[i].clock % 30 == 0) { - enemies[i].speed = fix16Sub(enemies[i].speed, FIX16(0.25)); - if(enemies[i].speed <= 0){ - enemies[i].speed = 0; - enemies[i].bools[0] = TRUE; - enemies[i].clock = -1; - } - updateEnemyVel(i); - } + } else bossIntro(i); } spawnEnemy(spawner, updater, EMPTY); }