diff options
| author | notyourav <65437533+notyourav@users.noreply.github.com> | 2022-01-22 11:35:36 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-22 11:35:36 -0800 |
| commit | 85aaada18f7eace3284937c4da8db05f047d316b (patch) | |
| tree | b9aa9840d57e5d3bd889e29a86163d3387b5aec5 /src/object | |
| parent | 93e745e9638bb4f48e27908eebe2bb4eb349812e (diff) | |
| parent | 737302d9d1808e5a1def42725e27cef99d0196b2 (diff) | |
Merge pull request #310 from notyourav/pressurePlate
pressure plate ok
Diffstat (limited to 'src/object')
| -rw-r--r-- | src/object/bird.c | 2 | ||||
| -rw-r--r-- | src/object/book.c | 2 | ||||
| -rw-r--r-- | src/object/button.c | 4 | ||||
| -rw-r--r-- | src/object/heartContainer.c | 2 | ||||
| -rw-r--r-- | src/object/itemOnGround.c | 8 | ||||
| -rw-r--r-- | src/object/pressurePlate.c | 185 |
6 files changed, 194 insertions, 9 deletions
diff --git a/src/object/bird.c b/src/object/bird.c index efd3ce74..cafe1262 100644 --- a/src/object/bird.c +++ b/src/object/bird.c @@ -116,7 +116,7 @@ void sub_0809D10C(Entity* this) { void sub_0809D130(Entity* this) { if ((gPlayerState.flags & PL_MINISH) != 0) { sub_0800445C(this); - } else if (sub_08017850(this) != 0) { + } else if (IsCollidingPlayer(this) != 0) { CreateItemEntity(0x17, 0, 0); gSave.windcrests |= 0x10000000; DeleteThisEntity(); diff --git a/src/object/book.c b/src/object/book.c index 811ca4ae..790c5839 100644 --- a/src/object/book.c +++ b/src/object/book.c @@ -141,7 +141,7 @@ void sub_0809B56C(Entity* this) { void sub_0809B5B4(Entity* this) { if (gPlayerState.flags & PL_MINISH) { sub_0800445C(this); - } else if (sub_08017850(this)) { + } else if (IsCollidingPlayer(this)) { CreateItemEntity(this->type + 0x39, 0, 0); DeleteThisEntity(); } diff --git a/src/object/button.c b/src/object/button.c index cb7a58c7..316f7608 100644 --- a/src/object/button.c +++ b/src/object/button.c @@ -90,7 +90,7 @@ void sub_08081C30(Entity* this) { this->action = 2; ClearFlag(this->field_0x86.HWORD); SetTileType(0x77, this->field_0x74.HWORD, this->collisionLayer); - SoundReq(SFX_10C); + SoundReq(SFX_BUTTON_PRESS); } } @@ -251,7 +251,7 @@ u32 sub_08081F7C(Entity* this, u32 r7) { SetFlag(this->field_0x86.HWORD); SetTileType(r7, this->field_0x74.HWORD, this->collisionLayer); sub_08081F24(this); - SoundReq(SFX_10C); + SoundReq(SFX_BUTTON_PRESS); if (this->field_0x70.HALF_U.LO != 0xFFFF) SetTile(this->field_0x70.HALF_U.LO, this->field_0x74.HWORD, this->collisionLayer); return 0; diff --git a/src/object/heartContainer.c b/src/object/heartContainer.c index 9e8346b3..a81709c4 100644 --- a/src/object/heartContainer.c +++ b/src/object/heartContainer.c @@ -59,7 +59,7 @@ static void sub_0808E714(Entity* this) { static void sub_0808E764(Entity* this) { sub_08080CB4(this); - if (!(gPlayerState.flags & PL_MINISH) && sub_08017850(this)) { + if (!(gPlayerState.flags & PL_MINISH) && IsCollidingPlayer(this)) { SetFlag(this->cutsceneBeh.HWORD); CreateItemEntity(0x62, 0, 0); DeleteThisEntity(); diff --git a/src/object/itemOnGround.c b/src/object/itemOnGround.c index 910764a2..ec9b2bef 100644 --- a/src/object/itemOnGround.c +++ b/src/object/itemOnGround.c @@ -18,7 +18,7 @@ void sub_080813BC(Entity*); void sub_080810FC(Entity*); bool32 CheckShouldPlayItemGetCutscene(Entity*); -extern u32 sub_080177A0(Entity*, Entity*); +extern u32 IsColliding(Entity*, Entity*); extern void GiveItem(u32, u32); extern void (*const gUnk_0811E7D4[])(Entity*); @@ -269,10 +269,10 @@ void sub_080812A8(Entity* this) { void sub_080812E8(Entity* this) { PlayerState* playerState = &gPlayerState; #ifdef EU - if ((playerState->swim_state & 0x80) && sub_080177A0(this, &gPlayerEntity)) { + if ((playerState->swim_state & 0x80) && IsColliding(this, &gPlayerEntity)) { #else if ((playerState->swim_state & 0x80) && (playerState->flags & PL_MINISH) == 0 && - sub_080177A0(this, &gPlayerEntity)) { + IsColliding(this, &gPlayerEntity)) { #endif sub_080810FC(this); } @@ -289,7 +289,7 @@ void sub_08081328(Entity* this) { CopyPosition(other, this); this->z.HALF.HI--; other = &gPlayerEntity; - if (sub_080177A0(this, other)) { + if (IsColliding(this, other)) { sub_080810FC(this); } } diff --git a/src/object/pressurePlate.c b/src/object/pressurePlate.c new file mode 100644 index 00000000..891616ca --- /dev/null +++ b/src/object/pressurePlate.c @@ -0,0 +1,185 @@ +#define NENT_DEPRECATED +#include "object.h" +#include "functions.h" + +u32 IsColliding(Entity*, Entity*); + +typedef struct { + Entity base; + /*0x68*/ union SplitHWord field_0x68; + /*0x6a*/ union SplitHWord field_0x6a; + /*0x6c*/ union SplitHWord field_0x6c; + /*0x6e*/ union SplitHWord field_0x6e; + /*0x70*/ u16 canToggle; + /*0x72*/ u8 dir; + /*0x73*/ u8 filler73[0x86 - 0x73]; + /*0x86*/ u16 flag; +} PressurePlateEntity; + +typedef void(PressurePlateAction)(PressurePlateEntity*); + +PressurePlateAction sub_08088840; +PressurePlateAction sub_0808886C; +PressurePlateAction sub_080888F4; + +extern Hitbox gUnk_080FD1D4; + +static u32 sub_08088938(PressurePlateEntity*); +static u32 get_standing_count(PressurePlateEntity*); + +static const u8 sSpriteOffsets[]; + +void PressurePlate(PressurePlateEntity* this) { + static PressurePlateAction* const sActions[] = { + sub_08088840, + sub_0808886C, + sub_080888F4, + }; + + if (super->field_0xf) { + if (--super->field_0xf == 0) { + this->dir = super->animationState; + InitializeAnimation(super, super->animationState); + } + } + + sActions[super->action](this); +} + +void sub_08088840(PressurePlateEntity* this) { + super->action = 1; + super->spriteSettings.draw = 1; + super->spritePriority.b0 = 7; + super->hitbox = &gUnk_080FD1D4; + this->dir = super->animationState; +} + +void sub_0808886C(PressurePlateEntity* this) { + u8 weight; + + weight = sub_08088938(this) + get_standing_count(this); + if (super->type + 2 <= weight) { + super->action = 2; + super->field_0xf = 0; + super->animationState = 4; + super->z.HALF.HI = 0; + InitializeAnimation(super, 4); + SetFlag(this->flag); + EnqueueSFX(SFX_PRESSURE_PLATE); + } else { + if (weight > super->animationState) { + if (super->type + 1 == weight) { + super->field_0xf = 4; + InitializeAnimation(super, weight + 1); + } else { + InitializeAnimation(super, weight); + } + EnqueueSFX(SFX_BUTTON_PRESS); + } else if (weight < super->animationState) { + InitializeAnimation(super, weight); + } + super->animationState = weight; + } +} + +void sub_080888F4(PressurePlateEntity* this) { + u8 weight; + + if (this->canToggle) { + weight = sub_08088938(this) + get_standing_count(this); + if (super->type + 2 > weight) { + super->action = 1; + super->animationState = weight; + ClearFlag(this->flag); + InitializeAnimation(super, weight); + } + } +} + +static u32 NONMATCH("asm/non_matching/pressurePlate/sub_08088938.inc", sub_08088938(PressurePlateEntity* this)) { + u16 x, y; + s32 num; + u8* tmp; + u32 i; + + num = 0; + x = super->x.HALF.HI - 8; + y = super->y.HALF.HI - 8; + + tmp = &this->dir; + for (i = 0; i < 8; ++i) { + Entity* e = gRoomVars.field_0x8c[8 + i]; + if (e != NULL) { + if ((u16)(e->x.HALF.HI - x) < 0x11 && ((u16)(e->y.HALF_U.HI - y) < 0x11)) { + e->spriteOffsetY = sSpriteOffsets[*tmp]; + num++; + } + } + } + return num; +} +END_NONMATCH + +static u32 get_standing_count(PressurePlateEntity* this) { + u32 num; + + num = 0; + if (IsCollidingPlayer(super) != 0) { + gPlayerEntity.spriteOffsetY = sSpriteOffsets[this->dir]; + num = 1; + } + if ((gPlayerState.flags & PL_CLONING) != 0) { + if (IsColliding(super, gPlayerClones[0]) != 0) { + gPlayerClones[0]->spriteOffsetY = sSpriteOffsets[this->dir]; + num++; + } + if (IsColliding(super, gPlayerClones[1]) != 0) { + gPlayerClones[1]->spriteOffsetY = sSpriteOffsets[this->dir]; + num++; + } + if (IsColliding(super, gPlayerClones[2]) != 0) { + gPlayerClones[2]->spriteOffsetY = sSpriteOffsets[this->dir]; + num++; + } + } + return num; +} + +static const u8 sSpriteOffsets[] = { + -4, -3, -2, -1, 0, +}; + +static const Frame gSpriteAnimations_PressurePlate_0 = { + .index = 0, + .duration = 0xFF, + .frameSettings = { .b = { .endOfAnimation = 1 } }, +}; + +static const Frame gSpriteAnimations_PressurePlate_1 = { + .index = 1, + .duration = 0xFF, + .frameSettings = { .b = { .endOfAnimation = 1 } }, +}; + +static const Frame gSpriteAnimations_PressurePlate_2 = { + .index = 2, + .duration = 0xFF, + .frameSettings = { .b = { .endOfAnimation = 1 } }, +}; + +static const Frame gSpriteAnimations_PressurePlate_3 = { + .index = 3, + .duration = 0xFF, + .frameSettings = { .b = { .endOfAnimation = 1 } }, +}; + +static const Frame gSpriteAnimations_PressurePlate_4 = { + .index = 4, + .duration = 0xFF, + .frameSettings = { .b = { .endOfAnimation = 1 } }, +}; + +const Frame* const gSpriteAnimations_PressurePlate[] = { + &gSpriteAnimations_PressurePlate_0, &gSpriteAnimations_PressurePlate_1, &gSpriteAnimations_PressurePlate_2, + &gSpriteAnimations_PressurePlate_3, &gSpriteAnimations_PressurePlate_4, +}; |
