summaryrefslogtreecommitdiff
path: root/src/projectile/v1EyeLaser.c
blob: f5f38f5f1b2ed5e35da66cd7bbf429b48201f807 (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
/**
 * @file v1EyeLaser.c
 * @ingroup Projectiles
 *
 * @brief V1 Eye Laser Projectile
 */
#include "entity.h"
#include "projectile.h"
#include "room.h"
#include "physics.h"

typedef struct {
    /*0x00*/ Entity base;
    /*0x68*/ u8 unused1[12];
    /*0x74*/ u32 unk_74;
} V1EyeLaserEntity;

extern void (*const V1EyeLaser_Actions[])(V1EyeLaserEntity*);
extern const Hitbox* const gUnk_0812A5F4[];
extern const Hitbox gUnk_0812A614;
extern const Hitbox gUnk_0812A61C;

void sub_080AB758(Entity*);
void sub_080AB888(Entity*);
void sub_080AB844(Entity* this, s32 param_1, s32 param_2);

void V1EyeLaser(V1EyeLaserEntity* this) {
    if (super->parent->spriteSettings.draw == 0) {
        DeleteThisEntity();
    }
    V1EyeLaser_Actions[super->action](this);
}

void V1EyeLaser_Init(V1EyeLaserEntity* this) {
    this->unk_74 = super->parent->x.WORD;
    if (super->type == 0) {
        super->action = 1;
        COLLISION_OFF(super);
        super->hitbox = (Hitbox*)&gUnk_0812A614;
        InitializeAnimation(super, 0);
    } else {
        super->action = 2;
        super->subtimer = 4;
        InitializeAnimation(super, super->timer);
    }
}

void V1EyeLaser_Action1(V1EyeLaserEntity* this) {
    GetNextFrame(super);
    if ((super->frame & ANIM_DONE) != 0) {
        super->action = 2;
        InitializeAnimation(super, 1);
        sub_080AB758(super);
    }
}

void V1EyeLaser_Action2(V1EyeLaserEntity* this) {
    GetNextFrame(super);
    super->x.WORD += (super->parent->x.WORD - this->unk_74);
    this->unk_74 = super->parent->x.WORD;
    sub_080AB888(super);
    if (super->parent->subtimer == 0) {
        DeleteThisEntity();
    }
}

void sub_080AB758(Entity* this) {
    s32 r6 = 6;
    u32 r7 = 0;
    u32 index = 0;
    u32 tmp = this->y.HALF.HI + r7 + (index << 3);
    for (; tmp <= (u16)(gRoomControls.origin_y + 0xd4);
         index = (index + 1) & 7, tmp = this->y.HALF.HI + r7 + (index << 3)) {
        if ((index & 7) == 7) {
            sub_080AB844(this, 4, r6);
            r6 += 0x3e;
            r7 += 0x3e;
        }
    }

    index = 0;
    tmp = this->y.HALF.HI + r7 + (index << 3);
    for (; tmp <= (u16)(gRoomControls.origin_y + 0xd4);
         index = (index + 1) & 3, tmp = this->y.HALF.HI + r7 + (index << 3)) {
        if ((index & 3) == 3) {
            sub_080AB844(this, 3, r6);
            r6 += 0x1e;
            r7 += 0x1e;
        }
    }

    if (index & 0x2) {
        sub_080AB844(this, 2, r6);
        r6 += 0xe;
    } else if (index & 0x1) {
        sub_080AB844(this, 1, r6);
        r6 += 0x6;
    }

    sub_080AB844(this, 6, r6);
}

void sub_080AB844(Entity* this, s32 param_1, s32 param_2) {
    Entity* entity;

    entity = CreateProjectile(V1_EYE_LASER);
    if (entity != NULL) {
        entity->type = 1;
        entity->timer = param_1;
        entity->parent = this->parent;
        PositionRelative(this, entity, 0, Q_16_16(param_2));
        if (param_1 != 1) {
            entity->hitbox = (Hitbox*)&gUnk_0812A61C;
        } else {
            entity->hitbox = (Hitbox*)&gUnk_0812A614;
        }
    }
}

void sub_080AB888(Entity* this) {
    s32 index;

    this->subtimer--;
    index = 0;

    switch (this->timer) {
        case 3:
            index = 1;
        case 4:
            this->hitbox = (Hitbox*)gUnk_0812A5F4[this->subtimer * 2 + index];
            break;
        case 0:
        case 1:
        case 2:
        default:
            break;
    }

    if (this->subtimer == 0) {
        this->subtimer = 4;
    }
}

void (*const V1EyeLaser_Actions[])(V1EyeLaserEntity*) = {
    V1EyeLaser_Init,
    V1EyeLaser_Action1,
    V1EyeLaser_Action2,
};

extern const Hitbox gUnk_0812A624;
extern const Hitbox gUnk_0812A62C;
extern const Hitbox gUnk_0812A634;

const Hitbox* const gUnk_0812A5F4[] = {
    &gUnk_0812A61C, &gUnk_0812A61C, &gUnk_0812A624, &gUnk_0812A61C,
    &gUnk_0812A62C, &gUnk_0812A624, &gUnk_0812A634, &gUnk_0812A624,
};

const Hitbox gUnk_0812A614 = { 0, 4, { 0, 0, 0, 0 }, 1, 3 };
const Hitbox gUnk_0812A61C = { 0, 8, { 0, 0, 0, 0 }, 1, 6 };
const Hitbox gUnk_0812A624 = { 0, 24, { 0, 0, 0, 0 }, 1, 6 };
const Hitbox gUnk_0812A62C = { 0, 40, { 0, 0, 0, 0 }, 1, 6 };
const Hitbox gUnk_0812A634 = { 0, 56, { 0, 0, 0, 0 }, 1, 6 };