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
|
/**
* @file spark.c
* @ingroup Enemies
*
* @brief Spark enemy
*/
#include "collision.h"
#include "enemy.h"
#include "effects.h"
#include "object.h"
#include "physics.h"
extern void (*const Spark_Functions[])(Entity*);
extern void (*const gUnk_080CD24C[])(Entity*);
void Spark(Entity* this) {
Spark_Functions[GetNextFunction(this)](this);
}
void Spark_OnTick(Entity* this) {
gUnk_080CD24C[this->action](this);
}
void Spark_OnCollision(Entity* this) {
Entity* entity;
if (this->contactFlags & CONTACT_NOW) {
if ((this->contactFlags & 0x7f) == 0x14) {
COLLISION_OFF(this);
this->iframes = 0;
this->spriteSettings.draw = 0;
this->action = 2;
entity = CreateFx(this, FX_DEATH, 0);
if (entity != NULL) {
this->child = entity;
this->timer = 14;
CopyPosition(this, entity);
}
}
}
}
void Spark_OnGrabbed(Entity* this) {
}
void sub_0802B33C(Entity* this) {
sub_0804A720(this);
this->action = 1;
this->direction = this->type2;
this->subtimer = 120;
InitializeAnimation(this, 0);
}
void sub_0802B35C(Entity* this) {
bool32 is_head;
GetNextFrame(this);
ProcessMovement0(this);
is_head = this->type == 0;
if (this->collisions == COL_NONE) {
if (--this->subtimer == 0) {
this->subtimer = 120;
this->direction += is_head ? DirectionEast : DirectionWest;
this->direction = DirectionRound(this->direction);
}
} else {
this->subtimer = 120;
switch (DirectionRound(this->direction)) {
case DirectionNorth:
if ((this->collisions & COL_NORTH_ANY) != COL_NONE) {
this->direction = is_head ? DirectionWest : DirectionEast;
} else {
if (((this->collisions & COL_EAST_ANY) == COL_EAST_NORTH) && is_head) {
this->direction = DirectionEast;
}
if (((this->collisions & COL_WEST_ANY) == COL_WEST_NORTH) && !is_head) {
this->direction = DirectionWest;
}
}
break;
case DirectionSouth:
if ((this->collisions & COL_SOUTH_ANY) != COL_NONE) {
this->direction = is_head ? DirectionEast : DirectionWest;
} else {
if (((this->collisions & COL_EAST_ANY) == COL_EAST_SOUTH) && !is_head) {
this->direction = DirectionEast;
}
if (((this->collisions & COL_WEST_ANY) == COL_WEST_SOUTH) && is_head) {
this->direction = DirectionWest;
}
}
break;
case DirectionWest:
if ((this->collisions & COL_WEST_ANY) != COL_NONE) {
this->direction = is_head ? DirectionSouth : DirectionNorth;
} else {
if (((this->collisions & COL_NORTH_ANY) == COL_NORTH_EAST) && is_head) {
this->direction = DirectionNorth;
}
if (((this->collisions & COL_SOUTH_ANY) == COL_SOUTH_EAST) && !is_head) {
this->direction = DirectionSouth;
}
}
break;
case DirectionEast:
if ((this->collisions & COL_EAST_ANY) != COL_NONE) {
this->direction = is_head ? DirectionNorth : DirectionSouth;
} else {
if (((this->collisions & COL_NORTH_ANY) == COL_NORTH_WEST) && !is_head) {
this->direction = DirectionNorth;
}
if (((this->collisions & COL_SOUTH_ANY) == COL_SOUTH_WEST) && is_head) {
this->direction = DirectionSouth;
}
}
break;
}
}
}
void sub_0802B4A8(Entity* this) {
if (--this->timer == 0) {
Entity* entity = CreateObjectWithParent(this, GROUND_ITEM, 0x60, 0);
if (entity != NULL) {
entity->y.HALF.HI -= 4;
}
DeleteEntity(this);
}
}
// clang-format off
void (*const Spark_Functions[])(Entity*) = {
Spark_OnTick,
Spark_OnCollision,
GenericKnockback,
GenericDeath,
GenericConfused,
Spark_OnGrabbed,
};
void (*const gUnk_080CD24C[])(Entity*) = {
sub_0802B33C,
sub_0802B35C,
sub_0802B4A8,
};
// clang-format on
|