This commit is contained in:
2026-07-05 21:03:55 +02:00
14 changed files with 507 additions and 914 deletions
+98 -48
View File
@@ -1,4 +1,5 @@
#include "app.h"
#include "engine.h"
typedef enum {
FLAPPING,
@@ -10,30 +11,27 @@ const SoundAsset playerSoundAssets[SOUND_COUNT] = {
};
const TextureAsset playerTextureAssets[PLAYER_TEX_COUNT] = {
{"assets/ship_start.png", 16.0f, 16.0f, 0.0f}
};
{"assets/ship_start.png", 16.0f, 16.0f, 0.0f}};
float playerSpeeds[SPEED_COUNT] = {
0.0f,
5.0f,
10.0f
};
float playerSpeeds[SPEED_COUNT] = {0.0f, 5.0f, 10.0f};
Config config;
playerSpeedID GetPlayerSpeedID(float speed) {
for (int i = 0; i < SPEED_COUNT; i++) {
if (playerSpeeds[i] == speed) {
return (playerSpeedID)i;
}
for (int i = 0; i < SPEED_COUNT; i++) {
if (playerSpeeds[i] == speed) {
return (playerSpeedID)i;
}
return ANCHOR;
}
return ANCHOR;
}
Player* GetPlayer(void)
{
static Player player;
return &player;
Player *GetPlayer(void) {
static Player player;
return &player;
}
<<<<<<< HEAD
void CreatePlayer(void)
{
TextureAsset startShipAsset = playerTextureAssets[START_SHIP];
@@ -51,16 +49,17 @@ void CreatePlayer(void)
.rotation = rotation,
.color = WHITE
};
=======
void CreatePlayer(void) {
Animation playerAnimation = {
.state = 1,
.currentFrame = 0,
.maxFrame = 3,
.framesCounter = 0,
.framesSpeed = 0.0f,
.animTimer = 0.0f
};
InitConfig(&config, "config/player.ini");
int PLAYER_HEALTH_MAX = GetConfigInt(&config, "HEALTH_MAX");
int START_GOLD = GetConfigInt(&config, "START_GOLD");
>>>>>>> origin/pirate
TextureAsset startShipAsset = playerTextureAssets[START_SHIP];
<<<<<<< HEAD
Physics playerPhysics = {
.position = (Vector2){(float)LoadStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_POSX), (float)LoadStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_POSY)},
.direction = (Vector2){0.0f, 0.0f},
@@ -95,35 +94,83 @@ void UpdatePlayer(void)
}
}
}
=======
Texture2D texture = LoadTexture(startShipAsset.path);
float frameWidth = startShipAsset.frameWidth;
float rotation = startShipAsset.rotation;
if(IsKeyPressed(KEY_S) || IsKeyPressed(KEY_DOWN)){
if(player->physics.speed > playerSpeeds[ANCHOR]){
if(player->physics.speed > playerSpeeds[SLOW_AHEAD]){
player->physics.speed = playerSpeeds[SLOW_AHEAD];
}
else {
player->physics.speed = playerSpeeds[ANCHOR];
Sprite playerSprite = {.texture = texture,
.frameSize = {frameWidth, frameWidth},
.sourceRec = {0.0f, 0.0f, frameWidth, frameWidth},
.destRec = {0.0f, 0.0f, frameWidth, frameWidth},
.origin = {frameWidth / 2, frameWidth / 2},
.rotation = rotation,
.color = WHITE};
}
}
}
Animation playerAnimation = {.state = 1,
.currentFrame = 0,
.maxFrame = 3,
.framesCounter = 0,
.framesSpeed = 0.0f,
.animTimer = 0.0f};
player->sprite.sourceRec.x = 16.0f * GetPlayerSpeedID(player->physics.speed);
Physics playerPhysics = {.position = (Vector2){0.0f, 0.0f},
.direction = (Vector2){0.0f, 0.0f},
.speed = playerSpeeds[ANCHOR],
.weight = 10.0f};
Player *player = GetPlayer();
*player = (Player){.sprite = playerSprite,
.animation = playerAnimation,
.physics = playerPhysics,
.rotation = rotation,
.health = PLAYER_HEALTH_MAX,
.gold = START_GOLD};
}
float rotationSpeed = 50.0f;
void UpdatePlayer(void) {
Player *player = GetPlayer();
if (IsKeyPressed(KEY_W) || IsKeyPressed(KEY_UP)) {
if (player->physics.speed < playerSpeeds[FAST_AHEAD]) {
if (player->physics.speed < playerSpeeds[SLOW_AHEAD]) {
player->physics.speed = playerSpeeds[SLOW_AHEAD];
} else {
player->physics.speed = playerSpeeds[FAST_AHEAD];
}
}
}
>>>>>>> origin/pirate
if (player->physics.speed > playerSpeeds[ANCHOR]){
if (IsKeyPressed(KEY_S) || IsKeyPressed(KEY_DOWN)) {
if (player->physics.speed > playerSpeeds[ANCHOR]) {
if (player->physics.speed > playerSpeeds[SLOW_AHEAD]) {
player->physics.speed = playerSpeeds[SLOW_AHEAD];
} else {
player->physics.speed = playerSpeeds[ANCHOR];
}
}
}
if (IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT)) {
player->rotation -= rotationSpeed * GetFrameTime();
}
player->sprite.sourceRec.x = 16.0f * GetPlayerSpeedID(player->physics.speed);
if (IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT)) {
player->rotation += rotationSpeed * GetFrameTime();
}
}
float rotationSpeed = 50.0f;
if (player->physics.speed > playerSpeeds[ANCHOR]) {
if (IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT)) {
player->rotation -= rotationSpeed * GetFrameTime();
}
if (IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT)) {
player->rotation += rotationSpeed * GetFrameTime();
}
}
player->sprite.rotation = player->rotation;
Vector2 dir = RotationToVector2(player->rotation - 90.0f);
<<<<<<< HEAD
player->sprite.rotation = player->rotation;
Vector2 dir = RotationToVector2(player->rotation - 90.0f);
UpdatePhysics(&player->physics, dir);
@@ -131,10 +178,13 @@ void UpdatePlayer(void)
SaveStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_POSX, (int)player->physics.position.x);
SaveStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_POSY, (int)player->physics.position.y);
SaveStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_ROTATION, (int)player->rotation);
=======
UpdatePhysics(&player->physics, dir);
UpdateSpriteDestRec(&player->sprite, &player->physics.position);
>>>>>>> origin/pirate
}
void RenderPlayer(void){
Player* player = GetPlayer();
RenderSprite(&player->sprite);
void RenderPlayer(void) {
Player *player = GetPlayer();
RenderSprite(&player->sprite);
}