summaryrefslogtreecommitdiff
path: root/src/enemy/spinyChuchu.c
blob: c6ffc5abb1c245f3d58c7ece2dd13600245b2907 (plain)
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/**
 * @file spinyChuchu.c
 * @ingroup Enemies
 *
 * @brief Spiny Chuchu enemy
 */
#include "enemy.h"
#include "hitbox.h"
#include "physics.h"
#include "asm.h"

typedef struct {
    /*0x00*/ Entity base;
    /*0x68*/ u8 unused1[24];
    /*0x80*/ u8 unk_80;
    /*0x81*/ u8 unk_81;
} SpinyChuchuEntity;

u32 sub_080228CC(SpinyChuchuEntity*);
u32 sub_080228F0(SpinyChuchuEntity*);

extern void (*const SpinyChuchu_Functions[])(SpinyChuchuEntity*);
extern void (*const gUnk_080CBA40[])(SpinyChuchuEntity*);

extern const u8 gUnk_080CBA60[];

extern Entity* gUnk_020000B0;

void SpinyChuchu(SpinyChuchuEntity* this) {
    EnemyFunctionHandler(super, (EntityActionArray)SpinyChuchu_Functions);
    EnemySetFXOffset(super, 0, 1, -0x10);
}

void SpinyChuchu_OnTick(SpinyChuchuEntity* this) {
    gUnk_080CBA40[super->action](this);
}

void SpinyChuchu_OnCollision(SpinyChuchuEntity* this) {
    if (super->health) {
        if (super->hitType == 0x65) {
            switch (super->contactFlags & 0x7f) {
                case 2:
                case 3:
                    super->action = 2;
                    super->subtimer = 60;
                    super->hitType = 0x5c;
                    super->hitbox = (Hitbox*)&gHitbox_23;
                    InitializeAnimation(super, 0);
                    break;
                case 8:
                case 9:
                case 10:
                case 0xb:
                case 0xc:
                case 0x16:
                case 0x18:
                case 0x19:
                case 0x1a:
                    EnemyCreateFX(super, FX_STARS);
                    super->action = 5;
                    super->hitType = 0x5c;
                    InitializeAnimation(super, 1);
            }
        } else if (super->contactFlags == (CONTACT_NOW | 0x14)) {
            EnemyCreateFX(super, FX_STARS);
            super->action = 5;
            InitializeAnimation(super, 1);
        }

        if (this->unk_80 != super->health) {
            super->action = 5;
            super->hitType = 0x5c;
            InitializeAnimation(super, 1);
        } else {
            if (super->action == 3) {
                super->action = 4;
                InitializeAnimation(super, 3);
                EnqueueSFX(SFX_194);
            }
        }
    } else {
        InitializeAnimation(super, 1);
    }

    this->unk_80 = super->health;
    EnemyFunctionHandlerAfterCollision(super, SpinyChuchu_Functions);
}

void SpinyChuchu_OnKnockback(SpinyChuchuEntity* this) {
    if (super->animIndex == 1)
        GetNextFrame(super);
    sub_08001318(super);
}

void SpinyChuchu_OnDeath(SpinyChuchuEntity* this) {
    GravityUpdate(super, Q_8_8(24.0));
    if (super->frame & 1) {
        GenericDeath(super);
    } else {
        GetNextFrame(super);
    }
}

void SpinyChuchu_OnGrabbed(SpinyChuchuEntity* this) {
}

void sub_080225EC(SpinyChuchuEntity* this) {
    sub_0804A720(super);
    this->unk_80 = super->health;
    this->unk_81 = 0x5a;
    if (super->timer == 0) {
        super->action = 2;
        InitializeAnimation(super, 0);
    } else {
        super->action = 1;
        super->subtimer = 60;
        super->spriteSettings.draw = 3;
        super->spriteRendering.b3 = 1;
        super->spriteOrientation.flipY = 1;
        super->z.HALF.HI = -0x80;
        InitializeAnimation(super, 6);
    }
}

