summaryrefslogtreecommitdiff
path: root/keyboards/winry
diff options
context:
space:
mode:
authorTom Parker-Shemilt <palfrey@tevp.net>2023-07-07 15:10:39 +0100
committerGitHub <noreply@github.com>2023-07-08 00:10:39 +1000
commitd7c43dbd9d78ad0fa521692145a8b0dae318c940 (patch)
tree15376b52a95c1ac682f9bc550c27cad30a10d3f9 /keyboards/winry
parentef39ecd1b77feeba9cbe978c7431d0f9ce40010d (diff)
Lights Out keymap for winry25t (#20538)
Co-authored-by: Drashna Jaelre <drashna@live.com>
Diffstat (limited to 'keyboards/winry')
-rw-r--r--keyboards/winry/winry25tc/config.h2
-rw-r--r--keyboards/winry/winry25tc/keymaps/lightsout/keymap.c136
-rw-r--r--keyboards/winry/winry25tc/keymaps/lightsout/readme.md3
3 files changed, 141 insertions, 0 deletions
diff --git a/keyboards/winry/winry25tc/config.h b/keyboards/winry/winry25tc/config.h
index 98c540c876..e668a85218 100644
--- a/keyboards/winry/winry25tc/config.h
+++ b/keyboards/winry/winry25tc/config.h
@@ -20,3 +20,5 @@
20#define RGBLIGHT_HUE_STEP 8 20#define RGBLIGHT_HUE_STEP 8
21#define RGBLIGHT_SAT_STEP 8 21#define RGBLIGHT_SAT_STEP 8
22#define RGBLIGHT_VAL_STEP 8 22#define RGBLIGHT_VAL_STEP 8
23
24#define RGBLIGHT_EFFECT_RAINBOW_SWIRL
diff --git a/keyboards/winry/winry25tc/keymaps/lightsout/keymap.c b/keyboards/winry/winry25tc/keymaps/lightsout/keymap.c
new file mode 100644
index 0000000000..f175f36b91
--- /dev/null
+++ b/keyboards/winry/winry25tc/keymaps/lightsout/keymap.c
@@ -0,0 +1,136 @@
1/* Copyright 2023 Tom Parker-Shemilt <palfrey@tevp.net>
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 */
15
16#include <stdlib.h>
17
18#include QMK_KEYBOARD_H
19
20// clang-format off
21
22// Exact keymap is irrelevant as we're using rows/cols
23// but we need _something_ set so we're using no-ops
24const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
25 [0] = LAYOUT(
26 KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
27 KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
28 KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
29 KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
30 KC_NO, KC_NO, KC_NO, KC_NO, KC_NO
31 )};
32
33bool tiles[5][5] = {
34 {false, false, false, false, false},
35 {false, false, false, false, false},
36 {false, false, false, false, false},
37 {false, false, false, false, false},
38 {false, false, false, false, false},
39};
40
41/* Because snake pattern of leds */
42const uint8_t remap[25] = {
43 20,21,22,23,24,
44 19,6,7,8,9,
45 18,5,0,1,10,
46 17,4,3,2,11,
47 16,15,14,13,12,
48};
49
50// clang-format on
51
52bool is_blank(void) {
53 for (uint8_t y = 0; y < 5; y++) {
54 for (uint8_t x = 0; x < 5; x++) {
55 if (tiles[x][y]) {
56 return false;
57 }
58 }
59 }
60 return true;
61}
62
63void do_move(uint8_t x, uint8_t y) {
64 tiles[x][y] ^= true;
65 if (x > 0) {
66 tiles[x - 1][y] ^= true;
67 }
68 if (y > 0) {
69 tiles[x][y - 1] ^= true;
70 }
71 if (x < 4) {
72 tiles[x + 1][y] ^= true;
73 }
74 if (y < 4) {
75 tiles[x][y + 1] ^= true;
76 }
77}
78
79void refresh_leds(void) {
80 for (uint8_t y = 0; y < 5; y++) {
81 for (uint8_t x = 0; x < 5; x++) {
82 uint8_t tile = tiles[x][y];
83 uint8_t index = (y * 5) + x;
84 if (tile) {
85 setrgb(RGB_RED, &led[remap[index]]);
86 } else {
87 setrgb(RGB_WHITE, &led[remap[index]]);
88 }
89 }
90 }
91 rgblight_set();
92}
93
94uint8_t initial_moves = 1;
95
96void start_game(void) {
97 rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT);
98 srand(timer_read32());
99 while (true) {
100 for (uint8_t i = 0; i < initial_moves; i++) {
101 do_move(rand() % 5, rand() % 5);
102 }
103 if (!is_blank()) {
104 // Catch the "we picked the same location 2*N times" case
105 break;
106 }
107 }
108 refresh_leds();
109}
110
111void keyboard_post_init_user(void) {
112 rgblight_enable_noeeprom();
113 start_game();
114}
115
116bool won = false;
117
118bool process_record_user(uint16_t keycode, keyrecord_t *record) {
119 if (record->event.pressed) {
120 if (won) {
121 initial_moves++;
122 won = false;
123 start_game();
124 } else {
125 uint8_t x = record->event.key.col;
126 uint8_t y = record->event.key.row;
127 do_move(x, y);
128 if (is_blank()) {
129 rgblight_mode(RGBLIGHT_MODE_RAINBOW_SWIRL);
130 won = true;
131 }
132 }
133 }
134 refresh_leds();
135 return true;
136}
diff --git a/keyboards/winry/winry25tc/keymaps/lightsout/readme.md b/keyboards/winry/winry25tc/keymaps/lightsout/readme.md
new file mode 100644
index 0000000000..4271bff43f
--- /dev/null
+++ b/keyboards/winry/winry25tc/keymaps/lightsout/readme.md
@@ -0,0 +1,3 @@
1# Lights Out game
2
3Implements a "lights out" mode as per https://en.m.wikipedia.org/wiki/Lights_Out_(game) with a single move having been played on start. On completion of the game, the Rainbow Swirl pattern is displayed. If another key is then pressed, the game resets, with the initial number of moves incremented by one.