aboutsummaryrefslogtreecommitdiff
path: root/keyboards/clueboard/66/keymaps/tetris/keymap.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/clueboard/66/keymaps/tetris/keymap.c')
-rw-r--r--keyboards/clueboard/66/keymaps/tetris/keymap.c156
1 files changed, 156 insertions, 0 deletions
diff --git a/keyboards/clueboard/66/keymaps/tetris/keymap.c b/keyboards/clueboard/66/keymaps/tetris/keymap.c
new file mode 100644
index 000000000..26dd97fee
--- /dev/null
+++ b/keyboards/clueboard/66/keymaps/tetris/keymap.c
@@ -0,0 +1,156 @@
1#include QMK_KEYBOARD_H
2#include "tetris_text.h"
3
4// Each layer gets a name for readability, which is then used in the keymap matrix below.
5// The underscores don't mean anything - you can have a layer called STUFF or any other name.
6// Layer names don't all need to be of the same length, obviously, and you can also skip them
7// entirely and just use numbers.
8#define _BL 0
9#define _FL 1
10#define _CL 2
11
12enum custom_keycodes {
13 TETRIS_START = SAFE_RANGE
14};
15
16const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
17 /* Keymap _BL: Base Layer (Default Layer)
18 */
19[_BL] = LAYOUT(
20 KC_GESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_GRV, KC_BSPC, KC_PGUP,
21 KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_PGDN,
22 KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_NUHS, KC_ENT,
23 KC_LSFT, KC_NUBS, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RO, KC_RSFT, KC_UP,
24 KC_LCTL, KC_LGUI, KC_LALT, KC_MHEN, KC_SPC,KC_SPC, KC_HENK, KC_RALT, KC_RCTL, MO(_FL), KC_LEFT, KC_DOWN, KC_RGHT),
25
26 /* Keymap _FL: Function Layer
27 */
28[_FL] = LAYOUT(
29 KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, KC_DEL, BL_STEP,
30 _______, _______, _______,_______,_______,F(1) ,_______,_______,KC_PSCR,KC_SLCK, KC_PAUS, _______, _______, _______, _______,
31 _______, _______, MO(_CL),_______,_______,_______,_______,_______,_______,_______, _______, _______, _______, _______,
32 _______, _______, _______,_______,_______,_______,_______,_______,_______,_______, _______, _______, _______, _______, KC_PGUP,
33 _______, _______, _______, _______, _______,_______, _______, _______, _______, MO(_FL), KC_HOME, KC_PGDN, KC_END),
34
35 /* Keymap _CL: Control layer
36 */
37[_CL] = LAYOUT(
38 _______, _______, _______,_______,_______,_______,_______,_______,_______,_______, _______, _______, _______, _______, RGB_TOG, RGB_VAI,
39 _______, _______, _______,_______,RESET, _______,_______,_______,_______,_______, _______, _______, _______, _______, RGB_VAD,
40 _______, _______, MO(_CL),_______,_______,_______,_______,_______,_______,_______, _______, _______, _______, _______,
41 MO(_FL), _______, _______,_______,_______,_______,_______,_______,_______,_______, _______, _______, _______, MO(_FL), RGB_SAI,
42 _______, _______, _______,_______, RGB_MOD, RGB_MOD, _______, _______, _______, _______, RGB_HUD, RGB_SAD, RGB_HUI),
43};
44
45static uint8_t tetris_key_presses = 0;
46static uint16_t tetris_timer = 0;
47static uint8_t tetris_running = 0;
48static int tetris_keypress = 0;
49
50/*
51 * Set up tetris
52 */
53
54bool process_record_user(uint16_t keycode, keyrecord_t *record) {
55 if (record->event.pressed) {
56 tetris_key_presses++;
57 }
58
59 if (tetris_running && record->event.pressed) {
60 tetris_keypress = 0;
61 switch (keycode) {
62 case KC_UP: tetris_keypress = 1; break;
63 case KC_LEFT: tetris_keypress = 2; break;
64 case KC_DOWN: tetris_keypress = 3; break;
65 case KC_RIGHT: tetris_keypress = 4; break;
66 // Make ESC stop tetris (on keyboards other than clueboard)
67 // case KC_ESC: tetris_running = 0; return false;
68 }
69 if (tetris_keypress != 0) {
70 return false;
71 }
72 }
73
74 switch (keycode) {
75 case KC_GESC:
76 // clueboard specific hook to make escape quite tetris
77 if (tetris_running) {
78 tetris_running = 0;
79 return false;
80 }
81 break;
82 case TETRIS_START:
83 if (record->event.pressed) {
84 tetris_running = 1;
85 tetris_timer = 0;
86 tetris_keypress = 0;
87 // set randomness using total number of key presses
88 tetris_start(tetris_key_presses);
89 }
90 return false;
91 }
92
93 return true;
94}
95
96// Runs constantly in the background, in a loop.
97void matrix_scan_user(void) {
98 if (tetris_running) {
99 tetris_timer++;
100 if (tetris_timer > 1000) {
101 // every 1000 times this is run is about 100 ms.
102 if (!tetris_tick(100)) {
103 // game over
104 tetris_running = 0;
105 }
106 tetris_timer = 0;
107 }
108 }
109}
110
111void tetris_send_up(void) {
112 tap_code(KC_UP);
113}
114void tetris_send_left(void) {
115 tap_code(KC_LEFT);
116}
117void tetris_send_down(void) {
118 tap_code(KC_DOWN);
119}
120void tetris_send_right(void) {
121 tap_code(KC_RGHT);
122}
123void tetris_send_backspace(void) {
124 tap_code(KC_BSPC);
125}
126void tetris_send_delete(void) {
127 tap_code(KC_DEL);
128}
129
130void tetris_send_string(const char *s) {
131 for (int i = 0; s[i] != 0; i++) {
132 if (s[i] >= 'a' && s[i] <= 'z') {
133 tap_code(KC_A + (s[i] - 'a'));
134 } else if (s[i] >= 'A' && s[i] <= 'Z') {
135 tap_code16(S(KC_A + (s[i] - 'A')));
136 } else if (s[i] >= '1' && s[i] <= '9') {
137 tap_code(KC_1 + (s[i] - '1'));
138 } else {
139 switch (s[i]) {
140 case ' ': tap_code(KC_SPACE); break;
141 case '.': tap_code(KC_DOT); break;
142 case '0': tap_code(KC_0); break;
143 }
144 }
145 }
146}
147
148void tetris_send_newline(void) {
149 tap_code(KC_ENT);
150}
151
152int tetris_get_keypress(void) {
153 int out = tetris_keypress;
154 tetris_keypress = 0;
155 return out;
156}