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 TI-84 Plus CE version's data

Mason3633a4c29a7e54b
diff --git a/games/celeste/ce/.gitignore b/games/celeste/ce/.gitignore
new file mode 100644
index 00000000..754681b5
--- /dev/null
+++ b/games/celeste/ce/.gitignore
@@ -0,0 +1,3 @@
+bin/
+build/
+obj/
diff --git a/games/celeste/ce/data/CEL10.bin b/games/celeste/ce/data/CEL10.bin
new file mode 100644
index 00000000..7ae63591
Binary files /dev/null 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
new file mode 100644
index 00000000..3cf02106
Binary files /dev/null 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
new file mode 100644
index 00000000..35d721bd
Binary files /dev/null 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
new file mode 100644
index 00000000..dda8a811
--- /dev/null
+++ b/games/celeste/ce/data/CEL13.bin
@@ -0,0 +1 @@
+JJLLLLLLLLLLLLLLLLLLLLLLLJJJJLLLLLLLLLLLLLLLLLLLLLLLJJJJLLLLLLLLLLLLLLLLLLLLLLLJJJJLLLLLLLLLLLLLLLLLLLLLLLJJJJJJJJJJJJJJJJJJLLLLLLLLLLLLLLLLLLLLLLLLJLLLLLLLLLLLLLLLLLLLLLLLJJLLLLLLLLLLLLLLLLLLLLLLLJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLJJJJJLLLJJJLLLLJJJJLLFFFFFFFFFFFFFFFFFFFFFFFFFFLLJJJJJLLJJJJJLLJJJJJLLFFFFFFFFFFFFFFFFFFFFF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LLLLLLLLLLLLLLLLLLLLLLLLLLLLLJLLJLLJLLJJJLLJJJLLJJJLLJJJLLLJJJJLLLJLLLLLLLLLLLLLLLLLLLLLLLLLLLLLJJJJJFFFFFFFFFJJLFFLLLLLLLLLLLLLLJJJJJJJJJJJJJJJJJJLLLJJJLLJJJJLLJLLLLLLLLLLLLLLLLLLLLLLLLJLLLJJJLLLJJJJJJJJJJJLLLJJJLLJJJLLLLLLLLJLLJLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
\ No newline at end of file
diff --git a/games/celeste/ce/data/CELG0.bin b/games/celeste/ce/data/CELG0.bin
new file mode 100644
index 00000000..d64d7733
Binary files /dev/null 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
new file mode 100644
index 00000000..ed2f59e9
Binary files /dev/null and b/games/celeste/ce/data/CELG1.bin differ
diff --git a/games/celeste/ce/src/ce.h b/games/celeste/ce/src/ce.h
new file mode 100644
index 00000000..9c285215
--- /dev/null
+++ b/games/celeste/ce/src/ce.h
@@ -0,0 +1,290 @@
+/* Celeste for the TI-84 Plus CE: shared declarations.
+ *
+ * Inspired by Celeste, not affiliated with Maddy Makes Games.
+ * Made by Mason Chen as part of NumPlay.
+ *
+ * The CE version of games/celeste: Celeste's rules (Player.cs, as src/player.c ports them for the NumWorks) in whole
+ * numbers, drawn at 8 bits a pixel from the game's own pictures (tools/pack_ce.py), 60 updates a second.
+ *
+ * Numbers: an int has 24 bits on the CE (32 on a computer: everything here stays within 24). Positions are whole
+ * pixels; what moves keeps the rest in MU-ths of a pixel; speeds are in 60ths of a pixel a second (a frame moves an
+ * entity `speed` MU); times are in 600ths of a second (a frame is DTU of them). Celeste's float constants are exact in
+ * these units, so its movement comes out the same, pixel for pixel (tests/physics.c checks it against the NumWorks
+ * port's floats). */
+#ifndef CE_H
+#define CE_H
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <string.h>
+#include "gen.h"
+
+#define MU 3600 /* sub-pixels a pixel */
+#define SPD(v) ((int)((v) * 60)) /* px/s -> speed units */
+#define TIM(s) ((int)((s) * 600 + 0.5f)) /* seconds -> time units */
+#define DTU 10 /* a frame */
+#define VIEW_W 320
+#define VIEW_H 180
+#define VIEW_Y 30 /* the view's top on the screen */
+
+/* ---------------------------------------------------------------- platform (plat_ce.c, host/plat_host.c) */
+enum {
+ K_LEFT = 1, K_RIGHT = 2, K_UP = 4, K_DOWN = 8, K_JUMP = 16, K_DASH = 32, K_GRAB = 64, K_PAUSE = 128,
+ K_OK = 256, K_BACK = 512, K_QUIT = 1024, K_TALK = 2048
+};
+extern uint8_t *g_fb; /* the buffer drawn this frame: 320 x 240 bytes */
+void plat_init(void);
+void plat_exit(void);
+void plat_frame(void); /* shows g_fb, and g_fb becomes the other buffer */
+void plat_palette(const uint16_t *pal, int first, int n); /* 1555 colours */
+unsigned plat_keys(void);
+unsigned plat_ticks(void); /* a 32768 Hz clock (wraps at 16 bits) */
+void plat_wait(unsigned ticks);
+const uint8_t *plat_appvar(const char *name); /* an appvar's data in place, NULL if missing */
+bool plat_save(const char *name, const void *data, unsigned n);
+bool plat_load(const char *name, void *data, unsigned n);
+void plat_unpack(void *dst, const void *src); /* ZX0 */
+
+/* ---------------------------------------------------------------- reading data */
+#ifdef __TICE__
+#define R16(p) (*(const uint16_t *)(const void *)(p))
+#define R24(p) (*(const unsigned int *)(const void *)(p))
+#define S16(p) (*(const int16_t *)(const void *)(p))
+#define S24(p) (*(const int *)(const void *)(p))
+#else
+static inline unsigned R16(const uint8_t *p) { return (unsigned)(p[0] | p[1] << 8); }
+static inline unsigned R24(const uint8_t *p) { return (unsigned)(p[0] | p[1] << 8 | p[2] << 16); }
+static inline int S16(const uint8_t *p) { return (int16_t)R16(p); }
+static inline int S24(const uint8_t *p) { return (int)(R24(p) << 8) >> 8; }
+#endif
+#define MAX_PARTS 8
+extern const uint8_t *g_common[MAX_PARTS], *g_chap[MAX_PARTS];
+/* a 3-byte pointer of a blob: offset, then the appvar */
+static inline const uint8_t *far_ptr(const uint8_t *const *parts, const uint8_t *p) {
+ return parts[p[2]] + R16(p);
+}
+#define CPTR(p) far_ptr(g_common, p)
+#define HPTR(p) far_ptr(g_chap, p)
+bool data_open(void); /* the common appvars; false if missing */
+bool chapter_open(int n); /* chapter n's appvars and colours */
+void palette_apply(int fade); /* the chapter's colours (fade 0..256: to black) */
+void palette_hair(uint32_t rgb); /* Madeline's hair colour */
+const uint8_t *sprite(int id); /* a common sprite */
+const uint8_t *csprite(int id); /* a chapter sprite */
+const uint8_t *anim(int id); /* an animation: u8 frames, u8 flags, u16 delay, u8 goto, u8 bank, u16 sprites */
+extern const uint8_t *g_tile_flags;
+extern int g_nrooms;
+const uint8_t *room_rec(int i);
+const uint8_t *tile_data(int id);
+const uint8_t *player_meta(int sprite_id); /* s8 hair x, s8 hair y, u8 bangs | has hair << 7 */
+const uint16_t *hair_mask(int which); /* 0 hair, 1-3 bangs: 10 rows (mask), then 10 (dark) */
+extern const uint8_t *g_bg; /* the chapter's background (320 x 180), NULL if none */
+extern int g_bg_camx, g_bg_camy;
+
+/* ---------------------------------------------------------------- drawing (draw.c) */
+enum { DF_FLIPX = 1, DF_FLIPY = 2, DF_SOLID = 4 }; /* DF_SOLID: every pixel in one colour (draw_color) */
+extern int g_camx, g_camy; /* the view's top left in the world */
+extern uint8_t g_draw_color;
+void draw_sprite(const uint8_t *spr, int x, int y, uint8_t flags); /* (x, y): the frame's top left, world */
+void draw_sprite_scaled(const uint8_t *spr, int x, int y, int sx, int sy, int ox, int oy, uint8_t flags);
+void draw_tile(int tile, int x, int y); /* world */
+void draw_rect(int x, int y, int w, int h, uint8_t c); /* world */
+void draw_rect_screen(int x, int y, int w, int h, uint8_t c); /* view coordinates */
+void draw_line(int x0, int y0, int x1, int y1, uint8_t c); /* world */
+void draw_pixel(int x, int y, uint8_t c);
+void draw_circle_fill(int cx, int cy, int r, uint8_t c);
+void draw_text(const char *s, int x, int y, uint8_t c); /* screen coordinates (0..320, 0..240) */
+int text_width(const char *s);
+void draw_layers_back(void); /* background, bg tiles */
+void draw_layer_fg(void); /* fg tiles */
+void draw_decals(int fg);
+void draw_clear_screen(uint8_t c);
+
+/* ---------------------------------------------------------------- math */
+static inline int imin(int a, int b) { return a < b ? a : b; }
+static inline int imax(int a, int b) { return a > b ? a : b; }
+static inline int iabs(int a) { return a < 0 ? -a : a; }
+static inline int isign(int a) { return (a > 0) - (a < 0); }
+static inline int iclamp(int v, int lo, int hi) { return v < lo ? lo : v > hi ? hi : v; }
+static inline int approach(int v, int t, int d) { return v <= t ? imin(v + d, t) : imax(v - d, t); }
+int fdiv(int a, int b); /* floor(a / b), b > 0 */
+int round_mu(int c, int dir); /* c / MU rounded as Celeste's floats round it (see level.c) */
+int isqrt(int32_t v);
+int sin256(int a); /* a: 1024 a turn, result * 256 */
+static inline int cos256(int a) { return sin256(a + 256); }
+uint32_t rnd(void);
+static inline int rndn(int n) { return (int)((rnd() >> 8) % (uint32_t)n); }
+
+/* ---------------------------------------------------------------- input */
+typedef struct {
+ bool check, pressed; /* held; went down this frame (or buffered) */
+ int8_t buffer; /* frames the press is kept (Celeste's 0.08 s) */
+} Button;
+typedef struct {
+ Button jump, dash, grab, pause, ok, back, talk;
+ int move_x, move_y, aim_x, aim_y;
+ unsigned keys, prev;
+} Input;
+extern Input g_in;
+void input_update(unsigned keys);
+static inline bool btn_pressed(const Button *b) { return b->buffer > 0; }
+static inline void btn_consume(Button *b) { b->buffer = 0; }
+
+/* ---------------------------------------------------------------- entities (ents.c) */
+enum { /* Ent.flags */
+ EF_ACTIVE = 1, EF_VISIBLE = 2, EF_COLLIDABLE = 4, EF_SOLID = 8, EF_JUMPTHRU = 16, EF_PCOLLIDE = 32, EF_SAFE = 64,
+ EF_TRIGGER = 128
+};
+typedef struct Ent Ent;
+struct Ent {
+ uint8_t type; /* ET_ / TT_ + 64 (triggers), 255: free */
+ uint8_t flags, room; /* room: its slot (0, 1), 2: none (the player) */
+ uint8_t sub; /* type's own little state */
+ int16_t depth;
+ int x, y;
+ int remx, remy; /* MU */
+ int16_t hx, hy, hw, hh; /* collider: left, top (from x, y), width, height */
+ int liftx, lifty; /* speed units: a platform's LiftSpeed this frame */
+ const uint8_t *rec; /* its map record */
+ int t0, t1, t2, t3; /* the type's own numbers */
+ int16_t a0, a1, a2, a3;
+ void *ptr;
+};
+#define MAX_ENTS 96
+extern Ent g_ents[MAX_ENTS];
+extern int g_nents;
+static inline int e_left(const Ent *e) { return e->x + e->hx; }
+static inline int e_top(const Ent *e) { return e->y + e->hy; }
+static inline int e_right(const Ent *e) { return e->x + e->hx + e->hw; }
+static inline int e_bottom(const Ent *e) { return e->y + e->hy + e->hh; }
+Ent *ent_new(int type, int x, int y);
+void ent_free(Ent *e);
+void ents_spawn_room(int slot);
+void ents_update(void);
+void ents_render(int dmax, int dmin); /* depths in (dmin, dmax] */
+void ents_remove_room(int slot);
+void ents_clear(void);
+bool rect_hits(int l, int t, int r, int b, const Ent *o);
+bool ent_collide_at(const Ent *e, int x, int y, const Ent *o);
+
+/* ---------------------------------------------------------------- the level (level.c) */
+typedef struct {
+ int index; /* -1: none */
+ const uint8_t *rec;
+ int x, y, w, h; /* pixels, world */
+ int gx, gy, tw, th; /* its grid: the top left cell's world pixel, cells (with MARGIN) */
+ uint8_t *grid; /* fg[tw * th], bg[tw * th], solid bits (rb a row) */
+ int rb;
+ const uint8_t *tiles[256];
+ uint8_t ntiles;
+ uint8_t flags;
+ int8_t camx, camy;
+} Room;
+typedef struct {
+ int chapter;
+ Room rooms[2];
+ int slot; /* the current room */
+ Room *room;
+ int camx, camy; /* camera, 1/256 px */
+ int cam_offx, cam_offy; /* Level.CameraOffset, px */
+ int shake_timer, shakex, shakey, shake_dirx, shake_diry;
+ int8_t last_dir_shake;
+ bool transitioning;
+ int tr_t; /* 0..256*? the transition's progress (time units) */
+ int tr_fromx, tr_fromy, tr_tox, tr_toy, tr_px, tr_py;
+ int tr_dirx, tr_diry;
+ int respawn_x, respawn_y;
+ bool dead_reload;
+ int freeze; /* frames */
+ int flash;
+ uint32_t frame, time; /* frames played, the chapter's clock (frames) */
+ bool completed, paused;
+ int wipe; /* the wipe: 0 none, >0 closing, <0 opening (frames) */
+ uint8_t wipe_dir;
+} Level;
+extern Level g_level;
+bool level_load(int chapter, int room, int intro);
+void level_update(void);
+void level_render(void);
+bool solid_at(int l, int t, int r, int b, const Ent *self); /* tiles or solid entities over [l, r) x [t, b) */
+Ent *solid_first(int l, int t, int r, int b, const Ent *self);
+Ent *jumpthru_first_outside(const Ent *e, int x, int y);
+bool tiles_solid(int l, int t, int r, int b);
+void level_shake(int frames);
+void level_dir_shake(int dx, int dy, int frames);
+void level_freeze(int frames);
+int level_room_at(int x, int y);
+int level_room_find(const char *name);
+const char *level_room_name(void);
+
+/* ---------------------------------------------------------------- Madeline (player.c) */
+enum { ST_NORMAL, ST_CLIMB, ST_DASH, ST_INTRORESPAWN, ST_INTROJUMP, ST_INTROWALK, ST_DUMMY, ST_COUNT };
+enum { INTRO_TRANSITION, INTRO_RESPAWN, INTRO_WALKINRIGHT, INTRO_WALKINLEFT, INTRO_JUMP, INTRO_NONE };
+#define HAIR_NODES 5
+typedef struct {
+ Ent *e;
+ int sx, sy; /* speed */
+ int facing;
+ int state, prev_state;
+ bool on_ground, was_on_ground, on_safe_ground, ducking, dead;
+ int dashes, max_dashes, last_dashes;
+ int stamina; /* 1/36000 */
+ int move_x;
+ int jump_grace, var_jump, var_jump_speed, auto_jump_timer;
+ bool auto_jump;
+ int force_move_x, force_move_x_timer;
+ int dash_cooldown, dash_refill_cooldown, dash_attack;
+ int dash_dx, dash_dy; /* 1/256 */
+ int last_aim_x, last_aim_y; /* aim: -1, 0, 1 */
+ int wall_slide_timer, wall_slide_dir;
+ int climb_no_move;
+ int wall_speed_retention, wall_speed_retained;
+ int wall_boost_dir, wall_boost_timer;
+ int max_fall;
+ int hop_wait_x, hop_wait_x_speed;
+ int last_climb_move;
+ bool dash_started_on_ground, fast_jump, was_dash_b, called_dash_events;
+ int before_dash_sx, before_dash_sy;
+ int co_step, co_wait; /* the state's coroutine */
+ bool co_active;
+ int dash_trail_timer;
+ int lift_timer, last_liftx, last_lifty;
+ /* the sprite */
+ int anim, frame, anim_timer;
+ int scale_x, scale_y; /* 1/256 */
+ int idle_timer;
+ bool flash;
+ int hair_flash;
+ uint32_t hair_rgb;
+ int hairx[HAIR_NODES], hairy[HAIR_NODES]; /* 1/256 px */
+ int hair_count, hair_wave;
+ /* intro, respawn, death */
+ int intro_t, respawn_fromx, respawn_fromy;
+ int body_step, body_t, body_dx, body_dy, death_t;
+ int bodyx, bodyy;
+ int death_color;
+ int strawb_index, strawb_reset;
+ int walk_target;
+} Player;
+extern Player g_player;
+void player_spawn(int x, int y, int intro);
+void player_update(void);
+void player_render(void);
+void player_die(int dx, int dy);
+bool player_refill_dash(void);
+bool player_use_refill(bool two);
+void player_bounce(int from_y);
+void player_super_bounce(int from_y);
+void player_side_bounce(int dir, int from_x, int from_y);
+bool player_dash_attacking(void);
+int player_cam_targetx(void), player_cam_targety(void);
+bool player_transition_to(int x, int y);
+void player_on_transition(void);
+void player_before_up_transition(void);
+void player_before_down_transition(void);
+
+/* ---------------------------------------------------------------- the game (game.c) */
+extern bool g_running;
+void game_frame(void);
+void game_draw(void);
+#endif
diff --git a/games/celeste/ce/src/data.c b/games/celeste/ce/src/data.c
new file mode 100644
index 00000000..82672a19
--- /dev/null
+++ b/games/celeste/ce/src/data.c
@@ -0,0 +1,98 @@
+/* The appvars (tools/pack_ce.py): CELG0.. what every chapter draws, CEL<n>0.. chapter n. Read in place. */
+#include "ce.h"
+
+const uint8_t *g_common[MAX_PARTS], *g_chap[MAX_PARTS];
+static const uint8_t *chead, *sprites_c, *sprites_h, *anims, *meta, *hair;
+const uint8_t *g_tile_flags;
+static const uint8_t *tile_chunks;
+static int ntiles;
+int g_nrooms;
+static const uint8_t *rooms;
+const uint8_t *g_bg;
+int g_bg_camx, g_bg_camy;
+static uint16_t pal[256];
+static uint8_t tint[3];
+
+static int open_parts(const char *base, const uint8_t **parts) {
+ char name[9];
+ int n = 0, k = 0;
+ while (base[k]) name[k] = base[k], k++;
+ for (; n < MAX_PARTS; n++) {
+ name[k] = (char)('0' + n), name[k + 1] = 0;
+ parts[n] = plat_appvar(name);
+ if (!parts[n]) break;
+ }
+ return n;
+}
+
+bool data_open(void) {
+ if (!open_parts("CELG", g_common)) return false;
+ chead = g_common[0];
+ if (memcmp(chead, "CELG", 4) || chead[4] != FORMAT) return false;
+ const uint8_t *p = chead + 5 + COMMON * 2;
+ sprites_c = CPTR(p), anims = CPTR(p + 3), meta = CPTR(p + 6), hair = CPTR(p + 9);
+ memcpy(pal, chead + 5, COMMON * 2);
+ return true;
+}
+
+bool chapter_open(int n) {
+ char base[5] = "CEL0";
+ base[3] = (char)('0' + n);
+ memset(g_chap, 0, sizeof g_chap);
+ if (!open_parts(base, g_chap)) return false;
+ const uint8_t *h = g_chap[0];
+ if (memcmp(h, "CELC", 4) || h[4] != FORMAT) return false;
+ memcpy(pal + COMMON, h + 6, (256 - COMMON) * 2);
+ const uint8_t *p = h + 6 + (256 - COMMON) * 2;
+ memcpy(tint, p, 3);
+ p += 3;
+ ntiles = (int)R16(p);
+ tile_chunks = p + 3;
+ p += 3 + 3 * p[2];
+ g_tile_flags = HPTR(p);
+ sprites_h = HPTR(p + 3);
+ p += 6;
+ g_bg = p[0] ? HPTR(p + 7) : NULL;
+ g_bg_camx = S24(p + 1), g_bg_camy = S24(p + 4);
+ p += 10;
+ g_nrooms = (int)R16(p);
+ rooms = p + 2;
+ return true;
+}
+
+const uint8_t *room_rec(int i) { return HPTR(rooms + 3 * i); }
+const uint8_t *tile_data(int id) {
+ return HPTR(tile_chunks + 3 * (id / 1000)) + (id % 1000) * 64;
+}
+const uint8_t *sprite(int id) { return CPTR(sprites_c + 2 + 3 * id); }
+const uint8_t *csprite(int id) { return HPTR(sprites_h + 2 + 3 * id); }
+const uint8_t *anim(int id) { return CPTR(anims + 2 + 3 * id); }
+const uint8_t *player_meta(int id) { return meta + 2 + 3 * id; }
+const uint16_t *hair_mask(int which) { return (const uint16_t *)(const void *)(hair + 40 * which); }
+
+/* 1555 colours, plus the chapter's tint (its additive sunset), faded to black by fade (256: none) */
+static uint16_t shade(uint16_t c, int fade) {
+ int r = (c >> 10 & 31) << 3, g = (c >> 5 & 31) << 3, b = (c & 31) << 3;
+ r = imin(255, r + tint[0]), g = imin(255, g + tint[1]), b = imin(255, b + tint[2]);
+ r = r * fade >> 8, g = g * fade >> 8, b = b * fade >> 8;
+ return (uint16_t)((r >> 3) << 10 | (g >> 3) << 5 | (b >> 3));
+}
+static int cur_fade = 256;
+static uint32_t cur_hair = 0xAC3232;
+void palette_apply(int fade) {
+ uint16_t out[256];
+ cur_fade = fade;
+ out[0] = 0;
+ for (int i = 1; i < 256; i++) out[i] = shade(pal[i], fade);
+ plat_palette(out, 0, 256);
+ palette_hair(cur_hair);
+}
+void palette_hair(uint32_t rgb) {
+ cur_hair = rgb;
+ int r = rgb >> 16 & 255, g = rgb >> 8 & 255, b = rgb & 255;
+ uint16_t h[2];
+ h[0] = shade((uint16_t)((r >> 3) << 10 | (g >> 3) << 5 | (b >> 3)), cur_fade);
+ r = r * 134 >> 8, g = g * 134 >> 8, b = b * 134 >> 8;
+ h[1] = shade((uint16_t)((r >> 3) << 10 | (g >> 3) << 5 | (b >> 3)), cur_fade);
+ plat_palette(h, 1, 2);
+}
diff --git a/games/celeste/ce/src/draw.c b/games/celeste/ce/src/draw.c
new file mode 100644
index 00000000..b5d78abd
--- /dev/null
+++ b/games/celeste/ce/src/draw.c
@@ -0,0 +1,294 @@
+/* Drawing at 8 bits a pixel into g_fb (320 x 240; the view's 320 x 180 at VIEW_Y). Pictures come from the appvars
+ * (tools/pack_ce.py): sprites are rows of runs, tiles 8 x 8 bytes (0: see-through). */
+#include "ce.h"
+
+int g_camx, g_camy;
+uint8_t g_draw_color;
+#define FB(x, y) (g_fb + (VIEW_Y + (y)) * 320 + (x))
+
+/* a sprite at view (x, y) (its frame's top left), clipped to the view */
+static void blit_sprite(const uint8_t *s, int x, int y, uint8_t flags) {
+ int fw = s[0], fh = s[1], x0 = s[2], y0 = s[3], w = s[4], h = s[5];
+ const uint8_t *p = s + 6;
+ bool fx = flags & DF_FLIPX, fy = flags & DF_FLIPY, solid = flags & DF_SOLID;
+ uint8_t col = g_draw_color;
+ int left = fx ? x + fw - x0 - w : x + x0; /* the stored part's left on the view */
+ if (left >= VIEW_W || left + w <= 0) return;
+ for (int r = 0; r < h; r++) {
+ int vy = fy ? y + fh - 1 - (y0 + r) : y + y0 + r;
+ int n = *p++;
+ if (vy < 0 || vy >= VIEW_H) { /* skip the row */
+ while (n--) p += 2 + p[1];
+ continue;
+ }
+ uint8_t *row = FB(0, vy);
+ int at = 0;
+ while (n--) {
+ at += p[0];
+ int len = p[1];
+ const uint8_t *px = p + 2;
+ p += 2 + len;
+ if (!fx) {
+ int dx = x + x0 + at, a = 0, b = len;
+ if (dx < 0) a = -dx;
+ if (dx + b > VIEW_W) b = VIEW_W - dx;
+ if (a < b) {
+ if (solid) memset(row + dx + a, col, b - a);
+ else memcpy(row + dx + a, px + a, b - a);
+ }
+ } else {
+ /* stored pixel x0 + at + i goes to x + fw - 1 - (x0 + at + i) */
+ int base = x + fw - 1 - x0 - at;
+ for (int i = 0; i < len; i++) {
+ int dx = base - i;
+ if ((unsigned)dx < VIEW_W) row[dx] = solid ? col : px[i];
+ }
+ }
+ at += len;
+ }
+ }
+}
+
+void draw_sprite(const uint8_t *spr, int x, int y, uint8_t flags) { blit_sprite(spr, x - g_camx, y - g_camy, flags); }
+
+/* scaled (sx, sy: 1/256, nearest), its origin (ox, oy, frame pixels) at world (x, y) */
+void draw_sprite_scaled(const uint8_t *s, int x, int y, int sx, int sy, int ox, int oy, uint8_t flags) {
+ if (sx == 256 && sy == 256) {
+ draw_sprite(s, x - ((flags & DF_FLIPX) ? s[0] - ox : ox), y - oy, flags);
+ return;
+ }
+ /* decode into a buffer, then sample it */
+ static uint8_t buf[64 * 64];
+ int fw = s[0], fh = s[1], x0 = s[2], y0 = s[3], w = s[4], h = s[5];
+ if (fw > 64 || fh > 64) return;
+ memset(buf, 0, (size_t)fw * fh);
+ const uint8_t *p = s + 6;
+ for (int r = 0; r < h; r++) {
+ int n = *p++, at = 0;
+ while (n--) {
+ at += p[0];
+ memcpy(buf + (y0 + r) * fw + x0 + at, p + 2, p[1]);
+ at += p[1];
+ p += 2 + p[1];
+ }
+ }
+ bool fx = flags & DF_FLIPX;
+ /* the destination box: frame pixel u lands at x + (u - ox) * sx / 256 */
+ int dx0 = x - g_camx + fdiv(-ox * sx, 256), dx1 = x - g_camx + fdiv((fw - ox) * sx + 255, 256);
+ int dy0 = y - g_camy + fdiv(-oy * sy, 256), dy1 = y - g_camy + fdiv((fh - oy) * sy + 255, 256);
+ if (fx) {
+ int a = x - g_camx - fdiv((fw - ox) * sx + 255, 256) + 1, b = x - g_camx - fdiv(-ox * sx, 256) + 1;
+ dx0 = a, dx1 = b;
+ }
+ for (int vy = imax(dy0, 0); vy < imin(dy1, VIEW_H); vy++) {
+ int v = oy + fdiv((vy - (y - g_camy)) * 256 + 128, sy);
+ if (v < 0 || v >= fh) continue;
+ uint8_t *row = FB(0, vy);
+ for (int vx = imax(dx0, 0); vx < imin(dx1, VIEW_W); vx++) {
+ int rel = vx - (x - g_camx);
+ if (fx) rel = -rel;
+ int u = ox + fdiv(rel * 256 + 128, sx);
+ if (u < 0 || u >= fw) continue;
+ uint8_t c = buf[v * fw + u];
+ if (c) row[vx] = (flags & DF_SOLID) ? g_draw_color : c;
+ }
+ }
+}
+
+/* a tile at view (x, y), clipped */
+static void blit_tile(const uint8_t *t, int x, int y, bool opaque) {
+ int a = 0, b = 8, r0 = 0, r1 = 8;
+ if (x < 0) a = -x;
+ if (x + 8 > VIEW_W) b = VIEW_W - x;
+ if (y < 0) r0 = -y;
+ if (y + 8 > VIEW_H) r1 = VIEW_H - y;
+ if (a >= b || r0 >= r1) return;
+ for (int r = r0; r < r1; r++) {
+ uint8_t *d = FB(x, y + r);
+ const uint8_t *s = t + r * 8;
+ if (opaque) memcpy(d + a, s + a, b - a);
+ else
+ for (int i = a; i < b; i++)
+ if (s[i]) d[i] = s[i];
+ }
+}
+
+void draw_tile(int tile, int x, int y) {
+ if (tile) blit_tile(tile_data(tile), x - g_camx, y - g_camy, g_tile_flags[tile] & 1);
+}
+
+void draw_rect_screen(int x, int y, int w, int h, uint8_t c) {
+ if (x < 0) w += x, x = 0;
+ if (y < -VIEW_Y) h += y + VIEW_Y, y = -VIEW_Y;
+ if (x + w > 320) w = 320 - x;
+ if (y + h > 240 - VIEW_Y) h = 240 - VIEW_Y - y;
+ if (w <= 0 || h <= 0) return;
+ for (int r = 0; r < h; r++) memset(FB(x, y + r), c, w);
+}
+void draw_rect(int x, int y, int w, int h, uint8_t c) {
+ x -= g_camx, y -= g_camy;
+ if (x < 0) w += x, x = 0;
+ if (y < 0) h += y, y = 0;
+ if (x + w > VIEW_W) w = VIEW_W - x;
+ if (y + h > VIEW_H) h = VIEW_H - y;
+ if (w <= 0 || h <= 0) return;
+ for (int r = 0; r < h; r++) memset(FB(x, y + r), c, w);
+}
+void draw_pixel(int x, int y, uint8_t c) {
+ x -= g_camx, y -= g_camy;
+ if ((unsigned)x < VIEW_W && (unsigned)y < VIEW_H) *FB(x, y) = c;
+}
+void draw_line(int x0, int y0, int x1, int y1, uint8_t c) {
+ 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;
+ int e2 = 2 * err;
+ if (e2 >= dy) err += dy, x0 += sx;
+ if (e2 <= dx) err += dx, y0 += sy;
+ }
+}
+void draw_circle_fill(int cx, int cy, int r, uint8_t c) {
+ for (int y = -r; y <= r; y++) {
+ int w = isqrt((int32_t)r * r - (int32_t)y * y);
+ draw_rect(cx - w, cy + y, 2 * w + 1, 1, c);
+ }
+}
+void draw_clear_screen(uint8_t c) { memset(g_fb, c, 320 * 240); }
+
+/* ---------------------------------------------------------------- the tile layers */
+/* the tiles at world cell (cx, cy): the current room's grid first, then the other's */
+static void cell(int cx, int cy, const uint8_t **fg, const uint8_t **bg) {
+ *fg = *bg = NULL;
+ for (int k = 0; k < 2; k++) {
+ Room *rm = &g_level.rooms[k ? g_level.slot ^ 1 : g_level.slot];
+ if (rm->index < 0) continue;
+ int x = cx - (rm->gx >> 3), y = cy - (rm->gy >> 3);
+ if ((unsigned)x >= (unsigned)rm->tw || (unsigned)y >= (unsigned)rm->th) continue;
+ const uint8_t *g = rm->grid + y * rm->tw + x;
+ int f = g[0], b = g[rm->tw * rm->th];
+ *fg = f ? rm->tiles[f] : NULL;
+ *bg = b ? rm->tiles[b] : NULL;
+ return;
+ }
+}
+
+/* is a tile (its data) without see-through pixels: the tile's flags, from its pointer */
+static bool opaque_tile(const uint8_t *t) {
+ for (int i = 0; i < 64; i++)
+ if (!t[i]) return false;
+ return true;
+}
+
+#define COLS 42
+static const uint8_t *row_fg[COLS], *row_bg[COLS];
+static uint8_t row_kind[COLS]; /* 0: an opaque fg tile, 1: an opaque bg tile, 2: the background shows */
+
+static void background_rows(int vy0, int vy1, int vx0, int vx1) {
+ /* the background's pixel at view (x, y): the composite at (x + ox) % 320, y + oy (clamped) */
+ int ox = fdiv((g_camx - g_bg_camx) * 21, 256), oy = fdiv((g_camy - g_bg_camy) * 15, 256);
+ ox = ((ox % 320) + 320) % 320;
+ for (int y = vy0; y < vy1; y++) {
+ int sy = iclamp(y + oy, 0, VIEW_H - 1);
+ const uint8_t *src = g_bg + sy * 320;
+ uint8_t *d = FB(0, y);
+ int x = vx0;
+ while (x < vx1) {
+ int sx = (x + ox) % 320, n = imin(vx1 - x, 320 - sx);
+ memcpy(d + x, src + sx, n);
+ x += n;
+ }
+ }
+}
+
+void draw_layers_back(void) {
+ int c0 = g_camx >> 3, r0 = g_camy >> 3, offx = g_camx & 7, offy = g_camy & 7;
+ for (int r = 0; r <= VIEW_H / 8 + 1; r++) {
+ int vy = r * 8 - offy;
+ if (vy >= VIEW_H) break;
+ for (int c = 0; c < COLS; c++) {
+ const uint8_t *f, *b;
+ cell(c0 + c, r0 + r, &f, &b);
+ row_fg[c] = f, row_bg[c] = b;
+ row_kind[c] = f && opaque_tile(f) ? 0 : b && opaque_tile(b) ? 1 : 2;
+ }
+ int y0 = imax(vy, 0), y1 = imin(vy + 8, VIEW_H);
+ /* the background behind cells that show it, in runs */
+ for (int c = 0; c < COLS;) {
+ if (row_kind[c] != 2) { c++; continue; }
+ int e = c;
+ while (e < COLS && row_kind[e] == 2) e++;
+ int x0 = imax(c * 8 - offx, 0), x1 = imin(e * 8 - offx, VIEW_W);
+ if (x0 < x1) {
+ if (g_bg) background_rows(y0, y1, x0, x1);
+ else
+ for (int y = y0; y < y1; y++) memset(FB(x0, y), 0, x1 - x0);
+ }
+ c = e;
+ }
+ for (int c = 0; c < COLS; c++) {
+ if (row_kind[c] == 0 || !row_bg[c]) continue;
+ blit_tile(row_bg[c], c * 8 - offx, vy, row_kind[c] == 1);
+ }
+ }
+}
+
+void draw_layer_fg(void) {
+ int c0 = g_camx >> 3, r0 = g_camy >> 3, offx = g_camx & 7, offy = g_camy & 7;
+ for (int r = 0; r <= VIEW_H / 8 + 1; r++) {
+ int vy = r * 8 - offy;
+ if (vy >= VIEW_H) break;
+ for (int c = 0; c < COLS; c++) {
+ const uint8_t *f, *b;
+ cell(c0 + c, r0 + r, &f, &b);
+ if (f) blit_tile(f, c * 8 - offx, vy, opaque_tile(f));
+ }
+ }
+}
+
+/* the rooms' decals: u8 bg count, u8 fg count, then u16 sprite, s16 x, s16 y (centre), u8 flags, u8 frames */
+void draw_decals(int fg) {
+ for (int k = 0; k < 2; k++) {
+ Room *rm = &g_level.rooms[k];
+ if (rm->index < 0) continue;
+ const uint8_t *d = HPTR(rm->rec + rm->rec[0] + 1 + 3 + 3 + 2 + 2 + 3 + 4 + 1 + 2 * (rm->ntiles + 1) + 2 + 3);
+ int n = d[fg], skip = fg ? d[0] : 0;
+ const uint8_t *p = d + 2 + 8 * skip;
+ for (int i = 0; i < n; i++, p += 8) {
+ int id = (int)R16(p), frames = p[7];
+ if (frames > 1) id += (int)(g_level.frame / 5 % (unsigned)frames); /* 12 a second */
+ const uint8_t *s = csprite(id);
+ int x = rm->x + S16(p + 2) - s[0] / 2, y = rm->y + S16(p + 4) - s[1] / 2;
+ if (x - g_camx >= VIEW_W || y - g_camy >= VIEW_H || x + s[0] - g_camx <= 0 || y + s[1] - g_camy <= 0) continue;
+ draw_sprite(s, x, y, p[6] & 3);
+ }
+ }
+}
+
+/* ---------------------------------------------------------------- text: a 5 x 7 font for now */
+static const uint8_t FONT[96][5] = {
+ {0,0,0,0,0},{0,0,95,0,0},{0,7,0,7,0},{20,127,20,127,20},{36,42,127,42,18},{35,19,8,100,98},{54,73,85,34,80},{0,5,3,0,0},
+ {0,28,34,65,0},{0,65,34,28,0},{20,8,62,8,20},{8,8,62,8,8},{0,80,48,0,0},{8,8,8,8,8},{0,96,96,0,0},{32,16,8,4,2},
+ {62,81,73,69,62},{0,66,127,64,0},{66,97,81,73,70},{33,65,69,75,49},{24,20,18,127,16},{39,69,69,69,57},{60,74,73,73,48},{1,113,9,5,3},
+ {54,73,73,73,54},{6,73,73,41,30},{0,54,54,0,0},{0,86,54,0,0},{8,20,34,65,0},{20,20,20,20,20},{0,65,34,20,8},{2,1,81,9,6},
+ {50,73,121,65,62},{126,17,17,17,126},{127,73,73,73,54},{62,65,65,65,34},{127,65,65,34,28},{127,73,73,73,65},{127,9,9,9,1},{62,65,73,73,122},
+ {127,8,8,8,127},{0,65,127,65,0},{32,64,65,63,1},{127,8,20,34,65},{127,64,64,64,64},{127,2,12,2,127},{127,4,8,16,127},{62,65,65,65,62},
+ {127,9,9,9,6},{62,65,81,33,94},{127,9,25,41,70},{70,73,73,73,49},{1,1,127,1,1},{63,64,64,64,63},{31,32,64,32,31},{63,64,56,64,63},
+ {99,20,8,20,99},{7,8,112,8,7},{97,81,73,69,67},{0,127,65,65,0},{2,4,8,16,32},{0,65,65,127,0},{4,2,1,2,4},{64,64,64,64,64},
+ {0,1,2,4,0},{32,84,84,84,120},{127,72,68,68,56},{56,68,68,68,32},{56,68,68,72,127},{56,84,84,84,24},{8,126,9,1,2},{12,82,82,82,62},
+ {127,8,4,4,120},{0,68,125,64,0},{32,64,68,61,0},{127,16,40,68,0},{0,65,127,64,0},{124,4,24,4,120},{124,8,4,4,120},{56,68,68,68,56},
+ {124,20,20,20,8},{8,20,20,24,124},{124,8,4,4,8},{72,84,84,84,32},{4,63,68,64,32},{60,64,64,32,124},{28,32,64,32,28},{60,64,48,64,60},
+ {68,40,16,40,68},{12,80,80,80,60},{68,100,84,76,68},{0,8,54,65,0},{0,0,127,0,0},{0,65,54,8,0},{16,8,8,16,8},{0,0,0,0,0}};
+int text_width(const char *s) { return (int)strlen(s) * 6; }
+void draw_text(const char *s, int x, int y, uint8_t c) {
+ for (; *s; s++, x += 6) {
+ int ch = (uint8_t)*s - 32;
+ if (ch < 0 || ch >= 96) continue;
+ for (int i = 0; i < 5; i++) {
+ int bits = FONT[ch][i], sx = x + i;
+ if ((unsigned)sx >= 320) continue;
+ for (int j = 0; j < 7; j++)
+ if (bits >> j & 1 && (unsigned)(y + j) < 240) g_fb[(y + j) * 320 + sx] = c;
+ }
+ }
+}
diff --git a/games/celeste/ce/src/gen.h b/games/celeste/ce/src/gen.h
new file mode 100644
index 00000000..fbea74dd
--- /dev/null
+++ b/games/celeste/ce/src/gen.h
@@ -0,0 +1,547 @@
+/* Generated by tools/pack_ce.py: the ids of the appvars' contents. */
+#ifndef GEN_H
+#define GEN_H
+#define S_characters_player_idle00 0
+#define S_characters_player_idle01 1
+#define S_characters_player_idle02 2
+#define S_characters_player_idle03 3
+#define S_characters_player_idle04 4
+#define S_characters_player_idle05 5
+#define S_characters_player_idle06 6
+#define S_characters_player_idle07 7
+#define S_characters_player_idle08 8
+#define S_characters_player_idleA00 9
+#define S_characters_player_idleA01 10
+#define S_characters_player_idleA02 11
+#define S_characters_player_idleA03 12
+#define S_characters_player_idleA04 13
+#define S_characters_player_idleA05 14
+#define S_characters_player_idleA06 15
+#define S_characters_player_idleA07 16
+#define S_characters_player_idleA08 17
+#define S_characters_player_idleA09 18
+#define S_characters_player_idleA10 19
+#define S_characters_player_idleA11 20
+#define S_characters_player_idleB00 21
+#define S_characters_player_idleB01 22
+#define S_characters_player_idleB02 23
+#define S_characters_player_idleB03 24
+#define S_characters_player_idleB04 25
+#define S_characters_player_idleB05 26
+#define S_characters_player_idleB06 27
+#define S_characters_player_idleB07 28
+#define S_characters_player_idleB08 29
+#define S_characters_player_idleB09 30
+#define S_characters_player_idleB10 31
+#define S_characters_player_idleB11 32
+#define S_characters_player_idleB12 33
+#define S_characters_player_idleB13 34
+#define S_characters_player_idleB14 35
+#define S_characters_player_idleB15 36
+#define S_characters_player_idleB16 37
+#define S_characters_player_idleB17 38
+#define S_characters_player_idleB18 39
+#define S_characters_player_idleB19 40
+#define S_characters_player_idleB20 41
+#define S_characters_player_idleB21 42
+#define S_characters_player_idleB22 43
+#define S_characters_player_idleB23 44
+#define S_characters_player_idleC00 45
+#define S_characters_player_idleC01 46
+#define S_characters_player_idleC02 47
+#define S_characters_player_idleC03 48
+#define S_characters_player_idleC04 49
+#define S_characters_player_idleC05 50
+#define S_characters_player_idleC06 51
+#define S_characters_player_idleC07 52
+#define S_characters_player_idleC08 53
+#define S_characters_player_idleC09 54
+#define S_characters_player_idleC10 55
+#define S_characters_player_idleC11 56
+#define S_characters_player_lookUp02 57
+#define S_characters_player_lookUp03 58
+#define S_characters_player_lookUp04 59
+#define S_characters_player_lookUp05 60
+#define S_characters_player_lookUp06 61
+#define S_characters_player_lookUp07 62
+#define S_characters_player_walk00 63
+#define S_characters_player_walk01 64
+#define S_characters_player_walk02 65
+#define S_characters_player_walk03 66
+#define S_characters_player_walk04 67
+#define S_characters_player_walk05 68
+#define S_characters_player_walk06 69
+#define S_characters_player_walk07 70
+#define S_characters_player_walk08 71
+#define S_characters_player_walk09 72
+#define S_characters_player_walk10 73
+#define S_characters_player_walk11 74
+#define S_characters_player_push00 75
+#define S_characters_player_push01 76
+#define S_characters_player_push02 77
+#define S_characters_player_push03 78
+#define S_characters_player_push04 79
+#define S_characters_player_push05 80
+#define S_characters_player_push06 81
+#define S_characters_player_push07 82
+#define S_characters_player_push08 83
+#define S_characters_player_push09 84
+#define S_characters_player_push10 85
+#define S_characters_player_push11 86
+#define S_characters_player_push12 87
+#define S_characters_player_push13 88
+#define S_characters_player_push14 89
+#define S_characters_player_push15 90
+#define S_characters_player_runSlow00 91
+#define S_characters_player_runSlow01 92
+#define S_characters_player_runSlow02 93
+#define S_characters_player_runSlow03 94
+#define S_characters_player_runSlow04 95
+#define S_characters_player_runSlow05 96
+#define S_characters_player_runSlow06 97
+#define S_characters_player_runSlow07 98
+#define S_characters_player_runSlow08 99
+#define S_characters_player_runSlow09 100
+#define S_characters_player_runSlow10 101
+#define S_characters_player_runSlow11 102
+#define S_characters_player_runFast00 103
+#define S_characters_player_runFast01 104
+#define S_characters_player_runFast02 105
+#define S_characters_player_runFast03 106
+#define S_characters_player_runFast04 107
+#define S_characters_player_runFast05 108
+#define S_characters_player_runFast06 109
+#define S_characters_player_runFast07 110
+#define S_characters_player_runFast08 111
+#define S_characters_player_runFast09 112
+#define S_characters_player_runFast10 113
+#define S_characters_player_runFast11 114
+#define S_characters_player_runStumble10 115
+#define S_characters_player_runStumble11 116
+#define S_characters_player_runStumble00 117
+#define S_characters_player_runStumble01 118
+#define S_characters_player_runStumble02 119
+#define S_characters_player_runStumble03 120
+#define S_characters_player_runStumble04 121
+#define S_characters_player_runStumble05 122
+#define S_characters_player_runStumble06 123
+#define S_characters_player_runStumble07 124
+#define S_characters_player_runStumble08 125
+#define S_characters_player_runStumble09 126
+#define S_characters_player_dash00 127
+#define S_characters_player_dash01 128
+#define S_characters_player_dash02 129
+#define S_characters_player_dash03 130
+#define S_characters_player_slide00 131
+#define S_characters_player_slide01 132
+#define S_characters_player_slide02 133
+#define S_characters_player_jumpSlow00 134
+#define S_characters_player_jumpSlow01 135
+#define S_characters_player_jumpFast00 136
+#define S_characters_player_jumpFast01 137
+#define S_characters_player_jumpSlow02 138
+#define S_characters_player_jumpSlow03 139
+#define S_characters_player_jumpFast02 140
+#define S_characters_player_jumpFast03 141
+#define S_characters_player_tired00 142
+#define S_characters_player_tired01 143
+#define S_characters_player_tired02 144
+#define S_characters_player_tired03 145
+#define S_characters_player_climb00 146
+#define S_characters_player_climb06 147
+#define S_characters_player_climb07 148
+#define S_characters_player_climb08 149
+#define S_characters_player_climb01 150
+#define S_characters_player_climb02 151
+#define S_characters_player_climb03 152
+#define S_characters_player_climb04 153
+#define S_characters_player_climb05 154
+#define S_characters_player_duck 155
+#define S_characters_player_fallPose00 156
+#define S_characters_player_fallPose01 157
+#define S_characters_player_fallPose02 158
+#define S_characters_player_fallPose03 159
+#define S_characters_player_fallPose04 160
+#define S_characters_player_fallPose05 161
+#define S_characters_player_fallPose06 162
+#define S_characters_player_fallPose07 163
+#define S_characters_player_fallPose08 164
+#define S_characters_player_fallPose09 165
+#define S_characters_player_fallPose10 166
+#define S_characters_player_edge00 167
+#define S_characters_player_edge01 168
+#define S_characters_player_edge02 169
+#define S_characters_player_edge03 170
+#define S_characters_player_edge04 171
+#define S_characters_player_edge05 172
+#define S_characters_player_edge06 173
+#define S_characters_player_edge07 174
+#define S_characters_player_edge08 175
+#define S_characters_player_edge09 176
+#define S_characters_player_edge10 177
+#define S_characters_player_edge11 178
+#define S_characters_player_edge12 179
+#define S_characters_player_edge13 180
+#define S_characters_player_edge_back00 181
+#define S_characters_player_edge_back01 182
+#define S_characters_player_edge_back02 183
+#define S_characters_player_edge_back03 184
+#define S_characters_player_edge_back04 185
+#define S_characters_player_edge_back05 186
+#define S_characters_player_edge_back06 187
+#define S_characters_player_edge_back07 188
+#define S_characters_player_edge_back08 189
+#define S_characters_player_edge_back09 190
+#define S_characters_player_edge_back10 191
+#define S_characters_player_edge_back11 192
+#define S_characters_player_edge_back12 193
+#define S_characters_player_edge_back13 194
+#define S_characters_player_flip00 195
+#define S_characters_player_flip01 196
+#define S_characters_player_flip02 197
+#define S_characters_player_flip03 198
+#define S_characters_player_flip04 199
+#define S_characters_player_flip05 200
+#define S_characters_player_flip06 201
+#define S_characters_player_flip07 202
+#define S_characters_player_flip08 203
+#define S_characters_player_dangling00 204
+#define S_characters_player_dangling01 205
+#define S_characters_player_dangling02 206
+#define S_characters_player_dangling03 207
+#define S_characters_player_dangling04 208
+#define S_characters_player_dangling05 209
+#define S_characters_player_dangling06 210
+#define S_characters_player_dangling07 211
+#define S_characters_player_dangling08 212
+#define S_characters_player_dangling09 213
+#define S_characters_player_death_h00 214
+#define S_characters_player_death_h01 215
+#define S_characters_player_death_h02 216
+#define S_characters_player_death_h03 217
+#define S_characters_player_death_h04 218
+#define S_characters_player_death_h05 219
+#define S_characters_player_death_h06 220
+#define S_characters_player_death_h07 221
+#define S_characters_player_death_h08 222
+#define S_characters_player_death_h09 223
+#define S_characters_player_death_h10 224
+#define S_characters_player_death_h11 225
+#define S_characters_player_death_h12 226
+#define S_characters_player_fall00 227
+#define S_characters_player_fall01 228
+#define S_characters_player_fall02 229
+#define S_characters_player_fall03 230
+#define S_characters_player_fall04 231
+#define S_characters_player_fall05 232
+#define S_characters_player_fall06 233
+#define S_characters_player_fall07 234
+#define S_characters_player_bigfall00 235
+#define S_characters_player_bigfall01 236
+#define S_characters_player_bigfall02 237
+#define S_characters_player_bigfall03 238
+#define S_characters_player_bigfall04 239
+#define S_characters_player_wakeUp_00 240
+#define S_characters_player_wakeUp_01 241
+#define S_characters_player_wakeUp_02 242
+#define S_characters_player_wakeUp_03 243
+#define S_characters_player_wakeUp_04 244
+#define S_characters_player_wakeUp_05 245
+#define S_characters_player_wakeUp_06 246
+#define S_characters_player_wakeUp_07 247
+#define S_characters_player_wakeUp_08 248
+#define S_characters_player_wakeUp_09 249
+#define S_characters_player_wakeUp_10 250
+#define S_characters_player_wakeUp_11 251
+#define S_characters_player_wakeUp_12 252
+#define S_characters_player_wakeUp_13 253
+#define S_characters_player_wakeUp_14 254
+#define S_characters_player_spin00 255
+#define S_characters_player_spin01 256
+#define S_characters_player_spin02 257
+#define S_characters_player_spin03 258
+#define S_characters_player_spin04 259
+#define S_characters_player_spin05 260
+#define S_characters_player_spin06 261
+#define S_characters_player_spin07 262
+#define S_characters_player_spin08 263
+#define S_characters_player_spin09 264
+#define S_characters_player_spin10 265
+#define S_characters_player_spin11 266
+#define S_characters_player_spin12 267
+#define S_characters_player_spin13 268
+#define S_characters_player_sitDown00 269
+#define S_characters_player_sitDown01 270
+#define S_characters_player_sitDown02 271
+#define S_characters_player_sitDown03 272
+#define S_characters_player_sitDown04 273
+#define S_characters_player_sitDown05 274
+#define S_characters_player_sitDown06 275
+#define S_characters_player_sitDown07 276
+#define S_characters_player_sitDown08 277
+#define S_characters_player_sitDown09 278
+#define S_characters_player_sitDown10 279
+#define S_characters_player_sitDown11 280
+#define S_characters_player_sitDown12 281
+#define S_characters_player_sitDown13 282
+#define S_characters_player_sitDown14 283
+#define S_characters_player_sitDown15 284
+#define S_characters_player_launch00 285
+#define S_characters_player_launch01 286
+#define S_characters_player_launch02 287
+#define S_characters_player_launch03 288
+#define S_characters_player_launch04 289
+#define S_characters_player_launch05 290
+#define S_characters_player_launch06 291
+#define S_characters_player_launch07 292
+#define S_characters_player_launchRecover00 293
+#define S_characters_player_launchRecover01 294
+#define S_characters_player_launchRecover02 295
+#define S_characters_player_launchRecover03 296
+#define S_characters_player_launchRecover04 297
+#define S_characters_player_launchRecover05 298
+#define S_characters_player_launchRecover06 299
+#define S_characters_player_launchRecover07 300
+#define S_characters_player_launchRecover08 301
+#define S_characters_player_launchRecover09 302
+#define S_characters_player_launchRecover10 303
+#define S_characters_player_hair00 304
+#define S_characters_player_bangs00 305
+#define S_characters_player_bangs01 306
+#define S_characters_player_bangs02 307
+#define S_collectables_strawberry_normal00 308
+#define S_collectables_strawberry_normal01 309
+#define S_collectables_strawberry_normal02 310
+#define S_collectables_strawberry_normal03 311
+#define S_collectables_strawberry_normal04 312
+#define S_collectables_strawberry_normal05 313
+#define S_collectables_strawberry_normal06 314
+#define S_collectables_strawberry_normal07 315
+#define S_collectables_strawberry_normal08 316
+#define S_collectables_strawberry_normal09 317
+#define S_collectables_strawberry_normal10 318
+#define S_collectables_strawberry_normal11 319
+#define S_collectables_strawberry_wings00 320
+#define S_collectables_strawberry_wings01 321
+#define S_collectables_strawberry_wings02 322
+#define S_collectables_strawberry_wings03 323
+#define S_collectables_strawberry_wings04 324
+#define S_collectables_strawberry_wings05 325
+#define S_collectables_strawberry_wings06 326
+#define S_collectables_strawberry_wings07 327
+#define S_collectables_strawberry_wings08 328
+#define S_collectables_strawberry_wings09 329
+#define S_collectables_strawberry_normal12 330
+#define S_collectables_strawberry_normal13 331
+#define S_collectables_strawberry_normal14 332
+#define S_collectables_strawberry_normal15 333
+#define S_collectables_strawberry_normal16 334
+#define S_collectables_strawberry_normal17 335
+#define S_collectables_strawberry_normal18 336
+#define S_collectables_strawberry_normal19 337
+#define S_collectables_strawberry_normal20 338
+#define S_collectables_strawberry_normal21 339
+#define S_collectables_strawberry_normal22 340
+#define S_collectables_strawberry_normal23 341
+#define S_collectables_strawberry_normal24 342
+#define S_collectables_strawberry_normal25 343
+#define S_collectables_strawberry_normal26 344
+#define S_collectables_strawberry_normal28 345
+#define S_collectables_strawberry_normal29 346
+#define S_collectables_strawberry_normal30 347
+#define S_collectables_strawberry_normal31 348
+#define S_collectables_strawberry_normal32 349
+#define S_collectables_strawberry_normal33 350
+#define S_collectables_strawberry_normal34 351
+#define S_collectables_strawberry_normal36 352
+#define S_collectables_strawberry_normal37 353
+#define S_collectables_strawberry_normal38 354
+#define S_collectables_strawberry_normal39 355
+#define S_collectables_strawberry_normal40 356
+#define S_collectables_strawberry_normal41 357
+#define S_collectables_strawberry_normal42 358
+#define S_collectables_strawberry_normal44 359
+#define S_collectables_strawberry_normal45 360
+#define S_collectables_strawberry_normal46 361
+#define S_collectables_strawberry_normal47 362
+#define S_collectables_strawberry_normal48 363
+#define S_collectables_strawberry_normal49 364
+#define S_collectables_strawberry_normal50 365
+#define S_collectables_strawberry_normal52 366
+#define S_collectables_strawberry_normal53 367
+#define S_collectables_strawberry_normal54 368
+#define S_collectables_strawberry_normal55 369
+#define S_collectables_strawberry_normal56 370
+#define S_collectables_strawberry_normal57 371
+#define S_collectables_strawberry_normal58 372
+#define S_collectables_strawberry_normal59 373
+#define S_collectables_ghostberry_idle00 374
+#define S_collectables_ghostberry_idle01 375
+#define S_collectables_ghostberry_idle02 376
+#define S_collectables_ghostberry_idle03 377
+#define S_collectables_ghostberry_idle04 378
+#define S_collectables_ghostberry_idle05 379
+#define S_collectables_ghostberry_idle06 380
+#define S_collectables_ghostberry_idle07 381
+#define S_collectables_ghostberry_idle08 382
+#define S_collectables_ghostberry_idle09 383
+#define S_collectables_ghostberry_idle10 384
+#define S_collectables_ghostberry_idle11 385
+#define S_collectables_ghostberry_wings00 386
+#define S_collectables_ghostberry_wings01 387
+#define S_collectables_ghostberry_wings02 388
+#define S_collectables_ghostberry_wings03 389
+#define S_collectables_ghostberry_wings04 390
+#define S_collectables_ghostberry_wings05 391
+#define S_collectables_ghostberry_wings06 392
+#define S_collectables_ghostberry_wings07 393
+#define S_collectables_ghostberry_wings08 394
+#define S_collectables_ghostberry_wings09 395
+#define S_collectables_goldberry_idle00 396
+#define S_collectables_goldberry_idle01 397
+#define S_collectables_goldberry_idle02 398
+#define S_collectables_goldberry_idle03 399
+#define S_collectables_goldberry_idle04 400
+#define S_collectables_goldberry_idle05 401
+#define S_collectables_goldberry_idle06 402
+#define S_collectables_goldberry_idle07 403
+#define S_collectables_goldberry_idle08 404
+#define S_collectables_goldberry_idle09 405
+#define S_collectables_goldberry_idle10 406
+#define S_collectables_goldberry_idle11 407
+#define S_collectables_goldberry_wings00 408
+#define S_collectables_goldberry_wings01 409
+#define S_collectables_goldberry_wings02 410
+#define S_collectables_goldberry_wings03 411
+#define S_collectables_goldberry_wings04 412
+#define S_collectables_goldberry_wings05 413
+#define S_collectables_goldberry_wings06 414
+#define S_collectables_goldberry_wings07 415
+#define S_collectables_goldberry_wings08 416
+#define S_collectables_goldberry_wings09 417
+#define S_collectables_strawberry_seed00 418
+#define S_collectables_strawberry_seed01 419
+#define S_objects_refill_idle00 420
+#define S_objects_refill_idle01 421
+#define S_objects_refill_idle02 422
+#define S_objects_refill_idle03 423
+#define S_objects_refill_idle04 424
+#define S_objects_refill_flash00 425
+#define S_objects_refill_flash01 426
+#define S_objects_refill_flash02 427
+#define S_objects_refill_flash03 428
+#define S_objects_refill_flash04 429
+#define S_objects_refill_flash05 430
+#define S_objects_refill_outline 431
+#define S_objects_spring_00 432
+#define S_objects_spring_01 433
+#define S_objects_spring_02 434
+#define S_objects_spring_03 435
+#define S_objects_spring_04 436
+#define S_objects_spring_05 437
+#define B_player 0
+#define B_strawberry 1
+#define B_ghostberry 2
+#define B_goldberry 3
+#define B_strawberrySeed 4
+#define A_player_idle 0
+#define A_player_idleA 1
+#define A_player_idleB 2
+#define A_player_idleC 3
+#define A_player_lookUp 4
+#define A_player_walk 5
+#define A_player_push 6
+#define A_player_runSlow 7
+#define A_player_runFast 8
+#define A_player_runStumble 9
+#define A_player_dash 10
+#define A_player_slide 11
+#define A_player_jumpSlow 12
+#define A_player_jumpFast 13
+#define A_player_fallSlow 14
+#define A_player_fallFast 15
+#define A_player_tired 16
+#define A_player_tiredStill 17
+#define A_player_wallslide 18
+#define A_player_climbLookBackStart 19
+#define A_player_climbLookBack 20
+#define A_player_climbup 21
+#define A_player_duck 22
+#define A_player_fallPose 23
+#define A_player_edge 24
+#define A_player_edgeBack 25
+#define A_player_flip 26
+#define A_player_skid 27
+#define A_player_dangling 28
+#define A_player_deadside 29
+#define A_player_deadup 30
+#define A_player_deaddown 31
+#define A_player_fall 32
+#define A_player_bigFall 33
+#define A_player_asleep 34
+#define A_player_wakeUp 35
+#define A_player_spin 36
+#define A_player_sitDown 37
+#define A_player_launch 38
+#define A_player_launchRecover 39
+#define A_strawberry_idle 40
+#define A_strawberry_noFlash 41
+#define A_strawberry_collect 42
+#define A_strawberry_flap 43
+#define A_strawberry_fade0 44
+#define A_strawberry_fade1 45
+#define A_strawberry_fade2 46
+#define A_strawberry_fade3 47
+#define A_strawberry_fade4 48
+#define A_strawberry_fade5 49
+#define A_ghostberry_idle 50
+#define A_ghostberry_collect 51
+#define A_ghostberry_flap 52
+#define A_goldberry_idle 53
+#define A_goldberry_collect 54
+#define A_goldberry_flap 55
+#define A_strawberrySeed_idle 56
+#define A_strawberrySeed_noFlash 57
+/* banks' origins: mode (0 none, 1 pixels, 2 justify x256), x, y */
+#define BANK_ORIGINS {{1, 16, 32}, {2, 128, 128}, {2, 128, 128}, {2, 128, 128}, {2, 128, 128}}
+#define NBANKS 5
+#define COMMON 96
+#define ET_player 0
+#define ET_spikesUp 1
+#define ET_spikesDown 2
+#define ET_spikesLeft 3
+#define ET_spikesRight 4
+#define ET_jumpThru 5
+#define ET_zipMover 6
+#define ET_strawberry 7
+#define ET_goldenBerry 8
+#define ET_crumbleBlock 9
+#define ET_refill 10
+#define ET_spring 11
+#define ET_wallSpringLeft 12
+#define ET_wallSpringRight 13
+#define ET_cassetteBlock 14
+#define ET_fallingBlock 15
+#define ET_flutterbird 16
+#define ET_fakeWall 17
+#define ET_dashBlock 18
+#define ET_lightbeam 19
+#define ET_checkpoint 20
+#define ET_bonfire 21
+#define ET_cassette 22
+#define ET_npc 23
+#define ET_coverupWall 24
+#define ET_memorial 25
+#define ET_memorialTextController 26
+#define ET_birdForsakenCityGem 27
+#define ET_wire 28
+#define ET_blackGem 29
+#define TT_cameraOffsetTrigger 0
+#define TT_cameraTargetTrigger 1
+#define TT_changeRespawnTrigger 2
+#define TT_eventTrigger 3
+#define TT_goldenBerryCollectTrigger 4
+#define EV_end_city 0
+#define FORMAT 1
+#define MARGIN 4
+#endif
diff --git a/games/celeste/ce/src/level.c b/games/celeste/ce/src/level.c
new file mode 100644
index 00000000..238a3a22
--- /dev/null
+++ b/games/celeste/ce/src/level.c
@@ -0,0 +1,324 @@
+/* The level: a chapter's rooms (two at once during a transition), collisions with their tiles, the camera, the
+ * transitions between rooms, deaths and respawns (Celeste's Level and LevelLoader, after src/level.c). */
+#include "ce.h"
+
+Level g_level;
+#define GRID_BYTES 9000 /* a room's grids in RAM (the biggest of the chapters here, with a margin) */
+static uint8_t grid_mem[2][GRID_BYTES];
+static int pending_room = -1, pending_intro;
+
+/* a room record (tools/pack_ce.py Chapter.room) */
+typedef struct { const uint8_t *name; int nlen; const uint8_t *after; } RoomName;
+static const uint8_t *rec_after_name(const uint8_t *r) { return r + 1 + r[0]; }
+static int rec_x(const uint8_t *r) { return S24(rec_after_name(r)); }
+static int rec_y(const uint8_t *r) { return S24(rec_after_name(r) + 3); }
+static int rec_w(const uint8_t *r) { return (int)R16(rec_after_name(r) + 6); }
+static int rec_h(const uint8_t *r) { return (int)R16(rec_after_name(r) + 8); }
+
+int level_room_at(int x, int y) {
+ for (int i = 0; i < g_nrooms; i++) {
+ const uint8_t *r = room_rec(i);
+ int rx = rec_x(r), ry = rec_y(r);
+ if (x >= rx && y >= ry && x < rx + rec_w(r) && y < ry + rec_h(r)) return i;
+ }
+ return -1;
+}
+int level_room_find(const char *name) {
+ int n = (int)strlen(name);
+ for (int i = 0; i < g_nrooms; i++) {
+ const uint8_t *r = room_rec(i);
+ if (r[0] == n && !memcmp(r + 1, name, n)) return i;
+ }
+ return -1;
+}
+const char *level_room_name(void) {
+ static char buf[24];
+ const uint8_t *r = g_level.room->rec;
+ int n = imin(r[0], 23);
+ memcpy(buf, r + 1, n);
+ buf[n] = 0;
+ return buf;
+}
+
+static bool room_load(int slot, int index) {
+ Room *rm = &g_level.rooms[slot];
+ const uint8_t *r = room_rec(index), *p = rec_after_name(r);
+ rm->rec = r;
+ rm->x = S24(p), rm->y = S24(p + 3), rm->w = (int)R16(p + 6), rm->h = (int)R16(p + 8);
+ rm->flags = p[10], rm->camx = (int8_t)p[11], rm->camy = (int8_t)p[12];
+ rm->tw = (int)R16(p + 13), rm->th = (int)R16(p + 15);
+ rm->gx = rm->x - MARGIN * 8, rm->gy = rm->y - MARGIN * 8;
+ rm->rb = (rm->tw + 7) >> 3;
+ p += 17;
+ rm->ntiles = p[0];
+ for (int i = 0; i <= rm->ntiles; i++) {
+ int t = (int)R16(p + 1 + 2 * i);
+ rm->tiles[i] = t ? tile_data(t) : NULL;
+ }
+ p += 1 + 2 * (rm->ntiles + 1);
+ int raw = (int)R16(p);
+ if (raw > GRID_BYTES) return false;
+ rm->grid = grid_mem[slot];
+ plat_unpack(rm->grid, HPTR(p + 2));
+ rm->decals = HPTR(p + 5);
+ rm->ents = HPTR(p + 8);
+ rm->trigs = HPTR(p + 11);
+ rm->index = index;
+ return true;
+}
+
+/* ---------------------------------------------------------------- collisions with the tiles */
+static bool cell_solid(int cx, int cy) {
+ for (int k = 0; k < 2; k++) {
+ const Room *rm = &g_level.rooms[k ? g_level.slot ^ 1 : g_level.slot];
+ if (rm->index < 0) continue;
+ int x = cx - (rm->gx >> 3), y = cy - (rm->gy >> 3);
+ if ((unsigned)x >= (unsigned)rm->tw || (unsigned)y >= (unsigned)rm->th) continue;
+ return rm->grid[2 * rm->tw * rm->th + y * rm->rb + (x >> 3)] >> (x & 7) & 1;
+ }
+ return false;
+}
+/* Grid.Collide: [l, r) x [t, b) in pixels */
+bool tiles_solid(int l, int t, int r, int b) {
+ if (r <= l || b <= t) return false;
+ int cx0 = l >> 3, cy0 = t >> 3, cx1 = (r - 1) >> 3, cy1 = (b - 1) >> 3;
+ for (int cy = cy0; cy <= cy1; cy++)
+ for (int cx = cx0; cx <= cx1; cx++)
+ if (cell_solid(cx, cy)) return true;
+ return false;
+}
+Ent *solid_first(int l, int t, int r, int b, const Ent *self) {
+ for (int i = 0; i < g_nents; i++) {
+ Ent *o = &g_ents[i];
+ if (o != self && (o->flags & (EF_SOLID | EF_COLLIDABLE)) == (EF_SOLID | EF_COLLIDABLE) && o->type != 255 &&
+ rect_hits(l, t, r, b, o))
+ return o;
+ }
+ return NULL;
+}
+static Ent tiles_ent = {.type = 254, .flags = EF_SAFE | EF_SOLID | EF_COLLIDABLE}; /* SolidTiles */
+bool solid_at(int l, int t, int r, int b, const Ent *self) { return tiles_solid(l, t, r, b) || solid_first(l, t, r, b, self); }
+/* CollideFirst<Solid>: an entity, or the tiles' stand-in */
+Ent *solid_hit(int l, int t, int r, int b, const Ent *self) {
+ if (tiles_solid(l, t, r, b)) return &tiles_ent;
+ return solid_first(l, t, r, b, self);
+}
+/* CollideFirstOutside<JumpThru>: one e touches at (x, y) and not where it is */
+Ent *jumpthru_first_outside(const Ent *e, int x, int y) {
+ for (int i = 0; i < g_nents; i++) {
+ Ent *o = &g_ents[i];
+ if ((o->flags & (EF_JUMPTHRU | EF_COLLIDABLE)) == (EF_JUMPTHRU | EF_COLLIDABLE) && o != e &&
+ ent_collide_at(e, x, y, o) && !ent_collide_at(e, e->x, e->y, o))
+ return o;
+ }
+ return NULL;
+}
+
+/* ---------------------------------------------------------------- effects */
+void level_shake(int frames) { g_level.shake_timer = imax(g_level.shake_timer, frames), g_level.shake_dirx = g_level.shake_diry = 0; }
+void level_dir_shake(int dx, int dy, int frames) {
+ g_level.shake_timer = imax(g_level.shake_timer, frames);
+ g_level.shake_dirx = dx, g_level.shake_diry = dy;
+}
+void level_freeze(int frames) { g_level.freeze = imax(g_level.freeze, frames); }
+
+/* ---------------------------------------------------------------- loading */
+static int spawn_near(int x, int y) { /* the room's spawn nearest (x, y), as an index into its records */
+ const uint8_t *p = g_level.room->ents;
+ int n = p[0], best = -1;
+ int32_t bd = 0;
+ p++;
+ for (int i = 0; i < n; i++, p += p[1]) {
+ if (p[0] != ET_player) continue;
+ int sx = g_level.room->x + S16(p + 2), sy = g_level.room->y + S16(p + 4);
+ int32_t d = (int32_t)(sx - x) * (sx - x) + (int32_t)(sy - y) * (sy - y);
+ if (best < 0 || d < bd) best = i, bd = d, g_level.respawn_x = sx, g_level.respawn_y = sy;
+ }
+ return best;
+}
+
+static void load_into_current(int index, int intro) {
+ ents_clear();
+ g_level.rooms[0].index = g_level.rooms[1].index = -1;
+ g_level.slot = 0;
+ g_level.room = &g_level.rooms[0];
+ room_load(0, index);
+ Room *rm = g_level.room;
+ if (intro != INTRO_RESPAWN) spawn_near(rm->x, rm->y + rm->h);
+ ents_spawn_room(0);
+ player_spawn(g_level.respawn_x, g_level.respawn_y, intro);
+ g_level.cam_offx = rm->camx * 48, g_level.cam_offy = rm->camy * 32;
+ g_level.camx = player_cam_targetx() << 8, g_level.camy = player_cam_targety() << 8;
+ g_level.transitioning = false;
+ g_level.wipe = -24;
+}
+
+bool level_load(int chapter, int room, int intro) {
+ memset(&g_level, 0, sizeof g_level);
+ g_level.chapter = chapter;
+ g_level.rooms[0].index = g_level.rooms[1].index = -1;
+ if (room < 0) room = imax(level_room_at(0, 0), 0);
+ g_level.room = &g_level.rooms[0];
+ room_load(0, room);
+ spawn_near(g_level.room->x, g_level.room->y + g_level.room->h);
+ load_into_current(room, intro);
+ return true;
+}
+
+/* ---------------------------------------------------------------- transitions */
+static void transition_to(int index, int dx, int dy) {
+ int slot = g_level.slot ^ 1;
+ ents_remove_room(slot);
+ if (!room_load(slot, index)) return;
+ g_level.slot = slot;
+ g_level.room = &g_level.rooms[slot];
+ ents_spawn_room(slot);
+ Room *rm = g_level.room;
+ g_level.transitioning = true;
+ g_level.tr_dirx = dx, g_level.tr_diry = dy;
+ g_level.tr_t = 0;
+ g_level.tr_fromx = g_level.camx, g_level.tr_fromy = g_level.camy;
+ int padx = dx * 4, pady = dy * (dy > 0 ? 12 : 4);
+ Ent *pe = g_player.e;
+ int tx = pe->x, ty = pe->y;
+ if (dx != 0)
+ while (ty >= rm->y + rm->h) ty--;
+ for (int guard = 0; guard < 400; guard++) { /* IsInBounds(playerTo, dirPad) */
+ if (tx >= rm->x + imax(padx, 0) && ty >= rm->y + imax(pady, 0) && tx < rm->x + rm->w - imax(-padx, 0) &&
+ ty < rm->y + rm->h - imax(-pady, 0))
+ break;
+ tx += dx, ty += dy;
+ }
+ g_level.tr_px = tx, g_level.tr_py = ty;
+ int wx = pe->x, wy = pe->y;
+ pe->x = tx, pe->y = ty;
+ g_level.cam_offx = rm->camx * 48, g_level.cam_offy = rm->camy * 32;
+ g_level.tr_tox = player_cam_targetx() << 8, g_level.tr_toy = player_cam_targety() << 8;
+ pe->x = wx, pe->y = wy;
+}
+
+static int ease_cube_out(int t) { /* t, result: 0..256 */
+ int u = 256 - t;
+ return 256 - (int)((int32_t)u * u / 256 * u / 256);
+}
+static void transition_update(void) {
+ bool arrived = player_transition_to(g_level.tr_px, g_level.tr_py);
+ g_level.tr_t = imin(g_level.tr_t + DTU, TIM(0.65f));
+ int t = g_level.tr_t * 256 / TIM(0.65f);
+ if (t > 230) g_level.camx = g_level.tr_tox, g_level.camy = g_level.tr_toy;
+ else {
+ int e = ease_cube_out(t);
+ g_level.camx = g_level.tr_fromx + (int)((int32_t)(g_level.tr_tox - g_level.tr_fromx) * e / 256);
+ g_level.camy = g_level.tr_fromy + (int)((int32_t)(g_level.tr_toy - g_level.tr_fromy) * e / 256);
+ }
+ if (arrived && g_level.tr_t >= TIM(0.65f)) {
+ int old = g_level.slot ^ 1;
+ ents_remove_room(old);
+ g_level.rooms[old].index = -1;
+ spawn_near(g_player.e->x, g_player.e->y);
+ player_on_transition();
+ g_level.transitioning = false;
+ }
+}
+
+/* Level.EnforceBounds */
+static void enforce_bounds(void) {
+ Ent *e = g_player.e;
+ Room *rm = g_level.room;
+ int bl = rm->x, bt = rm->y, br = rm->x + rm->w, bb = rm->y + rm->h;
+ if (e_left(e) < bl) {
+ int next = level_room_at((e_left(e) + e_right(e)) / 2 - 8, (e_top(e) + e_bottom(e)) / 2);
+ if (e_top(e) >= bt && e_bottom(e) < bb && next >= 0 && next != rm->index) {
+ transition_to(next, -1, 0);
+ return;
+ }
+ e->x += bl - e_left(e);
+ g_player.sx = 0;
+ }
+ if (e_right(e) > br) {
+ int next = level_room_at((e_left(e) + e_right(e)) / 2 + 8, (e_top(e) + e_bottom(e)) / 2);
+ if (e_top(e) >= bt && e_bottom(e) < bb && next >= 0 && next != rm->index) {
+ transition_to(next, 1, 0);
+ return;
+ }
+ e->x += br - e_right(e);
+ g_player.sx = 0;
+ }
+ int cym = e->y + e->hy + e->hh / 2;
+ if (cym < bt) {
+ int next = level_room_at((e_left(e) + e_right(e)) / 2, cym - 12);
+ if (next >= 0 && next != rm->index) {
+ player_before_up_transition();
+ transition_to(next, 0, -1);
+ return;
+ }
+ if (e_top(e) < bt - 24) {
+ e->y += bt - 24 - e_top(e);
+ g_player.sy = 0;
+ }
+ }
+ if (e_bottom(e) > bb) {
+ int next = level_room_at((e_left(e) + e_right(e)) / 2, cym + 12);
+ if (next >= 0 && next != rm->index && !(rm->flags & 8)) {
+ if (!solid_at(e_left(e), e_top(e) + 4, e_right(e), e_bottom(e) + 4, e)) {
+ player_before_down_transition();
+ transition_to(next, 0, 1);
+ }
+ return;
+ }
+ }
+ if (e_top(e) > bb) player_die(0, 0);
+}
+
+/* ---------------------------------------------------------------- the frame */
+void level_update(void) {
+ if (g_level.freeze > 0) {
+ g_level.freeze--;
+ return;
+ }
+ g_level.frame++;
+ if (!g_level.completed) g_level.time++;
+ if (g_level.shake_timer > 0) { /* as many pixels as tenths of a second left, rounded up (every 0.04 s) */
+ if (g_level.frame % 2 == 0) {
+ int n = (g_level.shake_timer + 5) / 6;
+ if (!g_level.shake_dirx && !g_level.shake_diry)
+ g_level.shakex = rndn(n * 2 + 1) - n, g_level.shakey = rndn(n * 2 + 1) - n;
+ else {
+ g_level.last_dir_shake = (int8_t)(g_level.last_dir_shake ? -g_level.last_dir_shake : 1);
+ g_level.shakex = g_level.shake_dirx * -g_level.last_dir_shake * n;
+ g_level.shakey = g_level.shake_diry * -g_level.last_dir_shake * n;
+ }
+ }
+ g_level.shake_timer--;
+ } else
+ g_level.shakex = g_level.shakey = 0;
+ if (g_level.wipe < 0) g_level.wipe++;
+ else if (g_level.wipe > 0 && g_level.wipe < 24) g_level.wipe++;
+ if (g_level.transitioning) {
+ transition_update();
+ } else {
+ ents_update();
+ if (!g_player.dead && g_player.state != ST_INTRORESPAWN && !g_level.transitioning) enforce_bounds();
+ }
+ if (pending_room >= 0) {
+ int r = pending_room;
+ pending_room = -1;
+ load_into_current(r, pending_intro);
+ return;
+ }
+ if (g_level.dead_reload) {
+ g_level.dead_reload = false;
+ load_into_current(g_level.room->index, INTRO_RESPAWN);
+ }
+}
+
+void level_render(void) {
+ g_camx = (g_level.camx >> 8) + g_level.shakex;
+ g_camy = (g_level.camy >> 8) + g_level.shakey;
+ draw_layers_back();
+ draw_decals(0);
+ ents_render(32767, -10000);
+ draw_layer_fg();
+ draw_decals(1);
+ ents_render(-10000, -32768);
+}
diff --git a/games/celeste/ce/src/player.c b/games/celeste/ce/src/player.c
new file mode 100644
index 00000000..ed868940
--- /dev/null
+++ b/games/celeste/ce/src/player.c
@@ -0,0 +1,1299 @@
+/* Madeline: Player.cs (NoelFB/Celeste) as src/player.c ports it for the NumWorks, in whole numbers (ce.h): the same
+ * constants, states and order of operations. */
+#include "ce.h"
+
+Player g_player;
+#define P (&g_player)
+static Ent *E;
+
+/* Player.cs's constants in the CE's units */
+#define MaxFall SPD(160)
+#define Gravity 900 /* per frame */
+#define HalfGravThreshold SPD(40)
+#define FastMaxFall SPD(240)
+#define FastMaxAccel 300
+#define MaxRun SPD(90)
+#define RunAccel 1000
+#define RunReduce 400
+#define DuckFriction 500
+#define DuckCorrectCheck 4
+#define DuckCorrectSlide SPD(50)
+#define JumpGraceTime TIM(.1f)
+#define JumpSpeed SPD(-105)
+#define JumpHBoost SPD(40)
+#define VarJumpTime TIM(.2f)
+#define CeilingVarJumpGrace TIM(.05f)
+#define UpwardCornerCorrection 4
+#define WallSpeedRetentionTime TIM(.06f)
+#define WallJumpCheckDist 3
+#define WallJumpForceTime TIM(.16f)
+#define WallJumpHSpeed (MaxRun + JumpHBoost)
+#define WallSlideStartMax SPD(20)
+#define WallSlideTime TIM(1.2f)
+#define BounceVarJumpTime TIM(.2f)
+#define BounceSpeed SPD(-140)
+#define BounceAutoJumpTime TIM(.1f)
+#define SuperBounceVarJumpTime TIM(.2f)
+#define SuperBounceSpeed SPD(-185)
+#define SuperJumpH SPD(260)
+#define SuperWallJumpSpeed SPD(-160)
+#define SuperWallJumpVarTime TIM(.25f)
+#define SuperWallJumpH (MaxRun + JumpHBoost * 2)
+#define DashSpeed SPD(240)
+#define EndDashSpeed SPD(160)
+#define DashTime TIM(.15f)
+#define DashCooldown TIM(.2f)
+#define DashRefillCooldown TIM(.1f)
+#define DashHJumpThruNudge 6
+#define DashCornerCorrection 4
+#define DashVFloorSnapDist 3
+#define DashAttackTime TIM(.3f)
+#define STAM 3600 /* stamina: 3600ths */
+#define ClimbMaxStamina (110 * STAM)
+#define ClimbUpCost 2727 /* 100 / 2.2 a second, a frame */
+#define ClimbStillCost 600 /* 10 a second */
+#define ClimbJumpCost (110 * STAM / 4)
+#define ClimbTiredThreshold (20 * STAM)
+#define ClimbCheckDist 2
+#define ClimbUpCheckDist 2
+#define ClimbNoMoveTime TIM(.1f)
+#define ClimbUpSpeed SPD(-45)
+#define ClimbDownSpeed SPD(80)
+#define ClimbSlipSpeed SPD(30)
+#define ClimbAccel 900
+#define ClimbHopY SPD(-120)
+#define ClimbHopX SPD(100)
+#define ClimbHopForceTime TIM(.2f)
+#define ClimbJumpBoostTime TIM(.2f)
+#define LiftYCap SPD(-130)
+#define LiftXCap SPD(250)
+#define JumpThruAssistSpeed SPD(-40)
+#define D 181 /* 0.70710677 * 256 */
+
+#define NormalHairColor 0xAC3232
+#define UsedHairColor 0x44B7FF
+#define FlashHairColor 0xFFFFFF
+#define TwoDashesHairColor 0xFF6DEF
+
+/* hitboxes: w, h, x, y */
+static const int8_t HB_NORMAL[4] = {8, 11, -4, -11}, HB_DUCK[4] = {8, 6, -4, -6};
+static const int8_t HB_NORMAL_HURT[4] = {8, 9, -4, -11}, HB_DUCK_HURT[4] = {8, 4, -4, -6};
+
+static void set_box(const int8_t *b) { E->hw = b[0], E->hh = b[1], E->hx = b[2], E->hy = b[3]; }
+static bool box_is(const int8_t *b) { return E->hw == b[0] && E->hh == b[1] && E->hx == b[2] && E->hy == b[3]; }
+#define Ducking box_is(HB_DUCK)
+static void set_ducking(bool d) { set_box(d ? HB_DUCK : HB_NORMAL); }
+
+static bool solid_off(int dx, int dy) { return solid_at(e_left(E) + dx, e_top(E) + dy, e_right(E) + dx, e_bottom(E) + dy, E); }
+static Ent *solid_hit_off(int dx, int dy) {
+ extern Ent *solid_hit(int l, int t, int r, int b, const Ent *self);
+ return solid_hit(e_left(E) + dx, e_top(E) + dy, e_right(E) + dx, e_bottom(E) + dy, E);
+}
+static bool jumpthru_off(int dx, int dy) { return jumpthru_first_outside(E, E->x + dx, E->y + dy) != NULL; }
+static bool point_solid(int x, int y) { return solid_at(x, y, x + 1, y + 1, E); }
+
+/* ---------------------------------------------------------------- moving (Actor) */
+typedef void (*Collide)(int dx, int dy, Ent *hit);
+static bool move_h_exact(int move, Collide cb) {
+ int s = isign(move);
+ while (move) {
+ Ent *hit = solid_hit_off(s, 0);
+ if (hit) {
+ E->remx = 0;
+ if (cb) cb(s, 0, hit);
+ return true;
+ }
+ move -= s;
+ E->x += s;
+ }
+ return false;
+}
+static bool move_v_exact(int move, Collide cb) {
+ int s = isign(move);
+ while (move) {
+ Ent *hit = solid_hit_off(0, s);
+ if (!hit && move > 0) hit = jumpthru_first_outside(E, E->x, E->y + s);
+ if (hit) {
+ E->remy = 0;
+ if (cb) cb(0, s, hit);
+ return true;
+ }
+ move -= s;
+ E->y += s;
+ }
+ return false;
+}
+static bool move_h(int amount, Collide cb) {
+ E->remx += amount;
+ int n = round_mu(E->remx, amount);
+ if (!n) return false;
+ E->remx -= n * MU;
+ return move_h_exact(n, cb);
+}
+static bool move_v(int amount, Collide cb) {
+ E->remy += amount;
+ int n = round_mu(E->remy, amount);
+ if (!n) return false;
+ E->remy -= n * MU;
+ return move_v_exact(n, cb);
+}
+static bool on_ground_at(int x, int y) {
+ int ox = E->x, oy = E->y;
+ E->x = x, E->y = y;
+ bool r = solid_off(0, 1) || jumpthru_off(0, 1);
+ E->x = ox, E->y = oy;
+ return r;
+}
+
+/* lift speed: what the platform under her gives (kept 0.16 s after she leaves it) */
+static int liftx(void) { return E->liftx || E->lifty ? E->liftx : P->last_liftx; }
+static int lifty(void) { return E->liftx || E->lifty ? E->lifty : P->last_lifty; }
+static void lift_boost(int *x, int *y) {
+ int lx = liftx(), ly = lifty();
+ if (iabs(lx) > LiftXCap) lx = LiftXCap * isign(lx);
+ if (ly > 0) ly = 0;
+ else if (ly < LiftYCap) ly = LiftYCap;
+ *x = lx, *y = ly;
+}
+
+/* ---------------------------------------------------------------- the sprite */
+static void play(int a) {
+ if (P->anim == a) return;
+ P->anim = a, P->frame = 0, P->anim_timer = 0;
+}
+static void play_r(int a) { P->anim = -1, play(a); }
+static int cur_sprite(void) {
+ const uint8_t *an = anim(P->anim);
+ int f = imin(P->frame, an[0] - 1);
+ return (int)R16(an + 6 + 2 * f);
+}
+static void sprite_update(void) {
+ const uint8_t *an = anim(P->anim);
+ int delay = (int)R16(an + 2), n = an[0];
+ if (!delay) return;
+ P->anim_timer += DTU;
+ if (P->anim_timer < delay) return;
+ P->anim_timer -= delay;
+ if (P->frame + 1 < n) {
+ P->frame++;
+ return;
+ }
+ if (an[4] != 255) { /* goto */
+ int g = an[4];
+ if (g == A_player_idle && P->anim == A_player_idle && P->idle_timer > TIM(3) && rndn(5) == 0) {
+ int r = rndn(9); /* the idle's variants (Player.cs: idleA, B, C) */
+ g = r < 5 ? A_player_idleA : r < 8 ? A_player_idleB : A_player_idleC;
+ }
+ P->anim = -1, play(g);
+ } else if (an[1] & 1)
+ P->frame = 0;
+}
+
+/* ---------------------------------------------------------------- states */
+static bool in_control(void) {
+ return P->state != ST_INTROJUMP && P->state != ST_INTROWALK && P->state != ST_INTRORESPAWN && P->state != ST_DUMMY;
+}
+bool player_dash_attacking(void) { return P->dash_attack > 0; }
+static bool is_tired(void) { return (P->wall_boost_timer > 0 ? P->stamina + ClimbJumpCost : P->stamina) < ClimbTiredThreshold; }
+bool player_refill_dash(void) {
+ if (P->dashes < P->max_dashes) {
+ P->dashes = P->max_dashes;
+ return true;
+ }
+ return false;
+}
+bool player_use_refill(bool two) {
+ int max = two ? 2 : P->max_dashes;
+ if (P->dashes < max || P->stamina < ClimbTiredThreshold) {
+ P->dashes = max;
+ P->stamina = ClimbMaxStamina;
+ return true;
+ }
+ return false;
+}
+
+static bool can_unduck(void) {
+ if (!Ducking) return true;
+ set_box(HB_NORMAL);
+ bool ok = !solid_off(0, 0);
+ set_box(HB_DUCK);
+ return ok;
+}
+static bool can_unduck_at(int x, int y) {
+ int ox = E->x, oy = E->y;
+ E->x = x, E->y = y;
+ bool r = can_unduck();
+ E->x = ox, E->y = oy;
+ return r;
+}
+static bool duck_free_at(int x, int y) {
+ int ox = E->x, oy = E->y;
+ int8_t was[4] = {(int8_t)E->hw, (int8_t)E->hh, (int8_t)E->hx, (int8_t)E->hy};
+ E->x = x, E->y = y;
+ set_box(HB_DUCK);
+ bool r = !solid_off(0, 0);
+ E->x = ox, E->y = oy;
+ set_box(was);
+ return r;
+}
+
+static bool climb_bounds_check(int dir) {
+ Room *rm = g_level.room;
+ return e_left(E) + dir * ClimbCheckDist >= rm->x && e_right(E) + dir * ClimbCheckDist < rm->x + rm->w;
+}
+static bool climb_check(int dir, int yadd) { return climb_bounds_check(dir) && solid_off(dir * ClimbCheckDist, yadd); }
+static bool wall_jump_check(int dir) { return climb_bounds_check(dir) && solid_off(dir * WallJumpCheckDist, 0); }
+
+static void aim(int *x, int *y) { /* 1/256 */
+ int ax = g_in.aim_x, ay = g_in.aim_y;
+ if (!ax && !ay) *x = P->facing * 256, *y = 0;
+ else if (ax && ay) *x = ax * D, *y = ay * D;
+ else *x = ax * 256, *y = ay * 256;
+}
+
+static int normal_update(void), climb_update(void), dash_update(void);
+static void normal_begin(void), normal_end(void), climb_begin(void), climb_end(void), dash_begin(void), dash_end(void);
+static void respawn_begin(void), respawn_end(void);
+static int co_dash(void), co_intro_jump(void), co_intro_walk(void);
+typedef int (*UpdFn)(void);
+typedef void (*VFn)(void);
+static const UpdFn UPD[ST_COUNT] = {normal_update, climb_update, dash_update};
+static const VFn BEGIN[ST_COUNT] = {normal_begin, climb_begin, dash_begin, respawn_begin};
+static const VFn END[ST_COUNT] = {normal_end, climb_end, dash_end, respawn_end};
+static const UpdFn CO[ST_COUNT] = {NULL, NULL, co_dash, NULL, co_intro_jump, co_intro_walk};
+
+static void set_state(int st) {
+ if (P->state == st) return;
+ P->prev_state = P->state;
+ P->state = st;
+ if (P->prev_state >= 0 && END[P->prev_state]) END[P->prev_state]();
+ if (BEGIN[st]) BEGIN[st]();
+ P->co_active = CO[st] != NULL;
+ P->co_step = 0, P->co_wait = 0;
+}
+static void co_update(void) {
+ if (!P->co_active) return;
+ if (P->co_wait > 0) {
+ P->co_wait -= DTU;
+ return;
+ }
+ int st = P->state;
+ int r = CO[st]();
+ if (P->state != st || !P->co_active) return;
+ if (r < 0) P->co_active = false;
+ else P->co_wait = r;
+}
+
+/* ---------------------------------------------------------------- jumps */
+static void jump_common(int var_time) {
+ btn_consume(&g_in.jump), g_in.jump.pressed = true; /* (ConsumeBuffer: still Pressed this frame) */
+ P->jump_grace = 0;
+ P->var_jump = var_time;
+ P->auto_jump = false;
+ P->dash_attack = 0;
+ P->wall_slide_timer = WallSlideTime;
+ P->wall_boost_timer = 0;
+}
+static void jump(void) {
+ jump_common(VarJumpTime);
+ int lx, ly;
+ lift_boost(&lx, &ly);
+ P->sx += JumpHBoost * P->move_x + lx;
+ P->sy = JumpSpeed + ly;
+ P->var_jump_speed = P->sy;
+ P->scale_x = 614, P->scale_y = 1434;
+}
+static void super_jump(void) {
+ jump_common(VarJumpTime);
+ int lx, ly;
+ lift_boost(&lx, &ly);
+ P->sx = SuperJumpH * P->facing + lx;
+ P->sy = JumpSpeed + ly;
+ if (Ducking) {
+ set_ducking(false);
+ P->sx = P->sx * 5 / 4; /* DuckSuperJumpXMult */
+ P->sy /= 2; /* DuckSuperJumpYMult */
+ }
+ P->var_jump_speed = P->sy;
+ P->scale_x = 614, P->scale_y = 1434;
+}
+static void wall_jump(int dir) {
+ set_ducking(false);
+ jump_common(VarJumpTime);
+ if (P->move_x != 0) P->force_move_x = dir, P->force_move_x_timer = WallJumpForceTime;
+ int lx, ly;
+ lift_boost(&lx, &ly);
+ P->sx = WallJumpHSpeed * dir + lx;
+ P->sy = JumpSpeed + ly;
+ P->var_jump_speed = P->sy;
+ P->scale_x = 614, P->scale_y = 1434;
+}
+static void super_wall_jump(int dir) {
+ set_ducking(false);
+ jump_common(SuperWallJumpVarTime);
+ int lx, ly;
+ lift_boost(&lx, &ly);
+ P->sx = SuperWallJumpH * dir + lx;
+ P->sy = SuperWallJumpSpeed + ly;
+ P->var_jump_speed = P->sy;
+ P->scale_x = 614, P->scale_y = 1434;
+}
+static void climb_jump(void) {
+ if (!P->on_ground) P->stamina -= ClimbJumpCost;
+ jump();
+ if (P->move_x == 0) P->wall_boost_dir = -P->facing, P->wall_boost_timer = ClimbJumpBoostTime;
+}
+
+void player_bounce(int from_y) {
+ E = P->e;
+ int8_t was[4] = {(int8_t)E->hw, (int8_t)E->hh, (int8_t)E->hx, (int8_t)E->hy};
+ set_box(HB_NORMAL);
+ move_v_exact(from_y - e_bottom(E), NULL);
+ player_refill_dash();
+ P->stamina = ClimbMaxStamina;
+ set_state(ST_NORMAL);
+ P->jump_grace = 0;
+ P->var_jump = BounceVarJumpTime;
+ P->auto_jump = true;
+ P->auto_jump_timer = BounceAutoJumpTime;
+ P->dash_attack = 0;
+ P->wall_slide_timer = WallSlideTime;
+ P->wall_boost_timer = 0;
+ P->var_jump_speed = P->sy = BounceSpeed;
+ P->scale_x = 614, P->scale_y = 1434;
+ set_box(was);
+}
+void player_super_bounce(int from_y) {
+ E = P->e;
+ int8_t was[4] = {(int8_t)E->hw, (int8_t)E->hh, (int8_t)E->hx, (int8_t)E->hy};
+ set_box(HB_NORMAL);
+ move_v((from_y - e_bottom(E)) * MU, NULL);
+ player_refill_dash();
+ P->stamina = ClimbMaxStamina;
+ set_state(ST_NORMAL);
+ P->jump_grace = 0;
+ P->var_jump = SuperBounceVarJumpTime;
+ P->auto_jump = true;
+ P->auto_jump_timer = 0;
+ P->dash_attack = 0;
+ P->wall_slide_timer = WallSlideTime;
+ P->wall_boost_timer = 0;
+ P->sx = 0;
+ P->var_jump_speed = P->sy = SuperBounceSpeed;
+ level_dir_shake(0, -1, TIM(.1f) / DTU);
+ P->scale_x = 512, P->scale_y = 1536;
+ set_box(was);
+}
+void player_side_bounce(int dir, int from_x, int from_y) {
+ E = P->e;
+ int8_t was[4] = {(int8_t)E->hw, (int8_t)E->hh, (int8_t)E->hx, (int8_t)E->hy};
+ set_box(HB_NORMAL);
+ move_v(iclamp(from_y - e_bottom(E), -4, 4) * MU, NULL);
+ if (dir > 0) move_h((from_x - e_left(E)) * MU, NULL);
+ else if (dir < 0) move_h((from_x - e_right(E)) * MU, NULL);
+ player_refill_dash();
+ P->stamina = ClimbMaxStamina;
+ set_state(ST_NORMAL);
+ P->jump_grace = 0;
+ P->var_jump = BounceVarJumpTime;
+ P->auto_jump = true;
+ P->auto_jump_timer = 0;
+ P->dash_attack = 0;
+ P->wall_slide_timer = WallSlideTime;
+ P->force_move_x = dir;
+ P->force_move_x_timer = TIM(.3f);
+ P->wall_boost_timer = 0;
+ P->sx = SPD(240) * dir;
+ P->var_jump_speed = P->sy = BounceSpeed;
+ level_dir_shake(dir, 0, TIM(.1f) / DTU);
+ P->scale_x = 1536, P->scale_y = 512;
+ set_box(was);
+}
+
+/* ---------------------------------------------------------------- collisions */
+static void on_collide_h(int dx, int dy, Ent *hit) {
+ (void)dy, (void)hit;
+ if (P->state == ST_DASH) {
+ if (P->on_ground && duck_free_at(E->x + isign(P->sx), E->y)) {
+ set_ducking(true);
+ return;
+ } else if (P->sy == 0 && P->sx != 0) {
+ for (int i = 1; i <= DashCornerCorrection; i++)
+ for (int j = 1; j >= -1; j -= 2)
+ if (!solid_off(isign(P->sx), i * j)) {
+ move_v_exact(i * j, NULL);
+ move_h_exact(isign(P->sx), NULL);
+ return;
+ }
+ }
+ }
+ if (P->wall_speed_retention <= 0) {
+ P->wall_speed_retained = P->sx;
+ P->wall_speed_retention = WallSpeedRetentionTime;
+ }
+ P->sx = 0;
+ P->dash_attack = 0;
+ (void)dx;
+}
+static void on_collide_v(int dx, int dy, Ent *hit) {
+ (void)dx, (void)dy, (void)hit;
+ if (P->sy > 0) {
+ if (P->state == ST_DASH && !P->dash_started_on_ground) {
+ if (P->sx <= 0)
+ for (int i = -1; i >= -DashCornerCorrection; i--)
+ if (!on_ground_at(E->x + i, E->y)) {
+ move_h_exact(i, NULL);
+ move_v_exact(1, NULL);
+ return;
+ }
+ if (P->sx >= 0)
+ for (int i = 1; i <= DashCornerCorrection; i++)
+ if (!on_ground_at(E->x + i, E->y)) {
+ move_h_exact(i, NULL);
+ move_v_exact(1, NULL);
+ return;
+ }
+ }
+ if (P->dash_dx != 0 && P->dash_dy > 0 && P->sy > 0) { /* a diagonal dash into the floor: a slide */
+ P->dash_dx = isign(P->dash_dx) * 256;
+ P->dash_dy = 0;
+ P->sy = 0;
+ P->sx = P->sx * 6 / 5; /* DodgeSlideSpeedMult */
+ set_ducking(true);
+ }
+ if (P->state != ST_CLIMB) { /* a squash as she lands */
+ int sq = imin(P->sy * 256 / FastMaxFall, 256);
+ P->scale_x = 1024 + 614 * sq / 256;
+ P->scale_y = 1024 - 614 * sq / 256;
+ }
+ } else if (P->sy < 0) {
+ if (P->sx <= 0)
+ for (int i = 1; i <= UpwardCornerCorrection; i++)
+ if (!solid_off(-i, -1)) {
+ E->x -= i, E->y -= 1;
+ return;
+ }
+ if (P->sx >= 0)
+ for (int i = 1; i <= UpwardCornerCorrection; i++)
+ if (!solid_off(i, -1)) {
+ E->x += i, E->y -= 1;
+ return;
+ }
+ if (P->var_jump < VarJumpTime - CeilingVarJumpGrace) P->var_jump = 0;
+ }
+ P->dash_attack = 0;
+ P->sy = 0;
+}
+
+/* ---------------------------------------------------------------- normal */
+static void normal_begin(void) { P->max_fall = MaxFall; }
+static void normal_end(void) {
+ P->wall_boost_timer = 0;
+ P->wall_speed_retention = 0;
+ P->hop_wait_x = 0;
+}
+static bool can_dash(void) { return btn_pressed(&g_in.dash) && P->dash_cooldown <= 0 && P->dashes > 0; }
+static int start_dash(void) {
+ P->was_dash_b = P->dashes == 2;
+ P->dashes = imax(P->dashes - 1, 0);
+ btn_consume(&g_in.dash), g_in.dash.pressed = true;
+ return ST_DASH;
+}
+
+static int normal_update(void) {
+ int lx, ly;
+ lift_boost(&lx, &ly);
+ if (ly < 0 && P->was_on_ground && !P->on_ground && P->sy >= 0) P->sy = ly;
+ if (g_in.grab.check && !is_tired() && !Ducking) {
+ if (P->sy >= 0 && isign(P->sx) != -P->facing) {
+ if (climb_check(P->facing, 0)) {
+ set_ducking(false);
+ return ST_CLIMB;
+ }
+ if (g_in.move_y < 1)
+ for (int i = 1; i <= ClimbUpCheckDist; i++)
+ if (!solid_off(0, -i) && climb_check(P->facing, -i)) {
+ move_v_exact(-i, NULL);
+ set_ducking(false);
+ return ST_CLIMB;
+ }
+ }
+ }
+ if (can_dash()) {
+ P->sx += lx, P->sy += ly;
+ return start_dash();
+ }
+ if (Ducking) {
+ if (P->on_ground && g_in.move_y != 1) {
+ if (can_unduck()) {
+ set_ducking(false);
+ P->scale_x = 819, P->scale_y = 1229;
+ } else if (P->sx == 0) {
+ for (int i = DuckCorrectCheck; i > 0; i--) {
+ if (can_unduck_at(E->x + i, E->y)) {
+ move_h(DuckCorrectSlide, on_collide_h);
+ break;
+ } else if (can_unduck_at(E->x - i, E->y)) {
+ move_h(-DuckCorrectSlide, on_collide_h);
+ break;
+ }
+ }
+ }
+ }
+ } else if (P->on_ground && g_in.move_y == 1 && P->sy >= 0) {
+ set_ducking(true);
+ P->scale_x = 1434, P->scale_y = 614;
+ }
+ if (Ducking && P->on_ground) P->sx = approach(P->sx, 0, DuckFriction);
+ else {
+ bool g = P->on_ground;
+ if (iabs(P->sx) > MaxRun && isign(P->sx) == P->move_x)
+ P->sx = approach(P->sx, MaxRun * P->move_x, g ? RunReduce : RunReduce * 65 / 100);
+ else
+ P->sx = approach(P->sx, MaxRun * P->move_x, g ? RunAccel : RunAccel * 65 / 100);
+ }
+ if (g_in.move_y == 1 && P->sy >= MaxFall) {
+ P->max_fall = approach(P->max_fall, FastMaxFall, FastMaxAccel);
+ int half = MaxFall + (FastMaxFall - MaxFall) / 2;
+ if (P->sy >= half) {
+ int l = imin(256, (P->sy - half) * 256 / (FastMaxFall - half));
+ P->scale_x = 1024 - 512 * l / 256, P->scale_y = 1024 + 512 * l / 256;
+ }
+ } else
+ P->max_fall = approach(P->max_fall, MaxFall, FastMaxAccel);
+ if (!P->on_ground) {
+ int max = P->max_fall;
+ if ((P->move_x == P->facing || (P->move_x == 0 && g_in.grab.check)) && g_in.move_y != 1) {
+ if (P->sy >= 0 && P->wall_slide_timer > 0 && climb_bounds_check(P->facing) && solid_off(P->facing, 0) &&
+ can_unduck()) {
+ set_ducking(false);
+ P->wall_slide_dir = P->facing;
+ }
+ if (P->wall_slide_dir != 0) /* Lerp(MaxFall, WallSlideStartMax, timer / WallSlideTime) */
+ max = MaxFall + (int)((int32_t)(WallSlideStartMax - MaxFall) * P->wall_slide_timer / WallSlideTime);
+ }
+ bool half = iabs(P->sy) < HalfGravThreshold && (g_in.jump.check || P->auto_jump);
+ P->sy = approach(P->sy, max, half ? Gravity / 2 : Gravity);
+ }
+ if (P->var_jump > 0) {
+ if (P->auto_jump || g_in.jump.check) P->sy = imin(P->sy, P->var_jump_speed);
+ else P->var_jump = 0;
+ }
+ if (btn_pressed(&g_in.jump)) {
+ if (P->jump_grace > 0) jump();
+ else if (can_unduck()) {
+ if (wall_jump_check(1)) {
+ if (P->facing == 1 && g_in.grab.check && P->stamina > 0) climb_jump();
+ else if (player_dash_attacking() && P->dash_dx == 0 && P->dash_dy == -256) super_wall_jump(-1);
+ else wall_jump(-1);
+ } else if (wall_jump_check(-1)) {
+ if (P->facing == -1 && g_in.grab.check && P->stamina > 0) climb_jump();
+ else if (player_dash_attacking() && P->dash_dx == 0 && P->dash_dy == -256) super_wall_jump(1);
+ else wall_jump(1);
+ }
+ }
+ }
+ return ST_NORMAL;
+}
+
+/* ---------------------------------------------------------------- climb */
+static void climb_begin(void) {
+ P->auto_jump = false;
+ P->sx = 0;
+ P->sy /= 5; /* ClimbGrabYMult */
+ P->wall_slide_timer = WallSlideTime;
+ P->climb_no_move = ClimbNoMoveTime;
+ P->wall_boost_timer = 0;
+ P->last_climb_move = 0;
+ for (int i = 0; i < ClimbCheckDist; i++)
+ if (!solid_off(P->facing, 0)) E->x += P->facing;
+ else break;
+}
+static void climb_end(void) { P->wall_speed_retention = 0; }
+static void climb_hop(void) {
+ P->hop_wait_x = 0;
+ if (solid_off(P->facing, 0)) P->hop_wait_x = P->facing, P->hop_wait_x_speed = P->facing * ClimbHopX;
+ else P->sx = P->facing * ClimbHopX;
+ P->sy = imin(P->sy, ClimbHopY);
+ P->force_move_x = 0;
+ P->force_move_x_timer = ClimbHopForceTime;
+ P->fast_jump = false;
+}
+static bool slip_check(int add_y) {
+ int ax = P->facing == 1 ? e_right(E) : e_left(E) - 1, ay = e_top(E) + 4 + add_y;
+ return !point_solid(ax, ay) && !point_solid(ax, ay + (-4 + add_y));
+}
+static bool ledge_blocked(int x, int y) { /* spikes in the way of a hop (LedgeBlocker) */
+ for (int i = 0; i < g_nents; i++) {
+ Ent *o = &g_ents[i];
+ if (o->type <= ET_spikesRight && o->type >= ET_spikesUp && o->type != ET_spikesDown && (o->flags & EF_COLLIDABLE) &&
+ ent_collide_at(E, x, y, o))
+ return true;
+ }
+ return false;
+}
+static int climb_update(void) {
+ P->climb_no_move -= DTU;
+ if (P->on_ground) P->stamina = ClimbMaxStamina;
+ if (btn_pressed(&g_in.jump) && (!Ducking || can_unduck())) {
+ if (P->move_x == -P->facing) wall_jump(-P->facing);
+ else climb_jump();
+ return ST_NORMAL;
+ }
+ int lx, ly;
+ if (can_dash()) {
+ lift_boost(&lx, &ly);
+ P->sx += lx, P->sy += ly;
+ return start_dash();
+ }
+ if (!g_in.grab.check) {
+ lift_boost(&lx, &ly);
+ P->sx += lx, P->sy += ly;
+ return ST_NORMAL;
+ }
+ if (!solid_off(P->facing, 0)) {
+ if (P->sy < 0) climb_hop();
+ return ST_NORMAL;
+ }
+ int target = 0;
+ bool try_slip = false;
+ if (P->climb_no_move <= 0) {
+ if (g_in.move_y == -1) {
+ target = ClimbUpSpeed;
+ if (solid_off(0, -1) || ((ledge_blocked(E->x + P->facing * 8, E->y) || solid_off(0, -6)) && slip_check(-1))) {
+ if (P->sy < 0) P->sy = 0;
+ target = 0;
+ try_slip = true;
+ } else if (slip_check(0)) {
+ climb_hop();
+ return ST_NORMAL;
+ }
+ } else if (g_in.move_y == 1) {
+ target = ClimbDownSpeed;
+ if (P->on_ground) {
+ if (P->sy > 0) P->sy = 0;
+ target = 0;
+ }
+ } else
+ try_slip = true;
+ } else
+ try_slip = true;
+ P->last_climb_move = isign(target);
+ if (try_slip && slip_check(0)) target = ClimbSlipSpeed;
+ P->sy = approach(P->sy, target, ClimbAccel);
+ if (g_in.move_y != 1 && P->sy > 0 && !solid_off(P->facing, 1)) P->sy = 0;
+ if (P->climb_no_move <= 0) {
+ if (P->last_climb_move == -1) P->stamina -= ClimbUpCost;
+ else if (P->last_climb_move == 0) P->stamina -= ClimbStillCost;
+ }
+ if (P->stamina <= 0) {
+ lift_boost(&lx, &ly);
+ P->sx += lx, P->sy += ly;
+ return ST_NORMAL;
+ }
+ return ST_CLIMB;
+}
+
+/* ---------------------------------------------------------------- dash */
+static void dash_begin(void) {
+ P->called_dash_events = false;
+ P->dash_started_on_ground = P->on_ground;
+ level_freeze(TIM(.05f));
+ P->dash_cooldown = DashCooldown;
+ P->dash_refill_cooldown = DashRefillCooldown;
+ P->wall_slide_timer = WallSlideTime;
+ P->dash_trail_timer = 0;
+ P->dash_attack = DashAttackTime;
+ P->before_dash_sx = P->sx, P->before_dash_sy = P->sy;
+ P->sx = P->sy = 0;
+ P->dash_dx = P->dash_dy = 0;
+ if (!P->on_ground && Ducking && can_unduck()) set_ducking(false);
+}
+static void dash_end(void) { P->called_dash_events = true; }
+static int dash_update(void) {
+ if (P->dash_dy == 0) {
+ for (int i = 0; i < g_nents; i++) { /* up onto a jump-through a dash runs into */
+ Ent *jt = &g_ents[i];
+ if ((jt->flags & (EF_JUMPTHRU | EF_COLLIDABLE)) == (EF_JUMPTHRU | EF_COLLIDABLE) && ent_collide_at(E, E->x, E->y, jt) &&
+ e_bottom(E) - e_top(jt) <= DashHJumpThruNudge)
+ move_v_exact(e_top(jt) - e_bottom(E), NULL);
+ }
+ if (can_unduck() && btn_pressed(&g_in.jump) && P->jump_grace > 0) {
+ super_jump();
+ return ST_NORMAL;
+ }
+ }
+ if (P->dash_dx == 0 && P->dash_dy == -256) {
+ if (btn_pressed(&g_in.jump) && can_unduck()) {
+ if (wall_jump_check(1)) { super_wall_jump(-1); return ST_NORMAL; }
+ if (wall_jump_check(-1)) { super_wall_jump(1); return ST_NORMAL; }
+ }
+ } else if (btn_pressed(&g_in.jump) && can_unduck()) {
+ if (wall_jump_check(1)) { wall_jump(-1); return ST_NORMAL; }
+ if (wall_jump_check(-1)) { wall_jump(1); return ST_NORMAL; }
+ }
+ return ST_DASH;
+}
+static int co_dash(void) {
+ switch (P->co_step) {
+ case 0:
+ P->co_step = 1;
+ return 0;
+ case 1: {
+ int dx = P->last_aim_x, dy = P->last_aim_y;
+ int nx = dx * DashSpeed / 256, ny = dy * DashSpeed / 256;
+ if (dx && dy) nx = isign(dx) * 10182, ny = isign(dy) * 10182; /* 240 * 0.70710677 */
+ if (isign(P->before_dash_sx) == isign(nx) && iabs(P->before_dash_sx) > iabs(nx)) nx = P->before_dash_sx;
+ P->sx = nx, P->sy = ny;
+ P->dash_dx = dx, P->dash_dy = dy;
+ level_dir_shake(isign(dx), isign(dy), TIM(.2f) / DTU);
+ if (dx != 0) P->facing = isign(dx);
+ P->called_dash_events = true;
+ if (P->on_ground && P->dash_dx != 0 && P->dash_dy > 0 && P->sy > 0) {
+ P->dash_dx = isign(P->dash_dx) * 256;
+ P->dash_dy = 0;
+ P->sy = 0;
+ P->sx = P->sx * 6 / 5;
+ set_ducking(true);
+ }
+ P->co_step = 2;
+ return DashTime;
+ }
+ case 2:
+ P->auto_jump = true;
+ P->auto_jump_timer = 0;
+ if (P->dash_dy <= 0) {
+ int dx = P->dash_dx, dy = P->dash_dy;
+ P->sx = dx * EndDashSpeed / 256, P->sy = dy * EndDashSpeed / 256;
+ if (dx && dy) P->sx = isign(dx) * 6788, P->sy = isign(dy) * 6788; /* 160 * 0.70710677 */
+ }
+ if (P->sy < 0) P->sy = P->sy * 3 / 4; /* EndDashUpMult */
+ set_state(ST_NORMAL);
+ return -1;
+ }
+ return -1;
+}
+
+/* ---------------------------------------------------------------- intros */
+static int intro_x, intro_y;
+static int co_intro_jump(void) {
+ switch (P->co_step) {
+ case 0:
+ intro_x = E->x, intro_y = E->y;
+ E->depth = -1000000 / 64;
+ P->facing = 1;
+ E->y = g_level.room->y + g_level.room->h + 16;
+ P->co_step = 1;
+ return TIM(.5f);
+ case 1:
+ play(A_player_jumpSlow);
+ P->co_step = 2;
+ /* fall through */
+ case 2:
+ if (E->y > intro_y - 8) {
+ E->remy -= SPD(120);
+ int n = round_mu(E->remy, -1);
+ E->y += n, E->remy -= n * MU;
+ return 0;
+ }
+ E->remy = 0;
+ P->sy = SPD(-100);
+ P->co_step = 3;
+ /* fall through */
+ case 3:
+ if (P->sy < 0) {
+ P->sy += 800;
+ return 0;
+ }
+ P->sy = 0;
+ P->co_step = 4;
+ return TIM(.1f);
+ case 4:
+ play(A_player_fallSlow);
+ P->co_step = 5;
+ /* fall through */
+ case 5:
+ if (!P->on_ground) {
+ P->sy += 800;
+ return 0;
+ }
+ E->x = intro_x, E->y = intro_y;
+ E->depth = 0;
+ level_dir_shake(0, 1, TIM(.3f) / DTU);
+ set_state(ST_NORMAL);
+ return -1;
+ }
+ return -1;
+}
+static int co_intro_walk(void) {
+ switch (P->co_step) {
+ case 0:
+ intro_x = E->x, intro_y = E->y;
+ if (P->facing > 0) E->x = g_level.room->x - 16;
+ else E->x = g_level.room->x + g_level.room->w + 16;
+ P->co_step = 1;
+ return TIM(.3f);
+ case 1:
+ play(A_player_runSlow);
+ P->co_step = 2;
+ /* fall through */
+ case 2:
+ if (iabs(E->x - intro_x) > 2 && !solid_off(P->facing, 0)) {
+ move_h(isign(intro_x - E->x) * SPD(64), NULL);
+ return 0;
+ }
+ E->x = intro_x, E->y = intro_y;
+ play(A_player_idle);
+ P->co_step = 3;
+ return TIM(.2f);
+ default:
+ set_state(ST_NORMAL);
+ return -1;
+ }
+}
+static void respawn_begin(void) {
+ Room *rm = g_level.room;
+ int fx = iclamp(E->x, rm->x + 40, rm->x + rm->w - 40), fy = iclamp(E->y, rm->y + 40, rm->y + rm->h - 40);
+ P->respawn_fromx = fx - E->x, P->respawn_fromy = fy - E->y;
+ P->intro_t = 0;
+}
+static void respawn_end(void) {}
+
+/* ---------------------------------------------------------------- death */
+void player_die(int dx, int dy) {
+ if (P->dead) return;
+ P->dead = true;
+ P->sx = P->sy = 0;
+ E = P->e;
+ E->flags &= ~EF_COLLIDABLE;
+ E->depth = -32000;
+ level_shake(TIM(.3f) / DTU);
+ P->body_step = 0;
+ P->body_dx = dx, P->body_dy = dy;
+ P->body_t = 0;
+ P->death_t = -1;
+ P->bodyx = E->x, P->bodyy = E->y;
+ P->co_active = false;
+ btn_consume(&g_in.dash), btn_consume(&g_in.jump);
+}
+/* PlayerDeadBody.DeathRoutine: a bounce back (0.5 s, stopped at 3/4), then the burst of hair, then the reload */
+static void body_update(void) {
+ if (P->body_step == 0) {
+ if (P->body_dx || P->body_dy) {
+ level_freeze(TIM(.05f));
+ P->body_step = 1;
+ return;
+ }
+ P->body_step = 3;
+ }
+ if (P->body_step == 1) {
+ P->body_t += DTU;
+ int t = imin(P->body_t * 256 / TIM(.5f), 256), u = 256 - t;
+ int e = 256 - (int)((int32_t)u * u / 256 * u / 256);
+ E->x = P->bodyx + P->body_dx * 24 * e / 256;
+ E->y = P->bodyy + P->body_dy * 24 * e / 256;
+ if (P->body_t >= TIM(.5f) * 3 / 4) P->body_step = 3;
+ return;
+ }
+ if (P->body_step == 3) {
+ E->y -= 5;
+ level_shake(TIM(.3f) / DTU);
+ P->death_t = 0;
+ P->body_step = 4;
+ P->body_t = 0;
+ return;
+ }
+ P->death_t += DTU;
+ P->body_t += DTU;
+ if (P->body_step == 4 && P->body_t >= TIM(.834f * .65f)) {
+ P->body_step = 5;
+ g_level.wipe = 1; /* the wipe, then the reload */
+ }
+ if (P->body_step == 5 && g_level.wipe >= 24) g_level.dead_reload = true;
+}
+
+/* ---------------------------------------------------------------- the update */
+static void update_hair_color(void) {
+ uint32_t c;
+ if (P->dashes == 0 && P->dashes < P->max_dashes) c = UsedHairColor;
+ else if (P->last_dashes != P->dashes) c = FlashHairColor, P->hair_flash = TIM(.12f);
+ else if (P->hair_flash > 0) c = FlashHairColor, P->hair_flash -= DTU;
+ else c = P->dashes == 2 ? TwoDashesHairColor : NormalHairColor;
+ if (P->dashes == 0 && P->dashes < P->max_dashes && P->hair_rgb != UsedHairColor) { /* Lerp to it, 6 a second */
+ uint32_t a = P->hair_rgb, b = UsedHairColor;
+ int r = (int)(a >> 16 & 255), g = (int)(a >> 8 & 255), bl = (int)(a & 255);
+ r += ((int)(b >> 16 & 255) - r) * 26 / 256, g += ((int)(b >> 8 & 255) - g) * 26 / 256, bl += ((int)(b & 255) - bl) * 26 / 256;
+ c = (uint32_t)r << 16 | (uint32_t)g << 8 | (uint32_t)bl;
+ if (iabs(r - 0x44) < 4 && iabs(g - 0xB7) < 4 && iabs(bl - 0xFF) < 4) c = UsedHairColor;
+ }
+ P->hair_rgb = c;
+ P->last_dashes = P->dashes;
+}
+
+static void hair_update(void) {
+ const uint8_t *m = player_meta(cur_sprite());
+ int fac = P->facing;
+ /* PlayerHair.AfterUpdate: the first node at the head, the others following, 3 px apart at most */
+ P->hairx[0] = (E->x + (int8_t)m[0] * fac) << 8;
+ P->hairy[0] = (E->y - 9 * P->scale_y / 1024 + (int8_t)m[1]) << 8;
+ int tx = P->hairx[0] - fac * 128, ty = P->hairy[0] + 512; /* the step: (-facing * 0.5, 2) */
+ for (int i = 1; i < P->hair_count; i++) {
+ int dx = tx - P->hairx[i], dy = ty - P->hairy[i];
+ int l = isqrt((int32_t)dx * dx + (int32_t)dy * dy);
+ int mv = (256 - i * 128 / P->hair_count) * 64 / 60; /* (1 - i / n / 2) * 64 px a second */
+ if (l <= mv) P->hairx[i] = tx, P->hairy[i] = ty;
+ else if (l > 0) P->hairx[i] += (int)((int32_t)dx * mv / l), P->hairy[i] += (int)((int32_t)dy * mv / l);
+ dx = P->hairx[i] - P->hairx[i - 1], dy = P->hairy[i] - P->hairy[i - 1];
+ l = isqrt((int32_t)dx * dx + (int32_t)dy * dy);
+ if (l > 768) P->hairx[i] = P->hairx[i - 1] + (int)((int32_t)dx * 768 / l), P->hairy[i] = P->hairy[i - 1] + (int)((int32_t)dy * 768 / l);
+ tx = P->hairx[i] - fac * 128, ty = P->hairy[i] + 512;
+ }
+}
+
+static void update_sprite(void) {
+ P->scale_x = approach(P->scale_x, 1024, 30);
+ P->scale_y = approach(P->scale_y, 1024, 30);
+ if (!in_control()) return;
+ if (player_dash_attacking()) {
+ if (P->on_ground && P->dash_dy == 0 && !Ducking && P->sx != 0 && P->move_x == -isign(P->sx)) play(A_player_skid);
+ else play(A_player_dash);
+ } else if (P->state == ST_CLIMB) {
+ if (P->last_climb_move < 0) play(A_player_climbup);
+ else if (P->last_climb_move > 0) play(A_player_wallslide);
+ else if (!solid_off(P->facing, 6)) play(A_player_dangling);
+ else if (g_in.move_x == -P->facing) {
+ if (P->anim != A_player_climbLookBack) play(A_player_climbLookBackStart);
+ } else
+ play(A_player_wallslide);
+ } else if (Ducking && P->state == ST_NORMAL) {
+ play(A_player_duck);
+ } else if (P->on_ground) {
+ P->fast_jump = false;
+ if (P->move_x != 0 && solid_off(P->move_x, 0)) play(A_player_push);
+ else if (iabs(P->sx) <= RunAccel / 40 * 60 / 60 && P->move_x == 0) {
+ int f = P->facing;
+ if (!solid_at(E->x + f, E->y + 2, E->x + f + 1, E->y + 3, E) && !solid_at(E->x + f * 4, E->y + 2, E->x + f * 4 + 1, E->y + 3, E) &&
+ !jumpthru_first_outside(E, E->x + f * 4, E->y + 2))
+ play(A_player_edge);
+ else if (!solid_at(E->x - f, E->y + 2, E->x - f + 1, E->y + 3, E) &&
+ !solid_at(E->x - f * 4, E->y + 2, E->x - f * 4 + 1, E->y + 3, E) && !jumpthru_first_outside(E, E->x - f * 4, E->y + 2))
+ play(A_player_edgeBack);
+ else if (g_in.move_y == -1) {
+ if (P->anim != A_player_lookUp) play(A_player_lookUp);
+ } else if (P->anim != A_player_idle && P->anim != A_player_idleA && P->anim != A_player_idleB && P->anim != A_player_idleC)
+ play(A_player_idle);
+ } else if (isign(P->sx) == -P->move_x && P->move_x != 0) {
+ if (iabs(P->sx) > MaxRun) play(A_player_skid);
+ else if (P->anim != A_player_skid) play(A_player_flip);
+ } else if (P->anim != A_player_flip && P->anim != A_player_runSlow && P->anim != A_player_runFast &&
+ P->anim != A_player_runStumble) {
+ if (iabs(P->sx) < MaxRun / 2) play(A_player_runSlow);
+ else play(A_player_runFast);
+ }
+ } else if (P->wall_slide_dir != 0) {
+ play(A_player_wallslide);
+ } else if (P->sy < 0) {
+ if (P->fast_jump || iabs(P->sx) > MaxRun) {
+ P->fast_jump = true;
+ play(A_player_jumpFast);
+ } else
+ play(A_player_jumpSlow);
+ } else {
+ if (P->fast_jump || P->sy >= MaxFall) {
+ P->fast_jump = true;
+ play(A_player_fallFast);
+ } else
+ play(A_player_fallSlow);
+ }
+}
+
+void player_update(void) {
+ E = P->e;
+ if (P->dead) {
+ body_update();
+ if (P->body_step < 4) sprite_update();
+ return;
+ }
+ P->idle_timer += DTU;
+ if (P->sx || P->sy) P->idle_timer = 0;
+ if (P->strawb_reset > 0 && (P->strawb_reset -= DTU) <= 0) P->strawb_index = 0;
+ if (P->sy >= 0) {
+ Ent *first = solid_hit_off(0, 1);
+ if (!first) first = jumpthru_first_outside(E, E->x, E->y + 1);
+ P->on_ground = first != NULL;
+ P->on_safe_ground = first && (first->flags & EF_SAFE);
+ } else
+ P->on_ground = P->on_safe_ground = false;
+ if (g_level.frame % 6 == 0) P->flash = !P->flash; /* (OnInterval .05) */
+ if (P->wall_slide_dir != 0) {
+ P->wall_slide_timer = imax(P->wall_slide_timer - DTU, 0);
+ P->wall_slide_dir = 0;
+ }
+ if (P->wall_boost_timer > 0) {
+ P->wall_boost_timer -= DTU;
+ if (P->move_x == P->wall_boost_dir) {
+ P->sx = WallJumpHSpeed * P->move_x;
+ P->stamina += ClimbJumpCost;
+ P->wall_boost_timer = 0;
+ }
+ }
+ if (P->on_ground && P->state != ST_CLIMB) {
+ P->auto_jump = false;
+ P->stamina = ClimbMaxStamina;
+ P->wall_slide_timer = WallSlideTime;
+ }
+ if (P->dash_attack > 0) P->dash_attack -= DTU;
+ if (P->on_ground) P->jump_grace = JumpGraceTime;
+ else if (P->jump_grace > 0) P->jump_grace -= DTU;
+ if (P->dash_cooldown > 0) P->dash_cooldown -= DTU;
+ if (P->dash_refill_cooldown > 0) P->dash_refill_cooldown -= DTU;
+ else if (P->on_ground && (solid_off(0, 1) || jumpthru_off(0, 1))) {
+ bool on_spikes = false; /* (CollideCheck<Spikes>) */
+ for (int i = 0; i < g_nents && !on_spikes; i++) {
+ Ent *o = &g_ents[i];
+ on_spikes = o->type >= ET_spikesUp && o->type <= ET_spikesRight && (o->flags & EF_COLLIDABLE) && ent_collide_at(E, E->x, E->y, o);
+ }
+ if (!on_spikes) player_refill_dash();
+ }
+ if (P->var_jump > 0) P->var_jump -= DTU;
+ if (P->auto_jump_timer > 0) {
+ if (P->auto_jump) {
+ P->auto_jump_timer -= DTU;
+ if (P->auto_jump_timer <= 0) P->auto_jump = false;
+ } else
+ P->auto_jump_timer = 0;
+ }
+ if (P->force_move_x_timer > 0) {
+ P->force_move_x_timer -= DTU;
+ P->move_x = P->force_move_x;
+ } else
+ P->move_x = g_in.move_x;
+ if (P->move_x != 0 && in_control() && P->state != ST_CLIMB) {
+ if (P->move_x != P->facing && Ducking) P->scale_x = 819, P->scale_y = 1229;
+ P->facing = P->move_x;
+ }
+ aim(&P->last_aim_x, &P->last_aim_y);
+ if (P->wall_speed_retention > 0) {
+ if (isign(P->sx) == -isign(P->wall_speed_retained)) P->wall_speed_retention = 0;
+ else if (!solid_off(isign(P->wall_speed_retained), 0)) {
+ P->sx = P->wall_speed_retained;
+ P->wall_speed_retention = 0;
+ } else
+ P->wall_speed_retention -= DTU;
+ }
+ if (P->hop_wait_x != 0) {
+ if (isign(P->sx) == -P->hop_wait_x || P->sy > 0) P->hop_wait_x = 0;
+ else if (!solid_off(P->hop_wait_x, 0)) {
+ P->sx = P->hop_wait_x_speed;
+ P->hop_wait_x = 0;
+ }
+ }
+ P->hair_count = P->dashes > 1 ? 5 : 4;
+ /* components: the hair's wave, the sprite, the state machine, then the actor's lift */
+ P->hair_wave += 4;
+ sprite_update();
+ if (P->state == ST_INTRORESPAWN) { /* the respawn's tween: 0.6 s */
+ P->intro_t += DTU;
+ if (P->intro_t >= TIM(.6f)) {
+ set_state(ST_NORMAL);
+ P->scale_x = 1536, P->scale_y = 512;
+ }
+ }
+ if (P->state < 3 && UPD[P->state]) set_state(UPD[P->state]());
+ co_update();
+ /* the lift speed: kept 0.16 s */
+ if (E->liftx || E->lifty) P->last_liftx = E->liftx, P->last_lifty = E->lifty, P->lift_timer = TIM(.16f);
+ E->liftx = E->lifty = 0;
+ if (P->lift_timer > 0 && (P->lift_timer -= DTU) <= 0) P->last_liftx = P->last_lifty = 0;
+ if (!P->on_ground && P->sy <= 0 && (P->state != ST_CLIMB || P->last_climb_move == -1)) { /* up through jump-throughs */
+ bool in = false;
+ for (int i = 0; i < g_nents && !in; i++) {
+ Ent *o = &g_ents[i];
+ in = (o->flags & (EF_JUMPTHRU | EF_COLLIDABLE)) == (EF_JUMPTHRU | EF_COLLIDABLE) && ent_collide_at(E, E->x, E->y, o);
+ }
+ if (in && !ledge_blocked(E->x, E->y - 2)) move_v(JumpThruAssistSpeed, NULL);
+ }
+ if (!P->on_ground && player_dash_attacking() && P->dash_dy == 0)
+ if (solid_off(0, DashVFloorSnapDist) || jumpthru_off(0, DashVFloorSnapDist)) move_v_exact(DashVFloorSnapDist, NULL);
+ if (P->sy > 0 && can_unduck() && !P->on_ground) set_ducking(false);
+ if (P->state != ST_INTROJUMP || P->co_step >= 3) {
+ move_h(P->sx, on_collide_h);
+ move_v(P->sy, on_collide_v);
+ }
+ if (P->dead) return;
+ update_sprite();
+ if (in_control() && P->state != ST_INTROJUMP) { /* the camera: 1 - 0.01 ^ dt of the way */
+ int tx = player_cam_targetx() << 8, ty = player_cam_targety() << 8;
+ g_level.camx += (int)(((int32_t)(tx - g_level.camx) * 1210) >> 14);
+ g_level.camy += (int)(((int32_t)(ty - g_level.camy) * 1210) >> 14);
+ }
+ /* what she touches (PlayerCollider), with the hurt box */
+ if (!P->dead) {
+ int8_t was[4] = {(int8_t)E->hw, (int8_t)E->hh, (int8_t)E->hx, (int8_t)E->hy};
+ set_box(Ducking ? HB_DUCK_HURT : HB_NORMAL_HURT);
+ extern void ents_player_touch(Ent *p);
+ ents_player_touch(E);
+ if (P->dead) return;
+ if (box_is(HB_DUCK_HURT) || box_is(HB_NORMAL_HURT)) set_box(was);
+ }
+ update_hair_color();
+ P->was_on_ground = P->on_ground;
+}
+
+/* ---------------------------------------------------------------- camera and transitions */
+int player_cam_targetx(void) {
+ Room *rm = g_level.room;
+ return iclamp(P->e->x - 160 + g_level.cam_offx, rm->x, rm->x + rm->w - 320);
+}
+int player_cam_targety(void) {
+ Room *rm = g_level.room;
+ return iclamp(P->e->y - 90 + g_level.cam_offy, rm->y, rm->y + rm->h - 180);
+}
+bool player_transition_to(int x, int y) {
+ E = P->e;
+ /* MoveTowardsX/Y: 60 px a second */
+ int cx = E->x * MU + E->remx, cy = E->y * MU + E->remy;
+ move_h(approach(cx, x * MU, SPD(60)) - cx, NULL);
+ move_v(approach(cy, y * MU, SPD(60)) - cy, NULL);
+ hair_update();
+ if (E->x == x && E->y == y) {
+ E->remx = E->remy = 0;
+ P->sx = P->sx / 60 * 60, P->sy = P->sy / 60 * 60; /* Speed rounded to whole pixels a second */
+ return true;
+ }
+ return false;
+}
+void player_on_transition(void) {
+ P->wall_slide_timer = WallSlideTime;
+ P->jump_grace = 0;
+ P->force_move_x_timer = 0;
+ player_refill_dash();
+ P->stamina = ClimbMaxStamina;
+}
+void player_before_up_transition(void) {
+ P->sx = 0;
+ P->var_jump_speed = P->sy = JumpSpeed;
+ set_state(ST_NORMAL);
+ P->auto_jump = true;
+ P->auto_jump_timer = 0;
+ P->var_jump = VarJumpTime;
+ P->dash_cooldown = TIM(.2f);
+}
+void player_before_down_transition(void) {
+ set_state(ST_NORMAL);
+ P->sy = imax(0, P->sy);
+ P->auto_jump = false;
+ P->var_jump = 0;
+}
+
+/* ---------------------------------------------------------------- drawing */
+static void hair_draw(bool outline) {
+ const uint8_t *m = player_meta(cur_sprite());
+ if (!(m[2] & 0x80)) return;
+ int n = P->hair_count, bangs = m[2] & 0x7F;
+ for (int i = outline ? 0 : n - 1; outline ? i < n : i >= 0; i += outline ? 1 : -1) {
+ const uint16_t *mask = hair_mask(i == 0 ? 1 + (bangs < 3 ? bangs : 0) : 0);
+ int scale = 64 + (256 - i * 256 / n) * 3 / 4; /* 0.25 + (1 - i / n) * 0.75 */
+ int cx = (i == 0 ? P->hairx[0] >> 8 : (P->hairx[i] + 128) >> 8) - g_camx;
+ int cy = (i == 0 ? P->hairy[0] >> 8 : (P->hairy[i] + 128) >> 8) - g_camy;
+ bool flip = i == 0 && P->facing < 0;
+ int sx = (i == 0 ? 256 : scale) * P->scale_x / 1024, sy = i == 0 ? 256 : scale;
+ /* the 10 x 10 picture, its centre (5, 5) at (cx, cy) */
+ int x0 = cx - (5 * sx + 128) / 256, x1 = cx + (5 * sx + 128) / 256, y0 = cy - (5 * sy + 128) / 256, y1 = cy + (5 * sy + 128) / 256;
+ for (int y = y0; y < y1; y++)
+ for (int x = x0; x < x1; x++) {
+ int u = 5 + ((x - cx) * 256 + 128) / sx, v = 5 + ((y - cy) * 256 + 128) / sy;
+ if ((unsigned)u >= 10 || (unsigned)v >= 10) continue;
+ if (flip) u = 9 - u;
+ if (!(mask[v] >> u & 1)) continue;
+ if (outline) {
+ static const int8_t O[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
+ for (int k = 0; k < 4; k++) {
+ int px = x + O[k][0], py = y + O[k][1];
+ if ((unsigned)px < VIEW_W && (unsigned)py < VIEW_H) g_fb[(VIEW_Y + py) * 320 + px] = BLACK;
+ }
+ } else if ((unsigned)x < VIEW_W && (unsigned)y < VIEW_H)
+ g_fb[(VIEW_Y + y) * 320 + x] = mask[10 + v] >> u & 1 ? 2 : 1;
+ }
+ }
+}
+
+static void death_effect(int x, int y, int t) { /* DeathEffect: 8 hair circles flying out, t 0..256 */
+ int e = 256 - (int)((int32_t)(256 - t) * (256 - t) / 256 * (256 - t) / 256);
+ int s = t < 128 ? 128 + t : (256 - (int)((int32_t)(t * 2 - 256) * (t * 2 - 256) / 256 * (t * 2 - 256) / 256));
+ int r = 4 * s / 256;
+ uint8_t col = (t * 10 / 256) % 2 == 0 ? 1 : WHITE;
+ for (int i = 0; i < 8; i++) {
+ int a = i * 128 + t / 4;
+ int px = x + sin256(a + 256) * 24 * e / 65536, py = y + sin256(a) * 24 * e / 65536;
+ draw_circle_fill(px, py, r + 1, BLACK);
+ }
+ for (int i = 0; i < 8; i++) {
+ int a = i * 128 + t / 4;
+ int px = x + sin256(a + 256) * 24 * e / 65536, py = y + sin256(a) * 24 * e / 65536;
+ draw_circle_fill(px, py, r, col);
+ }
+}
+
+void player_render(void) {
+ E = P->e;
+ if (P->dead) {
+ if (P->body_step < 4) {
+ const uint8_t *s = sprite(cur_sprite());
+ draw_sprite_scaled(s, E->x, E->y, 256, 256, 16, 32, P->facing < 0 ? DF_FLIPX : 0);
+ } else if (P->death_t >= 0 && P->death_t <= TIM(.834f))
+ death_effect(E->x, E->y - 6, P->death_t * 256 / TIM(.834f));
+ return;
+ }
+ palette_hair(P->hair_rgb);
+ if (P->state == ST_INTRORESPAWN) {
+ int t = imin(P->intro_t * 256 / TIM(.6f), 256);
+ death_effect(E->x + P->respawn_fromx * (256 - t) / 256, E->y - 6 + P->respawn_fromy * (256 - t) / 256, 256 - t);
+ return;
+ }
+ hair_draw(true);
+ hair_draw(false);
+ const uint8_t *s = sprite(cur_sprite());
+ bool red = is_tired() && P->flash;
+ if (red) g_draw_color = 1;
+ draw_sprite_scaled(s, E->x, E->y, P->scale_x / 4, P->scale_y / 4, 16, 32, (P->facing < 0 ? DF_FLIPX : 0));
+}
+
+void player_spawn(int x, int y, int intro) {
+ memset(P, 0, sizeof *P);
+ Ent *e = ent_new(ET_player, x, y);
+ P->e = e;
+ E = e;
+ e->room = 2;
+ e->depth = 0;
+ set_box(HB_NORMAL);
+ P->facing = 1;
+ P->max_dashes = 1;
+ P->dashes = P->last_dashes = 1;
+ P->stamina = ClimbMaxStamina;
+ P->wall_slide_timer = WallSlideTime;
+ P->max_fall = MaxFall;
+ P->scale_x = P->scale_y = 1024;
+ P->hair_rgb = NormalHairColor;
+ P->hair_count = 4;
+ P->anim = -1;
+ play(A_player_idle);
+ P->state = -1;
+ if (e->x > g_level.room->x + g_level.room->w / 2 && intro != INTRO_NONE) P->facing = -1;
+ switch (intro) {
+ case INTRO_RESPAWN: set_state(ST_INTRORESPAWN); break;
+ case INTRO_JUMP: set_state(ST_INTROJUMP); break;
+ case INTRO_WALKINRIGHT: P->facing = 1, set_state(ST_INTROWALK); break;
+ case INTRO_WALKINLEFT: P->facing = -1, set_state(ST_INTROWALK); break;
+ default: set_state(ST_NORMAL); break;
+ }
+ for (int i = 0; i < HAIR_NODES; i++) P->hairx[i] = (x - P->facing * 2) << 8, P->hairy[i] = (y - 10) << 8;
+ hair_update();
+}
+
+void player_after_update(void) {
+ if (P->e && (!P->dead || P->body_step < 4)) {
+ E = P->e;
+ hair_update();
+ }
+}
diff --git a/games/celeste/ce/tools/appvar.py b/games/celeste/ce/tools/appvar.py
new file mode 100644
index 00000000..cbb77198
--- /dev/null
+++ b/games/celeste/ce/tools/appvar.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+"""TI-84 Plus CE appvars (.8xv, archived) of files: each file's name without its extension is the appvar's.
+
+ python3 tools/appvar.py OUT_DIR data/CELG0.bin data/CEL10.bin ..."""
+import os
+import struct
+import sys
+
+
+def appvar(name, data, archived=True):
+ assert len(data) <= 65505, (name, len(data))
+ var = struct.pack("<H", len(data)) + data
+ entry = struct.pack("<HHB8sBBH", 13, len(var), 0x15, name.encode().ljust(8, b"\0"), 0, 0x80 if archived else 0,
+ len(var)) + var
+ out = b"**TI83F*\x1a\x0a\x00" + b"Celeste for the TI-84 Plus CE".ljust(42, b"\0") + struct.pack("<H", len(entry))
+ return out + entry + struct.pack("<H", sum(entry) & 0xFFFF)
+
+
+if __name__ == "__main__":
+ out = sys.argv[1]
+ os.makedirs(out, exist_ok=True)
+ for path in sys.argv[2:]:
+ name = os.path.splitext(os.path.basename(path))[0]
+ open(os.path.join(out, name + ".8xv"), "wb").write(appvar(name, open(path, "rb").read()))
diff --git a/games/celeste/ce/tools/pack_ce.py b/games/celeste/ce/tools/pack_ce.py
new file mode 100644
index 00000000..0b1a3f40
--- /dev/null
+++ b/games/celeste/ce/tools/pack_ce.py
@@ -0,0 +1,1101 @@
+#!/usr/bin/env python3
+"""Celeste's content -> the TI-84 Plus CE version's appvars (ce/bin/*.8xv) and ce/src/gen.h.
+
+ CELESTE=<the game's Content folder> python3 tools/pack_ce.py
+
+The CE draws at 8 bits a pixel: every chapter has its own 256 colours, the first COMMON of them the same in all of
+them (Madeline, the strawberries, what every chapter has), the rest made from the chapter's own pictures. Everything
+lives in archived appvars the game reads in place: CELG0.. (what every chapter draws), CEL<n>0.. (chapter n: its
+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 os
+import random
+import re
+import struct
+import sys
+
+import numpy as np
+
+HERE = os.path.dirname(os.path.abspath(__file__))
+sys.path.insert(0, os.path.join(HERE, "..", "..", "tools"))
+os.environ.setdefault("CELESTE_CACHE", os.path.join(HERE, "..", "build", "cache"))
+from cel import CELESTE, Atlas # noqa: E402
+import tiles as T # noqa: E402
+import entities as E # noqa: E402
+import pack # noqa: E402 (the NumWorks converter: its map reader, autotiler and sprite banks)
+
+OUT = os.path.join(HERE, "..", "data") # the appvars' contents (tools/appvar.py makes bin/*.8xv of them)
+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)
+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)
+
+# (map, chapter number, side): the chapters this build has
+CHAPTERS = [("1-ForsakenCity", 1)]
+AREA_STYLE = {1: dict(jumpthru="wood", spike="default", crumble="default")}
+
+GAMEPLAY = Atlas("Gameplay")
+H = [] # gen.h lines
+
+
+def tex(path):
+ return GAMEPLAY[path] if path in GAMEPLAY else None
+
+
+def family(prefix):
+ fam = GAMEPLAY.prefix(prefix)
+ if not fam and prefix in GAMEPLAY:
+ fam = [GAMEPLAY[prefix]]
+ return fam
+
+
+def cname(s):
+ return re.sub(r"[^A-Za-z0-9]", "_", s)
+
+
+# ------------------------------------------------------------------ blobs laid out over appvars
+
+class Ref:
+ __slots__ = ("item",)
+
+ def __init__(self, item):
+ self.item = item
+
+
+class Item:
+ def __init__(self, name):
+ self.name = name
+ self.chunks = []
+ self.part = self.off = None
+
+ def u8(self, v):
+ assert 0 <= v < 256, (self.name, v)
+ self.chunks.append(bytes((v,)))
+ return self
+
+ def s8(self, v):
+ assert -128 <= v < 128, (self.name, v)
+ self.chunks.append(struct.pack("<b", v))
+ return self
+
+ def u16(self, v):
+ assert 0 <= v < 65536, (self.name, v)
+ self.chunks.append(struct.pack("<H", v))
+ return self
+
+ def s16(self, v):
+ assert -32768 <= v < 32768, (self.name, v)
+ self.chunks.append(struct.pack("<h", v))
+ return self
+
+ def u24(self, v):
+ assert 0 <= v < 1 << 24, (self.name, v)
+ self.chunks.append(struct.pack("<I", v)[:3])
+ return self
+
+ def s24(self, v):
+ assert -(1 << 23) <= v < 1 << 23, (self.name, v)
+ self.chunks.append(struct.pack("<i", v)[:3])
+ return self
+
+ def raw(self, b):
+ self.chunks.append(bytes(b))
+ return self
+
+ def ref(self, item):
+ self.chunks.append(Ref(item))
+ return self
+
+ def size(self):
+ return sum(3 if isinstance(c, Ref) else c.size() if isinstance(c, Item) else len(c) for c in self.chunks)
+
+ def place(self, part, off):
+ """Where it goes, and the items inside it (chunks that are items) with it."""
+ self.part, self.off = part, off
+ for c in self.chunks:
+ if isinstance(c, Item):
+ c.place(part, off)
+ off += 3 if isinstance(c, Ref) else c.size() if isinstance(c, Item) else len(c)
+
+ def bytes(self):
+ out = bytearray()
+ for c in self.chunks:
+ if isinstance(c, Ref):
+ it = c.item
+ assert it.part is not None, it.name
+ out += struct.pack("<HB", it.off, it.part)
+ elif isinstance(c, Item):
+ out += c.bytes()
+ else:
+ out += c
+ return bytes(out)
+
+
+class Blob:
+ """Items laid out in order over appvars NAME0, NAME1... (an item never straddles two)."""
+
+ def __init__(self, name):
+ self.name = name
+ self.items = []
+
+ def item(self, name):
+ it = Item(name)
+ self.items.append(it)
+ return it
+
+ def add(self, it):
+ self.items.append(it)
+ return it
+
+ def layout(self):
+ parts = [bytearray()]
+ for it in self.items:
+ n = it.size()
+ assert n <= PART_MAX, (it.name, n)
+ if len(parts[-1]) + n > PART_MAX:
+ parts.append(bytearray())
+ it.place(len(parts) - 1, len(parts[-1]))
+ parts[-1] += b"\0" * n
+ for it in self.items:
+ parts[it.part][it.off:it.off + it.size()] = it.bytes()
+ return parts
+
+ def write(self):
+ parts = self.layout()
+ total = 0
+ for i, p in enumerate(parts):
+ open(os.path.join(OUT, "%s%d.bin" % (self.name, i)), "wb").write(bytes(p))
+ total += len(p)
+ print(f"{self.name}: {len(parts)} appvars, {total} bytes")
+ return len(parts)
+
+
+# ------------------------------------------------------------------ colours
+
+def c15(rgb):
+ rgb = rgb.astype(np.int32)
+ return (rgb[..., 0] >> 3) << 10 | (rgb[..., 1] >> 3) << 5 | (rgb[..., 2] >> 3)
+
+
+def unpremultiply(img):
+ """Celeste's textures have premultiplied alpha: the colour of each pixel, and its alpha."""
+ a = img[..., 3].astype(np.int32)
+ rgb = img[..., :3].astype(np.int32)
+ u = np.where(a[..., None] > 0, np.minimum(255, rgb * 255 // np.maximum(a[..., None], 1)), 0)
+ return u.astype(np.uint8), a
+
+
+def rgb_of(c):
+ r, g, b = (c >> 10) & 31, (c >> 5) & 31, c & 31
+ return np.array([r << 3 | r >> 2, g << 3 | g >> 2, b << 3 | b >> 2], np.float64)
+
+
+def kmeans(counts, fixed, k, iters=12):
+ """At most k colours for a {15-bit colour: pixels} table, on top of `fixed` ones (15-bit) that stay: all of them
+ when they fit, else k-means in RGB weighed by how many pixels have each colour."""
+ fixed = set(fixed)
+ cols = [c for c in counts if c not in fixed]
+ if len(cols) <= k:
+ return sorted(cols)
+ pts = np.array([rgb_of(c) for c in cols])
+ w = np.array([counts[c] for c in cols], np.float64)
+ fx = np.array([rgb_of(c) for c in fixed])
+ d = np.min(((pts[:, None, :] - fx[None]) ** 2).sum(-1), 1) if len(fx) else np.full(len(pts), np.inf)
+ centers = []
+ for _ in range(k):
+ j = int(np.argmax(d * np.sqrt(w)))
+ centers.append(pts[j])
+ d = np.minimum(d, ((pts - pts[j]) ** 2).sum(-1))
+ c = np.array(centers)
+ for _ in range(iters):
+ allc = np.concatenate([c, fx]) if len(fx) else c
+ lab = np.argmin(((pts[:, None, :] - allc[None]) ** 2).sum(-1), 1)
+ for j in range(k):
+ m = lab == j
+ if m.any():
+ c[j] = (pts[m] * w[m, None]).sum(0) / w[m].sum()
+ out = set()
+ for v in c:
+ v = np.clip(np.round(v), 0, 255).astype(int)
+ q = int((v[0] >> 3) << 10 | (v[1] >> 3) << 5 | (v[2] >> 3))
+ if q not in fixed:
+ out.add(q)
+ return sorted(out)
+
+
+class Palette:
+ """256 colours (15-bit), index 0 black (also the tiles' see-through key: art never maps to it)."""
+
+ def __init__(self, colors):
+ assert len(colors) <= 256
+ self.colors = list(colors) + [0] * (256 - len(colors))
+ self.n = len(colors)
+ self.rgb = np.array([rgb_of(c) for c in self.colors[:self.n]])
+ self.cache = {}
+
+ def index(self, q):
+ if q in self.cache:
+ return self.cache[q]
+ d = ((self.rgb - rgb_of(q)) ** 2).sum(1)
+ d[0] = d[HAIR] = d[HAIR_DARK] = np.inf
+ i = int(np.argmin(d))
+ self.cache[q] = i
+ return i
+
+ def map(self, img, alpha_min=128):
+ """RGBA (premultiplied) -> indices, 0 where see-through."""
+ rgb, a = unpremultiply(img)
+ q = c15(rgb)
+ out = np.zeros(q.shape, np.uint8)
+ vis = a >= alpha_min
+ for v in np.unique(q[vis]):
+ out[vis & (q == v)] = self.index(int(v))
+ return out
+
+ def rgb1555(self, lo=0, hi=256):
+ return b"".join(struct.pack("<H", c) for c in self.colors[lo:hi])
+
+
+def count_colors(img, counts, alpha_min=128):
+ rgb, a = unpremultiply(img)
+ q = c15(rgb)[a >= alpha_min]
+ v, n = np.unique(q, return_counts=True)
+ for c, k in zip(v.tolist(), n.tolist()):
+ counts[c] += k
+
+
+# ------------------------------------------------------------------ sprites
+
+def rle_sprite(idx, name="sprite"):
+ """A picture with see-through pixels (0) as src/draw.c draws it: u8 w, h of the frame, u8 x, y, w, h of what is
+ stored, then per stored row: u8 runs, then each run (u8 skip from the end of the one before, u8 n, n pixels)."""
+ fh, fw = idx.shape
+ assert fw < 256 and fh < 256, (name, fw, fh)
+ ys, xs = np.nonzero(idx)
+ it = Item(name)
+ if len(xs) == 0:
+ return it.u8(fw).u8(fh).u8(0).u8(0).u8(0).u8(0)
+ x0, x1, y0, y1 = int(xs.min()), int(xs.max()) + 1, int(ys.min()), int(ys.max()) + 1
+ it.u8(fw).u8(fh).u8(x0).u8(y0).u8(x1 - x0).u8(y1 - y0)
+ for y in range(y0, y1):
+ row = idx[y, x0:x1]
+ runs = []
+ x = 0
+ while x < len(row):
+ if row[x] == 0:
+ x += 1
+ continue
+ s = x
+ while x < len(row) and row[x] != 0 and x - s < 255:
+ x += 1
+ runs.append((s, x))
+ it.u8(len(runs))
+ at = 0
+ for s, e in runs:
+ it.u8(s - at).u8(e - s).raw(bytes(row[s:e].tolist()))
+ at = e
+ return it
+
+
+class SpriteSet:
+ """A blob's sprites: a table item (u16 count, then a pointer each) and each one's picture."""
+
+ def __init__(self, blob, prefix):
+ self.blob = blob
+ self.prefix = prefix
+ self.ids = {}
+ self.list = []
+
+ def add(self, key, idx):
+ if key in self.ids:
+ return self.ids[key]
+ it = rle_sprite(idx, str(key))
+ self.blob.add(it)
+ self.ids[key] = len(self.list)
+ self.list.append(it)
+ return self.ids[key]
+
+ def table(self):
+ t = Item(self.prefix + " sprite table")
+ t.u16(len(self.list))
+ for it in self.list:
+ t.ref(it)
+ return t
+
+
+def bank_anims(name, anims=None):
+ b = pack.bank(name)
+ return b, [(a, an) for a, an in b.anims.items() if anims is None or a in anims]
+
+
+class Anims:
+ """Sprite banks (Sprites.xml): each anim u8 frames, u8 flags (1 loop), u16 delay (1/600 s), u8 goto (255: none),
+ u8 its bank, then u16 sprite ids. gen.h names them A_<bank>_<anim>, and B_<bank> the bank (its first anim and its
+ origin)."""
+
+ def __init__(self, prefix):
+ self.prefix = prefix
+ self.list = [] # (bank, name, frames[keys], delay, loop, gotos)
+ self.banks = collections.OrderedDict()
+
+ def add_bank(self, name, image, anims=None, alias=None, missing_ok=True):
+ b, an = bank_anims(name, anims)
+ key = alias or name
+ first = len(self.list)
+ for a, d in an:
+ keys = [image(pack.TEX.list[t].path) for t in d["frames"]]
+ if not keys:
+ continue
+ self.list.append((key, a, keys, d["delay"], d["loop"], d["goto"]))
+ self.banks[key] = (first, len(self.list), b.origin)
+ return b
+
+ def write(self, blob, sprites):
+ it = blob.item(self.prefix + " anims")
+ index = {(k, a): i for i, (k, a, *_r) in enumerate(self.list)}
+ it.u16(len(self.list))
+ recs = []
+ for k, a, keys, delay, loop, gotos in self.list:
+ g = 255
+ if gotos:
+ g = index.get((k, gotos[0][0]), 255)
+ r = Item("anim")
+ r.u8(len(keys)).u8(1 if loop else 0).u16(int(round(delay * 600))).u8(g).u8(list(self.banks).index(k))
+ for key in keys:
+ r.u16(sprites.ids[key])
+ recs.append(r)
+ for r in recs:
+ it.ref(r)
+ for r in recs:
+ blob.add(r)
+ p = self.prefix
+ for bi, (k, (first, last, origin)) in enumerate(self.banks.items()):
+ H.append(f"#define {p}B_{cname(k)} {bi}")
+ for i, (k, a, *_r) in enumerate(self.list):
+ H.append(f"#define {p}A_{cname(k)}_{cname(a)} {i}")
+ H.append(f"/* banks' origins: mode (0 none, 1 pixels, 2 justify x256), x, y */")
+ H.append(f"#define {p}BANK_ORIGINS {{" + ", ".join(
+ "{%d, %d, %d}" % (o[0], round(o[1] * (256 if o[0] == 2 else 1)), round(o[2] * (256 if o[0] == 2 else 1)))
+ for (first, last, o) in self.banks.values()) + "}")
+ H.append(f"#define {p}NBANKS {len(self.banks)}")
+ return it
+
+
+# ------------------------------------------------------------------ the common sprites
+
+PLAYER_ANIMS = ["idle", "idleA", "idleB", "idleC", "lookUp", "walk", "push", "runSlow", "runFast", "runStumble",
+ "dash", "slide", "jumpSlow", "jumpFast", "fallSlow", "fallFast", "tired", "tiredStill", "wallslide",
+ "climbLookBackStart", "climbLookBack", "climbup", "duck", "fallPose", "edge", "edgeBack", "flip",
+ "skid", "dangling", "deadside", "deadup", "deaddown", "sitDown", "asleep", "wakeUp", "spin", "fall",
+ "bigFall", "launch", "launchRecover"]
+
+
+class Common:
+ """What every chapter draws: Madeline, her hair, the pickups and the objects the chapters share."""
+
+ def __init__(self):
+ self.blob = Blob("CELG")
+ self.head = self.blob.item("common header")
+ self.images = collections.OrderedDict() # key -> RGBA
+ self.anims = Anims("")
+ self.sprites = None
+ self.meta = {}
+
+ def image(self, path):
+ if path not in self.images:
+ s = tex(path)
+ assert s is not None, path
+ self.images[path] = s.image()
+ return path
+
+ def collect(self):
+ b = self.anims.add_bank("player", self.image, PLAYER_ANIMS)
+ for path, (hair, carry) in b.meta.items():
+ fam = family("characters/player/" + path)
+ hairs = hair.split("|") if hair is not None else []
+ for i, s in enumerate(fam):
+ m = [0, 0, 0, 1]
+ if i < len(hairs):
+ h = hairs[i].strip()
+ if h == "x":
+ m[3] = 0
+ elif h:
+ if ":" in h:
+ h, fr = h.split(":")
+ m[2] = int(fr)
+ hx, hy = h.split(",")
+ m[0], m[1] = int(hx), int(hy)
+ self.meta[s.path] = m
+ for p in ("characters/player/hair00", "characters/player/bangs00", "characters/player/bangs01",
+ "characters/player/bangs02"):
+ self.image(p)
+ for bank in ("strawberry", "ghostberry", "goldberry", "strawberrySeed"):
+ self.anims.add_bank(bank, self.image)
+ for f in family("objects/refill/idle") + family("objects/refill/flash"):
+ self.image(f.path)
+ self.image("objects/refill/outline")
+ for f in family("objects/spring/"):
+ self.image(f.path)
+ for f in family("collectables/strawberry/wings"):
+ self.image(f.path)
+
+ def palette(self):
+ 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
+ extra = kmeans(counts, set(fixed), COMMON - len(fixed))
+ cols = fixed + extra
+ print(f"common: {len(counts)} colours -> {len(cols)}")
+ return cols
+
+ def build(self):
+ self.collect()
+ self.cols = self.palette()
+ pal = Palette(self.cols)
+ self.pal = pal
+ self.sprites = SpriteSet(self.blob, "common")
+ for k, img in self.images.items():
+ self.sprites.add(k, pal.map(img))
+ for k in self.images:
+ H.append(f"#define S_{cname(k)} {self.sprites.ids[k]}")
+ anims = self.anims.write(self.blob, self.sprites)
+ # Madeline's frames: hair x, y (signed), bangs frame | has hair << 7, one each sprite id (0 for the others)
+ meta = self.blob.item("player meta")
+ n = len(self.sprites.list)
+ meta.u16(n)
+ inv = {v: k for k, v in self.sprites.ids.items()}
+ for i in range(n):
+ m = self.meta.get(inv[i], [0, 0, 0, 1])
+ meta.s8(m[0]).s8(m[1]).u8(m[2] | m[3] << 7)
+ # hair: hair00 and bangs 0-2 as 1-bit masks 10x10 (bit x of row y), the bangs' shade (2: dark) as a second mask
+ hair = self.blob.item("hair")
+ for p in ("characters/player/hair00", "characters/player/bangs00", "characters/player/bangs01",
+ "characters/player/bangs02"):
+ img = self.images[p]
+ for y in range(10):
+ v = sum(1 << x for x in range(10) if img[y, x, 3] >= 128)
+ hair.u16(v)
+ for y in range(10):
+ v = sum(1 << x for x in range(10) if img[y, x, 3] >= 128 and img[y, x, 0] < 200)
+ hair.u16(v)
+ table = self.sprites.table()
+ self.blob.add(table)
+ h = self.head
+ h.raw(b"CELG").u8(FORMAT)
+ h.raw(pal.rgb1555(0, COMMON))
+ h.ref(table).ref(anims).ref(meta).ref(hair)
+ H.append(f"#define COMMON {COMMON}")
+ return self.blob.write()
+
+
+# ------------------------------------------------------------------ chapters
+
+def is_air(c):
+ return c in ("0", "\0")
+
+
+class Tiles:
+ """A chapter's 8x8 tiles: 64 bytes each (0: see-through), deduplicated; tile 0 is none."""
+
+ def __init__(self):
+ self.ids = {bytes(64): 0}
+ self.list = [bytes(64)]
+
+ def add(self, idx):
+ key = bytes(idx.astype(np.uint8).reshape(-1).tolist())
+ if key not in self.ids:
+ self.ids[key] = len(self.list)
+ self.list.append(key)
+ return self.ids[key]
+
+ def opaque(self, i):
+ return 0 not in self.list[i]
+
+
+def autotile_rect(sets, get, rect, force, behaviour, level_bounds, rnd):
+ """Autotiler.Generate for one rectangle (GenerateBox, GenerateOverlay): {(x, y): (qx, qy)} of the tileset of
+ `force`. get(x, y): the map's character there (None: no map)."""
+ rx, ry, rw, rh = rect
+
+ def inside(x, y):
+ return rx <= x < rx + rw and ry <= y < ry + rh
+
+ def check(t, x, y):
+ if inside(x, y):
+ return True
+ c = get(x, y)
+ if c is None:
+ return behaviour.edges_extend
+ return not is_air(c) and not t.ignore(c)
+
+ def same(x1, y1, x2, y2):
+ return any(lx <= x1 < lx + lw and ly <= y1 < ly + lh and lx <= x2 < lx + lw and ly <= y2 < ly + lh
+ for lx, ly, lw, lh in level_bounds)
+
+ out = {}
+ t = sets[force]
+ for x in range(rx, rx + rw):
+ for y in range(ry, ry + rh):
+ adj, full = [], True
+ for i in (-1, 0, 1):
+ for j in (-1, 0, 1):
+ f = check(t, x + j, y + i)
+ if not f and behaviour.edges_ignore_out and not same(x, y, x + j, y + i):
+ f = True
+ adj.append(1 if f else 0)
+ full = full and f
+ tl = None
+ if full:
+ if behaviour.padding_ignore_out:
+ pad = any(not check(t, x + dx, y + dy) and same(x, y, x + dx, y + dy)
+ for dx, dy in ((-2, 0), (2, 0), (0, -2), (0, 2)))
+ else:
+ pad = any(not check(t, x + dx, y + dy) for dx, dy in ((-2, 0), (2, 0), (0, -2), (0, 2)))
+ tl = t.padded if pad else t.center
+ else:
+ for m, tiles, sprites in t.masks:
+ if all(m[k] == 2 or m[k] == adj[k] for k in range(9)):
+ tl = tiles
+ break
+ if tl:
+ out[(x, y)] = rnd.choice(tl)
+ return out
+
+
+# entity types: name -> (code name, extra fields); every kind the chapters have that the CE plays
+ENTITY_TYPES = ["player", "spikesUp", "spikesDown", "spikesLeft", "spikesRight", "jumpThru", "zipMover", "strawberry",
+ "goldenBerry", "crumbleBlock", "refill", "spring", "wallSpringLeft", "wallSpringRight", "cassetteBlock",
+ "fallingBlock", "flutterbird", "fakeWall", "dashBlock", "lightbeam", "checkpoint", "bonfire",
+ "cassette", "npc", "coverupWall", "memorial", "memorialTextController", "birdForsakenCityGem", "wire",
+ "blackGem"]
+TRIGGER_TYPES = ["cameraOffsetTrigger", "cameraTargetTrigger", "changeRespawnTrigger", "eventTrigger",
+ "goldenBerryCollectTrigger"]
+POSITION_MODES = ["NoEffect", "LeftToRight", "RightToLeft", "TopToBottom", "BottomToTop", "HorizontalCenter",
+ "VerticalCenter"]
+
+
+class Chapter:
+ def __init__(self, name, number, common):
+ self.name = name
+ self.number = number
+ self.style = AREA_STYLE.get(number, dict(jumpthru="wood", spike="default", crumble="default"))
+ self.common = common
+ self.ch = pack.Chapter(name)
+ self.fgsets = T.read_tilesets("ForegroundTiles")
+ self.bgsets = T.read_tilesets("BackgroundTiles")
+ at = pack.ET.parse(os.path.join(CELESTE, "Graphics", "AnimatedTiles.xml")).getroot()
+ anim_frames = {sp.get("name"): len(pack.TEX.family(sp.get("path"))) for sp in at.iter("sprite")}
+ self.ch.generate(self.fgsets, self.bgsets, anim_frames)
+ self.blob = Blob("CEL%d" % number)
+ self.head = self.blob.item("chapter header")
+ self.imgs = {}
+ self.rnd = random.Random(number)
+
+ # -------------------------------------------------------------- pictures
+ def image(self, path):
+ if path not in self.imgs:
+ s = tex(path)
+ assert s is not None, path
+ self.imgs[path] = s.image()
+ return self.imgs[path]
+
+ def tileset(self, layer, c):
+ t = (self.fgsets if layer == 0 else self.bgsets)[c]
+ return self.image(t.path)
+
+ def cell_rgba(self, layer, gx, gy):
+ """The tile the game draws at map cell (gx, gy) of a layer, RGBA 8x8 (None: none)."""
+ tiles = self.ch.fgt if layer == 0 else self.ch.bgt
+ vm = self.ch.fgmap if layer == 0 else self.ch.bgmap
+ c = vm[gx, gy]
+ if is_air(c):
+ return None
+ t = tiles.get((gx, gy))
+ if not t or t[0] is None:
+ return None
+ qx, qy = t[0]
+ return self.tileset(layer, c)[qy * 8:qy * 8 + 8, qx * 8:qx * 8 + 8]
+
+ def room_cells(self, r):
+ """(layer, room cell x, y, RGBA) of a room's tiles with MARGIN cells around."""
+ TX, TY, TW, TH = self.ch.tb
+ x0, y0 = r.x // 8 - MARGIN - TX, r.y // 8 - MARGIN - TY
+ tw, th = r.w // 8 + 2 * MARGIN, r.h // 8 + 2 * MARGIN
+ for layer in (0, 1):
+ for y in range(th):
+ for x in range(tw):
+ img = self.cell_rgba(layer, x0 + x, y0 + y)
+ if img is not None:
+ yield layer, x, y, img
+ # scenery tiles drawn over the autotiled ones (fgtiles / bgtiles: tilesets/scenery, 8x8 each)
+ for layer, name in ((0, "fgtiles"), (1, "bgtiles")):
+ for x, y, v in self.csv_cells(r, name):
+ sc = self.image("tilesets/scenery")
+ cols = sc.shape[1] // 8
+ yield layer, x + MARGIN, y + MARGIN, ("scenery", sc[(v // cols) * 8:(v // cols) * 8 + 8,
+ (v % cols) * 8:(v % cols) * 8 + 8])
+
+ @staticmethod
+ def csv_cells(r, name):
+ out = []
+ el = r.e.child(name)
+ if el is not None and el.get("innerText"):
+ for y, row in enumerate(el.get("innerText").replace("\r", "").split("\n")):
+ for x, v in enumerate(row.split(",")):
+ v = v.strip()
+ if v and v != "-1":
+ out.append((x, y, int(v)))
+ return out
+
+ def solid_char(self, gx, gy):
+ """The map's fg character at map cell (gx, gy) (map-wide grid coordinates), None outside the map."""
+ TX, TY, TW, TH = self.ch.tb
+ if not (0 <= gx < TW and 0 <= gy < TH):
+ return None
+ return self.ch.fgmap[gx, gy]
+
+ def decal_paths(self):
+ out = []
+ for r in self.ch.rooms:
+ for layer in ("fgdecals", "bgdecals"):
+ el = r.e.child(layer)
+ for d in (el.children if el else []):
+ p = decal_base(d["texture"])
+ if p not in out:
+ out.append(p)
+ return out
+
+ def background(self):
+ """The chapter's parallax backgrounds as one picture (320 x 180), as they look from the chapter's middle
+ height: the CE has no time to draw five layers a frame. The foreground's additive gradient (purplesunset)
+ is the chapter's tint, added to every colour (src/data.c)."""
+ bgs, fgs = pack.styleground_list(self.ch)
+ layers = [(n, a) for n, a in bgs if n == "parallax" and a.get("texture", "").startswith("bgs/")]
+ self.tint = (0, 0, 0)
+ for n, a in fgs:
+ if n == "parallax" and a.get("blendmode") == "additive" and a.get("texture") == "purplesunset":
+ g = Atlas("Misc")["purplesunset"].image()[..., :3].reshape(-1, 3).mean(0) * float(a.get("alpha", 1))
+ self.tint = tuple(int(v) for v in g)
+ if not layers:
+ return None
+ W, Hh = 320, 180
+ out = np.zeros((Hh, W, 3), np.float64)
+ cams = [(r.x + r.w / 2 - 160, r.y + r.h / 2 - 90) for r in self.ch.rooms]
+ cy = float(np.median([c[1] for c in cams]))
+ self.bg_cam = (0, int(cy))
+ for n, a in layers:
+ s = tex(a["texture"])
+ if s is None:
+ continue
+ img = s.image().astype(np.float64)
+ alpha = float(a.get("alpha", 1))
+ py = int(np.floor(a.get("y", 0) - cy * a.get("scrolly", 0)))
+ px = int(np.floor(a.get("x", 0)))
+ tw, th = img.shape[1], img.shape[0]
+ for y in range(Hh):
+ sy = y - py
+ if not 0 <= sy < th:
+ continue
+ row = img[sy][(np.arange(W) - px) % tw]
+ a1 = row[:, 3:4] / 255 * alpha
+ out[y] = out[y] * (1 - a1) + row[:, :3] * alpha
+ return np.clip(out, 0, 255).astype(np.uint8)
+
+ # -------------------------------------------------------------- building
+ def build(self):
+ common = self.common
+ bg = self.background()
+ counts = collections.Counter()
+ cells = {}
+ for r in self.ch.rooms:
+ cells[r.name] = list(self.room_cells(r))
+ for layer, x, y, img in cells[r.name]:
+ count_colors(img[1] if isinstance(img, tuple) else img, counts)
+ decals = self.decal_paths()
+ for p in decals:
+ for s in decal_family(p):
+ count_colors(s.image(), counts)
+ if bg is not None:
+ bgc = np.concatenate([bg, np.full(bg.shape[:2] + (1,), 255, np.uint8)], 2)
+ count_colors(bgc, counts)
+ ent_paths = self.entity_images()
+ for p in ent_paths:
+ count_colors(self.image(p), counts)
+ extra = kmeans(counts, set(common.cols), 256 - COMMON)
+ pal = Palette(common.cols + extra)
+ self.pal = pal
+ print(f"{self.name}: {len(counts)} colours, {len(extra)} of its own")
+ self.tiles = Tiles()
+ self.sprites = SpriteSet(self.blob, "chapter")
+ # decals' sprites: each family's frames in a row (an animated decal plays them)
+ self.decal_ids = {}
+ for p in decals:
+ fam = decal_family(p)
+ first = None
+ for s in fam:
+ i = self.sprites.add(s.path, pal.map(s.image()))
+ first = i if first is None else first
+ self.decal_ids[p] = (first, len(fam))
+ for p in ent_paths:
+ self.sprites.add(p, pal.map(self.image(p)))
+ rooms = []
+ for r in self.ch.rooms:
+ rooms.append(self.room(r, cells[r.name]))
+ # tiles: 1000 a part
+ chunks = []
+ for i in range(0, len(self.tiles.list), 1000):
+ it = self.blob.item("tiles %d" % i)
+ for t in self.tiles.list[i:i + 1000]:
+ it.raw(t)
+ chunks.append(it)
+ flags = self.blob.item("tile flags")
+ for i in range(len(self.tiles.list)):
+ flags.u8(1 if self.tiles.opaque(i) else 0)
+ table = self.sprites.table()
+ self.blob.add(table)
+ bgit = None
+ if bg is not None:
+ idx = pal.map(np.concatenate([bg, np.full(bg.shape[:2] + (1,), 255, np.uint8)], 2))
+ bgit = []
+ for y0 in range(0, idx.shape[0], 180):
+ bgit.append(self.blob.item("background").raw(bytes(idx[y0:y0 + 180].reshape(-1).tolist())))
+ h = self.head
+ h.raw(b"CELC").u8(FORMAT).u8(self.number)
+ h.raw(pal.rgb1555(COMMON, 256))
+ h.u8(self.tint[0]).u8(self.tint[1]).u8(self.tint[2])
+ h.u16(len(self.tiles.list)).u8(len(chunks))
+ for c in chunks:
+ h.ref(c)
+ h.ref(flags).ref(table)
+ if bgit:
+ h.u8(1).s24(self.bg_cam[0]).s24(self.bg_cam[1]).ref(bgit[0])
+ else:
+ h.u8(0).s24(0).s24(0).u24(0)
+ h.u16(len(rooms))
+ for it in rooms:
+ h.ref(it)
+ print(f"{self.name}: {len(self.tiles.list)} tiles, {len(self.sprites.list)} sprites, {len(rooms)} rooms")
+ return self.blob.write()
+
+ def entity_images(self):
+ """Textures the chapter's entities draw (they get the chapter's colours)."""
+ st = self.style
+ out = []
+ for d in ("up", "down", "left", "right"):
+ out += [s.path for s in family("danger/spikes/%s_%s" % (st["spike"], d))]
+ return out
+
+ 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
+ grids = [[[0] * tw for _ in range(th)] for _ in range(2)]
+ imgs = [[[None] * tw for _ in range(th)] for _ in range(2)]
+ for layer, x, y, img in cells:
+ if isinstance(img, tuple): # scenery over the tile
+ base = imgs[layer][y][x]
+ sc = img[1]
+ if base is None:
+ imgs[layer][y][x] = sc
+ else:
+ m = sc[..., 3:4] >= 128
+ imgs[layer][y][x] = np.where(m, sc, base)
+ else:
+ imgs[layer][y][x] = img
+ for layer in (0, 1):
+ for y in range(th):
+ for x in range(tw):
+ if imgs[layer][y][x] is not None:
+ grids[layer][y][x] = self.tiles.add(self.pal.map(imgs[layer][y][x]))
+ # collision: the fg characters (solid even where no tile is drawn)
+ TX, TY, TW, TH = self.ch.tb
+ x0, y0 = r.x // 8 - MARGIN - TX, r.y // 8 - MARGIN - TY
+ solid = [[0 if is_air(self.ch.fgmap[x0 + x, y0 + y]) else 1 for x in range(tw)] for y in range(th)]
+ it = self.blob.item("room " + r.name)
+ name = r.name.encode()
+ it.u8(len(name)).raw(name)
+ it.s24(r.x).s24(r.y).u16(r.w).u16(r.h)
+ fl = sum(b for k, b in ROOM_FLAGS if r.e.get(k))
+ it.u8(fl).s8(int(r.e.get("cameraOffsetX", 0))).s8(int(r.e.get("cameraOffsetY", 0)))
+ it.u16(tw).u16(th)
+ # the grids: each cell a byte, its tile's number in the room's own list of tiles (u16 chapter tiles), the fg
+ # grid, the bg grid, then a bit a cell for what is solid (bit x & 7 of byte x >> 3 of each row), zx0 packed
+ ids = sorted(set(v for g in grids for row in g for v in row) | {0})
+ assert len(ids) <= 256, (r.name, len(ids))
+ loc = {v: i for i, v in enumerate(ids)}
+ raw = bytearray()
+ for g in grids:
+ for row in g:
+ raw += bytes(loc[v] for v in row)
+ rb = (tw + 7) // 8
+ for row in solid:
+ bits = bytearray(rb)
+ for x, v in enumerate(row):
+ if v:
+ bits[x >> 3] |= 1 << (x & 7)
+ raw += bits
+ packed = zx0(bytes(raw))
+ it.u8(len(ids) - 1)
+ for v in ids:
+ it.u16(v)
+ it.u16(len(raw))
+ it.ref(self.blob.item("grid " + r.name).raw(packed))
+ it.ref(self.decals(r))
+ ents, trigs = self.entities(r)
+ it.ref(ents).ref(trigs)
+ return it
+
+ def rows(self, r, grid, solid):
+ """A layer's rows: a pointer each, then each row's runs: u8 n, u16 tile (bit 15: solid, fg only)."""
+ th, tw = len(grid), len(grid[0])
+ table = self.blob.item("rows " + r.name)
+ data = []
+ for y in range(th):
+ line = [grid[y][x] | (0x8000 if solid and solid[y][x] else 0) for x in range(tw)]
+ it = Item("row")
+ x = 0
+ while x < tw:
+ v = line[x]
+ n = 1
+ while x + n < tw and line[x + n] == v and n < 255:
+ n += 1
+ it.u8(n).u16(v)
+ x += n
+ data.append(it)
+ for it in data:
+ table.ref(it)
+ # rows go after their table, packed into items of up to 4 KB (an item never straddles two appvars)
+ cur = None
+ for it in data:
+ if cur is None or cur.size() + it.size() > 4096:
+ cur = self.blob.item("row data " + r.name)
+ # the row's pointer is to its own bytes inside `cur`: make it an item of its own laid out within cur
+ cur.chunks.append(it)
+ return table
+
+ def decals(self, r):
+ """u8 bg count, u8 fg count, then each: u16 sprite, s16 x, s16 y (its centre, room coordinates),
+ u8 flags (1 flip x, 2 flip y), u8 frames (an animated one plays them, 12 a second)."""
+ it = self.blob.item("decals " + r.name)
+ lists = []
+ for layer in ("bgdecals", "fgdecals"):
+ el = r.e.child(layer)
+ lst = []
+ for d in (el.children if el else []):
+ p = decal_base(d["texture"])
+ sid, n = self.decal_ids[p]
+ if sid is None:
+ continue
+ fl = (1 if d.get("scaleX", 1) < 0 else 0) | (2 if d.get("scaleY", 1) < 0 else 0)
+ lst.append((sid, int(round(d["x"])), int(round(d["y"])), fl, n))
+ lists.append(lst)
+ it.u8(len(lists[0])).u8(len(lists[1]))
+ for lst in lists:
+ for sid, x, y, fl, n in lst:
+ it.u16(sid).s16(x).s16(y).u8(fl).u8(n)
+ return it
+
+ def entities(self, r):
+ """Records: u8 type, u8 size, s16 x, y (room), u16 w, h, u16 id, u8 nodes, nodes (s16 x, y), u8 flags,
+ u8 n, u16 values[n] (each type's own: tiles, numbers)."""
+ out = []
+ for kind, types in (("entities", ENTITY_TYPES), ("triggers", TRIGGER_TYPES)):
+ el = r.e.child(kind)
+ it = self.blob.item(kind + " " + r.name)
+ recs = []
+ for e in (el.children if el else []):
+ if e.name not in types:
+ if e.name not in E.DROP and e.name not in E.DROP_TRIGGERS:
+ MISSING[e.name] += 1
+ continue
+ recs.append(self.entity(r, e, types.index(e.name)))
+ it.u8(len(recs))
+ for rec in recs:
+ it.raw(rec)
+ out.append(it)
+ return out
+
+ def entity(self, r, e, t):
+ a = lambda k, d=None: (E.attr(e, k) if E.attr(e, k) is not None else d) # noqa: E731
+ x, y = int(e["x"]), int(e["y"])
+ w, h = int(e.get("width", 0)), int(e.get("height", 0))
+ nodes = [(int(n["x"]), int(n["y"])) for n in e.children]
+ flags = 0
+ vals = []
+ n = e.name
+ if n.startswith("spikes"):
+ d = n[6:].lower()
+ fam = family("danger/spikes/%s_%s" % (self.style["spike"], d))
+ size = w if d in ("up", "down") else h
+ for j in range(max(1, size // 8)):
+ vals.append(self.sprites.ids[self.rnd.choice(fam).path])
+ elif n == "jumpThru":
+ tname = a("texture", "default")
+ tname = self.style["jumpthru"] if tname in ("default", None) else tname
+ img = self.image("objects/jumpthru/" + tname)
+ cols = img.shape[1] // 8
+ TX, TY, TW, TH = self.ch.tb
+ gx, gy = (r.x + x) // 8 - TX, (r.y + y) // 8 - TY
+ ncol = max(1, w // 8)
+ for i in range(ncol):
+ if i == 0:
+ c, row = 0, 0 if self.solid_at(gx - 1, gy, (r.x + x - 1) % 8) else 1
+ elif i == ncol - 1:
+ c, row = cols - 1, 0 if self.solid_at(gx + ncol, gy, 0) else 1
+ else:
+ c, row = 1 + self.rnd.randrange(cols - 2), self.rnd.choice((0, 1))
+ vals.append(self.tiles.add(self.pal.map(img[row * 8:row * 8 + 8, c * 8:c * 8 + 8])))
+ elif n == "crumbleBlock":
+ img = self.image("objects/crumbleBlock/" + self.style["crumble"])
+ out = self.image("objects/crumbleBlock/outline")
+ for j in range(0, max(8, w), 8):
+ k = ((abs(r.x + x) + j) // 8) % 4
+ vals.append(self.tiles.add(self.pal.map(img[:8, k * 8:k * 8 + 8])))
+ for j in range(0, max(8, w), 8):
+ k = 3 if w <= 8 else 0 if j == 0 else 1 if j < w - 8 else 2
+ vals.append(self.tiles.add(self.pal.map(out[:8, k * 8:k * 8 + 8])))
+ elif n in ("fallingBlock", "dashBlock", "fakeWall", "coverupWall"):
+ c = str(a("tiletype", "3"))
+ blend = n in ("fakeWall", "coverupWall") or (n == "dashBlock" and a("blendin", False))
+ if n == "fallingBlock":
+ flags |= 1 if a("climbFall", True) else 0
+ flags |= 2 if a("behind", False) else 0
+ if n == "dashBlock":
+ flags |= 1 if a("permanent", True) else 0
+ flags |= 2 if a("canDash", True) else 0
+ flags |= 4 if blend else 0
+ vals += self.block_tiles(r, x, y, w, h, c, blend)
+ elif n == "zipMover":
+ pass
+ elif n in ("strawberry", "goldenBerry"):
+ flags |= 1 if a("winged", False) else 0
+ flags |= 2 if a("moon", False) else 0
+ vals += [int(a("checkpointID", -1)) & 0xFFFF, int(a("order", -1)) & 0xFFFF]
+ elif n == "refill":
+ flags |= 1 if a("twoDash", False) else 0
+ flags |= 2 if a("oneUse", False) else 0
+ elif n == "cassetteBlock":
+ vals += [int(a("index", 0)), int(round(float(a("tempo", 1)) * 100))]
+ elif n == "cameraOffsetTrigger":
+ vals += [int(round(float(a("cameraX", 0)) * 48)) & 0xFFFF, int(round(float(a("cameraY", 0)) * 32)) & 0xFFFF]
+ elif n == "cameraTargetTrigger":
+ vals += [int(round(float(a("lerpStrength", 0)) * 256)), POSITION_MODES.index(a("positionMode", "NoEffect"))]
+ flags |= (1 if a("xOnly", False) else 0) | (2 if a("yOnly", False) else 0)
+ elif n == "eventTrigger":
+ vals += [EVENTS.setdefault(a("event", ""), len(EVENTS))]
+ elif n == "bonfire":
+ flags |= {"unlit": 0, "lit": 1, "smoking": 2}.get(str(a("mode", "unlit")).lower(), 0)
+ elif n == "wire":
+ flags |= 1 if a("above", False) else 0
+ rec = bytearray(struct.pack("<BBhhHHH", t, 0, x, y, w, h, int(e.get("id", 0)) & 0xFFFF))
+ rec.append(len(nodes))
+ for nx, ny in nodes:
+ rec += struct.pack("<hh", nx, ny)
+ rec.append(flags)
+ rec.append(len(vals))
+ for v in vals:
+ rec += struct.pack("<H", v)
+ assert len(rec) < 256, (n, len(rec))
+ rec[1] = len(rec)
+ return bytes(rec)
+
+ def solid_at(self, gx, gy, _sub=0):
+ c = self.solid_char(gx, gy)
+ return c is not None and not is_air(c)
+
+ def block_tiles(self, r, x, y, w, h, c, blend):
+ """An autotiled block's tiles (row-major, w/8 x h/8): GenerateBox, or GenerateOverlay over the map's solids
+ (blending with what is around)."""
+ tw, th = max(1, w // 8), max(1, h // 8)
+ TX, TY, TW, TH = self.ch.tb
+ gx, gy = (r.x + x) // 8 - TX, (r.y + y) // 8 - TY
+ if blend:
+ beh = T.Behaviour(True, True, True)
+ got = autotile_rect(self.fgsets, self.solid_char, (gx, gy, tw, th), c, beh, self.ch.level_bounds, self.rnd)
+ else:
+ beh = T.Behaviour(False, False, False)
+ got = autotile_rect(self.fgsets, lambda X, Y: None, (0, 0, tw, th), c, beh, [], self.rnd)
+ got = {(gx + k[0], gy + k[1]): v for k, v in got.items()}
+ img = self.image(self.fgsets[c].path)
+ out = []
+ for j in range(th):
+ for i in range(tw):
+ q = got.get((gx + i, gy + j))
+ if q is None:
+ out.append(0)
+ else:
+ qx, qy = q
+ out.append(self.tiles.add(self.pal.map(img[qy * 8:qy * 8 + 8, qx * 8:qx * 8 + 8])))
+ return out
+
+
+EVENTS = {}
+MISSING = collections.Counter()
+
+
+ZX0_CACHE = {}
+
+
+def zx0(data):
+ """data packed with ZX0 (the CE's zx0_Decompress unpacks it), by the CE toolchain's convbin."""
+ import hashlib
+ import subprocess
+ import tempfile
+ key = hashlib.sha1(data).hexdigest()
+ cache = os.path.join(os.environ["CELESTE_CACHE"], "zx0")
+ os.makedirs(cache, exist_ok=True)
+ path = os.path.join(cache, key)
+ if os.path.exists(path):
+ return open(path, "rb").read()
+ cedev = os.environ.get("CEDEV", os.path.expanduser("~/Documents/Assets/toolchains/CEdev"))
+ with tempfile.TemporaryDirectory() as d:
+ src, dst = os.path.join(d, "in.bin"), os.path.join(d, "out.bin")
+ open(src, "wb").write(data)
+ subprocess.run([os.path.join(cedev, "bin", "convbin"), "-l", "0", "-j", "bin", "-k", "bin", "-c", "zx0", "-i", src,
+ "-o", dst], check=True)
+ out = open(dst, "rb").read()
+ open(path, "wb").write(out)
+ return out
+
+
+def decal_base(path):
+ p = "decals/" + path.replace("\\", "/")
+ if p.endswith(".png"):
+ p = p[:-4]
+ return p
+
+
+def decal_family(p):
+ base = re.sub(r"\d+$", "", p)
+ fam = GAMEPLAY.prefix(base) if not p.startswith("decals/6-reflection/secret_") else []
+ if not fam:
+ fam = family(p)
+ return fam
+
+
+def main():
+ os.makedirs(OUT, exist_ok=True)
+ H[:] = ["/* Generated by tools/pack_ce.py: the ids of the appvars' contents. */", "#ifndef GEN_H", "#define GEN_H"]
+ common = Common()
+ common.build()
+ for name, number in CHAPTERS:
+ Chapter(name, number, common).build()
+ for i, n in enumerate(ENTITY_TYPES):
+ H.append(f"#define ET_{cname(n)} {i}")
+ for i, n in enumerate(TRIGGER_TYPES):
+ H.append(f"#define TT_{cname(n)} {i}")
+ for n, i in EVENTS.items():
+ H.append(f"#define EV_{cname(n)} {i}")
+ H.append(f"#define FORMAT {FORMAT}")
+ H.append(f"#define MARGIN {MARGIN}")
+ H.append("#endif")
+ open(GEN_H, "w").write("\n".join(H) + "\n")
+ if MISSING:
+ print("not in the CE version:", dict(MISSING))
+
+
+if __name__ == "__main__":
+ main()