summaryrefslogtreecommitdiff
path: root/src/player.c
diff options
context:
space:
mode:
authorBoredGuy <osome3717@gmail.com>2025-07-28 05:14:54 -0700
committerBoredGuy <osome3717@gmail.com>2025-07-28 05:14:54 -0700
commit9e1627c229d8d094c7b55751d82db9d3579a16e1 (patch)
treeb8623b5980e090b3faa91e55ed6f84cd1634b570 /src/player.c
parentdc3d98ab47fefc8388455dbbd4d330e81499d95a (diff)
Completed Basics
Diffstat (limited to 'src/player.c')
-rw-r--r--src/player.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/player.c b/src/player.c
new file mode 100644
index 0000000..d65b873
--- /dev/null
+++ b/src/player.c
@@ -0,0 +1,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;
+ player.type = Player_Entity;
+
+ player.position = (Vector2) {xpos, ypos};
+ player.flags |= (ENTITY_PHYSICS_ACTIVE | ENTITY_VISIBLE);
+
+ player.physicsCollider = (Rectangle) {0, 0, 100, 100};
+
+ #ifdef BEATEMUP_DEBUG
+ player.physicsColliderColor = RED;
+ #endif
+
+ AddEntity(&player);
+} \ No newline at end of file