Skip to content

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.

NumBlocks: mobs climb one-block steps; a mob in front takes the crosshair

Mason Chen11131f82d748
diff --git a/games/numblocks/src/mob.c b/games/numblocks/src/mob.c
index e07a9c52..5d9f1dfc 100644
--- a/games/numblocks/src/mob.c
+++ b/games/numblocks/src/mob.c
@@ -880,10 +880,7 @@ void mob_tick(Entity *e) {
e->x = p[0], e->y = p[1], e->z = p[2];
e->vx = v[0], e->vy = v[1], e->vz = v[2];
e->on_ground = ground;
- if (blocked && go) {
- if (e->type == E_SPIDER) e->vy = 0.2f; /* climbing */
- else if (ground) e->vy = 0.42f;
- }
+ if (blocked && go && e->type == E_SPIDER) e->vy = 0.2f; /* climbing */
if (in_water) e->vx *= 0.8f, e->vy *= 0.8f, e->vz *= 0.8f, e->vy -= 0.02f;
else {
e->vy -= 0.08f;
@@ -892,6 +889,9 @@ void mob_tick(Entity *e) {
e->vx *= fr, e->vz *= fr;
if (e->type == E_CHICKEN && !ground && e->vy < 0) e->vy *= 0.6f; /* flapping */
}
+ /* against a wall: a jump (EntityJumpHelper), set for the next move as Minecraft sets it before
+ * moving, so the first rise is the whole 0.42 and a block is climbed */
+ if (blocked && go && ground && e->type != E_SPIDER) e->vy = 0.42f;
/* the walk's swing (limbSwingAmount follows how fast it moves) */
float target = moved * 4;
if (target > 1) target = 1;
diff --git a/games/numblocks/src/player.c b/games/numblocks/src/player.c
index 6a4c113a..11425c47 100644
--- a/games/numblocks/src/player.c
+++ b/games/numblocks/src/player.c
@@ -378,7 +378,7 @@ static bool ray_block(int b, int x, int y, int z, float *t, int *face) {
}
/* the first block the eyes' ray meets within reach (4.5, 5 in creative) */
-static void pick(void) {
+static void pick_block(void) {
float ex = look_ray[0], ey = look_ray[1], ez = look_ray[2], dx = look_ray[3], dy = look_ray[4], dz = look_ray[5];
int x = ifloor(ex), y = ifloor(ey), z = ifloor(ez);
int sx = dx > 0 ? 1 : -1, sy = dy > 0 ? 1 : -1, sz = dz > 0 ? 1 : -1;
@@ -406,6 +406,13 @@ static void pick(void) {
}
}
+/* what the crosshair is on (EntityRenderer.getMouseOver): a mob in front of the block takes it, so the
+ * block has no outline; past 3 blocks, in survival, nothing is in reach */
+static void pick(void) {
+ pick_block();
+ if (entity_looked_at(pl.mode ? 5.0f : 4.5f, pl.hit_face >= 0 ? hit_t : 1e9f)) pl.hit_face = -1;
+}
+
void player_look(float ex, float ey, float ez, float yaw, float pitch) {
float yr = yaw * 0.017453292f, pr = pitch * 0.017453292f;
look_ray[0] = ex, look_ray[1] = ey, look_ray[2] = ez;
@@ -919,7 +926,7 @@ void player_tick(uint32_t keys, uint32_t pressed) {
if (pl.mode == 0) food_tick();
if (pl.dead) return;
pick();
- /* a mob under the crosshair, nearer than the block: Back hits it, OK uses on it */
+ /* a mob under the crosshair, nearer than the block: attacking hits it, using uses on it */
Entity *target = entity_looked_at(pl.mode ? 5.0f : 3.0f, pl.hit_face >= 0 ? hit_t : 1e9f);
if (target) {
if (pressed & K_ATTACK) mob_attack(target), player_swing();
@@ -927,7 +934,7 @@ void player_tick(uint32_t keys, uint32_t pressed) {
keys &= ~K_ATTACK;
pl.breaking = 0;
}
- /* mining (Back held) */
+ /* mining (attack held) */
if (break_cooldown) break_cooldown--;
if ((pressed & K_ATTACK) && pl.hit_face < 0 && !target) player_swing();
if ((pressed & K_ATTACK) && pl.hit_face >= 0 && !target) {
diff --git a/games/numblocks/tests/unit.c b/games/numblocks/tests/unit.c
index aba8ba2a..0a42e06f 100644
--- a/games/numblocks/tests/unit.c
+++ b/games/numblocks/tests/unit.c
@@ -151,6 +151,28 @@ int main(void) {
CHECK(calves == 1);
plat_remove_prefix("ut3");
}
+ /* a zombie after the player climbs a one-block step (the jump's first rise is the whole 0.42) */
+ {
+ extern uint32_t game_time;
+ world_new(0, "ut3z");
+ world_follow(8, 70, 8);
+ int y = 70;
+ for (int z = 0; z <= 16; z++)
+ for (int x = 0; x <= 16; x++) {
+ world_set(x, y - 1, z, B_STONE);
+ world_set(x, y, z, x >= 10 ? B_STONE : B_AIR);
+ for (int k = 1; k < 4; k++) world_set(x, y + k, z, B_AIR);
+ }
+ memset(ents, 0, sizeof ents);
+ opt.difficulty = 2, pl.mode = 0, pl.dead = false, pl.health = 20;
+ pl.x = 12.5f, pl.y = (float)y + 1, pl.z = 8.5f;
+ game_time = 18000; /* (midnight: no burning) */
+ Entity *zb = ent_new(E_ZOMBIE, 5.5f, (float)y, 8.5f);
+ zb->health = 20, zb->panic = 60;
+ for (int t = 0; t < 100; t++) ticks_run++, ents_tick(), game_time++;
+ CHECK(zb->type == E_ZOMBIE && zb->y >= y + 1 && zb->x > 10);
+ plat_remove_prefix("ut3z");
+ }
{
/* weather: the clock, the strength, the light, and where rain falls */
extern uint32_t game_time;
@@ -380,6 +402,17 @@ int main(void) {
CHECK(pl.hit_z == 12);
player_look(8.5f, 100.25f, 8.5f, 0, 0);
CHECK(pl.hit_face == 2 && pl.hit_z == 10);
+ /* a mob in front of the block takes the crosshair (no outline); past 3 blocks nothing is in reach */
+ world_set(8, 100, 10, B_AIR), world_set(8, 100, 12, B_AIR), world_set(8, 100, 13, B_STONE);
+ memset(ents, 0, sizeof ents);
+ player_look(8.5f, 100.75f, 8.6f, 0, 0);
+ CHECK(pl.hit_face == 2 && pl.hit_z == 13);
+ Entity *cow = ent_new(E_COW, 8.5f, 100, 10.5f);
+ player_look(8.5f, 100.75f, 8.6f, 0, 0);
+ CHECK(pl.hit_face < 0 && entity_looked_at(3, 1e9f) == cow);
+ cow->z = 12.3f;
+ player_look(8.5f, 100.75f, 8.6f, 0, 0);
+ CHECK(pl.hit_face < 0 && !entity_looked_at(3, 1e9f));
plat_remove_prefix("ut10");
}
{