From 04d24f0f9ec14447a74d75e252c4dd4d133561aa Mon Sep 17 00:00:00 2001 From: valvin Date: Sat, 9 Mar 2024 21:53:47 +0100 Subject: [PATCH] feat: add bomb fish --- carrot_game/carrot_game.ino | 57 +++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/carrot_game/carrot_game.ino b/carrot_game/carrot_game.ino index a55524d..303fad9 100644 --- a/carrot_game/carrot_game.ino +++ b/carrot_game/carrot_game.ino @@ -142,6 +142,9 @@ void display_game() { else if(fishes[i][2] == FT_LIFE){ u8g2.drawXBMP(fishes[i][0], fishes[i][1], 16, 16, fish_life); } + else if(fishes[i][2] == FT_BOMB){ + u8g2.drawXBMP(fishes[i][0], fishes[i][1], 16, 16, fish); + } } } } @@ -171,6 +174,21 @@ void init_game(){ } } +void missed_or_bomb(){ + score = score - 10; + lives = lives - 1; + + play_sound(NOTE_B1,300); + if (score <= 0 || lives == 0){ + play_sound(NOTE_G1,300); + play_sound(NOTE_F1,300); + play_sound(NOTE_E1,300); + play_sound(NOTE_D1,300); + play_sound(NOTE_C1,300); + game_init = true; + } +} + void compute_fishes_position(){ short fish_step = (200 + score)/200; for (int i = 0; i < NUM_FISHES; i++) { @@ -179,19 +197,7 @@ void compute_fishes_position(){ if(fishes[i][0] <= fish_step) { fishes[i][0] = random(MAX_X+1,255); - score = score - 10; - lives = lives - 1; - - play_sound(NOTE_B1,300); - //end game - if (score <= 0 || lives == 0){ - play_sound(NOTE_G1,300); - play_sound(NOTE_F1,300); - play_sound(NOTE_E1,300); - play_sound(NOTE_D1,300); - play_sound(NOTE_C1,300); - game_init = true; - } + missed_or_bomb(); } //move fish to the left else{ @@ -201,24 +207,33 @@ void compute_fishes_position(){ if( (posX > (fishes[i][0] - 8) && posX < (fishes[i][0] + 8) ) && (posY > (fishes[i][1] - 8) && posY < (fishes[i][1] + 8) ) ){ + if(fishes[i][2] == FT_BOMB){ + missed_or_bomb(); + } + else{ + play_sound(NOTE_B5,100); + score = score + 10; + if (score > max_score){ + max_score = score; + } + } + if(fishes[i][2] == FT_LIFE){ lives = lives + 1; } - fishes[i][0] = random(128,255); + fishes[i][0] = random(MAX_X+1,255); //random type short rdm_type = random(1,100); - if(rdm_type < 90){ + if(rdm_type < 80){ fishes[i][2] = FT_NORMAL; } - else{ + else if (rdm_type >= 80 and rdm_type < 90){ fishes[i][2] = FT_LIFE; } - - play_sound(NOTE_B5,100); - score = score + 10; - if (score > max_score){ - max_score = score; + else{ + fishes[i][2] = FT_BOMB; } + } } }