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,19 +174,11 @@ void init_game(){
} }
} }
void compute_fishes_position(){ void missed_or_bomb(){
short fish_step = (200 + score)/200;
for (int i = 0; i < NUM_FISHES; i++) {
if(fishes[i][0] != NULL){
//fish alive
if(fishes[i][0] <= fish_step)
{
fishes[i][0] = random(MAX_X+1,255);
score = score - 10; score = score - 10;
lives = lives - 1; lives = lives - 1;
play_sound(NOTE_B1,300); play_sound(NOTE_B1,300);
//end game
if (score <= 0 || lives == 0){ if (score <= 0 || lives == 0){
play_sound(NOTE_G1,300); play_sound(NOTE_G1,300);
play_sound(NOTE_F1,300); play_sound(NOTE_F1,300);
@ -192,6 +187,17 @@ void compute_fishes_position(){
play_sound(NOTE_C1,300); play_sound(NOTE_C1,300);
game_init = true; game_init = true;
} }
}
void compute_fishes_position(){
short fish_step = (200 + score)/200;
for (int i = 0; i < NUM_FISHES; i++) {
if(fishes[i][0] != NULL){
//fish alive
if(fishes[i][0] <= fish_step)
{
fishes[i][0] = random(MAX_X+1,255);
missed_or_bomb();
} }
//move fish to the left //move fish to the left
else{ else{
@ -201,25 +207,34 @@ 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_LIFE){ if(fishes[i][2] == FT_BOMB){
lives = lives + 1; missed_or_bomb();
}
fishes[i][0] = random(128,255);
//random type
short rdm_type = random(1,100);
if(rdm_type < 90){
fishes[i][2] = FT_NORMAL;
} }
else{ else{
fishes[i][2] = FT_LIFE;
}
play_sound(NOTE_B5,100); play_sound(NOTE_B5,100);
score = score + 10; score = score + 10;
if (score > max_score){ if (score > max_score){
max_score = score; max_score = score;
} }
} }
if(fishes[i][2] == FT_LIFE){
lives = lives + 1;
}
fishes[i][0] = random(MAX_X+1,255);
//random type
short rdm_type = random(1,100);
if(rdm_type < 80){
fishes[i][2] = FT_NORMAL;
}
else if (rdm_type >= 80 and rdm_type < 90){
fishes[i][2] = FT_LIFE;
}
else{
fishes[i][2] = FT_BOMB;
}
}
} }
} }
} }