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.

Champion Island: the intro cutscene, the island map menu, lighter menus

Mason Chen4b58544fdfca
diff --git a/games/championisland/src/film.c b/games/championisland/src/film.c
index f71a7e43..3927bb83 100644
--- a/games/championisland/src/film.c
+++ b/games/championisland/src/film.c
@@ -1,18 +1,79 @@
-/* Cutscenes and the doodle's films (intro, each champion's outro, the ending). */
+/* The cutscene and the doodle's films.
+ *
+ * The one cutscene (the cutscene library's "intro", Qq) is an Animate movie
+ * with subtitles: it plays to its end (Gq), or Back or OK on its close button
+ * leave it (Iq, Pq), and the island comes back.
+ *
+ * The films (the intro, each champion's intro and outro, the ending) are
+ * videos in the doodle; the calculator has no room for them, so they are
+ * marked as seen and the game goes on as it does after one. */
#include <stdio.h>
#include "ent.h"
+static NodeId film;
+
+static void translate(NodeId n) {
+ ent_translate(n);
+ for (NodeId c = nodes[n].first; c; c = nodes[c].next) translate(c);
+}
+
+static void came_on(NodeId n) {
+ ent_register_tree(n);
+ translate(n);
+}
+
static void start_cutscene(void) {
+ film = 0;
+ node_dynamic_sym = S_cutscene_nbb; /* the movie inside the cutscene entity */
NodeId n = node_new_sym(S_cutscene_pab);
+ node_dynamic_sym = NONE16;
+ if (!n) return;
+ node_stream_hook = came_on;
node_add(game.root, n);
ent_register_tree(n);
+ translate(n);
+ film = ent_first(C_cutscene);
+ if (film) node_goto(film, NULL, 0, true);
}
+
+static void tick_cutscene(void) {
+ /* Pq, Iq: Back, or OK on the close button */
+ if (in.pressed[A_BACK] || in.pressed[A_ACTION]) {
+ input_consume(A_BACK);
+ input_consume(A_ACTION);
+ game_go("overworld");
+ return;
+ }
+ /* Gq: the end of the movie */
+ if (film && nodes[film].frame + 1 >= node_frames(film)) game_go("overworld");
+}
+
+static void end_cutscene(void) {
+ film = 0;
+ node_stream_hook = NULL;
+}
+
static void start_video(void) {
char k[48];
snprintf(k, sizeof k, "%s_VIDEO_SEEN", game.variant);
store_set_bool(k, true);
- game_go("overworld");
+ /* Iu: after a sport's first film comes the sport; after a champion's
+ * outro, the ending once all seven are won, else the island */
+ size_t n = strlen(game.variant);
+ if (n > 5 && !strcmp(game.variant + n - 5, "outro") && strcmp(game.variant, "outro")) {
+ static const char *const sports[7] = {"archery", "climbing", "marathon", "pingpong", "rugby", "skate", "swim"};
+ bool all = true;
+ for (int i = 0; i < 7; i++) if (rating_of(sports[i]) < 3) all = false;
+ if (all) store_set_bool("outro_VIDEO_SEEN", true);
+ }
+ if (n > 5 && !strcmp(game.variant + n - 5, "intro") && strcmp(game.variant, "intro")) {
+ char s[32];
+ snprintf(s, sizeof s, "%.*s", (int)(n - 5), game.variant);
+ game_go(s);
+ } else game_go("overworld");
}
-static void tick(void) {}
-const SceneDef scene_cutscene = {"cutscene", start_cutscene, tick, NULL, NULL, NULL, NULL};
-const SceneDef scene_video = {"video", start_video, tick, NULL, NULL, NULL, NULL};
+
+static void tick_video(void) {}
+
+const SceneDef scene_cutscene = {"cutscene", start_cutscene, tick_cutscene, end_cutscene, NULL, NULL, NULL};
+const SceneDef scene_video = {"video", start_video, tick_video, NULL, NULL, NULL, NULL};
diff --git a/games/championisland/src/game.c b/games/championisland/src/game.c
index 7252e006..e6db73ff 100644
--- a/games/championisland/src/game.c
+++ b/games/championisland/src/game.c
@@ -92,7 +92,8 @@ const ScoreRule *score_rule(const char *key) {
int score_rating(const char *key, float g) {
const ScoreRule *r = score_rule(key);
if (!r) return 0;
- if (r->time) return g < r->gold ? 3 : g < r->silver ? 2 : g < r->bronze ? 1 : 0;
+ /* Ao: the doodle compares the rule itself with "time", never true, so every
+ * score is rated as points (bigger is better) */
return g > r->gold ? 3 : g > r->silver ? 2 : g > r->bronze ? 1 : 0;
}
diff --git a/games/championisland/src/game.h b/games/championisland/src/game.h
index f7b1a72a..4e55575b 100644
--- a/games/championisland/src/game.h
+++ b/games/championisland/src/game.h
@@ -78,6 +78,7 @@ void menus_tick(void);
void menus_draw(void);
/* end of a sport: rates the score, records it, plays the outro or shows the results */
void menus_game_over(float score);
+void menus_game_over_rated(float score, int rating); /* when the sport rates it itself (-1: by score) */
void menus_game_over_rated(float score, int rating); /* the sport's own rating (0..3), -1: the table's */
void hud_init(void);
diff --git a/games/championisland/src/menus.c b/games/championisland/src/menus.c
index 36cda7d3..e97d4b37 100644
--- a/games/championisland/src/menus.c
+++ b/games/championisland/src/menus.c
@@ -374,19 +374,44 @@ static void results_tick(NodeId m) {
if (count_t > 26) results_counting = false;
}
+/* Gp: the map with each sport's best, its stars, the team and where the player is */
static void stats_tick(NodeId m) {
+ static const char *const nm[7] = {"archery", "climbing", "marathon", "pingpong", "rugby", "skate", "syncswim"};
+ static const char *const stars[4] = {"0star", "1star", "2star", "3star"};
for (int i = 0; i < 7; i++) {
- NodeId b = button(m, sports[i]);
- if (!b) continue;
+ char k[24];
bool has;
float s = score_best(sports[i], &has);
const ScoreRule *r = score_rule(sports[i]);
if (has) format_score(stat_bufs[i], sizeof stat_bufs[i], s, r && r->time);
else snprintf(stat_bufs[i], sizeof stat_bufs[i], "???");
- NodeId sc = node_find(b, "score");
+ snprintf(k, sizeof k, "%sScore", nm[i]);
+ NodeId sc = node_find(m, k);
if (sc) node_set_text(sc, stat_bufs[i]);
- NodeId st = node_find(b, "stars");
- if (st) node_goto(st, NULL, rating_of(sports[i]), false);
+ snprintf(k, sizeof k, "%sStars", nm[i]);
+ NodeId st = node_find(m, k);
+ int rt = rating_of(sports[i]);
+ if (st) node_goto(st, stars[rt < 0 ? 0 : rt > 3 ? 3 : rt], 0, false);
+ }
+ /* the team, in its colour */
+ static const struct { const char *team; uint16_t c; } teams[] = {
+ {"BLUE", 0x657E}, {"GREEN", 0x6F8D}, {"RED", 0xFACB}, {"YELLOW", 0xF74D}, {"NO_TEAM", 0xFFFF}};
+ const char *team = store_str("PLAYER_TEAM");
+ static char up[16];
+ snprintf(up, sizeof up, "%s", team && team[0] ? team : "NO_TEAM");
+ for (char *c = up; *c; c++) if (*c >= 'a' && *c <= 'z') *c -= 32;
+ NodeId tn = node_find(m, "teamName");
+ if (tn) {
+ node_set_text(tn, msg(up));
+ for (unsigned i = 0; i < sizeof teams / sizeof teams[0]; i++)
+ if (!strcmp(teams[i].team, up)) node_set_text_color(tn, teams[i].c);
+ }
+ /* the player on the map: the island (Vs) squeezed into the map picture (Ws) */
+ NodeId map = node_find(m, "map"), pl = map ? node_find(map, "player") : 0;
+ if (pl && store_get("PLAYER_POS_X").type == SV_NUM) {
+ float nx = (store_num("PLAYER_POS_X", 0) + 1536) / 3088, ny = (store_num("PLAYER_POS_Y", 0) + 833) / 1600;
+ nodes[pl].x = 120 * clampf(nx, .1f, .9f);
+ nodes[pl].y = 96 * clampf(ny, .1f, .85f);
}
}
diff --git a/games/championisland/src/node.c b/games/championisland/src/node.c
index 4fcc91f0..9d4c78c3 100644
--- a/games/championisland/src/node.c
+++ b/games/championisland/src/node.c
@@ -15,7 +15,7 @@ static Xf xfs[XF_MAX];
/* texts set by code */
#define TX_MAX 48
-typedef struct { NodeId n; const char *s; } Tx;
+typedef struct { NodeId n; const char *s; int32_t color; } Tx; /* color: RGB565, -1 as designed */
static Tx txs[TX_MAX];
/* event listeners */
@@ -198,12 +198,13 @@ NodeId node_new_sym_lazy(uint16_t sym) {
return n;
}
-uint16_t node_lazy_sym = NONE16;
+uint16_t node_lazy_sym = NONE16, node_dynamic_sym = NONE16;
static bool key_bounds(const Key *k, float *x, float *y, float *w, float *h);
static NodeId new_child_for(const Key *k) {
NodeId c = 0;
- if (k->kind == CK_SYM) c = k->ref == node_lazy_sym ? node_new_sym_lazy(k->ref) : node_new_sym(k->ref);
+ if (k->kind == CK_SYM)
+ c = k->ref == node_lazy_sym ? node_new_sym_lazy(k->ref) : k->ref == node_dynamic_sym ? node_new_sym_dynamic(k->ref) : node_new_sym(k->ref);
else if (k->kind == CK_SHAPE) { c = node_new(NK_SHAPE); if (c) nodes[c].ref = k->ref; }
else if (k->kind == CK_TEXT) { c = node_new(NK_TEXT); if (c) nodes[c].ref = k->ref; }
if (c) {
@@ -237,6 +238,16 @@ NodeId node_new_sym_frame(uint16_t sym, int frame) {
return n;
}
+/* a long movie: only the children of its current frame, made and freed as it plays */
+NodeId node_new_sym_dynamic(uint16_t sym) {
+ NodeId n = node_new_sym_frame(sym, 0);
+ if (n && nodes[n].kind == NK_CLIP) {
+ nodes[n].flags2 |= NF2_DYN;
+ nodes[n].flags |= NF_PLAYING;
+ }
+ return n;
+}
+
/* Creates the nodes of the children a clip's timeline shows at any frame. */
static void instantiate_children(NodeId n) {
Clip c;
@@ -454,9 +465,37 @@ static void update_rec(NodeId n) {
Clip c;
if (clip_get(p->sym, &c) && c.nframes > 1) {
const uint8_t *q = c.slots;
- NodeId ch = p->first;
+ NodeId ch = p->first, prev = 0;
+ bool dyn = p->flags2 & NF2_DYN;
for (unsigned s = 0; s < c.nslots; s++) {
- while (ch && nodes[ch].slot != NONE16 && nodes[ch].slot < s) ch = nodes[ch].next;
+ while (ch && nodes[ch].slot != NONE16 && nodes[ch].slot < s) { prev = ch; ch = nodes[ch].next; }
+ if (dyn) {
+ /* a long movie: its children exist while they are on stage */
+ Key k;
+ uint16_t idx;
+ const uint8_t *q2 = slot_key(q, p->frame, &k, &idx);
+ bool present = idx != NONE16 && !(k.flags & K_ABSENT);
+ bool have = ch && nodes[ch].slot == s;
+ if (present && !have && needs_node(&k)) {
+ NodeId nc = new_child_for(&k);
+ if (nc) {
+ nodes[nc].slot = (uint16_t)s;
+ nodes[nc].parent = n;
+ nodes[nc].next = ch;
+ nodes[nc].key = NONE16; /* its key is applied just below */
+ nodes[nc].flags &= (uint8_t)~NF_ONSTAGE;
+ if (prev) nodes[prev].next = nc; else nodes[n].first = nc;
+ ch = nc;
+ if (node_stream_hook) node_stream_hook(nc);
+ }
+ } else if (!present && have && !(nodes[ch].flags2 & NF2_KEEP) && nodes[ch].name == NONE16) {
+ NodeId nx = nodes[ch].next;
+ node_free(ch);
+ ch = nx;
+ q = q2;
+ continue;
+ }
+ }
if (ch && nodes[ch].slot == s) {
Key k;
uint16_t idx;
@@ -955,6 +994,7 @@ static void draw_virtual(uint16_t sym, unsigned frame, Mat m, uint8_t alpha, int
}
static const char *text_of(NodeId n);
+static int32_t text_color(NodeId n);
static void draw_rec(NodeId id, Mat parent, uint8_t alpha) {
const Node *n = &nodes[id];
@@ -979,7 +1019,8 @@ static void draw_rec(NodeId id, Mat parent, uint8_t alpha) {
int yoff = t[7] == 1 ? -5 * k : t[7] >= 2 ? -9 * k : 0; /* middle / alphabetic baselines */
Mat tm = m;
tm.ty += yoff;
- gfx_text_k(s, tm, rgb565(t[3], t[4], t[5]), t[6], (int16_t)lw, (int16_t)lh, al, k);
+ int32_t tc = text_color(id);
+ gfx_text_k(s, tm, tc >= 0 ? (uint16_t)tc : rgb565(t[3], t[4], t[5]), t[6], (int16_t)lw, (int16_t)lh, al, k);
return;
}
default: break;
@@ -1036,13 +1077,23 @@ void node_emit(NodeId n, uint16_t ev) {
/* ---------------------------------------------------------------- texts */
static const char *text_of(NodeId n) {
- for (int i = 0; i < TX_MAX; i++) if (txs[i].n == n) return txs[i].s;
+ for (int i = 0; i < TX_MAX; i++) if (txs[i].n == n && txs[i].s) return txs[i].s;
return nodes[n].ref != NONE16 ? str(rd16(payload(nodes[n].ref))) : "";
}
void node_set_text(NodeId n, const char *s) {
for (int i = 0; i < TX_MAX; i++) if (txs[i].n == n) { txs[i].s = s; return; }
- for (int i = 0; i < TX_MAX; i++) if (!txs[i].n) { txs[i] = (Tx){n, s}; return; }
+ for (int i = 0; i < TX_MAX; i++) if (!txs[i].n) { txs[i] = (Tx){n, s, -1}; return; }
+}
+
+void node_set_text_color(NodeId n, uint16_t c) {
+ for (int i = 0; i < TX_MAX; i++) if (txs[i].n == n) { txs[i].color = c; return; }
+ for (int i = 0; i < TX_MAX; i++) if (!txs[i].n) { txs[i] = (Tx){n, NULL, c}; return; }
+}
+
+static int32_t text_color(NodeId n) {
+ for (int i = 0; i < TX_MAX; i++) if (txs[i].n == n) return txs[i].color;
+ return -1;
}
const char *node_text(NodeId n) { return text_of(n); }
diff --git a/games/championisland/src/node.h b/games/championisland/src/node.h
index 24d077e7..6c0aca0b 100644
--- a/games/championisland/src/node.h
+++ b/games/championisland/src/node.h
@@ -41,7 +41,7 @@ typedef struct {
uint8_t kind, flags, flags2, alpha;
} Node;
/* flags2: how its parent's timeline drives it, streaming */
-enum { NF2_LAZY = 1, NF2_KEEP = 2, NF2_NOLOOP = 4, NF2_MODE = 24 /* mode << 3 */ };
+enum { NF2_LAZY = 1, NF2_KEEP = 2, NF2_NOLOOP = 4, NF2_MODE = 24 /* mode << 3 */, NF2_DYN = 32 };
static inline uint8_t node_mode(const Node *n) { return (uint8_t)((n->flags2 & NF2_MODE) >> 3); }
static inline bool node_loops(const Node *n) { return !(n->flags2 & NF2_NOLOOP); }
@@ -97,6 +97,10 @@ NodeId node_new_sym_lazy(uint16_t sym);
void node_stream(NodeId n, float x0, float y0, float x1, float y1);
extern void (*node_stream_hook)(NodeId n);
extern uint16_t node_lazy_sym; /* instances of this symbol are made lazy */
+/* A long movie (NF2_DYN) has nodes only for the children on stage now; they
+ * are made and freed as it plays (new ones go through node_stream_hook). */
+NodeId node_new_sym_dynamic(uint16_t sym);
+extern uint16_t node_dynamic_sym; /* instances of this symbol are made dynamic */
/* a clip's timeline children at a frame, without nodes: symbol, instance
* name, origin and bounds in the clip's space; fn returns false to stop */
@@ -127,5 +131,6 @@ void node_emit(NodeId n, uint16_t event);
/* text nodes */
void node_set_text(NodeId n, const char *s); /* string kept by pointer */
+void node_set_text_color(NodeId n, uint16_t rgb565);
const char *node_text(NodeId n);
#endif
diff --git a/games/championisland/src/world.c b/games/championisland/src/world.c
index fec3c0a9..bafafa5e 100644
--- a/games/championisland/src/world.c
+++ b/games/championisland/src/world.c
@@ -275,11 +275,11 @@ static void streamed_in(NodeId c) {
static void stream_children(bool force) {
float vx, vy;
view_origin(&vx, &vy);
- if (!force && W->streamed && fabsf(vx - W->stream_x) < 24 && fabsf(vy - W->stream_y) < 24) return;
+ if (!force && W->streamed && fabsf(vx - W->stream_x) < 16 && fabsf(vy - W->stream_y) < 16) return;
W->stream_x = vx;
W->stream_y = vy;
W->streamed = true;
- node_stream(W->map, vx - 96, vy - 96, vx + VIEW_W + 96, vy + VIEW_H + 96);
+ node_stream(W->map, vx - 40, vy - 40, vx + VIEW_W + 40, vy + VIEW_H + 40);
}
/* ---------------------------------------------------------------- places (location markers) */
@@ -649,6 +649,35 @@ static void sys_save_place(void) {
if (W->tick % 60 == 59) save_place();
}
+/* ---------------------------------------------------------------- tests (host) */
+#ifdef HOST
+typedef struct { int want, i; char name[32]; } Nth;
+void nth_place(const char *name, float x, float y, void *ctx) {
+ Nth *q = ctx;
+ if (q->i++ == q->want) snprintf(q->name, sizeof q->name, "%s", name);
+ (void)x; (void)y;
+}
+static int subtree(NodeId n) {
+ int t = 1;
+ for (NodeId c = nodes[n].first; c; c = nodes[c].next) t += subtree(c);
+ return t;
+}
+void world_census(void) {
+ int used = 0;
+ for (int i = 1; i < NODE_MAX; i++) if (nodes[i].flags & NF_USED) used++;
+ fprintf(stderr, "census: %d nodes\n", used);
+ for (int i = 1; i < NODE_MAX; i++)
+ if ((nodes[i].flags & NF_USED) && !nodes[i].parent) fprintf(stderr, " root %d sym %d: %d\n", i, nodes[i].sym, subtree((NodeId)i));
+ if (!W || !W->map) return;
+ int k = 0;
+ for (NodeId c = nodes[W->map].first; c; c = nodes[c].next, k++) {
+ int n = subtree(c);
+ if (n >= 4) fprintf(stderr, " map child sym %d T %d: %d\n", nodes[c].sym, nodes[c].T, n);
+ }
+ fprintf(stderr, " map children %d\n", k);
+}
+#endif
+
/* ---------------------------------------------------------------- the scene */
static bool player_slot(unsigned slot, const SlotInfo *si, void *ctx) {
Clip c;
@@ -741,6 +770,21 @@ static void tick_overworld(void) {
sys_rain();
stream_children(false);
#ifdef HOST
+ /* CI_TOUR: visit every place, one per 20 frames, and report the busiest */
+ if (getenv("CI_TOUR")) {
+ static int place_i, max_nodes;
+ static char max_at[32];
+ typedef struct { int want, i; char name[32]; } Nth;
+ void nth_place(const char *name, float x, float y, void *ctx);
+ if (W->tick % 20 == 19) {
+ unsigned used = node_count();
+ if ((int)used > max_nodes) { max_nodes = (int)used; snprintf(max_at, sizeof max_at, "%s", game.location); }
+ Nth q = {place_i++, 0, ""};
+ each_place(nth_place, &q);
+ if (q.name[0]) { teleport(q.name); snprintf(game.location, sizeof game.location, "%s", q.name); sys_camera_snap(); stream_children(true); }
+ else if (place_i == q.i + 1) fprintf(stderr, "tour: busiest %s with %d nodes\n", max_at, max_nodes);
+ }
+ }
if (getenv("CI_DEBUG") && W->player && W->tick % 10 == 0) {
float px, py;
ent_pos(W->player, &px, &py);
diff --git a/games/championisland/tests/play.c b/games/championisland/tests/play.c
index 930b5834..a752d22f 100644
--- a/games/championisland/tests/play.c
+++ b/games/championisland/tests/play.c
@@ -33,6 +33,8 @@ static uint32_t key_bit(const char *s) {
return 0;
}
+void world_census(void);
+
int main(int argc, char **argv) {
const char *scene = NULL, *out = "build/play", *saves = "build/play/saves", *shots = "", *gif = NULL;
int frames = 300;
@@ -82,5 +84,6 @@ int main(int argc, char **argv) {
if (gif && f >= g0 && f <= g1 && (f - g0) % gs == 0) { snprintf(p, sizeof p, "%s/f_%05d.ppm", out, f); host_shot(p); }
}
printf("frames done: %u ticks, nodes %u, cache %u, scene %s:%s\n", game.ticks, node_count(), spr_cache_used(), game.name, game.variant);
+ if (getenv("CI_CENSUS")) world_census();
return 0;
}
diff --git a/games/championisland/tools/pack.py b/games/championisland/tools/pack.py
index 6b2f87d9..b42965ee 100644
--- a/games/championisland/tools/pack.py
+++ b/games/championisland/tools/pack.py
@@ -725,7 +725,9 @@ def child_name(c):
"""The names code can find a child by: its instance name and/or the property
it is kept in, as "name|property" when both."""
nm, pk = c['tr'].get('nm'), c.get('pk')
- if pk not in USED_PROPS or pk == nm:
+ if nm == 'hitArea': # touch areas: the calculator has keys
+ nm = None
+ if pk not in USED_PROPS or pk == nm or pk == 'hitArea':
pk = None
if nm and pk:
return nm + '|' + pk