Repository navigation
Expand file tree
/
Copy pathPlayer.cpp
More file actions
198 lines (138 loc) · 4.59 KB
/
Copy pathPlayer.cpp
File metadata and controls
198 lines (138 loc) · 4.59 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include "Player.h"
// ----- Class Object Declaration -----
Player_Main player_main;
Player_Enemy player_enemy;
// ---------- Player: Main ----------
Player_Main::Player_Main() {
Health = 100;
Speed = 10.0f;
pitch = 0.0f;
yaw = 0.0f;
Pos = { 1 ,2.5f ,1 };
cam = { 0 };
CurrentFrame = 0;
AnimIndex = 17;
AnimCount = 0;
PlayerHitbox = { {-1, -5, -1} , {1, 5 ,1} };
}
void Player_Main::InitializeCamera() {
cam.fovy = 45.0f;
cam.projection = CAMERA_PERSPECTIVE;
cam.up = { 0, 1 , 0 };
cam.position = { -92 , 4 , -92 };
cam.target = { 1 , 1 , 1 };
}
void Player_Main::CameraPos() {
yaw -= MD.x * 0.15f;
pitch -= MD.y * 0.15;
pitch = Clamp(pitch, -89.0f, 89.0f);
MouseMovement = {
sinf(DEG2RAD * yaw) * cosf(DEG2RAD * pitch),
sinf(DEG2RAD * pitch),
cosf(DEG2RAD * yaw) * cosf(DEG2RAD * pitch)
};
}
void Player_Main::PlayerMovement()
{
Forward = { MouseMovement.x, 0, MouseMovement.z };
Forward = Vector3Normalize(Forward);
Right = Vector3Normalize(Vector3CrossProduct(Forward, { 0, 1, 0 }));
Vector3 nextPos = Pos;
float moveSpeed = Speed * DT;
if (IsKeyDown(KEY_W)) {
nextPos = Vector3Add(nextPos, Vector3Scale(Forward, moveSpeed));
AnimIndex = 14;
}
else if (IsKeyDown(KEY_S)) {
nextPos = Vector3Subtract(nextPos, Vector3Scale(Forward, moveSpeed));
AnimIndex = 14;
}
else if (IsKeyDown(KEY_A)) {
nextPos = Vector3Subtract(nextPos, Vector3Scale(Right, moveSpeed));
AnimIndex = 15;
}
else if (IsKeyDown(KEY_D)) {
nextPos = Vector3Add(nextPos, Vector3Scale(Right, moveSpeed));
AnimIndex = 15;
}
else {
AnimIndex = 23;
}
BoundingBox nextHitbox = {
Vector3Add(nextPos, { -0.5f, -1.5f, -0.5f }),
Vector3Add(nextPos, { 0.5f, 1.5f, 0.5f })
};
bool canMove = true;
for (int i = 0; i < MW.HitBox.size(); i++) {
if (CheckCollisionBoxes(nextHitbox, MW.HitBox[i])) {
canMove = false;
break;
}
}
for (int i = 0; i < MB.HitBox.size(); i++) {
if (CheckCollisionBoxes(nextHitbox, MB.HitBox[i])) {
canMove = false;
break;
}
}
if (canMove) {
Pos = nextPos;
}
PlayerHitbox = {
Vector3Add(Pos, { -0.5f, -1.5f, -0.5f }),
Vector3Add(Pos, { 0.5f, 1.5f, 0.5f })
};
UpdateModelAnimation(model, Anim[AnimIndex], CurrentFrame);
DrawModelEx( model, Vector3Subtract(Pos, { 0, 1.5f, 0 }), { 0, 1, 0 }, yaw, { 1, 1, 1 }, WHITE);
}
void Player_Main::LoadAnimation() {
model = LoadModel("Assets/KayKit_Character_Animations_1.1/Mannequin Character/characters/Mannequin_medium_fix_3.glb");
Anim = LoadModelAnimations("Assets/KayKit_Character_Animations_1.1/Mannequin Character/characters/Mannequin_medium_fix_3.glb", &AnimCount);
Tex = LoadTexture("Assets/KayKit_Character_Animations_1.1/Mannequin Character/Textures/mannequin_texture.png");
// "Assets/KayKit_Character_Animations_1.1/Animations/gltf/Rig_Medium/Rig_Medium_MovementBasic.glb"
// "Assets/KayKit_Character_Animations_1.1/Mannequin Character/characters/Mannequin_medium_fix.glb"
//"Assets/characterbystyloov1.2/characterbystyloocharacter_root.glb"
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = Tex;
}
void Player_Main::PlayerAnimation() {
CurrentFrame++;
if (CurrentFrame >= Anim[AnimIndex].frameCount) CurrentFrame = 0;
}
Player_Main::~Player_Main() {
std::cout << "\n\033[1;93m Player Unloded \033[0m\n\n";
UnloadModel(model);
UnloadTexture(Tex);
UnloadModelAnimations(Anim , AnimCount);
}
// ---------- Player: Enemy ----------
Player_Enemy::Player_Enemy() {
Health = 100;
Speed = 10.0f;
Pos = { 1 ,1 ,1 };
cam = { 0 };
CurrentFrame = 0;
AnimIndex = 0;
AnimCount = 0;
//Anim = LoadModelAnimations("Assets/KayKit_Skeletons_1.1_FREE/KayKit_Skeletons_1.1_FREE/Animations/gltf/Rig_Medium/Rig_Medium_MovementBasic.glb", &AnimCount);
PlayerHitbox = { {0 , 0, 0} , {0, 0 ,0} };
}
void Player_Enemy::InitializeCamera() {
cam.fovy = 45.0f;
cam.projection = CAMERA_PERSPECTIVE;
cam.up = { 0, 1 , 0 };
cam.position = { 5 , 5 , 5 };
cam.target = { 1 , 1 , 1 };
}
void Player_Enemy::CameraPos() {
}
void Player_Enemy::PlayerMovement() {
//UpdateModelAnimation(Skeleton_Mage, Anim[AnimIndex], CurrentFrame);
//DrawModel(Skeleton_Mage, { 5 , 5 , 5 }, 1.0f, WHITE);
}
void Player_Enemy::LoadAnimation() {
//Anim = LoadModelAnimations("Assets/KayKit_Skeletons_1.1_FREE/KayKit_Skeletons_1.1_FREE/Animations/gltf/Rig_Medium/Rig_Medium_General.glb", &AnimCount);
}
void Player_Enemy::PlayerAnimation() {
CurrentFrame++;
if (CurrentFrame >= Anim[AnimIndex].frameCount) CurrentFrame = 0;
}