Skip to content

Commit

Permalink
[Decompilation] [th01] Kikuri: Player↔ripple collision detection
Browse files Browse the repository at this point in the history
What's with all these useful helper functions all of a sudden?

Part of P0198, funded by Lmocinemod and Ember2528.
  • Loading branch information
nmlgc committed Jun 16, 2022
1 parent 38dd331 commit ca5aef3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 71 deletions.
20 changes: 20 additions & 0 deletions th01/main/boss/b15j.cpp
Expand Up @@ -8,6 +8,7 @@
#include "th01/v_colors.hpp"
extern "C" {
#include "th01/hardware/egc.h"
#include "th01/hardware/input.hpp"
#include "th01/formats/ptn.hpp"
}
#include "th01/formats/pf.hpp"
Expand All @@ -25,6 +26,7 @@ extern "C" {
#include "th01/main/boss/boss.hpp"
#include "th01/main/boss/entity_a.hpp"
#include "th01/main/player/orb.hpp"
#include "th01/main/player/player.hpp"

// Coordinates
// -----------
Expand All @@ -49,6 +51,8 @@ static const screen_y_t HITBOX_BOTTOM = DISC_CENTER_Y;

static const pixel_t SOUL_W = 32;
static const pixel_t SOUL_H = 32;
static const pixel_t RIPPLE_W = 16;
static const pixel_t RIPPLE_H = 16;

static const screen_x_t SOUL_AREA_LEFT = (PLAYFIELD_LEFT + (PLAYFIELD_W / 20));
static const screen_y_t SOUL_AREA_TOP = PLAYFIELD_TOP;
Expand Down Expand Up @@ -230,3 +234,19 @@ void pascal near tears_add(screen_x_t left, screen_y_t top)
}
}
}

bool16 pascal near tear_ripple_hittest(screen_x_t left, pixel_t extra_w)
{
if(player_invincible != true) {
// Translation: 8 pixels in Reimu's center vs. 10 pixels in the ripple
// sprite's center.
if(
(player_left >= (left - ((PLAYER_W / 4) + (RIPPLE_W / 2)))) &&
(player_left <= (left + extra_w))
) {
done = true;
return true;
}
}
return false;
}
85 changes: 14 additions & 71 deletions th01_reiiden.asm
Expand Up @@ -14710,48 +14710,15 @@ main_34_TEXT segment byte public 'CODE' use16
soul:word, delta_x:word, delta_y:word
@TEARS_ADD$QII procdesc pascal near \
left:word, top:word
@TEAR_RIPPLE_HITTEST$QII procdesc pascal near \
left:word, hitbox_w:word
main_34_TEXT ends

main_34__TEXT segment byte public 'CODE' use16
assume cs:main_34
;org 4
assume es:nothing, ss:nothing, ds:_DATA, fs:nothing, gs:nothing

; =============== S U B R O U T I N E =======================================

; Attributes: bp-based frame

sub_236E0 proc near

arg_0 = word ptr 4
arg_2 = word ptr 6

push bp
mov bp, sp
mov dx, [bp+arg_2]
cmp _player_invincible, 1
jz short loc_2370F
mov ax, dx
add ax, -16
cmp ax, _player_left
jg short loc_2370F
mov ax, dx
add ax, [bp+arg_0]
cmp ax, _player_left
jl short loc_2370F
mov _done, 1
mov ax, 1
pop bp
retn 4
; ---------------------------------------------------------------------------

loc_2370F:
xor ax, ax
pop bp
retn 4
sub_236E0 endp


; =============== S U B R O U T I N E =======================================

; Attributes: bp-based frame
Expand Down Expand Up @@ -14860,9 +14827,7 @@ arg_6 = word ptr 0Ah
cmp ax, 5
jge short loc_237DA
call _ptn_put_quarter_8 stdcall, si, di, large 80h or (0 shl 16)
push si
push 0
call sub_236E0
call @tear_ripple_hittest$qii pascal, si, 0
push 7
call _mdrv2_se_play
add sp, 0Ah
Expand All @@ -14876,9 +14841,7 @@ loc_237DA:
cmp ax, 10
jge short loc_237FF
call _ptn_put_quarter_8 c, si, di, large 80h or (1 shl 16)
push si
push 0
call sub_236E0
call @tear_ripple_hittest$qii pascal, si, 0
jmp loc_23C44
; ---------------------------------------------------------------------------

