Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MorsGames
GitHub Repository: MorsGames/sm64plus
Path: blob/master/src/game/behaviors/beta_chest.inc.c
7861 views
1
/**
2
* Behavior for bhvBetaChestBottom and bhvBetaChestLid.
3
* These are apparently the beta versions of chests.
4
* They do not spawn stars or appear in groups; they only
5
* open and spawn an air bubble. In other words, they're
6
* practically the same as underwater chests in-game, except
7
* without any star-giving or puzzle functionality.
8
*/
9
10
/**
11
* Init function for bhvBetaChestBottom.
12
*/
13
void bhv_beta_chest_bottom_init(void) {
14
// Set the object's model
15
cur_obj_set_model(MODEL_TREASURE_CHEST_BASE);
16
17
// ??? Pointless code?
18
// Maybe chests were originally intended to have random yaws.
19
// Shoshinkai 1995 footage shows chests in DDD scattered around
20
// a point with different yaws. Maybe this feature was lazily
21
// cancelled by setting the yaw to 0, right before this beta
22
// object was discarded?
23
o->oMoveAngleYaw = random_u16();
24
o->oMoveAngleYaw = 0;
25
26
// Spawn the chest lid 97 units in the +Y direction and 77 units in the -Z direction.
27
spawn_object_relative(0, 0, 97, -77, o, MODEL_TREASURE_CHEST_LID, bhvBetaChestLid);
28
}
29
30
/**
31
* Update function for bhvBetaChestBottom.
32
* This gives the chest a "virtual hitbox" that pushes Mario away
33
* with radius 200 units and height 200 units.
34
*/
35
void bhv_beta_chest_bottom_loop(void) {
36
cur_obj_push_mario_away_from_cylinder(200.0f, 200.0f);
37
}
38
39
/**
40
* Update function for bhvBetaChestLid.
41
* The chest lid handles all the logic of the chest,
42
* namely opening the chest and spawning an air bubble.
43
*/
44
void bhv_beta_chest_lid_loop(void) {
45
switch (o->oAction) {
46
case BETA_CHEST_ACT_IDLE_CLOSED:
47
if (dist_between_objects(o->parentObj, gMarioObject) < 300.0f) {
48
o->oAction++; // Set to BETA_CHEST_ACT_OPENING
49
}
50
51
break;
52
case BETA_CHEST_ACT_OPENING:
53
if (o->oTimer == 0) {
54
// Spawn the bubble 80 units in the -Y direction and 120 units in the +Z direction.
55
spawn_object_relative(0, 0, -80, 120, o, MODEL_BUBBLE, bhvWaterAirBubble);
56
play_sound(SOUND_GENERAL_CLAM_SHELL1, o->header.gfx.cameraToObject);
57
}
58
59
// Rotate the lid 0x400 (1024) angle units per frame backwards.
60
// When the lid becomes vertical, stop rotating.
61
o->oFaceAnglePitch -= 0x400;
62
if (o->oFaceAnglePitch < -0x4000) {
63
o->oAction++; // Set to BETA_CHEST_ACT_IDLE_OPEN
64
}
65
66
// Fall-through
67
case BETA_CHEST_ACT_IDLE_OPEN:
68
break;
69
}
70
}
71
72