소스 검색

Squashed 'game15/' changes from ef28adca7..dcb9b977f

dcb9b977f fixing some big bugs
9d11784ff update ublox, game15, uart terminal, intervalometer, seader
7e148bcde combine 1
93e333ed5 move base pack here
REVERT: ef28adca7 Merge pull request #2 from FeyXieXzf/main
REVERT: 44f4d4f36 only run timer on first move + typo fix
REVERT: d73ee8893 Merge branch 'dev'
REVERT: a4855e0f2 Del FAP file. Edit README
REVERT: 9b54df44a Save and Restore sate of game on exit/run. Popoup menu for reset.
REVERT: a23c2decd refactoring draw_cell()
REVERT: a42626139 add image file
REVERT: 52c4477b3 first init

git-subtree-dir: game15
git-subtree-split: dcb9b977f81b4407b7987cebaf378434ddb7c7ab
Willy-JL 2 년 전
부모
커밋
10d25ce6d6
5개의 변경된 파일70개의 추가작업 그리고 71개의 파일을 삭제
  1. 2 1
      README.md
  2. 3 1
      application.fam
  3. 51 52
      game15.c
  4. BIN
      img/1.png
  5. 14 17
      sandbox.c

+ 2 - 1
README.md

@@ -1,6 +1,8 @@
 
 # Game "15" for Flipper Zero
 
