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.
C calculatorcalculator-gamescasiochesscrossy-roaddrive-madfx-cg50gamesgeometry-dashgraphing-calculatorndlessnumworksnumworks-appsnumworks-calculatornumworks-gamenumworks-gamestetristi-84-plus-ceti-nspire
Celeste: dash after-images
Mason Chenec7d60077604
diff --git a/games/celeste/src/ch2.c b/games/celeste/src/ch2.cindex 0a01130f..49fc4efa 100644--- a/games/celeste/src/ch2.c+++ b/games/celeste/src/ch2.c@@ -527,7 +527,7 @@ static void chaser_trail(Ent *e) {if (!level_on_interval(0.1f)) return;uint16_t t = spr_tex(&c->spr);if (t != 0xFFFF)- trail_add(e->x + c->spr_x, e->y + c->spr_y, t, c->spr.ox, c->spr.oy, c->scale * c->facing, c->scale, 0xAC3232, 1);+ trail_add(e->x + c->spr_x, e->y + c->spr_y, t, c->spr.ox, c->spr.oy, c->scale * c->facing, c->scale, 0xAC3232, 1, e->depth + 1);}static void chaser_on_player(Ent *e, Player *p) {V2 d = v2sub(v2(p->ent->x, p->ent->y), v2(e->x, e->y));diff --git a/games/celeste/src/ch3.c b/games/celeste/src/ch3.cindex 3140567d..9085273d 100644--- a/games/celeste/src/ch3.c+++ b/games/celeste/src/ch3.c@@ -1901,7 +1901,7 @@ static void osh_update(Ent *e) {break;}if (level_on_interval(0.05f)) {- trail_add(e->x, e->y, ospr_tex(&o->spr), 48, 48, o->sx, o->sy, 0x990000, 0.5f);+ trail_add(e->x, e->y, ospr_tex(&o->spr), 48, 48, o->sx, o->sy, 0x990000, 0.5f, e->depth + 1);}break;case OS_WAITING:diff --git a/games/celeste/src/ch5.c b/games/celeste/src/ch5.cindex a488cd19..d16cbf35 100644--- a/games/celeste/src/ch5.c+++ b/games/celeste/src/ch5.c@@ -2001,7 +2001,7 @@ static void seeker_trail(Ent *e) {Seeker *s = ST(e, Seeker);float k = 1 - 0.3f * s->wig.value;uint16_t t = cs_tex(&s->spr);- if (t != 0xFFFF) trail_add(e->x, e->y, t, 48, 48, s->sx * k * s->sprite_facing, s->sy * k, 0x99E550, 0.5f);+ if (t != 0xFFFF) trail_add(e->x, e->y, t, 48, 48, s->sx * k * s->sprite_facing, s->sy * k, 0x99E550, 0.5f, e->depth + 1);}static bool seeker_can_attack(Ent *e) {Seeker *s = ST(e, Seeker);@@ -3162,7 +3162,7 @@ static V2 pseeker_cam(Ent *e) {static void pseeker_trail(Ent *e) {PSeeker *s = ST(e, PSeeker);uint16_t t = cs_tex(&s->spr);- if (t != 0xFFFF) trail_add(e->x, e->y, t, 48, 48, s->sx * s->facing, s->sy, 0x99E550, 1);+ if (t != 0xFFFF) trail_add(e->x, e->y, t, 48, 48, s->sx * s->facing, s->sy, 0x99E550, 1, e->depth + 1);}static void pseeker_dash(Ent *e, V2 dir) {PSeeker *s = ST(e, PSeeker);@@ -3592,7 +3592,7 @@ static void evil_update(Ent *e) {particles_emit(PL_FG, &P_BadelineOldsite_P_Vanish, 2, v2add(at, v2(0, -6)), v2(2, 2), P_BadelineOldsite_P_Vanish.direction);if (k >= 0.1f && k <= 0.9f && level_on_interval(0.05f)) {uint16_t t = spr_tex(&b->spr);- if (t != 0xFFFF) trail_add(at.x + b->spr_pos.x, at.y + b->spr_pos.y, t, b->spr.ox, b->spr.oy, b->spr.sx, b->spr.sy, 0xFF0000, 0.5f);+ if (t != 0xFFFF) trail_add(at.x + b->spr_pos.x, at.y + b->spr_pos.y, t, b->spr.ox, b->spr.oy, b->spr.sx, b->spr.sy, 0xFF0000, 0.5f, v->shadow->depth + 1);}if (done) job_end(&v->job);}diff --git a/games/celeste/src/ch6.c b/games/celeste/src/ch6.cindex 11a0ba5e..59de361f 100644--- a/games/celeste/src/ch6.c+++ b/games/celeste/src/ch6.c@@ -1038,7 +1038,7 @@ static void bboost_update(Ent *e) {e->x = at.x, e->y = at.y;if (k < 0.9f && level_on_interval(0.03f)) {uint16_t t = fs_tex(&b->spr, BB_ANIMS, bb_tex);- if (t != 0xFFFF) trail_add(e->x + b->spr_pos.x, e->y + b->spr_pos.y, t, 12, 12, 1, 1, 0xFF6DEF, 0.5f);+ if (t != 0xFFFF) trail_add(e->x + b->spr_pos.x, e->y + b->spr_pos.y, t, 12, 12, 1, 1, 0xFF6DEF, 0.5f, e->depth + 1);particles_emit(PL_FG, &P_BadelineBoost_P_Move, 1, v2(e->x, e->y), v2(4, 4), P_BadelineBoost_P_Move.direction);}if (done) {@@ -2067,7 +2067,7 @@ static void boss_move_sequence(Ent *e) {float ox, oy;cs_origin(&b->spr, t, &ox, &oy);V2 sc = boss_spr_scale(e);- if (t != 0xFFFF) trail_add(e->x + b->spr_pos.x, e->y + b->spr_pos.y, t, ox, oy, sc.x, sc.y, 0xAC3232, 0.5f);+ if (t != 0xFFFF) trail_add(e->x + b->spr_pos.x, e->y + b->spr_pos.y, t, ox, oy, sc.x, sc.y, 0xAC3232, 0.5f, e->depth + 1);particles_emit(PL_MID, &P_Player_P_DashB, 2, boss_center(e), v2(3, 3), vangle(v2sub(b->to, b->from)));}if (done) { /* OnComplete */@@ -4096,7 +4096,7 @@ static bool sjend_par(void *ctx, Co *c) {if (sg) BD(bd)->spr.sx = (float)sg;if ((int)((g_level.time_active - DT) / 0.1f) < (int)(g_level.time_active / 0.1f)) { /* OnInterval: TrailManager.Add */Sprite *sp = &BD(bd)->spr;- trail_add(floorf(bd->x), floorf(bd->y), spr_tex(sp), sp->ox, sp->oy, sp->sx, sp->sy, 0xAC3232, 1);+ trail_add(floorf(bd->x), floorf(bd->y), spr_tex(sp), sp->ox, sp->oy, sp->sx, sp->sy, 0xAC3232, 1, bd->depth + 1);}}NB_YIELD(c);diff --git a/games/celeste/src/ch7.c b/games/celeste/src/ch7.cindex cebd82ba..cbb1b9e0 100644--- a/games/celeste/src/ch7.c+++ b/games/celeste/src/ch7.c@@ -1243,7 +1243,7 @@ static void around_step(Around *a) {if (level_on_interval(0.1f)) {BDummy *b = BD(a->e);uint16_t t = spr_tex(&b->spr);- if (t != 0xFFFF) trail_add(a->e->x, a->e->y, t, b->spr.ox, b->spr.oy, b->spr.sx, b->spr.sy, 0xAC3232, 1); /* Player.NormalHairColor */+ if (t != 0xFFFF) trail_add(a->e->x, a->e->y, t, b->spr.ox, b->spr.oy, b->spr.sx, b->spr.sy, 0xAC3232, 1, a->e->depth + 1); /* Player.NormalHairColor */}a->p += DT / 3;return;diff --git a/games/celeste/src/ent.c b/games/celeste/src/ent.cindex af824a91..a1c84ac0 100644--- a/games/celeste/src/ent.c+++ b/games/celeste/src/ent.c@@ -2,6 +2,7 @@* JumpThru movement (pixel by pixel, pushing and carrying riders). */#include "ent.h"#include "level.h"+#include "fx.h"const EntMore g_no_more;Ent g_ents[MAX_ENTS];@@ -155,12 +156,15 @@ void ents_mark_unsorted(void) { unsorted = true; }void ents_render_between(int hi, int lo) {if (unsorted) sort_ents();+ int at = hi; /* the trails' snapshots among them (each at its own depth, after those of the same) */for (int i = 0; i < nsorted; i++) {Ent *e = &g_ents[sorted[i]];if (!e->cls || e->dead == 1 || !e->visible || !e->cls->render || (e->tags & TAG_HUD)) continue;if (e->depth > hi || e->depth <= lo) continue;+ if (e->depth < at) trail_render_between(at, e->depth), at = e->depth;e->cls->render(e);}+ trail_render_between(at, lo);}/* HudRenderer: the interface's entities, over everything */void ents_render_hud(void) {diff --git a/games/celeste/src/fx.c b/games/celeste/src/fx.cindex 2fa36e7d..a3f08121 100644--- a/games/celeste/src/fx.c+++ b/games/celeste/src/fx.c@@ -116,34 +116,115 @@ void dust_burst_fg(V2 pos, float dir, int n, float range) {}/* ---------------------------------------------------------------- trails */-typedef struct {- float x, y, ox, oy, sx, sy, t, dur;- uint16_t tex;- uint32_t color;- uint8_t on;-} Trail;-static Trail trails[12];+#pragma GCC push_options+#pragma GCC optimize("Os") /* a few a frame: smaller over faster */+/* TrailManager.Snapshot: what was drawn into its 64x64 cell (the sprite's frame, and PlayerHair's nodes with+ * their outline) is kept as what to draw again, not as pixels; drawn as one silhouette in Color * 0.75 *+ * (1 - CubeOut(Percent)), at Depth (the entity's + 1), oldest first */+static Trail trails[MAX_TRAILS];+static int ntrails;-void trail_add(float x, float y, uint16_t tex, float ox, float oy, float sx, float sy, uint32_t color, float dur) {- for (int i = 0; i < 12; i++)- if (!trails[i].on) {- trails[i] = (Trail){x, y, ox, oy, sx, sy, 0, dur, tex, color, 1};- return;+Trail *trail_add(float x, float y, uint16_t tex, float ox, float oy, float sx, float sy, uint32_t color, float dur, int depth) {+ if (tex == 0xFFFF) return NULL;+ if (ntrails >= MAX_TRAILS) { /* (not the game's 64: the oldest goes, another's before Madeline's) */+ int k = 0;+ while (k < ntrails - 1 && trails[k].nhair) k++;+ if (trails[k].nhair) k = 0;+ memmove(trails + k, trails + k + 1, (size_t)(--ntrails - k) * sizeof *trails);+ }+ Trail *t = &trails[ntrails++];+ memset(t, 0, sizeof *t);+ t->x = (int16_t)floorf(x + 0.5f), t->y = (int16_t)floorf(y + 0.5f);+ t->ox = ox, t->oy = oy, t->sx = sx, t->sy = sy, t->dur = dur;+ t->tex = tex, t->color = rgb(color), t->depth = (int16_t)depth;+ t->born = (uint8_t)g_frame;+ return t;+}+void trail_update(void) { /* Snapshot.Update (Tags.Global: not while between rooms, frozen or paused) */+ if (g_level.transitioning) return;+ for (int i = 0; i < ntrails; i++) {+ Trail *t = &trails[i];+ if (t->born == (uint8_t)g_frame && t->pct == 0) continue; /* added this frame: in the scene from the next */+ if ((t->pct += DT / t->dur) >= 1) {+ memmove(t, t + 1, (size_t)(ntrails - i - 1) * sizeof *t);+ ntrails--, i--;}+ }}-void trail_update(void) {- for (int i = 0; i < 12; i++)- if (trails[i].on && (trails[i].t += DT) >= trails[i].dur) trails[i].on = 0;++/* what of view row Y a texture drawn at (PX, PY) (origin o, scale s, as gfx_tex_ex) covers, as bits from+ * column cx on */+static uint64_t trail_tex_row(const Tex *t, int PX, int PY, float ox, float oy, float sx, float sy, int Y, int cx) {+ int k = t->scale > 1 ? t->scale : 1;+ ox /= k, oy /= k, sx *= k, sy *= k;+ int v = (int)floorf((Y + 0.5f - PY) / sy + oy) - t->oy;+ if ((unsigned)v >= (unsigned)t->h || t->w > 64) return 0;+ uint8_t px[64];+ tex_row(t, v, px);+ float isx = 1 / sx, xa = PX + (t->ox - ox) * sx, xb = PX + (t->ox + t->w - ox) * sx;+ int i0 = (int)floorf(fminf(xa, xb)) - cx, i1 = (int)ceilf(fmaxf(xa, xb)) - cx;+ uint64_t m = 0;+ for (int i = i0 < 0 ? 0 : i0; i < i1 && i < 64; i++) {+ int u = (int)floorf((cx + i + 0.5f - PX) * isx + ox) - t->ox;+ if ((unsigned)u < (unsigned)t->w && px[u]) m |= 1ull << i;+ }+ return m;+}+static const uint16_t TR_HAIR[4] = {T_characters_player_bangs00, T_characters_player_bangs01, T_characters_player_bangs02, T_characters_player_hair00};+/* PlayerHair.Render's node i (the bangs, else hair00) on row Y */+static uint64_t trail_node_row(const Trail *t, const Tex *hair, int i, int Y, int cx) {+ int PY = t->y - g_camy + t->hair[i][1];+ if (Y < PY - 6 || Y > PY + 6) return 0; /* (10x10 around the node, scaled by 1 at most) */+ float as = fabsf(t->sx), num = 0.25f + (1 - (float)i / t->nhair) * 0.75f;+ return trail_tex_row(&hair[i > 0], t->x - g_camx + t->hair[i][0], PY, 5, 5, i ? num * as : t->sx < 0 ? -as : as, num, Y, cx);}-void trail_render(void) {- for (int i = 0; i < 12; i++) {+static void trail_strip(uint16_t *strip, int sy0, int sy1, void *ctx) {+ uint32_t set = (uint32_t)(uintptr_t)ctx;+ for (int i = 0; i < ntrails; i++) {+ if (!(set >> i & 1)) continue;Trail *t = &trails[i];- if (!t->on) continue;- float a = 1 - t->t / t->dur;- gfx_tex_ex(t->tex, t->x, t->y, t->ox, t->oy, t->sx, t->sy, 0, rgb(t->color), (uint8_t)(a * 255 * 0.75f), GF_SILHOUETTE);+ Tex spr, hair[2];+ if (!tex_get(t->tex, &spr) || (t->nhair && (!tex_get(TR_HAIR[t->bangs], &hair[0]) || !tex_get(TR_HAIR[3], &hair[1])))) continue;+ float e = 1 - t->pct;+ int a8 = (int)(0.75f * e * e * e * 255), a = a8 + (a8 >> 7);+ if (a <= 0) continue;+ uint16_t pc = scale565(t->color, a);+ int cx = t->x - g_camx - 32, cy = t->y - g_camy - 32; /* the cell */+ int y0 = cy > sy0 ? cy : sy0, y1 = cy + 64 < sy1 ? cy + 64 : sy1;+ for (int Y = y0; Y < y1; Y++) {+ uint64_t m = trail_tex_row(&spr, t->x - g_camx, t->y + t->sdy - g_camy, t->ox, t->oy, t->sx, t->sy, Y, cx);+ for (int n = 0; n < t->nhair; n++) { /* the node, and its outline (drawn at the 4 neighbours) */+ uint64_t b = trail_node_row(t, hair, n, Y, cx);+ m |= b | b << 1 | b >> 1 | trail_node_row(t, hair, n, Y - 1, cx) | trail_node_row(t, hair, n, Y + 1, cx);+ }+ uint16_t *row = strip + (Y - sy0) * VIEW_W;+ while (m) {+ int X = cx + __builtin_ctzll(m);+ m &= m - 1;+ if ((unsigned)X < VIEW_W) row[X] = blend565(row[X], pc, a);+ }+ }+ }+}+/* the snapshots of depth in (lo, hi] (drawn among the entities: ents_render_between), in one command */+void trail_render_between(int hi, int lo) {+ uint32_t set = 0;+ int y0 = 1 << 30, y1 = -(1 << 30);+ Tex t;+ for (int i = 0; i < ntrails; i++) {+ Trail *tr = &trails[i];+ /* (from the frame after it was added, as Scene.Add: between rooms too, at Percent 0) */+ if (tr->depth > hi || tr->depth <= lo || (tr->pct <= 0 && tr->born == (uint8_t)(g_frame - 1))) continue;+ if (!tex_get(tr->tex, &t) || (tr->nhair && (!tex_get(TR_HAIR[tr->bangs], &t) || !tex_get(TR_HAIR[3], &t)))) continue; /* (loaded now) */+ set |= 1u << i;+ int cy = tr->y - g_camy - 32;+ if (cy < y0) y0 = cy;+ if (cy + 64 > y1) y1 = cy + 64;}+ if (set) gfx_custom(trail_strip, (void *)(uintptr_t)set, y0, y1);}-void trail_clear(void) { memset(trails, 0, sizeof trails); }+void trail_clear(void) { ntrails = 0; }+#pragma GCC pop_optionsvoid fx_update(void) {particles_update();trail_update();diff --git a/games/celeste/src/fx.h b/games/celeste/src/fx.hindex ad2b805d..eb409139 100644--- a/games/celeste/src/fx.h+++ b/games/celeste/src/fx.h@@ -33,9 +33,19 @@ void dust_burst(V2 pos, float dir, int n);void dust_burst_fg(V2 pos, float dir, int n, float range);/* TrailManager: afterimages */-void trail_add(float x, float y, uint16_t tex, float ox, float oy, float sx, float sy, uint32_t color, float duration);+#define MAX_TRAILS 12+#define TRAIL_HAIR 7+typedef struct {+ float ox, oy, sx, sy, pct, dur; /* sx: the facing's sign in it */+ int16_t x, y, depth; /* Position (rounded), Depth */+ uint16_t tex, color; /* the frame; Color (RGB565) */+ int8_t sdy; /* the sprite's offset */+ uint8_t born, nhair, bangs; /* the frame added; PlayerHair's nodes, its bangs frame */+ int8_t hair[TRAIL_HAIR][2]; /* the nodes (as drawn: rounded) from Position */+} Trail;+Trail *trail_add(float x, float y, uint16_t tex, float ox, float oy, float sx, float sy, uint32_t color, float duration, int depth);void trail_update(void);-void trail_render(void);+void trail_render_between(int hi, int lo);void trail_clear(void);/* SlashFx and the like: short sprite effects */diff --git a/games/celeste/src/gfx.c b/games/celeste/src/gfx.cindex e4270648..d356b9a2 100644--- a/games/celeste/src/gfx.c+++ b/games/celeste/src/gfx.c@@ -45,7 +45,7 @@ static Cmd cmds[MAX_CMDS];static int ncmds;static Affine affs[MAX_AFFINE];static int naffs;-static Custom customs[16];+static Custom customs[20];static int ncustoms;void gfx_camera(float x, float y) {@@ -865,7 +865,7 @@ static void blit_mask(uint16_t *strip, int sy0, int sy1, const uint8_t *bits, in}void gfx_custom(StripFn fn, void *ctx, int y0, int y1) {- if (ncustoms >= 16) return;+ if (ncustoms >= 20) return;Cmd *c = add(OP_CUSTOM, y0, y1);if (!c) return;customs[ncustoms] = (Custom){fn, ctx};diff --git a/games/celeste/src/level.c b/games/celeste/src/level.cindex 691d95f3..177fff3e 100644--- a/games/celeste/src/level.c+++ b/games/celeste/src/level.c@@ -529,6 +529,7 @@ static void chapter_memory(const uint8_t *ch) {/* LevelLoader: the session's chapter, at its level */void level_start(int intro) {memset(&g_level, 0, sizeof g_level);+ trail_clear(); /* (a new Level: a new TrailManager) */g_level.chapter = g_session.chapter;g_level.ch = chapter_rec(g_session.chapter);chapter_memory(g_level.ch);diff --git a/games/celeste/src/player.c b/games/celeste/src/player.cindex b53c0f8a..b0de396c 100644--- a/games/celeste/src/player.c+++ b/games/celeste/src/player.c@@ -1178,11 +1178,34 @@ static int climb_update(void) {}/* ---------------------------------------------------------------- dash */+/* Player.CreateTrail: TrailManager.Add(this, (|Scale.X| * Facing, Scale.Y), wasDashB ? NormalHairColor :+ * UsedHairColor), 1 s, at Depth + 1; what it shows is taken at the end of the frame (trail_snapshots) */static void create_trail(void) {- uint16_t t = spr_tex(&P->spr);- if (t == 0xFFFF) return;- trail_add(floorf(E->x), floorf(E->y), t, P->spr.ox, P->spr.oy, P->spr.sx * P->facing, P->spr.sy,- P->was_dash_b ? NormalHairColor : UsedHairColor, 0.5f);+ if (P->trail_n < 2) P->trail_n++;+ P->trail_color = rgb(P->was_dash_b ? NormalHairColor : UsedHairColor);+ P->trail_depth = (int16_t)(E->depth + 1);+}+/* TrailManager.BeforeRender: the sprite's frame and the hair's nodes as they are drawn this frame */+static void trail_snapshots(void) {+ for (int n = P->trail_n; n; n--) {+ P->trail_n = 0;+ float x = floorf(E->x), y = floorf(E->y);+ Trail *t = trail_add(x, y, spr_tex(&P->spr), P->spr.ox, P->spr.oy, fabsf(P->spr.sx) * P->facing, P->spr.sy, 0, 1, P->trail_depth);+ if (!t) return;+ t->color = P->trail_color;+ t->sdy = (int8_t)P->spr_dy;+ int hx, hy, fr, carry;+ bool has;+ hair_meta(t->tex, &hx, &hy, &fr, &has, &carry);+ if (!has) continue;+ t->nhair = (uint8_t)(P->hair_count < TRAIL_HAIR ? P->hair_count : TRAIL_HAIR);+ t->bangs = (uint8_t)(fr < 3 ? fr : 0);+ for (int i = 0; i < t->nhair; i++) {+ V2 h = P->hair[i];+ if (!i) h = v2(floorf(h.x), floorf(h.y));+ t->hair[i][0] = (int8_t)(floorf(h.x + 0.5f) - x), t->hair[i][1] = (int8_t)(floorf(h.y + 0.5f) - y);+ }+ }}static void dash_begin(void) {@@ -2581,6 +2604,7 @@ void player_after_update(Player *p) {if (!p->ent || !p->ent->cls) return;E = p->ent;if (!p->body || p->body_step < 4) hair_after_update();+ trail_snapshots();}/* ---------------------------------------------------------------- camera */diff --git a/games/celeste/src/player.h b/games/celeste/src/player.hindex aef2f776..0457526a 100644--- a/games/celeste/src/player.h+++ b/games/celeste/src/player.h@@ -78,8 +78,11 @@ struct Player {float launched_timer;float dash_trail_timer;bool was_dash_b;+ uint8_t trail_n; /* CreateTrail calls this frame: snapshots taken once it is drawn (BeforeRender) */+ uint16_t trail_color;V2 before_dash_speed;bool started_dashing;+ int16_t trail_depth;float hair_flash_timer;V2 wind_dir;float wind_timeout, wind_hair_timer;