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: the Prologue's night sky and snow
Mason Chen3c42e836a9a6
diff --git a/games/celeste/src/celeste.h b/games/celeste/src/celeste.hindex 0dd7b671..a5ded317 100644--- a/games/celeste/src/celeste.h+++ b/games/celeste/src/celeste.h@@ -178,7 +178,8 @@ extern bool g_res_drawing;uint16_t res_tex_by_name(const char *path); /* 0xFFFF: none */ /* free RAM while nothing else needs it *//* ---------------------------------------------------------------- drawing (gfx.c) */-enum { GF_FLIPX = 1, GF_FLIPY = 2, GF_ADD = 4, GF_SCALE = 8, GF_HUD = 16, GF_SILHOUETTE = 32 };+/* GF_ADD | GF_ADDALPHA: XNA's BlendState.Additive, the color also weighed by its alpha */+enum { GF_FLIPX = 1, GF_FLIPY = 2, GF_ADD = 4, GF_SCALE = 8, GF_HUD = 16, GF_SILHOUETTE = 32, GF_ADDALPHA = 64 };void gfx_begin(void);void gfx_end(void); /* draw the strips and push them */void gfx_clear(uint16_t c);diff --git a/games/celeste/src/ch0.c b/games/celeste/src/ch0.cindex 64a42d6d..fa80d172 100644--- a/games/celeste/src/ch0.c+++ b/games/celeste/src/ch0.c@@ -519,10 +519,12 @@ static bool ending_wait(Ending *s, float time) { /* WaitFor: raw time */s->t = 0;return false;}-/* PrologueEndingText: "You can do this.", a character every 1/20 s after 4 s, sliding in as it fades */-typedef struct { Co co; float fade[24]; int n, i; } EndText;+/* PrologueEndingText: "You can do this.", a character every 1/20 s after 4 s, sliding in as it fades; and the+ * HiresSnow added with it */+typedef struct { Co co; float fade[24], snow, snow_t; int n, i; } EndText;static void endtext_update(Ent *e) {EndText *t = ST(e, EndText);+ t->snow_t += DT;CO_BEGIN(&t->co);if (!e->eid) CO_WAIT(&t->co, 4);for (t->i = 0; t->i < t->n; t->i++)@@ -545,6 +547,7 @@ static void endtext_render(Ent *e) {if (f > 0) font_draw_glyph(FONT_S, c, x, y - 8 * (1 - f) / 6, 0xD69A, (uint8_t)(f * 255));x += font_glyph_advance(FONT_S, c, next);}+ hires_snow(t->snow_t, t->snow);gfx_hud(false);}static const EntClass ENDTEXT = {.size = sizeof(EndText), .name = "PrologueEndingText", .update = endtext_update,@@ -557,8 +560,10 @@ static Ent *endtext_new(bool instant) {e->eid = instant;char text[32];ST(e, EndText)->n = dialog_clean("CH0_END", text, sizeof text);- if (instant)+ if (instant) {for (int i = 0; i < 24; i++) ST(e, EndText)->fade[i] = 1;+ ST(e, EndText)->snow = 1;+ }return e;}@@ -577,7 +582,9 @@ static void ending_end(Ent *e, bool skipped) {else {EndText *t = ST(s->text, EndText);for (int i = 0; i < 24; i++) t->fade[i] = 1;+ t->snow = 1;}+ g_snow_alpha = 0;g_level.ending_text_y = 540;}g_time_rate = 1;@@ -647,6 +654,8 @@ static void ending_update(Ent *e) {g_level.ending_text_y = -540;while (s->percent < 1) {s->percent += DT * 0.25f;+ g_snow_alpha -= DT * 0.5f; /* the Snow stylegrounds out, HiresSnow in */+ if (s->text) ST(s->text, EndText)->snow = approach(ST(s->text, EndText)->snow, 1, DT * 0.5f);g_level.ending_text_y = 540 - 1080 * (1 - ease_cube_inout(s->percent));g_level.cam.y = (float)g_level.room->y - 3900 * ease_cube_inout(s->percent);CO_YIELD(c);diff --git a/games/celeste/src/gfx.c b/games/celeste/src/gfx.cindex 503aec1b..627a3809 100644--- a/games/celeste/src/gfx.c+++ b/games/celeste/src/gfx.c@@ -139,7 +139,7 @@ static const uint16_t *EC; /* the colors (by index: 1 the palette's first)static const uint8_t *EA; /* plain: the palette's own alphas (0..255), else NULL (ealpha) */static void prep(uint16_t pal, uint16_t tint, uint8_t alpha, uint8_t flags) {- flags &= GF_ADD | GF_SILHOUETTE;+ flags &= GF_ADD | GF_SILHOUETTE | GF_ADDALPHA;if (pal == ep_pal && tint == ep_tint && alpha == ep_alpha && flags == ep_flags) return;ep_pal = pal, ep_tint = tint, ep_alpha = alpha, ep_flags = flags;int n;@@ -180,6 +180,7 @@ static void prep(uint16_t pal, uint16_t tint, uint8_t alpha, uint8_t flags) {int aa = a[i] + (a[i] >> 7);if (ga != 256) aa = (aa * ga) >> 8;epal[i + 1] = (uint16_t)(lr[col >> 11] << 11 | lg[col >> 5 & 63] << 5 | lb[col & 31]);+ if (flags & GF_ADDALPHA) epal[i + 1] = scale565(epal[i + 1], aa);ealpha[i + 1] = (uint16_t)aa;if (aa != 256) ep_opaque = false;}diff --git a/games/celeste/src/level.h b/games/celeste/src/level.hindex c5b0b963..01a64868 100644--- a/games/celeste/src/level.h+++ b/games/celeste/src/level.h@@ -290,6 +290,8 @@ TileQ *blocks_new_tiles(int n); /* n tiles for an entity of the room being mvoid blocks_free_tiles(int slot); /* the room in that slot is gone: its blocks' tiles (entities.c) *//* stylegrounds (style.c) */+extern float g_snow_alpha; /* the Snow stylegrounds' Alpha */+void hires_snow(float time, float alpha); /* HiresSnow (menu.c), in screen coordinates */void style_init(void);void style_update(void);void style_render(bool fg);diff --git a/games/celeste/src/menu.c b/games/celeste/src/menu.cindex 9dbde2f4..c2376b35 100644--- a/games/celeste/src/menu.c+++ b/games/celeste/src/menu.c@@ -46,9 +46,12 @@ static void backdrop(void) {if (pass) return;static const uint32_t sky[6] = {0x0b0d24, 0x121633, 0x1a1e45, 0x262759, 0x35306a, 0x45376f};for (int i = 0; i < 6; i++) gfx_rect(0, i * 30, VIEW_W, 30, rgb(sky[i]), 255);+ hires_snow(M.t + 100, 1);+}+/* HiresSnow's flakes at `time`, faded by alpha (screen coordinates) */+void hires_snow(float time, float alpha) {Tex t;if (!tex_get(T__snow, &t)) return;- float time = M.t + 100;for (int i = 0; i < 24; i++) {uint32_t h = (uint32_t)i * 2654435761u;float n = (h >> 8 & 255) / 255.f;@@ -56,7 +59,7 @@ static void backdrop(void) {float sc = 0.05f + n * 0.75f, speed = sc * (2500 + (h >> 16 & 255) * 10);float x = 2176 - fmodf(time * speed + (h & 0xFFFF), 2176) - 128, y = (h >> 4 & 1023) + sinf(time + i) * 100;gfx_tex_ex(T__snow, x / 6, fmodf(y, 1080) / 6, t.fw * t.scale / 2.f, t.fh * t.scale / 2.f, sc, sc, 0, WHITE,- (uint8_t)(255 * (1 - n * 0.8f) * 0.6f), GF_ADD);+ a8((1 - n * 0.8f) * 0.6f * alpha), GF_ADD);}}diff --git a/games/celeste/src/style.c b/games/celeste/src/style.cindex ee062d2c..120308eb 100644--- a/games/celeste/src/style.c+++ b/games/celeste/src/style.c@@ -11,6 +11,8 @@ typedef struct {} SgState;static SgState sg[MAX_SG];static int nbg, nfg;+float g_snow_alpha; /* Snow.Alpha (the Prologue's ending fades the snow out) */+static float snow_tx, snow_ty; /* the snow's time: modulo 320 s (when the flakes' x repeat) and 2 pi s (their wave) *//* record: u8 effect, u8 flags, u16 tex, f32 x, y, scrollx, scrolly, speedx, speedy, alpha, u32 color,* u16 flag, notflag, tag, fadex, fadey, only */@@ -35,6 +37,7 @@ static bool is_visible(int i) {void style_init(void) {const uint8_t *c = g_level.ch;+ g_snow_alpha = 1;nbg = c[12], nfg = c[13];for (int i = 0; i < nbg + nfg && i < MAX_SG; i++) {const uint8_t *r = rec(i);@@ -45,16 +48,54 @@ void style_init(void) {}void style_update(void) {+ snow_tx = fmodf(snow_tx + DT, 320), snow_ty = fmodf(snow_ty + DT, 2 * PI_F);for (int i = 0; i < nbg + nfg && i < MAX_SG; i++) {const uint8_t *r = rec(i);sg[i].visible = is_visible(i);sg[i].x += rdf(r + 20) * DT + g_level.wind.x * DT * 0;sg[i].y += rdf(r + 24) * DT;- if (r[1] & SF_FADEIN) sg[i].fade = approach(sg[i].fade, sg[i].visible ? 1 : 0, DT);+ if (r[0] == SG_snowFg || r[0] == SG_snowBg) sg[i].fade = approach(sg[i].fade, sg[i].visible ? 1 : 0, DT * 2); /* visibleFade */+ else if (r[1] & SF_FADEIN) sg[i].fade = approach(sg[i].fade, sg[i].visible ? 1 : 0, DT);else sg[i].fade = sg[i].visible ? 1 : 0;}}+/* Snow: 60 flakes blown left, a pixel each. A flake's start, speed, color and wave come from its number, where it is+ * now from the time (Snow.Update's steps, worked out): the flakes need no memory */+typedef struct { float camx; uint8_t fg, a, row[60]; } SnowDraw; /* row: each flake's on the screen (this frame) */+static SnowDraw snow_draws[2];+static uint32_t flake_hash(int k, int fg) { return (uint32_t)(k + 1 + fg * 60) * 2654435761u; }+static float flake_speed(uint32_t h, int fg) { return (float)((fg ? 120 : 40) + (int)(h >> 8) % (fg ? 180 : 60)); }+static void snow_strip(uint16_t *strip, int y0, int y1, void *ctx) {+ const SnowDraw *s = ctx;+ static const uint16_t COLORS[2][2] = {{0x3186, 0x198F}, {0xFFFF, 0x64BD}}; /* Background-, ForegroundColors */+ int a = s->a + (s->a >> 7);+ for (int k = 0; k < 60; k++) {+ int py = s->row[k];+ if (py < y0 || py >= y1) continue;+ uint32_t h = flake_hash(k, s->fg);+ float x = (float)(h >> 22) * (320 / 1024.f) - flake_speed(h, s->fg) * snow_tx - s->camx;+ int px = (int)(x - floorf(x / 320) * 320);+ uint16_t *d = strip + (py - y0) * VIEW_W + (px < VIEW_W ? px : VIEW_W - 1), c = COLORS[s->fg][h >> 31];+ *d = a >= 256 ? c : blend565(*d, scale565(c, a), a);+ }+}+static void snow(int i, bool fg) {+ float a = sg[i].fade * g_snow_alpha;+ if (a <= 0) return;+ SnowDraw *s = &snow_draws[fg];+ s->camx = g_level.cam.x, s->fg = fg, s->a = a8(a);+ float half = snow_ty / 2, sh = sinf(half);+ for (int k = 0; k < 60; k++) { /* y: the wave's sum, cos(w) - cos(w + t) = 2 sin(w + t / 2) sin(t / 2) */+ uint32_t h = flake_hash(k, fg), g = h * 2246822519u;+ float y = (float)(g >> 22) * (180 / 1024.f) + flake_speed(h, fg) * 0.4f * sinf((g & 1023) * (2 * PI_F / 1024) + half) * sh -+ g_level.cam.y;+ int py = (int)(y - floorf(y / 180) * 180);+ s->row[k] = (uint8_t)(py < VIEW_H ? py : VIEW_H - 1);+ }+ gfx_custom(snow_strip, s, 0, VIEW_H);+}+static void parallax(int i) {const uint8_t *r = rec(i);uint16_t tex = rd16(r + 2);@@ -76,7 +117,7 @@ static void parallax(int i) {while (py < 0) py += fh;while (py > 0) py -= fh;}- uint8_t gf = (flags & SF_FLIPX ? GF_FLIPX : 0) | (flags & SF_FLIPY ? GF_FLIPY : 0) | (flags & SF_ADD ? GF_ADD : 0);+ uint8_t gf = (flags & SF_FLIPX ? GF_FLIPX : 0) | (flags & SF_FLIPY ? GF_FLIPY : 0) | (flags & SF_ADD ? GF_ADD | GF_ADDALPHA : 0);uint8_t a = (uint8_t)(alpha * 255);for (float x = px; x < 320; x += fw) {for (float y = py; y < 180; y += fh) {@@ -95,6 +136,8 @@ void style_render(bool fg) {if (sg[i].fade <= 0) continue;switch (r[0]) {case SG_parallax: parallax(i); break;+ case SG_snowFg:+ case SG_snowBg: snow(i, r[0] == SG_snowFg); break;default: break;}}