+[Original link](https://github.com/x27/flipperzero-game15)
+
 Logic game [Wikipedia](https://en.wikipedia.org/wiki/15_puzzle)
 
 ![Game screen](images/Game15.png)
@@ -9,4 +11,3 @@ Logic game [Wikipedia](https://en.wikipedia.org/wiki/15_puzzle)
 
 ![Popoup](images/Game15Popup.png)
 
-FAP file for firmware 0.69.1

+ 3 - 1
application.fam

@@ -3,10 +3,12 @@ App(
     name="Game 15",
     apptype=FlipperAppType.EXTERNAL,
     entry_point="game15_app",
-    cdefines=["APP_GAME15"],
     requires=["gui"],
     stack_size=1 * 1024,
     fap_icon="game15_10px.png",
     order=30,
     fap_category="Games",
+    fap_author="@x27",
+    fap_version="1.1",
+    fap_description="Logic Game",
 )

+ 51 - 52
game15.c

@@ -3,6 +3,7 @@
 #include <notification/notification.h>
 #include <notification/notification_messages.h>
 #include <storage/storage.h>
+#include <dolphin/dolphin.h>
 
 #include "sandbox.h"
 
@@ -46,10 +47,7 @@ static moving_cell_t moving_cell;
 static uint8_t loaded_saving_ticks;
 static uint8_t popup_menu_selected_item;
 
-static const char* popup_menu_strings[] = {
-    "Continue",
-    "Reset"
-};
+static const char* popup_menu_strings[] = {"Continue", "Reset"};
 
 static uint8_t keys[KEY_STACK_SIZE];
 static uint8_t key_stack_head = 0;
@@ -263,27 +261,25 @@ static void game_tick() {
         break;
 
     case ScenePopup:
-        if (!key_stack_is_empty()) {
-            switch(key_stack_pop())
-            {
-                case DirectionDown:
-                    popup_menu_selected_item++;
-                    popup_menu_selected_item = popup_menu_selected_item % POPUP_MENU_ITEMS;
-                    break;
-                case DirectionUp:
-                    popup_menu_selected_item--;
-                    popup_menu_selected_item = popup_menu_selected_item % POPUP_MENU_ITEMS;
-                    break;
-                case DirectionNone:
-                    if (popup_menu_selected_item == 0) {
-                        game_state.scene = ScenePlay;
-                        notification_message(notification, &sequence_single_vibro);
-                    }
-                    else if (popup_menu_selected_item == 1) {
-                        notification_message(notification, &sequence_single_vibro);
-                        game_init();
-                    }
-                    break;
+        if(!key_stack_is_empty()) {
+            switch(key_stack_pop()) {
+            case DirectionDown:
+                popup_menu_selected_item++;
+                popup_menu_selected_item = popup_menu_selected_item % POPUP_MENU_ITEMS;
+                break;
+            case DirectionUp:
+                popup_menu_selected_item--;
+                popup_menu_selected_item = popup_menu_selected_item % POPUP_MENU_ITEMS;
+                break;
+            case DirectionNone:
+                if(popup_menu_selected_item == 0) {
+                    game_state.scene = ScenePlay;
+                    notification_message(notification, &sequence_single_vibro);
+                } else if(popup_menu_selected_item == 1) {
+                    notification_message(notification, &sequence_single_vibro);
+                    game_init();
+                }
+                break;
             }
         }
         break;
@@ -358,12 +354,13 @@ static void render_callback(Canvas* const canvas) {
     canvas_set_color(canvas, ColorWhite);
     canvas_draw_box(canvas, 0, 0, 128, 64);
 
-    if(game_state.scene == ScenePlay || game_state.scene == SceneWin || game_state.scene == ScenePopup) {
+    if(game_state.scene == ScenePlay || game_state.scene == SceneWin ||
+       game_state.scene == ScenePopup) {
         canvas_set_color(canvas, ColorBlack);
         board_draw(canvas);
         info_draw(canvas);
 
-        if (loaded_saving_ticks && game_state.scene != ScenePopup) {
+        if(loaded_saving_ticks && game_state.scene != ScenePopup) {
             canvas_set_color(canvas, ColorWhite);
             canvas_draw_rbox(canvas, 20, 24, 88, 16, 4);
             canvas_set_color(canvas, ColorBlack);
@@ -381,23 +378,23 @@ static void render_callback(Canvas* const canvas) {
         canvas_draw_box(canvas, 10, 23, 108, 18);
         canvas_set_color(canvas, ColorBlack);
         canvas_draw_xbm(canvas, 14, 27, 100, 10, pic_puzzled);
-    }
-    else if (game_state.scene == ScenePopup) {
-            gray_screen(canvas);
-            canvas_set_color(canvas, ColorWhite);
-            canvas_draw_rbox(canvas, 28, 16, 72, 32, 4);
-            canvas_set_color(canvas, ColorBlack);
-            canvas_draw_rframe(canvas, 28, 16, 72, 32, 4);
+    } else if(game_state.scene == ScenePopup) {
+        gray_screen(canvas);
+        canvas_set_color(canvas, ColorWhite);
+        canvas_draw_rbox(canvas, 28, 16, 72, 32, 4);
+        canvas_set_color(canvas, ColorBlack);
+        canvas_draw_rframe(canvas, 28, 16, 72, 32, 4);
 
-            for(int i=0; i < POPUP_MENU_ITEMS; i++) {
-                if ( i ==  popup_menu_selected_item) {
-                    canvas_set_color(canvas, ColorBlack);
-                    canvas_draw_box(canvas, 34, 20 + 12 * i, 60, 12);
-                }
-                
-                canvas_set_color(canvas, i == popup_menu_selected_item ? ColorWhite : ColorBlack);
-                canvas_draw_str_aligned(canvas, 64, 26 + 12 * i, AlignCenter, AlignCenter, popup_menu_strings[i]);
+        for(int i = 0; i < POPUP_MENU_ITEMS; i++) {
+            if(i == popup_menu_selected_item) {
+                canvas_set_color(canvas, ColorBlack);
+                canvas_draw_box(canvas, 34, 20 + 12 * i, 60, 12);
             }
+
+            canvas_set_color(canvas, i == popup_menu_selected_item ? ColorWhite : ColorBlack);
+            canvas_draw_str_aligned(
+                canvas, 64, 26 + 12 * i, AlignCenter, AlignCenter, popup_menu_strings[i]);
+        }
     }
 }
 
@@ -418,22 +415,22 @@ static void game_event_handler(GameEvent const event) {
                 key_stack_push(DirectionLeft);
                 break;
             case InputKeyOk:
-                if (game_state.scene == ScenePlay) {
+                if(game_state.scene == ScenePlay) {
                     game_state.scene = ScenePopup;
                     key_stack_init();
-                } 
-                else
+                } else
                     key_stack_push(DirectionNone);
                 break;
             case InputKeyBack:
-                if (game_state.scene == ScenePopup) {
+                if(game_state.scene == ScenePopup) {
                     game_state.scene = ScenePlay;
-                }
-                else {
+                } else {
                     storage_game_state_save();
                     sandbox_loop_exit();
                 }
                 break;
+            default:
+                break;
             }
         }
     } else if(event.type == EventTypeTick) {
@@ -442,7 +439,6 @@ static void game_event_handler(GameEvent const event) {
 }
 
 static void game_alloc() {
-    srand(DWT->CYCCNT);
     key_stack_init();
     notification = furi_record_open(RECORD_NOTIFICATION);
     notification_message_block(notification, &sequence_display_backlight_enforce_on);
@@ -459,16 +455,19 @@ int32_t game15_app() {
 
     loaded_saving_ticks = 0;
     if(storage_game_state_load()) {
-        if (game_state.scene != ScenePlay) 
+        if(game_state.scene != ScenePlay)
             game_init();
         else
             loaded_saving_ticks = FPS;
-    }
-    else 
+    } else
         game_init();
 
     sandbox_init(
         FPS, (SandboxRenderCallback)render_callback, (SandboxEventHandler)game_event_handler);
+
+    // Call dolphin deed on game start
+    dolphin_deed(DolphinDeedPluginGameStart);
+
     sandbox_loop();
     sandbox_free();
     game_free();

BIN
img/1.png


+ 14 - 17
sandbox.c

@@ -13,11 +13,9 @@ SandboxEventHandler sandbox_user_event_handler;
 
 static void sandbox_render_callback(Canvas* const canvas, void* context) {
     UNUSED(context);
-    if (furi_mutex_acquire(sandbox_mutex, 25) != FuriStatusOk)
-        return;
+    if(furi_mutex_acquire(sandbox_mutex, 25) != FuriStatusOk) return;
 
-    if (sandbox_user_render_callback)
-        sandbox_user_render_callback(canvas);
+    if(sandbox_user_render_callback) sandbox_user_render_callback(canvas);
 
     furi_mutex_release(sandbox_mutex);
 }
@@ -28,7 +26,7 @@ static void sandbox_input_callback(InputEvent* input_event, void* context) {
     furi_message_queue_put(sandbox_event_queue, &event, FuriWaitForever);
 }
 
-static void sandbox_timer_callback(void* context ) {
+static void sandbox_timer_callback(void* context) {
     UNUSED(context);
     GameEvent event = {.type = EventTypeTick};
     furi_message_queue_put(sandbox_event_queue, &event, 0);
@@ -36,21 +34,20 @@ static void sandbox_timer_callback(void* context ) {
 
 void sandbox_loop() {
     sandbox_loop_processing = true;
-    while( sandbox_loop_processing ) {
+    while(sandbox_loop_processing) {
         GameEvent event;
         FuriStatus event_status = furi_message_queue_get(sandbox_event_queue, &event, 100);
-        if (event_status != FuriStatusOk) {
+        if(event_status != FuriStatusOk) {
             // timeout
             continue;
         }
 
         furi_mutex_acquire(sandbox_mutex, FuriWaitForever);
 
-        if (sandbox_user_event_handler)
-            sandbox_user_event_handler(event);
+        if(sandbox_user_event_handler) sandbox_user_event_handler(event);
 
-        view_port_update(sandbox_view_port);
         furi_mutex_release(sandbox_mutex);
+        view_port_update(sandbox_view_port);
     }
 }
 
@@ -58,8 +55,10 @@ void sandbox_loop_exit() {
     sandbox_loop_processing = false;
 }
 
-void sandbox_init(uint8_t fps, SandboxRenderCallback u_render_callback, SandboxEventHandler u_event_handler)
-{
+void sandbox_init(
+    uint8_t fps,
+    SandboxRenderCallback u_render_callback,
+    SandboxEventHandler u_event_handler) {
     sandbox_user_render_callback = u_render_callback;
     sandbox_user_event_handler = u_event_handler;
 
@@ -73,17 +72,15 @@ void sandbox_init(uint8_t fps, SandboxRenderCallback u_render_callback, SandboxE
     sandbox_gui = furi_record_open(RECORD_GUI);
     gui_add_view_port(sandbox_gui, sandbox_view_port, GuiLayerFullscreen);
 
-    if (fps > 0) {
+    if(fps > 0) {
         sandbox_timer = furi_timer_alloc(sandbox_timer_callback, FuriTimerTypePeriodic, NULL);
         furi_timer_start(sandbox_timer, furi_kernel_get_tick_frequency() / fps);
     } else
         sandbox_timer = NULL;
 }
 
-void sandbox_free()
-{
-    if (sandbox_timer)    
-        furi_timer_free(sandbox_timer);
+void sandbox_free() {
+    if(sandbox_timer) furi_timer_free(sandbox_timer);
 
     gui_remove_view_port(sandbox_gui, sandbox_view_port);
     view_port_enabled_set(sandbox_view_port, false);