moving cursor

flagsbased-uncover
Felix Pankratz 2 years ago
parent b8aa5feab0
commit b3ec5e7aa6

@ -1,6 +1,6 @@
App( App(
appid="minesweeper", appid="minesweeper",
name="BPM Tapper", name="Minesweeper",
apptype=FlipperAppType.PLUGIN, apptype=FlipperAppType.PLUGIN,
entry_point="minesweeper_app", entry_point="minesweeper_app",
cdefines=["APP_MINESWEEPER"], cdefines=["APP_MINESWEEPER"],

@ -45,6 +45,8 @@ typedef enum {
typedef struct { typedef struct {
Field minefield[PLAYFIELD_WIDTH][PLAYFIELD_HEIGHT]; Field minefield[PLAYFIELD_WIDTH][PLAYFIELD_HEIGHT];
TileType playfield[PLAYFIELD_WIDTH][PLAYFIELD_HEIGHT]; TileType playfield[PLAYFIELD_WIDTH][PLAYFIELD_HEIGHT];
int cursor_cell_x;
int cursor_cell_y;
} Minesweeper; } Minesweeper;
static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
@ -62,6 +64,9 @@ static void render_callback(Canvas* const canvas, void* ctx) {
canvas_set_font(canvas, FontPrimary); canvas_set_font(canvas, FontPrimary);
for (int y = 0; y < PLAYFIELD_HEIGHT; y++) { for (int y = 0; y < PLAYFIELD_HEIGHT; y++) {
for (int x = 0; x < PLAYFIELD_WIDTH; x++) { for (int x = 0; x < PLAYFIELD_WIDTH; x++) {
if ( x == minesweeper_state->cursor_cell_x && y == minesweeper_state->cursor_cell_y) {
canvas_invert_color(canvas);
}
canvas_draw_xbm( canvas_draw_xbm(
canvas, canvas,
x*TILE_HEIGHT, // x x*TILE_HEIGHT, // x
@ -69,15 +74,18 @@ static void render_callback(Canvas* const canvas, void* ctx) {
TILE_WIDTH, TILE_WIDTH,
TILE_HEIGHT, TILE_HEIGHT,
tile_uncleared_bits); tile_uncleared_bits);
if ( x == minesweeper_state->cursor_cell_x && y == minesweeper_state->cursor_cell_y) {
canvas_invert_color(canvas);
}
} }
} }
release_mutex((ValueMutex*)ctx, minesweeper_state); release_mutex((ValueMutex*)ctx, minesweeper_state);
} }
//static void minesweeper_state_init(Minesweeper* const plugin_state) { static void minesweeper_state_init(Minesweeper* const plugin_state) {
// plugin_state->cursor_cell_x = plugin_state->cursor_cell_y = 0;
//} }
int32_t minesweeper_app(void* p) { int32_t minesweeper_app(void* p) {
UNUSED(p); UNUSED(p);
@ -86,7 +94,7 @@ int32_t minesweeper_app(void* p) {
Minesweeper* minesweeper_state = malloc(sizeof(Minesweeper)); Minesweeper* minesweeper_state = malloc(sizeof(Minesweeper));
// setup // setup
//minesweeper_state_init(minesweeper_state); minesweeper_state_init(minesweeper_state);
ValueMutex state_mutex; ValueMutex state_mutex;
if (!init_mutex(&state_mutex, minesweeper_state, sizeof(minesweeper_state))) { if (!init_mutex(&state_mutex, minesweeper_state, sizeof(minesweeper_state))) {
@ -115,9 +123,29 @@ int32_t minesweeper_app(void* p) {
if(event.input.type == InputTypePress) { if(event.input.type == InputTypePress) {
switch(event.input.key) { switch(event.input.key) {
case InputKeyUp: case InputKeyUp:
minesweeper_state->cursor_cell_y--;
if(minesweeper_state->cursor_cell_y < 0) {
minesweeper_state->cursor_cell_y = 0;
}
break;
case InputKeyDown: case InputKeyDown:
minesweeper_state->cursor_cell_y++;
if(minesweeper_state->cursor_cell_y > PLAYFIELD_HEIGHT) {
minesweeper_state->cursor_cell_y = PLAYFIELD_HEIGHT;
}
break;
case InputKeyRight: case InputKeyRight:
minesweeper_state->cursor_cell_x++;
if(minesweeper_state->cursor_cell_x > PLAYFIELD_WIDTH) {
minesweeper_state->cursor_cell_x = PLAYFIELD_WIDTH;
}
break;
case InputKeyLeft: case InputKeyLeft:
minesweeper_state->cursor_cell_x--;
if(minesweeper_state->cursor_cell_x < 0) {
minesweeper_state->cursor_cell_x = 0;
}
break;
case InputKeyOk: case InputKeyOk:
break; break;
case InputKeyBack: case InputKeyBack:

Loading…
Cancel
Save