Compare commits

..

2 Commits

Author SHA1 Message Date
valvin b8d78b2620 feat: add new life fish type 2024-03-09 18:40:32 +01:00
valvin d427542597 feat: add more fishes 2024-03-09 14:29:09 +01:00
3 changed files with 44 additions and 9 deletions

View File

@ -12,6 +12,11 @@ PROGMEM const unsigned char fish_reverse[] {
0xec, 0x7f, 0xfe, 0x3f, 0xfc, 0x3f, 0xf8, 0x77, 0xf0, 0x67, 0xe0, 0x07, 0xec, 0x7f, 0xfe, 0x3f, 0xfc, 0x3f, 0xf8, 0x77, 0xf0, 0x67, 0xe0, 0x07,
0x00, 0x0e, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00 }; 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[]{ PROGMEM const unsigned char heart[]{
0x1b,0x1b,0x1f,0x1f,0x0e 0x1b,0x1b,0x1f,0x1f,0x0e
}; };

View File

@ -36,9 +36,13 @@ unsigned long next_note = millis();
short notes_index = 0; short notes_index = 0;
short intro_size = sizeof(notes_intro)/sizeof(notes_intro[0]); short intro_size = sizeof(notes_intro)/sizeof(notes_intro[0]);
short fishes[8][2] = { enum FishType { FT_NORMAL, FT_LIFE, FT_BOMB};
{0,1},{0,1},{0,16},{0,16}, const short NUM_FISHES = 12;
{0,32},{0,32},{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 game_init = true;
bool jump = false; bool jump = false;
@ -119,6 +123,7 @@ void display_game() {
short y = 0; short y = 0;
short x = 0; short x = 0;
for(int i = 0; i < lives; i++){ for(int i = 0; i < lives; i++){
//display 3 hearts per line
if (i % 3 == 0){ if (i % 3 == 0){
y = y +1; y = y +1;
x = 0; x = 0;
@ -128,11 +133,16 @@ void display_game() {
} }
//draw fishes //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] != NULL){
if(fishes[i][0] < MAX_X){ if(fishes[i][0] < MAX_X){
if(fishes[i][2] == FT_NORMAL){
u8g2.drawXBMP(fishes[i][0], fishes[i][1], 16, 16, fish_reverse); 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);
}
}
} }
} }
//draw carrot //draw carrot
@ -149,19 +159,21 @@ void display_game() {
} }
void init_game(){ void init_game(){
Serial.print("Number of fishes: ");
Serial.println(sizeof(fishes));
score = 0; score = 0;
max_score = 0; max_score = 0;
lives = 5; lives = 5;
posX = INIT_X; posX = INIT_X;
posY = INIT_Y; 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); fishes[i][0]= random(MAX_X + 1,255);
} }
} }
void compute_fishes_position(){ void compute_fishes_position(){
short fish_step = (200 + score)/100; short fish_step = (200 + score)/200;
for (int i = 0; i < 8; i++) { for (int i = 0; i < NUM_FISHES; i++) {
if(fishes[i][0] != NULL){ if(fishes[i][0] != NULL){
//fish alive //fish alive
if(fishes[i][0] <= fish_step) if(fishes[i][0] <= fish_step)
@ -189,7 +201,19 @@ 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){
lives = lives + 1;
}
fishes[i][0] = random(128,255); 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); play_sound(NOTE_B5,100);
score = score + 10; score = score + 10;
if (score > max_score){ if (score > max_score){
@ -228,7 +252,7 @@ void compute_cat_position() {
posX = posX - 4; posX = posX - 4;
} }
} }
if (nunchuk.analogX > 140 && posX < (MAX_X - 16)) { if (nunchuk.analogX > 140 && posX < (MAX_X - 8)) {
if (nunchuk.analogX > 180) { if (nunchuk.analogX > 180) {
posX = posX + 8; posX = posX + 8;
} else { } else {

View File

@ -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 };