Skip to content

Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.

Celeste: the CE version's menus in the game's style

Mason363aa151d0e2df4
diff --git a/games/celeste/ce/data/CEL10.bin b/games/celeste/ce/data/CEL10.bin
index 46455e6d..1116f129 100644
Binary files a/games/celeste/ce/data/CEL10.bin and b/games/celeste/ce/data/CEL10.bin differ
diff --git a/games/celeste/ce/data/CEL11.bin b/games/celeste/ce/data/CEL11.bin
index 766fa166..84a3ed60 100644
Binary files a/games/celeste/ce/data/CEL11.bin and b/games/celeste/ce/data/CEL11.bin differ
diff --git a/games/celeste/ce/data/CEL12.bin b/games/celeste/ce/data/CEL12.bin
index 6a00d09e..6d55eb60 100644
Binary files a/games/celeste/ce/data/CEL12.bin and b/games/celeste/ce/data/CEL12.bin differ
diff --git a/games/celeste/ce/data/CEL13.bin b/games/celeste/ce/data/CEL13.bin
index bd28abf3..7ec12add 100644
Binary files a/games/celeste/ce/data/CEL13.bin and b/games/celeste/ce/data/CEL13.bin differ
diff --git a/games/celeste/ce/data/CEL14.bin b/games/celeste/ce/data/CEL14.bin
index 687d23fa..58f426d8 100644
Binary files a/games/celeste/ce/data/CEL14.bin and b/games/celeste/ce/data/CEL14.bin differ
diff --git a/games/celeste/ce/data/CELG0.bin b/games/celeste/ce/data/CELG0.bin
index 7f02df2c..a785e203 100644
Binary files a/games/celeste/ce/data/CELG0.bin and b/games/celeste/ce/data/CELG0.bin differ
diff --git a/games/celeste/ce/data/CELG1.bin b/games/celeste/ce/data/CELG1.bin
index c0fceccc..5b85053e 100644
Binary files a/games/celeste/ce/data/CELG1.bin and b/games/celeste/ce/data/CELG1.bin differ
diff --git a/games/celeste/ce/host/plat_host.c b/games/celeste/ce/host/plat_host.c
index 13ff86ed..e6c50a9f 100644
--- a/games/celeste/ce/host/plat_host.c
+++ b/games/celeste/ce/host/plat_host.c
@@ -135,7 +135,7 @@ unsigned plat_keys(void) {
{ int cnt[256] = {0}; for (int i = 0; i < g_nents; i++) if (g_ents[i].type != 255) cnt[g_ents[i].type]++;
printf("ents:"); for (int t = 0; t < 256; t++) if (cnt[t]) printf(" %d:%d", t, cnt[t]); printf("\n"); }
for (int i = 0; i < g_nents; i++)
- if (g_ents[i].type == ET_zipMover) printf("zip at %d %d (%d x %d)\n", g_ents[i].x - rm->x, g_ents[i].y - rm->y, g_ents[i].hw, g_ents[i].hh);
+ if (g_ents[i].type == ET_zipMover || g_ents[i].type == ET_strawberry) printf("%s at %d %d (%d x %d)\n", g_ents[i].type == ET_zipMover ? "zip" : "berry", g_ents[i].x - rm->x, g_ents[i].y - rm->y, g_ents[i].hw, g_ents[i].hh);
printf("room %s tw %d th %d ntiles %d fg %d bg %d bg4 %d hasbg %d map %d %d %d\n", level_room_name(), rm->tw, rm->th,
rm->ntiles, nf, nb, nt, g_has_bg, g_bg_map[0], g_bg_map[1], g_bg_map[2]);
}
diff --git a/games/celeste/ce/makefile b/games/celeste/ce/makefile
index 2feb178c..eef84b87 100644
--- a/games/celeste/ce/makefile
+++ b/games/celeste/ce/makefile
@@ -1,7 +1,7 @@
# Celeste for the TI-84 Plus CE: a CE C toolchain project (CEdev v15).
# make bin/CELESTE.8xp and its appvars bin/CEL*.8xv
# make host build/host/celeste: the same game on a computer, for the tests and pictures
-# make test the tests (tests/run.py) on the computer build
+# make tests Madeline against the NumWorks port (tests/physics.py; make host in games/celeste first)
# make data data/ and src/gen.h again from the game (CELESTE=<its Content folder>)
all: target appvars
@@ -28,10 +28,10 @@ build/host/celeste: $(HOST_SRC) $(wildcard src/*.h)
@mkdir -p $(@D)
cc $(HOST_FLAGS) -fsanitize=address,undefined $(HOST_SRC) -lz -o $@
-test: build/host/celeste
- python3 tests/run.py build/host/celeste
+tests: build/host/celeste
+ python3 tests/physics.py build/host/celeste ../build/play
data:
python3 tools/pack_ce.py
-.PHONY: all appvars host test data
+.PHONY: all appvars host tests data
diff --git a/games/celeste/ce/src/ce.h b/games/celeste/ce/src/ce.h
index 12504c39..10c44eff 100644
--- a/games/celeste/ce/src/ce.h
+++ b/games/celeste/ce/src/ce.h
@@ -87,7 +87,8 @@ extern uint8_t g_bg8[320 * 180]; /* the room's picture of them */
extern int g_bg_refx, g_bg_refy; /* the camera it was made for */
extern uint8_t g_cells_gen; /* changes when the rooms' tiles do (draw.c keeps the view's cells) */
extern int g_chapter_berries; /* the chapter's strawberries */
-extern const uint8_t *g_remap, *g_remap_red, *g_remap_half; /* sprites drawn through g_remap if set */
+extern const uint8_t *g_remap, *g_remap_red, *g_remap_half, *g_remap_fade;
+extern const uint8_t *g_fonts[3]; /* Renogare: body text, titles, small (src/text.c) */ /* sprites drawn through g_remap if set */
/* ---------------------------------------------------------------- drawing (draw.c) */
enum { DF_FLIPX = 1, DF_FLIPY = 2, DF_SOLID = 4 };
@@ -114,8 +115,16 @@ void draw_rect_screen(int x, int y, int w, int h, uint8_t c); /* view coordina
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_text(const char *s, int x, int y, uint8_t c); /* a 5 x 7 font (before the appvars are open), screen */
+/* Renogare (src/text.c): FONT_BODY, FONT_TITLE; screen coordinates, (x, y) the line's top left; drawn in rgb over the
+ * colour `under` (its edges in between) */
+enum { FONT_BODY, FONT_TITLE, FONT_SMALL };
+int text_width(int font, const char *s);
+int text_height(int font);
+void text_draw(int font, const char *s, int x, int y, uint32_t rgb, uint32_t under);
+void text_center(int font, const char *s, int cx, int y, uint32_t rgb, uint32_t under);
+void text_right(int font, const char *s, int rx, int y, uint32_t rgb, uint32_t under);
+uint8_t pal_nearest(uint32_t rgb); /* the palette's colour nearest (as shown) */
void draw_cells_update(void); /* the view's cells, for the camera now */
extern int g_offx, g_offy; /* the camera in its cell */
void draw_layers_back(int ca, int cb, int ra, int rb); /* background, bg tiles: the view's cells [ca, cb] x [ra, rb] */
diff --git a/games/celeste/ce/src/data.c b/games/celeste/ce/src/data.c
index 3272dc6d..e1945dc1 100644
--- a/games/celeste/ce/src/data.c
+++ b/games/celeste/ce/src/data.c
@@ -3,6 +3,7 @@
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_fonts[3];
const uint8_t *g_tile_flags;
static const uint8_t *tile_chunks;
static int ntiles;
@@ -12,7 +13,7 @@ bool g_has_bg;
int g_bg_scrollx, g_bg_scrolly;
uint8_t g_bg_map[16];
int g_chapter_berries;
-const uint8_t *g_remap, *g_remap_red, *g_remap_half;
+const uint8_t *g_remap, *g_remap_red, *g_remap_half, *g_remap_fade;
static uint16_t pal[256];
static uint8_t tint[3];
@@ -34,6 +35,7 @@ bool data_open(void) {
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);
+ for (int i = 0; i < p[12] && i < 3; i++) g_fonts[i] = CPTR(p + 13 + 3 * i);
memcpy(pal, chead + 5, COMMON * 2);
return true;
}
@@ -49,8 +51,8 @@ bool chapter_open(int n) {
const uint8_t *p = h + 6 + (256 - COMMON) * 2;
memcpy(tint, p, 3);
g_chapter_berries = p[3];
- g_remap_red = p + 4, g_remap_half = p + 4 + 256;
- p += 4 + 512;
+ g_remap_red = p + 4, g_remap_half = p + 4 + 256, g_remap_fade = p + 4 + 512;
+ p += 4 + 768;
ntiles = (int)R16(p);
tile_chunks = p + 3;
p += 3 + 3 * p[2];
@@ -83,9 +85,22 @@ static uint16_t shade(uint16_t c, int fade) {
return (uint16_t)((r >> 3) << 10 | (g >> 3) << 5 | (b >> 3));
}
static int cur_fade = 256;
+uint8_t pal_nearest(uint32_t rgb) {
+ int r = (int)(rgb >> 19 & 31), g = (int)(rgb >> 11 & 31), b = (int)(rgb >> 3 & 31), best = BLACK;
+ unsigned bd = 0xFFFFFF;
+ for (int i = 3; i < 256; i++) { /* (not 0, the see-through key, nor the hair's) */
+ uint16_t c = shade(pal[i], 256);
+ int dr = (c >> 10 & 31) - r, dg = (c >> 5 & 31) - g, db = (c & 31) - b;
+ unsigned d = (unsigned)(dr * dr + dg * dg + db * db);
+ if (d < bd) bd = d, best = i;
+ }
+ return (uint8_t)best;
+}
static uint32_t cur_hair = 0xAC3232;
static bool hair_set;
+uint8_t g_palette_gen = 1; /* (changes with the palette: src/text.c finds its shades again) */
void palette_apply(int fade) {
+ if (++g_palette_gen == 0) g_palette_gen = 1;
uint16_t out[256];
cur_fade = fade;
out[0] = 0;
diff --git a/games/celeste/ce/src/draw.c b/games/celeste/ce/src/draw.c
index b93ec39a..cf3bc6ca 100644
--- a/games/celeste/ce/src/draw.c
+++ b/games/celeste/ce/src/draw.c
@@ -438,7 +438,6 @@ static const uint8_t FONT[96][5] = {
{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;
diff --git a/games/celeste/ce/src/game.c b/games/celeste/ce/src/game.c
index 7b63e385..d09cebf3 100644
--- a/games/celeste/ce/src/game.c
+++ b/games/celeste/ce/src/game.c
@@ -6,10 +6,10 @@ int g_berries_now;
int g_anchor_x, g_anchor_y, g_anchor_lerp;
uint8_t g_anchor_ignore;
-enum { SC_TITLE, SC_CHAPTERS, SC_PLAY, SC_PAUSE, SC_COMPLETE };
+enum { SC_KEYS, SC_TITLE, SC_CHAPTERS, SC_PLAY, SC_PAUSE, SC_COMPLETE };
static int screen = SC_TITLE, sel, chapter = 1;
static int screen_t;
-static bool full_redraw = true;
+static int full_redraw = 2; /* (frames to clear the screen in: both buffers) */
#ifdef CEL_BENCH
unsigned long g_bench[16], g_bench_last;
static int selftest;
@@ -27,6 +27,7 @@ typedef struct {
uint8_t checkpoints;
} ch[NCHAPTERS];
uint32_t total_deaths;
+ uint8_t keys_seen; /* the controls were shown */
} Save;
static Save save;
static void save_write(void) { plat_save("CELSAVE", &save, sizeof save); }
@@ -52,8 +53,9 @@ void save_add_death(void) {
save.total_deaths++;
}
-/* ---------------------------------------------------------------- text helpers */
-static void text_center(const char *s, int y, uint8_t c) { draw_text(s, 160 - text_width(s) / 2, y, c); }
+/* ---------------------------------------------------------------- words and pictures */
+#define C_WHITE 0xFFFFFFul
+#define C_GRAY 0x808080ul
static void num(char *out, uint32_t v) {
char t[12];
int n = 0;
@@ -62,16 +64,56 @@ static void num(char *out, uint32_t v) {
while (n) *out++ = t[--n];
*out = 0;
}
+static uint32_t highlight(void) { return screen_t % 12 < 6 ? 0x84FF54ul : 0xFCFF59ul; } /* TextMenu's, in turn */
+static void pic(int id, int cx, int cy) { /* a menu picture centred at (cx, cy), screen */
+ const uint8_t *sp = sprite(id);
+ int camx = g_camx, camy = g_camy;
+ g_camx = g_camy = 0;
+ draw_sprite(sp, cx - sp[0] / 2, cy - sp[1] / 2 - VIEW_Y, 0);
+ g_camx = camx, g_camy = camy;
+}
+static void prompt(const char *key, const char *what, int y) { /* "2nd" and what it does, at the bottom */
+ int gap = text_width(FONT_BODY, " "), kw = text_width(FONT_BODY, key);
+ int w = 10 + kw + gap + text_width(FONT_BODY, what), x = 160 - w / 2;
+ if (screen_t % 60 < 45) pic(S_gui_button, x + 3, y + 7);
+ text_draw(FONT_BODY, key, x + 10, y, C_WHITE, 0);
+ text_draw(FONT_BODY, what, x + 10 + kw + gap, y, C_GRAY, 0);
+}
+static void time_text(uint32_t frames, char *out) { /* m:ss.mmm */
+ uint32_t ms = frames * 50 / 3, m = ms / 60000, sec = ms / 1000 % 60;
+ num(out, m);
+ out += strlen(out);
+ *out++ = ':', *out++ = (char)('0' + sec / 10), *out++ = (char)('0' + sec % 10), *out++ = '.';
+ ms %= 1000;
+ *out++ = (char)('0' + ms / 100), *out++ = (char)('0' + ms / 10 % 10), *out++ = (char)('0' + ms % 10), *out = 0;
+}
+/* the chapter's icon over its banner (OuiChapterSelect's: "Chapter 1" small in the accent colour, the name in white;
+ * the icon at (960, 360) of 1080p, the banner's left top at (552, 620), the words right-aligned at its 816) */
+static void banner(void) {
+ pic(S_gui_city, 160, VIEW_Y + 60);
+ const uint8_t *b = sprite(S_gui_banner1);
+ int x = 92, top = VIEW_Y + 103;
+ pic(S_gui_banner1, x + b[0] / 2, top + b[1] / 2);
+ text_right(FONT_SMALL, "Chapter 1", x + 136, top + 3, 0x2f344bul, 0x6c7c81ul);
+ text_right(FONT_BODY, "Forsaken City", x + 136, top + 11, C_WHITE, 0x6c7c81ul);
+}
+static void stat_line(int icon, const char *t, int y) {
+ int w = text_width(FONT_BODY, t) + 16;
+ pic(icon, 160 - w / 2 + 5, y + 7);
+ text_draw(FONT_BODY, t, 160 - w / 2 + 14, y, C_WHITE, 0);
+}
/* ---------------------------------------------------------------- playing */
+static void hud_reset(void);
static void play_chapter(int ch) {
if (!chapter_open(ch)) return;
chapter = ch;
palette_apply(256);
g_berries_now = 0;
+ hud_reset();
level_load(ch, -1, INTRO_JUMP);
screen = SC_PLAY;
- full_redraw = true;
+ full_redraw = 2;
}
void game_chapter_end(void) {
@@ -85,22 +127,43 @@ void game_chapter_end(void) {
screen_t = 0;
}
-static void hud_draw(void) {
- /* the strawberry count, top left, while some are being collected (Celeste's TotalStrawberriesDisplay) */
- static int shown, timer;
- if (g_berries_now != shown) shown = g_berries_now, timer = 180;
- if (timer > 0) {
- timer--;
- char buf[16];
- buf[0] = 'x';
- num(buf + 1, (uint32_t)(berries_of(chapter)));
- draw_sprite(sprite(S_collectables_strawberry_normal00), g_camx + 2, g_camy + 2, 0);
- draw_text(buf, 22, VIEW_Y + 8, WHITE);
- draw_gone(0, 0, 22 + text_width(buf), 20); /* (drawn over the view: both buffers draw it again) */
+/* TotalStrawberriesDisplay: slides in from the left when strawberries are collected (Ease.CubeOut, 1.2 a second in,
+ * 2 out), counts them up one at a time (0.4 s, then 0.3 s each), stays 2 s; its 1080p places at 1/6 on the view */
+static struct { int lerp, update, wait, amount; bool started; } H; /* (lerp 1/256, times in frames) */
+static void hud_reset(void) { H.started = false, H.lerp = 0; }
+static void hud_update(void) {
+ int total = berries_of(chapter);
+ if (!H.started) H.started = true, H.amount = total;
+ if (total > H.amount && H.update <= 0) H.update = 24;
+ if (total > H.amount || H.update > 0 || H.wait > 0) H.lerp = imin(256, H.lerp + 256 * 12 / 10 / 60 + 1);
+ else H.lerp = imax(0, H.lerp - 256 * 2 / 60);
+ if (H.wait > 0) H.wait--;
+ if (H.update > 0 && H.lerp == 256 && --H.update <= 0) {
+ if (H.amount < total) H.amount++;
+ H.wait = 120;
+ if (H.amount < total) H.update = 18;
}
}
+static void hud_draw(void) {
+ if (H.lerp <= 0) return;
+ int t = 256 - H.lerp, e = 256 - t * t / 256 * t / 256; /* (CubeOut) */
+ int x = (-288 + (32 + 288) * e / 256) / 6, y = 16; /* (its 1080p x / 6, the view's y) */
+ const uint8_t *bg = sprite(S_gui_countbg), *st = sprite(S_gui_strawberry), *xs = sprite(S_gui_x);
+ int camx = g_camx, camy = g_camy;
+ g_camx = g_camy = 0;
+ draw_sprite(bg, x - 16, y - 1, 0);
+ draw_sprite(st, x + 5 - st[0] / 2, y - st[1] / 2, 0);
+ draw_sprite(xs, x + 10, y + 1 - xs[1] / 2, 0);
+ g_camx = camx, g_camy = camy;
+ char n[8];
+ num(n, (uint32_t)H.amount);
+ text_draw(FONT_BODY, n, x + 10 + xs[0], VIEW_Y + y - text_height(FONT_BODY) / 2, C_WHITE, 0x1a1a1aul);
+ draw_gone(0, 0, x + 40 + text_width(FONT_BODY, n), y + 12); /* (drawn over the view: both buffers draw it again) */
+}
/* ---------------------------------------------------------------- the frame */
+static bool ok_pressed(void) { return btn_pressed(&g_in.ok) || btn_pressed(&g_in.jump); }
+static void go(int sc) { screen = sc, sel = 0, screen_t = 0, full_redraw = 2; }
void game_frame(void) {
input_update(plat_keys());
if (g_in.keys & K_QUIT) {
@@ -110,39 +173,52 @@ void game_frame(void) {
}
screen_t++;
switch (screen) {
+ case SC_KEYS:
+ if (screen_t > 20 && ok_pressed()) save.keys_seen = 1, save_write(), go(SC_CHAPTERS);
+ break;
case SC_TITLE:
- if (btn_pressed(&g_in.ok) || btn_pressed(&g_in.jump)) screen = SC_CHAPTERS, sel = 0, full_redraw = true;
+ if (screen_t > 20 && ok_pressed()) go(save.keys_seen ? SC_CHAPTERS : SC_KEYS);
break;
case SC_CHAPTERS:
- if (btn_pressed(&g_in.back)) screen = SC_TITLE, full_redraw = true;
- else if (btn_pressed(&g_in.ok) || btn_pressed(&g_in.jump)) play_chapter(1);
+ if (btn_pressed(&g_in.back)) go(SC_TITLE);
+ else if (screen_t > 10 && ok_pressed()) play_chapter(1);
break;
case SC_PLAY:
- if (g_level.completed) {
- if (++screen_t > 90 && (btn_pressed(&g_in.ok) || btn_pressed(&g_in.jump))) screen = SC_CHAPTERS, full_redraw = true;
+ if (g_level.completed) { /* the end: the wipe closes, then what was done */
+ memset(&g_in, 0, sizeof g_in);
+ if (!g_level.wipe) g_level.wipe = 1;
+ level_update();
+ if (g_level.wipe >= 24) go(SC_COMPLETE);
break;
}
if (btn_pressed(&g_in.pause) && !g_player.dead && !g_level.transitioning) {
btn_consume(&g_in.pause);
- screen = SC_PAUSE, sel = 0;
+ screen = SC_PAUSE, sel = 0, screen_t = 0;
break;
}
level_update();
+ hud_update();
break;
case SC_PAUSE:
- if (btn_pressed(&g_in.back) || btn_pressed(&g_in.pause)) screen = SC_PLAY;
- else if (g_in.move_y && !(g_in.prev & (K_UP | K_DOWN))) sel = (sel + g_in.move_y + 3) % 3;
- else if (btn_pressed(&g_in.ok) || btn_pressed(&g_in.jump)) {
+ if (btn_pressed(&g_in.back) || btn_pressed(&g_in.pause)) {
+ btn_consume(&g_in.back), btn_consume(&g_in.pause);
+ screen = SC_PLAY;
+ } else if (g_in.move_y && !(g_in.prev & (K_UP | K_DOWN))) sel = (sel + g_in.move_y + 3) % 3;
+ else if (ok_pressed()) {
+ btn_consume(&g_in.ok), btn_consume(&g_in.jump);
if (sel == 0) screen = SC_PLAY;
else if (sel == 1) {
screen = SC_PLAY;
if (!g_player.dead) player_die(0, 0);
} else {
save_write();
- screen = SC_CHAPTERS, full_redraw = true;
+ go(SC_CHAPTERS);
}
}
break;
+ case SC_COMPLETE:
+ if (screen_t > 60 && ok_pressed()) go(SC_CHAPTERS);
+ break;
}
}
@@ -158,28 +234,81 @@ static void wipe_draw(void) { /* AngledWipe: black bands sliding across, 24 fr
}
}
+/* the pause menu over the level, under HudRenderer's black (70 %, drawn into each buffer once), its words each frame */
+static void pause_draw(void) {
+ static const char *const items[3] = {"Resume", "Retry", "Save & Quit"};
+ int y = 96;
+ text_center(FONT_TITLE, "PAUSED", 160, y - 14, C_GRAY, 0);
+ for (int i = 0; i < 3; i++) text_center(FONT_BODY, items[i], 160, y + 18 + i * 14, i == sel ? highlight() : C_WHITE, 0);
+}
+static void fade_view(void) {
+ uint8_t *p = g_fb + VIEW_Y * 320;
+ for (unsigned n = 320 * VIEW_H; n; n--, p++) *p = g_remap_fade[*p];
+}
void game_draw(void) {
- if (full_redraw) draw_clear_screen(0), full_redraw = false, level_render_forget();
+ static int paused; /* (frames drawn paused: the black goes into both buffers) */
+ if (full_redraw) draw_clear_screen(0), full_redraw--, level_render_forget();
+ if (screen != SC_PAUSE) paused = 0;
switch (screen) {
- case SC_TITLE:
+ case SC_KEYS: { /* NumPlay's keys on the CE (platform/ti84ce/README.md), as the NumWorks version has them */
+ static const char *const keys[][2] = {{"arrows", "Move"}, {"2nd", "Jump"}, {"clear", "Dash"}, {"math", "Grab"},
+ {"del", "Pause"}, {"mode", "Save and quit"}};
draw_clear_screen(0);
- text_center("CELESTE", 90, WHITE);
- text_center("2nd: start", 150, WHITE);
+ text_center(FONT_TITLE, "Controls", 160, 26, C_WHITE, 0);
+ for (int i = 0; i < 6; i++) {
+ text_right(FONT_BODY, keys[i][0], 150, 66 + i * 20, 0xFCFF59ul, 0);
+ text_draw(FONT_BODY, keys[i][1], 170, 66 + i * 20, C_WHITE, 0);
+ }
+ prompt("2nd", "OK", 212);
break;
- case SC_CHAPTERS: {
+ }
+ case SC_TITLE: {
draw_clear_screen(0);
- text_center("Chapter 1", 80, WHITE);
- text_center("Forsaken City", 95, WHITE);
- char buf[24];
- num(buf, (uint32_t)berries_of(1));
- strcat(buf, " / 20 strawberries");
- text_center(buf, 120, WHITE);
- text_center("2nd: climb clear: back", 200, WHITE);
+ const uint8_t *l = sprite(S_gui_logo);
+ pic(S_gui_logo, GUI_LOGO_X + l[0] / 2, VIEW_Y + GUI_LOGO_Y + l[1] / 2);
+ prompt("2nd", "Start", 212);
+ break;
+ }
+ case SC_CHAPTERS:
+ case SC_COMPLETE: {
+ bool done = screen == SC_COMPLETE;
+ draw_clear_screen(0);
+ if (done) text_center(FONT_TITLE, "Chapter Complete", 160, 6, C_WHITE, 0);
+ banner();
+ char b[24];
+ int got = berries_of(1);
+ if (done || got || (save.ch[1].flags & 1)) {
+ num(b, (uint32_t)got);
+ strcat(b, "/");
+ num(b + strlen(b), (uint32_t)g_chapter_berries);
+ stat_line(S_gui_strawberry_small, b, 170);
+ num(b, save.ch[1].deaths);
+ stat_line(S_gui_skull, b, 186);
+ }
+ if (done) {
+ time_text(g_level.time, b);
+ text_center(FONT_BODY, b, 160, 202, C_WHITE, 0);
+ if (screen_t > 60) prompt("2nd", "Continue", 222);
+ } else {
+ prompt("2nd", "Climb", 212);
+ text_center(FONT_BODY, "clear Back", 160, 226, C_GRAY, 0);
+ }
break;
}
case SC_PLAY:
case SC_PAUSE:
+ if (screen == SC_PAUSE && paused >= 2) {
+ pause_draw();
+ break;
+ }
level_render(screen == SC_PAUSE || g_level.wipe || g_level.completed);
+ if (screen == SC_PAUSE) {
+ fade_view();
+ paused++;
+ level_render_forget();
+ pause_draw();
+ break;
+ }
hud_draw();
wipe_draw();
BENCH(7);
@@ -209,19 +338,6 @@ void game_draw(void) {
draw_text(selftest ? "BAD" : "ok", 290, 14, WHITE);
}
#endif
- if (screen == SC_PAUSE) {
- static const char *items[] = {"Resume", "Retry", "Save & Quit"};
- draw_rect_screen(100, 50, 120, 80, 0);
- for (int i = 0; i < 3; i++) draw_text(items[i], 120, VIEW_Y + 62 + i * 20, i == sel ? WHITE : 60);
- }
- if (g_level.completed) {
- draw_rect_screen(60, 50, 200, 80, 0);
- text_center("Chapter complete", VIEW_Y + 62, WHITE);
- char buf[32];
- num(buf, (uint32_t)berries_of(chapter));
- strcat(buf, " strawberries");
- text_center(buf, VIEW_Y + 82, WHITE);
- }
break;
}
}
@@ -238,7 +354,7 @@ void game_start_room(int ch, const char *room, int x, int y) {
g_level.camx = player_cam_targetx() * 256, g_level.camy = player_cam_targety() * 256;
}
screen = SC_PLAY;
- full_redraw = true;
+ full_redraw = 2;
}
void game_init(void) {
diff --git a/games/celeste/ce/src/gen.h b/games/celeste/ce/src/gen.h
index 5f92bc01..1db871e1 100644
--- a/games/celeste/ce/src/gen.h
+++ b/games/celeste/ce/src/gen.h
@@ -1,6 +1,8 @@
/* Generated by tools/pack_ce.py: the ids of the appvars' contents. */
#ifndef GEN_H
#define GEN_H
+#define GUI_LOGO_X 66
+#define GUI_LOGO_Y 14
#define S_characters_player_idle00 0
#define S_characters_player_idle01 1
#define S_characters_player_idle02 2
@@ -439,6 +441,15 @@
#define S_objects_spring_03 435
#define S_objects_spring_04 436
#define S_objects_spring_05 437
+#define S_gui_logo 438
+#define S_gui_city 439
+#define S_gui_banner1 440
+#define S_gui_strawberry 441
+#define S_gui_strawberry_small 442
+#define S_gui_countbg 443
+#define S_gui_skull 444
+#define S_gui_button 445
+#define S_gui_x 446
#define B_player 0
#define B_strawberry 1
#define B_ghostberry 2
@@ -505,8 +516,8 @@
/* 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 S_hair_disc 438
-#define S_hair_bangs 480
+#define S_hair_disc 447
+#define S_hair_bangs 489
#define COMMON 96
#define HAIR 1
#define HAIR_DARK 2
@@ -550,7 +561,7 @@
#define TT_eventTrigger 3
#define TT_goldenBerryCollectTrigger 4
#define EV_end_city 0
-#define FORMAT 1
+#define FORMAT 2
#define GRID_MAX 6603 /* the biggest room's grids */
#define MARGIN 4
#endif
diff --git a/games/celeste/ce/src/text.c b/games/celeste/ce/src/text.c
new file mode 100644
index 00000000..96a540c9
--- /dev/null
+++ b/games/celeste/ce/src/text.c
@@ -0,0 +1,75 @@
+/* Renogare, the game's font (tools/pack_ce.py font_item): each glyph's cover, 2 bits a pixel, drawn in a colour over
+ * another one known to be under it: the four shades between them are the palette's nearest colours, found once for
+ * each pair of colours. Screen coordinates (320 x 240), (x, y) the line's top left. */
+#include "ce.h"
+
+static const uint8_t *glyph(const uint8_t *f, int c) { return f + 3 + 7 * (c - 32); }
+static int kern(const uint8_t *f, int a, int b) { /* quarter pixels */
+ const uint8_t *k = f + 3 + 7 * 95;
+ for (int i = 0; i < f[2]; i++, k += 3)
+ if (k[0] == a && k[1] == b) return (int8_t)k[2];
+ return 0;
+}
+static bool printable(int c) { return c >= 32 && c < 127; }
+
+int text_width(int font, const char *s) {
+ const uint8_t *f = g_fonts[font];
+ int w = 0;
+ for (; *s; s++) {
+ int c = (uint8_t)*s;
+ if (!printable(c)) continue;
+ w += glyph(f, c)[4];
+ if (printable((uint8_t)s[1])) w += kern(f, c, (uint8_t)s[1]);
+ }
+ return (w + 2) >> 2;
+}
+int text_height(int font) { return g_fonts[font][0]; }
+
+void text_draw(int font, const char *s, int x, int y, uint32_t rgb, uint32_t under) {
+ /* the shades of the last few pairs of colours (finding them looks through the palette) */
+ static struct { uint32_t rgb, under; uint8_t gen, shade[4]; } cache[8];
+ static uint8_t next, gen = 1;
+ extern uint8_t g_palette_gen;
+ if (gen != g_palette_gen) { /* (another palette: found again) */
+ for (int i = 0; i < 8; i++) cache[i].gen = 0;
+ gen = g_palette_gen;
+ }
+ int at = 0;
+ while (at < 8 && !(cache[at].gen && cache[at].rgb == rgb && cache[at].under == under)) at++;
+ if (at == 8) {
+ at = next, next = (uint8_t)((next + 1) & 7);
+ for (int k = 1; k < 4; k++) {
+ int r = (int)(under >> 16 & 255), g = (int)(under >> 8 & 255), b = (int)(under & 255);
+ r += ((int)(rgb >> 16 & 255) - r) * k / 3, g += ((int)(rgb >> 8 & 255) - g) * k / 3, b += ((int)(rgb & 255) - b) * k / 3;
+ cache[at].shade[k] = pal_nearest((uint32_t)r << 16 | (uint32_t)g << 8 | (uint32_t)b);
+ }
+ cache[at].rgb = rgb, cache[at].under = under, cache[at].gen = 1;
+ }
+ const uint8_t *shade = cache[at].shade;
+ const uint8_t *f = g_fonts[font];
+ int pen = x * 4;
+ for (; *s; s++) {
+ int c = (uint8_t)*s;
+ if (!printable(c)) continue;
+ const uint8_t *g = glyph(f, c);
+ int gx = ((pen + 2) >> 2) + (int8_t)g[0], gy = y + (int8_t)g[1], w = g[2], h = g[3], stride = (w + 3) >> 2;
+ const uint8_t *bits = f + R16(g + 5);
+ for (int r = 0; r < h; r++, bits += stride) {
+ int sy = gy + r;
+ if ((unsigned)sy >= 240) continue;
+ uint8_t *d = g_fb + sy * 320;
+ for (int i = 0; i < w; i++) {
+ int a = bits[i >> 2] >> ((i & 3) * 2) & 3, sx = gx + i;
+ if (a && (unsigned)sx < 320) d[sx] = shade[a];
+ }
+ }
+ pen += g[4];
+ if (printable((uint8_t)s[1])) pen += kern(f, c, (uint8_t)s[1]);
+ }
+}
+void text_center(int font, const char *s, int cx, int y, uint32_t rgb, uint32_t under) {
+ text_draw(font, s, cx - text_width(font, s) / 2, y, rgb, under);
+}
+void text_right(int font, const char *s, int rx, int y, uint32_t rgb, uint32_t under) {
+ text_draw(font, s, rx - text_width(font, s), y, rgb, under);
+}
diff --git a/games/celeste/ce/tools/pack_ce.py b/games/celeste/ce/tools/pack_ce.py
index b844c6a5..cc55a670 100644
--- a/games/celeste/ce/tools/pack_ce.py
+++ b/games/celeste/ce/tools/pack_ce.py
@@ -33,14 +33,83 @@ COMMON = 96 # colours every chapter shares (indices 0 .. COMMON - 1)
HAIR, HAIR_DARK, WHITE, BLACK = 1, 2, 3, 4 # fixed colours (HAIR and HAIR_DARK change as Madeline's hair does)
ROPE, ROPE_LIGHT = 5, 6 # ZipMover's ropes (663931) and their teeth (9b6157), drawn as lines
MARGIN = 4 # tiles kept around each room (transitions show the next one's edges)
-FORMAT = 1 # bumped when the layout changes (the game checks it)
+FORMAT = 2 # 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")
+GUI = Atlas("Gui") # the menus' pictures, drawn at 1/6 (the game's 1920 x 1080 on 320 x 180)
H = [] # gen.h lines
+# the chapters' banners (OuiChapterSelect's title and accent colours)
+TITLE_BASE = {1: (0x6c, 0x7c, 0x81)}
+TITLE_ACCENT = {1: (0x2f, 0x34, 0x4b)}
+# Renogare, the game's font: (face, scale) as the NumWorks port has it (tools/textdata.py), body text and titles
+FONTS = [("renogare64", 1 / 4.8), ("renogare192", 1 / 7.2), ("renogare64", 0.6 / 4.8)] # (and small: 0.6)
+
+
+def gui_image(path, scale, tint=None):
+ """A Gui picture at `scale` of its size (area-averaged, premultiplied), tinted (multiplied) if asked."""
+ from PIL import Image
+ img = GUI[path].image().astype(np.float32)
+ if tint is not None:
+ img[..., :3] *= np.array(tint, np.float32) / 255
+ h, w = img.shape[:2]
+ ow, oh = max(1, int(round(w * scale))), max(1, int(round(h * scale)))
+ chans = [np.array(Image.fromarray(img[..., k]).resize((ow, oh), Image.BOX)) for k in range(4)]
+ return np.clip(np.round(np.stack(chans, 2)), 0, 255).astype(np.uint8)
+
+
+def font_item(blob):
+ """The fonts (src/text.c): u8 count, then each one's offset (u16, from the item's start); each: u8 line height,
+ u8 base, u8 kerning pairs, then ' '..'~' (95): s8 x, s8 y offset, u8 w, h, u8 advance (quarter pixels), u16 its
+ bitmap (from the font's start: 2 bits a pixel, the left one low, rows padded to bytes); kerning (u8 a, b, s8 quarter
+ pixels)."""
+ from PIL import Image
+ sys.path.insert(0, os.path.join(HERE, "..", "..", "tools"))
+ from textdata import read_fnt
+ codes = list(range(32, 127))
+ fonts = []
+ for face, scale in FONTS:
+ chars, kern, line_h, base = read_fnt(face)
+ page = GUI[face + "_0"].image()[..., 3]
+ recs, bitmaps = [], bytearray()
+ for code in codes:
+ x, y, w, h, xo, yo, xa = chars.get(code, (0, 0, 0, 0, 0, 0, 0))
+ q = np.zeros((0, 0), np.uint8)
+ gx = gy = 0
+ if w and h:
+ g = page[y:y + h, x:x + w].astype(np.float32)
+ fx, fy = xo * scale - np.floor(xo * scale), yo * scale - np.floor(yo * scale)
+ ow, oh = int(np.ceil(w * scale + fx)) + 1, int(np.ceil(h * scale + fy)) + 1
+ big = np.zeros((int(round(oh / scale)) + 2, int(round(ow / scale)) + 2), np.float32)
+ ox, oy = int(round(fx / scale)), int(round(fy / scale))
+ big[oy:oy + h, ox:ox + w] = g
+ a = np.array(Image.fromarray(big).resize((ow, oh), Image.BOX))
+ rows, cols = np.where(a.max(axis=1) > 32)[0], np.where(a.max(axis=0) > 32)[0]
+ if len(rows) and len(cols):
+ a = a[rows[0]:rows[-1] + 1, cols[0]:cols[-1] + 1]
+ gx, gy = int(np.floor(xo * scale)) + int(cols[0]), int(np.floor(yo * scale)) + int(rows[0])
+ q = np.clip(np.round(a / 255 * 3), 0, 3).astype(np.uint8)
+ off = len(bitmaps)
+ for row in q:
+ r = list(row) + [0] * (-len(row) % 4)
+ bitmaps += bytes(r[i] | r[i + 1] << 2 | r[i + 2] << 4 | r[i + 3] << 6 for i in range(0, len(r), 4))
+ recs.append((gx, gy, q.shape[1] if q.size else 0, q.shape[0] if q.size else 0, int(round(xa * scale * 4)), off))
+ kerns = [(a, b, int(round(v * scale * 4))) for (a, b), v in kern.items()
+ if a in codes and b in codes and int(round(v * scale * 4))]
+ assert len(kerns) < 256
+ it = blob.item("font %s %.3f" % (face, scale))
+ it.u8(int(round(line_h * scale))).u8(int(round(base * scale))).u8(len(kerns))
+ head = 3 + 7 * len(recs) + 3 * len(kerns)
+ for gx, gy, gw, gh, adv, off in recs:
+ it.s8(gx).s8(gy).u8(gw).u8(gh).u8(adv).u16(head + off)
+ for a, b, v in kerns:
+ it.u8(a).u8(b).s8(v)
+ it.raw(bytes(bitmaps))
+ fonts.append(it)
+ return fonts
def tex(path):
@@ -445,6 +514,22 @@ class Common:
self.image(f.path)
for f in family("collectables/strawberry/wings"):
self.image(f.path)
+ # the menus' pictures (S_gui_...): the logo, chapter 1's icon and banner, the strawberry count's, the button
+ gi = self.images
+ logo = gui_image("logo", 1 / 6)
+ ys, xs = np.nonzero(logo[..., 3] >= 128)
+ gi["gui/logo"] = logo[ys.min():ys.max() + 1, xs.min():xs.max() + 1] # (its place on the screen: GUI_LOGO_X, Y)
+ H.append(f"#define GUI_LOGO_X {xs.min()}\n#define GUI_LOGO_Y {ys.min()}")
+ gi["gui/city"] = gui_image("areas/city", 1.25 / 6)
+ title = gui_image("areaselect/title", 1 / 6, TITLE_BASE[1]).astype(np.float32)
+ acc = gui_image("areaselect/accent", 1 / 6, TITLE_ACCENT[1]).astype(np.float32)
+ gi["gui/banner1"] = np.clip(acc + title * (1 - acc[..., 3:] / 255), 0, 255).astype(np.uint8)
+ gi["gui/strawberry"] = gui_image("collectables/strawberry", 1 / 6)
+ gi["gui/strawberry_small"] = gui_image("collectables/strawberry", 0.6 / 6)
+ gi["gui/countbg"] = gui_image("strawberryCountBG", 1 / 6)
+ gi["gui/skull"] = gui_image("collectables/skullBlue", 0.6 / 6)
+ gi["gui/button"] = gui_image("textboxbutton", 1 / 6)
+ gi["gui/x"] = gui_image("x", 1 / 6)
def hair_sprites(self):
"""Madeline's hair as src/player.c draws it: circles down it (hair00 scaled 0.25 + (1 - i / n) * 0.75, for 2-7
@@ -497,12 +582,14 @@ class Common:
H.append(f"#define S_hair_bangs {first}")
def palette(self):
- counts = collections.Counter()
+ counts, gui = collections.Counter(), collections.Counter()
for k, img in self.images.items():
- count_colors(img, counts)
+ count_colors(img, gui if k.startswith("gui/") else counts)
fixed = [0, 0x5466, 0x2C33, 0x7FFF, 0x0000, # 0 black, HAIR, HAIR_DARK, white, black for the art
int(c15(np.array([0x66, 0x39, 0x31]))), int(c15(np.array([0x9B, 0x61, 0x57])))] # ROPE, ROPE_LIGHT
- extra = kmeans(counts, set(fixed), COMMON - len(fixed))
+ game = kmeans(counts, set(fixed), COMMON - len(fixed) - 16) # (the game's own exact, the menus' after)
+ extra = game + kmeans(gui, set(fixed + game), COMMON - len(fixed) - len(game))
+ counts.update(gui)
cols = fixed + extra
print(f"common: {len(counts)} colours -> {len(cols)}")
return cols + [0] * (COMMON - len(cols)) # (the chapters' own start at COMMON)
@@ -540,10 +627,14 @@ class Common:
hair.u16(v)
table = self.sprites.table()
self.blob.add(table)
+ fonts = font_item(self.blob)
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.u8(len(fonts))
+ for f in fonts:
+ h.ref(f)
H.append(f"#define COMMON {COMMON}")
H.append(f"#define HAIR {HAIR}\n#define HAIR_DARK {HAIR_DARK}\n#define WHITE {WHITE}\n#define BLACK {BLACK}")
H.append(f"#define ROPE {ROPE}\n#define ROPE_LIGHT {ROPE_LIGHT}")
@@ -862,8 +953,9 @@ class Chapter:
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]).u8(self.nberries)
- # remaps: each colour tinted red (Color.Red: Madeline tired), and halved (Color.Gray)
- for f in (lambda c: c * np.array([1, 0, 0]), lambda c: c * 0.5):
+ # remaps: each colour tinted red (Color.Red: Madeline tired), halved (Color.Gray), and under the pause menu's
+ # black (HudRenderer's BackgroundFade, 70 %)
+ for f in (lambda c: c * np.array([1, 0, 0]), lambda c: c * 0.5, lambda c: c * (1 - 178 / 255)):
for i in range(256):
if i == 0 or i >= pal.n:
h.u8(i)