From d427542597be4a92d4416f4cea83e70e80701e1f Mon Sep 17 00:00:00 2001 From: valvin Date: Sat, 9 Mar 2024 14:29:09 +0100 Subject: [PATCH] feat: add more fishes --- carrot_game/carrot_game.ino | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/carrot_game/carrot_game.ino b/carrot_game/carrot_game.ino index 68d1c24..59cd6ef 100644 --- a/carrot_game/carrot_game.ino +++ b/carrot_game/carrot_game.ino @@ -36,9 +36,12 @@ unsigned long next_note = millis(); short notes_index = 0; short intro_size = sizeof(notes_intro)/sizeof(notes_intro[0]); -short fishes[8][2] = { - {0,1},{0,1},{0,16},{0,16}, - {0,32},{0,32},{0,48},{0,48} +const short NUM_FISHES = 12; +short fishes[NUM_FISHES][2] = { + {0,1},{0,1},{0,1}, + {0,16},{0,16},{0,16}, + {0,32},{0,32},{0,32}, + {0,48},{0,48},{0,48} }; bool game_init = true; bool jump = false; @@ -119,6 +122,7 @@ void display_game() { short y = 0; short x = 0; for(int i = 0; i < lives; i++){ + //display 3 hearts per line if (i % 3 == 0){ y = y +1; x = 0; @@ -128,7 +132,7 @@ void display_game() { } //draw fishes - for (int i = 0; i < 8; i++) { + for (int i = 0; i < NUM_FISHES; i++) { if(fishes[i][0] != NULL){ if(fishes[i][0] < MAX_X){ u8g2.drawXBMP(fishes[i][0], fishes[i][1], 16, 16, fish_reverse); @@ -149,19 +153,21 @@ void display_game() { } void init_game(){ + Serial.print("Number of fishes: "); + Serial.println(sizeof(fishes)); score = 0; max_score = 0; lives = 5; posX = INIT_X; posY = INIT_Y; - for ( short i = 0 ; i < 8; i++){ + for ( short i = 0 ; i < NUM_FISHES; i++){ fishes[i][0]= random(MAX_X + 1,255); } } void compute_fishes_position(){ - short fish_step = (200 + score)/100; - for (int i = 0; i < 8; i++) { + 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) @@ -228,7 +234,7 @@ void compute_cat_position() { posX = posX - 4; } } - if (nunchuk.analogX > 140 && posX < (MAX_X - 16)) { + if (nunchuk.analogX > 140 && posX < (MAX_X - 8)) { if (nunchuk.analogX > 180) { posX = posX + 8; } else {