feat: add bomb fish

This commit is contained in:
valvin 2024-03-09 21:53:47 +01:00
parent b8d78b2620
commit 04d24f0f9e
1 changed files with 36 additions and 21 deletions

View File

@ -142,6 +142,9 @@ void display_game() {
else if(fishes[i][2] == FT_LIFE){ else if(fishes[i][2] == FT_LIFE){
u8g2.drawXBMP(fishes[i][0], fishes[i][1], 16, 16, fish_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(){ void compute_fishes_position(){
short fish_step = (200 + score)/200; short fish_step = (200 + score)/200;
for (int i = 0; i < NUM_FISHES; i++) { for (int i = 0; i < NUM_FISHES; i++) {
@ -179,19 +197,7 @@ void compute_fishes_position(){
if(fishes[i][0] <= fish_step) if(fishes[i][0] <= fish_step)
{ {
fishes[i][0] = random(MAX_X+1,255); fishes[i][0] = random(MAX_X+1,255);
score = score - 10; missed_or_bomb();
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;
}
} }
//move fish to the left //move fish to the left
else{ else{
@ -201,24 +207,33 @@ void compute_fishes_position(){
if( (posX > (fishes[i][0] - 8) && posX < (fishes[i][0] + 8) ) if( (posX > (fishes[i][0] - 8) && posX < (fishes[i][0] + 8) )
&& (posY > (fishes[i][1] - 8) && posY < (fishes[i][1] + 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){ if(fishes[i][2] == FT_LIFE){
lives = lives + 1; lives = lives + 1;
} }
fishes[i][0] = random(128,255); fishes[i][0] = random(MAX_X+1,255);
//random type //random type
short rdm_type = random(1,100); short rdm_type = random(1,100);
if(rdm_type < 90){ if(rdm_type < 80){
fishes[i][2] = FT_NORMAL; fishes[i][2] = FT_NORMAL;
} }
else{ else if (rdm_type >= 80 and rdm_type < 90){
fishes[i][2] = FT_LIFE; fishes[i][2] = FT_LIFE;
} }
else{
play_sound(NOTE_B5,100); fishes[i][2] = FT_BOMB;
score = score + 10;
if (score > max_score){
max_score = score;
} }
} }
} }
} }