tox_box.inc.c (5167B)
1 // tox_box.inc.c 2 3 #define FORWARD TOX_BOX_ACT_ROLL_FORWARD, TOX_BOX_ACT_ROLL_LAND 4 #define BACKWARD TOX_BOX_ACT_ROLL_BACKWARD, TOX_BOX_ACT_ROLL_LAND 5 #define RIGHT TOX_BOX_ACT_ROLL_RIGHT, TOX_BOX_ACT_ROLL_LAND 6 #define LEFT TOX_BOX_ACT_ROLL_LEFT, TOX_BOX_ACT_ROLL_LAND 7 #define IDLE TOX_BOX_ACT_IDLE 8 #define END TOX_BOX_ACT_TABLE_END 9 10 s8 sToxBoxActionTable1[] = { 11 FORWARD, FORWARD, RIGHT, RIGHT, BACKWARD, BACKWARD, RIGHT, RIGHT, BACKWARD, IDLE, 12 13 FORWARD, FORWARD, FORWARD, IDLE, 14 15 BACKWARD, BACKWARD, LEFT, LEFT, FORWARD, FORWARD, LEFT, LEFT, BACKWARD, BACKWARD, BACKWARD, IDLE, 16 17 FORWARD, END, 18 }; 19 20 s8 sToxBoxActionTable2[] = { 21 FORWARD, FORWARD, LEFT, LEFT, LEFT, IDLE, 22 23 RIGHT, RIGHT, RIGHT, BACKWARD, BACKWARD, RIGHT, BACKWARD, BACKWARD, IDLE, 24 25 FORWARD, FORWARD, LEFT, END, 26 }; 27 28 s8 sToxBoxActionTable3[] = { 29 FORWARD, FORWARD, FORWARD, FORWARD, FORWARD, IDLE, 30 31 BACKWARD, BACKWARD, BACKWARD, BACKWARD, BACKWARD, LEFT, IDLE, 32 33 RIGHT, RIGHT, BACKWARD, IDLE, 34 35 FORWARD, LEFT, END, 36 }; 37 38 #undef FORWARD 39 #undef BACKWARD 40 #undef RIGHT 41 #undef LEFT 42 #undef IDLE 43 #undef END 44 45 /* 46 * (number = table, v = direction, * = idle) 47 * 48 * +---+ +---+ 49 * |1 *| |1 *| 50 * +---+---+---+ +---+ +---+ +---+ 51 * | 1 | 1 | 1 | |1 v| |2 *| | | 52 * +---+---+---+ +---+---+---+---+---+ +---+---+---+ 53 * | 1 | | 1 | | 1 | | | | 2 | | | | | 54 * +---+---+ +---+---+---+---+---+---+---+---+---+---+---+---+ 55 * | |1 *| | 1 | 1 | 1 | | 2 |2 v| | | | | 56 * +---+---+ +---+---+---+ +---+---+---+---+ +---+ 57 * | 2 | 58 * +---+---+---+---+---+---+---+ +---+ 59 * | 2 | 2 | 2 |2 *| | |3 *| | | 60 * +---+---+---+---+---+---+---+---+---+ 61 * | 3 |3 v|3 *| 62 * +---+---+---+ 63 * | 3 | 64 * +---+ 65 * | 3 | 66 * +---+ 67 * | 3 | 68 * +---+ 69 * | 3 | 70 * +---+ 71 * |3 *| 72 * +---+ 73 */ 74 s8 *sToxBoxActionTables[] = { 75 /* TOX_BOX_BP_MOVEMENT_PATTERN_1 */ sToxBoxActionTable1, 76 /* TOX_BOX_BP_MOVEMENT_PATTERN_2 */ sToxBoxActionTable2, 77 /* TOX_BOX_BP_MOVEMENT_PATTERN_3 */ sToxBoxActionTable3, 78 }; 79 80 void tox_box_shake_screen(void) { 81 if (o->oDistanceToMario < 3000.0f) { 82 cur_obj_shake_screen(SHAKE_POS_SMALL); 83 } 84 } 85 86 void tox_box_move(f32 forwardVel, f32 upVel, s16 deltaPitch, s16 deltaRoll) { 87 o->oPosY = 99.41124 * sins((f32)(o->oTimer + 1) / 8 * 0x8000) + o->oHomeY + 3.0f; 88 o->oForwardVel = forwardVel; 89 o->oUpVel = upVel; 90 o->oFaceAnglePitch += deltaPitch; 91 92 if ((s16) o->oFaceAnglePitch < 0) { 93 deltaRoll = -deltaRoll; 94 } 95 96 o->oFaceAngleRoll += deltaRoll; 97 cur_obj_set_pos_via_transform(); 98 99 if (o->oTimer == 7) { 100 o->oAction = cur_obj_progress_action_table(); 101 cur_obj_play_sound_2(SOUND_GENERAL_UNK46); 102 } 103 } 104 105 void tox_box_act_roll_forward(void) { 106 tox_box_move(64.0f, 0.0f, 0x800, 0); 107 } 108 109 void tox_box_act_roll_backward(void) { 110 tox_box_move(-64.0f, 0.0f, -0x800, 0); 111 } 112 113 void tox_box_act_roll_right(void) { 114 tox_box_move(0.0f, -64.0f, 0, 0x800); 115 } 116 117 void tox_box_act_roll_left(void) { 118 tox_box_move(0.0f, 64.0f, 0, -0x800); 119 } 120 121 void tox_box_act_roll_land(void) { 122 o->oForwardVel = 0.0f; 123 124 if (o->oTimer == 0) { 125 tox_box_shake_screen(); 126 } 127 128 o->oPosY = o->oHomeY + 3.0f; 129 130 if (o->oTimer == 20) { 131 o->oAction = cur_obj_progress_action_table(); 132 } 133 } 134 135 void tox_box_act_idle(void) { 136 if (o->oTimer == 20) { 137 o->oAction = cur_obj_progress_action_table(); 138 } 139 } 140 141 void tox_box_act_unused_idle(void) { 142 if (o->oTimer == 20) { 143 o->oAction = cur_obj_progress_action_table(); 144 } 145 } 146 147 void tox_box_act_init(void) { 148 s8 *actionTable = sToxBoxActionTables[o->oBhvParams2ndByte]; 149 o->oAction = cur_obj_set_action_table(actionTable); 150 } 151 152 void (*sToxBoxActions[])(void) = { 153 tox_box_act_init, 154 tox_box_act_roll_land, 155 tox_box_act_idle, 156 tox_box_act_unused_idle, 157 tox_box_act_roll_forward, 158 tox_box_act_roll_backward, 159 tox_box_act_roll_right, 160 tox_box_act_roll_left, 161 }; 162 163 void bhv_tox_box_loop(void) { 164 cur_obj_call_action_function(sToxBoxActions); 165 load_object_collision_model(); 166 }