-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.cpp
More file actions
34 lines (28 loc) · 1.12 KB
/
player.cpp
File metadata and controls
34 lines (28 loc) · 1.12 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
#include "player.h"
#include <algorithm>
#include <raymath.h>
Player::Player(const float width_limit, const float height_limit) : Fish(width_limit, height_limit) {
// Starts player at bottom of the ocean
position = {width_limit / 2.0f, height_limit - 50.0f};
}
void Player::Update(Camera2D &camera, const float deltaTime) {
GatherInstructions();
ApplyPhysics(deltaTime);
// Updates camera position
camera.target = { position.x, position.y };
if (position.x < 853.0f || position.x > width_limit - 853.0f) {
camera.target.x = std::clamp(camera.target.x, 852.0f, width_limit - 853.0f);
}
if (position.y < 478.0f || position.y > height_limit - 478.0f) {
camera.target.y = std::clamp(camera.target.y, 478.0f, height_limit - 478.0f);
}
}
// Takes in user input for acceleration
void Player::GatherInstructions() {
acceleration = { 0, 0 };
if (IsKeyDown(KEY_W)) acceleration.y -= 5;
if (IsKeyDown(KEY_S)) acceleration.y += 5;
if (IsKeyDown(KEY_A)) acceleration.x -= 5;
if (IsKeyDown(KEY_D)) acceleration.x += 5;
acceleration = Vector2Normalize(acceleration) * 5.0f;
}