-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplayer.h
More file actions
159 lines (129 loc) · 3.14 KB
/
player.h
File metadata and controls
159 lines (129 loc) · 3.14 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
/**
* Player types and functions.
*/
#ifndef _PLAYER_H
#define _PLAYER_H
#include <stdint.h>
#include "timer.h"
/**
* Denotes that the player is standing still.
*/
#define PLAYER_STANDING 0
/**
* Denotes that the player is walking. Primarily used to determine the sprite
* graphics to display when the player is in motion.
*/
#define PLAYER_WALKING 1
/**
* Denotes that the player is moving fast enough to be considered "running".
* Primarily used to determine the sprite graphics to display.
*/
#define PLAYER_RUNNING 2
/**
* Denotes that the player is jumping. Used for sprite graphics selection.
*/
#define PLAYER_JUMPING 3
/**
* Denotes that the player if pivoting (accelerating opposite of the current
* horizontal velocity while not airbore). Primairily used for sprite selection.
*/
#define PLAYER_PIVOTING 4
/**
* Denotes that the player is facing right. Note this is not the same thing as
* the direction the player is moving.
*/
#define HEADING_RIGHT 0
/**
* Denotes that the player is facing left.
*/
#define HEADING_LEFT 1
/**
* Maximum walking speed in 8.8 fixed point.
*/
#define MAX_WALK_SPEED 0x180
/**
* Maximum running speed in 8.8 fixed point.
*/
#define MAX_RUN_SPEED 0x280
/**
* Initial jump speed in 8.8 fixed point.
*/
#define INITIAL_JUMP_SPEED 0x280
/**
* How fast "gravity" affects a jump when the player is "slow falling". Slow
* falls occur for up to 24 frames while the player is holding the A button
* after a jump. Denoted in 8.8 fixed point.
*/
#define FALL_SLOW_ACCEL 0x10
/**
* How fast "gravity" is when the player is "fast falling". Denoted in 8.8
* fixed point.
*/
#define FALL_FAST_ACCEL 0x50
/**
* Maximum fall speed for the player in 8.8 fixed point.
*/
#define MAX_FALL_SPEED 0x400
/**
* Maximum number of frames to apply "slow fall" acceleration.
*/
#define MAX_FALL_SLOW_FRAMES 24
/**
* Y position for the player when grounded in 8.8 fixed point.
*/
#define GROUND_Y (96 << 8)
/**
* Starting horizontal position for the player in 8.8 fixed point.
*/
#define PLAYER_X_START (90 << 8)
/**
* Player structure. Organizes various values related to the player's state.
*/
typedef struct Player {
/**
* Player's x position in 8.8 fixed point.
*/
uint16_t x;
/**
* Player's x velocity in 8.8 fixed point.
*/
int16_t dx;
/**
* Player's y position in 8.8 fixed point.
*/
uint16_t y;
/**
* Player's y velocity in 8.8 fixed point.
*/
int16_t dy;
/**
* Player's graphical state.
* @see PLAYER_STANDING, PLAYER_WALKING, PLAYER_RUNNING, PLAYER_JUMPING,
* PLAYER_PIVOTING
*/
uint8_t state;
/**
* The direction the player is facing.
* @see HEADING_LEFT, HEADING_RIGHT
*/
uint8_t heading;
/**
* Current walk animation frame. Can be either 0 or 1.
*/
uint8_t walk_frame;
/**
* Whether or not the player is considered "airborne".
*/
uint8_t airborne;
/**
* Whether or not the player is "slow falling".
*/
uint8_t slow_fall;
} Player;
/**
* The main player state object.
*/
extern Player player;
void init_player(void);
void update_player(void);
#endif