1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
/**
* @file pressurePlate.c
* @ingroup Objects
*
* @brief Pressure Plate object
*/
#include "collision.h"
#include "hitbox.h"
#include "object.h"
#include "sound.h"
#include "flags.h"
#include "room.h"
#include "player.h"
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 PressurePlate_Init;
PressurePlateAction PressurePlate_Action1;
PressurePlateAction PressurePlate_Action2;
static u32 sub_08088938(PressurePlateEntity*);
static u32 get_standing_count(PressurePlateEntity*);
static const u8 sSpriteOffsets[];
void PressurePlate(PressurePlateEntity* this) {
static PressurePlateAction* const PressurePlate_Actions[] = {
PressurePlate_Init,
PressurePlate_Action1,
PressurePlate_Action2,
};
if (super->subtimer) {
if (--super->subtimer == 0) {
this->dir = super->animationState;
InitializeAnimation(super, super->animationState);
}
}
PressurePlate_Actions[super->action](this);
}
void PressurePlate_Init(PressurePlateEntity* this) {
super->action = 1;
super->spriteSettings.draw = 1;
super->spritePriority.b0 = 7;
super->hitbox = (Hitbox*)&gUnk_080FD1D4;
this->dir = super->animationState;
}
void PressurePlate_Action1(PressurePlateEntity* this) {
u8 weight = sub_08088938(this) + get_standing_count(this);
if (super->type + 2 <= weight) {
super->action = 2;
super->subtimer = 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->subtimer = 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 PressurePlate_Action2(PressurePlateEntity* this) {
if (this->canToggle) {
u8 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 sub_08088938(PressurePlateEntity* this) {
u16 x, y;
s32 num;
u32 i;
num = 0;
x = super->x.HALF.HI - 8;
y = super->y.HALF.HI - 8;
for (i = 0; i < 8; ++i) {
Entity* e = gRoomVars.puzzleEntities[i];
if (e != NULL) {
if ((u16)(e->x.HALF.HI - x) < 0x11 && ((u16)(e->y.HALF_U.HI - y) < 0x11)) {
e->spriteOffsetY = sSpriteOffsets[this->dir];
num++;
}
}
}
return num;
}
static u32 get_standing_count(PressurePlateEntity* this) {
u32 num;
num = 0;
if (IsCollidingPlayer(super) != 0) {
gPlayerEntity.base.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,
};
|