summaryrefslogtreecommitdiff
path: root/src/enemy/wizzrobeIce.c
blob: 99ec30ce74accacd934d761cf7b17f26c48b7bb2 (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
/**
 * @file wizzrobeIce.c
 * @ingroup Enemies
 *
 * @brief Wizzrobe Ice enemy
 */
#include "enemy/wizzrobe.h"
#include "enemy.h"
#include "projectile.h"
#include "object.h"
#include "asm.h"
#include "sound.h"
#include "effects.h"
#include "player.h"

extern void (*const WizzrobeIce_Functions[])(WizzrobeEntity*);
extern void (*const WizzrobeIce_Actions[])(WizzrobeEntity*);

void WizzrobeIce(WizzrobeEntity* this) {
    WizzrobeIce_Functions[GetNextFunction(super)](this);
    EnemySetFXOffset(super, 0, 1, -0x10);
}

void WizzrobeIce_OnTick(WizzrobeEntity* this) {
    WizzrobeIce_Actions[super->action](this);
}

void WizzrobeIce_OnCollision(WizzrobeEntity* this) {
    if (super->confusedTime != 0) {
        EnemyCreateFX(super, FX_STARS);
    }
    EnemyFunctionHandlerAfterCollision(super, WizzrobeIce_Functions);
    if (super->contactFlags == (CONTACT_NOW | 0x7)) {
        Entity* obj = CreateObject(FLAME, 3, 0);
        if (obj != NULL) {
            obj->spritePriority.b0 = 3;
            obj->spriteOffsetY = -4;
            obj->parent = super;
        }
    }
    if (super->health == 0) {
        SetTile(this->tileIndex, this->tilePos, super->collisionLayer);
    }
}

void WizzrobeIce_Init(WizzrobeEntity* this) {
    Entity* projectile;

    sub_0804A720(super);
    super->action = 1;
    this->timer2 = 0xff;
    this->timer1 = 0x28;
    super->timer = 40;
    super->subtimer = 96;
    sub_0802F888(this);
    projectile = EnemyCreateProjectile(super, ICE_PROJECTILE, 0);
    if (projectile != NULL) {
        super->child = projectile;
        projectile->parent = super;
        projectile->direction = super->direction;
    }
    InitializeAnimation(super, super->direction >> 3);
}

void WizzrobeIce_Action1(WizzrobeEntity* this) {
    u8 tmp;
    Entity* child;
    switch (this->timer2) {
        case 0xff:
            if (--super->subtimer == 0) {
                this->timer2 = 0;
            }
            break;
        case 0:
            if (--super->timer == 0) {
                this->timer2++;
                super->timer = 12;
                super->flags |= 0x80;
            }

            break;
        case 1:
            if (--super->timer == 0) {
                super->action = 2;
                this->timer2 = 0;
                super->timer = 32;
                tmp = super->direction >> 3;
                child = super->child;
                child->timer = 1;
                child->spriteSettings.draw = 1;
                InitializeAnimation(super, tmp | 4);
            }
            break;
    }
    sub_0802F9C8(this);
}

void WizzrobeIce_Action2(WizzrobeEntity* this) {
    switch (this->timer2) {
        case 0:
            switch (--super->timer) {
                case 0:
                    this->timer2++;
                    super->timer = 56;
                    super->subtimer = 0;
                    super->child->spriteSettings.draw = 0;
                    break;
                case 0xa:
                    if (EntityInRectRadius(super, &gPlayerEntity.base, 0xa0, 0xa0) && CheckOnScreen(super)) {
                        Entity* projectile = EnemyCreateProjectile(super, ICE_PROJECTILE, 1);
                        if (projectile != NULL) {
                            projectile->direction = super->direction & 0x18;
                        }
                    }
                    break;
            }
            break;
        case 1:
            if (--super->timer == 0) {
                this->timer2++;
                this->timer1 = 0x28;
                super->timer = 40;
                super->subtimer = 0;
                super->flags &= ~0x80;
                SetTile(this->tileIndex, this->tilePos, super->collisionLayer);
                EnqueueSFX(SFX_156);
                InitializeAnimation(super, super->direction >> 3);
            }
            break;
        case 2:
            if (--super->timer == 0) {
                this->timer2++;
                super->timer = (Random() & 0x3f) + 24;
                super->spriteSettings.draw = 0;
            }
            break;
        case 3:
            if (--super->timer == 0) {
                super->action = 1;
                this->timer2 = 0;
                this->timer1 = 0x28;
                super->timer = 40;
                EnqueueSFX(SFX_156);
                sub_0802F8E4(this);
                InitializeAnimation(super, super->direction >> 3);
            }
            break;
    }
    sub_0802F9C8(this);
}

void (*const WizzrobeIce_Functions[])(WizzrobeEntity*) = {
    WizzrobeIce_OnTick,
    WizzrobeIce_OnCollision,
    (void (*)(WizzrobeEntity*))GenericKnockback,
    (void (*)(WizzrobeEntity*))GenericDeath,
    (void (*)(WizzrobeEntity*))GenericConfused,
    WizzrobeIce_OnTick,
};
void (*const WizzrobeIce_Actions[])(WizzrobeEntity*) = {
    WizzrobeIce_Init,
    WizzrobeIce_Action1,
    WizzrobeIce_Action2,
};