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: Baldur and Elder Baldur
Mason Chenff8e12bdf809
diff --git a/games/hollowknight/src/data.bin b/games/hollowknight/src/data.binindex f57db079..8f785226 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 63a18ce1..50475b56 100644--- a/games/hollowknight/src/data.h+++ b/games/hollowknight/src/data.h@@ -230,37 +230,53 @@#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 CLIP_BALDUR_DEATH_AIR 173+#define CLIP_BALDUR_DEATH_LAND 174+#define CLIP_BALDUR_IDLE 175+#define CLIP_BALDUR_ROLL 176+#define CLIP_BALDUR_START 177+#define CLIP_BALDUR_STOP 178+#define CLIP_ELDERBALDUR_CLOSE1 179+#define CLIP_ELDERBALDUR_CLOSE2 180+#define CLIP_ELDERBALDUR_CLOSED 181+#define CLIP_ELDERBALDUR_DEATH 182+#define CLIP_ELDERBALDUR_DEATH_STUN 183+#define CLIP_ELDERBALDUR_HIT 184+#define CLIP_ELDERBALDUR_IDLE 185+#define CLIP_ELDERBALDUR_OPEN 186+#define CLIP_ELDERBALDUR_SHOOT_ANTIC 187+#define CLIP_ELDERBALDUR_SHOOT_CD 188+#define CLIP_HUSK_ATTACK_ANTICIPATE 189+#define CLIP_HUSK_ATTACK_COOLDOWN 190+#define CLIP_HUSK_ATTACK_LUNGE 191+#define CLIP_HUSK_DEATH_AIR 192+#define CLIP_HUSK_DEATH_LAND 193+#define CLIP_HUSK_IDLE 194+#define CLIP_HUSK_TURN 195+#define CLIP_HUSK_WALK 196+#define CLIP_BARGER_ATTACK_ANTICIPATE 197+#define CLIP_BARGER_ATTACK_COOLDOWN 198+#define CLIP_BARGER_ATTACK_LUNGE 199+#define CLIP_BARGER_DEATH_AIR 200+#define CLIP_BARGER_DEATH_LAND 201+#define CLIP_BARGER_IDLE 202+#define CLIP_BARGER_TURN 203+#define CLIP_BARGER_WALK 204+#define CLIP_HORNHEAD_ATTACK_ANTICIPATE 205+#define CLIP_HORNHEAD_ATTACK_COOLDOWN 206+#define CLIP_HORNHEAD_ATTACK_LUNGE 207+#define CLIP_HORNHEAD_DEATH_AIR 208+#define CLIP_HORNHEAD_DEATH_LAND 209+#define CLIP_HORNHEAD_IDLE 210+#define CLIP_HORNHEAD_TURN 211+#define CLIP_HORNHEAD_WALK 212+#define CLIP_BULLET_IDLE 213+#define CLIP_BULLET_IMPACT 214+#define SPRITE_HERO_LIGHT 915+#define SPRITE_DIALOGUE_BACKBOARD 916+#define SPRITE_PROMPT_SHADOW 917+#define SPRITE_CORPSE_NAIL 918+#define SPRITE_DIGIT0 1099#define STYLE_DIALOGUE 0#define STYLE_PROMPT 1#define TEXT_K 1.333333f@@ -271,11 +287,13 @@#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 EK_BALDUR 7+#define EK_ELDERBALDUR 8+#define EK_HUSK 9+#define EK_BARGER 10+#define EK_HORNHEAD 11+#define NUM_KINDS 12+#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_ROLLER, {175, -1, -1, 177, 176, 178, -1, -1, -1, -1, -1, 173, 174}}, {EF_BLOCKER, {185, -1, -1, 181, 186, 179, 180, 187, 188, 184, 183, -1, 182}}, {EF_HUSK, {194, 195, 196, 189, 191, 190, -1, -1, -1, -1, -1, 192, 193}}, {EF_HUSK, {202, 203, 204, 197, 199, 198, -1, -1, -1, -1, -1, 200, 201}}, {EF_HUSK, {210, 211, 212, 205, 207, 206, -1, -1, -1, -1, -1, 208, 209}}}#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 25e03740..bc1f0988 100644--- a/games/hollowknight/src/enemy.c+++ b/games/hollowknight/src/enemy.c@@ -2,15 +2,19 @@* FSM, the corpses they leave and the geo they drop. */#include <math.h>#include "game.h"+#ifdef HOST+#include <stdio.h>+#include <stdlib.h>+#endif#define DT 0.02f-#define MAX_ENEMIES 16+#define MAX_ENEMIES 24#define MAX_GEO 24#define TERRAIN_FRICTION 0.2f /* (the Terrain material; with another, their geometric mean) *//* ---------------------------------------------------------------- what each kind is *//* (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 { EF_CRAWLER = 1, EF_BUZZER, EF_SHADE, EF_HUSK, EF_CLIMBER, EF_BOUNCER, EF_SPITTER, EF_ROLLER, EF_BLOCKER };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;@@ -21,7 +25,7 @@ static const Kind kinds[NUM_KINDS] = KIND_TABLE;#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, ET_VARS };+enum { ET_COLLIDER, ET_ALERT, ET_RANGE, ET_WALKER, ET_RECOIL, ET_CORPSE, ET_VARS, ET_TERRAIN };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) */@@ -64,7 +68,7 @@ typedef struct {float cbox_ox, cbox_oy, cbox_hx, cbox_hy; /* its collider */} Enemy;static Enemy en[MAX_ENEMIES];-static uint16_t swing_bits; /* (a bit an enemy: hit this swing) */+static uint32_t swing_bits; /* (a bit an enemy: hit this swing) *//* its transform's x scale (its collider's offset with it) */static void set_scale_x(Enemy *e, float sx) {@@ -86,6 +90,13 @@ static const Ent *enemy_rec(const Enemy *e, int tag) {return NULL;}+/* the terrain it holds (a child's colliders) gone: it died */+static void enemy_terrain_off(const Ent *d) {+ for (int i = 1; i <= d->s0; i++)+ if (d[i].type == ENT_BOX && d[i].flags == ET_TERRAIN)+ for (int c = d[i].a; c < d[i].a + d[i].group; c++) phys_collider_enable(c, false);+}+/* the collider's world box */static void enemy_box(const Enemy *e, float *x0, float *y0, float *x1, float *y1) {float cx = e->body.x + e->body.ox, cy = e->body.y + e->body.oy;@@ -189,9 +200,10 @@ static uint8_t flash_tint(const Enemy *e, int slot) {}/* ---------------------------------------------------------------- Recoil */+#define RF_NONE 0x80 /* (no Recoil component) */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_state != RC_READY || (e->rc_flags & RF_NONE)) 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);@@ -260,31 +272,47 @@ static void corpse_start(Enemy *e, float direction, bool has_direction) {/* HealthManager.Die, EnemyDeathEffects */static void shade_killed(Enemy *e);+static void blocker_die(Enemy *e);static void enemy_die(Enemy *e, float direction, bool has_direction) {if (FSM(e) == EF_SHADE) {shade_killed(e);return;}+ if (FSM(e) == EF_BLOCKER) {+ blocker_die(e);+ return;+ }/* the geo: SpawnAndFling, small, medium then large */float x = e->body.x, y = e->body.y;geo_fling(0, e->geo_s, x, y, 15, 30, 80, 100);geo_fling(1, e->geo_m, x, y, 15, 30, 80, 100);geo_fling(2, e->geo_l, x, y, 15, 30, 80, 100);- if (e->ent != NO_ENT) persist_set(ent_at(e->ent)->persist);+ if (e->ent != NO_ENT) persist_set(ent_at(e->ent)->persist), enemy_terrain_off(ent_at(e->ent));corpse_start(e, direction, has_direction);cam_shake(SHAKE_ENEMY_KILL);FREEZE_MOMENT_1();}/* HealthManager.Hit (a nail's): evasion, damage, recoil, flash, soul */+static void blocker_hit(Enemy *e);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);+ if (e->flags & 4) {+ /* Invincible: the hit blocked, the Knight recoiling off it */+ if (dir == 0) hero_recoil_left();+ else if (dir == 2) hero_recoil_right();+ FREEZE_MOMENT_1();+ cam_shake(SHAKE_ENEMY_KILL);+ e->evasion = 0.15f;+ return;+ }recoil_by_direction(e, dir, 1);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 ((FSM(e) == EF_BUZZER || FSM(e) == EF_SHADE || FSM(e) == EF_HUSK) && e->st == 0) e->b1 = true; /* (TOOK DAMAGE, in Idle / Ready) */+ if (FSM(e) == EF_BLOCKER && e->hp > 0) blocker_hit(e);if (e->hp > 0)e->evasion = 0.2f;else@@ -771,16 +799,26 @@ static void bouncer_start(Enemy *e) {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) {+/* CheckCollisionSide: three short rays from a side of its collider (0 right, 1 top, 2 left, 3 bottom) */+static bool side_hit(const Enemy *e, int side) {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;+ float dx = side == 0 ? 1 : side == 2 ? -1 : 0, dy = side == 1 ? 1 : side == 3 ? -1 : 0;+ float x = dx > 0 ? x1 : x0, y = dy > 0 ? y1 : y0;+ for (int i = 0; i < 3; i++) {+ float k = (float)i / 2;+ float rx = dx ? x : x0 + (x1 - x0) * k, ry = dy ? y : y0 + (y1 - y0) * k;+ if (phys_ray(rx, ry, dx, dy, d, CF_TERRAIN, NULL)) return true;+ }+ return false;+}++/* (the side it bumped, top first) */+static int bouncer_side(const Enemy *e) {+ static const int order[4] = {1, 0, 3, 2};+ for (int i = 0; i < 4; i++)+ if (side_hit(e, order[i])) return order[i];return -1;}@@ -839,13 +877,27 @@ static void distance_fly(Enemy *e, float dist, float vmax, float accel, bool hei#define MAX_BULLETS 8typedef struct {bool on, active;- float x, y, vx, vy, scale, ang;+ float x, y, vx, vy, scale, ang, gravity;Anim anim;} Bullet;static Bullet bullets[MAX_BULLETS];#define BULLET_HX (0.6406f / 2)#define BULLET_HY (0.5625f / 2)+/* a shot from (x, y) at a velocity, falling at a gravity scale */+static Bullet *bullet_new(float x, float y, float vx, float vy, float gravity) {+ Bullet *b = NULL;+ for (int i = 0; i < MAX_BULLETS && !b; i++)+ if (!bullets[i].on) b = &bullets[i];+ if (!b) return NULL;+ memset(b, 0, sizeof *b);+ b->on = b->active = true;+ b->x = x, b->y = y, b->vx = vx, b->vy = vy, b->gravity = gravity;+ b->scale = rand_range(1.15f, 1.45f);+ anim_play(&b->anim, CLIP_BULLET_IDLE);+ return b;+}+/* FireAtTarget: from (x, y) at the hero, at a speed */static void bullet_fire(float x, float y, float speed) {Bullet *b = NULL;@@ -856,6 +908,7 @@ static void bullet_fire(float x, float y, float speed) {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) */+ b->gravity = 0.05f;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;@@ -878,7 +931,7 @@ static void bullets_tick(void) {if (b->anim.events & ANIM_DONE) b->on = false;continue;}- b->vy += -60 * 0.05f * DT; /* (its Rigidbody2D: gravity 0.05) */+ 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 (l > 0 && phys_ray(b->x, b->y, dx / l, dy / l, l + BULLET_HX, CF_SOLID, &hit)) {@@ -1022,6 +1075,268 @@ static void spitter_update(Enemy *e) {}}+/* ---------------------------------------------------------------- spawned enemies (no record of the room's) */+static Enemy *enemy_spawn(int kind, float x, float y, int hp) {+ Enemy *e = NULL;+ for (int i = 0; i < MAX_ENEMIES && !e; i++)+ if (en[i].mode == EM_OFF) e = &en[i];+ if (!e) return NULL;+ memset(e, 0, sizeof *e);+ e->mode = EM_ALIVE, e->kind = (uint8_t)kind, e->ent = NO_ENT;+ e->hp = (int16_t)hp, e->damage = 1, e->sx = 1;+ e->rc_base = 15, e->rc_dur = 0.15f;+ e->body.x = x, e->body.y = y;+ e->body.friction = 0.2828f, e->body.mask = CF_SOLID;+ return e;+}++/* the hero in a box range of its (local: center, half size) */+static bool hero_in_box(const Enemy *e, float cx, float cy, float hx, float hy) {+ float x = e->body.x + cx * (e->sx < 0 ? -1 : 1), y = e->body.y + cy;+ float kx = g_hero.body.x + g_hero.body.ox, ky = g_hero.body.y + g_hero.body.oy;+ return !g_hero.hidden && fabsf(kx - x) < hx + g_hero.body.hx && fabsf(ky - y) < hy + g_hero.body.hy;+}++/* ---------------------------------------------------------------- Baldurs: the Roller FSM */+enum { RO_IDLE, RO_START, RO_ROLL, RO_COLLIDE, RO_AIR, RO_STOP, RO_REST };+/* (its variables, or a spawned one's) */+static float roller_var(const Enemy *e, int i) {+ static const float dflt[5] = {0.45f, 11, 2, 3, 0.5f};+ const Ent *v = enemy_rec(e, ET_VARS);+ if (!v) return dflt[i];+ return i == 0 ? v->p0 : i == 1 ? v->p1 : i == 2 ? v->p2 : i == 3 ? v->p3 : v->x0;+}++static void roller_roll(Enemy *e) {+ e->st = RO_ROLL;+ set_scale_x(e, e->b0 ? -fabsf(e->sx) : fabsf(e->sx));+ anim_play(&e->anim, CLIP(e, R_A2));+}++static void roller_start(Enemy *e) {+ e->st = RO_IDLE;+ anim_play(&e->anim, CLIP(e, R_IDLE));+}++/* (a spawned one: from the air, rolling its way) */+static void roller_spawned(Enemy *e, bool right) {+ e->b0 = right;+ set_scale_x(e, right ? -1.0f : 1.0f);+ e->body.gravity_scale = 0.8f;+ e->body.ox = -0.0156f, e->body.oy = -0.1094f, e->body.hx = e->body.hy = 1.0938f / 2;+ e->ar_x = 0, e->ar_y = 0, e->ar_r = 39.35f / 2, e->ar_hy = 1.9f / 2;+ e->wait = rand_range(roller_var(e, 2), roller_var(e, 3));+ anim_play(&e->anim, CLIP(e, R_A2));+ e->st = RO_AIR;+}++static void roller_fixed(Enemy *e) {+ if (e->st == RO_IDLE) e->body.vx = 0;+ else if (e->st == RO_ROLL) {+ float a = roller_var(e, 0), m = roller_var(e, 1), vx = e->body.vx + (e->b0 ? a : -a);+ e->body.vx = vx > m ? m : vx < -m ? -m : vx;+ }+}++static void roller_update(Enemy *e) {+ bool done = (e->anim.events & ANIM_DONE) != 0;+ if (e->flags & 2) { /* (RECOIL HORIZONTAL: Recoil Decel) */+ e->flags &= (uint8_t)~2;+ if (e->st == RO_ROLL) e->body.vx = 0;+ }+ switch (e->st) {+ case RO_IDLE: {+ float want = hero_x() > e->body.x ? -fabsf(e->sx) : fabsf(e->sx);+ if (e->sx != want) set_scale_x(e, want), anim_play_from_frame(&e->anim, CLIP(e, R_IDLE), 0);+ if (e->can_see && e->in_alert) {+ /* Facing Check, Start */+ e->b0 = hero_x() >= e->body.x;+ set_scale_x(e, e->b0 ? -fabsf(e->sx) : fabsf(e->sx));+ anim_play_from_frame(&e->anim, CLIP(e, R_A1), 0);+ e->wait = rand_range(roller_var(e, 2), roller_var(e, 3));+ e->st = RO_START;+ }+ break;+ }+ case RO_START:+ if (done) roller_roll(e);+ break;+ case RO_ROLL: {+ if (e->body.ncontacts && side_hit(e, e->b0 ? 0 : 2)) {+ /* Collide: off the wall, up and back the other way */+ e->b0 = !e->b0;+ set_scale_x(e, fabsf(e->sx));+ float a = (e->b0 ? 65 : 115) * (float)M_PI / 180;+ e->body.vx = cosf(a) * 12, e->body.vy = sinf(a) * 12;+ e->st = RO_COLLIDE;+ break;+ }+ if ((e->wait -= DT) <= 0) {+ e->body.vx = e->body.vy = 0;+ anim_play_from_frame(&e->anim, CLIP(e, R_A3), 0);+ e->st = RO_STOP;+ }+ break;+ }+ case RO_COLLIDE:+ e->st = RO_AIR; /* (the next frame) */+ break;+ case RO_AIR:+ e->wait -= DT;+ if (e->body.ncontacts && side_hit(e, 3)) roller_roll(e); /* (GROUND: Land, Left or right?) */+ break;+ case RO_STOP:+ if (done) {+ anim_play(&e->anim, CLIP(e, R_IDLE));+ e->st = RO_REST, e->t0 = 0;+ }+ break;+ case RO_REST:+ if ((e->t0 += DT) >= roller_var(e, 4)) e->st = RO_IDLE;+ break;+ }+}++/* ---------------------------------------------------------------- Elder Baldurs: the Blocker Control FSM */+enum { BL_DORMANT, BL_OPEN, BL_IDLE, BL_CLOSE1, BL_CLOSE2, BL_CLOSED, BL_SHOT_ANTIC, BL_SHOT_END, BL_HIT_PAUSE, BL_HIT };+#define BL_SHOT_ORIGIN_X 2.76f+#define BL_SHOT_ORIGIN_Y 0.78f++/* the hero in its alert range (ET_ALERT) or its attack range (ET_RANGE), boxes */+static bool blocker_in(const Enemy *e, int tag) {+ const Ent *r = enemy_rec(e, tag);+ return r && hero_in_box(e, r->x0, r->y0, r->x1, r->y1);+}++static void blocker_start(Enemy *e) {+ e->flags |= 4; /* (SetInvincible) */+ e->start_x = e->body.x, e->start_y = e->body.y;+ anim_play(&e->anim, CLIP(e, R_A1)); /* (Closed) */+ e->st = BL_DORMANT;+}++static void blocker_idle(Enemy *e) {+ e->st = BL_IDLE;+ e->body.x = e->start_x, e->body.y = e->start_y;+ anim_play(&e->anim, CLIP(e, R_IDLE));+ e->wait = rand_range(0.8f, 1.2f);+}++static void blocker_close(Enemy *e) {+ e->flags |= 4;+ e->body.x = e->start_x, e->body.y = e->start_y;+ anim_play_from_frame(&e->anim, CLIP(e, R_A3), 0);+ e->st = BL_CLOSE1;+}++static void blocker_hit(Enemy *e) {+ /* TOOK DAMAGE: Hit Pause, Hit */+ e->st = BL_HIT_PAUSE;+}++static void blocker_fire(Enemy *e) {+ const Ent *v = enemy_rec(e, ET_VARS);+ bool right = v && (v->a & 1);+ float ox = right ? BL_SHOT_ORIGIN_X : -BL_SHOT_ORIGIN_X;+ float vx = right ? rand_range(3, 15) : rand_range(-15, -1), vy = v ? v->p0 : 20;+ if (e->b1) {+ /* a roller, rolling its way */+ Enemy *r = enemy_spawn(EK_BALDUR, e->body.x + ox, e->body.y + BL_SHOT_ORIGIN_Y, 15);+ if (r) roller_spawned(r, right), r->body.vx = vx, r->body.vy = vy, r->rc_base = 25;+ } else {+ /* goop (Shot Mawlek) */+ bullet_new(e->body.x + ox, e->body.y + BL_SHOT_ORIGIN_Y, vx, vy, 0.6f);+ }+ anim_play_from_frame(&e->anim, CLIP(e, R_A6), 0); /* (Shoot CD) */+ e->st = BL_SHOT_END;+}++static void blocker_update(Enemy *e) {+ bool done = (e->anim.events & ANIM_DONE) != 0;+ switch (e->st) {+ case BL_DORMANT:+ if (blocker_in(e, ET_ALERT)) {+ e->flags &= (uint8_t)~4;+ anim_play_from_frame(&e->anim, CLIP(e, R_A2), 0); /* (Open) */+ e->st = BL_OPEN;+ }+ break;+ case BL_OPEN:+ if (done) blocker_idle(e);+ break;+ case BL_IDLE:+ if (blocker_in(e, ET_RANGE)) blocker_close(e);+ else if ((e->wait -= DT) <= 0) {+ /* Attack Choose: goop, or a roller if the Knight has his fireball and none is about */+ bool roller = rand_range(0, 1) < 0.5f && g_pd.fireball_level > 0;+ if (roller)+ for (int i = 0; i < MAX_ENEMIES; i++)+ if (en[i].mode == EM_ALIVE && en[i].ent == NO_ENT && FSM(&en[i]) == EF_ROLLER) roller = false;+ e->b1 = roller;+ anim_play_from_frame(&e->anim, CLIP(e, R_A5), 0); /* (Shoot Antic) */+ e->st = BL_SHOT_ANTIC;+ }+ break;+ case BL_SHOT_ANTIC:+ if (done) blocker_fire(e);+ break;+ case BL_SHOT_END:+ if (blocker_in(e, ET_RANGE)) blocker_close(e);+ else if (done) blocker_idle(e);+ break;+ case BL_CLOSE1:+ if (done) anim_play_from_frame(&e->anim, CLIP(e, R_A4), 0), e->st = BL_CLOSE2;+ break;+ case BL_CLOSE2:+ if (done) anim_play(&e->anim, CLIP(e, R_A1)), e->st = BL_CLOSED;+ break;+ case BL_CLOSED:+ if (!blocker_in(e, ET_RANGE)) {+ e->flags &= (uint8_t)~4;+ anim_play_from_frame(&e->anim, CLIP(e, R_A2), 0);+ e->st = BL_OPEN;+ }+ break;+ case BL_HIT_PAUSE:+ e->st = BL_HIT;+ anim_play_from_frame(&e->anim, CLIP(e, R_A7), 0);+ break;+ case BL_HIT:+ e->jx = rand_range(-0.05f, 0.05f), e->jy = rand_range(-0.05f, 0.05f);+ if (blocker_in(e, ET_RANGE)) e->jx = e->jy = 0, blocker_close(e);+ else if (done) e->jx = e->jy = 0, blocker_idle(e);+ break;+ }+}++/* its corpse (Corpse Blocker): stunned a second, then its death, staying */+static void blocker_die(Enemy *e) {+ geo_fling(0, e->geo_s, e->body.x, e->body.y, 15, 30, 80, 100);+ geo_fling(1, e->geo_m, e->body.x, e->body.y, 15, 30, 80, 100);+ geo_fling(2, e->geo_l, e->body.x, e->body.y, 15, 30, 80, 100);+ if (e->ent != NO_ENT) persist_set(ent_at(e->ent)->persist), enemy_terrain_off(ent_at(e->ent));+ cam_shake(SHAKE_ENEMY_KILL);+ FREEZE_MOMENT_1();+ /* (the Snail Shaman hears of it) */+ if (g_pd.shaman == 3) g_pd.shaman = 4;+ else if (g_pd.shaman == 2) g_pd.shaman = 5;+ e->mode = EM_CORPSE, e->st = 0, e->t0 = 0;+ e->body.vx = e->body.vy = 0, e->body.gravity_scale = 0, e->body.mask = 0;+ anim_play(&e->anim, CLIP(e, R_A8));+}++static void blocker_corpse(Enemy *e) {+ e->t0 += DT;+ if (e->st == 0) {+ e->jx = rand_range(-0.05f, 0.05f), e->jy = rand_range(-0.05f, 0.05f);+ if (e->t0 >= 1) {+ e->jx = e->jy = 0;+ anim_play_from_frame(&e->anim, CLIP(e, R_DEATH_LAND), 0);+ e->st = 1;+ }+ }+}+/* ---------------------------------------------------------------- Husks: the Zombie Swipe FSM, a Walker */enum { ZS_READY, ZS_ANTICIPATE, ZS_LUNGE, ZS_COOLDOWN, ZS_IDLE };#define ZS_LUNGE_SPEED 6.0f@@ -1452,7 +1767,11 @@ void enemies_enter(void) {const Ent *es = room_ents(&n);for (int i = 0; i < n && k < MAX_ENEMIES; i++) {const Ent *d = &es[i];- if (d->type != ENT_OBJ || d->flags != OK_ENEMY || persist_get(d->persist)) continue;+ if (d->type != ENT_OBJ || d->flags != OK_ENEMY) continue;+ if (persist_get(d->persist)) {+ enemy_terrain_off(d);+ continue;+ }Enemy *e = &en[k++];e->mode = EM_ALIVE, e->kind = (uint8_t)d->a, e->ent = (uint16_t)i;e->damage = (int8_t)d->p1, e->geo_s = (uint8_t)d->p2, e->geo_m = (uint8_t)d->p3, e->geo_l = (uint8_t)d->group;@@ -1469,7 +1788,7 @@ void enemies_enter(void) {if (!ar) ar = enemy_rec(e, ET_RANGE);if (ar) e->ar_x = ar->x0 * (e->sx < 0 ? -1 : 1), e->ar_y = ar->y0, e->ar_r = ar->x1, e->ar_hy = ar->y1;const Ent *rc = enemy_rec(e, ET_RECOIL);- e->rc_base = rc ? rc->x0 : 15, e->rc_dur = rc ? rc->y0 : 0.5f, e->rc_flags = rc ? (uint8_t)rc->a : 0;+ e->rc_base = rc ? rc->x0 : 15, e->rc_dur = rc ? rc->y0 : 0.5f, e->rc_flags = rc ? (uint8_t)rc->a : RF_NONE;const Ent *wk = enemy_rec(e, ET_WALKER);e->wk_rec = wk ? (uint16_t)(wk - room_ents(&n)) : 0;if (FSM(e) == EF_CRAWLER) crawler_start(e, d);@@ -1478,7 +1797,16 @@ void enemies_enter(void) {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);+ else if (FSM(e) == EF_ROLLER) roller_start(e);+ else if (FSM(e) == EF_BLOCKER) blocker_start(e);+ }+#ifdef HOST+ if (getenv("ENEMYCOUNT")) {+ int c = 0;+ for (int i = 0; i < n; i++) c += es[i].type == ENT_OBJ && es[i].flags == OK_ENEMY;+ fprintf(stderr, "enemies %d\n", c);}+#endifmemset(&sh, 0, sizeof sh);memset(balls, 0, sizeof balls);memset(bullets, 0, sizeof bullets);@@ -1508,9 +1836,10 @@ void enemies_fixed(void) {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);+ else if (FSM(e) == EF_ROLLER) roller_fixed(e);recoil_fixed(e);body_step(&e->body, DT);- } else {+ } else if (FSM(e) != EF_BLOCKER) {/* Corpse: falls, lands (or smashes, a breaker) and stays */const Ent *cr = enemy_rec(e, ET_CORPSE);bool breaker = cr && (cr->a & CF_BREAKER);@@ -1559,8 +1888,12 @@ void enemies_update(void) {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_ROLLER) roller_update(e);+ else if (FSM(e) == EF_BLOCKER) blocker_update(e);} else if (FSM(e) == EF_SHADE)shade_update(e);+ else if (FSM(e) == EF_BLOCKER)+ blocker_corpse(e);else if (e->st == CS_DEATH_ANIM && !e->anim.playing)e->mode = EM_OFF;}@@ -1614,7 +1947,7 @@ int enemies_nail(const float *pts, int npts, float direction, int damage) {if (!box_meets_shape(x0, y0, x1, y1, pts, npts)) continue;out |= HB_BOUNCE | HB_RECOIL;if (swing_bits >> i & 1) continue;- swing_bits |= (uint16_t)(1 << i);+ swing_bits |= 1u << i;enemy_hit(e, direction, damage);}return out;@@ -1657,7 +1990,6 @@ int enemies_touch_hero(float x0, float y0, float x1, float y1, int *side) {}#ifdef HOST-#include <stdio.h>void enemies_debug(void) {for (int i = 0; i < MAX_ENEMIES; i++) {const Enemy *e = &en[i];@@ -1669,4 +2001,15 @@ void enemies_debug(void) {for (int i = 0; i < MAX_GEO; i++) ng += geo[i].on;printf(" geo %d pieces, %d in purse, mp %d\n", ng, g_pd.geo, g_pd.mp);}++/* (tests: a hit on every enemy near the Knight, invincible or not) */+void enemies_debug_hit(int damage) {+ for (int i = 0; i < MAX_ENEMIES; i++) {+ Enemy *e = &en[i];+ float dx = e->body.x - g_hero.body.x, dy = e->body.y - g_hero.body.y;+ if (e->mode != EM_ALIVE || dx * dx + dy * dy > 15 * 15) continue;+ e->flags &= (uint8_t)~4, e->evasion = 0;+ enemy_hit(e, dx > 0 ? 0 : 180, damage);+ }+}#endifdiff --git a/games/hollowknight/src/game.h b/games/hollowknight/src/game.hindex 54fe1aa7..975629f2 100644--- a/games/hollowknight/src/game.h+++ b/games/hollowknight/src/game.h@@ -26,7 +26,8 @@ typedef struct {int32_t geo_pool;float play_time;uint8_t flags[32]; /* PDF_* */- uint8_t reserved[64];+ uint8_t shaman; /* (the Snail Shaman's state) */+ uint8_t reserved[63];/* (saved apart, by the objects' names: their states) */uint8_t persist[MAX_PERSIST / 8];/* (not saved) */@@ -99,7 +100,7 @@ void enemies_hero_leave(void); /* HERO LEAVE (the Knight dead): the shade depavoid geo_fling_at(int type, int n, float x, float y, float smin, float smax, float amin, float amax, float spread);int cardinal(float degrees); /* DirectionUtils.GetCardinalDirection */const Ent *room_ents(int *n);-#define MAX_ENTS 320+#define MAX_ENTS 448/* ---------------------------------------------------------------- the game */typedef struct {diff --git a/games/hollowknight/tests/play.c b/games/hollowknight/tests/play.cindex 75757e40..1c7488c3 100644--- a/games/hollowknight/tests/play.c+++ b/games/hollowknight/tests/play.c@@ -57,6 +57,7 @@ int main(int argc, char **argv) {if (getenv("HKMP")) g_pd.mp = (int16_t)atoi(getenv("HKMP"));if (getenv("HKHEALTH")) g_pd.health = (int8_t)atoi(getenv("HKHEALTH"));if (getenv("HKGEO")) g_pd.geo = atoi(getenv("HKGEO"));+ if (getenv("HKFIRE")) g_pd.fireball_level = atoi(getenv("HKFIRE"));/* (HKLOAD=slot: that save loaded, the Knight at its respawn point) */if (getenv("HKLOAD")) {if (!save_load(atoi(getenv("HKLOAD"))) || (getenv("HKGEO") && (g_pd.geo = atoi(getenv("HKGEO")), 0)) || !game_respawn()) {@@ -81,6 +82,10 @@ int main(int argc, char **argv) {dialogue_start(atoi(strchr(getenv("HKTALK"), ':') + 1));}if (getenv("HKKILL") && atoi(getenv("HKKILL")) == tick) hero_take_damage(SIDE_LEFT, 99, HAZ_NORMAL);+ if (getenv("HKHIT") && atoi(getenv("HKHIT")) <= tick && tick % 10 == 0) {+ extern void enemies_debug_hit(int damage);+ enemies_debug_hit(21);+ }if (getenv("HKPROMPT") && atoi(getenv("HKPROMPT")) == tick)prompt_show(-1, TXT_PROMPT_LISTEN, g_hero.body.x, g_hero.body.y + 1.5f);game_tick(keys);diff --git a/games/hollowknight/tools/actors.py b/games/hollowknight/tools/actors.pyindex b366b58d..a5ae043d 100644--- a/games/hollowknight/tools/actors.py+++ b/games/hollowknight/tools/actors.py@@ -30,6 +30,10 @@ ENEMY_KINDS = [("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"}),+ ("baldur", "Roller", ("sharedassets50.assets", 111), "ROLLER", {"IDLE": "Idle", "A1": "Start", "A2": "Roll", "A3": "Stop"}),+ ("elderbaldur", "Blocker Control", ("sharedassets50.assets", 109), "BLOCKER",+ {"IDLE": "Idle", "A1": "Closed", "A2": "Open", "A3": "Close1", "A4": "Close2", "A5": "Shoot Antic", "A6": "Shoot CD",+ "A7": "Hit", "A8": "Death Stun", "DEATH_LAND": "Death"}),("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",diff --git a/games/hollowknight/tools/ents.py b/games/hollowknight/tools/ents.pyindex 1d228185..6e25566a 100644--- a/games/hollowknight/tools/ents.py+++ b/games/hollowknight/tools/ents.py@@ -15,9 +15,11 @@ import actors as _actorsENEMIES = {(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"])}+ "Bouncer Control": (["Speed"], ["Starts Inactive", "Start Up"]),+ "Roller": (["Acceleration", "Max Speed", "Roll time Min", "Roll time Max", "Stop Time"], ["Moving Right"]),+ "Blocker Control": (["Shot Y Speed"], ["Facing Right"])}# what follows an enemy's record: ENT_BOX records, tagged-ET_COLLIDER, ET_ALERT, ET_RANGE, ET_WALKER, ET_RECOIL, ET_CORPSE, ET_VARS = 0, 1, 2, 3, 4, 5, 6+ET_COLLIDER, ET_ALERT, ET_RANGE, ET_WALKER, ET_RECOIL, ET_CORPSE, ET_VARS, ET_TERRAIN = 0, 1, 2, 3, 4, 5, 6, 7EF_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}@@ -315,10 +317,11 @@ def _alert_range(q):return None-def _enemy(o, by_id, persist, name, d=None, strings=None):+def _enemy(o, by_id, persist, name, d=None, strings=None, owners=None):"""An enemy -> its records: ENT_OBJ (OK_ENEMY: its kind, place (x, y, z, x scale), hp, damage, small and mediumgeo; large geo in group; s0 how many records follow), then ENT_BOX records each tagged (flags, ET_*): its- collider, alert ranges, Walker, Recoil, corpse; or None."""+ collider, alert ranges, Walker, Recoil, corpse, the terrain it holds (its subtree's colliders: a first, group how+ many); or None."""an = next((c.get("v") for c in o["c"] if c.get("class") == "tk2dSpriteAnimator" and c.get("v")), None)hm = next((c.get("v") for c in o["c"] if c.get("class") == "HealthManager" and c.get("v")), None)if not an or not hm:@@ -378,9 +381,10 @@ def _enemy(o, by_id, persist, name, d=None, strings=None):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))+ # (up to eight numbers: p0..p3, then the box's)+ vals = [float((var.get(k) or [0, 0])[1] or 0) for k in nums] + [0.0] * (8 - 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))+ out.append(rec(ENT_BOX, ET_VARS, p=tuple(vals[:4]), box=tuple(vals[4:8]), 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),@@ -410,6 +414,11 @@ def _enemy(o, by_id, persist, name, d=None, strings=None):a=cfl | (0 if cb else 32)))except Exception as e:print("ents: %s: corpse %s" % (o["path"], e))+ if owners:+ import coll+ c0, cn = coll.subtree_colliders(d, owners, o["id"])+ if cn:+ out.append(rec(ENT_BOX, ET_TERRAIN, a=c0, group=cn))persistent = any(c.get("class") == "PersistentBoolItem" for c in o["c"])head = rec(ENT_OBJ, OK_ENEMY, (o["pos"][0], o["pos"][1], o["pos"][2], sx),(hm.get("hp", 1), dh.get("damageDealt", 0), hm.get("smallGeoDrops", 0), hm.get("mediumGeoDrops", 0)),@@ -554,7 +563,7 @@ def room(d, rooms, strings, persist, name, sprites=None, owners=None):group=g_lit, group2=g_light, s0=strings.id(o["name"])))recs.append(rec(ENT_BOX, 0, box))recs.append(rec(ENT_BOX, 0, dr or box))- en = _enemy(o, by_id, persist, name, d, strings) or _props(d, o, by_id, rooms, strings, persist, sprites, owners, name)+ en = _enemy(o, by_id, persist, name, d, strings, owners) or _props(d, o, by_id, rooms, strings, persist, sprites, owners, name)if en:recs += enbr = next((c for c in o["c"] if c.get("class") == "Breakable" and c.get("v") is not None), None)@@ -660,5 +669,5 @@ def room(d, rooms, strings, persist, name, sprites=None, owners=None):else:print("ents: %s: HIT receiver %d has no record" % (name, target))assert ngroups[0] < MAX_GROUPS, ngroups[0]- assert len(recs) <= 320, len(recs) # (src/game.h: MAX_ENTS)+ assert len(recs) <= 448, len(recs) # (src/game.h: MAX_ENTS)return recs, groups