From 68fe5af0106bee0de10a4c6f09521d3b0db81e9d Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Sat, 7 Jan 2023 00:22:00 -0500 Subject: [PATCH 01/75] clang autoformat (no code change) --- app.c | 397 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 190 insertions(+), 207 deletions(-) diff --git a/app.c b/app.c index 39639f0..372aa0d 100644 --- a/app.c +++ b/app.c @@ -23,42 +23,42 @@ /* ============================ Data structures ============================= */ typedef struct Ship { - float x, /* Ship x position. */ - y, /* Ship y position. */ - vx, /* x velocity. */ - vy, /* y velocity. */ - rot; /* Current rotation. 2*PI full ortation. */ + float x, /* Ship x position. */ + y, /* Ship y position. */ + vx, /* x velocity. */ + vy, /* y velocity. */ + rot; /* Current rotation. 2*PI full ortation. */ } Ship; typedef struct Bullet { - float x, y, vx, vy; /* Fields like in ship. */ - uint32_t ttl; /* Time to live, in ticks. */ + float x, y, vx, vy; /* Fields like in ship. */ + uint32_t ttl; /* Time to live, in ticks. */ } Bullet; typedef struct Asteroid { - float x, y, vx, vy, rot, /* Fields like ship. */ - rot_speed, /* Angular velocity (rot speed and sense). */ - size; /* Asteroid size. */ - uint8_t shape_seed; /* Seed to give random shape. */ + float x, y, vx, vy, rot, /* Fields like ship. */ + rot_speed, /* Angular velocity (rot speed and sense). */ + size; /* Asteroid size. */ + uint8_t shape_seed; /* Seed to give random shape. */ } Asteroid; -#define MAXBUL 10 /* Max bullets on the screen. */ -#define MAXAST 32 /* Max asteroids on the screen. */ +#define MAXBUL 10 /* Max bullets on the screen. */ +#define MAXAST 32 /* Max asteroids on the screen. */ #define SHIP_HIT_ANIMATION_LEN 15 typedef struct AsteroidsApp { /* GUI */ - Gui *gui; - ViewPort *view_port; /* We just use a raw viewport and we render + Gui* gui; + ViewPort* view_port; /* We just use a raw viewport and we render everything into the low level canvas. */ - FuriMessageQueue *event_queue; /* Keypress events go here. */ + FuriMessageQueue* event_queue; /* Keypress events go here. */ /* Game state. */ - int running; /* Once false exists the app. */ - bool gameover; /* Gameover status. */ - uint32_t ticks; /* Game ticks. Increments at each refresh. */ - uint32_t score; /* Game score. */ - uint32_t lives; /* Number of lives in the current game. */ - uint32_t ship_hit; /* When non zero, the ship was hit by an asteroid + int running; /* Once false exists the app. */ + bool gameover; /* Gameover status. */ + uint32_t ticks; /* Game ticks. Increments at each refresh. */ + uint32_t score; /* Game score. */ + uint32_t lives; /* Number of lives in the current game. */ + uint32_t ship_hit; /* When non zero, the ship was hit by an asteroid and we need to show an animation as long as its value is non-zero (and decrease it's value at each tick of animation). */ @@ -67,26 +67,26 @@ typedef struct AsteroidsApp { struct Ship ship; /* Bullets state. */ - struct Bullet bullets[MAXBUL]; /* Each bullet state. */ - int bullets_num; /* Active bullets. */ - uint32_t last_bullet_tick; /* Tick the last bullet was fired. */ + struct Bullet bullets[MAXBUL]; /* Each bullet state. */ + int bullets_num; /* Active bullets. */ + uint32_t last_bullet_tick; /* Tick the last bullet was fired. */ /* Asteroids state. */ - Asteroid asteroids[MAXAST]; /* Each asteroid state. */ - int asteroids_num; /* Active asteroids. */ + Asteroid asteroids[MAXAST]; /* Each asteroid state. */ + int asteroids_num; /* Active asteroids. */ uint32_t pressed[InputKeyMAX]; /* pressed[id] is true if pressed. Each array item contains the time in milliseconds the key was pressed. */ - bool fire; /* Short press detected: fire a bullet. */ + bool fire; /* Short press detected: fire a bullet. */ } AsteroidsApp; /* ============================== Prototyeps ================================ */ // Only functions called before their definition are here. -void restart_game_after_gameover(AsteroidsApp *app); -uint32_t key_pressed_time(AsteroidsApp *app, InputKey key); +void restart_game_after_gameover(AsteroidsApp* app); +uint32_t key_pressed_time(AsteroidsApp* app, InputKey key); /* ============================ 2D drawing ================================== */ @@ -101,23 +101,19 @@ typedef struct Poly { } Poly; /* Define the polygons we use. */ -Poly ShipPoly = { - {-3, 0, 3}, - {-3, 6, -3}, - 3 -}; +Poly ShipPoly = {{-3, 0, 3}, {-3, 6, -3}, 3}; /* Rotate the point of the poligon 'poly' and store the new rotated * polygon in 'rot'. The polygon is rotated by an angle 'a', with * center at 0,0. */ -void rotate_poly(Poly *rot, Poly *poly, float a) { +void rotate_poly(Poly* rot, Poly* poly, float a) { /* We want to compute sin(a) and cos(a) only one time * for every point to rotate. It's a slow operation. */ float sin_a = (float)sin(a); float cos_a = (float)cos(a); - for (uint32_t j = 0; j < poly->points; j++) { - rot->x[j] = poly->x[j]*cos_a - poly->y[j]*sin_a; - rot->y[j] = poly->y[j]*cos_a + poly->x[j]*sin_a; + for(uint32_t j = 0; j < poly->points; j++) { + rot->x[j] = poly->x[j] * cos_a - poly->y[j] * sin_a; + rot->y[j] = poly->y[j] * cos_a + poly->x[j] * sin_a; } rot->points = poly->points; } @@ -125,36 +121,34 @@ void rotate_poly(Poly *rot, Poly *poly, float a) { /* This is an 8 bit LFSR we use to generate a predictable and fast * pseudorandom sequence of numbers, to give a different shape to * each asteroid. */ -void lfsr_next(unsigned char *prev) { +void lfsr_next(unsigned char* prev) { unsigned char lsb = *prev & 1; *prev = *prev >> 1; - if (lsb == 1) *prev ^= 0b11000111; - *prev ^= *prev<<7; /* Mix things a bit more. */ + if(lsb == 1) *prev ^= 0b11000111; + *prev ^= *prev << 7; /* Mix things a bit more. */ } /* Render the polygon 'poly' at x,y, rotated by the specified angle. */ -void draw_poly(Canvas *const canvas, Poly *poly, uint8_t x, uint8_t y, float a) -{ +void draw_poly(Canvas* const canvas, Poly* poly, uint8_t x, uint8_t y, float a) { Poly rot; - rotate_poly(&rot,poly,a); + rotate_poly(&rot, poly, a); canvas_set_color(canvas, ColorBlack); - for (uint32_t j = 0; j < rot.points; j++) { + for(uint32_t j = 0; j < rot.points; j++) { uint32_t a = j; - uint32_t b = j+1; - if (b == rot.points) b = 0; - canvas_draw_line(canvas,x+rot.x[a],y+rot.y[a], - x+rot.x[b],y+rot.y[b]); + uint32_t b = j + 1; + if(b == rot.points) b = 0; + canvas_draw_line(canvas, x + rot.x[a], y + rot.y[a], x + rot.x[b], y + rot.y[b]); } } /* A bullet is just a + pixels pattern. A single pixel is not * visible enough. */ -void draw_bullet(Canvas *const canvas, Bullet *b) { - canvas_draw_dot(canvas,b->x-1,b->y); - canvas_draw_dot(canvas,b->x+1,b->y); - canvas_draw_dot(canvas,b->x,b->y); - canvas_draw_dot(canvas,b->x,b->y-1); - canvas_draw_dot(canvas,b->x,b->y+1); +void draw_bullet(Canvas* const canvas, Bullet* b) { + canvas_draw_dot(canvas, b->x - 1, b->y); + canvas_draw_dot(canvas, b->x + 1, b->y); + canvas_draw_dot(canvas, b->x, b->y); + canvas_draw_dot(canvas, b->x, b->y - 1); + canvas_draw_dot(canvas, b->x, b->y + 1); } /* Draw an asteroid. The asteroid shapes is computed on the fly and @@ -162,15 +156,15 @@ void draw_bullet(Canvas *const canvas, Bullet *b) { * the shape, we use an initial fixed shape that we resize according * to the asteroid size, perturbate according to the asteroid shape * seed, and finally draw it rotated of the right amount. */ -void draw_asteroid(Canvas *const canvas, Asteroid *ast) { +void draw_asteroid(Canvas* const canvas, Asteroid* ast) { Poly ap; /* Start with what is kinda of a circle. Note that this could be * stored into a template and copied here, to avoid computing * sin() / cos(). But the Flipper can handle it without problems. */ uint8_t r = ast->shape_seed; - for (int j = 0; j < 8; j++) { - float a = (PI*2)/8*j; + for(int j = 0; j < 8; j++) { + float a = (PI * 2) / 8 * j; /* Before generating the point, to make the shape unique generate * a random factor between .7 and 1.3 to scale the distance from @@ -178,73 +172,71 @@ void draw_asteroid(Canvas *const canvas, Asteroid *ast) { * that remains always the same, so we use a predictable PRNG * implemented by an 8 bit shift register. */ lfsr_next(&r); - float scaling = .7+((float)r/255*.6); + float scaling = .7 + ((float)r / 255 * .6); ap.x[j] = (float)sin(a) * ast->size * scaling; ap.y[j] = (float)cos(a) * ast->size * scaling; } ap.points = 8; - draw_poly(canvas,&ap,ast->x,ast->y,ast->rot); + draw_poly(canvas, &ap, ast->x, ast->y, ast->rot); } /* Draw small ships in the top-right part of the screen, one for * each left live. */ -void draw_left_lives(Canvas *const canvas, AsteroidsApp *app) { +void draw_left_lives(Canvas* const canvas, AsteroidsApp* app) { int lives = app->lives; - int x = SCREEN_XRES-5; + int x = SCREEN_XRES - 5; - Poly mini_ship = { - {-2, 0, 2}, - {-2, 4, -2}, - 3 - }; + Poly mini_ship = {{-2, 0, 2}, {-2, 4, -2}, 3}; while(lives--) { - draw_poly(canvas,&mini_ship,x,6,PI); + draw_poly(canvas, &mini_ship, x, 6, PI); x -= 6; } } /* Given the current position, update it according to the velocity and * wrap it back to the other side if the object went over the screen. */ -void update_pos_by_velocity(float *x, float *y, float vx, float vy) { +void update_pos_by_velocity(float* x, float* y, float vx, float vy) { /* Return back from one side to the other of the screen. */ *x += vx; *y += vy; - if (*x >= SCREEN_XRES) *x = 0; - else if (*x < 0) *x = SCREEN_XRES-1; - if (*y >= SCREEN_YRES) *y = 0; - else if (*y < 0) *y = SCREEN_YRES-1; + if(*x >= SCREEN_XRES) + *x = 0; + else if(*x < 0) + *x = SCREEN_XRES - 1; + if(*y >= SCREEN_YRES) + *y = 0; + else if(*y < 0) + *y = SCREEN_YRES - 1; } /* Render the current game screen. */ -void render_callback(Canvas *const canvas, void *ctx) { - AsteroidsApp *app = ctx; +void render_callback(Canvas* const canvas, void* ctx) { + AsteroidsApp* app = ctx; /* Clear screen. */ canvas_set_color(canvas, ColorWhite); - canvas_draw_box(canvas, 0, 0, SCREEN_XRES-1, SCREEN_YRES-1); + canvas_draw_box(canvas, 0, 0, SCREEN_XRES - 1, SCREEN_YRES - 1); /* Draw score. */ canvas_set_color(canvas, ColorBlack); canvas_set_font(canvas, FontSecondary); char score[32]; - snprintf(score,sizeof(score),"%lu",app->score); + snprintf(score, sizeof(score), "%lu", app->score); canvas_draw_str(canvas, 0, 8, score); /* Draw left ships. */ - draw_left_lives(canvas,app); + draw_left_lives(canvas, app); /* Draw ship, asteroids, bullets. */ - draw_poly(canvas,&ShipPoly,app->ship.x,app->ship.y,app->ship.rot); + draw_poly(canvas, &ShipPoly, app->ship.x, app->ship.y, app->ship.rot); - for (int j = 0; j < app->bullets_num; j++) - draw_bullet(canvas,&app->bullets[j]); + for(int j = 0; j < app->bullets_num; j++) draw_bullet(canvas, &app->bullets[j]); - for (int j = 0; j < app->asteroids_num; j++) - draw_asteroid(canvas,&app->asteroids[j]); + for(int j = 0; j < app->asteroids_num; j++) draw_asteroid(canvas, &app->asteroids[j]); /* Game over text. */ - if (app->gameover) { + if(app->gameover) { canvas_set_color(canvas, ColorBlack); canvas_set_font(canvas, FontPrimary); canvas_draw_str(canvas, 28, 35, "GAME OVER"); @@ -256,9 +248,9 @@ void render_callback(Canvas *const canvas, void *ctx) { /* ============================ Game logic ================================== */ float distance(float x1, float y1, float x2, float y2) { - float dx = x1-x2; - float dy = y1-y2; - return sqrt(dx*dx+dy*dy); + float dx = x1 - x2; + float dy = y1 - y2; + return sqrt(dx * dx + dy * dy); } /* Detect a collision between the object at x1,y1 of radius r1 and @@ -272,10 +264,7 @@ float distance(float x1, float y1, float x2, float y2) { * spheres (this is why this function only takes the radius). This * is, after all, kinda accurate for asteroids, for bullets, and * even for the ship "core" itself. */ -bool objects_are_colliding(float x1, float y1, float r1, - float x2, float y2, float r2, - float factor) -{ +bool objects_are_colliding(float x1, float y1, float r1, float x2, float y2, float r2, float factor) { /* The objects are colliding if the distance between object 1 and 2 * is smaller than the sum of the two radiuses r1 and r2. * So it would be like: sqrt((x1-x2)^2+(y1-y2)^2) < r1+r2. @@ -284,24 +273,24 @@ bool objects_are_colliding(float x1, float y1, float r1, * the comparison like this: * * (x1-x2)^2+(y1-y2)^2 < (r1+r2)^2. */ - float dx = (x1-x2)*factor; - float dy = (y1-y2)*factor; - float rsum = r1+r2; - return dx*dx+dy*dy < rsum*rsum; + float dx = (x1 - x2) * factor; + float dy = (y1 - y2) * factor; + float rsum = r1 + r2; + return dx * dx + dy * dy < rsum * rsum; } /* Create a new bullet headed in the same direction of the ship. */ -void ship_fire_bullet(AsteroidsApp *app) { - if (app->bullets_num == MAXBUL) return; - Bullet *b = &app->bullets[app->bullets_num]; +void ship_fire_bullet(AsteroidsApp* app) { + if(app->bullets_num == MAXBUL) return; + Bullet* b = &app->bullets[app->bullets_num]; b->x = app->ship.x; b->y = app->ship.y; b->vx = -sin(app->ship.rot); b->vy = cos(app->ship.rot); /* Ship should fire from its head, not in the middle. */ - b->x += b->vx*5; - b->y += b->vy*5; + b->x += b->vx * 5; + b->y += b->vy * 5; /* Give the bullet some velocity (for now the vector is just * normalized to 1). */ @@ -319,68 +308,68 @@ void ship_fire_bullet(AsteroidsApp *app) { } /* Remove the specified bullet by id (index in the array). */ -void remove_bullet(AsteroidsApp *app, int bid) { +void remove_bullet(AsteroidsApp* app, int bid) { /* Replace the top bullet with the empty space left * by the removal of this bullet. This way we always take the * array dense, which is an advantage when looping. */ int n = --app->bullets_num; - if (n && bid != n) app->bullets[bid] = app->bullets[n]; + if(n && bid != n) app->bullets[bid] = app->bullets[n]; } /* Create a new asteroid, away from the ship. Return the * pointer to the asteroid object, so that the caller can change * certain things of the asteroid if needed. */ -Asteroid *add_asteroid(AsteroidsApp *app) { - if (app->asteroids_num == MAXAST) return NULL; - float size = 4+rand()%15; +Asteroid* add_asteroid(AsteroidsApp* app) { + if(app->asteroids_num == MAXAST) return NULL; + float size = 4 + rand() % 15; float min_distance = 20; - float x,y; + float x, y; do { x = rand() % SCREEN_XRES; y = rand() % SCREEN_YRES; - } while(distance(app->ship.x,app->ship.y,x,y) < min_distance+size); - Asteroid *a = &app->asteroids[app->asteroids_num++]; + } while(distance(app->ship.x, app->ship.y, x, y) < min_distance + size); + Asteroid* a = &app->asteroids[app->asteroids_num++]; a->x = x; a->y = y; - a->vx = 2*(-.5 + ((float)rand()/RAND_MAX)); - a->vy = 2*(-.5 + ((float)rand()/RAND_MAX)); + a->vx = 2 * (-.5 + ((float)rand() / RAND_MAX)); + a->vy = 2 * (-.5 + ((float)rand() / RAND_MAX)); a->size = size; a->rot = 0; - a->rot_speed = ((float)rand()/RAND_MAX)/10; - if (app->ticks & 1) a->rot_speed = -(a->rot_speed); + a->rot_speed = ((float)rand() / RAND_MAX) / 10; + if(app->ticks & 1) a->rot_speed = -(a->rot_speed); a->shape_seed = rand() & 255; return a; } /* Remove the specified asteroid by id (index in the array). */ -void remove_asteroid(AsteroidsApp *app, int id) { +void remove_asteroid(AsteroidsApp* app, int id) { /* Replace the top asteroid with the empty space left * by the removal of this one. This way we always take the * array dense, which is an advantage when looping. */ int n = --app->asteroids_num; - if (n && id != n) app->asteroids[id] = app->asteroids[n]; + if(n && id != n) app->asteroids[id] = app->asteroids[n]; } /* Called when an asteroid was reached by a bullet. The asteroid * hit is the one with the specified 'id'. */ -void asteroid_was_hit(AsteroidsApp *app, int id) { +void asteroid_was_hit(AsteroidsApp* app, int id) { float sizelimit = 6; // Smaller than that polverize in one shot. - Asteroid *a = &app->asteroids[id]; + Asteroid* a = &app->asteroids[id]; /* Asteroid is large enough to break into fragments. */ float size = a->size; float x = a->x, y = a->y; - remove_asteroid(app,id); - if (size > sizelimit) { + remove_asteroid(app, id); + if(size > sizelimit) { int max_fragments = size / sizelimit; - int fragments = 2+rand()%max_fragments; - float newsize = size/fragments; - if (newsize < 2) newsize = 2; - for (int j = 0; j < fragments; j++) { + int fragments = 2 + rand() % max_fragments; + float newsize = size / fragments; + if(newsize < 2) newsize = 2; + for(int j = 0; j < fragments; j++) { a = add_asteroid(app); - if (a == NULL) break; // Too many asteroids on screen. - a->x = x + -(size/2) + rand() % (int)newsize; - a->y = y + -(size/2) + rand() % (int)newsize; + if(a == NULL) break; // Too many asteroids on screen. + a->x = x + -(size / 2) + rand() % (int)newsize; + a->y = y + -(size / 2) + rand() % (int)newsize; a->size = newsize; } } else { @@ -390,18 +379,19 @@ void asteroid_was_hit(AsteroidsApp *app, int id) { /* Set gameover state. When in game-over mode, the game displays a gameover * text with a background of many asteroids floating around. */ -void game_over(AsteroidsApp *app) { +void game_over(AsteroidsApp* app) { restart_game_after_gameover(app); app->gameover = true; int asteroids = 8; - while(asteroids-- && add_asteroid(app) != NULL); + while(asteroids-- && add_asteroid(app) != NULL) + ; } /* Function called when a collision between the asteroid and the * ship is detected. */ -void ship_was_hit(AsteroidsApp *app) { +void ship_was_hit(AsteroidsApp* app) { app->ship_hit = SHIP_HIT_ANIMATION_LEN; - if (app->lives) { + if(app->lives) { app->lives--; } else { game_over(app); @@ -410,10 +400,10 @@ void ship_was_hit(AsteroidsApp *app) { /* Restart game after the ship is hit. Will reset the ship position, bullets * and asteroids to restart the game. */ -void restart_game(AsteroidsApp *app) { +void restart_game(AsteroidsApp* app) { app->ship.x = SCREEN_XRES / 2; app->ship.y = SCREEN_YRES / 2; - app->ship.rot = PI; /* Start headed towards top. */ + app->ship.rot = PI; /* Start headed towards top. */ app->ship.vx = 0; app->ship.vy = 0; app->bullets_num = 0; @@ -423,7 +413,7 @@ void restart_game(AsteroidsApp *app) { /* Called after gameover to restart the game. This function * also calls restart_game(). */ -void restart_game_after_gameover(AsteroidsApp *app) { +void restart_game_after_gameover(AsteroidsApp* app) { app->gameover = false; app->ticks = 0; app->score = 0; @@ -433,12 +423,12 @@ void restart_game_after_gameover(AsteroidsApp *app) { } /* Move bullets. */ -void update_bullets_position(AsteroidsApp *app) { - for (int j = 0; j < app->bullets_num; j++) { - update_pos_by_velocity(&app->bullets[j].x,&app->bullets[j].y, - app->bullets[j].vx,app->bullets[j].vy); - if (--app->bullets[j].ttl == 0) { - remove_bullet(app,j); +void update_bullets_position(AsteroidsApp* app) { + for(int j = 0; j < app->bullets_num; j++) { + update_pos_by_velocity( + &app->bullets[j].x, &app->bullets[j].y, app->bullets[j].vx, app->bullets[j].vy); + if(--app->bullets[j].ttl == 0) { + remove_bullet(app, j); j--; /* Process this bullet index again: the removal will fill it with the top bullet to take the array dense. */ } @@ -446,28 +436,28 @@ void update_bullets_position(AsteroidsApp *app) { } /* Move asteroids. */ -void update_asteroids_position(AsteroidsApp *app) { - for (int j = 0; j < app->asteroids_num; j++) { - update_pos_by_velocity(&app->asteroids[j].x,&app->asteroids[j].y, - app->asteroids[j].vx,app->asteroids[j].vy); +void update_asteroids_position(AsteroidsApp* app) { + for(int j = 0; j < app->asteroids_num; j++) { + update_pos_by_velocity( + &app->asteroids[j].x, &app->asteroids[j].y, app->asteroids[j].vx, app->asteroids[j].vy); app->asteroids[j].rot += app->asteroids[j].rot_speed; - if (app->asteroids[j].rot < 0) app->asteroids[j].rot = 2*PI; - else if (app->asteroids[j].rot > 2*PI) app->asteroids[j].rot = 0; + if(app->asteroids[j].rot < 0) + app->asteroids[j].rot = 2 * PI; + else if(app->asteroids[j].rot > 2 * PI) + app->asteroids[j].rot = 0; } } /* Collision detection and game state update based on collisions. */ -void detect_collisions(AsteroidsApp *app) { +void detect_collisions(AsteroidsApp* app) { /* Detect collision between bullet and asteroid. */ - for (int j = 0; j < app->bullets_num; j++) { - Bullet *b = &app->bullets[j]; - for (int i = 0; i < app->asteroids_num; i++) { - Asteroid *a = &app->asteroids[i]; - if (objects_are_colliding(a->x, a->y, a->size, - b->x, b->y, 1.5, 1)) - { - asteroid_was_hit(app,i); - remove_bullet(app,j); + for(int j = 0; j < app->bullets_num; j++) { + Bullet* b = &app->bullets[j]; + for(int i = 0; i < app->asteroids_num; i++) { + Asteroid* a = &app->asteroids[i]; + if(objects_are_colliding(a->x, a->y, a->size, b->x, b->y, 1.5, 1)) { + asteroid_was_hit(app, i); + remove_bullet(app, j); /* The bullet no longer exist. Break the loop. * However we want to start processing from the * same bullet index, since now it is used by @@ -479,11 +469,9 @@ void detect_collisions(AsteroidsApp *app) { } /* Detect collision between ship and asteroid. */ - for (int j = 0; j < app->asteroids_num; j++) { - Asteroid *a = &app->asteroids[j]; - if (objects_are_colliding(a->x, a->y, a->size, - app->ship.x, app->ship.y, 4, 1)) - { + for(int j = 0; j < app->asteroids_num; j++) { + Asteroid* a = &app->asteroids[j]; + if(objects_are_colliding(a->x, a->y, a->size, app->ship.x, app->ship.y, 4, 1)) { ship_was_hit(app); break; } @@ -496,26 +484,26 @@ void detect_collisions(AsteroidsApp *app) { * on velocity. Detect collisions. Update the score and so forth. * * Each time this function is called, app->tick is incremented. */ -void game_tick(void *ctx) { - AsteroidsApp *app = ctx; +void game_tick(void* ctx) { + AsteroidsApp* app = ctx; /* There are two special screens: * * 1. Ship was hit, we frozen the game as long as ship_hit isn't zero * again, and show an animation of a rotating ship. */ - if (app->ship_hit) { + if(app->ship_hit) { app->ship.rot += 0.5; app->ship_hit--; view_port_update(app->view_port); - if (app->ship_hit == 0) { + if(app->ship_hit == 0) { restart_game(app); } return; - } else if (app->gameover) { - /* 2. Game over. We need to update only background asteroids. In this + } else if(app->gameover) { + /* 2. Game over. We need to update only background asteroids. In this * state the game just displays a GAME OVER text with the floating * asteroids in backgroud. */ - if (key_pressed_time(app,InputKeyOk) > 100) { + if(key_pressed_time(app, InputKeyOk) > 100) { restart_game_after_gameover(app); } update_asteroids_position(app); @@ -524,12 +512,12 @@ void game_tick(void *ctx) { } /* Handle keypresses. */ - if (app->pressed[InputKeyLeft]) app->ship.rot -= .35; - if (app->pressed[InputKeyRight]) app->ship.rot += .35; - if (key_pressed_time(app,InputKeyOk) > 70) { - app->ship.vx -= 0.5*(float)sin(app->ship.rot); - app->ship.vy += 0.5*(float)cos(app->ship.rot); - } else if (app->pressed[InputKeyDown]) { + if(app->pressed[InputKeyLeft]) app->ship.rot -= .35; + if(app->pressed[InputKeyRight]) app->ship.rot += .35; + if(key_pressed_time(app, InputKeyOk) > 70) { + app->ship.vx -= 0.5 * (float)sin(app->ship.rot); + app->ship.vy += 0.5 * (float)cos(app->ship.rot); + } else if(app->pressed[InputKeyDown]) { app->ship.vx *= 0.75; app->ship.vy *= 0.75; } @@ -537,10 +525,10 @@ void game_tick(void *ctx) { /* Fire a bullet if needed. app->fire is set in * asteroids_update_keypress_state() since depends on exact * pressure timing. */ - if (app->fire) { + if(app->fire) { uint32_t bullet_min_period = 200; // In milliseconds uint32_t now = furi_get_tick(); - if (now - app->last_bullet_tick >= bullet_min_period) { + if(now - app->last_bullet_tick >= bullet_min_period) { ship_fire_bullet(app); app->last_bullet_tick = now; } @@ -548,7 +536,7 @@ void game_tick(void *ctx) { } /* Update positions and detect collisions. */ - update_pos_by_velocity(&app->ship.x,&app->ship.y,app->ship.vx,app->ship.vy); + update_pos_by_velocity(&app->ship.x, &app->ship.y, app->ship.vx, app->ship.vy); update_bullets_position(app); update_asteroids_position(app); detect_collisions(app); @@ -556,9 +544,7 @@ void game_tick(void *ctx) { /* From time to time, create a new asteroid. The more asteroids * already on the screen, the smaller probability of creating * a new one. */ - if (app->asteroids_num == 0 || - (random() % 5000) < (30/(1+app->asteroids_num))) - { + if(app->asteroids_num == 0 || (random() % 5000) < (30 / (1 + app->asteroids_num))) { add_asteroid(app); } @@ -570,16 +556,15 @@ void game_tick(void *ctx) { /* Here all we do is putting the events into the queue that will be handled * in the while() loop of the app entry point function. */ -void input_callback(InputEvent* input_event, void* ctx) -{ - AsteroidsApp *app = ctx; - furi_message_queue_put(app->event_queue,input_event,FuriWaitForever); +void input_callback(InputEvent* input_event, void* ctx) { + AsteroidsApp* app = ctx; + furi_message_queue_put(app->event_queue, input_event, FuriWaitForever); } /* Allocate the application state and initialize a number of stuff. * This is called in the entry point to create the application state. */ AsteroidsApp* asteroids_app_alloc() { - AsteroidsApp *app = malloc(sizeof(AsteroidsApp)); + AsteroidsApp* app = malloc(sizeof(AsteroidsApp)); app->gui = furi_record_open(RECORD_GUI); app->view_port = view_port_alloc(); @@ -588,16 +573,16 @@ AsteroidsApp* asteroids_app_alloc() { gui_add_view_port(app->gui, app->view_port, GuiLayerFullscreen); app->event_queue = furi_message_queue_alloc(8, sizeof(InputEvent)); - app->running = 1; /* Turns 0 when back is pressed. */ + app->running = 1; /* Turns 0 when back is pressed. */ restart_game_after_gameover(app); - memset(app->pressed,0,sizeof(app->pressed)); + memset(app->pressed, 0, sizeof(app->pressed)); return app; } /* Free what the application allocated. It is not clear to me if the * Flipper OS, once the application exits, will be able to reclaim space * even if we forget to free something here. */ -void asteroids_app_free(AsteroidsApp *app) { +void asteroids_app_free(AsteroidsApp* app) { furi_assert(app); // View related. @@ -613,28 +598,27 @@ void asteroids_app_free(AsteroidsApp *app) { /* Return the time in milliseconds the specified key is continuously * pressed. Or 0 if it is not pressed. */ -uint32_t key_pressed_time(AsteroidsApp *app, InputKey key) { - return app->pressed[key] == 0 ? 0 : - furi_get_tick() - app->pressed[key]; +uint32_t key_pressed_time(AsteroidsApp* app, InputKey key) { + return app->pressed[key] == 0 ? 0 : furi_get_tick() - app->pressed[key]; } /* Handle keys interaction. */ -void asteroids_update_keypress_state(AsteroidsApp *app, InputEvent input) { - if (input.type == InputTypePress) { +void asteroids_update_keypress_state(AsteroidsApp* app, InputEvent input) { + if(input.type == InputTypePress) { app->pressed[input.key] = furi_get_tick(); - } else if (input.type == InputTypeRelease) { - uint32_t dur = key_pressed_time(app,input.key); + } else if(input.type == InputTypeRelease) { + uint32_t dur = key_pressed_time(app, input.key); app->pressed[input.key] = 0; - if (dur < 200 && input.key == InputKeyOk) app->fire = true; + if(dur < 200 && input.key == InputKeyOk) app->fire = true; } } int32_t asteroids_app_entry(void* p) { UNUSED(p); - AsteroidsApp *app = asteroids_app_alloc(); + AsteroidsApp* app = asteroids_app_alloc(); /* Create a timer. We do data analysis in the callback. */ - FuriTimer *timer = furi_timer_alloc(game_tick, FuriTimerTypePeriodic, app); + FuriTimer* timer = furi_timer_alloc(game_tick, FuriTimerTypePeriodic, app); furi_timer_start(timer, furi_kernel_get_tick_frequency() / 10); /* This is the main event loop: here we get the events that are pushed @@ -643,25 +627,24 @@ int32_t asteroids_app_entry(void* p) { InputEvent input; while(app->running) { FuriStatus qstat = furi_message_queue_get(app->event_queue, &input, 100); - if (qstat == FuriStatusOk) { - if (DEBUG_MSG) FURI_LOG_E(TAG, "Main Loop - Input: type %d key %u", - input.type, input.key); + if(qstat == FuriStatusOk) { + if(DEBUG_MSG) + FURI_LOG_E(TAG, "Main Loop - Input: type %d key %u", input.type, input.key); /* Handle navigation here. Then handle view-specific inputs * in the view specific handling function. */ - if (input.type == InputTypeShort && - input.key == InputKeyBack) - { + if(input.type == InputTypeShort && input.key == InputKeyBack) { app->running = 0; } else { - asteroids_update_keypress_state(app,input); + asteroids_update_keypress_state(app, input); } } else { /* Useful to understand if the app is still alive when it * does not respond because of bugs. */ - if (DEBUG_MSG) { - static int c = 0; c++; - if (!(c % 20)) FURI_LOG_E(TAG, "Loop timeout"); + if(DEBUG_MSG) { + static int c = 0; + c++; + if(!(c % 20)) FURI_LOG_E(TAG, "Loop timeout"); } } } From 6c8444e490da1d2268d60a32473c91e60ab4770e Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Sat, 7 Jan 2023 00:23:21 -0500 Subject: [PATCH 02/75] Map key press up to thrusters --- app.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.c b/app.c index 372aa0d..b4e765e 100644 --- a/app.c +++ b/app.c @@ -514,7 +514,7 @@ void game_tick(void* ctx) { /* Handle keypresses. */ if(app->pressed[InputKeyLeft]) app->ship.rot -= .35; if(app->pressed[InputKeyRight]) app->ship.rot += .35; - if(key_pressed_time(app, InputKeyOk) > 70) { + if(app->pressed[InputKeyUp]) { app->ship.vx -= 0.5 * (float)sin(app->ship.rot); app->ship.vy += 0.5 * (float)cos(app->ship.rot); } else if(app->pressed[InputKeyDown]) { From 5e7e4c7717cad623cfee7b814d161506b22ecffa Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Sat, 7 Jan 2023 00:44:21 -0500 Subject: [PATCH 03/75] Press and Hold to continuous fire to reduce wear --- app.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app.c b/app.c index b4e765e..b6fc9e7 100644 --- a/app.c +++ b/app.c @@ -604,12 +604,10 @@ uint32_t key_pressed_time(AsteroidsApp* app, InputKey key) { /* Handle keys interaction. */ void asteroids_update_keypress_state(AsteroidsApp* app, InputEvent input) { + if(input.key == InputKeyOk) app->fire = true; + if(input.type == InputTypePress) { app->pressed[input.key] = furi_get_tick(); - } else if(input.type == InputTypeRelease) { - uint32_t dur = key_pressed_time(app, input.key); - app->pressed[input.key] = 0; - if(dur < 200 && input.key == InputKeyOk) app->fire = true; } } From 81d7a2b44a141bc8c2b2001ab8b6a12fee620fb9 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Sat, 7 Jan 2023 01:16:25 -0500 Subject: [PATCH 04/75] Bugfix: Wrong branch. Keys not registering --- app.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app.c b/app.c index b6fc9e7..6e6f0c6 100644 --- a/app.c +++ b/app.c @@ -604,10 +604,15 @@ uint32_t key_pressed_time(AsteroidsApp* app, InputKey key) { /* Handle keys interaction. */ void asteroids_update_keypress_state(AsteroidsApp* app, InputEvent input) { - if(input.key == InputKeyOk) app->fire = true; + // Allow Rapid fire + if(input.key == InputKeyOk) { + app->fire = true; + } if(input.type == InputTypePress) { app->pressed[input.key] = furi_get_tick(); + } else if(input.type == InputTypeRelease) { + app->pressed[input.key] = 0; } } From d05a98010f1ac5d6fc0d99f2f57f042793f95ae4 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Sat, 7 Jan 2023 01:18:00 -0500 Subject: [PATCH 05/75] Reduce max bullets for increased difficulty --- app.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.c b/app.c index 6e6f0c6..3221194 100644 --- a/app.c +++ b/app.c @@ -42,7 +42,7 @@ typedef struct Asteroid { uint8_t shape_seed; /* Seed to give random shape. */ } Asteroid; -#define MAXBUL 10 /* Max bullets on the screen. */ +#define MAXBUL 5 /* Max bullets on the screen. */ #define MAXAST 32 /* Max asteroids on the screen. */ #define SHIP_HIT_ANIMATION_LEN 15 typedef struct AsteroidsApp { From a2555237df21c42f61769259a73e97c8ec29b800 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Sat, 7 Jan 2023 01:25:05 -0500 Subject: [PATCH 06/75] Shorten Bullet TTL, Reorganize defines --- app.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app.c b/app.c index 3221194..71f05fa 100644 --- a/app.c +++ b/app.c @@ -16,6 +16,10 @@ #define SCREEN_XRES 128 #define SCREEN_YRES 64 #define GAME_START_LIVES 3 +#define TTLBUL 30 /* Bullet time to live, in ticks. */ +#define MAXBUL 5 /* Max bullets on the screen. */ +#define MAXAST 32 /* Max asteroids on the screen. */ +#define SHIP_HIT_ANIMATION_LEN 15 #ifndef PI #define PI 3.14159265358979f #endif @@ -42,9 +46,6 @@ typedef struct Asteroid { uint8_t shape_seed; /* Seed to give random shape. */ } Asteroid; -#define MAXBUL 5 /* Max bullets on the screen. */ -#define MAXAST 32 /* Max asteroids on the screen. */ -#define SHIP_HIT_ANIMATION_LEN 15 typedef struct AsteroidsApp { /* GUI */ Gui* gui; @@ -303,7 +304,7 @@ void ship_fire_bullet(AsteroidsApp* app) { b->vx += app->ship.vx; b->vy += app->ship.vy; - b->ttl = 50; /* The bullet will disappear after N ticks. */ + b->ttl = TTLBUL; /* The bullet will disappear after N ticks. */ app->bullets_num++; } From c55cde8d2f6c1d048b4c6fc3dec85e496a53629f Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Sat, 7 Jan 2023 01:45:04 -0500 Subject: [PATCH 07/75] Add vibration and red LED on crash --- app.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app.c b/app.c index 71f05fa..76da1d3 100644 --- a/app.c +++ b/app.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include #define TAG "Asteroids" // Used for logging #define DEBUG_MSG 1 @@ -82,6 +84,18 @@ typedef struct AsteroidsApp { bool fire; /* Short press detected: fire a bullet. */ } AsteroidsApp; +const NotificationSequence sequence_crash = { + &message_red_255, + + &message_vibro_on, + // &message_note_g5, // Play sound but currently disabled + &message_delay_25, + // &message_note_e5, + &message_vibro_off, + &message_sound_off, + NULL, +}; + /* ============================== Prototyeps ================================ */ // Only functions called before their definition are here. @@ -493,6 +507,7 @@ void game_tick(void* ctx) { * 1. Ship was hit, we frozen the game as long as ship_hit isn't zero * again, and show an animation of a rotating ship. */ if(app->ship_hit) { + notification_message(furi_record_open(RECORD_NOTIFICATION), &sequence_crash); app->ship.rot += 0.5; app->ship_hit--; view_port_update(app->view_port); From ef4c55286bba769c3adb69f4de1435931145b15a Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Sat, 7 Jan 2023 01:51:58 -0500 Subject: [PATCH 08/75] Vibrate on bullets fired. FIRE ZE LAZERS! --- app.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app.c b/app.c index 76da1d3..bd19330 100644 --- a/app.c +++ b/app.c @@ -96,6 +96,22 @@ const NotificationSequence sequence_crash = { NULL, }; +const NotificationSequence sequence_bullet_fired = { + &message_vibro_on, + // &message_note_g5, // Play sound but currently disabled. Need On/Off menu setting + &message_delay_10, + &message_delay_1, + &message_delay_1, + &message_delay_1, + &message_delay_1, + &message_delay_1, + + // &message_note_e5, + &message_vibro_off, + &message_sound_off, + NULL, +}; + /* ============================== Prototyeps ================================ */ // Only functions called before their definition are here. @@ -297,6 +313,7 @@ bool objects_are_colliding(float x1, float y1, float r1, float x2, float y2, flo /* Create a new bullet headed in the same direction of the ship. */ void ship_fire_bullet(AsteroidsApp* app) { if(app->bullets_num == MAXBUL) return; + notification_message(furi_record_open(RECORD_NOTIFICATION), &sequence_bullet_fired); Bullet* b = &app->bullets[app->bullets_num]; b->x = app->ship.x; b->y = app->ship.y; From 12a62a9a0b4786138c6768a4675274c2f6430008 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Sat, 7 Jan 2023 03:02:37 -0500 Subject: [PATCH 09/75] New Astroid build --- binaries/asteroids.fap | Bin 21244 -> 21960 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/binaries/asteroids.fap b/binaries/asteroids.fap index dd58ad446cf64fb66dfa40942c543b80cb514362..d9693082ba3a437c8c07bae2e5799fc1715c39c3 100644 GIT binary patch delta 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ys;$g=_K0u=CJTvr9318-bOx(S31$FNHlzqM8kC?0yjzhCnQc!^|WyPdXkBe z=zu@Wxw%(Phen)668$xYwNJgu!d|7m6T=)AG&(3H5onR{8R1S6frG*uW`uPW`35$Z z=-tA1r2eSr^TJ#6nHbi;4h1&cN+PpYNhEZbL;^?29;H4ak=UnF|2c_ve-``qBoa$6 z2-g>q&`U|QKPdICtHZjK^l^kNfXjrdNCbXRbR&sCO`==HzD;zS*bj>C5}qUxr&shj z(LvGQfj$O~nHhFWCy~fB(X&L)BjNXn@DJpx_&OG?W`*@U5`ObV-zEA}5^&KKh5%lkP2oq6ceNqP7hmMm8U_T!ISrYCiN^VhYf-m0QX*56{s{ qmrNVyKtF57h2Nl8>OWaBIi|4;Kf+@4XP0EB4p-rgg3j`ovHk~~bm))( From 9ea751f9e647925b8491befb08b09924676fbd6a Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Sat, 7 Jan 2023 10:44:02 -0500 Subject: [PATCH 10/75] Update ReadMe --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 58cc4dd..7f10e27 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,10 @@ This is an implementation of the classic Asteroids game for the [Flipper Zero](h Controls: * Left/Right: rotate ship in the two directions. -* Ok, short press: fire bullets. -* Ok, long press: accelerate towards ship head. -* Down: decelerates. +* Ok, short press: Short burst bullets +* Ok, long press: Auto-fire bullets +* Up: accelerate +* Down: decelerates This is a screenshot, but the game looks a lot better in the device itself: From d7c8a220d7c54605394189374e9cebd3c2ee8fa9 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Sat, 7 Jan 2023 11:01:16 -0500 Subject: [PATCH 11/75] Bugfix: Properly account for lives (from antirez) --- app.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.c b/app.c index bd19330..d9cc53b 100644 --- a/app.c +++ b/app.c @@ -450,7 +450,7 @@ void restart_game_after_gameover(AsteroidsApp* app) { app->ticks = 0; app->score = 0; app->ship_hit = 0; - app->lives = GAME_START_LIVES; + app->lives = GAME_START_LIVES - 1; restart_game(app); } From 6c0a033294521b3697296b995c22872902ef7ba1 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Sat, 7 Jan 2023 11:19:08 -0500 Subject: [PATCH 12/75] Cosmetically show 3 lives on Game Over screen --- app.c | 1 + 1 file changed, 1 insertion(+) diff --git a/app.c b/app.c index d9cc53b..36b1db4 100644 --- a/app.c +++ b/app.c @@ -536,6 +536,7 @@ void game_tick(void* ctx) { /* 2. Game over. We need to update only background asteroids. In this * state the game just displays a GAME OVER text with the floating * asteroids in backgroud. */ + app->lives = GAME_START_LIVES; // Show 3 lives in game over screen to match new game start if(key_pressed_time(app, InputKeyOk) > 100) { restart_game_after_gameover(app); } From 0beaa3f47fbce6135c97be06ca1b8f2f3197c5a9 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Sun, 8 Jan 2023 11:19:52 -0500 Subject: [PATCH 13/75] update .gitignore and add .editorconfig --- .editorconfig | 13 +++++++++++++ .gitignore | 3 +++ 2 files changed, 16 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitignore diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..a31ef8e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 + +[*.{cpp,h,c,py,sh}] +indent_style = space +indent_size = 4 + +[{Makefile,*.mk}] +indent_size = tab diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b0a64d5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.vscode/ +dist/ +.clang-format From deadbf533693fb0dfaa32e123afff24329d24887 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Sun, 8 Jan 2023 11:20:07 -0500 Subject: [PATCH 14/75] Add High Score system --- app.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app.c b/app.c index 36b1db4..a37944d 100644 --- a/app.c +++ b/app.c @@ -60,6 +60,8 @@ typedef struct AsteroidsApp { bool gameover; /* Gameover status. */ uint32_t ticks; /* Game ticks. Increments at each refresh. */ uint32_t score; /* Game score. */ + uint32_t highscore; /* Highscore. Shown on Game Over Screen */ + uint32_t last_score; /* Last score. Shown on Game Over screen */ uint32_t lives; /* Number of lives in the current game. */ uint32_t ship_hit; /* When non zero, the ship was hit by an asteroid and we need to show an animation as long as @@ -270,6 +272,25 @@ void render_callback(Canvas* const canvas, void* ctx) { if(app->gameover) { canvas_set_color(canvas, ColorBlack); canvas_set_font(canvas, FontPrimary); + + // Display High Score + canvas_draw_str(canvas, 36, 9, "High Score"); + + // Convert highscore to string + int length = snprintf(NULL, 0, "%lu", app->highscore); + char* str_high_score = malloc(length + 1); + snprintf(str_high_score, length + 1, "%lu", app->highscore); + + // Get length to center on screen + int nDigits = 0; + if(app->highscore > 0) { + nDigits = floor(log10(app->highscore)) + 1; + } + + // Draw highscore centered + canvas_draw_str(canvas, (SCREEN_XRES / 2) - (nDigits * 2), 18, str_high_score); + free(str_high_score); + canvas_draw_str(canvas, 28, 35, "GAME OVER"); canvas_set_font(canvas, FontSecondary); canvas_draw_str(canvas, 25, 50, "Press OK to restart"); @@ -406,6 +427,10 @@ void asteroid_was_hit(AsteroidsApp* app, int id) { } } else { app->score++; + app->last_score = app->score; // Save for Game Over Screen + if(app->score > app->highscore) { + app->highscore = app->score; // Show on Game Over Screen and future main menu + } } } @@ -537,6 +562,7 @@ void game_tick(void* ctx) { * state the game just displays a GAME OVER text with the floating * asteroids in backgroud. */ app->lives = GAME_START_LIVES; // Show 3 lives in game over screen to match new game start + app->score = app->last_score; if(key_pressed_time(app, InputKeyOk) > 100) { restart_game_after_gameover(app); } From da4cfe091760150899e9cbeb0167f3215f3f200b Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Sun, 8 Jan 2023 11:50:09 -0500 Subject: [PATCH 15/75] Add thrusters animation --- app.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app.c b/app.c index a37944d..24bcfbe 100644 --- a/app.c +++ b/app.c @@ -136,6 +136,8 @@ typedef struct Poly { /* Define the polygons we use. */ Poly ShipPoly = {{-3, 0, 3}, {-3, 6, -3}, 3}; +Poly ShipFirePoly = {{-1.5, 0, 1.5}, {-3, -6, -3}, 3}; + /* Rotate the point of the poligon 'poly' and store the new rotated * polygon in 'rot'. The polygon is rotated by an angle 'a', with * center at 0,0. */ @@ -264,6 +266,10 @@ void render_callback(Canvas* const canvas, void* ctx) { /* Draw ship, asteroids, bullets. */ draw_poly(canvas, &ShipPoly, app->ship.x, app->ship.y, app->ship.rot); + if(key_pressed_time(app, InputKeyUp) > 0) { + draw_poly(canvas, &ShipFirePoly, app->ship.x, app->ship.y, app->ship.rot); + } + for(int j = 0; j < app->bullets_num; j++) draw_bullet(canvas, &app->bullets[j]); for(int j = 0; j < app->asteroids_num; j++) draw_asteroid(canvas, &app->asteroids[j]); From 5829369a8565c825869dc3afec20674ba22ed93c Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Sun, 8 Jan 2023 12:45:08 -0500 Subject: [PATCH 16/75] Added auto save/load game state to save high score --- app.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/app.c b/app.c index 24bcfbe..4ec7071 100644 --- a/app.c +++ b/app.c @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -22,6 +23,8 @@ #define MAXBUL 5 /* Max bullets on the screen. */ #define MAXAST 32 /* Max asteroids on the screen. */ #define SHIP_HIT_ANIMATION_LEN 15 +#define SAVING_DIRECTORY "/ext/apps/Games" +#define SAVING_FILENAME SAVING_DIRECTORY "/game_asteroids.save" #ifndef PI #define PI 3.14159265358979f #endif @@ -117,7 +120,8 @@ const NotificationSequence sequence_bullet_fired = { /* ============================== Prototyeps ================================ */ // Only functions called before their definition are here. - +bool load_game(AsteroidsApp* app); +void save_game(AsteroidsApp* app); void restart_game_after_gameover(AsteroidsApp* app); uint32_t key_pressed_time(AsteroidsApp* app, InputKey key); @@ -443,6 +447,7 @@ void asteroid_was_hit(AsteroidsApp* app, int id) { /* Set gameover state. When in game-over mode, the game displays a gameover * text with a background of many asteroids floating around. */ void game_over(AsteroidsApp* app) { + save_game(app); // Save highscore restart_game_after_gameover(app); app->gameover = true; int asteroids = 8; @@ -620,6 +625,41 @@ void game_tick(void* ctx) { /* ======================== Flipper specific code =========================== */ +bool load_game(AsteroidsApp* app) { + Storage* storage = furi_record_open(RECORD_STORAGE); + + File* file = storage_file_alloc(storage); + uint16_t bytes_readed = 0; + if(storage_file_open(file, SAVING_FILENAME, FSAM_READ, FSOM_OPEN_EXISTING)) { + bytes_readed = storage_file_read(file, app, sizeof(AsteroidsApp)); + } + storage_file_close(file); + storage_file_free(file); + + furi_record_close(RECORD_STORAGE); + + return bytes_readed == sizeof(AsteroidsApp); +} + +void save_game(AsteroidsApp* app) { + Storage* storage = furi_record_open(RECORD_STORAGE); + + if(storage_common_stat(storage, SAVING_DIRECTORY, NULL) == FSE_NOT_EXIST) { + if(!storage_simply_mkdir(storage, SAVING_DIRECTORY)) { + return; + } + } + + File* file = storage_file_alloc(storage); + if(storage_file_open(file, SAVING_FILENAME, FSAM_WRITE, FSOM_CREATE_ALWAYS)) { + storage_file_write(file, app, sizeof(AsteroidsApp)); + } + storage_file_close(file); + storage_file_free(file); + + furi_record_close(RECORD_STORAGE); +} + /* Here all we do is putting the events into the queue that will be handled * in the while() loop of the app entry point function. */ void input_callback(InputEvent* input_event, void* ctx) { @@ -632,6 +672,8 @@ void input_callback(InputEvent* input_event, void* ctx) { AsteroidsApp* asteroids_app_alloc() { AsteroidsApp* app = malloc(sizeof(AsteroidsApp)); + load_game(app); + app->gui = furi_record_open(RECORD_GUI); app->view_port = view_port_alloc(); view_port_draw_callback_set(app->view_port, render_callback, app); @@ -640,6 +682,7 @@ AsteroidsApp* asteroids_app_alloc() { app->event_queue = furi_message_queue_alloc(8, sizeof(InputEvent)); app->running = 1; /* Turns 0 when back is pressed. */ + restart_game_after_gameover(app); memset(app->pressed, 0, sizeof(app->pressed)); return app; From 4a49e0458cd19891f361058ad0c17b569b2ecd44 Mon Sep 17 00:00:00 2001 From: antirez Date: Sun, 8 Jan 2023 00:56:48 +0100 Subject: [PATCH 17/75] Prep for automated build system --- binaries/README.md | 10 ---------- binaries/asteroids.fap | Bin 21960 -> 0 bytes binaries/update.sh | 4 ---- 3 files changed, 14 deletions(-) delete mode 100644 binaries/README.md delete mode 100644 binaries/asteroids.fap delete mode 100755 binaries/update.sh diff --git a/binaries/README.md b/binaries/README.md deleted file mode 100644 index f9dbaac..0000000 --- a/binaries/README.md +++ /dev/null @@ -1,10 +0,0 @@ -This is the binary distribution of the application. If you don't want -to build it from source, just take `asteroids.fap` file and drop it into the -following Flipper Zero location: - - /ext/apps/Games - -The `ext` part means that we are in the SD card. So if you don't want -to use the Android (or other) application to upload the file, -you can just take out the SD card, insert it in your computer, -copy the fine into `apps/Games`, and that's it. diff --git a/binaries/asteroids.fap b/binaries/asteroids.fap deleted file mode 100644 index d9693082ba3a437c8c07bae2e5799fc1715c39c3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 21960 zcmbt+3tW_C_W$#~@60d`BZ8**E@{*+#@l9E zyCk+hMNPM?EXuI7wJmliZPPBhLt=kZD7uNx$n1<@P1@$~d)^BS)b4-(zyJIBynNsD zob#OLJkL4Lc`jpBr!5jWj$`V>v3N$5cDP(}ak+%rBnje~kp)X%>%AEeymuDli1uKX3u`;|S@b;lho?mO>1=2&Af zwoOR2yLf)ROAt1=7~AOLIF+70af>6dG0e*{GhN)|%x-(sB3IaC-f6aEyOX(asa%-4 z$Q3@7cP_K!x>E#dnR#EZAMkOSGd@$u!1MgIkRM~NX|LELl6{O5u7%($<(jtZp5&1B z=X@q@2&B02DE~3uvB=9CiPsdd)cy7SoR_5qoyqjFkX9cvKH_Gq#LaPsui8hAIDPmk z8)ZD5p|`pc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u^o%S1J5;3T_~T zJzEue2O;Y1QRwFt{vm}vrtq5-`U8dki9&ZPd`+xumyrhTFOe+(h)N+m@3-3q-y;h$B?mrRi5a|o$_3T{&HcZ8__ z2Zi2G2)zdt`Zb0BXN5kY@XsprMFqPFq31`1)=ZS?VT5Qmh7fuuDdnk3`C^5>OQC;5 z2sw{}-x1a`W|}0I#}k77jY1bF^dky=g%IscxkbhWgwU6#&{Yc7DOiK0kKZZ(2Ejjx z^_1xULfk31U%>+k9#rsU!uJq&gw60L;a04Zgiz8%h{6+ukUL2TIX0>M!8H}xIlziC z84J~~vi#yn6|@PTL|vFanik&S)nh_$9iUv%c#BvFUcarC4D^53qA3Ph#Ml5N7aWZ z+ecsAa_oPUG6AUSn~ZPLPh~r&U@wa|72oPZa`fDamvoa{D`bXDm34rW9#w7*DAK1s zBzLDu099UEz&EjrAvc6Rlt diff --git a/binaries/update.sh b/binaries/update.sh deleted file mode 100755 index a474894..0000000 --- a/binaries/update.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -BINPATH="/Users/antirez/hack/flipper/official/build/f7-firmware-D/.extapps/asteroids.fap" -cp $BINPATH . -git commit -a -m 'Binary file updated.' From fd1b4ede7c2c70a3d938422a286e922f7b70b34d Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Sun, 8 Jan 2023 14:10:03 -0500 Subject: [PATCH 18/75] bugfix: last score display, added new high score --- app.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app.c b/app.c index 4ec7071..55061c2 100644 --- a/app.c +++ b/app.c @@ -65,6 +65,7 @@ typedef struct AsteroidsApp { uint32_t score; /* Game score. */ uint32_t highscore; /* Highscore. Shown on Game Over Screen */ uint32_t last_score; /* Last score. Shown on Game Over screen */ + bool is_new_highscore; /* Is the last score a new highscore? */ uint32_t lives; /* Number of lives in the current game. */ uint32_t ship_hit; /* When non zero, the ship was hit by an asteroid and we need to show an animation as long as @@ -283,8 +284,13 @@ void render_callback(Canvas* const canvas, void* ctx) { canvas_set_color(canvas, ColorBlack); canvas_set_font(canvas, FontPrimary); + // TODO: if new highscore, display blinking "New High Score" // Display High Score - canvas_draw_str(canvas, 36, 9, "High Score"); + if(app->is_new_highscore) { + canvas_draw_str(canvas, 22, 9, "New High Score!"); + } else { + canvas_draw_str(canvas, 36, 9, "High Score"); + } // Convert highscore to string int length = snprintf(NULL, 0, "%lu", app->highscore); @@ -439,6 +445,7 @@ void asteroid_was_hit(AsteroidsApp* app, int id) { app->score++; app->last_score = app->score; // Save for Game Over Screen if(app->score > app->highscore) { + app->is_new_highscore = true; app->highscore = app->score; // Show on Game Over Screen and future main menu } } @@ -450,6 +457,8 @@ void game_over(AsteroidsApp* app) { save_game(app); // Save highscore restart_game_after_gameover(app); app->gameover = true; + app->score = app->last_score; + app->lives = GAME_START_LIVES; // Show 3 lives in game over screen to match new game start int asteroids = 8; while(asteroids-- && add_asteroid(app) != NULL) ; @@ -482,6 +491,7 @@ void restart_game(AsteroidsApp* app) { /* Called after gameover to restart the game. This function * also calls restart_game(). */ void restart_game_after_gameover(AsteroidsApp* app) { + app->is_new_highscore = false; app->gameover = false; app->ticks = 0; app->score = 0; @@ -572,8 +582,6 @@ void game_tick(void* ctx) { /* 2. Game over. We need to update only background asteroids. In this * state the game just displays a GAME OVER text with the floating * asteroids in backgroud. */ - app->lives = GAME_START_LIVES; // Show 3 lives in game over screen to match new game start - app->score = app->last_score; if(key_pressed_time(app, InputKeyOk) > 100) { restart_game_after_gameover(app); } From 8f0c10ceb1ca43e702e0534a22e8b2126a3a9702 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Mon, 9 Jan 2023 01:53:10 -0500 Subject: [PATCH 19/75] Hiscore, disable pretty game over anim for clarity --- app.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/app.c b/app.c index 55061c2..d6f3b3e 100644 --- a/app.c +++ b/app.c @@ -64,7 +64,6 @@ typedef struct AsteroidsApp { uint32_t ticks; /* Game ticks. Increments at each refresh. */ uint32_t score; /* Game score. */ uint32_t highscore; /* Highscore. Shown on Game Over Screen */ - uint32_t last_score; /* Last score. Shown on Game Over screen */ bool is_new_highscore; /* Is the last score a new highscore? */ uint32_t lives; /* Number of lives in the current game. */ uint32_t ship_hit; /* When non zero, the ship was hit by an asteroid @@ -304,7 +303,7 @@ void render_callback(Canvas* const canvas, void* ctx) { } // Draw highscore centered - canvas_draw_str(canvas, (SCREEN_XRES / 2) - (nDigits * 2), 18, str_high_score); + canvas_draw_str(canvas, (SCREEN_XRES / 2) - (nDigits * 2), 20, str_high_score); free(str_high_score); canvas_draw_str(canvas, 28, 35, "GAME OVER"); @@ -443,7 +442,6 @@ void asteroid_was_hit(AsteroidsApp* app, int id) { } } else { app->score++; - app->last_score = app->score; // Save for Game Over Screen if(app->score > app->highscore) { app->is_new_highscore = true; app->highscore = app->score; // Show on Game Over Screen and future main menu @@ -455,13 +453,8 @@ void asteroid_was_hit(AsteroidsApp* app, int id) { * text with a background of many asteroids floating around. */ void game_over(AsteroidsApp* app) { save_game(app); // Save highscore - restart_game_after_gameover(app); app->gameover = true; - app->score = app->last_score; app->lives = GAME_START_LIVES; // Show 3 lives in game over screen to match new game start - int asteroids = 8; - while(asteroids-- && add_asteroid(app) != NULL) - ; } /* Function called when a collision between the asteroid and the @@ -486,16 +479,16 @@ void restart_game(AsteroidsApp* app) { app->bullets_num = 0; app->last_bullet_tick = 0; app->asteroids_num = 0; + app->ship_hit = 0; } /* Called after gameover to restart the game. This function * also calls restart_game(). */ void restart_game_after_gameover(AsteroidsApp* app) { - app->is_new_highscore = false; app->gameover = false; app->ticks = 0; app->score = 0; - app->ship_hit = 0; + app->is_new_highscore = false; app->lives = GAME_START_LIVES - 1; restart_game(app); } @@ -582,6 +575,7 @@ void game_tick(void* ctx) { /* 2. Game over. We need to update only background asteroids. In this * state the game just displays a GAME OVER text with the floating * asteroids in backgroud. */ + if(key_pressed_time(app, InputKeyOk) > 100) { restart_game_after_gameover(app); } From 82ec5fdfaec1d40816ac9bd1fc67d97a1e24422d Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Mon, 9 Jan 2023 12:06:04 -0500 Subject: [PATCH 20/75] Update ReadMe to add high score details and credit --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7f10e27..c4f2061 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -This is an implementation of the classic Asteroids game for the [Flipper Zero](https://flipperzero.one/). Inside you will find a simple 2D engine that can be reused to implement other games. +This is an implementation of the classic Asteroids game for the [Flipper Zero](https://flipperzero.one/). Inside you will find a simple 2D engine that can be reused to implement other games. Note: This one is SimplyMinimal's fork of Antirez's version with several modifications. Controls: * Left/Right: rotate ship in the two directions. @@ -7,15 +7,15 @@ Controls: * Up: accelerate * Down: decelerates +Your high scores will automatically be saved. Go forth and compete! + This is a screenshot, but the game looks a lot better in the device itself: ![Asteroids for Flipper Zero screenshot](/images/Asteroids.jpg) -P.S. Don't miss the game over screen. - ## Installing the binary file (no build needed) -Drop the `asteroids.fap` file you can find in the `binaries` folder into the +Go to the releases and drop the `asteroids.fap` file into the following Flipper Zero location: /ext/apps/Games From 73d562540f5e4a4f70e0e685f19c8cd020d4cf7e Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Mon, 9 Jan 2023 15:58:06 -0500 Subject: [PATCH 21/75] haptic feedback thrusters --- app.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app.c b/app.c index d6f3b3e..33edc99 100644 --- a/app.c +++ b/app.c @@ -89,6 +89,22 @@ typedef struct AsteroidsApp { bool fire; /* Short press detected: fire a bullet. */ } AsteroidsApp; +const NotificationSequence sequence_thrusters = { + &message_vibro_on, + &message_delay_10, + &message_vibro_off, + NULL, +}; + +const NotificationSequence sequence_brake = { + &message_vibro_on, + &message_delay_10, + &message_delay_1, + &message_delay_1, + &message_vibro_off, + NULL, +}; + const NotificationSequence sequence_crash = { &message_red_255, @@ -271,6 +287,7 @@ void render_callback(Canvas* const canvas, void* ctx) { draw_poly(canvas, &ShipPoly, app->ship.x, app->ship.y, app->ship.rot); if(key_pressed_time(app, InputKeyUp) > 0) { + notification_message(furi_record_open(RECORD_NOTIFICATION), &sequence_thrusters); draw_poly(canvas, &ShipFirePoly, app->ship.x, app->ship.y, app->ship.rot); } @@ -591,6 +608,7 @@ void game_tick(void* ctx) { app->ship.vx -= 0.5 * (float)sin(app->ship.rot); app->ship.vy += 0.5 * (float)cos(app->ship.rot); } else if(app->pressed[InputKeyDown]) { + notification_message(furi_record_open(RECORD_NOTIFICATION), &sequence_brake); app->ship.vx *= 0.75; app->ship.vy *= 0.75; } From 06f8f55a6f39dac625b01a8ee8e31031f760e7cb Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Tue, 10 Jan 2023 15:44:41 -0500 Subject: [PATCH 22/75] Update ReadMe --- README.md | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c4f2061..716f8e8 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,34 @@ This is an implementation of the classic Asteroids game for the [Flipper Zero](https://flipperzero.one/). Inside you will find a simple 2D engine that can be reused to implement other games. Note: This one is SimplyMinimal's fork of Antirez's version with several modifications. -Controls: +# What's New +* Auto rapid fire (less wear on the buttons this way too) +* Up button applies thrusters +* Haptic feedback and LED effects +* High Score system +* Automatic save and load of high score +* Some modifications to certain game play elements + +## What's coming next +* Settings screen +* Enabling sound effects (configurable on/off option) +* Power Ups + +--- + +This is a screenshot, but the game looks a lot better in the device itself: + +![Asteroids for Flipper Zero screenshot](/images/Asteroids.jpg) + +# Controls: * Left/Right: rotate ship in the two directions. * Ok, short press: Short burst bullets * Ok, long press: Auto-fire bullets * Up: accelerate -* Down: decelerates +* Down: decelerate Your high scores will automatically be saved. Go forth and compete! -This is a screenshot, but the game looks a lot better in the device itself: - -![Asteroids for Flipper Zero screenshot](/images/Asteroids.jpg) - +--- ## Installing the binary file (no build needed) Go to the releases and drop the `asteroids.fap` file into the From f1ecffbc8acb441908b1eb7790f715d5d34e2df6 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Tue, 17 Jan 2023 08:24:43 -0500 Subject: [PATCH 23/75] Autosave on exit, set longpress to exit for safety --- app.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app.c b/app.c index 33edc99..27a44db 100644 --- a/app.c +++ b/app.c @@ -469,7 +469,7 @@ void asteroid_was_hit(AsteroidsApp* app, int id) { /* Set gameover state. When in game-over mode, the game displays a gameover * text with a background of many asteroids floating around. */ void game_over(AsteroidsApp* app) { - save_game(app); // Save highscore + if(app->is_new_highscore) save_game(app); // Save highscore but only on change app->gameover = true; app->lives = GAME_START_LIVES; // Show 3 lives in game over screen to match new game start } @@ -765,7 +765,9 @@ int32_t asteroids_app_entry(void* p) { /* Handle navigation here. Then handle view-specific inputs * in the view specific handling function. */ - if(input.type == InputTypeShort && input.key == InputKeyBack) { + if(input.type == InputTypeLong && input.key == InputKeyBack) { + // Save High Score even if player didn't finish game + if(app->is_new_highscore) save_game(app); // Save highscore but only on change app->running = 0; } else { asteroids_update_keypress_state(app, input); From 0ad2a3168f06c58bd6631cbeed8bfee3af5b1286 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Tue, 17 Jan 2023 08:28:17 -0500 Subject: [PATCH 24/75] Update readme about long back button press --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 716f8e8..7899ff0 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,9 @@ This is a screenshot, but the game looks a lot better in the device itself: * Left/Right: rotate ship in the two directions. * Ok, short press: Short burst bullets * Ok, long press: Auto-fire bullets -* Up: accelerate -* Down: decelerate +* Up: Accelerate +* Down: Decelerate +* Back (Long Press): Exit game. It will automatically save the high scoore too. Your high scores will automatically be saved. Go forth and compete! From 99ffbfa6fe2cb80a51fcaabf09689e996a2ba1e6 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Sat, 28 Jan 2023 01:18:17 -0500 Subject: [PATCH 25/75] first draft of power up system --- app.c | 157 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 155 insertions(+), 2 deletions(-) diff --git a/app.c b/app.c index 27a44db..e04202e 100644 --- a/app.c +++ b/app.c @@ -22,6 +22,8 @@ #define TTLBUL 30 /* Bullet time to live, in ticks. */ #define MAXBUL 5 /* Max bullets on the screen. */ #define MAXAST 32 /* Max asteroids on the screen. */ +#define MAXPOWERUPS 3 /* Max powerups allowed active */ +#define POWERUPSTTL 60 * 1000 /* Max powerup time to live, in ticks. */ #define SHIP_HIT_ANIMATION_LEN 15 #define SAVING_DIRECTORY "/ext/apps/Games" #define SAVING_FILENAME SAVING_DIRECTORY "/game_asteroids.save" @@ -30,6 +32,27 @@ #endif /* ============================ Data structures ============================= */ +typedef enum PowerUpType { + PowerUpTypeNone, // No powerup + PowerUpTypeShield, // Shield + PowerUpTypeLife, // Extra life + PowerUpTypeFirePower, // Burst Fire power + PowerUpTypeRadialFire, // Radial Fire power + PowerUpTypeNuke, // Nuke power + PowerUpTypeClone, // Clone ship + PowerUpTypeAssist, // Secondary ship + Number_of_PowerUps // Used to count the number of powerups +} PowerUpType; + +typedef struct PowerUp { + float x, y, vx, vy, /* Fields like in ship. */ + // rot, /* Fields like ship. */ + // rot_speed, /* Angular velocity (rot speed and sense). */ + size; /* Power Up size. */ + uint32_t ttl; /* Time to live, in ticks. */ + enum PowerUpType powerUpType; /* Powerup type */ + +} PowerUp; typedef struct Ship { float x, /* Ship x position. */ @@ -37,6 +60,8 @@ typedef struct Ship { vx, /* x velocity. */ vy, /* y velocity. */ rot; /* Current rotation. 2*PI full ortation. */ + enum PowerUpType powerUp; /* Current powerup */ + bool isPowerUpActive; /* Is the powerup active? */ } Ship; typedef struct Bullet { @@ -51,6 +76,7 @@ typedef struct Asteroid { uint8_t shape_seed; /* Seed to give random shape. */ } Asteroid; +// @todo AsteroidsApp typedef struct AsteroidsApp { /* GUI */ Gui* gui; @@ -73,9 +99,11 @@ typedef struct AsteroidsApp { /* Ship state. */ struct Ship ship; + struct PowerUp powerUps[MAXPOWERUPS]; /* Each powerup state. */ + int powerUps_num; /* Active powerups. */ /* Bullets state. */ - struct Bullet bullets[MAXBUL]; /* Each bullet state. */ + struct Bullet bullets[MAXBUL * 2]; /* Each bullet state. */ int bullets_num; /* Active bullets. */ uint32_t last_bullet_tick; /* Tick the last bullet was fired. */ @@ -249,6 +277,52 @@ void draw_left_lives(Canvas* const canvas, AsteroidsApp* app) { } } +void draw_powerUps(Canvas* const canvas, PowerUp* p) { + //@todo draw_powerUp + int BOX_SIZE = p->size; + switch(p->powerUpType) { + case PowerUpTypeNone: + break; + case PowerUpTypeFirePower: + // Draw box with letter F inside + canvas_draw_frame(canvas, p->x, p->y, BOX_SIZE, BOX_SIZE); + canvas_draw_str(canvas, p->x + 8, p->y + 6, "F"); + break; + case PowerUpTypeShield: + // Draw box with letter S inside + canvas_draw_frame(canvas, p->x, p->y, BOX_SIZE, BOX_SIZE); + canvas_draw_str(canvas, p->x + 8, p->y + 6, "S"); + break; + case PowerUpTypeLife: + // Draw box with letter L inside + canvas_draw_frame(canvas, p->x, p->y, BOX_SIZE, BOX_SIZE); + canvas_draw_str(canvas, p->x + 8, p->y + 6, "L"); + break; + case PowerUpTypeNuke: + // Draw box with letter N inside + canvas_draw_frame(canvas, p->x, p->y, BOX_SIZE, BOX_SIZE); + canvas_draw_str(canvas, p->x + 8, p->y + 6, "N"); + break; + case PowerUpTypeRadialFire: + // Draw box with letter R inside + canvas_draw_frame(canvas, p->x, p->y, BOX_SIZE, BOX_SIZE); + canvas_draw_str(canvas, p->x + 8, p->y + 6, "R"); + break; + case PowerUpTypeAssist: + // Draw box with letter A inside + canvas_draw_frame(canvas, p->x, p->y, BOX_SIZE, BOX_SIZE); + canvas_draw_str(canvas, p->x + 8, p->y + 6, "A"); + break; + default: + //@todo Uknown Power Up Type Detected + // Draw box with letter U inside + canvas_draw_frame(canvas, p->x, p->y, BOX_SIZE, BOX_SIZE); + canvas_draw_str(canvas, p->x + 3, p->y + 3, "U"); + FURI_LOG_E(TAG, "Unexpected Power Up Type Detected: %i", p->powerUpType); + break; + } +} + /* Given the current position, update it according to the velocity and * wrap it back to the other side if the object went over the screen. */ void update_pos_by_velocity(float* x, float* y, float vx, float vy) { @@ -295,6 +369,8 @@ void render_callback(Canvas* const canvas, void* ctx) { for(int j = 0; j < app->asteroids_num; j++) draw_asteroid(canvas, &app->asteroids[j]); + for(int j = 0; j < app->powerUps_num; j++) draw_powerUps(canvas, &app->powerUps[j]); + /* Game over text. */ if(app->gameover) { canvas_set_color(canvas, ColorBlack); @@ -365,7 +441,12 @@ bool objects_are_colliding(float x1, float y1, float r1, float x2, float y2, flo /* Create a new bullet headed in the same direction of the ship. */ void ship_fire_bullet(AsteroidsApp* app) { - if(app->bullets_num == MAXBUL) return; + // No power ups, only MAXBUL allowed + if(app->ship.isPowerUpActive == false && app->bullets_num == MAXBUL) return; + + // Double the Fire Power + if((app->ship.powerUp == PowerUpTypeFirePower) && (app->bullets_num == MAXBUL * 2)) return; + notification_message(furi_record_open(RECORD_NOTIFICATION), &sequence_bullet_fired); Bullet* b = &app->bullets[app->bullets_num]; b->x = app->ship.x; @@ -466,6 +547,54 @@ void asteroid_was_hit(AsteroidsApp* app, int id) { } } +PowerUp* add_powerUp(AsteroidsApp* app) { + if(app->powerUps_num == MAXPOWERUPS) return NULL; + float size = 4; + float min_distance = 20; + float x, y; + do { + x = rand() % SCREEN_XRES; + y = rand() % SCREEN_YRES; + } while(distance(app->ship.x, app->ship.y, x, y) < min_distance + size); + PowerUp* p = &app->powerUps[app->powerUps_num++]; + p->x = x; + p->y = y; + p->vx = 2 * (-.5 + ((float)rand() / RAND_MAX)); + p->vy = 2 * (-.5 + ((float)rand() / RAND_MAX)); + // p->size = size; + // p->rot = 0; + // p->rot_speed = ((float)rand() / RAND_MAX) / 10; + // if(app->ticks & 1) p->rot_speed = -(p->rot_speed); + // p->shape_seed = rand() & 255; + + //@todo add powerup type, for now hardcoding to firepower + p->powerUpType = 3; //rand() % Number_of_PowerUps; + return p; +} + +void remove_powerUp(AsteroidsApp* app, int id) { + /* Replace the top powerUp with the empty space left + * by the removal of this one. This way we always take the + * array dense, which is an advantage when looping. */ + int n = --app->powerUps_num; + if(n && id != n) app->powerUps[id] = app->powerUps[n]; +} + +void powerUp_was_hit(AsteroidsApp* app, int id) { + PowerUp* p = &app->powerUps[id]; + remove_powerUp(app, id); + switch(p->powerUpType) { + case PowerUpTypeLife: + if(app->lives < GAME_START_LIVES) app->lives++; + break; + case PowerUpTypeFirePower: + app->powerUps[id].powerUpType = PowerUpTypeFirePower; + break; + default: + break; + } +} + /* Set gameover state. When in game-over mode, the game displays a gameover * text with a background of many asteroids floating around. */ void game_over(AsteroidsApp* app) { @@ -494,6 +623,7 @@ void restart_game(AsteroidsApp* app) { app->ship.vx = 0; app->ship.vy = 0; app->bullets_num = 0; + app->powerUps_num = 0; app->last_bullet_tick = 0; app->asteroids_num = 0; app->ship_hit = 0; @@ -536,6 +666,13 @@ void update_asteroids_position(AsteroidsApp* app) { } } +void update_powerUps_position(AsteroidsApp* app) { + for(int j = 0; j < app->powerUps_num; j++) { + update_pos_by_velocity( + &app->powerUps[j].x, &app->powerUps[j].y, app->powerUps[j].vx, app->powerUps[j].vy); + } +} + /* Collision detection and game state update based on collisions. */ void detect_collisions(AsteroidsApp* app) { /* Detect collision between bullet and asteroid. */ @@ -564,6 +701,15 @@ void detect_collisions(AsteroidsApp* app) { break; } } + + /* Detect collision between ship and powerUp. */ + for(int j = 0; j < app->powerUps_num; j++) { + PowerUp* p = &app->powerUps[j]; + if(objects_are_colliding(p->x, p->y, p->size, app->ship.x, app->ship.y, 4, 1)) { + powerUp_was_hit(app, j); + break; + } + } } /* This is the main game execution function, called 10 times for @@ -597,6 +743,7 @@ void game_tick(void* ctx) { restart_game_after_gameover(app); } update_asteroids_position(app); + update_powerUps_position(app); view_port_update(app->view_port); return; } @@ -630,6 +777,7 @@ void game_tick(void* ctx) { update_pos_by_velocity(&app->ship.x, &app->ship.y, app->ship.vx, app->ship.vy); update_bullets_position(app); update_asteroids_position(app); + update_powerUps_position(app); detect_collisions(app); /* From time to time, create a new asteroid. The more asteroids @@ -639,6 +787,11 @@ void game_tick(void* ctx) { add_asteroid(app); } + /* From time to time add a random power up */ + if(app->powerUps_num == 0 || (random() % 5000) < (30 / (1 + app->powerUps_num))) { + add_powerUp(app); + } + app->ticks++; view_port_update(app->view_port); } From 8d5e78af5f9ee44687a3cb871e92134adbcb4ff0 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Tue, 31 Jan 2023 18:43:23 -0500 Subject: [PATCH 26/75] Fix power up system --- app.c | 215 +++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 167 insertions(+), 48 deletions(-) diff --git a/app.c b/app.c index e04202e..f97591e 100644 --- a/app.c +++ b/app.c @@ -21,9 +21,10 @@ #define GAME_START_LIVES 3 #define TTLBUL 30 /* Bullet time to live, in ticks. */ #define MAXBUL 5 /* Max bullets on the screen. */ -#define MAXAST 32 /* Max asteroids on the screen. */ -#define MAXPOWERUPS 3 /* Max powerups allowed active */ -#define POWERUPSTTL 60 * 1000 /* Max powerup time to live, in ticks. */ +//@todo MAX Asteroids +#define MAXAST 0 //32 /* Max asteroids on the screen. */ +#define MAXPOWERUPS 3 /* Max powerups allowed on screen */ +#define POWERUPSTTL 10 * 1000 /* Max powerup time to live, in ticks. */ #define SHIP_HIT_ANIMATION_LEN 15 #define SAVING_DIRECTORY "/ext/apps/Games" #define SAVING_FILENAME SAVING_DIRECTORY "/game_asteroids.save" @@ -33,7 +34,7 @@ /* ============================ Data structures ============================= */ typedef enum PowerUpType { - PowerUpTypeNone, // No powerup + // PowerUpTypeNone, // No powerup PowerUpTypeShield, // Shield PowerUpTypeLife, // Extra life PowerUpTypeFirePower, // Burst Fire power @@ -44,14 +45,17 @@ typedef enum PowerUpType { Number_of_PowerUps // Used to count the number of powerups } PowerUpType; +// struct PowerUp typedef struct PowerUp { - float x, y, vx, vy, /* Fields like in ship. */ - // rot, /* Fields like ship. */ - // rot_speed, /* Angular velocity (rot speed and sense). */ - size; /* Power Up size. */ - uint32_t ttl; /* Time to live, in ticks. */ - enum PowerUpType powerUpType; /* Powerup type */ + float x, y, vx, vy; /* Fields like in ship. */ + // rot, /* Fields like ship. */ + // rot_speed, /* Angular velocity (rot speed and sense). */ + int size; /* Power Up size */ + uint32_t ttl; /* Time to live, in ticks. */ + uint32_t display_ttl; /* How long to display the powerup before it disappears */ + enum PowerUpType powerUpType; /* PowerUp type */ + bool isPowerUpActive; /* Is the powerup active? */ } PowerUp; typedef struct Ship { @@ -60,8 +64,6 @@ typedef struct Ship { vx, /* x velocity. */ vy, /* y velocity. */ rot; /* Current rotation. 2*PI full ortation. */ - enum PowerUpType powerUp; /* Current powerup */ - bool isPowerUpActive; /* Is the powerup active? */ } Ship; typedef struct Bullet { @@ -164,6 +166,8 @@ const NotificationSequence sequence_bullet_fired = { /* ============================== Prototyeps ================================ */ // Only functions called before their definition are here. +bool isPowerUpActive(AsteroidsApp* app, enum PowerUpType powerUpType); +bool isPowerUpAlreadyExists(AsteroidsApp* app, enum PowerUpType powerUpType); bool load_game(AsteroidsApp* app); void save_game(AsteroidsApp* app); void restart_game_after_gameover(AsteroidsApp* app); @@ -277,47 +281,87 @@ void draw_left_lives(Canvas* const canvas, AsteroidsApp* app) { } } -void draw_powerUps(Canvas* const canvas, PowerUp* p) { - //@todo draw_powerUp - int BOX_SIZE = p->size; +void draw_powerUps(Canvas* const canvas, PowerUp* const p) { + /* + + * * * * * * * * * * + * * + * * + * * + * F * + * * + * * + * * + * * + * * * * * * * * * * + + BOX_SIZE = 10 + Box_Width = BOX_SIZE + BOX_HEIGHT = BOX_SIZE + BOX_X_POS = x - BOX_WIDTH/2 + BOX_Y_POS = y - BOX_HEIGHT/2 + POS_F_X = WIDTH/2 + POS_F_Y = HEIGHT/2 + + */ + + //@todo render_callback + + // Just return if power up has already been picked up + FURI_LOG_I(TAG, "[draw_powerUps] Display TTL: %lu", p->display_ttl); + if(p->display_ttl == 0) return; + + canvas_set_color(canvas, ColorXOR); + + int BOX_SIZE = p->size * 2; switch(p->powerUpType) { - case PowerUpTypeNone: - break; case PowerUpTypeFirePower: // Draw box with letter F inside - canvas_draw_frame(canvas, p->x, p->y, BOX_SIZE, BOX_SIZE); - canvas_draw_str(canvas, p->x + 8, p->y + 6, "F"); + FURI_LOG_D( + TAG, + "[draw_powerUps] p->size: %i x:%i y:%i BOX_SIZE: %i", + p->size, + abs((int)p->x - (int)(p->size / 2)), + abs((int)p->y - (int)(p->size / 2)), + BOX_SIZE); + canvas_draw_frame( + canvas, + abs((int)p->x - (int)(p->size / 2)), + abs((int)p->y - (int)(p->size / 2)), + BOX_SIZE, + BOX_SIZE); + canvas_draw_str(canvas, p->x, p->y, "F"); break; case PowerUpTypeShield: // Draw box with letter S inside - canvas_draw_frame(canvas, p->x, p->y, BOX_SIZE, BOX_SIZE); - canvas_draw_str(canvas, p->x + 8, p->y + 6, "S"); + canvas_draw_frame(canvas, p->x - p->size / 2, p->y - p->size / 2, BOX_SIZE, BOX_SIZE); + canvas_draw_str(canvas, p->x, p->y - BOX_SIZE / 2, "S"); break; case PowerUpTypeLife: // Draw box with letter L inside - canvas_draw_frame(canvas, p->x, p->y, BOX_SIZE, BOX_SIZE); - canvas_draw_str(canvas, p->x + 8, p->y + 6, "L"); + canvas_draw_frame(canvas, p->x - p->size / 2, p->y - p->size / 2, BOX_SIZE, BOX_SIZE); + canvas_draw_str(canvas, p->x, p->y - BOX_SIZE / 2, "L"); break; case PowerUpTypeNuke: // Draw box with letter N inside - canvas_draw_frame(canvas, p->x, p->y, BOX_SIZE, BOX_SIZE); - canvas_draw_str(canvas, p->x + 8, p->y + 6, "N"); + canvas_draw_frame(canvas, p->x - p->size / 2, p->y - p->size / 2, BOX_SIZE, BOX_SIZE); + canvas_draw_str(canvas, p->x, p->y - BOX_SIZE / 2, "N"); break; case PowerUpTypeRadialFire: // Draw box with letter R inside - canvas_draw_frame(canvas, p->x, p->y, BOX_SIZE, BOX_SIZE); - canvas_draw_str(canvas, p->x + 8, p->y + 6, "R"); + canvas_draw_frame(canvas, p->x - p->size / 2, p->y - p->size / 2, BOX_SIZE, BOX_SIZE); + canvas_draw_str(canvas, p->x, p->y - BOX_SIZE / 2, "R"); break; case PowerUpTypeAssist: // Draw box with letter A inside - canvas_draw_frame(canvas, p->x, p->y, BOX_SIZE, BOX_SIZE); - canvas_draw_str(canvas, p->x + 8, p->y + 6, "A"); + canvas_draw_frame(canvas, p->x - p->size / 2, p->y - p->size / 2, BOX_SIZE, BOX_SIZE); + canvas_draw_str(canvas, p->x, p->y - BOX_SIZE / 2, "A"); break; default: //@todo Uknown Power Up Type Detected // Draw box with letter U inside canvas_draw_frame(canvas, p->x, p->y, BOX_SIZE, BOX_SIZE); - canvas_draw_str(canvas, p->x + 3, p->y + 3, "U"); + canvas_draw_str(canvas, p->x, p->y, "U"); FURI_LOG_E(TAG, "Unexpected Power Up Type Detected: %i", p->powerUpType); break; } @@ -438,14 +482,14 @@ bool objects_are_colliding(float x1, float y1, float r1, float x2, float y2, flo float rsum = r1 + r2; return dx * dx + dy * dy < rsum * rsum; } - +//@todo ship_fire_bullet /* Create a new bullet headed in the same direction of the ship. */ void ship_fire_bullet(AsteroidsApp* app) { // No power ups, only MAXBUL allowed - if(app->ship.isPowerUpActive == false && app->bullets_num == MAXBUL) return; + if(isPowerUpActive(app, PowerUpTypeFirePower) == false && app->bullets_num == MAXBUL) return; // Double the Fire Power - if((app->ship.powerUp == PowerUpTypeFirePower) && (app->bullets_num == MAXBUL * 2)) return; + if(isPowerUpActive(app, PowerUpTypeFirePower) && (app->bullets_num == (MAXBUL * 2))) return; notification_message(furi_record_open(RECORD_NOTIFICATION), &sequence_bullet_fired); Bullet* b = &app->bullets[app->bullets_num]; @@ -547,52 +591,95 @@ void asteroid_was_hit(AsteroidsApp* app, int id) { } } +//@todo Add PowerUp PowerUp* add_powerUp(AsteroidsApp* app) { if(app->powerUps_num == MAXPOWERUPS) return NULL; - float size = 4; + + // Randomly select power up for display + //@todo Random Power Up Select + // PowerUpType powerUpType = rand() % Number_of_PowerUps; + PowerUpType selected_powerUpType = PowerUpTypeFirePower; + + FURI_LOG_I(TAG, "[add_powerUp] Power Ups Active: %i", app->powerUps_num); + // Don't add already existing power ups + if(isPowerUpAlreadyExists(app, selected_powerUpType)) { + FURI_LOG_I(TAG, "[add_powerUp] Power Up %i already active", selected_powerUpType); + return NULL; + } + + float size = 10; float min_distance = 20; float x, y; do { x = rand() % SCREEN_XRES; y = rand() % SCREEN_YRES; } while(distance(app->ship.x, app->ship.y, x, y) < min_distance + size); + PowerUp* p = &app->powerUps[app->powerUps_num++]; p->x = x; p->y = y; - p->vx = 2 * (-.5 + ((float)rand() / RAND_MAX)); - p->vy = 2 * (-.5 + ((float)rand() / RAND_MAX)); + //@todo Disable Velocity + p->vx = 0; //2 * (-.5 + ((float)rand() / RAND_MAX)); + p->vy = 0; //2 * (-.5 + ((float)rand() / RAND_MAX)); + p->display_ttl = 500; + p->ttl = POWERUPSTTL; + p->size = (int)size; // p->size = size; // p->rot = 0; // p->rot_speed = ((float)rand() / RAND_MAX) / 10; // if(app->ticks & 1) p->rot_speed = -(p->rot_speed); - // p->shape_seed = rand() & 255; //@todo add powerup type, for now hardcoding to firepower - p->powerUpType = 3; //rand() % Number_of_PowerUps; + p->powerUpType = selected_powerUpType; + p->isPowerUpActive = false; return p; } +//@todo remove_powerUp void remove_powerUp(AsteroidsApp* app, int id) { /* Replace the top powerUp with the empty space left * by the removal of this one. This way we always take the * array dense, which is an advantage when looping. */ + int n = --app->powerUps_num; if(n && id != n) app->powerUps[id] = app->powerUps[n]; } +//@todo powerUp_was_hit void powerUp_was_hit(AsteroidsApp* app, int id) { PowerUp* p = &app->powerUps[id]; - remove_powerUp(app, id); + if(p->display_ttl == 0) return; // Don't collect if already collected + switch(p->powerUpType) { case PowerUpTypeLife: if(app->lives < GAME_START_LIVES) app->lives++; break; - case PowerUpTypeFirePower: - app->powerUps[id].powerUpType = PowerUpTypeFirePower; - break; + // case PowerUpTypeFirePower: + // app->powerUps[id].powerUpType = PowerUpTypeFirePower; + // break; default: break; } + p->display_ttl = 0; + p->isPowerUpActive = true; +} + +bool isPowerUpActive(AsteroidsApp* const app, PowerUpType const powerUpType) { + for(int i = 0; i < app->powerUps_num; i++) { + // PowerUp* p = &app->powerUps[i]; + // if(p->powerUpType == powerUpType && p->ttl > 0 && p->display_ttl == 0) return true; + if(app->powerUps[i].isPowerUpActive && app->powerUps[i].powerUpType == powerUpType) { + return true; + } + } + return false; +} + +bool isPowerUpAlreadyExists(AsteroidsApp* const app, PowerUpType const powerUpType) { + for(int i = 0; i < app->powerUps_num; i++) { + if(app->powerUps[i].powerUpType == powerUpType) return true; + } + return false; } /* Set gameover state. When in game-over mode, the game displays a gameover @@ -668,8 +755,27 @@ void update_asteroids_position(AsteroidsApp* app) { void update_powerUps_position(AsteroidsApp* app) { for(int j = 0; j < app->powerUps_num; j++) { - update_pos_by_velocity( - &app->powerUps[j].x, &app->powerUps[j].y, app->powerUps[j].vx, app->powerUps[j].vy); + // @todo update_powerUps_position + if(app->powerUps[j].display_ttl > 0) { + update_pos_by_velocity( + &app->powerUps[j].x, &app->powerUps[j].y, app->powerUps[j].vx, app->powerUps[j].vy); + } + } +} + +// @todo update_powerUp_status +/* This updates the state of each power up collected and removes them if they have expired. */ +void update_powerUp_status(AsteroidsApp* app) { + for(int j = app->powerUps_num; j > 0; j--) { + if(app->powerUps[j].ttl > 0 && app->powerUps[j].isPowerUpActive) { + // Only decrement ttl if we actually picked up power up + app->powerUps[j].ttl--; + } else if(app->powerUps[j].ttl == 0 && app->powerUps[j].display_ttl == 0) { + // we've reached the end of life of the power up + // Time to remove it + app->powerUps[j].isPowerUpActive = false; + remove_powerUp(app, j); + } } } @@ -743,7 +849,6 @@ void game_tick(void* ctx) { restart_game_after_gameover(app); } update_asteroids_position(app); - update_powerUps_position(app); view_port_update(app->view_port); return; } @@ -773,10 +878,23 @@ void game_tick(void* ctx) { app->fire = false; } + // DEBUG: Show Power Up Status + for(int j = 0; j < app->powerUps_num; j++) { + PowerUp* p = &app->powerUps[j]; + FURI_LOG_I( + TAG, + "Power Up Type: %d TTL: %lu Display_TTL: %lu PowerUpNum: %i", + p->powerUpType, + p->ttl, + p->display_ttl, + app->powerUps_num); + } + /* Update positions and detect collisions. */ update_pos_by_velocity(&app->ship.x, &app->ship.y, app->ship.vx, app->ship.vy); update_bullets_position(app); update_asteroids_position(app); + update_powerUp_status(app); //@todo update_powerUp_status update_powerUps_position(app); detect_collisions(app); @@ -788,7 +906,8 @@ void game_tick(void* ctx) { } /* From time to time add a random power up */ - if(app->powerUps_num == 0 || (random() % 5000) < (30 / (1 + app->powerUps_num))) { + //@todo game tick + if((app->powerUps_num == 0 || random() % 5000) < (30 / (1 + app->powerUps_num))) { add_powerUp(app); } @@ -913,8 +1032,8 @@ int32_t asteroids_app_entry(void* p) { while(app->running) { FuriStatus qstat = furi_message_queue_get(app->event_queue, &input, 100); if(qstat == FuriStatusOk) { - if(DEBUG_MSG) - FURI_LOG_E(TAG, "Main Loop - Input: type %d key %u", input.type, input.key); + // if(DEBUG_MSG) + // FURI_LOG_E(TAG, "Main Loop - Input: type %d key %u", input.type, input.key); /* Handle navigation here. Then handle view-specific inputs * in the view specific handling function. */ From cd76484d92bba9a74ba415a88e9af671b7f603bd Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Tue, 31 Jan 2023 19:47:50 -0500 Subject: [PATCH 27/75] Add images, update manifest --- application.fam | 3 ++- assets/ammo_10x10.png | Bin 0 -> 287 bytes assets/ammo_11x11.png | Bin 0 -> 378 bytes assets/heart_10x10.png | Bin 0 -> 281 bytes assets/heart_12x12.png | Bin 0 -> 299 bytes 5 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 assets/ammo_10x10.png create mode 100644 assets/ammo_11x11.png create mode 100644 assets/heart_10x10.png create mode 100644 assets/heart_12x12.png diff --git a/application.fam b/application.fam index 0a56122..d8a4131 100644 --- a/application.fam +++ b/application.fam @@ -5,8 +5,9 @@ App( entry_point="asteroids_app_entry", cdefines=["APP_PROTOVIEW"], requires=["gui"], - stack_size=8*1024, + stack_size=8 * 1024, order=50, fap_icon="appicon.png", fap_category="Games", + fap_icon_assets="assets", # Image assets to compile for this application ) diff --git a/assets/ammo_10x10.png b/assets/ammo_10x10.png new file mode 100644 index 0000000000000000000000000000000000000000..b112a1a7f288ac881808d7d104def1c790cb5734 GIT binary patch literal 287 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2V6Od#Ihk44ofy`glX(f`u%tWsIx;Y9 z?C1WI$O`0h7I;J!GcfQS24TkI`72U@f?GUY978mMm-gxkH5-Vu7zc<8w>vlrEJzBt zSh$y2yurCZAjP0SY*~}Chzi%i`#dkr&OBK4tFw0Z?@5&@vz8@F^cdFOcg{ENQx5aH zY*HF4?DWZ|KDuj>!y5f=vZ&O2% z)bWj*-~TR@Ilbw@@ol-UcO6n##J=Ox(p6e7E*H5!hPx#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0S`$;K~yMHZH}+2 zgHRZTk3Y%;^H$tYW^$}(6&F?)Z}h*gYFXL8APfwG#b{Zu53wmW8EnxcOQNFpW#@9? z!hOQa!~1=F=a6}xPp4BDhLC?D_xqg?qA1EVO~Wu;E*Ip_@B=xY&)5KUU0<(PNDu@V z^nKqn4TRlnHeVkYhKZsG8+Z}vx~^%O<2drFsveI=RH7)pUN6Y=`RuyR_x-kQZ?_w9 z90x7P^BfzG#{*ea6)io_$PQB5LVN)q9}NtUoMxrt|v)i7{+R~Vp+B<%iV7G Y4g5HkZgB`Q*8l(j07*qoM6N<$f=U*eX#fBK literal 0 HcmV?d00001 diff --git a/assets/heart_10x10.png b/assets/heart_10x10.png new file mode 100644 index 0000000000000000000000000000000000000000..0d66b49ee5db803016de0e530df9a19118dd140d GIT binary patch literal 281 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2V6Od#Ihk44ofy`glX(f`u%tWsIx;Y9 z?C1WI$O`0h7I;J!GcfQS24TkI`72U@g6lk8978mMQ~M3MS_}kS)61<_H*_e?I2O03 z>0WyNGs!P3VqA_+8v=`1nKO@F^x4?WFZ8e8If1DoW9{2rd9&0`v9PXE(R9B5Jy7J} z+3#v8lMWj=goZA(U-|l1u}u5-c}MNf?JU2&?T(y@FZ1nfqOJ!Yv1>lv_x}2`V>4{d zN8VqOxl8Bt)}LQRUDlRPOHG`n(ix;xAt(IV=6In_i^TDXqK~@$DqPmQ_9~B@wvg!n Z=cnde%Ukb`P6oQ1!PC{xWt~$(695hWY+C>T literal 0 HcmV?d00001 diff --git a/assets/heart_12x12.png b/assets/heart_12x12.png new file mode 100644 index 0000000000000000000000000000000000000000..b1cfdcdfe6936d2524eb859f780ad8b47a27e74f GIT binary patch literal 299 zcmeAS@N?(olHy`uVBq!ia0vp^JRr=$1SD^YpWXnZ7>k44ofy`glX(f`u%tWsIx;Y9 z?C1WI$O`0h7I;J!GcfQS24TkI`72U@f(JZZ978mMOD8yTH5&-HE{`pp+dDza@rY}O zc;WJNfj#N@58?y`1@Ek27kHDBrs4F_u_^x<`;)_-TXJukoGp}D^P}-rsjPO+?P<>~ z1p-BCI}CU#o3wcxLPOu2=@w9YwX02m<4E3xD0{(;(lv{8yf;dBE&5>pZqDR`@{!Zt z{(h$&G3{uS_G9kMS?4~#(O#f*E_2o-m5Hi}J(6vW+l8Et74|%yAsi8L|NEvLZ31h4 r`2N|ICRg#pbn`mxdtRDh{0GGIA5Z=te Date: Tue, 31 Jan 2023 19:48:06 -0500 Subject: [PATCH 28/75] use image assets, add Lives Power up --- app.c | 55 ++++++++++++++++++++----------------------------------- 1 file changed, 20 insertions(+), 35 deletions(-) diff --git a/app.c b/app.c index f97591e..e624800 100644 --- a/app.c +++ b/app.c @@ -13,6 +13,7 @@ #include #include #include +#include #define TAG "Asteroids" // Used for logging #define DEBUG_MSG 1 @@ -308,60 +309,40 @@ void draw_powerUps(Canvas* const canvas, PowerUp* const p) { //@todo render_callback // Just return if power up has already been picked up - FURI_LOG_I(TAG, "[draw_powerUps] Display TTL: %lu", p->display_ttl); + // FURI_LOG_I(TAG, "[draw_powerUps] Display TTL: %lu", p->display_ttl); if(p->display_ttl == 0) return; canvas_set_color(canvas, ColorXOR); - int BOX_SIZE = p->size * 2; switch(p->powerUpType) { case PowerUpTypeFirePower: - // Draw box with letter F inside - FURI_LOG_D( - TAG, - "[draw_powerUps] p->size: %i x:%i y:%i BOX_SIZE: %i", - p->size, - abs((int)p->x - (int)(p->size / 2)), - abs((int)p->y - (int)(p->size / 2)), - BOX_SIZE); - canvas_draw_frame( - canvas, - abs((int)p->x - (int)(p->size / 2)), - abs((int)p->y - (int)(p->size / 2)), - BOX_SIZE, - BOX_SIZE); - canvas_draw_str(canvas, p->x, p->y, "F"); + canvas_draw_icon(canvas, p->x, p->y, &I_ammo_11x11); break; case PowerUpTypeShield: // Draw box with letter S inside - canvas_draw_frame(canvas, p->x - p->size / 2, p->y - p->size / 2, BOX_SIZE, BOX_SIZE); - canvas_draw_str(canvas, p->x, p->y - BOX_SIZE / 2, "S"); + canvas_draw_str(canvas, p->x, p->y, "S"); break; case PowerUpTypeLife: - // Draw box with letter L inside - canvas_draw_frame(canvas, p->x - p->size / 2, p->y - p->size / 2, BOX_SIZE, BOX_SIZE); - canvas_draw_str(canvas, p->x, p->y - BOX_SIZE / 2, "L"); + // Draw a heart + canvas_draw_icon(canvas, p->x, p->y, &I_heart_10x10); break; case PowerUpTypeNuke: // Draw box with letter N inside - canvas_draw_frame(canvas, p->x - p->size / 2, p->y - p->size / 2, BOX_SIZE, BOX_SIZE); - canvas_draw_str(canvas, p->x, p->y - BOX_SIZE / 2, "N"); + // canvas_draw_disc(canvas, p->x, p->y, p->size); + canvas_draw_str(canvas, p->x, p->y, "N"); break; case PowerUpTypeRadialFire: // Draw box with letter R inside - canvas_draw_frame(canvas, p->x - p->size / 2, p->y - p->size / 2, BOX_SIZE, BOX_SIZE); - canvas_draw_str(canvas, p->x, p->y - BOX_SIZE / 2, "R"); + canvas_draw_str(canvas, p->x, p->y, "R"); break; case PowerUpTypeAssist: // Draw box with letter A inside - canvas_draw_frame(canvas, p->x - p->size / 2, p->y - p->size / 2, BOX_SIZE, BOX_SIZE); - canvas_draw_str(canvas, p->x, p->y - BOX_SIZE / 2, "A"); + canvas_draw_str(canvas, p->x, p->y, "A"); break; default: //@todo Uknown Power Up Type Detected // Draw box with letter U inside - canvas_draw_frame(canvas, p->x, p->y, BOX_SIZE, BOX_SIZE); - canvas_draw_str(canvas, p->x, p->y, "U"); + canvas_draw_str(canvas, p->x, p->y, "?"); FURI_LOG_E(TAG, "Unexpected Power Up Type Detected: %i", p->powerUpType); break; } @@ -597,8 +578,9 @@ PowerUp* add_powerUp(AsteroidsApp* app) { // Randomly select power up for display //@todo Random Power Up Select - // PowerUpType powerUpType = rand() % Number_of_PowerUps; - PowerUpType selected_powerUpType = PowerUpTypeFirePower; + PowerUpType selected_powerUpType = rand() % Number_of_PowerUps; + // PowerUpType selected_powerUpType = PowerUpTypeFirePower; + // PowerUpType selected_powerUpType = PowerUpTypeLife; FURI_LOG_I(TAG, "[add_powerUp] Power Ups Active: %i", app->powerUps_num); // Don't add already existing power ups @@ -611,8 +593,10 @@ PowerUp* add_powerUp(AsteroidsApp* app) { float min_distance = 20; float x, y; do { - x = rand() % SCREEN_XRES; - y = rand() % SCREEN_YRES; + //size*2 to make sure power up is not spawned on the edge of the screen + //It also keeps it away from the lives and score at the top of screen + x = rand() % (SCREEN_XRES - (int)size * 2); + y = rand() % (SCREEN_YRES - (int)size * 2); } while(distance(app->ship.x, app->ship.y, x, y) < min_distance + size); PowerUp* p = &app->powerUps[app->powerUps_num++]; @@ -652,7 +636,8 @@ void powerUp_was_hit(AsteroidsApp* app, int id) { switch(p->powerUpType) { case PowerUpTypeLife: - if(app->lives < GAME_START_LIVES) app->lives++; + if(app->lives <= GAME_START_LIVES) app->lives++; + remove_powerUp(app, id); break; // case PowerUpTypeFirePower: // app->powerUps[id].powerUpType = PowerUpTypeFirePower; From 29863ada54077e20ab84d93477c85202451a36f7 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Tue, 31 Jan 2023 22:45:24 -0500 Subject: [PATCH 29/75] improved PowerUpTypeFirePower --- app.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/app.c b/app.c index e624800..ad6ee0d 100644 --- a/app.c +++ b/app.c @@ -20,12 +20,13 @@ #define SCREEN_XRES 128 #define SCREEN_YRES 64 #define GAME_START_LIVES 3 +#define MAXLIVES 8 /* Max lives allowed. */ #define TTLBUL 30 /* Bullet time to live, in ticks. */ -#define MAXBUL 5 /* Max bullets on the screen. */ +#define MAXBUL 50 /* Max bullets on the screen. */ //@todo MAX Asteroids #define MAXAST 0 //32 /* Max asteroids on the screen. */ #define MAXPOWERUPS 3 /* Max powerups allowed on screen */ -#define POWERUPSTTL 10 * 1000 /* Max powerup time to live, in ticks. */ +#define POWERUPSTTL 100 /* Max powerup time to live, in ticks. */ #define SHIP_HIT_ANIMATION_LEN 15 #define SAVING_DIRECTORY "/ext/apps/Games" #define SAVING_FILENAME SAVING_DIRECTORY "/game_asteroids.save" @@ -106,9 +107,10 @@ typedef struct AsteroidsApp { int powerUps_num; /* Active powerups. */ /* Bullets state. */ - struct Bullet bullets[MAXBUL * 2]; /* Each bullet state. */ + struct Bullet bullets[MAXBUL]; /* Each bullet state. */ int bullets_num; /* Active bullets. */ uint32_t last_bullet_tick; /* Tick the last bullet was fired. */ + uint32_t bullet_min_period; /* Minimum time between bullets in ms. */ /* Asteroids state. */ Asteroid asteroids[MAXAST]; /* Each asteroid state. */ @@ -466,11 +468,11 @@ bool objects_are_colliding(float x1, float y1, float r1, float x2, float y2, flo //@todo ship_fire_bullet /* Create a new bullet headed in the same direction of the ship. */ void ship_fire_bullet(AsteroidsApp* app) { - // No power ups, only MAXBUL allowed - if(isPowerUpActive(app, PowerUpTypeFirePower) == false && app->bullets_num == MAXBUL) return; + // No power ups, only 5 bullets allowed + if(isPowerUpActive(app, PowerUpTypeFirePower) == false && app->bullets_num >= 5) return; // Double the Fire Power - if(isPowerUpActive(app, PowerUpTypeFirePower) && (app->bullets_num == (MAXBUL * 2))) return; + if(isPowerUpActive(app, PowerUpTypeFirePower) && (app->bullets_num == (MAXBUL))) return; notification_message(furi_record_open(RECORD_NOTIFICATION), &sequence_bullet_fired); Bullet* b = &app->bullets[app->bullets_num]; @@ -597,7 +599,7 @@ PowerUp* add_powerUp(AsteroidsApp* app) { //It also keeps it away from the lives and score at the top of screen x = rand() % (SCREEN_XRES - (int)size * 2); y = rand() % (SCREEN_YRES - (int)size * 2); - } while(distance(app->ship.x, app->ship.y, x, y) < min_distance + size); + } while(distance(app->ship.x, app->ship.y, (float)x, (float)y) < min_distance + size); PowerUp* p = &app->powerUps[app->powerUps_num++]; p->x = x; @@ -606,7 +608,7 @@ PowerUp* add_powerUp(AsteroidsApp* app) { p->vx = 0; //2 * (-.5 + ((float)rand() / RAND_MAX)); p->vy = 0; //2 * (-.5 + ((float)rand() / RAND_MAX)); p->display_ttl = 500; - p->ttl = POWERUPSTTL; + p->ttl = POWERUPSTTL / 2; p->size = (int)size; // p->size = size; // p->rot = 0; @@ -621,10 +623,14 @@ PowerUp* add_powerUp(AsteroidsApp* app) { //@todo remove_powerUp void remove_powerUp(AsteroidsApp* app, int id) { + // TODO: Break this out into object types that set the game state + if(app->powerUps[id].powerUpType == PowerUpTypeFirePower) { + app->bullet_min_period = 200; + } + /* Replace the top powerUp with the empty space left * by the removal of this one. This way we always take the * array dense, which is an advantage when looping. */ - int n = --app->powerUps_num; if(n && id != n) app->powerUps[id] = app->powerUps[n]; } @@ -636,12 +642,12 @@ void powerUp_was_hit(AsteroidsApp* app, int id) { switch(p->powerUpType) { case PowerUpTypeLife: - if(app->lives <= GAME_START_LIVES) app->lives++; + if(app->lives < MAXLIVES) app->lives++; remove_powerUp(app, id); break; - // case PowerUpTypeFirePower: - // app->powerUps[id].powerUpType = PowerUpTypeFirePower; - // break; + case PowerUpTypeFirePower: + app->bullet_min_period = 100; + break; default: break; } @@ -697,6 +703,7 @@ void restart_game(AsteroidsApp* app) { app->bullets_num = 0; app->powerUps_num = 0; app->last_bullet_tick = 0; + app->bullet_min_period = 200; app->asteroids_num = 0; app->ship_hit = 0; } @@ -854,9 +861,8 @@ void game_tick(void* ctx) { * asteroids_update_keypress_state() since depends on exact * pressure timing. */ if(app->fire) { - uint32_t bullet_min_period = 200; // In milliseconds uint32_t now = furi_get_tick(); - if(now - app->last_bullet_tick >= bullet_min_period) { + if(now - app->last_bullet_tick >= app->bullet_min_period) { ship_fire_bullet(app); app->last_bullet_tick = now; } From 11bc81ed70a1d58332f4e0c115f0f4ebbcd2281a Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 1 Feb 2023 00:25:28 -0500 Subject: [PATCH 30/75] add PowerUpShieldType --- app.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/app.c b/app.c index ad6ee0d..41a0679 100644 --- a/app.c +++ b/app.c @@ -26,7 +26,7 @@ //@todo MAX Asteroids #define MAXAST 0 //32 /* Max asteroids on the screen. */ #define MAXPOWERUPS 3 /* Max powerups allowed on screen */ -#define POWERUPSTTL 100 /* Max powerup time to live, in ticks. */ +#define POWERUPSTTL 400 /* Max powerup time to live, in ticks. */ #define SHIP_HIT_ANIMATION_LEN 15 #define SAVING_DIRECTORY "/ext/apps/Games" #define SAVING_FILENAME SAVING_DIRECTORY "/game_asteroids.save" @@ -36,7 +36,6 @@ /* ============================ Data structures ============================= */ typedef enum PowerUpType { - // PowerUpTypeNone, // No powerup PowerUpTypeShield, // Shield PowerUpTypeLife, // Extra life PowerUpTypeFirePower, // Burst Fire power @@ -316,22 +315,22 @@ void draw_powerUps(Canvas* const canvas, PowerUp* const p) { canvas_set_color(canvas, ColorXOR); + // Display power up to be picked up switch(p->powerUpType) { case PowerUpTypeFirePower: canvas_draw_icon(canvas, p->x, p->y, &I_ammo_11x11); break; case PowerUpTypeShield: - // Draw box with letter S inside - canvas_draw_str(canvas, p->x, p->y, "S"); + canvas_draw_icon(canvas, p->x, p->y, &I_split_shield_10x10); break; case PowerUpTypeLife: // Draw a heart canvas_draw_icon(canvas, p->x, p->y, &I_heart_10x10); break; case PowerUpTypeNuke: - // Draw box with letter N inside // canvas_draw_disc(canvas, p->x, p->y, p->size); - canvas_draw_str(canvas, p->x, p->y, "N"); + // canvas_draw_str(canvas, p->x, p->y, "N"); + canvas_draw_icon(canvas, p->x, p->y, &I_nuke_10x10); break; case PowerUpTypeRadialFire: // Draw box with letter R inside @@ -341,6 +340,10 @@ void draw_powerUps(Canvas* const canvas, PowerUp* const p) { // Draw box with letter A inside canvas_draw_str(canvas, p->x, p->y, "A"); break; + case PowerUpTypeClone: + // Draw box with letter C inside + canvas_draw_str(canvas, p->x, p->y, "C"); + break; default: //@todo Uknown Power Up Type Detected // Draw box with letter U inside @@ -350,6 +353,14 @@ void draw_powerUps(Canvas* const canvas, PowerUp* const p) { } } +void draw_shield(Canvas* const canvas, AsteroidsApp* app) { + if(isPowerUpActive(app, PowerUpTypeShield) == false) return; + + canvas_set_color(canvas, ColorXOR); + // canvas_draw_disc(canvas, app->ship.x, app->ship.y, 4); + canvas_draw_circle(canvas, app->ship.x, app->ship.y, 10); +} + /* Given the current position, update it according to the velocity and * wrap it back to the other side if the object went over the screen. */ void update_pos_by_velocity(float* x, float* y, float vx, float vy) { @@ -387,6 +398,9 @@ void render_callback(Canvas* const canvas, void* ctx) { /* Draw ship, asteroids, bullets. */ draw_poly(canvas, &ShipPoly, app->ship.x, app->ship.y, app->ship.rot); + /* Draw shield if active. */ + draw_shield(canvas, app); + if(key_pressed_time(app, InputKeyUp) > 0) { notification_message(furi_record_open(RECORD_NOTIFICATION), &sequence_thrusters); draw_poly(canvas, &ShipFirePoly, app->ship.x, app->ship.y, app->ship.rot); @@ -597,8 +611,8 @@ PowerUp* add_powerUp(AsteroidsApp* app) { do { //size*2 to make sure power up is not spawned on the edge of the screen //It also keeps it away from the lives and score at the top of screen - x = rand() % (SCREEN_XRES - (int)size * 2); - y = rand() % (SCREEN_YRES - (int)size * 2); + x = rand() % (SCREEN_XRES - (int)size); + y = rand() % (SCREEN_YRES - (int)size); } while(distance(app->ship.x, app->ship.y, (float)x, (float)y) < min_distance + size); PowerUp* p = &app->powerUps[app->powerUps_num++]; @@ -608,7 +622,7 @@ PowerUp* add_powerUp(AsteroidsApp* app) { p->vx = 0; //2 * (-.5 + ((float)rand() / RAND_MAX)); p->vy = 0; //2 * (-.5 + ((float)rand() / RAND_MAX)); p->display_ttl = 500; - p->ttl = POWERUPSTTL / 2; + p->ttl = POWERUPSTTL; p->size = (int)size; // p->size = size; // p->rot = 0; @@ -646,6 +660,7 @@ void powerUp_was_hit(AsteroidsApp* app, int id) { remove_powerUp(app, id); break; case PowerUpTypeFirePower: + p->ttl = POWERUPSTTL / 2; app->bullet_min_period = 100; break; default: @@ -795,7 +810,13 @@ void detect_collisions(AsteroidsApp* app) { for(int j = 0; j < app->asteroids_num; j++) { Asteroid* a = &app->asteroids[j]; if(objects_are_colliding(a->x, a->y, a->size, app->ship.x, app->ship.y, 4, 1)) { - ship_was_hit(app); + if(isPowerUpActive(app, PowerUpTypeShield)) { + // Asteroid was hit with shield + asteroid_was_hit(app, j); + } else { + // No sheild active, take damage + ship_was_hit(app); + } break; } } From 4e1d1cb2e5de00900d27951a70c77f9c2a763c80 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 1 Feb 2023 00:26:24 -0500 Subject: [PATCH 31/75] Update assets: add nuke and split shield --- assets/nuke_10x10.png | Bin 0 -> 300 bytes assets/split_shield_10x10.png | Bin 0 -> 299 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 assets/nuke_10x10.png create mode 100644 assets/split_shield_10x10.png diff --git a/assets/nuke_10x10.png b/assets/nuke_10x10.png new file mode 100644 index 0000000000000000000000000000000000000000..8b49fc98e3f120156e73261c4128b3a47154b1b8 GIT binary patch literal 300 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2V6Od#Ihk44ofy`glX(f`u%tWsIx;Y9 z?C1WI$O`0h7I;J!GcfQS24TkI`72U@f(Jca978mMefxd+Tn$88Z%avZi2mp_a7|+F zZ7iK}dz$D5wxld(wIs&2mbUVFw{705_@4XgmtTD9o%?5--}~l2uM8BK_dHSMT%kmA zX)OO?hW+cZr=|8io|4MBZu{?j{+F+q_$s={9GB>PEwO6VtLnLi621Q(YjkPw9S&F= zzh;UNPjk|q`g!VwjxQ|ut|;c;{`^z(5?c$5`l4NO2jm)o!72h^l<>8$E s$2)Ym>lpuqW#7J5d&Q*J?fYNGH7ggHdEYX>2J{Srr>mdKI;Vst0AQDN>i_@% literal 0 HcmV?d00001 diff --git a/assets/split_shield_10x10.png b/assets/split_shield_10x10.png new file mode 100644 index 0000000000000000000000000000000000000000..bff879ca1a04c302abab84da10f4feb86029cdba GIT binary patch literal 299 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2V6Od#Ihk44ofy`glX(f`u%tWsIx;Y9 z?C1WI$O`0h7I;J!GcfQS24TkI`72U@f(JZZ978mML;DQ*S`-9aJEf*NN30h!yH>!F zwc(?dncBQV$1VxqxaGNM>QeO&ENZXBZ}@&wRWbg5(BO%g%<+rc-X3pYT6^~7zW1S_ zfnJ>p*S%Kpyr9&g6y&9?Q&BkYxdBh)G|i=Z40z`L6k=%WD t)!x5-C)1!WdERr^K%dJ`7X7Yc`0%-@@7TkcK#wvoc)I$ztaD0e0syXgc%lFR literal 0 HcmV?d00001 From c88ab5b653e3a8a9f4754dc6468f884c92263a9c Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 1 Feb 2023 10:52:34 -0500 Subject: [PATCH 32/75] improvd firepower asset --- assets/firepower_12x12.png | Bin 0 -> 294 bytes assets/firepower_9x10.png | Bin 0 -> 123 bytes assets/firepower_shifted_9x10.png | Bin 0 -> 137 bytes 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 assets/firepower_12x12.png create mode 100644 assets/firepower_9x10.png create mode 100644 assets/firepower_shifted_9x10.png diff --git a/assets/firepower_12x12.png b/assets/firepower_12x12.png new file mode 100644 index 0000000000000000000000000000000000000000..711a2920056943cd57c7968abd4d5f7fa12ce077 GIT binary patch literal 294 zcmeAS@N?(olHy`uVBq!ia0vp^JRr=$1SD^YpWXnZ7>k44ofy`glX(f`u%tWsIx;Y9 z?C1WI$O`0h7I;J!GcfQS24TkI`72U@g1bFk978mM*G^F6YcUXUi8lMu=3LMzmB+OF z0oT+WS$P2>Os#4XB8;KUiX1!wB4^&+Z@3-1G5OcB$v(@T9xvRGUv%%eyX9w_?6qsR zJ~_SV%%(SwOnm2yv^{*?_O*8X6eYJXkyZgF8P|)8Go`p}&aZyG>$TN~ZMo}SKda=+ zyZ!CnmUXX9e2@IzmwfD~J@4~l5=!^KA1_?Ow5D<0^*ddUBfLCiSQvE-k4#okbh^Ar n=deLTAaiu6sO$eS3j3^P6?5+B|ZQE literal 0 HcmV?d00001 diff --git a/assets/firepower_shifted_9x10.png b/assets/firepower_shifted_9x10.png new file mode 100644 index 0000000000000000000000000000000000000000..9c8506d1810658e72926cfaaeb98e62085288060 GIT binary patch literal 137 zcmeAS@N?(olHy`uVBq!ia0vp^oIuRQ!3HGLSWET+DaPU;cPEB*=VV?2InJIgjv*Ss zM*|%B7!){~{@c%5cG<1$g@n0afs>~ar{|1}c@A${eWx6JE>h_vJ;!>|vz=x!O8&nz jtLmn!iY}VnHhnh(Gk3^uK9<8Evl%>H{an^LB{Ts5Z%rxA literal 0 HcmV?d00001 From 6ecb58f0d0a66e5faa589176c9a9b3c4d6c5cc31 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 1 Feb 2023 10:53:16 -0500 Subject: [PATCH 33/75] add nuke, fix firepower bug --- app.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 90 insertions(+), 5 deletions(-) diff --git a/app.c b/app.c index 41a0679..e442b17 100644 --- a/app.c +++ b/app.c @@ -24,7 +24,7 @@ #define TTLBUL 30 /* Bullet time to live, in ticks. */ #define MAXBUL 50 /* Max bullets on the screen. */ //@todo MAX Asteroids -#define MAXAST 0 //32 /* Max asteroids on the screen. */ +#define MAXAST 32 /* Max asteroids on the screen. */ #define MAXPOWERUPS 3 /* Max powerups allowed on screen */ #define POWERUPSTTL 400 /* Max powerup time to live, in ticks. */ #define SHIP_HIT_ANIMATION_LEN 15 @@ -165,6 +165,74 @@ const NotificationSequence sequence_bullet_fired = { NULL, }; +const NotificationSequence sequence_nuke = { + &message_red_255, + &message_vibro_on, + // &message_note_g5, // Play sound but currently disabled + &message_delay_250, + &message_red_0, + &message_vibro_off, + + &message_red_255, + &message_vibro_on, + // &message_note_g5, // Play sound but currently disabled + &message_delay_250, + &message_red_0, + &message_vibro_off, + + &message_vibro_on, + &message_red_255, + &message_delay_100, + &message_red_0, + &message_vibro_off, + &message_delay_1, + &message_delay_1, + &message_vibro_on, + &message_red_255, + &message_delay_100, + &message_red_0, + &message_vibro_off, + + &message_delay_1, + &message_delay_1, + &message_delay_1, + &message_vibro_on, + &message_red_255, + &message_delay_100, + &message_red_0, + &message_vibro_off, + + &message_delay_1, + &message_delay_1, + &message_delay_1, + &message_vibro_on, + &message_delay_1, + &message_delay_1, + &message_delay_1, + &message_delay_1, + &message_delay_1, + &message_red_0, + &message_vibro_off, + + &message_delay_1, + &message_delay_1, + &message_vibro_on, + &message_delay_1, + &message_delay_1, + &message_delay_1, + &message_red_0, + &message_vibro_off, + + &message_delay_1, + &message_vibro_on, + &message_delay_1, + &message_delay_1, + &message_red_0, + &message_vibro_off, + &message_sound_off, + NULL, +}; + /* ============================== Prototyeps ================================ */ // Only functions called before their definition are here. @@ -318,7 +386,7 @@ void draw_powerUps(Canvas* const canvas, PowerUp* const p) { // Display power up to be picked up switch(p->powerUpType) { case PowerUpTypeFirePower: - canvas_draw_icon(canvas, p->x, p->y, &I_ammo_11x11); + canvas_draw_icon(canvas, p->x, p->y, &I_firepower_shifted_9x10); break; case PowerUpTypeShield: canvas_draw_icon(canvas, p->x, p->y, &I_split_shield_10x10); @@ -486,7 +554,7 @@ void ship_fire_bullet(AsteroidsApp* app) { if(isPowerUpActive(app, PowerUpTypeFirePower) == false && app->bullets_num >= 5) return; // Double the Fire Power - if(isPowerUpActive(app, PowerUpTypeFirePower) && (app->bullets_num == (MAXBUL))) return; + if(isPowerUpActive(app, PowerUpTypeFirePower) && (app->bullets_num >= (MAXBUL))) return; notification_message(furi_record_open(RECORD_NOTIFICATION), &sequence_bullet_fired); Bullet* b = &app->bullets[app->bullets_num]; @@ -594,9 +662,10 @@ PowerUp* add_powerUp(AsteroidsApp* app) { // Randomly select power up for display //@todo Random Power Up Select - PowerUpType selected_powerUpType = rand() % Number_of_PowerUps; - // PowerUpType selected_powerUpType = PowerUpTypeFirePower; + // PowerUpType selected_powerUpType = rand() % Number_of_PowerUps; + PowerUpType selected_powerUpType = PowerUpTypeFirePower; // PowerUpType selected_powerUpType = PowerUpTypeLife; + // PowerUpType selected_powerUpType = PowerUpTypeNuke; FURI_LOG_I(TAG, "[add_powerUp] Power Ups Active: %i", app->powerUps_num); // Don't add already existing power ups @@ -637,6 +706,9 @@ PowerUp* add_powerUp(AsteroidsApp* app) { //@todo remove_powerUp void remove_powerUp(AsteroidsApp* app, int id) { + // Invalid ID, ignore + if(id <= 0) return; + // TODO: Break this out into object types that set the game state if(app->powerUps[id].powerUpType == PowerUpTypeFirePower) { app->bullet_min_period = 200; @@ -649,6 +721,12 @@ void remove_powerUp(AsteroidsApp* app, int id) { if(n && id != n) app->powerUps[id] = app->powerUps[n]; } +void remove_all_astroids_and_bullets(AsteroidsApp* app) { + app->score += app->asteroids_num; + app->asteroids_num = 0; + app->bullets_num = 0; +} + //@todo powerUp_was_hit void powerUp_was_hit(AsteroidsApp* app, int id) { PowerUp* p = &app->powerUps[id]; @@ -663,6 +741,11 @@ void powerUp_was_hit(AsteroidsApp* app, int id) { p->ttl = POWERUPSTTL / 2; app->bullet_min_period = 100; break; + case PowerUpTypeNuke: + //TODO: Animate explosion + notification_message(furi_record_open(RECORD_NOTIFICATION), &sequence_nuke); + remove_all_astroids_and_bullets(app); + break; default: break; } @@ -812,6 +895,8 @@ void detect_collisions(AsteroidsApp* app) { if(objects_are_colliding(a->x, a->y, a->size, app->ship.x, app->ship.y, 4, 1)) { if(isPowerUpActive(app, PowerUpTypeShield)) { // Asteroid was hit with shield + notification_message( + furi_record_open(RECORD_NOTIFICATION), &sequence_bullet_fired); asteroid_was_hit(app, j); } else { // No sheild active, take damage From e52246b083469fd6154a52f0d16ef54fddcafc8b Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 1 Feb 2023 10:57:02 -0500 Subject: [PATCH 34/75] Re-enable random power up --- app.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app.c b/app.c index e442b17..94da718 100644 --- a/app.c +++ b/app.c @@ -662,8 +662,8 @@ PowerUp* add_powerUp(AsteroidsApp* app) { // Randomly select power up for display //@todo Random Power Up Select - // PowerUpType selected_powerUpType = rand() % Number_of_PowerUps; - PowerUpType selected_powerUpType = PowerUpTypeFirePower; + PowerUpType selected_powerUpType = rand() % Number_of_PowerUps; + // PowerUpType selected_powerUpType = PowerUpTypeFirePower; // PowerUpType selected_powerUpType = PowerUpTypeLife; // PowerUpType selected_powerUpType = PowerUpTypeNuke; From 520178787bc6ae20018bfb9f8a7a96717187eb93 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 1 Feb 2023 11:19:06 -0500 Subject: [PATCH 35/75] shield artwork update --- app.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app.c b/app.c index 94da718..b36047e 100644 --- a/app.c +++ b/app.c @@ -389,7 +389,7 @@ void draw_powerUps(Canvas* const canvas, PowerUp* const p) { canvas_draw_icon(canvas, p->x, p->y, &I_firepower_shifted_9x10); break; case PowerUpTypeShield: - canvas_draw_icon(canvas, p->x, p->y, &I_split_shield_10x10); + canvas_draw_icon(canvas, p->x, p->y, &I_shield_frame); break; case PowerUpTypeLife: // Draw a heart @@ -666,6 +666,7 @@ PowerUp* add_powerUp(AsteroidsApp* app) { // PowerUpType selected_powerUpType = PowerUpTypeFirePower; // PowerUpType selected_powerUpType = PowerUpTypeLife; // PowerUpType selected_powerUpType = PowerUpTypeNuke; + // PowerUpType selected_powerUpType = PowerUpTypeShield; FURI_LOG_I(TAG, "[add_powerUp] Power Ups Active: %i", app->powerUps_num); // Don't add already existing power ups From 44da826e3445e217df1c0f39bc9248fa4bd61080 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 1 Feb 2023 11:19:21 -0500 Subject: [PATCH 36/75] shield artwork --- assets/shield-frame.png | Bin 0 -> 320 bytes assets/shield_clean.png | Bin 0 -> 203 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 assets/shield-frame.png create mode 100644 assets/shield_clean.png diff --git a/assets/shield-frame.png b/assets/shield-frame.png new file mode 100644 index 0000000000000000000000000000000000000000..60a670f0ee7d8b11d3ad8be0081db239185a316f GIT binary patch literal 320 zcmV-G0l)rPx#`bk7VR47w*kg={sKomvy2+{isohT)KLZ`j_fJP%KomMBJ&?psZjfhS{rSt=$ zl?di$<~}d?74IZd?0wdpJ#z@9lmfuEZOHQ+S(Y&g*LCrFy`U%x*JN218buMxvc$gc z++;dUQ>^O>+qMygAqejPeCksyOfrb*kj{eZ(Tz%UFP$H8F+ z3W7jnS*Cs8L)Y~W$eKk_@V#Bv#n&c^B4r+14>ul=iKc1bc^)K5LXspr<*7F;Sbe4G SPb$Fx0000f4F%}28J29*~C-V}>Y4vn*4ABVg zop76rMUkV;lx1Q2i@);gelMEb{7&lZ0iD~vKYstLb`TV_kW-5KGJ#RH$IwYL)mc;Z zgyrmIu57!yrL&WI7+qNI%j|24Tk^pF`2GW1r)}R-Z=Lnka(VL)!QA_MO^uzi&su3o zI60(Ei&~v2eZ^t>oZ?x2E|;qBi|=cE&T+mu{+?&f^YqJ?g@F!Y@O1TaS?83{1OVz6 BO`8A! literal 0 HcmV?d00001 From 97f08666aff219415ace49ca0456dcc1d0ab8811 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 1 Feb 2023 12:13:42 -0500 Subject: [PATCH 37/75] flashing powerups when expiring --- app.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app.c b/app.c index b36047e..0ee1c99 100644 --- a/app.c +++ b/app.c @@ -351,6 +351,18 @@ void draw_left_lives(Canvas* const canvas, AsteroidsApp* app) { } } +bool should_draw_powerUp(PowerUp* const p) { + // Just return if power up has already been picked up + if(p->display_ttl == 0) return false; + + // Begin flashing power up when it is about to expire + if(p->display_ttl < 100) { + return p->display_ttl % 8 > 0; + } + + return true; +} + void draw_powerUps(Canvas* const canvas, PowerUp* const p) { /* @@ -380,6 +392,7 @@ void draw_powerUps(Canvas* const canvas, PowerUp* const p) { // Just return if power up has already been picked up // FURI_LOG_I(TAG, "[draw_powerUps] Display TTL: %lu", p->display_ttl); if(p->display_ttl == 0) return; + if(!should_draw_powerUp(p)) return; canvas_set_color(canvas, ColorXOR); @@ -691,7 +704,7 @@ PowerUp* add_powerUp(AsteroidsApp* app) { //@todo Disable Velocity p->vx = 0; //2 * (-.5 + ((float)rand() / RAND_MAX)); p->vy = 0; //2 * (-.5 + ((float)rand() / RAND_MAX)); - p->display_ttl = 500; + p->display_ttl = 200; p->ttl = POWERUPSTTL; p->size = (int)size; // p->size = size; @@ -866,6 +879,8 @@ void update_powerUp_status(AsteroidsApp* app) { // Time to remove it app->powerUps[j].isPowerUpActive = false; remove_powerUp(app, j); + } else if(app->powerUps[j].display_ttl > 0) { + app->powerUps[j].display_ttl--; } } } From fb1f116a6f5bc2d02c7365ff3c5795ea79589b13 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 1 Feb 2023 12:37:19 -0500 Subject: [PATCH 38/75] bugfix towards power up system add/remove --- app.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app.c b/app.c index 0ee1c99..55c415a 100644 --- a/app.c +++ b/app.c @@ -721,7 +721,7 @@ PowerUp* add_powerUp(AsteroidsApp* app) { //@todo remove_powerUp void remove_powerUp(AsteroidsApp* app, int id) { // Invalid ID, ignore - if(id <= 0) return; + if(id < 0) return; // TODO: Break this out into object types that set the game state if(app->powerUps[id].powerUpType == PowerUpTypeFirePower) { @@ -879,6 +879,8 @@ void update_powerUp_status(AsteroidsApp* app) { // Time to remove it app->powerUps[j].isPowerUpActive = false; remove_powerUp(app, j); + j--; /* Process this power up index again: the removal will + fill it with the top power up to take the array dense. */ } else if(app->powerUps[j].display_ttl > 0) { app->powerUps[j].display_ttl--; } From 1af018af19a62b6b4bcd2f7d66b3827b4749c401 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 1 Feb 2023 22:42:17 -0500 Subject: [PATCH 39/75] bugfix: power up off by one index --- app.c | 96 +++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 73 insertions(+), 23 deletions(-) diff --git a/app.c b/app.c index 55c415a..dbd1bec 100644 --- a/app.c +++ b/app.c @@ -24,7 +24,7 @@ #define TTLBUL 30 /* Bullet time to live, in ticks. */ #define MAXBUL 50 /* Max bullets on the screen. */ //@todo MAX Asteroids -#define MAXAST 32 /* Max asteroids on the screen. */ +#define MAXAST 0 //32 /* Max asteroids on the screen. */ #define MAXPOWERUPS 3 /* Max powerups allowed on screen */ #define POWERUPSTTL 400 /* Max powerup time to live, in ticks. */ #define SHIP_HIT_ANIMATION_LEN 15 @@ -39,10 +39,10 @@ typedef enum PowerUpType { PowerUpTypeShield, // Shield PowerUpTypeLife, // Extra life PowerUpTypeFirePower, // Burst Fire power - PowerUpTypeRadialFire, // Radial Fire power + // PowerUpTypeRadialFire, // Radial Fire power PowerUpTypeNuke, // Nuke power - PowerUpTypeClone, // Clone ship - PowerUpTypeAssist, // Secondary ship + // PowerUpTypeClone, // Clone ship + // PowerUpTypeAssist, // Secondary ship Number_of_PowerUps // Used to count the number of powerups } PowerUpType; @@ -363,6 +363,52 @@ bool should_draw_powerUp(PowerUp* const p) { return true; } +void draw_powerUp_RemainingLife(Canvas* canvas, PowerUp* p, int y_offset) { + if(!p->isPowerUpActive) return; + + /* + Here we generate a reverse progress bar. The bar is 24 pixels wide and 1 pixel tall. + Calculate the percentage of hitpoints left: hitpoints / total hitpoints + Multiply the percentage by the width of the bar (in pixels): percentage * bar width + Subtract the result from the width of the bar to get the filled portion of the bar: bar width - (percentage * bar width) + Round the result to the nearest integer to get the final result. + + 400 / 400 = 1.0 + 1.0 * 24 = 24 + 24 - 24 = 0 + Round(0) = 0 + */ + int progress_bar_width = SCREEN_XRES / 4; + if(p->ttl > 0) { + //Erase the previous progress bar + canvas_set_color(canvas, ColorWhite); + canvas_draw_line( + canvas, + SCREEN_XRES / 2 - progress_bar_width, + 3 + y_offset, + SCREEN_XRES / 2 + progress_bar_width, + 3 + y_offset); + + canvas_set_color(canvas, ColorXOR); + int percentage = p->ttl / POWERUPSTTL; + int remaining = round(percentage * progress_bar_width); + // int filled = progress_bar_width - remaining; + canvas_draw_line( + canvas, + round(SCREEN_XRES / 2) - remaining, // x1 + 3 + y_offset, //y1 + round(SCREEN_XRES / 2) + remaining, //x2 + 3 + y_offset); //y2 + FURI_LOG_I( + TAG, + "[draw_powerUp_RemainingLife] Percentage: %d, Remaining: %d Id: %d powerUpType: %d", + percentage, + remaining, + y_offset, + p->powerUpType); + } +} + void draw_powerUps(Canvas* const canvas, PowerUp* const p) { /* @@ -413,18 +459,18 @@ void draw_powerUps(Canvas* const canvas, PowerUp* const p) { // canvas_draw_str(canvas, p->x, p->y, "N"); canvas_draw_icon(canvas, p->x, p->y, &I_nuke_10x10); break; - case PowerUpTypeRadialFire: - // Draw box with letter R inside - canvas_draw_str(canvas, p->x, p->y, "R"); - break; - case PowerUpTypeAssist: - // Draw box with letter A inside - canvas_draw_str(canvas, p->x, p->y, "A"); - break; - case PowerUpTypeClone: - // Draw box with letter C inside - canvas_draw_str(canvas, p->x, p->y, "C"); - break; + // case PowerUpTypeRadialFire: + // // Draw box with letter R inside + // canvas_draw_str(canvas, p->x, p->y, "R"); + // break; + // case PowerUpTypeAssist: + // // Draw box with letter A inside + // canvas_draw_str(canvas, p->x, p->y, "A"); + // break; + // case PowerUpTypeClone: + // // Draw box with letter C inside + // canvas_draw_str(canvas, p->x, p->y, "C"); + // break; default: //@todo Uknown Power Up Type Detected // Draw box with letter U inside @@ -491,7 +537,10 @@ void render_callback(Canvas* const canvas, void* ctx) { for(int j = 0; j < app->asteroids_num; j++) draw_asteroid(canvas, &app->asteroids[j]); - for(int j = 0; j < app->powerUps_num; j++) draw_powerUps(canvas, &app->powerUps[j]); + for(int j = 0; j < app->powerUps_num; j++) { + draw_powerUps(canvas, &app->powerUps[j]); + draw_powerUp_RemainingLife(canvas, &app->powerUps[j], j); + } /* Game over text. */ if(app->gameover) { @@ -671,6 +720,7 @@ void asteroid_was_hit(AsteroidsApp* app, int id) { //@todo Add PowerUp PowerUp* add_powerUp(AsteroidsApp* app) { + FURI_LOG_I(TAG, "add_powerUp: %i", app->powerUps_num); if(app->powerUps_num == MAXPOWERUPS) return NULL; // Randomly select power up for display @@ -870,19 +920,19 @@ void update_powerUps_position(AsteroidsApp* app) { // @todo update_powerUp_status /* This updates the state of each power up collected and removes them if they have expired. */ void update_powerUp_status(AsteroidsApp* app) { - for(int j = app->powerUps_num; j > 0; j--) { + for(int j = app->powerUps_num; j >= 0; j--) { if(app->powerUps[j].ttl > 0 && app->powerUps[j].isPowerUpActive) { // Only decrement ttl if we actually picked up power up app->powerUps[j].ttl--; - } else if(app->powerUps[j].ttl == 0 && app->powerUps[j].display_ttl == 0) { + } else if(app->powerUps[j].display_ttl > 0) { + app->powerUps[j].display_ttl--; + } else { // we've reached the end of life of the power up // Time to remove it app->powerUps[j].isPowerUpActive = false; remove_powerUp(app, j); - j--; /* Process this power up index again: the removal will - fill it with the top power up to take the array dense. */ - } else if(app->powerUps[j].display_ttl > 0) { - app->powerUps[j].display_ttl--; + // j--; /* Process this power up index again: the removal will + // fill it with the top power up to take the array dense. */ } } } From 45b41b48b4940169230af4f3c193d6e4360f1f67 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 1 Feb 2023 22:50:14 -0500 Subject: [PATCH 40/75] Adjust bonus lives to something more reasonable --- app.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.c b/app.c index dbd1bec..34a1a26 100644 --- a/app.c +++ b/app.c @@ -20,7 +20,7 @@ #define SCREEN_XRES 128 #define SCREEN_YRES 64 #define GAME_START_LIVES 3 -#define MAXLIVES 8 /* Max lives allowed. */ +#define MAXLIVES 5 /* Max bonus lives allowed. */ #define TTLBUL 30 /* Bullet time to live, in ticks. */ #define MAXBUL 50 /* Max bullets on the screen. */ //@todo MAX Asteroids From 505aef0fccfd77cb1806ab6db9bc7d5dd180095e Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 1 Feb 2023 23:45:58 -0500 Subject: [PATCH 41/75] Fix realtime power up status --- app.c | 66 +++++++++++++++++++++++------------------------------------ 1 file changed, 26 insertions(+), 40 deletions(-) diff --git a/app.c b/app.c index 34a1a26..97025bd 100644 --- a/app.c +++ b/app.c @@ -363,7 +363,7 @@ bool should_draw_powerUp(PowerUp* const p) { return true; } -void draw_powerUp_RemainingLife(Canvas* canvas, PowerUp* p, int y_offset) { +void draw_powerUp_RemainingLife(Canvas* canvas, PowerUp* const p, int y_offset) { if(!p->isPowerUpActive) return; /* @@ -379,33 +379,19 @@ void draw_powerUp_RemainingLife(Canvas* canvas, PowerUp* p, int y_offset) { Round(0) = 0 */ int progress_bar_width = SCREEN_XRES / 4; + if(p->ttl > 0) { - //Erase the previous progress bar - canvas_set_color(canvas, ColorWhite); - canvas_draw_line( - canvas, - SCREEN_XRES / 2 - progress_bar_width, - 3 + y_offset, - SCREEN_XRES / 2 + progress_bar_width, - 3 + y_offset); - - canvas_set_color(canvas, ColorXOR); - int percentage = p->ttl / POWERUPSTTL; - int remaining = round(percentage * progress_bar_width); - // int filled = progress_bar_width - remaining; - canvas_draw_line( - canvas, - round(SCREEN_XRES / 2) - remaining, // x1 - 3 + y_offset, //y1 - round(SCREEN_XRES / 2) + remaining, //x2 - 3 + y_offset); //y2 - FURI_LOG_I( - TAG, - "[draw_powerUp_RemainingLife] Percentage: %d, Remaining: %d Id: %d powerUpType: %d", - percentage, - remaining, - y_offset, - p->powerUpType); + canvas_set_color(canvas, ColorBlack); + int remaining = ceil(((float)p->ttl / (float)POWERUPSTTL) * (float)progress_bar_width); + + if(remaining > 0) { + canvas_draw_line( + canvas, + (SCREEN_XRES / 2) - remaining, // x1 + 3 + y_offset, //y1 + (SCREEN_XRES / 2) + remaining, //x2 + 3 + y_offset); // + } } } @@ -720,7 +706,7 @@ void asteroid_was_hit(AsteroidsApp* app, int id) { //@todo Add PowerUp PowerUp* add_powerUp(AsteroidsApp* app) { - FURI_LOG_I(TAG, "add_powerUp: %i", app->powerUps_num); + // FURI_LOG_I(TAG, "add_powerUp: %i", app->powerUps_num); if(app->powerUps_num == MAXPOWERUPS) return NULL; // Randomly select power up for display @@ -731,10 +717,10 @@ PowerUp* add_powerUp(AsteroidsApp* app) { // PowerUpType selected_powerUpType = PowerUpTypeNuke; // PowerUpType selected_powerUpType = PowerUpTypeShield; - FURI_LOG_I(TAG, "[add_powerUp] Power Ups Active: %i", app->powerUps_num); + // FURI_LOG_I(TAG, "[add_powerUp] Power Ups Active: %i", app->powerUps_num); // Don't add already existing power ups if(isPowerUpAlreadyExists(app, selected_powerUpType)) { - FURI_LOG_I(TAG, "[add_powerUp] Power Up %i already active", selected_powerUpType); + FURI_LOG_D(TAG, "[add_powerUp] Power Up %i already active", selected_powerUpType); return NULL; } @@ -1044,16 +1030,16 @@ void game_tick(void* ctx) { } // DEBUG: Show Power Up Status - for(int j = 0; j < app->powerUps_num; j++) { - PowerUp* p = &app->powerUps[j]; - FURI_LOG_I( - TAG, - "Power Up Type: %d TTL: %lu Display_TTL: %lu PowerUpNum: %i", - p->powerUpType, - p->ttl, - p->display_ttl, - app->powerUps_num); - } + // for(int j = 0; j < app->powerUps_num; j++) { + // PowerUp* p = &app->powerUps[j]; + // FURI_LOG_I( + // TAG, + // "Power Up Type: %d TTL: %lu Display_TTL: %lu PowerUpNum: %i", + // p->powerUpType, + // p->ttl, + // p->display_ttl, + // app->powerUps_num); + // } /* Update positions and detect collisions. */ update_pos_by_velocity(&app->ship.x, &app->ship.y, app->ship.vx, app->ship.vy); From 790ff263d2692c16794e581dea9f26b21a7cb012 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 1 Feb 2023 23:51:37 -0500 Subject: [PATCH 42/75] make circle shield a little smaller --- app.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.c b/app.c index 97025bd..8a3f92d 100644 --- a/app.c +++ b/app.c @@ -471,7 +471,7 @@ void draw_shield(Canvas* const canvas, AsteroidsApp* app) { canvas_set_color(canvas, ColorXOR); // canvas_draw_disc(canvas, app->ship.x, app->ship.y, 4); - canvas_draw_circle(canvas, app->ship.x, app->ship.y, 10); + canvas_draw_circle(canvas, app->ship.x, app->ship.y, 8); } /* Given the current position, update it according to the velocity and From 8b64ee9859a6011203317e5b0d2ba5776455b2f8 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 1 Feb 2023 23:56:14 -0500 Subject: [PATCH 43/75] restore asteroids --- app.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.c b/app.c index 8a3f92d..d976fb5 100644 --- a/app.c +++ b/app.c @@ -24,7 +24,7 @@ #define TTLBUL 30 /* Bullet time to live, in ticks. */ #define MAXBUL 50 /* Max bullets on the screen. */ //@todo MAX Asteroids -#define MAXAST 0 //32 /* Max asteroids on the screen. */ +#define MAXAST 32 /* Max asteroids on the screen. */ #define MAXPOWERUPS 3 /* Max powerups allowed on screen */ #define POWERUPSTTL 400 /* Max powerup time to live, in ticks. */ #define SHIP_HIT_ANIMATION_LEN 15 From ce40ee9bfdb3b099211bfaa98e28f70a05ada037 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Thu, 2 Feb 2023 08:43:17 -0500 Subject: [PATCH 44/75] Added isPowerUpCollidingWithEachOther --- app.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app.c b/app.c index d976fb5..43fd5bb 100644 --- a/app.c +++ b/app.c @@ -704,6 +704,14 @@ void asteroid_was_hit(AsteroidsApp* app, int id) { } } +bool isPowerUpCollidingWithEachOther(AsteroidsApp* app, float x, float y) { + for(int i = 0; i < app->powerUps_num; i++) { + PowerUp* p2 = &app->powerUps[i]; + if(distance(x, y, p2->x, p2->y) < p2->size) return true; + } + return false; +} + //@todo Add PowerUp PowerUp* add_powerUp(AsteroidsApp* app) { // FURI_LOG_I(TAG, "add_powerUp: %i", app->powerUps_num); @@ -732,7 +740,8 @@ PowerUp* add_powerUp(AsteroidsApp* app) { //It also keeps it away from the lives and score at the top of screen x = rand() % (SCREEN_XRES - (int)size); y = rand() % (SCREEN_YRES - (int)size); - } while(distance(app->ship.x, app->ship.y, (float)x, (float)y) < min_distance + size); + } while((distance(app->ship.x, app->ship.y, (float)x, (float)y) < min_distance + size) && + (!isPowerUpCollidingWithEachOther(app, x, y))); PowerUp* p = &app->powerUps[app->powerUps_num++]; p->x = x; From 827031c4e4b4183eeedc1427360d539905b7aeff Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Thu, 2 Feb 2023 12:22:39 -0500 Subject: [PATCH 45/75] change power up size to %f, organize code --- app.c | 107 +++++++++++++++++++++++----------------------------------- 1 file changed, 42 insertions(+), 65 deletions(-) diff --git a/app.c b/app.c index 43fd5bb..c91f246 100644 --- a/app.c +++ b/app.c @@ -51,7 +51,7 @@ typedef struct PowerUp { float x, y, vx, vy; /* Fields like in ship. */ // rot, /* Fields like ship. */ // rot_speed, /* Angular velocity (rot speed and sense). */ - int size; /* Power Up size */ + float size; /* Power Up size */ uint32_t ttl; /* Time to live, in ticks. */ uint32_t display_ttl; /* How long to display the powerup before it disappears */ @@ -166,68 +166,41 @@ const NotificationSequence sequence_bullet_fired = { }; const NotificationSequence sequence_nuke = { - &message_red_255, + &message_blink_set_color_red, + &message_blink_start_100, + &message_vibro_on, - // &message_note_g5, // Play sound but currently disabled - &message_delay_250, - &message_red_0, + &message_delay_10, &message_vibro_off, - &message_red_255, &message_vibro_on, - // &message_note_g5, // Play sound but currently disabled - &message_delay_250, - &message_red_0, + &message_delay_10, &message_vibro_off, &message_vibro_on, - &message_red_255, - &message_delay_100, - &message_red_0, + &message_delay_10, &message_vibro_off, - &message_delay_1, - &message_delay_1, - &message_vibro_on, - &message_red_255, - &message_delay_100, &message_red_0, - &message_vibro_off, + &message_vibro_on, + &message_delay_10, &message_delay_1, &message_delay_1, - &message_delay_1, - &message_vibro_on, - &message_red_255, - &message_delay_100, - &message_red_0, &message_vibro_off, - &message_delay_1, - &message_delay_1, - &message_delay_1, &message_vibro_on, + &message_delay_10, &message_delay_1, &message_delay_1, - &message_delay_1, - &message_delay_1, - &message_delay_1, - &message_red_0, &message_vibro_off, - &message_delay_1, - &message_delay_1, &message_vibro_on, + &message_delay_10, &message_delay_1, &message_delay_1, - &message_delay_1, - &message_red_0, &message_vibro_off, - &message_delay_1, - &message_vibro_on, - &message_delay_1, - &message_delay_1, - &message_red_0, + &message_blink_stop, &message_vibro_off, &message_sound_off, NULL, @@ -285,6 +258,8 @@ void lfsr_next(unsigned char* prev) { *prev ^= *prev << 7; /* Mix things a bit more. */ } +/* ================================ Render ================================ */ + /* Render the polygon 'poly' at x,y, rotated by the specified angle. */ void draw_poly(Canvas* const canvas, Poly* poly, uint8_t x, uint8_t y, float a) { Poly rot; @@ -474,22 +449,6 @@ void draw_shield(Canvas* const canvas, AsteroidsApp* app) { canvas_draw_circle(canvas, app->ship.x, app->ship.y, 8); } -/* Given the current position, update it according to the velocity and - * wrap it back to the other side if the object went over the screen. */ -void update_pos_by_velocity(float* x, float* y, float vx, float vy) { - /* Return back from one side to the other of the screen. */ - *x += vx; - *y += vy; - if(*x >= SCREEN_XRES) - *x = 0; - else if(*x < 0) - *x = SCREEN_XRES - 1; - if(*y >= SCREEN_YRES) - *y = 0; - else if(*y < 0) - *y = SCREEN_YRES - 1; -} - /* Render the current game screen. */ void render_callback(Canvas* const canvas, void* ctx) { AsteroidsApp* app = ctx; @@ -564,6 +523,22 @@ void render_callback(Canvas* const canvas, void* ctx) { /* ============================ Game logic ================================== */ +/* Given the current position, update it according to the velocity and + * wrap it back to the other side if the object went over the screen. */ +void update_pos_by_velocity(float* x, float* y, float vx, float vy) { + /* Return back from one side to the other of the screen. */ + *x += vx; + *y += vy; + if(*x >= SCREEN_XRES) + *x = 0; + else if(*x < 0) + *x = SCREEN_XRES - 1; + if(*y >= SCREEN_YRES) + *y = 0; + else if(*y < 0) + *y = SCREEN_YRES - 1; +} + float distance(float x1, float y1, float x2, float y2) { float dx = x1 - x2; float dy = y1 - y2; @@ -595,6 +570,8 @@ bool objects_are_colliding(float x1, float y1, float r1, float x2, float y2, flo float rsum = r1 + r2; return dx * dx + dy * dy < rsum * rsum; } + +/* ================================ Bullets ================================ */ //@todo ship_fire_bullet /* Create a new bullet headed in the same direction of the ship. */ void ship_fire_bullet(AsteroidsApp* app) { @@ -639,6 +616,7 @@ void remove_bullet(AsteroidsApp* app, int bid) { if(n && bid != n) app->bullets[bid] = app->bullets[n]; } +/* ================================ Asteroids ================================ */ /* Create a new asteroid, away from the ship. Return the * pointer to the asteroid object, so that the caller can change * certain things of the asteroid if needed. */ @@ -704,10 +682,11 @@ void asteroid_was_hit(AsteroidsApp* app, int id) { } } -bool isPowerUpCollidingWithEachOther(AsteroidsApp* app, float x, float y) { +/* ================================ Power Up ================================ */ +bool isPowerUpCollidingWithEachOther(AsteroidsApp* app, float x, float y, float size) { for(int i = 0; i < app->powerUps_num; i++) { PowerUp* p2 = &app->powerUps[i]; - if(distance(x, y, p2->x, p2->y) < p2->size) return true; + if(objects_are_colliding(x, y, size, p2->x, p2->y, p2->size, 1.0)) return true; } return false; } @@ -718,12 +697,7 @@ PowerUp* add_powerUp(AsteroidsApp* app) { if(app->powerUps_num == MAXPOWERUPS) return NULL; // Randomly select power up for display - //@todo Random Power Up Select PowerUpType selected_powerUpType = rand() % Number_of_PowerUps; - // PowerUpType selected_powerUpType = PowerUpTypeFirePower; - // PowerUpType selected_powerUpType = PowerUpTypeLife; - // PowerUpType selected_powerUpType = PowerUpTypeNuke; - // PowerUpType selected_powerUpType = PowerUpTypeShield; // FURI_LOG_I(TAG, "[add_powerUp] Power Ups Active: %i", app->powerUps_num); // Don't add already existing power ups @@ -740,8 +714,8 @@ PowerUp* add_powerUp(AsteroidsApp* app) { //It also keeps it away from the lives and score at the top of screen x = rand() % (SCREEN_XRES - (int)size); y = rand() % (SCREEN_YRES - (int)size); - } while((distance(app->ship.x, app->ship.y, (float)x, (float)y) < min_distance + size) && - (!isPowerUpCollidingWithEachOther(app, x, y))); + } while((distance(app->ship.x, app->ship.y, x, y) < min_distance + size) && + (!isPowerUpCollidingWithEachOther(app, x, y, size))); PowerUp* p = &app->powerUps[app->powerUps_num++]; p->x = x; @@ -751,7 +725,7 @@ PowerUp* add_powerUp(AsteroidsApp* app) { p->vy = 0; //2 * (-.5 + ((float)rand() / RAND_MAX)); p->display_ttl = 200; p->ttl = POWERUPSTTL; - p->size = (int)size; + p->size = size; // p->size = size; // p->rot = 0; // p->rot_speed = ((float)rand() / RAND_MAX) / 10; @@ -803,6 +777,7 @@ void powerUp_was_hit(AsteroidsApp* app, int id) { case PowerUpTypeNuke: //TODO: Animate explosion notification_message(furi_record_open(RECORD_NOTIFICATION), &sequence_nuke); + // Simulate nuke explosion remove_all_astroids_and_bullets(app); break; default: @@ -830,6 +805,7 @@ bool isPowerUpAlreadyExists(AsteroidsApp* const app, PowerUpType const powerUpTy return false; } +/* ================================ Game States ================================ */ /* Set gameover state. When in game-over mode, the game displays a gameover * text with a background of many asteroids floating around. */ void game_over(AsteroidsApp* app) { @@ -876,6 +852,7 @@ void restart_game_after_gameover(AsteroidsApp* app) { restart_game(app); } +/* ================================ Position & Status ================================ */ /* Move bullets. */ void update_bullets_position(AsteroidsApp* app) { for(int j = 0; j < app->bullets_num; j++) { From 35a2c6fdcf2836dfde78f95426d93ddb5a14f237 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Thu, 2 Feb 2023 16:27:40 -0500 Subject: [PATCH 46/75] Bugfix: Powerup spawn anti-collide, code reorganiz --- app.c | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/app.c b/app.c index c91f246..395f33e 100644 --- a/app.c +++ b/app.c @@ -686,7 +686,7 @@ void asteroid_was_hit(AsteroidsApp* app, int id) { bool isPowerUpCollidingWithEachOther(AsteroidsApp* app, float x, float y, float size) { for(int i = 0; i < app->powerUps_num; i++) { PowerUp* p2 = &app->powerUps[i]; - if(objects_are_colliding(x, y, size, p2->x, p2->y, p2->size, 1.0)) return true; + if(objects_are_colliding(x, y, size, p2->x, p2->y, p2->size, 1)) return true; } return false; } @@ -714,8 +714,9 @@ PowerUp* add_powerUp(AsteroidsApp* app) { //It also keeps it away from the lives and score at the top of screen x = rand() % (SCREEN_XRES - (int)size); y = rand() % (SCREEN_YRES - (int)size); - } while((distance(app->ship.x, app->ship.y, x, y) < min_distance + size) && - (!isPowerUpCollidingWithEachOther(app, x, y, size))); + } while( + ((distance(app->ship.x, app->ship.y, x, y) < min_distance + size) || + isPowerUpCollidingWithEachOther(app, x, y, size))); PowerUp* p = &app->powerUps[app->powerUps_num++]; p->x = x; @@ -737,6 +738,24 @@ PowerUp* add_powerUp(AsteroidsApp* app) { return p; } +bool isPowerUpActive(AsteroidsApp* const app, PowerUpType const powerUpType) { + for(int i = 0; i < app->powerUps_num; i++) { + // PowerUp* p = &app->powerUps[i]; + // if(p->powerUpType == powerUpType && p->ttl > 0 && p->display_ttl == 0) return true; + if(app->powerUps[i].isPowerUpActive && app->powerUps[i].powerUpType == powerUpType) { + return true; + } + } + return false; +} + +bool isPowerUpAlreadyExists(AsteroidsApp* const app, PowerUpType const powerUpType) { + for(int i = 0; i < app->powerUps_num; i++) { + if(app->powerUps[i].powerUpType == powerUpType) return true; + } + return false; +} + //@todo remove_powerUp void remove_powerUp(AsteroidsApp* app, int id) { // Invalid ID, ignore @@ -787,24 +806,6 @@ void powerUp_was_hit(AsteroidsApp* app, int id) { p->isPowerUpActive = true; } -bool isPowerUpActive(AsteroidsApp* const app, PowerUpType const powerUpType) { - for(int i = 0; i < app->powerUps_num; i++) { - // PowerUp* p = &app->powerUps[i]; - // if(p->powerUpType == powerUpType && p->ttl > 0 && p->display_ttl == 0) return true; - if(app->powerUps[i].isPowerUpActive && app->powerUps[i].powerUpType == powerUpType) { - return true; - } - } - return false; -} - -bool isPowerUpAlreadyExists(AsteroidsApp* const app, PowerUpType const powerUpType) { - for(int i = 0; i < app->powerUps_num; i++) { - if(app->powerUps[i].powerUpType == powerUpType) return true; - } - return false; -} - /* ================================ Game States ================================ */ /* Set gameover state. When in game-over mode, the game displays a gameover * text with a background of many asteroids floating around. */ @@ -1184,11 +1185,11 @@ int32_t asteroids_app_entry(void* p) { } else { /* Useful to understand if the app is still alive when it * does not respond because of bugs. */ - if(DEBUG_MSG) { - static int c = 0; - c++; - if(!(c % 20)) FURI_LOG_E(TAG, "Loop timeout"); - } + // if(DEBUG_MSG) { + // static int c = 0; + // c++; + // if(!(c % 20)) FURI_LOG_E(TAG, "Loop timeout"); + // } } } From cccf54c4a1808c86df010d5448344e4c64cad0ea Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Mon, 6 Feb 2023 22:47:12 -0500 Subject: [PATCH 47/75] limit bonus <3, add should_add_powerups, adj spawn --- app.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/app.c b/app.c index 395f33e..c6de9bc 100644 --- a/app.c +++ b/app.c @@ -15,6 +15,8 @@ #include #include +#include + #define TAG "Asteroids" // Used for logging #define DEBUG_MSG 1 #define SCREEN_XRES 128 @@ -694,7 +696,8 @@ bool isPowerUpCollidingWithEachOther(AsteroidsApp* app, float x, float y, float //@todo Add PowerUp PowerUp* add_powerUp(AsteroidsApp* app) { // FURI_LOG_I(TAG, "add_powerUp: %i", app->powerUps_num); - if(app->powerUps_num == MAXPOWERUPS) return NULL; + if(app->powerUps_num == MAXPOWERUPS) return NULL; // Max Power Ups reached + if(app->lives == MAXLIVES) return NULL; // Max Lives reached // Randomly select power up for display PowerUpType selected_powerUpType = rand() % Number_of_PowerUps; @@ -713,7 +716,7 @@ PowerUp* add_powerUp(AsteroidsApp* app) { //size*2 to make sure power up is not spawned on the edge of the screen //It also keeps it away from the lives and score at the top of screen x = rand() % (SCREEN_XRES - (int)size); - y = rand() % (SCREEN_YRES - (int)size); + y = rand() % (SCREEN_YRES - (int)size + 20); } while( ((distance(app->ship.x, app->ship.y, x, y) < min_distance + size) || isPowerUpCollidingWithEachOther(app, x, y, size))); @@ -880,6 +883,24 @@ void update_asteroids_position(AsteroidsApp* app) { } } +bool should_add_powerUp(AsteroidsApp* app) { + srand(furi_get_tick()); + int random_number = rand() % 100 + 1; + + // The chance of spawning a power-up decreases as the game goes on + int threshold = 100 - (app->score * 5); + + // Make sure the threshold doesn't go below 10 + threshold = (threshold < 10) ? 10 : threshold; + FURI_LOG_I( + TAG, + "Random number: %d, threshold: %d Bool: %d", + random_number, + threshold, + random_number <= threshold); + return random_number <= threshold; +} + void update_powerUps_position(AsteroidsApp* app) { for(int j = 0; j < app->powerUps_num; j++) { // @todo update_powerUps_position @@ -899,7 +920,7 @@ void update_powerUp_status(AsteroidsApp* app) { app->powerUps[j].ttl--; } else if(app->powerUps[j].display_ttl > 0) { app->powerUps[j].display_ttl--; - } else { + } else if(app->powerUps[j].ttl == 0) { // we've reached the end of life of the power up // Time to remove it app->powerUps[j].isPowerUpActive = false; @@ -1045,7 +1066,8 @@ void game_tick(void* ctx) { /* From time to time add a random power up */ //@todo game tick - if((app->powerUps_num == 0 || random() % 5000) < (30 / (1 + app->powerUps_num))) { + // if(app->powerUps_num == 0 || random() % (500 + (100 * (int)app->score)) <= app->powerUps_num) { + if(should_add_powerUp(app)) { add_powerUp(app); } From 9ed721ee70e9bf452cc48aca37ddc8db38612759 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Mon, 6 Feb 2023 23:01:46 -0500 Subject: [PATCH 48/75] Add basic pause state using back button --- app.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app.c b/app.c index c6de9bc..f4e5235 100644 --- a/app.c +++ b/app.c @@ -92,6 +92,7 @@ typedef struct AsteroidsApp { /* Game state. */ int running; /* Once false exists the app. */ bool gameover; /* Gameover status. */ + bool paused; /* Game paused status. */ uint32_t ticks; /* Game ticks. Increments at each refresh. */ uint32_t score; /* Game score. */ uint32_t highscore; /* Highscore. Shown on Game Over Screen */ @@ -1011,6 +1012,12 @@ void game_tick(void* ctx) { update_asteroids_position(app); view_port_update(app->view_port); return; + } else if(app->paused) { + if(key_pressed_time(app, InputKeyBack) > 100 || key_pressed_time(app, InputKeyOk) > 100) { + app->paused = false; + } + view_port_update(app->view_port); + return; } /* Handle keypresses. */ @@ -1194,6 +1201,15 @@ int32_t asteroids_app_entry(void* p) { if(qstat == FuriStatusOk) { // if(DEBUG_MSG) // FURI_LOG_E(TAG, "Main Loop - Input: type %d key %u", input.type, input.key); + /* Handle Pause */ + if(input.type == InputTypeShort && input.key == InputKeyBack) { + app->paused = !app->paused; + if(app->paused) { + furi_timer_stop(timer); + } else { + furi_timer_start(timer, furi_kernel_get_tick_frequency() / 10); + } + } /* Handle navigation here. Then handle view-specific inputs * in the view specific handling function. */ From eff243b474f18a486f31780a359110d0452bb422 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Mon, 6 Feb 2023 23:11:16 -0500 Subject: [PATCH 49/75] Add pause screen --- app.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app.c b/app.c index f4e5235..fd7ef6a 100644 --- a/app.c +++ b/app.c @@ -490,6 +490,15 @@ void render_callback(Canvas* const canvas, void* ctx) { draw_powerUp_RemainingLife(canvas, &app->powerUps[j], j); } + if(app->paused) { + canvas_set_color(canvas, ColorXOR); + canvas_set_font(canvas, FontPrimary); + canvas_draw_rbox(canvas, 0, 0, SCREEN_XRES, SCREEN_YRES, 4); + canvas_draw_str_aligned( + canvas, SCREEN_XRES / 2, SCREEN_YRES / 2, AlignCenter, AlignCenter, "Paused"); + return; + } + /* Game over text. */ if(app->gameover) { canvas_set_color(canvas, ColorBlack); From 6687bf162634ace93691edb94d226d895513552d Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Mon, 6 Feb 2023 23:14:26 -0500 Subject: [PATCH 50/75] minor comment clarification --- app.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.c b/app.c index fd7ef6a..77439ee 100644 --- a/app.c +++ b/app.c @@ -795,7 +795,7 @@ void remove_all_astroids_and_bullets(AsteroidsApp* app) { //@todo powerUp_was_hit void powerUp_was_hit(AsteroidsApp* app, int id) { PowerUp* p = &app->powerUps[id]; - if(p->display_ttl == 0) return; // Don't collect if already collected + if(p->display_ttl == 0) return; // Don't collect if already collected or expired switch(p->powerUpType) { case PowerUpTypeLife: From 7633b2bdbafd7b81ab7e157cc218b410b6c9e280 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Tue, 7 Feb 2023 19:33:30 -0500 Subject: [PATCH 51/75] debugging power ups --- app.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app.c b/app.c index 77439ee..f9545e5 100644 --- a/app.c +++ b/app.c @@ -705,7 +705,7 @@ bool isPowerUpCollidingWithEachOther(AsteroidsApp* app, float x, float y, float //@todo Add PowerUp PowerUp* add_powerUp(AsteroidsApp* app) { - // FURI_LOG_I(TAG, "add_powerUp: %i", app->powerUps_num); + FURI_LOG_I(TAG, "add_powerUp: %i", app->powerUps_num); if(app->powerUps_num == MAXPOWERUPS) return NULL; // Max Power Ups reached if(app->lives == MAXLIVES) return NULL; // Max Lives reached @@ -771,10 +771,14 @@ bool isPowerUpAlreadyExists(AsteroidsApp* const app, PowerUpType const powerUpTy //@todo remove_powerUp void remove_powerUp(AsteroidsApp* app, int id) { + FURI_LOG_I(TAG, "remove_powerUp: %i", id); // Invalid ID, ignore - if(id < 0) return; - + if(id < 0) { + FURI_LOG_E(TAG, "remove_powerUp: Invalid ID: %i", id); + return; + } // TODO: Break this out into object types that set the game state + // Return the bullet period to normal if(app->powerUps[id].powerUpType == PowerUpTypeFirePower) { app->bullet_min_period = 200; } @@ -902,12 +906,12 @@ bool should_add_powerUp(AsteroidsApp* app) { // Make sure the threshold doesn't go below 10 threshold = (threshold < 10) ? 10 : threshold; - FURI_LOG_I( - TAG, - "Random number: %d, threshold: %d Bool: %d", - random_number, - threshold, - random_number <= threshold); + // FURI_LOG_I( + // TAG, + // "Random number: %d, threshold: %d Bool: %d", + // random_number, + // threshold, + // random_number <= threshold); return random_number <= threshold; } @@ -930,7 +934,7 @@ void update_powerUp_status(AsteroidsApp* app) { app->powerUps[j].ttl--; } else if(app->powerUps[j].display_ttl > 0) { app->powerUps[j].display_ttl--; - } else if(app->powerUps[j].ttl == 0) { + } else if(app->powerUps[j].ttl == 0 || app->powerUps[j].display_ttl == 0) { // we've reached the end of life of the power up // Time to remove it app->powerUps[j].isPowerUpActive = false; From f97247ef17a36edd60eea9a6717f416073c5ebd9 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Tue, 7 Feb 2023 20:19:33 -0500 Subject: [PATCH 52/75] need more logs --- app.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app.c b/app.c index f9545e5..2fb1541 100644 --- a/app.c +++ b/app.c @@ -935,12 +935,26 @@ void update_powerUp_status(AsteroidsApp* app) { } else if(app->powerUps[j].display_ttl > 0) { app->powerUps[j].display_ttl--; } else if(app->powerUps[j].ttl == 0 || app->powerUps[j].display_ttl == 0) { + FURI_LOG_I( + TAG, + "[update_powerUp_status] Power up expired!, ttl: %lu, display_ttl: %lu id: %d", + app->powerUps[j].ttl, + app->powerUps[j].display_ttl, + j); // we've reached the end of life of the power up // Time to remove it app->powerUps[j].isPowerUpActive = false; remove_powerUp(app, j); // j--; /* Process this power up index again: the removal will // fill it with the top power up to take the array dense. */ + } else { + FURI_LOG_E( + TAG, + "[update_powerUp_status] Power up error! Invalid Index: %d ttl: %lu display_ttl: %lu PowerUp_Num: %d", + j, + app->powerUps[j].ttl, + app->powerUps[j].display_ttl, + app->powerUps_num); } } } From 4150a8b7cf56079e548b63175d50b2f4c25c47df Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 8 Feb 2023 09:47:54 -0500 Subject: [PATCH 53/75] allow immediate collsion with smaller asteroids --- app.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app.c b/app.c index 2fb1541..cba8199 100644 --- a/app.c +++ b/app.c @@ -988,11 +988,12 @@ void detect_collisions(AsteroidsApp* app) { notification_message( furi_record_open(RECORD_NOTIFICATION), &sequence_bullet_fired); asteroid_was_hit(app, j); + j--; /* Scan this j value again. */ } else { // No sheild active, take damage ship_was_hit(app); + break; } - break; } } @@ -1001,7 +1002,7 @@ void detect_collisions(AsteroidsApp* app) { PowerUp* p = &app->powerUps[j]; if(objects_are_colliding(p->x, p->y, p->size, app->ship.x, app->ship.y, 4, 1)) { powerUp_was_hit(app, j); - break; + // break; } } } From 48188ec9d52f961ffea3cfbfe8473442fdd2f76b Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 8 Feb 2023 10:34:30 -0500 Subject: [PATCH 54/75] reverse the for loop for power up status check --- app.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app.c b/app.c index cba8199..26d690e 100644 --- a/app.c +++ b/app.c @@ -928,7 +928,7 @@ void update_powerUps_position(AsteroidsApp* app) { // @todo update_powerUp_status /* This updates the state of each power up collected and removes them if they have expired. */ void update_powerUp_status(AsteroidsApp* app) { - for(int j = app->powerUps_num; j >= 0; j--) { + for(int j = 0; j < app->powerUps_num; j++) { if(app->powerUps[j].ttl > 0 && app->powerUps[j].isPowerUpActive) { // Only decrement ttl if we actually picked up power up app->powerUps[j].ttl--; @@ -945,8 +945,8 @@ void update_powerUp_status(AsteroidsApp* app) { // Time to remove it app->powerUps[j].isPowerUpActive = false; remove_powerUp(app, j); - // j--; /* Process this power up index again: the removal will - // fill it with the top power up to take the array dense. */ + j--; /* Process this power up index again: the removal will + fill it with the top power up to take the array dense. */ } else { FURI_LOG_E( TAG, From 9c9eb8f71be3bea166a810ff0f75cb96285735f6 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 8 Feb 2023 10:34:57 -0500 Subject: [PATCH 55/75] Update readme to include power up and pause menu --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7899ff0..e5c5f62 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,16 @@ This is an implementation of the classic Asteroids game for the [Flipper Zero](h * Auto rapid fire (less wear on the buttons this way too) * Up button applies thrusters * Haptic feedback and LED effects +* Power up system * High Score system * Automatic save and load of high score +* Ability to Pause * Some modifications to certain game play elements ## What's coming next * Settings screen * Enabling sound effects (configurable on/off option) -* Power Ups +* ~~Power Ups~~ Improved power up management --- @@ -25,6 +27,7 @@ This is a screenshot, but the game looks a lot better in the device itself: * Ok, long press: Auto-fire bullets * Up: Accelerate * Down: Decelerate +* Back (Short Press): Pause game * Back (Long Press): Exit game. It will automatically save the high scoore too. Your high scores will automatically be saved. Go forth and compete! From 4c0f3adab9a3f61b642434e7af3ff29106e9ad22 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 8 Feb 2023 10:42:36 -0500 Subject: [PATCH 56/75] disable debug mode --- app.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.c b/app.c index 26d690e..7f0d07a 100644 --- a/app.c +++ b/app.c @@ -18,7 +18,7 @@ #include #define TAG "Asteroids" // Used for logging -#define DEBUG_MSG 1 +#define DEBUG_MSG 0 #define SCREEN_XRES 128 #define SCREEN_YRES 64 #define GAME_START_LIVES 3 From 96e7a6b041bb6f1859b49a16a1aaeeb258b59083 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 8 Feb 2023 10:46:24 -0500 Subject: [PATCH 57/75] Add haptic feedback on power up pick up --- app.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app.c b/app.c index 7f0d07a..8b485fa 100644 --- a/app.c +++ b/app.c @@ -168,6 +168,17 @@ const NotificationSequence sequence_bullet_fired = { NULL, }; +const NotificationSequence sequence_powerup_collected = { + &message_vibro_on, + &message_delay_1, + &message_delay_1, + &message_delay_1, + &message_delay_1, + &message_delay_1, + &message_vibro_off, + NULL, +}; + const NotificationSequence sequence_nuke = { &message_blink_set_color_red, &message_blink_start_100, @@ -801,6 +812,9 @@ void powerUp_was_hit(AsteroidsApp* app, int id) { PowerUp* p = &app->powerUps[id]; if(p->display_ttl == 0) return; // Don't collect if already collected or expired + // Vibrate to indicate power up was collected + notification_message(furi_record_open(RECORD_NOTIFICATION), &sequence_powerup_collected); + switch(p->powerUpType) { case PowerUpTypeLife: if(app->lives < MAXLIVES) app->lives++; From acc738af09c0304c5b18662bbcc27ec1e7edb955 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 8 Feb 2023 10:49:40 -0500 Subject: [PATCH 58/75] V1 of power up system and pause screen --- app.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.c b/app.c index 8b485fa..c1046cb 100644 --- a/app.c +++ b/app.c @@ -379,7 +379,7 @@ void draw_powerUp_RemainingLife(Canvas* canvas, PowerUp* const p, int y_offset) (SCREEN_XRES / 2) - remaining, // x1 3 + y_offset, //y1 (SCREEN_XRES / 2) + remaining, //x2 - 3 + y_offset); // + 3 + y_offset); // y2 } } } From d8fc8cba8a62786a13d9b39ec1bbfeb29fdae804 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 8 Feb 2023 11:01:10 -0500 Subject: [PATCH 59/75] Updated application manifest, new power up system --- application.fam | 3 +++ 1 file changed, 3 insertions(+) diff --git a/application.fam b/application.fam index d8a4131..c62de55 100644 --- a/application.fam +++ b/application.fam @@ -10,4 +10,7 @@ App( fap_icon="appicon.png", fap_category="Games", fap_icon_assets="assets", # Image assets to compile for this application + fap_description="An implementation of the classic arcade game Asteroids", + fap_author="antirez, SimplyMinimal", + fap_weburl="https://github.com/SimplyMinimal/FlipperZero-Asteroids", ) From e50cb64db9888925611b468a9089c25f940c20d7 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 8 Feb 2023 11:18:45 -0500 Subject: [PATCH 60/75] Update readme for new power up system --- README.md | 13 ++++++++++++- images/Asteroids-PowerUps.png | Bin 0 -> 1570 bytes images/Pause Screen.png | Bin 0 -> 1421 bytes 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 images/Asteroids-PowerUps.png create mode 100644 images/Pause Screen.png diff --git a/README.md b/README.md index e5c5f62..3d16998 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,9 @@ This is an implementation of the classic Asteroids game for the [Flipper Zero](h This is a screenshot, but the game looks a lot better in the device itself: -![Asteroids for Flipper Zero screenshot](/images/Asteroids.jpg) +![Asteroids for Flipper Zero screenshot](/images/Asteroids-PowerUps.png "In game screenshot") + +![Pause Screen](images/Pause%20Screen.png "Pause screen") # Controls: * Left/Right: rotate ship in the two directions. @@ -32,6 +34,15 @@ This is a screenshot, but the game looks a lot better in the device itself: Your high scores will automatically be saved. Go forth and compete! +--- +# Power Ups +* ![](assets/firepower_shifted_9x10.png "Ammunition") - Machine gun fire. Press and hold OK button to fire more than the default 5 bullets +* ![](assets/heart_10x10.png "Lives") - Et tu, Brute? Gives a bonus life up to a maximum of 5 lives +* ![](assets/nuke_10x10.png "Nuke") - Nuke (work in progress). Destroys everything in sight (but keeps the power ups) +* ![](assets/split_shield_10x10.png "Shield") - Use the force! Spins up a shield that can be used as a battering ram. Take zero damage while in use. + +## More power ups coming soon... + --- ## Installing the binary file (no build needed) diff --git a/images/Asteroids-PowerUps.png b/images/Asteroids-PowerUps.png new file mode 100644 index 0000000000000000000000000000000000000000..66b17b1967b3da38d8eb5d7889551f07951adc3b GIT binary patch literal 1570 zcmd5+ZA?>V6h61GF(k+kVg`hkt(&k6N8QFIXj>*lK#hz|1`Mc;(bfc!Zis*_A9Web z2sA_@!m2fHW+uHBS3uT5p(8pRM98KQ`7B##2GS3p&^vlpy31(NmnHkZA2;XTH|IU) zd7kr}d*Oq_$^KhHw*Y{DY6|Z|02=j*!3*o*z*07g3cli$>>_||XVxEVO2{Y$cBlL-3BRN^8t-tn|LDjHXpvuU2weIGKiipCJiJN^-uK?snP(XtgN3~n zQqrfihp=*8S`(yCsHmJHKHy7T`zbL`u`o7n#I7F_vS{4R8Ur1;K z;OPn~-_}&0d>Hssok>+-zHMbVyCw|bYQJ5coN}r2<^GXZWW9B`m7&|-PwbE*70ec_ zR>7tz28pq;q4-C0?ZY->GTeF9-F=e8c4vAE3U)wMl>3Nl2b}aea|PgrH$)tu0;m2O z`)CdMmA=<)%-*)BR_l6f=14yU+I~b!Qrf&{d zyL!WdHgsFZ#fFH2u7LD$B?4#E3##{OIQ*O(v4hsC~~}aY{oT^66fg|3%5O~v&fdXx7r=z{AQ13>I@9T|0e>blk86%$wO0Rc8<(edHrW( zH!2{lJ+F&9?^?y3(7H!}YAV)-~RajpH&PxzEBh1 zseWC2YnKf}@vVE$dl?vK=g8~CX z5J=7Uz~BEqFPPtG9Ldhmz`)?43e+XXNZI{)oH3j9dn=g~4tD+i zGi6TtX%2|HKni@f^DQW=|08*eCnkFJ^RhE#a>@|f!49vkJ7F;|l;J|ZAcKPjBZGh! zFlh0DKab3IF<$vuQ~&qZ_tUqJfB4Msx=Qjc1H&-^U`Vk54Jl^ezOnlH_kZ;dZuKC% zI>oYqH7EOv>bFf^;K*jl}n|*Pqe#ZeeBMGpQyGSyz=6_;VQBEtMB)J&-mQ+ zcY_s*84DVfOaI(@@3MK_r2Sj1EYgjT-13ZJp2XJYyQ2#F_HJcbyslC1yz7muulv$o ztiCGA2uTtUkBX+PFy0m=KVic;hu$AG^Oo)rL$TulyYclt?{AZLUfTD0&f_!L`>y^A z-@JBy#6(0`w-~W+n6Wo%`7ZUvGAoa+zT2P50*(Vnx?3!5&@GxhQF~kEl$pP?o^87d zRE=VV?17{!J})1hdA;g*_Rp9$A|T%c@&{+%o%ak^VMY*0O%}>kZ#c4L(0l6?KEgEii$cvT8VZ z#ZbQQ%31HMvumFjMD2YyvG(&qQ8b_L{oWh+yH9GUojlDfsGzkly-eG{c>`fKlF?=v6d&QJNXGols6PXPiu?4 zzb@qNp5wb(wEy0%wr^i>)$-?D6qOeoJoiS(7T2X;TM)j!eE!cIwqJ%walHK^ZvyY$ z*V}Br-PE^ycEY$Z+V=GJTb&f0zZ>;8WD^v!UCCc~F+Z|B)> zkY(Ue0cS9XLmId@@-ZlMlmd$*hK3MO>9XCjLH9Ew!}Sf-^X+#6%QGivX;k){VcQvY phBZrH+^ci4W|%Pns0CC~{AFgE|6TP;UUxXiL{C>gmvv4FO#mht|FZx9 literal 0 HcmV?d00001 From 12443abf92f83d5c8b77d0d8b4cbc74791e1bb30 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 8 Feb 2023 11:20:06 -0500 Subject: [PATCH 61/75] No time --- app.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/app.c b/app.c index c1046cb..a6868b3 100644 --- a/app.c +++ b/app.c @@ -15,8 +15,6 @@ #include #include -#include - #define TAG "Asteroids" // Used for logging #define DEBUG_MSG 0 #define SCREEN_XRES 128 From 343e87d2b2e8ac919dabb6d04edd928eefadf758 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 8 Feb 2023 19:27:18 -0500 Subject: [PATCH 62/75] Keep power up on game play area --- app.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app.c b/app.c index a6868b3..883d3cb 100644 --- a/app.c +++ b/app.c @@ -732,10 +732,12 @@ PowerUp* add_powerUp(AsteroidsApp* app) { float min_distance = 20; float x, y; do { - //size*2 to make sure power up is not spawned on the edge of the screen - //It also keeps it away from the lives and score at the top of screen + //Make sure power up is not spawned on the edge of the screen x = rand() % (SCREEN_XRES - (int)size); - y = rand() % (SCREEN_YRES - (int)size + 20); + y = rand() % (SCREEN_YRES - (int)size); + + //Also keep it away from the lives and score at the top of screen + if(y < size) y = size; } while( ((distance(app->ship.x, app->ship.y, x, y) < min_distance + size) || isPowerUpCollidingWithEachOther(app, x, y, size))); From 9bd77bd8b0bdc782f27816b75e6537bc99c012a9 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 8 Feb 2023 19:41:48 -0500 Subject: [PATCH 63/75] Make extra life power up more rare --- app.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app.c b/app.c index 883d3cb..2e4e272 100644 --- a/app.c +++ b/app.c @@ -728,6 +728,14 @@ PowerUp* add_powerUp(AsteroidsApp* app) { return NULL; } + // Make extra life power up more rare + if(selected_powerUpType == PowerUpTypeLife) { + if(rand() % 10 != 0) { + FURI_LOG_D(TAG, "[add_powerUp] Power Up %i not selected", selected_powerUpType); + return NULL; + } + } + float size = 10; float min_distance = 20; float x, y; From b46e722d11b7caac67c64a60f337bf3516b2ca3c Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 8 Feb 2023 19:55:35 -0500 Subject: [PATCH 64/75] make shield more rare, additional logging --- app.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app.c b/app.c index 2e4e272..977ff59 100644 --- a/app.c +++ b/app.c @@ -720,6 +720,7 @@ PowerUp* add_powerUp(AsteroidsApp* app) { // Randomly select power up for display PowerUpType selected_powerUpType = rand() % Number_of_PowerUps; + FURI_LOG_I(TAG, "[add_powerUp] Power Up Selected: %i", selected_powerUpType); // FURI_LOG_I(TAG, "[add_powerUp] Power Ups Active: %i", app->powerUps_num); // Don't add already existing power ups @@ -731,7 +732,16 @@ PowerUp* add_powerUp(AsteroidsApp* app) { // Make extra life power up more rare if(selected_powerUpType == PowerUpTypeLife) { if(rand() % 10 != 0) { - FURI_LOG_D(TAG, "[add_powerUp] Power Up %i not selected", selected_powerUpType); + FURI_LOG_D( + TAG, "[add_powerUp] Exra Life Power Up %i not selected", selected_powerUpType); + return NULL; + } + } + + // Make shield power up more rare + if(selected_powerUpType == PowerUpTypeShield) { + if(rand() % 4 != 0) { + FURI_LOG_D(TAG, "[add_powerUp] Shield Power Up %i not selected", selected_powerUpType); return NULL; } } @@ -767,6 +777,7 @@ PowerUp* add_powerUp(AsteroidsApp* app) { //@todo add powerup type, for now hardcoding to firepower p->powerUpType = selected_powerUpType; p->isPowerUpActive = false; + FURI_LOG_I(TAG, "[add_powerUp] Power Up Added: %i", p->powerUpType); return p; } From 10dcf70662e0dace67e1bb39d7fe04a62d1e8b90 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 8 Feb 2023 20:04:57 -0500 Subject: [PATCH 65/75] Add rare chance trigger for power ups --- app.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/app.c b/app.c index 977ff59..495542a 100644 --- a/app.c +++ b/app.c @@ -712,6 +712,17 @@ bool isPowerUpCollidingWithEachOther(AsteroidsApp* app, float x, float y, float return false; } +bool should_trigger_rare_powerUp(PowerUpType selected_powerUpType) { + switch(selected_powerUpType) { + case PowerUpTypeLife: // Make extra life power up more rare + return rand() % 10 != 0; + case PowerUpTypeShield: // Make shield power up more rare + return rand() % 4 != 0; + default: + return true; + } +} + //@todo Add PowerUp PowerUp* add_powerUp(AsteroidsApp* app) { FURI_LOG_I(TAG, "add_powerUp: %i", app->powerUps_num); @@ -722,28 +733,16 @@ PowerUp* add_powerUp(AsteroidsApp* app) { PowerUpType selected_powerUpType = rand() % Number_of_PowerUps; FURI_LOG_I(TAG, "[add_powerUp] Power Up Selected: %i", selected_powerUpType); - // FURI_LOG_I(TAG, "[add_powerUp] Power Ups Active: %i", app->powerUps_num); // Don't add already existing power ups if(isPowerUpAlreadyExists(app, selected_powerUpType)) { FURI_LOG_D(TAG, "[add_powerUp] Power Up %i already active", selected_powerUpType); return NULL; } - // Make extra life power up more rare - if(selected_powerUpType == PowerUpTypeLife) { - if(rand() % 10 != 0) { - FURI_LOG_D( - TAG, "[add_powerUp] Exra Life Power Up %i not selected", selected_powerUpType); - return NULL; - } - } - - // Make shield power up more rare - if(selected_powerUpType == PowerUpTypeShield) { - if(rand() % 4 != 0) { - FURI_LOG_D(TAG, "[add_powerUp] Shield Power Up %i not selected", selected_powerUpType); - return NULL; - } + // Make some power ups more rare + if(!should_trigger_rare_powerUp(selected_powerUpType)) { + FURI_LOG_D(TAG, "[add_powerUp] Power Up %i not triggered", selected_powerUpType); + return NULL; } float size = 10; From 048a8dd3d1b2232cb5b92e3abbb45307a94f9545 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 16 Jul 2025 18:56:52 -0400 Subject: [PATCH 66/75] ci: Add GitHub Actions workflow for automated FAP building - Add .github/workflows/build-fap.yml for CI/CD automation - Triggers on pushes to main, pull requests, and tagged releases - Uses official flipperdevices/flipperzero-ufbt-action for building - Uploads FAP artifacts for download from workflow runs - Automatically creates releases with FAP files on tag pushes - Enables continuous integration for Asteroids Flipper Zero app --- .github/workflows/build-fap.yml | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/build-fap.yml diff --git a/.github/workflows/build-fap.yml b/.github/workflows/build-fap.yml new file mode 100644 index 0000000..d6ebc91 --- /dev/null +++ b/.github/workflows/build-fap.yml @@ -0,0 +1,47 @@ +name: Build Flipper Application Package (FAP) + +on: + push: + branches: [ main ] + tags: [ 'v*' ] + pull_request: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + name: Build Asteroids FAP + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: true + + - name: Build Flipper Application Package + uses: flipperdevices/flipperzero-ufbt-action@v0.1.3 + id: build-fap + with: + app-dir: . + + - name: Upload FAP artifact + uses: actions/upload-artifact@v4 + with: + name: asteroids-fap + path: | + dist/*.fap + dist/*.fap.debug + retention-days: 30 + + - name: Create Release + if: startsWith(github.ref, 'refs/tags/') + uses: softprops/action-gh-release@v1 + with: + files: | + dist/*.fap + generate_release_notes: true + draft: false + prerelease: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From e95f81795cbb0aaf2a25ad9c5750f595a33c56d0 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 16 Jul 2025 21:42:36 -0400 Subject: [PATCH 67/75] feat: Add automatic firmware release monitoring to CI/CD workflow - Add scheduled job to check for new Flipper Zero firmware releases daily - Automatically build and release FAP files for new firmware versions - Create releases with firmware-specific tags (e.g., asteroids-0.98.3) - Include comprehensive release notes with compatibility information - Prevent duplicate releases for same firmware versions - Maintain separate workflows for manual and automatic releases - Add workflow_dispatch trigger for manual testing This ensures users always have access to FAP files compatible with the latest Flipper Zero firmware without manual intervention. --- .github/workflows/build-fap.yml | 85 +++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-fap.yml b/.github/workflows/build-fap.yml index d6ebc91..ce4cf6f 100644 --- a/.github/workflows/build-fap.yml +++ b/.github/workflows/build-fap.yml @@ -6,12 +6,53 @@ on: tags: [ 'v*' ] pull_request: branches: [ main ] + schedule: + # Check for new Flipper Zero firmware releases daily at 12:00 UTC + - cron: '0 12 * * *' + workflow_dispatch: + # Allow manual triggering for testing jobs: + check-firmware: + runs-on: ubuntu-latest + name: Check for New Flipper Zero Firmware + outputs: + new-release: ${{ steps.check.outputs.new-release }} + firmware-version: ${{ steps.check.outputs.firmware-version }} + release-tag: ${{ steps.check.outputs.release-tag }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Check for new Flipper Zero firmware release + id: check + run: | + # Get the latest Flipper Zero firmware release + LATEST_FW=$(curl -s https://api.github.com/repos/flipperdevices/flipperzero-firmware/releases/latest | jq -r '.tag_name') + echo "Latest firmware version: $LATEST_FW" + + # Check if we already have a release for this firmware version + EXISTING_RELEASE=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases | jq -r --arg fw "$LATEST_FW" '.[] | select(.tag_name | contains($fw)) | .tag_name' | head -1) + + if [ -z "$EXISTING_RELEASE" ]; then + echo "New firmware version detected: $LATEST_FW" + echo "new-release=true" >> $GITHUB_OUTPUT + echo "firmware-version=$LATEST_FW" >> $GITHUB_OUTPUT + echo "release-tag=asteroids-$LATEST_FW" >> $GITHUB_OUTPUT + else + echo "Release already exists for firmware $LATEST_FW: $EXISTING_RELEASE" + echo "new-release=false" >> $GITHUB_OUTPUT + fi + build: runs-on: ubuntu-latest name: Build Asteroids FAP - + needs: check-firmware + if: always() && (github.event_name != 'schedule' || needs.check-firmware.outputs.new-release == 'true') + steps: - name: Checkout repository uses: actions/checkout@v4 @@ -28,14 +69,14 @@ jobs: - name: Upload FAP artifact uses: actions/upload-artifact@v4 with: - name: asteroids-fap + name: asteroids-fap-${{ needs.check-firmware.outputs.firmware-version || 'manual' }} path: | dist/*.fap dist/*.fap.debug retention-days: 30 - - name: Create Release - if: startsWith(github.ref, 'refs/tags/') + - name: Create Release for Manual Tags + if: startsWith(github.ref, 'refs/tags/') && github.event_name != 'schedule' uses: softprops/action-gh-release@v1 with: files: | @@ -45,3 +86,39 @@ jobs: prerelease: false env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Create Automatic Release for New Firmware + if: needs.check-firmware.outputs.new-release == 'true' && github.event_name == 'schedule' + uses: softprops/action-gh-release@v1 + with: + tag_name: ${{ needs.check-firmware.outputs.release-tag }} + name: "Asteroids for Flipper Zero ${{ needs.check-firmware.outputs.firmware-version }}" + body: | + 🎮 **Asteroids Game for Flipper Zero** + + This release is automatically built and tested for compatibility with **Flipper Zero firmware ${{ needs.check-firmware.outputs.firmware-version }}**. + + ## 📦 Installation + 1. Download the `asteroids.fap` file from the assets below + 2. Copy it to your Flipper Zero's `apps/Games/` folder via qFlipper or SD card + 3. Launch the game from Apps → Games → Asteroids + + ## 🔧 Compatibility + - **Firmware Version**: ${{ needs.check-firmware.outputs.firmware-version }} + - **Build Date**: ${{ github.run_id }} + - **App Version**: Built from commit ${{ github.sha }} + + ## 🎯 Game Features + - Classic Asteroids gameplay + - Power-ups and special weapons + - High score tracking + - Optimized for Flipper Zero controls + + --- + *This release was automatically generated when Flipper Zero firmware ${{ needs.check-firmware.outputs.firmware-version }} was detected.* + files: | + dist/*.fap + draft: false + prerelease: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 57fbad93c650c083de3e1e23c23e1d6b2402fe8d Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 16 Jul 2025 21:53:14 -0400 Subject: [PATCH 68/75] feat: Add automatic README updates and enhanced release visibility - Add automatic README.md updates with latest release information - Include release badges, direct download links, and firmware compatibility - Add quick install instructions prominently displayed on main page - Enhance release creation with proper IDs for tracking - Add error handling with continue-on-error for README operations - Support both manual and automatic release types - Auto-commit README changes back to repository - Improve main page visibility without requiring navigation to releases This ensures the latest FAP file is immediately visible and downloadable from the main repository page, improving user experience and accessibility. --- .github/workflows/build-fap.yml | 78 +++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/.github/workflows/build-fap.yml b/.github/workflows/build-fap.yml index ce4cf6f..c13956e 100644 --- a/.github/workflows/build-fap.yml +++ b/.github/workflows/build-fap.yml @@ -77,6 +77,7 @@ jobs: - name: Create Release for Manual Tags if: startsWith(github.ref, 'refs/tags/') && github.event_name != 'schedule' + id: manual-release uses: softprops/action-gh-release@v1 with: files: | @@ -89,6 +90,7 @@ jobs: - name: Create Automatic Release for New Firmware if: needs.check-firmware.outputs.new-release == 'true' && github.event_name == 'schedule' + id: auto-release uses: softprops/action-gh-release@v1 with: tag_name: ${{ needs.check-firmware.outputs.release-tag }} @@ -122,3 +124,79 @@ jobs: prerelease: false env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Update README with Latest Release Info + if: steps.manual-release.conclusion == 'success' || steps.auto-release.conclusion == 'success' + run: | + # Set release information based on which type of release was created + if [ "${{ steps.auto-release.conclusion }}" == "success" ]; then + RELEASE_TAG="${{ needs.check-firmware.outputs.release-tag }}" + RELEASE_NAME="Asteroids for Flipper Zero ${{ needs.check-firmware.outputs.firmware-version }}" + FIRMWARE_VERSION="${{ needs.check-firmware.outputs.firmware-version }}" + else + RELEASE_TAG="${{ github.ref_name }}" + RELEASE_NAME="Asteroids ${{ github.ref_name }}" + FIRMWARE_VERSION="Latest" + fi + + # Get current date + CURRENT_DATE=$(date -u +"%Y-%m-%d %H:%M UTC") + + # Create the latest release section + cat > latest_release_section.md << EOF + + ## 🚀 Latest Release + + [![Latest Release](https://img.shields.io/github/v/release/SimplyMinimal/FlipperZero-Asteroids?style=for-the-badge&logo=github&color=success)](https://github.com/SimplyMinimal/FlipperZero-Asteroids/releases/latest) + [![Download FAP](https://img.shields.io/badge/Download-asteroids.fap-blue?style=for-the-badge&logo=download)](https://github.com/SimplyMinimal/FlipperZero-Asteroids/releases/latest/download/asteroids.fap) + [![Firmware Compatibility](https://img.shields.io/badge/Firmware-${FIRMWARE_VERSION}-orange?style=for-the-badge&logo=flipboard)](https://github.com/flipperdevices/flipperzero-firmware) + + **${RELEASE_NAME}** | *Last updated: ${CURRENT_DATE}* + + ### 📥 Quick Install + 1. **[Download asteroids.fap](https://github.com/SimplyMinimal/FlipperZero-Asteroids/releases/latest/download/asteroids.fap)** ⬅️ *Click here for direct download* + 2. Copy to your Flipper Zero: `/ext/apps/Games/asteroids.fap` + 3. Launch from: Apps → Games → Asteroids + + --- + + + EOF + + # Check if the latest release section already exists + if grep -q "" README.md; then + # Replace existing section + sed -i '//,//c\' README.md + sed -i '1r latest_release_section.md' README.md + else + # Add new section at the top + cat latest_release_section.md README.md > temp_readme.md + mv temp_readme.md README.md + fi + + # Clean up + rm latest_release_section.md + continue-on-error: true + + - name: Commit README Updates + if: steps.manual-release.conclusion == 'success' || steps.auto-release.conclusion == 'success' + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + + if git diff --quiet README.md; then + echo "No changes to README.md" + else + git add README.md + git commit -m "docs: Update README with latest release information + + - Add latest release badges and download links + - Update firmware compatibility information + - Add quick install instructions + - Auto-generated from workflow run ${{ github.run_id }}" + + git push origin main + fi + continue-on-error: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 872d3b9902e14b021b292fe3a684d653cc8404ee Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 16 Jul 2025 23:24:27 -0400 Subject: [PATCH 69/75] Fixed critical rendering bug --- .gitignore | 1 + app.c | 120 +++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 103 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index b0a64d5..7225e82 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .vscode/ dist/ .clang-format +docs/ diff --git a/app.c b/app.c index 495542a..0efd968 100644 --- a/app.c +++ b/app.c @@ -272,8 +272,15 @@ void lfsr_next(unsigned char* prev) { /* ================================ Render ================================ */ +/* Safely clamp coordinate to valid canvas bounds */ +static inline int clamp_coordinate(float coord, int min_val, int max_val) { + if(coord < min_val) return min_val; + if(coord > max_val) return max_val; + return (int)coord; +} + /* Render the polygon 'poly' at x,y, rotated by the specified angle. */ -void draw_poly(Canvas* const canvas, Poly* poly, uint8_t x, uint8_t y, float a) { +void draw_poly(Canvas* const canvas, Poly* poly, int x, int y, float a) { Poly rot; rotate_poly(&rot, poly, a); canvas_set_color(canvas, ColorBlack); @@ -281,18 +288,43 @@ void draw_poly(Canvas* const canvas, Poly* poly, uint8_t x, uint8_t y, float a) uint32_t a = j; uint32_t b = j + 1; if(b == rot.points) b = 0; - canvas_draw_line(canvas, x + rot.x[a], y + rot.y[a], x + rot.x[b], y + rot.y[b]); + + /* Calculate final coordinates with bounds checking */ + int x1 = clamp_coordinate(x + rot.x[a], 0, SCREEN_XRES - 1); + int y1 = clamp_coordinate(y + rot.y[a], 0, SCREEN_YRES - 1); + int x2 = clamp_coordinate(x + rot.x[b], 0, SCREEN_XRES - 1); + int y2 = clamp_coordinate(y + rot.y[b], 0, SCREEN_YRES - 1); + + /* Only draw if coordinates are reasonable (prevent extreme off-screen rendering) */ + if(abs(x - SCREEN_XRES/2) < SCREEN_XRES * 2 && abs(y - SCREEN_YRES/2) < SCREEN_YRES * 2) { + canvas_draw_line(canvas, x1, y1, x2, y2); + } } } +/* Validate that coordinates are safe for drawing */ +static inline bool is_coordinate_safe(float x, float y) { + return (x >= -10 && x <= SCREEN_XRES + 10 && y >= -10 && y <= SCREEN_YRES + 10); +} + /* A bullet is just a + pixels pattern. A single pixel is not * visible enough. */ void draw_bullet(Canvas* const canvas, Bullet* b) { - canvas_draw_dot(canvas, b->x - 1, b->y); - canvas_draw_dot(canvas, b->x + 1, b->y); - canvas_draw_dot(canvas, b->x, b->y); - canvas_draw_dot(canvas, b->x, b->y - 1); - canvas_draw_dot(canvas, b->x, b->y + 1); + /* Safety check to prevent drawing at invalid coordinates */ + if(!is_coordinate_safe(b->x, b->y)) { + FURI_LOG_W(TAG, "Unsafe bullet coordinates: x=%.2f, y=%.2f", (double)b->x, (double)b->y); + return; + } + + int x = clamp_coordinate(b->x, 0, SCREEN_XRES - 1); + int y = clamp_coordinate(b->y, 0, SCREEN_YRES - 1); + + /* Draw bullet with bounds checking for each dot */ + if(x > 0) canvas_draw_dot(canvas, x - 1, y); + if(x < SCREEN_XRES - 1) canvas_draw_dot(canvas, x + 1, y); + canvas_draw_dot(canvas, x, y); + if(y > 0) canvas_draw_dot(canvas, x, y - 1); + if(y < SCREEN_YRES - 1) canvas_draw_dot(canvas, x, y + 1); } /* Draw an asteroid. The asteroid shapes is computed on the fly and @@ -301,6 +333,18 @@ void draw_bullet(Canvas* const canvas, Bullet* b) { * to the asteroid size, perturbate according to the asteroid shape * seed, and finally draw it rotated of the right amount. */ void draw_asteroid(Canvas* const canvas, Asteroid* ast) { + /* Safety check for asteroid coordinates */ + if(!is_coordinate_safe(ast->x, ast->y)) { + FURI_LOG_W(TAG, "Unsafe asteroid coordinates: x=%.2f, y=%.2f", (double)ast->x, (double)ast->y); + return; + } + + /* Validate asteroid size to prevent extreme shapes */ + if(ast->size < 1 || ast->size > 50) { + FURI_LOG_W(TAG, "Invalid asteroid size: %.2f", (double)ast->size); + return; + } + Poly ap; /* Start with what is kinda of a circle. Note that this could be @@ -456,9 +500,16 @@ void draw_powerUps(Canvas* const canvas, PowerUp* const p) { void draw_shield(Canvas* const canvas, AsteroidsApp* app) { if(isPowerUpActive(app, PowerUpTypeShield) == false) return; + /* Safety check for shield coordinates */ + if(!is_coordinate_safe(app->ship.x, app->ship.y)) { + return; /* Skip drawing shield if ship coordinates are invalid */ + } + canvas_set_color(canvas, ColorXOR); - // canvas_draw_disc(canvas, app->ship.x, app->ship.y, 4); - canvas_draw_circle(canvas, app->ship.x, app->ship.y, 8); + int x = clamp_coordinate(app->ship.x, 8, SCREEN_XRES - 8); + int y = clamp_coordinate(app->ship.y, 8, SCREEN_YRES - 8); + // canvas_draw_disc(canvas, x, y, 4); + canvas_draw_circle(canvas, x, y, 8); } /* Render the current game screen. */ @@ -480,6 +531,16 @@ void render_callback(Canvas* const canvas, void* ctx) { draw_left_lives(canvas, app); /* Draw ship, asteroids, bullets. */ + /* Safety check for ship coordinates before rendering */ + if(!is_coordinate_safe(app->ship.x, app->ship.y)) { + FURI_LOG_E(TAG, "Ship coordinate corruption detected: x=%.2f, y=%.2f", (double)app->ship.x, (double)app->ship.y); + /* Emergency reset ship to center */ + app->ship.x = SCREEN_XRES / 2; + app->ship.y = SCREEN_YRES / 2; + app->ship.vx = 0; + app->ship.vy = 0; + } + draw_poly(canvas, &ShipPoly, app->ship.x, app->ship.y, app->ship.rot); /* Draw shield if active. */ @@ -544,20 +605,43 @@ void render_callback(Canvas* const canvas, void* ctx) { /* ============================ Game logic ================================== */ +/* Safely wrap coordinate to screen bounds with proper modulo arithmetic */ +static inline float safe_wrap_coordinate(float coord, float max_val) { + /* Handle extreme negative values */ + while(coord < 0) { + coord += max_val; + } + /* Handle extreme positive values */ + while(coord >= max_val) { + coord -= max_val; + } + return coord; +} + /* Given the current position, update it according to the velocity and * wrap it back to the other side if the object went over the screen. */ void update_pos_by_velocity(float* x, float* y, float vx, float vy) { - /* Return back from one side to the other of the screen. */ + /* Update position */ *x += vx; *y += vy; - if(*x >= SCREEN_XRES) - *x = 0; - else if(*x < 0) - *x = SCREEN_XRES - 1; - if(*y >= SCREEN_YRES) - *y = 0; - else if(*y < 0) - *y = SCREEN_YRES - 1; + + /* Clamp velocity to prevent extreme jumps that could cause coordinate corruption */ + const float MAX_VELOCITY = 10.0f; + if(vx > MAX_VELOCITY || vx < -MAX_VELOCITY || vy > MAX_VELOCITY || vy < -MAX_VELOCITY) { + FURI_LOG_W(TAG, "Extreme velocity detected: vx=%.2f, vy=%.2f", (double)vx, (double)vy); + } + + /* Safely wrap coordinates using proper modulo arithmetic */ + *x = safe_wrap_coordinate(*x, SCREEN_XRES); + *y = safe_wrap_coordinate(*y, SCREEN_YRES); + + /* Additional safety check - ensure coordinates are within reasonable bounds */ + if(*x < 0 || *x >= SCREEN_XRES || *y < 0 || *y >= SCREEN_YRES) { + FURI_LOG_E(TAG, "Coordinate corruption detected: x=%.2f, y=%.2f", (double)*x, (double)*y); + /* Emergency reset to center of screen */ + *x = SCREEN_XRES / 2; + *y = SCREEN_YRES / 2; + } } float distance(float x1, float y1, float x2, float y2) { From af842db0549cbc97a40fa5f3511fc22e3bbd48fc Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 16 Jul 2025 23:48:28 -0400 Subject: [PATCH 70/75] feat: Add splash screen with developer credits - Implement main splash screen that displays before game starts - Show proper credits for SimplyMinimal (enhancements) and AntiRez (original) - Display for 3 seconds with option to skip by pressing any key - Uses safe rendering functions with coordinate bounds checking - Automatically transitions to main game after timeout - Fits FlipperZero's 128x64 pixel display perfectly --- app.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/app.c b/app.c index 0efd968..12719e1 100644 --- a/app.c +++ b/app.c @@ -30,6 +30,7 @@ #define SHIP_HIT_ANIMATION_LEN 15 #define SAVING_DIRECTORY "/ext/apps/Games" #define SAVING_FILENAME SAVING_DIRECTORY "/game_asteroids.save" +#define SPLASH_SCREEN_DURATION 3000 /* Splash screen duration in milliseconds */ #ifndef PI #define PI 3.14159265358979f #endif @@ -91,6 +92,8 @@ typedef struct AsteroidsApp { int running; /* Once false exists the app. */ bool gameover; /* Gameover status. */ bool paused; /* Game paused status. */ + bool splash_screen; /* Splash screen status. */ + uint32_t splash_start_time; /* When splash screen started. */ uint32_t ticks; /* Game ticks. Increments at each refresh. */ uint32_t score; /* Game score. */ uint32_t highscore; /* Highscore. Shown on Game Over Screen */ @@ -512,10 +515,45 @@ void draw_shield(Canvas* const canvas, AsteroidsApp* app) { canvas_draw_circle(canvas, x, y, 8); } +/* Render the splash screen with credits */ +void render_splash_screen(Canvas* const canvas, AsteroidsApp* app) { + UNUSED(app); + + /* Clear screen */ + canvas_set_color(canvas, ColorWhite); + canvas_draw_box(canvas, 0, 0, SCREEN_XRES - 1, SCREEN_YRES - 1); + + /* Set black color for text */ + canvas_set_color(canvas, ColorBlack); + + /* Draw main title */ + canvas_set_font(canvas, FontPrimary); + canvas_draw_str_aligned(canvas, SCREEN_XRES / 2, 12, AlignCenter, AlignCenter, "ASTEROIDS++"); + + /* Draw credits section */ + canvas_set_font(canvas, FontSecondary); + canvas_draw_str_aligned(canvas, SCREEN_XRES / 2, 26, AlignCenter, AlignCenter, "Designed and Developed by"); + + /* Draw developer credits */ + canvas_set_font(canvas, FontSecondary); + canvas_draw_str_aligned(canvas, SCREEN_XRES / 2, 38, AlignCenter, AlignCenter, "SimplyMinimal"); + canvas_draw_str_aligned(canvas, SCREEN_XRES / 2, 48, AlignCenter, AlignCenter, "& AntiRez"); + + /* Draw skip instruction */ + canvas_set_font(canvas, FontSecondary); + canvas_draw_str_aligned(canvas, SCREEN_XRES / 2, 60, AlignCenter, AlignCenter, "Press any key to skip"); +} + /* Render the current game screen. */ void render_callback(Canvas* const canvas, void* ctx) { AsteroidsApp* app = ctx; + /* Handle splash screen rendering */ + if(app->splash_screen) { + render_splash_screen(canvas, app); + return; + } + /* Clear screen. */ canvas_set_color(canvas, ColorWhite); canvas_draw_box(canvas, 0, 0, SCREEN_XRES - 1, SCREEN_YRES - 1); @@ -1132,7 +1170,17 @@ void detect_collisions(AsteroidsApp* app) { void game_tick(void* ctx) { AsteroidsApp* app = ctx; - /* There are two special screens: + /* Handle splash screen timing */ + if(app->splash_screen) { + uint32_t elapsed = furi_get_tick() - app->splash_start_time; + if(elapsed >= SPLASH_SCREEN_DURATION) { + app->splash_screen = false; + } + view_port_update(app->view_port); + return; + } + + /* There are three special screens: * * 1. Ship was hit, we frozen the game as long as ship_hit isn't zero * again, and show an animation of a rotating ship. */ @@ -1286,6 +1334,10 @@ AsteroidsApp* asteroids_app_alloc() { app->running = 1; /* Turns 0 when back is pressed. */ + /* Initialize splash screen */ + app->splash_screen = true; + app->splash_start_time = furi_get_tick(); + restart_game_after_gameover(app); memset(app->pressed, 0, sizeof(app->pressed)); return app; @@ -1345,6 +1397,13 @@ int32_t asteroids_app_entry(void* p) { if(qstat == FuriStatusOk) { // if(DEBUG_MSG) // FURI_LOG_E(TAG, "Main Loop - Input: type %d key %u", input.type, input.key); + + /* Handle splash screen skip */ + if(app->splash_screen && input.type == InputTypePress) { + app->splash_screen = false; + continue; + } + /* Handle Pause */ if(input.type == InputTypeShort && input.key == InputKeyBack) { app->paused = !app->paused; From cd536bc471f2bbd8e0471cd5b403f3cbf216b7a3 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Wed, 16 Jul 2025 23:54:53 -0400 Subject: [PATCH 71/75] feat: Add Drone Buddy power-up with autonomous assistant - Implement new PowerUpTypeDroneBuddy power-up type - Add Drone structure with position, velocity, rotation, and TTL - Create drone spawning system that positions drone near ship - Implement autonomous drone behavior: * Follows main ship at safe distance * Automatically targets and fires at nearby asteroids * Has limited duration (300 ticks) like other power-ups - Add drone collision detection with asteroids (drone can be destroyed) - Use smaller triangular polygon shape to distinguish from main ship - Apply coordinate safety checks for stable rendering - Integrate with existing power-up collection and management system - Add proper cleanup when drone expires or is destroyed The drone buddy provides tactical assistance while maintaining game balance through limited duration and vulnerability to asteroid collisions. --- app.c | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) diff --git a/app.c b/app.c index 0efd968..d120c59 100644 --- a/app.c +++ b/app.c @@ -27,6 +27,9 @@ #define MAXAST 32 /* Max asteroids on the screen. */ #define MAXPOWERUPS 3 /* Max powerups allowed on screen */ #define POWERUPSTTL 400 /* Max powerup time to live, in ticks. */ +#define MAXDRONES 1 /* Max drone buddies allowed */ +#define DRONE_TTL 300 /* Drone time to live, in ticks. */ +#define DRONE_FIRE_RATE 20 /* Drone fire rate in ticks. */ #define SHIP_HIT_ANIMATION_LEN 15 #define SAVING_DIRECTORY "/ext/apps/Games" #define SAVING_FILENAME SAVING_DIRECTORY "/game_asteroids.save" @@ -41,6 +44,7 @@ typedef enum PowerUpType { PowerUpTypeFirePower, // Burst Fire power // PowerUpTypeRadialFire, // Radial Fire power PowerUpTypeNuke, // Nuke power + PowerUpTypeDroneBuddy, // Drone assistant // PowerUpTypeClone, // Clone ship // PowerUpTypeAssist, // Secondary ship Number_of_PowerUps // Used to count the number of powerups @@ -79,6 +83,13 @@ typedef struct Asteroid { uint8_t shape_seed; /* Seed to give random shape. */ } Asteroid; +typedef struct Drone { + float x, y, vx, vy, rot; /* Fields like ship. */ + uint32_t ttl; /* Time to live, in ticks. */ + uint32_t last_fire_tick; /* Last time drone fired. */ + bool active; /* Is the drone active? */ +} Drone; + // @todo AsteroidsApp typedef struct AsteroidsApp { /* GUI */ @@ -116,6 +127,10 @@ typedef struct AsteroidsApp { Asteroid asteroids[MAXAST]; /* Each asteroid state. */ int asteroids_num; /* Active asteroids. */ + /* Drone state. */ + Drone drones[MAXDRONES]; /* Each drone state. */ + int drones_num; /* Active drones. */ + uint32_t pressed[InputKeyMAX]; /* pressed[id] is true if pressed. Each array item contains the time in milliseconds the key was pressed. */ @@ -227,6 +242,7 @@ bool load_game(AsteroidsApp* app); void save_game(AsteroidsApp* app); void restart_game_after_gameover(AsteroidsApp* app); uint32_t key_pressed_time(AsteroidsApp* app, InputKey key); +void spawn_drone_buddy(AsteroidsApp* app); /* ============================ 2D drawing ================================== */ @@ -245,6 +261,9 @@ Poly ShipPoly = {{-3, 0, 3}, {-3, 6, -3}, 3}; Poly ShipFirePoly = {{-1.5, 0, 1.5}, {-3, -6, -3}, 3}; +/* Smaller drone polygon - triangular shape */ +Poly DronePoly = {{-2, 0, 2}, {-2, 4, -2}, 3}; + /* Rotate the point of the poligon 'poly' and store the new rotated * polygon in 'rot'. The polygon is rotated by an angle 'a', with * center at 0,0. */ @@ -476,6 +495,10 @@ void draw_powerUps(Canvas* const canvas, PowerUp* const p) { // canvas_draw_str(canvas, p->x, p->y, "N"); canvas_draw_icon(canvas, p->x, p->y, &I_nuke_10x10); break; + case PowerUpTypeDroneBuddy: + // Draw box with letter D inside for drone buddy + canvas_draw_str(canvas, p->x, p->y, "D"); + break; // case PowerUpTypeRadialFire: // // Draw box with letter R inside // canvas_draw_str(canvas, p->x, p->y, "R"); @@ -512,6 +535,24 @@ void draw_shield(Canvas* const canvas, AsteroidsApp* app) { canvas_draw_circle(canvas, x, y, 8); } +/* Draw a drone buddy */ +void draw_drone(Canvas* const canvas, Drone* drone) { + /* Safety check for drone coordinates */ + if(!is_coordinate_safe(drone->x, drone->y)) { + FURI_LOG_W(TAG, "Unsafe drone coordinates: x=%.2f, y=%.2f", (double)drone->x, (double)drone->y); + return; + } + + /* Draw drone with a different color/style to distinguish from main ship */ + canvas_set_color(canvas, ColorBlack); + draw_poly(canvas, &DronePoly, drone->x, drone->y, drone->rot); + + /* Draw a small dot in the center to make it more visible */ + int x = clamp_coordinate(drone->x, 0, SCREEN_XRES - 1); + int y = clamp_coordinate(drone->y, 0, SCREEN_YRES - 1); + canvas_draw_dot(canvas, x, y); +} + /* Render the current game screen. */ void render_callback(Canvas* const canvas, void* ctx) { AsteroidsApp* app = ctx; @@ -555,6 +596,13 @@ void render_callback(Canvas* const canvas, void* ctx) { for(int j = 0; j < app->asteroids_num; j++) draw_asteroid(canvas, &app->asteroids[j]); + /* Draw active drones */ + for(int j = 0; j < app->drones_num; j++) { + if(app->drones[j].active) { + draw_drone(canvas, &app->drones[j]); + } + } + for(int j = 0; j < app->powerUps_num; j++) { draw_powerUps(canvas, &app->powerUps[j]); draw_powerUp_RemainingLife(canvas, &app->powerUps[j], j); @@ -932,6 +980,11 @@ void powerUp_was_hit(AsteroidsApp* app, int id) { // Simulate nuke explosion remove_all_astroids_and_bullets(app); break; + case PowerUpTypeDroneBuddy: + // Spawn a drone buddy + spawn_drone_buddy(app); + remove_powerUp(app, id); + break; default: break; } @@ -939,6 +992,149 @@ void powerUp_was_hit(AsteroidsApp* app, int id) { p->isPowerUpActive = true; } +/* ================================ Drone Buddy ================================ */ +/* Spawn a drone buddy near the ship */ +void spawn_drone_buddy(AsteroidsApp* app) { + if(app->drones_num >= MAXDRONES) return; // Max drones reached + + Drone* drone = &app->drones[app->drones_num++]; + + /* Position drone near the ship but not too close */ + drone->x = app->ship.x + 15; + drone->y = app->ship.y + 10; + drone->vx = 0; + drone->vy = 0; + drone->rot = app->ship.rot; + drone->ttl = DRONE_TTL; + drone->last_fire_tick = 0; + drone->active = true; + + FURI_LOG_I(TAG, "Drone buddy spawned at x=%.2f, y=%.2f", (double)drone->x, (double)drone->y); +} + +/* Remove a drone */ +void remove_drone(AsteroidsApp* app, int id) { + if(id < 0 || id >= app->drones_num) return; + + FURI_LOG_I(TAG, "Removing drone %d", id); + + /* Replace with last drone to keep array dense */ + int n = --app->drones_num; + if(n && id != n) app->drones[id] = app->drones[n]; +} + +/* Find the nearest asteroid to a drone */ +int find_nearest_asteroid(AsteroidsApp* app, Drone* drone) { + int nearest = -1; + float min_distance = 50.0f; /* Maximum targeting range */ + + for(int i = 0; i < app->asteroids_num; i++) { + float dist = distance(drone->x, drone->y, app->asteroids[i].x, app->asteroids[i].y); + if(dist < min_distance) { + min_distance = dist; + nearest = i; + } + } + + return nearest; +} + +/* Make drone fire at nearest asteroid */ +void drone_fire_bullet(AsteroidsApp* app, Drone* drone) { + if(app->bullets_num >= MAXBUL) return; /* No space for more bullets */ + + int target = find_nearest_asteroid(app, drone); + if(target == -1) return; /* No target in range */ + + Asteroid* ast = &app->asteroids[target]; + + /* Calculate direction to target */ + float dx = ast->x - drone->x; + float dy = ast->y - drone->y; + float dist = sqrt(dx * dx + dy * dy); + + if(dist > 0) { + Bullet* b = &app->bullets[app->bullets_num++]; + b->x = drone->x; + b->y = drone->y; + b->vx = (dx / dist) * 3.0f; /* Bullet speed */ + b->vy = (dy / dist) * 3.0f; + b->ttl = TTLBUL; + + /* Update drone rotation to face target */ + drone->rot = atan2(-dx, dy); + + notification_message(furi_record_open(RECORD_NOTIFICATION), &sequence_bullet_fired); + } +} + +/* Update drone positions and behavior */ +void update_drones(AsteroidsApp* app) { + for(int i = 0; i < app->drones_num; i++) { + Drone* drone = &app->drones[i]; + + if(!drone->active) continue; + + /* Decrease TTL */ + if(drone->ttl > 0) { + drone->ttl--; + } else { + /* Drone expired */ + remove_drone(app, i); + i--; /* Process this index again */ + continue; + } + + /* Follow the ship at a distance */ + float target_x = app->ship.x - 20; + float target_y = app->ship.y - 15; + + /* Simple following behavior */ + float dx = target_x - drone->x; + float dy = target_y - drone->y; + float dist = sqrt(dx * dx + dy * dy); + + if(dist > 5.0f) { + /* Move towards target position */ + drone->vx = (dx / dist) * 1.5f; + drone->vy = (dy / dist) * 1.5f; + } else { + /* Close enough, reduce velocity */ + drone->vx *= 0.8f; + drone->vy *= 0.8f; + } + + /* Update position */ + update_pos_by_velocity(&drone->x, &drone->y, drone->vx, drone->vy); + + /* Fire at asteroids */ + uint32_t now = furi_get_tick(); + if(now - drone->last_fire_tick >= DRONE_FIRE_RATE) { + drone_fire_bullet(app, drone); + drone->last_fire_tick = now; + } + } +} + +/* Check drone collisions with asteroids */ +void check_drone_collisions(AsteroidsApp* app) { + for(int i = 0; i < app->drones_num; i++) { + Drone* drone = &app->drones[i]; + if(!drone->active) continue; + + for(int j = 0; j < app->asteroids_num; j++) { + Asteroid* ast = &app->asteroids[j]; + if(objects_are_colliding(drone->x, drone->y, 3, ast->x, ast->y, ast->size, 1)) { + /* Drone was hit by asteroid */ + FURI_LOG_I(TAG, "Drone destroyed by asteroid"); + remove_drone(app, i); + i--; /* Process this index again */ + break; + } + } + } +} + /* ================================ Game States ================================ */ /* Set gameover state. When in game-over mode, the game displays a gameover * text with a background of many asteroids floating around. */ @@ -972,6 +1168,7 @@ void restart_game(AsteroidsApp* app) { app->last_bullet_tick = 0; app->bullet_min_period = 200; app->asteroids_num = 0; + app->drones_num = 0; app->ship_hit = 0; } @@ -1206,7 +1403,9 @@ void game_tick(void* ctx) { update_asteroids_position(app); update_powerUp_status(app); //@todo update_powerUp_status update_powerUps_position(app); + update_drones(app); detect_collisions(app); + check_drone_collisions(app); /* From time to time, create a new asteroid. The more asteroids * already on the screen, the smaller probability of creating From 649de14eccd4bc0554425633c6b217de746ef306 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Sun, 20 Jul 2025 01:15:31 -0400 Subject: [PATCH 72/75] Update README.md to add Drone Power Up --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3d16998..8b3c70c 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Your high scores will automatically be saved. Go forth and compete! * ![](assets/heart_10x10.png "Lives") - Et tu, Brute? Gives a bonus life up to a maximum of 5 lives * ![](assets/nuke_10x10.png "Nuke") - Nuke (work in progress). Destroys everything in sight (but keeps the power ups) * ![](assets/split_shield_10x10.png "Shield") - Use the force! Spins up a shield that can be used as a battering ram. Take zero damage while in use. +* D - A mini drone assist that has your back! ## More power ups coming soon... From c2eb6c8b14f65a97d6b8c09f623b5a122888db03 Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Sun, 20 Jul 2025 01:16:56 -0400 Subject: [PATCH 73/75] Rename Pause Screen.png to PauseScreen.png --- images/{Pause Screen.png => PauseScreen.png} | Bin 1 file changed, 0 insertions(+), 0 deletions(-) rename images/{Pause Screen.png => PauseScreen.png} (100%) diff --git a/images/Pause Screen.png b/images/PauseScreen.png similarity index 100% rename from images/Pause Screen.png rename to images/PauseScreen.png From 537e0bfb26279f91c42074dca16054144f23fd8e Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Sun, 20 Jul 2025 01:51:28 -0400 Subject: [PATCH 74/75] Update README.md (fixed images) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8b3c70c..ba57a69 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ This is a screenshot, but the game looks a lot better in the device itself: ![Asteroids for Flipper Zero screenshot](/images/Asteroids-PowerUps.png "In game screenshot") -![Pause Screen](images/Pause%20Screen.png "Pause screen") +![Pause Screen](images/PauseScreen.png "Pause screen") # Controls: * Left/Right: rotate ship in the two directions. From 9c74c3cdceafa0c06ce3b18a08ddc16058f9092b Mon Sep 17 00:00:00 2001 From: SimplyMinimal Date: Sun, 20 Jul 2025 02:00:46 -0400 Subject: [PATCH 75/75] Update README.md to modernize build instructions --- README.md | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ba57a69..4994fa4 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,12 @@ Your high scores will automatically be saved. Go forth and compete! --- ## Installing the binary file (no build needed) +### Option 1 (Recommended) +Download from the Flipper Zero App catalog store +https://lab.flipper.net/apps/asteroids + +### Option 2) Go to the releases and drop the `asteroids.fap` file into the following Flipper Zero location: @@ -58,17 +63,19 @@ you can just take out the SD card, insert it in your computer, copy the fine into `apps/Games`, and that's it. ## Installing the app from source +Step 1) Install `ufbt` cli tool +- **Linux & macOS**: `python3 -m pip install --upgrade ufbt` +- **Windows**: `py -m pip install --upgrade ufbt` -* Download the Flipper Zero dev kit and build it: +Step 2) Clone this repo with `git` ``` -mkdir -p ~/flipperZero/official/ -cd ~/flipperZero/official/ -git clone --recursive https://github.com/flipperdevices/flipperzero-firmware.git ./ -./fbt +git clone https://github.com/SimplyMinimal/FlipperZero-Asteroids/ ``` -* Copy this application folder in `official/application_user`. + +Step 3) Launch Asteroids +* `cd FlipperZero-Asteroids` * Connect your Flipper via USB. -* Build and install with: `./fbt launch_app APPSRC=asteroids`. +* Build and install with: `ufbt launch`. ## License