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.

Celeste: the CE version's zip movers

Mason363b038a99c9361
diff --git a/games/celeste/ce/data/CEL10.bin b/games/celeste/ce/data/CEL10.bin
index 08314948..46455e6d 100644
Binary files a/games/celeste/ce/data/CEL10.bin and b/games/celeste/ce/data/CEL10.bin differ
diff --git a/games/celeste/ce/data/CEL11.bin b/games/celeste/ce/data/CEL11.bin
index a1acbdff..766fa166 100644
Binary files a/games/celeste/ce/data/CEL11.bin and b/games/celeste/ce/data/CEL11.bin differ
diff --git a/games/celeste/ce/data/CEL12.bin b/games/celeste/ce/data/CEL12.bin
index 3328b9f4..6a00d09e 100644
Binary files a/games/celeste/ce/data/CEL12.bin and b/games/celeste/ce/data/CEL12.bin differ
diff --git a/games/celeste/ce/data/CEL13.bin b/games/celeste/ce/data/CEL13.bin
index 992fae63..bd28abf3 100644
Binary files a/games/celeste/ce/data/CEL13.bin and b/games/celeste/ce/data/CEL13.bin differ
diff --git a/games/celeste/ce/data/CEL14.bin b/games/celeste/ce/data/CEL14.bin
index e9be5df1..687d23fa 100644
Binary files a/games/celeste/ce/data/CEL14.bin and b/games/celeste/ce/data/CEL14.bin differ
diff --git a/games/celeste/ce/data/CELG0.bin b/games/celeste/ce/data/CELG0.bin
index aea22f2f..7f02df2c 100644
Binary files a/games/celeste/ce/data/CELG0.bin and b/games/celeste/ce/data/CELG0.bin differ
diff --git a/games/celeste/ce/data/CELG1.bin b/games/celeste/ce/data/CELG1.bin
index 34df819c..c0fceccc 100644
Binary files a/games/celeste/ce/data/CELG1.bin and b/games/celeste/ce/data/CELG1.bin differ
diff --git a/games/celeste/ce/host/plat_host.c b/games/celeste/ce/host/plat_host.c
index 9964ae38..13ff86ed 100644
--- a/games/celeste/ce/host/plat_host.c
+++ b/games/celeste/ce/host/plat_host.c
@@ -134,6 +134,8 @@ unsigned plat_keys(void) {
for (int i = 0; i < 320 * 180; i++) nt += g_bg8[i] != 0;
{ int cnt[256] = {0}; for (int i = 0; i < g_nents; i++) if (g_ents[i].type != 255) cnt[g_ents[i].type]++;
printf("ents:"); for (int t = 0; t < 256; t++) if (cnt[t]) printf(" %d:%d", t, cnt[t]); printf("\n"); }
+ for (int i = 0; i < g_nents; i++)
+ if (g_ents[i].type == ET_zipMover) printf("zip at %d %d (%d x %d)\n", g_ents[i].x - rm->x, g_ents[i].y - rm->y, g_ents[i].hw, g_ents[i].hh);
printf("room %s tw %d th %d ntiles %d fg %d bg %d bg4 %d hasbg %d map %d %d %d\n", level_room_name(), rm->tw, rm->th,
rm->ntiles, nf, nb, nt, g_has_bg, g_bg_map[0], g_bg_map[1], g_bg_map[2]);
}
diff --git a/games/celeste/ce/src/draw.c b/games/celeste/ce/src/draw.c
index d4da3f94..b93ec39a 100644
--- a/games/celeste/ce/src/draw.c
+++ b/games/celeste/ce/src/draw.c
@@ -204,11 +204,14 @@ void draw_pixel(int x, int y, uint8_t c) {
if (dry_box(x, y, x + 1, y + 1, c)) return;
if (x >= g_clip_x0 && y >= g_clip_y0 && x < g_clip_x1 && y < g_clip_y1) *FB(x, y) = c;
}
-void draw_line(int x0, int y0, int x1, int y1, uint8_t c) {
+void draw_line(int x0, int y0, int x1, int y1, uint8_t c) { /* (x1, y1) left out */
+ x0 -= g_camx, y0 -= g_camy, x1 -= g_camx, y1 -= g_camy;
+ if (dry_box(imin(x0, x1), imin(y0, y1), imax(x0, x1) + 1, imax(y0, y1) + 1, c + (unsigned)(x1 - x0) * 5 + (unsigned)(y1 - y0)))
+ return;
+ if (imax(x0, x1) < g_clip_x0 || imin(x0, x1) >= g_clip_x1 || imax(y0, y1) < g_clip_y0 || imin(y0, y1) >= g_clip_y1) return;
int dx = iabs(x1 - x0), dy = -iabs(y1 - y0), sx = x0 < x1 ? 1 : -1, sy = y0 < y1 ? 1 : -1, err = dx + dy;
- for (int guard = 0; guard < 2000; guard++) {
- draw_pixel(x0, y0, c);
- if (x0 == x1 && y0 == y1) break;
+ while (x0 != x1 || y0 != y1) {
+ if (x0 >= g_clip_x0 && y0 >= g_clip_y0 && x0 < g_clip_x1 && y0 < g_clip_y1) *FB(x0, y0) = c;
int e2 = 2 * err;
if (e2 >= dy) err += dy, x0 += sx;
if (e2 <= dx) err += dx, y0 += sy;
diff --git a/games/celeste/ce/src/ents.c b/games/celeste/ce/src/ents.c
index a84c1056..36b0474c 100644
--- a/games/celeste/ce/src/ents.c
+++ b/games/celeste/ce/src/ents.c
@@ -593,6 +593,8 @@ static void zip_moveto(Ent *e, bool back, f32 pct) { /* Platform.MoveTo(Vector
plat_move_h(e, f_sub(x, f_add(f_int(e->x), e->remx)));
plat_move_v(e, f_sub(y, f_add(f_int(e->y), e->remy)));
}
+#define ZIP_PATH 201 /* (its path: ropes and cogs, an entity of its own behind it) */
+#define F_4096 0x45800000ul
static void zip_update(Ent *e) {
shake_update(e);
e->liftx = e->lifty = 0;
@@ -609,6 +611,7 @@ static void zip_update(Ent *e) {
break;
case 2: /* there in half a second, Ease.SineIn */
zip_moveto(e, false, zip_out[e->t0]);
+ e->a1 = (int16_t)f_round(f_mul(zip_out[e->t0], F_4096)); /* (its percent, in 4096ths) */
if (++e->t0 >= ZIP_OUT_N) {
shake_start(e, TIM(.2f));
level_shake(TIM(.3f) / DTU);
@@ -621,6 +624,7 @@ static void zip_update(Ent *e) {
break;
case 4: /* back in two seconds */
zip_moveto(e, true, zip_back[e->t0]);
+ e->a1 = (int16_t)(4096 - f_round(f_mul(zip_back[e->t0], F_4096)));
if (++e->t0 >= ZIP_BACK_N) {
shake_start(e, TIM(.2f));
e->a0 = 1, e->t1 = TIM(.5f), st = 5;
@@ -633,10 +637,74 @@ static void zip_update(Ent *e) {
}
e->sub = (uint8_t)((e->sub & 0x80) | st);
}
+/* ZipMover.Render: black inside, cogs turning in it (12 frames; every other one the other way, at half brightness;
+ * those on the sides cut so they stay inside), the block's edges, the light on top. Its pictures: the record's values
+ * (tools/pack_ce.py zip_sprites). a1: its percent (4096ths) */
static void zip_render(Ent *e) {
- int x = e->x + e->a2, y = e->y + e->a3, w = e->hw, h = e->hh;
+ int x = e->x + e->a2, y = e->y + e->a3, w = e->hw, h = e->hh, p = e->a1;
draw_rect(x + 1, y + 1, w - 2, h - 2, BLACK);
- tiles_render(e, 0, w / 8, rec_nvals(e->rec), e->a2, e->a3);
+ int blk = rec_val(e->rec, 0), inner = rec_val(e->rec, 2);
+ int c0 = g_clip_x0, c1 = g_clip_x1, r0 = g_clip_y0, r1 = g_clip_y1;
+ g_clip_x0 = imax(c0, x + 1 - g_camx), g_clip_x1 = imin(c1, x + w - 1 - g_camx);
+ g_clip_y0 = imax(r0, y + 1 - g_camy), g_clip_y1 = imin(r1, y + h - 1 - g_camy);
+ if (g_clip_x0 < g_clip_x1 && g_clip_y0 < g_clip_y1) {
+ int num = 1, k = 0;
+ for (int i = 4; i <= h - 4; i += 8) {
+ int num3 = num;
+ for (int j = 4; j <= w - 4; j += 8, k++) {
+ /* frame: (pi / 3 a cog + num percent 4 pi) / (pi / 2), its fraction in twelfths */
+ int f = fdiv(8 * k * 4096 + num * 96 * p, 4096) % 12;
+ if (f < 0) f += 12;
+ int lx = j <= 4 ? j - 5 : j >= w - 4 ? j - 7 : j - 6, ly = i <= 4 ? i - 5 : i >= h - 4 ? i - 7 : i - 6;
+ draw_sprite(csprite(inner + f + (num < 0 ? 12 : 0)), x + lx, y + ly, 0);
+ num = -num;
+ }
+ if (num3 == num) num = -num;
+ }
+ }
+ g_clip_x0 = c0, g_clip_x1 = c1, g_clip_y0 = r0, g_clip_y1 = r1;
+ for (int k = 0; k * 8 < w; k++)
+ for (int l = 0; l * 8 < h; l++) {
+ int a = k == 0 ? 0 : k * 8 + 8 != w ? 1 : 2, b = l == 0 ? 0 : l * 8 + 8 != h ? 1 : 2;
+ if (a != 1 || b != 1) draw_sprite(csprite(blk + a + 3 * b), x + k * 8, y + l * 8, 0);
+ }
+ draw_sprite(csprite(rec_val(e->rec, 1) + e->a0), x + w / 2 - 4, y, 0);
+}
+/* ZipMoverPathRenderer (depth 5000): the two ropes with their teeth moving along them, a cog at each end turning a
+ * full turn as it goes; all once more in black a pixel lower first, and a black frame round the block after */
+static void zippath_lines(Ent *z, int fx, int fy, int tx, int ty, int off, bool black) {
+ int dx = tx - fx, dy = ty - fy, len = isqrt24(dx * dx + dy * dy);
+ int ux = len ? dx * 256 / len : 0, uy = len ? dy * 256 / len : 0; /* (1/256 px) */
+ int px = -uy, py = ux; /* Perpendicular */
+ int ax = fx * 256 + px * 3, ay = (fy + off) * 256 + py * 3, bx = fx * 256 - px * 4, by = (fy + off) * 256 - py * 4;
+ int ex = (tx - fx) * 256, ey = (ty - fy) * 256;
+ uint8_t rope = black ? BLACK : ROPE, light = black ? BLACK : ROPE_LIGHT;
+#define PX(v) (((v) + 128) >> 8)
+ draw_line(PX(ax), PX(ay), PX(ax + ex), PX(ay + ey), rope);
+ draw_line(PX(bx), PX(by), PX(bx + ex), PX(by + ey), rope);
+ /* the teeth: 2 px every 4 along each, starting 4 - (percent 8 pi) % 4 in */
+ int n = 1024 - (int)((long)z->a1 * 1608 / 1024 % 1024); /* (1/256 px) */
+ for (; n < len * 256; n += 1024) {
+ int sx = ax + px + (ux * n >> 8), sy = ay + py + (uy * n >> 8);
+ int qx = bx + ex - (ux * n >> 8), qy = by + ey - (uy * n >> 8);
+ draw_line(PX(sx), PX(sy), PX(sx + ux * 2), PX(sy + uy * 2), light);
+ draw_line(PX(qx), PX(qy), PX(qx - ux * 2), PX(qy - uy * 2), light);
+ }
+#undef PX
+ int cog = rec_val(z->rec, 3) + ((z->a1 + 64) >> 7 & 31) + (black ? 32 : 0);
+ draw_sprite(csprite(cog), fx - 9, fy + off - 9, 0);
+ draw_sprite(csprite(cog), tx - 9, ty + off - 9, 0);
+}
+static void zippath_render(Ent *e) {
+ Ent *z = e->ptr;
+ Room *rm = &g_level.rooms[z->room];
+ const uint8_t *n = rec_node(z->rec, 0);
+ int w = z->hw, h = z->hh;
+ int fx = rm->x + REC_X(z->rec) + w / 2, fy = rm->y + REC_Y(z->rec) + h / 2;
+ int tx = rm->x + S16(n) + w / 2, ty = rm->y + S16(n + 2) + h / 2;
+ zippath_lines(z, fx, fy, tx, ty, 1, true);
+ zippath_lines(z, fx, fy, tx, ty, 0, false);
+ draw_rect(z->x + z->a2 - 1, z->y + z->a3 - 1, w + 2, h + 2, BLACK);
}
/* ---------------------------------------------------------------- triggers */
@@ -746,7 +814,17 @@ static Ent *spawn(const uint8_t *r, int slot, bool trigger) {
case ET_dashBlock: box(e, w, h, 0, 0), e->flags |= EF_SOLID, e->depth = -12999; break;
case ET_fakeWall: box(e, w, h, 0, 0), e->flags &= ~EF_COLLIDABLE, e->depth = -13000, e->t0 = 256; break;
case ET_coverupWall: box(e, w, h, 0, 0), e->flags &= ~EF_COLLIDABLE, e->depth = -13000, e->t0 = 256; break;
- case ET_zipMover: box(e, w, h, 0, 0), e->flags |= EF_SOLID, e->depth = -9999, e->a0 = 1; break;
+ case ET_zipMover: {
+ box(e, w, h, 0, 0), e->flags |= EF_SOLID, e->depth = -9999, e->a0 = 1;
+ Ent *p = ent_new(ZIP_PATH, x, y); /* (its box round both ends, for leaving it out when far) */
+ if (p) {
+ const uint8_t *n = rec_node(r, 0);
+ int tx = rm->x + S16(n), ty = rm->y + S16(n + 2);
+ p->flags = EF_VISIBLE, p->room = (uint8_t)slot, p->depth = 5000, p->ptr = e;
+ box(p, iabs(tx - x) + w, iabs(ty - y) + h, imin(tx, x) - x, imin(ty, y) - y);
+ }
+ break;
+ }
default:
e->flags = EF_ACTIVE | EF_VISIBLE; /* scenery not drawn yet */
e->type = 100;
@@ -860,6 +938,7 @@ static void ent_draw(Ent *e) {
case ET_fallingBlock: case ET_dashBlock: block_render(e); break;
case ET_fakeWall: case ET_coverupWall: fakewall_render(e); break;
case ET_zipMover: zip_render(e); break;
+ case ZIP_PATH: zippath_render(e); break;
case 200: {
const uint8_t *s = sprite(anim_sprite(e));
draw_sprite(s, e->x - s[0] / 2, e->y - s[1] / 2, 0);
diff --git a/games/celeste/ce/src/gen.h b/games/celeste/ce/src/gen.h
index ead42a86..5f92bc01 100644
--- a/games/celeste/ce/src/gen.h
+++ b/games/celeste/ce/src/gen.h
@@ -512,6 +512,8 @@
#define HAIR_DARK 2
#define WHITE 3
#define BLACK 4
+#define ROPE 5
+#define ROPE_LIGHT 6
#define ET_player 0
#define ET_spikesUp 1
#define ET_spikesDown 2
diff --git a/games/celeste/ce/tools/pack_ce.py b/games/celeste/ce/tools/pack_ce.py
index 700ca262..b844c6a5 100644
--- a/games/celeste/ce/tools/pack_ce.py
+++ b/games/celeste/ce/tools/pack_ce.py
@@ -9,6 +9,7 @@ lives in archived appvars the game reads in place: CELG0.. (what every chapter d
tiles, rooms, decals and background). An appvar holds 64 KB at most, so a blob is laid out over several of them, and
its pointers are 3 bytes: the offset in the appvar, then which one (src/data.c)."""
import collections
+import math
import os
import random
import re
@@ -30,6 +31,7 @@ GEN_H = os.path.join(HERE, "..", "src", "gen.h")
PART_MAX = 65000 # bytes of an appvar
COMMON = 96 # colours every chapter shares (indices 0 .. COMMON - 1)
HAIR, HAIR_DARK, WHITE, BLACK = 1, 2, 3, 4 # fixed colours (HAIR and HAIR_DARK change as Madeline's hair does)
+ROPE, ROPE_LIGHT = 5, 6 # ZipMover's ropes (663931) and their teeth (9b6157), drawn as lines
MARGIN = 4 # tiles kept around each room (transitions show the next one's edges)
FORMAT = 1 # bumped when the layout changes (the game checks it)
@@ -498,7 +500,8 @@ class Common:
counts = collections.Counter()
for k, img in self.images.items():
count_colors(img, counts)
- fixed = [0, 0x5466, 0x2C33, 0x7FFF, 0x0000] # 0 black, HAIR, HAIR_DARK, white, black for the art
+ fixed = [0, 0x5466, 0x2C33, 0x7FFF, 0x0000, # 0 black, HAIR, HAIR_DARK, white, black for the art
+ int(c15(np.array([0x66, 0x39, 0x31]))), int(c15(np.array([0x9B, 0x61, 0x57])))] # ROPE, ROPE_LIGHT
extra = kmeans(counts, set(fixed), COMMON - len(fixed))
cols = fixed + extra
print(f"common: {len(counts)} colours -> {len(cols)}")
@@ -543,6 +546,7 @@ class Common:
h.ref(table).ref(anims).ref(meta).ref(hair)
H.append(f"#define COMMON {COMMON}")
H.append(f"#define HAIR {HAIR}\n#define HAIR_DARK {HAIR_DARK}\n#define WHITE {WHITE}\n#define BLACK {BLACK}")
+ H.append(f"#define ROPE {ROPE}\n#define ROPE_LIGHT {ROPE_LIGHT}")
return self.blob.write()
@@ -820,6 +824,7 @@ class Chapter:
self.decal_ids = {}
for p in ent_paths:
self.sprites.add(p, pal.map(self.image(p)))
+ self.zip_ids = self.zip_sprites(pal)
# the backgrounds' 16 colours (chapter palette indices), then each room's picture: 4 bits a pixel (the left
# one low), zx0 packed; rooms with the same picture share it
bgpal = Palette([0] + bgcols, reserved=False)
@@ -884,8 +889,54 @@ class Chapter:
out = []
for d in ("up", "down", "left", "right"):
out += [s.path for s in family("danger/spikes/%s_%s" % (st["spike"], d))]
+ out += ["objects/zipmover/block", "objects/zipmover/cog"]
+ out += [s.path for s in family("objects/zipmover/light") + family("objects/zipmover/innercog")]
return out
+ def zip_sprites(self, pal):
+ """ZipMover's pictures (src/ents.c zip_render): the block's 8 x 8 parts (part (a, b) at a + 3 b), the light's 4
+ frames, the 12 inner cogs and the same at half brightness (Color.White * 0.5 over the black inside), and the cog
+ turned 32 ways round (18 x 18, its middle at (9, 9): point sampled, as the game draws it turned), then the same
+ in black (its shadow, a pixel lower). Their first ids: [block, light, inner, cog], each zip mover's values."""
+ S = self.sprites
+ blk = self.image("objects/zipmover/block")
+ ids = [S.add(("zip block", 0), pal.map(blk[0:8, 0:8]))]
+ for k in range(1, 9):
+ a, b = k % 3, k // 3
+ assert S.add(("zip block", k), pal.map(blk[b * 8:b * 8 + 8, a * 8:a * 8 + 8])) == ids[0] + k
+ lights = family("objects/zipmover/light")
+ inner = family("objects/zipmover/innercog")
+ assert len(lights) == 4 and len(inner) == 12
+ ids.append(S.add(("zip light", 0), pal.map(lights[0].image())))
+ for k in range(1, 4):
+ assert S.add(("zip light", k), pal.map(lights[k].image())) == ids[1] + k
+ ids.append(S.add(("zip inner", 0), pal.map(inner[0].image())))
+ for k in range(1, 24):
+ img = inner[k % 12].image()
+ if k >= 12:
+ img = img.copy()
+ img[..., :3] //= 2
+ assert S.add(("zip inner", k), pal.map(img)) == ids[2] + k
+ cog = self.image("objects/zipmover/cog")
+ ch, cw = cog.shape[:2]
+ for k in range(64):
+ ang = (k % 32) * math.pi * 2 / 32
+ c, s_ = math.cos(ang), math.sin(ang)
+ out = np.zeros((18, 18, 4), np.uint8)
+ for y in range(18):
+ for x in range(18):
+ dx, dy = x + 0.5 - 9, y + 0.5 - 9
+ sx, sy = math.floor(c * dx + s_ * dy + cw / 2), math.floor(-s_ * dx + c * dy + ch / 2)
+ if 0 <= sx < cw and 0 <= sy < ch:
+ out[y, x] = cog[sy, sx]
+ if k >= 32:
+ out[..., :3] = 0
+ i = S.add(("zip cog", k), pal.map(out))
+ if k == 0:
+ ids.append(i)
+ assert i == ids[3] + k
+ return ids
+
def room(self, r, cells):
ROOM_FLAGS = [("dark", 1), ("space", 2), ("underwater", 4), ("disableDownTransition", 8), ("whisper", 16)]
tw, th = r.w // 8 + 2 * MARGIN, r.h // 8 + 2 * MARGIN
@@ -1089,7 +1140,7 @@ class Chapter:
flags |= 4 if blend else 0
vals += self.block_tiles(r, x, y, w, h, c, blend)
elif n == "zipMover":
- pass
+ vals += self.zip_ids
elif n in ("strawberry", "goldenBerry"):
flags |= 1 if a("winged", False) else 0
flags |= 2 if a("moon", False) else 0