blob: c8e3f7da6118e0e921fab0584f726e7c17da5640 (
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
|
#include "player.h"
#include "physics.h"
#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);
}
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);
}
|