From b8d78b26203a0ec20979fc1db67e9f9cf5b0bf62 Mon Sep 17 00:00:00 2001 From: valvin Date: Sat, 9 Mar 2024 18:40:32 +0100 Subject: [PATCH] feat: add new life fish type --- carrot_game/bitmap.h | 5 +++++ carrot_game/carrot_game.ino | 30 ++++++++++++++++++++++++------ resources/poisson_vie.xbm | 6 ++++++ 3 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 resources/poisson_vie.xbm diff --git a/carrot_game/bitmap.h b/carrot_game/bitmap.h index a438a8e..bb075b2 100644 --- a/carrot_game/bitmap.h +++ b/carrot_game/bitmap.h @@ -12,6 +12,11 @@ PROGMEM const unsigned char fish_reverse[] { 0xec, 0x7f, 0xfe, 0x3f, 0xfc, 0x3f, 0xf8, 0x77, 0xf0, 0x67, 0xe0, 0x07, 0x00, 0x0e, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00 }; +PROGMEM const unsigned char fish_life[] { + 0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x07,0xf8,0x8f,0xfc,0xdf,0x7e,0x7d,0xb7, + 0x7a,0xdf,0xf7,0xbf,0x7b,0x7e,0x7d,0xfc,0xde,0xf8,0x8f,0xf0,0x07,0x00,0x00, + 0x00,0x00 }; + PROGMEM const unsigned char heart[]{ 0x1b,0x1b,0x1f,0x1f,0x0e }; \ No newline at end of file diff --git a/carrot_game/carrot_game.ino b/carrot_game/carrot_game.ino index 59cd6ef..a55524d 100644 --- a/carrot_game/carrot_game.ino +++ b/carrot_game/carrot_game.ino @@ -36,12 +36,13 @@ unsigned long next_note = millis(); short notes_index = 0; short intro_size = sizeof(notes_intro)/sizeof(notes_intro[0]); +enum FishType { FT_NORMAL, FT_LIFE, FT_BOMB}; 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} +short fishes[NUM_FISHES][3] = { + {0,1,FT_NORMAL},{0,1, FT_NORMAL},{0,1,FT_NORMAL}, + {0,16,FT_NORMAL},{0,16,FT_NORMAL},{0,16,FT_NORMAL}, + {0,32,FT_NORMAL},{0,32,FT_NORMAL},{0,32,FT_NORMAL}, + {0,48,FT_NORMAL},{0,48,FT_LIFE},{0,48,FT_NORMAL} }; bool game_init = true; bool jump = false; @@ -135,7 +136,12 @@ void display_game() { 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); + if(fishes[i][2] == FT_NORMAL){ + u8g2.drawXBMP(fishes[i][0], fishes[i][1], 16, 16, fish_reverse); + } + else if(fishes[i][2] == FT_LIFE){ + u8g2.drawXBMP(fishes[i][0], fishes[i][1], 16, 16, fish_life); + } } } } @@ -195,7 +201,19 @@ 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_LIFE){ + lives = lives + 1; + } fishes[i][0] = random(128,255); + //random type + short rdm_type = random(1,100); + if(rdm_type < 90){ + fishes[i][2] = FT_NORMAL; + } + else{ + fishes[i][2] = FT_LIFE; + } + play_sound(NOTE_B5,100); score = score + 10; if (score > max_score){ diff --git a/resources/poisson_vie.xbm b/resources/poisson_vie.xbm new file mode 100644 index 0000000..f9b84b6 --- /dev/null +++ b/resources/poisson_vie.xbm @@ -0,0 +1,6 @@ +#define _width 16 +#define _height 16 +static char _bits[] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x07,0xf8,0x8f,0xfc,0xdf,0x7e,0x7d,0xb7, + 0x7a,0xdf,0xf7,0xbf,0x7b,0x7e,0x7d,0xfc,0xde,0xf8,0x8f,0xf0,0x07,0x00,0x00, + 0x00,0x00 };