From cf79bcbfbc9e7811e5ecd10706fc006f7f1eb2de Mon Sep 17 00:00:00 2001 From: huaqo Date: Sun, 5 Jul 2026 21:20:59 +0200 Subject: [PATCH] fix: merge conflict --- include/app.h | 5 +- include/engine.h | 9 +-- src/appGame.c | 29 ++----- src/appGameEnemies.c | 179 +++++++++++++++---------------------------- src/appGamePlayer.c | 120 ++++++++--------------------- 5 files changed, 103 insertions(+), 239 deletions(-) diff --git a/include/app.h b/include/app.h index 4bcfe2b..c91a89f 100644 --- a/include/app.h +++ b/include/app.h @@ -108,11 +108,8 @@ typedef struct { Animation animation; Physics physics; float rotation; -<<<<<<< HEAD Sound soundFlapping; -======= int health; ->>>>>>> origin/pirate int gold; } Player; @@ -249,7 +246,7 @@ void UpdatePlayer(void); void RenderPlayer(void); Enemies CreateEnemies(void); -void UpdateEnemies(Enemies *enemies, Projectiles *projectiles); +void UpdateEnemies(Enemies *enemies); void RenderEnemies(Enemies *enemies); Birds CreateBirds(void); diff --git a/include/engine.h b/include/engine.h index ba59057..61acc35 100644 --- a/include/engine.h +++ b/include/engine.h @@ -243,12 +243,7 @@ float Cross2D(Vector2 a, Vector2 b); Vector2 GetPositionInsideRectangle(Rectangle rec); Vector2 GetPositionOutsideRectangle(Rectangle rec, int min, int max); -<<<<<<< HEAD -bool SaveStorageValue(const char* fileName, unsigned int position, int value); -int LoadStorageValue(const char* fileName, unsigned int position); +bool SaveStorageValue(const char *fileName, unsigned int position, int value); +int LoadStorageValue(const char *fileName, unsigned int position); -#endif //ENGINE_H - -======= #endif // ENGINE_H ->>>>>>> origin/pirate diff --git a/src/appGame.c b/src/appGame.c index e454cc1..b3a6d82 100644 --- a/src/appGame.c +++ b/src/appGame.c @@ -2,9 +2,7 @@ const ShaderAsset shaderAssets[SHADER_COUNT] = {{"shaders/postfx.fs"}}; const SoundtrackAsset soundtrackAssets[SOUNDTRACK_COUNT] = { - {"assets/gameplay_theme.mp3"}, - {"assets/sea.wav"} -}; + {"assets/gameplay_theme.mp3"}, {"assets/sea.wav"}}; void InitGame(App *app) { @@ -61,23 +59,19 @@ void UpdateGame(App *app) { UpdateMouse(&g->mouse); - Player *player = GetPlayer(); UpdateCamera2D(&player->physics.position, &g->mouse); UpdateFloor(&g->floor); UpdatePlayer(); UpdateBirds(&g->birds); - UpdateEnemies(&g->enemies, &g->projectiles); + UpdateEnemies(&g->enemies); UpdateIslands(&g->islands); -<<<<<<< HEAD - UpdateProjectiles(&g->projectiles, &g->enemies); UpdateSoundtrack(&g->soundtracks[AMBIENT], app->flags.soundtrackOn); -======= - UpdateProjectiles(&g->projectiles); + UpdateProjectiles(&g->projectiles, &g->enemies); CheckPlayerCollisions(GetPlayer(), &app->game.enemies); CheckEnemyCollisions(&app->game.enemies); - CheckProjectileCollisions(&app->game.projectiles, &app->game.enemies, GetPlayer()); ->>>>>>> origin/pirate + CheckProjectileCollisions(&app->game.projectiles, &app->game.enemies, + GetPlayer()); } void RenderComponents(App *app) { @@ -99,20 +93,9 @@ void RenderGame(App *app) { BeginMode2D(*camera); RenderComponents(app); EndMode2D(); -<<<<<<< HEAD - DrawTextureRec( - g->mouse.cursorTexture, - (Rectangle){0, 0, g->mouse.cursorTexture.width, - g->mouse.cursorTexture.height}, - (Vector2){g->mouse.screenPosition.x, g->mouse.screenPosition.y}, WHITE); - - Player *player = GetPlayer(); - DrawText(TextFormat("Gold: %u", player->gold), 0.0f, 0.0f, 12.0f, YELLOW); -======= RenderOverlay(&g->mouse); ->>>>>>> origin/pirate EndTextureMode(); - + BeginDrawing(); ClearBackground(BLACK); for (int i = 0; i < SHADER_COUNT; i++) { diff --git a/src/appGameEnemies.c b/src/appGameEnemies.c index 5e44ea0..88f51d3 100644 --- a/src/appGameEnemies.c +++ b/src/appGameEnemies.c @@ -1,148 +1,93 @@ #include "app.h" const TextureAsset enemiesTextureAssets[ENEMIES_TEX_COUNT] = { - {"assets/ship_start.png", 16.0f, 16.0f, 90.0f} -}; + {"assets/ship_start.png", 16.0f, 16.0f, 90.0f}}; -Enemies CreateEnemies(void){ - Enemies enemies = {.count = MAX_ENEMIES}; - TextureAsset textureAsset = enemiesTextureAssets[BOAT]; - Texture2D texture = LoadTexture(textureAsset.path); - float frameWidth = textureAsset.frameWidth; - float rotation = textureAsset.rotation; +Enemies CreateEnemies(void) { + Enemies enemies = {.count = MAX_ENEMIES}; + TextureAsset textureAsset = enemiesTextureAssets[BOAT]; + Texture2D texture = LoadTexture(textureAsset.path); + float frameWidth = textureAsset.frameWidth; + float rotation = textureAsset.rotation; - for (int i = 0; i < enemies.count; i++) - { - enemies.sprite[i] = (Sprite){ - .texture = texture, - .frameSize = {frameWidth, frameWidth}, - .sourceRec = {0.0f, 0.0f, frameWidth, frameWidth}, - .destRec = {GetScreenWidth()/2, 0.0f, frameWidth, frameWidth}, - .origin = {frameWidth / 2, frameWidth / 2}, - .rotation = rotation, - .color = WHITE - }; + for (int i = 0; i < enemies.count; i++) { + enemies.sprite[i] = (Sprite){ + .texture = texture, + .frameSize = {frameWidth, frameWidth}, + .sourceRec = {0.0f, 0.0f, frameWidth, frameWidth}, + .destRec = {GetScreenWidth() / 2, 0.0f, frameWidth, frameWidth}, + .origin = {frameWidth / 2, frameWidth / 2}, + .rotation = rotation, + .color = WHITE}; - enemies.animation[i] = (Animation){ - .state = 1, - .currentFrame = 0, - .maxFrame = 2, - .framesCounter = 0, - .framesSpeed = 2.0f, - .animTimer = 0.0f - }; + enemies.animation[i] = (Animation){.state = 1, + .currentFrame = 0, + .maxFrame = 2, + .framesCounter = 0, + .framesSpeed = 2.0f, + .animTimer = 0.0f}; - Rectangle cameraRec = GetCameraRectangle(); + Rectangle cameraRec = GetCameraRectangle(); - enemies.physics[i] = (Physics){ - .position = GetPositionOutsideRectangle(cameraRec, 100, 1000), - .direction = (Vector2){0.0f, 0.0f}, - .speed = 5.0f, - .weight = 5.0f - }; + enemies.physics[i] = + (Physics){.position = GetPositionOutsideRectangle(cameraRec, 100, 1000), + .direction = (Vector2){0.0f, 0.0f}, + .speed = 5.0f, + .weight = 5.0f}; -<<<<<<< HEAD enemies.arrived[i] = true; enemies.destPos[i] = (Vector2){0.0f, 0.0f}; enemies.alive[i] = true; } -======= - enemies.arrived[i] = true; - enemies.destPos[i] = (Vector2){0.0f, 0.0f}; ->>>>>>> origin/pirate - } - - return enemies; + return enemies; } -<<<<<<< HEAD -void UpdateEnemies(Enemies *enemies, Projectiles *projectiles) { +void UpdateEnemies(Enemies *enemies) { Camera2D *camera = GetCamera(); Rectangle cameraRec = GetCameraRectangle(); for (int i = 0; i < enemies->count; i++) { - if (enemies->alive[i]) { - - for (int j = 0; j < projectiles->count; j++){ - if (!projectiles->active[j]) continue; - if (CheckCollisionCircleRec(projectiles->physics[j].position, projectiles->radius[j], enemies->sprite[i].destRec)){ - enemies->alive[i] = false; - break; - } - } + if (!enemies->alive[i]) + continue; - if (enemies->arrived[i]) { - enemies->destPos[i] = GetPositionOutsideRectangle(cameraRec, 100, 1000); - enemies->arrived[i] = false; - } - if (CheckCollisionPointCircle(enemies->physics[i].position, - enemies->destPos[i], 10.0F)) { - enemies->arrived[i] = true; - } - if (GetDistanceBetweenTwoVectors(enemies->physics[i].position, - camera->target) > 1000) { - enemies->physics[i].position = - GetPositionOutsideRectangle(cameraRec, 100, 1000); - } - Vector2 dir = GetDirectionBetweenTwoVectors(enemies->physics[i].position, - enemies->destPos[i]); - UpdatePhysics(&enemies->physics[i], dir); - UpdateSpriteDestRec(&enemies->sprite[i], &enemies->physics[i].position); - float rotation = Vector2ToRotation(dir); - UpdateSpriteRotation(&enemies->sprite[i], rotation + 90.0f); - UpdateAnimation(&enemies->animation[i], GetFrameTime()); - UpdateSpriteSourceRec(&enemies->sprite[i], - &(Vector2){enemies->sprite[i].frameSize.x * - enemies->animation[i].currentFrame, - enemies->sprite[i].frameSize.y}); + if (enemies->arrived[i]) { + enemies->destPos[i] = GetPositionOutsideRectangle(cameraRec, 100, 1000); + enemies->arrived[i] = false; } + + if (CheckCollisionPointCircle(enemies->physics[i].position, + enemies->destPos[i], 10.0F)) { + enemies->arrived[i] = true; + } + + if (GetDistanceBetweenTwoVectors(enemies->physics[i].position, + camera->target) > 1000) { + enemies->physics[i].position = + GetPositionOutsideRectangle(cameraRec, 100, 1000); + } + + Vector2 dir = GetDirectionBetweenTwoVectors(enemies->physics[i].position, + enemies->destPos[i]); + + UpdatePhysics(&enemies->physics[i], dir); + UpdateSpriteDestRec(&enemies->sprite[i], &enemies->physics[i].position); + + float rotation = Vector2ToRotation(dir); + UpdateSpriteRotation(&enemies->sprite[i], rotation + 90.0f); + + UpdateAnimation(&enemies->animation[i], GetFrameTime()); + UpdateSpriteSourceRec(&enemies->sprite[i], + &(Vector2){enemies->sprite[i].frameSize.x * + enemies->animation[i].currentFrame, + enemies->sprite[i].frameSize.y}); } } void RenderEnemies(Enemies *enemies) { for (int i = 0; i < enemies->count; i++) { - if (enemies->alive[i]){ + if (enemies->alive[i]) { RenderSprite(&enemies->sprite[i]); } } -======= -void UpdateEnemies(Enemies *enemies){ - Camera2D *camera = GetCamera(); - Rectangle cameraRec = GetCameraRectangle(); - - for (int i = 0; i < enemies->count; i++) - { - if(enemies->arrived[i]) - { - enemies->destPos[i] = GetPositionOutsideRectangle(cameraRec, 100, 1000); - enemies->arrived[i] = false; - } - if(CheckCollisionPointCircle(enemies->physics[i].position, enemies->destPos[i], 10.0F)) - { - enemies->arrived[i] = true; - } - if(GetDistanceBetweenTwoVectors(enemies->physics[i].position, camera->target) > 1000){ - enemies->physics[i].position = GetPositionOutsideRectangle(cameraRec, 100, 1000); - } - Vector2 dir = GetDirectionBetweenTwoVectors(enemies->physics[i].position, enemies->destPos[i]); - UpdatePhysics(&enemies->physics[i], dir); - UpdateSpriteDestRec(&enemies->sprite[i], &enemies->physics[i].position); - float rotation = Vector2ToRotation(dir); - UpdateSpriteRotation(&enemies->sprite[i], rotation + 90.0f); - UpdateAnimation(&enemies->animation[i], GetFrameTime()); - UpdateSpriteSourceRec(&enemies->sprite[i], &(Vector2){enemies->sprite[i].frameSize.x * enemies->animation[i].currentFrame, enemies->sprite[i].frameSize.y}); - } } - -void RenderEnemies(Enemies *enemies){ - - for (int i = 0; i < enemies->count; i++) - { - RenderSprite(&enemies->sprite[i]); - } - ->>>>>>> origin/pirate -} - - diff --git a/src/appGamePlayer.c b/src/appGamePlayer.c index 6141b79..f0878f4 100644 --- a/src/appGamePlayer.c +++ b/src/appGamePlayer.c @@ -1,14 +1,9 @@ #include "app.h" #include "engine.h" -typedef enum { - FLAPPING, - SOUND_COUNT -}SoundID; +typedef enum { FLAPPING, SOUND_COUNT } SoundID; -const SoundAsset playerSoundAssets[SOUND_COUNT] = { - {"assets/flapping.wav"} -}; +const SoundAsset playerSoundAssets[SOUND_COUNT] = {{"assets/flapping.wav"}}; const TextureAsset playerTextureAssets[PLAYER_TEX_COUNT] = { {"assets/ship_start.png", 16.0f, 16.0f, 0.0f}}; @@ -31,73 +26,18 @@ Player *GetPlayer(void) { return &player; } -<<<<<<< HEAD -void CreatePlayer(void) -{ - TextureAsset startShipAsset = playerTextureAssets[START_SHIP]; - - Texture2D texture = LoadTexture(startShipAsset.path); - float frameWidth = startShipAsset.frameWidth; - float rotation = (float)LoadStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_ROTATION); - - 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 - }; -======= void CreatePlayer(void) { - 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}, - .speed = playerSpeeds[ANCHOR] - }; - - Player* player = GetPlayer(); - *player = (Player){ - .sprite = playerSprite, - .animation = playerAnimation, - .physics = playerPhysics, - .rotation = rotation, - .soundFlapping = LoadSound(playerSoundAssets[FLAPPING].path), - .gold = LoadStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_GOLD) - }; -} - -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]){ - PlaySound(player->soundFlapping); - player->physics.speed = playerSpeeds[SLOW_AHEAD]; - } - else { - PlaySound(player->soundFlapping); - player->physics.speed = playerSpeeds[FAST_AHEAD]; - } - } - } -======= Texture2D texture = LoadTexture(startShipAsset.path); float frameWidth = startShipAsset.frameWidth; - float rotation = startShipAsset.rotation; + float rotation = + (float)LoadStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_ROTATION); Sprite playerSprite = {.texture = texture, .frameSize = {frameWidth, frameWidth}, @@ -114,18 +54,29 @@ void UpdatePlayer(void) .framesSpeed = 0.0f, .animTimer = 0.0f}; - Physics playerPhysics = {.position = (Vector2){0.0f, 0.0f}, - .direction = (Vector2){0.0f, 0.0f}, - .speed = playerSpeeds[ANCHOR], - .weight = 10.0f}; + Physics playerPhysics = { + .position = {(float)LoadStorageValue(STORAGE_DATA_FILE, + STORAGE_POSITION_POSX), + (float)LoadStorageValue(STORAGE_DATA_FILE, + STORAGE_POSITION_POSY)}, + .direction = {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}; + + *player = (Player){ + .sprite = playerSprite, + .animation = playerAnimation, + .physics = playerPhysics, + .rotation = rotation, + .soundFlapping = LoadSound(playerSoundAssets[FLAPPING].path), + .health = PLAYER_HEALTH_MAX, + .gold = LoadStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_GOLD)}; + + if (player->gold == 0) { + player->gold = START_GOLD; + } } void UpdatePlayer(void) { @@ -139,7 +90,6 @@ void UpdatePlayer(void) { } } } ->>>>>>> origin/pirate if (IsKeyPressed(KEY_S) || IsKeyPressed(KEY_DOWN)) { if (player->physics.speed > playerSpeeds[ANCHOR]) { @@ -167,21 +117,15 @@ void UpdatePlayer(void) { } 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); UpdateSpriteDestRec(&player->sprite, &player->physics.position); - 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 + 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); } void RenderPlayer(void) {