From b8aa5feab016f257bbbfe98275a272f8244fc53b Mon Sep 17 00:00:00 2001 From: Felix Pankratz Date: Thu, 22 Sep 2022 01:10:21 +0200 Subject: [PATCH] initial commit, drawing cells --- .assets.h.swp | Bin 0 -> 12288 bytes application.fam | 11 +++ assets.h | 4 ++ assets/mockup.png | Bin 0 -> 400 bytes assets/tile_0.png | Bin 0 -> 148 bytes assets/tile_1.png | Bin 0 -> 155 bytes assets/tile_2.png | Bin 0 -> 164 bytes assets/tile_3.png | Bin 0 -> 162 bytes assets/tile_4.png | Bin 0 -> 162 bytes assets/tile_5.png | Bin 0 -> 164 bytes assets/tile_6.png | Bin 0 -> 173 bytes assets/tile_7.png | Bin 0 -> 168 bytes assets/tile_8.png | Bin 0 -> 166 bytes assets/tile_empty.png | Bin 0 -> 131 bytes assets/tile_flag.png | Bin 0 -> 170 bytes assets/tile_mine.png | Bin 0 -> 152 bytes assets/tile_uncleared.png | Bin 0 -> 127 bytes assets/tile_uncleared.xbm | 4 ++ minesweeper.c | 147 ++++++++++++++++++++++++++++++++++++++ 19 files changed, 166 insertions(+) create mode 100644 .assets.h.swp create mode 100644 application.fam create mode 100644 assets.h create mode 100644 assets/mockup.png create mode 100644 assets/tile_0.png create mode 100644 assets/tile_1.png create mode 100644 assets/tile_2.png create mode 100644 assets/tile_3.png create mode 100644 assets/tile_4.png create mode 100644 assets/tile_5.png create mode 100644 assets/tile_6.png create mode 100644 assets/tile_7.png create mode 100644 assets/tile_8.png create mode 100644 assets/tile_empty.png create mode 100644 assets/tile_flag.png create mode 100644 assets/tile_mine.png create mode 100644 assets/tile_uncleared.png create mode 100644 assets/tile_uncleared.xbm create mode 100644 minesweeper.c diff --git a/.assets.h.swp b/.assets.h.swp new file mode 100644 index 0000000000000000000000000000000000000000..3566dca0bfa835a4d8030e4f28c444a977aa662e GIT binary patch literal 12288 zcmeI&%}T>S5C`z7dKE=qV6{hW($cV^IR3ve5Z<0E7Cd|-84~TS5J?`@|NrUv|C876 zJf0`DpsFJv009U<00Izz00bZa0SG_<0ucCFKyY+!yWMS`J$L?Gbw2Eqv3v(U5T(wn v=UZWQqWm%o62+I~Lw~5Pxx5kw;+~qJiui_ny(3ooI<~_5tv=SFjk){Nn{1`ISV`@iy0XB4ude`@%$AjKn<#%E{-7;ac?hg|U>wZs4b literal 0 HcmV?d00001 diff --git a/assets/tile_0.png b/assets/tile_0.png new file mode 100644 index 0000000000000000000000000000000000000000..21cd190a7a2a3e2eacd60635216039744d952381 GIT binary patch literal 148 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBufiR<}hF1enP}9@JF+?LcIVB;=R-a)WqQF>gTe~DWM4f__QLG literal 0 HcmV?d00001 diff --git a/assets/tile_1.png b/assets/tile_1.png new file mode 100644 index 0000000000000000000000000000000000000000..e887fa9ad57c2a4459cf77b5c82d1ae4544baac1 GIT binary patch literal 155 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1SGw4HSYi^#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=DjSL74G){)!Z!pn<20V~9j}a!NwNkN^MeC%CZnI5g;Vok?v9 va9|K=-E@FKu`x}-iHUcDUgP1NJv|Huy7;-D1_cWO^)h(6`njxgN@xNA4Bjfj literal 0 HcmV?d00001 diff --git a/assets/tile_2.png b/assets/tile_2.png new file mode 100644 index 0000000000000000000000000000000000000000..423d097c53d006136b07243e7c9afc51c2db0258 GIT binary patch literal 164 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1SGw4HSYi^#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=DjSL74G){)!Z!prxmaV~9j}YEK{+g8_$A@%R0kg?YN)*0#*- zT&1*fXX6I#MD2xkEiV1v=l?9Y9X++pfc^cVxhr@ZxV`O^f4{fd`2uJNgQu&X%Q~lo FCIAlIGN=Fm literal 0 HcmV?d00001 diff --git a/assets/tile_3.png b/assets/tile_3.png new file mode 100644 index 0000000000000000000000000000000000000000..f6d678446fed0560f69d10e0de2abcd3c16882fc GIT binary patch literal 162 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1SGw4HSYi^#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=DjSL74G){)!Z!pt+}uV~9j}a!NwNkN^MeC%CZnI4}sZ8Ywsx zxCU@qG-#(beK2HnVn1SX$nBtp&*_Pl1qV)?;9#&cRsLO8=P(&)1cRrmpUXO@geCw4 CtSrm` literal 0 HcmV?d00001 diff --git a/assets/tile_4.png b/assets/tile_4.png new file mode 100644 index 0000000000000000000000000000000000000000..4ac276ed1dde9bb81a29592a71559aa002fe999f GIT binary patch literal 162 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1SGw4HSYi^#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=DjSL74G){)!Z!pt+}uV~9j}a!NwNkN^MeC%CZnI4}sd8b4^@ z^lD}dkUHfw*@2CNv!iH-n#kgbxrZ`E_?{aXF)^^86%ycoz&s0R1cRrmpUXO@geCy` Cs4D{i literal 0 HcmV?d00001 diff --git a/assets/tile_5.png b/assets/tile_5.png new file mode 100644 index 0000000000000000000000000000000000000000..22fad623f915bde27c43ef8e4b16dcee2c86f95a GIT binary patch literal 164 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1SGw4HSYi^#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=DjSL74G){)!Z!prxmaV~9j}a!NwNkN^MeC%CZnI4}sZ8YwtA zFo-sKFL;^UbV=Z?$FB>bhqfw}EMP1-{gCZJfu6E5!_n(&i2F5!nj P(-=Hm{an^LB{Ts5kn%H( literal 0 HcmV?d00001 diff --git a/assets/tile_7.png b/assets/tile_7.png new file mode 100644 index 0000000000000000000000000000000000000000..385dbb38897d58bdeb26d83bc77019be7bf04286 GIT binary patch literal 168 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBufiR<}hF1en(ALw%F+?M{wV#oTL4kvL`@jFsiw+)|^ufV( zZWoI|Gl%G;1-reB&L@R$MOMdVc^;zbftje!s|C?UAqXRUE!PC{x JWt~$(697e9Fhc+U literal 0 HcmV?d00001 diff --git a/assets/tile_8.png b/assets/tile_8.png new file mode 100644 index 0000000000000000000000000000000000000000..2e59014a553b8e080b3998a707eb08fe73e8607e GIT binary patch literal 166 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBufiR<}hF1en(Av|*F+?MHY41fY1_ci0^1uJ>r+0HHFKXvY z+2HFM#Ovh8FfmwKO@GQl+mZ(}T|d_+issqG-#9s!*MZkaU*q4*xi=$##xQug`njxg HN@xNAnS(Au literal 0 HcmV?d00001 diff --git a/assets/tile_empty.png b/assets/tile_empty.png new file mode 100644 index 0000000000000000000000000000000000000000..1f48880fbe2e606a88491c357c69a66515f79bcc GIT binary patch literal 131 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1SGw4HSYi^#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=DjSL74G){)!Z!poFK3V~9j}GDFjU35MMoEIeyi%AOk;0F_MI V?3?*H{vc2dgQu&X%Q~loCIJ57AM*eJ literal 0 HcmV?d00001 diff --git a/assets/tile_flag.png b/assets/tile_flag.png new file mode 100644 index 0000000000000000000000000000000000000000..6ec2a71f82b3a8d3f0b4923b1693241933be52b9 GIT binary patch literal 170 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBufiR<}hF1en(B9L?Q`cmH2X`)4vG&WJ}Z rRN8Ud{7Y^V-Y(xFnDSdQ*M^;&xov*ptM1)7K#dHZu6{1-oD!M!lvI6;>1s;*b3=DjSL74G){)!Z!popi7V~9j}@&WdL$qfe;8d(htfGYX2r&gWJ R{{xg~@O1TaS?83{1OSrF9}EBh literal 0 HcmV?d00001 diff --git a/assets/tile_uncleared.xbm b/assets/tile_uncleared.xbm new file mode 100644 index 0000000..ad05436 --- /dev/null +++ b/assets/tile_uncleared.xbm @@ -0,0 +1,4 @@ +#define tile_uncleared_width 8 +#define tile_uncleared_height 8 +static char tile_uncleared_bits[] = { + 0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF, }; diff --git a/minesweeper.c b/minesweeper.c new file mode 100644 index 0000000..7c0e2ff --- /dev/null +++ b/minesweeper.c @@ -0,0 +1,147 @@ +#include +#include +#include +#include +#include + +#include "assets.h" + +#define PLAYFIELD_WIDTH 16 +#define PLAYFIELD_HEIGHT 7 +#define TILE_WIDTH 8 +#define TILE_HEIGHT 8 + +typedef enum { + EventTypeTick, + EventTypeKey, +} EventType; + +typedef struct { + EventType type; + InputEvent input; +} PluginEvent; + +typedef enum { + TileTypeUncleared, + TileTypeCleared, + TileType0, + TileType1, + TileType2, + TileType3, + TileType4, + TileType5, + TileType6, + TileType7, + TileType8, + TileTypeFlag, + TileTypeMine +} TileType; + +typedef enum { + FieldMine, + FieldEmpty +} Field; + +typedef struct { + Field minefield[PLAYFIELD_WIDTH][PLAYFIELD_HEIGHT]; + TileType playfield[PLAYFIELD_WIDTH][PLAYFIELD_HEIGHT]; +} Minesweeper; + +static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { + furi_assert(event_queue); + + PluginEvent event = {.type = EventTypeKey, .input = *input_event}; + furi_message_queue_put(event_queue, &event, FuriWaitForever); +} + +static void render_callback(Canvas* const canvas, void* ctx) { + const Minesweeper* minesweeper_state = acquire_mutex((ValueMutex*)ctx, 25); + if (minesweeper_state == NULL) { + return; + } + canvas_set_font(canvas, FontPrimary); + for (int y = 0; y < PLAYFIELD_HEIGHT; y++) { + for (int x = 0; x < PLAYFIELD_WIDTH; x++) { + canvas_draw_xbm( + canvas, + x*TILE_HEIGHT, // x + 8 + (y * TILE_WIDTH), // y + TILE_WIDTH, + TILE_HEIGHT, + tile_uncleared_bits); + } + } + release_mutex((ValueMutex*)ctx, minesweeper_state); +} + + +//static void minesweeper_state_init(Minesweeper* const plugin_state) { +// +//} + +int32_t minesweeper_app(void* p) { + UNUSED(p); + + FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent)); + + Minesweeper* minesweeper_state = malloc(sizeof(Minesweeper)); + // setup + //minesweeper_state_init(minesweeper_state); + + ValueMutex state_mutex; + if (!init_mutex(&state_mutex, minesweeper_state, sizeof(minesweeper_state))) { + FURI_LOG_E("Minesweeper", "cannot create mutex\r\n"); + free(minesweeper_state); + return 255; + } + // BEGIN IMPLEMENTATION + + // Set system callbacks + ViewPort* view_port = view_port_alloc(); + view_port_draw_callback_set(view_port, render_callback, &state_mutex); + view_port_input_callback_set(view_port, input_callback, event_queue); + + // Open GUI and register view_port + Gui* gui = furi_record_open("gui"); + gui_add_view_port(gui, view_port, GuiLayerFullscreen); + + PluginEvent event; + for (bool processing = true; processing;) { + FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); + Minesweeper* minesweeper_state = (Minesweeper*)acquire_mutex_block(&state_mutex); + if(event_status == FuriStatusOk) { + // press events + if(event.type == EventTypeKey) { + if(event.input.type == InputTypePress) { + switch(event.input.key) { + case InputKeyUp: + case InputKeyDown: + case InputKeyRight: + case InputKeyLeft: + case InputKeyOk: + break; + case InputKeyBack: + // Exit the plugin + processing = false; + break; + } + } + } + } else { + FURI_LOG_D("Minesweeper", "FuriMessageQueue: event timeout"); + // event timeout + } + view_port_update(view_port); + release_mutex(&state_mutex, minesweeper_state); + } + view_port_enabled_set(view_port, false); + gui_remove_view_port(gui, view_port); + furi_record_close("gui"); + view_port_free(view_port); + furi_message_queue_free(event_queue); + delete_mutex(&state_mutex); + free(minesweeper_state); + + return 0; +} +