Skip to content

Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.

Hollow Knight: room transitions, Great Door, geo rocks, chest

Mason Chene467c22992d0
diff --git a/games/hollowknight/src/data.bin b/games/hollowknight/src/data.bin
index 1b08b26d..985675c9 100644
Binary files a/games/hollowknight/src/data.bin and b/games/hollowknight/src/data.bin differ
diff --git a/games/hollowknight/src/data.h b/games/hollowknight/src/data.h
index 2c75ebb6..af866d1f 100644
--- a/games/hollowknight/src/data.h
+++ b/games/hollowknight/src/data.h
@@ -147,10 +147,20 @@
#define CLIP_BUZZER_FLY 90
#define CLIP_BUZZER_TURNTOFLY 91
#define CLIP_BUZZER_TURNTOIDLE 92
-#define CLIP_GEO_SMALL_IDLE 93
-#define CLIP_GEO_SMALL_AIR 94
-#define CLIP_GEO_MED_IDLE 95
-#define CLIP_GEO_MED_AIR 96
-#define CLIP_GEO_LARGE_IDLE 97
-#define CLIP_GEO_LARGE_AIR 98
-#define SPRITE_HERO_LIGHT 405
+#define CLIP_GEOROCK_IDLE_1 93
+#define CLIP_GEOROCK_GLEAM_1 94
+#define CLIP_GEOROCK_BROKEN_1 95
+#define CLIP_GEOROCK_IDLE_2 96
+#define CLIP_GEOROCK_GLEAM_2 97
+#define CLIP_GEOROCK_BROKEN_2 98
+#define CLIP_CHEST_IDLE 99
+#define CLIP_CHEST_OPEN 100
+#define CLIP_CHEST_BURST 101
+#define CLIP_CHEST_OPENED 102
+#define CLIP_GEO_SMALL_IDLE 103
+#define CLIP_GEO_SMALL_AIR 104
+#define CLIP_GEO_MED_IDLE 105
+#define CLIP_GEO_MED_AIR 106
+#define CLIP_GEO_LARGE_IDLE 107
+#define CLIP_GEO_LARGE_AIR 108
+#define SPRITE_HERO_LIGHT 431
diff --git a/games/hollowknight/src/enemy.c b/games/hollowknight/src/enemy.c
index 02431ff7..a264647b 100644
--- a/games/hollowknight/src/enemy.c
+++ b/games/hollowknight/src/enemy.c
@@ -96,6 +96,10 @@ static const struct {
/* FlingUtils.SpawnAndFling: n of a kind, each at a random speed and angle */
static void geo_fling(int type, int n, float x, float y, float smin, float smax, float amin, float amax) {
+ geo_fling_at(type, n, x, y, smin, smax, amin, amax, 0);
+}
+
+void geo_fling_at(int type, int n, float x, float y, float smin, float smax, float amin, float amax, float spread) {
for (int k = 0; k < n; k++) {
Geo *g = NULL;
for (int i = 0; i < MAX_GEO && !g; i++)
@@ -104,7 +108,7 @@ static void geo_fling(int type, int n, float x, float y, float smin, float smax,
memset(g, 0, sizeof *g);
g->on = true, g->type = (uint8_t)type;
Body *b = &g->body;
- b->x = x, b->y = y;
+ b->x = x + rand_range(-spread, spread), b->y = y + rand_range(-spread, spread);
b->ox = geo_kinds[type].ox * GEO_SCALE, b->oy = geo_kinds[type].oy * GEO_SCALE;
b->hx = geo_kinds[type].hx * GEO_SCALE, b->hy = geo_kinds[type].hy * GEO_SCALE;
b->gravity_scale = geo_kinds[type].gravity, b->friction = 0.2f, b->mask = CF_TERRAIN;
diff --git a/games/hollowknight/src/game.c b/games/hollowknight/src/game.c
index c3f8abff..e2451675 100644
--- a/games/hollowknight/src/game.c
+++ b/games/hollowknight/src/game.c
@@ -33,6 +33,82 @@ const Ent *room_ents(int *n) {
/* ---------------------------------------------------------------- triggers: the Knight's box in the objects' */
+/* ---------------------------------------------------------------- scene transitions (TransitionPoint, BeginSceneTransition) */
+enum { SC_NONE, SC_LEAVING };
+
+/* TransitionPoint.GetGatePosition: by its name */
+static int gate_kind(const Ent *e) {
+ if (e->flags & G_DOOR) return GATE_DOOR;
+ const char *n = str_at(e->s0);
+ if (strstr(n, "top")) return GATE_TOP;
+ if (strstr(n, "right")) return GATE_RIGHT;
+ if (strstr(n, "left")) return GATE_LEFT;
+ if (strstr(n, "bot")) return GATE_BOTTOM;
+ return strstr(n, "door") ? GATE_DOOR : GATE_UNKNOWN;
+}
+
+void game_fade_scene_in(void) { game_fade(0, 0.5f, 0.1f); }
+
+void game_transition(int room, int entry, int gate, float delay, bool without_input) {
+ Game *g = &g_game;
+ if (g->scene_phase != SC_NONE || room < 0) return;
+ g->scene_phase = SC_LEAVING, g->scene_t = 0;
+ g->next_room = (int16_t)room, g->next_entry = (uint16_t)entry, g->next_delay = delay;
+ g_hero.enter_without_input = without_input;
+ hero_leave_scene(gate);
+ cam_freeze();
+ if (g->fade < 1) game_fade(1, 0.33f, 0); /* (the camera's FADE OUT) */
+}
+
+/* TryDoTransition: the Knight through a gate (facing it, not recoiling), or pushed back out of it */
+static void gate_touched(const Ent *e) {
+ Hero *h = &g_hero;
+ if ((e->flags & G_DOOR) || g_game.scene_phase != SC_NONE) return;
+ int g = gate_kind(e);
+ bool back = h->cs.recoiling || (g == GATE_RIGHT && !h->cs.facing_right) || (g == GATE_LEFT && h->cs.facing_right) ||
+ e->a == 0xFFFF; /* (or to a room this game leaves out) */
+ const Body *b = &h->body;
+ if (back && (g == GATE_RIGHT || g == GATE_LEFT)) {
+ h->body.vx = 0;
+ h->body.x += g == GATE_RIGHT ? e->x0 - (b->x + b->ox + b->hx) : e->x1 - (b->x + b->ox - b->hx);
+ } else if (back && (g == GATE_TOP || g == GATE_BOTTOM)) {
+ h->body.vy = 0;
+ h->body.y += g == GATE_TOP ? e->y0 - (b->y + b->oy + b->hy) : e->y1 - (b->y + b->oy - b->hy);
+ } else if (!back)
+ game_transition(e->a, e->s1, g, e->p0, false);
+}
+
+/* the new room, the Knight at its entry gate */
+static void scene_load(void) {
+ Game *g = &g_game;
+ g->scene_phase = SC_NONE;
+ if (!room_load(g->next_room)) return;
+ memset(inside, 0, sizeof inside);
+ world_enter();
+ int n;
+ const Ent *es = room_ents(&n);
+ const char *want = str_at(g->next_entry);
+ for (int i = 0; i < n; i++) {
+ const Ent *e = &es[i];
+ if (e->type != ENT_GATE || strcmp(str_at(e->s0), want)) continue;
+ float gx = (e->x0 + e->x1) / 2, gy = (e->y0 + e->y1) / 2;
+ for (int j = i + 1; j < n && es[j].type == ENT_BOX; j++)
+ if (es[j].flags & 1) gx = es[j].x0, gy = es[j].y0;
+ hero_enter_scene(i, gate_kind(e), gx, gy, e->p1, e->p2, e->flags, g->next_delay + e->p0);
+ return;
+ }
+ /* (no such gate: in the middle of the room) */
+ hero_enter_scene(-1, GATE_DOOR, g_room.h->w / 2, g_room.h->h / 2, 0, 0, 0, g->next_delay);
+}
+
+static void scene_tick(float real_dt) {
+ Game *g = &g_game;
+ if (g->scene_phase != SC_LEAVING) return;
+ /* (the scene loads once the camera has faded: half a second) */
+ g->scene_t += real_dt;
+ if (g->scene_t >= 0.5f) scene_load();
+}
+
static void trigger_event(int i, const Ent *e, int kind) {
Hero *h = &g_hero;
switch (e->type) {
@@ -40,6 +116,9 @@ static void trigger_event(int i, const Ent *e, int kind) {
if (kind == EV_EXIT) cam_release(i);
else cam_lock(i); /* (Enter and Stay) */
break;
+ case ENT_GATE:
+ if (kind == EV_ENTER) gate_touched(e);
+ break;
case ENT_HAZARD_TRIGGER:
if (kind == EV_ENTER) {
int n;
@@ -65,7 +144,7 @@ static void triggers_tick(void) {
if (e->type != ENT_CAMLOCK && e->type != ENT_GATE && e->type != ENT_HAZARD_TRIGGER && e->type != ENT_MASK) continue;
bool in = false;
for (int j = i; j < n && (j == i || es[j].type == ENT_BOX); j++)
- in |= x1 > es[j].x0 && x0 < es[j].x1 && y1 > es[j].y0 && y0 < es[j].y1;
+ if (j == i || !(es[j].flags & 1)) in |= x1 > es[j].x0 && x0 < es[j].x1 && y1 > es[j].y0 && y0 < es[j].y1;
bool was = inside[i >> 3] >> (i & 7) & 1;
if (in) inside[i >> 3] |= (uint8_t)(1 << (i & 7));
else inside[i >> 3] &= (uint8_t)~(1 << (i & 7));
@@ -171,6 +250,7 @@ static void step(uint32_t keys) {
void game_tick(uint32_t keys) {
Game *g = &g_game;
freeze_tick(0.02f);
+ scene_tick(0.02f);
/* (game time runs at the time scale: frozen, no steps) */
g->step_acc += 0.02f * g->time_scale;
if (g->step_acc >= 0.02f - 1e-6f) {
diff --git a/games/hollowknight/src/game.h b/games/hollowknight/src/game.h
index 7294bba5..e4e6ea60 100644
--- a/games/hollowknight/src/game.h
+++ b/games/hollowknight/src/game.h
@@ -19,12 +19,12 @@ extern PlayerData g_pd;
/* ---------------------------------------------------------------- the room's game objects (tools/ents.py) */
enum { ENT_CAMLOCK = 1, ENT_GATE, ENT_HAZARD_MARKER, ENT_RESPAWN, ENT_HAZARD_TRIGGER, ENT_MASK, ENT_DAMAGE, ENT_SHAPE,
ENT_BOX, ENT_OBJ, ENT_PIECE }; /* (shape, box, piece: more of the record before) */
-enum { OK_BREAKABLE = 1, OK_ENEMY }; /* objects (ENT_OBJ's flags) */
+enum { OK_BREAKABLE = 1, OK_ENEMY, OK_GREAT_DOOR, OK_GEO_ROCK, OK_CHEST }; /* objects (ENT_OBJ's flags) */
enum { HB_BOUNCE = 1, HB_RECOIL = 2 }; /* a hit box (ENT_BOX's flags): a down slash bounces off it, a slash recoils */
enum { HAZ_NONE, HAZ_NORMAL, HAZ_SPIKES, HAZ_ACID, HAZ_LAVA, HAZ_PIT }; /* DamageHero.hazardType */
enum { MK_SECRET = 1, MK_REMASK = 2, MK_SIMPLE = 4 }; /* masks: the unmasker, remasker and inverse FSMs */
enum { CL_PREVENT_UP = 1, CL_PREVENT_DOWN = 2, CL_MAX_PRIORITY = 4 };
-enum { G_DOOR = 1, G_ENTER_RIGHT = 2, G_ENTER_LEFT = 4, G_DONT_WALK_OUT = 8, G_NON_HAZARD = 16 };
+enum { G_DOOR = 1, G_ENTER_RIGHT = 2, G_ENTER_LEFT = 4, G_DONT_WALK_OUT = 8, G_NON_HAZARD = 16, G_HARD_LAND = 32 };
#define FACING_RIGHT 1
typedef struct {
uint8_t type, flags;
@@ -45,6 +45,7 @@ void world_send_hit(int ent); /* HIT to an object's FSM (from anot
void group_fade(int group, float alpha, float time); /* iTweenFadeTo (linear) */
bool persist_get(int bit); /* an object's state in the save (PersistentBoolItem) */
void persist_set(int bit);
+void persist_clear(int bit);
/* the objects the Knight acts on (obj.c) */
void obj_enter(void);
@@ -62,6 +63,8 @@ void enemies_draw(void);
void enemies_swing_start(void);
int enemies_nail(const float *pts, int npts, float direction, int damage);
int enemies_touch_hero(float x0, float y0, float x1, float y1, int *side); /* -> its damage, 0: none */
+/* geo of a size (0 small, 1 medium, 2 large) flung from (x, y), each from a little about it (FlingUtils) */
+void 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
@@ -80,6 +83,11 @@ typedef struct {
float freeze_t, freeze_from, freeze_down, freeze_wait, freeze_up, freeze_target;
uint8_t hazard_phase;
float hazard_t;
+ /* a scene transition */
+ uint8_t scene_phase;
+ int16_t next_room;
+ uint16_t next_entry;
+ float scene_t, next_delay;
/* the camera's fade to black */
float fade, fade_from, fade_to, fade_t, fade_time, fade_delay;
} Game;
@@ -88,6 +96,10 @@ void game_freeze(float down, float wait, float up, float target, bool hero); /
#define FREEZE_MOMENT_1() game_freeze(0.04f, 0.03f, 0.04f, 0, false) /* FreezeMoment(1): a kill */
void game_player_dead_from_hazard(void);
void game_fade(float to, float time, float delay);
+void game_fade_scene_in(void); /* the camera's FADE SCENE IN */
+/* BeginSceneTransition: to the room's entry gate (a string), leaving by a gate kind (GATE_UNKNOWN: standing),
+ * entering after delay; without input: the Knight comes in without control */
+void game_transition(int room, int entry, int gate, float delay, bool without_input);
extern Game g_game;
/* ---------------------------------------------------------------- the Knight (hero.c) */
@@ -124,7 +136,8 @@ typedef struct {
float transition_vx, transition_vy;
bool accepting_input, control_relinquished, doing_hazard_respawn, landed_event;
bool touching_wall_l, touching_wall_r;
- bool hidden, hit_buffered;
+ bool hidden, hit_buffered, enter_without_input;
+ 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;
bool invuln_routine, pulsing, pulse_reverse, respawning;
@@ -147,7 +160,10 @@ void hero_recoil_left(void);
void hero_recoil_right(void);
void hero_recoil_down(void);
void hero_bounce(void);
-void hero_finished_entering_scene(void);
+void hero_finished_entering_scene(bool set_hazard_marker);
+void hero_leave_scene(int gate); /* LeaveScene: walking, jumping or falling out through the gate */
+/* EnterScene: the Knight through the room's entry gate (its record, kind, place, entry offset, G_* flags) after delay */
+void hero_enter_scene(int gate_ent, int gate, float gx, float gy, float ox, float oy, uint8_t flags, float delay);
void hero_take_damage(int side, int damage, int hazard); /* (side: where the damage comes from, SIDE_LEFT/RIGHT) */
void hero_recoil_unfreeze(void); /* the end of StartRecoil, after the freeze */
void hero_hazard_respawn(void); /* HeroController.HazardRespawn */
diff --git a/games/hollowknight/src/hero.c b/games/hollowknight/src/hero.c
index 90d411cd..8be28b64 100644
--- a/games/hollowknight/src/hero.c
+++ b/games/hollowknight/src/hero.c
@@ -99,6 +99,7 @@ static void respawn_tick(void);
static void die_from_hazard(void);
static void slash_fixed(void);
static void slash_hits(void);
+static void entering_tick(void);
void hero_die(void);
static bool can_exit_no_input(void) { return !g_hero.doing_hazard_respawn && !g_hero.cs.dead; }
@@ -472,7 +473,7 @@ static void on_enter(const BodyEvent *e) {
else if (!(f & CF_STEEP) && h->state != HS_HARD_LANDING) back_on_ground();
}
} else if (h->transition_state == TS_DROPPING_DOWN && (h->gate_position == GATE_BOTTOM || h->gate_position == GATE_TOP))
- hero_finished_entering_scene();
+ hero_finished_entering_scene(true);
}
static void on_stay(const BodyEvent *e) {
@@ -753,6 +754,7 @@ void hero_init(float x, float y, bool facing_right) {
Hero *h = &g_hero;
static BodyEvent events[MAX_EVENTS];
memset(h, 0, sizeof *h);
+ h->entry_gate = -1;
h->body.events = events;
h->body.x = x, h->body.y = y;
h->body.ox = 0, h->body.oy = -0.75f, h->body.hx = 0.25f, h->body.hy = 0.640625f; /* the Knight's BoxCollider2D */
@@ -794,6 +796,7 @@ void hero_update(void) {
update();
invulnerable_tick();
respawn_tick();
+ entering_tick();
if (h->anim_control) animation();
h->anim.events = 0;
anim_update(&h->anim, DT);
@@ -930,9 +933,173 @@ void slash_draw(void) {
void fx_dash_burst(float x, float y, bool facing_right, bool on_ground) { (void)x, (void)y, (void)facing_right, (void)on_ground; }
+/* ---------------------------------------------------------------- scenes: LeaveScene, EnterScene */
+#define SPEED_TO_ENTER_SCENE_HOR 6.0f
+#define SPEED_TO_ENTER_SCENE_UP 9.4f
+#define SPEED_TO_ENTER_SCENE_DOWN (-12.0f)
+#define TIME_TO_ENTER_SCENE_BOT 0.1f
+#define MIN_JUMP_SPEED 3.0f
+
+void hero_leave_scene(int gate) {
+ Hero *h = &g_hero;
+ h->accepting_input = false; /* (IgnoreInputWithoutReset) */
+ h->hard_landing_timer = 0;
+ set_state(HS_NO_INPUT);
+ h->damage_mode = DAMAGE_NONE;
+ h->transition_state = TS_EXITING_SCENE;
+ h->transition_vx = h->transition_vy = 0;
+ if (gate == GATE_TOP) h->transition_vy = MIN_JUMP_SPEED, h->cs.on_ground = false;
+ else if (gate == GATE_RIGHT) h->transition_vx = RUN_SPEED;
+ else if (gate == GATE_BOTTOM) h->cs.on_ground = false;
+ else if (gate == GATE_LEFT) h->transition_vx = -RUN_SPEED;
+ h->cs.transitioning = true;
+}
+
+/* FindGroundPointY: the Knight's place standing on the ground below (x, y) */
+static float ground_point_y(float x, float y, float dist) {
+ Hero *h = &g_hero;
+ PhysHit hit;
+ if (!phys_ray(x, y, 0, -1, dist, CF_TERRAIN, &hit)) hit.y = 0;
+ return hit.y + h->body.hy - h->body.oy + 0.01f;
+}
+
+/* the EnterScene coroutine: its steps, each after a wait */
+static struct {
+ int8_t step;
+ uint8_t gate, flags;
+ float t, delay, gx, gy, ox, oy;
+ int gate_ent;
+} en;
+
+static void entering_wait(float t) { en.t = t; }
+
+void hero_enter_scene(int gate_ent, int gate, float gx, float gy, float ox, float oy, uint8_t flags, float delay) {
+ Hero *h = &g_hero;
+ h->accepting_input = false;
+ reset_motion();
+ h->air_dashed = false;
+ h->hard_landing_timer = 0;
+ reset_attacks();
+ affected_by_gravity(false);
+ set_state(HS_NO_INPUT);
+ h->transition_state = TS_WAITING_TO_ENTER_LEVEL;
+ h->cs.transitioning = true;
+ h->gate_position = (uint8_t)gate;
+ memset(&en, 0, sizeof en);
+ en.gate = (uint8_t)gate, en.flags = flags, en.gx = gx, en.gy = gy, en.ox = ox, en.oy = oy, en.delay = delay;
+ en.gate_ent = gate_ent;
+ en.step = 1;
+ h->entry_gate = (int16_t)gate_ent;
+ if (gate == GATE_TOP) {
+ h->cs.on_ground = false;
+ h->hidden = true;
+ h->body.x = gx + ox, h->body.y = gy + oy;
+ world_hero_in_position(), cam_init();
+ entering_wait(0.165f);
+ } else if (gate == GATE_BOTTOM) {
+ h->cs.on_ground = false;
+ if (flags & G_ENTER_RIGHT) face_right();
+ if (flags & G_ENTER_LEFT) face_left();
+ h->body.x = gx + ox, h->body.y = gy + oy + 3;
+ world_hero_in_position(), cam_init();
+ entering_wait(0.165f);
+ } else if (gate == GATE_LEFT || gate == GATE_RIGHT) {
+ float k = gate == GATE_LEFT ? 1.0f : -1.0f;
+ h->cs.on_ground = true;
+ h->body.x = gx + ox - k;
+ h->body.y = ground_point_y(h->body.x + 2 * k, gy, 10);
+ world_hero_in_position(), cam_init();
+ if (gate == GATE_LEFT) face_right();
+ else face_left();
+ entering_wait(0.165f);
+ } else {
+ /* a door */
+ if (flags & G_ENTER_RIGHT) face_right();
+ if (flags & G_ENTER_LEFT) face_left();
+ h->cs.on_ground = true;
+ anim_play(&h->anim, CLIP_KNIGHT_IDLE);
+ h->body.x = gx, h->body.y = ground_point_y(gx, gy, 10);
+ world_hero_in_position(), cam_init();
+ entering_wait(0);
+ }
+ h->body.ncontacts = 0;
+}
+
+static void entering_tick(void) {
+ Hero *h = &g_hero;
+ if (!en.step) return;
+ if (en.t > 0) {
+ en.t -= DT;
+ if (en.t > 0) return;
+ }
+ int step = en.step++;
+ float wait_delays = en.delay; /* (the delay before entering, then the gate's entry delay) */
+ switch (en.gate) {
+ case GATE_TOP:
+ if (step == 1) game_fade_scene_in(), entering_wait(wait_delays + 0.2f);
+ else if (step == 2) {
+ h->hidden = false;
+ h->body.vy = SPEED_TO_ENTER_SCENE_DOWN;
+ h->transition_state = TS_DROPPING_DOWN;
+ affected_by_gravity(true);
+ if (en.flags & G_HARD_LAND) h->cs.will_hard_land = true;
+ entering_wait(0.33f);
+ } else {
+ en.step = 0;
+ h->transition_state = TS_ENTERING_SCENE;
+ hero_finished_entering_scene(true);
+ }
+ break;
+ case GATE_BOTTOM:
+ if (step == 1) entering_wait(wait_delays + 0.2f);
+ else if (step == 2) {
+ game_fade_scene_in();
+ h->transition_vx = h->cs.facing_right ? SPEED_TO_ENTER_SCENE_HOR : -SPEED_TO_ENTER_SCENE_HOR;
+ h->transition_vy = SPEED_TO_ENTER_SCENE_UP;
+ h->transition_state = TS_ENTERING_SCENE;
+ h->body.x = en.gx + en.ox, h->body.y = en.gy + en.oy + 3;
+ entering_wait(TIME_TO_ENTER_SCENE_BOT);
+ } else {
+ en.step = 0;
+ h->transition_vx = h->body.vx, h->transition_vy = 0;
+ affected_by_gravity(true);
+ h->transition_state = TS_DROPPING_DOWN; /* (finished as it lands) */
+ }
+ break;
+ case GATE_LEFT:
+ case GATE_RIGHT:
+ if (step == 1) game_fade_scene_in(), entering_wait(wait_delays + 0.2f);
+ else if (step == 2) {
+ h->transition_vx = en.gate == GATE_LEFT ? RUN_SPEED : -RUN_SPEED, h->transition_vy = 0;
+ h->transition_state = TS_ENTERING_SCENE;
+ entering_wait(0.33f + 1 / RUN_SPEED);
+ } else {
+ en.step = 0;
+ hero_finished_entering_scene(true);
+ }
+ break;
+ default:
+ if (step == 1) entering_wait(DT + wait_delays + 0.4f); /* (WaitForEndOfFrame, then the waits) */
+ else if (step == 2) {
+ game_fade_scene_in();
+ if (en.flags & G_DONT_WALK_OUT) entering_wait(0.33f);
+ else {
+ anim_play(&h->anim, CLIP_KNIGHT_EXIT_DOOR_TO_IDLE);
+ float d = clip_duration(CLIP_KNIGHT_EXIT_DOOR_TO_IDLE);
+ entering_wait(d > 0 ? d : 0.33f);
+ }
+ } else {
+ en.step = 0;
+ hero_finished_entering_scene(true);
+ }
+ break;
+ }
+}
+
/* FinishedEnteringScene */
-void hero_finished_entering_scene(void) {
+void hero_finished_entering_scene(bool set_hazard_marker) {
Hero *h = &g_hero;
+ en.step = 0;
h->doing_hazard_respawn = false;
h->cs.transitioning = false;
h->transition_state = TS_WAITING_TO_TRANSITION;
@@ -949,8 +1116,20 @@ void hero_finished_entering_scene(void) {
}
anim_update_state(h->state);
affected_by_gravity(true);
+ if (set_hazard_marker) {
+ /* (the room's first: where the Knight is; else the entry gate's marker, unless it is a non hazard gate) */
+ int n;
+ const Ent *es = room_ents(&n);
+ if (h->entry_gate < 0 || h->entry_gate >= n)
+ g_game.hazard_x = h->body.x, g_game.hazard_y = h->body.y, g_game.hazard_facing_right = h->cs.facing_right;
+ else if (!(es[h->entry_gate].flags & G_NON_HAZARD) && es[h->entry_gate].p3 > 0) {
+ const Ent *m = &es[(int)es[h->entry_gate].p3 - 1];
+ g_game.hazard_x = m->x0, g_game.hazard_y = m->y0, g_game.hazard_facing_right = m->flags & FACING_RIGHT;
+ }
+ }
h->damage_mode = DAMAGE_FULL;
- h->accepting_input = true;
+ if (h->enter_without_input) h->enter_without_input = false; /* (something in the room gives control back) */
+ else h->accepting_input = true;
}
/* ---------------------------------------------------------------- damage (TakeDamage, StartRecoil, Invulnerable) */
@@ -1106,7 +1285,7 @@ static void respawn_tick(void) {
h->respawning = false;
h->cs.hazard_respawning = false;
h->anim_control = true;
- hero_finished_entering_scene();
+ hero_finished_entering_scene(false);
}
/* HeroBox: what touches the Knight's hurt box (hazards; enemies through world.c) */
diff --git a/games/hollowknight/src/obj.c b/games/hollowknight/src/obj.c
index ff57128b..de7e7d91 100644
--- a/games/hollowknight/src/obj.c
+++ b/games/hollowknight/src/obj.c
@@ -10,6 +10,11 @@
typedef struct {
uint8_t kind, state;
uint16_t ent; /* its record */
+ int8_t hits;
+ bool shown;
+ int16_t sprite;
+ float t, t2, jx, jy; /* (timers; a jitter) */
+ Anim anim;
} Obj;
static Obj objs[MAX_OBJS];
static int nobjs;
@@ -138,6 +143,166 @@ static void breakable_hit(Obj *o, const Ent *e, float direction) {
cam_shake(SHAKE_ENEMY_KILL);
}
+/* ---------------------------------------------------------------- the Great Door (King's Pass): 13 blows open it */
+enum { GD_IDLE, GD_WAIT, GD_BREAK, GD_OPEN };
+
+static void great_door_enter(Obj *o, const Ent *e) {
+ o->sprite = (int16_t)e->p0, o->shown = true;
+ if (persist_get(e->persist)) {
+ /* Activate: its collider and sprite off */
+ o->state = GD_OPEN, o->shown = false;
+ for (int c = e->a; c < e->a + e->group; c++) phys_collider_enable(c, false);
+ }
+}
+
+static void great_door_hit(Obj *o, const Ent *e) {
+ if (o->state != GD_IDLE) return;
+ cam_shake(SHAKE_ENEMY_KILL);
+ /* Check Hits */
+ o->hits++;
+ if (o->hits == 4 || o->hits == 8) {
+ o->sprite = (int16_t)(o->hits == 4 ? e->p1 : e->p2);
+ cam_shake(SHAKE_AVERAGE);
+ }
+ if (o->hits == 13) {
+ /* Break: the screen black at once, then (a frame later) the Knight, without control, to Dirtmouth */
+ o->state = GD_BREAK, o->t = DT;
+ persist_set(e->persist);
+ game_fade(1, 0, 0);
+ return;
+ }
+ o->state = GD_WAIT, o->t = 0.15f;
+}
+
+static void great_door_tick(Obj *o, const Ent *e) {
+ if (o->state == GD_WAIT && (o->t -= DT) <= 0) o->state = GD_IDLE;
+ else if (o->state == GD_BREAK && (o->t -= DT) <= 0) {
+ o->state = GD_OPEN;
+ game_transition((int)e->p3, e->s0, GATE_UNKNOWN, 2.5f, false); /* (its EnterWithoutInput goes to an object without it) */
+ }
+}
+
+/* ---------------------------------------------------------------- geo rocks (the Geo Rock FSM; GeoRock keeps its hits) */
+enum { GR_IDLE, GR_HIT, GR_RETURN, GR_DESTROY, GR_BROKEN };
+
+static int georock_clip(const Ent *e, int which) { /* 0 gleam, 1 broken */
+ static const int clips[2][2] = {{CLIP_GEOROCK_GLEAM_1, CLIP_GEOROCK_BROKEN_1}, {CLIP_GEOROCK_GLEAM_2, CLIP_GEOROCK_BROKEN_2}};
+ return clips[e->p3 == 2][which];
+}
+
+static void georock_broken(Obj *o, const Ent *e) {
+ anim_play(&o->anim, georock_clip(e, 1));
+ o->state = GR_BROKEN;
+ o->jx = o->jy = 0;
+}
+
+static void georock_save(const Obj *o, const Ent *e) {
+ /* (4 bits: the hits left, plus one; none: as the room has it) */
+ for (int b = 0; b < 4; b++)
+ if ((o->hits + 1) >> b & 1) persist_set(e->persist + b);
+ else persist_clear(e->persist + b);
+}
+
+static void georock_enter(Obj *o, const Ent *e) {
+ int saved = 0;
+ for (int b = 0; b < 4; b++) saved |= persist_get(e->persist + b) << b;
+ o->hits = (int8_t)(saved ? saved - 1 : (int)e->p0);
+ anim_play(&o->anim, e->p3 == 2 ? CLIP_GEOROCK_IDLE_2 : CLIP_GEOROCK_IDLE_1);
+ if (o->hits < 1) georock_broken(o, e);
+ else o->state = GR_IDLE, o->t = rand_range(1.5f, 4);
+}
+
+static void georock_hit(Obj *o, const Ent *e, float direction) {
+ if (o->state != GR_IDLE) return;
+ geo_fling_at(0, (int)e->p1, e->x0, e->y0, 23, 30, 80, 100, 0.25f);
+ o->hits--;
+ georock_save(o, e);
+ if (o->hits <= 0) {
+ o->state = GR_DESTROY, o->t = DT; /* (Pause Frame) */
+ return;
+ }
+ o->state = GR_HIT, o->t = 0.1f;
+ (void)direction;
+}
+
+static void georock_tick(Obj *o, const Ent *e) {
+ switch (o->state) {
+ case GR_IDLE:
+ if ((o->t -= DT) <= 0) {
+ /* Gleam, then Idle again */
+ anim_play_from_frame(&o->anim, georock_clip(e, 0), 0);
+ o->t = rand_range(1.5f, 4);
+ }
+ break;
+ case GR_HIT:
+ case GR_RETURN:
+ /* ObjectJitter, as it recoils and comes back */
+ o->jx = rand_range(-0.05f, 0.05f), o->jy = rand_range(-0.05f, 0.05f);
+ if ((o->t -= DT) <= 0) {
+ if (o->state == GR_HIT) o->state = GR_RETURN, o->t = 0.1f;
+ else o->state = GR_IDLE, o->t = rand_range(1.5f, 4), o->jx = o->jy = 0;
+ }
+ break;
+ case GR_DESTROY:
+ if ((o->t -= DT) <= 0) {
+ cam_shake(SHAKE_ENEMY_KILL);
+ geo_fling_at(0, (int)e->p2, e->x0, e->y0, 23, 30, 80, 100, 0.25f);
+ georock_broken(o, e);
+ }
+ break;
+ }
+}
+
+/* ---------------------------------------------------------------- chests (Chest Control) */
+enum { CH_IDLE, CH_OPEN, CH_SPAWNED, CH_OPENED };
+
+static void chest_opened(Obj *o, const Ent *e) {
+ o->state = CH_OPENED;
+ for (int c = e->a; c < e->a + e->group; c++) phys_collider_enable(c, false);
+}
+
+static void chest_enter(Obj *o, const Ent *e) {
+ o->sprite = (int16_t)e->s0;
+ anim_play(&o->anim, CLIP_CHEST_IDLE);
+ o->state = CH_IDLE;
+ if (persist_get(e->persist)) chest_opened(o, e);
+}
+
+static void chest_hit(Obj *o, const Ent *e) {
+ if (o->state != CH_IDLE) return;
+ /* Open */
+ FREEZE_MOMENT_1();
+ cam_shake(SHAKE_ENEMY_KILL);
+ persist_set(e->persist);
+ anim_play(&o->anim, CLIP_CHEST_OPEN);
+ o->state = CH_OPEN;
+}
+
+static void chest_tick(Obj *o, const Ent *e) {
+ if (o->state == CH_OPEN && (o->anim.events & ANIM_TRIGGER)) {
+ /* Spawn Items: the geo, the item */
+ geo_fling_at(0, (int)e->p0, e->x0, e->y0, 25, 38, 78, 102, 1);
+ geo_fling_at(1, (int)e->p1, e->x0, e->y0, 25, 38, 78, 102, 1);
+ geo_fling_at(2, (int)e->p2, e->x0, e->y0, 25, 38, 78, 102, 1);
+ o->state = CH_SPAWNED;
+ } else if (o->state == CH_SPAWNED && (o->anim.events & ANIM_DONE))
+ chest_opened(o, e);
+}
+
+static void chest_draw(const Obj *o, const Ent *e) {
+ Inst in;
+ if (o->state != CH_OPENED) {
+ sprite_inst(o->anim.sprite, e->x0, e->y0, e->x1, 1, 1, 0, &in);
+ gfx_actor(&in, SORT_KEY(0, 0));
+ return;
+ }
+ const Ent *p = e + 1 + e->s1;
+ for (int i = 0; i < (int)e->p3; i++, p++) {
+ sprite_inst(p->s0, e->x0 + p->x0, e->y0 + p->y0, p->y1, 1, 1, 0, &in);
+ gfx_actor(&in, SORT_KEY(0, 0));
+ }
+}
+
/* ---------------------------------------------------------------- the room */
void obj_enter(void) {
nobjs = 0;
@@ -149,18 +314,45 @@ void obj_enter(void) {
const Ent *es = room_ents(&n);
for (int i = 0; i < n && nobjs < MAX_OBJS; i++) {
if (es[i].type != ENT_OBJ) continue;
+ if (es[i].flags == OK_ENEMY) continue; /* (enemy.c's) */
Obj *o = &objs[nobjs++];
- o->kind = es[i].flags, o->state = 0, o->ent = (uint16_t)i;
+ memset(o, 0, sizeof *o);
+ o->kind = es[i].flags, o->ent = (uint16_t)i;
if (o->kind == OK_BREAKABLE) breakable_enter(o, &es[i]);
+ else if (o->kind == OK_GREAT_DOOR) great_door_enter(o, &es[i]);
+ else if (o->kind == OK_GEO_ROCK) georock_enter(o, &es[i]);
+ else if (o->kind == OK_CHEST) chest_enter(o, &es[i]);
}
}
void obj_tick(void) {
+ for (int k = 0; k < nobjs; k++) {
+ Obj *o = &objs[k];
+ const Ent *e = ent_at(o->ent);
+ o->anim.events = 0;
+ anim_update(&o->anim, DT);
+ if (o->kind == OK_GREAT_DOOR) great_door_tick(o, e);
+ else if (o->kind == OK_GEO_ROCK) georock_tick(o, e);
+ else if (o->kind == OK_CHEST) chest_tick(o, e);
+ }
pieces_tick();
enemies_update();
}
void obj_draw(void) {
+ for (int k = 0; k < nobjs; k++) {
+ const Obj *o = &objs[k];
+ const Ent *e = ent_at(o->ent);
+ Inst in;
+ if (o->kind == OK_GREAT_DOOR && o->shown && o->state != GD_OPEN) {
+ sprite_inst(o->sprite, e->x0, e->y0, e->x1, 1, 1, 0, &in);
+ gfx_actor(&in, SORT_KEY(0, 0));
+ } else if (o->kind == OK_GEO_ROCK) {
+ sprite_inst_rot(o->anim.sprite, e->x0 + o->jx, e->y0 + o->jy, e->x1, 1, 1, e->y1, 0, &in);
+ gfx_actor(&in, SORT_KEY(0, 0));
+ } else if (o->kind == OK_CHEST)
+ chest_draw(o, e);
+ }
pieces_draw();
enemies_draw();
}
@@ -188,6 +380,9 @@ int obj_nail(const float *pts, int npts, float direction) {
if (!touched || (swing_hit[k >> 5] >> (k & 31) & 1)) continue;
swing_hit[k >> 5] |= 1u << (k & 31);
if (o->kind == OK_BREAKABLE) breakable_hit(o, e, direction);
+ else if (o->kind == OK_GREAT_DOOR) great_door_hit(o, e);
+ else if (o->kind == OK_GEO_ROCK) georock_hit(o, e, direction);
+ else if (o->kind == OK_CHEST) chest_hit(o, e);
}
return out;
}
diff --git a/games/hollowknight/src/world.c b/games/hollowknight/src/world.c
index dfbb10b4..03cc6dbd 100644
--- a/games/hollowknight/src/world.c
+++ b/games/hollowknight/src/world.c
@@ -47,6 +47,10 @@ static EntState es[MAX_ENTS];
static bool hero_in_position;
bool persist_get(int i) { return i != NO_PERSIST && (g_pd.persist[i >> 3] >> (i & 7) & 1); }
+void persist_clear(int i) {
+ if (i != NO_PERSIST) g_pd.persist[i >> 3] &= (uint8_t)~(1 << (i & 7));
+}
+
void persist_set(int i) {
if (i != NO_PERSIST) g_pd.persist[i >> 3] |= (uint8_t)(1 << (i & 7));
}
diff --git a/games/hollowknight/tools/actors.py b/games/hollowknight/tools/actors.py
index 4450f393..43718344 100644
--- a/games/hollowknight/tools/actors.py
+++ b/games/hollowknight/tools/actors.py
@@ -24,6 +24,8 @@ KNIGHT = ("resources.assets", 20600, [
ACTORS = {"knight": KNIGHT,
"crawler": ("sharedassets6.assets", 1113, None),
"buzzer": ("sharedassets6.assets", 1150, None),
+ "georock": ("sharedassets6.assets", 1149, None),
+ "chest": ("sharedassets6.assets", 1148, None),
"geo": ("resources.assets", 23266, ["Small Idle", "Small Air", "Med Idle", "Med Air", "Large Idle", "Large Air"])}
# sprites of prefab objects the game draws itself: name -> (file, prefab, object, resolution)
@@ -87,6 +89,16 @@ def unity_sprites(keys):
object's scale."""
out = []
for level, exts, fid, pid, scale, res in keys:
+ if level == "tk2d":
+ path, col, name = exts, fid, pid
+ c = tk2d.collection(path, col)
+ sid = next(i for i, dd in enumerate(c["spriteDefinitions"]) if unity.S(dd["name"]) == name)
+ img, lx, ty, upp, (wu, hu) = tk2d.sprite_image(path, c, sid)
+ w, h = max(1, round(img.width * upp * K0 * scale)), max(1, round(img.height * upp * K0 * scale))
+ arr = np.asarray(img.resize((w, h), Image.BOX)).copy()
+ out.append({"key": (path, col, sid), "job": art.ImageJob(arr, "tk2d/%s" % name), "lx": lx * scale,
+ "ty": ty * scale, "tu": wu * scale / w, "tv": hu * scale / h})
+ continue
s = unity.sprite(level, list(exts), fid, pid)
img = unity.sprite_image(s)
wu, hu = s.w / s.ppu * scale, s.h / s.ppu * scale
diff --git a/games/hollowknight/tools/ents.py b/games/hollowknight/tools/ents.py
index 7440752b..e097d5f5 100644
--- a/games/hollowknight/tools/ents.py
+++ b/games/hollowknight/tools/ents.py
@@ -8,7 +8,7 @@ import numpy as np
ENT_CAMLOCK, ENT_GATE, ENT_HAZARD_MARKER, ENT_RESPAWN, ENT_HAZARD_TRIGGER, ENT_MASK, ENT_DAMAGE, ENT_SHAPE, ENT_BOX, \
ENT_OBJ, ENT_PIECE = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
# objects (ENT_OBJ's flags: src/obj.c)
-OK_BREAKABLE, OK_ENEMY = 1, 2
+OK_BREAKABLE, OK_ENEMY, OK_GREAT_DOOR, OK_GEO_ROCK, OK_CHEST = 1, 2, 3, 4, 5
# enemies (an OK_ENEMY's a: src/enemy.c), by their FSM and animation library
EK_CRAWLER, EK_BUZZER = 1, 2
ENEMIES = {("Crawler", 1113): EK_CRAWLER, ("chaser", 1150): EK_BUZZER}
@@ -20,19 +20,23 @@ MAX_GROUPS = 256
MK_SECRET, MK_REMASK, MK_SIMPLE = 1, 2, 4
# flags
CL_PREVENT_UP, CL_PREVENT_DOWN, CL_MAX_PRIORITY = 1, 2, 4
-G_DOOR, G_ENTER_RIGHT, G_ENTER_LEFT, G_DONT_WALK_OUT, G_NON_HAZARD = 1, 2, 4, 8, 16
+G_DOOR, G_ENTER_RIGHT, G_ENTER_LEFT, G_DONT_WALK_OUT, G_NON_HAZARD, G_HARD_LAND = 1, 2, 4, 8, 16, 32
FACING_RIGHT = 1
REC = "<BBBBHHffffffffHH" # type, flags, group, group2, a, persist, box (x0, y0, x1, y1), p0..p3, s0, s1
NO_PERSIST = 0xFFFF
class Persist:
- """The objects whose state a save keeps (PersistentBoolItem): one bit each."""
+ """The objects whose state a save keeps (PersistentBoolItem): one bit each (or a few: a number)."""
def __init__(self):
- self.keys = {}
+ self.keys, self.n = {}, 0
- def id(self, room, path):
- return self.keys.setdefault((room, path), len(self.keys))
+ def id(self, room, path, bits=1):
+ if (room, path) not in self.keys:
+ self.keys[(room, path)] = self.n
+ self.n += bits
+ assert self.n <= 1024, self.n # (src/game.h: MAX_PERSIST)
+ return self.keys[(room, path)]
class Strings:
@@ -60,7 +64,13 @@ class Sprites:
def id(self, d, ref, scale, res=1.0):
"""(res: its texture's resolution, as a part of the screen's: smooth sprites can be stretched)"""
- key = (d["level"], tuple(d["externals"]), ref[0], ref[1], round(scale, 3), res)
+ return self._add((d["level"], tuple(d["externals"]), ref[0], ref[1], round(scale, 3), res))
+
+ def tk2d(self, path, col, name, scale=1.0):
+ """A 2D Toolkit sprite of a collection (file, path id), by name."""
+ return self._add(("tk2d", path, col, name, round(scale, 3), 1.0))
+
+ def _add(self, key):
if key not in self.index:
self.index[key] = len(self.list)
self.list.append(key)
@@ -308,6 +318,69 @@ def _enemy(o, by_id, persist, name):
return [head] + out
+def _tk2d_sprite(d, o):
+ """An object's tk2dSprite -> (its collection's file, path id, the sprite's name) or None."""
+ import tk2d, unity
+ v = next((c.get("v") for c in o["c"] if c.get("class") == "tk2dSprite" and c.get("v")), None)
+ if not v or not v.get("collection"):
+ return None
+ fid, pid = v["collection"]
+ path = d["externals"][fid - 1] if fid else d["level"]
+ col = tk2d.collection(path, pid)
+ return path, pid, unity.S(col["spriteDefinitions"][v["_spriteId"]]["name"])
+
+
+def _angle(o):
+ m = np.array(o["m3"]).reshape(3, 3)
+ return float(np.degrees(np.arctan2(m[1, 0], m[0, 0])))
+
+
+def _props(d, o, by_id, rooms, strings, persist, sprites, owners, name):
+ """Objects run by their own FSMs (src/obj.c) -> records, or None."""
+ import coll
+ var = lambda f, k, dflt: (f.get("vars", {}).get(k) or [0, dflt])[1]
+ hits = _hit_boxes(o, by_id)
+ c0, cn = coll.subtree_colliders(d, owners, o["id"]) if owners else (0, 0)
+ persistent = any(c.get("class") == "PersistentBoolItem" for c in o["c"])
+ f = _fsm(o, ("Great Door",))
+ if f:
+ sp = _tk2d_sprite(d, o)
+ ids = [sprites.tk2d(sp[0], sp[1], "door_v%02d" % k) for k in (1, 2, 3)]
+ return [rec(ENT_OBJ, OK_GREAT_DOOR, (o["pos"][0], o["pos"][1], o["pos"][2], 1), (ids[0], ids[1], ids[2],
+ rooms.index("Town") if "Town" in rooms else -1), a=c0, group=cn, s0=strings.id("left1"), s1=len(hits),
+ persist=persist.id(name, o["path"]) if persistent else NO_PERSIST)] + \
+ [rec(ENT_BOX, fl, box=b) for b, fl in hits]
+ f = _fsm(o, ("Geo Rock",))
+ if f:
+ variant = 2 if str(var(f, "Gleam Anim", "Gleam 1")).endswith("2") else 1
+ return [rec(ENT_OBJ, OK_GEO_ROCK, (o["pos"][0], o["pos"][1], o["pos"][2], _angle(o)),
+ (var(f, "Hits", 5), var(f, "Geo Per Hit", 2), var(f, "Final Payout", 5), variant), a=c0, group=cn,
+ s1=len(hits), persist=persist.id(name, o["path"], 4))] + [rec(ENT_BOX, fl, box=b) for b, fl in hits]
+ f = _fsm(o, ("Chest Control",))
+ if f:
+ # (opened: its Opened child's front and back sprites; inside, geo or a shiny item)
+ opened = [q for q in (by_id[c] for c in o.get("children", [])) if q["name"] == "Opened"]
+ parts = []
+ for q in (by_id[c] for c in opened[0].get("children", [])) if opened else []:
+ sp = _tk2d_sprite(d, q)
+ if sp:
+ parts.append(rec(ENT_PIECE, 0, (q["lpos"][0], q["lpos"][1], 0, o["pos"][2] + q["lpos"][2]),
+ s0=sprites.tk2d(*sp)))
+ sp = _tk2d_sprite(d, o)
+ shiny = 0
+ for q in d["objects"]:
+ if q["path"].startswith(o["path"] + "/Item/"):
+ sf = _fsm(q, ("Shiny Control",))
+ if sf and var(sf, "Charm", False):
+ shiny = var(sf, "Charm ID", 0)
+ return [rec(ENT_OBJ, OK_CHEST, (o["pos"][0], o["pos"][1], o["pos"][2], shiny),
+ (var(f, "Geo Small", 0), var(f, "Geo Med", 0), var(f, "Geo Large", 0), len(parts)), a=c0, group=cn,
+ s0=sprites.tk2d(*sp) if sp else 0, s1=len(hits),
+ persist=persist.id(name, o["path"]) if persistent else NO_PERSIST)] + \
+ [rec(ENT_BOX, fl, box=b) for b, fl in hits] + parts
+ return None
+
+
def room(d, rooms, strings, persist, name, sprites=None, owners=None):
"""-> (packed records, {object id: render group}). owners: each collider's object (coll.room); sprites: where the
objects' own sprites go (Sprites)."""
@@ -358,7 +431,7 @@ def room(d, rooms, strings, persist, name, sprites=None, owners=None):
persist=persist.id(name, o["path"]) if persistent else NO_PERSIST))
recs += _more_boxes(o)
classes = {c.get("class") for c in o["c"]}
- en = _enemy(o, by_id, persist, name)
+ en = _enemy(o, by_id, persist, name) or _props(d, o, by_id, rooms, strings, persist, sprites, owners, name)
if en:
recs += en
br = next((c for c in o["c"] if c.get("class") == "Breakable" and c.get("v") is not None), None)
@@ -427,12 +500,20 @@ def room(d, rooms, strings, persist, name, sprites=None, owners=None):
continue
fl = (G_DOOR if v.get("isADoor") else 0) | (G_ENTER_RIGHT if v.get("alwaysEnterRight") else 0) | \
(G_ENTER_LEFT if v.get("alwaysEnterLeft") else 0) | (G_DONT_WALK_OUT if v.get("dontWalkOutOfDoor") else 0) | \
- (G_NON_HAZARD if v.get("nonHazardGate") else 0)
+ (G_NON_HAZARD if v.get("nonHazardGate") else 0) | (G_HARD_LAND if v.get("hardLandOnExit") else 0)
target = v.get("targetScene") or ""
ti = rooms.index(target) if target in rooms else 0xFFFF
- recs.append(rec(ENT_GATE, fl, box, (float(v.get("entryDelay", 0)), 0, 0, 0), a=ti, s0=strings.id(o["name"]),
- s1=strings.id(v.get("entryPoint") or "")))
+ # (its respawn marker: a component; the record of its object)
+ ref = v.get("respawnMarker")
+ mid = ref[1] if isinstance(ref, (list, tuple)) else None
+ marker = next((marker_index[oo["id"]] for oo in objs for cc in oo["c"] if cc.get("pid") == mid and
+ oo["id"] in marker_index), -1)
+ off = v.get("entryOffset") or {"x": 0, "y": 0}
+ recs.append(rec(ENT_GATE, fl, box, (float(v.get("entryDelay", 0)), off["x"], off["y"], marker + 1), a=ti,
+ s0=strings.id(o["name"]), s1=strings.id(v.get("entryPoint") or "")))
recs += _more_boxes(o)
+ # (the gate's own place, where the Knight comes in: a box record flagged 1, not part of its trigger)
+ recs.append(rec(ENT_BOX, 1, (o["pos"][0], o["pos"][1], o["pos"][0], o["pos"][1])))
elif cls == "HazardRespawnTrigger":
box = _trigger(o)
ref = v.get("respawnMarker")