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
NumDrive: Spinning World, Tilt, Double Trouble and Stealth Game work, Laser Gun's beam holds together
Mason363884edd98c924
diff --git a/games/numdrive/src/physics.c b/games/numdrive/src/physics.cindex 7a8ceeb4..79e0cb35 100644--- a/games/numdrive/src/physics.c+++ b/games/numdrive/src/physics.c@@ -10,7 +10,7 @@vec3 phys_gravity = {0, -9.8f, 0};#define DT (1.0f / PHYS_HZ)-#define MAX_ELEMS 128 /* collision elements considered per body */+#define MAX_ELEMS 136 /* collision elements considered per body (the most a level makes is 129, in Mobile Home) */#define MAX_CONTACTS 1024#define MAX_EVENTS 64#define ITER 10@@ -372,12 +372,13 @@ static bool build_elems(Body *b) {const Block *bk = blocks[s->blk[i]];if (bk->flags & 3) cap++;}- if (cap > 255) cap = 255;+ /* every collider part first (Spinning World's box has 320, Tilt's 378: past 255 the parts furthest along x+ were left out, and that side of them let the car through), merged below, then at most 255 kept */uint32_t mark = arena_mark();- b->el = arena_alloc(sizeof(Elem) * (cap ? cap : 1));- if (!b->el) return false;- b->nel = 0;- for (int i = 0; i < s->np && b->nel < cap; i++) {+ Elem *el = arena_alloc(sizeof(Elem) * (cap ? cap : 1));+ if (!el) return false;+ int n = 0;+ for (int i = 0; i < s->np && n < cap; i++) {const Block *bk = blocks[s->blk[i]];int coll = bk->flags & 3;if (!coll) continue;@@ -387,7 +388,7 @@ static bool build_elems(Body *b) {vec3 c;float rad;part_sphere(bk, comp, k, &c, &rad);- Elem *e = &b->el[b->nel++];+ Elem *e = &el[n++];e->circle = 1;e->cx = c.x - s->com.x;e->cy = c.y - s->com.y;@@ -401,7 +402,7 @@ static bool build_elems(Body *b) {if (bb[0] > bb[3]) continue;float mnx = PK_X(k) + bb[0] / 8.0f, mny = PK_Y(k) + bb[1] / 8.0f, mnz = PK_Z(k) + bb[2] / 8.0f;float mxx = PK_X(k) + (bb[3] + 1) / 8.0f, mxy = PK_Y(k) + (bb[4] + 1) / 8.0f, mxz = PK_Z(k) + (bb[5] + 1) / 8.0f;- Elem *e = &b->el[b->nel++];+ Elem *e = &el[n++];e->circle = 0;e->cx = (mnx + mxx) * 0.5f - s->com.x;e->cy = (mny + mxy) * 0.5f - s->com.y;@@ -411,11 +412,11 @@ static bool build_elems(Body *b) {e->z1 = mxz - s->com.z;}/* merge boxes sharing an edge */- for (int i = 0; i < b->nel; i++) {- Elem *e = &b->el[i];+ for (int i = 0; i < n; i++) {+ Elem *e = &el[i];if (e->circle) continue;- for (int j = i + 1; j < b->nel; j++) {- Elem *f = &b->el[j];+ for (int j = i + 1; j < n; j++) {+ Elem *f = &el[j];if (f->circle || fabsf(e->z0 - f->z0) > 1e-4f || fabsf(e->z1 - f->z1) > 1e-4f) continue;int merged = 0;if (fabsf(e->cx - f->cx) < 1e-4f && fabsf(e->hx - f->hx) < 1e-4f && fabsf(fabsf(e->cy - f->cy) - (e->hy + f->hy)) < 1e-4f) {@@ -430,14 +431,16 @@ static bool build_elems(Body *b) {merged = 1;}if (merged) {- *f = b->el[b->nel - 1];- b->nel--;+ *f = el[n - 1];+ n--;j = i;}}}+ if (n > 255) n = 255;arena_release(mark);- arena_alloc(sizeof(Elem) * (b->nel ? b->nel : 1)); /* keep only the merged elements */+ b->el = arena_alloc(sizeof(Elem) * (n ? n : 1)); /* keep only the merged elements (where they are) */+ b->nel = (uint8_t)n;nelems += b->nel;b->bound = 0;for (int i = 0; i < b->nel; i++) {diff --git a/games/numdrive/src/vm.c b/games/numdrive/src/vm.cindex 0f5147d1..0dd19c98 100644--- a/games/numdrive/src/vm.c+++ b/games/numdrive/src/vm.c@@ -547,6 +547,17 @@ static void eval_node(Env *e, int ni, int out, Val *r) {vec3 from = in_vec(e, nd, 0), to = in_vec(e, nd, 1), hit;int o = -1;bool h = phys_raycast(from, to, &hit, &o);+ /* like Fancade: the ground (its floor, the plane y = 0) stops rays coming from above too, with no+ object hit; and a ray that hits nothing gives 0, 0, 0 for its position (fancade.com/wiki/Raycast) */+ if (from.y > 0 && to.y < 0) {+ float t = from.y / (from.y - to.y);+ vec3 g = v3(from.x + (to.x - from.x) * t, 0, from.z + (to.z - from.z) * t);+ if (!h || vdot(vsub(g, from), vsub(g, from)) < vdot(vsub(hit, from), vsub(hit, from))) {+ h = true;+ hit = g;+ o = -1;+ }+ }#ifdef HOSTif (getenv("ND_RDBG") && (vm_frame_count == atoi(getenv("ND_RDBG")) || atoi(getenv("ND_RDBG")) < 0)){@@ -563,7 +574,7 @@ static void eval_node(Env *e, int ni, int out, Val *r) {fprintf(stderr, " f%d cand obj %d flags %x local (%.3f %.3f %.3f)->(%.3f %.3f %.3f) bounds (%.2f %.2f %.2f)-(%.2f %.2f %.2f) np=%d\n", vm_frame_count, q, objs[q].flags, l.x, l.y, l.z, l2.x, l2.y, l2.z,sh->bmin.x, sh->bmin.y, sh->bmin.z, sh->bmax.x, sh->bmax.y, sh->bmax.z, sh->np);}- if (h) {+ if (h && o >= 0) {vec3 l = obj_local(&objs[o], from), l2 = obj_local(&objs[o], to);fprintf(stderr, " local (%.3f %.3f %.3f)->(%.3f %.3f %.3f) np=%d env anchor=%d\n", l.x, l.y, l.z, l2.x, l2.y, l2.z, objs[o].shape->np, e->anchor);}@@ -574,7 +585,7 @@ static void eval_node(Env *e, int ni, int out, Val *r) {r->u.i = h;} else if (out == 1) {r->t = T_VEC;- r->u.v = h ? hit : to;+ r->u.v = h ? hit : v3(0, 0, 0);} else {r->t = T_OBJ;r->u.i = h ? o : -1;@@ -695,9 +706,10 @@ static void exec_stmt(Env *e, int ni) {Val v;eval(e, node_in(nd, 0), &v);deref(&v);- /* a value wired from an input the outer script left unconnected changes nothing (scripts use- "set a default, then set the input" for optional inputs) */- if (v.t == 0xff && node_in(nd, 0) != NONE16) return;+ /* no value (Value not wired, or wired from an input the outer script left unconnected) changes+ nothing, as in Fancade (fancade.com/wiki/Set_Variable; scripts use "set a default, then set the+ input" for optional inputs) */+ if (v.t == 0xff) return;if (v.t != vs->type && !(vs->type == T_CON && v.t == T_OBJ)) val_default(&v, vs->type);var_write(vs, 0, &v);return;@@ -709,7 +721,7 @@ static void exec_stmt(Env *e, int ni) {if (!ptr.isptr) return;eval(e, node_in(nd, 1), &v);deref(&v);- if (v.t == 0xff && node_in(nd, 1) != NONE16) return;+ if (v.t == 0xff) return; /* no value: nothing changes, as above */if (v.t != ptr.u.p.vs->type && !(ptr.u.p.vs->type == T_CON && v.t == T_OBJ)) val_default(&v, ptr.u.p.vs->type);var_write(ptr.u.p.vs, ptr.u.p.idx, &v);return;@@ -1000,6 +1012,19 @@ static bool make_env(Prog *p, int parent, int pnode, int bx, int by, int bz) {const uint8_t *ob = nd + 10 + 2 * nd[9];uint16_t a = rd16(ob);e->anchor = a == NONE16 ? -1 : pe->tbase + a;+ if (e->anchor >= 0) {+ /* a block split between two objects (a Slider: one voxel group on its rail, one on the part that slides)+ belongs to the object holding its first group. The pack tool took the group at the block's centre,+ and Double Trouble's gate then cast its rays from the rail, stopping as soon as it reached them. */+ int lo = pe->tbase, hi = pp->is_level ? nlevelobj : pe->tbase + pp->ntmpl;+ for (int i = lo; i < hi && i < nobj; i++) {+ int pi = shape_find(objs[i].shape, bx, by, bz);+ if (pi >= 0 && PK_C(objs[i].shape->key[pi]) == 0) {+ e->anchor = i;+ break;+ }+ }+ }e->selfobj = arena_alloc(2 * (p->nself ? p->nself : 1));if (!e->selfobj) return false;for (int k = 0; k < p->nself; k++) {diff --git a/games/numdrive/src/world.c b/games/numdrive/src/world.cindex fbe709f6..ee81c1e5 100644--- a/games/numdrive/src/world.c+++ b/games/numdrive/src/world.c@@ -388,7 +388,8 @@ static void shape_finish(Shape *s) {}{/* Fancade's object position: the centre of its bounds, where a stock block counts its whole cell- and a custom block its voxels */+ and a custom block its voxels; an object without colliders counts whole cells (Laser Gun's beams,+ thin lines of voxels at a cell's corner, are placed by their cell's centre) */float lo[3] = {1e9f, 1e9f, 1e9f}, hi[3] = {-1e9f, -1e9f, -1e9f};for (int i = 0; i < s->np; i++) {const Block *b = blocks[s->blk[i]];@@ -396,7 +397,8 @@ static void shape_finish(Shape *s) {const uint8_t *bb = b->bb + PK_C(k) * 6;int c[3] = {PK_X(k), PK_Y(k), PK_Z(k)};for (int a = 0; a < 3; a++) {- float l = (b->flags & 8) ? c[a] : c[a] + bb[a] / 8.0f, h = (b->flags & 8) ? c[a] + 1 : c[a] + (bb[a + 3] + 1) / 8.0f;+ bool cell = (b->flags & 8) || !coll;+ float l = cell ? c[a] : c[a] + bb[a] / 8.0f, h = cell ? c[a] + 1 : c[a] + (bb[a + 3] + 1) / 8.0f;if (l < lo[a]) lo[a] = l;if (h > hi[a]) hi[a] = h;}