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
Crossy Road and NumDrive: Quit game asks first; Crossy coins add up
Mason363e0c4d4cb05c9
diff --git a/games/crossyroad/src/crossy.c b/games/crossyroad/src/crossy.cindex de552753..88be566c 100644--- a/games/crossyroad/src/crossy.c+++ b/games/crossyroad/src/crossy.c@@ -145,12 +145,13 @@ struct Rom {uint8_t obstacle_pct[12];uint8_t kinds[4];int8_t dx[4], dz[4];- char font_chars[23];- uint8_t font_w[22];- uint16_t font[22][10];+ char font_chars[30];+ uint8_t font_w[29];+ uint16_t font[29][10];uint16_t hand_ol[14], hand_in[14];char save_name[15];char s_crossy[7], s_road[5], s_new_top[8];+ char s_quit[10], s_quit_q[11], s_no[3], s_yes[4];};struct State {@@ -161,6 +162,8 @@ struct State {float st_time, game_time, fade, restart_t;float eagle_x, eagle_y, eagle_z;int state, paused, show_logo, new_top, restarting, eagle_on;+ int pause_sel; // on the pause screen: 0 the game, 1 Quit game+ int quitting, quit_sel; // the "QUIT GAME?" question is open; 1 on YESint score, top_score, coins;int gen_next, set_left, set_type, prev_dir, start_end;uint32_t rng_s;@@ -216,6 +219,9 @@ static struct State G;#define eagle_z G.eagle_z#define state G.state#define paused G.paused+#define pause_sel G.pause_sel+#define quitting G.quitting+#define quit_sel G.quit_sel#define show_logo G.show_logo#define new_top G.new_top#define restarting G.restarting@@ -420,8 +426,8 @@ static const struct Rom rom_init = {.dz = {1, 0, -1, 0},// Font: the original's blocky digits (decoded from the game) and matching// capitals. 10 rows; bit 11 is the leftmost column.- .font_chars = "0123456789ACDENOPRSTWY",- .font_w = {10, 5, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 12, 10},+ .font_chars = "0123456789ACDEGILMNOPQRSTUWY?",+ .font_w = {10, 5, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 4, 10, 12, 10, 10, 10, 10, 10, 10, 10, 10, 12, 10, 10},.font = {GLYPH(0x1FE, 0x3FF, 0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x3FF, 0x1FE), // 0GLYPH(0x3C0, 0x3E0, 0x1E0, 0x1E0, 0x1E0, 0x1E0, 0x1E0, 0x1E0, 0x1E0, 0x1E0), // 1@@ -437,14 +443,21 @@ static const struct Rom rom_init = {GLYPH(0x1FF, 0x3FF, 0x3C0, 0x3C0, 0x3C0, 0x3C0, 0x3C0, 0x3C0, 0x3FF, 0x1FF), // CGLYPH(0x3FE, 0x3FF, 0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x3FF, 0x3FE), // DGLYPH(0x1FF, 0x3FF, 0x3C0, 0x3C0, 0x3F8, 0x3F8, 0x3C0, 0x3C0, 0x3FF, 0x1FF), // E+ GLYPH(0x1FF, 0x3FF, 0x3C0, 0x3C0, 0x3DF, 0x3DF, 0x3CF, 0x3CF, 0x3FF, 0x1FF), // G+ GLYPH(0x3C0, 0x3C0, 0x3C0, 0x3C0, 0x3C0, 0x3C0, 0x3C0, 0x3C0, 0x3C0, 0x3C0), // I+ GLYPH(0x3C0, 0x3C0, 0x3C0, 0x3C0, 0x3C0, 0x3C0, 0x3C0, 0x3C0, 0x3FF, 0x1FF), // L+ {0xF0F, 0xF9F, 0xFFF, 0xFFF, 0xF6F, 0xF6F, 0xF0F, 0xF0F, 0xF0F, 0xF0F}, // MGLYPH(0x3CF, 0x3EF, 0x3FF, 0x3FF, 0x3DF, 0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x3CF), // NGLYPH(0x1FE, 0x3FF, 0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x3FF, 0x1FE), // OGLYPH(0x3FE, 0x3FF, 0x3CF, 0x3CF, 0x3FF, 0x3FE, 0x3C0, 0x3C0, 0x3C0, 0x3C0), // P+ GLYPH(0x1FE, 0x3FF, 0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x3EF, 0x3FE, 0x3FF, 0x1F3), // QGLYPH(0x3FE, 0x3FF, 0x3CF, 0x3CF, 0x3FE, 0x3FF, 0x3CF, 0x3CF, 0x3CF, 0x3CF), // RGLYPH(0x1FF, 0x3FF, 0x3C0, 0x3C0, 0x3FE, 0x1FF, 0x00F, 0x00F, 0x3FF, 0x3FE), // SGLYPH(0x3FF, 0x3FF, 0x078, 0x078, 0x078, 0x078, 0x078, 0x078, 0x078, 0x078), // T+ GLYPH(0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x3FF, 0x1FE), // U{0xF0F, 0xF0F, 0xF0F, 0xF6F, 0xF6F, 0xFFF, 0xFFF, 0xF9F, 0xF0F, 0xF0F}, // WGLYPH(0x3CF, 0x3CF, 0x3CF, 0x3CF, 0x3FF, 0x1FE, 0x078, 0x078, 0x078, 0x078), // Y+ GLYPH(0x1FE, 0x3FF, 0x00F, 0x00F, 0x07E, 0x078, 0x078, 0x000, 0x078, 0x078), // ?},// Pixel-art pointing hand (tap hint), 12x14: outline and fill masks..hand_ol = {0x0E0, 0x1B0, 0x1B0, 0x1BE, 0x1B5, 0x7B5, 0x9D5, 0x8C1,@@ -455,6 +468,10 @@ static const struct Rom rom_init = {.s_crossy = "CROSSY",.s_road = "ROAD",.s_new_top = "NEW TOP",+ .s_quit = "QUIT GAME",+ .s_quit_q = "QUIT GAME?",+ .s_no = "NO",+ .s_yes = "YES",};#endif@@ -477,6 +494,10 @@ static const struct Rom rom_init = {#define str_crossy G.rom.s_crossy#define str_road G.rom.s_road#define str_new_top G.rom.s_new_top+#define str_quit G.rom.s_quit+#define str_quit_q G.rom.s_quit_q+#define str_no G.rom.s_no+#define str_yes G.rom.s_yesstatic void init_palette(void) {for (int i = 0; i < NCOLORS; i++) shade[i] = i;@@ -1087,12 +1108,16 @@ static void start_hop(int dir) {P.log = -1;}+static void write_save(void);++// Coins are saved as soon as they are collected: they add up across rounds.static void collect_coin(void) {Lane *L = lane_at(iround(P.z));int col = iround(P.x);if (L->coin != NO_COIN && L->coin == col && fabs_(P.x - col) < 0.4f && fabs_(P.z - L->row) < 0.4f) {L->coin = NO_COIN;coins++;+ write_save();spawn_parts(col, P.base + 0.3f, L->row, 8, C_GOLD, C_COIN, 1.0f, 3.0f);}if (L->type == L_RIVER && P.log >= 0) {@@ -1100,6 +1125,7 @@ static void collect_coin(void) {if (o->coin >= 0 && fabs_(o->x - o->kind * 0.5f + 0.5f + o->coin - P.x) < 0.4f) {o->coin = -1;coins++;+ write_save();spawn_parts(P.x, P.base + 0.3f, L->row, 8, C_GOLD, C_COIN, 1.0f, 3.0f);}}@@ -1424,7 +1450,7 @@ static float bob_of(const Lane *L, int idx) {static void draw_coin(float x, float g, float z) {float sx = sx_of(x, z);if (sx < -10 || sx > SW + 10) return;- float a = game_time * 3.2f;+ float a = game_time * 1.6f; // a turn in 0.6 sfloat ph = a - (int)a; // 0..1 turnfloat c = ph < 0.5f ? 1 - ph * 4 : -3 + ph * 4;float ac = fabs_(c), w = 0.2f * ac + 0.02f, d = 0.2f * (1 - ac) + 0.02f;@@ -1643,11 +1669,12 @@ static void draw_coin_icon(int x, int y) {fill_rect(x + 7, y + 6, 4, 4, C_COIN);}+// The coins ever collected, top right; smaller once too wide for the corner.static void draw_coins_hud(void) {char buf[12];itoa_(coins, buf);- int w = text_width(buf, 2);- text_ol(SW - 28 - w, 6, buf, 2, C_GOLD);+ int sc = text_width(buf, 2) > 110 ? 1 : 2, w = text_width(buf, sc);+ text_ol(SW - 28 - w, sc == 2 ? 6 : 11, buf, sc, C_GOLD);draw_coin_icon(SW - 22, 8);}@@ -1699,11 +1726,32 @@ static void draw_play_button(int cx, int y) {for (int i = 0; i < 10; i++) fill_rect(cx - 9 + i * 2, y + 9 + i, 2, 22 - 2 * i, C_WHITE);}+// A small button with an outline, blue when selected.+static void draw_small_button(int cx, int y, const char *s, int on) {+ int w = text_width(s, 1) + 18;+ fill_rect(cx - w / 2 - 2, y - 2, w + 4, 22, C_OUTLINE);+ fill_rect(cx - w / 2, y, w, 18, on ? C_WHITE : C_GRAY);+ fill_rect(cx - w / 2 + 2, y + 2, w - 4, 14, on ? C_BTN : C_GRAY);+ text_ol(cx - text_width(s, 1) / 2 + 1, y + 4, s, 1, C_WHITE);+}++// Paused: the pause bars (white while they are selected: any move resumes), and Quit game below.static void draw_pause(void) {- fill_rect(140, 94, 16, 48, C_OUTLINE);- fill_rect(164, 94, 16, 48, C_OUTLINE);- fill_rect(142, 96, 12, 44, C_WHITE);- fill_rect(166, 96, 12, 44, C_WHITE);+ int c = pause_sel ? C_GRAY : C_WHITE;+ fill_rect(140, 84, 16, 48, C_OUTLINE);+ fill_rect(164, 84, 16, 48, C_OUTLINE);+ fill_rect(142, 86, 12, 44, c);+ fill_rect(166, 86, 12, 44, c);+ draw_small_button(160, 150, str_quit, pause_sel);+}++// Leaving asks first: Back sits right next to OK.+static void draw_quit_question(void) {+ fill_rect(24, 68, 272, 104, C_OUTLINE);+ fill_rect(26, 70, 268, 100, C_BTN_S);+ text_ol(160 - text_width(str_quit_q, 2) / 2, 84, str_quit_q, 2, C_WHITE);+ draw_small_button(120, 132, str_no, !quit_sel);+ draw_small_button(200, 132, str_yes, quit_sel);}static void render(void) {@@ -1731,7 +1779,8 @@ static void render(void) {}}draw_coins_hud();- if (paused) draw_pause();+ if (paused && !quitting) draw_pause();+ if (quitting) draw_quit_question();}// ---------------------------------------------------------------------------@@ -1795,7 +1844,7 @@ static void load_save(void) {const uint8_t *d = f + 2 + sizeof(save_name);uint32_t v[3];for (int i = 0; i < 3; i++) v[i] = d[4 * i] | d[4 * i + 1] << 8 | d[4 * i + 2] << 16 | (uint32_t)d[4 * i + 3] << 24;- if (save_sum(v[0], v[1]) != v[2] || v[0] > 1000000 || v[1] > 1000000) return;+ if (save_sum(v[0], v[1]) != v[2] || v[0] > 999999999 || v[1] > 999999999) return;top_score = (int)v[0];coins = (int)v[1];}@@ -1944,13 +1993,23 @@ int main(int argc, char *argv[]) {else if (PRESSED(eadk_key_right)) dir = 1;else if (PRESSED(eadk_key_down)) dir = 2;else if (PRESSED(eadk_key_left)) dir = 3;- if (PRESSED(eadk_key_back)) {- if (state == ST_PLAY && !paused) paused = 1;+ int ok = PRESSED(eadk_key_ok) || PRESSED(eadk_key_exe);+ if (quitting) {+ if (PRESSED(eadk_key_left) || PRESSED(eadk_key_right)) quit_sel ^= 1;+ if (PRESSED(eadk_key_back)) quitting = 0;+ else if (ok && quit_sel) break;+ else if (ok) quitting = 0;+ dir = -1;+ } else if (PRESSED(eadk_key_back)) {+ if (state == ST_PLAY && !paused) paused = 1, pause_sel = 0;else if (paused) paused = 0;- else break;- }- if (paused) {- if (dir >= 0) paused = 0;+ else quitting = 1, quit_sel = 0; // title or game over: nothing to pause+ dir = -1;+ } else if (paused) {+ if (PRESSED(eadk_key_down)) pause_sel = 1;+ else if (pause_sel && PRESSED(eadk_key_up)) pause_sel = 0;+ else if (pause_sel && ok) quitting = 1, quit_sel = 0;+ else if (!pause_sel && dir >= 0) paused = 0;dir = -1;}if (dir >= 0 && !restarting) {@@ -1997,6 +2056,7 @@ int main(int argc, char *argv[]) {#endifpresent();}+ write_save();#if PLATFORM_DEVICE && !defined(HOST)g9 = caller_r9;#endifdiff --git a/games/numdrive/src/main.c b/games/numdrive/src/main.cindex aa4f255f..fdaceb20 100644--- a/games/numdrive/src/main.c+++ b/games/numdrive/src/main.c@@ -19,7 +19,7 @@ const uint32_t eadk_api_level __attribute__((section(".rodata.eadk_api_level")))#endif#endif-enum { ST_PLAY, ST_CARD, ST_LEVELS };+enum { ST_PLAY, ST_CARD, ST_LEVELS, ST_QUIT };#define SHOT_FRAMES 10 /* viewfinder shown before the photo */static int win_timer = -1, lose_timer = -1;@@ -119,7 +119,7 @@ int main(int argc, char **argv) {return plat_end(1);}int state = ST_PLAY, kind = CARD_PAUSE, anim = 0, sel = 1, lsel = 0, lscroll = 0;- bool dirty = true;+ bool dirty = true, qyes = false;uint64_t prev = 0;uint32_t last = plat_millis();int acc = 0;@@ -191,13 +191,28 @@ int main(int argc, char **argv) {render_frame(hud_post);} else if (state == ST_CARD) {int nb = card_buttons();- if (nb > 1) {- if ((hit & KEY(K_LEFT)) && sel > 0) sel--, dirty = true;- if ((hit & KEY(K_RIGHT)) && sel < nb - 1) sel++, dirty = true;+ bool ok = (hit & (KEY(K_OK) | KEY(K_EXE))) != 0;+ if (sel == CARD_SEL_QUIT) { /* Quit game, under the other buttons */+ if (hit & KEY(K_UP)) sel = 1, dirty = true;+ if (ok) {+ state = ST_QUIT;+ qyes = false;+ dirty = true;+ continue;+ }} else {- sel = 1;+ if (nb > 1) {+ if ((hit & KEY(K_LEFT)) && sel > 0) sel--, dirty = true;+ if ((hit & KEY(K_RIGHT)) && sel < nb - 1) sel++, dirty = true;+ } else {+ sel = 1;+ }+ if (hit & KEY(K_DOWN)) sel = CARD_SEL_QUIT, dirty = true;+ }+ if ((hit & KEY(K_BACK)) && kind == CARD_PAUSE) { /* Back resumes, as it paused */+ state = ST_PLAY;+ continue;}- bool ok = (hit & (KEY(K_OK) | KEY(K_EXE))) != 0;if ((hit & KEY(K_BACK)) || (ok && kind == CARD_PAUSE && sel == 2)) { /* the "<" arrow or Levels */state = ST_LEVELS;lsel = cur;@@ -205,7 +220,7 @@ int main(int argc, char **argv) {dirty = true;continue;}- if (ok) {+ if (ok && sel != CARD_SEL_QUIT) {if (kind == CARD_PAUSE && sel == 1) {state = ST_PLAY;} else {@@ -221,6 +236,19 @@ int main(int argc, char **argv) {if (kind != CARD_PAUSE || full) card_draw(anim, sel, full);dirty = false;anim++;+ } else if (state == ST_QUIT) {+ /* asks first: Back sits right next to OK */+ if (hit & (KEY(K_LEFT) | KEY(K_RIGHT))) qyes = !qyes, dirty = true;+ bool ok = (hit & (KEY(K_OK) | KEY(K_EXE))) != 0;+ if (ok && qyes) break;+ if (ok || (hit & KEY(K_BACK))) {+ state = ST_CARD;+ anim = 14;+ dirty = true;+ continue;+ }+ if (dirty) quit_draw(qyes);+ dirty = false;} else {int old = lsel;if (hit & KEY(K_LEFT)) lsel--;@@ -236,7 +264,12 @@ int main(int argc, char **argv) {state = ST_PLAY;continue;}- if (hit & KEY(K_BACK)) break; /* leave the game (Home also works, but it closes NumPlay too) */+ if (hit & KEY(K_BACK)) { /* back to the card */+ state = ST_CARD;+ anim = 14;+ dirty = true;+ continue;+ }if (dirty) levels_draw(lsel, lscroll);dirty = false;}diff --git a/games/numdrive/src/ui.c b/games/numdrive/src/ui.cindex 5e769ab7..ba9d420b 100644--- a/games/numdrive/src/ui.c+++ b/games/numdrive/src/ui.c@@ -406,13 +406,20 @@ static void card_btns(int sel, int yb) {g_text_c(&font_s, lx, yb + 25 - font_s.base, "Levels", C_WHITE, 32);}/* focus ring */- int fx = sel == 0 ? xb : sel == 1 ? xb + ws : xb + wb - wl;- int fw = sel == 0 ? ws : sel == 1 ? wb - ws - wl : wl;- g_rect(fx + 1, yb + 1, fw - 2, 1, C_WHITE, 26);- g_rect(fx + 1, yb + h - 5, fw - 2, 1, C_WHITE, 26);- g_rect(fx + 1, yb + 1, 1, h - 5, C_WHITE, 26);- g_rect(fx + fw - 2, yb + 1, 1, h - 5, C_WHITE, 26);+ if (sel != CARD_SEL_QUIT) {+ int fx = sel == 0 ? xb : sel == 1 ? xb + ws : xb + wb - wl;+ int fw = sel == 0 ? ws : sel == 1 ? wb - ws - wl : wl;+ g_rect(fx + 1, yb + 1, fw - 2, 1, C_WHITE, 26);+ g_rect(fx + 1, yb + h - 5, fw - 2, 1, C_WHITE, 26);+ g_rect(fx + 1, yb + 1, 1, h - 5, C_WHITE, 26);+ g_rect(fx + fw - 2, yb + 1, 1, h - 5, C_WHITE, 26);+ }}+ /* Quit game, small, under the others (Down to reach it) */+ int qw = g_text_w(&font_s, "Quit game") + 16, qy = yb + h + 5;+ bool q = sel == CARD_SEL_QUIT;+ g_button(160 - qw / 2, qy, qw, 15, 5, q ? C_BLUE : C_GRAY, q ? C_BLUE_D : C_GRAY_D, q);+ g_text_c(&font_s, 160, qy + 12 - font_s.base, "Quit game", C_WHITE, 32);}void card_draw(int anim, int sel, bool full) {@@ -493,8 +500,8 @@ void card_draw(int anim, int sel, bool full) {}}g_begin(buf, sy, n);- if (full || (ybtn - 3 < sy + n && ybtn + 33 > sy)) card_btns(sel, ybtn);- if (full) {+ if (full || (ybtn - 3 < sy + n && ybtn + 54 > sy)) card_btns(sel, ybtn);+ if (full && cd.kind != CARD_PAUSE) { /* Back: the level list (on the pause card, Back resumes) */g_icon(&ic_back, 34, 84, C_WHITE, 32);g_icon(&ic_back, 35, 84, C_WHITE, 32);}@@ -565,3 +572,25 @@ void levels_draw(int sel, int scroll) {plat_push(0, sy, SCREEN_W, n, buf);}}++/* ------------------------------------------------------------------ quit */+void quit_draw(bool yes) {+ for (int sy = 0; sy < SCREEN_H; sy += STRIP_H) {+ int n = SCREEN_H - sy < STRIP_H ? SCREEN_H - sy : STRIP_H;+ uint16_t *buf = render_buffer();+ for (int r = 0; r < n; r++) bg_row(buf + r * SCREEN_W, sy + r, 0, SCREEN_W);+ g_begin(buf, sy, n);+ g_rrect(63, 75, 200, 94, 12, C_SHADOW, 13);+ g_rrect(59, 71, 202, 94, 13, C_BLACK, 32);+ g_rrect(60, 72, 200, 92, 12, C_WHITE, 32);+ g_text_c(&font_m, 160, 100 - font_m.base, "Quit game?", C_OUTLINE, 32);+ g_text_c(&font_s, 160, 116 - font_s.base, "You can come back anytime.", C_CAPTION, 32);+ for (int k = 0; k < 2; k++) {+ bool on = k == yes;+ int x = k ? 170 : 80;+ g_button(x, 126, 70, 26, 6, on ? C_BLUE : C_GRAY, on ? C_BLUE_D : C_GRAY_D, on);+ g_text_c(&font_s, x + 35, 126 + 17 - font_s.base, k ? "Yes" : "No", C_WHITE, 32);+ }+ plat_push(0, sy, SCREEN_W, n, buf);+ }+}diff --git a/games/numdrive/src/ui.h b/games/numdrive/src/ui.hindex ed97834a..7baa07e8 100644--- a/games/numdrive/src/ui.h+++ b/games/numdrive/src/ui.h@@ -17,8 +17,11 @@ void ui_capture_background(void);/* card screen; anim counts frames since the card appeared; sel is the focused button */void card_setup(int kind, int level);void card_draw(int anim, int sel, bool full);+#define CARD_SEL_QUIT 9 /* sel: the Quit game button under the others */int card_buttons(void); /* number of buttons (1 to 3) *//* level select */void levels_draw(int sel, int scroll);+/* "Quit game?" over the blurred background, Yes focused or not */+void quit_draw(bool yes);#endifdiff --git a/tests/test_games.py b/tests/test_games.pyindex b2ca885e..8732902f 100644--- a/tests/test_games.py+++ b/tests/test_games.py@@ -46,11 +46,13 @@ GAMES = {"chess": ("NumChess.nwa", "numchess.sav", presses((1500, "ok"), (2500, "ok")), 4000, [], 2500),"numdash": ("NumDash.nwa", "numdash.nds", presses((2500, "ok"), (4000, "ok"), (5500, "ok")), 9000,presses((2500, "ok")), 5000),- # pause, level list, next level, play: that saves the level to start from+ # pause, Levels, level list, next level, play: that saves the level to start from# (held keys: the pause card's frames are slow while it slides in)"numdrive": ("NumDrive.nwa", "drivemad.sav",- presses((1500, "ok", 250), (2000, "back", 250), (2500, "right", 250), (3000, "ok", 250)), 5000,- presses((1500, "ok", 250), (2000, "back", 250), (2500, "left", 250), (3000, "ok", 250)), 5000),+ presses((1500, "ok", 250), (2000, "right", 250), (2500, "ok", 250), (3000, "right", 250),+ (3500, "ok", 250)), 5500,+ presses((1500, "ok", 250), (2000, "right", 250), (2500, "ok", 250), (3000, "left", 250),+ (3500, "ok", 250)), 5500),"tetris": ("Tetris.nwa", "tetris.sav", presses((1200, "ok")) + every(2500, 7000, 500, "up"), 8000,presses((1200, "ok"), (2500, "ok")), 5000),}