summaryrefslogtreecommitdiff
path: root/src/projectile/dekuSeedProjectile.c
blob: 897fbace3ac9753f95707f7d4b46f4d08a033137 (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
/**
 * @file dekuSeedProjectile.c
 * @ingroup Projectiles
 *
 * @brief Deku Seed Projectile
 */
#include "collision.h"
#include "enemy.h"
#include "entity.h"
#include "physics.h"

extern void (*const DekuSeedProjectile_Functions[])(Entity*);
extern void (*const DekuSeedProjectile_Actions[])(Entity*);

void sub_080A8680(Entity*);
void sub_080A86A0(Entity*);

void DekuSeedProjectile(Entity* this) {
    DekuSeedProjectile_Functions[GetNextFunction(this)](this);
}

void DekuSeedProjectile_OnTick(Entity* this) {
    DekuSeedProjectile_Actions[this->action](this);
}

void DekuSeedProjectile_OnCollision(Entity* this) {
    if (this->contactFlags == CONTACT_NOW) {
        if (this->hitType == 0x68) {
            EnqueueSFX(SFX_86);
        }
        DeleteEntity(this);
    } else {
        this->direction = DirectionRoundUp(this->knockbackDirection);
        if ((u8)(this->contactFlags + 0x7e) < 2) {
            sub_080A8680(this);
        } else {
            InitializeAnimation(this, 0x19);
            sub_080A86A0(this);
        }
    }
}

void DekuSeedProjectile_Init(Entity* this) {
    this->action = 1;
    this->timer = 48;
    this->subtimer = 0;
    this->z.HALF.HI -= 4;
    if (CheckGlobalFlag(TABIDACHI) == 0) {
        this->hitType = 0x68;
    }
    EnqueueSFX(SFX_18D);
    InitializeAnimation(this, 0x18);
}

void DekuSeedProjectile_Action1(Entity* this) {
    Entity* parent;

    GetNextFrame(this);
    if (ProcessMovement3(this) != 0) {
        if (IsProjectileOffScreen(this)) {
            DeleteThisEntity();
        }
        UpdateCollisionLayer(this);
        if (--this->timer == 0) {
            this->action = 4;
        }
    } else {
        sub_0800417E(this, this->collisions);
        UpdateCollisionLayer(this);
        InitializeAnimation(this, 0x19);
        sub_080A86A0(this);
    }
    if (this->subtimer != 0) {
        parent = this->parent;
        if ((parent->next != NULL) && (IsColliding(this, parent) != 0)) {
            this->iframes = 0x10;
            this->knockbackDirection = -this->direction;
            this->contactFlags = CONTACT_NOW;
            this->knockbackDuration = 0xc;
            this->knockbackSpeed = 0;
            parent->iframes = 0x10;
            parent->knockbackDirection = this->direction;
            parent->contactFlags = 0xc2;
            parent->knockbackDuration = 0xc;
            parent->knockbackSpeed = 0;
        }
    }
}

void DekuSeedProjectile_Action2(Entity* this) {
    GetNextFrame(this);
    if (ProcessMovement3(this) != 0) {
        if (IsProjectileOffScreen(this)) {
            DeleteThisEntity();
        }
        if (--this->timer == 0) {
            this->action = 1;
            COLLISION_ON(this);
        }
    } else {
        sub_0800417E(this, this->collisions);
        UpdateCollisionLayer(this);
        InitializeAnimation(this, 0x19);
        sub_080A86A0(this);
    }
}

void DekuSeedProjectile_Action3(Entity* this) {
    GetNextFrame(this);
    if ((this->frame & ANIM_DONE) != 0) {
        DeleteThisEntity();
    }
}

void DekuSeedProjectile_Action4(Entity* this) {
    GetNextFrame(this);
    ProcessMovement3(this);
    switch (BounceUpdate(this, Q_8_8(40.0))) {
        case BOUNCE_DONE_ALL:
            DeleteThisEntity();
            return;
        case BOUNCE_INIT_NEXT:
            COLLISION_OFF(this);
            this->speed = 0x120;

            break;
    }
    if ((this->flags & ENT_COLLIDE) == 0) {
        this->spriteSettings.draw ^= 1;
    }
}

void sub_080A8680(Entity* this) {
    this->action = 2;
    COLLISION_OFF(this);
    this->timer = 3;
    this->subtimer = 1;
    EnqueueSFX(SFX_ITEM_SHIELD_BOUNCE);
}

void sub_080A86A0(Entity* this) {
    this->action = 3;
    COLLISION_OFF(this);
    this->speed = 0;
    EnqueueSFX(SFX_18E);
}

void (*const DekuSeedProjectile_Functions[])(Entity*) = {
    DekuSeedProjectile_OnTick, DekuSeedProjectile_OnCollision, DeleteEntity, DeleteEntity, DeleteEntity,
};
void (*const DekuSeedProjectile_Actions[])(Entity*) = {
    DekuSeedProjectile_Init,    DekuSeedProjectile_Action1, DekuSeedProjectile_Action2,
    DekuSeedProjectile_Action3, DekuSeedProjectile_Action4,
};