void sub_08022654(SpinyChuchuEntity* this) {
    switch (super->subAction) {
        case 0:
            if (--super->subtimer)
                return;
            super->subAction = 1;
            SoundReq(SFX_12D);
            InitializeAnimation(super, 0);
            /* fallthrough */
        case 1:
            if (GravityUpdate(super, Q_8_8(24.0)))
                return;

            super->subAction = 2;
            super->spriteSettings.draw = 1;
            InitializeAnimation(super, 5);
            EnqueueSFX(SFX_PLY_LAND);
            UpdateSpriteForCollisionLayer(super);
            /* fallthrough */
        case 2:
            GetNextFrame(super);
            if (--super->timer == 0) {
                super->action = 3;
                super->hitType = 0x65;
                InitializeAnimation(super, 2);
            }
            break;
    }
}

void sub_080226EC(SpinyChuchuEntity* this) {
    if (sub_08049FDC(super, 1)) {
        if (sub_080228CC(this)) {
            super->action = 3;
            super->hitType = 0x65;
            InitializeAnimation(super, 2);
            return;
        }

        if (sub_080228F0(this)) {
            super->action = 6;
            super->zVelocity = Q_16_16(1.125);
            super->speed = 0x140;
            super->direction = GetFacingDirection(super, gUnk_020000B0);
            super->hitType = 0x5a;
            InitializeAnimation(super, 4);
            return;
        }

        if ((super->timer++ & 7) == 0) {
            super->direction = sub_08049F84(super, 1);
        }

        ProcessMovement0(super);
    }

    GetNextFrame(super);
}

void sub_08022780(SpinyChuchuEntity* this) {
    GetNextFrame(super);
    if (super->frame & ANIM_DONE) {
        super->action = 4;
        InitializeAnimation(super, 3);
        EnqueueSFX(SFX_194);
    }
}

void sub_080227AC(SpinyChuchuEntity* this) {
    GetNextFrame(super);
    if (super->frame & 1) {
        super->hitbox = (Hitbox*)&gHitbox_32;
    } else {
        super->hitbox = (Hitbox*)&gHitbox_23;
    }

    if (super->frame & 2) {
        super->frame &= ~2;
        super->hitType = 0x5c;
    }

    if (super->frame & ANIM_DONE) {
        super->action = 2;
        super->subtimer = gUnk_080CBA60[Random() & 3];
        InitializeAnimation(super, 0);
    }
}

void sub_0802281C(SpinyChuchuEntity* this) {
    GravityUpdate(super, Q_8_8(24.0));
    GetNextFrame(super);
    if (super->frame & ANIM_DONE) {
        super->action = 2;
        super->speed = 0x20;
        InitializeAnimation(super, 0);
        EnemyDetachFX(super);
    }
}

void sub_08022854(SpinyChuchuEntity* this) {
    GetNextFrame(super);
    if (super->frame & 1) {
        ProcessMovement2(super);
        if (GravityUpdate(super, Q_8_8(24.0)) == 0) {
            super->action = 7;
            super->hitType = 0x5c;
            InitializeAnimation(super, 5);
            EnqueueSFX(SFX_PLY_LAND);
        }
    }
}

void sub_0802289C(SpinyChuchuEntity* this) {
    GetNextFrame(super);
    if (super->frame & ANIM_DONE) {
        super->action = 2;
        super->speed = 0x20;
        this->unk_81 = 0x78;
        InitializeAnimation(super, 0);
    }
}

u32 sub_080228CC(SpinyChuchuEntity* this) {
    if (super->subtimer == 0) {
        if (PlayerInRange(super, 1, 0x28))
            return 1;
    } else {
        super->subtimer--;
    }
    return 0;
}

u32 sub_080228F0(SpinyChuchuEntity* this) {
    if (this->unk_81 == 0) {
        if (PlayerInRange(super, 1, 0x40))
            return 1;
    } else {
        this->unk_81--;
    }
    return 0;
}

// clang-format off
void (*const SpinyChuchu_Functions[])(SpinyChuchuEntity*) = {
    SpinyChuchu_OnTick,
    SpinyChuchu_OnCollision,
    SpinyChuchu_OnKnockback,
    SpinyChuchu_OnDeath,
    (void (*)(SpinyChuchuEntity*))GenericConfused,
    SpinyChuchu_OnGrabbed,
};

void (*const gUnk_080CBA40[])(SpinyChuchuEntity*) = {
    sub_080225EC,
    sub_08022654,
    sub_080226EC,
    sub_08022780,
    sub_080227AC,
    sub_0802281C,
    sub_08022854,
    sub_0802289C,
};

const u8 gUnk_080CBA60[] = {
    10, 20, 30, 20,
};
// clang-format on