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.nwa: dungeon spawners make their skeletons, zombies and spiders
Mason363db3c08a96614
diff --git a/games/numblocks/src/dims.h b/games/numblocks/src/dims.hindex e13b6e4b..8bc9a25c 100644--- a/games/numblocks/src/dims.h+++ b/games/numblocks/src/dims.h@@ -61,7 +61,8 @@ extern uint8_t *gen_hi; /* (gen.c) the ninth bits ofvoid pearl_land(float x, float y, float z);void dims_explode(float x, float y, float z, float power, bool fire); /* (mob.c) */void dims_spawners_tick(void); /* (mob.c) the fortresses' blaze spawners */-int gen_fortress_spawners(int x, int z, int *out, int n); /* (gen.c) theirs near there: x, y, z */ /* (mob.c) the player's ender pearl lands there */+int gen_fortress_spawners(int x, int z, int *out, int n); /* (gen.c) theirs near there: x, y, z */+int gen_dungeon_spawners(int x, int z, int *out, int n); /* (gen.c) the dungeons' near there: x, y, z, mob */ /* (mob.c) the player's ender pearl lands there */enum { SKIN_CRYSTAL = 16, SKIN_DRAGON = 17 }; /* (the big skins: data.h's skin_crystal_px, skin_dragon_px) */void dims_credits(void);void credits_open(void); /* (gui.c) GuiWinGame */diff --git a/games/numblocks/src/gen.c b/games/numblocks/src/gen.cindex 7ff461c1..b4cda9d6 100644--- a/games/numblocks/src/gen.c+++ b/games/numblocks/src/gen.c@@ -113,6 +113,26 @@ static int stronghold_prepare(int cx, int cz);static void structs_slab(int cx, int cz, void *smem);static int structs_populate(void);static void struct_cache(void *mem);+/* the dungeons' spawners in the chunks made last (the game runs them): where, the mob (0 skeleton, 1 zombie,+ * 2 spider) */+static struct {+ int16_t x, z;+ uint8_t y, mob;+} gsp[4];+static uint8_t gsp_next;+static void gen_spawner_made(int x, int y, int z, int mob) {+ for (int i = 0; i < 4; i++)+ if (gsp[i].x == x && gsp[i].y == y && gsp[i].z == z && gsp[i].mob != 255) return;+ int i = gsp_next++ & 3;+ gsp[i].x = (int16_t)x, gsp[i].y = (uint8_t)y, gsp[i].z = (int16_t)z, gsp[i].mob = (uint8_t)mob;+}+int gen_dungeon_spawners(int x, int z, int *out, int n) {+ int k = 0;+ for (int i = 0; i < 4 && k < n; i++)+ if (gsp[i].mob != 255 && gsp[i].x - x <= 24 && x - gsp[i].x <= 24 && gsp[i].z - z <= 24 && z - gsp[i].z <= 24)+ out[k * 4] = gsp[i].x, out[k * 4 + 1] = gsp[i].y, out[k * 4 + 2] = gsp[i].z, out[k * 4 + 3] = gsp[i].mob, k++;+ return k;+}#endif/* The float arithmetic here must be done as written (IEEE single precision, each operation@@ -3758,7 +3778,12 @@ static void dungeon(int X, int Y, int Z) {}}put(X, Y, Z, B_MOB_SPAWNER, R_ALWAYS);+#if NB_DIMS+ int mob = RI(4); /* DungeonHooks: skeleton, zombie, zombie, spider */+ if (in_c_range(X, Y, Z)) gen_spawner_made(X, Y, Z, mob == 0 ? 0 : mob == 3 ? 2 : 1);+#elseRI(4); /* mob type */+#endifPV.qon = 0;}@@ -5472,6 +5497,7 @@ void gen_init(int64_t seed) {last_cx = bc_cx = 0x7fffffff;#if NB_DIMSstruct_cache(0); /* (another world: what its regions hold forgotten) */+ memset(gsp, 255, sizeof gsp);#endif}diff --git a/games/numblocks/src/mob.c b/games/numblocks/src/mob.cindex f15e26dc..1d891d39 100644--- a/games/numblocks/src/mob.c+++ b/games/numblocks/src/mob.c@@ -1137,32 +1137,41 @@ void pearl_land(float x, float y, float z) {#if NB_DIMSvoid dims_explode(float x, float y, float z, float power, bool fire) { explode_fire(x, y, z, power, true, fire); }-/* MobSpawnerBaseLogic, for the blaze spawners of the fortresses (the Nether's thrones): with the player within- * 16, after 200 to 800 ticks, four tries within 4 of it, while fewer than six blazes are about, where it is- * dark enough (EntityMob.getBlockPathWeight: block light up to 11) and there is room */+/* MobSpawnerBaseLogic, for the blaze spawners of the fortresses (the Nether's thrones) and the dungeons'+ * skeletons, zombies and spiders: with the player within 16, after 200 to 800 ticks, four tries within 4 of+ * it, while fewer than six of its mob are about, where it is dark enough (blazes: block light up to 11,+ * EntityMob.getBlockPathWeight; the others: EntityMob.isValidLightLevel) and there is room */static struct {int16_t x, z;- uint8_t y, on;+ uint8_t y, type; /* (type: E_NONE, off) */int16_t delay;} spw[2];void dims_spawners_tick(void) {extern uint32_t ticks_run;- if (dim != DIM_NETHER) {- spw[0].on = spw[1].on = 0;+ if (dim == DIM_END) {+ spw[0].type = spw[1].type = E_NONE;return;}if (ticks_run % 20 == 0) {- int at[6], n = gen_fortress_spawners((int)floorf(pl.x), (int)floorf(pl.z), at, 2);+ static const uint8_t mobs[3] = {E_SKELETON, E_ZOMBIE, E_SPIDER};+ int at[8], n;+ if (dim == DIM_NETHER) {+ int f[6];+ n = gen_fortress_spawners((int)floorf(pl.x), (int)floorf(pl.z), f, 2);+ for (int i = 0; i < n; i++) at[i * 4] = f[i * 3], at[i * 4 + 1] = f[i * 3 + 1], at[i * 4 + 2] = f[i * 3 + 2], at[i * 4 + 3] = -1;+ } else+ n = gen_dungeon_spawners((int)floorf(pl.x), (int)floorf(pl.z), at, 2);for (int i = 0; i < 2; i++) {- bool same = spw[i].on && i < n && spw[i].x == at[i * 3] && spw[i].y == at[i * 3 + 1] && spw[i].z == at[i * 3 + 2];+ int t = i >= n ? E_NONE : at[i * 4 + 3] < 0 ? E_BLAZE : mobs[at[i * 4 + 3]];+ bool same = spw[i].type == t && i < n && spw[i].x == at[i * 4] && spw[i].y == at[i * 4 + 1] && spw[i].z == at[i * 4 + 2];if (same) continue;- spw[i].on = (uint8_t)(i < n);- if (i < n) spw[i].x = (int16_t)at[i * 3], spw[i].y = (uint8_t)at[i * 3 + 1], spw[i].z = (int16_t)at[i * 3 + 2], spw[i].delay = -1;+ spw[i].type = (uint8_t)t;+ if (i < n) spw[i].x = (int16_t)at[i * 4], spw[i].y = (uint8_t)at[i * 4 + 1], spw[i].z = (int16_t)at[i * 4 + 2], spw[i].delay = -1;}}for (int i = 0; i < 2; i++) {- int x = spw[i].x, y = spw[i].y, z = spw[i].z;- if (!spw[i].on || world_get(x, y, z) != B_MOB_SPAWNER) continue;+ int x = spw[i].x, y = spw[i].y, z = spw[i].z, t = spw[i].type;+ if (t == E_NONE || world_get(x, y, z) != B_MOB_SPAWNER) continue;float dx = x + 0.5f - pl.x, dy = y + 0.5f - pl.y, dz = z + 0.5f - pl.z;if (dx * dx + dy * dy + dz * dz > 16 * 16) continue;if (spw[i].delay < 0) spw[i].delay = (int16_t)(200 + rnd(600));@@ -1175,15 +1184,15 @@ void dims_spawners_tick(void) {int near = 0;for (int j = 0; j < N_ENT; j++) {const Entity *e = &ents[j];- if (e->type == E_BLAZE && e->x > x - 4 && e->x < x + 5 && e->y > y - 4 && e->y < y + 5 && e->z > z - 4 && e->z < z + 5) near++;+ if (e->type == t && e->x > x - 4 && e->x < x + 5 && e->y > y - 4 && e->y < y + 5 && e->z > z - 4 && e->z < z + 5) near++;}if (near >= 6) break;float bx = x + (rndf() - rndf()) * 4 + 0.5f, by = (float)(y + rnd(3) - 1), bz = z + (rndf() - rndf()) * 4 + 0.5f;int lx = (int)floorf(bx), ly = (int)floorf(by), lz = (int)floorf(bz);- if (!opt.difficulty || light_there(lx, ly, lz) > 11 || !room_for(bx, by, bz, info[E_BLAZE].w, info[E_BLAZE].h) ||- blk_model[world_get(lx, ly, lz)] == M_LIQUID)+ if (!opt.difficulty || light_there(lx, ly, lz) > (t == E_BLAZE ? 11 : rnd(8)) ||+ !room_for(bx, by, bz, info[t].w, info[t].h) || blk_model[world_get(lx, ly, lz)] == M_LIQUID)continue;- Entity *e = spawn(E_BLAZE, bx, by, bz);+ Entity *e = spawn(t, bx, by, bz);if (!e) break;for (int q = 0; q < 12; q++) particle_add(bx + rndf() - 0.5f, by + rndf() * 1.8f, bz + rndf() - 0.5f, 0, 0.02f, 0, 0xC618, 15);any = true;diff --git a/games/numblocks/tests/structs.c b/games/numblocks/tests/structs.cindex 07830743..f26b0df7 100644--- a/games/numblocks/tests/structs.c+++ b/games/numblocks/tests/structs.c@@ -5,8 +5,8 @@* worked out here again with a java.util.Random of this file's own, for a few seeds;* how villages are laid out: no two pieces in each other, all within reach of the well, kept only with* more than two pieces off the roads;- * how they are built: a village's well and a desert temple's trap where 1.8.8 puts them, and the same- * blocks whichever rows of a chunk are made;+ * how they are built: a village's well, its blacksmith's chest and a desert temple's trap where 1.8.8 puts+ * them, and the same blocks whichever rows of a chunk are made; a dungeon's spawner at work;* old worlds: a world saved before NumBlocks.nwa made villages keeps its look where it had been (no* village there), and gets them elsewhere; it remembers where that is. */#include <math.h>@@ -163,6 +163,36 @@ int main(void) {SAY("its nine chunks made in rows of 24: %d blocks of the village differ", differ);CHECK(differ == 0);+ printf("the blacksmith's chest\n");+ int smith = -1, sp[8];+ gen_village_find(-2, -1, out);+ for (int i = 0; gen_village_piece(i, sp); i++)+ if (sp[0] == 10) smith = i; /* (VT_HOUSE2) */+ CHECK(smith >= 0);+ if (smith >= 0) {+ gen_village_piece(smith, sp);+ /* its chest at (5, 1, 5) of the piece: turned its way, on the floor the ground sets */+ int f = sp[1], kx = f == 3 ? sp[5] - 5 : f == 1 ? sp[2] + 5 : sp[2] + 5, kz = f == 0 ? sp[7] - 5 : f == 2 ? sp[4] + 5 : sp[4] + 5;+ make(kx >> 4, kz >> 4, 0, 128, slab, hb);+ int ky = -1;+ for (int y = 40; y < 110; y++)+ if (block_at(slab, hb, kx, y, kz) == B_CHEST) ky = y;+ SAY("at %d %d %d: a chest %s", kx, ky, kz, ky >= 0 && gen_struct_chest(kx, ky, kz) == 1 ? "with its loot" : "missing");+ CHECK(ky >= 0 && gen_struct_chest(kx, ky, kz) == 1);+ }++ printf("a dungeon's spawner\n");+ gen_init(0);+ int dsp[8], nd = 0;+ for (int qz = -6; qz <= 6 && !nd; qz++)+ for (int qx = -6; qx <= 6 && !nd; qx++) {+ make(qx, qz, 0, 128, slab, hb);+ nd = gen_dungeon_spawners(qx * 16 + 8, qz * 16 + 8, dsp, 2);+ if (nd) CHECK(block_at(slab, hb, dsp[0], dsp[1], dsp[2]) == B_MOB_SPAWNER);+ }+ SAY("at %d %d %d, of %s", dsp[0], dsp[1], dsp[2], nd ? dsp[3] == 0 ? "skeletons" : dsp[3] == 1 ? "zombies" : "spiders" : "nothing");+ CHECK(nd > 0);+printf("a desert temple's trap\n");gen_init(12345);int t[2];@@ -190,6 +220,29 @@ int main(void) {SAY("a new world: the well's water %d deep", new_well);CHECK(new_well >= 10);CHECK(save_world());+ /* the dungeon's spawner at work, in the dark */+ if (nd) {+ pl.mode = 0, pl.flying = false;+ pl.x = dsp[0] + 2.5f, pl.y = (float)dsp[1], pl.z = dsp[2] + 0.5f;+ world_finish(pl.x, pl.y, pl.z);+ for (int x = dsp[0] - 3; x <= dsp[0] + 3; x++) /* (room around it: the dungeon may be crossed by a cave) */+ for (int z = dsp[2] - 3; z <= dsp[2] + 3; z++) {+ world_set(x, dsp[1] - 1, z, B_COBBLESTONE);+ for (int y = dsp[1]; y <= dsp[1] + 2; y++)+ if (x != dsp[0] || z != dsp[2] || y != dsp[1]) world_set(x, y, z, B_AIR);+ }+ static const int kind[3] = {E_SKELETON, E_ZOMBIE, E_SPIDER};+ int made = 0;+ for (int k = 0; k < 900 && !made; k++) {+ host_time += 50;+ game_frame();+ pl.health = 20;+ for (int i = 0; i < N_ENT; i++) made += ents[i].type == kind[dsp[3]];+ }+ SAY("it made %d mob(s) of its kind", made);+ CHECK(made > 0);+ pl.mode = 1, pl.flying = true, pl.y = 80;+ }/* the world as NumBlocks.nwa saved it before: its side record without the boxes ("NBD1") */uint32_t len;const uint8_t *d = plat_load("nb1rdim.nbx", &len);