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
Hollow Knight: props that only show, water drips
Mason Chenf40de898ec86
diff --git a/games/hollowknight/src/data.bin b/games/hollowknight/src/data.binindex b6de99aa..f4b10662 100644Binary files a/games/hollowknight/src/data.bin and b/games/hollowknight/src/data.bin differdiff --git a/games/hollowknight/src/data.h b/games/hollowknight/src/data.hindex 2ef3fa97..bf3ad534 100644--- a/games/hollowknight/src/data.h+++ b/games/hollowknight/src/data.h@@ -371,16 +371,23 @@#define CLIP_BGATE_BONE_GATE_CLOSE 312#define CLIP_BGATE_BONE_GATE_CLOSED 313#define CLIP_BGATE_BONE_GATE_OPEN 314-#define CLIP_BULLET_IDLE 315-#define CLIP_BULLET_IMPACT 316-#define CLIP_BULLET_SHOCKWAVE_SPURT 317-#define SPRITE_HERO_LIGHT 1286-#define SPRITE_DIALOGUE_BACKBOARD 1287-#define SPRITE_PROMPT_SHADOW 1288-#define SPRITE_CORPSE_NAIL 1289-#define SPRITE_FK_BARREL 1290-#define SPRITE_FK_STAFF 1291-#define SPRITE_DIGIT0 1478+#define CLIP_DRIP_IDLE 315+#define CLIP_DRIP_DRIP 316+#define CLIP_DRIP_FALL 317+#define CLIP_DRIP_IMPACT 318+#define CLIP_BULLET_IDLE 319+#define CLIP_BULLET_IMPACT 320+#define CLIP_BULLET_SHOCKWAVE_SPURT 321+#define CLIP_PROP0_WATERFALL_LOOP 322+#define CLIP_PROP1_TORCH2 323+#define CLIP_PROP1_TORCH3 324+#define SPRITE_HERO_LIGHT 1323+#define SPRITE_DIALOGUE_BACKBOARD 1324+#define SPRITE_PROMPT_SHADOW 1325+#define SPRITE_CORPSE_NAIL 1326+#define SPRITE_FK_BARREL 1327+#define SPRITE_FK_STAFF 1328+#define SPRITE_DIGIT0 1515#define STYLE_DIALOGUE 0#define STYLE_PROMPT 1#define TEXT_K 1.333333fdiff --git a/games/hollowknight/src/game.h b/games/hollowknight/src/game.hindex fa3ac952..2bb2c1db 100644--- a/games/hollowknight/src/game.h+++ b/games/hollowknight/src/game.h@@ -54,7 +54,7 @@ void save_set_respawn(const char *marker, bool facing_right); /* (Bench Controenum { ENT_CAMLOCK = 1, ENT_GATE, ENT_HAZARD_MARKER, ENT_RESPAWN, ENT_HAZARD_TRIGGER, ENT_MASK, ENT_DAMAGE, ENT_SHAPE,ENT_BOX, ENT_OBJ, ENT_PIECE, ENT_SHADE_MARKER }; /* (shape, box, piece: more of the record before) */enum { OK_BREAKABLE = 1, OK_ENEMY, OK_GREAT_DOOR, OK_GEO_ROCK, OK_CHEST, OK_BENCH, OK_BATTLE, OK_FK_FLOOR, OK_BGATE,- OK_ARENA, OK_EVENT, OK_SUMMON, OK_COND }; /* objects (ENT_OBJ's flags) */+ OK_ARENA, OK_EVENT, OK_SUMMON, OK_COND, OK_PROP, OK_DRIP }; /* objects (ENT_OBJ's flags) *//* an enemy record's s1: starts alert (or first); startles; one of an arena's Pre Battle Enemies; its death counts for its arena; gone once its arena's* fight is over; spawned by its mother's burster; there only once its arena's fight is over; its FSMs off till near* the camera (FSMActivator); then its death's effectsdiff --git a/games/hollowknight/src/obj.c b/games/hollowknight/src/obj.cindex b6d8ee1d..78b608dc 100644--- a/games/hollowknight/src/obj.c+++ b/games/hollowknight/src/obj.c@@ -8,7 +8,7 @@#endif#define DT 0.02f-#define MAX_OBJS 64+#define MAX_OBJS 96#define MAX_PIECES 24typedef struct {@@ -475,6 +475,63 @@ static void arena_tick(void) {}}+/* ---------------------------------------------------------------- props: 2D Toolkit sprites that only show; water drips */+static void prop_draw(const Obj *o, const Ent *e) {+ Inst in;+ int sprite = e->p2 >= 0 ? o->anim.sprite : (int)e->s0;+ if (sprite < 0) return;+ if (e->p1 != 0) sprite_inst_rot(sprite, e->x0, e->y0, e->x1, e->y1, e->p0, e->p1, 0, &in);+ else sprite_inst(sprite, e->x0, e->y0, e->x1, e->y1, e->p0, 0, &in);+ gfx_actor(&in, SORT_KEY(e->group, (int)e->a - 32768));+}++/* WaterDrip: idle a while, drips, falls till it hits the ground, splashes there, then again from its place */+enum { DR_IDLE, DR_DRIP, DR_FALL, DR_IMPACT };++static void drip_idle(Obj *o, const Ent *e) {+ anim_play(&o->anim, CLIP_DRIP_IDLE);+ o->state = DR_IDLE, o->t = rand_range(e->p0, e->p1);+ o->jy = 0, o->t2 = 0;+}++static void drip_enter(Obj *o, const Ent *e) {+ /* (where it will hit: the ground below its collider's bottom) */+ PhysHit hit;+ float bottom = e->y0 + e->y1;+ o->jx = phys_ray(e->x0, bottom, 0, -1, 200, CF_TERRAIN, &hit) ? bottom - hit.dist : -1e9f;+ drip_idle(o, e);+}++static void drip_tick(Obj *o, const Ent *e) {+ switch (o->state) {+ case DR_IDLE:+ if ((o->t -= DT) <= 0) anim_play_from_frame(&o->anim, CLIP_DRIP_DRIP, 0), o->state = DR_DRIP;+ break;+ case DR_DRIP:+ if (o->anim.events & ANIM_DONE) anim_play(&o->anim, CLIP_DRIP_FALL), o->state = DR_FALL, o->t2 = e->p2;+ break;+ case DR_FALL:+ /* (gravity's; jy: how far below its place) */+ o->t2 += -60.0f * DT, o->jy += o->t2 * DT;+ if (e->y0 + e->y1 + o->jy <= o->jx) {+ o->jy = o->jx - (e->y0 + e->y1) + e->p3;+ anim_play_from_frame(&o->anim, CLIP_DRIP_IMPACT, 0);+ o->state = DR_IMPACT;+ } else if (o->jy < -200)+ drip_idle(o, e);+ break;+ case DR_IMPACT:+ if (o->anim.events & ANIM_DONE) drip_idle(o, e);+ break;+ }+}++static void drip_draw(const Obj *o, const Ent *e) {+ Inst in;+ sprite_inst(o->anim.sprite, e->x0, e->y0 + o->jy, e->x1, 1, 1, 0, &in);+ gfx_actor(&in, SORT_KEY(e->group, (int)e->a - 32768));+}+/* ---------------------------------------------------------------- the room */void obj_enter(void) {nobjs = 0;@@ -504,6 +561,8 @@ void obj_enter(void) {else if (o->kind == OK_GEO_ROCK) georock_enter(o, &es[i]);else if (o->kind == OK_CHEST) chest_enter(o, &es[i]);else if (o->kind == OK_BGATE) gate_enter(o, &es[i]);+ else if (o->kind == OK_PROP && es[i].p2 >= 0) anim_play(&o->anim, (int)es[i].p2);+ else if (o->kind == OK_DRIP) drip_enter(o, &es[i]);}/* (then what sends the gates their events: SendPlaymakerEventOnEnable, the arenas) */for (int i = 0; i < n; i++)@@ -530,6 +589,7 @@ void obj_tick(void) {else if (o->kind == OK_GEO_ROCK) georock_tick(o, e);else if (o->kind == OK_CHEST) chest_tick(o, e);else if (o->kind == OK_BGATE) gate_tick(o, e);+ else if (o->kind == OK_DRIP) drip_tick(o, e);}arena_tick();pieces_tick();@@ -549,6 +609,10 @@ void obj_draw(void) {gfx_actor(&in, SORT_KEY(0, 0));} else if (o->kind == OK_CHEST)chest_draw(o, e);+ else if (o->kind == OK_PROP)+ prop_draw(o, e);+ else if (o->kind == OK_DRIP)+ drip_draw(o, e);else if (o->kind == OK_BGATE && o->state != GT_GONE) {sprite_inst(o->anim.sprite, e->x0, e->y0, e->x1, e->y1, e->p0, 0, &in);gfx_actor(&in, SORT_KEY(0, 0));diff --git a/games/hollowknight/tools/actors.py b/games/hollowknight/tools/actors.pyindex 48d6ab2e..652cdf5d 100644--- a/games/hollowknight/tools/actors.py+++ b/games/hollowknight/tools/actors.py@@ -119,6 +119,29 @@ ACTORS.update(_enemy_actors())# battle gates (BG Control: the plain ones and the bone ones)ACTORS["bgate"] = ("sharedassets9.assets", 197, ["BG Opened", "BG Close 1", "BG Close 2", "BG Open", "BG Closed","Bone Gate Opened", "Bone Gate Close", "Bone Gate Closed", "Bone Gate Open"])+# water drips (WaterDrip)+ACTORS["drip"] = ("sharedassets6.assets", 1095, ["Idle", "Drip", "Fall", "Impact"])+PROP_ACTOR = {} # (props' libraries: their actors)+++def add_props(rooms):+ """The rooms' props (ents.prop: sprites that only show) with an animator: their libraries and default clips as+ actors ("prop0", ...)."""+ import ents+ libs = {}+ for r in rooms:+ d = unity.scene(r)+ by = {o["id"]: o for o in d["objects"]}+ for o in d["objects"]:+ if o["active"]:+ pr = ents.prop(d, o, by)+ if pr and pr[0]:+ libs.setdefault(pr[0], set()).add(pr[1])+ for i, (lib, names) in enumerate(sorted(libs.items())):+ PROP_ACTOR[lib] = "prop%d" % i+ ACTORS["prop%d" % i] = (lib[0], lib[1], sorted(names))++# enemies' shots (EnemyBullet)ACTORS["bullet"] = ("sharedassets32.assets", 745, ["Idle", "Impact", "Shockwave Spurt"])diff --git a/games/hollowknight/tools/ents.py b/games/hollowknight/tools/ents.pyindex 7b0e8d01..5c2a011a 100644--- a/games/hollowknight/tools/ents.py+++ b/games/hollowknight/tools/ents.py@@ -9,7 +9,7 @@ ENT_CAMLOCK, ENT_GATE, ENT_HAZARD_MARKER, ENT_RESPAWN, ENT_HAZARD_TRIGGER, ENT_MENT_OBJ, ENT_PIECE, ENT_SHADE_MARKER = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12# objects (ENT_OBJ's flags: src/obj.c)OK_BREAKABLE, OK_ENEMY, OK_GREAT_DOOR, OK_GEO_ROCK, OK_CHEST, OK_BENCH, OK_BATTLE, OK_FK_FLOOR, OK_BGATE, OK_ARENA, \- OK_EVENT, OK_SUMMON, OK_COND = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13+ OK_EVENT, OK_SUMMON, OK_COND, OK_PROP, OK_DRIP = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15# the battle gates' events (src/game.h: BG_*)BG_EVENTS = ["BG CLOSE", "BG QUICK CLOSE", "BG OPEN", "BG QUICK OPEN", "BG DESTROY"]# battle gates (BG Control: OK_BGATE's s0): closed at first, the bone ones' clips, gone once a PlayerData bool is set@@ -632,6 +632,41 @@ def _arenas(d, by_id):return gone, counted, later+CLIP_INDEX = {} # (actors' clips: their constant -> number, as pack.py builds them)+++def prop(d, o, by_id):+ """A 2D Toolkit sprite that only shows: no FSM or script runs it or anything above it, and it is no sprite cache+ (sprite_set_*) -> (the animator's library (file, path id), its default clip's name) or (None, None) when it has no+ animator; None when it is no such thing."""+ import tk2d, unity+ mbs = {c.get("class") for c in o["c"] if c["type"] == "MonoBehaviour"}+ if "tk2dSprite" not in mbs or mbs - {"tk2dSprite", "tk2dSpriteAnimator"} or any(c.get("fsm") for c in o["c"]):+ return None+ mr = next((c.get("v") for c in o["c"] if c["type"] == "MeshRenderer"), None)+ if isinstance(mr, dict) and not mr.get("m_Enabled", 1):+ return None+ p = by_id.get(o.get("parent"))+ while p is not None:+ if any(c.get("fsm") or c.get("class") in ("HealthManager", "HealthCocoon") for c in p["c"]) or \+ p["name"].startswith("sprite_set_"):+ return None+ p = by_id.get(p.get("parent"))+ an = next((c.get("v") for c in o["c"] if c.get("class") == "tk2dSpriteAnimator" and c.get("v")), None)+ if not an:+ return (None, None)+ lib = _ref_file(d, an["library"])+ clips = tk2d.animation(*lib)["clips"]+ return lib, unity.S(clips[an["defaultClipId"]]["name"])+++def _sorting(o):+ """Its renderer's sorting layer (index) and order."""+ import scene+ mr = next((c.get("v") for c in o["c"] if c["type"] == "MeshRenderer" and isinstance(c.get("v"), dict)), {}) or {}+ return scene.layer_index(mr.get("m_SortingLayerID", 0)), mr.get("m_SortingOrder", 0)++def _gate(d, o, owners):"""A battle gate (BG Control, or a gate closed till a PlayerData bool is set) -> its record, or None."""f = _fsm(o, ("BG Control",))@@ -810,6 +845,27 @@ def room(d, rooms, strings, persist, name, sprites=None, owners=None, rec_base=0# an object off as the room loads with a PlayerData bool so: its sprites (and what is under it), its collidersc0, cn = _subcols(d, owners, o["id"]) if owners else (0, 0)recs.append(rec(ENT_OBJ, OK_COND, p=(flag, 1 if off_if else 0, 0, 0), a=c0, group=cn, group2=new_group(o["id"])))+ pr = prop(d, o, by_id)+ if pr is not None:+ # a sprite that shows (its default clip, or its sprite); its place, scale, angle, its sorting+ import actors+ lib, clip = pr+ m = np.array(o["m3"]).reshape(3, 3)+ sx = float(np.hypot(m[0, 0], m[1, 0])) * (-1.0 if np.linalg.det(m[:2, :2]) < 0 else 1.0)+ sy = float(np.hypot(m[0, 1], m[1, 1]))+ ci = CLIP_INDEX.get(actors.clip_id(actors.PROP_ACTOR[lib], clip), -1) if lib else -1+ sp = _tk2d_sprite(d, o) if ci < 0 else None+ layer, order = _sorting(o)+ recs.append(rec(ENT_OBJ, OK_PROP, (o["pos"][0], o["pos"][1], o["pos"][2], sx), (sy, _angle(o), ci, 0),+ a=order + 32768, group=layer, s0=sprites.tk2d(*sp) if sp else 0))+ dv = next((c.get("v") for c in o["c"] if c.get("class") == "WaterDrip" and c.get("v")), None)+ if dv is not None:+ # a water drip: its place, its idle times, fall speed and how far it sinks as it hits+ layer, order = _sorting(o)+ box = next((c["v"] for c in o["c"] if c["type"] == "BoxCollider2D" and c.get("v")), None)+ recs.append(rec(ENT_OBJ, OK_DRIP, (o["pos"][0], o["pos"][1], o["pos"][2], box["m_Offset"]["y"] - box["m_Size"]["y"] / 2 if box else 0),+ (dv.get("idleTimeMin", 2), dv.get("idleTimeMax", 8), dv.get("fallVelocity", -7),+ dv.get("impactTranslation", -0.5)), a=order + 32768, group=layer))ev = next((c.get("v") for c in o["c"] if c.get("class") == "SendPlaymakerEventOnEnable" and c.get("v")), None)if ev:# (an event broadcast as the room starts)diff --git a/games/hollowknight/tools/pack.py b/games/hollowknight/tools/pack.pyindex e1bff37f..1147b6fe 100644--- a/games/hollowknight/tools/pack.py+++ b/games/hollowknight/tools/pack.py@@ -322,7 +322,9 @@ def main():variants, per_room = art.build_variants(ROOMS, visible.compute)print("variants", len(variants), "%.0fs" % (time.time() - t0), flush=True)jobs = [art.Job(v) for v in variants]+ actors.add_props(ALL_ROOMS)sprites, clips = actors.build()+ ents.CLIP_INDEX.update({c["id"]: i for i, c in enumerate(clips)})# the rooms' objects, and the sprites they show (after the actors')SPRITES.base = len(sprites)named = actors.named_sprites(SPRITES)