Просмотр исходного кода

added moving background and minor fixes

Rrycbarm 2 лет назад
Родитель
Сommit
eec5ed845b

+ 1 - 0
.gitignore

@@ -1,2 +1,3 @@
 /.idea/
 /.idea/
 /cmake-build-*/
 /cmake-build-*/
+.vscode

+ 6 - 7
README.md

@@ -5,22 +5,21 @@ Flipper Zero port of Chrome's running T-rex game
 - Added command to move DINO
 - Added command to move DINO
 - Added (boring) cactus spawn
 - Added (boring) cactus spawn
 - Added lose condition and lose screen
 - Added lose condition and lose screen
+- Added moving backgrounf
 
 
 ## TODO
 ## TODO
 - Change cactus icon
 - Change cactus icon
 - More random cactus spawn
 - More random cactus spawn
 - Increase cactus speed with time
 - Increase cactus speed with time
+- Fix background speed with cactus
+- Fix Dino transparency
 - Allow to play again without the need to close the game in the lose screen
 - Allow to play again without the need to close the game in the lose screen
 
 
-## Screenshots
-
-![image](imgs/Screenshot-20230504-232830.png)
-![image](imgs/Screenshot-20230504-234841.png)
-![image](imgs/Screenshot-20230504-232915.png)
-![image](imgs/Screenshot-20230504-233007.png)
+## Gameplay
+![image](video.gif)
 
 
 ## Compiling
 ## Compiling
 
 
 The easier way to compile it is to use https://github.com/flipperdevices/flipperzero-ufbt.   
 The easier way to compile it is to use https://github.com/flipperdevices/flipperzero-ufbt.   
 Install it with: ```python3 -m pip install --upgrade ufbt```     
 Install it with: ```python3 -m pip install --upgrade ufbt```     
-Then run ```ufbt``` in this folder.
+Then run ```ufbt update && ufbt``` in this folder.

+ 1 - 0
application.fam

@@ -8,5 +8,6 @@ App(
     stack_size=8 * 1024,
     stack_size=8 * 1024,
     fap_category="Games",
     fap_category="Games",
     fap_icon="trexrunner_icon.png",
     fap_icon="trexrunner_icon.png",
+    fap_icon_assets="assets",  
     order=36,
     order=36,
 )
 )

BIN
assets/HorizonLine0.png


+ 0 - 25
assets_icons.c

