Merge pull request #149 from an4tur0r/feature/flappy_assets

Flappy Bird: draw bird via icon animation
This commit is contained in:
MX 2022-11-03 19:11:28 +03:00 committed by GitHub
commit 8ea0178a0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 78 deletions

View file

@ -9,4 +9,5 @@ App(
order=100, order=100,
fap_icon="flappy_10px.png", fap_icon="flappy_10px.png",
fap_category="Games", fap_category="Games",
fap_icon_assets="assets",
) )

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 B

View file

@ -0,0 +1 @@
3

View file

@ -1,54 +0,0 @@
#include <furi.h>
uint8_t bird_array[3][15][11] = {
{
{0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0},
{0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0},
{0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0},
{0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1},
{1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1},
{1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1},
{1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0},
{1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0},
{0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0},
{0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0},
{0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0},
{0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0},
},
{
{0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0},
{0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0},
{0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0},
{0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1},
{1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1},
{1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1},
{1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0},
{1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0},
{0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0},
{0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0},
{0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0},
{0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0},
},
{
{0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0},
{0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0},
{0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0},
{0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0},
{0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},
{1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1},
{1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1},
{1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0},
{1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0},
{0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0},
{0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0},
{0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0},
{0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0},
}};

View file

@ -1,9 +1,10 @@
#include <furi.h>
#include <gui/gui.h>
#include <input/input.h>
#include <stdlib.h> #include <stdlib.h>
#include "bird.h" #include <FlappyBird_icons.h>
#include <furi.h>
#include <gui/gui.h>
#include <gui/icon_animation_i.h>
#include <input/input.h>
#define TAG "Flappy" #define TAG "Flappy"
#define DEBUG false #define DEBUG false
@ -36,6 +37,7 @@ typedef struct {
typedef struct { typedef struct {
float gravity; float gravity;
POINT point; POINT point;
IconAnimation* sprite;
} BIRD; } BIRD;
typedef struct { typedef struct {
@ -89,6 +91,7 @@ static void flappy_game_state_init(GameState* const game_state) {
bird.gravity = 0.0f; bird.gravity = 0.0f;
bird.point.x = 15; bird.point.x = 15;
bird.point.y = 32; bird.point.y = 32;
bird.sprite = icon_animation_alloc(&A_bird);
game_state->debug = DEBUG; game_state->debug = DEBUG;
game_state->bird = bird; game_state->bird = bird;
@ -100,6 +103,11 @@ static void flappy_game_state_init(GameState* const game_state) {
flappy_game_random_pilar(game_state); flappy_game_random_pilar(game_state);
} }
static void flappy_game_state_free(GameState* const game_state) {
icon_animation_free(game_state->bird.sprite);
free(game_state);
}
static void flappy_game_tick(GameState* const game_state) { static void flappy_game_tick(GameState* const game_state) {
if(game_state->state == GameStateLife) { if(game_state->state == GameStateLife) {
if(!game_state->debug) { if(!game_state->debug) {
@ -213,27 +221,16 @@ static void flappy_game_render_callback(Canvas* const canvas, void* ctx) {
FLIPPER_LCD_HEIGHT - pilar->height - FLAPPY_GAB_HEIGHT); FLIPPER_LCD_HEIGHT - pilar->height - FLAPPY_GAB_HEIGHT);
} }
} }
// Flappy
for(int h = 0; h < FLAPPY_BIRD_HEIGHT; h++) {
for(int w = 0; w < FLAPPY_BIRD_WIDTH; w++) {
// Switch animation // Switch animation
int bird = 1; game_state->bird.sprite->frame = 1;
if(game_state->bird.gravity < -0.5) if(game_state->bird.gravity < -0.5)
bird = 0; game_state->bird.sprite->frame = 0;
else if(game_state->bird.gravity > 0.5) else if(game_state->bird.gravity > 0.5)
bird = 2; game_state->bird.sprite->frame = 2;
// Draw bird pixels canvas_draw_icon_animation(
if(bird_array[bird][h][w] == 1) { canvas, game_state->bird.point.x, game_state->bird.point.y, game_state->bird.sprite);
int x = game_state->bird.point.x + h;
int y = game_state->bird.point.y + w;
canvas_draw_dot(canvas, x, y);
}
}
}
// Stats
canvas_set_font(canvas, FontSecondary); canvas_set_font(canvas, FontSecondary);
char buffer[12]; char buffer[12];
@ -366,7 +363,7 @@ int32_t flappy_game_app(void* p) {
delete_mutex(&state_mutex); delete_mutex(&state_mutex);
free_and_exit: free_and_exit:
free(game_state); flappy_game_state_free(game_state);
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
return return_code; return return_code;