summaryrefslogtreecommitdiff
path: root/src/object/picoBloom.c
blob: 157e344c7f26c6e2cb2b2dd0d20a39fbd5174d1a (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
/**
 * @file picoBloom.c
 * @ingroup Objects
 *
 * @brief Pico Bloom object
 */
#include "asm.h"
#include "entity.h"
#include "sound.h"

void PicoBloom_Init(Entity*);
void PicoBloom_Action1(Entity*);
void PicoBloom_Action2(Entity*);

void PicoBloom(Entity* this) {
    static void (*const PicoBloom_Actions[])(Entity*) = {
        PicoBloom_Init,
        PicoBloom_Action1,
        PicoBloom_Action2,
    };

    PicoBloom_Actions[this->action](this);
}

void PicoBloom_Init(Entity* this) {
    static const u8 typeAnimationStates[] = { 3, 0, 3, 3, 3, 3 };
    u32 nextAction;

    nextAction = this->type2;
    if (nextAction != 1) {
        nextAction = 2;
    }
    this->action = nextAction;
    this->timer = (Random() & 0x7f) + 127;
    this->collisionLayer = 1;
    UpdateSpriteForCollisionLayer(this);
    InitializeAnimation(this, typeAnimationStates[this->type] + this->type2);
}

void PicoBloom_Action1(Entity* this) {
    if (--this->timer == 0) {
        this->action++;
    }
}

void PicoBloom_Action2(Entity* this) {
    GetNextFrame(this);
    if (this->frame & 1) {
        this->frame &= ~1;
        EnqueueSFX(SFX_21B);
    }
}