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.
C calculatorcalculator-gamescasiochesscrossy-roaddrive-madfx-cg50gamesgeometry-dashgraphing-calculatorndlessnumworksnumworks-appsnumworks-calculatornumworks-gamenumworks-gamestetristi-84-plus-ceti-nspire
NumBlocks: walking on the right-hand keys, and a key sheet
Mason Chen90a0a81a3ac2
diff --git a/docs/play.md b/docs/play.mdindex 03760a0d..7d247e7c 100644--- a/docs/play.md+++ b/docs/play.md@@ -105,9 +105,10 @@ Shooting yourself with a blank keeps your turn.| Key | What it does || --- | --- || **Arrows** | Look around |-| **ln**, **cos**, **sin**, **tan** | Walk forward, back, left, right |-| **π** | Jump (twice in Creative: fly) |-| **√** / **x²** | Sneak / sprint |+| **,** / **π** / **√** / **x²** | Walk forward / left / back / right (like W, A, S, D) |+| **xʸ** | Jump (twice in Creative: fly) |+| **i** | Sneak |+| **⌫** | Sprint (or press forward twice) || **Back** | Mine and attack (hold it to mine) || **OK** or **EXE** | Place a block, use, eat || **var** | Inventory (in Creative: every block and item) |@@ -116,7 +117,7 @@ Shooting yourself with a blank keeps your turn.| **Toolbox** | Pause || **Home** | Save and quit |-In NumBlocks, Back mines, so **Toolbox** pauses. In the inventory, the arrows move between slots, **OK** picks up or puts down a stack, **EXE** one item, and **shift** with **OK** sends a stack to the other side. Your world saves as you play and when you quit.+The left thumb looks with the arrows, the right one walks. The first time you open NumBlocks it shows these keys, and Options, then Controls, shows them again. In NumBlocks, Back mines, so **Toolbox** pauses. In the inventory, the arrows move between slots, **OK** picks up or puts down a stack, **EXE** one item, and **shift** with **OK** sends a stack to the other side. Your world saves as you play and when you quit.<br clear="right">diff --git a/games/numblocks/README.md b/games/numblocks/README.mdindex 5f47636a..a1fd77db 100644--- a/games/numblocks/README.md+++ b/games/numblocks/README.md@@ -18,10 +18,10 @@ Mine, craft and survive on your NumWorks calculator, in a world like Minecraft 1| Key | What it does || --- | --- || Arrows | Look around |-| ln, cos, sin, tan | Walk forward, back, left, right |-| π | Jump (twice in Creative: fly) |-| √ | Sneak |-| x² | Sprint |+| , π √ x² | Walk forward, left, back, right (like W, A, S, D) |+| xʸ | Jump (twice in Creative: fly) |+| i | Sneak |+| ⌫ | Sprint (or press forward twice) || Back | Mine, attack || OK | Place, use, eat || var | Inventory |@@ -30,7 +30,7 @@ Mine, craft and survive on your NumWorks calculator, in a world like Minecraft 1| Toolbox | Pause || Home | Save and quit |-In the inventory, the arrows move between slots, OK picks up or puts down, EXE takes or leaves one, and shift with OK moves a whole stack. Options, then Controls, shows these keys in the game too.+In the inventory, the arrows move between slots, OK picks up or puts down, EXE takes or leaves one, and shift with OK moves a whole stack. The game shows these keys the first time you open it, and again from Options, then Controls.## Get itdiff --git a/games/numblocks/src/gui.c b/games/numblocks/src/gui.cindex 8d7da1c9..f1329322 100644--- a/games/numblocks/src/gui.c+++ b/games/numblocks/src/gui.c@@ -98,17 +98,22 @@ static void dark_background(void) {#define RGB(r, g, b) (uint16_t)(((r) & 0xF8) << 8 | ((g) & 0xFC) << 3 | (b) >> 3)/* ---------------------------------------------------------------- text (FontRenderer) */+/* three symbols the font lacks, for the key sheet: \1 pi, \2 the square root, \3 backspace */+static const uint8_t sym_bits[3][8] = {{0x00, 0x3F, 0x12, 0x12, 0x12, 0x12, 0x21, 0x00},+ {0x78, 0x08, 0x08, 0x08, 0x09, 0x0A, 0x04, 0x00},+ {0xFC, 0x82, 0xA9, 0x91, 0xA9, 0x82, 0xFC, 0x00}};+static const uint8_t sym_w[3] = {7, 8, 9};+static int char_w(int c) { return c >= 1 && c <= 3 ? sym_w[c - 1] : c >= 32 && c < 127 ? font_w[c - 32] : 0; }int text_width(const char *s) {int w = 0;- for (; *s; s++)- if (*s >= 32 && *s < 127) w += font_w[*s - 32];+ for (; *s; s++) w += char_w((unsigned char)*s);return w;}static void glyphs(const char *s, int x, int y, uint16_t col, int scale) {for (; *s; s++) {int c = (unsigned char)*s;- if (c < 32 || c >= 127) continue;- const uint8_t *g = font_bits + (c - 32) * 8;+ if (!char_w(c)) continue;+ const uint8_t *g = c < 32 ? sym_bits[c - 1] : font_bits + (c - 32) * 8;for (int r = 0; r < 8 * scale; r++) {int ty = y + r;if (ty < clip_y0 || ty >= clip_y1) continue;@@ -118,7 +123,7 @@ static void glyphs(const char *s, int x, int y, uint16_t col, int scale) {for (int k = 0; k < 8 * scale; k++)if (bits & (1 << (k / scale)) && (unsigned)(x + k) < SCREEN_W) d[x + k] = col;}- x += font_w[c - 32] * scale;+ x += char_w(c) * scale;}}/* drawStringWithShadow: the shadow is the colour at a quarter, one pixel down and right */@@ -781,6 +786,7 @@ int menu_choice; /* an action for main.c (ACT_*) */int create_mode; /* the new world's game mode */char seed_text[21]; /* the new world's seed, as typed */static int options_from; /* the screen the options go back to */+static int controls_from; /* and the key sheet */static bool seed_focus;static void add_button(int x, int y, int w, int on, int id, const char *label) {@@ -872,6 +878,7 @@ static void menu(int screen) {}void gui_menu(int screen) {+ if (screen == GUI_CONTROLS && gui != GUI_CONTROLS) controls_from = gui; /* Options, or the title */gui = screen;bcur = 0;seed_focus = false;@@ -920,7 +927,10 @@ static void press(int id) {gui_menu(options_from);break;case B_CONTROLS: gui_menu(GUI_CONTROLS); break;- case B_CONTROLS_DONE: gui_menu(GUI_OPTIONS); break;+ case B_CONTROLS_DONE:+ if (!opt.keys_seen) opt.keys_seen = 1, save_options();+ gui_menu(controls_from);+ break;case B_BACK_GAME: gui = GUI_NONE; break;case B_SAVEQUIT: menu_choice = ACT_SAVE_QUIT; break;case B_RESPAWN: menu_choice = ACT_RESPAWN; break;@@ -938,7 +948,7 @@ static void menu_input(uint32_t keys, uint32_t pressed) {if (pressed & (K_SLOT1 << d) && n < 19) seed_text[n++] = (char)('1' + d), seed_text[n] = 0;if (pressed & K_ZERO && n < 19) seed_text[n++] = '0', seed_text[n] = 0;if (pressed & K_MINUS && n == 0) seed_text[n++] = '-', seed_text[n] = 0;- if ((pressed & K_ATTACK) && !(keys & K_BACK) && n > 0) seed_text[--n] = 0;+ if ((pressed & K_SPRINT) && n > 0) seed_text[--n] = 0; /* (backspace) */if (pressed & (K_USE | K_BACK)) seed_focus = false;menu(gui);return;@@ -1027,6 +1037,73 @@ static void dirt_background(void) {}}+/* ---------------------------------------------------------------- the key sheet */+/* a key's name, a character after ^ raised (x^y) */+static void key_text(const char *s, int cx, int y, uint16_t col) {+ int w = 0;+ for (const char *c = s; *c; c++) w += *c == '^' ? 0 : char_w((unsigned char)*c);+ int x = cx - w / 2;+ for (const char *c = s; *c; c++) {+ if (*c == '^') continue;+ char t[2] = {*c, 0};+ text(t, x, y - (c > s && c[-1] == '^' ? 3 : 0), col, true);+ x += char_w((unsigned char)*c);+ }+}+/* a key: bright with what it does, dim if the game doesn't use it */+static void key(int x, int y, int w, const char *cap, const char *act) {+ fill(x, y, w, 29, act ? RGB(0xA0, 0xA0, 0xA0) : RGB(0x50, 0x50, 0x50));+ fill(x + 1, y + 1, w - 2, 27, act ? RGB(0x28, 0x28, 0x28) : RGB(0x18, 0x18, 0x18));+ if (!act) {+ key_text(cap, x + w / 2, y + 11, RGB(0x70, 0x70, 0x70));+ return;+ }+ if (cap[0] == ',' && !cap[1]) {+ /* the comma, big enough to see: a dot and its tail */+ int cx = x + w / 2;+ fill(cx - 1, y + 6, 3, 3, 0xFFFF);+ fill(cx, y + 9, 2, 2, 0xFFFF);+ fill(cx - 1, y + 11, 2, 1, 0xFFFF);+ } else key_text(cap, x + w / 2, y + 5, 0xFFFF);+ text_center(act, x + w / 2, y + 17, RGB(0xFF, 0xFF, 0xA0));+}+/* the round pad of arrows */+static void arrow_pad(int cx, int cy, int r) {+ for (int dy = -r; dy < r; dy++) {+ float e = (float)(r * r) - (dy + 0.5f) * (dy + 0.5f);+ int hw = (int)sqrtf(e), hi = (int)sqrtf(e - 2 * r + 1);+ fill(cx - hw, cy + dy, 2 * hw, 1, RGB(0xA0, 0xA0, 0xA0));+ if (abs(dy) < r - 1) fill(cx - hi, cy + dy, 2 * hi, 1, RGB(0x28, 0x28, 0x28));+ }+ for (int i = 1; i <= 5; i++) {+ fill(cx - i, cy - r + 3 + i, 2 * i, 1, 0xFFFF);+ fill(cx - i, cy + r - 4 - i, 2 * i, 1, 0xFFFF);+ fill(cx - r + 3 + i, cy - i, 1, 2 * i, 0xFFFF);+ fill(cx + r - 4 - i, cy - i, 1, 2 * i, 0xFFFF);+ }+ text_center("Look", cx, cy - 4, RGB(0xFF, 0xFF, 0xA0));+}+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");+ /* 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] = {{0, 0, "Drop", "Inventory", "Pause", "Sprint"},+ {0, 0, 0, "Sneak", "Forward", "Jump"},+ {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]);+ text_center("1 to 9: hotbar slot. EXE: same as OK.", SCREEN_W / 2, 178, 0xFFFF);+ text_center("Forward twice: sprint. Jump twice: fly (Creative).", SCREEN_W / 2, 189, 0xFFFF);+ text_center("Menus: OK moves a stack, EXE one item, Back closes.", SCREEN_W / 2, 200, 0xFFFF);+}+static void menu_screen(void) {int w = SCREEN_W, h = SCREEN_H;switch (gui) {@@ -1074,23 +1151,7 @@ static void menu_screen(void) {text_center("'New World' will be lost forever! (A long time!)", w / 2, 90, 0xFFFF);break;case GUI_OPTIONS: text_center("Options", w / 2, 15, 0xFFFF); break;- case GUI_CONTROLS: {- /* GuiControls: each action and its key (the calculator's) */- static const char *const rows[][2] = {- {"Look Around", "Arrows"}, {"Walk Forwards", "ln"}, {"Walk Backwards", "cos"}, {"Strafe Left", "sin"},- {"Strafe Right", "tan"}, {"Jump (twice: fly)", "pi"}, {"Sneak", "sqrt"}, {"Sprint", "x^2"},- {"Attack/Destroy", "Back"}, {"Use Item/Place Block", "OK or EXE"}, {"Inventory", "var"},- {"Drop Item", "x,n,t"}, {"Hotbar Slots", "1 to 9"}, {"Pause", "Toolbox"}, {"Save and Quit", "Home"}};- text_center("Controls", w / 2, 6, 0xFFFF);- for (int i = 0; i < 15; i++) {- int y = 20 + i * 12;- text(rows[i][0], w / 2 - 140, y + 2, 0xFFFF, true);- fill(w / 2 + 20, y, 100, 11, RGB(0x60, 0x60, 0x60));- fill(w / 2 + 21, y + 1, 98, 9, RGB(0x20, 0x20, 0x20));- text_center(rows[i][1], w / 2 + 70, y + 2, RGB(0xFF, 0xFF, 0xA0));- }- break;- }+ case GUI_CONTROLS: key_sheet(); break;case GUI_PAUSE: text_center("Game menu", w / 2, 40, 0xFFFF); break;case GUI_LOADING:text_center("Loading world", w / 2, h / 2 - 50, 0xFFFF);diff --git a/games/numblocks/src/main.c b/games/numblocks/src/main.cindex 5241cf36..292d665d 100644--- a/games/numblocks/src/main.c+++ b/games/numblocks/src/main.c@@ -77,6 +77,7 @@ void game_init(void) {return;}title();+ if (!opt.keys_seen) gui_menu(GUI_CONTROLS); /* the first time: the keys */}/* one frame: input, the ticks due, the picture; false once the player quits */@@ -151,7 +152,6 @@ bool game_frame(void) {if (k & K_DOWN) pl.pitch += 100 * turn;if (pl.pitch > 90) pl.pitch = 90;if (pl.pitch < -90) pl.pitch = -90;- pl.sprinting = (k & K_SPRINT) && (k & K_FWD) && !pl.sneaking;}bool paused = gui == GUI_PAUSE || gui == GUI_OPTIONS || gui == GUI_CONTROLS;if (!paused) acc += dt;diff --git a/games/numblocks/src/mob.c b/games/numblocks/src/mob.cindex f5dead44..c02845f7 100644--- a/games/numblocks/src/mob.c+++ b/games/numblocks/src/mob.c@@ -347,7 +347,12 @@ bool mob_attack(const Entity *ce) {/* a critical hit: falling, not on a ladder or in water */if (pl.vy < 0 && !pl.on_ground && !pl.in_water) dmg *= 1.5f;float kx = e->x - pl.x, kz = e->z - pl.z;- if (pl.sprinting) e->vx += kx * 0.2f, e->vz += kz * 0.2f;+ if (pl.sprinting) {+ /* a sprinting hit knocks harder, slows you and ends the sprint */+ e->vx += kx * 0.2f, e->vz += kz * 0.2f;+ pl.vx *= 0.6f, pl.vz *= 0.6f;+ pl.sprinting = false;+ }hurt(e, dmg, kx, kz);if (pl.mode == 0) {if (k == IK_SWORD) stack_wear(h, 1);diff --git a/games/numblocks/src/nb.h b/games/numblocks/src/nb.hindex 36570e9f..358ea64d 100644--- a/games/numblocks/src/nb.h+++ b/games/numblocks/src/nb.h@@ -18,11 +18,11 @@/* ---------------------------------------------------------------- the platform (plat_eadk.c / plat_host.c) */enum {K_LEFT = 1 << 0, K_RIGHT = 1 << 1, K_UP = 1 << 2, K_DOWN = 1 << 3, /* arrows: look */- K_FWD = 1 << 4, K_BACKW = 1 << 5, K_STRAFE_L = 1 << 6, K_STRAFE_R = 1 << 7, /* ln, cos, sin, tan */- K_JUMP = 1 << 8, K_USE = 1 << 9, K_ATTACK = 1 << 10, K_INV = 1 << 11, /* pi, OK, Back, var */- K_HOME = 1 << 12, K_SNEAK = 1 << 13, K_PAUSE = 1 << 14, K_DROP = 1 << 15,+ K_FWD = 1 << 4, K_BACKW = 1 << 5, K_STRAFE_L = 1 << 6, K_STRAFE_R = 1 << 7, /* comma, sqrt, pi, x^2 */+ K_JUMP = 1 << 8, K_USE = 1 << 9, K_ATTACK = 1 << 10, K_INV = 1 << 11, /* x^y, OK, Back, var */+ K_HOME = 1 << 12, K_SNEAK = 1 << 13, K_PAUSE = 1 << 14, K_DROP = 1 << 15, /* Home, i, Toolbox, x,n,t */K_SLOT1 = 1 << 16, /* K_SLOT1 << n: digit n + 1 */- K_SPRINT = 1 << 25,+ K_SPRINT = 1 << 25, /* backspace (also deletes, typing a seed) */K_EXE = 1 << 26, /* EXE alone (OK and EXE both give K_USE): right click in screens */K_SHIFT = 1 << 27, /* shift: shift click in screens */K_BACK = 1 << 28, /* Back alone: closes screens */@@ -246,6 +246,7 @@ typedef struct {uint8_t fancy; /* graphics: 0 fast (solid leaves), 1 fancy */uint8_t look; /* look speed, % */uint8_t clouds, bobbing;+ uint8_t keys_seen; /* the key sheet has been shown (it opens the first time) */} Options;extern Options opt;extern int64_t world_seed;diff --git a/games/numblocks/src/plat_eadk.c b/games/numblocks/src/plat_eadk.cindex 9fbaa624..9d5e1647 100644--- a/games/numblocks/src/plat_eadk.c+++ b/games/numblocks/src/plat_eadk.c@@ -1,9 +1,11 @@/* The calculator: EADK display, keyboard, time and files.*- * Keys, Minecraft's on the calculator's keyboard: the arrows look around;- * ln, sin, cos and tan are W, A, S and D; pi jumps; OK uses and places, Back- * mines and hits; 1-9 pick the hotbar slot; var opens the inventory; square- * root sneaks, x squared sprints; Toolbox pauses; Home saves and quits. */+ * 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. Next to them,+ * x^y jumps, i sneaks and backspace sprints. 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. */#include <eadk.h>#include "../../common/epsilon_app.h"#include "../../common/epsilon_files.h"@@ -18,11 +20,11 @@ uint32_t plat_keys(void) {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_ln)) r |= K_FWD;- if (k & KEY(eadk_key_cosine)) r |= K_BACKW;- if (k & KEY(eadk_key_sine)) r |= K_STRAFE_L;- if (k & KEY(eadk_key_tangent)) r |= K_STRAFE_R;- if (k & KEY(eadk_key_pi)) r |= K_JUMP;+ 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_power)) 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;@@ -30,11 +32,11 @@ uint32_t plat_keys(void) {if (k & KEY(eadk_key_back)) r |= K_BACK;if (k & KEY(eadk_key_zero)) r |= K_ZERO;if (k & KEY(eadk_key_minus)) r |= K_MINUS;- if (k & (KEY(eadk_key_back) | KEY(eadk_key_backspace))) r |= K_ATTACK;+ 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_sqrt)) r |= K_SNEAK;- if (k & KEY(eadk_key_square)) r |= K_SPRINT;+ if (k & KEY(eadk_key_imaginary)) 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,diff --git a/games/numblocks/src/player.c b/games/numblocks/src/player.cindex 961c82de..da5f18fa 100644--- a/games/numblocks/src/player.c+++ b/games/numblocks/src/player.c@@ -20,6 +20,7 @@ static void box_of(float x, float y, float z, float *a) {}/* Entity.moveEntity: y first, then x and z; step up 0.6 if that goes further */+static bool hit_wall; /* the last move ran into something sideways (isCollidedHorizontally) */static void move(float dx, float dy, float dz) {float a[6];box_of(pl.x, pl.y, pl.z, a);@@ -67,6 +68,7 @@ static void move(float dx, float dy, float dz) {pl.y = a[1];pl.z = (a[2] + a[5]) / 2;pl.on_ground = ody != mdy && ody < 0;+ hit_wall = odx != mdx || odz != mdz;if (ody != mdy) pl.vy = 0;if (odx != mdx) pl.vx = 0;if (odz != mdz) pl.vz = 0;@@ -661,7 +663,8 @@ void player_respawn(void) {pl.pitch = 0;}-static int break_cooldown, jump_timer;+static int break_cooldown, jump_timer, sprint_timer;+static bool was_fwd; /* forward was held last tick */static uint32_t prev_keys;/* the damage the world does: falls, drowning, lava, fire, cactus, suffocation, the void */@@ -722,7 +725,18 @@ void player_tick(uint32_t keys, uint32_t pressed) {fwd *= 0.98f;strafe *= 0.98f;if (pl.sneaking) fwd *= 0.3f, strafe *= 0.3f;- if (pl.using_ticks) fwd *= 0.2f, strafe *= 0.2f; /* eating slows you down */+ if (pl.using_ticks) fwd *= 0.2f, strafe *= 0.2f, sprint_timer = 0; /* eating slows you down */+ /* EntityPlayerSP.onLivingUpdate: forward pressed twice within 7 ticks on the ground, or with the+ * sprint key, sprints until forward is let go, you walk into a wall, sneak or get hungry */+ bool fed = pl.food > 6 || pl.mode == 1, went = fwd >= 0.8f * 0.98f;+ if (sprint_timer) sprint_timer--;+ if (pl.on_ground && !was_fwd && went && !pl.sprinting && fed && !pl.using_ticks) {+ if (!sprint_timer && !(keys & K_SPRINT)) sprint_timer = 7;+ else pl.sprinting = true;+ }+ if (!pl.sprinting && went && fed && !pl.using_ticks && (keys & K_SPRINT)) pl.sprinting = true;+ if (pl.sprinting && (!went || hit_wall || !fed)) pl.sprinting = false;+ was_fwd = went;pl.in_water = in_liquid();/* creative: jump twice quickly to fly or land */if (jump_timer) jump_timer--;@@ -732,7 +746,6 @@ void player_tick(uint32_t keys, uint32_t pressed) {jump_timer = 0;} else jump_timer = 7;}- if (pl.food <= 6 && pl.mode == 0) pl.sprinting = false;float y0 = pl.y, ox = pl.x, oz = pl.z;if (pl.flying) {/* PlayerCapabilities: flying speed 0.05, x2 sprinting; up with jump, down with sneak */diff --git a/games/numblocks/src/save.c b/games/numblocks/src/save.cindex d59cfa30..21fe263a 100644--- a/games/numblocks/src/save.c+++ b/games/numblocks/src/save.c@@ -9,7 +9,7 @@#define WORLD_REC "nb1.nbw"#define OPTIONS_REC "numblocks.cfg"-Options opt = {2, 0, 100, 1, 1};+Options opt = {2, 0, 100, 1, 1, 0};int64_t world_seed;typedef struct {diff --git a/games/numblocks/tests/unit.c b/games/numblocks/tests/unit.cindex fe09c3a3..1a6612b0 100644--- a/games/numblocks/tests/unit.c+++ b/games/numblocks/tests/unit.c@@ -256,6 +256,41 @@ int main(void) {CHECK(pl.on_ground && pl.y >= g && pl.z > 10);plat_remove_prefix("ut7");}+ {+ /* sprinting (EntityPlayerSP): forward twice, or with the sprint key; it lasts while forward is held */+ world_new(0, "ut8");+ world_follow(8, 110, 8);+ int g = 110;+ for (int z = -8; z <= 60; z++)+ for (int x = 2; x <= 14; x++)+ for (int y = g - 2; y < g + 4; y++) world_set(x, y, z, y >= g ? B_AIR : B_STONE);+ memset(&pl, 0, sizeof pl);+ pl.x = 8.5f, pl.z = 0.5f, pl.y = (float)g, pl.health = 20, pl.food = 20, pl.mode = 0, pl.on_ground = true;+ for (int t = 0; t < 3; t++) player_tick(0, 0);+ player_tick(K_FWD, K_FWD), player_tick(0, 0), player_tick(0, 0);+ CHECK(!pl.sprinting);+ player_tick(K_FWD, K_FWD);+ CHECK(pl.sprinting);+ for (int t = 0; t < 5; t++) player_tick(K_FWD, 0);+ CHECK(pl.sprinting);+ player_tick(0, 0);+ CHECK(!pl.sprinting);+ /* too slow a second press: walking */+ for (int t = 0; t < 10; t++) player_tick(0, 0);+ player_tick(K_FWD, K_FWD);+ for (int t = 0; t < 10; t++) player_tick(0, 0);+ player_tick(K_FWD, K_FWD);+ CHECK(!pl.sprinting);+ /* the key, let go, still sprints; sneaking stops it; hungry, it doesn't start */+ player_tick(K_FWD | K_SPRINT, K_SPRINT), player_tick(K_FWD, 0);+ CHECK(pl.sprinting);+ player_tick(K_FWD | K_SNEAK, K_SNEAK);+ CHECK(!pl.sprinting);+ pl.food = 6;+ player_tick(K_FWD | K_SPRINT, K_SPRINT);+ CHECK(!pl.sprinting);+ plat_remove_prefix("ut8");+ }printf("%s (%d recipes)\n", fails ? "FAILED" : "all good", N_RECIPES);return fails != 0;}