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: readable text, clean room transitions, visible blocks

Mason Chen8da2433009db
diff --git a/games/celeste/src/ch5.c b/games/celeste/src/ch5.c
index 4ae5f7b3..9c0e7897 100644
--- a/games/celeste/src/ch5.c
+++ b/games/celeste/src/ch5.c
@@ -1615,6 +1615,8 @@ Ent *level_holdable_check(void) {
}
return NULL;
}
+/* Level.EnforceBounds: a TheoCrystal about and nothing held keeps the player from leaving right */
+bool theo_left_behind(const Player *p) { return g_session.area == 5 && !p->holding && first_of(&THEO); }
void holdable_carry(Ent *h, V2 at) {
if (h->cls != &THEO) return;
h->x = at.x, h->y = at.y;
@@ -2753,7 +2755,7 @@ static void portal_buffer_strip(uint16_t *strip, int sy0, int sy1, void *ctx) {
break;
}
int c = (int)(128 * num); /* Color.Lerp(Black, Purple, num) */
- row[x] = blend565(row[x], rgb((uint32_t)(c << 16 | c)), a);
+ row[x] = blend565(row[x], scale565(rgb((uint32_t)(c << 16 | c)), a), a);
}
}
}
diff --git a/games/celeste/src/ch7.c b/games/celeste/src/ch7.c
index 61c49032..b307eac0 100644
--- a/games/celeste/src/ch7.c
+++ b/games/celeste/src/ch7.c
@@ -568,6 +568,7 @@ static void streaks_strip(uint16_t *strip, int sy0, int sy1, void *ctx) {
cols[0] = m && m->dark ? rgb(0x041B44) : 0xFFFF;
cols[1] = m && m->dark ? rgb(0x011230) : rgb(0xE69ECB);
if (al <= 0) return;
+ cols[0] = scale565(cols[0], al), cols[1] = scale565(cols[1], al);
for (int i = 0; i < STREAKS; i++) {
Streak *k = &streaks[i];
float t = clamped_map(k->speed, 600, 2000, 0, 1), big = 1 + 3 * t;
diff --git a/games/celeste/src/data.bin b/games/celeste/src/data.bin
index 0ad19775..f3e45544 100644
Binary files a/games/celeste/src/data.bin and b/games/celeste/src/data.bin differ
diff --git a/games/celeste/src/entities.c b/games/celeste/src/entities.c
index c78e3e02..75d0512a 100644
--- a/games/celeste/src/entities.c
+++ b/games/celeste/src/entities.c
@@ -874,10 +874,15 @@ static Ent *new_block(const EntClass *cls, const EData *d, float w, float h, cha
if (b->q) tiles_box(type, b->w, b->h, b->q);
return e;
}
-static char tile_char(float v, const char *s) {
- if (s && *s) return s[0];
- return (char)('0' + (int)v);
+/* data.Char("tiletype", '3'): a number in some maps, a letter in others (data.bin keeps those as text) */
+static char tile_attr(const EData *d, int off, char kind) {
+ if (kind == 's') {
+ const char *s = ea_str(d, off);
+ return *s ? s[0] : '3';
+ }
+ return (char)('0' + (int)ea_num(d, off, kind));
}
+#define TILE_ATTR(d, ent, attr) tile_attr(d, EA_##ent##_##attr, EK_##ent##_##attr)
/* DashBlock */
static int dash_block_hit(Ent *e, Player *p, V2 dir);
@@ -1168,7 +1173,7 @@ bool ent_create(const EData *d) {
case ET_zipMover: new_zip(d); return true;
case ET_fallingBlock: {
Ent *e = new_block(&FALLING, d, EA(d, fallingBlock, width), EA(d, fallingBlock, height),
- tile_char(EA(d, fallingBlock, tiletype), NULL));
+ TILE_ATTR(d, fallingBlock, tiletype));
if (!e) return true;
if (EAB(d, fallingBlock, behind)) e->depth = 5000;
ST(e, Block)->flags = EAB(d, fallingBlock, climbFall) ? 1 : 0;
@@ -1177,7 +1182,7 @@ bool ent_create(const EData *d) {
case ET_dashBlock: {
uint32_t h = level_entity_hash(d);
if (level_do_not_load(h)) return true;
- char t = tile_char(EA(d, dashBlock, tiletype), NULL);
+ char t = TILE_ATTR(d, dashBlock, tiletype);
Ent *e = new_block(&DASHBLOCK, d, EA(d, dashBlock, width), EA(d, dashBlock, height), t);
if (!e) return true;
e->depth = -12999;
@@ -1193,7 +1198,7 @@ bool ent_create(const EData *d) {
case ET_fakeWall: {
uint32_t h = level_entity_hash(d);
if (level_do_not_load(h)) return true;
- char t = tile_char(EA(d, fakeWall, tiletype), NULL);
+ char t = TILE_ATTR(d, fakeWall, tiletype);
Ent *e = new_block(&FAKEWALL, d, EA(d, fakeWall, width), EA(d, fakeWall, height), t);
if (!e) return true;
e->depth = -13000;
@@ -1202,7 +1207,7 @@ bool ent_create(const EData *d) {
return true;
}
case ET_coverupWall: {
- char t = tile_char(EA(d, coverupWall, tiletype), NULL);
+ char t = TILE_ATTR(d, coverupWall, tiletype);
Ent *e = new_block(&COVERUP, d, EA(d, coverupWall, width), EA(d, coverupWall, height), t);
if (!e) return true;
e->depth = -13000;
@@ -1211,7 +1216,7 @@ bool ent_create(const EData *d) {
return true;
}
case ET_exitBlock: {
- char t = tile_char(EA(d, exitBlock, tileType), NULL);
+ char t = TILE_ATTR(d, exitBlock, tileType);
Ent *e = new_block(&EXITBLOCK, d, EA(d, exitBlock, width), EA(d, exitBlock, height), t);
if (!e) return true;
e->depth = -13000;
diff --git a/games/celeste/src/entities.h b/games/celeste/src/entities.h
index 128bfacf..069dd737 100644
--- a/games/celeste/src/entities.h
+++ b/games/celeste/src/entities.h
@@ -54,6 +54,7 @@ bool trig_create(const EData *d);
Ent *level_holdable_check(void); /* a holdable the player can grab now, picked up (Holdable.Pickup) */
void holdable_carry(Ent *h, V2 at); /* Holdable.Carry */
void holdable_release(Ent *h, V2 force); /* Holdable.Release */
+bool theo_left_behind(const Player *p);
V2 level_closest_spawn(V2 at);
void level_dash_listeners(V2 dir);
void level_booster_boosted(Ent *booster, V2 dir);
diff --git a/games/celeste/src/game.c b/games/celeste/src/game.c
index 35c09235..c630cc0c 100644
--- a/games/celeste/src/game.c
+++ b/games/celeste/src/game.c
@@ -54,7 +54,7 @@ void game_level_exit(int mode) {
g_in_level = false;
wipe_start(WIPE_FADE, true, NULL);
if (mode == LEXIT_SAVEQUIT) menu_open_main();
- else menu_open_overworld(mode == LEXIT_COMPLETED && area != 0 && area != 8);
+ else menu_open_overworld(mode == LEXIT_COMPLETED, mode == LEXIT_COMPLETED && g_should_advance);
}
/* Home: the run is kept (Save & Quit) */
diff --git a/games/celeste/src/gfx.c b/games/celeste/src/gfx.c
index 90591903..74f797a0 100644
--- a/games/celeste/src/gfx.c
+++ b/games/celeste/src/gfx.c
@@ -56,10 +56,16 @@ void gfx_screen(bool on) { hud = on, ui = false; }
void gfx_clear(uint16_t c) { clear_color = c; }
void gfx_present_all(void) { letterbox_dirty = true; }
+#ifdef HOST
+#include <stdio.h>
+static int dropped_cmds;
+#endif
void gfx_begin(void) {
#ifdef HOST
extern void res_debug_working_set(void);
res_debug_working_set();
+ if (getenv("CMDDBG")) printf("cmds %d dropped %d\n", ncmds, dropped_cmds);
+ dropped_cmds = 0;
#endif
g_res_frame++;
g_res_drawing = true;
@@ -73,7 +79,13 @@ void gfx_begin(void) {
#define HUD_CMDS 48
#define HUD_AFFS 8
static Cmd *add(uint8_t op, int y0, int y1) {
- if (y1 <= 0 || y0 >= VIEW_H || ncmds >= (ui ? MAX_CMDS : MAX_CMDS - HUD_CMDS)) return NULL;
+ if (y1 <= 0 || y0 >= VIEW_H) return NULL;
+ if (ncmds >= (ui ? MAX_CMDS : MAX_CMDS - HUD_CMDS)) {
+#ifdef HOST
+ dropped_cmds++;
+#endif
+ return NULL;
+ }
Cmd *c = &cmds[ncmds++];
c->op = op;
c->extra = ui ? 1 : 0; /* the interface's: not zoomed */
diff --git a/games/celeste/src/heart.c b/games/celeste/src/heart.c
index 0300e6d0..267eed47 100644
--- a/games/celeste/src/heart.c
+++ b/games/celeste/src/heart.c
@@ -169,7 +169,7 @@ static void poem_render(Ent *e) {
s.alpha = (uint8_t)(s.alpha * HR.alpha);
spr_draw(&s, 160, 90);
if (HR.text[0] && HR.text_alpha > 0) {
- float w = text_measure(HR.text) * 1.5f;
+ float w = text_width(HR.text, 1.5f);
uint8_t a = (uint8_t)(HR.text_alpha * HR.alpha * 255);
if (tex_get(T__poemside, &t))
for (int side = -1; side <= 1; side += 2)
@@ -494,7 +494,7 @@ transform: /* TransformRoutine */
float mx = fmaxf(20, (1 - b->t) * 200);
if (v2len(b->speed) > mx) b->speed = safe_norm(b->speed, mx);
e->x += b->speed.x * DT, e->y += b->speed.y * DT;
- b->color = blend565(b->color_from, 0xFFFF, (int)(b->t * 256));
+ b->color = blend565(b->color_from, scale565(0xFFFF, (int)(b->t * 256)), (int)(b->t * 256));
b->heart_scale = fmaxf(0, (b->t - 0.75f) * 4);
if (d.x != 0) b->sx = fabsf(b->sx) * signf(d.x);
b->sx = signf(b->sx) * (1 - b->heart_scale);
diff --git a/games/celeste/src/level.c b/games/celeste/src/level.c
index 0c667abc..971a035c 100644
--- a/games/celeste/src/level.c
+++ b/games/celeste/src/level.c
@@ -534,9 +534,10 @@ static void transition_to(int index, V2 dir) {
V2 to = v2(pe->x, pe->y);
if (dir.x != 0)
while (to.y >= rm->y + rm->h) to.y -= 1;
- for (int guard = 0; guard < 400; guard++) {
- bool in = to.x >= rm->x + pad.x * 0 && level_in_bounds(v2add(to, pad), 0);
- if (in) break;
+ for (int guard = 0; guard < 400; guard++) { /* IsInBounds(playerTo, dirPad): the pad on the side entered */
+ if (to.x >= rm->x + fmaxf(pad.x, 0) && to.y >= rm->y + fmaxf(pad.y, 0) && to.x < rm->x + rm->w - fmaxf(-pad.x, 0) &&
+ to.y < rm->y + rm->h - fmaxf(-pad.y, 0))
+ break;
to = v2add(to, dir);
}
g_level.tr_player_to = to;
@@ -593,6 +594,8 @@ void level_enforce_bounds(Player *p) {
if (lock == 2 && e_right(e) > cr && cr < br - 4) {
e->x += cr - e_right(e);
player_on_bounds_h(p);
+ } else if (e_right(e) > br - 1 && theo_left_behind(p)) {
+ e->x += (br - 1) - e_right(e);
} else if (e_right(e) > br) {
V2 at = v2(e_cxm(e) + 8, e_cym(e));
int next = room_at(at);
@@ -635,7 +638,7 @@ void level_enforce_bounds(Player *p) {
return;
}
}
- if (e_top(e) > bb + 4) player_die(p, v2(0, 0), false);
+ if (e_top(e) > bb) player_die(p, v2(0, 0), false);
}
/* ---------------------------------------------------------------- update / render */
diff --git a/games/celeste/src/level.h b/games/celeste/src/level.h
index b7be59cd..c928deff 100644
--- a/games/celeste/src/level.h
+++ b/games/celeste/src/level.h
@@ -226,7 +226,8 @@ void menu_update(void);
void menu_render(void);
void menu_pause(void);
void menu_open_title(void);
-void menu_open_overworld(bool completed);
+void menu_open_overworld(bool completed, bool advance);
+extern bool g_should_advance; /* Session.ShouldAdvance, as the chapter was completed */
void menu_open_main(void);
void hud_update(void); /* TotalStrawberriesDisplay */
void hud_reset(void);
diff --git a/games/celeste/src/menu.c b/games/celeste/src/menu.c
index 4f1616e4..9dbde2f4 100644
--- a/games/celeste/src/menu.c
+++ b/games/celeste/src/menu.c
@@ -14,6 +14,7 @@ static struct {
uint8_t screen, back; /* back: where Back goes from the options (S_PAUSE or S_MAIN) */
int8_t sel, area, mode, cp, binding, confirm;
uint8_t hold, last_dir; /* the arrows' repeat */
+ uint8_t advance; /* after a first completion: 1 the panel waits, 2 and 3 the chapter select moves on */
float t, wig, repeat;
} M;
uint8_t g_menu; /* the screen on (S_NONE while playing) */
@@ -156,11 +157,14 @@ static void play_chapter(int start) { /* the panel's choice: Continue, Start o
int k = start - (session_here() ? 1 : 0);
game_play(chapter_index(M.area, M.mode), k == 0 ? -1 : nth_checkpoint(k - 1));
}
-void menu_open_overworld(bool completed) { /* the chapter select: after a chapter, its end first */
+/* the overworld after a chapter (StartMode.AreaComplete, AreaQuit): its end (AreaComplete) unless an interlude,
+ * then its panel; after a first completion, on to the next chapter (Session.ShouldAdvance) */
+void menu_open_overworld(bool completed, bool advance) {
M.area = (int8_t)(g_save.last_area <= 9 ? g_save.last_area : 1);
M.mode = (int8_t)g_save.last_mode;
if (M.area > max_area()) M.area = (int8_t)max_area();
- go(completed ? S_COMPLETE : S_CHAPTERS, 0);
+ M.advance = advance;
+ go(completed && !interlude(M.area) ? S_COMPLETE : S_PANEL, 0);
}
void menu_open_title(void) { go(g_save.key_sheet_seen ? S_TITLE : S_SHEET, 0); }
void menu_open_main(void) { go(S_MAIN, 0); }
@@ -182,28 +186,28 @@ static const char *action_on(int k) {
return NULL;
}
static void key_cap(float x, float y, float w, int k, const char *what) { /* a key: bright with what it does */
- box(x, y, w, 174, what ? rgb(0xA0A0A0) : rgb(0x505050), 255);
- box(x + 6, y + 6, w - 12, 162, what ? rgb(0x282828) : rgb(0x181818), 255);
- say(key_name(k), x + w / 2, y + (what ? 52 : 87), 0.5f, 0.5f, 0.8f, what ? WHITE : rgb(0x707070), 255);
- if (what) say(what, x + w / 2, y + 124, 0.5f, 0.5f, 0.8f, rgb(0xFFFFA0), 255);
+ box(x, y, w, 162, what ? rgb(0xA0A0A0) : rgb(0x505050), 255);
+ box(x + 6, y + 6, w - 12, 150, what ? rgb(0x282828) : rgb(0x181818), 255);
+ say(key_name(k), x + w / 2, y + (what ? 46 : 81), 0.5f, 0.5f, 0.8f, what ? WHITE : rgb(0x707070), 255);
+ if (what) say(what, x + w / 2, y + 116, 0.5f, 0.5f, 0.8f, rgb(0xFFFFA0), 255);
}
static void sheet_draw(void) {
say("Controls", 960, 40, 0.5f, 0.5f, 1, WHITE, 255);
/* the arrows' pad */
if (!pass) {
- gfx_circle(40, 52, 26, rgb(0xA0A0A0), 255, 24);
- gfx_circle(40, 52, 24, rgb(0x282828), 255, 24);
+ gfx_circle(40, 45, 25, rgb(0xA0A0A0), 255, 24);
+ gfx_circle(40, 45, 23, rgb(0x282828), 255, 24);
}
- say("Move", 240, 312, 0.5f, 0.5f, 0.8f, rgb(0xFFFFA0), 255);
- key_cap(780, 160, 360, 6, "Save, quit");
- key_cap(1416, 80, 480, 4, action_on(4));
- key_cap(1416, 272, 480, 5, ui_str("KEY_CONFIG_PAUSE"));
+ say("Move", 240, 270, 0.5f, 0.5f, 0.8f, rgb(0xFFFFA0), 255);
+ key_cap(780, 150, 360, 6, "Save, quit");
+ key_cap(1416, 70, 480, 4, action_on(4));
+ key_cap(1416, 250, 480, 5, ui_str("KEY_CONFIG_PAUSE"));
for (int r = 0; r < 3; r++)
for (int c = 0; c < 6; c++) {
int k = 12 + r * 6 + c;
- key_cap(c < 2 ? 30 + c * 222 : 474 + (c - 2) * 360, 480 + r * 192, c < 2 ? 204 : 342, k, action_on(k));
+ key_cap(c < 2 ? 30 + c * 222 : 474 + (c - 2) * 360, 440 + r * 180, c < 2 ? 204 : 342, k, action_on(k));
}
- say("Menus: OK or EXE confirm, Back cancels.", 960, 1050, 0.5f, 0.5f, 0.8f, WHITE, 255);
+ say("Menus: OK or EXE confirm, Back cancels.", 960, 1028, 0.5f, 0.5f, 0.8f, WHITE, 255);
}
static void sheet_update(void) {
if (confirm() || cancel()) {
@@ -241,6 +245,7 @@ static void main_update(void) {
if (cancel()) go(S_TITLE, 0);
else if (confirm()) switch (M.sel) {
case 0:
+ M.advance = 0;
M.area = (int8_t)(g_save.last_area <= max_area() ? g_save.last_area : max_area());
M.mode = (int8_t)g_save.last_mode;
go(S_CHAPTERS, 0);
@@ -274,8 +279,8 @@ static void banner(float x, float y, int a, float alpha) { /* the title: areas
chapter[n++] = *c;
}
chapter[n] = 0;
- say(chapter, x + 816, y + 84, 1, 1, 0.6f, rgb(TITLE_ACCENT[a]), (uint8_t)(al * 0.8f));
- say(ui_str(name), x + 816, y + 66, 1, 0, 1, text, (uint8_t)(al * 0.8f));
+ say(chapter, x + 816, y + 72, 1, 1, 0.6f, rgb(TITLE_ACCENT[a]), (uint8_t)(al * 0.8f));
+ say(ui_str(name), x + 816, y + 54, 1, 0, 1, text, (uint8_t)(al * 0.8f)); /* (its baseline where the game's is) */
}
}
static void chapters_draw(void) {
@@ -303,6 +308,16 @@ static void chapters_draw(void) {
}
}
static void chapters_update(void) {
+ if (M.advance) { /* AutoAdvanceRoutine: a second, the next chapter, a quarter more, then the input */
+ if (M.advance == 2 && M.t >= 1) {
+ int a = M.area + 1;
+ while (a <= max_area() && chapter_index(a, M_A) < 0) a++;
+ if (a <= max_area()) M.area = (int8_t)a, M.wig = 0;
+ M.advance = 3;
+ } else if (M.advance == 3 && M.t >= 1.25f)
+ M.advance = 0;
+ return;
+ }
int d = dir_pressed(0);
if (d) {
int a = M.area + d;
@@ -330,8 +345,8 @@ static void panel_draw(void) {
if (!has_mode(M.area, m)) continue;
const char *w = interlude(M.area) ? ui_str("FILE_BEGIN") : ui_str(modes[m]);
say(w, mx, y + 280, 0, 0.5f, 0.8f, m == M.mode ? rgb(0x101010) : rgb(0x808080), 255);
- if (m == M.mode) box(mx, y + 314, text_measure(w) * 0.8f, 8, rgb(TITLE_BASE[M.area]), 255);
- mx += text_measure(w) * 0.8f + 60;
+ if (m == M.mode) box(mx, y + 314, text_width(w, 0.8f), 8, rgb(TITLE_BASE[M.area]), 255);
+ mx += text_width(w, 0.8f) + 60;
}
/* where to start */
int ncp, n = start_count(&ncp);
@@ -368,6 +383,14 @@ static void panel_draw(void) {
}
}
static void panel_update(void) {
+ if (M.advance) { /* IncrementStats, then AdvanceToNext: the chapter select moves on */
+ if (M.t >= 1.2f) {
+ M.mode = M_A;
+ go(S_CHAPTERS, 0);
+ M.advance = 2;
+ }
+ return;
+ }
int ncp, n = start_count(&ncp);
int d = dir_pressed(1);
if (d && n) M.sel = (int8_t)((M.sel + d + n) % n);
@@ -385,6 +408,7 @@ static void panel_update(void) {
#define OPT_SHAKE 1
#define OPT_FLASH 2
static const char *on_off(bool on) { return ui_str(on ? "OPTIONS_ON" : "OPTIONS_OFF"); }
+#define ITEM_H 84 /* TextMenu's rows: the text's LineHeight and ItemSpacing (4), at its size here */
static void menu_item(const char *w, const char *value, int i, float y, bool disabled) {
uint16_t col = disabled ? SLATE : i == M.sel ? highlight() : WHITE;
if (value) {
@@ -399,10 +423,10 @@ static void options_draw(void) {
say(ui_str("OPTIONS_TITLE"), 960, 200, 0.5f, 0.5f, 2, GRAY, 255);
static const char *const clocks[3] = {"OPTIONS_OFF", "OPTIONS_SPEEDRUN_CHAPTER", "OPTIONS_SPEEDRUN_FILE"};
menu_item(ui_str("OPTIONS_KEYCONFIG"), NULL, 0, 380, false);
- menu_item("Key Sheet", NULL, 1, 448, false);
- menu_item(ui_str("OPTIONS_DISABLE_SHAKE"), on_off(!(g_save.options & OPT_SHAKE)), 2, 560, false);
- menu_item(ui_str("OPTIONS_DISABLE_FLASH"), on_off(g_save.options & OPT_FLASH), 3, 628, false);
- menu_item(ui_str("OPTIONS_SPEEDRUN"), ui_str(clocks[g_save.options >> 2 & 3]), 4, 696, false);
+ menu_item("Key Sheet", NULL, 1, 380 + ITEM_H, false);
+ menu_item(ui_str("OPTIONS_DISABLE_SHAKE"), on_off(!(g_save.options & OPT_SHAKE)), 2, 420 + ITEM_H * 2, false);
+ menu_item(ui_str("OPTIONS_DISABLE_FLASH"), on_off(g_save.options & OPT_FLASH), 3, 420 + ITEM_H * 3, false);
+ menu_item(ui_str("OPTIONS_SPEEDRUN"), ui_str(clocks[g_save.options >> 2 & 3]), 4, 420 + ITEM_H * 4, false);
}
static void options_update(void) {
int d = dir_pressed(1);
@@ -433,14 +457,14 @@ static void keys_draw(void) {
else box(0, 0, 1920, 1080, 0, 178);
say(ui_str("KEY_CONFIG_TITLE"), 960, 200, 0.5f, 0.5f, 2, GRAY, 255);
say(ui_str("KEY_CONFIG_GAMEPLAY"), 960, 330, 0.5f, 0.5f, 0.6f, GRAY, 255);
- for (int a = 0; a < 4; a++) menu_item(ui_str(ACTION_KEYS[a]), M.binding == a ? "..." : key_name(g_bind[a]), a, 400 + a * 68, false);
- menu_item(ui_str("KEY_CONFIG_RESET"), NULL, 4, 700, false);
+ for (int a = 0; a < 4; a++) menu_item(ui_str(ACTION_KEYS[a]), M.binding == a ? "..." : key_name(g_bind[a]), a, 410 + a * ITEM_H, false);
+ menu_item(ui_str("KEY_CONFIG_RESET"), NULL, 4, 450 + ITEM_H * 4, false);
if (M.binding >= 0) {
char w[48];
strcpy(w, ui_str("KEY_CONFIG_CHANGING"));
strcat(w, " ");
strcat(w, ui_str(ACTION_KEYS[M.binding]));
- say(w, 960, 860, 0.5f, 0.5f, 0.8f, WHITE, 255);
+ say(w, 960, 900, 0.5f, 0.5f, 0.8f, WHITE, 255);
}
}
static void keys_update(void) {
@@ -500,11 +524,7 @@ static void complete_draw(void) {
if (M.t > 1 && fmodf(M.t, 1) < 0.75f) pic(T__textboxbutton, 1824, 984, 0.5f, 0.5f, 1, WHITE, 255);
}
static void complete_update(void) {
- if (M.t > 1 && (confirm() || cancel())) {
- M.area = (int8_t)(g_save.unlocked_areas <= max_area() ? g_save.unlocked_areas : max_area());
- M.mode = M_A;
- go(S_CHAPTERS, 0);
- }
+ if (M.t > 1 && (confirm() || cancel())) go(S_PANEL, 0);
}
/* ---------------------------------------------------------------- the pause menu (Level.Pause) */
@@ -532,13 +552,13 @@ static void pause_draw(void) {
box(0, 0, 1920, 1080, 0, 178); /* HudRenderer.BackgroundFade */
int8_t items[P_COUNT];
int n = pause_items(items);
- float h = 128 + n * 68 + 40, y = 540 - h / 2 + 64;
+ float h = 128 + n * ITEM_H + 40, y = 540 - h / 2 + 64;
say(ui_str("MENU_PAUSE_TITLE"), 960, y, 0.5f, 0.5f, 2, GRAY, 255);
- y += 64 + 34;
+ y += 64 + ITEM_H / 2;
for (int i = 0; i < n; i++) {
if (items[i] == P_RESTART) y += 40; /* SubHeader("") */
- menu_item(ui_str(words[items[i]]), NULL, i, y + 34, pause_disabled(items[i]));
- y += 68;
+ menu_item(ui_str(words[items[i]]), NULL, i, y + ITEM_H / 2, pause_disabled(items[i]));
+ y += ITEM_H;
}
}
static void confirm_draw(void) {
@@ -546,7 +566,7 @@ static void confirm_draw(void) {
bool restart = M.confirm == 0;
say(ui_str(restart ? "MENU_RESTART_TITLE" : "MENU_RETURN_TITLE"), 960, 360, 0.5f, 0.5f, 2, GRAY, 255);
menu_item(ui_str(restart ? "MENU_RESTART_CONTINUE" : "MENU_RETURN_CONTINUE"), NULL, 0, 520, false);
- menu_item(ui_str(restart ? "MENU_RESTART_CANCEL" : "MENU_RETURN_CANCEL"), NULL, 1, 588, false);
+ menu_item(ui_str(restart ? "MENU_RESTART_CANCEL" : "MENU_RETURN_CANCEL"), NULL, 1, 520 + ITEM_H, false);
}
void menu_pause(void) { /* Level.Pause */
g_level.paused = true;
diff --git a/games/celeste/src/npc.c b/games/celeste/src/npc.c
index 851222d0..eae6db46 100644
--- a/games/celeste/src/npc.c
+++ b/games/celeste/src/npc.c
@@ -230,10 +230,11 @@ void tutorial_update(Tutorial *t) {
t->scale = approach(t->scale, t->open ? 1.f : 0.f, RAW_DT * 8);
}
-/* a key cap: a light frame, dark inside, its name */
+/* a key cap: a light frame, dark inside, its name (as tall as the text, and a margin) */
+static float key_h(void) { return font_line_height(FONT_S) * 6 + 16; }
static void draw_key(float x, float y, const char *name, float sx) {
float w = (font_measure(name, (int)strlen(name), FONT_S) * 6 + 48) * sx;
- float h = 64;
+ float h = key_h();
gfx_rect((x) / 6, (y - h / 2) / 6, w / 6, h / 6, 0xFFFF, 255);
gfx_rect((x + 6) / 6, (y - h / 2 + 6) / 6, (w - 12) / 6, (h - 12) / 6, 0x2104, 255);
if (sx > 0.5f) font_draw(name, (int)strlen(name), (x + w / 2) / 6 - font_measure(name, (int)strlen(name), FONT_S) / 2,
@@ -256,9 +257,9 @@ void tutorial_render(Tutorial *t) {
if (!t->added || t->scale <= 0 || g_level.frozen || g_level.paused) return;
Ent *b = &g_ents[t->bird];
float px = (b->x + t->offset.x - floorf(g_level.cam.x)) * 6, py = (b->y + t->offset.y - floorf(g_level.cam.y)) * 6;
- float lh = 64;
+ float lh = font_line_height(FONT_S) * 6, kh = key_h();
float w = (fmaxf(t->controls_w, t->info_w) + 64) * t->scale;
- float h = lh + lh + 32; /* infoHeight is the line height for text */
+ float h = lh + kh + 48; /* the info's line, the controls' row (the game's: two lines and 32) */
float x = px - w / 2, y = py - h - 32;
gfx_hud(true);
gfx_rect((x - 6) / 6, (y - 6) / 6, (w + 12) / 6, (h + 12) / 6, 0xFFFF, 255);
@@ -271,7 +272,7 @@ void tutorial_render(Tutorial *t) {
if (w > 3) {
float cx = px, cy = y + 16;
if (t->scale > 0.5f) font_draw(t->info, (int)strlen(t->info), cx / 6 - t->info_w / 12 * t->scale, cy / 6, FONT_S, 0x63DC, 255);
- cy += lh + lh * 0.5f;
+ cy += lh + 16 + kh / 2;
float ox = -t->controls_w / 2;
for (int i = 0; i < t->n; i++) {
GuiControl *c = &t->controls[i];
@@ -286,8 +287,9 @@ void tutorial_render(Tutorial *t) {
} else if (c->kind == GC_TEXT) {
float tw = control_width(c);
if (t->scale > 0.5f) {
- font_draw(c->text, (int)strlen(c->text), (cx + ox * t->scale) / 6, cy / 6 - 6 + 0.33f, FONT_S, 0x63DC, 255);
- font_draw(c->text, (int)strlen(c->text), (cx + ox * t->scale) / 6, cy / 6 - 6 - 0.33f, FONT_S, 0xFFFF, 255);
+ float ty = cy / 6 - font_line_height(FONT_S) / 2;
+ font_draw(c->text, (int)strlen(c->text), (cx + ox * t->scale) / 6, ty + 0.33f, FONT_S, 0x63DC, 255);
+ font_draw(c->text, (int)strlen(c->text), (cx + ox * t->scale) / 6, ty - 0.33f, FONT_S, 0xFFFF, 255);
}
ox += tw + 1;
}
diff --git a/games/celeste/src/save.c b/games/celeste/src/save.c
index 600be1d7..f7261493 100644
--- a/games/celeste/src/save.c
+++ b/games/celeste/src/save.c
@@ -165,6 +165,7 @@ static bool full_clear(void) {
return true;
}
+bool g_should_advance;
/* SaveData.RegisterCompletion */
void save_register_completion(void) {
ModeStats *m = save_mode();
@@ -184,6 +185,7 @@ void save_register_completion(void) {
}
}
if (s->area + 1 > g_save.unlocked_areas && s->area < AREAS - 1) g_save.unlocked_areas = (uint8_t)(s->area + 1);
+ g_should_advance = s->mode == M_A && !(m->flags & MS_COMPLETED) && chapter_index(s->area + 1, M_A) >= 0;
m->flags |= MS_COMPLETED;
s->in_area = 0;
}
diff --git a/games/celeste/src/text.c b/games/celeste/src/text.c
index 78719eb6..03fd3d43 100644
--- a/games/celeste/src/text.c
+++ b/games/celeste/src/text.c
@@ -112,9 +112,9 @@ static Port ports[MAX_PORTS];
static int nports;
/* the textbox's sizes (interface pixels) */
-#define LINE_H 63 /* Renogare 64's LineHeight - 1 */
-#define LINES 3 /* (int)(240 / LINE_H) */
-#define PAD 41.5f /* (272 - LINE_H * LINES) / 2 */
+#define LINE_H 79 /* Renogare 64's LineHeight - 1, at the bigger size the text has here (data.bin's FONTS) */
+#define LINES 2 /* three lines a page (FancyText's linesPerPage + 1): what the box holds at that size */
+#define PAD 41.5f /* the game's margin: (272 - 63 * 3) / 2 */
#define MAXW_NOPORT 1605 /* 1688 - PAD * 2 */
#define MAXW 1333 /* MAXW_NOPORT - 240 - 32 */
@@ -734,7 +734,7 @@ static FancyDraw TD;
static void blend_px(uint16_t *row, int x, uint16_t col, int a) {
if ((unsigned)x >= VIEW_W || a <= 0) return;
- row[x] = a >= 255 ? col : blend565(row[x], col, a + 1);
+ row[x] = a >= 255 ? col : blend565(row[x], scale565(col, a + 1), a + 1);
}
/* a glyph of `size` at screen (x, y) (its top-left), scaled by k (nearest pixels) */
static void glyph_strip(uint16_t *strip, int sy0, int sy1, int size, const uint8_t *g, float x, float y, float k,
@@ -745,21 +745,41 @@ static void glyph_strip(uint16_t *strip, int sy0, int sy1, int size, const uint8
int stride = (w + 1) / 2;
int W = (int)ceilf(w * k), H = (int)ceilf(h * k);
int X0 = (int)floorf(x + 0.5f), Y0 = (int)floorf(y + 0.5f);
+ float ik = 1 / k;
for (int r = 0; r < H; r++) {
int Y = Y0 + r;
if (Y < sy0 || Y >= sy1) continue;
- int gy = (int)(r / k);
+ int gy = (int)(r * ik);
if (gy >= h) continue;
uint16_t *row = strip + (Y - sy0) * VIEW_W;
for (int c = 0; c < W; c++) {
- int gx = (int)(c / k);
+ int gx = (int)(c * ik), v;
if (gx >= w) continue;
- int v = (bits[gy * stride + (gx >> 1)] >> ((gx & 1) * 4)) & 15;
- if (v) blend_px(row, X0 + c, col, v * 17 * alpha / 255);
+ if (k >= 1) v = ((bits[gy * stride + (gx >> 1)] >> ((gx & 1) * 4)) & 15) * 17;
+ else { /* smaller than its size: the glyph's pixels under this one, averaged (nearest ones drop strokes) */
+ float x0 = c * ik, x1 = x0 + ik, y0 = r * ik, y1 = y0 + ik, sum = 0;
+ for (int sy = (int)y0; sy < y1 && sy < h; sy++)
+ for (int sx = (int)x0; sx < x1 && sx < w; sx++)
+ sum += (fminf(x1, sx + 1) - fmaxf(x0, sx)) * (fminf(y1, sy + 1) - fmaxf(y0, sy)) *
+ ((bits[sy * stride + (sx >> 1)] >> ((sx & 1) * 4)) & 15);
+ v = (int)(sum * k * k * 17 + 0.5f);
+ }
+ if (v) blend_px(row, X0 + c, col, v * alpha / 255);
}
}
}
+/* the face for text at an interface scale, and its zoom: the 64 face up to 1.5, the 192 face above. The 64 face is
+ * shown a quarter bigger than the game's 1/6 already, and smaller is hard to read on this screen: so from 3/4 up
+ * the text keeps its size, and smaller captions (0.6) have the game's own 1/6 */
+static int face_of(float scale, float *k) {
+ if (scale >= 1.5f) {
+ *k = scale > 2 ? scale / 2 : 1;
+ return FONT_M;
+ }
+ *k = scale < 0.75f ? 0.8f : scale < 1 ? 1 : scale;
+ return FONT_S;
+}
/* ActiveFont.Draw(text, position, justify, scale, color), in interface units: each line justified
* by its own width, the block by its height */
static float line_width(const char *s, const char *end, int size) {
@@ -774,8 +794,8 @@ static float line_width(const char *s, const char *end, int size) {
}
void text_into(uint16_t *strip, int sy0, int sy1, const char *s, float px, float py, float jx, float jy, float scale,
uint16_t col, uint8_t alpha) {
- int size = scale > 1.01f ? FONT_M : FONT_S; /* the 64 face, or the 192 one at 1/9 (scale 2) */
- float k = size == FONT_M ? scale / 2 : scale;
+ float k;
+ int size = face_of(scale, &k);
const char *end = s + strlen(s);
float lh = font_line_height(size), lines = 1;
for (const char *q = s; q < end; q++) lines += *q == '\n';
@@ -805,8 +825,9 @@ void text_draw(const TextDraw *d) {
if (!d->s || !d->alpha) return;
int lines = 1;
for (const char *q = d->s; *q; q++) lines += *q == '\n';
- int size = d->scale > 1.01f ? FONT_M : FONT_S;
- float k = size == FONT_M ? d->scale / 2 : d->scale, h = lines * font_line_height(size) * k;
+ float k;
+ int size = face_of(d->scale, &k);
+ float h = lines * font_line_height(size) * k;
float y = d->y / 6 - h * d->jy;
gfx_custom(draw_strip, (void *)d, (int)floorf(y) - 1, (int)ceilf(y + h) + 1);
}
@@ -826,18 +847,20 @@ const char *ui_str(const char *key) {
return "";
}
-/* ActiveFont.Measure(text).X, in interface units at scale 1 */
-float text_measure(const char *s) {
- float w = 0;
+/* ActiveFont.Measure(text).X * scale, in interface units: as drawn (face_of) */
+float text_width(const char *s, float scale) {
+ float k, w = 0;
+ int size = face_of(scale, &k);
const char *end = s + strlen(s);
while (s < end) {
- float lw = line_width(s, end, FONT_M) * 3; /* the 192 face at 1/9 is the 64 one at 1/3 */
+ float lw = line_width(s, end, size) * k * 6;
if (lw > w) w = lw;
while (s < end && *s != '\n') s++;
if (s < end) s++;
}
return w;
}
+float text_measure(const char *s) { return text_width(s, 1); }
/* PixelFontSize.AutoNewline(text, width), in place (the text grows by nothing: spaces become newlines,
* words wider than the width get one inserted, up to cap) */
void text_auto_newline(char *s, int cap, float width) {
@@ -887,7 +910,7 @@ static void text_strip(uint16_t *strip, int sy0, int sy1, void *ctx) {
}
lines += cur;
/* in interface units, then to the screen */
- float px = TD.x - 0.5f * widest * TD.sx, py = TD.y - 0.5f * lines * 64 * TD.sy;
+ float px = TD.x - 0.5f * widest * TD.sx, py = TD.y - 0.5f * lines * (LINE_H + 1) * TD.sy;
cur = 0;
uint32_t seed = TD.seed;
for (int i = TD.start; i < end; i++) {
@@ -895,7 +918,7 @@ static void text_strip(uint16_t *strip, int sy0, int sy1, void *ctx) {
if (!t || t->type == N_NEWPAGE) break;
if (t->type == N_NEWLINE) {
if (cur == 0) cur = 1;
- py += 64 * cur * TD.sy;
+ py += (LINE_H + 1) * cur * TD.sy;
cur = 0;
}
if (t->type != N_CHAR) continue;
@@ -913,9 +936,9 @@ static void text_strip(uint16_t *strip, int sy0, int sy1, void *ctx) {
if (t->flags & CF_WAVE) zy += sinf(t->index * 0.25f + g_level.raw_time_active * 8) * 4;
zy += -8 * (1 - fade) + t->yoff * fade;
float x = px + t->pos / 4.f * TD.sx;
- /* the 64 face up to its size, the 192 face (shown at 1/6, 32 px) above */
- int size = v > 1.01f ? FONT_M : FONT_S;
- float k = size == FONT_M ? v / 2 : v;
+ /* the 64 face up to 1.5 (smaller while the box eases), the 192 face from there ({big}, {!}) */
+ int size = v >= 1.5f ? FONT_M : FONT_S;
+ float k = size == FONT_M ? fmaxf(1, v / 2) : v;
const uint8_t *g = font_glyph_rec(size, t->v);
if (!g) continue;
float gx = (x + zx * vx) / 6 + rds16(g + 2) / 16.f * k, gy = (py + zy * vy) / 6 + (int16_t)rd16(g + 4) * k;
@@ -970,10 +993,10 @@ static void box_render(Ent *e) {
if (!n || n->type == N_NEWPAGE) break;
if (n->type == N_NEWLINE) lines++;
}
- float ox = PAD + (b->has_cur && b->cur.side < 0 ? 256 : 0), oy = PAD;
- float hx = (!b->has_cur ? MAXW_NOPORT : MAXW) / 2.f, hy = LINES * LINE_H * num / 2;
+ float ox = PAD + (b->has_cur && b->cur.side < 0 ? 256 : 0);
+ float hx = (!b->has_cur ? MAXW_NOPORT : MAXW) / 2.f;
float k = lines >= 4 ? 0.75f : 1;
- TD = (FancyDraw){vx + ox + hx, vy + oy + hy, k, num * k, num, b->start, b->shake_seed};
+ TD = (FancyDraw){vx + ox + hx, vy + 272 * num / 2, k, num * k, num, b->start, b->shake_seed}; /* (in the box's middle) */
gfx_custom(text_strip, NULL, (int)((vy) / 6) - 4, (int)((vy + 272) / 6) + 8);
gfx_hud(false);
}
@@ -1102,10 +1125,10 @@ static void mini_render(Ent *e) {
p += n;
}
if (l < 3) m->line[l][k] = 0;
- float lh = LINE_H * 0.75f * m->ease;
+ float lh = (LINE_H + 1) * m->ease; /* (the game's 0.75 scale: here the text's own size, two lines) */
for (int i = 0; i < m->nlines && i < 3; i++) {
if (!m->line[i][0]) continue;
- m->td[i] = (TextDraw){m->line[i], 276, cy - m->nlines * lh / 2 + i * lh, 0, 0, 0.75f, 0xD69A, 255};
+ m->td[i] = (TextDraw){m->line[i], 276, cy - m->nlines * lh / 2 + i * lh, 0, 0, 1, 0xD69A, 255};
text_draw(&m->td[i]);
}
gfx_hud(false);
@@ -1129,7 +1152,7 @@ Ent *mini_textbox(const char *key) {
strncpy(P.key, key, sizeof P.key - 1);
P.color = 0xD69A, P.scale = 1, P.delay = 0.01f;
nnodes = base = nports = 0;
- parse_maxw = 1544;
+ parse_maxw = 1496; /* (what the box holds from 276 at the text's size here) */
parse_more();
parse_maxw = MAXW;
int at = 0;
@@ -1147,7 +1170,7 @@ Ent *mini_textbox(const char *key) {
} else if ((n->type == N_CHAR || n->type == N_NEWLINE) && at < MINI_LEN - 4 && m->len < MINI_LEN) {
uint32_t c = n->type == N_NEWLINE ? '\n' : n->v;
if (c == '\n') {
- if (!at || m->nlines >= 3) continue;
+ if (!at || m->nlines >= 2) continue;
m->nlines++;
}
if (c < 0x80) m->text[at++] = (char)c;
diff --git a/games/celeste/src/text.h b/games/celeste/src/text.h
index 5abd26c2..97002c0e 100644
--- a/games/celeste/src/text.h
+++ b/games/celeste/src/text.h
@@ -27,6 +27,7 @@ typedef struct {
} TextDraw;
void text_draw(const TextDraw *d);
float text_measure(const char *s); /* ActiveFont.Measure(s).X */
+float text_width(const char *s, float scale); /* ... * scale, as drawn */
/* ActiveFont.Draw into a strip, from a gfx_custom callback (nothing kept: menus redraw their words per strip) */
void text_into(uint16_t *strip, int sy0, int sy1, const char *s, float x, float y, float jx, float jy, float scale,
uint16_t col, uint8_t alpha);
diff --git a/games/celeste/tests/play.c b/games/celeste/tests/play.c
index 94419e92..2e1f30eb 100644
--- a/games/celeste/tests/play.c
+++ b/games/celeste/tests/play.c
@@ -143,6 +143,11 @@ int main(int argc, char **argv) {
game_save();
break;
}
+ if (getenv("CAMDBG") && fr == 0 && g_level.room)
+ printf("bounds %d %d %d %d\n", g_level.room->x, g_level.room->y, g_level.room->w, g_level.room->h);
+ if (getenv("CAMDBG") && g_player.ent)
+ printf("f%d room %s cam %.2f,%.2f player %.1f,%.1f tr %d at %.3f st %d\n", fr, level_room_name(), g_level.cam.x, g_level.cam.y,
+ g_player.ent->x, g_player.ent->y, g_level.transitioning, g_level.tr_at, g_player.state);
if (getenv("TRACE") && g_player.ent)
printf("f%d pos %.0f,%.0f sp %.1f,%.1f st %d gr %d dash %d stam %.0f anim %d keys %x\n", fr, g_player.ent->x, g_player.ent->y,
g_player.speed.x, g_player.speed.y, g_player.state, g_player.on_ground, g_player.dashes, g_player.stamina,
diff --git a/games/celeste/tools/textdata.py b/games/celeste/tools/textdata.py
index 7370d12e..956ea16c 100644
--- a/games/celeste/tools/textdata.py
+++ b/games/celeste/tools/textdata.py
@@ -9,8 +9,12 @@ from PIL import Image
from cel import CELESTE, Atlas
-# (face file, scale): body text (64 / 6 = 10.7 px), and the 192 face at 2x and 3x the body
-FONT_SIZES = [("renogare64", 1 / 6), ("renogare192", 1 / 9)]
+# (face file, scale): body text a quarter bigger than the interface's 1/6 (64 / 4.8 = 13.3 px, the
+# calculator's own small size: smaller is hard to read on its screen), and the 192 face for titles (21.3 px)
+FONT_SIZES = [("renogare64", 1 / 4.8), ("renogare192", 1 / 9)]
+# extra space after each glyph (screen pixels) for the body text: the face's own is a pixel or two at 64 px,
+# nothing at this size, and dots and colons run into what follows
+TRACKING = {"renogare64": 0.4}
def read_fnt(name):
@@ -69,7 +73,7 @@ def font_section(W, codes):
r = list(row) + ([0] if len(row) % 2 else [])
bitmaps += bytes(r[i] | r[i + 1] << 4 for i in range(0, len(r), 2))
glyphs.append((code, gx, gy, q.shape[1] if q.size else 0, q.shape[0] if q.size else 0,
- int(round(xa * scale * 16)), off))
+ int(round((xa * scale + TRACKING.get(face, 0)) * 16)), off))
kerns = [(a, b, int(round(v * scale * 16))) for (a, b), v in kern.items() if a in codes and b in codes]
w = W()
w.u16(len(glyphs))