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: Tiktik, Gruzzer, Aspid Hunter, Husk Bully and Hornhead
Mason Chenbdac2e349096
diff --git a/games/hollowknight/src/data.bin b/games/hollowknight/src/data.binindex 14c78a44..f57db079 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 c8ab7229..63a18ce1 100644--- a/games/hollowknight/src/data.h+++ b/games/hollowknight/src/data.h@@ -138,105 +138,144 @@#define CLIP_KNIGHT_COLLECT_STANDTOIDLE 78#define CLIP_KNIGHT_GETUPTOIDLE 79#define CLIP_KNIGHT_DEATH_HEAD_CRACKED 80-#define CLIP_CRAWLER_WALK 81-#define CLIP_CRAWLER_TURN 82-#define CLIP_CRAWLER_IDLE 83-#define CLIP_CRAWLER_DEATH_AIR 84-#define CLIP_CRAWLER_DEATH_LAND 85-#define CLIP_BUZZER_CHASE 86-#define CLIP_BUZZER_IDLE 87-#define CLIP_BUZZER_STARTLE 88-#define CLIP_BUZZER_DEATH_AIR 89-#define CLIP_BUZZER_DEATH_LAND 90-#define CLIP_BUZZER_FLY 91-#define CLIP_BUZZER_TURNTOFLY 92-#define CLIP_BUZZER_TURNTOIDLE 93-#define CLIP_HUSK_ATTACK_ANTICIPATE 94-#define CLIP_HUSK_IDLE 95-#define CLIP_HUSK_WALK 96-#define CLIP_HUSK_TURN 97-#define CLIP_HUSK_FALL 98-#define CLIP_HUSK_ATTACK_LUNGE 99-#define CLIP_HUSK_ATTACK_COOLDOWN 100-#define CLIP_HUSK_DEATH_AIR 101-#define CLIP_HUSK_DEATH_LAND 102-#define CLIP_GEOROCK_IDLE_1 103-#define CLIP_GEOROCK_GLEAM_1 104-#define CLIP_GEOROCK_BROKEN_1 105-#define CLIP_GEOROCK_IDLE_2 106-#define CLIP_GEOROCK_GLEAM_2 107-#define CLIP_GEOROCK_BROKEN_2 108-#define CLIP_CHEST_IDLE 109-#define CLIP_CHEST_OPEN 110-#define CLIP_CHEST_BURST 111-#define CLIP_CHEST_OPENED 112-#define CLIP_HUD_HEALTH_EMPTY 113-#define CLIP_HUD_HEALTH_IDLE 114-#define CLIP_HUD_HEALTH_BREAK 115-#define CLIP_HUD_HEALTH_REFILL 116-#define CLIP_HUD_HEALTH_APPEAR 117-#define CLIP_HUD_BLUE_APPEAR 118-#define CLIP_HUD_BLUE_IDLE 119-#define CLIP_HUD_BLUE_BREAK 120-#define CLIP_HUD_HUD_FRAME 121-#define CLIP_HUD_HUD_FRAME_IDLE 122-#define CLIP_HUD_HUD_FRAME_CRACKAPPEAR 123-#define CLIP_HUD_HUD_FRAME_CRACKED 124-#define CLIP_HUD_COIN_APPEAR 125-#define CLIP_HUD_COIN_IDLE 126-#define CLIP_HUD_COIN_GET 127-#define CLIP_HUD_SOUL_BURST 128-#define CLIP_LIQUID_FILL 129-#define CLIP_LIQUID_IDLE 130-#define CLIP_LIQUID_SHRINK 131-#define CLIP_LIQUID_DRAIN 132-#define CLIP_GEO_SMALL_IDLE 133-#define CLIP_GEO_SMALL_AIR 134-#define CLIP_GEO_MED_IDLE 135-#define CLIP_GEO_MED_AIR 136-#define CLIP_GEO_LARGE_IDLE 137-#define CLIP_GEO_LARGE_AIR 138-#define CLIP_DIALOGUE_ARROW_UP 139-#define CLIP_DIALOGUE_ARROW_DOWN 140-#define CLIP_DIALOGUE_STOP_UP 141-#define CLIP_DIALOGUE_STOP_DOWN 142-#define CLIP_DIALOGUE_FLEUR_TOP_UP 143-#define CLIP_DIALOGUE_FLEUR_TOP_DOWN 144-#define CLIP_DIALOGUE_FLEUR_BOT_UP 145-#define CLIP_DIALOGUE_FLEUR_BOT_DOWN 146-#define CLIP_PROMPT_UP 147-#define CLIP_PROMPT_DOWN 148-#define CLIP_PROMPT_BLANK 149-#define CLIP_SHADE_IDLE 150-#define CLIP_SHADE_STARTLE 151-#define CLIP_SHADE_FLY 152-#define CLIP_SHADE_TURNTOFLY 153-#define CLIP_SHADE_TURNTOIDLE 154-#define CLIP_SHADE_SLASH_ANTIC 155-#define CLIP_SHADE_SLASH 156-#define CLIP_SHADE_SLASH_CD 157-#define CLIP_SHADE_SLASH_EFFECT 158-#define CLIP_SHADE_CAST_ANTIC 159-#define CLIP_SHADE_CAST_CHARGE 160-#define CLIP_SHADE_CAST 161-#define CLIP_SHADE_RETREAT_START 162-#define CLIP_SHADE_RETREAT_END 163-#define CLIP_SHADE_DEATH_START 164-#define CLIP_SHADE_DEATH 165-#define CLIP_SHADE_DEPART 166-#define CLIP_SHADE_APPEAR 167-#define CLIP_SHADE_FIREBALL 168-#define CLIP_SHADE_FIREBALL_END 169-#define CLIP_SHADE_CAST_RING 170-#define SPRITE_HERO_LIGHT 732-#define SPRITE_DIALOGUE_BACKBOARD 733-#define SPRITE_PROMPT_SHADOW 734-#define SPRITE_CORPSE_NAIL 735-#define SPRITE_DIGIT0 916+#define CLIP_GEOROCK_IDLE_1 81+#define CLIP_GEOROCK_GLEAM_1 82+#define CLIP_GEOROCK_BROKEN_1 83+#define CLIP_GEOROCK_IDLE_2 84+#define CLIP_GEOROCK_GLEAM_2 85+#define CLIP_GEOROCK_BROKEN_2 86+#define CLIP_CHEST_IDLE 87+#define CLIP_CHEST_OPEN 88+#define CLIP_CHEST_BURST 89+#define CLIP_CHEST_OPENED 90+#define CLIP_HUD_HEALTH_EMPTY 91+#define CLIP_HUD_HEALTH_IDLE 92+#define CLIP_HUD_HEALTH_BREAK 93+#define CLIP_HUD_HEALTH_REFILL 94+#define CLIP_HUD_HEALTH_APPEAR 95+#define CLIP_HUD_BLUE_APPEAR 96+#define CLIP_HUD_BLUE_IDLE 97+#define CLIP_HUD_BLUE_BREAK 98+#define CLIP_HUD_HUD_FRAME 99+#define CLIP_HUD_HUD_FRAME_IDLE 100+#define CLIP_HUD_HUD_FRAME_CRACKAPPEAR 101+#define CLIP_HUD_HUD_FRAME_CRACKED 102+#define CLIP_HUD_COIN_APPEAR 103+#define CLIP_HUD_COIN_IDLE 104+#define CLIP_HUD_COIN_GET 105+#define CLIP_HUD_SOUL_BURST 106+#define CLIP_LIQUID_FILL 107+#define CLIP_LIQUID_IDLE 108+#define CLIP_LIQUID_SHRINK 109+#define CLIP_LIQUID_DRAIN 110+#define CLIP_GEO_SMALL_IDLE 111+#define CLIP_GEO_SMALL_AIR 112+#define CLIP_GEO_MED_IDLE 113+#define CLIP_GEO_MED_AIR 114+#define CLIP_GEO_LARGE_IDLE 115+#define CLIP_GEO_LARGE_AIR 116+#define CLIP_DIALOGUE_ARROW_UP 117+#define CLIP_DIALOGUE_ARROW_DOWN 118+#define CLIP_DIALOGUE_STOP_UP 119+#define CLIP_DIALOGUE_STOP_DOWN 120+#define CLIP_DIALOGUE_FLEUR_TOP_UP 121+#define CLIP_DIALOGUE_FLEUR_TOP_DOWN 122+#define CLIP_DIALOGUE_FLEUR_BOT_UP 123+#define CLIP_DIALOGUE_FLEUR_BOT_DOWN 124+#define CLIP_PROMPT_UP 125+#define CLIP_PROMPT_DOWN 126+#define CLIP_PROMPT_BLANK 127+#define CLIP_SHADE_IDLE 128+#define CLIP_SHADE_STARTLE 129+#define CLIP_SHADE_FLY 130+#define CLIP_SHADE_TURNTOFLY 131+#define CLIP_SHADE_TURNTOIDLE 132+#define CLIP_SHADE_SLASH_ANTIC 133+#define CLIP_SHADE_SLASH 134+#define CLIP_SHADE_SLASH_CD 135+#define CLIP_SHADE_SLASH_EFFECT 136+#define CLIP_SHADE_CAST_ANTIC 137+#define CLIP_SHADE_CAST_CHARGE 138+#define CLIP_SHADE_CAST 139+#define CLIP_SHADE_RETREAT_START 140+#define CLIP_SHADE_RETREAT_END 141+#define CLIP_SHADE_DEATH_START 142+#define CLIP_SHADE_DEATH 143+#define CLIP_SHADE_DEPART 144+#define CLIP_SHADE_APPEAR 145+#define CLIP_SHADE_FIREBALL 146+#define CLIP_SHADE_FIREBALL_END 147+#define CLIP_SHADE_CAST_RING 148+#define CLIP_CRAWLER_WALK 149+#define CLIP_CRAWLER_TURN 150+#define CLIP_CRAWLER_IDLE 151+#define CLIP_CRAWLER_DEATH_AIR 152+#define CLIP_CRAWLER_DEATH_LAND 153+#define CLIP_BUZZER_CHASE 154+#define CLIP_BUZZER_IDLE 155+#define CLIP_BUZZER_STARTLE 156+#define CLIP_BUZZER_DEATH_AIR 157+#define CLIP_BUZZER_DEATH_LAND 158+#define CLIP_BUZZER_FLY 159+#define CLIP_BUZZER_TURNTOFLY 160+#define CLIP_BUZZER_TURNTOIDLE 161+#define CLIP_TIKTIK_DEATH_AIR 162+#define CLIP_TIKTIK_DEATH_LAND 163+#define CLIP_TIKTIK_STUN 164+#define CLIP_TIKTIK_WALK 165+#define CLIP_GRUZZER_DEATH_AIR 166+#define CLIP_GRUZZER_DEATH_LAND 167+#define CLIP_GRUZZER_FLY 168+#define CLIP_ASPID_DEATH_AIR 169+#define CLIP_ASPID_FIRE_LONG 170+#define CLIP_ASPID_FLY 171+#define CLIP_ASPID_TURNTOFLY 172+#define CLIP_HUSK_ATTACK_ANTICIPATE 173+#define CLIP_HUSK_ATTACK_COOLDOWN 174+#define CLIP_HUSK_ATTACK_LUNGE 175+#define CLIP_HUSK_DEATH_AIR 176+#define CLIP_HUSK_DEATH_LAND 177+#define CLIP_HUSK_IDLE 178+#define CLIP_HUSK_TURN 179+#define CLIP_HUSK_WALK 180+#define CLIP_BARGER_ATTACK_ANTICIPATE 181+#define CLIP_BARGER_ATTACK_COOLDOWN 182+#define CLIP_BARGER_ATTACK_LUNGE 183+#define CLIP_BARGER_DEATH_AIR 184+#define CLIP_BARGER_DEATH_LAND 185+#define CLIP_BARGER_IDLE 186+#define CLIP_BARGER_TURN 187+#define CLIP_BARGER_WALK 188+#define CLIP_HORNHEAD_ATTACK_ANTICIPATE 189+#define CLIP_HORNHEAD_ATTACK_COOLDOWN 190+#define CLIP_HORNHEAD_ATTACK_LUNGE 191+#define CLIP_HORNHEAD_DEATH_AIR 192+#define CLIP_HORNHEAD_DEATH_LAND 193+#define CLIP_HORNHEAD_IDLE 194+#define CLIP_HORNHEAD_TURN 195+#define CLIP_HORNHEAD_WALK 196+#define CLIP_BULLET_IDLE 197+#define CLIP_BULLET_IMPACT 198+#define SPRITE_HERO_LIGHT 866+#define SPRITE_DIALOGUE_BACKBOARD 867+#define SPRITE_PROMPT_SHADOW 868+#define SPRITE_CORPSE_NAIL 869+#define SPRITE_DIGIT0 1050#define STYLE_DIALOGUE 0#define STYLE_PROMPT 1#define TEXT_K 1.333333f#define FONT_PHASES 4+#define EK_CRAWLER 1+#define EK_BUZZER 2+#define EK_SHADE 3+#define EK_TIKTIK 4+#define EK_GRUZZER 5+#define EK_ASPID 6+#define EK_HUSK 7+#define EK_BARGER 8+#define EK_HORNHEAD 9+#define NUM_KINDS 10+#define KIND_TABLE {{0}, {EF_CRAWLER, {-1, 150, 149, -1, -1, -1, -1, -1, -1, -1, -1, 152, 153}}, {EF_BUZZER, {155, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 157, 158}}, {EF_SHADE, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}}, {EF_CLIMBER, {-1, -1, 165, 164, -1, -1, -1, -1, -1, -1, -1, 162, 163}}, {EF_BOUNCER, {-1, -1, -1, 168, -1, -1, -1, -1, -1, -1, -1, 166, 167}}, {EF_SPITTER, {-1, -1, -1, 171, 172, 170, -1, -1, -1, -1, -1, 169, -1}}, {EF_HUSK, {178, 179, 180, 173, 175, 174, -1, -1, -1, -1, -1, 176, 177}}, {EF_HUSK, {186, 187, 188, 181, 183, 182, -1, -1, -1, -1, -1, 184, 185}}, {EF_HUSK, {194, 195, 196, 189, 191, 190, -1, -1, -1, -1, -1, 192, 193}}}#define TXT_PROMPT_LISTEN 0#define TXT_PROMPT_REST 1#define TXT_PROMPT_INSPECT 2diff --git a/games/hollowknight/src/enemy.c b/games/hollowknight/src/enemy.cindex bfdddb68..25e03740 100644--- a/games/hollowknight/src/enemy.c+++ b/games/hollowknight/src/enemy.c@@ -9,27 +9,26 @@#define TERRAIN_FRICTION 0.2f /* (the Terrain material; with another, their geometric mean) *//* ---------------------------------------------------------------- what each kind is */-enum { EK_CRAWLER = 1, EK_BUZZER, EK_SHADE, EK_HUSK };+/* (data.h: EK_* each kind, KIND_TABLE: the FSM each runs and the clips its roles play) */+enum { EF_CRAWLER = 1, EF_BUZZER, EF_SHADE, EF_HUSK, EF_CLIMBER, EF_BOUNCER, EF_SPITTER };+enum { R_IDLE, R_TURN, R_WALK, R_A1, R_A2, R_A3, R_A4, R_A5, R_A6, R_A7, R_A8, R_DEATH_AIR, R_DEATH_LAND, NUM_ROLES };+typedef struct {+ uint8_t fsm;+ int16_t clip[NUM_ROLES];+} Kind;+static const Kind kinds[NUM_KINDS] = KIND_TABLE;+#define CLIP(e, role) (kinds[(e)->kind].clip[role])+#define FSM(e) (kinds[(e)->kind].fsm)#define NO_ENT 0xFFFF /* (an enemy spawned, not one of the room's) *//* the records after an enemy's (tools/ents.py: ET_*) */-enum { ET_COLLIDER, ET_ALERT, ET_RANGE, ET_WALKER, ET_RECOIL, ET_CORPSE };-enum { CF_BREAKER = 1, CF_FACES_RIGHT = 2, CF_LOW_ARC = 4 }; /* a corpse's (ET_CORPSE) */+enum { ET_COLLIDER, ET_ALERT, ET_RANGE, ET_WALKER, ET_RECOIL, ET_CORPSE, ET_VARS };+enum { CF_BREAKER = 1, CF_FACES_RIGHT = 2, CF_LOW_ARC = 4, CF_NO_COLLIDER = 32 }; /* a corpse's (ET_CORPSE) */enum { WF_PAUSES = 1, WF_IGNORE_HOLES = 2, WF_NO_TURN_TO_HERO = 4, WF_START_INACTIVE = 8, WF_AMBUSH = 16, WF_WAIT_HERO_X = 32,WF_PREVENT_TURN = 64, WF_NO_SCALE = 128, WF_RIGHT_NEG = 256 }; /* a Walker's (ET_WALKER) */-typedef struct {- int clip_death_air, clip_death_land; /* its corpse's (Corpse: Death Air, Death Land) */- int clip_idle, clip_turn, clip_walk; /* (Walker's) */-} Kind;-static const Kind kinds[] = {- [EK_CRAWLER] = {CLIP_CRAWLER_DEATH_AIR, CLIP_CRAWLER_DEATH_LAND, -1, -1, -1},- [EK_BUZZER] = {CLIP_BUZZER_DEATH_AIR, CLIP_BUZZER_DEATH_LAND, -1, -1, -1},- [EK_SHADE] = {-1, -1, -1, -1, -1},- [EK_HUSK] = {CLIP_HUSK_DEATH_AIR, CLIP_HUSK_DEATH_LAND, CLIP_HUSK_IDLE, CLIP_HUSK_TURN, CLIP_HUSK_WALK},-};/* ---------------------------------------------------------------- an enemy */enum { EM_OFF, EM_ALIVE, EM_CORPSE };-enum { RC_READY, RC_RECOILING };+enum { RC_READY, RC_RECOILING, RC_FROZEN };enum { CS_AIR, CS_DEATH_ANIM, CS_LANDED };typedef struct {uint8_t mode, kind, st, flags;@@ -57,6 +56,7 @@ typedef struct {bool flashing;/* the FSM's state */float t0, t1, wait, start_x, start_y, ax, ay, pause0, pause1, jx, jy;+ float ang, qx, qy, tx, ty; /* (its rotation, degrees; a tween's from and to) */bool b0, b1;/* alert range (local circle, or box: ar_hy >= 0) and sight */float ar_x, ar_y, ar_r, ar_hy;@@ -189,8 +189,15 @@ static uint8_t flash_tint(const Enemy *e, int slot) {}/* ---------------------------------------------------------------- Recoil */+static void climber_stun(Enemy *e);static void recoil_by_direction(Enemy *e, int dir, float magnitude) {if (e->rc_state != RC_READY) return;+ if (e->rc_flags & 2) {+ /* freezeInPlace: a climber is stunned (its own handling); others stop still a while */+ if (FSM(e) == EF_CLIMBER) climber_stun(e);+ else e->rc_state = RC_FROZEN, e->rc_time = e->rc_dur, e->body.vx = e->body.vy = 0;+ return;+ }if (dir == 1 && (e->rc_flags & 4)) return; /* (preventRecoilUp) */e->rc_state = RC_RECOILING;e->rc_speed = e->rc_base * magnitude;@@ -202,6 +209,11 @@ static void recoil_by_direction(Enemy *e, int dir, float magnitude) {/* Sweep.Check: three rays from the collider's side, the distance clipped by the terrain */static void recoil_fixed(Enemy *e) {+ if (e->rc_state == RC_FROZEN) {+ e->body.vx = e->body.vy = 0;+ if ((e->rc_time -= DT) <= 0) e->rc_state = RC_READY;+ return;+ }if (e->rc_state != RC_RECOILING) return;if (e->rc_sweep) {float dx = (float)(e->rc_dir == 0) - (float)(e->rc_dir == 2), dy = (float)(e->rc_dir == 1) - (float)(e->rc_dir == 3);@@ -222,16 +234,15 @@ static void recoil_fixed(Enemy *e) {/* ---------------------------------------------------------------- death */static void corpse_start(Enemy *e, float direction, bool has_direction) {- const Kind *k = &kinds[e->kind];const Ent *c = enemy_rec(e, ET_CORPSE);- if (!c || k->clip_death_air < 0) {+ if (!c || kinds[e->kind].clip[R_DEATH_AIR] < 0) {e->mode = EM_OFF; /* (no corpse) */return;}e->mode = EM_CORPSE, e->st = CS_AIR;e->body.y += c->p3;e->body.ox = c->x0, e->body.oy = c->y0, e->body.hx = c->x1, e->body.hy = c->y1;- e->body.gravity_scale = c->p0, e->body.friction = 0.2f, e->body.mask = CF_SOLID;+ e->body.gravity_scale = c->p0, e->body.friction = 0.2f, e->body.mask = (c->a & CF_NO_COLLIDER) ? 0 : CF_SOLID;e->body.ncontacts = 0;float speed = c->p2, angle = 90, sign = e->sx < 0 ? -1.0f : 1.0f;switch (cardinal(direction)) {@@ -243,14 +254,14 @@ static void corpse_start(Enemy *e, float direction, bool has_direction) {if (!has_direction) speed = 0;float a = angle * (float)M_PI / 180;e->body.vx = cosf(a) * speed, e->body.vy = sinf(a) * speed;- anim_play(&e->anim, k->clip_death_air);+ anim_play(&e->anim, kinds[e->kind].clip[R_DEATH_AIR]);e->flashing = true, e->flash_t = 0; /* (EmitInfectedEffects: the corpse flashes) */}/* HealthManager.Die, EnemyDeathEffects */static void shade_killed(Enemy *e);static void enemy_die(Enemy *e, float direction, bool has_direction) {- if (e->kind == EK_SHADE) {+ if (FSM(e) == EF_SHADE) {shade_killed(e);return;}@@ -270,10 +281,10 @@ static void enemy_hit(Enemy *e, float direction, int damage) {if (e->mode != EM_ALIVE || e->evasion > 0 || damage <= 0) return;int dir = cardinal(direction);recoil_by_direction(e, dir, 1);- if (e->kind != EK_SHADE) hero_soul_gain(); /* (enemyType 3, a shade: no soul) */+ if (FSM(e) != EF_SHADE) hero_soul_gain(); /* (enemyType 3, a shade: no soul) */e->flashing = true, e->flash_t = 0;e->hp = (int16_t)(e->hp - damage < -50 ? -50 : e->hp - damage);- if ((e->kind == EK_BUZZER || e->kind == EK_SHADE || e->kind == EK_HUSK) && e->st == 0) e->b1 = true; /* (TOOK DAMAGE, in Idle / Ready) */+ if ((FSM(e) == EF_BUZZER || FSM(e) == EF_SHADE || FSM(e) == EF_HUSK) && e->st == 0) e->b1 = true; /* (TOOK DAMAGE, in Idle / Ready) */if (e->hp > 0)e->evasion = 0.2f;else@@ -490,7 +501,7 @@ static void walker_scale(Enemy *e, int facing) {static void walker_begin_walking(Enemy *e, int facing) {const Ent *w = walker_rec(e);e->wk_state = WK_WALKING;- anim_play(&e->anim, kinds[e->kind].clip_walk);+ anim_play(&e->anim, CLIP(e, R_WALK));walker_scale(e, facing);e->wk_walk = rand_range(w->p0, w->p1);e->body.vx = facing > 0 ? w->y0 : w->x0;@@ -507,7 +518,7 @@ static void walker_begin_turning(Enemy *e, int facing) {}e->wk_turn_cd = w->p2;e->body.vx = 0;- anim_play_from_frame(&e->anim, kinds[e->kind].clip_turn, 0);+ anim_play_from_frame(&e->anim, CLIP(e, R_TURN), 0);}static void walker_walk_or_turn(Enemy *e, int facing) {@@ -526,7 +537,7 @@ static void walker_stop(Enemy *e, int reason) {const Ent *w = walker_rec(e);e->wk_state = WK_STOPPED, e->wk_stop = (uint8_t)reason;if (reason == STOP_BORED) {- anim_play(&e->anim, kinds[e->kind].clip_idle);+ anim_play(&e->anim, CLIP(e, R_IDLE));e->body.vx = 0;if (w->a & WF_PAUSES) e->wk_pause = rand_range(w->x1, w->y1);else walker_end_stopping(e);@@ -615,6 +626,402 @@ static void walker_update(Enemy *e) {}}+/* ---------------------------------------------------------------- Tiktiks: Climber, round the terrain's edges */+enum { CL_WALK, CL_TURN, CL_STUN };+enum { DIR_RIGHT, DIR_DOWN, DIR_LEFT, DIR_UP };++/* its collider at its rotation (quarter turns) */+static void climber_box(Enemy *e) {+ const Ent *c = enemy_rec(e, ET_COLLIDER);+ if (!c) return;+ float ox = c->x0 * (e->sx < 0 ? -1 : 1), oy = c->y0;+ int q = ((int)lrintf(e->ang / 90) % 4 + 4) % 4;+ float rx = q == 0 ? ox : q == 1 ? -oy : q == 2 ? -ox : oy, ry = q == 0 ? oy : q == 1 ? ox : q == 2 ? -oy : -ox;+ e->body.ox = rx, e->body.oy = ry;+ e->body.hx = q & 1 ? c->y1 : c->x1, e->body.hy = q & 1 ? c->x1 : c->y1;+}++/* FireRayLocal: from its collider's center along a direction of its own */+static bool climber_ray(const Enemy *e, float lx, float ly, float len) {+ const Ent *c = enemy_rec(e, ET_COLLIDER);+ float a = e->ang * (float)M_PI / 180, ca = cosf(a), sa = sinf(a);+ float ox = c ? c->x0 * (e->sx < 0 ? -1 : 1) : 0, oy = c ? c->y0 : 0;+ float x = e->body.x + ox * ca - oy * sa, y = e->body.y + ox * sa + oy * ca;+ return phys_ray(x, y, lx * ca - ly * sa, lx * sa + ly * ca, len, CF_TERRAIN, NULL);+}++static void climber_velocity(Enemy *e) {+ const Ent *v = enemy_rec(e, ET_VARS);+ float sp = v ? v->p0 : 2;+ int d = e->wk_facing;+ e->body.vx = d == DIR_RIGHT ? sp : d == DIR_LEFT ? -sp : 0;+ e->body.vy = d == DIR_UP ? sp : d == DIR_DOWN ? -sp : 0;+}++static void climber_walk(Enemy *e) {+ e->st = CL_WALK;+ anim_play(&e->anim, CLIP(e, R_WALK));+ climber_velocity(e);+}++static void climber_start(Enemy *e) {+ const Ent *v = enemy_rec(e, ET_VARS);+ e->ang = v ? 90.0f * v->s1 : 0;+ climber_box(e);+ /* StickToGround: onto the ground below, within 2 */+ const Ent *c = enemy_rec(e, ET_COLLIDER);+ float a = e->ang * (float)M_PI / 180, ca = cosf(a), sa = sinf(a);+ float ox = c ? c->x0 * (e->sx < 0 ? -1 : 1) : 0, oy = c ? c->y0 : 0;+ PhysHit hit;+ if (phys_ray(e->body.x + ox * ca - oy * sa, e->body.y + ox * sa + oy * ca, sa, -ca, 2, CF_TERRAIN, &hit))+ e->body.x = hit.x, e->body.y = hit.y;+ float k = e->sx < 0 ? -1.0f : 1.0f;+ if (v && !(v->a & 1)) k = -k;+ e->b0 = k > 0; /* (clockwise) */+ float r = fmodf(e->ang, 360);+ if (r < 0) r += 360;+ if (r >= 45 && r <= 135) e->wk_facing = e->b0 ? DIR_UP : DIR_DOWN;+ else if (r >= 135 && r <= 225) e->wk_facing = e->b0 ? DIR_LEFT : DIR_RIGHT;+ else if (r >= 225 && r <= 315) e->wk_facing = e->b0 ? DIR_DOWN : DIR_UP;+ else e->wk_facing = e->b0 ? DIR_RIGHT : DIR_LEFT;+ e->start_x = e->body.x, e->start_y = e->body.y;+ e->ax = e->body.x, e->ay = e->body.y; /* (previousTurnPos: none yet, its place) */+ e->ax = 1e9f;+ climber_walk(e);+}++static void climber_turn(Enemy *e, bool cw, bool tween) {+ const Ent *c = enemy_rec(e, ET_COLLIDER), *v = enemy_rec(e, ET_VARS);+ float w = c ? c->x1 : 0.5f, h = c ? c->y1 : 0.5f, pad = v ? v->p2 : 0.1f; /* (half sizes) */+ e->st = CL_TURN, e->t0 = 0;+ e->body.vx = e->body.vy = 0;+ e->pause0 = e->ang, e->pause1 = e->ang + (cw ? -90.0f : 90.0f);+ e->qx = e->body.x, e->qy = e->body.y, e->b1 = tween;+ float tx = 0, ty = 0; /* GetTweenPos */+ switch (e->wk_facing) {+ case DIR_RIGHT: tx = w + pad, ty = e->b0 ? h : -h; break;+ case DIR_UP: tx = e->b0 ? -w : w, ty = h + pad; break;+ case DIR_DOWN: tx = e->b0 ? w : -w, ty = -h - pad; break;+ case DIR_LEFT: tx = -w - pad, ty = e->b0 ? -h : h; break;+ }+ e->tx = e->body.x + tx, e->ty = e->body.y + ty;+ e->wait = cw ? 1 : -1;+}++static void climber_stun(Enemy *e) {+ if (e->st == CL_TURN) return;+ e->st = CL_STUN;+ e->body.vx = e->body.vy = 0;+ anim_play_from_frame(&e->anim, CLIP(e, R_A1), 0);+}++static void climber_update(Enemy *e) {+ const Ent *v = enemy_rec(e, ET_VARS);+ switch (e->st) {+ case CL_WALK: {+ /* (constrain: held to its line) */+ bool moved = false;+ if (fabsf(e->body.x - e->start_x) > 0.1f) e->body.x = e->start_x, moved = true;+ if (fabsf(e->body.y - e->start_y) > 0.1f) e->body.y = e->start_y, moved = true;+ if (!moved) e->start_x = e->body.x, e->start_y = e->body.y;+ float dx = e->body.x - e->ax, dy = e->body.y - e->ay;+ if (e->ax > 1e8f || dx * dx + dy * dy >= (v ? v->p3 * v->p3 : 0.0625f)) {+ const Ent *c = enemy_rec(e, ET_COLLIDER);+ float w = c ? c->x1 : 0.5f, pad = v ? v->p2 : 0.1f;+ if (!climber_ray(e, 0, -1, 1)) climber_turn(e, e->b0, false);+ else if (climber_ray(e, e->b0 ? 1 : -1, 0, w + pad)) climber_turn(e, !e->b0, true);+ }+ break;+ }+ case CL_TURN: {+ float spin = v ? v->p1 : 0.25f;+ e->t0 += DT;+ float t = e->t0 >= spin ? 1 : e->t0 / spin;+ e->ang = e->pause0 + (e->pause1 - e->pause0) * t;+ if (e->b1) e->body.x = e->qx + (e->tx - e->qx) * t, e->body.y = e->qy + (e->ty - e->qy) * t;+ if (e->t0 >= spin) {+ e->ang = e->pause1;+ e->wk_facing = (int8_t)((e->wk_facing + (e->wait > 0 ? 1 : -1) + 4) % 4);+ climber_box(e);+ e->start_x = e->ax = e->body.x, e->start_y = e->ay = e->body.y;+ climber_walk(e);+ }+ break;+ }+ case CL_STUN:+ if (e->anim.events & ANIM_DONE) climber_walk(e);+ break;+ }+}++/* ---------------------------------------------------------------- Gruzzers: the Bouncer Control FSM */+enum { BO_WAIT, BO_FLY, BO_STOPPED };++static void bouncer_aim(Enemy *e, float lo, float hi) {+ e->wait = rand_range(lo, hi); /* (Angle) */+ float a = fmodf(e->wait, 360);+ if (a < 0) a += 360;+ e->b0 = a < 90 || a >= 270; /* (Left or Right?: Facing Right) */+ e->st = BO_FLY;+}++static void bouncer_start(Enemy *e) {+ const Ent *v = enemy_rec(e, ET_VARS);+ e->st = v && (v->a & 1) ? BO_STOPPED : BO_WAIT;+ anim_play(&e->anim, CLIP(e, R_A1));+}++/* CheckCollisionSide: short rays from its sides, top first: the side it bumped */+static int bouncer_side(const Enemy *e) {+ float x0, y0, x1, y1;+ enemy_box(e, &x0, &y0, &x1, &y1);+ float cx = (x0 + x1) / 2, cy = (y0 + y1) / 2;+ const float d = 0.08f;+ if (phys_ray(x0, y1, 0, 1, d, CF_TERRAIN, NULL) || phys_ray(cx, y1, 0, 1, d, CF_TERRAIN, NULL) || phys_ray(x1, y1, 0, 1, d, CF_TERRAIN, NULL)) return 1;+ if (phys_ray(x1, y1, 1, 0, d, CF_TERRAIN, NULL) || phys_ray(x1, cy, 1, 0, d, CF_TERRAIN, NULL) || phys_ray(x1, y0, 1, 0, d, CF_TERRAIN, NULL)) return 0;+ if (phys_ray(x1, y0, 0, -1, d, CF_TERRAIN, NULL) || phys_ray(cx, y0, 0, -1, d, CF_TERRAIN, NULL) || phys_ray(x0, y0, 0, -1, d, CF_TERRAIN, NULL)) return 3;+ if (phys_ray(x0, y0, -1, 0, d, CF_TERRAIN, NULL) || phys_ray(x0, cy, -1, 0, d, CF_TERRAIN, NULL) || phys_ray(x0, y1, -1, 0, d, CF_TERRAIN, NULL)) return 2;+ return -1;+}++static void bouncer_fixed(Enemy *e) {+ if (e->st != BO_FLY) return;+ const Ent *v = enemy_rec(e, ET_VARS);+ float sp = v ? v->p0 : 5.2f, a = e->wait * (float)M_PI / 180;+ e->body.vx = cosf(a) * sp, e->body.vy = sinf(a) * sp; /* (SetVelocityAsAngle) */+}++static void bouncer_update(Enemy *e) {+ switch (e->st) {+ case BO_WAIT: {+ float dx = e->body.x - g_cam_x, dy = e->body.y - g_cam_y;+ if (dx * dx + dy * dy < 44 * 44) {+ const Ent *v = enemy_rec(e, ET_VARS);+ if (v && (v->a & 2)) bouncer_aim(e, 90, 90); /* (Start Up) */+ else bouncer_aim(e, 0, 360);+ }+ break;+ }+ case BO_FLY: {+ /* FaceDirection (sprite facing left), no pause */+ float want = e->body.vx > 0 ? -fabsf(e->sx) : fabsf(e->sx);+ if (e->body.vx != 0 && e->sx != want) set_scale_x(e, want);+ if (!e->body.ncontacts) break;+ float a = fmodf(e->wait, 360);+ if (a < 0) a += 360;+ switch (bouncer_side(e)) {+ case 1: if (e->b0) bouncer_aim(e, 320, 350); else bouncer_aim(e, 190, 220); break; /* (Hit Up) */+ case 3: if (e->b0) bouncer_aim(e, 10, 40); else bouncer_aim(e, 140, 170); break; /* (Hit Down) */+ case 0: if (a < 180) bouncer_aim(e, 140, 170); else bouncer_aim(e, 190, 220); break; /* (Hit Right) */+ case 2: if (a < 180) bouncer_aim(e, 10, 40); else bouncer_aim(e, 320, 350); break; /* (Hit Left) */+ }+ break;+ }+ }+}++/* DistanceFly: keeps a distance from the hero (targeting its height, or its distance in y too) */+static void distance_fly(Enemy *e, float dist, float vmax, float accel, bool height) {+ float vx = e->body.vx, vy = e->body.vy;+ float dx = e->body.x - hero_x(), dy = e->body.y - hero_y(), d = sqrtf(dx * dx + dy * dy);+ bool left = e->body.x < hero_x(), below = e->body.y < hero_y();+ vx += (d > dist) == left ? accel : -accel;+ if (!height) vy += (d > dist) == below ? accel : -accel;+ else {+ if (e->body.y < hero_y()) vy += accel;+ if (e->body.y > hero_y()) vy -= accel;+ }+ e->body.vx = vx > vmax ? vmax : vx < -vmax ? -vmax : vx;+ e->body.vy = vy > vmax ? vmax : vy < -vmax ? -vmax : vy;+}++/* ---------------------------------------------------------------- enemies' shots (EnemyBullet) */+#define MAX_BULLETS 8+typedef struct {+ bool on, active;+ float x, y, vx, vy, scale, ang;+ Anim anim;+} Bullet;+static Bullet bullets[MAX_BULLETS];+#define BULLET_HX (0.6406f / 2)+#define BULLET_HY (0.5625f / 2)++/* FireAtTarget: from (x, y) at the hero, at a speed */+static void bullet_fire(float x, float y, float speed) {+ Bullet *b = NULL;+ for (int i = 0; i < MAX_BULLETS && !b; i++)+ if (!bullets[i].on) b = &bullets[i];+ if (!b) return;+ memset(b, 0, sizeof *b);+ b->on = b->active = true;+ b->x = x, b->y = y;+ b->scale = rand_range(1.15f, 1.45f) * 0.7f; /* (its random scale, on the prefab's) */+ float dx = hero_x() - x, dy = hero_y() - y, l = sqrtf(dx * dx + dy * dy);+ if (l < 1e-4f) l = 1, dx = 1;+ b->vx = dx / l * speed, b->vy = dy / l * speed;+ anim_play(&b->anim, CLIP_BULLET_IDLE);+}++static void bullet_impact(Bullet *b) {+ b->active = false;+ b->vx = b->vy = 0;+ anim_play_from_frame(&b->anim, CLIP_BULLET_IMPACT, 0);+}++static void bullets_tick(void) {+ for (int i = 0; i < MAX_BULLETS; i++) {+ Bullet *b = &bullets[i];+ if (!b->on) continue;+ b->anim.events = 0;+ anim_update(&b->anim, DT);+ if (!b->active) {+ if (b->anim.events & ANIM_DONE) b->on = false;+ continue;+ }+ b->vy += -60 * 0.05f * DT; /* (its Rigidbody2D: gravity 0.05) */+ float dx = b->vx * DT, dy = b->vy * DT, l = sqrtf(dx * dx + dy * dy);+ PhysHit hit;+ if (l > 0 && phys_ray(b->x, b->y, dx / l, dy / l, l + BULLET_HX, CF_SOLID, &hit)) {+ b->x = hit.x - dx / l * BULLET_HX, b->y = hit.y - dy / l * BULLET_HX;+ b->ang = atan2f(hit.ny, hit.nx) * 180 / (float)M_PI + 90;+ bullet_impact(b);+ continue;+ }+ b->x += dx, b->y += dy;+ b->ang = atan2f(b->vy, b->vx) * 180 / (float)M_PI;+ if (b->y < -10) b->on = false;+ }+}++/* (a shot that touched the HeroBox bursts there) */+static int bullets_touch_hero(float x0, float y0, float x1, float y1, int *side) {+ for (int i = 0; i < MAX_BULLETS; i++) {+ Bullet *b = &bullets[i];+ if (!b->on || !b->active) continue;+ float hx = BULLET_HX * b->scale, hy = BULLET_HY * b->scale;+ if (x1 > b->x - hx && x0 < b->x + hx && y1 > b->y - hy && y0 < b->y + hy) {+ *side = b->vx < 0 ? SIDE_RIGHT : SIDE_LEFT;+ bullet_impact(b);+ return 1;+ }+ }+ return 0;+}++static void bullets_draw(void) {+ for (int i = 0; i < MAX_BULLETS; i++) {+ const Bullet *b = &bullets[i];+ if (!b->on) continue;+ /* (stretched along its flight) */+ float sp = sqrtf(b->vx * b->vx + b->vy * b->vy), sy = 1 - sp * 1.2f * 0.01f, sx = 1 + sp * 1.2f * 0.01f;+ if (!b->active) sx = sy = 1;+ Inst in;+ sprite_inst_rot(b->anim.sprite, b->x, b->y, -0.01f, sx * b->scale, sy * b->scale, b->ang, 0, &in);+ gfx_actor(&in, SORT_KEY(0, 0));+ }+}++/* ---------------------------------------------------------------- Aspid Hunters: the spitter FSM */+enum { SP_IDLE, SP_DISTANCE_FLY, SP_RAYCAST, SP_FLY_BACK, SP_FIRE_ANTIC, SP_FIRE, SP_DRIBBLE };++static bool spitter_unalert_range(const Enemy *e) {+ /* the hero in its Unalert Range (its circle) */+ const Ent *d = ent_at(e->ent);+ for (int i = 1; i <= d->s0; i++) {+ const Ent *r = &d[i];+ if (r->type != ENT_BOX || r->flags != ET_RANGE) continue;+ float dx = hero_x() - (e->body.x + r->x0 * (e->sx < 0 ? -1 : 1)), dy = hero_y() - (e->body.y + r->y0);+ return dx * dx + dy * dy < r->x1 * r->x1;+ }+ return true;+}++static void spitter_idle(Enemy *e) {+ e->st = SP_IDLE;+ anim_play_from_frame(&e->anim, CLIP(e, R_A1), 2);+ e->start_x = e->body.x, e->start_y = e->body.y;+ e->wait = 0, e->ax = e->ay = 0;+}++static void spitter_distance_fly(Enemy *e) {+ e->st = SP_DISTANCE_FLY;+ anim_play_from_frame(&e->anim, CLIP(e, R_A1), 2);+ e->t0 = rand_range(1.5f, 2.25f);+}++static void spitter_start(Enemy *e, const Ent *d) {+ spitter_idle(e);+ if (d->s1 & 1) spitter_distance_fly(e); /* (startAlert) */+}++static void spitter_face(Enemy *e, bool turn_clip) {+ float want = hero_x() > e->body.x ? -fabsf(e->sx) : fabsf(e->sx);+ if (e->sx != want) {+ set_scale_x(e, want);+ if (turn_clip) anim_play_from_frame(&e->anim, CLIP(e, R_A2), 0);+ }+}++static void spitter_fixed(Enemy *e) {+ switch (e->st) {+ case SP_IDLE: idle_buzz(e); break;+ case SP_DISTANCE_FLY:+ case SP_RAYCAST: distance_fly(e, 7, 4, 0.1f, false); break;+ case SP_FLY_BACK: distance_fly(e, 8.25f, 4, 0.1f, false); break;+ case SP_FIRE_ANTIC: distance_fly(e, 9, 2, 0.1f, false); break;+ default: break;+ }+}++static void spitter_update(Enemy *e) {+ /* the range out timer: out of its unalert range 8 s, it gives up */+ if (e->st >= SP_DISTANCE_FLY && e->st <= SP_RAYCAST) {+ if (spitter_unalert_range(e)) e->t1 = 0;+ else if ((e->t1 += DT) > 8) {+ spitter_idle(e);+ return;+ }+ }+ switch (e->st) {+ case SP_IDLE:+ face_direction(e, &e->pause0, CLIP(e, R_A2));+ if (e->can_see && e->in_alert) spitter_distance_fly(e);+ break;+ case SP_DISTANCE_FLY:+ spitter_face(e, true);+ if ((e->t0 -= DT) <= 0) {+ /* Raycast: near enough, nothing between: fire */+ float dx = hero_x() - e->body.x, dy = hero_y() - e->body.y, l = sqrtf(dx * dx + dy * dy);+ if (l > 14) spitter_distance_fly(e);+ else {+ bool blocked = l > 1e-4f && phys_ray(e->body.x, e->body.y, dx / l, dy / l, l, CF_TERRAIN, NULL);+ if (blocked) spitter_distance_fly(e);+ else e->st = SP_FLY_BACK, e->t0 = 0.5f;+ }+ }+ break;+ case SP_FLY_BACK:+ spitter_face(e, true);+ if ((e->t0 -= DT) <= 0) {+ e->st = SP_FIRE_ANTIC;+ anim_play_from_frame(&e->anim, CLIP(e, R_A3), 0);+ }+ break;+ case SP_FIRE_ANTIC:+ spitter_face(e, false);+ if (e->anim.events & ANIM_TRIGGER) {+ /* Fire: its shot at the hero */+ bullet_fire(e->body.x, e->body.y, 15);+ spitter_face(e, false);+ e->st = SP_DRIBBLE;+ }+ break;+ case SP_DRIBBLE:+ if ((e->anim.events & ANIM_DONE) || !e->anim.playing) spitter_distance_fly(e);+ break;+ }+}+/* ---------------------------------------------------------------- Husks: the Zombie Swipe FSM, a Walker */enum { ZS_READY, ZS_ANTICIPATE, ZS_LUNGE, ZS_COOLDOWN, ZS_IDLE };#define ZS_LUNGE_SPEED 6.0f@@ -635,12 +1042,14 @@ static void husk_attack(Enemy *e) {/* Left or Right?: the walker stopped, facing the hero (Face Left / Face Right) */walker_stop(e, STOP_CONTROLLED);bool right = hero_x() > e->body.x;- e->ax = right ? ZS_LUNGE_SPEED : -ZS_LUNGE_SPEED;+ const Ent *v = enemy_rec(e, ET_VARS);+ float speed = v ? v->p0 : ZS_LUNGE_SPEED;+ e->ax = right ? speed : -speed;set_scale_x(e, right ? -fabsf(e->sx) : fabsf(e->sx));e->wk_facing = right ? 1 : -1; /* (SetWalkerFacing: ChangeFacing) *//* Anticipate */e->body.vx = e->body.vy = 0;- anim_play_from_frame(&e->anim, CLIP_HUSK_ATTACK_ANTICIPATE, 0);+ anim_play_from_frame(&e->anim, CLIP(e, R_A1), 0);e->st = ZS_ANTICIPATE;}@@ -664,24 +1073,27 @@ static void husk_update(Enemy *e) {case ZS_ANTICIPATE:if (done) {e->st = ZS_LUNGE;- anim_play_from_frame(&e->anim, CLIP_HUSK_ATTACK_LUNGE, 0);+ anim_play_from_frame(&e->anim, CLIP(e, R_A2), 0);}break;case ZS_LUNGE:if (done) {e->st = ZS_COOLDOWN;- anim_play_from_frame(&e->anim, CLIP_HUSK_ATTACK_COOLDOWN, 0);+ anim_play_from_frame(&e->anim, CLIP(e, R_A3), 0);e->body.vx = 0;}break;case ZS_COOLDOWN:if (done) {e->st = ZS_IDLE, e->t0 = 0;- anim_play(&e->anim, CLIP_HUSK_IDLE);+ anim_play(&e->anim, CLIP(e, R_IDLE));}break;- case ZS_IDLE:- if ((e->t0 += DT) >= ZS_IDLE_TIME) husk_ready(e);+ case ZS_IDLE: {+ const Ent *v = enemy_rec(e, ET_VARS);+ if ((e->t0 += DT) >= (v ? v->p1 : ZS_IDLE_TIME)) husk_ready(e);+ break;+ }break;}}@@ -739,17 +1151,6 @@ static bool roamed_off(const Enemy *e) {return dx * dx + dy * dy > SHADE_MAX_ROAM * SHADE_MAX_ROAM;}-/* DistanceFly (targets height): keeps a distance from the hero, at its height */-static void distance_fly(Enemy *e, float dist, float vmax, float accel) {- float vx = e->body.vx, vy = e->body.vy, d = hero_dist(e);- bool left = e->body.x < hero_x();- vx += (d > dist) == left ? accel : -accel;- if (e->body.y < hero_y()) vy += accel;- if (e->body.y > hero_y()) vy -= accel;- e->body.vx = vx > vmax ? vmax : vx < -vmax ? -vmax : vx;- e->body.vy = vy > vmax ? vmax : vy < -vmax ? -vmax : vy;-}-static void shade_retreat(Enemy *e) {/* Retreat Start: no collider, slowing */e->st = SH_RETREAT_START;@@ -834,7 +1235,7 @@ static void shade_killed(Enemy *e) {void enemies_hero_leave(void) {for (int i = 0; i < MAX_ENEMIES; i++) {Enemy *e = &en[i];- if (e->kind != EK_SHADE || e->mode != EM_ALIVE) continue;+ if (FSM(e) != EF_SHADE || e->mode != EM_ALIVE) continue;e->mode = EM_CORPSE, e->flags |= 1, sh.slash_on = false;anim_play(&e->anim, CLIP_SHADE_FLY);shade_face_hero(e, CLIP_SHADE_TURNTOFLY);@@ -855,8 +1256,8 @@ static void shade_fixed(Enemy *e) {break;}case SH_POSITION:- case SH_SLASH_ANTIC: distance_fly(e, 3, 4, 0.2f); break;- case SH_FIREBALL_POS: distance_fly(e, 12, 4, 0.2f); break;+ case SH_SLASH_ANTIC: distance_fly(e, 3, 4, 0.2f, true); break;+ case SH_FIREBALL_POS: distance_fly(e, 12, 4, 0.2f, true); break;case SH_CAST_ANTIC: e->body.vx *= 0.8f, e->body.vy *= 0.8f; break;case SH_DECEL:case SH_COOLDOWN:@@ -1071,12 +1472,16 @@ void enemies_enter(void) {e->rc_base = rc ? rc->x0 : 15, e->rc_dur = rc ? rc->y0 : 0.5f, e->rc_flags = rc ? (uint8_t)rc->a : 0;const Ent *wk = enemy_rec(e, ET_WALKER);e->wk_rec = wk ? (uint16_t)(wk - room_ents(&n)) : 0;- if (e->kind == EK_CRAWLER) crawler_start(e, d);- else if (e->kind == EK_BUZZER) buzzer_start(e, d);- else if (e->kind == EK_HUSK) husk_start(e);+ if (FSM(e) == EF_CRAWLER) crawler_start(e, d);+ else if (FSM(e) == EF_BUZZER) buzzer_start(e, d);+ else if (FSM(e) == EF_HUSK) husk_start(e);+ else if (FSM(e) == EF_CLIMBER) climber_start(e);+ else if (FSM(e) == EF_BOUNCER) bouncer_start(e);+ else if (FSM(e) == EF_SPITTER) spitter_start(e, d);}memset(&sh, 0, sizeof sh);memset(balls, 0, sizeof balls);+ memset(bullets, 0, sizeof bullets);shade_spawn_check();}@@ -1085,21 +1490,28 @@ void enemies_fixed(void) {for (int i = 0; i < MAX_ENEMIES; i++) {Enemy *e = &en[i];if (e->mode == EM_OFF) continue;- if (e->kind == EK_SHADE) {+ if (FSM(e) == EF_SHADE) {if (e->mode == EM_ALIVE) shade_fixed(e), recoil_fixed(e);else shade_fixed(e);if (e->st != SH_RETREAT) body_step(&e->body, DT);continue;}+ if (e->mode == EM_ALIVE && FSM(e) == EF_CLIMBER) {+ /* (a kinematic body: its velocity, nothing in its way) */+ recoil_fixed(e);+ e->body.x += e->body.vx * DT, e->body.y += e->body.vy * DT;+ continue;+ }if (e->mode == EM_ALIVE) {- if (e->kind == EK_CRAWLER) crawler_fixed(e);- else if (e->kind == EK_BUZZER) buzzer_fixed(e);- else if (e->kind == EK_HUSK) husk_fixed(e);+ if (FSM(e) == EF_CRAWLER) crawler_fixed(e);+ else if (FSM(e) == EF_BUZZER) buzzer_fixed(e);+ else if (FSM(e) == EF_HUSK) husk_fixed(e);+ else if (FSM(e) == EF_BOUNCER) bouncer_fixed(e);+ else if (FSM(e) == EF_SPITTER) spitter_fixed(e);recoil_fixed(e);body_step(&e->body, DT);} else {/* Corpse: falls, lands (or smashes, a breaker) and stays */- const Kind *k = &kinds[e->kind];const Ent *cr = enemy_rec(e, ET_CORPSE);bool breaker = cr && (cr->a & CF_BREAKER);float cbounce = cr ? cr->p1 : -1;@@ -1111,12 +1523,12 @@ void enemies_fixed(void) {for (int c = 0; c < e->body.ncontacts; c++) ground |= e->body.cny[c] > 0.5f;if (ground) {if (breaker) {- anim_play(&e->anim, k->clip_death_land);+ anim_play(&e->anim, kinds[e->kind].clip[R_DEATH_LAND]);e->body.vx = e->body.vy = 0;e->st = CS_DEATH_ANIM;} else {bounce(&e->body, pvx, pvy, had, cbounce);- anim_play(&e->anim, k->clip_death_land);+ anim_play(&e->anim, kinds[e->kind].clip[R_DEATH_LAND]);e->st = CS_LANDED;}} else@@ -1127,6 +1539,7 @@ void enemies_fixed(void) {}geo_tick();balls_tick();+ bullets_tick();}/* Update: the FSMs' every-frame actions, the animations, the timers */@@ -1140,10 +1553,13 @@ void enemies_update(void) {if (e->mode == EM_ALIVE) {if (e->evasion > 0) e->evasion -= DT;if (e->ar_r > 0) sight_update(e);- if (e->kind == EK_BUZZER) buzzer_update(e, ent_at(e->ent));- else if (e->kind == EK_SHADE) shade_update(e);- else if (e->kind == EK_HUSK) husk_update(e);- } else if (e->kind == EK_SHADE)+ if (FSM(e) == EF_BUZZER) buzzer_update(e, ent_at(e->ent));+ else if (FSM(e) == EF_SHADE) shade_update(e);+ else if (FSM(e) == EF_HUSK) husk_update(e);+ else if (FSM(e) == EF_CLIMBER) climber_update(e);+ else if (FSM(e) == EF_BOUNCER) bouncer_update(e);+ else if (FSM(e) == EF_SPITTER) spitter_update(e);+ } else if (FSM(e) == EF_SHADE)shade_update(e);else if (e->st == CS_DEATH_ANIM && !e->anim.playing)e->mode = EM_OFF;@@ -1155,15 +1571,19 @@ void enemies_draw(void) {const Enemy *e = &en[i];if (e->mode == EM_OFF) continue;Inst in;- float z = e->mode == EM_CORPSE && e->kind != EK_SHADE ? 0.0085f : e->z;- if (e->kind == EK_SHADE && e->st == SH_DISSIPATE) continue; /* (its renderer off) */- sprite_inst(e->anim.sprite, e->body.x + e->jx, e->body.y + e->jy, z, e->sx, 1, flash_tint(e, 2 + i % 5), &in);+ float z = e->mode == EM_CORPSE && FSM(e) != EF_SHADE ? 0.0085f : e->z;+ if (FSM(e) == EF_SHADE && e->st == SH_DISSIPATE) continue; /* (its renderer off) */+ if (e->ang != 0 && e->mode == EM_ALIVE)+ sprite_inst_rot(e->anim.sprite, e->body.x, e->body.y, z, e->sx, 1, e->ang, flash_tint(e, 2 + i % 5), &in);+ else+ sprite_inst(e->anim.sprite, e->body.x + e->jx, e->body.y + e->jy, z, e->sx, 1, flash_tint(e, 2 + i % 5), &in);gfx_actor(&in, SORT_KEY(0, 0));- if (e->kind == EK_SHADE && sh.slash_on) {+ if (FSM(e) == EF_SHADE && sh.slash_on) {sprite_inst(sh.slash.sprite, e->body.x - 0.0486f * e->sx, e->body.y - 0.0117f, z - 0.001f, 1.27f * e->sx, 1, 0, &in);gfx_actor(&in, SORT_KEY(0, 0));}}+ bullets_draw();for (int i = 0; i < MAX_BALLS; i++) {const Ball *b = &balls[i];if (!b->on) continue;@@ -1211,7 +1631,7 @@ int enemies_touch_hero(float x0, float y0, float x1, float y1, int *side) {*side = e->body.x > g_hero.body.x ? SIDE_RIGHT : SIDE_LEFT;return e->damage;}- if (e->kind == EK_SHADE && sh.slash_on) {+ if (FSM(e) == EF_SHADE && sh.slash_on) {/* its Slash's polygon */float pts[10];for (int k = 0; k < 5; k++)@@ -1222,6 +1642,8 @@ int enemies_touch_hero(float x0, float y0, float x1, float y1, int *side) {}}}+ int dmg = bullets_touch_hero(x0, y0, x1, y1, side);+ if (dmg) return dmg;for (int i = 0; i < MAX_BALLS; i++) {const Ball *b = &balls[i];if (!b->on || b->ending) continue;diff --git a/games/hollowknight/tools/actors.py b/games/hollowknight/tools/actors.pyindex 417f3990..b366b58d 100644--- a/games/hollowknight/tools/actors.py+++ b/games/hollowknight/tools/actors.py@@ -20,11 +20,56 @@ KNIGHT = ("resources.assets", 20600, ["Collect Heart Piece", "Collect Heart Piece End", "Collect StandToIdle", "GetUpToIdle", "Death Head Cracked",])-# enemies: their libraries (all their clips)+# enemy kinds: name, the FSM (or component) that runs them, their library, the C code for that FSM, and the clips each+# role plays (src/enemy.c: R_*); the corpse's from its library (by default the enemy's)+ROLES = ["IDLE", "TURN", "WALK", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "DEATH_AIR", "DEATH_LAND"]+ENEMY_KINDS = [+ ("crawler", "Crawler", ("sharedassets6.assets", 1113), "CRAWLER", {"WALK": "Walk", "TURN": "Turn"}),+ ("buzzer", "chaser", ("sharedassets6.assets", 1150), "BUZZER", {"IDLE": "Idle"}),+ ("shade", None, ("resources.assets", 22801), "SHADE", {}),+ ("tiktik", "Climber", ("sharedassets37.assets", 146), "CLIMBER", {"WALK": "Walk", "A1": "Stun"}),+ ("gruzzer", "Bouncer Control", ("sharedassets40.assets", 208), "BOUNCER", {"A1": "Fly"}),+ ("aspid", "spitter", ("sharedassets39.assets", 104), "SPITTER", {"A1": "Fly", "A2": "TurnToFly", "A3": "Fire Long"}),+ ("husk", "Zombie Swipe", ("sharedassets37.assets", 149), "HUSK",+ {"IDLE": "Idle", "TURN": "Turn", "WALK": "Walk", "A1": "Attack Anticipate", "A2": "Attack Lunge", "A3": "Attack Cooldown"}),+ ("barger", "Zombie Swipe", ("sharedassets40.assets", 198), "HUSK",+ {"IDLE": "Idle", "TURN": "Turn", "WALK": "Walk", "A1": "Attack Anticipate", "A2": "Attack Lunge", "A3": "Attack Cooldown"}),+ ("hornhead", "Zombie Swipe", ("sharedassets40.assets", 192), "HUSK",+ {"IDLE": "Idle", "TURN": "Turn", "WALK": "Walk", "A1": "Attack Anticipate", "A2": "Attack Lunge", "A3": "Attack Cooldown"}),+]+ENEMY_CORPSE_LIBS = {} # (name -> its corpse's library, if not its own)+++def enemy_kind_id(name):+ return 1 + [k[0] for k in ENEMY_KINDS].index(name)+++def _enemy_actors():+ out = {}+ for name, fsm, (f, pid), code, roles in ENEMY_KINDS:+ if name in ("crawler", "buzzer"):+ out[name] = (f, pid, None)+ continue+ if name == "shade":+ continue+ have = {unity.S(c["name"]) for c in tk2d.animation(f, pid)["clips"]}+ out[name] = (f, pid, sorted((set(roles.values()) | {"Death Air", "Death Land"}) & have))+ return out+++def kind_table(clip_ids):+ """src/data.h's KIND_TABLE: each kind's FSM code and its roles' clips (-1: none)"""+ rows = []+ for name, fsm, lib, code, roles in ENEMY_KINDS:+ ids = []+ for r in ROLES:+ clip = roles.get(r) or {"DEATH_AIR": "Death Air", "DEATH_LAND": "Death Land"}.get(r)+ ids.append(clip_ids.get(clip_id(name, clip), -1) if clip else -1)+ rows.append("{EF_%s, {%s}}" % (code, ", ".join(str(i) for i in ids)))+ return "{{0}, " + ", ".join(rows) + "}"++ACTORS = {"knight": KNIGHT,- "crawler": ("sharedassets6.assets", 1113, None),- "buzzer": ("sharedassets6.assets", 1150, None),- "husk": ("sharedassets37.assets", 149, None),"georock": ("sharedassets6.assets", 1149, None),"chest": ("sharedassets6.assets", 1148, None),# the HUD: drawn by its own camera, 11.48 pixels a unit (scenes: K0), masks at 0.7135@@ -43,6 +88,9 @@ ACTORS = {"knight": KNIGHT,"Slash CD", "Slash Effect", "Cast Antic", "Cast Charge", "Cast","Retreat Start", "Retreat End", "Death Start", "Death", "Depart","Appear", "Fireball", "Fireball End", "Cast Ring"])}+ACTORS.update(_enemy_actors())+# enemies' shots (EnemyBullet)+ACTORS["bullet"] = ("sharedassets32.assets", 745, ["Idle", "Impact"])# sprites of prefab objects the game draws itself: name -> (file, prefab, object, resolution)NAMED = {diff --git a/games/hollowknight/tools/ents.py b/games/hollowknight/tools/ents.pyindex 59f93cd1..1d228185 100644--- a/games/hollowknight/tools/ents.py+++ b/games/hollowknight/tools/ents.py@@ -10,10 +10,14 @@ ENT_CAMLOCK, ENT_GATE, ENT_HAZARD_MARKER, ENT_RESPAWN, ENT_HAZARD_TRIGGER, ENT_M# objects (ENT_OBJ's flags: src/obj.c)OK_BREAKABLE, OK_ENEMY, OK_GREAT_DOOR, OK_GEO_ROCK, OK_CHEST, OK_BENCH = 1, 2, 3, 4, 5, 6# enemies (an OK_ENEMY's a: src/enemy.c), by their FSM and animation library-EK_CRAWLER, EK_BUZZER, EK_SHADE, EK_HUSK = 1, 2, 3, 4-ENEMIES = {("Crawler", 1113): EK_CRAWLER, ("chaser", 1150): EK_BUZZER, ("Zombie Swipe", 149): EK_HUSK}+import actors as _actors+# enemies: by the FSM (or component) that runs them and their animation library -> their kind (actors.ENEMY_KINDS)+ENEMIES = {(fsm, f, pid): i + 1 for i, (name, fsm, (f, pid), code, roles) in enumerate(_actors.ENEMY_KINDS) if fsm}+# their FSMs' variables an enemy's record keeps (ET_VARS: up to four numbers, then bools as bits)+ENEMY_VARS = {"Zombie Swipe": (["Lunge Speed", "Idle Time"], ["Coward"]),+ "Bouncer Control": (["Speed"], ["Starts Inactive", "Start Up"])}# what follows an enemy's record: ENT_BOX records, tagged-ET_COLLIDER, ET_ALERT, ET_RANGE, ET_WALKER, ET_RECOIL, ET_CORPSE = 0, 1, 2, 3, 4, 5+ET_COLLIDER, ET_ALERT, ET_RANGE, ET_WALKER, ET_RECOIL, ET_CORPSE, ET_VARS = 0, 1, 2, 3, 4, 5, 6EF_START, EF_STARTLES = 1, 2 # (FSM bools: First Crawler or Start Alert; Startles)# the layers the nail's slashes touch (Physics2D's collision matrix, layer 17 Attack)ATTACK_HITS = {3, 6, 7, 8, 11, 12, 17, 19, 20, 21, 25, 31}@@ -320,9 +324,10 @@ def _enemy(o, by_id, persist, name, d=None, strings=None):if not an or not hm:return Nonekind, fsm = None, {}+ lib = _ref_file(d, an["library"]) if d is not None else ("", an["library"][1])for c in o["c"]:f = c.get("fsm")- key = (f["name"] if f else c.get("class"), an["library"][1])+ key = (f["name"] if f else c.get("class"),) + libif key in ENEMIES:kind, fsm = ENEMIES[key], f or {}if kind is None:@@ -345,7 +350,7 @@ def _enemy(o, by_id, persist, name, d=None, strings=None):# its alert ranges (children with AlertRange): "Alert Range New" the main one, others by namefor ch in o.get("children", []):q = by_id[ch]- if not any(c.get("class") == "AlertRange" for c in q["c"]) and q["name"] != "Alert Range New":+ if not any(c.get("class") == "AlertRange" for c in q["c"]) and q["name"] not in ("Alert Range New", "Unalert Range"):continuer = _alert_range(q)if r is None:@@ -365,6 +370,17 @@ def _enemy(o, by_id, persist, name, d=None, strings=None):p=(w.get("pauseWaitMin", 0), w.get("pauseWaitMax", 0), w.get("turnPause", 0), w.get("edgeXAdjuster", 0)),group=w.get("turnAfterIdlePercentage", 0), a=wf,s1=max(0, min(65535, int(round(w.get("waitHeroX", 0) * 16))))))+ cl = next((c.get("v") for c in o["c"] if c.get("class") == "Climber" and c.get("v")), None)+ if cl:+ # (Climber: speed, spin time, wall ray padding, min turn distance; start right; its start angle's quarter)+ ang = int(round(_angle(o) / 90)) % 4+ out.append(rec(ENT_BOX, ET_VARS, p=(cl.get("speed", 2), cl.get("spinTime", 0.25), cl.get("wallRayPadding", 0.1),+ cl.get("minTurnDistance", 0.25)), a=1 if cl.get("startRight", 1) else 0, s1=ang))+ nums, bools = ENEMY_VARS.get(fsm.get("name"), ([], []))+ if nums or bools:+ vals = [float((var.get(k) or [0, 0])[1] or 0) for k in nums] + [0.0] * (4 - len(nums))+ bits = sum(1 << i for i, k in enumerate(bools) if (var.get(k) or [0, False])[1])+ out.append(rec(ENT_BOX, ET_VARS, p=tuple(vals[:4]), a=bits))rc = next((c.get("v") for c in o["c"] if c.get("class") == "Recoil" and c.get("v")), None)if rc:out.append(rec(ENT_BOX, ET_RECOIL, box=(rc.get("recoilSpeedBase", 15), rc.get("recoilDuration", 0.15), 0, 0),@@ -386,11 +402,12 @@ def _enemy(o, by_id, persist, name, d=None, strings=None):sp = de.get("corpseSpawnPoint") or {"y": 0}cfl = (1 if cv.get("breaker") else 0) | (2 if de.get("corpseFacesRight") else 0) | \(4 if de.get("lowCorpseArc") else 0) | (8 if cv.get("instantChunker") else 0) | (16 if cv.get("massless") else 0)- if cb:- out.append(rec(ENT_BOX, ET_CORPSE, box=(cb["m_Offset"]["x"] * k[0], cb["m_Offset"]["y"] * k[1],- cb["m_Size"]["x"] / 2 * k[0], cb["m_Size"]["y"] / 2 * k[1]),- p=(rb.get("m_GravityScale", 1), ob.get("bounceFactor", -1) if ob else -1,- de.get("corpseFlingSpeed", 15), sp.get("y", 0)), a=cfl))+ # (a corpse with no collider falls through all: flag 32)+ box = (cb["m_Offset"]["x"] * k[0], cb["m_Offset"]["y"] * k[1], cb["m_Size"]["x"] / 2 * k[0],+ cb["m_Size"]["y"] / 2 * k[1]) if cb else (0, 0, 0, 0)+ out.append(rec(ENT_BOX, ET_CORPSE, box=box, p=(rb.get("m_GravityScale", 1), ob.get("bounceFactor", -1) if ob else -1,+ de.get("corpseFlingSpeed", 15), sp.get("y", 0)),+ a=cfl | (0 if cb else 32)))except Exception as e:print("ents: %s: corpse %s" % (o["path"], e))persistent = any(c.get("class") == "PersistentBoolItem" for c in o["c"])diff --git a/games/hollowknight/tools/pack.py b/games/hollowknight/tools/pack.pyindex d97c9946..0bd41f60 100644--- a/games/hollowknight/tools/pack.py+++ b/games/hollowknight/tools/pack.py@@ -423,6 +423,10 @@ def main():for i, k in enumerate(text.STYLES):f.write("#define STYLE_%s %d\n" % (k, i))f.write("#define TEXT_K %.6ff\n#define FONT_PHASES %d\n" % (text.TEXT_K, text.PHASES))+ for i, k in enumerate(actors.ENEMY_KINDS):+ f.write("#define EK_%s %d\n" % (k[0].upper(), i + 1))+ f.write("#define NUM_KINDS %d\n" % (len(actors.ENEMY_KINDS) + 1))+ f.write("#define KIND_TABLE %s\n" % actors.kind_table({c["id"]: i for i, c in enumerate(clips)}))for k, v in prompt_ids.items():f.write("#define TXT_PROMPT_%s %d\n" % (k.upper(), v))f.write("#define PROMPT_SORT %du\n" % ((scene.layer_index(-349214895) << 16) | (1 + 32768)))