summaryrefslogtreecommitdiff
path: root/src/object/angryStatue.c
blob: be83f7ddc4534f4800a94515c9ce1bc16d2482d1 (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
/**
 * @file angryStatue.c
 * @ingroup Objects
 *
 * @brief Angry Statue object
 */
#include "asm.h"
#include "entity.h"
#include "hitbox.h"
#include "physics.h"
#include "projectile.h"
#include "room.h"
#include "sound.h"
#include "tiles.h"

void AngryStatue_Init(Entity*);
void AngryStatue_Action1(Entity*);
void AngryStatue_Action2(Entity*);
void AngryStatue_Action3(Entity*);
void AngryStatue_Action4(Entity*);

void AngryStatue(Entity* this) {
    static void (*const AngryStatue_Actions[])(Entity*) = {
        AngryStatue_Init, AngryStatue_Action1, AngryStatue_Action2, AngryStatue_Action3, AngryStatue_Action4,
    };

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

void AngryStatue_Init(Entity* this) {
    this->action = 1;
    this->hitbox = (Hitbox*)&gUnk_080FD178;
    SetTile(SPECIAL_TILE_34, COORD_TO_TILE(this), this->collisionLayer);
    InitializeAnimation(this, this->type);
}

void AngryStatue_Action1(Entity* this) {
    if (this->parent->subtimer == 1) {
        this->action = 2;
        InitializeAnimation(this, this->type + 4);
    }
}

void AngryStatue_Action2(Entity* this) {
    static const s8 gUnk_08124684[] = {
        0, 12, 12, 2, 0, 12, -12, 2,
    };

    Entity* pEVar2;
    const s8* ptr;

    GetNextFrame(this);
    if (this->frame & 1) {
        this->frame &= 0xfe;
        pEVar2 = CreateProjectile(CANNONBALL_PROJECTILE);
        if (pEVar2 != NULL) {
            pEVar2->type = this->type;
            pEVar2->parent = this->parent;
            ptr = &gUnk_08124684[this->type * 2];
            PositionRelative(this, pEVar2, ptr[0] << 0x10, ptr[1] << 0x10);
            EnqueueSFX(SFX_EC);
        }

    } else if ((this->frame & ANIM_DONE) != 0) {
        this->action = 1;
        InitializeAnimation(this, this->type);
    }
}

void AngryStatue_Action3(Entity* this) {
    if (--this->timer == 0) {
        this->action = 4;
        this->timer = 15;
        InitializeAnimation(this, this->type);
    } else {
        this->parent->z.BYTES.byte2 |= 1 << this->type2;
    }
}

void AngryStatue_Action4(Entity* this) {
    this->spriteSettings.draw ^= 1;
    if (--this->timer == 0) {
        this->action = 1;
        this->spriteSettings.draw = 1;
    }
}