MX 2 лет назад
Родитель
Сommit
eaf07d8434
2 измененных файлов с 19 добавлено и 11 удалено
  1. 2 3
      README.md
  2. 17 8
      trexrunner.c

+ 2 - 3
README.md

@@ -4,14 +4,13 @@ Flipper Zero port of Chrome's running T-rex game
 ## Improvements
 - Added command to move DINO
 - Added gravity
-- Added (boring) cactus spawn
 - Added lose condition and lose screen
 - Added moving background
 - Added score system
+- Random cactus spawn
+- Increase cactus speed with time
 
 ## TODO
-- More random cactus spawn
-- Increase cactus speed with time
 - Fix background speed with cactus
 - Allow to play again without the need to close the game in the lose screen
 

+ 17 - 8
trexrunner.c

@@ -1,5 +1,6 @@
 #include <furi.h>
 #include <furi_hal.h>
+#include <furi_hal_random.h>
 #include <gui/gui.h>
 #include <gui/icon_i.h>
 #include <gui/elements.h>
@@ -21,7 +22,8 @@
 
 #define CACTUS_W 10
 #define CACTUS_H 10
-#define START_x_speed 25
+#define START_x_speed 35
+#define X_INCREASE 3
 
 #define BACKGROUND_W 128
 #define BACKGROUND_H 12
@@ -100,16 +102,23 @@ static void timer_callback(void* ctx) {
     // Update Cactus state
     if(game_state->has_cactus) {
         game_state->cactus_position =
-            game_state->cactus_position - game_state->x_speed * delta_time_ms / 1000;
+            game_state->cactus_position - (game_state->x_speed - 15) * delta_time_ms / 1000;
         if(game_state->cactus_position <= 0) {
             game_state->has_cactus = 0;
             game_state->score = game_state->score + 1;
+
+            // Increase speed
+            game_state->x_speed = game_state->x_speed + X_INCREASE;
         }
     }
-    // Create cactus (not random)
+    // Create cactus (random frame in 1.5s)
     else {
-        game_state->has_cactus = 1;
-        game_state->cactus_position = 120;
+        uint8_t randomuint8[1];
+        furi_hal_random_fill_buf(randomuint8, 1);
+        if(randomuint8[0] % 30 == 0) {
+            game_state->has_cactus = 1;
+            game_state->cactus_position = 120;
+        }
     }
 
     // Move horizontal line
@@ -119,9 +128,9 @@ static void timer_callback(void* ctx) {
         game_state->background_position - game_state->x_speed * delta_time_ms / 1000;
 
     // 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->has_cactus && ((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;
 
     furi_mutex_release(game_state->mutex);