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: bows, throwing, TNT, armour, options that work, controls
Mason Chenf4ffd922c2de
diff --git a/games/numblocks/src/gen.c b/games/numblocks/src/gen.cindex 963d14df..b0521527 100644--- a/games/numblocks/src/gen.c+++ b/games/numblocks/src/gen.c@@ -1481,12 +1481,16 @@ static float grass_noise_div(int x, int z, int d) {typedef struct {float grid[825]; /* main noise, then density */- float acc[825]; /* limit noise accumulator */- float surf[256]; /* surface depth noise, index z*16+x */- uint8_t cls[825]; /* clamped-lerp class per grid point */+ union {+ float acc[825]; /* limit noise accumulator (density pass) */+ struct { /* surface pass, after the density */+ float surf[256]; /* surface depth noise, index z*16+x */+ uint8_t mperm[6][256]; /* mesa noises (built when a mesa column shows up) */+ uint8_t col[256];+ };+ };+ uint8_t cls[825]; /* per grid point: sign decided by bounds / noise needed / limits needed */uint8_t perm[256];- uint8_t mperm[6][256]; /* mesa noises (built when a mesa column shows up) */- uint8_t col[256];uint8_t mesa_ready;} TerrainScratch;@@ -1541,6 +1545,12 @@ static void chunk_biomes(int cx, int cz) {static void octave_setup(const Octave *o, i64 off[3]) { perm_build(o->st, U.t.perm, off); }+/* the density's height offset at grid level j2 (ChunkProviderGenerate: d4) */+static inline float dens_offset(int j2, float d3, float d2) {+ float d4 = ((float)j2 - d3) * 12.0f * 128.0f / 256.0f / d2;+ return d4 < 0.0f ? d4 * 4.0f : d4;+}+/* noise grid for chunk (cx, cz) -> U.t.grid holds the 5x5x33 densities.* The density is lerp(min, max, main) / 512 - offset(y); each limit noise is a sum of 16* octaves of amplitude 2^o whose values are within [-2, 2] (gradient dots of fractions,@@ -1564,7 +1574,7 @@ static void chunk_density(int cx, int cz) {}perlin2_octave(T->perm, depth, xc, xf, zc, zf, (float)(1 << o));}- /* height offsets per column; T->acc temporarily holds d4 (and the top blending) */+ /* per grid column: height (d3) and scale (d2) from the blended biomes and the depth noise */float colD3[25], colD2[25];for (int j1 = 0, i1 = 0; j1 < 5; j1++)for (int k1 = 0; k1 < 5; k1++, i1++) {@@ -1603,40 +1613,36 @@ static void chunk_density(int cx, int cz) {colD3[i1] = 8.5f + d1 * 4.0f;colD2[i1] = f2;}- /* sign classes of the grid points from the bounds: 1 solid, 2 empty, 0 undecided */- uint8_t dec[825];+ /* T->cls per grid point: D_SOLID / D_EMPTY when the bounds decide the sign, D_NEED when+ * the noise is needed, then D_MIN / D_MAX for the limit noises the clamped lerp uses */+ enum { D_MIN = 1, D_MAX = 2, D_NEED = 4, D_SOLID = 16, D_EMPTY = 32 };+ uint8_t *cls = T->cls;for (int c = 0; c < 25; c++)for (int j2 = 0; j2 < 33; j2++) {- float d4 = ((float)j2 - colD3[c]) * 12.0f * 128.0f / 256.0f / colD2[c];- if (d4 < 0.0f) d4 *= 4.0f;+ float d4 = dens_offset(j2, colD3[c], colD2[c]);float lo = -256.5f - d4, hi = 256.5f - d4;if (j2 > 29) {float d9 = (float)(j2 - 29) / 3.0f;lo = lo * (1.0f - d9) + -10.0f * d9;hi = hi * (1.0f - d9) + -10.0f * d9;}- T->acc[c * 33 + j2] = d4;- dec[c * 33 + j2] = lo > 0.0f ? 1 : (hi <= 0.0f ? 2 : 0);+ cls[c * 33 + j2] = lo > 0.0f ? D_SOLID : (hi <= 0.0f ? D_EMPTY : 0);}/* a point needs noise if one of the cells around it has corners of different classes */- static const uint8_t NEED = 4;- uint8_t need[825];- memset(need, 0, sizeof need);for (int gx = 0; gx < 4; gx++)for (int gz = 0; gz < 4; gz++)for (int gy = 0; gy < 32; gy++) {int c0 = (gx * 5 + gz) * 33 + gy, c1 = (gx * 5 + gz + 1) * 33 + gy;int c2 = ((gx + 1) * 5 + gz) * 33 + gy, c3 = ((gx + 1) * 5 + gz + 1) * 33 + gy;- uint8_t k = dec[c0];- if (k && dec[c1] == k && dec[c2] == k && dec[c3] == k && dec[c0 + 1] == k && dec[c1 + 1] == k &&- dec[c2 + 1] == k && dec[c3 + 1] == k)+ int k = cls[c0] & (D_SOLID | D_EMPTY);+ if (k && (cls[c1] & (D_SOLID | D_EMPTY)) == k && (cls[c2] & (D_SOLID | D_EMPTY)) == k &&+ (cls[c3] & (D_SOLID | D_EMPTY)) == k && (cls[c0 + 1] & (D_SOLID | D_EMPTY)) == k &&+ (cls[c1 + 1] & (D_SOLID | D_EMPTY)) == k && (cls[c2 + 1] & (D_SOLID | D_EMPTY)) == k &&+ (cls[c3 + 1] & (D_SOLID | D_EMPTY)) == k)continue;- need[c0] = need[c1] = need[c2] = need[c3] = NEED;- need[c0 + 1] = need[c1 + 1] = need[c2 + 1] = need[c3 + 1] = NEED;+ cls[c0] |= D_NEED, cls[c1] |= D_NEED, cls[c2] |= D_NEED, cls[c3] |= D_NEED;+ cls[c0 + 1] |= D_NEED, cls[c1 + 1] |= D_NEED, cls[c2 + 1] |= D_NEED, cls[c3 + 1] |= D_NEED;}- float d4s[825];- memcpy(d4s, T->acc, sizeof d4s);- memcpy(T->cls, need, sizeof need);/* main noise (8 octaves) */memset(T->grid, 0, sizeof T->grid);for (int o = 0; o < 8; o++) {@@ -1646,14 +1652,14 @@ static void chunk_density(int cx, int cz) {coord_split(coord_q32(bz, SC_MAINXZ, o, n, off[2]), &zc[n], &zf[n]);}for (int n = 0; n < 33; n++) coord_split(coord_q32(0, SC_MAINY, o, n, off[1]), &yc[n], &yf[n]);- perlin3_octave(T->perm, T->grid, T->cls, NEED, 0, xc, xf, zc, zf, yc, yf, (float)(1 << o));+ perlin3_octave(T->perm, T->grid, cls, D_NEED, 0, xc, xf, zc, zf, yc, yf, (float)(1 << o));}- /* classes of the needed points: bit 0 min needed, bit 1 max needed (bit 2: needed) */+ /* which limits the clamped lerp needs: min only (d7 < 0), max only (d7 > 1) or both */for (int i = 0; i < 825; i++) {- if (!T->cls[i]) continue;+ if (!(cls[i] & D_NEED)) continue;float d7 = (T->grid[i] / 10.0f + 1.0f) / 2.0f;T->grid[i] = d7;- T->cls[i] = (uint8_t)(d7 < 0.0f ? 1 : (d7 > 1.0f ? 2 : 3));+ cls[i] |= d7 < 0.0f ? D_MIN : (d7 > 1.0f ? D_MAX : D_MIN | D_MAX);}memset(T->acc, 0, sizeof T->acc);for (int o = 0; o < 16; o++) {@@ -1663,11 +1669,12 @@ static void chunk_density(int cx, int cz) {coord_split(coord_q32(bz, SC_LIMIT, o, n, off[2]), &zc[n], &zf[n]);}for (int n = 0; n < 33; n++) coord_split(coord_q32(0, SC_LIMIT, o, n, off[1]), &yc[n], &yf[n]);- perlin3_octave(T->perm, T->acc, T->cls, 1, 0, xc, xf, zc, zf, yc, yf, (float)(1 << o));+ perlin3_octave(T->perm, T->acc, cls, D_MIN, 0, xc, xf, zc, zf, yc, yf, (float)(1 << o));}for (int i = 0; i < 825; i++) {- if (T->cls[i] == 3) T->acc[i] *= 1.0f - T->grid[i];- if (T->cls[i] == 2) T->grid[i] = 1.0f;+ int k = cls[i] & (D_MIN | D_MAX);+ if (k == (D_MIN | D_MAX)) T->acc[i] *= 1.0f - T->grid[i];+ if (k == D_MAX) T->grid[i] = 1.0f;}for (int o = 0; o < 16; o++) {octave_setup(&oc_max[o], off);@@ -1676,16 +1683,16 @@ static void chunk_density(int cx, int cz) {coord_split(coord_q32(bz, SC_LIMIT, o, n, off[2]), &zc[n], &zf[n]);}for (int n = 0; n < 33; n++) coord_split(coord_q32(0, SC_LIMIT, o, n, off[1]), &yc[n], &yf[n]);- perlin3_octave(T->perm, T->acc, T->cls, 2, T->grid, xc, xf, zc, zf, yc, yf, (float)(1 << o));+ perlin3_octave(T->perm, T->acc, cls, D_MAX, T->grid, xc, xf, zc, zf, yc, yf, (float)(1 << o));}- /* density */+ /* density (decided points get +-1: only their sign matters) */for (int i = 0; i < 825; i++) {int j2 = i % 33;- if (!need[i]) {- T->grid[i] = dec[i] == 1 ? 1.0f : -1.0f;+ if (!(cls[i] & D_NEED)) {+ T->grid[i] = cls[i] & D_SOLID ? 1.0f : -1.0f;continue;}- float d8 = T->acc[i] / 512.0f - d4s[i];+ float d8 = T->acc[i] / 512.0f - dens_offset(j2, colD3[i / 33], colD2[i / 33]);if (j2 > 29) {float d9 = (float)(j2 - 29) / 3.0f;d8 = d8 * (1.0f - d9) + -10.0f * d9;diff --git a/games/numblocks/src/gui.c b/games/numblocks/src/gui.cindex 91002a3d..513436ff 100644--- a/games/numblocks/src/gui.c+++ b/games/numblocks/src/gui.c@@ -236,7 +236,7 @@ static void hand(void) {}int sh = view_light();int id = held()->id;- if (pl.using_ticks > 0) {+ if (pl.using_ticks > 0 && item_kind(id) != IK_BOW) {/* eating: the food comes to the mouth and bobs */float k = pl.using_ticks > 6 ? 1 : pl.using_ticks / 6.0f;dx -= 70 * k;@@ -766,7 +766,8 @@ typedef struct { int16_t x, y, w; uint8_t on, id; char label[32]; } Button;static Button buttons[12];static int nbuttons, bcur;enum { B_NO, B_SINGLE, B_OPTIONS, B_QUITAPP, B_PLAY, B_CREATE, B_DELETE, B_CANCEL, B_MODE, B_SEED, B_DOCREATE,- B_DODELETE, B_DIFF, B_GFX, B_LOOK, B_CLOUDS, B_BOB, B_DONE, B_BACK_GAME, B_SAVEQUIT, B_RESPAWN, B_TITLE };+ B_DODELETE, B_DIFF, B_GFX, B_LOOK, B_CLOUDS, B_BOB, B_DONE, B_BACK_GAME, B_SAVEQUIT, B_RESPAWN, B_TITLE,+ B_CONTROLS, B_CONTROLS_DONE };int menu_choice; /* an action for main.c (ACT_*) */int create_mode; /* the new world's game mode */char seed_text[21]; /* the new world's seed, as typed */@@ -837,8 +838,12 @@ static void menu(int screen) {add_button(w / 2 + 5, h / 6 + 12, 150, 1, B_CLOUDS, t);cat(t, "View Bobbing: ", opt.bobbing ? "ON" : "OFF");add_button(w / 2 - 155, h / 6 + 36, 150, 1, B_BOB, t);+ add_button(w / 2 + 5, h / 6 + 36, 150, 1, B_CONTROLS, "Controls...");add_button(w / 2 - 100, h / 6 + 168, 200, 1, B_DONE, "Done");break;+ case GUI_CONTROLS:+ add_button(w / 2 - 100, h - 26, 200, 1, B_CONTROLS_DONE, "Done");+ break;}case GUI_PAUSE:add_button(w / 2 - 100, h / 4 + 24 - 16, 200, 1, B_BACK_GAME, "Back to Game");@@ -905,6 +910,8 @@ static void press(int id) {save_options();gui_menu(options_from);break;+ case B_CONTROLS: gui_menu(GUI_CONTROLS); break;+ case B_CONTROLS_DONE: gui_menu(GUI_OPTIONS); break;case B_BACK_GAME: gui = GUI_NONE; break;case B_SAVEQUIT: menu_choice = ACT_SAVE_QUIT; break;case B_RESPAWN: menu_choice = ACT_RESPAWN; break;@@ -938,6 +945,7 @@ static void menu_input(uint32_t keys, uint32_t pressed) {/* Back: the way out of each screen */if (gui == GUI_PAUSE) gui = GUI_NONE;else if (gui == GUI_OPTIONS) press(B_DONE);+ else if (gui == GUI_CONTROLS) press(B_CONTROLS_DONE);else if (gui == GUI_WORLDS || gui == GUI_CREATE || gui == GUI_CONFIRM) press(B_CANCEL);}}@@ -1055,6 +1063,23 @@ static void menu_screen(void) {text_center("'New World' will be lost forever! (A long time!)", w / 2, 90, 0xFFFF);break;case GUI_OPTIONS: text_center("Options", w / 2, 15, 0xFFFF); break;+ case GUI_CONTROLS: {+ /* GuiControls: each action and its key (the calculator's) */+ static const char *const rows[][2] = {+ {"Look Around", "Arrows"}, {"Walk Forwards", "ln"}, {"Walk Backwards", "cos"}, {"Strafe Left", "sin"},+ {"Strafe Right", "tan"}, {"Jump (twice: fly)", "pi"}, {"Sneak", "sqrt"}, {"Sprint", "x^2"},+ {"Attack/Destroy", "Back"}, {"Use Item/Place Block", "OK or EXE"}, {"Inventory", "var"},+ {"Drop Item", "x,n,t"}, {"Hotbar Slots", "1 to 9"}, {"Pause", "Toolbox"}, {"Save and Quit", "Home"}};+ text_center("Controls", w / 2, 6, 0xFFFF);+ for (int i = 0; i < 15; i++) {+ int y = 20 + i * 12;+ text(rows[i][0], w / 2 - 140, y + 2, 0xFFFF, true);+ fill(w / 2 + 20, y, 100, 11, RGB(0x60, 0x60, 0x60));+ fill(w / 2 + 21, y + 1, 98, 9, RGB(0x20, 0x20, 0x20));+ text_center(rows[i][1], w / 2 + 70, y + 2, RGB(0xFF, 0xFF, 0xA0));+ }+ break;+ }case GUI_PAUSE: text_center("Game menu", w / 2, 40, 0xFFFF); break;case GUI_LOADING:text_center("Loading world", w / 2, h / 2 - 50, 0xFFFF);@@ -1246,7 +1271,7 @@ void hud_strip(uint16_t *buf, int y0, int rows) {dark_background();menu_screen();break;- case GUI_OPTIONS:+ case GUI_OPTIONS: case GUI_CONTROLS:if (options_from == GUI_PAUSE) dark_background();else dirt_background();menu_screen();diff --git a/games/numblocks/src/main.c b/games/numblocks/src/main.cindex e492b052..4a007626 100644--- a/games/numblocks/src/main.c+++ b/games/numblocks/src/main.c@@ -136,7 +136,7 @@ bool game_frame(void) {if (pl.pitch < -90) pl.pitch = -90;pl.sprinting = (k & K_SPRINT) && (k & K_FWD) && !pl.sneaking;}- bool paused = gui == GUI_PAUSE || (gui == GUI_OPTIONS);+ bool paused = gui == GUI_PAUSE || gui == GUI_OPTIONS || gui == GUI_CONTROLS;if (!paused) acc += dt;uint32_t game_keys = in_game ? k : 0, game_pressed = in_game ? pressed : 0;while (acc >= 50) {@@ -164,7 +164,17 @@ bool game_frame(void) {tick_frac = t;Camera c = {px + (pl.x - px) * t, py + (pl.y - py) * t + (pl.sneaking ? 1.54f : 1.62f), pz + (pl.z - pz) * t, pl.yaw,pl.pitch};+ if (opt.bobbing && !pl.flying) {+ /* EntityRenderer.setupViewBobbing: the eyes sway side to side and dip with each step */+ float w = (pl.prev_walked + (pl.walked - pl.prev_walked) * t) * 3.14159265f;+ float b = pl.prev_bob + (pl.bob - pl.prev_bob) * t;+ float side = sinf(w) * b * 0.5f, dip = -fabsf(cosf(w) * b);+ float yr = pl.yaw * 0.017453292f;+ c.x += -cosf(yr) * side, c.z += -sinf(yr) * side, c.y += dip;+ c.pitch += fabsf(cosf(w - 0.2f) * b) * 5;+ }if (pl.dead) c.y = pl.y + 0.3f;+ if (pl.sleep_timer) c.y = pl.y + 0.3f;render_frame(&c, game_time);perf_frames++;return true;diff --git a/games/numblocks/src/mob.c b/games/numblocks/src/mob.cindex 25d256d0..628790c7 100644--- a/games/numblocks/src/mob.c+++ b/games/numblocks/src/mob.c@@ -396,7 +396,7 @@ static void push_player(float kx, float kz, float s) {}/* ---------------------------------------------------------------- explosions (Explosion, power 3) */-static void explode(float x, float y, float z, float power) {+void explode(float x, float y, float z, float power) {int r = (int)ceilf(power);for (int dy = -r; dy <= r; dy++)for (int dz = -r; dz <= r; dz++)@@ -411,6 +411,12 @@ static void explode(float x, float y, float z, float power) {if (f - resist * 0.3f <= 0) continue;if (b == B_CHEST || b == B_FURNACE || b == B_FURNACE_LIT) tiles_removed(bx, by, bz);world_set(bx, by, bz, B_AIR);+ if (b == B_TNT) {+ /* TNT caught in a blast is lit, with a shorter fuse */+ Entity *t = ent_new(E_TNT, bx + 0.5f, (float)by, bz + 0.5f);+ if (t) t->delay = (int16_t)(10 + rnd(20)), t->item.id = B_TNT;+ continue;+ }/* one in power of the blocks drop */if (rnd((int)power) == 0) {Stack out[2];@@ -453,23 +459,61 @@ static void shoot(const Entity *from) {a->yaw = atan2f(-a->vx, a->vz) * 57.29578f;}+/* the player throws or shoots: from the eyes, the way they look (EntityThrowable, EntityArrow) */+void throw_item(int id, float speed, bool from_player) {+ float yaw = pl.yaw * 0.017453292f, pitch = pl.pitch * 0.017453292f;+ Entity *a = ent_new(E_ARROW, pl.x - cosf(yaw) * 0.16f, pl.y + 1.52f, pl.z - sinf(yaw) * 0.16f);+ if (!a) return;+ a->item.id = (uint16_t)id;+ a->item.aux = from_player; /* the player's arrows can be picked up again */+ float dx = -sinf(yaw) * cosf(pitch), dy = -sinf(pitch), dz = cosf(yaw) * cosf(pitch);+ a->vx = (dx + (rndf() - 0.5f) * 0.015f) * speed + pl.vx;+ a->vy = (dy + (rndf() - 0.5f) * 0.015f) * speed + (pl.on_ground ? 0 : pl.vy);+ a->vz = (dz + (rndf() - 0.5f) * 0.015f) * speed + pl.vz;+ a->yaw = pl.yaw;+}+static void arrow_tick(Entity *e) {- if (e->state) { /* stuck in a block */- if (++e->timer > 600) e->type = E_NONE;+ bool arrow = e->item.id == I_ARROW;+ if (e->state) { /* stuck in a block: the player's can be picked up */+ float px = pl.x - e->x, py = pl.y + 0.9f - e->y, pz = pl.z - e->z;+ if (e->item.aux && px * px + py * py + pz * pz < 2.0f && !inv_add(pl.inv, 36, I_ARROW, 1, 0)) e->type = E_NONE;+ if (++e->timer > 1200) e->type = E_NONE;return;}float nx = e->x + e->vx, ny = e->y + e->vy, nz = e->z + e->vz;- /* the player in its way? */+ float sp = sqrtf(e->vx * e->vx + e->vy * e->vy + e->vz * e->vz);+ /* the player in the way of a mob's arrow */float px = pl.x - nx, pz = pl.z - nz;- if (!pl.dead && px * px + pz * pz < 0.5f && ny > pl.y && ny < pl.y + 1.8f) {- float sp = sqrtf(e->vx * e->vx + e->vy * e->vy + e->vz * e->vz);+ if (!e->item.aux && !pl.dead && px * px + pz * pz < 0.5f && ny > pl.y && ny < pl.y + 1.8f) {player_hurt(scaled(ceilf(sp * 2.2f)), DMG_ARROW);push_player(e->vx, e->vz, 0.4f);e->type = E_NONE;return;}+ /* a mob in the way of the player's */+ if (e->item.aux)+ for (int i = 0; i < N_ENT; i++) {+ Entity *m = &ents[i];+ if (m->type < E_ZOMBIE || m->type > E_CHICKEN || m->state == 255) continue;+ float w = info[m->type].w / 2 + 0.15f, mx = m->x - nx, mz = m->z - nz;+ if (fabsf(mx) < w && fabsf(mz) < w && ny > m->y - 0.1f && ny < m->y + info[m->type].h) {+ /* EntityArrow: damage 2 x speed, rounded up (a full draw sometimes more) */+ float dmg = arrow ? ceilf(sp * 2) + (sp > 2.9f ? rnd((int)(sp * 2) / 2 + 2) : 0) : 0;+ hurt(m, dmg, e->vx, e->vz);+ if (!arrow && dmg == 0) m->vx += e->vx * 0.2f, m->vz += e->vz * 0.2f;+ e->type = E_NONE;+ return;+ }+ }int b = world_get(ifl(nx), ifl(ny), ifl(nz));if (blk_flags[b] & BF_SOLID) {+ if (!arrow) {+ /* EntityEgg: one in eight hatches a chick (a chicken here) */+ if (e->item.id == I_EGG && rnd(8) == 0) spawn(E_CHICKEN, e->x, e->y, e->z);+ e->type = E_NONE;+ return;+ }e->state = 1;e->vx = e->vy = e->vz = 0;return;@@ -478,8 +522,21 @@ static void arrow_tick(Entity *e) {bool water = blk_model[b] == M_LIQUID;float drag = water ? 0.8f : 0.99f;e->vx *= drag, e->vy *= drag, e->vz *= drag;- e->vy -= 0.05f;- if (++e->timer > 200) e->type = E_NONE;+ e->vy -= arrow ? 0.05f : 0.03f;+ if (++e->timer > 400) e->type = E_NONE;+}++/* lit TNT: falls, flashes, and blows with power 4 after 80 ticks (EntityTNTPrimed) */+static void tnt_tick(Entity *e) {+ float p[3] = {e->x, e->y, e->z}, v[3] = {e->vx, e->vy - 0.04f, e->vz};+ bool ground = phys_move(p, v, 0.98f, 0.98f);+ e->x = p[0], e->y = p[1], e->z = p[2];+ e->vx = v[0] * 0.98f, e->vy = v[1] * 0.98f, e->vz = v[2] * 0.98f;+ if (ground) e->vx *= 0.7f, e->vz *= 0.7f, e->vy *= -0.5f;+ if (--e->delay <= 0) {+ e->type = E_NONE;+ explode(e->x, e->y + 0.49f, e->z, 4);+ }}/* ---------------------------------------------------------------- a tick */@@ -494,6 +551,10 @@ void mob_tick(Entity *e) {arrow_tick(e);return;}+ if (e->type == E_TNT) {+ tnt_tick(e);+ return;+ }const MobInfo *mi = &info[e->type];if (e->hurt > 0) e->hurt--;if (e->invuln > 0) e->invuln--;diff --git a/games/numblocks/src/nb.h b/games/numblocks/src/nb.hindex 761f17ea..69ae322c 100644--- a/games/numblocks/src/nb.h+++ b/games/numblocks/src/nb.h@@ -128,6 +128,7 @@ typedef struct {int food, food_timer, air, invuln, hurt_time, fire, using_ticks;int xp_level, xp_total;int sleep_timer; /* ticks asleep in a bed (0: awake) */+ float walked, bob, prev_walked, prev_bob; /* view bobbing (EntityPlayer.cameraYaw) */float xp; /* 0..1 of the way to the next level */int spawn_x, spawn_y, spawn_z;uint8_t mode; /* 0 survival, 1 creative */@@ -145,7 +146,7 @@ void hand_tick(void);void gui_message(const char *s); /* a line at the bottom left, as Minecraft's chat shows *//* ---------------------------------------------------------------- entities (entity.c) */-enum { E_NONE, E_ITEM, E_ZOMBIE, E_SKELETON, E_CREEPER, E_SPIDER, E_PIG, E_COW, E_SHEEP, E_CHICKEN, E_ARROW };+enum { E_NONE, E_ITEM, E_ZOMBIE, E_SKELETON, E_CREEPER, E_SPIDER, E_PIG, E_COW, E_SHEEP, E_CHICKEN, E_ARROW, E_TNT };typedef struct {uint8_t type, on_ground, hurt, state; /* hurt: ticks of red; state 255: dying (timer counts) */int16_t age, health, timer, delay; /* delay: an item's pickup delay, a mob's attack wait, a creeper's fuse */@@ -164,6 +165,8 @@ void ent_drop(int id, int count, int dmg, float x, float y, float z, bool thrownvoid ents_tick(void);void mob_tick(Entity *e);void mobs_spawn(void);+void explode(float x, float y, float z, float power);+void throw_item(int id, float speed, bool from_player); /* arrows, snowballs, eggs */bool mob_attack(const Entity *e); /* the player hits this mob (with the held item) */bool mob_use(Entity *e); /* the player uses the held item on it (shears, bucket) */Entity *entity_looked_at(float reach, float block_t); /* the mob under the crosshair, nearer than block_t */@@ -179,7 +182,7 @@ void break_block_at(int x, int y, int z, bool drops);/* ---------------------------------------------------------------- screens (gui.c) */enum { GUI_NONE, GUI_INVENTORY, GUI_CRAFTING, GUI_FURNACE, GUI_CHEST, GUI_CREATIVE,- GUI_PAUSE, GUI_DEATH, GUI_OPTIONS, GUI_TITLE, GUI_WORLDS, GUI_CREATE, GUI_CONFIRM, GUI_LOADING };+ GUI_PAUSE, GUI_DEATH, GUI_OPTIONS, GUI_TITLE, GUI_WORLDS, GUI_CREATE, GUI_CONFIRM, GUI_LOADING, GUI_CONTROLS };extern int gui; /* the screen open */void gui_open(int screen, int x, int y, int z);void gui_close(void);diff --git a/games/numblocks/src/player.c b/games/numblocks/src/player.cindex 98c11209..7dc4f154 100644--- a/games/numblocks/src/player.c+++ b/games/numblocks/src/player.c@@ -551,6 +551,28 @@ static void use(uint32_t pressed) {case IK_MILK_BUCKET:if (pl.mode == 0) h->id = I_BUCKET, h->aux = 1;return;+ case IK_HELMET: case IK_CHESTPLATE: case IK_LEGGINGS: case IK_BOOTS: {+ /* ItemArmor.onItemRightClick: worn at once if that slot is free */+ int slot = IK_BOOTS - k;+ if (!pl.armor[slot].id) pl.armor[slot] = *h, h->id = 0, h->aux = 0;+ return;+ }+ case IK_SNOWBALL: case IK_EGG:+ throw_item(h->id, 1.5f, true);+ use_up();+ player_swing();+ return;+ case IK_FLINT_AND_STEEL:+ if (on_block && b == B_TNT) {+ /* BlockTNT: lit, it falls and blows after 4 seconds */+ world_set(x, y, z, B_AIR);+ neighbours_changed(x, y, z);+ Entity *e = ent_new(E_TNT, x + 0.5f, (float)y, z + 0.5f);+ if (e) e->delay = 80, e->vy = 0.2f, e->item.id = B_TNT;+ if (pl.mode == 0) stack_wear(h, 1);+ player_swing();+ }+ return;}}@@ -702,6 +724,10 @@ void player_tick(uint32_t keys, uint32_t pressed) {}/* walking, sprinting and swimming tire (EntityPlayer.addMovementStat) */float moved = sqrtf((pl.x - ox) * (pl.x - ox) + (pl.z - oz) * (pl.z - oz));+ pl.prev_walked = pl.walked, pl.prev_bob = pl.bob;+ pl.walked += moved * 0.6f;+ float want = pl.on_ground ? (moved > 0.1f ? 0.1f : moved) : 0;+ pl.bob += (want - pl.bob) * 0.4f;if (pl.mode == 0) exhaust(moved * (pl.in_water ? 0.015f : pl.sprinting ? 0.1f : 0.0f));hazards(y0);if (pl.mode == 0) food_tick();@@ -756,8 +782,38 @@ void player_tick(uint32_t keys, uint32_t pressed) {}}} else pl.breaking = 0;- /* eating: OK held for 32 ticks */+ /* a bow: OK held draws it, letting go shoots (ItemBow.onPlayerStoppedUsing) */int k = item_kind(held()->id);+ static int draw;+ if (k == IK_BOW) {+ bool arrows = pl.mode == 1;+ for (int i = 0; i < 36 && !arrows; i++) arrows = pl.inv[i].id == I_ARROW;+ if ((keys & K_USE) && arrows) draw++;+ else if (draw) {+ float f = draw / 20.0f;+ f = (f * f + f * 2) / 3;+ if (f > 1) f = 1;+ if (f >= 0.1f) {+ throw_item(I_ARROW, f * 3, true);+ if (pl.mode == 0) {+ stack_wear(held(), 1);+ for (int i = 0; i < 36; i++)+ if (pl.inv[i].id == I_ARROW) {+ stack_take(&pl.inv[i], 1);+ break;+ }+ }+ }+ draw = 0;+ }+ pl.using_ticks = draw; /* (slows the player, as drawing a bow does) */+ prev_keys = keys;+ for (int n = 0; n < 9; n++)+ if (pressed & (K_SLOT1 << n)) pl.slot = n, draw = 0;+ return;+ }+ draw = 0;+ /* eating: OK held for 32 ticks */bool edible = k == IK_FOOD || k == IK_STEW;if (edible && (keys & K_USE) && (pl.food < 20 || held()->id == I_GOLDEN_APPLE || pl.mode == 1) &&!(pl.hit_face >= 0 && it_place[held()->id - 256] != 255 &&diff --git a/games/numblocks/src/render.c b/games/numblocks/src/render.cindex 2d620bb6..07c42b58 100644--- a/games/numblocks/src/render.c+++ b/games/numblocks/src/render.c@@ -107,7 +107,7 @@ static uint16_t sky(float dx, float dy, float dz, float len) {else r += (int)(255 * s), g += (int)(250 * s), b += (int)(200 * s);}/* clouds: Minecraft's 12-block cells at y = 128.33 */- if (dy > 0.01f) {+ if (dy > 0.01f && opt.clouds) {float t = (128.33f - (oy + vc_y0)) / dy;float cx = (ox + vc_x0) + dx * t + cloud_off, cz = (oz + vc_z0) + dz * t;float dist = t * len;@@ -307,7 +307,7 @@ static uint16_t trace(float dx, float dy, float dz) {u &= 15;v &= 15;int tc = texel565(b, blk_front[b] ? face_tex(b, f, x, y, z) : blk_tex[b][f], u, v, col);- if (tc < 0 && m == M_LEAVES) tc = 0; /* Fast graphics: the holes are black */+ if (tc < 0 && m == M_LEAVES && !opt.fancy) tc = 0; /* Fast graphics: the holes are black */if (tc >= 0) {tc = cracked(tc, i, u, v);last_t = t;@@ -495,7 +495,7 @@ static int face_pixel(float dx, float dy, float dz, int plane, int f) {}if ((unsigned)u > 15 || (unsigned)v > 15) return -1;int tc = texel565(b, blk_front[b] ? face_tex(b, f, x, y, z) : blk_tex[b][f], u, v, z * VCX + x);- if (tc < 0 && m == M_LEAVES) tc = 0;+ if (tc < 0 && m == M_LEAVES && !opt.fancy) tc = 0;if (tc < 0) return -1;tc = cracked(tc, VC_I(x, y, z), u, v);last_t = t;@@ -661,6 +661,7 @@ static void ents_frame(void) {if (dist > MAX_T + 1) continue;float w, h;if (e->type == E_ITEM) w = 0.5f, h = 0.6f;+ else if (e->type == E_TNT) w = 1.2f, h = 1.1f;else if (e->type == E_ARROW) w = 0.6f, h = 0.6f, ey -= 0.3f;else w = mob_width(e->type) * 2.2f, h = mob_height(e->type) * 1.2f;if (e->type >= E_ZOMBIE && e->type <= E_CHICKEN && e->state == 255) w = h = 2.4f; /* dying: lying down */@@ -851,17 +852,18 @@ static bool item_hit(const Draw *dr, const float *d, float *best_t, uint16_t *coconst Entity *e = dr->e;int id = e->item.id;float age = e->age + tick_frac;- float bob = sinf(age / 10.0f + e->yaw) * 0.1f + 0.1f;+ bool tnt = e->type == E_TNT;+ float bob = tnt ? 0 : sinf(age / 10.0f + e->yaw) * 0.1f + 0.1f;bool cube = id < 256 && (blk_model[id] == M_CUBE || blk_model[id] == M_LEAVES || blk_model[id] == M_GLASS ||blk_model[id] == M_SLAB);- float cx = dr->ex, cy = dr->ey + bob + 0.125f, cz = dr->ez;+ float hs = tnt ? 0.49f : 0.125f;+ float cx = dr->ex, cy = dr->ey + bob + hs, cz = dr->ez;if (cube) {- /* EntityItem render: a quarter block, turning */- float a = age / 20.0f + e->yaw, ca = cosf(a), sa = sinf(a);+ /* EntityItem render: a quarter block, turning (lit TNT: a whole block, still) */+ float a = tnt ? 0 : age / 20.0f + e->yaw, ca = cosf(a), sa = sinf(a);float rel[3] = {ox - cx, oy - cy, oz - cz};float o[3] = {ca * rel[0] + sa * rel[2], rel[1], -sa * rel[0] + ca * rel[2]};float dl[3] = {ca * d[0] + sa * d[2], d[1], -sa * d[0] + ca * d[2]};- const float hs = 0.125f;float t0 = 0, t1 = *best_t;int f0 = -1;for (int k = 0; k < 3; k++) {@@ -896,6 +898,7 @@ static bool item_hit(const Draw *dr, const float *d, float *best_t, uint16_t *coif (tc < 0) tc = 0;*best_t = t0;*col = lit565((uint16_t)tc, f0, dr->light, t0 * sqrtf(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]));+ if (tnt && (e->delay / 5) % 2 == 0) *col = mix565(*col, 0xFFFF, 16); /* RenderTNTPrimed: flashing */return true;}/* a flat picture half a block wide, facing the camera */