@@ -1,25 +0,0 @@
-#include "assets_icons.h"
-
-#include <gui/icon_i.h>
-
-const uint8_t _I_Dino_0[] = {0x01,0x00,0x3d,0x00,0x80,0x7e,0x20,0xf0,0x0f,0xe4,0x3e,0x01,0xec,0x01,0x08,0x14,0x80,0x4b,0x7c,0x0a,0x0f,0xf2,0x07,0x01,0x9f,0x40,0x30,0x33,0xf8,0x07,0x0f,0xff,0x00,0xf3,0xef,0xe0,0x1f,0xf0,0x40,0x80,0x8b,0xfd,0x1f,0x0b,0x08,0x08,0x7f,0x01,0xf1,0xf8,0x0c,0x47,0xc1,0x06,0x80,0x58,0x20,0x90,0x09,0x00,0x08,0x6c,0x10,0xc8,0x00,};
-const uint8_t* const _I_Dino[] = {_I_Dino_0};
-
-const uint8_t _I_DinoRun0_0[] = {0x01,0x00,0x3b,0x00,0x80,0x7e,0x20,0xf0,0x0f,0xe4,0x3e,0x01,0xec,0x01,0x08,0x14,0x80,0x4b,0x7c,0x0a,0x0f,0xf2,0x07,0x01,0x9f,0x40,0x30,0x33,0xf8,0x07,0x0f,0xff,0x00,0xf3,0xef,0xe0,0x1f,0xf0,0x40,0x80,0x8b,0xfd,0x1f,0x0b,0x08,0x08,0x7f,0x01,0xf1,0xf8,0x0c,0x47,0xc1,0x0c,0x80,0x58,0x04,0xa3,0x20,0x01,0x08,0x14,0x80,};
-const uint8_t* const _I_DinoRun0[] = {_I_DinoRun0_0};
-
-const uint8_t _I_DinoRun1_0[] = {0x01,0x00,0x3b,0x00,0x80,0x7e,0x20,0xf0,0x0f,0xe4,0x3e,0x01,0xec,0x01,0x08,0x14,0x80,0x4b,0x7c,0x0a,0x0f,0xf2,0x07,0x01,0x9f,0x40,0x30,0x33,0xf8,0x07,0x0f,0xff,0x00,0xf3,0xef,0xe0,0x1f,0xf0,0x40,0x80,0x8b,0xfd,0x1f,0x0b,0x08,0x08,0x7f,0x01,0xf1,0xf8,0x0c,0x46,0xc1,0x06,0x80,0x70,0x20,0x82,0x61,0x01,0x14,0x32,0x00,};
-const uint8_t* const _I_DinoRun1[] = {_I_DinoRun1_0};
-
-const uint8_t _I_HorizonLine0_0[] = {0x01,0x00,0x9c,0x00,0x00,0x78,0x03,0xc0,0x1e,0x00,0xf0,0x07,0x80,0x3c,0x01,0xe0,0x0f,0x00,0x78,0x03,0xc0,0x1e,0x00,0xf0,0x07,0x80,0x3c,0x01,0xe0,0x0f,0x00,0x78,0x03,0xc0,0x17,0xff,0x00,0x78,0x03,0xc0,0x1e,0x00,0xf0,0x04,0x96,0xbc,0x01,0xe0,0x0f,0x00,0x78,0x03,0xc0,0x1e,0x00,0xf0,0x07,0x80,0x3c,0x01,0x78,0x08,0x18,0x2e,0xa0,0xe0,0x97,0x8e,0x09,0x7a,0x3c,0x36,0xf1,0xa6,0xf0,0x08,0x91,0x20,0x05,0x88,0x66,0x01,0x27,0x80,0x01,0x95,0x00,0x23,0x10,0x60,0x21,0xc1,0x20,0x1e,0x00,0xfb,0x40,0x40,0xeb,0x0e,0x02,0xa5,0x8a,0x01,0x38,0x2d,0x78,0x03,0xc9,0x86,0x00,0x48,0x40,0x5b,0x21,0x80,0x98,0x0b,0x91,0x13,0xe0,0x48,0x74,0x9e,0x1f,0xaa,0xe0,0x1a,0x7a,0x00,0xe0,0x5c,0xfe,0x00,0x66,0x74,0x00,0x0e,0x20,0x03,0x28,0x7b,0x55,0x21,0xe1,0x27,0x61,0x08,0x03,0xd4,0x50,0x3a,0x98,0x78,0xe0,0xc0,0x0f,0x30,0x26,0x40,};
-const uint8_t* const _I_HorizonLine0[] = {_I_HorizonLine0_0};
-
-const uint8_t _I_HorizonLine1_0[] = {0x01,0x00,0xc6,0x00,0x00,0x7f,0x02,0x1e,0x11,0xf0,0x07,0x80,0x17,0x01,0x1f,0x01,0x18,0x03,0xc0,0x19,0x60,0x8c,0x04,0x7c,0x01,0xe7,0x26,0x88,0x00,0x8c,0x01,0xe0,0x0c,0x9c,0x4c,0x02,0x3e,0x00,0xf0,0x02,0xdc,0x2c,0x00,0x23,0x00,0x78,0x03,0x21,0x9c,0x00,0x8f,0x80,0x3c,0x00,0xb1,0x8c,0x04,0x06,0x18,0x02,0x10,0x96,0x7f,0xc0,0x1d,0x07,0xc0,0x00,0xc6,0x07,0xf8,0x0a,0xf8,0x03,0xc0,0x03,0x0f,0x1c,0x8c,0x1c,0x79,0xc6,0xdf,0x00,0x1c,0x1a,0x18,0x11,0xf0,0x07,0x80,0x3c,0x01,0xe0,0x08,0xfe,0x1b,0xc4,0x01,0xe0,0x0f,0x00,0x78,0x02,0x70,0x10,0x30,0x5d,0x12,0x22,0x38,0x25,0xe8,0xf0,0xdb,0xc6,0x9b,0xc0,0x22,0x44,0x80,0x16,0x21,0x98,0x04,0x9e,0x00,0x06,0x54,0x07,0xa4,0x81,0x0e,0x09,0x00,0xf0,0x07,0xda,0x02,0x07,0x58,0x70,0x15,0x2c,0x50,0x09,0xc1,0x6b,0xc0,0x1e,0x4c,0x30,0x02,0x42,0x02,0xd9,0x0c,0x04,0xc0,0x5c,0x88,0x9f,0x02,0x43,0xa4,0xf0,0xfd,0x57,0x00,0xd3,0xd0,0x07,0x02,0xe7,0xf0,0x03,0x33,0xa0,0x00,0x71,0x00,0x19,0x43,0xda,0xa9,0x0f,0x09,0x3b,0x08,0x40,0x1e,0xa2,0x81,0xd4,0xc3,0xc7,0x06,0x00,0x79,0x81,0x32,0x00,};
-const uint8_t* const _I_HorizonLine1[] = {_I_HorizonLine1_0};
-
-const Icon I_Dino = {.width=20,.height=22,.frame_count=1,.frame_rate=0,.frames=_I_Dino};
-const Icon I_DinoRun0 = {.width=20,.height=22,.frame_count=1,.frame_rate=0,.frames=_I_DinoRun0};
-const Icon I_DinoRun1 = {.width=20,.height=22,.frame_count=1,.frame_rate=0,.frames=_I_DinoRun1};
-//const Icon I_HorizonLine0 = {.width=600,.height=12,.frame_count=1,.frame_rate=0,.frames=_I_HorizonLine0};
-//const Icon I_HorizonLine1 = {.width=600,.height=12,.frame_count=1,.frame_rate=0,.frames=_I_HorizonLine1};
-