Expand All @@ -14889,9 +14852,7 @@ loc_237FF:
cmp ax, 15
jge short loc_2383B
lea ax, [si-16]
push ax
push 20h ; ' '
call sub_236E0
call @tear_ripple_hittest$qii pascal, ax, 32
push 80h or (1 shl 16)
lea ax, [di-8]
push ax
Expand All @@ -14914,9 +14875,7 @@ loc_2383B:
cmp ax, 20
jge short loc_23881
lea ax, [si-16]
push ax
push 20h ; ' '
call sub_236E0
call @tear_ripple_hittest$qii pascal, ax, 32
push 80h or (1 shl 16)
lea ax, [di-16]
push ax
Expand Down Expand Up @@ -14945,9 +14904,7 @@ loc_23881:
cmp ax, 25
jge short loc_238E7
lea ax, [si-20h]
push ax
push 40h
call sub_236E0
call @tear_ripple_hittest$qii pascal, ax, 64
push 80h or (1 shl 16)
lea ax, [di-24]
push ax
Expand Down Expand Up @@ -14985,9 +14942,7 @@ loc_238E7:
cmp ax, 30
jge short loc_2394A
lea ax, [si-20h]
push ax
push 40h
call sub_236E0
call @tear_ripple_hittest$qii pascal, ax, 64
pushd 80h or (0 shl 16)
lea ax, [di-32]
push ax
Expand Down Expand Up @@ -15022,9 +14977,7 @@ loc_2394A:
cmp ax, 35
jge short loc_239B8
lea ax, [si-20h]
push ax
push 40h
call sub_236E0
call @tear_ripple_hittest$qii pascal, ax, 64
pushd 80h or (0 shl 16)
lea ax, [di-24]
push ax
Expand Down Expand Up @@ -15065,9 +15018,7 @@ loc_239B8:
cmp ax, 40
jge short loc_23A25
lea ax, [si-20h]
push ax
push 40h
call sub_236E0
call @tear_ripple_hittest$qii pascal, ax, 64
pushd 80h or (0 shl 16)
lea ax, [di-16]
push ax
Expand Down Expand Up @@ -15108,9 +15059,7 @@ loc_23A25:
cmp ax, 45
jge short loc_23AA2
lea ax, [si-20h]
push ax
push 40h
call sub_236E0
call @tear_ripple_hittest$qii pascal, ax, 64
pushd 80h or (0 shl 16)
lea ax, [di-8]
push ax
Expand Down Expand Up @@ -15163,9 +15112,7 @@ loc_23AA2:
cmp ax, 50
jge short loc_23B0D
lea ax, [si-20h]
push ax
push 40h
call sub_236E0
call @tear_ripple_hittest$qii pascal, ax, 64
pushd 80h or (0 shl 16)
push di
push si
Expand Down Expand Up @@ -15202,9 +15149,7 @@ loc_23B0D:
cmp ax, 55
jge short loc_23B70
lea ax, [si-20h]
push ax
push 40h
call sub_236E0
call @tear_ripple_hittest$qii pascal, ax, 64
call _ptn_put_quarter_8 stdcall, si, di, 80h or (3 shl 16)
pushd 80h ; '?'
lea ax, [di-8]
Expand Down Expand Up @@ -15236,9 +15181,7 @@ loc_23B70:
cmp ax, 60
jge short loc_23BC0
lea ax, [si-20h]
push ax
push 40h
call sub_236E0
call @tear_ripple_hittest$qii pascal, ax, 64
pushd 80h or (0 shl 16)
push di
lea ax, [si-16]
Expand Down

0 comments on commit ca5aef3

Please sign in to comment.