Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MorsGames
GitHub Repository: MorsGames/sm64plus
Path: blob/master/src/game/behaviors/blue_fish.inc.c
7861 views
1
/**
2
* @file blue_fish.inc.c
3
* Implements behaviour and spawning for bhvBlueFish located in the castle aquarium outside of SA.
4
*/
5
6
/**
7
* Determines fish movement.
8
*/
9
void bhv_blue_fish_movement_loop(void) {
10
f32 randomSwitch;
11
switch (o->oAction) {
12
// Initial dive phase after spawning
13
case BLUE_FISH_ACT_DIVE:
14
cur_obj_init_animation_with_accel_and_sound(0, 1.0f);
15
16
// Assigns random values to variables that help determine natural motion.
17
if (o->oTimer == 0) {
18
o->oBlueFishRandomAngle = random_sign() << 11;
19
o->oBlueFishRandomVel = random_float() * 2;
20
o->oBlueFishRandomTime = (s32)(random_float() * 30) & 0xFE;
21
22
// Adjusts pitch velocity or sets to zero dependant on outcome of randomSwitch.
23
randomSwitch = random_float() * 5;
24
if (randomSwitch < 2.0f) {
25
o->oAngleVelPitch = random_f32_around_zero(128);
26
} else {
27
o->oAngleVelPitch = 0;
28
}
29
}
30
31
// Set forward velocity and progress oAction to BLUE_FISH_ACT_TURN.
32
o->oForwardVel = o->oBlueFishRandomVel + 3.0f;
33
if (o->oTimer >= o->oBlueFishRandomTime + 60) {
34
o->oAction++;
35
}
36
37
// Set pitch velocity
38
if (o->oTimer < (o->oBlueFishRandomTime + 60) / 2) {
39
o->oFaceAnglePitch += o->oAngleVelPitch;
40
} else {
41
o->oFaceAnglePitch -= o->oAngleVelPitch;
42
}
43
44
// Calculate new Y velocity
45
o->oVelY = -sins(o->oFaceAnglePitch) * o->oForwardVel;
46
break;
47
// Animates and adjusts fish yaw angle.
48
case BLUE_FISH_ACT_TURN:
49
cur_obj_init_animation_with_accel_and_sound(0, 2.0f);
50
o->oMoveAngleYaw = (s32)(o->oBlueFishRandomAngle + o->oMoveAngleYaw);
51
if (o->oTimer == 15) {
52
o->oAction++;
53
}
54
break;
55
// Animates and adjusts pitch to an upward direction.
56
case BLUE_FISH_ACT_ASCEND:
57
cur_obj_init_animation_with_accel_and_sound(0, 1.0f);
58
59
// Progresses oAction to BLUE_FISH_ACT_TURN_BACK after elapsed time.
60
if (o->oTimer >= o->oBlueFishRandomTime + 60) {
61
o->oAction++;
62
}
63
64
// Adjusts pitch angle. Direction relies on time not passed.
65
if (o->oTimer < (o->oBlueFishRandomTime + 60) / 2) {
66
o->oFaceAnglePitch -= o->oAngleVelPitch;
67
} else {
68
o->oFaceAnglePitch += o->oAngleVelPitch;
69
}
70
break;
71
// Animates and turns fish around
72
case BLUE_FISH_ACT_TURN_BACK:
73
cur_obj_init_animation_with_accel_and_sound(0, 2.0f);
74
o->oMoveAngleYaw = (s32)(o->oBlueFishRandomAngle + o->oMoveAngleYaw);
75
76
// Sets the fish back to the BLUE_FISH_ACT_DIVE phase.
77
if (o->oTimer == 15) {
78
o->oAction = BLUE_FISH_ACT_DIVE;
79
}
80
break;
81
}
82
83
// Calculates Y velocity and calls physics engine.
84
o->oVelY = -sins(o->oFaceAnglePitch) * o->oForwardVel;
85
cur_obj_move_using_fvel_and_gravity();
86
87
// Deletes object if the parent has oAction set to BLUE_FISH_ACT_DUPLICATE.
88
if (o->parentObj->oAction == BLUE_FISH_ACT_DUPLICATE) {
89
obj_mark_for_deletion(o);
90
}
91
}
92
93
/**
94
* Spawns fifteen fish if Mario resides in room fifteen or seven.
95
* They move at random within 200.0f
96
*/
97
void bhv_tank_fish_group_loop(void) {
98
struct Object *fish;
99
s32 i;
100
switch (o->oAction) {
101
case BLUE_FISH_ACT_SPAWN:
102
if (gMarioCurrentRoom == 15 || gMarioCurrentRoom == 7) {
103
104
// spawns fifteen fish and moves them within 200.0f
105
for (i = 0; i < 15; i++) {
106
fish = spawn_object_relative(0, 300, 0, -200, o, MODEL_FISH, bhvBlueFish);
107
obj_translate_xyz_random(fish, 200.0f);
108
}
109
110
// Proceed to BLUE_FISH_ACT_ROOM phase.
111
o->oAction++;
112
}
113
break;
114
115
// Sets next oAction phase if Mario is not in rooms fifteen and seven.
116
case BLUE_FISH_ACT_ROOM:
117
if (gMarioCurrentRoom != 15 && gMarioCurrentRoom != 7) {
118
o->oAction++;
119
}
120
break;
121
122
// Sets oAction to the BLUE_FISH_ACT_SPAWN phase.
123
case BLUE_FISH_ACT_DUPLICATE:
124
o->oAction = BLUE_FISH_ACT_SPAWN;
125
break;
126
}
127
}
128
129