blob: 6426db7450da50401a5f7ad54349b9aec3fc4898 (
plain)
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
|
#include <math.h>
#include "constants.h"
#include "game.h"
#include "player.h"
#include "physics.h"
extern Game game;
#define PLAYER_SPEED 300.0f
void UpdatePlayer(Entity* player, float deltaTime) {
player->velocity = (Vector2) {0.0f, 0.0f};
if (IsKeyDown(KEY_W)) {
player->velocity.y = -1.0f;
} else if (IsKeyDown(KEY_S)) {
player->velocity.y = 1.0f;
}
if (IsKeyDown(KEY_A)) {
player->velocity.x = -1.0f;
} else if (IsKeyDown(KEY_D)) {
player->velocity.x = 1.0f;
}
if (Vector2Length(player->velocity) > 0.0f) {
player->velocity = Vector2Normalize(player->velocity);
}
player->velocity = Vector2Scale(player->velocity, PLAYER_SPEED);
MoveAndSlide(player, deltaTime);
game.camera.target =
(Vector2) {fmax(WINDOW_WIDTH / 2.0f, player->position.x), 0.0f};
}
void AddPlayer(float xpos, float ypos) {
Entity player = {0};
player.type = Player_Entity;
player.position = (Vector2) {xpos, ypos};
player.flags |= (ENTITY_PHYSICS_ACTIVE);
player.physicsCollider = (Rectangle) {0, 0, 100, 100};
#ifdef BEATEMUP_DEBUG
player.physicsColliderColor = RED;
#endif
AddEntity(&player);
}
|