summaryrefslogtreecommitdiff
path: root/src/player.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/player.c')
-rw-r--r--src/player.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/player.c b/src/player.c
index 6426db7..67f971f 100644
--- a/src/player.c
+++ b/src/player.c
@@ -1,13 +1,29 @@
+#include <stdlib.h>
#include <math.h>
#include "constants.h"
#include "game.h"
#include "player.h"
#include "physics.h"
+#include "assets.h"
extern Game game;
#define PLAYER_SPEED 300.0f
+const Rectangle shadowDestRect = (Rectangle) {
+ .x = 0,
+ .y = 100,
+ .width = 100,
+ .height = 40
+};
+
+const Rectangle physicsCollider = (Rectangle) {
+ .x = 0,
+ .y = 0,
+ .width = 100,
+ .height = 100
+};
+
void UpdatePlayer(Entity* player, float deltaTime) {
player->velocity = (Vector2) {0.0f, 0.0f};
@@ -31,7 +47,7 @@ void UpdatePlayer(Entity* player, float deltaTime) {
MoveAndSlide(player, deltaTime);
game.camera.target =
- (Vector2) {fmax(WINDOW_WIDTH / 2.0f, player->position.x), 0.0f};
+ (Vector2) {fmaxf(WINDOW_WIDTH / 2.0f, player->position.x), 0.0f};
}
void AddPlayer(float xpos, float ypos) {
@@ -39,13 +55,26 @@ void AddPlayer(float xpos, float ypos) {
player.type = Player_Entity;
player.position = (Vector2) {xpos, ypos};
- player.flags |= (ENTITY_PHYSICS_ACTIVE);
+ player.flags |= (ENTITY_PHYSICS_ACTIVE | ENTITY_VISIBLE);
- player.physicsCollider = (Rectangle) {0, 0, 100, 100};
+ player.physicsCollider = physicsCollider;
#ifdef BEATEMUP_DEBUG
player.physicsColliderColor = RED;
#endif
-
+
+ Asset* shadowTexture = GetMatchingAssetWithType("human-shadow", Texture_Asset);
+
+ if (shadowTexture == NULL) {
+ TraceLog(LOG_ERROR, "Failed to find texture asset human-shadow, exitting!");
+ exit(EXIT_FAILURE);
+ }
+
+ AddSpriteToEntity(&player, (Sprite){
+ .texture = shadowTexture->texture,
+ .layer = Foreground_Layer,
+ .destRect = shadowDestRect
+ });
+
AddEntity(&player);
}