Skip to content

Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.

NumBlocks: keys can be changed; Pause moves off Toolbox; Pick Block

Mason Chend4f50039aada
diff --git a/games/numblocks/src/gui.c b/games/numblocks/src/gui.c
index 9373b500..10c318ad 100644
--- a/games/numblocks/src/gui.c
+++ b/games/numblocks/src/gui.c
@@ -838,6 +838,11 @@ char seed_text[21]; /* the new world's seed, as typed */
char name_text[WORLD_NAME + 1]; /* the new world's name, or the world being renamed's */
int play_slot; /* the world to play */
static int options_from; /* the screen the options go back to */
+/* the Controls list's selection: -1 the Key Sheet button, 0.. the actions (kcol 1: their Reset), N_ACTIONS Done
+ * (kcol 1: Reset Keys); waiting for a key (GuiControls.buttonId) */
+static int ksel = -1, kcol, kscroll;
+static bool kwait;
+static void keys_input(uint32_t pressed);
static int controls_from; /* and the key sheet */
/* the worlds, the one played last first, and the one selected */
@@ -1166,6 +1171,8 @@ void gui_menu(int screen) {
bcur = 0;
field = F_NONE;
if (screen == GUI_WORLDS) list_worlds();
+ if (screen == GUI_KEYS && controls_from != GUI_KEYS) ksel = -1, kcol = 0, kscroll = 0;
+ kwait = false;
menu(screen);
}
@@ -1267,7 +1274,7 @@ static void press(int id) {
save_options();
gui_menu(options_from);
break;
- case B_CONTROLS: gui_menu(GUI_CONTROLS); break;
+ case B_CONTROLS: gui_menu(GUI_KEYS); break;
case B_CONTROLS_DONE:
if (opt.keys_seen != KEY_SHEET) opt.keys_seen = KEY_SHEET, save_options();
gui_menu(controls_from);
@@ -1281,6 +1288,10 @@ static void press(int id) {
}
static void menu_input(uint32_t keys, uint32_t pressed) {
+ if (gui == GUI_KEYS) {
+ keys_input(pressed);
+ return;
+ }
if (!nbuttons) menu(gui);
if (field) {
field_input();
@@ -1299,7 +1310,7 @@ static void menu_input(uint32_t keys, uint32_t pressed) {
bcur = (bcur + dir + nbuttons) % nbuttons;
if (buttons[bcur].on) break;
}
- if (pressed & K_USE && buttons[bcur].on) press(buttons[bcur].id);
+ if (pressed & (K_OK | K_EXE) && buttons[bcur].on) press(buttons[bcur].id);
else if (pressed & K_BACK) {
/* Back: the way out of each screen */
if (gui == GUI_PAUSE) gui = GUI_NONE;
@@ -1424,27 +1435,197 @@ static void arrow_pad(int cx, int cy, int r) {
}
text_center("Look", cx, cy - 4, RGB(0xFF, 0xFF, 0xA0));
}
+/* ---------------------------------------------------------------- the keys (KeyBinding) */
+typedef struct { uint32_t bit; uint8_t key; const char *name, *what; } Action;
+/* (what: the key sheet's word for it; key: where it starts) */
+static const Action actions[N_ACTIONS] = {
+ {K_ATTACK, 5, "Attack/Destroy", "Mine, attack"}, {0, 20, "Pick Block", "Pick block"},
+ {K_USE, 4, "Use Item/Place Block", "Place, use"}, {K_DROP, 14, "Drop Item", "Drop"},
+ {K_SLOT1, 42, "Hotbar Slot 1", "Slot 1"}, {K_SLOT1 << 1, 43, "Hotbar Slot 2", "Slot 2"},
+ {K_SLOT1 << 2, 44, "Hotbar Slot 3", "Slot 3"}, {K_SLOT1 << 3, 36, "Hotbar Slot 4", "Slot 4"},
+ {K_SLOT1 << 4, 37, "Hotbar Slot 5", "Slot 5"}, {K_SLOT1 << 5, 38, "Hotbar Slot 6", "Slot 6"},
+ {K_SLOT1 << 6, 30, "Hotbar Slot 7", "Slot 7"}, {K_SLOT1 << 7, 31, "Hotbar Slot 8", "Slot 8"},
+ {K_SLOT1 << 8, 32, "Hotbar Slot 9", "Slot 9"}, {K_INV, 15, "Inventory", "Inventory"},
+ {K_PAUSE, 51, "Pause", "Pause"}, {K_JUMP, 12, "Jump", "Jump"}, {K_SNEAK, 13, "Sneak", "Sneak"},
+ {K_SPRINT, 17, "Sprint", "Sprint"}, {K_STRAFE_L, 27, "Strafe Left", "Left"},
+ {K_STRAFE_R, 29, "Strafe Right", "Right"}, {K_BACKW, 28, "Walk Backwards", "Backward"},
+ {K_FWD, 22, "Walk Forwards", "Forward"}, {K_CHAT, 39, "Open Chat", "Chat"},
+ {K_COMMAND, 40, "Open Command", "Command"}};
+static const char *const categories[5] = {"Gameplay", "Inventory", "Miscellaneous", "Movement", "Multiplayer"};
+static const uint8_t category_at[5] = {A_ATTACK, A_DROP, A_PAUSE, A_JUMP, A_CHAT};
+
+void keys_reset(void) {
+ for (int a = 0; a < N_ACTIONS; a++) opt.keys[a] = actions[a].key;
+}
+/* the keys that can be set: not the arrows (they look), Home (it leaves), On/Off or EXE (it does what OK does) */
+static bool settable(int k) { return k == 4 || k == 5 || (k >= 12 && k <= 51 && k != 35 && k != 41 && k != 47); }
+uint32_t keys_of(uint64_t raw) {
+ uint32_t r = 0;
+ static const uint32_t fixed[8] = {K_LEFT, K_UP, K_DOWN, K_RIGHT, K_OK, K_BACK, K_HOME, K_HOME};
+ for (int k = 0; k < 8; k++)
+ if (raw >> k & 1) r |= fixed[k];
+ if (raw >> 12 & 1) r |= K_SHIFT;
+ if (raw >> 52 & 1) r |= K_EXE, raw |= 1 << 4; /* (EXE: what OK does) */
+ for (int a = 0; a < N_ACTIONS; a++)
+ if (opt.keys[a] < 64 && (raw >> opt.keys[a] & 1)) r |= actions[a].bit;
+ return r;
+}
+/* the key's name, as the calculator writes it */
+static const char *key_name(int k) {
+ static const char *const names[52] = {
+ [4] = "OK", [5] = "Back", [12] = "shift", [13] = "alpha", [14] = "x,n,t", [15] = "var", [16] = "toolbox",
+ [17] = "\3", [18] = "e^x", [19] = "ln", [20] = "log", [21] = "i", [22] = ",", [23] = "x^y", [24] = "sin",
+ [25] = "cos", [26] = "tan", [27] = "\1", [28] = "\2", [29] = "x^2", [30] = "7", [31] = "8", [32] = "9",
+ [33] = "(", [34] = ")", [36] = "4", [37] = "5", [38] = "6", [39] = "\4", [40] = "\5", [42] = "1", [43] = "2",
+ [44] = "3", [45] = "+", [46] = "-", [48] = "0", [49] = ".", [50] = "x10^x", [51] = "ans"};
+ return k < 52 && names[k] ? names[k] : "NONE";
+}
+static const char *action_on(int k) {
+ for (int a = 0; a < N_ACTIONS; a++)
+ if (opt.keys[a] == k) return actions[a].what;
+ return NULL;
+}
+
static void key_sheet(void) {
text_center("Controls", SCREEN_W / 2, 4, 0xFFFF);
arrow_pad(40, 45, 27);
key(130, 30, 60, "Home", "Save, quit");
- key(236, 14, 80, "OK", "Place, use");
- key(236, 46, 80, "Back", "Mine, attack");
+ key(236, 14, 80, "OK", action_on(4));
+ key(236, 46, 80, "Back", action_on(5));
/* the three rows under them, as on the calculator (the two left columns narrower) */
- static const char *const caps[3][6] = {{"shift", "alpha", "x,n,t", "var", "toolbox", "\3"},
- {"e^x", "ln", "log", "i", ",", "x^y"},
- {"sin", "cos", "tan", "\1", "\2", "x^2"}};
- static const char *const acts[3][6] = {{"Jump", "Sneak", "Drop", "Inventory", "Pause", "Sprint"},
- {0, 0, 0, 0, "Forward", 0},
- {0, 0, 0, "Left", "Backward", "Right"}};
for (int r = 0; r < 3; r++)
- for (int c = 0; c < 6; c++)
- key(c < 2 ? 5 + c * 37 : 79 + (c - 2) * 60, 80 + r * 32, c < 2 ? 34 : 57, caps[r][c], acts[r][c]);
- static const char *const notes[4] = {"1 to 9: hotbar slot. EXE: as OK. \4: chat. \5: command.",
- "Forward twice: sprint. Jump twice: fly (Creative).",
+ for (int c = 0; c < 6; c++) {
+ int k = 12 + r * 6 + c;
+ key(c < 2 ? 5 + c * 37 : 79 + (c - 2) * 60, 80 + r * 32, c < 2 ? 34 : 57, key_name(k), action_on(k));
+ }
+ /* the keys set further down, in words */
+ char line[2][72];
+ int n = 0, len = 0;
+ line[0][0] = line[1][0] = 0;
+ bool digits = true;
+ for (int a = A_SLOT1; a < A_SLOT1 + 9; a++) digits &= opt.keys[a] == actions[a].key;
+ for (int a = -1; a <= N_ACTIONS && n < 2; a++) {
+ char t[32];
+ if (a == -1) {
+ if (!digits) continue;
+ strcpy(t, "1 to 9: hotbar slot.");
+ } else if (a == N_ACTIONS) strcpy(t, "EXE: as OK.");
+ else {
+ int k = opt.keys[a];
+ if ((digits && a >= A_SLOT1 && a < A_SLOT1 + 9) || k == 4 || k == 5 || (k >= 12 && k < 30) || k > 51) continue;
+ cat(t, key_name(k), ": ");
+ cat(t + strlen(t), actions[a].what, ".");
+ for (char *c = t + strlen(key_name(k)) + 2; *c; c++)
+ if (*c >= 'A' && *c <= 'Z') *c = (char)(*c - 'A' + 'a');
+ }
+ if (len && text_width(line[n]) + text_width(t) + 12 > SCREEN_W - 8) {
+ if (++n == 2) break;
+ len = 0;
+ }
+ if (len) strcat(line[n], " ");
+ strcat(line[n], t);
+ len++;
+ }
+ static const char *const notes[3] = {"Forward twice: sprint. Jump twice: fly (Creative).",
"Menus: OK takes or puts, EXE one, shift+OK moves.",
"Hold OK and move over slots to spread a stack out."};
- for (int i = 0; i < 4; i++) text_center(notes[i], SCREEN_W / 2, 177 + i * 10, 0xFFFF);
+ int rows = line[1][0] ? 2 : 1;
+ for (int i = 0; i < rows; i++) text_center(line[i], SCREEN_W / 2, 177 + i * 10, 0xFFFF);
+ for (int i = 0; i + rows < 4; i++) text_center(notes[i], SCREEN_W / 2, 177 + (i + rows) * 10, 0xFFFF);
+}
+
+/* GuiControls: the actions by category, each with its key and Reset; Done and Reset Keys under them */
+#define KLIST_Y 42
+#define KLIST_ROWS 8
+static int krow_of(int a) {
+ int r = a;
+ for (int c = 0; c < 5; c++) r += category_at[c] <= a;
+ return r;
+}
+static void keys_screen(void) {
+ int w = SCREEN_W, h = SCREEN_H;
+ text_center("Controls", w / 2, 8, 0xFFFF);
+ Button b = {(int16_t)(w / 2 - 100), 18, 200, 1, 0, "Key Sheet..."};
+ button(&b, ksel == -1);
+ /* the label column: as wide as the widest label */
+ int lw = 0;
+ for (int a = 0; a < N_ACTIONS; a++)
+ if (text_width(actions[a].name) > lw) lw = text_width(actions[a].name);
+ int x = w / 2 - 126 + 2;
+ for (int a = 0, c = 0, row = 0; a < N_ACTIONS; row++) {
+ int y = KLIST_Y + (row - kscroll) * 20;
+ bool shown = row >= kscroll && row < kscroll + KLIST_ROWS;
+ if (c < 5 && category_at[c] == a) {
+ if (shown) text_center(categories[c], w / 2, y + 20 - 9 - 1, 0xFFFF);
+ c++;
+ continue;
+ }
+ if (shown) {
+ text(actions[a].name, x + 90 - lw, y + 6, 0xFFFF, false);
+ /* the key: yellow between > < while waiting for one, red if another action has it too */
+ Button kb = {(int16_t)(x + 105), (int16_t)y, 75, 1, 0, ""};
+ button(&kb, ksel == a && kcol == 0);
+ bool clash = false;
+ for (int o = 0; o < N_ACTIONS; o++) clash |= o != a && opt.keys[o] == opt.keys[a] && opt.keys[a] != 255;
+ const char *n = key_name(opt.keys[a]);
+ uint16_t col = kwait && ksel == a ? RGB(0xFF, 0xFF, 0x55) : clash ? RGB(0xFF, 0x55, 0x55)
+ : ksel == a && kcol == 0 ? RGB(0xFF, 0xFF, 0xA0) : RGB(0xE0, 0xE0, 0xE0);
+ key_text(n, x + 105 + 37, y + 6, col);
+ if (kwait && ksel == a) {
+ int nw = text_width(n) / 2 + 6;
+ text(">", x + 105 + 37 - nw - 6, y + 6, 0xFFFF, true);
+ text("<", x + 105 + 37 + nw, y + 6, 0xFFFF, true);
+ }
+ Button rb = {(int16_t)(x + 190), (int16_t)y, 50, opt.keys[a] != actions[a].key, 0, "Reset"};
+ button(&rb, ksel == a && kcol == 1);
+ }
+ a++;
+ }
+ Button done = {(int16_t)(w / 2 - 155), (int16_t)(h - 29), 150, 1, 0, "Done"};
+ bool any = false;
+ for (int a = 0; a < N_ACTIONS; a++) any |= opt.keys[a] != actions[a].key;
+ Button all = {(int16_t)(w / 2 + 5), (int16_t)(h - 29), 150, any, 0, "Reset Keys"};
+ button(&done, ksel == N_ACTIONS && kcol == 0);
+ button(&all, ksel == N_ACTIONS && kcol == 1);
+}
+static void keys_input(uint32_t pressed) {
+ if (kwait) {
+ uint64_t raw = plat_scan(), down = raw & ~raw_held;
+ raw_held = raw;
+ for (int k = 0; k < 64; k++) {
+ if (!(down >> k & 1)) continue;
+ if (k <= 3) kwait = false; /* (an arrow: as it was) */
+ else if (settable(k)) opt.keys[ksel] = (uint8_t)k, kwait = false;
+ }
+ return;
+ }
+ raw_held = plat_scan();
+ if (pressed & K_DOWN) ksel = ksel < N_ACTIONS ? ksel + 1 : N_ACTIONS;
+ if (pressed & K_UP) ksel = ksel > -1 ? ksel - 1 : -1;
+ if (pressed & (K_LEFT | K_RIGHT)) kcol = !kcol;
+ if (ksel == -1) kcol = 0;
+ /* the selected action in view */
+ if (ksel >= 0 && ksel < N_ACTIONS) {
+ int r = krow_of(ksel);
+ if (ksel == category_at[0] || ksel == category_at[1] || ksel == category_at[2] || ksel == category_at[3] ||
+ ksel == category_at[4])
+ r--; /* (its category's name with it) */
+ if (r < kscroll) kscroll = r;
+ if (krow_of(ksel) >= kscroll + KLIST_ROWS) kscroll = krow_of(ksel) - KLIST_ROWS + 1;
+ }
+ if (pressed & (K_OK | K_EXE)) {
+ if (ksel == -1) gui_menu(GUI_CONTROLS);
+ else if (ksel < N_ACTIONS && kcol == 0) kwait = true, raw_held = plat_scan();
+ else if (ksel < N_ACTIONS) opt.keys[ksel] = actions[ksel].key;
+ else if (kcol == 1) keys_reset();
+ else {
+ save_options();
+ gui_menu(GUI_OPTIONS);
+ }
+ } else if (pressed & K_BACK) {
+ save_options();
+ gui_menu(GUI_OPTIONS);
+ }
}
/* GuiTextField: grey framed (white when chosen), the text, and while typing a blinking cursor
@@ -1736,7 +1917,7 @@ void hud_strip(uint16_t *buf, int y0, int rows) {
tint_rect(0, y0, SCREEN_W, rows, 0x0841, a > 30 ? 30 : a);
}
if (gui < GUI_PAUSE || gui == GUI_PAUSE || gui == GUI_DEATH || gui == GUI_LAN ||
- (gui == GUI_OPTIONS && options_from == GUI_PAUSE))
+ ((gui == GUI_OPTIONS || gui == GUI_KEYS) && options_from == GUI_PAUSE))
hud();
if (gui == GUI_NONE || gui == GUI_CHAT) chat_lines();
if (pl.hurt_time > 0 && gui == GUI_NONE) {
@@ -1753,10 +1934,11 @@ void hud_strip(uint16_t *buf, int y0, int rows) {
menu_screen();
break;
case GUI_CHAT: chat_screen(); break;
- case GUI_OPTIONS: case GUI_CONTROLS:
+ case GUI_OPTIONS: case GUI_CONTROLS: case GUI_KEYS:
if (options_from == GUI_PAUSE) dark_background();
else dirt_background();
- menu_screen();
+ if (gui == GUI_KEYS) keys_screen();
+ else menu_screen();
break;
case GUI_TITLE:
menu_screen();
diff --git a/games/numblocks/src/main.c b/games/numblocks/src/main.c
index 93025cff..b286a2d5 100644
--- a/games/numblocks/src/main.c
+++ b/games/numblocks/src/main.c
@@ -112,6 +112,10 @@ bool game_frame(void) {
uint32_t k = plat_keys();
uint32_t pressed = k & ~keys_held;
keys_held = k;
+ static bool pick_held;
+ bool pick = opt.keys[A_PICK] < 64 && (plat_scan() >> opt.keys[A_PICK] & 1);
+ if (pick && !pick_held && in_world && gui == GUI_NONE && !pl.dead) player_pick_block();
+ pick_held = pick;
if (k & K_HOME) {
/* Home: save and quit, from anywhere */
if (in_world) {
@@ -186,7 +190,7 @@ bool game_frame(void) {
if (pl.pitch > 90) pl.pitch = 90;
if (pl.pitch < -90) pl.pitch = -90;
}
- bool paused = gui == GUI_PAUSE || gui == GUI_OPTIONS || gui == GUI_CONTROLS || gui == GUI_LAN;
+ bool paused = gui == GUI_PAUSE || gui == GUI_OPTIONS || gui == GUI_CONTROLS || gui == GUI_LAN || gui == GUI_KEYS;
if (!paused) acc += dt;
/* a key pressed on a frame between ticks waits for the next tick (else that press is lost) */
static uint32_t game_pressed;
diff --git a/games/numblocks/src/nb.h b/games/numblocks/src/nb.h
index 1fae9cbd..cee4868d 100644
--- a/games/numblocks/src/nb.h
+++ b/games/numblocks/src/nb.h
@@ -152,6 +152,7 @@ typedef struct {
enum { EF_POISON, EF_HUNGER, EF_REGEN };
extern Player pl;
void player_spawn(void);
+void player_pick_block(void); /* the block looked at, into the hand (Pick Block) */
extern float look_ray[6]; /* the eyes' ray as last drawn: from, direction */
void player_look(float ex, float ey, float ez, float yaw, float pitch);
void player_tick(uint32_t keys, uint32_t pressed); /* 20 a second */
@@ -242,7 +243,7 @@ void break_block_at(int x, int y, int z, bool drops);
/* ---------------------------------------------------------------- screens (gui.c) */
enum { GUI_NONE, GUI_INVENTORY, GUI_CRAFTING, GUI_FURNACE, GUI_CHEST, GUI_CREATIVE, GUI_CHAT,
GUI_PAUSE, GUI_DEATH, GUI_OPTIONS, GUI_TITLE, GUI_WORLDS, GUI_CREATE, GUI_CONFIRM, GUI_LOADING, GUI_CONTROLS,
- GUI_RENAME, GUI_LAN };
+ GUI_RENAME, GUI_LAN, GUI_KEYS };
extern int gui; /* the screen open */
void gui_open(int screen, int x, int y, int z);
void gui_close(void);
@@ -268,7 +269,13 @@ typedef struct {
uint8_t keys_seen; /* the key sheet's version last shown (it opens when the keys change) */
uint8_t last_world; /* the world played last (its slot, 0: none): the title's backdrop */
uint32_t plays; /* worlds opened so far: each world keeps the count when it was last played */
+ uint8_t keys[24]; /* the key of each action (A_*): the calculator's number for it, 255 none */
} Options;
+/* the actions keys are set to (KeyBinding), in the order of Minecraft's list: by category, then name */
+enum { A_ATTACK, A_PICK, A_USE, A_DROP, A_SLOT1, A_INVENTORY = A_SLOT1 + 9, A_PAUSE, A_JUMP, A_SNEAK, A_SPRINT,
+ A_LEFT, A_RIGHT, A_BACK, A_FORWARD, A_CHAT, A_COMMAND, N_ACTIONS };
+uint32_t keys_of(uint64_t raw); /* the K_ bits of the keys held (the calculator's keys, as bound) */
+void keys_reset(void); /* the keys as they start */
#define KEY_SHEET 3 /* (2: jump and sneak on shift and alpha; 3: chat and commands) */
extern Options opt;
extern int64_t world_seed;
diff --git a/games/numblocks/src/plat_eadk.c b/games/numblocks/src/plat_eadk.c
index 8dfecf61..f8a4977d 100644
--- a/games/numblocks/src/plat_eadk.c
+++ b/games/numblocks/src/plat_eadk.c
@@ -1,50 +1,12 @@
/* The calculator: EADK display, keyboard, time and files.
*
- * Keys, Minecraft's on the calculator's keyboard: the left thumb looks around
- * with the arrows, the right one walks with the keys under OK and Back, laid
- * out like W, A, S and D: comma, pi, square root and x squared; backspace
- * sprints. Under the arrows, shift jumps and alpha sneaks. OK uses and places,
- * Back mines and hits; 1-9 pick the hotbar slot; var opens the inventory;
- * x,n,t drops; Toolbox pauses; Home saves and quits. */
+ * The keys are as Options > Controls has them (gui.c, keys_of). */
#include <eadk.h>
#include "../../common/epsilon_app.h"
#include "../../common/epsilon_files.h"
#include "nb.h"
-#define KEY(k) ((uint64_t)1 << (k))
-
-uint32_t plat_keys(void) {
- uint64_t k = eadk_keyboard_scan();
- uint32_t r = 0;
- if (k & KEY(eadk_key_left)) r |= K_LEFT;
- if (k & KEY(eadk_key_right)) r |= K_RIGHT;
- if (k & KEY(eadk_key_up)) r |= K_UP;
- if (k & KEY(eadk_key_down)) r |= K_DOWN;
- if (k & KEY(eadk_key_comma)) r |= K_FWD;
- if (k & KEY(eadk_key_sqrt)) r |= K_BACKW;
- if (k & KEY(eadk_key_pi)) r |= K_STRAFE_L;
- if (k & KEY(eadk_key_square)) r |= K_STRAFE_R;
- if (k & KEY(eadk_key_shift)) r |= K_JUMP;
- if (k & (KEY(eadk_key_ok) | KEY(eadk_key_exe))) r |= K_USE;
- if (k & KEY(eadk_key_ok)) r |= K_OK;
- if (k & KEY(eadk_key_exe)) r |= K_EXE;
- if (k & KEY(eadk_key_shift)) r |= K_SHIFT;
- if (k & KEY(eadk_key_back)) r |= K_BACK;
- if (k & KEY(eadk_key_multiplication)) r |= K_CHAT;
- if (k & KEY(eadk_key_division)) r |= K_COMMAND;
- if (k & KEY(eadk_key_back)) r |= K_ATTACK;
- if (k & KEY(eadk_key_var)) r |= K_INV;
- if (k & (KEY(eadk_key_home) | KEY(eadk_key_on_off))) r |= K_HOME;
- if (k & KEY(eadk_key_alpha)) r |= K_SNEAK;
- if (k & KEY(eadk_key_backspace)) r |= K_SPRINT;
- if (k & KEY(eadk_key_toolbox)) r |= K_PAUSE;
- if (k & KEY(eadk_key_xnt)) r |= K_DROP;
- static const uint8_t digits[9] = {eadk_key_one, eadk_key_two, eadk_key_three, eadk_key_four, eadk_key_five,
- eadk_key_six, eadk_key_seven, eadk_key_eight, eadk_key_nine};
- for (int i = 0; i < 9; i++)
- if (k & KEY(digits[i])) r |= K_SLOT1 << i;
- return r;
-}
+uint32_t plat_keys(void) { return keys_of(eadk_keyboard_scan()); }
uint64_t plat_scan(void) { return eadk_keyboard_scan(); }
uint32_t plat_millis(void) { return (uint32_t)eadk_timing_millis(); }
diff --git a/games/numblocks/src/player.c b/games/numblocks/src/player.c
index f5d151d7..1adb2b8c 100644
--- a/games/numblocks/src/player.c
+++ b/games/numblocks/src/player.c
@@ -699,6 +699,26 @@ static void use(uint32_t pressed) {
}
/* ---------------------------------------------------------------- a tick */
+/* Minecraft.middleClickMouse: the block looked at in the hand, from the hotbar if it is there; in
+ * Creative, else into the first empty hotbar slot, or the one held (InventoryPlayer.setCurrentItem) */
+void player_pick_block(void) {
+ if (pl.hit_face < 0) return;
+ int id = blk_item[world_get(pl.hit_x, pl.hit_y, pl.hit_z)];
+ if (id == 0xFFFF) return;
+ for (int i = 0; i < 9; i++)
+ if (pl.inv[i].id == id) {
+ pl.slot = i;
+ return;
+ }
+ if (pl.mode != 1) return;
+ for (int i = 0; i < 9; i++)
+ if (!pl.inv[i].id) {
+ pl.slot = i;
+ break;
+ }
+ pl.inv[pl.slot] = (Stack){(uint16_t)id, 1};
+}
+
void player_spawn(void) {
int x, y, z;
gen_spawn(&x, &y, &z);
diff --git a/games/numblocks/src/render.c b/games/numblocks/src/render.c
index c9b76e26..63e8df30 100644
--- a/games/numblocks/src/render.c
+++ b/games/numblocks/src/render.c
@@ -1848,7 +1848,7 @@ static uint32_t strip_hash(void) {
}
static bool still_screen(void) {
return gui == GUI_PAUSE || gui == GUI_OPTIONS || gui == GUI_CONTROLS || gui == GUI_WORLDS || gui == GUI_CREATE ||
- gui == GUI_CONFIRM || gui == GUI_RENAME || gui == GUI_LOADING || gui == GUI_LAN;
+ gui == GUI_CONFIRM || gui == GUI_RENAME || gui == GUI_LOADING || gui == GUI_LAN || gui == GUI_KEYS;
}
static void send_strip(int py, bool still) {
if (still) {
diff --git a/games/numblocks/src/save.c b/games/numblocks/src/save.c
index 54935f5d..2527175c 100644
--- a/games/numblocks/src/save.c
+++ b/games/numblocks/src/save.c
@@ -10,7 +10,7 @@
#define OPTIONS_REC "numblocks.cfg"
-Options opt = {2, 0, 100, 1, 1, 0, 0, 0};
+Options opt = {2, 0, 100, 1, 1, 0, 0, 0, {0}};
int64_t world_seed;
/* the record's head: version 1 had no name (it was "New World") */
@@ -233,6 +233,7 @@ void delete_world(int s) {
}
void load_options(void) {
+ keys_reset();
uint32_t len = 0;
const uint8_t *d = plat_load(OPTIONS_REC, &len);
/* (an older, shorter record: what it has; the rest stays as it was) */