+ 0 - 9
assets_icons.h

@@ -1,9 +0,0 @@
-#pragma once
-
-#include <gui/icon.h>
-
-extern const Icon I_Dino;
-extern const Icon I_DinoRun0;
-extern const Icon I_DinoRun1;
-//extern const Icon I_HorizonLine0;
-//extern const Icon I_HorizonLine1;

BIN
dist/debug/t-rex-runner_d.elf


BIN
dist/t-rex-runner.fap


BIN
imgs/Screenshot-20230504-232830.png


BIN
imgs/Screenshot-20230504-232915.png


BIN
imgs/Screenshot-20230504-233007.png


BIN
imgs/Screenshot-20230504-234841.png


+ 28 - 9
trexrunner.c

@@ -7,10 +7,10 @@
 #include <stdlib.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdio.h>
 
 
-#include "assets_icons.h"
+#include "t-rex-runner_icons.h"
 
 
 #define DINO_START_X 10
 #define DINO_START_X 10
-#define DINO_START_Y 42
+#define DINO_START_Y 35 // 64 - 22 - BACKGROUND_H / 2 - 1
 
 
 #define FPS 20
 #define FPS 20
 
 
@@ -21,7 +21,10 @@
 
 
 #define CACTUS_W 8
 #define CACTUS_W 8
 #define CACTUS_H 10
 #define CACTUS_H 10
