diff options
| author | swreinehr <swreinehr@mymail.mines.edu> | 2020-03-06 17:15:44 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-07 00:15:44 +0000 |
| commit | 57de9e65ef58ad72c88830a57e68b1203a3e8f9a (patch) | |
| tree | 470671cf01b3b6e4f23d28d9a804d85a2f8c3eb4 /keyboards/1upkeyboards | |
| parent | 6b6e47cbf1fd700010432105843f194cb4cbd895 (diff) | |
| download | qmk_firmware-57de9e65ef58ad72c88830a57e68b1203a3e8f9a.tar.gz qmk_firmware-57de9e65ef58ad72c88830a57e68b1203a3e8f9a.zip | |
Super 16 Puzzle Game (#8306)
* 15/16 game with lights for the super 16
* Updated readme with style
* adding comments and initial style to keymap
trying to make the code look prettier, need to test by redownloading
* Final style revisions before pull request
* formatting changes, removed config.h
* modified rules.mk, works with changes in PR8314
* formatting
no number of spaces is enough for a newline, whoops
Co-Authored-By: Ryan <fauxpark@gmail.com>
* Update keyboards/1upkeyboards/super16/keymaps/15game/keymap.c
Co-Authored-By: Ryan <fauxpark@gmail.com>
* Update keyboards/1upkeyboards/super16/keymaps/15game/keymap.c
Co-Authored-By: Ryan <fauxpark@gmail.com>
* Update keyboards/1upkeyboards/super16/keymaps/15game/keymap.c
Co-Authored-By: Ryan <fauxpark@gmail.com>
Co-authored-by: Sam Reinehr <swreinehr@mines.edu>
Co-authored-by: Ryan <fauxpark@gmail.com>
Diffstat (limited to 'keyboards/1upkeyboards')
3 files changed, 117 insertions, 0 deletions
diff --git a/keyboards/1upkeyboards/super16/keymaps/15game/keymap.c b/keyboards/1upkeyboards/super16/keymaps/15game/keymap.c new file mode 100644 index 000000000..5988a7cf0 --- /dev/null +++ b/keyboards/1upkeyboards/super16/keymaps/15game/keymap.c | |||
| @@ -0,0 +1,110 @@ | |||
| 1 | /* Copyright 2020 Sam Reinehr | ||
| 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, either version 2 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #include QMK_KEYBOARD_H | ||
| 17 | enum my_keycodes { | ||
| 18 | K00 = SAFE_RANGE, | ||
| 19 | K01, | ||
| 20 | K02, | ||
| 21 | K03, | ||
| 22 | K04, | ||
| 23 | K05, | ||
| 24 | K06, | ||
| 25 | K07, | ||
| 26 | K08, | ||
| 27 | K09, | ||
| 28 | K10, | ||
| 29 | K11, | ||
| 30 | K12, | ||
| 31 | K13, | ||
| 32 | K14, | ||
| 33 | K15, | ||
| 34 | }; | ||
| 35 | /* just a simple way to give each key a unique code */ | ||
| 36 | //clang-format off | ||
| 37 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | ||
| 38 | /* Base */ | ||
| 39 | [0] = LAYOUT_ortho_4x4( | ||
| 40 | K00, K01, K02, K03, | ||
| 41 | K04, K05, K06, K07, | ||
| 42 | K08, K09, K10, K11, | ||
| 43 | K12, K13, K14, K15 | ||
| 44 | ) | ||
| 45 | }; | ||
| 46 | /* flags describing current free square/0 */ | ||
| 47 | uint8_t current = 0; | ||
| 48 | /* r g and b describe the colors for the initial map, | ||
| 49 | currently blank for free, and evenly spaced hues with maximum sat/value */ | ||
| 50 | const uint8_t r[16] = { | ||
| 51 | 0x00, 0xFF, 0xFF, 0xFF, | ||
| 52 | 0xCC, 0x66, 0x00, 0x00, | ||
| 53 | 0x00, 0x00, 0x00, 0x00, | ||
| 54 | 0x66, 0xCC, 0xFF, 0xFF | ||
| 55 | }; | ||
| 56 | const uint8_t g[16] = { | ||
| 57 | 0x00, 0x00, 0x66, 0xCC, | ||
| 58 | 0xFF, 0xFF, 0xFF, 0xFF, | ||
| 59 | 0xFF, 0xCC, 0x66, 0x00, | ||
| 60 | 0x00, 0x00, 0x00, 0x00 | ||
| 61 | }; | ||
| 62 | const uint8_t b[16] = { | ||
| 63 | 0x00, 0x00, 0x00, 0x00, | ||
| 64 | 0x00, 0x00, 0x00, 0x66, | ||
| 65 | 0xCC, 0xFF, 0xFF, 0xFF, | ||
| 66 | 0xFF, 0xFF, 0xCC, 0x66 | ||
| 67 | }; | ||
| 68 | /* pos contains the current positions, could technically be compressed to 4 bits per, but not worth it | ||
| 69 | index into pos is the position we're looking at, output is the tile that is currently there */ | ||
| 70 | uint8_t tiles[16] = { | ||
| 71 | 0, 1, 2, 3, | ||
| 72 | 4, 5, 6, 7, | ||
| 73 | 8, 9, 10, 11, | ||
| 74 | 12, 13, 14, 15 | ||
| 75 | }; | ||
| 76 | /* default led array for super 16 has them in a snake, so we must do some remapping/flipping of the 2nd and 4th rows */ | ||
| 77 | uint8_t remap[16] = { | ||
| 78 | 0, 1, 2, 3, | ||
| 79 | 7, 6, 5, 4, | ||
| 80 | 8, 9, 10, 11, | ||
| 81 | 15, 14, 13, 12 | ||
| 82 | }; | ||
| 83 | //clang-format on | ||
| 84 | /* function to refresh the led coloring with the positions with current tiles */ | ||
| 85 | void refresh_leds(void) { | ||
| 86 | for (uint8_t index = 0; index < 16; ++index) { | ||
| 87 | uint8_t tile = tiles[index]; | ||
| 88 | setrgb(r[tile], g[tile], b[tile], (LED_TYPE *)&led[remap[index]]); | ||
| 89 | } | ||
| 90 | rgblight_set(); | ||
| 91 | } | ||
| 92 | void keyboard_post_init_user(void) { | ||
| 93 | rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT); | ||
| 94 | rgblight_enable_noeeprom(); | ||
| 95 | refresh_leds(); | ||
| 96 | } | ||
| 97 | bool process_record_user(uint16_t keycode, keyrecord_t *record) { | ||
| 98 | uint8_t offset = keycode - K00; | ||
| 99 | uint8_t x = offset & 0x03; | ||
| 100 | uint8_t y = (offset & 0x0C) >> 2; | ||
| 101 | /* if the adjacent space exists and is empty, */ | ||
| 102 | if ((x > 0 && 0 == tiles[offset - 1]) || (y > 0 && 0 == tiles[offset - 4]) || (x < 3 && 0 == tiles[offset + 1]) || (y < 3 && 0 == tiles[offset + 4])) { | ||
| 103 | /* set the currently blank tile to this tile, and make this one blank */ | ||
| 104 | tiles[current] = tiles[offset]; | ||
| 105 | tiles[offset] = 0; | ||
| 106 | current = offset; | ||
| 107 | } | ||
| 108 | refresh_leds(); | ||
| 109 | return false; | ||
| 110 | } | ||
diff --git a/keyboards/1upkeyboards/super16/keymaps/15game/readme.md b/keyboards/1upkeyboards/super16/keymaps/15game/readme.md new file mode 100644 index 000000000..ede6bdd15 --- /dev/null +++ b/keyboards/1upkeyboards/super16/keymaps/15game/readme.md | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # Trying to put a game that plays like the 15 puzzle on the super16 | ||
| 2 | The 15/16 puzzle consists of a grid where one space is free, and adjacent spaces can be swapped with the free space | ||
| 3 | * future planned features: | ||
| 4 | * fix the start at red | ||
| 5 | * have a cute animation play when the puzzle is solved | ||
diff --git a/keyboards/1upkeyboards/super16/keymaps/15game/rules.mk b/keyboards/1upkeyboards/super16/keymaps/15game/rules.mk new file mode 100644 index 000000000..03198637f --- /dev/null +++ b/keyboards/1upkeyboards/super16/keymaps/15game/rules.mk | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | RGBLIGHT_ENABLE = yes | ||
| 2 | RGB_MATRIX_ENABLE = no | ||
