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: text on the remaining screens

Mason Chen480aaabc7339
diff --git a/games/celeste/src/ch2.c b/games/celeste/src/ch2.c
index 516c4b56..0a01130f 100644
--- a/games/celeste/src/ch2.c
+++ b/games/celeste/src/ch2.c
@@ -2649,12 +2649,15 @@ static void page_render(Ent *e) {
if (g_level.frozen || g_level.paused || g_level.skipping_cutscene || g->c.alpha <= 0 || !g->loaded) return;
uint8_t a = (uint8_t)(clampf(g->c.alpha, 0, 1) * 255);
float w = g->memo ? 936 / 6.f : 855 / 6.f, h = g->memo ? 1380 / 6.f : 580 / 6.f;
- float x = g->c.pos.x / 6 - w / 2, y = g->c.pos.y / 6 - (g->memo ? 0 : h / 2); /* origin: (w / 2, 0) or the middle */
- float maxw = g->memo ? (936 - 120) / 6.f : (855 - 120) / 6.f, lh = font_line_height(FONT_S);
+ /* the poem's lines break where the game's do (its width at 0.7, in the body font's pixels: 1/4.8) */
+ float maxw = g->memo ? (936 - 120) / 6.f : (855 - 120) / 0.7f / 4.8f, lh = font_line_height(FONT_S);
int lines = 0;
float widest = 0;
for (int i = 0, end; i < g->n; i = end + 1, lines++) widest = fmaxf(widest, page_line(g, i, &end, maxw));
- if (g->memo) h = fmaxf(h, 210 / 6.f + lines * lh + 20); /* (the text at its full size takes more room) */
+ /* (the text at its full size takes more room: the page grows around it) */
+ if (g->memo) h = fmaxf(h, 210 / 6.f + lines * lh + 20);
+ else w = fmaxf(w, widest + 120 / 6.f), h = fmaxf(h, lines * lh + 120 / 6.f);
+ float x = g->c.pos.x / 6 - w / 2, y = g->c.pos.y / 6 - (g->memo ? 0 : h / 2); /* origin: (w / 2, 0) or the middle */
g->c.h = h;
gfx_hud(true);
gfx_rect(x, y, w, h, g->memo ? rgb(0xE4DAC5) : rgb(0xDED1C9), a);
diff --git a/games/celeste/src/ch6.c b/games/celeste/src/ch6.c
index 29c17ca0..11a0ba5e 100644
--- a/games/celeste/src/ch6.c
+++ b/games/celeste/src/ch6.c
@@ -3705,6 +3705,7 @@ typedef struct {
uint8_t opts[CAMP_MAX], nopts, sel, node, selfie, selfie_wait, q;
char key[24];
char text[CAMP_MAX][56]; /* the asks, cleaned once */
+ TextDraw td[CAMP_MAX]; /* (the long ones) */
} Camp;
#define CAMP(e) ST(e, Camp)
static bool camp_can_ask(const Camp *k, const CampOpt *o) { /* Option.CanAsk */
@@ -3715,6 +3716,19 @@ static bool camp_can_ask(const Camp *k, const CampOpt *o) { /* Option.CanAsk *
static void camp_key(Camp *k, bool answer, int q) { /* ch6_theo_ask_ / ch6_theo_say_ and the question */
path2(k->key, answer ? "ch6_theo_say_" : "ch6_theo_ask_", CAMP_Q[q], -1);
}
+/* an ask's room in its box (Option: 1400 wide, the portrait's 100 and the padding before the text) */
+static float camp_pad(void) { return (140 - font_line_height(FONT_S) * 6 * 0.7f) / 2; }
+static float camp_room(void) { return (1400 - 20 - camp_pad() - 100 - 20) / 6; }
+/* the game's text is 0.7 of the font: a long ask (larger here) is drawn at 0.8 of it, on two lines if it still runs out
+ * of its box */
+static void camp_fit(char *s) {
+ int n = (int)strlen(s);
+ if (font_measure(s, n, FONT_S) * 0.8f <= camp_room()) return;
+ int best = -1;
+ for (int i = 0; i < n; i++)
+ if (s[i] == ' ' && (best < 0 || (i > n / 2 ? i - n / 2 : n / 2 - i) < (best > n / 2 ? best - n / 2 : n / 2 - best))) best = i;
+ if (best > 0) s[best] = '\n';
+}
static void camp_options(Camp *k) {
int from = k->node == GO_SLEEP ? 14 : 0, to = k->node == GO_SLEEP ? 16 : 14;
k->nopts = 0, k->sel = 0;
@@ -3722,6 +3736,7 @@ static void camp_options(Camp *k) {
if (camp_can_ask(k, &CAMP_OPTS[i])) {
camp_key(k, false, CAMP_OPTS[i].q);
dialog_clean(k->key, k->text[k->nopts], 56);
+ camp_fit(k->text[k->nopts]);
k->hl[k->nopts] = 0;
k->opts[k->nopts++] = (uint8_t)i;
}
@@ -3762,9 +3777,14 @@ static void camp_draw(Ent *e) {
gfx_tex_ex(pt, (x + (right ? 1380 - 50 : 20 + 50)) / 6, (y + 70) / 6, ox, oy, 100 / 240.f, 100 / 240.f, 0,
rgb((uint32_t)(l << 16 | l << 8 | l)), a8(num), right ? GF_FLIPX : 0);
}
- float pad = (140 - font_line_height(FONT_S) * 6 * 0.7f) / 2;
- font_draw_justified(k->text[i], (right ? x + 1400 - 20 - pad - 100 : x + 20 + pad + 100) / 6, (y + 70) / 6, right ? 1 : 0, 0.5f,
- FONT_S, 0xFFFF, a8((0.6f + 0.4f * hh) * num));
+ float pad = camp_pad(), at = right ? x + 1400 - 20 - pad - 100 : x + 20 + pad + 100;
+ uint8_t ta = a8((0.6f + 0.4f * hh) * num);
+ const char *t = k->text[i];
+ if (strchr(t, '\n') || font_measure(t, (int)strlen(t), FONT_S) > camp_room()) {
+ k->td[i] = (TextDraw){t, at, y + 70, right ? 1 : 0, 0.5f, 0.7f, 0xFFFF, ta};
+ text_draw(&k->td[i]);
+ } else
+ font_draw_justified(t, at / 6, (y + 70) / 6, right ? 1 : 0, 0.5f, FONT_S, 0xFFFF, ta);
}
gfx_hud(false);
}
diff --git a/games/celeste/src/ch7.c b/games/celeste/src/ch7.c
index dc4f1c84..cebd82ba 100644
--- a/games/celeste/src/ch7.c
+++ b/games/celeste/src/ch7.c
@@ -423,8 +423,9 @@ static void height_update(Ent *e) {
static void height_render(Ent *e) { /* "{X} M": the number, then the rest */
Height *h = ST(e, Height);
if (g_level.paused || h->index < 0 || h->ease <= 0 || !h->has_text) return;
- char right[24], num[8];
- int nr = dialog_clean(h->index == 0 ? "CH7_HEIGHT_0" : "CH7_HEIGHT_0", right, sizeof right);
+ char right[24], num[8], key[16] = "CH7_HEIGHT_0";
+ key[11] = (char)('0' + h->index);
+ int nr = dialog_clean(key, right, sizeof right); /* ("{X} M": the number's place dropped) */
num[0] = 0;
{
char tmp[8], *o = num;
diff --git a/games/celeste/src/ch8.c b/games/celeste/src/ch8.c
index 0f04b960..4284f51c 100644
--- a/games/celeste/src/ch8.c
+++ b/games/celeste/src/ch8.c
@@ -191,6 +191,19 @@ static int file_time(char *b, uint32_t frames) {
*o++ = (char)('0' + f % 10), *o = 0;
return (int)(o - b);
}
+/* StrawberriesCounter, DeathsCounter (centeredX): the icon, an x, the amount, and what it is out of (light gray), centered
+ * at (cx, cy) interface pixels */
+static void counter8(float cx, float cy, uint16_t icon, const char *amount, const char *outof) {
+ Tex t;
+ float xw = tex_get(T__x, &t) ? t.fw * 6.f : 24, lh = font_line_height(FONT_S);
+ int na = (int)strlen(amount), no = outof ? (int)strlen(outof) : 0;
+ float wa = font_measure(amount, na, FONT_S) * 6, wo = no ? font_measure(outof, no, FONT_S) * 6 : 0;
+ float total = 62 + xw + 2 + wa + wo, x = cx - total / 2;
+ if (tex_get(icon, &t)) gfx_tex_ex(icon, (x + 30) / 6, cy / 6, t.fw * t.scale / 2.f, t.fh * t.scale / 2.f, 1, 1, 0, 0xFFFF, 255, 0);
+ if (tex_get(T__x, &t)) gfx_tex_ex(T__x, (x + 62 + xw / 2) / 6, (cy + 2) / 6, t.fw * t.scale / 2.f, t.fh * t.scale / 2.f, 1, 1, 0, 0xFFFF, 255, 0);
+ font_draw_outline(amount, na, (x + total - wo - wa) / 6, cy / 6 - lh / 2, FONT_S, 0xFFFF, 0, 255);
+ if (no) font_draw_outline(outof, no, (x + total - wo) / 6, cy / 6 - lh / 2, FONT_S, rgb(0xD3D3D3), 0, 255);
+}
static void ending_render(Ent *e) {
Ending8 *s = ST(e, Ending8);
if (g_level.paused) return;
@@ -207,13 +220,12 @@ static void ending_render(Ent *e) {
}
if (s->steps) { /* StrawberriesCounter (of 175), DeathsCounter, TimeDisplay */
char b[24];
- int n = uitoa(save_total_berries(), b);
- memcpy(b + n, "/175", 5);
float y = s->counters.y / 6;
- font_draw_outline(b, (int)strlen(b), (s->counters.x - 170) / 6 - font_measure(b, (int)strlen(b), FONT_S) / 2, y - 4, FONT_S, 0xFFFF, 0, 255);
+ uitoa(save_total_berries(), b);
+ counter8(s->counters.x - 170, s->counters.y, T__collectables_strawberry, b, "/175");
uitoa((int)g_save.total_deaths, b);
- font_draw_outline(b, (int)strlen(b), (s->counters.x + 170) / 6 - font_measure(b, (int)strlen(b), FONT_S) / 2, y - 4, FONT_S, 0xFFFF, 0, 255);
- n = file_time(b, g_save.time);
+ counter8(s->counters.x + 170, s->counters.y, T__collectables_skullBlue, b, NULL);
+ int n = file_time(b, g_save.time);
font_draw_outline(b, n, s->counters.x / 6 - font_measure(b, n, FONT_S) / 2, y + 100 / 6.f - 4, FONT_S, 0xFFFF, 0, 255);
}
gfx_hud(false);
diff --git a/games/celeste/src/ch9.c b/games/celeste/src/ch9.c
index 35c40c4f..d86615f4 100644
--- a/games/celeste/src/ch9.c
+++ b/games/celeste/src/ch9.c
@@ -1465,14 +1465,16 @@ static const EntClass NOREFILL = {.name = "noRefillTrigger", .size = sizeof(NoRe
/* ---------------------------------------------------------------- CoreMessage */
typedef struct { float alpha; uint8_t line; } CoreMsg;
-/* Dialog.Clean("app_ending").Split('\n')[line]: the cleaned text runs its lines together, a line ending where a
- * sentence's end meets a capital */
+/* Dialog.Clean("app_ending").Split('\n')[line] (empty lines left out) */
static int core_line(int line, char *out, int cap) {
char all[200];
int n = dialog_clean("app_ending", all, sizeof all), k = 0, at = 0;
for (int i = 0; i < n; i++) {
+ if (all[i] == '\n') {
+ if (i > 0 && all[i - 1] != '\n') k++;
+ continue;
+ }
if (k == line && at < cap - 1) out[at++] = all[i];
- if ((all[i] == '.' || all[i] == '?' || all[i] == '!') && i + 1 < n && all[i + 1] >= 'A' && all[i + 1] <= 'Z') k++;
}
out[at] = 0;
return at;
diff --git a/games/celeste/src/font.c b/games/celeste/src/font.c
index 68b286cd..63aa81dc 100644
--- a/games/celeste/src/font.c
+++ b/games/celeste/src/font.c
@@ -77,6 +77,7 @@ void font_draw_glyph(int size, uint32_t code, float x, float y, uint16_t col, ui
float font_draw(const char *s, int n, float x, float y, int size, uint16_t col, uint8_t alpha) {
const char *end = s + n;
float x0 = x;
+ x = floorf(x + 0.5f); /* (from a whole pixel: the glyphs' rounding, and so their gaps, the same wherever it starts) */
y = floorf(y + 0.5f);
while (s < end) {
uint32_t c = utf8_next(&s, end);
diff --git a/games/celeste/src/menu.c b/games/celeste/src/menu.c
index 84b637d8..cbc2d517 100644
--- a/games/celeste/src/menu.c
+++ b/games/celeste/src/menu.c
@@ -654,8 +654,8 @@ static void pause_update(void) {
g_menu = M.screen = S_NONE;
level_save_and_quit();
break;
- case P_RESTART: M.confirm = 0, go(S_CONFIRM, 1); break;
- case P_RETURN: M.confirm = 1, go(S_CONFIRM, 1); break;
+ case P_RESTART: M.confirm = 0, go(S_CONFIRM, 0); break; /* (TextMenu: its first button) */
+ case P_RETURN: M.confirm = 1, go(S_CONFIRM, 0); break;
}
}
static void confirm_update(void) {
diff --git a/games/celeste/src/text.c b/games/celeste/src/text.c
index 03fd3d43..99adf0ac 100644
--- a/games/celeste/src/text.c
+++ b/games/celeste/src/text.c
@@ -801,12 +801,12 @@ void text_into(uint16_t *strip, int sy0, int sy1, const char *s, float px, float
for (const char *q = s; q < end; q++) lines += *q == '\n';
float x0 = px / 6, y = py / 6 - lines * lh * k * jy;
if (y > sy1 || y + lines * lh * k < sy0) return;
- float x = x0 - line_width(s, end, size) * k * jx;
+ float x = floorf(x0 - line_width(s, end, size) * k * jx + 0.5f); /* (lines from a whole pixel: see font_draw) */
while (s < end) {
uint32_t c = utf8_next(&s, end);
if (c == '\n') {
y += lh * k;
- x = x0 - line_width(s, end, size) * k * jx;
+ x = floorf(x0 - line_width(s, end, size) * k * jx + 0.5f);
continue;
}
const uint8_t *g = font_glyph_rec(size, c);