diff --git a/th05/main/boss/b4_both.cpp b/th05/main/boss/b4_both.cpp index 8f30a727..252c6b62 100644 --- a/th05/main/boss/b4_both.cpp +++ b/th05/main/boss/b4_both.cpp @@ -13,6 +13,7 @@ #include "th05/sprites/main_pat.h" #include "th04/main/playfld.hpp" #include "th05/main/boss/boss.hpp" +#include "th05/main/boss/impl.hpp" #define mai boss #define yuki boss2 diff --git a/th05/main/boss/boss.hpp b/th05/main/boss/boss.hpp index 60d0786d..f7b237a3 100644 --- a/th05/main/boss/boss.hpp +++ b/th05/main/boss/boss.hpp @@ -36,66 +36,6 @@ static const int BOSS_FLYSTEP_RANDOM_FRAMES = 28; // function returns true. bool pascal near boss_flystep_random(int frame); -#define flystep_random_for( \ - boss, \ - next_y_direction, \ - speed, \ - frames, \ - clamp_left, \ - clamp_right, \ - clamp_top, \ - clamp_bottom, \ - sprite_left, \ - sprite_right, \ - sprite_still, \ - frame \ -) \ - if(frame == 0) { \ - if(boss.pos.cur.x.v < BOSS_FLYSTEP_RANDOM_FIELD_LEFT) { \ - boss.angle = (randring2_next16_mod(0x60) - 0x30); \ - } else if(boss.pos.cur.x.v > BOSS_FLYSTEP_RANDOM_FIELD_RIGHT) { \ - boss.angle = (randring2_next16_and(0x60) + 0x30); \ - } else { \ - boss.angle = randring2_next16(); \ - } \ - if( \ - (next_y_direction == Y_UP ) && (boss.angle < 0x80) || \ - (next_y_direction == Y_DOWN) && (boss.angle >= 0x80) \ - ) { \ - boss.angle = -boss.angle; \ - } \ - next_y_direction = Y_ANY; \ - } \ - if(frame >= 0) { \ - vector2_near( \ - boss.pos.velocity, boss.angle, (to_sp(speed) - (frame * 2)) \ - ); \ - boss.pos.cur.x.v += boss.pos.velocity.x.v; \ - boss.pos.cur.y.v += boss.pos.velocity.y.v; \ - if(boss.pos.velocity.x.v < 0) { \ - boss.sprite = sprite_left; \ - } else { \ - boss.sprite = sprite_right; \ - } \ - if(boss.pos.cur.y.v < clamp_top) { \ - boss.pos.cur.y.v = clamp_top; \ - next_y_direction = Y_DOWN; \ - } else if(boss.pos.cur.y.v > clamp_bottom) { \ - boss.pos.cur.y.v = clamp_bottom; \ - next_y_direction = Y_UP; \ - } \ - if(boss.pos.cur.x.v < clamp_left) { \ - boss.pos.cur.x.v = clamp_left; \ - } else if(boss.pos.cur.x.v > clamp_right) { \ - boss.pos.cur.x.v = clamp_right; \ - } \ - if(frame >= frames) { \ - boss.sprite = sprite_still; \ - return true; \ - } \ - } \ - return false; - // Steps the [boss] from its current position towards the target point, moving // it by a hardcoded fraction of the distance. Returns true once the [boss] // has reached the target point. diff --git a/th05/main/boss/impl.hpp b/th05/main/boss/impl.hpp new file mode 100644 index 00000000..56c8d23d --- /dev/null +++ b/th05/main/boss/impl.hpp @@ -0,0 +1,62 @@ +// Shared boss implementation macros. + +#define flystep_random_for( \ + boss, \ + next_y_direction, \ + speed, \ + frames, \ + clamp_left, \ + clamp_right, \ + clamp_top, \ + clamp_bottom, \ + sprite_left, \ + sprite_right, \ + sprite_still, \ + frame \ +) { \ + if(frame == 0) { \ + if(boss.pos.cur.x.v < BOSS_FLYSTEP_RANDOM_FIELD_LEFT) { \ + boss.angle = (randring2_next16_mod(0x60) - 0x30); \ + } else if(boss.pos.cur.x.v > BOSS_FLYSTEP_RANDOM_FIELD_RIGHT) { \ + boss.angle = (randring2_next16_and(0x60) + 0x30); \ + } else { \ + boss.angle = randring2_next16(); \ + } \ + if( \ + (next_y_direction == Y_UP ) && (boss.angle < 0x80) || \ + (next_y_direction == Y_DOWN) && (boss.angle >= 0x80) \ + ) { \ + boss.angle = -boss.angle; \ + } \ + next_y_direction = Y_ANY; \ + } \ + if(frame >= 0) { \ + vector2_near( \ + boss.pos.velocity, boss.angle, (to_sp(speed) - (frame * 2)) \ + ); \ + boss.pos.cur.x.v += boss.pos.velocity.x.v; \ + boss.pos.cur.y.v += boss.pos.velocity.y.v; \ + if(boss.pos.velocity.x.v < 0) { \ + boss.sprite = sprite_left; \ + } else { \ + boss.sprite = sprite_right; \ + } \ + if(boss.pos.cur.y.v < clamp_top) { \ + boss.pos.cur.y.v = clamp_top; \ + next_y_direction = Y_DOWN; \ + } else if(boss.pos.cur.y.v > clamp_bottom) { \ + boss.pos.cur.y.v = clamp_bottom; \ + next_y_direction = Y_UP; \ + } \ + if(boss.pos.cur.x.v < clamp_left) { \ + boss.pos.cur.x.v = clamp_left; \ + } else if(boss.pos.cur.x.v > clamp_right) { \ + boss.pos.cur.x.v = clamp_right; \ + } \ + if(frame >= frames) { \ + boss.sprite = sprite_still; \ + return true; \ + } \ + } \ + return false; \ +} diff --git a/th05/main/boss/move.cpp b/th05/main/boss/move.cpp index 8d78aa5c..4d0396df 100644 --- a/th05/main/boss/move.cpp +++ b/th05/main/boss/move.cpp @@ -1,3 +1,5 @@ +#include "th05/main/boss/impl.hpp" + extern y_direction_t boss_flystep_random_next_y_direction; bool pascal near boss_flystep_random(int frame)