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
Rider: the track streamed per polygon, the picture in the physics' free memory, a search that waits
Mason363347851aebd05
diff --git a/games/rider/README.md b/games/rider/README.mdindex 61cc3829..f865eaa4 100644--- a/games/rider/README.md+++ b/games/rider/README.md@@ -23,7 +23,7 @@## Highlights* **One button:** hold it and the bike speeds up on the ground. Hold it in the air and the bike turns backwards. Let go to land on both wheels, not on its head.-* **The game's physics:** its gravity, speed, push down in the air, turning force and the way the turn dies down when you let go, all read from the game's own settings. The track is slippery, as in the game.+* **The game's own physics:** Box2D, the engine Rider runs on, set up as the game sets it up: the bike's body, wheels and sensors, their weights and every number, read from the game's files. Platforms tip, swing, fall and throw you as in the game. The track is slippery, as in the game.* **The endless run:** the game's 95 track pieces, picked at random, harder as your score grows. Every landed flip is a point, and two wheels down together is a perfect flip.* **48 levels** in six groups, from Easy to Extreme, with the game's tracks: loops, ramps that tip, catapults, trapdoors, falling platforms, speed pads and red saws. Finish fast for three stars. Each flip takes half a second off your time.* **55 bikes:** win them with gems, or open the special ones by playing runs, scoring, getting stars and finishing challenges, as the game has it.@@ -75,8 +75,9 @@ In the endless run every landed flip is a point. Gems you pick up win new bikes.Made by Mason Chen as part of NumPlay, inspired by **Rider** by **Ketchapp**. Not affiliated with Ketchapp.* From the game's files: the levels, the endless run's pieces, the collision shapes, the physics numbers, the bikes' unlock rules, the challenges, the colour themes and the texts, read by `tools/data.py`. The bikes and the icon are drawn again as outlines; none of the game's pictures are kept.+* The physics is **LiquidFun 1.1.0** (Box2D 2.3.0) by Erin Catto and Google, as Corona SDK builds it, altered to fit the calculator's memory (zlib license, see `src/Box2D/License.txt`).* The texts use NumPlay's **Nunito** (SIL Open Font License).## License-The game's code is licensed under the GNU General Public License v3.0: see the `LICENSE` file at the root of the repository. Rider and its levels belong to Ketchapp. Nunito keeps the SIL Open Font License (`LICENSES/OFL-1.1-Nunito.txt`).+The game's code is licensed under the GNU General Public License v3.0: see the `LICENSE` file at the root of the repository. Rider and its levels belong to Ketchapp. LiquidFun keeps its zlib license (`LICENSES/Zlib-LiquidFun.txt`). Nunito keeps the SIL Open Font License (`LICENSES/OFL-1.1-Nunito.txt`).diff --git a/games/rider/src/game.c b/games/rider/src/game.cindex 3658c745..873475d9 100644--- a/games/rider/src/game.c+++ b/games/rider/src/game.c@@ -765,24 +765,25 @@ static void endless_more(rd_run *r) {/* the bike goes 18 pixels a frame at most: what is this near comes in some frames before it can touch it; short of* memory (many falling platforms and their contacts), only what is right round the bike stays */static bool tight;-static bool near_box(float x0, float y0, float x1, float y1, float cx, float cy, float m) {- if (tight) return x1 > cx - 50 && x0 < cx + 80 && y1 > cy - 55 && y0 < cy + 55;- return x1 > cx - m - 80 && x0 < cx + m + 150 && y1 > cy - m - 90 && y0 < cy + m + 90;+typedef struct {+ float x0, y0, x1, y1;+} box_t;+static bool near_box(float x0, float y0, float x1, float y1, const box_t *w, float m) {+ return x1 > w->x0 - m && x0 < w->x1 + m && y1 > w->y0 - m && y0 < w->y1 + m;}static void stream(rd_run *r, bool all) {rd_bikestate *b = &r->b;tight = ph_free() < RESERVE;- /* the windows: the bike, and anything falling free (awake) */- float wx[MAXDYN + 1], wy[MAXDYN + 1];+ /* the windows: round the bike, and round anything falling free (awake) */+ box_t win[MAXDYN + 1];int nw = 0;- wx[nw] = b->x, wy[nw] = b->y, nw++;+ if (tight) win[nw++] = (box_t){b->x - 50, b->y - 55, b->x + 80, b->y + 55};+ else win[nw++] = (box_t){b->x - 80, b->y - 90, b->x + 150, b->y + 90};for (int k = 0; k < MAXDYN && !tight; k++) {rd_dyn *d = &r->dyn[k];- if (d->used && d->body && (d->flags & DY_FREE) && ph_awake(d->body)) {- float x, y, a;- ph_get(d->body, &x, &y, &a);- wx[nw] = x, wy[nw] = y, nw++;- }+ box_t *w = &win[nw];+ if (d->used && d->body && (d->flags & DY_FREE) && ph_awake(d->body) && ph_bounds(d->body, &w->x0, &w->y0, &w->x1, &w->y1))+ w->x0 -= 50, w->y0 -= 50, w->x1 += 50, w->y1 += 50, nw++;}for (int i = 0; i < r->nlive; i++) {rd_live *l = &r->live[i];@@ -796,8 +797,8 @@ static void stream(rd_run *r, bool all) {float m = l->dyn != NO_DYN ? 60 : 0;bool in = false, keep = false;for (int w = 0; w < nw; w++) {- in |= near_box(x0, y0, x1, y1, wx[w], wy[w], m);- keep |= near_box(x0, y0, x1, y1, wx[w], wy[w], m + 60);+ in |= near_box(x0, y0, x1, y1, &win[w], tight ? 0 : m);+ keep |= near_box(x0, y0, x1, y1, &win[w], tight ? 0 : m + 60);}if (l->dyn != NO_DYN) { /* a moving object: all of it */if (all) in = keep;@@ -823,8 +824,8 @@ static void stream(rd_run *r, bool all) {for (int j = 1; j < n; j++) a0 = fminf(a0, xy[2 * j]), a1 = fmaxf(a1, xy[2 * j]), b0 = fminf(b0, xy[2 * j + 1]), b1 = fmaxf(b1, xy[2 * j + 1]);bool pin = false, pkeep = false;for (int w = 0; w < nw; w++) {- pin |= near_box(a0, b0, a1, b1, wx[w], wy[w], 0);- pkeep |= near_box(a0, b0, a1, b1, wx[w], wy[w], 60);+ pin |= near_box(a0, b0, a1, b1, &win[w], 0);+ pkeep |= near_box(a0, b0, a1, b1, &win[w], tight ? 0 : 60);}if (all) pin = pkeep;uint64_t bit = (uint64_t)1 << k;diff --git a/games/rider/tests/play.c b/games/rider/tests/play.cindex 444ce733..d8b1d217 100644--- a/games/rider/tests/play.c+++ b/games/rider/tests/play.c@@ -179,16 +179,23 @@ static void snap_save(snap_t *s) { s->run = run, s->n = ph_top(), memcpy(s->mem,static void snap_load(const snap_t *s) { run = s->run, memcpy(ph_arena(), s->mem, s->n); }static void snap_copy(snap_t *d, const snap_t *s) { d->run = s->run, d->n = s->n, memcpy(d->mem, s->mem, s->n); }static snap_t beam[BEAM], next_beam[BEAM * PAT];+static int spread = 3; /* states kept at each stretch of track */static uint8_t paths[BEAM][1600], next_paths[BEAM * PAT][1600];static float worth(const rd_run *r) { /* (a loop takes the bike back over its x a while: how far it rode counts too) */return r->mode == RUN_ENDLESS ? (r->score + r->pending) * 2000.0f + r->perfect * 300 + r->b.x : r->b.max_x + 0.5f * r->b.odo;}-static int solve_run(int mode, int level, int bike, uint32_t seed, uint8_t *out, int max_segs) {+/* (wait: the ride begins with a touch and that many pieces let go, for platforms that move in time) */+static int solve_from(int mode, int level, int bike, uint32_t seed, uint8_t *out, int max_segs, int wait) {int nb = 1;run_start(&run, mode, level, bike, mode == RUN_LEVEL ? level / 8 : 6, seed);+ for (int sg = 0; sg <= wait; sg++) {+ int p = sg ? 1 : 4;+ for (int f = 0; f < SEG && !run.ended; f++) run_step(&run, pat(p, f));+ for (int k = 0; k < BEAM; k++) paths[k][sg] = (uint8_t)p;+ }snap_save(&beam[0]);float far_x = -1e9f;- for (int sg = 0; sg < max_segs; sg++) {+ for (int sg = wait + 1; sg < max_segs; sg++) {int nn = 0;for (int i = 0; i < nb; i++)for (int p = 0; p < PAT; p++) {@@ -233,7 +240,7 @@ static int solve_run(int mode, int level, int bike, uint32_t seed, uint8_t *out,same += (int)floorf(a->b.max_x / 48) == (int)floorf(c->b.max_x / 48);}if (near) continue;- if (same >= 3) spare[ns++] = order[q];+ if (same >= spread) spare[ns++] = order[q];else pick[np++] = order[q];}for (int q = 0; q < ns && np < BEAM; q++) pick[np++] = spare[q];@@ -244,6 +251,15 @@ static int solve_run(int mode, int level, int bike, uint32_t seed, uint8_t *out,printf(" [out of time at x %.0f]", beam[0].run.b.x);return 0;}+static int solve_run(int mode, int level, int bike, uint32_t seed, uint8_t *out, int max_segs) {+ int n = 0;+ for (int k = 0; k < (mode == RUN_LEVEL ? 2 : 1) && !n; k++) {+ spread = k ? BEAM : 3; /* (then the plain furthest ones) */+ for (int w = 0; w < (mode == RUN_LEVEL ? 8 : 1) && !n; w++) n = solve_from(mode, level, bike, seed, out, max_segs, w);+ }+ spread = 3;+ return n;+}static int solve_level(int level, uint8_t *out, int max_segs) { return solve_run(RUN_LEVEL, level, 0, 9, out, max_segs); }static int ride(int mode, int level, int flips, int frames, int bike) {@@ -255,7 +271,7 @@ static int ride(int mode, int level, int flips, int frames, int bike) {static void test_levels(void) {/* levels ridden to their end by a search over the button (the game's own tracks and times) */static uint8_t path[1600];- static const int some[] = {0, 4, 7, 17};+ static const int some[] = {0, 1, 10, 25}; /* Easy 1 and 2 (#341), a catapult, falling platforms (play solve 0 47: all) */int ok = 0;for (unsigned i = 0; i < sizeof some / sizeof *some; i++) {int n = solve_level(some[i], path, 300);