Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
knockback.c
Go to the documentation of this file.
1#include "common.h"
2#include "sprite/player.h"
3
4enum {
7};
8
10 PlayerStatus* playerStatus = &gPlayerStatus;
11 f32 dx, dy;
12 f32 speed;
13
14 static f32 ReturnAngle;
15
16 if (playerStatus->flags & PS_FLAG_ACTION_STATE_CHANGED) {
17 playerStatus->flags &= ~PS_FLAG_ACTION_STATE_CHANGED;
18
19 suggest_player_anim_always_forward(ANIM_Mario1_Hurt);
20
21 playerStatus->flags |= PS_FLAG_FLYING;
22
23 playerStatus->actionSubstate = SUBSTATE_FLYING;
24 playerStatus->gravityIntegrator[0] = 18.3473f;
25 playerStatus->gravityIntegrator[1] = -3.738f;
26 playerStatus->gravityIntegrator[2] = 0.8059f;
27 playerStatus->gravityIntegrator[3] = -0.0987f;
28
30
31 ReturnAngle = atan2(playerStatus->pos.x, playerStatus->pos.z, playerStatus->lastGoodPos.x,
32 playerStatus->lastGoodPos.z);
33 playerStatus->curSpeed = get_xz_dist_to_player(playerStatus->lastGoodPos.x, playerStatus->lastGoodPos.z) / 18.0f;
34 }
35
36 sin_cos_rad(DEG_TO_RAD(ReturnAngle), &dx, &dy);
37
38 speed = playerStatus->curSpeed;
39
40 if (playerStatus->flags & PS_FLAG_ENTERING_BATTLE) {
41 speed *= 0.5f;
42 }
43
44 playerStatus->pos.x += speed * dx;
45 playerStatus->pos.z -= speed * dy;
46
47 if (playerStatus->actionSubstate == SUBSTATE_FLYING) {
49
50 playerStatus->pos.y += playerStatus->gravityIntegrator[0];
51
52 if (playerStatus->gravityIntegrator[0] < 0.0f) {
53 playerStatus->actionSubstate = SUBSTATE_FALLING;
54 playerStatus->flags |= PS_FLAG_FALLING;
55 }
56 } else {
57 s32 colliderID;
58
59 playerStatus->pos.y = player_check_collision_below(player_fall_distance(), &colliderID);
60
61 if (colliderID > NO_COLLIDER) {
62 colliderID = get_collider_flags(colliderID); //TODO surfaceType
64 }
65 }
66}
f32 gravityIntegrator[4]
#define atan2
@ PS_FLAG_FALLING
Definition enums.h:3036
@ PS_FLAG_ENTERING_BATTLE
Definition enums.h:3061
@ PS_FLAG_ACTION_STATE_CHANGED
Definition enums.h:3084
@ PS_FLAG_FLYING
Definition enums.h:3037
@ ACTION_STATE_LAND
Definition enums.h:2437
@ CAMERA_MOVE_IGNORE_PLAYER_Y
Definition enums.h:4732
@ CAM_DEFAULT
Definition enums.h:1800
f32 integrate_gravity(void)
Definition 7BB60.c:436
void suggest_player_anim_always_forward(AnimID anim)
Definition 77480.c:913
s32 get_collider_flags(s32 colliderID)
Definition collision.c:481
f32 player_check_collision_below(f32, s32 *colliderID)
Definition 7BB60.c:470
void set_action_state(s32 actionState)
Definition 7E9D0.c:209
void sin_cos_rad(f32 rad, f32 *outSinTheta, f32 *outCosTheta)
Definition 43F0.c:706
f32 get_xz_dist_to_player(f32, f32)
Definition 77480.c:960
f32 player_fall_distance(void)
Definition 7BB60.c:461
void action_update_knockback(void)
Definition knockback.c:9
@ SUBSTATE_FALLING
Definition knockback.c:6
@ SUBSTATE_FLYING
Definition knockback.c:5
#define DEG_TO_RAD(deg)
Definition macros.h:134
#define NO_COLLIDER
Definition macros.h:156
Camera gCameras[4]
Definition cam_main.c:17
PlayerStatus gPlayerStatus
Definition 77480.c:39