Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Commit

Permalink
Squashed 'game15/' changes from ef28adc..dcb9b97
Browse files Browse the repository at this point in the history
dcb9b97 fixing some big bugs
9d11784 update ublox, game15, uart terminal, intervalometer, seader
7e148bc combine 1
93e333e move base pack here
REVERT: ef28adc Merge pull request #2 from FeyXieXzf/main
REVERT: 44f4d4f only run timer on first move + typo fix
REVERT: d73ee88 Merge branch 'dev'
REVERT: a4855e0 Del FAP file. Edit README
REVERT: 9b54df4 Save and Restore sate of game on exit/run. Popoup menu for reset.
REVERT: a23c2de refactoring draw_cell()
REVERT: a426261 add image file
REVERT: 52c4477 first init

git-subtree-dir: game15
git-subtree-split: dcb9b97
  • Loading branch information
Willy-JL committed Nov 12, 2023
1 parent ef28adc commit 10d25ce
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 71 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
4 changes: 3 additions & 1 deletion application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
103 changes: 51 additions & 52 deletions game15.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <notification/notification.h>
#include <notification/notification_messages.h>
#include <storage/storage.h>
#include <dolphin/dolphin.h>

#include "sandbox.h"

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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]);
}
}
}

Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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();
Expand Down
Binary file added img/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 14 additions & 17 deletions sandbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -28,38 +26,39 @@ 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);
}

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);
}
}

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;

Expand All @@ -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);
Expand Down

0 comments on commit 10d25ce

Please sign in to comment.