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: the Ender Dragon shown when out of sight, and kept out of the island
Mason3630e3c50a26643
diff --git a/games/numblocks/src/dims.h b/games/numblocks/src/dims.hindex 2512973f..bbcb994d 100644--- a/games/numblocks/src/dims.h+++ b/games/numblocks/src/dims.h@@ -44,6 +44,8 @@ void dragon_enter(void); /* (end.c) */void end_tick(void);float dragon_bar(void);bool dragon_beam(float *from, float *to);+int end_marks(float (*at)[3], uint8_t *kind, int max); /* (end.c) the dragon and its whole crystals: kind 0, 1 */+bool view_mark(float x, float y, float z, float far, float *sx, float *sy, float *ux, float *uy); /* (render.c) */void dragon_offsets(int i, float pt, float *yaw, float *y);float dragon_anim(float pt);void throw_eye(int tx, int ty, int tz); /* (mob.c) an eye of ender towards there */diff --git a/games/numblocks/src/end.c b/games/numblocks/src/end.cindex 0f30eb97..49431548 100644--- a/games/numblocks/src/end.c+++ b/games/numblocks/src/end.c@@ -95,6 +95,28 @@ static bool through(float x0, float y0, float z0, float x1, float y1, float z1)return hard;}+/* the blocks it can't break in its body (5 wide) or head (3 wide), both 3 high, there (part: their places+ * from the dragon's): obsidian, end stone, bedrock; without mob griefing, anything solid */+static bool hard_in(float x0, float y0, float z0, float x1, float y1, float z1) {+ if (!rule(GR_MOB_GRIEFING)) {+ float a[6] = {x0, y0, z0, x1, y1, z1};+ return !phys_free(a);+ }+ for (int y = ifl(y0); y <= ifl(y1); y++)+ for (int z = ifl(z0); z <= ifl(z1); z++)+ for (int x = ifl(x0); x <= ifl(x1); x++) {+ if (!world_loaded(x, y, z)) continue;+ int b = world_get(x, y, z);+ if (b == B_OBSIDIAN || b == B_END_STONE || b == B_BEDROCK) return true;+ }+ return false;+}+static bool stopped(float x, float y, float z, const float (*part)[3]) {+ float bx = x + part[0][0], bz = z + part[0][2], hx = x + part[1][0], hy = y + part[1][1], hz = z + part[1][2];+ return hard_in(bx - 2.5f, y, bz - 2.5f, bx + 2.5f, y + 3, bz + 2.5f) ||+ hard_in(hx - 1.5f, hy, hz - 1.5f, hx + 1.5f, hy + 3, hz + 1.5f);+}+/* EntityDragon.generatePortal: the exit portal (bedrock round it and under it), the pillar with its* four torches and the egg */static void exit_portal(int px, int py, int pz) {@@ -209,13 +231,6 @@ void dragon_tick(Entity *e) {/* moveFlying(0, -1): head first */yr = dg.yaw * 0.017453292f;e->vx += fr * sinf(yr), e->vz -= fr * cosf(yr);- float k = dg.slowed ? 0.8f : 1;- e->x += e->vx * k, e->y += e->vy * k, e->z += e->vz * k; /* (noClip) */- float mx = e->vx, my = e->vy, mz = e->vz, ml = sqrtf(mx * mx + my * my + mz * mz);- if (ml > 0) mx /= ml, my /= ml, mz /= ml;- float f9 = 0.8f + 0.15f * (((mx * lx + my * ly + mz * lz) + 1) / 2);- e->vx *= f9, e->vz *= f9, e->vy *= 0.91f;- e->yaw = dg.yaw + 180;/* its parts: the body, the wings out at 4.5, the head 5.5 ahead (as the neck lifts it) */float o5y, o10y, o0y, oy;dragon_offsets(5, 1, &oy, &o5y);@@ -223,9 +238,27 @@ void dragon_tick(Entity *e) {dragon_offsets(0, 1, &oy, &o0y);float f1 = (o5y - o10y) * 10 / 180 * 3.1415927f, f2 = cosf(f1), f15 = -sinf(f1);float f16 = sinf(yr), f4 = cosf(yr);- float bx = e->x + f16 * 0.5f, bz = e->z - f4 * 0.5f;float f17 = sinf(yr - dg.yaw_v * 0.01f), f18 = cosf(yr - dg.yaw_v * 0.01f);- float hx = e->x + f17 * 5.5f * f2, hy = e->y + (o0y - o5y) + f15 * 5.5f, hz = e->z - f18 * 5.5f * f2;+ const float part[2][3] = {{f16 * 0.5f, 0, -f4 * 0.5f}, {f17 * 5.5f * f2, (o0y - o5y) + f15 * 5.5f, -f18 * 5.5f * f2}};+ /* the move: 1.8.8's dragon goes through everything (noClip); here what it can't break stops it, so it+ * doesn't come at the player through the island: it slides along it and climbs (free once inside) */+ float k = dg.slowed ? 0.8f : 1, dx = e->vx * k, dy = e->vy * k, dz = e->vz * k;+ if (stopped(e->x, e->y, e->z, part)) e->x += dx, e->y += dy, e->z += dz, e->vy += 0.05f;+ else {+ if (stopped(e->x, e->y + dy, e->z, part)) e->vy = dy > 0 ? 0 : 0.1f, dy = 0;+ e->y += dy;+ if (stopped(e->x + dx, e->y, e->z, part)) e->vx = 0, e->vy += 0.1f, dx = 0;+ e->x += dx;+ if (stopped(e->x, e->y, e->z + dz, part)) e->vz = 0, e->vy += 0.1f, dz = 0;+ e->z += dz;+ }+ float mx = e->vx, my = e->vy, mz = e->vz, ml = sqrtf(mx * mx + my * my + mz * mz);+ if (ml > 0) mx /= ml, my /= ml, mz /= ml;+ float f9 = 0.8f + 0.15f * (((mx * lx + my * ly + mz * lz) + 1) / 2);+ e->vx *= f9, e->vz *= f9, e->vy *= 0.91f;+ e->yaw = dg.yaw + 180;+ float bx = e->x + part[0][0], bz = e->z + part[0][2];+ float hx = e->x + part[1][0], hy = e->y + part[1][1], hz = e->z + part[1][2];if (e->hurt == 0 && !pl.dead && dim == DIM_END) {/* the wings knock the player away; the head bites (10) */for (int w = -1; w <= 1; w += 2) {@@ -327,6 +360,18 @@ float dragon_bar(void) {if (dx * dx + dz * dz > 160 * 160) return -1;return e->health / 200.0f;}+/* what the HUD points to in the End while the dragon lives: the dragon (kind 0) and the tops of the pillars+ * whose crystals are whole (kind 1) */+int end_marks(float (*at)[3], uint8_t *kind, int max) {+ Entity *e = dragon();+ if (!e || dim != DIM_END || dg.death || dst.dragon_dead) return 0;+ int n = 0, ns;+ at[n][0] = e->x, at[n][1] = e->y + 2, at[n][2] = e->z, kind[n++] = 0;+ const EndSpike *s = gen_spikes(&ns);+ for (int i = 0; i < ns && n < max; i++)+ if (crystal_alive(i)) at[n][0] = s[i].x + 0.5f, at[n][1] = s[i].y + s[i].h + 1.0f, at[n][2] = s[i].z + 0.5f, kind[n++] = 1;+ return n;+}/* the beam to the dragon from the crystal healing it: the crystal's place, false if none */bool dragon_beam(float *from, float *to) {Entity *e = dragon();diff --git a/games/numblocks/src/gui.c b/games/numblocks/src/gui.cindex 778e6a62..6b741857 100644--- a/games/numblocks/src/gui.c+++ b/games/numblocks/src/gui.c@@ -484,6 +484,49 @@ static void hud_portal(void) {}}}+/* a triangle, its tip at (x, y), pointing (ux, uy): len long, 2 w wide, outlined in black */+static void mark(float x, float y, float ux, float uy, float len, float w, uint16_t k) {+ for (int pass = 0; pass < 2; pass++) {+ float g = pass ? 0 : 1.5f, bx = x - ux * len, by = y - uy * len;+ float p[3][2] = {{x + ux * g, y + uy * g}, {bx - uy * (w + g) - ux * g, by + ux * (w + g) - uy * g},+ {bx + uy * (w + g) - ux * g, by - ux * (w + g) - uy * g}};+ int y0 = (int)floorf(fminf(p[0][1], fminf(p[1][1], p[2][1]))), y1 = (int)ceilf(fmaxf(p[0][1], fmaxf(p[1][1], p[2][1])));+ int x0 = (int)floorf(fminf(p[0][0], fminf(p[1][0], p[2][0]))), x1 = (int)ceilf(fmaxf(p[0][0], fmaxf(p[1][0], p[2][0])));+ if (y0 < clip_y0) y0 = clip_y0;+ if (y1 >= clip_y1) y1 = clip_y1 - 1;+ if (x0 < 0) x0 = 0;+ if (x1 >= SCREEN_W) x1 = SCREEN_W - 1;+ for (int py = y0; py <= y1; py++) {+ uint16_t *d = row_at(py);+ for (int px = x0; px <= x1; px++) {+ float cx = px + 0.5f, cy = py + 0.5f;+ bool in = true;+ for (int e = 0; e < 3 && in; e++) {+ const float *a = p[e], *b = p[(e + 1) % 3];+ in = (b[0] - a[0]) * (cy - a[1]) - (b[1] - a[1]) * (cx - a[0]) >= 0;+ }+ if (!in) { /* (either winding) */+ in = true;+ for (int e = 0; e < 3 && in; e++) {+ const float *a = p[e], *b = p[(e + 1) % 3];+ in = (b[0] - a[0]) * (cy - a[1]) - (b[1] - a[1]) * (cx - a[0]) <= 0;+ }+ }+ if (in) d[px] = pass ? k : 0;+ }+ }+ }+}+/* the End: triangles to the Ender Dragon (big, purple) and to the pillars whose crystals are whole (pink), when+ * they are out of sight (the drawing reaches 19 blocks, the dragon 31) */+static void hud_marks(void) {+ float at[12][3], x, y, ux, uy;+ uint8_t kind[12];+ int n = end_marks(at, kind, 12);+ for (int i = n - 1; i >= 0; i--)+ if (view_mark(at[i][0], at[i][1], at[i][2], kind[i] ? 19 : 31, &x, &y, &ux, &uy))+ mark(x, y, ux, uy, kind[i] ? 8 : 13, kind[i] ? 4 : 7, kind[i] ? 0xFC1F : 0x901F);+}/* GuiIngame.renderBossHealth: the dragon's bar and name at the top */static void hud_boss(void) {float hp = dragon_bar();@@ -515,6 +558,7 @@ static void hud(void) {}}#if NB_DIMS+ if (gui == GUI_NONE || gui == GUI_CHAT) hud_marks();hud_boss();#endifif (clip_y1 <= SCREEN_H - 60) return;diff --git a/games/numblocks/src/render.c b/games/numblocks/src/render.cindex da61317d..a29bc112 100644--- a/games/numblocks/src/render.c+++ b/games/numblocks/src/render.c@@ -1189,6 +1189,35 @@ static bool project(float x, float y, float z, float *sx, float *sy) {return true;}+#if NB_DIMS+/* a mark for a place out of sight (world coordinates; far: as far as it is drawn): at the screen's edge the+ * way to turn to it, or over it when it is on the screen past what is drawn; its tip (screen pixels) and the+ * way it points (a unit vector, y down). False: in sight */+bool view_mark(float x, float y, float z, float far, float *sx, float *sy, float *ux, float *uy) {+ float rx = x - vc_x0 - ox, ry = y - vc_y0 - oy, rz = z - vc_z0 - oz;+ float cz = rx * fwx + ry * fwy + rz * fwz, cx = rx * rgx + rz * rgz, cy = rx * upx + ry * upy + rz * upz;+ float dx = cx, dy = -cy;+ if (cz > 0.05f) {+ float px = cx / cz / TAN_H, py = cy / cz / TAN_V;+ if (px > -1 && px < 1 && py > -1 && py < 1) {+ if (rx * rx + ry * ry + rz * rz <= far * far) return false;+ *sx = (px + 1) * SCREEN_W / 2, *sy = (1 - py) * SCREEN_H / 2 - 4, *ux = 0, *uy = 1;+ return true;+ }+ dx = px, dy = -py;+ }+ float l = sqrtf(dx * dx + dy * dy);+ if (l < 1e-6f) dx = 0, dy = 1, l = 1;+ dx /= l, dy /= l;+ /* (between the boss bar and the hotbar) */+ const float x0 = 10, x1 = SCREEN_W - 10, y0 = 28, y1 = SCREEN_H - 50, mx = (x0 + x1) / 2, my = (y0 + y1) / 2;+ float tx = fabsf(dx) > 1e-6f ? (x1 - mx) / fabsf(dx) : 1e9f, ty = fabsf(dy) > 1e-6f ? (y1 - my) / fabsf(dy) : 1e9f;+ float t = tx < ty ? tx : ty;+ *sx = mx + dx * t, *sy = my + dy * t, *ux = dx, *uy = dy;+ return true;+}+#endif+/* the rectangle a box (its 8 corners, cache coordinates) covers on the picture: what of it is in front of* the camera, its edges cut where they pass behind (false: none of it is) */static bool rect_of(const float (*p)[3], int *r) {diff --git a/games/numblocks/tests/dims.c b/games/numblocks/tests/dims.cindex 52c43876..a1a2b49b 100644--- a/games/numblocks/tests/dims.c+++ b/games/numblocks/tests/dims.c@@ -285,6 +285,33 @@ int main(void) {SAY("%d of %d broken", broken, nsk);CHECK(broken == nsk);+ printf("the dragon at a player on the island\n");+ /* (it comes at the player, but no more through the end stone: its body never in it) */+ {+ int gy = 90;+ while (gy > 10 && gen_end_block(0, gy - 1, 20) != B_END_STONE) gy--;+ fly_to(0.5f, (float)gy, 20.5f);+ pl.flying = false;+ Entity *d = find_ent(E_DRAGON);+ int inside = 0;+ float nearest = 1e9f;+ for (int t = 0; t < 2000 && d; t++) {+ pl.x = 0.5f, pl.z = 20.5f, pl.y = (float)gy, pl.vx = pl.vy = pl.vz = 0, pl.health = 20;+ frames(1);+ d = find_ent(E_DRAGON);+ if (!d) break;+ nearest = fminf(nearest, hypotf(d->x - pl.x, d->z - pl.z) + fabsf(d->y - pl.y));+ bool in = false;+ for (int y = (int)floorf(d->y + 0.2f); y <= (int)floorf(d->y + 2.8f) && !in; y++)+ for (int z = (int)floorf(d->z - 1.5f); z <= (int)floorf(d->z + 1.5f) && !in; z++)+ for (int x = (int)floorf(d->x - 1.5f); x <= (int)floorf(d->x + 1.5f) && !in; x++)+ in = world_get(x, y, z) == B_END_STONE;+ inside += in;+ }+ SAY("standing at y %d: it came within %.1f, %d ticks in the end stone", gy, nearest, inside);+ CHECK(nearest < 16 && inside == 0);+ }+printf("the dragon\n");fly_to(0.5f, 80, 20.5f);Entity *dr = find_ent(E_DRAGON);