From 851a13ce0db19eff7b43f28cb12769b270d1c4b7 Mon Sep 17 00:00:00 2001 From: Mark B Date: Fri, 15 Jul 2022 12:59:37 -0400 Subject: [PATCH] enemy hurt sprite and shorter feather wait times --- asset-src/gfx/enemy.piskel | 2 +- assets/gfx/enemy.png | Bin 228 -> 453 bytes src/Gameplay.c | 139 ++++++++++++++----------------------- src/Gameplay.h | 5 +- src/Main.c | 1 + src/Screens.h | 3 +- src/Timers.h | 1 + src/Title.c | 1 + 8 files changed, 63 insertions(+), 89 deletions(-) diff --git a/asset-src/gfx/enemy.piskel b/asset-src/gfx/enemy.piskel index fceb375..93d6d99 100644 --- a/asset-src/gfx/enemy.piskel +++ b/asset-src/gfx/enemy.piskel @@ -1 +1 @@ -{"modelVersion":2,"piskel":{"name":"cat","description":"","fps":12,"height":50,"width":50,"layers":["{\"name\":\"Layer 1\",\"opacity\":1,\"frameCount\":1,\"chunks\":[{\"layout\":[[0]],\"base64PNG\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAqUlEQVRoge3UMQ6AMAxD0e7c/7rAhlgoTXCDET+SJ4TSlxJaO9W6LFsv7aUKn+UOUo1Jn2MEUgF63D8CmYWR9O68dGQWSDrEEYgadNVr2qc1AxO9efVfa6hZtM/IkOTLnm2mGJAU4pA0JDqx5OFqlx0IECBAgAD5LcQtQNwihWT3RrFvZZDsMyBAgACpgWQDBIhZgLgFiFuAuAWIW4C4BYhbgLjlH5Av1w4h7f0lPcROigAAAABJRU5ErkJggg==\"}]}"],"hiddenFrames":[""]}} \ No newline at end of file +{"modelVersion":2,"piskel":{"name":"cat","description":"","fps":12,"height":50,"width":50,"layers":["{\"name\":\"Layer 1\",\"opacity\":1,\"frameCount\":2,\"chunks\":[{\"layout\":[[0],[1]],\"base64PNG\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAAAyCAYAAACqNX6+AAABiklEQVR4nO3VS44CMQwE0Oy5/3WHWc0ItSDxp5wU7orkDR0S288NY7ysn8fjOYtxaDHlsnWtQHY3giWPY8sCsqMhp++nWR6QqqYwDATNmhT/H1XNYRgGumUBGWCYT3cJZCz/ROEo3jexCsT7dm4bDuPlpqZ57xkGbFaQMhTH5aGmIaBRDUAglKNUJFkVrHWiLJaJDucEB4sp/8liHxZzsp5m3R0EhtIdZBcGDKUzyG4MCIpAyFC6gpzESKF0BJnd8eme657XfbNnq3sEYgBZNRu1J/SmdAOxTr8lUN93oXQC8dxlbSTq+xAQtkDUEoFAnXErkEwTPRjZ824Bkm2eFyV7HhQkOlWZaewGMkVBgkSfZUAiDVx9vuu8diDRc5hCIIQhELIQCFkIhCxgING4O8g193Yg34bzLn+BEID85f21r/07EG8diIHKDtm1jjYgkToEIhCBWEEyezz7BCIQgQhEIOdDIGSxC6T6LIEIRCACIchPIA3raFPI6dwE0rSONoWczg0GonV+/QItl3L0EqklsAAAAABJRU5ErkJggg==\"}]}"],"hiddenFrames":[""]}} \ No newline at end of file diff --git a/assets/gfx/enemy.png b/assets/gfx/enemy.png index e13889692c7f48b9694d6b57fcee7e31a27a0026..dbfc75417f9e513b96c8a6d8778879296d2b6d07 100644 GIT binary patch literal 453 zcmV;$0XqJPP)ScR**6j$K|1>A)rwWKp>Q(R3upytaYL+mWdAM1P6;L|H)z>7IU(mX5AeG zhSD8m7X}QaGstcX2#P?+P`ZMg#7LoZ1ex9O>7MJJ*L|~Rt9t}u09iE~wI}qZbOW(Y zza>!LccF9w@!Vx?BZJrk;dma=dI#roz>;^JL zL4rh|Wk4bgTz$UlymlbbbC^OPgdq^J5C~Zage+hn(YQOvHTQNP--h!pe}NEy{N??% zul+j^Zykt%$`0AJjy52XIs_sRfmlH@dp!FDA`pQHL?GuwAY`!%r1~s@2t*(PA;?c4 v4eMxA$m!e!(zK2?g`Ca}2BLL-{Q@nQa`Y0ZC9nVh002ovPDHLkV1fVuD1y0r literal 228 zcmeAS@N?(olHy`uVBq!ia0vp^Mj*_=1|;R|J2nETm7Xq+AsLNtuNd+*81Oh>e0S&n zt^;im8omY1g7%ZtTP{r(in6}COD9_Y?NYA!Px*p+J?AI01Tj|Kv1gjuI`PZ9JtZk( z9#%&LJETgkX5U(F$}GIM@@stdipVYJPfU1ndS31_i3uW)CYY#LZG7@DYq~6lfPzB< z!%y8Kx(;`gT2sEeZOl)d@WvPbpajC P;OXk;vd$@?iGcwC0-son diff --git a/src/Gameplay.c b/src/Gameplay.c index b6a2971..f8c692c 100644 --- a/src/Gameplay.c +++ b/src/Gameplay.c @@ -17,46 +17,65 @@ int score = 0, bestscore = 0; +void LoadGamplayScreen(void) +{ + fxhit = LoadSound("assets/sfx/hit.wav"); + player_sprite = LoadTexture("assets/gfx/player.png"); + enemy_sprite = LoadTexture("assets/gfx/enemy.png"); + fxfeather = LoadSound("assets/sfx/feather.wav"); + feather_sprite = LoadTexture("assets/gfx/feather.png"); + attack_sprite = LoadTexture("assets/gfx/attack.png"); + firework_sprite = LoadTexture("assets/gfx/firework.png"); + fxboom = LoadSound("assets/sfx/boom.wav"); +} + void InitGameplayScreen(void) { SetMasterVolume(0.5); - fxhit = LoadSound("assets/sfx/hit.wav"); - player_sprite = LoadTexture("assets/gfx/player.png"); player.currentframe = 0; player.speed = 300.0f; player.hp = PLAYER_HP; - player.frameRec = (Rectangle) { - player.hitbox.x, - player.hitbox.y, - (float) player_sprite.width/3, - (float) player_sprite.height - }; + if (GI_callcount < 1) { + player.frameRec = (Rectangle) { + player.hitbox.x, + player.hitbox.y, + (float) player_sprite.width/3, + (float) player_sprite.height + }; + } player.hitbox = (Rectangle) { 0, 100, (float) player_sprite.width/3, - (float) player_sprite.height/2 + 5 + (float) player_sprite.height/2 +5 }; player_iframeTimer = 0; player_in = false; player.color = RAYWHITE; player_flashtimer = 0; - enemy_sprite = LoadTexture("assets/gfx/enemy.png"); enemy.currentframe = 0; enemy.speed = 2.0f; enemy.hp = 30; + if (GI_callcount < 1) { + enemy.frameRec = (Rectangle) { + enemy.hitbox.x, + enemy.hitbox.y, + (float) enemy_sprite.width/2, + (float) enemy_sprite.height + }; + } enemy.hitbox = (Rectangle) { 690, 10, - (float) enemy_sprite.width, + (float) enemy_sprite.width/2, (float) enemy_sprite.height }; enemy.color = RAYWHITE; + enemy_hurt = false; + - fxfeather = LoadSound("assets/sfx/feather.wav"); - feather_sprite = LoadTexture("assets/gfx/feather.png"); feather.hitbox = (Rectangle) { GetRandomValue(0, GetScreenWidth() - feather_sprite.width), GetRandomValue(0, GetScreenHeight() - feather_sprite.height), @@ -67,7 +86,6 @@ void InitGameplayScreen(void) feather.power = 0; - firework_sprite = LoadTexture("assets/gfx/firework.png"); for (int i = 0; i < MAX_FIREWORKS; i++) { fireworks[i].speed.x = 300.0f; fireworks[i].active = 0; @@ -80,8 +98,6 @@ void InitGameplayScreen(void) fireworks[i].color = RAYWHITE; } - attack_sprite = LoadTexture("assets/gfx/attack.png"); - fxboom = LoadSound("assets/sfx/boom.wav"); for (int i = 0; i < MAX_SHOOTS; i++) { shoot[i].hitbox = (Rectangle) { player.hitbox.x, @@ -97,75 +113,11 @@ void InitGameplayScreen(void) ammo = 0; pause = 0; - mute = false; DebugMode = 0; pauseTimer = 0; -} + score = 0; -void ResetGameplayScreen(void) -{ - // code to reset all variables without reloading assets - player.currentframe = 0; - player.speed = 300.0f; - player.hp = PLAYER_HP; - player.hitbox = (Rectangle) { - 0, - 100, - (float) player_sprite.width/3, - (float) player_sprite.height/2 + 5 - }; - player_iframeTimer = 0; - player_in = false; - player.color = RAYWHITE; - player_flashtimer = 0; - - enemy.currentframe = 0; - enemy.speed = 2.0f; - enemy.hp = 30; - enemy.hitbox = (Rectangle) { - 690, - 10, - (float) enemy_sprite.width, - (float) enemy_sprite.height - }; - - feather.hitbox = (Rectangle) { - GetRandomValue(0, GetScreenWidth() - feather_sprite.width), - GetRandomValue(0, GetScreenHeight() - feather_sprite.height), - (float) feather_sprite.width, - (float) feather_sprite.height - }; - feather.active = true; - feather.power = 0; - - for (int i = 0; i < MAX_FIREWORKS; i++) { - fireworks[i].speed.x = 300.0f; - fireworks[i].active = 0; - fireworks[i].hitbox = (Rectangle) { - 630, - GetRandomValue(0, GetScreenHeight()), - (float) firework_sprite.width/2 + 10, - (float) firework_sprite.height - }; - } - - for (int i = 0; i < MAX_SHOOTS; i++) { - shoot[i].hitbox = (Rectangle) { - player.hitbox.x, - player.hitbox.y, - (float) attack_sprite.width, - (float) attack_sprite.height - }; - shoot[i].speed.x = 7; - shoot[i].speed.y = 0; - shoot[i].active = false; - shoot[i].color = RED; - } - ammo = 0; - - DebugMode = 0; - pauseTimer = 0; - score = 0; + GI_callcount++; } void DamagePlayer(void) @@ -190,6 +142,15 @@ void UpdateiFrameTimer(void) player_iframeTimer = 0; } } else player.color = RAYWHITE; + + if (enemy_hurt) { + enemy_frametimer++; + enemy.currentframe = 1; + if (enemy_frametimer >= 60) { + enemy_hurt = false; + enemy_frametimer = 0; + } + } else enemy.currentframe = 0; } void UpdateGameplayScreen(void) @@ -227,6 +188,8 @@ void UpdateGameplayScreen(void) feather.sprite_pos = (Vector2){ feather.hitbox.x, feather.hitbox.y }; enemy.sprite_pos = (Vector2){ enemy.hitbox.x, enemy.hitbox.y }; + enemy.frameRec.x = (float)enemy.currentframe*(float)enemy_sprite.width/2; + player_flashtimer++; @@ -239,7 +202,7 @@ void UpdateGameplayScreen(void) } - if (score % 1000 == 0) feather.active = true; + if (score % 500 == 0) feather.active = true; // Player to da wallz collies if ((player.hitbox.x + player.hitbox.width) >= GetScreenWidth()) player.hitbox.x = GetScreenWidth() - player.hitbox.width; @@ -254,6 +217,8 @@ void UpdateGameplayScreen(void) if (IsKeyPressed(KEY_NINE)) ammo = 99; if (IsKeyPressed(KEY_ZERO)) ammo = 0; + + if (IsKeyPressed(KEY_R)) { gameReset(); currentScreen = TITLE; @@ -271,6 +236,7 @@ void UpdateGameplayScreen(void) if (CheckCollisionRecs(shoot[i].hitbox, enemy.hitbox) && shoot[i].active) { // enemy.hp--; + enemy_hurt = true; score += 300; if (!mute) PlaySoundMulti(fxboom); shoot[i].active = false; @@ -361,7 +327,7 @@ void DrawGameplayScreen(void) DrawText(TextFormat("player_in: %d", player_in), 10, 320, 20, GREEN); } if (feather.active) DrawTexture(feather_sprite, feather.sprite_pos.x, feather.sprite_pos.y, feather.color); - DrawTexture(enemy_sprite, enemy.sprite_pos.x, enemy.sprite_pos.y, enemy.color); + DrawTextureRec(enemy_sprite, enemy.frameRec, enemy.sprite_pos, enemy.color); for (int i = 0; i < MAX_FIREWORKS; i++) { DrawTexture(firework_sprite, fireworks[i].sprite_pos.x, fireworks[i].sprite_pos.y, fireworks[i].color); } @@ -374,7 +340,8 @@ void DrawGameplayScreen(void) DrawTexture(feather_sprite, 70, 0, RED); DrawText(TextFormat("= %i", ammo), 100, 30, 20, RED); // DrawText(TextFormat("ENEMY HP: %i", enemy.hp), GetScreenWidth() - 150, 10, 20, RED); - DrawText(TextFormat("SCORE: %i", score), 10, 65, 20, BLUE); + if (score >= 10000) DrawText(TextFormat("SCORE: %i", score), 10, 65, 20, (Color){ 222, 181, 0, 255 }); + else DrawText(TextFormat("SCORE: %i", score), 10, 65, 20, BLUE); if (pause && ((pauseTimer/30)%2)) DrawText("PAUSED", 330, 190, 30, WHITE); } @@ -392,6 +359,6 @@ void UnloadGameplayScreen() void gameReset(void) { - ResetGameplayScreen(); + InitGameplayScreen(); InitGameoverScreen(); } diff --git a/src/Gameplay.h b/src/Gameplay.h index 8e66df0..8b5a542 100644 --- a/src/Gameplay.h +++ b/src/Gameplay.h @@ -48,9 +48,12 @@ Sound fxhit = { 0 }; Sound fxfeather = { 0 }; Sound fxboom = { 0 }; bool pause; -bool mute; +bool mute = false; bool player_in; +bool enemy_hurt; int ammo = 0; +int GI_callcount = 0; + bool DebugMode; diff --git a/src/Main.c b/src/Main.c index a43cb9f..2501900 100644 --- a/src/Main.c +++ b/src/Main.c @@ -64,6 +64,7 @@ void gameSetup(void) // asset loading & setting of variable values currentScreen = TITLE; + LoadGamplayScreen(); InitGameplayScreen(); InitTitleScreen(); } diff --git a/src/Screens.h b/src/Screens.h index 86fa370..46f7f57 100644 --- a/src/Screens.h +++ b/src/Screens.h @@ -25,7 +25,8 @@ void InitGameplayScreen(void); void UpdateGameplayScreen(void); void DrawGameplayScreen(void); void UnloadGameplayScreen(void); -void ResetGameplayScreen(void); +void LoadGamplayScreen(void); + void UpdateCreditsScreen(void); void DrawCreditsScreen(void); diff --git a/src/Timers.h b/src/Timers.h index 07e1684..7bf511c 100644 --- a/src/Timers.h +++ b/src/Timers.h @@ -12,5 +12,6 @@ int pauseTimer; int player_iframeTimer; int player_flashtimer; +int enemy_frametimer; #endif diff --git a/src/Title.c b/src/Title.c index 6d2a56b..599307d 100644 --- a/src/Title.c +++ b/src/Title.c @@ -57,6 +57,7 @@ void DrawTitleScreen(void) DrawText("Press 'ENTER' or 'START' to select an option", 10, 140, 10, WHITE); DrawText("Press 'X' or 'A' on a gamepad to shoot", 10, 160, 10, WHITE); DrawText("Avoid", 330, 20, 50, BLUE); +// DrawText("Ver: 0.1", 680, 420, 30, WHITE); if (titleSelected == 0) DrawText("PLAY", 360, 220, 20, WHITE); else DrawText("PLAY", 360, 220, 20, BLUE);