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: Moss Knights
Mason Chen20e4c26dfedd
diff --git a/games/hollowknight/src/data.bin b/games/hollowknight/src/data.binindex 41cfd1b3..11ea95b1 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 47243108..4d26475c 100644--- a/games/hollowknight/src/data.h+++ b/games/hollowknight/src/data.h@@ -411,58 +411,83 @@#define CLIP_MOSSCHARGER_GET_UP 351#define CLIP_MOSSCHARGER_STUN 352#define CLIP_MOSSCHARGER_TURNRUN 353-#define CLIP_BGATE_BG_OPENED 354-#define CLIP_BGATE_BG_CLOSE_1 355-#define CLIP_BGATE_BG_CLOSE_2 356-#define CLIP_BGATE_BG_OPEN 357-#define CLIP_BGATE_BG_CLOSED 358-#define CLIP_BGATE_BONE_GATE_OPENED 359-#define CLIP_BGATE_BONE_GATE_CLOSE 360-#define CLIP_BGATE_BONE_GATE_CLOSED 361-#define CLIP_BGATE_BONE_GATE_OPEN 362-#define CLIP_COCOON_COCOON_IDLE 363-#define CLIP_COCOON_COCOON_SWEAT 364-#define CLIP_COCOON_SCUTTLER_LAND 365-#define CLIP_COCOON_SCUTTLER_RUN 366-#define CLIP_FX_SPLAT 367-#define CLIP_FX_SPLAT2 368-#define CLIP_FIREBALL_BLAST 369-#define CLIP_FIREBALL_BALL 370-#define CLIP_FIREBALL_BALL_END 371-#define CLIP_FIREBALL_FIREBALL_WALL_IMPACT 372-#define CLIP_DRIP_IDLE 373-#define CLIP_DRIP_DRIP 374-#define CLIP_DRIP_FALL 375-#define CLIP_DRIP_IMPACT 376-#define CLIP_BULLET_IDLE 377-#define CLIP_BULLET_IMPACT 378-#define CLIP_BULLET_SHOCKWAVE_SPURT 379-#define CLIP_PROP0_WATERFALL_LOOP 380-#define CLIP_PROP1_TORCH2 381-#define CLIP_PROP1_TORCH3 382-#define CLIP_VM0_FLOWER 383-#define CLIP_VM0_IDLE 384-#define CLIP_VM0_REACH 385-#define CLIP_VM0_REACH_TO_IDLE 386-#define CLIP_VM0_TALK_LEFT 387-#define CLIP_VM0_TALK_RIGHT 388-#define CLIP_VM0_TURN_LEFT 389-#define CLIP_VM0_TURN_RIGHT 390-#define CLIP_VM2_IDLE 391-#define CLIP_VM2_SIT_IDLE 392-#define CLIP_VM2_SIT_TALK 393-#define CLIP_VM2_SIT_TALK_END 394-#define CLIP_VM2_SUMMON 395-#define CLIP_VM2_TALK 396-#define CLIP_VM2_TALK_END 397-#define CLIP_VM2_TURN 398-#define SPRITE_HERO_LIGHT 1681-#define SPRITE_DIALOGUE_BACKBOARD 1682-#define SPRITE_PROMPT_SHADOW 1683-#define SPRITE_CORPSE_NAIL 1684-#define SPRITE_FK_BARREL 1685-#define SPRITE_FK_STAFF 1686-#define SPRITE_DIGIT0 1885+#define CLIP_MOSSKNIGHT_DEATH_AIR 354+#define CLIP_MOSSKNIGHT_DEATH_LAND 355+#define CLIP_MOSSKNIGHT_DORMANT_1 356+#define CLIP_MOSSKNIGHT_DORMANT_2 357+#define CLIP_MOSSKNIGHT_EVADE 358+#define CLIP_MOSSKNIGHT_IDLE 359+#define CLIP_MOSSKNIGHT_SHAKE 360+#define CLIP_MOSSKNIGHT_SHIELD_FRONT 361+#define CLIP_MOSSKNIGHT_SHIELD_FRONT_BUMP 362+#define CLIP_MOSSKNIGHT_SHIELD_TOP 363+#define CLIP_MOSSKNIGHT_SHIELD_TOP_BUMP 364+#define CLIP_MOSSKNIGHT_SHOOT 365+#define CLIP_MOSSKNIGHT_SHOOT_END 366+#define CLIP_MOSSKNIGHT_SLASH 367+#define CLIP_MOSSKNIGHT_SLASH_2 368+#define CLIP_MOSSKNIGHT_SLASH_2_EFFECT 369+#define CLIP_MOSSKNIGHT_SLASH_EFFECT 370+#define CLIP_MOSSKNIGHT_SLASH_EFFECT_QUICK 371+#define CLIP_MOSSKNIGHT_SLASH_END 372+#define CLIP_MOSSKNIGHT_SLASH_QUICK 373+#define CLIP_MOSSKNIGHT_TURN 374+#define CLIP_MOSSKNIGHT_UNSHIELD_FRONT 375+#define CLIP_MOSSKNIGHT_UNSHIELD_TOP 376+#define CLIP_MOSSKNIGHT_WAKE 377+#define CLIP_MOSSKNIGHT_WALK 378+#define CLIP_BGATE_BG_OPENED 379+#define CLIP_BGATE_BG_CLOSE_1 380+#define CLIP_BGATE_BG_CLOSE_2 381+#define CLIP_BGATE_BG_OPEN 382+#define CLIP_BGATE_BG_CLOSED 383+#define CLIP_BGATE_BONE_GATE_OPENED 384+#define CLIP_BGATE_BONE_GATE_CLOSE 385+#define CLIP_BGATE_BONE_GATE_CLOSED 386+#define CLIP_BGATE_BONE_GATE_OPEN 387+#define CLIP_COCOON_COCOON_IDLE 388+#define CLIP_COCOON_COCOON_SWEAT 389+#define CLIP_COCOON_SCUTTLER_LAND 390+#define CLIP_COCOON_SCUTTLER_RUN 391+#define CLIP_FX_SPLAT 392+#define CLIP_FX_SPLAT2 393+#define CLIP_FIREBALL_BLAST 394+#define CLIP_FIREBALL_BALL 395+#define CLIP_FIREBALL_BALL_END 396+#define CLIP_FIREBALL_FIREBALL_WALL_IMPACT 397+#define CLIP_DRIP_IDLE 398+#define CLIP_DRIP_DRIP 399+#define CLIP_DRIP_FALL 400+#define CLIP_DRIP_IMPACT 401+#define CLIP_BULLET_IDLE 402+#define CLIP_BULLET_IMPACT 403+#define CLIP_BULLET_SHOCKWAVE_SPURT 404+#define CLIP_PROP0_WATERFALL_LOOP 405+#define CLIP_PROP1_TORCH2 406+#define CLIP_PROP1_TORCH3 407+#define CLIP_VM0_FLOWER 408+#define CLIP_VM0_IDLE 409+#define CLIP_VM0_REACH 410+#define CLIP_VM0_REACH_TO_IDLE 411+#define CLIP_VM0_TALK_LEFT 412+#define CLIP_VM0_TALK_RIGHT 413+#define CLIP_VM0_TURN_LEFT 414+#define CLIP_VM0_TURN_RIGHT 415+#define CLIP_VM2_IDLE 416+#define CLIP_VM2_SIT_IDLE 417+#define CLIP_VM2_SIT_TALK 418+#define CLIP_VM2_SIT_TALK_END 419+#define CLIP_VM2_SUMMON 420+#define CLIP_VM2_TALK 421+#define CLIP_VM2_TALK_END 422+#define CLIP_VM2_TURN 423+#define SPRITE_HERO_LIGHT 1782+#define SPRITE_DIALOGUE_BACKBOARD 1783+#define SPRITE_PROMPT_SHADOW 1784+#define SPRITE_CORPSE_NAIL 1785+#define SPRITE_FK_BARREL 1786+#define SPRITE_FK_STAFF 1787+#define SPRITE_DIGIT0 1987#define STYLE_DIALOGUE 0#define STYLE_PROMPT 1#define STYLE_TITLE_L 2@@ -499,8 +524,9 @@#define EK_MOSQUITO 25#define EK_FATFLY 26#define EK_MOSSCHARGER 27-#define NUM_KINDS 28-#define KIND_TABLE {{0}, {EF_CRAWLER, {-1, 156, 155, -1, -1, -1, -1, -1, -1, -1, -1, 158, 159}}, {EF_BUZZER, {161, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 163, 164}}, {EF_SHADE, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}}, {EF_CLIMBER, {-1, -1, 171, 170, -1, -1, -1, -1, -1, -1, -1, 168, 169}}, {EF_BOUNCER, {-1, -1, -1, 174, -1, -1, -1, -1, -1, -1, -1, 172, 173}}, {EF_SPITTER, {-1, -1, -1, 177, 178, 176, -1, -1, -1, -1, -1, 175, -1}}, {EF_ROLLER, {181, -1, -1, 183, 182, 184, -1, -1, -1, -1, -1, 179, 180}}, {EF_BLOCKER, {191, -1, -1, 187, 192, 185, 186, 193, 194, 190, 189, -1, 188}}, {EF_HUSK, {200, 201, 202, 195, 197, 196, -1, -1, -1, -1, -1, 198, 199}}, {EF_HUSK, {208, 209, 210, 203, 205, 204, -1, -1, -1, -1, -1, 206, 207}}, {EF_HUSK, {216, 217, 218, 211, 213, 212, -1, -1, -1, -1, -1, 214, 215}}, {EF_HUSK, {224, 225, 226, 219, 221, 220, -1, -1, -1, -1, -1, 222, 223}}, {EF_LEAPER, {230, 232, 233, 227, 231, -1, -1, -1, -1, -1, -1, 228, 229}}, {EF_GUARD, {239, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 236, 237}}, {EF_FK, {261, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 259}}, {EF_FKHEAD, {281, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 279}}, {EF_HATCHER, {-1, -1, -1, 286, 285, -1, -1, -1, -1, -1, -1, 283, 284}}, {EF_HATCHLING, {-1, -1, -1, 287, -1, -1, -1, -1, -1, -1, -1, -1, -1}}, {EF_SLUG, {293, -1, -1, 291, 292, 295, 294, 288, -1, -1, -1, 289, 290}}, {EF_GFLY, {308, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}}, {EF_MOSSWALKER, {-1, 317, 318, 316, 312, 313, -1, -1, -1, -1, -1, 314, 315}}, {EF_PIGEON, {-1, -1, -1, 320, 321, 322, 319, -1, -1, -1, -1, -1, -1}}, {EF_PLANTTRAP, {324, -1, -1, 327, 326, 325, -1, -1, -1, -1, -1, 323, -1}}, {EF_SHAKER, {331, 332, 333, 328, -1, -1, -1, -1, -1, -1, -1, 329, 330}}, {EF_MOSQUITO, {338, -1, -1, 340, 339, 335, 334, -1, -1, -1, -1, 336, 337}}, {EF_FATFLY, {344, -1, -1, 341, -1, -1, -1, -1, -1, -1, -1, 342, 343}}, {EF_MOSSCHARGER, {-1, -1, -1, 345, 346, 349, 352, 351, 353, 350, -1, 347, 348}}}+#define EK_MOSSKNIGHT 28+#define NUM_KINDS 29+#define KIND_TABLE {{0}, {EF_CRAWLER, {-1, 156, 155, -1, -1, -1, -1, -1, -1, -1, -1, 158, 159}}, {EF_BUZZER, {161, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 163, 164}}, {EF_SHADE, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}}, {EF_CLIMBER, {-1, -1, 171, 170, -1, -1, -1, -1, -1, -1, -1, 168, 169}}, {EF_BOUNCER, {-1, -1, -1, 174, -1, -1, -1, -1, -1, -1, -1, 172, 173}}, {EF_SPITTER, {-1, -1, -1, 177, 178, 176, -1, -1, -1, -1, -1, 175, -1}}, {EF_ROLLER, {181, -1, -1, 183, 182, 184, -1, -1, -1, -1, -1, 179, 180}}, {EF_BLOCKER, {191, -1, -1, 187, 192, 185, 186, 193, 194, 190, 189, -1, 188}}, {EF_HUSK, {200, 201, 202, 195, 197, 196, -1, -1, -1, -1, -1, 198, 199}}, {EF_HUSK, {208, 209, 210, 203, 205, 204, -1, -1, -1, -1, -1, 206, 207}}, {EF_HUSK, {216, 217, 218, 211, 213, 212, -1, -1, -1, -1, -1, 214, 215}}, {EF_HUSK, {224, 225, 226, 219, 221, 220, -1, -1, -1, -1, -1, 222, 223}}, {EF_LEAPER, {230, 232, 233, 227, 231, -1, -1, -1, -1, -1, -1, 228, 229}}, {EF_GUARD, {239, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 236, 237}}, {EF_FK, {261, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 259}}, {EF_FKHEAD, {281, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 279}}, {EF_HATCHER, {-1, -1, -1, 286, 285, -1, -1, -1, -1, -1, -1, 283, 284}}, {EF_HATCHLING, {-1, -1, -1, 287, -1, -1, -1, -1, -1, -1, -1, -1, -1}}, {EF_SLUG, {293, -1, -1, 291, 292, 295, 294, 288, -1, -1, -1, 289, 290}}, {EF_GFLY, {308, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}}, {EF_MOSSWALKER, {-1, 317, 318, 316, 312, 313, -1, -1, -1, -1, -1, 314, 315}}, {EF_PIGEON, {-1, -1, -1, 320, 321, 322, 319, -1, -1, -1, -1, -1, -1}}, {EF_PLANTTRAP, {324, -1, -1, 327, 326, 325, -1, -1, -1, -1, -1, 323, -1}}, {EF_SHAKER, {331, 332, 333, 328, -1, -1, -1, -1, -1, -1, -1, 329, 330}}, {EF_MOSQUITO, {338, -1, -1, 340, 339, 335, 334, -1, -1, -1, -1, 336, 337}}, {EF_FATFLY, {344, -1, -1, 341, -1, -1, -1, -1, -1, -1, -1, 342, 343}}, {EF_MOSSCHARGER, {-1, -1, -1, 345, 346, 349, 352, 351, 353, 350, -1, 347, 348}}, {EF_MOSSKNIGHT, {359, 374, 378, -1, -1, -1, -1, -1, -1, -1, -1, 354, 355}}}#define TXT_PROMPT_LISTEN 27#define TXT_PROMPT_REST 28#define TXT_PROMPT_INSPECT 29@@ -618,6 +644,12 @@#define VMSTR_NPC_TITLE 14#define VMSTR_VISITED 127#define VMSTR_DISPLAY_RIGHT 128+#define STR_ATTACK_RANGE 23+#define STR_EVADE_RANGE 50+#define STR_SPIT_RANGE 51+#define STR_WAKE_BOX 52+#define STR_SLASH_HITBOX 53+#define STR_SLASH2_HITBOX 54#define TITLE_KINGSPASS 0#define TITLE_DIRTMOUTH 1#define TITLE_CROSSROADS 2@@ -640,16 +672,17 @@#define TITLE_CHARM_SLUG 19#define NUM_TITLES 20#define TITLE_TABLE {{41, 42, -1, -1}, {43, 44, 45, -1}, {46, 47, -1, 48}, {49, 50, -1, 51}, {52, 53, -1, 54}, {55, 56, -1, -1}, {57, 58, 59, -1}, {60, 61, -1, -1}, {62, 63, -1, -1}, {64, 65, -1, -1}, {66, 67, -1, -1}, {68, 69, -1, -1}, {70, 71, -1, -1}, {72, 73, -1, -1}, {74, 75, -1, 76}, {77, 78, -1, 79}, {77, 78, -1, 80}, {81, 82, 83, -1}, {81, 82, -1, -1}, {84, 85, -1, 86}}-#define SPRITE_FLEUR_TOP 1687+#define SPRITE_FLEUR_TOP 1788#define FLEUR_TOP_RECTS {{0.781f, -0.844f, 0.953f, -0.688f}, {-1.078f, -0.984f, 1.141f, -0.531f}, {-1.281f, -1.016f, 1.313f, -0.484f}, {-1.359f, -1.016f, 1.969f, -0.141f}, {-2.141f, -1.031f, 2.531f, 0.047f}, {-2.250f, -1.078f, 2.766f, 0.266f}, {-2.797f, -1.203f, 3.094f, 0.578f}, {-2.938f, -1.219f, 3.219f, 0.859f}, {-3.203f, -1.234f, 3.469f, 1.141f}, {-3.312f, -1.234f, 3.766f, 1.281f}, {-3.547f, -1.250f, 4.000f, 1.328f}, {-3.844f, -1.250f, 4.016f, 1.328f}, {-4.016f, -1.250f, 4.031f, 1.344f}, {-4.031f, -1.250f, 4.031f, 1.344f}, {-4.047f, -1.250f, 4.031f, 1.359f}, {-4.047f, -1.250f, 4.031f, 1.359f}, {-4.047f, -1.266f, 4.031f, 1.359f}, {-4.047f, -1.266f, 4.031f, 1.359f}, {-4.062f, -1.266f, 4.047f, 1.375f}, {-4.062f, -1.266f, 4.047f, 1.375f}, {-4.062f, -1.266f, 4.047f, 1.375f}, {-4.062f, -1.266f, 4.047f, 1.375f}}#define FLEUR_FRAMES 22#define FLEUR_FPS 15.0f-#define SPRITE_FLEUR_BOT 1688+#define SPRITE_FLEUR_BOT 1789#define FLEUR_BOT_RECTS {{0.000f, 0.000f, 0.016f, 0.016f}, {0.000f, 0.000f, 0.016f, 0.016f}, {0.391f, 0.406f, 0.828f, 0.844f}, {-1.063f, 0.281f, 1.516f, 1.016f}, {-1.594f, -0.047f, 2.109f, 1.031f}, {-1.984f, -0.156f, 2.375f, 1.047f}, {-2.531f, -0.438f, 2.719f, 1.172f}, {-2.688f, -0.594f, 2.766f, 1.188f}, {-2.797f, -0.797f, 3.156f, 1.219f}, {-3.078f, -0.938f, 3.219f, 1.219f}, {-3.250f, -1.156f, 3.438f, 1.219f}, {-3.250f, -1.172f, 3.828f, 1.219f}, {-3.781f, -1.188f, 4.203f, 1.234f}, {-3.984f, -1.188f, 4.344f, 1.234f}, {-4.281f, -1.203f, 4.562f, 1.234f}, {-4.406f, -1.203f, 4.641f, 1.234f}, {-4.578f, -1.219f, 4.719f, 1.234f}, {-4.656f, -1.219f, 4.719f, 1.234f}, {-4.734f, -1.219f, 4.734f, 1.234f}, {-4.750f, -1.234f, 4.734f, 1.234f}, {-4.766f, -1.234f, 4.734f, 1.250f}, {-4.766f, -1.234f, 4.734f, 1.250f}}-#define SPRITE_MSG_BG 1689-#define SPRITE_MSG_STOP 1690-#define SPRITE_MSG_FLEUR 1691-#define SPRITE_MSG_KEY 1692-#define SPRITE_MSG_ICON_FIREBALL 1693+#define SPRITE_MSG_BG 1790+#define SPRITE_MSG_STOP 1791+#define SPRITE_MSG_FLEUR 1792+#define SPRITE_MSG_KEY 1793+#define SPRITE_MSG_ICON_FIREBALL 1794+#define SPRITE_GRASS_BALL 1795#define MSG_TABLE {{87, 88, 89, 90, 91, 92}}#define MSG_FIREBALL 0diff --git a/games/hollowknight/src/enemy.c b/games/hollowknight/src/enemy.cindex 8048eb16..7185151a 100644--- a/games/hollowknight/src/enemy.c+++ b/games/hollowknight/src/enemy.c@@ -17,7 +17,7 @@enum {EF_CRAWLER = 1, EF_BUZZER, EF_SHADE, EF_HUSK, EF_CLIMBER, EF_BOUNCER, EF_SPITTER, EF_ROLLER, EF_BLOCKER, EF_LEAPER, EF_GUARD,EF_FK, EF_FKHEAD, EF_GFLY, EF_HATCHER, EF_HATCHLING, EF_SLUG, EF_MOSSWALKER, EF_PIGEON, EF_PLANTTRAP, EF_SHAKER,- EF_MOSQUITO, EF_FATFLY, EF_MOSSCHARGER+ EF_MOSQUITO, EF_FATFLY, EF_MOSSCHARGER, EF_MOSSKNIGHT};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 {@@ -69,6 +69,7 @@ typedef struct {/* SpriteFlash (flashInfected) */float flash_t;bool flashing;+ uint8_t c2, c3, c4; /* (more counters) *//* 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) */@@ -80,7 +81,8 @@ typedef struct {/* alert range (local circle, or box: ar_hy >= 0) and sight */float ar_x, ar_y, ar_r, ar_hy;bool in_alert, can_see;- float cbox_ox, cbox_oy, cbox_hx, cbox_hy; /* its collider */+ uint8_t inv_dir; /* (HealthManager.invincibleFromDirection) */+ uint8_t fx; /* (an effect its sub sprite plays, + 1) */} Enemy;static Enemy en[MAX_ENEMIES];static uint32_t swing_bits; /* (a bit an enemy: hit this swing) */@@ -400,6 +402,20 @@ static void enemy_die(Enemy *e, float direction, bool has_direction) {FREEZE_MOMENT_1();}+/* HealthManager.IsBlockingByDirection: invincible, from every way or from some (a spell gets through to what is Spell+ * Vulnerable) */+static bool blocking_by_direction(const Enemy *e, int dir, bool nail) {+ if (!(e->flags & 4)) return false;+ if (!nail && FSM(e) == EF_MOSSKNIGHT && (e->c4 & 0x80)) return false;+ int d = e->inv_dir;+ switch (dir) {+ case 0: return d == 0 || d == 1 || d == 5 || d == 8 || d == 10;+ case 1: return d == 0 || d == 2 || (d >= 5 && d <= 9);+ case 2: return d == 0 || d == 3 || d == 6 || d == 9 || d == 11;+ default: return d == 0 || d == 4 || (d >= 7 && d <= 11);+ }+}+/* HealthManager.Hit (a nail's): evasion, damage, recoil, flash, soul */static void blocker_hit(Enemy *e);static void fk_head_hit(void);@@ -409,7 +425,7 @@ static void enemy_hit_by(Enemy *e, float direction, int damage, bool nail, floatif (e->mode != EM_ALIVE || e->evasion > 0 || damage <= 0) return;int dir = cardinal(direction);e->rc_flags = (uint8_t)((e->rc_flags & ~(3 << RF_DIR_SHIFT)) | dir << RF_DIR_SHIFT); /* (directionOfLastAttack) */- if (e->flags & 4) {+ if (blocking_by_direction(e, dir, nail)) {/* Invincible: the hit blocked (BLOCKED HIT), the Knight recoiling off it (a nail's) */e->rc_flags |= RF_BLOCKED;if (nail && dir == 0) hero_recoil_left();@@ -1002,7 +1018,9 @@ static void distance_fly_at(Enemy *e, float dist, float vmax, float accel, bool#define MAX_BULLETS 8typedef struct {bool on, active;+ uint8_t kind; /* (0 a spit shot, 1 a Moss Knight's grass ball) */float x, y, vx, vy, scale, ang, gravity;+ float spin, age; /* (a grass ball's: degrees a second, its time) */Anim anim;} Bullet;static Bullet bullets[MAX_BULLETS];@@ -1044,7 +1062,23 @@ static void bullet_fire(float x, float y, float speed) {anim_play(&b->anim, CLIP_BULLET_IDLE);}+/* a Moss Knight's Grass Ball (grass ball control, SpinSelf): from (x, y) at a velocity, falling */+#define GRASS_BALL_R 0.4f+static void grass_ball_spawn(float x, float y, float vx, float vy) {+ Bullet *b = bullet_new(x, y, vx, vy, 1);+ if (!b) return;+ b->kind = 1;+ b->ang = rand_range(0, 360);+ b->spin = vx * 15 / (0.5f * GRASS_BALL_R * GRASS_BALL_R) * DT * 180 / (float)M_PI; /* (its one push of torque) */+}+static void bullet_impact(Bullet *b) {+ if (b->kind == 1) {+ /* (Break: gone, with a shake) */+ cam_shake(SHAKE_ENEMY_KILL);+ b->on = false;+ return;+ }b->active = false;b->vx = b->vy = 0;anim_play_from_frame(&b->anim, CLIP_BULLET_IMPACT, 0);@@ -1063,6 +1097,18 @@ static void bullets_tick(void) {b->vy += -60 * b->gravity * DT; /* (its Rigidbody2D's gravity) */float dx = b->vx * DT, dy = b->vy * DT, l = sqrtf(dx * dx + dy * dy);PhysHit hit;+ if (b->kind == 1) {+ /* (its circle meets the terrain: Break; its scale tweened up from half in 0.1 s) */+ b->age += DT;+ b->scale = b->age < 0.1f ? 0.5f + 5 * b->age : 1;+ b->ang += b->spin * DT;+ b->x += dx, b->y += dy;+ if (phys_ray(b->x - GRASS_BALL_R, b->y, 1, 0, 2 * GRASS_BALL_R, CF_TERRAIN, NULL) ||+ phys_ray(b->x, b->y - GRASS_BALL_R, 0, 1, 2 * GRASS_BALL_R, CF_TERRAIN, NULL))+ bullet_impact(b);+ if (b->y < -10) b->on = false;+ continue;+ }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;@@ -1081,6 +1127,7 @@ static int bullets_touch_hero(float x0, float y0, float x1, float y1, int *side)Bullet *b = &bullets[i];if (!b->on || !b->active) continue;float hx = BULLET_HX * b->scale, hy = BULLET_HY * b->scale;+ if (b->kind == 1) hx = hy = GRASS_BALL_R * 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);@@ -1094,10 +1141,15 @@ static void bullets_draw(void) {for (int i = 0; i < MAX_BULLETS; i++) {const Bullet *b = &bullets[i];if (!b->on) continue;+ Inst in;+ if (b->kind == 1) {+ sprite_inst_rot(SPRITE_GRASS_BALL, b->x, b->y, -0.01f, b->scale, b->scale, b->ang, 0, &in);+ gfx_actor(&in, SORT_KEY(0, 0));+ 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));}@@ -4788,6 +4840,383 @@ static void mosscharger_update(Enemy *e) {}}+/* ---------------------------------------------------------------- Moss Knights: Moss Knight Control (a Walker; with the+ * Knight in its Attack Range it raises its shield against where he is, then slashes (once or twice), jumps back, or+ * spits grass balls; some sleep in the moss till struck or till their battle starts) */+enum { MK_PAUSE, MK_DETECT, MK_SHIELD, MK_BLOCK, MK_UNSHIELD, MK_A1_ANTIC, MK_A1_LUNGE, MK_A1_ON, MK_A1_OFF, MK_A1_END,+ MK_A2_ANTIC, MK_A2_SLASH, MK_A2_END, MK_SLASH_END, MK_EVADE_ANTIC, MK_EVADE, MK_EVADE_END, MK_SHOOT_ANTIC, MK_SHOOT,+ MK_SHOT_END, MK_SLEEP, MK_SHAKE, MK_WAKE };+enum { MKS_RIGHT_LOW, MKS_RIGHT_HIGH, MKS_LEFT_HIGH, MKS_LEFT_LOW };+enum { MKF_SPIT = 1, MKF_QUICK = 2, MKF_LOW6 = 4 }; /* (c4: After Evade SPIT, Slash Quick, Low Block Direction 6) */+#define MK_DORMANT 1+#define MK_START_BATTLE 4+#define MK_EFFECT_SLASH2 1 /* (its effect's sprite: Slash2 Effect's place) */+/* (c0: its shield; c1: Shot Repeats; c2: Ct Slash, Ct Jump Back; c3: Ct Single, Ct Double (2 bits each); c4: MKF_*;+ * qx: Attack Pause; qy: Lunge1 Speed; ax: Evade Speed; ay: Spit X; t0, t1: its Spit and Evade Ranges' on (> 0) or off+ * (< 0) time left; sub: its slash effect, fx its kind + 1 (drawn while it plays)) */++/* a named range of its own (ET_RANGE by its child's name): the Knight in it? */+static bool mk_in(const Enemy *e, int name) {+ const Ent *d = ent_at(e->ent);+ for (int i = 1; i <= d->s0; i++)+ if (d[i].type == ENT_BOX && d[i].flags == ET_RANGE && d[i].s0 == name) {+ float x, y, rx, hy;+ enemy_range(e, &d[i], &x, &y, &rx, &hy);+ const Body *h = &g_hero.body;+ return !g_hero.hidden && fabsf(h->x + h->ox - e->body.x - x) < rx + h->hx && fabsf(h->y + h->oy - e->body.y - y) < hy + h->hy;+ }+ return false;+}+static bool mk_attack_range(const Enemy *e) { return mk_in(e, STR_ATTACK_RANGE); }+static bool mk_evade_range(const Enemy *e) { return e->t1 > 0 && mk_in(e, STR_EVADE_RANGE); }+static bool mk_spit_range(const Enemy *e) { return e->t0 > 0 && mk_in(e, STR_SPIT_RANGE); }+/* (LineOfSightDetector: the Knight in any of its ranges, nothing between) */+static bool mk_sees(const Enemy *e) {+ if (!(e->in_alert || mk_attack_range(e) || mk_evade_range(e) || mk_spit_range(e))) return false;+ float dx = hero_x() - e->body.x, dy = hero_y() - e->body.y, l = sqrtf(dx * dx + dy * dy);+ return l < 1e-4f || !phys_ray(e->body.x, e->body.y, dx / l, dy / l, l, CF_TERRAIN, NULL);+}++static const Ent *mk_vars(const Enemy *e) {+ const Ent *v = enemy_rec(e, ET_VARS);+ return v;+}++/* SendRandomEventV2: of two, by weight, neither more than its most in a row (2-bit counts in *ct) */+static int random_v2(uint8_t *ct, float w0, int max0, int max1) {+ for (;;) {+ int k = rand_range(0, 1) < w0 ? 0 : 1, n = (*ct >> (2 * k)) & 3;+ if (n < (k ? max1 : max0)) {+ *ct = (uint8_t)((n + 1) << (2 * k));+ return k;+ }+ }+}++static void mk_slash_effect(Enemy *e, int clip, int kind) {+ anim_play_from_frame(&e->sub, clip, 0);+ e->fx = (uint8_t)(kind + 1);+}++/* a child's Randomise: its collider on for a while, then off (on: t > 0, the time left; off: t < 0) */+static void randomise(float *t, float on0, float on1, float off0, float off1) {+ if (*t > 0) {+ if ((*t -= DT) <= 0) *t = -rand_range(off0, off1);+ } else if ((*t += DT) >= 0)+ *t = rand_range(on0, on1);+}++static void mk_hitbox(Enemy *e, int name, bool on) {+ for (int k = 0; k < 8; k++) {+ const Ent *h = hitbox_rec(e, k);+ if (!h) break;+ if (h->s0 == name) e->hb_on = on ? (uint8_t)(e->hb_on | 1 << k) : (uint8_t)(e->hb_on & ~(1 << k));+ }+}++/* Reset: the shield's directions gone (its invincibility as it was), walking; Detect */+static void mk_reset(Enemy *e) {+ e->inv_dir = 0;+ e->st = MK_DETECT;+ walker_start(e);+}++/* the shield its stance shows (Shield Right / Left, High / Low) */+static void mk_shield(Enemy *e, int s) {+ static const uint8_t inv[4] = {6, 4, 4, 5};+ bool right = s == MKS_RIGHT_LOW || s == MKS_RIGHT_HIGH, high = s == MKS_RIGHT_HIGH || s == MKS_LEFT_HIGH;+ e->st = MK_SHIELD, e->c0 = (uint8_t)s;+ e->c4 = (uint8_t)((e->c4 & ~MKF_LOW6) | (right ? MKF_LOW6 : 0));+ e->inv_dir = inv[s];+ e->wk_facing = right ? 1 : -1; /* (SetWalkerFacing) */+ anim_play_from_frame(&e->anim, high ? CLIP_MOSSKNIGHT_SHIELD_TOP : CLIP_MOSSKNIGHT_SHIELD_FRONT, 0);+ e->qy = right ? 11 : -11;+ set_scale_x(e, right ? -fabsf(e->sx) : fabsf(e->sx));+}++/* (where the Knight is: right of it, above its middle) */+static bool mk_hero_right(const Enemy *e) { return hero_x() > e->body.x; }+static bool mk_hero_left(const Enemy *e) { return hero_x() < e->body.x; }+static bool mk_hero_high(const Enemy *e) { return hero_y() > e->body.y + 2.5f; }++static void mk_attack1(Enemy *e) {+ /* Attack 1 Antic: its slash (or the quick one) and its effect; its shield's low side still up */+ bool quick = (e->c4 & MKF_QUICK) != 0;+ e->st = MK_A1_ANTIC;+ anim_play_from_frame(&e->anim, quick ? CLIP_MOSSKNIGHT_SLASH_QUICK : CLIP_MOSSKNIGHT_SLASH, 0);+ mk_slash_effect(e, quick ? CLIP_MOSSKNIGHT_SLASH_EFFECT_QUICK : CLIP_MOSSKNIGHT_SLASH_EFFECT, 0);+ e->inv_dir = (e->c4 & MKF_LOW6) ? 6 : 5;+}++/* Attack Choice: a slash, or a jump back (then a spit or a slash) */+static void mk_evade_check(Enemy *e);+static void mk_attack_choice(Enemy *e) {+ e->body.vx = 0;+ e->c4 &= (uint8_t)~MKF_QUICK;+ if (random_v2(&e->c2, 0.75f, 3, 2) == 0) mk_attack1(e);+ else {+ /* After Evade Choice: then a spit or a slash, even odds */+ if (rand_range(0, 2) < 1) e->c4 |= MKF_SPIT;+ else e->c4 &= (uint8_t)~MKF_SPIT;+ mk_evade_check(e);+ }+}++/* Shoot Check: not invincible; a spit at the Knight, facing him */+static void mk_shoot_check(Enemy *e) {+ e->flags &= (uint8_t)~4;+ e->c1--;+ anim_play_from_frame(&e->anim, CLIP_MOSSKNIGHT_SHOOT, 0);+ if (mk_hero_right(e)) set_scale_x(e, -fabsf(e->sx));+ else if (mk_hero_left(e)) set_scale_x(e, fabsf(e->sx));+ /* Shoot Antic: where it aims */+ float x = (hero_x() - e->body.x) * 1.1f + rand_range(-1, 1);+ e->ay = x < -15 ? -15 : x > 15 ? 15 : x;+ e->st = MK_SHOOT_ANTIC;+}++static void mk_set_repeater(Enemy *e) {+ e->body.vx = 0;+ walker_stop(e, STOP_CONTROLLED);+ e->c1 = 2;+ mk_shoot_check(e);+}++/* Evade Check: not invincible; away from the Knight, unless a wall is behind (Evade Cancel) */+static void mk_evade_check(Enemy *e) {+ e->body.vx = 0;+ e->flags &= (uint8_t)~4;+ anim_play_from_frame(&e->anim, CLIP_MOSSKNIGHT_EVADE, 0);+ bool right = mk_hero_right(e);+ if (!right && !mk_hero_left(e)) {+ e->st = MK_EVADE_ANTIC; /* (neither: it stays there) */+ return;+ }+ bool wall = phys_ray(e->body.x, e->body.y, -1, 0, 4, CF_TERRAIN, NULL); /* (from its Centre Point, to its own left) */+ set_scale_x(e, right ? -fabsf(e->sx) : fabsf(e->sx));+ e->ax = right ? -28 : 28;+ e->qy = right ? 13 : -13;+ if (wall) {+ /* Evade Cancel: a spit's evade slashes; a slash's evades all the same */+ if (e->c4 & MKF_SPIT) mk_attack1(e);+ else e->st = MK_EVADE_ANTIC;+ return;+ }+ e->st = MK_EVADE_ANTIC;+}++static void mossknight_wake(Enemy *e) {+ /* Shake, then Wake */+ if (e->st != MK_SLEEP) return;+ e->st = MK_SHAKE, e->wait = 1;+ anim_play(&e->anim, CLIP_MOSSKNIGHT_SHAKE);+}++static void mossknight_start(Enemy *e) {+ walker_init(e);+ e->t0 = rand_range(1, 2), e->t1 = rand_range(2, 2.5f); /* (its ranges' Randomise: On) */+ const Ent *v = mk_vars(e);+ if (v && (v->a & MK_DORMANT)) {+ /* Sleep: kinematic, harmless, untouchable, in the moss */+ e->st = MK_SLEEP;+ walker_stop(e, STOP_CONTROLLED);+ anim_play(&e->anim, rand_range(0, 2) < 1 ? CLIP_MOSSKNIGHT_DORMANT_1 : CLIP_MOSSKNIGHT_DORMANT_2);+ e->flags |= 4 | 1;+ e->inv_dir = 0;+ e->damage = 0;+ e->body.vx = e->body.vy = 0, e->body.gravity_scale = 0;+ } else+ e->st = MK_PAUSE;+}++/* (its Wake Box struck by the nail, the Knight near it: it wakes, or its battle starts) */+static void mossknight_nailed(Enemy *e) {+ if (e->st != MK_SLEEP || fabsf(hero_x() - e->body.x) >= 8) return;+ const Ent *v = mk_vars(e);+ if (v && (v->a & MK_START_BATTLE)) arena_start(); /* (BATTLE EARLY START) */+ else mossknight_wake(e);+}++static void mossknight_update(Enemy *e) {+ bool done = (e->anim.events & ANIM_DONE) != 0, trig = (e->anim.events & ANIM_TRIGGER) != 0;+ /* its Spit and Evade Ranges' Randomise: on 1-2 s, off 1-2 s; on 2-2.5 s, off 2.5-3.5 s */+ randomise(&e->t0, 1, 2, 1, 2);+ randomise(&e->t1, 2, 2.5f, 2.5f, 3.5f);+ if (e->fx) {+ e->sub.events = 0;+ anim_update(&e->sub, DT);+ if (!e->sub.playing) e->fx = 0;+ }+ switch (e->st) {+ case MK_PAUSE:+ e->st = MK_DETECT; /* (Pause Frame, Initialise) */+ break;+ case MK_DETECT: {+ walker_update(e);+ bool see = mk_sees(e), spit = mk_spit_range(e), evade = mk_evade_range(e), attack = see && mk_attack_range(e);+ /* (the frame's last event wins: ATTACK, EVADE, SPIT) */+ if (attack) {+ /* Shield Start: its pause before it attacks, still and invincible; then its stance */+ e->qx = rand_range(0.75f, 1.1f);+ walker_stop(e, STOP_CONTROLLED);+ e->body.vx = 0;+ e->flags |= 4;+ bool right = mk_hero_right(e), high = mk_hero_high(e);+ mk_shield(e, high && right ? MKS_RIGHT_HIGH : high ? MKS_LEFT_HIGH : right ? MKS_RIGHT_LOW : MKS_LEFT_LOW);+ } else if (evade) {+ walker_stop(e, STOP_CONTROLLED);+ e->c4 &= (uint8_t)~MKF_SPIT, e->c4 |= MKF_QUICK; /* (Evade Hero: then a quick slash) */+ mk_evade_check(e);+ } else if (spit)+ mk_set_repeater(e);+ break;+ }+ case MK_SHIELD: {+ if (e->rc_flags & RF_BLOCKED) {+ /* Block: its shield bumped, then its attack */+ bool high = e->c0 == MKS_RIGHT_HIGH || e->c0 == MKS_LEFT_HIGH;+ anim_play_from_frame(&e->anim, high ? CLIP_MOSSKNIGHT_SHIELD_TOP_BUMP : CLIP_MOSSKNIGHT_SHIELD_FRONT_BUMP, 0);+ e->st = MK_BLOCK, e->wait = 0.4f;+ break;+ }+ bool left = mk_hero_left(e), right = mk_hero_right(e), high = mk_hero_high(e), low = !high;+ int s = e->c0, to = -1;+ /* (the other stances' events, in its actions' order; the last of the frame wins) */+ if (s != MKS_LEFT_HIGH && high && left) to = MKS_LEFT_HIGH;+ if (s != MKS_RIGHT_HIGH && high && right) to = MKS_RIGHT_HIGH;+ if (s != MKS_LEFT_LOW && low && left) to = MKS_LEFT_LOW;+ if (s != MKS_RIGHT_LOW && low && right) to = MKS_RIGHT_LOW;+ int ev = to >= 0 ? 1 : 0; /* (1 a stance, 2 COUNTER END, 3 LEFT RANGE, 4 EVADE) */+ if ((e->qx -= DT) <= 0) ev = 2;+ if (!(mk_attack_range(e) && mk_sees(e))) ev = 3;+ if (mk_evade_range(e)) ev = 4;+ if (ev == 1) mk_shield(e, to);+ else if (ev == 2) mk_attack_choice(e);+ else if (ev == 3) {+ /* Unshield: its shield down, then Reset */+ bool hi = s == MKS_RIGHT_HIGH || s == MKS_LEFT_HIGH;+ anim_play_from_frame(&e->anim, hi ? CLIP_MOSSKNIGHT_UNSHIELD_TOP : CLIP_MOSSKNIGHT_UNSHIELD_FRONT, 0);+ e->st = MK_UNSHIELD;+ } else if (ev == 4) {+ e->c4 &= (uint8_t)~MKF_SPIT, e->c4 |= MKF_QUICK;+ mk_evade_check(e);+ }+ break;+ }+ case MK_BLOCK:+ if ((e->wait -= DT) <= 0) mk_attack_choice(e);+ break;+ case MK_UNSHIELD:+ if (!e->anim.playing) mk_reset(e);+ break;+ case MK_A1_ANTIC:+ if (trig) {+ /* Attack1 Lunge: vulnerable, lunging at the Knight */+ e->flags &= (uint8_t)~4, e->inv_dir = 0;+ e->body.vx = e->qy;+ e->st = MK_A1_LUNGE;+ }+ break;+ case MK_A1_LUNGE:+ if (trig) mk_hitbox(e, STR_SLASH_HITBOX, true), e->st = MK_A1_ON;+ break;+ case MK_A1_ON:+ if (trig) mk_hitbox(e, STR_SLASH_HITBOX, false), e->st = MK_A1_OFF;+ break;+ case MK_A1_OFF:+ if (trig) e->body.vx = 0, e->st = MK_A1_END;+ break;+ case MK_A1_END:+ if (!e->anim.playing) {+ /* Slash 2?: facing the Knight still, a second slash or not */+ bool face_right = e->sx < 0, hero_right = mk_hero_right(e);+ if (hero_right != face_right || random_v2(&e->c3, 0.5f, 2, 2) == 1) {+ e->st = MK_SLASH_END;+ anim_play_from_frame(&e->anim, CLIP_MOSSKNIGHT_SLASH_END, 0);+ } else {+ e->st = MK_A2_ANTIC;+ anim_play_from_frame(&e->anim, CLIP_MOSSKNIGHT_SLASH_2, 0);+ mk_slash_effect(e, CLIP_MOSSKNIGHT_SLASH_2_EFFECT, MK_EFFECT_SLASH2);+ }+ }+ break;+ case MK_A2_ANTIC:+ if (trig) {+ mk_hitbox(e, STR_SLASH2_HITBOX, true);+ e->body.vx = e->qy;+ e->st = MK_A2_SLASH;+ }+ break;+ case MK_A2_SLASH:+ if (trig) {+ mk_hitbox(e, STR_SLASH2_HITBOX, false);+ e->body.vx = 0;+ e->st = MK_A2_END;+ }+ break;+ case MK_A2_END:+ case MK_SLASH_END:+ case MK_SHOT_END:+ if (!e->anim.playing) mk_reset(e);+ break;+ case MK_EVADE_ANTIC:+ if (trig) e->body.vx = e->ax, e->st = MK_EVADE;+ break;+ case MK_EVADE:+ if (trig) e->body.vx = 0, e->st = MK_EVADE_END;+ break;+ case MK_EVADE_END:+ if (!e->anim.playing) {+ /* Evade Move Check: its After Evade */+ if (e->c4 & MKF_SPIT) mk_set_repeater(e);+ else mk_attack1(e);+ }+ break;+ case MK_SHOOT_ANTIC:+ if (trig) {+ /* Shoot: a grass ball from its Shot Point, up and at the Knight */+ grass_ball_spawn(e->body.x + (e->sx < 0 ? 2.07f : -2.07f), e->body.y + 1.17f, e->ay, 20);+ e->st = MK_SHOOT;+ }+ break;+ case MK_SHOOT:+ if (!e->anim.playing) {+ /* Repeat Check */+ if (e->c1 == 0 || rand_range(0, 1) < 0.6f) {+ e->st = MK_SHOT_END;+ anim_play_from_frame(&e->anim, CLIP_MOSSKNIGHT_SHOOT_END, 0);+ } else+ mk_shoot_check(e);+ }+ break;+ case MK_SLEEP:+ break;+ case MK_SHAKE:+ if ((e->wait -= DT) <= 0) {+ /* Wake: up, harmless no more; its Spit Range off a while (To Off) */+ e->st = MK_WAKE;+ cam_shake(SHAKE_ENEMY_KILL);+ e->t0 = -1 - rand_range(1, 2);+ anim_play_from_frame(&e->anim, CLIP_MOSSKNIGHT_WAKE, 0);+ e->flags &= (uint8_t)~(4 | 1);+ e->c4 |= 0x80; /* (Spell Vulnerable) */+ e->damage = 1;+ e->body.gravity_scale = 1;+ }+ break;+ case MK_WAKE:+ if (done) mk_reset(e);+ break;+ }+}++static void mossknight_fixed(Enemy *e) {+ if (e->st == MK_DETECT && e->wk_state == WK_WALKING) {+ const Ent *w = walker_rec(e);+ if (w) e->body.vx = e->wk_facing > 0 ? w->y0 : w->x0;+ }+}+/* the collisions a step brought (Collision2dEvent, ObjectBounce): the kinds that want them */static BodyEvent body_events[MAX_EVENTS];static bool wants_contacts(const Enemy *e) { return FSM(e) == EF_MOSQUITO || FSM(e) == EF_FATFLY || FSM(e) == EF_MOSSCHARGER; }@@ -4841,6 +5270,7 @@ static void enemy_fsm_start(Enemy *e, const Ent *d) {else if (FSM(e) == EF_MOSQUITO) mosquito_start(e, d);else if (FSM(e) == EF_FATFLY) fatfly_start(e);else if (FSM(e) == EF_MOSSCHARGER) mosscharger_start(e);+ else if (FSM(e) == EF_MOSSKNIGHT) mossknight_start(e);}/* ActiveRegion (a 50 by 35 box round the camera) meets its collider: FSMActivator turns its FSMs on */@@ -4882,7 +5312,9 @@ void enemies_summon(void) {}void enemies_battle_start(void) {- /* (BATTLE START: no kind of a plain arena's listens yet; the False Knight's arena is its own) */+ /* (BATTLE START, to all: sleeping Moss Knights wake) */+ for (int i = 0; i < MAX_ENEMIES; i++)+ if (en[i].mode == EM_ALIVE && FSM(&en[i]) == EF_MOSSKNIGHT) mossknight_wake(&en[i]);}static void summons_tick(void) {@@ -5050,6 +5482,7 @@ void enemies_fixed(void) {else if (FSM(e) == EF_MOSQUITO) mosquito_fixed(e);else if (FSM(e) == EF_FATFLY) fatfly_fixed(e);else if (FSM(e) == EF_MOSSCHARGER) mosscharger_fixed(e);+ else if (FSM(e) == EF_MOSSKNIGHT) mossknight_fixed(e);recoil_fixed(e);if (wants_contacts(e)) {float pvx = e->body.vx, pvy = e->body.vy, box[4];@@ -5147,10 +5580,13 @@ void enemies_update(void) {else if (FSM(e) == EF_MOSQUITO) mosquito_update(e);else if (FSM(e) == EF_FATFLY) fatfly_update(e);else if (FSM(e) == EF_MOSSCHARGER) mosscharger_update(e);+ else if (FSM(e) == EF_MOSSKNIGHT) mossknight_update(e);if (FSM(e) == EF_FK) {/* (its Hitter: on till its FSM turns it off) */e->sub.events = 0;if (e->sub_hb) anim_update(&e->sub, DT);+ } else if (FSM(e) == EF_MOSSKNIGHT) {+ /* (its hitboxes its own; its effect updated with it) */} elsehitbox_tick(e);e->flags &= (uint8_t)~8;@@ -5190,6 +5626,13 @@ void enemies_draw(void) {sprite_inst(e->sub.sprite, e->body.x, e->body.y, z - 0.001f, e->sx, sy, flash_tint(e, 2 + i % 5), &in);gfx_actor(&in, SORT_KEY(0, 0));}+ if (FSM(e) == EF_MOSSKNIGHT && e->fx && e->sub.sprite >= 0 && e->mode == EM_ALIVE) {+ /* (Slash Effect at it; Slash2 Effect at its child's place and scale) */+ bool s2 = e->fx == 1 + MK_EFFECT_SLASH2;+ sprite_inst(e->sub.sprite, e->body.x + (s2 ? (e->sx < 0 ? 1.14f : -1.14f) : 0), e->body.y + (s2 ? -0.59f : 0), z - 0.001f,+ e->sx * (s2 ? 0.7655f : 1), sy, flash_tint(e, 2 + i % 5), &in);+ gfx_actor(&in, SORT_KEY(0, 0));+ }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));@@ -5226,8 +5669,58 @@ void enemies_hero_cast_spell(void) {}/* the slash's shape: enemies it touches are hit, once a swing -> HB_* */-int enemies_nail(const float *pts, int npts, float direction, int damage) {+/* the slash's shape's bounds */+static void shape_bounds(const float *pts, int n, float *x0, float *y0, float *x1, float *y1) {+ *x0 = *x1 = pts[0], *y0 = *y1 = pts[1];+ for (int k = 1; k < n; k++) {+ *x0 = fminf(*x0, pts[2 * k]), *x1 = fmaxf(*x1, pts[2 * k]);+ *y0 = fminf(*y0, pts[2 * k + 1]), *y1 = fmaxf(*y1, pts[2 * k + 1]);+ }+}++/* the Moss Knights' own: its Wake Box struck, its slash met (a parry: the Knight thrown back, unhurt a moment) */+static int mossknights_nail(const float *pts, int npts) {int out = 0;+ float x0, y0, x1, y1;+ shape_bounds(pts, npts, &x0, &y0, &x1, &y1);+ for (int i = 0; i < MAX_ENEMIES; i++) {+ Enemy *e = &en[i];+ if (e->mode != EM_ALIVE || FSM(e) != EF_MOSSKNIGHT) continue;+ if (e->st == MK_SLEEP) {+ const Ent *d = ent_at(e->ent);+ for (int k = 1; k <= d->s0; k++)+ if (d[k].type == ENT_BOX && d[k].flags == ET_RANGE && d[k].s0 == STR_WAKE_BOX) {+ float cx, cy, rx, hy;+ enemy_range(e, &d[k], &cx, &cy, &rx, &hy);+ cx += e->body.x, cy += e->body.y;+ if (box_meets_shape(cx - rx, cy - hy, cx + rx, cy + hy, pts, npts)) mossknight_nailed(e);+ }+ continue;+ }+ if (e->hb_on && hitbox_touch(e, x0, y0, x1, y1)) {+ FREEZE_MOMENT_1();+ cam_shake(SHAKE_ENEMY_KILL);+ hero_nail_parry();+ out |= HB_BOUNCE | HB_RECOIL;+ }+ }+ return out;+}++/* grass balls the nail or a spell meets: Break */+static void grass_balls_hit(float x0, float y0, float x1, float y1) {+ for (int i = 0; i < MAX_BULLETS; i++) {+ Bullet *b = &bullets[i];+ float r = GRASS_BALL_R * b->scale;+ if (b->on && b->kind == 1 && x1 > b->x - r && x0 < b->x + r && y1 > b->y - r && y0 < b->y + r) bullet_impact(b);+ }+}++int enemies_nail(const float *pts, int npts, float direction, int damage) {+ int out = mossknights_nail(pts, npts);+ float bx0, by0, bx1, by1;+ shape_bounds(pts, npts, &bx0, &by0, &bx1, &by1);+ grass_balls_hit(bx0, by0, bx1, by1);barrels_nail(pts, npts, direction);for (int i = 0; i < MAX_ENEMIES; i++) {Enemy *e = &en[i];@@ -5245,6 +5738,7 @@ int enemies_nail(const float *pts, int npts, float direction, int damage) {uint32_t enemies_spell(float x0, float y0, float x1, float y1, float direction, int damage, float magnitude, uint32_t done) {uint32_t out = 0;+ grass_balls_hit(x0, y0, x1, y1);for (int i = 0; i < MAX_ENEMIES; i++) {Enemy *e = &en[i];if (e->mode != EM_ALIVE || (e->flags & 17) || (done >> i & 1)) continue;diff --git a/games/hollowknight/src/game.h b/games/hollowknight/src/game.hindex 3a8ad2cb..96e4a7cf 100644--- a/games/hollowknight/src/game.h+++ b/games/hollowknight/src/game.h@@ -198,6 +198,7 @@ typedef struct {bool touching_wall_l, touching_wall_r;bool hidden, hit_buffered, enter_without_input;float prevent_cast; /* (PreventCastByDialogueEnd: casts kept back a moment) */+ float parry_t; /* (NailParry: unhurt by enemies a moment) */int16_t entry_gate; /* the record of the gate it came in by (-1: none) */int8_t buffered_side, buffered_damage, buffered_hazard;float invuln_freeze, invuln_time, pulse_t, recoil_timer2, respawn_timer, wake_timer;@@ -218,6 +219,7 @@ void hero_update(void); /* then Update and the animations */void hero_draw(void);bool hero_touching_ground(void);void hero_recoil_left(void);+void hero_nail_parry(void); /* (NailParry) */void hero_recoil_right(void);void hero_recoil_down(void);void hero_bounce(void);diff --git a/games/hollowknight/src/hero.c b/games/hollowknight/src/hero.cindex 5e760a80..4cd5aa06 100644--- a/games/hollowknight/src/hero.c+++ b/games/hollowknight/src/hero.c@@ -285,6 +285,9 @@ static void do_attack(void) {h->thunk_hit = false;}+/* NailParry: a moment unhurt by what is no hazard */+void hero_nail_parry(void) { g_hero.parry_t = 0.25f; }+void hero_recoil_left(void) {Hero *h = &g_hero;if (!h->cs.recoiling_left && !h->cs.recoiling_right && !h->control_relinquished) {@@ -795,6 +798,7 @@ void hero_fixed(uint32_t keys) {void hero_update(void) {Hero *h = &g_hero;if (h->prevent_cast > 0) h->prevent_cast -= DT;+ if (h->parry_t > 0) h->parry_t -= DT;update();invulnerable_tick();respawn_tick();@@ -1250,6 +1254,7 @@ static void take_health(int damage) {void hero_take_damage(int side, int damage, int hazard) {Hero *h = &g_hero;if (damage <= 0) return;+ if (h->parry_t > 0 && hazard == HAZ_NORMAL) return;if (can_take_damage()) {spell_cancel(); /* (HERO DAMAGED) */vm_broadcast(VMEV_HERO_DAMAGED);diff --git a/games/hollowknight/tools/actors.py b/games/hollowknight/tools/actors.pyindex 381c1b7c..4d0fe120 100644--- a/games/hollowknight/tools/actors.py+++ b/games/hollowknight/tools/actors.py@@ -77,6 +77,12 @@ ENEMY_KINDS = [("fatfly", "Fatty Fly Attack", ("sharedassets147.assets", 98), "FATFLY", {"IDLE": "Fly", "A1": "Attack"}),("mosscharger", "Mossy Control", ("sharedassets139.assets", 37), "MOSSCHARGER",{"A1": "Appear", "A2": "Charge", "A3": "Disappear", "A4": "Stun", "A5": "Get Up", "A6": "TurnRun", "A7": "Escape"}),+ # (Moss Knight: its code plays its clips by name, CLIP_MOSSKNIGHT_*)+ ("mossknight", "Moss Knight Control", ("sharedassets149.assets", 104), "MOSSKNIGHT",+ {"IDLE": "Idle", "WALK": "Walk", "TURN": "Turn"},+ ["Shield Front", "Shield Front Bump", "Shield Top", "Shield Top Bump", "Unshield Front", "Unshield Top", "Slash",+ "Slash Quick", "Slash Effect", "Slash Effect Quick", "Slash 2", "Slash 2 Effect", "Slash End", "Evade", "Shoot",+ "Shoot End", "Wake", "Dormant 1", "Dormant 2", "Shake"]),]ENEMY_CORPSE_LIBS = {} # (name -> its corpse's library, if not its own)diff --git a/games/hollowknight/tools/ents.py b/games/hollowknight/tools/ents.pyindex 3bce1d36..c4d051d8 100644--- a/games/hollowknight/tools/ents.py+++ b/games/hollowknight/tools/ents.py@@ -41,7 +41,10 @@ ENEMY_VARS = {"Zombie Swipe": (["Lunge Speed", "Idle Time"], ["Coward"]),# enemies whose body is a trigger, whose body is only their frames' colliders, and other children that are rangesTRIGGER_BODIES = {"Pigeon"}FRAME_BODIES = {"Plant Trap Control", "Mossy Control"}-RANGES = {"Moss Walker": ("Wake Range",), "Pigeon": ("Hero Range", "Enemy Range"), "Plant Trap Control": ("Detector",)}+RANGES = {"Moss Walker": ("Wake Range",), "Pigeon": ("Hero Range", "Enemy Range"), "Plant Trap Control": ("Detector",),+ "Moss Knight Control": ("Wake Box",)}+# (enemies whose attacks start with their colliders off: those still kept, off)+HITBOXES_OFF = {"Moss Knight Control"}# what follows an enemy's record: ENT_BOX records, taggedET_COLLIDER, ET_ALERT, ET_RANGE, ET_WALKER, ET_RECOIL, ET_CORPSE, ET_VARS, ET_TERRAIN, ET_HITBOX, ET_ZONE, ET_COND, \ET_CONTACT = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11@@ -439,7 +442,7 @@ def _enemy(o, by_id, persist, name, d=None, strings=None, owners=None):q = by_id[ch]qd = next((c.get("v") for c in q["c"] if c.get("class") == "DamageHero" and c.get("v") is not None), None)qc = next((c for c in q["c"] if c["type"] in ("BoxCollider2D", "PolygonCollider2D") and c.get("v") and- c["v"].get("m_IsTrigger") and c["v"].get("m_Enabled", 1)), None)+ c["v"].get("m_IsTrigger") and (c["v"].get("m_Enabled", 1) or fsm.get("name") in HITBOXES_OFF)), None)zone = q["name"] == "Battle Range"if (qd is None and not zone) or qc is None:continue@@ -448,7 +451,8 @@ def _enemy(o, by_id, persist, name, d=None, strings=None, owners=None):nrec = (len(pts) + 3) // 4qd = qd or {"damageDealt": 0, "hazardType": 0}out.append(rec(ENT_BOX, ET_ZONE if zone else ET_HITBOX, box=(min(xs), min(ys), max(xs), max(ys)),- p=(len(pts), qd.get("damageDealt", 1), qd.get("hazardType", 1), 0), a=1 if q["self_active"] else 0,+ p=(len(pts), qd.get("damageDealt", 1), qd.get("hazardType", 1), 0),+ a=1 if q["self_active"] and qc["v"].get("m_Enabled", 1) else 0,group=nrec, s0=strings.id(q["name"]) if strings else 0))for i in range(nrec):t = pts[4 * i:4 * i + 4] + [pts[-1]] * (4 - len(pts[4 * i:4 * i + 4]))@@ -485,6 +489,13 @@ def _enemy(o, by_id, persist, name, d=None, strings=None, owners=None):e, w, g = (kid.get(k, [0, 0]) for k in ("Edge Range", "Wall Range", "Ground Range"))out.append(rec(ENT_BOX, ET_VARS, p=(e[0], e[1], w[0], w[1]), box=(g[0], g[1], 0, 0),a=1 if (var.get("Roams") or [0, False])[1] else 0))+ if fsm.get("name") == "Moss Knight Control":+ # (Dormant, Lakeside; its Wake Box's Start Battle)+ wb = next((by_id[ch] for ch in o.get("children", []) if by_id[ch]["name"] == "Wake Box"), None)+ wf = next((c["fsm"] for c in wb["c"] if c.get("fsm")), {}) if wb else {}+ bits = (1 if (var.get("Dormant") or [0, False])[1] else 0) | (2 if (var.get("Lakeside") or [0, False])[1] else 0) | \+ (4 if (wf.get("vars", {}).get("Start Battle") or [0, False])[1] else 0)+ out.append(rec(ENT_BOX, ET_VARS, a=bits))if fsm.get("name") == "Mozzie":# (its TileDetector: a second box for the terrain, in its own units)q = next((by_id[ch] for ch in o.get("children", []) if by_id[ch]["name"] == "TileDetector"), None)diff --git a/games/hollowknight/tools/pack.py b/games/hollowknight/tools/pack.pyindex 4c0b76e3..d865792b 100644--- a/games/hollowknight/tools/pack.py+++ b/games/hollowknight/tools/pack.py@@ -480,6 +480,9 @@ def main():sr = next(c["v"] for c in o["c"] if c["type"] == "SpriteRenderer")fleurs["SPRITE_MSG_" + name] = SPRITES.id(pmsg, ref or sr["m_Sprite"], max(o["lscale"][:2]), res)fleurs["SPRITE_MSG_ICON_FIREBALL"] = SPRITES.id(unity.scene("Crossroads_ShamanTemple"), [4, 44], 1.5607, hud_res)+ # (a Moss Knight's grass ball: a Unity sprite)+ pgb = unity.prefab("sharedassets149.assets", 34)+ fleurs["SPRITE_GRASS_BALL"] = SPRITES.id(pgb, next(c["v"] for c in pgb["objects"][0]["c"] if c["type"] == "SpriteRenderer")["m_Sprite"], 1)fleurs["MSG_TABLE"] = "{%s}" % ", ".join(msgs)for i, item in enumerate(text.MSGS):fleurs["MSG_" + item] = i@@ -636,6 +639,9 @@ def main():print("room %-26s %5d instances in %2d sectors, %6d packed, ground %d, recs %d" % (r, len(keep), len(blobs), packed + len(hc), len(ground), len(recs)), flush=True)secs["ROOMS"].b += roomssecs["RVAR"].b += rvar+ # (the children enemy.c knows by name)+ str_ids = {n: STRINGS.id(n) for n in ("Attack Range", "Evade Range", "Spit Range", "Wake Box", "Slash Hitbox",+ "Slash2 Hitbox")}secs["STR"].b += STRINGS.blob()secs["TEXT"].b += TEXTS.blob()secs["FONT"].b += TEXTS.fonts()@@ -693,6 +699,8 @@ def main():f.write("#define VMEV_%s %d\n" % (e.upper().replace(" ", "_"), i))for name in ("NPC Title", "Visited", "Display Right"):f.write("#define VMSTR_%s %d\n" % (name.upper().replace(" ", "_"), vm.STR.index[name]))+ for name, i in str_ids.items():+ f.write("#define STR_%s %d\n" % (name.upper().replace(" ", "_"), i))for i, t in enumerate(text.TITLES):f.write("#define TITLE_%s %d\n" % (t, i))f.write("#define NUM_TITLES %d\n#define TITLE_TABLE {%s}\n" % (len(titles), ", ".join(titles)))