-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayer.c
80 lines (75 loc) · 2.09 KB
/
Player.c
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
#include "Player.h"
// float timeOfAscent = 0.18f;
// Game Mechanic Functions
void Jump(struct Player *player, float *timeOfAscent, float *timeOfDescent){
static float ta = 0;
if(player->state == Jumping){
// Take a few frames to jump and do not do it instantaneously
// make the jump occur to the heighest point over a few frames
if(ta < *timeOfAscent){
player->Velocity.y += GetFrameTime() * 100 * -0.3f;
ta += GetFrameTime();
}
else if(ta > *timeOfAscent && ta < *timeOfDescent){
player->Velocity.y += GetFrameTime() * 100 * 0.5f;
ta += GetFrameTime();
}
// Enable movement while jumping
if(IsKeyDown(KEY_LEFT)){
player->Velocity.x = -2;
player->dir = LEFT;
}
else if(IsKeyDown(KEY_RIGHT)){
player->Velocity.x = 2;
player->dir = RIGHT;
}
}
else{
player->Velocity.y = 2;
ta = 0;
}
}
void Gravity(struct Player *player, float *timeOfDescent){
static float td = 0;
if(td< *timeOfDescent){
player->Velocity.y += GetFrameTime() * 100 * 0.5f;
td += GetFrameTime();
}
else{
player->Velocity.y = 0;
td = 0;
}
}
//Debug Functions
void PrintPlayerState(struct Player *player){
switch (player->state) {
case Idle: {
printf("The Player State is : Idle\n");
break;
}
case Walking: {
printf("The Player State is : Walking\n");
break;
}
case Jumping: {
printf("The Player State is : Jumping\n");
break;
}
case Ducking: {
printf("The Player State is : Ducking\n");
break;
}
case Skiding: {
printf("The Player State is : Skiding\n");
break;
}
case Climbing: {
printf("The Player State is : Climbing\n");
break;
}
case Swimming: {
printf("The Player State is : Swimming\n");
break;
}
}
}