diff --git a/th05/main/bullet/b6ball.cpp b/th05/main/bullet/b6ball.cpp index e6126183..7f0f82bd 100644 --- a/th05/main/bullet/b6ball.cpp +++ b/th05/main/bullet/b6ball.cpp @@ -2,16 +2,22 @@ #include "platform.h" #include "pc98.h" +#include "th01/math/overlap.hpp" #include "th01/math/subpixel.hpp" #include "th04/math/motion.hpp" extern "C" { #include "th04/math/vector.hpp" #include "th04/main/playfld.hpp" +#include "th04/main/player/player.hpp" +#include "th04/main/bullet/clearzap.hpp" +#include "th05/sprites/main_pat.h" #include "th05/main/playperf.hpp" } #include "th05/main/custom.h" #include "th05/main/bullet/b6ball.hpp" +inline void optimization_barrier(void) {} + void near b6balls_add(void) { subpixel_t speed = playperf_speedtune(b6ball_template.speed); @@ -29,3 +35,63 @@ void near b6balls_add(void) return; } } + +void near b6balls_update(void) +{ + CUSTOM_VERIFY(b6ball_t, B6BALL_COUNT); + + b6ball_t near *p; + int i; + for((p = b6balls, i = 1); i < (1 + B6BALL_COUNT); (i++, p++)) { + if(p->flag == B6BF_FREE) { + continue; + } + if(p->flag == B6BF_CLOUD) { + p->cloud_radius -= 2.0f; + if(p->cloud_radius.v < to_sp(B6BALL_W / 2)) { + static_cast(p->flag)++; + } else { + continue; + } + } + + if(bullet_clear_time || bullet_zap.active) { + p->flag = B6BF_DECAY; + } + + p->age++; + /* DX:AX = */ p->pos.update_seg3(); + if(!playfield_encloses(_AX, _DX, B6BALL_W, B6BALL_H)) { + optimization_barrier(); + p->flag = B6BF_FREE; + } else if(p->flag != B6BF_DECAY) { + _AX -= player_pos.cur.x.v; + _DX -= player_pos.cur.y.v; + if(overlap_wh_inplace_fast( + _AX, _DX, to_sp(B6BALL_W / 2), to_sp(B6BALL_H / 2) + )) { + player_is_hit = true; + p->flag = B6BF_DECAY; + continue; + } + optimization_barrier(); + } else if(p->patnum_tiny < PAT_DECAY_B6BALL) { + // Rather brave to assume that the regular patnums of this entity + // can't be smaller. You know how you properly DRY decay state + // initialization? By moving it into a function... + p->patnum_tiny = PAT_DECAY_B6BALL; + p->pos.velocity.x.v /= 2; + p->pos.velocity.y.v /= 2; + p->decay_frames = 0; + } else /* if(p->flag == B6BF_DECAY) */ { + p->decay_frames++; + if((p->decay_frames % 4) == 0) { + p->patnum_tiny++; + if(p->patnum_tiny >= (PAT_DECAY_B6BALL_last + 1)) { + p->flag = B6BF_FREE; + } + } + } + loop_end: + } +} diff --git a/th05/main/bullet/b6ball.hpp b/th05/main/bullet/b6ball.hpp index 9b89aead..3d0bba4f 100644 --- a/th05/main/bullet/b6ball.hpp +++ b/th05/main/bullet/b6ball.hpp @@ -18,7 +18,7 @@ typedef struct { b6ball_flag_t flag; unsigned char angle; // unused PlayfieldMotion pos; - unsigned int age; + unsigned int age; // unused and broken, because it's never reset Subpixel cloud_radius; int patnum_tiny; int decay_frames; @@ -33,5 +33,5 @@ typedef struct { // Spawns a new ball bullet according to the [b6ball_template]. void near b6balls_add(); -void pascal near b6balls_update(); +void near b6balls_update(); void pascal near b6balls_render(); diff --git a/th05/main/bullet/b6balls_add_update.asm b/th05/main/bullet/b6balls_add_update.asm deleted file mode 100644 index 6d6f0997..00000000 --- a/th05/main/bullet/b6balls_add_update.asm +++ /dev/null @@ -1,112 +0,0 @@ -public B6BALLS_UPDATE -b6balls_update proc near - push bp - mov bp, sp - push si - push di - mov si, offset b6balls - mov di, 1 - jmp @@more? -; --------------------------------------------------------------------------- - -@@loop: - cmp [si+b6ball_t.flag], 0 - jz @@next - cmp [si+b6ball_t.flag], 1 - jnz short @@no_cloud - sub [si+b6ball_t.cloud_radius], (2 shl 4) - cmp [si+b6ball_t.cloud_radius], ((B6BALL_W / 2) shl 4) - jge @@next - inc [si+b6ball_t.flag] - -@@no_cloud: - cmp _bullet_clear_time, 0 - jnz short @@decay - cmp _bullet_zap_active, 0 - jz short @@motion_update - -@@decay: - mov [si+b6ball_t.flag], 3 - -@@motion_update: - inc [si+b6ball_t.B6B_age] - lea ax, [si+b6ball_t.pos.cur] - call @PlayfieldMotion@update_seg3$qv pascal, ax - cmp ax, (-16 shl 4) - jle short @@clip - cmp ax, ((PLAYFIELD_W + 16) shl 4) - jge short @@clip - cmp dx, (-16 shl 4) - jle short @@clip - cmp dx, ((PLAYFIELD_H + 16) shl 4) - jl short @@hitbox_active_or_already_decaying? - -@@clip: - jmp short @@remove -; --------------------------------------------------------------------------- - -@@hitbox_active_or_already_decaying?: - cmp [si+b6ball_t.flag], 3 - jz short @@in_decay_state - sub ax, _player_pos.cur.x - sub dx, _player_pos.cur.y - add ax, 8 * 16 - cmp ax, 16 * 16 - ja short @@not_hitting_player - add dx, 8 * 16 - cmp dx, 16 * 16 - ja short @@not_hitting_player - mov _player_is_hit, 1 - mov [si+b6ball_t.flag], 3 - jmp short @@next -; --------------------------------------------------------------------------- - -@@not_hitting_player: - jmp short @@next -; --------------------------------------------------------------------------- - -@@in_decay_state: - cmp [si+b6ball_t.B6B_patnum_tiny], PAT_DECAY_B6BALL - jge short @@already_decaying - mov [si+b6ball_t.B6B_patnum_tiny], PAT_DECAY_B6BALL - mov ax, [si+b6ball_t.pos.velocity.x] - cwd - sub ax, dx - sar ax, 1 - mov [si+b6ball_t.pos.velocity.x], ax - mov ax, [si+b6ball_t.pos.velocity.y] - cwd - sub ax, dx - sar ax, 1 - mov [si+b6ball_t.pos.velocity.y], ax - mov [si+b6ball_t.B6B_decay_frames], 0 - jmp short @@next -; --------------------------------------------------------------------------- - -@@already_decaying: - inc [si+b6ball_t.B6B_decay_frames] - mov ax, [si+b6ball_t.B6B_decay_frames] - mov bx, 4 - cwd - idiv bx - or dx, dx - jnz short @@next - inc [si+b6ball_t.B6B_patnum_tiny] - cmp [si+b6ball_t.B6B_patnum_tiny], (PAT_DECAY_B6BALL + BULLET_DECAY_CELS) - jl short @@next - -@@remove: - mov [si+b6ball_t.flag], 0 - -@@next: - inc di - add si, size b6ball_t - -@@more?: - cmp di, 1 + B6BALL_COUNT - jl @@loop - pop di - pop si - pop bp - retn -b6balls_update endp diff --git a/th05_main.asm b/th05_main.asm index ac4e5764..77e73c05 100644 --- a/th05_main.asm +++ b/th05_main.asm @@ -19673,10 +19673,10 @@ main_035_TEXT ends BOSS_6_TEXT segment byte public 'CODE' use16 @b6balls_add$qv procdesc near + @b6balls_update$qv procdesc near BOSS_6_TEXT ends BOSS_X_TEXT segment byte public 'CODE' use16 -include th05/main/bullet/b6balls_add_update.asm ; =============== S U B R O U T I N E ======================================= @@ -21130,7 +21130,7 @@ loc_1E522: call @boss_defeat_update$qui pascal, 65 loc_1E527: - call b6balls_update + call @b6balls_update$qv call @curvebullets_update$qv call hud_hp_update_and_render pascal, _boss_hp, 22800 pop di