-#define START_CACTUS_SPEED 25
+#define START_x_speed 25
+
+#define BACKGROUND_W 176
+#define BACKGROUND_H 12
 
 
 typedef enum {
 typedef enum {
     EventTypeTick,
     EventTypeTick,
@@ -44,12 +47,15 @@ typedef struct {
     float y_position;
     float y_position;
     float y_speed;
     float y_speed;
     int y_acceleration;
     int y_acceleration;
+    float x_speed;
 
 
     // Cactus info
     // Cactus info
     int cactus_position;
     int cactus_position;
-    float cactus_speed;
     int has_cactus;
     int has_cactus;
 
 
+    // Horizontal line
+    int background_position;
+
     int lost;
     int lost;
 } GameState;
 } GameState;
 
 
@@ -91,7 +97,7 @@ static void timer_callback(void *ctx) {
 
 
     // Update Cactus state
     // Update Cactus state
     if (game_state->has_cactus){
     if (game_state->has_cactus){
-        game_state->cactus_position = game_state->cactus_position - game_state->cactus_speed *  delta_time_ms / 1000;
+        game_state->cactus_position = game_state->cactus_position - game_state->x_speed *  delta_time_ms / 1000;
         if (game_state->cactus_position <= CACTUS_W + 1) {
         if (game_state->cactus_position <= CACTUS_W + 1) {
             game_state->has_cactus = 0;
             game_state->has_cactus = 0;
             game_state->cactus_position = 120;
             game_state->cactus_position = 120;
@@ -101,9 +107,14 @@ static void timer_callback(void *ctx) {
     else {
     else {
         game_state->has_cactus = 1;
         game_state->has_cactus = 1;
         game_state->cactus_position = 120;
         game_state->cactus_position = 120;
-        game_state->cactus_speed = START_CACTUS_SPEED;
+        game_state->x_speed = START_x_speed;
     }
     }
 
 
+    // Move horizontal line
+    if (game_state->background_position <= - BACKGROUND_W)
+        game_state->background_position += BACKGROUND_W;
+    game_state->background_position = game_state->background_position - game_state->x_speed * delta_time_ms / 1000;
+
     // Lose condition
     // Lose condition
     if ((game_state->y_position + 22 >= (64 - CACTUS_H)) && ((DINO_START_X+20) >= game_state->cactus_position) && (DINO_START_X <= (game_state->cactus_position + CACTUS_W)))
     if ((game_state->y_position + 22 >= (64 - CACTUS_H)) && ((DINO_START_X+20) >= game_state->cactus_position) && (DINO_START_X <= (game_state->cactus_position + CACTUS_W)))
         game_state->lost = 1;
         game_state->lost = 1;
@@ -127,10 +138,17 @@ static void render_callback(Canvas *const canvas, void *ctx) {
     }
     }
 
 
     if(!game_state->lost){
     if(!game_state->lost){
+        // Show Ground
+        canvas_draw_icon(canvas, game_state->background_position, 64 - BACKGROUND_H, &I_HorizonLine0);
+        canvas_draw_icon(canvas, game_state->background_position + BACKGROUND_W, 64 - BACKGROUND_H, &I_HorizonLine0);
+
+        // Show DINO
         canvas_draw_icon(canvas, DINO_START_X, game_state->y_position, game_state->dino_icon);
         canvas_draw_icon(canvas, DINO_START_X, game_state->y_position, game_state->dino_icon);
 
 
+        // Show cactus
         if (game_state->has_cactus)
         if (game_state->has_cactus)
-            canvas_draw_triangle(canvas, game_state->cactus_position, 63, CACTUS_W, CACTUS_H, CanvasDirectionBottomToTop);
+            canvas_draw_triangle(canvas, game_state->cactus_position, 64 - BACKGROUND_H + CACTUS_W, CACTUS_W, CACTUS_H, CanvasDirectionBottomToTop);
+
     } else {
     } else {
         canvas_set_font(canvas, FontPrimary);
         canvas_set_font(canvas, FontPrimary);
         canvas_draw_str_aligned(canvas, 64, 32, AlignCenter, AlignBottom, "You lost :c");
         canvas_draw_str_aligned(canvas, 64, 32, AlignCenter, AlignBottom, "You lost :c");
@@ -146,6 +164,7 @@ static void game_state_init(GameState *const game_state) {
     game_state->y_acceleration = game_state->y_speed = 0;
     game_state->y_acceleration = game_state->y_speed = 0;
     game_state->y_position = DINO_START_Y;
     game_state->y_position = DINO_START_Y;
     game_state->has_cactus = 0;
     game_state->has_cactus = 0;
+    game_state->background_position = 0;
     game_state->lost = 0;
     game_state->lost = 0;
     game_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
     game_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
 }
 }
@@ -185,11 +204,11 @@ int32_t trexrunner_app() {
                 if (event.input.type == InputTypeShort) {
                 if (event.input.type == InputTypeShort) {
                     switch (event.input.key) {
                     switch (event.input.key) {
                         case InputKeyUp:
                         case InputKeyUp:
-                            //if (game_state->y_position == DINO_START_Y)
+                            // Test command
                                 game_state->y_position -= 10;
                                 game_state->y_position -= 10;
                             break;
                             break;
                         case InputKeyDown:
                         case InputKeyDown:
-                            //if (game_state->y_position == DINO_START_Y)
+                            // Test command
                                 game_state->y_position += 10;
                                 game_state->y_position += 10;
                             break;
                             break;
                         case InputKeyLeft:
                         case InputKeyLeft:

BIN
uncut_assets/HorizonLine0.png


+ 0 - 0
assets/HorizonLine1.png → uncut_assets/HorizonLine1.png