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
Celeste: the whole climb, as an app of its own
Mason Chen0e0e4e647704
diff --git a/Makefile b/Makefileindex 680f6696..c1972119 100644--- a/Makefile+++ b/Makefile@@ -142,7 +142,8 @@ APP_portal = games/portal/output/portal.nwa:PortalReturns.nwaAPP_chess = games/chess/output/chess.nwa:NumChess.nwaAPP_tetris = games/tetris/tetris/target/thumbv7em-none-eabihf/release/tetris:Tetris.nwaAPP_numvisuals = games/numvisuals/output/numvisuals.nwa:NumVisuals.nwa-# too big to share the calculator's app space with NumPlay: only on its own+# too big to share the calculator's app space with NumPlay: only on their own+APP_celeste = games/celeste/output/celeste.nwa:Celeste.nwaAPP_championisland = games/championisland/output/championisland.nwa:ChampionIsland.nwaapps: | $(B)@@ -154,6 +155,7 @@ apps: | $(B)$(MAKE) -C games/portal build NWLINK="$(NWLINK)"$(MAKE) -C games/chess build NWLINK="$(NWLINK)"$(MAKE) -C games/numvisuals build NWLINK="$(NWLINK)"+ $(MAKE) -C games/celeste build NWLINK="$(NWLINK)"$(MAKE) -C games/championisland build NWLINK="$(NWLINK)"cd games/tetris/tetris && NWLINK="$(NWLINK)" $(CARGO) build --release --quietcp $(word 1,$(subst :, ,$(APP_numdash))) $(B)/apps/$(word 2,$(subst :, ,$(APP_numdash)))@@ -165,6 +167,7 @@ apps: | $(B)cp $(word 1,$(subst :, ,$(APP_chess))) $(B)/apps/$(word 2,$(subst :, ,$(APP_chess)))cp $(word 1,$(subst :, ,$(APP_tetris))) $(B)/apps/$(word 2,$(subst :, ,$(APP_tetris)))cp $(word 1,$(subst :, ,$(APP_numvisuals))) $(B)/apps/$(word 2,$(subst :, ,$(APP_numvisuals)))+ cp $(word 1,$(subst :, ,$(APP_celeste))) $(B)/apps/$(word 2,$(subst :, ,$(APP_celeste)))cp $(word 1,$(subst :, ,$(APP_championisland))) $(B)/apps/$(word 2,$(subst :, ,$(APP_championisland)))arm-none-eabi-strip --strip-unneeded $(B)/apps/Tetris.nwadiff --git a/README.md b/README.mdindex 893f32bc..125acd0c 100644--- a/README.md+++ b/README.md@@ -7,11 +7,12 @@<p align="center"><b>17 free games for your NumWorks calculator, in one app.</b><br>NumDash, Crossy Road, NumBlocks, NumDrive, Balatro, Buckshot Roulette, Portal Returns, Tetris, Chess, Flappy Bird, Pac-Man, Snake, Connect Four, Solitaire, 2048, Minesweeper and Block Breaker, plus NumVisuals: moving backgrounds with a clock, a timer and more.<br>- And <b>Champion Island</b>, the Doodle Champion Island Games, as an app of its own.+ And two apps of their own: <b>Celeste</b>, the whole climb up Celeste Mountain, and <b>Champion Island</b>, the Doodle Champion Island Games.</p><p align="center">- <b>New: <a href="#new-numblocks">NumBlocks</a></b>. Mine, craft and survive in a world like Minecraft 1.8.+ <b>New: <a href="#new-numblocks">NumBlocks</a></b>. Mine, craft and survive in a world like Minecraft 1.8.<br>+ <b>And <a href="#new-celeste">Celeste</a></b>. Climb Celeste Mountain with Madeline, every chapter, B-side and C-side.</p><p align="center">@@ -57,6 +58,29 @@ Mine, craft and survive in a world like Minecraft 1.8, right on your calculator.+## New: Celeste++<p align="center">+ <img src="docs/media/celeste.gif" width="640" alt="Celeste: Madeline dashing through the Forsaken City, climbing Golden Ridge and the Summit">+</p>++Climb Celeste Mountain with Madeline, right on your calculator.++- **The whole climb:** the Prologue, all eight chapters, the Epilogue, and every B-side and C-side.+- **Madeline moves like in the game:** the same jumps, dashes, climbing and wall jumps.+- **The story:** every conversation with Theo, Granny, Oshiro and Badeline, with their portraits.+- **Everything to find:** strawberries, crystal hearts, cassettes and the Summit's gems.++<p align="center">+ <a href="https://github.com/Mason363/NumPlay/releases/latest/download/Celeste.nwa"><img src="https://img.shields.io/badge/Download-Celeste.nwa-AC3232?style=for-the-badge" alt="Download Celeste.nwa"></a>+</p>++<p align="center">+ It fills the calculator's app space, so it comes on its own. <a href="games/celeste/README.md"><b>More about Celeste</b></a> · <a href="docs/play.md#celeste"><b>How to play</b></a>+</p>+++## Go support the original games!NumPlay is a fan project, made out of love for these games and for the NumWorks calculator. It is not meant to replace any of them. If you enjoy a game here, go play the original and support the people who made it.@@ -99,6 +123,10 @@ Click a file to download it. Not sure which one? Take the first.<td width="120" align="center"><img src="docs/media/thumb_numblocks.png" width="112" alt="NumBlocks"></td><td><a href="https://github.com/Mason363/NumPlay/releases/latest/download/NumBlocks.nwa">NumBlocks.nwa</a><br>Only NumBlocks: mine, craft, survive (<a href="games/numblocks/README.md">more</a>)</td></tr>+ <tr>+ <td width="120" align="center"><img src="docs/media/thumb_celeste.png" width="112" alt="Celeste"></td>+ <td><a href="https://github.com/Mason363/NumPlay/releases/latest/download/Celeste.nwa">Celeste.nwa</a><br>Celeste: the whole climb up Celeste Mountain. It fills the calculator's app space, so it comes on its own, not inside NumPlay (<a href="games/celeste/README.md">more</a>)</td>+ </tr><tr><td width="120" align="center"><img src="docs/media/thumb_numdrive.png" width="112" alt="NumDrive"></td><td><a href="https://github.com/Mason363/NumPlay/releases/latest/download/NumDrive.nwa">NumDrive.nwa</a><br>Only NumDrive: drive, flip, finish</td>@@ -196,6 +224,10 @@ You need your calculator, its USB cable, and a computer with **Google Chrome** o<td><img src="docs/media/numblocks.gif" alt="NumBlocks: chopping a birch tree, then building a pillar of planks"></td><td><img src="docs/media/numblocks_night.gif" alt="NumBlocks: sunset, then a zombie walks up and is beaten with an iron sword"></td></tr>+ <tr>+ <td><img src="docs/media/celeste.gif" alt="Celeste: Madeline dashing through the Forsaken City, climbing Golden Ridge and the Summit"></td>+ <td><img src="games/celeste/docs/reflection.png" width="100%" alt="Celeste: Badeline fights back in Reflection"></td>+ </tr><tr><td><img src="docs/media/numdrive.gif" alt="NumDrive gameplay"></td><td><img src="docs/media/balatro.gif" alt="Balatro: a Four of a Kind scoring with five Jokers"></td>@@ -242,6 +274,7 @@ You need your calculator, its USB cable, and a computer with **Google Chrome** o- **[gd3ds](https://github.com/AleFunky/gd3ds)** by AleFunky and friends, whose research into Geometry Dash made NumDash possible. Clubstep, Deadlocked and Dash also rely on [gdsolver](https://github.com/gdsolver/gdsolver)'s measurements of Geometry Dash 2.2, level data from [gmdkit](https://github.com/UHDanke/gmdkit) by HDanke and checks against [GDRWeb](https://github.com/iliasHDZ/GDRWeb) by IliasHDZ.- **Balatro** by LocalThunk inspired NumPlay's Balatro, which uses art adapted from the game and the **m6x11** font by Daniel Linssen.- **Minecraft** by Mojang inspired NumBlocks, which uses Minecraft 1.8.8's textures, font and screens and makes its worlds the way Minecraft 1.8.8 does.+- **Celeste** inspired NumPlay's Celeste, which uses the game's own pictures, maps, texts and fonts. Not affiliated with Maddy Makes Games.- **Buckshot Roulette** by Mike Klubnika inspired NumPlay's Buckshot Roulette, whose scenes are rendered from the game through the Open Buckshot Roulette project (1503Dev). Fonts: Fake Receipt by Ray Larabie and Dot Matrix by Dionaea.- The **Doodle Champion Island Games** (2021) inspired Champion Island, which uses the doodle's own pictures, maps and texts from the [Google-Doodle-Champion-Island](https://github.com/potherca-blog/Google-Doodle-Champion-Island) archive by potherca-blog, and the **PixelMplus** font by Itou Hiroki ([license](LICENSES/PixelMplus.txt)).- **[Portal Returns](https://www.cemetech.net/downloads/files/1313/x1313)** by MateoConLechuga for the TI-84 Plus CE, with sprites by CKH4 and Portal Prelude chambers ported by Unicorn from BuilderBoy's original.@@ -253,4 +286,4 @@ NumPlay is licensed under the [GNU General Public License v3.0](LICENSE). CopyriCode and fonts from others keep their own licenses: the `UNLICENSE` files in the games' folders and the [LICENSES](LICENSES) folder. The names, artwork and music of the games NumPlay is inspired by belong to their makers and are not covered by it.-<sub>Unofficial fan games, not affiliated with NumWorks, RobTop Games (Geometry Dash), Hipster Whale (Crossy Road), the makers of Drive Mad, LocalThunk or Playstack (Balatro), Mike Klubnika or Critical Reflex (Buckshot Roulette), Mojang or Microsoft (Minecraft), MateoConLechuga (Portal Returns), Valve (Portal), .GEARS (Flappy Bird), Bandai Namco (Pac-Man), Hasbro (Connect Four), Google (Snake, Solitaire, Block Breaker, Doodle Champion Island Games), STUDIO4°C or Microsoft (Minesweeper). Tetris is a trademark of The Tetris Company, Minecraft of Mojang Synergies AB, Pac-Man of Bandai Namco and Connect Four of Hasbro.</sub>+<sub>Unofficial fan games, not affiliated with NumWorks, RobTop Games (Geometry Dash), Hipster Whale (Crossy Road), the makers of Drive Mad, LocalThunk or Playstack (Balatro), Mike Klubnika or Critical Reflex (Buckshot Roulette), Mojang or Microsoft (Minecraft), Maddy Makes Games (Celeste), MateoConLechuga (Portal Returns), Valve (Portal), .GEARS (Flappy Bird), Bandai Namco (Pac-Man), Hasbro (Connect Four), Google (Snake, Solitaire, Block Breaker, Doodle Champion Island Games), STUDIO4°C or Microsoft (Minesweeper). Tetris is a trademark of The Tetris Company, Minecraft of Mojang Synergies AB, Pac-Man of Bandai Namco and Connect Four of Hasbro.</sub>diff --git a/docs/media/celeste.gif b/docs/media/celeste.gifnew file mode 100644index 00000000..050546daBinary files /dev/null and b/docs/media/celeste.gif differdiff --git a/docs/media/thumb_celeste.png b/docs/media/thumb_celeste.pngnew file mode 100644index 00000000..8594860dBinary files /dev/null and b/docs/media/thumb_celeste.png differdiff --git a/docs/play.md b/docs/play.mdindex ed2ba623..50c0f811 100644--- a/docs/play.md+++ b/docs/play.md@@ -73,6 +73,25 @@ The left thumb looks with the arrows (shift and alpha are just under them), the<br clear="right">+## Celeste++<img src="media/celeste.gif" width="320" align="right" alt="Celeste: Madeline dashing through the Forsaken City">++Celeste comes as its own app, `Celeste.nwa`: it is too big to share the calculator with NumPlay.++| Key | What it does |+| --- | --- |+| **Arrows** | Move, and aim the dash |+| **OK** | Jump |+| **⌫** | Dash, and talk |+| **toolbox** | Grab, climb |+| **Back** | Pause |+| **Home** | Save and quit |++Choose Climb, then a chapter, then Start. Madeline can dash once in the air (twice later on), and grab and climb walls until she gets tired. In menus, **OK** or **EXE** confirms and **Back** goes back. The first time you open Celeste it shows these keys; you can change them in Options, then Keyboard Config. Home saves and quits, and Climb then offers Continue. Your progress is also copied into `celeste_saves.py`, so installing the app again doesn't erase it.++<br clear="right">+## NumDrive<img src="media/numdrive.gif" width="320" align="right" alt="NumDrive gameplay">diff --git a/games/celeste/.gitignore b/games/celeste/.gitignorenew file mode 100644index 00000000..643bd909--- /dev/null+++ b/games/celeste/.gitignore@@ -0,0 +1,3 @@+output/+build/+__pycache__/diff --git a/games/celeste/Makefile b/games/celeste/Makefilenew file mode 100644index 00000000..ad8b6594--- /dev/null+++ b/games/celeste/Makefile@@ -0,0 +1,64 @@+# Celeste for the NumWorks calculator.+# make output/celeste.nwa+# make check link it like the calculator does (output/celeste.bin)+# make host build/play: the game on a computer, for tests and screenshots+# make test checks of the host build (tests/check.py)+# make data regenerate src/data.bin from the game (CELESTE=<its Content folder>)+Q ?= @+CC = arm-none-eabi-gcc+NWLINK ?= npx --yes -- [email protected]+STRIP ?= arm-none-eabi-strip --strip-unneeded+BUILD_DIR = output+GAME = src/res.c src/gfx.c src/util.c src/ent.c src/level.c src/tiles.c src/style.c src/player.c src/entities.c \+ src/fx.c src/ptypes.c src/font.c src/light.c src/spinner.c src/berry.c src/save.c src/text.c src/wipe.c src/cutscene.c src/npc.c src/talk.c src/heart.c src/cassette.c src/dust.c src/breath.c src/menu.c $(wildcard src/ch*.c) src/game.c \+ src/lzma/LzmaDec.c+SRC = $(GAME) src/plat_eadk.c src/main.c+HEADERS = $(wildcard src/*.h) ../common/epsilon_app.h ../common/epsilon_files.h++CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DDATA_BIN='"src/data.bin"'+CFLAGS += -O2 -Wall -Wextra -Wno-unused-parameter -fno-math-errno -fsingle-precision-constant+CFLAGS += -fno-tree-loop-distribute-patterns -flto -fno-fat-lto-objects -fwhole-program -fvisibility=internal+CFLAGS += -ffunction-sections -fdata-sections $(EXTRA)+LDFLAGS = -Wl,--relocatable -nostartfiles --specs=nano.specs+LDFLAGS += -Wl,-e,main -Wl,-u,eadk_app_name -Wl,-u,eadk_app_icon -Wl,-u,eadk_api_level+LDFLAGS += -Wl,--gc-sections -flinker-output=nolto-rel++.PHONY: build check clean host data test+build: $(BUILD_DIR)/celeste.nwa++check: $(BUILD_DIR)/celeste.nwa+ $(Q) $(NWLINK) nwa-bin --ram-length 153676 $< $(BUILD_DIR)/celeste.bin+ @echo "BIN $(BUILD_DIR)/celeste.bin: $$(wc -c < $(BUILD_DIR)/celeste.bin) bytes"++$(BUILD_DIR)/data.o: src/data.S src/data.bin | $(BUILD_DIR)+ $(Q) $(CC) -c -DDATA_BIN='"src/data.bin"' $< -o $@++$(BUILD_DIR)/celeste.nwa: $(SRC) $(HEADERS) $(BUILD_DIR)/icon.o $(BUILD_DIR)/data.o+ @echo "LD $@"+ $(Q) $(CC) $(CFLAGS) $(LDFLAGS) $(SRC) $(BUILD_DIR)/data.o $(BUILD_DIR)/icon.o -lm -o $@+ $(Q) $(STRIP) $@+ $(Q) arm-none-eabi-size $@++$(BUILD_DIR)/icon.o: src/icon.png | $(BUILD_DIR)+ @echo "ICON $<"+ $(Q) $(NWLINK) png-icon-o $< $@++$(BUILD_DIR):+ $(Q) mkdir -p $@++HOST_FLAGS = -std=gnu11 -O1 -g -Wall -Wextra -Wno-unused-parameter -Isrc -DHOST+HOST_OUT ?= build/play+host: $(HOST_OUT)+$(HOST_OUT): $(GAME) src/plat_host.c tests/play.c $(HEADERS)+ $(Q) mkdir -p $(dir $@) build/host-saves+ $(Q) cc $(HOST_FLAGS) -fsanitize=address,undefined $(GAME) src/plat_host.c tests/play.c -lm -o $@+ @echo "HOST $@"++test: $(HOST_OUT)+ python3 tests/check.py $(HOST_OUT) src/data.bin++data:+ cd tools && python3 pack.py++clean:+ $(Q) rm -rf $(BUILD_DIR) builddiff --git a/games/celeste/README.md b/games/celeste/README.mdnew file mode 100644index 00000000..c2717b4f--- /dev/null+++ b/games/celeste/README.md@@ -0,0 +1,87 @@+> **Celeste is a [NumPlay](../../README.md) game that comes on its own.** It fills the calculator's whole app space, so it can't sit next to NumPlay. Get `Celeste.nwa` from the [latest release](https://github.com/Mason363/NumPlay/releases/latest).++<p align="center">+ <img src="src/icon.png" width="84" alt="Celeste icon">+</p>++<h1 align="center">Celeste</h1>++<p align="center">+ <b>Climb Celeste Mountain with Madeline, on the NumWorks calculator.</b><br>+ The Prologue, all eight chapters, the Epilogue, and every B-side and C-side.+</p>++<p align="center">+ <a href="https://github.com/Mason363/NumPlay/releases/latest/download/Celeste.nwa"><b>Download Celeste.nwa</b></a>+ · <a href="#controls">Controls</a>+</p>++<p align="center">+ <img src="../../docs/media/celeste.gif" width="640" alt="Madeline dashing through the Forsaken City, climbing Golden Ridge and the Summit">+</p>++## Highlights++* **The whole climb:** the Prologue, Forsaken City, Old Site, Celestial Resort, Golden Ridge, Mirror Temple, Reflection, The Summit, the Epilogue and Core, with all their rooms, B-sides and C-sides.+* **Madeline moves like in the game:** the same jumps, dashes, climbing and wall jumps, down to the frame.+* **The story:** every conversation with Theo, Granny, Oshiro and Badeline, with their portraits, and the scenes between, from the campfires to the hug in Reflection.+* **Everything to find:** strawberries, golden strawberries, crystal hearts with their poems, cassettes that unlock the B-sides, the Summit's gems.+* **The game's look:** its rooms, decorations and backgrounds, from dust bunnies and dream blocks to the Summit's wind.+* **Saved as you go:** Home saves and quits, and Climb then offers Continue. Your progress is also copied into `celeste_saves.py`, so installing the app again doesn't erase it.++<table>+ <tr>+ <td align="center"><img src="docs/forsaken.png" width="390" alt="Forsaken City"><br><sub>Forsaken City</sub></td>+ <td align="center"><img src="docs/oldsite.png" width="390" alt="Old Site"><br><sub>Old Site: a night at the camp with Theo</sub></td>+ </tr>+ <tr>+ <td align="center"><img src="docs/resort.png" width="390" alt="Celestial Resort"><br><sub>The Celestial Resort and its dust bunnies</sub></td>+ <td align="center"><img src="docs/ridge.png" width="390" alt="Golden Ridge"><br><sub>Golden Ridge</sub></td>+ </tr>+ <tr>+ <td align="center"><img src="docs/temple.png" width="390" alt="Mirror Temple"><br><sub>Mirror Temple</sub></td>+ <td align="center"><img src="docs/reflection.png" width="390" alt="Reflection"><br><sub>Reflection: Badeline fights back</sub></td>+ </tr>+ <tr>+ <td align="center"><img src="docs/summit.png" width="390" alt="The Summit"><br><sub>The Summit</sub></td>+ <td align="center"><img src="docs/core.png" width="390" alt="Core"><br><sub>Core</sub></td>+ </tr>+</table>++## How to play++Choose Climb, then a chapter, then Start. Each chapter is a series of rooms: get Madeline to the next one. She can dash once in the air (twice later on), and grab and climb walls until she gets tired. A death sends her back to the start of the room.++Back pauses: from there you can skip a scene, retry the room, restart the chapter, change the options, save and quit, or go back to the chapter select.++## Controls++| Key | What it does |+| --- | --- |+| Arrows | Move, and aim the dash |+| OK | Jump |+| ⌫ | Dash, and talk |+| Toolbox | Grab, climb |+| Back | Pause |+| Home | Save and quit |++In menus, OK or EXE confirms and Back goes back. You can change the keys in Options, then Keyboard Config. The game shows these keys the first time you open it, and again from Options, then Key Sheet.++## Good to know++* **One app at a time:** Celeste takes all the room the calculator has for apps. Installing it from the NumWorks website swaps out NumPlay and the other apps, and installing NumPlay again swaps it back out. Your progress in each one is kept.+* **No music:** the calculator has no speaker.+* **A few effects are simpler:** some glows, color filters and screen distortions are left out, and the Epilogue's last picture is shown at half size.+* **Farewell isn't here:** the free chapter added after the game's release doesn't fit.++## Credits++Inspired by Celeste, not affiliated with Maddy Makes Games.++* The pictures, animations, maps, texts and fonts come from the game's own files.++Made by Mason Chen as part of NumPlay.++## License++The game's code is licensed under the GNU General Public License v3.0: see the `LICENSE` file at the root of the repository. The game's pictures, animations, maps, texts and fonts keep their own terms (see Credits).diff --git a/games/celeste/docs/core.png b/games/celeste/docs/core.pngnew file mode 100644index 00000000..577ab1c5Binary files /dev/null and b/games/celeste/docs/core.png differdiff --git a/games/celeste/docs/forsaken.png b/games/celeste/docs/forsaken.pngnew file mode 100644index 00000000..421d4c7aBinary files /dev/null and b/games/celeste/docs/forsaken.png differdiff --git a/games/celeste/docs/oldsite.png b/games/celeste/docs/oldsite.pngnew file mode 100644index 00000000..a0678f1aBinary files /dev/null and b/games/celeste/docs/oldsite.png differdiff --git a/games/celeste/docs/reflection.png b/games/celeste/docs/reflection.pngnew file mode 100644index 00000000..12b24aa3Binary files /dev/null and b/games/celeste/docs/reflection.png differdiff --git a/games/celeste/docs/resort.png b/games/celeste/docs/resort.pngnew file mode 100644index 00000000..167e9f17Binary files /dev/null and b/games/celeste/docs/resort.png differdiff --git a/games/celeste/docs/ridge.png b/games/celeste/docs/ridge.pngnew file mode 100644index 00000000..01d63822Binary files /dev/null and b/games/celeste/docs/ridge.png differdiff --git a/games/celeste/docs/summit.png b/games/celeste/docs/summit.pngnew file mode 100644index 00000000..c075c05cBinary files /dev/null and b/games/celeste/docs/summit.png differdiff --git a/games/celeste/docs/temple.png b/games/celeste/docs/temple.pngnew file mode 100644index 00000000..7180e058Binary files /dev/null and b/games/celeste/docs/temple.png differdiff --git a/games/celeste/src/badeline.h b/games/celeste/src/badeline.hnew file mode 100644index 00000000..56b432f6--- /dev/null+++ b/games/celeste/src/badeline.h@@ -0,0 +1,138 @@+/* The story's shared pieces (src/ch6.c), for chapters 5 to 9: BadelineDummy+ * with its BadelineAutoAnimator, the NPC base class (its sprite, light,+ * talker and MoveTo), and coroutines nested in coroutines. */+#ifndef BADELINE_H+#define BADELINE_H+#include "npc.h"+#include "talk.h"++/* routines an entity runs for others (FloatTo, MoveTo): started now, they step from the next update; a+ * coroutine waits on one with CO_AWAIT (it goes on the update after the one the routine ends on) */+typedef struct { uint32_t start, done; uint8_t step; } Job;+static inline void job_start(Job *j) { j->start = g_frame, j->step = 1; }+static inline bool job_due(const Job *j) { return j->step && j->start != g_frame; }+static inline void job_end(Job *j) { j->step = 0, j->done = g_frame; }+static inline bool job_busy(const Job *j) { return j->step || j->done == g_frame; }+#define CO_AWAIT(c, job) \+ do { \+ CO_YIELD(c); \+ while (job_busy(job)) CO_YIELD(c); \+ } while (0)+#define NB_AWAIT(c, job) \+ do { \+ NB_YIELD(c); \+ while (job_busy(job)) NB_YIELD(c); \+ } while (0)++/* nested steps of the level and the player, as one statement */+#define CO_WALK(c, w, walk) \+ do { \+ (w) = (walk); \+ CO_NEST(c, player_walk(&g_player, &(w))); \+ } while (0)+#define NB_WALK(c, w, walk) \+ do { \+ (w) = (walk); \+ NB_NEST(c, player_walk(&g_player, &(w))); \+ } while (0)+#define CO_ZOOM_TO(c, st, focus, zoom, d) \+ do { \+ step_reset(st); \+ CO_NEST(c, zoom_to(st, focus, zoom, d)); \+ } while (0)+#define NB_ZOOM_TO(c, st, focus, zoom, d) \+ do { \+ step_reset(st); \+ NB_NEST(c, zoom_to(st, focus, zoom, d)); \+ } while (0)+#define CO_ZOOM_BACK(c, st, d) \+ do { \+ step_reset(st); \+ CO_NEST(c, zoom_back(st, d)); \+ } while (0)+static inline Walk walk_back(int x) { return (Walk){(float)x, 1, WALK_EXACT, WALK_BACKWARDS, 0, 0}; }+static inline Walk walk_mult(int x, float mult) { return (Walk){(float)x, mult, WALK_EXACT, 0, 0, 0}; }++/* CutsceneEntity: a new one of that class (its state begins with a Cutscene), started (Level.StartCutscene) */+Ent *scene_new(const EntClass *cls, void (*on_end)(Ent *e, bool skipped), bool fade_in_on_skip, bool ending_after);+void player_dummy(Player *p); /* StateMachine.State = Dummy; Locked = true */+void player_free(Player *p); /* Locked = false; State = Normal */+/* a textbox event's own coroutine: reset when another event starts */+Co *ev_co(Co *c, int8_t *last, int index);+/* Level.LoadLevel of another room at the end of the frame (its default spawn; the player comes in with the respawn+ * intro, which player_intro_none() undoes on the room's first update: IntroTypes.None) */+void level_goto(const char *room);+void player_intro_none(Player *p);+/* OshiroSprite's update: it turns to the side with the portrait's "side" animations (its wiggler: Pop) */+void oshiro_sprite_update(Sprite *s, Wiggler *w);+/* FadeWipe(wipeIn, done) with its duration; ScreenWipe.Wait(): CO_NEST(c, wipe_busy()) */+void fade_wipe(bool in, float duration, WipeDone done);+static inline bool wipe_busy(void) { return g_wipe.active && g_wipe.percent < 1; }++/* ---------------------------------------------------------------- PlayerHair (4 nodes) */+typedef struct {+ V2 n[4];+ float sx; /* drawn with: the sprite's |Scale.X|, its color and alpha */+ uint16_t color;+ uint8_t alpha, pad;+} Hair;+void hair_follow(Hair *h, const Sprite *s, V2 render_pos, int facing); /* PlayerHair.AfterUpdate */+void hair_draw(Hair *h, const Sprite *s, int facing, uint16_t color, float alpha); /* PlayerHair.Render */++/* ---------------------------------------------------------------- BadelineDummy */+typedef struct {+ Sprite spr; /* PlayerSprite(Badeline): spr.sx is Sprite.Scale.X */+ Hair hair; /* PlayerHair, BadelineOldsite.HairColor */+ V2 spr_pos, float_normal; /* Sprite.Position (Wave), floatNormal */+ V2 target, perp; /* FloatTo's */+ SineWave wave;+ Wiggler pop; /* the autoanimator's */+ Job job; /* FloatTo / WalkTo */+ float float_speed, float_accel, floatness, light_alpha, hair_alpha, speed, walk_speed;+ int8_t hair_facing, last_anim, turn_at_end;+ uint8_t auto_enabled, syncing, walking, face, fade_light, quick_end, no_light;+} BDummy;+Ent *bd_new(V2 at); /* new BadelineDummy(position), added */+void bd_appear(Ent *e); /* Appear(level, silent) */+void bd_vanish(Ent *e); /* Vanish(): particles, removed */+/* FloatTo(target, turnAtEndTo (0: none), faceDirection, fadeLight, quickEnd) and WalkTo(x, speed): CO_AWAIT on ->job */+void bd_float_to(Ent *e, V2 target, int turn_at_end, bool face, bool fade_light, bool quick_end);+void bd_walk_to(Ent *e, float x, float speed);+void bd_set_frame(Ent *e, int frame); /* Sprite.SetAnimationFrame */+#define BD(e) ST(e, BDummy)+void sprite_set_frame(Sprite *s, int frame);++/* ---------------------------------------------------------------- NPC */+enum { NPC_THEO05_ENTRANCE = 1, NPC_THEO05_MIRROR, NPC_THEO06_PLATEAU, NPC_GRANNY06, NPC_THEO06_ENDING, NPC_GRANNY06_ENDING,+ NPC_GRANNY07X, NPC_GRANNY08, NPC_THEO08, NPC_GRANNY09_IN, NPC_GRANNY09_OUT, NPC_OSHIRO };+typedef struct {+ Sprite spr;+ Talk talk;+ Job mv; /* MoveTo */+ V2 mv_target;+ float mv_speed, mv_alpha, light_alpha, maxspeed, speed_y;+ uint32_t light_color;+ int8_t light_dy, mv_turn;+ uint8_t light_r0, light_r1, has_light, has_talk, move_y, gravity, mv_fade, mv_remove, idle_anim, move_anim;+ uint8_t which; /* the chapter file's own class */+ uint16_t haha; /* its Hahaha: g_ents index + 1, 0 none */+ float f[4]; /* the class's own */+ int32_t i[4];+ void (*think)(Ent *e); /* the class's Update, before NPC.Update */+ void (*on_talk)(Ent *e); /* TalkComponent's OnTalk */+ void (*paint)(Ent *e); /* its own Render, instead of NPC's */+} Npc;+#define NPC_(e) ST(e, Npc)+Ent *npc_new(float x, float y, int bank, int anim, void (*think)(Ent *e));+void npc_light(Ent *e, int dy, uint32_t color, int r0, int r1); /* VertexLight(0, dy) */+void npc_talker(Ent *e, int x, int y, int w, int h, V2 draw_at, void (*on_talk)(Ent *e));+void npc_haha(Ent *e); /* its Hahaha at (8, -4), laughing with the sprite's "laugh" */+/* MoveTo(target, fadeIn, turnAtEndTo (0: none), removeAtEnd): CO_AWAIT on ->mv */+void npc_move_to(Ent *e, V2 target, bool fade_in, int turn_at_end, bool remove_at_end);+Ent *npc_find(int which); /* the first NPC of that class */++/* ---------------------------------------------------------------- the textbox's portrait */+/* Textbox.PortraitName / PortraitAnimation: the shown portrait's bank and its idle animation; false if+ * no textbox shows one (text.c's, weak here until it has one) */+bool textbox_portrait(int *bank, int *idle_anim);+#endifdiff --git a/games/celeste/src/berry.c b/games/celeste/src/berry.cnew file mode 100644index 00000000..e9d2dda3--- /dev/null+++ b/games/celeste/src/berry.c@@ -0,0 +1,879 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* Strawberries: Strawberry, StrawberrySeed, StrawberryPoints and the seeds'+ * cutscene (CSGEN_StrawberrySeeds), and what makes things follow the player+ * (Leader, Follower). Line by line from the game's code. */+#include "entities.h"++/* ---------------------------------------------------------------- Leader and Follower */+/* The game keeps 350 past points; followers only use every 5th, one each */+#define MAX_FOLLOWERS 14+#define LEADER_POINTS (5 * MAX_FOLLOWERS + 1)+typedef struct {+ Ent *e;+ uint32_t id; /* ParentEntityID */+ float delay; /* DelayTimer */+ uint8_t move, persistent;+} Fol;+static V2 past[LEADER_POINTS];+static int npast;+static Fol fol[MAX_FOLLOWERS];+static int nfol;++static int find(const Ent *e) {+ for (int i = 0; i < nfol; i++)+ if (fol[i].e == e) return i;+ return -1;+}++/* Leader.Update: the player's component, at Position (0, -8) */+void leader_update(V2 at) {+ if (level_on_interval(0.02f) && (npast == 0 || v2len(v2sub(at, past[0])) >= 3)) {+ memmove(past + 1, past, sizeof(V2) * (LEADER_POINTS - 1));+ past[0] = at;+ if (npast < LEADER_POINTS) npast++;+ }+ int k = 5;+ for (int i = 0; i < nfol; i++) {+ if (k >= npast) break;+ Fol *f = &fol[i];+ if (f->delay <= 0 && f->move) {+ float m = 1 - powf(0.01f, DT);+ f->e->x += (past[k].x - f->e->x) * m;+ f->e->y += (past[k].y - f->e->y) * m;+ }+ k += 5;+ }+}+/* a new player: a new Leader */+void leader_reset(void) { npast = nfol = 0; }++/* Leader.GainFollower and Follower.OnGainLeaderUtil */+bool leader_gain(Ent *e, float follow_delay, bool persistent) {+ if (nfol >= MAX_FOLLOWERS || find(e) >= 0) return false;+ Fol *f = &fol[nfol++];+ f->e = e;+ f->id = level_entity_id(g_level.rooms[e->room].index, e->eid);+ f->delay = follow_delay;+ f->move = 1;+ f->persistent = persistent;+ if (persistent) e->tags |= TAG_PERSISTENT;+ if (e->cls->on_gain_leader) e->cls->on_gain_leader(e);+ return true;+}+/* Follower.OnLoseLeaderUtil */+static void lost(Fol *f) {+ Ent *e = f->e;+ if (f->persistent) {+ e->tags &= (uint8_t)~TAG_PERSISTENT;+ e->room = (uint8_t)g_level.room_slot; /* it stays in this room now */+ }+ if (e->cls->on_lose_leader) e->cls->on_lose_leader(e);+}+void leader_lose(Ent *e) {+ int i = find(e);+ if (i < 0) return;+ Fol f = fol[i];+ memmove(fol + i, fol + i + 1, sizeof(Fol) * (size_t)(nfol - i - 1));+ nfol--;+ lost(&f);+}+/* LoseFollowers: each is told while the list is still whole */+void leader_lose_all(void) {+ Fol copy[MAX_FOLLOWERS];+ int n = nfol;+ memcpy(copy, fol, sizeof(Fol) * (size_t)n);+ for (int i = 0; i < n; i++) lost(©[i]);+ nfol = 0;+}+/* TransferFollowers: those that do not follow between rooms let go */+void leader_transfer(void) {+ for (int i = 0; i < nfol; i++)+ if (!(fol[i].e->tags & TAG_PERSISTENT)) leader_lose(fol[i--].e);+}+int leader_index(const Ent *e) { return find(e); } /* FollowIndex, -1 without a leader */+int leader_count(void) { return nfol; }+Ent *leader_follower(int i) { return i < nfol ? fol[i].e : NULL; }+bool leader_has(const Ent *e) { return find(e) >= 0; }+bool leader_has_id(uint32_t id) {+ for (int i = 0; i < nfol; i++)+ if (fol[i].id == id) return true;+ return false;+}+float leader_delay(const Ent *e) {+ int i = find(e);+ return i < 0 ? 0 : fol[i].delay;+}+/* Follower.Update */+void leader_tick(const Ent *e) {+ int i = find(e);+ if (i >= 0 && fol[i].delay > 0) fol[i].delay -= DT;+}+void leader_set_move(const Ent *e, bool move) {+ int i = find(e);+ if (i >= 0) fol[i].move = move;+}++/* ---------------------------------------------------------------- Strawberry */+/* "collected_seeds_of_" + its EntityID ("room:id") */+static void seeds_flag(char *buf, int room, int id) {+ char num[8];+ int n = 0;+ do num[n++] = (char)('0' + id % 10), id /= 10;+ while (id);+ path2(buf, "collected_seeds_of_", level_room_name_of(room), -1);+ char *p = buf + strlen(buf);+ *p++ = ':';+ while (n) *p++ = num[--n];+ *p = 0;+}++typedef struct {+ Sprite spr;+ Wiggler wig, rot_wig;+ Tween pulse, home, flap1, flap2;+ V2 start, home_from, home_ctrl;+ float wobble, collect_timer, flap_speed, wings_alarm, home_alarm, co_wait;+ int8_t index; /* in the chapter's strawberries (the save keeps them by it) */+ uint8_t golden, moon, winged, ghost, collected, flying, waiting_seeds, return_home;+ uint8_t fly_step, collect_step, collect_index, nseeds;+ uint8_t room; /* its EntityID: the room and the id */+ uint16_t eid;+} Berry;+static const EntClass BERRY;++static const PType *glow_type(const Berry *b) {+ return b->ghost ? &P_Strawberry_P_GhostGlow : b->golden ? &P_Strawberry_P_GoldGlow+ : !b->moon ? &P_Strawberry_P_Glow : &P_Strawberry_P_MoonGlow;+}+static int anim(const Berry *b, int which) { /* 0 idle, 1 collect, 2 flap */+ switch (b->spr.bank) {+ case SB_goldberry: return which == 0 ? A_goldberry_idle : which == 1 ? A_goldberry_collect : A_goldberry_flap;+ case SB_goldghostberry: return which == 0 ? A_goldghostberry_idle : which == 1 ? A_goldghostberry_collect : A_goldghostberry_flap;+ case SB_ghostberry: return which == 0 ? A_ghostberry_idle : which == 1 ? A_ghostberry_collect : A_ghostberry_flap;+ default: return which == 0 ? A_strawberry_idle : which == 1 ? A_strawberry_collect : A_strawberry_flap;+ }+}++/* IsFirstStrawberry: no other (not golden) strawberry ahead of it */+static bool first_berry(const Ent *e) {+ for (int i = leader_index(e) - 1; i >= 0; i--) {+ Ent *o = leader_follower(i);+ if (o->cls == &BERRY && !ST(o, Berry)->golden) return false;+ }+ return true;+}++static void points_new(V2 at, bool ghost, int index, bool moon);++/* OnCollect */+static void berry_collect(Ent *e) {+ Berry *b = ST(e, Berry);+ if (b->collected) return;+ int index = 0;+ b->collected = 1;+ if (leader_has(e)) {+ Player *p = level_player();+ index = p->strawb_index++;+ p->strawb_reset_timer = 2.5f;+ leader_lose(e);+ }+ save_add_berry(b->index, b->golden);+ if (b->index >= 0) g_session.berries |= (uint64_t)1 << b->index; /* Strawberries, DoNotLoad */+ g_session.dashes_at_level_start = g_session.dashes; /* UpdateLevelStartDashes */+ b->collect_index = (uint8_t)index;+ b->collect_step = 1; /* CollectRoutine, from the components' turn */+}++/* OnAnimate: the sprite's frame changed */+static void berry_on_frame(Ent *e, Berry *b) {+ int id = b->spr.anim, frame = b->spr.frame;+ bool flap = id == anim(b, 2);+ if (!b->flying && flap && frame % 9 == 4) b->flap_speed = -50;+ int num = flap ? 25 : b->golden ? 30 : !b->moon ? 35 : 30;+ if (frame == num) {+ tween_start(&b->pulse, 0.5f); /* the light pulses; Displacement bursts are not drawn here */+ (void)e;+ }+}++/* FlyAwayRoutine: a Monocle coroutine, `yield return t` waits t then a frame more */+static void fly_away(Berry *b) {+ if (b->co_wait > 0) {+ b->co_wait -= DT;+ return;+ }+ switch (b->fly_step) {+ case 1:+ wiggler_restart(&b->rot_wig);+ b->flap_speed = -200;+ tween_start(&b->flap1, 0.25f);+ b->co_wait = 0.1f;+ b->fly_step = 2;+ break;+ case 2:+ b->co_wait = 0.2f;+ b->fly_step = 3;+ break;+ case 3:+ tween_start(&b->flap2, 0.5f);+ b->fly_step = 0;+ break;+ }+}++static void berry_update(Ent *e) {+ Berry *b = ST(e, Berry);+ if (b->waiting_seeds) return;+ if (!b->collected) {+ if (!b->winged) b->wobble += DT * 4;+ int follow = leader_index(e);+ if (follow >= 0 && leader_delay(e) <= 0 && first_berry(e)) {+ Player *p = level_player();+ bool ok = false;+ if (p && !p->dead && !p->strawberries_blocked) {+ if (b->golden) {+ if (level_gold_collect_check(p->ent) || g_level.completed) ok = true;+ } else if (p->on_safe_ground && (!b->moon || p->state != ST_INTROJUMP))+ ok = true;+ }+ if (ok) {+ b->collect_timer += DT;+ if (b->collect_timer > 0.15f) berry_collect(e);+ } else+ b->collect_timer = fminf(b->collect_timer, 0);+ } else {+ if (follow > 0) b->collect_timer = -0.15f;+ if (b->winged) {+ e->y += b->flap_speed * DT;+ if (b->flying) {+ if (e->y < g_level.room->y - 16) {+ ent_remove(e);+ return;+ }+ } else {+ b->flap_speed = approach(b->flap_speed, 20, 170 * DT);+ if (e->y < b->start.y - 5) e->y = b->start.y - 5;+ else if (e->y > b->start.y + 5) e->y = b->start.y + 5;+ }+ }+ }+ }+ /* base.Update(): its components in order */+ leader_tick(e);+ int anim_was = b->spr.anim, frame_was = b->spr.frame;+ spr_update(&b->spr);+ if (b->spr.anim != anim_was || b->spr.frame != frame_was) berry_on_frame(e, b);+ wiggler_update(&b->wig);+ wiggler_update(&b->rot_wig);+ tween_update(&b->pulse);+ /* tweens added during a turn start on the next one: they go before what starts them */+ if (b->flap1.active) {+ tween_update(&b->flap1);+ b->flap_speed = -200 + 200 * ease_cube_out(b->flap1.percent);+ }+ if (b->flap2.active) {+ tween_update(&b->flap2);+ b->flap_speed = -200 * b->flap2.percent;+ }+ if (b->home.active) {+ bool done = tween_update(&b->home);+ float t = ease_sine_out(b->home.percent), u = 1 - t; /* SimpleCurve.GetPoint */+ e->x = u * u * b->home_from.x + 2 * u * t * b->home_ctrl.x + t * t * b->start.x;+ e->y = u * u * b->home_from.y + 2 * u * t * b->home_ctrl.y + t * t * b->start.y;+ if (done) e->depth = 0, ents_mark_unsorted();+ }+ if (b->wings_alarm > 0 && (b->wings_alarm -= DT) <= 0) { /* Alarm: the wings come off */+ b->spr.rate = 1;+ spr_play(&b->spr, anim(b, 0), false);+ particles_emit(PL_MID, &P_Strawberry_P_WingsBurst, 8, v2(e->x + 8, e->y), v2(4, 2), P_Strawberry_P_WingsBurst.direction);+ particles_emit(PL_MID, &P_Strawberry_P_WingsBurst, 8, v2(e->x - 8, e->y), v2(4, 2), P_Strawberry_P_WingsBurst.direction);+ }+ if (b->home_alarm > 0 && (b->home_alarm -= DT) <= 0) { /* OnLoseLeader's alarm: a curve home */+ V2 d = v2sub(b->start, v2(e->x, e->y));+ float dist = v2len(d);+ V2 n = dist > 0 ? v2mul(d, 1 / dist) : v2(0, 0);+ float side = clamped_map(dist, 16, 120, 16, 96) * (rndi(2) ? -1.f : 1.f);+ b->home_from = v2(e->x, e->y);+ b->home_ctrl = v2add(v2add(b->start, v2mul(n, 16)), v2mul(v2(-n.y, n.x), side));+ tween_start(&b->home, fmaxf(dist / 100, 0.4f));+ }+ if (b->collect_step == 1) { /* CollectRoutine */+ e->tags = TAG_TRANSITION_UPDATE;+ e->depth = -2000010;+ ents_mark_unsorted();+ spr_play(&b->spr, anim(b, 1), false);+ b->collect_step = 2;+ } else if (b->collect_step == 2 && !b->spr.playing) {+ points_new(v2(e->x, e->y), b->ghost, b->collect_index, b->moon);+ ent_remove(e);+ return;+ }+ if (b->fly_step) fly_away(b);+ if (leader_has(e) && level_on_interval(0.08f)) {+ const PType *t = glow_type(b);+ particles_emit1(PL_FG, t, v2(e->x + rnd_rangef(-6, 6), e->y + rnd_rangef(-6, 6)), t->direction);+ }+}++static void berry_render(Ent *e) {+ Berry *b = ST(e, Berry);+ if (b->waiting_seeds) return;+ Sprite s = b->spr;+ float y = b->winged ? 0 : sinf(b->wobble) * 2;+ s.sx = s.sy = 1 + b->wig.value * 0.35f;+ s.rot = b->rot_wig.value * 30 * (PI_F / 180);+ spr_draw(&s, e->x, e->y + y);+ float bloom = (b->golden || b->moon || b->ghost) ? 0.5f : 1;+ if (g_session.bloom_base_add > 0.1f) bloom *= 0.5f;+ bloom_add(e->x, e->y + y, bloom, 12);+ /* VertexLight(white, 1, 16, 24) and its pulse: the radii grow by 6 and 12 and come back */+ float k = b->pulse.active ? 1 - b->pulse.percent : 0;+ light_add(e->x, e->y + y, 0xFFFFFF, 1, (float)(int)(16 + 6 * k), (float)(int)(24 + 12 * k));+}++/* PlayerCollider */+static void berry_on_player(Ent *e, Player *p) {+ Berry *b = ST(e, Berry);+ if (leader_has(e) || b->collected || b->waiting_seeds) return;+ b->return_home = 1;+ if (b->winged) {+ b->winged = 0;+ b->spr.rate = 0;+ b->wings_alarm = 0.3f; /* FollowDelay */+ }+ if (b->golden) g_session.grabbed_golden = 1;+ leader_gain(e, 0.3f, true);+ wiggler_restart(&b->wig);+ e->depth = -1000000;+ ents_mark_unsorted();+ (void)p;+}++/* OnLoseLeader */+static void berry_lose_leader(Ent *e) {+ Berry *b = ST(e, Berry);+ if (b->collected || !b->return_home) return;+ b->home_alarm = 0.15f;+}++/* DashListener */+static void berry_on_dash(Ent *e, V2 dir) {+ Berry *b = ST(e, Berry);+ (void)dir;+ if (!b->flying && b->winged && !b->waiting_seeds) {+ e->depth = -1000000;+ ents_mark_unsorted();+ b->fly_step = 1;+ b->flying = 1;+ }+}++static const EntClass BERRY = {.size = sizeof(Berry), .name = "strawberry", .update = berry_update, .render = berry_render,+ .on_player = berry_on_player, .on_lose_leader = berry_lose_leader,+ .on_dash = berry_on_dash, .kind = KIND_PCOLLIDE};++int berry_golden_room(void) {+ for (int i = 0; i < leader_count(); i++) {+ Ent *o = leader_follower(i);+ if (o->cls == &BERRY && ST(o, Berry)->golden && !ST(o, Berry)->winged) return ST(o, Berry)->room;+ }+ return -1;+}++/* the player reached the end: every strawberry it carries is collected (Level.RegisterAreaComplete) */+void berries_collect_all(void) {+ Ent *list[MAX_FOLLOWERS];+ int n = 0;+ for (int i = 0; i < leader_count(); i++)+ if (leader_follower(i)->cls == &BERRY) list[n++] = leader_follower(i);+ for (int i = 0; i < n; i++) berry_collect(list[i]);+}++/* ---------------------------------------------------------------- StrawberrySeed */+typedef struct {+ Sprite spr;+ Wiggler wig;+ SineWave sine;+ Tween pulse, a, b; /* spin: a (spinLerp) and b; combine: b */+ V2 start, from, avg, center;+ float can_lose, lose, light_alpha, co_wait, angle_off, spin, start_angle;+ uint16_t berry; /* its strawberry: g_ents index */+ uint8_t index, ghost, finished, losing, attached, step, anim; /* anim: 1 spinning, 2 combining */+ int8_t shakex, shakey;+ float shake_timer;+} Seed;+static const EntClass SEED;++static void seed_lose_leader(Ent *e) {+ Seed *s = ST(e, Seed);+ if (!s->finished) s->step = 1; /* the ReturnRoutine coroutine */+}+static void seed_gain_leader(Ent *e) {+ Seed *s = ST(e, Seed);+ wiggler_restart(&s->wig);+ s->can_lose = 0.25f;+ s->lose = 0.15f;+}++static void seeds_cutscene_start(Ent *berry);++static void seed_on_player(Ent *e, Player *p) {+ Seed *s = ST(e, Seed);+ (void)p;+ leader_gain(e, 0.2f, false);+ e->collidable = 0;+ e->depth = -1000000;+ ents_mark_unsorted();+ /* all of its strawberry's seeds following: the cutscene */+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o->cls == &SEED && o->dead != 1 && ST(o, Seed)->berry == s->berry && !leader_has(o)) return;+ }+ seeds_cutscene_start(&g_ents[s->berry]);+}++/* ReturnRoutine */+static void seed_return(Ent *e, Seed *s) {+ if (s->co_wait > 0) {+ s->co_wait -= DT;+ return;+ }+ if (s->step == 1) {+ e->collidable = 0;+ s->spr.sx = s->spr.sy = 2;+ s->co_wait = 0.05f;+ s->step = 2;+ } else if (s->step == 2) {+ for (int i = 0; i < 6; i++) {+ float a = rndf() * PI_F * 2;+ particles_emit(PL_FG, &P_StrawberrySeed_P_Burst, 1, v2add(v2(e->x, e->y), angle_vec(a, 4)), v2(0, 0), a);+ }+ e->visible = 0;+ s->co_wait = 0.3f + s->index * 0.1f;+ s->step = 3;+ } else if (s->step == 3) {+ e->x = s->start.x, e->y = s->start.y;+ if (s->attached && ent_platform(e)) e->x += ent_platform(e)->x, e->y += ent_platform(e)->y;+ s->shake_timer = 0.4f; /* Shaker.ShakeFor(0.4) */+ s->spr.sx = s->spr.sy = 1;+ e->visible = 1;+ e->collidable = 1;+ s->step = 0;+ }+}++static void seed_update(Ent *e) {+ Seed *s = ST(e, Seed);+ /* base.Update(): Follower, StaticMover, PlayerCollider, Wiggler, SineWave, Shaker, lights, coroutines */+ leader_tick(e);+ wiggler_update(&s->wig);+ sine_update(&s->sine);+ V2 shake = v2(0, 0);+ if (s->shake_timer > 0) {+ if (level_on_interval(0.04f)) s->shakex = (int8_t)(rndi(3) - 1), s->shakey = (int8_t)(rndi(3) - 1);+ s->shake_timer -= DT;+ if (s->shake_timer <= 0) s->shakex = s->shakey = 0;+ shake = v2(s->shakex, s->shakey);+ }+ int was = s->spr.frame;+ spr_update(&s->spr);+ if (s->spr.frame != was && e->visible && s->spr.anim == 0 && s->spr.frame == 19) tween_start(&s->pulse, 0.5f);+ tween_update(&s->pulse);+ if (s->step) seed_return(e, s);+ if (s->anim == 1) { /* StartSpinAnimation */+ if (s->a.active) {+ tween_update(&s->a);+ s->spin = ease_cube_in(s->a.percent);+ }+ bool done = tween_update(&s->b);+ float ang = PI_F / 2 + s->angle_off - 32.201324f * ease_cube_inout(s->b.percent);+ V2 c = v2add(v2lerp(s->avg, s->center, s->spin), angle_vec(ang, 25));+ V2 p = v2lerp(s->from, c, s->spin);+ e->x = p.x, e->y = p.y;+ if (done) s->anim = 0;+ } else if (s->anim == 2) { /* StartCombineAnimation */+ bool done = tween_update(&s->b);+ float ang = s->start_angle - PI_F * 2 * ease_cube_in(s->b.percent);+ float len = 25 * (1 - ease_big_back_in(s->b.percent));+ V2 p = v2add(s->center, angle_vec(ang, len));+ e->x = p.x, e->y = p.y;+ if (done) {+ e->visible = 0;+ for (int i = 0; i < 6; i++) {+ float a = rndf() * PI_F * 2;+ particles_emit(PL_FG, &P_StrawberrySeed_P_Burst, 1, v2add(v2(e->x, e->y), angle_vec(a, 4)), v2(0, 0), a);+ }+ ent_remove(e);+ return;+ }+ }+ if (!s->finished) {+ Player *p = level_player();+ if (s->can_lose > 0) s->can_lose -= DT;+ else if (leader_has(e) && p && p->on_ground) s->losing = 1;+ if (s->losing && p) {+ if (s->lose <= 0 || p->speed.y < 0) {+ leader_lose(e);+ s->losing = 0;+ } else if (p->on_ground)+ s->lose -= DT;+ else {+ s->lose = 0.15f;+ s->losing = 0;+ }+ }+ } else+ s->light_alpha = approach(s->light_alpha, 0, DT * 4);+ (void)shake;+}++static void seed_render(Ent *e) {+ Seed *s = ST(e, Seed);+ Sprite sp = s->spr;+ float k = 1 + 0.2f * s->wig.value;+ sp.sx *= k, sp.sy *= k;+ float ox = s->finished ? 0 : s->sine.value * 2 + s->shakex, oy = s->finished ? 0 : s->sine.value_over_two + s->shakey;+ spr_draw(&sp, e->x + ox, e->y + oy);+ bloom_add(e->x, e->y, 1, 12);+ float pk = s->pulse.active ? 1 - s->pulse.percent : 0;+ light_add(e->x, e->y, 0xFFFFFF, s->light_alpha, (float)(int)(16 + 6 * pk), (float)(int)(24 + 12 * pk));+}++/* StaticMover: SolidChecker = the solid overlaps the seed */+static bool seed_riding(Ent *e, Ent *solid) { return (solid->kind & KIND_SOLID) && collide_ent_at(solid, solid->x, solid->y, e); }+static void seed_attach(Ent *e, Ent *solid) {+ Seed *s = ST(e, Seed);+ e->depth = -1000000;+ ents_mark_unsorted();+ ent_box(e, 24, 24, -12, -12);+ s->attached = 1;+ s->start = v2(e->x - solid->x, e->y - solid->y);+}+static void seed_sm_move(Ent *e, V2 amount) { e->x += amount.x, e->y += amount.y; }++static const EntClass SEED = {.size = sizeof(Seed), .name = "strawberrySeed", .update = seed_update, .render = seed_render,+ .on_player = seed_on_player, .on_gain_leader = seed_gain_leader,+ .on_lose_leader = seed_lose_leader, .sm_riding = seed_riding, .sm_attach = seed_attach,+ .sm_move = seed_sm_move, .kind = KIND_PCOLLIDE | KIND_STATICMOVER};++/* ---------------------------------------------------------------- the strawberry entity */+static void berry_new(const EData *d, bool golden, bool memorial) {+ int index = session_berry_index(d->room, d->id);+ if (index >= 0 && (g_session.berries >> index & 1)) return; /* DoNotLoad */+ Ent *e = ent_new(&BERRY, d->x, d->y);+ if (!e) return;+ Berry *b = ST(e, Berry);+ b->index = (int8_t)index;+ b->room = (uint8_t)d->room;+ b->eid = (uint16_t)d->id;+ b->start = v2(d->x, d->y);+ b->golden = golden || memorial;+ b->winged = memorial || (!golden && EAB(d, strawberry, winged));+#ifdef EA_strawberry_moon+ b->moon = !golden && EAB(d, strawberry, moon);+#endif+ b->ghost = save_check_berry(index);+ b->return_home = 1;+ e->depth = -100;+ ent_box(e, 14, 14, -7, -7);+ wiggler_init(&b->wig, 0.4f, 4);+ wiggler_init(&b->rot_wig, 0.5f, 4);+ /* Added(): the sprite */+ spr_init(&b->spr, b->ghost ? (b->golden ? SB_goldghostberry : SB_ghostberry) : (b->golden ? SB_goldberry : SB_strawberry));+ if (b->ghost) b->spr.tint = 0xCE79, b->spr.alpha = 204; /* Color.White * 0.8 */+ if (b->winged) spr_play(&b->spr, anim(b, 2), false);+ /* seeds */+ if (d->nnodes && !golden && !memorial) {+ char flag[48];+ seeds_flag(flag, d->room, d->id);+ b->eid = (uint16_t)d->id;+ if (!level_get_flag(flag)) {+ b->nseeds = (uint8_t)d->nnodes;+ b->waiting_seeds = 1;+ e->visible = 0;+ e->collidable = 0;+ int count = 0;+ for (int i = 0; i < d->nnodes; i++) {+ V2 at = ed_node(d, i);+ Ent *se = ent_new(&SEED, at.x, at.y);+ if (!se) break;+ Seed *s = ST(se, Seed);+ se->depth = -100;+ ent_box(se, 12, 12, -6, -6);+ s->start = at;+ s->index = (uint8_t)i;+ s->ghost = b->ghost;+ s->berry = (uint16_t)(e - g_ents);+ s->light_alpha = 1;+ wiggler_init(&s->wig, 0.5f, 4);+ s->sine.freq = 0.5f;+ sine_randomize(&s->sine);+ spr_init(&s->spr, s->ghost ? SB_ghostberrySeed : g_session.mode == M_C ? SB_goldberrySeed : SB_strawberrySeed);+ if (s->ghost) s->spr.tint = 0xCE79, s->spr.alpha = 204;+ count++;+ }+ /* Awake: the idle animation starts later for later seeds */+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o->cls != &SEED || ST(o, Seed)->berry != (uint16_t)(e - g_ents)) continue;+ Seed *s = ST(o, Seed);+ float k = 0.25f + (1 - s->index / (count + 1.f)) * 0.75f;+ spr_play(&s->spr, 0, true);+ s->spr.frame = (uint8_t)(k * spr_frames(&s->spr)); /* PlayOffset */+ if (s->spr.frame >= spr_frames(&s->spr)) s->spr.frame = (uint8_t)(spr_frames(&s->spr) - 1);+ }+ }+ }+}+bool berry_create(const EData *d) {+ switch (d->type) {+ case ET_strawberry: berry_new(d, false, false); return true;+ case ET_goldenBerry: berry_new(d, true, false); return true;+ case ET_memorialTextController: berry_new(d, false, true); return true;+ }+ return false;+}++/* GoldBerryCollectTrigger: golden strawberries are collected only here (or at the end) */+static const EntClass GOLDTRIG = {.name = "goldenBerryCollectTrigger", .kind = KIND_TRIGGER};+bool berry_trigger(const EData *d) {+ if (d->type != TT_goldenBerryCollectTrigger) return false;+ Ent *e = ent_new(&GOLDTRIG, d->x, d->y);+ if (e) ent_box(e, EA(d, goldenBerryCollectTrigger, width), EA(d, goldenBerryCollectTrigger, height), 0, 0), e->visible = 0;+ return true;+}+bool level_gold_collect_check(const Ent *player) {+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o->cls == &GOLDTRIG && o->dead != 1 && collide_ent_at(player, player->x, player->y, o)) return true;+ }+ return false;+}++/* ---------------------------------------------------------------- StrawberryPoints */+typedef struct {+ Sprite spr;+ float light;+ uint8_t ghost, moon;+} Points;+static void points_update(Ent *e) {+ Points *p = ST(e, Points);+ if (g_level.frozen) return;+ spr_update(&p->spr);+ if (!p->spr.playing) { /* OnFinish */+ ent_remove(e);+ return;+ }+ e->y -= 8 * DT;+ e->x = clampf(e->x, g_level.cam.x + 8, g_level.cam.x + 320 - 8);+ e->y = clampf(e->y, g_level.cam.y + 8, g_level.cam.y + 180 - 8);+ p->light = approach(p->light, 0, DT * 4);+ const PType *t = p->ghost ? &P_Strawberry_P_GhostGlow : &P_Strawberry_P_Glow;+ if (p->moon && !p->ghost) t = &P_Strawberry_P_MoonGlow;+ if (level_on_interval(0.05f)) {+ uint16_t c1 = (uint16_t)rgb(t->color & 0xFFFFFF), c2 = (uint16_t)rgb(t->color2 & 0xFFFFFF);+ p->spr.tint = p->spr.tint == c2 ? c1 : c2;+ }+ if (level_on_interval(0.06f) && p->spr.frame > 11) particles_emit(PL_FG, t, 1, v2(e->x, e->y - 2), v2(8, 4), t->direction);+}+static void points_render(Ent *e) {+ Points *p = ST(e, Points);+ spr_draw(&p->spr, e->x, e->y);+ light_add(e->x, e->y, 0xFFFFFF, p->light, 16, 24);+ bloom_add(e->x, e->y, p->light, 12);+}+static const EntClass POINTS = {.size = sizeof(Points), .name = "strawberryPoints", .update = points_update, .render = points_render};++static void points_new(V2 at, bool ghost, int index, bool moon) {+ /* those already shown within 16 px go */+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o->cls == &POINTS && o->dead != 1 && (o->x - at.x) * (o->x - at.x) + (o->y - at.y) * (o->y - at.y) <= 256) ent_remove(o);+ }+ Ent *e = ent_new(&POINTS, at.x, at.y);+ if (!e) return;+ Points *p = ST(e, Points);+ e->depth = -2000100;+ e->tags = TAG_PERSISTENT | TAG_TRANSITION_UPDATE | TAG_FROZEN_UPDATE;+ p->ghost = ghost, p->moon = moon;+ p->light = 1;+ spr_init(&p->spr, SB_strawberry);+ if (index > 5) index = 5;+ spr_play(&p->spr, moon ? A_strawberry_fade_wow : A_strawberry_fade0 + index, true);+}++/* ---------------------------------------------------------------- CSGEN_StrawberrySeeds */+typedef struct {+ uint16_t berry;+ uint8_t step, cam_on, cam_ease;+ float wait, cam_p, cam_dur, dist;+ V2 cam_start, cam_from, cam_to;+} SeedsScene;++/* CutsceneEntity.CameraTo: true once there */+static bool camera_to(SeedsScene *c) {+ if (c->cam_p < 1) {+ float k = c->cam_ease ? ease_cube_inout(c->cam_p) : c->cam_p;+ g_level.cam = v2add(c->cam_from, v2mul(v2sub(c->cam_to, c->cam_from), k));+ c->cam_p += DT / c->cam_dur;+ return false;+ }+ g_level.cam = c->cam_to;+ return true;+}+static void camera_start(SeedsScene *c, V2 to, float dur, bool ease) {+ c->cam_from = g_level.cam;+ c->cam_to = to;+ c->cam_dur = dur;+ c->cam_p = dur > 0 ? 0 : 1;+ c->cam_ease = ease;+ c->cam_on = 1;+}++static void each_seed(uint16_t berry, void (*fn)(Ent *, void *), void *ctx) {+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o->cls == &SEED && o->dead != 1 && ST(o, Seed)->berry == berry) fn(o, ctx);+ }+}+/* OnAllCollected */+static void seed_all_collected(Ent *o, void *ctx) {+ (void)ctx;+ Seed *s = ST(o, Seed);+ s->finished = 1;+ leader_lose(o);+ o->depth = -2000002;+ o->tags = TAG_FROZEN_UPDATE;+ wiggler_restart(&s->wig);+}+typedef struct { V2 sum; int n; float angle, step; V2 center; } SpinCtx;+static void seed_sum(Ent *o, void *ctx) {+ SpinCtx *c = ctx;+ c->sum = v2add(c->sum, v2(o->x, o->y));+ c->n++;+}+static void seed_spin(Ent *o, void *ctx) {+ SpinCtx *c = ctx;+ Seed *s = ST(o, Seed);+ s->spin = 0;+ s->from = v2(o->x, o->y);+ s->avg = v2mul(c->sum, 1.f / c->n);+ s->center = c->center;+ s->angle_off = c->angle;+ c->angle -= c->step;+ spr_play(&s->spr, 1, true); /* noFlash */+ tween_start(&s->a, 2);+ tween_start(&s->b, 4);+ s->anim = 1;+}+static void seed_combine(Ent *o, void *ctx) {+ SpinCtx *c = ctx;+ Seed *s = ST(o, Seed);+ s->center = c->center;+ s->start_angle = atan2f(o->y - c->center.y, o->x - c->center.x);+ tween_start(&s->b, 0.6f);+ s->anim = 2;+}+static void seed_remove(Ent *o, void *ctx) {+ (void)ctx;+ ent_remove(o);+}+/* Strawberry.CollectedSeeds */+static void berry_seeds_done(Ent *be) {+ Berry *b = ST(be, Berry);+ b->waiting_seeds = 0;+ be->visible = 1;+ be->collidable = 1;+ char flag[48];+ seeds_flag(flag, b->room, b->eid);+ level_set_flag(flag, true);+}++static void scene_update(Ent *e) {+ SeedsScene *c = ST(e, SeedsScene);+ Ent *be = &g_ents[c->berry];+ if (c->cam_on == 1 && camera_to(c)) c->cam_on = 0; /* the camera's own coroutine */+ if (c->wait > 0) { /* yield return t */+ c->wait -= DT;+ return;+ }+ switch (c->step) {+ case 0: {+ Player *p = level_player();+ c->cam_start = p ? player_camera_target(p) : g_level.cam;+ each_seed(c->berry, seed_all_collected, NULL);+ be->depth = -2000002;+ be->tags |= TAG_FROZEN_UPDATE;+ ents_mark_unsorted();+ c->wait = 0.35f;+ c->step = 1;+ break;+ }+ case 1:+ e->tags = TAG_FROZEN_UPDATE | TAG_HUD;+ g_level.frozen = true;+ g_level.formation = true; /* FormationBackdrop */+ g_level.formation_alpha = 0.5f;+ c->wait = 0.1f;+ c->step = 2;+ break;+ case 2: {+ SpinCtx s = {v2(0, 0), 0, PI_F / 2, 0, v2(be->x, be->y)};+ each_seed(c->berry, seed_sum, &s);+ if (!s.n) s.n = 1;+ s.step = PI_F * 2 / s.n;+ each_seed(c->berry, seed_spin, &s);+ Room *rm = g_level.room;+ camera_start(c, v2(clampf(be->x - 160, (float)rm->x, (float)(rm->x + rm->w - 320)),+ clampf(be->y - 90, (float)rm->y, (float)(rm->y + rm->h - 180))), 3.5f, true);+ c->wait = 4;+ c->step = 3;+ break;+ }+ case 3: {+ SpinCtx s = {v2(0, 0), 0, 0, 0, v2(be->x, be->y)};+ each_seed(c->berry, seed_combine, &s);+ c->wait = 0.6f;+ c->step = 4;+ break;+ }+ case 4:+ each_seed(c->berry, seed_remove, NULL);+ berry_seeds_done(be);+ c->wait = 0.5f;+ c->step = 5;+ break;+ case 5: /* yield return CameraTo(cameraStart, dist / 180) */+ c->dist = v2len(v2sub(g_level.cam, c->cam_start));+ camera_start(c, c->cam_start, c->dist / 180, false);+ c->cam_on = 2;+ c->step = 6;+ break;+ case 6:+ if (!camera_to(c)) break;+ c->cam_on = 0;+ c->step = 7;+ if (c->dist > 80) c->wait = 0.25f;+ break;+ case 7: /* EndCutscene, OnEnd */+ g_level.in_cutscene = false;+ be->depth = -100;+ be->tags &= (uint8_t)~TAG_FROZEN_UPDATE;+ ents_mark_unsorted();+ g_level.frozen = false;+ g_level.formation = false;+ ent_remove(e);+ break;+ }+}+static const EntClass SEEDSCENE = {.size = sizeof(SeedsScene), .name = "CSGEN_StrawberrySeeds", .update = scene_update};+static void seeds_cutscene_start(Ent *berry) {+ Ent *e = ent_new(&SEEDSCENE, 0, 0);+ if (!e) return;+ e->visible = 0;+ e->tags = TAG_FROZEN_UPDATE;+ ST(e, SeedsScene)->berry = (uint16_t)(berry - g_ents);+ g_level.in_cutscene = true; /* Level.StartCutscene */+}diff --git a/games/celeste/src/breath.c b/games/celeste/src/breath.cnew file mode 100644index 00000000..659a32b0--- /dev/null+++ b/games/celeste/src/breath.c@@ -0,0 +1,293 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* BreathingMinigame: holding up breathes the feather higher, letting go lets it fall; kept in the box long+ * enough, it is calm. Golden Ridge's gondola (winnable, with its words) and Reflection's dream (it cannot be+ * won: the feather gets cut). The glow behind the feather (MagicGlow, blurred) is not drawn. */+#include "cutscene.h"+#include "level.h"+#include "player.h"+#include "text.h"+#include "data.h"++#define DOTS 50+typedef struct { int16_t x, y; uint8_t scale, speed, sin, pad; } Dot; /* interface units x8; scale /255 * 0.8 */+typedef struct {+ Co co, box_co;+ SineWave sine, wave;+ float feather, speed, stab, bounds, center, mult, inside, trail, losing_t, bg, box, falpha, palpha, pspeed, timer;+ float active, text_a, p, sy, pop_p, half_p; /* sy: the feather's top (interface units) */+ uint8_t winnable, completed, pausing, box_on, losing, box_started, popped, slicing, text;+ char words[96];+ TextDraw td;+ Dot dots[DOTS];+} Breath;+static const EntClass BREATH;++static void dot_reset(Dot *d, bool top, bool bottom) { /* Particle.Reset */+ float n = rndf();+ n *= n * n * n;+ d->x = (int16_t)(rndf() * 1920 * 8), d->y = (int16_t)((top ? -128 : bottom ? 1208 : rndf() * 1080) * 8);+ d->scale = (uint8_t)((0.05f + n * 0.75f) / 0.8f * 255), d->speed = (uint8_t)((2 + rndf() * 6) * 32), d->sin = (uint8_t)rndi(256);+}+static bool box_in(Breath *b) { /* FadeBoxIn */+ Co *c = &b->box_co;+ NB_BEGIN(c);+ NB_WAIT(c, b->winnable ? 5 : 2);+ while (fabsf(b->feather) > 300) NB_YIELD(c);+ b->box_on = 1;+ b->sine.freq = 0.12f;+ sine_set(&b->sine, 0);+ while (b->box < 1) {+ b->box += DT;+ NB_YIELD(c);+ }+ b->box = 1;+ NB_END(c);+}+static bool confirm(void) { return btn_pressed(&g_in.confirm) || btn_pressed(&g_in.jump); } /* MenuConfirm */++static void breath_update(Ent *e) {+ Breath *b = ST(e, Breath);+ Co *c = &b->co;+ b->timer += DT;+ b->trail = approach(b->trail, b->speed, DT * 200 * 8);+ sine_update(&b->wave);+ if (b->box_on) sine_update(&b->sine);+ for (int i = 0; i < DOTS; i++) {+ Dot *d = &b->dots[i];+ float sp = d->scale / 255.f * 0.8f * d->speed / 32.f;+ d->y = (int16_t)clampf(d->y + sp * b->pspeed * DT * 8, -32768, 32767);+ if (b->pspeed > -400) d->x = (int16_t)(d->x + (b->pspeed + 400) * sinf(d->sin / 256.f * 2 * PI_F + b->timer) * 0.8f * DT);+ if (d->y < -128 * 8 || d->y > 1208 * 8) dot_reset(d, b->pspeed >= 0, b->pspeed < 0);+ }+ if (b->box_started == 1 && !box_in(b)) b->box_started = 2;+ CO_BEGIN(c);+ b->inside = 1;+ for (b->p = 0; b->p < 1; b->p += DT) {+ CO_YIELD(c);+ b->bg = fminf(b->p, 1) * 0.65f;+ }+ for (b->text = 1; b->text <= (b->winnable ? 5 : 0); b->text++) { /* ShowText(n), FadeGameIn after the first */+ if (b->text_a != 0)+ for (b->p = 0; b->p < 1; b->p += DT * 4) {+ CO_YIELD(c);+ b->text_a = 1 - b->p;+ }+ b->text_a = 0;+ {+ char key[24] = "CH4_GONDOLA_FEATHER_0";+ key[20] = (char)('0' + b->text);+ dialog_clean(key, b->words, sizeof b->words);+ }+ CO_WAIT(c, 0.1f);+ for (b->p = 0; b->p < 1; b->p += DT * 4) {+ CO_YIELD(c);+ b->text_a = b->p;+ }+ b->text_a = 1;+ while (!confirm()) CO_YIELD(c);+ for (b->p = 0; b->p < 1; b->p += DT * 4) {+ CO_YIELD(c);+ b->text_a = 1 - b->p;+ }+ b->text_a = 0;+ if (b->text == 1)+ while (b->falpha < 1) {+ b->falpha += DT;+ CO_YIELD(c);+ }+ }+ b->text = 0;+ while (b->falpha < 1) { /* FadeGameIn */+ b->falpha += DT;+ CO_YIELD(c);+ }+ b->falpha = 1;+ b->box_started = 1;+ b->active = 450;+ while (b->stab < 30) {+ float num = b->stab / 30;+ bool up = g_in.jump.check || g_in.dash.check || g_in.aim_y < 0;+ if (b->losing) {+ if (fmodf(b->losing_t * 10, 1) > 0.5f) up = !up; /* Calc.BetweenInterval(losingTimer * 10, 0.5) */+ b->active = 450 - ease_cube_in(b->losing_t) * 200;+ }+ if (up) {+ if (b->feather > -b->active) b->speed -= 280 * DT;+ b->pspeed -= 2800 * DT;+ } else {+ if (b->feather < b->active) b->speed += 280 * DT;+ b->pspeed += 2800 * DT;+ }+ b->speed = clampf(b->speed, -200, 200);+ if (b->feather > b->active && b->mult == 0 && b->speed > 0) b->speed = 0;+ if (b->feather < b->active && b->mult == 0 && b->speed < 0) b->speed = 0;+ b->pspeed = clampf(b->pspeed, -1600, 120);+ b->mult = approach(b->mult, ((b->feather < -b->active && b->speed < 0) || (b->feather > b->active && b->speed > 0)) ? 0 : 1, DT * 4);+ b->bounds = approach(b->bounds, 160 - 60 * num, DT * 16);+ b->feather += b->speed * b->mult * DT;+ if (b->box_on) {+ b->center = -b->sine.value * 300 * lerpf(1, 0, ease_cube_in(num));+ if (b->feather > b->center - b->bounds && b->feather < b->center + b->bounds) {+ b->inside += DT;+ if (b->inside > 0.2f) b->stab += DT;+ } else {+ if (b->inside > 0.2f) b->stab = fmaxf(0, b->stab - 0.5f);+ if (b->stab > 0) b->stab -= 0.5f * DT;+ b->inside = 0;+ }+ }+ b->bg = approach(b->bg, 0.65f + fminf(1, num / 0.8f) * 0.35f, DT);+ b->sy = 540 + b->feather - 128;+ b->palpha = approach(b->palpha, 1, DT);+ if (!b->winnable && b->stab > 12) b->losing = 1;+ if (b->losing && (b->losing_t += DT / 5) > 1) break;+ CO_YIELD(c);+ }+ if (!b->winnable) {+ for (b->pausing = 1; b->pausing;) { /* the cutscene goes on, then lets it pop */+ b->sy += (540 - b->sy) * (1 - powf(0.01f, DT));+ b->box -= DT * 10;+ b->palpha = b->box;+ CO_YIELD(c);+ }+ b->losing = 0, b->losing_t = 0;+ b->popped = 1; /* PopFeather: still, centered */+ CO_WAIT(c, 0.25f);+ b->slicing = 1;+ for (b->pop_p = 0; b->pop_p < 1; b->pop_p += DT * 8) CO_YIELD(c);+ b->slicing = 0;+ level_shake(0.3f);+ level_flash(0xFFFF, false);+ b->popped = 2; /* the halves */+ for (b->half_p = 0; b->half_p < 1; b->half_p += DT) {+ b->falpha = 1 - b->half_p;+ CO_YIELD(c);+ }+ } else {+ b->bg = 1;+ while (b->box > 0) {+ CO_YIELD(c);+ b->box -= DT;+ b->palpha = b->box;+ }+ b->palpha = 0;+ CO_WAIT(c, 2);+ while (b->falpha > 0) {+ CO_YIELD(c);+ b->falpha -= DT;+ }+ CO_WAIT(c, 1);+ }+ for (b->completed = 1; b->bg > 0; b->bg -= DT * (b->winnable ? 1 : 10)) CO_YIELD(c);+ ent_remove(e);+ return;+ CO_END(c);+}++/* the particles: OVR's snow (a soft dot), stretched while they rush up */+static void dots_strip(uint16_t *strip, int y0, int y1, void *ctx) {+ const Breath *b = ctx;+ float k = b->pspeed < 0 ? fmaxf(1, -b->pspeed * 0.004f) : 1, kx = b->pspeed < 0 ? fminf(1, 1 / (-b->pspeed * 0.004f)) : 1;+ int a = (int)(0.5f * b->palpha * 256);+ if (a <= 0) return;+ for (int i = 0; i < DOTS; i++) {+ const Dot *d = &b->dots[i];+ float r = d->scale / 255.f * 0.8f * 127 / 6, cx = d->x / 48.f, cy = d->y / 48.f, rx = fmaxf(r * kx, 0.5f), ry = fmaxf(r * k, 0.5f);+ int ya = (int)floorf(cy - ry), yb = (int)ceilf(cy + ry);+ if (yb < y0 || ya >= y1) continue;+ for (int y = ya < y0 ? y0 : ya; y <= yb && y < y1; y++)+ for (int x = (int)floorf(cx - rx); x <= (int)ceilf(cx + rx); x++) {+ if (x < 0 || x >= VIEW_W) continue;+ float dx = (x + 0.5f - cx) / rx, dy = (y + 0.5f - cy) / ry, q = dx * dx + dy * dy;+ if (q >= 1) continue;+ int al = (int)(a * (1 - q));+ uint16_t *p = strip + (y - y0) * VIEW_W + x;+ *p = blend565(*p, scale565(0xFFFF, al), al);+ }+ }+}+#define BORDER_W 207 /* Gui feather/border's width, box's size, feather's height (interface pixels) */+#define BOX_W 300+#define FEATHER_H 256+static void breath_render(Ent *e) {+ Breath *b = ST(e, Breath);+ const float k = 1 / 6.f;+ gfx_hud(true);+ gfx_rect(-2, -2, 324, 184, 0, a8(b->bg));+ if (!g_level.frozen && !g_level.paused && !g_level.skipping_cutscene && !g_player.dead) {+ Tex t;+ float cy = 540 + b->center;+ if (b->box > 0 && tex_get(T__feather_box, &t)) /* the box, white at a quarter */+ gfx_tex_ex(T__feather_box, 160, cy * k, t.fw * t.scale / 2.f, t.fh * t.scale / 2.f, (BORDER_W * 2 - 32.f) / BOX_W,+ (b->bounds * 2 - 32) / BOX_W, 0, 0xFFFF, a8(b->box * 0.25f), 0);+ if (b->box > 0 && tex_get(T__feather_border, &t)) { /* its corners: brighter while the feather is in */+ uint8_t a = a8(b->box * (b->inside > 0.2f ? 1 : 0.6f));+ float w = t.fw * t.scale, h = t.fh * t.scale;+ gfx_tex_ex(T__feather_border, (960 - BORDER_W) * k, (cy - b->bounds) * k, 0, 0, 1, 1, 0, 0xFFFF, a, 0);+ gfx_tex_ex(T__feather_border, (960 + BORDER_W) * k, (cy + b->bounds) * k, w, h, 1, 1, 0, 0xFFFF, a, GF_FLIPX | GF_FLIPY);+ }+ gfx_custom(dots_strip, b, 0, VIEW_H);+ uint8_t fa = a8(b->falpha);+ float fx = 960, fy = b->sy;+ if (fa && !b->popped) { /* the feather (GuiSpriteBank "feather": hover, or flutter while out of the box) */+ float rot = b->wave.value * 0.25f + 0.1f;+ if (b->losing) {+ V2 d = safe_norm(v2((float)(rndi(3) - 1), (float)(rndi(3) - 1)), 1);+ fx += d.x * b->losing_t * 10, fy += d.y * b->losing_t * 10;+ rot += (rndi(3) - 1) * b->losing_t * 0.1f;+ }+ int f = (b->inside > 0 || !b->box_on) ? 0 : (int)(b->timer * 10) % 4;+ uint16_t ft = (uint16_t)(T__feather_feather0 + f);+ if (tex_get(ft, &t)) gfx_tex_ex(ft, fx * k, fy * k, t.fw * t.scale / 2.f, 0, 1, 1, rot, 0xFFFF, fa, 0);+ }+ fy += FEATHER_H / 2.f; /* (popped: centered) */+ if (fa && b->popped == 1 && tex_get(T__feather_feather0, &t))+ gfx_tex_ex(T__feather_feather0, fx * k, fy * k, t.fw * t.scale / 2.f, t.fh * t.scale / 2.f, 1, 1, 0, 0xFFFF, fa, 0);+ if (b->slicing && tex_get(T__feather_slice, &t)) {+ V2 at = v2add(v2(fx, fy), v2lerp(v2(128, -128), v2(-128, 128), b->pop_p));+ float y = yoyo(b->pop_p);+ gfx_tex_ex(T__feather_slice, at.x * k, at.y * k, t.fw * t.scale / 2.f, t.fh * t.scale / 2.f, (0.25f + y * 0.75f) * 8,+ (0.5f + (1 - y) * 0.5f) * 8, atan2f(112 - 165, 140 - 96), 0xFFFF, 255, 0);+ }+ if (fa && b->popped == 2)+ for (int i = 0; i < 2; i++) {+ uint16_t h = i ? T__feather_feather_half1 : T__feather_feather_half0;+ V2 at = v2add(v2(fx, fy), v2mul(v2(i ? 128 : -128, i ? 32 : -32), b->half_p));+ if (tex_get(h, &t)) gfx_tex_ex(h, at.x * k, at.y * k, t.fw * t.scale / 2.f, t.fh * t.scale / 2.f, 1, 1, 0, 0xFFFF, fa, 0);+ }+ if (b->text && b->text_a > 0) { /* the words, and the button once they are in */+ b->td = (TextDraw){b->words, 960, 920, 0.5f, 0.5f, 1, 0xFFFF, a8(b->text_a)};+ text_draw(&b->td);+ if (b->text_a >= 1 && tex_get(T__textboxbutton, &t))+ gfx_tex_ex(T__textboxbutton, ((1920 + text_measure(b->words)) / 2 + 40) * k, (920 + 32 - 16 + (fmodf(b->timer, 1) < 0.25f ? 6 : 0)) * k,+ t.fw * t.scale / 2.f, t.fh * t.scale / 2.f, 1, 1, 0, 0xFFFF, 255, 0);+ }+ }+ gfx_hud(false);+}+static const EntClass BREATH = {.name = "breathingMinigame", .size = sizeof(Breath), .update = breath_update, .render = breath_render};++Ent *breath_new(bool winnable) {+ Ent *e = ent_new(&BREATH, 0, 0);+ if (!e) return NULL;+ e->tags = TAG_HUD, e->depth = 100, e->collidable = 0;+ Breath *b = ST(e, Breath);+ b->winnable = winnable;+ b->bounds = 160, b->mult = 1, b->pspeed = 120;+ b->wave.freq = 0.25f;+ sine_set(&b->wave, 0);+ b->sy = 540 - 128;+ for (int i = 0; i < DOTS; i++) dot_reset(&b->dots[i], false, false);+ return e;+}+static Breath *live(Ent *e) { return e && e->cls == &BREATH && e->dead != 1 ? ST(e, Breath) : NULL; }+bool breath_done(Ent *e) { return !live(e) || live(e)->completed; }+bool breath_pausing(Ent *e) { return live(e) && live(e)->pausing; }+void breath_resume(Ent *e) {+ if (live(e)) live(e)->pausing = 0;+}+void breath_remove(Ent *e) {+ if (live(e)) ent_remove(e);+}diff --git a/games/celeste/src/cassette.c b/games/celeste/src/cassette.cnew file mode 100644index 00000000..eacd7b38--- /dev/null+++ b/games/celeste/src/cassette.c@@ -0,0 +1,546 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* Cassettes: the Cassette (B-side tape) with its message, CassetteBlock and+ * CassetteBlockManager (blocks in time with the music, here with its clock).+ * Line by line from the game's code. */+#include "cutscene.h"+#include "text.h"++/* ---------------------------------------------------------------- the memory every chapter has */+typedef struct {+ /* Cassette.CollectRoutine (one at a time) */+ Co co;+ float p, alpha, timer, wait;+ uint8_t phase;+ V2 cam_was, cam_to, from, to;+ Ent *cassette, *msg;+ bool wait_key;+ Step zoom;+ char text[120];+ TextDraw td;+ /* Player.StartCassetteFly */+ CassetteFly fly;+} CasRam;+#define CR (*(CasRam *)(void *)g_chram[14])+uint32_t cassette_ram(void) { return sizeof(CasRam); }+CassetteFly *cassette_fly(void) { return &CR.fly; }++/* ---------------------------------------------------------------- CassetteBlockManager */+typedef struct {+ int current, beat, lead_beats, max_beat, offset;+ float beat_timer;+ uint8_t started; /* the song's instance exists (its first update only makes it) */+} Cbm;+static const EntClass CBM;+static const EntClass BLOCK;+static Ent *first_of(const EntClass *c) {+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == c && g_ents[i].dead != 1) return &g_ents[i];+ return NULL;+}+#define FOR_BLOCKS(b) \+ for (Ent *b = g_ents; b < g_ents + g_nents; b++) \+ if (b->cls == &BLOCK && b->dead != 1)++typedef struct {+ uint8_t index, activated, leader_flag, ncx, ncy;+ int8_t block_height;+ uint16_t leader, side; /* g_ents indices */+ int16_t lox, loy; /* the group's origin, from the block */+ float wsx, wsy; /* wigglerScaler (the leader's) */+ Wiggler wig; /* the leader's */+ uint8_t cells[40]; /* per 8x8 cell: the tile of the sheet (tx | ty << 2), 12 for none */+} Block;+#define NO_TILE 12++static void block_set_activated_silently(Ent *e, bool on);+static void block_will_toggle(Ent *e);+static bool cassette_should_manage(void) { return g_session.mode != M_A || !g_session.cassette; }++static void cbm_set_active(int index) {+ FOR_BLOCKS(b) ST(b, Block)->activated = ST(b, Block)->index == index;+}+static void cbm_set_will_activate(int index) {+ FOR_BLOCKS(b) if (ST(b, Block)->index == index || ST(b, Block)->activated) block_will_toggle(b);+}+static void cbm_update(Ent *e) {+ Cbm *m = ST(e, Cbm);+ if (!m->started) { /* the cassette song's instance is made: nothing advances this update */+ m->started = 1;+ return;+ }+ m->beat_timer += DT; /* AdvanceMusic(DeltaTime * tempoMult): the tempo is 1 in every map */+ if (!(m->beat_timer >= 1 / 6.f)) return;+ m->beat_timer -= 1 / 6.f;+ m->beat = (m->beat + 1) % 256;+ if (m->beat % 8 == 0) {+ m->current = (m->current + 1) % m->max_beat;+ cbm_set_active(m->current);+ } else if ((m->beat + 1) % 8 == 0)+ cbm_set_will_activate((m->current + 1) % m->max_beat);+ if (m->lead_beats > 0 && --m->lead_beats == 0) m->beat = 0;+}+static const EntClass CBM = {.name = "cassetteBlockManager", .size = sizeof(Cbm), .update = cbm_update};++static Ent *cbm_new(void) {+ Ent *e = ent_new(&CBM, 0, 0);+ if (!e) return NULL;+ Cbm *m = ST(e, Cbm);+ e->tags = TAG_GLOBAL;+ /* Awake: the areas with a cassette song lead in 16 beats; the others follow the level's music */+ bool level_music = g_session.area == 0 || g_session.area == 8 || g_session.area >= 10;+ m->lead_beats = level_music ? 0 : 16;+ m->offset = level_music ? 5 : 0;+ m->max_beat = g_level.cassette_beats;+ return e;+}++/* the end of LoadLevel, and TransitionListener.OnOutBegin */+void cassette_level_start(bool transition) {+ Ent *e = first_of(&CBM);+ if (!e) return;+ Cbm *m = ST(e, Cbm);+ if (transition && !g_level.has_cassette_blocks) {+ ent_remove(e);+ return;+ }+ if (!g_level.has_cassette_blocks || !cassette_should_manage()) return;+ /* OnLevelStart */+ m->max_beat = g_level.cassette_beats;+ m->current = m->beat % 8 >= 5 ? m->max_beat - 2 : m->max_beat - 1;+ FOR_BLOCKS(b) if (b->room == g_level.room_slot) block_set_activated_silently(b, ST(b, Block)->index == m->current);+}++/* ---------------------------------------------------------------- CassetteBlock */+static const uint32_t COLORS[4] = {0x49aaf0, 0xf049be, 0xfcdc3a, 0x38e04e};+static uint16_t block_color(const Block *b) { return rgb(COLORS[b->index < 4 ? b->index : 0]); }+static uint16_t block_disabled_color(const Block *b) { /* 667da5 times the color */+ uint32_t c = COLORS[b->index < 4 ? b->index : 0];+ int r = (int)(c >> 16) * 0x66 / 255, g = (int)(c >> 8 & 255) * 0x7d / 255, bl = (int)(c & 255) * 0xa5 / 255;+ return rgb((uint32_t)(r << 16 | g << 8 | bl));+}+static Ent *block_leader(const Ent *e) { return &g_ents[ST(e, Block)->leader]; }++static void block_shift(Ent *e, int amount) { /* ShiftSize */+ plat_move_v(e, (float)amount);+ ST(e, Block)->block_height = (int8_t)(ST(e, Block)->block_height - amount);+}++/* TryActorWiggleUp */+static bool block_wiggle_up(Ent *e, Ent *actor) {+ Block *b = ST(e, Block);+ FOR_BLOCKS(o) if (o != e && ST(o, Block)->leader == b->leader && collide_ent_at(o, o->x, o->y + 4, actor)) return false;+ bool was = e->collidable;+ e->collidable = 1;+ for (int i = 1; i <= 4; i++)+ if (!collide_solid(actor, actor->x, actor->y - i)) {+ actor->y -= (float)i;+ e->collidable = was;+ return true;+ }+ e->collidable = was;+ return false;+}+static bool block_blocked(Ent *e) { /* BlockedCheck */+ for (Ent *a = g_ents; a < g_ents + g_nents; a++)+ if (a->cls && a->dead != 1 && (a->kind & KIND_HOLDABLE) && (a->kind & KIND_ACTOR) && collide_ent_at(e, e->x, e->y, a) &&+ !block_wiggle_up(e, a))+ return true;+ Ent *p = level_player_ent();+ return p && collide_ent_at(e, e->x, e->y, p) && !block_wiggle_up(e, p);+}++static void block_visual(Ent *e) { /* UpdateVisualState */+ Block *b = ST(e, Block);+ if (!e->collidable) e->depth = 8990;+ else {+ Ent *p = level_player_ent();+ e->depth = p && e_top(p) >= e_bottom(e) - 1 ? 10 : -10;+ }+ for (Ent *m = g_ents; m < g_ents + g_nents; m++)+ if (m->cls && ent_platform(m) == e) m->depth = e->depth + 1;+ Ent *side = &g_ents[b->side];+ if (side->cls) side->depth = e->depth + 5, side->visible = b->block_height > 0;+}++static void block_set_activated_silently(Ent *e, bool on) {+ Block *b = ST(e, Block);+ b->activated = on;+ e->collidable = on;+ block_visual(e);+ if (on) plat_static_movers_enable(e, true);+ else {+ block_shift(e, 2);+ plat_static_movers_enable(e, false);+ }+}+static void block_will_toggle(Ent *e) {+ block_shift(e, e->collidable ? 1 : -1);+ block_visual(e);+}+void cassette_blocks_finish(void) { /* CassetteBlockManager.StopBlocks */+ FOR_BLOCKS(b) ST(b, Block)->activated = 0;+}++static void block_update(Ent *e) {+ Block *b = ST(e, Block);+ plat_update(e);+ if (b->leader_flag) wiggler_update(&b->wig);+ if (b->leader_flag && b->activated && !e->collidable) {+ bool blocked = false;+ FOR_BLOCKS(o) if (ST(o, Block)->leader == b->leader && block_blocked(o)) {+ blocked = true;+ break;+ }+ if (!blocked) {+ FOR_BLOCKS(o) if (ST(o, Block)->leader == b->leader) {+ o->collidable = 1;+ plat_static_movers_enable(o, true);+ block_shift(o, -1);+ }+ wiggler_restart(&b->wig);+ }+ } else if (!b->activated && e->collidable) {+ block_shift(e, 1);+ e->collidable = 0;+ plat_static_movers_enable(e, false);+ }+ block_visual(e);+}++/* the group's wiggle (the leader's): scale around the group's origin */+static V2 block_scale(const Ent *e) {+ const Block *l = ST(block_leader(e), Block);+ return v2(1 + l->wig.value * 0.05f * l->wsx, 1 + l->wig.value * 0.15f * l->wsy);+}+/* for the spikes on a block (Spikes.SetOrigins): its group's scale, and its origin */+bool cassette_block_scale(const Ent *e, V2 *origin, V2 *scale) {+ if (!e || e->cls != &BLOCK) return false;+ *origin = v2(e->x + ST(e, Block)->lox, e->y + ST(e, Block)->loy);+ *scale = block_scale(e);+ return true;+}++static uint16_t block_tex(const Ent *e) {+ return e->collidable ? T_objects_cassetteblock_solid : (uint16_t)(T_objects_cassetteblock_pressed00 + ST(e, Block)->index % 4);+}+static void block_strip(uint16_t *strip, int y0, int y1, void *ctx) {+ Ent *e = ctx;+ Block *b = ST(e, Block);+ Tex t;+ if (!tex_get(block_tex(e), &t)) return;+ V2 s = block_scale(e);+ float x = floorf(e->x + 0.5f) - g_camx, y = floorf(e->y + 0.5f) - g_camy;+ blit_cells(strip, y0, y1, &t, x, y, b->ncx, b->ncy, b->cells, x + b->lox, y + b->loy, s.x, s.y, block_color(b));+}+static void block_render(Ent *e) {+ Block *b = ST(e, Block);+ Tex t;+ if (!tex_get(block_tex(e), &t)) return; /* (loaded before the strips are drawn) */+ V2 s = block_scale(e);+ float y = floorf(e->y + 0.5f) - g_camy, gy = y + b->loy;+ float top = gy + (y - gy) * s.y, bot = gy + (y + b->ncy * 8 - gy) * s.y;+ gfx_custom(block_strip, e, (int)floorf(top) - 1, (int)ceilf(bot) + 1);+}+static void side_render(Ent *e) { /* BoxSide */+ Ent *blk = &g_ents[ST(e, uint16_t)[0]];+ if (blk->cls != &BLOCK) return;+ Block *b = ST(blk, Block);+ gfx_rect(blk->x, e_bottom(blk) - 8, blk->cw, (float)(8 + b->block_height), block_disabled_color(b), 255);+}+static const EntClass SIDE = {.name = "boxSide", .size = sizeof(uint16_t) * 2, .render = side_render};++static bool same_at(const Ent *e, float x, float y) { /* CheckForSame */+ FOR_BLOCKS(o) if (ST(o, Block)->index == ST(e, Block)->index && collide_rect(o, x, y, x + 8, y + 8)) return true;+ return false;+}+static void find_in_group(Ent *leader, Ent *blk) { /* FindInGroup */+ uint16_t li = (uint16_t)(leader - g_ents);+ FOR_BLOCKS(o) {+ if (o == leader || o == blk || ST(o, Block)->leader == li || ST(o, Block)->index != ST(leader, Block)->index) continue;+ if (collide_rect(o, blk->x - 1, blk->y, blk->x + blk->cw + 1, blk->y + blk->ch) ||+ collide_rect(o, blk->x, blk->y - 1, blk->x + blk->cw, blk->y + blk->ch + 1)) {+ ST(o, Block)->leader = li;+ find_in_group(leader, o);+ }+ }+}++static void block_awake(Ent *e) {+ Block *b = ST(e, Block);+ plat_static_movers_attach(e);+ uint16_t me = (uint16_t)(e - g_ents);+ Ent *side = ent_new(&SIDE, e->x, e->y);+ if (side) {+ ST(side, uint16_t)[0] = me;+ b->side = (uint16_t)(side - g_ents);+ side->room = e->room;+ }+ if (b->leader == 0xFFFF) { /* no group yet: this one leads it */+ b->leader_flag = 1;+ b->leader = me;+ find_in_group(e, e);+ float l = 1e9f, r = -1e9f, t = 1e9f, bo = -1e9f;+ FOR_BLOCKS(o) if (ST(o, Block)->leader == me) {+ l = fminf(l, o->x), r = fmaxf(r, o->x + o->cw), t = fminf(t, o->y), bo = fmaxf(bo, o->y + o->ch);+ }+ float gx = (float)(int)(l + (r - l) / 2), gy = (float)(int)bo;+ b->wsx = clamped_map(r - l, 32, 96, 1, 0.2f), b->wsy = clamped_map(bo - t, 32, 96, 1, 0.2f);+ wiggler_init(&b->wig, 0.3f, 3);+ FOR_BLOCKS(o) if (ST(o, Block)->leader == me) {+ ST(o, Block)->lox = (int16_t)(gx - o->x), ST(o, Block)->loy = (int16_t)(gy - o->y);+ }+ }+ /* the spikes on it: its colors, seen while disabled, scaled with the group */+ for (Ent *m = g_ents; m < g_ents + g_nents; m++)+ if (m->cls && ent_platform(m) == e && (m->kind & KIND_SPIKES))+ spikes_set_cassette(m, block_color(b), block_disabled_color(b), v2(e->x + b->lox, e->y + b->loy));+ /* the sheet's tiles: corners, edges, inner corners */+ for (int cy = 0; cy < b->ncy; cy++)+ for (int cx = 0; cx < b->ncx; cx++) {+ float x = e->x + cx * 8, y = e->y + cy * 8;+ bool l = same_at(e, x - 8, y), r = same_at(e, x + 8, y), u = same_at(e, x, y - 8), d = same_at(e, x, y + 8);+ int tx = -1, ty = 0;+ if (l && r && u && d) {+ if (!same_at(e, x + 8, y - 8)) tx = 3, ty = 0;+ else if (!same_at(e, x - 8, y - 8)) tx = 3, ty = 1;+ else if (!same_at(e, x + 8, y + 8)) tx = 3, ty = 2;+ else if (!same_at(e, x - 8, y + 8)) tx = 3, ty = 3;+ else tx = 1, ty = 1;+ } else if (l && r && !u && d) tx = 1, ty = 0;+ else if (l && r && u && !d) tx = 1, ty = 2;+ else if (l && !r && u && d) tx = 2, ty = 1;+ else if (!l && r && u && d) tx = 0, ty = 1;+ else if (l && !r && !u && d) tx = 2, ty = 0;+ else if (!l && r && !u && d) tx = 0, ty = 0;+ else if (l && !r && u && !d) tx = 2, ty = 2;+ else if (!l && r && u && !d) tx = 0, ty = 2;+ int i = cy * b->ncx + cx, v = tx < 0 ? NO_TILE : tx | ty << 2;+ b->cells[i >> 1] = (uint8_t)((b->cells[i >> 1] & ~(15 << ((i & 1) * 4))) | v << ((i & 1) * 4));+ }+ block_visual(e);+}++static const EntClass BLOCK = {.name = "cassetteBlock", .size = sizeof(Block), .update = block_update, .render = block_render,+ .awake = block_awake, .kind = KIND_SOLID};++static bool block_new(const EData *d) {+ int w = (int)EA(d, cassetteBlock, width), h = (int)EA(d, cassetteBlock, height);+ int index = (int)EA(d, cassetteBlock, index);+ if ((w / 8) * (h / 8) > 80) return true; /* (none so big in the maps) */+ Ent *e = ent_new(&BLOCK, d->x, d->y);+ if (!e) return true;+ Block *b = ST(e, Block);+ ent_box(e, (float)w, (float)h, 0, 0);+ e->collidable = 0;+ b->index = (uint8_t)index;+ b->ncx = (uint8_t)(w / 8), b->ncy = (uint8_t)(h / 8);+ b->block_height = 2;+ b->leader = 0xFFFF;+ b->side = 0;+ /* Level.LoadLevel */+ g_level.has_cassette_blocks = true;+ if (index + 1 > g_level.cassette_beats) g_level.cassette_beats = (uint8_t)(index + 1);+ if (!first_of(&CBM) && cassette_should_manage()) cbm_new();+ return true;+}++/* ---------------------------------------------------------------- Cassette */+typedef struct {+ Sprite spr;+ SineWave hover;+ Wiggler wig;+ int16_t n0x, n0y, n1x, n1y;+ uint8_t ghost, collected, collecting, nodes;+} Cas;++/* UnlockedBSide: the message, in the interface */+static void msg_update(Ent *e) {+ (void)e;+ CR.timer += DT;+}+static void msg_render(Ent *e) {+ (void)e;+ float num = ease_cube_out(CR.alpha);+ uint8_t a = (uint8_t)(num * 255);+ float k = 64 * (1 - num);+ gfx_hud(true);+ gfx_rect(0, 0, VIEW_W, VIEW_H, 0, (uint8_t)(num * 0.8f * 255));+ Tex t;+ if (tex_get(T__collectables_cassette, &t))+ gfx_tex_ex(T__collectables_cassette, 160, (604 - k + 32) / 6, t.fw * t.scale / 2.f, (float)t.fh * t.scale, 1, 1, 0,+ 0xFFFF, a, 0);+ CR.td = (TextDraw){CR.text, 960, 604 + k, 0.5f, 0, 1, 0xFFFF, a};+ text_draw(&CR.td);+ if (CR.wait_key && tex_get(T__textboxbutton, &t))+ gfx_tex_ex(T__textboxbutton, 1824 / 6.f, (984 + (fmodf(CR.timer, 1) < 0.25f ? 6 : 0)) / 6.f, t.fw * t.scale / 2.f,+ t.fh * t.scale / 2.f, 1, 1, 0, 0xFFFF, 255, 0);+ gfx_hud(false);+}+static const EntClass MSG = {.name = "unlockedBSide", .update = msg_update, .render = msg_render};++static bool msg_ease_in(void) { /* EaseIn: true while it runs */+ if (CR.phase == 0) {+ if ((CR.alpha += DT / 0.5f) < 1) return true;+ CR.alpha = 1;+ CR.wait = 1.5f; /* yield return 1.5f */+ CR.phase = 1;+ return true;+ }+ if (CR.wait > 0) {+ CR.wait -= DT;+ return true;+ }+ CR.wait_key = true;+ CR.phase = 0;+ return false;+}+static bool msg_ease_out(void) {+ CR.wait_key = false;+ if ((CR.alpha -= DT / 0.5f) > 0) return true;+ CR.alpha = 0;+ if (CR.msg) ent_remove(CR.msg);+ CR.msg = NULL;+ return false;+}++WEAK void level_sandwich_lava_leave(void) {}++static void cas_routine(Ent *e) { /* CollectRoutine */+ Cas *c = ST(e, Cas);+ Co *co = &CR.co;+ CO_BEGIN(co);+ c->collecting = 1;+ g_level.pause_lock = true;+ g_level.frozen = true;+ e->tags = TAG_FROZEN_UPDATE;+ g_session.cassette = 1;+ {+ V2 sp = level_closest_spawn(v2(c->n1x, c->n1y));+ g_session.rx = (int32_t)sp.x, g_session.ry = (int32_t)sp.y;+ }+ g_session.dashes_at_level_start = g_session.dashes;+ save_register_cassette();+ cassette_blocks_finish();+ e->depth = -1000000;+ level_shake(0.3f);+ level_flash(0xFFFF, false);+ {+ const Room *rm = g_level.room;+ CR.cam_was = g_level.cam;+ V2 v = v2(e->x - 160, e->y - 90);+ CR.cam_to = v2(clampf(v.x, rm->x - 64, rm->x + rm->w + 64 - 320), clampf(v.y, rm->y - 32, rm->y + rm->h + 32 - 180));+ g_level.cam = CR.cam_to;+ V2 f = v2sub(v2(e->x, e->y), g_level.cam);+ zoom_snap(v2(clampf(f.x, 60, 260), clampf(f.y, 60, 120)), 2);+ }+ spr_play(&c->spr, A_cassette_spin, true);+ c->spr.rate = 2;+ for (CR.p = 0; CR.p < 1.5f; CR.p += DT) {+ c->spr.rate += DT * 4;+ CO_YIELD(co);+ }+ c->spr.rate = 0;+ c->spr.frame = 0;+ wiggler_restart(&c->wig);+ CO_WAIT(co, 0.25f);+ CR.from = v2(e->x, e->y);+ CR.to = v2(e->x, g_level.cam.y - 16);+ for (CR.p = 0; CR.p < 1; CR.p += DT / 0.4f) {+ c->spr.sx = lerpf(1, 0.1f, CR.p);+ c->spr.sy = lerpf(1, 3, CR.p);+ float k = ease_cube_in(CR.p);+ e->x = lerpf(CR.from.x, CR.to.x, k), e->y = lerpf(CR.from.y, CR.to.y, k);+ CO_YIELD(co);+ }+ e->visible = 0;+ CR.alpha = 0;+ CR.timer = 0;+ CR.text[0] = 0;+ dialog_clean("UI_REMIX_UNLOCKED", CR.text, sizeof CR.text);+ text_auto_newline(CR.text, sizeof CR.text, 900);+ CR.msg = ent_new(&MSG, 0, 0);+ if (CR.msg) CR.msg->tags = TAG_HUD | TAG_PAUSE_UPDATE, CR.msg->depth = -10000;+ CO_NEST(co, msg_ease_in());+ while (!btn_pressed(&g_in.confirm)) CO_YIELD(co);+ CO_NEST(co, msg_ease_out());+ step_reset(&CR.zoom);+ for (CR.p = 0; CR.p < 1; CR.p += DT / 0.25f) {+ zoom_back(&CR.zoom, 0.2f); /* (its own coroutine, alongside) */+ g_level.cam = v2add(CR.cam_to, v2mul(v2sub(CR.cam_was, CR.cam_to), ease_sine_inout(CR.p)));+ CO_YIELD(co);+ }+ if (!g_player.dead && c->nodes >= 2) player_start_cassette_fly(&g_player, v2(c->n1x, c->n1y), v2(c->n0x, c->n0y));+ level_sandwich_lava_leave();+ g_level.frozen = false;+ CO_WAIT(co, 0.25f);+ {+ Ent *m = first_of(&CBM); /* Finish */+ if (m) ent_remove(m);+ }+ g_level.pause_lock = false;+ zoom_reset();+ ent_remove(e);+ CO_END(co);+}++static void cas_update(Ent *e) {+ Cas *c = ST(e, Cas);+ spr_update(&c->spr);+ wiggler_update(&c->wig);+ if (!c->collecting || c->wig.active) c->spr.sx = c->spr.sy = 1 + c->wig.value * 0.25f;+ sine_update(&c->hover);+ if (c->collected && CR.cassette == e) cas_routine(e);+ if (e->dead) return;+ if (!c->collecting && level_on_interval(0.1f))+ particles_emit(PL_MID, &P_Cassette_P_Shine, 1, v2(e->x, e->y), v2(12, 10), 0);+}+static void cas_on_player(Ent *e, Player *p) {+ Cas *c = ST(e, Cas);+ if (c->collected) return;+ player_refill_stamina(p);+ c->collected = 1;+ level_freeze(0.1f);+ memset(&CR.co, 0, sizeof CR.co);+ CR.cassette = e;+}+static void cas_render(Ent *e) {+ Cas *c = ST(e, Cas);+ float y = c->hover.value * 2;+ spr_draw(&c->spr, e->x, e->y + y);+ bloom_add(e->x, e->y + y, 0.25f, 16);+ light_add(e->x, e->y + y, 0xFFFFFF, 0.4f, 32, 64);+}+static const EntClass CASSETTE = {.name = "cassette", .size = sizeof(Cas), .update = cas_update, .render = cas_render,+ .on_player = cas_on_player, .kind = KIND_PCOLLIDE};++static bool cas_new(const EData *d) {+ if (g_session.cassette) return true;+ Ent *e = ent_new(&CASSETTE, d->x, d->y);+ if (!e) return true;+ Cas *c = ST(e, Cas);+ ent_box(e, 16, 16, -8, -8);+ c->nodes = (uint8_t)d->nnodes;+ if (d->nnodes >= 2) {+ V2 a = ed_node(d, 0), b = ed_node(d, 1);+ c->n0x = (int16_t)a.x, c->n0y = (int16_t)a.y, c->n1x = (int16_t)b.x, c->n1y = (int16_t)b.y;+ }+ /* Added */+ c->ghost = (g_save.cassettes >> g_session.area & 1) != 0;+ spr_init(&c->spr, c->ghost ? SB_cassetteGhost : SB_cassette);+ spr_play(&c->spr, c->ghost ? A_cassetteGhost_idle : A_cassette_idle, true);+ if (c->ghost) c->spr.alpha = 204;+ wiggler_init(&c->wig, 0.25f, 4);+ c->hover.freq = 0.5f;+ sine_set(&c->hover, 0);+ return true;+}++bool cassette_create(const EData *d) {+ switch (d->type) {+ case ET_cassette: return cas_new(d);+ case ET_cassetteBlock: return block_new(d);+ }+ return false;+}diff --git a/games/celeste/src/celeste.h b/games/celeste/src/celeste.hnew file mode 100644index 00000000..60b13f08--- /dev/null+++ b/games/celeste/src/celeste.h@@ -0,0 +1,307 @@+/* Celeste for the NumWorks calculator: shared declarations.+ *+ * Inspired by Celeste, not affiliated with Maddy Makes Games.+ * Made by Mason Chen as part of NumPlay.+ *+ * The game runs Celeste's own levels, art and text (converted by+ * tools/pack.py into data.bin) on a small engine shaped like Monocle, the+ * game's engine: entities with depths, actors and solids that move a pixel at+ * a time, a fixed 60 updates a second. Gameplay is drawn at Celeste's 320x180,+ * pixel for pixel, in the middle of the 320x240 screen. */+#ifndef CELESTE_H+#define CELESTE_H+#include <math.h>+/* sinf, cosf and powf of src/util.c: smaller than the C library's (which reduces any angle exactly): the angles here+ * are small, the powers easings */+float c_sinf(float x);+float c_cosf(float x);+void c_sincosf(float x, float *s, float *c);+float c_powf(float a, float b);+#define sinf(x) c_sinf(x)+#define cosf(x) c_cosf(x)+#define sincosf(x, s, c) c_sincosf(x, s, c)+#define powf(a, b) c_powf(a, b)+#include <stdbool.h>+#include <stddef.h>+#include <stdint.h>+#include <string.h>+#include "data.h"++#define WEAK __attribute__((weak))++#define SCREEN_W 320+#define SCREEN_H 240+#define VIEW_W 320+#define VIEW_H 180+#define VIEW_Y 30+#define RAW_DT 0.0166667f /* Engine.RawDeltaTime: XNA's 166667-tick frame */+extern float g_dt; /* Engine.DeltaTime: RawDeltaTime * TimeRate */+extern float g_time_rate; /* Engine.TimeRate (slow motion in cutscenes) */+#define DT g_dt++/* ---------------------------------------------------------------- data.bin */+extern const uint8_t *cel_bin;+static inline uint16_t rd16(const uint8_t *p) { return (uint16_t)(p[0] | p[1] << 8); }+static inline int16_t rds16(const uint8_t *p) { return (int16_t)rd16(p); }+static inline uint32_t rd32(const uint8_t *p) { return p[0] | p[1] << 8 | p[2] << 16 | (uint32_t)p[3] << 24; }+static inline int8_t rds8(const uint8_t *p) { return (int8_t)p[0]; }+static inline int32_t rds32(const uint8_t *p) { return (int32_t)rd32(p); }+static inline float rdf(const uint8_t *p) { uint32_t v = rd32(p); float f; memcpy(&f, &v, 4); return f; }+const uint8_t *section(int s);+const char *str(uint16_t id);+/* "a" + "b" + n as two digits (n < 0: none) into buf: names of textures */+char *path2(char *buf, const char *a, const char *b, int n);++/* ---------------------------------------------------------------- platform */+enum {+ K_LEFT = 1 << 0, K_RIGHT = 1 << 1, K_UP = 1 << 2, K_DOWN = 1 << 3,+ K_JUMP = 1 << 4, K_DASH = 1 << 5, K_GRAB = 1 << 6, K_TALK = 1 << 7,+ K_PAUSE = 1 << 8, K_HOME = 1 << 9, K_OK = 1 << 10, K_BACK = 1 << 11,+ K_ANY = 1 << 15+};+uint32_t plat_keys(void);+extern uint8_t g_bind[4]; /* jump, dash, grab, talk: EADK keys */+void plat_default_binds(void);+int plat_key_pressed(void); /* the EADK key that went down this frame, -1 if none */+int uitoa(int v, char *out); /* v in digits, 0-terminated; the length */+void time_text(uint32_t frames, char *out); /* a time as the game shows it: 1:23.456 */+uint32_t plat_millis(void);+void plat_sleep(uint32_t ms);+void plat_push(int x, int y, int w, int h, const uint16_t *px);+void plat_fill(int x, int y, int w, int h, uint16_t c);+bool plat_save(const char *name, const void *data, uint32_t len);+const uint8_t *plat_load(const char *name, uint32_t *len);++/* ---------------------------------------------------------------- math */+static inline float clampf(float v, float lo, float hi) { return v < lo ? lo : v > hi ? hi : v; }+static inline int clampi(int v, int lo, int hi) { return v < lo ? lo : v > hi ? hi : v; }+static inline float approach(float v, float t, float d) { return v <= t ? fminf(v + d, t) : fmaxf(v - d, t); }+static inline float signf(float v) { return v > 0 ? 1.f : v < 0 ? -1.f : 0.f; }+static inline int signi(int v) { return v > 0 ? 1 : v < 0 ? -1 : 0; }+static inline float lerpf(float a, float b, float t) { return a + (b - a) * t; }+static inline int sgn(float v) { return v > 0 ? 1 : v < 0 ? -1 : 0; }+static inline float yoyo(float v) { return v <= .5f ? v * 2 : 1 - (v - .5f) * 2; } /* Calc.YoYo */+static inline uint8_t a8(float a) { return (uint8_t)(clampf(a, 0, 1) * 255 + 0.5f); } /* an alpha 0..1 as a byte */+static inline int roundi(float v) { return (int)rintf(v); } /* Math.Round: to even */+typedef struct { float x, y; } V2;+static inline V2 v2(float x, float y) { return (V2){x, y}; }+static inline V2 v2add(V2 a, V2 b) { return (V2){a.x + b.x, a.y + b.y}; }+static inline V2 v2sub(V2 a, V2 b) { return (V2){a.x - b.x, a.y - b.y}; }+static inline V2 v2mul(V2 a, float k) { return (V2){a.x * k, a.y * k}; }+static inline float v2len(V2 a) { return sqrtf(a.x * a.x + a.y * a.y); }+static inline V2 v2norm(V2 a) { float l = v2len(a); return l > 0 ? (V2){a.x / l, a.y / l} : a; }+static inline V2 safe_norm(V2 v, float l) { float n = v2len(v); return n > 0 ? v2mul(v, l / n) : v2(0, 0); } /* Calc.SafeNormalize */+static inline V2 approach_v(V2 v, V2 t, float m) { /* Calc.Approach(Vector2) */+ if (m == 0 || (v.x == t.x && v.y == t.y)) return v;+ V2 d = v2sub(t, v);+ float l = v2len(d);+ return l < m ? t : v2add(v, v2mul(d, m / l));+}+static inline float vangle(V2 v) { return atan2f(v.y, v.x); } /* Calc.Angle */+static inline V2 v2lerp(V2 a, V2 b, float t) { return (V2){a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t}; }+static inline V2 angle_vec(float a, float len) { return (V2){cosf(a) * len, sinf(a) * len}; } /* Calc.AngleToVector */+/* Calc.ClampedMap */+static inline float clamped_map(float v, float min, float max, float nmin, float nmax) {+ float t = (v - min) / (max - min);+ t = t < 0 ? 0 : t > 1 ? 1 : t;+ return nmin + (nmax - nmin) * t;+}+static inline bool v2eq(V2 a, V2 b) { return a.x == b.x && a.y == b.y; }+#define PI_F 3.14159265f++/* Calc.Random: .NET's System.Random */+typedef struct { int32_t seed[56]; int inext, inextp; } NetRandom;+void rnd_seed(NetRandom *r, int32_t seed);+int32_t rnd_next(NetRandom *r); /* [0, int max) */+int32_t rnd_range(NetRandom *r, int32_t max); /* [0, max) */+float rnd_float(NetRandom *r); /* [0, 1) */+extern NetRandom g_rnd; /* Calc.Random */+static inline float rndf(void) { return rnd_float(&g_rnd); }+static inline float rnd_rangef(float a, float b) { return a + rndf() * (b - a); }+static inline int rndi(int n) { return rnd_range(&g_rnd, n); }++/* eases (Monocle Ease) */+float ease_cube_out(float t);+float ease_cube_in(float t);+float ease_cube_inout(float t);+float ease_sine_in(float t);+float ease_sine_out(float t);+float ease_sine_inout(float t);+float ease_quad_out(float t);+float ease_quad_in(float t);+float ease_back_out(float t);+float ease_back_in(float t);+float ease_bounce_out(float t);+float ease_elastic_out(float t);+float ease_big_back_in(float t);+float ease_expo_out(float t);++/* ---------------------------------------------------------------- textures (res.c) */+typedef struct {+ uint16_t w, h; /* stored pixels (trimmed) */+ int16_t ox, oy; /* where they sit in the frame */+ uint16_t fw, fh; /* the frame */+ uint16_t pal;+ uint8_t fmt; /* TF_RLE or TF_RAW4, and for RLE: TF_ROW8, TF_NIB */+ uint8_t scale; /* drawn this many times bigger (smooth gradients) */+ const uint8_t *px; /* RLE: u16 row offsets (h + 1) (TF_ROW8: u8 row lengths (h)) then ops; RAW: w * h indices */+ const uint8_t *map; /* TF_NIB: its colors (count, then their palette indices) */+} Tex;+enum { TF_RLE = 0, TF_RAW4 = 2, TF_ROW8 = 4, TF_NIB = 8, TF_SHARED = 16 }; /* ROW8, NIB, SHARED: drawn from flash only */+void tex_row(const Tex *t, int r, uint8_t *out); /* row r's palette indices (0: transparent) */+bool tex_get(uint16_t id, Tex *t); /* false if not loaded (packed and not cached) */+const uint16_t *pal_colors(uint16_t pal, int *n);+const uint8_t *pal_alpha(uint16_t pal);+bool pal_opaque(uint16_t pal); /* every color fully opaque */+void res_init(void);+/* the texture cache: what a room needs is loaded by res_need() */+void res_begin_need(void);+void res_need(uint16_t tex);+void res_need_list(const uint8_t *ids, int n);+void res_load_needed(void);+/* room packs: copies [off, off + size) of pack p's stream through sink */+typedef void (*Sink)(const uint8_t *p, uint32_t n, void *ctx);+void res_stream(uint16_t pack, uint32_t off, uint32_t size, Sink sink, void *ctx);+uint8_t *arena_scratch(uint32_t *size);+uint8_t *res_scratch(uint32_t need, uint32_t *size);+void res_load_frames(const uint16_t *ids, int n, uint16_t hard); /* an animation's frames: `hard` surely, the others if they fit */ /* the cache's free top, `need` bytes made free if it can */+void res_load(const uint16_t *ids, int n); /* loads those not loaded, in one pass */+bool res_cached(uint16_t id);+extern uint8_t *g_chapter_ram; /* the chapter files' own tables, while it is played */+extern uint8_t *g_chram[16]; /* each chapter file's (src/chN.c) part of it */+void res_chapter_ram(uint32_t bytes);+void res_flush(void);+int tex_half_extent(uint16_t id); /* half the bigger side of its frame, known without loading it */+extern uint16_t g_res_frame;+extern bool g_res_can_load;+extern bool g_res_drawing;+uint16_t res_tex_by_name(const char *path); /* 0xFFFF: none */ /* free RAM while nothing else needs it */++/* ---------------------------------------------------------------- drawing (gfx.c) */+enum { GF_FLIPX = 1, GF_FLIPY = 2, GF_ADD = 4, GF_SCALE = 8, GF_HUD = 16, GF_SILHOUETTE = 32 };+void gfx_begin(void);+void gfx_end(void); /* draw the strips and push them */+void gfx_clear(uint16_t c);+/* a texture with its frame's (0,0) at world (x, y); tint RGB565 0xFFFF = none */+void gfx_tex(uint16_t tex, float x, float y, uint8_t flags, uint16_t tint, uint8_t alpha);+/* drawn like Monocle's MTexture.Draw(position, origin, color, scale, rotation, flip) */+void gfx_tex_ex(uint16_t tex, float x, float y, float ox, float oy, float sx, float sy, float rot, uint16_t tint, uint8_t alpha, uint8_t flags);+void gfx_zoom(float zoom, float focus_x, float focus_y); /* Level.Zoom around a screen point */+void gfx_screen(bool on); /* screen coordinates for gameplay layers (zoomed with the world) */+/* part of a texture (tile sheets): sub-rect (sx, sy, w, h) of the frame */+void gfx_tex_part_ex(uint16_t tex, float x, float y, int sx, int sy, int w, int h, float ox, float oy, float scx, float scy,+ float rot, uint16_t tint, uint8_t alpha, uint8_t flags);+void gfx_tex_part(uint16_t tex, float x, float y, int sx, int sy, int w, int h, uint8_t flags, uint16_t tint, uint8_t alpha);+void gfx_rect(float x, float y, float w, float h, uint16_t c, uint8_t alpha);+void gfx_hollow_rect(float x, float y, float w, float h, uint16_t c, uint8_t alpha);+void gfx_line(float x0, float y0, float x1, float y1, uint16_t c, uint8_t alpha);+void gfx_pixel(float x, float y, uint16_t c, uint8_t alpha);+void gfx_circle(float x, float y, float r, uint16_t c, uint8_t alpha, int resolution);+/* layers drawn by callbacks, once per strip: y0 and y1 are view rows */+typedef void (*StripFn)(uint16_t *strip, int y0, int y1, void *ctx);+void gfx_custom(StripFn fn, void *ctx, int y0, int y1);+void gfx_camera(float x, float y); /* world position of the view's top left */+extern int g_camx, g_camy; /* floored */+void gfx_hud(bool on); /* following draws ignore the camera */+void gfx_present_all(void); /* letterbox and full redraw next frame */+static inline uint16_t rgb(uint32_t c) { return (uint16_t)(((c >> 8) & 0xF800) | ((c >> 5) & 0x7E0) | ((c >> 3) & 0x1F)); }+uint16_t blend565(uint16_t d, uint16_t s, int a); /* a: 0..256 */+static inline uint16_t scale565(uint16_t c, int a) { /* c * a / 256 */+ uint32_t r = ((c >> 11) * a) >> 8, g = (((c >> 5) & 63) * a) >> 8, b = ((c & 31) * a) >> 8;+ return (uint16_t)(r << 11 | g << 5 | b);+}+uint16_t mul565(uint16_t c, uint16_t tint);+/* blitting into a strip (for StripFn layers) */+void blit_tex(uint16_t *strip, int sy0, int sy1, const Tex *t, int x, int y, uint8_t flags, uint16_t tint, uint8_t alpha);+void blit_part_ex(uint16_t *strip, int sy0, int sy1, const Tex *t, int x, int y, int sx, int sy, int w, int h, uint8_t flags,+ uint16_t tint, uint8_t alpha); /* sub-rect (sx, sy, w, h) of the frame at strip-relative (x, y) */+void blit_turned(uint16_t *strip, int sy0, int sy1, const Tex *t, int x, int y, int q, uint8_t flags, uint16_t tint);+void blit_cells(uint16_t *strip, int sy0, int sy1, const Tex *t, float x, float y, int ncx, int ncy, const uint8_t *cells,+ float gx, float gy, float scx, float scy, uint16_t tint);+/* a 4-bit texture (TF_RAW4) centered on screen (cx, cy) (its frame's (ox, oy)), rotated (cos, sin), scaled 1 / inv */+typedef struct { const Tex *t; float cx, cy, ox, oy, cs, sn, inv; const uint16_t *lc, *la; } Layer; /* lc, la: pal_lut's */+void blit_layers(uint16_t *strip, int sy0, int sy1, const Layer *l, int n, int x0, int y0, int x1, int y1,+ uint16_t (*outline)(int x, int y, void *ctx), void *ctx, uint32_t *mask);+void pal_lut(uint16_t pal, uint16_t tint, uint16_t *col, uint16_t *alpha);+void blit_raw4(uint16_t *strip, int sy0, int sy1, const Tex *t, int x, int y, const uint16_t *lc, const uint16_t *la);+void blit_edges(uint16_t *strip, int sy0, int sy1, const uint32_t *mask, uint16_t (*outline)(int x, int y, void *ctx), void *ctx);++/* ---------------------------------------------------------------- sprites (sprite.c) */+typedef struct {+ uint8_t bank;+ uint8_t anim; /* 255: none */+ uint8_t frame;+ uint8_t playing;+ float timer, rate;+ float ox, oy; /* origin */+ float sx, sy; /* scale */+ float rot;+ uint16_t tint;+ uint8_t alpha;+ uint8_t flipx, flipy;+ uint8_t visible;+ uint8_t justify; /* origin follows the frame (Justify) */+ uint8_t raw; /* UseRawDeltaTime: runs through slow motion */+ float jx, jy;+ int8_t last_goto;+} Sprite;+void spr_init(Sprite *s, int bank);+int bank_anim_textures(int bank, int anim, uint16_t *out, int max, uint16_t *gotos, int *ngotos);+void spr_play(Sprite *s, int anim, bool restart);+void spr_play_offset(Sprite *s, int anim, int frame);+void spr_update(Sprite *s);+uint16_t spr_tex(const Sprite *s);+int spr_frames(const Sprite *s);+void spr_draw(const Sprite *s, float x, float y);+bool spr_is(const Sprite *s, int anim);+int bank_anim_count(int bank);+float spr_anim_duration(int bank, int anim);+extern void (*spr_on_frame)(Sprite *s, int anim); /* unused hook */++void gfx_mask4(const uint8_t *bits, int w, int h, float x, float y, uint16_t col, uint8_t alpha);++/* ---------------------------------------------------------------- text (font.c): Renogare */+enum { FONT_S, FONT_M }; /* the game's 64 px face at 1/6, and its 192 px face at 1/9 (twice as big) */+float font_line_height(int size);+float font_measure(const char *s, int n, int size); /* width in screen pixels of n bytes (UTF-8) */+float font_glyph_advance(int size, uint32_t code, uint32_t next);+/* draws at (x, y) = top-left of the line, screen coordinates (gfx_hud); returns the width */+float font_draw(const char *s, int n, float x, float y, int size, uint16_t col, uint8_t alpha);+void font_draw_glyph(int size, uint32_t code, float x, float y, uint16_t col, uint8_t alpha);+void font_draw_outline(const char *s, int n, float x, float y, int size, uint16_t col, uint16_t outline, uint8_t alpha);+/* ActiveFont.Draw with justify: (jx, jy) in 0..1 of the text's size */+void font_draw_justified(const char *s, float x, float y, float jx, float jy, int size, uint16_t col, uint8_t alpha);+uint32_t utf8_next(const char **s, const char *end);+/* a glyph: u16 code, s16 xo x16, s16 yo, u8 w, u8 h, u16 advance x16, u32 bitmap (NULL if none) */+const uint8_t *font_glyph_rec(int size, uint32_t code);+int font_kerning_x16(int size, uint32_t a, uint32_t b);+const uint8_t *font_glyph_bits(int size, const uint8_t *g);++/* ---------------------------------------------------------------- input (Celeste's Input) */+typedef struct {+ bool check, edge, released; /* edge: pressed this frame (the key's Node.Pressed) */+ float buffer, buffer_time;+ bool consumed;+} Button;+typedef struct {+ Button jump, dash, grab, talk, pause, confirm, back;+ int move_x, move_y; /* Input.MoveX/MoveY */+ int aim_x, aim_y; /* Input.Aim, 8 directions */+ int feather_x, feather_y;+ uint32_t keys, prev;+} Input;+extern Input g_in;+void input_update(uint32_t keys);+/* VirtualButton.Pressed, ConsumePress, ConsumeBuffer */+static inline bool btn_pressed(const Button *b) { return !b->consumed && (b->buffer > 0 || b->edge); }+static inline void btn_consume(Button *b) { b->buffer = 0; b->consumed = true; }+static inline void btn_consume_buffer(Button *b) { b->buffer = 0; }++/* ---------------------------------------------------------------- the game */+extern uint32_t g_frame;+extern bool g_running;+void game_init(void);+void game_frame(void); /* one update at 60 Hz (and drawing when due) */+void game_draw(void);+void game_save(void);+#endifdiff --git a/games/celeste/src/ch0.c b/games/celeste/src/ch0.cnew file mode 100644index 00000000..060dd1ad--- /dev/null+++ b/games/celeste/src/ch0.c@@ -0,0 +1,683 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* The Prologue: IntroCar, IntroCrusher, the bridge, Granny and her cutscene,+ * and the ending with the bird (CS00_Granny, CS00_Ending). Line by line from+ * the game's code. */+#include "npc.h"++/* ---------------------------------------------------------------- IntroCar */+typedef struct {+ float start_y;+ uint8_t had_rider;+} Car;+/* the car's two hitboxes: Hitbox(25, 4, -15, -17) and Hitbox(19, 4, 8, -11) */+static bool car_rect(const Ent *e, float l, float t, float r, float b) {+ float x = e->x, y = e->y;+ if (r > x - 15 && b > y - 17 && l < x + 10 && t < y - 13) return true;+ return r > x + 8 && b > y - 11 && l < x + 27 && t < y - 7;+}+static void car_update(Ent *e) {+ Car *c = ST(e, Car);+ plat_update(e);+ bool rider = jumpthru_has_player_rider(e);+ if (e->y > c->start_y && (!rider || e->y > c->start_y + 1)) plat_move_v(e, -10 * DT);+ if (e->y <= c->start_y && !c->had_rider && rider) plat_move_v(e, 2);+ c->had_rider = rider;+}+static void car_render(Ent *e) {+ Tex t;+ if (tex_get(T_scenery_car_body, &t)) gfx_tex_ex(T_scenery_car_body, e->x, e->y, t.fw / 2.f, (float)t.fh, 1, 1, 0, 0xFFFF, 255, 0);+}+static const EntClass CAR = {.size = sizeof(Car), .name = "introCar", .update = car_update, .render = car_render,+ .collide_rect = car_rect, .kind = KIND_JUMPTHRU};+typedef struct { uint16_t tex, tint; uint8_t origin_bottom, center; } Pic;+static void pic_render(Ent *e) {+ Pic *p = ST(e, Pic);+ Tex t;+ if (!tex_get(p->tex, &t)) return;+ gfx_tex_ex(p->tex, e->x, e->y, p->center ? t.fw / 2.f : 0, p->origin_bottom ? (float)t.fh : 0, 1, 1, 0, p->tint, 255, 0);+}+static const EntClass PIC = {.size = sizeof(Pic), .name = "image", .render = pic_render};+static Ent *pic_new(uint16_t tex, float x, float y, int depth, uint16_t tint, bool center) {+ Ent *e = ent_new(&PIC, x, y);+ if (!e) return NULL;+ Pic *p = ST(e, Pic);+ p->tex = tex, p->tint = tint, p->origin_bottom = 1, p->center = center;+ e->depth = depth;+ e->collidable = 0;+ return e;+}++/* IntroPavement: a solid of 8 x 8 pieces, random but for the last two */+typedef struct { uint8_t cols, piece[48]; } Pavement;+static void pavement_render(Ent *e) {+ Pavement *p = ST(e, Pavement);+ for (int i = 0; i < p->cols; i++) gfx_tex_part(T_scenery_car_pavement, e->x + i * 8, e->y, p->piece[i] * 8, 0, 8, 8, 0, 0xFFFF, 255);+}+static const EntClass PAVEMENT = {.size = sizeof(Pavement), .name = "introPavement", .update = plat_update, .render = pavement_render,+ .kind = KIND_SOLID};++static void new_car(const EData *d) {+ Ent *e = ent_new(&CAR, d->x, d->y);+ if (!e) return;+ ST(e, Car)->start_y = d->y;+ e->depth = 1;+ e->ctype = COL_LIST;+ e->cx = -15, e->cy = -17, e->cw = 42, e->ch = 10; /* the bounds of the two */+ e->safe = 1;+ Tex t;+ pic_new(T_scenery_car_wheels, d->x, d->y, 3, 0xFFFF, true);+ (void)t;+ if (g_session.area == 0) {+ float left = (float)g_level.room->x;+ int width = (int)(d->x - left - 48);+ Ent *pv = ent_new(&PAVEMENT, left, d->y);+ if (pv) {+ ent_box(pv, (float)width, 8, 0, 0);+ pv->depth = -10001;+ pv->safe = 1;+ Pavement *p = ST(pv, Pavement);+ p->cols = (uint8_t)(width / 8 > 48 ? 48 : width / 8);+ for (int i = 0; i < p->cols; i++) p->piece[i] = (uint8_t)(i >= p->cols - 2 ? (i != p->cols - 2 ? 3 : 2) : rndi(2));+ }+ pic_new(T_scenery_car_barrier, d->x + 32, d->y, -10, 0xFFFF, false);+ pic_new(T_scenery_car_barrier, d->x + 41, d->y, 5, 0xAD55 /* DarkGray */, false);+ }+}++/* ---------------------------------------------------------------- IntroCrusher */+typedef struct {+ V2 start, end;+ Co co;+ float time;+ int8_t shakex, shakey;+ float shake_timer;+ TileQ tiles[7 * 4];+ uint8_t tw, th;+} Crusher;+static void crusher_shake(Crusher *c, float t) { c->shake_timer = t; }+static void crusher_seq(Ent *e, Crusher *c) {+ Player *p;+ CO_BEGIN(&c->co);+ do {+ CO_YIELD(&c->co);+ p = level_player();+ } while (!p || !(p->ent->x >= e->x + 30) || !(p->ent->x <= e_right(e) + 8));+ crusher_shake(c, 1.2f);+ c->time = 1.2f;+ while (c->time > 0) {+ p = level_player();+ if (p && (p->ent->x >= e->x + e->cw - 8 || p->ent->x < e->x + 28)) {+ c->shake_timer = 0, c->shakex = c->shakey = 0;+ break;+ }+ CO_YIELD(&c->co);+ c->time -= DT;+ }+ for (int i = 2; i < e->cw; i += 4) {+ particles_emit(PL_MID, &P_FallingBlock_P_FallDustA, 2, v2(e->x + i, e->y), v2(4, 4), PI_F / 2);+ particles_emit(PL_MID, &P_FallingBlock_P_FallDustB, 2, v2(e->x + i, e->y), v2(4, 4), P_FallingBlock_P_FallDustB.direction);+ }+ c->time = 0;+ do {+ CO_YIELD(&c->co);+ c->time = approach(c->time, 1, 2 * DT);+ {+ float k = ease_cube_in(c->time);+ plat_move_to(e, c->start.x + (c->end.x - c->start.x) * k, c->start.y + (c->end.y - c->start.y) * k);+ }+ } while (!(c->time >= 1));+ for (int i = 0; i <= e->cw; i += 4) {+ particles_emit(PL_FG, &P_FallingBlock_P_FallDustA, 1, v2(e->x + i, e_bottom(e)), v2(4, 4), -PI_F / 2);+ particles_emit(PL_FG, &P_FallingBlock_P_LandDust, 1, v2(e->x + i, e_bottom(e)), v2(4, 4), i < e->cw / 2 ? PI_F : 0);+ }+ level_shake(0.3f);+ crusher_shake(c, 0.25f);+ CO_END(&c->co);+}+static void crusher_update(Ent *e) {+ Crusher *c = ST(e, Crusher);+ plat_update(e);+ if (c->shake_timer > 0) { /* Shaker: a new shake every 0.04 s */+ c->shake_timer -= DT;+ if (level_on_interval(0.04f)) c->shakex = (int8_t)(rndi(3) - 1), c->shakey = (int8_t)(rndi(3) - 1);+ if (c->shake_timer <= 0) c->shakex = c->shakey = 0;+ }+ if (c->co.co >= 0) crusher_seq(e, c);+}+static void crusher_render(Ent *e) {+ Crusher *c = ST(e, Crusher);+ tiles_draw(c->tiles, c->tw, c->th, e->x + c->shakex, e->y + c->shakey, 0xFFFF, 255);+}+static const EntClass CRUSHER = {.size = sizeof(Crusher), .name = "introCrusher", .update = crusher_update, .render = crusher_render,+ .kind = KIND_SOLID};+static void new_crusher(const EData *d) {+ int w = (int)EA(d, introCrusher, width), h = (int)EA(d, introCrusher, height);+ if (w / 8 * (h / 8) > 7 * 4) return;+ Ent *e = ent_new(&CRUSHER, d->x, d->y);+ if (!e) return;+ ent_box(e, (float)w, (float)h, 0, 0);+ e->safe = 1;+ e->depth = -10501;+ Crusher *c = ST(e, Crusher);+ c->start = v2(d->x, d->y);+ c->end = ed_node(d, 0);+ c->tw = (uint8_t)(w / 8), c->th = (uint8_t)(h / 8);+ tiles_box('3', c->tw, c->th, c->tiles);+ if (level_visited("1") || level_visited("0b")) {+ e->x = c->end.x, e->y = c->end.y;+ c->co.co = -1;+ }+}++/* ---------------------------------------------------------------- Bridge */+#define MAX_TILES 100+typedef struct {+ uint8_t img; /* its piece of scenery/bridge: 0..10 */+ uint8_t fallen;+ float shake_timer, speed_y, color_lerp;+ int8_t shakex, shakey;+ float rot[5], dy[5]; /* the 16-wide pieces: their images falling */+} BTile;+static const uint8_t TILE_X[11] = {0, 16, 24, 32, 40, 48, 56, 64, 72, 80, 96}, TILE_W[11] = {16, 8, 8, 8, 8, 8, 8, 8, 8, 16, 8};+static void btile_update(Ent *e) {+ BTile *t = ST(e, BTile);+ plat_update(e);+ bool wide = TILE_W[t->img] == 16;+ if (!t->fallen) return;+ if (t->shake_timer > 0) {+ t->shake_timer -= DT;+ if (level_on_interval(0.02f)) t->shakex = (int8_t)(rndi(3) - 1), t->shakey = (int8_t)(rndi(3) - 1);+ if (t->shake_timer <= 0) {+ e->collidable = 0;+ level_shake(0.1f);+ if (wide)+ for (int i = 0, y = 0; y < 52; y += i ? 12 : 24, i++)+ if (e->y - 8 + y > e->y + 4) dust_burst(v2(e->x + 8, e->y - 8 + y), -PI_F / 2, 8);+ }+ return;+ }+ t->color_lerp = approach(t->color_lerp, 1, 10 * DT);+ t->shakex = t->shakey = 0;+ if (wide) {+ for (int i = 0; i < 5; i++) {+ t->rot[i] -= (i % 2 ? 1.f : -1.f) * DT * i * 2;+ t->dy[i] += i * DT * 16;+ }+ t->speed_y = approach(t->speed_y, 120, 600 * DT);+ } else+ t->speed_y = approach(t->speed_y, 200, 900 * DT);+ plat_move_v(e, t->speed_y * DT);+ if (e_top(e) > 220) ent_remove(e);+}+static void btile_render(Ent *e) {+ BTile *t = ST(e, BTile);+ int x = TILE_X[t->img], w = TILE_W[t->img];+ /* the first image greys as it falls (Color.Lerp(White, Gray)) */+ int g = (int)(255 - (255 - 128) * t->color_lerp);+ uint16_t tint = rgb((uint32_t)(g << 16 | g << 8 | g));+ if (w == 16) {+ for (int i = 0, y = 0, h = 24; y < 52; y += h, h = 12, i++) {+ float ox = i == 0 ? t->shakex : 0, oy = i == 0 ? t->shakey : 0;+ gfx_tex_part_ex(T_scenery_bridge, e->x + 8 + ox, e->y + y - 8 + t->dy[i] + oy, x, y, w, h < 52 - y ? h : 52 - y, 8, 0, 1,+ 1, t->rot[i], i == 0 ? tint : 0xFFFF, 255, 0);+ }+ } else+ gfx_tex_part_ex(T_scenery_bridge, e->x + w / 2.f + t->shakex, e->y - 8 + t->shakey, x, 0, w, 52, w / 2.f, 0, 1, 1, 0, tint, 255, 0);+}+static const EntClass BTILE = {.size = sizeof(BTile), .name = "bridgeTile", .update = btile_update, .render = btile_render,+ .kind = KIND_JUMPTHRU};+static void btile_fall(Ent *e, float timer) {+ BTile *t = ST(e, BTile);+ if (!t->fallen) t->fallen = 1, t->shake_timer = timer;+}++typedef struct {+ uint16_t tiles[MAX_TILES]; /* g_ents indices, in order */+ int n;+ float width, collapse_timer;+ uint8_t can_collapse, end_a, end_b, ending;+} BridgeS;+static void bridge_take(BridgeS *b, int i, float timer) {+ btile_fall(&g_ents[b->tiles[i]], timer);+ memmove(b->tiles + i, b->tiles + i + 1, sizeof(uint16_t) * (size_t)(b->n - i - 1));+ b->n--;+}+static void bridge_update(Ent *e) {+ BridgeS *b = ST(e, BridgeS);+ Player *p = level_player();+ if (p && p->dead) p = NULL;+ if (!b->can_collapse) {+ if (p && p->ent->x >= e->x + 112) {+ b->can_collapse = b->end_a = b->end_b = 1;+ for (int i = 0; i < 11 && b->n; i++) bridge_take(b, 0, rnd_rangef(0.1f, 0.5f));+ }+ } else if (b->n > 0) {+ if (!p) return;+ if (b->end_a && p->ent->x > e->x + b->width - 216) {+ b->end_a = 0;+ for (int j = 0; j < 5 && b->n >= 8; j++) bridge_take(b, b->n - 8, rnd_rangef(0.1f, 0.5f));+ } else if (b->end_b && p->ent->x > e->x + b->width - 104) {+ b->end_b = 0;+ for (int k = 0; k < 7 && b->n > 0; k++) bridge_take(b, b->n - 1, rnd_rangef(0.1f, 0.3f));+ } else if (b->collapse_timer > 0) {+ b->collapse_timer -= DT;+ if (b->n >= 5 && p->ent->x >= g_ents[b->tiles[4]].x) bridge_take(b, 0, 0.2f);+ } else {+ bridge_take(b, 0, 0.2f);+ b->collapse_timer = 0.2f;+ }+ } else if (!b->ending)+ b->ending = 1;+}+static const EntClass BRIDGE = {.size = sizeof(BridgeS), .name = "bridge", .update = bridge_update};+static Ent *g_bridge;+static void new_bridge(const EData *d) {+ Ent *e = ent_new(&BRIDGE, d->x, d->y);+ if (!e) return;+ g_bridge = e;+ e->collidable = 0;+ e->visible = 0;+ BridgeS *b = ST(e, BridgeS);+ b->width = EA(d, bridge, width);+ float gap0 = ed_node(d, 0).x - d->rx + g_level.room->x, gap1 = ed_node(d, 1).x - d->rx + g_level.room->x;+ /* Calc.PushRandom(1): the same pieces as the game's */+ NetRandom r;+ rnd_seed(&r, 1);+ float x = d->x;+ int k = 0;+ while (x < d->x + b->width) {+ int img = (k < 2 || k > 7) ? k : 2 + rnd_range(&r, 6);+ if ((x < gap0 || x >= gap1) && b->n < MAX_TILES) {+ Ent *t = ent_new(&BTILE, x, d->y);+ if (t) {+ ent_box(t, (float)TILE_W[img], 5, 0, 0);+ ST(t, BTile)->img = (uint8_t)img;+ b->tiles[b->n++] = (uint16_t)(t - g_ents);+ }+ }+ x += TILE_W[img];+ k = (k + 1) % 11;+ }+}++/* ---------------------------------------------------------------- Granny: NPC00_Granny and CS00_Granny */+typedef struct {+ Sprite spr;+ uint16_t haha; /* its Hahaha */+ uint8_t talking;+} Granny;+static const EntClass GRANNY;++typedef struct {+ Cutscene cs;+ Ent *granny, *tb;+ float end_x;+ Step step, zoom;+ Walk walk;+ Co ev; /* the textbox's events, one at a time */+ int ev_index;+ uint8_t zooming;+} GrannyScene;++static Ent *granny_scene;+/* Textbox.Say's events: Meet, RunAlong, LaughAndAirQuotes, Laugh, StopLaughing, OminousZoom, PanToMaddy */+static bool granny_event(void *ctx, int index) {+ Ent *e = ctx;+ GrannyScene *s = ST(e, GrannyScene);+ Granny *g = ST(s->granny, Granny);+ Player *p = &g_player;+ Co *c = &s->ev;+ if (s->ev_index != index) {+ s->ev_index = index;+ memset(c, 0, sizeof *c);+ }+#define EV_BEGIN \+ if (c->wait > 0) { \+ c->wait -= DT; \+ return false; \+ } \+ switch (c->co) { \+ case 0:+#define EV_YIELD_(n) \+ do { \+ c->co = (n); \+ return false; \+ case (n):; \+ } while (0)+#define EV_YIELD EV_YIELD_(__COUNTER__ + 1)+#define EV_WAIT(t) \+ do { \+ c->wait = (t); \+ EV_YIELD; \+ } while (0)+#define EV_NEST(call) \+ do { \+ EV_YIELD; \+ while (call) EV_YIELD; \+ EV_YIELD; \+ } while (0)+#define EV_END \+ default:; \+ } \+ return true+ switch (index) {+ case 0: { /* Meet */+ EV_BEGIN;+ EV_WAIT(0.25f);+ g->spr.sx = signf(p->ent->x - s->granny->x);+ s->walk = walk_to(s->granny->x - 20);+ EV_NEST(player_walk(p, &s->walk));+ p->facing = 1;+ EV_WAIT(0.8f);+ EV_END;+ }+ case 1: { /* RunAlong */+ EV_BEGIN;+ s->walk = walk_exact((int)s->end_x);+ EV_NEST(player_walk(p, &s->walk));+ EV_WAIT(0.8f);+ p->facing = -1;+ EV_WAIT(0.4f);+ g->spr.sx = 1;+ step_reset(&s->step);+ EV_NEST(zoom_to(&s->step, v2(210, 90), 2, 0.5f));+ EV_WAIT(0.2f);+ EV_END;+ }+ case 2: { /* LaughAndAirQuotes */+ EV_BEGIN;+ EV_WAIT(0.6f);+ spr_play(&g->spr, A_granny_laugh, false);+ EV_WAIT(2);+ spr_play(&g->spr, A_granny_airQuotes, false);+ EV_END;+ }+ case 3: { /* Laugh */+ EV_BEGIN;+ EV_YIELD;+ spr_play(&g->spr, A_granny_laugh, false);+ EV_END;+ }+ case 4: /* StopLaughing */+ spr_play(&g->spr, A_granny_idle, false);+ return true;+ case 5: { /* OminousZoom: the zoom goes on by itself */+ EV_BEGIN;+ step_reset(&s->zoom);+ s->zooming = 1;+ spr_play(&g->spr, A_granny_idle, false);+ EV_WAIT(0.2f);+ EV_END;+ }+ case 6: { /* PanToMaddy */+ EV_BEGIN;+ while (s->zooming) EV_YIELD;+ EV_WAIT(0.2f);+ step_reset(&s->step);+ EV_NEST(zoom_across(&s->step, v2(210, 90), 2, 0.5f));+ EV_WAIT(0.2f);+ EV_END;+ }+ }+ return true;+}++static void granny_scene_end(Ent *e, bool skipped) {+ (void)skipped;+ GrannyScene *s = ST(e, GrannyScene);+ Granny *g = ST(s->granny, Granny);+ hahaha_enable(&g_ents[g->haha], true);+ spr_play(&g->spr, A_granny_laugh, false);+ g->spr.sx = 1;+ g_player.ent->x = s->end_x;+ g_player.facing = -1;+ player_set_state(&g_player, ST_NORMAL);+ level_set_flag("granny", true);+ zoom_reset();+ granny_scene = NULL;+}+static void granny_scene_update(Ent *e) {+ GrannyScene *s = ST(e, GrannyScene);+ Player *p = &g_player;+ if (s->zooming && !zoom_across(&s->zoom, v2(210, 100), 4, 3)) s->zooming = 0; /* its own coroutine */+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_set_state(p, ST_DUMMY);+ if (fabsf(p->ent->x - s->granny->x) < 20) {+ s->walk = walk_to(s->granny->x - 48);+ CO_NEST(c, player_walk(p, &s->walk));+ }+ p->facing = 1;+ CO_WAIT(c, 0.5f);+ s->ev_index = -1;+ CO_SAY(c, s->tb, "CH0_GRANNY", granny_event, e);+ step_reset(&s->step);+ CO_NEST(c, zoom_back(&s->step, 0.5f));+ cutscene_end(e);+ return;+ CO_END(c);+}+static const EntClass GRANNY_SCENE = {.size = sizeof(GrannyScene), .name = "CS00_Granny", .update = granny_scene_update};++static void granny_update(Ent *e) {+ Granny *g = ST(e, Granny);+ Player *p = level_player();+ if (p && !p->dead && !level_get_flag("granny") && !g->talking) {+ float left = (float)(g_level.room->x + 96);+ if (p->on_ground && p->ent->x >= left && p->ent->x <= e->x + 16 && fabsf(p->ent->y - e->y) < 4 &&+ p->facing == (int)signf(e->x - p->ent->x)) {+ g->talking = 1;+ Ent *cs = ent_new(&GRANNY_SCENE, 0, 0);+ if (cs) {+ cs->collidable = 0, cs->visible = 0;+ GrannyScene *s = ST(cs, GrannyScene);+ s->granny = e;+ s->end_x = e->x + 48;+ granny_scene = cs;+ cutscene_start(cs, granny_scene_end, true, false);+ }+ }+ }+ hahaha_enable(&g_ents[g->haha], g->spr.anim == A_granny_laugh);+ spr_update(&g->spr);+}+static void granny_render(Ent *e) {+ Granny *g = ST(e, Granny);+ Sprite s = g->spr;+ s.flipx = s.sx < 0;+ s.sx = fabsf(s.sx);+ spr_draw(&s, e->x, e->y);+}+static const EntClass GRANNY = {.size = sizeof(Granny), .name = "granny", .update = granny_update, .render = granny_render};+static void new_granny(const EData *d) {+ Ent *e = ent_new(&GRANNY, d->x, d->y);+ if (!e) return;+ e->depth = 1000;+ ent_box(e, 8, 8, -4, -8);+ Granny *g = ST(e, Granny);+ spr_init(&g->spr, SB_granny);+ spr_play(&g->spr, level_get_flag("granny") ? A_granny_laugh : A_granny_idle, false);+ Ent *h = hahaha_new(v2(d->x + 8, d->y - 4), NULL);+ if (h) {+ g->haha = (uint16_t)(h - g_ents);+ hahaha_enable(h, false);+ }+}++/* ---------------------------------------------------------------- CS00_Ending */+typedef struct {+ Cutscene cs;+ Ent *bird, *text;+ float t, percent;+ V2 from, to;+ uint8_t key_offed;+} Ending;+static bool ending_wait(Ending *s, float time) { /* WaitFor: raw time */+ s->t += RAW_DT;+ if (s->t < time) return true;+ s->t = 0;+ return false;+}+/* PrologueEndingText: "You can do this.", a character every 1/20 s after 4 s, sliding in as it fades */+typedef struct { Co co; float fade[24]; int n, i; } EndText;+static void endtext_update(Ent *e) {+ EndText *t = ST(e, EndText);+ CO_BEGIN(&t->co);+ if (!e->eid) CO_WAIT(&t->co, 4);+ for (t->i = 0; t->i < t->n; t->i++)+ while ((t->fade[t->i] += DT * 20) < 1) CO_YIELD(&t->co);+ CO_END(&t->co);+}+static void endtext_render(Ent *e) {+ EndText *t = ST(e, EndText);+ char text[32];+ int n = dialog_clean("CH0_END", text, sizeof text);+ float w = font_measure(text, n, FONT_S);+ float x = 160 - w / 2, y = g_level.ending_text_y / 6 - font_line_height(FONT_S) / 2;+ gfx_hud(true);+ int k = 0;+ for (const char *s = text, *end = text + n; s < end; k++) {+ uint32_t c = utf8_next(&s, end);+ const char *nx = s;+ uint32_t next = s < end ? utf8_next(&nx, end) : 0;+ float f = k < 24 ? fminf(t->fade[k], 1) : 1;+ if (f > 0) font_draw_glyph(FONT_S, c, x, y - 8 * (1 - f) / 6, 0xD69A, (uint8_t)(f * 255));+ x += font_glyph_advance(FONT_S, c, next);+ }+ gfx_hud(false);+}+static const EntClass ENDTEXT = {.size = sizeof(EndText), .name = "PrologueEndingText", .update = endtext_update,+ .render = endtext_render};+static Ent *endtext_new(bool instant) {+ Ent *e = ent_new(&ENDTEXT, 0, 0);+ if (!e) return NULL;+ e->tags = TAG_HUD | TAG_PERSISTENT;+ e->collidable = 0;+ e->eid = instant;+ char text[32];+ ST(e, EndText)->n = dialog_clean("CH0_END", text, sizeof text);+ if (instant)+ for (int i = 0; i < 24; i++) ST(e, EndText)->fade[i] = 1;+ return e;+}++static void ending_end(Ent *e, bool skipped) {+ Ending *s = ST(e, Ending);+ Player *p = &g_player;+ if (skipped) {+ if (s->bird && s->bird->cls) s->bird->visible = 0;+ p->ent->x = 2120, p->ent->y = 40;+ player_set_state(p, ST_DUMMY);+ p->dummy_auto_animate = false;+ spr_play(&p->spr, A_player_tired, false);+ p->speed = v2(0, 0);+ g_level.cam.y = (float)g_level.room->y - 3900;+ if (!s->text) s->text = endtext_new(true);+ else {+ EndText *t = ST(s->text, EndText);+ for (int i = 0; i < 24; i++) t->fade[i] = 1;+ }+ g_level.ending_text_y = 540;+ }+ g_time_rate = 1;+ g_level.pause_lock = true;+ g_level.ending_delay = 3; /* EndingCutsceneDelay: then CompleteArea(spotlightWipe: false) */+}+static void ending_update(Ent *e) {+ Ending *s = ST(e, Ending);+ Player *p = &g_player;+ Bird *b = ST(s->bird, Bird);+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ while (g_time_rate > 0) {+ CO_YIELD(c);+ g_level.shake_timer = 0; /* StopShake */+ g_level.shake_vec = v2(0, 0);+ g_time_rate -= RAW_DT * 2;+ }+ g_time_rate = 0;+ player_set_state(p, ST_DUMMY);+ p->facing = 1;+ s->t = 0;+ CO_NEST(c, ending_wait(s, 1));+ b->facing = -1;+ spr_play(&b->spr, A_bird_fall, false);+ s->percent = 0;+ s->from = v2(s->bird->x, s->bird->y);+ s->to = b->start;+ while (s->percent < 1) {+ {+ float k = ease_quad_out(s->percent);+ s->bird->x = s->from.x + (s->to.x - s->from.x) * k, s->bird->y = s->from.y + (s->to.y - s->from.y) * k;+ }+ if (s->percent > 0.5f) spr_play(&b->spr, A_bird_fly, false);+ s->percent += RAW_DT * 0.5f;+ CO_YIELD(c);+ }+ s->bird->x = s->to.x, s->bird->y = s->to.y;+ dust_burst(s->to, -PI_F / 2, 12);+ spr_play(&b->spr, A_bird_idle, false);+ CO_NEST(c, ending_wait(s, 0.5f));+ spr_play(&b->spr, A_bird_peck, false);+ CO_NEST(c, ending_wait(s, 1.1f));+ {+ GuiControl ctl[3] = {{GC_DIR, 0, {1, -1}, ""}, {GC_TEXT, 0, {0, 0}, "+"}, {GC_BUTTON, IN_DASH, {0, 0}, ""}};+ tutorial_init(&g_tuts[0], s->bird, v2(0, -16), "tutorial_dash", ctl, 3);+ b->sub_step = 0;+ }+ CO_NEST(c, bird_show_tutorial(s->bird, &g_tuts[0], true));+ while (!(g_in.aim_x > 0 && g_in.aim_y < 0 && btn_pressed(&g_in.dash))) CO_YIELD(c);+ player_set_state(p, ST_BIRDDASHTUTORIAL);+ p->dashes = 0;+ g_session.inv_dashes = 1;+ p->inventory_dashes = 1;+ g_time_rate = 1;+ s->key_offed = 1;+ b->routine = NULL; /* its tutorial is over: it hides the bubble, then startles and flies away */+ b->hide_then_fly = 1;+ CO_WAIT(c, 0.25f);+ b->fly_now = 1;+ while (!p->dead && !p->on_ground) CO_YIELD(c);+ CO_WAIT(c, 2);+ CO_WAIT(c, 2);+ /* PrologueEndingText and the hires snow fade in while the camera goes up 3900 */+ s->percent = 0;+ s->text = endtext_new(false);+ g_level.ending_text_y = -540;+ while (s->percent < 1) {+ s->percent += DT * 0.25f;+ g_level.ending_text_y = 540 - 1080 * (1 - ease_cube_inout(s->percent));+ g_level.cam.y = (float)g_level.room->y - 3900 * ease_cube_inout(s->percent);+ CO_YIELD(c);+ }+ cutscene_end(e);+ return;+ CO_END(c);+}+static const EntClass ENDING = {.size = sizeof(Ending), .name = "CS00_Ending", .update = ending_update};+void prologue_ending_start(Player *p, Ent *bird) {+ (void)p;+ Ent *e = ent_new(&ENDING, 0, 0);+ if (!e) return;+ e->collidable = 0, e->visible = 0;+ ST(e, Ending)->bird = bird;+ cutscene_start(e, ending_end, false, true);+}++/* ---------------------------------------------------------------- the factory */+bool ents_ch0(const EData *d) {+ switch (d->type) {+ case ET_introCar: new_car(d); return true;+ case ET_introCrusher: new_crusher(d); return true;+ case ET_bridge: new_bridge(d); return true;+ case ET_npc:+ if (!strncmp(EAS(d, npc, npc), "granny_00", 9)) {+ new_granny(d);+ return true;+ }+ return false;+ }+ return false;+}diff --git a/games/celeste/src/ch1.c b/games/celeste/src/ch1.cnew file mode 100644index 00000000..79741aa7--- /dev/null+++ b/games/celeste/src/ch1.c@@ -0,0 +1,649 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* Forsaken City (chapter 1): Theo at his campfire (NPC01_Theo), the bonfire+ * (Bonfire), the ending (CS01_Ending), the memorial (Memorial, MemorialText).+ * Line by line from the game's code.+ *+ * Also the pieces chapters 1 to 4 share (ch1_ functions, used by ch2.c to+ * ch4.c): the talk prompt's interface entity, Session counters, SaveData's+ * Theo flags, and NPC.MoveTo. */+#include "npc.h"+#include "talk.h"++/* ---------------------------------------------------------------- shared: TalkComponentUI */+/* the prompt is an entity of the interface (TAG_HUD): it draws its owner's Talk */+typedef struct { const EntClass *cls; int16_t owner; uint16_t off; } TalkUi;+static Ent *talkui_owner(Ent *e) {+ TalkUi *u = ST(e, TalkUi);+ Ent *o = &g_ents[u->owner];+ return o->cls == u->cls && o->dead != 1 ? o : NULL;+}+static void talkui_update(Ent *e) {+ if (!talkui_owner(e)) talk_removed(&g_ents[ST(e, TalkUi)->owner]), ent_remove(e);+}+static void talkui_render(Ent *e) {+ Ent *o = talkui_owner(e);+ if (o) talk_render((Talk *)(void *)(g_ent_arena + (uint32_t)o->data * 4 + ST(e, TalkUi)->off), o);+}+static const EntClass TALKUI = {.size = sizeof(TalkUi), .name = "talkUI", .update = talkui_update, .render = talkui_render};+/* Add(Talker = new TalkComponent(...)): t is in owner's state */+void ch1_talk_add(Ent *owner, Talk *t, int x, int y, int w, int h, V2 draw_at) {+ talk_init(t, x, y, w, h, draw_at);+ Ent *e = ent_new(&TALKUI, 0, 0);+ if (!e) return;+ e->tags = TAG_HUD;+ e->depth = owner->depth;+ e->collidable = 0;+ TalkUi *u = ST(e, TalkUi);+ u->cls = owner->cls;+ u->owner = (int16_t)(owner - g_ents);+ u->off = (uint16_t)((uint8_t *)t - (g_ent_arena + (uint32_t)owner->data * 4));+}+/* Remove(Talker) */+void ch1_talk_remove(Ent *owner) {+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &TALKUI && ST(&g_ents[i], TalkUi)->owner == owner - g_ents) ent_remove(&g_ents[i]);+ talk_removed(owner);+}++/* ---------------------------------------------------------------- shared: Session counters, SaveData flags */+static uint32_t name_hash(const char *s) {+ uint32_t h = 2166136261u;+ while (*s) h = (h ^ (uint8_t)*s++) * 16777619u;+ return h;+}+int ch1_counter(const char *name) { /* Session.GetCounter */+ uint32_t h = name_hash(name);+ for (int i = 0; i < 3; i++)+ if (g_session.counters[i].key == h) return g_session.counters[i].value;+ return 0;+}+void ch1_set_counter(const char *name, int v) { /* Session.SetCounter */+ uint32_t h = name_hash(name);+ int k = 2;+ for (int i = 2; i >= 0; i--)+ if (g_session.counters[i].key == h || !g_session.counters[i].key) k = i;+ for (int i = 0; i < 3; i++)+ if (g_session.counters[i].key == h) k = i;+ g_session.counters[k].key = h, g_session.counters[k].value = v;+}++/* Dialog.Clean, its {n} and {break} new lines */+int ch1_clean_lines(const char *key, char *out, int cap) { return dialog_clean(key, out, cap); }++/* ---------------------------------------------------------------- shared: Level.Flash */+/* a color over the gameplay that comes in fast and fades (drawn under the interface's other entities) */+typedef struct { uint32_t color; float flash; uint8_t doflash; } Flash;+static void flash_update(Ent *e) {+ Flash *f = ST(e, Flash);+ if (f->doflash) {+ f->flash = approach(f->flash, 1, DT * 10);+ if (f->flash >= 1) f->doflash = 0;+ } else if (f->flash > 0)+ f->flash = approach(f->flash, 0, DT * 3);+ else+ ent_remove(e);+}+static void flash_render(Ent *e) {+ Flash *f = ST(e, Flash);+ gfx_hud(true);+ gfx_rect(-1, -1, 322, 182, rgb(f->color), (uint8_t)(f->flash * 255));+ gfx_hud(false);+}+static const EntClass FLASH = {.size = sizeof(Flash), .name = "flash", .update = flash_update, .render = flash_render};+void ch1_flash(uint32_t color) {+ Ent *e = NULL;+ for (int i = 0; i < g_nents && !e; i++)+ if (g_ents[i].cls == &FLASH && g_ents[i].dead != 1) e = &g_ents[i];+ if (!e && (e = ent_new(&FLASH, 0, 0))) e->tags = TAG_HUD | TAG_GLOBAL, e->depth = 2000000, e->collidable = 0;+ if (!e) return;+ Flash *f = ST(e, Flash);+ f->doflash = 1, f->flash = 1, f->color = color;+}++/* ---------------------------------------------------------------- shared: NPC.MoveTo */+/* a nested step (true while it runs); m->step starts at 0. flags: MV_FADEIN, MV_REMOVE (MoveToAndRemove),+ * MV_NOY (MoveY false), MV_TURN (turnAtEndTo: m->turn) */+typedef struct { V2 target; float speed, alpha; int8_t turn; uint8_t step, flags, pad; } Move;+enum { MV_FADEIN = 1, MV_REMOVE = 2, MV_NOY = 4, MV_TURN = 8 };+bool ch1_move_to(Ent *e, Sprite *s, Move *m, float maxspeed, int move_anim, int idle_anim) {+ switch (m->step) {+ case 0:+ if (m->flags & MV_REMOVE) e->tags |= TAG_TRANSITION_UPDATE;+ if (signf(m->target.x - e->x) != 0 && s) s->sx = signf(m->target.x - e->x);+ m->alpha = m->flags & MV_FADEIN ? 0 : 1;+ if (s && move_anim >= 0) spr_play(s, move_anim, false);+ m->speed = 0;+ m->step = 1;+ /* fall through */+ case 1:+ if (!(m->flags & MV_NOY) ? (e->x != m->target.x || e->y != m->target.y) : e->x != m->target.x) {+ m->speed = approach(m->speed, maxspeed, 160 * DT);+ if (!(m->flags & MV_NOY)) { /* Calc.Approach(Vector2...) */+ V2 d = v2sub(m->target, v2(e->x, e->y));+ float l = v2len(d), k = m->speed * DT;+ if (l <= k) e->x = m->target.x, e->y = m->target.y;+ else e->x += d.x / l * k, e->y += d.y / l * k;+ } else+ e->x = approach(e->x, m->target.x, m->speed * DT);+ if (s) s->alpha = (uint8_t)(m->alpha * 255);+ m->alpha = approach(m->alpha, 1, DT);+ return true;+ }+ if (s && idle_anim >= 0) spr_play(s, idle_anim, false);+ m->step = 2;+ /* fall through */+ case 2:+ if (m->alpha < 1) {+ if (s) s->alpha = (uint8_t)(m->alpha * 255);+ m->alpha = approach(m->alpha, 1, DT);+ return true;+ }+ if ((m->flags & MV_TURN) && s) s->sx = m->turn;+ m->step = 3;+ if (m->flags & MV_REMOVE) ent_remove(e);+ return true;+ default:+ m->step = 0;+ return false;+ }+}+/* a sprite whose Scale.X turns it (flipped instead: the frames' origin is kept) */+static void draw_npc(const Sprite *spr, float x, float y) {+ Sprite s = *spr;+ s.flipx = s.sx < 0;+ s.sx = fabsf(s.sx);+ spr_draw(&s, x, y);+}++/* the textbox's events, each a coroutine run by its Co until it ends (as in ch0.c) */+#define EV_BEGIN \+ if (c->wait > 0) { \+ c->wait -= DT; \+ return false; \+ } \+ switch (c->co) { \+ case 0:+#define EV_YIELD_(n) \+ do { \+ c->co = (n); \+ return false; \+ case (n):; \+ } while (0)+#define EV_YIELD EV_YIELD_(__COUNTER__ + 1)+#define EV_WAIT(t) \+ do { \+ c->wait = (t); \+ EV_YIELD; \+ } while (0)+#define EV_NEST(call) \+ do { \+ EV_YIELD; \+ while (call) EV_YIELD; \+ EV_YIELD; \+ } while (0)+#define EV_END \+ default:; \+ } \+ return true+/* a new event: its coroutine starts over */+static Co *ev_start(Co *c, int8_t *at, int index) {+ if (*at != index) *at = (int8_t)index, memset(c, 0, sizeof *c);+ return c;+}++/* ---------------------------------------------------------------- Bonfire */+enum { BF_UNLIT, BF_LIT, BF_SMOKING };+typedef struct {+ Sprite spr;+ Wiggler wig;+ float brightness, mult, light;+ uint8_t mode, activated;+} Bonfire;+static void bonfire_set_mode(Ent *e, int mode) { /* SetMode */+ Bonfire *b = ST(e, Bonfire);+ b->mode = (uint8_t)mode;+ if (mode == BF_LIT)+ spr_play(&b->spr, b->activated ? (g_session.dreaming ? A_campfire_startDream : A_campfire_start)+ : (g_session.dreaming ? A_campfire_burnDream : A_campfire_burn), false);+ else if (mode == BF_SMOKING)+ spr_play(&b->spr, A_campfire_smoking, false);+ else {+ spr_play(&b->spr, A_campfire_idle, false);+ b->light = b->brightness = 0;+ }+ b->activated = 1;+}+static void bonfire_update(Ent *e) {+ Bonfire *b = ST(e, Bonfire);+ if (b->mode == BF_LIT) {+ b->mult = approach(b->mult, 1, DT * 2);+ if (level_on_interval(0.25f)) {+ b->brightness = 0.5f + rndf() * 0.5f;+ wiggler_restart(&b->wig);+ b->light = fminf(1, b->brightness + b->wig.value * 0.25f) * b->mult;+ }+ }+ spr_update(&b->spr);+ if (b->wig.active) {+ wiggler_update(&b->wig);+ b->light = fminf(1, b->brightness + b->wig.value * 0.25f) * b->mult;+ }+}+static void bonfire_render(Ent *e) {+ Bonfire *b = ST(e, Bonfire);+ spr_draw(&b->spr, e->x, e->y);+ light_add(e->x, e->y - 6, 0xDB7093, b->light, 32, 64); /* PaleVioletRed */+ bloom_add(e->x, e->y - 6, b->light, 32);+}+static const EntClass BONFIRE = {.size = sizeof(Bonfire), .name = "bonfire", .update = bonfire_update, .render = bonfire_render};+static void new_bonfire(const EData *d) {+ Ent *e = ent_new(&BONFIRE, d->x, d->y);+ if (!e) return;+ e->tags = TAG_TRANSITION_UPDATE;+ e->depth = -5;+ e->collidable = 0;+ Bonfire *b = ST(e, Bonfire);+ spr_init(&b->spr, SB_campfire);+ wiggler_init(&b->wig, 0.2f, 4);+ b->light = 1;+ const char *m = EAS(d, bonfire, mode);+ bonfire_set_mode(e, !strcmp(m, "lit") ? BF_LIT : !strcmp(m, "smoking") ? BF_SMOKING : BF_UNLIT); /* Added */+ b->activated = 0;+ bonfire_set_mode(e, b->mode);+}+static Ent *find_class(const EntClass *cls) {+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == cls && g_ents[i].dead != 1) return &g_ents[i];+ return NULL;+}++/* ---------------------------------------------------------------- NPC01_Theo */+typedef struct {+ Talk talk;+ Sprite spr;+ int8_t conv;+ uint8_t has_talk;+} Theo1;+typedef struct {+ Cutscene cs;+ Ent *theo, *tb;+ NpcWalk nw;+ Step step;+ Co ev;+ int8_t evi;+} Theo1Talk;+static const EntClass THEO1;++static bool theo1_event(void *ctx, int index) { /* CH1_THEO_A's PlayerApproach48px, CH1_THEO_F's Yolo */+ Theo1Talk *s = ST((Ent *)ctx, Theo1Talk);+ Ent *te = s->theo;+ Theo1 *t = ST(te, Theo1);+ Co *c = ev_start(&s->ev, &s->evi, index);+ if (t->conv == 0) { /* PlayerApproach48px */+ EV_BEGIN;+ EV_NEST(npc_approach(&s->nw, te, &t->spr, 48, 0));+ EV_END;+ }+ EV_BEGIN; /* Yolo */+ step_reset(&s->step);+ EV_NEST(zoom_to(&s->step, v2(128, 128), 2, 0.5f));+ EV_WAIT(0.2f);+ spr_play(&t->spr, A_theo_yolo, false);+ EV_WAIT(0.1f);+ level_dir_shake(v2(0, -1), 0.3f);+ particles_emit(PL_FG, &P_NPC01_Theo_P_YOLO, 6, v2(te->x - 3, te->y - 24), v2(4, 4), P_NPC01_Theo_P_YOLO.direction);+ EV_WAIT(0.5f);+ EV_END;+}+static void theo1_talk_end(Ent *e, bool skipped) { /* OnTalkEnd */+ (void)skipped;+ Theo1Talk *s = ST(e, Theo1Talk);+ Ent *te = s->theo;+ Theo1 *t = ST(te, Theo1);+ if (t->conv == 0) save_set_flag(0);+ else if (t->conv == 1) save_set_flag(1);+ else if (t->conv == 5) {+ level_set_flag("theoDoneTalking", true);+ if (t->has_talk) t->has_talk = 0, ch1_talk_remove(te);+ }+ Player *p = level_player();+ if (p) p->state_locked = false, player_set_state(p, ST_NORMAL);+ ch1_set_counter("theo", ch1_counter("theo") + 1);+ t->conv++;+ spr_play(&t->spr, A_theo_idle, false);+}+static void theo1_talk_update(Ent *e) { /* Talk */+ static const char *const KEYS[6] = {"CH1_THEO_A", "CH1_THEO_B", "CH1_THEO_C", "CH1_THEO_D", "CH1_THEO_E", "CH1_THEO_F"};+ Theo1Talk *s = ST(e, Theo1Talk);+ Ent *te = s->theo;+ Theo1 *t = ST(te, Theo1);+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ if (t->conv > 5) goto done;+ /* PlayerApproachRightSide(player, turnToFace, the 48 px from the third talk on) */+ CO_NEST(c, npc_approach(&s->nw, te, &t->spr, t->conv >= 2 ? 48 : 0, 1));+ if (t->conv == 1) {+ CO_WAIT(c, 0.2f);+ CO_NEST(c, npc_approach(&s->nw, te, &t->spr, 48, 0));+ }+ s->evi = -1;+ CO_SAY(c, s->tb, KEYS[t->conv], theo1_event, e);+ if (t->conv == 5) {+ spr_play(&t->spr, A_theo_yoloEnd, false);+ if (t->has_talk) t->has_talk = 0, ch1_talk_remove(te);+ step_reset(&s->step);+ CO_NEST(c, zoom_back(&s->step, 0.5f));+ }+done:+ cutscene_end(e);+ return;+ CO_END(c);+}+static const EntClass THEO1TALK = {.size = sizeof(Theo1Talk), .name = "NPC01_Theo.Talk", .update = theo1_talk_update};+static void theo1_update(Ent *e) {+ Theo1 *t = ST(e, Theo1);+ spr_update(&t->spr);+ if (t->has_talk && talk_update(&t->talk, e)) { /* OnTalk: Level.StartCutscene(OnTalkEnd), the Talk routine */+ Ent *c = ent_new(&THEO1TALK, 0, 0);+ if (!c) return;+ c->collidable = 0, c->visible = 0;+ ST(c, Theo1Talk)->theo = e;+ cutscene_start(c, theo1_talk_end, true, false);+ }+}+static void theo1_render(Ent *e) { draw_npc(&ST(e, Theo1)->spr, e->x, e->y); }+static const EntClass THEO1 = {.size = sizeof(Theo1), .name = "NPC01_Theo", .update = theo1_update, .render = theo1_render};+static void new_theo1(const EData *d) {+ Ent *e = ent_new(&THEO1, d->x, d->y);+ if (!e) return;+ e->depth = 1000;+ ent_box(e, 8, 8, -4, -8);+ Theo1 *t = ST(e, Theo1);+ spr_init(&t->spr, SB_theo);+ spr_play(&t->spr, A_theo_idle, false);+ t->conv = (int8_t)ch1_counter("theo");+ if (!level_get_flag("theoDoneTalking")) t->has_talk = 1, ch1_talk_add(e, &t->talk, -8, -8, 88, 8, v2(0, -24));+}++/* ---------------------------------------------------------------- CS01_Ending */+typedef struct {+ Cutscene cs;+ Ent *bonfire, *tb, *bird;+ Walk walk;+ Co ev;+ int8_t evi;+ float percent;+ V2 from, to;+} End1;+static bool end1_event(void *ctx, int index) { /* EndCityTrigger */+ End1 *s = ST((Ent *)ctx, End1);+ Player *p = &g_player;+ Ent *bf = s->bonfire;+ Co *c = ev_start(&s->ev, &s->evi, index);+ Bird *b;+ EV_BEGIN;+ EV_WAIT(0.2f);+ s->walk = walk_to(bf->x - 12);+ EV_NEST(player_walk(p, &s->walk));+ EV_WAIT(0.2f);+ p->facing = 1;+ p->dummy_auto_animate = false;+ spr_play(&p->spr, A_player_duck, false);+ EV_WAIT(0.5f);+ bonfire_set_mode(bf, BF_LIT);+ EV_WAIT(1);+ spr_play(&p->spr, A_player_idle, false);+ EV_WAIT(0.4f);+ p->dummy_auto_animate = true;+ s->walk = walk_to(bf->x - 24);+ EV_NEST(player_walk(p, &s->walk));+ EV_WAIT(0.4f);+ p->dummy_auto_animate = false;+ p->facing = 1;+ spr_play(&p->spr, A_player_sleep, false);+ EV_WAIT(4);+ s->bird = bird_new(v2add(v2(p->ent->x, p->ent->y), v2(88, -200)), BIRD_NONE);+ if (!s->bird) return true;+ b = ST(s->bird, Bird);+ b->facing = -1;+ spr_play(&b->spr, A_bird_fall, false);+ s->from = v2(s->bird->x, s->bird->y);+ s->to = v2add(v2(p->ent->x, p->ent->y), v2(1, -12));+ for (s->percent = 0; s->percent < 1; s->percent += DT * 0.5f) {+ {+ float k = ease_quad_out(s->percent);+ s->bird->x = s->from.x + (s->to.x - s->from.x) * k, s->bird->y = s->from.y + (s->to.y - s->from.y) * k;+ }+ if (s->percent > 0.5f) spr_play(&ST(s->bird, Bird)->spr, A_bird_fly, false);+ EV_YIELD;+ }+ s->bird->x = s->to.x, s->bird->y = s->to.y;+ spr_play(&ST(s->bird, Bird)->spr, A_bird_idle, false);+ EV_WAIT(0.5f);+ spr_play(&ST(s->bird, Bird)->spr, A_bird_croak, false);+ EV_WAIT(0.6f);+ EV_WAIT(0.9f);+ spr_play(&ST(s->bird, Bird)->spr, A_bird_sleep, false);+ EV_YIELD;+ EV_WAIT(2);+ EV_END;+}+static void end1_end(Ent *e, bool skipped) {+ (void)e, (void)skipped;+ level_complete_area(true, false);+}+static void end1_update(Ent *e) {+ End1 *s = ST(e, End1);+ Player *p = &g_player;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_set_state(p, ST_DUMMY);+ p->dashes = 1;+ CO_WAIT(c, 0.5f);+ s->walk = walk_to(s->bonfire->x + 40);+ CO_NEST(c, player_walk(p, &s->walk));+ CO_WAIT(c, 1.5f);+ p->facing = -1;+ CO_WAIT(c, 0.5f);+ s->evi = -1;+ CO_SAY(c, s->tb, "CH1_END", end1_event, e);+ CO_WAIT(c, 0.3f);+ cutscene_end(e);+ return;+ CO_END(c);+}+static const EntClass END1 = {.size = sizeof(End1), .name = "CS01_Ending", .update = end1_update};++/* EventTrigger "end_city" */+static void event1_enter(Ent *e, Player *p) {+ (void)p;+ if (*ST(e, uint8_t)) return;+ *ST(e, uint8_t) = 1;+ Ent *bf = find_class(&BONFIRE);+ Ent *c = bf ? ent_new(&END1, 0, 0) : NULL;+ if (!c) return;+ c->collidable = 0, c->visible = 0;+ ST(c, End1)->bonfire = bf;+ level_register_complete(); /* OnBegin */+ cutscene_start(c, end1_end, false, true);+}+static const EntClass EVENT1 = {.size = 1, .name = "eventTrigger", .on_enter = event1_enter, .kind = KIND_TRIGGER};++/* ---------------------------------------------------------------- Memorial and MemorialText */+#define MEMO_N 96+typedef struct {+ float index, alpha, timer, widest;+ uint8_t show, dreamy, n, first;+ char msg[MEMO_N];+ int16_t memorial;+} MemoText;+typedef struct { uint16_t floaty[3]; int16_t text; float timer; uint8_t dreaming; } Memo;+static const EntClass MEMORIAL;+static int memo_line_len(const MemoText *m, int start) { /* CountToNewline */+ int i = start;+ while (i < m->n && m->msg[i] != '\n') i++;+ return i - start;+}+static void memotext_message(MemoText *mt);+static void memotext_update(Ent *e) {+ MemoText *m = ST(e, MemoText);+ if (!m->n) memotext_message(m);+ if (g_level.paused) return;+ m->timer += DT;+ if (!m->show) {+ m->alpha = approach(m->alpha, 0, DT);+ if (m->alpha <= 0) m->index = m->first;+ } else {+ m->alpha = approach(m->alpha, 1, DT * 2);+ if (m->alpha >= 1) m->index = approach(m->index, m->n, 32 * DT);+ }+}+/* the glyphs, drawn into the strip (dreamy ones turn over: Scale.X -1) */+typedef struct { MemoText *m; float x0, y0, ease; int count; } MemoDraw;+static MemoDraw memo_draw;+/* a glyph of the 64 px face into a strip (gfx_custom layers: a page of text is one command): (x, top) the+ * left of its advance and the top of its line, view pixels; flip turns it over (Scale.X -1) */+void ch1_glyph(uint16_t *strip, int sy0, int sy1, uint32_t ch, float x, float top, bool flip, uint16_t col, uint8_t alpha) {+ const uint8_t *g = font_glyph_rec(FONT_S, ch);+ if (!g || !g[6]) return;+ float adv = rd16(g + 8) / 16.f;+ int w = g[6], h = g[7], stride = (w + 1) / 2;+ const uint8_t *bits = font_glyph_bits(FONT_S, g);+ int ox = (int)floorf(rds16(g + 2) / 16.f + 0.5f), Y0 = (int)floorf(top + 0.5f) + rds16(g + 4);+ int left = (int)floorf(x + 0.5f), mirror = (int)floorf(2 * x + adv + 0.5f);+ int ga = alpha + (alpha >> 7);+ for (int r = 0; r < h; r++) {+ int Y = Y0 + r;+ if (Y < sy0 || Y >= sy1) continue;+ uint16_t *row = strip + (Y - sy0) * VIEW_W;+ for (int i = 0; i < w; i++) {+ int X = flip ? mirror - (left + ox + i) - 1 : left + ox + i;+ if ((unsigned)X >= VIEW_W) continue;+ int v = (bits[r * stride + (i >> 1)] >> ((i & 1) * 4)) & 15;+ if (!v) continue;+ int a = (v * 17 * ga) >> 8;+ uint32_t c = col, pr = ((c >> 11) * a) >> 8, pg = (((c >> 5) & 63) * a) >> 8, pb = ((c & 31) * a) >> 8;+ row[X] = blend565(row[X], (uint16_t)(pr << 11 | pg << 5 | pb), a + 1);+ }+ }+}+static void memo_layer(uint16_t *strip, int sy0, int sy1, void *ctx) {+ MemoDraw *d = ctx;+ MemoText *m = d->m;+ int col = 0, len = memo_line_len(m, 0);+ float y = 64 * (1 - d->ease) / 6;+ for (int i = 0; i < d->count; i++) {+ char c = m->msg[i];+ if (c == '\n') {+ col = 0;+ len = memo_line_len(m, i + 1);+ y += font_line_height(FONT_S) * 1.1f;+ continue;+ }+ bool flip = false;+ float yo = 0;+ float x = (-len * m->widest / 2 + (col + 0.5f) * m->widest) / 6;+ if (m->dreamy && c != ' ' && c != '-') {+ float sn = sinf(m->timer * 2 + i / 8.f);+ c = m->msg[(i + (int)(sn * 4) + m->n) % m->n];+ yo = sn * 8 / 6;+ flip = sinf(m->timer * 4 + i / 16.f) < 0;+ }+ if (c != '\n') { /* ActiveFont.Draw(c, at, justify (0.5, 1), scale) */+ const uint8_t *g = font_glyph_rec(FONT_S, (uint8_t)c);+ float adv = g ? rd16(g + 8) / 16.f : 0;+ ch1_glyph(strip, sy0, sy1, (uint8_t)c, d->x0 + x - adv / 2, d->y0 + y + yo - font_line_height(FONT_S), flip, 0xFFFF,+ (uint8_t)(d->ease * 255));+ }+ col++;+ }+}+static void memotext_render(Ent *e) {+ MemoText *m = ST(e, MemoText);+ Ent *me = &g_ents[m->memorial];+ if (g_level.frozen || g_level.paused || g_level.completed || !(m->index > 0) || !(m->alpha > 0) || me->cls != &MEMORIAL) return;+ memo_draw.m = m;+ memo_draw.x0 = me->x - g_level.cam.x;+ memo_draw.y0 = me->y - g_level.cam.y - (350 + font_line_height(FONT_S) * 6 * 3.3f) / 6;+ memo_draw.ease = ease_cube_inout(m->alpha);+ memo_draw.count = (int)fminf(m->n, m->index);+ gfx_hud(true);+ gfx_custom(memo_layer, &memo_draw, (int)memo_draw.y0 - 24, (int)memo_draw.y0 + 50);+ gfx_hud(false);+}+static const EntClass MEMOTEXT = {.size = sizeof(MemoText), .name = "MemorialText", .update = memotext_update, .render = memotext_render};+static void memorial_update(Ent *e) {+ Memo *m = ST(e, Memo);+ if (g_level.paused) return;+ Ent *t = &g_ents[m->text];+ Ent *p = level_player_ent();+ if (t->cls == &MEMOTEXT) ST(t, MemoText)->show = p && collide_ent_at(e, e->x, e->y, p);+ m->timer += DT;+}+static void memorial_render(Ent *e) {+ Memo *m = ST(e, Memo);+ Tex t;+ if (tex_get(T_scenery_memorial_memorial, &t)) gfx_tex_ex(T_scenery_memorial_memorial, e->x, e->y, t.fw / 2.f, (float)t.fh, 1, 1, 0, 0xFFFF, 255, 0);+ /* the dreamy text: a Sprite of scenery/memorial/floatytext looping at 0.1, at (-Width / 2, -33) */+ if (m->dreaming) gfx_tex(m->floaty[(int)(m->timer / 0.1f) % 3], e->x - 10, e->y - 33, 0, 0xFFFF, 255);+}+static const EntClass MEMORIAL = {.size = sizeof(Memo), .name = "memorial", .update = memorial_update, .render = memorial_render};+static void new_memorial(const EData *d) {+ Ent *e = ent_new(&MEMORIAL, d->x, d->y);+ if (!e) return;+ e->tags = TAG_PAUSE_UPDATE;+ e->depth = 100;+ ent_box(e, 60, 80, -30, -60);+ Memo *m = ST(e, Memo);+ m->dreaming = g_session.dreaming;+ char pth[40];+ for (int i = 0; i < 3 && m->dreaming; i++) m->floaty[i] = res_tex_by_name(path2(pth, "scenery/memorial/floatytext", NULL, i));+ Ent *t = ent_new(&MEMOTEXT, 0, 0);+ if (!t) return;+ t->tags = TAG_HUD | TAG_PAUSE_UPDATE;+ t->collidable = 0;+ m->text = (int16_t)(t - g_ents);+ MemoText *mt = ST(t, MemoText);+ mt->memorial = (int16_t)(e - g_ents);+ mt->dreamy = g_session.dreaming;+}+/* the constructor's message (read once the room is loaded: the dialog is decoded in free cache memory) */+static void memotext_message(MemoText *mt) {+ int k = ch1_clean_lines("memorial", mt->msg, MEMO_N);+ mt->n = (uint8_t)k;+ mt->first = (uint8_t)memo_line_len(mt, 0);+ mt->index = mt->first;+ for (int i = 0; i < k; i++) {+ const uint8_t *g = font_glyph_rec(FONT_S, (uint8_t)mt->msg[i]);+ float w = g ? rd16(g + 8) * 6 / 16.f : 0; /* ActiveFont.Measure(c).X, interface pixels */+ if (w > mt->widest) mt->widest = w;+ }+ mt->widest *= 0.9f;+}++/* ---------------------------------------------------------------- the factories */+bool ents_ch1(const EData *d) {+ switch (d->type) {+ case ET_npc:+ if (!strcmp(EAS(d, npc, npc), "theo_01_campfire")) {+ new_theo1(d);+ return true;+ }+ return false;+ case ET_bonfire:+ if (g_session.area < 1 || g_session.area > 4) return false;+ new_bonfire(d);+ return true;+ case ET_memorial: new_memorial(d); return true;+ }+ return false;+}++bool trigs_ch1(const EData *d) {+ if (d->type != TT_eventTrigger || strcmp(EAS(d, eventTrigger, event), "end_city")) return false;+ Ent *e = ent_new(&EVENT1, d->x, d->y);+ if (e) ent_box(e, EA(d, eventTrigger, width), EA(d, eventTrigger, height), 0, 0), e->visible = 0;+ return true;+}diff --git a/games/celeste/src/ch2.c b/games/celeste/src/ch2.cnew file mode 100644index 00000000..09afcca3--- /dev/null+++ b/games/celeste/src/ch2.c@@ -0,0 +1,2974 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* Old Site (chapter 2), ported from the game's classes: dream blocks+ * (DreamBlock), the chasers (BadelineOldsite), touch switches and switch+ * gates, hanging lamps, floating and foreground debris, the dream mirror and+ * its cutscene, the payphone, lookouts (Lookout), invisible barriers+ * and the chapter's triggers. Dream dashing itself is in player.c.+ * The story: Badeline's intro (CS02_BadelineIntro), the phone calls+ * (CS02_DreamingPhonecall, CS02_Ending), the journal (CS02_Journal), Theo+ * at his campfire (NPC02_Theo, Selfie), and BadelineDummy. */+#include <stdlib.h>+#include "npc.h"+#include "talk.h"++/* the story's shared pieces (ch1.c) */+void ch1_talk_add(Ent *owner, Talk *t, int x, int y, int w, int h, V2 draw_at);+void ch1_talk_remove(Ent *owner);+int ch1_counter(const char *name);+void ch1_set_counter(const char *name, int v);+void ch1_flash(uint32_t color);+int ch1_clean_lines(const char *key, char *out, int cap);+bool save_flag(int bit);+void save_set_flag(int bit);+bool textbox_portrait(int *bank, int *idle);++/* ---------------------------------------------------------------- helpers */+static uint16_t tex(const char *p) { return res_tex_by_name(p); }+static float shake_val(void) { /* Calc.Random.ShakeVector */+ static const int8_t o[5] = {-1, -1, 0, 1, 1};+ return o[rndi(5)];+}+static uint32_t lerp_rgb(uint32_t a, uint32_t b, float t) {+ t = clampf(t, 0, 1);+ int r = (int)(((a >> 16) & 255) + (((int)((b >> 16) & 255) - (int)((a >> 16) & 255)) * t));+ int g = (int)(((a >> 8) & 255) + (((int)((b >> 8) & 255) - (int)((a >> 8) & 255)) * t));+ int bl = (int)((a & 255) + (((int)(b & 255) - (int)(a & 255)) * t));+ return (uint32_t)(r << 16 | g << 8 | bl);+}+static uint32_t scale_rgb(uint32_t c, float k) {+ k = clampf(k, 0, 1);+ return (uint32_t)((int)(((c >> 16) & 255) * k) << 16 | (int)(((c >> 8) & 255) * k) << 8 | (int)((c & 255) * k));+}+static const char *room_of(const Ent *e) {+ const Room *r = &g_level.rooms[e->room];+ return r->info ? str(rd16(r->info)) : "";+}+/* the room an entity is being created in (entities_load sets room_slot) */+static const char *loading_room(void) {+ const Room *r = &g_level.rooms[g_level.room_slot];+ return r->info ? str(rd16(r->info)) : "";+}+/* Session.GetLevelFlag: a room was visited (Level.LoadLevel adds the one it loads before its entities) */+static bool room_visited(const char *name) {+ int i = chapter_find_room(g_session.chapter, name);+ if (i < 0) return false;+ return g_level.rooms[g_level.room_slot].index == i || (g_session.visited[i >> 3] & (1 << (i & 7)));+}+static bool player_on_ground(Player *p) { return actor_on_ground(p->ent, 1); }+/* entity references in states (only 4-byte aligned): an index into g_ents */+static int16_t ent_ref(const Ent *e) { return e ? (int16_t)(e - g_ents) : -1; }+static Ent *ent_at(int16_t i, const EntClass *cls) { return i >= 0 && g_ents[i].cls == cls && g_ents[i].dead != 1 ? &g_ents[i] : NULL; }+static float quad_curve(float a, float c, float b, float t) { return (1 - t) * (1 - t) * a + 2 * (1 - t) * t * c + t * t * b; }++/* drawing straight into a strip (gfx_custom layers): view coordinates */+static inline void sp_plot(uint16_t *strip, int sy0, int sy1, int x, int y, uint16_t c, int a) {+ if (y < sy0 || y >= sy1 || (unsigned)x >= VIEW_W) return;+ uint16_t *d = strip + (y - sy0) * VIEW_W + x;+ *d = a >= 256 ? c : blend565(*d, scale565(c, a), a);+}+static void sp_rect(uint16_t *strip, int sy0, int sy1, int x, int y, int w, int h, uint16_t c, int a) {+ int x0 = x < 0 ? 0 : x, x1 = x + w > VIEW_W ? VIEW_W : x + w;+ int y0 = y < sy0 ? sy0 : y, y1 = y + h > sy1 ? sy1 : y + h;+ if (x0 >= x1 || y0 >= y1 || a <= 0) return;+ uint16_t pc = a >= 256 ? c : scale565(c, a);+ for (int r = y0; r < y1; r++) {+ uint16_t *d = strip + (r - sy0) * VIEW_W + x0;+ if (a >= 256)+ for (int i = x0; i < x1; i++) *d++ = c;+ else+ for (int i = x0; i < x1; i++, d++) *d = blend565(*d, pc, a);+ }+}+static void sp_line(uint16_t *strip, int sy0, int sy1, int x0, int y0, int x1, int y1, uint16_t c) {+ if ((y0 < sy0 && y1 < sy0) || (y0 >= sy1 && y1 >= sy1)) return;+ int dx = abs(x1 - x0), dy = -abs(y1 - y0), sx = x0 < x1 ? 1 : -1, sy = y0 < y1 ? 1 : -1, err = dx + dy;+ for (int guard = 0; guard < 1024; guard++) {+ sp_plot(strip, sy0, sy1, x0, y0, c, 256);+ if (x0 == x1 && y0 == y1) break;+ int e2 = 2 * err;+ if (e2 >= dy) err += dy, x0 += sx;+ if (e2 <= dx) err += dx, y0 += sy;+ }+}+static inline int vx(float x) { return (int)floorf(x + 0.5f) - g_camx; }+static inline int vy(float y) { return (int)floorf(y + 0.5f) - g_camy; }+/* a stored row of a texture as palette indices (0: transparent), like gfx.c's */+enum { OFF_rowbuf = 0, END_rowbuf = OFF_rowbuf + (int)sizeof(uint8_t[256]) };+#define rowbuf (*(uint8_t(*)[256])(void *)(g_chram[2] + OFF_rowbuf))+static void tex_row_idx(const Tex *t, int r, uint8_t *out) { tex_row(t, r, out); }+/* a small texture's whole frame (fw x fh) as palette indices, and its palette */+static bool tex_frame_idx(uint16_t id, uint8_t *buf, int fw, int fh, const uint16_t **col, const uint8_t **al) {+ Tex t;+ if (!tex_get(id, &t) || t.fw != fw || t.fh != fh || t.w > (int)sizeof rowbuf) return false;+ memset(buf, 0, (size_t)(fw * fh));+ for (int r = 0; r < t.h; r++) {+ tex_row_idx(&t, r, rowbuf);+ for (int i = 0; i < t.w; i++)+ if (t.oy + r < fh && t.ox + i < fw) buf[(t.oy + r) * fw + t.ox + i] = rowbuf[i];+ }+ int n;+ *col = pal_colors(t.pal, &n);+ *al = pal_alpha(t.pal);+ return true;+}+/* a texture a gfx_custom layer reads, loaded now and marked drawn this frame: nothing loads while the+ * strips are drawn (res.c), and what was drawn longest ago goes first */+static void tex_touch(uint16_t id) {+ Tex t;+ if (id != 0xFFFF) tex_get(id, &t);+}+/* a palette entry drawn with a tint (or as a silhouette of it) and an alpha */+static inline void sp_texel(uint16_t *d, const uint16_t *col, const uint8_t *al, uint8_t v, uint16_t tint, int ga, bool sil) {+ int aa = al[v - 1] + (al[v - 1] >> 7);+ uint16_t c = sil ? (aa >= 256 ? tint : scale565(tint, aa)) : tint != 0xFFFF ? mul565(col[v - 1], tint) : col[v - 1];+ if (ga < 256) c = scale565(c, ga), aa = (aa * ga) >> 8;+ *d = aa >= 256 ? c : blend565(*d, c, aa);+}++/* ---------------------------------------------------------------- DreamBlock */+typedef struct {+ V2 start, end;+ Tween tw;+ uint8_t tw_reverse;+ float anim, wobble_from, wobble_to, wobble_ease;+ float white_fill, white_height;+ uint32_t seed;+ uint16_t n; /* particles */+ uint8_t moving, one_use, active, inside;+ int8_t sx, sy; /* the Shaker's offset */+} Dream;+static void dream_setup(Ent *e) {+ Dream *d = ST(e, Dream);+ d->n = (uint16_t)(int)(e->cw / 8 * (e->ch / 8) * 0.7f);+ d->seed = (uint32_t)rnd_next(&g_rnd);+}+/* a particle's random values (Setup), from a hash of the block's seed */+static uint32_t dream_hash(uint32_t x) {+ x ^= x >> 16, x *= 0x7feb352du, x ^= x >> 15, x *= 0x846ca68bu, x ^= x >> 16;+ return x;+}+static const uint32_t DREAM_COLORS[3][3] = {{0xFFEF11, 0xFF00D0, 0x08a310}, {0x5fcde4, 0x7fb25e, 0xE0564C}, {0x5b6ee1, 0xCC3B3B, 0x7daa64}};+static const uint8_t DREAM_LAYERS[6] = {0, 1, 1, 2, 2, 2};+/* the particle textures (objects/dreamblock/particles): pixels around the center */+static const int8_t PT_DOT[] = {0, 0};+static const int8_t PT_PLUS[] = {0, -1, -1, 0, 0, 0, 1, 0, 0, 1};+static const int8_t PT_DIAMOND[] = {0, -2, -1, -1, 0, -1, 1, -1, -2, 0, -1, 0, 1, 0, 2, 0, -1, 1, 0, 1, 1, 1, 0, 2};++static float dream_amp(float seed, float index) {+ return (sinf(seed + index / 16.f + sinf(seed * 2.f + index / 32.f) * 6.2831855f) + 1) * 1.5f;+}+static void dream_wobble_line(uint16_t *strip, int sy0, int sy1, Dream *d, V2 from, V2 to, float offset, uint16_t line, uint16_t back) {+ V2 dv = v2sub(to, from);+ float num = v2len(dv);+ V2 n = v2norm(dv), perp = v2(n.y, -n.x);+ float last = 0;+ const int step = 16;+ for (int i = 2; (float)i < num - 2; i += step) {+ float amp = lerpf(dream_amp(d->wobble_from + offset, (float)i), dream_amp(d->wobble_to + offset, (float)i), d->wobble_ease);+ if ((float)(i + step) >= num) amp = 0;+ float len = fminf((float)step, num - 2 - i);+ V2 a = v2add(v2add(from, v2mul(n, (float)i)), v2mul(perp, last));+ V2 b = v2add(v2add(from, v2mul(n, i + len)), v2mul(perp, amp));+ sp_line(strip, sy0, sy1, vx(a.x - perp.x), vy(a.y - perp.y), vx(b.x - perp.x), vy(b.y - perp.y), back);+ sp_line(strip, sy0, sy1, vx(a.x - perp.x * 2), vy(a.y - perp.y * 2), vx(b.x - perp.x * 2), vy(b.y - perp.y * 2), back);+ sp_line(strip, sy0, sy1, vx(a.x), vy(a.y), vx(b.x), vy(b.y), line);+ last = amp;+ }+}+static const EntClass DREAMBLOCK;+static bool dream_on_camera(const Ent *e) {+ float cl = g_level.cam.x, ct = g_level.cam.y;+ return !(e_right(e) < cl || e_left(e) > cl + 320 || e_bottom(e) < ct || e_top(e) > ct + 180);+}+static void dream_draw(uint16_t *strip, int sy0, int sy1, Ent *e) {+ Dream *d = ST(e, Dream);+ float X = e->x + d->sx, Y = e->y + d->sy, W = e->cw, H = e->ch;+ if (vy(Y - 4) >= sy1 || vy(Y + H + 4) < sy0) return;+ uint32_t back = d->active ? 0x000000 : 0x1f2e2d, line = d->active ? 0xFFFFFF : 0x6a8480;+ sp_rect(strip, sy0, sy1, vx(X), vy(Y), (int)W, (int)H, rgb(back), 256);+ /* the stars: a parallax layer each, wrapped inside the block */+ for (int i = 0; i < d->n; i++) {+ uint32_t h1 = dream_hash(d->seed + (uint32_t)i * 3u), h2 = dream_hash(h1 ^ 0x68e31da4u), h3 = dream_hash(h2 + 0x1b56c4e9u);+ int layer = DREAM_LAYERS[h3 % 6];+ float px = (h1 >> 8) * (1.f / 16777216.f) * W, py = (h2 >> 8) * (1.f / 16777216.f) * H;+ float k = 0.3f + 0.25f * layer;+ px += g_level.cam.x * k, py += g_level.cam.y * k;+ px = e->x + fmodf(px - e->x, W);+ if (px < e->x) px += W;+ py = e->y + fmodf(py - e->y, H);+ if (py < e->y) py += H;+ if (!(px >= e->x + 2 && py >= e->y + 2 && px < e_right(e) - 2 && py < e_bottom(e) - 2)) continue;+ int cy = (int)floorf(py + d->sy) - g_camy;+ if (cy + 2 < sy0 || cy - 2 >= sy1) continue;+ int cx = (int)floorf(px + d->sx) - g_camx;+ float toff = ((h3 >> 8) & 0xFFFF) * (1.f / 65536.f);+ uint32_t col;+ int a = 256;+ if (d->active) col = DREAM_COLORS[layer][(h3 >> 4) % 3];+ else {+ float m = 0.5f + layer / 2.f * 0.5f; /* Color.LightGray * m */+ col = scale_rgb(0xD3D3D3, m);+ a = (int)(m * 256);+ }+ const int8_t *pt;+ int np;+ if (layer == 0) {+ int f = (int)fmodf(toff * 4 + d->anim, 4); /* particleTextures[3 - f] */+ if (f == 3) pt = PT_DIAMOND, np = 12;+ else if (f == 1) pt = PT_DOT, np = 1;+ else pt = PT_PLUS, np = 5;+ } else if (layer == 1) {+ int f = (int)fmodf(toff * 2 + d->anim, 2);+ if (f == 0) pt = PT_PLUS, np = 5;+ else pt = PT_DOT, np = 1;+ } else+ pt = PT_DOT, np = 1;+ uint16_t c = rgb(col);+ for (int j = 0; j < np; j++) sp_plot(strip, sy0, sy1, cx + pt[2 * j], cy + pt[2 * j + 1], c, a);+ }+ if (d->white_fill > 0) sp_rect(strip, sy0, sy1, vx(X), vy(Y), (int)W, (int)(H * d->white_height), 0xFFFF, (int)(d->white_fill * 256));+ uint32_t lc = line, bc = back;+ if (d->white_fill > 0) lc = lerp_rgb(lc, 0xFFFFFF, d->white_fill), bc = lerp_rgb(bc, 0xFFFFFF, d->white_fill);+ uint16_t l565 = rgb(lc), b565 = rgb(bc);+ dream_wobble_line(strip, sy0, sy1, d, v2(X, Y), v2(X + W, Y), 0, l565, b565);+ dream_wobble_line(strip, sy0, sy1, d, v2(X + W, Y), v2(X + W, Y + H), 0.7f, l565, b565);+ dream_wobble_line(strip, sy0, sy1, d, v2(X + W, Y + H), v2(X, Y + H), 1.5f, l565, b565);+ dream_wobble_line(strip, sy0, sy1, d, v2(X, Y + H), v2(X, Y), 2.5f, l565, b565);+ uint16_t cc = rgb(line);+ sp_rect(strip, sy0, sy1, vx(X), vy(Y), 2, 2, cc, 256);+ sp_rect(strip, sy0, sy1, vx(X + W - 2), vy(Y), 2, 2, cc, 256);+ sp_rect(strip, sy0, sy1, vx(X), vy(Y + H - 2), 2, 2, cc, 256);+ sp_rect(strip, sy0, sy1, vx(X + W - 2), vy(Y + H - 2), 2, 2, cc, 256);+}+/* all the dream blocks of one depth are drawn by one strip layer */+static void dream_layer(uint16_t *strip, int sy0, int sy1, void *ctx) {+ int depth = (int)(intptr_t)ctx;+ for (int i = 0; i < g_nents; i++) {+ Ent *e = &g_ents[i];+ if (e->cls == &DREAMBLOCK && e->dead != 1 && e->visible && e->depth == depth && dream_on_camera(e)) dream_draw(strip, sy0, sy1, e);+ }+}+static uint32_t dream_drawn[2] = {0xFFFFFFFF, 0xFFFFFFFF};+static void dream_render(Ent *e) {+ if (!dream_on_camera(e)) return;+ int k = e->depth == 5000;+ if (dream_drawn[k] == g_frame) return;+ dream_drawn[k] = g_frame;+ gfx_custom(dream_layer, (void *)(intptr_t)e->depth, 0, VIEW_H);+}+static void dream_on_player_exit(Ent *e, Player *p) {+ Dream *d = ST(e, Dream);+ dust_burst(v2(p->ent->x, p->ent->y), atan2f(p->speed.y, p->speed.x), 16);+ if (d->one_use) { /* OneUseDestroy */+ e->collidable = e->visible = 0;+ plat_static_movers_enable(e, false);+ ent_remove(e);+ }+}+static void dream_update(Ent *e) {+ Dream *d = ST(e, Dream);+ if (d->moving) { /* the yoyo tween (a component: before Platform.Update) */+ bool end = tween_update(&d->tw);+ float t = ease_sine_inout(d->tw_reverse ? 1 - d->tw.percent : d->tw.percent);+ V2 to = v2(lerpf(d->start.x, d->end.x, t), lerpf(d->start.y, d->end.y, t));+ if (e->collidable) plat_move_to(e, to.x, to.y);+ else { /* MoveToNaive: no pushing, no riders */+ float ax = to.x - (e->x + e->remx), ay = to.y - (e->y + e->remy);+ e->lift = v2(ax / DT, ay / DT);+ e->remx += ax, e->remy += ay;+ int nx = roundi(e->remx), ny = roundi(e->remy);+ e->remx -= nx, e->remy -= ny;+ e->x += nx, e->y += ny;+ if (nx || ny) plat_static_movers_move(e, v2((float)nx, (float)ny));+ }+ if (end) tween_start(&d->tw, d->tw.duration), d->tw_reverse = !d->tw_reverse;+ }+ plat_update(e);+ if (d->active) {+ d->anim += 6 * DT;+ d->wobble_ease += DT * 2;+ if (d->wobble_ease > 1) {+ d->wobble_ease = 0;+ d->wobble_from = d->wobble_to;+ d->wobble_to = rndf() * 2 * PI_F;+ }+ }+ /* DreamBlock.OnPlayerExit, called by the player when its dream dash ends */+ Player *p = level_player();+ bool in = p && p->state == ST_DREAMDASH && p->dream_block == e;+ if (d->inside && !in && p) dream_on_player_exit(e, p);+ d->inside = in;+}+static void dream_awake(Ent *e) { plat_static_movers_attach(e); }+static void dream_activate_now(Ent *e) { /* ActivateNoRoutine */+ Dream *d = ST(e, Dream);+ if (d->active) return;+ d->active = 1;+ dream_setup(e);+ d->white_height = 0, d->white_fill = 0;+ d->sx = d->sy = 0;+}+static const EntClass DREAMBLOCK = {.name = "dreamBlock", .size = sizeof(Dream), .update = dream_update, .render = dream_render,+ .awake = dream_awake, .kind = KIND_SOLID | KIND_DREAMBLOCK};+static void new_dreamblock(const EData *d) {+ Ent *e = ent_new(&DREAMBLOCK, d->x, d->y);+ if (!e) return;+ ent_box(e, EA(d, dreamBlock, width), EA(d, dreamBlock, height), 0, 0);+ e->safe = 1;+ e->depth = EAB(d, dreamBlock, below) ? 5000 : -11000;+ Dream *s = ST(e, Dream);+ s->wobble_from = rndf() * 2 * PI_F;+ s->wobble_to = rndf() * 2 * PI_F;+ s->one_use = EAB(d, dreamBlock, oneUse);+ s->white_height = 1;+ s->active = g_session.dreamdash;+ if (s->active && d->nnodes) { /* Added: the tween between the two places */+ s->moving = 1;+ s->start = v2(d->x, d->y);+ s->end = ed_node(d, 0);+ float dur = v2len(v2sub(s->end, s->start)) / 12;+ if (EAB(d, dreamBlock, fastMoving)) dur /= 3;+ tween_start(&s->tw, dur);+ }+ dream_setup(e);+}++/* ---------------------------------------------------------------- PlayerHair (Badeline's) */+#define BHAIR 4 /* PlayerSprite.HairCount */+typedef struct { V2 n[BHAIR]; float wave; } Hair;+static void hair_start(Hair *h, V2 pos, int facing) { /* PlayerHair.Start */+ for (int i = 0; i < BHAIR; i++) h->n[i] = v2(pos.x - facing * 200, pos.y + 200);+}+/* PlayerHair.AfterUpdate, with the default steps (0, 2), 0.5, 64, 0 */+static void hair_after_update(Hair *h, const Sprite *s, V2 render_pos, int facing) {+ int hx, hy, fr, carry;+ bool has;+ hair_meta(spr_tex(s), &hx, &hy, &fr, &has, &carry);+ h->n[0] = v2(render_pos.x + hx * facing, render_pos.y - 9 * s->sy + hy);+ V2 target = v2add(h->n[0], v2(-facing * 0.5f * 2, 2)), prev = h->n[0];+ for (int i = 1; i < BHAIR; i++) {+ float m = (1 - (float)i / BHAIR * 0.5f) * 64 * DT;+ V2 d = v2sub(target, h->n[i]);+ float l = v2len(d);+ h->n[i] = l <= m ? target : v2add(h->n[i], v2mul(d, m / l));+ V2 dd = v2sub(h->n[i], prev);+ if (v2len(dd) > 3) h->n[i] = v2add(prev, v2mul(v2norm(dd), 3));+ target = v2add(h->n[i], v2(-facing * 0.5f, 2));+ prev = h->n[i];+ }+}+/* the smaller hair nodes (characters/player/hair00 scaled down) are drawn in a strip layer:+ * as affine draws they would use up gfx.c's few affine slots. hair00: an 8x8 disc in 10x10, origin (5, 5) */+static const uint8_t HAIR_SPAN[10][2] = {{0, 0}, {3, 7}, {2, 8}, {1, 9}, {1, 9}, {1, 9}, {1, 9}, {2, 8}, {3, 7}, {0, 0}};+/* cw: a clip rect (view pixels) when not 0 */+typedef struct { float px[BHAIR], py[BHAIR], s[BHAIR]; uint16_t color; int16_t cx, cy, cw, ch; int a; } HairJob;+enum { OFF_hair_jobs = ((END_rowbuf + 7) & ~7), END_hair_jobs = OFF_hair_jobs + (int)sizeof(HairJob[8]) };+#define hair_jobs (*(HairJob(*)[8])(void *)(g_chram[2] + OFF_hair_jobs))+enum { OFF_lamp_px = ((END_hair_jobs + 7) & ~7), END_lamp_px = OFF_lamp_px + (int)sizeof(uint8_t[8 * 24]) };+#define lamp_px (*(uint8_t(*)[8 * 24])(void *)(g_chram[2] + OFF_lamp_px)) /* objects/hanginglamp as indices */+enum { OFF_debris_px = ((END_lamp_px + 7) & ~7), END_debris_px = OFF_debris_px + (int)sizeof(uint8_t[64 * 8]) };+#define debris_px (*(uint8_t(*)[64 * 8])(void *)(g_chram[2] + OFF_debris_px))+static int nhair_jobs;+static uint32_t hair_jobs_frame = 0xFFFFFFFF;+static void hair_disc(uint16_t *strip, int sy0, int sy1, float PX, float PY, float s, uint16_t c, int a, const HairJob *j) {+ int x0 = (int)floorf(PX - 5 * s) - 1, x1 = (int)ceilf(PX + 5 * s) + 1;+ int y0 = (int)floorf(PY - 5 * s) - 1, y1 = (int)ceilf(PY + 5 * s) + 1;+ if (y0 < sy0) y0 = sy0;+ if (y1 > sy1) y1 = sy1;+ for (int Y = y0; Y < y1; Y++) {+ int v = (int)floorf((Y + 0.5f - PY) / s + 5);+ if (v < 0 || v >= 10) continue;+ for (int X = x0; X < x1; X++) {+ int u = (int)floorf((X + 0.5f - PX) / s + 5);+ if (j->cw && (X < j->cx || X >= j->cx + j->cw || Y < j->cy || Y >= j->cy + j->ch)) continue;+ if (u >= HAIR_SPAN[v][0] && u < HAIR_SPAN[v][1]) sp_plot(strip, sy0, sy1, X, Y, c, a);+ }+ }+}+static void hair_layer(uint16_t *strip, int sy0, int sy1, void *ctx) {+ HairJob *j = ctx;+ for (int i = 1; i < BHAIR; i++)+ for (int k = 0; k < 4; k++)+ hair_disc(strip, sy0, sy1, j->px[i] + (k == 0 ? -1 : k == 1 ? 1 : 0), j->py[i] + (k == 2 ? -1 : k == 3 ? 1 : 0), j->s[i], 0, j->a, j);+ for (int i = BHAIR - 1; i >= 1; i--) hair_disc(strip, sy0, sy1, j->px[i], j->py[i], j->s[i], j->color, j->a, j);+}+static void hair_render_into(Hair *h, const Sprite *s, int facing, uint16_t color, float alpha, HairJob *job) {+ int hx, hy, fr, carry;+ bool has;+ hair_meta(spr_tex(s), &hx, &hy, &fr, &has, &carry);+ if (!has || alpha <= 0) return;+ static const uint16_t BANGS[3] = {T_characters_player_bangs00, T_characters_player_bangs01, T_characters_player_bangs02};+ uint8_t a = (uint8_t)(clampf(alpha, 0, 1) * 255);+ h->n[0] = v2(floorf(h->n[0].x), floorf(h->n[0].y));+ uint16_t bangs = BANGS[fr < 3 ? fr : 0];+ float bsx = facing * fabsf(s->sx);+ V2 at = h->n[0];+ bool bangs_in = !job || !job->cw ||+ (at.x - g_camx >= job->cx && at.x - g_camx < job->cx + job->cw && at.y - g_camy >= job->cy && at.y - g_camy < job->cy + job->ch);+ if (bangs_in) {+ gfx_tex_ex(bangs, at.x - 1, at.y, 5, 5, bsx, 1, 0, 0, a, GF_SILHOUETTE);+ gfx_tex_ex(bangs, at.x + 1, at.y, 5, 5, bsx, 1, 0, 0, a, GF_SILHOUETTE);+ gfx_tex_ex(bangs, at.x, at.y - 1, 5, 5, bsx, 1, 0, 0, a, GF_SILHOUETTE);+ gfx_tex_ex(bangs, at.x, at.y + 1, 5, 5, bsx, 1, 0, 0, a, GF_SILHOUETTE);+ }+ if (!job) {+ if (hair_jobs_frame != g_frame) hair_jobs_frame = g_frame, nhair_jobs = 0;+ if (nhair_jobs < (int)(sizeof hair_jobs / sizeof hair_jobs[0])) job = &hair_jobs[nhair_jobs++], job->cw = 0;+ }+ if (job) {+ HairJob *j = job;+ float y0 = 1e9f, y1 = -1e9f;+ for (int i = 1; i < BHAIR; i++) {+ j->px[i] = floorf(h->n[i].x + 0.5f) - g_camx, j->py[i] = floorf(h->n[i].y + 0.5f) - g_camy;+ j->s[i] = (0.25f + (1 - (float)i / BHAIR) * 0.75f) * fmaxf(fabsf(s->sx), 0.01f);+ y0 = fminf(y0, j->py[i] - 7), y1 = fmaxf(y1, j->py[i] + 7);+ }+ j->color = color, j->a = a + (a >> 7);+ gfx_custom(hair_layer, j, (int)y0, (int)y1);+ }+ if (bangs_in) gfx_tex_ex(bangs, at.x, at.y, 5, 5, bsx, 1, 0, color, a, GF_SILHOUETTE);+}+static void hair_render(Hair *h, const Sprite *s, int facing, uint16_t color, float alpha) { hair_render_into(h, s, facing, color, alpha, NULL); }+/* the player's animations that Badeline's sprite also has */+static const uint8_t BADELINE_ANIMS[][2] = {+ {A_player_idle, A_badeline_idle}, {A_player_idleA, A_badeline_idleA}, {A_player_idleB, A_badeline_idleB},+ {A_player_idleC, A_badeline_idleC}, {A_player_lookUp, A_badeline_lookUp}, {A_player_walk, A_badeline_walk},+ {A_player_push, A_badeline_push}, {A_player_runSlow, A_badeline_runSlow}, {A_player_runFast, A_badeline_runFast},+ {A_player_runStumble, A_badeline_runStumble}, {A_player_dash, A_badeline_dash},+ {A_player_dreamDashIn, A_badeline_dreamDashIn}, {A_player_dreamDashLoop, A_badeline_dreamDashLoop},+ {A_player_dreamDashOut, A_badeline_dreamDashOut}, {A_player_slide, A_badeline_slide},+ {A_player_jumpSlow, A_badeline_jumpSlow}, {A_player_jumpFast, A_badeline_jumpFast},+ {A_player_fallSlow, A_badeline_fallSlow}, {A_player_fallFast, A_badeline_fallFast}, {A_player_tired, A_badeline_tired},+ {A_player_wallslide, A_badeline_wallslide}, {A_player_climbLookBackStart, A_badeline_climbLookBackStart},+ {A_player_climbLookBack, A_badeline_climbLookBack}, {A_player_climbup, A_badeline_climbup},+ {A_player_duck, A_badeline_duck}, {A_player_edge, A_badeline_edge}, {A_player_sleep, A_badeline_sleep},+ {A_player_faint, A_badeline_faint}, {A_player_fainted, A_badeline_fainted}, {A_player_flip, A_badeline_flip},+ {A_player_skid, A_badeline_skid}, {A_player_dangling, A_badeline_dangling}, {A_player_spin, A_badeline_spin},+ {A_player_hug, A_badeline_hug}};+static int badeline_anim(int player_anim) {+ for (unsigned i = 0; i < sizeof BADELINE_ANIMS / 2; i++)+ if (BADELINE_ANIMS[i][0] == player_anim) return BADELINE_ANIMS[i][1];+ return -1;+}++/* ---------------------------------------------------------------- Player.ChaserStates */+/* the player's last 3.2 s: position, animation, facing, depth, one record per Player.Update */+#define CHASE_N 192+enum { OFF_chase_x = ((END_debris_px + 7) & ~7), END_chase_x = OFF_chase_x + (int)sizeof(int16_t[CHASE_N]) };+#define chase_x (*(int16_t(*)[CHASE_N])(void *)(g_chram[2] + OFF_chase_x))+enum { OFF_chase_y = ((END_chase_x + 7) & ~7), END_chase_y = OFF_chase_y + (int)sizeof(int16_t[CHASE_N]) };+#define chase_y (*(int16_t(*)[CHASE_N])(void *)(g_chram[2] + OFF_chase_y))+enum { OFF_chase_t = ((END_chase_y + 7) & ~7), END_chase_t = OFF_chase_t + (int)sizeof(uint8_t[CHASE_N]) };+#define chase_t (*(uint8_t(*)[CHASE_N])(void *)(g_chram[2] + OFF_chase_t))+enum { OFF_chase_anim = ((END_chase_t + 7) & ~7), END_chase_anim = OFF_chase_anim + (int)sizeof(uint8_t[CHASE_N]) };+#define chase_anim (*(uint8_t(*)[CHASE_N])(void *)(g_chram[2] + OFF_chase_anim))+enum { OFF_chase_flags = ((END_chase_anim + 7) & ~7), END_chase_flags = OFF_chase_flags + (int)sizeof(uint8_t[CHASE_N]) };+#define chase_flags (*(uint8_t(*)[CHASE_N])(void *)(g_chram[2] + OFF_chase_flags))+static int chase_head, chase_n;+static float chase_last = -1;+typedef struct { V2 pos; int anim, facing, depth; } ChaseState;+static uint32_t chase_tick(void) { return (uint32_t)(g_level.time_active / DT + 0.5f); }+static void chase_record(void) {+ Player *p = level_player();+ if (!p || g_level.time_active == chase_last) return;+ chase_last = g_level.time_active;+ int i = (chase_head + chase_n) % CHASE_N;+ if (chase_n < CHASE_N) chase_n++;+ else chase_head = (chase_head + 1) % CHASE_N;+ chase_x[i] = (int16_t)p->ent->x, chase_y[i] = (int16_t)p->ent->y;+ chase_t[i] = (uint8_t)(chase_tick() - 1); /* (recorded before Player.Update: the last frame's) */+ chase_anim[i] = p->spr.anim;+ chase_flags[i] = (uint8_t)((p->facing < 0 ? 1 : 0) | (p->ent->depth == D_PLAYERDREAMDASHING ? 2 : 0));+}+/* Player.GetChasePosition */+static bool chase_get(float time_ago, ChaseState *out) {+ Player *p = level_player();+ if (!p || p->dead) return false;+ uint8_t now = (uint8_t)chase_tick();+ bool older = chase_n == CHASE_N;+ for (int k = 0; k < chase_n; k++) {+ int i = (chase_head + k) % CHASE_N;+ float num = (uint8_t)(now - chase_t[i]) * DT;+ if (num <= time_ago) {+ if (older || time_ago - num < 0.02f) {+ out->pos = v2(chase_x[i], chase_y[i]);+ out->anim = chase_anim[i];+ out->facing = chase_flags[i] & 1 ? -1 : 1;+ out->depth = chase_flags[i] & 2 ? D_PLAYERDREAMDASHING : D_PLAYER;+ return true;+ }+ return false;+ }+ older = true;+ }+ return false;+}+static void recorder_update(Ent *e) { (void)e; chase_record(); }+static const EntClass CHASE_RECORDER = {.name = "chaseRecorder", .size = 0, .update = recorder_update};++/* ---------------------------------------------------------------- BadelineOldsite */+typedef struct {+ Sprite spr;+ Hair hair;+ V2 from, to, end;+ float hover_timer, spr_x, spr_y, scale, color_a, hair_alpha;+ float wait, delay;+ Tween tw, pop;+ uint8_t index, step, following, hovering, ignore_anim, hair_visible, intro;+ int8_t facing;+} Chaser;+enum { CH_WAIT_PLAYER, CH_DELAY, CH_TWEEN, CH_FOLLOW, CH_STOP_WAIT, CH_INTRO };+#define FOLLOW_BEHIND 1.55f+static uint16_t chaser_hair_color(int index) { return rgb(lerp_rgb(0x9B3FB5, 0xFFFFFF, index / 6.f)); }+static void chaser_trail(Ent *e) {+ Chaser *c = ST(e, Chaser);+ if (!level_on_interval(0.1f)) return;+ uint16_t t = spr_tex(&c->spr);+ if (t != 0xFFFF)+ trail_add(e->x + c->spr_x, e->y + c->spr_y, t, c->spr.ox, c->spr.oy, c->scale * c->facing, c->scale, 0xAC3232, 1);+}+static void chaser_on_player(Ent *e, Player *p) {+ V2 d = v2sub(v2(p->ent->x, p->ent->y), v2(e->x, e->y));+ player_die(p, v2norm(d), false);+}+static void chaser_start_chasing(Ent *e) { /* StartChasingRoutine */+ Chaser *c = ST(e, Chaser);+ c->hovering = 1;+ c->step = CH_WAIT_PLAYER;+}+static void bintro_start(Ent *bad, V2 end);+static void chaser_update(Ent *e) {+ Chaser *c = ST(e, Chaser);+ Player *p = level_player();+ ChaseState cs;+ if (p && p->dead && c->step != CH_INTRO) {+ spr_play(&c->spr, A_badeline_laugh, false);+ c->spr_x = sinf(c->hover_timer) * 4;+ c->hovering = 1;+ c->hover_timer += DT * 2;+ if (e->depth != -12500) e->depth = -12500, ents_mark_unsorted();+ chaser_trail(e);+ } else if (c->following && chase_get(FOLLOW_BEHIND + c->delay, &cs)) {+ V2 d = v2sub(cs.pos, v2(e->x, e->y));+ float l = v2len(d), m = 500 * DT;+ if (l <= m) e->x = cs.pos.x, e->y = cs.pos.y;+ else e->x += d.x * m / l, e->y += d.y * m / l;+ if (!c->ignore_anim && cs.anim != 255) {+ int a = badeline_anim(cs.anim);+ if (a >= 0 && a != c->spr.anim) spr_play(&c->spr, a, true);+ }+ if (!c->ignore_anim) c->facing = (int8_t)cs.facing;+ if (e->depth != cs.depth) e->depth = cs.depth, ents_mark_unsorted();+ chaser_trail(e);+ }+ if (c->hovering) {+ c->hover_timer += DT;+ c->spr_y = sinf(c->hover_timer * 2) * 4;+ } else+ c->spr_y = approach(c->spr_y, 0, DT * 4);+ /* base.Update(): the components */+ c->hair.wave += DT * 4;+ spr_update(&c->spr);+ if (c->pop.active) { /* PopIntoExistence */+ tween_update(&c->pop);+ float t = ease_cube_in(c->pop.percent);+ c->scale = t, c->color_a = t, c->hair_alpha = t;+ }+ if (c->step == CH_INTRO) { /* CS02_BadelineIntro moves it */+ } else if (c->wait > 0)+ c->wait -= DT;+ else switch (c->step) {+ case CH_WAIT_PLAYER:+ if (!p || p->just_respawned) break;+ c->to = v2(p->ent->x, p->ent->y);+ c->wait = c->delay;+ c->step = CH_DELAY;+ break;+ case CH_DELAY:+ if (!e->visible) {+ e->visible = 1;+ c->scale = 0, c->color_a = 0;+ c->hair_visible = 1, c->hair_alpha = 0;+ tween_start(&c->pop, 0.5f);+ }+ spr_play(&c->spr, A_badeline_fallSlow, false);+ c->hair_visible = 1;+ c->hovering = 0;+ c->from = v2(e->x, e->y);+ tween_start(&c->tw, FOLLOW_BEHIND - 0.1f);+ c->step = CH_TWEEN;+ break;+ case CH_TWEEN: {+ bool end = tween_update(&c->tw);+ float t = ease_cube_in(c->tw.percent);+ e->x = lerpf(c->from.x, c->to.x, t), e->y = lerpf(c->from.y, c->to.y, t);+ if (c->to.x != c->from.x) c->facing = c->to.x > c->from.x ? 1 : -1;+ chaser_trail(e);+ if (!end) break;+ e->collidable = 1;+ c->following = 1;+ c->step = CH_FOLLOW;+ break;+ }+ case CH_FOLLOW:+ if (!strcmp(room_of(e), "2")) { /* StopChasing */+ Room *rm = &g_level.rooms[e->room];+ float r = (float)(rm->x + 148), b = (float)(rm->y + 168 + 184);+ if (e->x > r) e->x = r;+ if (e->y > b) e->y = b;+ if (e->x == r && e->y == b) {+ c->following = 0;+ c->ignore_anim = 1;+ spr_play(&c->spr, A_badeline_laugh, false);+ c->facing = 1;+ c->wait = 1;+ c->step = CH_STOP_WAIT;+ }+ }+ break;+ case CH_STOP_WAIT:+ particles_emit(PL_MID, &P_BadelineOldsite_P_Vanish, 12, e_center(e), v2(6, 6), 0);+ ent_remove(e);+ break;+ }+ hair_after_update(&c->hair, &c->spr, v2(e->x + c->spr_x, e->y + c->spr_y), c->facing);+}+static void chaser_render(Ent *e) {+ Chaser *c = ST(e, Chaser);+ float x = floorf(e->x + c->spr_x), y = floorf(e->y + c->spr_y);+ if (c->hair_visible) {+ Sprite s = c->spr;+ s.sx = c->scale;+ hair_render(&c->hair, &s, c->facing, chaser_hair_color(c->index), c->hair_alpha);+ }+ Sprite s = c->spr;+ s.sx = c->scale * c->facing, s.sy = c->scale;+ s.alpha = (uint8_t)(clampf(c->color_a, 0, 1) * 255);+ spr_draw(&s, x, y);+}+static const EntClass CHASER = {.name = "darkChaser", .size = sizeof(Chaser), .update = chaser_update, .render = chaser_render,+ .on_player = chaser_on_player, .kind = KIND_PCOLLIDE};+static int chasers_loaded[2]; /* Level.LoadLevel numbers each room's chasers */+static int chasers_room[2] = {-1, -1};+static void new_chaser(const EData *d) {+ int slot = g_level.room_slot;+ bool normal = g_session.mode == 0;+ const char *room = loading_room();+ if (chasers_room[slot] != d->room || !level_player_ent()) chasers_loaded[slot] = 0, chasers_room[slot] = d->room;+ int index = chasers_loaded[slot]++;+ if (index == 0) { /* the player's ChaserStates: kept while it lives */+ if (!level_player_ent()) chase_n = 0, chase_head = 0;+ Ent *r = ent_new(&CHASE_RECORDER, 0, 0);+ if (r) r->depth = -1, r->collidable = 0, r->visible = 0;+ }+ /* Added */+ if (normal && (room_visited("11") || !room_visited("3"))) return;+ Ent *e = ent_new(&CHASER, d->x, d->y);+ if (!e) return;+ e->depth = -1;+ ent_box(e, 6, 6, -3, -7);+ e->collidable = 0;+ e->visible = 0;+ Chaser *c = ST(e, Chaser);+ c->index = (uint8_t)index;+ spr_init(&c->spr, SB_badeline);+ spr_play(&c->spr, A_badeline_fallSlow, true);+ c->facing = 1;+ c->scale = 1, c->color_a = 1, c->hair_alpha = 1;+ c->delay = 0.4f * index;+ hair_start(&c->hair, v2(d->x, d->y), 1);+ if (normal && !level_get_flag("evil_maddy_intro") && !strcmp(room, "3")) {+ c->hovering = 0;+ e->visible = 1;+ c->hair_visible = 0;+ spr_play(&c->spr, A_badeline_pretendDead, false);+ c->step = CH_INTRO;+ bintro_start(e, v2(d->x + 8, d->y - 24)); /* Scene.Add(new CS02_BadelineIntro(this)) */+ } else+ chaser_start_chasing(e);+}++/* ---------------------------------------------------------------- TouchSwitch (and its Switch) */+#define TS_INACTIVE 0x5fcde4+#define TS_ACTIVE 0xFFFFFF+#define TS_FINISH 0xf141df+typedef struct {+ float ease, timer, rate, anim_t, k;+ Wiggler wig;+ uint32_t color; /* icon.Color before its alpha */+ uint8_t activated, finished, frame, spin;+} Touch;+static uint16_t ts_icon[6], ts_container;+static const EntClass TOUCHSWITCH;+static void switch_flag_name(char *buf, const char *room) { path2(buf, "switches_", room, -1); }+static void touch_finish(Ent *e) { /* Switch.Finish -> OnFinish */+ Touch *t = ST(e, Touch);+ t->finished = 1;+ t->ease = 0;+}+/* Switch.FinishedCheck */+static bool switches_finished_check(void) {+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &TOUCHSWITCH && g_ents[i].dead != 1 && !ST(&g_ents[i], Touch)->activated) return false;+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &TOUCHSWITCH && g_ents[i].dead != 1) touch_finish(&g_ents[i]);+ return true;+}+/* Switch.Check: the first switch is finished */+static bool switch_check(void) {+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &TOUCHSWITCH && g_ents[i].dead != 1) return ST(&g_ents[i], Touch)->finished;+ return false;+}+static void touch_turn_on(Ent *e) {+ Touch *t = ST(e, Touch);+ if (t->activated || t->finished) return;+ t->activated = 1; /* Switch.Activate -> OnActivate */+ wiggler_start(&t->wig, 0.5f, 4);+ for (int i = 0; i < 32; i++) {+ float a = rndf() * 2 * PI_F;+ particles_emit1(PL_MID, &P_TouchSwitch_P_FireWhite, v2add(v2(e->x, e->y), angle_vec(a, 6)), a);+ }+ t->rate = 4;+ switches_finished_check();+}+static void touch_on_player(Ent *e, Player *p) { (void)p, touch_turn_on(e); }+static void touch_awake(Ent *e) { /* Switch.EntityAdded: CheckLevelFlag -> StartFinished */+ Touch *t = ST(e, Touch);+ char f[48];+ switch_flag_name(f, room_of(e));+ if (level_get_flag(f) && !t->finished) {+ t->activated = t->finished = 1;+ t->rate = 0.1f;+ t->spin = 0, t->frame = 0;+ t->color = TS_FINISH;+ t->ease = 1;+ }+}+static void touch_update(Ent *e) {+ Touch *t = ST(e, Touch);+ /* HoldableCollider (20x20) and SeekerCollider (24x24, inside the camera) */+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (!o->cls || o->dead == 1 || o == e) continue;+ bool hold = o->kind & KIND_HOLDABLE, seeker = !hold && o->cls->name && !strcmp(o->cls->name, "seeker");+ if (!hold && !seeker) continue;+ float r = hold ? 10 : 12;+ if (collide_rect(o, e->x - r, e->y - r, e->x + r, e->y + r)) {+ if (hold) touch_turn_on(e);+ else if (e->x > g_level.cam.x - 10 && e->x < g_level.cam.x + 330 && e->y > g_level.cam.y - 10 && e->y < g_level.cam.y + 190)+ touch_turn_on(e);+ }+ }+ t->timer += DT * 8;+ t->ease = approach(t->ease, (t->finished || t->activated) ? 1 : 0, DT * 2);+ t->color = lerp_rgb(TS_INACTIVE, t->finished ? TS_FINISH : TS_ACTIVE, t->ease);+ t->k = 0.5f + (sinf(t->timer) + 1) / 2 * (1 - t->ease) * 0.5f + 0.5f * t->ease;+ if (t->finished) {+ if (t->rate > 0.1f) {+ t->rate -= 2 * DT;+ if (t->rate <= 0.1f) {+ t->rate = 0.1f;+ wiggler_start(&t->wig, 0.5f, 4);+ t->spin = 0, t->frame = 0, t->anim_t = 0;+ }+ } else if (level_on_interval(0.03f)) {+ V2 at = v2add(v2add(v2(e->x, e->y), v2(0, 1)), angle_vec(rndf() * 2 * PI_F, 5));+ particles_emit1(PL_BG, &P_TouchSwitch_P_Fire, at, P_TouchSwitch_P_Fire.direction);+ }+ }+ /* base.Update(): the icon ("spin": 0-5 at 0.1 s, looping) and the wiggler */+ if (t->spin) {+ t->anim_t += DT * t->rate;+ if (fabsf(t->anim_t) >= 0.1f) t->frame = (uint8_t)((t->frame + 1) % 6), t->anim_t -= 0.1f;+ }+ wiggler_update(&t->wig);+}+static void touch_render(Ent *e) {+ Touch *t = ST(e, Touch);+ uint16_t c = rgb(t->color);+ uint8_t a = (uint8_t)(clampf(t->k, 0, 1) * 255);+ float pulse = 1 + t->wig.value * 0.25f;+ gfx_tex_ex(ts_container, e->x, e->y - 1, 10, 10, 1, 1, 0, 0, 255, GF_SILHOUETTE);+ gfx_tex_ex(ts_container, e->x, e->y, 10, 10, pulse, pulse, 0, c, a, 0);+ gfx_tex_ex(ts_icon[t->frame], e->x, e->y, 10, 10, 1, 1, 0, c, a, 0);+ light_add(e->x, e->y, 0xFFFFFF, 0.8f, 16, 32);+ bloom_add(e->x, e->y, t->ease, 16);+}+static const EntClass TOUCHSWITCH = {.name = "touchSwitch", .size = sizeof(Touch), .update = touch_update, .render = touch_render,+ .awake = touch_awake, .on_player = touch_on_player, .kind = KIND_PCOLLIDE};+static void new_touchswitch(const EData *d) {+ Ent *e = ent_new(&TOUCHSWITCH, d->x, d->y);+ if (!e) return;+ e->depth = 2000;+ ent_box(e, 30, 30, -15, -15); /* the PlayerCollider's hitbox */+ Touch *t = ST(e, Touch);+ t->spin = 1, t->rate = 1;+ t->color = TS_INACTIVE;+ char p[40];+ for (int i = 0; i < 6; i++) ts_icon[i] = tex(path2(p, "objects/touchswitch/icon", NULL, i));+ ts_container = tex("objects/touchswitch/container");+}++/* ---------------------------------------------------------------- SwitchGate */+typedef struct {+ V2 start, node;+ float rate, anim_t, wait, tw_left;+ Wiggler wig;+ uint32_t color;+ uint16_t slice;+ uint8_t persistent, step, frame, particle_at, tw_on;+} Gate;+static uint16_t gate_icon[6];+static void gate_dust(Ent *e, bool cond, V2 a, V2 step, V2 inward, V2 spread, int n, float dir) {+ if (!cond) return;+ for (int i = 0; i < n; i++) {+ V2 p = v2add(a, v2mul(step, (float)i));+ if (point_solid(p.x, p.y) && !point_solid(p.x + inward.x, p.y + inward.y)) {+ particles_emit1(PL_FG, &P_SwitchGate_P_Dust, v2add(p, spread), dir);+ particles_emit1(PL_FG, &P_SwitchGate_P_Dust, v2sub(p, spread), dir);+ }+ }+ (void)e;+}+static void gate_update(Ent *e) {+ Gate *g = ST(e, Gate);+ /* components: the tween, then the Sequence coroutine, then the icon and wiggler */+ if (g->tw_on) {+ g->tw_left -= DT;+ float t = ease_cube_out(1 - fmaxf(0, g->tw_left) / 2);+ plat_move_to(e, lerpf(g->start.x, g->node.x, t), lerpf(g->start.y, g->node.y, t));+ if (level_on_interval(0.1f)) {+ g->particle_at = (uint8_t)((g->particle_at + 1) % 2);+ for (int i = 0; (float)i < e->cw / 8; i++)+ for (int j = 0; (float)j < e->ch / 8; j++)+ if ((i + j) % 2 == g->particle_at)+ particles_emit1(PL_BG, &P_SwitchGate_P_Behind, v2(e->x + i * 8 + rnd_rangef(2, 6), e->y + j * 8 + rnd_rangef(2, 6)),+ P_SwitchGate_P_Behind.direction);+ }+ if (g->tw_left <= 0) g->tw_on = 0;+ }+ if (g->wait > 0) g->wait -= DT;+ else switch (g->step) {+ case 0: /* while (!Switch.Check) */+ if (!switch_check()) break;+ if (g->persistent) {+ char f[48];+ switch_flag_name(f, room_of(e));+ level_set_flag(f, true);+ }+ g->wait = 0.1f, g->step = 1;+ break;+ case 1:+ plat_start_shaking(e, 0.5f);+ g->step = 2;+ /* fall through */+ case 2:+ if (g->rate < 1) {+ g->color = lerp_rgb(TS_INACTIVE, TS_ACTIVE, g->rate);+ g->rate += DT * 2;+ break;+ }+ g->wait = 0.1f, g->step = 3;+ break;+ case 3:+ g->tw_on = 1, g->tw_left = 2; /* Tween.Create(Oneshot, CubeOut, 2) */+ g->particle_at = 0;+ g->wait = 1.8f, g->step = 4;+ break;+ case 4: {+ uint8_t was = e->collidable;+ e->collidable = 0;+ float l = e_left(e), r = e_right(e), t = e_top(e), b = e_bottom(e);+ int nh = (int)(e->ch / 8), nw = (int)(e->cw / 8);+ gate_dust(e, g->node.x <= g->start.x, v2(l - 1, t + 4), v2(0, 8), v2(1, 0), v2(0, 2), nh, PI_F);+ gate_dust(e, g->node.x >= g->start.x, v2(r + 1, t + 4), v2(0, 8), v2(-2, 0), v2(0, 2), nh, 0);+ gate_dust(e, g->node.y <= g->start.y, v2(l + 4, t - 1), v2(8, 0), v2(0, 1), v2(2, 0), nw, -PI_F / 2);+ gate_dust(e, g->node.y >= g->start.y, v2(l + 4, b + 1), v2(8, 0), v2(0, -2), v2(2, 0), nw, PI_F / 2);+ e->collidable = was;+ plat_start_shaking(e, 0.2f);+ g->step = 5;+ }+ /* fall through */+ case 5:+ if (g->rate > 0) {+ g->color = lerp_rgb(TS_ACTIVE, TS_FINISH, 1 - g->rate);+ g->rate -= DT * 4;+ break;+ }+ g->rate = 0;+ g->frame = 0, g->anim_t = 0;+ wiggler_start(&g->wig, 0.5f, 4);+ {+ uint8_t was = e->collidable;+ e->collidable = 0;+ V2 c = e_center(e);+ if (!point_solid(c.x, c.y))+ for (int i = 0; i < 32; i++) {+ float a = rndf() * 2 * PI_F;+ particles_emit1(PL_FG, &P_TouchSwitch_P_Fire, v2add(v2(e->x + e->cw / 2, e->y + e->ch / 2), angle_vec(a, 4)), a);+ }+ e->collidable = was;+ }+ g->step = 6;+ break;+ default: break;+ }+ if (g->rate != 0) { /* the icon spins at its Rate */+ g->anim_t += DT * g->rate;+ if (fabsf(g->anim_t) >= 0.1f) {+ int s = g->anim_t > 0 ? 1 : -1;+ g->frame = (uint8_t)((g->frame + s + 6) % 6);+ g->anim_t -= s * 0.1f;+ }+ }+ wiggler_update(&g->wig);+ plat_update(e);+}+static void gate_render(Ent *e) {+ Gate *g = ST(e, Gate);+ V2 sh = e_shake(e);+ int nx = (int)(e->cw / 8) - 1, ny = (int)(e->ch / 8) - 1;+ for (int i = 0; i <= nx; i++)+ for (int j = 0; j <= ny; j++) {+ int a = i < nx ? (i < 1 ? i : 1) : 2, b = j < ny ? (j < 1 ? j : 1) : 2;+ gfx_tex_part(g->slice, e->x + sh.x + i * 8, e->y + sh.y + j * 8, a * 8, b * 8, 8, 8, 0, 0xFFFF, 255);+ }+ float s = 1 + g->wig.value, cx = e->x + e->cw / 2 + sh.x, cy = e->y + e->ch / 2 + sh.y;+ uint16_t ic = gate_icon[g->frame];+ for (int i = -1; i < 2; i++)+ for (int j = -1; j < 2; j++)+ if (i || j) gfx_tex_ex(ic, cx + i, cy + j, 6, 6, s, s, 0, 0, 255, GF_SILHOUETTE);+ gfx_tex_ex(ic, cx, cy, 6, 6, s, s, 0, rgb(g->color), 255, 0);+}+static void gate_awake(Ent *e) {+ Gate *g = ST(e, Gate);+ plat_static_movers_attach(e);+ char f[48];+ switch_flag_name(f, room_of(e));+ if (level_get_flag(f)) {+ plat_move_to(e, g->node.x, g->node.y);+ g->rate = 0, g->frame = 0;+ g->color = TS_FINISH;+ g->step = 6;+ }+}+static const EntClass SWITCHGATE = {.name = "switchGate", .size = sizeof(Gate), .update = gate_update, .render = gate_render,+ .awake = gate_awake, .kind = KIND_SOLID};+static void new_switchgate(const EData *d) {+ Ent *e = ent_new(&SWITCHGATE, d->x, d->y);+ if (!e) return;+ ent_box(e, EA(d, switchGate, width), EA(d, switchGate, height), 0, 0);+ Gate *g = ST(e, Gate);+ g->start = v2(d->x, d->y);+ g->node = ed_node(d, 0);+ g->persistent = EAB(d, switchGate, persistent);+ g->color = TS_INACTIVE;+ const char *sp = EAS(d, switchGate, sprite);+ char p[48];+ g->slice = tex(path2(p, "objects/switchgate/", *sp ? sp : "block", -1));+ for (int i = 0; i < 6; i++) gate_icon[i] = tex(path2(p, "objects/switchgate/icon", NULL, i));+}++/* ---------------------------------------------------------------- HangingLamp */+/* drawn in a strip layer (rotated, with its outline): as images it would take ~10 draws per 8 px */+typedef struct { float speed, rot, sound_delay; int16_t length; } Lamp;+static uint16_t lamp_tex;+static const uint16_t *lamp_col;+static const uint8_t *lamp_alpha;+static uint32_t lamp_px_frame = 0xFFFFFFFF;+static bool lamp_decode(void) {+ if (lamp_px_frame != g_frame) lamp_px_frame = g_frame, lamp_col = NULL, tex_frame_idx(lamp_tex, lamp_px, 8, 24, &lamp_col, &lamp_alpha);+ return lamp_col != NULL;+}+/* the lamp's pixel at (lx, ly) in its unrotated frame: x in [-4, 4), y in [0, length) */+static uint8_t lamp_texel(int lx, int ly, int len) {+ int u = lx + 4;+ if (u < 0 || u >= 8 || ly < 0 || ly >= len) return 0;+ if (ly >= len - 8) return lamp_px[(16 + ly - (len - 8)) * 8 + u]; /* the lamp (0, 16) */+ uint8_t v = ly < 8 ? lamp_px[ly * 8 + u] : 0; /* the top (0, 0) over the chain */+ return v ? v : lamp_px[(8 + ly % 8) * 8 + u]; /* the chain (0, 8), every 8 px */+}+static const EntClass LAMP;+static void lamp_layer(uint16_t *strip, int sy0, int sy1, void *ctx) {+ Ent *e = ctx;+ Lamp *l = ST(e, Lamp);+ int len = l->length;+ float c = cosf(l->rot), s = sinf(l->rot);+ float ox = floorf(e->x) - g_camx, oy = floorf(e->y) - g_camy;+ float ext = fabsf(s) * len + 6;+ int x0 = (int)(ox - ext), x1 = (int)(ox + ext) + 1, y0 = (int)oy - 2, y1 = (int)(oy + len) + 2;+ if (y0 < sy0) y0 = sy0;+ if (y1 > sy1) y1 = sy1;+ for (int Y = y0; Y < y1; Y++)+ for (int X = x0; X < x1; X++) {+ if ((unsigned)X >= VIEW_W) continue;+ /* the pixel's texel and the 8 around it (DrawOutline: black, offset 1) */+ uint8_t here = 0;+ bool outline = false;+ for (int j = -1; j <= 1; j++)+ for (int i = -1; i <= 1; i++) {+ float dx = X + 0.5f - i - ox, dy = Y + 0.5f - j - oy;+ float lx = dx * c + dy * s, ly = -dx * s + dy * c;+ uint8_t v = lamp_texel((int)floorf(lx), (int)floorf(ly), len);+ if (!i && !j) here = v;+ else if (v) outline = true;+ }+ uint16_t *d = strip + (Y - sy0) * VIEW_W + X;+ if (here) sp_texel(d, lamp_col, lamp_alpha, here, 0xFFFF, 256, false);+ else if (outline) *d = 0;+ }+}+static void lamp_update(Ent *e) {+ Lamp *l = ST(e, Lamp);+ l->sound_delay -= DT;+ Player *p = level_player();+ if (p && collide_ent_at(e, e->x, e->y, p->ent)) {+ l->speed = -p->speed.x * 0.005f * ((p->ent->y - e->y) / l->length);+ if (fabsf(l->speed) < 0.1f) l->speed = 0;+ else if (l->sound_delay <= 0) l->sound_delay = 0.25f;+ }+ float num = signf(l->rot) == signf(l->speed) ? 8 : 6;+ if (fabsf(l->rot) < 0.5f) num *= 0.5f;+ if (fabsf(l->rot) < 0.25f) num *= 0.5f;+ float was = l->rot;+ l->speed += -signf(l->rot) * num * DT;+ l->rot += l->speed * DT;+ l->rot = clampf(l->rot, -0.4f, 0.4f);+ if (fabsf(l->rot) < 0.02f && fabsf(l->speed) < 0.2f) l->rot = l->speed = 0;+ else if (signf(l->rot) != signf(was) && l->sound_delay <= 0 && fabsf(l->speed) > 0.5f) l->sound_delay = 0.25f;+}+static void lamp_render(Ent *e) {+ Lamp *l = ST(e, Lamp);+ if (lamp_decode()) {+ float oy = floorf(e->y) - g_camy;+ gfx_custom(lamp_layer, e, (int)oy - 2, (int)(oy + l->length) + 2);+ }+ V2 at = v2add(v2(e->x, e->y), angle_vec(l->rot + PI_F / 2, l->length - 4.f));+ bloom_add(at.x, at.y, 1, 48);+ light_add(at.x, at.y, 0xFFFFFF, 1, 24, 48);+}+static const EntClass LAMP = {.name = "hanginglamp", .size = sizeof(Lamp), .update = lamp_update, .render = lamp_render};+static void new_lamp(const EData *d) {+ Ent *e = ent_new(&LAMP, d->x + 4, d->y);+ if (!e) return;+ int len = (int)EA(d, hanginglamp, height);+ if (len < 16) len = 16;+ e->depth = 2000;+ ent_box(e, 8, (float)len, -4, 0);+ ST(e, Lamp)->length = (int16_t)len;+ lamp_tex = tex("objects/hanginglamp");+}++/* ---------------------------------------------------------------- FloatingDebris */+typedef struct { V2 start, push; float rot, rot_speed, accel; SineWave sine; uint8_t piece; } Debris2;+static uint16_t debris_tex;+static void fdebris_on_player(Ent *e, Player *p) {+ Debris2 *d = ST(e, Debris2);+ V2 v = v2sub(v2(e->x, e->y), player_center(p));+ float l = v2len(v);+ v = l > 0 ? v2mul(v, v2len(p->speed) * 0.2f / l) : v2(0, 0); /* SafeNormalize(length) */+ if (v.x * v.x + v.y * v.y > d->push.x * d->push.x + d->push.y * d->push.y) d->push = v;+ d->accel = 1;+}+static void fdebris_update(Ent *e) {+ Debris2 *d = ST(e, Debris2);+ sine_update(&d->sine); /* base.Update() */+ if (d->push.x != 0 || d->push.y != 0) {+ e->x += d->push.x * DT, e->y += d->push.y * DT;+ float m = 64 * d->accel * DT, l = v2len(d->push);+ d->push = l <= m ? v2(0, 0) : v2sub(d->push, v2mul(d->push, m / l));+ } else {+ d->accel = 1;+ V2 to = v2sub(d->start, v2(e->x, e->y));+ float l = v2len(to), m = 6 * DT;+ if (l <= m) e->x = d->start.x, e->y = d->start.y;+ else e->x += to.x * m / l, e->y += to.y * m / l;+ }+ d->rot += d->rot_speed * DT;+}+/* all the pieces (8x8 parts of scenery/debris, rotating about their centers) in one strip layer */+static const EntClass FDEBRIS;+static const uint16_t *debris_col;+static const uint8_t *debris_alpha;+static uint32_t debris_frame = 0xFFFFFFFF;+static void fdebris_layer(uint16_t *strip, int sy0, int sy1, void *ctx) {+ (void)ctx;+ for (int k = 0; k < g_nents; k++) {+ Ent *e = &g_ents[k];+ if (e->cls != &FDEBRIS || e->dead == 1 || !e->visible) continue;+ Debris2 *d = ST(e, Debris2);+ float px = floorf(e->x + 0.5f) - g_camx, py = floorf(e->y + d->sine.value * 2 + 0.5f) - g_camy;+ if (py + 7 < sy0 || py - 7 >= sy1 || px < -8 || px > VIEW_W + 8) continue;+ float c = cosf(d->rot), s = sinf(d->rot);+ for (int Y = (int)py - 6; Y < (int)py + 7; Y++) {+ if (Y < sy0 || Y >= sy1) continue;+ for (int X = (int)px - 6; X < (int)px + 7; X++) {+ if ((unsigned)X >= VIEW_W) continue;+ float dx = X + 0.5f - px, dy = Y + 0.5f - py;+ int u = (int)floorf(dx * c + dy * s + 4), v = (int)floorf(-dx * s + dy * c + 4);+ if ((unsigned)u >= 8 || (unsigned)v >= 8) continue;+ uint8_t idx = debris_px[v * 64 + d->piece * 8 + u];+ if (idx) sp_texel(strip + (Y - sy0) * VIEW_W + X, debris_col, debris_alpha, idx, 0xFFFF, 256, false);+ }+ }+ }+}+static void fdebris_render(Ent *e) {+ (void)e;+ if (debris_frame == g_frame) return;+ debris_frame = g_frame;+ if (tex_frame_idx(debris_tex, debris_px, 64, 8, &debris_col, &debris_alpha)) gfx_custom(fdebris_layer, NULL, 0, VIEW_H);+}+static const EntClass FDEBRIS = {.name = "floatingDebris", .size = sizeof(Debris2), .update = fdebris_update, .render = fdebris_render,+ .on_player = fdebris_on_player, .kind = KIND_PCOLLIDE};+static void new_fdebris(const EData *dd) {+ Ent *e = ent_new(&FDEBRIS, dd->x, dd->y);+ if (!e) return;+ ent_box(e, 12, 12, -6, -6);+ e->depth = -5;+ Debris2 *d = ST(e, Debris2);+ d->start = v2(dd->x, dd->y);+ debris_tex = tex("scenery/debris");+ d->piece = (uint8_t)rndi(64 / 8);+ static const int8_t R[11] = {-2, -1, 0, 0, 0, 0, 0, 0, 0, 1, 2};+ d->rot_speed = R[rndi(11)] * 40 * (PI_F / 180);+ d->sine.freq = 0.4f;+ sine_randomize(&d->sine);+ d->accel = 1;+}++/* ---------------------------------------------------------------- ForegroundDebris */+typedef struct { V2 start; float parallax; SineWave sine[3]; uint8_t rock_b; } FgDebris;+static uint16_t fg_rock[2][3];+static void fgdebris_update(Ent *e) {+ FgDebris *f = ST(e, FgDebris);+ for (int i = 0; i < 3; i++) sine_update(&f->sine[i]);+}+static void fgdebris_render(Ent *e) {+ FgDebris *f = ST(e, FgDebris);+ V2 off = v2sub(v2add(g_level.cam, v2(160, 90)), f->start);+ float x = e->x - off.x * f->parallax, y = e->y - off.y * f->parallax;+ int n = f->rock_b ? 2 : 3;+ for (int i = 0; i < n; i++) { /* the images, in reverse order of the family */+ uint16_t t = fg_rock[f->rock_b][n - 1 - i];+ gfx_tex_ex(t, x, y + f->sine[i].value * 2, 24, 24, 1, 1, 0, 0xFFFF, 255, 0);+ }+}+static const EntClass FGDEBRIS = {.name = "foregroundDebris", .size = sizeof(FgDebris), .update = fgdebris_update,+ .render = fgdebris_render};+static void new_fgdebris(const EData *d) {+ Ent *e = ent_new(&FGDEBRIS, d->x, d->y);+ if (!e) return;+ e->depth = -999900;+ e->collidable = 0;+ FgDebris *f = ST(e, FgDebris);+ f->start = v2(d->x, d->y);+ f->rock_b = (uint8_t)rndi(2);+ int n = f->rock_b ? 2 : 3;+ for (int i = 0; i < n; i++) {+ f->sine[i].freq = 0.4f;+ sine_randomize(&f->sine[i]);+ }+ f->parallax = 0.05f + rndf() * 0.08f;+ char p[40];+ for (int i = 0; i < 3; i++) fg_rock[0][i] = tex(path2(p, "scenery/fgdebris/rock_a", NULL, i));+ for (int i = 0; i < 2; i++) fg_rock[1][i] = tex(path2(p, "scenery/fgdebris/rock_b", NULL, i));+}++/* ---------------------------------------------------------------- InvisibleBarrier */+static void barrier_update(Ent *e) {+ e->collidable = 1;+ Ent *p = level_player_ent();+ if (p && collide_ent_at(e, e->x, e->y, p)) e->collidable = 0;+ if (!e->collidable) e->active = 0;+}+static const EntClass BARRIER = {.name = "invisibleBarrier", .size = 0, .update = barrier_update, .kind = KIND_SOLID | KIND_CLIMBBLOCKER};+static void new_barrier(const EData *d, float w, float h) {+ Ent *e = ent_new(&BARRIER, d->x, d->y);+ if (!e) return;+ ent_box(e, w, h, 0, 0);+ e->safe = 1;+ e->tags = TAG_TRANSITION_UPDATE;+ e->collidable = 0;+ e->visible = 0;+}++/* ---------------------------------------------------------------- Lookout (towerviewer) */+typedef struct {+ float easer, timer[4], mult[4], dir[4]; /* up, down, left, right */+ float track_pct;+ uint8_t track, only_y;+} LookHud;+enum { LU, LD, LL, LR };+static void lookhud_update(Ent *e) {+ LookHud *h = ST(e, LookHud);+ Room *rm = g_level.room;+ V2 c = g_level.cam;+ bool bl = false, br = false, bu = h->track && h->track_pct >= 1, bd = h->track && h->track_pct <= 0; /* (no LookoutBlocker here) */+ h->dir[LL] = approach(h->dir[LL], (!bl && c.x > rm->x + 2) ? 1 : 0, DT * 8);+ h->dir[LR] = approach(h->dir[LR], (!br && c.x + 320 < rm->x + rm->w - 2) ? 1 : 0, DT * 8);+ h->dir[LU] = approach(h->dir[LU], (!bu && c.y > rm->y + 2) ? 1 : 0, DT * 8);+ h->dir[LD] = approach(h->dir[LD], (!bd && c.y + 180 < rm->y + rm->h - 2) ? 1 : 0, DT * 8);+ bool on[4] = {g_in.aim_y < 0, g_in.aim_y > 0, g_in.aim_x < 0, g_in.aim_x > 0};+ for (int i = 0; i < 4; i++) {+ h->mult[i] = approach(h->mult[i], on[i] ? 0 : 1, DT * 2);+ h->timer[i] += DT * (on[i] ? 12 : 6);+ }+}+/* GFX.Gui["towerarrow"] is not packed: a small arrow head instead, at the HUD's 1/6 scale */+static void look_arrow(float x, float y, int dir, uint16_t c, uint8_t a) {+ for (int i = 0; i < 4; i++) {+ float w = (float)i;+ switch (dir) {+ case LU: gfx_rect(x - w, y - 2 + i, 2 * w + 1, 1, c, a); break;+ case LD: gfx_rect(x - w, y + 2 - i, 2 * w + 1, 1, c, a); break;+ case LL: gfx_rect(x - 2 + i, y - w, 1, 2 * w + 1, c, a); break;+ default: gfx_rect(x + 2 - i, y - w, 1, 2 * w + 1, c, a); break;+ }+ }+}+static void lookhud_render(Ent *e) {+ LookHud *h = ST(e, LookHud);+ float num = ease_cube_inout(h->easer);+ uint8_t a = (uint8_t)(num * 255);+ if (!a) return;+ int n2 = (int)(80 * num), n3 = (int)(80 * num * 0.5625f), n4 = 8;+ const float k = 1 / 6.f;+ gfx_hud(true);+ gfx_rect(n2 * k, n3 * k, (1920 - n2 * 2 - n4) * k, n4 * k, 0xFFFF, a);+ gfx_rect(n2 * k, (n3 + n4) * k, (n4 + 2) * k, (1080 - n3 * 2 - n4) * k, 0xFFFF, a);+ gfx_rect((1920 - n2 - n4 - 2) * k, n3 * k, (n4 + 2) * k, (1080 - n3 * 2 - n4) * k, 0xFFFF, a);+ gfx_rect((n2 + n4) * k, (1080 - n3 - n4) * k, (1920 - n2 * 2 - n4) * k, n4 * k, 0xFFFF, a);+ float up = n3 * h->dir[LU] - sinf(h->timer[LU]) * 18 * lerpf(0.5f, 1, h->mult[LU]) - (1 - h->mult[LU]) * 12;+ look_arrow(160, up * k + 4, LU, 0xFFFF, (uint8_t)(a * h->dir[LU]));+ float down = 1080 - n3 * h->dir[LD] + sinf(h->timer[LD]) * 18 * lerpf(0.5f, 1, h->mult[LD]) + (1 - h->mult[LD]) * 12;+ look_arrow(160, down * k - 4, LD, 0xFFFF, (uint8_t)(a * h->dir[LD]));+ if (!h->track && !h->only_y) {+ float l = n2 * h->dir[LL] - sinf(h->timer[LL]) * 18 * lerpf(0.5f, 1, h->mult[LL]) - (1 - h->mult[LL]) * 12;+ look_arrow(l * k + 4, 90, LL, 0xFFFF, (uint8_t)(a * h->dir[LL]));+ float r = 1920 - n2 * h->dir[LR] + sinf(h->timer[LR]) * 18 * lerpf(0.5f, 1, h->mult[LR]) + (1 - h->mult[LR]) * 12;+ look_arrow(r * k - 4, 90, LR, 0xFFFF, (uint8_t)(a * h->dir[LR]));+ } else if (h->track) { /* the track and its cursor (GUI art: drawn as plain shapes) */+ int n15 = 1080 - n3 * 2 - 128 - 64, n16 = 1920 - n2 - 64;+ float n17 = (1080 - n15) / 2.f + 32;+ gfx_rect((n16 - 7) * k, (n17 + 7) * k, 14 * k, (n15 - 14) * k, 0, a);+ gfx_rect((n16 - 6) * k, (n17 + (1 - h->track_pct) * n15 - 6) * k, 12 * k, 12 * k, 0xFFFF, a);+ }+ gfx_hud(false);+}+static const EntClass LOOKHUD = {.name = "lookoutHud", .size = sizeof(LookHud), .update = lookhud_update, .render = lookhud_render};++/* the sprite "lookout" (Justify (0.5, 1)) as a frame table (smaller than a Sprite in the state), frames+ * of objects/lookout/lookout or nobackpack; an animation loads when first drawn, the room loads "idle" */+enum { LA_IDLE, LA_LOOKRIGHT, LA_LOOKLEFT, LA_LOOKING, LA_UP, LA_UPRIGHT, LA_RIGHT, LA_DOWNRIGHT, LA_DOWN, LA_DOWNLEFT, LA_LEFT,+ LA_UPLEFT, LA_ENDED = 255 };+static const uint8_t LA_FRAMES[12][10] = {{5, 5, 5, 5, 5, 5, 5, 5, 5, 6}, {0, 1, 2, 3, 4}, {15, 16, 17, 3, 4}, {4}, {7}, {8}, {9}, {10},+ {11}, {12}, {13}, {14}};+static const uint8_t LA_N[12] = {10, 5, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1};+static const float LA_DELAY[12] = {0.1f, 0.08f, 0.08f, 0.08f, 0, 0, 0, 0, 0, 0, 0, 0};+static uint16_t look_tex[2][18];+typedef struct { uint8_t anim, frame, variant; float timer; } LSpr;+static void lspr_play(LSpr *s, int a) {+ if (s->anim == a) return;+ s->anim = (uint8_t)a, s->frame = 0, s->timer = 0;+}+static void lspr_update(LSpr *s) {+ if (s->anim >= 12 || LA_DELAY[s->anim] <= 0) return;+ s->timer += DT;+ if (s->timer < LA_DELAY[s->anim]) return;+ s->timer -= LA_DELAY[s->anim];+ if (++s->frame < LA_N[s->anim]) return;+ if (s->anim == LA_LOOKRIGHT || s->anim == LA_LOOKLEFT) s->anim = LA_LOOKING; /* goto */+ s->frame = 0;+}+typedef struct {+ LSpr spr;+ Talk talk;+ V2 cam, speed, cam_start, cam_start_center, last_dir;+ float wait, node_pct, t;+ int16_t hud;+ int16_t nodes[8][2];+ Walk walk;+ Step zs; /* the summit's Level.ZoomTo */+ uint8_t nnodes, node, step, interacting, summit, only_y, at_top;+} Look;+static void look_play(Look *l, int anim) { lspr_play(&l->spr, anim); }+static V2 look_node(const Look *l, int i) { return v2(l->nodes[i][0], l->nodes[i][1]); }+static void look_end(Ent *e, Look *l, Player *p) {+ l->interacting = 0;+ ent_remove(ent_at(l->hud, &LOOKHUD));+ l->hud = -1;+ if (p && !p->dead) player_set_state(p, ST_NORMAL);+ l->step = 0;+ (void)e;+}+static void look_update(Ent *e) {+ Look *l = ST(e, Look);+ Player *p = level_player();+ bool talk = talk_update(&l->talk, e);+ if (talk && p) { /* Interact */+ l->spr.variant = p->no_backpack ? 1 : 0; /* (animPrefix "badeline_": Play As Badeline, not here) */+ l->interacting = 1;+ l->step = 1;+ return; /* the coroutine starts next frame */+ }+ Ent *hud = ent_at(l->hud, &LOOKHUD);+ LookHud *h = hud ? ST(hud, LookHud) : NULL;+ if (l->step && p) {+ if (l->wait > 0) l->wait -= DT;+ else switch (l->step) {+ case 1: /* LookRoutine */+ if (p->holding) holdable_release(p->holding, v2(0, 0)), p->holding = NULL;+ player_set_state(p, ST_DUMMY);+ l->walk = walk_exact((int)floorf(e->x)); /* yield return DummyWalkToExact((int)X, cancelOnFall: true) */+ l->walk.flags = WALK_CANCEL_ON_FALL;+ l->step = 2;+ break;+ case 2:+ if (!player_walk(p, &l->walk)) l->step = 21;+ break;+ case 21: {+ Ent *pe = p->ent;+ if (fabsf(e->x - pe->x) > 4 || p->dead || !player_on_ground(p)) {+ if (!p->dead) player_set_state(p, ST_NORMAL);+ l->step = 0, l->interacting = 0;+ break;+ }+ look_play(l, p->facing == 1 ? LA_LOOKRIGHT : LA_LOOKLEFT);+ p->ent->visible = 0; /* the player's sprite and hair */+ l->wait = 0.2f, l->step = 3;+ break;+ }+ case 3:+ hud = ent_new(&LOOKHUD, 0, 0);+ l->hud = ent_ref(hud);+ if (hud) {+ hud->depth = -2000000;+ hud->collidable = 0;+ hud->tags = TAG_HUD;+ LookHud *nh = ST(hud, LookHud);+ nh->track = l->nnodes > 0;+ nh->only_y = l->only_y;+ }+ l->node_pct = 0, l->node = 0;+ l->step = 4;+ break;+ case 4:+ if (h && (h->easer = approach(h->easer, 1, DT * 3)) < 1) break;+ l->cam = g_level.cam;+ l->speed = v2(0, 0), l->last_dir = v2(0, 0);+ l->cam_start = g_level.cam;+ l->cam_start_center = v2add(l->cam_start, v2(160, 90));+ l->step = 5;+ /* fall through */+ case 5: {+ if (btn_pressed(&g_in.back) || btn_pressed(&g_in.confirm) || btn_pressed(&g_in.dash) || btn_pressed(&g_in.jump) || !l->interacting) {+ l->step = 6;+ goto look_out;+ }+ V2 v = v2((float)g_in.aim_x, (float)g_in.aim_y);+ if (v.x && v.y) v = v2mul(v, 0.70710677f);+ if (l->only_y) v.x = 0;+ l->last_dir = v;+ if (l->spr.anim != LA_LOOKLEFT && l->spr.anim != LA_LOOKRIGHT) {+ int a;+ if (v.x == 0) a = v.y == 0 ? LA_LOOKING : v.y > 0 ? LA_DOWN : LA_UP;+ else if (v.x > 0) a = v.y == 0 ? LA_RIGHT : v.y > 0 ? LA_DOWNRIGHT : LA_UPRIGHT;+ else a = v.y == 0 ? LA_LEFT : v.y > 0 ? LA_DOWNLEFT : LA_UPLEFT;+ look_play(l, a);+ }+ Room *rm = g_level.room;+ const float accel = 800, maxspd = 240;+ if (!l->nnodes) {+ l->speed = v2add(l->speed, v2mul(v, accel * DT));+ if (v.x == 0) l->speed.x = approach(l->speed.x, 0, accel * 2 * DT);+ if (v.y == 0) l->speed.y = approach(l->speed.y, 0, accel * 2 * DT);+ float sl = v2len(l->speed);+ if (sl > maxspd) l->speed = v2mul(l->speed, maxspd / sl);+ l->cam.x += l->speed.x * DT;+ if (l->cam.x < rm->x || l->cam.x + 320 > rm->x + rm->w) l->speed.x = 0;+ l->cam.x = clampf(l->cam.x, (float)rm->x, (float)(rm->x + rm->w - 320));+ l->cam.y += l->speed.y * DT;+ if (l->cam.y < rm->y || l->cam.y + 180 > rm->y + rm->h) l->speed.y = 0;+ l->cam.y = clampf(l->cam.y, (float)rm->y, (float)(rm->y + rm->h - 180));+ g_level.cam = l->cam;+ break;+ }+ /* track mode: along the nodes */+ V2 a = l->node <= 0 ? l->cam_start_center : look_node(l, l->node - 1), b = look_node(l, l->node);+ float len = v2len(v2sub(a, b));+ V2 at;+ if (l->node_pct < 0.25f && l->node > 0) {+ V2 pa = l->node <= 1 ? l->cam_start_center : look_node(l, l->node - 2);+ V2 c0 = v2add(pa, v2mul(v2sub(a, pa), 0.75f)), c1 = v2add(a, v2mul(v2sub(b, a), 0.25f));+ float t = 0.5f + l->node_pct / 0.25f * 0.5f;+ at = v2(quad_curve(c0.x, a.x, c1.x, t), quad_curve(c0.y, a.y, c1.y, t));+ } else if (l->node_pct > 0.75f && l->node < l->nnodes - 1) {+ V2 nb = look_node(l, l->node + 1);+ V2 c0 = v2add(a, v2mul(v2sub(b, a), 0.75f)), c1 = v2add(b, v2mul(v2sub(nb, b), 0.25f));+ float t = (l->node_pct - 0.75f) / 0.25f * 0.5f;+ at = v2(quad_curve(c0.x, b.x, c1.x, t), quad_curve(c0.y, b.y, c1.y, t));+ } else+ at = v2add(a, v2mul(v2sub(b, a), l->node_pct));+ g_level.cam = v2add(at, v2(-160, -90));+ l->node_pct -= v.y * (maxspd / len) * DT;+ if (l->node_pct < 0) {+ if (l->node > 0) l->node--, l->node_pct = 1;+ else l->node_pct = 0;+ } else if (l->node_pct > 1) {+ if (l->node < l->nnodes - 1) l->node++, l->node_pct = 0;+ else {+ l->node_pct = 1;+ if (l->summit) {+ l->step = 6;+ goto look_out;+ }+ }+ }+ float done = 0, total = 0;+ for (int i = 0; i < l->nnodes; i++) {+ float sl = v2len(v2sub(i == 0 ? l->cam_start_center : look_node(l, i - 1), look_node(l, i)));+ total += sl;+ if (i < l->node) done += sl;+ else if (i == l->node) done += sl * l->node_pct;+ }+ if (h) h->track_pct = done / total;+ break;+ }+ look_out:+ case 6:+ p->ent->visible = 1;+ look_play(l, LA_IDLE);+ l->step = 7;+ /* fall through */+ case 7:+ if (h && (h->easer = approach(h->easer, 0, DT * 3)) > 0) break;+ l->at_top = l->summit && l->node >= l->nnodes - 1 && l->node_pct >= 0.95f;+ if (l->at_top) {+ l->wait = 0.5f;+ step_reset(&l->zs); /* Add(new Coroutine(level.ZoomTo((160, 90), 2, 3))): it starts next frame */+ l->step = 8;+ break;+ }+ l->step = 9;+ break;+ case 8: /* (the "escape" music parameter: no music) */+ if (l->zs.p < 1) zoom_to(&l->zs, v2(160, 90), 2, 3);+ if (!(btn_pressed(&g_in.back) || btn_pressed(&g_in.confirm) || btn_pressed(&g_in.dash) || btn_pressed(&g_in.jump)) &&+ l->interacting)+ break;+ l->step = 9;+ /* fall through */+ case 9:+ if (v2len(v2sub(l->cam_start, g_level.cam)) > 600) { /* back near the start, behind a FadeWipe */+ l->cam = g_level.cam;+ l->speed = v2norm(v2sub(l->cam, l->cam_start));+ l->t = 0;+ wipe_start(WIPE_FADE, false, NULL);+ g_wipe.duration = l->at_top ? 1.f : 0.5f;+ l->step = 10;+ break;+ }+ l->step = 11;+ break;+ case 10:+ l->t += DT / (l->at_top ? 1.f : 0.5f);+ if (l->t < 1) {+ g_level.cam = v2sub(l->cam, v2mul(l->speed, lerpf(0, 64, ease_cube_in(l->t))));+ break;+ }+ g_level.cam = v2add(l->cam_start, v2mul(l->speed, 32));+ wipe_start(WIPE_FADE, true, NULL);+ l->step = 11;+ break;+ case 11:+ zoom_snap(v2(0, 0), 1); /* Level.ZoomSnap(Vector2.Zero, 1) */+ look_end(e, l, p);+ break;+ }+ }+ /* base.Update() (the sprite), then Update's own */+ if (p) {+ bool active = l->interacting || p->state != ST_DUMMY;+ if (active) lspr_update(&l->spr);+ else l->spr.frame = 0;+ }+ if (l->talk.enabled && collide_solid(e, e->x, e->y)) l->talk.enabled = 0;+}+static void look_render(Ent *e) {+ Look *l = ST(e, Look);+ int a = l->spr.anim < 12 ? l->spr.anim : LA_IDLE;+ const uint16_t *tx = look_tex[l->spr.variant];+ if (!res_cached(tx[LA_FRAMES[a][l->spr.frame]])) { /* an animation not loaded yet: all its frames at once */+ uint16_t ids[10];+ for (int i = 0; i < LA_N[a]; i++) ids[i] = tx[LA_FRAMES[a][i]];+ res_load(ids, LA_N[a]);+ }+ gfx_tex(tx[LA_FRAMES[a][l->spr.frame]], e->x - 16, e->y - 32, 0, 0xFFFF, 255);+ light_add(e->x - 1, e->y - 11, 0xFFFFFF, 0.8f, 16, 24);+}+static void look_removed(Ent *e) {+ Look *l = ST(e, Look);+ if (l->interacting) {+ Player *p = level_player();+ if (p) player_set_state(p, ST_NORMAL), p->ent->visible = 1;+ ent_remove(ent_at(l->hud, &LOOKHUD));+ }+}+static const EntClass LOOKOUT = {.name = "towerviewer", .size = sizeof(Look), .update = look_update, .render = look_render,+ .removed = look_removed, .kind = KIND_TALK};+static void new_lookout(const EData *d) {+ Ent *e = ent_new(&LOOKOUT, d->x, d->y);+ if (!e) return;+ e->depth = -8500;+ ent_box(e, 4, 4, -2, -4);+ Look *l = ST(e, Look);+ ch1_talk_add(e, &l->talk, -24, -8, 48, 8, v2(-0.5f, -20));+ l->talk.must_face = false;+ l->summit = EAB(d, towerviewer, summit);+ l->only_y = EAB(d, towerviewer, onlyY);+ l->hud = -1;+ l->spr.anim = LA_IDLE;+ char p[40];+ for (int i = 0; i < 18; i++) {+ look_tex[0][i] = tex(path2(p, "objects/lookout/lookout", NULL, i));+ look_tex[1][i] = tex(path2(p, "objects/lookout/nobackpack", NULL, i));+ }+ l->nnodes = (uint8_t)(d->nnodes < 8 ? d->nnodes : 8);+ for (int i = 0; i < l->nnodes; i++) {+ V2 n = ed_node(d, i);+ l->nodes[i][0] = (int16_t)n.x, l->nodes[i][1] = (int16_t)n.y;+ }+}++/* ---------------------------------------------------------------- DreamMirror and CS02_Mirror */+#define GLASS_W 54+#define GLASS_H 29+typedef struct {+ Sprite glass, refl;+ Hair hair;+ V2 rpos; /* the reflection, inside the glass (its render target) */+ V2 bpos; /* BadelineDummy, after the break */+ float shine_alpha, shine_offset, wait, t, bspeed, refl_sx;+ float act_p, zb_t;+ Step zs; /* Level.ZoomTo / ZoomBack */+ Walk walk; /* DummyRunTo */+ int16_t dream, cs_ent;+ int16_t hb_x, hb_w; /* the hitbox, widened once the player is in */+ int8_t dir, act_shx, act_shy;+ uint8_t smashed, smash_ended, update_shine, auto_refl, step, cs, act, bstate, refl_on, zb_on;+} Mirror;+static uint16_t mirror_frame_tex, mirror_bg, mirror_fg;+static const EntClass MIRROR;+static bool mirror_hit(Ent *e, Mirror *m, Ent *pe) {+ float l = e->x + m->hb_x, t = e->y - 39 - 32;+ return collide_rect(pe, l, t, l + m->hb_w, t + 39 + 32);+}+/* the glass, drawn like its render target: glassbg, the reflection, the shine, all at 0.7 */+typedef struct { uint16_t col; uint8_t a; } Px;+static void mirror_layer(uint16_t *strip, int sy0, int sy1, void *ctx) {+ Ent *e = ctx;+ Mirror *m = ST(e, Mirror);+ int ox = vx(e->x - 27), oy = vy(e->y - 29);+ Tex bg, fg, rt;+ if (!tex_get(mirror_bg, &bg) || !tex_get(mirror_fg, &fg)) return;+ uint16_t rtex = m->refl_on ? spr_tex(&m->refl) : 0xFFFF;+ bool has_r = rtex != 0xFFFF && tex_get(rtex, &rt);+ int n;+ const uint16_t *bgc = pal_colors(bg.pal, &n), *fgc = pal_colors(fg.pal, &n), *rc = has_r ? pal_colors(rt.pal, &n) : NULL;+ const uint8_t *bga = pal_alpha(bg.pal), *fga = pal_alpha(fg.pal), *ra = has_r ? pal_alpha(rt.pal) : NULL;+ static uint8_t r1[GLASS_W], r2[GLASS_W], r3[GLASS_W], r4[64];+ int hx = 0, hy = 0, hfr = 0, carry;+ bool hhas = false;+ if (has_r) hair_meta(rtex, &hx, &hy, &hfr, &hhas, &carry);+ int rflip = m->refl_sx < 0;+ for (int y = 0; y < GLASS_H; y++) {+ int Y = oy + y;+ if (Y < sy0 || Y >= sy1) continue;+ Px row[GLASS_W];+ memset(row, 0, sizeof row);+ /* glassbg */+ int br = y - bg.oy;+ if (br >= 0 && br < bg.h) {+ tex_row_idx(&bg, br, r1);+ for (int i = 0; i < bg.w; i++)+ if (r1[i] && bg.ox + i < GLASS_W) row[bg.ox + i] = (Px){bgc[r1[i] - 1], bga[r1[i] - 1]};+ }+ /* the reflection: hair, then the sprite (origin from Justify, flipped by its scale) */+ if (has_r) {+ if (hhas) {+ for (int pass = 0; pass < 2; pass++)+ for (int k = 0; k < BHAIR; k++) {+ int i = pass ? BHAIR - 1 - k : k;+ float s = 0.25f + (1 - (float)i / BHAIR) * 0.75f;+ V2 c = m->hair.n[i];+ for (int x = 0; x < GLASS_W; x++)+ for (int o = pass ? 4 : 0; o < (pass ? 5 : 4); o++) {+ float px = c.x + (o == 0 ? -1 : o == 1 ? 1 : 0), py = c.y + (o == 2 ? -1 : o == 3 ? 1 : 0);+ int v = (int)floorf((y + 0.5f - floorf(py + 0.5f)) / s + 5), u = (int)floorf((x + 0.5f - floorf(px + 0.5f)) / s + 5);+ if (v >= 0 && v < 10 && u >= HAIR_SPAN[v][0] && u < HAIR_SPAN[v][1])+ row[x] = (Px){pass ? rgb(0x9B3FB5) : 0, 255};+ }+ }+ }+ int sx0 = (int)floorf(m->rpos.x - m->refl.ox * (rflip ? -1 : 1) + 0.5f), sy0r = (int)floorf(m->rpos.y - m->refl.oy + 0.5f);+ int rr = y - sy0r - rt.oy;+ if (rr >= 0 && rr < rt.h && rt.w <= 64) {+ tex_row_idx(&rt, rr, r4);+ for (int i = 0; i < rt.w; i++) {+ if (!r4[i]) continue;+ int x = rflip ? sx0 - (rt.ox + i) - 1 : sx0 + rt.ox + i;+ if (x >= 0 && x < GLASS_W) row[x] = (Px){rc[r4[i] - 1], ra[r4[i] - 1]};+ }+ }+ }+ /* glassfg, twice, at the shine's offset */+ int sa = (int)(m->shine_alpha * 256);+ for (int k = 0; k < 2; k++) {+ int fr = y - (int)(m->shine_offset - k * fg.fh) - fg.oy;+ if (fr < 0 || fr >= fg.h) continue;+ tex_row_idx(&fg, fr, k ? r3 : r2);+ uint8_t *rb = k ? r3 : r2;+ for (int i = 0; i < fg.w; i++) {+ if (!rb[i] || fg.ox + i >= GLASS_W) continue;+ Px *d = &row[fg.ox + i];+ int a = (fga[rb[i] - 1] * sa) >> 8;+ uint16_t c = scale565(fgc[rb[i] - 1], sa);+ d->col = blend565(scale565(d->col, 256), c, a);+ d->a = (uint8_t)(a + ((255 - a) * d->a >> 8));+ }+ }+ for (int x = 0; x < GLASS_W; x++) {+ int X = ox + x;+ if (!row[x].a || (unsigned)X >= VIEW_W) continue;+ int a = (row[x].a * 179) >> 8; /* * 0.7 */+ uint16_t *d = strip + (Y - sy0) * VIEW_W + X;+ *d = blend565(*d, scale565(row[x].col, 179), a + 1);+ }+ }+}+static void mirror_render(Ent *e) {+ Mirror *m = ST(e, Mirror);+ if (m->smashed) spr_draw(&m->glass, e->x, e->y);+ else {+ tex_touch(mirror_bg), tex_touch(mirror_fg);+ if (m->refl_on) tex_touch(spr_tex(&m->refl));+ gfx_custom(mirror_layer, e, vy(e->y - 29), vy(e->y) + 1);+ }+ gfx_tex(mirror_frame_tex, e->x - 32, e->y - 39, 0, 0xFFFF, 255); /* frame, JustifyOrigin(0.5, 1) */+ if (m->bstate) { /* BadelineDummy */+ Sprite s = m->refl;+ s.sx = m->refl_sx;+ hair_render(&m->hair, &s, m->refl_sx < 0 ? -1 : 1, rgb(0x9B3FB5), 1);+ spr_draw(&s, floorf(m->bpos.x), floorf(m->bpos.y));+ }+}+static Ent *first_dreamblock(void) {+ Ent *best = NULL;+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o->cls == &DREAMBLOCK && o->dead != 1 && (!best || (int16_t)(o->order - best->order) < 0)) best = o;+ }+ return best;+}+/* DreamBlock.Activate, on the first dream block; true when done */+static bool dream_activate_step(Mirror *m) {+ Ent *e = ent_at(m->dream, &DREAMBLOCK);+ if (!e) return true;+ Dream *d = ST(e, Dream);+ if (m->wait > 0) {+ m->wait -= DT;+ return false;+ }+ switch (m->act) {+ case 0:+ m->wait = 1, m->act = 1, m->act_p = 0;+ return false;+ case 1: /* the Shaker (0.02 s) while it fills with white */+ if (m->act_p < 1) {+ if (level_on_interval(0.02f)) d->sx = (int8_t)shake_val(), d->sy = (int8_t)shake_val();+ d->white_fill = ease_cube_in(m->act_p);+ m->act_p += DT;+ return false;+ }+ d->sx = d->sy = 0;+ m->wait = 0.5f, m->act = 2;+ return false;+ case 2:+ dream_activate_now(e);+ d->white_height = 1, d->white_fill = 1;+ m->act_p = 1, m->act = 3;+ /* fall through */+ case 3:+ if (m->act_p > 0) {+ d->white_height = m->act_p;+ if (level_on_interval(0.1f))+ for (int i = 0; (float)i < e->cw; i += 4)+ particles_emit1(PL_FG, &P_Strawberry_P_WingsBurst, v2(e->x + i, e->y + e->ch * d->white_height + 1),+ P_Strawberry_P_WingsBurst.direction);+ if (level_on_interval(0.1f)) level_shake(0.3f);+ m->act_p -= DT * 0.5f;+ return false;+ }+ m->act = 4;+ /* fall through */+ default:+ if (d->white_fill > 0) {+ d->white_fill -= DT * 3;+ return false;+ }+ return true;+ }+}+static void mirror_cs_end(Ent *e, Mirror *m, Player *p, bool skipped) { /* CS02_Mirror.OnEnd */+ m->update_shine = 0; /* Broken(WasSkipped) */+ m->smashed = m->smash_ended = 1;+ spr_play(&m->glass, A_glass_broken, false);+ if (skipped) m->bstate = 0, m->refl_on = 0; /* the BadelineDummy goes */+ if (p) {+ player_set_state(p, ST_NORMAL);+ p->dummy_auto_animate = true;+ p->speed = v2(0, 0);+ p->ent->x = e->x + 8 * m->dir;+ p->facing = m->dir ? -m->dir : 1;+ p->inventory_dreamdash = true;+ }+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &DREAMBLOCK && g_ents[i].dead != 1) dream_activate_now(&g_ents[i]);+ zoom_reset(); /* Level.ResetZoom */+ g_session.dreamdash = 1; /* Session.Inventory.DreamDash */+ m->cs = 0, m->zb_on = 0;+}+/* CS02_Mirror's Cutscene and DreamMirror.BreakRoutine */+static void mirror_cutscene(Ent *e, Mirror *m, Player *p) {+ if (m->zb_on) { /* the ZoomBack coroutine: 1.2 s, then Level.ZoomBack(3) */+ if (m->zb_t > 0) m->zb_t -= DT;+ else if (!zoom_back(&m->zs, 3)) m->zb_on = 0;+ }+ if (m->cs >= 20) { /* yield return dreamBlock.Activate(); yield return 0.5f; EndCutscene */+ if (m->cs == 0xFF || !dream_activate_step(m)) return;+ if (m->cs == 20) m->cs = 21, m->wait = 0.5f;+ else if (m->wait > 0) m->wait -= DT;+ else m->cs = 0xFF;+ return;+ }+ if (m->wait > 0) {+ m->wait -= DT;+ return;+ }+ Ent *pe = p->ent;+ switch (m->cs) {+ case 1:+ m->dir = (int8_t)signf(pe->x - e->x);+ player_set_state(p, ST_DUMMY);+ m->wait = 1, m->cs = 2;+ break;+ case 2:+ p->facing = -m->dir;+ m->wait = 0.4f, m->cs = 3;+ break;+ case 3: /* yield return DummyRunTo(mirror.X + 8 * direction) */+ m->walk = (Walk){e->x + 8 * m->dir, 1, RUN_TO, 0, 0, 0};+ m->cs = 4;+ break;+ case 4:+ if (player_walk(p, &m->walk)) break;+ m->wait = 0.5f, m->cs = 5;+ break;+ case 5: /* yield return Level.ZoomTo(mirror - camera - (0, 24), 2, 1) */+ step_reset(&m->zs);+ m->cs = 15;+ break;+ case 15:+ if (zoom_to(&m->zs, v2(e->x - g_level.cam.x, e->y - g_level.cam.y - 24), 2, 1)) break;+ m->wait = 0.5f, m->cs = 6;+ break;+ case 6: /* BreakRoutine */+ m->auto_refl = 0;+ spr_play(&m->refl, A_badeline_runFast, false);+ m->cs = 7;+ /* fall through */+ case 7:+ if (fabsf(m->rpos.x - GLASS_W / 2.f) > 3) {+ m->rpos.x += m->dir * 32 * DT;+ break;+ }+ spr_play(&m->refl, A_badeline_idle, false);+ m->wait = 0.65f + 0.15f, m->cs = 8;+ break;+ case 8:+ m->update_shine = 0;+ if (m->shine_offset != 33 || m->shine_alpha < 1) {+ m->shine_offset = approach(m->shine_offset, 33, DT * 120);+ m->shine_alpha = approach(m->shine_alpha, 1, DT * 4);+ break;+ }+ m->smashed = 1;+ spr_play(&m->glass, A_glass_break, false);+ m->wait = 0.6f, m->cs = 9;+ break;+ case 9:+ level_shake(0.3f);+ for (float x = -GLASS_W / 2.f; x < GLASS_W / 2.f; x += 8)+ for (float y = -GLASS_H; y < 0; y += 8)+ if (rndf() < 0.5f)+ particles_emit(PL_MID, &P_DreamMirror_P_Shatter, 2, v2(e->x + x + 4, e->y + y + 4), v2(8, 8), atan2f(y, x));+ m->smash_ended = 1;+ m->bpos = v2(m->rpos.x + e->x - 27, m->rpos.y + e->y - 29);+ m->bstate = 1;+ spr_play(&m->refl, A_badeline_idle, false);+ m->refl_on = 0;+ for (int i = 0; i < BHAIR; i++) m->hair.n[i] = v2add(m->hair.n[i], v2(e->x - 27, e->y - 29));+ m->wait = 1.2f, m->cs = 10;+ break;+ case 10:+ m->bspeed = -m->dir * 32.f;+ m->refl_sx = (float)-m->dir;+ spr_play(&m->refl, A_badeline_runFast, false);+ m->cs = 11;+ /* fall through */+ case 11:+ if (fabsf(m->bpos.x - e->x) < 60) {+ m->bspeed += DT * -m->dir * 128;+ m->bpos.x += m->bspeed * DT;+ break;+ }+ spr_play(&m->refl, A_badeline_jumpFast, false);+ m->cs = 12;+ /* fall through */+ case 12:+ if (fabsf(m->bpos.x - e->x) < 128) {+ m->bspeed += DT * -m->dir * 128;+ m->bpos.x += m->bspeed * DT;+ m->bpos.y -= fabsf(m->bspeed) * DT * 0.8f;+ break;+ }+ m->bstate = 0;+ m->wait = 1.5f, m->cs = 13;+ break;+ case 13: /* back in the cutscene: Madeline looks up, the camera goes up */+ p->dummy_auto_animate = false;+ spr_play(&p->spr, A_player_lookUp, false);+ m->t = 0;+ m->rpos = g_level.cam; /* (the reflection is gone: its fields keep the camera's start) */+ m->cs = 14;+ /* fall through */+ case 14:+ if (m->t < 1) {+ g_level.cam = v2add(m->rpos, v2(0, -80 * ease_cube_inout(m->t)));+ m->t += DT * 1.2f;+ break;+ }+ m->dream = ent_ref(first_dreamblock());+ m->zb_on = 1, m->zb_t = 1.2f; /* Add(new Coroutine(ZoomBack())) */+ step_reset(&m->zs);+ m->act = 0;+ m->cs = 20;+ break;+ }+}+/* CS02_Mirror, the CutsceneEntity (skippable): its steps run on the mirror's state */+typedef struct { Cutscene c; int16_t mirror; } CS02;+static void cs02_update(Ent *e) {+ Ent *me = ent_at(ST(e, CS02)->mirror, &MIRROR);+ Player *p = level_player();+ if (!me || !p) return;+ Mirror *m = ST(me, Mirror);+ if (m->cs && m->cs != 0xFF) mirror_cutscene(me, m, p);+ if (m->cs == 0xFF) cutscene_end(e); /* EndCutscene: OnEnd */+}+static void cs02_on_end(Ent *e, bool skipped) {+ Ent *me = ent_at(ST(e, CS02)->mirror, &MIRROR);+ if (me) mirror_cs_end(me, ST(me, Mirror), level_player(), skipped);+}+static const EntClass CS02_MIRROR = {.name = "CS02_Mirror", .size = sizeof(CS02), .update = cs02_update};+static void mirror_update(Ent *e) {+ Mirror *m = ST(e, Mirror);+ Player *p = level_player();+ spr_update(&m->glass);+ spr_update(&m->refl);+ if (!m->smashed && p) { /* InteractRoutine */+ if (m->step == 0 && mirror_hit(e, m, p->ent)) m->hb_w += 32, m->hb_x -= 16, m->step = 1;+ else if (m->step == 1 && !mirror_hit(e, m, p->ent)) {+ m->step = 2, m->cs = 1;+ Ent *c = ent_new(&CS02_MIRROR, 0, 0); /* Scene.Add(new CS02_Mirror(player, this)) */+ m->cs_ent = ent_ref(c);+ if (c) ST(c, CS02)->mirror = ent_ref(e), cutscene_start(c, cs02_on_end, true, false);+ }+ }+ if (m->cs && p && !ent_at(m->cs_ent, &CS02_MIRROR)) { /* (no room for the cutscene's entity: run here) */+ if (m->cs != 0xFF) mirror_cutscene(e, m, p);+ if (m->cs == 0xFF) mirror_cs_end(e, m, p, false);+ }+ /* BeforeRender: the reflection copies the player, mirrored */+ if (!m->smashed && p && m->auto_refl) {+ m->rpos = v2(e->x - p->ent->x + 27, p->ent->y - e->y + 29);+ m->refl_sx = (float)-p->facing * fabsf(p->spr.sx);+ int a = badeline_anim(p->spr.anim);+ if (a >= 0 && a != m->refl.anim && p->spr.anim != 255) spr_play(&m->refl, a, false);+ }+ if (m->update_shine) {+ Tex fg;+ float h = tex_get(mirror_fg, &fg) ? fg.fh : 73;+ m->shine_offset = h - (float)(int)fmodf(g_level.cam.y * 0.8f, h);+ }+ if (m->refl_on || m->bstate) {+ int f = m->refl_sx < 0 ? -1 : 1;+ V2 at = m->bstate ? m->bpos : m->rpos;+ hair_after_update(&m->hair, &m->refl, at, f);+ m->hair.wave += DT * 4;+ }+}+static const EntClass MIRROR = {.name = "dreammirror", .size = sizeof(Mirror), .update = mirror_update, .render = mirror_render};+static void new_mirror(const EData *d) {+ Ent *e = ent_new(&MIRROR, d->x, d->y);+ if (!e) return;+ e->depth = 9500;+ e->collidable = 0;+ Mirror *m = ST(e, Mirror);+ mirror_frame_tex = tex("objects/mirror/frame");+ mirror_bg = tex("objects/mirror/glassbg");+ mirror_fg = tex("objects/mirror/glassfg");+ m->dream = m->cs_ent = -1;+ spr_init(&m->glass, SB_glass);+ spr_play(&m->glass, A_glass_idle, true);+ m->hb_x = -32 + 8, m->hb_w = 64 - 16;+ m->shine_alpha = 0.5f;+ m->update_shine = 1;+ m->smashed = g_session.dreamdash;+ if (m->smashed) {+ spr_play(&m->glass, A_glass_broken, true);+ m->smash_ended = 1;+ } else {+ spr_init(&m->refl, SB_badeline);+ spr_play(&m->refl, A_badeline_idle, true);+ m->refl_on = 1, m->auto_refl = 1;+ m->refl_sx = 1;+ hair_start(&m->hair, v2(d->x, d->y), 1);+ }+}++/* ---------------------------------------------------------------- the story's helpers (ch1.c) */+#define EV_BEGIN \+ if (c->wait > 0) { \+ c->wait -= DT; \+ return false; \+ } \+ switch (c->co) { \+ case 0:+#define EV_YIELD_(n) \+ do { \+ c->co = (n); \+ return false; \+ case (n):; \+ } while (0)+#define EV_YIELD EV_YIELD_(__COUNTER__ + 1)+#define EV_WAIT(t) \+ do { \+ c->wait = (t); \+ EV_YIELD; \+ } while (0)+#define EV_NEST(call) \+ do { \+ EV_YIELD; \+ while (call) EV_YIELD; \+ EV_YIELD; \+ } while (0)+#define EV_END \+ default:; \+ } \+ return true+static Co *ev_start(Co *c, int8_t *at, int index) {+ if (*at != index) *at = (int8_t)index, memset(c, 0, sizeof *c);+ return c;+}+static Ent *find_class(const EntClass *cls) {+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == cls && g_ents[i].dead != 1) return &g_ents[i];+ return NULL;+}+static void draw_npc(const Sprite *spr, float x, float y) { /* Scale.X turns it */+ Sprite s = *spr;+ s.flipx = s.sx < 0;+ s.sx = fabsf(s.sx);+ spr_draw(&s, x, y);+}+/* Sprite.PlayRoutine's wait: true while the animation plays */+static bool spr_playing(const Sprite *s, int anim) { return s->anim == anim && s->playing; }++/* ---------------------------------------------------------------- BadelineDummy (ch2_bdummy_: chapters 3 and 4 too) */+typedef struct {+ Sprite spr;+ Hair hair;+ HairJob job;+ SineWave wave;+ Wiggler pop; /* BadelineAutoAnimator's */+ V2 float_normal, perp, from;+ float floatness, light, speed, p, clip[4], calpha;+ uint8_t step, syncing, last_anim, clipped;+} BDummy;+static const EntClass BDUMMY;+static float bd_facing(const BDummy *b) { return b->spr.sx < 0 ? -1.f : 1.f; }+static V2 bd_center(const Ent *e) { return v2(e->x, e->y - 4); } /* Hitbox(6, 6, -3, -7) */+static void bdummy_update(Ent *e) {+ BDummy *b = ST(e, BDummy);+ b->hair.wave += DT * 4; /* the components: Hair, Sprite, the auto animator (and its pop), the wave */+ spr_update(&b->spr);+ int bank, idle;+ bool sync = false;+ if (textbox_portrait(&bank, &idle) && bank == SB_portrait_badeline) { /* BadelineAutoAnimator */+ if (idle == A_portrait_badeline_idle_scoff) {+ if (!b->syncing) b->last_anim = b->spr.anim;+ spr_play(&b->spr, A_badeline_laugh, false);+ b->syncing = 1, sync = 1;+ } else if (idle == A_portrait_badeline_idle_yell || idle == A_portrait_badeline_idle_freakA ||+ idle == A_portrait_badeline_idle_freakB || idle == A_portrait_badeline_idle_freakC) {+ if (!b->syncing) wiggler_restart(&b->pop), b->last_anim = b->spr.anim;+ spr_play(&b->spr, A_badeline_angry, false);+ b->syncing = 1, sync = 1;+ }+ }+ if (b->syncing && !sync) {+ b->syncing = 0;+ if (b->last_anim == 255 || b->last_anim == A_badeline_spin) b->last_anim = A_badeline_fallSlow;+ if (b->spr.anim == A_badeline_angry) wiggler_restart(&b->pop);+ spr_play(&b->spr, b->last_anim, false);+ }+ if (b->pop.active) {+ wiggler_update(&b->pop);+ float k = 1 + 0.25f * b->pop.value;+ b->spr.sx = bd_facing(b) * k, b->spr.sy = k;+ }+ sine_update(&b->wave);+ V2 off = v2mul(b->float_normal, b->wave.value * b->floatness); /* Sprite.Position */+ hair_after_update(&b->hair, &b->spr, v2(e->x + off.x, e->y + off.y), (int)bd_facing(b));+}+static void bdummy_render(Ent *e) {+ BDummy *b = ST(e, BDummy);+ V2 off = v2mul(b->float_normal, b->wave.value * b->floatness);+ float x = floorf(e->x + off.x), y = floorf(e->y + off.y); /* RenderPosition floored */+ if (!b->clipped) {+ b->job.cw = 0;+ hair_render_into(&b->hair, &b->spr, (int)bd_facing(b), rgb(0x9B3FB5), 1, &b->job);+ draw_npc(&b->spr, x, y);+ } else { /* cut to a rect (the resort mirror's glass shows her) */+ int cx0 = (int)b->clip[0] - g_camx, cy0 = (int)b->clip[1] - g_camy, cx1 = (int)b->clip[2] - g_camx, cy1 = (int)b->clip[3] - g_camy;+ b->job.cx = (int16_t)cx0, b->job.cy = (int16_t)cy0, b->job.cw = (int16_t)(cx1 - cx0), b->job.ch = (int16_t)(cy1 - cy0);+ hair_render_into(&b->hair, &b->spr, (int)bd_facing(b), rgb(0x9B3FB5), b->calpha, &b->job);+ uint16_t t = spr_tex(&b->spr);+ Tex tx;+ if (t != 0xFFFF && tex_get(t, &tx)) {+ float ox = b->spr.justify ? tx.fw * b->spr.jx : b->spr.ox, oy = b->spr.justify ? tx.fh * b->spr.jy : b->spr.oy;+ bool flip = b->spr.sx < 0;+ int fx = (int)(x - (flip ? tx.fw - ox : ox)) - g_camx, fy = (int)(y - oy) - g_camy; /* the frame's top left */+ int l = fx > cx0 ? fx : cx0, r = fx + tx.fw < cx1 ? fx + tx.fw : cx1, tp = fy > cy0 ? fy : cy0, bt = fy + tx.fh < cy1 ? fy + tx.fh : cy1;+ if (l < r && tp < bt)+ gfx_tex_part(t, (float)(l + g_camx), (float)(tp + g_camy), flip ? tx.fw - (r - fx) : l - fx, tp - fy, r - l, bt - tp, flip ? GF_FLIPX : 0,+ 0xFFFF, (uint8_t)(clampf(b->calpha, 0, 1) * 255));+ }+ }+ light_add(e->x, e->y - 8, 0xDB7093, b->light, 20, 60);+}+static const EntClass BDUMMY = {.size = sizeof(BDummy), .name = "BadelineDummy", .update = bdummy_update, .render = bdummy_render};+Ent *ch2_bdummy_new(V2 at) {+ Ent *e = ent_new(&BDUMMY, at.x, at.y);+ if (!e) return NULL;+ e->collidable = 0;+ BDummy *b = ST(e, BDummy);+ spr_init(&b->spr, SB_badeline);+ spr_play(&b->spr, A_badeline_fallSlow, false);+ b->spr.sx = -1;+ hair_start(&b->hair, at, -1);+ wiggler_init(&b->pop, 0.5f, 4);+ b->wave.freq = 0.25f;+ sine_set(&b->wave, 0);+ b->float_normal = v2(0, 1);+ b->floatness = 2;+ b->light = 1;+ b->last_anim = 255;+ return e;+}+void ch2_bdummy_appear(Ent *e) { /* Appear (the displacement burst: no distortion here) */+ particles_emit(PL_MID, &P_BadelineOldsite_P_Vanish, 12, bd_center(e), v2(6, 6), P_BadelineOldsite_P_Vanish.direction);+}+void ch2_bdummy_vanish(Ent *e) { /* Vanish */+ particles_emit(PL_MID, &P_BadelineOldsite_P_Vanish, 12, bd_center(e), v2(6, 6), P_BadelineOldsite_P_Vanish.direction);+ ent_remove(e);+}+void ch2_bdummy_face(Ent *e, int f) { ST(e, BDummy)->spr.sx = (float)f; }+void ch2_bdummy_clip(Ent *e, float x0, float y0, float x1, float y1, float alpha) {+ BDummy *b = ST(e, BDummy);+ b->clip[0] = x0, b->clip[1] = y0, b->clip[2] = x1, b->clip[3] = y1;+ b->calpha = alpha, b->clipped = 1;+}+void ch2_bdummy_floatness(Ent *e, float f) { ST(e, BDummy)->floatness = f; }+/* FloatTo: a nested step; flags: BD_TURN (turnAtEndTo: turn), BD_NOFACE, BD_FADELIGHT, BD_QUICKEND */+enum { BD_TURN = 1, BD_NOFACE = 2, BD_FADELIGHT = 4, BD_QUICKEND = 8 };+bool ch2_bdummy_float_to(Ent *e, V2 target, int turn, int flags) {+ BDummy *b = ST(e, BDummy);+ switch (b->step) {+ case 0: {+ spr_play(&b->spr, A_badeline_fallSlow, false);+ if (!(flags & BD_NOFACE) && signf(target.x - e->x) != 0) b->spr.sx = signf(target.x - e->x);+ V2 d = v2norm(v2sub(target, v2(e->x, e->y)));+ b->perp = v2(-d.y, d.x);+ b->speed = 0;+ b->step = 1;+ }+ /* fall through */+ case 1:+ if (e->x != target.x || e->y != target.y) {+ b->speed = approach(b->speed, 120, 240 * DT);+ V2 d = v2sub(target, v2(e->x, e->y));+ float l = v2len(d), k = b->speed * DT;+ if (l <= k) e->x = target.x, e->y = target.y;+ else e->x += d.x / l * k, e->y += d.y / l * k;+ b->floatness = approach(b->floatness, 4, 8 * DT);+ V2 n = v2sub(b->perp, b->float_normal);+ l = v2len(n), k = DT * 12;+ b->float_normal = l <= k ? b->perp : v2add(b->float_normal, v2mul(n, k / l));+ if (flags & BD_FADELIGHT) b->light = approach(b->light, 0, DT * 2);+ return true;+ }+ if (flags & BD_QUICKEND) b->floatness = 2;+ b->step = 2;+ /* fall through */+ default:+ if (b->floatness != 2) {+ b->floatness = approach(b->floatness, 2, 8 * DT);+ return true;+ }+ if (flags & BD_TURN) b->spr.sx = (float)turn;+ b->step = 0;+ return false;+ }+}+/* WalkTo */+bool ch2_bdummy_walk_to(Ent *e, float x, float speed) {+ BDummy *b = ST(e, BDummy);+ if (!b->step) {+ b->floatness = 0;+ spr_play(&b->spr, A_badeline_walk, false);+ if (signf(x - e->x) != 0) b->spr.sx = signf(x - e->x);+ b->step = 1;+ }+ if (e->x != x) {+ e->x = approach(e->x, x, DT * speed);+ return true;+ }+ spr_play(&b->spr, A_badeline_idle, false);+ b->step = 0;+ return false;+}+/* SmashBlock: the first DashBlock breaks */+bool ch2_bdummy_smash(Ent *e, V2 target) {+ BDummy *b = ST(e, BDummy);+ switch (b->step) {+ case 0:+ spr_play(&b->spr, A_badeline_dreamDashLoop, false);+ b->from = v2(e->x, e->y);+ b->p = 0, b->step = 1;+ /* fall through */+ case 1:+ if (b->p < 1) {+ V2 at = v2lerp(b->from, target, ease_cube_out(b->p));+ e->x = at.x, e->y = at.y;+ b->p += DT * 6;+ return true;+ }+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls && g_ents[i].dead != 1 && level_is_dash_block(&g_ents[i])) {+ level_break_dash_block(&g_ents[i], v2(0, -1));+ break;+ }+ spr_play(&b->spr, A_badeline_idle, false);+ b->p = 0, b->step = 2;+ /* fall through */+ case 2:+ if (b->p < 1) {+ V2 at = v2lerp(target, b->from, ease_cube_out(b->p));+ e->x = at.x, e->y = at.y;+ b->p += DT * 4;+ return true;+ }+ spr_play(&b->spr, A_badeline_fallSlow, false);+ b->step = 0;+ return false;+ }+ return false;+}++/* ---------------------------------------------------------------- Selfie (ch2_selfie_: chapter 4's too) */+/* the photos: Portraits' selfie (with selfieFilter sliding over it) and selfieGondola */+enum { SF_PICTURE, SF_FILTER, SF_OPEN };+typedef struct { Co co; float p, timer, rot, filter; V2 pos; uint16_t photo; uint8_t mode, waiting, done; } Selfie;+static bool selfie_confirm(void) { return btn_pressed(&g_in.confirm) || btn_pressed(&g_in.back) || btn_pressed(&g_in.jump) || btn_pressed(&g_in.dash); }+static void selfie_update(Ent *e) {+ Selfie *s = ST(e, Selfie);+ if (s->waiting) s->timer += DT;+ Co *c = &s->co;+ CO_BEGIN(c);+ if (s->mode == SF_PICTURE) {+ ch1_flash(0xFFFFFF);+ CO_WAIT(c, 0.5f);+ }+ for (s->p = 0; s->p < 1;) { /* OpenRoutine */+ s->p += DT;+ s->pos = v2lerp(v2(992, 1080 + 400), v2(960, 540), ease_cube_out(s->p));+ s->rot = lerpf(0.5f, 0, ease_back_out(s->p));+ CO_YIELD(c);+ }+ if (s->mode == SF_FILTER) {+ CO_WAIT(c, 0.5f);+ for (s->p = 0; s->p < 1; s->p += DT / 0.4f) { /* the filter slides in */+ s->filter = ease_sine_inout(fminf(s->p, 1));+ CO_YIELD(c);+ }+ s->filter = 1;+ }+ s->waiting = 1; /* WaitForInput */+ CO_YIELD(c);+ while (!selfie_confirm()) CO_YIELD(c);+ s->waiting = 0;+ if (s->mode == SF_OPEN) {+ s->done = 1;+ return;+ }+ for (s->p = 0; s->p < 1;) { /* EndRoutine */+ s->p += DT * 2;+ s->pos = v2lerp(v2(960, 540), v2(928, -400), ease_back_in(s->p));+ s->rot = lerpf(0, -0.15f, ease_back_in(s->p));+ CO_YIELD(c);+ }+ CO_YIELD(c);+ s->done = 1;+ ent_remove(e);+ CO_END(c);+}+static void selfie_render(Ent *e) {+ Selfie *s = ST(e, Selfie);+ if (g_level.frozen || g_level.paused || g_level.skipping_cutscene || !s->p) return;+ float x = s->pos.x / 6, y = s->pos.y / 6, h = 800 / 6.f;+ gfx_hud(true);+ Tex t;+ if (tex_get(s->photo, &t)) {+ h = t.fh * t.scale;+ gfx_tex_ex(s->photo, x, y, t.fw * t.scale / 2.f, h / 2, 1, 1, s->rot, 0xFFFF, 255, 0);+ }+ int at = s->filter > 0 && tex_get(T__selfieFilter, &t) ? (int)roundf(t.fw * s->filter) : 0;+ if (at > 0) /* overImage: the filter's right part, as wide as it has come, right edges together */+ gfx_tex_part_ex(T__selfieFilter, x, y, t.fw - at, 0, at, t.fh, at - t.fw / 2.f, t.fh / 2.f, 1, 1, s->rot, 0xFFFF, 255, 0);+ if (s->waiting) {+ float bx = x + h / 2 + 40 / 6.f, by = y + h / 2 + (fmodf(s->timer, 1) < 0.25f ? 1 : 0);+ if (tex_get(T__textboxbutton, &t)) gfx_tex_ex(T__textboxbutton, bx, by, t.fw * t.scale / 2.f, t.fh * t.scale / 2.f, 1, 1, 0, 0xFFFF, 255, 0);+ }+ gfx_hud(false);+}+static const EntClass SELFIE = {.size = sizeof(Selfie), .name = "Selfie", .update = selfie_update, .render = selfie_render};+Ent *ch2_selfie_new(int mode) {+ Ent *e = ent_new(&SELFIE, 0, 0);+ if (!e) return NULL;+ e->tags = TAG_HUD;+ e->collidable = 0;+ ST(e, Selfie)->mode = (uint8_t)mode;+ ST(e, Selfie)->photo = mode == SF_OPEN ? T__selfieGondola : T__selfie;+ return e;+}+/* the routine has run: true while it runs (its entity is kept for an open picture) */+bool ch2_selfie_running(Ent *e) { return e && e->cls == &SELFIE && e->dead != 1 && !ST(e, Selfie)->done; }++/* ---------------------------------------------------------------- Payphone */+typedef struct {+ Sprite spr;+ float flicker, flicker_for, light2;+ int8_t last_frame, blink_x;+ uint8_t light, blink, broken, light2_on;+} Phone;+static const EntClass PAYPHONE;+static void phone_update(Ent *e) {+ Phone *p = ST(e, Phone);+ spr_update(&p->spr);+ if (!p->broken) {+ p->flicker -= DT;+ if (p->flicker <= 0) {+ if (level_on_interval(0.025f)) {+ bool on = rndf() > 0.5f;+ p->light = on, p->blink = !on;+ }+ if (p->flicker < -p->flicker_for) {+ static const float A[4] = {0.4f, 0.6f, 0.8f, 1};+ static const float B[3] = {0.1f, 0.2f, 0.05f};+ p->flicker = A[rndi(4)];+ p->flicker_for = B[rndi(3)];+ p->light = 1, p->blink = 0;+ }+ }+ } else+ p->light = p->blink = 0;+ if (p->spr.anim == A_payphone_eat && p->spr.frame == 5 && p->last_frame != 5) {+ V2 at = v2add(g_level.cam, v2(236, 152));+ particles_emit(PL_FG, &P_Payphone_P_Snow, 10, at, v2(10, 0), P_Payphone_P_Snow.direction);+ particles_emit(PL_FG, &P_Payphone_P_SnowB, 8, at, v2(6, 0), P_Payphone_P_SnowB.direction);+ level_dir_shake(v2(0, 1), 0.3f);+ }+ p->last_frame = (int8_t)p->spr.frame;+}+static void phone_render(Ent *e) {+ Phone *p = ST(e, Phone);+ spr_draw(&p->spr, e->x, e->y);+ if (p->blink) gfx_tex(T_cutscenes_payphone_blink, e->x - 56 + p->blink_x, e->y - 80, 0, 0xFFFF, 255); /* at the sprite's origin */+ if (p->light) {+ light_add(e->x - 6, e->y - 45, 0xFFFFFF, 1, 8, 96); /* a spotlight, downwards */+ bloom_add(e->x - 6, e->y - 45, 0.8f, 8);+ }+ if (p->light2_on) light_add(e->x + 16, e->y - 28, 0xFFFFFF, p->light2, 32, 48);+}+static const EntClass PAYPHONE = {.name = "payphone", .size = sizeof(Phone), .update = phone_update, .render = phone_render};+static void new_payphone(const EData *d) {+ Ent *e = ent_new(&PAYPHONE, d->x, d->y);+ if (!e) return;+ e->depth = 1;+ e->collidable = 0;+ Phone *p = ST(e, Phone);+ spr_init(&p->spr, SB_payphone);+ spr_play(&p->spr, A_payphone_idle, false);+ p->light = 1;+ p->flicker_for = 0.1f;+}++/* ---------------------------------------------------------------- CS02_BadelineIntro */+typedef struct {+ Cutscene cs;+ Ent *bad, *tb;+ V2 end, from, cam_to;+ Step step, cam;+ Co ev;+ float t;+ int8_t evi;+ uint8_t cam_on;+} BIntro;+static bool bintro_event(void *ctx, int index) { /* TurnAround, RevealBadeline, StartLaughing, StopLaughing */+ BIntro *s = ST((Ent *)ctx, BIntro);+ Ent *be = s->bad;+ Chaser *ch = ST(be, Chaser);+ Player *p = &g_player;+ Co *c = ev_start(&s->ev, &s->evi, index);+ switch (index) {+ case 0: {+ EV_BEGIN;+ p->facing = -1;+ EV_WAIT(0.2f);+ step_reset(&s->cam); /* Add(new Coroutine(CameraTo((Bounds.X, Camera.Y), 0.5))) */+ s->cam_to = v2((float)g_level.room->x, g_level.cam.y);+ s->cam_on = 1;+ step_reset(&s->step);+ EV_NEST(zoom_to(&s->step, v2(84, 135), 2, 0.5f));+ EV_WAIT(0.2f);+ EV_END;+ }+ case 1: {+ EV_BEGIN;+ EV_WAIT(0.1f);+ EV_WAIT(0.1f); /* (the displacement burst: no distortion here) */+ ch->hovering = 1, ch->hair_visible = 1;+ spr_play(&ch->spr, A_badeline_fallSlow, false);+ s->from = v2(be->x, be->y);+ for (s->t = 0; s->t < 1; s->t += DT) {+ V2 at = v2lerp(s->from, s->end, ease_cube_inout(s->t));+ be->x = at.x, be->y = at.y;+ EV_YIELD;+ }+ p->facing = (int)signf(be->x - p->ent->x);+ EV_WAIT(1);+ EV_END;+ }+ case 2: {+ EV_BEGIN;+ EV_WAIT(0.2f);+ spr_play(&ch->spr, A_badeline_laugh, true);+ EV_YIELD;+ EV_END;+ }+ default: {+ EV_BEGIN;+ spr_play(&ch->spr, A_badeline_fallSlow, true);+ EV_YIELD;+ EV_END;+ }+ }+}+static void bintro_end(Ent *e, bool skipped) { /* OnEnd */+ (void)skipped;+ BIntro *s = ST(e, BIntro);+ Player *p = level_player();+ if (p) {+ p->state_locked = false;+ p->facing = -1;+ player_set_state(p, ST_NORMAL);+ p->just_respawned = true;+ }+ Ent *be = s->bad;+ Chaser *c = ST(be, Chaser);+ be->x = s->end.x, be->y = s->end.y;+ be->visible = 1;+ c->hair_visible = 1;+ spr_play(&c->spr, A_badeline_fallSlow, false);+ c->hovering = 0;+ chaser_start_chasing(be);+ level_set_flag("evil_maddy_intro", true);+}+static void bintro_update(Ent *e) {+ BIntro *s = ST(e, BIntro);+ if (s->cam_on && !camera_to(&s->cam, s->cam_to, 0.5f, NULL)) s->cam_on = 0;+ Player *p = level_player();+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ while (!p) {+ CO_YIELD(c);+ p = level_player();+ }+ while (!actor_on_ground(p->ent, 1)) CO_YIELD(c);+ player_set_state(p, ST_DUMMY);+ p->state_locked = true;+ CO_WAIT(c, 1);+ s->evi = -1;+ CO_SAY(c, s->tb, "CH2_BADELINE_INTRO", bintro_event, e);+ step_reset(&s->step);+ CO_NEST(c, zoom_back(&s->step, 0.5f));+ cutscene_end(e);+ return;+ CO_END(c);+}+static const EntClass BINTRO = {.size = sizeof(BIntro), .name = "CS02_BadelineIntro", .update = bintro_update};+static void bintro_start(Ent *bad, V2 end) {+ Ent *e = ent_new(&BINTRO, 0, 0);+ if (!e) return;+ e->collidable = 0, e->visible = 0;+ BIntro *s = ST(e, BIntro);+ s->bad = bad;+ s->end = end;+ cutscene_start(e, bintro_end, true, false);+}++/* ---------------------------------------------------------------- CS02_DreamingPhonecall, CS02_Ending */+typedef struct {+ Cutscene cs;+ Ent *phone, *tb, *evil;+ Walk walk;+ Step step;+ Co ev;+ V2 wire_speed;+ float light, t, wire_wait;+ int8_t evi;+ uint8_t wire_on, end;+} Call;+static bool call_event(void *ctx, int index) { /* ShowShadowMadeline */+ (void)index;+ Call *s = ST((Ent *)ctx, Call);+ Phone *ph = ST(s->phone, Phone);+ Co *c = ev_start(&s->ev, &s->evi, 0);+ EV_BEGIN;+ step_reset(&s->step);+ EV_NEST(zoom_to(&s->step, v2(240, 116), 2, 0.5f));+ s->evil = ch2_bdummy_new(v2add(v2(s->phone->x, s->phone->y), v2(32, -24)));+ if (s->evil) ch2_bdummy_appear(s->evil);+ EV_WAIT(0.2f);+ ph->blink_x++;+ spr_play(&ph->spr, A_payphone_jumpBack, false);+ EV_NEST(spr_playing(&ph->spr, A_payphone_jumpBack));+ spr_play(&ph->spr, A_payphone_scare, false);+ EV_NEST(spr_playing(&ph->spr, A_payphone_scare));+ EV_WAIT(1.2f);+ EV_END;+}+static void call_wire(Call *s) { /* WireFalls */+ if (s->wire_wait > 0) {+ s->wire_wait -= DT;+ return;+ }+ Ent *w = NULL;+ for (int i = 0; i < g_nents && !w; i++)+ if (g_ents[i].cls && g_ents[i].dead != 1 && g_ents[i].cls->name && !strcmp(g_ents[i].cls->name, "wire")) w = &g_ents[i];+ V2 *b = w ? wire_curve_begin(w) : NULL;+ if (!b || b->x >= g_level.room->x + g_level.room->w) {+ s->wire_on = 0;+ return;+ }+ s->wire_speed = v2add(s->wire_speed, v2mul(v2(0.7f, 1), 200 * DT));+ *b = v2add(*b, v2mul(s->wire_speed, DT));+}+static Ent *call_wiping;+static void call_wiped(void) { /* the FadeWipe's end: EndCutscene(level) */+ if (call_wiping && call_wiping->cls) cutscene_end(call_wiping);+ call_wiping = NULL;+}+static void call_end(Ent *e, bool skipped) {+ (void)skipped;+ Call *s = ST(e, Call);+ if (s->end) { /* CS02_Ending */+ level_complete_area(true, false);+ return;+ }+ zoom_reset();+ g_session.dreaming = 0;+ int r = chapter_find_room(g_session.chapter, "end_0");+ if (r >= 0) level_load_room(r, INTRO_WAKEUP);+ g_level.in_cutscene = false;+}+static void call_update(Ent *e) {+ Call *s = ST(e, Call);+ Ent *pe = s->phone;+ Phone *ph = ST(pe, Phone);+ Player *p = &g_player;+ if (s->wire_on) call_wire(s);+ if (ph->light2_on == 1 && (ph->light2 += DT / 2) >= 1) ph->light2 = 1, ph->light2_on = 2; /* its Tween */+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_set_state(p, ST_DUMMY);+ p->dashes = 1;+ if (!s->end) CO_WAIT(c, 0.3f);+ for (s->light = 1; s->light > 0;) { /* the player's light fades */+ s->light -= DT * (s->end ? 1.25f : 2);+ CO_YIELD(c);+ }+ if (s->end) { /* CS02_Ending */+ CO_WAIT(c, 1);+ s->walk = walk_to(pe->x - 4);+ CO_NEST(c, player_walk(p, &s->walk));+ CO_WAIT(c, 0.2f);+ p->facing = 1;+ CO_WAIT(c, 0.5f);+ p->ent->visible = 0;+ spr_play(&ph->spr, A_payphone_pickUp, false);+ CO_NEST(c, spr_playing(&ph->spr, A_payphone_pickUp));+ CO_WAIT(c, 0.25f);+ CO_WAIT(c, 6);+ spr_play(&ph->spr, A_payphone_talkPhone, false);+ CO_SAY(c, s->tb, "CH2_END_PHONECALL", NULL, NULL);+ CO_WAIT(c, 0.3f);+ cutscene_end(e);+ return;+ }+ CO_WAIT(c, 3.2f);+ s->walk = walk_to(pe->x - 24);+ CO_NEST(c, player_walk(p, &s->walk));+ CO_WAIT(c, 1.5f);+ p->facing = -1;+ CO_WAIT(c, 1.5f);+ p->facing = 1;+ CO_WAIT(c, 0.25f);+ s->walk = walk_to(pe->x - 4);+ CO_NEST(c, player_walk(p, &s->walk));+ CO_WAIT(c, 1.5f);+ p->ent->visible = 0;+ spr_play(&ph->spr, A_payphone_pickUp, false);+ CO_NEST(c, spr_playing(&ph->spr, A_payphone_pickUp));+ CO_WAIT(c, 1);+ spr_play(&ph->spr, A_payphone_talkPhone, false);+ s->evi = -1;+ CO_SAY(c, s->tb, "CH2_DREAM_PHONECALL", call_event, e);+ if (s->evil) {+ ch2_bdummy_vanish(s->evil);+ s->evil = NULL;+ CO_WAIT(c, 1);+ }+ s->wire_on = 1, s->wire_wait = 0.5f;+ ph->broken = 1;+ level_shake(0.2f);+ ph->light2_on = 1, ph->light2 = 0;+ spr_play(&ph->spr, A_payphone_transform, false);+ CO_NEST(c, spr_playing(&ph->spr, A_payphone_transform));+ CO_WAIT(c, 0.4f);+ spr_play(&ph->spr, A_payphone_eat, false);+ CO_NEST(c, spr_playing(&ph->spr, A_payphone_eat));+ spr_play(&ph->spr, A_payphone_monsterIdle, false);+ CO_WAIT(c, 1.2f);+ g_level.in_cutscene = false; /* level.EndCutscene(), then the wipe ends this one */+ call_wiping = e;+ wipe_start(WIPE_FADE, false, call_wiped);+ for (;;) CO_YIELD(c);+ CO_END(c);+}+static const EntClass CALL = {.size = sizeof(Call), .name = "CS02_DreamingPhonecall", .update = call_update};++/* ---------------------------------------------------------------- CS02_Journal and its PoemPage */+/* The pages (PoemPage here, CS03_Memo's MemoPage: ch2_page_new): GFX.Gui's poempage, memo/memo and+ * memo/title are not packed, so a page of their color (855 x 580, and 624 x 920 x 1.5 interface pixels)+ * with the text at the font's size (FancyText's 0.7 and 0.75 scales are not drawn); their rotation neither */+typedef struct { V2 pos; float alpha, h; uint8_t out; } PageCtl; /* what the cutscenes move (ch3.c too) */+#define PAGE_N 640+typedef struct {+ PageCtl c;+ float timer, tx, ty, tw, maxw, widest; /* where its text goes (its layer reads them) */+ int16_t n;+ uint8_t memo, loaded, ta;+ char txt[PAGE_N];+} Page;+static float page_line(const Page *g, int at, int *end, float maxw) { /* the words of a line that fit */+ float w = 0;+ int i = at, last = -1;+ while (i < g->n && g->txt[i] != '\n') {+ int j = i;+ while (j < g->n && g->txt[j] != ' ' && g->txt[j] != '\n') j++;+ float ww = font_measure(g->txt + at, j - at, FONT_S);+ if (ww > maxw && last >= 0) break;+ w = ww, last = j, i = j;+ if (i < g->n && g->txt[i] == ' ') i++;+ }+ *end = last >= 0 ? last : i;+ return w;+}+void ch1_glyph(uint16_t *strip, int sy0, int sy1, uint32_t ch, float x, float top, bool flip, uint16_t col, uint8_t alpha);+/* the text, a layer of its own (one command for all its glyphs) */+static void page_text(uint16_t *strip, int sy0, int sy1, void *ctx) {+ Page *g = ctx;+ float ly = g->ty, lh = font_line_height(FONT_S);+ for (int i = 0, end; i < g->n; i = end + 1, ly += lh) {+ float lw = page_line(g, i, &end, g->maxw);+ while (i < end && g->txt[i] == ' ') i++;+ if (ly + lh < sy0 || ly >= sy1) continue;+ float x = g->tx + g->tw / 2 - (g->memo ? g->widest : lw) / 2;+ for (const char *p = g->txt + i, *q = g->txt + end; p < q;) {+ uint32_t c = utf8_next(&p, q);+ const char *t = p;+ ch1_glyph(strip, sy0, sy1, c, x, ly, false, 0, g->ta);+ x += font_glyph_advance(FONT_S, c, p < q ? utf8_next(&t, q) : 0);+ }+ }+}+static void page_update(Ent *e) {+ Page *g = ST(e, Page);+ g->timer += DT;+ if (!g->loaded) g->loaded = 1, g->n = (int16_t)ch1_clean_lines(g->memo ? "CH3_MEMO" : "CH2_POEM", g->txt, PAGE_N);+}+static void page_render(Ent *e) {+ Page *g = ST(e, Page);+ if (g_level.frozen || g_level.paused || g_level.skipping_cutscene || g->c.alpha <= 0 || !g->loaded) return;+ uint8_t a = (uint8_t)(clampf(g->c.alpha, 0, 1) * 255);+ float w = g->memo ? 936 / 6.f : 855 / 6.f, h = g->memo ? 1380 / 6.f : 580 / 6.f;+ float x = g->c.pos.x / 6 - w / 2, y = g->c.pos.y / 6 - (g->memo ? 0 : h / 2); /* origin: (w / 2, 0) or the middle */+ float maxw = g->memo ? (936 - 120) / 6.f : (855 - 120) / 6.f, lh = font_line_height(FONT_S);+ int lines = 0;+ float widest = 0;+ for (int i = 0, end; i < g->n; i = end + 1, lines++) widest = fmaxf(widest, page_line(g, i, &end, maxw));+ if (g->memo) h = fmaxf(h, 210 / 6.f + lines * lh + 20); /* (the text at its full size takes more room) */+ g->c.h = h;+ gfx_hud(true);+ gfx_rect(x, y, w, h, g->memo ? rgb(0xE4DAC5) : rgb(0xDED1C9), a);+ /* the poem: DrawJustifyPerLine in the middle; the memo: Draw at (w / 2, 210) justified (0.5, 0) */+ g->ty = g->memo ? y + 210 / 6.f : y + h / 2 - lines * lh / 2;+ g->tx = x, g->tw = w, g->maxw = maxw, g->widest = widest, g->ta = (uint8_t)(a * 0.6f);+ gfx_custom(page_text, g, (int)g->ty - 2, (int)(g->ty + lines * lh) + 2);+ if (!g->c.out) {+ Tex t;+ float bx = x + w + 40 / 6.f, by = y + h + (fmodf(g->timer, 1) < 0.25f ? 1 : 0);+ if (tex_get(T__textboxbutton, &t)) gfx_tex_ex(T__textboxbutton, bx, by, t.fw * t.scale / 2.f, t.fh * t.scale / 2.f, 1, 1, 0, 0xFFFF, 255, 0);+ }+ gfx_hud(false);+}+static const EntClass PAGE = {.size = sizeof(Page), .name = "PoemPage", .update = page_update, .render = page_render};+Ent *ch2_page_new(bool memo) {+ Ent *e = ent_new(&PAGE, 0, 0);+ if (!e) return NULL;+ e->tags = TAG_HUD;+ e->collidable = 0;+ ST(e, Page)->memo = memo;+ return e;+}+typedef struct { Cutscene cs; Ent *tb, *page; float p; V2 from; } Journal;+static void journal_end(Ent *e, bool skipped) {+ (void)skipped;+ Journal *s = ST(e, Journal);+ Player *p = level_player();+ if (p) p->state_locked = false, player_set_state(p, ST_NORMAL);+ level_set_flag("poem_read", true);+ if (s->page && s->page->cls == &PAGE) ent_remove(s->page);+}+static void journal_update(Ent *e) {+ Journal *s = ST(e, Journal);+ Player *p = &g_player;+ PageCtl *pg = s->page && s->page->cls == &PAGE ? ST(s->page, PageCtl) : NULL;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_set_state(p, ST_DUMMY);+ p->state_locked = true;+ if (!level_get_flag("poem_read")) {+ CO_SAY(c, s->tb, "ch2_journal", NULL, NULL);+ CO_WAIT(c, 0.1f);+ }+ s->page = ch2_page_new(false);+ if (!s->page) goto done;+ CO_YIELD(c);+ for (s->p = 0; s->p < 1; s->p += DT) { /* EaseIn (its rotation, -0.1 to 0.05, is not drawn) */+ pg->pos = v2lerp(v2(960, 740), v2(960, 540), ease_cube_out(s->p));+ pg->alpha = ease_cube_out(s->p);+ CO_YIELD(c);+ }+ while (!btn_pressed(&g_in.confirm) && !btn_pressed(&g_in.jump) && !btn_pressed(&g_in.dash)) CO_YIELD(c);+ pg->out = 1; /* EaseOut */+ s->from = pg->pos;+ for (s->p = 0; s->p < 1; s->p += DT * 1.5f) {+ pg->pos = v2lerp(s->from, v2(960, 340), ease_cube_in(s->p));+ pg->alpha = 1 - ease_cube_in(s->p);+ CO_YIELD(c);+ }+ ent_remove(s->page);+ s->page = NULL;+done:+ cutscene_end(e);+ return;+ CO_END(c);+}+static const EntClass JOURNAL = {.size = sizeof(Journal), .name = "CS02_Journal", .update = journal_update};+static void journal_start(Ent *trig, Player *p) {+ (void)trig, (void)p;+ Ent *e = ent_new(&JOURNAL, 0, 0);+ if (e) e->collidable = 0, e->visible = 0, cutscene_start(e, journal_end, true, false);+}++/* ---------------------------------------------------------------- NPC02_Theo */+typedef struct {+ Talk talk;+ Sprite spr;+ uint8_t has_talk;+} Theo2;+typedef struct {+ Cutscene cs;+ Ent *theo, *tb, *selfie;+ NpcWalk nw;+ Co ev;+ int8_t evi, conv, intro;+} Theo2Talk;+static bool theo2_event(void *ctx, int index) { /* ShowPhotos, HidePhotos, Selfie, PlayerApproach48px / SelfieFiltered */+ Theo2Talk *s = ST((Ent *)ctx, Theo2Talk);+ Ent *te = s->theo;+ Theo2 *t = ST(te, Theo2);+ Co *c = ev_start(&s->ev, &s->evi, index);+ if (s->conv == 1) index = 4; /* CH2_THEO_B: SelfieFiltered */+ switch (index) {+ case 0: {+ EV_BEGIN;+ EV_NEST(npc_approach(&s->nw, te, &t->spr, 10, 0));+ spr_play(&t->spr, A_theo_getPhone, false);+ EV_WAIT(2);+ EV_END;+ }+ case 1: {+ EV_BEGIN;+ spr_play(&t->spr, A_theo_idle, false);+ EV_WAIT(0.5f);+ EV_END;+ }+ case 2: {+ EV_BEGIN;+ EV_WAIT(0.5f);+ t->spr.sx = -t->spr.sx;+ spr_play(&t->spr, A_theo_takeSelfie, false);+ EV_WAIT(1);+ s->selfie = ch2_selfie_new(SF_PICTURE);+ EV_NEST(ch2_selfie_running(s->selfie));+ s->selfie = NULL;+ t->spr.sx = -t->spr.sx;+ EV_END;+ }+ case 3: {+ EV_BEGIN;+ EV_NEST(npc_approach(&s->nw, te, &t->spr, 48, 0));+ EV_END;+ }+ default: {+ EV_BEGIN;+ s->selfie = ch2_selfie_new(SF_FILTER);+ EV_NEST(ch2_selfie_running(s->selfie));+ s->selfie = NULL;+ EV_END;+ }+ }+}+static void theo2_talk_end(Ent *e, bool skipped) { /* OnTalkEnd */+ Theo2Talk *s = ST(e, Theo2Talk);+ Ent *te = s->theo;+ Theo2 *t = ST(te, Theo2);+ int conv = ch1_counter("theo");+ if (conv == 4) {+ level_set_flag("theoDoneTalking", true);+ if (t->has_talk) t->has_talk = 0, ch1_talk_remove(te);+ }+ Player *p = level_player();+ if (p) {+ p->state_locked = false;+ player_set_state(p, ST_NORMAL);+ if (skipped) p->ent->x = (float)(int)(te->x + 48), p->facing = -1;+ }+ t->spr.sx = 1;+ if (s->selfie && s->selfie->cls == &SELFIE) ent_remove(s->selfie);+ ch1_set_counter("theo", conv + 1);+}+static void theo2_talk_update(Ent *e) { /* Talk */+ static const char *const KEYS[5] = {NULL, "CH2_THEO_B", "CH2_THEO_C", "CH2_THEO_D", "CH2_THEO_E"};+ Theo2Talk *s = ST(e, Theo2Talk);+ Ent *te = s->theo;+ Theo2 *t = ST(te, Theo2);+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ s->evi = -1;+ s->conv = (int8_t)ch1_counter("theo");+ if (!save_flag(0) || !save_flag(1)) {+ s->intro = !save_flag(0) ? 0 : 1;+ level_set_flag("hadntMetTheoAtStart", true);+ save_set_flag(s->intro);+ CO_NEST(c, npc_approach(&s->nw, te, &t->spr, 48, 1));+ CO_SAY(c, s->tb, s->intro ? "CH2_THEO_INTRO_NEVER_INTRODUCED" : "CH2_THEO_INTRO_NEVER_MET", NULL, NULL);+ } else if (s->conv <= 0) {+ s->conv = 0;+ CO_NEST(c, npc_approach(&s->nw, te, &t->spr, 0, 1));+ CO_WAIT(c, 0.2f);+ if (level_get_flag("hadntMetTheoAtStart")) {+ CO_NEST(c, npc_approach(&s->nw, te, &t->spr, 48, 0));+ CO_SAY(c, s->tb, "CH2_THEO_A", theo2_event, e);+ } else+ CO_SAY(c, s->tb, "CH2_THEO_A_EXT", theo2_event, e);+ } else if (s->conv <= 4) {+ CO_NEST(c, npc_approach(&s->nw, te, &t->spr, 48, 1));+ CO_SAY(c, s->tb, KEYS[s->conv], theo2_event, e);+ }+ cutscene_end(e);+ return;+ CO_END(c);+}+static const EntClass THEO2TALK = {.size = sizeof(Theo2Talk), .name = "NPC02_Theo.Talk", .update = theo2_talk_update};+static void theo2_update(Ent *e) {+ Theo2 *t = ST(e, Theo2);+ spr_update(&t->spr);+ if (t->has_talk && talk_update(&t->talk, e)) { /* OnTalk */+ if (!save_flag(0) || !save_flag(1)) ch1_set_counter("theo", -1);+ Ent *c = ent_new(&THEO2TALK, 0, 0);+ if (!c) return;+ c->collidable = 0, c->visible = 0;+ ST(c, Theo2Talk)->theo = e;+ cutscene_start(c, theo2_talk_end, true, false);+ }+}+static void theo2_render(Ent *e) { draw_npc(&ST(e, Theo2)->spr, e->x, e->y); }+static const EntClass THEO2 = {.size = sizeof(Theo2), .name = "NPC02_Theo", .update = theo2_update, .render = theo2_render};+static void new_theo2(const EData *d) {+ Ent *e = ent_new(&THEO2, d->x, d->y);+ if (!e) return;+ e->depth = 1000;+ ent_box(e, 8, 8, -4, -8);+ Theo2 *t = ST(e, Theo2);+ spr_init(&t->spr, SB_theo);+ spr_play(&t->spr, A_theo_idle, false);+ if (!level_get_flag("theoDoneTalking")) t->has_talk = 1, ch1_talk_add(e, &t->talk, -20, -8, 100, 8, v2(0, -24));+}++/* ---------------------------------------------------------------- triggers */+/* EventTrigger: the chapter's two endings */+typedef struct { uint8_t which, triggered; } Event;+static void event_enter(Ent *e, Player *p) {+ (void)p;+ Event *ev = ST(e, Event);+ if (ev->triggered) return;+ ev->triggered = 1;+ Ent *ph = find_class(&PAYPHONE);+ Ent *c = ph ? ent_new(&CALL, 0, 0) : NULL;+ if (!c) return;+ c->collidable = 0, c->visible = 0;+ Call *s = ST(c, Call);+ s->phone = ph;+ s->end = ev->which == 2;+ if (s->end) level_register_complete(); /* CS02_Ending.OnBegin */+ cutscene_start(c, call_end, false, s->end);+}+static const EntClass EVENTTRIG = {.name = "eventTrigger", .size = sizeof(Event), .on_enter = event_enter, .kind = KIND_TRIGGER};++/* InteractTrigger: talk to read something (ch2_interact_new: chapter 3's too) */+typedef struct { Talk talk; void (*on_talk)(Ent *e, Player *p); } Interact;+static void interact_update(Ent *e) {+ Interact *it = ST(e, Interact);+ Player *p = level_player();+ if (talk_update(&it->talk, e) && p && it->on_talk) it->on_talk(e, p);+}+static const EntClass INTERACT = {.name = "interactTrigger", .size = sizeof(Interact), .update = interact_update};+void ch2_interact_new(const EData *d, void (*on_talk)(Ent *e, Player *p)) {+ Ent *e = ent_new(&INTERACT, d->x, d->y);+ if (!e) return;+ float w = EA(d, interactTrigger, width), h = EA(d, interactTrigger, height);+ ent_box(e, w, h, 0, 0);+ e->visible = 0;+ Interact *it = ST(e, Interact);+ ch1_talk_add(e, &it->talk, 0, 0, (int)w, (int)h, d->nnodes ? v2sub(ed_node(d, 0), v2(d->x, d->y)) : v2(w / 2, 0));+ it->talk.must_face = false;+ it->on_talk = on_talk;+}+++/* RespawnTargetTrigger: where the respawn point goes when a transition ends inside it */+typedef struct { V2 target; uint8_t was_transitioning; } RespawnTarget;+static void rtarget_update(Ent *e) {+ RespawnTarget *r = ST(e, RespawnTarget);+ if (r->was_transitioning && !g_level.transitioning) { /* Level.TransitionRoutine's end */+ Ent *p = level_player_ent();+ if (p && collide_ent_at(p, p->x, p->y, e)) {+ V2 s = level_closest_spawn(r->target);+ g_session.rx = (int32_t)s.x, g_session.ry = (int32_t)s.y;+ }+ }+ r->was_transitioning = g_level.transitioning;+}+static const EntClass RTARGET = {.name = "respawnTargetTrigger", .size = sizeof(RespawnTarget), .update = rtarget_update};++/* ---------------------------------------------------------------- the factories */+bool ents_ch2(const EData *d) {+ switch (d->type) {+ case ET_dreamBlock: new_dreamblock(d); return true;+ case ET_darkChaser: new_chaser(d); return true;+ case ET_touchSwitch: new_touchswitch(d); return true;+ case ET_switchGate: new_switchgate(d); return true;+ case ET_hanginglamp: new_lamp(d); return true;+ case ET_floatingDebris: new_fdebris(d); return true;+ case ET_foregroundDebris: new_fgdebris(d); return true;+ case ET_invisibleBarrier: new_barrier(d, EA(d, invisibleBarrier, width), EA(d, invisibleBarrier, height)); return true;+ case ET_payphone: new_payphone(d); return true;+ case ET_towerviewer: new_lookout(d); return true;+ case ET_dreammirror: new_mirror(d); return true;+ case ET_npc:+ if (strcmp(EAS(d, npc, npc), "theo_02_campfire")) return false;+ new_theo2(d);+ return true;+ }+ return false;+}++bool trigs_ch2(const EData *d) {+ switch (d->type) {+ case TT_eventTrigger: {+ const char *ev = EAS(d, eventTrigger, event);+ int which = !strcmp(ev, "end_oldsite_dream") ? 1 : !strcmp(ev, "end_oldsite_awake") ? 2 : 0;+ if (!which) return false; /* other chapters' events */+ Ent *e = ent_new(&EVENTTRIG, d->x, d->y);+ if (e) ent_box(e, EA(d, eventTrigger, width), EA(d, eventTrigger, height), 0, 0), e->visible = 0, ST(e, Event)->which = (uint8_t)which;+ return true;+ }+ case TT_interactTrigger:+ if (strcmp(EAS(d, interactTrigger, event), "ch2_poem")) return false;+ ch2_interact_new(d, journal_start);+ return true;+ case TT_respawnTargetTrigger: {+ Ent *e = ent_new(&RTARGET, d->x, d->y);+ if (!e) return true;+ ent_box(e, EA(d, respawnTargetTrigger, width), EA(d, respawnTargetTrigger, height), 0, 0);+ e->visible = 0;+ e->tags = TAG_TRANSITION_UPDATE;+ ST(e, RespawnTarget)->target = ed_node(d, 0);+ return true;+ }+ }+ return false;+}++/* this chapter's tables: in the memory it is given while it is played (res_chapter_ram) */+uint32_t ch2_ram(void) { return g_session.area == 2 ? END_chase_flags : END_debris_px; } /* the chasers: Old Site's */diff --git a/games/celeste/src/ch3.c b/games/celeste/src/ch3.cnew file mode 100644index 00000000..7c89967f--- /dev/null+++ b/games/celeste/src/ch3.c@@ -0,0 +1,4346 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* Celestial Resort (chapter 3), ported from the game's classes: the clutter+ * (ClutterBlockBase, ClutterBlock and its generator, ClutterSwitch,+ * ClutterDoor, ClutterCabinet, ClutterAbsorbEffect), resort lanterns,+ * cobwebs, trigger spikes (dust tendrils), doors, trapdoors, sinking and+ * moving platforms, clotheslines, water and waterfalls, Oshiro the boss+ * (AngryOshiro) and his door, the resort mirror, the PICO-8 console, keys+ * and lock blocks, block fields, the roof's end, kill boxes, and the light+ * and bloom triggers. The story: Oshiro (NPC03_Oshiro_*, OshiroSprite, OshiroLobbyBell) and his+ * cutscenes (CS03_OshiroLobby, Hallway1 and 2, Clutter, Breakdown, MasterSuite, Rooftop), Theo+ * (NPC03_Theo_Escaping and _Vents, CS03_TheoEscape), the memo, diary and guestbook, and the ending+ * (CS03_Ending). */+#include <stdlib.h>+#include "npc.h"+#include "talk.h"++/* the story's shared pieces (ch1.c, ch2.c) */+void ch1_talk_add(Ent *owner, Talk *t, int x, int y, int w, int h, V2 draw_at);+void ch1_talk_remove(Ent *owner);+int ch1_counter(const char *name);+void ch1_set_counter(const char *name, int v);+void ch1_flash(uint32_t color);+bool save_flag(int bit);+void save_set_flag(int bit);+bool textbox_portrait(int *bank, int *idle);+typedef struct { V2 target; float speed, alpha; int8_t turn; uint8_t step, flags, pad; } Move;+enum { MV_FADEIN = 1, MV_REMOVE = 2, MV_NOY = 4, MV_TURN = 8 };+bool ch1_move_to(Ent *e, Sprite *s, Move *m, float maxspeed, int move_anim, int idle_anim);+Ent *ch2_bdummy_new(V2 at);+void ch2_bdummy_appear(Ent *e);+void ch2_bdummy_vanish(Ent *e);+void ch2_bdummy_face(Ent *e, int f);+void ch2_bdummy_clip(Ent *e, float x0, float y0, float x1, float y1, float alpha);+enum { BD_TURN = 1, BD_NOFACE = 2, BD_FADELIGHT = 4, BD_QUICKEND = 8 };+bool ch2_bdummy_float_to(Ent *e, V2 target, int turn, int flags);+bool ch2_bdummy_walk_to(Ent *e, float x, float speed);+bool ch2_bdummy_smash(Ent *e, V2 target);+void ch2_interact_new(const EData *d, void (*on_talk)(Ent *e, Player *p));+typedef struct { V2 pos; float alpha, h; uint8_t out; } PageCtl;+Ent *ch2_page_new(bool memo);++/* ---------------------------------------------------------------- the story's helpers */+#define EV_BEGIN \+ if (c->wait > 0) { \+ c->wait -= DT; \+ return false; \+ } \+ switch (c->co) { \+ case 0:+#define EV_YIELD_(n) \+ do { \+ c->co = (n); \+ return false; \+ case (n):; \+ } while (0)+#define EV_YIELD EV_YIELD_(__COUNTER__ + 1)+#define EV_WAIT(t) \+ do { \+ c->wait = (t); \+ EV_YIELD; \+ } while (0)+#define EV_NEST(call) \+ do { \+ EV_YIELD; \+ while (call) EV_YIELD; \+ EV_YIELD; \+ } while (0)+#define EV_END \+ default:; \+ } \+ return true+static Co *ev_start(Co *c, int8_t *at, int index) {+ if (*at != index) *at = (int8_t)index, memset(c, 0, sizeof *c);+ return c;+}+static void draw_npc(const Sprite *spr, float x, float y) { /* Scale.X turns it */+ Sprite s = *spr;+ s.flipx = s.sx < 0;+ s.sx = fabsf(s.sx);+ spr_draw(&s, x, y);+}+static void set_depth(Ent *e, int d) {+ if (e->depth != d) e->depth = d, ents_mark_unsorted();+}+static Ent *cs_new(const EntClass *cls, void (*on_end)(Ent *e, bool skipped), bool fade_in, bool ending) {+ Ent *e = ent_new(cls, 0, 0);+ if (!e) return NULL;+ e->collidable = 0, e->visible = 0;+ cutscene_start(e, on_end, fade_in, ending);+ return e;+}+static void player_free(void) { /* StateMachine.Locked = false, State = 0 */+ Player *p = level_player();+ if (p) p->state_locked = false, player_set_state(p, ST_NORMAL);+}+static void player_hold(Player *p) { /* State = 11, Locked */+ player_set_state(p, ST_DUMMY);+ p->state_locked = true;+}+/* CutsceneEntity.CameraTo / PanCamera's x only: from where the camera is, eased */+typedef struct { V2 from; float p; } Pan;+static bool pan_to(Pan *s, V2 to, float duration, float (*ease)(float), bool x_only) {+ if (s->p < 0) s->from = g_level.cam, s->p = 0;+ float k = ease(fminf(s->p, 1));+ g_level.cam.x = lerpf(s->from.x, to.x, k);+ if (!x_only) g_level.cam.y = lerpf(s->from.y, to.y, k);+ if (s->p >= 1) return false;+ s->p += DT / duration;+ return true;+}+++/* ---------------------------------------------------------------- helpers */+static uint16_t tex(const char *p) { return res_tex_by_name(p); }+static float shake_val(void) { /* Calc.Random.ShakeVector */+ static const int8_t o[5] = {-1, -1, 0, 1, 1};+ return o[rndi(5)];+}+static const Room *room_ptr(const Ent *e) { return &g_level.rooms[e->room]; }+static int16_t ent_ref(const Ent *e) { return e ? (int16_t)(e - g_ents) : -1; }+static Ent *ent_at(int16_t i, const EntClass *cls) { return i >= 0 && g_ents[i].cls == cls && g_ents[i].dead != 1 ? &g_ents[i] : NULL; }+static float quad_curve(float a, float c, float b, float t) { return (1 - t) * (1 - t) * a + 2 * (1 - t) * t * c + t * t * b; }+static V2 curve_point(V2 a, V2 b, V2 c, float t) { return v2(quad_curve(a.x, c.x, b.x, t), quad_curve(a.y, c.y, b.y, t)); }+static uint32_t hash32(uint32_t x) {+ x ^= x >> 16, x *= 0x7feb352du, x ^= x >> 15, x *= 0x846ca68bu, x ^= x >> 16;+ return x;+}+static float hashf(uint32_t x) { return (hash32(x) >> 8) * (1.f / 16777216.f); }++/* drawing straight into a strip (gfx_custom layers): view coordinates */+static inline void sp_plot(uint16_t *strip, int sy0, int sy1, int x, int y, uint16_t c, int a) {+ if (y < sy0 || y >= sy1 || (unsigned)x >= VIEW_W) return;+ uint16_t *d = strip + (y - sy0) * VIEW_W + x;+ *d = a >= 256 ? c : blend565(*d, scale565(c, a), a);+}+static void sp_rect(uint16_t *strip, int sy0, int sy1, int x, int y, int w, int h, uint16_t c, int a) {+ int x0 = x < 0 ? 0 : x, x1 = x + w > VIEW_W ? VIEW_W : x + w;+ int y0 = y < sy0 ? sy0 : y, y1 = y + h > sy1 ? sy1 : y + h;+ if (x0 >= x1 || y0 >= y1 || a <= 0) return;+ uint16_t pc = a >= 256 ? c : scale565(c, a);+ for (int r = y0; r < y1; r++) {+ uint16_t *d = strip + (r - sy0) * VIEW_W + x0;+ if (a >= 256)+ for (int i = x0; i < x1; i++) *d++ = c;+ else+ for (int i = x0; i < x1; i++, d++) *d = blend565(*d, pc, a);+ }+}+static void sp_line(uint16_t *strip, int sy0, int sy1, int x0, int y0, int x1, int y1, uint16_t c, int a) {+ if ((y0 < sy0 && y1 < sy0) || (y0 >= sy1 && y1 >= sy1)) return;+ int dx = abs(x1 - x0), dy = -abs(y1 - y0), sx = x0 < x1 ? 1 : -1, sy = y0 < y1 ? 1 : -1, err = dx + dy;+ for (int guard = 0; guard < 2048; guard++) {+ sp_plot(strip, sy0, sy1, x0, y0, c, a);+ if (x0 == x1 && y0 == y1) break;+ int e2 = 2 * err;+ if (e2 >= dy) err += dy, x0 += sx;+ if (e2 <= dx) err += dx, y0 += sy;+ }+}+static inline int vx(float x) { return (int)floorf(x + 0.5f) - g_camx; }+static inline int vy(float y) { return (int)floorf(y + 0.5f) - g_camy; }+/* the file's memory (g_chram[3]): what other chapters' maps use first (the water's rows, the trigger spikes), then+ * the Celestial Resort's own (its clutter) */+enum { OFF_rowbuf = 0, END_rowbuf = OFF_rowbuf + (int)sizeof(uint8_t[256]) };+#define rowbuf (*(uint8_t(*)[256])(void *)(g_chram[3] + OFF_rowbuf))+#define TSPIKES 600+enum { OFF_ts_lerp = ((END_rowbuf + 7) & ~7), END_ts_lerp = OFF_ts_lerp + (int)sizeof(uint8_t[TSPIKES]) };+#define ts_lerp (*(uint8_t(*)[TSPIKES])(void *)(g_chram[3] + OFF_ts_lerp))+enum { OFF_ts_state = ((END_ts_lerp + 7) & ~7), END_ts_state = OFF_ts_state + (int)sizeof(uint8_t[TSPIKES]) };+#define ts_state (*(uint8_t(*)[TSPIKES])(void *)(g_chram[3] + OFF_ts_state))+static void tex_row_idx(const Tex *t, int r, uint8_t *out) { tex_row(t, r, out); }+static inline void sp_texel(uint16_t *d, const uint16_t *col, const uint8_t *al, uint8_t v, uint16_t tint, int ga, bool sil) {+ int aa = al[v - 1] + (al[v - 1] >> 7);+ uint16_t c = sil ? (aa >= 256 ? tint : scale565(tint, aa)) : tint != 0xFFFF ? mul565(col[v - 1], tint) : col[v - 1];+ if (ga < 256) c = scale565(c, ga), aa = (aa * ga) >> 8;+ *d = aa >= 256 ? c : blend565(*d, c, aa);+}+/* a texture's frame scaled by s about its frame point (ox, oy), placed at view (px, py) */+static void sp_tex_scaled(uint16_t *strip, int sy0, int sy1, uint16_t id, float px, float py, float ox, float oy, float sx, float sy,+ uint16_t tint, int ga, bool sil) {+ Tex t;+ if (!tex_get(id, &t) || t.w > (int)sizeof rowbuf || sx == 0 || sy == 0) return;+ int n;+ const uint16_t *col = pal_colors(t.pal, &n);+ const uint8_t *al = pal_alpha(t.pal);+ float x0 = px + (t.ox - ox) * sx, x1 = px + (t.ox + t.w - ox) * sx, y0 = py + (t.oy - oy) * sy, y1 = py + (t.oy + t.h - oy) * sy;+ if (x0 > x1) { float k = x0; x0 = x1, x1 = k; }+ if (y0 > y1) { float k = y0; y0 = y1, y1 = k; }+ int Y0 = (int)floorf(y0), Y1 = (int)ceilf(y1), X0 = (int)floorf(x0), X1 = (int)ceilf(x1);+ if (Y0 < sy0) Y0 = sy0;+ if (Y1 > sy1) Y1 = sy1;+ if (X0 < 0) X0 = 0;+ if (X1 > VIEW_W) X1 = VIEW_W;+ int cached = -1;+ for (int Y = Y0; Y < Y1; Y++) {+ int v = (int)floorf((Y + 0.5f - py) / sy + oy) - t.oy;+ if (v < 0 || v >= t.h) continue;+ if (v != cached) tex_row_idx(&t, v, rowbuf), cached = v;+ uint16_t *row = strip + (Y - sy0) * VIEW_W;+ for (int X = X0; X < X1; X++) {+ int u = (int)floorf((X + 0.5f - px) / sx + ox) - t.ox;+ if (u < 0 || u >= t.w || !rowbuf[u]) continue;+ sp_texel(row + X, col, al, rowbuf[u], tint, ga, sil);+ }+ }+}+/* a texture's frame with its top-left at view (x, y) */+static void sp_tex(uint16_t *strip, int sy0, int sy1, uint16_t id, int x, int y, uint16_t tint, int ga, bool sil) {+ Tex t;+ if (!tex_get(id, &t) || t.w > (int)sizeof rowbuf) return;+ if (y + t.oy >= sy1 || y + t.oy + t.h <= sy0 || x + t.ox >= VIEW_W || x + t.ox + t.w <= 0) return;+ int n;+ const uint16_t *col = pal_colors(t.pal, &n);+ const uint8_t *al = pal_alpha(t.pal);+ for (int r = 0; r < t.h; r++) {+ int Y = y + t.oy + r;+ if (Y < sy0 || Y >= sy1) continue;+ tex_row_idx(&t, r, rowbuf);+ uint16_t *row = strip + (Y - sy0) * VIEW_W;+ for (int i = 0; i < t.w; i++) {+ int X = x + t.ox + i;+ if (!rowbuf[i] || (unsigned)X >= VIEW_W) continue;+ sp_texel(row + X, col, al, rowbuf[i], tint, ga, sil);+ }+ }+}+/* a texture a gfx_custom layer reads, loaded now and marked drawn this frame: nothing loads while the+ * strips are drawn (res.c), and what was drawn longest ago goes first */+static void tex_touch(uint16_t id) {+ Tex t;+ if (id != 0xFFFF) tex_get(id, &t);+}+/* layers drawn once per frame for every entity of a class at one depth */+static bool layer_once(uint32_t *mark) {+ if (*mark == g_frame + 1) return false;+ *mark = g_frame + 1;+ return true;+}++/* ---------------------------------------------------------------- the clutter */+/* ClutterBlockBase: the solid areas (one manager entity per room holds them, ClutterBlock: the pictures+ * filling them, made by ClutterBlockGenerator at the room's load. Kept in two small pools. */+enum { CL_RED, CL_GREEN, CL_YELLOW };+#define CLUT_BASES 240+#define CLUT_BLOCKS 960+typedef struct { uint8_t x, y, w, h, f; } ClutBase; /* f: color | enabled << 2 | slot << 3 */+typedef struct { uint8_t x, y, tex, f, since; } ClutBlock; /* tex 0xFF: gone; f: see CB_ */+enum { CB_COLOR = 3, CB_GROUND = 4, CB_TOP = 8, CB_LEFT = 16, CB_RIGHT = 32, CB_FLY = 64, CB_SLOT = 128 };+enum { OFF_clut_base = ((END_ts_state + 7) & ~7), END_clut_base = OFF_clut_base + (int)sizeof(ClutBase[CLUT_BASES]) };+#define clut_base (*(ClutBase(*)[CLUT_BASES])(void *)(g_chram[3] + OFF_clut_base))+enum { OFF_clut_blk = ((END_clut_base + 7) & ~7), END_clut_blk = OFF_clut_blk + (int)sizeof(ClutBlock[CLUT_BLOCKS]) };+#define clut_blk (*(ClutBlock(*)[CLUT_BLOCKS])(void *)(g_chram[3] + OFF_clut_blk))+static int nclut_base, nclut_blk;+static uint16_t clut_tex[3][15];+/* the texture sets of each color, biggest first: (columns, rows, first, count) */+static const uint8_t CLUT_SETS[5][4] = {{3, 3, 14, 1}, {2, 3, 12, 1}, {3, 2, 13, 1}, {2, 2, 6, 6}, {1, 1, 0, 6}};+static const uint8_t CLUT_W[15] = {1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3}, CLUT_H[15] = {1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 2, 3};+static const char *CLUT_NAMES[3] = {"Red", "Green", "Yellow"};+static void clut_flag(char *buf, int color) { path2(buf, "oshiro_clutter_cleared_", NULL, -1), buf[23] = (char)('0' + color), buf[24] = 0; }+static bool clut_enabled(int color) {+ char f[32];+ clut_flag(f, color);+ return !level_get_flag(f);+}+static void clut_load_tex(void) {+ static const char *n[3] = {"objects/resortclutter/red_", "objects/resortclutter/green_", "objects/resortclutter/yellow_"};+ char p[48];+ for (int c = 0; c < 3; c++)+ for (int i = 0; i < 15; i++) clut_tex[c][i] = tex(path2(p, n[c], NULL, i));+}+static void clut_drop_slot(int slot) { /* a room goes away: its bases and blocks too */+ int j = 0;+ for (int i = 0; i < nclut_base; i++)+ if (((clut_base[i].f >> 3) & 1) != slot) clut_base[j++] = clut_base[i];+ nclut_base = j;+ j = 0;+ for (int i = 0; i < nclut_blk; i++)+ if (((clut_blk[i].f & CB_SLOT) ? 1 : 0) != slot) clut_blk[j++] = clut_blk[i];+ nclut_blk = j;+}++typedef struct { int16_t rx, ry; uint8_t slot, generated; float timer; } Clutter;+static const EntClass CLUTTER;+static Ent *clutter_of_slot(int slot) {+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &CLUTTER && g_ents[i].dead != 1 && ST(&g_ents[i], Clutter)->slot == slot) return &g_ents[i];+ return NULL;+}+static bool clutter_collide_rect(const Ent *e, float l, float t, float r, float b) {+ const Clutter *c = ST(e, Clutter);+ for (int i = 0; i < nclut_base; i++) {+ const ClutBase *k = &clut_base[i];+ if (((k->f >> 3) & 1) != c->slot || !(k->f & 4)) continue;+ float x = c->rx + k->x * 8.f, y = c->ry + k->y * 8.f;+ if (r > x && b > y && l < x + k->w * 8 && t < y + k->h * 8) return true;+ }+ return false;+}+/* ClutterBlockGenerator.Generate. No grid of the room (RAM): the cells are the areas' cells, numbered+ * area by area, with a bit each for "taken" */+#define CLUT_CELLS 2048+enum { OFF_clut_taken = ((END_clut_blk + 7) & ~7), END_clut_taken = OFF_clut_taken + (int)sizeof(uint8_t[CLUT_CELLS / 8]) };+#define clut_taken (*(uint8_t(*)[CLUT_CELLS / 8])(void *)(g_chram[3] + OFF_clut_taken))+enum { OFF_clut_off = ((END_clut_taken + 7) & ~7), END_clut_off = OFF_clut_off + (int)sizeof(uint16_t[CLUT_BASES + 1]) };+#define clut_off (*(uint16_t(*)[CLUT_BASES + 1])(void *)(g_chram[3] + OFF_clut_off)) /* the first cell of each area (of the room's slot) */+/* the area (an index in clut_base) holding a cell, the last one like the generator's grid; -1: none */+static int clut_area_at(int slot, int x, int y) {+ for (int i = nclut_base - 1; i >= 0; i--) {+ const ClutBase *k = &clut_base[i];+ if (((k->f >> 3) & 1) == slot && (k->f & 4) && x >= k->x && x < k->x + k->w && y >= k->y && y < k->y + k->h) return i;+ }+ return -1;+}+static int clut_cell(int area, int x, int y) {+ const ClutBase *k = &clut_base[area];+ return clut_off[area] + (y - k->y) * k->w + (x - k->x);+}+static bool clut_is_taken(int c) { return c < CLUT_CELLS && (clut_taken[c >> 3] & (1 << (c & 7))); }+static int clut_block_at(int slot, int x, int y) { /* the block covering a cell, -1 if none */+ for (int i = 0; i < nclut_blk; i++) {+ const ClutBlock *b = &clut_blk[i];+ if (((b->f & CB_SLOT) ? 1 : 0) == slot && b->tex != 0xFF && x >= b->x && x < b->x + CLUT_W[b->tex] && y >= b->y &&+ y < b->y + CLUT_H[b->tex])+ return i;+ }+ return -1;+}+static void clutter_generate(Ent *e) {+ Clutter *c = ST(e, Clutter);+ const Room *rm = room_ptr(e);+ int slot = c->slot, cols = rm->w / 8, rows = rm->h / 8 + 1;+ int ncells = 0;+ for (int i = 0; i < nclut_base; i++) {+ clut_off[i] = (uint16_t)ncells;+ const ClutBase *k = &clut_base[i];+ if (((k->f >> 3) & 1) == slot && (k->f & 4)) ncells += k->w * k->h;+ }+ clut_off[nclut_base] = (uint16_t)ncells;+ if (ncells > CLUT_CELLS) ncells = CLUT_CELLS;+ memset(clut_taken, 0, sizeof clut_taken);+ /* active.Shuffle(): a shuffled order of the cells (a stride through them) */+ int stride = 1;+ if (ncells > 1) {+ stride = 1 + rndi(ncells - 1);+ while (1) { /* coprime with the count */+ int a = stride, b = ncells;+ while (b) { int t = a % b; a = b, b = t; }+ if (a == 1) break;+ stride++;+ }+ }+ int start = ncells ? rndi(ncells) : 0;+ int first = nclut_blk;+ for (int n = 0; n < ncells; n++) {+ int cell = (start + n * stride) % ncells;+ if (clut_is_taken(cell)) continue;+ int area = 0;+ while (area < nclut_base && clut_off[area + 1] <= cell) area++;+ const ClutBase *k = &clut_base[area];+ int local = cell - clut_off[area], x = k->x + local % k->w, y = k->y + local / k->w, color = k->f & 3;+ if (clut_area_at(slot, x, y) != area) continue; /* (overlapping areas: the last one has it) */+ int set = 0;+ for (; set < 5; set++) {+ int w = CLUT_SETS[set][0], h = CLUT_SETS[set][1];+ if (x + w > cols || y + h > rows) continue;+ bool ok = true;+ for (int i = x; i < x + w && ok; i++)+ for (int j = y; j < y + h && ok; j++) {+ int a = (i >= k->x && i < k->x + k->w && j >= k->y && j < k->y + k->h) ? area : clut_area_at(slot, i, j);+ if (a < 0 || (clut_base[a].f & 3) != color || clut_is_taken(clut_cell(a, i, j))) ok = false;+ }+ if (ok) break;+ }+ if (set >= 5 || nclut_blk >= CLUT_BLOCKS) continue;+ ClutBlock *b = &clut_blk[nclut_blk++];+ b->x = (uint8_t)x, b->y = (uint8_t)y;+ b->tex = (uint8_t)(CLUT_SETS[set][2] + rndi(CLUT_SETS[set][3]));+ b->f = (uint8_t)(color | (slot ? CB_SLOT : 0));+ b->since = 6; /* floatDelay 0: floating from the start */+ for (int i = x; i < x + CLUT_SETS[set][0]; i++)+ for (int j = y; j < y + CLUT_SETS[set][1]; j++) {+ int a = clut_area_at(slot, i, j), cc = a < 0 ? CLUT_CELLS : clut_cell(a, i, j);+ if (cc < CLUT_CELLS) clut_taken[cc >> 3] |= (uint8_t)(1 << (cc & 7));+ }+ }+ /* the open sides, and what rests on a wall: tiles[,].Empty is neither a wall nor clutter */+#define WALL(cx_, cy_) (level_tile_type(0, rm->x / 8 + (cx_), rm->y / 8 + (cy_)) != '0')+#define EMPTY(cx_, cy_) (!WALL(cx_, cy_) && clut_area_at(slot, cx_, cy_) < 0)+ for (int i = first; i < nclut_blk; i++) {+ ClutBlock *b = &clut_blk[i];+ int w = CLUT_W[b->tex], h = CLUT_H[b->tex];+ for (int k = b->x; k < b->x + w; k++) {+ if (b->y == 0 || EMPTY(k, b->y - 1)) b->f |= CB_TOP;+ if (b->y + h - 1 < rows - 1 && WALL(k, b->y + h)) b->f |= CB_GROUND;+ }+ for (int l = b->y; l < b->y + h; l++) {+ if (b->x == 0 || EMPTY(b->x - 1, l)) b->f |= CB_LEFT;+ if (b->x + w - 1 == cols - 1 || EMPTY(b->x + w, l)) b->f |= CB_RIGHT;+ }+ }+#undef EMPTY+#undef WALL+ /* SetAboveToOnGround: from the bottom up, a block on one on the ground is too */+ for (int y = rows - 1; y >= 0; y--)+ for (int i = first; i < nclut_blk; i++) {+ ClutBlock *b = &clut_blk[i];+ int h = CLUT_H[b->tex];+ if (b->y + h - 1 != y || (b->f & CB_GROUND)) continue;+ for (int k = b->x; k < b->x + CLUT_W[b->tex]; k++) {+ int o = clut_block_at(slot, k, b->y + h);+ if (o >= 0 && (clut_blk[o].f & CB_GROUND)) {+ b->f |= CB_GROUND;+ break;+ }+ }+ }+}+static bool clut_mine(const Clutter *c, const ClutBlock *b) { return ((b->f & CB_SLOT) ? 1 : 0) == c->slot && b->tex != 0xFF; }+/* ClutterBlock.WeightDown, through the blocks below */+static void clut_weight_down(const Clutter *c, int i, int depth) {+ ClutBlock *b = &clut_blk[i];+ if (depth < 16) {+ int bx0 = b->x, bx1 = b->x + CLUT_W[b->tex], by = b->y + CLUT_H[b->tex];+ for (int j = 0; j < nclut_blk; j++) {+ ClutBlock *o = &clut_blk[j];+ if (j == i || !clut_mine(c, o) || o->y != by || (o->f & CB_FLY)) continue;+ if (o->x < bx1 && o->x + CLUT_W[o->tex] > bx0) clut_weight_down(c, j, depth + 1);+ }+ }+ b->since = 0; /* floatTarget 0, floatDelay 0.1 */+}+static float clut_wave(const Clutter *c, const ClutBlock *b) {+ int x = c->rx + b->x * 8;+ return -(sinf((float)(x / 16) * 0.25f + c->timer * 2) + 1) / 2 - 1;+}+static float clut_float(const Clutter *c, const ClutBlock *b) {+ if (b->f & CB_GROUND) return 0;+ if (b->since < 6) return 0;+ return fmaxf(clut_wave(c, b), -4 * (b->since - 6) * DT);+}+static void clutter_update(Ent *e) {+ Clutter *c = ST(e, Clutter);+ Player *p = level_player();+ Ent *pe = p ? p->ent : NULL;+ c->timer += DT;+ for (int i = 0; i < nclut_blk; i++) {+ ClutBlock *b = &clut_blk[i];+ if (!clut_mine(c, b) || (b->f & (CB_GROUND | CB_FLY))) continue;+ if (b->since >= 6 && pe) {+ float l = c->rx + b->x * 8.f, t = c->ry + b->y * 8.f, r = l + CLUT_W[b->tex] * 8, bt = t + CLUT_H[b->tex] * 8;+ bool climb = p->state == ST_CLIMB;+ if (((b->f & CB_TOP) && e_right(pe) > l && e_left(pe) < r && e_bottom(pe) >= t - 1 && e_bottom(pe) <= t + 4) ||+ (climb && (b->f & CB_LEFT) && e_right(pe) >= l - 1 && e_right(pe) < l + 4 && e_bottom(pe) > t && e_top(pe) < bt) ||+ (climb && (b->f & CB_RIGHT) && e_left(pe) <= r + 1 && e_left(pe) > r - 4 && e_bottom(pe) > t && e_top(pe) < bt))+ clut_weight_down(c, i, 0);+ }+ if (b->since < 255) b->since++;+ }+}+static void clutter_awake(Ent *e) {+ Clutter *c = ST(e, Clutter);+ clut_load_tex();+ if (!c->generated) c->generated = 1, clutter_generate(e);+}+static void clutter_removed(Ent *e) { clut_drop_slot(ST(e, Clutter)->slot); }+/* ClutterBlockBase.Render: a dark rectangle (deeper), then the blocks in front of the player */+static void clut_base_layer(uint16_t *strip, int sy0, int sy1, void *ctx) {+ Ent *e = ctx;+ Clutter *c = ST(e, Clutter);+ for (int i = 0; i < nclut_base; i++) {+ ClutBase *k = &clut_base[i];+ if (((k->f >> 3) & 1) != c->slot) continue;+ bool on = k->f & 4;+ sp_rect(strip, sy0, sy1, vx(c->rx + k->x * 8.f), vy(c->ry + k->y * 8.f), k->w * 8, k->h * 8 + (on ? 2 : 0), 0, on ? 179 : 77);+ }+}+static void clut_blk_layer(uint16_t *strip, int sy0, int sy1, void *ctx) {+ Ent *e = ctx;+ Clutter *c = ST(e, Clutter);+ for (int i = 0; i < nclut_blk; i++) {+ ClutBlock *b = &clut_blk[i];+ if (!clut_mine(c, b) || (b->f & CB_FLY)) continue;+ int x = vx(c->rx + b->x * 8.f), y = vy(c->ry + b->y * 8.f + clut_float(c, b));+ if (y >= sy1 || y + CLUT_H[b->tex] * 8 <= sy0 || x >= VIEW_W || x + CLUT_W[b->tex] * 8 <= 0) continue;+ sp_tex(strip, sy0, sy1, clut_tex[b->f & CB_COLOR][b->tex], x, y, 0xFFFF, 256, false);+ }+}+static void clutter_render(Ent *e) { gfx_custom(clut_base_layer, e, 0, VIEW_H); }+/* the blocks (depth -9998) are drawn by a second entity of the same room */+typedef struct { int16_t mgr; } ClutterFront;+static void clutfront_render(Ent *e) {+ Ent *m = ent_at(ST(e, ClutterFront)->mgr, &CLUTTER);+ if (!m) return;+ Clutter *c = ST(m, Clutter);+ for (int i = 0; i < nclut_blk; i++) {+ ClutBlock *b = &clut_blk[i];+ if (!clut_mine(c, b) || (b->f & CB_FLY)) continue;+ int x = vx(c->rx + b->x * 8.f), y = vy(c->ry + b->y * 8.f);+ if (y < VIEW_H + 8 && y + CLUT_H[b->tex] * 8 > -8 && x < VIEW_W && x + CLUT_W[b->tex] * 8 > 0) tex_touch(clut_tex[b->f & CB_COLOR][b->tex]);+ }+ gfx_custom(clut_blk_layer, m, 0, VIEW_H);+}+static const EntClass CLUTTERFRONT = {.name = "clutterBlocks", .size = sizeof(ClutterFront), .render = clutfront_render};+static const EntClass CLUTTER = {.name = "clutterBase", .size = sizeof(Clutter), .update = clutter_update, .render = clutter_render,+ .awake = clutter_awake, .removed = clutter_removed, .collide_rect = clutter_collide_rect,+ .kind = KIND_SOLID};+/* yellowBlocks / greenBlocks / redBlocks: ClutterBlockGenerator.Add */+static void new_clutter_area(const EData *d, int color, float w, float h) {+ int slot = g_level.room_slot;+ Ent *m = clutter_of_slot(slot);+ if (!m) {+ clut_drop_slot(slot);+ m = ent_new(&CLUTTER, 0, 0);+ if (!m) return;+ Clutter *c = ST(m, Clutter);+ c->slot = (uint8_t)slot;+ c->rx = (int16_t)d->rx, c->ry = (int16_t)d->ry;+ m->depth = 8999;+ m->ctype = COL_LIST;+ m->safe = 1;+ Ent *f = ent_new(&CLUTTERFRONT, 0, 0);+ if (f) f->depth = -9998, f->collidable = 0, ST(f, ClutterFront)->mgr = ent_ref(m);+ }+ if (nclut_base >= CLUT_BASES) return;+ ClutBase *k = &clut_base[nclut_base++];+ k->x = (uint8_t)((d->x - d->rx) / 8), k->y = (uint8_t)((d->y - d->ry) / 8);+ k->w = (uint8_t)(w / 8), k->h = (uint8_t)(h / 8);+ k->f = (uint8_t)(color | (clut_enabled(color) ? 4 : 0) | slot << 3);+}++/* ClutterCabinet */+typedef struct { Sprite spr; uint8_t opened; } Cabinet;+static void cabinet_update(Ent *e) { spr_update(&ST(e, Cabinet)->spr); }+static void cabinet_render(Ent *e) { spr_draw(&ST(e, Cabinet)->spr, e->x + 8, e->y + 8); }+static const EntClass CABINET = {.name = "clutterCabinet", .size = sizeof(Cabinet), .update = cabinet_update, .render = cabinet_render};+static void cabinet_open(Ent *e) {+ Cabinet *c = ST(e, Cabinet);+ spr_play(&c->spr, A_clutterCabinet_open, false);+ c->opened = 1;+}+static void new_cabinet(const EData *d) {+ Ent *e = ent_new(&CABINET, d->x, d->y);+ if (!e) return;+ e->depth = -10001;+ e->collidable = 0;+ Cabinet *c = ST(e, Cabinet);+ spr_init(&c->spr, SB_clutterCabinet);+ spr_play(&c->spr, A_clutterCabinet_idle, true);+}++/* ClutterAbsorbEffect: the clutter flies into the cabinets. The flying pictures are worked out from+ * hashes (a delay, a cabinet, a curve) rather than kept: absorbed blocks, then 125 more from offscreen */+typedef struct { V2 target; float t, extra_t; uint8_t color, closing, closed; int16_t ncab; } Absorb;+static const EntClass ABSORB;+static Ent *cabinet_n(int k) {+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &CABINET && g_ents[i].dead != 1 && k-- == 0) return &g_ents[i];+ return NULL;+}+/* where a flying picture is at time t since it started (its delay included); false when gone */+static bool fly_at(Absorb *a, uint32_t seed, V2 from, float delay, bool shake, float t, V2 *pos, float *scale, Ent **cab_out) {+ t -= delay;+ if (t < 0) {+ *pos = from, *scale = 1;+ return true;+ }+ if (!a->ncab) return false;+ Ent *cab = cabinet_n((int)(hash32(seed) % (uint32_t)a->ncab));+ if (!cab) return false;+ *cab_out = cab;+ V2 to = v2add(v2add(v2(cab->x, cab->y), v2(8, 8)), v2((float)(hash32(seed + 1) % 16) - 8, (float)(hash32(seed + 2) % 4) - 2));+ if (shake) {+ if (t < 0.25f) {+ *pos = v2add(from, v2((float)(hash32(seed + (uint32_t)(t * 60) * 7) % 3) - 1, (float)(hash32(seed + (uint32_t)(t * 60) * 13) % 3) - 1));+ *scale = 1;+ return true;+ }+ t -= 0.25f;+ }+ if (t >= 1) return false;+ V2 dir = v2norm(v2sub(to, from));+ float len = v2len(v2sub(to, from)), side = (hash32(seed + 3) & 1) ? -1 : 1;+ V2 ctrl = v2add(v2mul(v2add(to, from), 0.5f), v2mul(v2(-dir.y, dir.x), (len / 4 + hashf(seed + 4) * 40) * side));+ *pos = curve_point(from, to, ctrl, ease_cube_inout(t));+ *scale = ease_cube_inout(1 - t * 0.5f);+ if (t > 0.5f) *cab_out = cab;+ else *cab_out = NULL;+ return true;+}+static void absorb_layer(uint16_t *strip, int sy0, int sy1, void *ctx) {+ Ent *e = ctx;+ Absorb *a = ST(e, Absorb);+ for (int s = 0; s < 2; s++) {+ Ent *m = clutter_of_slot(s);+ if (!m) continue;+ Clutter *c = ST(m, Clutter);+ for (int i = 0; i < nclut_blk; i++) {+ ClutBlock *b = &clut_blk[i];+ if (!clut_mine(c, b) || !(b->f & CB_FLY) || (b->f & CB_COLOR) != a->color) continue;+ uint32_t seed = (uint32_t)i * 977u + 31u;+ V2 from = v2(c->rx + b->x * 8 + CLUT_W[b->tex] * 4.f, c->ry + b->y * 8 + CLUT_H[b->tex] * 4.f);+ V2 pos;+ float sc;+ Ent *cab;+ if (!fly_at(a, seed, from, hashf(seed + 9) * 0.5f, true, a->t, &pos, &sc, &cab)) continue;+ sp_tex_scaled(strip, sy0, sy1, clut_tex[a->color][b->tex], pos.x - g_camx, pos.y - g_camy, CLUT_W[b->tex] * 4.f,+ CLUT_H[b->tex] * 4.f, sc, sc, 0xFFFF, 256, false);+ }+ }+ if (a->extra_t > 0)+ for (int k = 0; k < 125; k++) {+ float start = (k / 5) * 0.05f;+ if (a->extra_t < start) break;+ uint32_t seed = 0x51ED + (uint32_t)k * 131u;+ V2 from = v2add(a->target, angle_vec(hashf(seed + 5) * 2 * PI_F, 320));+ V2 pos;+ float sc;+ Ent *cab;+ if (!fly_at(a, seed, from, 0, false, a->extra_t - start, &pos, &sc, &cab)) continue;+ uint8_t ti = (uint8_t)(hash32(seed + 6) % 15);+ sp_tex_scaled(strip, sy0, sy1, clut_tex[a->color][ti], pos.x - g_camx, pos.y - g_camy, CLUT_W[ti] * 4.f, CLUT_H[ti] * 4.f, sc,+ sc, 0xFFFF, 256, false);+ }+}+static void absorb_update(Ent *e) {+ Absorb *a = ST(e, Absorb);+ a->t += DT;+ if (a->extra_t > 0 || a->t >= 1.5f) a->extra_t += DT;+ /* the cabinets open when the first pictures are half way */+ if (a->t > 0.75f && !a->closing)+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &CABINET && g_ents[i].dead != 1 && !ST(&g_ents[i], Cabinet)->opened) cabinet_open(&g_ents[i]);+ if (level_on_interval(0.25f)) { /* ClutterSwitch.P_ClutterFly along the way */+ int n = 0;+ for (int i = 0; i < g_nents && n < 3; i++)+ if (g_ents[i].cls == &CABINET && g_ents[i].dead != 1 && ST(&g_ents[i], Cabinet)->opened && rndi(4) == 0)+ particles_emit1(PL_FG, &P_ClutterSwitch_P_ClutterFly, v2(g_ents[i].x + 8, g_ents[i].y + 8), P_ClutterSwitch_P_ClutterFly.direction),+ n++;+ }+}+static void absorb_render(Ent *e) {+ for (int i = 0; i < 15; i++) tex_touch(clut_tex[ST(e, Absorb)->color][i]);+ gfx_custom(absorb_layer, e, 0, VIEW_H);+}+static const EntClass ABSORB = {.name = "clutterAbsorb", .size = sizeof(Absorb), .update = absorb_update, .render = absorb_render};+/* CloseCabinetsRoutine: in rows, left to right, three at a time */+static void absorb_close_step(Ent *e) {+ Absorb *a = ST(e, Absorb);+ int done = 0, total = 0;+ Ent *order[64];+ for (int i = 0; i < g_nents && total < 64; i++)+ if (g_ents[i].cls == &CABINET && g_ents[i].dead != 1) order[total++] = &g_ents[i];+ for (int i = 1; i < total; i++)+ for (int j = i; j > 0; j--) {+ Ent *p = order[j - 1], *q = order[j];+ int c = fabsf(p->y - q->y) < 24 ? (int)signf(p->x - q->x) : (int)signf(p->y - q->y);+ if (c <= 0) break;+ order[j - 1] = q, order[j] = p;+ }+ for (int i = 0; i < total; i++) {+ Cabinet *c = ST(order[i], Cabinet);+ if (!c->opened) {+ done++;+ continue;+ }+ spr_play(&c->spr, A_clutterCabinet_close, false);+ c->opened = 0;+ if (++done % 3 == 1) break;+ }+ if (done >= total) a->closed = 1;+}++/* ClutterSwitch */+typedef struct {+ Sprite spr;+ float start_y, at_y, speed_y, target_sx, wait, t, light_t, light_from;+ int16_t effect;+ uint8_t color, pressed, was_on_top, step, closing_wait;+} CSwitch;+static float area_darkness(void);+static uint16_t cswitch_icon[3];+static void cswitch_be_pressed(Ent *e) {+ CSwitch *s = ST(e, CSwitch);+ s->pressed = 1;+ s->at_y += 10;+ e->y += 10;+ spr_play(&s->spr, A_clutterSwitch_active, false);+}+static int cswitch_dashed(Ent *e, Player *p, V2 dir) {+ CSwitch *s = ST(e, CSwitch);+ if (!s->pressed && dir.x == 0 && dir.y == 1) {+ level_freeze(0.2f);+ char f[32];+ clut_flag(f, s->color);+ level_set_flag(f, true);+ level_set_flag("oshiro_clutter_door_open", false);+ level_dir_shake(v2(0, 1), 0.6f);+ particles_emit(PL_MID, &P_ClutterSwitch_P_Pressed, 20, v2(e_cxm(e), e_top(e) - 10), v2(16, 8), P_ClutterSwitch_P_Pressed.direction);+ cswitch_be_pressed(e);+ s->spr.sx = 1.5f;+ s->step = 1; /* AbsorbRoutine */+ (void)p;+ }+ return DASH_NORMAL;+}+static void cswitch_absorb(Ent *e, CSwitch *s) {+ Player *p = level_player();+ if (s->wait > 0) {+ s->wait -= DT;+ return;+ }+ switch (s->step) {+ case 1: {+ if (p) player_set_state(p, ST_DUMMY);+ Ent *fx = ent_new(&ABSORB, 0, 0);+ if (fx) {+ fx->depth = -10001;+ fx->collidable = 0;+ fx->tags = TAG_TRANSITION_UPDATE;+ Absorb *a = ST(fx, Absorb);+ a->target = v2(e->x + e->cw / 2, e->y);+ a->color = s->color;+ int n = 0;+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &CABINET && g_ents[i].dead != 1) n++;+ a->ncab = (int16_t)n;+ }+ s->effect = ent_ref(fx);+ spr_play(&s->spr, A_clutterSwitch_break, false);+ g_session.lighting_alpha_add -= 0.05f; /* the lights: down to 0.05 in 2 s, back up 3 s later */+ s->light_from = g_level.lighting, s->light_t = 0.0001f;+ for (int i = 0; i < nclut_blk; i++) /* every ClutterBlock of the color: Absorb */+ if (clut_blk[i].tex != 0xFF && (clut_blk[i].f & CB_COLOR) == s->color) clut_blk[i].f |= CB_FLY;+ for (int i = 0; i < nclut_base; i++) /* every ClutterBlockBase of the color: Deactivate */+ if ((clut_base[i].f & 3) == s->color) clut_base[i].f &= (uint8_t)~4;+ s->wait = 1.5f, s->step = 2;+ break;+ }+ case 2:+ if (p) player_set_state(p, ST_NORMAL);+ s->t = 0, s->step = 3; /* the 125 flying in from offscreen (the effect draws them), shaking */+ /* fall through */+ case 3:+ if (level_on_interval(0.05f)) level_shake(0.3f);+ s->t += DT;+ if (s->t < 25 * 0.05f) break;+ s->wait = 1.5f, s->step = 4;+ break;+ case 4: {+ Ent *fx = ent_at(s->effect, &ABSORB);+ if (fx) ST(fx, Absorb)->closing = 1;+ s->step = 5;+ }+ /* fall through */+ case 5: {+ Ent *fx = ent_at(s->effect, &ABSORB);+ if (fx && !ST(fx, Absorb)->closed) {+ absorb_close_step(fx);+ s->wait = 0.1f;+ break;+ }+ s->wait = 0.2f + 0.3f, s->step = 6;+ break;+ }+ case 6:+ s->step = 0;+ break;+ }+}+static void cswitch_update(Ent *e) {+ CSwitch *s = ST(e, CSwitch);+ spr_update(&s->spr);+ plat_update(e);+ if (s->step) cswitch_absorb(e, s);+ if (s->light_t > 0) { /* the Level.Lighting tweens (SineInOut, 2 s each) */+ float t = s->light_t += DT;+ if (t <= 2) g_level.lighting = lerpf(s->light_from, 0.05f, ease_sine_inout(t / 2));+ else if (t >= 3) {+ float k = fminf((t - 3) / 2, 1);+ g_level.lighting = lerpf(0.05f, area_darkness() + g_session.lighting_alpha_add, ease_sine_inout(k));+ if (k >= 1) s->light_t = 0;+ }+ }+ if (solid_has_player_on_top(e)) {+ if (s->speed_y < 0) s->speed_y = 0;+ s->speed_y = approach(s->speed_y, 70, 200 * DT);+ plat_move_towards_y(e, s->at_y + (s->pressed ? 2 : 4), s->speed_y * DT);+ s->target_sx = 1.2f;+ s->was_on_top = 1;+ } else {+ if (s->speed_y > 0) s->speed_y = 0;+ s->speed_y = approach(s->speed_y, -150, 200 * DT);+ plat_move_towards_y(e, s->at_y, -s->speed_y * DT);+ s->target_sx = 1;+ s->was_on_top = 0;+ }+ s->spr.sx = approach(s->spr.sx, s->target_sx, 0.8f * DT);+}+static void cswitch_render(Ent *e) {+ CSwitch *s = ST(e, CSwitch);+ Sprite sp = s->spr;+ spr_draw(&sp, e->x + 16, e->y + 16 + (s->pressed ? 2 : 0));+ if (!s->pressed) gfx_tex_ex(cswitch_icon[s->color], e->x + 16, e->y + 8, 8, 8, 1, 1, 0, 0xFFFF, 255, 0);+ light_add(e->x + e->cw / 2, e->y - 1, 0x00FFFF, 1, s->pressed ? 24 : 32, s->pressed ? 48 : 64);+}+static const EntClass CSWITCH = {.name = "colorSwitch", .size = sizeof(CSwitch), .update = cswitch_update, .render = cswitch_render,+ .on_dash_collide = cswitch_dashed, .kind = KIND_SOLID};+static int clut_color_of(const char *s) {+ for (int i = 0; i < 3; i++)+ if (!strcmp(s, CLUT_NAMES[i])) return i;+ return CL_GREEN;+}+static void new_cswitch(const EData *d) {+ Ent *e = ent_new(&CSWITCH, d->x, d->y);+ if (!e) return;+ ent_box(e, 32, 16, 0, 0);+ e->safe = 1;+ CSwitch *s = ST(e, CSwitch);+ s->color = (uint8_t)clut_color_of(EAS(d, colorSwitch, type));+ s->start_y = s->at_y = d->y;+ s->target_sx = 1;+ s->effect = -1;+ spr_init(&s->spr, SB_clutterSwitch);+ spr_play(&s->spr, A_clutterSwitch_idle, true);+ static const char *ic[3] = {"objects/resortclutter/icon_red", "objects/resortclutter/icon_green", "objects/resortclutter/icon_yellow"};+ for (int i = 0; i < 3; i++) cswitch_icon[i] = tex(ic[i]);+ if (!clut_enabled(s->color)) cswitch_be_pressed(e);+}++/* ClutterDoor and MrOshiroDoor: ghost doors */+typedef struct { Sprite spr; Wiggler wig; uint8_t color, oshiro; } GDoor;+static bool gdoor_locked(GDoor *g) {+ char f[32];+ clut_flag(f, g->color);+ if (level_get_flag("oshiro_clutter_door_open")) return level_get_flag(f);+ return true;+}+static int gdoor_dashed(Ent *e, Player *p, V2 dir) {+ (void)p, (void)dir;+ wiggler_start(&ST(e, GDoor)->wig, 0.6f, 3);+ return DASH_BOUNCE;+}+static void gdoor_update(Ent *e) {+ GDoor *g = ST(e, GDoor);+ if (!g->oshiro) {+ Ent *p = level_player_ent();+ bool in = p && collide_ent_at(e, e->x, e->y, p);+ if (g_level.transitioning && in) e->visible = e->collidable = 0;+ else if (!e->collidable && gdoor_locked(g) && !in) {+ e->visible = e->collidable = 1;+ wiggler_start(&g->wig, 0.6f, 3);+ }+ }+ spr_update(&g->spr);+ wiggler_update(&g->wig);+ plat_update(e);+}+static void gdoor_render(Ent *e) {+ GDoor *g = ST(e, GDoor);+ Sprite s = g->spr;+ s.sx = s.sy = 1 - g->wig.value * 0.2f;+ spr_draw(&s, e->x + e->cw / 2, e->y + e->ch / 2);+}+static const EntClass GDOOR = {.name = "clutterDoor", .size = sizeof(GDoor), .update = gdoor_update, .render = gdoor_render,+ .on_dash_collide = gdoor_dashed, .kind = KIND_SOLID};+static void new_gdoor(const EData *d, bool oshiro) {+ Ent *e = ent_new(&GDOOR, d->x, d->y);+ if (!e) return;+ GDoor *g = ST(e, GDoor);+ g->oshiro = oshiro;+ spr_init(&g->spr, SB_ghost_door);+ spr_play(&g->spr, A_ghost_door_idle, true);+ if (oshiro) { /* MrOshiroDoor */+ ent_box(e, 32, 32, 0, 0);+ e->visible = e->collidable = !level_get_flag("oshiro_resort_talked_1");+ return;+ }+ ent_box(e, EA(d, clutterDoor, width), EA(d, clutterDoor, height), 0, 0);+ e->tags = TAG_TRANSITION_UPDATE;+ g->color = (uint8_t)clut_color_of(EAS(d, clutterDoor, type));+ if (!gdoor_locked(g)) e->visible = e->collidable = 0; /* InstantUnlock */+}++static bool is_gdoor(const Ent *e) { return e->cls == &GDOOR && e->dead != 1 && !ST(e, GDoor)->oshiro; }+static bool gdoor_locked_ent(Ent *e) { return gdoor_locked(ST(e, GDoor)); }+static void gdoor_instant_unlock(Ent *e) { e->visible = e->collidable = 0; } /* InstantUnlock */+static void gdoor_open(Ent *e, bool instant) { /* MrOshiroDoor.Open / InstantOpen */+ if (instant) e->visible = e->collidable = 0;+ else if (e->collidable) spr_play(&ST(e, GDoor)->spr, A_ghost_door_open, false), e->collidable = 0;+}+/* ClutterDoor.UnlockRoutine: the camera goes to it, it opens (*p starts at -1) */+static V2 gdoor_cam(Ent *e) {+ const Room *rm = g_level.room;+ return v2(clampf(e->x - 160, (float)rm->x, (float)(rm->x + rm->w - 320)), clampf(e->y - 90, (float)rm->y, (float)(rm->y + rm->h - 180)));+}+static bool gdoor_unlock(Ent *e, float *p, V2 *from) {+ if (*p < 0) {+ *from = g_level.cam;+ *p = v2len(v2sub(*from, gdoor_cam(e))) > 8 ? 0 : 10 + 0.2f; /* (10 + the wait: no camera move) */+ }+ if (*p < 1) {+ g_level.cam = v2lerp(*from, gdoor_cam(e), ease_cube_inout(*p));+ *p += DT;+ return true;+ }+ if (*p > 10) {+ if ((*p -= DT) > 10) return true;+ *p = 1;+ }+ if (*p < 2) { /* it opens */+ spr_play(&ST(e, GDoor)->spr, A_ghost_door_open, false);+ e->collidable = 0;+ *p = 2;+ }+ if (*p < 2.4f) {+ g_level.cam = gdoor_cam(e);+ *p += DT;+ return true;+ }+ return false;+}++/* ---------------------------------------------------------------- ResortLantern */+typedef struct { Wiggler wig; float collide_timer, alpha_timer, anim_t; int8_t mult, flip; uint8_t frame; } Lantern;+static uint16_t lantern_holder, lantern_tex[3];+static void lantern_on_player(Ent *e, Player *p) {+ Lantern *l = ST(e, Lantern);+ if (l->collide_timer <= 0) {+ if (p->speed.x != 0 || p->speed.y != 0) {+ l->collide_timer = 0.5f;+ l->mult = rndi(2) ? -1 : 1;+ wiggler_restart(&l->wig);+ }+ } else+ l->collide_timer = 0.5f;+}+static void lantern_awake(Ent *e) {+ if (point_solid(e->x + 8, e->y)) ST(e, Lantern)->flip = 1;+}+static void lantern_update(Ent *e) {+ Lantern *l = ST(e, Lantern);+ static const uint8_t SEQ[5] = {0, 0, 1, 2, 1}; /* AddLoop("light", "lantern", 0.3, 0, 0, 1, 2, 1) */+ l->anim_t += DT;+ if (l->anim_t >= 0.3f) l->anim_t -= 0.3f, l->frame = (uint8_t)((l->frame + 1) % 5);+ (void)SEQ;+ wiggler_update(&l->wig);+ if (l->collide_timer > 0) l->collide_timer -= DT;+ l->alpha_timer += DT;+}+static void lantern_render(Ent *e) {+ Lantern *l = ST(e, Lantern);+ static const uint8_t SEQ[5] = {0, 0, 1, 2, 1};+ float sx = l->flip ? -1.f : 1.f;+ gfx_tex_ex(lantern_holder, e->x, e->y, 8, 12, sx, 1, 0, 0xFFFF, 255, 0);+ float rot = l->wig.value * l->mult * (PI_F / 180) * 30;+ gfx_tex_ex(lantern_tex[SEQ[l->frame]], e->x - 1 + (l->flip ? 2 : 0), e->y - 5, 7, 7, sx, 1, rot, 0xFFFF, 255, 0);+ float a = 0.95f + sinf(l->alpha_timer) * 0.05f;+ light_add(e->x, e->y, 0xFFFFFF, a, 32, 64);+ bloom_add(e->x, e->y, a, 8);+}+static const EntClass LANTERN = {.name = "resortLantern", .size = sizeof(Lantern), .update = lantern_update, .render = lantern_render,+ .awake = lantern_awake, .on_player = lantern_on_player, .kind = KIND_PCOLLIDE};+static void new_lantern(const EData *d) {+ Ent *e = ent_new(&LANTERN, d->x, d->y);+ if (!e) return;+ ent_box(e, 8, 8, -4, -4);+ e->depth = 2000;+ Lantern *l = ST(e, Lantern);+ wiggler_init(&l->wig, 2.5f, 1.2f);+ l->wig.start_zero = true;+ l->mult = 1;+ lantern_holder = tex("objects/resortLantern/holder");+ char p[40];+ for (int i = 0; i < 3; i++) lantern_tex[i] = tex(path2(p, "objects/resortLantern/lantern", NULL, i));+}++/* ---------------------------------------------------------------- Cobweb */+/* all of a room's cobwebs in one strip layer (a dozen lines each) */+typedef struct { V2 a, b, off[4]; float ending[4], wave; uint32_t color, edge; uint8_t noff; } Cobweb;+static const EntClass COBWEB;+static void cobweb_draw(uint16_t *strip, int sy0, int sy1, Cobweb *c, V2 a, V2 b, int steps, bool offshoots) {+ V2 ctrl = v2add(v2mul(v2add(a, b), 0.5f), v2(0, 8 + sinf(c->wave) * 4));+ if (offshoots)+ for (int i = 0; i < c->noff; i++) cobweb_draw(strip, sy0, sy1, c, c->off[i], curve_point(a, b, ctrl, c->ending[i]), 4, false);+ V2 prev = a;+ for (int j = 1; j <= steps; j++) {+ V2 pt = curve_point(a, b, ctrl, (float)j / steps);+ uint32_t col = (j <= 2 || j >= steps - 1) ? c->edge : c->color;+ sp_line(strip, sy0, sy1, vx(prev.x), vy(prev.y), vx(pt.x), vy(pt.y), rgb(col), 256);+ prev = v2add(pt, v2norm(v2sub(prev, pt)));+ }+}+static void cobweb_layer(uint16_t *strip, int sy0, int sy1, void *ctx) {+ (void)ctx;+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &COBWEB && g_ents[i].dead != 1) {+ Cobweb *c = ST(&g_ents[i], Cobweb);+ cobweb_draw(strip, sy0, sy1, c, c->a, c->b, 12, true);+ }+}+static uint32_t cobweb_mark;+static void cobweb_render(Ent *e) {+ (void)e;+ if (layer_once(&cobweb_mark)) gfx_custom(cobweb_layer, NULL, 0, VIEW_H);+}+static void cobweb_update(Ent *e) { ST(e, Cobweb)->wave += DT; }+static void cobweb_awake(Ent *e) { /* Added: anchored to solids at both ends, offshoots too */+ Cobweb *c = ST(e, Cobweb);+ if (!rect_solid((int)c->a.x - 2, (int)c->a.y - 2, (int)c->a.x + 2, (int)c->a.y + 2) ||+ !rect_solid((int)c->b.x - 2, (int)c->b.y - 2, (int)c->b.x + 2, (int)c->b.y + 2)) {+ ent_remove(e);+ return;+ }+ for (int i = 0; i < c->noff; i++)+ if (!rect_solid((int)c->off[i].x - 2, (int)c->off[i].y - 2, (int)c->off[i].x + 2, (int)c->off[i].y + 2)) {+ memmove(c->off + i, c->off + i + 1, sizeof(V2) * (size_t)(c->noff - i - 1));+ memmove(c->ending + i, c->ending + i + 1, sizeof(float) * (size_t)(c->noff - i - 1));+ c->noff--, i--;+ }+}+static const EntClass COBWEB = {.name = "cobweb", .size = sizeof(Cobweb), .update = cobweb_update, .render = cobweb_render,+ .awake = cobweb_awake};+static void new_cobweb(const EData *d) {+ Ent *e = ent_new(&COBWEB, d->x, d->y);+ if (!e) return;+ e->depth = -1;+ e->collidable = 0;+ Cobweb *c = ST(e, Cobweb);+ c->a = v2(d->x, d->y);+ c->b = ed_node(d, 0);+ for (int i = 1; i < d->nnodes && c->noff < 4; i++) {+ c->off[c->noff] = ed_node(d, i);+ c->ending[c->noff++] = 0.3f + rndf() * 0.4f;+ }+ c->wave = rndf();+ /* AreaData.CobwebColor */+ static const uint32_t F[3] = {0x42c192, 0xaf36a8, 0x3474a6};+ c->color = g_session.area == 5 ? 0x9f2166 : g_session.area == 10 ? F[rndi(3)] : 0x696a6a;+ c->edge = 0;+ int r = (int)(((c->color >> 16) & 255) * 0.8f + 0x0f * 0.2f), g = (int)(((c->color >> 8) & 255) * 0.8f + 0x0e * 0.2f),+ b = (int)((c->color & 255) * 0.8f + 0x17 * 0.2f);+ c->edge = (uint32_t)(r << 16 | g << 8 | b);+}++/* ---------------------------------------------------------------- TriggerSpikes (dust tendrils) */+/* each tendril: Lerp (0..255) and DelayTimer (frames) | Triggered (128); kept in a pool, the rest from hashes */+static int nts;+typedef struct { int16_t first, n; uint8_t dir; } TSpikes;+enum { TS_UP, TS_DOWN, TS_LEFT, TS_RIGHT };+static uint16_t ts_tent_v[9], ts_tent_h[9], ts_dust[3];+static const EntClass TSPIKES_CLASS;+static V2 ts_outwards(int dir) { return dir == TS_UP ? v2(0, -1) : dir == TS_DOWN ? v2(0, 1) : dir == TS_LEFT ? v2(-1, 0) : v2(1, 0); }+static void ts_index_range(Ent *e, TSpikes *s, Player *p, int *mn, int *mx) {+ Ent *pe = p->ent;+ *mn = *mx = -1;+ switch (s->dir) {+ case TS_UP: if (p->speed.y >= 0) *mn = (int)((e_left(pe) - e_left(e)) / 4), *mx = (int)((e_right(pe) - e_left(e)) / 4); break;+ case TS_DOWN: if (p->speed.y <= 0) *mn = (int)((e_left(pe) - e_left(e)) / 4), *mx = (int)((e_right(pe) - e_left(e)) / 4); break;+ case TS_LEFT: if (p->speed.x >= 0) *mn = (int)((e_top(pe) - e_top(e)) / 4), *mx = (int)((e_bottom(pe) - e_top(e)) / 4); break;+ default: if (p->speed.x <= 0) *mn = (int)((e_top(pe) - e_top(e)) / 4), *mx = (int)((e_bottom(pe) - e_top(e)) / 4); break;+ }+}+static void ts_on_player(Ent *e, Player *p) {+ TSpikes *s = ST(e, TSpikes);+ int mn, mx;+ ts_index_range(e, s, p, &mn, &mx);+ if (mx < 0 || mn >= s->n) return;+ if (mn < 0) mn = 0;+ if (mx > s->n - 1) mx = s->n - 1;+ for (int i = mn; i <= mx; i++) { /* SpikeInfo.OnPlayer */+ int k = s->first + i;+ if (!(ts_state[k] & 128)) {+ ts_state[k] = 128 | 24; /* Triggered, DelayTimer 0.4 */+ } else if (ts_lerp[k] >= 255) {+ player_die(p, ts_outwards(s->dir), false);+ return;+ }+ }+}+static bool ts_player_check(Ent *e, TSpikes *s, int i) {+ Player *p = level_player();+ if (!p || !collide_ent_at(e, e->x, e->y, p->ent)) return false;+ int mn, mx;+ ts_index_range(e, s, p, &mn, &mx);+ return mn <= i + 1 && mx >= i - 1;+}+static void ts_update(Ent *e) {+ TSpikes *s = ST(e, TSpikes);+ for (int i = 0; i < s->n; i++) {+ int k = s->first + i;+ uint8_t st = ts_state[k];+ if (st & 128) {+ int delay = st & 127;+ if (delay > 0) {+ if (--delay == 0 && ts_player_check(e, s, i)) delay = 3; /* 0.05 more while the player is on it */+ ts_state[k] = (uint8_t)(128 | delay);+ } else+ ts_lerp[k] = (uint8_t)(ts_lerp[k] + 34 > 255 ? 255 : ts_lerp[k] + 34); /* Approach(1, 8 * DT) */+ } else+ ts_lerp[k] = (uint8_t)(ts_lerp[k] > 17 ? ts_lerp[k] - 17 : 0);+ }+}+static bool ts_riding(Ent *e, Ent *pl) {+ TSpikes *s = ST(e, TSpikes);+ if (pl->kind & KIND_JUMPTHRU) return s->dir == TS_UP && collide_ent_at(e, e->x, e->y + 1, pl);+ float dx = s->dir == TS_LEFT ? 1 : s->dir == TS_RIGHT ? -1 : 0, dy = s->dir == TS_UP ? 1 : s->dir == TS_DOWN ? -1 : 0;+ return collide_ent_at(e, e->x + dx, e->y + dy, pl) && !collide_ent_at(e, e->x, e->y, pl); /* CollideCheckOutside */+}+static void ts_layer(uint16_t *strip, int sy0, int sy1, void *ctx) {+ (void)ctx;+ /* DustStyles: the edges' colors */+ static const uint32_t EDGE3[3] = {0xf25a10, 0xff0000, 0xf21067}, EDGE5[3] = {0x245ebb, 0x17a0ff, 0x17a0ff};+ const uint32_t *edges = g_session.area == 5 ? EDGE5 : EDGE3;+ for (int q = 0; q < g_nents; q++) {+ Ent *e = &g_ents[q];+ if (e->cls != &TSPIKES_CLASS || e->dead == 1) continue;+ TSpikes *s = ST(e, TSpikes);+ V2 along = (s->dir == TS_UP || s->dir == TS_DOWN) ? v2(1, 0) : v2(0, 1), out = ts_outwards(s->dir);+ bool vert = s->dir == TS_UP || s->dir == TS_DOWN;+ for (int i = 0; i < s->n; i++) {+ int k = s->first + i;+ uint32_t h = hash32((uint32_t)(int)e->x * 7919u + (uint32_t)(int)e->y * 104729u + (uint32_t)i);+ V2 at = v2add(v2(e->x, e->y), v2mul(along, 2 + i * 4.f));+ if (!(ts_state[k] & 128)) { /* the tendril, waving */+ int frame = (int)(fmodf((h % 900) / 100.f + g_level.time_active * 12, 9));+ uint16_t t = vert ? ts_tent_v[frame] : ts_tent_h[frame];+ uint32_t col = edges[(h >> 12) % 3];+ uint32_t tc = (uint32_t)((int)(((col >> 16) & 255) * 0.6f + 0x48 * 0.4f) << 16 | (int)(((col >> 8) & 255) * 0.6f + 0x3D * 0.4f) << 8 |+ (int)((col & 255) * 0.6f + 0x8B * 0.4f));+ float sx = s->dir == TS_LEFT ? -1 : 1, sy = s->dir == TS_UP ? -1 : 1;+ float ox = vert ? 3 : 0, oy = vert ? 0 : 3; /* Justify (0.5, 0) or (0, 0.5) of 6x3 / 3x6 */+ sp_tex_scaled(strip, sy0, sy1, t, vx(at.x + along.x) + 0.f, vy(at.y + along.y) + 0.f, ox, oy, sx, sy, 0, 256, true);+ sp_tex_scaled(strip, sy0, sy1, t, vx(at.x) + 0.f, vy(at.y) + 0.f, ox, oy, sx, sy, rgb(tc), 256, true);+ } else if (ts_lerp[k] > 0) { /* the dust (DustEdge: an edge of its color around it) */+ float lerp = ts_lerp[k] / 255.f;+ static const uint8_t OUT[3] = {3, 4, 6};+ V2 pos = v2add(at, v2mul(out, -4 + lerp * OUT[(h >> 4) % 3]));+ float sc = 0.5f * lerp;+ uint16_t t = ts_dust[(h >> 8) % 3];+ float px = pos.x - g_camx, py = pos.y - g_camy;+ uint16_t ec = rgb(edges[(h >> 16) % 3]);+ for (int o = 0; o < 4; o++)+ sp_tex_scaled(strip, sy0, sy1, t, px + (o == 0 ? -1 : o == 1 ? 1 : 0), py + (o == 2 ? -1 : o == 3 ? 1 : 0), 8, 8, sc, sc, ec, 256, true);+ sp_tex_scaled(strip, sy0, sy1, t, px, py, 8, 8, sc, sc, 0xFFFF, 256, false);+ }+ }+ }+}+static uint32_t ts_mark;+static void ts_render(Ent *e) {+ (void)e;+ if (!layer_once(&ts_mark)) return;+ bool v = false, h = false;+ for (int q = 0; q < g_nents; q++)+ if (g_ents[q].cls == &TSPIKES_CLASS && g_ents[q].dead != 1) {+ int d = ST(&g_ents[q], TSpikes)->dir;+ if (d == TS_UP || d == TS_DOWN) v = true;+ else h = true;+ }+ for (int i = 0; i < 9; i++) {+ if (v) tex_touch(ts_tent_v[i]);+ if (h) tex_touch(ts_tent_h[i]);+ }+ for (int i = 0; i < 3; i++) tex_touch(ts_dust[i]);+ gfx_custom(ts_layer, NULL, 0, VIEW_H);+}+static void ts_removed(Ent *e) { /* frees its tendrils: the later ones move down */+ TSpikes *s = ST(e, TSpikes);+ int a = s->first, n = s->n;+ memmove(ts_lerp + a, ts_lerp + a + n, (size_t)(nts - a - n));+ memmove(ts_state + a, ts_state + a + n, (size_t)(nts - a - n));+ nts -= n;+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &TSPIKES_CLASS && &g_ents[i] != e && ST(&g_ents[i], TSpikes)->first > a) ST(&g_ents[i], TSpikes)->first -= (int16_t)n;+ s->n = 0;+}+static const EntClass TSPIKES_CLASS = {.name = "triggerSpikes", .size = sizeof(TSpikes), .update = ts_update, .render = ts_render,+ .removed = ts_removed, .on_player = ts_on_player, .sm_riding = ts_riding,+ .kind = KIND_PCOLLIDE | KIND_STATICMOVER};+static void new_tspikes(const EData *d, int dir, int size) {+ int n = size / 4;+ if (nts + n > TSPIKES) return;+ Ent *e = ent_new(&TSPIKES_CLASS, d->x, d->y);+ if (!e) return;+ e->depth = -50;+ switch (dir) {+ case TS_UP: ent_box(e, (float)size, 4, 0, -4); break;+ case TS_DOWN: ent_box(e, (float)size, 4, 0, 0); break;+ case TS_LEFT: ent_box(e, 4, (float)size, -4, 0); break;+ default: ent_box(e, 4, (float)size, 0, 0); break;+ }+ TSpikes *s = ST(e, TSpikes);+ s->dir = (uint8_t)dir;+ s->first = (int16_t)nts, s->n = (int16_t)n;+ memset(ts_lerp + nts, 0, (size_t)n);+ memset(ts_state + nts, 0, (size_t)n);+ nts += n;+ char p[48];+ for (int i = 0; i < 9; i++) {+ ts_tent_v[i] = tex(path2(p, "danger/triggertentacle/wiggle_v", NULL, i));+ ts_tent_h[i] = tex(path2(p, "danger/triggertentacle/wiggle_h", NULL, i));+ }+ for (int i = 0; i < 3; i++) ts_dust[i] = tex(path2(p, "danger/dustcreature/base", NULL, i));+}++/* ---------------------------------------------------------------- Door (an Actor) */+typedef struct { ActorExt ext; Sprite spr; uint8_t disabled, metal; } Door;+static bool door_riding(Ent *e, Ent *s) { return collide_rect(s, (int)e->x - 2, (int)e->y - 2, (int)e->x + 2, (int)e->y + 2); }+static void door_squish(Ent *e, Collision *c) { (void)e, (void)c; }+static int door_anim(const Door *d, int which) { /* 0 idle, 1 open, 2 close (the sprites rooms ask for) */+ (void)which;+#ifdef SB_metaldoor+ if (d->metal) return which == 0 ? A_metaldoor_idle : which == 1 ? A_metaldoor_open : A_metaldoor_close;+#endif+#ifdef SB_door+ if (!d->metal) return which == 0 ? A_door_idle : which == 1 ? A_door_open : A_door_close;+#endif+ (void)d;+ return 0;+}+static void door_open(Ent *e, float x) {+ Door *d = ST(e, Door);+ int idle = door_anim(d, 0), open = door_anim(d, 1), close = door_anim(d, 2);+ if (spr_is(&d->spr, idle)) {+ spr_play(&d->spr, open, false);+ if (e->x != x) d->spr.sx = signf(x - e->x);+ } else if (spr_is(&d->spr, close))+ spr_play(&d->spr, close, true);+}+static void door_on_player(Ent *e, Player *p) {+ if (!ST(e, Door)->disabled) door_open(e, p->ent->x);+}+static void door_update(Ent *e) {+ Door *d = ST(e, Door);+ spr_update(&d->spr);+ actor_update_lift(e);+ if (!d->disabled && collide_solid(e, e->x, e->y)) d->disabled = 1;+}+static void door_render(Ent *e) { spr_draw(&ST(e, Door)->spr, e->x, e->y); }+static const EntClass DOOR = {.name = "door", .size = sizeof(Door), .update = door_update, .render = door_render,+ .on_player = door_on_player, .on_squish = door_squish, .is_riding_solid = door_riding,+ .kind = KIND_ACTOR | KIND_PCOLLIDE};+static void new_door(const EData *d) {+ Ent *e = ent_new(&DOOR, d->x, d->y);+ if (!e) return;+ e->depth = 8998;+ ent_box(e, 12, 22, -6, -23);+ Door *s = ST(e, Door);+ const char *t = EAS(d, door, type);+ s->metal = *t && strcmp(t, "wood");+ int bank = -1;+#ifdef SB_metaldoor+ if (s->metal) bank = SB_metaldoor;+#endif+#ifdef SB_door+ if (!s->metal) bank = SB_door;+#endif+ if (bank >= 0) spr_init(&s->spr, bank), spr_play(&s->spr, door_anim(s, 0), true);+ else s->spr.visible = 0;+}++/* ---------------------------------------------------------------- Trapdoor */+typedef struct { Sprite spr; float wait; uint8_t step; } Hatch;+static void hatch_on_player(Ent *e, Player *p) {+ Hatch *h = ST(e, Hatch);+ e->collidable = 0;+ if (p->speed.y >= 0) spr_play(&h->spr, A_trapdoor_open, false);+ else { /* OpenFromBottom */+ h->spr.sy = -1;+ spr_play(&h->spr, A_trapdoor_open_partial, true);+ h->step = 1;+ }+}+static void hatch_update(Ent *e) {+ Hatch *h = ST(e, Hatch);+ spr_update(&h->spr);+ if (h->wait > 0) {+ h->wait -= DT;+ return;+ }+ switch (h->step) {+ case 1: /* PlayRoutine("open_partial") */+ if (spr_is(&h->spr, A_trapdoor_open_partial)) break;+ h->wait = 0.1f, h->step = 2;+ break;+ case 2:+ h->spr.rate = -1; /* (from its first frame: it ends at once) */+ spr_play(&h->spr, A_trapdoor_open_partial, true);+ h->step = 3;+ break;+ case 3:+ if (spr_is(&h->spr, A_trapdoor_open_partial)) break;+ h->spr.sy = 1, h->spr.rate = 1;+ spr_play(&h->spr, A_trapdoor_open, true);+ h->step = 0;+ break;+ }+}+static void hatch_render(Ent *e) { spr_draw(&ST(e, Hatch)->spr, e->x, e->y + 6); }+static const EntClass HATCH = {.name = "trapdoor", .size = sizeof(Hatch), .update = hatch_update, .render = hatch_render,+ .on_player = hatch_on_player, .kind = KIND_PCOLLIDE};+static void new_hatch(const EData *d) {+ Ent *e = ent_new(&HATCH, d->x, d->y);+ if (!e) return;+ e->depth = 8999;+ ent_box(e, 24, 4, 0, 6);+ Hatch *h = ST(e, Hatch);+ spr_init(&h->spr, SB_trapdoor);+ spr_play(&h->spr, A_trapdoor_idle, true);+}++/* ---------------------------------------------------------------- SinkingPlatform, MovingPlatform */+static uint16_t wood_platform_tex(void) {+ return tex(g_session.area == 4 ? "objects/woodPlatform/cliffside" : "objects/woodPlatform/default");+}+static void platform_draw(uint16_t t, float x, float y, float w) { /* the four 8 px pieces */+ gfx_tex_part(t, x, y, 0, 0, 8, 8, 0, 0xFFFF, 255);+ for (int i = 8; (float)i < w - 8; i += 8) gfx_tex_part(t, x + i, y, 8, 0, 8, 8, 0, 0xFFFF, 255);+ gfx_tex_part(t, x + w - 8, y, 24, 0, 8, 8, 0, 0xFFFF, 255);+ gfx_tex_part(t, x + w / 2 - 4, y, 16, 0, 8, 8, 0, 0xFFFF, 255);+}+typedef struct { float speed, start_y, rise_timer, shake_timer; int8_t shx, shy; uint16_t tex; } Sinking;+static void sinking_update(Ent *e) {+ Sinking *s = ST(e, Sinking);+ plat_update(e);+ if (s->shake_timer > 0) { /* Shaker */+ if (level_on_interval(0.02f)) s->shx = (int8_t)shake_val(), s->shy = (int8_t)shake_val();+ if ((s->shake_timer -= DT) <= 0) s->shx = s->shy = 0;+ }+ Player *p = level_player();+ bool rider = p && jumpthru_has_player_rider(e);+ if (rider) {+ if (s->rise_timer <= 0) s->shake_timer = 0.15f;+ s->rise_timer = 0.1f;+ s->speed = approach(s->speed, player_ducking(p) ? 60 : 30, 400 * DT);+ } else if (s->rise_timer > 0) {+ s->rise_timer -= DT;+ s->speed = approach(s->speed, 45, 600 * DT);+ } else+ s->speed = approach(s->speed, -50, 400 * DT);+ if (s->speed > 0) plat_move_v(e, s->speed * DT);+ else if (s->speed < 0 && e->y + e->remy > s->start_y) {+ plat_move_towards_y(e, s->start_y, -s->speed * DT);+ if (e->y + e->remy <= s->start_y) s->shake_timer = 0.1f;+ }+}+static void sinking_render(Ent *e) {+ Sinking *s = ST(e, Sinking);+ platform_draw(s->tex, e->x + s->shx, e->y + s->shy, e->cw);+}+static const EntClass SINKING = {.name = "sinkingPlatform", .size = sizeof(Sinking), .update = sinking_update, .render = sinking_render,+ .kind = KIND_JUMPTHRU};+/* SinkingPlatformLine, MovingPlatformLine */+typedef struct { V2 end; float height; uint32_t edge, inner; uint8_t moving; } PLine;+static void pline_render(Ent *e) {+ PLine *l = ST(e, PLine);+ if (!l->moving) {+ gfx_rect(e->x - 1, e->y, 3, l->height, rgb(l->edge), 255);+ gfx_rect(e->x, e->y + 1, 1, l->height, rgb(l->inner), 255);+ return;+ }+ V2 d = v2norm(v2sub(l->end, v2(e->x, e->y))), n = v2(-d.y, d.x);+ V2 a = v2(e->x, e->y), b = l->end;+ gfx_line(a.x - d.x - n.x, a.y - d.y - n.y, b.x + d.x - n.x, b.y + d.y - n.y, rgb(l->edge), 255);+ gfx_line(a.x - d.x, a.y - d.y, b.x + d.x, b.y + d.y, rgb(l->edge), 255);+ gfx_line(a.x - d.x + n.x, a.y - d.y + n.y, b.x + d.x + n.x, b.y + d.y + n.y, rgb(l->edge), 255);+ gfx_line(a.x, a.y, b.x, b.y, rgb(l->inner), 255);+}+static const EntClass PLINE = {.name = "platformLine", .size = sizeof(PLine), .render = pline_render};+static void new_sinking(const EData *d) {+ float w = EA(d, sinkingPlatform, width);+ Ent *e = ent_new(&SINKING, d->x, d->y);+ if (!e) return;+ ent_box(e, w, 5, 0, 0);+ e->depth = 1;+ Sinking *s = ST(e, Sinking);+ s->start_y = d->y;+ s->tex = wood_platform_tex();+ Ent *l = ent_new(&PLINE, d->x + w / 2, d->y + 2.5f);+ if (l) {+ l->depth = 9001;+ l->collidable = 0;+ PLine *pl = ST(l, PLine);+ pl->height = g_level.rooms[g_level.room_slot].h - (l->y - d->ry); /* Bounds.Height - (Y - Bounds.Y) */+ pl->edge = 0x2a1923, pl->inner = 0x160b12;+ }+}+typedef struct { V2 start, end; float add_y, sink_timer; Tween tw; uint8_t reverse; uint16_t tex; } Moving;+static void moving_update(Ent *e) {+ Moving *m = ST(e, Moving);+ bool end = tween_update(&m->tw); /* the yoyo tween (SineInOut, 2 s) */+ float t = ease_sine_inout(m->reverse ? 1 - m->tw.percent : m->tw.percent);+ plat_move_to(e, lerpf(m->start.x, m->end.x, t), lerpf(m->start.y, m->end.y, t) + m->add_y);+ if (end) tween_start(&m->tw, 2), m->reverse = !m->reverse;+ plat_update(e);+ if (jumpthru_has_player_rider(e)) {+ m->sink_timer = 0.2f;+ m->add_y = approach(m->add_y, 3, 50 * DT);+ } else if (m->sink_timer > 0) {+ m->sink_timer -= DT;+ m->add_y = approach(m->add_y, 3, 50 * DT);+ } else+ m->add_y = approach(m->add_y, 0, 20 * DT);+}+static void moving_trigger(Ent *e, Ent *m) { (void)m, ST(e, Moving)->sink_timer = 0.4f; }+static void moving_render(Ent *e) { platform_draw(ST(e, Moving)->tex, e->x, e->y, e->cw); }+static void moving_awake(Ent *e) { plat_static_movers_attach(e); }+static const EntClass MOVING = {.name = "movingPlatform", .size = sizeof(Moving), .update = moving_update, .render = moving_render,+ .awake = moving_awake, .on_staticmover_trigger = moving_trigger, .kind = KIND_JUMPTHRU};+static void new_moving(const EData *d) {+ float w = EA(d, movingPlatform, width);+ Ent *e = ent_new(&MOVING, d->x, d->y);+ if (!e) return;+ ent_box(e, w, 5, 0, 0);+ Moving *m = ST(e, Moving);+ m->start = v2(d->x, d->y);+ m->end = ed_node(d, 0);+ m->tex = wood_platform_tex();+ tween_start(&m->tw, 2);+ V2 half = v2(w / 2, (5 + 4) / 2.f);+ Ent *l = ent_new(&PLINE, m->start.x + half.x, m->start.y + half.y);+ if (l) {+ l->depth = 9001;+ l->collidable = 0;+ PLine *pl = ST(l, PLine);+ pl->moving = 1;+ pl->end = v2add(m->end, half);+ if (g_session.area == 4) pl->edge = 0xa4464a, pl->inner = 0x86354e;+ else pl->edge = 0x2a1923, pl->inner = 0x160b12;+ }+}++/* ---------------------------------------------------------------- Clothesline (Flagline) */+/* all of a room's clotheslines in one strip layer: a rectangle per column of cloth */+typedef struct { V2 from, to; float wave; uint32_t seed; } Cloth;+static const EntClass CLOTHESLINE;+static const uint32_t CLOTH_COLORS[4] = {0x0d2e6b, 0x3d2688, 0x4f6e9d, 0x47194a};+static uint32_t cl_lerp(uint32_t a, uint32_t b, float t) {+ int r = (int)(((a >> 16) & 255) + (((int)((b >> 16) & 255) - (int)((a >> 16) & 255)) * t));+ int g = (int)(((a >> 8) & 255) + (((int)((b >> 8) & 255) - (int)((a >> 8) & 255)) * t));+ int bl = (int)((a & 255) + (((int)(b & 255) - (int)(a & 255)) * t));+ return (uint32_t)(r << 16 | g << 8 | bl);+}+/* Calc.Random.Next(min, max) of the cloths, from the line's seed: color, height, length, step */+static int cloth_val(uint32_t seed, int j, int k, int lo, int hi) { return lo + (int)(hash32(seed + (uint32_t)(j * 4 + k)) % (uint32_t)(hi - lo)); }+static void flagline_draw(uint16_t *strip, int sy0, int sy1, V2 from, V2 to, float wave, uint32_t seed, const uint32_t *colors, int ncol,+ uint32_t line, uint32_t pin, int minh, int maxh, int minl, int maxl, int mins, int maxs, float droop) {+ V2 a = from.x < to.x ? from : to, b = from.x < to.x ? to : from;+ float num = v2len(v2sub(a, b)), num2 = num / 8;+ V2 ctrl = v2add(v2mul(v2add(a, b), 0.5f), v2(0, num2 + sinf(wave) * num2 * 0.3f));+ V2 p4 = a;+ float t = 0;+ int k = 0;+ bool flag = false;+ uint16_t lc = rgb(line), pc = rgb(pin);+ for (int guard = 0; t < 1 && guard < 400; guard++) {+ int j = k % 10;+ int length = cloth_val(seed, j, 2, minl, maxl), step = cloth_val(seed, j, 3, mins, maxs);+ t += (float)(flag ? length : step) / num;+ V2 p5 = curve_point(a, b, ctrl, t);+ sp_line(strip, sy0, sy1, vx(p4.x), vy(p4.y), vx(p5.x), vy(p5.y), lc, 256);+ if (t < 1 && flag) {+ int col = cloth_val(seed, j, 0, 0, ncol), height = cloth_val(seed, j, 1, minh, maxh);+ float n5 = length * droop;+ V2 c2 = v2add(v2mul(v2add(p4, p5), 0.5f), v2(0, n5 + sinf(wave * 2 + t) * n5 * 0.4f));+ V2 p6 = p4;+ uint16_t cc = rgb(colors[col]), hc = rgb(cl_lerp(colors[col], 0xFFFFFF, 0.1f));+ for (float n6 = 1; n6 <= (float)length; n6 += 1) {+ V2 pt = curve_point(p4, p5, c2, n6 / length);+ if (pt.x != p6.x) {+ sp_rect(strip, sy0, sy1, vx(p6.x), vy(p6.y), (int)floorf(pt.x - p6.x + 1 + 0.5f), height, cc, 256);+ p6 = pt;+ }+ }+ sp_rect(strip, sy0, sy1, vx(p4.x), vy(p4.y), 1, height, hc, 256);+ sp_rect(strip, sy0, sy1, vx(p5.x), vy(p5.y), 1, height, hc, 256);+ sp_rect(strip, sy0, sy1, vx(p4.x), vy(p4.y - 1), 1, 3, pc, 256);+ sp_rect(strip, sy0, sy1, vx(p5.x), vy(p5.y - 1), 1, 3, pc, 256);+ k++;+ }+ p4 = p5;+ flag = !flag;+ }+}+static void cloth_layer(uint16_t *strip, int sy0, int sy1, void *ctx) {+ (void)ctx;+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &CLOTHESLINE && g_ents[i].dead != 1) {+ Cloth *c = ST(&g_ents[i], Cloth);+ /* lineColor = Color.Lerp(Gray, DarkBlue, 0.25), pinColor = Gray */+ flagline_draw(strip, sy0, sy1, c->from, c->to, c->wave, c->seed, CLOTH_COLORS, 4, 0x606082, 0x808080, 8, 20, 8, 16, 2, 8, 0.6f);+ }+}+static uint32_t cloth_mark;+static void cloth_render(Ent *e) {+ (void)e;+ if (layer_once(&cloth_mark)) gfx_custom(cloth_layer, NULL, 0, VIEW_H);+}+static void cloth_update(Ent *e) { ST(e, Cloth)->wave += DT; }+static const EntClass CLOTHESLINE = {.name = "clothesline", .size = sizeof(Cloth), .update = cloth_update, .render = cloth_render};+static void new_clothesline(const EData *d) {+ Ent *e = ent_new(&CLOTHESLINE, d->x, d->y);+ if (!e) return;+ e->depth = 8999;+ e->collidable = 0;+ Cloth *c = ST(e, Cloth);+ c->from = v2(d->x, d->y);+ c->to = ed_node(d, 0);+ c->wave = rndf() * 2 * PI_F;+ c->seed = (uint32_t)rnd_next(&g_rnd);+}++/* ---------------------------------------------------------------- Water */+#define WATER_RIPPLES 6+typedef struct { float pos, speed, height, percent; } Ripple;+typedef struct {+ float timer[2];+ Ripple rip[2][WATER_RIPPLES];+ uint8_t nrip[2];+ uint8_t top, bottom, player_in, tension_on;+ float tension_pos, tension_str;+ uint32_t ray_seed;+} Water;+static const EntClass WATER;+/* Water.Surface; k: 0 top, 1 bottom */+static float water_surface_height(const Ent *e, const Water *w, int k, float position) {+ float W = e->cw;+ if (position < 0 || position > W) return 0;+ float num = 0;+ for (int i = 0; i < w->nrip[k]; i++) {+ const Ripple *r = &w->rip[k][i];+ float d = fabsf(r->pos - position);+ float v = d < 12 ? clamped_map(d, 0, 16, 1, -0.75f) : clamped_map(d, 16, 32, -0.75f, 0);+ num += v * r->height * ease_cube_in(1 - r->percent);+ }+ num = clampf(num, -4, 4);+ if (k == 1 && w->tension_on) num += ease_cube_out(clamped_map(fabsf(w->tension_pos - position), 0, 24, 1, 0)) * w->tension_str * 12;+ float val = position / W;+ num *= clamped_map(val, 0, 0.1f, 0.5f, 1);+ num *= clamped_map(val, 0.9f, 1, 1, 0.5f);+ num += sinf(w->timer[k] + position * 0.1f);+ return num + 6;+}+static void water_ripple(Ent *e, Water *w, int k, float x, float mult) { /* Surface.DoRipple */+ float W = e->cw, dur = 3;+ float along = clampf(x - e->x, 0, W);+ if (W < 200) dur *= clamped_map(W, 0, 200, 0.25f, 1), mult *= clamped_map(W, 0, 200, 0.5f, 1);+ for (int s = -1; s <= 1; s += 2) {+ if (w->nrip[k] >= WATER_RIPPLES) { /* full: the oldest goes */+ memmove(&w->rip[k][0], &w->rip[k][1], sizeof(Ripple) * (WATER_RIPPLES - 1));+ w->nrip[k]--;+ }+ w->rip[k][w->nrip[k]++] = (Ripple){along, s * 80.f, 2 * mult, 0};+ }+ (void)dur;+ /* the duration only depends on the width: kept out of the record */+}+static float water_ripple_duration(const Ent *e) { return e->cw < 200 ? 3 * clamped_map(e->cw, 0, 200, 0.25f, 1) : 3; }+static void water_update(Ent *e) {+ Water *w = ST(e, Water);+ float W = e->cw, dur = water_ripple_duration(e);+ for (int k = 0; k < 2; k++) {+ if (!(k ? w->bottom : w->top)) continue;+ w->timer[k] += DT;+ for (int i = w->nrip[k] - 1; i >= 0; i--) {+ Ripple *r = &w->rip[k][i];+ if (r->percent > 1) {+ memmove(r, r + 1, sizeof(Ripple) * (size_t)(w->nrip[k] - i - 1));+ w->nrip[k]--;+ continue;+ }+ r->pos += r->speed * DT;+ if (r->pos < 0 || r->pos > W) r->speed = -r->speed, r->pos = clampf(r->pos, 0, W);+ r->percent += DT / dur;+ }+ }+ /* the player's WaterInteraction */+ Player *p = level_player();+ if (p) {+ Ent *pe = p->ent;+ bool in = collide_ent_at(e, e->x, e->y, pe);+ if (in != w->player_in) {+ V2 c = e_center(pe);+ if (c.y <= e_cym(e) && w->top) water_ripple(e, w, 0, c.x, 1);+ else if (c.y > e_cym(e) && w->bottom) water_ripple(e, w, 1, c.x, 1);+ w->player_in = in;+ }+ if (w->bottom) {+ if (in && pe->y > e_bottom(e) - 8) {+ w->tension_on = 1;+ w->tension_pos = pe->x - e->x;+ w->tension_str = clamped_map(pe->y, e_bottom(e) - 8, e_bottom(e) + 4, 0, 1);+ } else+ w->tension_on = 0;+ }+ }+}+/* the fill, the light rays and the surfaces, like the surfaces' meshes */+static void water_layer(uint16_t *strip, int sy0, int sy1, void *ctx) {+ Ent *e = ctx;+ Water *w = ST(e, Water);+ float W = e->cw, H = e->ch;+ uint16_t sky = rgb(0x87CEFA);+ int fill_a = 77, surf_a = 204; /* LightSkyBlue * 0.3, * 0.8 */+ /* the fill between the surfaces' bases */+ float ft = e->y + (w->top ? 8 : 0), fb = e->y + H - (w->bottom ? 8 : 0);+ sp_rect(strip, sy0, sy1, vx(e->x), vy(ft), (int)W, vy(fb) - vy(ft), sky, fill_a);+ for (int k = 0; k < 2; k++) {+ if (!(k ? w->bottom : w->top)) continue;+ float base = k ? e->y + H - 8 : e->y + 8, out = k ? 1.f : -1.f;+ /* surface heights at the mesh's points, every 4 px */+ for (int x = 0; x < (int)W; x++) {+ int x0 = x / 4 * 4, x1 = x0 + 4 < (int)W ? x0 + 4 : (int)W;+ float h0 = water_surface_height(e, w, k, (float)x0), h1 = water_surface_height(e, w, k, (float)x1);+ float h = x1 > x0 ? lerpf(h0, h1, (x + 0.5f - x0) / (x1 - x0)) : h0;+ int X = vx(e->x + x);+ if ((unsigned)X >= VIEW_W) continue;+ /* fill from the base to the surface, then the surface line, a pixel further out */+ float s = base + out * h, s2 = base + out * (h + 1);+ float y0 = fminf(base, s), y1 = fmaxf(base, s);+ for (int Y = (int)ceilf(y0 - 0.5f); (float)Y + 0.5f < y1; Y++) sp_plot(strip, sy0, sy1, X, Y - g_camy, sky, fill_a);+ float z0 = fminf(s, s2), z1 = fmaxf(s, s2);+ for (int Y = (int)ceilf(z0 - 0.5f); (float)Y + 0.5f < z1; Y++) sp_plot(strip, sy0, sy1, X, Y - g_camy, sky, surf_a);+ }+ /* the rays (Surface.Rays, from hashes: each its own cycle) */+ int nrays = (int)(W * 0.2f);+ for (int r = 0; r < nrays; r++) {+ uint32_t h = hash32(w->ray_seed + (uint32_t)r * 2654435761u);+ float duration = 2 + hashf(h) * 6;+ float t = w->timer[k] / duration + hashf(h + 1);+ uint32_t cycle = (uint32_t)floorf(t);+ float pct = t - cycle;+ uint32_t hc = hash32(h + cycle * 7919u);+ float rpos = hashf(hc) * W, rw = (float)(2 + hash32(hc + 1) % 14), len = 8 + hashf(hc + 2) * 120;+ float a = pct < 0.1f ? clamped_map(pct, 0, 0.1f, 0, 1) : pct > 0.9f ? clamped_map(pct, 0.9f, 1, 1, 0) : 1;+ float n9 = fmaxf(0, rpos - rw / 2), n10 = fminf(W, rpos + rw / 2);+ float depth = fminf(H, 0.7f * len), skew = 0.3f * len;+ if (n10 <= n9 || depth <= 0 || a <= 0) continue;+ float top = base + out * water_surface_height(e, w, k, (n9 + n10) / 2);+ for (int d = 0; d < (int)depth; d++) {+ float k2 = (d + 0.5f) / depth;+ int alpha = (int)(0.6f * a * (1 - k2) * 256);+ if (alpha <= 0) continue;+ float xs = e->x + n9 - skew * k2, xe = e->x + n10 - skew * k2;+ int Y = vy(top - out * (d + 0.5f) - 0.5f);+ for (int X = vx(xs); X < vx(xe); X++) sp_plot(strip, sy0, sy1, X, Y, sky, alpha);+ }+ }+ }+}+static void water_render(Ent *e) {+ float t = e->y - 8 - g_level.cam.y;+ gfx_custom(water_layer, e, (int)t, (int)(t + e->ch + 16));+}+static const EntClass WATER = {.name = "water", .size = sizeof(Water), .update = water_update, .render = water_render, .kind = KIND_WATER};+static void new_water(const EData *d) {+ Ent *e = ent_new(&WATER, d->x, d->y);+ if (!e) return;+ e->tags = TAG_TRANSITION_UPDATE;+ e->depth = -9999;+ ent_box(e, EA(d, water, width), EA(d, water, height), 0, 0);+ Water *w = ST(e, Water);+ w->top = 1;+ w->bottom = EAB(d, water, hasBottom);+ w->ray_seed = (uint32_t)rnd_next(&g_rnd);+}++/* ---------------------------------------------------------------- WaterFall */+typedef struct { float height; int16_t water; uint8_t solid; } Fall;+static void fall_awake(Ent *e) {+ Fall *f = ST(e, Fall);+ const Room *rm = room_ptr(e);+ f->height = 8;+ f->water = -1;+ for (;;) {+ float y = e->y + f->height;+ if (!(y < rm->y + rm->h)) break;+ Ent *w = NULL;+ for (int i = 0; i < g_nents && !w; i++)+ if (g_ents[i].cls == &WATER && g_ents[i].dead != 1 && collide_rect(&g_ents[i], (int)e->x, (int)y, (int)e->x + 8, (int)y + 8)) w = &g_ents[i];+ if (w) {+ f->water = ent_ref(w);+ break;+ }+ if (rect_solid((int)e->x, (int)y, (int)e->x + 8, (int)y + 8)) { /* Solid.BlockWaterfalls */+ f->solid = 1;+ break;+ }+ f->height += 8;+ }+}+static void fall_update(Ent *e) {+ Fall *f = ST(e, Fall);+ Ent *w = ent_at(f->water, &WATER);+ if (w && level_on_interval(0.3f) && ST(w, Water)->top) water_ripple(w, ST(w, Water), 0, e->x + 4, 0.75f);+ if (w || f->solid)+ particles_emit(PL_FG, &P_Water_P_Splash, 1, v2(e->x + 4, e->y + f->height + 2), v2(8, 2), -PI_F / 2);+}+static void fall_render(Ent *e) {+ Fall *f = ST(e, Fall);+ uint16_t sky = rgb(0x87CEFA);+ Ent *w = ent_at(f->water, &WATER);+ if (!w || !ST(w, Water)->top) {+ gfx_rect(e->x + 1, e->y, 6, f->height, sky, 77);+ gfx_rect(e->x - 1, e->y, 2, f->height, sky, 204);+ gfx_rect(e->x + 7, e->y, 2, f->height, sky, 204);+ return;+ }+ Water *wa = ST(w, Water);+ float num = f->height + (w->y + 8) - w->y;+ for (int i = 0; i < 6; i++)+ gfx_rect(e->x + i + 1, e->y, 1, num - water_surface_height(w, wa, 0, e->x + 1 + i - w->x), sky, 77);+ gfx_rect(e->x - 1, e->y, 2, num - water_surface_height(w, wa, 0, e->x - w->x), sky, 204);+ gfx_rect(e->x + 7, e->y, 2, num - water_surface_height(w, wa, 0, e->x + 8 - w->x), sky, 204);+}+static const EntClass FALL = {.name = "waterfall", .size = sizeof(Fall), .update = fall_update, .render = fall_render, .awake = fall_awake};+static void new_waterfall(const EData *d) {+ Ent *e = ent_new(&FALL, d->x, d->y);+ if (!e) return;+ e->depth = -9999;+ e->tags = TAG_TRANSITION_UPDATE;+ e->collidable = 0;+}++/* ---------------------------------------------------------------- AngryOshiro (friendlyGhost) */+enum { OS_CHASE, OS_CHARGE, OS_ATTACK, OS_DUMMY, OS_WAITING, OS_HURT };+/* its sprites (oshiro_boss, oshiro_boss_lightning) as tables of the frames the boss plays (smaller than+ * two Sprites in its state); an animation loads when first drawn, the room loads only "idle" */+enum { OA_RESPAWN, OA_IDLE, OA_CHARGE, OA_DASH, OA_HURT, OA_LIGHTNING, OA_BACK, OA_NONE = 255 };+/* transformBack (CS03_Ending): boss38-53, 53 four times more, 53-67 */+static const struct { uint8_t first, n, loop, next; float delay; } OANIM[7] = {+ {0, 13, 0, OA_IDLE, 0.06f}, {13, 8, 1, OA_IDLE, 0.09f}, {21, 13, 0, OA_DASH, 0.08f},+ {34, 4, 1, OA_DASH, 0.06f}, {68, 5, 0, OA_NONE, 0.04f}, {0, 7, 0, OA_NONE, 0.03f}, {38, 35, 0, OA_NONE, 0.06f}};+static int oback(int f) { return f < 16 ? 38 + f : f < 20 ? 53 : 33 + f; }+typedef struct { uint8_t anim, last, frame; float timer; } OSpr; /* anim OA_NONE: ended on its last frame */+static uint16_t osh_boss[73], osh_light[7];+static void ospr_play(OSpr *s, int a, bool restart) {+ if (s->anim == a && !restart) return;+ s->anim = s->last = (uint8_t)a, s->frame = 0, s->timer = 0;+}+static void ospr_update(OSpr *s) {+ if (s->anim == OA_NONE) return;+ s->timer += DT;+ if (s->timer < OANIM[s->anim].delay) return;+ s->timer -= OANIM[s->anim].delay;+ if (++s->frame < OANIM[s->anim].n) return;+ if (OANIM[s->anim].loop) s->frame = 0;+ else if (OANIM[s->anim].next != OA_NONE) s->anim = s->last = OANIM[s->anim].next, s->frame = 0;+ else s->frame = (uint8_t)(OANIM[s->anim].n - 1), s->anim = OA_NONE;+}+static uint16_t ospr_tex(const OSpr *s) {+ int a = s->anim != OA_NONE ? s->anim : s->last;+ return a == OA_LIGHTNING ? osh_light[s->frame] : a == OA_BACK ? osh_boss[oback(s->frame)] : osh_boss[OANIM[a].first + s->frame];+}+typedef struct {+ OSpr spr, lightning;+ float sx, sy, rot;+ float cam_x_off, y_speed, attack_speed, shake_timer, co_wait, col_x;+ int8_t shx, shy;+ uint8_t st, co_step, attack_index, lightning_on, ease_back, respawn_anim, leaving, from_cutscene;+} Osh;+static const EntClass OSHIRO;+static float osh_target_y(Ent *e) {+ Player *p = level_player();+ if (!p) return e->y;+ const Room *rm = room_ptr(e);+ return clampf(e_cym(p->ent), rm->y + 8.f, rm->y + rm->h - 8.f);+}+static float osh_cy(Ent *e) { return e->y + 4; } /* Circle(14) at (3, 4) */+static void osh_set_cy(Ent *e, float cy) { e->y = cy - 4; }+static void osh_box(Ent *e) { /* covers the Circle and the bounce Hitbox(28, 6, -11, -11) */+ Osh *o = ST(e, Osh);+ float l = fminf(o->col_x - 14, -11), r = fmaxf(o->col_x + 14, 17);+ ent_box(e, r - l, 29, l, -11);+}+static void osh_state(Ent *e, Osh *o, int st) { /* StateMachine.State */+ if (o->st == st) return;+ int prev = o->st;+ o->st = (uint8_t)st;+ if (prev == OS_CHARGE) o->shx = o->shy = 0; /* ChargeUpEnd: Sprite.Position = 0 */+ switch (st) { /* begins */+ case OS_CHASE: ospr_play(&o->spr, OA_IDLE, false); break;+ case OS_ATTACK: o->attack_speed = 0, level_dir_shake(v2(1, 0), 0.3f); break;+ case OS_HURT: ospr_play(&o->spr, OA_HURT, true); break;+ }+ o->co_step = 0, o->co_wait = 0; /* the state's coroutine starts over */+}+static void osh_on_player(Ent *e, Player *p) {+ Osh *o = ST(e, Osh);+ Ent *pe = p->ent;+ /* bounce collider first */+ if (collide_rect(pe, e->x - 11, e->y - 11, e->x + 17, e->y - 5) && o->st == OS_ATTACK && e_bottom(pe) <= e->y + o->col_x * 0 + (4 - 14) + 6) {+ level_freeze(0.2f);+ player_bounce(p, e->y - 10 + 2);+ osh_state(e, o, OS_HURT);+ return;+ }+ /* the Circle */+ float cx = e->x + o->col_x, cy = osh_cy(e);+ float nx = clampf(cx, e_left(pe), e_right(pe)), ny = clampf(cy, e_top(pe), e_bottom(pe));+ if ((cx - nx) * (cx - nx) + (cy - ny) * (cy - ny) >= 14 * 14) return;+ if (o->st != OS_HURT && (cx < e_cxm(pe) + 4 || o->spr.anim != OA_RESPAWN)) {+ V2 d = v2sub(e_center(pe), v2(cx, cy));+ player_die(p, v2len(d) > 0 ? v2norm(d) : v2(1, 0), false);+ }+}+static void osh_coroutine(Ent *e, Osh *o) {+ if (o->co_wait > 0) {+ o->co_wait -= DT;+ return;+ }+ switch (o->st) {+ case OS_CHASE: /* ChaseCoroutine */+ if (o->co_step == 0) {+ static const float WAIT[5] = {1, 2, 3, 2, 3};+ if (g_session.mode != M_A) o->co_wait = 1;+ else o->co_wait = WAIT[o->attack_index], o->attack_index = (uint8_t)((o->attack_index + 1) % 5);+ o->co_step = 1;+ } else if (o->co_step == 1) {+ ospr_play(&o->spr, OA_CHARGE, false);+ o->co_wait = 0.7f, o->co_step = 2;+ } else if (o->co_step == 2) {+ o->co_step = 3;+ if (level_player()) osh_state(e, o, OS_CHARGE);+ else ospr_play(&o->spr, OA_IDLE, false);+ }+ break;+ case OS_CHARGE: /* ChargeUpCoroutine */+ if (o->co_step == 0) {+ level_freeze(0.05f);+ o->lightning_on = 1;+ ospr_play(&o->lightning, OA_LIGHTNING, true);+ o->co_wait = 0.3f, o->co_step = 1;+ } else if (o->co_step == 1) {+ o->co_step = 2;+ osh_state(e, o, level_player() ? OS_ATTACK : OS_CHASE);+ }+ break;+ case OS_ATTACK: /* AttackCoroutine */+ if (o->co_step == 0) o->co_wait = 0.1f, o->co_step = 1;+ break;+ }+}+static void osh_update(Ent *e) {+ Osh *o = ST(e, Osh);+ const Room *rm = room_ptr(e);+ float cl = g_level.cam.x;+ if (g_level.transitioning) { /* TransitionListener.OnOut */+ if (e->room != g_level.room_slot) {+ ospr_update(&o->lightning);+ if (o->ease_back) e->x -= 128 * DT;+ }+ return;+ }+ /* base.Update(): the sprites, the state machine (its update, then its coroutine), the shaker */+ ospr_update(&o->spr);+ ospr_update(&o->lightning);+ if (o->lightning_on && o->lightning.anim != OA_LIGHTNING) o->lightning_on = 0; /* OnFinish */+ int next = o->st;+ Player *p = level_player();+ switch (o->st) {+ case OS_CHASE:+ if (o->respawn_anim && o->cam_x_off >= 0) {+ o->col_x = -48;+ e->visible = 1;+ ospr_play(&o->spr, OA_RESPAWN, false);+ o->respawn_anim = 0;+ }+ o->cam_x_off = approach(o->cam_x_off, 20, 80 * DT);+ e->x = cl + o->cam_x_off;+ o->col_x = approach(o->col_x, 3, DT * 128);+ e->collidable = e->visible;+ if (p && o->spr.anim != OA_RESPAWN) osh_set_cy(e, approach(osh_cy(e), osh_target_y(e), o->y_speed * DT));+ next = OS_CHASE;+ break;+ case OS_CHARGE:+ if (level_on_interval(0.05f)) o->shx = (int8_t)shake_val(), o->shy = (int8_t)shake_val();+ o->cam_x_off = approach(o->cam_x_off, 0, 40 * DT);+ e->x = cl + o->cam_x_off;+ if (p) osh_set_cy(e, approach(osh_cy(e), clampf(e_cym(p->ent), rm->y + 8.f, rm->y + rm->h - 8.f), 30 * DT));+ next = OS_CHARGE;+ break;+ case OS_ATTACK:+ e->x += o->attack_speed * DT;+ o->attack_speed = approach(o->attack_speed, 500, 2000 * DT);+ next = OS_ATTACK;+ if (e->x >= cl + 320 + 48) {+ if (o->leaving) {+ ent_remove(e);+ return;+ }+ e->x = cl - 48;+ o->cam_x_off = -48;+ o->respawn_anim = 1;+ e->visible = 0;+ next = OS_CHASE;+ break;+ }+ if (level_on_interval(0.05f)) {+ trail_add(e->x, e->y, ospr_tex(&o->spr), 48, 48, o->sx, o->sy, 0x990000, 0.5f);+ }+ break;+ case OS_WAITING:+ next = (p && (p->speed.x != 0 || p->speed.y != 0) && p->ent->x > rm->x + 48) ? OS_CHASE : OS_WAITING;+ break;+ case OS_HURT:+ e->x += 100 * DT, e->y += 200 * DT;+ next = OS_HURT;+ if (e->y - 10 > rm->y + rm->h + 20) {+ if (o->leaving) {+ ent_remove(e);+ return;+ }+ e->x = cl - 48;+ o->cam_x_off = -48;+ o->respawn_anim = 1;+ e->visible = 0;+ next = OS_CHASE;+ }+ break;+ }+ osh_state(e, o, next);+ if (o->st == OS_CHASE || o->st == OS_CHARGE || o->st == OS_ATTACK) osh_coroutine(e, o);+ if (o->shake_timer > 0) { /* Shaker */+ if ((o->shake_timer -= DT) <= 0) o->shx = o->shy = 0;+ }+ /* Update's own */+ o->sx = approach(o->sx, 1, 0.6f * DT);+ o->sy = approach(o->sy, 1, 0.6f * DT);+ if (!o->respawn_anim) e->visible = e->x > rm->x - 14;+ o->y_speed = approach(o->y_speed, 100, 300 * DT);+ /* Engine.TimeRate: slow motion while it attacks just behind the player (canControlTimeRate: nothing+ * here stops it); TODO Distort.GameRate / Distort.Anxiety (no distortion shader) */+ if (o->st != OS_DUMMY) {+ Player *pl = level_player();+ float cx = e->x + o->col_x;+ if (o->st == OS_ATTACK && o->attack_speed > 200 && pl && !pl->dead && cx < e_cxm(pl->ent) + 4)+ g_time_rate = lerpf(clamped_map(e_cxm(pl->ent) - cx, 30, 80, 0.5f, 1), 1, clamped_map(fabsf(e_cym(pl->ent) - osh_cy(e)), 32, 48, 0, 1));+ else+ g_time_rate = 1;+ }+ osh_box(e);+}+/* an animation not loaded yet: all its frames at once (as spr_draw does) */+static void ospr_load(const OSpr *s) {+ if (res_cached(ospr_tex(s))) return;+ int a = s->anim != OA_NONE ? s->anim : s->last;+ uint16_t ids[36];+ for (int i = 0; i < OANIM[a].n; i++) ids[i] = a == OA_LIGHTNING ? osh_light[i] : a == OA_BACK ? osh_boss[oback(i)] : osh_boss[OANIM[a].first + i];+ res_load(ids, OANIM[a].n);+}+static void osh_render(Ent *e) {+ Osh *o = ST(e, Osh);+ if (o->lightning_on) ospr_load(&o->lightning);+ ospr_load(&o->spr);+ if (o->lightning_on) gfx_tex(ospr_tex(&o->lightning), g_level.cam.x - 2, e->y - 10 + 16 - 32, 0, 0xFFFF, 255); /* Justify (0, 0.5) */+ float sh = o->shake_timer > 0 ? 2.f : 0.f; /* Sprite.Position = shaker.Value * 2 */+ gfx_tex_ex(ospr_tex(&o->spr), e->x + o->shx * sh, e->y + o->shy * sh, 48, 48, o->sx, o->sy, o->rot, 0xFFFF, 255, 0);+ light_add(e->x, e->y, 0xFFFFFF, 1, 32, 64);+}+static const EntClass OSHIRO = {.name = "friendlyGhost", .size = sizeof(Osh), .update = osh_update, .render = osh_render,+ .on_player = osh_on_player, .kind = KIND_PCOLLIDE};+static void new_oshiro(float x, float y, bool from_cutscene) {+ if (level_get_flag("oshiroEnding") || (!level_get_flag("oshiro_resort_roof") && !strcmp(level_room_name_of(g_level.rooms[g_level.room_slot].index), "roof00")))+ return;+ Ent *e = ent_new(&OSHIRO, x, y);+ if (!e) return;+ e->depth = -12500;+ e->visible = 0;+ e->tags = TAG_TRANSITION_UPDATE;+ Osh *o = ST(e, Osh);+ char pth[40];+ for (int i = 0; i < 73; i++) osh_boss[i] = tex(path2(pth, "characters/oshiro/boss", NULL, i));+ for (int i = 0; i < 7; i++) osh_light[i] = tex(path2(pth, "characters/oshiro/lightning", NULL, i));+ ospr_play(&o->spr, OA_IDLE, true);+ o->lightning.anim = o->lightning.last = OA_NONE;+ o->lightning.last = OA_LIGHTNING;+ o->sx = o->sy = 1;+ o->col_x = 3;+ o->y_speed = from_cutscene ? 0 : 100;+ o->from_cutscene = from_cutscene;+ o->st = 0xFF;+ osh_state(e, o, OS_CHASE); /* the StateMachine's EntityAdded */+ if (!from_cutscene) { /* Added */+ osh_state(e, o, OS_WAITING);+ osh_set_cy(e, osh_target_y(e));+ o->cam_x_off = -48;+ } else+ o->cam_x_off = x - g_level.cam.x;+ osh_box(e);+}+/* OshiroTrigger */+typedef struct { uint8_t state; } OshTrig;+static void oshtrig_enter(Ent *e, Player *p) {+ (void)p;+ if (ST(e, OshTrig)->state) {+ const Room *rm = room_ptr(e);+ new_oshiro(rm->x - 32.f, rm->y + rm->h / 2.f, false);+ } else+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &OSHIRO && g_ents[i].dead != 1) {+ ST(&g_ents[i], Osh)->leaving = 1;+ break;+ }+ ent_remove(e);+}+static const EntClass OSHTRIG = {.name = "oshiroTrigger", .size = sizeof(OshTrig), .on_enter = oshtrig_enter, .kind = KIND_TRIGGER};++/* ---------------------------------------------------------------- ResortMirror */+/* the glass (glassbg's middle), its shine (glassfg) at shineAlpha x mirrorAlpha, and the frame (its own entity,+ * in front); the Badeline of the suite's cutscene walks in it (a BadelineDummy cut to the glass). The+ * reflections of the player and of Oshiro are not drawn */+typedef struct { Sprite glass; float shine, alpha; int16_t evil; uint8_t smashed, breaking, appear, fading, step; } RMirror;+static uint16_t rmirror_frame, rmirror_bg, rmirror_broken, rmirror_fg;+static const EntClass RMIRROR;+static void rmirror_layer(uint16_t *strip, int sy0, int sy1, void *ctx) {+ Ent *e = ctx;+ RMirror *m = ST(e, RMirror);+ Tex fg;+ if (!tex_get(rmirror_fg, &fg) || fg.w > (int)sizeof rowbuf) return;+ int n;+ const uint16_t *col = pal_colors(fg.pal, &n);+ const uint8_t *al = pal_alpha(fg.pal);+ const int W = 30, H = 27;+ int ox = vx(e->x - W / 2.f), oy = vy(e->y - H);+ int num = -(int)fmodf(g_level.cam.y * 0.8f, 73);+ for (int k = 0; k < 2; k++) { /* DrawJustified((W / 2, num), (0.5, 1)) and the second one (it uses H / 2) */+ int x0 = k ? H / 2 - fg.fw / 2 : W / 2 - fg.fw / 2, y0 = (k ? num - fg.fh : num) - fg.fh;+ for (int r = 0; r < fg.h; r++) {+ int y = y0 + fg.oy + r, Y = oy + y;+ if (y < 0 || y >= H || Y < sy0 || Y >= sy1) continue;+ tex_row_idx(&fg, r, rowbuf);+ for (int i = 0; i < fg.w; i++) {+ int x = x0 + fg.ox + i, X = ox + x;+ if (!rowbuf[i] || x < 0 || x >= W || (unsigned)X >= VIEW_W) continue;+ sp_texel(strip + (Y - sy0) * VIEW_W + X, col, al, rowbuf[i], 0xFFFF, (int)(m->shine * m->alpha * 256), false);+ }+ }+ }+}+static Ent *rmirror_evil(RMirror *m) { return m->evil >= 0 && g_ents[m->evil].cls && g_ents[m->evil].dead != 1 ? &g_ents[m->evil] : NULL; }+static void rmirror_update(Ent *e) {+ RMirror *m = ST(e, RMirror);+ Ent *ev = rmirror_evil(m);+ if (m->appear && ev && !ch2_bdummy_walk_to(ev, e->x, 64)) m->appear = 0; /* EvilAppearRoutine */+ if (m->fading) { /* FadeLights */+ g_level.lighting = approach(g_level.lighting, 0.35f, DT * 0.1f);+ if (g_level.lighting == 0.35f) m->fading = 0;+ }+ if (m->breaking) spr_update(&m->glass);+}+static void rmirror_render(Ent *e) {+ RMirror *m = ST(e, RMirror);+ gfx_tex_part(m->smashed ? rmirror_broken : rmirror_bg, e->x - 15, e->y - 27, 12, 2, 30, 27, 0, 0xFFFF, 255);+}+static const EntClass RMIRROR = {.name = "resortmirror", .size = sizeof(RMirror), .update = rmirror_update, .render = rmirror_render};+static void rmframe_render(Ent *e) { /* the target's glass over what it shows, then the frame */+ Ent *me = &g_ents[*ST(e, int16_t)];+ if (me->cls == &RMIRROR && !ST(me, RMirror)->smashed) {+ RMirror *m = ST(me, RMirror);+ if (m->breaking) { /* the breaking glass (a 54 x 29 frame cut to the 30 x 27 glass) */+ Tex t;+ uint16_t tx = spr_tex(&m->glass);+ if (tx != 0xFFFF && tex_get(tx, &t))+ gfx_tex_part(tx, me->x - 15, me->y - 27, 12, 2, 30, 27, 0, 0xFFFF, (uint8_t)(clampf(m->shine * m->alpha, 0, 1) * 255));+ } else+ tex_touch(rmirror_fg), gfx_custom(rmirror_layer, me, vy(me->y - 27), vy(me->y));+ }+ gfx_tex(rmirror_frame, e->x - 16, e->y - 39, 0, 0xFFFF, 255);+}+static const EntClass RMFRAME = {.name = "resortmirrorFrame", .size = sizeof(int16_t), .render = rmframe_render};+static void rmirror_evil_appear(Ent *e) { /* EvilAppear */+ RMirror *m = ST(e, RMirror);+ Ent *ev = ch2_bdummy_new(v2(e->x + 23, e->y)); /* (mirror.Width + 8, mirror.Height) in the glass */+ m->evil = ev ? (int16_t)(ev - g_ents) : -1;+ if (ev) set_depth(ev, 9499), ch2_bdummy_clip(ev, e->x - 15, e->y - 27, e->x + 15, e->y, m->alpha);+ m->appear = m->fading = 1;+}+static bool rmirror_smash(Ent *e) { /* SmashRoutine */+ RMirror *m = ST(e, RMirror);+ Ent *ev = rmirror_evil(m);+ switch (m->step) {+ case 0:+ if (ev && ch2_bdummy_float_to(ev, v2(e->x, e->y - 8), 0, 0)) return true;+ spr_init(&m->glass, SB_glass);+ spr_play(&m->glass, A_glass_break, false);+ m->breaking = 1, m->step = 1;+ return true;+ case 1:+ if (m->glass.anim == A_glass_break) {+ if (m->glass.frame == 7) level_shake(0.3f);+ m->shine = approach(m->shine, 1, DT * 2);+ m->alpha = approach(m->alpha, 1, DT * 2);+ if (ev) ch2_bdummy_clip(ev, e->x - 15, e->y - 27, e->x + 15, e->y, m->alpha);+ return true;+ }+ level_shake(0.3f);+ for (float x = -27; x < 27; x += 8)+ for (float y = -29; y < 0; y += 8)+ if (rndf() < 0.5f) particles_emit(PL_MID, &P_DreamMirror_P_Shatter, 2, v2(e->x + x + 4, e->y + y + 4), v2(8, 8), atan2f(y, x));+ if (ev) ent_remove(ev); /* evil = null: no longer drawn in the glass */+ m->evil = -1;+ m->step = 2;+ /* fall through */+ default:+ return false;+ }+}+static void rmirror_set_broken(Ent *e) { /* Broken */+ RMirror *m = ST(e, RMirror);+ Ent *ev = rmirror_evil(m);+ if (ev) ent_remove(ev);+ m->evil = -1;+ m->smashed = 1, m->breaking = 0;+}+static void new_rmirror(const EData *d) {+ Ent *e = ent_new(&RMIRROR, d->x, d->y);+ if (!e) return;+ e->depth = 9500;+ e->collidable = 0;+ RMirror *m = ST(e, RMirror);+ m->smashed = level_get_flag("oshiro_resort_suite");+ m->shine = m->alpha = 0.7f;+ m->evil = -1;+ rmirror_frame = tex("objects/mirror/resortframe");+ rmirror_bg = tex("objects/mirror/glassbg");+ rmirror_broken = tex("objects/mirror/glassbreak09");+ rmirror_fg = tex("objects/mirror/glassfg");+ Ent *f = ent_new(&RMFRAME, d->x, d->y);+ if (f) f->depth = 9000, f->collidable = 0, *ST(f, int16_t) = (int16_t)(e - g_ents);+}++/* ---------------------------------------------------------------- PicoConsole */+typedef struct { Talk talk; Walk walk; float wait; uint8_t step; } Pico;+static uint16_t pico_tex;+static void pico_update(Ent *e) {+ Pico *c = ST(e, Pico);+ Player *p = level_player();+ if (talk_update(&c->talk, e) && !c->step && p) { /* OnInteract */+ c->step = 1;+ player_set_state(p, ST_DUMMY);+ c->walk = walk_exact((int)floorf(e->x) - 6); /* yield return DummyWalkToExact */+ return;+ }+ if (!c->step || !p) return;+ if (c->wait > 0) {+ c->wait -= DT;+ return;+ }+ switch (c->step) {+ case 1:+ if (player_walk(p, &c->walk)) break;+ p->facing = 1;+ c->wait = 0.5f, c->step = 2;+ break;+ case 2: /* TODO: the PICO-8 game (Emulator) behind a SpotlightWipe */+ c->wait = 0.25f, c->step = 3;+ break;+ default:+ player_set_state(p, ST_NORMAL);+ c->step = 0;+ break;+ }+}+static void pico_render(Ent *e) { gfx_tex(pico_tex, e->x - 24, e->y - 32, 0, 0xFFFF, 255); }+static const EntClass PICO = {.name = "picoconsole", .size = sizeof(Pico), .update = pico_update, .render = pico_render, .kind = KIND_TALK};+static void new_pico(const EData *d) {+ Ent *e = ent_new(&PICO, d->x, d->y);+ if (!e) return;+ e->depth = 1000;+ e->tags = TAG_TRANSITION_UPDATE | TAG_PAUSE_UPDATE;+ e->collidable = 0;+ ch1_talk_add(e, &ST(e, Pico)->talk, -12, -8, 24, 8, v2(0, -24));+ pico_tex = tex("objects/pico8Console");+}++/* ---------------------------------------------------------------- Key */+typedef struct {+ Sprite spr;+ Wiggler wig;+ Tween tw;+ V2 from, to, ctrl;+ float wobble, wait, alarm, light;+ uint32_t id;+ uint8_t used, started, turning, step, wobble_on, gain_pending;+} Key;+static const EntClass KEY;+static bool keys_restored;+static bool session_has_key(uint32_t id) {+ for (int i = 0; i < g_session.nkeys && i < 4; i++)+ if (g_session.keys[i] == id) return true;+ return false;+}+static void session_add_key(uint32_t id) {+ if (!session_has_key(id) && g_session.nkeys < 4) g_session.keys[g_session.nkeys++] = id;+}+static void session_remove_key(uint32_t id) {+ for (int i = 0; i < g_session.nkeys; i++)+ if (g_session.keys[i] == id) {+ memmove(g_session.keys + i, g_session.keys + i + 1, sizeof(uint32_t) * (size_t)(g_session.nkeys - i - 1));+ g_session.nkeys--;+ return;+ }+}+static void key_on_player(Ent *e, Player *p) {+ Key *k = ST(e, Key);+ (void)p;+ particles_emit(PL_MID, &P_Key_P_Collect, 10, v2(e->x, e->y), v2(3, 3), P_Key_P_Collect.direction);+ leader_gain(e, 0.5f, true);+ e->collidable = 0;+ level_set_do_not_load(k->id);+ session_add_key(k->id);+ g_session.dashes_at_level_start = g_session.dashes; /* UpdateLevelStartDashes */+ wiggler_restart(&k->wig);+ e->depth = -1000000;+ ents_mark_unsorted();+ /* (keys with two nodes start a cassette fly: none here) */+}+/* Key.UseRoutine, stepped */+static void key_use_step(Ent *e, Key *k) {+ if (k->wait > 0) {+ k->wait -= DT;+ return;+ }+ switch (k->step) {+ case 1: {+ bool end = tween_update(&k->tw);+ V2 at = curve_point(k->from, k->to, k->ctrl, ease_cube_out(k->tw.percent));+ e->x = at.x, e->y = at.y;+ k->spr.rate = 1 + ease_cube_out(k->tw.percent) * 2;+ if (end) k->step = 2;+ break;+ }+ case 2:+ if (k->spr.frame != 4) break;+ for (int i = 0; i < 16; i++) particles_emit1(PL_FG, &P_Key_P_Insert, e_center(e), PI_F / 8 * i);+ spr_play(&k->spr, A_key_enter, false);+ k->wait = 0.3f, k->step = 3;+ break;+ case 3:+ tween_start(&k->tw, 0.3f);+ k->step = 4;+ break;+ case 4: {+ bool end = tween_update(&k->tw);+ k->spr.rot = ease_cube_in(k->tw.percent) * (PI_F / 2);+ if (!end) break;+ k->alarm = 1; /* then the light fades over 1 s and the key goes */+ k->wait = 0.2f, k->step = 5;+ break;+ }+ case 5:+ for (int i = 0; i < 8; i++) particles_emit1(PL_FG, &P_Key_P_Insert, e_center(e), PI_F / 4 * i);+ k->spr.visible = 0;+ k->turning = 0;+ k->step = 6;+ break;+ }+}+static void key_update(Ent *e) {+ Key *k = ST(e, Key);+ keys_restored = false;+ if (k->gain_pending && level_player()) { /* Key(player, id): it follows at once */+ Player *p = level_player();+ e->x = p->ent->x - 12 * p->facing, e->y = p->ent->y - 8;+ leader_gain(e, 0.5f, true);+ k->gain_pending = 0;+ }+ if (g_level.transitioning) { /* TransitionListener.OnOut */+ k->started = 0;+ if (!k->used && k->step) {+ k->step = 0, k->turning = 0, k->tw.active = false;+ e->visible = 1, k->spr.visible = 1, k->spr.rate = 1, k->spr.sx = k->spr.sy = 1, k->spr.rot = 0;+ spr_play(&k->spr, A_key_idle, false);+ k->wig.active = false;+ leader_set_move(e, true);+ }+ return;+ }+ if (k->wobble_on) k->wobble += DT * 4;+ /* base.Update(): follower, sprite, wiggler, the shimmer, the coroutine, the alarm */+ leader_tick(e);+ spr_update(&k->spr);+ wiggler_update(&k->wig);+ if (k->spr.visible && level_on_interval(0.1f))+ particles_emit(PL_FG, &P_Key_P_Shimmer, 1, v2(e->x, e->y), v2(6, 6), P_Key_P_Shimmer.direction);+ if (k->step) key_use_step(e, k);+ if (k->alarm > 0 && (k->alarm -= DT) <= 0) k->light = 1, k->alarm = -1;+ if (k->alarm < 0) {+ k->light -= DT;+ if (k->light <= 0) ent_remove(e);+ }+}+static void key_render(Ent *e) {+ Key *k = ST(e, Key);+ Sprite s = k->spr;+ s.sx = s.sy = (k->step ? 1 : 1) * (1 + k->wig.value * 0.35f);+ spr_draw(&s, e->x, e->y + (k->wobble_on ? sinf(k->wobble) : 0));+ float la = k->alarm < 0 ? fmaxf(k->light, 0) : 1;+ light_add(e->x, e->y, 0xFFFFFF, la, 32, 48);+}+static const EntClass KEY = {.name = "key", .size = sizeof(Key), .update = key_update, .render = key_render, .on_player = key_on_player,+ .kind = KIND_PCOLLIDE};+static Ent *make_key(float x, float y, uint32_t id) {+ Ent *e = ent_new(&KEY, x, y);+ if (!e) return NULL;+ ent_box(e, 12, 12, -6, -6);+ e->tags = TAG_TRANSITION_UPDATE;+ Key *k = ST(e, Key);+ k->id = id;+ spr_init(&k->spr, SB_key);+ spr_play(&k->spr, A_key_idle, true);+ wiggler_init(&k->wig, 0.4f, 4);+ return e;+}+static void new_key(const EData *d) {+ uint32_t id = level_entity_hash(d);+ if (level_do_not_load(id)) return;+ make_key(d->x, d->y, id);+}+/* Level.LoadLevel: the session's keys follow the new player */+static void restore_keys(void) {+ for (int i = 0; i < g_session.nkeys && i < 4; i++) {+ Ent *e = make_key((float)g_session.rx, (float)g_session.ry - 8, g_session.keys[i]);+ if (!e) continue;+ e->collidable = 0;+ e->depth = -1000000;+ ST(e, Key)->gain_pending = 1;+ }+}++/* ---------------------------------------------------------------- LockBlock */+typedef struct { Sprite spr; float wait; int16_t key; uint32_t id; uint8_t opening, step, bank; } Lock;+/* the sprites lockdoor_<sprite>: only those some map's assets ask for exist in data.bin */+static int lock_anim(const Lock *l, int which) { /* 0 idle, 1 open, 2 burst */+ (void)which;+ switch (l->bank) {+#ifdef SB_lockdoor_temple_a+ case 1: return which == 0 ? A_lockdoor_temple_a_idle : which == 1 ? A_lockdoor_temple_a_open : A_lockdoor_temple_a_burst;+#endif+#ifdef SB_lockdoor_temple_b+ case 2: return which == 0 ? A_lockdoor_temple_b_idle : which == 1 ? A_lockdoor_temple_b_open : A_lockdoor_temple_b_burst;+#endif+#ifdef SB_lockdoor_moon+ case 3: return which == 0 ? A_lockdoor_moon_idle : which == 1 ? A_lockdoor_moon_open : A_lockdoor_moon_burst;+#endif+#ifdef SB_lockdoor_wood+ case 0: return which == 0 ? A_lockdoor_wood_idle : which == 1 ? A_lockdoor_wood_open : A_lockdoor_wood_burst;+#endif+ default: return 0;+ }+}+static int lock_bank(int b) {+ switch (b) {+#ifdef SB_lockdoor_temple_a+ case 1: return SB_lockdoor_temple_a;+#endif+#ifdef SB_lockdoor_temple_b+ case 2: return SB_lockdoor_temple_b;+#endif+#ifdef SB_lockdoor_moon+ case 3: return SB_lockdoor_moon;+#endif+#ifdef SB_lockdoor_wood+ case 0: return SB_lockdoor_wood;+#endif+ default: return -1;+ }+}+/* its PlayerCollider is Circle(60) at (16, 16), not its solid box: checked from its update */+static void lock_on_player(Ent *e, Player *p) {+ Lock *l = ST(e, Lock);+ if (l->opening) return;+ float cx = e->x + 16, cy = e->y + 16;+ Ent *pe = p->ent;+ float nx = clampf(cx, e_left(pe), e_right(pe)), ny = clampf(cy, e_top(pe), e_bottom(pe));+ if ((cx - nx) * (cx - nx) + (cy - ny) * (cy - ny) >= 60 * 60) return;+ for (int i = 0; i < leader_count(); i++) {+ Ent *f = leader_follower(i);+ if (f->cls != &KEY || ST(f, Key)->started) continue;+ /* TryOpen: nothing solid between the player and the block */+ e->collidable = 0;+ V2 a = player_center(p), b = e_center(e);+ bool blocked = false;+ for (int s = 0; s <= 16 && !blocked; s++) {+ V2 q = v2add(a, v2mul(v2sub(b, a), s / 16.f));+ blocked = point_solid(q.x, q.y);+ }+ if (!blocked) {+ l->opening = 1;+ ST(f, Key)->started = 1;+ l->key = ent_ref(f);+ /* Key.UseRoutine(Center + (0, 2)) */+ Key *k = ST(f, Key);+ k->turning = 1;+ leader_set_move(f, false);+ wiggler_restart(&k->wig);+ k->wobble_on = 0;+ k->from = v2(f->x, f->y);+ k->to = v2add(b, v2(0, 2));+ k->ctrl = v2add(v2mul(v2add(k->to, k->from), 0.5f), v2(0, -48));+ tween_start(&k->tw, 1);+ k->step = 1;+ l->wait = 1.2f, l->step = 1;+ }+ e->collidable = 1;+ break;+ }+}+static void lock_update(Ent *e) {+ Lock *l = ST(e, Lock);+ spr_update(&l->spr);+ plat_update(e);+ Player *p = level_player();+ if (p && !p->dead && !l->opening) lock_on_player(e, p);+ if (!l->step) return;+ if (l->wait > 0) {+ l->wait -= DT;+ return;+ }+ Ent *k = ent_at(l->key, &KEY);+ switch (l->step) {+ case 1:+ level_set_do_not_load(l->id);+ if (k) { /* Key.RegisterUsed */+ ST(k, Key)->used = 1;+ leader_lose(k);+ session_remove_key(ST(k, Key)->id);+ }+ l->step = 2;+ /* fall through */+ case 2:+ if (k && ST(k, Key)->turning) break;+ e->tags |= TAG_TRANSITION_UPDATE;+ e->collidable = 0;+ spr_play(&l->spr, lock_anim(l, 1), false);+ l->step = 3;+ break;+ case 3:+ if (spr_is(&l->spr, lock_anim(l, 1))) break;+ level_shake(0.3f);+ spr_play(&l->spr, lock_anim(l, 2), false);+ l->step = 4;+ break;+ case 4:+ if (spr_is(&l->spr, lock_anim(l, 2))) break;+ ent_remove(e);+ break;+ }+}+static void lock_render(Ent *e) { spr_draw(&ST(e, Lock)->spr, e->x + 16, e->y + 16); }+static void lock_awake(Ent *e) { plat_static_movers_attach(e); }+static const EntClass LOCK = {.name = "lockBlock", .size = sizeof(Lock), .update = lock_update, .render = lock_render, .awake = lock_awake,+ .kind = KIND_SOLID};+static void new_lock(const EData *d) {+ uint32_t id = level_entity_hash(d);+ if (level_do_not_load(id)) return;+ Ent *e = ent_new(&LOCK, d->x, d->y);+ if (!e) return;+ ent_box(e, 32, 32, 0, 0);+ Lock *l = ST(e, Lock);+ l->id = id;+ l->key = -1;+ const char *sp = EAS(d, lockBlock, sprite);+ l->bank = !strcmp(sp, "temple_a") ? 1 : !strcmp(sp, "temple_b") ? 2 : !strcmp(sp, "moon") ? 3 : 0;+ if (lock_bank(l->bank) >= 0) spr_init(&l->spr, lock_bank(l->bank)), spr_play(&l->spr, lock_anim(l, 0), true);+ else l->spr.visible = 0;+ /* TODO: stepMusicProgress (no music) */+}++/* ---------------------------------------------------------------- BlockField, Killbox */+static const EntClass BLOCKFIELD = {.name = "blockField", .size = 0, .kind = KIND_BLOCKFIELD};+static void killbox_on_player(Ent *e, Player *p) { (void)e, player_die(p, v2(0, 0), false); }+static void killbox_update(Ent *e) {+ Ent *p = level_player_ent();+ if (!e->collidable) {+ if (p && e_bottom(p) < e_top(e) - 32) e->collidable = 1;+ } else if (p && e_top(p) > e_bottom(e) + 32)+ e->collidable = 0;+}+static const EntClass KILLBOX3 = {.name = "killbox", .size = 0, .update = killbox_update, .on_player = killbox_on_player,+ .kind = KIND_KILLBOX | KIND_PCOLLIDE};++static float area_darkness(void);+/* ---------------------------------------------------------------- Oshiro: NPC03_Oshiro_* and OshiroSprite */+enum { OK_LOBBY, OK_HALL1, OK_HALL2, OK_CLUTTER, OK_BREAKDOWN, OK_SUITE, OK_ROOF };+typedef struct {+ Talk talk;+ Sprite spr;+ Wiggler wig; /* OshiroSprite's */+ Move move; /* MoveToAndRemove, the pacing's MoveTo */+ NpcWalk nw;+ Co co; /* its coroutines: the pacing, the suite's talk */+ Ent *tb;+ V2 home, nodes[3];+ float light, light_y, bloom, pace_t;+ uint8_t kind, has_talk, light_on, changes, turn_invisible, talked, in_routine, sections, removing, pacing;+} Osh3;+static const EntClass OSH3;+static void osh_pop(Osh3 *o, int anim, bool flip) { /* OshiroSprite.Pop */+ if (o->spr.anim == anim) return;+ spr_play(&o->spr, anim, false);+ if (flip) o->spr.sx = -o->spr.sx;+ wiggler_restart(&o->wig);+}+static void osh_remove_at(Ent *e, Osh3 *o, V2 to) { /* MoveToAndRemove */+ memset(&o->move, 0, sizeof o->move);+ o->move.target = to, o->move.flags = MV_REMOVE;+ o->removing = 1, o->pacing = 0;+ (void)e;+}+static bool osh_move(Ent *e, Move *m) { return ch1_move_to(e, &ST(e, Osh3)->spr, m, 80, A_oshiro_move, A_oshiro_idle); }+static void osh_talk(Ent *e, Osh3 *o, Player *p);+static void osh_trigger(Ent *e, Osh3 *o, Player *p);+static void osh_pace(Ent *e, Osh3 *o) { /* NPC03_Oshiro_Cluttter.Pace */+ Co *c = &o->co;+ CO_BEGIN(c);+ for (;;) {+ wiggler_restart(&o->wig);+ memset(&o->move, 0, sizeof o->move), o->move.target = v2add(o->home, v2(-20, 0)); /* PaceLeft */+ CO_NEST(c, osh_move(e, &o->move));+ while (o->pace_t < 2.266f) CO_YIELD(c);+ o->pace_t = 0;+ wiggler_restart(&o->wig);+ memset(&o->move, 0, sizeof o->move), o->move.target = o->home; /* PaceRight */+ CO_NEST(c, osh_move(e, &o->move));+ while (o->pace_t < 2.266f) CO_YIELD(c);+ o->pace_t = 0;+ }+ CO_END(c);+}+static void osh_suite_talk(Ent *e, Osh3 *o) { /* NPC03_Oshiro_Suite.Talk */+ static const char *const SAD[7] = {"CH3_OSHIRO_SUITE_SAD0", "CH3_OSHIRO_SUITE_SAD1", "CH3_OSHIRO_SUITE_SAD2", "CH3_OSHIRO_SUITE_SAD3",+ "CH3_OSHIRO_SUITE_SAD4", "CH3_OSHIRO_SUITE_SAD5", "CH3_OSHIRO_SUITE_SAD6"};+ Co *c = &o->co;+ CO_BEGIN(c);+ o->in_routine = (uint8_t)ch1_counter("oshiroSuiteSadConversation");+ CO_NEST(c, npc_approach(&o->nw, e, NULL, 12, 0));+ CO_SAY(c, o->tb, SAD[o->in_routine % 7], NULL, NULL);+ player_free(); /* PlayerLeave */+ CO_YIELD(c);+ o->in_routine = (uint8_t)((o->in_routine + 1) % 7);+ if (!o->in_routine) o->in_routine = 1;+ ch1_set_counter("oshiroSuiteSadConversation", o->in_routine);+ o->pacing = 0;+ CO_END(c);+}+static void osh3_update(Ent *e) {+ Osh3 *o = ST(e, Osh3);+ Player *p = level_player();+ /* the components: the sprite (OshiroSprite.Update), its wiggler, the talker, the coroutines */+ spr_update(&o->spr);+ int bank, idle;+ if (o->changes && textbox_portrait(&bank, &idle)) {+ if (bank == SB_portrait_oshiro && (idle == A_portrait_oshiro_idle_sidehappy || idle == A_portrait_oshiro_idle_sideworried ||+ idle == A_portrait_oshiro_idle_sidesuspicious)) {+ if (o->spr.anim == A_oshiro_idle) osh_pop(o, A_oshiro_side, true);+ } else if (o->spr.anim == A_oshiro_side)+ osh_pop(o, A_oshiro_idle, true);+ }+ if (o->turn_invisible && o->spr.visible) {+ const Room *rm = g_level.room;+ o->spr.visible = e->x > rm->x - 8 && e->y > rm->y - 8 && e->x < rm->x + rm->w + 8 && e->y < rm->y + rm->h + 16;+ }+ if (o->wig.active) {+ wiggler_update(&o->wig);+ float k = o->wig.value * 0.2f;+ o->spr.sx = (o->spr.sx < 0 ? -1 : 1) * (1 + k), o->spr.sy = 1 - k;+ }+ if (o->has_talk && talk_update(&o->talk, e) && p) osh_talk(e, o, p);+ if (o->pacing == 1) osh_pace(e, o);+ else if (o->pacing == 2) osh_suite_talk(e, o);+ if (o->removing) osh_move(e, &o->move);+ if (o->light_on == 1) { /* NPC.Update: its Light in the level's bounds */+ const Room *rm = g_level.room;+ bool in = e->x > rm->x - 16 && e->y > rm->y - 16 && e->x < rm->x + rm->w + 16 && e->y < rm->y + rm->h + 16;+ o->light = approach(o->light, in && !g_level.transitioning ? 1 : 0, DT * 2);+ }+ osh_trigger(e, o, p);+}+static void osh3_render(Ent *e) {+ Osh3 *o = ST(e, Osh3);+ if (o->spr.visible) draw_npc(&o->spr, e->x, e->y);+ if (o->light_on) light_add(e->x, e->y + (o->light_on == 2 ? -8 + o->light_y : -16), 0xFFFFFF, o->light, 32, 64);+ if (o->bloom > 0) bloom_add(e->x, e->y - 8, o->bloom, 16);+}+static const EntClass OSH3 = {.size = sizeof(Osh3), .name = "NPC03_Oshiro", .update = osh3_update, .render = osh3_render};+static Ent *find_osh(int kind) {+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &OSH3 && g_ents[i].dead != 1 && ST(&g_ents[i], Osh3)->kind == kind) return &g_ents[i];+ return NULL;+}++/* OshiroLobbyBell: talking to it rings it (a sound), once Oshiro has gone */+static void bell_update(Ent *e) {+ Talk *t = ST(e, Talk);+ if (!t->enabled && !find_osh(OK_LOBBY)) t->enabled = true;+ talk_update(t, e);+}+static const EntClass BELL = {.size = sizeof(Talk), .name = "OshiroLobbyBell", .update = bell_update};++/* ---------------------------------------------------------------- CS03_OshiroLobby */+typedef struct {+ Cutscene cs;+ Ent *osh, *tb;+ Walk walk;+ Step step;+ Co ev;+ Tween tw;+ float start_light, from_y;+ int8_t evi;+ uint8_t sparks, tw_kind;+} Lobby;+static bool lobby_event(void *ctx, int index) { /* ZoomOut */+ Lobby *s = ST((Ent *)ctx, Lobby);+ Co *c = ev_start(&s->ev, &s->evi, index);+ EV_BEGIN;+ EV_WAIT(0.2f);+ step_reset(&s->step);+ EV_NEST(zoom_back(&s->step, 0.5f));+ EV_WAIT(0.2f);+ EV_END;+}+static void gdoor_open(Ent *e, bool instant);+static void lobby_doors(bool instant) { /* every MrOshiroDoor: Open / InstantOpen */+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls && g_ents[i].dead != 1 && g_ents[i].cls->name && !strcmp(g_ents[i].cls->name, "oshirodoor")) gdoor_open(&g_ents[i], instant);+}+static void lobby_end(Ent *e, bool skipped) {+ Lobby *s = ST(e, Lobby);+ player_free();+ if (skipped) lobby_doors(true);+ g_level.lighting = s->start_light;+ level_set_flag("oshiro_resort_talked_1", true);+ if (skipped && s->osh->cls == &OSH3) ent_remove(s->osh);+}+static void lobby_update(Ent *e) {+ Lobby *s = ST(e, Lobby);+ Ent *oe = s->osh;+ Osh3 *o = ST(oe, Osh3);+ Player *p = &g_player;+ if (s->sparks && level_on_interval(0.025f)) {+ V2 at = v2add(v2(oe->x, oe->y - 12), v2((float)((4 + rndi(8)) * (rndi(2) ? 1 : -1)), (float)((4 + rndi(8)) * (rndi(2) ? 1 : -1))));+ V2 d = v2sub(at, v2(oe->x, oe->y));+ particles_emit1(PL_MID, &P_NPC03_Oshiro_Lobby_P_AppearSpark, at, atan2f(d.y, d.x));+ }+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ s->start_light = g_level.lighting;+ s->from_y = oe->y;+ player_hold(p);+ CO_WAIT(c, 0.5f);+ s->walk = walk_to(oe->x - 16);+ CO_NEST(c, player_walk(p, &s->walk));+ p->facing = 1;+ CO_WAIT(c, 1.4f);+ level_shake(0.3f);+ for (g_level.lighting += 0.5f; g_level.lighting > s->start_light;) {+ g_level.lighting -= DT * 4;+ CO_YIELD(c);+ }+ o->light_on = 2, o->light = 0, o->light_y = -48; /* its VertexLight and BloomPoint (the level's spotlight) */+ oe->y -= 16;+ tween_start(&s->tw, 0.5f), s->tw_kind = 1;+ CO_YIELD(c);+ while (s->tw.active) {+ tween_update(&s->tw);+ o->light = o->bloom = s->tw.percent;+ o->light_y = lerpf(-48, 0, s->tw.percent);+ g_level.lighting = lerpf(s->start_light, 1, ease_cube_out(s->tw.percent));+ if (s->tw.active) CO_YIELD(c);+ }+ CO_WAIT(c, 0.2f);+ step_reset(&s->step);+ CO_NEST(c, zoom_to(&s->step, v2(170, 126), 2, 0.5f));+ CO_WAIT(c, 0.6f);+ level_shake(0.3f);+ o->spr.visible = 1;+ spr_play(&o->spr, A_oshiro_appear, false);+ s->walk = walk_exact((int)(p->ent->x - 12));+ s->walk.flags = WALK_BACKWARDS;+ CO_NEST(c, player_walk(p, &s->walk));+ p->dummy_auto_animate = false;+ spr_play(&p->spr, A_player_shaking, false);+ CO_WAIT(c, 0.6f);+ s->sparks = 1;+ CO_WAIT(c, 0.4f);+ s->sparks = 0;+ CO_WAIT(c, 0.2f);+ level_shake(0.3f);+ CO_WAIT(c, 1.4f);+ tween_start(&s->tw, 0.5f); /* the lights back: in parallel with Oshiro going down */+ for (;;) {+ if (s->tw.active) {+ tween_update(&s->tw);+ g_level.lighting = lerpf(1, s->start_light, s->tw.percent);+ o->bloom = 1 - s->tw.percent;+ }+ if (oe->y == s->from_y) break;+ oe->y = approach(oe->y, s->from_y, DT * 40);+ CO_YIELD(c);+ }+ while (s->tw.active) {+ CO_YIELD(c);+ tween_update(&s->tw);+ g_level.lighting = lerpf(1, s->start_light, s->tw.percent);+ o->bloom = 1 - s->tw.percent;+ }+ p->dummy_auto_animate = true;+ s->evi = -1;+ CO_SAY(c, s->tb, "CH3_OSHIRO_FRONT_DESK", lobby_event, e);+ lobby_doors(false);+ osh_remove_at(oe, o, v2((float)(g_level.room->x + g_level.room->w + 64), oe->y));+ CO_WAIT(c, 1.5f);+ cutscene_end(e);+ return;+ CO_END(c);+}+static const EntClass LOBBY = {.size = sizeof(Lobby), .name = "CS03_OshiroLobby", .update = lobby_update};++/* ---------------------------------------------------------------- CS03_OshiroHallway1, CS03_OshiroHallway2 */+typedef struct { Cutscene cs; Ent *osh, *tb; uint8_t two; } Hall;+static void hall_end(Ent *e, bool skipped) {+ Hall *s = ST(e, Hall);+ player_free();+ level_set_flag(s->two ? "oshiro_resort_talked_3" : "oshiro_resort_talked_2", true);+ if (skipped && s->osh->cls == &OSH3) ent_remove(s->osh);+}+static void hall_update(Ent *e) {+ Hall *s = ST(e, Hall);+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_hold(&g_player);+ CO_SAY(c, s->tb, s->two ? "CH3_OSHIRO_HALLWAY_B" : "CH3_OSHIRO_HALLWAY_A", NULL, NULL);+ if (s->osh->cls == &OSH3) osh_remove_at(s->osh, ST(s->osh, Osh3), v2((float)(g_level.room->x + g_level.room->w + 64), s->osh->y));+ CO_WAIT(c, 1);+ cutscene_end(e);+ return;+ CO_END(c);+}+static const EntClass HALL = {.size = sizeof(Hall), .name = "CS03_OshiroHallway", .update = hall_update};++/* ---------------------------------------------------------------- NPC03_Oshiro_Cluttter's talk and CS03_OshiroClutter */+static V2 oclutter_zoom(Ent *oe) { /* ZoomPoint */+ Osh3 *o = ST(oe, Osh3);+ return v2(oe->x - g_level.cam.x, oe->y - (o->sections < 2 ? 30 : 15) - g_level.cam.y);+}+static bool gdoor_locked_ent(Ent *e);+static bool gdoor_unlock(Ent *e, float *p, V2 *from);+static void gdoor_instant_unlock(Ent *e);+static bool is_gdoor(const Ent *e);+typedef struct {+ Cutscene cs;+ Ent *osh, *tb;+ int16_t doors[6];+ Walk walk;+ Step step;+ Pan pan;+ Move move; /* the coroutines' own MoveTo */+ Move pace; /* Add(new Coroutine(oshiro.PaceRight())) */+ NpcWalk nw;+ Co ev;+ float p;+ V2 from;+ int8_t evi, index, ndoors, door, pacing, talk;+} OClutter;+static bool oclutter_event(void *ctx, int index) { /* Collapse, PaceLeft, PaceRight; StandUp */+ OClutter *s = ST((Ent *)ctx, OClutter);+ Ent *oe = s->osh;+ Osh3 *o = ST(oe, Osh3);+ Co *c = ev_start(&s->ev, &s->evi, index);+ if (s->talk) { /* StandUp */+ EV_BEGIN;+ osh_pop(o, A_oshiro_idle, false);+ EV_WAIT(0.25f);+ EV_END;+ }+ EV_BEGIN;+ if (index == 0) {+ spr_play(&o->spr, A_oshiro_fall, false);+ EV_WAIT(0.5f);+ } else {+ memset(&s->move, 0, sizeof s->move);+ s->move.target = index == 1 ? v2add(o->home, v2(-20, 0)) : o->home;+ EV_NEST(osh_move(oe, &s->move));+ }+ EV_END;+}+static void oclutter_end(Ent *e, bool skipped) {+ OClutter *s = ST(e, OClutter);+ Ent *oe = s->osh;+ Osh3 *o = ST(oe, Osh3);+ if (s->talk) { /* NPC03_Oshiro_Cluttter.EndTalkRoutine */+ osh_pop(o, A_oshiro_idle, false);+ player_free();+ return;+ }+ player_free();+ if (o->spr.anim == A_oshiro_side) osh_pop(o, A_oshiro_idle, true);+ if (s->index < 3) {+ char f[32];+ level_set_flag("oshiro_clutter_door_open", true);+ path2(f, "oshiro_clutter_", NULL, s->index);+ f[15] = (char)('0' + s->index), f[16] = 0;+ level_set_flag(f, true);+ for (int i = 0; i < s->ndoors; i++) {+ Ent *d = &g_ents[s->doors[i]];+ if (is_gdoor(d) && !gdoor_locked_ent(d)) gdoor_instant_unlock(d);+ }+ if (skipped && s->index == 0) spr_play(&o->spr, A_oshiro_idle_ground, false);+ } else {+ level_set_flag("oshiro_clutter_finished", true);+ ent_remove(oe);+ }+}+static void oclutter_update(Ent *e) {+ static const char *const KEYS[3] = {"CH3_OSHIRO_CLUTTER0", "CH3_OSHIRO_CLUTTER1", "CH3_OSHIRO_CLUTTER2"};+ static const char *const KEYS_B[3] = {"CH3_OSHIRO_CLUTTER0_B", "CH3_OSHIRO_CLUTTER1_B", "CH3_OSHIRO_CLUTTER2_B"};+ OClutter *s = ST(e, OClutter);+ Ent *oe = s->osh;+ Osh3 *o = ST(oe, Osh3);+ Player *p = &g_player;+ if (s->pacing && !osh_move(oe, &s->pace)) s->pacing = 0;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ s->evi = -1;+ if (s->talk) { /* NPC03_Oshiro_Cluttter.TalkRoutine */+ CO_NEST(c, npc_approach(&s->nw, oe, &o->spr, 24, s->index != 1 && s->index != 2 ? 1 : -1));+ step_reset(&s->step);+ CO_NEST(c, zoom_to(&s->step, oclutter_zoom(oe), 2, 0.5f));+ CO_SAY(c, s->tb, KEYS_B[s->index], oclutter_event, e);+ step_reset(&s->step);+ CO_NEST(c, zoom_back(&s->step, 0.5f));+ cutscene_end(e);+ return;+ }+ player_hold(p);+ if (s->index == 1 || s->index == 2) {+ s->walk = walk_exact((int)oe->x - 24);+ CO_NEST(c, player_walk(p, &s->walk));+ p->facing = 1;+ o->spr.sx = -1;+ } else {+ memset(&s->pace, 0, sizeof s->pace), s->pace.target = o->home, s->pacing = 1;+ s->walk = walk_exact((int)o->home.x + 24);+ CO_NEST(c, player_walk(p, &s->walk));+ p->facing = -1;+ o->spr.sx = 1;+ }+ if (s->index < 3) {+ step_reset(&s->step);+ CO_NEST(c, zoom_to(&s->step, oclutter_zoom(oe), 2, 0.5f));+ CO_SAY(c, s->tb, KEYS[s->index], oclutter_event, e);+ step_reset(&s->step);+ CO_NEST(c, zoom_back(&s->step, 0.5f));+ level_set_flag("oshiro_clutter_door_open", true);+ for (s->door = 0; s->door < s->ndoors; s->door++) {+ if (!is_gdoor(&g_ents[s->doors[s->door]]) || gdoor_locked_ent(&g_ents[s->doors[s->door]])) continue;+ s->p = -1;+ CO_NEST(c, gdoor_unlock(&g_ents[s->doors[s->door]], &s->p, &s->from));+ }+ } else {+ s->pan.p = -1;+ CO_NEST(c, pan_to(&s->pan, v2((float)g_level.room->x, (float)g_level.room->y), 0.5f, ease_cube_inout, false));+ step_reset(&s->step);+ CO_NEST(c, zoom_to(&s->step, v2(90, 60), 2, 0.5f));+ CO_SAY(c, s->tb, "CH3_OSHIRO_CLUTTER_ENDING", NULL, NULL);+ memset(&s->move, 0, sizeof s->move), s->move.target = v2(oe->x, (float)(g_level.room->y - 32));+ CO_NEST(c, osh_move(oe, &s->move));+ step_reset(&s->step);+ CO_NEST(c, zoom_back(&s->step, 0.5f));+ }+ cutscene_end(e);+ return;+ CO_END(c);+}+static const EntClass CLUTTER3 = {.size = sizeof(OClutter), .name = "CS03_OshiroClutter", .update = oclutter_update};+static void oclutter_start(Ent *oe, Osh3 *o, bool talk) {+ Ent *e = cs_new(&CLUTTER3, oclutter_end, true, false);+ if (!e) return;+ OClutter *s = ST(e, OClutter);+ s->osh = oe;+ s->index = (int8_t)o->sections;+ s->talk = talk;+ for (int i = 0; i < g_nents && s->ndoors < 6; i++) /* the ClutterDoors, by y */+ if (is_gdoor(&g_ents[i])) {+ int k = s->ndoors++;+ while (k > 0 && g_ents[s->doors[k - 1]].y > g_ents[i].y) s->doors[k] = s->doors[k - 1], k--;+ s->doors[k] = (int16_t)i;+ }+}++/* ---------------------------------------------------------------- CS03_OshiroBreakdown */+/* (DustStaticSpinners are not ported: the creatures it hides and sends back home are left out, with+ * their timing) */+typedef struct {+ Cutscene cs;+ Ent *osh, *tb;+ Walk walk, walk2;+ Step step;+ Pan pan;+ Move move, leave;+ Co ev;+ V2 origin;+ float anxiety;+ int8_t evi, i;+ uint8_t walking, leaving;+} Breakdown;+static bool breakdown_event(void *ctx, int index) { /* WalkLeft, WalkRight, CreateDustA, CreateDustB */+ Breakdown *s = ST((Ent *)ctx, Breakdown);+ Ent *oe = s->osh;+ Osh3 *o = ST(oe, Osh3);+ Player *p = &g_player;+ Co *c = ev_start(&s->ev, &s->evi, index);+ EV_BEGIN;+ if (index < 2) {+ o->changes = 0;+ memset(&s->move, 0, sizeof s->move);+ s->move.target = v2add(s->origin, v2(index == 0 ? -24.f : 0.f, 0));+ EV_NEST(osh_move(oe, &s->move));+ o->changes = 1;+ } else if (index == 2) {+ o->changes = 0;+ spr_play(&o->spr, A_oshiro_fall, false);+ for (s->i = 0; s->i < 4; s->i++) { /* MoveDust(creatures[i]) */+ if (s->i % 4 == 0) {+ level_shake(0.3f);+ EV_WAIT(0.4f);+ } else+ EV_WAIT(0.1f);+ }+ EV_WAIT(0.5f);+ } else {+ EV_WAIT(1); /* (no creatures beyond the first four) */+ for (s->anxiety = 0.1f + rndf() * 0.1f; s->anxiety > 0; s->anxiety -= DT) EV_YIELD; /* Distort.Anxiety */+ step_reset(&s->step);+ EV_NEST(zoom_back(&s->step, 0.5f));+ s->walk2 = walk_exact(g_level.room->x + 200);+ EV_NEST(player_walk(p, &s->walk2));+ EV_WAIT(1);+ spr_play(&o->spr, A_oshiro_recover, false);+ EV_WAIT(0.7f);+ o->spr.sx = 1;+ EV_WAIT(0.5f);+ }+ EV_END;+}+static void breakdown_end(Ent *e, bool skipped) {+ Breakdown *s = ST(e, Breakdown);+ Player *p = level_player();+ player_free();+ if (skipped && p) {+ p->ent->x = (float)(g_level.room->x + 200);+ for (int i = 0; i < 400 && !actor_on_ground(p->ent, 1); i++) p->ent->y++;+ }+ if (p) g_level.cam = player_camera_target(p);+ if (s->osh->cls == &OSH3) ent_remove(s->osh);+ level_set_flag("oshiro_breakdown", true);+}+static void breakdown_update(Ent *e) {+ Breakdown *s = ST(e, Breakdown);+ Ent *oe = s->osh;+ Player *p = &g_player;+ if (s->walking && !player_walk(p, &s->walk)) s->walking = 0; /* Add(new Coroutine(player.DummyWalkTo(player.X - 64))) */+ if (s->leaving && !osh_move(oe, &s->leave)) s->leaving = 0;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_hold(p);+ s->walk = walk_to(p->ent->x - 64), s->walking = 1;+ s->pan.p = -1;+ CO_NEST(c, pan_to(&s->pan, v2((float)g_level.room->x, 0), 1, ease_cube_inout, true));+ CO_WAIT(c, 0.2f);+ step_reset(&s->step);+ CO_NEST(c, zoom_to(&s->step, v2(100, 120), 2, 0.5f));+ s->evi = -1;+ CO_SAY(c, s->tb, "CH3_OSHIRO_BREAKDOWN", breakdown_event, e);+ memset(&s->leave, 0, sizeof s->leave), s->leave.target = v2((float)(g_level.room->x - 64), oe->y), s->leaving = 1;+ CO_WAIT(c, 0.25f);+ s->pan.p = -1;+ CO_NEST(c, pan_to(&s->pan, player_camera_target(p), 1, ease_cube_inout, true));+ cutscene_end(e);+ return;+ CO_END(c);+}+static const EntClass BREAKDOWN = {.size = sizeof(Breakdown), .name = "CS03_OshiroBreakdown", .update = breakdown_update};++/* ---------------------------------------------------------------- CS03_OshiroMasterSuite */+typedef struct {+ Cutscene cs;+ Ent *osh, *tb, *evil, *mirror;+ Walk walk, pwalk;+ Step step;+ Co ev;+ V2 from;+ float p;+ int8_t evi;+ uint8_t walking;+} Suite;+static bool suite_event(void *ctx, int index) {+ /* SuiteShadowAppear, SuiteShadowDisrupt, SuiteShadowCeiling, Wander, Console, JumpBack, Collapse, AwkwardPause */+ Suite *s = ST((Ent *)ctx, Suite);+ Ent *oe = s->osh;+ Osh3 *o = ST(oe, Osh3);+ Player *p = &g_player;+ Co *c = ev_start(&s->ev, &s->evi, index);+ switch (index) {+ case 0: {+ EV_BEGIN;+ if (!s->mirror) return true;+ rmirror_evil_appear(s->mirror);+ s->from = g_level.zoom_focus;+ for (s->p = 0; s->p < 1; s->p += DT * 2) {+ g_level.zoom_focus = v2lerp(s->from, v2(216, 110), ease_sine_inout(s->p));+ EV_YIELD;+ }+ EV_YIELD;+ EV_END;+ }+ case 1: {+ EV_BEGIN;+ if (!s->mirror) return true;+ EV_NEST(rmirror_smash(s->mirror));+ s->evil = ch2_bdummy_new(v2add(v2(s->mirror->x, s->mirror->y), v2(0, -8)));+ EV_WAIT(1.2f);+ o->spr.sx = 1;+ if (s->evil) EV_NEST(ch2_bdummy_float_to(s->evil, v2add(v2(oe->x, oe->y), v2(32, -24)), 0, 0));+ EV_END;+ }+ case 2: {+ EV_BEGIN;+ step_reset(&s->step);+ EV_NEST(zoom_back(&s->step, 0.5f));+ if (!s->evil) return true;+ s->from = v2((float)(g_level.room->x + 96), s->evil->y - 16);+ EV_NEST(ch2_bdummy_float_to(s->evil, s->from, 1, BD_TURN));+ p->facing = -1;+ EV_WAIT(0.25f);+ level_dir_shake(v2(0, -1), 0.3f);+ s->from = v2add(v2(s->evil->x, s->evil->y), v2(0, -32));+ EV_NEST(ch2_bdummy_smash(s->evil, s->from));+ EV_WAIT(0.8f);+ EV_END;+ }+ case 3: {+ EV_BEGIN;+ EV_WAIT(0.5f);+ p->facing = 1;+ EV_WAIT(0.1f);+ s->walk = walk_exact((int)oe->x + 48);+ EV_NEST(player_walk(p, &s->walk));+ EV_WAIT(1);+ p->facing = -1;+ EV_WAIT(0.2f);+ s->walk = walk_exact((int)oe->x - 32);+ EV_NEST(player_walk(p, &s->walk));+ EV_WAIT(0.1f);+ o->spr.sx = -1;+ EV_WAIT(0.2f);+ p->dummy_auto_animate = false;+ spr_play(&p->spr, A_player_lookUp, false);+ EV_WAIT(1);+ p->dummy_auto_animate = true;+ EV_WAIT(0.4f);+ p->facing = 1;+ EV_WAIT(0.2f);+ s->walk = walk_exact((int)oe->x - 24);+ EV_NEST(player_walk(p, &s->walk));+ EV_WAIT(0.5f);+ step_reset(&s->step);+ EV_NEST(zoom_to(&s->step, v2(190, 110), 2, 0.5f));+ EV_END;+ }+ case 4: {+ EV_BEGIN;+ s->walk = walk_exact((int)oe->x - 16);+ EV_NEST(player_walk(p, &s->walk));+ EV_END;+ }+ case 5: {+ EV_BEGIN;+ s->walk = walk_exact((int)oe->x - 24);+ s->walk.flags = WALK_BACKWARDS;+ EV_NEST(player_walk(p, &s->walk));+ EV_WAIT(0.8f);+ EV_END;+ }+ case 6: {+ EV_BEGIN;+ spr_play(&o->spr, A_oshiro_fall, false);+ EV_YIELD;+ EV_END;+ }+ default: {+ EV_BEGIN;+ EV_WAIT(2);+ EV_END;+ }+ }+}+static void suite_end(Ent *e, bool skipped) {+ Suite *s = ST(e, Suite);+ Ent *oe = s->osh;+ Osh3 *o = ST(oe, Osh3);+ if (skipped) {+ if (s->evil && s->evil->cls) ent_remove(s->evil);+ if (s->mirror) rmirror_set_broken(s->mirror);+ for (int i = 0; i < g_nents; i++) /* the DashBlock: RemoveAndFlagAsGone */+ if (g_ents[i].cls && g_ents[i].dead != 1 && level_is_dash_block(&g_ents[i])) {+ level_break_dash_block(&g_ents[i], v2(0, -1));+ break;+ }+ spr_play(&o->spr, A_oshiro_idle_ground, false);+ }+ o->talk.enabled = true;+ player_free();+ g_level.lighting = area_darkness(); /* BaseLightingAlpha */+ level_set_flag("oshiro_resort_suite", true);+}+static void suite_update(Ent *e) {+ Suite *s = ST(e, Suite);+ Ent *oe = s->osh;+ Player *p = level_player();+ if (s->walking && p && !player_walk(p, &s->pwalk)) s->walking = 0;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ while (!p) {+ CO_YIELD(c);+ p = level_player();+ }+ CO_WAIT(c, 0.4f);+ player_hold(p);+ s->pwalk = walk_to(oe->x + 32), s->walking = 1; /* Add(new Coroutine(player.DummyWalkTo(...))) */+ CO_WAIT(c, 1);+ s->evi = -1;+ CO_SAY(c, s->tb, "CH3_OSHIRO_SUITE", suite_event, e);+ if (s->evil) s->from = v2(s->evil->x, (float)(g_level.room->y - 32));+ if (s->evil) CO_NEST(c, ch2_bdummy_float_to(s->evil, s->from, 0, 0));+ if (s->evil) ent_remove(s->evil);+ s->evil = NULL;+ while (g_level.lighting != area_darkness()) {+ g_level.lighting = approach(g_level.lighting, area_darkness(), DT * 0.5f);+ CO_YIELD(c);+ }+ cutscene_end(e);+ return;+ CO_END(c);+}+static const EntClass SUITE = {.size = sizeof(Suite), .name = "CS03_OshiroMasterSuite", .update = suite_update};++/* ---------------------------------------------------------------- CS03_OshiroRooftop */+typedef struct {+ Cutscene cs;+ Ent *osh, *tb, *evil;+ Walk walk;+ Step step;+ Move move;+ Pan pan;+ Co ev;+ V2 spawn, from, to;+ float p, anxiety, offset;+ int8_t evi;+ uint8_t walking, floating, moving, cam_out;+} Roof3;+static bool roof3_event(void *ctx, int index) { /* MaddyWalkAway, MaddyTurnAround, EnterOshiro, OshiroGetsAngry */+ Roof3 *s = ST((Ent *)ctx, Roof3);+ Ent *oe = s->osh;+ Osh3 *o = ST(oe, Osh3);+ Player *p = &g_player;+ Co *c = ev_start(&s->ev, &s->evi, index);+ switch (index) {+ case 0: {+ EV_BEGIN;+ s->walk = walk_to((float)g_level.room->x + 170), s->walking = 1;+ EV_WAIT(0.2f);+ if (s->evil) s->to = v2add(v2(s->evil->x, s->evil->y), v2(80, 30)), s->floating = 1;+ EV_YIELD;+ EV_END;+ }+ case 1: {+ EV_BEGIN;+ EV_WAIT(0.25f);+ p->facing = -1;+ EV_WAIT(0.1f);+ step_reset(&s->step);+ EV_NEST(zoom_to(&s->step, v2(150, s->spawn.y - g_level.room->y - 8), 2, 0.5f));+ EV_END;+ }+ case 2: {+ EV_BEGIN;+ EV_WAIT(0.3f);+ s->offset = (0.5f - 0.667f) * 96; /* the boss sprite's Justify less Oshiro's, times its height */+ oe->visible = 1;+ o->spr.sx = 1;+ memset(&s->move, 0, sizeof s->move), s->move.target = v2sub(s->spawn, v2(0, s->offset)), s->moving = 1;+ s->from.x = g_level.zoom_focus.x;+ for (s->p = 0; s->p < 1; s->p += DT / 0.7f) {+ g_level.zoom_focus.x = s->from.x + (126 - s->from.x) * ease_cube_inout(s->p);+ EV_YIELD;+ }+ EV_WAIT(0.3f);+ p->facing = -1;+ EV_WAIT(0.1f);+ if (s->evil) ch2_bdummy_face(s->evil, -1);+ EV_END;+ }+ default: {+ EV_BEGIN;+ EV_WAIT(0.1f);+ if (s->evil) ch2_bdummy_vanish(s->evil);+ s->evil = NULL, s->floating = 0;+ EV_WAIT(0.8f);+ spr_init(&o->spr, SB_oshiro_boss); /* the boss's sprite instead */+ spr_play(&o->spr, A_oshiro_boss_transformStart, false);+ o->changes = 0;+ oe->y += s->offset;+ set_depth(oe, -12500);+ EV_WAIT(1);+ EV_END;+ }+ }+}+static void roof3_end(Ent *e, bool skipped) {+ Roof3 *s = ST(e, Roof3);+ Player *p = level_player();+ if (s->evil && s->evil->cls) ent_remove(s->evil);+ if (p) {+ p->state_locked = false;+ player_set_state(p, ST_NORMAL);+ p->ent->x = (float)g_level.room->x + 170;+ p->speed.y = 0;+ for (int i = 0; i < 400 && collide_solid(p->ent, p->ent->x, p->ent->y); i++) p->ent->y--;+ g_level.cam = player_camera_target(p);+ }+ (void)skipped;+ if (s->osh->cls == &OSH3) ent_remove(s->osh);+ level_set_flag("oshiro_resort_roof", true); /* (first: the boss checks it) */+ new_oshiro(s->spawn.x, s->spawn.y, true);+ g_session.rx = (int32_t)(g_level.room->x + 170), g_session.ry = g_level.room->y + 160;+ g_session.has_respawn = 1;+}+static void roof3_update(Ent *e) {+ Roof3 *s = ST(e, Roof3);+ Ent *oe = s->osh;+ Osh3 *o = ST(oe, Osh3);+ Player *p = level_player();+ if (s->walking && p && !player_walk(p, &s->walk)) s->walking = 0;+ if (s->floating && s->evil && !ch2_bdummy_float_to(s->evil, s->to, 0, 0)) s->floating = 0;+ if (s->moving && !osh_move(oe, &s->move)) s->moving = 0;+ if (s->cam_out) { /* AnxietyAndCameraOut */+ s->anxiety = approach(s->anxiety, 0, DT * 4);+ if (!pan_to(&s->pan, s->to, 0.5f, ease_cube_inout, false)) s->cam_out = 0;+ }+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ while (!p) {+ CO_YIELD(c);+ p = level_player();+ }+ player_hold(p);+ while (!actor_on_ground(p->ent, 1) || p->speed.y < 0) CO_YIELD(c);+ CO_WAIT(c, 0.6f);+ s->evil = ch2_bdummy_new(v2(oe->x - 40, (float)(g_level.room->y + g_level.room->h - 60)));+ if (s->evil) ch2_bdummy_face(s->evil, 1), ch2_bdummy_appear(s->evil);+ CO_WAIT(c, 0.1f);+ p->facing = -1;+ s->evi = -1;+ CO_SAY(c, s->tb, "CH3_OSHIRO_START_CHASE", roof3_event, e);+ CO_WAIT(c, 0.2f); /* OshiroTransform */+ spr_play(&o->spr, A_oshiro_boss_transformFinish, false);+ level_shake(0.5f);+ while (s->anxiety < 0.5f) {+ s->anxiety = approach(s->anxiety, 0.5f, DT * 0.5f);+ CO_YIELD(c);+ }+ CO_WAIT(c, 0.25f);+ s->pan.p = -1, s->to = player_camera_target(p), s->cam_out = 1;+ step_reset(&s->step);+ CO_NEST(c, zoom_back(&s->step, 0.5f));+ CO_WAIT(c, 0.25f);+ cutscene_end(e);+ return;+ CO_END(c);+}+static const EntClass ROOF3 = {.size = sizeof(Roof3), .name = "CS03_OshiroRooftop", .update = roof3_update};++/* the Oshiros: Added, OnTalk, and the checks of their Update */+static void osh_talk(Ent *e, Osh3 *o, Player *p) {+ (void)p;+ switch (o->kind) {+ case OK_LOBBY: {+ Ent *c = cs_new(&LOBBY, lobby_end, true, false);+ if (c) ST(c, Lobby)->osh = e;+ o->talk.enabled = false;+ break;+ }+ case OK_CLUTTER: { /* OnTalk */+ char f[40];+ o->talked = 1;+ o->pacing = 0;+ path2(f, "oshiro_clutter_", NULL, -1);+ f[15] = (char)('0' + o->sections), f[16] = 0;+ if (!level_get_flag(f)) {+ oclutter_start(e, o, false);+ break;+ }+ path2(f, "oshiro_clutter_optional_", NULL, -1);+ f[24] = (char)('0' + o->sections), f[25] = 0;+ level_set_flag(f, true);+ oclutter_start(e, o, true); /* Level.StartCutscene(EndTalkRoutine), TalkRoutine */+ o->talk.enabled = false;+ break;+ }+ case OK_SUITE: /* Add(new Coroutine(Talk(player))) */+ memset(&o->co, 0, sizeof o->co), memset(&o->nw, 0, sizeof o->nw);+ o->pacing = 2;+ break;+ }+}+static void osh_trigger(Ent *e, Osh3 *o, Player *p) {+ switch (o->kind) {+ case OK_LOBBY:+ if (e->x >= o->home.x + 12) set_depth(e, 1000);+ break;+ case OK_HALL1:+ case OK_HALL2:+ if (!o->talked && p && p->ent->x > e->x - 60) {+ Ent *c = cs_new(&HALL, hall_end, true, false);+ if (c) ST(c, Hall)->osh = e, ST(c, Hall)->two = o->kind == OK_HALL2;+ o->talked = 1;+ }+ break;+ case OK_CLUTTER:+ o->pace_t += DT;+ if (o->sections == 3 && !o->in_routine && p && p->ent->x < e->x + 32 && p->ent->y <= e->y) {+ osh_talk(e, o, p);+ o->in_routine = 1;+ }+ break;+ case OK_BREAKDOWN:+ if (!o->talked && p) {+ const Room *rm = g_level.room;+ if ((p->ent->x <= rm->x + 370 && p->on_safe_ground && p->ent->y < rm->y + rm->h / 2) || p->ent->x <= rm->x + 320) {+ Ent *c = cs_new(&BREAKDOWN, breakdown_end, true, false);+ if (c) ST(c, Breakdown)->osh = e, ST(c, Breakdown)->origin = v2(e->x, e->y);+ o->talked = 1;+ }+ }+ break;+ }+}+static void new_osh(const EData *d, int kind) {+ static const char *const DONE[7] = {"oshiro_resort_talked_1", "oshiro_resort_talked_2", "oshiro_resort_talked_3",+ "oshiro_clutter_finished", "oshiro_breakdown", NULL, "oshiro_resort_roof"};+ if (DONE[kind] && level_get_flag(DONE[kind])) return; /* Added: RemoveSelf */+ Ent *e = ent_new(&OSH3, d->x, d->y);+ if (!e) return;+ e->depth = 1000;+ ent_box(e, 8, 8, -4, -8);+ Osh3 *o = ST(e, Osh3);+ o->kind = (uint8_t)kind;+ spr_init(&o->spr, SB_oshiro);+ spr_play(&o->spr, A_oshiro_idle, false);+ o->spr.sx = kind <= OK_CLUTTER ? -1 : 1; /* OshiroSprite(facing) */+ wiggler_init(&o->wig, 0.3f, 2);+ o->changes = o->turn_invisible = 1;+ o->light_on = kind != OK_LOBBY, o->light = 1;+ o->home = v2(d->x, d->y);+ switch (kind) {+ case OK_LOBBY: {+ o->spr.visible = 0;+ e->depth = 9001;+ ch1_talk_add(e, &o->talk, -30, -16, 42, 32, v2(-12, -24)); /* (its "hover/resort" note: the plain prompt) */+ o->talk.must_face = false;+ o->has_talk = 1;+ Ent *b = ent_new(&BELL, d->x - 14, d->y);+ if (b) {+ b->collidable = 0;+ ch1_talk_add(b, ST(b, Talk), -8, -8, 16, 16, v2(0, -24));+ ST(b, Talk)->enabled = false;+ }+ break;+ }+ case OK_HALL2: g_session.lighting_alpha_add = 0.15f; break;+ case OK_CLUTTER: {+ for (int i = 0; i < 3 && i < d->nnodes; i++) o->nodes[i] = ed_node(d, i);+ char f[32];+ for (int i = 0; i < 3; i++) {+ path2(f, "oshiro_clutter_cleared_", NULL, -1);+ f[23] = (char)('0' + i), f[24] = 0;+ if (level_get_flag(f)) o->sections++;+ }+ if (o->sections == 0 || o->sections == 3) o->spr.sx = 1;+ if (o->sections > 0) e->x = o->nodes[o->sections - 1].x, e->y = o->nodes[o->sections - 1].y;+ else if (!level_get_flag("oshiro_clutter_0")) o->pacing = 1;+ if (o->sections == 0 && level_get_flag("oshiro_clutter_0") && !level_get_flag("oshiro_clutter_optional_0"))+ spr_play(&o->spr, A_oshiro_idle_ground, false);+ path2(f, "oshiro_clutter_optional_", NULL, -1);+ f[24] = (char)('0' + o->sections), f[25] = 0;+ o->has_talk = !(o->sections == 3 || level_get_flag(f));+ ch1_talk_add(e, &o->talk, -24, -8, 48, 8, v2(0, -24));+ if (!o->has_talk) ch1_talk_remove(e);+ o->home = v2(e->x, e->y);+ break;+ }+ case OK_SUITE:+ ch1_talk_add(e, &o->talk, -16, -8, 32, 8, v2(0, -24));+ o->has_talk = 1;+ if (!level_get_flag("oshiro_resort_suite")) {+ o->talk.enabled = false;+ Ent *c = cs_new(&SUITE, suite_end, true, false);+ if (c) {+ ST(c, Suite)->osh = e;+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &RMIRROR && g_ents[i].dead != 1) ST(c, Suite)->mirror = &g_ents[i];+ }+ } else+ spr_play(&o->spr, A_oshiro_idle_ground, false);+ break;+ case OK_ROOF: {+ o->turn_invisible = 0;+ e->visible = 0;+ Ent *c = cs_new(&ROOF3, roof3_end, true, false);+ if (c) ST(c, Roof3)->osh = e, ST(c, Roof3)->spawn = v2(d->x, (float)(g_level.rooms[g_level.room_slot].y + g_level.rooms[g_level.room_slot].h - 40));+ break;+ }+ }+}++/* ---------------------------------------------------------------- Theo: NPC03_Theo_Escaping, NPC03_Theo_Vents */+/* their grates: the vent's (falls up and left, turning) and the ceiling's (shakes, then drops) */+typedef struct { V2 speed; float alpha, rot, shake; int8_t x; uint8_t falling, ceiling; } Grate;+static void grate_update(Ent *e) {+ Grate *g = ST(e, Grate);+ if (g->shake > 0) {+ g->shake -= DT;+ if (level_on_interval(0.05f)) g->x = (int8_t)(1 - g->x);+ }+ if (!g->falling) return;+ g->speed.x = approach(g->speed.x, 0, DT * (g->ceiling ? 80 : 120));+ g->speed.y += (g->ceiling ? 200 : 400) * DT;+ e->x += g->speed.x * DT, e->y += g->speed.y * DT;+ if (collide_solid(e, e->x, e->y + 2) && g->speed.y > 0) g->speed.y = -g->speed.y * 0.25f;+ g->alpha -= DT;+ g->rot += DT * (g->ceiling ? 1 : v2len(g->speed) * 0.05f);+ if (g->alpha <= 0) ent_remove(e);+}+static void grate_render(Ent *e) {+ Grate *g = ST(e, Grate);+ /* JustifyOrigin(0.5, 0) of a 16 x 8 picture; the vent's lies on its side (Rotation PI / 2) */+ gfx_tex_ex(T_scenery_grate, e->x + g->x, e->y, 8, 0, 1, 1, g->rot, 0xFFFF, (uint8_t)(clampf(g->alpha, 0, 1) * 255), 0);+}+static const EntClass GRATE = {.size = sizeof(Grate), .name = "Grate", .update = grate_update, .render = grate_render};+static void grate_fall(Ent *e) {+ Grate *g = ST(e, Grate);+ if (g->falling) return;+ g->falling = 1;+ g->speed = g->ceiling ? v2(40, 200) : v2(-120, -120);+ ent_box(e, 2, 2, g->ceiling ? -1 : -2, g->ceiling ? 0 : -1);+}++enum { TK_ESCAPING, TK_VENTS };+typedef struct {+ Talk talk;+ Sprite spr;+ Move move;+ Co co;+ NpcWalk nw;+ Step step;+ Pan pan;+ Ent *tb;+ int16_t grate;+ float light, particles, spr_y, from;+ uint8_t kind, has_talk, talked, appeared, crawling, talking;+} Theo3;+static const EntClass THEO3;+static Ent *theo3_grate(Theo3 *t) { return t->grate >= 0 && g_ents[t->grate].cls == &GRATE ? &g_ents[t->grate] : NULL; }++/* CS03_TheoEscape */+typedef struct {+ Cutscene cs;+ Ent *theo, *tb;+ Walk walk;+ Step step;+ Co ev;+ V2 start;+ int8_t evi;+} Escape;+static bool escape_event(void *ctx, int index) { /* StopRemovingVent, StartRemoveVent, RemoveVent, GivePhone */+ Escape *s = ST((Ent *)ctx, Escape);+ Ent *te = s->theo;+ Theo3 *t = ST(te, Theo3);+ Player *p = &g_player;+ Co *c = ev_start(&s->ev, &s->evi, index);+ switch (index) {+ case 0: {+ EV_BEGIN;+ spr_play(&t->spr, A_theo_idle, false);+ EV_WAIT(0.1f);+ t->spr.sx = -1;+ EV_END;+ }+ case 1: {+ EV_BEGIN;+ t->spr.sx = 1;+ EV_WAIT(0.1f);+ spr_play(&t->spr, A_theo_goToVent, false);+ EV_WAIT(0.25f);+ EV_END;+ }+ case 2: {+ EV_BEGIN;+ EV_WAIT(0.8f);+ spr_play(&t->spr, A_theo_fallVent, false);+ EV_WAIT(0.8f);+ if (theo3_grate(t)) grate_fall(theo3_grate(t));+ EV_WAIT(0.8f);+ t->spr.sx = -1;+ EV_WAIT(0.25f);+ EV_END;+ }+ default: {+ EV_BEGIN;+ spr_play(&t->spr, A_theo_walk, false);+ t->spr.sx = -1;+ while (te->x > p->ent->x + 24) {+ te->x -= 48 * DT;+ EV_YIELD;+ }+ spr_play(&t->spr, A_theo_idle, false);+ EV_WAIT(1);+ EV_END;+ }+ }+}+static void theo3_crawl(Ent *e, Theo3 *t) { /* CrawlUntilOut */+ t->spr.sx = 1;+ spr_play(&t->spr, A_theo_crawl, false);+ e->tags |= TAG_GLOBAL;+ t->crawling = 1;+}+static void escape_end(Ent *e, bool skipped) {+ Escape *s = ST(e, Escape);+ Ent *te = s->theo;+ player_free();+ level_set_flag("resort_theo", true);+ save_set_flag(0), save_set_flag(1);+ if (skipped && te->cls == &THEO3) {+ Theo3 *t = ST(te, Theo3);+ te->x = s->start.x, te->y = s->start.y;+ theo3_crawl(te, t);+ if (theo3_grate(t)) ent_remove(theo3_grate(t));+ }+}+static void escape_update(Ent *e) {+ Escape *s = ST(e, Escape);+ Ent *te = s->theo;+ Theo3 *t = ST(te, Theo3);+ Player *p = &g_player;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_hold(p);+ s->walk = walk_to(te->x - 64);+ CO_NEST(c, player_walk(p, &s->walk));+ p->facing = 1;+ step_reset(&s->step);+ CO_NEST(c, zoom_to(&s->step, v2(240, 135), 2, 0.5f));+ s->evi = -1;+ CO_SAY(c, s->tb, !save_flag(0) ? "CH3_THEO_NEVER_MET" : !save_flag(1) ? "CH3_THEO_NEVER_INTRODUCED" : "CH3_THEO_INTRO", escape_event, e);+ t->spr.sx = 1;+ CO_WAIT(c, 0.2f);+ spr_play(&t->spr, A_theo_walk, false);+ while (!collide_solid(te, te->x + 2, te->y)) {+ CO_YIELD(c);+ te->x += 48 * DT;+ }+ spr_play(&t->spr, A_theo_idle, false);+ CO_WAIT(c, 0.2f);+ spr_play(&t->spr, A_theo_duck, false);+ CO_WAIT(c, 0.5f);+ level_set_flag("resort_theo", true);+ p->state_locked = false;+ player_set_state(p, ST_NORMAL);+ theo3_crawl(te, t);+ step_reset(&s->step);+ CO_NEST(c, zoom_back(&s->step, 0.5f));+ cutscene_end(e);+ return;+ CO_END(c);+}+static const EntClass ESCAPE = {.size = sizeof(Escape), .name = "CS03_TheoEscape", .update = escape_update};++/* NPC03_Theo_Vents' talk: Level.StartCutscene(OnTalkEnd) and its routine */+typedef struct { Cutscene cs; Ent *theo; } VentTalk;+static void vents_talk_end(Ent *e, bool skipped) { /* OnTalkEnd */+ (void)skipped;+ Ent *te = ST(e, VentTalk)->theo;+ Player *p = level_player();+ if (p) p->dummy_auto_animate = true;+ player_free();+ level_set_flag("theoVentsTalked", true);+ if (te->cls == &THEO3) ent_remove(te);+}+static void vents_talk_update(Ent *e) {+ Ent *te = ST(e, VentTalk)->theo;+ Theo3 *t = ST(te, Theo3);+ Player *p = &g_player;+ Co *c = &ST(e, VentTalk)->cs.co;+ CO_BEGIN(c);+ CO_NEST(c, npc_approach(&t->nw, te, &t->spr, 10, -1));+ p->dummy_auto_animate = false;+ spr_play(&p->spr, A_player_lookUp, false);+ t->pan.p = -1;+ CO_NEST(c, pan_to(&t->pan, v2((float)(g_level.room->x + g_level.room->w - 320), (float)g_level.room->y), 0.5f, ease_cube_inout, false));+ step_reset(&t->step);+ CO_NEST(c, zoom_to(&t->step, v2(240, 70), 2, 0.5f));+ CO_SAY(c, t->tb, "CH3_THEO_VENTS", NULL, NULL);+ t->from = t->spr_y; /* Disappear */+ for (t->particles = 0; t->particles < 1; t->particles += DT * 2) {+ CO_YIELD(c);+ particles_emit(PL_FG, &P_VentDust, 1, v2(te->x, te->y), v2(6, 0), P_VentDust.direction);+ t->spr_y = t->from + (-24 - t->from) * ease_back_in(t->particles);+ }+ CO_WAIT(c, 0.25f);+ step_reset(&t->step);+ CO_NEST(c, zoom_back(&t->step, 0.5f));+ cutscene_end(e);+ return;+ CO_END(c);+}+static const EntClass VENTTALK = {.size = sizeof(VentTalk), .name = "NPC03_Theo_Vents.Talk", .update = vents_talk_update};++static void theo3_appear(Ent *e, Theo3 *t) { /* NPC03_Theo_Vents.Appear */+ Player *p = level_player();+ Co *c = &t->co;+ CO_BEGIN(c);+ if (!level_get_flag("theoVentsAppeared")) {+ {+ Ent *g = ent_new(&GRATE, e->x, e->y);+ t->grate = g ? (int16_t)(g - g_ents) : -1;+ if (g) g->collidable = 0, ST(g, Grate)->ceiling = 1, ST(g, Grate)->alpha = 1;+ }+ do {+ CO_YIELD(c);+ p = level_player();+ } while (!p || !(p->ent->x > e->x - 32));+ particles_emit(PL_FG, &P_VentDust, 24, v2(e->x, e->y), v2(6, 0), P_VentDust.direction);+ if (theo3_grate(t)) grate_fall(theo3_grate(t));+ for (t->particles = 0; t->particles < 1; t->particles += DT * 2) {+ CO_YIELD(c);+ e->visible = 1;+ t->spr_y = -24 + 16 * ease_cube_out(t->particles);+ }+ level_set_flag("theoVentsAppeared", true);+ }+ t->appeared = 1;+ t->spr_y = -8;+ e->visible = 1;+ ch1_talk_add(e, &t->talk, -16, 0, 32, 100, v2(0, -8));+ t->has_talk = 1;+ CO_END(c);+}+static void theo3_update(Ent *e) {+ Theo3 *t = ST(e, Theo3);+ Player *p = level_player();+ spr_update(&t->spr);+ if (t->has_talk && talk_update(&t->talk, e) && !t->talking) { /* OnTalk */+ Ent *c = cs_new(&VENTTALK, vents_talk_end, true, false);+ if (c) ST(c, VentTalk)->theo = e, t->talking = 1, memset(&t->nw, 0, sizeof t->nw);+ }+ if (t->crawling) { /* CrawlUntilOutRoutine */+ float target = (float)(g_level.room->x + g_level.room->w + 280);+ if (e->x == target) ent_remove(e);+ else e->x = approach(e->x, target, 20 * DT);+ }+ if (t->kind == TK_VENTS) {+ if (!t->appeared) {+ theo3_appear(e, t);+ if ((t->particles -= DT) <= 0 && !t->appeared) { /* (the appear routine's timer is its own) */+ }+ }+ return;+ }+ if (p && !t->talked && p->ent->x > e->x - 100) { /* Talk */+ t->talked = 1;+ Ent *c = cs_new(&ESCAPE, escape_end, true, false);+ if (c) ST(c, Escape)->theo = e, ST(c, Escape)->start = v2(e->x, e->y);+ }+ Ent *g = theo3_grate(t);+ if (g) ST(g, Grate)->x = (int8_t)(t->spr.anim == A_theo_pullVent && t->spr.frame > 0 ? 0 : 1);+}+static void theo3_render(Ent *e) {+ Theo3 *t = ST(e, Theo3);+ if (t->kind == TK_VENTS) {+ Sprite s = t->spr; /* Scale (-1, -1): upside down, below its origin */+ s.sy = -1;+ spr_draw(&s, e->x, e->y + t->spr_y);+ return;+ }+ draw_npc(&t->spr, e->x - 4, e->y);+ light_add(e->x, e->y - 4, 0xFFFFFF, 1, 32, 64);+}+static const EntClass THEO3 = {.size = sizeof(Theo3), .name = "NPC03_Theo", .update = theo3_update, .render = theo3_render};+static void new_theo3(const EData *d, int kind) {+ if (kind == TK_ESCAPING ? level_get_flag("resort_theo") : level_get_flag("theoVentsTalked")) return;+ Ent *e = ent_new(&THEO3, d->x, d->y);+ if (!e) return;+ e->depth = 1000;+ ent_box(e, 8, 8, -4, -8);+ Theo3 *t = ST(e, Theo3);+ t->kind = (uint8_t)kind;+ t->grate = -1;+ spr_init(&t->spr, SB_theo);+ spr_play(&t->spr, A_theo_idle, false);+ if (kind == TK_VENTS) {+ e->tags = TAG_TRANSITION_UPDATE;+ t->spr.sx = -1;+ e->visible = 0;+ return;+ }+ for (int i = 0; i < 64 && !collide_solid(e, e->x + 1, e->y); i++) e->x++; /* Added */+ Ent *g = ent_new(&GRATE, e->x + 4, e->y - 8); /* Position + (Width / 2, -8) */+ if (g) {+ g->collidable = 0;+ ST(g, Grate)->rot = PI_F / 2, ST(g, Grate)->alpha = 1;+ t->grate = (int16_t)(g - g_ents);+ }+ spr_play(&t->spr, A_theo_goToVent, false);+}++/* ---------------------------------------------------------------- CS03_Memo, CS03_Diary, CS03_Guestbook */+typedef struct { Cutscene cs; Ent *tb, *page; float p; V2 from; int8_t which, index; } Read3;+static void read3_end(Ent *e, bool skipped) {+ (void)skipped;+ Read3 *s = ST(e, Read3);+ player_free();+ if (s->which == 2) {+ level_set_flag("memo_read", true);+ if (s->page && s->page->cls) ent_remove(s->page);+ }+}+static bool read3_pressed(const Button *b) { return btn_pressed(b); }+static void read3_update(Ent *e) {+ static const char *const KEYS[3] = {"CH3_DIARY", "ch3_guestbook", "ch3_memo_opening"};+ Read3 *s = ST(e, Read3);+ Player *p = &g_player;+ PageCtl *pg = s->page && s->page->cls && s->page->dead != 1 ? ST(s->page, PageCtl) : NULL;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_hold(p);+ if (s->which < 2 || !level_get_flag("memo_read")) {+ CO_SAY(c, s->tb, KEYS[s->which], NULL, NULL);+ CO_WAIT(c, 0.1f);+ }+ if (s->which < 2) goto done;+ s->page = ch2_page_new(true); /* MemoPage */+ if (!s->page) goto done;+ CO_YIELD(c);+ for (s->p = 0; s->p < 1; s->p += DT) { /* EaseIn */+ pg->pos = v2lerp(v2(960, 1180), v2(960, 390), ease_cube_out(s->p));+ pg->alpha = ease_cube_out(s->p);+ CO_YIELD(c);+ }+ for (s->from.y = pg->pos.y, s->index = 0; !read3_pressed(&g_in.back);) { /* Wait: three places down the page */+ /* (400 down each time; more if the page is longer than the game's) */+ pg->pos.y += (s->from.y - s->index * fmaxf(400, (390 + pg->h * 6 - 1020) / 2) - pg->pos.y) * (1 - powf(0.01f, DT));+ if (g_in.aim_y < 0 && (g_in.keys & ~g_in.prev & K_UP) && s->index > 0) s->index--;+ else if (s->index < 2) {+ if (((g_in.keys & ~g_in.prev & K_DOWN)) || read3_pressed(&g_in.confirm) || read3_pressed(&g_in.jump)) s->index++;+ } else if (read3_pressed(&g_in.confirm) || read3_pressed(&g_in.jump))+ break;+ CO_YIELD(c);+ }+ pg->out = 1; /* EaseOut */+ s->from = pg->pos;+ for (s->p = 0; s->p < 1; s->p += DT * 1.5f) {+ pg->pos = v2lerp(s->from, v2(960, -1380), ease_cube_in(s->p));+ pg->alpha = 1 - ease_cube_in(s->p);+ CO_YIELD(c);+ }+ ent_remove(s->page);+ s->page = NULL;+done:+ cutscene_end(e);+ return;+ CO_END(c);+}+static const EntClass READ3 = {.size = sizeof(Read3), .name = "CS03_Memo", .update = read3_update};+static void read3_start(Ent *trig, Player *p, int which) {+ (void)trig, (void)p;+ Ent *e = cs_new(&READ3, read3_end, true, false);+ if (e) ST(e, Read3)->which = (int8_t)which;+}++/* ---------------------------------------------------------------- ResortRoofEnding and CS03_Ending */+/* the roof's pictures (all but the first edge) wobble when Oshiro slams it; at the last slam they snap+ * and fall. phase: 0 still, 1 waiting its delay, 2 wobbling, 3 shaking until it falls, 4 falling, 5 gone */+#define ROOF_N 12+typedef struct { float x, y, rot, delay, p, amount, speed_x, speed_y, off; uint8_t tex, phase, fall; } RoofImg;+typedef struct { RoofImg img[ROOF_N]; uint8_t n, begin_falling; } Roof;+static uint16_t roof_tex[8]; /* the four centers, the edge, the snapped a, b, c */+static uint16_t roof_edge_d;+static void roof_render(Ent *e) {+ Roof *r = ST(e, Roof);+ if (roof_edge_d == 0xFFFF) return;+ V2 sh = e_shake(e);+ float x = e->x + sh.x, y = e->y + sh.y;+ gfx_tex_ex(roof_edge_d, x + 8, y + 4, 8, 12, 1, 1, 0, 0xFFFF, 255, 0);+ for (int i = 0; i < r->n; i++) {+ RoofImg *m = &r->img[i];+ Tex t;+ if (m->phase < 5 && tex_get(roof_tex[m->tex], &t))+ gfx_tex_ex(roof_tex[m->tex], x + m->x, y + m->y, t.fw / 2.f, t.fh / 2.f, 1, 1, m->rot, 0xFFFF, 255, 0);+ }+}+static bool interval_off(float t, float off) { /* Scene.OnInterval(interval, offset) */+ float now = g_level.time_active - off;+ return floorf((now - DT) / t) < floorf(now / t);+}+static void roof_update(Ent *e) {+ Roof *r = ST(e, Roof);+ plat_update(e);+ for (int i = 0; i < r->n; i++) { /* the WobbleImage coroutines */+ RoofImg *m = &r->img[i];+ switch (m->phase) {+ case 1:+ if (m->delay > 0) {+ m->delay -= DT;+ break;+ }+ for (int k = 0; k < 2; k++) {+ float dx = e->x + m->x - 4 + k * 8, dy = e->y + m->off + rndi(8);+ level_debris(dx, dy, '9', v2(dx, dy + 8));+ }+ m->phase = m->fall ? 3 : 2, m->p = 0, m->amount = 5;+ break;+ case 2:+ m->p += DT * 16;+ m->amount = approach(m->amount, 1, DT * 5);+ m->y = m->off + sinf(m->p) * m->amount;+ break;+ case 3:+ if (!r->begin_falling) {+ if ((m->delay -= DT) <= 0) m->y = m->off + (float)rndi(2), m->delay = 0.01f + DT; /* yield return 0.01f */+ break;+ }+ m->tex = (uint8_t)(5 + rndi(3));+ e->collidable = 0;+ m->amount = rndf();+ m->speed_x = -24 + rndf() * 48;+ m->speed_y = -(80 + rndf() * 80);+ m->off = rndf();+ m->p = 0, m->phase = 4;+ /* fall through */+ case 4:+ m->x += m->speed_x * DT, m->y += m->speed_y * DT;+ m->rot += m->amount * ease_cube_in(m->p);+ m->speed_x = approach(m->speed_x, 0, DT * 200);+ m->speed_y += 600 * DT;+ if (interval_off(0.1f, m->off)) dust_burst(v2(e->x + m->x, e->y + m->y), -PI_F / 2, 1);+ if ((m->p += DT) >= 4) m->phase = 5;+ break;+ }+ }+}+static void roof_wobble(Ent *e, Ent *ghost, bool fall) { /* Wobble */+ Roof *r = ST(e, Roof);+ for (int i = 0; i < r->n; i++) {+ RoofImg *m = &r->img[i];+ if (m->phase >= 4) continue;+ m->off = m->y; /* orig */+ m->delay = fabsf(e->x + m->x - ghost->x) * 0.001f;+ m->phase = 1, m->fall = fall;+ }+}+static void roof_awake(Ent *e);+static const EntClass ROOF = {.name = "resortRoofEnding", .size = sizeof(Roof), .update = roof_update, .render = roof_render,+ .awake = roof_awake, .kind = KIND_SOLID};+static void new_roof(const EData *d) {+ Ent *e = ent_new(&ROOF, d->x, d->y);+ if (!e) return;+ float w = EA(d, resortRoofEnding, width);+ ent_box(e, w, 2, 0, 0);+ e->safe = 1;+ Roof *r = ST(e, Roof);+ /* (decals have no run-time names: their ids) */+#if defined(T_decals_3_resort_roofEdge_d) && defined(T_decals_3_resort_roofCenter_snapped_a)+ static const uint16_t T[8] = {T_decals_3_resort_roofCenter, T_decals_3_resort_roofCenter_b, T_decals_3_resort_roofCenter_c,+ T_decals_3_resort_roofCenter_d, T_decals_3_resort_roofEdge, T_decals_3_resort_roofCenter_snapped_a,+ T_decals_3_resort_roofCenter_snapped_b, T_decals_3_resort_roofCenter_snapped_c};+ memcpy(roof_tex, T, sizeof roof_tex);+ roof_edge_d = T_decals_3_resort_roofEdge_d;+#else+ roof_edge_d = 0xFFFF;+#endif+ int i;+ for (i = 0; (float)i < w && r->n < ROOF_N - 1; i += 16) {+ RoofImg *m = &r->img[r->n++];+ m->x = (float)(i + 8), m->y = 4, m->tex = (uint8_t)rndi(4);+ }+ RoofImg *m = &r->img[r->n++];+ m->x = (float)(i + 8), m->y = 4, m->tex = 4;+}++/* BgFlash: black behind the level while the lightning strikes */+static void bgflash_render(Ent *e) {+ gfx_rect(g_level.cam.x - 10, g_level.cam.y - 10, 340, 200, 0, (uint8_t)(clampf(*ST(e, float), 0, 1) * 255));+}+static const EntClass BGFLASH = {.size = sizeof(float), .name = "BgFlash", .render = bgflash_render};+/* the Oshiro left on the roof: an Entity with his sprite and a light */+typedef struct { Sprite spr; float y; } Osh0;+static void osh0_update(Ent *e) { spr_update(&ST(e, Osh0)->spr); }+static void osh0_render(Ent *e) {+ Osh0 *o = ST(e, Osh0);+ draw_npc(&o->spr, e->x, e->y + o->y);+ light_add(e->x, e->y - 8, 0xFFFFFF, 1, 16, 32);+}+static const EntClass OSH0 = {.size = sizeof(Osh0), .name = "oshiro", .update = osh0_update, .render = osh0_render};+/* the player's RunPlayerRight, which goes on after the cutscene */+typedef struct { Walk run; float wait; } Runner;+static void runner_update(Ent *e) {+ Runner *r = ST(e, Runner);+ Player *p = level_player();+ if (r->wait > 0) {+ r->wait -= DT;+ if (r->wait <= 0 && p) r->run = walk_to(p->ent->x + 128), r->run.mode = RUN_TO;+ return;+ }+ if (!p || !player_walk(p, &r->run)) ent_remove(e);+}+static const EntClass RUNNER = {.size = sizeof(Runner), .name = "RunPlayerRight", .update = runner_update};++typedef struct {+ Cutscene cs;+ Ent *roof, *ghost, *tb, *bg, *osh;+ Walk walk, run;+ Step step;+ Pan pan, pan2;+ Co ev, smash;+ Tween tw;+ V2 fall, ghost_to, lpos, cam_to;+ float t, sp, from, to, ground, lrot, light_t, wait;+ int8_t evi;+ uint8_t running, moving, lightning, cam2, sm_final;+} End3;+static bool end3_ghost_to(End3 *s) { /* MoveGhostTo */+ Ent *g = s->ghost;+ if (!g || !g->cls) return false;+ V2 d = v2sub(s->ghost_to, v2(g->x, g->y));+ float l = v2len(d), k = 64 * DT;+ if (l <= k) {+ g->x = s->ghost_to.x, g->y = s->ghost_to.y;+ return false;+ }+ g->x += d.x / l * k, g->y += d.y / l * k;+ return true;+}+/* GhostSmash(topDelay, final): a nested step */+static bool end3_smash(End3 *s, float top_delay, bool final) {+ Ent *g = s->ghost;+ Player *p = &g_player;+ Co *c = &s->smash;+ if (!g || !g->cls) return false;+ Osh *o = ST(g, Osh);+ if (c->wait > 0) {+ c->wait -= DT;+ return true;+ }+ switch (c->co) {+ case 0:+ s->from = g->y, s->to = g->y - 32;+ s->sp = 0, c->co = 1;+ /* fall through */+ case 1:+ if (s->sp < 1) {+ g->y = lerpf(s->from, s->to, ease_cube_out(s->sp));+ s->sp += DT * 2;+ return true;+ }+ c->wait = top_delay, c->co = 2;+ return true;+ case 2:+ s->ground = s->from + 20;+ s->sp = 0, c->co = 3;+ /* fall through */+ case 3:+ if (s->sp < 1) {+ g->y = lerpf(s->to, s->ground, ease_cube_out(s->sp));+ s->sp += DT * 8;+ return true;+ }+ o->sx = 1.3f, o->sy = 0.5f, o->shake_timer = 0.5f; /* Squish */+ level_shake(0.5f);+ plat_start_shaking(s->roof, 0.5f);+ s->sp = 0, c->co = 4;+ if (final) {+ g->y = (s->ground + s->from) / 2;+ goto wobble;+ }+ /* fall through */+ case 4:+ if (s->sp < 1) {+ g->y = lerpf(s->ground, s->from, ease_cube_out(s->sp));+ s->sp += DT * 16;+ return true;+ }+ wobble:+ p->dummy_auto_animate = false;+ spr_play(&p->spr, A_player_shaking, false);+ roof_wobble(s->roof, g, final);+ c->co = 5;+ if (!final) {+ c->wait = 0.5f;+ return true;+ }+ /* fall through */+ default:+ c->co = 0;+ return false;+ }+}+static bool end3_event(void *ctx, int index) { /* GhostSmash; then CH3_ENDING's OshiroTurns */+ End3 *s = ST((Ent *)ctx, End3);+ Co *c = ev_start(&s->ev, &s->evi, index);+ EV_BEGIN;+ if (s->osh) {+ EV_WAIT(1);+ ST(s->osh, Osh0)->spr.sx = -1;+ EV_WAIT(0.2f);+ return true;+ }+ memset(&s->smash, 0, sizeof s->smash);+ EV_NEST(end3_smash(s, 0, false));+ EV_END;+}+static void end3_end(Ent *e, bool skipped) {+ (void)e, (void)skipped;+ level_complete_area(true, false);+ g_wipe.focus = v2(192, 120);+}+static void end3_render(Ent *e) { /* its Sprite: the lightning ("oshiro_boss_lightning", Justify (0, 0.5)) */+ End3 *s = ST(e, End3);+ if (!s->lightning) return;+ int f = (int)(s->light_t / 0.03f);+ if (f > 6) return;+ gfx_tex_ex(osh_light[f], s->lpos.x, s->lpos.y, 0, 32, 1, 1, s->lrot, 0xFFFF, 255, 0);+}+static void end3_update(Ent *e) {+ End3 *s = ST(e, End3);+ Ent *g = s->ghost;+ Player *p = &g_player;+ if (s->running && !player_walk(p, &s->run)) s->running = 0; /* Add(new Coroutine(player.DummyRunTo(...))) */+ if (s->moving && !end3_ghost_to(s)) s->moving = 0;+ if (s->lightning) s->light_t += DT;+ if (s->tw.active && g && g->cls) { /* the falling Oshiro's turn */+ tween_update(&s->tw);+ ST(g, Osh)->rot = ease_sine_inout(s->tw.percent) * -100 * (PI_F / 180);+ }+ if (s->cam2 && !pan_to(&s->pan2, s->cam_to, s->cam2 == 1 ? 3 : 2, ease_cube_inout, false)) s->cam2 = 0;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_hold(p);+ p->force_camera_update = false;+ s->run = walk_to(e_right(s->roof) - 32), s->run.mode = RUN_TO, s->run.flags = RUN_FAST, s->running = 1;+ CO_YIELD(c);+ p->dummy_auto_animate = false;+ CO_WAIT(c, 0.5f);+ for (int i = 0; i < g_nents && !s->ghost; i++)+ if (g_ents[i].cls == &OSHIRO && g_ents[i].dead != 1) s->ghost = &g_ents[i];+ g = s->ghost;+ if (g) { /* MoveGhostTo(roof + (40, -12)): its target less half its height */+ s->ghost_to = v2(s->roof->x + 40, s->roof->y - 12 - 14);+ osh_state(g, ST(g, Osh), OS_DUMMY);+ g->collidable = 0;+ s->moving = 1;+ }+ CO_WAIT(c, 1);+ p->dummy_auto_animate = true;+ step_reset(&s->step);+ CO_NEST(c, zoom_to(&s->step, v2(130, 60), 2, 0.5f));+ p->facing = -1;+ CO_WAIT(c, 0.5f);+ s->evi = -1;+ CO_SAY(c, s->tb, "CH3_OSHIRO_CHASE_END", end3_event, e);+ memset(&s->smash, 0, sizeof s->smash);+ CO_NEST(c, end3_smash(s, 0.5f, true));+ s->bg = ent_new(&BGFLASH, 0, 0);+ if (s->bg) s->bg->depth = 10100, s->bg->collidable = 0, *ST(s->bg, float) = 1;+ if (g && g->cls) {+ s->lpos = v2add(v2(g->x, g->y), v2(140, -100));+ V2 d = v2sub(v2add(v2(g->x, g->y), v2(0, 10)), s->lpos);+ s->lrot = atan2f(d.y, d.x);+ s->lightning = 1, s->light_t = 0;+ }+ CO_YIELD(c);+ level_freeze(0.3f);+ CO_YIELD(c);+ level_shake(0.3f);+ CO_WAIT(c, 0.2f);+ ch1_flash(0xFFFFFF);+ p->dummy_gravity = false;+ if (g && g->cls) ospr_play(&ST(g, Osh)->spr, OA_BACK, false);+ spr_play(&p->spr, A_player_fall, false);+ ST(s->roof, Roof)->begin_falling = 1;+ CO_YIELD(c);+ g_time_rate = 0.01f;+ spr_play(&p->spr, A_player_fallFast, false);+ p->dummy_gravity = true;+ p->speed = v2(300, -200);+ s->fall = v2(-100, -250);+ tween_start(&s->tw, 1.5f);+ for (s->t = 0; s->t < 2; s->t += DT) {+ s->fall.x = approach(s->fall.x, 0, DT * 400);+ s->fall.y += DT * 800;+ if (g && g->cls) g->x += s->fall.x * DT, g->y += s->fall.y * DT;+ if (s->bg) *ST(s->bg, float) = approach(*ST(s->bg, float), 0, RAW_DT);+ g_time_rate = approach(g_time_rate, 1, RAW_DT * 0.6f);+ CO_YIELD(c);+ }+ level_dir_shake(v2(0, -1), 0.5f);+ CO_WAIT(c, 1);+ for (int i = 0; i < 400 && !actor_on_ground(p->ent, 1); i++) actor_move_v(p->ent, 1, NULL, NULL);+ p->dummy_auto_animate = false;+ spr_play(&p->spr, A_player_tired, false);+ if (g && g->cls) ent_remove(g);+ s->ghost = NULL;+ s->osh = ent_new(&OSH0, (float)(g_level.room->x + 110), p->ent->y);+ if (s->osh) {+ ent_box(s->osh, 8, 8, -4, -8);+ Osh0 *o = ST(s->osh, Osh0);+ spr_init(&o->spr, SB_oshiro);+ spr_play(&o->spr, A_oshiro_fall, false);+ }+ s->pan.p = -1;+ CO_NEST(c, pan_to(&s->pan, v2add(player_camera_target(p), v2(0, 40)), 1, ease_cube_out, false));+ CO_WAIT(c, 1.5f);+ CO_WAIT(c, 3);+ if (!s->osh) goto out;+ spr_play(&ST(s->osh, Osh0)->spr, A_oshiro_recover, false);+ s->to = s->osh->y + 4;+ while (s->osh->y != s->to) {+ s->osh->y = approach(s->osh->y, s->to, 6 * DT);+ CO_YIELD(c);+ }+ CO_WAIT(c, 0.6f);+ s->evi = -1;+ CO_SAY(c, s->tb, "CH3_ENDING", end3_event, e);+ s->pan2.p = -1, s->cam_to = v2add(g_level.cam, v2(-80, 0)), s->cam2 = 1;+ CO_WAIT(c, 0.5f);+ ST(s->osh, Osh0)->spr.sx = -1;+ CO_WAIT(c, 0.2f);+ for (s->t = 0; s->osh->x > g_level.room->x - 16;) {+ s->osh->x -= 40 * DT;+ s->t += DT * 2;+ ST(s->osh, Osh0)->y = sinf(s->t) * 2;+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &DOOR && g_ents[i].dead != 1 && collide_ent_at(s->osh, s->osh->x, s->osh->y, &g_ents[i])) {+ door_open(&g_ents[i], s->osh->x);+ break;+ }+ CO_YIELD(c);+ }+ s->pan2.p = -1, s->cam_to = v2add(g_level.cam, v2(80, 0)), s->cam2 = 2;+ CO_WAIT(c, 1.2f);+out:+ p->dummy_auto_animate = true;+ s->walk = walk_to(p->ent->x - 16);+ CO_NEST(c, player_walk(p, &s->walk));+ CO_WAIT(c, 2);+ p->facing = 1;+ CO_WAIT(c, 1);+ p->force_camera_update = false;+ {+ Ent *r = ent_new(&RUNNER, 0, 0);+ if (r) r->tags = TAG_PERSISTENT, r->collidable = 0, r->visible = 0, ST(r, Runner)->wait = 0.75f;+ }+ cutscene_end(e);+ return;+ CO_END(c);+}+static const EntClass END3 = {.size = sizeof(End3), .name = "CS03_Ending", .update = end3_update, .render = end3_render};+static void roof_awake(Ent *e) {+ plat_static_movers_attach(e);+ Player *p = level_player();+ if (!level_get_flag("oshiroEnding") && p) { /* Scene.Add(new CS03_Ending(this, player)) */+ Ent *c = ent_new(&END3, 0, 0);+ if (!c) return;+ c->collidable = 0;+ c->depth = -1000000;+ ST(c, End3)->roof = e;+ level_register_complete();+ cutscene_start(c, end3_end, false, true);+ }+}++/* ---------------------------------------------------------------- LightFadeTrigger, BloomFadeTrigger */+typedef struct { float from, to; uint8_t mode, bloom; } Fade;+static int position_mode(const char *m) {+ static const char *modes[] = {"NoEffect", "LeftToRight", "RightToLeft", "TopToBottom", "BottomToTop", "HorizontalCenter", "VerticalCenter"};+ for (int i = 0; i < 7; i++)+ if (!strcmp(m, modes[i])) return i;+ return 0;+}+static float position_lerp(Ent *e, Player *p, int mode) { /* Trigger.GetPositionLerp */+ float px = p->ent->x, py = p->ent->y;+ float l = e_left(e), r = e_right(e), t = e_top(e), b = e_bottom(e), cx = e_cxm(e), cy = e_cym(e);+ switch (mode) {+ case 1: return clamped_map(px, l, r, 0, 1);+ case 2: return clamped_map(px, r, l, 0, 1);+ case 3: return clamped_map(py, t, b, 0, 1);+ case 4: return clamped_map(py, b, t, 0, 1);+ case 5: return fminf(clamped_map(px, l, cx, 0, 1), clamped_map(px, r, cx, 0, 1));+ case 6: return fminf(clamped_map(py, t, cy, 0, 1), clamped_map(py, b, cy, 0, 1));+ default: return 1;+ }+}+static float area_darkness(void) { /* AreaData.DarknessAlpha */+ static const float D[11] = {0.05f, 0.05f, 0.15f, 0.15f, 0.1f, 0.15f, 0.15f, 0.05f, 0.05f, 0.05f, 0.05f};+ return g_session.area < 11 ? D[g_session.area] : 0.05f;+}+static float area_bloom(void) { /* AreaData.BloomBase */+ static const float B[11] = {0, 0, 0.5f, 0, 0.25f, 0, 0, 0, 0, 0, 0};+ return g_session.area < 11 ? B[g_session.area] : 0;+}+static void fade_stay(Ent *e, Player *p) {+ Fade *f = ST(e, Fade);+ float v = f->from + (f->to - f->from) * clampf(position_lerp(e, p, f->mode), 0, 1);+ if (f->bloom) {+ g_session.bloom_base_add = v;+ g_level.bloom = area_bloom() + v;+ } else {+ g_session.lighting_alpha_add = v;+ g_level.lighting = area_darkness() + v;+ }+}+static const EntClass FADETRIG = {.name = "fadeTrigger", .size = sizeof(Fade), .on_stay = fade_stay, .kind = KIND_TRIGGER};++/* ---------------------------------------------------------------- the factories */+bool ents_ch3(const EData *d) {+ if (!keys_restored && !level_player_ent()) { /* a level (re)load: the session's keys */+ keys_restored = true;+ restore_keys();+ }+ switch (d->type) {+ case ET_yellowBlocks: new_clutter_area(d, CL_YELLOW, EA(d, yellowBlocks, width), EA(d, yellowBlocks, height)); return true;+ case ET_greenBlocks: new_clutter_area(d, CL_GREEN, EA(d, greenBlocks, width), EA(d, greenBlocks, height)); return true;+ case ET_redBlocks: new_clutter_area(d, CL_RED, EA(d, redBlocks, width), EA(d, redBlocks, height)); return true;+ case ET_clutterCabinet: new_cabinet(d); return true;+ case ET_colorSwitch: new_cswitch(d); return true;+ case ET_clutterDoor: new_gdoor(d, false); return true;+ case ET_oshirodoor: new_gdoor(d, true); return true;+ case ET_resortLantern: new_lantern(d); return true;+ case ET_cobweb: new_cobweb(d); return true;+ case ET_triggerSpikesUp: new_tspikes(d, TS_UP, (int)EA(d, triggerSpikesUp, width)); return true;+ case ET_triggerSpikesDown: new_tspikes(d, TS_DOWN, (int)EA(d, triggerSpikesDown, width)); return true;+ case ET_triggerSpikesLeft: new_tspikes(d, TS_LEFT, (int)EA(d, triggerSpikesLeft, height)); return true;+ case ET_triggerSpikesRight: new_tspikes(d, TS_RIGHT, (int)EA(d, triggerSpikesRight, height)); return true;+ case ET_door: new_door(d); return true;+ case ET_trapdoor: new_hatch(d); return true;+ case ET_sinkingPlatform: new_sinking(d); return true;+ case ET_movingPlatform: new_moving(d); return true;+ case ET_clothesline: new_clothesline(d); return true;+ case ET_water: new_water(d); return true;+ case ET_waterfall: new_waterfall(d); return true;+ case ET_friendlyGhost: new_oshiro(d->x, d->y, false); return true;+ case ET_resortmirror: new_rmirror(d); return true;+ case ET_picoconsole: new_pico(d); return true;+ case ET_key: new_key(d); return true;+ case ET_lockBlock: new_lock(d); return true;+ case ET_blockField: {+ Ent *e = ent_new(&BLOCKFIELD, d->x, d->y);+ if (e) ent_box(e, EA(d, blockField, width), EA(d, blockField, height), 0, 0), e->visible = 0;+ return true;+ }+ case ET_killbox: {+ Ent *e = ent_new(&KILLBOX3, d->x, d->y);+ if (e) ent_box(e, EA(d, killbox, width), 32, 0, 0), e->visible = 0, e->collidable = 0;+ return true;+ }+ case ET_resortRoofEnding: new_roof(d); return true;+ case ET_npc: {+ static const char *const NPCS[9] = {"oshiro_03_lobby", "oshiro_03_hallway", "oshiro_03_hallway2", "oshiro_03_bigroom",+ "oshiro_03_breakdown", "oshiro_03_suite", "oshiro_03_rooftop", "theo_03_escaping",+ "theo_03_vents"};+ const char *n = EAS(d, npc, npc);+ for (int i = 0; i < 9; i++)+ if (!strcmp(n, NPCS[i])) {+ if (i < 7) new_osh(d, i);+ else new_theo3(d, i - 7);+ return true;+ }+ return false;+ }+ }+ return false;+}++static void diary_start(Ent *e, Player *p) { read3_start(e, p, 0); }+static void guestbook_start(Ent *e, Player *p) { read3_start(e, p, 1); }+static void memo_start(Ent *e, Player *p) { read3_start(e, p, 2); }+bool trigs_ch3(const EData *d) {+ switch (d->type) {+ case TT_interactTrigger: { /* CS03_Diary, CS03_Guestbook, CS03_Memo */+ static const char *const EV[3] = {"ch3_diary", "ch3_guestbook", "ch3_memo"};+ static void (*const FN[3])(Ent *e, Player *p) = {diary_start, guestbook_start, memo_start};+ const char *ev = EAS(d, interactTrigger, event);+ for (int i = 0; i < 3; i++)+ if (!strcmp(ev, EV[i])) {+ ch2_interact_new(d, FN[i]);+ return true;+ }+ return false;+ }+ case TT_oshiroTrigger: {+ Ent *e = ent_new(&OSHTRIG, d->x, d->y);+ if (e) ent_box(e, EA(d, oshiroTrigger, width), EA(d, oshiroTrigger, height), 0, 0), e->visible = 0,+ ST(e, OshTrig)->state = EAB(d, oshiroTrigger, state);+ return true;+ }+ case TT_lightFadeTrigger:+ case TT_bloomFadeTrigger: {+ bool bloom = d->type == TT_bloomFadeTrigger;+ Ent *e = ent_new(&FADETRIG, d->x, d->y);+ if (!e) return true;+ e->visible = 0;+ Fade *f = ST(e, Fade);+ f->bloom = bloom;+ if (bloom) {+ ent_box(e, EA(d, bloomFadeTrigger, width), EA(d, bloomFadeTrigger, height), 0, 0);+ f->from = EA(d, bloomFadeTrigger, bloomAddFrom), f->to = EA(d, bloomFadeTrigger, bloomAddTo);+ f->mode = (uint8_t)position_mode(EAS(d, bloomFadeTrigger, positionMode));+ } else {+ ent_box(e, EA(d, lightFadeTrigger, width), EA(d, lightFadeTrigger, height), 0, 0);+ f->from = EA(d, lightFadeTrigger, lightAddFrom), f->to = EA(d, lightFadeTrigger, lightAddTo);+ f->mode = (uint8_t)position_mode(EAS(d, lightFadeTrigger, positionMode));+ e->tags = TAG_TRANSITION_UPDATE;+ }+ return true;+ }+ }+ return false;+}++/* this chapter's tables: in the memory it is given while it is played (res_chapter_ram) */+uint32_t ch3_ram(void) { return g_session.area == 3 ? END_clut_off : END_ts_state; } /* the clutter: the Resort's */diff --git a/games/celeste/src/ch4.c b/games/celeste/src/ch4.cnew file mode 100644index 00000000..d29b1ed8--- /dev/null+++ b/games/celeste/src/ch4.c@@ -0,0 +1,2220 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* Golden Ridge (chapter 4), ported from the game's classes: boosters (the+ * green and red bubbles), move blocks (MoveBlock and its debris), clouds,+ * ridge gates, the white block, the gondola, the cliffside flags (CliffsideWindFlag,+ * CliffFlags), and the wind: WindController (which also does the player's+ * WindMove), WindTrigger, WindAttackTrigger and its Snowball. The story: Granny+ * (NPC04_Granny, CS04_Granny), Theo and the gondola's ride (NPC04_Theo, CS04_Gondola) with its+ * breathing (BreathingMinigame). */+#include <stdlib.h>+#include "npc.h"+#include "talk.h"++/* the story's shared pieces (ch1.c, ch2.c) */+void ch1_talk_add(Ent *owner, Talk *t, int x, int y, int w, int h, V2 draw_at);+void ch1_talk_remove(Ent *owner);+void ch1_flash(uint32_t color);+typedef struct { V2 target; float speed, alpha; int8_t turn; uint8_t step, flags, pad; } Move;+bool ch1_move_to(Ent *e, Sprite *s, Move *m, float maxspeed, int move_anim, int idle_anim);+Ent *ch2_bdummy_new(V2 at);+void ch2_bdummy_appear(Ent *e);+void ch2_bdummy_vanish(Ent *e);+void ch2_bdummy_floatness(Ent *e, float f);+Ent *ch2_selfie_new(int mode);+bool ch2_selfie_running(Ent *e);++/* ---------------------------------------------------------------- helpers */+static uint16_t tex(const char *p) { return res_tex_by_name(p); }+static const Room *room_ptr(const Ent *e) { return &g_level.rooms[e->room]; }+static int16_t ent_ref(const Ent *e) { return e ? (int16_t)(e - g_ents) : -1; }+static Ent *ent_at(int16_t i, const EntClass *cls) { return i >= 0 && g_ents[i].cls == cls && g_ents[i].dead != 1 ? &g_ents[i] : NULL; }+static float quad_curve(float a, float c, float b, float t) { return (1 - t) * (1 - t) * a + 2 * (1 - t) * t * c + t * t * b; }+static V2 curve_point(V2 a, V2 b, V2 c, float t) { return v2(quad_curve(a.x, c.x, b.x, t), quad_curve(a.y, c.y, b.y, t)); }+static uint32_t hash32(uint32_t x) {+ x ^= x >> 16, x *= 0x7feb352du, x ^= x >> 15, x *= 0x846ca68bu, x ^= x >> 16;+ return x;+}+static uint32_t lerp_color(uint32_t a, uint32_t b, float t) { /* Color.Lerp, on bytes */+ t = clampf(t, 0, 1);+ int r = (int)(((a >> 16) & 255) + (((int)((b >> 16) & 255) - (int)((a >> 16) & 255)) * t));+ int g = (int)(((a >> 8) & 255) + (((int)((b >> 8) & 255) - (int)((a >> 8) & 255)) * t));+ int bl = (int)((a & 255) + (((int)(b & 255) - (int)(a & 255)) * t));+ return (uint32_t)(r << 16 | g << 8 | bl);+}++/* drawing straight into a strip (gfx_custom layers): view coordinates */+static inline void sp_plot(uint16_t *strip, int sy0, int sy1, int x, int y, uint16_t c, int a) {+ if (y < sy0 || y >= sy1 || (unsigned)x >= VIEW_W) return;+ uint16_t *d = strip + (y - sy0) * VIEW_W + x;+ *d = a >= 256 ? c : blend565(*d, scale565(c, a), a);+}+static void sp_rect(uint16_t *strip, int sy0, int sy1, int x, int y, int w, int h, uint16_t c, int a) {+ int x0 = x < 0 ? 0 : x, x1 = x + w > VIEW_W ? VIEW_W : x + w;+ int y0 = y < sy0 ? sy0 : y, y1 = y + h > sy1 ? sy1 : y + h;+ if (x0 >= x1 || y0 >= y1 || a <= 0) return;+ uint16_t pc = a >= 256 ? c : scale565(c, a);+ for (int r = y0; r < y1; r++) {+ uint16_t *d = strip + (r - sy0) * VIEW_W + x0;+ if (a >= 256)+ for (int i = x0; i < x1; i++) *d++ = c;+ else+ for (int i = x0; i < x1; i++, d++) *d = blend565(*d, pc, a);+ }+}+static void sp_line(uint16_t *strip, int sy0, int sy1, int x0, int y0, int x1, int y1, uint16_t c, int a) {+ if ((y0 < sy0 && y1 < sy0) || (y0 >= sy1 && y1 >= sy1)) return;+ int dx = abs(x1 - x0), dy = -abs(y1 - y0), sx = x0 < x1 ? 1 : -1, sy = y0 < y1 ? 1 : -1, err = dx + dy;+ for (int guard = 0; guard < 2048; guard++) {+ sp_plot(strip, sy0, sy1, x0, y0, c, a);+ if (x0 == x1 && y0 == y1) break;+ int e2 = 2 * err;+ if (e2 >= dy) err += dy, x0 += sx;+ if (e2 <= dx) err += dx, y0 += sy;+ }+}+static inline int vx(float x) { return (int)floorf(x + 0.5f) - g_camx; }+static inline int vy(float y) { return (int)floorf(y + 0.5f) - g_camy; }+enum { OFF_rowbuf = 0, END_rowbuf = OFF_rowbuf + (int)sizeof(uint8_t[256]) };+#define rowbuf (*(uint8_t(*)[256])(void *)(g_chram[4] + OFF_rowbuf))+static void tex_row_idx(const Tex *t, int r, uint8_t *out) { tex_row(t, r, out); }+static inline void sp_texel(uint16_t *d, const uint16_t *col, const uint8_t *al, uint8_t v, uint16_t tint, int ga, bool sil) {+ int aa = al[v - 1] + (al[v - 1] >> 7);+ uint16_t c = sil ? (aa >= 256 ? tint : scale565(tint, aa)) : tint != 0xFFFF ? mul565(col[v - 1], tint) : col[v - 1];+ if (ga < 256) c = scale565(c, ga), aa = (aa * ga) >> 8;+ *d = aa >= 256 ? c : blend565(*d, c, aa);+}+static bool layer_once(uint32_t *mark) {+ if (*mark == g_frame + 1) return false;+ *mark = g_frame + 1;+ return true;+}++/* ---------------------------------------------------------------- Booster */+typedef struct {+ Sprite spr;+ Wiggler wig;+ V2 spr_pos, dir;+ float respawn, cannot_use;+ int16_t outline;+ uint8_t red, boosting, routine, was_current, leaving;+} Booster;+static const EntClass BOOSTER, BOOSTER_OUTLINE;+/* (the sprites exist in data.bin when some map's rooms ask for them: hence the #ifdefs) */+static int booster_anim(const Booster *b, int which) { /* 0 loop, 1 inside, 2 spin, 3 pop */+#ifdef SB_boosterRed+ if (b->red)+ return which == 0 ? A_boosterRed_loop : which == 1 ? A_boosterRed_inside : which == 2 ? A_boosterRed_spin : A_boosterRed_pop;+#endif+#ifdef SB_booster+ if (!b->red) return which == 0 ? A_booster_loop : which == 1 ? A_booster_inside : which == 2 ? A_booster_spin : A_booster_pop;+#endif+ (void)b, (void)which;+ return 0;+}+static int booster_bank(bool red) {+#ifdef SB_boosterRed+ if (red) return SB_boosterRed;+#endif+#ifdef SB_booster+ if (!red) return SB_booster;+#endif+ (void)red;+ return -1;+}+static void booster_appear_particles(Ent *e, Booster *b) {+ for (int i = 0; i < 360; i += 30)+ particles_emit(PL_BG, b->red ? &P_Booster_P_RedAppear : &P_Booster_P_Appear, 1, v2(e->x, e->y + 2), v2(2, 2), i * (PI_F / 180));+}+static void booster_released(Ent *e, Booster *b) { /* PlayerReleased */+ (void)e;+ spr_play(&b->spr, booster_anim(b, 3), false);+ b->cannot_use = 0;+ b->respawn = 1;+ b->boosting = 0;+ b->wig.active = false;+}+static void booster_on_player(Ent *e, Player *p) {+ Booster *b = ST(e, Booster);+ if (b->respawn <= 0 && b->cannot_use <= 0 && !b->boosting) {+ b->cannot_use = 0.45f;+ player_boost(p, e, b->red);+ p->boost_target = v2(e->x, e->y + 2); /* Booster.Center: its Circle(10) is at (0, 2) */+ wiggler_restart(&b->wig);+ spr_play(&b->spr, booster_anim(b, 1), false);+ b->spr.flipx = p->facing == -1;+ }+}+static void booster_on_dash(Ent *e, V2 dir) { /* DashListener */+ (void)dir;+ Booster *b = ST(e, Booster);+ if (b->boosting) b->boosting = 0;+}+static void booster_boosted(Ent *e, Booster *b, Player *p) { /* PlayerBoosted, from the player's dash */+ b->boosting = 1;+ e->tags = TAG_PERSISTENT | TAG_TRANSITION_UPDATE;+ spr_play(&b->spr, booster_anim(b, 2), false);+ b->spr.flipx = p->facing == -1;+ Ent *o = ent_at(b->outline, &BOOSTER_OUTLINE);+ if (o) o->visible = 1;+ wiggler_restart(&b->wig);+ b->dir = p->dash_dir;+ b->routine = 1; /* BoostRoutine */+}+static void booster_update(Ent *e) {+ Booster *b = ST(e, Booster);+ Player *p = level_player();+ /* base.Update(): sprite, wiggler, the dash routine */+ spr_update(&b->spr);+ wiggler_update(&b->wig);+ if (b->routine == 1) {+ if (p && (p->state == ST_DASH || p->state == ST_REDDASH) && b->boosting) {+ b->spr_pos = v2sub(v2add(player_center(p), v2(0, -2)), v2(e->x, e->y));+ if (level_on_interval(0.02f))+ particles_emit(PL_BG, b->red ? &P_Booster_P_BurstRed : &P_Booster_P_Burst, 2,+ v2add(v2sub(player_center(p), v2mul(b->dir, 3)), v2(0, -2)), v2(3, 3), atan2f(-b->dir.y, -b->dir.x));+ } else {+ booster_released(e, b);+ if (p && p->state == ST_BOOST) b->spr.visible = 0;+ b->routine = 2;+ }+ } else if (b->routine == 2) {+ if (!g_level.transitioning) e->tags = 0, b->routine = 0;+ }+ /* the player's dash out of it: Player.CallDashEvents -> PlayerBoosted (player.c's level_booster_boosted does nothing) */+ bool cur = p && p->current_booster == e;+ if (b->was_current && !cur && p && !p->dead && (p->state == ST_DASH || p->state == ST_REDDASH)) booster_boosted(e, b, p);+ b->was_current = cur;+ if (p && p->dead && b->boosting) { /* PlayerDied */+ booster_released(e, b);+ b->routine = 0;+ e->tags = 0;+ }+ /* Update's own */+ if (b->cannot_use > 0) b->cannot_use -= DT;+ if (b->respawn > 0) {+ b->respawn -= DT;+ if (b->respawn <= 0) { /* Respawn */+ b->spr_pos = v2(0, 0);+ spr_play(&b->spr, booster_anim(b, 0), true);+ wiggler_restart(&b->wig);+ b->spr.visible = 1;+ Ent *o = ent_at(b->outline, &BOOSTER_OUTLINE);+ if (o) o->visible = 0;+ booster_appear_particles(e, b);+ }+ }+ if (!b->routine && b->respawn <= 0) {+ V2 target = v2(0, 0);+ if (p && collide_ent_at(e, e->x, e->y, p->ent)) target = v2sub(v2add(player_center(p), v2(0, -2)), v2(e->x, e->y));+ V2 d = v2sub(target, b->spr_pos);+ float l = v2len(d), m = 80 * DT;+ b->spr_pos = l <= m ? target : v2add(b->spr_pos, v2mul(d, m / l));+ }+ if (spr_is(&b->spr, booster_anim(b, 1)) && !b->boosting && !(p && collide_ent_at(e, e->x, e->y, p->ent)))+ spr_play(&b->spr, booster_anim(b, 0), false);+}+static void booster_render(Ent *e) {+ Booster *b = ST(e, Booster);+ if (!b->spr.visible) return;+ Sprite s = b->spr;+ s.sx = s.sy = 1 + b->wig.value * 0.25f;+ float x = e->x + floorf(b->spr_pos.x), y = e->y + floorf(b->spr_pos.y);+ if (!spr_is(&s, booster_anim(b, 3))) { /* DrawOutline */+ Sprite o = s;+ o.tint = 0;+ for (int i = -1; i < 2; i++)+ for (int j = -1; j < 2; j++)+ if (i || j) spr_draw(&o, x + i, y + j);+ }+ spr_draw(&s, x, y);+ light_add(e->x, e->y, 0xFFFFFF, 1, 16, 32);+ bloom_add(e->x, e->y, 0.1f, 16);+}+static void outline_render(Ent *e) { gfx_tex_ex(tex("objects/booster/outline"), e->x, e->y, 16, 16, 1, 1, 0, 0xFFFF, 191, 0); }+static const EntClass BOOSTER_OUTLINE = {.name = "boosterOutline", .size = 0, .render = outline_render};+static const EntClass BOOSTER = {.name = "booster", .size = sizeof(Booster), .update = booster_update, .render = booster_render,+ .on_player = booster_on_player, .on_dash = booster_on_dash, .kind = KIND_PCOLLIDE};+static void new_booster(const EData *d) {+ Ent *e = ent_new(&BOOSTER, d->x, d->y);+ if (!e) return;+ e->depth = -8500;+ ent_circle(e, 10, 0, 2);+ Booster *b = ST(e, Booster);+ b->red = EAB(d, booster, red);+ int bank = booster_bank(b->red);+ if (bank >= 0) spr_init(&b->spr, bank), spr_play(&b->spr, booster_anim(b, 0), true);+ else b->spr.visible = 0;+ wiggler_init(&b->wig, 0.5f, 4);+ Ent *o = ent_new(&BOOSTER_OUTLINE, d->x, d->y); /* Added: the outline, shown while it is away */+ if (o) o->depth = 8999, o->visible = 0, o->collidable = 0;+ b->outline = ent_ref(o);+}++/* ---------------------------------------------------------------- MoveBlock */+enum { MB_LEFT, MB_RIGHT, MB_UP, MB_DOWN };+enum { MS_IDLE, MS_MOVING, MS_BREAKING };+typedef struct {+ V2 start;+ float speed, target_speed, angle, target_angle, home_angle, flash, crash, crash_reset, no_steer, wait, particle_rem;+ uint32_t fill;+ int16_t border, nosquish;+ int8_t steer_sign;+ uint8_t dir, can_steer, fast, state, step, triggered, left_p, right_p, top_p;+} MoveB;+static const EntClass MOVEBLOCK, MB_DEBRIS;+static uint16_t mb_base, mb_base_h, mb_base_v, mb_button, mb_arrow[8], mb_x, mb_debris_tex[3];+#define MB_IDLE_FILL 0x474070+#define MB_PRESSED_FILL 0x30b335+#define MB_BREAKING_FILL 0xcc2541+static bool mb_horizontal(const MoveB *m) { return m->dir == MB_LEFT || m->dir == MB_RIGHT; }+/* MoveHExact / MoveVExact, overridden: not into the player it moves along with (noSquish) */+static void mb_move_exact(Ent *e, MoveB *m, int move, bool vertical) {+ Ent *ns = m->nosquish ? level_player_ent() : NULL;+ if (ns) {+ if (!vertical && ((move < 0 && ns->x < e->x) || (move > 0 && ns->x > e->x)))+ while (move != 0 && collide_solid(ns, ns->x + move, ns->y)) move -= signi(move);+ if (vertical && move < 0 && ns->y <= e->y)+ while (move != 0 && collide_solid(ns, ns->x, ns->y + move)) move -= signi(move);+ }+ if (vertical) plat_move_v_exact(e, move);+ else plat_move_h_exact(e, move);+}+/* Platform.MoveH/VCollideSolids (no dash blocks) with those exact moves */+static bool mb_move_collide(Ent *e, MoveB *m, float amount, bool vertical) {+ if (vertical) e->lift.y = amount / DT;+ else e->lift.x = amount / DT;+ float *rem = vertical ? &e->remy : &e->remx;+ *rem += amount;+ int n = roundi(*rem);+ if (!n) return false;+ *rem -= n;+ int s = signi(n), moved = 0;+ float was = vertical ? e->y : e->x;+ Ent *hit = NULL;+ while (n) {+ hit = collide_first_solid(e, e->x + (vertical ? 0 : s), e->y + (vertical ? s : 0));+ if (hit) break;+ moved += s, n -= s;+ if (vertical) e->y += s;+ else e->x += s;+ }+ if (vertical) e->y = was;+ else e->x = was;+ mb_move_exact(e, m, moved, vertical);+ return hit != NULL;+}+/* MoveCheck: into a wall, or around a corner of up to 3 px */+static bool mb_move_check(Ent *e, MoveB *m, V2 sp) {+ if (sp.x != 0) {+ if (!plat_move_h_collide_solids(e, sp.x, false)) return false;+ for (int i = 1; i <= 3; i++)+ for (int k = 1; k >= -1; k -= 2)+ if (!collide_solid(e, e->x + signf(sp.x), e->y + i * k)) {+ mb_move_exact(e, m, i * k, true);+ mb_move_exact(e, m, (int)signf(sp.x), false);+ return false;+ }+ return true;+ }+ if (sp.y != 0) {+ if (!plat_move_v_collide_solids(e, sp.y, false)) return false;+ for (int j = 1; j <= 3; j++)+ for (int k = 1; k >= -1; k -= 2)+ if (!collide_solid(e, e->x + j * k, e->y + signf(sp.y))) {+ mb_move_exact(e, m, j * k, false);+ mb_move_exact(e, m, (int)signf(sp.y), true);+ return false;+ }+ return true;+ }+ return false;+}+static void mb_activate_particles(Ent *e, MoveB *m) {+ Ent *p = level_player_ent();+ bool vert = m->dir == MB_DOWN || m->dir == MB_UP;+ bool a = (!m->can_steer || !vert) && !(p && collide_ent_at(e, e->x - 1, e->y, p));+ bool b = (!m->can_steer || !vert) && !(p && collide_ent_at(e, e->x + 1, e->y, p));+ bool c = (!m->can_steer || vert) && !(p && collide_ent_at(e, e->x, e->y - 1, p));+ float w = e->cw, h = e->ch;+ if (a) particles_emit(PL_BG, &P_MoveBlock_P_Activate, (int)(h / 2), v2(e->x, e->y + h / 2), v2(0, (h - 4) * 0.5f), PI_F);+ if (b) particles_emit(PL_BG, &P_MoveBlock_P_Activate, (int)(h / 2), v2(e->x + w, e->y + h / 2), v2(0, (h - 4) * 0.5f), 0);+ if (c) particles_emit(PL_BG, &P_MoveBlock_P_Activate, (int)(w / 2), v2(e->x + w / 2, e->y), v2((w - 4) * 0.5f, 0), -PI_F / 2);+ particles_emit(PL_BG, &P_MoveBlock_P_Activate, (int)(w / 2), v2(e->x + w / 2, e->y + h), v2((w - 4) * 0.5f, 0), PI_F / 2);+}+static void mb_move_particles(Ent *e, MoveB *m) {+ V2 pos, range;+ float dir, num;+ float w = e->cw, h = e->ch;+ switch (m->dir) {+ case MB_RIGHT: pos = v2(e->x + 1, e->y + h / 2), range = v2(0, h - 4), dir = PI_F, num = h / 32; break;+ case MB_LEFT: pos = v2(e->x + w, e->y + h / 2), range = v2(0, h - 4), dir = 0, num = h / 32; break;+ case MB_DOWN: pos = v2(e->x + w / 2, e->y + 1), range = v2(w - 4, 0), dir = -PI_F / 2, num = w / 32; break;+ default: pos = v2(e->x + w / 2, e->y + h), range = v2(w - 4, 0), dir = PI_F / 2, num = w / 32; break;+ }+ m->particle_rem += num;+ int n = (int)m->particle_rem;+ m->particle_rem -= n;+ if (n > 0) particles_emit(PL_BG, &P_MoveBlock_P_Move, n, pos, v2mul(range, 0.5f), dir);+}+static void mb_scrape(Ent *e, V2 d) {+ uint8_t was = e->collidable;+ e->collidable = 0;+ if (d.x != 0) {+ float x = d.x > 0 ? e_right(e) : e_left(e) - 1;+ for (int i = 0; (float)i < e->ch; i += 8)+ if (point_solid(x, e_top(e) + 4 + i)) particles_emit1(PL_FG, &P_ZipMover_P_Scrape, v2(x, e_top(e) + 4 + i), P_ZipMover_P_Scrape.direction);+ } else {+ float y = d.y > 0 ? e_bottom(e) : e_top(e) - 1;+ for (int j = 0; (float)j < e->cw; j += 8)+ if (point_solid(e_left(e) + 4 + j, y)) particles_emit1(PL_FG, &P_ZipMover_P_Scrape, v2(e_left(e) + 4 + j, y), P_ZipMover_P_Scrape.direction);+ }+ e->collidable = was;+}++/* MoveBlock.Debris (an Actor) */+typedef struct {+ ActorExt ext;+ V2 home, speed, from, ctrl;+ float rot, spin, alpha, ret, ret_dur;+ int16_t parent;+ int8_t ox, oy;+ uint8_t tex, flip, shaking, returning, first_hit, moving;+} MDebris;+static void mdebris_collide_h(Ent *e, Collision *c) { (void)c, ST(e, MDebris)->speed.x *= -0.5f; }+static void mdebris_collide_v(Ent *e, Collision *c) {+ (void)c;+ MDebris *d = ST(e, MDebris);+ if (d->speed.y > 0 && d->speed.y < 40) d->speed.y = 0;+ else d->speed.y = -d->speed.y * 0.25f;+ d->first_hit = 0;+}+static void mdebris_squish(Ent *e, Collision *c) { (void)e, (void)c; }+static void mdebris_update(Ent *e) {+ MDebris *d = ST(e, MDebris);+ actor_update_lift(e);+ if (!d->returning) {+ if (d->moving) {+ d->speed.x = approach(d->speed.x, 0, DT * 100);+ if (!actor_on_ground(e, 1)) d->speed.y += 400 * DT;+ actor_move_h(e, d->speed.x * DT, mdebris_collide_h, NULL);+ actor_move_v(e, d->speed.y * DT, mdebris_collide_v, NULL);+ }+ if (d->shaking && level_on_interval(0.05f)) d->ox = (int8_t)(rndi(3) - 1), d->oy = (int8_t)(rndi(3) - 1);+ } else {+ V2 at = curve_point(d->from, d->home, d->ctrl, ease_cube_out(d->ret));+ e->x = at.x, e->y = at.y;+ d->ret = approach(d->ret, 1, DT / d->ret_dur);+ }+ if (g_level.transitioning) d->alpha = approach(d->alpha, 0, DT * 4);+ d->rot += d->spin * clamped_map(fabsf(d->speed.y), 50, 150, 0, 1) * DT;+}+static void mdebris_render(Ent *e) {+ MDebris *d = ST(e, MDebris);+ float s = d->returning ? 1 + d->ret * 0.5f : 1;+ gfx_tex_ex(mb_debris_tex[d->tex], e->x + d->ox, e->y + d->oy, 4, 4, d->flip ? -s : s, s, d->rot, 0xFFFF, (uint8_t)(d->alpha * 255), 0);+}+static const EntClass MB_DEBRIS = {.name = "moveBlockDebris", .size = sizeof(MDebris), .update = mdebris_update, .render = mdebris_render,+ .on_squish = mdebris_squish, .kind = KIND_ACTOR};++/* MoveBlock.Border */+typedef struct { int16_t parent; } MBorder;+static void mborder_render(Ent *e) {+ Ent *p = ent_at(ST(e, MBorder)->parent, &MOVEBLOCK);+ if (!p) {+ ent_remove(e);+ return;+ }+ if (!p->visible) return;+ V2 sh = e_shake(p);+ gfx_rect(p->x + sh.x - 1, p->y + sh.y - 1, p->cw + 2, p->ch + 2, 0, 255);+}+static const EntClass MB_BORDER = {.name = "moveBlockBorder", .size = sizeof(MBorder), .render = mborder_render};++static void mb_each_debris(Ent *e, int what, float arg) {+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o->cls != &MB_DEBRIS || o->dead == 1) continue;+ MDebris *d = ST(o, MDebris);+ if (d->parent != ent_ref(e)) continue;+ switch (what) {+ case 0: o->collidable = 0, d->moving = 0; break; /* StopMoving */+ case 1: d->shaking = 1; break; /* StartShaking */+ case 2: { /* ReturnHome */+ float cx = g_level.cam.x, cy = g_level.cam.y;+ if (o->x < cx) o->x = cx - 8;+ if (o->y < cy) o->y = cy - 8;+ if (o->x > cx + 320) o->x = cx + 320 + 8;+ if (o->y > cy + 180) o->y = cy + 180 + 8;+ d->returning = 1, d->ret = 0, d->ret_dur = arg;+ V2 n = v2norm(v2sub(d->home, v2(o->x, o->y)));+ d->from = v2(o->x, o->y);+ d->ctrl = v2add(v2mul(v2add(d->from, d->home), 0.5f), v2mul(v2(n.y, -n.x), (rndf() * 16 + 16) * (rndi(2) ? 1 : -1)));+ break;+ }+ case 3: ent_remove(o); break;+ }+ }+}+static void mb_controller(Ent *e, MoveB *m) {+ if (m->wait > 0) {+ m->wait -= DT;+ return;+ }+ const Room *rm = room_ptr(e);+ switch (m->step) {+ case 0:+ m->triggered = 0;+ m->state = MS_IDLE;+ m->step = 1;+ /* fall through */+ case 1:+ if (!m->triggered && !solid_has_player_rider(e)) return;+ m->state = MS_MOVING;+ plat_start_shaking(e, 0.2f);+ mb_activate_particles(e, m);+ m->wait = 0.2f, m->step = 2;+ return;+ case 2:+ m->target_speed = m->fast ? 75 : 60;+ m->crash = 0.15f, m->crash_reset = 0.1f, m->no_steer = 0.2f;+ m->step = 3;+ /* fall through */+ case 3: {+ bool horiz = mb_horizontal(m);+ if (m->can_steer) {+ m->target_angle = m->home_angle;+ bool flag = horiz ? solid_has_player_on_top(e) : solid_has_player_climbing(e);+ if (flag && m->no_steer > 0) m->no_steer -= DT;+ if (flag) {+ if (m->no_steer <= 0) m->target_angle = m->home_angle + PI_F / 4 * m->steer_sign * (horiz ? g_in.move_y : g_in.move_x);+ } else+ m->no_steer = 0.2f;+ }+ if (level_on_interval(0.02f)) mb_move_particles(e, m);+ m->speed = approach(m->speed, m->target_speed, 300 * DT);+ m->angle = approach(m->angle, m->target_angle, PI_F * 16 * DT);+ V2 v = v2mul(angle_vec(m->angle, m->speed), DT);+ bool stop;+ if (horiz) {+ stop = mb_move_check(e, m, v2(v.x, 0));+ m->nosquish = 1;+ mb_move_collide(e, m, v.y, true);+ m->nosquish = 0;+ if (level_on_interval(0.03f)) {+ if (v.y > 0) mb_scrape(e, v2(0, 1));+ else if (v.y < 0) mb_scrape(e, v2(0, -1));+ }+ } else {+ stop = mb_move_check(e, m, v2(0, v.y));+ m->nosquish = 1;+ mb_move_collide(e, m, v.x, false);+ m->nosquish = 0;+ if (level_on_interval(0.03f)) {+ if (v.x > 0) mb_scrape(e, v2(1, 0));+ else if (v.x < 0) mb_scrape(e, v2(-1, 0));+ }+ if (m->dir == MB_DOWN && e_top(e) > rm->y + rm->h + 32) stop = true;+ }+ bool brk = false;+ if (stop) {+ m->crash_reset = 0.1f;+ if (!(m->crash > 0)) brk = true;+ else m->crash -= DT;+ } else {+ if (m->crash_reset > 0) m->crash_reset -= DT;+ else m->crash = 0.15f;+ }+ if (e_left(e) < rm->x || e_top(e) < rm->y || e_right(e) > rm->x + rm->w) brk = true;+ if (!brk) return;+ m->state = MS_BREAKING; /* the break */+ m->speed = m->target_speed = 0;+ m->angle = m->target_angle = m->home_angle;+ plat_start_shaking(e, 0.2f);+ m->wait = 0.2f, m->step = 4;+ return;+ }+ case 4: {+ V2 c = e_center(e); /* BreakParticles */+ for (int i = 0; (float)i < e->cw; i += 4)+ for (int j = 0; (float)j < e->ch; j += 4) {+ V2 at = v2(e->x + 2 + i, e->y + 2 + j);+ particles_emit(PL_MID, &P_MoveBlock_P_Break, 1, at, v2(2, 2), atan2f(at.y - c.y, at.x - c.x));+ }+ for (int i = 0; (float)i < e->cw; i += 8)+ for (int j = 0; (float)j < e->ch; j += 8) {+ V2 at = v2(e->x + i + 4, e->y + j + 4);+ Ent *d = ent_new(&MB_DEBRIS, at.x, at.y);+ if (!d) continue;+ d->tags = TAG_TRANSITION_UPDATE;+ d->collidable = 1;+ ent_box(d, 4, 4, -2, -2);+ MDebris *s = ST(d, MDebris);+ s->parent = ent_ref(e);+ s->home = v2(m->start.x + i + 4, m->start.y + j + 4);+ V2 dir = v2norm(v2sub(at, c));+ s->speed = v2mul(dir, 60 + rndf() * 60);+ s->tex = (uint8_t)rndi(3);+ s->flip = rndf() < 0.5f;+ s->rot = rndf() * 2 * PI_F;+ s->alpha = 1;+ s->moving = 1;+ s->spin = rnd_rangef(3.4906585f, 10.471975f) * (rndi(2) ? 1 : -1);+ }+ plat_static_movers_move(e, v2(m->start.x - e->x, m->start.y - e->y));+ plat_static_movers_enable(e, false);+ e->x = m->start.x, e->y = m->start.y;+ e->visible = e->collidable = 0;+ m->wait = 2.2f, m->step = 5;+ return;+ }+ case 5:+ mb_each_debris(e, 0, 0);+ m->step = 6;+ /* fall through */+ case 6: { /* while (CollideCheck<Actor>() || CollideCheck<Solid>()) */+ bool blocked = collide_first_solid(e, e->x, e->y) != NULL;+ for (int i = 0; i < g_nents && !blocked; i++) {+ Ent *o = &g_ents[i];+ if ((o->kind & KIND_ACTOR) && o->cls && o->dead != 1 && o->collidable && collide_ent_at(e, e->x, e->y, o)) blocked = true;+ }+ if (blocked) return;+ e->collidable = 1;+ mb_each_debris(e, 1, 0);+ m->wait = 0.2f, m->step = 7;+ return;+ }+ case 7:+ mb_each_debris(e, 2, 0.65f);+ m->wait = 0.6f, m->step = 8;+ return;+ case 8:+ mb_each_debris(e, 3, 0);+ e->visible = 1;+ plat_static_movers_enable(e, true);+ m->speed = m->target_speed = 0;+ m->angle = m->target_angle = m->home_angle;+ m->fill = MB_IDLE_FILL;+ m->flash = 1;+ m->step = 0;+ return;+ }+}+static void mb_update(Ent *e) {+ MoveB *m = ST(e, MoveB);+ mb_controller(e, m); /* the Controller coroutine (a component) */+ plat_update(e);+ if (m->can_steer) {+ Ent *p = level_player_ent();+ bool vert = m->dir == MB_UP || m->dir == MB_DOWN;+ m->left_p = vert && p && collide_ent_at(e, e->x - 1, e->y, p);+ m->right_p = vert && p && collide_ent_at(e, e->x + 1, e->y, p);+ m->top_p = !vert && p && collide_ent_at(e, e->x, e->y - 1, p);+ }+ Ent *b = ent_at(m->border, &MB_BORDER);+ if (b) b->visible = e->visible;+ m->flash = approach(m->flash, 0, DT * 5);+ uint32_t target = m->state == MS_MOVING ? MB_PRESSED_FILL : m->state == MS_BREAKING ? MB_BREAKING_FILL : MB_IDLE_FILL; /* UpdateColors */+ m->fill = lerp_color(m->fill, target, 10 * DT);+}+static void mb_trigger(Ent *e, Ent *sm) { (void)sm, ST(e, MoveB)->triggered = 1; }+/* the side buttons of the up/down blocks are turned a quarter: drawn in a strip layer, not as affine draws */+enum { OFF_mb_btn_px = ((END_rowbuf + 7) & ~7), END_mb_btn_px = OFF_mb_btn_px + (int)sizeof(uint8_t[24 * 8]) };+#define mb_btn_px (*(uint8_t(*)[24 * 8])(void *)(g_chram[4] + OFF_mb_btn_px))+static const uint16_t *mb_btn_col;+static const uint8_t *mb_btn_al;+static uint32_t mb_btn_frame = 0xFFFFFFFF;+static void mb_buttons_layer(uint16_t *strip, int sy0, int sy1, void *ctx) {+ Ent *e = ctx;+ MoveB *m = ST(e, MoveB);+ V2 sh = e_shake(e);+ uint16_t tint = rgb(m->fill);+ int n = (int)(e->ch / 8);+ for (int side = 0; side < 2; side++) {+ float cx = side ? e->cw + (m->right_p ? -2 : 0) : (m->left_p ? 2 : 0);+ for (int j = 0; j < n; j++) {+ int piece = j != 0 ? (j < n - 1 ? 1 : 2) : 0;+ float px = e->x + sh.x + cx, py = e->y + sh.y + j * 8 + 4;+ int X0 = vx(px) - 4, Y0 = vy(py) - 4;+ for (int dy = 0; dy < 8; dy++) {+ int Y = Y0 + dy;+ if (Y < sy0 || Y >= sy1) continue;+ for (int dx = 0; dx < 8; dx++) {+ /* rotation pi/2 then scale (1, -1) on the left, (1, 1) on the right */+ int u = dy, v = side ? 7 - dx : dx;+ uint8_t idx = mb_btn_px[v * 24 + piece * 8 + u];+ int X = X0 + dx;+ if (idx && (unsigned)X < VIEW_W) sp_texel(strip + (Y - sy0) * VIEW_W + X, mb_btn_col, mb_btn_al, idx, tint, 256, false);+ }+ }+ }+ }+}+static void mb_render(Ent *e) {+ MoveB *m = ST(e, MoveB);+ V2 sh = e_shake(e);+ float x = e->x + sh.x, y = e->y + sh.y, w = e->cw, h = e->ch;+ int nx = (int)(w / 8), ny = (int)(h / 8);+ uint16_t fill = rgb(m->fill);+ if (m->can_steer && !mb_horizontal(m)) {+ if (mb_btn_frame != g_frame) {+ mb_btn_frame = g_frame;+ Tex t;+ mb_btn_col = NULL;+ if (tex_get(mb_button, &t) && t.fw == 24 && t.fh == 8) {+ memset(mb_btn_px, 0, sizeof mb_btn_px);+ for (int r = 0; r < t.h; r++) {+ tex_row_idx(&t, r, rowbuf);+ for (int i = 0; i < t.w; i++) mb_btn_px[(t.oy + r) * 24 + t.ox + i] = rowbuf[i];+ }+ int n;+ mb_btn_col = pal_colors(t.pal, &n);+ mb_btn_al = pal_alpha(t.pal);+ }+ }+ if (mb_btn_col) gfx_custom(mb_buttons_layer, e, vy(y) - 1, vy(y + h) + 1);+ } else if (m->can_steer)+ for (int i = 0; i < nx; i++) {+ int piece = i != 0 ? (i < nx - 1 ? 1 : 2) : 0;+ gfx_tex_part(mb_button, x + i * 8, y - 4 + (m->top_p ? 2 : 0), piece * 8, 0, 8, 8, 0, fill, 255);+ }+ gfx_rect(x + 3, y + 3, w - 6, h - 6, fill, 255);+ uint16_t body = !m->can_steer ? mb_base : mb_horizontal(m) ? mb_base_h : mb_base_v;+ for (int k = 0; k < nx; k++)+ for (int l = 0; l < ny; l++) {+ int a = k != 0 ? (k < nx - 1 ? 1 : 2) : 0, b = l != 0 ? (l < ny - 1 ? 1 : 2) : 0;+ gfx_tex_part(body, x + k * 8, y + l * 8, a * 8, b * 8, 8, 8, 0, 0xFFFF, 255);+ }+ gfx_rect(x + w / 2 - 4, y + h / 2 - 4, 8, 8, fill, 255);+ if (m->state != MS_BREAKING) {+ int v = (int)floorf(fmodf(-m->angle + PI_F * 2, PI_F * 2) / (PI_F * 2) * 8 + 0.5f);+ gfx_tex_ex(mb_arrow[clampi(v, 0, 7)], x + w / 2, y + h / 2, 5, 5, 1, 1, 0, 0xFFFF, 255, 0);+ } else+ gfx_tex_ex(mb_x, x + w / 2, y + h / 2, 5, 5, 1, 1, 0, 0xFFFF, 255, 0);+ if (m->flash > 0) {+ float n = m->flash * 4;+ gfx_rect(e->x - n, e->y - n, w + n * 2, h + n * 2, 0xFFFF, (uint8_t)(m->flash * 255));+ }+}+static void mb_awake(Ent *e) {+ plat_static_movers_attach(e);+ Ent *b = ent_new(&MB_BORDER, e->x, e->y);+ if (b) b->depth = 1, b->collidable = 0, ST(b, MBorder)->parent = ent_ref(e);+ ST(e, MoveB)->border = ent_ref(b);+}+static const EntClass MOVEBLOCK = {.name = "moveBlock", .size = sizeof(MoveB), .update = mb_update, .render = mb_render, .awake = mb_awake,+ .on_staticmover_trigger = mb_trigger, .kind = KIND_SOLID};+static void new_moveblock(const EData *d) {+ Ent *e = ent_new(&MOVEBLOCK, d->x, d->y);+ if (!e) return;+ ent_box(e, EA(d, moveBlock, width), EA(d, moveBlock, height), 0, 0);+ e->depth = -1;+ MoveB *m = ST(e, MoveB);+ m->start = v2(d->x, d->y);+ m->can_steer = EAB(d, moveBlock, canSteer);+ m->fast = EAB(d, moveBlock, fast);+ m->border = -1;+ const char *dir = EAS(d, moveBlock, direction);+ m->dir = !strcmp(dir, "Right") ? MB_RIGHT : !strcmp(dir, "Up") ? MB_UP : !strcmp(dir, "Down") ? MB_DOWN : MB_LEFT;+ switch (m->dir) {+ case MB_LEFT: m->home_angle = PI_F, m->steer_sign = -1; break;+ case MB_UP: m->home_angle = -PI_F / 2, m->steer_sign = 1; break;+ case MB_DOWN: m->home_angle = PI_F / 2, m->steer_sign = -1; break;+ default: m->home_angle = 0, m->steer_sign = 1; break;+ }+ m->angle = m->target_angle = m->home_angle;+ m->fill = MB_IDLE_FILL;+ mb_base = tex("objects/moveBlock/base");+ mb_base_h = tex("objects/moveBlock/base_h");+ mb_base_v = tex("objects/moveBlock/base_v");+ mb_button = tex("objects/moveBlock/button");+ mb_x = tex("objects/moveBlock/x");+ char p[40];+ for (int i = 0; i < 8; i++) mb_arrow[i] = tex(path2(p, "objects/moveBlock/arrow", NULL, i));+ for (int i = 0; i < 3; i++) mb_debris_tex[i] = tex(path2(p, "objects/moveBlock/debris", NULL, i));+}++/* ---------------------------------------------------------------- Cloud */+typedef struct {+ Sprite spr;+ Wiggler wig;+ V2 spr_pos, scale;+ float speed, start_y, respawn, timer;+ uint8_t fragile, waiting, returning, last_frame;+} Cloud;+static int cloud_anim(const Cloud *c, int which) { /* 0 idle, 1 fade, 2 spawn */+ bool remix = g_session.mode != M_A;+ (void)remix, (void)which;+ if (!c->fragile) {+#ifdef SB_cloudRemix+ if (remix) return A_cloudRemix_idle;+#endif+#ifdef SB_cloud+ return A_cloud_idle;+#endif+ } else {+#ifdef SB_cloudFragileRemix+ if (remix) return which == 0 ? A_cloudFragileRemix_idle : which == 1 ? A_cloudFragileRemix_fade : A_cloudFragileRemix_spawn;+#endif+#ifdef SB_cloudFragile+ return which == 0 ? A_cloudFragile_idle : which == 1 ? A_cloudFragile_fade : A_cloudFragile_spawn;+#endif+ }+ return 0;+}+static int cloud_bank(bool fragile, bool remix) {+ (void)fragile, (void)remix;+#ifdef SB_cloudFragileRemix+ if (fragile && remix) return SB_cloudFragileRemix;+#endif+#ifdef SB_cloudFragile+ if (fragile) return SB_cloudFragile;+#endif+#ifdef SB_cloudRemix+ if (!fragile && remix) return SB_cloudRemix;+#endif+#ifdef SB_cloud+ if (!fragile) return SB_cloud;+#endif+ return -1;+}+static void cloud_update(Ent *e) {+ Cloud *c = ST(e, Cloud);+ /* base.Update(): the sprite (spawn's 7th frame starts the wiggler), the wiggler, the lift speed */+ spr_update(&c->spr);+ if (c->fragile && spr_is(&c->spr, cloud_anim(c, 2)) && c->spr.frame == 6 && c->last_frame != 6) wiggler_restart(&c->wig);+ c->last_frame = c->spr.frame;+ wiggler_update(&c->wig);+ plat_update(e);+ c->scale.x = approach(c->scale.x, 1, DT);+ c->scale.y = approach(c->scale.y, 1, DT);+ c->timer += DT;+ Player *p = level_player();+ bool rider = p && jumpthru_has_player_rider(e);+ if (rider) c->spr_pos = v2(0, 0);+ else {+ V2 t = v2(0, sinf(c->timer * 2)), d = v2sub(t, c->spr_pos);+ float l = v2len(d), m = DT * 4;+ c->spr_pos = l <= m ? t : v2add(c->spr_pos, v2mul(d, m / l));+ }+ if (c->respawn > 0) {+ c->respawn -= DT;+ if (c->respawn <= 0) {+ c->waiting = 1;+ e->y = c->start_y, e->remy = 0;+ c->speed = 0;+ c->scale = v2(1, 1);+ e->collidable = 1;+ spr_play(&c->spr, cloud_anim(c, 2), false);+ }+ return;+ }+ if (c->waiting) {+ if (rider && p->speed.y >= 0) {+ c->speed = 180;+ c->scale = v2(1.3f, 0.7f);+ c->waiting = 0;+ }+ return;+ }+ if (c->returning) {+ c->speed = approach(c->speed, 180, 600 * DT);+ plat_move_towards_y(e, c->start_y, c->speed * DT);+ if (e->y + e->remy == c->start_y) c->returning = 0, c->waiting = 1, c->speed = 0;+ return;+ }+ if (c->fragile && e->collidable && !rider) {+ e->collidable = 0;+ spr_play(&c->spr, cloud_anim(c, 1), false);+ }+ if (c->speed < 0 && level_on_interval(0.02f))+ particles_emit(PL_BG, c->fragile ? &P_Cloud_P_FragileCloud : &P_Cloud_P_Cloud, 1, v2(e->x, e->y + 2), v2(e->cw / 2, 1), PI_F / 2);+ if (c->fragile && c->speed < 0) c->spr.sy = approach(c->spr.sy, 0, DT * 4);+ if (e->y >= c->start_y) c->speed -= 1200 * DT;+ else {+ c->speed += 1200 * DT;+ if (c->speed >= -100) {+ if (rider && p->speed.y >= 0) p->speed.y = -200;+ if (c->fragile) {+ e->collidable = 0;+ spr_play(&c->spr, cloud_anim(c, 1), false);+ c->respawn = 2.5f;+ } else {+ c->scale = v2(0.7f, 1.3f);+ c->returning = 1;+ }+ }+ }+ float lift = c->speed < 0 ? -220 : c->speed;+ plat_move_v_lift(e, c->speed * DT, lift);+}+static void cloud_render(Ent *e) {+ Cloud *c = ST(e, Cloud);+ Sprite s = c->spr;+ Tex t;+ uint16_t id = spr_tex(&s);+ s.justify = 0;+ s.ox = id != 0xFFFF && tex_get(id, &t) ? t.fw / 2.f : 16, s.oy = 8; /* sprite.Origin = (Width / 2, 8) */+ float k = 1 + 0.1f * c->wig.value;+ s.sx = c->scale.x * k, s.sy = c->scale.y * k * (c->fragile ? c->spr.sy : 1);+ spr_draw(&s, e->x + c->spr_pos.x, e->y + c->spr_pos.y);+}+static const EntClass CLOUD = {.name = "cloud", .size = sizeof(Cloud), .update = cloud_update, .render = cloud_render, .kind = KIND_JUMPTHRU};+static void new_cloud(const EData *d) {+ Ent *e = ent_new(&CLOUD, d->x, d->y);+ if (!e) return;+ Cloud *c = ST(e, Cloud);+ c->fragile = EAB(d, cloud, fragile);+ if (g_session.mode != M_A) ent_box(e, 26, 5, -14, 0);+ else ent_box(e, 32, 5, -16, 0);+ c->start_y = d->y;+ c->timer = rndf() * 4;+ c->waiting = 1;+ c->scale = v2(1, 1);+ wiggler_init(&c->wig, 0.3f, 4);+ int bank = cloud_bank(c->fragile, g_session.mode != M_A);+ if (bank >= 0) spr_init(&c->spr, bank), spr_play(&c->spr, cloud_anim(c, 0), true);+ else c->spr.visible = 0;+}++/* ---------------------------------------------------------------- RidgeGate */+typedef struct { V2 move_to; Tween tw; V2 tw_from; float wait; uint8_t step, has_node; V2 node; } Ridge;+static void ridge_awake(Ent *e) {+ Ridge *r = ST(e, Ridge);+ plat_static_movers_attach(e);+ Ent *p = level_player_ent();+ if (r->has_node && p && collide_ent_at(e, e->x, e->y, p)) {+ e->visible = e->collidable = 0;+ r->move_to = v2(e->x, e->y);+ e->x = r->node.x, e->y = r->node.y;+ r->step = 1; /* EnterSequence */+ }+}+static void ridge_update(Ent *e) {+ Ridge *r = ST(e, Ridge);+ if (r->tw.active) {+ tween_update(&r->tw);+ float t = ease_cube_out(r->tw.percent);+ plat_move_to(e, lerpf(r->tw_from.x, r->move_to.x, t), lerpf(r->tw_from.y, r->move_to.y, t));+ }+ if (r->wait > 0) r->wait -= DT;+ else switch (r->step) {+ case 1:+ e->visible = e->collidable = 1;+ r->wait = 0.25f, r->step = 2;+ break;+ case 2:+ r->wait = 0.25f, r->step = 3;+ break;+ case 3:+ r->tw_from = v2(e->x, e->y);+ tween_start(&r->tw, 1);+ r->step = 0;+ break;+ }+ plat_update(e);+}+static void ridge_render(Ent *e) {+ V2 sh = e_shake(e);+ gfx_tex(tex("objects/ridgeGate"), e->x + sh.x, e->y + sh.y, 0, 0xFFFF, 255);+}+static const EntClass RIDGE = {.name = "ridgeGate", .size = sizeof(Ridge), .update = ridge_update, .render = ridge_render,+ .awake = ridge_awake, .kind = KIND_SOLID};+/* "room:id,room:id": every one collected (strawberries) or held (keys) this session */+static bool ridge_ids_ok(const char *list, bool keys) {+ while (*list) {+ char room[24];+ int n = 0;+ while (*list && *list != ':' && n < 23) room[n++] = *list++;+ room[n] = 0;+ if (*list != ':') return true;+ list++;+ int id = 0;+ while (*list >= '0' && *list <= '9') id = id * 10 + (*list++ - '0');+ if (*list == ',') list++;+ int ri = chapter_find_room(g_session.chapter, room);+ if (ri < 0) return false;+ if (keys) {+ bool have = false;+ for (int i = 0; i < g_session.nkeys && i < 4; i++)+ if (g_session.keys[i] == level_entity_id(ri, id)) have = true;+ if (!have) return false;+ } else {+ int bi = session_berry_index(ri, id);+ if (bi < 0 || !(g_session.berries >> bi & 1)) return false;+ }+ }+ return true;+}+static void new_ridge(const EData *d) {+ if (!ridge_ids_ok(EAS(d, ridgeGate, strawberries), false) || !ridge_ids_ok(EAS(d, ridgeGate, keys), true)) return;+ Ent *e = ent_new(&RIDGE, d->x, d->y);+ if (!e) return;+ ent_box(e, EA(d, ridgeGate, width), EA(d, ridgeGate, height), 0, 0);+ e->safe = 1;+ Ridge *r = ST(e, Ridge);+ r->has_node = d->nnodes > 0;+ r->node = ed_node(d, 0);+}++/* ---------------------------------------------------------------- WhiteBlock */+/* once the player has ducked on it for 3 s, the background's tiles turn solid (a Solid with their Grid) */+typedef struct { int16_t room; } BgSolid;+static bool bgsolid_collide_rect(const Ent *e, float l, float t, float r, float b) {+ (void)e;+ int x0 = (int)floorf(l), y0 = (int)floorf(t), x1 = (int)ceilf(r) - 1, y1 = (int)ceilf(b) - 1;+ if (x1 < x0 || y1 < y0) return false;+ const Room *rm = g_level.room;+ for (int cy = y0 >> 3; cy <= y1 >> 3; cy++)+ for (int cx = x0 >> 3; cx <= x1 >> 3; cx++) {+ int px = cx * 8, py = cy * 8;+ if (px < rm->x || py < rm->y || px >= rm->x + rm->w || py >= rm->y + rm->h) continue;+ if (level_tile_type(1, cx, cy) != '0') return true;+ }+ return false;+}+static const EntClass BGSOLID = {.name = "bgSolidTiles", .size = sizeof(BgSolid), .collide_rect = bgsolid_collide_rect, .kind = KIND_SOLID};+typedef struct { float duck_timer; int16_t bg; uint8_t enabled, activated; } White;+static void white_disable(Ent *e) {+ White *w = ST(e, White);+ w->enabled = 0;+ e->collidable = 0;+}+static void white_awake(Ent *e) {+ if (g_session.heart) white_disable(e);+}+static bool heart_gem_here(void) { /* Tracker.GetEntity<HeartGem>() */+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls && g_ents[i].dead != 1 && g_ents[i].cls->name && !strcmp(g_ents[i].cls->name, "blackGem")) return true;+ return false;+}+static void white_update(Ent *e) {+ White *w = ST(e, White);+ plat_update(e);+ if (!w->enabled) return;+ Player *p = level_player();+ if (!w->activated) {+ if (p && jumpthru_has_player_rider(e) && player_ducking(p)) {+ w->duck_timer += DT;+ if (w->duck_timer >= 3) { /* Activate */+ w->activated = 1;+ e->collidable = 0;+ p->ent->depth = 10001;+ ents_mark_unsorted();+ Ent *bg = ent_new(&BGSOLID, 0, 0);+ if (bg) bg->ctype = COL_LIST, bg->safe = 1, bg->visible = 0;+ w->bg = ent_ref(bg);+ }+ } else+ w->duck_timer = 0;+ if (g_session.heart) white_disable(e);+ } else if (!heart_gem_here() && p) {+ white_disable(e);+ p->ent->depth = 0;+ ents_mark_unsorted();+ ent_remove(ent_at(w->bg, &BGSOLID));+ }+}+static void white_render(Ent *e) {+ White *w = ST(e, White);+ gfx_tex(tex("objects/whiteblock"), e->x, e->y, 0, 0xFFFF, w->enabled ? 255 : 64);+}+static const EntClass WHITE = {.name = "whiteblock", .size = sizeof(White), .update = white_update, .render = white_render,+ .awake = white_awake, .kind = KIND_JUMPTHRU};+static void new_white(const EData *d) {+ Ent *e = ent_new(&WHITE, d->x, d->y);+ if (!e) return;+ ent_box(e, 48, 5, 0, 0);+ e->safe = 1;+ e->depth = -9000;+ White *w = ST(e, White);+ w->enabled = 1;+ w->bg = -1;+}++/* ---------------------------------------------------------------- Gondola */+typedef struct {+ Sprite front;+ V2 start, dest;+ V2 lever_pos, lever_speed; /* the Lever's offset and its fall once broken off */+ float rot, rot_speed, lever_t, lever_rot;+ uint8_t active, lever_frame, lever_broken, front_pull;+} Gondola;+static uint16_t gd_top, gd_back, gd_left, gd_right, gd_lever[2];+static void gondola_update(Ent *e) {+ Gondola *g = ST(e, Gondola);+ if (g->active) { /* inCliffside: it swings back like a lamp */+ float num = signf(g->rot) == signf(g->rot_speed) ? 8 : 6;+ if (fabsf(g->rot) < 0.5f) num *= 0.5f;+ if (fabsf(g->rot) < 0.25f) num *= 0.5f;+ g->rot_speed += -signf(g->rot) * num * DT;+ g->rot += g->rot_speed * DT;+ g->rot = clampf(g->rot, -0.4f, 0.4f);+ if (fabsf(g->rot) < 0.02f && fabsf(g->rot_speed) < 0.2f) g->rot = g->rot_speed = 0;+ }+ spr_update(&g->front);+ if (g->lever_t > 0) g->lever_t -= DT; /* Lever "pulled": frame 1, twice 0.5 s, then idle */+ g->lever_frame = g->lever_t > 0;+ if (g->lever_broken) { /* BreakLeverRoutine */+ g->lever_pos = v2add(g->lever_pos, v2mul(g->lever_speed, DT));+ g->lever_rot += 2 * DT;+ g->lever_speed.y += 400 * DT;+ } else+ g->lever_rot = g->rot;+ plat_update(e);+}+static void gondola_render(Ent *e) {+ Gondola *g = ST(e, Gondola);+ float top_rot = atan2f(g->dest.y - g->start.y, g->dest.x - g->start.x);+ Sprite s = g->front;+ s.justify = 0, s.ox = 40, s.oy = 12, s.rot = g->rot;+ spr_draw(&s, e->x, e->y - 52);+ gfx_tex_ex(gd_top, e->x, e->y - 52, 40, 12, 1, 1, top_rot, 0xFFFF, 255, 0);+ if (g->active) gfx_tex_ex(gd_lever[g->lever_frame], e->x + g->lever_pos.x, e->y - 52 + g->lever_pos.y, 40, 12, 1, 1, g->lever_rot, 0xFFFF, 255, 0);+}+/* the gondola's back (depth 9000), the two cliffsides (8998) and the rope (8999) */+typedef struct { int16_t g; uint8_t part; } GPart;+static const EntClass GONDOLA;+static void gpart_render(Ent *e) {+ GPart *p = ST(e, GPart);+ Ent *ge = ent_at(p->g, &GONDOLA);+ if (!ge) return;+ Gondola *g = ST(ge, Gondola);+ V2 left = v2add(g->start, v2(-124, 0)), right = v2add(g->dest, v2(144, -104));+ switch (p->part) {+ case 0: gfx_tex_ex(gd_back, ge->x, ge->y - 52, 40, 12, 1, 1, g->rot, 0xFFFF, 255, 0); break;+ case 1: gfx_tex(gd_left, left.x, left.y - 32, 0, 0xFFFF, 255); break; /* JustifyOrigin(0, 1) */+ case 2: gfx_tex_ex(gd_right, right.x, right.y, 0, 24, -1, 1, 0, 0xFFFF, 255, 0); break; /* (0, 0.5), Scale.X -1 */+ default: {+ V2 a = v2(floorf(left.x + 40), floorf(left.y - 12)), b = v2(floorf(right.x - 40), floorf(right.y - 4));+ V2 n = v2norm(v2sub(b, a));+ V2 c4 = v2sub(v2add(v2(ge->x, ge->y), v2(0, -55)), v2mul(n, 6)), c5 = v2add(v2add(v2(ge->x, ge->y), v2(0, -55)), v2mul(n, 6));+ for (int i = 0; i < 2; i++) {+ gfx_line(a.x, a.y + i, c4.x, c4.y + i, 0, 255);+ gfx_line(c5.x, c5.y + i, b.x, b.y + i, 0, 255);+ }+ }+ }+}+static const EntClass GPART = {.name = "gondolaPart", .size = sizeof(GPart), .render = gpart_render};+static const EntClass PLAIN_JUMPTHRU = {.name = "jumpThruPlain", .size = 0, .update = plat_update, .kind = KIND_JUMPTHRU};+static const EntClass GONDOLA = {.name = "gondola", .size = sizeof(Gondola), .update = gondola_update, .render = gondola_render,+ .kind = KIND_SOLID};+static void new_gondola(const EData *d) {+ Ent *e = ent_new(&GONDOLA, d->x, d->y);+ if (!e) return;+ ent_box(e, 64, 8, -32, 0);+ e->safe = 1;+ e->depth = -10500;+ Gondola *g = ST(e, Gondola);+ g->start = v2(d->x, d->y);+ g->dest = ed_node(d, 0);+ g->active = EAB(d, gondola, active);+ spr_init(&g->front, SB_gondola);+ spr_play(&g->front, A_gondola_idle, true);+ gd_top = tex("objects/gondola/top");+ gd_back = tex("objects/gondola/back");+ gd_left = tex("objects/gondola/cliffsideLeft");+ gd_right = tex("objects/gondola/cliffsideRight");+ gd_lever[0] = tex("objects/gondola/lever00");+ gd_lever[1] = tex("objects/gondola/lever01");+ static const int depths[4] = {9000, 8998, 8998, 8999};+ for (int i = 0; i < 4; i++) {+ Ent *p = ent_new(&GPART, 0, 0);+ if (!p) continue;+ p->depth = depths[i];+ p->collidable = 0;+ ST(p, GPart)->g = ent_ref(e);+ ST(p, GPart)->part = (uint8_t)i;+ }+ if (!g->active) { /* already across: a (plain, unseen) JumpThru in it */+ e->x = g->dest.x, e->y = g->dest.y;+ Ent *j = ent_new(&PLAIN_JUMPTHRU, e->x - 32, e->y - 36);+ if (j) ent_box(j, 64, 5, 0, 0), j->safe = 1, j->visible = 0;+ }+}++/* ---------------------------------------------------------------- CliffsideWindFlag */+/* every flag's columns in one strip layer: each a 1-px slice of its texture, moved by the wind */+typedef struct { float sine, random; int8_t sign; uint8_t index; } WFlag;+static const EntClass WFLAG;+static uint16_t wflag_tex[11];+static float wflag_wind(void) { return clamped_map(fabsf(g_level.wind.x), 0, 800, 0, 1); }+static void wflag_offset(const WFlag *f, int i, int n, float *ox, float *oy) { /* SetFlagSegmentPosition (snapped) */+ float wind = wflag_wind();+ float value = (float)(i * f->sign) * (0.2f + wind * 0.8f * (0.8f + f->random * 0.2f)) * (0.9f + sinf(-f->sine) * 0.1f);+ float a = sinf(-(f->sine * 0.5f - i * 0.1f)) * ((float)i / n) * i * 0.2f;+ *ox = ceilf(wind) >= 1 ? value : a;+ *oy = (float)i / n * fmaxf(0.1f, 1 - wind) * 16;+}+static void wflag_layer(uint16_t *strip, int sy0, int sy1, void *ctx) {+ (void)ctx;+ for (int q = 0; q < g_nents; q++) {+ Ent *e = &g_ents[q];+ if (e->cls != &WFLAG || e->dead == 1) continue;+ WFlag *f = ST(e, WFlag);+ Tex t;+ if (!tex_get(wflag_tex[f->index], &t) || t.w > (int)sizeof rowbuf) continue;+ if (vy(e->y) > sy1 + 20 || vy(e->y) + t.fh + 20 < sy0) continue;+ int n;+ const uint16_t *col = pal_colors(t.pal, &n);+ const uint8_t *al = pal_alpha(t.pal);+ int segs = t.fw;+ for (int r = 0; r < t.h; r++) {+ tex_row_idx(&t, r, rowbuf);+ for (int k = 0; k < t.w; k++) {+ if (!rowbuf[k]) continue;+ int i = t.ox + k;+ float ox, oy;+ wflag_offset(f, i, segs, &ox, &oy);+ float bob = (float)i / segs * sinf(-(-i * 0.1f + f->sine)) * 2;+ int X = vx(e->x + ox + i), Y = vy(e->y + oy + bob) + t.oy + r;+ if (Y < sy0 || Y >= sy1 || (unsigned)X >= VIEW_W) continue;+ sp_texel(strip + (Y - sy0) * VIEW_W + X, col, al, rowbuf[k], 0xFFFF, 256, false);+ }+ }+ }+}+static uint32_t wflag_mark;+static void wflag_render(Ent *e) {+ (void)e;+ if (!layer_once(&wflag_mark)) return;+ /* its textures loaded now (and kept): nothing loads while the strips are drawn */+ for (int q = 0; q < g_nents; q++)+ if (g_ents[q].cls == &WFLAG && g_ents[q].dead != 1) {+ Tex t;+ tex_get(wflag_tex[ST(&g_ents[q], WFlag)->index], &t);+ }+ gfx_custom(wflag_layer, NULL, 0, VIEW_H);+}+static void wflag_update(Ent *e) {+ WFlag *f = ST(e, WFlag);+ float wind = wflag_wind();+ if (wind != 0) f->sign = (int8_t)signf(g_level.wind.x);+ f->sine += DT * (4 + wind * 4) * (0.8f + f->random * 0.2f);+}+static const EntClass WFLAG = {.name = "cliffside_flag", .size = sizeof(WFlag), .update = wflag_update, .render = wflag_render};+static void new_wflag(const EData *d) {+ Ent *e = ent_new(&WFLAG, d->x, d->y);+ if (!e) return;+ e->depth = 8999;+ e->tags = TAG_TRANSITION_UPDATE;+ e->collidable = 0;+ WFlag *f = ST(e, WFlag);+ int idx = (int)EA(d, cliffside_flag, index);+ f->index = (uint8_t)(idx < 0 ? 0 : idx > 10 ? 10 : idx);+ f->sine = rndf() * 2 * PI_F;+ f->random = rndf();+ f->sign = 1;+ if (wflag_wind() != 0) f->sign = (int8_t)signf(g_level.wind.x);+ char p[40];+ for (int i = 0; i < 11; i++) wflag_tex[i] = tex(path2(p, "scenery/cliffside/flag", NULL, i));+}++/* ---------------------------------------------------------------- CliffFlags (Flagline) */+typedef struct { V2 from, to; float wave; uint32_t seed; } Flagline;+static const EntClass CLIFFFLAGS;+static int cloth_val(uint32_t seed, int j, int k, int lo, int hi) {+ return hi <= lo ? lo : lo + (int)(hash32(seed + (uint32_t)(j * 4 + k)) % (uint32_t)(hi - lo));+}+static void flagline_draw(uint16_t *strip, int sy0, int sy1, const Flagline *f, const uint32_t *colors, int ncol, uint32_t line,+ uint32_t pin, int minh, int maxh, int minl, int maxl, int mins, int maxs, float droop) {+ V2 a = f->from.x < f->to.x ? f->from : f->to, b = f->from.x < f->to.x ? f->to : f->from;+ float num = v2len(v2sub(a, b)), num2 = num / 8;+ V2 ctrl = v2add(v2mul(v2add(a, b), 0.5f), v2(0, num2 + sinf(f->wave) * num2 * 0.3f));+ V2 p4 = a;+ float t = 0;+ int k = 0;+ bool flag = false;+ uint16_t lc = rgb(line), pc = rgb(pin);+ for (int guard = 0; t < 1 && guard < 400; guard++) {+ int j = k % 10;+ int length = cloth_val(f->seed, j, 2, minl, maxl), step = cloth_val(f->seed, j, 3, mins, maxs);+ t += (float)(flag ? length : step) / num;+ V2 p5 = curve_point(a, b, ctrl, t);+ sp_line(strip, sy0, sy1, vx(p4.x), vy(p4.y), vx(p5.x), vy(p5.y), lc, 256);+ if (t < 1 && flag) {+ int col = cloth_val(f->seed, j, 0, 0, ncol), height = cloth_val(f->seed, j, 1, minh, maxh);+ float n5 = length * droop;+ V2 c2 = v2add(v2mul(v2add(p4, p5), 0.5f), v2(0, n5 + sinf(f->wave * 2 + t) * n5 * 0.4f));+ V2 p6 = p4;+ uint16_t cc = rgb(colors[col]), hc = rgb(lerp_color(colors[col], 0xFFFFFF, 0.1f));+ for (float n6 = 1; n6 <= (float)length; n6 += 1) {+ V2 pt = curve_point(p4, p5, c2, n6 / length);+ if (pt.x != p6.x) {+ sp_rect(strip, sy0, sy1, vx(p6.x), vy(p6.y), (int)floorf(pt.x - p6.x + 1 + 0.5f), height, cc, 256);+ p6 = pt;+ }+ }+ sp_rect(strip, sy0, sy1, vx(p4.x), vy(p4.y), 1, height, hc, 256);+ sp_rect(strip, sy0, sy1, vx(p5.x), vy(p5.y), 1, height, hc, 256);+ sp_rect(strip, sy0, sy1, vx(p4.x), vy(p4.y - 1), 1, 3, pc, 256);+ sp_rect(strip, sy0, sy1, vx(p5.x), vy(p5.y - 1), 1, 3, pc, 256);+ k++;+ }+ p4 = p5;+ flag = !flag;+ }+}+static void cliffflags_layer(uint16_t *strip, int sy0, int sy1, void *ctx) {+ (void)ctx;+ static const uint32_t COLORS[4] = {0xd85f2f, 0xd82f63, 0x2fd8a2, 0xd8d62f};+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &CLIFFFLAGS && g_ents[i].dead != 1)+ flagline_draw(strip, sy0, sy1, ST(&g_ents[i], Flagline), COLORS, 4, 0x606082, 0x808080, 10, 10, 10, 10, 2, 8, 0.2f);+}+static uint32_t cliffflags_mark;+static void cliffflags_render(Ent *e) {+ (void)e;+ if (layer_once(&cliffflags_mark)) gfx_custom(cliffflags_layer, NULL, 0, VIEW_H);+}+static void cliffflags_update(Ent *e) { ST(e, Flagline)->wave += DT; }+static const EntClass CLIFFFLAGS = {.name = "cliffflag", .size = sizeof(Flagline), .update = cliffflags_update, .render = cliffflags_render};+static void new_cliffflags(const EData *d) {+ Ent *e = ent_new(&CLIFFFLAGS, d->x, d->y);+ if (!e) return;+ e->depth = 8999;+ e->collidable = 0;+ Flagline *f = ST(e, Flagline);+ f->from = v2(d->x, d->y);+ f->to = ed_node(d, 0);+ f->wave = rndf() * 2 * PI_F;+ f->seed = (uint32_t)rnd_next(&g_rnd);+}++/* ---------------------------------------------------------------- WindController */+enum { WP_NONE, WP_LEFT, WP_RIGHT, WP_LEFTSTRONG, WP_RIGHTSTRONG, WP_LEFTONOFF, WP_RIGHTONOFF, WP_LEFTONOFFFAST, WP_RIGHTONOFFFAST,+ WP_ALTERNATING, WP_LEFTGEMSONLY, WP_RIGHTCRAZY, WP_DOWN, WP_UP, WP_SPACE };+typedef struct { V2 target; float wait; uint8_t pattern, start, ever_set, step; } Wind;+static const EntClass WIND;+static void wind_set_pattern(Wind *w, int pattern) {+ if (w->pattern == pattern && w->ever_set) return;+ w->ever_set = 1;+ w->pattern = (uint8_t)pattern;+ w->step = 0, w->wait = 0; /* the old sequence goes */+ switch (pattern) {+ case WP_NONE: w->target = v2(0, 0); break;+ case WP_LEFT: w->target.x = -400; break;+ case WP_RIGHT: w->target.x = 400; break;+ case WP_LEFTSTRONG: w->target.x = -800; break;+ case WP_RIGHTSTRONG: w->target.x = 800; break;+ case WP_RIGHTCRAZY: w->target.x = 1200; break;+ case WP_DOWN: w->target.y = 300; break;+ case WP_UP: w->target.y = -400; break;+ case WP_SPACE: w->target.y = -600; break;+ default: w->step = 1; break; /* the on/off sequences */+ }+}+/* the sequences (each a coroutine): their steps of (target x, time) */+static void wind_sequence(Wind *w) {+ if (!w->step) return;+ if (w->wait > 0) {+ w->wait -= DT;+ return;+ }+ static const float ALT[4][2] = {{-400, 3}, {0, 2}, {400, 3}, {0, 2}};+ int k = w->step - 1;+ float x, t;+ switch (w->pattern) {+ case WP_ALTERNATING: x = ALT[k % 4][0], t = ALT[k % 4][1]; break;+ case WP_RIGHTONOFF: x = k % 2 ? 0 : 800, t = 3; break;+ case WP_LEFTONOFF: x = k % 2 ? 0 : -800, t = 3; break;+ case WP_RIGHTONOFFFAST: x = k % 2 ? 0 : 800, t = 2; break;+ case WP_LEFTONOFFFAST: x = k % 2 ? 0 : -800, t = 2; break;+ default: return;+ }+ w->target.x = x;+ w->wait = t;+ w->step = (uint8_t)(1 + (k + 1) % 4);+}+/* Player.WindMove (WindMover): the wind pushes the player */+static void wind_move_player(Player *p, V2 move) {+ Ent *pe = p->ent;+ if (p->just_respawned || p->no_wind_timer > 0 || !player_in_control(p) || p->state == ST_BOOST || p->state == ST_DASH ||+ p->state == ST_SUMMITLAUNCH)+ return;+ const Room *rm = g_level.room;+ if (move.x != 0 && p->state != ST_CLIMB) {+ p->wind_timeout = 0.2f;+ p->wind_dir.x = signf(move.x);+ if (!collide_solid(pe, pe->x - signf(move.x) * 3, pe->y)) {+ if (player_ducking(p) && p->on_ground) move.x *= 0;+ if (move.x < 0) move.x = fmaxf(move.x, rm->x - (pe->x + pe->remx + pe->cx));+ else move.x = fminf(move.x, rm->x + rm->w - (pe->x + pe->remx + pe->cx + pe->cw));+ actor_move_h(pe, move.x, NULL, NULL);+ }+ }+ if (move.y == 0) return;+ p->wind_timeout = 0.2f;+ p->wind_dir.y = signf(move.y);+ if (!(e_bottom(pe) > rm->y) || (!(p->speed.y < 0) && actor_on_ground(pe, 1))) return;+ if (p->state == ST_CLIMB) {+ if (!(move.y > 0) || !(p->climb_no_move_timer <= 0)) return;+ move.y *= 0.4f;+ }+ /* (windMovedUp: not in player.c) */+ actor_move_v(pe, move.y, NULL, NULL);+}+static const EntClass WINDTRIG;+static void wind_transition_pattern(Wind *w);+static void wind_update(Ent *e) {+ Wind *w = ST(e, Wind);+ if (w->pattern == 0xFF) wind_transition_pattern(w);+ wind_sequence(w); /* base.Update(): the sequence's coroutine */+ if (w->pattern == WP_LEFTGEMSONLY) { /* a collected StrawberrySeed (berry.c) */+ bool any = false;+ for (int i = 0; i < g_nents && !any; i++)+ if (g_ents[i].cls && g_ents[i].dead != 1 && g_ents[i].cls->name && !strcmp(g_ents[i].cls->name, "strawberrySeed") && leader_has(&g_ents[i]))+ any = true;+ w->target.x = any ? -400 : 0;+ }+ V2 d = v2sub(w->target, g_level.wind);+ float l = v2len(d), m = 1000 * DT;+ g_level.wind = l <= m ? w->target : v2add(g_level.wind, v2mul(d, m / l));+ if ((g_level.wind.x == 0 && g_level.wind.y == 0) || g_level.transitioning) return;+ Player *p = level_player();+ if (p && !p->dead) wind_move_player(p, v2mul(g_level.wind, 0.1f * DT));+}+static const EntClass WIND = {.name = "windController", .size = sizeof(Wind), .update = wind_update};+static Ent *wind_controller(void) {+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &WIND && g_ents[i].dead != 1) return &g_ents[i];+ return NULL;+}+/* Level.LoadLevel: the old controller goes, a new one with the room's pattern */+static int16_t wind_room = -1;+static int8_t wind_slot = -1;+static void wind_room_load(const EData *d) {+ if (d->room == wind_room && g_level.room_slot == wind_slot && wind_controller()) return;+ wind_room = (int16_t)d->room, wind_slot = (int8_t)g_level.room_slot;+ ent_remove(wind_controller());+ Ent *e = ent_new(&WIND, 0, 0);+ if (!e) return;+ e->tags = TAG_TRANSITION_UPDATE;+ e->collidable = 0, e->visible = 0;+ Wind *w = ST(e, Wind);+ const Room *rm = &g_level.rooms[g_level.room_slot];+ w->start = rm->info ? rm->info[25] : 0; /* the room's windPattern */+ if (level_player_ent()) w->pattern = 0xFF; /* a transition: its wind triggers or SetStartPattern (in its awake) */+ else {+ wind_set_pattern(w, w->start); /* SetStartPattern */+ g_level.wind = w->target; /* (a reload snaps the wind: SnapWind) */+ }+}++/* WindTrigger, WindAttackTrigger */+typedef struct { uint8_t pattern; } WindTrig;+static void windtrig_enter(Ent *e, Player *p) {+ (void)p;+ Ent *c = wind_controller();+ if (!c) {+ c = ent_new(&WIND, 0, 0);+ if (!c) return;+ c->tags = TAG_TRANSITION_UPDATE, c->collidable = 0, c->visible = 0;+ ST(c, Wind)->start = ST(e, WindTrig)->pattern;+ }+ wind_set_pattern(ST(c, Wind), ST(e, WindTrig)->pattern);+}+static const EntClass WINDTRIG = {.name = "windTrigger", .size = sizeof(WindTrig), .on_enter = windtrig_enter, .kind = KIND_TRIGGER};+/* Level.TransitionRoutine: the wind trigger under the player's destination sets the pattern, else the room's */+static void wind_transition_pattern(Wind *w) {+ w->pattern = 0, w->ever_set = 0;+ Ent *p = level_player_ent();+ for (int i = 0; i < g_nents && p; i++) {+ Ent *t = &g_ents[i];+ if (t->cls == &WINDTRIG && t->dead != 1 && t->room == g_level.room_slot &&+ collide_ent_at(p, g_level.tr_player_to.x, g_level.tr_player_to.y, t)) {+ wind_set_pattern(w, ST(t, WindTrig)->pattern);+ return;+ }+ }+ wind_set_pattern(w, w->start);+}++/* Snowball */+typedef struct { Sprite spr; SineWave sine; float reset, at_y; uint8_t broken; } Snowball;+static const EntClass SNOWBALL;+static void snowball_reset(Ent *e) { /* ResetPosition */+ Snowball *s = ST(e, Snowball);+ Ent *p = level_player_ent();+ if (p && e_right(p) < g_level.room->x + g_level.room->w - 64) {+ e->collidable = e->visible = 1;+ s->reset = 0;+ e->x = g_level.cam.x + 320 + 10;+ e->y = s->at_y = e_cym(p);+ sine_set(&s->sine, 0);+#ifdef SB_snowball+ spr_play(&s->spr, A_snowball_spin, false);+#endif+ s->broken = 0;+ return;+ }+ s->reset = 0.05f;+}+static void snowball_destroy(Ent *e) {+ e->collidable = 0;+#ifdef SB_snowball+ spr_play(&ST(e, Snowball)->spr, A_snowball_break, false);+#endif+}+static void snowball_on_player(Ent *e, Player *p) {+ Ent *pe = p->ent;+ /* PlayerCollider(OnPlayer) on Hitbox(12, 9, -5, -2) first, then the bounce one, Hitbox(16, 6, -6, -8) */+ if (collide_rect(pe, e->x - 5, e->y - 2, e->x + 7, e->y + 7)) {+ player_die(p, v2(-1, 0), false);+ snowball_destroy(e);+ return;+ }+ if (collide_rect(pe, e->x - 6, e->y - 8, e->x + 10, e->y - 2)) {+ level_freeze(0.1f);+ player_bounce(p, e->y - 2 - 2);+ snowball_destroy(e);+ }+}+static void snowball_update(Ent *e) {+ Snowball *s = ST(e, Snowball);+ sine_update(&s->sine);+ spr_update(&s->spr);+ e->x -= 200 * DT;+ e->y = s->at_y + 4 * s->sine.value;+ if (e->x < g_level.cam.x - 60) {+ s->reset += DT;+ if (s->reset >= 0.8f) snowball_reset(e);+ }+}+static void snowball_render(Ent *e) {+ Snowball *s = ST(e, Snowball);+ Sprite o = s->spr;+ o.tint = 0;+ for (int i = -1; i < 2; i++)+ for (int j = -1; j < 2; j++)+ if (i || j) spr_draw(&o, e->x + i, e->y + j);+ spr_draw(&s->spr, e->x, e->y);+}+static const EntClass SNOWBALL = {.name = "snowball", .size = sizeof(Snowball), .update = snowball_update, .render = snowball_render,+ .on_player = snowball_on_player, .kind = KIND_PCOLLIDE};+static void windattack_enter(Ent *e, Player *p) {+ (void)p;+ bool have = false;+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &SNOWBALL && g_ents[i].dead != 1) have = true;+ if (!have) {+ Ent *s = ent_new(&SNOWBALL, 0, 0);+ if (s) {+ s->depth = -12500;+ ent_box(s, 16, 15, -6, -8); /* both of its colliders */+ Snowball *b = ST(s, Snowball);+#ifdef SB_snowball /* (the sprite is in data.bin once pack.py gathers triggers' assets) */+ spr_init(&b->spr, SB_snowball);+ spr_play(&b->spr, A_snowball_spin, true);+#else+ b->spr.visible = 0;+#endif+ b->sine.freq = 0.5f;+ snowball_reset(s);+ }+ }+ ent_remove(e);+}+static const EntClass WINDATTACK = {.name = "windAttackTrigger", .size = 0, .on_enter = windattack_enter, .kind = KIND_TRIGGER};++/* ---------------------------------------------------------------- the factories */+/* ---------------------------------------------------------------- the story: helpers */+#define EV_BEGIN \+ if (c->wait > 0) { \+ c->wait -= DT; \+ return false; \+ } \+ switch (c->co) { \+ case 0:+#define EV_YIELD_(n) \+ do { \+ c->co = (n); \+ return false; \+ case (n):; \+ } while (0)+#define EV_YIELD EV_YIELD_(__COUNTER__ + 1)+#define EV_WAIT(t) \+ do { \+ c->wait = (t); \+ EV_YIELD; \+ } while (0)+#define EV_NEST(call) \+ do { \+ EV_YIELD; \+ while (call) EV_YIELD; \+ EV_YIELD; \+ } while (0)+#define EV_END \+ default:; \+ } \+ return true+static Co *ev_start(Co *c, int8_t *at, int index) {+ if (*at != index) *at = (int8_t)index, memset(c, 0, sizeof *c);+ return c;+}+static void draw_npc(const Sprite *spr, float x, float y) { /* Scale.X turns it */+ Sprite s = *spr;+ s.flipx = s.sx < 0;+ s.sx = fabsf(s.sx);+ spr_draw(&s, x, y);+}+static void player_free(void) { /* StateMachine.Locked = false, State = 0 */+ Player *p = level_player();+ if (p) p->state_locked = false, player_set_state(p, ST_NORMAL);+}++/* ---------------------------------------------------------------- NPC04_Granny and CS04_Granny */+typedef struct {+ Talk talk;+ Sprite spr;+ int16_t haha;+ uint8_t has_talk, cutscene;+} Granny4;+typedef struct {+ Cutscene cs;+ Ent *granny, *tb;+ Walk walk;+ NpcWalk nw;+ Step step;+ Co ev;+ int8_t evi;+ uint8_t talk;+} Gran4Cs;+static bool gran4_event(void *ctx, int index) {+ /* Laughs, StopLaughing, WaitABeat, ZoomIn, MaddyTurnsAround, MaddyApproaches, MaddyWalksPastGranny */+ Gran4Cs *s = ST((Ent *)ctx, Gran4Cs);+ Ent *ge = s->granny;+ Granny4 *g = ST(ge, Granny4);+ Player *p = &g_player;+ Co *c = ev_start(&s->ev, &s->evi, index);+ EV_BEGIN;+ switch (index) {+ case 0: spr_play(&g->spr, A_granny_laugh, false), c->wait = 1; break;+ case 1: spr_play(&g->spr, A_granny_idle, false), c->wait = 0.25f; break;+ case 2: c->wait = 1.2f; break;+ case 4: c->wait = 0.2f; break;+ }+ EV_YIELD;+ if (index == 3) {+ step_reset(&s->step);+ EV_NEST(zoom_to(&s->step, v2(123, 116), 2, 0.5f));+ } else if (index == 4) {+ p->facing = -1;+ EV_WAIT(0.1f);+ } else if (index >= 5) {+ s->walk = index == 5 ? walk_to(ge->x - 20) : walk_exact((int)ge->x + 30);+ EV_NEST(player_walk(p, &s->walk));+ }+ EV_END;+}+static void gran4_end(Ent *e, bool skipped) {+ Gran4Cs *s = ST(e, Gran4Cs);+ Ent *ge = s->granny;+ Granny4 *g = ST(ge, Granny4);+ Player *p = level_player();+ if (s->talk) { /* NPC04_Granny.TalkEnd */+ if (!level_get_flag("granny_2")) level_set_flag("granny_2", true);+ else if (!level_get_flag("granny_3")) {+ level_set_flag("granny_3", true);+ if (g->has_talk) g->has_talk = 0, ch1_talk_remove(ge);+ }+ player_free();+ if (p) p->force_camera_update = false;+ return;+ }+ if (p) {+ p->ent->x = ge->x + 30;+ p->state_locked = false;+ player_set_state(p, ST_NORMAL);+ p->force_camera_update = false;+ if (skipped) g_level.cam = player_camera_target(p);+ }+ spr_play(&g->spr, A_granny_laugh, false);+ level_set_flag("granny_1", true);+}+static void gran4_update(Ent *e) {+ Gran4Cs *s = ST(e, Gran4Cs);+ Ent *ge = s->granny;+ Granny4 *g = ST(ge, Granny4);+ Player *p = &g_player;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ s->evi = -1;+ if (s->talk) { /* TalkRoutine */+ spr_play(&g->spr, A_granny_idle, false);+ p->force_camera_update = true;+ CO_NEST(c, npc_approach(&s->nw, ge, &g->spr, 20, -1));+ step_reset(&s->step);+ CO_NEST(c, zoom_to(&s->step, v2((p->ent->x + ge->x) / 2 - g_level.cam.x, 116), 2, 0.5f));+ CO_SAY(c, s->tb, level_get_flag("granny_2") ? "CH4_GRANNY_3" : "CH4_GRANNY_2", NULL, NULL);+ } else {+ player_set_state(p, ST_DUMMY);+ p->state_locked = true;+ p->force_camera_update = true;+ s->walk = walk_to(ge->x - 30);+ CO_NEST(c, player_walk(p, &s->walk));+ p->facing = 1;+ CO_SAY(c, s->tb, "CH4_GRANNY_1", gran4_event, e);+ }+ step_reset(&s->step);+ CO_NEST(c, zoom_back(&s->step, 0.5f));+ cutscene_end(e);+ return;+ CO_END(c);+}+static const EntClass GRAN4CS = {.size = sizeof(Gran4Cs), .name = "CS04_Granny", .update = gran4_update};+static void granny4_update(Ent *e) {+ Granny4 *g = ST(e, Granny4);+ Player *p = level_player();+ if (p && !level_get_flag("granny_1") && !g->cutscene && p->ent->x > e->x - 40) {+ g->cutscene = 1;+ Ent *c = ent_new(&GRAN4CS, 0, 0);+ if (c) c->collidable = 0, c->visible = 0, ST(c, Gran4Cs)->granny = e, cutscene_start(c, gran4_end, true, false);+ g->talk.enabled = true;+ }+ if (g->haha >= 0 && g_ents[g->haha].cls) hahaha_enable(&g_ents[g->haha], g->spr.anim == A_granny_laugh);+ spr_update(&g->spr);+ if (g->has_talk && talk_update(&g->talk, e) && p) { /* OnTalk */+ Ent *c = ent_new(&GRAN4CS, 0, 0);+ if (c) c->collidable = 0, c->visible = 0, ST(c, Gran4Cs)->granny = e, ST(c, Gran4Cs)->talk = 1, cutscene_start(c, gran4_end, true, false);+ }+}+static void granny4_render(Ent *e) { draw_npc(&ST(e, Granny4)->spr, e->x, e->y); }+static const EntClass GRANNY4 = {.size = sizeof(Granny4), .name = "NPC04_Granny", .update = granny4_update, .render = granny4_render};+static void new_granny4(const EData *d) {+ Ent *e = ent_new(&GRANNY4, d->x, d->y);+ if (!e) return;+ e->depth = 1000;+ ent_box(e, 8, 8, -4, -8);+ Granny4 *g = ST(e, Granny4);+ spr_init(&g->spr, SB_granny);+ g->spr.sx = -1;+ spr_play(&g->spr, A_granny_idle, false);+ Ent *h = hahaha_new(v2(d->x + 8, d->y - 4), NULL);+ g->haha = h ? (int16_t)(h - g_ents) : -1;+ if (h) hahaha_enable(h, false);+ if (level_get_flag("granny_1") && !level_get_flag("granny_2")) spr_play(&g->spr, A_granny_laugh, false);+ if (!level_get_flag("granny_3")) {+ g->has_talk = 1;+ ch1_talk_add(e, &g->talk, -20, -16, 40, 16, v2(0, -24));+ if (!level_get_flag("granny_1")) g->talk.enabled = false;+ }+}++/* NPC04_Theo's state, and NPC.MoveTo with its walk (Maxspeed 48) */+typedef struct { Sprite spr; uint8_t started; } Theo4;+static bool theo4_move(Ent *e, Move *m) { return ch1_move_to(e, &ST(e, Theo4)->spr, m, 48, A_theo_walk, A_theo_idle); }++/* ---------------------------------------------------------------- CS04_Gondola */+/* the clouds it adds behind the level (Parallax bgs/04/bgCloudLoop and bgCloud), and the background's fade */+typedef struct { V2 loop_pos, bottom_pos, offset; float fade; uint8_t loop_y, on; } Clouds;+static void clouds_render(Ent *e) {+ Clouds *k = ST(e, Clouds);+ gfx_screen(true);+ if (k->on) {+ for (int w = 0; w < 2; w++) { /* Parallax.Render, Scroll (1, 1), LoopX */+ uint16_t id = w ? T_bgs_04_bgCloud : T_bgs_04_bgCloudLoop;+ Tex t;+ if (!tex_get(id, &t)) continue;+ V2 cam = w ? g_level.cam : v2add(g_level.cam, k->offset);+ V2 at = v2sub(w ? k->bottom_pos : k->loop_pos, v2(floorf(cam.x), floorf(cam.y)));+ at = v2(floorf(at.x), floorf(at.y));+ while (at.x < 0) at.x += t.fw;+ while (at.x > 0) at.x -= t.fw;+ if (!w && k->loop_y) {+ while (at.y < 0) at.y += t.fh;+ while (at.y > 0) at.y -= t.fh;+ }+ for (float x = at.x; x < 320; x += t.fw)+ for (float y = at.y; y < 180; y += t.fh) {+ gfx_tex(id, x, y, 0, 0xFFFF, 255);+ if (w || !k->loop_y) break;+ }+ }+ }+ if (k->fade > 0) gfx_rect(0, 0, 320, 180, 0, (uint8_t)(clampf(k->fade, 0, 1) * 255)); /* Level.Background.Fade */+ gfx_screen(false);+}+static const EntClass CLOUDS = {.size = sizeof(Clouds), .name = "gondolaClouds", .render = clouds_render};++enum { GS_STOPPED, GS_TO_CENTER, GS_CENTER, GS_SHAKING, GS_TO_END };+typedef struct {+ Cutscene cs;+ Ent *theo, *gondola, *tb, *evil, *breath, *clouds;+ Walk walk, pwalk;+ Step step, zoom2;+ Move move;+ Co ev;+ Tween tw;+ V2 from, to;+ float percent, speed, theo_x, player_x, shake, p, sp, loop_at, start_x, dur;+ int8_t evi;+ uint8_t state, snap, pwalking, zooming, panning, walk_anim;+} Gond;+static Gondola *gond(Gond *s) { return ST(s->gondola, Gondola); }+static V2 gond_floor(Gond *s, float x, float y) { /* Gondola.GetRotatedFloorPositionAt */+ Ent *ge = s->gondola;+ float r = gond(s)->rot;+ return v2(ge->x - sinf(r) * y + cosf(r) * x, ge->y - 52 + cosf(r) * y + sinf(r) * x);+}+static bool gond_pan(Gond *s, V2 to, float duration, float (*ease)(float)) { /* PanCamera */+ if (s->p < 0) s->from = g_level.cam, s->p = 0, s->dur = duration;+ if (s->p >= 1) return false;+ s->p += DT / s->dur;+ g_level.cam = v2lerp(s->from, to, (ease ? ease : ease_cube_inout)(fminf(s->p, 1)));+ return true;+}+static bool gond_move(Gond *s, bool theo, float x, bool face) { /* MovePlayerOnGondola / MoveTheoOnGondola */+ float *at = theo ? &s->theo_x : &s->player_x;+ Sprite *spr = theo ? &ST(s->theo, Theo4)->spr : &g_player.spr;+ if (!s->walk_anim) {+ s->walk_anim = 1;+ spr_play(spr, theo ? A_theo_walk : A_player_walk, false);+ if (theo) {+ if (face) spr->sx = signf(x - *at);+ } else+ g_player.facing = (int)signf(x - *at);+ }+ if (*at != x) {+ *at = approach(*at, x, 48 * DT);+ return true;+ }+ spr_play(spr, theo ? A_theo_idle : A_player_idle, false);+ s->walk_anim = 0;+ return false;+}+static void gond_towards(Gond *s, float percent) { /* MoveGondolaTowards */+ Gondola *g = gond(s);+ float len = v2len(v2sub(g->start, g->dest));+ s->speed = approach(s->speed, 64, 120 * DT);+ s->percent = approach(s->percent, percent, s->speed / len * DT);+ V2 at = v2lerp(g->start, g->dest, s->percent);+ s->gondola->x = floorf(at.x), s->gondola->y = floorf(at.y);+ g_level.cam = v2add(v2(s->gondola->x, s->gondola->y), v2(-160, -120));+}+static bool gond_event(void *ctx, int index) {+ Gond *s = ST((Ent *)ctx, Gond);+ Ent *te = s->theo, *ge = s->gondola;+ Theo4 *t = ST(te, Theo4);+ Gondola *g = gond(s);+ Player *p = &g_player;+ Co *c = ev_start(&s->ev, &s->evi, index);+ switch (index) {+ case 0: { /* EnterTheo */+ EV_BEGIN;+ p->facing = -1;+ EV_WAIT(0.2f);+ s->p = -1;+ EV_NEST(gond_pan(s, v2((float)g_level.room->x, te->y - 90), 1, NULL));+ te->visible = 1;+ s->start_x = te->x;+ memset(&s->move, 0, sizeof s->move), s->move.target = v2(s->start_x + 35, te->y);+ EV_NEST(theo4_move(te, &s->move));+ EV_WAIT(0.6f);+ memset(&s->move, 0, sizeof s->move), s->move.target = v2(s->start_x + 60, te->y);+ EV_NEST(theo4_move(te, &s->move));+ spr_play(&t->spr, A_theo_idleEdge, false);+ EV_WAIT(1);+ spr_play(&t->spr, A_theo_falling, false);+ te->x += 4;+ te->depth = -10010, ents_mark_unsorted();+ for (s->sp = 80; te->y < p->ent->y;) {+ te->y += s->sp * DT;+ s->sp += 120 * DT;+ EV_YIELD;+ }+ level_dir_shake(v2(0, 1), 0.3f);+ te->y = p->ent->y;+ spr_play(&t->spr, A_theo_hitGround, false);+ t->spr.rate = 0;+ te->depth = 1000, ents_mark_unsorted();+ t->spr.sx = 1.3f, t->spr.sy = 0.8f;+ EV_WAIT(0.5f);+ tween_start(&s->tw, 2); /* Theo's scale back to 1 */+ s->p = -1;+ EV_NEST(gond_pan(s, v2((float)g_level.room->x, te->y - 120), 1, NULL));+ EV_WAIT(0.6f);+ EV_END;+ }+ case 1: { /* CheckOnTheo */+ EV_BEGIN;+ s->walk = walk_to(ge->x - 18);+ EV_NEST(player_walk(p, &s->walk));+ EV_END;+ }+ case 2: { /* GetUpTheo */+ EV_BEGIN;+ EV_WAIT(1.4f);+ t->spr.rate = 1;+ spr_play(&t->spr, A_theo_recoverGround, false);+ EV_WAIT(1.6f);+ memset(&s->move, 0, sizeof s->move), s->move.target = v2(ge->x - 50, p->ent->y);+ EV_NEST(theo4_move(te, &s->move));+ EV_WAIT(0.2f);+ EV_END;+ }+ case 3: { /* LookAtLever */+ EV_BEGIN;+ memset(&s->move, 0, sizeof s->move), s->move.target = v2(ge->x + 7, te->y);+ EV_NEST(theo4_move(te, &s->move));+ p->facing = 1;+ t->spr.sx = -1;+ EV_END;+ }+ case 4: { /* PullLever */+ EV_BEGIN;+ s->pwalk = walk_exact((int)ge->x - 7), s->pwalking = 1;+ t->spr.sx = -1;+ EV_WAIT(0.2f);+ spr_play(&t->spr, A_theo_pullVent, false);+ EV_WAIT(1);+ g->lever_t = 0.5f; /* Lever.Play("pulled") */+ spr_play(&t->spr, A_theo_fallVent, false);+ EV_WAIT(0.6f);+ level_shake(0.3f);+ EV_WAIT(0.5f);+ s->p = -1;+ EV_NEST(gond_pan(s, v2add(v2(ge->x, ge->y), v2(-160, -120)), 1, NULL));+ EV_WAIT(0.5f);+ if (s->clouds) { /* the two Parallax: above the camera, the loop one above the bottom one */+ Clouds *k = ST(s->clouds, Clouds);+ Tex a, b;+ float ha = tex_get(T_bgs_04_bgCloudLoop, &a) ? a.fh : 200, hb = tex_get(T_bgs_04_bgCloud, &b) ? b.fh : 29;+ k->loop_pos = v2(0, g_level.cam.y - ha - hb);+ k->bottom_pos = v2(0, g_level.cam.y - hb);+ s->loop_at = k->bottom_pos.y;+ k->on = 1;+ }+ s->snap = 1;+ s->theo_x = te->x - ge->x;+ s->player_x = p->ent->x - ge->x;+ s->pwalking = 0;+ player_set_state(p, ST_FROZEN);+ level_shake(0.3f);+ s->speed = 32;+ g->rot_speed = 1;+ s->state = GS_TO_CENTER;+ EV_WAIT(1);+ EV_NEST(gond_move(s, true, 12, false));+ EV_WAIT(0.2f);+ t->spr.sx = -1;+ EV_END;+ }+ case 5:+ case 15: { /* WaitABit */+ EV_BEGIN;+ EV_WAIT(1);+ EV_END;+ }+ case 6: { /* WaitForCenter */+ EV_BEGIN;+ while (s->state != GS_CENTER) EV_YIELD;+ t->spr.sx = 1;+ EV_WAIT(1);+ EV_NEST(gond_move(s, false, -20, false));+ EV_WAIT(0.5f);+ EV_END;+ }+ case 7: { /* SelfieThenStallsOut */+ EV_BEGIN;+ step_reset(&s->zoom2), s->zooming = 1; /* Add(new Coroutine(Level.ZoomTo((160, 110), 2, 0.5))) */+ EV_WAIT(0.3f);+ t->spr.sx = 1;+ EV_WAIT(0.2f);+ s->to.x = s->theo_x - 8, s->panning = 2; /* Add(new Coroutine(MovePlayerOnGondola(theoXOffset - 8))) */+ EV_WAIT(0.4f);+ spr_play(&t->spr, A_theo_holdOutPhone, false);+ EV_WAIT(1.5f);+ s->theo_x += 4, s->player_x += 4;+ g->rot_speed = -1;+ s->state = GS_STOPPED;+ spr_play(&t->spr, A_theo_takeSelfieImmediate, false);+ { /* Add(new Coroutine(PanCamera(... 0.3, CubeOut))) */+ V2 d = v2norm(v2sub(g->dest, v2(ge->x, ge->y)));+ s->to = v2add(v2add(v2(ge->x, ge->y), v2mul(d, 32)), v2(-160, -120));+ s->p = -1, s->panning = 1;+ }+ EV_WAIT(0.5f);+ ch1_flash(0xFFFFFF);+ s->evil = ch2_bdummy_new(v2(0, 0));+ if (s->evil) {+ V2 at = gond_floor(s, -24, 20);+ s->evil->x = at.x, s->evil->y = at.y;+ ch2_bdummy_appear(s->evil);+ ch2_bdummy_floatness(s->evil, 0);+ s->evil->depth = -1000000, ents_mark_unsorted();+ }+ s->state = GS_SHAKING;+ s->panning = 0;+ s->p = -1;+ EV_NEST(gond_pan(s, v2add(v2(ge->x, ge->y), v2(-160, -120)), 1, NULL));+ EV_WAIT(1);+ EV_END;+ }+ case 8: { /* MovePlayerLeft */+ EV_BEGIN;+ EV_NEST(gond_move(s, false, -20, false));+ t->spr.sx = -1;+ EV_WAIT(0.5f);+ EV_NEST(gond_move(s, false, 20, false));+ EV_WAIT(0.5f);+ EV_NEST(gond_move(s, false, -10, false));+ EV_WAIT(0.5f);+ p->facing = 1;+ EV_END;+ }+ case 9: { /* SnapLeverOff */+ EV_BEGIN;+ EV_NEST(gond_move(s, true, 7, true));+ spr_play(&t->spr, A_theo_pullVent, false);+ EV_WAIT(1);+ spr_play(&t->spr, A_theo_fallVent, false);+ EV_WAIT(1);+ g->lever_broken = 1, g->lever_speed = v2(240, -130); /* BreakLever */+ level_shake(0.3f);+ EV_WAIT(2.5f);+ EV_END;+ }+ case 10: { /* DarknessAppears (the tentacles of the dark are left out) */+ EV_BEGIN;+ EV_WAIT(0.25f);+ spr_play(&p->spr, A_player_tired, false);+ EV_WAIT(0.25f);+ if (s->evil) ch2_bdummy_vanish(s->evil);+ s->evil = NULL;+ EV_WAIT(0.3f);+ level_shake(0.3f);+ for (s->sp = 0; s->sp < 1; s->sp += DT / 2) {+ EV_YIELD;+ if (s->clouds) ST(s->clouds, Clouds)->fade = s->sp;+ }+ EV_WAIT(0.25f);+ EV_END;+ }+ case 11: { /* DarknessConsumes */+ EV_BEGIN;+ level_shake(0.3f);+ EV_NEST(gond_move(s, true, 0, true));+ spr_play(&t->spr, A_theo_comfortStart, false);+ EV_END;+ }+ case 12: { /* CantBreath */+ EV_BEGIN;+ level_shake(0.3f);+ EV_YIELD;+ EV_END;+ }+ case 13: { /* StartBreathing */+ EV_BEGIN;+ s->breath = breath_new(true);+ while (!breath_done(s->breath)) EV_YIELD;+ if (s->clouds) ST(s->clouds, Clouds)->fade = 0;+ g->front_pull = 0, spr_play(&g->front, A_gondola_idle, false); /* CancelPullSides */+ zoom_reset();+ EV_WAIT(0.5f);+ EV_WAIT(1);+ level_shake(0.3f);+ s->state = GS_CENTER;+ g->rot_speed = 0.5f;+ EV_WAIT(1.2f);+ EV_END;+ }+ case 14: { /* Ascend */+ EV_BEGIN;+ s->state = GS_TO_END;+ while (s->state != GS_STOPPED) EV_YIELD;+ level_shake(0.3f);+ g->rot_speed = 0.5f;+ EV_WAIT(0.1f);+ while (g->rot > 0) EV_YIELD;+ g->rot = g->rot_speed = 0;+ level_shake(0.3f);+ s->snap = 0;+ p->state_locked = false;+ player_set_state(p, ST_DUMMY);+ p->ent->x = floorf(p->ent->x), p->ent->y = floorf(p->ent->y);+ for (int i = 0; i < 64 && collide_solid(p->ent, p->ent->x, p->ent->y); i++) p->ent->y--;+ te->y = p->ent->y;+ spr_play(&t->spr, A_theo_comfortRecover, false);+ t->spr.sx = 1;+ s->walk = walk_to(ge->x + 80);+ EV_NEST(player_walk(p, &s->walk));+ p->dummy_auto_animate = false;+ spr_play(&p->spr, A_player_tired, false);+ memset(&s->move, 0, sizeof s->move), s->move.target = v2(ge->x + 64, te->y);+ EV_NEST(theo4_move(te, &s->move));+ EV_WAIT(0.5f);+ EV_END;+ }+ case 16: { /* TheoTakesOutPhone */+ EV_BEGIN;+ p->facing = 1;+ EV_WAIT(0.25f);+ spr_play(&t->spr, A_theo_usePhone, false);+ EV_WAIT(2);+ EV_END;+ }+ default: { /* FaceTheo */+ EV_BEGIN;+ p->dummy_auto_animate = true;+ EV_WAIT(0.2f);+ p->facing = -1;+ EV_WAIT(0.2f);+ EV_END;+ }+ }+}+static void gond_end(Ent *e, bool skipped) {+ (void)e;+ level_complete_area(true, false);+ if (!skipped) g_wipe.modifier = 120, g_wipe.focus = v2(160, 90);+}+static void gond_update(Ent *e) {+ Gond *s = ST(e, Gond);+ Ent *te = s->theo, *ge = s->gondola;+ Theo4 *t = ST(te, Theo4);+ Gondola *g = gond(s);+ Player *p = &g_player;+ /* its parallel coroutines and tween */+ if (s->pwalking && !player_walk(p, &s->pwalk)) s->pwalking = 0;+ if (s->zooming && !zoom_to(&s->zoom2, v2(160, 110), 2, 0.5f)) s->zooming = 0;+ if (s->panning == 1 && !gond_pan(s, s->to, 0.3f, ease_cube_out)) s->panning = 0;+ if (s->panning == 2 && !gond_move(s, false, s->to.x, false)) s->panning = 0;+ if (s->tw.active) {+ tween_update(&s->tw);+ t->spr.sx = lerpf(1.3f, 1, s->tw.percent), t->spr.sy = lerpf(0.8f, 1, s->tw.percent);+ }+ /* Update: the gondola's ride */+ if (s->state == GS_TO_CENTER) {+ gond_towards(s, 0.5f);+ if (s->percent >= 0.5f) s->state = GS_CENTER;+ } else if (s->state == GS_CENTER) {+ if (s->clouds) {+ Clouds *k = ST(s->clouds, Clouds);+ V2 d = v2mul(v2norm(v2sub(g->dest, v2(ge->x, ge->y))), s->speed);+ k->offset = v2add(k->offset, v2mul(d, DT));+ k->loop_y = 1;+ }+ } else if (s->state == GS_SHAKING) {+ g_level.wind.x = -400;+ if (s->shake <= 0 && (g->rot == 0 || g->rot < -0.25f)) s->shake = 1, g->rot_speed = 0.5f;+ s->shake -= DT;+ } else if (s->state == GS_TO_END) {+ gond_towards(s, 1);+ if (s->percent >= 1) s->state = GS_STOPPED;+ }+ if (s->clouds && !ST(s->clouds, Clouds)->loop_y && g_level.cam.y + 180 < s->loop_at) ST(s->clouds, Clouds)->loop_y = 1;+ if (s->snap) { /* AutoSnapCharacters */+ V2 a = gond_floor(s, s->theo_x, 52), b = gond_floor(s, s->player_x, 52);+ te->x = a.x, te->y = a.y;+ p->ent->x = b.x, p->ent->y = b.y;+ if (s->evil && s->evil->cls) {+ V2 c = gond_floor(s, -24, 20);+ s->evil->x = c.x, s->evil->y = c.y;+ }+ }+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_set_state(p, ST_DUMMY);+ s->walk = walk_exact((int)ge->x + 16);+ CO_NEST(c, player_walk(p, &s->walk));+ while (!actor_on_ground(p->ent, 1)) CO_YIELD(c);+ s->evi = -1;+ CO_SAY(c, s->tb, "CH4_GONDOLA", gond_event, e);+ t->spr.sx = -1; /* ShowPhoto */+ CO_WAIT(c, 0.25f);+ s->walk = walk_to(te->x + 5);+ CO_NEST(c, player_walk(p, &s->walk));+ CO_WAIT(c, 1);+ s->breath = ch2_selfie_new(2); /* OpenRoutine("selfieGondola"), WaitForInput */+ CO_NEST(c, ch2_selfie_running(s->breath));+ cutscene_end(e);+ return;+ CO_END(c);+}+static const EntClass GOND = {.size = sizeof(Gond), .name = "CS04_Gondola", .update = gond_update};++/* NPC04_Theo */+static void theo4_update(Ent *e) {+ Theo4 *t = ST(e, Theo4);+ spr_update(&t->spr);+ if (t->started) return;+ Ent *ge = NULL;+ for (int i = 0; i < g_nents && !ge; i++)+ if (g_ents[i].cls == &GONDOLA && g_ents[i].dead != 1) ge = &g_ents[i];+ Player *p = level_player();+ if (ge && p && p->ent->x > e_left(ge) - 16) {+ t->started = 1;+ Ent *c = ent_new(&GOND, 0, 0);+ if (!c) return;+ c->collidable = 0, c->visible = 0;+ Gond *s = ST(c, Gond);+ s->theo = e, s->gondola = ge;+ s->clouds = ent_new(&CLOUDS, 0, 0);+ if (s->clouds) s->clouds->depth = 1 << 29, s->clouds->collidable = 0;+ level_register_complete(); /* OnBegin */+ cutscene_start(c, gond_end, false, true);+ }+}+static void theo4_render(Ent *e) { draw_npc(&ST(e, Theo4)->spr, e->x, e->y); }+static const EntClass THEO4 = {.size = sizeof(Theo4), .name = "NPC04_Theo", .update = theo4_update, .render = theo4_render};+static void new_theo4(const EData *d) {+ Ent *e = ent_new(&THEO4, d->x, d->y);+ if (!e) return;+ e->depth = 1000;+ e->visible = 0;+ ent_box(e, 8, 8, -4, -8);+ Theo4 *t = ST(e, Theo4);+ spr_init(&t->spr, SB_theo);+ spr_play(&t->spr, A_theo_idle, false);+}++bool ents_ch4(const EData *d) {+ wind_room_load(d);+ switch (d->type) {+ case ET_booster: new_booster(d); return true;+ case ET_moveBlock: new_moveblock(d); return true;+ case ET_cloud: new_cloud(d); return true;+ case ET_ridgeGate: new_ridge(d); return true;+ case ET_whiteblock: new_white(d); return true;+ case ET_gondola: new_gondola(d); return true;+ case ET_cliffside_flag: new_wflag(d); return true;+ case ET_cliffflag: new_cliffflags(d); return true;+ case ET_npc: {+ const char *n = EAS(d, npc, npc);+ if (!strcmp(n, "granny_04_cliffside")) new_granny4(d);+ else if (!strcmp(n, "theo_04_cliffside")) new_theo4(d);+ else return false;+ return true;+ }+ }+ return false;+}++bool trigs_ch4(const EData *d) {+ switch (d->type) {+ case TT_windTrigger: {+ Ent *e = ent_new(&WINDTRIG, d->x, d->y);+ if (!e) return true;+ ent_box(e, EA(d, windTrigger, width), EA(d, windTrigger, height), 0, 0);+ e->visible = 0;+ static const char *P[15] = {"None", "Left", "Right", "LeftStrong", "RightStrong", "LeftOnOff", "RightOnOff", "LeftOnOffFast",+ "RightOnOffFast", "Alternating", "LeftGemsOnly", "RightCrazy", "Down", "Up", "Space"};+ const char *s = EAS(d, windTrigger, pattern);+ for (int i = 0; i < 15; i++)+ if (!strcmp(s, P[i])) ST(e, WindTrig)->pattern = (uint8_t)i;+ return true;+ }+ case TT_windAttackTrigger: {+ Ent *e = ent_new(&WINDATTACK, d->x, d->y);+ if (e) ent_box(e, EA(d, windAttackTrigger, width), EA(d, windAttackTrigger, height), 0, 0), e->visible = 0;+ return true;+ }+ }+ return false;+}++/* this chapter's tables: in the memory it is given while it is played (res_chapter_ram) */+uint32_t ch4_ram(void) { return END_mb_btn_px; }diff --git a/games/celeste/src/ch5.c b/games/celeste/src/ch5.cnew file mode 100644index 00000000..4ae5f7b3--- /dev/null+++ b/games/celeste/src/ch5.c@@ -0,0 +1,4219 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* Mirror Temple (chapter 5): torches, temple eyes and gates, dash switches,+ * swap blocks, cracked walls, seeker barriers and seekers, Theo's crystal+ * (the holdable), condition blocks, the mirrors and the mirror portal, the+ * seeker statue, the big eyeball and the player seeker of the void.+ * Ported from the game's classes (Torch.cs, TempleEye.cs, TempleGate.cs...). */+#include <stdlib.h>+#include "badeline.h"++/* ---------------------------------------------------------------- helpers (Calc) */+static float angle_diff(float a, float b) {+ float d = b - a;+ while (d > PI_F) d -= 2 * PI_F;+ while (d <= -PI_F) d += 2 * PI_F;+ return d;+}+static float angle_lerp(float a, float b, float t) { return a + angle_diff(a, b) * t; }+static float angle_approach(float v, float t, float m) {+ float d = angle_diff(v, t);+ if (fabsf(d) < m) return t;+ return v + clampf(d, -m, m);+}+static float dist2(V2 a, V2 b) { return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); }+/* Scene.OnInterval(interval, offset) */+static bool on_interval_off(float interval, float offset) {+ float t = g_level.time_active;+ return floorf((t - offset - DT) / interval) < floorf((t - offset) / interval);+}+static uint16_t tex_named(const char *p) { return res_tex_by_name(p); }+static void tex_family(const char *prefix, uint16_t *out, int n) {+ char p[64];+ for (int i = 0; i < n; i++) out[i] = tex_named(path2(p, prefix, NULL, i));+}+/* frame f of a family drawn as an animation: when it is not loaded, the whole family is, in one pass */+static uint16_t fam_tex(const uint16_t *tex, int n, int f) {+ if (tex[f] != 0xFFFF && !res_cached(tex[f])) res_load(tex, n);+ return tex[f];+}+/* MTexture.DrawCentered */+static void draw_centered(uint16_t tex, float x, float y, uint16_t tint, uint8_t alpha, float sx, float sy, float rot) {+ Tex t;+ if (tex == 0xFFFF || !tex_get(tex, &t)) return;+ float k = t.scale > 1 ? t.scale : 1; /* stored smaller, drawn scaled up */+ gfx_tex_ex(tex, x, y, t.fw * k / 2.f, t.fh * k / 2.f, sx, sy, rot, tint, alpha, 0);+}+static uint16_t lerp565(uint32_t a, uint32_t b, float t) {+ t = clampf(t, 0, 1);+ int r = (int)(((a >> 16) & 255) + (((int)((b >> 16) & 255) - (int)((a >> 16) & 255)) * t));+ int g = (int)(((a >> 8) & 255) + (((int)((b >> 8) & 255) - (int)((a >> 8) & 255)) * t));+ int bl = (int)((a & 255) + (((int)(b & 255) - (int)(a & 255)) * t));+ return rgb((uint32_t)(r << 16 | g << 8 | bl));+}++/* the chapter's rooms: names and indices (EntityID.Level) */+static const char *room_name(int i) { return level_room_name_of(i); }+static int room_index(const char *name, int n) {+ char buf[24];+ if (n >= (int)sizeof buf) return -1;+ memcpy(buf, name, (size_t)n);+ buf[n] = 0;+ return chapter_find_room(g_level.chapter, buf);+}+/* "prefix" + EntityID.Key ("room:id") */+static const char *id_flag(char *buf, const char *prefix, int room, int id) {+ char num[8];+ int k = 0, v = id < 0 ? 0 : id;+ char tmp[8];+ do tmp[k++] = (char)('0' + v % 10), v /= 10;+ while (v);+ for (int i = 0; i < k; i++) num[i] = tmp[k - 1 - i];+ num[k] = 0;+ char *o = buf;+ for (const char *s = prefix; *s; s++) *o++ = *s;+ for (const char *s = room_name(room); *s; s++) *o++ = *s;+ *o++ = ':';+ for (const char *s = num; *s; s++) *o++ = *s;+ *o = 0;+ return buf;+}++/* entity references in states are indices (states are only 4-byte aligned) */+static uint8_t ent_ref(const Ent *e) { return (uint8_t)(e - g_ents); }+static Ent *ent_at(uint8_t i) { return &g_ents[i]; }+static Ent *first_of(const EntClass *c) {+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == c && g_ents[i].dead != 1) return &g_ents[i];+ return NULL;+}++/* the player's hurtbox (Player.hurtbox) overlapping a rect: PlayerCollider checks */+static void player_hurtbox(const Ent *pe, float *l, float *t, float *r, float *b) {+ float w = pe->cw, h = pe->ch, x = pe->cx, y = pe->cy;+ if (h == 11) h = 9;+ else if (h == 6) h = 4;+ else if (h == 8 && w == 8) w = 6, h = 6, x = -3, y = -9;+ *l = pe->x + x, *t = pe->y + y, *r = *l + w, *b = *t + h;+}+static Player *player_hits(float l, float t, float r, float b) {+ Player *p = level_player();+ if (!p || p->dead || p->state == ST_CASSETTEFLY) return NULL;+ float pl, pt, pr, pb;+ player_hurtbox(p->ent, &pl, &pt, &pr, &pb);+ return pr > l && pb > t && pl < r && pt < b ? p : NULL;+}++/* ---------------------------------------------------------------- compact sprites */+/* A Monocle Sprite's playing state; banks give the frames and origins */+typedef struct { uint8_t bank, anim, frame, playing; int8_t last; uint8_t pad[3]; float timer; } CSpr;+static Sprite cs_raw(const CSpr *c) {+ Sprite s;+ memset(&s, 0, sizeof s);+ s.bank = c->bank, s.anim = c->anim, s.frame = c->frame, s.playing = c->playing;+ s.timer = c->timer, s.rate = 1, s.last_goto = c->last, s.sx = s.sy = 1, s.tint = 0xFFFF, s.alpha = 255, s.visible = 1;+ return s;+}+static void cs_back(CSpr *c, const Sprite *s) {+ c->bank = s->bank, c->anim = s->anim, c->frame = s->frame, c->playing = s->playing, c->timer = s->timer, c->last = s->last_goto;+}+static void cs_init(CSpr *c, int bank) {+ Sprite s;+ spr_init(&s, bank);+ cs_back(c, &s);+}+static void cs_play(CSpr *c, int anim, bool restart) {+ Sprite s = cs_raw(c);+ spr_play(&s, anim, restart);+ cs_back(c, &s);+}+static int cs_cur(const CSpr *c) { return c->anim != 255 ? c->anim : -1; }+/* Sprite.Update; returns the animation that went past its last frame (OnLastFrame), else -1 */+static int cs_update(CSpr *c) {+ if (!c->playing || c->anim == 255) return -1;+ Sprite s = cs_raw(c);+ int n = spr_frames(&s);+ float delay = n ? spr_anim_duration(c->bank, c->anim) / n : 0;+ int ended = (c->frame >= n - 1 && delay > 0 && c->timer + DT >= delay) ? c->anim : -1;+ spr_update(&s);+ cs_back(c, &s);+ return ended;+}+static uint16_t cs_tex(const CSpr *c) {+ Sprite s = cs_raw(c);+ uint16_t t = spr_tex(&s);+ if (t != 0xFFFF && !res_cached(t)) { /* an animation not loaded yet: all its frames in one pass (as spr_draw) */+ uint16_t ids[32], gotos[8];+ int ng, a = c->anim != 255 ? c->anim : c->last;+ if (a >= 0) res_load(ids, bank_anim_textures(c->bank, a, ids, 32, gotos, &ng));+ }+ return t;+}+static void cs_draw(const CSpr *c, float x, float y, float sx, float sy, float rot, uint16_t tint, uint8_t alpha) {+ Sprite s;+ spr_init(&s, c->bank);+ uint16_t t = cs_tex(c);+ Tex tx;+ if (t == 0xFFFF || !tex_get(t, &tx)) return;+ float ox = s.justify ? tx.fw * tx.scale * s.jx : s.ox, oy = s.justify ? tx.fh * tx.scale * s.jy : s.oy;+ gfx_tex_ex(t, x, y, ox, oy, sx, sy, rot, tint, alpha, 0);+}++/* DeathEffect.Draw */+static void death_draw(V2 pos, uint16_t color, float ease) {+ uint16_t c2 = ((int)floorf(ease * 10) % 2 == 0) ? color : 0xFFFF;+ float s = ease < 0.5f ? 0.5f + ease : ease_cube_out(1 - (ease - 0.5f) * 2);+ for (int pass = 0; pass < 2; pass++)+ for (int i = 0; i < 8; i++) {+ V2 at = v2add(pos, angle_vec((i / 8.f + ease * 0.25f) * 2 * PI_F, ease_cube_out(ease) * 24));+ if (!pass) {+ static const int8_t o[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};+ for (int k = 0; k < 4; k++)+ gfx_tex_ex(T_characters_player_hair00, at.x + o[k][0], at.y + o[k][1], 5, 5, s, s, 0, 0, 255, GF_SILHOUETTE);+ } else+ gfx_tex_ex(T_characters_player_hair00, at.x, at.y, 5, 5, s, s, 0, c2, 255, GF_SILHOUETTE);+ }+}++/* ---------------------------------------------------------------- Torch */+/* 585 in the chapter, 54 in a room: one entity per room holds them all */+#define MAX_TORCH 100+typedef struct {+ int16_t x, y;+ uint16_t eid, frames; /* frames: updates since the sprite started playing */+ uint8_t slot, room, lit, lit_bank; /* lit_bank: startLit, the "litTorch" sprite */+ uint8_t on_mode, tween; /* on_mode: the sprite plays "on" (lit when added), else "turnOn" first;+ * tween: the light's tween, in updates (60: done) */+} Torch;+enum { OFF_torches = 0, END_torches = OFF_torches + (int)sizeof(Torch[MAX_TORCH]) };+#define torches (*(Torch(*)[MAX_TORCH])(void *)(g_chram[5] + OFF_torches))+static int ntorches;+typedef struct { uint8_t slot; } TorchMgr;+static uint16_t torch_tex[2][9];++static void torch_update(Ent *e) {+ int slot = ST(e, TorchMgr)->slot;+ for (int i = 0; i < ntorches; i++) {+ Torch *t = &torches[i];+ if (t->slot != slot) continue;+ if (t->lit) {+ t->frames++;+ if (t->frames * DT > 12.24f) t->frames -= 720; /* 25 loops of "on" (12 s), whole frames either way */+ if (t->tween < 60) t->tween++;+ continue;+ }+ /* PlayerCollider: Hitbox(32, 32, -16, -16) */+ if (player_hits(t->x - 16, t->y - 16, t->x + 16, t->y + 16)) {+ t->lit = 1;+ t->frames = 0;+ t->tween = 0;+ char flag[40];+ level_set_flag(id_flag(flag, "torch_", t->room, t->eid), true);+ particles_emit(PL_FG, &P_Torch_P_OnLight, 12, v2(t->x, t->y), v2(3, 3), 0);+ }+ }+}+static void torch_render(Ent *e) {+ int slot = ST(e, TorchMgr)->slot;+ for (int i = 0; i < ntorches; i++) {+ Torch *t = &torches[i];+ if (t->slot != slot) continue;+ int f = 0;+ float time = t->frames * DT;+ if (t->lit) {+ if (t->on_mode || time >= 0.24f) { /* "on": frames 3-8 */+ float on = t->on_mode ? time : time - 0.24f;+ f = 3 + (int)floorf(on / 0.08f) % 6;+ } else+ f = 1 + (int)floorf(time / 0.08f); /* "turnOn": frames 1-3 */+ }+ draw_centered(fam_tex(torch_tex[t->lit_bank], 9, f), t->x, t->y, 0xFFFF, 255, 1, 1, 0);+ if (t->lit) {+ /* VertexLight and BloomPoint */+ uint32_t c = t->lit_bank ? 0xFFD27F : 0x7FFFFF; /* StartLitColor, Torch.Color */+ float ease = 1, bloom = 0.5f;+ if (t->tween < 60) {+ ease = ease_back_out(t->tween * DT);+ uint16_t col = lerp565(0xFFFFFF, c, ease);+ c = (uint32_t)((col >> 11) << 19 | ((col >> 5) & 63) << 10 | (col & 31) << 3);+ bloom = 0.5f + 0.5f * (1 - ease);+ }+ light_add(t->x, t->y, c, 1, 48 + (1 - ease) * 32, 64 + (1 - ease) * 32);+ bloom_add(t->x, t->y, bloom, 8);+ }+ }+}+static void torch_removed(Ent *e) {+ int slot = ST(e, TorchMgr)->slot, n = 0;+ for (int i = 0; i < ntorches; i++)+ if (torches[i].slot != slot) torches[n++] = torches[i];+ ntorches = n;+}+static const EntClass TORCHES = {.name = "torch", .size = sizeof(TorchMgr), .update = torch_update, .render = torch_render,+ .removed = torch_removed};++static void new_torch(const EData *d) {+ int slot = g_level.room_slot;+ Ent *m = NULL;+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &TORCHES && g_ents[i].dead != 1 && ST(&g_ents[i], TorchMgr)->slot == slot) m = &g_ents[i];+ if (!m) {+ m = ent_new(&TORCHES, 0, 0);+ if (!m) return;+ m->depth = 2000;+ m->collidable = 0;+ ST(m, TorchMgr)->slot = (uint8_t)slot;+ }+ if (ntorches >= MAX_TORCH) return;+ if (torch_tex[0][0] == 0) {+ tex_family("objects/temple/torch", torch_tex[0], 9);+ tex_family("objects/temple/litTorch", torch_tex[1], 9);+ }+ Torch *t = &torches[ntorches++];+ memset(t, 0, sizeof *t);+ t->x = (int16_t)d->x, t->y = (int16_t)d->y;+ t->eid = (uint16_t)d->id;+ t->slot = (uint8_t)slot;+ t->room = (uint8_t)d->room;+ t->lit_bank = EAB(d, torch, startLit);+ t->tween = 60;+ char flag[40];+ if (t->lit_bank || level_get_flag(id_flag(flag, "torch_", d->room, d->id))) {+ t->lit = 1; /* Added: lit, sprite.Play("on") */+ t->on_mode = 1;+ }+}++/* ---------------------------------------------------------------- TempleEye */+/* 468 in the chapter, 71 in a room: one entity per room and layer draws them */+#define MAX_EYES 128+enum { EYE_BG = 1, EYE_KNOWN = 2, EYE_BLINK = 4, EYE_BURST = 8 };+typedef struct {+ int16_t x, y;+ int8_t px, py; /* pupilPosition, 1/32 pixels */+ int8_t tx, ty; /* pupilTarget, 1/100 */+ uint8_t slot, flags, n, pad; /* n: updates since the eyelid's blink or the burst began */+ float timer; /* blinkTimer */+} Eye;+enum { OFF_eyes = ((END_torches + 7) & ~7), END_eyes = OFF_eyes + (int)sizeof(Eye[MAX_EYES]) };+#define eyes (*(Eye(*)[MAX_EYES])(void *)(g_chram[5] + OFF_eyes))+static int neyes;+typedef struct { uint8_t slot, bg; } EyeMgr;+static uint16_t eye_tex[2][2], eye_lid[2][4], eye_burst[2][9];+static const uint8_t EYE_BLINK_FRAMES[6] = {0, 1, 1, 2, 3, 0};+static const EntClass THEO;+static void eye_set_timer(Eye *y) { y->timer = rnd_rangef(1, 15); }+static V2 theo_center(Ent *t) { return v2(t->x, t->y - 5); }+static void eye_target(Eye *y, Ent *theo) {+ V2 d = safe_norm(v2sub(theo_center(theo), v2(y->x, y->y)), 1);+ y->tx = (int8_t)roundi(d.x * 100), y->ty = (int8_t)roundi(d.y * 100);+}+static void eyes_resolve(int slot) {+ Ent *theo = first_of(&THEO);+ for (int i = 0; i < neyes; i++) {+ Eye *y = &eyes[i];+ if (y->slot != slot || (y->flags & EYE_KNOWN)) continue;+ y->flags |= EYE_KNOWN;+ if (!point_solid(y->x, y->y)) y->flags |= EYE_BG; /* Added: isBG = !CollideCheck<Solid>(Position) */+ if (theo) { /* Awake */+ eye_target(y, theo);+ y->px = (int8_t)(y->tx * 96 / 100), y->py = (int8_t)(y->ty * 96 / 100);+ }+ }+}+static void eyes_awake(Ent *e) { eyes_resolve(ST(e, EyeMgr)->slot); }+static void eyes_update(Ent *e) {+ EyeMgr *m = ST(e, EyeMgr);+ if (!m->bg) return; /* the background manager updates them all */+ Ent *theo = first_of(&THEO);+ bool chance = level_on_interval(0.25f);+ int n = 0;+ for (int i = 0; i < neyes; i++) {+ Eye *y = &eyes[i];+ if (y->slot != m->slot) {+ eyes[n++] = *y;+ continue;+ }+ if (y->flags & EYE_BURST) { /* "burst": 0.08 a frame, then RemoveSelf */+ if ((int)(++y->n * DT / 0.08f) >= 9) continue;+ eyes[n++] = *y;+ continue;+ }+ /* pupilPosition = Approach(pupilPosition, pupilTarget * 3, 16 * DT) */+ V2 p = approach_v(v2(y->px / 32.f, y->py / 32.f), v2(y->tx * 0.03f, y->ty * 0.03f), 16 * DT);+ y->px = (int8_t)roundi(p.x * 32), y->py = (int8_t)roundi(p.y * 32);+ if (theo) {+ eye_target(y, theo);+ if (chance && rndf() < 0.01f && !(y->flags & EYE_BLINK)) y->flags |= EYE_BLINK, y->n = 0;+ }+ y->timer -= DT;+ if (y->timer <= 0) {+ eye_set_timer(y);+ if (!(y->flags & EYE_BLINK)) y->flags |= EYE_BLINK, y->n = 0;+ }+ /* the eyelid's "blink": frames 0 1 1 2 3 0, 0.08 each, then "open" */+ if ((y->flags & EYE_BLINK) && (int)(++y->n * DT / 0.08f) >= 6) y->flags &= (uint8_t)~EYE_BLINK;+ eyes[n++] = *y;+ }+ neyes = n;+}+static void eyes_render(Ent *e) {+ EyeMgr *m = ST(e, EyeMgr);+ for (int i = 0; i < neyes; i++) {+ Eye *y = &eyes[i];+ if (y->slot != m->slot || !(y->flags & EYE_KNOWN) || !(y->flags & EYE_BG) != !m->bg) continue;+ int k = (y->flags & EYE_BG) ? 0 : 1;+ if (y->x < g_camx - 16 || y->x > g_camx + 336 || y->y < g_camy - 16 || y->y > g_camy + 196) continue;+ if (y->flags & EYE_BURST) {+ int f = (int)(y->n * DT / 0.08f);+ draw_centered(fam_tex(eye_burst[k], 9, f < 9 ? f : 8), y->x, y->y, 0xFFFF, 255, 1, 1, 0);+ continue;+ }+ draw_centered(eye_tex[k][0], y->x, y->y, 0xFFFF, 255, 1, 1, 0);+ draw_centered(eye_tex[k][1], y->x + y->px / 32.f, y->y + y->py / 32.f, 0xFFFF, 255, 1, 1, 0);+ int f = (y->flags & EYE_BLINK) ? EYE_BLINK_FRAMES[(int)(y->n * DT / 0.08f) % 6] : 0;+ draw_centered(eye_lid[k][f], y->x, y->y, 0xFFFF, 255, 1, 1, 0);+ }+}+static void eyes_removed(Ent *e) {+ EyeMgr *m = ST(e, EyeMgr);+ if (!m->bg) return;+ int n = 0;+ for (int i = 0; i < neyes; i++)+ if (eyes[i].slot != m->slot) eyes[n++] = eyes[i];+ neyes = n;+}+static const EntClass EYES = {.name = "templeEye", .size = sizeof(EyeMgr), .update = eyes_update, .render = eyes_render,+ .awake = eyes_awake, .removed = eyes_removed};+/* TempleEye.Burst, for every eye (TempleBigEyeball) */+static void eyes_burst_all(void) {+ for (int i = 0; i < neyes; i++)+ if (!(eyes[i].flags & EYE_BURST)) eyes[i].flags |= EYE_BURST, eyes[i].n = 0;+}++static void new_eye(const EData *d) {+ int slot = g_level.room_slot;+ bool have = false;+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &EYES && g_ents[i].dead != 1 && ST(&g_ents[i], EyeMgr)->slot == slot) have = true;+ if (!have)+ for (int bg = 1; bg >= 0; bg--) {+ Ent *m = ent_new(&EYES, 0, 0);+ if (!m) return;+ m->depth = bg ? 8990 : -10001;+ m->collidable = 0;+ ST(m, EyeMgr)->slot = (uint8_t)slot;+ ST(m, EyeMgr)->bg = (uint8_t)bg;+ }+ if (neyes >= MAX_EYES) return;+ if (!eye_tex[0][0]) {+ eye_tex[0][0] = tex_named("scenery/temple/eye/bg_eye");+ eye_tex[0][1] = tex_named("scenery/temple/eye/bg_pupil");+ eye_tex[1][0] = tex_named("scenery/temple/eye/fg_eye");+ eye_tex[1][1] = tex_named("scenery/temple/eye/fg_pupil");+ tex_family("scenery/temple/eye/bg_lid", eye_lid[0], 4);+ tex_family("scenery/temple/eye/fg_lid", eye_lid[1], 4);+ tex_family("scenery/temple/eye/bg_burst", eye_burst[0], 9);+ tex_family("scenery/temple/eye/fg_burst", eye_burst[1], 9);+ }+ Eye *y = &eyes[neyes++];+ memset(y, 0, sizeof *y);+ y->x = (int16_t)d->x, y->y = (int16_t)d->y;+ y->slot = (uint8_t)slot;+ eye_set_timer(y);+}+/* Shaker: Calc.Random.ShakeVector picks from {-1, -1, 0, 1, 1} */+static int8_t shake_off(void) {+ static const int8_t o[5] = {-1, -1, 0, 1, 1};+ return o[rndi(5)];+}+typedef struct { float timer; int8_t x, y; uint8_t on, pad; } Shaker;+static void shaker_for(Shaker *s, float t) { s->on = 1, s->timer = t; }+static void shaker_update(Shaker *s) {+ if (s->on && s->timer > 0) {+ s->timer -= DT;+ if (s->timer <= 0) {+ s->on = 0, s->x = s->y = 0;+ return;+ }+ }+ if (s->on && level_on_interval(0.05f)) s->x = shake_off(), s->y = shake_off();+}++/* ---------------------------------------------------------------- TempleGate */+enum { TG_NEAREST, TG_BEHIND, TG_BEHIND_ALWAYS, TG_HOLDING_THEO, TG_TOUCH, TG_BEHIND_THEO };+typedef struct {+ uint8_t type, look, open, claimed, lock, co, anim, frame; /* look: default, mirror, theo */+ uint8_t alarm_step, pad[3];+ Shaker shaker;+ int16_t closed_h, pad2;+ float draw_h, draw_speed, hold_wait, anim_t, alarm, co_wait;+ V2 hold_from;+} Gate;+static uint16_t gate_tex[3][15];+enum { GA_IDLE, GA_OPEN, GA_HIT };+static void gate_play(Gate *g, int anim) { /* Sprite.Play(anim) (no restart) */+ if (g->anim == anim) return;+ g->anim = (uint8_t)anim, g->frame = 0, g->anim_t = 0;+}+/* SetHeight: grows by pushing from above, as the gate comes down */+static void gate_set_height(Ent *e, int h) {+ if (h < e->ch) {+ e->ch = (float)h;+ return;+ }+ float y = e->y;+ int num = (int)e->ch;+ if (e->ch < 64) {+ e->y -= 64 - e->ch;+ e->ch = 64;+ }+ plat_move_v_exact(e, h - num);+ e->y = y;+ e->ch = (float)h;+}+static void gate_start_open(Ent *e) {+ Gate *g = ST(e, Gate);+ gate_set_height(e, 0);+ g->draw_h = 4;+ g->open = 1;+}+static void gate_open(Ent *e) {+ Gate *g = ST(e, Gate);+ g->hold_wait = 0.2f;+ g->draw_speed = 200;+ g->draw_h = e->ch;+ shaker_for(&g->shaker, 0.2f);+ gate_set_height(e, 0);+ gate_play(g, GA_OPEN);+ g->open = 1;+}+static void gate_close(Ent *e) {+ Gate *g = ST(e, Gate);+ g->hold_wait = 0.2f;+ g->draw_speed = 300;+ g->draw_h = fmaxf(4, e->ch);+ shaker_for(&g->shaker, 0.2f);+ gate_set_height(e, g->closed_h);+ gate_play(g, GA_HIT);+ g->open = 0;+}+static void gate_switch_open(Ent *e) { /* sprite "open", then 0.2 s: shake, then 0.2 s: Open */+ Gate *g = ST(e, Gate);+ gate_play(g, GA_OPEN);+ g->alarm = 0.2f;+ g->alarm_step = 1;+}+static Ent *theo_entity(void);+static bool gate_theo_nearby(Ent *e) {+ Gate *g = ST(e, Gate);+ Ent *t = theo_entity();+ if (!t || t->x > e->x + 10) return true;+ return dist2(g->hold_from, theo_center(t)) < (g->open ? 6400 : 4096);+}+/* Switch.Check: the touch switches (another chapter's file) say whether they are all on */+__attribute__((weak)) bool level_switch_check(void) { return false; }+static void gate_update(Ent *e) {+ Gate *g = ST(e, Gate);+ plat_update(e);+ /* components: the sprite, the shaker, coroutines, alarms */+ static const float DELAY[3] = {0.1f, 0.1f, 0.08f};+ static const uint8_t LEN[3] = {1, 9, 5};+ if (g->anim != GA_IDLE) {+ g->anim_t += DT;+ if (g->anim_t >= DELAY[g->anim]) {+ g->anim_t -= DELAY[g->anim];+ if (++g->frame >= LEN[g->anim]) g->anim = GA_IDLE, g->frame = 0, g->anim_t = 0; /* goto idle */+ }+ }+ shaker_update(&g->shaker);+ Ent *pe = level_player_ent();+ switch (g->co) {+ case 1: /* CloseBehindPlayer */+ if (!g->lock && pe && e_left(pe) > e_right(e) + 4) g->co = 0, gate_close(e);+ break;+ case 2: { /* CloseBehindPlayerAndTheo */+ Ent *t = theo_entity();+ if (pe && e_left(pe) > e_right(e) + 4 && !g->lock && t && e_left(t) > e_right(e) + 4) g->co = 0, gate_close(e);+ break;+ }+ case 3: /* CheckTouchSwitches */+ if (g->co_wait > 0) {+ g->co_wait -= DT;+ break;+ }+ if (!level_switch_check()) break;+ gate_play(g, GA_OPEN);+ g->co_wait = 0.5f;+ g->co = 4;+ break;+ case 4:+ if (g->co_wait > 0) {+ g->co_wait -= DT;+ break;+ }+ shaker_for(&g->shaker, 0.2f);+ g->co_wait = 0.2f;+ g->co = 5;+ break;+ case 5:+ if (g->co_wait > 0) {+ g->co_wait -= DT;+ break;+ }+ if (g->lock) break;+ g->co = 0;+ gate_open(e);+ break;+ }+ if (g->alarm_step && (g->alarm -= DT) <= 0) {+ if (g->alarm_step == 1) {+ shaker_for(&g->shaker, 0.2f);+ g->alarm = 0.2f;+ g->alarm_step = 2;+ } else {+ g->alarm_step = 0;+ gate_open(e);+ }+ }+ if (g->type == TG_HOLDING_THEO) {+ if (g->hold_wait > 0) g->hold_wait -= DT;+ else if (!g->lock) {+ if (g->open && !gate_theo_nearby(e)) {+ gate_close(e);+ /* CollideFirst<Player>(Position + (8, 0))?.Die */+ if (pe && collide_ent_at(e, e->x + 8, e->y, pe)) player_die(level_player(), v2(0, 0), false);+ } else if (!g->open && gate_theo_nearby(e))+ gate_open(e);+ }+ }+ float h = fmaxf(4, e->ch);+ if (g->draw_h != h) {+ g->lock = 1;+ g->draw_h = approach(g->draw_h, h, g->draw_speed * DT);+ } else+ g->lock = 0;+}+static void gate_awake(Ent *e) {+ Gate *g = ST(e, Gate);+ Ent *pe = level_player_ent();+ if (g->type == TG_BEHIND) {+ if (pe && e_left(pe) < e_right(e) && e_bottom(pe) >= e_top(e) && e_top(pe) <= e_bottom(e)) {+ gate_start_open(e);+ g->co = 1;+ }+ } else if (g->type == TG_BEHIND_ALWAYS) {+ gate_start_open(e);+ g->co = 1;+ } else if (g->type == TG_BEHIND_THEO) {+ gate_start_open(e);+ g->co = 2;+ } else if (g->type == TG_HOLDING_THEO) {+ if (gate_theo_nearby(e)) gate_start_open(e);+ e->cw = 16;+ } else if (g->type == TG_TOUCH)+ g->co = 3;+ g->draw_h = fmaxf(4, e->ch);+}+static void gate_render(Ent *e) {+ Gate *g = ST(e, Gate);+ float sx = (float)sgn(g->shaker.x);+ gfx_rect(e->x - 2, e->y - 8, 14, 10, 0, 255);+ static const uint8_t FIRST[3] = {0, 6, 0};+ uint16_t t = fam_tex(gate_tex[g->look], 15, FIRST[g->anim] + g->frame);+ int dh = (int)g->draw_h;+ /* DrawSubrect(0, 48 - drawHeight, 24, drawHeight): the bottom of the door, from the gate's top */+ if (dh > 0) gfx_tex_part(t, e->x + 4 - 12 + sx, e->y, 0, 48 - dh, 24, dh, 0, 0xFFFF, 255);+}+static const EntClass GATE = {.name = "templeGate", .size = sizeof(Gate), .update = gate_update, .render = gate_render,+ .awake = gate_awake, .kind = KIND_SOLID};++static void new_gate(const EData *d) {+ int h = (int)EA(d, templeGate, height);+ Ent *e = ent_new(&GATE, d->x, d->y);+ if (!e) return;+ ent_box(e, 8, (float)h, 0, 0);+ e->safe = 1;+ e->depth = -9000;+ Gate *g = ST(e, Gate);+ static const char *TYPES[] = {"NearestSwitch", "CloseBehindPlayer", "CloseBehindPlayerAlways", "HoldingTheo", "TouchSwitches",+ "CloseBehindPlayerAndTheo"};+ const char *ty = EAS(d, templeGate, type);+ for (int i = 0; i < 6; i++)+ if (!strcmp(ty, TYPES[i])) g->type = (uint8_t)i;+ const char *sp = EAS(d, templeGate, sprite);+ g->look = !strcmp(sp, "mirror") ? 1 : !strcasecmp(sp, "theo") ? 2 : 0;+ g->closed_h = (int16_t)h;+ g->hold_wait = 0.2f;+ g->hold_from = v2(d->x + 4, d->y + h / 2);+ if (!gate_tex[0][0]) {+ tex_family("objects/door/TempleDoor", gate_tex[0], 15);+ tex_family("objects/door/TempleDoorB", gate_tex[1], 15);+ tex_family("objects/door/TempleDoorC", gate_tex[2], 15);+ }+}++/* ---------------------------------------------------------------- DashSwitch */+enum { SIDE_UP, SIDE_DOWN, SIDE_LEFT, SIDE_RIGHT };+typedef struct {+ uint8_t side, persistent, all_gates, pressed, was_on, mirror, room, pad;+ uint16_t eid, pad2;+ CSpr spr;+ V2 target;+ float speed_y, start_y;+} DSwitch;+static const int8_t SIDE_DIR[4][2] = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};+static const int8_t SIDE_SPR[4][2] = {{8, 0}, {8, 8}, {0, 8}, {8, 8}};+static const float SIDE_ROT[4] = {-PI_F / 2, PI_F / 2, PI_F, 0};+static Ent *dswitch_gate(Ent *e) { /* GetGate: the nearest unclaimed NearestSwitch gate of the room */+ Ent *best = NULL;+ float bd = 0;+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o->cls != &GATE || o->dead == 1 || o->room != e->room) continue;+ Gate *g = ST(o, Gate);+ if (g->type != TG_NEAREST || g->claimed) continue;+ float d2 = dist2(v2(e->x, e->y), v2(o->x, o->y));+ if (!best || d2 < bd) best = o, bd = d2;+ }+ if (best) ST(best, Gate)->claimed = 1;+ return best;+}+static void portal_switch_hit(int side);+static int dswitch_hit(Ent *e, Player *p, V2 dir) {+ (void)p;+ DSwitch *s = ST(e, DSwitch);+ V2 pd = v2(SIDE_DIR[s->side][0], SIDE_DIR[s->side][1]);+ if (s->pressed || !v2eq(dir, pd)) return DASH_NORMAL;+ cs_play(&s->spr, s->mirror ? A_dashSwitch_mirror_push : A_dashSwitch_default_push, false);+ s->pressed = 1;+ plat_move_to(e, s->target.x, s->target.y);+ e->collidable = 0;+ e->x -= pd.x * 2, e->y -= pd.y * 2;+ s = ST(e, DSwitch);+ V2 at = v2(e->x + SIDE_SPR[s->side][0], e->y + SIDE_SPR[s->side][1]);+ V2 perp = v2(dir.y * 6, -dir.x * 6); /* direction.Perpendicular() * 6 */+ perp = v2(fabsf(perp.x), fabsf(perp.y));+ float a = SIDE_ROT[s->side] - PI_F;+ particles_emit(PL_FG, s->mirror ? &P_DashSwitch_P_PressAMirror : &P_DashSwitch_P_PressA, 10, at, perp, a);+ particles_emit(PL_FG, s->mirror ? &P_DashSwitch_P_PressBMirror : &P_DashSwitch_P_PressB, 4, at, perp, a);+ if (s->all_gates) {+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o->cls == &GATE && o->dead != 1 && o->room == e->room && ST(o, Gate)->type == TG_NEAREST) gate_switch_open(o);+ }+ } else {+ Ent *g = dswitch_gate(e);+ if (g) gate_switch_open(g);+ }+ Room *rm = g_level.room;+ portal_switch_hit(sgn(e->x - (rm->x + rm->w / 2)));+ if (s->persistent) {+ char flag[48];+ level_set_flag(id_flag(flag, "dashSwitch_", s->room, s->eid), true);+ }+ return DASH_NORMAL;+}+static void dswitch_awake(Ent *e) {+ DSwitch *s = ST(e, DSwitch);+ char flag[48];+ if (!s->persistent || !level_get_flag(id_flag(flag, "dashSwitch_", s->room, s->eid))) return;+ cs_play(&s->spr, s->mirror ? A_dashSwitch_mirror_pushed : A_dashSwitch_default_pushed, false);+ e->x = s->target.x - SIDE_DIR[s->side][0] * 2, e->y = s->target.y - SIDE_DIR[s->side][1] * 2;+ s->pressed = 1;+ e->collidable = 0;+ if (s->all_gates) {+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o->cls == &GATE && o->dead != 1 && o->room == e->room && ST(o, Gate)->type == TG_NEAREST) gate_start_open(o);+ }+ return;+ }+ Ent *g = dswitch_gate(e);+ if (g) gate_start_open(g);+}+static void dswitch_update(Ent *e) {+ DSwitch *s = ST(e, DSwitch);+ plat_update(e);+ cs_update(&s->spr);+ if (s->pressed || s->side != SIDE_DOWN) return;+ Ent *pe = level_player_ent();+ Player *on = pe && collide_ent_at(e, e->x, e->y - 1, pe) ? level_player() : NULL; /* GetPlayerOnTop */+ if (on) {+ if (on->holding) dswitch_hit(e, on, v2(0, 1));+ else {+ if (s->speed_y < 0) s->speed_y = 0;+ s->speed_y = approach(s->speed_y, 70, 200 * DT);+ plat_move_towards_y(e, s->start_y + 2, s->speed_y * DT);+ }+ } else {+ if (s->speed_y > 0) s->speed_y = 0;+ s->speed_y = approach(s->speed_y, -150, 200 * DT);+ plat_move_towards_y(e, s->start_y, -s->speed_y * DT);+ }+ s = ST(e, DSwitch);+ s->was_on = on != NULL;+}+static void dswitch_render(Ent *e) {+ DSwitch *s = ST(e, DSwitch);+ cs_draw(&s->spr, e->x + SIDE_SPR[s->side][0], e->y + SIDE_SPR[s->side][1], 1, 1, SIDE_ROT[s->side], 0xFFFF, 255);+}+static const EntClass DSWITCH = {.name = "dashSwitch", .size = sizeof(DSwitch), .update = dswitch_update, .render = dswitch_render,+ .awake = dswitch_awake, .on_dash_collide = dswitch_hit, .kind = KIND_SOLID};+static bool is_dswitch(Ent *e) { return e && e->cls == &DSWITCH; }++static void new_dswitch(const EData *d, bool horizontal) {+ int side;+ bool persistent, all;+ const char *spr;+ if (horizontal) {+ side = EAB(d, dashSwitchH, leftSide) ? SIDE_LEFT : SIDE_RIGHT;+ persistent = EAB(d, dashSwitchH, persistent), all = EAB(d, dashSwitchH, allGates), spr = EAS(d, dashSwitchH, sprite);+ } else {+ side = EAB(d, dashSwitchV, ceiling) ? SIDE_UP : SIDE_DOWN;+ persistent = EAB(d, dashSwitchV, persistent), all = EAB(d, dashSwitchV, allGates), spr = EAS(d, dashSwitchV, sprite);+ }+ Ent *e = ent_new(&DSWITCH, d->x, d->y);+ if (!e) return;+ e->safe = 1;+ if (side == SIDE_UP || side == SIDE_DOWN) ent_box(e, 16, 8, 0, 0);+ else ent_box(e, 8, 16, 0, 0);+ DSwitch *s = ST(e, DSwitch);+ s->side = (uint8_t)side, s->persistent = persistent, s->all_gates = all;+ s->mirror = *spr && strcmp(spr, "default") != 0;+ s->room = (uint8_t)d->room, s->eid = (uint16_t)d->id;+ cs_init(&s->spr, s->mirror ? SB_dashSwitch_mirror : SB_dashSwitch_default);+ cs_play(&s->spr, s->mirror ? A_dashSwitch_mirror_idle : A_dashSwitch_default_idle, false);+ s->target = v2(d->x + SIDE_DIR[side][0] * 8, d->y + SIDE_DIR[side][1] * 8);+ s->start_y = d->y;+}+/* ---------------------------------------------------------------- SwapBlock */+typedef struct {+ V2 start, end;+ float lerp, speed, max_fwd, max_back, ret_timer, red_alpha, prem, mid_t;+ uint8_t target, swapping, moon, pad;+ int16_t rx, ry, rw, rh; /* moveRect */+} Swap;+typedef struct { float timer; uint8_t block, pad[3]; } SwapPath;+static uint16_t swap_tex[2][3], swap_path[2], swap_mid[2][2][4]; /* [moon][green, red, target] */+static const EntClass SWAP;++static void swap_on_dash(Ent *e, V2 dir) { /* DashListener.OnDash */+ (void)dir;+ Swap *s = ST(e, Swap);+ s->swapping = s->lerp < 1;+ s->target = 1;+ s->ret_timer = 0.8f;+ if (s->lerp >= 0.2f) s->speed = s->max_fwd;+ else s->speed = lerpf(s->max_fwd * 0.333f, s->max_fwd, s->lerp / 0.2f);+}+static void swap_particles(Ent *e, V2 normal) {+ Swap *s = ST(e, Swap);+ V2 pos, range;+ float dir, num;+ if (normal.x > 0) pos = v2(e_left(e), e_cym(e)), range = v2(0, e->ch - 6), dir = PI_F, num = fmaxf(2, e->ch / 14);+ else if (normal.x < 0) pos = v2(e_right(e), e_cym(e)), range = v2(0, e->ch - 6), dir = 0, num = fmaxf(2, e->ch / 14);+ else if (normal.y > 0) pos = v2(e_cxm(e), e_top(e)), range = v2(e->cw - 6, 0), dir = -PI_F / 2, num = fmaxf(2, e->cw / 14);+ else pos = v2(e_cxm(e), e_bottom(e)), range = v2(e->cw - 6, 0), dir = PI_F / 2, num = fmaxf(2, e->cw / 14);+ s->prem += num;+ int n = (int)s->prem;+ s->prem -= n;+ particles_emit(PL_MID, &P_SwapBlock_P_Move, n, pos, v2mul(range, 0.5f), dir);+}+static void swap_update(Ent *e) {+ Swap *s = ST(e, Swap);+ plat_update(e);+ s->mid_t += DT; /* the middle lights' "idle" loop */+ if (s->ret_timer > 0) {+ s->ret_timer -= DT;+ if (s->ret_timer <= 0) s->target = 0, s->speed = 0;+ }+ s->red_alpha = approach(s->red_alpha, s->target != 1 ? 1 : 0, DT * 32);+ if (s->target == 0 && s->lerp == 0) s->mid_t = 0; /* SetAnimationFrame(0) */+ if (s->target == 1) s->speed = approach(s->speed, s->max_fwd, s->max_fwd / 0.2f * DT);+ else s->speed = approach(s->speed, s->max_back, s->max_back / 1.5f * DT);+ float was = s->lerp;+ s->lerp = approach(s->lerp, s->target, s->speed * DT);+ if (s->lerp != was) {+ V2 d = v2sub(s->end, s->start);+ V2 lift = v2mul(d, s->speed);+ if (s->target == 1) lift = v2mul(d, s->max_fwd);+ if (s->lerp < was) lift = v2mul(lift, -1);+ if (s->target == 1 && level_on_interval(0.02f)) swap_particles(e, d);+ V2 to = v2add(s->start, v2mul(d, s->lerp));+ plat_move_h_lift(e, to.x - (e->x + e->remx), lift.x); /* MoveTo(position, liftSpeed) */+ plat_move_v_lift(e, to.y - (e->y + e->remy), lift.y);+ }+ if (s->swapping && s->lerp >= 1) s->swapping = 0;+}+/* DrawBlockStyle: a nine-slice of 8x8 cells and the middle light */+static void swap_style(V2 pos, float w, float h, uint16_t nine, uint16_t mid, uint8_t alpha) {+ int nw = (int)(w / 8), nh = (int)(h / 8);+ gfx_tex_part(nine, pos.x, pos.y, 0, 0, 8, 8, 0, 0xFFFF, alpha);+ gfx_tex_part(nine, pos.x + w - 8, pos.y, 16, 0, 8, 8, 0, 0xFFFF, alpha);+ gfx_tex_part(nine, pos.x, pos.y + h - 8, 0, 16, 8, 8, 0, 0xFFFF, alpha);+ gfx_tex_part(nine, pos.x + w - 8, pos.y + h - 8, 16, 16, 8, 8, 0, 0xFFFF, alpha);+ for (int i = 1; i < nw - 1; i++) {+ gfx_tex_part(nine, pos.x + i * 8, pos.y, 8, 0, 8, 8, 0, 0xFFFF, alpha);+ gfx_tex_part(nine, pos.x + i * 8, pos.y + h - 8, 8, 16, 8, 8, 0, 0xFFFF, alpha);+ }+ for (int j = 1; j < nh - 1; j++) {+ gfx_tex_part(nine, pos.x, pos.y + j * 8, 0, 8, 8, 8, 0, 0xFFFF, alpha);+ gfx_tex_part(nine, pos.x + w - 8, pos.y + j * 8, 16, 8, 8, 8, 0, 0xFFFF, alpha);+ }+ for (int i = 1; i < nw - 1; i++)+ for (int j = 1; j < nh - 1; j++) gfx_tex_part(nine, pos.x + i * 8, pos.y + j * 8, 8, 8, 8, 8, 0, 0xFFFF, alpha);+ if (mid != 0xFFFF) draw_centered(mid, pos.x + w / 2, pos.y + h / 2, 0xFFFF, alpha, 1, 1, 0);+}+static void swap_render(Ent *e) {+ Swap *s = ST(e, Swap);+ V2 pos = v2(e->x + e->shakex, e->y + e->shakey);+ int f = (int)floorf(s->mid_t / 0.08f) % 4;+ if (s->lerp != s->target && s->speed > 0) {+ V2 dir = safe_norm(v2sub(s->end, s->start), 1);+ if (s->target == 1) dir = v2mul(dir, -1);+ float num2 = 16 * (s->speed / s->max_fwd);+ for (int i = 2; i < num2; i += 2)+ swap_style(v2add(pos, v2mul(dir, (float)i)), e->cw, e->ch, swap_tex[s->moon][0], swap_mid[s->moon][0][f], a8(1 - i / num2));+ }+ if (s->red_alpha < 1) swap_style(pos, e->cw, e->ch, swap_tex[s->moon][0], swap_mid[s->moon][0][f], 255);+ if (s->red_alpha > 0) swap_style(pos, e->cw, e->ch, swap_tex[s->moon][1], swap_mid[s->moon][1][f], a8(s->red_alpha));+}+static const EntClass SWAP = {.name = "swapBlock", .size = sizeof(Swap), .update = swap_update, .render = swap_render,+ .on_dash = swap_on_dash, .kind = KIND_SOLID};++static void swappath_update(Ent *e) { ST(e, SwapPath)->timer += DT * 4; }+static void swappath_render(Ent *e) {+ SwapPath *p = ST(e, SwapPath);+ Ent *b = ent_at(p->block);+ if (!b->cls || b->cls != &SWAP) return;+ Swap *s = ST(b, Swap);+ if (!s->moon) {+ uint16_t t = swap_path[s->start.x == s->end.x ? 1 : 0];+ for (int i = s->rx; i < s->rx + s->rw; i += 16)+ for (int j = s->ry; j < s->ry + s->rh; j += 16)+ gfx_tex_part(t, (float)i, (float)j, 0, 0, s->rx + s->rw - i < 16 ? s->rx + s->rw - i : 16,+ s->ry + s->rh - j < 16 ? s->ry + s->rh - j : 16, 0, 0xFFFF, 255);+ }+ float num = 0.5f * (0.5f + (sinf(p->timer) + 1) * 0.25f);+ swap_style(v2(s->rx, s->ry), s->rw, s->rh, swap_tex[s->moon][2], 0xFFFF, a8(num));+}+static const EntClass SWAPPATH = {.name = "swapBlockPath", .size = sizeof(SwapPath), .update = swappath_update, .render = swappath_render};++static void new_swap(const EData *d) {+ float w = EA(d, swapBlock, width), h = EA(d, swapBlock, height);+ Ent *e = ent_new(&SWAP, d->x, d->y);+ if (!e) return;+ ent_box(e, w, h, 0, 0);+ e->depth = -9999;+ Swap *s = ST(e, Swap);+ s->moon = !strcmp(EAS(d, swapBlock, theme), "Moon");+ s->start = v2(d->x, d->y);+ s->end = ed_node(d, 0);+ s->max_fwd = 360 / v2len(v2sub(s->start, s->end));+ s->max_back = s->max_fwd * 0.4f;+ s->red_alpha = 1;+ int x0 = (int)fminf(d->x, s->end.x), y0 = (int)fminf(d->y, s->end.y);+ int x1 = (int)fmaxf(d->x + w, s->end.x + w), y1 = (int)fmaxf(d->y + h, s->end.y + h);+ s->rx = (int16_t)x0, s->ry = (int16_t)y0, s->rw = (int16_t)(x1 - x0), s->rh = (int16_t)(y1 - y0);+ if (!swap_tex[0][0]) {+ swap_tex[0][0] = tex_named("objects/swapblock/block");+ swap_tex[0][1] = tex_named("objects/swapblock/blockRed");+ swap_tex[0][2] = tex_named("objects/swapblock/target");+ swap_tex[1][0] = tex_named("objects/swapblock/moon/block");+ swap_tex[1][1] = tex_named("objects/swapblock/moon/blockRed");+ swap_tex[1][2] = tex_named("objects/swapblock/moon/target");+ swap_path[0] = tex_named("objects/swapblock/pathH");+ swap_path[1] = tex_named("objects/swapblock/pathV");+ tex_family("objects/swapblock/midBlock", swap_mid[0][0], 4);+ tex_family("objects/swapblock/midBlockRed", swap_mid[0][1], 4);+ tex_family("objects/swapblock/moon/midBlock", swap_mid[1][0], 4);+ tex_family("objects/swapblock/moon/midBlockRed", swap_mid[1][1], 4);+ }+ Ent *p = ent_new(&SWAPPATH, d->x, d->y); /* Awake: the PathRenderer */+ if (p) {+ p->depth = 8999;+ p->collidable = 0;+ ST(p, SwapPath)->block = ent_ref(e);+ ST(p, SwapPath)->timer = rndf();+ }+}++/* ---------------------------------------------------------------- TempleCrackedBlock */+typedef struct { uint8_t w, h, persistent, broken; uint32_t hash; float frame; } Cracked;+static uint16_t cracked_tex[10];+static const EntClass CRACKED;+static void cracked_break(Ent *e, V2 from) {+ Cracked *c = ST(e, Cracked);+ if (c->broken) return;+ if (c->persistent) level_set_do_not_load(c->hash);+ c->broken = 1;+ e->collidable = 0;+ int w = c->w, h = c->h;+ float x = e->x, y = e->y;+ for (int i = 0; i < w; i++)+ for (int j = 0; j < h; j++) level_debris(x + i * 8 + 4, y + j * 8 + 4, '1', from);+}+static void cracked_awake(Ent *e) {+ Cracked *c = ST(e, Cracked);+ Ent *pe = level_player_ent();+ if (pe && collide_ent_at(e, e->x, e->y, pe)) { /* Added: CollideCheck<Player> */+ if (c->persistent) level_set_do_not_load(c->hash);+ ent_remove(e);+ } else+ e->collidable = e->visible = 1;+}+static void cracked_update(Ent *e) {+ Cracked *c = ST(e, Cracked);+ plat_update(e);+ if (c->broken) {+ c->frame += DT * 15;+ if (c->frame >= 10) ent_remove(e);+ }+}+static int cracked_tile(int i, int n) { /* the cell of the 48x48 picture for tile i of n */+ return (i < n / 2 && i < 2) ? i : (i < n / 2 || i < n - 2) ? 2 + i % 2 : 5 - (n - i - 1);+}+static void cracked_render(Ent *e) {+ Cracked *c = ST(e, Cracked);+ int f = (int)c->frame;+ if (f >= 10) return;+ for (int i = 0; i < c->w; i++)+ for (int j = 0; j < c->h; j++)+ gfx_tex_part(fam_tex(cracked_tex, 10, f), e->x + i * 8, e->y + j * 8, cracked_tile(i, c->w) * 8, cracked_tile(j, c->h) * 8, 8, 8, 0,+ 0xFFFF, 255);+}+static const EntClass CRACKED = {.name = "templeCrackedBlock", .size = sizeof(Cracked), .update = cracked_update,+ .render = cracked_render, .awake = cracked_awake, .kind = KIND_SOLID};+static void new_cracked(const EData *d) {+ uint32_t h = level_entity_hash(d);+ if (level_do_not_load(h)) return;+ float w = EA(d, templeCrackedBlock, width), ht = EA(d, templeCrackedBlock, height);+ Ent *e = ent_new(&CRACKED, d->x, d->y);+ if (!e) return;+ ent_box(e, w, ht, 0, 0);+ e->safe = 1;+ e->collidable = e->visible = 0;+ Cracked *c = ST(e, Cracked);+ c->w = (uint8_t)(w / 8), c->h = (uint8_t)(ht / 8);+ c->persistent = EAB(d, templeCrackedBlock, persistent);+ c->hash = h;+ if (!cracked_tex[0]) tex_family("objects/temple/breakBlock", cracked_tex, 10);+}++/* ---------------------------------------------------------------- SeekerBarrier and its renderer */+typedef struct { float flash, solidify, delay, ptime; uint16_t seed; uint8_t flashing, pad; } Barrier;+static const EntClass BARRIER;+static bool barrier_dirty;+static void barrier_reflect(Ent *e) { /* OnReflectSeeker */+ Barrier *b = ST(e, Barrier);+ b->flash = b->solidify = b->delay = 1;+ b->flashing = 1;+ float l = e->x, t = e->y, r = e->x + e->cw, bt = e->y + e->ch;+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o == e || o->cls != &BARRIER || o->dead == 1) continue;+ bool adj = collide_rect(o, (float)(int)l, (float)(int)t - 2, (float)(int)l + (int)e->cw, (float)(int)t - 2 + (int)e->ch + 4) ||+ collide_rect(o, (float)(int)l - 2, (float)(int)t, (float)(int)l - 2 + (int)e->cw + 4, (float)(int)t + (int)e->ch);+ (void)r, (void)bt;+ if (adj && !ST(o, Barrier)->flashing) barrier_reflect(o);+ }+}+static void barrier_update(Ent *e) {+ Barrier *b = ST(e, Barrier);+ if (b->flashing) {+ b->flash = approach(b->flash, 0, DT * 4);+ if (b->flash <= 0) b->flashing = 0;+ } else if (b->delay > 0)+ b->delay -= DT;+ else if (b->solidify > 0)+ b->solidify = approach(b->solidify, 0, DT);+ b->ptime += DT; /* the particles fall: their places come from the seed and the time */+ plat_update(e);+}+static void barrier_removed(Ent *e) {+ (void)e;+ barrier_dirty = true;+}+static const EntClass BARRIER = {.name = "seekerBarrier", .size = sizeof(Barrier), .update = barrier_update,+ .removed = barrier_removed, .kind = KIND_SOLID};+static void barriers_collidable(bool on) {+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &BARRIER && g_ents[i].dead != 1) g_ents[i].collidable = on;+}++#define MAX_EDGES 40+typedef struct {+ Ent *parent;+ int16_t ax, ay, len;+ int8_t nx, ny, px, py;+ uint8_t visible, pad;+ float wave_t, wave_sol; /* UpdateWave's time and the parent's Solidify then; -1: no wave yet */+} BEdge;+enum { OFF_edges = ((END_eyes + 7) & ~7), END_edges = OFF_edges + (int)sizeof(BEdge[MAX_EDGES]) };+#define edges (*(BEdge(*)[MAX_EDGES])(void *)(g_chram[5] + OFF_edges))+static int nedges;+static bool barrier_inside(int tx, int ty) {+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o->cls != &BARRIER || o->dead == 1) continue;+ if (tx >= (int)o->x / 8 && tx * 8 < o->x + o->cw && ty >= (int)o->y / 8 && ty * 8 < o->y + o->ch) return true;+ }+ return false;+}+static void edges_rebuild(void) { /* RebuildEdges */+ barrier_dirty = false;+ nedges = 0;+ static const int8_t DIRS[4][2] = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};+ for (int k = 0; k < g_nents; k++) {+ Ent *it = &g_ents[k];+ if (it->cls != &BARRIER || it->dead == 1) continue;+ for (int i = (int)it->x / 8; i < (it->x + it->cw) / 8; i++)+ for (int j = (int)it->y / 8; j < (it->y + it->ch) / 8; j++)+ for (int d = 0; d < 4; d++) {+ int vx = DIRS[d][0], vy = DIRS[d][1], px = -vy, py = vx;+ if (barrier_inside(i + vx, j + vy) || (barrier_inside(i - px, j - py) && !barrier_inside(i + vx - px, j + vy - py)))+ continue;+ int bx = i + px, by = j + py;+ V2 off = v2(4 + (vx - px) * 4.f, 4 + (vy - py) * 4.f);+ while (barrier_inside(bx, by) && !barrier_inside(bx + vx, by + vy)) bx += px, by += py;+ if (nedges >= MAX_EDGES) return;+ BEdge *ed = &edges[nedges++];+ V2 a = v2sub(v2add(v2(i * 8.f, j * 8.f), off), v2(it->x, it->y));+ V2 b = v2sub(v2add(v2(bx * 8.f, by * 8.f), off), v2(it->x, it->y));+ V2 n = safe_norm(v2sub(b, a), 1);+ ed->parent = it;+ ed->ax = (int16_t)a.x, ed->ay = (int16_t)a.y;+ ed->len = (int16_t)v2len(v2sub(a, b));+ ed->nx = (int8_t)n.x, ed->ny = (int8_t)n.y;+ ed->px = (int8_t)n.y, ed->py = (int8_t)-n.x; /* -Normal.Perpendicular() */+ ed->visible = 1;+ ed->wave_t = -1;+ }+ }+}+static float edge_wave(const BEdge *ed, int along) { /* GetWaveAt */+ float len = ed->len;+ if (along <= 1 || along >= len - 1) return 0;+ if (ed->wave_sol >= 1) return 0;+ float num = ed->wave_t + along * 0.25f;+ float num2 = sinf(num) * 2 + sinf(num * 0.25f);+ float yo = along / len;+ yo = yo <= .5f ? yo * 2 : 1 - (yo - .5f) * 2;+ return (1 + num2 * ease_sine_inout(yo)) * (1 - ed->wave_sol);+}+typedef struct { uint8_t pad; } BRenderer;+static void brender_update(Ent *e) {+ (void)e;+ if (barrier_dirty) edges_rebuild();+ float l = g_level.cam.x - 4, t = g_level.cam.y - 4, r = l + 328, b = t + 188;+ for (int i = 0; i < nedges; i++) {+ BEdge *ed = &edges[i];+ if (!ed->parent->cls) continue;+ float x0 = ed->parent->x + fminf(ed->ax, ed->ax + ed->nx * ed->len), x1 = ed->parent->x + fmaxf(ed->ax, ed->ax + ed->nx * ed->len);+ float y0 = ed->parent->y + fminf(ed->ay, ed->ay + ed->ny * ed->len), y1 = ed->parent->y + fmaxf(ed->ay, ed->ay + ed->ny * ed->len);+ bool in = l < x1 && r > x0 && t < y1 && b > y0;+ if (ed->visible) {+ if (on_interval_off(0.25f, i * 0.01f) && !in) ed->visible = 0;+ } else if (on_interval_off(0.05f, i * 0.01f) && in)+ ed->visible = 1;+ if (ed->visible && (on_interval_off(0.05f, i * 0.01f) || ed->wave_t < 0)) {+ ed->wave_t = g_level.time_active * 3;+ ed->wave_sol = ST(ed->parent, Barrier)->solidify;+ }+ }+}+static inline void px_blend(uint16_t *strip, int y0, int y1, int vx, int vy, uint16_t c, int a) {+ if ((unsigned)vx >= VIEW_W || vy < y0 || vy >= y1) return;+ uint16_t *d = strip + (vy - y0) * VIEW_W + vx;+ *d = blend565(*d, scale565(c, a), a);+}+static void fill_blend(uint16_t *strip, int y0, int y1, int x, int y, int w, int h, uint16_t c, int a) {+ int xa = x < 0 ? 0 : x, xb = x + w > VIEW_W ? VIEW_W : x + w, ya = y < y0 ? y0 : y, yb = y + h > y1 ? y1 : y + h;+ uint16_t s = scale565(c, a);+ for (int r = ya; r < yb; r++) {+ uint16_t *d = strip + (r - y0) * VIEW_W + xa;+ for (int i = xa; i < xb; i++, d++) *d = blend565(*d, s, a);+ }+}+/* a little hash: the particles' places (Calc.Random.NextFloat at construction) */+static float hash01(uint32_t seed, uint32_t i) {+ uint32_t h = seed * 0x9E3779B1u ^ (i + 0x7F4A7C15u) * 0x85EBCA6Bu;+ h ^= h >> 15, h *= 0x2C1B3C6Du, h ^= h >> 12, h *= 0x297A2D39u, h ^= h >> 15;+ return (h >> 8) / 16777216.f;+}+static void brender_strip(uint16_t *strip, int y0, int y1, void *ctx) {+ (void)ctx;+ int cx = g_camx, cy = g_camy;+ /* the renderer: the fills and the waving edges, white at 0.15 */+ for (int k = 0; k < g_nents; k++) {+ Ent *b = &g_ents[k];+ if (b->cls == &BARRIER && b->dead != 1 && b->visible)+ fill_blend(strip, y0, y1, (int)b->x - cx, (int)b->y - cy, (int)b->cw, (int)b->ch, 0xFFFF, 38);+ }+ for (int i = 0; i < nedges; i++) {+ BEdge *ed = &edges[i];+ if (!ed->visible || !ed->parent->cls || ed->wave_t < 0) continue;+ int ax = (int)ed->parent->x + ed->ax - cx, ay = (int)ed->parent->y + ed->ay - cy;+ for (int j = 0; j <= ed->len; j++) {+ int x = ax + ed->nx * j, y = ay + ed->ny * j;+ /* Draw.Line(p, p + Perpendicular * wave): a 1-pixel rect turned towards the line */+ float w = edge_wave(ed, j);+ int n = (int)floorf(fabsf(w) + 0.5f), dx = ed->px * sgn(w), dy = ed->py * sgn(w);+ for (int s = 0; s < n; s++) {+ if (dx > 0) px_blend(strip, y0, y1, x + s, y, 0xFFFF, 38);+ else if (dx < 0) px_blend(strip, y0, y1, x - 1 - s, y - 1, 0xFFFF, 38);+ else if (dy > 0) px_blend(strip, y0, y1, x - 1, y + s, 0xFFFF, 38);+ else px_blend(strip, y0, y1, x, y - 1 - s, 0xFFFF, 38);+ }+ }+ }+ /* each barrier: its falling particles (white 0.5), the flash */+ static const float SPEEDS[3] = {12, 20, 40};+ for (int k = 0; k < g_nents; k++) {+ Ent *b = &g_ents[k];+ if (b->cls != &BARRIER || b->dead == 1 || !b->visible) continue;+ Barrier *br = ST(b, Barrier);+ int n = (int)ceilf(b->cw * b->ch / 16);+ if ((int)b->y - cy > y1 || (int)(b->y + b->ch) - cy < y0) continue;+ for (int i = 0; i < n; i++) {+ float x = hash01(br->seed, 2 * i) * (b->cw - 1), y = hash01(br->seed, 2 * i + 1) * (b->ch - 1);+ y = fmodf(y + SPEEDS[i % 3] * br->ptime, b->ch - 1);+ px_blend(strip, y0, y1, (int)floorf(b->x + x + 0.5f) - cx, (int)floorf(b->y + y + 0.5f) - cy, 0xFFFF, 128);+ }+ if (br->flashing) fill_blend(strip, y0, y1, (int)b->x - cx, (int)b->y - cy, (int)b->cw, (int)b->ch, 0xFFFF, (int)(br->flash * 128));+ }+}+static void brender_render(Ent *e) {+ (void)e;+ gfx_custom(brender_strip, NULL, 0, VIEW_H);+}+static const EntClass BRENDERER = {.name = "seekerBarrierRenderer", .size = sizeof(BRenderer), .update = brender_update,+ .render = brender_render};+static void new_barrier(const EData *d) {+ if (!first_of(&BRENDERER)) {+ Ent *r = ent_new(&BRENDERER, 0, 0);+ if (!r) return;+ r->tags = TAG_GLOBAL | TAG_TRANSITION_UPDATE;+ r->collidable = 0;+ r->depth = 0;+ }+ Ent *e = ent_new(&BARRIER, d->x, d->y);+ if (!e) return;+ ent_box(e, EA(d, seekerBarrier, width), EA(d, seekerBarrier, height), 0, 0);+ e->collidable = 0;+ Barrier *b = ST(e, Barrier);+ b->seed = (uint16_t)(rndi(65536));+ barrier_dirty = true;+}++/* ---------------------------------------------------------------- ConditionBlock: an ExitBlock when its condition holds */+static void put_attr(uint8_t *b, int off, char kind, float v) {+ switch (kind) {+ case 'b': b[off] = v != 0; break;+ case 'i': {+ int16_t x = (int16_t)v;+ memcpy(b + off, &x, 2);+ break;+ }+ case 'I': {+ int32_t x = (int32_t)v;+ memcpy(b + off, &x, 4);+ break;+ }+ case 'f': memcpy(b + off, &v, 4); break;+ }+}+static void new_condition(const EData *d) {+ const char *mode = EAS(d, conditionBlock, condition), *cid = EAS(d, conditionBlock, conditionID);+ const char *colon = strchr(cid, ':');+ if (!colon) return;+ int room = room_index(cid, (int)(colon - cid)), id = atoi(colon + 1);+ bool ok = false;+ if (!strcmp(mode, "Button")) {+ char flag[48];+ path2(flag, "dashSwitch_", cid, -1);+ ok = level_get_flag(flag);+ } else if (!strcmp(mode, "Strawberry")) { /* Session.Strawberries */+ int k = room >= 0 ? session_berry_index(room, id) : -1;+ ok = k >= 0 && (g_session.berries >> k & 1);+ } else /* Key */+ ok = room >= 0 && level_do_not_load(level_entity_id(room, id));+ if (!ok) return;+ uint8_t attrs[EA_exitBlock__size + 4];+ memset(attrs, 0, sizeof attrs);+ put_attr(attrs, EA_exitBlock_width, EK_exitBlock_width, EA(d, conditionBlock, width));+ put_attr(attrs, EA_exitBlock_height, EK_exitBlock_height, EA(d, conditionBlock, height));+ memcpy(attrs + EA_exitBlock_tileType, d->attrs + EA_conditionBlock_tileType, 2);+ EData x = *d;+ x.type = ET_exitBlock;+ x.attrs = attrs;+ x.nnodes = 0;+ ent_create(&x);+}++/* ---------------------------------------------------------------- TempleMirror */+typedef struct { int16_t w, h; int8_t rx, ry; } Mirror;+/* a sprite (scale 1 or -1) drawn inside [l, r) x [t, b) only */+static void spr_draw_clip(const Sprite *s, float x, float y, float l, float t, float r, float b, uint8_t alpha) {+ uint16_t tex = spr_tex(s);+ if (tex == 0xFFFF) return;+ if (!res_cached(tex)) { /* the animation's frames, in one pass (as spr_draw) */+ uint16_t ids[32], gotos[8];+ int ng, a = s->anim != 255 ? s->anim : s->last_goto;+ if (a >= 0) res_load(ids, bank_anim_textures(s->bank, a, ids, 32, gotos, &ng));+ }+ Tex tx;+ if (!tex_get(tex, &tx)) return;+ float ox = s->justify ? tx.fw * tx.scale * s->jx : s->ox, oy = s->justify ? tx.fh * tx.scale * s->jy : s->oy;+ bool flip = s->sx < 0;+ float L = floorf(x - (flip ? tx.fw - ox : ox)), T = floorf(y - oy);+ int u0, u1;+ if (!flip) u0 = (int)ceilf(l - L), u1 = (int)ceilf(r - L);+ else u0 = (int)ceilf(L + tx.fw - r), u1 = (int)ceilf(L + tx.fw - l);+ int v0 = (int)ceilf(t - T), v1 = (int)ceilf(b - T);+ u0 = clampi(u0, 0, tx.fw), u1 = clampi(u1, 0, tx.fw), v0 = clampi(v0, 0, tx.fh), v1 = clampi(v1, 0, tx.fh);+ if (u1 <= u0 || v1 <= v0) return;+ gfx_tex_part(tex, flip ? L + tx.fw - u1 : L + u0, T + v0, u0, v0, u1 - u0, v1 - v0, flip ? GF_FLIPX : 0, s->tint, alpha);+}+static void mirror_render(Ent *e) {+ Mirror *m = ST(e, Mirror);+ gfx_rect(e->x + 3, e->y + 3, m->w - 6, m->h - 6, rgb(0x05070E), 255);+ /* MirrorSurfaces (depth 9490): what has a MirrorReflection, seen at its place less the surface's ReflectionOffset,+ * inside the surface (x + 2, y + 2, w - 4, h - 4), at half alpha. The NPCs' (Madeline's own is not drawn) */+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (!o->cls || o->dead == 1 || strcmp(o->cls->name, "npc")) continue;+ Npc *n = NPC_(o);+ spr_draw_clip(&n->spr, o->x - m->rx, o->y - m->ry, e->x + 2, e->y + 2, e->x + m->w - 2, e->y + m->h - 2, n->spr.alpha / 2);+ }+}+static void mirrorframe_render(Ent *e) { /* Frame: scenery/templemirror as a nine-slice */+ Mirror *m = ST(e, Mirror);+ uint16_t t = T_scenery_templemirror;+ float x = e->x, y = e->y, w = m->w, h = m->h;+ gfx_tex_part(t, x, y, 0, 0, 8, 8, 0, 0xFFFF, 255);+ gfx_tex_part(t, x + w - 8, y, 16, 0, 8, 8, 0, 0xFFFF, 255);+ gfx_tex_part(t, x, y + h - 8, 0, 16, 8, 8, 0, 0xFFFF, 255);+ gfx_tex_part(t, x + w - 8, y + h - 8, 16, 16, 8, 8, 0, 0xFFFF, 255);+ for (int i = 1; i < w / 8 - 1; i++) {+ gfx_tex_part(t, x + i * 8, y, 8, 0, 8, 8, 0, 0xFFFF, 255);+ gfx_tex_part(t, x + i * 8, y + h - 8, 8, 16, 8, 8, 0, 0xFFFF, 255);+ }+ for (int j = 1; j < h / 8 - 1; j++) {+ gfx_tex_part(t, x, y + j * 8, 0, 8, 8, 8, 0, 0xFFFF, 255);+ gfx_tex_part(t, x + w - 8, y + j * 8, 16, 8, 8, 8, 0, 0xFFFF, 255);+ }+}+static const EntClass MIRROR = {.name = "templeMirror", .size = sizeof(Mirror), .render = mirror_render};+static const EntClass MIRRORFRAME = {.name = "templeMirrorFrame", .size = sizeof(Mirror), .render = mirrorframe_render};+static void new_mirror(const EData *d) {+ int w = (int)EA(d, templeMirror, width), h = (int)EA(d, templeMirror, height);+ Ent *e = ent_new(&MIRROR, d->x, d->y);+ if (!e) return;+ e->depth = 9500;+ ent_box(e, (float)w, (float)h, 0, 0);+ e->collidable = 0;+ ST(e, Mirror)->w = (int16_t)w, ST(e, Mirror)->h = (int16_t)h;+ ST(e, Mirror)->rx = (int8_t)EA(d, templeMirror, reflectX), ST(e, Mirror)->ry = (int8_t)EA(d, templeMirror, reflectY);+ Ent *f = ent_new(&MIRRORFRAME, d->x, d->y);+ if (!f) return;+ f->depth = 8995;+ f->collidable = 0;+ ST(f, Mirror)->w = (int16_t)w, ST(f, Mirror)->h = (int16_t)h;+}+/* ---------------------------------------------------------------- TheoCrystal (Holdable) */+typedef struct {+ ActorExt ext;+ V2 speed, prev_lift, prev_pos;+ float no_grav, swat_timer, hard_cool, gravity_timer, cannot_hold, death_t, co_wait, co_p;+ CSpr spr;+ int32_t idle_depth;+ uint8_t held, on_pedestal, dead, shattering, co, hit_seeker, pad[2]; /* hit_seeker: an entity, 255 none */+} Theo;+static Ent *theo_entity(void) { return first_of(&THEO); }+static void theo_die(Ent *e);+static void seeker_on_holdable(Ent *s, Ent *theo);+static bool seeker_hits_holdable(Ent *s, Ent *theo);+static void bigeye_on_holdable(Ent *b, Ent *theo);+static const EntClass SEEKER, BIGEYE;++static void theo_impact(Ent *e, V2 dir) { /* ImpactParticles */+ float a;+ V2 at, range;+ if (dir.x > 0) a = PI_F, at = v2(e_right(e), e->y - 4), range = v2(0, 6);+ else if (dir.x < 0) a = 0, at = v2(e_left(e), e->y - 4), range = v2(0, 6);+ else if (dir.y > 0) a = -PI_F / 2, at = v2(e->x, e_bottom(e)), range = v2(6, 0);+ else a = PI_F / 2, at = v2(e->x, e_top(e)), range = v2(6, 0);+ particles_emit(PL_MID, &P_TheoCrystal_P_Impact, 12, at, range, a);+}+static void theo_collide_h(Ent *e, Collision *c) {+ Theo *t = ST(e, Theo);+ if (is_dswitch(c->hit)) dswitch_hit(c->hit, NULL, v2((float)sgn(t->speed.x), 0));+ if (fabsf(t->speed.x) > 100) theo_impact(e, c->dir);+ t->speed.x *= -0.4f;+}+static void theo_collide_v(Ent *e, Collision *c) {+ Theo *t = ST(e, Theo);+ if (is_dswitch(c->hit)) dswitch_hit(c->hit, NULL, v2(0, (float)sgn(t->speed.y)));+ if (t->speed.y > 0) {+ if (t->hard_cool <= 0) t->hard_cool = 0.5f;+ }+ if (t->speed.y > 160) theo_impact(e, c->dir);+ if (t->speed.y > 140 && !(c->hit && c->hit->cls == &SWAP) && !is_dswitch(c->hit)) t->speed.y *= -0.6f;+ else t->speed.y = 0;+}+static bool theo_riding(Ent *e, Ent *s) { return ST(e, Theo)->speed.y == 0 && collide_ent_at(e, e->x, e->y + 1, s); }+static void theo_squish(Ent *e, Collision *c) {+ if (!actor_try_squish_wiggle(e, c)) theo_die(e);+}+static void theo_die(Ent *e) {+ Theo *t = ST(e, Theo);+ if (t->dead) return;+ t->dead = 1;+ Player *p = level_player();+ if (p) player_die(p, v2((float)-p->facing, 0), false);+ t->death_t = 0;+ e->depth = -1000000;+ ents_mark_unsorted();+ e->allow_pushing = 0;+}+/* Holdable.Release */+static void theo_release(Ent *e, V2 force) {+ Theo *t = ST(e, Theo);+ if (collide_solid(e, e->x, e->y)) {+ if (force.x != 0) {+ bool ok = false;+ int s = sgn(force.x), n = 0;+ while (!ok && n++ < 10)+ if (!collide_solid(e, e->x + s * n, e->y)) ok = true;+ if (ok) e->x += s * n;+ }+ while (collide_solid(e, e->x, e->y)) e->y += 1;+ }+ e->depth = t->idle_depth;+ ents_mark_unsorted();+ t->held = 0;+ t->gravity_timer = 0.1f;+ t->cannot_hold = 0.1f;+ /* OnRelease */+ e->tags &= (uint8_t)~TAG_PERSISTENT;+ e->room = (uint8_t)g_level.room_slot; /* it belongs to the room it is dropped in */+ if (force.x != 0 && force.y == 0) force.y = -0.4f;+ t->speed = v2mul(force, 200);+ if (t->speed.x != 0 || t->speed.y != 0) t->no_grav = 0.1f;+}+/* Player.Swat */+static void theo_swat(Ent *e, Ent *seeker, int dir) {+ Theo *t = ST(e, Theo);+ if (!t->held || t->hit_seeker != 255) return;+ t->swat_timer = 0.1f;+ t->hit_seeker = ent_ref(seeker);+ Player *p = level_player();+ if (p && p->holding == e) {+ p->holding = NULL;+ theo_release(e, v2(0.8f * dir, -0.25f));+ }+}+static bool theo_dangerous(Ent *e, Ent *hc) {+ Theo *t = ST(e, Theo);+ return !t->held && (t->speed.x != 0 || t->speed.y != 0) && t->hit_seeker != ent_ref(hc);+}+static void theo_explode_launch(Ent *e, V2 from) {+ Theo *t = ST(e, Theo);+ if (!t->held) t->speed = safe_norm(v2sub(theo_center(e), from), 120); /* SlashFx.Burst: not drawn */+}+/* Spring.OnHoldable -> TheoCrystal.HitSpring (springs are entities.c's: their shape tells the side) */+static void theo_springs(Ent *e) {+ Theo *t = ST(e, Theo);+ if (t->held) return;+ for (int i = 0; i < g_nents; i++) {+ Ent *s = &g_ents[i];+ if (!s->cls || s->dead == 1 || !s->collidable || strcmp(s->cls->name, "spring") || !collide_ent_at(e, e->x, e->y, s)) continue;+ if (s->cw == 16) { /* Floor */+ if (t->speed.y >= 0) t->speed.x *= 0.5f, t->speed.y = -160, t->no_grav = 0.15f;+ } else if (s->cx == 0) { /* WallLeft */+ if (t->speed.x <= 0) {+ actor_move_towards_y(e, e_cym(s) + 5, 4, NULL);+ t->speed = v2(220, -80), t->no_grav = 0.1f;+ }+ } else if (t->speed.x >= 0) { /* WallRight */+ actor_move_towards_y(e, e_cym(s) + 5, 4, NULL);+ t->speed = v2(-220, -80), t->no_grav = 0.1f;+ }+ }+}+static void theo_update(Ent *e) {+ Theo *t = ST(e, Theo);+ /* Actor: LiftSpeedGraceTime is 0.1 for Theo */+ if (t->ext.lift_timer > 0.1f) t->ext.lift_timer -= 0.06f;+ actor_update_lift(e);+ /* Holdable.Update */+ if (t->cannot_hold > 0) t->cannot_hold -= DT;+ if (t->gravity_timer > 0) t->gravity_timer -= DT;+ cs_update(&t->spr);+ if (t->dead) { /* the DeathEffect */+ t->death_t = approach(t->death_t, 1, DT / 0.834f);+ return;+ }+ if (t->shattering) { /* Shatter() */+ switch (t->co) {+ case 0:+ if (t->co_p < 1) {+ e->x += t->speed.x * (1 - t->co_p) * DT, e->y += t->speed.y * (1 - t->co_p) * DT;+ t->co_p += DT;+ break;+ }+ t->co = 1, t->co_wait = 0.5f;+ /* fall through */+ case 1:+ if ((t->co_wait -= DT) > 0) break;+ level_shake(0.3f);+ cs_play(&t->spr, A_theo_crystal_shatter, false);+ t->co = 2, t->co_wait = 1;+ break;+ case 2:+ if ((t->co_wait -= DT) > 0) break;+ level_shake(0.3f);+ t->co = 3;+ break;+ }+ return;+ }+ if (t->swat_timer > 0) t->swat_timer -= DT;+ t->hard_cool -= DT;+ if (t->on_pedestal) {+ if (e->depth != 8999) e->depth = 8999, ents_mark_unsorted();+ return;+ }+ if (e->depth != 100 && !t->held) e->depth = 100, ents_mark_unsorted();+ Room *rm = g_level.room;+ if (t->held)+ t->prev_lift = v2(0, 0);+ else {+ if (actor_on_ground(e, 1)) {+ float target = !actor_on_ground_at(e, e->x + 3, e->y, 1) ? 20 : actor_on_ground_at(e, e->x - 3, e->y, 1) ? 0 : -20;+ t->speed.x = approach(t->speed.x, target, 800 * DT);+ V2 lift = actor_lift(e);+ if (lift.x == 0 && lift.y == 0 && (t->prev_lift.x != 0 || t->prev_lift.y != 0)) {+ t->speed = t->prev_lift;+ t->prev_lift = v2(0, 0);+ t->speed.y = fminf(t->speed.y * 0.6f, 0);+ if (t->speed.x != 0 && t->speed.y == 0) t->speed.y = -60;+ if (t->speed.y < 0) t->no_grav = 0.15f;+ } else {+ t->prev_lift = lift;+ if (lift.y < 0 && t->speed.y < 0) t->speed.y = 0;+ }+ } else if (t->gravity_timer <= 0) { /* Hold.ShouldHaveGravity */+ float g = 800, f = 350;+ if (fabsf(t->speed.y) <= 30) g *= 0.5f;+ if (t->speed.y < 0) f *= 0.5f;+ t->speed.x = approach(t->speed.x, 0, f * DT);+ if (t->no_grav > 0) t->no_grav -= DT;+ else t->speed.y = approach(t->speed.y, 200, g * DT);+ }+ t->prev_pos = plat_exact(e);+ actor_move_h(e, t->speed.x * DT, theo_collide_h, NULL);+ actor_move_v(e, ST(e, Theo)->speed.y * DT, theo_collide_v, NULL);+ t = ST(e, Theo);+ if (e->x > rm->x + rm->w) {+ actor_move_h(e, 32 * DT, NULL, NULL);+ if (e_left(e) - 8 > rm->x + rm->w) {+ ent_remove(e);+ return;+ }+ } else if (e_left(e) < rm->x) {+ e->x += rm->x - e_left(e);+ t->speed.x *= -0.4f;+ } else if (e_top(e) < rm->y - 4) {+ e->y += rm->y + 4 - e_top(e);+ t->speed.y = 0;+ } else if (e_top(e) > rm->y + rm->h)+ theo_die(e);+ if (e->x < rm->x + 10) actor_move_h(e, 32 * DT, NULL, NULL);+ Ent *pe = level_player_ent();+ Ent *gate = NULL; /* CollideFirst<TempleGate> */+ for (int i = 0; i < g_nents && !gate; i++)+ if (g_ents[i].cls == &GATE && g_ents[i].dead != 1 && g_ents[i].collidable && collide_ent_at(e, e->x, e->y, &g_ents[i]))+ gate = &g_ents[i];+ if (gate && pe) {+ gate->collidable = 0;+ actor_move_h(e, (float)(sgn(pe->x - e->x) * 32) * DT, NULL, NULL);+ gate->collidable = 1;+ }+ }+ t = ST(e, Theo);+ if (!t->dead) { /* Hold.CheckAgainstColliders */+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (!o->cls || o->dead == 1) continue;+ if (o->cls == &SEEKER && seeker_hits_holdable(o, e)) seeker_on_holdable(o, e);+ else if (o->cls == &BIGEYE && collide_ent_at(e, e->x, e->y, o)) bigeye_on_holdable(o, e);+ }+ theo_springs(e);+ }+ t = ST(e, Theo);+ if (t->hit_seeker != 255 && t->swat_timer <= 0) {+ Ent *hs = ent_at(t->hit_seeker);+ if (!(hs->cls == &SEEKER && hs->dead != 1 && seeker_hits_holdable(hs, e))) t->hit_seeker = 255;+ }+ /* TODO tutorial: BirdTutorialGui "tutorial_carry" / "tutorial_hold" in e-00 */+}+static void theo_awake(Ent *e) {+ /* Added: a crystal carried in from the last room wins */+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o != e && o->cls == &THEO && o->dead != 1 && ST(o, Theo)->held) ent_remove(e);+ }+}+static void theo_render(Ent *e) {+ Theo *t = ST(e, Theo);+ if (t->dead) {+ death_draw(v2(e->x, e->y - 5), rgb(0x228B22), t->death_t); /* Color.ForestGreen */+ return;+ }+ cs_draw(&t->spr, e->x, e->y, -1, 1, 0, 0xFFFF, 255);+ light_add(e->x, e->y - 5, 0xFFFFFF, 1, 32, 64);+}+static const EntClass THEO = {.name = "theoCrystal", .size = sizeof(Theo), .update = theo_update, .render = theo_render,+ .awake = theo_awake, .on_squish = theo_squish, .is_riding_solid = theo_riding,+ .kind = KIND_ACTOR | KIND_HOLDABLE};+static void new_theo(const EData *d) {+ Ent *e = ent_new(&THEO, d->x, d->y);+ if (!e) return;+ ent_box(e, 8, 10, -4, -10);+ e->depth = 100;+ e->tags = TAG_TRANSITION_UPDATE;+ Theo *t = ST(e, Theo);+ cs_init(&t->spr, SB_theo_crystal);+ t->prev_pos = v2(d->x, d->y);+ t->hit_seeker = 255;+}++/* the player's Holdable hooks (entities.c calls them) */+Ent *level_holdable_check(void) {+ Player *p = level_player();+ if (!p) return NULL;+ for (int i = 0; i < g_nents; i++) {+ Ent *e = &g_ents[i];+ if (e->cls != &THEO || e->dead == 1) continue;+ Theo *t = ST(e, Theo);+ /* Holdable.Check: the PickupCollider, Hitbox(16, 22, -8, -16) */+ if (!collide_rect(p->ent, e->x - 8, e->y - 16, e->x + 8, e->y + 6)) continue;+ if (t->cannot_hold > 0 || t->dead || t->held) continue;+ /* Holdable.Pickup */+ t->idle_depth = e->depth;+ e->depth = p->ent->depth - 1;+ ents_mark_unsorted();+ e->visible = 1;+ t->held = 1;+ t->speed = v2(0, 0); /* OnPickup */+ e->tags |= TAG_PERSISTENT;+ return e;+ }+ return NULL;+}+void holdable_carry(Ent *h, V2 at) {+ if (h->cls != &THEO) return;+ h->x = at.x, h->y = at.y;+}+void holdable_release(Ent *h, V2 force) {+ if (h->cls == &THEO) theo_release(h, force);+}++/* ---------------------------------------------------------------- TheoCrystalPedestal */+typedef struct { uint8_t dropped; } Pedestal;+static int pedestal_hit(Ent *e, Player *p, V2 dir) {+ (void)p, (void)dir;+ Ent *t = theo_entity();+ if (t) {+ ST(t, Theo)->on_pedestal = 0;+ ST(t, Theo)->speed = v2(0, -300);+ }+ ST(e, Pedestal)->dropped = 1;+ e->collidable = 0;+ level_flash(0xFFFF, false);+ level_freeze(0.1f);+ return DASH_REBOUND;+}+static void pedestal_awake(Ent *e) {+ if (level_get_flag("foundTheoInCrystal")) {+ ST(e, Pedestal)->dropped = 1;+ return;+ }+ Ent *t = theo_entity();+ if (t) t->depth = e->depth + 1, ents_mark_unsorted(); /* (CS05_SaveTheo makes it solid) */+}+static void pedestal_update(Ent *e) {+ Ent *t = theo_entity();+ if (t && !ST(e, Pedestal)->dropped) {+ t->x = e->x, t->y = e->y - 32;+ ST(t, Theo)->on_pedestal = 1;+ }+ plat_update(e);+}+static void pedestal_render(Ent *e) {+ gfx_tex_ex(T_characters_theoCrystal_pedestal, e->x, e->y, 32, 72, 1, 1, 0, 0xFFFF, 255, 0); /* JustifyOrigin(0.5, 1) */+}+static const EntClass PEDESTAL = {.name = "theoCrystalPedestal", .size = sizeof(Pedestal), .update = pedestal_update,+ .render = pedestal_render, .awake = pedestal_awake, .on_dash_collide = pedestal_hit,+ .kind = KIND_SOLID};+static void new_pedestal(const EData *d) {+ Ent *e = ent_new(&PEDESTAL, d->x, d->y);+ if (!e) return;+ ent_box(e, 32, 32, -16, -64);+ e->depth = 8998;+ e->collidable = 0;+ e->tags = TAG_TRANSITION_UPDATE;+}+/* ---------------------------------------------------------------- lines against solids */+/* Scene.CollideCheck<Solid>(from, to): Grid.Collide(from, to) for the tiles, RectToLine for the rest */+static int sector(float x, float y, float w, float h, V2 p) {+ int s = 0;+ if (p.x < x) s |= 1;+ else if (p.x >= x + w) s |= 2;+ if (p.y < y) s |= 4;+ else if (p.y >= y + h) s |= 8;+ return s;+}+static bool seg_seg(V2 a1, V2 a2, V2 b1, V2 b2) { /* Collide.LineCheck */+ V2 a = v2sub(a2, a1), b = v2sub(b2, b1);+ float d = a.x * b.y - a.y * b.x;+ if (d == 0) return false;+ V2 c = v2sub(b1, a1);+ float t = (c.x * b.y - c.y * b.x) / d;+ if (t < 0 || t > 1) return false;+ float u = (c.x * a.y - c.y * a.x) / d;+ return u >= 0 && u <= 1;+}+static bool rect_line(float x, float y, float w, float h, V2 f, V2 t) { /* Collide.RectToLine */+ int s1 = sector(x, y, w, h, f), s2 = sector(x, y, w, h, t);+ if (!s1 || !s2) return true;+ if (s1 & s2) return false;+ int s = s1 | s2;+ if ((s & 4) && seg_seg(v2(x, y), v2(x + w, y), f, t)) return true;+ if ((s & 8) && seg_seg(v2(x, y + h), v2(x + w, y + h), f, t)) return true;+ if ((s & 1) && seg_seg(v2(x, y), v2(x, y + h), f, t)) return true;+ if ((s & 2) && seg_seg(v2(x + w, y), v2(x + w, y + h), f, t)) return true;+ return false;+}+static bool tile_at(int cx, int cy) { return level_tile_type(0, cx, cy) != '0'; }+static bool grid_line(V2 f, V2 t) { /* Grid.Collide(from, to) */+ f = v2mul(f, 1 / 8.f), t = v2mul(t, 1 / 8.f);+ bool steep = fabsf(t.y - f.y) > fabsf(t.x - f.x);+ if (steep) f = v2(f.y, f.x), t = v2(t.y, t.x);+ if (f.x > t.x) {+ V2 k = f;+ f = t, t = k;+ }+ float err = 0, slope = fabsf(t.y - f.y) / (t.x - f.x);+ int ys = f.y < t.y ? 1 : -1, y = (int)floorf(f.y), xe = (int)floorf(t.x);+ for (int x = (int)floorf(f.x); x <= xe; x++) {+ if (steep ? tile_at(y, x) : tile_at(x, y)) return true;+ err += slope;+ if (err >= 0.5f) y += ys, err -= 1;+ }+ return false;+}+static bool line_solid(V2 f, V2 t) {+ if (grid_line(f, t)) return true;+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (!(o->kind & KIND_SOLID) || !o->cls || o->dead == 1 || !o->collidable || o->ctype != COL_BOX) continue;+ if (rect_line(o->x + o->cx, o->y + o->cy, o->cw, o->ch, f, t)) return true;+ }+ return false;+}++/* ---------------------------------------------------------------- Pathfinder (Level.Pathfinder.Find) */+/* the map lives in free texture-cache RAM while it runs (res_scratch): cost (28 bits), solid, parent direction */+#define PF_INF 0x0FFFFFFFu+static const int8_t PF_DIR[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};+#define SEEKER_TAB 6+#define SEEKER_PATH 32+#define SEEKER_NODES 96+typedef struct {+ Ent *owner;+ uint8_t node0, nnodes, npath, used;+ int16_t path[SEEKER_PATH][2];+} SeekerTab;+enum { OFF_seeker_tab = ((END_edges + 7) & ~7), END_seeker_tab = OFF_seeker_tab + (int)sizeof(SeekerTab[SEEKER_TAB]) };+#define seeker_tab (*(SeekerTab(*)[SEEKER_TAB])(void *)(g_chram[5] + OFF_seeker_tab))+enum { OFF_seeker_nodes = ((END_seeker_tab + 7) & ~7), END_seeker_nodes = OFF_seeker_nodes + (int)sizeof(int16_t[SEEKER_NODES][2]) };+#define seeker_nodes (*(int16_t(*)[SEEKER_NODES][2])(void *)(g_chram[5] + OFF_seeker_nodes))+static int nseeker_nodes;++static int pf_find(SeekerTab *tab, V2 from, V2 to) {+ Room *rm = g_level.room;+ int ox = rm->x / 8, oy = rm->y / 8, w = rm->w / 8, h = rm->h / 8;+ uint32_t cap, need = (uint32_t)(w * h) * 4;+ uint8_t *mem = res_scratch(need + 2048, &cap); /* textures not drawn last frame make way */+ if (need + 256 > cap) return 0; /* the open list takes what is left */+ uint32_t *map = (uint32_t *)(void *)mem;+ uint16_t *active = (uint16_t *)(void *)(mem + need);+ int maxact = (int)((cap - need) / 2);+ for (int j = 0; j < h; j++)+ for (int i = 0; i < w; i++) map[j * w + i] = PF_INF | (tile_at(ox + i, oy + j) ? 1u << 28 : 0);+ for (int k = 0; k < g_nents; k++) {+ Ent *o = &g_ents[k];+ if (!(o->kind & KIND_SOLID) || !o->cls || o->dead == 1 || !o->collidable || o->ctype != COL_BOX) continue;+ for (int i = (int)floorf(e_left(o) / 8); i < (int)ceilf(e_right(o) / 8); i++)+ for (int j = (int)floorf(e_top(o) / 8); j < (int)ceilf(e_bottom(o) / 8); j++) {+ int x = i - ox, y = j - oy;+ if (x >= 0 && y >= 0 && x < w && y < h) map[y * w + x] |= 1u << 28;+ }+ }+#define SOLID(i) (map[i] >> 28 & 1)+#define COST(i) (map[i] & PF_INF)+#define PAR(i) ((int)(map[i] >> 29)) /* 0: none, 1 + direction it came along */+ int sx = (int)floorf(from.x / 8) - ox, sy = (int)floorf(from.y / 8) - oy;+ int ex = (int)floorf(to.x / 8) - ox, ey = (int)floorf(to.y / 8) - oy;+ if (sx < 0 || sy < 0 || sx >= w || sy >= h || ex < 0 || ey < 0 || ex >= w || ey >= h) return 0;+ if (SOLID(sy * w + sx) || SOLID(ey * w + ex)) return 0;+ int na = 0;+ active[na++] = (uint16_t)(sy * w + sx);+ map[sy * w + sx] &= ~PF_INF;+ bool found = false;+ while (na > 0 && !found) {+ int cur = active[--na], cx = cur % w, cy = cur / w;+ for (int m = 0; m < 4; m++) {+ int nx = cx + PF_DIR[m][0], ny = cy + PF_DIR[m][1];+ if (nx < 0 || ny < 0 || nx >= w || ny >= h || SOLID(ny * w + nx)) continue;+ uint32_t add = 1;+ for (int n = 0; n < 4; n++) {+ int qx = nx + PF_DIR[n][0], qy = ny + PF_DIR[n][1];+ if (qx >= 0 && qy >= 0 && qx < w && qy < h && SOLID(qy * w + qx)) {+ add = 7;+ break;+ }+ }+ if (PAR(cur)) { /* fewerTurns */+ int pd = PAR(cur) - 1, px = cx - PF_DIR[pd][0], py = cy - PF_DIR[pd][1];+ if (nx != px && ny != py) add += 4;+ }+ uint32_t cost = COST(cur);+ if (PF_DIR[m][1] != 0) add += (uint32_t)(int)((float)cost * 0.5f);+ uint32_t nc = cost + add;+ if (nc >= PF_INF) continue;+ int ni = ny * w + nx;+ if (COST(ni) > nc) {+ map[ni] = (map[ni] & (1u << 28)) | nc | (uint32_t)(m + 1) << 29;+ /* List.BinarySearch with the comparer cost(b) - cost(a): costs fall along the list */+ int lo = 0, hi = na - 1, at = -1;+ while (lo <= hi) {+ int mid = lo + ((hi - lo) >> 1);+ int64_t c = (int64_t)COST(ni) - (int64_t)COST(active[mid]);+ if (c == 0) {+ at = mid;+ break;+ }+ if (c < 0) lo = mid + 1;+ else hi = mid - 1;+ }+ if (at < 0) at = lo;+ if (na >= maxact) return 0;+ memmove(active + at + 1, active + at, (size_t)(na - at) * 2);+ active[at] = (uint16_t)ni;+ na++;+ if (nx == ex && ny == ey) {+ found = true;+ break;+ }+ }+ }+ }+ if (!found) return 0;+ /* back from the end (the start tile left out); collinear points are removed, then the list is reversed */+ int16_t pts[SEEKER_PATH][2];+ int np = 0, guard = 0, x = ex, y = ey;+ while ((x != sx || y != sy) && guard++ < 1000) {+ int16_t px = (int16_t)((x + 0.5f) * 8 + rm->x), py = (int16_t)((y + 0.5f) * 8 + rm->y);+ if (np >= 2 && ((pts[np - 2][0] == pts[np - 1][0] && pts[np - 1][0] == px) || (pts[np - 2][1] == pts[np - 1][1] && pts[np - 1][1] == py)))+ np--;+ if (np >= SEEKER_PATH) return 0;+ pts[np][0] = px, pts[np][1] = py, np++;+ int d = PAR(y * w + x) - 1;+ if (d < 0) return 0;+ x -= PF_DIR[d][0], y -= PF_DIR[d][1];+ }+ if (guard >= 1000) return 0;+ for (int i = 0; i < np; i++) tab->path[i][0] = pts[np - 1 - i][0], tab->path[i][1] = pts[np - 1 - i][1];+ tab->npath = (uint8_t)np;+ return 1;+#undef SOLID+#undef COST+#undef PAR+}++/* ---------------------------------------------------------------- Seeker */+enum { SK_IDLE, SK_PATROL, SK_SPOTTED, SK_ATTACK, SK_STUNNED, SK_SKIDDING, SK_REGEN, SK_RETURNED };+typedef struct {+ ActorExt ext;+ V2 speed, last_spotted, last_path_to;+ float sx, sy, light, light_r;+ float patrol_wait, lose_timer, turn_delay, attack_speed, co_wait;+ float sinex, siney;+ Wiggler wig;+ Shaker shaker;+ CSpr spr;+ uint16_t rnd_calls;+ uint8_t state, co, locked, next, tab, path_idx;+ int8_t facing, sprite_facing;+ uint8_t spotted, can_see, path_found, wind_up, strong_skid, bounce_w;+ int8_t bounce_x, pad;+ uint8_t pc[2], pad2[2]; /* the PlayerCollider entities */+} Seeker;+static SeekerTab *seeker_tab_of(Seeker *s) { return &seeker_tab[s->tab]; }+static int tab_alloc(Ent *owner, const EData *d) {+ for (int i = 0; i < SEEKER_TAB; i++) {+ if (seeker_tab[i].used) continue;+ SeekerTab *t = &seeker_tab[i];+ memset(t, 0, sizeof *t);+ t->used = 1;+ t->owner = owner;+ t->node0 = (uint8_t)nseeker_nodes;+ for (int k = 0; k < d->nnodes && nseeker_nodes < SEEKER_NODES; k++) {+ V2 n = ed_node(d, k);+ seeker_nodes[nseeker_nodes][0] = (int16_t)n.x, seeker_nodes[nseeker_nodes][1] = (int16_t)n.y;+ nseeker_nodes++, t->nnodes++;+ }+ return i;+ }+ return -1;+}+static void tab_free(int i) {+ SeekerTab *t = &seeker_tab[i];+ if (!t->used) return;+ int a = t->node0, n = t->nnodes;+ memmove(seeker_nodes + a, seeker_nodes + a + n, sizeof(seeker_nodes[0]) * (size_t)(nseeker_nodes - a - n));+ nseeker_nodes -= n;+ for (int k = 0; k < SEEKER_TAB; k++)+ if (seeker_tab[k].used && seeker_tab[k].node0 > a) seeker_tab[k].node0 = (uint8_t)(seeker_tab[k].node0 - n);+ t->used = 0;+}+static V2 seeker_center(Ent *e) { return v2(e->x, e->y); } /* the physics hitbox is centred */+static V2 follow_target(Seeker *s) { return v2(s->last_spotted.x, s->last_spotted.y - 2); }+static void seeker_set_state(Ent *e, int st);+static void seeker_play(Seeker *s, int anim, bool restart);+static void seeker_last_frame(Seeker *s, int anim) { /* sprite.OnLastFrame */+ if ((anim == A_seeker_flipMouth || anim == A_seeker_flipEyes || anim == A_seeker_skid) && s->sprite_facing != s->facing) {+ s->sprite_facing = s->facing;+ if (s->next != 255) {+ int n = s->next;+ s->next = 255;+ seeker_play(s, n, false);+ }+ }+}+static void seeker_play(Seeker *s, int anim, bool restart) {+ if (cs_cur(&s->spr) != anim || restart) { /* OnChange(LastAnimationID, id) */+ s->next = 255;+ seeker_last_frame(s, s->spr.last);+ }+ cs_play(&s->spr, anim, restart);+}+static void turn_facing(Seeker *s, float dir, int goto_anim) {+ if (dir != 0) s->facing = (int8_t)sgn(dir);+ if (s->sprite_facing != s->facing) {+ if (s->state == SK_SKIDDING) seeker_play(s, A_seeker_skid, false);+ else if (s->state == SK_ATTACK || s->state == SK_SPOTTED) seeker_play(s, A_seeker_flipMouth, false);+ else seeker_play(s, A_seeker_flipEyes, false);+ s->next = (uint8_t)(goto_anim < 0 ? 255 : goto_anim);+ } else if (goto_anim >= 0)+ seeker_play(s, goto_anim, false);+}+static void snap_facing(Seeker *s, float dir) {+ if (dir != 0) s->sprite_facing = s->facing = (int8_t)sgn(dir);+}+static bool seeker_can_see(Ent *e, Player *p) {+ if (!p) return false;+ Seeker *s = ST(e, Seeker);+ V2 c = seeker_center(e), pc = player_center(p);+ V2 cam = g_level.cam;+ bool inside = c.x >= cam.x && c.x < cam.x + 320 && c.y >= cam.y && c.y < cam.y + 180;+ if (s->state != SK_SPOTTED && !inside && dist2(c, pc) > 25600) return false;+ V2 d = v2sub(pc, c);+ V2 v = safe_norm(v2(-d.y, d.x), 2);+ if (!line_solid(v2add(c, v), v2add(pc, v))) return !line_solid(v2sub(c, v), v2sub(pc, v));+ return false;+}+static V2 path_speed(Ent *e, float mag) { /* GetPathSpeed */+ Seeker *s = ST(e, Seeker);+ SeekerTab *t = seeker_tab_of(s);+ while (s->path_idx < t->npath) {+ V2 p = v2(t->path[s->path_idx][0], t->path[s->path_idx][1]);+ if (dist2(seeker_center(e), p) < 36) {+ s->path_idx++;+ continue;+ }+ return safe_norm(v2sub(p, seeker_center(e)), mag);+ }+ return v2(0, 0);+}+static float speed_mag(Ent *e, float base) {+ Player *p = level_player();+ if (p) return dist2(seeker_center(e), player_center(p)) > 12544 ? base * 3 : base * 1.5f;+ return base;+}+static void seeker_find_path(Ent *e) {+ Seeker *s = ST(e, Seeker);+ s->last_path_to = s->last_spotted;+ s->path_idx = 0;+ s->path_found = (uint8_t)pf_find(seeker_tab_of(s), seeker_center(e), follow_target(s));+}+static int choose_patrol(Ent *e) {+ Seeker *s = ST(e, Seeker);+ Player *p = level_player();+ if (!p) return SK_IDLE;+ SeekerTab *t = seeker_tab_of(s);+ V2 pt[3];+ float dd[3] = {0, 0, 0};+ int num = 0;+ for (int i = 0; i < t->nnodes; i++) {+ V2 v = v2(seeker_nodes[t->node0 + i][0], seeker_nodes[t->node0 + i][1]);+ if (dist2(seeker_center(e), v) < 576) continue;+ float d2 = dist2(v, player_center(p));+ for (int k = 0; k < 3; k++)+ if (d2 < dd[k] || dd[k] <= 0) {+ num++;+ for (int j = 2; j > k; j--) dd[j] = dd[j - 1], pt[j] = pt[j - 1];+ dd[k] = d2, pt[k] = v;+ break;+ }+ }+ if (num <= 0) return SK_IDLE;+ /* random = new Random(LevelData.LoadSeed): replayed up to this call */+ NetRandom r;+ int seed = 0;+ for (const char *c = room_name(g_level.room->index); *c; c++) seed += (uint8_t)*c;+ rnd_seed(&r, seed);+ for (int i = 0; i < s->rnd_calls; i++) rnd_next(&r);+ s->rnd_calls++;+ s->last_spotted = pt[rnd_range(&r, num < 3 ? num : 3)];+ seeker_find_path(e);+ return SK_PATROL;+}+static void seeker_trail(Ent *e) {+ Seeker *s = ST(e, Seeker);+ float k = 1 - 0.3f * s->wig.value;+ uint16_t t = cs_tex(&s->spr);+ if (t != 0xFFFF) trail_add(e->x, e->y, t, 48, 48, s->sx * k * s->sprite_facing, s->sy * k, 0x99E550, 0.5f);+}+static bool seeker_can_attack(Ent *e) {+ Seeker *s = ST(e, Seeker);+ if (fabsf(e->y - s->last_spotted.y) > 24) return false;+ if (fabsf(e->x - s->last_spotted.x) < 16) return false;+ V2 v = safe_norm(v2sub(follow_target(s), seeker_center(e)), 1);+ if (-v.y > 0.5f || v.y > 0.5f) return false;+ if (collide_solid(e, e->x + sgn(s->last_spotted.x - e->x) * 24, e->y)) return false;+ return true;+}+/* the state machine's update callbacks */+static int seeker_state_update(Ent *e) {+ Seeker *s = ST(e, Seeker);+ switch (s->state) {+ case SK_IDLE: {+ if (s->can_see) return SK_SPOTTED;+ V2 v = v2(0, 0);+ if (s->spotted && dist2(seeker_center(e), follow_target(s)) > 64) {+ float m = speed_mag(e, 50);+ v = s->path_found ? path_speed(e, m) : safe_norm(v2sub(follow_target(s), seeker_center(e)), m);+ }+ if (v.x == 0 && v.y == 0) v = v2(sinf(s->sinex) * 6, sinf(s->siney) * 6);+ s->speed = approach_v(s->speed, v, 200 * DT);+ if (s->speed.x * s->speed.x + s->speed.y * s->speed.y > 400) turn_facing(s, s->speed.x, -1);+ if (s->sprite_facing == s->facing) seeker_play(s, A_seeker_idle, false);+ return SK_IDLE;+ }+ case SK_PATROL: {+ if (s->can_see) return SK_SPOTTED;+ if (s->patrol_wait > 0) {+ s->patrol_wait -= DT;+ if (s->patrol_wait <= 0) return choose_patrol(e);+ } else if (dist2(seeker_center(e), s->last_spotted) < 144)+ s->patrol_wait = 0.4f;+ s = ST(e, Seeker);+ float m = speed_mag(e, 25);+ V2 t = s->path_found ? path_speed(e, m) : safe_norm(v2sub(follow_target(s), seeker_center(e)), m);+ s->speed = approach_v(s->speed, t, 600 * DT);+ if (s->speed.x * s->speed.x + s->speed.y * s->speed.y > 100) turn_facing(s, s->speed.x, -1);+ if (s->sprite_facing == s->facing) seeker_play(s, A_seeker_search, false);+ return SK_PATROL;+ }+ case SK_SPOTTED: {+ if (!s->can_see) {+ s->lose_timer -= DT;+ if (s->lose_timer < 0) return SK_IDLE;+ } else+ s->lose_timer = 0.6f;+ float m = speed_mag(e, 60);+ V2 ft = follow_target(s), c = seeker_center(e);+ V2 v = s->path_found ? path_speed(e, m) : safe_norm(v2sub(ft, c), m);+ if (dist2(c, ft) < 2500 && e->y < ft.y) {+ float a = vangle(v);+ if (e->y < ft.y - 2) a = angle_lerp(a, PI_F / 2, 0.5f);+ else if (e->y > ft.y + 2) a = angle_lerp(a, -PI_F / 2, 0.5f);+ v = angle_vec(a, 60);+ float off = sgn(e->x - s->last_spotted.x) * 48.f;+ if (fabsf(e->x - s->last_spotted.x) < 36 && !collide_solid(e, e->x + off, e->y)) {+ /* CollideCheck<Solid>(lastSpottedAt + val2): the seeker moved there */+ if (!collide_solid(e, s->last_spotted.x + off, s->last_spotted.y)) v.x = (float)(sgn(e->x - s->last_spotted.x) * 60);+ }+ }+ s->speed = approach_v(s->speed, v, 600 * DT);+ s->turn_delay -= DT;+ if (s->turn_delay <= 0) turn_facing(s, s->speed.x, A_seeker_spotted);+ return SK_SPOTTED;+ }+ case SK_ATTACK:+ if (!s->wind_up) {+ V2 v = safe_norm(v2sub(follow_target(s), seeker_center(e)), 1);+ V2 sn = safe_norm(s->speed, 1);+ if (sn.x * v.x + sn.y * v.y < 0.4f) return SK_SKIDDING;+ s->attack_speed = approach(s->attack_speed, 260, 300 * DT);+ float a = angle_approach(vangle(s->speed), vangle(v), 0.61086524f * DT);+ s->speed = safe_norm(angle_vec(a, v2len(s->speed)), s->attack_speed);+ if (level_on_interval(0.04f)) {+ V2 b = safe_norm(v2mul(s->speed, -1), 1);+ particles_emit(PL_MID, &P_Seeker_P_Attack, 2, v2add(v2(e->x, e->y), v2mul(b, 4)), v2(4, 4), vangle(b));+ }+ if (level_on_interval(0.06f)) seeker_trail(e);+ }+ return SK_ATTACK;+ case SK_STUNNED: s->speed = approach_v(s->speed, v2(0, 0), 150 * DT); return SK_STUNNED;+ case SK_SKIDDING:+ s->speed = approach_v(s->speed, v2(0, 0), (s->strong_skid ? 400 : 200) * DT);+ if (s->speed.x * s->speed.x + s->speed.y * s->speed.y < 400) return s->can_see ? SK_SPOTTED : SK_IDLE;+ return SK_SKIDDING;+ case SK_REGEN:+ s->speed.x = approach(s->speed.x, 0, 150 * DT);+ s->speed = approach_v(s->speed, v2(0, 0), 150 * DT);+ return SK_REGEN;+ }+ return s->state;+}+static const EntClass RECOVER;+static void seeker_explode_push(Ent *e);+/* the state's coroutine: one step a frame unless waiting */+static void seeker_coroutine(Ent *e) {+ Seeker *s = ST(e, Seeker);+ if (!s->co) return;+ if (s->co_wait > 0) {+ s->co_wait -= DT;+ return;+ }+ int st = s->state, step = s->co++;+ switch (st) {+ case SK_IDLE: { /* IdleCoroutine */+ SeekerTab *t = seeker_tab_of(s);+ if (step == 1 && !(t->nnodes && s->spotted)) {+ s->co = 0;+ break;+ }+ if (step <= 2) {+ if (dist2(seeker_center(e), follow_target(s)) > 64) s->co = 2;+ else s->co_wait = 0.3f, s->co = 3;+ break;+ }+ s->co = 0;+ seeker_set_state(e, SK_PATROL);+ break;+ }+ case SK_SPOTTED:+ if (step == 1) s->co_wait = 0.2f;+ else if (!seeker_can_attack(e)) s->co = 2;+ else {+ s->co = 0;+ seeker_set_state(e, SK_ATTACK);+ }+ break;+ case SK_ATTACK:+ if (step == 1) {+ turn_facing(s, s->last_spotted.x - e->x, A_seeker_windUp);+ s->co_wait = 0.3f;+ } else {+ s->wind_up = 0;+ s->attack_speed = 180;+ s->speed = safe_norm(v2sub(v2sub(s->last_spotted, v2(0, 2)), seeker_center(e)), 180);+ snap_facing(s, s->speed.x);+ s->co = 0;+ }+ break;+ case SK_STUNNED:+ if (step == 1) s->co_wait = 0.8f;+ else {+ s->co = 0;+ seeker_set_state(e, SK_IDLE);+ }+ break;+ case SK_SKIDDING:+ if (step == 1) s->co_wait = 0.08f;+ else s->strong_skid = 1, s->co = 0;+ break;+ case SK_REGEN:+ switch (step) {+ case 1: s->co_wait = 1; break;+ case 2: s->shaker.on = 1, s->co_wait = 0.2f; break;+ case 3: seeker_play(s, A_seeker_pulse, false), s->co_wait = 0.5f; break;+ case 4: {+ seeker_play(s, A_seeker_recover, false);+ Ent *b = ent_new(&RECOVER, e->x, e->y); /* RecoverBlast.Spawn */+ if (b) {+ b->depth = -199;+ b->collidable = 0;+ cs_init(ST(b, CSpr), SB_seekerShockWave);+ cs_play(ST(b, CSpr), A_seekerShockWave_shockwave, true);+ }+ ST(e, Seeker)->co_wait = 0.15f;+ break;+ }+ default:+ seeker_explode_push(e);+ s = ST(e, Seeker);+ s->shaker.on = 0, s->shaker.x = s->shaker.y = 0, s->shaker.timer = 0;+ s->locked = 0;+ s->co = 0;+ seeker_set_state(e, SK_RETURNED);+ break;+ }+ break;+ case SK_RETURNED:+ if (step == 1) s->co_wait = 0.3f;+ else {+ s->co = 0;+ seeker_set_state(e, SK_IDLE);+ }+ break;+ default: s->co = 0; break;+ }+}+static void seeker_set_state(Ent *e, int st) {+ Seeker *s = ST(e, Seeker);+ if (s->locked || s->state == st) return;+ int prev = s->state;+ s->state = (uint8_t)st;+ /* ends */+ if (prev == SK_SKIDDING) s->sprite_facing = s->facing;+ if (prev == SK_REGEN) {+ e->collidable = 1;+ s->light_r = 0; /* Light 32 / 64 */+ }+ /* coroutine: replaced (or cancelled) */+ bool has_co = st == SK_IDLE || st == SK_SPOTTED || st == SK_ATTACK || st == SK_STUNNED || st == SK_SKIDDING || st == SK_REGEN ||+ st == SK_RETURNED;+ s->co = has_co ? 1 : 0;+ s->co_wait = 0;+ /* begins */+ switch (st) {+ case SK_PATROL: {+ int to = choose_patrol(e);+ ST(e, Seeker)->patrol_wait = 0;+ if (to != SK_PATROL) seeker_set_state(e, to);+ break;+ }+ case SK_SPOTTED: {+ Player *p = level_player();+ if (p) turn_facing(s, p->ent->x - e->x, A_seeker_spot);+ s->lose_timer = 0.6f;+ s->turn_delay = 1;+ break;+ }+ case SK_ATTACK:+ s->wind_up = 1;+ s->attack_speed = -60;+ s->speed = safe_norm(v2sub(follow_target(s), seeker_center(e)), -60);+ break;+ case SK_SKIDDING:+ s->strong_skid = 0;+ turn_facing(s, (float)-s->facing, -1);+ break;+ case SK_REGEN:+ seeker_play(s, A_seeker_takeHit, false);+ e->collidable = 0;+ s->locked = 1;+ s->light_r = 1; /* Light 16 / 32 */+ break;+ }+}+/* the regeneration's blast: the player, Theo, cracked walls (touch switches: TODO, another file's) */+static void seeker_explode_push(Ent *e) {+ V2 c = v2(e->x, e->y);+ Player *p = level_player();+ /* Collider = pushRadius (Circle 40): CollideFirst<Player> */+ if (p && !p->dead) {+ float nx = clampf(c.x, e_left(p->ent), e_right(p->ent)), ny = clampf(c.y, e_top(p->ent), e_bottom(p->ent));+ if ((nx - c.x) * (nx - c.x) + (ny - c.y) * (ny - c.y) < 1600 && !line_solid(c, player_center(p))) player_explode_launch(p, c, true);+ }+ Ent *th = theo_entity();+ if (th) {+ float nx = clampf(c.x, e_left(th), e_right(th)), ny = clampf(c.y, e_top(th), e_bottom(th));+ if ((nx - c.x) * (nx - c.x) + (ny - c.y) * (ny - c.y) < 1600 && !line_solid(c, theo_center(th))) theo_explode_launch(th, c);+ }+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o->cls != &CRACKED || o->dead == 1 || !o->collidable) continue;+ float nx = clampf(c.x, e_left(o), e_right(o)), ny = clampf(c.y, e_top(o), e_bottom(o));+ if ((nx - c.x) * (nx - c.x) + (ny - c.y) * (ny - c.y) < 1600) cracked_break(o, c);+ }+ for (float a = 0; a < PI_F * 2; a += 0.17453292f) {+ V2 at = v2add(c, angle_vec(a + rnd_rangef(-PI_F / 90, PI_F / 90), (float)(12 + rndi(6))));+ particles_emit1(PL_MID, &P_Seeker_P_Regen, at, a);+ }+}+static void seeker_slammed(Ent *e, Collision *c) {+ Seeker *s = ST(e, Seeker);+ float dir, x;+ if (c->dir.x > 0) dir = PI_F, x = e_right(e);+ else dir = 0, x = e_left(e);+ particles_emit(PL_MID, &P_Seeker_P_HitWall, 12, v2(x, e->y), v2(0, 4), dir);+ int sx = sgn(s->speed.x);+ if (is_dswitch(c->hit)) dswitch_hit(c->hit, NULL, v2((float)sx, 0));+ /* breakWallsHitbox: Hitbox(6, 14, -3, -7) */+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o->cls != &CRACKED || o->dead == 1 || !o->collidable) continue;+ if (collide_rect(o, e->x - 3 + sx, e->y - 7, e->x + 3 + sx, e->y + 7)) cracked_break(o, v2(e->x, e->y));+ }+ s = ST(e, Seeker);+ level_dir_shake(v2((float)sx, 0), 0.3f);+ s->speed.x = sx * -100.f;+ s->speed.y *= 0.4f;+ s->sx = 0.6f, s->sy = 1.4f;+ shaker_for(&s->shaker, 0.5f);+ wiggler_restart(&s->wig);+ seeker_set_state(e, SK_STUNNED);+ if (c->hit && c->hit->cls == &BARRIER) barrier_reflect(c->hit);+}+static void seeker_collide_h(Ent *e, Collision *c) {+ Seeker *s = ST(e, Seeker);+ if (s->state == SK_ATTACK && c->hit) {+ int n = sgn(s->speed.x);+ if ((!collide_solid(e, e->x + n, e->y + 4) && !actor_move_v_exact(e, 4, NULL, NULL)) ||+ (!collide_solid(e, e->x + n, e->y - 4) && !actor_move_v_exact(e, -4, NULL, NULL)))+ return;+ }+ s = ST(e, Seeker);+ if ((s->state == SK_ATTACK || s->state == SK_SKIDDING) && fabsf(s->speed.x) >= 100) seeker_slammed(e, c);+ else s->speed.x *= -0.2f;+}+static void seeker_collide_v(Ent *e, Collision *c) {+ (void)c;+ Seeker *s = ST(e, Seeker);+ if (s->state == SK_ATTACK) s->speed.y *= -0.6f;+ else s->speed.y *= -0.2f;+}+static void seeker_got_bounced(Ent *e, V2 from) {+ Seeker *s = ST(e, Seeker);+ level_freeze(0.15f);+ V2 c = v2(e->x, e->y + 2); /* Center with the attack hitbox */+ s->speed = safe_norm(v2sub(c, from), 200);+ seeker_set_state(e, SK_REGEN);+ s = ST(e, Seeker);+ s->sx = 1.4f, s->sy = 0.6f;+ particles_emit(PL_MID, &P_Seeker_P_Stomp, 8, v2(c.x, c.y - 5), v2(6, 3), 0);+}+/* attackHitbox Hitbox(12, 8, -6, -2), bounceHitbox Hitbox(12 or 16, 6, x, -8) */+static void seeker_attack_player(Ent *e, Player *p) {+ Seeker *s = ST(e, Seeker);+ if (s->state != SK_STUNNED) {+ player_die(p, safe_norm(v2sub(player_center(p), v2(e->x, e->y)), 1), false);+ return;+ }+ V2 bc = v2(e->x + s->bounce_x + s->bounce_w / 2.f, e->y - 5);+ player_point_bounce(p, bc);+ s->speed = safe_norm(v2sub(bc, player_center(p)), 100);+ wiggler_restart(&s->wig);+}+static void seeker_bounce_player(Ent *e, Player *p) { /* OnBouncePlayer */+ if (player_hits(e->x - 6, e->y - 2, e->x + 6, e->y + 6)) seeker_attack_player(e, p);+ else {+ player_bounce(p, e->y - 2); /* Top, with the attack hitbox as the collider */+ seeker_got_bounced(e, player_center(p));+ }+}+/* its two PlayerColliders (attackHitbox, bounceHitbox) are small entities the player checks, in this order */+typedef struct { uint8_t owner, bounce, pad[2]; } SeekerPC;+static void seekerpc_on_player(Ent *e, Player *p) {+ SeekerPC *c = ST(e, SeekerPC);+ Ent *s = ent_at(c->owner);+ if (s->cls != &SEEKER || s->dead == 1 || !s->collidable) return;+ if (c->bounce) seeker_bounce_player(s, p);+ else seeker_attack_player(s, p);+}+static const EntClass SEEKERPC = {.name = "seekerCollider", .size = sizeof(SeekerPC), .on_player = seekerpc_on_player,+ .kind = KIND_PCOLLIDE};+static void seeker_sync_colliders(Ent *e) {+ Seeker *s = ST(e, Seeker);+ for (int k = 0; k < 2; k++) {+ Ent *c = ent_at(s->pc[k]);+ if (c->cls != &SEEKERPC || ST(c, SeekerPC)->owner != ent_ref(e)) continue;+ c->x = e->x, c->y = e->y;+ c->collidable = e->collidable;+ if (ST(c, SeekerPC)->bounce) ent_box(c, s->bounce_w, 6, s->bounce_x, -8);+ else ent_box(c, 12, 8, -6, -2);+ }+}+static bool seeker_hits_holdable(Ent *s, Ent *theo) {+ return s->collidable && collide_rect(theo, s->x - 6, s->y - 2, s->x + 6, s->y + 6);+}+static void seeker_on_holdable(Ent *e, Ent *theo) { /* OnHoldable */+ Seeker *s = ST(e, Seeker);+ Theo *t = ST(theo, Theo);+ if (s->state != SK_REGEN && theo_dangerous(theo, e)) {+ if (!t->held) t->speed = safe_norm(v2sub(theo_center(theo), v2(e->x, e->y)), 120); /* HitSeeker */+ seeker_set_state(e, SK_STUNNED);+ ST(e, Seeker)->speed = safe_norm(v2sub(v2(e->x, e->y), theo_center(theo)), 120);+ wiggler_restart(&ST(e, Seeker)->wig);+ } else if ((s->state == SK_ATTACK || s->state == SK_SKIDDING) && t->held) {+ theo_swat(theo, e, sgn(s->speed.x));+ seeker_set_state(e, SK_STUNNED);+ ST(e, Seeker)->speed = safe_norm(v2sub(v2(e->x, e->y), theo_center(theo)), 120);+ wiggler_restart(&ST(e, Seeker)->wig);+ }+}+static void seeker_update(Ent *e) {+ Seeker *s = ST(e, Seeker);+ actor_update_lift(e);+ s->light = approach(s->light, 1, DT * 2);+ barriers_collidable(true);+ s->sx = approach(s->sx, 1, 2 * DT);+ s->sy = approach(s->sy, 1, 2 * DT);+ if (s->state == SK_REGEN)+ s->can_see = 0;+ else {+ Player *p = level_player();+ s->can_see = seeker_can_see(e, p);+ if (s->can_see) s->spotted = 1, s->last_spotted = player_center(p);+ }+ if (!v2eq(s->last_path_to, s->last_spotted)) seeker_find_path(e);+ /* components: shaker, the state machine, the sines, the sprite, the wiggler */+ shaker_update(&s->shaker);+ seeker_set_state(e, seeker_state_update(e));+ seeker_coroutine(e);+ s = ST(e, Seeker);+ s->sinex = fmodf(s->sinex + 2 * PI_F * 0.5f * DT, PI_F * 8);+ s->siney = fmodf(s->siney + 2 * PI_F * 0.7f * DT, PI_F * 8);+ int ended = cs_update(&s->spr);+ if (ended >= 0) {+ seeker_last_frame(s, ended);+ if (cs_cur(&s->spr) >= 0) s->next = 255; /* the goto (loops too) calls OnChange */+ }+ wiggler_update(&s->wig);+ actor_move_h(e, s->speed.x * DT, seeker_collide_h, NULL);+ actor_move_v(e, ST(e, Seeker)->speed.y * DT, seeker_collide_v, NULL);+ s = ST(e, Seeker);+ Room *rm = g_level.room;+ Collision none = {{0, 0}, {0, 0}, {0, 0}, NULL, NULL};+ if (e_left(e) < rm->x && s->speed.x < 0) {+ e->x += rm->x - e_left(e);+ none.dir = v2(-1, 0);+ seeker_collide_h(e, &none);+ } else if (e_right(e) > rm->x + rm->w && s->speed.x > 0) {+ e->x -= e_right(e) - (rm->x + rm->w);+ none.dir = v2(1, 0);+ seeker_collide_h(e, &none);+ }+ s = ST(e, Seeker);+ if (e_top(e) < rm->y - 8 && s->speed.y < 0) {+ e->y += rm->y - 8 - e_top(e);+ seeker_collide_v(e, &none);+ } else if (e_bottom(e) > rm->y + rm->h && s->speed.y > 0) {+ e->y -= e_bottom(e) - (rm->y + rm->h);+ seeker_collide_v(e, &none);+ }+ /* SeekerColliders: touch switches (TODO: another chapter's file) */+ s = ST(e, Seeker);+ if (s->state == SK_ATTACK && s->speed.x > 0) s->bounce_w = 16, s->bounce_x = -10;+ else if (s->state == SK_ATTACK && s->speed.y < 0) s->bounce_w = 16, s->bounce_x = -6;+ else s->bounce_w = 12, s->bounce_x = -6;+ barriers_collidable(false);+ seeker_sync_colliders(e);+}+static void seeker_squish(Ent *e, Collision *c);+static void seeker_render(Ent *e) {+ Seeker *s = ST(e, Seeker);+ float k = 1 - 0.3f * s->wig.value;+ cs_draw(&s->spr, e->x + s->shaker.x, e->y + s->shaker.y, s->sx * k * s->sprite_facing, s->sy * k, 0, 0xFFFF, 255);+ light_add(e->x, e->y, 0xFFFFFF, s->light, s->light_r ? 16 : 32, s->light_r ? 32 : 64);+}+static void seeker_awake(Ent *e) {+ Seeker *s = ST(e, Seeker);+ Ent *pe = level_player_ent();+ if (!pe || e->x == pe->x) snap_facing(s, 1);+ else snap_facing(s, (float)sgn(pe->x - e->x));+}+static void seeker_removed(Ent *e) {+ Seeker *s = ST(e, Seeker);+ if (s->tab < SEEKER_TAB && seeker_tab[s->tab].owner == e) tab_free(s->tab);+ for (int k = 0; k < 2; k++) {+ Ent *c = ent_at(s->pc[k]);+ if (c->cls == &SEEKERPC && ST(c, SeekerPC)->owner == ent_ref(e)) ent_remove(c);+ }+}+static bool seeker_riding(Ent *e, Ent *o) { return (void)e, (void)o, false; }+static const EntClass SEEKER = {.name = "seeker", .size = sizeof(Seeker), .update = seeker_update, .render = seeker_render,+ .awake = seeker_awake, .removed = seeker_removed, .on_squish = seeker_squish,+ .is_riding_solid = seeker_riding, .is_riding_jumpthru = seeker_riding, .kind = KIND_ACTOR};++/* the HotPink DeathEffect of a squished seeker */+typedef struct { float t; uint16_t color, pad; } DeathFx;+static void deathfx_update(Ent *e) {+ DeathFx *d = ST(e, DeathFx);+ d->t = approach(d->t, 1, DT / 0.834f);+ if (d->t >= 1) ent_remove(e);+}+static void deathfx_render(Ent *e) { death_draw(v2(e->x, e->y), ST(e, DeathFx)->color, ST(e, DeathFx)->t); }+static const EntClass DEATHFX = {.name = "deathEffect", .size = sizeof(DeathFx), .update = deathfx_update, .render = deathfx_render};+static void seeker_squish(Ent *e, Collision *c) {+ if (actor_try_squish_wiggle(e, c)) return;+ Ent *d = ent_new(&DEATHFX, e->x, e->y);+ if (d) {+ d->depth = -1000000;+ d->collidable = 0;+ ST(d, DeathFx)->color = rgb(0xFF69B4);+ }+ ent_remove(e);+}++/* RecoverBlast: the shockwave sprite, gone after its last frame */+static void recover_update(Ent *e) {+ if (cs_update(ST(e, CSpr)) >= 0) ent_remove(e);+}+static void recover_render(Ent *e) { cs_draw(ST(e, CSpr), e->x, e->y, 1, 1, 0, 0xFFFF, 255); }+static const EntClass RECOVER = {.name = "seekerRecoverBlast", .size = sizeof(CSpr), .update = recover_update, .render = recover_render};++static Ent *spawn_seeker(float x, float y, int tab, float light) {+ Ent *e = ent_new(&SEEKER, x, y);+ if (!e) {+ if (tab >= 0) tab_free(tab);+ return NULL;+ }+ e->depth = -200;+ ent_box(e, 6, 6, -3, -3);+ e->ignore_jumpthrus = 1;+ Seeker *s = ST(e, Seeker);+ s->tab = (uint8_t)(tab < 0 ? SEEKER_TAB : tab);+ if (tab >= 0) seeker_tab[tab].owner = e;+ s->facing = s->sprite_facing = 1;+ s->next = 255;+ s->sx = s->sy = 1;+ s->light = light;+ s->bounce_w = 12, s->bounce_x = -6;+ s->last_spotted = s->last_path_to = v2(0, 0);+ wiggler_init(&s->wig, 0.8f, 2);+ cs_init(&s->spr, SB_seeker);+ s->state = 255;+ seeker_set_state(e, SK_IDLE);+ Ent *pc[2];+ for (int k = 0; k < 2; k++) {+ pc[k] = ent_new(&SEEKERPC, x, y);+ if (pc[k]) pc[k]->visible = 0, ST(pc[k], SeekerPC)->owner = ent_ref(e);+ }+ if (pc[0] && pc[1] && pc[1] < pc[0]) { /* the player checks them by slot: the attack one first */+ Ent *t = pc[0];+ pc[0] = pc[1], pc[1] = t;+ }+ s = ST(e, Seeker);+ for (int k = 0; k < 2; k++) {+ s->pc[k] = ent_ref(pc[k] ? pc[k] : e);+ if (pc[k]) ST(pc[k], SeekerPC)->bounce = (uint8_t)k;+ }+ seeker_sync_colliders(e);+ return e;+}+static void new_seeker(const EData *d) {+ int tab = tab_alloc(NULL, d);+ if (tab < 0) return;+ spawn_seeker(d->x, d->y, tab, 1);+}+/* ---------------------------------------------------------------- SeekerStatue */+typedef struct { CSpr spr; float alarm; uint8_t player_right, tab, pad[2]; } Statue;+static void breakout_particles(V2 c) {+ for (float a = 0; a < PI_F * 2; a += 0.17453292f) {+ V2 at = v2add(c, angle_vec(a + rnd_rangef(-PI_F / 90, PI_F / 90), (float)(12 + rndi(8))));+ particles_emit1(PL_MID, &P_Seeker_P_BreakOut, at, a);+ }+}+static void statue_update(Ent *e) {+ Statue *s = ST(e, Statue);+ int ended = cs_update(&s->spr);+ if (ended == A_seeker_hatch) { /* OnLastFrame("hatch"): the seeker breaks out */+ int tab = s->tab;+ s->tab = 255;+ float x = e->x, y = e->y;+ ent_remove(e);+ spawn_seeker(x, y, tab, 0);+ return;+ }+ if (s->alarm > 0 && (s->alarm -= DT) <= 0) breakout_particles(v2(e->x, e->y));+ Ent *pe = level_player_ent();+ if (!pe || cs_cur(&s->spr) != A_seeker_statue) return;+ bool go = s->player_right ? pe->x > e->x + 32 : v2len(v2sub(v2(pe->x, pe->y), v2(e->x, e->y))) < 220;+ if (go) {+ breakout_particles(v2(e->x, e->y));+ cs_play(&s->spr, A_seeker_hatch, false);+ s->alarm = 0.8f;+ }+}+static void statue_render(Ent *e) { cs_draw(&ST(e, Statue)->spr, e->x, e->y, 1, 1, 0, 0xFFFF, 255); }+static void statue_removed(Ent *e) {+ Statue *s = ST(e, Statue);+ if (s->tab < SEEKER_TAB && seeker_tab[s->tab].owner == e) tab_free(s->tab);+}+static const EntClass STATUE = {.name = "seekerStatue", .size = sizeof(Statue), .update = statue_update, .render = statue_render,+ .removed = statue_removed};+static void new_statue(const EData *d) {+ Ent *e = ent_new(&STATUE, d->x, d->y);+ if (!e) return;+ e->depth = 8999;+ e->collidable = 0;+ Statue *s = ST(e, Statue);+ s->player_right = !strcmp(EAS(d, seekerStatue, hatch), "PlayerRightOfX");+ int tab = tab_alloc(e, d);+ s = ST(e, Statue);+ s->tab = (uint8_t)(tab < 0 ? 255 : tab);+ cs_init(&s->spr, SB_seeker);+ cs_play(&s->spr, A_seeker_statue, false);+}++/* ---------------------------------------------------------------- TempleMirrorPortal */+typedef struct {+ uint8_t can_trigger, counter, nroutines, active; /* active: Activate()'s coroutine (2: from the next update) */+ uint8_t step[2];+ int8_t side[2];+ float wait[2];+ float light_target, buffer_alpha, buffer_timer, debris_start, distortion_fade;+ uint8_t curtain, torch[2], pad2; /* entities */+} Portal;+/* the story's memory in the chapter's: the portal's debris, the fade carried into the void */+#define PDEBRIS 50+typedef struct { const Ent *e; int x, y; } PortalJob; /* what the portal's strip layers draw */+typedef struct {+ float dpct[PDEBRIS]; /* < 0: not Enabled */+ uint8_t dang[PDEBRIS], ddur[PDEBRIS]; /* direction (1/256 turn), duration (0.5 + n / 255 * 0.7) */+ PortalJob job;+ float portal_fade; /* CS04_MirrorPortal's Fader, into the next room */+ uint8_t portal_wake, room_seen;+} Story5;+enum { OFF_story5 = ((END_seeker_nodes + 7) & ~7), END_story5 = OFF_story5 + (int)sizeof(Story5) };+#define story5 (*(Story5 *)(void *)(g_chram[5] + OFF_story5))+static bool have_story5(void) { return g_level.ch && (rd16(g_level.ch + CH_FILES) >> 5 & 1); }+typedef struct { CSpr spr; uint8_t dropped, pad[3]; } Curtain;+typedef struct { float bloom, light; uint8_t lit, pad[3]; float t; } PTorch;+static uint16_t ptorch_tex[7];+static const EntClass PORTAL, CURTAIN, PORTALBG, PTORCH;+static void ptorch_light(Ent *t) {+ PTorch *p = ST(t, PTorch);+ p->lit = 1, p->t = 0;+ p->bloom = 1, p->light = 0;+}+static void ptorch_update(Ent *e) {+ PTorch *p = ST(e, PTorch);+ if (!p->lit) return;+ p->t += DT;+ if (p->bloom > 0.5f) p->bloom -= DT;+ if (p->light < 1) p->light = approach(p->light, 1, DT);+}+static void ptorch_render(Ent *e) {+ PTorch *p = ST(e, PTorch);+ int f = p->lit ? 1 + (int)floorf(p->t / 0.08f) % 6 : 0; /* "lit": frames 1-6 */+ gfx_tex_ex(fam_tex(ptorch_tex, 7, f), e->x, e->y, 32, 64, 1, 1, 0, 0xFFFF, 255, 0);+ if (p->lit) {+ light_add(e->x, e->y, 0x20B2AA, p->light, 32, 128); /* Color.LightSeaGreen */+ bloom_add(e->x, e->y, p->bloom, 16);+ }+}+static const EntClass PTORCH = {.name = "templePortalTorch", .size = sizeof(PTorch), .update = ptorch_update, .render = ptorch_render};++static void curtain_drop(Ent *c) {+ Curtain *k = ST(c, Curtain);+ cs_play(&k->spr, A_temple_portal_curtain_fall, false);+ c->depth = -8999;+ ents_mark_unsorted();+ c->collidable = 1;+ bool hit = false;+ Ent *pe = level_player_ent();+ while (pe && collide_ent_at(c, c->x, c->y, pe) && !hit) {+ c->collidable = 0;+ hit = actor_move_v(pe, -1, NULL, NULL);+ c->collidable = 1;+ }+}+static void curtain_update(Ent *e) {+ plat_update(e);+ cs_update(&ST(e, Curtain)->spr);+ if (!e->collidable) return;+ Ent *pe = level_player_ent();+ Player *p = level_player();+ if (!pe || !p) return;+ if (collide_ent_at(e, e->x - 1, e->y, pe) && actor_on_ground(pe, 1) && g_in.aim_x > 0) {+ actor_move_v(pe, e_top(e) - e_bottom(pe), NULL, NULL);+ actor_move_h(pe, 1, NULL, NULL);+ } else if (collide_ent_at(e, e->x + 1, e->y, pe) && actor_on_ground(pe, 1) && g_in.aim_x < 0) {+ actor_move_v(pe, e_top(e) - e_bottom(pe), NULL, NULL);+ actor_move_h(pe, -1, NULL, NULL);+ }+}+static void curtain_render(Ent *e) { cs_draw(&ST(e, Curtain)->spr, e->x, e->y, 1, 1, 0, 0xFFFF, 255); }+static const EntClass CURTAIN = {.name = "templePortalCurtain", .size = sizeof(Curtain), .update = curtain_update,+ .render = curtain_render, .kind = KIND_SOLID};+static void portalbg_render(Ent *e) {+ draw_centered(T_objects_temple_portal_surface, e->x, e->y, 0xFFFF, 255, 1, 1, 0);+ /* MirrorSurface: the reflections are not drawn */+}+static const EntClass PORTALBG = {.name = "templePortalBg", .render = portalbg_render};++static void portal_switch_hit(int side) { /* TempleMirrorPortal.OnSwitchHit: a new OnSwitchRoutine */+ Ent *e = first_of(&PORTAL);+ if (!e) return;+ Portal *p = ST(e, Portal);+ if (p->nroutines >= 2) return;+ int i = p->nroutines++;+ p->step[i] = 0, p->side[i] = (int8_t)side, p->wait[i] = 0.4f;+}+static void portal_activate_step(Portal *p) { /* ActivateRoutine, an update of it */+ Story5 *st = &story5;+ p->buffer_alpha = approach(p->buffer_alpha, 1, DT);+ p->buffer_timer += 4 * DT;+ g_level.lighting = approach(g_level.lighting, 0.2f, DT * 0.25f);+ if (p->debris_start < PDEBRIS) {+ int n = (int)p->debris_start;+ st->dang[n] = (uint8_t)rndi(256);+ st->ddur[n] = (uint8_t)(rndf() * 255);+ if (st->dpct[n] < 0) st->dpct[n] = 0; /* Enabled */+ }+ p->debris_start += DT * 10;+ for (int i = 0; i < PDEBRIS; i++)+ if (st->dpct[i] >= 0) st->dpct[i] = fmodf(st->dpct[i], 1) + DT / (0.5f + st->ddur[i] / 255.f * 0.7f);+}+static void portal_update(Ent *e) {+ Portal *p = ST(e, Portal);+ if (p->active == 1) portal_activate_step(p);+ else if (p->active == 2) p->active = 1;+ for (int i = 0; i < p->nroutines; i++) {+ if (p->wait[i] > 0) {+ p->wait[i] -= DT;+ continue;+ }+ switch (p->step[i]) {+ case 0: {+ Ent *t = ent_at(p->torch[p->side[i] < 0 ? 0 : 1]);+ if (t->cls == &PTORCH) ptorch_light(t);+ p->counter++;+ p->light_target = fmaxf(0, g_level.lighting - 0.2f);+ p->step[i] = 1;+ }+ /* fall through */+ case 1:+ if (g_session.mode == 0 && (g_level.lighting -= DT) > p->light_target) break;+ p->wait[i] = 0.15f;+ p->step[i] = 2;+ break;+ case 2:+ if (p->counter < 2) {+ p->step[i] = 9;+ break;+ }+ p->wait[i] = 0.1f;+ p->step[i] = 3;+ break;+ case 3:+ if (ent_at(p->curtain)->cls == &CURTAIN) curtain_drop(ent_at(p->curtain));+ p->can_trigger = 1;+ p->wait[i] = 0.1f;+ p->step[i] = 4;+ break;+ case 4:+ for (int x = 0; x < 120; x += 12)+ for (int y = 0; y < 60; y += 6)+ particles_emit(PL_MID, &P_TempleMirrorPortal_P_CurtainDrop, 1, v2(ent_at(p->curtain)->x - 57 + x, ent_at(p->curtain)->y - 27 + y),+ v2(6, 3), 0);+ p->step[i] = 9;+ break;+ }+ }+}+/* the portal's buffer (BeforeRender): objects/temple/portal/portal drawn ten times, black to purple, growing and+ * turning, in 120 x 64; each copy covers what is outside its hole (radius 60 x its scale): rings */+static void portal_buffer_strip(uint16_t *strip, int sy0, int sy1, void *ctx) {+ const PortalJob *j = ctx;+ const Portal *p = ST(j->e, Portal);+ float t = fmodf(p->buffer_timer, 1) * 0.1f;+ int a = (int)(p->buffer_alpha * 256);+ for (int y = j->y < sy0 ? sy0 : j->y; y < j->y + 64 && y < sy1; y++) {+ float dy = y - j->y + 0.5f - 32;+ uint16_t *row = strip + (y - sy0) * VIEW_W;+ for (int x = j->x < 0 ? 0 : j->x; x < j->x + 120 && x < VIEW_W; x++) {+ float dx = x - j->x + 0.5f - 60, d = sqrtf(dx * dx + dy * dy), num = 0;+ for (int i = 9; i >= 0; i--)+ if (d >= 60 * (t + i / 10.f) && d <= 150 * (t + i / 10.f)) {+ num = t + i / 10.f;+ break;+ }+ int c = (int)(128 * num); /* Color.Lerp(Black, Purple, num) */+ row[x] = blend565(row[x], rgb((uint32_t)(c << 16 | c)), a);+ }+ }+}+/* the debris: particles/blob in Color.Lerp(f442d4, black), scaled 1 to 0.2, flying in */+static void portal_debris_strip(uint16_t *strip, int sy0, int sy1, void *ctx) {+ const Ent *e = ((const PortalJob *)ctx)->e;+ const Story5 *st = &story5;+ for (int i = 0; i < PDEBRIS; i++) {+ if (st->dpct[i] < 0) continue;+ float num = ease_sine_out(st->dpct[i]);+ V2 at = v2add(v2(e->x, e->y), angle_vec(st->dang[i] / 256.f * 2 * PI_F, (1 - num) * (190 - g_level.zoom * 30)));+ uint16_t col = lerp565(0xF442D4, 0, num);+ float r = 4 * (1 - 0.8f * clampf(num, 0, 1)), cx = at.x - g_camx, cy = at.y - g_camy;+ for (int y = (int)floorf(cy - r); y <= (int)ceilf(cy + r); y++) {+ if (y < sy0 || y >= sy1) continue;+ for (int x = (int)floorf(cx - r); x <= (int)ceilf(cx + r); x++) {+ float dx = x + 0.5f - cx, dy = y + 0.5f - cy;+ if ((unsigned)x < VIEW_W && dx * dx + dy * dy <= r * r) strip[(y - sy0) * VIEW_W + x] = col;+ }+ }+ }+}+static void portal_render(Ent *e) {+ Portal *p = ST(e, Portal);+ PortalJob *j = &story5.job;+ if (p->active) {+ j->e = e, j->x = (int)floorf(e->x - 60) - g_camx, j->y = (int)floorf(e->y - 32) - g_camy;+ if (p->buffer_alpha > 0) gfx_custom(portal_buffer_strip, j, j->y, j->y + 64);+ }+ draw_centered(T_objects_temple_portal_portalframe, e->x, e->y, 0xFFFF, 255, 1, 1, 0);+ if (p->active) gfx_custom(portal_debris_strip, j, 0, VIEW_H);+}++/* ---------------------------------------------------------------- CS04_MirrorPortal */+/* the Fader: black over the level, and Madeline over it while she floats */+typedef struct { float fade, target; uint8_t ended, first; } PFader;+static void pfader_update(Ent *e) {+ PFader *f = ST(e, PFader);+ if (f->first) { /* in the room after: the wipe is cancelled, Madeline wakes up there (B-side) */+ f->first = 0;+ g_wipe.active = false;+ Player *p = level_player();+ if (story5.portal_wake && p) {+ spr_play(&p->spr, A_player_asleep, false);+ p->facing = 1;+ player_set_state(p, ST_INTROWAKEUP);+ }+ story5.portal_fade = 0, story5.portal_wake = 0;+ }+ f->fade = approach(f->fade, f->target, DT * 0.5f);+ if (f->target <= 0 && f->fade <= 0 && f->ended) ent_remove(e);+}+static void pfader_render(Ent *e) {+ PFader *f = ST(e, PFader);+ if (f->fade > 0) gfx_rect(g_level.cam.x - 10, g_level.cam.y - 10, 340, 200, 0, a8(f->fade));+ Player *p = level_player();+ if (p && !actor_on_ground(p->ent, 2) && p->ent->cls->render) p->ent->cls->render(p->ent);+}+static const EntClass PFADER = {.name = "mirrorPortalFader", .size = sizeof(PFader), .update = pfader_update, .render = pfader_render};+static Ent *pfader_new(float fade, float target) {+ Ent *e = ent_new(&PFADER, 0, 0);+ if (!e) return NULL;+ e->depth = -1000000;+ e->collidable = 0;+ ST(e, PFader)->fade = fade, ST(e, PFader)->target = target;+ return e;+}+typedef struct {+ Cutscene cs;+ Ent *portal, *fader;+ Walk walk;+ Step zoom, step;+ V2 from, target;+ float p;+ uint8_t centering, zooming;+} MPortal;+static void mportal_update(Ent *e) {+ MPortal *s = ST(e, MPortal);+ Player *p = &g_player;+ Ent *pe = p->ent, *po = s->portal;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_dummy(p);+ p->dashes = 1;+ s->centering = 1; /* CenterCamera() */+ CO_WALK(c, s->walk, walk_exact((int)po->x));+ CO_WAIT(c, 0.25f);+ CO_WALK(c, s->walk, walk_exact((int)po->x - 16));+ CO_WAIT(c, 0.5f);+ CO_WALK(c, s->walk, walk_exact((int)po->x + 16));+ CO_WAIT(c, 0.25f);+ p->facing = -1;+ CO_WAIT(c, 0.25f);+ CO_WALK(c, s->walk, walk_exact((int)po->x));+ CO_WAIT(c, 0.1f);+ p->dummy_auto_animate = false;+ spr_play(&p->spr, A_player_lookUp, false);+ CO_WAIT(c, 1);+ p->dummy_auto_animate = true;+ ST(po, Portal)->active = 2; /* Activate() */+ step_reset(&s->zoom);+ s->zooming = 2; /* ZoomTo((160, 90), 3, 12) in a coroutine of its own */+ CO_WAIT(c, 0.25f);+ /* (ForceStrongWindHair.X = -1: the hair blown back is not here) */+ CO_WALK(c, s->walk, walk_back((int)pe->x + 12));+ CO_WAIT(c, 0.5f);+ p->facing = 1;+ p->dummy_auto_animate = false;+ p->dummy_gravity = false;+ spr_play(&p->spr, A_player_runWind, false);+ while (p->spr.rate > 0) {+ actor_move_h(pe, p->spr.rate * 10 * DT, NULL, NULL);+ actor_move_v(pe, -(1 - p->spr.rate) * 6 * DT, NULL, NULL);+ p->spr.rate -= DT * 0.15f;+ CO_YIELD(c);+ }+ CO_WAIT(c, 0.5f);+ spr_play(&p->spr, A_player_fallFast, false);+ p->spr.rate = 1;+ s->target = v2(po->x, po->y + 8);+ s->from = v2(pe->x, pe->y);+ for (s->p = 0; s->p < 1; s->p += DT * 2) {+ {+ V2 at = v2lerp(s->from, s->target, ease_sine_inout(s->p));+ pe->x = at.x, pe->y = at.y;+ }+ CO_YIELD(c);+ }+ if (s->fader && s->fader->cls == &PFADER) ST(s->fader, PFader)->target = 1;+ CO_WAIT(c, 2);+ spr_play(&p->spr, A_player_sleep, false);+ CO_WAIT(c, 1);+ CO_ZOOM_BACK(c, &s->step, 1);+ if (g_session.mode == M_A) /* the "templevoid" grade, Glitch and ScreenPadding growing over a second: not drawn */+ for (s->p = 0; s->p < 1; s->p += DT) CO_YIELD(c);+ while ((ST(po, Portal)->distortion_fade -= DT * 2) > 0) CO_YIELD(c);+ cutscene_end(e);+ return;+ CO_END(c);+}+static void mportal_tick(Ent *e) {+ MPortal *s = ST(e, MPortal);+ mportal_update(e);+ if (e->dead == 1) return;+ if (s->centering) {+ V2 t = v2(s->portal->x - 160, s->portal->y - 90);+ if (v2len(v2sub(g_level.cam, t)) > 1) g_level.cam = v2add(g_level.cam, v2mul(v2sub(t, g_level.cam), 1 - powf(0.01f, DT)));+ else s->centering = 0;+ }+ if (s->zooming == 2) s->zooming = 1;+ else if (s->zooming && !zoom_to(&s->zoom, v2(160, 90), 3, 12)) s->zooming = 0;+}+static void mportal_end(Ent *e, bool skipped) { /* OnEnd: the next room at the end of the frame */+ MPortal *s = ST(e, MPortal);+ if (have_story5()) {+ story5.portal_fade = !skipped && s->fader && s->fader->cls == &PFADER ? fmaxf(ST(s->fader, PFader)->fade, 0.01f) : 0;+ story5.portal_wake = g_session.mode != M_A;+ }+ g_session.dreaming = 1;+ g_session.nkeys = 0;+ /* the level moves on at the frame's end, at the spawn nearest the room's top left */+ int r = g_session.mode == M_A ? room_index("void", 4) : room_index("c-00", 4);+ if (r >= 0) level_load_room_near(r, g_session.mode == M_A ? INTRO_TEMPLEMIRRORVOID : INTRO_WAKEUP, 0, 0);+}+static const EntClass MPORTAL = {.name = "CS04_MirrorPortal", .size = sizeof(MPortal), .update = mportal_tick};+static void portal_on_player(Ent *e, Player *pl) {+ (void)pl;+ Portal *p = ST(e, Portal);+ if (!p->can_trigger) return;+ p->can_trigger = 0;+ Ent *cs = scene_new(&MPORTAL, mportal_end, true, false);+ if (!cs) return;+ MPortal *s = ST(cs, MPortal);+ s->portal = e;+ s->fader = pfader_new(0, 0);+}+/* a room is loading: the fade from the portal goes on in it */+static void story5_room(void) {+ if (!have_story5() || !g_level.room || story5.room_seen == (uint8_t)(g_level.room->index + 1)) return;+ story5.room_seen = (uint8_t)(g_level.room->index + 1);+ if (story5.portal_fade > 0) {+ Ent *f = pfader_new(story5.portal_fade, 0);+ if (f) ST(f, PFader)->ended = 1, ST(f, PFader)->first = 1;+ }+}+static const EntClass PORTAL = {.name = "templeMirrorPortal", .size = sizeof(Portal), .update = portal_update, .render = portal_render,+ .on_player = portal_on_player, .kind = KIND_PCOLLIDE};+static void new_portal(const EData *d) {+ Ent *e = ent_new(&PORTAL, d->x, d->y);+ if (!e) return;+ e->depth = 2000;+ ent_box(e, 120, 64, -60, -32);+ Ent *c = ent_new(&CURTAIN, d->x, d->y);+ if (c) {+ c->depth = 1999;+ ent_box(c, 140, 12, -70, 33);+ c->safe = 1;+ c->collidable = 0;+ cs_init(&ST(c, Curtain)->spr, SB_temple_portal_curtain);+ }+ Ent *bg = ent_new(&PORTALBG, d->x, d->y);+ if (bg) bg->depth = 9500, bg->collidable = 0;+ if (!ptorch_tex[0]) tex_family("objects/temple/portal/portaltorch", ptorch_tex, 7);+ Ent *t[2];+ for (int i = 0; i < 2; i++) {+ t[i] = ent_new(&PTORCH, d->x + (i ? 90 : -90), d->y);+ if (t[i]) t[i]->depth = 8999, t[i]->collidable = 0;+ }+ Portal *p = ST(e, Portal);+ p->distortion_fade = 1;+ if (have_story5())+ for (int i = 0; i < PDEBRIS; i++) story5.dpct[i] = -1;+ p->curtain = ent_ref(c ? c : e);+ p->torch[0] = ent_ref(t[0] ? t[0] : e), p->torch[1] = ent_ref(t[1] ? t[1] : e);+}++/* ---------------------------------------------------------------- TempleBigEyeball */+typedef struct {+ CSpr spr;+ Wiggler bounce, pupil_w;+ V2 pupil, pupil_target;+ float pupil_delay, pupil_speed, shock_timer, co_wait, fade;+ Step zoom;+ V2 zoom_at;+ uint8_t triggered, shock_flag, bursting, co, pupil_visible, scene, zooming, pad;+} BigEye;+/* Burst()'s Level.StartCutscene(OnSkip): its skip completes the area */+typedef struct { Cutscene cs; } EyeBurst;+static void eyeburst_end(Ent *e, bool skipped) {+ (void)e, (void)skipped;+ level_complete_area(false, false);+}+static const EntClass EYEBURST = {.name = "templeBigEyeballBurst", .size = sizeof(EyeBurst)};+typedef struct { uint8_t hit, pad[3]; } Shockwave;+static void shock_on_player(Ent *e, Player *p) {+ if (p->state == ST_DASH) return;+ p->speed.x = -100;+ if (p->speed.y > 30) p->speed.y = 30;+ ST(e, Shockwave)->hit = 1;+}+static void shock_update(Ent *e) {+ e->x -= 300 * DT;+ if (e->x < g_level.room->x - 20) ent_remove(e);+ /* the displacement ring is not drawn */+}+static const EntClass SHOCKWAVE = {.name = "templeBigEyeballShockwave", .size = sizeof(Shockwave), .update = shock_update,+ .on_player = shock_on_player, .kind = KIND_PCOLLIDE};+static void bigeye_on_player(Ent *e, Player *p) {+ BigEye *b = ST(e, BigEye);+ if (b->triggered) return;+ player_explode_launch(p, v2add(player_center(p), v2(20, 0)), true);+ wiggler_restart(&ST(e, BigEye)->bounce);+}+static void bigeye_on_holdable(Ent *e, Ent *theo) {+ BigEye *b = ST(e, BigEye);+ Theo *t = ST(theo, Theo);+ if (b->triggered || t->speed.x <= 32 || t->held) return;+ t->speed = v2(-50, -10);+ b->triggered = 1;+ wiggler_restart(&b->bounce);+ e->collidable = 0;+ b->bursting = 1; /* Burst() */+ b->co = 1;+ /* Level.StartCutscene(OnSkip, fadeInOnSkip: false, endingChapterAfterCutscene: true), RegisterAreaComplete */+ Ent *sc = scene_new(&EYEBURST, eyeburst_end, false, true);+ b->scene = ent_ref(sc ? sc : e);+ level_register_complete();+ level_freeze(0.1f);+}+static void bigeye_update(Ent *e) {+ BigEye *b = ST(e, BigEye);+ cs_update(&b->spr);+ wiggler_update(&b->bounce);+ wiggler_update(&b->pupil_w);+ Player *pl = level_player();+ if (b->co) { /* Burst() */+ if (b->co_wait > 0) b->co_wait -= DT;+ else+ switch (b->co++) {+ case 1: break; /* yield null */+ case 2: {+ g_level.in_cutscene = true;+ if (pl) {+ player_set_state(pl, ST_DUMMY);+ pl->state_locked = true;+ if (pl->on_ground) pl->dummy_auto_animate = false, spr_play(&pl->spr, A_player_shaking, false);+ }+ Ent *th = theo_entity();+ if (th) {+ b->zoom_at = v2(th->x - g_level.cam.x, th->y - 10 - g_level.cam.y);+ step_reset(&b->zoom);+ b->zooming = 2;+ ST(th, Theo)->shattering = 1; /* theo.Shatter() */+ ST(th, Theo)->co = 0, ST(th, Theo)->co_p = 0;+ }+ eyes_burst_all();+ cs_play(&b->spr, A_temple_eyeball_burst, false);+ b->pupil_visible = 0;+ level_shake(0.4f);+ b->co_wait = 2;+ break;+ }+ case 3:+ if (pl && pl->on_ground) pl->dummy_auto_animate = false, spr_play(&pl->spr, A_player_shaking, false);+ e->visible = 0;+ /* fall through */+ default:+ if ((b->fade += DT) < 1) b->co = 4; /* the Fader */+ else b->co_wait = 1, b->co = 99;+ break;+ case 99: /* Level.EndCutscene, CompleteArea(spotlightWipe: false) */+ b->co = 0;+ if (ent_at(b->scene)->cls == &EYEBURST) cutscene_end(ent_at(b->scene));+ else level_complete_area(false, false);+ return;+ }+ }+ if (b->zooming == 2) b->zooming = 1; /* ZoomTo(theo.TopCenter, 2, 0.5): a coroutine of its own */+ else if (b->zooming && !zoom_to(&b->zoom, b->zoom_at, 2, 0.5f)) b->zooming = 0;+ Ent *pe = level_player_ent();+ if (!b->triggered && b->shock_timer > 0) {+ b->shock_timer -= DT;+ if (b->shock_timer <= 0) {+ if (pe) {+ b->shock_timer = clamped_map(fabsf(e->x - pe->x), 100, 500, 2, 3);+ b->shock_flag = !b->shock_flag;+ if (b->shock_flag) b->shock_timer -= 1;+ }+ Ent *s = ent_new(&SHOCKWAVE, e->x + 50, e->y);+ if (s) {+ s->depth = -1000000;+ ent_box(s, 48, 200, -30, -100);+ }+ b = ST(e, BigEye);+ wiggler_restart(&b->pupil_w);+ b->pupil_target = v2(-1, 0);+ b->pupil_speed = 120;+ b->pupil_delay = fmaxf(0.5f, b->pupil_delay);+ }+ }+ b->pupil = approach_v(b->pupil, v2mul(b->pupil_target, 12), DT * b->pupil_speed);+ b->pupil_speed = approach(b->pupil_speed, 40, DT * 400);+ Ent *th = theo_entity();+ if (th && fabsf(e->x - th->x) < 64 && fabsf(e->y - th->y) < 64) b->pupil_target = safe_norm(v2sub(theo_center(th), v2(e->x, e->y)), 1);+ else if (b->pupil_delay < 0) {+ b->pupil_target = angle_vec(rndf() * PI_F * 2, 1);+ static const float CH[3] = {0.2f, 1, 2};+ b->pupil_delay = CH[rndi(3)];+ } else+ b->pupil_delay -= DT;+}+static void bigeye_render(Ent *e) {+ BigEye *b = ST(e, BigEye);+ cs_draw(&b->spr, e->x, e->y, 1 + 0.15f * b->bounce.value, 1, 0, 0xFFFF, 255);+ float s = 1 + b->pupil_w.value * 0.15f;+ if (b->pupil_visible) draw_centered(T_danger_templeeye_pupil, e->x + b->pupil.x, e->y + b->pupil.y, 0xFFFF, 255, s, s, 0);+}+/* the Fader: white over everything (Tags.HUD) */+typedef struct { uint8_t eye, pad[3]; } EyeFader;+static void eyefader_render(Ent *e) {+ Ent *b = ent_at(ST(e, EyeFader)->eye);+ if (b->cls != &BIGEYE || ST(b, BigEye)->fade <= 0) return;+ gfx_hud(true);+ gfx_rect(0, 0, 320, 180, 0xFFFF, a8(ST(b, BigEye)->fade));+ gfx_hud(false);+}+static const EntClass EYEFADER = {.name = "templeBigEyeballFader", .size = sizeof(EyeFader), .render = eyefader_render};+static const EntClass BIGEYE = {.name = "templeBigEyeball", .size = sizeof(BigEye), .update = bigeye_update, .render = bigeye_render,+ .on_player = bigeye_on_player, .kind = KIND_PCOLLIDE};+static void new_bigeye(const EData *d) {+ Ent *e = ent_new(&BIGEYE, d->x, d->y);+ if (!e) return;+ ent_box(e, 48, 64, -24, -32);+ BigEye *b = ST(e, BigEye);+ cs_init(&b->spr, SB_temple_eyeball);+ wiggler_init(&b->bounce, 0.5f, 3);+ wiggler_init(&b->pupil_w, 0.5f, 3);+ b->shock_timer = 2;+ b->pupil_speed = 40;+ b->pupil_visible = 1;+ Ent *f = ent_new(&EYEFADER, 0, 0);+ if (f) {+ f->depth = D_TOP;+ f->collidable = 0;+ ST(f, EyeFader)->eye = ent_ref(e);+ }+}++/* ---------------------------------------------------------------- PlayerSeeker (the void) */+typedef struct {+ CSpr spr;+ V2 speed, dash_dir;+ float dash_timer, trail_a, trail_b, sx, sy, co_wait, tween;+ V2 cam_from;+ Shaker shaker;+ int8_t facing;+ uint8_t enabled, co, pad;+} PSeeker;+static V2 pseeker_cam(Ent *e) {+ Room *rm = g_level.room;+ return v2(clampf(e->x - 160, rm->x, rm->x + rm->w - 320), clampf(e->y - 90, rm->y, rm->y + rm->h - 180));+}+static void pseeker_trail(Ent *e) {+ PSeeker *s = ST(e, PSeeker);+ uint16_t t = cs_tex(&s->spr);+ if (t != 0xFFFF) trail_add(e->x, e->y, t, 48, 48, s->sx * s->facing, s->sy, 0x99E550, 1);+}+static void pseeker_dash(Ent *e, V2 dir) {+ PSeeker *s = ST(e, PSeeker);+ if (s->dash_timer <= 0) {+ pseeker_trail(e);+ s->trail_a = 0.1f, s->trail_b = 0.25f;+ }+ s->dash_timer = 0.3f;+ s->dash_dir = dir;+ if (dir.x == 0 && dir.y == 0) s->dash_dir.x = (float)s->facing;+ if (s->dash_dir.x != 0) s->facing = (int8_t)sgn(s->dash_dir.x);+ s->speed = v2mul(s->dash_dir, 400);+ cs_play(&s->spr, A_seeker_attacking, false);+ level_dir_shake(s->dash_dir, 0.3f);+ if (s->dash_dir.x == 0) s->sx = 0.6f, s->sy = 1.4f;+ else s->sx = 1.4f, s->sy = 0.6f;+}+static void pseeker_collide(Ent *e, Collision *c) {+ PSeeker *s = ST(e, PSeeker);+ if (s->dash_timer <= 0) {+ if (c->dir.x != 0) s->speed.x = 0;+ if (c->dir.y != 0) s->speed.y = 0;+ return;+ }+ float dir;+ V2 at, range;+ if (c->dir.x > 0) dir = PI_F, at = v2(e_right(e), e->y), range = v2(0, 4);+ else if (c->dir.x < 0) dir = 0, at = v2(e_left(e), e->y), range = v2(0, 4);+ else if (c->dir.y > 0) dir = -PI_F / 2, at = v2(e->x, e_bottom(e)), range = v2(4, 0);+ else dir = PI_F / 2, at = v2(e->x, e_top(e)), range = v2(4, 0);+ particles_emit(PL_MID, &P_Seeker_P_HitWall, 12, at, range, dir);+ if (c->hit && c->hit->cls == &BARRIER) barrier_reflect(c->hit);+ if (c->dir.x != 0) s->speed.x *= -0.8f, s->sx = 0.6f, s->sy = 1.4f;+ else if (c->dir.y != 0) s->speed.y *= -0.8f, s->sx = 1.4f, s->sy = 0.6f;+ if (c->hit && c->hit->cls == &CRACKED) {+ level_freeze(0.15f);+ cracked_break(c->hit, v2(e->x, e->y));+ }+}+static void pseeker_on_player(Ent *e, Player *p) {+ if (p->dead) return;+ /* Leader.StoreStrawberries: TODO; Engine.TimeRate 0.25 */+ player_die(p, safe_norm(v2sub(v2(p->ent->x, p->ent->y), v2(e->x, e->y)), 1), true);+ int idx = room_index("c-00", 4); /* End(): then c-00, waking up */+ if (idx >= 0 && g_level.room) g_level.room->index = idx, g_session.has_respawn = 0;+ g_level.can_retry = true;+}+/* Player.StartTempleMirrorVoidSleep (the TempleMirrorVoid intro) */+static void pseeker_sleep(void) {+ Player *p = level_player();+ if (!p) return;+ spr_play(&p->spr, A_player_asleep, false);+ p->facing = 1;+ player_set_state(p, ST_DUMMY);+ p->state_locked = true;+ p->dummy_auto_animate = false;+ p->dummy_gravity = false;+}+static void pseeker_update(Ent *e) {+ PSeeker *s = ST(e, PSeeker);+ barriers_collidable(true);+ /* IntroSequence */+ if (s->co_wait > 0) s->co_wait -= DT;+ else+ switch (s->co) {+ case 0: s->co = 1; break; /* yield null */+ case 1:+ pseeker_sleep(); /* (already asleep: the intro did it) */+ s->co_wait = 3, s->co = 2;+ break;+ case 2:+ s->cam_from = g_level.cam;+ s->tween = 0;+ s->co_wait = 2, s->co = 3;+ break;+ case 3:+ shaker_for(&s->shaker, 0.5f);+ breakout_particles(v2(e->x, e->y));+ s->co_wait = 1, s->co = 4;+ break;+ case 4:+ shaker_for(&s->shaker, 0.5f);+ breakout_particles(v2(e->x, e->y));+ s->co_wait = 1, s->co = 5;+ break;+ case 5:+ breakout_particles(v2(e->x, e->y));+ shaker_for(&s->shaker, 1);+ cs_play(&s->spr, A_seeker_hatch, false);+ s->enabled = 1;+ s->co_wait = 0.8f, s->co = 6;+ break;+ case 6:+ breakout_particles(v2(e->x, e->y));+ s->co_wait = 0.7f, s->co = 7;+ break;+ }+ if (s->co >= 3 && s->tween < 1) { /* the camera's tween to the seeker */+ s->tween = fminf(1, s->tween + DT / 2);+ g_level.cam = v2add(s->cam_from, v2mul(v2sub(pseeker_cam(e), s->cam_from), ease_sine_inout(s->tween)));+ }+ shaker_update(&s->shaker);+ int ended = cs_update(&s->spr);+ if ((ended == A_seeker_flipMouth || ended == A_seeker_flipEyes)) s->facing = (int8_t)-s->facing;+ s->sx = approach(s->sx, 1, 2 * DT);+ s->sy = approach(s->sy, 1, 2 * DT);+ if (s->enabled && cs_cur(&s->spr) != A_seeker_hatch) {+ if (s->dash_timer > 0) {+ s->speed = approach_v(s->speed, v2(0, 0), 800 * DT);+ s->dash_timer -= DT;+ if (s->dash_timer <= 0) cs_play(&s->spr, A_seeker_spotted, false);+ if (s->trail_a > 0 && (s->trail_a -= DT) <= 0) pseeker_trail(e);+ if (s->trail_b > 0 && (s->trail_b -= DT) <= 0) pseeker_trail(e);+ if (level_on_interval(0.04f)) {+ V2 v = safe_norm(s->speed, 1);+ particles_emit(PL_MID, &P_Seeker_P_Attack, 2, v2add(v2(e->x, e->y), v2mul(v, 4)), v2(4, 4), vangle(v));+ }+ } else {+ V2 aim = safe_norm(v2((float)g_in.aim_x, (float)g_in.aim_y), 1);+ s->speed = v2add(s->speed, v2mul(aim, 600 * DT));+ float n = v2len(s->speed);+ if (n > 120) s->speed = safe_norm(s->speed, approach(n, 120, DT * 700));+ if (aim.y == 0) s->speed.y = approach(s->speed.y, 0, 400 * DT);+ if (aim.x == 0) s->speed.x = approach(s->speed.x, 0, 400 * DT);+ if ((aim.x != 0 || aim.y != 0) && cs_cur(&s->spr) == A_seeker_idle) cs_play(&s->spr, A_seeker_spotted, false);+ int sx = sgn(s->speed.x);+ if (sx != 0 && s->facing != sx && sgn((float)g_in.aim_x) == sx && fabsf(s->speed.x) > 20 &&+ cs_cur(&s->spr) != A_seeker_flipMouth && cs_cur(&s->spr) != A_seeker_flipEyes)+ cs_play(&s->spr, A_seeker_flipMouth, false);+ if (btn_pressed(&g_in.dash)) { /* Input.Aim.EightWayNormal */+ V2 d = v2((float)g_in.aim_x, (float)g_in.aim_y);+ pseeker_dash(e, safe_norm(d, 1));+ }+ }+ actor_move_h(e, s->speed.x * DT, pseeker_collide, NULL);+ actor_move_v(e, ST(e, PSeeker)->speed.y * DT, pseeker_collide, NULL);+ s = ST(e, PSeeker);+ Room *rm = g_level.room;+ e->x = clampf(e->x, rm->x, rm->x + rm->w), e->y = clampf(e->y, rm->y, rm->y + rm->h);+ Player *p = level_player();+ if (p) {+ float d = v2len(v2sub(v2(e->x, e->y), v2(p->ent->x, p->ent->y)));+ if (d < 200 && p->spr.anim == A_player_asleep) {+ p->spr.rate = 2;+ spr_play(&p->spr, A_player_wakeUp, false);+ } else if (d < 100 && p->spr.anim != A_player_wakeUp) {+ p->spr.rate = 1;+ spr_play(&p->spr, A_player_runFast, false);+ p->facing = e->x > p->ent->x ? -1 : 1;+ }+ if (d < 50 && s->dash_timer <= 0) pseeker_dash(e, safe_norm(v2sub(player_center(p), v2(e->x, e->y)), 1));+ /* Engine.TimeRate, Distort.Anxiety: not here */+ V2 t = pseeker_cam(e);+ g_level.cam = v2add(g_level.cam, v2mul(v2sub(t, g_level.cam), 1 - powf(0.01f, DT)));+ }+ }+ barriers_collidable(false);+}+static void pseeker_render(Ent *e) {+ PSeeker *s = ST(e, PSeeker);+ cs_draw(&s->spr, e->x + s->shaker.x, e->y + s->shaker.y, s->sx * s->facing, s->sy, 0, 0xFFFF, 255);+ light_add(e->x, e->y, 0xFFFFFF, 1, 32, 64);+}+static void pseeker_awake(Ent *e) {+ (void)e;+ g_level.can_retry = false; /* ColorGrade "templevoid", ScreenPadding 32: not here */+ /* the player came in with IntroTypes.TempleMirrorVoid, which player_spawn does not know: asleep from the start */+ Player *p = level_player();+ if (p) p->speed = v2(0, 0);+ pseeker_sleep();+}+static const EntClass PSEEKER = {.name = "playerSeeker", .size = sizeof(PSeeker), .update = pseeker_update, .render = pseeker_render,+ .awake = pseeker_awake, .on_player = pseeker_on_player, .kind = KIND_ACTOR | KIND_PCOLLIDE};+static void new_pseeker(const EData *d) {+ Ent *e = ent_new(&PSEEKER, d->x, d->y);+ if (!e) return;+ ent_box(e, 10, 10, -5, -5);+ PSeeker *s = ST(e, PSeeker);+ cs_init(&s->spr, SB_seeker);+ cs_play(&s->spr, A_seeker_statue, false);+ s->facing = 1;+ s->sx = s->sy = 1;+}++/* ================================================================ the story: Theo, Badeline, the cutscenes */+static bool on_ground(Ent *e) { return actor_on_ground(e, 1); }+static float room_right(void) { return (float)(g_level.room->x + g_level.room->w); }++/* ---------------------------------------------------------------- NPC05_Theo_Entrance and CS05_Entrance */+typedef struct {+ Cutscene cs;+ Ent *theo, *tb;+ V2 move_to;+ Co ev;+ int8_t ev_i;+ uint8_t started;+} Entrance;+static bool entrance_nb(Entrance *s, Co *c, int i) {+ switch (i) {+ case 0: g_player.facing = 1; return false; /* MaddyTurnsRight */+ case 1: NPC_(s->theo)->spr.sx *= -1; return false; /* TheoTurns */+ default: /* TheoLeaves */+ NB_BEGIN(c);+ npc_move_to(s->theo, v2(room_right() + 32, s->theo->y), false, 0, false);+ NB_AWAIT(c, &NPC_(s->theo)->mv);+ NB_END(c);+ }+}+static bool entrance_ev(void *ctx, int i) {+ Entrance *s = ST((Ent *)ctx, Entrance);+ return !entrance_nb(s, ev_co(&s->ev, &s->ev_i, i), i);+}+static void entrance_update(Ent *e) {+ Entrance *s = ST(e, Entrance);+ Player *p = &g_player;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ s->started = 1;+ player_dummy(p);+ p->ent->x = s->theo->x - 32;+ s->move_to = v2(s->theo->x - 32, p->ent->y);+ p->facing = -1;+ g_wipe.focus = v2(s->theo->x - 16 - g_level.cam.x, s->theo->y - 8 - g_level.cam.y); /* SpotlightWipe.FocusPoint */+ CO_WAIT(c, 2);+ p->facing = 1;+ CO_WAIT(c, 0.3f);+ npc_move_to(s->theo, v2(s->theo->x + 48, s->theo->y), false, 0, false);+ CO_AWAIT(c, &NPC_(s->theo)->mv);+ s->ev_i = -1;+ CO_SAY(c, s->tb, "ch5_entrance", entrance_ev, e);+ cutscene_end(e);+ return;+ CO_END(c);+}+static void entrance_end(Ent *e, bool skipped) {+ Entrance *s = ST(e, Entrance);+ Player *p = &g_player;+ (void)skipped;+ if (s->started) {+ player_free(p);+ p->force_camera_update = false;+ p->ent->x = s->move_to.x, p->ent->y = s->move_to.y;+ p->facing = 1;+ }+ ent_remove(s->theo);+ level_set_flag("entrance", true);+}+static const EntClass ENTRANCE = {.name = "CS05_Entrance", .size = sizeof(Entrance), .update = entrance_update};+static Ent *theo_npc_new(const EData *d, int which) {+ Ent *e = npc_new(d->x, d->y, SB_theo, -1, NULL);+ if (!e) return NULL;+ Npc *n = NPC_(e);+ n->which = (uint8_t)which;+ n->idle_anim = A_theo_idle, n->move_anim = A_theo_walk, n->maxspeed = 48;+ return e;+}+static void new_theo_entrance(const EData *d) {+ if (level_get_flag("entrance")) return;+ Ent *e = theo_npc_new(d, NPC_THEO05_ENTRANCE);+ if (!e) return;+ npc_light(e, -12, 0xFFFFFF, 32, 64);+ Ent *cs = scene_new(&ENTRANCE, entrance_end, true, false);+ if (cs) ST(cs, Entrance)->theo = e;+}++/* ---------------------------------------------------------------- NPC05_Theo_Mirror and CS05_TheoInMirror */+typedef struct {+ Cutscene cs;+ Ent *theo, *tb;+ Walk walk;+ int final_x;+} InMirror;+static void inmirror_update(Ent *e) {+ InMirror *s = ST(e, InMirror);+ Player *p = &g_player;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_dummy(p);+ CO_WALK(c, s->walk, walk_to(s->theo->x - 16));+ CO_WAIT(c, 0.5f);+ NPC_(s->theo)->spr.sx = -1;+ CO_WAIT(c, 0.25f);+ CO_SAY(c, s->tb, "ch5_theo_mirror", NULL, NULL);+ npc_move_to(s->theo, v2(s->theo->x + 64, s->theo->y), false, 0, false); /* a coroutine of its own */+ CO_WAIT(c, 0.4f);+ CO_WALK(c, s->walk, walk_exact(s->final_x));+ cutscene_end(e);+ return;+ CO_END(c);+}+static void inmirror_end(Ent *e, bool skipped) {+ InMirror *s = ST(e, InMirror);+ Player *p = &g_player;+ (void)skipped;+ player_free(p);+ p->ent->x = (float)s->final_x;+ actor_move_v(p->ent, 200, NULL, NULL);+ p->speed = v2(0, 0);+ ent_remove(s->theo);+ level_set_flag("theoInMirror", true);+}+static const EntClass INMIRROR = {.name = "CS05_TheoInMirror", .size = sizeof(InMirror), .update = inmirror_update};+static void theo_mirror_think(Ent *e) {+ Npc *n = NPC_(e);+ Player *p = level_player();+ if (!n->i[0] && p && p->ent->x > e->x - 64) {+ n->i[0] = 1;+ Ent *cs = scene_new(&INMIRROR, inmirror_end, true, false);+ if (cs) ST(cs, InMirror)->theo = e, ST(cs, InMirror)->final_x = (int)e->x + 24;+ }+}+static void new_theo_mirror(const EData *d) {+ if (level_get_flag("theoInMirror")) return;+ Ent *e = theo_npc_new(d, NPC_THEO05_MIRROR);+ if (!e) return;+ e->visible = 0; /* seen in the mirror only (MirrorReflection.IgnoreEntityVisible) */+ NPC_(e)->think = theo_mirror_think;+}++/* ---------------------------------------------------------------- NPC05_Badeline (evil_05) and CS05_Badeline */+typedef struct {+ Co co;+ Tween tw; /* MoveToNode's */+ Job job;+ V2 nodes[4], from, to;+ float speed;+ Ent *shadow, *cs;+ uint8_t nnodes, index, fallen, scene;+} Evil;+static const EntClass EVIL;+static void evil_move_to_node(Ent *e, int index) {+ Evil *v = ST(e, Evil);+ v->from = v2(v->shadow->x, v->shadow->y);+ v->to = v->nodes[index];+ tween_start(&v->tw, 0.5f);+ job_start(&v->job);+}+typedef struct {+ Cutscene cs;+ Ent *npc, *tb;+ Step step;+ V2 focus;+ Co ev;+ int8_t ev_i;+ uint8_t index, moved;+ char key[24];+} CsEvil;+static bool csevil_nb(Ent *e, CsEvil *s, Co *c) { /* BadelineLeaves */+ (void)e;+ NB_BEGIN(c);+ NB_WAIT(c, 0.1f);+ s->moved = 1;+ evil_move_to_node(s->npc, s->index);+ NB_WAIT(c, 0.5f);+ spr_play(&g_player.spr, A_player_tiredStill, false);+ NB_WAIT(c, 0.5f);+ spr_play(&g_player.spr, A_player_idle, false);+ NB_WAIT(c, 0.6f);+ NB_END(c);+}+static bool csevil_ev(void *ctx, int i) {+ CsEvil *s = ST((Ent *)ctx, CsEvil);+ return !csevil_nb(ctx, s, ev_co(&s->ev, &s->ev_i, i));+}+static void csevil_update(Ent *e) {+ CsEvil *s = ST(e, CsEvil);+ Player *p = &g_player;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_dummy(p);+ CO_WAIT(c, 0.25f);+ if (s->index == 3) {+ p->dummy_auto_animate = false;+ spr_play(&p->spr, A_player_tired, false);+ CO_WAIT(c, 0.2f);+ }+ while (p->ent && !on_ground(p->ent)) CO_YIELD(c);+ {+ Ent *sh = ST(s->npc, Evil)->shadow;+ s->focus = v2add(v2mul(v2add(v2(sh->x, sh->y - 4), player_center(p)), 0.5f), v2(-g_level.cam.x, -12 - g_level.cam.y));+ }+ CO_ZOOM_TO(c, &s->step, s->focus, 2, 0.5f);+ s->ev_i = -1;+ path2(s->key, "ch5_shadow_maddy_", NULL, -1);+ s->key[17] = (char)('0' + s->index), s->key[18] = 0;+ CO_SAY(c, s->tb, s->key, csevil_ev, e);+ if (!s->moved) evil_move_to_node(s->npc, s->index);+ CO_ZOOM_BACK(c, &s->step, 0.5f);+ cutscene_end(e);+ return;+ CO_END(c);+}+static void csevil_end(Ent *e, bool skipped) {+ CsEvil *s = ST(e, CsEvil);+ Evil *v = ST(s->npc, Evil);+ (void)skipped;+ v->shadow->x = v->nodes[s->index].x, v->shadow->y = v->nodes[s->index].y; /* SnapToNode */+ player_free(&g_player);+ char f[12] = "badeline_0";+ f[9] = (char)('0' + s->index);+ level_set_flag(f, true);+}+static const EntClass CSEVIL = {.name = "CS05_Badeline", .size = sizeof(CsEvil), .update = csevil_update};+static bool evil_flag(int i) {+ char f[12] = "badeline_0";+ f[9] = (char)('0' + i);+ return level_get_flag(f);+}+static void evil_update(Ent *e) {+ Evil *v = ST(e, Evil);+ BDummy *b = BD(v->shadow);+ Player *p = level_player();+ Room *rm = g_level.room;+ if (g_level.transitioning) { /* TransitionListener.OnOut */+ if (e->room != g_level.room_slot) {+ float a = 1 - fminf(1, g_level.tr_at * 2);+ b->hair_alpha = a, b->spr.alpha = a8(a), b->light_alpha = a;+ }+ return;+ }+ if (job_due(&v->job)) { /* MoveToNode's tween */+ bool done = tween_update(&v->tw);+ float k = ease_cube_inout(v->tw.percent);+ V2 at = v2lerp(v->from, v->to, k);+ v->shadow->x = at.x, v->shadow->y = at.y;+ if (level_on_interval(0.03f))+ particles_emit(PL_FG, &P_BadelineOldsite_P_Vanish, 2, v2add(at, v2(0, -6)), v2(2, 2), P_BadelineOldsite_P_Vanish.direction);+ if (k >= 0.1f && k <= 0.9f && level_on_interval(0.05f)) {+ uint16_t t = spr_tex(&b->spr);+ if (t != 0xFFFF) trail_add(at.x + b->spr_pos.x, at.y + b->spr_pos.y, t, b->spr.ox, b->spr.oy, b->spr.sx, b->spr.sy, 0xFF0000, 0.5f);+ }+ if (done) job_end(&v->job);+ }+ Co *c = &v->co;+ CO_BEGIN(c);+ b->spr.sx = -1;+ if (!v->scene) { /* FirstScene */+ b->float_speed = 150;+ for (;;) {+ p = level_player();+ if (p && p->ent->y > rm->y + 180 && !on_ground(p->ent) && !v->fallen) {+ player_set_state(p, ST_TEMPLEFALL);+ v->fallen = 1;+ }+ if (p && p->ent->x > e->x - 64 && p->ent->y > e->y - 32) break;+ CO_YIELD(c);+ }+ evil_move_to_node(e, 0);+ while (v->shadow->x < rm->x + rm->w + 8) {+ CO_YIELD(c);+ p = level_player();+ if (p && p->ent->x > v->shadow->x - 24) v->shadow->x = p->ent->x + 24;+ }+ } else { /* SecondScene */+ b->float_speed = 300, b->float_accel = 400;+ CO_WAIT(c, 0.1f);+ while (v->index < v->nnodes) {+ p = level_player();+ while (!p || v2len(v2sub(v2(p->ent->x, p->ent->y), v2(v->shadow->x, v->shadow->y))) > 70) {+ CO_YIELD(c);+ p = level_player();+ }+ if (v->index < 4 && !evil_flag(v->index)) {+ v->cs = scene_new(&CSEVIL, csevil_end, true, false);+ if (v->cs) {+ CsEvil *s = ST(v->cs, CsEvil);+ s->npc = e, s->index = v->index;+ }+ CO_YIELD(c);+ while (v->cs && v->cs->cls == &CSEVIL && v->cs->dead != 1) CO_YIELD(c);+ v->index++;+ }+ }+ }+ ent_remove(v->shadow);+ ent_remove(e);+ CO_END(c);+}+static const EntClass EVIL = {.name = "npc05Badeline", .size = sizeof(Evil), .update = evil_update};+static void new_evil(const EData *d) {+ const char *room = level_room_name_of(d->room);+ bool first = !strcmp(room, "c-00");+ int start = 0;+ if (first) {+ if (level_visited("c-01")) return;+ } else if (!strcmp(room, "c-01")) {+ if (level_visited("c-01b")) return;+ while (start < 4 && evil_flag(start)) start++;+ if (start >= 4) return;+ } else+ return;+ Ent *e = ent_new(&EVIL, d->x, d->y);+ if (!e) return;+ e->visible = e->collidable = 0;+ e->tags = TAG_TRANSITION_UPDATE;+ Evil *v = ST(e, Evil);+ v->nnodes = (uint8_t)(d->nnodes < 4 ? d->nnodes : 4);+ for (int i = 0; i < v->nnodes; i++) v->nodes[i] = ed_node(d, i);+ v->scene = !first;+ v->index = (uint8_t)start;+ v->shadow = bd_new(start > 0 ? v->nodes[start - 1] : v2(d->x, d->y));+ if (!v->shadow) {+ ent_remove(e);+ return;+ }+ v->shadow->depth = -1000000;+}++/* ---------------------------------------------------------------- CS05_SeeTheo */+typedef struct {+ Cutscene cs;+ Ent *tb, *theo;+ Step step, bstep;+ V2 focus;+ Co ev, br;+ int8_t ev_i;+ uint8_t index, brightening;+} SeeTheo;+static bool seetheo_brighten(SeeTheo *s) { /* Brighten() */+ Co *c = &s->br;+ NB_BEGIN(c);+ step_reset(&s->bstep);+ NB_NEST(c, zoom_back(&s->bstep, 0.5f));+ NB_WAIT(c, 0.3f);+ g_session.dark_room_alpha = 0.3f;+ while (g_level.lighting != g_session.dark_room_alpha) {+ g_level.lighting = approach(g_level.lighting, g_session.dark_room_alpha, DT * 0.5f);+ NB_YIELD(c);+ }+ NB_END(c);+}+static bool seetheo_nb(SeeTheo *s, Co *c, int i) {+ Player *p = &g_player;+ switch (i) {+ case 0: /* ZoomIn */+ NB_BEGIN(c);+ s->focus = v2sub(v2lerp(v2(p->ent->x, p->ent->y), v2(s->theo->x, s->theo->y), 0.5f), v2(g_level.cam.x, g_level.cam.y + 20));+ NB_ZOOM_TO(c, &s->step, s->focus, 2, 0.5f);+ NB_END(c);+ case 1: /* MadelineTurnsAround */+ NB_BEGIN(c);+ NB_WAIT(c, 0.3f);+ p->facing = -1;+ NB_WAIT(c, 0.1f);+ NB_END(c);+ case 2: /* WaitABit */+ NB_BEGIN(c);+ NB_WAIT(c, 1);+ NB_END(c);+ default: /* MadelineTurnsBackAndBrighten */+ NB_BEGIN(c);+ NB_WAIT(c, 0.1f);+ memset(&s->br, 0, sizeof s->br);+ s->brightening = 2;+ NB_WAIT(c, 0.2f);+ p->facing = 1;+ NB_WAIT(c, 0.1f);+ while (s->brightening) NB_YIELD(c);+ NB_END(c);+ }+}+static bool seetheo_ev(void *ctx, int i) {+ SeeTheo *s = ST((Ent *)ctx, SeeTheo);+ return !seetheo_nb(s, ev_co(&s->ev, &s->ev_i, i), i);+}+static void seetheo_update(Ent *e) {+ SeeTheo *s = ST(e, SeeTheo);+ Player *p = &g_player;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ while (!p->ent || !on_ground(p->ent)) CO_YIELD(c);+ player_dummy(p);+ CO_WAIT(c, 0.25f);+ s->theo = theo_entity();+ if (s->theo && sgn(p->ent->x - s->theo->x) != 0) p->facing = sgn(s->theo->x - p->ent->x);+ CO_WAIT(c, 0.25f);+ s->ev_i = -1;+ if (s->index == 0) CO_SAY(c, s->tb, "ch5_see_theo", seetheo_ev, e);+ else if (s->index == 1) CO_SAY(c, s->tb, "ch5_see_theo_b", NULL, NULL);+ CO_ZOOM_BACK(c, &s->step, 0.5f);+ cutscene_end(e);+ return;+ CO_END(c);+}+static void seetheo_after(Ent *e) { /* the added Brighten coroutine runs after the main one */+ SeeTheo *s = ST(e, SeeTheo);+ if (s->brightening == 2) s->brightening = 1; /* added this update: it starts with the next */+ else if (s->brightening && !seetheo_brighten(s)) s->brightening = 0;+}+static void seetheo_tick(Ent *e) {+ seetheo_update(e);+ if (e->dead != 1) seetheo_after(e);+}+static void seetheo_end(Ent *e, bool skipped) {+ Player *p = &g_player;+ (void)e, (void)skipped;+ player_free(p);+ p->force_camera_update = false;+ p->dummy_auto_animate = true;+ g_session.dark_room_alpha = 0.3f;+ g_level.lighting = g_session.dark_room_alpha;+ level_set_flag("seeTheoInCrystal", true);+}+static const EntClass SEETHEO = {.name = "CS05_SeeTheo", .size = sizeof(SeeTheo), .update = seetheo_tick};+static void see_theo(int index) {+ Ent *e = scene_new(&SEETHEO, seetheo_end, true, false);+ if (e) ST(e, SeeTheo)->index = (uint8_t)index;+}++/* ---------------------------------------------------------------- CS05_SaveTheo */+typedef struct {+ Cutscene cs;+ Ent *theo, *tb;+ V2 end;+ Walk walk;+ Step step;+ Co ev;+ int8_t ev_i;+ uint8_t dashing;+ float dash_x;+} SaveTheo;+/* TryToBreakCrystal: Madeline dashes up into the pedestal (Player.OverrideDashDirection, MInput.Disabled) */+static bool savetheo_nb(SaveTheo *s, Co *c) {+ Player *p = &g_player;+ NB_BEGIN(c);+ {+ Ent *ped = first_of(&PEDESTAL);+ if (ped) ped->collidable = 1;+ }+ NB_WALK(c, s->walk, walk_to(s->theo->x));+ NB_WAIT(c, 0.1f);+ NB_ZOOM_TO(c, &s->step, v2(160, 90), 2, 0.5f);+ p->dummy_auto_animate = false;+ spr_play(&p->spr, A_player_lookUp, false);+ NB_WAIT(c, 1);+ p->state_locked = false;+ player_set_state(p, ST_DASH); /* StartDash */+ p->dashes = 0;+ s->dashing = 1, s->dash_x = p->ent->x;+ NB_WAIT(c, 0.1f);+ while (!on_ground(p->ent) || p->speed.y < 0) {+ p->dashes = 0;+ p->force_move_x = 0, p->force_move_x_timer = DT * 2; /* Input.MoveX = 0 */+ NB_YIELD(c);+ }+ s->dashing = 0;+ player_set_state(p, ST_DUMMY);+ p->state_locked = true;+ p->dummy_auto_animate = true;+ NB_WALK(c, s->walk, walk_back((int)s->end.x));+ NB_WAIT(c, 1.5f);+ NB_END(c);+}+static bool savetheo_ev(void *ctx, int i) {+ SaveTheo *s = ST((Ent *)ctx, SaveTheo);+ return !savetheo_nb(s, ev_co(&s->ev, &s->ev_i, i));+}+static void savetheo_update(Ent *e) {+ SaveTheo *s = ST(e, SaveTheo);+ Player *p = &g_player;+ if (s->dashing == 1 && p->state == ST_DASH && p->co_step == 2) {+ /* the dash went the way the keys say: up it goes instead (OverrideDashDirection) */+ s->dashing = 2;+ p->ent->x = s->dash_x;+ p->speed = v2(0, -240);+ p->dash_dir = v2(0, -1);+ level_dir_shake(v2(0, -1), 0.2f);+ }+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_dummy(p);+ p->force_camera_update = true;+ CO_WALK(c, s->walk, walk_to(s->theo->x - 18));+ p->facing = 1;+ s->ev_i = -1;+ CO_SAY(c, s->tb, "ch5_found_theo", savetheo_ev, e);+ CO_WAIT(c, 0.25f);+ CO_ZOOM_BACK(c, &s->step, 0.5f);+ cutscene_end(e);+ return;+ CO_END(c);+}+static void savetheo_end(Ent *e, bool skipped) {+ SaveTheo *s = ST(e, SaveTheo);+ Player *p = &g_player;+ (void)skipped;+ p->ent->x = s->end.x, p->ent->y = s->end.y;+ for (int i = 0; i < 64 && !on_ground(p->ent); i++) actor_move_v(p->ent, 1, NULL, NULL);+ g_level.cam = player_camera_target(p);+ level_set_flag("foundTheoInCrystal", true);+ zoom_reset();+ /* a new Player there (the old one removed): the state of a fresh one */+ p->state_locked = false;+ player_set_state(p, ST_NORMAL);+ p->speed = v2(0, 0);+ p->dashes = player_max_dashes(p);+ p->dummy_auto_animate = p->dummy_gravity = true;+ p->force_camera_update = false;+ p->facing = 1;+ Ent *ped = first_of(&PEDESTAL);+ if (ped) ped->collidable = 0, ST(ped, Pedestal)->dropped = 1;+ Ent *t = s->theo;+ t->depth = 100;+ ents_mark_unsorted();+ ST(t, Theo)->on_pedestal = 0;+ ST(t, Theo)->speed = v2(0, 0);+ for (int i = 0; i < 64 && !on_ground(t); i++) actor_move_v(t, 1, NULL, NULL);+}+static const EntClass SAVETHEO = {.name = "CS05_SaveTheo", .size = sizeof(SaveTheo), .update = savetheo_update};++/* ---------------------------------------------------------------- CS05_Reflection1 */+typedef struct {+ Cutscene cs;+ Ent *tb;+ Walk walk;+ Step step;+ Co ev;+ int8_t ev_i;+} Reflect;+static bool reflect_nb(Reflect *s, Co *c, int i) {+ Player *p = &g_player;+ switch (i) {+ case 0: /* MadelineFallsToKnees */+ NB_BEGIN(c);+ NB_WAIT(c, 0.2f);+ p->dummy_auto_animate = false;+ spr_play(&p->spr, A_player_tired, false);+ NB_WAIT(c, 0.2f);+ NB_ZOOM_TO(c, &s->step, v2(90, 116), 2, 0.5f);+ NB_WAIT(c, 0.2f);+ NB_END(c);+ case 1: /* MadelineStopsPanicking */+ NB_BEGIN(c);+ NB_WAIT(c, 0.8f);+ spr_play(&p->spr, A_player_tiredStill, false);+ NB_WAIT(c, 0.4f);+ NB_END(c);+ default: /* MadelineGetsUp */+ p->dummy_auto_animate = true;+ spr_play(&p->spr, A_player_idle, false);+ return false;+ }+}+static bool reflect_ev(void *ctx, int i) {+ Reflect *s = ST((Ent *)ctx, Reflect);+ return !reflect_nb(s, ev_co(&s->ev, &s->ev_i, i), i);+}+static void reflect_update(Ent *e) {+ Reflect *s = ST(e, Reflect);+ Player *p = &g_player;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_dummy(p);+ p->force_camera_update = true;+ {+ Ent *m = first_of(&MIRROR);+ CO_WALK(c, s->walk, walk_to(m ? m->x + ST(m, Mirror)->w / 2.f + 8 : p->ent->x));+ }+ CO_WAIT(c, 0.2f);+ p->facing = -1;+ CO_WAIT(c, 0.3f);+ s->ev_i = -1;+ if (!p->dead) CO_SAY(c, s->tb, "ch5_reflection", reflect_ev, e);+ else CO_WAIT(c, 100);+ CO_ZOOM_BACK(c, &s->step, 0.5f);+ cutscene_end(e);+ return;+ CO_END(c);+}+static void reflect_end(Ent *e, bool skipped) {+ (void)e, (void)skipped;+ player_free(&g_player);+ g_player.force_camera_update = false;+ level_set_flag("reflection", true);+}+static const EntClass REFLECT = {.name = "CS05_Reflection1", .size = sizeof(Reflect), .update = reflect_update};++/* ---------------------------------------------------------------- TheoPhone and CS05_TheoPhone */+static void phone_render(Ent *e) {+ gfx_tex_ex(T_characters_theo_phone, e->x, e->y, 4, 8, 1, 1, 0, 0xFFFF, 255, 0); /* JustifyOrigin(0.5, 1) */+ /* its light blinks every half second */+ if ((int)floorf(g_level.time_active / 0.5f) % 2 == 0) light_add(e->x, e->y, 0x7CFC00, 1, 8, 16); /* Color.LawnGreen */+}+static const EntClass PHONE = {.name = "theoPhone", .render = phone_render};+typedef struct {+ Cutscene cs;+ Ent *tb;+ Walk walk;+ Step step;+ Co ev;+ int8_t ev_i;+ float target_x;+} CsPhone;+static void phone_remove(void) {+ Ent *ph = first_of(&PHONE);+ if (ph) ent_remove(ph);+}+static bool csphone_nb(CsPhone *s, Co *c, int i) {+ Player *p = &g_player;+ if (i == 0) { /* WalkToPhone */+ NB_BEGIN(c);+ NB_WAIT(c, 0.25f);+ NB_WALK(c, s->walk, walk_exact((int)s->target_x));+ p->facing = -1;+ NB_WAIT(c, 0.5f);+ p->dummy_auto_animate = false;+ spr_play(&p->spr, A_player_duck, false);+ NB_WAIT(c, 0.5f);+ NB_END(c);+ }+ NB_BEGIN(c); /* StandBackUp */+ phone_remove();+ NB_WAIT(c, 0.6f);+ spr_play(&p->spr, A_player_idle, false);+ NB_WAIT(c, 0.2f);+ NB_END(c);+}+static bool csphone_ev(void *ctx, int i) {+ CsPhone *s = ST((Ent *)ctx, CsPhone);+ return !csphone_nb(s, ev_co(&s->ev, &s->ev_i, i), i);+}+static void csphone_update(Ent *e) {+ CsPhone *s = ST(e, CsPhone);+ Player *p = &g_player;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_set_state(p, ST_DUMMY);+ if (p->ent->x != s->target_x) p->facing = sgn(s->target_x - p->ent->x);+ CO_WAIT(c, 0.5f);+ CO_ZOOM_TO(c, &s->step, v2(80, 60), 2, 0.5f);+ s->ev_i = -1;+ CO_SAY(c, s->tb, "CH5_PHONE", csphone_ev, e);+ CO_ZOOM_BACK(c, &s->step, 0.5f);+ cutscene_end(e);+ return;+ CO_END(c);+}+static void csphone_end(Ent *e, bool skipped) {+ (void)e, (void)skipped;+ phone_remove();+ player_set_state(&g_player, ST_NORMAL);+}+static const EntClass CSPHONE = {.name = "CS05_TheoPhone", .size = sizeof(CsPhone), .update = csphone_update};++/* ---------------------------------------------------------------- InteractTrigger (ch5_theo_phone, ch5_see_theo_b) */+typedef struct {+ Talk talk;+ float timeout;+ uint8_t which, used; /* which: 0 ch5_theo_phone, 1 ch5_mirror_reflection, 2 ch5_see_theo, 3 ch5_see_theo_b */+} Interact;+static const char *const INTERACT_EVENTS[4] = {"ch5_theo_phone", "ch5_mirror_reflection", "ch5_see_theo", "ch5_see_theo_b"};+static bool interact_flag(int which) {+ char f[32];+ return level_get_flag(path2(f, "it_", INTERACT_EVENTS[which], -1));+}+static void interact_update(Ent *e) {+ Interact *it = ST(e, Interact);+ if (it->used) {+ if ((it->timeout -= DT) <= 0) ent_remove(e);+ return;+ }+ if (interact_flag(it->which)) {+ ent_remove(e);+ return;+ }+ if (!talk_update(&it->talk, e)) return;+ Player *p = level_player();+ if (!p) return;+ /* OnTalk */+ if (it->which == 0) {+ Ent *cs = scene_new(&CSPHONE, csphone_end, true, false);+ if (cs) ST(cs, CsPhone)->target_x = e_cxm(e);+ } else if (it->which == 1) {+ scene_new(&REFLECT, reflect_end, true, false);+ } else+ see_theo(it->which - 2);+ char f[32];+ level_set_flag(path2(f, "it_", INTERACT_EVENTS[it->which], -1), true);+ it->used = 1;+ it->timeout = 0.25f;+}+static void interact_render(Ent *e) { talk_render(&ST(e, Interact)->talk, e); }+static const EntClass INTERACT = {.name = "interactTrigger", .size = sizeof(Interact), .update = interact_update,+ .render = interact_render, .removed = talk_removed};+static bool new_interact(const EData *d) {+ const char *ev = EAS(d, interactTrigger, event);+ int which = -1;+ for (int i = 0; i < 4; i++)+ if (!strcmp(ev, INTERACT_EVENTS[i])) which = i;+ if (which < 0) return false;+ if (interact_flag(which)) return true; /* Added: every event done */+ int w = (int)EA(d, interactTrigger, width), h = (int)EA(d, interactTrigger, height);+ Ent *e = ent_new(&INTERACT, d->x, d->y);+ if (!e) return true;+ ent_box(e, (float)w, (float)h, 0, 0);+ e->depth = -1000000;+ Interact *it = ST(e, Interact);+ V2 at = d->nnodes ? v2sub(ed_node(d, 0), v2(d->x, d->y)) : v2(w / 2.f, 0);+ talk_init(&it->talk, 0, 0, w, h, at);+ it->talk.must_face = false;+ it->which = (uint8_t)which;+ if (which == 0) {+ Ent *ph = ent_new(&PHONE, d->x + w / 2.f - 8, d->y + h - 1);+ if (ph) ph->collidable = 0;+ }+ return true;+}++/* ---------------------------------------------------------------- EventTrigger */+enum { EV_SEE_THEO, EV_FOUND_THEO, EV_MIRROR_REFLECTION, EV_CANCEL_SEE_THEO };+typedef struct { uint8_t which, triggered, brighten; } Event;+static void event_enter(Ent *e, Player *p) {+ Event *ev = ST(e, Event);+ if (ev->triggered) return;+ ev->triggered = 1;+ switch (ev->which) {+ case EV_SEE_THEO: see_theo(0); break;+ case EV_FOUND_THEO:+ if (!level_get_flag("foundTheoInCrystal")) {+ Ent *t = theo_entity();+ Ent *cs = t ? scene_new(&SAVETHEO, savetheo_end, true, false) : NULL;+ if (cs) ST(cs, SaveTheo)->theo = t, ST(cs, SaveTheo)->end = v2(t->x - 24, t->y);+ }+ break;+ case EV_MIRROR_REFLECTION:+ if (!level_get_flag("reflection")) scene_new(&REFLECT, reflect_end, true, false);+ break;+ default: {+ level_set_flag("it_ch5_see_theo", true);+ level_set_flag("it_ch5_see_theo_b", true);+ char f[40];+ level_set_flag(path2(f, "ignore_darkness_", level_room_name(), -1), true);+ ev->brighten = 1;+ }+ }+ (void)p;+}+static void event_update(Ent *e) { /* Brighten() */+ Event *ev = ST(e, Event);+ if (ev->brighten && (g_level.lighting = approach(g_level.lighting, 0.15f, DT * 4)) == 0.15f) ev->brighten = 0;+}+static const EntClass EVENTTRIG = {.name = "eventTrigger", .size = sizeof(Event), .update = event_update,+ .on_enter = event_enter, .kind = KIND_TRIGGER};+static bool new_event(const EData *d) {+ static const char *const names[4] = {"ch5_see_theo", "ch5_found_theo", "ch5_mirror_reflection", "cancel_ch5_see_theo"};+ const char *ev = EAS(d, eventTrigger, event);+ int which = -1;+ for (int i = 0; i < 4; i++)+ if (!strcmp(ev, names[i])) which = i;+ if (which < 0) return false;+ Ent *e = ent_new(&EVENTTRIG, d->x, d->y);+ if (e) ent_box(e, EA(d, eventTrigger, width), EA(d, eventTrigger, height), 0, 0), e->visible = 0, ST(e, Event)->which = (uint8_t)which;+ return true;+}++/* ---------------------------------------------------------------- triggers */+static const EntClass CHECKPOINT_BLOCKER = {.name = "checkpointBlockerTrigger", .kind = KIND_TRIGGER};++/* ---------------------------------------------------------------- the factories */+bool ents_ch5(const EData *d) {+ story5_room();+ switch (d->type) {+ case ET_npc: {+ const char *who = EAS(d, npc, npc);+ if (!strcmp(who, "theo_05_entrance")) new_theo_entrance(d);+ else if (!strcmp(who, "theo_05_inmirror")) new_theo_mirror(d);+ else if (!strcmp(who, "evil_05")) new_evil(d);+ else return false;+ return true;+ }+ case ET_torch: new_torch(d); return true;+ case ET_templeEye: new_eye(d); return true;+ case ET_templeGate: new_gate(d); return true;+ case ET_dashSwitchH: new_dswitch(d, true); return true;+ case ET_dashSwitchV: new_dswitch(d, false); return true;+ case ET_swapBlock: new_swap(d); return true;+ case ET_templeCrackedBlock: new_cracked(d); return true;+ case ET_seekerBarrier: new_barrier(d); return true;+ case ET_seeker: new_seeker(d); return true;+ case ET_seekerStatue: new_statue(d); return true;+ case ET_theoCrystal: new_theo(d); return true;+ case ET_theoCrystalPedestal: new_pedestal(d); return true;+ case ET_conditionBlock: new_condition(d); return true;+ case ET_templeMirror: new_mirror(d); return true;+ case ET_templeMirrorPortal: new_portal(d); return true;+ case ET_templeBigEyeball: new_bigeye(d); return true;+ case ET_playerSeeker: new_pseeker(d); return true;+ }+ return false;+}++/* ---------------------------------------------------------------- MiniTextboxTrigger */+typedef struct { uint32_t hash; uint8_t mode, once, triggered; int8_t deaths; const char *dialog; } MiniTrig;+static void minitrig_fire(Ent *e) { /* Trigger(): one of its dialogs (they are split by commas) */+ MiniTrig *t = ST(e, MiniTrig);+ if (t->triggered || (t->deaths >= 0 && g_session.deaths_in_current_level != (uint32_t)t->deaths)) return;+ t->triggered = 1;+ int n = 1;+ for (const char *c = t->dialog; *c; c++) n += *c == ',';+ int k = rndi(n);+ const char *a = t->dialog;+ while (k--) a = strchr(a, ',') + 1;+ char key[40];+ int len = 0;+ while (*a == ' ') a++;+ while (a[len] && a[len] != ',' && len < 39) len++;+ while (len && a[len - 1] == ' ') len--;+ memcpy(key, a, (size_t)len);+ key[len] = 0;+ mini_textbox(key);+ if (t->once) level_set_do_not_load(t->hash);+}+static void minitrig_awake(Ent *e) {+ if (ST(e, MiniTrig)->mode == 1) minitrig_fire(e); /* OnLevelStart */+}+static void minitrig_enter(Ent *e, Player *p) {+ (void)p;+ if (ST(e, MiniTrig)->mode == 0) minitrig_fire(e); /* OnPlayerEnter */+}+static void minitrig_update(Ent *e) { /* OnTheoEnter: a HoldableCollider */+ Ent *t = theo_entity();+ if (ST(e, MiniTrig)->mode == 2 && t && collide_ent_at(e, e->x, e->y, t)) minitrig_fire(e);+}+static const EntClass MINITRIG = {.name = "minitextboxTrigger", .size = sizeof(MiniTrig), .update = minitrig_update,+ .awake = minitrig_awake, .on_enter = minitrig_enter, .kind = KIND_TRIGGER};+static void new_minitrig(const EData *d) {+ uint32_t h = level_entity_hash(d);+ if (level_do_not_load(h)) return;+ Ent *e = ent_new(&MINITRIG, d->x, d->y);+ if (!e) return;+ ent_box(e, EA(d, minitextboxTrigger, width), EA(d, minitextboxTrigger, height), 0, 0);+ e->visible = 0;+ MiniTrig *t = ST(e, MiniTrig);+ const char *mode = EAS(d, minitextboxTrigger, mode);+ t->mode = !strcmp(mode, "OnLevelStart") ? 1 : !strcmp(mode, "OnTheoEnter") ? 2 : 0;+ t->once = EAB(d, minitextboxTrigger, only_once);+ t->deaths = (int8_t)EA(d, minitextboxTrigger, death_count);+ t->dialog = EAS(d, minitextboxTrigger, dialog_id);+ t->hash = h;+}++bool trigs_ch5(const EData *d) {+ switch (d->type) {+ case TT_checkpointBlockerTrigger: {+ Ent *e = ent_new(&CHECKPOINT_BLOCKER, d->x, d->y);+ if (e) ent_box(e, EA(d, checkpointBlockerTrigger, width), EA(d, checkpointBlockerTrigger, height), 0, 0), e->visible = 0;+ return true;+ }+ case TT_minitextboxTrigger: new_minitrig(d); return true;+ case TT_eventTrigger: return new_event(d);+ case TT_interactTrigger: return new_interact(d);+ }+ return false;+}++/* this chapter's tables: in the memory it is given while it is played (res_chapter_ram) */+uint32_t ch5_ram(void) { return END_story5; }diff --git a/games/celeste/src/ch6.c b/games/celeste/src/ch6.cnew file mode 100644index 00000000..71d6ff01--- /dev/null+++ b/games/celeste/src/ch6.c@@ -0,0 +1,4425 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* Reflection (chapter 6): pinball bumpers, feathers, star jump blocks and the+ * plateau, Kevins (crush blocks), the big waterfalls, Badeline's boost, the+ * heart statue, the tentacles, and Badeline the boss with her shots, beams,+ * falling and moving blocks (water is the Celestial Resort's, ch3.c).+ * Ported from the game's classes (Bumper.cs, FlyFeather.cs, CrushBlock.cs, FinalBoss.cs...). */+#include "badeline.h"++/* ---------------------------------------------------------------- helpers (Calc) */+static float angle_diff(float a, float b) {+ float d = b - a;+ while (d > PI_F) d -= 2 * PI_F;+ while (d <= -PI_F) d += 2 * PI_F;+ return d;+}+static float angle_lerp(float a, float b, float t) { return a + angle_diff(a, b) * t; }+static V2 closest_on_line(V2 a, V2 b, V2 p) { /* Calc.ClosestPointOnLine */+ V2 v = v2sub(b, a), w = v2sub(p, a);+ float t = (w.x * v.x + w.y * v.y) / (v.x * v.x + v.y * v.y);+ t = clampf(t, 0, 1);+ return v2add(a, v2mul(v, t));+}+static uint16_t tex_named(const char *p) { return res_tex_by_name(p); }+static int tex_family(const char *prefix, uint16_t *out, int n) {+ char p[64];+ int k = 0;+ for (int i = 0; i < n; i++) {+ out[i] = tex_named(path2(p, prefix, NULL, i));+ if (out[i] != 0xFFFF) k = i + 1;+ }+ return k;+}+static void draw_centered(uint16_t tex, float x, float y, uint16_t tint, uint8_t alpha, float sx, float sy, float rot) {+ Tex t;+ if (tex == 0xFFFF || !tex_get(tex, &t)) return;+ float k = t.scale > 1 ? t.scale : 1; /* stored smaller, drawn scaled up */+ gfx_tex_ex(tex, x, y, t.fw * k / 2.f, t.fh * k / 2.f, sx, sy, rot, tint, alpha, 0);+}+static float hash01(uint32_t seed, uint32_t i) {+ uint32_t h = seed * 0x9E3779B1u ^ (i + 0x7F4A7C15u) * 0x85EBCA6Bu;+ h ^= h >> 15, h *= 0x2C1B3C6Du, h ^= h >> 12, h *= 0x297A2D39u, h ^= h >> 15;+ return (h >> 8) / 16777216.f;+}+static uint8_t ent_ref(const Ent *e) { return (uint8_t)(e - g_ents); }+static Ent *ent_at(uint8_t i) { return &g_ents[i]; }+static Ent *first_of(const EntClass *c) {+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == c && g_ents[i].dead != 1) return &g_ents[i];+ return NULL;+}+static void player_hurtbox(const Ent *pe, float *l, float *t, float *r, float *b) {+ float w = pe->cw, h = pe->ch, x = pe->cx, y = pe->cy;+ if (h == 11) h = 9;+ else if (h == 6) h = 4;+ else if (h == 8 && w == 8) w = 6, h = 6, x = -3, y = -9;+ *l = pe->x + x, *t = pe->y + y, *r = *l + w, *b = *t + h;+}+static inline void px_blend(uint16_t *strip, int y0, int y1, int vx, int vy, uint16_t c, int a) {+ if ((unsigned)vx >= VIEW_W || vy < y0 || vy >= y1 || a <= 0) return;+ uint16_t *d = strip + (vy - y0) * VIEW_W + vx;+ *d = a >= 256 ? c : blend565(*d, scale565(c, a), a);+}++/* ---------------------------------------------------------------- compact sprites */+typedef struct { uint8_t bank, anim, frame, playing; int8_t last; uint8_t pad[3]; float timer; } CSpr;+static Sprite cs_raw(const CSpr *c) {+ Sprite s;+ memset(&s, 0, sizeof s);+ s.bank = c->bank, s.anim = c->anim, s.frame = c->frame, s.playing = c->playing;+ s.timer = c->timer, s.rate = 1, s.last_goto = c->last, s.sx = s.sy = 1, s.tint = 0xFFFF, s.alpha = 255, s.visible = 1;+ return s;+}+static void cs_back(CSpr *c, const Sprite *s) {+ c->bank = s->bank, c->anim = s->anim, c->frame = s->frame, c->playing = s->playing, c->timer = s->timer, c->last = s->last_goto;+}+static void cs_init(CSpr *c, int bank) {+ Sprite s;+ spr_init(&s, bank);+ cs_back(c, &s);+}+static void cs_play(CSpr *c, int anim, bool restart) {+ Sprite s = cs_raw(c);+ spr_play(&s, anim, restart);+ cs_back(c, &s);+}+static int cs_update(CSpr *c) {+ if (!c->playing || c->anim == 255) return -1;+ Sprite s = cs_raw(c);+ int n = spr_frames(&s);+ float delay = n ? spr_anim_duration(c->bank, c->anim) / n : 0;+ int ended = (c->frame >= n - 1 && delay > 0 && c->timer + DT >= delay) ? c->anim : -1;+ spr_update(&s);+ cs_back(c, &s);+ return ended;+}+static uint16_t cs_tex(const CSpr *c) {+ Sprite s = cs_raw(c);+ uint16_t t = spr_tex(&s);+ if (t != 0xFFFF && !res_cached(t)) { /* an animation not loaded yet: all its frames in one pass (as spr_draw) */+ uint16_t ids[32], gotos[8];+ int ng, a = c->anim != 255 ? c->anim : c->last;+ if (a >= 0) res_load(ids, bank_anim_textures(c->bank, a, ids, 32, gotos, &ng));+ }+ return t;+}+static void cs_origin(const CSpr *c, uint16_t t, float *ox, float *oy) {+ Sprite s;+ spr_init(&s, c->bank);+ Tex tx;+ *ox = s.ox, *oy = s.oy;+ if (s.justify && tex_get(t, &tx)) *ox = tx.fw * tx.scale * s.jx, *oy = tx.fh * tx.scale * s.jy;+}+static void cs_draw(const CSpr *c, float x, float y, float sx, float sy, float rot, uint16_t tint, uint8_t alpha) {+ uint16_t t = cs_tex(c);+ if (t == 0xFFFF) return;+ float ox, oy;+ cs_origin(c, t, &ox, &oy);+ gfx_tex_ex(t, x, y, ox, oy, sx, sy, rot, tint, alpha, 0);+}+/* frame-list animations for textures whose bank paths differ in case from the atlas */+typedef struct { const uint8_t *frames; uint8_t n, loop, next; float delay; } FAnim;+typedef struct { float t; uint8_t anim, frame, playing, pad; } FSpr;+static void fs_play(FSpr *s, int anim, bool restart) {+ if (s->anim == anim && !restart) return;+ s->anim = (uint8_t)anim, s->frame = 0, s->t = 0, s->playing = 1;+}+static void fs_update(FSpr *s, const FAnim *anims) {+ if (!s->playing) return;+ const FAnim *a = &anims[s->anim];+ s->t += DT;+ if (s->t < a->delay) return;+ s->t -= a->delay;+ if (++s->frame < a->n) return;+ if (a->loop) s->frame = 0;+ else if (a->next != 255) s->anim = a->next, s->frame = 0;+ else s->frame = (uint8_t)(a->n - 1), s->playing = 0;+}+static int fs_index(const FSpr *s, const FAnim *anims) { return anims[s->anim].frames[s->frame]; }+/* the frame's texture; its animation's frames are loaded in one pass when it is not */+static uint16_t fs_tex(const FSpr *s, const FAnim *anims, const uint16_t *tex) {+ const FAnim *a = &anims[s->anim];+ uint16_t t = tex[fs_index(s, anims)];+ if (t != 0xFFFF && !res_cached(t)) {+ uint16_t ids[32];+ int n = a->n < 32 ? a->n : 32;+ for (int i = 0; i < n; i++) ids[i] = tex[a->frames[i]];+ res_load(ids, n);+ }+ return t;+}++/* ---------------------------------------------------------------- Bumper (bigSpinner) */+/* Sprites.xml's objects/bumper/idle is objects/Bumper/Idle in the atlas: the frames are listed here */+enum { BA_ON, BA_IDLE, BA_HIT, BA_OFF };+static const uint8_t BI_ON[] = {42, 43, 44}, BI_HIT[] = {34, 35, 36, 37, 38, 39, 40, 41, 42}, BI_OFF[] = {42};+static const uint8_t BE_ON[] = {40, 41, 42}, BE_HIT[] = {32, 33, 34, 35, 36, 37, 38, 39, 40}, BE_OFF[] = {40};+static uint8_t BI_IDLE[34], BE_IDLE[32];+static const FAnim BUMPER_ANIMS[2][4] = {+ {{BI_ON, 3, 0, BA_IDLE, 0.06f}, {BI_IDLE, 34, 1, 255, 0.06f}, {BI_HIT, 9, 0, BA_OFF, 0.06f}, {BI_OFF, 1, 1, 255, 0.06f}},+ {{BE_ON, 3, 0, BA_IDLE, 0.06f}, {BE_IDLE, 32, 1, 255, 0.06f}, {BE_HIT, 9, 0, BA_OFF, 0.06f}, {BE_OFF, 1, 1, 255, 0.06f}}};+static uint16_t bumper_tex[2][45];+typedef struct {+ V2 anchor, start, end, hit_dir;+ float sine, tween, respawn;+ FSpr spr[2];+ Wiggler hit;+ uint8_t has_node, go_back, fire, mode;+} Bumper;+static void bumper_position(Ent *e) { /* UpdatePosition: anchor + (sine * 3, sine/2 * 2) */+ Bumper *b = ST(e, Bumper);+ e->x = b->anchor.x + sinf(b->sine) * 3, e->y = b->anchor.y + sinf(b->sine / 2) * 2;+}+static void bumper_on_player(Ent *e, Player *p) {+ Bumper *b = ST(e, Bumper);+ /* Circle(12) against the hurtbox */+ float l, t, r, bt;+ player_hurtbox(p->ent, &l, &t, &r, &bt);+ float nx = clampf(e->x, l, r), ny = clampf(e->y, t, bt);+ if ((nx - e->x) * (nx - e->x) + (ny - e->y) * (ny - e->y) >= 144) return;+ if (b->fire) {+ V2 v = safe_norm(v2sub(player_center(p), v2(e->x, e->y)), 1);+ b->hit_dir = v2mul(v, -1);+ wiggler_restart(&b->hit);+ b->respawn = 0.6f;+ player_die(p, v, false);+ particles_emit(PL_MID, &P_Bumper_P_FireHit, 12, v2add(v2(e->x, e->y), v2mul(v, 12)), v2(3, 3), vangle(v));+ } else if (b->respawn <= 0) {+ b->respawn = 0.6f;+ V2 v = player_explode_launch(p, v2(e->x, e->y), false);+ fs_play(&b->spr[0], BA_HIT, true);+ fs_play(&b->spr[1], BA_HIT, true);+ level_dir_shake(v, 0.15f);+ particles_emit(PL_MID, &P_Bumper_P_Launch, 12, v2add(v2(e->x, e->y), v2mul(v, 12)), v2(3, 3), vangle(v));+ }+}+static void bumper_update(Ent *e) {+ Bumper *b = ST(e, Bumper);+ /* CoreModeListener: the mode is read each frame */+ if (b->mode != g_level.core_mode) b->mode = (uint8_t)g_level.core_mode, b->fire = g_level.core_mode == 1;+ b->sine = fmodf(b->sine + 2 * PI_F * 0.44f * DT + PI_F * 8, PI_F * 8);+ if (b->has_node) { /* the looping tween, 1.8181819 s, CubeInOut */+ b->tween += DT / 1.8181819f;+ if (b->tween >= 1) b->tween -= 1, b->go_back = !b->go_back;+ float k = ease_cube_inout(b->tween);+ b->anchor = b->go_back ? v2lerp(b->end, b->start, k) : v2lerp(b->start, b->end, k);+ }+ fs_update(&b->spr[0], BUMPER_ANIMS[0]);+ fs_update(&b->spr[1], BUMPER_ANIMS[1]);+ wiggler_update(&b->hit);+ if (b->respawn > 0) {+ b->respawn -= DT;+ if (b->respawn <= 0) fs_play(&b->spr[0], BA_ON, false), fs_play(&b->spr[1], BA_ON, false);+ } else if (level_on_interval(0.05f)) {+ float a = rndf() * 2 * PI_F;+ float dir = b->fire ? -PI_F / 2 : a, len = b->fire ? 12.f : 8.f;+ particles_emit(PL_MID, b->fire ? &P_Bumper_P_FireAmbience : &P_Bumper_P_Ambience, 1, v2add(v2(e->x, e->y), angle_vec(a, len)),+ v2(2, 2), dir);+ }+ bumper_position(e);+}+static void bumper_render(Ent *e) {+ Bumper *b = ST(e, Bumper);+ int k = b->fire ? 1 : 0;+ float ox = k ? b->hit_dir.x * b->hit.value * 8 : 0, oy = k ? b->hit_dir.y * b->hit.value * 8 : 0;+ draw_centered(fs_tex(&b->spr[k], BUMPER_ANIMS[k], bumper_tex[k]), e->x + ox, e->y + oy, 0xFFFF, 255, 1, 1, 0);+ if (b->respawn <= 0) {+ light_add(e->x, e->y, 0x008080, 1, 16, 32); /* Color.Teal */+ bloom_add(e->x, e->y, 0.5f, 16);+ }+}+static const EntClass BUMPER = {.name = "bigSpinner", .size = sizeof(Bumper), .update = bumper_update, .render = bumper_render,+ .on_player = bumper_on_player, .kind = KIND_PCOLLIDE};+static void new_bumper(const EData *d) {+ Ent *e = ent_new(&BUMPER, d->x, d->y);+ if (!e) return;+ ent_box(e, 24, 24, -12, -12); /* Circle(12): the hit test is the circle */+ Bumper *b = ST(e, Bumper);+ b->anchor = b->start = v2(d->x, d->y);+ if (d->nnodes) b->has_node = 1, b->end = ed_node(d, 0);+ b->sine = fmodf(rndf() * PI_F * 2 * 2 + PI_F * 8, PI_F * 8); /* SineWave.Randomize */+ fs_play(&b->spr[0], BA_IDLE, true);+ fs_play(&b->spr[1], BA_IDLE, true);+ wiggler_init(&b->hit, 1.2f, 2);+ b->mode = 255;+ bumper_position(e);+ if (!bumper_tex[0][0]) {+ for (int i = 0; i < 34; i++) BI_IDLE[i] = (uint8_t)i;+ for (int i = 0; i < 32; i++) BE_IDLE[i] = (uint8_t)i;+ tex_family("objects/Bumper/Idle", bumper_tex[0], 45);+ tex_family("objects/Bumper/Evil", bumper_tex[1], 43);+ }+}++/* ---------------------------------------------------------------- FlyFeather (infiniteStar) */+typedef struct {+ CSpr spr;+ Wiggler wig, shield_wig, move_wig;+ V2 move_dir;+ float sine, respawn, light, co_wait, co_dir;+ uint8_t shielded, single, visible, outline, co, pad[3];+} Feather;+static void feather_on_player(Ent *e, Player *p) {+ Feather *f = ST(e, Feather);+ V2 speed = p->speed;+ if (f->shielded && !player_dash_attacking(p)) {+ player_point_bounce(p, e_center(e));+ wiggler_restart(&f->move_wig);+ wiggler_restart(&f->shield_wig);+ f->move_dir = safe_norm(v2sub(e_center(e), player_center(p)), 1);+ if (f->move_dir.x == 0 && f->move_dir.y == 0) f->move_dir = v2(0, 1);+ return;+ }+ if (player_start_star_fly(p)) {+ e->collidable = 0;+ level_shake(0.3f); /* CollectRoutine */+ f->visible = 0;+ f->co = 1, f->co_wait = 0.05f;+ f->co_dir = (speed.x != 0 || speed.y != 0) ? vangle(speed) : vangle(v2sub(v2(e->x, e->y), player_center(p)));+ if (!f->single) f->outline = 1, f->respawn = 3;+ }+}+static void feather_update(Ent *e) {+ Feather *f = ST(e, Feather);+ cs_update(&f->spr);+ wiggler_update(&f->wig);+ wiggler_update(&f->shield_wig);+ wiggler_update(&f->move_wig);+ f->sine = fmodf(f->sine + 2 * PI_F * 0.6f * DT + PI_F * 8, PI_F * 8);+ if (f->co) {+ if (f->co_wait > 0 && (f->co_wait -= DT) > 0) {+ } else {+ particles_emit(PL_FG, &P_FlyFeather_P_Collect, 10, v2(e->x, e->y), v2(6, 6), 0); /* SlashFx.Burst: not drawn */+ f->co = 0;+ }+ }+ if (f->respawn > 0) {+ f->respawn -= DT;+ if (f->respawn <= 0 && !e->collidable) { /* Respawn */+ f->outline = 0;+ e->collidable = 1;+ f->visible = 1;+ wiggler_restart(&f->wig);+ particles_emit(PL_FG, &P_FlyFeather_P_Respawn, 16, v2(e->x, e->y), v2(2, 2), 0);+ }+ }+ f->light = approach(f->light, f->visible ? 1 : 0, 4 * DT);+}+static void feather_render(Ent *e) {+ Feather *f = ST(e, Feather);+ float sx = -f->move_dir.x * f->move_wig.value * 8, sy = sinf(f->sine) * 2 - f->move_dir.y * f->move_wig.value * 8;+ if (f->outline) draw_centered(T_objects_flyFeather_outline, e->x, e->y, 0xFFFF, 255, 1, 1, 0);+ if (f->visible) {+ float s = 1 + f->wig.value * 0.2f;+ cs_draw(&f->spr, e->x + sx, e->y + sy, s, s, 0, 0xFFFF, 255);+ if (f->shielded) gfx_circle(e->x + sx, e->y + sy, 10 - f->shield_wig.value * 2, 0xFFFF, 255, 12);+ }+ light_add(e->x, e->y, 0xFFFFFF, f->light, 16, 48);+ bloom_add(e->x, e->y + sinf(f->sine) * 2, f->light * 0.8f, 20);+}+static const EntClass FEATHER = {.name = "infiniteStar", .size = sizeof(Feather), .update = feather_update, .render = feather_render,+ .on_player = feather_on_player, .kind = KIND_PCOLLIDE};+static void feather_new(float x, float y, bool shielded, bool single) {+ Ent *e = ent_new(&FEATHER, x, y);+ if (!e) return;+ ent_box(e, 20, 20, -10, -10);+ Feather *f = ST(e, Feather);+ f->shielded = shielded;+ f->single = single;+ f->visible = 1;+ f->light = 1;+ cs_init(&f->spr, SB_flyFeather);+ wiggler_init(&f->wig, 1, 4);+ wiggler_init(&f->shield_wig, 0.5f, 4);+ wiggler_init(&f->move_wig, 0.8f, 2);+ f->move_wig.start_zero = true;+ f->sine = fmodf(rndf() * PI_F * 2 * 2 + PI_F * 8, PI_F * 8);+}+static void new_feather(const EData *d) { feather_new(d->x, d->y, EAB(d, infiniteStar, shielded), EAB(d, infiniteStar, singleUse)); }++/* ---------------------------------------------------------------- StarJumpBlock */+/* its edges, railings and corners come from where other star jump blocks are: worked out at Awake */+typedef struct {+ float start_y, ylerp, sink;+ uint16_t seed;+ uint8_t sinks, w8, h8, corners, pad[2];+ uint8_t open[16]; /* top cells, bottom cells, left cells, right cells: one bit each */+} StarJump;+static uint16_t sj_left[7], sj_rail[7], sj_right[7], sj_edgeh[4], sj_edgev[4], sj_corner[4];+static const EntClass STARJUMP;+static bool sj_open(Ent *e, float x, float y) { /* Open: no star jump block at that cell's middle */+ float px = e->x + x + 4, py = e->y + y + 4;+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o->cls == &STARJUMP && o->dead != 1 && collide_rect(o, px, py, px + 1, py + 1)) return false;+ }+ return true;+}+static int sj_mod(int x, int m) { return (x % m + m) % m; }+static void sj_bit_set(StarJump *s, int i) {+ if (i < 128) s->open[i >> 3] |= (uint8_t)(1 << (i & 7));+}+static bool sj_bit(const StarJump *s, int i) { return i < 128 && (s->open[i >> 3] >> (i & 7) & 1); }+static void sj_awake(Ent *e) {+ StarJump *s = ST(e, StarJump);+ int w = (int)e->cw, h = (int)e->ch, k = 0;+ for (int i = 8; i < w - 8; i += 8, k++) {+ if (sj_open(e, (float)i, -8)) sj_bit_set(s, 2 * k);+ if (sj_open(e, (float)i, (float)h)) sj_bit_set(s, 2 * k + 1);+ }+ int base = 2 * k;+ k = 0;+ for (int j = 8; j < h - 8; j += 8, k++) {+ if (sj_open(e, -8, (float)j)) sj_bit_set(s, base + 2 * k);+ if (sj_open(e, (float)w, (float)j)) sj_bit_set(s, base + 2 * k + 1);+ }+ /* the corners: what each one's two neighbours are */+ uint8_t c = 0;+ c |= sj_open(e, -8, 0) << 0 | sj_open(e, 0, -8) << 1;+ c |= sj_open(e, (float)w, 0) << 2 | sj_open(e, w - 8.f, -8) << 3;+ c |= sj_open(e, -8, h - 8.f) << 4 | sj_open(e, 0, (float)h) << 5;+ c |= sj_open(e, (float)w, h - 8.f) << 6 | sj_open(e, w - 8.f, (float)h) << 7;+ s->corners = c;+}+static void sj_update(Ent *e) {+ StarJump *s = ST(e, StarJump);+ plat_update(e);+ if (!s->sinks) return;+ if (solid_has_player_rider(e)) s->sink = 0.1f;+ else if (s->sink > 0) s->sink -= DT;+ s->ylerp = approach(s->ylerp, s->sink > 0 ? 1 : 0, DT);+ plat_move_to_y(e, lerpf(s->start_y, s->start_y + 12, ease_sine_inout(s->ylerp)));+}+/* Calc.Random.Choose: a hash of the place */+static uint16_t sj_pick(StarJump *s, const uint16_t *t, int n, uint32_t at) { return t[(int)(hash01(s->seed, at) * n)]; }+static void sj_img(uint16_t t, float x, float y, float sx, float sy) { /* an Image with CenterOrigin */+ draw_centered(t, x, y, 0xFFFF, 255, sx, sy, 0);+}+static void sj_render(Ent *e) {+ StarJump *s = ST(e, StarJump);+ float x = e->x, y = e->y;+ int w = (int)e->cw, h = (int)e->ch, k = 0;+ if (x + w < g_camx - 8 || x > g_camx + 328 || y + h < g_camy - 8 || y > g_camy + 188) return;+ for (int i = 8; i < w - 8; i += 8, k++) {+ if (sj_bit(s, 2 * k)) {+ sj_img(sj_pick(s, sj_edgeh, 4, (uint32_t)k * 4), x + i + 4, y + 4, 1, 1);+ gfx_tex(sj_rail[sj_mod((int)(x + i) / 8, 7)], x + i, y - 8, 0, 0xFFFF, 255);+ }+ if (sj_bit(s, 2 * k + 1)) sj_img(sj_pick(s, sj_edgeh, 4, (uint32_t)k * 4 + 1), x + i + 4, y + h - 4, 1, -1);+ }+ int base = 2 * k;+ k = 0;+ for (int j = 8; j < h - 8; j += 8, k++) {+ if (sj_bit(s, base + 2 * k)) sj_img(sj_pick(s, sj_edgev, 4, (uint32_t)k * 4 + 2), x + 4, y + j + 4, -1, 1);+ if (sj_bit(s, base + 2 * k + 1)) sj_img(sj_pick(s, sj_edgev, 4, (uint32_t)k * 4 + 3), x + w - 4, y + j + 4, 1, 1);+ }+ uint8_t c = s->corners;+ /* top left */+ if ((c & 1) && (c & 2)) {+ sj_img(sj_pick(s, sj_corner, 4, 1000), x + 4, y + 4, -1, 1);+ gfx_tex(sj_left[sj_mod((int)x / 8, 7)], x, y - 8, 0, 0xFFFF, 255);+ } else if (c & 1)+ sj_img(sj_pick(s, sj_edgev, 4, 1000), x + 4, y + 4, -1, 1);+ else if (c & 2) {+ sj_img(sj_pick(s, sj_edgeh, 4, 1000), x + 4, y + 4, 1, 1);+ gfx_tex(sj_rail[sj_mod((int)x / 8, 7)], x, y - 8, 0, 0xFFFF, 255);+ }+ /* top right */+ if ((c & 4) && (c & 8)) {+ sj_img(sj_pick(s, sj_corner, 4, 1001), x + w - 4, y + 4, 1, 1);+ gfx_tex(sj_right[sj_mod((int)(x + w) / 8 - 1, 7)], x + w - 8, y - 8, 0, 0xFFFF, 255);+ } else if (c & 4)+ sj_img(sj_pick(s, sj_edgev, 4, 1001), x + w - 4, y + 4, 1, 1);+ else if (c & 8) {+ sj_img(sj_pick(s, sj_edgeh, 4, 1001), x + w - 4, y + 4, 1, 1);+ gfx_tex(sj_rail[sj_mod((int)(x + w) / 8 - 1, 7)], x + w - 8, y - 8, 0, 0xFFFF, 255);+ }+ /* bottom left */+ if ((c & 16) && (c & 32)) sj_img(sj_pick(s, sj_corner, 4, 1002), x + 4, y + h - 4, -1, -1);+ else if (c & 16)+ sj_img(sj_pick(s, sj_edgev, 4, 1002), x + 4, y + h - 4, -1, -1);+ else if (c & 32)+ sj_img(sj_pick(s, sj_edgeh, 4, 1002), x + 4, y + h - 4, 1, -1);+ /* bottom right */+ if ((c & 64) && (c & 128)) sj_img(sj_pick(s, sj_corner, 4, 1003), x + w - 4, y + h - 4, 1, -1);+ else if (c & 64)+ sj_img(sj_pick(s, sj_edgev, 4, 1003), x + w - 4, y + h - 4, 1, -1);+ else if (c & 128)+ sj_img(sj_pick(s, sj_edgeh, 4, 1003), x + w - 4, y + h - 4, 1, -1);+}+static const EntClass STARJUMP = {.name = "starJumpBlock", .size = sizeof(StarJump), .update = sj_update, .render = sj_render,+ .awake = sj_awake, .kind = KIND_SOLID};+static void new_starjump(const EData *d) {+ Ent *e = ent_new(&STARJUMP, d->x, d->y);+ if (!e) return;+ ent_box(e, EA(d, starJumpBlock, width), EA(d, starJumpBlock, height), 0, 0);+ e->depth = -10000;+ StarJump *s = ST(e, StarJump);+ s->sinks = EAB(d, starJumpBlock, sinks);+ s->start_y = d->y;+ s->seed = (uint16_t)rndi(65536);+ if (!sj_rail[0]) {+ tex_family("objects/starjumpBlock/leftrailing", sj_left, 7);+ tex_family("objects/starjumpBlock/railing", sj_rail, 7);+ tex_family("objects/starjumpBlock/rightrailing", sj_right, 7);+ tex_family("objects/starjumpBlock/edgeH", sj_edgeh, 4);+ tex_family("objects/starjumpBlock/edgeV", sj_edgev, 4);+ tex_family("objects/starjumpBlock/corner", sj_corner, 4);+ }+}++/* ---------------------------------------------------------------- Plateau */+static void plateau_render(Ent *e) { gfx_tex(T_scenery_fallplateau, e->x, e->y, 0, 0xFFFF, 255); }+static const EntClass PLATEAU = {.name = "plateau", .update = plat_update, .render = plateau_render, .kind = KIND_SOLID};+static void new_plateau(const EData *d) {+ Ent *e = ent_new(&PLATEAU, d->x, d->y);+ if (!e) return;+ ent_box(e, 104, 4, 8, 0); /* Collider.Left += 8 */+ e->safe = 1;+}++/* ---------------------------------------------------------------- CrushBlock (Kevin) */+#define KEVIN_STACK 8+typedef struct {+ V2 crush_dir;+ float speed, co_wait, alarm, wait_sfx;+ CSpr face;+ int16_t ret[KEVIN_STACK][2]; /* returnStack: From */+ int8_t retdir[KEVIN_STACK][2]; /* and Direction */+ uint16_t seed;+ uint8_t nret, can_activate, can_h, can_v, chill, giant, axes, co, slowing, next_face, lit, pad;+} Kevin;+static uint16_t kevin_block[4], kevin_lit[4]; /* lit: left, right, top, bottom */+static void kevin_particles(Ent *e, V2 dir) { /* ActivateParticles */+ float a;+ V2 at, range;+ int n;+ if (dir.x > 0) a = 0, at = v2(e_right(e) - 1, e_cym(e)), range = v2(0, (e->ch - 2) * 0.5f), n = (int)(e->ch / 8) * 4;+ else if (dir.x < 0) a = PI_F, at = v2(e_left(e) + 1, e_cym(e)), range = v2(0, (e->ch - 2) * 0.5f), n = (int)(e->ch / 8) * 4;+ else if (dir.y > 0) a = PI_F / 2, at = v2(e_cxm(e), e_bottom(e) - 1), range = v2((e->cw - 2) * 0.5f, 0), n = (int)(e->cw / 8) * 4;+ else a = -PI_F / 2, at = v2(e_cxm(e), e_top(e) + 1), range = v2((e->cw - 2) * 0.5f, 0), n = (int)(e->cw / 8) * 4;+ particles_emit(PL_MID, &P_CrushBlock_P_Activate, n + 2, at, range, a);+}+static bool kevin_can(Kevin *k, V2 dir) { /* CanActivate */+ if (k->giant && dir.x <= 0) return false;+ if (k->can_activate && !v2eq(k->crush_dir, dir)) {+ if (dir.x != 0 && !k->can_h) return false;+ if (dir.y != 0 && !k->can_v) return false;+ return true;+ }+ return false;+}+static void kevin_attack(Ent *e, V2 dir) {+ Kevin *k = ST(e, Kevin);+ cs_play(&k->face, k->giant ? A_giant_crushblock_face_hit : A_crushblock_face_hit, false);+ k->crush_dir = dir;+ k->can_activate = 0;+ k->co = 1, k->co_wait = 0, k->slowing = 0, k->alarm = 0; /* attackCoroutine.Replace(AttackSequence()) */+ e->remx = e->remy = 0;+ kevin_particles(e, dir);+ k->lit = dir.x < 0 ? 1 : dir.x > 0 ? 2 : dir.y < 0 ? 3 : 4;+ k->next_face = dir.x < 0 ? 0 : dir.x > 0 ? 1 : dir.y < 0 ? 2 : 3;+ bool push = true;+ if (k->nret) {+ int8_t *t = k->retdir[k->nret - 1];+ if ((t[0] == dir.x && t[1] == dir.y) || (t[0] == -dir.x && t[1] == -dir.y)) push = false;+ }+ if (push && k->nret < KEVIN_STACK) {+ k->ret[k->nret][0] = (int16_t)e->x, k->ret[k->nret][1] = (int16_t)e->y;+ k->retdir[k->nret][0] = (int8_t)dir.x, k->retdir[k->nret][1] = (int8_t)dir.y;+ k->nret++;+ }+}+static int kevin_dashed(Ent *e, Player *p, V2 dir) {+ (void)p;+ if (kevin_can(ST(e, Kevin), v2mul(dir, -1))) {+ kevin_attack(e, v2mul(dir, -1));+ return DASH_REBOUND;+ }+ return DASH_NORMAL;+}+/* MoveHCollideSolidsAndBounds / MoveVCollideSolidsAndBounds */+static bool kevin_move_bounds(Ent *e, float amount, bool vertical, bool check_bottom) {+ Room *rm = g_level.room;+ if (vertical) e->lift.y = amount / DT;+ else e->lift.x = amount / DT;+ float *rem = vertical ? &e->remy : &e->remx;+ *rem += amount;+ int n = roundi(*rem);+ if (!n) return false;+ *rem -= n;+ bool hit;+ if (!vertical) {+ if (e_left(e) + n < rm->x) hit = true, n = rm->x - (int)e_left(e);+ else if (e_right(e) + n > rm->x + rm->w) hit = true, n = rm->x + rm->w - (int)e_right(e);+ else hit = false;+ } else {+ int bottom = rm->y + rm->h + 32;+ if (e_top(e) + n < rm->y) hit = true, n = rm->y - (int)e_top(e);+ else if (check_bottom && e_bottom(e) + n > bottom) hit = true, n = bottom - (int)e_bottom(e);+ else hit = false;+ }+ /* MoveExactCollideSolids through the engine: a whole move, with no remainder */+ float keep = *rem, lift = vertical ? e->lift.y : e->lift.x;+ *rem = 0;+ bool solid = vertical ? plat_move_v_collide_solids(e, (float)n, true) : plat_move_h_collide_solids(e, (float)n, true);+ *rem = keep;+ if (vertical) e->lift.y = lift;+ else e->lift.x = lift;+ return solid || hit;+}+static bool kevin_move_check(Ent *e, float amount, bool vertical) { /* MoveHCheck / MoveVCheck */+ Room *rm = g_level.room;+ if (!kevin_move_bounds(e, amount, vertical, !vertical)) return false;+ if (!vertical) {+ if (amount < 0 && e_left(e) <= rm->x) return true;+ if (amount > 0 && e_right(e) >= rm->x + rm->w) return true;+ } else if (amount < 0 && e_top(e) <= rm->y)+ return true;+ for (int i = 1; i <= 4; i++)+ for (int s = 1; s >= -1; s -= 2) {+ float dx = vertical ? (float)(i * s) : (float)sgn(amount), dy = vertical ? (float)sgn(amount) : (float)(i * s);+ if (!collide_solid(e, e->x + dx, e->y + dy)) {+ if (vertical) plat_move_h_exact(e, i * s), plat_move_v_exact(e, sgn(amount));+ else plat_move_v_exact(e, i * s), plat_move_h_exact(e, sgn(amount));+ return false;+ }+ }+ return true;+}+static bool point_water(V2 p);+static void kevin_impact(Ent *e) { /* the impact particles where it hit solids */+ Kevin *k = ST(e, Kevin);+ V2 d = k->crush_dir;+ if (d.x != 0) {+ float x = d.x < 0 ? e_left(e) - 1 : e_right(e) + 1;+ for (int i = 0; i < e->ch / 8; i++) {+ V2 p = v2(x, e_top(e) + 4 + i * 8);+ if (!point_water(p) && point_solid(p.x, p.y)) {+ particles_emit1(PL_FG, &P_CrushBlock_P_Impact, v2add(p, v2(0, 2)), d.x < 0 ? 0 : PI_F);+ particles_emit1(PL_FG, &P_CrushBlock_P_Impact, v2sub(p, v2(0, 2)), d.x < 0 ? 0 : PI_F);+ }+ }+ } else {+ float y = d.y < 0 ? e_top(e) - 1 : e_bottom(e) + 1;+ for (int i = 0; i < e->cw / 8; i++) {+ V2 p = v2(e_left(e) + 4 + i * 8, y);+ if (!point_water(p) && point_solid(p.x, p.y)) {+ particles_emit1(PL_FG, &P_CrushBlock_P_Impact, v2add(p, v2(2, 0)), d.y < 0 ? PI_F / 2 : -PI_F / 2);+ particles_emit1(PL_FG, &P_CrushBlock_P_Impact, v2sub(p, v2(2, 0)), d.y < 0 ? PI_F / 2 : -PI_F / 2);+ }+ }+ }+}+static void kevin_update(Ent *e) {+ Kevin *k = ST(e, Kevin);+ plat_update(e);+ int ended = cs_update(&k->face);+ if (ended == (k->giant ? A_giant_crushblock_face_hit : A_crushblock_face_hit)) { /* OnLastFrame("hit") */+ static const int FACE[4] = {A_crushblock_face_left, A_crushblock_face_right, A_crushblock_face_up, A_crushblock_face_down};+ if (k->giant) cs_play(&k->face, A_giant_crushblock_face_right, false);+ else cs_play(&k->face, FACE[k->next_face], false);+ }+ if (k->alarm > 0 && (k->alarm -= DT) <= 0) { /* chillOut's slowing alarm */+ cs_play(&k->face, k->giant ? A_giant_crushblock_face_hurt : A_crushblock_face_hurt, false);+ k->lit = 0;+ }+ /* AttackSequence */+ if (k->co) {+ if (k->co_wait > 0) k->co_wait -= DT;+ else+ switch (k->co) {+ case 1:+ plat_start_shaking(e, 0.4f);+ k->co_wait = 0.4f;+ k->co = 2;+ break;+ case 2:+ if (!k->chill) k->can_activate = 1;+ k->speed = 0;+ k->co = 3;+ /* fall through */+ case 3: {+ if (!k->chill) k->speed = approach(k->speed, 240, 500 * DT);+ else if (k->slowing || tiles_solid_rect(e_left(e) + k->crush_dir.x * 256, e_top(e) + k->crush_dir.y * 256,+ e_right(e) + k->crush_dir.x * 256, e_bottom(e) + k->crush_dir.y * 256)) {+ k->speed = approach(k->speed, 24, 500 * DT * 0.25f);+ if (!k->slowing) k->slowing = 1, k->alarm = 0.5f;+ } else+ k->speed = approach(k->speed, 240, 500 * DT);+ bool hit = k->crush_dir.x == 0 ? kevin_move_check(e, k->speed * k->crush_dir.y * DT, true)+ : kevin_move_check(e, k->speed * k->crush_dir.x * DT, false);+ k = ST(e, Kevin);+ if (e_top(e) >= g_level.room->y + g_level.room->h + 32) {+ ent_remove(e);+ return;+ }+ if (!hit) {+ if (level_on_interval(0.02f)) {+ V2 at;+ float a;+ if (k->crush_dir.x > 0) at = v2(e_left(e) + 1, rnd_rangef(e_top(e) + 3, e_bottom(e) - 3)), a = PI_F;+ else if (k->crush_dir.x < 0) at = v2(e_right(e) - 1, rnd_rangef(e_top(e) + 3, e_bottom(e) - 3)), a = 0;+ else if (k->crush_dir.y > 0) at = v2(rnd_rangef(e_left(e) + 3, e_right(e) - 3), e_top(e) + 1), a = -PI_F / 2;+ else at = v2(rnd_rangef(e_left(e) + 3, e_right(e) - 3), e_bottom(e) - 1), a = PI_F / 2;+ particles_emit1(PL_MID, &P_CrushBlock_P_Crushing, at, a);+ }+ break;+ }+ /* CollideFirst<FallingBlock>(Position + crushDir).Triggered = true */+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o->cls && o->dead != 1 && !strcmp(o->cls->name, "fallingBlock") && collide_ent_at(e, e->x + k->crush_dir.x, e->y + k->crush_dir.y, o) &&+ o->cls->on_staticmover_trigger)+ o->cls->on_staticmover_trigger(o, NULL);+ }+ kevin_impact(e);+ level_dir_shake(k->crush_dir, 0.3f);+ plat_start_shaking(e, 0.4f);+ k->crush_dir = v2(0, 0);+ k->lit = 0;+ if (k->chill) {+ k->co = 0;+ break;+ }+ cs_play(&k->face, k->giant ? A_giant_crushblock_face_hurt : A_crushblock_face_hurt, false);+ k->co_wait = 0.4f;+ k->co = 4;+ k->speed = 0;+ k->wait_sfx = 0;+ break;+ }+ case 4: /* the return: a frame first (yield null), then towards the last place */+ k->co = 5;+ break;+ case 5: {+ if (!k->nret) {+ k->co = 0;+ break;+ }+ k->speed = approach(k->speed, 60, 160 * DT);+ k->wait_sfx -= DT;+ int16_t *from = k->ret[k->nret - 1];+ int8_t *dir = k->retdir[k->nret - 1];+ if (dir[0] != 0) plat_move_towards_x(e, from[0], k->speed * DT);+ if (dir[1] != 0) plat_move_towards_y(e, from[1], k->speed * DT);+ k = ST(e, Kevin);+ V2 ex = plat_exact(e);+ if ((dir[0] != 0 && ex.x != from[0]) || (dir[1] != 0 && ex.y != from[1])) {+ k->co = 4;+ break;+ }+ k->speed = 0;+ k->nret--;+ if (!k->nret) cs_play(&k->face, k->giant ? A_giant_crushblock_face_idle : A_crushblock_face_idle, false);+ k->wait_sfx = 0.1f;+ plat_start_shaking(e, 0.2f);+ k->co_wait = 0.2f;+ k->co = 4;+ break;+ }+ }+ }+}+static void kevin_render(Ent *e) {+ Kevin *k = ST(e, Kevin);+ float x = e->x + e->shakex, y = e->y + e->shakey;+ int w = (int)e->cw, h = (int)e->ch, nx = w / 8 - 1, ny = h / 8 - 1;+ gfx_rect(x + 2, y + 2, w - 4, h - 4, rgb(0x62222B), 255);+ uint16_t idle = kevin_block[k->axes];+ /* AddImage: the border tiles (a black copy outside each), with the lit edges over them */+ for (int pass = 0; pass < 2; pass++)+ for (int i = 0; i <= nx; i++)+ for (int j = 0; j <= ny; j++) {+ if (i != 0 && i != nx && j != 0 && j != ny) continue;+ int bx = i == 0 ? -1 : i == nx ? 1 : 0, by = j == 0 ? -1 : j == ny ? 1 : 0;+ int tx = i == 0 ? 0 : i == nx ? 3 : 1 + (int)(hash01(k->seed, (uint32_t)(i * 64 + j)) * 2);+ int ty = j == 0 ? 0 : j == ny ? 3 : 1 + (int)(hash01(k->seed, (uint32_t)(i * 64 + j) + 4096) * 2);+ if (bx != 0 && by != 0) tx = i == 0 ? 0 : 3, ty = j == 0 ? 0 : 3;+ float px = x + i * 8, py = y + j * 8;+ if (!pass) {+ if (bx) gfx_tex_part(idle, px + bx, py, tx * 8, ty * 8, 8, 8, GF_SILHOUETTE, 0, 255);+ if (by) gfx_tex_part(idle, px, py + by, tx * 8, ty * 8, 8, 8, GF_SILHOUETTE, 0, 255);+ continue;+ }+ gfx_tex_part(idle, px, py, tx * 8, ty * 8, 8, 8, 0, 0xFFFF, 255);+ if (k->lit == 1 && bx < 0) gfx_tex_part(kevin_lit[0], px, py, 0, ty * 8, 8, 8, 0, 0xFFFF, 255);+ if (k->lit == 2 && bx > 0) gfx_tex_part(kevin_lit[1], px, py, 0, ty * 8, 8, 8, 0, 0xFFFF, 255);+ if (k->lit == 3 && by < 0) gfx_tex_part(kevin_lit[2], px, py, tx * 8, 0, 8, 8, 0, 0xFFFF, 255);+ if (k->lit == 4 && by > 0) gfx_tex_part(kevin_lit[3], px, py, tx * 8, 0, 8, 8, 0, 0xFFFF, 255);+ }+ /* the face, nudged towards a player pressed against it */+ float fx = w / 2.f, fy = h / 2.f;+ if (k->crush_dir.x == 0 && k->crush_dir.y == 0) {+ Ent *pe = level_player_ent();+ if (pe && collide_ent_at(e, e->x - 1, e->y, pe)) fx -= 1;+ else if (pe && collide_ent_at(e, e->x + 1, e->y, pe)) fx += 1;+ else if (pe && collide_ent_at(e, e->x, e->y - 1, pe)) fy -= 1;+ }+ cs_draw(&k->face, x + fx, y + fy, 1, 1, 0, 0xFFFF, 255);+}+static const EntClass KEVIN = {.name = "crushBlock", .size = sizeof(Kevin), .update = kevin_update, .render = kevin_render,+ .on_dash_collide = kevin_dashed, .kind = KIND_SOLID};+static void new_kevin(const EData *d) {+ float w = EA(d, crushBlock, width), h = EA(d, crushBlock, height);+ Ent *e = ent_new(&KEVIN, d->x, d->y);+ if (!e) return;+ ent_box(e, w, h, 0, 0);+ Kevin *k = ST(e, Kevin);+ k->chill = EAB(d, crushBlock, chillout);+ k->giant = w >= 48 && h >= 48 && k->chill;+ k->can_activate = 1;+ const char *ax = EAS(d, crushBlock, axes);+ if (!strcmp(ax, "horizontal")) k->axes = 1, k->can_h = 1;+ else if (!strcmp(ax, "vertical")) k->axes = 2, k->can_v = 1;+ else k->axes = 3, k->can_h = k->can_v = 1;+ k->seed = (uint16_t)rndi(65536);+ cs_init(&k->face, k->giant ? SB_giant_crushblock_face : SB_crushblock_face);+ if (!kevin_block[0]) {+ tex_family("objects/crushblock/block", kevin_block, 4);+ kevin_lit[0] = tex_named("objects/crushblock/lit_left");+ kevin_lit[1] = tex_named("objects/crushblock/lit_right");+ kevin_lit[2] = tex_named("objects/crushblock/lit_top");+ kevin_lit[3] = tex_named("objects/crushblock/lit_bottom");+ }+}+/* ---------------------------------------------------------------- Water (ch3.c's): what the blocks ask of it */+static bool point_water(V2 p) { /* Scene.CollideCheck<Water>(point) */+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if ((o->kind & KIND_WATER) && o->cls && o->dead != 1 && o->collidable && collide_rect(o, p.x, p.y, p.x + 1, p.y + 1)) return true;+ }+ return false;+}++/* ---------------------------------------------------------------- BigWaterfall */+typedef struct { float sine, fade; uint8_t fg, nlines, pad[2]; float lines[8]; } Waterfall;+static float wf_render_x(Ent *e) { /* RenderPositionAtCamera(camera + (160, 90)).X */+ Waterfall *w = ST(e, Waterfall);+ float val = e->x + e->cw / 2 - (g_level.cam.x + 160);+ return e->x + (w->fg ? val * 0.2f : -val * 0.6f);+}+static void wf_update(Ent *e) {+ Waterfall *w = ST(e, Waterfall);+ w->sine += DT;+ /* TransitionListener: OnIn fade = f, OnOut fade = 1 - f */+ if (g_level.transitioning) w->fade = e->room == g_level.room_slot ? g_level.tr_at : 1 - g_level.tr_at;+}+/* the BG layer: every 3 rows its edges and lines are pushed sideways by a sine */+static void wf_strip(uint16_t *strip, int y0, int y1, void *ctx) {+ Ent *e = ctx;+ Waterfall *w = ST(e, Waterfall);+ uint16_t surf = rgb(0x89DBF0), fill = rgb(0x29A7EA);+ int sa = (int)(128 * w->fade), fa = (int)(77 * w->fade);+ int x = (int)wf_render_x(e) - g_camx, W = (int)e->cw;+ float start = fmaxf(e->y, floorf(g_level.cam.y / 3) * 3);+ for (int vy = y0; vy < y1; vy++) {+ float wy = (float)(vy + g_camy);+ if (wy < start || wy >= e->y + e->ch) continue;+ float row = start + floorf((wy - start) / 3) * 3;+ int n = (int)(sinf(row / 6 - w->sine * 8) * 2);+ uint16_t *line = strip + (vy - y0) * VIEW_W;+ if (fa > 0)+ for (int i = 0; i < W; i++) { /* Draw.Rect(x, y, width, height, fillColor) */+ int vx = x + i;+ if ((unsigned)vx < VIEW_W) line[vx] = blend565(line[vx], scale565(fill, fa), fa);+ }+ for (int i = 0; i < 4 + n; i++) px_blend(strip, y0, y1, x + i, vy, surf, sa);+ for (int i = W - 4 + n; i < W; i++) px_blend(strip, y0, y1, x + i, vy, surf, sa);+ for (int k = 0; k < w->nlines; k++) px_blend(strip, y0, y1, x + n + (int)w->lines[k], vy, surf, sa);+ }+}+static void wf_render(Ent *e) {+ Waterfall *w = ST(e, Waterfall);+ float x = wf_render_x(e);+ if (x + e->cw + 4 < g_camx || x - 4 > g_camx + VIEW_W) return;+ if (w->fg) { /* Water.FillColor (LightSkyBlue * 0.3) and SurfaceColor (* 0.8) */+ uint16_t c = rgb(0x87CEFA);+ uint8_t fa = a8(0.3f * w->fade), sa = a8(0.8f * w->fade);+ gfx_rect(x, e->y, e->cw, e->ch, c, fa);+ gfx_rect(x - 1, e->y, 3, e->ch, c, sa);+ gfx_rect(x + e->cw - 2, e->y, 3, e->ch, c, sa);+ for (int k = 0; k < w->nlines; k++) gfx_rect(x + w->lines[k], e->y, 1, e->ch, c, sa);+ return;+ }+ int y0 = (int)e->y - g_camy, y1 = (int)(e->y + e->ch) - g_camy;+ if (y1 <= 0 || y0 >= VIEW_H) return;+ gfx_custom(wf_strip, e, y0 < 0 ? 0 : y0, y1 > VIEW_H ? VIEW_H : y1);+}+static const EntClass WATERFALL = {.name = "bigWaterfall", .size = sizeof(Waterfall), .update = wf_update, .render = wf_render};+static void new_waterfall(const EData *d) {+ float w = EA(d, bigWaterfall, width), h = EA(d, bigWaterfall, height);+ Ent *e = ent_new(&WATERFALL, d->x, d->y);+ if (!e) return;+ ent_box(e, w, h, 0, 0);+ e->collidable = 0;+ e->tags = TAG_TRANSITION_UPDATE;+ Waterfall *f = ST(e, Waterfall);+ f->fg = !strcmp(EAS(d, bigWaterfall, layer), "FG");+ f->fade = g_level.transitioning ? 0 : 1; /* Added */+ e->depth = f->fg ? -49900 : 10010;+ (void)rndf(); /* its parallax: only RenderPosition is drawn */+ f->lines[0] = f->fg ? 3 : 6, f->lines[1] = f->fg ? w - 4 : w - 7;+ f->nlines = 2;+ if (w > 16) {+ int n = rndi((int)(w / 16));+ for (int i = 0; i < n && f->nlines < 8; i++) f->lines[f->nlines++] = 8 + rndf() * (w - 16);+ }+}++/* ---------------------------------------------------------------- BadelineBoost */+/* Sprites.xml's objects/badelineBoost/ is objects/badelineboost/ in the atlas: the frames are listed here */+enum { BB_IDLE, BB_FLASH, BB_BLINK };+static const uint8_t BBF_IDLE[] = {0, 1, 2, 3, 4, 5}, BBF_FLASH[] = {6, 7, 8, 9, 10, 11},+ BBF_BLINK[] = {12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25};+static const FAnim BB_ANIMS[3] = {{BBF_IDLE, 6, 0, 255, 0.08f}, {BBF_FLASH, 6, 0, BB_IDLE, 0.08f}, {BBF_BLINK, 14, 0, BB_IDLE, 0.08f}};+static uint16_t bb_tex[26];+#define BB_NODES 8+typedef struct {+ FSpr spr;+ CSpr dummy; /* BadelineDummy: her sprite (the hair is not drawn) */+ Wiggler wig;+ SineWave wave; /* the dummy's float */+ V2 spr_pos, pfrom, pto, bfrom, bto, from, to, dummy_at;+ float wait, p, alarm;+ Tween tw;+ int16_t nodes[BB_NODES][2];+ uint8_t node, nnodes, co, holding, travelling, dummy_on, stretch, can_skip;+ int8_t dummy_facing, final_, tw_on, lock;+} BBoost;+/* the tween to the next node: from the routine it starts next frame, from Skip (before the components) now */+static void bboost_tween_begin(Ent *e, bool now) {+ BBoost *b = ST(e, BBoost);+ b->from = v2(e->x, e->y);+ b->to = v2(b->nodes[b->node][0], b->nodes[b->node][1]);+ tween_start(&b->tw, fminf(3, v2len(v2sub(b->to, b->from)) / 320));+ b->tw_on = now ? 1 : 2;+ b->stretch = 1;+}+static void bboost_on_player(Ent *e, Player *p) {+ BBoost *b = ST(e, BBoost);+ if (b->co) return;+ /* BoostRoutine, up to its first yield */+ b->holding = 1, b->travelling = 1;+ b->node++;+ b->spr_pos = v2(0, 0);+ e->collidable = 0;+ b->final_ = b->node >= b->nnodes;+ /* TODO cutscene: finalCh9Boost (CS10_FinalLaunch) is Farewell's */+ if (p->holding) { /* Drop() */+ Ent *h = p->holding;+ p->holding = NULL;+ holdable_release(h, v2(0, 0));+ }+ player_set_state(p, ST_DUMMY);+ p->dummy_auto_animate = false;+ p->dummy_gravity = false;+ if (p->inventory_dashes > 1) p->dashes = 1;+ else player_refill_dash(p);+ player_refill_stamina(p);+ p->speed = v2(0, 0);+ int num = sgn(p->ent->x - e->x);+ if (num == 0) num = -1;+ b->dummy_on = 1;+ cs_init(&b->dummy, SB_badeline);+ cs_play(&b->dummy, A_badeline_fallSlow, true);+ sine_set(&b->wave, 0);+ p->facing = -num;+ b->dummy_facing = (int8_t)num;+ b->pfrom = v2(p->ent->x, p->ent->y);+ b->pto = v2add(v2(e->x, e->y), v2((float)(num * 4), -3));+ b->bfrom = b->dummy_at = v2(e->x, e->y);+ b->bto = v2add(v2(e->x, e->y), v2((float)(-num * 4), 3));+ b->p = 0;+ b->co = 1;+}+static void bboost_routine(Ent *e) {+ BBoost *b = ST(e, BBoost);+ Player *p = level_player();+ if (b->wait > 0) {+ b->wait -= DT;+ return;+ }+ switch (b->co) {+ case 1: /* for (p = 0; p < 1; p += DT / 0.2): both move together */+ if (b->p < 1) {+ V2 v = v2lerp(b->pfrom, b->pto, b->p);+ if (p && p->ent->cls) actor_move_to_x(p->ent, v.x, NULL), actor_move_to_y(p->ent, v.y, NULL);+ b->dummy_at = v2lerp(b->bfrom, b->bto, b->p);+ b->p += DT / 0.2f;+ break;+ }+ /* finalBoost: Level.ZoomTo(1.5) and Engine.TimeRate 0.5 are not done */+ cs_play(&b->dummy, A_badeline_boost, false);+ b->wait = 0.1f;+ b->co = 2;+ break;+ case 2:+ if (p && !p->dead) actor_move_v(p->ent, 5, NULL, NULL);+ b->wait = 0.1f;+ b->co = 3;+ break;+ case 3:+ /* endLevel (Farewell's golden boost) does not happen here */+ b->alarm = 0.15f; /* then a dash back for the player, and the dummy goes */+ level_shake(0.3f);+ b->holding = 0;+ if (!b->final_) {+ if (p) { /* Player.BadelineBoostLaunch(CenterX) */+ p->launch_approach_x = e->x, p->has_launch_approach = true;+ p->speed = v2(0, -330);+ p->auto_jump = true;+ if (p->holding) {+ Ent *h = p->holding;+ p->holding = NULL;+ holdable_release(h, v2(0, 0));+ }+ player_refill_dash(p);+ player_refill_stamina(p);+ p->dash_cooldown_timer = 0.2f;+ player_set_state(p, ST_LAUNCH);+ }+ bboost_tween_begin(e, false);+ level_dir_shake(v2(0, -1), 0.3f);+ b->co = 0;+ } else {+ level_freeze(0.1f); /* Engine.FreezeTimer */+ b->co = 4;+ }+ break;+ case 4: /* after a yield null (the displacement is not drawn) */+ level_flash_a(0xFFFF, 0.5f, true);+ level_dir_shake(v2(0, -1), 0.6f);+ if (p) { /* Player.SummitLaunch(X) */+ p->summit_target_x = e->x;+ player_set_state(p, ST_SUMMITLAUNCH);+ }+ /* Finish() */+ particles_emit(PL_MID, &P_BadelineOldsite_P_Vanish, 12, v2(e->x, e->y), v2(6, 6), P_BadelineOldsite_P_Vanish.direction);+ g_level.cam_lock = 0;+ g_level.cam_offset = v2(0, -16);+ ent_remove(e);+ b->co = 0;+ break;+ }+}+static void bboost_update(Ent *e) {+ BBoost *b = ST(e, BBoost);+ Player *p = level_player();+ bool visible = !b->holding && !b->travelling;+ if (visible && level_on_interval(0.05f))+ particles_emit(PL_BG, &P_BadelineBoost_P_Ambience, 1, v2(e->x, e->y), v2(3, 3), P_BadelineBoost_P_Ambience.direction);+ if (b->holding && p) p->speed = v2(0, 0);+ if (!b->travelling && p) {+ V2 d = v2sub(player_center(p), v2(e->x, e->y));+ float num = clamped_map(v2len(d), 16, 64, 12, 0);+ b->spr_pos = approach_v(b->spr_pos, v2mul(safe_norm(d, 1), num), 32 * DT);+ if (b->can_skip && p->ent->x - e->x >= 100 && b->node + 1 < b->nnodes) { /* Skip() */+ b->travelling = 1;+ b->node++;+ e->collidable = 0;+ bboost_tween_begin(e, true);+ }+ }+ /* components: the sprite, the stretch tween, the wiggler, the alarm, the routine */+ fs_update(&b->spr, BB_ANIMS);+ if (!b->spr.playing && b->spr.anim == BB_IDLE) { /* goto="idle:10,flash:2,blink" */+ int r = rndi(13);+ fs_play(&b->spr, r < 10 ? BB_IDLE : r < 12 ? BB_FLASH : BB_BLINK, true);+ }+ if (b->tw_on == 2) b->tw_on = 1; /* added by last frame's routine: it runs from now on */+ if (b->stretch && b->tw_on == 1) {+ {+ bool done = tween_update(&b->tw);+ float k = ease_sine_inout(b->tw.percent);+ V2 at = v2lerp(b->from, b->to, k);+ e->x = at.x, e->y = at.y;+ if (k < 0.9f && level_on_interval(0.03f)) {+ uint16_t t = fs_tex(&b->spr, BB_ANIMS, bb_tex);+ if (t != 0xFFFF) trail_add(e->x + b->spr_pos.x, e->y + b->spr_pos.y, t, 12, 12, 1, 1, 0xFF6DEF, 0.5f);+ particles_emit(PL_FG, &P_BadelineBoost_P_Move, 1, v2(e->x, e->y), v2(4, 4), P_BadelineBoost_P_Move.direction);+ }+ if (done) {+ b->stretch = 0, b->tw_on = 0;+ if (e->x >= g_level.room->x + g_level.room->w) {+ ent_remove(e);+ return;+ }+ b->travelling = 0;+ e->collidable = 1;+ }+ }+ }+ if (b->dummy_on) {+ cs_update(&b->dummy);+ sine_update(&b->wave);+ }+ wiggler_update(&b->wig);+ if (b->alarm > 0 && (b->alarm -= DT) <= 0) {+ if (p && p->dashes < p->inventory_dashes) p->dashes++;+ b->dummy_on = 0;+ }+ if (b->co) bboost_routine(e);+}+static void bboost_render(Ent *e) {+ BBoost *b = ST(e, BBoost);+ if (b->dummy_on) {+ cs_draw(&b->dummy, b->dummy_at.x, b->dummy_at.y + b->wave.value * 2, (float)b->dummy_facing, 1, 0, 0xFFFF, 255);+ light_add(b->dummy_at.x, b->dummy_at.y - 8, 0xDB7093, 1, 20, 60); /* Color.PaleVioletRed */+ }+ bool visible = !b->holding && !b->travelling;+ if (visible) {+ float s = 1 + b->wig.value * 0.4f;+ draw_centered(fs_tex(&b->spr, BB_ANIMS, bb_tex), e->x + b->spr_pos.x, e->y + b->spr_pos.y, 0xFFFF, 255, s, s, 0);+ }+ if (b->stretch && b->tw_on == 1) {+ float k = yoyo(ease_sine_inout(b->tw.percent));+ draw_centered(T_objects_badelineboost_stretch, e->x, e->y, 0xFFFF, 255, 1 + k * 2, 1 - k * 0.75f, vangle(v2sub(b->to, b->from)));+ }+ if (visible || b->stretch) {+ light_add(e->x, e->y, 0xFFFFFF, 0.7f, 12, 20);+ bloom_add(e->x, e->y, 0.5f, 12);+ }+}+static void bboost_awake(Ent *e) { /* CollideCheck<FakeWall>: in front of it */+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o->cls && o->dead != 1 && o->collidable && !strcmp(o->cls->name, "fakeWall") && collide_ent_at(e, e->x, e->y, o)) e->depth = -12500;+ }+}+/* Level.LoadLevel sets CameraLockMode back to None: here, when the locking entity goes with its room */+static void lock_release(Ent *e) {+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o != e && o->cls == e->cls && o->dead != 1) return;+ }+ g_level.cam_lock = 0;+}+static void bboost_removed(Ent *e) {+ if (ST(e, BBoost)->lock) lock_release(e);+}+static const EntClass BBOOST = {.name = "badelineBoost", .size = sizeof(BBoost), .update = bboost_update, .render = bboost_render,+ .awake = bboost_awake, .removed = bboost_removed, .on_player = bboost_on_player,+ .kind = KIND_PCOLLIDE};+static void new_bboost(const EData *d) {+ Ent *e = ent_new(&BBOOST, d->x, d->y);+ if (!e) return;+ e->depth = -1000000;+ ent_circle(e, 16, 0, 0);+ BBoost *b = ST(e, BBoost);+ if (!bb_tex[0]) tex_family("objects/badelineboost/idle", bb_tex, 26);+ fs_play(&b->spr, BB_IDLE, true);+ wiggler_init(&b->wig, 0.4f, 3);+ b->wave.freq = 0.25f;+ /* NodesWithPosition */+ b->nodes[0][0] = (int16_t)d->x, b->nodes[0][1] = (int16_t)d->y;+ int n = 1;+ for (int i = 0; i < d->nnodes && n < BB_NODES; i++, n++) {+ V2 v = ed_node(d, i);+ b->nodes[n][0] = (int16_t)v.x, b->nodes[n][1] = (int16_t)v.y;+ }+ b->nnodes = (uint8_t)n;+ b->can_skip = EAB(d, badelineBoost, canSkip);+ if (EAB(d, badelineBoost, lockCamera)) level_camera_locker(e, 1, 0, 160), b->lock = 1; /* CameraLocker(BoostSequence) */+}++/* ---------------------------------------------------------------- ReflectionHeartStatue */+static const char *HEART_CODE[6] = {"U", "L", "DR", "UR", "L", "UL"};+typedef struct { float alarm, t; uint8_t index, lit, pad[2]; } HTorch;+typedef struct {+ float wait, p;+ V2 gem_at;+ uint8_t inputs[6], ninputs, enabled, co, orbs, torch[4], dummy, pad[3];+} HStatue;+static uint16_t ht_tex[7], ht_hint[4];+static void htorch_lit(Ent *e) { /* PlayLit: from a random frame */+ HTorch *t = ST(e, HTorch);+ t->lit = 1;+ t->t = rndi(6) * 0.08f;+}+static void htorch_update(Ent *e) {+ HTorch *t = ST(e, HTorch);+ if (t->alarm > 0 && (t->alarm -= DT) <= 0) htorch_lit(e);+ if (t->lit) t->t += DT;+}+static void htorch_render(Ent *e) {+ HTorch *t = ST(e, HTorch);+ draw_centered(ht_hint[t->index & 3], e->x, e->y + 28, 0xFFFF, 255, 1, 1, 0);+ int f = t->lit ? 1 + (int)floorf(t->t / 0.08f) % 6 : 0;+ if (ht_tex[f] != 0xFFFF) gfx_tex_ex(ht_tex[f], e->x, e->y, 32, 64, 1, 1, 0, 0xFFFF, 255, 0);+ if (t->lit) {+ light_add(e->x, e->y, 0x20B2AA, 1, 24, 48); /* Color.LightSeaGreen */+ bloom_add(e->x, e->y, 0.6f, 16);+ }+}+static const EntClass HTORCH = {.name = "reflectionHeartTorch", .size = sizeof(HTorch), .update = htorch_update, .render = htorch_render};+static uint8_t dash_code(V2 dir) { /* "U"/"D" then "L"/"R", as bits */+ return (uint8_t)((dir.y < 0 ? 1 : dir.y > 0 ? 2 : 0) | (dir.x < 0 ? 4 : dir.x > 0 ? 8 : 0));+}+/* a torch's code: torch 1 flipped left-right, 2 up-down, 3 both (FlipCode) */+static uint8_t heart_code(int torch, int i) {+ uint8_t v = 0;+ for (const char *s = HEART_CODE[i]; *s; s++) {+ char c = *s;+ if ((torch & 1) && (c == 'L' || c == 'R')) c = c == 'L' ? 'R' : 'L';+ if ((torch & 2) && (c == 'U' || c == 'D')) c = c == 'U' ? 'D' : 'U';+ v |= c == 'U' ? 1 : c == 'D' ? 2 : c == 'L' ? 4 : 8;+ }+ return v;+}+static void heart_flag(char *out, int i) {+ memcpy(out, "heartTorch_", 11);+ out[11] = (char)('0' + i), out[12] = 0;+}+static void hstatue_spawn_heart(Ent *e) {+ /* new HeartGem(Position - (0, 52)): the heart gem is another file's (blackGem), made from a record */+ uint8_t attrs[EA_blackGem__size + 4];+ memset(attrs, 0, sizeof attrs);+ EData d;+ memset(&d, 0, sizeof d);+ d.type = ET_blackGem;+ d.x = e->x, d.y = e->y - 52;+ d.room = g_level.room ? g_level.room->index : 0;+ d.rx = (float)(g_level.room ? g_level.room->x : 0), d.ry = (float)(g_level.room ? g_level.room->y : 0);+ d.id = -1;+ d.attrs = d.nodes = attrs;+ ent_create(&d);+}+static void hstatue_check_all(Ent *e, bool skip) { /* CheckIfAllActivated */+ HStatue *s = ST(e, HStatue);+ if (!s->enabled) return;+ char flag[16];+ for (int i = 0; i < 4; i++) {+ heart_flag(flag, i);+ if (!level_get_flag(flag)) return;+ }+ s->enabled = 0; /* Activate */+ if (skip) hstatue_spawn_heart(e);+ else s->co = 1, s->wait = 0.533f;+}+static void hstatue_on_dash(Ent *e, V2 dir) {+ HStatue *s = ST(e, HStatue);+ if (!s->enabled) return;+ if (s->ninputs == 6) memmove(s->inputs, s->inputs + 1, 5), s->ninputs--;+ s->inputs[s->ninputs++] = dash_code(dir);+ char flag[16];+ for (int t = 0; t < 4; t++) {+ heart_flag(flag, t);+ if (level_get_flag(flag) || s->ninputs < 6) continue;+ bool ok = true;+ for (int i = 0; i < 6 && ok; i++) ok = s->inputs[i] == heart_code(t, i);+ if (!ok) continue;+ level_set_flag(flag, true); /* Torch.Activate: lit 0.2 s later */+ Ent *te = ent_at(s->torch[t]);+ if (te->cls == &HTORCH) ST(te, HTorch)->alarm = 0.2f;+ }+ hstatue_check_all(e, false);+}+typedef struct { float scale; } WhiteHeart;+static void wh_render(Ent *e) {+ float s = ST(e, WhiteHeart)->scale;+ if (s > 0) draw_centered(T_collectables_heartGem_white00, e->x, e->y, 0xFFFF, 255, s, s, 0);+ bloom_add(e->x, e->y, s, 16);+}+static const EntClass WHITEHEART = {.name = "reflectionHeartDummy", .size = sizeof(WhiteHeart), .render = wh_render};+static void hstatue_update(Ent *e) { /* ActivateRoutine */+ HStatue *s = ST(e, HStatue);+ if (!s->co) return;+ if (s->wait > 0) {+ s->wait -= DT;+ return;+ }+ Ent *dummy = ent_at(s->dummy);+ if (dummy->cls != &WHITEHEART) dummy = NULL;+ switch (s->co) {+ case 1: { /* the white heart, then 20 orbs, one a frame */+ Ent *d = ent_new(&WHITEHEART, e->x, e->y - 52);+ s = ST(e, HStatue);+ if (d) {+ d->depth = 1;+ d->collidable = 0;+ ST(d, WhiteHeart)->scale = 0;+ s->dummy = ent_ref(d);+ dummy = d;+ }+ s->orbs = 0;+ s->co = 2;+ }+ /* fall through */+ case 2:+ if (s->orbs < 20) {+ absorb_orb_new(v2(e->x, e->y - 20), dummy);+ s = ST(e, HStatue);+ s->orbs++;+ break;+ }+ s->wait = 0.8f;+ s->co = 3;+ s->p = 0;+ break;+ case 3:+ if (s->p < 1) {+ if (dummy) ST(dummy, WhiteHeart)->scale = s->p;+ level_shake(0.3f);+ s->p += DT / 0.6f;+ break;+ }+ absorb_orbs_remove();+ if (dummy) ent_remove(dummy);+ level_flash(0xFFFF, false);+ hstatue_spawn_heart(e);+ s->co = 0;+ break;+ }+}+static void hstatue_render(Ent *e) {+ HStatue *s = ST(e, HStatue);+ Tex t;+ if (tex_get(T_objects_reflectionHeart_statue, &t)) /* JustifyOrigin(0.5, 1), Origin.Y - 1 */+ gfx_tex_ex(T_objects_reflectionHeart_statue, e->x, e->y, t.fw * t.scale / 2.f, t.fh * t.scale - 1.f, 1, 1, 0, 0xFFFF, 255, 0);+ /* ForsakenCitySatellite.Colors of the code */+ static const uint32_t COLORS[6] = {0xF0F0F0, 0x9171F2, 0x0A44E0, 0xB32D00, 0x9171F2, 0xFFCD37};+ for (int j = 0; j < 6; j++) {+ V2 at = v2add(s->gem_at, v2((j - 2.5f) * 24, 0));+ draw_centered(T_objects_reflectionHeart_gem, at.x, at.y, rgb(COLORS[j]), 255, 1, 1, 0);+ bloom_add(at.x, at.y, 0.3f, 12);+ }+}+static void hstatue_awake(Ent *e) { hstatue_check_all(e, true); }+static const EntClass HSTATUE = {.name = "reflectionHeartStatue", .size = sizeof(HStatue), .update = hstatue_update,+ .render = hstatue_render, .awake = hstatue_awake, .on_dash = hstatue_on_dash};+static void new_hstatue(const EData *d) {+ if (d->nnodes < 5) return;+ Ent *e = ent_new(&HSTATUE, d->x, d->y);+ if (!e) return;+ e->depth = 8999;+ e->collidable = 0;+ if (!ht_tex[0]) tex_family("objects/reflectionHeart/torch", ht_tex, 7), tex_family("objects/reflectionHeart/hint", ht_hint, 4);+ HStatue *s = ST(e, HStatue);+ s->gem_at = ed_node(d, 4);+ s->enabled = !g_session.heart;+ char flag[16];+ for (int i = 0; i < 4; i++) {+ V2 at = ed_node(d, i);+ Ent *t = ent_new(&HTORCH, at.x, at.y);+ s = ST(e, HStatue);+ if (!t) continue;+ t->depth = 8999;+ t->collidable = 0;+ ST(t, HTorch)->index = (uint8_t)i;+ heart_flag(flag, i);+ if (level_get_flag(flag)) htorch_lit(t); /* Torch.Added */+ s->torch[i] = ent_ref(t);+ }+}+/* ---------------------------------------------------------------- the boss's blocks: tiles 'g', highlighted 'G' */+/* their tiles live in a small pool, in runs of 8, owned by the block */+#define BT_CHUNK 8+#define BT_CHUNKS 48+static TileQ bt_pool[BT_CHUNKS * BT_CHUNK];+static uint8_t bt_owner[BT_CHUNKS]; /* 0: free, else the block's entity + 1 */+static int bt_alloc(Ent *e, int n) {+ int k = (n + BT_CHUNK - 1) / BT_CHUNK, run = 0;+ for (int i = 0; i < BT_CHUNKS; i++) {+ run = bt_owner[i] ? 0 : run + 1;+ if (run == k) {+ for (int j = i - k + 1; j <= i; j++) bt_owner[j] = (uint8_t)(ent_ref(e) + 1);+ return (i - k + 1) * BT_CHUNK;+ }+ }+ return -1;+}+static void bt_free(Ent *e) {+ for (int i = 0; i < BT_CHUNKS; i++)+ if (bt_owner[i] == ent_ref(e) + 1) bt_owner[i] = 0;+}+/* the tiles at alpha a, and the same box in 'G' (the same random picks) at alpha hl */+static void bt_draw(int t0, int w, int h, float x, float y, float a, float hl) {+ if (t0 < 0) return;+ const TileQ *q = bt_pool + t0;+ if (a > 0) tiles_draw(q, w, h, x, y, 0xFFFF, a8(a));+ if (hl > 0) {+ TileQ tmp[BT_CHUNKS * BT_CHUNK / 2];+ int n = w * h, g = terrain_of(0, 'G');+ if (n > (int)(sizeof tmp / sizeof tmp[0]) || g < 0) return;+ for (int i = 0; i < n; i++) tmp[i].quad = q[i].quad, tmp[i].terrain = q[i].terrain == 255 ? 255 : (uint8_t)g;+ tiles_draw(tmp, w, h, x, y, 0xFFFF, a8(hl));+ }+}++/* FallingBlock(finalBoss: true), the map's finalBossFallingBlock */+typedef struct {+ float wait, timer, delay, speed, hl, hl_from, hl_to, hl_p;+ int16_t t0;+ uint8_t w, h, step, triggered, hl_run, pad;+} BFall;+static void bfall_highlight(BFall *b, float to) { /* HighlightFade(to): its coroutine starts next frame */+ b->hl_from = b->hl, b->hl_to = to, b->hl_p = 0, b->hl_run = 2;+}+static void bfall_drop(Ent *e) { /* StopShaking, the dust, and the fall begins */+ BFall *b = ST(e, BFall);+ plat_stop_shaking(e);+ for (int i = 2; i < e->cw; i += 4) {+ if (rect_solid(e->x + i, e->y - 2, e->x + i + 1, e->y - 1))+ particles_emit(PL_MID, &P_FallingBlock_P_FallDustA, 2, v2(e->x + i, e->y), v2(4, 4), PI_F / 2);+ particles_emit(PL_MID, &P_FallingBlock_P_FallDustB, 2, v2(e->x + i, e->y), v2(4, 4), P_FallingBlock_P_FallDustB.direction);+ }+ b->speed = 0;+ b->step = 4;+}+static void bfall_update(Ent *e) {+ BFall *b = ST(e, BFall);+ plat_update(e);+ if (b->hl_run == 2) b->hl_run = 1, b->hl_p = 0, b->hl = b->hl_from; /* its first step: p = 0 */+ else if (b->hl_run == 1) {+ b->hl_p += DT / 0.5f;+ if (b->hl_p < 1) b->hl = lerpf(b->hl_from, b->hl_to, ease_cube_inout(b->hl_p));+ else b->hl = b->hl_to, b->hl_run = 0;+ }+ if (b->wait > 0) {+ b->wait -= DT;+ return;+ }+ Room *rm = g_level.room;+ switch (b->step) {+ case 0: /* the boss triggers it (the player cannot) */+ if (!b->triggered) break;+ b->step = 1;+ /* fall through */+ case 1: /* while (FallDelay > 0) { FallDelay -= DT; yield null; } */+ if (b->delay > 0) {+ b->delay -= DT;+ break;+ }+ b->step = 2;+ /* fall through */+ case 2: /* shake, highlight, 0.2 s */+ plat_start_shaking(e, 0);+ bfall_highlight(b, 1);+ b->wait = 0.2f;+ b->timer = 0.2f;+ b->step = 3;+ break;+ case 3: /* while (timer > 0 && PlayerWaitCheck()) { yield null; timer -= DT; }: Triggered keeps it waiting */+ if (b->timer > 0) {+ b->step = 10;+ break;+ }+ bfall_drop(e);+ break;+ case 10:+ b->timer -= DT;+ if (b->timer > 0) break;+ bfall_drop(e);+ break;+ case 4:+ b->speed = approach(b->speed, 130, 500 * DT);+ if (plat_move_v_collide_solids(e, b->speed * DT, true)) { /* landed */+ level_dir_shake(v2(0, 1), 0.2f);+ bfall_highlight(b, 0);+ plat_start_shaking(e, 0);+ for (int i = 2; i <= e->cw; i += 4) /* LandParticles */+ if (rect_solid(e->x + i, e_bottom(e) + 3, e->x + i + 1, e_bottom(e) + 4)) {+ particles_emit(PL_FG, &P_FallingBlock_P_FallDustA, 1, v2(e->x + i, e_bottom(e)), v2(4, 4), -PI_F / 2);+ particles_emit(PL_FG, &P_FallingBlock_P_LandDust, 1, v2(e->x + i, e_bottom(e)), v2(4, 4), i < e->cw / 2 ? PI_F : 0);+ }+ b->wait = 0.2f;+ b->step = 6;+ break;+ }+ if (e_top(e) > rm->y + rm->h + 16 || (e_top(e) > rm->y + rm->h - 1 && collide_solid(e, e->x, e->y + 1))) {+ e->collidable = e->visible = 0;+ b->wait = 0.2f; /* (and 0.2 s more and a shake when it falls into another room) */+ b->step = 5;+ }+ break;+ case 5:+ ent_remove(e);+ plat_static_movers_destroy(e);+ b->step = 9;+ break;+ case 6:+ plat_stop_shaking(e);+ if (tiles_solid_rect(e_left(e), e_bottom(e), e_right(e), e_bottom(e) + 1)) {+ e->safe = 1;+ b->step = 9;+ break;+ }+ b->step = 7;+ /* fall through */+ case 7: /* while (CollideCheck<Platform>(Position + (0, 1))) yield 0.1 */+ if (collide_solid(e, e->x, e->y + 1) || collide_jumpthru(e, e->x, e->y + 1)) {+ b->wait = 0.1f;+ break;+ }+ b->step = 2;+ break;+ default: break;+ }+}+static void bfall_render(Ent *e) {+ BFall *b = ST(e, BFall);+ bt_draw(b->t0, b->w, b->h, e->x + e->shakex, e->y + e->shakey, 1 - b->hl, b->hl);+}+static void bfall_shake(Ent *e, V2 a) { plat_static_movers_shake(e, a); }+static const EntClass BFALL = {.name = "finalBossFallingBlock", .size = sizeof(BFall), .update = bfall_update, .render = bfall_render,+ .removed = bt_free, .on_shake = bfall_shake, .kind = KIND_SOLID};+static void new_bfall(const EData *d) {+ float w = EA(d, finalBossFallingBlock, width), h = EA(d, finalBossFallingBlock, height);+ Ent *e = ent_new(&BFALL, d->x, d->y);+ if (!e) return;+ ent_box(e, w, h, 0, 0);+ BFall *b = ST(e, BFall);+ b->w = (uint8_t)(w / 8), b->h = (uint8_t)(h / 8);+ b->t0 = (int16_t)bt_alloc(e, b->w * b->h);+ if (b->t0 >= 0) tiles_box('g', b->w, b->h, bt_pool + b->t0);+}++/* FinalBossMovingBlock */+#define BM_NODES 4+typedef struct {+ float wait, delay, hl, p, alarm;+ Tween tw;+ V2 from, to;+ int16_t nodes[BM_NODES][2];+ int16_t t0;+ uint8_t w, h, node, nnodes, boss_node, step, highlighted, tw_on;+} BMove;+static const EntClass BMOVE;+static void bmove_particles(Ent *e, V2 moved, bool impact) { /* ImpactParticles / StopParticles */+ float dir = vangle(moved);+ if (impact) {+ if (moved.x != 0) {+ float x = moved.x < 0 ? e_left(e) - 1 : e_right(e) + 1;+ for (int i = 0; i < e->ch / 8; i++) {+ V2 p = v2(x, e_top(e) + 4 + i * 8);+ if (!point_water(p) && point_solid(p.x, p.y)) {+ particles_emit1(PL_FG, &P_CrushBlock_P_Impact, v2add(p, v2(0, 2)), moved.x < 0 ? 0 : PI_F);+ particles_emit1(PL_FG, &P_CrushBlock_P_Impact, v2sub(p, v2(0, 2)), moved.x < 0 ? 0 : PI_F);+ }+ }+ }+ if (moved.y != 0) {+ float y = moved.y < 0 ? e_top(e) - 1 : e_bottom(e) + 1;+ for (int i = 0; i < e->cw / 8; i++) {+ V2 p = v2(e_left(e) + 4 + i * 8, y);+ if (!point_water(p) && point_solid(p.x, p.y)) {+ particles_emit1(PL_FG, &P_CrushBlock_P_Impact, v2add(p, v2(2, 0)), moved.y < 0 ? PI_F / 2 : -PI_F / 2);+ particles_emit1(PL_FG, &P_CrushBlock_P_Impact, v2sub(p, v2(2, 0)), moved.y < 0 ? PI_F / 2 : -PI_F / 2);+ }+ }+ }+ return;+ }+ if (moved.x != 0) {+ float x = moved.x > 0 ? e_right(e) - 1 : e_left(e);+ for (int i = 0; i < e->ch; i += 4) particles_emit1(PL_MID, &P_FinalBossMovingBlock_P_Stop, v2(x, e_top(e) + 2 + i + rndi(3) - 1), dir);+ }+ if (moved.y != 0) {+ float y = moved.y > 0 ? e_bottom(e) - 1 : e_top(e);+ for (int i = 0; i < e->cw; i += 4) particles_emit1(PL_MID, &P_FinalBossMovingBlock_P_Stop, v2(e_left(e) + 2 + i + rndi(3) - 1, y), dir);+ }+}+static void bmove_finish(Ent *e) {+ V2 from = v2(e_right(e) + 10, e_cym(e)); /* CenterRight + (10, 0) */+ for (int i = 0; i < e->cw / 8; i++)+ for (int j = 0; j < e->ch / 8; j++) level_debris(e->x + 4 + i * 8, e->y + 4 + j * 8, 'f', from);+ V2 c = e_center(e);+ for (int i = 0; i < e->cw; i += 4) /* BreakParticles */+ for (int j = 0; j < e->ch; j += 4) {+ V2 p = v2(e->x + 2 + i, e->y + 2 + j);+ particles_emit(PL_MID, &P_FinalBossMovingBlock_P_Break, 1, p, v2(2, 2), vangle(v2sub(p, c)));+ }+ plat_static_movers_destroy(e);+ ent_remove(e);+}+static void bmove_start(Ent *e, float delay) { /* StartMoving: the coroutine starts next frame */+ BMove *b = ST(e, BMove);+ b->delay = delay;+ b->step = 1;+ b->wait = 0;+}+static void bmove_destroy(Ent *e, float delay) {+ BMove *b = ST(e, BMove);+ if (e->dead == 1) return;+ b->step = 0;+ if (delay <= 0) {+ bmove_finish(e);+ return;+ }+ plat_start_shaking(e, delay);+ b->alarm = delay;+}+static void bmove_update(Ent *e) {+ BMove *b = ST(e, BMove);+ plat_update(e);+ if (b->alarm > 0 && (b->alarm -= DT) <= 0) {+ bmove_finish(e);+ return;+ }+ if (b->tw_on == 2) b->tw_on = 1; /* added by last frame's coroutine: it runs from now on */+ if (b->tw_on == 1) {+ bool done = tween_update(&b->tw);+ V2 at = v2lerp(b->from, b->to, ease_cube_in(b->tw.percent));+ plat_move_to(e, at.x, at.y);+ if (done) {+ b->tw_on = 0;+ V2 d = safe_norm(v2sub(b->to, b->from), 2);+ if (tiles_solid_rect(e_left(e) + d.x, e_top(e) + d.y, e_right(e) + d.x, e_bottom(e) + d.y)) bmove_particles(e, v2sub(b->to, b->from), true);+ else bmove_particles(e, v2sub(b->to, b->from), false);+ }+ }+ if (!b->step) return;+ if (b->wait > 0) {+ b->wait -= DT;+ return;+ }+ switch (b->step) {+ case 1:+ plat_start_shaking(e, 0.2f + b->delay);+ if (b->highlighted) {+ b->wait = 0.2f + b->delay + 0.2f;+ b->step = 3;+ break;+ }+ b->p = 0; /* for (p = 0; p < 1; p += DT / (0.2 + delay + 0.2)) { highlight = CubeIn(p); yield null; } */+ b->hl = 0;+ b->step = 2;+ break;+ case 2:+ b->p += DT / (0.2f + b->delay + 0.2f);+ if (b->p < 1) {+ b->hl = ease_cube_in(b->p);+ break;+ }+ b->hl = 1;+ b->highlighted = 1;+ /* fall through */+ case 3:+ b->delay = 0;+ b->node = (uint8_t)((b->node + 1) % b->nnodes);+ b->from = v2(e->x, e->y);+ b->to = v2(b->nodes[b->node][0], b->nodes[b->node][1]);+ tween_start(&b->tw, 0.8f);+ b->tw_on = 2;+ b->wait = 0.8f;+ b->step = 1;+ break;+ }+}+static void bmove_render(Ent *e) {+ BMove *b = ST(e, BMove);+ float x = e->x + e->shakex, y = e->y + e->shakey;+ bt_draw(b->t0, b->w, b->h, x, y, 1 - b->hl, b->hl);+ if (b->hl > 0 && b->hl < 1) { /* a hollow rect closing in, Color.Lerp(Purple, Pink, 0.7) */+ int n = (int)((1 - b->hl) * 16);+ gfx_hollow_rect(x - n, y - n, e->cw + 2 * n, e->ch + 2 * n, rgb(0xD886B4), 255);+ }+}+static void bmove_shake(Ent *e, V2 a) { plat_static_movers_shake(e, a); }+static const EntClass BMOVE = {.name = "finalBossMovingBlock", .size = sizeof(BMove), .update = bmove_update, .render = bmove_render,+ .removed = bt_free, .on_shake = bmove_shake, .kind = KIND_SOLID};+static void new_bmove(const EData *d) {+ float w = EA(d, finalBossMovingBlock, width), h = EA(d, finalBossMovingBlock, height);+ Ent *e = ent_new(&BMOVE, d->x, d->y);+ if (!e) return;+ ent_box(e, w, h, 0, 0);+ BMove *b = ST(e, BMove);+ b->w = (uint8_t)(w / 8), b->h = (uint8_t)(h / 8);+ b->boss_node = (uint8_t)EA(d, finalBossMovingBlock, nodeIndex);+ b->nodes[0][0] = (int16_t)d->x, b->nodes[0][1] = (int16_t)d->y;+ int n = 1;+ for (int i = 0; i < d->nnodes && n < BM_NODES; i++, n++) {+ V2 v = ed_node(d, i);+ b->nodes[n][0] = (int16_t)v.x, b->nodes[n][1] = (int16_t)v.y;+ }+ b->nnodes = (uint8_t)n;+ b->t0 = (int16_t)bt_alloc(e, b->w * b->h);+ if (b->t0 >= 0) tiles_box('g', b->w, b->h, bt_pool + b->t0);+}++/* ---------------------------------------------------------------- FinalBossShot */+typedef struct {+ CSpr spr;+ SineWave sine;+ V2 anchor, speed, perp;+ float cant_kill, appear, sine_mult, pdir;+ uint8_t boss, dead, in_cam, pad;+} Shot;+static const EntClass BOSS, SHOT, BEAM;+static void shot_on_player(Ent *e, Player *p) {+ Shot *s = ST(e, Shot);+ if (s->dead) return;+ if (s->cant_kill > 0) {+ s->dead = 1;+ ent_remove(e);+ } else+ player_die(p, safe_norm(v2sub(player_center(p), v2(e->x, e->y)), 1), false);+}+static V2 boss_center(const Ent *e) { return v2(e->x, e->y - 6); } /* Circle(14, 0, -6) */+static V2 boss_shot_origin(Ent *e);+static void shot_update(Ent *e) {+ Shot *s = ST(e, Shot);+ cs_update(&s->spr);+ sine_update(&s->sine);+ if (s->appear > 0) {+ Ent *b = ent_at(s->boss);+ if (b->cls == &BOSS) s->anchor = boss_shot_origin(b), e->x = s->anchor.x, e->y = s->anchor.y;+ s->appear -= DT;+ return;+ }+ if (s->cant_kill > 0) s->cant_kill -= DT;+ s->anchor = v2add(s->anchor, v2mul(s->speed, DT));+ V2 at = v2add(s->anchor, v2mul(s->perp, s->sine_mult * s->sine.value * 3));+ e->x = at.x, e->y = at.y;+ s->sine_mult = approach(s->sine_mult, 1, 2 * DT);+ if (s->dead) return;+ bool in = e->x > g_level.cam.x - 8 && e->x < g_level.cam.x + 328 && e->y > g_level.cam.y - 8 && e->y < g_level.cam.y + 188;+ if (in && !s->in_cam) s->in_cam = 1;+ else if (!in && s->in_cam) {+ s->dead = 1;+ ent_remove(e);+ return;+ }+ if (level_on_interval(0.04f)) particles_emit(PL_FG, &P_FinalBossShot_P_Trail, 1, v2(e->x, e->y), v2(2, 2), s->pdir);+}+static void shot_render(Ent *e) {+ Shot *s = ST(e, Shot);+ static const int8_t OUT[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};+ for (int i = 0; i < 4; i++) cs_draw(&s->spr, e->x + OUT[i][0], e->y + OUT[i][1], 1, 1, 0, 0, 255); /* Color.Black */+ cs_draw(&s->spr, e->x, e->y, 1, 1, 0, 0xFFFF, 255);+}+static const EntClass SHOT = {.name = "finalBossShot", .size = sizeof(Shot), .update = shot_update, .render = shot_render,+ .on_player = shot_on_player, .kind = KIND_PCOLLIDE};++/* ---------------------------------------------------------------- FinalBossBeam */+typedef struct {+ CSpr beam, start;+ float charge, follow, active, angle, beam_alpha, side_alpha;+ uint8_t boss, start_on, pad[2];+} Beam;+static V2 boss_beam_origin(Ent *e);+static bool segment_rect(V2 a, V2 b, float l, float t, float r, float bt) { /* Collide.RectToLine */+ float t0 = 0, t1 = 1, dx = b.x - a.x, dy = b.y - a.y;+ float p[4] = {-dx, dx, -dy, dy}, q[4] = {a.x - l, r - a.x, a.y - t, bt - a.y};+ for (int i = 0; i < 4; i++) {+ if (p[i] == 0) {+ if (q[i] < 0) return false;+ continue;+ }+ float k = q[i] / p[i];+ if (p[i] < 0) t0 = fmaxf(t0, k);+ else t1 = fminf(t1, k);+ if (t0 > t1) return false;+ }+ return true;+}+static void beam_update(Ent *e) {+ Beam *b = ST(e, Beam);+ Ent *be = ent_at(b->boss);+ if (be->cls != &BOSS) {+ ent_remove(e);+ return;+ }+ int ended = cs_update(&b->beam);+ if (b->start_on) cs_update(&b->start);+ if (ended == A_badeline_beam_shoot) { /* OnLastFrame("shoot") */+ ent_remove(e);+ return;+ }+ Player *p = level_player();+ V2 origin = boss_beam_origin(be);+ b->beam_alpha = approach(b->beam_alpha, 1, 2 * DT);+ if (b->charge > 0) {+ b->side_alpha = approach(b->side_alpha, 1, DT);+ if (p && !p->dead) {+ b->follow -= DT;+ b->charge -= DT;+ V2 pc = player_center(p);+ if (b->follow > 0 && !v2eq(pc, origin)) {+ V2 val = closest_on_line(origin, v2add(origin, angle_vec(b->angle, 2000)), pc);+ val = approach_v(val, pc, 200 * DT);+ b->angle = vangle(v2sub(val, origin));+ } else if (b->beam.anim == A_badeline_beam_charge)+ cs_play(&b->beam, A_badeline_beam_lock, false);+ if (b->charge <= 0) {+ level_dir_shake(angle_vec(b->angle, 1), 0.15f);+ /* DissipateParticles: along the beam, from the screen's center */+ V2 cam = v2add(g_level.cam, v2(160, 90));+ V2 v2a = v2add(origin, angle_vec(b->angle, 12)), v3 = v2add(origin, angle_vec(b->angle, 2000));+ V2 dir = safe_norm(v2sub(v3, v2a), 1), perp = v2(-dir.y, dir.x);+ float d1 = vangle(perp), d2 = vangle(v2mul(perp, -1));+ float num = v2len(v2sub(cam, v2a)) - 12;+ V2 at = closest_on_line(v2a, v3, cam);+ for (int i = 0; i < 200; i += 12)+ for (int j = -1; j <= 1; j += 2) {+ V2 r = v2mul(perp, rnd_rangef(-1, 1));+ particles_emit1(PL_FG, &P_FinalBossBeam_P_Dissipate, v2add(v2add(v2add(at, v2mul(dir, (float)i)), v2mul(perp, 2.f * j)), r), d1);+ particles_emit1(PL_FG, &P_FinalBossBeam_P_Dissipate, v2add(v2sub(v2add(at, v2mul(dir, (float)i)), v2mul(perp, 2.f * j)), r), d2);+ if (i != 0 && i < num) {+ particles_emit1(PL_FG, &P_FinalBossBeam_P_Dissipate, v2add(v2add(v2sub(at, v2mul(dir, (float)i)), v2mul(perp, 2.f * j)), r), d1);+ particles_emit1(PL_FG, &P_FinalBossBeam_P_Dissipate, v2add(v2sub(v2sub(at, v2mul(dir, (float)i)), v2mul(perp, 2.f * j)), r), d2);+ }+ }+ }+ }+ } else if (b->active > 0) {+ b->side_alpha = approach(b->side_alpha, 0, DT * 8);+ if (b->beam.anim != A_badeline_beam_shoot) {+ cs_play(&b->beam, A_badeline_beam_shoot, false);+ cs_play(&b->start, A_badeline_beam_start_shoot, true);+ b->start_on = 1;+ }+ b->active -= DT;+ if (b->active > 0 && p && !p->dead && p->ent->cls) { /* PlayerCollideCheck: three lines against the player's hitbox */+ V2 a = v2add(origin, angle_vec(b->angle, 12)), c = v2add(origin, angle_vec(b->angle, 2000));+ V2 n = safe_norm(v2sub(c, a), 2), side = v2(-n.y, n.x);+ Ent *pe = p->ent;+ float l = e_left(pe), t = e_top(pe), r = e_right(pe), bt = e_bottom(pe);+ if (segment_rect(v2add(a, side), v2add(c, side), l, t, r, bt) || segment_rect(v2sub(a, side), v2sub(c, side), l, t, r, bt) ||+ segment_rect(a, c, l, t, r, bt))+ player_die(p, safe_norm(v2sub(player_center(p), origin), 1), false);+ }+ }+}+/* the darkness on both sides of the beam: clear on it, dark 120 px out, then dark to 240 px */+typedef struct { V2 at, perp; int a; } BeamDark;+static BeamDark beam_dark;+static void beam_dark_strip(uint16_t *strip, int y0, int y1, void *ctx) {+ const BeamDark *d = ctx;+ for (int vy = y0; vy < y1; vy++) {+ uint16_t *row = strip + (vy - y0) * VIEW_W;+ float py = vy + g_camy + 0.5f - d->at.y;+ float base = py * d->perp.y;+ for (int vx = 0; vx < VIEW_W; vx++) {+ float dist = fabsf((vx + g_camx + 0.5f - d->at.x) * d->perp.x + base);+ if (dist >= 240) continue;+ int a = dist >= 120 ? d->a : (int)(d->a * dist / 120);+ if (a > 0) row[vx] = blend565(row[vx], 0, a);+ }+ }+}+static void beam_render(Ent *e) {+ Beam *b = ST(e, Beam);+ Ent *be = ent_at(b->boss);+ if (be->cls != &BOSS) return;+ V2 val = boss_beam_origin(be);+ uint16_t t = cs_tex(&b->beam);+ Tex tx;+ float w = (t != 0xFFFF && tex_get(t, &tx)) ? tx.fw * (float)tx.scale : 128;+ V2 step = angle_vec(b->angle, w);+ bool shoot = b->beam.anim == A_badeline_beam_shoot;+ if (shoot) val = v2add(val, angle_vec(b->angle, 8));+ uint8_t alpha = a8(b->beam_alpha);+ for (int i = 0; i < 15; i++) { /* only the copies on screen are drawn */+ V2 end = v2add(val, step);+ float l = fminf(val.x, end.x) - 16, r = fmaxf(val.x, end.x) + 16, tp = fminf(val.y, end.y) - 16, bt = fmaxf(val.y, end.y) + 16;+ if (r > g_camx && l < g_camx + VIEW_W && bt > g_camy && tp < g_camy + VIEW_H) cs_draw(&b->beam, val.x, val.y, 1, 1, b->angle, 0xFFFF, alpha);+ val = end;+ }+ if (shoot && b->start_on) cs_draw(&b->start, boss_beam_origin(be).x, boss_beam_origin(be).y, 1, 1, b->angle, 0xFFFF, alpha);+ int a = (int)(b->side_alpha * 0.35f * 256);+ if (a <= 0) return;+ V2 n = safe_norm(step, 1);+ beam_dark.at = val, beam_dark.perp = v2(-n.y, n.x), beam_dark.a = a;+ gfx_custom(beam_dark_strip, &beam_dark, 0, VIEW_H);+}+static const EntClass BEAM = {.name = "finalBossBeam", .size = sizeof(Beam), .update = beam_update, .render = beam_render};++/* ---------------------------------------------------------------- FinalBoss */+/* the attack sequences as little programs: each op runs, a wait or a yield ends the frame */+enum { OP_END, OP_WAIT, OP_YIELD, OP_SHOOT, OP_CHARGE, OP_AIM, OP_SHOOTAT, OP_WAITAIM, OP_A2BEGIN, OP_BEAM, OP_A2LOCK, OP_A2RECOIL,+ OP_MARK, OP_LOOP, OP_SKIPNOT0, OP_ENDIF0 };+typedef struct { uint8_t op, arg; } Op; /* waits in 1/20 s */+#define BEAM_SEQ {OP_YIELD, 0}, {OP_A2BEGIN, 0}, {OP_WAIT, 2}, {OP_BEAM, 0}, {OP_WAIT, 18}, {OP_A2LOCK, 0}, {OP_WAIT, 10}, {OP_A2RECOIL, 0}, {OP_YIELD, 0}+#define VSHOTS {OP_AIM, 0}, {OP_SHOOTAT, 0}, {OP_WAITAIM, 3}, {OP_SHOOTAT, 0}, {OP_WAITAIM, 3}+#define VGAP {OP_CHARGE, 0}, {OP_WAIT, 10}+static const Op ATK01[] = {{OP_CHARGE, 0}, {OP_MARK, 0}, {OP_WAIT, 10}, {OP_SHOOT, 0}, {OP_WAIT, 20}, {OP_CHARGE, 0}, {OP_WAIT, 3}, {OP_WAIT, 6}, {OP_LOOP, 0}};+static const Op ATK02[] = {{OP_MARK, 0}, {OP_WAIT, 10}, BEAM_SEQ, {OP_WAIT, 8}, {OP_CHARGE, 0}, {OP_WAIT, 6}, {OP_SHOOT, 0}, {OP_WAIT, 10}, {OP_WAIT, 6}, {OP_LOOP, 0}};+static const Op ATK03[] = {{OP_CHARGE, 0}, {OP_WAIT, 2}, {OP_MARK, 0}, VSHOTS, VGAP, VSHOTS, VGAP, VSHOTS, VGAP, VSHOTS, VGAP, VSHOTS,+ {OP_WAIT, 40}, {OP_CHARGE, 0}, {OP_WAIT, 14}, {OP_LOOP, 0}};+static const Op ATK04[] = {{OP_CHARGE, 0}, {OP_WAIT, 2}, {OP_MARK, 0}, VSHOTS, VGAP, VSHOTS, VGAP, VSHOTS, VGAP, VSHOTS, VGAP, VSHOTS,+ {OP_WAIT, 30}, BEAM_SEQ, {OP_WAIT, 30}, {OP_CHARGE, 0}, {OP_LOOP, 0}};+static const Op ATK05[] = {{OP_WAIT, 4}, {OP_MARK, 0}, BEAM_SEQ, {OP_WAIT, 12}, {OP_CHARGE, 0}, {OP_WAIT, 6}, VSHOTS, VGAP, VSHOTS, VGAP, VSHOTS,+ {OP_WAIT, 16}, {OP_LOOP, 0}};+static const Op ATK06[] = {{OP_MARK, 0}, BEAM_SEQ, {OP_WAIT, 14}, {OP_LOOP, 0}};+static const Op ATK07[] = {{OP_MARK, 0}, {OP_SHOOT, 0}, {OP_WAIT, 16}, {OP_CHARGE, 0}, {OP_WAIT, 16}, {OP_LOOP, 0}};+static const Op ATK08[] = {{OP_MARK, 0}, {OP_WAIT, 2}, BEAM_SEQ, {OP_WAIT, 16}, {OP_LOOP, 0}};+static const Op ATK09[] = {{OP_CHARGE, 0}, {OP_MARK, 0}, {OP_WAIT, 10}, {OP_SHOOT, 0}, {OP_WAIT, 3}, {OP_CHARGE, 0}, {OP_SHOOT, 0},+ {OP_WAIT, 8}, {OP_CHARGE, 0}, {OP_WAIT, 2}, {OP_LOOP, 0}};+static const Op ATK10[] = {{OP_END, 0}};+static const Op ATK11[] = {{OP_SKIPNOT0, 2}, {OP_CHARGE, 0}, {OP_WAIT, 12}, {OP_MARK, 0}, {OP_SHOOT, 0}, {OP_WAIT, 38}, {OP_CHARGE, 0},+ {OP_WAIT, 12}, {OP_LOOP, 0}};+static const Op ATK13[] = {{OP_ENDIF0, 0}, {OP_YIELD, 0}, {OP_CHARGE, 0}, {OP_MARK, 0}, {OP_WAIT, 10}, {OP_SHOOT, 0}, {OP_WAIT, 20},+ {OP_CHARGE, 0}, {OP_WAIT, 3}, {OP_WAIT, 6}, {OP_LOOP, 0}};+static const Op ATK14[] = {{OP_MARK, 0}, {OP_WAIT, 4}, BEAM_SEQ, {OP_WAIT, 6}, {OP_LOOP, 0}};+static const Op ATK15[] = {{OP_MARK, 0}, {OP_WAIT, 4}, BEAM_SEQ, {OP_WAIT, 24}, {OP_LOOP, 0}};+static const Op *const ATTACKS[16] = {ATK01, ATK01, ATK02, ATK03, ATK04, ATK05, ATK06, ATK07, ATK08, ATK09, ATK10, ATK11, NULL, ATK13, ATK14, ATK15};++#define BOSS_NODES 12+typedef struct {+ CSpr spr; /* badeline_boss, or (pattern 0, before the first hit) the player-like badeline */+ Wiggler wig;+ SineWave fsine;+ Tween tw;+ V2 spr_pos, avoid, from, to, aim;+ float wait, mv_wait, mv_timer, hit_alarm, spike_alarm;+ int16_t nodes[BOSS_NODES][2];+ uint8_t pattern, node, nnodes, normal, sitting, moving, player_moved, attacking;+ uint8_t ip, mv_step, aimed, last_hit, dialog, start_hit, tw_on, no_player;+ int8_t facing, normal_sx, last_anim;+ uint8_t syncing, autoanim; /* the intro's BadelineAutoAnimator on the normal sprite */+ Hair hair; /* normalHair */+ Wiggler pop;+} Boss;+static void level_break_dash_block_ext(Ent *e, V2 dir);+static void autoanim(Sprite *spr, Wiggler *pop, int8_t *last, uint8_t *syncing, bool enabled);+static V2 boss_spr_scale(const Ent *e) {+ const Boss *b = ST(e, Boss);+ if (b->normal) {+ float k = 1 + 0.25f * b->pop.value;+ return v2(b->normal_sx * k, k);+ }+ float s = 1 + b->wig.value * 0.2f;+ return v2(b->facing * s, s);+}+static V2 boss_shot_origin(Ent *e) { /* Center + Sprite.Position + (6 * Scale.X, 2) */+ Boss *b = ST(e, Boss);+ return v2add(v2add(boss_center(e), b->spr_pos), v2(6 * boss_spr_scale(e).x, 2));+}+static V2 boss_beam_origin(Ent *e) { return v2add(v2add(boss_center(e), ST(e, Boss)->spr_pos), v2(0, -14)); }+static bool player_at_attract(const Player *p) { /* AtAttractTarget */+ return p->state == ST_ATTRACT && p->ent->x == p->attract_to.x && p->ent->y == p->attract_to.y;+}+static void boss_make_sprite(Ent *e) { /* CreateBossSprite */+ Boss *b = ST(e, Boss);+ cs_init(&b->spr, SB_badeline_boss);+ cs_play(&b->spr, A_badeline_boss_idle, true);+ b->facing = -1;+ b->normal = 0;+}+static void boss_start_attacking(Ent *e) {+ Boss *b = ST(e, Boss);+ if (!ATTACKS[b->pattern & 15]) return; /* pattern 12: none */+ b->ip = 0, b->wait = 0, b->attacking = 1;+}+static void boss_play(Ent *e, int anim, bool restart) { cs_play(&ST(e, Boss)->spr, anim, restart); }+static void boss_add_shot(Ent *e, V2 target) { /* FinalBossShot.Init */+ Boss *b = ST(e, Boss);+ if (b->moving) return; /* Added: removed while the boss moves */+ V2 c = boss_center(e);+ Ent *s = ent_new(&SHOT, c.x, c.y);+ if (!s) return;+ ent_box(s, 4, 4, -2, -2);+ s->depth = -1000000;+ Shot *sh = ST(s, Shot);+ cs_init(&sh->spr, SB_badeline_projectile);+ cs_play(&sh->spr, A_badeline_projectile_charge, true);+ sh->boss = ent_ref(e);+ sh->anchor = c;+ sh->cant_kill = 0.15f;+ sh->appear = 0.1f;+ sh->sine.freq = 1.4f;+ sine_set(&sh->sine, 0);+ sh->speed = safe_norm(v2sub(target, c), 100);+ V2 pp = v2(-sh->speed.y, sh->speed.x);+ sh->perp = safe_norm(pp, 1);+ sh->pdir = vangle(v2mul(sh->speed, -1));+}+static void boss_add_beam(Ent *e, Player *p) { /* FinalBossBeam.Init */+ Boss *b = ST(e, Boss);+ if (b->moving) return;+ Ent *be = ent_new(&BEAM, e->x, e->y);+ if (!be) return;+ be->depth = -1000000;+ be->collidable = 0;+ Beam *m = ST(be, Beam);+ cs_init(&m->beam, SB_badeline_beam);+ cs_play(&m->beam, A_badeline_beam_charge, true);+ cs_init(&m->start, SB_badeline_beam_start);+ m->boss = ent_ref(e);+ m->charge = 1.4f, m->follow = 0.9f, m->active = 0.12f;+ V2 origin = boss_beam_origin(e), pc = player_center(p);+ int num = p->ent->y <= e->y + 16 ? 1 : -1;+ if (p->ent->x >= e->x) num = -num;+ float ang = vangle(v2sub(pc, origin));+ V2 val = closest_on_line(origin, v2add(origin, angle_vec(ang, 2000)), pc);+ V2 d = v2sub(pc, origin);+ val = v2add(val, v2mul(safe_norm(v2(-d.y, d.x), 100), (float)num));+ m->angle = vangle(v2sub(val, origin));+}+static void boss_run_attack(Ent *e) {+ Boss *b = ST(e, Boss);+ const Op *prog = ATTACKS[b->pattern & 15];+ if (!b->attacking || !prog) return;+ if (b->wait > 0) {+ b->wait -= DT;+ return;+ }+ Player *p = level_player();+ bool alive = p && !p->dead && p->ent->cls;+ for (int guard = 0; guard < 64; guard++) {+ Op op = prog[b->ip++];+ switch (op.op) {+ case OP_END: b->attacking = 0; return;+ case OP_WAIT: b->wait = op.arg * 0.05f; return;+ case OP_YIELD: return;+ case OP_SHOOT: /* Shoot() */+ boss_play(e, A_badeline_boss_attack1Recoil, true);+ if (alive) boss_add_shot(e, player_center(p));+ break;+ case OP_CHARGE: boss_play(e, A_badeline_boss_attack1Begin, false); break; /* StartShootCharge */+ case OP_AIM:+ b->aimed = alive;+ if (alive) b->aim = player_center(p);+ break;+ case OP_SHOOTAT: /* ShootAt(at) */+ if (b->aimed) boss_play(e, A_badeline_boss_attack1Recoil, true), boss_add_shot(e, b->aim);+ break;+ case OP_WAITAIM:+ if (b->aimed) {+ b->wait = op.arg * 0.05f;+ return;+ }+ break;+ case OP_A2BEGIN: boss_play(e, A_badeline_boss_attack2Begin, true); break;+ case OP_BEAM:+ if (alive) boss_add_beam(e, p);+ break;+ case OP_A2LOCK: boss_play(e, A_badeline_boss_attack2Lock, true); break;+ case OP_A2RECOIL: boss_play(e, A_badeline_boss_attack2Recoil, false); break;+ case OP_MARK: break;+ case OP_LOOP:+ while (b->ip > 0 && prog[b->ip - 1].op != OP_MARK) b->ip--;+ break;+ case OP_SKIPNOT0:+ if (b->node != 0) b->ip += op.arg;+ break;+ case OP_ENDIF0:+ if (b->node == 0) {+ b->attacking = 0;+ return;+ }+ break;+ }+ }+}+static int ents_by_x(const EntClass *cls, uint8_t *out, int max) { /* GetEntitiesCopy, sorted by (int)(a.X - b.X) */+ int n = 0;+ for (int i = 0; i < g_nents && n < max; i++)+ if (g_ents[i].cls == cls && g_ents[i].dead != 1) out[n++] = (uint8_t)i;+ for (int i = 1; i < n; i++) {+ uint8_t k = out[i];+ int j = i;+ while (j > 0 && (int)(g_ents[out[j - 1]].x - g_ents[k].x) > 0) out[j] = out[j - 1], j--;+ out[j] = k;+ }+ return n;+}+static void boss_trigger_falling(float left_of) { /* TriggerFallingBlocks */+ uint8_t ids[32];+ int n = ents_by_x(&BFALL, ids, 32), num = 0;+ for (int i = 0; i < n; i++) {+ Ent *f = &g_ents[ids[i]];+ BFall *b = ST(f, BFall);+ if (b->triggered) continue;+ if (f->x >= left_of) break;+ plat_start_shaking(f, 0);+ b->triggered = 1;+ b->delay = 0.4f * num++;+ }+}+static void boss_trigger_moving(int node) { /* TriggerMovingBlocks */+ uint8_t ids[32];+ int n = ents_by_x(&BMOVE, ids, 32);+ if (node > 0) { /* DestroyMovingBlocks(node - 1) */+ float t = 0;+ for (int i = 0; i < n; i++)+ if (ST(&g_ents[ids[i]], BMove)->boss_node == node - 1) bmove_destroy(&g_ents[ids[i]], t), t += 0.05f;+ }+ float t = 0;+ for (int i = 0; i < n; i++) {+ Ent *m = &g_ents[ids[i]];+ if (m->dead == 1 || !m->cls) continue;+ if (ST(m, BMove)->boss_node == node) bmove_start(m, t), t += 0.15f;+ }+}+static void boss_hit(Ent *e, Player *p) { /* OnPlayer */+ Boss *b = ST(e, Boss);+ if (b->normal) {+ V2 keep = b->spr_pos;+ boss_make_sprite(e);+ b->spr_pos = keep;+ }+ boss_play(e, A_badeline_boss_getHit, false);+ e->collidable = 0;+ b->avoid = v2(0, 0);+ b->node++;+ if (b->dialog && b->node >= 1 && b->node <= 3) {+ static const char *const TIRED[3] = {"ch6_boss_tired_a", "ch6_boss_tired_b", "ch6_boss_tired_c"};+ mini_textbox(TIRED[b->node - 1]);+ }+ for (int i = 0; i < g_nents; i++)+ if ((g_ents[i].cls == &SHOT || g_ents[i].cls == &BEAM) && g_ents[i].dead != 1) {+ if (g_ents[i].cls == &SHOT) ST(&g_ents[i], Shot)->dead = 1;+ ent_remove(&g_ents[i]);+ }+ boss_trigger_falling(e->x);+ boss_trigger_moving(b->node);+ b->attacking = 0; /* attackCoroutine.Active = false */+ b->moving = 1;+ b->last_hit = b->node == b->nnodes - 1;+ const char *room = level_room_name_of(g_level.room->index);+ if (g_session.mode == M_A && b->last_hit && !strcmp(room, "boss-19")) b->spike_alarm = 0.25f;+ /* the music (badeline_fight, badeline_glitch) is not played */+ b->mv_step = 1; /* Add(new Coroutine(MoveSequence(player, lastHit))) */+ b->mv_wait = 0;+ b->no_player = p == NULL;+ b->sitting = 0; /* (the intro cutscene would have stood her up) */+}+static void boss_on_player(Ent *e, Player *p) { boss_hit(e, p); }+static void tentacles_retreat_all(void);+static void boss_move_sequence(Ent *e) {+ Boss *b = ST(e, Boss);+ if (b->tw_on == 2) b->tw_on = 1; /* added by last frame's coroutine: it runs from now on */+ if (b->tw_on == 1) {+ bool done = tween_update(&b->tw);+ float k = ease_sine_inout(b->tw.percent);+ V2 at = v2lerp(b->from, b->to, k);+ e->x = at.x, e->y = at.y;+ if (k >= 0.1f && k <= 0.9f && level_on_interval(0.02f)) {+ uint16_t t = cs_tex(&b->spr);+ float ox, oy;+ cs_origin(&b->spr, t, &ox, &oy);+ V2 sc = boss_spr_scale(e);+ if (t != 0xFFFF) trail_add(e->x + b->spr_pos.x, e->y + b->spr_pos.y, t, ox, oy, sc.x, sc.y, 0xAC3232, 0.5f);+ particles_emit(PL_MID, &P_Player_P_DashB, 2, boss_center(e), v2(3, 3), vangle(v2sub(b->to, b->from)));+ }+ if (done) { /* OnComplete */+ b->tw_on = 0;+ boss_play(e, A_badeline_boss_recoverHit, false);+ b->moving = 0;+ e->collidable = 1;+ Player *p = level_player();+ if (p && p->ent->cls) {+ b->facing = (int8_t)sgn(p->ent->x - e->x);+ if (b->facing == 0) b->facing = -1;+ }+ boss_start_attacking(e);+ sine_set(&b->fsine, 0); /* floatSine.Reset() */+ }+ }+ if (!b->mv_step) return;+ if (b->mv_wait > 0) {+ b->mv_wait -= DT;+ return;+ }+ Player *p = level_player();+ bool alive = p && !p->dead && p->ent->cls && !b->no_player;+ switch (b->mv_step) {+ case 1: /* the glitch tweens are not drawn */+ if (alive) player_start_attract(p, v2add(boss_center(e), v2(0, 4)));+ b->mv_timer = 0.15f;+ b->mv_step = 2;+ /* fall through */+ case 2:+ if (alive && !player_at_attract(p)) {+ b->mv_step = 3;+ return;+ }+ b->mv_step = 4;+ if (b->mv_timer > 0) {+ b->mv_wait = b->mv_timer;+ return;+ }+ break;+ case 3: /* after the yield null */+ b->mv_timer -= DT;+ if (alive && !player_at_attract(p)) return;+ b->mv_step = 4;+ if (b->mv_timer > 0) {+ b->mv_wait = b->mv_timer;+ return;+ }+ break;+ default: break;+ }+ switch (b->mv_step) {+ case 4:+ tentacles_retreat_all();+ if (alive) level_freeze(0.1f); /* Engine.TimeRate 0.5 / 0.75 is not slowed */+ if (alive) { /* PushPlayer: Player.FinalBossPushLaunch */+ int dir = sgn(e->x - b->nodes[b->node][0]);+ if (dir == 0) dir = -1;+ p->has_launch_approach = false;+ p->speed = v2(0.9f * dir * 280, -150);+ p->auto_jump = true;+ player_refill_dash(p);+ player_refill_stamina(p);+ p->dash_cooldown_timer = 0.28f;+ player_set_state(p, ST_LAUNCH);+ }+ level_shake(0.3f);+ b->mv_wait = 0.05f;+ b->mv_step = 5;+ break;+ case 5:+ for (float num = 0; num < PI_F * 2; num += 0.17453292f) {+ V2 at = v2add(v2add(boss_center(e), b->spr_pos), angle_vec(num + rnd_rangef(-PI_F / 90, PI_F / 90), (float)(16 + rndi(4))));+ particles_emit1(PL_MID, &P_FinalBoss_P_Burst, at, num);+ }+ b->mv_wait = 0.05f;+ b->mv_step = 6;+ break;+ case 6: /* the tween back to TimeRate 1 and FinalBossStarfield's alpha are not here */+ b->mv_wait = 0.2f;+ b->mv_step = 7;+ break;+ case 7: {+ b->from = v2(e->x, e->y);+ int k = b->node < b->nnodes ? b->node : b->nnodes - 1;+ b->to = v2(b->nodes[k][0], b->nodes[k][1]);+ tween_start(&b->tw, fmaxf(v2len(v2sub(b->to, b->from)) / 600, DT));+ b->tw_on = 2;+ b->mv_step = 0;+ break;+ }+ }+}+static void boss_update_(Ent *e) {+ Boss *b = ST(e, Boss);+ /* components: the attack, the float sine, the wiggler, the sprite, the move sequence, the alarms */+ boss_run_attack(e);+ sine_update(&b->fsine);+ wiggler_update(&b->wig);+ cs_update(&b->spr);+ if (b->normal && b->autoanim) {+ Sprite s = cs_raw(&b->spr);+ autoanim(&s, &b->pop, &b->last_anim, &b->syncing, true);+ cs_back(&b->spr, &s);+ }+ if (b->pop.active) wiggler_update(&b->pop);+ boss_move_sequence(e);+ b = ST(e, Boss);+ if (b->hit_alarm > 0 && (b->hit_alarm -= DT) <= 0) boss_hit(e, NULL); /* startHit: OnPlayer(null) after 0.5 s */+ if (b->spike_alarm > 0 && (b->spike_alarm -= DT) <= 0) { /* boss-19: every spinner breaks */+ Room *rm = g_level.room;+ spinners_destroy_near(rm->x + rm->w / 2.f, rm->y + rm->h / 2.f, (float)(rm->w > rm->h ? rm->w : rm->h));+ }+ if (b->sitting) return;+ Player *p = level_player();+ bool has_p = p && p->ent->cls && !p->dead;+ if (!b->moving && has_p) {+ if (b->facing == -1 && p->ent->x > e->x + 20) b->facing = 1, wiggler_restart(&b->wig);+ else if (b->facing == 1 && p->ent->x < e->x - 20) b->facing = -1, wiggler_restart(&b->wig);+ }+ if (!b->player_moved && has_p && (p->speed.x != 0 || p->speed.y != 0)) {+ b->player_moved = 1;+ if (b->pattern != 0) boss_start_attacking(e);+ boss_trigger_moving(0);+ }+ if (!b->moving) b->spr_pos = v2add(b->avoid, v2(b->fsine.value * 3, b->fsine.value_over_two * 4));+ else b->spr_pos = approach_v(b->spr_pos, v2(0, 0), 12 * DT);+ /* CollideFirst<DashBlock> with a 6 px circle: broken from below */+ V2 c = boss_center(e);+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (!o->cls || o->dead == 1 || !o->collidable || strcmp(o->cls->name, "dashBlock")) continue;+ float nx = clampf(c.x, e_left(o), e_right(o)), ny = clampf(c.y, e_top(o), e_bottom(o));+ if ((nx - c.x) * (nx - c.x) + (ny - c.y) * (ny - c.y) < 36) {+ level_break_dash_block_ext(o, v2(0, -1));+ break;+ }+ }+ if (!level_in_bounds(v2(e->x, e->y), 24)) {+ e->active = e->visible = e->collidable = 0;+ return;+ }+ V2 target = v2(0, 0);+ if (!b->moving && has_p) {+ V2 d = v2sub(c, player_center(p));+ float l = clamped_map(v2len(d), 32, 88, 12, 0);+ if (l > 0) target = safe_norm(d, l);+ }+ b->avoid = approach_v(b->avoid, target, 40 * DT);+}+static Sprite boss_normal_sprite(const Ent *e) { /* NormalSprite, with its scale, for its hair */+ Sprite s = cs_raw(&ST(e, Boss)->spr);+ V2 k = boss_spr_scale(e);+ s.sx = k.x, s.sy = k.y;+ return s;+}+static void boss_update(Ent *e) {+ boss_update_(e);+ Boss *b = ST(e, Boss);+ if (e->dead == 1 || !b->normal) return;+ Sprite s = boss_normal_sprite(e); /* normalHair.AfterUpdate (it faces left) */+ hair_follow(&b->hair, &s, v2add(v2(e->x, e->y), b->spr_pos), -1);+}+static void boss_render(Ent *e) {+ Boss *b = ST(e, Boss);+ V2 s = boss_spr_scale(e);+ float x = e->x + b->spr_pos.x, y = e->y + b->spr_pos.y;+ if (b->normal) { /* NormalSprite.Position.Floor(), after its hair */+ Sprite ns = boss_normal_sprite(e);+ hair_draw(&b->hair, &ns, -1, rgb(0x9B3FB5), 1);+ x = floorf(x), y = floorf(y);+ }+ cs_draw(&b->spr, x, y, s.x, s.y, 0, 0xFFFF, 255);+ light_add(x, y - 10, 0xFFFFFF, 1, 32, 64);+}+static void boss_mid_new(void);+static const EntClass BOSS = {.name = "finalBoss", .size = sizeof(Boss), .update = boss_update, .render = boss_render,+ .removed = lock_release, .on_player = boss_on_player, .kind = KIND_PCOLLIDE};+static void new_boss(const EData *d) {+ Ent *e = ent_new(&BOSS, d->x, d->y);+ if (!e) return;+ ent_circle(e, 14, 0, -6);+ Boss *b = ST(e, Boss);+ b->pattern = (uint8_t)EA(d, finalBoss, patternIndex);+ b->dialog = EAB(d, finalBoss, dialog);+ b->start_hit = EAB(d, finalBoss, startHit);+ b->nodes[0][0] = (int16_t)d->x, b->nodes[0][1] = (int16_t)d->y;+ int n = 1;+ for (int i = 0; i < d->nnodes && n < BOSS_NODES; i++, n++) {+ V2 v = ed_node(d, i);+ b->nodes[n][0] = (int16_t)v.x, b->nodes[n][1] = (int16_t)v.y;+ }+ b->nnodes = (uint8_t)n;+ b->fsine.freq = 0.6f;+ sine_set(&b->fsine, 0);+ wiggler_init(&b->wig, 0.6f, 3);+ b->wig.active = false;+ b->facing = -1;+ level_camera_locker(e, EAB(d, finalBoss, cameraLockY) ? 2 : 3, 140, EA(d, finalBoss, cameraPastY)); /* CameraLocker */+ /* Added */+ const char *room = level_room_name_of(d->room);+ if (b->pattern == 0) { /* the player-like Badeline, laughing */+ cs_init(&b->spr, SB_badeline);+ cs_play(&b->spr, A_badeline_laugh, true);+ b->normal = 1, b->normal_sx = -1;+ } else+ boss_make_sprite(e);+ wiggler_init(&b->pop, 0.5f, 4);+ for (int i = 0; i < 4; i++) b->hair.n[i] = v2(e->x, e->y);+ if (b->pattern == 0 && !level_get_flag("boss_intro") && !strcmp(room, "boss-00")) {+ b->sitting = 1; /* until CS06_BossIntro (the eventTrigger ch6_boss_intro) stands her up */+ e->y += 16;+ cs_play(&b->spr, A_badeline_pretendDead, true);+ b->normal_sx = 1;+ } else if (b->pattern == 0 && !level_get_flag("boss_mid") && !strcmp(room, "boss-14"))+ boss_mid_new();+ else if (b->start_hit)+ b->hit_alarm = 0.5f;+}++/* ---------------------------------------------------------------- ReflectionTentacles */+/* four layers (the map's one and three behind it), each a row of tentacles drawn as flat quads+ * in the layer's color (the arm textures' light streaks are not drawn) */+#define TENT_MAX 44+#define TENT_NODES 10+typedef struct { int16_t x, y, fx, fy; uint8_t lerp, pad; } Tent; /* 1/2 px from the layer's first node */+typedef struct {+ V2 base, outwards, last_out;+ float ease, offset, fear, sound;+ uint16_t seed;+ uint8_t index, nnodes, slide_until, layer, count, has_player;+ int16_t nodes[TENT_NODES][2];+ Tent t[TENT_MAX];+} Tentacles;+static const EntClass TENTACLES;+static float tent_rand(const Tentacles *t, int i, int k) { return hash01(t->seed, (uint32_t)(i * 8 + k)); }+static float tent_width(const Tentacles *t, int i) { return 4 + tent_rand(t, i, 2) * 16; }+static V2 tent_node(const Tentacles *t, int i) { return v2(t->nodes[i][0], t->nodes[i][1]); }+static V2 tent_pos(const Tentacles *t, int i) { return v2(t->base.x + t->t[i].x * 0.5f, t->base.y + t->t[i].y * 0.5f); }+static void tent_set(Tentacles *t, int i, V2 p) {+ t->t[i].x = (int16_t)clampf(roundf((p.x - t->base.x) * 2), -32767, 32767);+ t->t[i].y = (int16_t)clampf(roundf((p.y - t->base.y) * 2), -32767, 32767);+}+static V2 tent_target(const Tentacles *t, int i, V2 position, float along, const Player *p) { /* TargetTentaclePosition */+ V2 val = v2sub(position, v2mul(t->outwards, t->offset)), val2 = val;+ V2 perp = v2(-t->outwards.y, t->outwards.x);+ if (p) val2 = closest_on_line(v2sub(val2, v2mul(perp, 200)), v2add(val2, v2mul(perp, 200)), v2(p->ent->x, p->ent->y));+ V2 val4 = v2add(val, v2mul(perp, -220 + along + tent_width(t, i) * 0.5f));+ float num = v2len(v2sub(val2, val4));+ return v2add(val4, v2mul(t->outwards, num * 0.6f));+}+static void tent_retreat(Tentacles *t) {+ if (t->index >= t->nnodes - 1) return;+ t->last_out = t->outwards;+ t->ease = 0;+ t->index++;+ for (int i = 0; i < t->count; i++) t->t[i].lerp = 0, t->t[i].fx = t->t[i].x, t->t[i].fy = t->t[i].y;+}+static void tentacles_retreat_all(void) {+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &TENTACLES && g_ents[i].dead != 1) tent_retreat(ST(&g_ents[i], Tentacles));+}+static void tent_move(Tentacles *t, V2 pos, const Player *p) { /* MoveTentacles */+ float num = 0;+ for (int i = 0; i < t->count; i++) {+ V2 target = tent_target(t, i, pos, num, p), at = tent_pos(t, i);+ float k = 1 - powf(0.1f * (0.25f + tent_rand(t, i, 0) * 0.75f), DT);+ tent_set(t, i, v2add(at, v2mul(v2sub(target, at), k)));+ num += tent_width(t, i);+ }+}+static void tent_snap(Tentacles *t, const Player *p) {+ float num = 0;+ for (int i = 0; i < t->count; i++) {+ t->t[i].lerp = 255;+ tent_set(t, i, tent_target(t, i, tent_node(t, t->index), num, p));+ num += tent_width(t, i);+ }+}+static void tent_awake(Ent *e) {+ Tentacles *t = ST(e, Tentacles);+ Player *p = level_player();+ bool flag = false;+ while (p && p->ent->cls && t->index < t->nnodes - 1) {+ V2 n = tent_node(t, t->index);+ V2 c = closest_on_line(n, v2add(n, v2mul(t->outwards, 10000)), player_center(p));+ if (v2len(v2sub(n, c)) >= t->fear) break;+ flag = true;+ tent_retreat(t);+ }+ if (flag) {+ t->ease = 1;+ tent_snap(t, NULL);+ }+}+static void tent_update(Ent *e) {+ Tentacles *t = ST(e, Tentacles);+ t->sound -= DT;+ Player *pl = level_player();+ const Player *p = pl && pl->ent->cls ? pl : NULL;+ t->has_player = p != NULL;+ if (t->slide_until > t->index) {+ if (p) {+ V2 n = tent_node(t, t->index);+ V2 c = closest_on_line(v2sub(n, v2mul(t->outwards, 10000)), v2add(n, v2mul(t->outwards, 10000)), player_center(p));+ if (v2len(v2sub(c, n)) < 32) {+ tent_retreat(t);+ t->outwards = safe_norm(v2sub(tent_node(t, t->index - 1), tent_node(t, t->index)), 1);+ } else+ tent_move(t, v2sub(c, v2mul(t->outwards, 190)), p);+ }+ } else {+ bool boss = first_of(&BOSS) != NULL;+ if (!boss && p && !p->dead && t->index < t->nnodes - 1) {+ V2 n = tent_node(t, t->index);+ V2 c = closest_on_line(n, v2add(n, v2mul(t->outwards, 10000)), player_center(p));+ if (v2len(v2sub(n, c)) < t->fear) tent_retreat(t);+ }+ if (t->index > 0) {+ t->ease = approach(t->ease, 1, (t->index != t->nnodes - 1 ? 1 : 2) * DT);+ V2 d = v2sub(tent_node(t, t->index - 1), tent_node(t, t->index));+ float q = 1 - (1 - t->ease) * (1 - t->ease); /* Ease.QuadOut */+ t->outwards = angle_vec(angle_lerp(vangle(t->last_out), vangle(d), q), 1);+ float num = 0;+ for (int i = 0; i < t->count; i++) {+ V2 target = tent_target(t, i, tent_node(t, t->index), num, p);+ if (t->t[i].lerp < 255) {+ float l = t->t[i].lerp / 255.f + DT / (0.5f + tent_rand(t, i, 4) * 0.25f);+ t->t[i].lerp = (uint8_t)(l >= 1 ? 255 : l * 255);+ V2 from = v2(t->base.x + t->t[i].fx * 0.5f, t->base.y + t->t[i].fy * 0.5f);+ tent_set(t, i, v2lerp(from, target, ease_cube_inout(fminf(l, 1))));+ } else {+ V2 at = tent_pos(t, i);+ float k = 1 - powf(0.1f * (0.25f + tent_rand(t, i, 0) * 0.75f), DT);+ tent_set(t, i, v2add(at, v2mul(v2sub(target, at), k)));+ }+ num += tent_width(t, i);+ }+ } else+ tent_move(t, tent_node(t, t->index), p);+ }+}+static float fast_sin(float x) { /* a parabola, good to 0.1% after the correction */+ x = fmodf(x + PI_F, 2 * PI_F);+ if (x < 0) x += 2 * PI_F;+ x -= PI_F;+ float y = 1.2732395f * x - 0.4052847f * x * fabsf(x);+ return 0.225f * (y * fabsf(y) - y) + y;+}+/* one convex quad, filled where pixel centers are inside */+static void quad_fill(uint16_t *strip, int y0, int y1, const V2 *v, uint16_t pc, int a) {+ float miny = v[0].y, maxy = v[0].y;+ for (int i = 1; i < 4; i++) miny = fminf(miny, v[i].y), maxy = fmaxf(maxy, v[i].y);+ int ra = (int)ceilf(miny - 0.5f), rb = (int)ceilf(maxy - 0.5f);+ if (ra < y0) ra = y0;+ if (rb > y1) rb = y1;+ for (int y = ra; y < rb; y++) {+ float yc = y + 0.5f, xl = 1e9f, xr = -1e9f;+ for (int i = 0; i < 4; i++) {+ V2 p = v[i], q = v[(i + 1) & 3];+ if ((p.y <= yc) == (q.y <= yc)) continue;+ float x = p.x + (yc - p.y) * (q.x - p.x) / (q.y - p.y);+ xl = fminf(xl, x), xr = fmaxf(xr, x);+ }+ if (xl > xr) continue;+ int xa = (int)ceilf(xl - 0.5f), xb = (int)ceilf(xr - 0.5f);+ if (xa < 0) xa = 0;+ if (xb > VIEW_W) xb = VIEW_W;+ uint16_t *d = strip + (y - y0) * VIEW_W;+ if (a >= 256)+ for (int x = xa; x < xb; x++) d[x] = pc;+ else+ for (int x = xa; x < xb; x++) d[x] = blend565(d[x], pc, a);+ }+}+static void tent_strip(uint16_t *strip, int y0, int y1, void *ctx) {+ Ent *e = ctx;+ Tentacles *t = ST(e, Tentacles);+ static const uint32_t COLOR[4] = {0x3F2A4F, 0x7B3555, 0x662847, 0x492632};+ float alpha = t->index == t->nnodes - 1 ? 1 - t->ease : 1;+ int a = (int)(alpha * 256);+ if (a <= 0) return;+ uint16_t pc = a >= 256 ? rgb(COLOR[t->layer & 3]) : scale565(rgb(COLOR[t->layer & 3]), a);+ V2 out = t->outwards, perpv = v2(out.y, -out.x); /* -outwards.Perpendicular() */+ float cx = (float)g_camx, cy = (float)g_camy, sy0 = y0 + cy, sy1 = y1 + cy;+ float time = g_level.time_active;+ for (int i = 0; i < t->count; i++) {+ V2 pos = tent_pos(t, i);+ float w = tent_width(t, i), len = 32 + tent_rand(t, i, 1) * 64, wave = tent_rand(t, i, 3);+ V2 val2 = v2mul(perpv, w * 0.5f + 2);+ /* the filler, 240 px back */+ V2 q[4] = {v2add(pos, val2), v2sub(v2add(pos, v2mul(val2, 1.5f)), v2mul(out, 240)), v2sub(v2sub(pos, v2mul(val2, 1.5f)), v2mul(out, 240)),+ v2sub(pos, val2)};+ float lo = q[0].y, hi = q[0].y;+ for (int k = 1; k < 4; k++) lo = fminf(lo, q[k].y), hi = fmaxf(hi, q[k].y);+ if (hi >= sy0 && lo < sy1) {+ for (int k = 0; k < 4; k++) q[k].x -= cx, q[k].y -= cy;+ quad_fill(strip, y0, y1, q, pc, a);+ }+ /* the arm: 10 quads along a wave */+ float seg = len / 10 + yoyo(t->t[i].lerp / 255.f) * 6;+ float reach = seg * 10 + 6 + w;+ if (pos.y + reach < sy0 && pos.y - reach < sy0) continue;+ if (pos.y - reach >= sy1 && pos.y + reach >= sy1) continue;+ if (fminf(pos.y - reach, pos.y + reach) >= sy1 || fmaxf(pos.y - reach, pos.y + reach) < sy0) continue;+ V2 v3 = pos, v4 = val2;+ float pw = 1;+ for (int j = 1; j <= 10; j++) {+ pw *= 1.1f;+ float num2 = j / 10.f;+ float s = fast_sin(time * wave * pw * 2 + wave * 3 + j * 0.05f);+ V2 v6 = v2add(v2add(v3, v2mul(out, seg)), v2mul(perpv, s * (2 + 4 * num2)));+ V2 v7 = v2mul(val2, 1 - num2);+ V2 r[4] = {v2sub(v6, v7), v2sub(v3, v4), v2add(v3, v4), v2add(v6, v7)};+ float rl = r[0].y, rh = r[0].y;+ for (int k = 1; k < 4; k++) rl = fminf(rl, r[k].y), rh = fmaxf(rh, r[k].y);+ if (rh >= sy0 && rl < sy1) {+ for (int k = 0; k < 4; k++) r[k].x -= cx, r[k].y -= cy;+ quad_fill(strip, y0, y1, r, pc, a);+ }+ v3 = v6, v4 = v7;+ }+ }+}+static void tent_render(Ent *e) {+ Tentacles *t = ST(e, Tentacles);+ if (!t->count) return;+ gfx_custom(tent_strip, e, 0, VIEW_H);+}+static const EntClass TENTACLES = {.name = "tentacles", .size = sizeof(Tentacles), .update = tent_update, .render = tent_render,+ .awake = tent_awake};+static Ent *tent_create(const int16_t (*nodes)[2], int n, float fear, int slide, int layer) { /* Create */+ Ent *e = ent_new(&TENTACLES, nodes[0][0], nodes[0][1]);+ if (!e) return NULL;+ e->collidable = 0;+ e->tags = TAG_TRANSITION_UPDATE;+ Tentacles *t = ST(e, Tentacles);+ for (int i = 0; i < n; i++) {+ t->nodes[i][0] = (int16_t)(nodes[i][0] + rndi(16) - 8);+ t->nodes[i][1] = (int16_t)(nodes[i][1] + rndi(16) - 8);+ }+ t->nnodes = (uint8_t)n;+ t->base = tent_node(t, 0);+ e->x = t->base.x, e->y = t->base.y;+ t->outwards = safe_norm(v2sub(tent_node(t, 0), tent_node(t, 1)), 1);+ t->fear = fear;+ t->slide_until = (uint8_t)slide;+ t->layer = (uint8_t)layer;+ t->sound = 0.25f;+ static const int32_t DEPTH[4] = {-1000000, 8990, 10010, 10011};+ static const float OFFSET[4] = {110, 80, 50, 20};+ e->depth = DEPTH[layer];+ t->offset = OFFSET[layer];+ t->seed = (uint16_t)rndi(65536);+ float along = 0;+ int k = 0;+ while (k < TENT_MAX && along < 440) { /* Width 4..20 each, until 440 px wide */+ tent_set(t, k, tent_target(t, k, tent_node(t, 0), along, NULL));+ t->t[k].lerp = 0;+ along += tent_width(t, k);+ k++;+ }+ t->count = (uint8_t)k;+ return e;+}+static void new_tentacles(const EData *d) {+ int16_t nodes[TENT_NODES][2];+ int n = 0;+ nodes[n][0] = (int16_t)d->x, nodes[n][1] = (int16_t)d->y, n++;+ for (int i = 0; i < d->nnodes && n < TENT_NODES; i++, n++) {+ V2 v = ed_node(d, i);+ nodes[n][0] = (int16_t)v.x, nodes[n][1] = (int16_t)v.y;+ }+ if (n < 2) return;+ const char *fd = EAS(d, tentacles, fear_distance);+ float fear = !strcmp(fd, "close") ? 16 : !strcmp(fd, "medium") ? 40 : !strcmp(fd, "far") ? 80 : 0;+ int slide = (int)EA(d, tentacles, slide_until);+ Ent *e = tent_create(nodes, n, fear, slide, 0);+ if (!e) return;+ /* Added: three more layers from the same (original) nodes */+ for (int i = 1; i < 4; i++) tent_create(nodes, n, fear, ST(e, Tentacles)->slide_until, i);+}++/* ---------------------------------------------------------------- LookoutBlocker */+/* a box the lookout's view cannot enter (the lookout, towerviewer, finds it by its class name) */+static const EntClass LOOKOUT_BLOCKER = {.name = "lookoutBlocker"};+static void new_lookout_blocker(const EData *d) {+ Ent *e = ent_new(&LOOKOUT_BLOCKER, d->x, d->y);+ if (!e) return;+ ent_box(e, EA(d, lookoutBlocker, width), EA(d, lookoutBlocker, height), 0, 0);+ e->visible = 0;+}++/* DashBlock.Break, from entities.c */+void level_break_dash_block(Ent *e, V2 dir);+static void level_break_dash_block_ext(Ent *e, V2 dir) { level_break_dash_block(e, dir); }++/* ---------------------------------------------------------------- the story's shared pieces (badeline.h) */+Ent *scene_new(const EntClass *cls, void (*on_end)(Ent *e, bool skipped), bool fade_in_on_skip, bool ending_after) {+ Ent *e = ent_new(cls, 0, 0);+ if (!e) return NULL;+ e->collidable = 0;+ if (!cls->render) e->visible = 0;+ cutscene_start(e, on_end, fade_in_on_skip, ending_after);+ return e;+}+void player_dummy(Player *p) {+ player_set_state(p, ST_DUMMY);+ p->state_locked = true;+}+void player_free(Player *p) {+ p->state_locked = false;+ player_set_state(p, ST_NORMAL);+}+Co *ev_co(Co *c, int8_t *last, int index) {+ if (*last != index) {+ *last = (int8_t)index;+ memset(c, 0, sizeof *c);+ }+ return c;+}+void level_goto(const char *room) {+ int idx = chapter_find_room(g_level.chapter, room);+ if (idx >= 0) level_load_room(idx, INTRO_NONE);+}+void player_intro_none(Player *p) {+ if (p->state == ST_INTRORESPAWN) player_set_state(p, ST_NORMAL);+ p->ent->visible = 1;+}+void oshiro_sprite_update(Sprite *s, Wiggler *w) {+ int bank, idle;+ spr_update(s);+ if (textbox_portrait(&bank, &idle)) {+ bool side = bank == SB_portrait_oshiro && ((idle >= A_portrait_oshiro_idle_sidehappy && idle <= A_portrait_oshiro_talk_sideworried) ||+ (idle >= A_portrait_oshiro_idle_sidesuspicious && idle <= A_portrait_oshiro_talk_sidesuspicious));+ int to = side && s->anim == A_oshiro_idle ? A_oshiro_side : !side && s->anim == A_oshiro_side ? A_oshiro_idle : -1;+ if (to >= 0) { /* Pop(name, flip: true) */+ spr_play(s, to, false);+ s->sx = -s->sx;+ wiggler_restart(w);+ }+ }+ if (w->active) {+ wiggler_update(w);+ s->sx = sgn(s->sx) * (1 + w->value * 0.2f), s->sy = 1 - w->value * 0.2f;+ }+}+void fade_wipe(bool in, float duration, WipeDone done) {+ wipe_start(WIPE_FADE, in, done);+ g_wipe.duration = duration;+}+void sprite_set_frame(Sprite *s, int frame) { /* Sprite.SetAnimationFrame */+ int n = spr_frames(s);+ if (s->anim == 255 || n <= 0) return;+ s->frame = (uint8_t)(frame % n);+ s->timer = 0;+}++/* PlayerHair.AfterUpdate with its default steps */+void hair_follow(Hair *h, const Sprite *s, V2 render_pos, int facing) {+ int hx, hy, fr, carry;+ bool has;+ V2 *n = h->n;+ hair_meta(spr_tex(s), &hx, &hy, &fr, &has, &carry);+ n[0] = v2(render_pos.x + hx * facing, render_pos.y - 9 * s->sy + hy);+ V2 target = v2add(n[0], v2(-facing * 0.5f * 2, 2)), prev = n[0];+ for (int i = 1; i < 4; i++) {+ n[i] = approach_v(n[i], target, (1 - i / 4.f * 0.5f) * 64 * DT);+ if (v2len(v2sub(n[i], prev)) > 3) n[i] = v2add(prev, safe_norm(v2sub(n[i], prev), 3));+ target = v2add(n[i], v2(-facing * 0.5f, 2));+ prev = n[i];+ }+}+/* the nodes after the bangs: characters/player/hair00 (a disc in 10x10, its rows' first and last pixels) scaled,+ * drawn in one layer (scaled textures are few a frame) */+static const uint8_t HAIR_LO[10] = {10, 3, 2, 1, 1, 1, 1, 2, 3, 10}, HAIR_HI[10] = {0, 6, 7, 8, 8, 8, 8, 7, 6, 0};+static void hair_strip(uint16_t *strip, int y0, int y1, void *ctx) {+ const Hair *h = ctx;+ int a = h->alpha >= 255 ? 256 : h->alpha;+ for (int pass = 0; pass < 2; pass++) /* the outlines (nodes 1 to 3), then the nodes back to front */+ for (int k = 1; k < 4; k++) {+ int i = pass ? 4 - k : k;+ float num = 0.25f + (1 - i / 4.f) * 0.75f, sx = num * h->sx;+ float px = floorf(h->n[i].x + 0.5f) - g_camx, py = floorf(h->n[i].y + 0.5f) - g_camy;+ for (int d = pass ? 4 : 0; d < (pass ? 5 : 4); d++) {+ float ox = px + (d == 0 ? -1 : d == 1 ? 1 : 0), oy = py + (d == 2 ? -1 : d == 3 ? 1 : 0);+ for (int y = (int)floorf(oy - 5 * num); y <= (int)ceilf(oy + 5 * num); y++) {+ int v = (int)floorf((y + 0.5f - oy) / num + 5);+ if (y < y0 || y >= y1 || v < 0 || v > 9) continue;+ for (int x = (int)floorf(ox - 5 * sx); x <= (int)ceilf(ox + 5 * sx); x++) {+ int u = (int)floorf((x + 0.5f - ox) / sx + 5);+ if (u >= HAIR_LO[v] && u <= HAIR_HI[v]) px_blend(strip, y0, y1, x, y, pass ? h->color : 0, a);+ }+ }+ }+ }+}+/* PlayerHair.Render: the outline, then the nodes back to front */+void hair_draw(Hair *h, const Sprite *s, int facing, uint16_t color, float alpha) {+ int hx, hy, fr, carry;+ bool has;+ hair_meta(spr_tex(s), &hx, &hy, &fr, &has, &carry);+ uint8_t a = a8(alpha);+ if (!has || !a || !s->sx) return;+ static const uint16_t BANGS[3] = {T_characters_player_bangs00, T_characters_player_bangs01, T_characters_player_bangs02};+ uint16_t t = BANGS[fr < 3 ? fr : 0];+ float x = floorf(h->n[0].x), y = floorf(h->n[0].y), sx = facing * fabsf(s->sx);+ h->sx = fabsf(s->sx), h->color = color, h->alpha = a;+ for (int d = 0; d < 4; d++)+ gfx_tex_ex(t, x + (d == 0 ? -1 : d == 1 ? 1 : 0), y + (d == 2 ? -1 : d == 3 ? 1 : 0), 5, 5, sx, 1, 0, 0, a, GF_SILHOUETTE);+ float top = h->n[0].y, bot = top;+ for (int i = 1; i < 4; i++) top = fminf(top, h->n[i].y), bot = fmaxf(bot, h->n[i].y);+ gfx_custom(hair_strip, h, (int)floorf(top) - g_camy - 7, (int)ceilf(bot) - g_camy + 7);+ gfx_tex_ex(t, x, y, 5, 5, sx, 1, 0, color, a, GF_SILHOUETTE);+}++/* ---------------------------------------------------------------- BadelineDummy */+static void bd_step(Ent *e, BDummy *b) { /* FloatTo / WalkTo, an update at a time */+ V2 at = v2(e->x, e->y);+ if (b->walking) {+ if (b->job.step == 1) {+ b->floatness = 0;+ spr_play(&b->spr, A_badeline_walk, false);+ if (sgn(b->target.x - e->x) != 0) b->spr.sx = (float)sgn(b->target.x - e->x);+ b->job.step = 2;+ }+ if (e->x != b->target.x) {+ e->x = approach(e->x, b->target.x, DT * b->walk_speed);+ return;+ }+ spr_play(&b->spr, A_badeline_idle, false);+ job_end(&b->job);+ return;+ }+ switch (b->job.step) {+ case 1: {+ spr_play(&b->spr, A_badeline_fallSlow, false);+ if (b->face && sgn(b->target.x - e->x) != 0) b->spr.sx = (float)sgn(b->target.x - e->x);+ V2 v = safe_norm(v2sub(b->target, at), 1);+ b->perp = v2(-v.y, v.x);+ b->speed = 0;+ b->job.step = 2;+ }+ /* fall through */+ case 2:+ if (!v2eq(at, b->target)) {+ b->speed = approach(b->speed, b->float_speed, b->float_accel * DT);+ at = approach_v(at, b->target, b->speed * DT);+ e->x = at.x, e->y = at.y;+ b->floatness = approach(b->floatness, 4, 8 * DT);+ b->float_normal = approach_v(b->float_normal, b->perp, DT * 12);+ if (b->fade_light) b->light_alpha = approach(b->light_alpha, 0, DT * 2);+ return;+ }+ if (b->quick_end) b->floatness = 2;+ b->job.step = 3;+ /* fall through */+ default:+ if (b->floatness != 2) {+ b->floatness = approach(b->floatness, 2, 8 * DT);+ return;+ }+ if (b->turn_at_end) b->spr.sx = b->turn_at_end;+ job_end(&b->job);+ }+}+/* BadelineAutoAnimator: laughs or yells with Badeline's portrait (its pop: the wiggler) */+static void autoanim(Sprite *spr, Wiggler *pop, int8_t *last, uint8_t *syncing, bool enabled) {+ int bank, idle;+ bool flag = false;+ if (enabled && textbox_portrait(&bank, &idle) && bank == SB_portrait_badeline) {+ if (idle == A_portrait_badeline_idle_scoff) {+ if (!*syncing) *last = (int8_t)(spr->anim == 255 ? -1 : spr->anim);+ spr_play(spr, A_badeline_laugh, false);+ *syncing = 1, flag = 1;+ } else if (idle == A_portrait_badeline_idle_yell || idle == A_portrait_badeline_idle_freakA ||+ idle == A_portrait_badeline_idle_freakB || idle == A_portrait_badeline_idle_freakC) {+ if (!*syncing) {+ wiggler_restart(pop);+ *last = (int8_t)(spr->anim == 255 ? -1 : spr->anim);+ }+ spr_play(spr, A_badeline_angry, false);+ *syncing = 1, flag = 1;+ }+ }+ if (*syncing && !flag) {+ *syncing = 0;+ if (*last < 0 || *last == A_badeline_spin) *last = A_badeline_fallSlow;+ if (spr->anim == A_badeline_angry) wiggler_restart(pop);+ spr_play(spr, *last, false);+ }+}+static void bd_autoanim(BDummy *b) { autoanim(&b->spr, &b->pop, &b->last_anim, &b->syncing, b->auto_enabled); }+static void bd_update(Ent *e) {+ BDummy *b = BD(e);+ if (b->spr.sx != 0) b->hair_facing = (int8_t)sgn(b->spr.sx);+ spr_update(&b->spr);+ bd_autoanim(b);+ if (b->pop.active) {+ wiggler_update(&b->pop);+ float s = 1 + 0.25f * b->pop.value;+ b->spr.sx = sgn(b->spr.sx) * s, b->spr.sy = s;+ }+ sine_update(&b->wave);+ b->spr_pos = v2mul(b->float_normal, b->wave.value * b->floatness);+ if (job_due(&b->job)) bd_step(e, b);+ hair_follow(&b->hair, &b->spr, v2add(v2(e->x, e->y), b->spr_pos), b->hair_facing);+}+static void bd_render(Ent *e) {+ BDummy *b = BD(e);+ hair_draw(&b->hair, &b->spr, b->hair_facing, rgb(0x9B3FB5), b->hair_alpha);+ spr_draw(&b->spr, floorf(e->x + b->spr_pos.x), floorf(e->y + b->spr_pos.y));+ if (!b->no_light) light_add(e->x, e->y - 8, 0xDB7093, b->light_alpha, 20, 60); /* Color.PaleVioletRed */+}+static const EntClass BDUMMY = {.name = "badelineDummy", .size = sizeof(BDummy), .update = bd_update, .render = bd_render};+Ent *bd_new(V2 at) {+ Ent *e = ent_new(&BDUMMY, at.x, at.y);+ if (!e) return NULL;+ ent_box(e, 6, 6, -3, -7);+ e->collidable = 0;+ BDummy *b = BD(e);+ spr_init(&b->spr, SB_badeline);+ spr_play(&b->spr, A_badeline_fallSlow, false);+ b->spr.sx = -1;+ b->hair_facing = -1;+ for (int i = 0; i < 4; i++) b->hair.n[i] = v2(at.x, at.y);+ b->float_speed = 120, b->float_accel = 240, b->floatness = 2;+ b->float_normal = v2(0, 1);+ b->wave.freq = 0.25f;+ b->light_alpha = b->hair_alpha = 1;+ b->auto_enabled = 1;+ b->last_anim = -1;+ wiggler_init(&b->pop, 0.5f, 4);+ return e;+}+void bd_appear(Ent *e) { /* the displacement burst is not drawn */+ particles_emit(PL_MID, &P_BadelineOldsite_P_Vanish, 12, v2(e->x, e->y - 4), v2(6, 6), P_BadelineOldsite_P_Vanish.direction);+}+void bd_vanish(Ent *e) {+ bd_appear(e);+ ent_remove(e);+}+void bd_float_to(Ent *e, V2 target, int turn_at_end, bool face, bool fade_light, bool quick_end) {+ BDummy *b = BD(e);+ b->target = target, b->turn_at_end = (int8_t)turn_at_end, b->face = face, b->fade_light = fade_light;+ b->quick_end = quick_end, b->walking = 0;+ job_start(&b->job);+}+void bd_walk_to(Ent *e, float x, float speed) {+ BDummy *b = BD(e);+ b->target.x = x, b->walk_speed = speed, b->walking = 1;+ job_start(&b->job);+}+void bd_set_frame(Ent *e, int frame) { sprite_set_frame(&BD(e)->spr, frame); }++/* ---------------------------------------------------------------- NPC */+static void npc_move_step(Ent *e, Npc *n) { /* MoveTo, an update at a time */+ switch (n->mv.step) {+ case 1:+ if (n->mv_remove) e->tags |= TAG_TRANSITION_UPDATE;+ if (sgn(n->mv_target.x - e->x) != 0) n->spr.sx = (float)sgn(n->mv_target.x - e->x);+ n->mv_alpha = n->mv_fade ? 0 : 1;+ if (n->move_anim != 255) spr_play(&n->spr, n->move_anim, false);+ n->mv_speed = 0;+ n->mv.step = 2;+ /* fall through */+ case 2:+ if (n->move_y ? !v2eq(v2(e->x, e->y), n->mv_target) : e->x != n->mv_target.x) {+ n->mv_speed = approach(n->mv_speed, n->maxspeed, 160 * DT);+ if (n->move_y) {+ V2 at = approach_v(v2(e->x, e->y), n->mv_target, n->mv_speed * DT);+ e->x = at.x, e->y = at.y;+ } else+ e->x = approach(e->x, n->mv_target.x, n->mv_speed * DT);+ n->spr.alpha = a8(n->mv_alpha);+ n->mv_alpha = approach(n->mv_alpha, 1, DT);+ return;+ }+ if (n->idle_anim != 255) spr_play(&n->spr, n->idle_anim, false);+ n->mv.step = 3;+ /* fall through */+ case 3:+ if (n->mv_alpha < 1) {+ n->spr.alpha = a8(n->mv_alpha);+ n->mv_alpha = approach(n->mv_alpha, 1, DT);+ return;+ }+ if (n->mv_turn) n->spr.sx = n->mv_turn;+ if (n->mv_remove) ent_remove(e);+ n->mv.step = 4;+ return; /* yield return null */+ default: job_end(&n->mv);+ }+}+static void npc_update(Ent *e) {+ Npc *n = NPC_(e);+ spr_update(&n->spr);+ if (n->has_talk && talk_update(&n->talk, e) && n->on_talk) n->on_talk(e);+ n = NPC_(e);+ if (job_due(&n->mv)) npc_move_step(e, n);+ if (n->has_light) {+ Room *rm = g_level.room;+ bool in = e->x > rm->x - 16 && e->y > rm->y - 16 && e->x < rm->x + rm->w + 16 && e->y < rm->y + rm->h + 16;+ n->light_alpha = approach(n->light_alpha, in && !g_level.transitioning ? 1 : 0, DT * 2);+ }+ if (n->gravity) { /* NPC06_Theo_Plateau and _Ending: falling to the ground */+ if (!collide_solid(e, e->x, e->y + 1)) n->speed_y += 400 * DT, e->y += n->speed_y * DT;+ else n->speed_y = 0;+ }+ if (n->haha) hahaha_enable(&g_ents[n->haha - 1], n->spr.anim == A_granny_laugh);+ if (n->think) n->think(e);+}+static void npc_render(Ent *e) {+ Npc *n = NPC_(e);+ if (n->paint) {+ n->paint(e);+ return;+ }+ spr_draw(&n->spr, e->x, e->y);+ if (n->has_light) light_add(e->x, e->y + n->light_dy, n->light_color, n->light_alpha, n->light_r0, n->light_r1);+ if (n->has_talk) talk_render(&n->talk, e);+}+static const EntClass NPC = {.name = "npc", .size = sizeof(Npc), .update = npc_update, .render = npc_render,+ .removed = talk_removed};+Ent *npc_new(float x, float y, int bank, int anim, void (*think)(Ent *e)) {+ Ent *e = ent_new(&NPC, x, y);+ if (!e) return NULL;+ e->depth = 1000;+ ent_box(e, 8, 8, -4, -8);+ Npc *n = NPC_(e);+ spr_init(&n->spr, bank);+ if (anim >= 0) spr_play(&n->spr, anim, false);+ n->maxspeed = 80;+ n->move_y = 1;+ n->idle_anim = n->move_anim = 255;+ n->think = think;+ return e;+}+void npc_light(Ent *e, int dy, uint32_t color, int r0, int r1) {+ Npc *n = NPC_(e);+ n->has_light = 1, n->light_dy = (int8_t)dy, n->light_color = color, n->light_r0 = (uint8_t)r0, n->light_r1 = (uint8_t)r1;+ n->light_alpha = 1;+}+void npc_talker(Ent *e, int x, int y, int w, int h, V2 draw_at, void (*on_talk)(Ent *e)) {+ Npc *n = NPC_(e);+ talk_init(&n->talk, x, y, w, h, draw_at);+ n->has_talk = 1, n->on_talk = on_talk;+}+void npc_haha(Ent *e) {+ Ent *h = hahaha_new(v2(e->x + 8, e->y - 4), NULL);+ if (!h) return;+ hahaha_enable(h, false);+ NPC_(e)->haha = (uint16_t)(h - g_ents + 1);+}+void npc_move_to(Ent *e, V2 target, bool fade_in, int turn_at_end, bool remove_at_end) {+ Npc *n = NPC_(e);+ n->mv_target = target, n->mv_fade = fade_in, n->mv_turn = (int8_t)turn_at_end, n->mv_remove = remove_at_end;+ job_start(&n->mv);+}+Ent *npc_find(int which) {+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &NPC && g_ents[i].dead != 1 && NPC_(&g_ents[i])->which == which) return &g_ents[i];+ return NULL;+}++/* ================================================================ the story */+/* this chapter's cutscenes: one class, its routine in `run`; Add(new Coroutine(...)) of a zoom or a camera move+ * goes on beside it (from the update after: 2, or from an event: 1) */+typedef struct {+ Cutscene cs;+ void (*run)(Ent *e), (*draw)(Ent *e);+ bool (*evs)(void *s, Co *c, int i); /* its textbox events (a nested routine each) */+ bool (*par)(void *s, Co *c); /* the routine beside it */+ Ent *tb, *a, *b, *bd; /* who it is about: the boss, Granny, Badeline crying, Theo, a BadelineDummy */+ Walk walk;+ Step step, cam, zoom;+ Co ev, pco; /* a textbox event's, and the routine beside the cutscene's */+ V2 cam_to, zoom_at, v[3];+ float (*cam_ease)(float);+ float cam_dur, cam_delay, zoom_dur, f[8];+ int8_t ev_i;+ uint8_t cam_on, zoom_on, par_on, i, j, k;+} S6;+#define S6_(e) ST(e, S6)+static void s6_render(Ent *e) {+ if (S6_(e)->draw) S6_(e)->draw(e);+}+static void s6_update(Ent *e);+static const EntClass SCENE6 = {.name = "cutscene6", .size = sizeof(S6), .update = s6_update, .render = s6_render};+static Ent *s6_new(void (*run)(Ent *e), void (*on_end)(Ent *e, bool skipped), bool fade_in_on_skip, bool ending_after) {+ Ent *e = scene_new(&SCENE6, on_end, fade_in_on_skip, ending_after);+ if (e) S6_(e)->run = run, S6_(e)->ev_i = -1;+ return e;+}+static void s6_update(Ent *e) {+ S6 *s = S6_(e);+ s->run(e);+ if (e->dead == 1) return;+ s = S6_(e);+ if (s->zoom_on == 2) s->zoom_on = 1;+ else if (s->zoom_on && !zoom_to(&s->zoom, s->zoom_at, 2, s->zoom_dur)) s->zoom_on = 0;+ if (s->cam_on == 2) s->cam_on = 1;+ else if (s->cam_on && (s->cam_delay > 0 ? (s->cam_delay -= DT, true) : camera_to(&s->cam, s->cam_to, s->cam_dur, s->cam_ease)) == false)+ s->cam_on = 0;+ if (s->par_on == 2) s->par_on = 1;+ else if (s->par_on && !s->par(s, &s->pco)) s->par_on = 0;+}+/* Add(new Coroutine(Level.ZoomTo(at, 2, duration))) and Add(new Coroutine(CameraTo(to, duration, ease, delay))) */+static void s6_zoom(S6 *s, V2 at, float duration, bool from_event) {+ step_reset(&s->zoom);+ s->zoom_at = at, s->zoom_dur = duration, s->zoom_on = from_event ? 1 : 2;+}+static void s6_cam(S6 *s, V2 to, float duration, float (*ease)(float), float delay, bool from_event) {+ step_reset(&s->cam);+ s->cam_to = to, s->cam_dur = duration, s->cam_ease = ease, s->cam_delay = delay, s->cam_on = from_event ? 1 : 2;+}+static bool s6_ev(void *ctx, int i) {+ S6 *s = S6_((Ent *)ctx);+ return !s->evs(s, ev_co(&s->ev, &s->ev_i, i), i);+}+static float room_bottom(void) { return (float)(g_level.room->y + g_level.room->h); }+static bool menu_confirm(void) { return btn_pressed(&g_in.confirm) || btn_pressed(&g_in.jump); }+static void player_drop_to_ground(Player *p) { /* while (!OnGround() && Y < Bounds.Bottom) Y++ */+ while (!actor_on_ground(p->ent, 1) && p->ent->y < room_bottom()) p->ent->y++;+}++/* ---------------------------------------------------------------- CS06_BossIntro, CS06_BossMid */+static bool bintro_nb(void *ctx, Co *c, int i) {+ S6 *s = ctx;+ Ent *boss = s->a;+ Boss *b = ST(boss, Boss);+ if (i == 0) { /* BadelineFloat */+ NB_BEGIN(c);+ s6_zoom(s, v2(170, 110), 1, true);+ b->sitting = 0;+ cs_play(&b->spr, A_badeline_fallSlow, false);+ b->normal_sx = -1;+ b->autoanim = 1, b->last_anim = -1;+ s->f[1] = boss->y;+ for (s->f[2] = 0; s->f[2] < 1; s->f[2] += DT * 4) {+ boss->y = lerpf(s->f[1], s->f[0], ease_cube_inout(s->f[2]));+ NB_YIELD(c);+ }+ NB_END(c);+ }+ NB_BEGIN(c); /* PlayerStepForward */+ NB_WALK(c, s->walk, walk_exact((int)g_player.ent->x + 8));+ NB_END(c);+}+static void bintro_run(Ent *e) {+ S6 *s = S6_(e);+ Player *p = &g_player;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_dummy(p);+ while (!p->dead && !actor_on_ground(p->ent, 1)) CO_YIELD(c);+ while (p->dead) CO_YIELD(c);+ p->facing = 1;+ s6_cam(s, v2((p->ent->x + s->a->x) / 2 - 160, room_bottom() - 180), 1, NULL, 0, false);+ CO_WAIT(c, 0.5f);+ if (!p->dead) CO_WALK(c, s->walk, walk_exact((int)(s->f[3] - 8)));+ p->facing = 1;+ CO_SAY(c, s->tb, "ch6_boss_start", s6_ev, e);+ CO_ZOOM_BACK(c, &s->step, 0.5f);+ cutscene_end(e);+ return;+ CO_END(c);+}+static void bintro_end(Ent *e, bool skipped) {+ S6 *s = S6_(e);+ Player *p = &g_player;+ if (skipped) {+ p->ent->x = s->f[3];+ player_drop_to_ground(p);+ }+ player_free(p);+ Boss *b = ST(s->a, Boss);+ s->a->y = s->f[0];+ if (b->normal) {+ b->normal_sx = -1;+ cs_play(&b->spr, A_badeline_laugh, false);+ }+ b->sitting = 0;+ b->autoanim = 0; /* boss.Remove(animator) */+ level_set_flag("boss_intro", true);+}+static void bmid_run(Ent *e) {+ S6 *s = S6_(e);+ Player *p = &g_player;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ do CO_YIELD(c);+ while (!level_player());+ player_dummy(p);+ while (!actor_on_ground(p->ent, 1)) CO_YIELD(c);+ CO_WALK(c, s->walk, walk_exact((int)p->ent->x + 20));+ CO_ZOOM_TO(c, &s->step, v2(80, 110), 2, 0.5f);+ CO_SAY(c, s->tb, "ch6_boss_middle", NULL, NULL);+ CO_WAIT(c, 0.1f);+ CO_ZOOM_BACK(c, &s->step, 0.4f);+ cutscene_end(e);+ return;+ CO_END(c);+}+static void bmid_end(Ent *e, bool skipped) {+ Player *p = level_player();+ (void)e;+ if (p) {+ if (skipped) player_drop_to_ground(p);+ player_free(p);+ }+ Ent *boss = first_of(&BOSS);+ if (boss) boss_hit(boss, NULL);+ level_set_flag("boss_mid", true);+}+static void boss_mid_new(void) { s6_new(bmid_run, bmid_end, true, false); }++/* ---------------------------------------------------------------- CS06_Reflection */+static void reflect6_run(Ent *e) {+ S6 *s = S6_(e);+ Player *p = &g_player;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_dummy(p);+ p->force_camera_update = true;+ CO_WALK(c, s->walk, walk_exact((int)s->f[0]));+ CO_WAIT(c, 0.1f);+ p->facing = 1;+ CO_WAIT(c, 0.1f);+ CO_ZOOM_TO(c, &s->step, v2(200, 90), 2, 1);+ CO_SAY(c, s->tb, "CH6_REFLECT_AFTER", NULL, NULL);+ CO_ZOOM_BACK(c, &s->step, 0.5f);+ cutscene_end(e);+ return;+ CO_END(c);+}+static void reflect6_end(Ent *e, bool skipped) {+ (void)e, (void)skipped;+ player_free(&g_player);+ g_player.force_camera_update = false;+ level_set_flag("reflection", true);+}++/* ---------------------------------------------------------------- NPC06_Granny and CS06_Granny */+static bool granny6_nb(void *ctx, Co *c, int i) {+ S6 *s = ctx;+ Player *p = &g_player;+ Npc *g = NPC_(s->a);+ NB_BEGIN(c);+ if (i == 0) { /* ZoomIn */+ s->v[0] = v2add(v2sub(v2lerp(v2(s->a->x, s->a->y), v2(p->ent->x, p->ent->y), 0.5f), g_level.cam), v2(0, -20));+ NB_ZOOM_TO(c, &s->step, s->v[0], 2, 0.5f);+ } else if (i == 1) { /* Laughs */+ if (s->j) {+ s->j = 0;+ NB_WAIT(c, 0.5f);+ }+ spr_play(&g->spr, A_granny_laugh, false);+ NB_WAIT(c, 1);+ } else if (i == 2) { /* StopLaughing */+ spr_play(&g->spr, A_granny_idle, false);+ NB_WAIT(c, 0.25f);+ } else if (i == 3 || i == 4) { /* MaddyWalksRight, MaddyWalksLeft */+ NB_WAIT(c, 0.1f);+ p->facing = i == 3 ? 1 : -1;+ NB_WALK(c, s->walk, walk_exact((int)p->ent->x + p->facing * 8));+ NB_WAIT(c, 0.1f);+ } else if (i == 5) /* WaitABit */+ NB_WAIT(c, 0.8f);+ else { /* MaddyTurnsRight */+ NB_WAIT(c, 0.1f);+ p->facing = 1;+ NB_WAIT(c, 0.1f);+ }+ NB_END(c);+}+static void granny6_run(Ent *e) {+ S6 *s = S6_(e);+ Player *p = &g_player;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_dummy(p);+ p->force_camera_update = true;+ if (s->i == 0) {+ CO_WALK(c, s->walk, walk_to(s->a->x - 40));+ p->facing = 1;+ s->j = 1; /* firstLaugh */+ CO_SAY(c, s->tb, "ch6_oldlady", s6_ev, e);+ } else {+ s->v[0] = v2add(v2sub(v2lerp(v2(s->a->x, s->a->y), v2(p->ent->x, p->ent->y), 0.5f), g_level.cam), v2(0, -20));+ CO_ZOOM_TO(c, &s->step, s->v[0], 2, 0.5f);+ CO_WALK(c, s->walk, walk_to(s->a->x - 20));+ p->facing = 1;+ CO_SAY(c, s->tb, s->i == 1 ? "ch6_oldlady_b" : "ch6_oldlady_c", NULL, NULL);+ }+ CO_ZOOM_BACK(c, &s->step, 0.5f);+ cutscene_end(e);+ return;+ CO_END(c);+}+static void granny6_end(Ent *e, bool skipped) {+ S6 *s = S6_(e);+ char f[12] = "granny_0";+ (void)skipped;+ player_free(&g_player);+ g_player.force_camera_update = false;+ spr_play(&NPC_(s->a)->spr, A_granny_idle, false);+ f[7] = (char)('0' + s->i);+ level_set_flag(f, true);+}+static void granny6_talk(Ent *e) { /* OnTalk */+ Npc *n = NPC_(e);+ Ent *cs = s6_new(granny6_run, granny6_end, true, false);+ if (cs) S6_(cs)->a = e, S6_(cs)->i = (uint8_t)n->i[0], S6_(cs)->evs = granny6_nb;+ n->i[0]++;+ n->talk.enabled = n->i[0] > 0 && n->i[0] < 3;+}+static void granny6_think(Ent *e) {+ Player *p = level_player();+ if (NPC_(e)->i[0] == 0 && p && p->ent->x > e->x - 60) granny6_talk(e);+}+static void new_granny6(const EData *d) {+ Ent *e = npc_new(d->x, d->y, SB_granny, A_granny_idle, granny6_think);+ if (!e) return;+ Npc *n = NPC_(e);+ n->which = NPC_GRANNY06;+ n->spr.sx = -1;+ npc_haha(e);+ char f[12] = "granny_0";+ while (n->i[0] < 9 && (f[7] = (char)('0' + n->i[0]), level_get_flag(f))) n->i[0]++;+ npc_talker(e, -20, -8, 30, 8, v2(0, -24), granny6_talk);+ n->talk.enabled = n->i[0] > 0 && n->i[0] < 3;+}++/* ---------------------------------------------------------------- NPC06_Badeline_Crying, its orbs, CS06_BossEnd */+typedef struct { V2 target, speed, aim, from; float ease, reset, p, offset; uint8_t mode, aiming, index; } COrb;+static float ease_bigback_in(float t) { return t * t * (4 * t - 3); }+static void corb_update(Ent *e) {+ COrb *o = ST(e, COrb);+ Player *p = level_player();+ if (o->mode == 0) { /* FloatRoutine */+ if (!o->aiming) o->aim = v2add(o->target, angle_vec(rndf() * 2 * PI_F, 16 + rndf() * 40)), o->reset = 0, o->aiming = 1;+ V2 d = v2sub(o->aim, v2(e->x, e->y));+ if (o->reset < 1 && v2len(d) > 8) {+ o->speed = v2add(o->speed, v2mul(safe_norm(d, 1), 420 * DT));+ if (v2len(o->speed) > 90) o->speed = safe_norm(o->speed, 90);+ e->x += o->speed.x * DT, e->y += o->speed.y * DT;+ o->reset += DT;+ o->ease = approach(o->ease, 1, DT * 4);+ } else+ o->aiming = 0;+ } else if (o->mode == 1 && p) { /* CircleRoutine */+ V2 to = v2add(player_center(p), angle_vec(g_level.time_active * 2 + o->offset, 24));+ o->p = approach(o->p, 1, DT * 2);+ V2 at = v2add(o->from, v2mul(v2sub(to, o->from), ease_cube_inout(o->p)));+ e->x = at.x, e->y = at.y;+ } else if (o->mode == 2 && o->p < 1) { /* AbsorbRoutine */+ float k = ease_bigback_in(o->p);+ V2 at = v2add(o->from, v2mul(v2sub(o->aim, o->from), k));+ e->x = at.x, e->y = at.y;+ o->ease = 0.2f + (1 - k) * 0.8f;+ o->p += DT;+ }+}+static void corb_render(Ent *e) {+ float k = ST(e, COrb)->ease;+ draw_centered(T_characters_badeline_orb, e->x, e->y, 0xFFFF, 255, k, k, 0);+}+static const EntClass CORB = {.name = "badelineOrb", .size = sizeof(COrb), .update = corb_update, .render = corb_render};+static void corb_routine(int mode, int i) { /* Routine.Replace(CircleRoutine(i / 8 * 2pi)) or (AbsorbRoutine()) */+ Player *p = level_player();+ for (int k = 0; k < g_nents; k++) {+ Ent *e = &g_ents[k];+ COrb *o = ST(e, COrb);+ if (e->cls != &CORB || e->dead == 1 || (mode == 1 && o->index != i)) continue;+ o->mode = (uint8_t)(p ? mode : 3), o->from = v2(e->x, e->y), o->p = 0;+ o->offset = i / 8.f * 2 * PI_F;+ if (p) o->aim = player_center(p);+ }+}+static void bossend_start(Ent *b);+/* the crying Badeline: f[0] white alpha, f[1] its size, i[0] started */+static void crying_think(Ent *e) {+ Npc *n = NPC_(e);+ Player *p = level_player();+ if (!n->i[1]) { /* Awake: after the connection, she is gone, with the tentacles */+ n->i[1] = 1;+ if (level_get_flag("badeline_connection")) {+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &TENTACLES) ent_remove(&g_ents[i]);+ ent_remove(e);+ return;+ }+ }+ if (!n->i[0] && p && p->ent->x > e->x - 32) {+ bossend_start(e);+ n->i[0] = 1;+ }+}+static void crying_paint(Ent *e) {+ Npc *n = NPC_(e);+ if (!n->i[2]) spr_draw(&n->spr, e->x, e->y); /* Sprite.Visible = false once she is white */+ Tex t;+ if (n->f[0] > 0 && tex_get(T_characters_badelineBoss_calm_white, &t)) /* white: Sprite's origin and place */+ gfx_tex_ex(T_characters_badelineBoss_calm_white, e->x, e->y, t.fw * t.scale * 0.5f, t.fh * t.scale * 0.64f, n->f[1], n->f[1], 0,+ 0xFFFF, a8(n->f[0]), 0);+ light_add(e->x, e->y - 6, 0xFFFFFF, n->f[1], 24, 64);+}+static void new_crying(const EData *d) {+ Ent *e = npc_new(d->x, d->y, SB_badeline_boss, A_badeline_boss_scaredIdle, crying_think);+ if (!e) return;+ NPC_(e)->f[1] = 1;+ NPC_(e)->paint = crying_paint;+}+static bool bossend_nb(void *ctx, Co *c, int i) {+ S6 *s = ctx;+ Player *p = &g_player;+ Ent *bd = s->a;+ NB_BEGIN(c);+ if (i == 0) NB_WAIT(c, 0.5f); /* StartMusic */+ else if (i == 1) { /* PlayerHug */+ s6_zoom(s, v2sub(v2add(v2(bd->x, bd->y + bd->cy + bd->ch / 2), v2(0, -24)), g_level.cam), 0.5f, true);+ NB_WAIT(c, 0.6f);+ NB_WALK(c, s->walk, walk_exact((int)bd->x - 10));+ p->facing = 1;+ NB_WAIT(c, 0.25f);+ p->dummy_auto_animate = false;+ spr_play(&p->spr, A_player_hug, false);+ NB_WAIT(c, 0.5f);+ } else { /* BadelineCalmDown */+ NB_WAIT(c, 0.5f);+ spr_play(&NPC_(bd)->spr, A_badeline_boss_scaredTransition, false);+ /* FinalBossStarfield's alpha goes down (the backdrop is not drawn here: its second) */+ for (s->f[5] = 1; s->f[5] > 0; s->f[5] -= DT) NB_YIELD(c);+ NB_WAIT(c, 1.5f);+ }+ NB_END(c);+}+/* Disperse(): f[1] size, k orbs */+static bool disperse_nb(S6 *s, Co *c) {+ Ent *bd = s->a;+ Npc *n = NPC_(bd);+ NB_BEGIN(c);+ s->k = 0;+ while (s->k < 8) {+ for (s->f[6] = n->f[1] - 0.125f; n->f[1] > s->f[6]; n->f[1] -= DT) NB_YIELD(c);+ Ent *o = ent_new(&CORB, bd->x, bd->y);+ if (o) {+ o->depth = -10001, o->collidable = 0;+ ST(o, COrb)->target = v2(bd->x - 16, bd->y - 40), ST(o, COrb)->ease = 0.2f, ST(o, COrb)->index = s->k;+ }+ s->k++;+ }+ NB_WAIT(c, 3.25f);+ for (s->k = 0; s->k < 8; s->k++) {+ corb_routine(1, s->k);+ NB_WAIT(c, 0.2f);+ }+ NB_WAIT(c, 2);+ corb_routine(2, 0);+ NB_WAIT(c, 1);+ NB_END(c);+}+/* LevelUpEffect */+static void levelup_update(Ent *e) {+ Sprite *s = ST(e, Sprite);+ spr_update(s);+ if (s->anim == 255) ent_remove(e);+}+static void levelup_render(Ent *e) { spr_draw(ST(e, Sprite), e->x, e->y); }+static const EntClass LEVELUP = {.name = "levelUpEffect", .size = sizeof(Sprite), .update = levelup_update, .render = levelup_render};+static void levelup_new(V2 at) {+ Ent *e = ent_new(&LEVELUP, at.x, at.y);+ if (!e) return;+ e->depth = -1000000, e->collidable = 0;+ spr_init(ST(e, Sprite), SB_player_level_up);+ spr_play(ST(e, Sprite), A_player_level_up_levelUp, true);+}+static void crying_paint(Ent *e);+static void crying_remove(Ent *bd) { /* badeline.RemoveSelf(), with her orbs */+ if (!bd || bd->dead == 1 || bd->cls != &NPC || NPC_(bd)->paint != crying_paint) return;+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &CORB) ent_remove(&g_ents[i]);+ ent_remove(bd);+}+static bool bossend_par(void *ctx, Co *c) { /* CenterCameraOnPlayer */+ S6 *s = ctx;+ NB_BEGIN(c);+ NB_WAIT(c, 0.5f);+ s->v[1] = g_level.zoom_focus;+ s->v[2] = v2sub(v2((float)g_level.room->x + 580, (float)g_level.room->y + 124), g_level.cam);+ for (s->f[7] = 0; s->f[7] < 1; s->f[7] += DT) {+ g_level.zoom_focus = v2add(s->v[1], v2mul(v2sub(s->v[2], s->v[1]), ease_sine_inout(s->f[7])));+ NB_YIELD(c);+ }+ NB_END(c);+}+/* f[0] fade, f[1] picture fade, f[2] picture glow, f[3] timer, f[4] white alpha; i: the picture (1, 2), j: waiting */+static bool pic_fade(S6 *s, float to, float duration) { return (s->f[1] = approach(s->f[1], to, DT / duration)) != to; }+static void bossend_run(Ent *e) {+ S6 *s = S6_(e);+ Player *p = &g_player;+ Co *c = &s->cs.co;+ s->f[3] += DT;+ if (s->f[4] > 0 && s->f[4] < 1 && s->a->dead != 1) { /* badeline.TurnWhite(1) */+ s->f[4] += DT;+ NPC_(s->a)->f[0] = fminf(s->f[4], 1);+ if (s->f[4] >= 1) NPC_(s->a)->i[2] = 1;+ }+ CO_BEGIN(c);+ player_dummy(p);+ while (!actor_on_ground(p->ent, 1)) CO_YIELD(c);+ p->facing = 1;+ CO_WAIT(c, 1);+ CO_SAY(c, s->tb, "ch6_boss_ending", s6_ev, e);+ CO_WAIT(c, 0.5f);+ while ((s->f[0] += DT) < 1) CO_YIELD(c);+ s->i = 1;+ while (pic_fade(s, 1, 1)) CO_YIELD(c);+ s->j = 1; /* WaitForPress */+ while (!menu_confirm()) CO_YIELD(c);+ s->j = 0;+ while (pic_fade(s, 0, 0.5f)) CO_YIELD(c);+ s->i = 2;+ while (pic_fade(s, 1, 1)) CO_YIELD(c);+ s->j = 1; /* WaitForPress */+ while (!menu_confirm()) CO_YIELD(c);+ s->j = 0;+ while ((s->f[2] += DT / 2) < 1) CO_YIELD(c);+ CO_WAIT(c, 0.2f);+ while (pic_fade(s, 0, 0.5f)) CO_YIELD(c);+ while ((s->f[0] -= DT * 12) > 0) CO_YIELD(c);+ s->f[4] = 0.0001f; /* Add(new Coroutine(badeline.TurnWhite(1))) */+ CO_WAIT(c, 0.5f);+ spr_play(&p->spr, A_player_idle, false);+ CO_WAIT(c, 0.25f);+ CO_WALK(c, s->walk, walk_back((int)p->ent->x - 8));+ memset(&s->pco, 0, sizeof s->pco);+ s->par_on = 2; /* Add(new Coroutine(CenterCameraOnPlayer())) */+ memset(&s->ev, 0, sizeof s->ev);+ CO_NEST(c, disperse_nb(s, &s->ev));+ level_set_flag("badeline_connection", true);+ level_flash(0xFFFF, false);+ g_session.inv_dashes = 2;+ p->inventory_dashes = 2;+ crying_remove(s->a);+ CO_WAIT(c, 0.1f);+ levelup_new(v2(p->ent->x, p->ent->y));+ CO_WAIT(c, 2);+ CO_ZOOM_BACK(c, &s->step, 0.5f);+ cutscene_end(e);+ return;+ CO_END(c);+}+static void bossend_draw(Ent *e) {+ S6 *s = S6_(e);+ if (s->f[0] <= 0 || g_level.paused) return;+ gfx_hud(true);+ gfx_rect(-2, -2, 324, 184, 0, a8(ease_cube_out(fminf(s->f[0], 1)) * 0.8f));+ if (s->i && s->f[1] > 0) { /* Portraits "hug1", "hug2" and the glow */+ float num = ease_cube_out(s->f[1]), k = 1 + (1 - num) * 0.025f, glow = ease_cube_out(s->f[1] * s->f[2]);+ static const uint16_t PICS[5] = {T__hug1, T__hug2, T__hug_light2a, T__hug_light2b, T__hug_light2c};+ for (int i = s->i - 1; i < 5; i = i < 2 ? 2 : i + 1) {+ if (i >= 2 && s->f[2] <= 0) break;+ uint16_t t = PICS[i];+ Tex tx;+ if (!tex_get(t, &tx)) continue;+ for (int add = 0; add < (i < 2 ? 1 : 2); add++) /* the glow: once, then once more added */+ gfx_tex_ex(t, 160, 90, tx.fw * tx.scale / 2.f, tx.fh * tx.scale / 2.f, k, k, 0, 0xFFFF, a8(i < 2 ? num : glow), add ? GF_ADD : 0);+ }+ Tex t;+ if (s->j && tex_get(T__textboxbutton, &t))+ gfx_tex_ex(T__textboxbutton, 1520 / 6.f, (880 + (fmodf(s->f[3], 1) < 0.25f ? 6 : 0)) / 6.f, t.fw / 2.f, t.fh / 2.f, 1, 1, 0, 0xFFFF,+ 255, 0);+ }+ gfx_hud(false);+}+static void bossend_end(Ent *e, bool skipped) {+ S6 *s = S6_(e);+ Player *p = &g_player;+ zoom_reset();+ g_session.inv_dashes = 2;+ p->inventory_dashes = 2;+ if (skipped) levelup_new(v2(p->ent->x, p->ent->y));+ p->dummy_auto_animate = true;+ player_free(p);+ crying_remove(s->a);+ level_set_flag("badeline_connection", true);+}+static void bossend_start(Ent *b) {+ Ent *e = s6_new(bossend_run, bossend_end, true, false);+ if (!e) return;+ e->tags |= TAG_HUD;+ S6_(e)->a = b, S6_(e)->draw = bossend_draw, S6_(e)->evs = bossend_nb, S6_(e)->par = bossend_par;+}++/* ---------------------------------------------------------------- NPC06_Theo_Ending, NPC06_Granny_Ending, CS06_Ending */+static void theo6_think(Ent *e) { /* the yolo alarm: yoloEnd after 0.8 s */+ Npc *n = NPC_(e);+ if (n->f[0] > 0 && (n->f[0] -= DT) <= 0) spr_play(&n->spr, A_theo_yoloEnd, false);+}+static void ending6_end(Ent *e, bool skipped) {+ (void)e, (void)skipped;+ level_complete_area(true, false);+ if (g_wipe.active && g_wipe.type == WIPE_SPOTLIGHT) g_wipe.focus.y -= 20;+}++static bool ending6_nb(void *ctx, Co *c, int i) {+ S6 *s = ctx;+ Player *p = &g_player;+ Ent *bd = s->bd, *granny = s->a, *theo = s->b;+ NB_BEGIN(c);+ if (i == 0) { /* GrannyEnter */+ NB_WAIT(c, 0.25f);+ BD(bd)->spr.sx = 1;+ NB_WAIT(c, 0.1f);+ granny->visible = 1;+ bd_float_to(bd, v2(bd->x - 10, bd->y), 1, false, false, false);+ npc_move_to(granny, v2(p->ent->x + 40, p->ent->y), false, 0, false);+ NB_AWAIT(c, &NPC_(granny)->mv);+ } else if (i == 1) { /* TheoEnter */+ p->facing = -1;+ BD(bd)->spr.sx = -1;+ NB_WAIT(c, 0.25f);+ s->v[0] = v2add(g_level.cam, v2(-40, 0));+ step_reset(&s->step);+ NB_NEST(c, camera_to(&s->step, s->v[0], 1, NULL));+ theo->visible = 1;+ s6_cam(s, v2add(g_level.cam, v2(40, 0)), 2, NULL, 1, true);+ bd_float_to(bd, v2(bd->x + 6, bd->y + 4), -1, false, false, false);+ npc_move_to(theo, v2(p->ent->x - 32, p->ent->y), false, 0, false);+ NB_AWAIT(c, &NPC_(theo)->mv);+ spr_play(&NPC_(theo)->spr, A_theo_tired, false);+ } else if (i == 2) { /* MaddyTurnsRight */+ NB_WAIT(c, 0.1f);+ p->facing = 1;+ NB_WAIT(c, 0.1f);+ bd_float_to(bd, v2(bd->x - 2, bd->y + 10), -1, false, false, false);+ NB_AWAIT(c, &BD(bd)->job);+ NB_WAIT(c, 0.1f);+ } else if (i == 3 || i == 4) { /* BadelineTurnsRight, BadelineTurnsLeft */+ NB_WAIT(c, 0.1f);+ BD(bd)->spr.sx = i == 3 ? 1 : -1;+ NB_WAIT(c, 0.1f);+ } else if (i == 5) /* WaitAbit */+ NB_WAIT(c, 0.4f);+ else if (i == 6) { /* TurnToLeft */+ NB_WAIT(c, 0.1f);+ p->facing = -1;+ NB_WAIT(c, 0.05f);+ BD(bd)->spr.sx = -1;+ NB_WAIT(c, 0.1f);+ } else { /* TheoRaiseFist, TheoStopTired */+ spr_play(&NPC_(theo)->spr, i == 7 ? A_theo_yolo : A_theo_idle, false);+ if (i == 7) NPC_(theo)->f[0] = 0.8f;+ NB_YIELD(c);+ }+ NB_END(c);+}+static void ending6_run(Ent *e) {+ S6 *s = S6_(e);+ Player *p = &g_player;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_dummy(p);+ CO_WAIT(c, 1);+ p->dashes = p->inventory_dashes = 1;+ g_session.inv_dashes = 1;+ s->bd = bd_new(player_center(p));+ if (!s->bd || !s->b) {+ cutscene_end(e);+ return;+ }+ bd_appear(s->bd);+ BD(s->bd)->float_speed = 80;+ BD(s->bd)->spr.sx = -1;+ bd_float_to(s->bd, v2(p->ent->x + 24, p->ent->y - 20), -1, false, false, false);+ CO_AWAIT(c, &BD(s->bd)->job);+ CO_ZOOM_TO(c, &s->step, v2(160, 120), 2, 1);+ CO_SAY(c, s->tb, "ch6_ending", s6_ev, e);+ p->dummy_auto_animate = false;+ spr_play(&p->spr, A_player_bagdown, false);+ cutscene_end(e);+ return;+ CO_END(c);+}+static void granny6e_think(Ent *e) {+ Npc *n = NPC_(e);+ Player *p = level_player();+ if (n->i[0] || !p || !actor_on_ground(p->ent, 1)) return;+ n->i[0] = 1; /* talked */+ Ent *cs = s6_new(ending6_run, ending6_end, false, true);+ if (!cs) return;+ level_register_complete();+ S6_(cs)->a = e, S6_(cs)->b = npc_find(NPC_THEO06_ENDING), S6_(cs)->evs = ending6_nb;+}+static void new_ending_npc(const EData *d, bool theo) {+ Ent *e = npc_new(d->x, d->y, theo ? SB_theo : SB_granny, theo ? A_theo_idle : A_granny_idle, theo ? theo6_think : granny6e_think);+ if (!e) return;+ Npc *n = NPC_(e);+ e->visible = 0;+ n->which = theo ? NPC_THEO06_ENDING : NPC_GRANNY06_ENDING;+ n->idle_anim = theo ? A_theo_idle : A_granny_idle;+ n->move_anim = theo ? A_theo_run : A_granny_walk;+ n->maxspeed = theo ? 72 : 30;+ if (theo) n->move_y = 0, n->gravity = 1;+ else n->spr.sx = -1;+ npc_light(e, -8, 0xFFFFFF, 16, 32);+}++/* ---------------------------------------------------------------- the dream: Bonfire, StarJumpController */+static uint8_t room_hook; /* the next room is room 04, after the dream */+static Ent *bonfire_find(void) { /* the map's bonfire (src/entities.c: a sprite of the campfire bank) */+ for (int i = 0; i < g_nents; i++) {+ Ent *e = &g_ents[i];+ if (e->cls && e->dead != 1 && e->cls->name && !strcmp(e->cls->name, "sprite") && ST(e, Sprite)->bank == SB_campfire) return e;+ }+ return NULL;+}+static void bonfire_mode(Ent *b, int mode, bool activated) { /* Bonfire.SetMode: 0 unlit, 1 lit, 2 smoking */+ if (!b) return;+ bool dream = g_session.dreaming;+ spr_play(ST(b, Sprite), mode == 2 ? A_campfire_smoking+ : mode == 0 ? A_campfire_idle+ : activated ? (dream ? A_campfire_startDream : A_campfire_start)+ : (dream ? A_campfire_burnDream : A_campfire_burn),+ false);+}+/* StarJumpController: the star blocks' fill (rays drifting up, the same from a hash of each ray and its+ * cycle: no table) and the camera kept up while flying */+typedef struct { float t, cam_timer; } SJCtrl;+static void sjctrl_update(Ent *e) {+ SJCtrl *k = ST(e, SJCtrl);+ Player *p = level_player();+ k->t += DT;+ if (!p) return;+ float *oy = &g_level.cam_offset.y;+ if (*oy == -38.4f) {+ if (p->state != ST_STARFLY) {+ if ((k->cam_timer += DT) >= 0.5f) k->cam_timer = 0, *oy = -12.8f;+ } else+ k->cam_timer = 0;+ } else if (p->state == ST_STARFLY) {+ if ((k->cam_timer += DT) >= 0.1f) k->cam_timer = 0, *oy = -38.4f;+ } else+ k->cam_timer = 0;+}+static float fmodp(float x, float m) { return fmodf(fmodf(x, m) + m, m); }+/* the fill: Color.Lerp(Black, LightSkyBlue, 0.3), then 100 rays (a3ffff * 0.25), in every star block crossing the+ * rows: one layer for them all (a frame has 16) */+#define SJ_RECTS 24+static void sjfill_strip(uint16_t *strip, int y0, int y1, void *ctx) {+ const Ent *ce = ctx;+ int16_t r[SJ_RECTS][4];+ int nr = 0, ya = y1, yb = y0;+ for (int i = 0; i < g_nents && nr < SJ_RECTS; i++) { /* the blocks' rectangles in these rows, filled */+ const Ent *b = &g_ents[i];+ if (b->cls != &STARJUMP || b->dead == 1) continue;+ int bx0 = (int)floorf(b->x) - g_camx, by0 = (int)floorf(b->y) - g_camy, bx1 = bx0 + (int)b->cw, by1 = by0 + (int)b->ch;+ int16_t *q = r[nr];+ q[0] = (int16_t)(bx0 > 0 ? bx0 : 0), q[2] = (int16_t)(bx1 < VIEW_W ? bx1 : VIEW_W);+ q[1] = (int16_t)(by0 > y0 ? by0 : y0), q[3] = (int16_t)(by1 < y1 ? by1 : y1);+ if (q[1] >= q[3] || q[0] >= q[2]) continue;+ for (int y = q[1]; y < q[3]; y++)+ for (int x = q[0]; x < q[2]; x++) strip[(y - y0) * VIEW_W + x] = rgb(0x283D4B);+ if (q[1] < ya) ya = q[1];+ if (q[3] > yb) yb = q[3];+ nr++;+ }+ float t = ST(ce, SJCtrl)->t;+ const float vx = -0.09983342f, vy = -0.99500417f; /* AngleToVector(-1.6707964) */+ for (int i = 0; i < 100 && nr; i++) {+ float dur = 4 + hash01(666, (uint32_t)i * 8) * 8, c = t / dur + hash01(666, (uint32_t)i * 8 + 1);+ uint32_t cyc = (uint32_t)c, h = (uint32_t)i * 8 + cyc * 1024;+ float pct = c - cyc, e = ease_cube_inout(yoyo(pct));+ int a = (int)(0.25f * e * 256);+ if (a <= 0) continue;+ float w = 8 + floorf(hash01(667, h) * 72), len = 20 + floorf(hash01(668, h) * 180);+ float rx = hash01(669, h) * 320, ry = hash01(670, h) * 580 + 8 * pct * dur;+ float px = floorf(fmodp(rx - g_level.cam.x * 0.9f, 320)), py = floorf(-200 + fmodp(ry - g_level.cam.y * 0.7f, 580));+ /* the two triangles: the parallelogram p - w2, p - w2 - l, p + w2, p + w2 + l (w2 = (-vy, vx) * w, l = v * len) */+ V2 q[4] = {v2(px + vy * w, py - vx * w), v2(px + vy * w - vx * len, py - vx * w - vy * len), v2(px - vy * w, py + vx * w),+ v2(px - vy * w + vx * len, py + vx * w + vy * len)};+ for (int y = ya; y < yb; y++) {+ float yc = y + 0.5f, xl = 1e9f, xr = -1e9f;+ for (int k = 0; k < 4; k++) {+ V2 p = q[k], o = q[(k + 1) & 3];+ if ((p.y <= yc) == (o.y <= yc)) continue;+ float x = p.x + (yc - p.y) * (o.x - p.x) / (o.y - p.y);+ xl = fminf(xl, x), xr = fmaxf(xr, x);+ }+ if (xl > xr) continue;+ int x0 = (int)ceilf(xl - 0.5f), x1 = (int)ceilf(xr - 0.5f);+ for (int k = 0; k < nr; k++) {+ if (y < r[k][1] || y >= r[k][3]) continue;+ for (int x = x0 > r[k][0] ? x0 : r[k][0]; x < x1 && x < r[k][2]; x++) px_blend(strip, y0, y1, x, y, rgb(0xA3FFFF), a);+ }+ }+ }+}++/* drawn just behind the blocks (depth -9999), before their edges */+static void sjctrl_render(Ent *e) { gfx_custom(sjfill_strip, e, 0, VIEW_H); }+static const EntClass SJCTRL = {.name = "starJumpController", .size = sizeof(SJCtrl), .update = sjctrl_update, .render = sjctrl_render};++/* ---------------------------------------------------------------- NPC06_Theo_Plateau and CS06_Campfire */+enum { Q_OUTFOR, Q_TEMPLE, Q_EXPLAIN, Q_THANKYOU, Q_WHY, Q_DEPRESSION, Q_DEFENSE, Q_VACATION, Q_TRUST, Q_FAMILY, Q_GRANDPA, Q_TIPS,+ Q_SELFIE, Q_SLEEP, Q_SLEEP_CONFIRM, Q_SLEEP_CANCEL };+static const char *const CAMP_Q[16] = {"outfor", "temple", "explain", "thankyou", "why", "depression", "defense", "vacation",+ "trust", "family", "grandpa", "tips", "selfie", "sleep", "sleep_confirm", "sleep_cancel"};+/* each question's portrait (its ask's first): Theo's on the left, Madeline's on the right, and its idle animation */+#define PT(a) (0x80 | A_portrait_theo_idle_##a)+#define PM(a) (A_portrait_madeline_idle_##a)+static const uint8_t CAMP_PORT[16] = {PT(thinking), PT(wtf), PT(wtf), PM(distracted), PM(distracted), PT(serious), PT(wtf),+ PT(thinking), PM(distracted), PM(normal), PM(normal), PM(normal), PM(normal), PM(distracted),+ PM(sad), PM(normal)};+#define QB(n) (1u << Q_##n)+enum { GO_START, GO_SLEEP, GO_END, GO_REPEAT = 0x10 };+typedef struct { uint8_t q, go; uint16_t req, exc; } CampOpt; /* Option: Require, ExcludedBy (all of them), Repeatable */+static const CampOpt CAMP_OPTS[16] = {+ {Q_OUTFOR, GO_START, 0, QB(WHY)}, {Q_TEMPLE, GO_START, QB(TRUST), 0}, {Q_TRUST, GO_START, QB(EXPLAIN), 0},+ {Q_FAMILY, GO_START, QB(TRUST) | QB(WHY), 0}, {Q_GRANDPA, GO_START, QB(FAMILY) | QB(DEFENSE), 0}, {Q_TIPS, GO_START, QB(GRANDPA), 0},+ {Q_EXPLAIN, GO_START, 0, 0}, {Q_THANKYOU, GO_START, QB(EXPLAIN), 0}, {Q_WHY, GO_START, QB(EXPLAIN) | QB(TRUST), 0},+ {Q_DEPRESSION, GO_START, QB(WHY), 0}, {Q_DEFENSE, GO_START, QB(DEPRESSION), 0}, {Q_VACATION, GO_START, QB(DEPRESSION), 0},+ {Q_SELFIE, GO_END, QB(DEFENSE) | QB(GRANDPA), 0}, {Q_SLEEP, GO_SLEEP | GO_REPEAT, QB(WHY), QB(DEFENSE) | QB(GRANDPA)},+ /* "sleep" */+ {Q_SLEEP_CANCEL, GO_START | GO_REPEAT, 0, 0}, {Q_SLEEP_CONFIRM, GO_END, 0, 0}};+#define CAMP_MAX 9+typedef struct {+ S6 s; /* a: Theo, b: the bonfire; v[0] cameraStart, v[1] Theo's and v[2] Madeline's places at the fire */+ Wiggler wig; /* Theo waking up */+ V2 selfie_pos;+ float opt_ease, hl[CAMP_MAX], theo_alarm, selfie_p, selfie_rot, selfie_timer;+ uint16_t asked;+ uint8_t opts[CAMP_MAX], nopts, sel, node, selfie, selfie_wait, q;+ char key[24];+ char text[CAMP_MAX][56]; /* the asks, cleaned once */+} Camp;+#define CAMP(e) ST(e, Camp)+static bool camp_can_ask(const Camp *k, const CampOpt *o) { /* Option.CanAsk */+ if (!(o->go & GO_REPEAT) && (k->asked >> o->q & 1)) return false;+ if ((k->asked & o->req) != o->req) return false;+ return !o->exc || (k->asked & o->exc) != o->exc;+}+static void camp_key(Camp *k, bool answer, int q) { /* ch6_theo_ask_ / ch6_theo_say_ and the question */+ path2(k->key, answer ? "ch6_theo_say_" : "ch6_theo_ask_", CAMP_Q[q], -1);+}+static void camp_options(Camp *k) {+ int from = k->node == GO_SLEEP ? 14 : 0, to = k->node == GO_SLEEP ? 16 : 14;+ k->nopts = 0, k->sel = 0;+ for (int i = from; i < to && k->nopts < CAMP_MAX; i++)+ if (camp_can_ask(k, &CAMP_OPTS[i])) {+ camp_key(k, false, CAMP_OPTS[i].q);+ dialog_clean(k->key, k->text[k->nopts], 56);+ k->hl[k->nopts] = 0;+ k->opts[k->nopts++] = (uint8_t)i;+ }+}+static void camp_selfie_draw(Camp *k) { /* Selfie: the picture (Portraits "selfieCampfire") */+ uint16_t t = T__selfieCampfire;+ Tex tx;+ float w = 0, h = 0;+ if (tex_get(t, &tx)) {+ w = tx.fw * tx.scale, h = tx.fh * tx.scale;+ gfx_tex_ex(t, k->selfie_pos.x / 6, k->selfie_pos.y / 6, w / 2, h / 2, 1, 1, k->selfie_rot, 0xFFFF, 255, 0);+ }+ if (k->selfie_wait && tex_get(T__textboxbutton, &tx))+ gfx_tex_ex(T__textboxbutton, k->selfie_pos.x / 6 + w / 2 + 40 / 6.f, k->selfie_pos.y / 6 + h / 2 + (fmodf(k->selfie_timer, 1) < 0.25f ? 1 : 0),+ tx.fw / 2.f, tx.fh / 2.f, 1, 1, 0, 0xFFFF, 255, 0);+}+static void camp_draw(Ent *e) {+ Camp *k = CAMP(e);+ if (g_level.paused) return;+ gfx_hud(true);+ if (k->selfie) camp_selfie_draw(k);+ for (int i = 0; i < k->nopts; i++) { /* Option.Render at (260, 120 + 160 i) */+ int q = CAMP_OPTS[k->opts[i]].q, port = CAMP_PORT[q];+ bool right = !(port & 0x80);+ float num = ease_cube_out(clampf(k->opt_ease, 0, 1)), hh = ease_cube_inout(k->hl[i]);+ float x = 260 + hh * 32, y = 120 + 160.f * i - 32 * (1 - num);+ int g = (int)(128 + 127 * hh);+ uint16_t box = right ? T__textbox_madeline_ask : T__textbox_theo_ask;+ gfx_tex_ex(box, x / 6, y / 6, 0, 0, 1, 1, 0, rgb((uint32_t)(g << 16 | g << 8 | g)), a8(num), 0);+ Sprite s; /* the portrait, 100 high: its idle animation's first frame (one texture each: the cache is small) */+ spr_init(&s, right ? SB_portrait_madeline : SB_portrait_theo);+ spr_play(&s, port & 0x7F, true);+ uint16_t pt = spr_tex(&s);+ Tex tx;+ int l = (int)(255 * (0.5f + hh * 0.5f));+ if (pt != 0xFFFF && tex_get(pt, &tx)) {+ float ox = s.justify ? tx.fw * tx.scale * s.jx : s.ox, oy = s.justify ? tx.fh * tx.scale * s.jy : s.oy;+ gfx_tex_ex(pt, (x + (right ? 1380 - 50 : 20 + 50)) / 6, (y + 70) / 6, ox, oy, 100 / 240.f, 100 / 240.f, 0,+ rgb((uint32_t)(l << 16 | l << 8 | l)), a8(num), right ? GF_FLIPX : 0);+ }+ float pad = (140 - font_line_height(FONT_S) * 6 * 0.7f) / 2;+ font_draw_justified(k->text[i], (right ? x + 1400 - 20 - pad - 100 : x + 20 + pad + 100) / 6, (y + 70) / 6, right ? 1 : 0, 0.5f,+ FONT_S, 0xFFFF, a8((0.6f + 0.4f * hh) * num));+ }+ gfx_hud(false);+}+static bool camp_nb(void *ctx, Co *c, int i) {+ Camp *k = ctx;+ S6 *s = &k->s;+ Player *p = &g_player;+ Ent *theo = s->a;+ Npc *tn = NPC_(theo);+ NB_BEGIN(c);+ if (i == 0) /* WaitABit */+ NB_WAIT(c, 0.8f);+ else if (i == 2) /* BeerSequence */+ NB_WAIT(c, 0.5f);+ else { /* SelfieSequence */+ s6_zoom(s, v2(160, 105), 0.5f, true);+ NB_WAIT(c, 0.1f);+ spr_play(&tn->spr, A_theo_idle, false);+ k->theo_alarm = 0.25f; /* Alarm: Theo turns */+ p->dummy_auto_animate = true;+ NB_WALK(c, s->walk, walk_mult((int)(theo->x + 5), 0.7f));+ NB_WAIT(c, 0.2f);+ spr_play(&tn->spr, A_theo_takeSelfie, false);+ NB_WAIT(c, 1);+ level_flash(0xFFFF, false); /* Selfie.PictureRoutine("selfieCampfire") */+ k->selfie = 1;+ NB_WAIT(c, 0.5f);+ for (k->selfie_p = 0; k->selfie_p < 1;) { /* OpenRoutine */+ k->selfie_p += DT;+ k->selfie_pos = v2lerp(v2(992, 1080), v2(960, 540), ease_cube_out(k->selfie_p));+ k->selfie_rot = lerpf(0.5f, 0, ease_back_out(k->selfie_p));+ NB_YIELD(c);+ }+ k->selfie_wait = 1; /* WaitForInput */+ while (!menu_confirm() && !btn_pressed(&g_in.back)) NB_YIELD(c);+ k->selfie_wait = 0;+ for (k->selfie_p = 0; k->selfie_p < 1;) { /* EndRoutine */+ k->selfie_p += DT * 2;+ k->selfie_pos = v2lerp(v2(960, 540), v2(928, 0), ease_back_in(k->selfie_p));+ k->selfie_rot = lerpf(0, -0.15f, ease_back_in(k->selfie_p));+ NB_YIELD(c);+ }+ NB_YIELD(c);+ k->selfie = 0;+ NB_WAIT(c, 0.5f);+ step_reset(&s->step);+ NB_NEST(c, zoom_back(&s->step, 0.5f));+ NB_WAIT(c, 0.2f);+ tn->spr.sx = 1;+ NB_WALK(c, s->walk, walk_mult((int)s->v[2].x, 0.7f));+ spr_play(&tn->spr, A_theo_wakeup, false);+ NB_YIELD(c); /* yield return 0.1 (a double): one update */+ p->dummy_auto_animate = false;+ p->facing = -1;+ spr_play(&p->spr, A_player_sleep, false);+ NB_WAIT(c, 2);+ spr_play(&p->spr, A_player_halfWakeUp, false);+ }+ NB_END(c);+}+static bool key_edge(uint32_t k) { return (g_in.keys & ~g_in.prev & k) != 0; }+static void camp_run(Ent *e) {+ Camp *k = CAMP(e);+ S6 *s = &k->s;+ Player *p = &g_player;+ Ent *theo = s->a;+ Npc *tn = NPC_(theo);+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ CO_WAIT(c, 0.1f);+ /* PlayerLightApproach: the player's light is the engine's */+ s6_cam(s, v2(g_level.cam.x + 90, g_level.cam.y), 6, ease_cube_in, 0, false);+ p->dummy_auto_animate = false;+ spr_play(&p->spr, A_player_carryTheoWalk, false);+ for (s->f[0] = 0; s->f[0] < 3.5f; s->f[0] += DT) {+ g_wipe.focus = v2(40, 120); /* SpotlightWipe.FocusPoint */+ p->ent->x += 32 * DT; /* NaiveMove */+ CO_YIELD(c);+ }+ spr_play(&p->spr, A_player_carryTheoCollapse, false);+ CO_WAIT(c, 0.3f);+ particles_emit(PL_FG, &P_Payphone_P_Snow, 2, v2(p->ent->x + 16, p->ent->y + 1), v2(4, 0), P_Payphone_P_Snow.direction);+ particles_emit(PL_FG, &P_Payphone_P_SnowB, 12, v2(p->ent->x + 16, p->ent->y + 1), v2(10, 0), P_Payphone_P_SnowB.direction);+ CO_WAIT(c, 0.7f);+ fade_wipe(false, 1.5f, NULL);+ g_wipe.end_timer = 2.5f;+ CO_NEST(c, wipe_busy());+ bonfire_mode(s->b, 1, true);+ CO_WAIT(c, 2.45f);+ s->cam_on = 0; /* camTo.Cancel() */+ theo->x = s->v[1].x, theo->y = s->v[1].y;+ spr_play(&tn->spr, A_theo_sleep, false);+ sprite_set_frame(&tn->spr, spr_frames(&tn->spr) - 1);+ p->ent->x = s->v[2].x, p->ent->y = s->v[2].y;+ p->facing = -1;+ spr_play(&p->spr, A_player_asleep, false);+ level_set_flag("starsbg", true);+ level_set_flag("duskbg", false);+ wipe_start(WIPE_FADE, true, NULL); /* fade.EndTimer = 0; new FadeWipe(level, true) */+ CO_YIELD(c);+ zoom_reset();+ g_level.cam = v2(s->b->x - 160, s->b->y - 140);+ CO_WAIT(c, 3);+ CO_WAIT(c, 1.5f);+ wiggler_init(&k->wig, 0.6f, 3);+ wiggler_restart(&k->wig);+ particles_emit(PL_MID, &P_NPC01_Theo_P_YOLO, 4, v2(theo->x - 4, theo->y - 14), v2(3, 3), P_NPC01_Theo_P_YOLO.direction);+ CO_WAIT(c, 0.5f);+ spr_play(&tn->spr, A_theo_wakeup, false);+ CO_WAIT(c, 1);+ spr_play(&p->spr, A_player_halfWakeUp, false);+ CO_WAIT(c, 0.25f);+ CO_SAY(c, s->tb, "ch6_theo_intro", NULL, NULL);+ k->node = GO_START;+ while (k->node != GO_END) {+ camp_options(k);+ if (!k->nopts) break;+ while ((k->opt_ease += DT * 4) < 1) CO_YIELD(c);+ k->opt_ease = 1;+ CO_WAIT(c, 0.25f);+ while (!menu_confirm()) {+ if (key_edge(K_UP) && k->sel > 0) k->sel--;+ else if (key_edge(K_DOWN) && k->sel < k->nopts - 1) k->sel++;+ CO_YIELD(c);+ }+ while ((k->opt_ease -= DT * 4) > 0) CO_YIELD(c);+ {+ const CampOpt *o = &CAMP_OPTS[k->opts[k->sel]];+ k->asked |= (uint16_t)(1u << o->q);+ k->node = o->go & 15;+ k->nopts = 0; /* currentOptions = null */+ camp_key(k, true, o->q);+ }+ CO_SAY(c, s->tb, k->key, s6_ev, e);+ }+ fade_wipe(false, 3, NULL);+ CO_NEST(c, wipe_busy());+ cutscene_end(e);+ return;+ CO_END(c);+}+static void camp_update(Ent *e) {+ Camp *k = CAMP(e);+ Npc *tn = NPC_(k->s.a);+ for (int i = 0; i < k->nopts; i++) k->hl[i] = approach(k->hl[i], i == k->sel ? 1 : 0, DT * 4);+ if (k->selfie_wait) k->selfie_timer += DT;+ if (k->theo_alarm > 0 && (k->theo_alarm -= DT) <= 0) tn->spr.sx = -1;+ if (k->wig.active) {+ wiggler_update(&k->wig);+ tn->spr.sx = tn->spr.sy = 1 + 0.1f * k->wig.value;+ }+ s6_update(e);+}+static const EntClass CAMPFIRE = {.name = "cutscene6", .size = sizeof(Camp), .update = camp_update, .render = s6_render};+static void sjend_wait_new(Ent *theo, V2 player_start, V2 cam_start, bool zoom_back);+static void camp_end(Ent *e, bool skipped) {+ Camp *k = CAMP(e);+ S6 *s = &k->s;+ Player *p = &g_player;+ Ent *theo = s->a;+ Npc *tn = NPC_(theo);+ Room *rm = g_level.room;+ if (!skipped) { /* a 3 s fade in, the zoom going back with it */+ zoom_snap(v2(160, 120), 2);+ fade_wipe(true, 3, NULL);+ }+ k->selfie = 0;+ level_set_flag("campfire_chat", true);+ level_set_flag("starsbg", false);+ level_set_flag("duskbg", false);+ g_session.dreaming = 1;+ Ent *ce = ent_new(&SJCTRL, 0, 0);+ if (ce) ce->collidable = 0, ce->depth = -9999;+ sjend_wait_new(theo, s->v[2], s->v[0], !skipped);+ feather_new(rm->x + 272.f, rm->y + 2616.f, false, false);+ bonfire_mode(s->b, 1, false);+ spr_play(&tn->spr, A_theo_sleep, false);+ sprite_set_frame(&tn->spr, spr_frames(&tn->spr) - 1);+ tn->spr.sx = tn->spr.sy = 1;+ theo->x = s->v[1].x, theo->y = s->v[1].y;+ spr_play(&p->spr, A_player_asleep, false);+ p->ent->x = s->v[2].x, p->ent->y = s->v[2].y;+ p->state_locked = false;+ player_set_state(p, skipped ? ST_NORMAL : ST_INTROWAKEUP);+ p->speed = v2(0, 0);+ p->facing = -1;+ g_level.cam = player_camera_target(p);+}+static void camp_begin(Ent *theo) { /* CS06_Campfire.OnBegin, from Theo's Awake */+ Player *p = level_player();+ Ent *bon = bonfire_find();+ if (!p || !bon) return;+ Ent *e = scene_new(&CAMPFIRE, camp_end, true, false);+ if (!e) return;+ e->tags |= TAG_HUD;+ Camp *k = CAMP(e);+ S6 *s = &k->s;+ Room *rm = g_level.room;+ s->run = camp_run, s->draw = camp_draw, s->evs = camp_nb, s->ev_i = -1;+ s->a = theo, s->b = bon;+ level_set_flag("duskbg", true);+ g_level.cam = v2((float)rm->x, bon->y - 144);+ zoom_snap(v2(80, 120), 2);+ s->v[0] = g_level.cam;+ theo->x = g_level.cam.x - 48;+ s->v[1] = v2(bon->x - 16, bon->y);+ p->ent->x = rm->x - 40.f;+ player_dummy(p);+ s->v[2] = v2(bon->x + 20, bon->y);+ if (level_get_flag("campfire_chat")) {+ k->s.cs.skipped = true;+ zoom_reset();+ cutscene_end(e);+ }+}+static void theo6p_think(Ent *e) {+ Npc *n = NPC_(e);+ if (!n->i[0] && level_player()) n->i[0] = 1, camp_begin(e);+}+static void new_theo6p(const EData *d) {+ Ent *e = npc_new(d->x, d->y, SB_theo, A_theo_idle, theo6p_think);+ if (!e) return;+ Npc *n = NPC_(e);+ n->which = NPC_THEO06_PLATEAU;+ n->idle_anim = A_theo_idle, n->move_anim = A_theo_walk, n->maxspeed = 48, n->move_y = 0, n->gravity = 1;+ npc_light(e, -6, 0xFFFFFF, 16, 48);+}++/* ---------------------------------------------------------------- CS06_StarJumpEnd */+/* S6: a Theo, bd Badeline, tb the textbox; v[0] playerStart, v[1] cameraStart, v[2] the cutscene's center;+ * f[0] maddySine, f[1] its target, f[2] its anchor, f[3] a loop's, f[4] the spin's timer; i: what goes beside it+ * (0 the camera, 1 the spin, 2 the circling), j: tentacles made, k: flags (1 waiting, 2 shaking, 4 zoom back,+ * 8 circling, 16 spinning, 32 flying down) */+typedef struct {+ S6 s;+ Ent *breath, *tent[4];+ V2 from, to, start, target, tw_from, tw_to;+ float tw; /* StartCirclingPlayer's Tween, -1 none */+} SJEnd;+#define SJE(e) ST(e, SJEnd)+static void tent_nodes(SJEnd *k, float y0, float y1, bool snap) {+ float cx = g_level.room->x + g_level.room->w / 2.f;+ for (int i = 0; i < k->s.j; i++) {+ Ent *t = k->tent[i];+ if (!t || t->cls != &TENTACLES || t->dead == 1) continue;+ Tentacles *tt = ST(t, Tentacles);+ if (snap) tt->index = 0;+ tt->nodes[0][0] = tt->nodes[1][0] = (int16_t)cx;+ tt->nodes[0][1] = (int16_t)(g_player.ent->y + y0), tt->nodes[1][1] = (int16_t)(g_player.ent->y + y1);+ if (snap) tent_snap(tt, NULL);+ }+}+static bool sjend_par(void *ctx, Co *c) {+ SJEnd *k = ctx;+ S6 *s = &k->s;+ Player *p = &g_player;+ Ent *bd = s->bd;+ if (s->i == 0) { /* the two camera moves: (-160, -70) in 1.5 s, then (-160, -120) in 2 s */+ NB_BEGIN(c);+ step_reset(&s->cam);+ NB_NEST(c, camera_to(&s->cam, v2add(s->v[2], v2(-160, -70)), 1.5f, ease_cube_out));+ step_reset(&s->cam);+ NB_NEST(c, camera_to(&s->cam, v2add(s->v[2], v2(-160, -120)), 2, ease_cube_inout));+ NB_END(c);+ }+ if (s->i == 1) { /* SpinCharacters */+ NB_BEGIN(c);+ k->start = v2(p->ent->x, p->ent->y), k->target = v2(bd->x, bd->y);+ k->from = v2mul(v2add(k->start, k->target), 0.5f);+ s->f[5] = fabsf(k->start.x - k->from.x);+ s->f[4] = PI_F / 2;+ spr_play(&p->spr, A_player_spin, false);+ spr_play(&BD(bd)->spr, A_badeline_spin, false);+ BD(bd)->spr.sx = 1;+ while (s->k & 16) {+ int n = (int)(s->f[4] / (PI_F * 2) * 14 + 10);+ sprite_set_frame(&p->spr, n);+ bd_set_frame(bd, n + 7);+ float sn = sinf(s->f[4]), cs = cosf(s->f[4]);+ p->ent->x = k->from.x - sn * s->f[5], p->ent->y = k->from.y - cs * 8;+ bd->x = k->from.x + sn * s->f[5], bd->y = k->from.y + cs * 8;+ s->f[4] += DT * 2;+ NB_YIELD(c);+ }+ p->facing = 1;+ spr_play(&p->spr, A_player_fallSlow, false);+ BD(bd)->spr.sx = -1;+ spr_play(&BD(bd)->spr, A_badeline_angry, false);+ BD(bd)->auto_enabled = 0;+ k->from = v2(p->ent->x, p->ent->y), k->to = v2(bd->x, bd->y);+ for (s->f[4] = 0; s->f[4] < 1; s->f[4] += DT * 3) {+ V2 a = v2lerp(k->from, k->start, ease_cube_out(s->f[4])), b = v2lerp(k->to, k->target, ease_cube_out(s->f[4]));+ p->ent->x = a.x, p->ent->y = a.y, bd->x = b.x, bd->y = b.y;+ NB_YIELD(c);+ }+ NB_END(c);+ }+ NB_BEGIN(c); /* BadelineCirclePlayer */+ s->f[4] = 0;+ s->f[5] = v2len(v2sub(v2(bd->x, bd->y), v2(p->ent->x, p->ent->y)));+ s->k |= 8;+ while (s->k & 8) {+ s->f[4] -= DT * 4;+ s->f[5] = approach(s->f[5], 24, DT * 32);+ {+ V2 at = v2add(v2(p->ent->x, p->ent->y), angle_vec(s->f[4], s->f[5]));+ bd->x = at.x, bd->y = at.y;+ int sg = sgn(p->ent->x - bd->x);+ if (sg) BD(bd)->spr.sx = (float)sg;+ if ((int)((g_level.time_active - DT) / 0.1f) < (int)(g_level.time_active / 0.1f)) { /* OnInterval: TrailManager.Add */+ Sprite *sp = &BD(bd)->spr;+ trail_add(floorf(bd->x), floorf(bd->y), spr_tex(sp), sp->ox, sp->oy, sp->sx, sp->sy, 0xAC3232, 1);+ }+ }+ NB_YIELD(c);+ }+ BD(bd)->spr.sx = -1;+ bd_float_to(bd, v2(p->ent->x + 40, p->ent->y - 16), -1, false, false, false);+ NB_AWAIT(c, &BD(bd)->job);+ NB_END(c);+}+static bool sjend_nb(void *ctx, Co *c, int i) {+ SJEnd *k = ctx;+ S6 *s = &k->s;+ Player *p = &g_player;+ Ent *bd = s->bd;+ NB_BEGIN(c);+ if (i == 0) { /* TentaclesAppear (the northern lights going down are the backdrop's) */+ level_shake(0.3f);+ if (s->j < 4) {+ int16_t nodes[2][2] = {{(int16_t)(g_level.cam.x + 160), (int16_t)(g_level.cam.y + 400)},+ {(int16_t)(g_level.cam.x + 160), (int16_t)(g_level.cam.y + 600)}};+ Ent *t = tent_create(nodes, 2, 0, 0, s->j);+ if (t) {+ Tentacles *tt = ST(t, Tentacles);+ tt->nodes[0][1] = (int16_t)(g_level.cam.y + 140);+ }+ k->tent[s->j++] = t;+ }+ s->k &= (uint8_t)~16; /* charactersSpinning = false */+ spr_play(&BD(bd)->spr, A_badeline_angry, false);+ s->f[1] = 1;+ NB_YIELD(c);+ } else if (i == 1) { /* TentaclesGrab (BreathingRumbler: rumble only) */+ s->f[1] = 0;+ spr_play(&p->spr, A_player_tentacle_grab, false);+ NB_WAIT(c, 0.1f);+ level_shake(0.3f);+ } else if (i == 2) { /* FeatherMinigame */+ k->breath = breath_new(false);+ while (!breath_done(k->breath) && !breath_pausing(k->breath)) NB_YIELD(c);+ } else if (i == 3) { /* EndFeatherMinigame */+ s->k &= (uint8_t)~8;+ breath_resume(k->breath);+ while (!breath_done(k->breath)) NB_YIELD(c);+ k->breath = NULL;+ } else { /* StartCirclingPlayer */+ memset(&s->pco, 0, sizeof s->pco);+ s->i = 2, s->par_on = 1;+ k->tw_from = v2(p->ent->x, p->ent->y); /* Tween.Set(0.5, CubeOut) */+ k->tw_to = v2(g_level.room->x + g_level.room->w / 2.f, p->ent->y);+ k->tw = 0;+ NB_YIELD(c);+ }+ NB_END(c);+}+static void sjend_run(Ent *e) {+ SJEnd *k = SJE(e);+ S6 *s = &k->s;+ Player *p = &g_player;+ Room *rm = g_level.room;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ {+ Ent *ce = first_of(&SJCTRL);+ if (ce) ent_remove(ce);+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &STARJUMP) g_ents[i].collidable = 0;+ }+ s->v[2] = v2(rm->x + 160.f, rm->y + 150.f);+ g_level.cam_offset.y = -30;+ memset(&s->pco, 0, sizeof s->pco);+ s->i = 0, s->par_on = 2; /* the camera moves (NorthernLights' OffsetY tween is the backdrop's) */+ p->dashes = 0;+ player_set_state(p, ST_DUMMY);+ p->dummy_gravity = false;+ p->dummy_auto_animate = false;+ spr_play(&p->spr, A_player_fallSlow, false);+ p->dashes = 1;+ p->speed = v2(0, -80);+ p->facing = 1;+ p->force_camera_update = false;+ while (v2len(p->speed) > 0 || !v2eq(v2(p->ent->x, p->ent->y), s->v[2])) {+ p->speed = approach_v(p->speed, v2(0, 0), 200 * DT);+ {+ V2 at = approach_v(v2(p->ent->x, p->ent->y), s->v[2], 64 * DT);+ p->ent->x = at.x, p->ent->y = at.y;+ }+ CO_YIELD(c);+ }+ spr_play(&p->spr, A_player_spin, false);+ CO_WAIT(c, 3.5f);+ p->facing = 1;+ s->bd = bd_new(v2(p->ent->x, p->ent->y));+ if (!s->bd) {+ cutscene_end(e);+ return;+ }+ particles_emit(PL_MID, &P_Player_P_Split, 16, player_center(p), v2(6, 6), P_Player_P_Split.direction); /* CreateSplitParticles */+ BD(s->bd)->spr.sx = -1;+ k->start = v2(p->ent->x, p->ent->y);+ k->target = v2add(s->v[2], v2(-30, 0));+ s->f[2] = s->v[2].y;+ for (s->f[3] = 0; s->f[3] <= 1; s->f[3] += 2 * DT) {+ CO_YIELD(c);+ if (s->f[3] > 1) s->f[3] = 1;+ {+ V2 a = v2lerp(k->start, k->target, ease_cube_out(s->f[3]));+ p->ent->x = a.x, p->ent->y = a.y;+ s->bd->x = s->v[2].x + (s->v[2].x - a.x), s->bd->y = a.y;+ }+ }+ s->k |= 16; /* SpinCharacters */+ memset(&s->pco, 0, sizeof s->pco);+ s->i = 1, s->par_on = 2;+ CO_WAIT(c, 1);+ CO_SAY(c, s->tb, "ch6_dreaming", s6_ev, e);+ /* BadelineFlyDown */+ spr_play(&BD(s->bd)->spr, A_badeline_fallFast, false);+ BD(s->bd)->float_speed = 600, BD(s->bd)->float_accel = 1200;+ bd_float_to(s->bd, v2(s->bd->x, g_level.cam.y + 200), 0, true, true, false);+ s->k |= 32;+ CO_WAIT(c, 0.7f);+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o->cls == &FEATHER || o->cls == &STARJUMP || (o->cls && o->cls->name && !strcmp(o->cls->name, "jumpThru"))) ent_remove(o);+ }+ level_shake(0.3f);+ g_level.cam_offset.y = 0;+ spr_play(&p->spr, A_player_tentacle_pull, false);+ p->speed.y = 160;+ /* FallEffects is not in the engine */+ for (s->f[3] = 0; s->f[3] < 1; s->f[3] += DT / 3) {+ p->speed.y += DT * 100;+ p->ent->x = clampf(p->ent->x, rm->x + 32.f, rm->x + rm->w - 32.f);+ if (s->f[3] > 0.7f) g_level.cam_offset.y -= 100 * DT;+ tent_nodes(k, 300, 600, false);+ CO_YIELD(c);+ }+ level_flash(0xFFFF, false); /* (the bloom is not drawn) */+ g_session.dreaming = 0;+ g_level.cam_offset.y = 0;+ g_level.cam = s->v[1];+ bonfire_mode(bonfire_find(), 2, true);+ {+ Ent *pl = first_of(&PLATEAU);+ if (pl) pl->depth = (int16_t)(p->ent->depth + 10);+ }+ p->ent->x = s->v[0].x, p->ent->y = s->v[0].y + 8;+ p->speed = v2(0, 0);+ spr_play(&p->spr, A_player_tentacle_dangling, false);+ p->facing = -1;+ if (s->a) {+ s->a->x -= 24;+ spr_play(&NPC_(s->a)->spr, A_theo_alert, false);+ }+ tent_nodes(k, 32, 400, true);+ s->k |= 2; /* shaking */+ CO_SAY(c, s->tb, "ch6_theo_watchout", NULL, NULL);+ s->k &= (uint8_t)~2;+ {+ Ent *pl = first_of(&PLATEAU);+ if (pl) {+ V2 from = v2(pl->x + 8 + 52, pl->y + 2 + 8); /* the plateau's center, 8 lower */+ for (int x = 0; x < 104; x += 8)+ for (int n = 0; n < 2; n++) level_debris(pl->x + 8 + x + rndf() * 8, pl->y + rndf() * 8, '3', from);+ ent_remove(pl);+ }+ Ent *bon = bonfire_find();+ if (bon) ent_remove(bon);+ }+ level_shake(0.3f);+ p->speed.y = 160;+ spr_play(&p->spr, A_player_tentacle_pull, false);+ p->force_camera_update = false;+ fade_wipe(false, 3, NULL);+ k->target = g_level.cam;+ k->start = v2add(g_level.cam, v2(0, 400));+ while (g_wipe.active && g_wipe.percent < 1) {+ g_level.cam = v2lerp(k->target, k->start, ease_cube_in(g_wipe.percent));+ p->speed.y += 400 * DT;+ tent_nodes(k, 300, 600, false);+ CO_YIELD(c);+ }+ cutscene_end(e); /* the wipe's onComplete */+ return;+ CO_END(c);+}+static void sjend_end(Ent *e, bool skipped) {+ SJEnd *k = SJE(e);+ breath_remove(k->breath);+ level_set_flag("plateau_2", true);+ g_session.dreaming = 0;+ g_session.first_level = 0;+ /* OverworldReflectionsFall (the mountain) is not here: straight to room 04, falling in (at the spawn nearest+ * its top middle, the background fading in); skipped: room 00 */+ int r = chapter_find_room(g_level.chapter, skipped ? "00" : "04");+ room_hook = !skipped;+ if (r >= 0) level_load_room_near(r, skipped ? INTRO_NONE : INTRO_FALL, skipped ? 0 : 0.5f, skipped ? 1 : 0);+}+static void sjend_update(Ent *e) {+ SJEnd *k = SJE(e);+ S6 *s = &k->s;+ Player *p = level_player();+ if (s->k & 4) { /* the campfire's end: Level.ZoomBack with the fade in */+ if (!zoom_back(&s->zoom, 3)) s->k &= (uint8_t)~4;+ }+ if (s->k & 1) {+ if (p && p->ent->y <= g_level.room->y + 160) { /* Start() */+ s->k &= (uint8_t)~1;+ cutscene_start(e, sjend_end, true, false);+ }+ return;+ }+ if (k->tw >= 0 && p) {+ k->tw = fminf(1, k->tw + DT / 0.5f);+ V2 a = v2lerp(k->tw_from, k->tw_to, ease_cube_out(k->tw));+ p->ent->x = a.x, p->ent->y = a.y;+ if (k->tw >= 1) k->tw = -1;+ }+ s6_update(e);+ if (e->dead == 1) return;+ if ((s->k & 32) && s->bd && !job_busy(&BD(s->bd)->job)) { /* flown down: badeline.RemoveSelf() */+ s->k &= (uint8_t)~32;+ ent_remove(s->bd);+ s->bd = NULL;+ }+ if (s->k & 2) level_shake(0.2f);+ /* Distort.Anxiety is not drawn */+ s->f[0] = approach(s->f[0], s->f[1], 12 * DT);+ if (s->f[0] > 0 && p) p->ent->y = s->f[2] + sinf(g_level.time_active * 2) * 3 * s->f[0];+}+static const EntClass SJEND = {.name = "cutscene6", .size = sizeof(SJEnd), .update = sjend_update};+static void sjend_wait_new(Ent *theo, V2 player_start, V2 cam_start, bool zoom_back_) {+ Ent *e = ent_new(&SJEND, 0, 0);+ if (!e) return;+ e->collidable = 0, e->visible = 0, e->depth = 10100;+ SJEnd *k = SJE(e);+ S6 *s = &k->s;+ s->run = sjend_run, s->evs = sjend_nb, s->par = sjend_par, s->ev_i = -1;+ s->a = theo, s->v[0] = player_start, s->v[1] = cam_start;+ s->k = 1 | (zoom_back_ ? 4 : 0);+ k->tw = -1;+ step_reset(&s->zoom);+}++/* ---------------------------------------------------------------- after the dream: the next room's start */+typedef struct { float delay, p; } BgFade;+static void bgfade_update(Ent *e) { /* BackgroundFadeIn(Black, 2, 30) */+ BgFade *f = ST(e, BgFade);+ if (f->delay > 0) f->delay -= DT;+ else if ((f->p += DT / 30) >= 1) ent_remove(e);+}+static void bgfade_render(Ent *e) { gfx_rect(g_level.cam.x - 10, g_level.cam.y - 10, 340, 200, 0, a8(1 - ST(e, BgFade)->p)); }+static const EntClass BGFADE = {.name = "backgroundFadeIn", .size = sizeof(BgFade), .update = bgfade_update, .render = bgfade_render};+/* ---------------------------------------------------------------- EventTrigger */+typedef struct { uint8_t which, triggered; } Event6;+static void event6_enter(Ent *e, Player *p) {+ Event6 *ev = ST(e, Event6);+ (void)p;+ if (ev->triggered) return;+ ev->triggered = 1;+ float cx = e->x + e->cx + e->cw / 2;+ Ent *boss = first_of(&BOSS), *cs;+ if (ev->which == 0) { /* ch6_boss_intro */+ if (level_get_flag("boss_intro") || !boss || !(cs = s6_new(bintro_run, bintro_end, true, false))) return;+ S6 *s = S6_(cs);+ s->a = boss, s->evs = bintro_nb;+ s->f[0] = boss->y - 16, s->f[3] = cx;+ } else if (!level_get_flag("reflection") && (cs = s6_new(reflect6_run, reflect6_end, true, false))) /* ch6_reflect */+ S6_(cs)->f[0] = cx - 5;+}+static const EntClass EVENT6 = {.name = "eventTrigger", .size = sizeof(Event6), .on_enter = event6_enter, .kind = KIND_TRIGGER};+static bool new_event6(const EData *d) {+ const char *ev = EAS(d, eventTrigger, event);+ int which = !strcmp(ev, "ch6_boss_intro") ? 0 : !strcmp(ev, "ch6_reflect") ? 1 : -1;+ if (which < 0) return false;+ Ent *e = ent_new(&EVENT6, d->x, d->y);+ if (e) ent_box(e, EA(d, eventTrigger, width), EA(d, eventTrigger, height), 0, 0), e->visible = 0, ST(e, Event6)->which = (uint8_t)which;+ return true;+}++/* ---------------------------------------------------------------- factories */+bool ents_ch6(const EData *d) {+ if (room_hook) { /* the room after the dream (CS06_StarJumpEnd): the background fades in */+ room_hook = 0;+ Ent *f = ent_new(&BGFADE, 0, 0);+ if (f) f->depth = 10100, f->collidable = 0, f->tags = TAG_PERSISTENT | TAG_TRANSITION_UPDATE, ST(f, BgFade)->delay = 2;+ }+ switch (d->type) {+ case ET_bigSpinner: new_bumper(d); return true;+ case ET_infiniteStar: new_feather(d); return true;+ case ET_starJumpBlock: new_starjump(d); return true;+ case ET_plateau: new_plateau(d); return true;+ case ET_crushBlock: new_kevin(d); return true;+ case ET_bigWaterfall: new_waterfall(d); return true;+ case ET_badelineBoost: new_bboost(d); return true;+ case ET_reflectionHeartStatue: new_hstatue(d); return true;+ case ET_finalBoss: new_boss(d); return true;+ case ET_finalBossFallingBlock: new_bfall(d); return true;+ case ET_finalBossMovingBlock: new_bmove(d); return true;+ case ET_tentacles: new_tentacles(d); return true;+ case ET_npc: {+ const char *who = EAS(d, npc, npc);+ if (!strcmp(who, "granny_06_intro")) new_granny6(d);+ else if (!strcmp(who, "theo_06_plateau")) new_theo6p(d);+ else if (!strcmp(who, "badeline_06_crying")) new_crying(d);+ else if (!strcmp(who, "granny_06_ending") || !strcmp(who, "theo_06_ending")) new_ending_npc(d, who[0] == 't');+ else return false;+ return true;+ }+ default: return false;+ }+}+bool trigs_ch6(const EData *d) {+ switch (d->type) {+ case TT_lookoutBlocker: new_lookout_blocker(d); return true;+ case TT_eventTrigger: return new_event6(d);+ default: return false;+ }+}diff --git a/games/celeste/src/ch7.c b/games/celeste/src/ch7.cnew file mode 100644index 00000000..61c49032--- /dev/null+++ b/games/celeste/src/ch7.c@@ -0,0 +1,1794 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* The Summit (chapter 7): its checkpoints (with their confetti), the summit+ * gems and the gem manager, the clouds, the ascent from one part of the+ * mountain to the next (AscendManager, CS07_Ascend, HeightDisplay), the+ * summit (CS07_Ending), the credits that follow it (CS07_Credits), and Granny+ * at the end of the C-side. Line by line from the game's code. */+#include "badeline.h"++static V2 shake_vec(void) { return v2((float)(rndi(3) - 1), (float)(rndi(3) - 1)); } /* Calc.Random.ShakeVector */+static void draw_centered(uint16_t tex, float x, float y, uint16_t tint, uint8_t alpha, float sx, float sy, float rot) {+ Tex t;+ if (tex == 0xFFFF || !tex_get(tex, &t)) return;+ gfx_tex_ex(tex, x, y, t.fw * t.scale / 2.f, t.fh * t.scale / 2.f, sx, sy, rot, tint, alpha, 0);+}+static Room *room(void) { return g_level.room; }+static void split_particles(Player *p) { /* Player.CreateSplitParticles */+ particles_emit(PL_MID, &P_Player_P_Split, 16, player_center(p), v2(6, 6), P_Player_P_Split.direction);+}++/* ---------------------------------------------------------------- SummitCheckpoint and its confetti */+#define CONFETTI 30+typedef struct { V2 pos, speed; float timer, percent, approach; uint8_t color, duration; } Confetto;+typedef struct { Confetto p[CONFETTI]; } Confetti;+static const uint32_t CONFETTI_COLORS[3] = {0xFE2074, 0x205EFE, 0xCEFE20};+static void confetti_update(Ent *e) {+ Confetti *c = ST(e, Confetti);+ bool live = false;+ for (int i = 0; i < CONFETTI; i++) {+ Confetto *p = &c->p[i];+ p->pos = v2add(p->pos, v2mul(p->speed, DT));+ p->speed.x = approach(p->speed.x, 0, 80 * DT);+ p->speed.y = approach(p->speed.y, 20, 500 * DT);+ p->timer += DT;+ p->percent += DT / p->duration;+ if (p->speed.y > 0) p->approach = approach(p->approach, 5, DT * 16);+ live |= p->percent < 1;+ }+ if (!live) ent_remove(e); /* (every one gone: alpha 0) */+}+static void confetti_render(Ent *e) { /* particles/confetti (4 x 1) as a line, turned */+ Confetti *c = ST(e, Confetti);+ for (int i = 0; i < CONFETTI; i++) {+ Confetto *p = &c->p[i];+ float ang, alpha = clamped_map(p->percent, 0.9f, 1, 1, 0);+ V2 at = p->pos;+ if (p->speed.y < 0) ang = atan2f(p->speed.y, p->speed.x);+ else {+ ang = sinf(p->timer * 4);+ at = v2add(at, angle_vec(PI_F / 2 + ang, p->approach));+ }+ if (alpha <= 0) continue;+ V2 d = angle_vec(ang, 1.5f);+ gfx_line(at.x - d.x, at.y + 1 - d.y, at.x + d.x, at.y + 1 + d.y, 0, a8(alpha * 0.5f));+ gfx_line(at.x - d.x, at.y - d.y, at.x + d.x, at.y + d.y, rgb(CONFETTI_COLORS[p->color]), a8(alpha));+ }+}+static const EntClass CONFETTI_CLS = {.name = "confettiRenderer", .size = sizeof(Confetti), .update = confetti_update, .render = confetti_render};+static void confetti_new(V2 at) {+ Ent *e = ent_new(&CONFETTI_CLS, at.x, at.y);+ if (!e) return;+ e->depth = -10010;+ e->collidable = 0;+ Confetti *c = ST(e, Confetti);+ for (int i = 0; i < CONFETTI; i++) {+ Confetto *p = &c->p[i];+ p->pos = v2add(at, v2((float)(rndi(6) - 3), (float)(rndi(6) - 3)));+ p->color = (uint8_t)rndi(3);+ p->timer = rndf();+ p->duration = (uint8_t)(2 + rndi(2));+ p->speed = angle_vec(-PI_F / 2 + rnd_rangef(-0.5f, 0.5f), (float)(140 + rndi(80)));+ }+}++typedef struct { V2 respawn; uint8_t number, active; } SCheck;+static void scheck_flag(char *f, int n) {+ path2(f, "summit_checkpoint_", NULL, -1);+ char *o = f + strlen(f);+ if (n >= 10) *o++ = (char)('0' + n / 10);+ *o++ = (char)('0' + n % 10), *o = 0;+}+static void scheck_activate(Ent *e, bool hit) {+ SCheck *c = ST(e, SCheck);+ char f[24];+ c->active = 1;+ scheck_flag(f, c->number);+ level_set_flag(f, true);+ g_session.rx = (int32_t)c->respawn.x, g_session.ry = (int32_t)c->respawn.y, g_session.has_respawn = 1;+ if (!hit) return;+ g_session.dashes_at_level_start = g_session.dashes; /* UpdateLevelStartDashes, HitCheckpoint */+ g_session.hit_checkpoint = 1;+ confetti_new(v2(e->x, e->y)); /* (the displacement burst is not drawn) */+}+static void scheck_awake(Ent *e) {+ Player *p = level_player();+ if (!ST(e, SCheck)->active && p && collide_ent_at(e, e->x, e->y, p->ent)) scheck_activate(e, false);+}+static void scheck_update(Ent *e) {+ Player *p = level_player();+ if (!ST(e, SCheck)->active && p && !p->dead && collide_ent_at(e, e->x, e->y, p->ent) && p->on_ground && p->speed.y >= 0)+ scheck_activate(e, true);+}+static void scheck_render(Ent *e) {+ SCheck *c = ST(e, SCheck);+ uint16_t base = c->active ? T_scenery_summitcheckpoints_base02+ : fmodf(g_level.time_active, 0.5f) > 0.25f ? T_scenery_summitcheckpoints_base00 : T_scenery_summitcheckpoints_base01;+ uint16_t num = c->active ? T_scenery_summitcheckpoints_number00 : T_scenery_summitcheckpoints_numberbg00;+ Tex t;+ if (tex_get(base, &t)) gfx_tex(base, e->x - (t.fw / 2 + 1), e->y - t.fh / 2, 0, 0xFFFF, 255);+ gfx_tex((uint16_t)(num + c->number / 10 % 10), e->x - 4, e->y + 1, 0, 0xFFFF, 255); /* justified (1, 0) and (0, 0) */+ gfx_tex((uint16_t)(num + c->number % 10), e->x, e->y + 1, 0, 0xFFFF, 255);+}+static const EntClass SCHECK = {.name = "summitcheckpoint", .size = sizeof(SCheck), .update = scheck_update, .render = scheck_render,+ .awake = scheck_awake};+static void new_scheck(const EData *d) {+ Ent *e = ent_new(&SCHECK, d->x, d->y);+ if (!e) return;+ ent_box(e, 32, 32, -16, -8);+ e->depth = 8999;+ SCheck *c = ST(e, SCheck);+ c->number = (uint8_t)EA(d, summitcheckpoint, number);+ char f[24];+ scheck_flag(f, c->number);+ c->active = level_get_flag(f);+ c->respawn = level_closest_spawn(v2(d->x, d->y));+}++/* ---------------------------------------------------------------- SummitGem */+static const uint32_t GEM_COLORS[6] = {0x9EE9FF, 0x54BAFF, 0x90FF2D, 0xFFD300, 0xFF609D, 0xC5E1BA};+static uint16_t gem_tex(int gem, const char *what) { /* collectables/summitgems/N/gem00 (14 frames) or .../bg */+ char p[40] = "collectables/summitgems/0/";+ p[24] = (char)('0' + gem);+ return res_tex_by_name(path2(p, p, what, -1));+}+typedef struct { float alpha; } BgFlash;+static void bgflash_update(Ent *e) {+ BgFlash *b = ST(e, BgFlash);+ if ((b->alpha = approach(b->alpha, 0, DT * 0.5f)) <= 0) ent_remove(e);+}+static void bgflash_render(Ent *e) { gfx_rect(g_level.cam.x - 10, g_level.cam.y - 10, 340, 200, 0, a8(ST(e, BgFlash)->alpha)); }+static const EntClass BGFLASH = {.name = "summitGemBgFlash", .size = sizeof(BgFlash), .update = bgflash_update, .render = bgflash_render};+typedef struct {+ Wiggler scale, move;+ V2 dir;+ float t, bounce_delay;+ uint32_t gid;+ uint16_t frame0;+ uint8_t gem, have, smash;+} Gem;+static void gem_on_player(Ent *e, Player *p) {+ Gem *g = ST(e, Gem);+ if (player_dash_attacking(p)) {+ g->smash = 1; /* Add(new Coroutine(SmashRoutine(player, level))) */+ e->visible = 0, e->collidable = 0;+ p->stamina = 110;+ level_set_do_not_load(g->gid);+ g_session.summit_gems |= (uint8_t)(1 << g->gem);+ g_save.summit_gems |= (uint8_t)(1 << g->gem); /* SaveData.RegisterSummitGem */+ level_shake(0.3f);+ level_freeze(0.1f);+ float ang = atan2f(p->speed.y, p->speed.x);+ particles_emit_c(PL_FG, &P_SummitGem_P_Shatter, 5, v2(e->x, e->y), v2(4, 4), GEM_COLORS[g->gem], ang - PI_F / 2);+ particles_emit_c(PL_FG, &P_SummitGem_P_Shatter, 5, v2(e->x, e->y), v2(4, 4), GEM_COLORS[g->gem], ang + PI_F / 2);+ for (int i = 0; i < 10; i++) absorb_orb_new(v2(e->x, e->y), p->ent); /* (SlashFx is not drawn) */+ level_flash(0xFFFF, true);+ Ent *f = ent_new(&BGFLASH, 0, 0);+ if (f) f->depth = 10100, f->tags = TAG_PERSISTENT, f->collidable = 0, ST(f, BgFlash)->alpha = 1;+ g_time_rate = 0.5f;+ return;+ }+ player_point_bounce(p, e_center(e));+ wiggler_restart(&g->move);+ wiggler_restart(&g->scale);+ g->dir = v2sub(e_center(e), player_center(p));+ g->dir = v2len(g->dir) > 0 ? v2norm(g->dir) : v2(0, 1);+ if (g->bounce_delay <= 0) g->bounce_delay = 0.1f;+}+static void gem_update(Ent *e) {+ Gem *g = ST(e, Gem);+ if (g->smash) { /* SmashRoutine: the time rate back to 1 */+ if (g_time_rate < 1 && (g_time_rate += RAW_DT * 0.5f) < 1) return;+ g_time_rate = 1;+ ent_remove(e);+ return;+ }+ g->t += DT;+ wiggler_update(&g->scale);+ wiggler_update(&g->move);+ g->bounce_delay -= DT;+}+static void gem_render(Ent *e) {+ Gem *g = ST(e, Gem);+ uint16_t t = (uint16_t)(g->frame0 + (int)(g->t / 0.08f) % 14);+ V2 off = v2mul(g->dir, g->move.value * -8);+ float s = 1 + g->scale.value * 0.3f;+ draw_centered(t, e->x + off.x, e->y + off.y, 0xFFFF, g->have ? 128 : 255, s, s, 0);+}+static const EntClass GEM = {.name = "summitgem", .size = sizeof(Gem), .update = gem_update, .render = gem_render,+ .on_player = gem_on_player, .kind = KIND_PCOLLIDE};+static void new_gem(const EData *d) {+ uint32_t gid = level_entity_hash(d);+ if (level_do_not_load(gid)) return;+ Ent *e = ent_new(&GEM, d->x, d->y);+ if (!e) return;+ ent_box(e, 12, 12, -6, -6);+ Gem *g = ST(e, Gem);+ g->gid = gid;+ g->gem = (uint8_t)((int)EA(d, summitgem, gem) % 6);+ g->frame0 = gem_tex(g->gem, "gem00");+ g->have = g_save.summit_gems >> g->gem & 1;+ wiggler_init(&g->scale, 0.5f, 4);+ wiggler_init(&g->move, 0.8f, 2);+ g->move.start_zero = true;+}++/* ---------------------------------------------------------------- SummitGemManager */+typedef struct { V2 shake; float t, y, scale, bloom; uint16_t frame0, bg; uint8_t spin, gone; } MGem;+static void mgem_update(Ent *e) {+ MGem *g = ST(e, MGem);+ g->t += DT;+ if (g->spin && g->t >= 14 * 0.05f) g->spin = 0, g->t = 0; /* "spin" goes back to "idle" */+}+static void mgem_render(Ent *e) {+ MGem *g = ST(e, MGem);+ draw_centered(g->bg, e->x, e->y, 0xFFFF, 255, 1, 1, 0);+ if (g->gone) return;+ draw_centered((uint16_t)(g->frame0 + (g->spin ? (int)(g->t / 0.05f) % 14 : 0)), e->x + g->shake.x, e->y + g->y + g->shake.y, 0xFFFF, 255,+ g->scale, g->scale, 0);+ bloom_add(e->x, e->y + g->y, g->bloom, 20);+}+static const EntClass MGEM = {.name = "summitGemManagerGem", .size = sizeof(MGem), .update = mgem_update, .render = mgem_render};+typedef struct { Co co; Ent *gems[6]; Ent *heart; V2 from; float p; uint8_t n, index, broken; } GemMgr;+static void gemmgr_update(Ent *e) {+ GemMgr *m = ST(e, GemMgr);+ Co *c = &m->co;+ Player *p;+ MGem *g;+ CO_BEGIN(c);+ if (g_session.heart) {+ for (int i = 0; i < m->n; i++) ST(m->gems[i], MGem)->gone = 1;+ CO_YIELD(c);+ return;+ }+ for (;;) {+ p = level_player();+ if (p && v2len(v2sub(v2(p->ent->x, p->ent->y), v2(e->x, e->y))) < 64) break;+ CO_YIELD(c);+ }+ CO_WAIT(c, 0.5f);+ for (m->index = 0; m->index < m->n; m->index++) {+ {+ bool has = (g_session.summit_gems >> m->index & 1) ||+ (!(g_session.old_stats.flags & MS_HEART) && (g_save.summit_gems >> m->index & 1));+ if (!has) continue;+ }+ g = ST(m->gems[m->index], MGem);+ g->spin = 1, g->t = 0;+ while (ST(m->gems[m->index], MGem)->spin) {+ g = ST(m->gems[m->index], MGem);+ g->bloom = approach(g->bloom, 1, DT * 3);+ if (g->bloom > 0.5f) g->shake = shake_vec();+ g->y -= DT * 8;+ g->scale = 1 + g->bloom * 0.1f;+ CO_YIELD(c);+ }+ CO_WAIT(c, 0.2f);+ level_shake(0.3f);+ {+ Ent *ge = m->gems[m->index];+ for (int i = 0; i < 20; i++)+ particles_emit_c(PL_FG, &P_SummitGem_P_Shatter, 1, v2add(v2(ge->x, ge->y), v2((float)(rndi(16) - 8), (float)(rndi(16) - 8))),+ v2(0, 0), GEM_COLORS[m->index], rndf() * 2 * PI_F);+ ST(ge, MGem)->gone = 1;+ }+ m->broken++;+ CO_WAIT(c, 0.25f);+ }+ if (m->broken < 6) {+ CO_YIELD(c);+ return;+ }+ for (int i = 0; i < g_nents; i++) /* the HeartGem (another file's blackGem) */+ if (g_ents[i].cls && g_ents[i].dead != 1 && !strcmp(g_ents[i].cls->name, "blackGem")) m->heart = &g_ents[i];+ if (!m->heart) {+ CO_YIELD(c);+ return;+ }+ CO_WAIT(c, 0.1f);+ m->from = v2(m->heart->x, m->heart->y);+ for (m->p = 0; m->p < 1; m->p += DT) {+ if (!m->heart->cls || m->heart->dead == 1) break;+ {+ V2 at = v2lerp(m->from, v2(e->x, e->y - 16), ease_cube_out(m->p));+ m->heart->x = at.x, m->heart->y = at.y;+ }+ CO_YIELD(c);+ }+ CO_END(c);+}+static const EntClass GEMMGR = {.name = "summitGemManager", .size = sizeof(GemMgr), .update = gemmgr_update};+static void new_gemmgr(const EData *d) {+ Ent *e = ent_new(&GEMMGR, d->x, d->y);+ if (!e) return;+ e->depth = -10010;+ e->visible = e->collidable = 0;+ GemMgr *m = ST(e, GemMgr);+ for (int i = 0; i < d->nnodes && i < 6; i++) {+ V2 at = ed_node(d, i);+ Ent *ge = ent_new(&MGEM, at.x, at.y);+ if (!ge) break;+ ge->depth = -10010;+ ge->collidable = 0;+ MGem *g = ST(ge, MGem);+ g->frame0 = gem_tex(i, "gem00"), g->bg = gem_tex(i, "bg");+ g->scale = 1;+ m->gems[m->n++] = ge;+ }+}++/* ---------------------------------------------------------------- SummitCloud */+typedef struct { SineWave sine; float diff; uint8_t tex, flip; } SCloud;+static void scloud_update(Ent *e) { sine_update(&ST(e, SCloud)->sine); }+static void scloud_render(Ent *e) {+ SCloud *c = ST(e, SCloud);+ V2 mid = v2add(g_level.cam, v2(160, 90));+ V2 at = v2add(v2(e->x, e->y), v2mul(v2sub(v2(e->x + 64, e->y + 32), mid), 0.1f + c->diff));+ draw_centered(c->tex ? T_scenery_summitclouds_cloud01 : T_scenery_summitclouds_cloud00, at.x, at.y + c->sine.value * 8, 0xFFFF, 255,+ c->flip ? -1 : 1, 1, 0);+}+static const EntClass SCLOUD = {.name = "summitcloud", .size = sizeof(SCloud), .update = scloud_update, .render = scloud_render};+static void new_scloud(const EData *d) {+ Ent *e = ent_new(&SCLOUD, d->x, d->y);+ if (!e) return;+ e->depth = -10550;+ e->collidable = 0;+ SCloud *c = ST(e, SCloud);+ c->diff = rnd_rangef(0.1f, 0.2f);+ c->tex = (uint8_t)rndi(2); /* GetAtlasSubtextures("scenery/summitclouds/cloud"): 00, 01 */+ c->flip = (uint8_t)rndi(2);+ c->sine.freq = rnd_rangef(0.05f, 0.15f);+ sine_randomize(&c->sine);+}++/* ---------------------------------------------------------------- SpeedRing */+typedef struct { V2 normal; float lerp; } Ring;+static void ring_update(Ent *e) {+ Ring *r = ST(e, Ring);+ r->lerp += 3 * DT;+ e->x += r->normal.x * 10 * DT, e->y += r->normal.y * 10 * DT;+ if (r->lerp >= 1) ent_remove(e);+}+static V2 ring_at(const Ring *r, float a, float max) {+ V2 v = angle_vec(a, 1);+ return v2mul(v, lerpf(max, max * 0.5f, fabsf(v.x * r->normal.x + v.y * r->normal.y)));+}+static void ring_render(Ent *e) { /* DrawRing: 16 lines, white * Lerp(0.6, 0, lerp) */+ Ring *r = ST(e, Ring);+ float max = lerpf(4, 14, r->lerp);+ uint8_t a = a8(lerpf(0.6f, 0, r->lerp));+ V2 prev = ring_at(r, 0, max);+ for (int i = 1; i <= 8; i++) {+ V2 v = ring_at(r, i * PI_F / 8, max);+ gfx_line(e->x + prev.x, e->y + prev.y, e->x + v.x, e->y + v.y, 0xFFFF, a);+ gfx_line(e->x - prev.x, e->y - prev.y, e->x - v.x, e->y - v.y, 0xFFFF, a);+ prev = v;+ }+}+static const EntClass RING = {.name = "speedRing", .size = sizeof(Ring), .update = ring_update, .render = ring_render};+static void ring_new(V2 at, float angle) {+ Ent *e = ent_new(&RING, at.x, at.y);+ if (e) e->collidable = 0, ST(e, Ring)->normal = angle_vec(angle, 1);+}++/* ---------------------------------------------------------------- HeightDisplay */+typedef struct {+ Co co;+ float approach, ease, pulse, cam_p;+ int16_t height;+ int8_t index;+ uint8_t room, easing_cam, cam_up, has_text;+} Height;+static void height_update(Ent *e) {+ Height *h = ST(e, Height);+ Player *p = level_player();+ Room *rm = room();+ if (h->index >= 0 && h->ease > 0) {+ float d = h->height - h->approach;+ if (d > 100) h->approach += 1000 * DT;+ else if (d > 25) h->approach += 200 * DT;+ else if (d > 5) h->approach += 50 * DT;+ else if (d > 0) h->approach += 10 * DT;+ else h->approach = h->height;+ }+ if (!h->easing_cam) g_level.cam.y = (float)(rm->y + rm->h - 180 + 64);+ if (h->cam_up) { /* CameraUp */+ if (h->cam_p < 1) {+ g_level.cam.y = rm->y + rm->h - 180 + 64 * (1 - ease_cube_out(h->cam_p));+ h->cam_p += DT * 1.5f;+ } else+ h->cam_up = 0;+ }+ Co *c = &h->co;+ CO_BEGIN(c);+ while (!p || rm->index == h->room) {+ CO_YIELD(c);+ p = level_player();+ rm = room();+ }+ h->easing_cam = 0; /* (StepAudioProgression: no music) */+ CO_WAIT(c, 0.1f);+ h->easing_cam = 1, h->cam_up = 1, h->cam_p = 0;+ while ((h->ease += DT / 0.15f) < 1) CO_YIELD(c);+ while (h->approach < h->height && !actor_on_ground(level_player_ent(), 1)) CO_YIELD(c);+ h->approach = h->height;+ h->pulse = 1;+ while ((h->pulse -= DT * 4) > 0) CO_YIELD(c);+ h->pulse = 0;+ CO_WAIT(c, 1);+ while ((h->ease -= DT / 0.15f) > 0) CO_YIELD(c);+ ent_remove(e);+ CO_END(c);+}+static void height_render(Ent *e) { /* "{X} M": the number, then the rest */+ Height *h = ST(e, Height);+ if (g_level.paused || h->index < 0 || h->ease <= 0 || !h->has_text) return;+ char right[24], num[8];+ int nr = dialog_clean(h->index == 0 ? "CH7_HEIGHT_0" : "CH7_HEIGHT_0", right, sizeof right);+ num[0] = 0;+ {+ char tmp[8], *o = num;+ int v = (int)h->approach, k = 0;+ do tmp[k++] = (char)('0' + v % 10), v /= 10;+ while (v);+ while (k) *o++ = tmp[--k];+ *o = 0;+ }+ char full[8];+ int hv = h->height, k = 0;+ do full[k++] = '0', hv /= 10;+ while (hv);+ float k_ = 1.2f + h->pulse * 0.2f, e_ = ease_sine_inout(h->ease);+ float wn = font_measure(full, k, FONT_S), w = wn + font_measure(right, nr, FONT_S), lh = font_line_height(FONT_S);+ float bw = w * k_ + 64 / 6.f, bh = (lh * k_ + 32 / 6.f) * e_;+ gfx_hud(true);+ gfx_rect(160 - bw / 2, 90 - bh / 2, bw, bh, 0, 255);+ uint8_t a = a8(e_);+ float x = 160 - w / 2;+ font_draw(right, nr, x + wn, 90 - lh / 2, FONT_S, 0xFFFF, a);+ font_draw_justified(num, x + wn / 2, 90, 0.5f, 0.5f, FONT_S, 0xFFFF, a);+ gfx_hud(false);+}+static const EntClass HEIGHT = {.name = "heightDisplay", .size = sizeof(Height), .update = height_update, .render = height_render};+static void height_new(int index) {+ Ent *e = ent_new(&HEIGHT, 0, 0);+ if (!e) return;+ e->tags = TAG_HUD | TAG_PERSISTENT;+ e->collidable = 0;+ Height *h = ST(e, Height);+ h->index = (int8_t)index;+ h->easing_cam = 1;+ h->room = (uint8_t)room()->index;+ char key[16] = "CH7_HEIGHT_0";+ key[11] = (char)('0' + (index < 0 ? 0 : index));+ if (index >= 0 && dialog_has(key)) {+ h->has_text = 1;+ h->height = (int16_t)((index + 1) * 500);+ h->approach = (float)(index * 500);+ }+}++/* ---------------------------------------------------------------- CS07_Ascend */+typedef struct {+ Cutscene cs;+ Ent *badeline, *tb;+ V2 origin, center;+ float dist, timer;+ int8_t index;+ uint8_t spinning, spin_on, dark;+ char key[24];+} Ascend7;+static void ascend_spin(Ascend7 *s) { /* SpinCharacters, an update of it */+ Player *p = &g_player;+ s->dist = approach(s->dist, s->spinning ? 1 : 0, DT * 4);+ int num = (int)(s->timer / (PI_F * 2) * 14 + 10);+ float si = sinf(s->timer), co = cosf(s->timer), r = ease_cube_out(s->dist) * 32;+ sprite_set_frame(&p->spr, num);+ if (s->badeline) bd_set_frame(s->badeline, num + 7);+ p->ent->x = s->center.x - si * r, p->ent->y = s->center.y - co * s->dist * 8;+ if (s->badeline) s->badeline->x = s->center.x + si * r, s->badeline->y = s->center.y + co * s->dist * 8;+ s->timer -= DT * 2;+ if (s->timer <= 0) s->timer += PI_F * 2;+ if (!s->spinning && s->dist <= 0) s->spin_on = 0;+}+static void ascend7_update(Ent *e) {+ Ascend7 *s = ST(e, Ascend7);+ Player *p = level_player();+ Co *c = &s->cs.co;+ if (s->spin_on == 1) ascend_spin(s);+ else if (s->spin_on == 2) s->spin_on = 1;+ CO_BEGIN(c);+ while (!level_player()) CO_YIELD(c);+ p = level_player();+ s->origin = v2(p->ent->x, p->ent->y);+ split_particles(p); /* (the displacement burst is not drawn) */+ p->dashes = 1;+ p->facing = 1;+ s->badeline = bd_new(s->origin);+ if (s->badeline) BD(s->badeline)->auto_enabled = 0;+ s->spinning = 1;+ s->center = s->origin, s->timer = PI_F / 2, s->dist = 0; /* SpinCharacters */+ spr_play(&p->spr, A_player_spin, false);+ if (s->badeline) spr_play(&BD(s->badeline)->spr, A_badeline_spin, false), BD(s->badeline)->spr.sx = 1;+ s->spin_on = 2;+ CO_SAY(c, s->tb, s->key, NULL, NULL);+ s->spinning = 0;+ CO_WAIT(c, 0.25f);+ if (s->badeline) ent_remove(s->badeline), s->badeline = NULL;+ p->dashes = 2;+ split_particles(p);+ cutscene_end(e);+ return;+ CO_END(c);+}+static void ascend7_end(Ent *e, bool skipped) {+ Ascend7 *s = ST(e, Ascend7);+ (void)skipped;+ if (s->badeline) ent_remove(s->badeline);+ Player *p = level_player();+ if (p && s->origin.x != 0) {+ p->dashes = 2;+ p->ent->x = s->origin.x, p->ent->y = s->origin.y;+ }+ if (!s->dark) height_new(s->index);+}+static const EntClass ASCEND7 = {.name = "CS07_Ascend", .size = sizeof(Ascend7), .update = ascend7_update};++/* ---------------------------------------------------------------- AscendManager (SummitBackgroundManager) */+#define STREAKS 80+typedef struct { float y; uint16_t speed, xic; } Streak; /* xic: x | texture << 10 | color << 12 */+enum { OFF_streaks = 0, END_streaks = OFF_streaks + (int)sizeof(Streak[STREAKS]) };+#define streaks (*(Streak(*)[STREAKS])(void *)(g_chram[7] + OFF_streaks))+typedef struct {+ Co co;+ Ent *cs, *fader, *streaks_e, *clouds_e;+ V2 from;+ float fade, p, scroll;+ int8_t index;+ uint8_t intro, dark, out_top;+ char cutscene[24];+} AscendM;+static const EntClass ASCENDM;+/* Streaks: 80 slices falling past, as bars of their color (white and e69ecb, or dark blues) */+static const uint8_t SLICE_W[3] = {9, 3, 3};+static float ascend_fade(Ent *m) { return m && m->cls == &ASCENDM ? ST(m, AscendM)->fade : 1; }+typedef struct { Ent *manager; float alpha; } Streaks;+static void streaks_update(Ent *e) {+ (void)e;+ for (int i = 0; i < STREAKS; i++) streaks[i].y += streaks[i].speed * DT;+}+static void streaks_strip(uint16_t *strip, int sy0, int sy1, void *ctx) {+ Ent *e = ctx;+ Streaks *s = ST(e, Streaks);+ AscendM *m = s->manager && s->manager->cls == &ASCENDM ? ST(s->manager, AscendM) : NULL;+ float a = ease_sine_inout(ascend_fade(s->manager) * s->alpha);+ int al = (int)(a * 256);+ uint16_t cols[2];+ cols[0] = m && m->dark ? rgb(0x041B44) : 0xFFFF;+ cols[1] = m && m->dark ? rgb(0x011230) : rgb(0xE69ECB);+ if (al <= 0) return;+ for (int i = 0; i < STREAKS; i++) {+ Streak *k = &streaks[i];+ float t = clamped_map(k->speed, 600, 2000, 0, 1), big = 1 + 3 * t;+ int kx = k->xic & 1023, idx = k->xic >> 10 & 3, col = k->xic >> 12 & 1;+ float sx = (1 - 0.75f * t) * big, sy = (1 + t) * big;+ float y = -128 + fmodf(fmodf(k->y, 436) + 436, 436);+ int w = (int)(SLICE_W[idx] * sx + 0.5f), h = (int)(110 * sy);+ int x0 = (int)(kx - w / 2.f), y0 = (int)(y - h / 2.f), y1 = y0 + h;+ if (y0 < sy0) y0 = sy0;+ if (y1 > sy1) y1 = sy1;+ for (int yy = y0; yy < y1; yy++)+ for (int xx = x0 < 0 ? 0 : x0; xx < x0 + w && xx < VIEW_W; xx++) {+ uint16_t *d = strip + (yy - sy0) * VIEW_W + xx;+ *d = blend565(*d, cols[col], al);+ }+ }+ for (int yy = sy0; yy < sy1; yy++) /* the bars at the sides */+ for (int xx = 0; xx < VIEW_W; xx++)+ if (xx < 16 || xx >= VIEW_W - 16) {+ uint16_t *d = strip + (yy - sy0) * VIEW_W + xx;+ *d = blend565(*d, cols[0], al);+ }+}+static void streaks_render(Ent *e) { gfx_custom(streaks_strip, e, 0, VIEW_H); }+static const EntClass STREAKS_CLS = {.name = "ascendStreaks", .size = sizeof(Streaks), .update = streaks_update, .render = streaks_render};+/* Clouds: ten launch clouds falling past */+typedef struct { Ent *manager; float alpha; struct { float x, y, speed; uint8_t idx; } p[10]; } Clouds;+static void clouds_update(Ent *e) {+ Clouds *c = ST(e, Clouds);+ for (int i = 0; i < 10; i++) c->p[i].y += c->p[i].speed * DT;+}+static void clouds_render(Ent *e) {+ Clouds *c = ST(e, Clouds);+ AscendM *m = c->manager && c->manager->cls == &ASCENDM ? ST(c->manager, AscendM) : NULL;+ float a = ascend_fade(c->manager) * c->alpha;+ uint16_t col = rgb(m && m->dark ? 0x082644 : 0xB64A86);+ for (int i = 0; i < 10; i++) {+ float y = -360 + fmodf(fmodf(c->p[i].y, 900) + 900, 900);+ draw_centered(c->p[i].idx ? T_scenery_launch_cloud01 : T_scenery_launch_cloud00, g_level.cam.x + c->p[i].x, g_level.cam.y + y, col,+ a8(a), 1, 1, 0);+ }+}+static const EntClass CLOUDS_CLS = {.name = "ascendClouds", .size = sizeof(Clouds), .update = clouds_update, .render = clouds_render};+typedef struct { Ent *manager; float fade; uint8_t dark; } AFader;+static void afader_render(Ent *e) {+ AFader *f = ST(e, AFader);+ if (f->fade > 0) gfx_rect(g_level.cam.x - 10, g_level.cam.y - 10, 340, 200, f->dark ? 0 : 0xFFFF, a8(f->fade));+}+static const EntClass AFADER = {.name = "ascendFader", .size = sizeof(AFader), .render = afader_render};++static bool ascend_fade_to(AscendM *m, float target, float duration) { /* FadeTo */+ m->fade = approach(m->fade, target, DT / duration);+ return m->fade != target; /* (FadeSnapTo: the snow, the bloom and the parallax are not changed) */+}+static void ascendm_flag(const char *pre, int index, bool on) {+ char f[16];+ path2(f, pre, NULL, -1);+ char *o = f + strlen(f);+ if (index < 0) *o++ = '-', index = -index;+ *o++ = (char)('0' + index % 10), *o = 0;+ level_set_flag(f, on);+}+static void ascendm_update(Ent *e) {+ AscendM *m = ST(e, AscendM);+ Player *p = level_player();+ m->scroll += DT * 240;+ Co *c = &m->co;+ CO_BEGIN(c);+ while (!p || p->ent->y > e->y) {+ CO_YIELD(c);+ p = level_player();+ }+ if (m->index == 9) CO_WAIT(c, 1.6f);+ m->streaks_e = ent_new(&STREAKS_CLS, 0, 0);+ if (m->streaks_e) {+ m->streaks_e->depth = 20, m->streaks_e->collidable = 0;+ ST(m->streaks_e, Streaks)->manager = e, ST(m->streaks_e, Streaks)->alpha = 1;+ for (int i = 0; i < STREAKS; i++) {+ Streak *k = &streaks[i];+ float x = 160 + rnd_rangef(24, 144) * (rndi(2) ? 1 : -1);+ k->y = rndf() * 436;+ k->speed = (uint16_t)(clamped_map(fabsf(x - 160), 0, 160, 0.25f, 1) * rnd_rangef(600, 2000));+ k->xic = (uint16_t)((int)x | rndi(3) << 10 | rndi(2) << 12);+ }+ }+ if (!m->dark) {+ m->clouds_e = ent_new(&CLOUDS_CLS, 0, 0);+ if (m->clouds_e) {+ m->clouds_e->depth = -1000000, m->clouds_e->collidable = 0;+ Clouds *cl = ST(m->clouds_e, Clouds);+ cl->manager = e, cl->alpha = 1;+ for (int i = 0; i < 10; i++) cl->p[i].x = rndf() * 320, cl->p[i].y = rndf() * 900, cl->p[i].speed = (float)(400 + rndi(400)), cl->p[i].idx = (uint8_t)rndi(2);+ }+ }+ ascendm_flag("beginswap_", m->index, true);+ p = level_player();+ spr_play(&p->spr, A_player_launch, false);+ p->speed = v2(0, 0);+ player_set_state(p, ST_DUMMY);+ p->dummy_gravity = false;+ p->dummy_auto_animate = false;+ if (m->intro) {+ m->fade = 1;+ g_level.cam = v2sub(player_center(p), v2(160, 90));+ CO_WAIT(c, 2.3f);+ } else {+ while (ascend_fade_to(m, 1, m->dark ? 2 : 0.8f)) CO_YIELD(c);+ if (m->cutscene[0]) {+ CO_WAIT(c, 0.25f);+ m->cs = scene_new(&ASCEND7, ascend7_end, true, false);+ if (m->cs) {+ Ascend7 *s = ST(m->cs, Ascend7);+ s->index = m->index, s->dark = m->dark;+ memcpy(s->key, m->cutscene, sizeof s->key);+ }+ CO_YIELD(c);+ while (m->cs && m->cs->cls == &ASCEND7 && m->cs->dead != 1) CO_YIELD(c);+ } else+ CO_WAIT(c, 0.5f);+ }+ g_level.can_retry = false;+ p = level_player();+ spr_play(&p->spr, A_player_launch, false);+ CO_WAIT(c, 0.25f);+ m->from = v2(level_player_ent()->x, level_player_ent()->y);+ for (m->p = 0; m->p < 1; m->p += DT / 1) {+ {+ Ent *pe = level_player_ent();+ V2 at = v2add(v2lerp(m->from, v2add(m->from, v2(0, 60)), ease_cube_inout(m->p)), shake_vec());+ pe->x = at.x, pe->y = at.y;+ }+ CO_YIELD(c);+ }+ m->fader = ent_new(&AFADER, 0, 0);+ if (m->fader) m->fader->depth = -1000010, m->fader->collidable = 0, ST(m->fader, AFader)->manager = e, ST(m->fader, AFader)->dark = m->dark;+ m->from = v2(level_player_ent()->x, level_player_ent()->y);+ for (m->p = 0; m->p < 1; m->p += DT / 0.5f) {+ {+ Ent *pe = level_player_ent();+ float y = pe->y;+ V2 at = v2lerp(m->from, v2add(m->from, v2(0, -160)), ease_sine_in(m->p));+ pe->x = at.x, pe->y = at.y;+ if (m->p == 0 || floorf(pe->y / 16) != floorf(y / 16)) ring_new(player_center(&g_player), -PI_F / 2); /* Calc.OnInterval */+ if (m->fader) ST(m->fader, AFader)->fade = m->p >= 0.5f ? (m->p - 0.5f) * 2 : 0;+ }+ CO_YIELD(c);+ }+ g_level.can_retry = true;+ m->out_top = 1;+ {+ Player *pl = &g_player;+ pl->ent->y = (float)room()->y;+ pl->summit_target_x = pl->ent->x; /* SummitLaunch */+ player_set_state(pl, ST_SUMMITLAUNCH);+ pl->dummy_gravity = true;+ pl->dummy_auto_animate = true;+ }+ ascendm_flag("bgswap_", m->index, true);+ g_level.tr_duration = 0.05f; /* NextTransitionDuration */+ if (m->intro) height_new(-1);+ CO_END(c);+}+static void ascendm_render(Ent *e) {+ AscendM *m = ST(e, AscendM);+ if (m->fade > 0) gfx_rect(g_level.cam.x - 10, g_level.cam.y - 10, 340, 200, m->dark ? 0 : rgb(0x75A0AB), a8(m->fade));+}+static void ascendm_removed(Ent *e) {+ AscendM *m = ST(e, AscendM);+ m->fade = 0;+ ascendm_flag("bgswap_", m->index, false);+ ascendm_flag("beginswap_", m->index, false);+ if (!m->out_top) return;+ /* the next part's wipe in (ScreenWipe.WipeColor white for the light ones: the wipes here are black) */+ static const uint8_t NEXT[6] = {WIPE_ANGLED, WIPE_DREAM, WIPE_KEYDOOR, WIPE_WIND, WIPE_DROP, WIPE_MOUNTAIN};+ if (m->intro) wipe_start(WIPE_MOUNTAIN, true, NULL);+ else if (m->index >= 0 && m->index < 6) wipe_start(NEXT[m->index], true, NULL);+ else if (m->index >= 9) wipe_start(WIPE_STARFIELD, true, NULL);+}+static const EntClass ASCENDM = {.name = "SummitBackgroundManager", .size = sizeof(AscendM), .update = ascendm_update,+ .render = ascendm_render, .removed = ascendm_removed};+static void new_ascendm(const EData *d) {+ Ent *e = ent_new(&ASCENDM, d->x, d->y);+ if (!e) return;+ e->tags = TAG_TRANSITION_UPDATE;+ e->depth = 8900;+ e->collidable = 0;+ AscendM *m = ST(e, AscendM);+ m->index = (int8_t)EA(d, SummitBackgroundManager, index);+ m->intro = EAB(d, SummitBackgroundManager, intro_launch);+ m->dark = EAB(d, SummitBackgroundManager, dark);+ strncpy(m->cutscene, EAS(d, SummitBackgroundManager, cutscene), sizeof m->cutscene - 1);+}++/* ---------------------------------------------------------------- CS07_Ending (the summit) */+static void credits_begin(void);+typedef struct {+ Cutscene cs;+ Ent *badeline, *tb;+ Walk walk;+ Step cam, cam2;+ V2 target, cam2_to;+ Co ev;+ int8_t ev_i;+ uint8_t cam_on, cam2_on;+} Ending7;+static bool ending7_nb(Ending7 *s, Co *c, int i) {+ Player *p = &g_player;+ switch (i) {+ case 0: /* WaitABit */+ NB_BEGIN(c);+ NB_WAIT(c, 3);+ NB_END(c);+ case 1: /* SitDown */+ NB_BEGIN(c);+ NB_WAIT(c, 0.5f);+ p->dummy_auto_animate = true;+ s->walk = walk_to(p->ent->x + 16);+ s->walk.mult = 0.25f;+ NB_NEST(c, player_walk(p, &s->walk));+ NB_WAIT(c, 0.1f);+ p->dummy_auto_animate = false;+ spr_play(&p->spr, A_player_sitDown, false);+ NB_WAIT(c, 1);+ NB_END(c);+ default: /* BadelineApproaches */+ NB_BEGIN(c);+ NB_WAIT(c, 0.5f);+ BD(s->badeline)->spr.sx = -1;+ NB_WAIT(c, 1);+ BD(s->badeline)->spr.sx = 1;+ NB_WAIT(c, 1);+ step_reset(&s->cam2);+ s->cam2_on = 2; /* CameraTo(camera + (88, 0), 6): a coroutine of its own */+ s->cam2_to = v2add(g_level.cam, v2(88, 0));+ BD(s->badeline)->float_speed = 40;+ bd_float_to(s->badeline, v2(p->ent->x - 10, p->ent->y - 4), 0, true, false, false);+ NB_AWAIT(c, &BD(s->badeline)->job);+ NB_WAIT(c, 0.5f);+ NB_END(c);+ }+}+static bool ending7_ev(void *ctx, int i) {+ Ending7 *s = ST((Ent *)ctx, Ending7);+ return !ending7_nb(s, ev_co(&s->ev, &s->ev_i, i), i);+}+static void ending7_update(Ent *e) {+ Ending7 *s = ST(e, Ending7);+ Player *p = &g_player;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_set_state(p, ST_DUMMY);+ CO_WALK(c, s->walk, walk_to(s->target.x));+ CO_WAIT(c, 0.25f);+ step_reset(&s->cam);+ s->cam_on = 2; /* CameraTo(target + (-160, -130), 3) */+ p->facing = 1;+ CO_WAIT(c, 1);+ spr_play(&p->spr, A_player_idle, false);+ p->dummy_auto_animate = false;+ p->dashes = p->inventory_dashes = 1;+ g_session.inv_dashes = 1;+ s->badeline = bd_new(player_center(p));+ split_particles(p);+ if (!s->badeline) {+ cutscene_end(e);+ return;+ }+ BD(s->badeline)->spr.sx = 1;+ bd_float_to(s->badeline, v2add(s->target, v2(-10, -30)), 1, false, false, false);+ CO_AWAIT(c, &BD(s->badeline)->job);+ CO_WAIT(c, 0.5f);+ s->ev_i = -1;+ CO_SAY(c, s->tb, "CH7_ENDING", ending7_ev, e);+ CO_WAIT(c, 1);+ cutscene_end(e);+ return;+ CO_END(c);+}+static void ending7_tick(Ent *e) {+ Ending7 *s = ST(e, Ending7);+ ending7_update(e);+ if (e->dead == 1) return;+ if (s->cam_on == 2) s->cam_on = 1;+ else if (s->cam_on && !camera_to(&s->cam, v2add(s->target, v2(-160, -130)), 3, ease_cube_inout)) s->cam_on = 0;+ if (s->cam2_on == 2) s->cam2_on = 1;+ else if (s->cam2_on && !camera_to(&s->cam2, s->cam2_to, 6, ease_cube_inout)) s->cam2_on = 0;+}+static void ending7_wiped(void) {+ if (g_session.mode == M_A) credits_begin(); /* AreaComplete, then the credits (in this chapter's credits rooms) */+ else level_complete_area(false, true);+}+static void ending7_end(Ent *e, bool skipped) { /* Level.CompleteArea(spotlightWipe: false), Duration 2, EndTimer 1 */+ (void)e, (void)skipped;+ g_level.pause_lock = true;+ if (g_level.skipping_cutscene) {+ ending7_wiped();+ return;+ }+ wipe_start(WIPE_FADE, false, ending7_wiped);+ g_wipe.duration = 2, g_wipe.end_timer = 1;+}+static const EntClass ENDING7 = {.name = "CS07_Ending", .size = sizeof(Ending7), .update = ending7_tick};+typedef struct { V2 target; uint8_t triggered; } Summit;+static void summit_enter(Ent *e, Player *p) {+ Summit *s = ST(e, Summit);+ (void)p;+ if (s->triggered) return;+ s->triggered = 1;+ Ent *cs = scene_new(&ENDING7, ending7_end, false, true);+ if (!cs) return;+ level_register_complete(); /* OnBegin: RegisterAreaComplete */+ ST(cs, Ending7)->target = s->target;+}+static const EntClass SUMMITTRIG = {.name = "eventTrigger", .size = sizeof(Summit), .on_enter = summit_enter, .kind = KIND_TRIGGER};++/* ---------------------------------------------------------------- NPC07X_Granny_Ending */+typedef struct {+ Cutscene cs;+ Ent *granny, *tb;+ Walk walk;+ Step step;+ Co ev;+ int8_t ev_i;+} Granny7;+static bool granny7_ev(void *ctx, int i) { /* StartLaughing, StopLaughing (then a yield) */+ Granny7 *s = ST((Ent *)ctx, Granny7);+ Co *c = ev_co(&s->ev, &s->ev_i, i);+ if (!c->co) {+ spr_play(&NPC_(s->granny)->spr, i == 0 ? A_granny_laugh : A_granny_idle, false);+ c->co = 1;+ return false;+ }+ return true;+}+static void granny7_update(Ent *e) {+ Granny7 *s = ST(e, Granny7);+ Player *p = &g_player;+ Npc *n = NPC_(s->granny);+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_set_state(p, ST_DUMMY);+ p->force_camera_update = true;+ while (!actor_on_ground(p->ent, 1)) CO_YIELD(c);+ CO_WALK(c, s->walk, walk_exact((int)s->granny->x - 16));+ p->facing = 1;+ if (n->i[0] < 2) {+ CO_WAIT(c, 0.5f);+ CO_ZOOM_TO(c, &s->step, v2(s->granny->x - g_level.cam.x, s->granny->y - g_level.cam.y - 32), 2, 0.5f);+ s->ev_i = -1;+ CO_SAY(c, s->tb, n->i[0] == 0 ? "CH7_CSIDE_OLDLADY" : "CH7_CSIDE_OLDLADY_B", granny7_ev, e);+ if (n->i[0] == 1) n->talk.enabled = false;+ }+ CO_ZOOM_BACK(c, &s->step, 0.5f);+ cutscene_end(e);+ return;+ CO_END(c);+}+static void granny7_end(Ent *e, bool skipped) { /* EndTalking */+ Granny7 *s = ST(e, Granny7);+ (void)skipped;+ player_set_state(&g_player, ST_NORMAL);+ g_player.force_camera_update = false;+ NPC_(s->granny)->i[0]++;+ spr_play(&NPC_(s->granny)->spr, A_granny_idle, false);+}+static const EntClass GRANNY7 = {.name = "npc07xGrannyTalk", .size = sizeof(Granny7), .update = granny7_update};+static void granny7_talk(Ent *e) {+ Ent *cs = scene_new(&GRANNY7, granny7_end, true, false);+ if (cs) ST(cs, Granny7)->granny = e;+}+static void new_granny7(const EData *d) {+ Ent *e = npc_new(d->x, d->y, SB_granny, A_granny_idle, NULL);+ if (!e) return;+ Npc *n = NPC_(e);+ n->which = NPC_GRANNY07X;+ n->spr.sx = -1;+ n->move_anim = A_granny_walk, n->maxspeed = 40;+ npc_talker(e, -20, -8, 40, 8, v2(0, -24), granny7_talk);+ npc_haha(e);+}++/* ---------------------------------------------------------------- CS07_Credits */+/* After the summit, scenes of the climb play with Madeline walking left and Badeline along, while the credits+ * roll. The game's own staff credits are not shown: in their place, what this is and who made it. */+static const char *const CREDITS_TEXT[6] = {"Inspired by Celeste,", "not affiliated with", "Maddy Makes Games", "",+ "Made by Mason Chen", "as part of NumPlay"};+static float linear(float t) { return t; }+/* the player's animations Badeline's sprite has too (ChaserState.Animation, Sprite.Has) */+static const uint8_t BL_ANIMS[][2] = {+ {A_player_idle, A_badeline_idle}, {A_player_idleA, A_badeline_idleA}, {A_player_idleB, A_badeline_idleB},+ {A_player_idleC, A_badeline_idleC}, {A_player_lookUp, A_badeline_lookUp}, {A_player_walk, A_badeline_walk},+ {A_player_push, A_badeline_push}, {A_player_runSlow, A_badeline_runSlow}, {A_player_runFast, A_badeline_runFast},+ {A_player_runStumble, A_badeline_runStumble}, {A_player_dash, A_badeline_dash}, {A_player_slide, A_badeline_slide},+ {A_player_jumpSlow, A_badeline_jumpSlow}, {A_player_jumpFast, A_badeline_jumpFast}, {A_player_fallSlow, A_badeline_fallSlow},+ {A_player_fallFast, A_badeline_fallFast}, {A_player_tired, A_badeline_tired}, {A_player_wallslide, A_badeline_wallslide},+ {A_player_climbup, A_badeline_climbup}, {A_player_duck, A_badeline_duck}, {A_player_edge, A_badeline_edge},+ {A_player_sleep, A_badeline_sleep}, {A_player_faint, A_badeline_faint}, {A_player_fainted, A_badeline_fainted},+ {A_player_flip, A_badeline_flip}, {A_player_skid, A_badeline_skid}, {A_player_dangling, A_badeline_dangling},+ {A_player_spin, A_badeline_spin}, {A_player_hug, A_badeline_hug}};+#define CHASE 32+typedef struct { float x, y; uint32_t frame; uint8_t anim, left, ground, pad; } Chase;+enum { EVT_NONE, EVT_WAITJUMPDASH, EVT_WAITJUMPDOUBLEDASH, EVT_CLIMBDOWN, EVT_WAIT, EVT_BADELINEOFFSET, EVT_OSHIRO };+typedef struct { Ent *e; float angle, dist, p; uint8_t remove_at_end, on; } Around;+typedef struct {+ Co co, ev;+ Step cam;+ Walk walk;+ V2 bl_from, cam_target, osh_target, from, to, dusty_off, dusty_start, override;+ float fade, bg_fade, fade_target, walk_offset, bl_approach, p, high_player, high_baddy, scroll, bottom_timer, dusty_t;+ float cam_dur, cam_delay, other_vy;+ Ent *bl, *other, *oshiro, *bird, *dust[3];+ Around around[3];+ float (*cam_ease)(float);+ Chase chase[CHASE];+ int chase_n, chase_head;+ uint8_t active, room_seen, event, auto_walk, auto_cam, bl_float, bl_walk, fading, cam_on, bl_appr, dusty_on, osh_moving;+ uint8_t ev_on, wait_par, dashing, high, broom, post, need_setup;+} Credits;+enum { OFF_credits = ((END_streaks + 7) & ~7), END_credits = OFF_credits + (int)sizeof(Credits) };+#define cr (*(Credits *)(void *)(g_chram[7] + OFF_credits))+static bool have_ch7(void) { return g_level.ch && (rd16(g_level.ch + CH_FILES) >> 7 & 1); }++static void credits_begin(void) { /* AreaComplete: the session goes on in credits-summit, with CS07_Credits */+ memset(&cr, 0, sizeof cr);+ cr.active = 1;+ cr.fade = 1;+ g_session.has_respawn = 0;+ level_goto("credits-summit");+}+/* the Fill backdrop: black over the background */+static void fill_render(Ent *e) {+ (void)e;+ if (cr.bg_fade > 0) gfx_rect(g_level.cam.x - 10, g_level.cam.y - 10, 340, 200, 0, a8(cr.bg_fade));+}+static const EntClass FILL = {.name = "creditsFill", .render = fill_render};++/* Player.GetChasePosition: what Madeline did timeAgo seconds ago */+static bool chase_get(float time_ago, Chase *out) {+ bool older = false;+ for (int k = 0; k < cr.chase_n; k++) {+ Chase *s = &cr.chase[(cr.chase_head + k) % CHASE];+ float ago = (g_frame - s->frame) * DT;+ if (ago <= time_ago) {+ if (older || time_ago - ago < 0.02f) {+ *out = *s;+ return true;+ }+ return false;+ }+ older = true;+ }+ return false;+}+static void chase_record(Player *p) { /* Player.ChaserStates (each update) */+ int i = (cr.chase_head + cr.chase_n) % CHASE;+ if (cr.chase_n < CHASE) cr.chase_n++;+ else cr.chase_head = (cr.chase_head + 1) % CHASE;+ Chase *s = &cr.chase[i];+ s->x = p->ent->x, s->y = p->ent->y, s->frame = g_frame;+ s->anim = p->spr.anim, s->left = p->facing < 0, s->ground = p->on_ground;+}+static int bl_anim(int player_anim) {+ for (unsigned i = 0; i < sizeof BL_ANIMS / 2; i++)+ if (BL_ANIMS[i][0] == player_anim) return BL_ANIMS[i][1];+ return -1;+}+static Ent *trigger_at(int event) { /* a CreditsTrigger of that event */+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o->cls && o->dead != 1 && !strcmp(o->cls->name, "creditsTrigger") && *(uint8_t *)ST(o, uint8_t) == event) return o;+ }+ return NULL;+}+static void player_jump_dir(Player *p, int dir) { /* PlayerJump */+ p->facing = dir;+ p->dummy_friction = false;+ p->dummy_auto_animate = true;+ p->speed.x = dir * 120.f;+ player_jump(p, true, true);+ p->auto_jump = true;+ p->auto_jump_timer = 2;+}+static void player_dash_toward(Player *p, V2 dir) { /* OverrideDashDirection; StateMachine.State = StartDash() */+ cr.override = dir;+ cr.dashing = 1;+ p->dashes = p->dashes - 1 < 0 ? 0 : p->dashes - 1;+ player_set_state(p, ST_DASH);+}+static bool wall_at(Player *p, float dx, float dy) { return collide_solid(p->ent, p->ent->x + dx, p->ent->y + dy); }++/* the dust bunnies of the resort scene (DustGraphic, drawn simply: base, center, eyes) and their boxes */+typedef struct { float t, rot; uint8_t box; } Dusty;+static void dusty_render(Ent *e) {+ Dusty *d = ST(e, Dusty);+ uint16_t box = (uint16_t)(T_decals_3_resort_brokenbox_a + d->box);+ Tex t;+ if (tex_get(box, &t)) gfx_tex_ex(box, e->x, e->y - 4, t.fw / 2.f, (float)t.fh, 1, 1, 0, 0xFFFF, 255, 0);+ draw_centered(T_danger_dustcreature_base00, e->x, e->y, 0xFFFF, 255, 1, 1, d->rot);+ draw_centered(T_danger_dustcreature_center00, e->x, e->y, 0xFFFF, 255, 1, 1, 0);+ V2 dir = angle_vec(d->t, 1), perp = v2(-dir.y, dir.x);+ for (int s = -1; s <= 1; s += 2)+ draw_centered(T_danger_dustcreature_eyes00, e->x + dir.x * 5 + perp.x * 3 * s, e->y + dir.y * 5 + perp.y * 3 * s, rgb(0xFF0000), 255, 1, 1, 0);+}+static void dusty_update(Ent *e) {+ Dusty *d = ST(e, Dusty);+ d->t += DT * 0.6f;+ d->rot += DT;+}+static const EntClass DUSTY = {.name = "creditsDusty", .size = sizeof(Dusty), .update = dusty_update, .render = dusty_render};+static void broom_render(Ent *e) {+ Tex t;+ if (tex_get(T_characters_oshiro_broom, &t)) gfx_tex(T_characters_oshiro_broom, e->x - 48, e->y - 48, 0, 0xFFFF, 255); /* origin: the sprite's */+}+static const EntClass BROOM = {.name = "oshiroBroom", .render = broom_render};++/* DoEvent's events, nested in WaitForPlayer */+static bool credits_event(int which) {+ Player *p = &g_player;+ Co *c = &cr.ev;+ NB_BEGIN(c);+ if (which == EVT_WAIT) {+ if (cr.bl) spr_play(&BD(cr.bl)->spr, A_badeline_idle, false);+ cr.bl_walk = 0;+ }+ cr.auto_walk = 0;+ p->dummy_friction = true;+ NB_WAIT(c, 0.1f);+ if (which == EVT_WAITJUMPDASH) {+ player_jump_dir(p, -1);+ NB_WAIT(c, 0.2f);+ player_dash_toward(p, v2(-1, -1)); /* (not normalized: as the game) */+ NB_WAIT(c, 0.6f);+ cr.dashing = 0;+ player_set_state(p, ST_DUMMY);+ cr.auto_walk = 1;+ } else if (which == EVT_WAITJUMPDOUBLEDASH) {+ p->facing = 1;+ NB_WAIT(c, 0.25f);+ if (cr.bl) { /* BadelineCombine */+ cr.bl_float = 0;+ cr.from = v2(cr.bl->x, cr.bl->y);+ for (cr.p = 0; cr.p < 1; cr.p += DT / 0.25f) {+ {+ V2 at = v2lerp(cr.from, v2(p->ent->x, p->ent->y), ease_cube_in(cr.p));+ cr.bl->x = at.x, cr.bl->y = at.y;+ }+ NB_YIELD(c);+ }+ cr.bl->visible = 0;+ }+ p->dashes = 2;+ NB_WAIT(c, 0.5f);+ p->facing = -1;+ NB_WAIT(c, 0.7f);+ player_jump_dir(p, -1);+ NB_WAIT(c, 0.4f);+ player_dash_toward(p, v2(-1, -1)); /* (not normalized: as the game) */+ NB_WAIT(c, 0.6f);+ player_dash_toward(p, v2(-1, 0));+ NB_WAIT(c, 0.6f);+ cr.dashing = 0;+ player_set_state(p, ST_DUMMY);+ cr.auto_walk = 1;+ while (!actor_on_ground(p->ent, 1)) NB_YIELD(c);+ cr.auto_walk = 0;+ p->dummy_friction = true;+ p->dashes = 2;+ NB_WAIT(c, 0.5f);+ p->facing = 1;+ NB_WAIT(c, 1);+ if (cr.bl) cr.bl->x = p->ent->x, cr.bl->y = p->ent->y, cr.bl->visible = 1;+ cr.bl_float = 1;+ p->dashes = 1;+ NB_WAIT(c, 0.8f);+ p->facing = -1;+ cr.auto_walk = 1;+ p->dummy_friction = false;+ } else if (which == EVT_CLIMBDOWN) {+ player_jump_dir(p, -1);+ NB_WAIT(c, 0.4f);+ while (!wall_at(p, -1, 0)) NB_YIELD(c);+ p->dummy_auto_animate = false;+ spr_play(&p->spr, A_player_wallslide, false);+ while (wall_at(p, -1, 32)) {+ if (level_on_interval(0.01f)) dust_burst(v2add(player_center(p), v2(-5, 4)), -PI_F / 2, 1); /* CreateWallSlideParticles */+ p->speed.y = fminf(p->speed.y, 40);+ NB_YIELD(c);+ }+ player_jump_dir(p, 1);+ NB_WAIT(c, 0.4f);+ while (!wall_at(p, 1, 0)) NB_YIELD(c);+ p->dummy_auto_animate = false;+ spr_play(&p->spr, A_player_wallslide, false);+ while (!wall_at(p, 0, 32)) {+ if (level_on_interval(0.01f)) dust_burst(v2add(player_center(p), v2(5, 4)), -PI_F / 2, 1);+ p->speed.y = fminf(p->speed.y, 40);+ NB_YIELD(c);+ }+ player_jump_dir(p, -1);+ NB_WAIT(c, 0.4f);+ cr.auto_walk = 1;+ } else if (which == EVT_WAIT) {+ p->dummy_auto_animate = false;+ p->speed = v2(0, 0);+ NB_WAIT(c, 0.5f);+ spr_play(&p->spr, A_player_lookUp, false);+ NB_WAIT(c, 2);+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls && g_ents[i].dead != 1 && !strcmp(g_ents[i].cls->name, "bird")) ST(&g_ents[i], Bird)->auto_fly = 1;+ NB_WAIT(c, 0.1f);+ spr_play(&p->spr, A_player_idle, false);+ NB_WAIT(c, 1);+ cr.auto_walk = 1;+ p->dummy_friction = false;+ p->dummy_auto_animate = true;+ cr.bl_walk = 1;+ cr.bl_approach = 0;+ if (cr.bl) {+ cr.bl_from = v2(cr.bl->x, cr.bl->y);+ spr_play(&BD(cr.bl)->spr, A_badeline_walk, false);+ }+ while (cr.bl_approach < 1) {+ cr.bl_approach += DT * 4;+ NB_YIELD(c);+ }+ }+ NB_END(c);+}+/* WaitForPlayer: until Madeline is past the room's middle, with the triggers' events on the way */+static bool credits_wait_player(void) {+ Player *p = level_player();+ if (cr.ev_on) {+ if (credits_event(cr.event)) return true;+ cr.ev_on = 0;+ cr.event = 0;+ return true; /* Event = null; yield return null */+ }+ if (!p || p->ent->x <= room()->x + 160) return false;+ if (cr.event == EVT_WAITJUMPDASH || cr.event == EVT_WAITJUMPDOUBLEDASH || cr.event == EVT_CLIMBDOWN || cr.event == EVT_WAIT) {+ cr.ev_on = 1;+ memset(&cr.ev, 0, sizeof cr.ev);+ return true; /* yield return DoEvent(Event): it begins next update */+ }+ cr.event = 0;+ return true;+}+/* BadelineAround: a Badeline circling Madeline */+static void around_start(int i, V2 start, V2 around, Ent *bl) {+ Around *a = &cr.around[i];+ a->remove_at_end = bl == NULL;+ a->e = bl ? bl : bd_new(start);+ if (!a->e) return;+ spr_play(&BD(a->e)->spr, A_badeline_fallSlow, false);+ a->angle = atan2f(start.y - around.y, start.x - around.x);+ a->dist = v2len(v2sub(around, start));+ a->p = 0;+ a->on = 2;+ cr.to = around;+}+static void around_step(Around *a) {+ if (a->on == 2) {+ a->on = 1;+ return;+ }+ if (a->p < 1) {+ float num = a->p * 2, yo = a->p <= 0.5f ? a->p * 2 : 1 - (a->p - 0.5f) * 2;+ V2 at = v2add(cr.to, angle_vec(a->angle - num * PI_F * 2, a->dist + yo * 16 + sinf(a->p * PI_F * 2 * 4) * 5));+ a->e->x = at.x, a->e->y = at.y;+ BD(a->e)->spr.sx = (float)sgn(cr.to.x - a->e->x);+ if (!a->remove_at_end) g_player.facing = sgn(a->e->x - g_player.ent->x) ? sgn(a->e->x - g_player.ent->x) : g_player.facing;+ if (level_on_interval(0.1f)) {+ BDummy *b = BD(a->e);+ uint16_t t = spr_tex(&b->spr);+ if (t != 0xFFFF) trail_add(a->e->x, a->e->y, t, b->spr.ox, b->spr.oy, b->spr.sx, b->spr.sy, 0xAC3232, 1); /* Player.NormalHairColor */+ }+ a->p += DT / 3;+ return;+ }+ if (a->remove_at_end) bd_vanish(a->e);+ else spr_play(&BD(a->e)->spr, A_badeline_laugh, false);+ a->on = 0;+}+/* SetupLevel */+static bool credits_setup(void) {+ Player *p = level_player();+ if (!p) return true;+ player_intro_none(p);+ cr.bl = bd_new(v2(p->ent->x + 16, p->ent->y - 16));+ if (cr.bl) BD(cr.bl)->floatness = 4;+ cr.bl_float = 1, cr.bl_walk = 0, cr.bl_approach = 0;+ g_session.inv_dashes = 1;+ p->dashes = p->inventory_dashes = 1;+ player_set_state(p, ST_DUMMY);+ p->dummy_friction = false;+ p->dummy_maxspeed = false;+ p->facing = -1;+ cr.auto_walk = 1, cr.auto_cam = 1;+ g_level.cam_offset = v2(70, -24);+ g_level.cam = player_camera_target(p);+ cr.chase_n = 0;+ return false;+}+static void credits_next(const char *room_name) { /* NextLevel (its two yields follow) */+ for (int i = 0; i < 3; i++) cr.around[i].on = 0, cr.dust[i] = NULL;+ cr.bl = cr.other = cr.oshiro = cr.bird = NULL;+ cr.cam_on = cr.bl_appr = cr.dusty_on = cr.osh_moving = cr.fading = cr.high = cr.wait_par = cr.broom = 0;+ level_goto(room_name);+}+static void credits_fade(float target) { cr.fade_target = target, cr.fading = 1; }+static void credits_camera(V2 target, float duration, float (*ease)(float)) {+ step_reset(&cr.cam);+ cr.cam_target = target, cr.cam_dur = duration, cr.cam_ease = ease;+ cr.cam_on = 2;+}+static void credits_done(void) { /* OnEnd: on to the Epilogue */+ cr.active = 0;+ level_complete_area(false, true);+}+static void credits_routine(void) {+ Player *p = level_player();+ Co *c = &cr.co;+ CO_BEGIN(c);+ g_level.in_credits = true;+ g_level.completed = true;+ CO_YIELD(c);+ g_wipe.active = false;+ CO_WAIT(c, 0.5f);+ CO_WAIT(c, 3);+ cr.bg_fade = 0;+ credits_fade(0);+ CO_NEST(c, credits_setup());+ CO_NEST(c, credits_wait_player());+ credits_fade(1);+ while (cr.fading) CO_YIELD(c);+ CO_WAIT(c, 1);+ cr.bg_fade = 0.1f;+ /* credits-dashes */+ credits_next("credits-dashes");+ CO_YIELD(c);+ CO_YIELD(c);+ CO_NEST(c, credits_setup());+ credits_fade(0);+ CO_NEST(c, credits_wait_player());+ credits_fade(1);+ while (cr.fading) CO_YIELD(c);+ CO_WAIT(c, 1);+ cr.bg_fade = 0.2f;+ /* credits-walking */+ credits_next("credits-walking");+ CO_YIELD(c);+ CO_YIELD(c);+ CO_NEST(c, credits_setup());+ credits_fade(0);+ CO_WAIT(c, 5.8f);+ cr.bl_float = 0;+ CO_WAIT(c, 0.5f);+ if (cr.bl) BD(cr.bl)->spr.sx = 1;+ CO_WAIT(c, 0.5f);+ cr.auto_walk = 0;+ p->speed = v2(0, 0);+ p->facing = 1;+ CO_WAIT(c, 1.5f);+ if (cr.bl) BD(cr.bl)->spr.sx = -1;+ CO_WAIT(c, 1);+ cr.bl_walk = 1;+ if (cr.bl) cr.bl_from = v2(cr.bl->x, cr.bl->y);+ cr.bl_appr = 1; /* BadelineApproachWalking */+ CO_WAIT(c, 0.7f);+ cr.auto_walk = 1;+ p->facing = -1;+ CO_NEST(c, credits_wait_player());+ credits_fade(1);+ while (cr.fading) CO_YIELD(c);+ CO_WAIT(c, 1);+ cr.bg_fade = 0.3f;+ /* credits-tree */+ credits_next("credits-tree");+ CO_YIELD(c);+ CO_YIELD(c);+ CO_NEST(c, credits_setup());+ cr.auto_cam = 0; /* (the Petals foreground is not drawn) */+ cr.to = v2add(g_level.cam, v2(-220, 32));+ g_level.cam.x -= 100;+ cr.bl_approach = 1, cr.bl_float = 0, cr.bl_walk = 1;+ if (cr.bl) BD(cr.bl)->floatness = 0;+ credits_fade(0);+ credits_camera(cr.to, 12, linear);+ CO_WAIT(c, 3.5f);+ if (cr.bl) spr_play(&BD(cr.bl)->spr, A_badeline_idle, false);+ cr.bl_walk = 0;+ CO_WAIT(c, 0.25f);+ cr.auto_walk = 0;+ spr_play(&p->spr, A_player_idle, false);+ p->speed = v2(0, 0);+ p->dummy_auto_animate = false;+ p->facing = 1;+ CO_WAIT(c, 0.5f);+ spr_play(&p->spr, A_player_sitDown, false);+ CO_WAIT(c, 4);+ if (cr.bl) spr_play(&BD(cr.bl)->spr, A_badeline_laugh, false);+ CO_WAIT(c, 1.75f);+ credits_fade(1);+ while (cr.fading) CO_YIELD(c);+ CO_WAIT(c, 1);+ cr.bg_fade = 0.4f;+ /* credits-clouds: Madeline and a Badeline that is a Player too, on the clouds */+ credits_next("credits-clouds");+ CO_YIELD(c);+ CO_YIELD(c);+ CO_NEST(c, credits_setup());+ cr.auto_walk = 0;+ p->speed = v2(0, 0);+ cr.auto_cam = 0;+ p->force_camera_update = false;+ if (cr.bl) cr.bl->visible = 0;+ {+ Ent *t = trigger_at(EVT_BADELINEOFFSET);+ if (t) {+ cr.other = bd_new(v2(t->x, t->y));+ if (cr.other) {+ BDummy *b = BD(cr.other);+ b->floatness = 0, b->spr.sx = -1;+ spr_play(&b->spr, A_badeline_idle, false);+ ent_box(cr.other, 8, 11, -4, -11);+ }+ cr.other_vy = 0;+ }+ }+ credits_fade(0);+ g_level.cam.y -= 100;+ credits_camera(v2add(g_level.cam, v2(0, 160)), 12, linear);+ for (cr.p = 0; cr.p < 10; cr.p += DT) {+ p = level_player();+ if (((cr.p > 3 && cr.p < 6) || cr.p > 9) && p->speed.y < 0 && actor_on_ground(p->ent, 4)) cr.high_player = 0.25f;+ if (cr.other && cr.p > 5 && cr.p < 8 && cr.other_vy < 0 && actor_on_ground(cr.other, 4)) cr.high_baddy = 0.25f;+ if (cr.high_player > 0) cr.high_player -= DT, p->speed.y = -200;+ if (cr.high_baddy > 0) cr.high_baddy -= DT, cr.other_vy = -200;+ CO_YIELD(c);+ }+ credits_fade(1);+ while (cr.fading) CO_YIELD(c);+ CO_WAIT(c, 1);+ cr.bg_fade = 0.5f;+ /* credits-resort: Oshiro sweeps the dust bunnies away */+ credits_next("credits-resort");+ CO_YIELD(c);+ CO_YIELD(c);+ CO_NEST(c, credits_setup());+ credits_fade(0);+ cr.bl_approach = 1, cr.bl_float = 0, cr.bl_walk = 1;+ if (cr.bl) BD(cr.bl)->floatness = 0;+ {+ Ent *t = trigger_at(EVT_OSHIRO);+ V2 at = t ? v2(t->x, t->y + 4) : v2(room()->x + 52.f, room()->y + 148.f);+ cr.oshiro = npc_new(at.x, at.y, SB_oshiro, A_oshiro_sweeping, NULL);+ if (cr.oshiro) {+ Npc *n = NPC_(cr.oshiro);+ n->move_anim = n->idle_anim = A_oshiro_sweeping;+ n->maxspeed = 10;+ n->which = NPC_OSHIRO;+ cr.oshiro->depth = -60;+ }+ cr.dusty_start = cr.dusty_off = v2add(at, v2(220, -24)); /* DustyRoutine */+ for (int i = 0; i < 3; i++) {+ cr.dust[i] = ent_new(&DUSTY, cr.dusty_off.x + i * 24, cr.dusty_off.y);+ if (cr.dust[i]) cr.dust[i]->depth = -50, cr.dust[i]->collidable = 0, ST(cr.dust[i], Dusty)->box = (uint8_t)i, ST(cr.dust[i], Dusty)->t = rndf();+ }+ cr.dusty_t = 0, cr.dusty_on = 1;+ }+ CO_WAIT(c, 4.8f);+ if (cr.oshiro) {+ cr.osh_target = v2add(v2(cr.oshiro->x, cr.oshiro->y), v2(116, 0));+ npc_move_to(cr.oshiro, cr.osh_target, false, 0, false); /* (a coroutine of its own) */+ }+ CO_WAIT(c, 2);+ cr.auto_cam = 0;+ step_reset(&cr.cam);+ CO_NEST(c, camera_to(&cr.cam, v2((float)room()->x + 64, (float)room()->y), 2, NULL));+ CO_WAIT(c, 5);+ if (cr.oshiro) {+ cr.bird = bird_new(v2add(v2(cr.oshiro->x, cr.oshiro->y), v2(280, -160)), BIRD_NONE);+ if (cr.bird) {+ cr.bird->depth = 10010;+ Bird *b = ST(cr.bird, Bird);+ b->facing = -1;+ spr_play(&b->spr, A_bird_fall, false);+ cr.from = v2(cr.bird->x, cr.bird->y);+ cr.to = v2add(cr.osh_target, v2(50, -12));+ }+ }+ for (cr.p = 0; cr.bird && cr.p < 1; cr.p += DT * 0.5f) {+ {+ V2 at = v2lerp(cr.from, cr.to, ease_quad_out(cr.p));+ cr.bird->x = at.x, cr.bird->y = at.y;+ if (cr.p > 0.5f) {+ spr_play(&ST(cr.bird, Bird)->spr, A_bird_fly, false);+ if (cr.bird->depth != -1000000) cr.bird->depth = -1000000, ents_mark_unsorted();+ }+ }+ CO_YIELD(c);+ }+ if (cr.bird) {+ cr.bird->x = cr.to.x, cr.bird->y = cr.to.y;+ spr_play(&ST(cr.bird, Bird)->spr, A_bird_idle, false);+ }+ if (cr.oshiro) {+ NPC_(cr.oshiro)->mv.step = 0; /* oshiroRoutine.RemoveSelf() */+ spr_play(&NPC_(cr.oshiro)->spr, A_oshiro_putBroomAway, false);+ cr.broom = 1;+ }+ CO_WAIT(c, 0.5f);+ if (cr.bird) spr_play(&ST(cr.bird, Bird)->spr, A_bird_croak, false);+ CO_WAIT(c, 0.6f);+ if (cr.oshiro) {+ Npc *n = NPC_(cr.oshiro);+ n->maxspeed = 40, n->move_anim = A_oshiro_move, n->idle_anim = A_oshiro_idle;+ npc_move_to(cr.oshiro, v2add(cr.osh_target, v2(14, 0)), false, 0, false);+ CO_AWAIT(c, &NPC_(cr.oshiro)->mv);+ }+ CO_WAIT(c, 2);+ if (cr.bird) ST(cr.bird, Bird)->fly_now = 1; /* Add(new Coroutine(bird.StartleAndFlyAway())) */+ CO_WAIT(c, 0.75f);+ if (cr.bird && cr.bird->cls) cr.bird->depth = 10010, ents_mark_unsorted();+ if (cr.oshiro) NPC_(cr.oshiro)->spr.sx = -1;+ credits_fade(1);+ while (cr.fading) CO_YIELD(c);+ CO_WAIT(c, 1);+ cr.bg_fade = 0.6f;+ /* credits-wallslide */+ credits_next("credits-wallslide");+ CO_YIELD(c);+ CO_YIELD(c);+ CO_NEST(c, credits_setup());+ cr.bl_float = 0;+ if (cr.bl) {+ BDummy *b = BD(cr.bl);+ b->floatness = 0;+ spr_play(&b->spr, A_badeline_idle, false);+ b->spr.sx = 1;+ Ent *t = trigger_at(EVT_BADELINEOFFSET);+ if (t) cr.bl->x = t->x + 8, cr.bl->y = t->y + 16;+ }+ credits_fade(0);+ cr.wait_par = 1; /* Add(new Coroutine(WaitForPlayer())) */+ while (cr.bl && level_player_ent()->x > cr.bl->x - 16) CO_YIELD(c);+ if (cr.bl) BD(cr.bl)->spr.sx = -1;+ CO_WAIT(c, 0.1f);+ cr.bl_walk = 1;+ if (cr.bl) cr.bl_from = v2(cr.bl->x, cr.bl->y), spr_play(&BD(cr.bl)->spr, A_badeline_walk, false);+ cr.bl_approach = 0;+ while (cr.bl_approach != 1) {+ cr.bl_approach = approach(cr.bl_approach, 1, DT * 4);+ CO_YIELD(c);+ }+ while (level_player_ent()->x > room()->x + 160) CO_YIELD(c);+ credits_fade(1);+ while (cr.fading) CO_YIELD(c);+ CO_WAIT(c, 1);+ cr.bg_fade = 0.7f;+ /* credits-payphone: Badeline circles Madeline */+ credits_next("credits-payphone");+ CO_YIELD(c);+ CO_YIELD(c);+ CO_NEST(c, credits_setup());+ p->speed = v2(0, 0);+ p->facing = -1;+ cr.auto_walk = 0;+ if (cr.bl) {+ BDummy *b = BD(cr.bl);+ spr_play(&b->spr, A_badeline_idle, false);+ b->floatness = 0;+ cr.bl->y = p->ent->y;+ b->spr.sx = 1;+ }+ cr.bl_float = 0;+ cr.auto_cam = 0;+ g_level.cam.x += 100;+ credits_camera(v2add(g_level.cam, v2(-200, 0)), 14, linear);+ credits_fade(0);+ CO_WAIT(c, 1.5f);+ if (cr.bl) BD(cr.bl)->spr.sx = -1;+ CO_WAIT(c, 0.5f);+ if (cr.bl) bd_float_to(cr.bl, v2(cr.bl->x + 16, cr.bl->y - 12), -1, false, false, false);+ CO_WAIT(c, 0.5f);+ p->facing = 1;+ CO_WAIT(c, 1.5f);+ if (cr.bl) {+ cr.from = v2(cr.bl->x, cr.bl->y);+ around_start(0, cr.from, player_center(p), cr.bl);+ }+ CO_WAIT(c, 0.5f);+ around_start(1, cr.from, cr.to, NULL);+ CO_WAIT(c, 0.5f);+ around_start(2, cr.from, cr.to, NULL);+ CO_WAIT(c, 3);+ if (cr.bl) spr_play(&BD(cr.bl)->spr, A_badeline_laugh, false);+ CO_WAIT(c, 0.5f);+ p->facing = -1;+ CO_WAIT(c, 0.5f);+ p->dummy_auto_animate = false;+ spr_play(&p->spr, A_player_sitDown, false);+ CO_WAIT(c, 3);+ credits_fade(1);+ while (cr.fading) CO_YIELD(c);+ CO_WAIT(c, 1);+ cr.bg_fade = 0.8f;+ /* credits-city */+ credits_next("credits-city");+ CO_YIELD(c);+ CO_YIELD(c);+ CO_NEST(c, credits_setup());+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls && g_ents[i].dead != 1 && !strcmp(g_ents[i].cls->name, "bird")) ST(&g_ents[i], Bird)->facing = 1;+ cr.bl_approach = 1, cr.bl_float = 0, cr.bl_walk = 1;+ if (cr.bl) BD(cr.bl)->floatness = 0;+ credits_fade(0);+ CO_NEST(c, credits_wait_player());+ credits_fade(1);+ while (cr.fading) CO_YIELD(c);+ CO_WAIT(c, 1);+ cr.bg_fade = 0;+ /* credits-prologue */+ credits_next("credits-prologue");+ CO_YIELD(c);+ CO_YIELD(c);+ CO_NEST(c, credits_setup());+ cr.bl_approach = 1, cr.bl_float = 0, cr.bl_walk = 1;+ if (cr.bl) BD(cr.bl)->floatness = 0;+ credits_fade(0);+ CO_NEST(c, credits_wait_player());+ credits_fade(1);+ while (cr.fading) CO_YIELD(c);+ while (cr.bottom_timer < 2) CO_YIELD(c);+ fade_wipe(false, 0.5f, credits_done); /* its end: EndCutscene */+ CO_END(c);+}+/* CS07_Credits.Update (before the player's), then its coroutines */+static const EntClass CREDITSPOST;+static void credits_update(Ent *e) {+ Player *p = level_player();+ if (!cr.active) {+ ent_remove(e);+ return;+ }+ if (cr.need_setup && p && !credits_setup()) cr.need_setup = 0;+ if (!cr.post && p) { /* (made after the player: it updates after it) */+ Ent *pe = ent_new(&CREDITSPOST, 0, 0);+ if (pe) pe->visible = pe->collidable = 0;+ cr.post = 1;+ }+ if (p && p->ent->cls) {+ if (cr.dashing) p->force_move_x = sgn(cr.override.x), p->force_move_x_timer = DT * 2; /* Input.MoveX = its x */+ if (cr.dashing && p->state == ST_DASH && p->co_step == 2 && !v2eq(p->dash_dir, cr.override)) {+ p->speed = v2mul(cr.override, 240); /* the dash goes the overridden way */+ p->dash_dir = cr.override;+ if (cr.override.x) p->facing = sgn(cr.override.x);+ }+ if (cr.auto_walk) {+ if (p->on_ground) {+ p->speed.x = -44.8f;+ bool wall = wall_at(p, -20, 0), gap = !wall_at(p, -8, 1) && !wall_at(p, -8, 32);+ if (wall || gap) {+ player_jump(p, true, true);+ p->auto_jump = true;+ p->auto_jump_timer = wall ? 0.6f : 2;+ }+ } else+ p->speed.x = -64;+ }+ if (cr.bl && cr.bl_float) {+ V2 to = v2(p->ent->x + 16, p->ent->y - 16), at = v2(cr.bl->x, cr.bl->y);+ at = v2add(at, v2mul(v2sub(to, at), 1 - powf(0.01f, DT)));+ cr.bl->x = at.x, cr.bl->y = at.y;+ BD(cr.bl)->spr.sx = -1;+ }+ if (cr.bl && cr.bl_walk) {+ Chase st;+ bool got = chase_get(0.35f + sinf(cr.walk_offset) * 0.1f, &st);+ if (got && st.ground) cr.walk_offset += DT;+ if (got) {+ BDummy *b = BD(cr.bl);+ if (cr.bl_approach >= 1) {+ cr.bl->x = st.x, cr.bl->y = st.y;+ int a = bl_anim(st.anim);+ if (a >= 0) spr_play(&b->spr, a, false);+ b->spr.sx = st.left ? -1.f : 1.f;+ } else {+ V2 at = v2lerp(cr.bl_from, v2(st.x, st.y), cr.bl_approach);+ cr.bl->x = at.x, cr.bl->y = at.y;+ }+ }+ }+ if (fabsf(p->speed.x) > 90) p->speed.x = approach(p->speed.x, 90 * sgn(p->speed.x), 1000 * DT);+ }+ /* the credits roll (Credits.Update): the lines come up the column and stay */+ cr.scroll += 100 * 0.6f * DT / 6;+ if (cr.scroll >= 180) cr.bottom_timer += DT;+ /* the coroutines: Routine, then the ones added beside it */+ credits_routine();+ if (!cr.active) return;+ if (cr.fading) { /* FadeTo */+ cr.fade = approach(cr.fade, cr.fade_target, DT * 0.5f);+ if (cr.fade == cr.fade_target) cr.fading = 0;+ }+ if (cr.cam_on == 2) cr.cam_on = 1;+ else if (cr.cam_on && !camera_to(&cr.cam, cr.cam_target, cr.cam_dur, cr.cam_ease)) cr.cam_on = 0;+ if (cr.bl_appr && cr.bl) { /* BadelineApproachWalking */+ BDummy *b = BD(cr.bl);+ if (cr.bl_approach < 1) {+ b->floatness = approach(b->floatness, 0, DT * 8);+ cr.bl_approach = approach(cr.bl_approach, 1, DT * 0.6f);+ } else+ cr.bl_appr = 0;+ }+ if (cr.wait_par && !credits_wait_player()) cr.wait_par = 0;+ for (int i = 0; i < 3; i++)+ if (cr.around[i].on && cr.around[i].e && cr.around[i].e->cls) around_step(&cr.around[i]);+ if (cr.dusty_on) { /* DustyRoutine */+ cr.dusty_t += DT;+ if (cr.dusty_t > 3.8f) {+ for (int j = 0; j < 3; j++)+ if (cr.dust[j]) cr.dust[j]->x = cr.dusty_off.x + j * 24, cr.dust[j]->y = cr.dusty_off.y + sinf((cr.dusty_t - 3.8f) * 4 + j * 0.8f) * 4;+ if (cr.dusty_off.x < room()->x + 120) cr.dusty_off.y = approach(cr.dusty_off.y, cr.dusty_start.y + 16, DT * 16);+ cr.dusty_off.x -= 26 * DT;+ }+ }+ if (cr.broom && cr.oshiro && NPC_(cr.oshiro)->spr.anim == A_oshiro_putBroomAway && NPC_(cr.oshiro)->spr.frame == 10) {+ Ent *b = ent_new(&BROOM, cr.oshiro->x, cr.oshiro->y); /* the broom stays behind */+ if (b) b->depth = cr.oshiro->depth + 1, b->collidable = 0;+ cr.broom = 0;+ }+ if (cr.other) { /* the other Player (Badeline): in its dummy state, falling, landing */+ cr.other_vy = approach(cr.other_vy, 160, 900 * DT);+ if (!actor_move_v(cr.other, cr.other_vy * DT, NULL, NULL) && cr.other_vy > 0 && actor_on_ground(cr.other, 1)) cr.other_vy = 0;+ else if (actor_on_ground(cr.other, 1) && cr.other_vy > 0) cr.other_vy = 0;+ }+}+/* PostUpdate: the camera follows Madeline; and her ChaserStates */+static void credits_post(Ent *e) {+ Player *p = level_player();+ (void)e;+ if (!cr.active || !p || !p->ent->cls) return;+ chase_record(p);+ if (!cr.auto_cam) return;+ V2 t = player_camera_target(p);+ if (!p->on_ground) t.y = (g_level.cam.y * 2 + t.y) / 3;+ g_level.cam = v2add(g_level.cam, v2mul(v2sub(t, g_level.cam), 1 - powf(0.01f, DT)));+ g_level.cam.x = (float)(int)t.x;+}+static void credits_render(Ent *e) {+ (void)e;+ if (g_level.paused) return;+ gfx_hud(true);+ /* creditsgradient (Gui): black, from nothing at 145 to 0.9 at 225, at 0.6 */+ for (int x = 145; x < 225; x += 8) gfx_rect((float)x, -2, 8, 184, 0, a8(0.6f * 0.9f * (x - 145 + 4) / 80.f));+ gfx_rect(225, -2, 97, 184, 0, a8(0.6f * 0.9f));+ if (cr.fade > 0) gfx_rect(-2, -2, 324, 184, 0, a8(ease_cube_inout(cr.fade)));+ float lh = font_line_height(FONT_S), y = 180 + 8 - cr.scroll;+ if (y < 90 - lh * 3) y = 90 - lh * 3;+ for (int i = 0; i < 6; i++)+ if (CREDITS_TEXT[i][0]) font_draw_justified(CREDITS_TEXT[i], 303, y + i * lh, 1, 0, FONT_S, 0xFFFF, 255);+ gfx_hud(false);+}+static const EntClass CREDITS = {.name = "CS07_Credits", .update = credits_update, .render = credits_render};+static const EntClass CREDITSPOST = {.name = "CS07_CreditsPostUpdate", .update = credits_post};+/* a room of the credits loads: the cutscene, its backdrop fill and its post update are in it */+static void credits_room(void) {+ if (!have_ch7() || !cr.active || !g_level.room) return;+ for (int i = 0; i < g_nents; i++) /* (one per load) */+ if (g_ents[i].cls == &CREDITS) return;+ /* what was made in the room before is gone; the same room again (a death): set up again */+ for (int i = 0; i < 3; i++) cr.around[i].on = 0, cr.dust[i] = NULL;+ cr.bl = cr.other = cr.oshiro = cr.bird = NULL;+ cr.need_setup = cr.room_seen == (uint8_t)(g_level.room->index + 1);+ cr.room_seen = (uint8_t)(g_level.room->index + 1);+ Ent *e = ent_new(&CREDITS, 0, 0);+ if (e) e->tags = TAG_HUD, e->collidable = 0, e->depth = -2000000;+ e = ent_new(&FILL, 0, 0);+ if (e) e->depth = 2000000, e->collidable = 0;+ cr.post = 0;+}+/* CreditsTrigger: its event to the credits */+static void ctrig_enter(Ent *e, Player *p) {+ (void)p;+ if (have_ch7() && cr.active) cr.event = *ST(e, uint8_t);+}+static const EntClass CTRIG = {.name = "creditsTrigger", .size = 4, .on_enter = ctrig_enter, .kind = KIND_TRIGGER};++/* ---------------------------------------------------------------- the factories */+bool ents_ch7(const EData *d) {+ credits_room();+ switch (d->type) {+ case ET_summitcheckpoint: new_scheck(d); return true;+ case ET_summitgem: new_gem(d); return true;+ case ET_summitGemManager: new_gemmgr(d); return true;+ case ET_summitcloud: new_scloud(d); return true;+ case ET_SummitBackgroundManager: new_ascendm(d); return true;+ case ET_npc:+ if (strcmp(EAS(d, npc, npc), "granny_07x")) return false;+ new_granny7(d);+ return true;+ }+ return false;+}+bool trigs_ch7(const EData *d) {+ if (d->type == TT_creditsTrigger) {+ static const char *const EVENTS[6] = {"WaitJumpDash", "WaitJumpDoubleDash", "ClimbDown", "Wait", "BadelineOffset", "Oshiro"};+ const char *ev = EAS(d, creditsTrigger, event);+ uint8_t which = EVT_NONE;+ for (int i = 0; i < 6; i++)+ if (!strcmp(ev, EVENTS[i])) which = (uint8_t)(i + 1);+ Ent *e = ent_new(&CTRIG, d->x, d->y);+ if (e) ent_box(e, EA(d, creditsTrigger, width), EA(d, creditsTrigger, height), 0, 0), e->visible = 0, *ST(e, uint8_t) = which;+ return true;+ }+ if (d->type == TT_eventTrigger && !strcmp(EAS(d, eventTrigger, event), "ch7_summit")) {+ Ent *e = ent_new(&SUMMITTRIG, d->x, d->y);+ float w = EA(d, eventTrigger, width), h = EA(d, eventTrigger, height);+ if (e) ent_box(e, w, h, 0, 0), e->visible = 0, ST(e, Summit)->target = v2(d->x + w / 2, d->y + h);+ return true;+ }+ return false;+}+uint32_t ch7_ram(void) { return END_credits; }diff --git a/games/celeste/src/ch8.c b/games/celeste/src/ch8.cnew file mode 100644index 00000000..ce806aeb--- /dev/null+++ b/games/celeste/src/ch8.c@@ -0,0 +1,349 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* The Epilogue (chapter 8): the fixed bridge (the Summit's credits have it too),+ * Granny and Theo in the cabin (NPC08_Granny, NPC08_Theo), the door+ * (CS08_EnterDoor) and the ending (CS08_Ending: the cabin, the pie and the+ * totals). Line by line from the game's code. */+#include "badeline.h"++/* ---------------------------------------------------------------- BridgeFixed */+static void bridgefixed_render(Ent *e) {+ for (int i = 0; i < e->cw; i += 208) gfx_tex(T_scenery_bridge_fixed, e->x + i, e->y - 8, 0, 0xFFFF, 255);+}+static const EntClass BRIDGEFIXED = {.name = "bridgeFixed", .update = plat_update, .render = bridgefixed_render, .kind = KIND_SOLID};+static void new_bridge_fixed(const EData *d) {+ Ent *e = ent_new(&BRIDGEFIXED, d->x, d->y);+ if (!e) return;+ ent_box(e, EA(d, bridgeFixed, width), 8, 0, 0);+ e->safe = 1;+}++/* ---------------------------------------------------------------- CS08_Ending */+typedef struct {+ Cutscene cs;+ Ent *granny, *theo, *badeline, *oshiro, *tb;+ Walk walk;+ Co ev;+ int8_t ev_i;+ uint8_t ending, vignette, steps, show_version, started;+ float fade, version_alpha, p, p2, scale_from, rot_from;+ V2 pos_from;+ float vg_alpha, vg_scale, vg_rot, bg_white; /* the vignette (its position: vg_pos), finalbg's color */+ V2 vg_pos, counters; /* the totals' place, interface pixels */+} Ending8;+static const char *const PIE[5] = {"EP_PIE_DISAPPOINTED", "EP_PIE_GROSSED_OUT", "EP_PIE_OKAY", "EP_PIE_REALLY_GOOD", "EP_PIE_AMAZING"};++/* the Oshiro that comes in: an Entity with an OshiroSprite(1) */+typedef struct { Sprite spr; Wiggler wig; } Oshiro8;+static void oshiro8_update(Ent *e) {+ Oshiro8 *o = ST(e, Oshiro8);+ oshiro_sprite_update(&o->spr, &o->wig);+ Room *rm = g_level.room; /* AllowTurnInvisible */+ o->spr.visible = e->x > rm->x - 8 && e->y > rm->y - 8 && e->x < rm->x + rm->w + 8 && e->y < rm->y + rm->h + 16;+}+static void oshiro8_render(Ent *e) { spr_draw(&ST(e, Oshiro8)->spr, e->x, e->y); }+static const EntClass OSHIRO8 = {.name = "oshiroSprite", .size = sizeof(Oshiro8), .update = oshiro8_update, .render = oshiro8_render};++static bool ending_nb(Ending8 *s, Co *c, int i) {+ Player *p = &g_player;+ switch (i) {+ case 0: /* BadelineEmerges */+ NB_BEGIN(c);+ g_session.inv_dashes = 1; /* (the displacement burst is not drawn) */+ p->dashes = p->inventory_dashes = 1;+ s->badeline = bd_new(v2(p->ent->x, p->ent->y));+ if (!s->badeline) NB_YIELD(c);+ else {+ BD(s->badeline)->spr.sx = 1;+ bd_float_to(s->badeline, v2(p->ent->x - 12, p->ent->y - 16), 1, false, false, false);+ NB_AWAIT(c, &BD(s->badeline)->job);+ }+ NB_END(c);+ case 1: /* OshiroEnters */+ NB_BEGIN(c);+ fade_wipe(false, 1.5f, NULL);+ NB_NEST(c, wipe_busy());+ s->fade = 1;+ NB_WAIT(c, 0.25f);+ {+ float x = p->ent->x;+ p->ent->x = s->granny->x + 8;+ if (s->badeline) s->badeline->x = p->ent->x + 12, BD(s->badeline)->spr.sx = -1;+ p->facing = -1;+ s->granny->x = x + 8;+ s->theo->x += 16;+ }+ s->oshiro = ent_new(&OSHIRO8, s->granny->x - 24, s->granny->y + 4);+ if (s->oshiro) {+ Oshiro8 *o = ST(s->oshiro, Oshiro8);+ spr_init(&o->spr, SB_oshiro);+ o->spr.sx = 1;+ wiggler_init(&o->wig, 0.3f, 2);+ }+ s->fade = 0;+ fade_wipe(true, 1, NULL);+ NB_WAIT(c, 0.25f);+ while (s->oshiro && s->oshiro->y > s->granny->y - 4) {+ s->oshiro->y -= DT * 32;+ NB_YIELD(c);+ }+ NB_END(c);+ case 2: /* OshiroSettles */+ NB_BEGIN(c);+ if (s->oshiro) {+ s->pos_from = v2(s->oshiro->x, s->oshiro->y);+ for (s->p = 0; s->p < 1; s->p += DT) {+ {+ V2 at = v2lerp(s->pos_from, v2add(s->pos_from, v2(40, 8)), s->p);+ s->oshiro->x = at.x, s->oshiro->y = at.y;+ }+ NB_YIELD(c);+ }+ }+ NPC_(s->granny)->spr.sx = 1;+ NB_YIELD(c);+ NB_END(c);+ default: /* MaddyTurns */+ NB_BEGIN(c);+ NB_WAIT(c, 0.1f);+ p->facing = -p->facing;+ NB_WAIT(c, 0.1f);+ NB_END(c);+ }+}+static bool ending_ev(void *ctx, int i) {+ Ending8 *s = ST((Ent *)ctx, Ending8);+ return !ending_nb(s, ev_co(&s->ev, &s->ev_i, i), i);+}+static void ending_update(Ent *e) {+ Ending8 *s = ST(e, Ending8);+ Player *p = &g_player;+ Co *c = &s->cs.co;+ s->version_alpha = approach(s->version_alpha, s->show_version ? 1 : 0, DT * 5);+ CO_BEGIN(c);+ zoom_snap(v2(164, 120), 2);+ g_wipe.active = false; /* Wipe.Cancel() */+ fade_wipe(true, 0.5f, NULL);+ player_intro_none(p);+ while (!s->granny || !s->theo) {+ s->granny = npc_find(NPC_GRANNY08);+ s->theo = npc_find(NPC_THEO08);+ CO_YIELD(c);+ }+ player_set_state(p, ST_DUMMY);+ s->started = 1;+ CO_WAIT(c, 1);+ CO_WALK(c, s->walk, walk_exact((int)p->ent->x + 16));+ CO_WAIT(c, 0.25f);+ s->ev_i = -1;+ CO_SAY(c, s->tb, "EP_CABIN", ending_ev, e);+ fade_wipe(false, 1.5f, NULL);+ CO_NEST(c, wipe_busy());+ s->fade = 1;+ CO_SAY(c, s->tb, "EP_PIE_START", NULL, NULL);+ CO_WAIT(c, 0.5f);+ s->vignette = 1, s->bg_white = 0, s->vg_alpha = 0, s->vg_pos = v2(960, 540);+ for (s->p = 0; s->p < 1; s->p += DT) {+ s->vg_alpha = ease_cube_in(s->p);+ s->vg_scale = 1 + 0.25f * (1 - s->p);+ s->vg_rot = 0.05f * (1 - s->p);+ CO_YIELD(c);+ }+ s->vg_alpha = 1, s->bg_white = 1;+ CO_WAIT(c, 2);+ for (s->p2 = 0; s->p2 < 1; s->p2 += DT / 1) {+ {+ float k = ease_cube_out(s->p2);+ s->vg_pos = v2lerp(v2(960, 540), v2(960, 680), k);+ s->vg_scale = 0.65f + 0.35f * (1 - k);+ s->vg_rot = -0.025f * k;+ }+ CO_YIELD(c);+ }+ CO_SAY(c, s->tb, PIE[s->ending], NULL, NULL);+ CO_WAIT(c, 0.25f);+ s->pos_from = s->vg_pos, s->rot_from = s->vg_rot, s->scale_from = s->vg_scale;+ for (s->p = 0; s->p < 1; s->p += DT / 2) {+ {+ float k = ease_cube_out(s->p);+ s->vg_pos = v2lerp(s->pos_from, v2(960, 540), k);+ s->vg_scale = lerpf(s->scale_from, 1, k);+ s->vg_rot = lerpf(s->rot_from, 0, k);+ }+ CO_YIELD(c);+ }+ cutscene_end(e); /* EndCutscene(level, removeSelf: false): the totals go on in another entity */+ return;+ CO_END(c);+}+/* Dialog.FileTime: hours:mm:ss.fff */+static int file_time(char *b, uint32_t frames) {+ uint32_t ms = (uint32_t)(frames * 1000.0 / 60), h = ms / 3600000, m = ms / 60000 % 60, sec = ms / 1000 % 60, f = ms % 1000;+ char *o = b;+ char tmp[12];+ int k = 0;+ do tmp[k++] = (char)('0' + h % 10), h /= 10;+ while (h);+ while (k) *o++ = tmp[--k];+ *o++ = ':', *o++ = (char)('0' + m / 10), *o++ = (char)('0' + m % 10), *o++ = ':', *o++ = (char)('0' + sec / 10);+ *o++ = (char)('0' + sec % 10), *o++ = '.', *o++ = (char)('0' + f / 100), *o++ = (char)('0' + f / 10 % 10);+ *o++ = (char)('0' + f % 10), *o = 0;+ return (int)(o - b);+}+static void ending_render(Ent *e) {+ Ending8 *s = ST(e, Ending8);+ if (g_level.paused) return;+ gfx_hud(true);+ if (s->fade > 0) gfx_rect(-2, -2, 324, 184, 0, (uint8_t)(clampf(s->fade, 0, 1) * 255));+ if (s->vignette) { /* Portraits "finalbg" and "final1".."final5" (kept at half size, drawn twice as big) */+ static const uint16_t FINAL[5] = {T__final1, T__final2, T__final3, T__final4, T__final5};+ uint16_t bg = T__finalbg, vg = FINAL[s->ending];+ Tex t;+ if (tex_get(bg, &t)) gfx_tex(bg, 0, 0, 0, s->bg_white ? 0xFFFF : 0, 255);+ if (tex_get(vg, &t))+ gfx_tex_ex(vg, s->vg_pos.x / 6, s->vg_pos.y / 6, t.fw * t.scale / 2.f, t.fh * t.scale / 2.f, s->vg_scale, s->vg_scale, s->vg_rot,+ 0xFFFF, (uint8_t)(clampf(s->vg_alpha, 0, 1) * 255), 0);+ }+ if (s->steps) { /* StrawberriesCounter (of 175), DeathsCounter, TimeDisplay */+ char b[24];+ int n = uitoa(save_total_berries(), b);+ memcpy(b + n, "/175", 5);+ float y = s->counters.y / 6;+ font_draw_outline(b, (int)strlen(b), (s->counters.x - 170) / 6 - font_measure(b, (int)strlen(b), FONT_S) / 2, y - 4, FONT_S, 0xFFFF, 0, 255);+ uitoa((int)g_save.total_deaths, b);+ font_draw_outline(b, (int)strlen(b), (s->counters.x + 170) / 6 - font_measure(b, (int)strlen(b), FONT_S) / 2, y - 4, FONT_S, 0xFFFF, 0, 255);+ n = file_time(b, g_save.time);+ font_draw_outline(b, n, s->counters.x / 6 - font_measure(b, n, FONT_S) / 2, y + 100 / 6.f - 4, FONT_S, 0xFFFF, 0, 255);+ }+ gfx_hud(false);+}+/* EndingRoutine: the totals come up, then a press ends the chapter */+static void endtotals_update(Ent *e) {+ Ending8 *s = ST(e, Ending8);+ Co *c = &s->ev;+ s->version_alpha = approach(s->version_alpha, s->show_version ? 1 : 0, DT * 5);+ CO_BEGIN(c);+ g_level.in_cutscene = true;+ g_level.pause_lock = true;+ CO_WAIT(c, 0.5f);+ s->steps = 1;+ for (s->p = 0; s->p < 1; s->p += DT / 0.5f) {+ s->counters = v2lerp(v2(960, 1180), v2(960, 940), ease_cube_out(s->p));+ CO_YIELD(c);+ }+ s->show_version = 1; /* (the version number: none) */+ CO_WAIT(c, 0.25f);+ while (!btn_pressed(&g_in.confirm) && !btn_pressed(&g_in.jump)) CO_YIELD(c);+ s->show_version = 0;+ CO_WAIT(c, 0.25f);+ level_complete_area(false, false);+ CO_END(c);+}+static const EntClass ENDTOTALS = {.name = "CS08_EndingRoutine", .size = sizeof(Ending8), .update = endtotals_update, .render = ending_render};+static void ending_end(Ent *e, bool skipped) {+ Ending8 *s = ST(e, Ending8);+ (void)skipped;+ s->vignette = 1, s->vg_alpha = 1, s->bg_white = 1, s->vg_pos = v2(960, 540), s->vg_scale = 1, s->vg_rot = 0;+ g_player.speed = v2(0, 0);+ if (s->tb && textbox_opened(s->tb)) ent_remove(s->tb);+ Ent *t = ent_new(&ENDTOTALS, 0, 0);+ if (!t) return;+ t->tags = TAG_HUD | TAG_PAUSE_UPDATE;+ t->collidable = 0;+ Ending8 *n = ST(t, Ending8);+ *n = *s;+ memset(&n->ev, 0, sizeof n->ev);+}+static const EntClass ENDING = {.name = "CS08_Ending", .size = sizeof(Ending8), .update = ending_update, .render = ending_render};+static void ending_start(void) {+ Ent *e = scene_new(&ENDING, ending_end, false, true);+ if (!e) return;+ e->tags = TAG_HUD | TAG_PAUSE_UPDATE;+ int n = save_total_berries();+ ST(e, Ending8)->ending = (uint8_t)(n < 20 ? 0 : n < 50 ? 1 : n < 90 ? 2 : n < 150 ? 3 : 4);+}++/* ---------------------------------------------------------------- CS08_EnterDoor */+static uint8_t ending_due; /* the room "inside" loads with CS08_Ending */+typedef struct {+ Cutscene cs;+ Walk walk;+ Step zoom;+ float target_x;+ uint8_t walking, zooming;+} EnterDoor;+static void door_update(Ent *e) {+ EnterDoor *s = ST(e, EnterDoor);+ Player *p = &g_player;+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_set_state(p, ST_DUMMY);+ s->walk = walk_mult((int)s->target_x, 0.7f); /* two coroutines of their own: the walk and the zoom */+ s->walking = 2;+ step_reset(&s->zoom);+ s->zooming = 2;+ fade_wipe(false, 2, NULL);+ CO_NEST(c, wipe_busy());+ cutscene_end(e);+ return;+ CO_END(c);+}+static void door_tick(Ent *e) {+ EnterDoor *s = ST(e, EnterDoor);+ door_update(e);+ if (e->dead == 1) return;+ if (s->walking == 2) s->walking = 1;+ else if (s->walking && !player_walk(&g_player, &s->walk)) s->walking = 0;+ if (s->zooming == 2) s->zooming = 1;+ else if (s->zooming && !zoom_to(&s->zoom, v2(s->target_x - g_level.cam.x, 90), 2, 2)) s->zooming = 0;+}+static void door_end(Ent *e, bool skipped) {+ (void)e, (void)skipped;+ ending_due = 1;+ level_goto("inside");+}+static const EntClass ENTERDOOR = {.name = "CS08_EnterDoor", .size = sizeof(EnterDoor), .update = door_tick};++typedef struct { float left; uint8_t triggered; } Door8;+static void door_enter(Ent *e, Player *p) {+ Door8 *d = ST(e, Door8);+ (void)p;+ if (d->triggered) return;+ d->triggered = 1;+ Ent *cs = scene_new(&ENTERDOOR, door_end, true, false);+ if (cs) ST(cs, EnterDoor)->target_x = d->left;+}+static const EntClass DOORTRIG = {.name = "eventTrigger", .size = sizeof(Door8), .on_enter = door_enter, .kind = KIND_TRIGGER};++/* ---------------------------------------------------------------- the factories */+bool ents_ch8(const EData *d) {+ if (ending_due && g_session.area == 8) { /* LoadLevel(IntroTypes.None), then CS08_Ending is added */+ ending_due = 0;+ ending_start();+ }+ switch (d->type) {+ case ET_bridgeFixed: new_bridge_fixed(d); return true;+ case ET_npc: {+ const char *who = EAS(d, npc, npc);+ bool granny = !strcmp(who, "granny_08_inside");+ if (!granny && strcmp(who, "theo_08_inside")) return false;+ Ent *e = npc_new(d->x, d->y, granny ? SB_granny : SB_theo, granny ? A_granny_idle : A_theo_idle, NULL);+ if (!e) return true;+ Npc *n = NPC_(e);+ n->spr.sx = -1;+ n->idle_anim = granny ? A_granny_idle : A_theo_idle, n->move_anim = granny ? A_granny_walk : A_theo_walk;+ n->maxspeed = 30;+ n->which = granny ? NPC_GRANNY08 : NPC_THEO08;+ if (granny) e->depth = -10;+ return true;+ }+ }+ return false;+}+bool trigs_ch8(const EData *d) {+ if (d->type != TT_eventTrigger || strcmp(EAS(d, eventTrigger, event), "ch8_door")) return false;+ Ent *e = ent_new(&DOORTRIG, d->x, d->y);+ if (e) ent_box(e, EA(d, eventTrigger, width), EA(d, eventTrigger, height), 0, 0), e->visible = 0, ST(e, Door8)->left = d->x;+ return true;+}diff --git a/games/celeste/src/ch9.c b/games/celeste/src/ch9.cnew file mode 100644index 00000000..21a64d42--- /dev/null+++ b/games/celeste/src/ch9.c@@ -0,0 +1,1712 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* Core (chapter 9): the core mode and what follows it (the switch, fire balls,+ * wall boosters, bounce blocks, fire barriers and ice blocks, rising and+ * sandwich lava), the heart gem door and Core's triggers.+ * Ported from the game's classes (CoreModeToggle.cs, FireBall.cs, LavaRect.cs...). */+#include "badeline.h"++/* ---------------------------------------------------------------- helpers (Calc) */+static float dist2(V2 a, V2 b) { return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); }+static uint16_t tex_named(const char *p) { return res_tex_by_name(p); }+static int tex_family(const char *prefix, uint16_t *out, int n) {+ char p[64];+ int k = 0;+ for (int i = 0; i < n; i++) {+ out[i] = tex_named(path2(p, prefix, NULL, i));+ if (out[i] != 0xFFFF) k = i + 1;+ }+ return k;+}+static void draw_centered(uint16_t tex, float x, float y, uint16_t tint, uint8_t alpha) {+ Tex t;+ if (tex == 0xFFFF || !tex_get(tex, &t)) return;+ float k = t.scale > 1 ? t.scale : 1; /* stored smaller, drawn scaled up */+ gfx_tex_ex(tex, x, y, t.fw * k / 2.f, t.fh * k / 2.f, 1, 1, 0, tint, alpha, 0);+}+/* Image.DrawOutline(Color.Black): the four neighbours in black */+static void draw_outlined(uint16_t tex, float x, float y, float ox, float oy, uint8_t flags, uint16_t tint, uint8_t alpha) {+ static const int8_t O[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};+ for (int k = 0; k < 4; k++) gfx_tex_ex(tex, x + O[k][0], y + O[k][1], ox, oy, 1, 1, 0, 0, alpha, flags | GF_SILHOUETTE);+ gfx_tex_ex(tex, x, y, ox, oy, 1, 1, 0, tint, alpha, flags);+}+static uint32_t lerp_rgb(uint32_t a, uint32_t b, float t) {+ t = clampf(t, 0, 1);+ int r = (int)(((a >> 16) & 255) + (((int)((b >> 16) & 255) - (int)((a >> 16) & 255)) * t));+ int g = (int)(((a >> 8) & 255) + (((int)((b >> 8) & 255) - (int)((a >> 8) & 255)) * t));+ int bl = (int)((a & 255) + (((int)(b & 255) - (int)(a & 255)) * t));+ return (uint32_t)(r << 16 | g << 8 | bl);+}+static float hash01(uint32_t seed, uint32_t i) {+ uint32_t h = seed * 0x9E3779B1u ^ (i + 0x7F4A7C15u) * 0x85EBCA6Bu;+ h ^= h >> 15, h *= 0x2C1B3C6Du, h ^= h >> 12, h *= 0x297A2D39u, h ^= h >> 15;+ return (h >> 8) / 16777216.f;+}+static uint8_t ent_ref(const Ent *e) { return (uint8_t)(e - g_ents); }+static Ent *ent_at(uint8_t i) { return &g_ents[i]; }+/* the player's hurtbox (PlayerCollider checks) */+static void player_hurtbox(const Ent *pe, float *l, float *t, float *r, float *b) {+ float w = pe->cw, h = pe->ch, x = pe->cx, y = pe->cy;+ if (h == 11) h = 9;+ else if (h == 6) h = 4;+ else if (h == 8 && w == 8) w = 6, h = 6, x = -3, y = -9;+ *l = pe->x + x, *t = pe->y + y, *r = *l + w, *b = *t + h;+}+static bool hurt_rect(const Player *p, float l, float t, float r, float b) {+ float pl, pt, pr, pb;+ player_hurtbox(p->ent, &pl, &pt, &pr, &pb);+ return pr > l && pb > t && pl < r && pt < b;+}+static bool hurt_circle(const Player *p, float cx, float cy, float rad) {+ float pl, pt, pr, pb;+ player_hurtbox(p->ent, &pl, &pt, &pr, &pb);+ float nx = clampf(cx, pl, pr), ny = clampf(cy, pt, pb);+ return (nx - cx) * (nx - cx) + (ny - cy) * (ny - cy) < rad * rad;+}++/* ---------------------------------------------------------------- compact sprites */+typedef struct { uint8_t bank, anim, frame, playing; int8_t last; uint8_t pad[3]; float timer; } CSpr;+static Sprite cs_raw(const CSpr *c) {+ Sprite s;+ memset(&s, 0, sizeof s);+ s.bank = c->bank, s.anim = c->anim, s.frame = c->frame, s.playing = c->playing;+ s.timer = c->timer, s.rate = 1, s.last_goto = c->last, s.sx = s.sy = 1, s.tint = 0xFFFF, s.alpha = 255, s.visible = 1;+ return s;+}+static void cs_back(CSpr *c, const Sprite *s) {+ c->bank = s->bank, c->anim = s->anim, c->frame = s->frame, c->playing = s->playing, c->timer = s->timer, c->last = s->last_goto;+}+static void cs_init(CSpr *c, int bank) {+ Sprite s;+ spr_init(&s, bank);+ cs_back(c, &s);+}+static void cs_play(CSpr *c, int anim, bool restart) {+ Sprite s = cs_raw(c);+ spr_play(&s, anim, restart);+ cs_back(c, &s);+}+/* Play(id, restart: false, randomizeFrame: true) */+static void cs_play_random(CSpr *c, int anim) {+ if (c->anim == anim) return;+ cs_play(c, anim, false);+ Sprite s = cs_raw(c);+ int n = spr_frames(&s);+ float delay = n ? spr_anim_duration(c->bank, anim) / n : 0;+ c->timer = rndf() * delay;+ c->frame = (uint8_t)(n ? rndi(n) : 0);+}+static int cs_update(CSpr *c) { /* returns the animation that passed its last frame */+ if (!c->playing || c->anim == 255) return -1;+ Sprite s = cs_raw(c);+ int n = spr_frames(&s);+ float delay = n ? spr_anim_duration(c->bank, c->anim) / n : 0;+ int ended = (c->frame >= n - 1 && delay > 0 && c->timer + DT >= delay) ? c->anim : -1;+ spr_update(&s);+ cs_back(c, &s);+ return ended;+}+static uint16_t cs_tex(const CSpr *c) {+ Sprite s = cs_raw(c);+ uint16_t t = spr_tex(&s);+ if (t != 0xFFFF && !res_cached(t)) { /* an animation not loaded yet: all its frames in one pass (as spr_draw) */+ uint16_t ids[32], gotos[8];+ int ng, a = c->anim != 255 ? c->anim : c->last;+ if (a >= 0) res_load(ids, bank_anim_textures(c->bank, a, ids, 32, gotos, &ng));+ }+ return t;+}+static void cs_origin(const CSpr *c, uint16_t t, float *ox, float *oy) {+ Sprite s;+ spr_init(&s, c->bank);+ Tex tx;+ *ox = s.ox, *oy = s.oy;+ if (s.justify && tex_get(t, &tx)) *ox = tx.fw * tx.scale * s.jx, *oy = tx.fh * tx.scale * s.jy;+}+static void cs_draw(const CSpr *c, float x, float y, float sx, float sy, uint16_t tint, uint8_t alpha, uint8_t flags) {+ uint16_t t = cs_tex(c);+ if (t == 0xFFFF) return;+ float ox, oy;+ cs_origin(c, t, &ox, &oy);+ gfx_tex_ex(t, x, y, ox, oy, sx, sy, 0, tint, alpha, flags);+}+/* Sprite.DrawOutline(Color.Black) then the sprite */+static void cs_draw_outlined(const CSpr *c, float x, float y, uint8_t flags) {+ uint16_t t = cs_tex(c);+ if (t == 0xFFFF) return;+ float ox, oy;+ cs_origin(c, t, &ox, &oy);+ draw_outlined(t, x, y, ox, oy, flags, 0xFFFF, 255);+}++/* nodes of the room's entities, a pool per room slot (freed when its last user goes) */+#define NODES 160+enum { OFF_nodes = 0, END_nodes = OFF_nodes + (int)sizeof(int16_t[2][NODES][2]) };+#define nodes (*(int16_t(*)[2][NODES][2])(void *)(g_chram[9] + OFF_nodes))+static uint8_t nnodes[2], node_users[2];+static int nodes_add(const EData *d, bool with_position, int *count) {+ int slot = g_level.room_slot, at = nnodes[slot], n = 0;+ if (with_position && nnodes[slot] < NODES) {+ nodes[slot][nnodes[slot]][0] = (int16_t)d->x, nodes[slot][nnodes[slot]][1] = (int16_t)d->y;+ nnodes[slot]++, n++;+ }+ for (int i = 0; i < d->nnodes && nnodes[slot] < NODES; i++) {+ V2 v = ed_node(d, i);+ nodes[slot][nnodes[slot]][0] = (int16_t)v.x, nodes[slot][nnodes[slot]][1] = (int16_t)v.y;+ nnodes[slot]++, n++;+ }+ *count = n;+ return at;+}+static void nodes_release(int slot) {+ if (node_users[slot] && --node_users[slot] == 0) nnodes[slot] = 0;+}+static V2 node_at(int slot, int i) { return v2(nodes[slot][i][0], nodes[slot][i][1]); }++/* ---------------------------------------------------------------- the core mode (Level.CoreMode) */+static void core_listeners(int mode);+static void core_set(int mode) {+ if (g_level.core_mode == mode) return;+ g_level.core_mode = mode;+ level_set_flag("cold", mode == 2);+ core_listeners(mode); /* CoreModeListener.OnChange */+}++/* ---------------------------------------------------------------- CoreModeToggle */+typedef struct { CSpr spr; float cooldown; uint8_t ice, only_fire, only_ice, persistent, play_sounds, pad[3]; } Toggle;+static bool toggle_usable(Toggle *t) {+ if (!t->only_fire || t->ice) return t->only_ice ? !t->ice : true;+ return false;+}+static void toggle_sprite(Toggle *t, bool animate) {+ if (animate) {+ if (toggle_usable(t)) cs_play(&t->spr, t->ice ? A_coreFlipSwitch_ice : A_coreFlipSwitch_hot, false);+ else cs_play(&t->spr, t->ice ? A_coreFlipSwitch_iceOff : A_coreFlipSwitch_hotOff, false);+ } else if (toggle_usable(t))+ cs_play(&t->spr, t->ice ? A_coreFlipSwitch_iceLoop : A_coreFlipSwitch_hotLoop, false);+ else+ cs_play(&t->spr, t->ice ? A_coreFlipSwitch_iceOffLoop : A_coreFlipSwitch_hotOffLoop, false);+ t->play_sounds = 0;+}+static void toggle_on_mode(Ent *e, int mode) {+ Toggle *t = ST(e, Toggle);+ t->ice = mode == 2;+ toggle_sprite(t, true);+}+static void toggle_on_player(Ent *e, Player *p) {+ (void)p;+ Toggle *t = ST(e, Toggle);+ if (!toggle_usable(t) || t->cooldown > 0) return;+ t->play_sounds = 1;+ core_set(g_level.core_mode == 2 ? 1 : 2);+ if (t->persistent) g_session.core_mode = (uint8_t)g_level.core_mode;+ level_flash_a(0xFFFF, 0.15f, true);+ level_freeze(0.05f);+ ST(e, Toggle)->cooldown = 1;+}+static void toggle_update(Ent *e) {+ Toggle *t = ST(e, Toggle);+ cs_update(&t->spr);+ if (t->cooldown > 0) t->cooldown -= DT;+}+static void toggle_render(Ent *e) { cs_draw(&ST(e, Toggle)->spr, e->x, e->y, 1, 1, 0xFFFF, 255, 0); }+static void toggle_awake(Ent *e) { /* Added */+ Toggle *t = ST(e, Toggle);+ t->ice = g_level.core_mode == 2;+ toggle_sprite(t, false);+}+static const EntClass TOGGLE = {.name = "coreModeToggle", .size = sizeof(Toggle), .update = toggle_update, .render = toggle_render,+ .awake = toggle_awake, .on_player = toggle_on_player, .kind = KIND_PCOLLIDE};+static void new_toggle(const EData *d) {+ Ent *e = ent_new(&TOGGLE, d->x, d->y);+ if (!e) return;+ ent_box(e, 16, 24, -8, -12);+ e->depth = 2000;+ Toggle *t = ST(e, Toggle);+ t->only_fire = EAB(d, coreModeToggle, onlyFire);+ t->only_ice = EAB(d, coreModeToggle, onlyIce);+ t->persistent = EAB(d, coreModeToggle, persistent);+ cs_init(&t->spr, SB_coreFlipSwitch);+}++/* ---------------------------------------------------------------- FireBall */+typedef struct {+ CSpr spr;+ Wiggler hit;+ V2 hit_dir;+ float speed, speed_mult, percent, mult;+ uint8_t node0, nnode, slot, index, amount, ice, broken, not_core;+} Fire;+static V2 fire_pos(Fire *f, float percent) { /* GetPercentPosition */+ if (percent <= 0) return node_at(f->slot, f->node0);+ if (percent >= 1) return node_at(f->slot, f->node0 + f->nnode - 1);+ float total = 0;+ for (int i = 1; i < f->nnode; i++) total += v2len(v2sub(node_at(f->slot, f->node0 + i), node_at(f->slot, f->node0 + i - 1)));+ float at = total * percent, len = 0;+ int i = 0;+ for (; i < f->nnode - 1; i++) {+ float seg = v2len(v2sub(node_at(f->slot, f->node0 + i + 1), node_at(f->slot, f->node0 + i)));+ if (len + seg > at) break;+ len += seg;+ }+ if (i >= f->nnode - 1) i = f->nnode - 2;+ float seg = v2len(v2sub(node_at(f->slot, f->node0 + i + 1), node_at(f->slot, f->node0 + i)));+ float t = clamped_map(percent, len / total, (len + seg) / total, 0, 1);+ return v2lerp(node_at(f->slot, f->node0 + i), node_at(f->slot, f->node0 + i + 1), t);+}+static void fire_kill(Ent *e, Player *p) {+ Fire *f = ST(e, Fire);+ V2 dir = safe_norm(v2sub(player_center(p), v2(e->x, e->y)), 1);+ player_die(p, dir, false);+ if (p->dead) {+ f->hit_dir = dir;+ wiggler_restart(&f->hit);+ }+}+/* two PlayerColliders: the Circle(6) and Hitbox(16, 6, -8, -3); this entity's box covers both */+static void fire_on_player(Ent *e, Player *p) {+ Fire *f = ST(e, Fire);+ if (hurt_circle(p, e->x, e->y, 6)) { /* OnPlayer */+ if (!f->ice && !f->broken) fire_kill(e, p);+ else if (f->ice && !f->broken && e_bottom(p->ent) > e->y + 4) fire_kill(e, p);+ if (p->dead) return;+ }+ if (e->collidable && hurt_rect(p, e->x - 8, e->y - 3, e->x + 8, e->y + 3)) { /* OnBounce */+ if (f->ice && !f->broken && e_bottom(p->ent) <= e->y + 4 && p->speed.y >= 0) {+ cs_play(&f->spr, A_fireball_shatter, false);+ f->broken = 1;+ e->collidable = 0;+ player_bounce(p, (float)(int)(e->y - 2));+ particles_emit(PL_MID, &P_FireBall_P_IceBreak, 18, v2(e->x, e->y), v2(6, 6), 0);+ }+ }+}+static void fire_on_mode(Ent *e, int mode) {+ Fire *f = ST(e, Fire);+ f->ice = mode == 2;+ if (!f->broken) cs_play_random(&f->spr, f->ice ? A_fireball_ice : A_fireball_hot);+}+static void fire_update(Ent *e) {+ if (g_level.transitioning) return;+ Fire *f = ST(e, Fire);+ cs_update(&f->spr);+ wiggler_update(&f->hit);+ f->speed_mult = approach(f->speed_mult, f->ice ? 0.5f : 1, 2 * DT);+ f->percent += f->speed * f->speed_mult * DT;+ if (f->percent >= 1) {+ f->percent = fmodf(f->percent, 1);+ if (f->broken && !v2eq(node_at(f->slot, f->node0 + f->nnode - 1), node_at(f->slot, f->node0))) {+ f->broken = 0;+ e->collidable = 1;+ cs_play_random(&f->spr, f->ice ? A_fireball_ice : A_fireball_hot);+ }+ }+ V2 p = fire_pos(f, f->percent);+ e->x = p.x, e->y = p.y;+ if (!f->broken && level_on_interval(f->ice ? 0.08f : 0.05f))+ particles_emit(PL_BG, f->ice ? &P_FireBall_P_IceTrail : &P_FireBall_P_FireTrail, 1, p, v2(4, 4), 0);+}+static void fire_render(Ent *e) {+ Fire *f = ST(e, Fire);+ float x = e->x + f->hit_dir.x * f->hit.value * 8, y = e->y + f->hit_dir.y * f->hit.value * 8;+ if (!f->broken) cs_draw_outlined(&f->spr, x, y, 0);+ else cs_draw(&f->spr, x, y, 1, 1, 0xFFFF, 255, 0);+}+static void fire_awake(Ent *e) { /* Added */+ Fire *f = ST(e, Fire);+ f->ice = g_level.core_mode == 2 || f->not_core;+ f->speed_mult = f->ice ? 0 : 1;+ cs_play_random(&f->spr, f->ice ? A_fireball_ice : A_fireball_hot);+}+static void fire_removed(Ent *e) { nodes_release(ST(e, Fire)->slot); }+static const EntClass FIRE = {.name = "fireBall", .size = sizeof(Fire), .update = fire_update, .render = fire_render, .awake = fire_awake,+ .removed = fire_removed, .on_player = fire_on_player, .kind = KIND_PCOLLIDE};+static void new_fireball(const EData *d) {+ int n;+ int at = nodes_add(d, true, &n);+ if (n < 2) return;+ int amount = (int)EA(d, fireBall, amount);+ if (amount < 1) amount = 1;+ float offset = EA(d, fireBall, offset), mult = EA(d, fireBall, speed);+ float total = 0;+ int slot = g_level.room_slot;+ for (int i = 1; i < n; i++) total += v2len(v2sub(node_at(slot, at + i), node_at(slot, at + i - 1)));+ for (int k = 0; k < amount; k++) { /* Added: the others of the group */+ Ent *e = ent_new(&FIRE, d->x, d->y);+ if (!e) return;+ ent_box(e, 16, 12, -8, -6);+ e->tags = TAG_TRANSITION_UPDATE;+ Fire *f = ST(e, Fire);+ f->node0 = (uint8_t)at, f->nnode = (uint8_t)n, f->slot = (uint8_t)slot;+ f->index = (uint8_t)k, f->amount = (uint8_t)amount;+ f->mult = mult;+ f->speed = 60 / total * mult;+ f->percent = k == 0 ? 0 : (float)k / amount;+ f->percent += 1.f / amount * offset;+ f->percent = fmodf(f->percent, 1);+ V2 p = fire_pos(f, f->percent);+ e->x = p.x, e->y = p.y;+ cs_init(&f->spr, SB_fireball);+ wiggler_init(&f->hit, 1.2f, 2);+ f->hit.start_zero = true;+ node_users[slot]++;+ }+}++/* ---------------------------------------------------------------- WallBooster */+#define WB_TILES 40+typedef struct {+ float t; /* the tiles' animation clock: every frame they show moves together */+ int8_t facing;+ uint8_t ice, ntiles, pad;+ uint8_t tile[WB_TILES]; /* ice: bit 7 = "iceShine", the rest the frame */+} WallB;+static uint16_t wb_tex[2][3][8]; /* [ice][top, mid, bottom][frame] */+static void wb_on_mode(Ent *e, int mode) {+ WallB *w = ST(e, WallB);+ w->ice = mode == 2;+ if (w->ice) e->kind |= KIND_CLIMBBLOCKER; /* climbBlocker.Blocking */+ else e->kind &= (uint16_t)~KIND_CLIMBBLOCKER;+ w->t = 0;+ memset(w->tile, 0, sizeof w->tile); /* tiles.Play(ice / hot) */+}+static void wb_update(Ent *e) {+ if (g_level.transitioning) return;+ WallB *w = ST(e, WallB);+ float delay = w->ice ? 0.08f : 0.035f;+ w->t += DT;+ if (w->t < delay) return;+ w->t -= delay;+ for (int i = 0; i < w->ntiles; i++) {+ uint8_t *k = &w->tile[i];+ if (!w->ice) {+ *k = (uint8_t)((*k + 1) % 8); /* "hot": frames 0-7, looping */+ continue;+ }+ int shine = *k >> 7, f = (*k & 127) + 1;+ if (f >= (shine ? 5 : 10)) { /* ice: frame 0 ten times, then ice x5 or iceShine (frames 0-4) */+ shine = shine ? 0 : rndi(6) == 5;+ f = 0;+ }+ *k = (uint8_t)(shine << 7 | f);+ }+}+static void wb_render(Ent *e) {+ WallB *w = ST(e, WallB);+ for (int i = 0; i < w->ntiles; i++) {+ int part = i == 0 ? 0 : (i * 8 + 16 > e->ch) ? 2 : 1;+ int f = w->ice ? ((w->tile[i] >> 7) ? (w->tile[i] & 127) : 0) : w->tile[i];+ uint16_t t = wb_tex[w->ice][part][f];+ gfx_tex(t, e->x + (w->facing > 0 ? 4 : 0), e->y + i * 8, w->facing > 0 ? GF_FLIPX : 0, 0xFFFF, 255);+ }+}+static void wb_awake(Ent *e) { wb_on_mode(e, g_level.core_mode == 2 ? 2 : 0); }+static const EntClass WALLBOOSTER = {.name = "wallBooster", .size = sizeof(WallB), .update = wb_update, .render = wb_render,+ .awake = wb_awake};+static void new_wallbooster(const EData *d) {+ float h = EA(d, wallBooster, height);+ bool left = EAB(d, wallBooster, left);+ Ent *e = ent_new(&WALLBOOSTER, d->x, d->y);+ if (!e) return;+ e->tags = TAG_TRANSITION_UPDATE;+ e->depth = 1999;+ if (left) ent_box(e, 2, h, 0, 0);+ else ent_box(e, 2, h, 6, 0);+ WallB *w = ST(e, WallB);+ w->facing = left ? -1 : 1;+ w->ntiles = (uint8_t)fminf(WB_TILES, ceilf(h / 8));+ if (!wb_tex[0][0][0]) {+ static const char *P[2][3] = {{"objects/wallBooster/fireTop", "objects/wallBooster/fireMid", "objects/wallBooster/fireBottom"},+ {"objects/wallBooster/iceTop", "objects/wallBooster/iceMid", "objects/wallBooster/iceBottom"}};+ for (int k = 0; k < 2; k++)+ for (int p = 0; p < 3; p++) tex_family(P[k][p], wb_tex[k][p], k ? 5 : 8);+ }+}++/* ---------------------------------------------------------------- LavaRect: drawn a strip at a time */+enum { LAVA_ALL, LAVA_TOP, LAVA_BOTTOM };+typedef struct {+ float ox, oy; /* its Position, relative to the entity */+ float w, h, timer, fade, spikey, small, big, curve, mult;+ uint32_t surface, edge, center;+ uint16_t seed;+ uint8_t step, only;+} Lava;+static void lava_init(Lava *l, float w, float h, int step) {+ memset(l, 0, sizeof *l);+ l->w = w, l->h = h, l->step = (uint8_t)step;+ l->fade = 16, l->small = 1, l->big = 4, l->curve = 12, l->mult = 1;+ l->surface = 0xFFFFFF, l->edge = 0xD3D3D3, l->center = 0xA9A9A9;+ l->timer = rndf() * 100;+ l->seed = (uint16_t)rndi(65536);+}+static float lava_sin(float v) { return (1 + sinf(v)) / 2; }+static float lava_wave(const Lava *l, int step, float length) { /* LavaRect.Wave */+ int num = step * l->step;+ float k = l->only != LAVA_ALL ? 1 : clamped_map((float)num, 0, length * 0.1f, 0, 1) * clamped_map((float)num, length * 0.9f, length, 1, 0);+ float v = lava_sin(num * 0.25f + l->timer * 4) * l->small;+ v += lava_sin(num * 0.05f + l->timer * 0.5f) * l->big;+ if (step % 2 == 0) v += l->spikey;+ if (l->only != LAVA_ALL) v += (1 - yoyo(num / length)) * l->curve;+ return v * k;+}+static void lava_update(Lava *l) { l->timer += l->mult * DT; }+static int lava_nbubbles(const Lava *l) { return (int)(l->w * l->h * 0.005f); }++/* drawing happens a strip at a time after every render call: each frame the waves are sampled once+ * (at the mesh's vertices, every SurfaceStep pixels, in 1/4 pixels) and the strips interpolate them */+#define LAVA_SAMPLES 2048+enum { OFF_lava_samples = ((END_nodes + 7) & ~7), END_lava_samples = OFF_lava_samples + (int)sizeof(int8_t[LAVA_SAMPLES]) };+#define lava_samples (*(int8_t(*)[LAVA_SAMPLES])(void *)(g_chram[9] + OFF_lava_samples))+static int nlava_samples;+#define MAX_LAVA_DRAWS 12+typedef struct { Ent *e; Lava *l; int16_t edge[4], nedge[4]; } LavaCtx; /* top, right, bottom, left */+enum { OFF_lava_draws = ((END_lava_samples + 7) & ~7), END_lava_draws = OFF_lava_draws + (int)sizeof(LavaCtx[MAX_LAVA_DRAWS]) };+#define lava_draws (*(LavaCtx(*)[MAX_LAVA_DRAWS])(void *)(g_chram[9] + OFF_lava_draws))+static int nlava_draws;+static uint32_t lava_frame;+static uint16_t lava_bubble_tex[4];+static float lava_sample(const LavaCtx *c, int edge, float s) { /* the wave at s along an edge */+ const Lava *l = c->l;+ int n = c->nedge[edge];+ if (n < 2) return 0;+ float k = s / l->step;+ int i = (int)floorf(k);+ float f = k - i;+ if (i < 0) i = 0, f = 0;+ if (i >= n - 1) i = n - 2, f = 1;+ const int8_t *w = lava_samples + c->edge[edge];+ return (w[i] * (1 - f) + w[i + 1] * f) * 0.25f;+}+static bool lava_sample_edge(LavaCtx *c, int edge, float length) {+ int n = (int)(length / c->l->step) + 2;+ if (nlava_samples + n > LAVA_SAMPLES) return false;+ c->edge[edge] = (int16_t)nlava_samples, c->nedge[edge] = (int16_t)n;+ for (int i = 0; i < n; i++) {+ float v = lava_wave(c->l, i, length) * 4;+ lava_samples[nlava_samples++] = (int8_t)clampf(roundf(v), -127, 127);+ }+ return true;+}+/* bubbles rise from the bottom and start again when they reach the surface; their x, speed and+ * alpha never change, so they come from the seed, and their height from LavaRect.timer */+static float lava_bubble_speed(const Lava *l, int i) { return (float)(4 + (int)(hash01(l->seed, 4u * i + 1) * 8)); }+static void lava_bubble(const LavaCtx *c, int i, float *x, float *y, float *alpha, int *cycle) {+ const Lava *l = c->l;+ float bx = 1 + hash01(l->seed, 4u * i) * (l->w - 2);+ float y0 = hash01(l->seed, 4u * i + 2) * l->h;+ float top = 2 - lava_sample(c, 0, (float)((int)(bx / l->step) * l->step));+ float span = l->h - 1 - top;+ if (span < 1) span = 1;+ float travel = l->h - 1 - y0 + lava_bubble_speed(l, i) * l->timer;+ *cycle = (int)floorf(travel / span);+ *y = l->h - 1 - fmodf(travel, span);+ *x = bx;+ *alpha = 0.4f + hash01(l->seed, 4u * i + 3) * 0.4f;+}+static void lava_strip(uint16_t *strip, int y0, int y1, void *ctx) {+ const LavaCtx *c = ctx;+ const Lava *l = c->l;+ float bx = c->e->x + l->ox, by = c->e->y + l->oy;+ int vx0 = (int)floorf(bx) - g_camx, vy0 = (int)floorf(by) - g_camy;+ float fade_x = fminf(l->fade, l->w / 2), fade_y = fminf(l->fade, l->h / 2);+ uint16_t cs = rgb(l->surface), cc = rgb(l->center);+ uint32_t ce = l->edge, cm = l->center;+ int xa = vx0 < 0 ? 0 : vx0, xb = vx0 + (int)l->w > VIEW_W ? VIEW_W : vx0 + (int)l->w;+ float up = l->only == LAVA_TOP ? 64 : 0, down = l->only == LAVA_BOTTOM ? 64 : 0;+ for (int vy = y0; vy < y1; vy++) {+ float ly = vy - vy0 + 0.5f;+ if (ly < -up || ly >= l->h + down) continue;+ uint16_t *row = strip + (vy - y0) * VIEW_W;+ float wl = 0, wr = 0;+ if (l->only == LAVA_ALL) wl = lava_sample(c, 3, l->h - ly), wr = lava_sample(c, 1, ly);+ for (int vx = xa; vx < xb; vx++) {+ float lx = vx - vx0 + 0.5f, d, fd = fade_y;+ if (l->only == LAVA_TOP) d = ly + lava_sample(c, 0, lx);+ else if (l->only == LAVA_BOTTOM) d = l->h + lava_sample(c, 2, l->w - lx) - ly;+ else {+ float dt = ly + lava_sample(c, 0, lx), db = l->h + lava_sample(c, 2, l->w - lx) - ly, dl = lx + wl, dr = l->w + wr - lx;+ d = dt;+ if (db < d) d = db;+ if (dl < d) d = dl, fd = fade_x;+ if (dr < d) d = dr, fd = fade_x;+ }+ if (d < 0) continue;+ if (d < 1) row[vx] = cs;+ else if (d < fd) row[vx] = rgb(lerp_rgb(ce, cm, (d - 1) / (fd - 1)));+ else row[vx] = cc;+ }+ }+ /* the bubbles (particles/bubble in SurfaceColor * alpha), and where they popped on the surface */+ Tex bt;+ bool have = tex_get(T_particles_bubble, &bt);+ int n = lava_nbubbles(l);+ for (int i = 0; i < n; i++) {+ float x, y, a;+ int cycle;+ lava_bubble(c, i, &x, &y, &a, &cycle);+ int px = (int)floorf(bx + x + 0.5f) - g_camx - 2, py = (int)floorf(by + y + 0.5f) - g_camy - 2;+ if (have && py + 4 > y0 && py < y1 && px + 4 > 0 && px < VIEW_W) blit_tex(strip, y0, y1, &bt, px, py, 0, cs, a8(a));+ if (l->only == LAVA_BOTTOM || cycle <= 0 || l->mult <= 0 || hash01(l->seed ^ 0x55u, (uint32_t)(i * 977 + cycle)) >= 0.75f) continue;+ /* Frame += DT * 6 since it reached the top: 4 frames of danger/lava/bubble_a */+ float since = (l->h - 1 - y) / lava_bubble_speed(l, i) / l->mult;+ int f = (int)(since * 6);+ if (f < 0 || f >= 4 || lava_bubble_tex[f] == 0xFFFF) continue;+ Tex st;+ if (!tex_get(lava_bubble_tex[f], &st)) continue;+ int num = (int)(x / l->step);+ float sy = 1 - lava_sample(c, 0, (float)(num * l->step));+ int sx_ = (int)floorf(bx + num * l->step - st.fw * 0.5f + 0.5f) - g_camx; /* DrawJustified(0.5, 1) */+ int sy_ = (int)floorf(by + sy - st.fh + 0.5f) - g_camy;+ blit_tex(strip, y0, y1, &st, sx_ + st.ox, sy_ + st.oy, 0, cs, 255);+ }+}+static void lava_render(Ent *e, Lava *l) {+ if (lava_frame != g_frame) lava_frame = g_frame, nlava_draws = 0, nlava_samples = 0;+ if (nlava_draws >= MAX_LAVA_DRAWS) return;+ float top = e->y + l->oy - (l->only == LAVA_TOP ? 64 : 0), bottom = e->y + l->oy + l->h + (l->only == LAVA_BOTTOM ? 64 : 0);+ int y0 = (int)floorf(top) - g_camy, y1 = (int)ceilf(bottom) - g_camy + 1;+ if (y1 <= 0 || y0 >= VIEW_H || e->x + l->ox + l->w < g_camx || e->x + l->ox > g_camx + VIEW_W) return;+ LavaCtx *c = &lava_draws[nlava_draws];+ memset(c, 0, sizeof *c);+ c->e = e, c->l = l;+ if (!lava_sample_edge(c, 0, l->w)) return; /* the top: the bubbles need it in every mode */+ if (l->only != LAVA_TOP && !lava_sample_edge(c, 2, l->w)) return;+ if (l->only == LAVA_ALL && (!lava_sample_edge(c, 1, l->h) || !lava_sample_edge(c, 3, l->h))) return;+ nlava_draws++;+ if (lava_bubble_tex[0] == 0) tex_family("danger/lava/bubble_a", lava_bubble_tex, 4);+ Tex bt; /* nothing loads while strips are drawn: the bubbles are loaded (and kept) now */+ for (int i = 0; i < 4; i++) tex_get(lava_bubble_tex[i], &bt);+ tex_get(T_particles_bubble, &bt);+ gfx_custom(lava_strip, c, y0 < 0 ? 0 : y0, y1 > VIEW_H ? VIEW_H : y1);+}++/* ---------------------------------------------------------------- FireBarrier and IceBlock */+typedef struct { Lava lava; uint8_t solid, ice, pad[2]; } Barrier;+static const EntClass FIREBARRIER, ICEBLOCK;+static void inner_solid_update(Ent *e) { plat_update(e); }+static const EntClass INNER_SOLID = {.name = "solid", .update = inner_solid_update, .kind = KIND_SOLID};+static void barrier_on_player(Ent *e, Player *p) { player_die(p, safe_norm(v2sub(player_center(p), e_center(e)), 1), false); }+static void barrier_on_mode(Ent *e, int mode) {+ Barrier *b = ST(e, Barrier);+ bool on = b->ice ? mode == 2 : mode == 1;+ e->collidable = on;+ Ent *s = ent_at(b->solid);+ if (s->cls == &INNER_SOLID) s->collidable = on;+ if (on) return;+ V2 c = e_center(e);+ for (int i = 0; i < e->cw; i += 4)+ for (int j = 0; j < e->ch; j += 4) {+ V2 v = v2(e->x + i + 2 + rnd_rangef(-2, 2), e->y + j + 2 + rnd_rangef(-2, 2));+ particles_emit1(PL_MID, b->ice ? &P_IceBlock_P_Deactivate : &P_FireBarrier_P_Deactivate, v, vangle(v2sub(v, c)));+ }+}+static void barrier_update(Ent *e) {+ if (g_level.transitioning && !ST(e, Barrier)->ice) return;+ lava_update(&ST(e, Barrier)->lava);+}+static void barrier_render(Ent *e) {+ if (e->collidable) lava_render(e, &ST(e, Barrier)->lava);+}+static void barrier_awake(Ent *e) { /* Added: the solid inside, on in its mode */+ Barrier *b = ST(e, Barrier);+ Ent *s = ent_new(&INNER_SOLID, e->x + 2, e->y + 3);+ bool on = b->ice ? g_level.core_mode == 2 : g_level.core_mode == 1;+ e->collidable = on;+ if (!s) return;+ ent_box(s, e->cw - 4, e->ch - 5, 0, 0);+ s->visible = 0;+ s->collidable = on;+ s->dead = 0; /* in the scene now, as Added does */+ ST(e, Barrier)->solid = ent_ref(s);+}+static void barrier_removed(Ent *e) {+ Ent *s = ent_at(ST(e, Barrier)->solid);+ if (s->cls == &INNER_SOLID) ent_remove(s);+}+static const EntClass FIREBARRIER = {.name = "fireBarrier", .size = sizeof(Barrier), .update = barrier_update, .render = barrier_render,+ .awake = barrier_awake, .removed = barrier_removed, .on_player = barrier_on_player,+ .kind = KIND_PCOLLIDE};+static const EntClass ICEBLOCK = {.name = "iceBlock", .size = sizeof(Barrier), .update = barrier_update, .render = barrier_render,+ .awake = barrier_awake, .removed = barrier_removed, .on_player = barrier_on_player,+ .kind = KIND_PCOLLIDE};+static void new_barrier(const EData *d, bool ice) {+ float w = ice ? EA(d, iceBlock, width) : EA(d, fireBarrier, width), h = ice ? EA(d, iceBlock, height) : EA(d, fireBarrier, height);+ Ent *e = ent_new(ice ? &ICEBLOCK : &FIREBARRIER, d->x, d->y);+ if (!e) return;+ ent_box(e, w, h, 0, 0);+ e->depth = -8500;+ if (!ice) e->tags = TAG_TRANSITION_UPDATE;+ Barrier *b = ST(e, Barrier);+ b->ice = ice;+ b->solid = ent_ref(e);+ if (ice) {+ lava_init(&b->lava, w, h, 2);+ b->lava.mult = 0;+ b->lava.surface = 0xA6FFF4, b->lava.edge = 0x6CD6EB, b->lava.center = 0x4CA8D6;+ b->lava.small = 1, b->lava.big = 1, b->lava.curve = 1, b->lava.spikey = 3;+ } else {+ lava_init(&b->lava, w, h, 4);+ b->lava.surface = 0xFF8933, b->lava.edge = 0xF25E29, b->lava.center = 0xD01C01; /* RisingLava.Hot */+ b->lava.small = 2, b->lava.big = 1, b->lava.curve = 1;+ }+}++/* ---------------------------------------------------------------- RisingLava and SandwichLava */+static const uint32_t HOT[3] = {0xFF8933, 0xF25E29, 0xD01C01}, COLD[3] = {0x33FFE7, 0x4CA2EB, 0x0151D0};+typedef struct {+ Lava bottom, top;+ float lerp, delay, start_x, trans_y, alarm;+ uint8_t intro, ice, waiting, sandwich, leaving, persistent, in_transition, pad;+} Rising;+static bool sandwich_handoff; /* the next room's sandwich lava gave its place to the one already here */+static void sandwich_leave(Ent *e) { /* Leave() */+ Rising *r = ST(e, Rising);+ e->tags |= TAG_TRANSITION_UPDATE;+ r->leaving = 1;+ e->collidable = 0;+ r->alarm = 2;+}+static void rising_colors(Rising *r, Lava *l) {+ l->surface = lerp_rgb(HOT[0], COLD[0], r->lerp);+ l->edge = lerp_rgb(HOT[1], COLD[1], r->lerp);+ l->center = lerp_rgb(HOT[2], COLD[2], r->lerp);+ l->spikey = r->lerp * 5;+ l->mult = (1 - r->lerp) * 2;+ l->fade = r->ice ? 128 : 32;+}+static void rising_on_mode(Ent *e, int mode) { ST(e, Rising)->ice = mode == 2; }+/* SandwichLava's collider is two boxes: the player is checked against each here */+static void rising_on_player(Ent *e, Player *p) {+ Rising *r = ST(e, Rising);+ if (r->sandwich) {+ if (r->waiting) return;+ if (!hurt_rect(p, e->x, e->y, e->x + 340, e->y + 120) && !hurt_rect(p, e->x, e->y - 280, e->x + 340, e->y - 160)) return;+ }+ player_die(p, v2(0, -1), false);+}+static float sandwich_center_y(void) { return (float)(g_level.room->y + g_level.room->h) - 10; }+static void rising_update(Ent *e) {+ Rising *r = ST(e, Rising);+ Player *p = level_player();+ if (r->sandwich) {+ if (g_level.transitioning) {+ if (!r->in_transition) { /* TransitionListener.OnOutBegin: leave unless the next room has one too */+ r->in_transition = 1;+ r->trans_y = e->y;+ if (r->persistent && !sandwich_handoff) sandwich_leave(e);+ sandwich_handoff = false;+ }+ e->x = g_level.cam.x; /* OnOut */+ if (!r->leaving) e->y = lerpf(r->trans_y, sandwich_center_y(), g_level.tr_at);+ if (g_level.tr_at > 0.95f && r->leaving) ent_remove(e);+ return;+ }+ r->in_transition = 0;+ e->x = g_level.cam.x;+ r->delay -= DT;+ if (r->alarm > 0 && (r->alarm -= DT) <= 0) {+ ent_remove(e);+ return;+ }+ e->visible = 1;+ if (r->waiting) {+ e->y = approach(e->y, sandwich_center_y(), 128 * DT);+ if (p && p->ent->x >= r->start_x && !p->just_respawned && p->state != ST_DUMMY) r->waiting = 0;+ } else if (!r->leaving && r->delay <= 0)+ e->y += (r->ice ? 20 : -20) * DT;+ r->top.oy = approach(r->top.oy, -160 - r->top.h + (r->leaving ? -512 : 0), (r->leaving ? 256 : 64) * DT);+ r->bottom.oy = approach(r->bottom.oy, r->leaving ? 512 : 0, (r->leaving ? 256 : 64) * DT);+ } else {+ r->delay -= DT;+ e->x = g_level.cam.x;+ e->visible = 1;+ float num = 1;+ if (r->waiting) {+ if (!r->intro && p && p->just_respawned) e->y = approach(e->y, p->ent->y + 32, 32 * DT);+ if ((!r->ice || !r->intro) && (!p || !p->just_respawned)) r->waiting = 0;+ } else {+ float bottom = g_level.cam.y + 180 - 12;+ if (e->y > bottom + 96) e->y = bottom + 96;+ num = e->y > bottom ? clamped_map(e->y - bottom, 0, 96, 1, 2) : clamped_map(bottom - e->y, 0, 32, 1, 0.5f);+ if (r->delay <= 0) e->y += -30 * num * DT;+ }+ }+ r->lerp = approach(r->lerp, r->ice ? 1 : 0, DT * 4);+ rising_colors(r, &r->bottom);+ lava_update(&r->bottom);+ if (r->sandwich) {+ rising_colors(r, &r->top);+ lava_update(&r->top);+ }+}+static void rising_render(Ent *e) {+ Rising *r = ST(e, Rising);+ lava_render(e, &r->bottom);+ if (r->sandwich) lava_render(e, &r->top);+}+static void rising_awake(Ent *e) {+ Rising *r = ST(e, Rising);+ Player *p = level_player();+ if (r->intro) r->waiting = 1;+ else if (p && p->just_respawned) r->waiting = 1;+ if (r->intro) e->visible = 1;+}+static void sandwich_awake(Ent *e) {+ Rising *r = ST(e, Rising);+ Player *p = level_player();+ if (p && (p->just_respawned || p->ent->x < r->start_x)) r->waiting = 1;+ /* a sandwich lava from the last room stays: this one only moves its start */+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o == e || !o->cls || o->dead == 1 || o->cls != e->cls) continue;+ Rising *q = ST(o, Rising);+ if (!r->persistent && !q->leaving) {+ q->start_x = r->start_x;+ q->waiting = 1;+ sandwich_handoff = true;+ ent_remove(e);+ return;+ }+ }+ r->persistent = 1;+ e->tags |= TAG_PERSISTENT | TAG_TRANSITION_UPDATE; /* its TransitionListener runs during transitions */+ if (!p || p->intro != INTRO_RESPAWN) r->top.oy -= 60, r->bottom.oy += 60;+ else e->visible = 1;+}+static const EntClass SANDWICH = {.name = "sandwichLava", .size = sizeof(Rising), .update = rising_update, .render = rising_render,+ .awake = sandwich_awake, .on_player = rising_on_player, .kind = KIND_PCOLLIDE};+static const EntClass RISING2 = {.name = "risingLava", .size = sizeof(Rising), .update = rising_update, .render = rising_render,+ .awake = rising_awake, .on_player = rising_on_player, .kind = KIND_PCOLLIDE};+static void new_rising(const EData *d, bool sandwich) {+ Room *rm = g_level.room;+ if (!rm) return;+ Ent *e = ent_new(sandwich ? &SANDWICH : &RISING2, 0, 0);+ if (!e) return;+ e->depth = -1000000;+ e->visible = 0;+ Rising *r = ST(e, Rising);+ lava_init(&r->bottom, 400, 200, 4);+ r->bottom.ox = -40, r->bottom.only = LAVA_TOP, r->bottom.small = 2;+ /* Added: below the room, as the room being loaded sees it */+ float rx = d->rx, ry = d->ry;+ int rh = 0;+ for (int s = 0; s < 2; s++)+ if (g_level.rooms[s].index == d->room) rh = g_level.rooms[s].h;+ if (!rh) rh = rm->h;+ e->x = rx - 10;+ r->ice = g_session.core_mode == 2;+ if (sandwich) {+ ent_box(e, 340, 400, 0, -280); /* both boxes (the hit test picks them apart) */+ r->sandwich = 1;+ r->start_x = d->x;+ lava_init(&r->top, 400, 200, 4);+ r->top.ox = -40, r->top.oy = -360, r->top.only = LAVA_BOTTOM, r->top.small = 2;+ r->top.big = r->bottom.big = 2;+ r->top.curve = r->bottom.curve = 4;+ e->y = ry + rh - 10;+ } else {+ ent_box(e, 340, 120, 0, 0);+ r->intro = EAB(d, risingLava, intro);+ e->y = ry + rh + 16;+ }+}++/* ---------------------------------------------------------------- BounceBlock */+enum { BB_WAITING, BB_WINDUP, BB_BOUNCING, BB_END, BB_BROKEN };+typedef struct {+ V2 bounce_dir, start, bounce_lift, debris_dir;+ float move_speed, windup_start, windup, respawn, bounce_end, flash, alarm;+ CSpr hot_center, cold_center;+ uint16_t seed;+ uint8_t state, ice, ice_next, reformed;+} Bounce;+static uint16_t bb_tex[2], bb_rubble[2][4];+/* the debris of broken blocks (BreakDebris, RespawnDebris): a pool drawn by one entity */+#define MAX_DEBRIS 96+/* vx, vy: its speed in 1/8 px/s, or (RespawnDebris) where it goes, in pixels; dur in 1/100 s */+typedef struct { float x, y; int16_t vx, vy; float percent; uint8_t dur, tex, respawn, used; } BDebris;+enum { OFF_debris = ((END_lava_draws + 7) & ~7), END_debris = OFF_debris + (int)sizeof(BDebris[MAX_DEBRIS]) };+#define debris (*(BDebris(*)[MAX_DEBRIS])(void *)(g_chram[9] + OFF_debris))+static void debris_add(V2 at, V2 v, float duration, bool ice, bool respawn) {+ for (int i = 0; i < MAX_DEBRIS; i++)+ if (!debris[i].used) {+ BDebris *b = &debris[i];+ b->x = at.x, b->y = at.y;+ b->vx = (int16_t)roundf(respawn ? v.x : v.x * 8), b->vy = (int16_t)roundf(respawn ? v.y : v.y * 8);+ b->percent = 0, b->dur = (uint8_t)clampf(duration * 100 + 0.5f, 1, 255);+ b->tex = (uint8_t)((ice ? 4 : 0) + rndi(4));+ b->respawn = respawn, b->used = 1;+ return;+ }+}+static void debrismgr_update(Ent *e) {+ (void)e;+ for (int i = 0; i < MAX_DEBRIS; i++) {+ BDebris *b = &debris[i];+ if (!b->used) continue;+ if (b->respawn) { /* RespawnDebris: from x, y to vx, vy */+ if (b->percent > 1) {+ b->used = 0;+ continue;+ }+ b->percent += DT / (b->dur * 0.01f);+ } else {+ if (b->percent >= 1) {+ b->used = 0;+ continue;+ }+ float vx = b->vx / 8.f, vy = b->vy / 8.f;+ b->x += vx * DT, b->y += vy * DT;+ b->vx = (int16_t)roundf(approach(vx, 0, 180 * DT) * 8);+ b->vy = (int16_t)clampf(roundf((vy + 200 * DT) * 8), -32767, 32767);+ b->percent += DT / (b->dur * 0.01f);+ }+ }+}+static void debrismgr_render(Ent *e) {+ (void)e;+ for (int i = 0; i < MAX_DEBRIS; i++) {+ BDebris *b = &debris[i];+ if (!b->used) continue;+ uint16_t t = bb_rubble[b->tex >> 2][b->tex & 3];+ Tex tx;+ if (!tex_get(t, &tx)) continue;+ float x = b->x, y = b->y, a = 1 - b->percent;+ if (b->respawn) {+ float k = ease_cube_in(fminf(b->percent, 1));+ x = b->x + (b->vx - b->x) * k, y = b->y + (b->vy - b->y) * k, a = b->percent;+ }+ draw_outlined(t, x, y, tx.fw * tx.scale / 2.f, tx.fh * tx.scale / 2.f, 0, 0xFFFF, a8(a));+ }+}+static const EntClass DEBRISMGR = {.name = "bounceBlockDebris", .update = debrismgr_update, .render = debrismgr_render};+static void debris_manager(void) {+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &DEBRISMGR && g_ents[i].dead != 1) return;+ memset(debris, 0, sizeof debris);+ Ent *m = ent_new(&DEBRISMGR, 0, 0);+ if (m) m->tags = TAG_GLOBAL, m->collidable = 0, m->depth = -9000;+}++static Player *bb_windup_player(Ent *e) { /* WindUpPlayerCheck */+ Ent *pe = level_player_ent();+ Player *p = level_player();+ if (!pe || !p) return NULL;+ if (collide_ent_at(e, e->x, e->y - 1, pe) && p->speed.y >= 0) return p;+ if (collide_ent_at(e, e->x + 1, e->y, pe) && p->state == ST_CLIMB && p->facing == -1) return p;+ if (collide_ent_at(e, e->x - 1, e->y, pe) && p->state == ST_CLIMB && p->facing == 1) return p;+ return NULL;+}+static void bb_move_to(Ent *e, V2 to, V2 lift) {+ plat_move_h_lift(e, to.x - (e->x + e->remx), lift.x);+ plat_move_v_lift(e, to.y - (e->y + e->remy), lift.y);+}+static void bb_break(Ent *e) {+ Bounce *b = ST(e, Bounce);+ b->state = BB_BROKEN;+ e->collidable = 0;+ plat_static_movers_enable(e, false);+ b->respawn = 1.6f;+ V2 dir = b->ice ? v2(0, 1) : b->debris_dir, c = e_center(e);+ for (int i = 0; i < e->cw; i += 8)+ for (int j = 0; j < e->ch; j += 8) {+ V2 at = v2(e->x + i + 4, e->y + j + 4);+ if (b->ice) dir = safe_norm(v2sub(at, c), 1);+ V2 d = angle_vec(vangle(dir) + rnd_rangef(-0.1f, 0.1f), 1);+ float sp = b->ice ? (float)(20 + rndi(20)) : (float)(120 + rndi(80));+ debris_add(at, v2mul(d, sp), (float)(2 + rndi(1)), b->ice, false);+ }+ float a = vangle(b->debris_dir);+ for (int k = 0; k < e->cw; k += 4)+ for (int l = 0; l < e->ch; l += 4) {+ V2 v = v2(e->x + 2 + k + rnd_rangef(-1, 1), e->y + 2 + l + rnd_rangef(-1, 1));+ particles_emit1(PL_MID, b->ice ? &P_BounceBlock_P_IceBreak : &P_BounceBlock_P_FireBreak, v, b->ice ? vangle(v2sub(v, c)) : a);+ }+}+static void bb_mode_check(Bounce *b) {+ if (b->ice_next != b->ice) b->ice = b->ice_next; /* ToggleSprite: drawn from ice */+}+static void bb_update(Ent *e) {+ Bounce *b = ST(e, Bounce);+ plat_update(e);+ cs_update(&b->hot_center);+ cs_update(&b->cold_center);+ if (b->alarm > 0 && (b->alarm -= DT) <= 0) { /* the reform alarm */+ b->reformed = 1;+ b->flash = 0.6f;+ plat_static_movers_enable(e, true);+ for (int i = 0; i < e->cw; i += 4) {+ particles_emit1(PL_MID, &P_BounceBlock_P_Reform, v2(e->x + 2 + i + rndi(2) - 1, e->y), -PI_F / 2);+ particles_emit1(PL_MID, &P_BounceBlock_P_Reform, v2(e->x + 2 + i + rndi(2) - 1, e_bottom(e) - 1), PI_F / 2);+ }+ for (int j = 0; j < e->ch; j += 4) {+ particles_emit1(PL_MID, &P_BounceBlock_P_Reform, v2(e->x, e->y + 2 + j + rndi(2) - 1), PI_F);+ particles_emit1(PL_MID, &P_BounceBlock_P_Reform, v2(e_right(e) - 1, e->y + 2 + j + rndi(2) - 1), 0);+ }+ }+ b->flash = approach(b->flash, 0, DT * 8);+ V2 ex = plat_exact(e);+ switch (b->state) {+ case BB_WAITING: {+ bb_mode_check(b);+ b->move_speed = approach(b->move_speed, 100, 400 * DT);+ V2 to = approach_v(ex, b->start, b->move_speed * DT);+ V2 lift = safe_norm(v2sub(to, ex), b->move_speed);+ lift.x *= 0.75f;+ bb_move_to(e, to, lift);+ b = ST(e, Bounce);+ b->windup = approach(b->windup, 0, DT);+ Player *p = bb_windup_player(e);+ if (p) {+ b->move_speed = 80;+ b->windup_start = 0;+ b->bounce_dir = b->ice ? v2(0, -1) : safe_norm(v2sub(player_center(p), e_center(e)), 1);+ b->state = BB_WINDUP;+ if (b->ice) plat_start_shaking(e, 0.2f);+ }+ break;+ }+ case BB_WINDUP: {+ Player *p = bb_windup_player(e);+ if (p) b->bounce_dir = b->ice ? v2(0, -1) : safe_norm(v2sub(player_center(p), e_center(e)), 1);+ if (b->windup_start > 0) {+ b->windup_start -= DT;+ b->windup = approach(b->windup, 0, DT);+ break;+ }+ b->move_speed = approach(b->move_speed, b->ice ? 35 : 40, 600 * DT);+ float k = b->ice ? 0.333f : 1;+ V2 target = v2sub(b->start, v2mul(b->bounce_dir, b->ice ? 16 : 10));+ V2 to = approach_v(ex, target, b->move_speed * k * DT);+ V2 lift = safe_norm(v2sub(to, ex), b->move_speed * k);+ lift.x *= 0.75f;+ bb_move_to(e, to, lift);+ b = ST(e, Bounce);+ ex = plat_exact(e);+ b->windup = clamped_map(v2len(v2sub(ex, target)), 16, 2, 0, 1);+ if (b->ice && dist2(ex, target) <= 12) plat_start_shaking(e, 0.1f);+ else if (!b->ice && b->windup >= 0.5f) plat_start_shaking(e, 0.1f);+ if (dist2(ex, target) <= 2) {+ if (b->ice) bb_break(e);+ else b->state = BB_BOUNCING;+ ST(e, Bounce)->move_speed = 0;+ }+ break;+ }+ case BB_BOUNCING: {+ b->move_speed = approach(b->move_speed, 140, 800 * DT);+ V2 target = v2add(b->start, v2mul(b->bounce_dir, 24));+ V2 to = approach_v(ex, target, b->move_speed * DT);+ b->bounce_lift = safe_norm(v2sub(to, ex), fminf(b->move_speed * 3, 200));+ b->bounce_lift.x *= 0.75f;+ bb_move_to(e, to, b->bounce_lift);+ b = ST(e, Bounce);+ b->windup = 1;+ if (v2eq(plat_exact(e), target) || (!b->ice && !bb_windup_player(e))) {+ b->debris_dir = safe_norm(v2sub(target, b->start), 1);+ b->state = BB_END;+ b->move_speed = 0;+ b->bounce_end = 0.05f;+ Player *p = bb_windup_player(e); /* ShakeOffPlayer */+ if (p) {+ player_set_state(p, ST_NORMAL);+ p->speed = b->bounce_lift;+ p->jump_grace_timer = 0.1f; /* StartJumpGraceTime */+ }+ }+ break;+ }+ case BB_END:+ b->bounce_end -= DT;+ if (b->bounce_end <= 0) bb_break(e);+ break;+ case BB_BROKEN: {+ if (e->depth != 8990) e->depth = 8990, ents_mark_unsorted();+ b->reformed = 0;+ if (b->respawn > 0) {+ b->respawn -= DT;+ break;+ }+ float px = e->x, py = e->y;+ e->x = b->start.x, e->y = b->start.y;+ bool blocked = false;+ e->collidable = 1;+ for (int i = 0; i < g_nents && !blocked; i++) {+ Ent *o = &g_ents[i];+ if (o != e && o->cls && o->dead != 1 && o->collidable && (o->kind & (KIND_ACTOR | KIND_SOLID)) && collide_ent_at(e, e->x, e->y, o))+ blocked = true;+ }+ e->collidable = 0;+ if (blocked) {+ e->x = px, e->y = py;+ break;+ }+ bb_mode_check(b);+ for (int i = 0; i < e->cw; i += 8)+ for (int j = 0; j < e->ch; j += 8) {+ V2 at = v2(e->x + i + 4, e->y + j + 4);+ debris_add(v2add(at, safe_norm(v2sub(at, e_center(e)), 12)), at, 0.35f, b->ice, true);+ }+ b->alarm = 0.35f;+ e->depth = -9000;+ ents_mark_unsorted();+ plat_static_movers_move(e, v2(e->x - px, e->y - py));+ e->collidable = 1;+ b->state = BB_WAITING;+ break;+ }+ }+}+static void bb_render(Ent *e) {+ Bounce *b = ST(e, Bounce);+ float x = e->x + e->shakex, y = e->y + e->shakey;+ if (b->state != BB_BROKEN && b->reformed) {+ int nx = 8, ny = 8; /* the 64x64 sources: 8 cells */+ for (int i = 0; i < e->cw; i += 8)+ for (int j = 0; j < e->ch; j += 8) {+ int ci = i == 0 ? 0 : i >= e->cw - 8 ? nx - 1 : 1 + (int)(hash01(b->seed + b->ice * 7919u, (uint32_t)(i * 64 + j) * 2) * (nx - 2));+ int cj = j == 0 ? 0 : j >= e->ch - 8 ? ny - 1 : 1 + (int)(hash01(b->seed + b->ice * 7919u, (uint32_t)(i * 64 + j) * 2 + 1) * (ny - 2));+ gfx_tex_part(bb_tex[b->ice], x + i, y + j, ci * 8, cj * 8, 8, 8, 0, 0xFFFF, 255);+ }+ cs_draw(b->ice ? &b->cold_center : &b->hot_center, x + e->cw / 2, y + e->ch / 2, 1, 1, 0xFFFF, 255, 0);+ }+ if (b->flash > 0) {+ float k = ease_cube_out(b->flash), n = k * 2;+ gfx_rect(e->x - n, e->y - n, e->cw + n * 2, e->ch + n * 2, 0xFFFF, a8(k));+ }+}+static void bb_on_mode(Ent *e, int mode) { ST(e, Bounce)->ice_next = mode == 2; }+static void bb_awake(Ent *e) {+ Bounce *b = ST(e, Bounce);+ b->ice_next = b->ice = g_level.core_mode == 2;+}+static const EntClass BOUNCE = {.name = "bounceBlock", .size = sizeof(Bounce), .update = bb_update, .render = bb_render, .awake = bb_awake,+ .kind = KIND_SOLID};+static void new_bounce(const EData *d) {+ Ent *e = ent_new(&BOUNCE, d->x, d->y);+ if (!e) return;+ ent_box(e, EA(d, bounceBlock, width), EA(d, bounceBlock, height), 0, 0);+ e->depth = -9000;+ Bounce *b = ST(e, Bounce);+ b->start = v2(d->x, d->y);+ b->reformed = 1;+ b->seed = (uint16_t)rndi(65536);+ cs_init(&b->hot_center, SB_bumpBlockCenterFire);+ cs_init(&b->cold_center, SB_bumpBlockCenterIce);+ if (!bb_tex[0]) {+ bb_tex[0] = tex_named("objects/BumpBlockNew/fire00");+ bb_tex[1] = tex_named("objects/BumpBlockNew/ice00");+ tex_family("objects/BumpBlockNew/fire_rubble", bb_rubble[0], 4);+ tex_family("objects/BumpBlockNew/ice_rubble", bb_rubble[1], 4);+ }+ debris_manager();+}++/* ---------------------------------------------------------------- HeartGemDoor */+typedef struct {+ float open_dist, open_pct, counter, offset, heart_alpha, co_wait, p, from[2], to[2];+ V2 mist;+ uint16_t seed;+ uint8_t requires, opened, start_hidden, co, top, bot, pad[2];+} HDoor;+static uint16_t hd_icon[7];+/* HeartGemDoor.P_Shimmer (tools/gen_particles.py does not output it) */+static const PType P_SHIMMER = {0xFFBAFFFF, 0xFF5ABCE2, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 2.0f, 5.0f, 1.0f, 1.4f, 2.0f, 0.0f,+ 1.0471976f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+static int hearts_total(void) { /* SaveData.TotalHeartGems */+ int n = 0;+ for (int a = 0; a < AREAS; a++)+ for (int m = 0; m < 3; m++)+ if (g_save.modes[a][m].flags & MS_HEART) n++;+ return n;+}+static const EntClass DOORSOLID;+static void doorsolid_update(Ent *e) { plat_update(e); }+static const EntClass DOORSOLID = {.name = "heartGemDoorSolid", .update = doorsolid_update, .kind = KIND_SOLID};+static void hd_white_line(Ent *e);+static void hd_update(Ent *e) {+ HDoor *h = ST(e, HDoor);+ Ent *top = ent_at(h->top), *bot = ent_at(h->bot);+ bool ok = top->cls == &DOORSOLID && bot->cls == &DOORSOLID;+ Player *p = level_player();+ /* Routine() */+ if (ok && h->co) {+ if (h->co_wait > 0) h->co_wait -= DT;+ else+ switch (h->co) {+ case 1: /* startHidden: wait for the player */+ if (!h->start_hidden) {+ h->co = 10;+ goto counting;+ }+ if (!p || fabsf(p->ent->x - e_cxm(e)) >= 100) break;+ e->visible = 1;+ h->heart_alpha = 0;+ h->to[0] = top->y, h->to[1] = bot->y;+ top->y -= 240, bot->y -= 240;+ h->from[0] = top->y, h->from[1] = bot->y;+ h->p = 0;+ h->co = 2;+ /* fall through */+ case 2:+ if (h->p < 1) {+ float k = ease_cube_in(h->p);+ plat_move_to_y(top, h->from[0] + (h->to[0] - h->from[0]) * k);+ plat_move_to_y(bot, h->from[1] + (h->to[1] - h->from[1]) * k);+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o->cls && o->dead != 1 && level_is_dash_block(o) && collide_ent_at(o, o->x, o->y, bot)) {+ level_shake(0.5f);+ level_freeze(0.1f);+ level_break_dash_block(o, v2(0, 1));+ if (p && fabsf(p->ent->x - e_cxm(e)) < 40) player_point_bounce(p, v2(p->ent->x + 8, p->ent->y));+ }+ }+ h->p += DT * 1.2f;+ break;+ }+ level_shake(0.5f);+ level_freeze(0.1f);+ top->y = h->to[0], bot->y = h->to[1];+ h->co = 3;+ /* fall through */+ case 3:+ if (h->heart_alpha < 1) {+ h->heart_alpha = approach(h->heart_alpha, 1, DT * 2);+ break;+ }+ h->co_wait = 0.6f;+ h->co = 10;+ break;+ case 10:+ counting:+ if (!h->opened && h->counter < h->requires) {+ if (p && fabsf(p->ent->x - e_cxm(e)) < 80 && p->ent->x < e->x) {+ int hearts = hearts_total();+ if (hearts < h->requires) level_set_flag("granny_door", true);+ int was = (int)h->counter, target = hearts < h->requires ? hearts : h->requires;+ h->counter = approach(h->counter, (float)target, DT * h->requires * 0.8f);+ if (was != (int)h->counter) h->co_wait = 0.1f;+ } else+ h->counter = approach(h->counter, 0, DT * h->requires * 4);+ break;+ }+ h->co_wait = 0.5f;+ h->co = 11;+ break;+ case 11: {+ hd_white_line(e);+ level_shake(0.3f);+ level_flash_a(0xFFFF, 0.5f, false);+ h->opened = 1;+ char flag[40];+ level_set_flag(path2(flag, "opened_heartgem_door_", NULL, h->requires), true);+ h->offset = 0;+ h->co_wait = 0.6f;+ h->co = 12;+ break;+ }+ case 12:+ h->from[0] = top->y, h->to[0] = top->y - h->open_dist;+ h->from[1] = bot->y, h->to[1] = bot->y + h->open_dist;+ h->p = 0;+ h->co = 13;+ /* fall through */+ case 13:+ if (h->p < 1) {+ level_shake(0.3f);+ h->open_pct = ease_cube_in(h->p);+ plat_move_to_y(top, lerpf(h->from[0], h->to[0], h->open_pct));+ plat_move_to_y(bot, lerpf(h->from[1], h->to[1], h->open_pct));+ if (h->p >= 0.4f && level_on_interval(0.1f))+ for (int i = 4; i < e->cw; i += 4) {+ particles_emit(PL_BG, &P_SHIMMER, 1, v2(e_left(top) + i + 1, e_bottom(top) - 2), v2(2, 2), -PI_F / 2);+ particles_emit(PL_BG, &P_SHIMMER, 1, v2(e_left(bot) + i + 1, e_top(bot) + 2), v2(2, 2), PI_F / 2);+ }+ h->p += DT;+ break;+ }+ plat_move_to_y(top, h->to[0]);+ plat_move_to_y(bot, h->to[1]);+ h->open_pct = 1;+ h->co = 0;+ break;+ }+ }+ h = ST(e, HDoor);+ if (!h->opened) {+ h->offset += 12 * DT;+ h->mist.x -= 4 * DT;+ h->mist.y -= 24 * DT;+ }+}+static float fmodp(float x, float m) { return fmodf(fmodf(x, m) + m, m); }+/* DrawInterior: the color, two mists, the falling sparkles (a pixel each) */+static void hd_interior(Ent *e, float bx, float by, int w, int h) {+ HDoor *d = ST(e, HDoor);+ gfx_rect(bx, by, (float)w, (float)h, rgb(0x18668F), 255);+ for (int pass = 0; pass < 2; pass++) {+ V2 m = pass ? v2(d->mist.y * 1.5f, d->mist.x * 1.5f) : d->mist;+ for (int i = 0; i < w; i += 160)+ for (int j = 0; j < h; j += 160) {+ int sw = 160 < w - i ? 160 : w - i, sh = 160 < h - j ? 160 : h - j;+ gfx_tex_part(T_objects_heartdoor_mist, bx + i, by + j, (int)fmodp(m.x, 160), (int)fmodp(m.y, 160), sw, sh, 0, 0xFFFF, 153);+ }+ }+ V2 cam = d->opened ? v2(0, 0) : g_level.cam;+ Room *rm = g_level.room;+ for (int i = 0; i < 50; i++) {+ float speed = (float)(4 + (int)(hash01(d->seed, 3u * i + 2) * 8));+ float px = hash01(d->seed, 3u * i) * e->cw, py = hash01(d->seed, 3u * i + 1) * rm->h + speed * g_level.time_active;+ if (d->opened) py = hash01(d->seed, 3u * i + 1) * rm->h;+ float x = fmodp(px + cam.x * 0.2f, (float)w), y = fmodp(py + cam.y * 0.2f, (float)h);+ gfx_pixel(bx + x, by + y, 0xFFFF, a8(0.2f + hash01(d->seed ^ 77u, (uint32_t)i) * 0.4f));+ }+}+static void hd_edges(Ent *e, float bx, float by, int w, int h, uint8_t alpha) {+ HDoor *d = ST(e, HDoor);+ int num = (int)fmodf(d->offset, 8);+ uint16_t edge = T_objects_heartdoor_edge, top = T_objects_heartdoor_top;+ /* DrawJustified((0.5, 0)) of 8-wide parts, the left one flipped */+ if (num > 0) {+ gfx_tex_part(edge, bx + 4 - 4, by, 0, 8 - num, 7, num, GF_FLIPX, 0xFFFF, alpha);+ gfx_tex_part(edge, bx + w - 4 - 3.5f, by, 0, 8 - num, 7, num, 0, 0xFFFF, alpha);+ }+ for (int i = num; i < h; i += 8) {+ int hh = 8 < h - i ? 8 : h - i;+ gfx_tex_part(edge, bx, by + i, 0, 0, 8, hh, GF_FLIPX, 0xFFFF, alpha);+ gfx_tex_part(edge, bx + w - 8, by + i, 0, 0, 8, hh, 0, 0xFFFF, alpha);+ }+ for (int j = 0; j < w; j += 8) {+ gfx_tex(top, bx + j, by, 0, 0xFFFF, alpha);+ gfx_tex(top, bx + j, by + h - 8, GF_FLIPY, 0xFFFF, alpha);+ }+}+static void hd_render(Ent *e) {+ HDoor *d = ST(e, HDoor);+ Ent *top = ent_at(d->top), *bot = ent_at(d->bot);+ if (top->cls != &DOORSOLID || bot->cls != &DOORSOLID) return;+ uint8_t alpha = d->opened ? 64 : 255;+ int w = (int)e->cw;+ if (!d->opened) {+ hd_interior(e, (float)(int)top->x, (float)(int)top->y, w, (int)(top->ch + bot->ch));+ hd_edges(e, (float)(int)top->x, (float)(int)top->y, w, (int)(top->ch + bot->ch), alpha);+ } else {+ hd_interior(e, (float)(int)top->x, (float)(int)top->y, w, (int)top->ch);+ hd_edges(e, (float)(int)top->x, (float)(int)top->y, w, (int)top->ch, alpha);+ hd_interior(e, (float)(int)bot->x, (float)(int)bot->y, w, (int)bot->ch);+ hd_edges(e, (float)(int)bot->x, (float)(int)bot->y, w, (int)bot->ch, alpha);+ }+ if (d->heart_alpha <= 0) return;+ float num = 12;+ int per = (int)((e->cw - 8) / num), rows = (int)ceilf((float)d->requires / per);+ uint8_t a = (uint8_t)(alpha * d->heart_alpha);+ for (int i = 0; i < rows; i++) {+ int n = (i + 1) * per < d->requires ? per : d->requires - i * per;+ V2 at = v2add(v2(e->x + e->cw * 0.5f, e->y), v2mul(v2(-n / 2.f + 0.5f, -rows / 2.f + i + 0.5f), num));+ if (d->opened) at.y += (i < rows / 2 ? -1 : 1) * (d->open_pct * d->open_dist + 8);+ for (int j = 0; j < n; j++) {+ int k = i * per + j;+ float f = ease_cube_in(clamped_map(d->counter, (float)k, k + 1.f, 0, 1));+ draw_centered(hd_icon[(int)(f * 6)], at.x + j * num, at.y, 0xFFFF, a);+ }+ }+}+/* WhiteLine: a line across the screen that thins out, then sparkles along it */+typedef struct { float fade; int16_t size, pad; } WhiteLine;+static void wl_update(Ent *e) {+ WhiteLine *w = ST(e, WhiteLine);+ w->fade = approach(w->fade, 0, DT);+ if (w->fade > 0) return;+ ent_remove(e);+ for (float x = (float)(int)g_level.cam.x; x < g_level.cam.x + 320; x += 1)+ if (x < e->x || x >= e->x + w->size) particles_emit1(PL_MID, &P_HeartGemDoor_P_Slice, v2(x, e->y), 0);+}+static void wl_render(Ent *e) {+ WhiteLine *w = ST(e, WhiteLine);+ float n = fmaxf(1, 4 * w->fade);+ gfx_rect(g_level.cam.x - 10, e->y - n / 2, 340, n, 0xFFFF, 255);+}+static const EntClass WHITELINE = {.name = "heartGemDoorWhiteLine", .size = sizeof(WhiteLine), .update = wl_update, .render = wl_render};+static void hd_white_line(Ent *e) {+ Ent *w = ent_new(&WHITELINE, e->x, e->y);+ if (!w) return;+ w->depth = -1000000;+ w->collidable = 0;+ ST(w, WhiteLine)->fade = 1;+ ST(w, WhiteLine)->size = (int16_t)e->cw;+}+static void hd_awake(Ent *e) {+ HDoor *h = ST(e, HDoor);+ Ent *bot = ent_at(h->bot);+ if (bot->cls != &DOORSOLID) return;+ if (h->opened) {+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls && level_is_dash_block(&g_ents[i]) && collide_ent_at(&g_ents[i], g_ents[i].x, g_ents[i].y, bot)) ent_remove(&g_ents[i]);+ } else if (h->start_hidden) {+ Ent *pe = level_player_ent();+ if (pe && pe->x > e->x) {+ h->start_hidden = 0;+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls && level_is_dash_block(&g_ents[i]) && collide_ent_at(&g_ents[i], g_ents[i].x, g_ents[i].y, bot))+ ent_remove(&g_ents[i]);+ } else+ e->visible = 0;+ }+}+static const EntClass HDOOR = {.name = "heartGemDoor", .size = sizeof(HDoor), .update = hd_update, .render = hd_render, .awake = hd_awake};+static void new_hdoor(const EData *d) {+ Room *rm = NULL;+ for (int s = 0; s < 2; s++)+ if (g_level.rooms[s].index == d->room) rm = &g_level.rooms[s];+ if (!rm) rm = g_level.room;+ float w = EA(d, heartGemDoor, width);+ Ent *e = ent_new(&HDOOR, d->x, d->y);+ if (!e) return;+ ent_box(e, w, 0, 0, 0);+ e->collidable = 0;+ HDoor *h = ST(e, HDoor);+ h->requires = (uint8_t)EA(d, heartGemDoor, requires);+ h->open_dist = d->nnodes ? fabsf(ed_node(d, 0).y - d->y) : 32;+ h->start_hidden = EAB(d, heartGemDoor, startHidden);+ h->heart_alpha = 1;+ h->seed = (uint16_t)rndi(65536);+ h->co = 1;+ if (!hd_icon[0]) tex_family("objects/heartdoor/icon", hd_icon, 7);+ /* Added: the two solids above and below */+ Ent *top = ent_new(&DOORSOLID, d->x, rm->y - 32);+ Ent *bot = ent_new(&DOORSOLID, d->x, d->y);+ h = ST(e, HDoor);+ if (!top || !bot) return;+ ent_box(top, w, d->y - rm->y + 32, 0, 0);+ ent_box(bot, w, rm->y + rm->h - d->y + 32, 0, 0);+ top->safe = bot->safe = 1;+ top->visible = bot->visible = 0;+ h->top = ent_ref(top), h->bot = ent_ref(bot);+ char flag[40];+ if (level_get_flag(path2(flag, "opened_heartgem_door_", NULL, h->requires))) {+ h->opened = 1;+ h->open_pct = 1;+ h->counter = h->requires;+ top->y -= h->open_dist;+ bot->y += h->open_dist;+ h->co = 0;+ }+}++/* ---------------------------------------------------------------- the core mode's listeners */+static void core_listeners(int mode) {+ for (int i = 0; i < g_nents; i++) {+ Ent *e = &g_ents[i];+ if (!e->cls || e->dead == 1) continue;+ if (e->cls == &TOGGLE) toggle_on_mode(e, mode);+ else if (e->cls == &FIRE) {+ if (!ST(e, Fire)->not_core) fire_on_mode(e, mode);+ } else if (e->cls == &WALLBOOSTER)+ wb_on_mode(e, mode);+ else if (e->cls == &FIREBARRIER || e->cls == &ICEBLOCK)+ barrier_on_mode(e, mode);+ else if (e->cls == &RISING2 || e->cls == &SANDWICH)+ rising_on_mode(e, mode);+ else if (e->cls == &BOUNCE)+ bb_on_mode(e, mode);+ }+}++/* ---------------------------------------------------------------- triggers */+typedef struct { V2 target, lerp; uint8_t mode_x, mode_y, xonly, yonly; } AdvTrig;+static float pos_lerp(Ent *e, Player *p, int mode) { /* Trigger.GetPositionLerp */+ float px = e_cxm(p->ent), py = e_cym(p->ent);+ float l = e_left(e), r = e_right(e), t = e_top(e), b = e_bottom(e), cx = e_cxm(e), cy = e_cym(e);+#define CMAP(v, a, bb) clampf(((v) - (a)) / ((bb) - (a)), 0, 1)+ switch (mode) {+ case 1: return CMAP(px, l, r);+ case 2: return CMAP(px, r, l);+ case 3: return CMAP(py, t, b);+ case 4: return CMAP(py, b, t);+ case 5: return fminf(CMAP(px, l, cx), CMAP(px, r, cx));+ case 6: return fminf(CMAP(py, t, cy), CMAP(py, b, cy));+ default: return 1;+ }+#undef CMAP+}+static int pos_mode(const char *m) {+ static const char *MODES[] = {"NoEffect", "LeftToRight", "RightToLeft", "TopToBottom", "BottomToTop", "HorizontalCenter", "VerticalCenter"};+ for (int i = 0; i < 7; i++)+ if (!strcmp(m, MODES[i])) return i;+ return 0;+}+static void adv_stay(Ent *e, Player *p) {+ AdvTrig *t = ST(e, AdvTrig);+ p->cam_anchor = t->target;+ p->cam_anchor_lerp = v2(clampf(t->lerp.x * pos_lerp(e, p, t->mode_x), 0, 1), clampf(t->lerp.y * pos_lerp(e, p, t->mode_y), 0, 1));+ p->cam_anchor_ignore_x = t->yonly;+ p->cam_anchor_ignore_y = t->xonly;+}+static void adv_leave(Ent *e, Player *p) {+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o == e || !o->cls || o->dead == 1 || !o->triggered) continue;+ if (!strcmp(o->cls->name, "cameraTargetTrigger") || !strcmp(o->cls->name, "cameraAdvanceTargetTrigger")) return;+ }+ p->cam_anchor_lerp = v2(0, 0);+}+static const EntClass ADVTRIG = {.name = "cameraAdvanceTargetTrigger", .size = sizeof(AdvTrig), .on_stay = adv_stay, .on_leave = adv_leave,+ .kind = KIND_TRIGGER};+typedef struct { uint8_t state; } NoRefill;+static void norefill_enter(Ent *e, Player *p) {+ g_session.no_refills = ST(e, NoRefill)->state; /* Session.Inventory.NoRefills */+ p->inventory_norefills = ST(e, NoRefill)->state;+}+static const EntClass NOREFILL = {.name = "noRefillTrigger", .size = sizeof(NoRefill), .on_enter = norefill_enter, .kind = KIND_TRIGGER};++/* ---------------------------------------------------------------- CoreMessage */+typedef struct { float alpha; uint8_t line; } CoreMsg;+/* Dialog.Clean("app_ending").Split('\n')[line]: the cleaned text runs its lines together, a line ending where a+ * sentence's end meets a capital */+static int core_line(int line, char *out, int cap) {+ char all[200];+ int n = dialog_clean("app_ending", all, sizeof all), k = 0, at = 0;+ for (int i = 0; i < n; i++) {+ if (k == line && at < cap - 1) out[at++] = all[i];+ if ((all[i] == '.' || all[i] == '?' || all[i] == '!') && i + 1 < n && all[i + 1] >= 'A' && all[i + 1] <= 'Z') k++;+ }+ out[at] = 0;+ return at;+}+static void coremsg_update(Ent *e) {+ Player *p = level_player();+ if (p) ST(e, CoreMsg)->alpha = ease_cube_inout(clamped_map(fabsf(e->x - p->ent->x), 0, 128, 1, 0));+}+static void coremsg_render(Ent *e) {+ CoreMsg *m = ST(e, CoreMsg);+ char text[64];+ if (m->alpha <= 0 || !core_line(m->line, text, sizeof text)) return;+ float x = e->x - g_level.cam.x, y = e->y - g_level.cam.y;+ gfx_hud(true);+ font_draw_justified(text, x + (x - 160) * 0.2f, y + (y - 90) * 0.2f, 0.5f, 0.5f, FONT_S, 0xFFFF, (uint8_t)(m->alpha * 255));+ gfx_hud(false);+}+static const EntClass COREMSG = {.name = "coreMessage", .size = sizeof(CoreMsg), .update = coremsg_update, .render = coremsg_render};++/* ---------------------------------------------------------------- NPC09_Granny_Inside and _Outside */+/* Session.GetCounter / IncrementCounter */+static int32_t *session_counter(const char *name) {+ uint32_t h = 2166136261u;+ for (const char *s = name; *s; s++) h = (h ^ (uint8_t)*s) * 16777619u;+ h |= 1;+ for (int i = 0; i < 3; i++)+ if (g_session.counters[i].key == h) return &g_session.counters[i].value;+ for (int i = 0; i < 3; i++)+ if (!g_session.counters[i].key) {+ g_session.counters[i].key = h, g_session.counters[i].value = 0;+ return &g_session.counters[i].value;+ }+ return &g_session.counters[2].value;+}+enum { G_CONV, G_TALKING, G_LEAVING }; /* the grannies' Npc.i[] */+static bool granny_door_talk(void) { return level_get_flag("granny_door") && !level_get_flag("granny_door_done"); }+static bool granny_talker_on(Ent *e) {+ int conv = NPC_(e)->i[G_CONV];+ return conv <= 0 || conv >= 4 ? granny_door_talk() : true;+}+typedef struct {+ Cutscene cs;+ Ent *granny, *tb;+ Walk walk;+ Step step;+ V2 zoom_at;+ Co ev;+ int8_t ev_i;+ uint8_t door;+} GTalk;+static bool gtalk_nb(GTalk *s, Co *c, int i) {+ Npc *n = NPC_(s->granny);+ if (n->which == NPC_GRANNY09_OUT) {+ if (i == 0) { /* MoveRight */+ NB_BEGIN(c);+ npc_move_to(s->granny, v2(s->granny->x + 8, s->granny->y), false, 0, false);+ NB_AWAIT(c, &n->mv);+ NB_END(c);+ }+ NB_BEGIN(c); /* ExitRight */+ n->i[G_LEAVING] = 1;+ npc_move_to(s->granny, v2(g_level.room->x + g_level.room->w + 16, s->granny->y), false, 0, false);+ NB_YIELD(c);+ NB_END(c);+ }+ NB_BEGIN(c); /* StartLaughing, StopLaughing */+ spr_play(&n->spr, i == 0 ? A_granny_laugh : A_granny_idle, false);+ NB_YIELD(c);+ NB_END(c);+}+static bool gtalk_ev(void *ctx, int i) {+ GTalk *s = ST((Ent *)ctx, GTalk);+ return !gtalk_nb(s, ev_co(&s->ev, &s->ev_i, i), i);+}+static const char *const GRANNY_TALKS[4] = {"APP_OLDLADY_B", "APP_OLDLADY_C", "APP_OLDLADY_D", "APP_OLDLADY_E"};+static void gtalk_update(Ent *e) {+ GTalk *s = ST(e, GTalk);+ Player *p = &g_player;+ Npc *n = NPC_(s->granny);+ Co *c = &s->cs.co;+ CO_BEGIN(c);+ player_set_state(p, ST_DUMMY);+ s->ev_i = -1;+ if (n->which == NPC_GRANNY09_OUT) { /* NPC09_Granny_Outside.TalkRoutine */+ while (!actor_on_ground(p->ent, 1)) CO_YIELD(c);+ n->spr.sx = -1;+ CO_WALK(c, s->walk, walk_exact((int)s->granny->x - 16));+ CO_WAIT(c, 0.5f);+ CO_ZOOM_TO(c, &s->step, v2(200, 110), 2, 0.5f);+ CO_SAY(c, s->tb, "APP_OLDLADY_A", gtalk_ev, e);+ CO_ZOOM_BACK(c, &s->step, 0.5f);+ n->spr.sx = 1;+ if (!n->i[G_LEAVING]) { /* yield return ExitRight() */+ CO_YIELD(c);+ n->i[G_LEAVING] = 1;+ npc_move_to(s->granny, v2(g_level.room->x + g_level.room->w + 16, s->granny->y), false, 0, false);+ CO_YIELD(c);+ CO_YIELD(c);+ }+ while (s->granny->x < g_level.room->x + g_level.room->w + 8) CO_YIELD(c);+ } else { /* NPC09_Granny_Inside.TalkRoutine */+ p->dashes = 1;+ p->force_camera_update = true;+ while (!actor_on_ground(p->ent, 1)) CO_YIELD(c);+ CO_WALK(c, s->walk, walk_exact((int)s->granny->x - 16));+ p->facing = 1;+ p->force_camera_update = false;+ s->zoom_at = v2(s->granny->x - 8 - g_level.cam.x, 110);+ s->door = granny_door_talk();+ if (s->door) {+ n->spr.sx = -1;+ CO_ZOOM_TO(c, &s->step, s->zoom_at, 2, 0.5f);+ CO_SAY(c, s->tb, "APP_OLDLADY_LOCKED", NULL, NULL);+ } else if (n->i[G_CONV] < 4) {+ if (n->i[G_CONV] == 0) {+ CO_WAIT(c, 0.5f);+ n->spr.sx = -1;+ CO_WAIT(c, 0.25f);+ } else+ n->spr.sx = -1;+ CO_ZOOM_TO(c, &s->step, s->zoom_at, 2, 0.5f);+ CO_SAY(c, s->tb, GRANNY_TALKS[n->i[G_CONV]], gtalk_ev, e);+ }+ n->talk.enabled = granny_talker_on(s->granny);+ CO_ZOOM_BACK(c, &s->step, 0.5f);+ }+ cutscene_end(e);+ return;+ CO_END(c);+}+static void gtalk_end(Ent *e, bool skipped) { /* EndTalking */+ GTalk *s = ST(e, GTalk);+ Npc *n = NPC_(s->granny);+ (void)skipped;+ player_set_state(&g_player, ST_NORMAL);+ if (n->which == NPC_GRANNY09_OUT) {+ level_set_flag("granny_outside", true);+ ent_remove(s->granny);+ return;+ }+ g_player.force_camera_update = false;+ if (granny_door_talk()) level_set_flag("granny_door_done", true);+ else {+ ++*session_counter("granny");+ n->i[G_CONV]++;+ }+ spr_play(&n->spr, A_granny_idle, false);+ n->i[G_TALKING] = 0;+}+static const EntClass GTALK = {.name = "grannyTalk", .size = sizeof(GTalk), .update = gtalk_update};+static void granny9_talk(Ent *e) { /* OnTalk: Level.StartCutscene(EndTalking) and TalkRoutine */+ Ent *cs = scene_new(>ALK, gtalk_end, true, false);+ if (!cs) return;+ ST(cs, GTalk)->granny = e;+ NPC_(e)->i[G_TALKING] = 1;+}+static void granny9_think(Ent *e) {+ Npc *n = NPC_(e);+ Player *p = level_player();+ if (n->which == NPC_GRANNY09_OUT) {+ if (!n->i[G_TALKING] && p && p->ent->x > e->x - 48) granny9_talk(e);+ return;+ }+ if (!n->i[G_TALKING] && n->i[G_CONV] == 0 && p && fabsf(p->ent->x - e->x) < 48) granny9_talk(e);+ n->talk.enabled = granny_talker_on(e);+}+static bool new_granny9(const EData *d) {+ const char *who = EAS(d, npc, npc);+ bool out = !strcmp(who, "granny_09_outside");+ if (!out && strcmp(who, "granny_09_inside")) return false;+ if (out && level_get_flag("granny_outside")) return true;+ Ent *e = npc_new(d->x, d->y, SB_granny, A_granny_idle, granny9_think);+ if (!e) return true;+ Npc *n = NPC_(e);+ n->which = out ? NPC_GRANNY09_OUT : NPC_GRANNY09_IN;+ n->move_anim = A_granny_walk, n->maxspeed = 40;+ if (out) n->idle_anim = A_granny_idle;+ else {+ npc_talker(e, -20, -8, 40, 8, v2(0, -24), granny9_talk);+ n->talk.enabled = false;+ n->i[G_CONV] = *session_counter("granny");+ }+ npc_haha(e);+ return true;+}++/* ---------------------------------------------------------------- the factories */+bool ents_ch9(const EData *d) {+ switch (d->type) {+ case ET_coreModeToggle: new_toggle(d); return true;+ case ET_fireBall: new_fireball(d); return true;+ case ET_wallBooster: new_wallbooster(d); return true;+ case ET_bounceBlock: new_bounce(d); return true;+ case ET_fireBarrier: new_barrier(d, false); return true;+ case ET_iceBlock: new_barrier(d, true); return true;+ case ET_risingLava: new_rising(d, false); return true;+ case ET_sandwichLava: new_rising(d, true); return true;+ case ET_heartGemDoor: new_hdoor(d); return true;+ case ET_coreMessage: {+ Ent *e = ent_new(&COREMSG, d->x, d->y);+ if (e) e->tags = TAG_HUD, e->collidable = 0, ST(e, CoreMsg)->line = (uint8_t)EA(d, coreMessage, line);+ return true;+ }+ case ET_npc: return new_granny9(d);+ }+ return false;+}++bool trigs_ch9(const EData *d) {+ switch (d->type) {+ case TT_cameraAdvanceTargetTrigger: {+ Ent *e = ent_new(&ADVTRIG, d->x, d->y);+ if (!e) return true;+ ent_box(e, EA(d, cameraAdvanceTargetTrigger, width), EA(d, cameraAdvanceTargetTrigger, height), 0, 0);+ e->visible = 0;+ AdvTrig *t = ST(e, AdvTrig);+ t->target = v2sub(ed_node(d, 0), v2(160, 90));+ t->lerp = v2(EA(d, cameraAdvanceTargetTrigger, lerpStrengthX), EA(d, cameraAdvanceTargetTrigger, lerpStrengthY));+ t->mode_x = (uint8_t)pos_mode(EAS(d, cameraAdvanceTargetTrigger, positionModeX));+ t->mode_y = (uint8_t)pos_mode(EAS(d, cameraAdvanceTargetTrigger, positionModeY));+ t->xonly = EAB(d, cameraAdvanceTargetTrigger, xOnly);+ t->yonly = EAB(d, cameraAdvanceTargetTrigger, yOnly);+ return true;+ }+ case TT_noRefillTrigger: {+ Ent *e = ent_new(&NOREFILL, d->x, d->y);+ if (!e) return true;+ ent_box(e, EA(d, noRefillTrigger, width), EA(d, noRefillTrigger, height), 0, 0);+ e->visible = 0;+ ST(e, NoRefill)->state = EAB(d, noRefillTrigger, state);+ return true;+ }+ }+ return false;+}++/* this chapter's tables: in the memory it is given while it is played (res_chapter_ram) */+uint32_t ch9_ram(void) { return END_debris; }diff --git a/games/celeste/src/cutscene.c b/games/celeste/src/cutscene.cnew file mode 100644index 00000000..e710b333--- /dev/null+++ b/games/celeste/src/cutscene.c@@ -0,0 +1,130 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* CutsceneEntity's part in the level (starting, ending and skipping a+ * cutscene), the zoom and camera moves cutscenes use. */+#include "cutscene.h"++/* ---------------------------------------------------------------- CutsceneEntity */+void cutscene_start(Ent *e, void (*on_end)(Ent *e, bool skipped), bool fade_in_on_skip, bool ending_after) {+ Cutscene *c = ST(e, Cutscene);+ c->running = true;+ c->on_end = on_end;+ c->fade_in_on_skip = fade_in_on_skip;+ c->ending_after = ending_after;+ g_level.in_cutscene = true; /* Level.StartCutscene */+ g_level.cutscene = e;+}++void cutscene_end(Ent *e) {+ Cutscene *c = ST(e, Cutscene);+ c->running = false;+ if (c->on_end) c->on_end(e, c->skipped);+ if (!g_level.skipping_cutscene) g_level.in_cutscene = false; /* Level.EndCutscene */+ if (g_level.cutscene == e) g_level.cutscene = NULL;+ ent_remove(e);+}++bool level_can_skip_cutscene(void) { return g_level.in_cutscene && g_level.cutscene && !g_level.skipping_cutscene; }++/* SkipCutsceneRoutine: a fade out, the cutscene's end, a fade in */+static void skip_faded_in(void) {+ g_level.skipping_cutscene = false;+ g_level.in_cutscene = false;+}+static void skip_faded_out(void) {+ Ent *e = g_level.cutscene;+ bool fade_in = true;+ if (e && e->cls) {+ Cutscene *c = ST(e, Cutscene);+ c->skipped = true;+ fade_in = c->fade_in_on_skip;+ cutscene_end(e);+ }+ zoom_reset();+ if (fade_in) {+ wipe_start(WIPE_FADE, true, skip_faded_in);+ g_wipe.duration = 0.25f;+ } else+ skip_faded_in();+}+void level_skip_cutscene(void) {+ if (!level_can_skip_cutscene()) return;+ g_level.skipping_cutscene = true;+ /* the textboxes go */+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls && g_ents[i].cls->name && !strcmp(g_ents[i].cls->name, "textbox")) ent_remove(&g_ents[i]);+ wipe_start(WIPE_FADE, false, skip_faded_out);+ g_wipe.duration = 0.25f;+}++/* ---------------------------------------------------------------- zoom */+void zoom_snap(V2 focus, float zoom) {+ g_level.zoom_focus = focus;+ g_level.zoom_target = g_level.zoom = zoom;+}+void zoom_reset(void) {+ g_level.zoom = g_level.zoom_target = 1;+ g_level.zoom_focus = v2(160, 90);+}+bool zoom_to(Step *s, V2 focus, float zoom, float duration) {+ if (s->p < 0) {+ g_level.zoom_focus = focus;+ g_level.zoom_target = zoom;+ s->from_zoom = g_level.zoom;+ s->p = 0;+ } else+ s->p += DT / duration;+ if (s->p < 1) {+ g_level.zoom = lerpf(s->from_zoom, g_level.zoom_target, ease_sine_inout(clampf(s->p, 0, 1)));+ return true;+ }+ g_level.zoom = g_level.zoom_target;+ return false;+}+bool zoom_across(Step *s, V2 focus, float zoom, float duration) {+ if (s->p < 0) {+ s->from_zoom = g_level.zoom;+ s->from = g_level.zoom_focus;+ s->p = 0;+ } else+ s->p += DT / duration;+ if (s->p < 1) {+ float k = ease_sine_inout(clampf(s->p, 0, 1));+ g_level.zoom = g_level.zoom_target = lerpf(s->from_zoom, zoom, k);+ g_level.zoom_focus = v2lerp(s->from, focus, k);+ return true;+ }+ g_level.zoom = g_level.zoom_target;+ g_level.zoom_focus = focus;+ return false;+}+bool zoom_back(Step *s, float duration) {+ if (s->p < 0) {+ s->from_zoom = g_level.zoom;+ s->p = 0;+ } else+ s->p += DT / duration;+ if (s->p < 1) {+ g_level.zoom = lerpf(s->from_zoom, 1, ease_sine_inout(clampf(s->p, 0, 1)));+ return true;+ }+ zoom_reset();+ return false;+}++/* ---------------------------------------------------------------- the camera */+bool camera_to(Step *s, V2 target, float duration, float (*ease)(float)) {+ if (!ease) ease = ease_cube_inout;+ if (s->p < 0) {+ s->from = g_level.cam;+ s->p = 0;+ } else+ s->p += DT / duration;+ if (s->p < 1) {+ g_level.cam = v2add(s->from, v2mul(v2sub(target, s->from), ease(s->p)));+ return true;+ }+ g_level.cam = target;+ return false;+}diff --git a/games/celeste/src/cutscene.h b/games/celeste/src/cutscene.hnew file mode 100644index 00000000..dfa8eefb--- /dev/null+++ b/games/celeste/src/cutscene.h@@ -0,0 +1,131 @@+/* Cutscenes: Monocle's coroutines in C, CutsceneEntity, the level's zoom and+ * camera moves, and the player's walks (Player.DummyWalkTo...). */+#ifndef CUTSCENE_H+#define CUTSCENE_H+#include "entities.h"+#include "text.h"+#include "wipe.h"++/* ---------------------------------------------------------------- coroutines+ * A coroutine keeps its place and its wait in a Co in the entity's state; its+ * body runs between CO_BEGIN and CO_END, once per update:+ * CO_YIELD yield return null+ * CO_WAIT(t) yield return t (the wait runs down first, then one more update)+ * CO_NEST yield return a nested coroutine: one update to start it, `call`+ * (true while it runs) each update after, one update when it ends+ * Locals do not survive a yield: keep them in the state. */+typedef struct { int co; float wait; } Co;+#define CO_BEGIN(c) CO_BEGIN_DT(c, DT)+#define CO_BEGIN_DT(c, dt) \+ if ((c)->wait > 0) { \+ (c)->wait -= (dt); \+ return; \+ } \+ switch ((c)->co) { \+ case 0:+#define CO_YIELD_(c, n) \+ do { \+ (c)->co = (n); \+ return; \+ case (n):; \+ } while (0)+#define CO_YIELD(c) CO_YIELD_(c, __COUNTER__ + 1)+#define CO_WAIT(c, t) \+ do { \+ (c)->wait = (t); \+ CO_YIELD(c); \+ } while (0)+#define CO_NEST(c, call) \+ do { \+ CO_YIELD(c); \+ while (call) CO_YIELD(c); \+ CO_YIELD(c); \+ } while (0)+#define CO_END(c) \+ default:; \+ } \+ (c)->co = -1+#define CO_DONE(c) ((c)->co < 0)++/* yield return Textbox.Say(key, events...): `tb` (an Ent * in the state) holds the textbox */+#define CO_SAY(c, tb, key, events, ctx) \+ do { \+ CO_YIELD(c); \+ (tb) = textbox_say(key, events, ctx); \+ while (textbox_opened(tb)) CO_YIELD(c); \+ CO_YIELD(c); \+ } while (0)++/* ---------------------------------------------------------------- CutsceneEntity */+typedef struct {+ Co co;+ bool skipped, running, fade_in_on_skip, ending_after;+ void (*on_end)(Ent *e, bool skipped); /* OnEnd(level), WasSkipped */+} Cutscene;+/* Level.StartCutscene: the cutscene's state must begin with a Cutscene */+void cutscene_start(Ent *e, void (*on_end)(Ent *e, bool skipped), bool fade_in_on_skip, bool ending_after);+void cutscene_end(Ent *e); /* EndCutscene(level): OnEnd, the level's cutscene over, removed */+void level_skip_cutscene(void); /* from the pause menu */+bool level_can_skip_cutscene(void);++/* ---------------------------------------------------------------- zoom and camera (nested steps) */+typedef struct { float p, from_zoom; V2 from, to; float zoom, duration; } Step;+void zoom_snap(V2 focus, float zoom);+bool zoom_to(Step *s, V2 focus, float zoom, float duration); /* Level.ZoomTo */+bool zoom_across(Step *s, V2 focus, float zoom, float duration); /* Level.ZoomAcross */+bool zoom_back(Step *s, float duration); /* Level.ZoomBack */+void zoom_reset(void); /* Level.ResetZoom */+bool camera_to(Step *s, V2 target, float duration, float (*ease)(float)); /* CutsceneEntity.CameraTo */+/* a step begins with p = 0: reset it before each nested use */+static inline void step_reset(Step *s) { memset(s, 0, sizeof *s); s->p = -1; }+/* ---------------------------------------------------------------- nested coroutines+ * `yield return Routine()`: a nested routine is a bool function called once an update (from CO_NEST): it+ * returns true at each of its yields and false on the update it ends. Its place and wait are in a Co. */+#define NB_BEGIN(c) \+ if ((c)->wait > 0) { \+ (c)->wait -= DT; \+ return true; \+ } \+ switch ((c)->co) { \+ case 0:+#define NB_YIELD_(c, n) \+ do { \+ (c)->co = (n); \+ return true; \+ case (n):; \+ } while (0)+#define NB_YIELD(c) NB_YIELD_(c, __COUNTER__ + 1)+#define NB_WAIT(c, t) \+ do { \+ (c)->wait = (t); \+ NB_YIELD(c); \+ } while (0)+#define NB_NEST(c, call) \+ do { \+ NB_YIELD(c); \+ while (call) NB_YIELD(c); \+ NB_YIELD(c); \+ } while (0)+#define NB_END(c) \+ default:; \+ } \+ (c)->co = 0; \+ (c)->wait = 0; \+ return false+/* yield return Textbox.Say(...) inside a nested routine */+#define NB_SAY(c, tb, key, events, ctx) \+ do { \+ NB_YIELD(c); \+ (tb) = textbox_say(key, events, ctx); \+ while (textbox_opened(tb)) NB_YIELD(c); \+ NB_YIELD(c); \+ } while (0)++/* BreathingMinigame(winnable) (src/breath.c): done once Completed (or gone); not winnable, it pauses for the+ * cutscene before the feather pops */+Ent *breath_new(bool winnable);+bool breath_done(Ent *e);+bool breath_pausing(Ent *e);+void breath_resume(Ent *e);+void breath_remove(Ent *e);+#endifdiff --git a/games/celeste/src/data.S b/games/celeste/src/data.Snew file mode 100644index 00000000..885ab471--- /dev/null+++ b/games/celeste/src/data.S@@ -0,0 +1,10 @@+/* data.bin (tools/pack.py) in the app's read-only data */+ .section .rodata.cel_data,"a"+ .balign 4+ .global cel_data+cel_data:+ .incbin DATA_BIN+ .balign 4+#ifdef __ELF__+ .section .note.GNU-stack,"",%progbits+#endifdiff --git a/games/celeste/src/data.bin b/games/celeste/src/data.binnew file mode 100644index 00000000..0ad19775Binary files /dev/null and b/games/celeste/src/data.bin differdiff --git a/games/celeste/src/data.h b/games/celeste/src/data.hnew file mode 100644index 00000000..3a3b2b67--- /dev/null+++ b/games/celeste/src/data.h@@ -0,0 +1,7359 @@+/* Generated by tools/pack.py: ids into data.bin. */+#ifndef DATA_H+#define DATA_H++#define SEC_TEX 0+#define SEC_PAL 1+#define SEC_PACKS 2+#define SEC_DIRECT 3+#define SEC_BANKS 4+#define SEC_PMETA 5+#define SEC_TILESETS 6+#define SEC_CHAPTERS 7+#define SEC_STRINGS 8+#define SEC_BLOBS 9+#define SEC_ANIMTILES 10+#define SEC_DECALANIM 11+#define SEC_TEXNAMES 12+#define SEC_FONTS 13+#define SEC_DIALOG 14+#define SEC_TEXDIM 15+#define SEC_UISTR 16++#define SB_flutterBird 0+#define A_flutterBird_idle 0+#define A_flutterBird_fly 1+#define SB_bird 1+#define A_bird_idle 0+#define A_bird_idleRarePeck 1+#define A_bird_croak 2+#define A_bird_peck 3+#define A_bird_peckRare 4+#define A_bird_jump 5+#define A_bird_fly 6+#define A_bird_dash 7+#define A_bird_fall 8+#define A_bird_sleep 9+#define A_bird_hover 10+#define A_bird_hoverStressed 11+#define A_bird_flyup 12+#define A_bird_flyupIdle 13+#define A_bird_flyupRoll 14+#define A_bird_throw 15+#define A_bird_hurt 16+#define A_bird_recover 17+#define A_bird_hold 18+#define SB_granny 2+#define A_granny_idle 0+#define A_granny_walk 1+#define A_granny_laugh 2+#define A_granny_airQuotes 3+#define A_granny_pointCane 4+#define SB_goldberry 3+#define A_goldberry_idle 0+#define A_goldberry_collect 1+#define A_goldberry_flap 2+#define SB_goldghostberry 4+#define A_goldghostberry_idle 0+#define A_goldghostberry_collect 1+#define A_goldghostberry_flap 2+#define SB_strawberry 5+#define A_strawberry_idle 0+#define A_strawberry_noFlash 1+#define A_strawberry_collect 2+#define A_strawberry_flap 3+#define A_strawberry_fade0 4+#define A_strawberry_fade1 5+#define A_strawberry_fade2 6+#define A_strawberry_fade3 7+#define A_strawberry_fade4 8+#define A_strawberry_fade5 9+#define A_strawberry_fade_wow 10+#define SB_ghostberry 6+#define A_ghostberry_idle 0+#define A_ghostberry_collect 1+#define A_ghostberry_flap 2+#define SB_strawberrySeed 7+#define A_strawberrySeed_idle 0+#define A_strawberrySeed_noFlash 1+#define SB_ghostberrySeed 8+#define A_ghostberrySeed_idle 0+#define A_ghostberrySeed_noFlash 1+#define SB_goldberrySeed 9+#define A_goldberrySeed_idle 0+#define A_goldberrySeed_noFlash 1+#define SB_cassette 10+#define A_cassette_idle 0+#define A_cassette_spin 1+#define A_cassette_pulse 2+#define SB_cassetteGhost 11+#define A_cassetteGhost_idle 0+#define A_cassetteGhost_spin 1+#define A_cassetteGhost_pulse 2+#define SB_campfire 12+#define A_campfire_idle 0+#define A_campfire_start 1+#define A_campfire_burn 2+#define A_campfire_startDream 3+#define A_campfire_burnDream 4+#define A_campfire_smoking 5+#define SB_theo 13+#define A_theo_idle 0+#define A_theo_idleEdge 1+#define A_theo_sitDown 2+#define A_theo_sleep 3+#define A_theo_wakeup 4+#define A_theo_comfortStart 5+#define A_theo_comfort 6+#define A_theo_comfortRecover 7+#define A_theo_falling 8+#define A_theo_hitGround 9+#define A_theo_idleGround 10+#define A_theo_talkGround 11+#define A_theo_recoverGround 12+#define A_theo_walk 13+#define A_theo_run 14+#define A_theo_yolo 15+#define A_theo_yoloEnd 16+#define A_theo_think 17+#define A_theo_lookBack 18+#define A_theo_duck 19+#define A_theo_crawl 20+#define A_theo_givePhone 21+#define A_theo_givePhoneFinish 22+#define A_theo_getPhone 23+#define A_theo_usePhone 24+#define A_theo_goToVent 25+#define A_theo_pullVent 26+#define A_theo_fallVent 27+#define A_theo_holdOutPhone 28+#define A_theo_takeSelfieImmediate 29+#define A_theo_takeSelfie 30+#define A_theo_tired 31+#define A_theo_alert 32+#define SB_heartgem0 14+#define A_heartgem0_idle 0+#define A_heartgem0_spin 1+#define A_heartgem0_fastspin 2+#define SB_heartGemWhite 15+#define A_heartGemWhite_idle 0+#define A_heartGemWhite_spin 1+#define A_heartGemWhite_fastspin 2+#define SB_lookout 16+#define A_lookout_idle 0+#define A_lookout_lookRight 1+#define A_lookout_lookLeft 2+#define A_lookout_looking 3+#define A_lookout_lookingUp 4+#define A_lookout_lookingUpRight 5+#define A_lookout_lookingRight 6+#define A_lookout_lookingDownRight 7+#define A_lookout_lookingDown 8+#define A_lookout_lookingDownLeft 9+#define A_lookout_lookingLeft 10+#define A_lookout_lookingUpLeft 11+#define A_lookout_badeline_idle 12+#define A_lookout_badeline_lookRight 13+#define A_lookout_badeline_lookLeft 14+#define A_lookout_badeline_looking 15+#define A_lookout_badeline_lookingUp 16+#define A_lookout_badeline_lookingUpRight 17+#define A_lookout_badeline_lookingRight 18+#define A_lookout_badeline_lookingDownRight 19+#define A_lookout_badeline_lookingDown 20+#define A_lookout_badeline_lookingDownLeft 21+#define A_lookout_badeline_lookingLeft 22+#define A_lookout_badeline_lookingUpLeft 23+#define A_lookout_nobackpack_idle 24+#define A_lookout_nobackpack_lookRight 25+#define A_lookout_nobackpack_lookLeft 26+#define A_lookout_nobackpack_looking 27+#define A_lookout_nobackpack_lookingUp 28+#define A_lookout_nobackpack_lookingUpRight 29+#define A_lookout_nobackpack_lookingRight 30+#define A_lookout_nobackpack_lookingDownRight 31+#define A_lookout_nobackpack_lookingDown 32+#define A_lookout_nobackpack_lookingDownLeft 33+#define A_lookout_nobackpack_lookingLeft 34+#define A_lookout_nobackpack_lookingUpLeft 35+#define SB_heartgem1 17+#define A_heartgem1_idle 0+#define A_heartgem1_spin 1+#define A_heartgem1_fastspin 2+#define SB_heartgem2 18+#define A_heartgem2_idle 0+#define A_heartgem2_spin 1+#define A_heartgem2_fastspin 2+#define SB_heartGemGhost 19+#define A_heartGemGhost_idle 0+#define A_heartGemGhost_spin 1+#define A_heartGemGhost_fastspin 2+#define SB_payphone 20+#define A_payphone_idle 0+#define A_payphone_pickUp 1+#define A_payphone_talkPhone 2+#define A_payphone_jumpBack 3+#define A_payphone_scare 4+#define A_payphone_transform 5+#define A_payphone_eat 6+#define A_payphone_monsterIdle 7+#define SB_glass 21+#define A_glass_idle 0+#define A_glass_break 1+#define A_glass_broken 2+#define SB_templeBlade 22+#define A_templeBlade_idle 0+#define A_templeBlade_spin 1+#define SB_door 23+#define A_door_idle 0+#define A_door_open 1+#define A_door_close 2+#define SB_oshiro 24+#define A_oshiro_idle 0+#define A_oshiro_side 1+#define A_oshiro_move 2+#define A_oshiro_appear 3+#define A_oshiro_sweeping 4+#define A_oshiro_putBroomAway 5+#define A_oshiro_fall 6+#define A_oshiro_recover 7+#define A_oshiro_idle_ground 8+#define SB_lockdoor_wood 25+#define A_lockdoor_wood_idle 0+#define A_lockdoor_wood_open 1+#define A_lockdoor_wood_burst 2+#define SB_key 26+#define A_key_idle 0+#define A_key_enter 1+#define SB_trapdoor 27+#define A_trapdoor_idle 0+#define A_trapdoor_open 1+#define A_trapdoor_open_partial 2+#define SB_metaldoor 28+#define A_metaldoor_idle 0+#define A_metaldoor_open 1+#define A_metaldoor_close 2+#define SB_ghost_door 29+#define A_ghost_door_idle 0+#define A_ghost_door_open 1+#define SB_clutterSwitch 30+#define A_clutterSwitch_idle 0+#define A_clutterSwitch_active 1+#define A_clutterSwitch_break 2+#define SB_clutterCabinet 31+#define A_clutterCabinet_idle 0+#define A_clutterCabinet_open 1+#define A_clutterCabinet_opened 2+#define A_clutterCabinet_close 3+#define SB_oshiro_boss 32+#define A_oshiro_boss_transformStart 0+#define A_oshiro_boss_transformCharge 1+#define A_oshiro_boss_transformFinish 2+#define A_oshiro_boss_transformBack 3+#define A_oshiro_boss_respawn 4+#define A_oshiro_boss_idle 5+#define A_oshiro_boss_charge 6+#define A_oshiro_boss_dash 7+#define A_oshiro_boss_hurt 8+#define SB_oshiro_boss_lightning 33+#define A_oshiro_boss_lightning_once 0+#define SB_cloud 34+#define A_cloud_idle 0+#define SB_cloudRemix 35+#define A_cloudRemix_idle 0+#define SB_booster 36+#define A_booster_loop 0+#define A_booster_inside 1+#define A_booster_spin 2+#define A_booster_pop 3+#define SB_cloudFragile 37+#define A_cloudFragile_idle 0+#define A_cloudFragile_fade 1+#define A_cloudFragile_spawn 2+#define SB_cloudFragileRemix 38+#define A_cloudFragileRemix_idle 0+#define A_cloudFragileRemix_fade 1+#define A_cloudFragileRemix_spawn 2+#define SB_snowball 39+#define A_snowball_spin 0+#define A_snowball_break 1+#define SB_flyFeather 40+#define A_flyFeather_loop 0+#define A_flyFeather_flash 1+#define SB_gondola 41+#define A_gondola_idle 0+#define A_gondola_pull 1+#define SB_boosterRed 42+#define A_boosterRed_appear 0+#define A_boosterRed_loop 1+#define A_boosterRed_inside 2+#define A_boosterRed_spin 3+#define A_boosterRed_pop 4+#define SB_dashSwitch_default 43+#define A_dashSwitch_default_idle 0+#define A_dashSwitch_default_pushed 1+#define A_dashSwitch_default_push 2+#define SB_lockdoor_temple_a 44+#define A_lockdoor_temple_a_idle 0+#define A_lockdoor_temple_a_open 1+#define A_lockdoor_temple_a_burst 2+#define SB_temple_portal_curtain 45+#define A_temple_portal_curtain_idle 0+#define A_temple_portal_curtain_fall 1+#define A_temple_portal_curtain_fallen 2+#define SB_dashSwitch_mirror 46+#define A_dashSwitch_mirror_idle 0+#define A_dashSwitch_mirror_pushed 1+#define A_dashSwitch_mirror_push 2+#define SB_seeker 47+#define A_seeker_idle 0+#define A_seeker_search 1+#define A_seeker_spot 2+#define A_seeker_spotted 3+#define A_seeker_windUp 4+#define A_seeker_attacking 5+#define A_seeker_takeHit 6+#define A_seeker_stunned 7+#define A_seeker_pulse 8+#define A_seeker_recover 9+#define A_seeker_skid 10+#define A_seeker_dazed 11+#define A_seeker_hatch 12+#define A_seeker_statue 13+#define A_seeker_flipMouth 14+#define A_seeker_flipEyes 15+#define SB_seekerShockWave 48+#define A_seekerShockWave_shockwave 0+#define SB_lockdoor_temple_b 49+#define A_lockdoor_temple_b_idle 0+#define A_lockdoor_temple_b_open 1+#define A_lockdoor_temple_b_burst 2+#define SB_temple_eyeball 50+#define A_temple_eyeball_idle 0+#define A_temple_eyeball_burst 1+#define SB_theo_crystal 51+#define A_theo_crystal_idle 0+#define A_theo_crystal_shatter 1+#define A_theo_crystal_shattered 2+#define SB_crushblock_face 52+#define A_crushblock_face_idle 0+#define A_crushblock_face_hurt 1+#define A_crushblock_face_hit 2+#define A_crushblock_face_left 3+#define A_crushblock_face_right 4+#define A_crushblock_face_up 5+#define A_crushblock_face_down 6+#define SB_giant_crushblock_face 53+#define A_giant_crushblock_face_idle 0+#define A_giant_crushblock_face_hurt 1+#define A_giant_crushblock_face_hit 2+#define A_giant_crushblock_face_right 3+#define SB_heartgem3 54+#define A_heartgem3_idle 0+#define A_heartgem3_spin 1+#define A_heartgem3_fastspin 2+#define SB_badeline 55+#define A_badeline_idle 0+#define A_badeline_idleA 1+#define A_badeline_idleB 2+#define A_badeline_idleC 3+#define A_badeline_lookUp 4+#define A_badeline_walk 5+#define A_badeline_push 6+#define A_badeline_runSlow 7+#define A_badeline_runFast 8+#define A_badeline_runStumble 9+#define A_badeline_dash 10+#define A_badeline_dreamDashIn 11+#define A_badeline_dreamDashLoop 12+#define A_badeline_dreamDashOut 13+#define A_badeline_slide 14+#define A_badeline_jumpSlow 15+#define A_badeline_jumpFast 16+#define A_badeline_fallSlow 17+#define A_badeline_fallFast 18+#define A_badeline_tired 19+#define A_badeline_wallslide 20+#define A_badeline_climbLookBackStart 21+#define A_badeline_climbLookBack 22+#define A_badeline_climbup 23+#define A_badeline_duck 24+#define A_badeline_edge 25+#define A_badeline_sleep 26+#define A_badeline_faint 27+#define A_badeline_fainted 28+#define A_badeline_flip 29+#define A_badeline_skid 30+#define A_badeline_dangling 31+#define A_badeline_spawn 32+#define A_badeline_laugh 33+#define A_badeline_angry 34+#define A_badeline_boost 35+#define A_badeline_pretendDead 36+#define A_badeline_spin 37+#define A_badeline_hug 38+#define SB_badeline_boss 56+#define A_badeline_boss_idle 0+#define A_badeline_boss_scaredIdle 1+#define A_badeline_boss_scaredTransition 2+#define A_badeline_boss_calm 3+#define A_badeline_boss_lookUp 4+#define A_badeline_boss_lookingUp 5+#define A_badeline_boss_attack1Begin 6+#define A_badeline_boss_attack1Loop 7+#define A_badeline_boss_attack1Recoil 8+#define A_badeline_boss_attack2Begin 9+#define A_badeline_boss_attack2Aim 10+#define A_badeline_boss_attack2Lock 11+#define A_badeline_boss_attack2Recoil 12+#define A_badeline_boss_getHit 13+#define A_badeline_boss_star 14+#define A_badeline_boss_recoverHit 15+#define SB_badeline_projectile 57+#define A_badeline_projectile_charge 0+#define A_badeline_projectile_loop 1+#define SB_badeline_beam 58+#define A_badeline_beam_charge 0+#define A_badeline_beam_lock 1+#define A_badeline_beam_shoot 2+#define SB_badeline_beam_start 59+#define A_badeline_beam_start_shoot 0+#define SB_player_level_up 60+#define A_player_level_up_levelUp 0+#define SB_fireball 61+#define A_fireball_hot 0+#define A_fireball_ice 1+#define A_fireball_shatter 2+#define SB_bumpBlockCenterFire 62+#define A_bumpBlockCenterFire_idle 0+#define SB_bumpBlockCenterIce 63+#define A_bumpBlockCenterIce_idle 0+#define SB_coreFlipSwitch 64+#define A_coreFlipSwitch_hot 0+#define A_coreFlipSwitch_hotLoop 1+#define A_coreFlipSwitch_hotOff 2+#define A_coreFlipSwitch_hotOffLoop 3+#define A_coreFlipSwitch_ice 4+#define A_coreFlipSwitch_iceLoop 5+#define A_coreFlipSwitch_iceOff 6+#define A_coreFlipSwitch_iceOffLoop 7+#define SB_player 65+#define A_player_idle_carry 0+#define A_player_runSlow_carry 1+#define A_player_jumpSlow_carry 2+#define A_player_fallSlow_carry 3+#define A_player_pickUp 4+#define A_player_throw 5+#define A_player_idle 6+#define A_player_idleA 7+#define A_player_idleB 8+#define A_player_idleC 9+#define A_player_lookUp 10+#define A_player_walk 11+#define A_player_push 12+#define A_player_runSlow 13+#define A_player_runFast 14+#define A_player_runStumble 15+#define A_player_runWind 16+#define A_player_dash 17+#define A_player_dreamDashIn 18+#define A_player_dreamDashLoop 19+#define A_player_dreamDashOut 20+#define A_player_slide 21+#define A_player_jumpSlow 22+#define A_player_jumpFast 23+#define A_player_fallSlow 24+#define A_player_fallFast 25+#define A_player_tired 26+#define A_player_tiredStill 27+#define A_player_wallslide 28+#define A_player_climbLookBackStart 29+#define A_player_climbLookBack 30+#define A_player_climbup 31+#define A_player_climbPush 32+#define A_player_climbPull 33+#define A_player_duck 34+#define A_player_fallPose 35+#define A_player_edge 36+#define A_player_edgeBack 37+#define A_player_faint 38+#define A_player_fainted 39+#define A_player_flip 40+#define A_player_skid 41+#define A_player_dangling 42+#define A_player_deadside 43+#define A_player_deadup 44+#define A_player_deaddown 45+#define A_player_swimIdle 46+#define A_player_swimUp 47+#define A_player_swimDown 48+#define A_player_startStarFly 49+#define A_player_starFly 50+#define A_player_bubble 51+#define A_player_fall 52+#define A_player_bigFall 53+#define A_player_bigFallRecover 54+#define A_player_sleep 55+#define A_player_bagdown 56+#define A_player_asleep 57+#define A_player_wakeUp 58+#define A_player_halfWakeUp 59+#define A_player_spin 60+#define A_player_shaking 61+#define A_player_hug 62+#define A_player_starMorph 63+#define A_player_starMorphIdle 64+#define A_player_carryTheoWalk 65+#define A_player_carryTheoCollapse 66+#define A_player_tentacle_grab 67+#define A_player_tentacle_grabbed 68+#define A_player_tentacle_pull 69+#define A_player_tentacle_dangling 70+#define A_player_sitDown 71+#define A_player_launch 72+#define A_player_launchRecover 73+#define SB_player_no_backpack 66+#define A_player_no_backpack_idle_carry 0+#define A_player_no_backpack_runSlow_carry 1+#define A_player_no_backpack_jumpSlow_carry 2+#define A_player_no_backpack_fallSlow_carry 3+#define A_player_no_backpack_pickUp 4+#define A_player_no_backpack_throw 5+#define A_player_no_backpack_idle 6+#define A_player_no_backpack_idleA 7+#define A_player_no_backpack_idleB 8+#define A_player_no_backpack_idleC 9+#define A_player_no_backpack_lookUp 10+#define A_player_no_backpack_walk 11+#define A_player_no_backpack_push 12+#define A_player_no_backpack_runSlow 13+#define A_player_no_backpack_runFast 14+#define A_player_no_backpack_runStumble 15+#define A_player_no_backpack_runWind 16+#define A_player_no_backpack_dash 17+#define A_player_no_backpack_dreamDashIn 18+#define A_player_no_backpack_dreamDashLoop 19+#define A_player_no_backpack_dreamDashOut 20+#define A_player_no_backpack_slide 21+#define A_player_no_backpack_jumpSlow 22+#define A_player_no_backpack_jumpFast 23+#define A_player_no_backpack_fallSlow 24+#define A_player_no_backpack_fallFast 25+#define A_player_no_backpack_tired 26+#define A_player_no_backpack_tiredStill 27+#define A_player_no_backpack_wallslide 28+#define A_player_no_backpack_climbLookBackStart 29+#define A_player_no_backpack_climbLookBack 30+#define A_player_no_backpack_climbup 31+#define A_player_no_backpack_climbPush 32+#define A_player_no_backpack_climbPull 33+#define A_player_no_backpack_duck 34+#define A_player_no_backpack_fallPose 35+#define A_player_no_backpack_edge 36+#define A_player_no_backpack_edgeBack 37+#define A_player_no_backpack_faint 38+#define A_player_no_backpack_fainted 39+#define A_player_no_backpack_flip 40+#define A_player_no_backpack_skid 41+#define A_player_no_backpack_dangling 42+#define A_player_no_backpack_deadside 43+#define A_player_no_backpack_deadup 44+#define A_player_no_backpack_deaddown 45+#define A_player_no_backpack_swimIdle 46+#define A_player_no_backpack_swimUp 47+#define A_player_no_backpack_swimDown 48+#define A_player_no_backpack_startStarFly 49+#define A_player_no_backpack_starFly 50+#define A_player_no_backpack_bubble 51+#define A_player_no_backpack_fall 52+#define A_player_no_backpack_bigFall 53+#define A_player_no_backpack_bigFallRecover 54+#define A_player_no_backpack_sleep 55+#define A_player_no_backpack_bagdown 56+#define A_player_no_backpack_asleep 57+#define A_player_no_backpack_wakeUp 58+#define A_player_no_backpack_halfWakeUp 59+#define A_player_no_backpack_spin 60+#define A_player_no_backpack_shaking 61+#define A_player_no_backpack_hug 62+#define A_player_no_backpack_starMorph 63+#define A_player_no_backpack_starMorphIdle 64+#define A_player_no_backpack_carryTheoWalk 65+#define A_player_no_backpack_carryTheoCollapse 66+#define A_player_no_backpack_tentacle_grab 67+#define A_player_no_backpack_tentacle_grabbed 68+#define A_player_no_backpack_tentacle_pull 69+#define A_player_no_backpack_tentacle_dangling 70+#define A_player_no_backpack_sitDown 71+#define A_player_no_backpack_launch 72+#define A_player_no_backpack_launchRecover 73+#define A_player_no_backpack_roll 74+#define A_player_no_backpack_rollGetUp 75+#define A_player_no_backpack_downed 76+#define SB_player_sweat 67+#define A_player_sweat_idle 0+#define A_player_sweat_climb 1+#define A_player_sweat_climbLoop 2+#define A_player_sweat_still 3+#define A_player_sweat_jump 4+#define A_player_sweat_danger 5+#define SB_gui_heartgem0 68+#define A_gui_heartgem0_idle 0+#define A_gui_heartgem0_spin 1+#define A_gui_heartgem0_fastspin 2+#define SB_gui_heartgem1 69+#define A_gui_heartgem1_idle 0+#define A_gui_heartgem1_spin 1+#define A_gui_heartgem1_fastspin 2+#define SB_gui_heartgem2 70+#define A_gui_heartgem2_idle 0+#define A_gui_heartgem2_spin 1+#define A_gui_heartgem2_fastspin 2+#define SB_portrait_madeline 71+#define A_portrait_madeline_idle_normal 0+#define A_portrait_madeline_idle_normal_blink 1+#define A_portrait_madeline_talk_normal 2+#define A_portrait_madeline_idle_peaceful 3+#define A_portrait_madeline_talk_peaceful 4+#define A_portrait_madeline_idle_angry 5+#define A_portrait_madeline_idle_angry_blink 6+#define A_portrait_madeline_talk_angry 7+#define A_portrait_madeline_idle_deadpan 8+#define A_portrait_madeline_idle_deadpan_blink 9+#define A_portrait_madeline_talk_deadpan 10+#define A_portrait_madeline_idle_sleep 11+#define A_portrait_madeline_idle_sad 12+#define A_portrait_madeline_idle_sad_blink 13+#define A_portrait_madeline_talk_sad 14+#define A_portrait_madeline_idle_sadder 15+#define A_portrait_madeline_idle_sadder_blink 16+#define A_portrait_madeline_talk_sadder 17+#define A_portrait_madeline_idle_upset 18+#define A_portrait_madeline_idle_upset_blink 19+#define A_portrait_madeline_talk_upset 20+#define A_portrait_madeline_idle_surprised 21+#define A_portrait_madeline_idle_surprised_blink 22+#define A_portrait_madeline_talk_surprised 23+#define A_portrait_madeline_idle_distracted 24+#define A_portrait_madeline_idle_distracted_blink1 25+#define A_portrait_madeline_idle_distracted_blink2 26+#define A_portrait_madeline_talk_distracted 27+#define A_portrait_madeline_idle_determined 28+#define A_portrait_madeline_idle_determined_blink 29+#define A_portrait_madeline_talk_determined 30+#define A_portrait_madeline_idle_determinedclosed 31+#define A_portrait_madeline_talk_determinedclosed 32+#define A_portrait_madeline_idle_panic 33+#define A_portrait_madeline_idle_panic_shake 34+#define A_portrait_madeline_talk_panic 35+#define A_portrait_madeline_idle_together 36+#define A_portrait_madeline_idle_together_blink 37+#define A_portrait_madeline_talk_together 38+#define A_portrait_madeline_begin_togetherZoom 39+#define A_portrait_madeline_idle_togetherZoom 40+#define A_portrait_madeline_idle_togetherZoom_blink 41+#define A_portrait_madeline_talk_togetherZoom 42+#define SB_portrait_madeline_phone 72+#define A_portrait_madeline_phone_idle_normal 0+#define A_portrait_madeline_phone_idle_normal_blink 1+#define A_portrait_madeline_phone_talk_normal 2+#define A_portrait_madeline_phone_idle_angry 3+#define A_portrait_madeline_phone_idle_angry_blink 4+#define A_portrait_madeline_phone_talk_angry 5+#define A_portrait_madeline_phone_idle_sad 6+#define A_portrait_madeline_phone_idle_sad_blink 7+#define A_portrait_madeline_phone_talk_sad 8+#define A_portrait_madeline_phone_idle_upset 9+#define A_portrait_madeline_phone_idle_upset_blink 10+#define A_portrait_madeline_phone_talk_upset 11+#define A_portrait_madeline_phone_idle_surprised 12+#define A_portrait_madeline_phone_idle_surprised_blink 13+#define A_portrait_madeline_phone_talk_surprised 14+#define A_portrait_madeline_phone_idle_distracted 15+#define A_portrait_madeline_phone_idle_distracted_blink1 16+#define A_portrait_madeline_phone_idle_distracted_blink2 17+#define A_portrait_madeline_phone_talk_distracted 18+#define SB_portrait_madeline_mirror 73+#define A_portrait_madeline_mirror_idle_normal 0+#define A_portrait_madeline_mirror_idle_normal_shine 1+#define A_portrait_madeline_mirror_idle_normal_blink 2+#define A_portrait_madeline_mirror_talk_normal 3+#define A_portrait_madeline_mirror_idle_angry 4+#define A_portrait_madeline_mirror_idle_angry_shine 5+#define A_portrait_madeline_mirror_idle_angry_blink 6+#define A_portrait_madeline_mirror_talk_angry 7+#define A_portrait_madeline_mirror_idle_deadpan 8+#define A_portrait_madeline_mirror_idle_deadpan_shine 9+#define A_portrait_madeline_mirror_idle_deadpan_blink 10+#define A_portrait_madeline_mirror_talk_deadpan 11+#define A_portrait_madeline_mirror_idle_sleep 12+#define A_portrait_madeline_mirror_idle_sad 13+#define A_portrait_madeline_mirror_idle_sad_shine 14+#define A_portrait_madeline_mirror_idle_sad_blink 15+#define A_portrait_madeline_mirror_talk_sad 16+#define A_portrait_madeline_mirror_idle_upset 17+#define A_portrait_madeline_mirror_idle_upset_shine 18+#define A_portrait_madeline_mirror_idle_upset_blink 19+#define A_portrait_madeline_mirror_talk_upset 20+#define A_portrait_madeline_mirror_idle_surprised 21+#define A_portrait_madeline_mirror_idle_surprised_shine 22+#define A_portrait_madeline_mirror_idle_surprised_blink 23+#define A_portrait_madeline_mirror_talk_surprised 24+#define A_portrait_madeline_mirror_idle_distracted 25+#define A_portrait_madeline_mirror_idle_distracted_shine 26+#define A_portrait_madeline_mirror_idle_distracted_blink1 27+#define A_portrait_madeline_mirror_idle_distracted_blink2 28+#define A_portrait_madeline_mirror_talk_distracted 29+#define A_portrait_madeline_mirror_idle_determined 30+#define A_portrait_madeline_mirror_idle_determined_shine 31+#define A_portrait_madeline_mirror_idle_determined_blink 32+#define A_portrait_madeline_mirror_talk_determined 33+#define A_portrait_madeline_mirror_idle_determinedclosed 34+#define A_portrait_madeline_mirror_talk_determinedclosed 35+#define A_portrait_madeline_mirror_idle_panic 36+#define A_portrait_madeline_mirror_idle_panic_shine 37+#define A_portrait_madeline_mirror_idle_panic_shake 38+#define A_portrait_madeline_mirror_talk_panic 39+#define SB_portrait_granny 74+#define A_portrait_granny_idle_normal 0+#define A_portrait_granny_idle_normal_blink1 1+#define A_portrait_granny_idle_normal_blink2 2+#define A_portrait_granny_talk_normal 3+#define A_portrait_granny_idle_mock 4+#define A_portrait_granny_idle_mock_blink 5+#define A_portrait_granny_talk_mock 6+#define A_portrait_granny_idle_creepA 7+#define A_portrait_granny_talk_creepA 8+#define A_portrait_granny_idle_creepB 9+#define A_portrait_granny_talk_creepB 10+#define A_portrait_granny_idle_laugh 11+#define A_portrait_granny_talk_laugh 12+#define SB_portrait_theo 75+#define A_portrait_theo_idle_normal 0+#define A_portrait_theo_idle_normal_blink1 1+#define A_portrait_theo_idle_normal_blink2 2+#define A_portrait_theo_talk_normal 3+#define A_portrait_theo_idle_thinking 4+#define A_portrait_theo_idle_thinking_blink 5+#define A_portrait_theo_talk_thinking 6+#define A_portrait_theo_idle_excited 7+#define A_portrait_theo_idle_excited_blink 8+#define A_portrait_theo_talk_excited 9+#define A_portrait_theo_idle_worried 10+#define A_portrait_theo_idle_worried_blink 11+#define A_portrait_theo_talk_worried 12+#define A_portrait_theo_idle_wtf 13+#define A_portrait_theo_idle_wtf_blink 14+#define A_portrait_theo_talk_wtf 15+#define A_portrait_theo_idle_yolo 16+#define A_portrait_theo_talk_yolo 17+#define A_portrait_theo_idle_nailedit 18+#define A_portrait_theo_talk_nailedit 19+#define A_portrait_theo_idle_serious 20+#define A_portrait_theo_idle_serious_blink 21+#define A_portrait_theo_talk_serious 22+#define SB_portrait_webcam_theo 76+#define A_portrait_webcam_theo_idle_normal 0+#define A_portrait_webcam_theo_idle_normal_blink1 1+#define A_portrait_webcam_theo_idle_normal_blink2 2+#define A_portrait_webcam_theo_talk_normal 3+#define A_portrait_webcam_theo_idle_thinking 4+#define A_portrait_webcam_theo_idle_thinking_blink 5+#define A_portrait_webcam_theo_talk_thinking 6+#define A_portrait_webcam_theo_idle_excited 7+#define A_portrait_webcam_theo_idle_excited_blink 8+#define A_portrait_webcam_theo_talk_excited 9+#define A_portrait_webcam_theo_idle_worried 10+#define A_portrait_webcam_theo_idle_worried_blink 11+#define A_portrait_webcam_theo_talk_worried 12+#define A_portrait_webcam_theo_idle_wtf 13+#define A_portrait_webcam_theo_idle_wtf_blink 14+#define A_portrait_webcam_theo_talk_wtf 15+#define A_portrait_webcam_theo_idle_yolo 16+#define A_portrait_webcam_theo_talk_yolo 17+#define A_portrait_webcam_theo_idle_nailedit 18+#define A_portrait_webcam_theo_talk_nailedit 19+#define A_portrait_webcam_theo_idle_serious 20+#define A_portrait_webcam_theo_idle_serious_blink 21+#define A_portrait_webcam_theo_talk_serious 22+#define SB_portrait_theo_mirror 77+#define A_portrait_theo_mirror_idle_normal 0+#define A_portrait_theo_mirror_idle_normal_shine 1+#define A_portrait_theo_mirror_idle_normal_blink1 2+#define A_portrait_theo_mirror_idle_normal_blink2 3+#define A_portrait_theo_mirror_talk_normal 4+#define A_portrait_theo_mirror_idle_thinking 5+#define A_portrait_theo_mirror_idle_thinking_shine 6+#define A_portrait_theo_mirror_idle_thinking_blink 7+#define A_portrait_theo_mirror_talk_thinking 8+#define A_portrait_theo_mirror_idle_excited 9+#define A_portrait_theo_mirror_idle_excited_shine 10+#define A_portrait_theo_mirror_idle_excited_blink 11+#define A_portrait_theo_mirror_talk_excited 12+#define A_portrait_theo_mirror_idle_worried 13+#define A_portrait_theo_mirror_idle_worried_shine 14+#define A_portrait_theo_mirror_idle_worried_blink 15+#define A_portrait_theo_mirror_talk_worried 16+#define A_portrait_theo_mirror_idle_wtf 17+#define A_portrait_theo_mirror_idle_wtf_shine 18+#define A_portrait_theo_mirror_idle_wtf_blink 19+#define A_portrait_theo_mirror_talk_wtf 20+#define A_portrait_theo_mirror_idle_serious 21+#define A_portrait_theo_mirror_idle_serious_shine 22+#define A_portrait_theo_mirror_idle_serious_blink 23+#define A_portrait_theo_mirror_talk_serious 24+#define SB_portrait_badeline 78+#define A_portrait_badeline_idle_normal 0+#define A_portrait_badeline_idle_normal_blink 1+#define A_portrait_badeline_talk_normal 2+#define A_portrait_badeline_idle_upset 3+#define A_portrait_badeline_idle_upset_blink 4+#define A_portrait_badeline_talk_upset 5+#define A_portrait_badeline_idle_scoff 6+#define A_portrait_badeline_idle_scoff_still 7+#define A_portrait_badeline_idle_scoff_blink 8+#define A_portrait_badeline_talk_scoff 9+#define A_portrait_badeline_begin_serious 10+#define A_portrait_badeline_idle_serious 11+#define A_portrait_badeline_idle_serious_blink 12+#define A_portrait_badeline_talk_serious 13+#define A_portrait_badeline_begin_serious_alt 14+#define A_portrait_badeline_idle_serious_alt 15+#define A_portrait_badeline_idle_serious_alt_blink 16+#define A_portrait_badeline_talk_serious_alt 17+#define A_portrait_badeline_idle_angry 18+#define A_portrait_badeline_idle_angry_blink 19+#define A_portrait_badeline_talk_angry 20+#define A_portrait_badeline_idle_angryAlt 21+#define A_portrait_badeline_idle_angryAlt_blink 22+#define A_portrait_badeline_talk_angryAlt 23+#define A_portrait_badeline_idle_yell 24+#define A_portrait_badeline_idle_yell_blink 25+#define A_portrait_badeline_talk_yell 26+#define A_portrait_badeline_idle_worried 27+#define A_portrait_badeline_idle_worried_blink 28+#define A_portrait_badeline_talk_worried 29+#define A_portrait_badeline_idle_concerned 30+#define A_portrait_badeline_idle_concerned_blink 31+#define A_portrait_badeline_talk_concerned 32+#define A_portrait_badeline_idle_worriedAlt 33+#define A_portrait_badeline_idle_worriedAlt_blink 34+#define A_portrait_badeline_talk_worriedAlt 35+#define A_portrait_badeline_idle_sad 36+#define A_portrait_badeline_idle_sad_shake 37+#define A_portrait_badeline_talk_sad 38+#define A_portrait_badeline_idle_freakA 39+#define A_portrait_badeline_idle_freakA_blink 40+#define A_portrait_badeline_idle_freakA_giggle 41+#define A_portrait_badeline_talk_freakA 42+#define A_portrait_badeline_begin_freakB 43+#define A_portrait_badeline_idle_freakB 44+#define A_portrait_badeline_idle_freakB_blink 45+#define A_portrait_badeline_idle_freakB_giggle 46+#define A_portrait_badeline_talk_freakB 47+#define A_portrait_badeline_begin_freakBAlt 48+#define A_portrait_badeline_idle_freakBAlt 49+#define A_portrait_badeline_idle_freakBAlt_blink 50+#define A_portrait_badeline_idle_freakBAlt_stop 51+#define A_portrait_badeline_talk_freakBAlt 52+#define A_portrait_badeline_begin_freakC 53+#define A_portrait_badeline_idle_freakC 54+#define A_portrait_badeline_idle_freakC_blink 55+#define A_portrait_badeline_idle_freakC_shake 56+#define A_portrait_badeline_talk_freakC 57+#define A_portrait_badeline_idle_freakC_cont 58+#define A_portrait_badeline_idle_freakC_cont_blink 59+#define A_portrait_badeline_idle_freakC_cont_shake 60+#define A_portrait_badeline_talk_freakC_cont 61+#define A_portrait_badeline_begin_freakCAlt 62+#define A_portrait_badeline_idle_freakCAlt 63+#define A_portrait_badeline_idle_freakCAlt_blink 64+#define A_portrait_badeline_idle_freakCAlt_stop 65+#define A_portrait_badeline_talk_freakCAlt 66+#define A_portrait_badeline_begin_sigh 67+#define A_portrait_badeline_idle_sigh 68+#define A_portrait_badeline_idle_sigh_blink 69+#define A_portrait_badeline_talk_sigh 70+#define A_portrait_badeline_idle_simple_sigh 71+#define A_portrait_badeline_idle_simple_sigh_blink 72+#define A_portrait_badeline_talk_simple_sigh 73+#define SB_portrait_ex_phone 79+#define A_portrait_ex_phone_idle_normal 0+#define A_portrait_ex_phone_talk_normal 1+#define SB_portrait_mom_phone 80+#define A_portrait_mom_phone_idle_normal 0+#define A_portrait_mom_phone_idle_normal_blink 1+#define A_portrait_mom_phone_talk_normal 2+#define A_portrait_mom_phone_idle_concerned 3+#define A_portrait_mom_phone_idle_concerned_blink 4+#define A_portrait_mom_phone_talk_concerned 5+#define SB_portrait_oshiro 81+#define A_portrait_oshiro_idle_normal 0+#define A_portrait_oshiro_idle_normal_blink 1+#define A_portrait_oshiro_idle_normal_hands 2+#define A_portrait_oshiro_talk_normal 3+#define A_portrait_oshiro_idle_worried 4+#define A_portrait_oshiro_idle_worried_blink 5+#define A_portrait_oshiro_talk_worried 6+#define A_portrait_oshiro_idle_nervous 7+#define A_portrait_oshiro_idle_nervous_twitch 8+#define A_portrait_oshiro_talk_nervous 9+#define A_portrait_oshiro_idle_drama_still 10+#define A_portrait_oshiro_idle_drama 11+#define A_portrait_oshiro_talk_drama 12+#define A_portrait_oshiro_idle_lostcontrol 13+#define A_portrait_oshiro_idle_lostcontrol_shake 14+#define A_portrait_oshiro_talk_lostcontrol 15+#define A_portrait_oshiro_idle_sidehappy 16+#define A_portrait_oshiro_idle_sidehappy_blink 17+#define A_portrait_oshiro_talk_sidehappy 18+#define A_portrait_oshiro_idle_sideworried 19+#define A_portrait_oshiro_idle_sideworried_blink 20+#define A_portrait_oshiro_idle_sideworried2 21+#define A_portrait_oshiro_talk_sideworried 22+#define A_portrait_oshiro_idle_serious 23+#define A_portrait_oshiro_idle_serious_blink 24+#define A_portrait_oshiro_talk_serious 25+#define A_portrait_oshiro_idle_sidesuspicious 26+#define A_portrait_oshiro_idle_sidesuspicious_blink 27+#define A_portrait_oshiro_talk_sidesuspicious 28++#define ET_player 0+#define ET_introCar 1+#define ET_lamp 2+#define ET_wire 3+#define ET_introCrusher 4+#define ET_jumpThru 5+#define ET_flutterbird 6+#define ET_bird 7+#define ET_npc 8+#define ET_bridge 9+#define ET_hahaha 10+#define ET_spikesUp 11+#define ET_spikesLeft 12+#define ET_goldenBerry 13+#define ET_zipMover 14+#define ET_spikesRight 15+#define ET_crumbleBlock 16+#define ET_refill 17+#define ET_spring 18+#define ET_strawberry 19+#define ET_spikesDown 20+#define ET_lightbeam 21+#define ET_cassette 22+#define ET_cassetteBlock 23+#define ET_fallingBlock 24+#define ET_fakeWall 25+#define ET_dashBlock 26+#define ET_checkpoint 27+#define ET_bonfire 28+#define ET_coverupWall 29+#define ET_memorial 30+#define ET_memorialTextController 31+#define ET_birdForsakenCityGem 32+#define ET_towerviewer 33+#define ET_blackGem 34+#define ET_touchSwitch 35+#define ET_switchGate 36+#define ET_dreamBlock 37+#define ET_hanginglamp 38+#define ET_floatingDebris 39+#define ET_foregroundDebris 40+#define ET_darkChaser 41+#define ET_invisibleBarrier 42+#define ET_exitBlock 43+#define ET_payphone 44+#define ET_dreammirror 45+#define ET_rotateSpinner 46+#define ET_door 47+#define ET_redBlocks 48+#define ET_yellowBlocks 49+#define ET_resortLantern 50+#define ET_greenBlocks 51+#define ET_spinner 52+#define ET_cobweb 53+#define ET_trackSpinner 54+#define ET_blockField 55+#define ET_resortmirror 56+#define ET_waterfall 57+#define ET_lockBlock 58+#define ET_sinkingPlatform 59+#define ET_key 60+#define ET_triggerSpikesLeft 61+#define ET_triggerSpikesRight 62+#define ET_triggerSpikesUp 63+#define ET_movingPlatform 64+#define ET_trapdoor 65+#define ET_water 66+#define ET_clutterDoor 67+#define ET_oshirodoor 68+#define ET_colorSwitch 69+#define ET_clutterCabinet 70+#define ET_picoconsole 71+#define ET_clothesline 72+#define ET_triggerSpikesDown 73+#define ET_friendlyGhost 74+#define ET_resortRoofEnding 75+#define ET_killbox 76+#define ET_cloud 77+#define ET_booster 78+#define ET_cliffside_flag 79+#define ET_moveBlock 80+#define ET_cliffflag 81+#define ET_ridgeGate 82+#define ET_whiteblock 83+#define ET_gondola 84+#define ET_templeGate 85+#define ET_dashSwitchH 86+#define ET_torch 87+#define ET_swapBlock 88+#define ET_templeMirror 89+#define ET_dashSwitchV 90+#define ET_templeMirrorPortal 91+#define ET_seeker 92+#define ET_templeCrackedBlock 93+#define ET_seekerStatue 94+#define ET_seekerBarrier 95+#define ET_conditionBlock 96+#define ET_theoCrystalPedestal 97+#define ET_theoCrystal 98+#define ET_templeEye 99+#define ET_templeBigEyeball 100+#define ET_playerSeeker 101+#define ET_wallSpringRight 102+#define ET_crushBlock 103+#define ET_bigWaterfall 104+#define ET_infiniteStar 105+#define ET_reflectionHeartStatue 106+#define ET_bigSpinner 107+#define ET_badelineBoost 108+#define ET_tentacles 109+#define ET_finalBoss 110+#define ET_finalBossFallingBlock 111+#define ET_finalBossMovingBlock 112+#define ET_plateau 113+#define ET_starJumpBlock 114+#define ET_SummitBackgroundManager 115+#define ET_wallSpringLeft 116+#define ET_summitgem 117+#define ET_bridgeFixed 118+#define ET_summitcheckpoint 119+#define ET_summitGemManager 120+#define ET_summitcloud 121+#define ET_heartGemDoor 122+#define ET_wallBooster 123+#define ET_fireBall 124+#define ET_bounceBlock 125+#define ET_iceBlock 126+#define ET_coreModeToggle 127+#define ET_fireBarrier 128+#define ET_risingLava 129+#define ET_sandwichLava 130+#define ET_coreMessage 131+#define ET_COUNT 132+#define TT_cameraOffsetTrigger 0+#define TT_cameraTargetTrigger 1+#define TT_changeRespawnTrigger 2+#define TT_eventTrigger 3+#define TT_goldenBerryCollectTrigger 4+#define TT_respawnTargetTrigger 5+#define TT_interactTrigger 6+#define TT_bloomFadeTrigger 7+#define TT_lightFadeTrigger 8+#define TT_oshiroTrigger 9+#define TT_windTrigger 10+#define TT_windAttackTrigger 11+#define TT_minitextboxTrigger 12+#define TT_checkpointBlockerTrigger 13+#define TT_lookoutBlocker 14+#define TT_creditsTrigger 15+#define TT_noRefillTrigger 16+#define TT_cameraAdvanceTargetTrigger 17+#define TT_COUNT 18++#define EA_player_width 0+#define EK_player_width 'i'+#define EA_player__size 2+#define EA_introCar__size 0+#define EA_lamp_broken 0+#define EK_lamp_broken 'b'+#define EA_lamp__size 2+#define EA_wire_above 0+#define EK_wire_above 'b'+#define EA_wire__size 2+#define EA_introCrusher_width 0+#define EK_introCrusher_width 'i'+#define EA_introCrusher_height 2+#define EK_introCrusher_height 'i'+#define EA_introCrusher__size 4+#define EA_jumpThru_width 0+#define EK_jumpThru_width 'i'+#define EA_jumpThru_texture 2+#define EK_jumpThru_texture 's'+#define EA_jumpThru_surfaceIndex 4+#define EK_jumpThru_surfaceIndex 'i'+#define EA_jumpThru__size 6+#define EA_flutterbird__size 0+#define EA_bird_mode 0+#define EK_bird_mode 's'+#define EA_bird__size 2+#define EA_npc_npc 0+#define EK_npc_npc 's'+#define EA_npc__size 2+#define EA_bridge_width 0+#define EK_bridge_width 'i'+#define EA_bridge__size 2+#define EA_hahaha_ifset 0+#define EK_hahaha_ifset 's'+#define EA_hahaha_triggerLaughSfx 2+#define EK_hahaha_triggerLaughSfx 'b'+#define EA_hahaha__size 4+#define EA_spikesUp_width 0+#define EK_spikesUp_width 'i'+#define EA_spikesUp_type 2+#define EK_spikesUp_type 's'+#define EA_spikesUp__size 4+#define EA_spikesLeft_height 0+#define EK_spikesLeft_height 'i'+#define EA_spikesLeft_type 2+#define EK_spikesLeft_type 's'+#define EA_spikesLeft__size 4+#define EA_goldenBerry__size 0+#define EA_zipMover_width 0+#define EK_zipMover_width 'i'+#define EA_zipMover_height 2+#define EK_zipMover_height 'i'+#define EA_zipMover_theme 4+#define EK_zipMover_theme 's'+#define EA_zipMover__size 6+#define EA_spikesRight_height 0+#define EK_spikesRight_height 'i'+#define EA_spikesRight_type 2+#define EK_spikesRight_type 's'+#define EA_spikesRight__size 4+#define EA_crumbleBlock_width 0+#define EK_crumbleBlock_width 'i'+#define EA_crumbleBlock__size 2+#define EA_refill_twoDash 0+#define EK_refill_twoDash 'b'+#define EA_refill_oneUse 1+#define EK_refill_oneUse 'b'+#define EA_refill__size 2+#define EA_spring_playerCanUse 0+#define EK_spring_playerCanUse 'b'+#define EA_spring__size 2+#define EA_strawberry_winged 0+#define EK_strawberry_winged 'b'+#define EA_strawberry_checkpointID 2+#define EK_strawberry_checkpointID 'i'+#define EA_strawberry_order 4+#define EK_strawberry_order 'i'+#define EA_strawberry__size 6+#define EA_spikesDown_width 0+#define EK_spikesDown_width 'i'+#define EA_spikesDown_type 2+#define EK_spikesDown_type 's'+#define EA_spikesDown__size 4+#define EA_lightbeam_width 0+#define EK_lightbeam_width 'i'+#define EA_lightbeam_height 2+#define EK_lightbeam_height 'i'+#define EA_lightbeam_rotation 4+#define EK_lightbeam_rotation 'i'+#define EA_lightbeam_flag 6+#define EK_lightbeam_flag 's'+#define EA_lightbeam__size 8+#define EA_cassette__size 0+#define EA_cassetteBlock_width 0+#define EK_cassetteBlock_width 'i'+#define EA_cassetteBlock_height 2+#define EK_cassetteBlock_height 'i'+#define EA_cassetteBlock_index 4+#define EK_cassetteBlock_index 'i'+#define EA_cassetteBlock_finishedState 6+#define EK_cassetteBlock_finishedState 'b'+#define EA_cassetteBlock__size 8+#define EA_fallingBlock_width 0+#define EK_fallingBlock_width 'i'+#define EA_fallingBlock_height 2+#define EK_fallingBlock_height 'i'+#define EA_fallingBlock_tiletype 4+#define EK_fallingBlock_tiletype 's'+#define EA_fallingBlock_behind 6+#define EK_fallingBlock_behind 'b'+#define EA_fallingBlock_climbFall 7+#define EK_fallingBlock_climbFall 'b'+#define EA_fallingBlock__size 8+#define EA_fakeWall_width 0+#define EK_fakeWall_width 'i'+#define EA_fakeWall_height 2+#define EK_fakeWall_height 'i'+#define EA_fakeWall_tiletype 4+#define EK_fakeWall_tiletype 's'+#define EA_fakeWall_playTransitionReveal 6+#define EK_fakeWall_playTransitionReveal 'b'+#define EA_fakeWall__size 8+#define EA_dashBlock_width 0+#define EK_dashBlock_width 'i'+#define EA_dashBlock_height 2+#define EK_dashBlock_height 'i'+#define EA_dashBlock_permanent 4+#define EK_dashBlock_permanent 'b'+#define EA_dashBlock_tiletype 6+#define EK_dashBlock_tiletype 's'+#define EA_dashBlock_blendin 8+#define EK_dashBlock_blendin 'b'+#define EA_dashBlock_canDash 9+#define EK_dashBlock_canDash 'b'+#define EA_dashBlock__size 10+#define EA_checkpoint_bg 0+#define EK_checkpoint_bg 's'+#define EA_checkpoint__size 2+#define EA_bonfire_mode 0+#define EK_bonfire_mode 's'+#define EA_bonfire__size 2+#define EA_coverupWall_width 0+#define EK_coverupWall_width 'i'+#define EA_coverupWall_height 2+#define EK_coverupWall_height 'i'+#define EA_coverupWall_tiletype 4+#define EK_coverupWall_tiletype 'i'+#define EA_coverupWall__size 6+#define EA_memorial_dreaming 0+#define EK_memorial_dreaming 'b'+#define EA_memorial__size 2+#define EA_memorialTextController__size 0+#define EA_birdForsakenCityGem__size 0+#define EA_towerviewer_summit 0+#define EK_towerviewer_summit 'b'+#define EA_towerviewer_onlyY 1+#define EK_towerviewer_onlyY 'b'+#define EA_towerviewer__size 2+#define EA_blackGem_removeCameraTriggers 0+#define EK_blackGem_removeCameraTriggers 'b'+#define EA_blackGem_fake 1+#define EK_blackGem_fake 'b'+#define EA_blackGem__size 2+#define EA_touchSwitch__size 0+#define EA_switchGate_width 0+#define EK_switchGate_width 'i'+#define EA_switchGate_height 2+#define EK_switchGate_height 'i'+#define EA_switchGate_persistent 4+#define EK_switchGate_persistent 'b'+#define EA_switchGate_sprite 6+#define EK_switchGate_sprite 's'+#define EA_switchGate__size 8+#define EA_dreamBlock_width 0+#define EK_dreamBlock_width 'i'+#define EA_dreamBlock_height 2+#define EK_dreamBlock_height 'i'+#define EA_dreamBlock_fastMoving 4+#define EK_dreamBlock_fastMoving 'b'+#define EA_dreamBlock_oneUse 5+#define EK_dreamBlock_oneUse 'b'+#define EA_dreamBlock_below 6+#define EK_dreamBlock_below 'b'+#define EA_dreamBlock__size 8+#define EA_hanginglamp_height 0+#define EK_hanginglamp_height 'i'+#define EA_hanginglamp__size 2+#define EA_floatingDebris__size 0+#define EA_foregroundDebris__size 0+#define EA_darkChaser__size 0+#define EA_invisibleBarrier_width 0+#define EK_invisibleBarrier_width 'i'+#define EA_invisibleBarrier_height 2+#define EK_invisibleBarrier_height 'i'+#define EA_invisibleBarrier__size 4+#define EA_exitBlock_width 0+#define EK_exitBlock_width 'i'+#define EA_exitBlock_height 2+#define EK_exitBlock_height 'i'+#define EA_exitBlock_tileType 4+#define EK_exitBlock_tileType 's'+#define EA_exitBlock__size 6+#define EA_payphone__size 0+#define EA_dreammirror__size 0+#define EA_rotateSpinner_clockwise 0+#define EK_rotateSpinner_clockwise 'b'+#define EA_rotateSpinner__size 2+#define EA_door_type 0+#define EK_door_type 's'+#define EA_door__size 2+#define EA_redBlocks_width 0+#define EK_redBlocks_width 'i'+#define EA_redBlocks_height 2+#define EK_redBlocks_height 'i'+#define EA_redBlocks_inverted 4+#define EK_redBlocks_inverted 'b'+#define EA_redBlocks__size 6+#define EA_yellowBlocks_width 0+#define EK_yellowBlocks_width 'i'+#define EA_yellowBlocks_height 2+#define EK_yellowBlocks_height 'i'+#define EA_yellowBlocks_inverted 4+#define EK_yellowBlocks_inverted 'b'+#define EA_yellowBlocks__size 6+#define EA_resortLantern__size 0+#define EA_greenBlocks_width 0+#define EK_greenBlocks_width 'i'+#define EA_greenBlocks_height 2+#define EK_greenBlocks_height 'i'+#define EA_greenBlocks_inverted 4+#define EK_greenBlocks_inverted 'b'+#define EA_greenBlocks__size 6+#define EA_spinner_attachToSolid 0+#define EK_spinner_attachToSolid 'b'+#define EA_spinner__size 2+#define EA_cobweb__size 0+#define EA_trackSpinner_startCenter 0+#define EK_trackSpinner_startCenter 'b'+#define EA_trackSpinner_speed 2+#define EK_trackSpinner_speed 's'+#define EA_trackSpinner__size 4+#define EA_blockField_width 0+#define EK_blockField_width 'i'+#define EA_blockField_height 2+#define EK_blockField_height 'i'+#define EA_blockField__size 4+#define EA_resortmirror__size 0+#define EA_waterfall__size 0+#define EA_lockBlock_stepMusicProgress 0+#define EK_lockBlock_stepMusicProgress 'b'+#define EA_lockBlock_sprite 2+#define EK_lockBlock_sprite 's'+#define EA_lockBlock__size 4+#define EA_sinkingPlatform_width 0+#define EK_sinkingPlatform_width 'i'+#define EA_sinkingPlatform__size 2+#define EA_key__size 0+#define EA_triggerSpikesLeft_height 0+#define EK_triggerSpikesLeft_height 'i'+#define EA_triggerSpikesLeft__size 2+#define EA_triggerSpikesRight_height 0+#define EK_triggerSpikesRight_height 'i'+#define EA_triggerSpikesRight__size 2+#define EA_triggerSpikesUp_width 0+#define EK_triggerSpikesUp_width 'i'+#define EA_triggerSpikesUp__size 2+#define EA_movingPlatform_width 0+#define EK_movingPlatform_width 'i'+#define EA_movingPlatform__size 2+#define EA_trapdoor__size 0+#define EA_water_width 0+#define EK_water_width 'i'+#define EA_water_height 2+#define EK_water_height 'i'+#define EA_water_steamy 4+#define EK_water_steamy 'b'+#define EA_water_hasBottom 5+#define EK_water_hasBottom 'b'+#define EA_water__size 6+#define EA_clutterDoor_width 0+#define EK_clutterDoor_width 'i'+#define EA_clutterDoor_height 2+#define EK_clutterDoor_height 'i'+#define EA_clutterDoor_type 4+#define EK_clutterDoor_type 's'+#define EA_clutterDoor__size 6+#define EA_oshirodoor__size 0+#define EA_colorSwitch_type 0+#define EK_colorSwitch_type 's'+#define EA_colorSwitch__size 2+#define EA_clutterCabinet__size 0+#define EA_picoconsole__size 0+#define EA_clothesline__size 0+#define EA_triggerSpikesDown_width 0+#define EK_triggerSpikesDown_width 'i'+#define EA_triggerSpikesDown__size 2+#define EA_friendlyGhost__size 0+#define EA_resortRoofEnding_width 0+#define EK_resortRoofEnding_width 'i'+#define EA_resortRoofEnding__size 2+#define EA_killbox_width 0+#define EK_killbox_width 'i'+#define EA_killbox__size 2+#define EA_cloud_fragile 0+#define EK_cloud_fragile 'b'+#define EA_cloud__size 2+#define EA_booster_red 0+#define EK_booster_red 'b'+#define EA_booster_ch9_hub_booster 1+#define EK_booster_ch9_hub_booster 'b'+#define EA_booster__size 2+#define EA_cliffside_flag_index 0+#define EK_cliffside_flag_index 'i'+#define EA_cliffside_flag__size 2+#define EA_moveBlock_width 0+#define EK_moveBlock_width 'i'+#define EA_moveBlock_height 2+#define EK_moveBlock_height 'i'+#define EA_moveBlock_direction 4+#define EK_moveBlock_direction 's'+#define EA_moveBlock_canSteer 6+#define EK_moveBlock_canSteer 'b'+#define EA_moveBlock_fast 7+#define EK_moveBlock_fast 'b'+#define EA_moveBlock__size 8+#define EA_cliffflag__size 0+#define EA_ridgeGate_width 0+#define EK_ridgeGate_width 'i'+#define EA_ridgeGate_height 2+#define EK_ridgeGate_height 'i'+#define EA_ridgeGate_strawberries 4+#define EK_ridgeGate_strawberries 's'+#define EA_ridgeGate_keys 6+#define EK_ridgeGate_keys 's'+#define EA_ridgeGate__size 8+#define EA_whiteblock__size 0+#define EA_gondola_active 0+#define EK_gondola_active 'b'+#define EA_gondola__size 2+#define EA_templeGate_height 0+#define EK_templeGate_height 'i'+#define EA_templeGate_type 2+#define EK_templeGate_type 's'+#define EA_templeGate_sprite 4+#define EK_templeGate_sprite 's'+#define EA_templeGate__size 6+#define EA_dashSwitchH_leftSide 0+#define EK_dashSwitchH_leftSide 'b'+#define EA_dashSwitchH_persistent 1+#define EK_dashSwitchH_persistent 'b'+#define EA_dashSwitchH_sprite 2+#define EK_dashSwitchH_sprite 's'+#define EA_dashSwitchH_allGates 4+#define EK_dashSwitchH_allGates 'b'+#define EA_dashSwitchH__size 6+#define EA_torch_startLit 0+#define EK_torch_startLit 'b'+#define EA_torch__size 2+#define EA_swapBlock_width 0+#define EK_swapBlock_width 'i'+#define EA_swapBlock_height 2+#define EK_swapBlock_height 'i'+#define EA_swapBlock_theme 4+#define EK_swapBlock_theme 's'+#define EA_swapBlock__size 6+#define EA_templeMirror_width 0+#define EK_templeMirror_width 'i'+#define EA_templeMirror_height 2+#define EK_templeMirror_height 'i'+#define EA_templeMirror_reflectX 4+#define EK_templeMirror_reflectX 'i'+#define EA_templeMirror_reflectY 6+#define EK_templeMirror_reflectY 'i'+#define EA_templeMirror__size 8+#define EA_dashSwitchV_ceiling 0+#define EK_dashSwitchV_ceiling 'b'+#define EA_dashSwitchV_persistent 1+#define EK_dashSwitchV_persistent 'b'+#define EA_dashSwitchV_sprite 2+#define EK_dashSwitchV_sprite 's'+#define EA_dashSwitchV_allGates 4+#define EK_dashSwitchV_allGates 'b'+#define EA_dashSwitchV__size 6+#define EA_templeMirrorPortal__size 0+#define EA_seeker__size 0+#define EA_templeCrackedBlock_width 0+#define EK_templeCrackedBlock_width 'i'+#define EA_templeCrackedBlock_height 2+#define EK_templeCrackedBlock_height 'i'+#define EA_templeCrackedBlock_persistent 4+#define EK_templeCrackedBlock_persistent 'b'+#define EA_templeCrackedBlock__size 6+#define EA_seekerStatue_hatch 0+#define EK_seekerStatue_hatch 's'+#define EA_seekerStatue__size 2+#define EA_seekerBarrier_width 0+#define EK_seekerBarrier_width 'i'+#define EA_seekerBarrier_height 2+#define EK_seekerBarrier_height 'i'+#define EA_seekerBarrier__size 4+#define EA_conditionBlock_width 0+#define EK_conditionBlock_width 'i'+#define EA_conditionBlock_height 2+#define EK_conditionBlock_height 'i'+#define EA_conditionBlock_tileType 4+#define EK_conditionBlock_tileType 's'+#define EA_conditionBlock_condition 6+#define EK_conditionBlock_condition 's'+#define EA_conditionBlock_conditionID 8+#define EK_conditionBlock_conditionID 's'+#define EA_conditionBlock__size 10+#define EA_theoCrystalPedestal__size 0+#define EA_theoCrystal__size 0+#define EA_templeEye__size 0+#define EA_templeBigEyeball__size 0+#define EA_playerSeeker__size 0+#define EA_wallSpringRight_playerCanUse 0+#define EK_wallSpringRight_playerCanUse 'b'+#define EA_wallSpringRight__size 2+#define EA_crushBlock_width 0+#define EK_crushBlock_width 'i'+#define EA_crushBlock_height 2+#define EK_crushBlock_height 'i'+#define EA_crushBlock_axes 4+#define EK_crushBlock_axes 's'+#define EA_crushBlock_chillout 6+#define EK_crushBlock_chillout 'b'+#define EA_crushBlock__size 8+#define EA_bigWaterfall_width 0+#define EK_bigWaterfall_width 'i'+#define EA_bigWaterfall_height 2+#define EK_bigWaterfall_height 'i'+#define EA_bigWaterfall_layer 4+#define EK_bigWaterfall_layer 's'+#define EA_bigWaterfall__size 6+#define EA_infiniteStar_shielded 0+#define EK_infiniteStar_shielded 'b'+#define EA_infiniteStar_singleUse 1+#define EK_infiniteStar_singleUse 'b'+#define EA_infiniteStar__size 2+#define EA_reflectionHeartStatue__size 0+#define EA_bigSpinner__size 0+#define EA_badelineBoost_lockCamera 0+#define EK_badelineBoost_lockCamera 'b'+#define EA_badelineBoost_canSkip 1+#define EK_badelineBoost_canSkip 'b'+#define EA_badelineBoost_finalCh9Boost 2+#define EK_badelineBoost_finalCh9Boost 'b'+#define EA_badelineBoost_finalCh9GoldenBoost 3+#define EK_badelineBoost_finalCh9GoldenBoost 'b'+#define EA_badelineBoost_finalCh9Dialog 4+#define EK_badelineBoost_finalCh9Dialog 'b'+#define EA_badelineBoost__size 6+#define EA_tentacles_fear_distance 0+#define EK_tentacles_fear_distance 's'+#define EA_tentacles_slide_until 2+#define EK_tentacles_slide_until 'i'+#define EA_tentacles__size 4+#define EA_finalBoss_patternIndex 0+#define EK_finalBoss_patternIndex 'i'+#define EA_finalBoss_cameraPastY 2+#define EK_finalBoss_cameraPastY 'i'+#define EA_finalBoss_dialog 4+#define EK_finalBoss_dialog 'b'+#define EA_finalBoss_startHit 5+#define EK_finalBoss_startHit 'b'+#define EA_finalBoss_cameraLockY 6+#define EK_finalBoss_cameraLockY 'b'+#define EA_finalBoss__size 8+#define EA_finalBossFallingBlock_width 0+#define EK_finalBossFallingBlock_width 'i'+#define EA_finalBossFallingBlock_height 2+#define EK_finalBossFallingBlock_height 'i'+#define EA_finalBossFallingBlock__size 4+#define EA_finalBossMovingBlock_width 0+#define EK_finalBossMovingBlock_width 'i'+#define EA_finalBossMovingBlock_height 2+#define EK_finalBossMovingBlock_height 'i'+#define EA_finalBossMovingBlock_nodeIndex 4+#define EK_finalBossMovingBlock_nodeIndex 'i'+#define EA_finalBossMovingBlock__size 6+#define EA_plateau__size 0+#define EA_starJumpBlock_width 0+#define EK_starJumpBlock_width 'i'+#define EA_starJumpBlock_height 2+#define EK_starJumpBlock_height 'i'+#define EA_starJumpBlock_sinks 4+#define EK_starJumpBlock_sinks 'b'+#define EA_starJumpBlock__size 6+#define EA_SummitBackgroundManager_index 0+#define EK_SummitBackgroundManager_index 'i'+#define EA_SummitBackgroundManager_intro_launch 2+#define EK_SummitBackgroundManager_intro_launch 'b'+#define EA_SummitBackgroundManager_cutscene 4+#define EK_SummitBackgroundManager_cutscene 's'+#define EA_SummitBackgroundManager_dark 6+#define EK_SummitBackgroundManager_dark 'b'+#define EA_SummitBackgroundManager__size 8+#define EA_wallSpringLeft_playerCanUse 0+#define EK_wallSpringLeft_playerCanUse 'b'+#define EA_wallSpringLeft__size 2+#define EA_summitgem_gem 0+#define EK_summitgem_gem 'i'+#define EA_summitgem__size 2+#define EA_bridgeFixed_width 0+#define EK_bridgeFixed_width 'i'+#define EA_bridgeFixed__size 2+#define EA_summitcheckpoint_number 0+#define EK_summitcheckpoint_number 'i'+#define EA_summitcheckpoint__size 2+#define EA_summitGemManager__size 0+#define EA_summitcloud__size 0+#define EA_heartGemDoor_width 0+#define EK_heartGemDoor_width 'i'+#define EA_heartGemDoor_height 2+#define EK_heartGemDoor_height 'i'+#define EA_heartGemDoor_requires 4+#define EK_heartGemDoor_requires 'i'+#define EA_heartGemDoor_startHidden 6+#define EK_heartGemDoor_startHidden 'b'+#define EA_heartGemDoor__size 8+#define EA_wallBooster_height 0+#define EK_wallBooster_height 'i'+#define EA_wallBooster_left 2+#define EK_wallBooster_left 'b'+#define EA_wallBooster__size 4+#define EA_fireBall_amount 0+#define EK_fireBall_amount 'i'+#define EA_fireBall_offset 4+#define EK_fireBall_offset 'f'+#define EA_fireBall_speed 8+#define EK_fireBall_speed 'f'+#define EA_fireBall__size 12+#define EA_bounceBlock_width 0+#define EK_bounceBlock_width 'i'+#define EA_bounceBlock_height 2+#define EK_bounceBlock_height 'i'+#define EA_bounceBlock__size 4+#define EA_iceBlock_width 0+#define EK_iceBlock_width 'i'+#define EA_iceBlock_height 2+#define EK_iceBlock_height 'i'+#define EA_iceBlock__size 4+#define EA_coreModeToggle_onlyFire 0+#define EK_coreModeToggle_onlyFire 'b'+#define EA_coreModeToggle_onlyIce 1+#define EK_coreModeToggle_onlyIce 'b'+#define EA_coreModeToggle_persistent 2+#define EK_coreModeToggle_persistent 'b'+#define EA_coreModeToggle__size 4+#define EA_fireBarrier_width 0+#define EK_fireBarrier_width 'i'+#define EA_fireBarrier_height 2+#define EK_fireBarrier_height 'i'+#define EA_fireBarrier__size 4+#define EA_risingLava_intro 0+#define EK_risingLava_intro 'b'+#define EA_risingLava__size 2+#define EA_sandwichLava__size 0+#define EA_coreMessage_line 0+#define EK_coreMessage_line 'i'+#define EA_coreMessage__size 2+#define EA_cameraOffsetTrigger_width 0+#define EK_cameraOffsetTrigger_width 'i'+#define EA_cameraOffsetTrigger_height 2+#define EK_cameraOffsetTrigger_height 'i'+#define EA_cameraOffsetTrigger_cameraX 4+#define EK_cameraOffsetTrigger_cameraX 'f'+#define EA_cameraOffsetTrigger_cameraY 8+#define EK_cameraOffsetTrigger_cameraY 'f'+#define EA_cameraOffsetTrigger__size 12+#define EA_cameraTargetTrigger_width 0+#define EK_cameraTargetTrigger_width 'i'+#define EA_cameraTargetTrigger_height 2+#define EK_cameraTargetTrigger_height 'i'+#define EA_cameraTargetTrigger_lerpStrength 4+#define EK_cameraTargetTrigger_lerpStrength 'f'+#define EA_cameraTargetTrigger_positionMode 8+#define EK_cameraTargetTrigger_positionMode 's'+#define EA_cameraTargetTrigger_xOnly 10+#define EK_cameraTargetTrigger_xOnly 'b'+#define EA_cameraTargetTrigger_yOnly 11+#define EK_cameraTargetTrigger_yOnly 'b'+#define EA_cameraTargetTrigger_deleteFlag 12+#define EK_cameraTargetTrigger_deleteFlag 's'+#define EA_cameraTargetTrigger__size 14+#define EA_changeRespawnTrigger_width 0+#define EK_changeRespawnTrigger_width 'i'+#define EA_changeRespawnTrigger_height 2+#define EK_changeRespawnTrigger_height 'i'+#define EA_changeRespawnTrigger__size 4+#define EA_eventTrigger_width 0+#define EK_eventTrigger_width 'i'+#define EA_eventTrigger_height 2+#define EK_eventTrigger_height 'i'+#define EA_eventTrigger_event 4+#define EK_eventTrigger_event 's'+#define EA_eventTrigger_onSpawn 6+#define EK_eventTrigger_onSpawn 'b'+#define EA_eventTrigger__size 8+#define EA_goldenBerryCollectTrigger_width 0+#define EK_goldenBerryCollectTrigger_width 'i'+#define EA_goldenBerryCollectTrigger_height 2+#define EK_goldenBerryCollectTrigger_height 'i'+#define EA_goldenBerryCollectTrigger__size 4+#define EA_respawnTargetTrigger_width 0+#define EK_respawnTargetTrigger_width 'i'+#define EA_respawnTargetTrigger_height 2+#define EK_respawnTargetTrigger_height 'i'+#define EA_respawnTargetTrigger__size 4+#define EA_interactTrigger_width 0+#define EK_interactTrigger_width 'i'+#define EA_interactTrigger_height 2+#define EK_interactTrigger_height 'i'+#define EA_interactTrigger_event 4+#define EK_interactTrigger_event 's'+#define EA_interactTrigger_event_2 6+#define EK_interactTrigger_event_2 's'+#define EA_interactTrigger_event_3 8+#define EK_interactTrigger_event_3 's'+#define EA_interactTrigger__size 10+#define EA_bloomFadeTrigger_width 0+#define EK_bloomFadeTrigger_width 'i'+#define EA_bloomFadeTrigger_height 2+#define EK_bloomFadeTrigger_height 'i'+#define EA_bloomFadeTrigger_bloomAddFrom 4+#define EK_bloomFadeTrigger_bloomAddFrom 'f'+#define EA_bloomFadeTrigger_bloomAddTo 8+#define EK_bloomFadeTrigger_bloomAddTo 'f'+#define EA_bloomFadeTrigger_positionMode 12+#define EK_bloomFadeTrigger_positionMode 's'+#define EA_bloomFadeTrigger__size 14+#define EA_lightFadeTrigger_width 0+#define EK_lightFadeTrigger_width 'i'+#define EA_lightFadeTrigger_height 2+#define EK_lightFadeTrigger_height 'i'+#define EA_lightFadeTrigger_lightAddFrom 4+#define EK_lightFadeTrigger_lightAddFrom 'f'+#define EA_lightFadeTrigger_lightAddTo 8+#define EK_lightFadeTrigger_lightAddTo 'f'+#define EA_lightFadeTrigger_positionMode 12+#define EK_lightFadeTrigger_positionMode 's'+#define EA_lightFadeTrigger__size 14+#define EA_oshiroTrigger_width 0+#define EK_oshiroTrigger_width 'i'+#define EA_oshiroTrigger_height 2+#define EK_oshiroTrigger_height 'i'+#define EA_oshiroTrigger_state 4+#define EK_oshiroTrigger_state 'b'+#define EA_oshiroTrigger__size 6+#define EA_windTrigger_width 0+#define EK_windTrigger_width 'i'+#define EA_windTrigger_height 2+#define EK_windTrigger_height 'i'+#define EA_windTrigger_pattern 4+#define EK_windTrigger_pattern 's'+#define EA_windTrigger__size 6+#define EA_windAttackTrigger_width 0+#define EK_windAttackTrigger_width 'i'+#define EA_windAttackTrigger_height 2+#define EK_windAttackTrigger_height 'i'+#define EA_windAttackTrigger__size 4+#define EA_minitextboxTrigger_width 0+#define EK_minitextboxTrigger_width 'i'+#define EA_minitextboxTrigger_height 2+#define EK_minitextboxTrigger_height 'i'+#define EA_minitextboxTrigger_mode 4+#define EK_minitextboxTrigger_mode 's'+#define EA_minitextboxTrigger_dialog_id 6+#define EK_minitextboxTrigger_dialog_id 's'+#define EA_minitextboxTrigger_only_once 8+#define EK_minitextboxTrigger_only_once 'b'+#define EA_minitextboxTrigger_death_count 10+#define EK_minitextboxTrigger_death_count 'i'+#define EA_minitextboxTrigger__size 12+#define EA_checkpointBlockerTrigger_width 0+#define EK_checkpointBlockerTrigger_width 'i'+#define EA_checkpointBlockerTrigger_height 2+#define EK_checkpointBlockerTrigger_height 'i'+#define EA_checkpointBlockerTrigger__size 4+#define EA_lookoutBlocker_width 0+#define EK_lookoutBlocker_width 'i'+#define EA_lookoutBlocker_height 2+#define EK_lookoutBlocker_height 'i'+#define EA_lookoutBlocker__size 4+#define EA_creditsTrigger_width 0+#define EK_creditsTrigger_width 'i'+#define EA_creditsTrigger_height 2+#define EK_creditsTrigger_height 'i'+#define EA_creditsTrigger_event 4+#define EK_creditsTrigger_event 's'+#define EA_creditsTrigger__size 6+#define EA_noRefillTrigger_width 0+#define EK_noRefillTrigger_width 'i'+#define EA_noRefillTrigger_height 2+#define EK_noRefillTrigger_height 'i'+#define EA_noRefillTrigger_state 4+#define EK_noRefillTrigger_state 'b'+#define EA_noRefillTrigger__size 6+#define EA_cameraAdvanceTargetTrigger_width 0+#define EK_cameraAdvanceTargetTrigger_width 'i'+#define EA_cameraAdvanceTargetTrigger_height 2+#define EK_cameraAdvanceTargetTrigger_height 'i'+#define EA_cameraAdvanceTargetTrigger_lerpStrengthX 4+#define EK_cameraAdvanceTargetTrigger_lerpStrengthX 'i'+#define EA_cameraAdvanceTargetTrigger_lerpStrengthY 6+#define EK_cameraAdvanceTargetTrigger_lerpStrengthY 'i'+#define EA_cameraAdvanceTargetTrigger_positionModeX 8+#define EK_cameraAdvanceTargetTrigger_positionModeX 's'+#define EA_cameraAdvanceTargetTrigger_positionModeY 10+#define EK_cameraAdvanceTargetTrigger_positionModeY 's'+#define EA_cameraAdvanceTargetTrigger_xOnly 12+#define EK_cameraAdvanceTargetTrigger_xOnly 'b'+#define EA_cameraAdvanceTargetTrigger_yOnly 13+#define EK_cameraAdvanceTargetTrigger_yOnly 'b'+#define EA_cameraAdvanceTargetTrigger__size 14+static const uint8_t ENT_ATTR_SIZE[] = {2,0,2,2,4,6,0,2,2,2,4,4,4,0,6,4,2,2,2,6,4,8,0,8,8,8,10,2,2,6,2,0,0,2,2,0,8,8,2,0,0,0,4,6,0,0,2,2,6,6,0,6,2,0,4,4,0,0,4,2,0,2,2,2,2,0,6,6,0,2,0,0,0,2,0,2,2,2,2,2,8,0,8,0,2,6,6,2,6,8,6,0,0,6,2,4,10,0,0,0,0,0,2,8,6,2,0,0,6,4,8,4,6,0,6,8,2,2,2,2,0,0,8,4,12,4,4,4,4,2,0,2};+static const uint8_t TRIG_ATTR_SIZE[] = {12,14,4,8,4,4,10,14,14,6,6,4,12,4,4,6,6,14};++#define T_animatedTiles_grass_top_a00 0+#define T_animatedTiles_grass_top_a01 1+#define T_animatedTiles_grass_top_a02 2+#define T_animatedTiles_grass_top_a03 3+#define T_animatedTiles_dead_top_a00 4+#define T_animatedTiles_dead_top_a01 5+#define T_animatedTiles_dead_top_a02 6+#define T_animatedTiles_dead_top_a03 7+#define T_scenery_car_body 8+#define T_scenery_car_wheels 9+#define T_scenery_car_pavement 10+#define T_scenery_car_barrier 11+#define T_scenery_lamp 12+#define T_objects_jumpthru_wood 13+#define T_objects_jumpthru_dream 14+#define T_objects_jumpthru_temple 15+#define T_objects_jumpthru_templeB 16+#define T_objects_jumpthru_cliffside 17+#define T_objects_jumpthru_reflection 18+#define T_objects_jumpthru_core 19+#define T_objects_jumpthru_moon 20+#define T_scenery_flutterbird_idle00 21+#define T_scenery_flutterbird_flap00 22+#define T_scenery_flutterbird_flap01 23+#define T_characters_bird_crow00 24+#define T_characters_bird_crow01 25+#define T_characters_bird_crow02 26+#define T_characters_bird_crow03 27+#define T_characters_bird_crow04 28+#define T_characters_bird_crow05 29+#define T_characters_bird_crow06 30+#define T_characters_bird_crow07 31+#define T_characters_bird_crow08 32+#define T_characters_bird_crow09 33+#define T_characters_bird_crow10 34+#define T_characters_bird_crow11 35+#define T_characters_bird_crow12 36+#define T_characters_bird_crow13 37+#define T_characters_bird_crow14 38+#define T_characters_bird_crow15 39+#define T_characters_bird_crow16 40+#define T_characters_bird_crow17 41+#define T_characters_bird_crow18 42+#define T_characters_bird_crow19 43+#define T_characters_bird_crow20 44+#define T_characters_bird_crow21 45+#define T_characters_bird_crow22 46+#define T_characters_bird_crow23 47+#define T_characters_bird_crow24 48+#define T_characters_bird_crow25 49+#define T_characters_bird_crow26 50+#define T_characters_bird_crow27 51+#define T_characters_bird_crow28 52+#define T_characters_bird_crow29 53+#define T_characters_bird_crow30 54+#define T_characters_bird_crow31 55+#define T_characters_bird_crow32 56+#define T_characters_bird_crow33 57+#define T_characters_bird_crow34 58+#define T_characters_bird_crow35 59+#define T_characters_bird_crow36 60+#define T_characters_bird_crow37 61+#define T_characters_bird_crow38 62+#define T_characters_bird_crow39 63+#define T_characters_bird_crow40 64+#define T_characters_bird_crow41 65+#define T_characters_bird_crow42 66+#define T_characters_bird_crow43 67+#define T_characters_bird_crow44 68+#define T_characters_bird_crow45 69+#define T_characters_bird_crow46 70+#define T_characters_bird_crow47 71+#define T_characters_bird_crow48 72+#define T_characters_bird_fly00 73+#define T_characters_bird_fly01 74+#define T_characters_bird_fly02 75+#define T_characters_bird_fly03 76+#define T_characters_bird_dash00 77+#define T_characters_bird_hover00 78+#define T_characters_bird_hover01 79+#define T_characters_bird_Hover02 80+#define T_characters_bird_Hover03 81+#define T_characters_bird_Hover04 82+#define T_characters_bird_Hover05 83+#define T_characters_bird_HoverStressed00 84+#define T_characters_bird_HoverStressed01 85+#define T_characters_bird_HoverStressed02 86+#define T_characters_bird_HoverStressed03 87+#define T_characters_bird_HoverStressed04 88+#define T_characters_bird_HoverStressed05 89+#define T_characters_bird_flyup00 90+#define T_characters_bird_FlyUp01 91+#define T_characters_bird_FlyUp02 92+#define T_characters_bird_FlyUp03 93+#define T_characters_bird_FlyUp04 94+#define T_characters_bird_FlyUp05 95+#define T_characters_bird_FlyUp06 96+#define T_characters_bird_FlyUp07 97+#define T_characters_bird_FlyUp08 98+#define T_characters_bird_FlyUp09 99+#define T_characters_bird_FlyUp10 100+#define T_characters_bird_FlyUp11 101+#define T_characters_bird_FlyUp12 102+#define T_characters_bird_FlyUp13 103+#define T_characters_bird_FlyUp14 104+#define T_characters_bird_FlyUp15 105+#define T_characters_bird_Throw00 106+#define T_characters_bird_Throw01 107+#define T_characters_bird_Throw02 108+#define T_characters_bird_Throw03 109+#define T_characters_bird_Throw04 110+#define T_characters_bird_Throw05 111+#define T_characters_bird_Throw06 112+#define T_characters_bird_hurt00 113+#define T_characters_bird_Hurt01 114+#define T_characters_bird_Hurt02 115+#define T_characters_bird_Hurt03 116+#define T_characters_bird_Hurt04 117+#define T_characters_bird_Hurt05 118+#define T_characters_bird_Hurt06 119+#define T_characters_bird_Hurt07 120+#define T_characters_bird_Hurt08 121+#define T_characters_bird_Hurt09 122+#define T_characters_bird_Hurt10 123+#define T_characters_bird_Hurt11 124+#define T_characters_bird_Hurt12 125+#define T_characters_bird_Hurt13 126+#define T_characters_bird_Hurt14 127+#define T_characters_bird_Hurt15 128+#define T_characters_bird_Hurt16 129+#define T_characters_bird_Hurt17 130+#define T_characters_bird_Hurt18 131+#define T_characters_bird_Hurt19 132+#define T_characters_bird_Hurt20 133+#define T_characters_bird_Hurt21 134+#define T_characters_bird_Recover00 135+#define T_characters_bird_Recover01 136+#define T_characters_bird_Recover02 137+#define T_characters_bird_Recover03 138+#define T_characters_bird_Recover04 139+#define T_characters_bird_Recover05 140+#define T_characters_bird_Recover06 141+#define T_characters_bird_Recover07 142+#define T_characters_bird_Hold00 143+#define T_characters_bird_Hold01 144+#define T_characters_bird_Hold02 145+#define T_characters_bird_Hold03 146+#define T_characters_bird_Hold04 147+#define T_characters_bird_Hold05 148+#define T_characters_oldlady_idle00 149+#define T_characters_oldlady_idle01 150+#define T_characters_oldlady_idle02 151+#define T_characters_oldlady_idle03 152+#define T_characters_oldlady_idle04 153+#define T_characters_oldlady_idle05 154+#define T_characters_oldlady_idle06 155+#define T_characters_oldlady_idle07 156+#define T_characters_oldlady_idle08 157+#define T_characters_oldlady_idle09 158+#define T_characters_oldlady_idle10 159+#define T_characters_oldlady_idle11 160+#define T_characters_oldlady_walk00 161+#define T_characters_oldlady_walk01 162+#define T_characters_oldlady_walk02 163+#define T_characters_oldlady_walk03 164+#define T_characters_oldlady_walk04 165+#define T_characters_oldlady_walk05 166+#define T_characters_oldlady_walk06 167+#define T_characters_oldlady_walk07 168+#define T_characters_oldlady_laugh00 169+#define T_characters_oldlady_laugh01 170+#define T_characters_oldlady_laugh02 171+#define T_characters_oldlady_laugh03 172+#define T_characters_oldlady_quotes00 173+#define T_characters_oldlady_quotes01 174+#define T_characters_oldlady_quotes02 175+#define T_characters_oldlady_quotes03 176+#define T_characters_oldlady_quotes04 177+#define T_characters_oldlady_quotes05 178+#define T_characters_oldlady_quotes06 179+#define T_characters_oldlady_quotes07 180+#define T_characters_oldlady_quotes08 181+#define T_characters_oldlady_quotes09 182+#define T_characters_oldlady_quotes10 183+#define T_characters_oldlady_quotes11 184+#define T_characters_oldlady_quotes12 185+#define T_characters_oldlady_quotes13 186+#define T_characters_oldlady_quotes14 187+#define T_characters_oldlady_quotes15 188+#define T_characters_oldlady_quotes16 189+#define T_characters_oldlady_quotes17 190+#define T_characters_oldlady_quotes18 191+#define T_characters_oldlady_quotes19 192+#define T_characters_oldlady_quotes20 193+#define T_characters_oldlady_quotes21 194+#define T_characters_oldlady_quotes22 195+#define T_characters_oldlady_quotes23 196+#define T_characters_oldlady_quotes24 197+#define T_characters_oldlady_quotes25 198+#define T_characters_oldlady_quotes26 199+#define T_characters_oldlady_quotes27 200+#define T_characters_oldlady_quotes28 201+#define T_scenery_bridge 202+#define T_characters_oldlady_ha00 203+#define T_characters_oldlady_ha01 204+#define T_characters_oldlady_ha02 205+#define T_characters_oldlady_ha03 206+#define T_characters_oldlady_ha04 207+#define T_characters_oldlady_ha05 208+#define T_characters_oldlady_ha06 209+#define T_characters_oldlady_ha07 210+#define T_characters_oldlady_ha08 211+#define T_characters_oldlady_ha09 212+#define T_danger_spikes_default_up00 213+#define T_danger_spikes_outline_up00 214+#define T_danger_spikes_cliffside_up00 215+#define T_danger_spikes_cliffside_up01 216+#define T_danger_spikes_cliffside_up02 217+#define T_danger_spikes_cliffside_up03 218+#define T_danger_spikes_reflection_up00 219+#define T_danger_spikes_reflection_up01 220+#define T_danger_spikes_reflection_up02 221+#define T_danger_spikes_reflection_up03 222+#define T_danger_spikes_default_left00 223+#define T_danger_spikes_outline_left00 224+#define T_danger_spikes_cliffside_left00 225+#define T_danger_spikes_cliffside_left01 226+#define T_danger_spikes_cliffside_left02 227+#define T_danger_spikes_reflection_left00 228+#define T_danger_spikes_reflection_left01 229+#define T_danger_spikes_reflection_left02 230+#define T_collectables_goldberry_idle00 231+#define T_collectables_goldberry_idle01 232+#define T_collectables_goldberry_idle02 233+#define T_collectables_goldberry_idle03 234+#define T_collectables_goldberry_idle04 235+#define T_collectables_goldberry_idle05 236+#define T_collectables_goldberry_idle06 237+#define T_collectables_goldberry_idle07 238+#define T_collectables_goldberry_idle08 239+#define T_collectables_goldberry_idle09 240+#define T_collectables_goldberry_idle10 241+#define T_collectables_goldberry_idle11 242+#define T_collectables_goldberry_wings00 243+#define T_collectables_goldberry_wings01 244+#define T_collectables_goldberry_wings02 245+#define T_collectables_goldberry_wings03 246+#define T_collectables_goldberry_wings04 247+#define T_collectables_goldberry_wings05 248+#define T_collectables_goldberry_wings06 249+#define T_collectables_goldberry_wings07 250+#define T_collectables_goldberry_wings08 251+#define T_collectables_goldberry_wings09 252+#define T_collectables_ghostgoldberry_idle00 253+#define T_collectables_ghostgoldberry_idle01 254+#define T_collectables_ghostgoldberry_idle02 255+#define T_collectables_ghostgoldberry_idle03 256+#define T_collectables_ghostgoldberry_idle04 257+#define T_collectables_ghostgoldberry_idle05 258+#define T_collectables_ghostgoldberry_idle06 259+#define T_collectables_ghostgoldberry_idle07 260+#define T_collectables_ghostgoldberry_idle08 261+#define T_collectables_ghostgoldberry_idle09 262+#define T_collectables_ghostgoldberry_idle10 263+#define T_collectables_ghostgoldberry_idle11 264+#define T_collectables_ghostgoldberry_wings00 265+#define T_collectables_ghostgoldberry_wings01 266+#define T_collectables_ghostgoldberry_wings02 267+#define T_collectables_ghostgoldberry_wings03 268+#define T_collectables_ghostgoldberry_wings04 269+#define T_collectables_ghostgoldberry_wings05 270+#define T_collectables_ghostgoldberry_wings06 271+#define T_collectables_ghostgoldberry_wings07 272+#define T_collectables_ghostgoldberry_wings08 273+#define T_collectables_ghostgoldberry_wings09 274+#define T_collectables_strawberry_normal00 275+#define T_collectables_strawberry_normal01 276+#define T_collectables_strawberry_normal02 277+#define T_collectables_strawberry_normal03 278+#define T_collectables_strawberry_normal04 279+#define T_collectables_strawberry_normal05 280+#define T_collectables_strawberry_normal06 281+#define T_collectables_strawberry_normal07 282+#define T_collectables_strawberry_normal08 283+#define T_collectables_strawberry_normal09 284+#define T_collectables_strawberry_normal10 285+#define T_collectables_strawberry_normal11 286+#define T_collectables_strawberry_normal12 287+#define T_collectables_strawberry_normal13 288+#define T_collectables_strawberry_normal14 289+#define T_collectables_strawberry_normal15 290+#define T_collectables_strawberry_normal16 291+#define T_collectables_strawberry_normal17 292+#define T_collectables_strawberry_normal18 293+#define T_collectables_strawberry_normal19 294+#define T_collectables_strawberry_normal20 295+#define T_collectables_strawberry_normal21 296+#define T_collectables_strawberry_normal22 297+#define T_collectables_strawberry_normal23 298+#define T_collectables_strawberry_normal24 299+#define T_collectables_strawberry_normal25 300+#define T_collectables_strawberry_normal26 301+#define T_collectables_strawberry_normal27 302+#define T_collectables_strawberry_normal28 303+#define T_collectables_strawberry_normal29 304+#define T_collectables_strawberry_normal30 305+#define T_collectables_strawberry_normal31 306+#define T_collectables_strawberry_normal32 307+#define T_collectables_strawberry_normal33 308+#define T_collectables_strawberry_normal34 309+#define T_collectables_strawberry_normal35 310+#define T_collectables_strawberry_normal36 311+#define T_collectables_strawberry_normal37 312+#define T_collectables_strawberry_normal38 313+#define T_collectables_strawberry_normal39 314+#define T_collectables_strawberry_normal40 315+#define T_collectables_strawberry_normal41 316+#define T_collectables_strawberry_normal42 317+#define T_collectables_strawberry_normal43 318+#define T_collectables_strawberry_normal44 319+#define T_collectables_strawberry_normal45 320+#define T_collectables_strawberry_normal46 321+#define T_collectables_strawberry_normal47 322+#define T_collectables_strawberry_normal48 323+#define T_collectables_strawberry_normal49 324+#define T_collectables_strawberry_normal50 325+#define T_collectables_strawberry_normal51 326+#define T_collectables_strawberry_normal52 327+#define T_collectables_strawberry_normal53 328+#define T_collectables_strawberry_normal54 329+#define T_collectables_strawberry_normal55 330+#define T_collectables_strawberry_normal56 331+#define T_collectables_strawberry_normal57 332+#define T_collectables_strawberry_normal58 333+#define T_collectables_strawberry_normal59 334+#define T_collectables_strawberry_normal60 335+#define T_collectables_strawberry_normal61 336+#define T_collectables_strawberry_wings00 337+#define T_collectables_strawberry_wings01 338+#define T_collectables_strawberry_wings02 339+#define T_collectables_strawberry_wings03 340+#define T_collectables_strawberry_wings04 341+#define T_collectables_strawberry_wings05 342+#define T_collectables_strawberry_wings06 343+#define T_collectables_strawberry_wings07 344+#define T_collectables_strawberry_wings08 345+#define T_collectables_strawberry_wings09 346+#define T_collectables_strawberry_wow_normal52 347+#define T_collectables_strawberry_wow_normal53 348+#define T_collectables_strawberry_wow_normal54 349+#define T_collectables_strawberry_wow_normal55 350+#define T_collectables_strawberry_wow_normal56 351+#define T_collectables_strawberry_wow_normal57 352+#define T_collectables_strawberry_wow_normal58 353+#define T_collectables_strawberry_wow_normal59 354+#define T_collectables_strawberry_wow_normal60 355+#define T_collectables_strawberry_wow_normal61 356+#define T_collectables_strawberry_wow_normal62 357+#define T_collectables_strawberry_wow_normal63 358+#define T_collectables_strawberry_wow_normal64 359+#define T_collectables_strawberry_wow_normal65 360+#define T_collectables_strawberry_wow_normal66 361+#define T_objects_zipmover_block 362+#define T_objects_zipmover_light00 363+#define T_objects_zipmover_light01 364+#define T_objects_zipmover_light02 365+#define T_objects_zipmover_light03 366+#define T_objects_zipmover_cog 367+#define T_objects_zipmover_innercog00 368+#define T_objects_zipmover_innercog01 369+#define T_objects_zipmover_innercog02 370+#define T_objects_zipmover_innercog03 371+#define T_objects_zipmover_innercog04 372+#define T_objects_zipmover_innercog05 373+#define T_objects_zipmover_innercog06 374+#define T_objects_zipmover_innercog07 375+#define T_objects_zipmover_innercog08 376+#define T_objects_zipmover_innercog09 377+#define T_objects_zipmover_innercog10 378+#define T_objects_zipmover_innercog11 379+#define T_danger_spikes_default_right00 380+#define T_danger_spikes_outline_right00 381+#define T_danger_spikes_cliffside_right00 382+#define T_danger_spikes_cliffside_right01 383+#define T_danger_spikes_cliffside_right02 384+#define T_danger_spikes_reflection_right00 385+#define T_danger_spikes_reflection_right01 386+#define T_danger_spikes_reflection_right02 387+#define T_objects_crumbleBlock_default 388+#define T_objects_crumbleBlock_outline 389+#define T_objects_crumbleBlock_cliffside 390+#define T_objects_refill_idle00 391+#define T_objects_refill_idle01 392+#define T_objects_refill_idle02 393+#define T_objects_refill_idle03 394+#define T_objects_refill_idle04 395+#define T_objects_refill_flash00 396+#define T_objects_refill_flash01 397+#define T_objects_refill_flash02 398+#define T_objects_refill_flash03 399+#define T_objects_refill_flash04 400+#define T_objects_refill_flash05 401+#define T_objects_refill_outline 402+#define T_objects_refillTwo_idle00 403+#define T_objects_refillTwo_idle01 404+#define T_objects_refillTwo_idle02 405+#define T_objects_refillTwo_idle03 406+#define T_objects_refillTwo_idle04 407+#define T_objects_refillTwo_idle05 408+#define T_objects_refillTwo_idle06 409+#define T_objects_refillTwo_idle07 410+#define T_objects_refillTwo_idle08 411+#define T_objects_refillTwo_idle09 412+#define T_objects_refillTwo_idle10 413+#define T_objects_refillTwo_idle11 414+#define T_objects_refillTwo_idle12 415+#define T_objects_refillTwo_flash00 416+#define T_objects_refillTwo_flash01 417+#define T_objects_refillTwo_flash02 418+#define T_objects_refillTwo_flash03 419+#define T_objects_refillTwo_flash04 420+#define T_objects_refillTwo_flash05 421+#define T_objects_refillTwo_outline 422+#define T_objects_spring_00 423+#define T_objects_spring_01 424+#define T_objects_spring_02 425+#define T_objects_spring_03 426+#define T_objects_spring_04 427+#define T_objects_spring_05 428+#define T_objects_spring_white 429+#define T_collectables_ghostberry_idle00 430+#define T_collectables_ghostberry_idle01 431+#define T_collectables_ghostberry_idle02 432+#define T_collectables_ghostberry_idle03 433+#define T_collectables_ghostberry_idle04 434+#define T_collectables_ghostberry_idle05 435+#define T_collectables_ghostberry_idle06 436+#define T_collectables_ghostberry_idle07 437+#define T_collectables_ghostberry_idle08 438+#define T_collectables_ghostberry_idle09 439+#define T_collectables_ghostberry_idle10 440+#define T_collectables_ghostberry_idle11 441+#define T_collectables_ghostberry_wings00 442+#define T_collectables_ghostberry_wings01 443+#define T_collectables_ghostberry_wings02 444+#define T_collectables_ghostberry_wings03 445+#define T_collectables_ghostberry_wings04 446+#define T_collectables_ghostberry_wings05 447+#define T_collectables_ghostberry_wings06 448+#define T_collectables_ghostberry_wings07 449+#define T_collectables_ghostberry_wings08 450+#define T_collectables_ghostberry_wings09 451+#define T_collectables_strawberry_seed00 452+#define T_collectables_strawberry_seed01 453+#define T_collectables_ghostberry_seed00 454+#define T_collectables_ghostberry_seed01 455+#define T_collectables_goldberry_seed00 456+#define T_collectables_goldberry_seed01 457+#define T_danger_spikes_default_down00 458+#define T_danger_spikes_outline_down00 459+#define T_danger_spikes_cliffside_down00 460+#define T_danger_spikes_cliffside_down01 461+#define T_danger_spikes_cliffside_down02 462+#define T_danger_spikes_reflection_down00 463+#define T_danger_spikes_reflection_down01 464+#define T_danger_spikes_reflection_down02 465+#define T_util_lightbeam 466+#define T_collectables_cassette_idle00 467+#define T_collectables_cassette_idle01 468+#define T_collectables_cassette_idle02 469+#define T_collectables_cassette_idle03 470+#define T_collectables_cassette_idle04 471+#define T_collectables_cassette_idle05 472+#define T_collectables_cassette_idle06 473+#define T_collectables_cassette_idle07 474+#define T_collectables_cassette_idle08 475+#define T_collectables_cassette_idle09 476+#define T_collectables_cassette_idle10 477+#define T_collectables_cassette_idle11 478+#define T_collectables_cassette_idle12 479+#define T_collectables_cassette_idle13 480+#define T_collectables_cassette_idle14 481+#define T_collectables_cassette_idle15 482+#define T_collectables_cassette_idle16 483+#define T_collectables_cassette_idle17 484+#define T_collectables_cassette_idle18 485+#define T_collectables_cassette_ghost00 486+#define T_collectables_cassette_ghost01 487+#define T_collectables_cassette_ghost02 488+#define T_collectables_cassette_ghost03 489+#define T_collectables_cassette_ghost04 490+#define T_collectables_cassette_ghost05 491+#define T_collectables_cassette_ghost06 492+#define T_collectables_cassette_ghost07 493+#define T_collectables_cassette_ghost08 494+#define T_collectables_cassette_ghost09 495+#define T_collectables_cassette_ghost10 496+#define T_collectables_cassette_ghost11 497+#define T_collectables_cassette_ghost12 498+#define T_collectables_cassette_ghost13 499+#define T_collectables_cassette_ghost14 500+#define T_collectables_cassette_ghost15 501+#define T_collectables_cassette_ghost16 502+#define T_collectables_cassette_ghost17 503+#define T_collectables_cassette_ghost18 504+#define T_objects_cassetteblock_solid 505+#define T_objects_cassetteblock_pressed00 506+#define T_objects_cassetteblock_pressed01 507+#define T_objects_cassetteblock_pressed02 508+#define T_objects_cassetteblock_pressed03 509+#define T_objects_checkpoint_bg_1 510+#define T_objects_checkpoint_bg_2 511+#define T_objects_checkpoint_bg_3 512+#define T_objects_checkpoint_bg_4 513+#define T_objects_checkpoint_bg_5 514+#define T_objects_checkpoint_bg_6 515+#define T_objects_checkpoint_bg_7 516+#define T_objects_checkpoint_bg_9 517+#define T_objects_checkpoint_bg_10 518+#define T_objects_campfire_fire00 519+#define T_objects_campfire_fire01 520+#define T_objects_campfire_fire02 521+#define T_objects_campfire_fire03 522+#define T_objects_campfire_fire04 523+#define T_objects_campfire_fire05 524+#define T_objects_campfire_fire06 525+#define T_objects_campfire_fire07 526+#define T_objects_campfire_fire08 527+#define T_objects_campfire_fire09 528+#define T_objects_campfire_fire10 529+#define T_objects_campfire_fire11 530+#define T_objects_campfire_fire12 531+#define T_objects_campfire_fire13 532+#define T_objects_campfire_fire14 533+#define T_objects_campfire_fire15 534+#define T_objects_campfire_dream00 535+#define T_objects_campfire_dream01 536+#define T_objects_campfire_dream02 537+#define T_objects_campfire_dream03 538+#define T_objects_campfire_dream04 539+#define T_objects_campfire_dream05 540+#define T_objects_campfire_dream06 541+#define T_objects_campfire_dream07 542+#define T_objects_campfire_dream08 543+#define T_objects_campfire_smoking00 544+#define T_objects_campfire_smoking01 545+#define T_objects_campfire_smoking02 546+#define T_objects_campfire_smoking03 547+#define T_objects_campfire_smoking04 548+#define T_objects_campfire_smoking05 549+#define T_objects_campfire_smoking06 550+#define T_objects_campfire_smoking07 551+#define T_characters_theo_theo00 552+#define T_characters_theo_theo01 553+#define T_characters_theo_theo02 554+#define T_characters_theo_theo03 555+#define T_characters_theo_theo04 556+#define T_characters_theo_theo05 557+#define T_characters_theo_theo06 558+#define T_characters_theo_theo07 559+#define T_characters_theo_theo08 560+#define T_characters_theo_theo09 561+#define T_characters_theo_theo10 562+#define T_characters_theo_theo11 563+#define T_characters_theo_theo12 564+#define T_characters_theo_theo13 565+#define T_characters_theo_theo14 566+#define T_characters_theo_theo15 567+#define T_characters_theo_theo16 568+#define T_characters_theo_theo17 569+#define T_characters_theo_theo18 570+#define T_characters_theo_theo19 571+#define T_characters_theo_theo20 572+#define T_characters_theo_theo21 573+#define T_characters_theo_theo22 574+#define T_characters_theo_theo23 575+#define T_characters_theo_theo24 576+#define T_characters_theo_theo25 577+#define T_characters_theo_theo26 578+#define T_characters_theo_theo27 579+#define T_characters_theo_theo28 580+#define T_characters_theo_theo29 581+#define T_characters_theo_theo30 582+#define T_characters_theo_theo31 583+#define T_characters_theo_theo32 584+#define T_characters_theo_theo33 585+#define T_characters_theo_theo34 586+#define T_characters_theo_theo35 587+#define T_characters_theo_theo36 588+#define T_characters_theo_theo37 589+#define T_characters_theo_theo38 590+#define T_characters_theo_theo39 591+#define T_characters_theo_theo40 592+#define T_characters_theo_theo41 593+#define T_characters_theo_theo42 594+#define T_characters_theo_theo43 595+#define T_characters_theo_theo44 596+#define T_characters_theo_theo45 597+#define T_characters_theo_theo46 598+#define T_characters_theo_theo47 599+#define T_characters_theo_theo48 600+#define T_characters_theo_theo49 601+#define T_characters_theo_theo50 602+#define T_characters_theo_theo51 603+#define T_characters_theo_theo52 604+#define T_characters_theo_theo53 605+#define T_characters_theo_theo54 606+#define T_characters_theo_theo55 607+#define T_characters_theo_theo56 608+#define T_characters_theo_theo57 609+#define T_characters_theo_theo58 610+#define T_characters_theo_theo59 611+#define T_characters_theo_theo60 612+#define T_characters_theo_theo61 613+#define T_characters_theo_theo62 614+#define T_characters_theo_theo63 615+#define T_characters_theo_theo64 616+#define T_characters_theo_theo65 617+#define T_characters_theo_theo66 618+#define T_characters_theo_theo67 619+#define T_characters_theo_theo68 620+#define T_characters_theo_theo69 621+#define T_characters_theo_theo70 622+#define T_characters_theo_theo71 623+#define T_characters_theo_theo72 624+#define T_characters_theo_theo73 625+#define T_characters_theo_theo74 626+#define T_characters_theo_theo75 627+#define T_characters_theo_theo76 628+#define T_characters_theo_theo77 629+#define T_characters_theo_theo78 630+#define T_characters_theo_theo79 631+#define T_characters_theo_theo80 632+#define T_characters_theo_theo81 633+#define T_characters_theo_theo82 634+#define T_characters_theo_theo83 635+#define T_characters_theo_theo84 636+#define T_characters_theo_theo85 637+#define T_characters_theo_theo86 638+#define T_characters_theo_theo87 639+#define T_characters_theo_theo88 640+#define T_characters_theo_theo89 641+#define T_characters_theo_theo90 642+#define T_characters_theo_theo91 643+#define T_characters_theo_theo92 644+#define T_characters_theo_theo93 645+#define T_characters_theo_theo94 646+#define T_characters_theo_theo95 647+#define T_characters_theo_theo96 648+#define T_characters_theo_theo97 649+#define T_characters_theo_theo98 650+#define T_characters_theo_theo99 651+#define T_characters_theo_theo100 652+#define T_characters_theo_theo101 653+#define T_characters_theo_theo102 654+#define T_characters_theo_theo103 655+#define T_characters_theo_theo104 656+#define T_characters_theo_theo105 657+#define T_characters_theo_theo106 658+#define T_characters_theo_theo107 659+#define T_characters_theo_theo108 660+#define T_characters_theo_theo109 661+#define T_characters_theo_theo110 662+#define T_characters_theo_theo111 663+#define T_characters_theo_theo112 664+#define T_characters_theo_theo113 665+#define T_characters_theo_theo114 666+#define T_characters_theo_theo115 667+#define T_characters_theo_theo116 668+#define T_characters_theo_theo117 669+#define T_characters_theo_theo118 670+#define T_characters_theo_theo119 671+#define T_characters_theo_theo120 672+#define T_characters_theo_theo121 673+#define T_characters_theo_theo122 674+#define T_characters_theo_theo123 675+#define T_characters_theo_theo124 676+#define T_characters_theo_theo125 677+#define T_characters_theo_theo126 678+#define T_characters_theo_theo127 679+#define T_characters_theo_theo128 680+#define T_characters_theo_theo129 681+#define T_characters_theo_theo130 682+#define T_characters_theo_theo131 683+#define T_characters_theo_theo132 684+#define T_characters_theo_theo133 685+#define T_characters_theo_theo134 686+#define T_characters_theo_theo135 687+#define T_characters_theo_theo136 688+#define T_characters_theo_theo137 689+#define T_characters_theo_theo138 690+#define T_characters_theo_theo139 691+#define T_characters_theo_theo140 692+#define T_characters_theo_theo141 693+#define T_characters_theo_theo142 694+#define T_characters_theo_theo143 695+#define T_characters_theo_theo144 696+#define T_characters_theo_theo145 697+#define T_characters_theo_theo146 698+#define T_characters_theo_theo147 699+#define T_characters_theo_theo148 700+#define T_characters_theo_theo149 701+#define T_characters_theo_theo150 702+#define T_characters_theo_theo151 703+#define T_characters_theo_theo152 704+#define T_characters_theo_theo153 705+#define T_characters_theo_theo154 706+#define T_characters_theo_theo155 707+#define T_characters_theo_theo156 708+#define T_characters_theo_theo157 709+#define T_characters_theo_theo158 710+#define T_characters_theo_theo159 711+#define T_characters_theo_theo160 712+#define T_characters_theo_theo161 713+#define T_characters_theo_theo162 714+#define T_characters_theo_theo163 715+#define T_characters_theo_theo164 716+#define T_characters_theo_theo165 717+#define T_characters_theo_theo166 718+#define T_characters_theo_theo167 719+#define T_characters_theo_theo168 720+#define T_characters_theo_theo169 721+#define T_characters_theo_theo170 722+#define T_characters_theo_theo171 723+#define T_characters_theo_theo172 724+#define T_characters_theo_theo173 725+#define T_characters_theo_theo174 726+#define T_characters_theo_theo175 727+#define T_characters_theo_theo176 728+#define T_characters_theo_theo177 729+#define T_characters_theo_theo178 730+#define T_characters_theo_theo179 731+#define T_characters_theo_theo180 732+#define T_characters_theo_theo181 733+#define T_characters_theo_theo182 734+#define T_characters_theo_theo183 735+#define T_characters_theo_theo184 736+#define T_characters_theo_theo185 737+#define T_characters_theo_theo186 738+#define T_characters_theo_theo187 739+#define T_characters_theo_theo188 740+#define T_characters_theo_run00 741+#define T_characters_theo_run01 742+#define T_characters_theo_run02 743+#define T_characters_theo_run03 744+#define T_characters_theo_run04 745+#define T_characters_theo_run05 746+#define T_characters_theo_run06 747+#define T_characters_theo_run07 748+#define T_characters_theo_tired00 749+#define T_characters_theo_tired01 750+#define T_characters_theo_tired02 751+#define T_characters_theo_tired03 752+#define T_characters_theo_tired04 753+#define T_characters_theo_tired05 754+#define T_characters_theo_alert00 755+#define T_characters_theo_alert01 756+#define T_characters_theo_alert02 757+#define T_characters_theo_alert03 758+#define T_characters_theo_alert04 759+#define T_characters_theo_alert05 760+#define T_characters_theo_alert06 761+#define T_characters_theo_alert07 762+#define T_characters_theo_alert08 763+#define T_scenery_memorial_memorial 764+#define T_objects_citysatellite_dish 765+#define T_objects_citysatellite_light 766+#define T_objects_citysatellite_computer 767+#define T_objects_citysatellite_computerscreen 768+#define T_objects_citysatellite_computerScreenNoise00 769+#define T_objects_citysatellite_computerScreenNoise01 770+#define T_objects_citysatellite_computerScreenNoise02 771+#define T_objects_citysatellite_computerscreenShine 772+#define T_collectables_heartGem_shape 773+#define T_collectables_heartGem_0_00 774+#define T_collectables_heartGem_0_01 775+#define T_collectables_heartGem_0_02 776+#define T_collectables_heartGem_0_03 777+#define T_collectables_heartGem_0_04 778+#define T_collectables_heartGem_0_05 779+#define T_collectables_heartGem_0_06 780+#define T_collectables_heartGem_0_07 781+#define T_collectables_heartGem_0_08 782+#define T_collectables_heartGem_0_09 783+#define T_collectables_heartGem_0_10 784+#define T_collectables_heartGem_0_11 785+#define T_collectables_heartGem_0_12 786+#define T_collectables_heartGem_0_13 787+#define T_collectables_heartGem_white00 788+#define T_collectables_heartGem_white01 789+#define T_collectables_heartGem_white02 790+#define T_collectables_heartGem_white03 791+#define T_collectables_heartGem_white04 792+#define T_collectables_heartGem_white05 793+#define T_collectables_heartGem_white06 794+#define T_collectables_heartGem_white07 795+#define T_collectables_heartGem_white08 796+#define T_collectables_heartGem_white09 797+#define T_collectables_heartGem_white10 798+#define T_collectables_heartGem_white11 799+#define T_collectables_heartGem_white12 800+#define T_collectables_heartGem_white13 801+#define T_collectables_heartGem_orb 802+#define T_objects_lookout_lookout00 803+#define T_objects_lookout_lookout01 804+#define T_objects_lookout_lookout02 805+#define T_objects_lookout_lookout03 806+#define T_objects_lookout_lookout04 807+#define T_objects_lookout_lookout05 808+#define T_objects_lookout_lookout06 809+#define T_objects_lookout_lookout07 810+#define T_objects_lookout_lookout08 811+#define T_objects_lookout_lookout09 812+#define T_objects_lookout_lookout10 813+#define T_objects_lookout_lookout11 814+#define T_objects_lookout_lookout12 815+#define T_objects_lookout_lookout13 816+#define T_objects_lookout_lookout14 817+#define T_objects_lookout_lookout15 818+#define T_objects_lookout_lookout16 819+#define T_objects_lookout_lookout17 820+#define T_objects_lookout_badeline00 821+#define T_objects_lookout_badeline01 822+#define T_objects_lookout_badeline02 823+#define T_objects_lookout_badeline03 824+#define T_objects_lookout_badeline04 825+#define T_objects_lookout_badeline05 826+#define T_objects_lookout_badeline06 827+#define T_objects_lookout_badeline07 828+#define T_objects_lookout_badeline08 829+#define T_objects_lookout_badeline09 830+#define T_objects_lookout_badeline10 831+#define T_objects_lookout_badeline11 832+#define T_objects_lookout_badeline12 833+#define T_objects_lookout_badeline13 834+#define T_objects_lookout_badeline14 835+#define T_objects_lookout_badeline15 836+#define T_objects_lookout_badeline16 837+#define T_objects_lookout_badeline17 838+#define T_objects_lookout_nobackpack00 839+#define T_objects_lookout_nobackpack01 840+#define T_objects_lookout_nobackpack02 841+#define T_objects_lookout_nobackpack03 842+#define T_objects_lookout_nobackpack04 843+#define T_objects_lookout_nobackpack05 844+#define T_objects_lookout_nobackpack06 845+#define T_objects_lookout_nobackpack07 846+#define T_objects_lookout_nobackpack08 847+#define T_objects_lookout_nobackpack09 848+#define T_objects_lookout_nobackpack10 849+#define T_objects_lookout_nobackpack11 850+#define T_objects_lookout_nobackpack12 851+#define T_objects_lookout_nobackpack13 852+#define T_objects_lookout_nobackpack14 853+#define T_objects_lookout_nobackpack15 854+#define T_objects_lookout_nobackpack16 855+#define T_objects_lookout_nobackpack17 856+#define T_collectables_heartGem_1_00 857+#define T_collectables_heartGem_1_01 858+#define T_collectables_heartGem_1_02 859+#define T_collectables_heartGem_1_03 860+#define T_collectables_heartGem_1_04 861+#define T_collectables_heartGem_1_05 862+#define T_collectables_heartGem_1_06 863+#define T_collectables_heartGem_1_07 864+#define T_collectables_heartGem_1_08 865+#define T_collectables_heartGem_1_09 866+#define T_collectables_heartGem_1_10 867+#define T_collectables_heartGem_1_11 868+#define T_collectables_heartGem_1_12 869+#define T_collectables_heartGem_1_13 870+#define T_collectables_heartGem_2_00 871+#define T_collectables_heartGem_2_01 872+#define T_collectables_heartGem_2_02 873+#define T_collectables_heartGem_2_03 874+#define T_collectables_heartGem_2_04 875+#define T_collectables_heartGem_2_05 876+#define T_collectables_heartGem_2_06 877+#define T_collectables_heartGem_2_07 878+#define T_collectables_heartGem_2_08 879+#define T_collectables_heartGem_2_09 880+#define T_collectables_heartGem_2_10 881+#define T_collectables_heartGem_2_11 882+#define T_collectables_heartGem_2_12 883+#define T_collectables_heartGem_2_13 884+#define T_collectables_heartGem_ghost00 885+#define T_collectables_heartGem_ghost01 886+#define T_collectables_heartGem_ghost02 887+#define T_collectables_heartGem_ghost03 888+#define T_collectables_heartGem_ghost04 889+#define T_collectables_heartGem_ghost05 890+#define T_collectables_heartGem_ghost06 891+#define T_collectables_heartGem_ghost07 892+#define T_collectables_heartGem_ghost08 893+#define T_collectables_heartGem_ghost09 894+#define T_collectables_heartGem_ghost10 895+#define T_collectables_heartGem_ghost11 896+#define T_collectables_heartGem_ghost12 897+#define T_collectables_heartGem_ghost13 898+#define T_objects_touchswitch_container 899+#define T_objects_touchswitch_icon00 900+#define T_objects_touchswitch_icon01 901+#define T_objects_touchswitch_icon02 902+#define T_objects_touchswitch_icon03 903+#define T_objects_touchswitch_icon04 904+#define T_objects_touchswitch_icon05 905+#define T_objects_switchgate_block 906+#define T_objects_switchgate_mirror 907+#define T_objects_switchgate_temple 908+#define T_objects_switchgate_stars 909+#define T_objects_switchgate_icon00 910+#define T_objects_switchgate_icon01 911+#define T_objects_switchgate_icon02 912+#define T_objects_switchgate_icon03 913+#define T_objects_switchgate_icon04 914+#define T_objects_switchgate_icon05 915+#define T_objects_hanginglamp 916+#define T_scenery_debris 917+#define T_scenery_fgdebris_rock_a00 918+#define T_scenery_fgdebris_rock_a01 919+#define T_scenery_fgdebris_rock_a02 920+#define T_scenery_fgdebris_rock_b00 921+#define T_scenery_fgdebris_rock_b01 922+#define T_cutscenes_payphone_phone00 923+#define T_cutscenes_payphone_phone01 924+#define T_cutscenes_payphone_phone02 925+#define T_cutscenes_payphone_phone03 926+#define T_cutscenes_payphone_phone04 927+#define T_cutscenes_payphone_phone05 928+#define T_cutscenes_payphone_phone06 929+#define T_cutscenes_payphone_phone07 930+#define T_cutscenes_payphone_phone08 931+#define T_cutscenes_payphone_phone09 932+#define T_cutscenes_payphone_phone10 933+#define T_cutscenes_payphone_phone11 934+#define T_cutscenes_payphone_phone12 935+#define T_cutscenes_payphone_phone13 936+#define T_cutscenes_payphone_phone14 937+#define T_cutscenes_payphone_phone15 938+#define T_cutscenes_payphone_phone16 939+#define T_cutscenes_payphone_phone17 940+#define T_cutscenes_payphone_phone18 941+#define T_cutscenes_payphone_phone19 942+#define T_cutscenes_payphone_phone20 943+#define T_cutscenes_payphone_phone21 944+#define T_cutscenes_payphone_phone22 945+#define T_cutscenes_payphone_phone23 946+#define T_cutscenes_payphone_phone24 947+#define T_cutscenes_payphone_phone25 948+#define T_cutscenes_payphone_phone26 949+#define T_cutscenes_payphone_phone27 950+#define T_cutscenes_payphone_phone28 951+#define T_cutscenes_payphone_phone29 952+#define T_cutscenes_payphone_phone30 953+#define T_cutscenes_payphone_phone31 954+#define T_cutscenes_payphone_phone32 955+#define T_cutscenes_payphone_phone33 956+#define T_cutscenes_payphone_phone34 957+#define T_cutscenes_payphone_phone35 958+#define T_cutscenes_payphone_phone36 959+#define T_cutscenes_payphone_phone37 960+#define T_cutscenes_payphone_phone38 961+#define T_cutscenes_payphone_phone39 962+#define T_cutscenes_payphone_phone40 963+#define T_cutscenes_payphone_phone41 964+#define T_cutscenes_payphone_phone42 965+#define T_cutscenes_payphone_phone43 966+#define T_cutscenes_payphone_phone44 967+#define T_cutscenes_payphone_phone45 968+#define T_cutscenes_payphone_phone46 969+#define T_cutscenes_payphone_phone47 970+#define T_cutscenes_payphone_phone48 971+#define T_cutscenes_payphone_phone49 972+#define T_cutscenes_payphone_phone50 973+#define T_cutscenes_payphone_phone51 974+#define T_cutscenes_payphone_phone52 975+#define T_cutscenes_payphone_phone53 976+#define T_cutscenes_payphone_phone54 977+#define T_cutscenes_payphone_phone55 978+#define T_cutscenes_payphone_phone56 979+#define T_cutscenes_payphone_phone57 980+#define T_cutscenes_payphone_phone58 981+#define T_cutscenes_payphone_phone59 982+#define T_cutscenes_payphone_phone60 983+#define T_cutscenes_payphone_phone61 984+#define T_cutscenes_payphone_phone62 985+#define T_cutscenes_payphone_phone63 986+#define T_cutscenes_payphone_phone64 987+#define T_cutscenes_payphone_phone65 988+#define T_cutscenes_payphone_phone66 989+#define T_cutscenes_payphone_phone67 990+#define T_cutscenes_payphone_phone68 991+#define T_cutscenes_payphone_phone69 992+#define T_cutscenes_payphone_phone70 993+#define T_cutscenes_payphone_phone71 994+#define T_cutscenes_payphone_phone72 995+#define T_cutscenes_payphone_phone73 996+#define T_cutscenes_payphone_phone74 997+#define T_cutscenes_payphone_phone75 998+#define T_cutscenes_payphone_phone76 999+#define T_cutscenes_payphone_phone77 1000+#define T_cutscenes_payphone_phone78 1001+#define T_cutscenes_payphone_phone79 1002+#define T_cutscenes_payphone_phone80 1003+#define T_cutscenes_payphone_phone81 1004+#define T_cutscenes_payphone_phone82 1005+#define T_cutscenes_payphone_phone83 1006+#define T_cutscenes_payphone_phone84 1007+#define T_cutscenes_payphone_phone85 1008+#define T_cutscenes_payphone_phone86 1009+#define T_cutscenes_payphone_phone87 1010+#define T_cutscenes_payphone_blink 1011+#define T_objects_mirror_glassbg 1012+#define T_objects_mirror_glassbreak00 1013+#define T_objects_mirror_glassbreak01 1014+#define T_objects_mirror_glassbreak02 1015+#define T_objects_mirror_glassbreak03 1016+#define T_objects_mirror_glassbreak04 1017+#define T_objects_mirror_glassbreak05 1018+#define T_objects_mirror_glassbreak06 1019+#define T_objects_mirror_glassbreak07 1020+#define T_objects_mirror_glassbreak08 1021+#define T_objects_mirror_glassbreak09 1022+#define T_objects_mirror_frame 1023+#define T_objects_mirror_glassfg 1024+#define T_scenery_memorial_floatytext00 1025+#define T_scenery_memorial_floatytext01 1026+#define T_scenery_memorial_floatytext02 1027+#define T_danger_blade00 1028+#define T_danger_blade01 1029+#define T_danger_blade02 1030+#define T_danger_blade03 1031+#define T_danger_blade04 1032+#define T_danger_blade05 1033+#define T_objects_door_door00 1034+#define T_objects_door_door01 1035+#define T_objects_door_door02 1036+#define T_objects_door_door03 1037+#define T_objects_door_door04 1038+#define T_objects_resortclutter_red_00 1039+#define T_objects_resortclutter_red_01 1040+#define T_objects_resortclutter_red_02 1041+#define T_objects_resortclutter_red_03 1042+#define T_objects_resortclutter_red_04 1043+#define T_objects_resortclutter_red_05 1044+#define T_objects_resortclutter_red_06 1045+#define T_objects_resortclutter_red_07 1046+#define T_objects_resortclutter_red_08 1047+#define T_objects_resortclutter_red_09 1048+#define T_objects_resortclutter_red_10 1049+#define T_objects_resortclutter_red_11 1050+#define T_objects_resortclutter_red_12 1051+#define T_objects_resortclutter_red_13 1052+#define T_objects_resortclutter_red_14 1053+#define T_objects_resortclutter_yellow_00 1054+#define T_objects_resortclutter_yellow_01 1055+#define T_objects_resortclutter_yellow_02 1056+#define T_objects_resortclutter_yellow_03 1057+#define T_objects_resortclutter_yellow_04 1058+#define T_objects_resortclutter_yellow_05 1059+#define T_objects_resortclutter_yellow_06 1060+#define T_objects_resortclutter_yellow_07 1061+#define T_objects_resortclutter_yellow_08 1062+#define T_objects_resortclutter_yellow_09 1063+#define T_objects_resortclutter_yellow_10 1064+#define T_objects_resortclutter_yellow_11 1065+#define T_objects_resortclutter_yellow_12 1066+#define T_objects_resortclutter_yellow_13 1067+#define T_objects_resortclutter_yellow_14 1068+#define T_objects_resortLantern_holder 1069+#define T_objects_resortLantern_lantern00 1070+#define T_objects_resortLantern_lantern01 1071+#define T_objects_resortLantern_lantern02 1072+#define T_objects_resortclutter_green_00 1073+#define T_objects_resortclutter_green_01 1074+#define T_objects_resortclutter_green_02 1075+#define T_objects_resortclutter_green_03 1076+#define T_objects_resortclutter_green_04 1077+#define T_objects_resortclutter_green_05 1078+#define T_objects_resortclutter_green_06 1079+#define T_objects_resortclutter_green_07 1080+#define T_objects_resortclutter_green_08 1081+#define T_objects_resortclutter_green_09 1082+#define T_objects_resortclutter_green_10 1083+#define T_objects_resortclutter_green_11 1084+#define T_objects_resortclutter_green_12 1085+#define T_objects_resortclutter_green_13 1086+#define T_objects_resortclutter_green_14 1087+#define T_objects_mirror_resortframe 1088+#define T_characters_oshiro_oshiro00 1089+#define T_characters_oshiro_oshiro01 1090+#define T_characters_oshiro_oshiro02 1091+#define T_characters_oshiro_oshiro03 1092+#define T_characters_oshiro_oshiro04 1093+#define T_characters_oshiro_oshiro05 1094+#define T_characters_oshiro_oshiro06 1095+#define T_characters_oshiro_oshiro07 1096+#define T_characters_oshiro_oshiro08 1097+#define T_characters_oshiro_oshiro09 1098+#define T_characters_oshiro_oshiro10 1099+#define T_characters_oshiro_oshiro11 1100+#define T_characters_oshiro_oshiro12 1101+#define T_characters_oshiro_oshiro13 1102+#define T_characters_oshiro_oshiro14 1103+#define T_characters_oshiro_oshiro15 1104+#define T_characters_oshiro_oshiro16 1105+#define T_characters_oshiro_oshiro17 1106+#define T_characters_oshiro_oshiro18 1107+#define T_characters_oshiro_oshiro19 1108+#define T_characters_oshiro_oshiro20 1109+#define T_characters_oshiro_oshiro21 1110+#define T_characters_oshiro_oshiro22 1111+#define T_characters_oshiro_oshiro23 1112+#define T_characters_oshiro_oshiro24 1113+#define T_characters_oshiro_oshiro25 1114+#define T_characters_oshiro_oshiro26 1115+#define T_characters_oshiro_oshiro27 1116+#define T_characters_oshiro_oshiro28 1117+#define T_characters_oshiro_oshiro29 1118+#define T_characters_oshiro_oshiro30 1119+#define T_characters_oshiro_oshiro31 1120+#define T_characters_oshiro_oshiro32 1121+#define T_characters_oshiro_oshiro33 1122+#define T_characters_oshiro_oshiro34 1123+#define T_characters_oshiro_oshiro35 1124+#define T_characters_oshiro_oshiro36 1125+#define T_characters_oshiro_oshiro37 1126+#define T_characters_oshiro_oshiro38 1127+#define T_characters_oshiro_oshiro39 1128+#define T_characters_oshiro_oshiro40 1129+#define T_characters_oshiro_oshiro41 1130+#define T_characters_oshiro_oshiro42 1131+#define T_characters_oshiro_oshiro43 1132+#define T_characters_oshiro_oshiro44 1133+#define T_characters_oshiro_oshiro45 1134+#define T_characters_oshiro_oshiro46 1135+#define T_characters_oshiro_oshiro47 1136+#define T_characters_oshiro_oshiro48 1137+#define T_characters_oshiro_oshiro49 1138+#define T_characters_oshiro_oshiro50 1139+#define T_characters_oshiro_oshiro51 1140+#define T_characters_oshiro_oshiro52 1141+#define T_characters_oshiro_oshiro53 1142+#define T_characters_oshiro_oshiro54 1143+#define T_characters_oshiro_oshiro55 1144+#define T_characters_oshiro_oshiro56 1145+#define T_characters_oshiro_oshiro57 1146+#define T_characters_oshiro_oshiro58 1147+#define T_characters_oshiro_oshiro59 1148+#define T_characters_oshiro_oshiro60 1149+#define T_characters_oshiro_oshiro61 1150+#define T_characters_oshiro_oshiro62 1151+#define T_characters_oshiro_oshiro63 1152+#define T_characters_oshiro_oshiro64 1153+#define T_characters_oshiro_oshiro65 1154+#define T_characters_oshiro_oshiro66 1155+#define T_characters_oshiro_oshiro67 1156+#define T_characters_oshiro_oshiro68 1157+#define T_characters_oshiro_oshiro69 1158+#define T_characters_oshiro_oshiro70 1159+#define T_characters_oshiro_oshiro71 1160+#define T_characters_oshiro_oshiro72 1161+#define T_characters_oshiro_oshiro73 1162+#define T_characters_oshiro_oshiro74 1163+#define T_characters_oshiro_oshiro75 1164+#define T_characters_oshiro_oshiro76 1165+#define T_characters_oshiro_oshiro77 1166+#define T_characters_oshiro_oshiro78 1167+#define T_characters_oshiro_oshiro79 1168+#define T_characters_oshiro_oshiro80 1169+#define T_characters_oshiro_oshiro81 1170+#define T_characters_oshiro_oshiro82 1171+#define T_characters_oshiro_oshiro83 1172+#define T_characters_oshiro_oshiro84 1173+#define T_characters_oshiro_oshiro85 1174+#define T_characters_oshiro_oshiro86 1175+#define T_characters_oshiro_oshiro87 1176+#define T_characters_oshiro_oshiro88 1177+#define T_characters_oshiro_oshiro89 1178+#define T_characters_oshiro_oshiro90 1179+#define T_characters_oshiro_oshiro91 1180+#define T_characters_oshiro_oshiro92 1181+#define T_characters_oshiro_oshiro93 1182+#define T_characters_oshiro_oshiro94 1183+#define T_characters_oshiro_oshiro95 1184+#define T_characters_oshiro_oshiro96 1185+#define T_characters_oshiro_oshiro97 1186+#define T_characters_oshiro_oshiro98 1187+#define T_characters_oshiro_oshiro99 1188+#define T_characters_oshiro_oshiro100 1189+#define T_characters_oshiro_oshiro101 1190+#define T_characters_oshiro_sweep00 1191+#define T_characters_oshiro_sweep01 1192+#define T_characters_oshiro_sweep02 1193+#define T_characters_oshiro_sweep03 1194+#define T_characters_oshiro_sweep04 1195+#define T_characters_oshiro_sweep05 1196+#define T_characters_oshiro_sweep06 1197+#define T_characters_oshiro_sweep07 1198+#define T_characters_oshiro_sweep08 1199+#define T_characters_oshiro_sweep09 1200+#define T_characters_oshiro_sweep10 1201+#define T_characters_oshiro_sweep11 1202+#define T_characters_oshiro_sweep12 1203+#define T_characters_oshiro_sweep13 1204+#define T_characters_oshiro_sweep14 1205+#define T_characters_oshiro_sweep15 1206+#define T_characters_oshiro_sweep16 1207+#define T_characters_oshiro_sweep17 1208+#define T_characters_oshiro_sweep18 1209+#define T_objects_door_lockdoor00 1210+#define T_objects_door_lockdoor01 1211+#define T_objects_door_lockdoor02 1212+#define T_objects_door_lockdoor03 1213+#define T_objects_door_lockdoor04 1214+#define T_objects_door_lockdoor05 1215+#define T_objects_door_lockdoor06 1216+#define T_objects_door_lockdoor07 1217+#define T_objects_door_lockdoor08 1218+#define T_objects_door_lockdoor09 1219+#define T_objects_door_lockdoor10 1220+#define T_objects_door_lockdoor11 1221+#define T_objects_door_lockdoor12 1222+#define T_objects_door_lockdoor13 1223+#define T_objects_door_lockdoor14 1224+#define T_objects_door_lockdoor15 1225+#define T_objects_door_lockdoor16 1226+#define T_objects_door_lockdoor17 1227+#define T_objects_door_lockdoor18 1228+#define T_objects_woodPlatform_default 1229+#define T_objects_woodPlatform_cliffside 1230+#define T_collectables_key_idle00 1231+#define T_collectables_key_idle01 1232+#define T_collectables_key_idle02 1233+#define T_collectables_key_idle03 1234+#define T_collectables_key_idle04 1235+#define T_collectables_key_idle05 1236+#define T_collectables_key_idle06 1237+#define T_collectables_key_idle07 1238+#define T_collectables_key_idle08 1239+#define T_collectables_key_idle09 1240+#define T_collectables_key_idle10 1241+#define T_collectables_key_idle11 1242+#define T_collectables_key_idle12 1243+#define T_collectables_key_idle13 1244+#define T_collectables_key_enter00 1245+#define T_collectables_key_enter01 1246+#define T_collectables_key_enter02 1247+#define T_collectables_key_enter03 1248+#define T_collectables_key_enter04 1249+#define T_collectables_key_enter05 1250+#define T_collectables_key_enter06 1251+#define T_collectables_key_enter07 1252+#define T_danger_triggertentacle_wiggle_h00 1253+#define T_danger_triggertentacle_wiggle_h01 1254+#define T_danger_triggertentacle_wiggle_h02 1255+#define T_danger_triggertentacle_wiggle_h03 1256+#define T_danger_triggertentacle_wiggle_h04 1257+#define T_danger_triggertentacle_wiggle_h05 1258+#define T_danger_triggertentacle_wiggle_h06 1259+#define T_danger_triggertentacle_wiggle_h07 1260+#define T_danger_triggertentacle_wiggle_h08 1261+#define T_danger_dustcreature_base00 1262+#define T_danger_dustcreature_base01 1263+#define T_danger_dustcreature_base02 1264+#define T_danger_triggertentacle_wiggle_v00 1265+#define T_danger_triggertentacle_wiggle_v01 1266+#define T_danger_triggertentacle_wiggle_v02 1267+#define T_danger_triggertentacle_wiggle_v03 1268+#define T_danger_triggertentacle_wiggle_v04 1269+#define T_danger_triggertentacle_wiggle_v05 1270+#define T_danger_triggertentacle_wiggle_v06 1271+#define T_danger_triggertentacle_wiggle_v07 1272+#define T_danger_triggertentacle_wiggle_v08 1273+#define T_objects_door_trap00 1274+#define T_objects_door_trap01 1275+#define T_objects_door_trap02 1276+#define T_objects_door_trap03 1277+#define T_objects_door_trap04 1278+#define T_objects_door_trap05 1279+#define T_objects_door_trap06 1280+#define T_objects_door_trap07 1281+#define T_objects_door_metaldoor00 1282+#define T_objects_door_metaldoor01 1283+#define T_objects_door_metaldoor02 1284+#define T_objects_door_metaldoor03 1285+#define T_objects_door_metaldoor04 1286+#define T_objects_door_ghost_door00 1287+#define T_objects_door_ghost_door01 1288+#define T_objects_door_ghost_door02 1289+#define T_objects_door_ghost_door03 1290+#define T_objects_door_ghost_door04 1291+#define T_objects_door_ghost_door05 1292+#define T_objects_door_ghost_door06 1293+#define T_objects_door_ghost_door07 1294+#define T_objects_door_ghost_door08 1295+#define T_objects_door_ghost_door09 1296+#define T_objects_door_ghost_door10 1297+#define T_objects_door_ghost_door11 1298+#define T_objects_door_ghost_door12 1299+#define T_objects_door_ghost_door13 1300+#define T_objects_door_ghost_door14 1301+#define T_objects_door_ghost_door15 1302+#define T_objects_door_ghost_door16 1303+#define T_objects_door_ghost_door17 1304+#define T_objects_door_ghost_door18 1305+#define T_objects_door_ghost_door19 1306+#define T_objects_door_ghost_door20 1307+#define T_objects_door_ghost_door21 1308+#define T_objects_door_ghost_door22 1309+#define T_objects_door_ghost_door23 1310+#define T_objects_door_ghost_door24 1311+#define T_objects_door_ghost_door25 1312+#define T_objects_door_ghost_door26 1313+#define T_objects_door_ghost_door27 1314+#define T_objects_door_ghost_door28 1315+#define T_scenery_grate 1316+#define T_objects_resortclutter_clutter_button00 1317+#define T_objects_resortclutter_clutter_button01 1318+#define T_objects_resortclutter_clutter_button02 1319+#define T_objects_resortclutter_clutter_button03 1320+#define T_objects_resortclutter_clutter_button04 1321+#define T_objects_resortclutter_clutter_button05 1322+#define T_objects_resortclutter_clutter_button06 1323+#define T_objects_resortclutter_clutter_button07 1324+#define T_objects_resortclutter_clutter_button08 1325+#define T_objects_resortclutter_clutter_button09 1326+#define T_objects_resortclutter_clutter_button10 1327+#define T_objects_resortclutter_clutter_button11 1328+#define T_objects_resortclutter_clutter_button12 1329+#define T_objects_resortclutter_clutter_button13 1330+#define T_objects_resortclutter_clutter_button14 1331+#define T_objects_resortclutter_clutter_button15 1332+#define T_objects_resortclutter_clutter_button16 1333+#define T_objects_resortclutter_clutter_button17 1334+#define T_objects_resortclutter_clutter_button18 1335+#define T_objects_resortclutter_clutter_button19 1336+#define T_objects_resortclutter_clutter_button20 1337+#define T_objects_resortclutter_clutter_button21 1338+#define T_objects_resortclutter_clutter_button22 1339+#define T_objects_resortclutter_clutter_button23 1340+#define T_objects_resortclutter_clutter_button24 1341+#define T_objects_resortclutter_clutter_button25 1342+#define T_objects_resortclutter_clutter_button26 1343+#define T_objects_resortclutter_clutter_button27 1344+#define T_objects_resortclutter_icon_red 1345+#define T_objects_resortclutter_icon_green 1346+#define T_objects_resortclutter_icon_yellow 1347+#define T_objects_resortclutter_cabinet00 1348+#define T_objects_resortclutter_cabinet01 1349+#define T_objects_resortclutter_cabinet02 1350+#define T_objects_resortclutter_cabinet03 1351+#define T_objects_resortclutter_cabinet04 1352+#define T_objects_resortclutter_cabinet05 1353+#define T_objects_resortclutter_cabinet06 1354+#define T_objects_resortclutter_cabinet07 1355+#define T_objects_resortclutter_cabinet08 1356+#define T_objects_resortclutter_cabinet09 1357+#define T_objects_resortclutter_cabinet10 1358+#define T_objects_resortclutter_cabinet11 1359+#define T_objects_resortclutter_cabinet12 1360+#define T_objects_resortclutter_cabinet13 1361+#define T_objects_resortclutter_cabinet14 1362+#define T_objects_resortclutter_cabinet15 1363+#define T_objects_pico8Console 1364+#define T_characters_oshiro_boss00 1365+#define T_characters_oshiro_boss01 1366+#define T_characters_oshiro_boss02 1367+#define T_characters_oshiro_boss03 1368+#define T_characters_oshiro_boss04 1369+#define T_characters_oshiro_boss05 1370+#define T_characters_oshiro_boss06 1371+#define T_characters_oshiro_boss07 1372+#define T_characters_oshiro_boss08 1373+#define T_characters_oshiro_boss09 1374+#define T_characters_oshiro_boss10 1375+#define T_characters_oshiro_boss11 1376+#define T_characters_oshiro_boss12 1377+#define T_characters_oshiro_boss13 1378+#define T_characters_oshiro_boss14 1379+#define T_characters_oshiro_boss15 1380+#define T_characters_oshiro_boss16 1381+#define T_characters_oshiro_boss17 1382+#define T_characters_oshiro_boss18 1383+#define T_characters_oshiro_boss19 1384+#define T_characters_oshiro_boss20 1385+#define T_characters_oshiro_boss21 1386+#define T_characters_oshiro_boss22 1387+#define T_characters_oshiro_boss23 1388+#define T_characters_oshiro_boss24 1389+#define T_characters_oshiro_boss25 1390+#define T_characters_oshiro_boss26 1391+#define T_characters_oshiro_boss27 1392+#define T_characters_oshiro_boss28 1393+#define T_characters_oshiro_boss29 1394+#define T_characters_oshiro_boss30 1395+#define T_characters_oshiro_boss31 1396+#define T_characters_oshiro_boss32 1397+#define T_characters_oshiro_boss33 1398+#define T_characters_oshiro_boss34 1399+#define T_characters_oshiro_boss35 1400+#define T_characters_oshiro_boss36 1401+#define T_characters_oshiro_boss37 1402+#define T_characters_oshiro_boss38 1403+#define T_characters_oshiro_boss39 1404+#define T_characters_oshiro_boss40 1405+#define T_characters_oshiro_boss41 1406+#define T_characters_oshiro_boss42 1407+#define T_characters_oshiro_boss43 1408+#define T_characters_oshiro_boss44 1409+#define T_characters_oshiro_boss45 1410+#define T_characters_oshiro_boss46 1411+#define T_characters_oshiro_boss47 1412+#define T_characters_oshiro_boss48 1413+#define T_characters_oshiro_boss49 1414+#define T_characters_oshiro_boss50 1415+#define T_characters_oshiro_boss51 1416+#define T_characters_oshiro_boss52 1417+#define T_characters_oshiro_boss53 1418+#define T_characters_oshiro_boss54 1419+#define T_characters_oshiro_boss55 1420+#define T_characters_oshiro_boss56 1421+#define T_characters_oshiro_boss57 1422+#define T_characters_oshiro_boss58 1423+#define T_characters_oshiro_boss59 1424+#define T_characters_oshiro_boss60 1425+#define T_characters_oshiro_boss61 1426+#define T_characters_oshiro_boss62 1427+#define T_characters_oshiro_boss63 1428+#define T_characters_oshiro_boss64 1429+#define T_characters_oshiro_boss65 1430+#define T_characters_oshiro_boss66 1431+#define T_characters_oshiro_boss67 1432+#define T_characters_oshiro_boss68 1433+#define T_characters_oshiro_boss69 1434+#define T_characters_oshiro_boss70 1435+#define T_characters_oshiro_boss71 1436+#define T_characters_oshiro_boss72 1437+#define T_characters_oshiro_lightning00 1438+#define T_characters_oshiro_lightning01 1439+#define T_characters_oshiro_lightning02 1440+#define T_characters_oshiro_lightning03 1441+#define T_characters_oshiro_lightning04 1442+#define T_characters_oshiro_lightning05 1443+#define T_characters_oshiro_lightning06 1444+#define T_decals_3_resort_roofCenter 1445+#define T_decals_3_resort_roofCenter_b 1446+#define T_decals_3_resort_roofCenter_c 1447+#define T_decals_3_resort_roofCenter_d 1448+#define T_decals_3_resort_roofEdge 1449+#define T_decals_3_resort_roofEdge_d 1450+#define T_decals_3_resort_roofCenter_snapped_a 1451+#define T_decals_3_resort_roofCenter_snapped_b 1452+#define T_decals_3_resort_roofCenter_snapped_c 1453+#define T_objects_clouds_cloud00 1454+#define T_objects_clouds_cloudRemix00 1455+#define T_objects_booster_outline 1456+#define T_objects_booster_booster00 1457+#define T_objects_booster_booster01 1458+#define T_objects_booster_booster02 1459+#define T_objects_booster_booster03 1460+#define T_objects_booster_booster04 1461+#define T_objects_booster_booster05 1462+#define T_objects_booster_booster06 1463+#define T_objects_booster_booster07 1464+#define T_objects_booster_booster08 1465+#define T_objects_booster_booster09 1466+#define T_objects_booster_booster10 1467+#define T_objects_booster_booster11 1468+#define T_objects_booster_booster12 1469+#define T_objects_booster_booster13 1470+#define T_objects_booster_booster14 1471+#define T_objects_booster_booster15 1472+#define T_objects_booster_booster16 1473+#define T_objects_booster_booster17 1474+#define T_objects_booster_booster18 1475+#define T_objects_booster_booster19 1476+#define T_objects_booster_booster20 1477+#define T_objects_booster_booster21 1478+#define T_objects_booster_booster22 1479+#define T_objects_booster_booster23 1480+#define T_objects_booster_booster24 1481+#define T_objects_booster_booster25 1482+#define T_scenery_cliffside_flag00 1483+#define T_scenery_cliffside_flag01 1484+#define T_scenery_cliffside_flag02 1485+#define T_scenery_cliffside_flag03 1486+#define T_scenery_cliffside_flag04 1487+#define T_scenery_cliffside_flag05 1488+#define T_scenery_cliffside_flag06 1489+#define T_scenery_cliffside_flag07 1490+#define T_scenery_cliffside_flag08 1491+#define T_scenery_cliffside_flag09 1492+#define T_scenery_cliffside_flag10 1493+#define T_objects_clouds_fragile00 1494+#define T_objects_clouds_fragile01 1495+#define T_objects_clouds_fragile02 1496+#define T_objects_clouds_fragile03 1497+#define T_objects_clouds_fragile04 1498+#define T_objects_clouds_fragile05 1499+#define T_objects_clouds_fragile06 1500+#define T_objects_clouds_fragile07 1501+#define T_objects_clouds_fragile08 1502+#define T_objects_clouds_fragile09 1503+#define T_objects_clouds_fragile10 1504+#define T_objects_clouds_fragile11 1505+#define T_objects_clouds_fragile12 1506+#define T_objects_clouds_fragileRemix00 1507+#define T_objects_clouds_fragileRemix01 1508+#define T_objects_clouds_fragileRemix02 1509+#define T_objects_clouds_fragileRemix03 1510+#define T_objects_clouds_fragileRemix04 1511+#define T_objects_clouds_fragileRemix05 1512+#define T_objects_clouds_fragileRemix06 1513+#define T_objects_clouds_fragileRemix07 1514+#define T_objects_clouds_fragileRemix08 1515+#define T_objects_clouds_fragileRemix09 1516+#define T_objects_clouds_fragileRemix10 1517+#define T_objects_clouds_fragileRemix11 1518+#define T_objects_clouds_fragileRemix12 1519+#define T_objects_moveBlock_base 1520+#define T_objects_moveBlock_base_h 1521+#define T_objects_moveBlock_base_v 1522+#define T_objects_moveBlock_button 1523+#define T_objects_moveBlock_arrow00 1524+#define T_objects_moveBlock_arrow01 1525+#define T_objects_moveBlock_arrow02 1526+#define T_objects_moveBlock_arrow03 1527+#define T_objects_moveBlock_arrow04 1528+#define T_objects_moveBlock_arrow05 1529+#define T_objects_moveBlock_arrow06 1530+#define T_objects_moveBlock_arrow07 1531+#define T_objects_moveBlock_x 1532+#define T_objects_moveBlock_debris00 1533+#define T_objects_moveBlock_debris01 1534+#define T_objects_moveBlock_debris02 1535+#define T_objects_ridgeGate 1536+#define T_objects_whiteblock 1537+#define T_danger_snowball00 1538+#define T_danger_snowball01 1539+#define T_danger_snowball02 1540+#define T_danger_snowball03 1541+#define T_danger_snowball04 1542+#define T_danger_snowball05 1543+#define T_danger_snowball06 1544+#define T_danger_snowball07 1545+#define T_danger_snowball08 1546+#define T_danger_snowball09 1547+#define T_danger_snowball10 1548+#define T_danger_snowball11 1549+#define T_danger_snowball12 1550+#define T_danger_snowball13 1551+#define T_danger_snowball14 1552+#define T_danger_snowball15 1553+#define T_danger_snowball16 1554+#define T_bgs_04_bgCloudLoop 1555+#define T_bgs_04_bgCloud 1556+#define T_objects_flyFeather_idle00 1557+#define T_objects_flyFeather_idle01 1558+#define T_objects_flyFeather_idle02 1559+#define T_objects_flyFeather_idle03 1560+#define T_objects_flyFeather_idle04 1561+#define T_objects_flyFeather_idle05 1562+#define T_objects_flyFeather_idle06 1563+#define T_objects_flyFeather_idle07 1564+#define T_objects_flyFeather_idle08 1565+#define T_objects_flyFeather_idle09 1566+#define T_objects_flyFeather_idle10 1567+#define T_objects_flyFeather_idle11 1568+#define T_objects_flyFeather_idle12 1569+#define T_objects_flyFeather_idle13 1570+#define T_objects_flyFeather_idle14 1571+#define T_objects_flyFeather_idle15 1572+#define T_objects_flyFeather_idle16 1573+#define T_objects_flyFeather_idle17 1574+#define T_objects_flyFeather_idle18 1575+#define T_objects_flyFeather_idle19 1576+#define T_objects_flyFeather_idle20 1577+#define T_objects_flyFeather_flash00 1578+#define T_objects_flyFeather_flash01 1579+#define T_objects_flyFeather_flash02 1580+#define T_objects_flyFeather_flash03 1581+#define T_objects_flyFeather_flash04 1582+#define T_objects_flyFeather_flash05 1583+#define T_objects_flyFeather_flash06 1584+#define T_objects_flyFeather_flash07 1585+#define T_objects_flyFeather_flash08 1586+#define T_objects_flyFeather_flash09 1587+#define T_objects_flyFeather_flash10 1588+#define T_objects_flyFeather_flash11 1589+#define T_objects_flyFeather_flash12 1590+#define T_objects_flyFeather_flash13 1591+#define T_objects_flyFeather_flash14 1592+#define T_objects_flyFeather_flash15 1593+#define T_objects_flyFeather_flash16 1594+#define T_objects_flyFeather_flash17 1595+#define T_objects_flyFeather_flash18 1596+#define T_objects_flyFeather_flash19 1597+#define T_objects_flyFeather_flash20 1598+#define T_objects_gondola_front 1599+#define T_objects_gondola_pull00 1600+#define T_objects_gondola_pull01 1601+#define T_objects_gondola_pull02 1602+#define T_objects_gondola_pull03 1603+#define T_objects_gondola_pull04 1604+#define T_objects_gondola_pull05 1605+#define T_objects_gondola_pull06 1606+#define T_objects_gondola_top 1607+#define T_objects_gondola_back 1608+#define T_objects_gondola_cliffsideLeft 1609+#define T_objects_gondola_cliffsideRight 1610+#define T_objects_gondola_lever00 1611+#define T_objects_gondola_lever01 1612+#define T_objects_booster_boosterRed00 1613+#define T_objects_booster_boosterRed01 1614+#define T_objects_booster_boosterRed02 1615+#define T_objects_booster_boosterRed03 1616+#define T_objects_booster_boosterRed04 1617+#define T_objects_booster_boosterRed05 1618+#define T_objects_booster_boosterRed06 1619+#define T_objects_booster_boosterRed07 1620+#define T_objects_booster_boosterRed08 1621+#define T_objects_booster_boosterRed09 1622+#define T_objects_booster_boosterRed10 1623+#define T_objects_booster_boosterRed11 1624+#define T_objects_booster_boosterRed12 1625+#define T_objects_booster_boosterRed13 1626+#define T_objects_booster_boosterRed14 1627+#define T_objects_booster_boosterRed15 1628+#define T_objects_booster_boosterRed16 1629+#define T_objects_booster_boosterRed17 1630+#define T_objects_booster_boosterRed18 1631+#define T_objects_booster_boosterRed19 1632+#define T_objects_booster_boosterRed20 1633+#define T_objects_booster_boosterRed21 1634+#define T_objects_booster_boosterRed22 1635+#define T_objects_booster_boosterRed23 1636+#define T_objects_booster_boosterRed24 1637+#define T_objects_booster_boosterRed25 1638+#define T_objects_booster_boosterRed26 1639+#define T_objects_booster_boosterRed27 1640+#define T_objects_booster_boosterRed28 1641+#define T_objects_booster_boosterRed29 1642+#define T_objects_booster_boosterRed30 1643+#define T_objects_booster_boosterRed31 1644+#define T_objects_booster_boosterRed32 1645+#define T_objects_booster_boosterRed33 1646+#define T_objects_booster_boosterRed34 1647+#define T_objects_door_TempleDoor00 1648+#define T_objects_door_TempleDoor01 1649+#define T_objects_door_TempleDoor02 1650+#define T_objects_door_TempleDoor03 1651+#define T_objects_door_TempleDoor04 1652+#define T_objects_door_TempleDoor05 1653+#define T_objects_door_TempleDoor06 1654+#define T_objects_door_TempleDoor07 1655+#define T_objects_door_TempleDoor08 1656+#define T_objects_door_TempleDoor09 1657+#define T_objects_door_TempleDoor10 1658+#define T_objects_door_TempleDoor11 1659+#define T_objects_door_TempleDoor12 1660+#define T_objects_door_TempleDoor13 1661+#define T_objects_door_TempleDoor14 1662+#define T_objects_temple_dashButton00 1663+#define T_objects_temple_dashButton01 1664+#define T_objects_temple_dashButton02 1665+#define T_objects_temple_dashButton03 1666+#define T_objects_temple_dashButton04 1667+#define T_objects_temple_dashButton05 1668+#define T_objects_temple_dashButton06 1669+#define T_objects_temple_dashButton07 1670+#define T_objects_temple_dashButton08 1671+#define T_objects_temple_dashButton09 1672+#define T_objects_temple_dashButton10 1673+#define T_objects_temple_dashButton11 1674+#define T_objects_temple_dashButton12 1675+#define T_objects_temple_dashButton13 1676+#define T_objects_temple_dashButton14 1677+#define T_objects_temple_dashButton15 1678+#define T_objects_temple_dashButton16 1679+#define T_objects_temple_dashButton17 1680+#define T_objects_temple_dashButton18 1681+#define T_objects_temple_dashButton19 1682+#define T_objects_temple_dashButton20 1683+#define T_objects_temple_dashButton21 1684+#define T_objects_temple_dashButton22 1685+#define T_objects_temple_dashButton23 1686+#define T_objects_temple_dashButton24 1687+#define T_objects_temple_dashButton25 1688+#define T_objects_temple_dashButton26 1689+#define T_objects_temple_dashButton27 1690+#define T_objects_temple_torch00 1691+#define T_objects_temple_torch01 1692+#define T_objects_temple_torch02 1693+#define T_objects_temple_torch03 1694+#define T_objects_temple_torch04 1695+#define T_objects_temple_torch05 1696+#define T_objects_temple_torch06 1697+#define T_objects_temple_torch07 1698+#define T_objects_temple_torch08 1699+#define T_objects_temple_litTorch00 1700+#define T_objects_temple_litTorch01 1701+#define T_objects_temple_litTorch02 1702+#define T_objects_temple_litTorch03 1703+#define T_objects_temple_litTorch04 1704+#define T_objects_temple_litTorch05 1705+#define T_objects_temple_litTorch06 1706+#define T_objects_temple_litTorch07 1707+#define T_objects_temple_litTorch08 1708+#define T_objects_swapblock_block 1709+#define T_objects_swapblock_blockRed 1710+#define T_objects_swapblock_target 1711+#define T_objects_swapblock_pathH 1712+#define T_objects_swapblock_pathV 1713+#define T_objects_swapblock_midBlock00 1714+#define T_objects_swapblock_midBlock01 1715+#define T_objects_swapblock_midBlock02 1716+#define T_objects_swapblock_midBlock03 1717+#define T_objects_swapblock_midBlockRed00 1718+#define T_objects_swapblock_midBlockRed01 1719+#define T_objects_swapblock_midBlockRed02 1720+#define T_objects_swapblock_midBlockRed03 1721+#define T_scenery_templemirror 1722+#define T_characters_theo_phone 1723+#define T_objects_door_lockdoorTempleA00 1724+#define T_objects_door_lockdoorTempleA01 1725+#define T_objects_door_lockdoorTempleA02 1726+#define T_objects_door_lockdoorTempleA03 1727+#define T_objects_door_lockdoorTempleA04 1728+#define T_objects_door_lockdoorTempleA05 1729+#define T_objects_door_lockdoorTempleA06 1730+#define T_objects_door_lockdoorTempleA07 1731+#define T_objects_door_lockdoorTempleA08 1732+#define T_objects_door_lockdoorTempleA09 1733+#define T_objects_door_lockdoorTempleA10 1734+#define T_objects_door_lockdoorTempleA11 1735+#define T_objects_door_lockdoorTempleA12 1736+#define T_objects_door_lockdoorTempleA13 1737+#define T_objects_door_lockdoorTempleA14 1738+#define T_objects_door_lockdoorTempleA15 1739+#define T_objects_door_lockdoorTempleA16 1740+#define T_objects_door_lockdoorTempleA17 1741+#define T_objects_door_lockdoorTempleA18 1742+#define T_objects_temple_portal_portalframe 1743+#define T_objects_temple_portal_surface 1744+#define T_objects_temple_portal_portalcurtain00 1745+#define T_objects_temple_portal_portalcurtain01 1746+#define T_objects_temple_portal_portalcurtain02 1747+#define T_objects_temple_portal_portalcurtain03 1748+#define T_objects_temple_portal_portalcurtain04 1749+#define T_objects_temple_portal_portalcurtain05 1750+#define T_objects_temple_portal_portalcurtain06 1751+#define T_objects_temple_portal_portalcurtain07 1752+#define T_objects_temple_portal_portaltorch00 1753+#define T_objects_temple_portal_portaltorch01 1754+#define T_objects_temple_portal_portaltorch02 1755+#define T_objects_temple_portal_portaltorch03 1756+#define T_objects_temple_portal_portaltorch04 1757+#define T_objects_temple_portal_portaltorch05 1758+#define T_objects_temple_portal_portaltorch06 1759+#define T_objects_temple_portal_portaltorch07 1760+#define T_objects_door_TempleDoorB00 1761+#define T_objects_door_TempleDoorB01 1762+#define T_objects_door_TempleDoorB02 1763+#define T_objects_door_TempleDoorB03 1764+#define T_objects_door_TempleDoorB04 1765+#define T_objects_door_TempleDoorB05 1766+#define T_objects_door_TempleDoorB06 1767+#define T_objects_door_TempleDoorB07 1768+#define T_objects_door_TempleDoorB08 1769+#define T_objects_door_TempleDoorB09 1770+#define T_objects_door_TempleDoorB10 1771+#define T_objects_door_TempleDoorB11 1772+#define T_objects_door_TempleDoorB12 1773+#define T_objects_door_TempleDoorB13 1774+#define T_objects_door_TempleDoorB14 1775+#define T_objects_temple_dashButtonMirror00 1776+#define T_objects_temple_dashButtonMirror01 1777+#define T_objects_temple_dashButtonMirror02 1778+#define T_objects_temple_dashButtonMirror03 1779+#define T_objects_temple_dashButtonMirror04 1780+#define T_objects_temple_dashButtonMirror05 1781+#define T_objects_temple_dashButtonMirror06 1782+#define T_objects_temple_dashButtonMirror07 1783+#define T_objects_temple_dashButtonMirror08 1784+#define T_objects_temple_dashButtonMirror09 1785+#define T_objects_temple_dashButtonMirror10 1786+#define T_objects_temple_dashButtonMirror11 1787+#define T_objects_temple_dashButtonMirror12 1788+#define T_objects_temple_dashButtonMirror13 1789+#define T_objects_temple_dashButtonMirror14 1790+#define T_objects_temple_dashButtonMirror15 1791+#define T_objects_temple_dashButtonMirror16 1792+#define T_objects_temple_dashButtonMirror17 1793+#define T_objects_temple_dashButtonMirror18 1794+#define T_objects_temple_dashButtonMirror19 1795+#define T_objects_temple_dashButtonMirror20 1796+#define T_objects_temple_dashButtonMirror21 1797+#define T_objects_temple_dashButtonMirror22 1798+#define T_objects_temple_dashButtonMirror23 1799+#define T_objects_temple_dashButtonMirror24 1800+#define T_objects_temple_dashButtonMirror25 1801+#define T_objects_temple_dashButtonMirror26 1802+#define T_objects_temple_dashButtonMirror27 1803+#define T_characters_monsters_predator00 1804+#define T_characters_monsters_predator01 1805+#define T_characters_monsters_predator02 1806+#define T_characters_monsters_predator03 1807+#define T_characters_monsters_predator04 1808+#define T_characters_monsters_predator05 1809+#define T_characters_monsters_predator06 1810+#define T_characters_monsters_predator07 1811+#define T_characters_monsters_predator08 1812+#define T_characters_monsters_predator09 1813+#define T_characters_monsters_predator10 1814+#define T_characters_monsters_predator11 1815+#define T_characters_monsters_predator12 1816+#define T_characters_monsters_predator13 1817+#define T_characters_monsters_predator14 1818+#define T_characters_monsters_predator15 1819+#define T_characters_monsters_predator16 1820+#define T_characters_monsters_predator17 1821+#define T_characters_monsters_predator18 1822+#define T_characters_monsters_predator19 1823+#define T_characters_monsters_predator20 1824+#define T_characters_monsters_predator21 1825+#define T_characters_monsters_predator22 1826+#define T_characters_monsters_predator23 1827+#define T_characters_monsters_predator24 1828+#define T_characters_monsters_predator25 1829+#define T_characters_monsters_predator26 1830+#define T_characters_monsters_predator27 1831+#define T_characters_monsters_predator28 1832+#define T_characters_monsters_predator29 1833+#define T_characters_monsters_predator30 1834+#define T_characters_monsters_predator31 1835+#define T_characters_monsters_predator32 1836+#define T_characters_monsters_predator33 1837+#define T_characters_monsters_predator34 1838+#define T_characters_monsters_predator35 1839+#define T_characters_monsters_predator36 1840+#define T_characters_monsters_predator37 1841+#define T_characters_monsters_predator38 1842+#define T_characters_monsters_predator39 1843+#define T_characters_monsters_predator40 1844+#define T_characters_monsters_predator41 1845+#define T_characters_monsters_predator42 1846+#define T_characters_monsters_predator43 1847+#define T_characters_monsters_predator44 1848+#define T_characters_monsters_predator45 1849+#define T_characters_monsters_predator46 1850+#define T_characters_monsters_predator47 1851+#define T_characters_monsters_predator48 1852+#define T_characters_monsters_predator49 1853+#define T_characters_monsters_predator50 1854+#define T_characters_monsters_predator51 1855+#define T_characters_monsters_predator52 1856+#define T_characters_monsters_predator53 1857+#define T_characters_monsters_predator54 1858+#define T_characters_monsters_predator55 1859+#define T_characters_monsters_predator56 1860+#define T_characters_monsters_predator57 1861+#define T_characters_monsters_predator58 1862+#define T_characters_monsters_predator59 1863+#define T_characters_monsters_predator60 1864+#define T_characters_monsters_predator61 1865+#define T_characters_monsters_predator62 1866+#define T_characters_monsters_predator63 1867+#define T_characters_monsters_predator64 1868+#define T_characters_monsters_predator65 1869+#define T_characters_monsters_predator66 1870+#define T_characters_monsters_predator67 1871+#define T_characters_monsters_predator68 1872+#define T_characters_monsters_predator69 1873+#define T_characters_monsters_predator70 1874+#define T_characters_monsters_predator71 1875+#define T_characters_monsters_predator72 1876+#define T_characters_monsters_predator73 1877+#define T_characters_monsters_predator74 1878+#define T_characters_monsters_predator75 1879+#define T_characters_monsters_predator76 1880+#define T_characters_monsters_predator77 1881+#define T_characters_monsters_predator78 1882+#define T_characters_monsters_predator79 1883+#define T_characters_monsters_predator80 1884+#define T_characters_monsters_predator81 1885+#define T_characters_monsters_predator82 1886+#define T_characters_monsters_predator83 1887+#define T_characters_monsters_predator84 1888+#define T_characters_monsters_predator85 1889+#define T_characters_monsters_predator86 1890+#define T_characters_monsters_predator87 1891+#define T_characters_monsters_predator88 1892+#define T_characters_monsters_predator89 1893+#define T_characters_monsters_predator90 1894+#define T_characters_monsters_predator91 1895+#define T_characters_monsters_predator92 1896+#define T_characters_monsters_predator93 1897+#define T_characters_monsters_predator94 1898+#define T_characters_monsters_predator95 1899+#define T_characters_monsters_predator96 1900+#define T_characters_monsters_predator97 1901+#define T_characters_monsters_predator98 1902+#define T_characters_monsters_predator99 1903+#define T_characters_monsters_predator100 1904+#define T_characters_monsters_predator101 1905+#define T_characters_monsters_predator102 1906+#define T_characters_monsters_predator103 1907+#define T_characters_monsters_predator104 1908+#define T_characters_monsters_predator105 1909+#define T_characters_monsters_predator106 1910+#define T_characters_monsters_predator107 1911+#define T_characters_monsters_predator108 1912+#define T_characters_monsters_predator109 1913+#define T_characters_monsters_predator110 1914+#define T_characters_monsters_predator111 1915+#define T_characters_monsters_predator112 1916+#define T_characters_monsters_predator113 1917+#define T_characters_monsters_predator114 1918+#define T_characters_monsters_predator115 1919+#define T_characters_monsters_predator116 1920+#define T_characters_monsters_predator117 1921+#define T_characters_monsters_predator118 1922+#define T_characters_monsters_predator119 1923+#define T_characters_monsters_predator120 1924+#define T_characters_monsters_predator121 1925+#define T_characters_monsters_predator122 1926+#define T_characters_monsters_predator123 1927+#define T_characters_monsters_predator124 1928+#define T_characters_monsters_predator125 1929+#define T_characters_monsters_predator126 1930+#define T_characters_monsters_predator127 1931+#define T_characters_monsters_predator128 1932+#define T_characters_monsters_predator129 1933+#define T_characters_monsters_predator130 1934+#define T_characters_monsters_predator131 1935+#define T_characters_monsters_predator132 1936+#define T_characters_monsters_predator133 1937+#define T_characters_monsters_predator134 1938+#define T_characters_monsters_predator135 1939+#define T_characters_monsters_predator136 1940+#define T_characters_monsters_predator137 1941+#define T_characters_monsters_predator138 1942+#define T_characters_monsters_predator139 1943+#define T_characters_monsters_predator140 1944+#define T_characters_monsters_predator141 1945+#define T_characters_monsters_predator142 1946+#define T_characters_monsters_predator143 1947+#define T_characters_monsters_predator144 1948+#define T_characters_monsters_predator145 1949+#define T_characters_monsters_predator146 1950+#define T_characters_monsters_predator147 1951+#define T_characters_monsters_predator148 1952+#define T_characters_monsters_predator149 1953+#define T_characters_monsters_predator150 1954+#define T_characters_monsters_predator151 1955+#define T_characters_monsters_rebirth00 1956+#define T_characters_monsters_rebirth01 1957+#define T_characters_monsters_rebirth02 1958+#define T_characters_monsters_rebirth03 1959+#define T_characters_monsters_rebirth04 1960+#define T_characters_monsters_rebirth05 1961+#define T_characters_monsters_rebirth06 1962+#define T_characters_monsters_rebirth07 1963+#define T_characters_monsters_rebirth08 1964+#define T_characters_monsters_rebirth09 1965+#define T_characters_monsters_rebirth10 1966+#define T_characters_monsters_Shockwave00 1967+#define T_characters_monsters_Shockwave01 1968+#define T_characters_monsters_Shockwave02 1969+#define T_characters_monsters_Shockwave03 1970+#define T_characters_monsters_Shockwave04 1971+#define T_characters_monsters_Shockwave05 1972+#define T_characters_monsters_Shockwave06 1973+#define T_characters_monsters_Shockwave07 1974+#define T_characters_monsters_Shockwave08 1975+#define T_characters_monsters_Shockwave09 1976+#define T_characters_monsters_Shockwave10 1977+#define T_characters_monsters_Shockwave11 1978+#define T_characters_monsters_Shockwave12 1979+#define T_characters_monsters_Shockwave13 1980+#define T_characters_monsters_Shockwave14 1981+#define T_characters_monsters_Shockwave15 1982+#define T_characters_monsters_Shockwave16 1983+#define T_characters_monsters_Shockwave17 1984+#define T_characters_monsters_Shockwave18 1985+#define T_objects_temple_breakBlock00 1986+#define T_objects_temple_breakBlock01 1987+#define T_objects_temple_breakBlock02 1988+#define T_objects_temple_breakBlock03 1989+#define T_objects_temple_breakBlock04 1990+#define T_objects_temple_breakBlock05 1991+#define T_objects_temple_breakBlock06 1992+#define T_objects_temple_breakBlock07 1993+#define T_objects_temple_breakBlock08 1994+#define T_objects_temple_breakBlock09 1995+#define T_debris_1 1996+#define T_objects_door_lockdoorTempleB00 1997+#define T_objects_door_lockdoorTempleB01 1998+#define T_objects_door_lockdoorTempleB02 1999+#define T_objects_door_lockdoorTempleB03 2000+#define T_objects_door_lockdoorTempleB04 2001+#define T_objects_door_lockdoorTempleB05 2002+#define T_objects_door_lockdoorTempleB06 2003+#define T_objects_door_lockdoorTempleB07 2004+#define T_objects_door_lockdoorTempleB08 2005+#define T_objects_door_lockdoorTempleB09 2006+#define T_objects_door_lockdoorTempleB10 2007+#define T_objects_door_lockdoorTempleB11 2008+#define T_objects_door_lockdoorTempleB12 2009+#define T_objects_door_lockdoorTempleB13 2010+#define T_objects_door_lockdoorTempleB14 2011+#define T_objects_door_lockdoorTempleB15 2012+#define T_objects_door_lockdoorTempleB16 2013+#define T_objects_door_lockdoorTempleB17 2014+#define T_objects_door_lockdoorTempleB18 2015+#define T_objects_door_TempleDoorC00 2016+#define T_objects_door_TempleDoorC01 2017+#define T_objects_door_TempleDoorC02 2018+#define T_objects_door_TempleDoorC03 2019+#define T_objects_door_TempleDoorC04 2020+#define T_objects_door_TempleDoorC05 2021+#define T_objects_door_TempleDoorC06 2022+#define T_objects_door_TempleDoorC07 2023+#define T_objects_door_TempleDoorC08 2024+#define T_objects_door_TempleDoorC09 2025+#define T_objects_door_TempleDoorC10 2026+#define T_objects_door_TempleDoorC11 2027+#define T_objects_door_TempleDoorC12 2028+#define T_objects_door_TempleDoorC13 2029+#define T_objects_door_TempleDoorC14 2030+#define T_characters_theoCrystal_pedestal 2031+#define T_characters_theoCrystal_idle00 2032+#define T_scenery_temple_eye_bg_eye 2033+#define T_scenery_temple_eye_bg_pupil 2034+#define T_scenery_temple_eye_fg_eye 2035+#define T_scenery_temple_eye_fg_pupil 2036+#define T_scenery_temple_eye_bg_lid00 2037+#define T_scenery_temple_eye_bg_lid01 2038+#define T_scenery_temple_eye_bg_lid02 2039+#define T_scenery_temple_eye_bg_lid03 2040+#define T_scenery_temple_eye_fg_lid00 2041+#define T_scenery_temple_eye_fg_lid01 2042+#define T_scenery_temple_eye_fg_lid02 2043+#define T_scenery_temple_eye_fg_lid03 2044+#define T_danger_templeeye_body00 2045+#define T_danger_templeeye_body01 2046+#define T_danger_templeeye_body02 2047+#define T_danger_templeeye_body03 2048+#define T_danger_templeeye_body04 2049+#define T_danger_templeeye_body05 2050+#define T_danger_templeeye_body06 2051+#define T_danger_templeeye_body07 2052+#define T_danger_templeeye_body08 2053+#define T_danger_templeeye_body09 2054+#define T_danger_templeeye_body10 2055+#define T_danger_templeeye_body11 2056+#define T_danger_templeeye_body12 2057+#define T_danger_templeeye_body13 2058+#define T_danger_templeeye_body14 2059+#define T_danger_templeeye_body15 2060+#define T_danger_templeeye_body16 2061+#define T_danger_templeeye_pupil 2062+#define T_characters_theoCrystal_shatter00 2063+#define T_characters_theoCrystal_shatter01 2064+#define T_characters_theoCrystal_shatter02 2065+#define T_characters_theoCrystal_shatter03 2066+#define T_characters_theoCrystal_shatter04 2067+#define T_characters_theoCrystal_shatter05 2068+#define T_characters_theoCrystal_shatter06 2069+#define T_characters_theoCrystal_shatter07 2070+#define T_characters_theoCrystal_shatter08 2071+#define T_characters_theoCrystal_shatter09 2072+#define T_characters_theoCrystal_shatter10 2073+#define T_characters_theoCrystal_shatter11 2074+#define T_characters_theoCrystal_shatter12 2075+#define T_characters_theoCrystal_shatter13 2076+#define T_characters_theoCrystal_shatter14 2077+#define T_characters_theoCrystal_shatter15 2078+#define T_characters_theoCrystal_shatter16 2079+#define T_scenery_temple_eye_bg_burst00 2080+#define T_scenery_temple_eye_bg_burst01 2081+#define T_scenery_temple_eye_bg_burst02 2082+#define T_scenery_temple_eye_bg_burst03 2083+#define T_scenery_temple_eye_bg_burst04 2084+#define T_scenery_temple_eye_bg_burst05 2085+#define T_scenery_temple_eye_bg_burst06 2086+#define T_scenery_temple_eye_bg_burst07 2087+#define T_scenery_temple_eye_bg_burst08 2088+#define T_scenery_temple_eye_fg_burst00 2089+#define T_scenery_temple_eye_fg_burst01 2090+#define T_scenery_temple_eye_fg_burst02 2091+#define T_scenery_temple_eye_fg_burst03 2092+#define T_scenery_temple_eye_fg_burst04 2093+#define T_scenery_temple_eye_fg_burst05 2094+#define T_scenery_temple_eye_fg_burst06 2095+#define T_scenery_temple_eye_fg_burst07 2096+#define T_scenery_temple_eye_fg_burst08 2097+#define T_objects_crushblock_block00 2098+#define T_objects_crushblock_block01 2099+#define T_objects_crushblock_block02 2100+#define T_objects_crushblock_block03 2101+#define T_objects_crushblock_lit_left 2102+#define T_objects_crushblock_lit_right 2103+#define T_objects_crushblock_lit_top 2104+#define T_objects_crushblock_lit_bottom 2105+#define T_objects_crushblock_idle_face 2106+#define T_objects_crushblock_hurt00 2107+#define T_objects_crushblock_hurt01 2108+#define T_objects_crushblock_hurt02 2109+#define T_objects_crushblock_hurt03 2110+#define T_objects_crushblock_hurt04 2111+#define T_objects_crushblock_hurt05 2112+#define T_objects_crushblock_hurt06 2113+#define T_objects_crushblock_hurt07 2114+#define T_objects_crushblock_hurt08 2115+#define T_objects_crushblock_hurt09 2116+#define T_objects_crushblock_hurt10 2117+#define T_objects_crushblock_hurt11 2118+#define T_objects_crushblock_hurt12 2119+#define T_objects_crushblock_hit00 2120+#define T_objects_crushblock_hit01 2121+#define T_objects_crushblock_hit02 2122+#define T_objects_crushblock_hit_left00 2123+#define T_objects_crushblock_hit_left01 2124+#define T_objects_crushblock_hit_right00 2125+#define T_objects_crushblock_hit_right01 2126+#define T_objects_crushblock_hit_up00 2127+#define T_objects_crushblock_hit_up01 2128+#define T_objects_crushblock_hit_down00 2129+#define T_objects_crushblock_hit_down01 2130+#define T_objects_crushblock_giant_block00 2131+#define T_objects_crushblock_giant_block01 2132+#define T_objects_crushblock_giant_block02 2133+#define T_objects_crushblock_giant_block03 2134+#define T_objects_crushblock_giant_block04 2135+#define T_objects_crushblock_giant_block05 2136+#define T_objects_crushblock_giant_block06 2137+#define T_objects_crushblock_giant_block07 2138+#define T_objects_crushblock_giant_block08 2139+#define T_objects_crushblock_giant_block09 2140+#define T_objects_crushblock_giant_block10 2141+#define T_objects_crushblock_giant_block11 2142+#define T_objects_crushblock_giant_block12 2143+#define T_objects_flyFeather_outline 2144+#define T_objects_reflectionHeart_statue 2145+#define T_objects_reflectionHeart_gem 2146+#define T_objects_reflectionHeart_torch00 2147+#define T_objects_reflectionHeart_torch01 2148+#define T_objects_reflectionHeart_torch02 2149+#define T_objects_reflectionHeart_torch03 2150+#define T_objects_reflectionHeart_torch04 2151+#define T_objects_reflectionHeart_torch05 2152+#define T_objects_reflectionHeart_torch06 2153+#define T_objects_reflectionHeart_hint00 2154+#define T_objects_reflectionHeart_hint01 2155+#define T_objects_reflectionHeart_hint02 2156+#define T_objects_reflectionHeart_hint03 2157+#define T_collectables_heartGem_3_00 2158+#define T_collectables_heartGem_3_01 2159+#define T_collectables_heartGem_3_02 2160+#define T_collectables_heartGem_3_03 2161+#define T_collectables_heartGem_3_04 2162+#define T_collectables_heartGem_3_05 2163+#define T_collectables_heartGem_3_06 2164+#define T_collectables_heartGem_3_07 2165+#define T_collectables_heartGem_3_08 2166+#define T_collectables_heartGem_3_09 2167+#define T_collectables_heartGem_3_10 2168+#define T_collectables_heartGem_3_11 2169+#define T_collectables_heartGem_3_12 2170+#define T_collectables_heartGem_3_13 2171+#define T_objects_Bumper_Idle00 2172+#define T_objects_Bumper_Idle01 2173+#define T_objects_Bumper_Idle02 2174+#define T_objects_Bumper_Idle03 2175+#define T_objects_Bumper_Idle04 2176+#define T_objects_Bumper_Idle05 2177+#define T_objects_Bumper_Idle06 2178+#define T_objects_Bumper_Idle07 2179+#define T_objects_Bumper_Idle08 2180+#define T_objects_Bumper_Idle09 2181+#define T_objects_Bumper_Idle10 2182+#define T_objects_Bumper_Idle11 2183+#define T_objects_Bumper_Idle12 2184+#define T_objects_Bumper_Idle13 2185+#define T_objects_Bumper_Idle14 2186+#define T_objects_Bumper_Idle15 2187+#define T_objects_Bumper_Idle16 2188+#define T_objects_Bumper_Idle17 2189+#define T_objects_Bumper_Idle18 2190+#define T_objects_Bumper_Idle19 2191+#define T_objects_Bumper_Idle20 2192+#define T_objects_Bumper_Idle21 2193+#define T_objects_Bumper_Idle22 2194+#define T_objects_Bumper_Idle23 2195+#define T_objects_Bumper_Idle24 2196+#define T_objects_Bumper_Idle25 2197+#define T_objects_Bumper_Idle26 2198+#define T_objects_Bumper_Idle27 2199+#define T_objects_Bumper_Idle28 2200+#define T_objects_Bumper_Idle29 2201+#define T_objects_Bumper_Idle30 2202+#define T_objects_Bumper_Idle31 2203+#define T_objects_Bumper_Idle32 2204+#define T_objects_Bumper_Idle33 2205+#define T_objects_Bumper_Idle34 2206+#define T_objects_Bumper_Idle35 2207+#define T_objects_Bumper_Idle36 2208+#define T_objects_Bumper_Idle37 2209+#define T_objects_Bumper_Idle38 2210+#define T_objects_Bumper_Idle39 2211+#define T_objects_Bumper_Idle40 2212+#define T_objects_Bumper_Idle41 2213+#define T_objects_Bumper_Idle42 2214+#define T_objects_Bumper_Idle43 2215+#define T_objects_Bumper_Idle44 2216+#define T_objects_Bumper_Evil00 2217+#define T_objects_Bumper_Evil01 2218+#define T_objects_Bumper_Evil02 2219+#define T_objects_Bumper_Evil03 2220+#define T_objects_Bumper_Evil04 2221+#define T_objects_Bumper_Evil05 2222+#define T_objects_Bumper_Evil06 2223+#define T_objects_Bumper_Evil07 2224+#define T_objects_Bumper_Evil08 2225+#define T_objects_Bumper_Evil09 2226+#define T_objects_Bumper_Evil10 2227+#define T_objects_Bumper_Evil11 2228+#define T_objects_Bumper_Evil12 2229+#define T_objects_Bumper_Evil13 2230+#define T_objects_Bumper_Evil14 2231+#define T_objects_Bumper_Evil15 2232+#define T_objects_Bumper_Evil16 2233+#define T_objects_Bumper_Evil17 2234+#define T_objects_Bumper_Evil18 2235+#define T_objects_Bumper_Evil19 2236+#define T_objects_Bumper_Evil20 2237+#define T_objects_Bumper_Evil21 2238+#define T_objects_Bumper_Evil22 2239+#define T_objects_Bumper_Evil23 2240+#define T_objects_Bumper_Evil24 2241+#define T_objects_Bumper_Evil25 2242+#define T_objects_Bumper_Evil26 2243+#define T_objects_Bumper_Evil27 2244+#define T_objects_Bumper_Evil28 2245+#define T_objects_Bumper_Evil29 2246+#define T_objects_Bumper_Evil30 2247+#define T_objects_Bumper_Evil31 2248+#define T_objects_Bumper_Evil32 2249+#define T_objects_Bumper_Evil33 2250+#define T_objects_Bumper_Evil34 2251+#define T_objects_Bumper_Evil35 2252+#define T_objects_Bumper_Evil36 2253+#define T_objects_Bumper_Evil37 2254+#define T_objects_Bumper_Evil38 2255+#define T_objects_Bumper_Evil39 2256+#define T_objects_Bumper_Evil40 2257+#define T_objects_Bumper_Evil41 2258+#define T_objects_Bumper_Evil42 2259+#define T_objects_badelineboost_idle00 2260+#define T_objects_badelineboost_idle01 2261+#define T_objects_badelineboost_idle02 2262+#define T_objects_badelineboost_idle03 2263+#define T_objects_badelineboost_idle04 2264+#define T_objects_badelineboost_idle05 2265+#define T_objects_badelineboost_idle06 2266+#define T_objects_badelineboost_idle07 2267+#define T_objects_badelineboost_idle08 2268+#define T_objects_badelineboost_idle09 2269+#define T_objects_badelineboost_idle10 2270+#define T_objects_badelineboost_idle11 2271+#define T_objects_badelineboost_idle12 2272+#define T_objects_badelineboost_idle13 2273+#define T_objects_badelineboost_idle14 2274+#define T_objects_badelineboost_idle15 2275+#define T_objects_badelineboost_idle16 2276+#define T_objects_badelineboost_idle17 2277+#define T_objects_badelineboost_idle18 2278+#define T_objects_badelineboost_idle19 2279+#define T_objects_badelineboost_idle20 2280+#define T_objects_badelineboost_idle21 2281+#define T_objects_badelineboost_idle22 2282+#define T_objects_badelineboost_idle23 2283+#define T_objects_badelineboost_idle24 2284+#define T_objects_badelineboost_idle25 2285+#define T_objects_badelineboost_stretch 2286+#define T_characters_badeline_idle00 2287+#define T_characters_badeline_idle01 2288+#define T_characters_badeline_idle02 2289+#define T_characters_badeline_idle03 2290+#define T_characters_badeline_idle04 2291+#define T_characters_badeline_idle05 2292+#define T_characters_badeline_idle06 2293+#define T_characters_badeline_idle07 2294+#define T_characters_badeline_idle08 2295+#define T_characters_badeline_lookUp00 2296+#define T_characters_badeline_lookUp01 2297+#define T_characters_badeline_lookUp02 2298+#define T_characters_badeline_lookUp03 2299+#define T_characters_badeline_lookUp04 2300+#define T_characters_badeline_lookUp05 2301+#define T_characters_badeline_lookUp06 2302+#define T_characters_badeline_lookUp07 2303+#define T_characters_badeline_walk00 2304+#define T_characters_badeline_walk01 2305+#define T_characters_badeline_walk02 2306+#define T_characters_badeline_walk03 2307+#define T_characters_badeline_walk04 2308+#define T_characters_badeline_walk05 2309+#define T_characters_badeline_walk06 2310+#define T_characters_badeline_walk07 2311+#define T_characters_badeline_walk08 2312+#define T_characters_badeline_walk09 2313+#define T_characters_badeline_walk10 2314+#define T_characters_badeline_walk11 2315+#define T_characters_badeline_push00 2316+#define T_characters_badeline_push01 2317+#define T_characters_badeline_push02 2318+#define T_characters_badeline_push03 2319+#define T_characters_badeline_push04 2320+#define T_characters_badeline_push05 2321+#define T_characters_badeline_push06 2322+#define T_characters_badeline_push07 2323+#define T_characters_badeline_push08 2324+#define T_characters_badeline_push09 2325+#define T_characters_badeline_push10 2326+#define T_characters_badeline_push11 2327+#define T_characters_badeline_push12 2328+#define T_characters_badeline_push13 2329+#define T_characters_badeline_push14 2330+#define T_characters_badeline_push15 2331+#define T_characters_badeline_runSlow00 2332+#define T_characters_badeline_runSlow01 2333+#define T_characters_badeline_runSlow02 2334+#define T_characters_badeline_runSlow03 2335+#define T_characters_badeline_runSlow04 2336+#define T_characters_badeline_runSlow05 2337+#define T_characters_badeline_runSlow06 2338+#define T_characters_badeline_runSlow07 2339+#define T_characters_badeline_runSlow08 2340+#define T_characters_badeline_runSlow09 2341+#define T_characters_badeline_runSlow10 2342+#define T_characters_badeline_runSlow11 2343+#define T_characters_badeline_runFast00 2344+#define T_characters_badeline_runFast01 2345+#define T_characters_badeline_runFast02 2346+#define T_characters_badeline_runFast03 2347+#define T_characters_badeline_runFast04 2348+#define T_characters_badeline_runFast05 2349+#define T_characters_badeline_runFast06 2350+#define T_characters_badeline_runFast07 2351+#define T_characters_badeline_runFast08 2352+#define T_characters_badeline_runFast09 2353+#define T_characters_badeline_runFast10 2354+#define T_characters_badeline_runFast11 2355+#define T_characters_badeline_runStumble00 2356+#define T_characters_badeline_runStumble01 2357+#define T_characters_badeline_runStumble02 2358+#define T_characters_badeline_runStumble03 2359+#define T_characters_badeline_runStumble04 2360+#define T_characters_badeline_runStumble05 2361+#define T_characters_badeline_runStumble06 2362+#define T_characters_badeline_runStumble07 2363+#define T_characters_badeline_runStumble08 2364+#define T_characters_badeline_runStumble09 2365+#define T_characters_badeline_runStumble10 2366+#define T_characters_badeline_runStumble11 2367+#define T_characters_badeline_dash00 2368+#define T_characters_badeline_dash01 2369+#define T_characters_badeline_dash02 2370+#define T_characters_badeline_dash03 2371+#define T_characters_badeline_dreamDash00 2372+#define T_characters_badeline_dreamDash01 2373+#define T_characters_badeline_dreamDash02 2374+#define T_characters_badeline_dreamDash03 2375+#define T_characters_badeline_dreamDash04 2376+#define T_characters_badeline_dreamDash05 2377+#define T_characters_badeline_dreamDash06 2378+#define T_characters_badeline_dreamDash07 2379+#define T_characters_badeline_dreamDash08 2380+#define T_characters_badeline_dreamDash09 2381+#define T_characters_badeline_dreamDash10 2382+#define T_characters_badeline_dreamDash11 2383+#define T_characters_badeline_dreamDash12 2384+#define T_characters_badeline_dreamDash13 2385+#define T_characters_badeline_dreamDash14 2386+#define T_characters_badeline_dreamDash15 2387+#define T_characters_badeline_dreamDash16 2388+#define T_characters_badeline_dreamDash17 2389+#define T_characters_badeline_dreamDash18 2390+#define T_characters_badeline_dreamDash19 2391+#define T_characters_badeline_dreamDash20 2392+#define T_characters_badeline_slide00 2393+#define T_characters_badeline_slide01 2394+#define T_characters_badeline_slide02 2395+#define T_characters_badeline_jumpSlow00 2396+#define T_characters_badeline_jumpSlow01 2397+#define T_characters_badeline_jumpSlow02 2398+#define T_characters_badeline_jumpSlow03 2399+#define T_characters_badeline_jumpFast00 2400+#define T_characters_badeline_jumpFast01 2401+#define T_characters_badeline_jumpFast02 2402+#define T_characters_badeline_jumpFast03 2403+#define T_characters_badeline_tired00 2404+#define T_characters_badeline_tired01 2405+#define T_characters_badeline_tired02 2406+#define T_characters_badeline_tired03 2407+#define T_characters_badeline_climb00 2408+#define T_characters_badeline_climb01 2409+#define T_characters_badeline_climb02 2410+#define T_characters_badeline_climb03 2411+#define T_characters_badeline_climb04 2412+#define T_characters_badeline_climb05 2413+#define T_characters_badeline_climb06 2414+#define T_characters_badeline_climb07 2415+#define T_characters_badeline_climb08 2416+#define T_characters_badeline_duck 2417+#define T_characters_badeline_edge00 2418+#define T_characters_badeline_edge01 2419+#define T_characters_badeline_edge02 2420+#define T_characters_badeline_edge03 2421+#define T_characters_badeline_edge04 2422+#define T_characters_badeline_edge05 2423+#define T_characters_badeline_edge06 2424+#define T_characters_badeline_edge07 2425+#define T_characters_badeline_edge08 2426+#define T_characters_badeline_edge09 2427+#define T_characters_badeline_edge10 2428+#define T_characters_badeline_edge11 2429+#define T_characters_badeline_edge12 2430+#define T_characters_badeline_edge13 2431+#define T_characters_badeline_sleep00 2432+#define T_characters_badeline_sleep01 2433+#define T_characters_badeline_sleep02 2434+#define T_characters_badeline_sleep03 2435+#define T_characters_badeline_sleep04 2436+#define T_characters_badeline_sleep05 2437+#define T_characters_badeline_sleep06 2438+#define T_characters_badeline_sleep07 2439+#define T_characters_badeline_sleep08 2440+#define T_characters_badeline_sleep09 2441+#define T_characters_badeline_sleep10 2442+#define T_characters_badeline_sleep11 2443+#define T_characters_badeline_sleep12 2444+#define T_characters_badeline_sleep13 2445+#define T_characters_badeline_sleep14 2446+#define T_characters_badeline_sleep15 2447+#define T_characters_badeline_sleep16 2448+#define T_characters_badeline_sleep17 2449+#define T_characters_badeline_sleep18 2450+#define T_characters_badeline_sleep19 2451+#define T_characters_badeline_sleep20 2452+#define T_characters_badeline_sleep21 2453+#define T_characters_badeline_sleep22 2454+#define T_characters_badeline_sleep23 2455+#define T_characters_badeline_faint00 2456+#define T_characters_badeline_faint01 2457+#define T_characters_badeline_faint02 2458+#define T_characters_badeline_faint03 2459+#define T_characters_badeline_faint04 2460+#define T_characters_badeline_faint05 2461+#define T_characters_badeline_faint06 2462+#define T_characters_badeline_faint07 2463+#define T_characters_badeline_faint08 2464+#define T_characters_badeline_faint09 2465+#define T_characters_badeline_faint10 2466+#define T_characters_badeline_flip00 2467+#define T_characters_badeline_flip01 2468+#define T_characters_badeline_flip02 2469+#define T_characters_badeline_flip03 2470+#define T_characters_badeline_flip04 2471+#define T_characters_badeline_flip05 2472+#define T_characters_badeline_flip06 2473+#define T_characters_badeline_flip07 2474+#define T_characters_badeline_flip08 2475+#define T_characters_badeline_dangling00 2476+#define T_characters_badeline_dangling01 2477+#define T_characters_badeline_dangling02 2478+#define T_characters_badeline_dangling03 2479+#define T_characters_badeline_dangling04 2480+#define T_characters_badeline_dangling05 2481+#define T_characters_badeline_dangling06 2482+#define T_characters_badeline_dangling07 2483+#define T_characters_badeline_dangling08 2484+#define T_characters_badeline_dangling09 2485+#define T_characters_badeline_spawn00 2486+#define T_characters_badeline_spawn01 2487+#define T_characters_badeline_spawn02 2488+#define T_characters_badeline_spawn03 2489+#define T_characters_badeline_spawn04 2490+#define T_characters_badeline_spawn05 2491+#define T_characters_badeline_spawn06 2492+#define T_characters_badeline_spawn07 2493+#define T_characters_badeline_spawn08 2494+#define T_characters_badeline_spawn09 2495+#define T_characters_badeline_spawn10 2496+#define T_characters_badeline_spawn11 2497+#define T_characters_badeline_spawn12 2498+#define T_characters_badeline_spawn13 2499+#define T_characters_badeline_spawn14 2500+#define T_characters_badeline_laugh00 2501+#define T_characters_badeline_laugh01 2502+#define T_characters_badeline_laugh02 2503+#define T_characters_badeline_laugh03 2504+#define T_characters_badeline_laugh04 2505+#define T_characters_badeline_laugh05 2506+#define T_characters_badeline_angry00 2507+#define T_characters_badeline_angry01 2508+#define T_characters_badeline_angry02 2509+#define T_characters_badeline_angry03 2510+#define T_characters_badeline_angry04 2511+#define T_characters_badeline_angry05 2512+#define T_characters_badeline_boost00 2513+#define T_characters_badeline_boost01 2514+#define T_characters_badeline_boost02 2515+#define T_characters_badeline_boost03 2516+#define T_characters_badeline_boost04 2517+#define T_characters_badeline_boost05 2518+#define T_characters_badeline_boost06 2519+#define T_characters_badeline_boost07 2520+#define T_characters_badeline_boost08 2521+#define T_characters_badeline_boost09 2522+#define T_characters_badeline_spin00 2523+#define T_characters_badeline_spin01 2524+#define T_characters_badeline_spin02 2525+#define T_characters_badeline_spin03 2526+#define T_characters_badeline_spin04 2527+#define T_characters_badeline_spin05 2528+#define T_characters_badeline_spin06 2529+#define T_characters_badeline_spin07 2530+#define T_characters_badeline_spin08 2531+#define T_characters_badeline_spin09 2532+#define T_characters_badeline_spin10 2533+#define T_characters_badeline_spin11 2534+#define T_characters_badeline_spin12 2535+#define T_characters_badeline_spin13 2536+#define T_characters_badeline_hug00 2537+#define T_characters_badelineBoss_boss00 2538+#define T_characters_badelineBoss_boss01 2539+#define T_characters_badelineBoss_boss02 2540+#define T_characters_badelineBoss_boss03 2541+#define T_characters_badelineBoss_boss04 2542+#define T_characters_badelineBoss_boss05 2543+#define T_characters_badelineBoss_boss06 2544+#define T_characters_badelineBoss_boss07 2545+#define T_characters_badelineBoss_boss08 2546+#define T_characters_badelineBoss_boss09 2547+#define T_characters_badelineBoss_boss10 2548+#define T_characters_badelineBoss_boss11 2549+#define T_characters_badelineBoss_boss12 2550+#define T_characters_badelineBoss_boss13 2551+#define T_characters_badelineBoss_boss14 2552+#define T_characters_badelineBoss_boss15 2553+#define T_characters_badelineBoss_boss16 2554+#define T_characters_badelineBoss_boss17 2555+#define T_characters_badelineBoss_boss18 2556+#define T_characters_badelineBoss_boss19 2557+#define T_characters_badelineBoss_boss20 2558+#define T_characters_badelineBoss_boss21 2559+#define T_characters_badelineBoss_boss22 2560+#define T_characters_badelineBoss_boss23 2561+#define T_characters_badelineBoss_boss24 2562+#define T_characters_badelineBoss_boss25 2563+#define T_characters_badelineBoss_boss26 2564+#define T_characters_badelineBoss_boss27 2565+#define T_characters_badelineBoss_boss28 2566+#define T_characters_badelineBoss_boss29 2567+#define T_characters_badelineBoss_boss30 2568+#define T_characters_badelineBoss_boss31 2569+#define T_characters_badelineBoss_boss32 2570+#define T_characters_badelineBoss_boss33 2571+#define T_characters_badelineBoss_boss34 2572+#define T_characters_badelineBoss_boss35 2573+#define T_characters_badelineBoss_boss36 2574+#define T_characters_badelineBoss_boss37 2575+#define T_characters_badelineBoss_boss38 2576+#define T_characters_badelineBoss_boss39 2577+#define T_characters_badelineBoss_boss40 2578+#define T_characters_badelineBoss_boss41 2579+#define T_characters_badelineBoss_boss42 2580+#define T_characters_badelineBoss_boss43 2581+#define T_characters_badelineBoss_boss44 2582+#define T_characters_badelineBoss_boss45 2583+#define T_characters_badelineBoss_boss46 2584+#define T_characters_badelineBoss_boss47 2585+#define T_characters_badelineBoss_boss48 2586+#define T_characters_badelineBoss_boss49 2587+#define T_characters_badelineBoss_boss50 2588+#define T_characters_badelineBoss_boss51 2589+#define T_characters_badelineBoss_boss52 2590+#define T_characters_badelineBoss_boss53 2591+#define T_characters_badelineBoss_boss54 2592+#define T_characters_badelineBoss_boss55 2593+#define T_characters_badelineBoss_boss56 2594+#define T_characters_badelineBoss_boss57 2595+#define T_characters_badelineBoss_boss58 2596+#define T_characters_badelineBoss_boss59 2597+#define T_characters_badelineBoss_boss60 2598+#define T_characters_badelineBoss_boss61 2599+#define T_characters_badelineBoss_boss62 2600+#define T_characters_badelineBoss_boss63 2601+#define T_characters_badelineBoss_boss64 2602+#define T_characters_badelineBoss_boss65 2603+#define T_characters_badelineBoss_boss66 2604+#define T_characters_badelineBoss_boss67 2605+#define T_characters_badelineBoss_boss68 2606+#define T_characters_badelineBoss_boss69 2607+#define T_characters_badelineBoss_boss70 2608+#define T_characters_badelineBoss_boss71 2609+#define T_characters_badelineBoss_boss72 2610+#define T_characters_badelineBoss_boss73 2611+#define T_characters_badelineBoss_boss74 2612+#define T_characters_badelineBoss_boss75 2613+#define T_characters_badelineBoss_boss76 2614+#define T_characters_badelineBoss_boss77 2615+#define T_characters_badelineBoss_boss78 2616+#define T_characters_badelineBoss_boss79 2617+#define T_characters_badelineBoss_boss80 2618+#define T_characters_badelineBoss_boss81 2619+#define T_characters_badelineBoss_boss82 2620+#define T_characters_badelineBoss_boss83 2621+#define T_characters_badelineBoss_boss84 2622+#define T_characters_badelineBoss_boss85 2623+#define T_characters_badelineBoss_boss86 2624+#define T_characters_badelineBoss_boss87 2625+#define T_characters_badelineBoss_boss88 2626+#define T_characters_badelineBoss_boss89 2627+#define T_characters_badelineBoss_boss90 2628+#define T_characters_badelineBoss_boss91 2629+#define T_characters_badelineBoss_boss92 2630+#define T_characters_badelineBoss_boss93 2631+#define T_characters_badelineBoss_boss94 2632+#define T_characters_badelineBoss_boss95 2633+#define T_characters_badelineBoss_boss96 2634+#define T_characters_badelineBoss_boss97 2635+#define T_characters_badelineBoss_boss98 2636+#define T_characters_badelineBoss_boss99 2637+#define T_characters_badelineBoss_boss100 2638+#define T_characters_badelineBoss_boss101 2639+#define T_characters_badelineBoss_boss102 2640+#define T_characters_badelineBoss_boss103 2641+#define T_characters_badelineBoss_boss104 2642+#define T_characters_badelineBoss_boss105 2643+#define T_characters_badelineBoss_boss106 2644+#define T_characters_badelineBoss_boss107 2645+#define T_characters_badelineBoss_boss108 2646+#define T_characters_badelineBoss_boss109 2647+#define T_characters_badelineBoss_boss110 2648+#define T_characters_badelineBoss_boss111 2649+#define T_characters_badelineBoss_boss112 2650+#define T_characters_badelineBoss_boss113 2651+#define T_characters_badelineBoss_boss114 2652+#define T_characters_badelineBoss_boss115 2653+#define T_characters_badelineBoss_boss116 2654+#define T_characters_badelineBoss_scared00 2655+#define T_characters_badelineBoss_scared01 2656+#define T_characters_badelineBoss_scared02 2657+#define T_characters_badelineBoss_scared03 2658+#define T_characters_badelineBoss_scared04 2659+#define T_characters_badelineBoss_scared05 2660+#define T_characters_badelineBoss_scared06 2661+#define T_characters_badelineBoss_scared07 2662+#define T_characters_badelineBoss_scared08 2663+#define T_characters_badelineBoss_scared09 2664+#define T_characters_badelineBoss_scared10 2665+#define T_characters_badelineBoss_scared11 2666+#define T_characters_badelineBoss_scared12 2667+#define T_characters_badelineBoss_scared13 2668+#define T_characters_badelineBoss_scared14 2669+#define T_characters_badelineBoss_scared15 2670+#define T_characters_badelineBoss_scared16 2671+#define T_characters_badelineBoss_scared17 2672+#define T_characters_badelineBoss_scared18 2673+#define T_characters_badelineBoss_scared19 2674+#define T_characters_badelineBoss_scared20 2675+#define T_characters_badelineBoss_scared21 2676+#define T_characters_badelineBoss_scared22 2677+#define T_characters_badelineBoss_scared23 2678+#define T_characters_badelineBoss_scared24 2679+#define T_characters_badelineBoss_scared25 2680+#define T_characters_badelineBoss_scared26 2681+#define T_characters_badelineBoss_scared27 2682+#define T_characters_badelineBoss_scared28 2683+#define T_characters_badelineBoss_scared29 2684+#define T_characters_badelineBoss_scared30 2685+#define T_characters_badelineBoss_scared31 2686+#define T_characters_badelineBoss_scared32 2687+#define T_characters_badelineBoss_scared33 2688+#define T_characters_badelineBoss_scared34 2689+#define T_characters_badelineBoss_scared35 2690+#define T_characters_badelineBoss_scared36 2691+#define T_characters_badelineBoss_charge00 2692+#define T_characters_badelineBoss_charge01 2693+#define T_characters_badelineBoss_charge02 2694+#define T_characters_badelineBoss_charge03 2695+#define T_characters_badelineBoss_charge04 2696+#define T_characters_badelineBoss_charge05 2697+#define T_characters_badelineBoss_charge06 2698+#define T_characters_badelineBoss_charge07 2699+#define T_characters_badelineBoss_charge08 2700+#define T_characters_badelineBoss_charge09 2701+#define T_characters_badelineBoss_charge10 2702+#define T_characters_badelineBoss_charge11 2703+#define T_characters_badelineBoss_charge12 2704+#define T_characters_badelineBoss_charge13 2705+#define T_characters_badelineBoss_charge14 2706+#define T_characters_badelineBoss_charge15 2707+#define T_characters_badelineBoss_charge16 2708+#define T_characters_badelineBoss_charge17 2709+#define T_characters_badelineBoss_charge18 2710+#define T_characters_badelineBoss_charge19 2711+#define T_characters_badelineBoss_charge20 2712+#define T_characters_badelineBoss_charge21 2713+#define T_characters_badelineBoss_charge22 2714+#define T_characters_badelineBoss_charge23 2715+#define T_characters_badelineBoss_charge24 2716+#define T_characters_badelineBoss_charge25 2717+#define T_characters_badelineBoss_charge26 2718+#define T_characters_badelineBoss_charge27 2719+#define T_characters_badelineBoss_charge28 2720+#define T_characters_badelineBoss_charge29 2721+#define T_characters_badelineBoss_charge30 2722+#define T_characters_badelineBoss_charge31 2723+#define T_characters_badelineBoss_charge32 2724+#define T_characters_badelineBoss_charge33 2725+#define T_characters_badelineBoss_charge34 2726+#define T_characters_badelineBoss_charge35 2727+#define T_characters_badelineBoss_charge36 2728+#define T_characters_badelineBoss_charge37 2729+#define T_characters_badelineBoss_charge38 2730+#define T_characters_badelineBoss_charge39 2731+#define T_characters_badelineBoss_charge40 2732+#define T_characters_badelineBoss_charge41 2733+#define T_characters_badelineBoss_charge42 2734+#define T_characters_badelineBoss_charge43 2735+#define T_characters_badelineBoss_charge44 2736+#define T_characters_badelineBoss_charge45 2737+#define T_characters_badelineBoss_hit00 2738+#define T_characters_badelineBoss_hit01 2739+#define T_characters_badelineBoss_hit02 2740+#define T_characters_badelineBoss_hit03 2741+#define T_characters_badelineBoss_hit04 2742+#define T_characters_badelineBoss_hit05 2743+#define T_characters_badelineBoss_hit06 2744+#define T_characters_badelineBoss_hit07 2745+#define T_characters_badelineBoss_hit08 2746+#define T_characters_badelineBoss_hit09 2747+#define T_characters_badelineBoss_hit10 2748+#define T_characters_badelineBoss_hit11 2749+#define T_characters_badelineBoss_hit12 2750+#define T_characters_badelineBoss_hit13 2751+#define T_characters_badelineBoss_hit14 2752+#define T_characters_badelineBoss_hit15 2753+#define T_characters_badelineBoss_hit16 2754+#define T_characters_badelineBoss_hit17 2755+#define T_characters_badelineBoss_hit18 2756+#define T_characters_badelineBoss_hit19 2757+#define T_characters_badelineBoss_projectile00 2758+#define T_characters_badelineBoss_projectile01 2759+#define T_characters_badelineBoss_projectile02 2760+#define T_characters_badelineBoss_projectile03 2761+#define T_characters_badelineBoss_projectile04 2762+#define T_characters_badelineBoss_projectile05 2763+#define T_characters_badelineBoss_projectile06 2764+#define T_characters_badelineBoss_projectile07 2765+#define T_characters_badelineBoss_projectile08 2766+#define T_characters_badelineBoss_projectile09 2767+#define T_characters_badelineBoss_projectile10 2768+#define T_characters_badelineBoss_projectile11 2769+#define T_characters_badelineBoss_projectile12 2770+#define T_characters_badelineBoss_beam00 2771+#define T_characters_badelineBoss_beam01 2772+#define T_characters_badelineBoss_beam02 2773+#define T_characters_badelineBoss_beam03 2774+#define T_characters_badelineBoss_beam04 2775+#define T_characters_badelineBoss_beam05 2776+#define T_characters_badelineBoss_beam06 2777+#define T_characters_badelineBoss_beam07 2778+#define T_characters_badelineBoss_beam08 2779+#define T_characters_badelineBoss_beam09 2780+#define T_characters_badelineBoss_beam10 2781+#define T_characters_badelineBoss_beam11 2782+#define T_characters_badelineBoss_beam12 2783+#define T_characters_badelineBoss_beam13 2784+#define T_characters_badelineBoss_beam14 2785+#define T_characters_badelineBoss_beam15 2786+#define T_characters_badelineBoss_beam16 2787+#define T_characters_badelineBoss_beam17 2788+#define T_characters_badelineBoss_beam18 2789+#define T_characters_badelineBoss_beam19 2790+#define T_characters_badelineBoss_beam20 2791+#define T_characters_badelineBoss_beam21 2792+#define T_characters_badelineBoss_beam22 2793+#define T_characters_badelineBoss_beam23 2794+#define T_characters_badelineBoss_beam24 2795+#define T_characters_badelineBoss_beam25 2796+#define T_characters_badelineBoss_beam26 2797+#define T_characters_badelineBoss_beam27 2798+#define T_characters_badelineBoss_beam28 2799+#define T_characters_badelineBoss_beam29 2800+#define T_characters_badelineBoss_beam30 2801+#define T_characters_badelineBoss_beam31 2802+#define T_characters_badelineBoss_beam32 2803+#define T_characters_badelineBoss_beam33 2804+#define T_characters_badelineBoss_beam34 2805+#define T_characters_badelineBoss_beam35 2806+#define T_characters_badelineBoss_beam36 2807+#define T_characters_badelineBoss_beamStart00 2808+#define T_characters_badelineBoss_beamStart01 2809+#define T_characters_badelineBoss_beamStart02 2810+#define T_characters_badelineBoss_beamStart03 2811+#define T_characters_badelineBoss_beamStart04 2812+#define T_tilesets_reflection 2813+#define T_tilesets_reflectionAlt 2814+#define T_debris_f 2815+#define T_characters_badelineBoss_calm_white 2816+#define T_characters_badeline_orb 2817+#define T_characters_player_levelUp_levelUp00 2818+#define T_characters_player_levelUp_levelUp01 2819+#define T_characters_player_levelUp_levelUp02 2820+#define T_characters_player_levelUp_levelUp03 2821+#define T_characters_player_levelUp_levelUp04 2822+#define T_characters_player_levelUp_levelUp05 2823+#define T_characters_player_levelUp_levelUp06 2824+#define T_characters_player_levelUp_levelUp07 2825+#define T_characters_player_levelUp_levelUp08 2826+#define T_characters_player_levelUp_levelUp09 2827+#define T_characters_player_levelUp_levelUp10 2828+#define T_characters_player_levelUp_levelUp11 2829+#define T_characters_player_levelUp_levelUp12 2830+#define T_characters_player_levelUp_levelUp13 2831+#define T_characters_player_levelUp_levelUp14 2832+#define T_characters_player_levelUp_levelUp15 2833+#define T_characters_player_levelUp_levelUp16 2834+#define T_characters_player_levelUp_levelUp17 2835+#define T_characters_player_levelUp_levelUp18 2836+#define T_characters_player_levelUp_levelUp19 2837+#define T_characters_player_levelUp_levelUp20 2838+#define T_characters_player_levelUp_levelUp21 2839+#define T_characters_player_levelUp_levelUp22 2840+#define T_characters_player_levelUp_levelUp23 2841+#define T_characters_player_levelUp_levelUp24 2842+#define T_characters_player_levelUp_levelUp25 2843+#define T_characters_player_levelUp_levelUp26 2844+#define T_scenery_fallplateau 2845+#define T_objects_starjumpBlock_corner00 2846+#define T_objects_starjumpBlock_corner01 2847+#define T_objects_starjumpBlock_corner02 2848+#define T_objects_starjumpBlock_corner03 2849+#define T_objects_starjumpBlock_edgeH00 2850+#define T_objects_starjumpBlock_edgeH01 2851+#define T_objects_starjumpBlock_edgeH02 2852+#define T_objects_starjumpBlock_edgeH03 2853+#define T_objects_starjumpBlock_edgeV00 2854+#define T_objects_starjumpBlock_edgeV01 2855+#define T_objects_starjumpBlock_edgeV02 2856+#define T_objects_starjumpBlock_edgeV03 2857+#define T_objects_starjumpBlock_leftrailing00 2858+#define T_objects_starjumpBlock_leftrailing01 2859+#define T_objects_starjumpBlock_leftrailing02 2860+#define T_objects_starjumpBlock_leftrailing03 2861+#define T_objects_starjumpBlock_leftrailing04 2862+#define T_objects_starjumpBlock_leftrailing05 2863+#define T_objects_starjumpBlock_leftrailing06 2864+#define T_objects_starjumpBlock_railing00 2865+#define T_objects_starjumpBlock_railing01 2866+#define T_objects_starjumpBlock_railing02 2867+#define T_objects_starjumpBlock_railing03 2868+#define T_objects_starjumpBlock_railing04 2869+#define T_objects_starjumpBlock_railing05 2870+#define T_objects_starjumpBlock_railing06 2871+#define T_objects_starjumpBlock_rightrailing00 2872+#define T_objects_starjumpBlock_rightrailing01 2873+#define T_objects_starjumpBlock_rightrailing02 2874+#define T_objects_starjumpBlock_rightrailing03 2875+#define T_objects_starjumpBlock_rightrailing04 2876+#define T_objects_starjumpBlock_rightrailing05 2877+#define T_objects_starjumpBlock_rightrailing06 2878+#define T_scenery_launch_slice00 2879+#define T_scenery_launch_slice01 2880+#define T_scenery_launch_slice02 2881+#define T_scenery_launch_cloud00 2882+#define T_scenery_launch_cloud01 2883+#define T_collectables_summitgems_0_gem00 2884+#define T_collectables_summitgems_0_gem01 2885+#define T_collectables_summitgems_0_gem02 2886+#define T_collectables_summitgems_0_gem03 2887+#define T_collectables_summitgems_0_gem04 2888+#define T_collectables_summitgems_0_gem05 2889+#define T_collectables_summitgems_0_gem06 2890+#define T_collectables_summitgems_0_gem07 2891+#define T_collectables_summitgems_0_gem08 2892+#define T_collectables_summitgems_0_gem09 2893+#define T_collectables_summitgems_0_gem10 2894+#define T_collectables_summitgems_0_gem11 2895+#define T_collectables_summitgems_0_gem12 2896+#define T_collectables_summitgems_0_gem13 2897+#define T_collectables_summitgems_1_gem00 2898+#define T_collectables_summitgems_1_gem01 2899+#define T_collectables_summitgems_1_gem02 2900+#define T_collectables_summitgems_1_gem03 2901+#define T_collectables_summitgems_1_gem04 2902+#define T_collectables_summitgems_1_gem05 2903+#define T_collectables_summitgems_1_gem06 2904+#define T_collectables_summitgems_1_gem07 2905+#define T_collectables_summitgems_1_gem08 2906+#define T_collectables_summitgems_1_gem09 2907+#define T_collectables_summitgems_1_gem10 2908+#define T_collectables_summitgems_1_gem11 2909+#define T_collectables_summitgems_1_gem12 2910+#define T_collectables_summitgems_1_gem13 2911+#define T_collectables_summitgems_2_gem00 2912+#define T_collectables_summitgems_2_gem01 2913+#define T_collectables_summitgems_2_gem02 2914+#define T_collectables_summitgems_2_gem03 2915+#define T_collectables_summitgems_2_gem04 2916+#define T_collectables_summitgems_2_gem05 2917+#define T_collectables_summitgems_2_gem06 2918+#define T_collectables_summitgems_2_gem07 2919+#define T_collectables_summitgems_2_gem08 2920+#define T_collectables_summitgems_2_gem09 2921+#define T_collectables_summitgems_2_gem10 2922+#define T_collectables_summitgems_2_gem11 2923+#define T_collectables_summitgems_2_gem12 2924+#define T_collectables_summitgems_2_gem13 2925+#define T_scenery_bridge_fixed 2926+#define T_characters_oshiro_broom 2927+#define T_decals_3_resort_brokenbox_a 2928+#define T_decals_3_resort_brokenbox_b 2929+#define T_decals_3_resort_brokenbox_c 2930+#define T_danger_dustcreature_center00 2931+#define T_danger_dustcreature_eyes00 2932+#define T_danger_dustcreature_eyes01 2933+#define T_danger_dustcreature_eyes02 2934+#define T_collectables_summitgems_3_gem00 2935+#define T_collectables_summitgems_3_gem01 2936+#define T_collectables_summitgems_3_gem02 2937+#define T_collectables_summitgems_3_gem03 2938+#define T_collectables_summitgems_3_gem04 2939+#define T_collectables_summitgems_3_gem05 2940+#define T_collectables_summitgems_3_gem06 2941+#define T_collectables_summitgems_3_gem07 2942+#define T_collectables_summitgems_3_gem08 2943+#define T_collectables_summitgems_3_gem09 2944+#define T_collectables_summitgems_3_gem10 2945+#define T_collectables_summitgems_3_gem11 2946+#define T_collectables_summitgems_3_gem12 2947+#define T_collectables_summitgems_3_gem13 2948+#define T_collectables_summitgems_4_gem00 2949+#define T_collectables_summitgems_4_gem01 2950+#define T_collectables_summitgems_4_gem02 2951+#define T_collectables_summitgems_4_gem03 2952+#define T_collectables_summitgems_4_gem04 2953+#define T_collectables_summitgems_4_gem05 2954+#define T_collectables_summitgems_4_gem06 2955+#define T_collectables_summitgems_4_gem07 2956+#define T_collectables_summitgems_4_gem08 2957+#define T_collectables_summitgems_4_gem09 2958+#define T_collectables_summitgems_4_gem10 2959+#define T_collectables_summitgems_4_gem11 2960+#define T_collectables_summitgems_4_gem12 2961+#define T_collectables_summitgems_4_gem13 2962+#define T_collectables_summitgems_5_gem00 2963+#define T_collectables_summitgems_5_gem01 2964+#define T_collectables_summitgems_5_gem02 2965+#define T_collectables_summitgems_5_gem03 2966+#define T_collectables_summitgems_5_gem04 2967+#define T_collectables_summitgems_5_gem05 2968+#define T_collectables_summitgems_5_gem06 2969+#define T_collectables_summitgems_5_gem07 2970+#define T_collectables_summitgems_5_gem08 2971+#define T_collectables_summitgems_5_gem09 2972+#define T_collectables_summitgems_5_gem10 2973+#define T_collectables_summitgems_5_gem11 2974+#define T_collectables_summitgems_5_gem12 2975+#define T_collectables_summitgems_5_gem13 2976+#define T_scenery_summitcheckpoints_base00 2977+#define T_scenery_summitcheckpoints_base01 2978+#define T_scenery_summitcheckpoints_base02 2979+#define T_scenery_summitcheckpoints_numberbg00 2980+#define T_scenery_summitcheckpoints_numberbg01 2981+#define T_scenery_summitcheckpoints_numberbg02 2982+#define T_scenery_summitcheckpoints_numberbg03 2983+#define T_scenery_summitcheckpoints_numberbg04 2984+#define T_scenery_summitcheckpoints_numberbg05 2985+#define T_scenery_summitcheckpoints_numberbg06 2986+#define T_scenery_summitcheckpoints_numberbg07 2987+#define T_scenery_summitcheckpoints_numberbg08 2988+#define T_scenery_summitcheckpoints_numberbg09 2989+#define T_scenery_summitcheckpoints_number00 2990+#define T_scenery_summitcheckpoints_number01 2991+#define T_scenery_summitcheckpoints_number02 2992+#define T_scenery_summitcheckpoints_number03 2993+#define T_scenery_summitcheckpoints_number04 2994+#define T_scenery_summitcheckpoints_number05 2995+#define T_scenery_summitcheckpoints_number06 2996+#define T_scenery_summitcheckpoints_number07 2997+#define T_scenery_summitcheckpoints_number08 2998+#define T_scenery_summitcheckpoints_number09 2999+#define T_collectables_summitgems_0_bg 3000+#define T_collectables_summitgems_1_bg 3001+#define T_collectables_summitgems_2_bg 3002+#define T_collectables_summitgems_3_bg 3003+#define T_collectables_summitgems_4_bg 3004+#define T_collectables_summitgems_5_bg 3005+#define T_scenery_summitclouds_cloud00 3006+#define T_scenery_summitclouds_cloud01 3007+#define T_objects_heartdoor_icon00 3008+#define T_objects_heartdoor_icon01 3009+#define T_objects_heartdoor_icon02 3010+#define T_objects_heartdoor_icon03 3011+#define T_objects_heartdoor_icon04 3012+#define T_objects_heartdoor_icon05 3013+#define T_objects_heartdoor_icon06 3014+#define T_objects_heartdoor_edge 3015+#define T_objects_heartdoor_top 3016+#define T_objects_heartdoor_mist 3017+#define T_objects_wallBooster_fireTop00 3018+#define T_objects_wallBooster_fireTop01 3019+#define T_objects_wallBooster_fireTop02 3020+#define T_objects_wallBooster_fireTop03 3021+#define T_objects_wallBooster_fireTop04 3022+#define T_objects_wallBooster_fireTop05 3023+#define T_objects_wallBooster_fireTop06 3024+#define T_objects_wallBooster_fireTop07 3025+#define T_objects_wallBooster_fireMid00 3026+#define T_objects_wallBooster_fireMid01 3027+#define T_objects_wallBooster_fireMid02 3028+#define T_objects_wallBooster_fireMid03 3029+#define T_objects_wallBooster_fireMid04 3030+#define T_objects_wallBooster_fireMid05 3031+#define T_objects_wallBooster_fireMid06 3032+#define T_objects_wallBooster_fireMid07 3033+#define T_objects_wallBooster_fireBottom00 3034+#define T_objects_wallBooster_fireBottom01 3035+#define T_objects_wallBooster_fireBottom02 3036+#define T_objects_wallBooster_fireBottom03 3037+#define T_objects_wallBooster_fireBottom04 3038+#define T_objects_wallBooster_fireBottom05 3039+#define T_objects_wallBooster_fireBottom06 3040+#define T_objects_wallBooster_fireBottom07 3041+#define T_objects_wallBooster_iceTop00 3042+#define T_objects_wallBooster_iceTop01 3043+#define T_objects_wallBooster_iceTop02 3044+#define T_objects_wallBooster_iceTop03 3045+#define T_objects_wallBooster_iceTop04 3046+#define T_objects_wallBooster_iceMid00 3047+#define T_objects_wallBooster_iceMid01 3048+#define T_objects_wallBooster_iceMid02 3049+#define T_objects_wallBooster_iceMid03 3050+#define T_objects_wallBooster_iceMid04 3051+#define T_objects_wallBooster_iceBottom00 3052+#define T_objects_wallBooster_iceBottom01 3053+#define T_objects_wallBooster_iceBottom02 3054+#define T_objects_wallBooster_iceBottom03 3055+#define T_objects_wallBooster_iceBottom04 3056+#define T_objects_fireball_fireball00 3057+#define T_objects_fireball_fireball01 3058+#define T_objects_fireball_fireball02 3059+#define T_objects_fireball_fireball03 3060+#define T_objects_fireball_fireball04 3061+#define T_objects_fireball_fireball05 3062+#define T_objects_fireball_fireball06 3063+#define T_objects_fireball_fireball07 3064+#define T_objects_fireball_fireball08 3065+#define T_objects_fireball_fireball09 3066+#define T_objects_fireball_fireball10 3067+#define T_objects_fireball_fireball11 3068+#define T_objects_fireball_fireball12 3069+#define T_objects_fireball_fireball13 3070+#define T_objects_fireball_fireball14 3071+#define T_objects_fireball_fireball15 3072+#define T_objects_fireball_fireball16 3073+#define T_objects_fireball_fireball17 3074+#define T_objects_fireball_fireball18 3075+#define T_objects_fireball_fireball19 3076+#define T_objects_fireball_fireball20 3077+#define T_objects_fireball_fireball21 3078+#define T_objects_fireball_fireball22 3079+#define T_objects_fireball_fireball23 3080+#define T_objects_fireball_fireball24 3081+#define T_objects_BumpBlockNew_fire00 3082+#define T_objects_BumpBlockNew_ice00 3083+#define T_objects_BumpBlockNew_fire_rubble00 3084+#define T_objects_BumpBlockNew_fire_rubble01 3085+#define T_objects_BumpBlockNew_fire_rubble02 3086+#define T_objects_BumpBlockNew_fire_rubble03 3087+#define T_objects_BumpBlockNew_ice_rubble00 3088+#define T_objects_BumpBlockNew_ice_rubble01 3089+#define T_objects_BumpBlockNew_ice_rubble02 3090+#define T_objects_BumpBlockNew_ice_rubble03 3091+#define T_objects_BumpBlockNew_fire_center00 3092+#define T_objects_BumpBlockNew_fire_center01 3093+#define T_objects_BumpBlockNew_fire_center02 3094+#define T_objects_BumpBlockNew_fire_center03 3095+#define T_objects_BumpBlockNew_fire_center04 3096+#define T_objects_BumpBlockNew_fire_center05 3097+#define T_objects_BumpBlockNew_fire_center06 3098+#define T_objects_BumpBlockNew_ice_center00 3099+#define T_objects_BumpBlockNew_ice_center01 3100+#define T_objects_BumpBlockNew_ice_center02 3101+#define T_objects_BumpBlockNew_ice_center03 3102+#define T_objects_BumpBlockNew_ice_center04 3103+#define T_objects_BumpBlockNew_ice_center05 3104+#define T_objects_BumpBlockNew_ice_center06 3105+#define T_objects_BumpBlockNew_ice_center07 3106+#define T_objects_BumpBlockNew_ice_center08 3107+#define T_objects_BumpBlockNew_ice_center09 3108+#define T_objects_BumpBlockNew_ice_center10 3109+#define T_objects_BumpBlockNew_ice_center11 3110+#define T_objects_coreFlipSwitch_switch00 3111+#define T_objects_coreFlipSwitch_switch01 3112+#define T_objects_coreFlipSwitch_switch02 3113+#define T_objects_coreFlipSwitch_switch03 3114+#define T_objects_coreFlipSwitch_switch04 3115+#define T_objects_coreFlipSwitch_switch05 3116+#define T_objects_coreFlipSwitch_switch06 3117+#define T_objects_coreFlipSwitch_switch07 3118+#define T_objects_coreFlipSwitch_switch08 3119+#define T_objects_coreFlipSwitch_switch09 3120+#define T_objects_coreFlipSwitch_switch10 3121+#define T_objects_coreFlipSwitch_switch11 3122+#define T_objects_coreFlipSwitch_switch12 3123+#define T_objects_coreFlipSwitch_switch13 3124+#define T_objects_coreFlipSwitch_switch14 3125+#define T_objects_coreFlipSwitch_switch15 3126+#define T_objects_coreFlipSwitch_switch16 3127+#define T_danger_lava_bubble_a00 3128+#define T_danger_lava_bubble_a01 3129+#define T_danger_lava_bubble_a02 3130+#define T_danger_lava_bubble_a03 3131+#define T_characters_player_idle_carry00 3132+#define T_characters_player_idle_carry01 3133+#define T_characters_player_idle_carry02 3134+#define T_characters_player_idle_carry03 3135+#define T_characters_player_idle_carry04 3136+#define T_characters_player_idle_carry05 3137+#define T_characters_player_idle_carry06 3138+#define T_characters_player_idle_carry07 3139+#define T_characters_player_idle_carry08 3140+#define T_characters_player_run_carry00 3141+#define T_characters_player_run_carry01 3142+#define T_characters_player_run_carry02 3143+#define T_characters_player_run_carry03 3144+#define T_characters_player_run_carry04 3145+#define T_characters_player_run_carry05 3146+#define T_characters_player_run_carry06 3147+#define T_characters_player_run_carry07 3148+#define T_characters_player_run_carry08 3149+#define T_characters_player_run_carry09 3150+#define T_characters_player_run_carry10 3151+#define T_characters_player_run_carry11 3152+#define T_characters_player_jump_carry00 3153+#define T_characters_player_jump_carry01 3154+#define T_characters_player_jump_carry02 3155+#define T_characters_player_jump_carry03 3156+#define T_characters_player_pickup00 3157+#define T_characters_player_pickup01 3158+#define T_characters_player_pickup02 3159+#define T_characters_player_pickup03 3160+#define T_characters_player_pickup04 3161+#define T_characters_player_throw00 3162+#define T_characters_player_throw01 3163+#define T_characters_player_throw02 3164+#define T_characters_player_throw03 3165+#define T_characters_player_idle00 3166+#define T_characters_player_idle01 3167+#define T_characters_player_idle02 3168+#define T_characters_player_idle03 3169+#define T_characters_player_idle04 3170+#define T_characters_player_idle05 3171+#define T_characters_player_idle06 3172+#define T_characters_player_idle07 3173+#define T_characters_player_idle08 3174+#define T_characters_player_idleA00 3175+#define T_characters_player_idleA01 3176+#define T_characters_player_idleA02 3177+#define T_characters_player_idleA03 3178+#define T_characters_player_idleA04 3179+#define T_characters_player_idleA05 3180+#define T_characters_player_idleA06 3181+#define T_characters_player_idleA07 3182+#define T_characters_player_idleA08 3183+#define T_characters_player_idleA09 3184+#define T_characters_player_idleA10 3185+#define T_characters_player_idleA11 3186+#define T_characters_player_idleB00 3187+#define T_characters_player_idleB01 3188+#define T_characters_player_idleB02 3189+#define T_characters_player_idleB03 3190+#define T_characters_player_idleB04 3191+#define T_characters_player_idleB05 3192+#define T_characters_player_idleB06 3193+#define T_characters_player_idleB07 3194+#define T_characters_player_idleB08 3195+#define T_characters_player_idleB09 3196+#define T_characters_player_idleB10 3197+#define T_characters_player_idleB11 3198+#define T_characters_player_idleB12 3199+#define T_characters_player_idleB13 3200+#define T_characters_player_idleB14 3201+#define T_characters_player_idleB15 3202+#define T_characters_player_idleB16 3203+#define T_characters_player_idleB17 3204+#define T_characters_player_idleB18 3205+#define T_characters_player_idleB19 3206+#define T_characters_player_idleB20 3207+#define T_characters_player_idleB21 3208+#define T_characters_player_idleB22 3209+#define T_characters_player_idleB23 3210+#define T_characters_player_idleC00 3211+#define T_characters_player_idleC01 3212+#define T_characters_player_idleC02 3213+#define T_characters_player_idleC03 3214+#define T_characters_player_idleC04 3215+#define T_characters_player_idleC05 3216+#define T_characters_player_idleC06 3217+#define T_characters_player_idleC07 3218+#define T_characters_player_idleC08 3219+#define T_characters_player_idleC09 3220+#define T_characters_player_idleC10 3221+#define T_characters_player_idleC11 3222+#define T_characters_player_lookUp00 3223+#define T_characters_player_lookUp01 3224+#define T_characters_player_lookUp02 3225+#define T_characters_player_lookUp03 3226+#define T_characters_player_lookUp04 3227+#define T_characters_player_lookUp05 3228+#define T_characters_player_lookUp06 3229+#define T_characters_player_lookUp07 3230+#define T_characters_player_walk00 3231+#define T_characters_player_walk01 3232+#define T_characters_player_walk02 3233+#define T_characters_player_walk03 3234+#define T_characters_player_walk04 3235+#define T_characters_player_walk05 3236+#define T_characters_player_walk06 3237+#define T_characters_player_walk07 3238+#define T_characters_player_walk08 3239+#define T_characters_player_walk09 3240+#define T_characters_player_walk10 3241+#define T_characters_player_walk11 3242+#define T_characters_player_push00 3243+#define T_characters_player_push01 3244+#define T_characters_player_push02 3245+#define T_characters_player_push03 3246+#define T_characters_player_push04 3247+#define T_characters_player_push05 3248+#define T_characters_player_push06 3249+#define T_characters_player_push07 3250+#define T_characters_player_push08 3251+#define T_characters_player_push09 3252+#define T_characters_player_push10 3253+#define T_characters_player_push11 3254+#define T_characters_player_push12 3255+#define T_characters_player_push13 3256+#define T_characters_player_push14 3257+#define T_characters_player_push15 3258+#define T_characters_player_runSlow00 3259+#define T_characters_player_runSlow01 3260+#define T_characters_player_runSlow02 3261+#define T_characters_player_runSlow03 3262+#define T_characters_player_runSlow04 3263+#define T_characters_player_runSlow05 3264+#define T_characters_player_runSlow06 3265+#define T_characters_player_runSlow07 3266+#define T_characters_player_runSlow08 3267+#define T_characters_player_runSlow09 3268+#define T_characters_player_runSlow10 3269+#define T_characters_player_runSlow11 3270+#define T_characters_player_runFast00 3271+#define T_characters_player_runFast01 3272+#define T_characters_player_runFast02 3273+#define T_characters_player_runFast03 3274+#define T_characters_player_runFast04 3275+#define T_characters_player_runFast05 3276+#define T_characters_player_runFast06 3277+#define T_characters_player_runFast07 3278+#define T_characters_player_runFast08 3279+#define T_characters_player_runFast09 3280+#define T_characters_player_runFast10 3281+#define T_characters_player_runFast11 3282+#define T_characters_player_runStumble00 3283+#define T_characters_player_runStumble01 3284+#define T_characters_player_runStumble02 3285+#define T_characters_player_runStumble03 3286+#define T_characters_player_runStumble04 3287+#define T_characters_player_runStumble05 3288+#define T_characters_player_runStumble06 3289+#define T_characters_player_runStumble07 3290+#define T_characters_player_runStumble08 3291+#define T_characters_player_runStumble09 3292+#define T_characters_player_runStumble10 3293+#define T_characters_player_runStumble11 3294+#define T_characters_player_run_wind00 3295+#define T_characters_player_run_wind01 3296+#define T_characters_player_run_wind02 3297+#define T_characters_player_run_wind03 3298+#define T_characters_player_run_wind04 3299+#define T_characters_player_run_wind05 3300+#define T_characters_player_run_wind06 3301+#define T_characters_player_run_wind07 3302+#define T_characters_player_run_wind08 3303+#define T_characters_player_run_wind09 3304+#define T_characters_player_run_wind10 3305+#define T_characters_player_run_wind11 3306+#define T_characters_player_dash00 3307+#define T_characters_player_dash01 3308+#define T_characters_player_dash02 3309+#define T_characters_player_dash03 3310+#define T_characters_player_dreamDash00 3311+#define T_characters_player_dreamDash01 3312+#define T_characters_player_dreamDash02 3313+#define T_characters_player_dreamDash03 3314+#define T_characters_player_dreamDash04 3315+#define T_characters_player_dreamDash05 3316+#define T_characters_player_dreamDash06 3317+#define T_characters_player_dreamDash07 3318+#define T_characters_player_dreamDash08 3319+#define T_characters_player_dreamDash09 3320+#define T_characters_player_dreamDash10 3321+#define T_characters_player_dreamDash11 3322+#define T_characters_player_dreamDash12 3323+#define T_characters_player_dreamDash13 3324+#define T_characters_player_dreamDash14 3325+#define T_characters_player_dreamDash15 3326+#define T_characters_player_dreamDash16 3327+#define T_characters_player_dreamDash17 3328+#define T_characters_player_dreamDash18 3329+#define T_characters_player_dreamDash19 3330+#define T_characters_player_dreamDash20 3331+#define T_characters_player_slide00 3332+#define T_characters_player_slide01 3333+#define T_characters_player_slide02 3334+#define T_characters_player_jumpSlow00 3335+#define T_characters_player_jumpSlow01 3336+#define T_characters_player_jumpSlow02 3337+#define T_characters_player_jumpSlow03 3338+#define T_characters_player_jumpFast00 3339+#define T_characters_player_jumpFast01 3340+#define T_characters_player_jumpFast02 3341+#define T_characters_player_jumpFast03 3342+#define T_characters_player_tired00 3343+#define T_characters_player_tired01 3344+#define T_characters_player_tired02 3345+#define T_characters_player_tired03 3346+#define T_characters_player_climb00 3347+#define T_characters_player_climb01 3348+#define T_characters_player_climb02 3349+#define T_characters_player_climb03 3350+#define T_characters_player_climb04 3351+#define T_characters_player_climb05 3352+#define T_characters_player_climb06 3353+#define T_characters_player_climb07 3354+#define T_characters_player_climb08 3355+#define T_characters_player_climb09 3356+#define T_characters_player_climb10 3357+#define T_characters_player_climb11 3358+#define T_characters_player_climb12 3359+#define T_characters_player_climb13 3360+#define T_characters_player_climb14 3361+#define T_characters_player_duck 3362+#define T_characters_player_fallPose00 3363+#define T_characters_player_fallPose01 3364+#define T_characters_player_fallPose02 3365+#define T_characters_player_fallPose03 3366+#define T_characters_player_fallPose04 3367+#define T_characters_player_fallPose05 3368+#define T_characters_player_fallPose06 3369+#define T_characters_player_fallPose07 3370+#define T_characters_player_fallPose08 3371+#define T_characters_player_fallPose09 3372+#define T_characters_player_fallPose10 3373+#define T_characters_player_edge00 3374+#define T_characters_player_edge01 3375+#define T_characters_player_edge02 3376+#define T_characters_player_edge03 3377+#define T_characters_player_edge04 3378+#define T_characters_player_edge05 3379+#define T_characters_player_edge06 3380+#define T_characters_player_edge07 3381+#define T_characters_player_edge08 3382+#define T_characters_player_edge09 3383+#define T_characters_player_edge10 3384+#define T_characters_player_edge11 3385+#define T_characters_player_edge12 3386+#define T_characters_player_edge13 3387+#define T_characters_player_edge_back00 3388+#define T_characters_player_edge_back01 3389+#define T_characters_player_edge_back02 3390+#define T_characters_player_edge_back03 3391+#define T_characters_player_edge_back04 3392+#define T_characters_player_edge_back05 3393+#define T_characters_player_edge_back06 3394+#define T_characters_player_edge_back07 3395+#define T_characters_player_edge_back08 3396+#define T_characters_player_edge_back09 3397+#define T_characters_player_edge_back10 3398+#define T_characters_player_edge_back11 3399+#define T_characters_player_edge_back12 3400+#define T_characters_player_edge_back13 3401+#define T_characters_player_faint00 3402+#define T_characters_player_faint01 3403+#define T_characters_player_faint02 3404+#define T_characters_player_faint03 3405+#define T_characters_player_faint04 3406+#define T_characters_player_faint05 3407+#define T_characters_player_faint06 3408+#define T_characters_player_faint07 3409+#define T_characters_player_faint08 3410+#define T_characters_player_faint09 3411+#define T_characters_player_faint10 3412+#define T_characters_player_flip00 3413+#define T_characters_player_flip01 3414+#define T_characters_player_flip02 3415+#define T_characters_player_flip03 3416+#define T_characters_player_flip04 3417+#define T_characters_player_flip05 3418+#define T_characters_player_flip06 3419+#define T_characters_player_flip07 3420+#define T_characters_player_flip08 3421+#define T_characters_player_dangling00 3422+#define T_characters_player_dangling01 3423+#define T_characters_player_dangling02 3424+#define T_characters_player_dangling03 3425+#define T_characters_player_dangling04 3426+#define T_characters_player_dangling05 3427+#define T_characters_player_dangling06 3428+#define T_characters_player_dangling07 3429+#define T_characters_player_dangling08 3430+#define T_characters_player_dangling09 3431+#define T_characters_player_death_h00 3432+#define T_characters_player_death_h01 3433+#define T_characters_player_death_h02 3434+#define T_characters_player_death_h03 3435+#define T_characters_player_death_h04 3436+#define T_characters_player_death_h05 3437+#define T_characters_player_death_h06 3438+#define T_characters_player_death_h07 3439+#define T_characters_player_death_h08 3440+#define T_characters_player_death_h09 3441+#define T_characters_player_death_h10 3442+#define T_characters_player_death_h11 3443+#define T_characters_player_death_h12 3444+#define T_characters_player_death_h13 3445+#define T_characters_player_death_h14 3446+#define T_characters_player_swim00 3447+#define T_characters_player_swim01 3448+#define T_characters_player_swim02 3449+#define T_characters_player_swim03 3450+#define T_characters_player_swim04 3451+#define T_characters_player_swim05 3452+#define T_characters_player_swim06 3453+#define T_characters_player_swim07 3454+#define T_characters_player_swim08 3455+#define T_characters_player_swim09 3456+#define T_characters_player_swim10 3457+#define T_characters_player_swim11 3458+#define T_characters_player_Swim12 3459+#define T_characters_player_Swim13 3460+#define T_characters_player_Swim14 3461+#define T_characters_player_Swim15 3462+#define T_characters_player_Swim16 3463+#define T_characters_player_Swim17 3464+#define T_characters_player_startStarFly00 3465+#define T_characters_player_startStarFly01 3466+#define T_characters_player_startStarFly02 3467+#define T_characters_player_startStarFly03 3468+#define T_characters_player_starFly00 3469+#define T_characters_player_bubble 3470+#define T_characters_player_fall00 3471+#define T_characters_player_fall01 3472+#define T_characters_player_fall02 3473+#define T_characters_player_fall03 3474+#define T_characters_player_fall04 3475+#define T_characters_player_fall05 3476+#define T_characters_player_fall06 3477+#define T_characters_player_fall07 3478+#define T_characters_player_bigfall00 3479+#define T_characters_player_bigfall01 3480+#define T_characters_player_bigfall02 3481+#define T_characters_player_bigfall03 3482+#define T_characters_player_bigfall04 3483+#define T_characters_player_bigfall05 3484+#define T_characters_player_bigfall06 3485+#define T_characters_player_bigfall07 3486+#define T_characters_player_bigfall08 3487+#define T_characters_player_bigfall09 3488+#define T_characters_player_bigfall10 3489+#define T_characters_player_sleep00 3490+#define T_characters_player_sleep01 3491+#define T_characters_player_sleep02 3492+#define T_characters_player_sleep03 3493+#define T_characters_player_sleep04 3494+#define T_characters_player_sleep05 3495+#define T_characters_player_sleep06 3496+#define T_characters_player_sleep07 3497+#define T_characters_player_sleep08 3498+#define T_characters_player_sleep09 3499+#define T_characters_player_sleep10 3500+#define T_characters_player_sleep11 3501+#define T_characters_player_sleep12 3502+#define T_characters_player_sleep13 3503+#define T_characters_player_sleep14 3504+#define T_characters_player_sleep15 3505+#define T_characters_player_sleep16 3506+#define T_characters_player_sleep17 3507+#define T_characters_player_sleep18 3508+#define T_characters_player_sleep19 3509+#define T_characters_player_sleep20 3510+#define T_characters_player_sleep21 3511+#define T_characters_player_sleep22 3512+#define T_characters_player_sleep23 3513+#define T_characters_player_wakeUp_00 3514+#define T_characters_player_wakeUp_01 3515+#define T_characters_player_wakeUp_02 3516+#define T_characters_player_wakeUp_03 3517+#define T_characters_player_wakeUp_04 3518+#define T_characters_player_wakeUp_05 3519+#define T_characters_player_wakeUp_06 3520+#define T_characters_player_wakeUp_07 3521+#define T_characters_player_wakeUp_08 3522+#define T_characters_player_wakeUp_09 3523+#define T_characters_player_wakeUp_10 3524+#define T_characters_player_wakeUp_11 3525+#define T_characters_player_wakeUp_12 3526+#define T_characters_player_wakeUp_13 3527+#define T_characters_player_wakeUp_14 3528+#define T_characters_player_halfWakeUp00 3529+#define T_characters_player_spin00 3530+#define T_characters_player_spin01 3531+#define T_characters_player_spin02 3532+#define T_characters_player_spin03 3533+#define T_characters_player_spin04 3534+#define T_characters_player_spin05 3535+#define T_characters_player_spin06 3536+#define T_characters_player_spin07 3537+#define T_characters_player_spin08 3538+#define T_characters_player_spin09 3539+#define T_characters_player_spin10 3540+#define T_characters_player_spin11 3541+#define T_characters_player_spin12 3542+#define T_characters_player_spin13 3543+#define T_characters_player_shaking00 3544+#define T_characters_player_hug00 3545+#define T_characters_player_starMorph00 3546+#define T_characters_player_starMorph01 3547+#define T_characters_player_starMorph02 3548+#define T_characters_player_starMorph03 3549+#define T_characters_player_starMorph04 3550+#define T_characters_player_starMorph05 3551+#define T_characters_player_starMorph06 3552+#define T_characters_player_starMorph07 3553+#define T_characters_player_starMorph08 3554+#define T_characters_player_starMorph09 3555+#define T_characters_player_starMorph10 3556+#define T_characters_player_starMorph11 3557+#define T_characters_player_starMorph12 3558+#define T_characters_player_starMorph13 3559+#define T_characters_player_starMorph14 3560+#define T_characters_player_starMorph15 3561+#define T_characters_player_starMorph16 3562+#define T_characters_player_starMorph17 3563+#define T_characters_player_walk_carry_theo00 3564+#define T_characters_player_walk_carry_theo01 3565+#define T_characters_player_walk_carry_theo02 3566+#define T_characters_player_walk_carry_theo03 3567+#define T_characters_player_walk_carry_theo04 3568+#define T_characters_player_walk_carry_theo05 3569+#define T_characters_player_walk_carry_theo06 3570+#define T_characters_player_walk_carry_theo07 3571+#define T_characters_player_walk_carry_theo08 3572+#define T_characters_player_walk_carry_theo09 3573+#define T_characters_player_walk_carry_theo10 3574+#define T_characters_player_walk_carry_theo11 3575+#define T_characters_player_walk_carry_theo12 3576+#define T_characters_player_walk_carry_theo13 3577+#define T_characters_player_walk_carry_theo14 3578+#define T_characters_player_walk_carry_theo15 3579+#define T_characters_player_walk_carry_theo16 3580+#define T_characters_player_walk_carry_theo17 3581+#define T_characters_player_walk_carry_theo18 3582+#define T_characters_player_tentacle_grab00 3583+#define T_characters_player_tentacle_grab01 3584+#define T_characters_player_tentacle_grab02 3585+#define T_characters_player_tentacle_grab03 3586+#define T_characters_player_tentacle_grab04 3587+#define T_characters_player_tentacle_grab05 3588+#define T_characters_player_tentacle_grab06 3589+#define T_characters_player_tentacle_grab07 3590+#define T_characters_player_tentacle_grab08 3591+#define T_characters_player_tentacle_grab09 3592+#define T_characters_player_tentacle_grab10 3593+#define T_characters_player_tentacle_grab11 3594+#define T_characters_player_tentacle_grab12 3595+#define T_characters_player_tentacle_grab13 3596+#define T_characters_player_tentacle_grab14 3597+#define T_characters_player_tentacle_grab15 3598+#define T_characters_player_tentacle_grab16 3599+#define T_characters_player_tentacle_grab17 3600+#define T_characters_player_tentacle_grab18 3601+#define T_characters_player_tentacle_grab19 3602+#define T_characters_player_tentacle_grab20 3603+#define T_characters_player_tentacle_grab21 3604+#define T_characters_player_tentacle_grab22 3605+#define T_characters_player_tentacle_grab23 3606+#define T_characters_player_tentacle_grab24 3607+#define T_characters_player_tentacle_grab25 3608+#define T_characters_player_sitDown00 3609+#define T_characters_player_sitDown01 3610+#define T_characters_player_sitDown02 3611+#define T_characters_player_sitDown03 3612+#define T_characters_player_sitDown04 3613+#define T_characters_player_sitDown05 3614+#define T_characters_player_sitDown06 3615+#define T_characters_player_sitDown07 3616+#define T_characters_player_sitDown08 3617+#define T_characters_player_sitDown09 3618+#define T_characters_player_sitDown10 3619+#define T_characters_player_sitDown11 3620+#define T_characters_player_sitDown12 3621+#define T_characters_player_sitDown13 3622+#define T_characters_player_sitDown14 3623+#define T_characters_player_sitDown15 3624+#define T_characters_player_launch00 3625+#define T_characters_player_launch01 3626+#define T_characters_player_launch02 3627+#define T_characters_player_launch03 3628+#define T_characters_player_launch04 3629+#define T_characters_player_launch05 3630+#define T_characters_player_launch06 3631+#define T_characters_player_launch07 3632+#define T_characters_player_launchRecover00 3633+#define T_characters_player_launchRecover01 3634+#define T_characters_player_launchRecover02 3635+#define T_characters_player_launchRecover03 3636+#define T_characters_player_launchRecover04 3637+#define T_characters_player_launchRecover05 3638+#define T_characters_player_launchRecover06 3639+#define T_characters_player_launchRecover07 3640+#define T_characters_player_launchRecover08 3641+#define T_characters_player_launchRecover09 3642+#define T_characters_player_launchRecover10 3643+#define T_characters_player_no_backpack_idle_carry00 3644+#define T_characters_player_no_backpack_idle_carry01 3645+#define T_characters_player_no_backpack_idle_carry02 3646+#define T_characters_player_no_backpack_idle_carry03 3647+#define T_characters_player_no_backpack_idle_carry04 3648+#define T_characters_player_no_backpack_idle_carry05 3649+#define T_characters_player_no_backpack_idle_carry06 3650+#define T_characters_player_no_backpack_idle_carry07 3651+#define T_characters_player_no_backpack_idle_carry08 3652+#define T_characters_player_no_backpack_run_carry00 3653+#define T_characters_player_no_backpack_run_carry01 3654+#define T_characters_player_no_backpack_run_carry02 3655+#define T_characters_player_no_backpack_run_carry03 3656+#define T_characters_player_no_backpack_run_carry04 3657+#define T_characters_player_no_backpack_run_carry05 3658+#define T_characters_player_no_backpack_run_carry06 3659+#define T_characters_player_no_backpack_run_carry07 3660+#define T_characters_player_no_backpack_run_carry08 3661+#define T_characters_player_no_backpack_run_carry09 3662+#define T_characters_player_no_backpack_run_carry10 3663+#define T_characters_player_no_backpack_run_carry11 3664+#define T_characters_player_no_backpack_jump_carry00 3665+#define T_characters_player_no_backpack_jump_carry01 3666+#define T_characters_player_no_backpack_jump_carry02 3667+#define T_characters_player_no_backpack_jump_carry03 3668+#define T_characters_player_no_backpack_pickup00 3669+#define T_characters_player_no_backpack_pickup01 3670+#define T_characters_player_no_backpack_pickup02 3671+#define T_characters_player_no_backpack_pickup03 3672+#define T_characters_player_no_backpack_pickup04 3673+#define T_characters_player_no_backpack_throw00 3674+#define T_characters_player_no_backpack_throw01 3675+#define T_characters_player_no_backpack_throw02 3676+#define T_characters_player_no_backpack_throw03 3677+#define T_characters_player_no_backpack_idle00 3678+#define T_characters_player_no_backpack_idle01 3679+#define T_characters_player_no_backpack_idle02 3680+#define T_characters_player_no_backpack_idle03 3681+#define T_characters_player_no_backpack_idle04 3682+#define T_characters_player_no_backpack_idle05 3683+#define T_characters_player_no_backpack_idle06 3684+#define T_characters_player_no_backpack_idle07 3685+#define T_characters_player_no_backpack_idleA00 3686+#define T_characters_player_no_backpack_idleA01 3687+#define T_characters_player_no_backpack_idleA02 3688+#define T_characters_player_no_backpack_idleA03 3689+#define T_characters_player_no_backpack_idleA04 3690+#define T_characters_player_no_backpack_idleA05 3691+#define T_characters_player_no_backpack_idleA06 3692+#define T_characters_player_no_backpack_idleA07 3693+#define T_characters_player_no_backpack_idleA08 3694+#define T_characters_player_no_backpack_idleA09 3695+#define T_characters_player_no_backpack_idleA10 3696+#define T_characters_player_no_backpack_idleA11 3697+#define T_characters_player_no_backpack_idleB00 3698+#define T_characters_player_no_backpack_idleB01 3699+#define T_characters_player_no_backpack_idleB02 3700+#define T_characters_player_no_backpack_idleB03 3701+#define T_characters_player_no_backpack_idleB04 3702+#define T_characters_player_no_backpack_idleB05 3703+#define T_characters_player_no_backpack_idleB06 3704+#define T_characters_player_no_backpack_idleB07 3705+#define T_characters_player_no_backpack_idleB08 3706+#define T_characters_player_no_backpack_idleB09 3707+#define T_characters_player_no_backpack_idleB10 3708+#define T_characters_player_no_backpack_idleB11 3709+#define T_characters_player_no_backpack_idleB12 3710+#define T_characters_player_no_backpack_idleB13 3711+#define T_characters_player_no_backpack_idleB14 3712+#define T_characters_player_no_backpack_idleC00 3713+#define T_characters_player_no_backpack_idleC01 3714+#define T_characters_player_no_backpack_idleC02 3715+#define T_characters_player_no_backpack_idleC03 3716+#define T_characters_player_no_backpack_idleC04 3717+#define T_characters_player_no_backpack_idleC05 3718+#define T_characters_player_no_backpack_idleC06 3719+#define T_characters_player_no_backpack_idleC07 3720+#define T_characters_player_no_backpack_idleC08 3721+#define T_characters_player_no_backpack_idleC09 3722+#define T_characters_player_no_backpack_idleC10 3723+#define T_characters_player_no_backpack_idleC11 3724+#define T_characters_player_no_backpack_idleC12 3725+#define T_characters_player_no_backpack_idleC13 3726+#define T_characters_player_no_backpack_idleC14 3727+#define T_characters_player_no_backpack_lookUp00 3728+#define T_characters_player_no_backpack_lookUp01 3729+#define T_characters_player_no_backpack_lookUp02 3730+#define T_characters_player_no_backpack_lookUp03 3731+#define T_characters_player_no_backpack_lookUp04 3732+#define T_characters_player_no_backpack_lookUp05 3733+#define T_characters_player_no_backpack_lookUp06 3734+#define T_characters_player_no_backpack_lookUp07 3735+#define T_characters_player_no_backpack_walk00 3736+#define T_characters_player_no_backpack_walk01 3737+#define T_characters_player_no_backpack_walk02 3738+#define T_characters_player_no_backpack_walk03 3739+#define T_characters_player_no_backpack_walk04 3740+#define T_characters_player_no_backpack_walk05 3741+#define T_characters_player_no_backpack_walk06 3742+#define T_characters_player_no_backpack_walk07 3743+#define T_characters_player_no_backpack_walk08 3744+#define T_characters_player_no_backpack_walk09 3745+#define T_characters_player_no_backpack_walk10 3746+#define T_characters_player_no_backpack_walk11 3747+#define T_characters_player_no_backpack_push00 3748+#define T_characters_player_no_backpack_push01 3749+#define T_characters_player_no_backpack_push02 3750+#define T_characters_player_no_backpack_push03 3751+#define T_characters_player_no_backpack_push04 3752+#define T_characters_player_no_backpack_push05 3753+#define T_characters_player_no_backpack_push06 3754+#define T_characters_player_no_backpack_push07 3755+#define T_characters_player_no_backpack_push08 3756+#define T_characters_player_no_backpack_push09 3757+#define T_characters_player_no_backpack_push10 3758+#define T_characters_player_no_backpack_push11 3759+#define T_characters_player_no_backpack_push12 3760+#define T_characters_player_no_backpack_push13 3761+#define T_characters_player_no_backpack_push14 3762+#define T_characters_player_no_backpack_push15 3763+#define T_characters_player_no_backpack_runSlow00 3764+#define T_characters_player_no_backpack_runSlow01 3765+#define T_characters_player_no_backpack_runSlow02 3766+#define T_characters_player_no_backpack_runSlow03 3767+#define T_characters_player_no_backpack_runSlow04 3768+#define T_characters_player_no_backpack_runSlow05 3769+#define T_characters_player_no_backpack_runSlow06 3770+#define T_characters_player_no_backpack_runSlow07 3771+#define T_characters_player_no_backpack_runSlow08 3772+#define T_characters_player_no_backpack_runSlow09 3773+#define T_characters_player_no_backpack_runSlow10 3774+#define T_characters_player_no_backpack_runSlow11 3775+#define T_characters_player_no_backpack_runFast00 3776+#define T_characters_player_no_backpack_runFast01 3777+#define T_characters_player_no_backpack_runFast02 3778+#define T_characters_player_no_backpack_runFast03 3779+#define T_characters_player_no_backpack_runFast04 3780+#define T_characters_player_no_backpack_runFast05 3781+#define T_characters_player_no_backpack_runFast06 3782+#define T_characters_player_no_backpack_runFast07 3783+#define T_characters_player_no_backpack_runFast08 3784+#define T_characters_player_no_backpack_runFast09 3785+#define T_characters_player_no_backpack_runFast10 3786+#define T_characters_player_no_backpack_runFast11 3787+#define T_characters_player_no_backpack_runStumble00 3788+#define T_characters_player_no_backpack_runStumble01 3789+#define T_characters_player_no_backpack_runStumble02 3790+#define T_characters_player_no_backpack_runStumble03 3791+#define T_characters_player_no_backpack_runStumble04 3792+#define T_characters_player_no_backpack_runStumble05 3793+#define T_characters_player_no_backpack_runStumble06 3794+#define T_characters_player_no_backpack_runStumble07 3795+#define T_characters_player_no_backpack_runStumble08 3796+#define T_characters_player_no_backpack_runStumble09 3797+#define T_characters_player_no_backpack_runStumble10 3798+#define T_characters_player_no_backpack_runStumble11 3799+#define T_characters_player_no_backpack_run_wind00 3800+#define T_characters_player_no_backpack_run_wind01 3801+#define T_characters_player_no_backpack_run_wind02 3802+#define T_characters_player_no_backpack_run_wind03 3803+#define T_characters_player_no_backpack_run_wind04 3804+#define T_characters_player_no_backpack_run_wind05 3805+#define T_characters_player_no_backpack_run_wind06 3806+#define T_characters_player_no_backpack_run_wind07 3807+#define T_characters_player_no_backpack_run_wind08 3808+#define T_characters_player_no_backpack_run_wind09 3809+#define T_characters_player_no_backpack_run_wind10 3810+#define T_characters_player_no_backpack_run_wind11 3811+#define T_characters_player_no_backpack_dash00 3812+#define T_characters_player_no_backpack_dash01 3813+#define T_characters_player_no_backpack_dash02 3814+#define T_characters_player_no_backpack_dash03 3815+#define T_characters_player_no_backpack_jumpSlow00 3816+#define T_characters_player_no_backpack_jumpSlow01 3817+#define T_characters_player_no_backpack_jumpSlow02 3818+#define T_characters_player_no_backpack_jumpSlow03 3819+#define T_characters_player_no_backpack_jumpFast00 3820+#define T_characters_player_no_backpack_jumpFast01 3821+#define T_characters_player_no_backpack_jumpFast02 3822+#define T_characters_player_no_backpack_jumpFast03 3823+#define T_characters_player_no_backpack_climb00 3824+#define T_characters_player_no_backpack_climb01 3825+#define T_characters_player_no_backpack_climb02 3826+#define T_characters_player_no_backpack_climb03 3827+#define T_characters_player_no_backpack_climb04 3828+#define T_characters_player_no_backpack_climb05 3829+#define T_characters_player_no_backpack_climb06 3830+#define T_characters_player_no_backpack_climb07 3831+#define T_characters_player_no_backpack_climb08 3832+#define T_characters_player_no_backpack_climb09 3833+#define T_characters_player_no_backpack_climb10 3834+#define T_characters_player_no_backpack_climb11 3835+#define T_characters_player_no_backpack_climb12 3836+#define T_characters_player_no_backpack_climb13 3837+#define T_characters_player_no_backpack_climb14 3838+#define T_characters_player_no_backpack_duck 3839+#define T_characters_player_no_backpack_edge00 3840+#define T_characters_player_no_backpack_edge01 3841+#define T_characters_player_no_backpack_edge02 3842+#define T_characters_player_no_backpack_edge03 3843+#define T_characters_player_no_backpack_edge04 3844+#define T_characters_player_no_backpack_edge05 3845+#define T_characters_player_no_backpack_edge06 3846+#define T_characters_player_no_backpack_edge07 3847+#define T_characters_player_no_backpack_edge08 3848+#define T_characters_player_no_backpack_edge09 3849+#define T_characters_player_no_backpack_edge10 3850+#define T_characters_player_no_backpack_edge11 3851+#define T_characters_player_no_backpack_edge12 3852+#define T_characters_player_no_backpack_edge13 3853+#define T_characters_player_no_backpack_flip00 3854+#define T_characters_player_no_backpack_flip01 3855+#define T_characters_player_no_backpack_flip02 3856+#define T_characters_player_no_backpack_flip03 3857+#define T_characters_player_no_backpack_flip04 3858+#define T_characters_player_no_backpack_flip05 3859+#define T_characters_player_no_backpack_flip06 3860+#define T_characters_player_no_backpack_flip07 3861+#define T_characters_player_no_backpack_flip08 3862+#define T_characters_player_no_backpack_dangling00 3863+#define T_characters_player_no_backpack_dangling01 3864+#define T_characters_player_no_backpack_dangling02 3865+#define T_characters_player_no_backpack_dangling03 3866+#define T_characters_player_no_backpack_dangling04 3867+#define T_characters_player_no_backpack_dangling05 3868+#define T_characters_player_no_backpack_dangling06 3869+#define T_characters_player_no_backpack_dangling07 3870+#define T_characters_player_no_backpack_dangling08 3871+#define T_characters_player_no_backpack_dangling09 3872+#define T_characters_player_no_backpack_bubble 3873+#define T_characters_player_no_backpack_spin00 3874+#define T_characters_player_no_backpack_spin01 3875+#define T_characters_player_no_backpack_spin02 3876+#define T_characters_player_no_backpack_spin03 3877+#define T_characters_player_no_backpack_spin04 3878+#define T_characters_player_no_backpack_spin05 3879+#define T_characters_player_no_backpack_spin06 3880+#define T_characters_player_no_backpack_spin07 3881+#define T_characters_player_no_backpack_spin08 3882+#define T_characters_player_no_backpack_spin09 3883+#define T_characters_player_no_backpack_spin10 3884+#define T_characters_player_no_backpack_spin11 3885+#define T_characters_player_no_backpack_spin12 3886+#define T_characters_player_no_backpack_spin13 3887+#define T_characters_player_no_backpack_shaking00 3888+#define T_characters_player_no_backpack_sitDown00 3889+#define T_characters_player_no_backpack_sitDown01 3890+#define T_characters_player_no_backpack_sitDown02 3891+#define T_characters_player_no_backpack_sitDown03 3892+#define T_characters_player_no_backpack_sitDown04 3893+#define T_characters_player_no_backpack_sitDown05 3894+#define T_characters_player_no_backpack_sitDown06 3895+#define T_characters_player_no_backpack_sitDown07 3896+#define T_characters_player_no_backpack_sitDown08 3897+#define T_characters_player_no_backpack_sitDown09 3898+#define T_characters_player_no_backpack_sitDown10 3899+#define T_characters_player_no_backpack_sitDown11 3900+#define T_characters_player_no_backpack_sitDown12 3901+#define T_characters_player_no_backpack_sitDown13 3902+#define T_characters_player_no_backpack_sitDown14 3903+#define T_characters_player_no_backpack_sitDown15 3904+#define T_characters_player_no_backpack_sitDown16 3905+#define T_characters_player_no_backpack_sitDown17 3906+#define T_characters_player_no_backpack_launch00 3907+#define T_characters_player_no_backpack_launch01 3908+#define T_characters_player_no_backpack_launch02 3909+#define T_characters_player_no_backpack_launch03 3910+#define T_characters_player_no_backpack_launch04 3911+#define T_characters_player_no_backpack_launch05 3912+#define T_characters_player_no_backpack_launch06 3913+#define T_characters_player_no_backpack_launch07 3914+#define T_characters_player_no_backpack_launchRecover00 3915+#define T_characters_player_no_backpack_launchRecover01 3916+#define T_characters_player_no_backpack_launchRecover02 3917+#define T_characters_player_no_backpack_launchRecover03 3918+#define T_characters_player_no_backpack_launchRecover04 3919+#define T_characters_player_no_backpack_launchRecover05 3920+#define T_characters_player_no_backpack_launchRecover06 3921+#define T_characters_player_no_backpack_launchRecover07 3922+#define T_characters_player_no_backpack_launchRecover08 3923+#define T_characters_player_no_backpack_launchRecover09 3924+#define T_characters_player_no_backpack_roll00 3925+#define T_characters_player_no_backpack_roll01 3926+#define T_characters_player_no_backpack_roll02 3927+#define T_characters_player_no_backpack_roll03 3928+#define T_characters_player_no_backpack_roll04 3929+#define T_characters_player_no_backpack_roll05 3930+#define T_characters_player_no_backpack_roll06 3931+#define T_characters_player_no_backpack_roll07 3932+#define T_characters_player_no_backpack_roll08 3933+#define T_characters_player_no_backpack_roll09 3934+#define T_characters_player_no_backpack_roll10 3935+#define T_characters_player_no_backpack_roll11 3936+#define T_characters_player_no_backpack_roll12 3937+#define T_characters_player_no_backpack_roll13 3938+#define T_characters_player_no_backpack_roll14 3939+#define T_characters_player_no_backpack_roll15 3940+#define T_characters_player_no_backpack_roll16 3941+#define T_characters_player_hair00 3942+#define T_characters_player_bangs00 3943+#define T_characters_player_bangs01 3944+#define T_characters_player_bangs02 3945+#define T_particles_smoke0 3946+#define T_particles_smoke1 3947+#define T_particles_smoke2 3948+#define T_particles_smoke3 3949+#define T_particles_zappysmoke00 3950+#define T_particles_zappysmoke01 3951+#define T_particles_zappysmoke02 3952+#define T_particles_zappysmoke03 3953+#define T_particles_stars_00 3954+#define T_particles_stars_01 3955+#define T_particles_stars_02 3956+#define T_particles_stars_03 3957+#define T_particles_stars_04 3958+#define T_particles_starfield_00 3959+#define T_particles_starfield_01 3960+#define T_particles_starfield_02 3961+#define T_particles_starfield_03 3962+#define T_particles_blob 3963+#define T_particles_bubble 3964+#define T_particles_circle 3965+#define T_particles_cloud 3966+#define T_particles_confetti 3967+#define T_particles_feather 3968+#define T_particles_fire 3969+#define T_particles_petal 3970+#define T_particles_rect 3971+#define T_particles_shard 3972+#define T_particles_shatter 3973+#define T_particles_snow 3974+#define T_particles_triangle 3975+#define T_particles_triggerspike 3976+#define T_characters_player_sweat_idle00 3977+#define T_characters_player_sweat_climb00 3978+#define T_characters_player_sweat_climb01 3979+#define T_characters_player_sweat_climb02 3980+#define T_characters_player_sweat_climb03 3981+#define T_characters_player_sweat_climb04 3982+#define T_characters_player_sweat_climb05 3983+#define T_characters_player_sweat_climb06 3984+#define T_characters_player_sweat_climb07 3985+#define T_characters_player_sweat_still00 3986+#define T_characters_player_sweat_still01 3987+#define T_characters_player_sweat_still02 3988+#define T_characters_player_sweat_still03 3989+#define T_characters_player_sweat_still04 3990+#define T_characters_player_sweat_still05 3991+#define T_characters_player_sweat_jump00 3992+#define T_characters_player_sweat_jump01 3993+#define T_characters_player_sweat_jump02 3994+#define T_characters_player_sweat_jump03 3995+#define T_characters_player_sweat_danger00 3996+#define T_characters_player_sweat_danger01 3997+#define T_characters_player_sweat_danger02 3998+#define T_characters_player_sweat_danger03 3999+#define T_characters_player_sweat_danger04 4000+#define T_characters_player_sweat_danger05 4001+#define T__textbox_default 4002+#define T__textbox_madeline 4003+#define T__textbox_theo 4004+#define T__textbox_badeline 4005+#define T__textbox_granny 4006+#define T__textbox_oshiro 4007+#define T__textbox_oshiro_overlay 4008+#define T__textbox_default_mini 4009+#define T__textbox_theo_mini 4010+#define T__textbox_badeline_mini 4011+#define T__textbox_madeline_ask 4012+#define T__textbox_theo_ask 4013+#define T__textboxbutton 4014+#define T__hug1 4015+#define T__hug2 4016+#define T__hug_light2a 4017+#define T__hug_light2b 4018+#define T__hug_light2c 4019+#define T__selfie 4020+#define T__selfieFilter 4021+#define T__selfieGondola 4022+#define T__selfieCampfire 4023+#define T__finalbg 4024+#define T__final1 4025+#define T__final2 4026+#define T__final3 4027+#define T__final4 4028+#define T__final5 4029+#define T__feather_border 4030+#define T__feather_box 4031+#define T__feather_feather0 4032+#define T__feather_feather1 4033+#define T__feather_feather2 4034+#define T__feather_feather3 4035+#define T__feather_feather_half0 4036+#define T__feather_feather_half1 4037+#define T__feather_particle 4038+#define T__feather_slice 4039+#define T__hover_idle 4040+#define T__hover_highlight 4041+#define T__collectables_heartgem_0_spin00 4042+#define T__collectables_heartgem_0_spin01 4043+#define T__collectables_heartgem_0_spin02 4044+#define T__collectables_heartgem_0_spin03 4045+#define T__collectables_heartgem_0_spin04 4046+#define T__collectables_heartgem_0_spin05 4047+#define T__collectables_heartgem_0_spin06 4048+#define T__collectables_heartgem_0_spin07 4049+#define T__collectables_heartgem_0_spin08 4050+#define T__collectables_heartgem_0_spin09 4051+#define T__collectables_heartgem_0_spin10 4052+#define T__collectables_heartgem_1_spin00 4053+#define T__collectables_heartgem_1_spin01 4054+#define T__collectables_heartgem_1_spin02 4055+#define T__collectables_heartgem_1_spin03 4056+#define T__collectables_heartgem_1_spin04 4057+#define T__collectables_heartgem_1_spin05 4058+#define T__collectables_heartgem_1_spin06 4059+#define T__collectables_heartgem_1_spin07 4060+#define T__collectables_heartgem_1_spin08 4061+#define T__collectables_heartgem_1_spin09 4062+#define T__collectables_heartgem_1_spin10 4063+#define T__collectables_heartgem_2_spin00 4064+#define T__collectables_heartgem_2_spin01 4065+#define T__collectables_heartgem_2_spin02 4066+#define T__collectables_heartgem_2_spin03 4067+#define T__collectables_heartgem_2_spin04 4068+#define T__collectables_heartgem_2_spin05 4069+#define T__collectables_heartgem_2_spin06 4070+#define T__collectables_heartgem_2_spin07 4071+#define T__collectables_heartgem_2_spin08 4072+#define T__collectables_heartgem_2_spin09 4073+#define T__collectables_heartgem_2_spin10 4074+#define T__poemside 4075+#define T__snow 4076+#define T__collectables_cassette 4077+#define T__areas_intro 4078+#define T__areas_city 4079+#define T__areas_oldsite 4080+#define T__areas_resort 4081+#define T__areas_cliffside 4082+#define T__areas_temple 4083+#define T__areas_reflection 4084+#define T__areas_Summit 4085+#define T__areas_core 4086+#define T__areas_lock 4087+#define T__areaselect_title 4088+#define T__areaselect_accent 4089+#define T__menu_start 4090+#define T__menu_options 4091+#define T__menu_credits 4092+#define T__menu_exit 4093+#define T__title 4094+#define T__collectables_strawberry 4095+#define T__collectables_goldberry 4096+#define T__collectables_skullBlue 4097+#define T__strawberryCountBG 4098+#define T__x 4099+#define T__noise_00 4100+#define T__noise_01 4101+#define T__noise_02 4102+#define T__madeline_normal00 4103+#define T__madeline_normal01 4104+#define T__madeline_normal02 4105+#define T__madeline_normal03 4106+#define T__madeline_normal04 4107+#define T__madeline_normal05 4108+#define T__madeline_normal06 4109+#define T__madeline_peaceful00 4110+#define T__madeline_peaceful01 4111+#define T__madeline_peaceful02 4112+#define T__madeline_peaceful03 4113+#define T__madeline_angry00 4114+#define T__madeline_angry01 4115+#define T__madeline_angry02 4116+#define T__madeline_angry03 4117+#define T__madeline_angry04 4118+#define T__madeline_angry05 4119+#define T__madeline_angry06 4120+#define T__madeline_deadpan00 4121+#define T__madeline_deadpan01 4122+#define T__madeline_deadpan02 4123+#define T__madeline_deadpan03 4124+#define T__madeline_deadpan04 4125+#define T__madeline_deadpan05 4126+#define T__madeline_deadpan06 4127+#define T__madeline_deadpan07 4128+#define T__madeline_deadpan08 4129+#define T__madeline_sad00 4130+#define T__madeline_sad01 4131+#define T__madeline_sad02 4132+#define T__madeline_sad03 4133+#define T__madeline_sad04 4134+#define T__madeline_sad05 4135+#define T__madeline_sad06 4136+#define T__madeline_sadder00 4137+#define T__madeline_sadder01 4138+#define T__madeline_sadder02 4139+#define T__madeline_sadder03 4140+#define T__madeline_sadder04 4141+#define T__madeline_sadder05 4142+#define T__madeline_sadder06 4143+#define T__madeline_upset00 4144+#define T__madeline_upset01 4145+#define T__madeline_upset02 4146+#define T__madeline_upset03 4147+#define T__madeline_upset04 4148+#define T__madeline_upset05 4149+#define T__madeline_upset06 4150+#define T__madeline_surprised00 4151+#define T__madeline_surprised01 4152+#define T__madeline_surprised02 4153+#define T__madeline_surprised03 4154+#define T__madeline_surprised04 4155+#define T__madeline_surprised05 4156+#define T__madeline_surprised06 4157+#define T__madeline_distracted00 4158+#define T__madeline_distracted01 4159+#define T__madeline_distracted02 4160+#define T__madeline_distracted03 4161+#define T__madeline_distracted04 4162+#define T__madeline_distracted05 4163+#define T__madeline_distracted06 4164+#define T__madeline_distracted07 4165+#define T__madeline_distracted08 4166+#define T__madeline_distracted09 4167+#define T__madeline_determined00 4168+#define T__madeline_determined01 4169+#define T__madeline_determined02 4170+#define T__madeline_determined03 4171+#define T__madeline_determined04 4172+#define T__madeline_determined05 4173+#define T__madeline_determined06 4174+#define T__madeline_determined07 4175+#define T__madeline_determined08 4176+#define T__madeline_determined09 4177+#define T__madeline_determined10 4178+#define T__madeline_panic00 4179+#define T__madeline_panic01 4180+#define T__madeline_panic02 4181+#define T__madeline_panic03 4182+#define T__madeline_panic04 4183+#define T__madeline_together00 4184+#define T__madeline_together01 4185+#define T__madeline_together02 4186+#define T__madeline_together03 4187+#define T__madeline_together04 4188+#define T__madeline_together05 4189+#define T__madeline_together06 4190+#define T__madeline_togetherZoom00 4191+#define T__madeline_togetherZoom01 4192+#define T__madeline_togetherZoom02 4193+#define T__madeline_togetherZoom03 4194+#define T__madeline_togetherZoom04 4195+#define T__madeline_togetherZoom05 4196+#define T__madeline_togetherZoom06 4197+#define T__madeline_togetherZoom07 4198+#define T__madeline_togetherZoom08 4199+#define T__madeline_togetherZoom09 4200+#define T__madeline_togetherZoom10 4201+#define T__madeline_togetherZoom11 4202+#define T__madeline_togetherZoom12 4203+#define T__madeline_togetherZoom13 4204+#define T__madeline_togetherZoom14 4205+#define T__madeline_togetherZoom15 4206+#define T__madeline_togetherZoom16 4207+#define T__madelineph_normal00 4208+#define T__madelineph_normal01 4209+#define T__madelineph_normal02 4210+#define T__madelineph_normal03 4211+#define T__madelineph_normal04 4212+#define T__madelineph_normal05 4213+#define T__madelineph_normal06 4214+#define T__madelineph_angry00 4215+#define T__madelineph_angry01 4216+#define T__madelineph_angry02 4217+#define T__madelineph_angry03 4218+#define T__madelineph_angry04 4219+#define T__madelineph_angry05 4220+#define T__madelineph_angry06 4221+#define T__madelineph_sad00 4222+#define T__madelineph_sad01 4223+#define T__madelineph_sad02 4224+#define T__madelineph_sad03 4225+#define T__madelineph_sad04 4226+#define T__madelineph_sad05 4227+#define T__madelineph_sad06 4228+#define T__madelineph_upset00 4229+#define T__madelineph_upset01 4230+#define T__madelineph_upset02 4231+#define T__madelineph_upset03 4232+#define T__madelineph_upset04 4233+#define T__madelineph_upset05 4234+#define T__madelineph_upset06 4235+#define T__madelineph_surprised00 4236+#define T__madelineph_surprised01 4237+#define T__madelineph_surprised02 4238+#define T__madelineph_surprised03 4239+#define T__madelineph_surprised04 4240+#define T__madelineph_surprised05 4241+#define T__madelineph_surprised06 4242+#define T__madelineph_distracted00 4243+#define T__madelineph_distracted01 4244+#define T__madelineph_distracted02 4245+#define T__madelineph_distracted03 4246+#define T__madelineph_distracted04 4247+#define T__madelineph_distracted05 4248+#define T__madelineph_distracted06 4249+#define T__madelineph_distracted07 4250+#define T__madelineph_distracted08 4251+#define T__madelineph_distracted09 4252+#define T__madelinemirror_normal00 4253+#define T__madelinemirror_normal01 4254+#define T__madelinemirror_normal02 4255+#define T__madelinemirror_normal03 4256+#define T__madelinemirror_normal04 4257+#define T__madelinemirror_normal05 4258+#define T__madelinemirror_normal06 4259+#define T__madelinemirror_normal07 4260+#define T__madelinemirror_normal08 4261+#define T__madelinemirror_normal09 4262+#define T__madelinemirror_normal10 4263+#define T__madelinemirror_angry00 4264+#define T__madelinemirror_angry01 4265+#define T__madelinemirror_angry02 4266+#define T__madelinemirror_angry03 4267+#define T__madelinemirror_angry04 4268+#define T__madelinemirror_angry05 4269+#define T__madelinemirror_angry06 4270+#define T__madelinemirror_angry07 4271+#define T__madelinemirror_angry08 4272+#define T__madelinemirror_angry09 4273+#define T__madelinemirror_angry10 4274+#define T__madelinemirror_deadpan00 4275+#define T__madelinemirror_deadpan01 4276+#define T__madelinemirror_deadpan02 4277+#define T__madelinemirror_deadpan03 4278+#define T__madelinemirror_deadpan04 4279+#define T__madelinemirror_deadpan05 4280+#define T__madelinemirror_deadpan06 4281+#define T__madelinemirror_deadpan07 4282+#define T__madelinemirror_deadpan08 4283+#define T__madelinemirror_deadpan09 4284+#define T__madelinemirror_deadpan10 4285+#define T__madelinemirror_deadpan11 4286+#define T__madelinemirror_deadpan12 4287+#define T__madelinemirror_sad00 4288+#define T__madelinemirror_sad01 4289+#define T__madelinemirror_sad02 4290+#define T__madelinemirror_sad03 4291+#define T__madelinemirror_sad04 4292+#define T__madelinemirror_sad05 4293+#define T__madelinemirror_sad06 4294+#define T__madelinemirror_sad07 4295+#define T__madelinemirror_sad08 4296+#define T__madelinemirror_sad09 4297+#define T__madelinemirror_sad10 4298+#define T__madelinemirror_upset00 4299+#define T__madelinemirror_upset01 4300+#define T__madelinemirror_upset02 4301+#define T__madelinemirror_upset03 4302+#define T__madelinemirror_upset04 4303+#define T__madelinemirror_upset05 4304+#define T__madelinemirror_upset06 4305+#define T__madelinemirror_upset07 4306+#define T__madelinemirror_upset08 4307+#define T__madelinemirror_upset09 4308+#define T__madelinemirror_upset10 4309+#define T__madelinemirror_surprised00 4310+#define T__madelinemirror_surprised01 4311+#define T__madelinemirror_surprised02 4312+#define T__madelinemirror_surprised03 4313+#define T__madelinemirror_surprised04 4314+#define T__madelinemirror_surprised05 4315+#define T__madelinemirror_surprised06 4316+#define T__madelinemirror_surprised07 4317+#define T__madelinemirror_surprised08 4318+#define T__madelinemirror_surprised09 4319+#define T__madelinemirror_surprised10 4320+#define T__madelinemirror_distracted00 4321+#define T__madelinemirror_distracted01 4322+#define T__madelinemirror_distracted02 4323+#define T__madelinemirror_distracted03 4324+#define T__madelinemirror_distracted04 4325+#define T__madelinemirror_distracted05 4326+#define T__madelinemirror_distracted06 4327+#define T__madelinemirror_distracted07 4328+#define T__madelinemirror_distracted08 4329+#define T__madelinemirror_distracted09 4330+#define T__madelinemirror_distracted10 4331+#define T__madelinemirror_distracted11 4332+#define T__madelinemirror_distracted12 4333+#define T__madelinemirror_distracted13 4334+#define T__madelinemirror_determined00 4335+#define T__madelinemirror_determined01 4336+#define T__madelinemirror_determined02 4337+#define T__madelinemirror_determined03 4338+#define T__madelinemirror_determined04 4339+#define T__madelinemirror_determined05 4340+#define T__madelinemirror_determined06 4341+#define T__madelinemirror_determined07 4342+#define T__madelinemirror_determined08 4343+#define T__madelinemirror_determined09 4344+#define T__madelinemirror_determined10 4345+#define T__madelinemirror_determined11 4346+#define T__madelinemirror_determined12 4347+#define T__madelinemirror_determined13 4348+#define T__madelinemirror_determined14 4349+#define T__madelinemirror_panic00 4350+#define T__madelinemirror_panic01 4351+#define T__madelinemirror_panic02 4352+#define T__madelinemirror_panic03 4353+#define T__madelinemirror_panic04 4354+#define T__madelinemirror_panic05 4355+#define T__madelinemirror_panic06 4356+#define T__madelinemirror_panic07 4357+#define T__madelinemirror_panic08 4358+#define T__granny_normal00 4359+#define T__granny_normal01 4360+#define T__granny_normal02 4361+#define T__granny_normal03 4362+#define T__granny_normal04 4363+#define T__granny_normal05 4364+#define T__granny_normal06 4365+#define T__granny_normal07 4366+#define T__granny_normal08 4367+#define T__granny_normal09 4368+#define T__granny_normal10 4369+#define T__granny_normal11 4370+#define T__granny_normal12 4371+#define T__granny_normal13 4372+#define T__granny_normal14 4373+#define T__granny_mock00 4374+#define T__granny_mock01 4375+#define T__granny_mock02 4376+#define T__granny_mock03 4377+#define T__granny_mock04 4378+#define T__granny_mock05 4379+#define T__granny_creepA00 4380+#define T__granny_creepA04 4381+#define T__granny_creepA05 4382+#define T__granny_creepA06 4383+#define T__granny_creepA07 4384+#define T__granny_creepA08 4385+#define T__granny_creepB00 4386+#define T__granny_creepB04 4387+#define T__granny_creepB05 4388+#define T__granny_creepB06 4389+#define T__granny_creepB07 4390+#define T__granny_creepB08 4391+#define T__granny_laugh00 4392+#define T__granny_laugh01 4393+#define T__granny_laugh02 4394+#define T__granny_laugh03 4395+#define T__theo_normal00 4396+#define T__theo_normal01 4397+#define T__theo_normal02 4398+#define T__theo_normal03 4399+#define T__theo_normal04 4400+#define T__theo_normal05 4401+#define T__theo_normal06 4402+#define T__theo_normal07 4403+#define T__theo_normal08 4404+#define T__theo_normal09 4405+#define T__theo_thinking00 4406+#define T__theo_thinking01 4407+#define T__theo_thinking02 4408+#define T__theo_thinking03 4409+#define T__theo_thinking04 4410+#define T__theo_thinking05 4411+#define T__theo_thinking06 4412+#define T__theo_excited00 4413+#define T__theo_excited01 4414+#define T__theo_excited02 4415+#define T__theo_excited03 4416+#define T__theo_excited04 4417+#define T__theo_excited05 4418+#define T__theo_excited06 4419+#define T__theo_worried00 4420+#define T__theo_worried01 4421+#define T__theo_worried02 4422+#define T__theo_worried03 4423+#define T__theo_worried04 4424+#define T__theo_worried05 4425+#define T__theo_worried06 4426+#define T__theo_wtf00 4427+#define T__theo_wtf01 4428+#define T__theo_wtf02 4429+#define T__theo_wtf03 4430+#define T__theo_wtf04 4431+#define T__theo_wtf05 4432+#define T__theo_wtf06 4433+#define T__theo_yolo00 4434+#define T__theo_yolo01 4435+#define T__theo_yolo02 4436+#define T__theo_yolo03 4437+#define T__theo_nailedit00 4438+#define T__theo_nailedit01 4439+#define T__theo_nailedit02 4440+#define T__theo_nailedit03 4441+#define T__theo_serious00 4442+#define T__theo_serious01 4443+#define T__theo_serious02 4444+#define T__theo_serious03 4445+#define T__theo_serious04 4446+#define T__theo_serious05 4447+#define T__theo_serious06 4448+#define T__theomirror_normal00 4449+#define T__theomirror_normal01 4450+#define T__theomirror_normal02 4451+#define T__theomirror_normal03 4452+#define T__theomirror_normal04 4453+#define T__theomirror_normal05 4454+#define T__theomirror_normal06 4455+#define T__theomirror_normal07 4456+#define T__theomirror_normal08 4457+#define T__theomirror_normal09 4458+#define T__theomirror_normal10 4459+#define T__theomirror_normal11 4460+#define T__theomirror_normal12 4461+#define T__theomirror_normal13 4462+#define T__theomirror_thinking00 4463+#define T__theomirror_thinking01 4464+#define T__theomirror_thinking02 4465+#define T__theomirror_thinking03 4466+#define T__theomirror_thinking04 4467+#define T__theomirror_thinking05 4468+#define T__theomirror_thinking06 4469+#define T__theomirror_thinking07 4470+#define T__theomirror_thinking08 4471+#define T__theomirror_thinking09 4472+#define T__theomirror_thinking10 4473+#define T__theomirror_excited00 4474+#define T__theomirror_excited01 4475+#define T__theomirror_excited02 4476+#define T__theomirror_excited03 4477+#define T__theomirror_excited04 4478+#define T__theomirror_excited05 4479+#define T__theomirror_excited06 4480+#define T__theomirror_excited07 4481+#define T__theomirror_excited08 4482+#define T__theomirror_excited09 4483+#define T__theomirror_excited10 4484+#define T__theomirror_worried00 4485+#define T__theomirror_worried01 4486+#define T__theomirror_worried02 4487+#define T__theomirror_worried03 4488+#define T__theomirror_worried04 4489+#define T__theomirror_worried05 4490+#define T__theomirror_worried06 4491+#define T__theomirror_worried07 4492+#define T__theomirror_worried08 4493+#define T__theomirror_worried09 4494+#define T__theomirror_worried10 4495+#define T__theomirror_wtf00 4496+#define T__theomirror_wtf01 4497+#define T__theomirror_wtf02 4498+#define T__theomirror_wtf03 4499+#define T__theomirror_wtf04 4500+#define T__theomirror_wtf05 4501+#define T__theomirror_wtf06 4502+#define T__theomirror_wtf07 4503+#define T__theomirror_wtf08 4504+#define T__theomirror_wtf09 4505+#define T__theomirror_wtf10 4506+#define T__theomirror_serious00 4507+#define T__theomirror_serious01 4508+#define T__theomirror_serious02 4509+#define T__theomirror_serious03 4510+#define T__theomirror_serious04 4511+#define T__theomirror_serious05 4512+#define T__theomirror_serious06 4513+#define T__theomirror_serious07 4514+#define T__theomirror_serious08 4515+#define T__theomirror_serious09 4516+#define T__theomirror_serious10 4517+#define T__ghost_normal00 4518+#define T__ghost_normal01 4519+#define T__ghost_normal02 4520+#define T__ghost_normal03 4521+#define T__ghost_normal04 4522+#define T__ghost_normal05 4523+#define T__ghost_normal06 4524+#define T__ghost_upset00 4525+#define T__ghost_upset01 4526+#define T__ghost_upset02 4527+#define T__ghost_upset03 4528+#define T__ghost_upset04 4529+#define T__ghost_upset05 4530+#define T__ghost_upset06 4531+#define T__ghost_scoff00 4532+#define T__ghost_scoff01 4533+#define T__ghost_scoff02 4534+#define T__ghost_scoff03 4535+#define T__ghost_scoff04 4536+#define T__ghost_scoff05 4537+#define T__ghost_scoff06 4538+#define T__ghost_scoff07 4539+#define T__ghost_scoff08 4540+#define T__ghost_scoff09 4541+#define T__ghost_scoff10 4542+#define T__ghost_scoff11 4543+#define T__ghost_scoff12 4544+#define T__ghost_scoff13 4545+#define T__ghost_serious00 4546+#define T__ghost_serious01 4547+#define T__ghost_serious02 4548+#define T__ghost_serious03 4549+#define T__ghost_serious04 4550+#define T__ghost_serious05 4551+#define T__ghost_serious06 4552+#define T__ghost_serious07 4553+#define T__ghost_serious08 4554+#define T__ghost_serious09 4555+#define T__ghost_serious10 4556+#define T__ghost_serious11 4557+#define T__ghost_serious12 4558+#define T__ghost_serious13 4559+#define T__ghost_serious14 4560+#define T__ghost_serious15 4561+#define T__ghost_serious16 4562+#define T__ghost_serious17 4563+#define T__ghost_serious18 4564+#define T__ghost_serious19 4565+#define T__ghost_serious20 4566+#define T__ghost_serious21 4567+#define T__ghost_serious22 4568+#define T__ghost_serious23 4569+#define T__ghost_serious24 4570+#define T__ghost_serious25 4571+#define T__ghost_serious26 4572+#define T__ghost_serious27 4573+#define T__ghost_serious28 4574+#define T__ghost_serious29 4575+#define T__ghost_angry00 4576+#define T__ghost_angry01 4577+#define T__ghost_angry02 4578+#define T__ghost_angry03 4579+#define T__ghost_angry04 4580+#define T__ghost_angry05 4581+#define T__ghost_angry06 4582+#define T__ghost_angryAlt00 4583+#define T__ghost_angryAlt01 4584+#define T__ghost_angryAlt02 4585+#define T__ghost_angryAlt03 4586+#define T__ghost_angryAlt04 4587+#define T__ghost_angryAlt05 4588+#define T__ghost_angryAlt06 4589+#define T__ghost_yell00 4590+#define T__ghost_yell01 4591+#define T__ghost_yell02 4592+#define T__ghost_yell03 4593+#define T__ghost_yell04 4594+#define T__ghost_yell05 4595+#define T__ghost_yell06 4596+#define T__ghost_worried00 4597+#define T__ghost_worried01 4598+#define T__ghost_worried02 4599+#define T__ghost_worried03 4600+#define T__ghost_worried04 4601+#define T__ghost_worried05 4602+#define T__ghost_worried06 4603+#define T__ghost_concerned00 4604+#define T__ghost_concerned01 4605+#define T__ghost_concerned02 4606+#define T__ghost_concerned03 4607+#define T__ghost_concerned04 4608+#define T__ghost_concerned05 4609+#define T__ghost_concerned06 4610+#define T__ghost_worriedAlt00 4611+#define T__ghost_worriedAlt01 4612+#define T__ghost_worriedAlt02 4613+#define T__ghost_worriedAlt03 4614+#define T__ghost_worriedAlt04 4615+#define T__ghost_worriedAlt05 4616+#define T__ghost_worriedAlt06 4617+#define T__ghost_sad00 4618+#define T__ghost_sad01 4619+#define T__ghost_sad02 4620+#define T__ghost_sad03 4621+#define T__ghost_sad04 4622+#define T__ghost_freakA00 4623+#define T__ghost_freakA01 4624+#define T__ghost_freakA02 4625+#define T__ghost_freakA03 4626+#define T__ghost_freakA04 4627+#define T__ghost_freakA05 4628+#define T__ghost_freakA06 4629+#define T__ghost_freakA07 4630+#define T__ghost_freakA08 4631+#define T__ghost_freakA09 4632+#define T__ghost_freakA10 4633+#define T__ghost_freakB00 4634+#define T__ghost_freakB01 4635+#define T__ghost_freakB02 4636+#define T__ghost_freakB03 4637+#define T__ghost_freakB04 4638+#define T__ghost_freakB05 4639+#define T__ghost_freakB06 4640+#define T__ghost_freakB07 4641+#define T__ghost_freakB08 4642+#define T__ghost_freakB09 4643+#define T__ghost_freakB10 4644+#define T__ghost_freakB11 4645+#define T__ghost_freakB12 4646+#define T__ghost_freakB13 4647+#define T__ghost_freakB14 4648+#define T__ghost_freakB15 4649+#define T__ghost_freakB16 4650+#define T__ghost_freakB17 4651+#define T__ghost_freakB18 4652+#define T__ghost_freakC00 4653+#define T__ghost_freakC01 4654+#define T__ghost_freakC02 4655+#define T__ghost_freakC03 4656+#define T__ghost_freakC04 4657+#define T__ghost_freakC05 4658+#define T__ghost_freakC06 4659+#define T__ghost_freakC07 4660+#define T__ghost_freakC08 4661+#define T__ghost_freakC09 4662+#define T__ghost_freakC10 4663+#define T__ghost_freakC11 4664+#define T__ghost_freakC12 4665+#define T__ghost_freakC13 4666+#define T__ghost_freakC14 4667+#define T__ghost_freakC15 4668+#define T__ghost_freakC16 4669+#define T__ghost_freakC17 4670+#define T__ghost_sigh00 4671+#define T__ghost_sigh01 4672+#define T__ghost_sigh02 4673+#define T__ghost_sigh03 4674+#define T__ghost_sigh04 4675+#define T__ghost_sigh05 4676+#define T__ghost_sigh06 4677+#define T__ghost_sigh07 4678+#define T__ghost_sigh08 4679+#define T__ghost_sigh09 4680+#define T__ghost_sigh10 4681+#define T__ghost_sigh11 4682+#define T__ghost_sigh12 4683+#define T__ghost_sigh13 4684+#define T__exph_normal00 4685+#define T__momph_normal00 4686+#define T__momph_normal01 4687+#define T__momph_normal02 4688+#define T__momph_normal03 4689+#define T__momph_normal04 4690+#define T__momph_normal05 4691+#define T__momph_normal06 4692+#define T__momph_concerned00 4693+#define T__momph_concerned01 4694+#define T__momph_concerned02 4695+#define T__momph_concerned03 4696+#define T__momph_concerned04 4697+#define T__momph_concerned05 4698+#define T__momph_concerned06 4699+#define T__oshiro_normal00 4700+#define T__oshiro_normal01 4701+#define T__oshiro_normal02 4702+#define T__oshiro_normal03 4703+#define T__oshiro_normal04 4704+#define T__oshiro_normal05 4705+#define T__oshiro_normal06 4706+#define T__oshiro_normal07 4707+#define T__oshiro_normal08 4708+#define T__oshiro_normal09 4709+#define T__oshiro_normal10 4710+#define T__oshiro_normal11 4711+#define T__oshiro_normal12 4712+#define T__oshiro_worried00 4713+#define T__oshiro_worried01 4714+#define T__oshiro_worried02 4715+#define T__oshiro_worried03 4716+#define T__oshiro_worried04 4717+#define T__oshiro_worried05 4718+#define T__oshiro_worried06 4719+#define T__oshiro_worried07 4720+#define T__oshiro_nervous00 4721+#define T__oshiro_nervous01 4722+#define T__oshiro_nervous02 4723+#define T__oshiro_nervous03 4724+#define T__oshiro_nervous04 4725+#define T__oshiro_nervous05 4726+#define T__oshiro_nervous06 4727+#define T__oshiro_nervous07 4728+#define T__oshiro_drama00 4729+#define T__oshiro_drama01 4730+#define T__oshiro_drama02 4731+#define T__oshiro_drama03 4732+#define T__oshiro_drama04 4733+#define T__oshiro_drama05 4734+#define T__oshiro_lostcontrol00 4735+#define T__oshiro_lostcontrol01 4736+#define T__oshiro_lostcontrol02 4737+#define T__oshiro_lostcontrol03 4738+#define T__oshiro_lostcontrol04 4739+#define T__oshiro_lostcontrol05 4740+#define T__oshiro_sidehappy00 4741+#define T__oshiro_sidehappy01 4742+#define T__oshiro_sidehappy02 4743+#define T__oshiro_sidehappy03 4744+#define T__oshiro_sidehappy04 4745+#define T__oshiro_sidehappy05 4746+#define T__oshiro_sidehappy06 4747+#define T__oshiro_sidehappy07 4748+#define T__oshiro_sideworried00 4749+#define T__oshiro_sideworried01 4750+#define T__oshiro_sideworried02 4751+#define T__oshiro_sideworried03 4752+#define T__oshiro_sideworried04 4753+#define T__oshiro_sideworried05 4754+#define T__oshiro_sideworried06 4755+#define T__oshiro_sideworried07 4756+#define T__oshiro_sideworried08 4757+#define T__oshiro_serious00 4758+#define T__oshiro_serious01 4759+#define T__oshiro_serious02 4760+#define T__oshiro_serious03 4761+#define T__oshiro_serious04 4762+#define T__oshiro_serious05 4763+#define T__oshiro_serious06 4764+#define T__oshiro_serious07 4765+#define T__oshiro_sidesuspicious00 4766+#define T__oshiro_sidesuspicious01 4767+#define T__oshiro_sidesuspicious02 4768+#define T__oshiro_sidesuspicious03 4769+#define T__oshiro_sidesuspicious04 4770+#define T__oshiro_sidesuspicious05 4771+#define T__oshiro_sidesuspicious06 4772+#define T__oshiro_sidesuspicious07 4773+#define T_tilesets_template 4774+#define T_tilesets_dirt 4775+#define T_tilesets_snow 4776+#define T_tilesets_girder 4777+#define T_tilesets_tower 4778+#define T_tilesets_stone 4779+#define T_tilesets_cement 4780+#define T_tilesets_rock 4781+#define T_tilesets_wood 4782+#define T_tilesets_woodStoneEdges 4783+#define T_tilesets_cliffside 4784+#define T_tilesets_poolEdges 4785+#define T_tilesets_templeA 4786+#define T_tilesets_templeB 4787+#define T_tilesets_cliffsideAlt 4788+#define T_tilesets_grass 4789+#define T_tilesets_summit 4790+#define T_tilesets_summitNoSnow 4791+#define T_tilesets_lostlevels 4792+#define T_tilesets_core 4793+#define T_tilesets_deadgrass 4794+#define T_tilesets_scifi 4795+#define T_tilesets_bgDirt 4796+#define T_tilesets_bgBrick 4797+#define T_tilesets_bgBrickRuined 4798+#define T_tilesets_bgWood 4799+#define T_tilesets_bgResortStone 4800+#define T_tilesets_bgCliffside 4801+#define T_tilesets_bgPool 4802+#define T_tilesets_bgTempleA 4803+#define T_tilesets_bgTempleB 4804+#define T_tilesets_bgReflection 4805+#define T_tilesets_bgSnow 4806+#define T_tilesets_bgSummit 4807+#define T_tilesets_bgCore 4808+#define T_tilesets_bgLostLevels 4809+#define T_tilesets_scenery 4810+#define T_danger_dustcreature_overlay00 4811+#define T_danger_dustcreature_overlay01 4812+#define T_danger_dustcreature_overlay02 4813+#define T_danger_dustcreature_templeeyes00 4814+#define T_danger_dustcreature_templeeyes01 4815+#define T_danger_dustcreature_templeeyes02 4816+#define T_danger_dustcreature_deadEyes 4817+#define T_bgs_00_bg0 4818+#define T_bgs_00_bg1 4819+#define T_bgs_00_bg2 4820+#define T_bgs_00_bg3 4821+#define T_bgs_00_fg0 4822+#define T_purplesunset 4823+#define T_bgs_01_bg0 4824+#define T_bgs_01_bg1 4825+#define T_bgs_01_bg2 4826+#define T_mist 4827+#define T_vignette 4828+#define T_bgs_03_bg0 4829+#define T_bgs_03_bg1 4830+#define T_bgs_04_bg0 4831+#define T_bgs_04_bg1 4832+#define T_bgs_04_bgc0 4833+#define T_bgs_04_bgc1 4834+#define T_bgs_04_bgc2 4835+#define T_bgs_04_bgc3 4836+#define T_bgs_04_bgc4 4837+#define T_bgs_03_bg2 4838+#define T_bgs_03_bg2b 4839+#define T_bgs_03_bg3 4840+#define T_bgs_03_bg3b 4841+#define T_bgs_03_fg0 4842+#define T_bgs_05_temple_bg0 4843+#define T_bgs_05_temple_bg1 4844+#define T_bgs_05_temple_bg2 4845+#define T_bgs_05_temple_bg3 4846+#define T_bgs_05_mirror_bg0 4847+#define T_bgs_05_mirror_bg1 4848+#define T_bgs_05_mirror_bg2 4849+#define T_bgs_05_mirror_bg3 4850+#define T_bgs_05_mirror_bg4 4851+#define T_bgs_05_mirror_bg5 4852+#define T_bgs_05_mirror_bg6 4853+#define T_bgs_05_mirror_fx0 4854+#define T_bgs_05_mirror_fx1 4855+#define T_bgs_06_bg0 4856+#define T_bgs_06_bg1 4857+#define T_bgs_06_fx0 4858+#define T_bgs_06_bg2 4859+#define T_bgs_06_plateau_bg0 4860+#define T_bgs_06_plateau_bg1 4861+#define T_darkswamp 4862+#define T_bgs_07_bg0 4863+#define T_bgs_07_00_bg1 4864+#define T_bgs_07_00_bg2 4865+#define T_bgs_07_01_bg1 4866+#define T_bgs_07_01_bg2 4867+#define T_bgs_07_01_bg3 4868+#define T_bgs_07_02_bg1 4869+#define T_bgs_07_02_bg2 4870+#define T_bgs_07_02_bg3 4871+#define T_bgs_07_03_bg1 4872+#define T_bgs_07_03_bg2 4873+#define T_bgs_07_04_bgc0 4874+#define T_bgs_07_04_bgc1 4875+#define T_bgs_07_04_bgc2 4876+#define T_bgs_07_04_bgc3 4877+#define T_bgs_07_04_bgc4 4878+#define T_bgs_07_07_bg00 4879+#define T_bgs_07_07_bg01 4880+#define T_bgs_07_07_bg02 4881+#define T_bgs_07_07_bg03 4882+#define T_bgs_07_07_bg04 4883+#define T_bgs_03_back 4884+#define T_bgs_09_bg0 4885+#define T_bgs_09_bg1 4886+#define T_bgs_09_bg2 4887+#define T_bgs_09_bg0_c 4888+#define T_bgs_09_bg1_c 4889+#define T_bgs_09_bg2_c 4890+#define T_decals_generic_grass_b 4891+#define T_decals_generic_grass_d 4892+#define T_decals_generic_grass_c 4893+#define T_decals_generic_grass_a 4894+#define T_decals_0_prologue_sign 4895+#define T_decals_1_forsakencity_leftArrowSign 4896+#define T_decals_generic_snow_c 4897+#define T_decals_0_prologue_axe 4898+#define T_decals_0_prologue_house 4899+#define T_decals_generic_hanginggrass_a 4900+#define T_decals_generic_snow_b 4901+#define T_decals_1_forsakencity_collumn_small_broken 4902+#define T_decals_1_forsakencity_collumn_small_E 4903+#define T_decals_1_forsakencity_Collumn_concrete_E_broken 4904+#define T_decals_1_forsakencity_sign_under_construction 4905+#define T_decals_1_forsakencity_box 4906+#define T_decals_generic_snow_e 4907+#define T_decals_generic_snow_d 4908+#define T_decals_generic_snow_g 4909+#define T_decals_generic_snow_h 4910+#define T_decals_1_forsakencity_windowA 4911+#define T_decals_1_forsakencity_posterE 4912+#define T_decals_1_forsakencity_posterA 4913+#define T_decals_1_forsakencity_ragsB 4914+#define T_decals_1_forsakencity_rags 4915+#define T_decals_generic_snow_a 4916+#define T_decals_generic_snow_f 4917+#define T_decals_1_forsakencity_posterC 4918+#define T_decals_1_forsakencity_posterB 4919+#define T_decals_1_forsakencity_windowB 4920+#define T_decals_1_forsakencity_collumn_small_broken_b 4921+#define T_decals_1_forsakencity_box_and_bottle 4922+#define T_decals_1_forsakencity_collumn_small_mid 4923+#define T_decals_1_forsakencity_post_extra_broken 4924+#define T_decals_1_forsakencity_Collumn_concrete_E_less_broken 4925+#define T_decals_1_forsakencity_old_lamp 4926+#define T_decals_1_forsakencity_sign_foward 4927+#define T_decals_1_forsakencity_Collumn_concrete_E_very_broken 4928+#define T_decals_1_forsakencity_big_sign_c 4929+#define T_decals_1_forsakencity_posterD 4930+#define T_decals_1_forsakencity_paint_buckets 4931+#define T_decals_1_forsakencity_windowC 4932+#define T_decals_1_forsakencity_Collumn_concrete_E 4933+#define T_decals_1_forsakencity_Collumn_concrete_mid 4934+#define T_decals_1_forsakencity_Collumn_concrete_mid_broken 4935+#define T_decals_1_forsakencity_Collumn_concrete_mid_broken_E 4936+#define T_decals_1_forsakencity_trafic_lights_ceiling_busted 4937+#define T_decals_1_forsakencity_bench_concrete_snow 4938+#define T_decals_generic_snow_j 4939+#define T_decals_1_forsakencity_ladder 4940+#define T_decals_1_forsakencity_sign_you_can_park 4941+#define T_decals_1_forsakencity_sign_you_can_t_go_up 4942+#define T_decals_1_forsakencity_sign_you_can_t_dash 4943+#define T_decals_1_forsakencity_poted_plant 4944+#define T_decals_1_forsakencity_trafic_lights_ceiling 4945+#define T_decals_1_forsakencity_trafic_lights 4946+#define T_decals_1_forsakencity_bench_concrete 4947+#define T_decals_1_forsakencity_post_broken 4948+#define T_decals_1_forsakencity_brazilian_coffee_building 4949+#define T_decals_1_forsakencity_big_sign_e 4950+#define T_decals_1_forsakencity_sign_you_can_go_down 4951+#define T_decals_1_forsakencity_sign_slippery 4952+#define T_decals_1_forsakencity_big_sign_b 4953+#define T_decals_1_forsakencity_broken_plane 4954+#define T_decals_1_forsakencity_camping_medium 4955+#define T_decals_1_forsakencity_sign_rockslide 4956+#define T_decals_1_forsakencity_big_sign_d 4957+#define T_decals_1_forsakencity_car_ruined 4958+#define T_decals_1_forsakencity_big_sign_f 4959+#define T_decals_1_forsakencity_hanging_sign 4960+#define T_decals_1_forsakencity_big_sign 4961+#define T_decals_1_forsakencity_sign_you_can_go_right 4962+#define T_decals_generic_snow_i 4963+#define T_decals_1_forsakencity_hydrant 4964+#define T_decals_1_forsakencity_sign_you_can_go_up 4965+#define T_decals_2_oldsite_cage_modular_midC 4966+#define T_decals_2_oldsite_cage_modular_midB 4967+#define T_decals_2_oldsite_door 4968+#define T_decals_2_oldsite_window 4969+#define T_decals_2_oldsite_window_boarded 4970+#define T_decals_2_oldsite_table_broken 4971+#define T_decals_2_oldsite_cloth_pole00 4972+#define T_decals_2_oldsite_pilar_vertical_endC 4973+#define T_decals_2_oldsite_pilar_verticalA 4974+#define T_decals_2_oldsite_pilar_instersection_small 4975+#define T_decals_2_oldsite_barrel_brokenA 4976+#define T_decals_2_oldsite_barrel 4977+#define T_decals_2_oldsite_barrel_brokenB 4978+#define T_decals_2_oldsite_cage_modular_midA 4979+#define T_decals_2_oldsite_pilar_vertical_endA 4980+#define T_decals_2_oldsite_pilar_instersection_smallB 4981+#define T_decals_2_oldsite_pilar_vertical_endB 4982+#define T_decals_2_oldsite_pilar_hA 4983+#define T_decals_2_oldsite_pilar_h_endA 4984+#define T_decals_2_oldsite_pilar_hC 4985+#define T_decals_2_oldsite_pilar_hB 4986+#define T_decals_2_oldsite_simple_pole 4987+#define T_decals_2_oldsite_tableA 4988+#define T_decals_2_oldsite_chair 4989+#define T_decals_2_oldsite_chained_cage 4990+#define T_decals_2_oldsite_pilar_diagonalB 4991+#define T_decals_2_oldsite_pilar_verticalB 4992+#define T_decals_2_oldsite_tableB 4993+#define T_decals_2_oldsite_cage_modular_midD 4994+#define T_decals_2_oldsite_chair_old 4995+#define T_decals_2_oldsite_chair_broken 4996+#define T_decals_2_oldsite_medium_cage_broken 4997+#define T_decals_2_oldsite_tableC 4998+#define T_decals_2_oldsite_chain_broken 4999+#define T_decals_2_oldsite_chain_mid 5000+#define T_decals_2_oldsite_pilar_h_endB 5001+#define T_decals_2_oldsite_cage_modular_bot 5002+#define T_decals_1_forsakencity_informationKiosk 5003+#define T_decals_1_forsakencity_skelly 5004+#define T_decals_1_forsakencity_cook_pot 5005+#define T_decals_2_oldsite_medium_cage 5006+#define T_decals_1_forsakencity_flag00 5007+#define T_decals_2_oldsite_cage_modular_top 5008+#define T_decals_2_oldsite_tableD 5009+#define T_decals_3_resort_vent 5010+#define T_decals_3_resort_fgtilehole 5011+#define T_decals_3_resort_cobweb 5012+#define T_decals_3_resort_cobweb_b 5013+#define T_decals_3_resort_curtain_side_c 5014+#define T_decals_3_resort_window 5015+#define T_decals_3_resort_curtain_side_a 5016+#define T_decals_3_resort_curtain_center_a 5017+#define T_decals_3_resort_curtain_side_d 5018+#define T_decals_3_resort_painting_a 5019+#define T_decals_3_resort_bgtilehole 5020+#define T_decals_3_resort_chandelier_b 5021+#define T_decals_3_resort_carpet_left_a 5022+#define T_decals_3_resort_carpet_inner_a 5023+#define T_decals_3_resort_carpet_inner_b 5024+#define T_decals_3_resort_bgtilehole_e 5025+#define T_decals_3_resort_bgtilehole_d 5026+#define T_decals_3_resort_window_broken_b 5027+#define T_decals_3_resort_window_broken_a 5028+#define T_decals_3_resort_painting_c 5029+#define T_decals_3_resort_head_trophy_a 5030+#define T_decals_3_resort_chair_a 5031+#define T_decals_3_resort_bedstand_a 5032+#define T_decals_3_resort_laundry_c 5033+#define T_decals_3_resort_laundry_a 5034+#define T_decals_3_resort_painting_b 5035+#define T_decals_3_resort_bed_b 5036+#define T_decals_3_resort_bed_a 5037+#define T_decals_3_resort_brokenbox_d 5038+#define T_decals_3_resort_bench_a 5039+#define T_decals_3_resort_bench_b 5040+#define T_decals_3_resort_chair_b 5041+#define T_decals_3_resort_laundry_d 5042+#define T_decals_3_resort_bgtilehole_b 5043+#define T_decals_3_resort_bgtilehole_c 5044+#define T_decals_3_resort_bgtilehole_f 5045+#define T_decals_3_resort_carpet_top_a 5046+#define T_decals_3_resort_carpet_innercorner_a 5047+#define T_decals_3_resort_curtain_side_b 5048+#define T_decals_3_resort_brokenwood_bottom 5049+#define T_decals_3_resort_brokenwood 5050+#define T_decals_3_resort_painting_g 5051+#define T_decals_3_resort_bed_c 5052+#define T_decals_3_resort_bench 5053+#define T_decals_3_resort_curtain_center_b 5054+#define T_decals_3_resort_painting_f 5055+#define T_decals_3_resort_painting_e 5056+#define T_decals_3_resort_chair_c 5057+#define T_decals_3_resort_table_b 5058+#define T_decals_3_resort_cabinet_b 5059+#define T_decals_3_resort_granfather_clock00 5060+#define T_decals_3_resort_storageshelf_mid_c 5061+#define T_decals_3_resort_laundry_b 5062+#define T_decals_3_resort_washing_machine_a 5063+#define T_decals_3_resort_washing_machine_b 5064+#define T_decals_3_resort_bucket_a 5065+#define T_decals_3_resort_storageshelf_mid_b 5066+#define T_decals_3_resort_storageshelf_mid_a 5067+#define T_decals_3_resort_storageshelf_top_a 5068+#define T_decals_3_resort_sticks 5069+#define T_decals_3_resort_pipe_bot_a 5070+#define T_decals_3_resort_pipe_vert_a 5071+#define T_decals_3_resort_pipe_top_a 5072+#define T_decals_3_resort_pipe_turn_b 5073+#define T_decals_3_resort_pipe_turn_a 5074+#define T_decals_3_resort_pipe_vert_b 5075+#define T_decals_3_resort_pipe_vert_c 5076+#define T_decals_3_resort_pipe_turn_d 5077+#define T_decals_3_resort_pipe_horz 5078+#define T_decals_3_resort_pipe_turn_c 5079+#define T_decals_3_resort_gold_railingCenter 5080+#define T_decals_3_resort_gold_railingRight 5081+#define T_decals_3_resort_gold_railingLeft 5082+#define T_decals_3_resort_gold_railingCenterBrokenB 5083+#define T_decals_3_resort_bedstand_b 5084+#define T_decals_3_resort_piano 5085+#define T_decals_3_resort_carpet_corner_a 5086+#define T_decals_3_resort_bridgeBack 5087+#define T_decals_3_resort_bridgeBackBrokenC 5088+#define T_decals_3_resort_guestbook 5089+#define T_decals_3_resort_bellhopcart_a 5090+#define T_decals_3_resort_chandelier_a 5091+#define T_decals_3_resort_bookshelf_bl_a 5092+#define T_decals_3_resort_bookshelf_bm_a 5093+#define T_decals_3_resort_bookshelf_br_a 5094+#define T_decals_3_resort_bookshelf_mr_a 5095+#define T_decals_3_resort_bookshelf_mm_c 5096+#define T_decals_3_resort_bookshelf_ml_a 5097+#define T_decals_3_resort_bookshelf_mm_d 5098+#define T_decals_3_resort_bookshelf_tm_a 5099+#define T_decals_3_resort_bookshelf_tr_a 5100+#define T_decals_3_resort_bookshelf_tl_a 5101+#define T_decals_3_resort_cabinet_a 5102+#define T_decals_3_resort_bookshelf_mm_e 5103+#define T_decals_3_resort_bookshelf_mm_a 5104+#define T_decals_3_resort_bookshelf_mm_b 5105+#define T_decals_3_resort_boilder_a 5106+#define T_decals_3_resort_trashcan_a 5107+#define T_decals_3_resort_lifesaver 5108+#define T_decals_3_resort_carpet_inner_c 5109+#define T_decals_3_resort_brokenelevatortop 5110+#define T_decals_3_resort_brokenelevator 5111+#define T_decals_3_resort_bridgebackPost 5112+#define T_decals_3_resort_desk 5113+#define T_decals_3_resort_keyrack 5114+#define T_decals_3_resort_painting_d 5115+#define T_decals_3_resort_hangshelf_a 5116+#define T_decals_3_resort_cloth_a 5117+#define T_decals_generic_snow_k 5118+#define T_decals_3_resort_bridgeBackBrokenE 5119+#define T_decals_3_resort_bridgeBackBrokenD 5120+#define T_decals_3_resort_bridgeBackBrokenB 5121+#define T_decals_3_resort_bridgeBackBrokenG 5122+#define T_decals_3_resort_bridgeBackBrokenA 5123+#define T_decals_3_resort_bridgeBackBrokenH 5124+#define T_decals_3_resort_bridgeBackBrokenF 5125+#define T_decals_3_resort_roofEdge_b 5126+#define T_decals_3_resort_roofEdge_c 5127+#define T_decals_3_resort_debris_roof_a 5128+#define T_decals_3_resort_debris_roof_b 5129+#define T_decals_3_resort_bridgebackPostBroken 5130+#define T_decals_3_resort_debris_roof_c 5131+#define T_decals_3_resort_debris_roof_d 5132+#define T_decals_3_resort_bridgeColumnTop 5133+#define T_decals_3_resort_bridgeColumn 5134+#define T_decals_3_resort_bridgeColumnTopBg 5135+#define T_decals_3_resort_bridgeColumnBg 5136+#define T_decals_3_resort_railingCenter 5137+#define T_decals_3_resort_railingCenterBrokenA 5138+#define T_decals_3_resort_railingCenterBrokenB 5139+#define T_decals_3_resort_railingLeft 5140+#define T_decals_3_resort_railingRight 5141+#define T_decals_generic_snow_l 5142+#define T_decals_generic_snow_m 5143+#define T_decals_generic_snow_n 5144+#define T_decals_3_resort_table_a 5145+#define T_decals_4_cliffside_flower_c 5146+#define T_decals_4_cliffside_flower_b 5147+#define T_decals_4_cliffside_rubble_i 5148+#define T_decals_4_cliffside_rubble_j 5149+#define T_decals_4_cliffside_rubble_a 5150+#define T_decals_4_cliffside_flower_a 5151+#define T_decals_4_cliffside_rock_d 5152+#define T_decals_4_cliffside_flower_d 5153+#define T_decals_4_cliffside_tree_b 5154+#define T_decals_4_cliffside_rubble_b 5155+#define T_decals_4_cliffside_bg_b 5156+#define T_decals_4_cliffside_rubble_g 5157+#define T_decals_4_cliffside_rubble_c 5158+#define T_decals_4_cliffside_rubble_e 5159+#define T_decals_4_cliffside_woodbean_h 5160+#define T_decals_4_cliffside_tree_d 5161+#define T_decals_4_cliffside_rock_a 5162+#define T_decals_4_cliffside_rock_b 5163+#define T_decals_4_cliffside_woodbeam_k 5164+#define T_decals_4_cliffside_woodbeam_i 5165+#define T_decals_4_cliffside_woodbeam_d 5166+#define T_decals_4_cliffside_rubble_d 5167+#define T_decals_4_cliffside_bg_c 5168+#define T_decals_4_cliffside_bg_d 5169+#define T_decals_4_cliffside_bridge_a 5170+#define T_decals_4_cliffside_rock_e 5171+#define T_decals_4_cliffside_woodbeam_h 5172+#define T_decals_4_cliffside_woodbeam_l 5173+#define T_decals_4_cliffside_woodbeam_j 5174+#define T_decals_4_cliffside_woodbeam_f 5175+#define T_decals_4_cliffside_bg_e 5176+#define T_decals_4_cliffside_bg_a 5177+#define T_decals_4_cliffside_rubble_f 5178+#define T_decals_4_cliffside_ruleboard 5179+#define T_decals_4_cliffside_woodbeam_b 5180+#define T_decals_4_cliffside_woodbeam_a 5181+#define T_decals_4_cliffside_bridge_c 5182+#define T_decals_4_cliffside_house_b 5183+#define T_decals_4_cliffside_woodbeam_e 5184+#define T_decals_4_cliffside_woodbeam_c 5185+#define T_decals_4_cliffside_woodbeam_g 5186+#define T_decals_4_cliffside_rubble_h 5187+#define T_danger_crystal_fg_blue00 5188+#define T_danger_crystal_fg_blue01 5189+#define T_danger_crystal_fg_blue02 5190+#define T_danger_crystal_fg_blue03 5191+#define T_danger_crystal_bg_blue00 5192+#define T_danger_crystal_fg_blue00_border 5193+#define T_danger_crystal_fg_blue01_border 5194+#define T_danger_crystal_fg_blue02_border 5195+#define T_danger_crystal_fg_blue03_border 5196+#define T_danger_crystal_bg_blue00_border 5197+#define T_decals_4_cliffside_roots_a 5198+#define T_decals_4_cliffside_roots_b 5199+#define T_decals_4_cliffside_roots_bot_a 5200+#define T_decals_4_cliffside_tree_a 5201+#define T_decals_4_cliffside_roots_c 5202+#define T_decals_4_cliffside_roots_bot_b 5203+#define T_decals_4_cliffside_house_a 5204+#define T_decals_4_cliffside_bg_f 5205+#define T_decals_4_cliffside_tree_c 5206+#define T_decals_4_cliffside_rock_c 5207+#define T_decals_5_temple_bricks_a 5208+#define T_decals_5_temple_hole_a 5209+#define T_decals_5_temple_bg_mirror_shard_d 5210+#define T_decals_5_temple_bg_mirror_shard_a 5211+#define T_decals_5_temple_bg_mirror_shard_e 5212+#define T_decals_5_temple_bg_mirror_shard_b 5213+#define T_decals_5_temple_bg_mirror_shard_c 5214+#define T_decals_5_temple_bg_symbols_h_f 5215+#define T_decals_5_temple_bg_symbols_h_g 5216+#define T_decals_5_temple_bg_symbols_h_e 5217+#define T_decals_5_temple_bg_mirror_shard_group_a 5218+#define T_decals_5_temple_bg_mirror_shard_group_e 5219+#define T_decals_5_temple_bg_mirror_shard_group_c 5220+#define T_decals_5_temple_bg_mirror_shard_group_b 5221+#define T_decals_5_temple_bg_mirror_shard_f 5222+#define T_decals_5_temple_bg_mirror_shard_k 5223+#define T_decals_5_temple_bg_mirror_shard_i 5224+#define T_decals_5_temple_collumn_top 5225+#define T_decals_5_temple_collumn_mid_c 5226+#define T_decals_5_temple_collumn_mid_d 5227+#define T_decals_5_temple_rubble_d 5228+#define T_decals_5_temple_rubble_l 5229+#define T_decals_5_temple_bg_symbols_v_c 5230+#define T_decals_5_temple_bg_symbols_v_e 5231+#define T_decals_5_temple_bg_symbols_v_b 5232+#define T_decals_5_temple_bg_mirror_shard_group_d 5233+#define T_decals_5_temple_bg_symbols_v_d 5234+#define T_decals_5_temple_bg_symbols_v_g 5235+#define T_decals_5_temple_bg_symbols_c_b 5236+#define T_decals_5_temple_bg_symbols_h_h 5237+#define T_decals_5_temple_bg_symbols_v_f 5238+#define T_decals_5_temple_bg_mirror_shard_h 5239+#define T_decals_5_temple_bg_mirror_shard_j 5240+#define T_decals_5_temple_broken_arch 5241+#define T_decals_5_temple_bg_symbols_c_a 5242+#define T_decals_5_temple_bg_symbols_v_a 5243+#define T_decals_5_temple_bg_mirror_c 5244+#define T_decals_5_temple_bg_mirror_b 5245+#define T_decals_5_temple_bg_symbols_h_a 5246+#define T_decals_5_temple_bg_symbols_h_d 5247+#define T_decals_5_temple_bg_eye_a 5248+#define T_decals_5_temple_statue_a 5249+#define T_decals_5_temple_collumn_bot 5250+#define T_decals_5_temple_rubble_b 5251+#define T_decals_5_temple_rubble_c 5252+#define T_decals_5_temple_rubble_e 5253+#define T_decals_5_temple_rubble_g 5254+#define T_decals_5_temple_rubble_a 5255+#define T_decals_5_temple_bricks_b 5256+#define T_decals_5_temple_bg_mirror_a 5257+#define T_decals_5_temple_bg_eye_b 5258+#define T_decals_5_temple_rubble_f 5259+#define T_decals_5_temple_bg_mirror_shard_group_a_b 5260+#define T_decals_5_temple_bg_mirror_shard_group_a_c 5261+#define T_decals_5_temple_rubble_m 5262+#define T_decals_5_temple_rubble_n 5263+#define T_decals_5_temple_rubble_j 5264+#define T_decals_5_temple_rubble_h 5265+#define T_decals_5_temple_statue_b 5266+#define T_decals_5_temple_collumn_mid_a 5267+#define T_decals_5_temple_collumn_mid_b 5268+#define T_decals_5_temple_hole_b 5269+#define T_decals_5_temple_bg_symbols_h_b 5270+#define T_decals_5_temple_collumn_broken_top 5271+#define T_decals_5_temple_bg_mirror_shard_g 5272+#define T_decals_5_temple_bg_symbols_h_c 5273+#define T_decals_5_temple_collumn_broken_bot 5274+#define T_danger_crystal_fg_red00 5275+#define T_danger_crystal_fg_red01 5276+#define T_danger_crystal_fg_red02 5277+#define T_danger_crystal_fg_red03 5278+#define T_danger_crystal_bg_red00 5279+#define T_danger_crystal_fg_red00_border 5280+#define T_danger_crystal_fg_red01_border 5281+#define T_danger_crystal_fg_red02_border 5282+#define T_danger_crystal_fg_red03_border 5283+#define T_danger_crystal_bg_red00_border 5284+#define T_decals_5_temple_statue_a_c 5285+#define T_decals_5_temple_statue_a_b 5286+#define T_decals_5_temple_crystal_c 5287+#define T_decals_5_temple_huge_bg_eye 5288+#define T_decals_5_temple_altar 5289+#define T_decals_5_temple_rubble_i 5290+#define T_decals_5_temple_statue_d 5291+#define T_decals_5_temple_rubble_k 5292+#define T_decals_5_temple_Mosaic_a 5293+#define T_decals_5_temple_rubble_p 5294+#define T_decals_5_temple_rubble_o 5295+#define T_decals_5_temple_rubble_q 5296+#define T_decals_5_temple_vine_a 5297+#define T_decals_5_temple_vine_b 5298+#define T_decals_5_temple_vine_c 5299+#define T_decals_5_temple_statue_e 5300+#define T_decals_5_temple_vine_e 5301+#define T_decals_5_temple_vine_d 5302+#define T_decals_5_temple_vine_g 5303+#define T_decals_5_temple_vine_f 5304+#define T_decals_5_temple_vine_h 5305+#define T_decals_5_temple_vine_k 5306+#define T_decals_5_temple_weird_eye_hole 5307+#define T_decals_5_temple_bg_tile_a 5308+#define T_decals_5_temple_bg_tile_b 5309+#define T_decals_5_temple_vine_j 5310+#define T_decals_5_temple_statue_f 5311+#define T_decals_5_temple_vine_i 5312+#define T_decals_5_temple_chest_a 5313+#define T_decals_5_temple_chair_a 5314+#define T_decals_5_temple_statue_c 5315+#define T_decals_5_temple_dark_bg_symbols_v_e 5316+#define T_decals_5_temple_dark_bg_symbols_v_d 5317+#define T_decals_5_temple_dark_bg_symbols_v_g 5318+#define T_decals_5_temple_dark_bg_symbols_v_c 5319+#define T_decals_5_temple_dark_bg_symbols_v_f 5320+#define T_decals_5_temple_dark_vine_h 5321+#define T_decals_5_temple_dark_vine_k 5322+#define T_decals_5_temple_dark_vine_j 5323+#define T_decals_5_temple_dark_vine_c 5324+#define T_decals_5_temple_dark_vine_i 5325+#define T_decals_5_temple_dark_vine_f 5326+#define T_decals_5_temple_dark_vine_b 5327+#define T_decals_5_temple_dark_vine_g 5328+#define T_decals_5_temple_dark_Mosaic_b 5329+#define T_decals_5_temple_dark_bg_symbols_h_e 5330+#define T_decals_5_temple_dark_bg_symbols_c_b 5331+#define T_decals_5_temple_dark_bg_symbols_h_c 5332+#define T_decals_5_temple_dark_bg_symbols_c_a 5333+#define T_decals_5_temple_dark_rubble_j 5334+#define T_decals_5_temple_dark_rubble_e 5335+#define T_decals_5_temple_dark_rubble_b 5336+#define T_decals_5_temple_dark_rubble_f 5337+#define T_decals_5_temple_dark_rubble_i 5338+#define T_decals_5_temple_dark_rubble_n 5339+#define T_decals_5_temple_dark_rubble_l 5340+#define T_decals_5_temple_dark_bg_claw_b 5341+#define T_decals_5_temple_dark_hole_b 5342+#define T_decals_5_temple_dark_rubble_p 5343+#define T_decals_5_temple_dark_column_c 5344+#define T_decals_5_temple_dark_column_b 5345+#define T_decals_5_temple_dark_column_a 5346+#define T_decals_5_temple_dark_bg_symbols_h_a 5347+#define T_decals_5_temple_dark_bg_symbols_h_f 5348+#define T_decals_5_temple_dark_bg_symbols_h_d 5349+#define T_decals_5_temple_dark_bg_symbols_h_h 5350+#define T_decals_5_temple_dark_rubble_h 5351+#define T_decals_5_temple_dark_vine_d 5352+#define T_decals_5_temple_dark_rubble_o 5353+#define T_decals_5_temple_dark_bg_symbols_h_b 5354+#define T_decals_5_temple_dark_bg_tile_b 5355+#define T_decals_5_temple_dark_bg_tile_a 5356+#define T_decals_5_temple_dark_bg_tile_c 5357+#define T_decals_5_temple_dark_rubble_d 5358+#define T_decals_5_temple_dark_hole_a 5359+#define T_decals_5_temple_dark_vine_e 5360+#define T_decals_5_temple_dark_column_d 5361+#define T_decals_5_temple_dark_rubble_g 5362+#define T_decals_5_temple_dark_rubble_k 5363+#define T_decals_5_temple_dark_bg_symbols_v_a 5364+#define T_decals_5_temple_dark_rubble_c 5365+#define T_decals_5_temple_dark_bg_symbols_v_b 5366+#define T_decals_5_temple_dark_column_e 5367+#define T_decals_5_temple_dark_rubble_a 5368+#define T_decals_5_temple_dark_Mosaic_c 5369+#define T_decals_5_temple_dark_Mosaic_a 5370+#define T_decals_5_temple_dark_bg_symbols_h_g 5371+#define T_decals_5_temple_track00 5372+#define T_decals_5_temple_dark_rubble_q 5373+#define T_decals_5_temple_dark_bg_symbols_c_d 5374+#define T_decals_5_temple_dark_vine_a 5375+#define T_decals_5_temple_dark_rubble_m 5376+#define T_decals_5_temple_dark_bg_symbols_c_c 5377+#define T_decals_5_temple_dark_bg_claw_c 5378+#define T_decals_5_temple_Mosaic_b 5379+#define T_decals_5_temple_Mosaic_c 5380+#define T_decals_5_temple_crystal_a 5381+#define T_decals_5_temple_crystal_b 5382+#define T_decals_6_reflection_dead_fish_a 5383+#define T_decals_6_reflection_short_grass_d 5384+#define T_decals_6_reflection_short_grass_b 5385+#define T_decals_6_reflection_long_grass 5386+#define T_decals_6_reflection_crystal_reflection 5387+#define T_decals_6_reflection_crystal_a 5388+#define T_decals_6_reflection_short_grass_c 5389+#define T_decals_6_reflection_collumn_top_a 5390+#define T_decals_6_reflection_ceiling_slime 5391+#define T_decals_6_reflection_top_vine_a 5392+#define T_decals_6_reflection_top_vine_b 5393+#define T_decals_6_reflection_big_crystal_a 5394+#define T_decals_6_reflection_crystal_b 5395+#define T_decals_6_reflection_crystal_c 5396+#define T_decals_6_reflection_crystal_shard_a 5397+#define T_decals_6_reflection_bulb_plant 5398+#define T_decals_6_reflection_big_vine 5399+#define T_decals_6_reflection_crystal_shard_b 5400+#define T_decals_6_reflection_crystal_shard_e 5401+#define T_decals_6_reflection_crystal_rock_a 5402+#define T_decals_6_reflection_algae_b 5403+#define T_decals_6_reflection_rubble_a 5404+#define T_decals_6_reflection_rubble_i 5405+#define T_decals_6_reflection_rubble_g 5406+#define T_decals_6_reflection_rubble_j 5407+#define T_decals_6_reflection_collumn_base_top_a 5408+#define T_decals_6_reflection_collumn_mid_d 5409+#define T_decals_6_reflection_collumn_mid_a 5410+#define T_decals_6_reflection_collumn_mid_c 5411+#define T_decals_6_reflection_collumn_mid_b 5412+#define T_decals_6_reflection_collumn_base_bot_a 5413+#define T_decals_6_reflection_collumn_bot_a 5414+#define T_decals_6_reflection_crystal_shard_c 5415+#define T_decals_6_reflection_big_crystal_b 5416+#define T_decals_6_reflection_crystal_shard_d 5417+#define T_decals_6_reflection_grass_fall_a 5418+#define T_decals_6_reflection_short_grass_a 5419+#define T_decals_6_reflection_moss_a 5420+#define T_decals_6_reflection_bulb_plant_b 5421+#define T_decals_6_reflection_bulb_plant_c 5422+#define T_decals_6_reflection_rubble_h 5423+#define T_decals_6_reflection_fruits_a 5424+#define T_decals_6_reflection_flower_a 5425+#define T_decals_6_reflection_flower_b 5426+#define T_danger_crystal_fg_purple00 5427+#define T_danger_crystal_fg_purple01 5428+#define T_danger_crystal_fg_purple02 5429+#define T_danger_crystal_fg_purple03 5430+#define T_danger_crystal_bg_purple00 5431+#define T_danger_crystal_fg_purple00_border 5432+#define T_danger_crystal_fg_purple01_border 5433+#define T_danger_crystal_fg_purple02_border 5434+#define T_danger_crystal_fg_purple03_border 5435+#define T_danger_crystal_bg_purple00_border 5436+#define T_decals_6_reflection_big_vine_b 5437+#define T_decals_6_reflection_rubble_d 5438+#define T_decals_6_reflection_rubble_b 5439+#define T_decals_6_reflection_crystal_plant_a 5440+#define T_decals_6_reflection_big_crystal_vine 5441+#define T_decals_6_reflection_rubble_k 5442+#define T_decals_6_reflection_rubble_e 5443+#define T_decals_6_reflection_algae_a 5444+#define T_decals_6_reflection_mushroom_a 5445+#define T_decals_6_reflection_mushroom_c 5446+#define T_decals_6_reflection_mushroom_b 5447+#define T_decals_6_reflection_mushroom_d 5448+#define T_decals_6_reflection_mushroom_e 5449+#define T_decals_6_reflection_Elevator 5450+#define T_decals_6_reflection_elavator_cable 5451+#define T_decals_6_reflection_secret_towerfall00 5452+#define T_decals_6_reflection_secret_ogmo00 5453+#define T_decals_6_reflection_secret_yuri00 5454+#define T_decals_6_reflection_secret_skytorn00 5455+#define T_decals_6_reflection_secret_eyebat00 5456+#define T_decals_6_reflection_rubble_c 5457+#define T_decals_6_reflection_Wood_a 5458+#define T_decals_6_reflection_rubble_f 5459+#define T_decals_7_summit_cloud_f 5460+#define T_decals_7_summit_cloud_a 5461+#define T_decals_7_summit_cloud_e 5462+#define T_decals_7_summit_cloud_cc 5463+#define T_decals_7_summit_cloud_bb 5464+#define T_decals_7_summit_cloud_bc 5465+#define T_decals_7_summit_cloud_d 5466+#define T_decals_7_summit_cloud_b 5467+#define T_decals_7_summit_cloud_db 5468+#define T_decals_7_summit_cloud_c 5469+#define T_decals_7_summit_cloud_dc 5470+#define T_decals_7_summit_cloud_cb 5471+#define T_decals_5_temple_squid_head_a 5472+#define T_decals_7_summit_cloud_cd 5473+#define T_decals_7_summit_cloud_dd 5474+#define T_decals_7_summit_cloud_ce 5475+#define T_decals_7_summit_SummitFlag00 5476+#define T_decals_7_summit_cherry_tree 5477+#define T_decals_8_epilogue_table_a 5478+#define T_decals_8_epilogue_housebg 5479+#define T_decals_8_epilogue_backpack 5480+#define T_decals_8_epilogue_nest_front 5481+#define T_decals_generic_algae_d 5482+#define T_decals_generic_algae_a 5483+#define T_decals_generic_algae_e 5484+#define T_decals_generic_algae_c 5485+#define T_decals_8_epilogue_nest_back 5486+#define T_decals_9_core_stalagtite_b 5487+#define T_decals_9_core_stalagtite 5488+#define T_decals_9_core_column_mid_a 5489+#define T_decals_9_core_column_mid_d 5490+#define T_decals_9_core_stalagtite_c 5491+#define T_decals_9_core_stalagtite_d 5492+#define T_decals_9_core_column_mid_b 5493+#define T_decals_9_core_column_top 5494+#define T_decals_9_core_column_bot_b 5495+#define T_decals_9_core_heart_bevel_a 5496+#define T_decals_9_core_heart_bevel_b 5497+#define T_decals_9_core_heart_bevel_c 5498+#define T_decals_9_core_column_bot_a 5499+#define T_decals_9_core_rock_d 5500+#define T_decals_9_core_rock_b 5501+#define T_decals_9_core_fossil_a 5502+#define T_decals_9_core_rope_a 5503+#define T_decals_9_core_rock_a 5504+#define T_decals_9_core_rubble_b 5505+#define T_decals_9_core_rubble_j 5506+#define T_decals_9_core_rubble_i 5507+#define T_decals_9_core_capsule_a 5508+#define T_decals_9_core_rock_c 5509+#define T_decals_9_core_rubble_d 5510+#define T_decals_9_core_column_mid_c 5511+#define T_decals_9_core_heart_bevel_d 5512+#define T_decals_9_core_machine_a 5513+#define T_decals_9_core_rubble_k 5514+#define T_decals_9_core_rubble_l 5515+#define T_decals_9_core_fossil_b 5516+#define T_decals_9_core_rock_e 5517+#define T_decals_9_core_heart_b 5518+#define T_decals_9_core_rubble_q 5519+#define T_decals_9_core_column_top_b 5520+#define T_decals_9_core_capsule_b 5521+#define T_decals_9_core_capsule_c 5522+#define T_decals_9_core_rubble_h 5523+#define T_decals_9_core_rubble_o 5524+#define T_decals_9_core_Chain_top 5525+#define T_decals_9_core_chain_mid_a 5526+#define T_decals_9_core_chain_bot 5527+#define T_decals_9_core_rubble_g 5528+#define T_decals_9_core_heart_a 5529+#define T_decals_9_core_rubble_c 5530+#define T_decals_9_core_rubble_n 5531+#define T_decals_9_core_heart_sphere_a 5532+#define T_decals_9_core_rubble_p 5533+#define T_decals_9_core_rubble_m 5534+#define T_decals_9_core_rubble_f 5535+#define T_decals_9_core_ball_a 5536+#define T_decals_9_core_chain_mid_b 5537+#define T_decals_9_core_stump_a 5538+#define T_decals_9_core_rubble_e 5539+#define T_decals_9_core_rubble_a 5540+#define T_decals_9_core_nevoa_shovel 5541+#define T_decals_9_core_Chain_heart_top 5542+#define T_decals_9_core_rock_e_ice 5543+#define TEX_COUNT 5544+#define ROOM_POOL_BYTES 19448 /* 7-Summit:g-00b+g-01 */+#define SG_parallax 0+#define SG_snowFg 1+#define SG_snowBg 2+#define SG_windsnow 3+#define SG_stars 4+#define SG_reflectionfg 5+#define SG_godrays 6+#define SG_heatwave 7+#define SG_corestarsfg 8+#define SG_mirrorfg 9+#define SG_bossStarField 10+#define SG_petals 11+#define SG_northernlights 12+#define SG_dreamstars 13+#define SG_planets 14+#define SG_rain 15+#define SG_tentacles 16+#define SG_blackhole 17+#define SG_starfield 18++#endifdiff --git a/games/celeste/src/dust.c b/games/celeste/src/dust.cnew file mode 100644index 00000000..4c93302a--- /dev/null+++ b/games/celeste/src/dust.c@@ -0,0 +1,465 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* Dust bunnies (DustGraphic, drawn with DustEdges' colored outline) and the+ * spinners that move: Dust/Blade RotateSpinner and TrackSpinner. A room can+ * have hundreds of dust bunnies (DustStaticSpinner, spinner.c's records): what+ * the game keeps per bunny comes here from its place (the random picks) and+ * from the time (rotations, blinks), the nodes from pack.py (the tiles). */+#include "entities.h"++static const uint16_t BASE[3] = {T_danger_dustcreature_base00, T_danger_dustcreature_base01, T_danger_dustcreature_base02};+static const uint16_t OVERLAY[3] = {T_danger_dustcreature_overlay00, T_danger_dustcreature_overlay01,+ T_danger_dustcreature_overlay02};+static const uint16_t EYES[2][3] = {{T_danger_dustcreature_eyes00, T_danger_dustcreature_eyes01, T_danger_dustcreature_eyes02},+ {T_danger_dustcreature_templeeyes00, T_danger_dustcreature_templeeyes01,+ T_danger_dustcreature_templeeyes02}};++static uint32_t mix(uint32_t h) {+ h ^= h >> 16;+ h *= 0x7feb352du;+ h ^= h >> 15;+ h *= 0x846ca68bu;+ return h ^ (h >> 16);+}+static float hf(uint32_t h, int k) { return (float)(mix(h + (uint32_t)k * 0x9E3779B9u) >> 8) / 16777216.f; }++/* the dust that killed Madeline (OnHitPlayer): it shakes, its eyes go dead */+static struct { float x, y, timer; V2 shake; } hit;+void dust_hit(float x, float y) {+ hit.x = x, hit.y = y, hit.timer = 0.6f;+}++/* DustStyles: area 5's are blue, everyone else's (the resort's) red */+static bool temple_style(void) { return g_session.area == 5; }+static uint16_t edge_cols[8];+static uint32_t edge_epoch = 0xFFFFFFFF;+static float edge_ease;+/* FxDust: the outline's colors, from noise (two random fields 2.5 pixels a cell, eased one into the other each second) */+static uint16_t edge_color(int x, int y, void *ctx) {+ (void)ctx;+ int cx = (int)floorf((x + g_camx) / 2.5f), cy = (int)floorf((y + g_camy) / 2.5f);+ uint32_t e = edge_epoch;+ uint32_t ox0 = mix(e) & 127, oy0 = mix(e * 3 + 1) & 63, ox1 = mix(e + 1) & 127, oy1 = mix(e * 3 + 4) & 63;+ float a = (float)(mix((uint32_t)(cx + ox0) * 73856093u ^ (uint32_t)(cy + oy0) * 19349663u ^ e) & 255) / 255.f;+ float b = (float)(mix((uint32_t)(cx + ox1) * 73856093u ^ (uint32_t)(cy + oy1) * 19349663u ^ (e + 1)) & 255) / 255.f;+ float n = a + (b - a) * edge_ease;+ return edge_cols[(int)(n * 7.99f)];+}+static void edge_prepare(void) {+ float t = g_level.time_active;+ uint32_t e = (uint32_t)t;+ edge_ease = t - (float)e;+ if (e == edge_epoch && edge_cols[0]) return;+ edge_epoch = e;+ static const uint32_t red[3] = {0xf25a10, 0xff0000, 0xf21067}, blue[3] = {0x245ebb, 0x17a0ff, 0x17a0ff};+ const uint32_t *c = temple_style() ? blue : red;+ for (int i = 0; i < 8; i++) { /* the three colors, one into the next */+ float n = i / 7.f * 2;+ int k = n >= 1 ? 1 : 0;+ float f = n - k;+ uint32_t p = c[k], q = c[k + 1];+ int r = (int)((p >> 16) + (((int)(q >> 16) - (int)(p >> 16)) * f));+ int g = (int)((p >> 8 & 255) + (((int)(q >> 8 & 255) - (int)(p >> 8 & 255)) * f));+ int bl = (int)((p & 255) + (((int)(q & 255) - (int)(p & 255)) * f));+ edge_cols[i] = rgb((uint32_t)(r << 16 | g << 8 | bl));+ }+}++/* one DustGraphic: at (x, y), its picks from seed; nodes: enabled (4 bits), expanded in x (4), in y (4);+ * eyes: their direction unless follow; static: DustStaticSpinner's (autoControlEyes) */+typedef struct {+ float x, y;+ uint32_t seed;+ uint16_t nodes;+ bool statik;+ V2 eye;+ bool eye_set;+} Dust;++static uint32_t *mask; /* the strip's dust (DustEdges draws one outline around all of it) */+#define MASK_BYTES (17 * 40) /* the rows of a strip and one each side, 320 bits each */+uint32_t dust_ram(void) { return MASK_BYTES; }+/* the textures' colors (each has its own palette): center, bases, overlays, eyes (red), dead eyes */+enum { L_CENTER, L_BASE, L_OVERLAY = L_BASE + 3, L_EYES = L_OVERLAY + 3, L_DEAD = L_EYES + 3, L_COUNT };+typedef struct { uint16_t c[L_COUNT][16], a[L_COUNT][16]; Tex t[L_COUNT]; bool ok[L_COUNT]; } Luts;+static void luts_make(Luts *l) {+ memset(l, 0, sizeof *l);+ uint16_t ids[L_COUNT] = {T_danger_dustcreature_center00, BASE[0], BASE[1], BASE[2], OVERLAY[0], OVERLAY[1], OVERLAY[2],+ EYES[temple_style()][0], EYES[temple_style()][1], EYES[temple_style()][2],+ T_danger_dustcreature_deadEyes};+ uint16_t eye = temple_style() ? rgb(0x245ebb) : rgb(0xff0000);+ for (int i = 0; i < L_COUNT; i++)+ if ((l->ok[i] = tex_get(ids[i], &l->t[i])) && l->t[i].fmt == TF_RAW4)+ pal_lut(l->t[i].pal, i >= L_EYES ? eye : 0xFFFF, l->c[i], l->a[i]);+ else+ l->ok[i] = false;+}+static void dust_draw(uint16_t *strip, int sy0, int sy1, const Dust *d, int pass, const Luts *lt) { /* pass 0: body, 1: eyes */+ uint32_t h = mix(d->seed);+ float t = g_level.time_active;+ bool killer = hit.timer > 0 && d->x == hit.x && d->y == hit.y;+ float px = d->x, py = d->y;+ int en = d->nodes & 15;+ /* AddDustNodesIfInCamera: Position moved a pixel towards the nodes */+ if (en & 5) px -= 1;+ if (en & 10) px += 1;+ if (en & 3) py -= 1;+ if (en & 12) py += 1;+ if (killer) px += hit.shake.x, py += hit.shake.y;+ float sx = floorf(px + 0.5f) - g_camx, sy = floorf(py + 0.5f) - g_camy; /* RenderPosition on screen */+ if (sy + 20 < sy0 - 1 || sy - 20 > sy1 + 1) return;+ if (!lt->ok[L_CENTER]) return;+ if (pass) goto eyes;+ Layer l[9];+ int n = 0;+ float tr = hf(h, 1) + t * 0.6f; /* the center turns with timer */+ const Tex *tc = <->t[L_CENTER];+ l[n++] = (Layer){tc, sx, sy, tc->fw / 2.f, tc->fh / 2.f, cosf(tr), sinf(tr), 1, lt->c[L_CENTER], lt->a[L_CENTER]};+ int reach = 13;+ static const int8_t nx[4] = {-1, 1, -1, 1}, ny[4] = {-1, -1, 1, 1};+ for (int i = 3; i >= 0; i--) {+ if (!(en >> i & 1)) continue;+ int bi = (int)(hf(h, 10 + i) * 3), oi = (int)(hf(h, 20 + i) * 3);+ if (!lt->ok[L_BASE + bi] || !lt->ok[L_OVERLAY + oi]) continue;+ const Tex *tb = <->t[L_BASE + bi], *to = <->t[L_OVERLAY + oi];+ float r = hf(h, 30 + i) * PI_F * 2 + t * 0.5f;+ float vx = d->nodes >> (4 + i) & 1 ? 5.f : 1.f, vy = d->nodes >> (8 + i) & 1 ? 5.f : 1.f;+ if (vx > 1 || vy > 1) reach = 15;+ float ax = sx + nx[i] * 0.70710677f * vx, ay = sy + ny[i] * 0.70710677f * vy;+ float c = cosf(r), s = sinf(r);+ l[n++] = (Layer){to, ax, ay, to->fw / 2.f, to->fh / 2.f, c, -s, 1, lt->c[L_OVERLAY + oi], lt->a[L_OVERLAY + oi]};+ l[n++] = (Layer){tb, ax, ay, tb->fw / 2.f, tb->fh / 2.f, c, s, 1, lt->c[L_BASE + bi], lt->a[L_BASE + bi]};+ }+ blit_layers(strip, sy0, sy1, l, n, (int)sx - reach, (int)sy - reach, (int)sx + reach + 1, (int)sy + reach + 1, edge_color,+ NULL, mask);+ return;+eyes:;+ /* the eyes (Eyeballs) */+ int count = (en & 1) + (en >> 1 & 1) + (en >> 2 & 1) + (en >> 3 & 1);+ bool exist = !d->statik || hf(h, 2) < 0.5f;+ if (!exist) return;+ V2 dir = d->eye;+ if (!d->eye_set) {+ bool by_rotation = count < 4;+ V2 range = v2(0, 0);+ if (by_rotation) {+ for (int i = 0; i < 4; i++)+ if (en >> i & 1) range = v2add(range, v2(nx[i] * 0.70710677f, ny[i] * 0.70710677f));+ float len = v2len(range);+ if (len > 0) range = v2mul(range, 1 / len);+ dir = range;+ } else+ dir = angle_vec(hf(h, 3) * PI_F * 2, 1);+ Player *p = level_player();+ if (hf(h, 4) < 0.3f && p) { /* eyesFollowPlayer */+ V2 to_p = v2sub(v2(p->ent->x, p->ent->y), v2(d->x, d->y));+ float l2 = v2len(to_p);+ if (l2 > 0) {+ to_p = v2mul(to_p, 1 / l2);+ if (by_rotation) {+ float a = atan2f(range.y, range.x), b = atan2f(to_p.y, to_p.x), diff = b - a;+ while (diff > PI_F) diff -= PI_F * 2;+ while (diff < -PI_F) diff += PI_F * 2;+ diff = clampf(diff, -PI_F / 4, PI_F / 4);+ dir = angle_vec(a + diff, 1);+ } else+ dir = to_p;+ }+ }+ }+ /* BlinkRoutine: 2 to 3.5 s open, the left one shut first, both for 0.25 s */+ float period = 2.27f + hf(h, 5) * 1.5f + 0.035f, ph = fmodf(t + hf(h, 6) * period, period);+ bool left = !(ph > period - 0.27f), right = !(ph > period - 0.25f);+ if (killer) left = right = true;+ int ei = killer ? L_DEAD : L_EYES + (int)(mix(h + 7) % 3);+ if (!lt->ok[ei]) return;+ const Tex *te = <->t[ei];+ V2 perp = v2(-dir.y, dir.x);+ float pl = v2len(perp);+ if (pl > 0) perp = v2mul(perp, 1 / pl);+ for (int k = -1; k <= 1; k += 2) { /* DrawCentered */+ if (!(k < 0 ? left : right)) continue;+ float ex = sx + dir.x * 5 - k * perp.x * 3, ey = sy + dir.y * 5 - k * perp.y * 3;+ blit_raw4(strip, sy0, sy1, te, (int)floorf(ex - te->fw / 2.f + 0.5f), (int)floorf(ey - te->fh / 2.f + 0.5f), lt->c[ei],+ lt->a[ei]);+ }+}++/* ---------------------------------------------------------------- the moving spinners */+typedef struct {+ V2 center, start, end, eye, eye_target, outwards;+ float percent, length, pause, angle;+ Sprite spr;+ uint8_t rotate, clockwise, moving, dust, fall, up, speed, trail, started, nodes, color;+} Mover;+static const EntClass MOVER;++/* the dust layer (DustEdges, depth -48): every dust bunny on the screen */+typedef struct { uint16_t *strip; int sy0, sy1, pass; const Luts *lt; } StripCtx;+static void one_static(float x, float y, uint16_t bits, void *ctx) {+ StripCtx *c = ctx;+ Dust d = {x, y, (uint32_t)((int)x * 31 + (int)y * 977), bits, true, {0, 0}, false};+ dust_draw(c->strip, c->sy0, c->sy1, &d, c->pass, c->lt);+}+static void layer_strip(uint16_t *strip, int sy0, int sy1, void *ctx) {+ (void)ctx;+ Luts lt;+ luts_make(<);+ StripCtx c = {strip, sy0, sy1, 0, <};+ uint32_t need = (uint32_t)(sy1 - sy0 + 2) * 40;+ mask = need <= MASK_BYTES && g_chram[13] ? (uint32_t *)(void *)g_chram[13] : NULL;+ if (mask) memset(mask, 0, need);+ /* the bodies, their outline (DustEdges), then the eyes in front (Eyeballs, depth -51) */+ for (c.pass = 0; c.pass < 2; c.pass++) {+ for (int s = 0; s < 2; s++) {+ const Room *rm = &g_level.rooms[s];+ if (rm->index >= 0 && rm->spin_dust)+ spinners_each(rm, g_camx - 20.f, sy0 - 20.f + g_camy, g_camx + VIEW_W + 20.f, sy1 + 20.f + g_camy, one_static, &c);+ }+ for (int i = 0; i < g_nents; i++) {+ Ent *e = &g_ents[i];+ if (e->cls != &MOVER || e->dead == 1 || !ST(e, Mover)->dust || !e->visible) continue;+ Mover *m = ST(e, Mover);+ Dust d = {e->x, e->y, (uint32_t)(e->eid * 7919u + 13u), m->nodes, false, m->eye, true};+ dust_draw(strip, sy0, sy1, &d, c.pass, <);+ }+ if (!c.pass && mask) blit_edges(strip, sy0, sy1, mask, edge_color, NULL);+ }+}+static void layer_update(Ent *e) {+ (void)e;+ if (hit.timer > 0) {+ hit.timer -= DT;+ if (hit.timer <= 0) hit.shake = v2(0, 0);+ else if (level_on_interval(0.05f)) hit.shake = v2((float)(rndi(3) - 1), (float)(rndi(3) - 1));+ }+}+static void layer_render(Ent *e) {+ (void)e;+ if (!g_level.rooms[0].spin_dust && !g_level.rooms[1].spin_dust && g_session.area != 3 && g_session.area != 7) return;+ /* the textures, loaded before the strips are drawn */+ Tex t;+ tex_get(T_danger_dustcreature_center00, &t);+ for (int i = 0; i < 3; i++) tex_get(BASE[i], &t), tex_get(OVERLAY[i], &t), tex_get(EYES[temple_style()][i], &t);+ tex_get(T_danger_dustcreature_deadEyes, &t);+ edge_prepare();+ gfx_custom(layer_strip, NULL, 0, VIEW_H);+}+static const EntClass LAYER = {.name = "dustEdges", .update = layer_update, .render = layer_render};+void dust_entities(void) {+ Ent *e = ent_new(&LAYER, 0, 0);+ if (!e) return;+ e->depth = -48;+ e->tags = TAG_GLOBAL | TAG_TRANSITION_UPDATE;+ e->collidable = 0;+ hit.timer = 0;+}++/* RotateSpinner, TrackSpinner */+static const float PAUSE[3] = {0.3f, 0.2f, 0.6f}, MOVE[3] = {0.9f, 0.4f, 0.3f};+static void track_pos(Ent *e) { /* UpdatePosition */+ Mover *m = ST(e, Mover);+ float k = ease_sine_inout(m->percent);+ e->x = m->start.x + (m->end.x - m->start.x) * k, e->y = m->start.y + (m->end.y - m->start.y) * k;+}+static float rotate_angle(const Mover *m) { return lerpf(4.712389f, -PI_F / 2, m->percent); }++static void track_start(Ent *e) { /* OnTrackStart */+ Mover *m = ST(e, Mover);+ if (!m->dust) spr_play(&m->spr, A_templeBlade_spin, true), m->started = 1, m->trail = 1;+}+static void track_end(Ent *e) { /* OnTrackEnd */+ Mover *m = ST(e, Mover);+ if (!m->dust) {+ m->trail = 0;+ return;+ }+ if (m->outwards.x != 0 || m->outwards.y != 0) {+ float a = atan2f(m->outwards.y, m->outwards.x), b = m->up ? m->angle + PI_F : m->angle, diff = b - a;+ while (diff > PI_F) diff -= PI_F * 2;+ while (diff < -PI_F) diff += PI_F * 2;+ m->eye_target = angle_vec(a + diff * 0.3f, 1);+ } else+ m->eye_target = angle_vec(m->up ? m->angle + PI_F : m->angle, 1);+}++static void mover_update(Ent *e) {+ Mover *m = ST(e, Mover);+ if (!m->dust) spr_update(&m->spr);+ if (m->rotate) {+ if (m->moving) {+ if (m->clockwise) m->percent += 1 - DT / 1.8f;+ else m->percent += DT / 1.8f;+ m->percent = fmodf(m->percent, 1);+ V2 v = angle_vec(rotate_angle(m), m->length);+ e->x = m->center.x + v.x, e->y = m->center.y + v.y;+ }+ if (m->fall) {+ m->center.y += 160 * DT;+ if (e->y > g_level.room->y + g_level.room->h + 32) {+ ent_remove(e);+ return;+ }+ }+ if (m->dust) {+ if (m->moving) {+ m->eye = angle_vec(rotate_angle(m) + PI_F / 2 * (m->clockwise ? 1 : -1), 1);+ if (level_on_interval(0.02f)) particles_emit(PL_BG, &P_DustStaticSpinner_P_Move, 1, v2(e->x, e->y), v2(4, 4), 0);+ }+ } else {+ if (level_on_interval(0.04f)) particles_emit(PL_BG, &P_BladeTrackSpinner_P_Trail, 2, v2(e->x, e->y), v2(3, 3), 0);+ if (level_on_interval(1)) spr_play(&m->spr, A_templeBlade_spin, false);+ }+ return;+ }+ /* TrackSpinner */+ if (m->dust && (m->eye.x != m->eye_target.x || m->eye.y != m->eye_target.y)) { /* DustGraphic: EyeDirection approaches */+ V2 d = v2sub(m->eye_target, m->eye);+ float l = v2len(d), k = 12 * DT;+ m->eye = l <= k ? m->eye_target : v2add(m->eye, v2mul(d, k / l));+ }+ if (m->moving) {+ if (m->pause > 0) {+ m->pause -= DT;+ if (m->pause <= 0) track_start(e);+ } else {+ m->percent = approach(m->percent, m->up ? 1.f : 0.f, DT / MOVE[m->speed]);+ track_pos(e);+ if ((m->up && m->percent == 1) || (!m->up && m->percent == 0)) {+ m->up = !m->up;+ m->pause = PAUSE[m->speed];+ track_end(e);+ }+ }+ }+ if (m->dust) {+ if (m->moving && m->pause < 0 && level_on_interval(0.02f))+ particles_emit(PL_BG, &P_DustStaticSpinner_P_Move, 1, v2(e->x, e->y), v2(4, 4), 0);+ } else if (m->trail && level_on_interval(0.04f))+ particles_emit(PL_BG, &P_BladeTrackSpinner_P_Trail, 2, v2(e->x, e->y), v2(3, 3), 0);+}++static void mover_on_player(Ent *e, Player *p) {+ Mover *m = ST(e, Mover);+ V2 d = v2sub(v2(p->ent->x, p->ent->y), v2(e->x, e->y));+ float l = v2len(d);+ bool was = p->dead;+ player_die(p, l > 0 ? v2mul(d, 1 / l) : v2(0, 0), false);+ if (!was && p->dead) {+ m->moving = 0;+ if (m->dust) dust_hit(e->x, e->y);+ }+}+static void mover_render(Ent *e) {+ Mover *m = ST(e, Mover);+ if (!m->dust) spr_draw(&m->spr, e->x, e->y);+}+static bool mover_collide(const Ent *e, float l, float t, float r, float b) { /* Circle(6), Hitbox(16, 4, -8, -3) */+ float nx = clampf(e->x, l, r), ny = clampf(e->y, t, b), dx = e->x - nx, dy = e->y - ny;+ if (dx * dx + dy * dy < 36) return true;+ return !ST(e, Mover)->rotate && r > e->x - 8 && l < e->x + 8 && b > e->y - 3 && t < e->y + 1;+}+/* StaticMover: a RotateSpinner rides what its center is in */+static bool mover_riding(Ent *e, Ent *p) {+ Mover *m = ST(e, Mover);+ return m->rotate && p->collidable && collide_rect(p, m->center.x, m->center.y, m->center.x + 1, m->center.y + 1);+}+static void mover_sm_move(Ent *e, V2 v) {+ Mover *m = ST(e, Mover);+ m->center = v2add(m->center, v);+ e->x += v.x, e->y += v.y;+}+static void mover_sm_destroy(Ent *e) { ST(e, Mover)->fall = 1; }++static void mover_awake(Ent *e) {+ Mover *m = ST(e, Mover);+ if (m->rotate) return;+ track_start(e);+ if (!m->dust) return;+ /* DustTrackSpinner.Establish: against a wall the whole way, the nodes on its side go */+ V2 dir = v2sub(m->end, m->start);+ float len = v2len(dir);+ if (len <= 0) return;+ dir = v2mul(dir, 1 / len);+ V2 side = v2(-dir.y, dir.x);+ bool on = rect_solid(e->x + side.x * 4 - 2, e->y + side.y * 4 - 2, e->x + side.x * 4 + 2, e->y + side.y * 4 + 2);+ if (!on) {+ side = v2(-side.x, -side.y);+ on = rect_solid(e->x + side.x * 4 - 2, e->y + side.y * 4 - 2, e->x + side.x * 4 + 2, e->y + side.y * 4 + 2);+ }+ if (!on) return;+ for (int i = 8; i < len && on; i += 8) {+ float x = e->x + side.x * 4 + dir.x * i, y = e->y + side.y * 4 + dir.y * i;+ on = rect_solid(x - 2, y - 2, x + 2, y + 2);+ }+ if (!on) return;+ if (side.x < 0) m->nodes &= ~5; /* LeftNodes */+ else if (side.x > 0) m->nodes &= ~10; /* RightNodes */+ else if (side.y < 0) m->nodes &= ~3; /* TopNodes */+ else if (side.y > 0) m->nodes &= ~12; /* BottomNodes */+ m->outwards = v2(-side.x, -side.y);+ float a = atan2f(m->outwards.y, m->outwards.x), b = m->up ? m->angle + PI_F : m->angle, diff = b - a;+ while (diff > PI_F) diff -= PI_F * 2;+ while (diff < -PI_F) diff += PI_F * 2;+ m->eye = m->eye_target = angle_vec(a + diff * 0.3f, 1);+}++static const EntClass MOVER = {.name = "movingSpinner", .size = sizeof(Mover), .update = mover_update,+ .render = mover_render, .on_player = mover_on_player, .awake = mover_awake,+ .collide_rect = mover_collide, .sm_riding = mover_riding, .sm_move = mover_sm_move,+ .sm_destroy = mover_sm_destroy, .kind = KIND_PCOLLIDE | KIND_STATICMOVER};++static bool dust_room_of(const EData *d) {+ int a = g_session.area;+ return a == 3 || (a == 7 && !strncmp(level_room_name_of(d->room), "d-", 2));+}++static bool mover_new(const EData *d, bool rotate) {+ Ent *e = ent_new(&MOVER, d->x, d->y);+ if (!e) return true;+ Mover *m = ST(e, Mover);+ e->depth = -50;+ e->ctype = COL_LIST;+ e->cx = -8, e->cy = -6, e->cw = 16, e->ch = 12;+ m->rotate = rotate;+ m->dust = dust_room_of(d);+ m->moving = 1;+ m->nodes = 15;+ if (!m->dust) {+ spr_init(&m->spr, SB_templeBlade);+ spr_play(&m->spr, A_templeBlade_idle, true);+ }+ if (rotate) {+ m->center = ed_node(d, 0);+ m->clockwise = EAB(d, rotateSpinner, clockwise);+ float a = atan2f(e->y - m->center.y, e->x - m->center.x); /* Calc.Angle(center, Position), wrapped */+ while (a > PI_F) a -= PI_F * 2;+ while (a <= -PI_F) a += PI_F * 2;+ m->percent = (a - -PI_F / 2) / (4.712389f - -PI_F / 2); /* Calc.Percent */+ m->length = v2len(v2sub(v2(e->x, e->y), m->center));+ V2 v = angle_vec(rotate_angle(m), m->length);+ e->x = m->center.x + v.x, e->y = m->center.y + v.y;+ } else {+ m->start = v2(d->x, d->y);+ m->end = ed_node(d, 0);+ const char *sp = EAS(d, trackSpinner, speed);+ m->speed = !strcmp(sp, "Slow") ? 0 : !strcmp(sp, "Fast") ? 2 : 1;+ m->angle = atan2f(m->start.y - m->end.y, m->start.x - m->end.x);+ m->percent = EAB(d, trackSpinner, startCenter) ? 0.5f : 0;+ m->up = 1;+ track_pos(e);+ V2 dir = v2sub(m->end, m->start);+ float l = v2len(dir);+ m->eye = m->eye_target = l > 0 ? v2mul(dir, 1 / l) : v2(1, 0);+ }+ return true;+}++bool dust_create(const EData *d) {+ switch (d->type) {+ case ET_rotateSpinner: return mover_new(d, true);+ case ET_trackSpinner: return mover_new(d, false);+ }+ return false;+}diff --git a/games/celeste/src/ent.c b/games/celeste/src/ent.cnew file mode 100644index 00000000..bccf3ef3--- /dev/null+++ b/games/celeste/src/ent.c@@ -0,0 +1,794 @@+/* Entities: the pool, depth order, collisions, and Monocle's Actor, Solid,+ * JumpThru movement (pixel by pixel, pushing and carrying riders). */+#include "ent.h"+#include "level.h"++Ent g_ents[MAX_ENTS];+int g_nents;+static uint16_t next_order;+uint16_t g_new_eid = 0xFFFF;+static uint8_t sorted[MAX_ENTS]; /* by depth: rendering */+static uint8_t uord[MAX_ENTS]; /* by insertion: updating (Monocle's EntityList) */+static int nsorted;+static bool unsorted = true;+Ent *g_solidtiles;++uint8_t g_ent_arena[ENT_ARENA] __attribute__((aligned(8)));+/* states hold pointers: aligned for them (8 bytes on a 64-bit computer) */+#define ARENA_ALIGN ((uint32_t)sizeof(void *) > 4 ? 8u : 4u)+static inline uint32_t arena_size(const EntClass *c) { return (c->size + ARENA_ALIGN - 1) & ~(ARENA_ALIGN - 1); }+static uint32_t arena_top; /* bytes used */++Ent *ent_new(const EntClass *cls, float x, float y) {+ uint32_t size = arena_size(cls);+ if (arena_top + size > ENT_ARENA) return NULL;+ for (int i = 0; i < MAX_ENTS; i++) {+ Ent *e = &g_ents[i];+ if (e->cls) continue;+ memset(e, 0, sizeof *e);+ e->cls = cls;+ e->kind = cls->kind;+ e->x = x, e->y = y;+ e->active = e->visible = e->collidable = 1;+ e->allow_pushing = 1;+ e->order = next_order++;+ e->eid = g_new_eid;+ e->room = (uint8_t)g_level.room_slot;+ e->dead = 2; /* added: joins the update list next frame (Scene.Add) */+ e->data = (uint16_t)(arena_top / 4);+ memset(g_ent_arena + arena_top, 0, size);+ arena_top += size;+ if (i >= g_nents) g_nents = i + 1;+ unsorted = true;+ return e;+ }+ return NULL;+}++/* slides the states of live entities down over freed ones (end of frame only) */+static void arena_compact(void) {+ uint32_t top = 0;+ /* in arena order: entities sorted by data offset */+ for (;;) {+ Ent *next = NULL;+ for (int i = 0; i < g_nents; i++) {+ Ent *e = &g_ents[i];+ if (e->cls && e->cls->size && e->data * 4u >= top && (!next || e->data < next->data)) next = e;+ }+ if (!next) break;+ uint32_t size = arena_size(next->cls);+ if (next->data * 4u != top) memmove(g_ent_arena + top, g_ent_arena + next->data * 4u, size);+ next->data = (uint16_t)(top / 4);+ top += size;+ }+ arena_top = top;+}++void ent_remove(Ent *e) {+ if (!e || !e->cls || e->dead == 1) return;+ e->dead = 1;+ e->collidable = 0;+}++void ent_box(Ent *e, float w, float h, float x, float y) {+ e->ctype = COL_BOX;+ e->cw = w, e->ch = h, e->cx = x, e->cy = y;+}+void ent_circle(Ent *e, float r, float x, float y) {+ e->ctype = COL_CIRCLE;+ e->cw = r, e->cx = x, e->cy = y, e->ch = 0;+}++static void sort_ents(void) {+ nsorted = 0;+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls && g_ents[i].dead != 2) sorted[nsorted++] = (uint8_t)i;+ /* depth descending (back first), then insertion order */+ for (int i = 1; i < nsorted; i++) {+ uint8_t k = sorted[i];+ int j = i;+ while (j > 0) {+ Ent *a = &g_ents[sorted[j - 1]], *b = &g_ents[k];+ if (a->depth > b->depth || (a->depth == b->depth && (int16_t)(a->order - b->order) < 0)) break;+ sorted[j] = sorted[j - 1];+ j--;+ }+ sorted[j] = k;+ }+ memcpy(uord, sorted, (size_t)nsorted);+ for (int i = 1; i < nsorted; i++) {+ uint8_t k = uord[i];+ int j = i;+ while (j > 0 && (int16_t)(g_ents[uord[j - 1]].order - g_ents[k].order) > 0) uord[j] = uord[j - 1], j--;+ uord[j] = k;+ }+ unsorted = false;+}++void ents_awake_new(void) {+ bool any = false;+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls && g_ents[i].dead == 2) g_ents[i].dead = 0, any = true;+ if (!any) return;+ unsorted = true;+ for (int i = 0; i < g_nents; i++) {+ Ent *e = &g_ents[i];+ if (e->cls && e->cls->awake && !e->awoken) {+ e->awoken = 1;+ e->cls->awake(e);+ }+ }+}++void ents_flush_removed(void) {+ for (int i = 0; i < g_nents; i++) {+ Ent *e = &g_ents[i];+ if (e->cls && e->dead == 1) {+ if (e->cls->removed) e->cls->removed(e);+ /* static movers lose their platform, platforms their movers */+ for (int j = 0; j < g_nents; j++)+ if (g_ents[j].cls && ent_platform(&g_ents[j]) == e) ent_set_platform(&g_ents[j], NULL);+ e->cls = NULL;+ unsorted = true;+ }+ }+ while (g_nents > 0 && !g_ents[g_nents - 1].cls) g_nents--;+ arena_compact();+}++/* Level.Update: paused, frozen or between rooms, only the entities tagged for it update */+void ents_update(void) {+ if (unsorted) sort_ents();+ uint8_t need = g_level.paused ? TAG_PAUSE_UPDATE : g_level.frozen ? TAG_FROZEN_UPDATE+ : g_level.transitioning ? TAG_TRANSITION_UPDATE : 0;+ for (int i = 0; i < nsorted; i++) {+ Ent *e = &g_ents[uord[i]];+ if (!e->cls || e->dead || !e->active) continue;+ if (need && !(e->tags & need)) continue;+ if (e->cls->update) e->cls->update(e);+ }+}++void ents_mark_unsorted(void) { unsorted = true; }++void ents_render_between(int hi, int lo) {+ if (unsorted) sort_ents();+ for (int i = 0; i < nsorted; i++) {+ Ent *e = &g_ents[sorted[i]];+ if (!e->cls || e->dead == 1 || !e->visible || !e->cls->render || (e->tags & TAG_HUD)) continue;+ if (e->depth > hi || e->depth <= lo) continue;+ e->cls->render(e);+ }+}+/* HudRenderer: the interface's entities, over everything */+void ents_render_hud(void) {+ if (unsorted) sort_ents();+ for (int i = 0; i < nsorted; i++) {+ Ent *e = &g_ents[sorted[i]];+ if (e->cls && e->dead != 1 && e->visible && e->cls->render && (e->tags & TAG_HUD)) e->cls->render(e);+ }+}++void ents_clear(bool keep_persistent) {+ for (int i = 0; i < g_nents; i++) {+ Ent *e = &g_ents[i];+ if (!e->cls) continue;+ if (keep_persistent && (e->tags & (TAG_PERSISTENT | TAG_GLOBAL))) continue;+ if (e->cls->removed) e->cls->removed(e);+ e->cls = NULL;+ }+ while (g_nents > 0 && !g_ents[g_nents - 1].cls) g_nents--;+ unsorted = true;+ arena_compact();+}++void ents_remove_room(int room) {+ for (int i = 0; i < g_nents; i++) {+ Ent *e = &g_ents[i];+ if (e->cls && e->room == room && !(e->tags & (TAG_PERSISTENT | TAG_GLOBAL))) {+ if (e->cls->removed) e->cls->removed(e);+ e->cls = NULL;+ }+ }+ while (g_nents > 0 && !g_ents[g_nents - 1].cls) g_nents--;+ unsorted = true;+ arena_compact();+}++/* ---------------------------------------------------------------- collision */+static bool rect_circle(float l, float t, float r, float b, float cx, float cy, float rad) {+ if (cx >= l && cx <= r && cy >= t && cy <= b) return true;+ float nx = clampf(cx, l, r), ny = clampf(cy, t, b);+ float dx = cx - nx, dy = cy - ny;+ return dx * dx + dy * dy < rad * rad;+}++bool tiles_solid_rect(float l, float t, float r, float b) {+ /* Grid.Collide(Rectangle): the rect is in whole pixels */+ int x0 = (int)floorf(l), y0 = (int)floorf(t), x1 = (int)floorf(r), y1 = (int)floorf(b);+ int w = x1 - x0, h = y1 - y0;+ if (w <= 0 || h <= 0) return false;+ return level_solid_cells(x0 >> 3, y0 >> 3, (x0 + w - 1) >> 3, (y0 + h - 1) >> 3);+}++/* the collider of e at (x, y) vs other's, both as Monocle colliders */+bool collide_ent_at(const Ent *e, float x, float y, const Ent *o) {+ if (e->ctype == COL_NONE || o->ctype == COL_NONE) return false;+ /* ColliderLists: the entity's own test against the other's box */+ if (o->ctype == COL_LIST && e->ctype == COL_BOX)+ return o->cls->collide_rect(o, x + e->cx, y + e->cy, x + e->cx + e->cw, y + e->cy + e->ch);+ if (e->ctype == COL_LIST && o->ctype == COL_BOX) {+ float dx = e->x - x, dy = e->y - y;+ return e->cls->collide_rect(e, o->x + o->cx + dx, o->y + o->cy + dy, o->x + o->cx + o->cw + dx, o->y + o->cy + o->ch + dy);+ }+ float l = x + e->cx, t = y + e->cy;+ if (e->ctype == COL_BOX) {+ float r = l + e->cw, b = t + e->ch;+ switch (o->ctype) {+ case COL_BOX: return r > o->x + o->cx && b > o->y + o->cy && l < o->x + o->cx + o->cw && t < o->y + o->cy + o->ch;+ case COL_CIRCLE: return rect_circle(l, t, r, b, o->x + o->cx, o->y + o->cy, o->cw);+ case COL_GRID: return o->cls == NULL ? false : (o == g_solidtiles ? tiles_solid_rect((int)l, (int)t, (int)l + (int)e->cw, (int)t + (int)e->ch) : level_grid_collide(o, l, t, r, b));+ }+ } else if (e->ctype == COL_CIRCLE) {+ float cx = x + e->cx, cy = y + e->cy;+ switch (o->ctype) {+ case COL_BOX: return rect_circle(o->x + o->cx, o->y + o->cy, o->x + o->cx + o->cw, o->y + o->cy + o->ch, cx, cy, e->cw);+ case COL_CIRCLE: {+ float dx = cx - (o->x + o->cx), dy = cy - (o->y + o->cy), rr = e->cw + o->cw;+ return dx * dx + dy * dy < rr * rr;+ }+ }+ }+ return false;+}++bool collide_rect(const Ent *e, float l, float t, float r, float b) {+ if (e->ctype == COL_BOX)+ return e->x + e->cx + e->cw > l && e->y + e->cy + e->ch > t && e->x + e->cx < r && e->y + e->cy < b;+ if (e->ctype == COL_CIRCLE) return rect_circle(l, t, r, b, e->x + e->cx, e->y + e->cy, e->cw);+ if (e == g_solidtiles) return tiles_solid_rect(l, t, r, b);+ if (e->ctype == COL_GRID) return level_grid_collide(e, l, t, r, b);+ if (e->ctype == COL_LIST) return e->cls->collide_rect(e, l, t, r, b);+ return false;+}++static inline bool live(const Ent *o, const Ent *self) { return o->cls && o != self && o->collidable && o->dead != 1; }++Ent *collide_first_solid(const Ent *e, float x, float y) {+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if ((o->kind & KIND_SOLID) && live(o, e) && collide_ent_at(e, x, y, o)) return o;+ }+ return NULL;+}+bool collide_solid(const Ent *e, float x, float y) { return collide_first_solid(e, x, y) != NULL; }++Ent *collide_first_kind(const Ent *e, float x, float y, uint16_t kind) {+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if ((o->kind & kind) && live(o, e) && collide_ent_at(e, x, y, o)) return o;+ }+ return NULL;+}++Ent *collide_first_jumpthru_outside(const Ent *e, float x, float y) {+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if ((o->kind & KIND_JUMPTHRU) && live(o, e) && collide_ent_at(e, x, y, o) && !collide_ent_at(e, e->x, e->y, o)) return o;+ }+ return NULL;+}++bool collide_jumpthru(const Ent *e, float x, float y) { return collide_first_kind(e, x, y, KIND_JUMPTHRU) != NULL; }++bool rect_solid(float l, float t, float r, float b) {+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if ((o->kind & KIND_SOLID) && o->cls && o->collidable && o->dead != 1 && collide_rect(o, l, t, r, b)) return true;+ }+ return false;+}+bool point_solid(float x, float y) { return rect_solid(x, y, x + 1, y + 1); }++/* ---------------------------------------------------------------- Actor */+bool actor_is_riding_jumpthru(Ent *e, Ent *j) {+ if (e->cls->is_riding_jumpthru) return e->cls->is_riding_jumpthru(e, j);+ if (e->ignore_jumpthrus) return false;+ return collide_ent_at(e, e->x, e->y + 1, j) && !collide_ent_at(e, e->x, e->y, j);+}+bool actor_is_riding_solid(Ent *e, Ent *s) {+ if (e->cls->is_riding_solid) return e->cls->is_riding_solid(e, s);+ return collide_ent_at(e, e->x, e->y + 1, s);+}++bool actor_on_ground(const Ent *e, int down) {+ if (collide_solid(e, e->x, e->y + down)) return true;+ if (!e->ignore_jumpthrus) return collide_first_jumpthru_outside(e, e->x, e->y + down) != NULL;+ return false;+}+bool actor_on_ground_at(Ent *e, float x, float y, int down) {+ float ox = e->x, oy = e->y;+ e->x = x, e->y = y;+ bool r = actor_on_ground(e, down);+ e->x = ox, e->y = oy;+ return r;+}++void actor_set_lift(Ent *e, V2 v) {+ e->lift = v;+ if ((v.x != 0 || v.y != 0) && (e->kind & KIND_ACTOR)) {+ ActorExt *x = ST(e, ActorExt);+ x->last_lift = v;+ x->lift_timer = 0.16f;+ }+}+V2 actor_lift(const Ent *e) {+ if (e->lift.x == 0 && e->lift.y == 0 && (e->kind & KIND_ACTOR)) return ST(e, ActorExt)->last_lift;+ return e->lift;+}+void actor_update_lift(Ent *e) {+ e->lift = v2(0, 0);+ ActorExt *x = ST(e, ActorExt);+ if (x->lift_timer > 0) {+ x->lift_timer -= DT;+ if (x->lift_timer <= 0) x->last_lift = v2(0, 0);+ }+}++bool actor_move_h_exact(Ent *e, int move, CollideFn cb, Ent *pusher) {+ float tx = e->x + move;+ int s = signi(move), moved = 0;+ while (move) {+ Ent *hit = collide_first_solid(e, e->x + s, e->y);+ if (hit) {+ e->remx = 0;+ if (cb) {+ Collision c = {v2((float)s, 0), v2((float)moved, 0), v2(tx, e->y), hit, pusher};+ cb(e, &c);+ }+ return true;+ }+ moved += s;+ move -= s;+ e->x += s;+ }+ return false;+}++bool actor_move_v_exact(Ent *e, int move, CollideFn cb, Ent *pusher) {+ float ty = e->y + move;+ int s = signi(move), moved = 0;+ while (move) {+ Ent *hit = collide_first_solid(e, e->x, e->y + s);+ if (!hit && move > 0 && !e->ignore_jumpthrus) hit = collide_first_jumpthru_outside(e, e->x, e->y + s);+ if (hit) {+ e->remy = 0;+ if (cb) {+ Collision c = {v2(0, (float)s), v2(0, (float)moved), v2(e->x, ty), hit, pusher};+ cb(e, &c);+ }+ return true;+ }+ moved += s;+ move -= s;+ e->y += s;+ }+ return false;+}++bool actor_move_h(Ent *e, float amount, CollideFn cb, Ent *pusher) {+ e->remx += amount;+ int n = roundi(e->remx);+ if (n) {+ e->remx -= n;+ return actor_move_h_exact(e, n, cb, pusher);+ }+ return false;+}+bool actor_move_v(Ent *e, float amount, CollideFn cb, Ent *pusher) {+ e->remy += amount;+ int n = roundi(e->remy);+ if (n) {+ e->remy -= n;+ return actor_move_v_exact(e, n, cb, pusher);+ }+ return false;+}+void actor_move_to_x(Ent *e, float x, CollideFn cb) { actor_move_h(e, x - e->x - e->remx, cb, NULL); }+void actor_move_to_y(Ent *e, float y, CollideFn cb) { actor_move_v(e, y - e->y - e->remy, cb, NULL); }+void actor_move_towards_x(Ent *e, float x, float amount, CollideFn cb) { actor_move_to_x(e, approach(e->x + e->remx, x, amount), cb); }+void actor_move_towards_y(Ent *e, float y, float amount, CollideFn cb) { actor_move_to_y(e, approach(e->y + e->remy, y, amount), cb); }++void actor_naive_move(Ent *e, V2 a) {+ e->remx += a.x, e->remy += a.y;+ int nx = roundi(e->remx), ny = roundi(e->remy);+ e->x += nx, e->y += ny;+ e->remx -= nx, e->remy -= ny;+}++bool actor_try_squish_wiggle(Ent *e, Collision *c) {+ if (c->pusher) c->pusher->collidable = 1;+ for (int i = 0; i <= 3; i++)+ for (int j = 0; j <= 3; j++) {+ if (!i && !j) continue;+ for (int sx = 1; sx >= -1; sx -= 2)+ for (int sy = 1; sy >= -1; sy -= 2) {+ float x = e->x + i * sx, y = e->y + j * sy;+ if (!collide_solid(e, x, y)) {+ e->x = x, e->y = y;+ if (c->pusher) c->pusher->collidable = 0;+ return true;+ }+ }+ }+ if (c->pusher) c->pusher->collidable = 0;+ return false;+}++static void actor_squish(Ent *e, Collision *c) {+ if (e->cls->on_squish) e->cls->on_squish(e, c);+ else if (!actor_try_squish_wiggle(e, c)) ent_remove(e);+}++/* ---------------------------------------------------------------- Platform */+static Ent *riders[32];+static int nriders;++static void get_riders(Ent *p) {+ nriders = 0;+ for (int i = 0; i < g_nents; i++) {+ Ent *a = &g_ents[i];+ if (!(a->kind & KIND_ACTOR) || !a->cls || a->dead == 1) continue;+ if ((p->kind & KIND_SOLID) ? actor_is_riding_solid(a, p) : actor_is_riding_jumpthru(a, p))+ if (nriders < 32) riders[nriders++] = a;+ }+}+static bool is_rider(Ent *a, Ent **list, int n) {+ for (int i = 0; i < n; i++)+ if (list[i] == a) return true;+ return false;+}++void plat_static_movers_move(Ent *p, V2 amount) {+ for (int i = 0; i < g_nents; i++) {+ Ent *m = &g_ents[i];+ if (m->cls && ent_platform(m) == p && m->dead != 1) {+ if (m->cls->sm_move) m->cls->sm_move(m, amount);+ else m->x += amount.x, m->y += amount.y;+ }+ }+}+void plat_static_movers_shake(Ent *p, V2 amount) {+ for (int i = 0; i < g_nents; i++) {+ Ent *m = &g_ents[i];+ if (m->cls && ent_platform(m) == p && m->cls->sm_shake) m->cls->sm_shake(m, amount);+ }+}+void plat_static_movers_enable(Ent *p, bool on) {+ for (int i = 0; i < g_nents; i++) {+ Ent *m = &g_ents[i];+ if (m->cls && ent_platform(m) == p) {+ if (m->cls->sm_enable) m->cls->sm_enable(m, on);+ else m->collidable = m->visible = m->active = on;+ }+ }+}+void plat_static_movers_destroy(Ent *p) {+ for (int i = 0; i < g_nents; i++) {+ Ent *m = &g_ents[i];+ if (m->cls && ent_platform(m) == p) {+ if (m->cls->sm_destroy) m->cls->sm_destroy(m);+ else ent_remove(m);+ ent_set_platform(m, NULL);+ }+ }+}+void plat_static_movers_trigger(Ent *p) {+ if (p->cls->on_staticmover_trigger) p->cls->on_staticmover_trigger(p, NULL);+}++void plat_static_movers_attach(Ent *p) {+ for (int i = 0; i < g_nents; i++) {+ Ent *m = &g_ents[i];+ if (!m->cls || !(m->kind & KIND_STATICMOVER) || m->plat || m->dead == 1) continue;+ if (m->cls->sm_riding && m->cls->sm_riding(m, p)) {+ ent_set_platform(m, p);+ if (m->cls->sm_attach) m->cls->sm_attach(m, p);+ }+ }+}++#define MAX_SHAKES 24+typedef struct { Ent *e; float timer; } Shake;+static Shake shakes[MAX_SHAKES];+static int nshakes;++void plat_update(Ent *e) {+ e->lift = v2(0, 0);+ if (e->shaking) {+ if (level_on_interval(0.04f)) {+ V2 was = e_shake(e);+ e->shakex = (int8_t)(rndi(3) - 1), e->shakey = (int8_t)(rndi(3) - 1); /* Calc.Random.ShakeVector */+ V2 d = v2sub(e_shake(e), was);+ if (e->cls->on_shake) e->cls->on_shake(e, d);+ else plat_static_movers_shake(e, d);+ }+ for (int i = 0; i < nshakes; i++)+ if (shakes[i].e == e && shakes[i].timer > 0) {+ shakes[i].timer -= DT;+ if (shakes[i].timer <= 0) {+ shakes[i] = shakes[--nshakes];+ plat_stop_shaking(e);+ }+ break;+ }+ }+}+void plat_start_shaking(Ent *e, float t) {+ e->shaking = 1;+ /* Platform.ShakeTimer: kept for the few shaking at once (those that stopped or went are dropped) */+ for (int i = 0; i < nshakes; i++)+ if (!shakes[i].e->cls || !shakes[i].e->shaking) shakes[i--] = shakes[--nshakes];+ for (int i = 0; i < nshakes; i++)+ if (shakes[i].e == e) {+ shakes[i].timer = t;+ return;+ }+ if (nshakes < MAX_SHAKES) shakes[nshakes++] = (Shake){e, t};+}+void plat_stop_shaking(Ent *e) {+ for (int i = 0; i < nshakes; i++)+ if (shakes[i].e == e) shakes[i--] = shakes[--nshakes];+ e->shaking = 0;+ if (e->shakex || e->shakey) {+ V2 d = v2(-e->shakex, -(float)e->shakey);+ if (e->cls->on_shake) e->cls->on_shake(e, d);+ else plat_static_movers_shake(e, d);+ e->shakex = e->shakey = 0;+ }+}++static void solid_move_h_exact(Ent *s, int move) {+ get_riders(s);+ Ent *rl[32];+ int nr = nriders;+ memcpy(rl, riders, sizeof(Ent *) * nr);+ float right = e_right(s), left = e_left(s);+ Ent *p = level_player_ent();+ if (p && g_in.move_x == signi(move) && signf(level_player_speed_x()) == signi(move) && !is_rider(p, rl, nr) &&+ collide_ent_at(s, s->x + move, s->y - 1, p))+ actor_move_v(p, 1, NULL, NULL);+ (void)right, (void)left;+ s->x += move;+ plat_static_movers_move(s, v2((float)move, 0));+ if (s->collidable) {+ for (int i = 0; i < g_nents; i++) {+ Ent *a = &g_ents[i];+ if (!(a->kind & KIND_ACTOR) || !a->cls || a->dead == 1 || !a->allow_pushing) continue;+ uint8_t was = a->collidable;+ a->collidable = 1;+ if (!a->treat_naive && collide_ent_at(s, s->x, s->y, a)) {+ int mv = move > 0 ? (int)(e_right(s) - e_left(a)) : (int)(e_left(s) - e_right(a));+ s->collidable = 0;+ actor_move_h_exact(a, mv, actor_squish, s);+ actor_set_lift(a, s->lift);+ s->collidable = 1;+ } else if (is_rider(a, rl, nr)) {+ s->collidable = 0;+ if (a->treat_naive) actor_naive_move(a, v2((float)move, 0));+ else actor_move_h_exact(a, move, NULL, NULL);+ actor_set_lift(a, s->lift);+ s->collidable = 1;+ }+ a->collidable = was;+ }+ }+}++static void solid_move_v_exact(Ent *s, int move) {+ get_riders(s);+ Ent *rl[32];+ int nr = nriders;+ memcpy(rl, riders, sizeof(Ent *) * nr);+ s->y += move;+ plat_static_movers_move(s, v2(0, (float)move));+ if (s->collidable) {+ for (int i = 0; i < g_nents; i++) {+ Ent *a = &g_ents[i];+ if (!(a->kind & KIND_ACTOR) || !a->cls || a->dead == 1 || !a->allow_pushing) continue;+ uint8_t was = a->collidable;+ a->collidable = 1;+ if (!a->treat_naive && collide_ent_at(s, s->x, s->y, a)) {+ int mv = move > 0 ? (int)(e_bottom(s) - e_top(a)) : (int)(e_top(s) - e_bottom(a));+ s->collidable = 0;+ actor_move_v_exact(a, mv, actor_squish, s);+ actor_set_lift(a, s->lift);+ s->collidable = 1;+ } else if (is_rider(a, rl, nr)) {+ s->collidable = 0;+ if (a->treat_naive) actor_naive_move(a, v2(0, (float)move));+ else actor_move_v_exact(a, move, NULL, NULL);+ actor_set_lift(a, s->lift);+ s->collidable = 1;+ }+ a->collidable = was;+ }+ }+}++static void jumpthru_move_h_exact(Ent *j, int move) {+ if (j->collidable) {+ for (int i = 0; i < g_nents; i++) {+ Ent *a = &g_ents[i];+ if (!(a->kind & KIND_ACTOR) || !a->cls || a->dead == 1) continue;+ if (actor_is_riding_jumpthru(a, j)) {+ if (a->treat_naive) actor_naive_move(a, v2((float)move, 0));+ else actor_move_h_exact(a, move, NULL, NULL);+ }+ }+ }+ j->x += move;+ plat_static_movers_move(j, v2((float)move, 0));+}++static void jumpthru_move_v_exact(Ent *j, int move) {+ if (j->collidable) {+ for (int i = 0; i < g_nents; i++) {+ Ent *a = &g_ents[i];+ if (!(a->kind & KIND_ACTOR) || !a->cls || a->dead == 1) continue;+ if (move < 0) {+ if (actor_is_riding_jumpthru(a, j)) {+ j->collidable = 0;+ if (a->treat_naive) actor_naive_move(a, v2(0, (float)move));+ else actor_move_v_exact(a, move, NULL, NULL);+ actor_set_lift(a, j->lift);+ j->collidable = 1;+ } else if (!a->treat_naive && collide_ent_at(j, j->x, j->y + move, a) && !collide_ent_at(j, j->x, j->y, a)) {+ j->collidable = 0;+ actor_move_v_exact(a, (int)(e_top(j) + move - e_bottom(a)), NULL, NULL);+ actor_set_lift(a, j->lift);+ j->collidable = 1;+ }+ } else if (actor_is_riding_jumpthru(a, j)) {+ j->collidable = 0;+ if (a->treat_naive) actor_naive_move(a, v2(0, (float)move));+ else actor_move_v_exact(a, move, NULL, NULL);+ actor_set_lift(a, j->lift);+ j->collidable = 1;+ }+ }+ }+ j->y += move;+ plat_static_movers_move(j, v2(0, (float)move));+}++void plat_move_h_exact(Ent *e, int move) {+ if (e->kind & KIND_SOLID) solid_move_h_exact(e, move);+ else if (e->kind & KIND_JUMPTHRU) jumpthru_move_h_exact(e, move);+ else e->x += move;+}+void plat_move_v_exact(Ent *e, int move) {+ if (e->kind & KIND_SOLID) solid_move_v_exact(e, move);+ else if (e->kind & KIND_JUMPTHRU) jumpthru_move_v_exact(e, move);+ else e->y += move;+}++void plat_move_h(Ent *e, float amount) {+ e->lift.x = amount / DT;+ e->remx += amount;+ int n = roundi(e->remx);+ if (n) {+ e->remx -= n;+ plat_move_h_exact(e, n);+ }+}+void plat_move_v(Ent *e, float amount) {+ e->lift.y = amount / DT;+ e->remy += amount;+ int n = roundi(e->remy);+ if (n) {+ e->remy -= n;+ plat_move_v_exact(e, n);+ }+}+void plat_move_h_lift(Ent *e, float amount, float lift) {+ e->lift.x = lift;+ e->remx += amount;+ int n = roundi(e->remx);+ if (n) {+ e->remx -= n;+ plat_move_h_exact(e, n);+ }+}+void plat_move_v_lift(Ent *e, float amount, float lift) {+ e->lift.y = lift;+ e->remy += amount;+ int n = roundi(e->remy);+ if (n) {+ e->remy -= n;+ plat_move_v_exact(e, n);+ }+}+void plat_move_to_x(Ent *e, float x) { plat_move_h(e, x - (e->x + e->remx)); }+void plat_move_to_y(Ent *e, float y) { plat_move_v(e, y - (e->y + e->remy)); }+void plat_move_to(Ent *e, float x, float y) {+ plat_move_h(e, x - (e->x + e->remx));+ plat_move_v(e, y - (e->y + e->remy));+}+void plat_move_towards_x(Ent *e, float x, float amount) { plat_move_to_x(e, approach(e->x + e->remx, x, amount)); }+void plat_move_towards_y(Ent *e, float y, float amount) { plat_move_to_y(e, approach(e->y + e->remy, y, amount)); }++/* MoveVExactCollideSolids / MoveHExactCollideSolids: step by step, breaking dash blocks on the way */+static bool exact_collide_solids(Ent *e, int move, bool vertical, bool thru_dash_blocks) {+ float was = vertical ? e->y : e->x;+ int s = signi(move), moved = 0;+ Ent *hit = NULL;+ while (move) {+ float dx = vertical ? 0 : (float)s, dy = vertical ? (float)s : 0;+ if (thru_dash_blocks)+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o->cls && o->dead != 1 && o->collidable && level_is_dash_block(o) && collide_ent_at(e, e->x + dx, e->y + dy, o)) {+ level_break_dash_block(o, v2(dx, dy));+ level_shake(0.2f);+ }+ }+ hit = collide_first_solid(e, e->x + dx, e->y + dy);+ if (hit) break;+ if (vertical && move > 0) {+ hit = collide_first_jumpthru_outside(e, e->x, e->y + dy);+ if (hit) break;+ }+ moved += s;+ move -= s;+ if (vertical) e->y += s;+ else e->x += s;+ }+ if (vertical) e->y = was;+ else e->x = was;+ if (vertical) plat_move_v_exact(e, moved);+ else plat_move_h_exact(e, moved);+ return hit != NULL;+}+bool plat_move_v_collide_solids(Ent *e, float amount, bool thru_dash_blocks) {+ e->lift.y = amount / DT;+ e->remy += amount;+ int n = roundi(e->remy);+ if (!n) return false;+ e->remy -= n;+ return exact_collide_solids(e, n, true, thru_dash_blocks);+}+bool plat_move_h_collide_solids(Ent *e, float amount, bool thru_dash_blocks) {+ e->lift.x = amount / DT;+ e->remx += amount;+ int n = roundi(e->remx);+ if (!n) return false;+ e->remx -= n;+ return exact_collide_solids(e, n, false, thru_dash_blocks);+}++bool solid_has_player_rider(Ent *e) {+ Ent *p = level_player_ent();+ return p && actor_is_riding_solid(p, e);+}+bool solid_has_player_on_top(Ent *e) {+ Ent *p = level_player_ent();+ return p && collide_ent_at(e, e->x, e->y - 1, p);+}+bool solid_has_player_climbing(Ent *e) {+ Ent *p = level_player_ent();+ if (!p || !level_player_climbing()) return false;+ int f = level_player_facing();+ return f < 0 ? collide_ent_at(e, e->x + 1, e->y, p) : collide_ent_at(e, e->x - 1, e->y, p);+}+bool solid_has_rider(Ent *e) {+ for (int i = 0; i < g_nents; i++) {+ Ent *a = &g_ents[i];+ if ((a->kind & KIND_ACTOR) && a->cls && a->dead != 1 && actor_is_riding_solid(a, e)) return true;+ }+ return false;+}+bool jumpthru_has_player_rider(Ent *e) {+ Ent *p = level_player_ent();+ return p && actor_is_riding_jumpthru(p, e);+}diff --git a/games/celeste/src/ent.h b/games/celeste/src/ent.hnew file mode 100644index 00000000..a4492c07--- /dev/null+++ b/games/celeste/src/ent.h@@ -0,0 +1,191 @@+/* Entities, as in Monocle: a position, a collider, a depth; actors and+ * solids that move a whole pixel at a time with sub-pixel remainders. */+#ifndef ENT_H+#define ENT_H+#include "celeste.h"++typedef struct Ent Ent;+typedef struct Player Player;++enum { /* kinds (Monocle's Tracker types) */+ KIND_SOLID = 1, KIND_JUMPTHRU = 2, KIND_ACTOR = 4, KIND_TRIGGER = 8, KIND_PLAYER = 16,+ KIND_PCOLLIDE = 32, /* has a PlayerCollider */+ KIND_STATICMOVER = 64, /* sticks to a platform */+ KIND_SPIKES = 128, KIND_WATER = 256, KIND_DREAMBLOCK = 512, KIND_HOLDABLE = 1024, KIND_SPINNER = 2048,+ KIND_TALK = 4096, KIND_BLOCKFIELD = 8192, KIND_KILLBOX = 16384, KIND_CLIMBBLOCKER = 32768+};+enum { COL_NONE, COL_BOX, COL_CIRCLE, COL_GRID, COL_LIST };+enum { TAG_PERSISTENT = 1, TAG_GLOBAL = 2, TAG_HUD = 4, TAG_TRANSITION_UPDATE = 8, TAG_FROZEN_UPDATE = 16, TAG_PAUSE_UPDATE = 32 };+enum { DASH_NORMAL, DASH_REBOUND, DASH_BOUNCE, DASH_IGNORE };++/* depths (Celeste.Depths) */+enum {+ D_BGTERRAIN = 10000, D_BGMIRRORS = 11500, D_BGDECALS = 9000, D_BGPARTICLES = 8000, D_SOLIDSBELOW = 5000,+ D_BELOW = 2000, D_NPCS = 1000, D_THEOCRYSTAL = 100, D_PLAYER = 0, D_DUST = -50, D_PICKUPS = -100,+ D_PARTICLES = -8000, D_ABOVE = -8500, D_SOLIDS = -9000, D_FGTERRAIN = -10000, D_FGDECALS = -10500,+ D_DREAMBLOCKS = -11000, D_CRYSTALSPINNERS = -11500, D_PLAYERDREAMDASHING = -12000, D_ENEMY = -12500,+ D_FAKEWALLS = -13000, D_FGPARTICLES = -50000, D_TOP = -1000000, D_FORMATIONSEQUENCES = -2000000+};++typedef struct { V2 dir, moved, target; Ent *hit, *pusher; } Collision;+typedef void (*CollideFn)(Ent *self, Collision *c);++typedef struct {+ const char *name;+ uint16_t size; /* bytes of state (ST) */+ void (*update)(Ent *e);+ void (*render)(Ent *e);+ void (*awake)(Ent *e);+ void (*removed)(Ent *e);+ /* platforms */+ int (*on_dash_collide)(Ent *e, Player *p, V2 dir); /* DASH_* */+ void (*on_collide)(Ent *e, V2 dir);+ void (*on_shake)(Ent *e, V2 amount);+ void (*on_staticmover_trigger)(Ent *e, Ent *mover);+ /* PlayerCollider */+ void (*on_player)(Ent *e, Player *p);+ /* StaticMover */+ void (*sm_move)(Ent *e, V2 amount);+ void (*sm_shake)(Ent *e, V2 amount);+ void (*sm_enable)(Ent *e, bool on);+ void (*sm_destroy)(Ent *e);+ bool (*sm_riding)(Ent *e, Ent *platform); /* SolidChecker / JumpThruChecker */+ void (*sm_attach)(Ent *e, Ent *platform);+ /* actors */+ void (*on_squish)(Ent *e, Collision *c);+ bool (*is_riding_solid)(Ent *e, Ent *s);+ bool (*is_riding_jumpthru)(Ent *e, Ent *j);+ /* triggers */+ void (*on_enter)(Ent *e, Player *p);+ void (*on_stay)(Ent *e, Player *p);+ void (*on_leave)(Ent *e, Player *p);+ /* Follower: the leader got it / let it go; DashListener */+ void (*on_gain_leader)(Ent *e);+ void (*on_lose_leader)(Ent *e);+ void (*on_dash)(Ent *e, V2 dir);+ /* custom collision for entities made of many parts (spinners, clutter): e vs a rect */+ bool (*collide_rect)(const Ent *e, float l, float t, float r, float b);+ /* tracker-like membership */+ uint16_t kind;+} EntClass;++/* An entity: about 64 bytes here, plus its type's own state (EntClass.size bytes)+ * in a shared arena, reached with ST(e, Type). */+struct Ent {+ const EntClass *cls;+ float x, y;+ float remx, remy; /* movementCounter */+ V2 lift; /* platforms: LiftSpeed this frame; actors: current lift speed */+ int32_t depth;+ float cx, cy, cw, ch; /* collider: box left, top, width, height; circle: cx, cy, radius in cw */+ uint16_t kind;+ uint16_t eid; /* id in the map (EntityID with the room) */+ uint16_t order; /* insertion order, for stable depth sorting */+ uint16_t data; /* state: offset / 4 in the arena */+ uint16_t active : 1, visible : 1, collidable : 1, triggered : 1, safe : 1, treat_naive : 1, ignore_jumpthrus : 1,+ allow_pushing : 1, shaking : 1, awoken : 1, dead : 2, ctype : 3;+ uint8_t tags, room;+ int8_t shakex, shakey; /* Platform.Shake */+ uint16_t plat; /* static movers: the platform carrying them (g_ents index + 1, 0: none) */+};+#define MAX_ENTS 256+_Static_assert(sizeof(struct Ent) == (sizeof(void *) == 4 ? 64 : 72), "Ent: 64 bytes on the calculator");+#define ENT_ARENA (9 * 1024)+extern uint8_t g_ent_arena[];+/* the state of e, a T (its class's size must be sizeof(T)) */+#define ST(e, T) ((T *)(void *)(g_ent_arena + (uint32_t)(e)->data * 4))+/* actors keep their lift speed grace and squish callback here, at the start of their state */+typedef struct { V2 last_lift; float lift_timer; } ActorExt;+extern Ent g_ents[MAX_ENTS];+static inline Ent *ent_platform(const Ent *e) { return e->plat ? &g_ents[e->plat - 1] : NULL; }+static inline void ent_set_platform(Ent *e, const Ent *p) { e->plat = p ? (uint16_t)(p - g_ents + 1) : 0; }+extern int g_nents;++Ent *ent_new(const EntClass *cls, float x, float y);+extern uint16_t g_new_eid; /* the id in the map new entities get (EntityID), while a room loads */+void ent_remove(Ent *e);+void ent_box(Ent *e, float w, float h, float x, float y);+void ent_circle(Ent *e, float r, float x, float y);+void ents_update(void);+void ents_render_between(int depth_hi, int depth_lo);+void ents_render_hud(void);+void ents_flush_removed(void);+void ents_awake_new(void);+void ents_clear(bool keep_persistent);+void ents_remove_room(int room);+void ents_mark_unsorted(void);++/* the collider's bounds (a circle's: its center, radius cw) */+static inline float e_left(const Ent *e) { return e->x + e->cx - (e->ctype == COL_CIRCLE ? e->cw : 0); }+static inline float e_top(const Ent *e) { return e->y + e->cy - (e->ctype == COL_CIRCLE ? e->cw : 0); }+static inline float e_right(const Ent *e) { return e->x + e->cx + e->cw; }+static inline float e_bottom(const Ent *e) { return e->y + e->cy + (e->ctype == COL_CIRCLE ? e->cw : e->ch); }+static inline float e_cxm(const Ent *e) { return e->x + e->cx + (e->ctype == COL_CIRCLE ? 0 : e->cw / 2); }+static inline float e_cym(const Ent *e) { return e->y + e->cy + (e->ctype == COL_CIRCLE ? 0 : e->ch / 2); }+static inline V2 e_center(const Ent *e) { return v2(e_cxm(e), e_cym(e)); }++/* collision of e's collider moved to (x, y) */+bool collide_ent_at(const Ent *e, float x, float y, const Ent *other);+bool collide_rect(const Ent *e, float l, float t, float r, float b); /* e's collider vs a rect */+Ent *collide_first_solid(const Ent *e, float x, float y);+bool collide_solid(const Ent *e, float x, float y);+Ent *collide_first_jumpthru_outside(const Ent *e, float x, float y); /* CollideFirstOutside<JumpThru> */+bool collide_jumpthru(const Ent *e, float x, float y); /* CollideCheck<JumpThru> */+Ent *collide_first_kind(const Ent *e, float x, float y, uint16_t kind);+bool rect_solid(float l, float t, float r, float b); /* Scene.CollideCheck<Solid>(rect) */+bool point_solid(float x, float y);++/* Actor */+bool actor_move_h(Ent *e, float amount, CollideFn cb, Ent *pusher);+bool actor_move_v(Ent *e, float amount, CollideFn cb, Ent *pusher);+bool actor_move_h_exact(Ent *e, int amount, CollideFn cb, Ent *pusher);+bool actor_move_v_exact(Ent *e, int amount, CollideFn cb, Ent *pusher);+void actor_move_to_x(Ent *e, float x, CollideFn cb);+void actor_move_to_y(Ent *e, float y, CollideFn cb);+void actor_move_towards_x(Ent *e, float x, float amount, CollideFn cb);+void actor_move_towards_y(Ent *e, float y, float amount, CollideFn cb);+void actor_naive_move(Ent *e, V2 amount);+bool actor_on_ground(const Ent *e, int down);+bool actor_on_ground_at(Ent *e, float x, float y, int down);+bool actor_try_squish_wiggle(Ent *e, Collision *c);+void actor_set_lift(Ent *e, V2 v);+V2 actor_lift(const Ent *e);+void actor_update_lift(Ent *e);+bool actor_is_riding_solid(Ent *e, Ent *s);+bool actor_is_riding_jumpthru(Ent *e, Ent *j);++/* Platform (Solid / JumpThru) */+void plat_move_h(Ent *e, float amount);+void plat_move_v(Ent *e, float amount);+void plat_move_h_lift(Ent *e, float amount, float lift);+void plat_move_v_lift(Ent *e, float amount, float lift);+void plat_move_h_exact(Ent *e, int amount);+void plat_move_v_exact(Ent *e, int amount);+void plat_move_to(Ent *e, float x, float y);+void plat_move_to_x(Ent *e, float x);+void plat_move_to_y(Ent *e, float y);+void plat_move_towards_x(Ent *e, float x, float amount);+void plat_move_towards_y(Ent *e, float y, float amount);+bool plat_move_v_collide_solids(Ent *e, float amount, bool thru_dash_blocks);+bool plat_move_h_collide_solids(Ent *e, float amount, bool thru_dash_blocks);+void plat_update(Ent *e); /* lift speed reset and shaking */+void plat_start_shaking(Ent *e, float time);+void plat_stop_shaking(Ent *e);+void plat_static_movers_attach(Ent *e);+void plat_static_movers_move(Ent *e, V2 amount);+void plat_static_movers_shake(Ent *e, V2 amount);+void plat_static_movers_enable(Ent *e, bool on);+void plat_static_movers_destroy(Ent *e);+void plat_static_movers_trigger(Ent *e);+bool solid_has_player_rider(Ent *e);+bool solid_has_player_on_top(Ent *e);+bool solid_has_player_climbing(Ent *e);+bool solid_has_rider(Ent *e);+bool jumpthru_has_player_rider(Ent *e);+#define e_shake(e) v2((e)->shakex, (e)->shakey)+static inline V2 plat_exact(const Ent *e) { return v2(e->x + e->remx, e->y + e->remy); }++/* the level's tiles act as one solid (SolidTiles) */+extern Ent *g_solidtiles;+bool tiles_solid_rect(float l, float t, float r, float b);+#endifdiff --git a/games/celeste/src/entities.c b/games/celeste/src/entities.cnew file mode 100644index 00000000..c78e3e02--- /dev/null+++ b/games/celeste/src/entities.c@@ -0,0 +1,1303 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* The entities of Prologue and Forsaken City and the ones every chapter+ * uses: spikes, springs, refills, strawberries, jumpthrus, zip movers,+ * crumbling and falling blocks, dash blocks, fake walls, camera triggers. */+#include "entities.h"+#include "npc.h"++/* ---------------------------------------------------------------- records */+float ea_num(const EData *d, int off, char kind) {+ const uint8_t *p = d->attrs + off;+ switch (kind) {+ case 'b': return p[0] ? 1.f : 0.f;+ case 'i': return (float)rds16(p);+ case 'I': return (float)rds32(p);+ case 'f': return rdf(p);+ }+ return 0;+}+const char *ea_str(const EData *d, int off) { return str(rd16(d->attrs + off)); }+V2 ed_node(const EData *d, int i) {+ if (i >= d->nnodes) return v2(d->x, d->y);+ return v2(d->rx + rds16(d->nodes + 4 * i), d->ry + rds16(d->nodes + 4 * i + 2));+}+uint32_t level_entity_hash(const EData *d) { return level_entity_id(d->room, d->id); }++const char *area_jumpthru(void) {+ /* AreaData.Jumpthru */+ static const char *J[] = {"wood", "wood", "wood", "wood", "cliffside", "temple", "reflection", "temple", "wood", "core", "wood"};+ int a = g_session.area;+ return a < 11 ? J[a] : "wood";+}+const char *area_crumble(void) {+ int a = g_session.area;+ return a == 4 ? "cliffside" : "default";+}+static int area_spike(void) { /* AreaData.Spike: 0 default, 1 outline, 2 cliffside, 3 reflection */+ int a = g_session.area;+ return a == 4 ? 2 : a == 6 ? 3 : a == 7 ? 1 : 0;+}++static uint16_t tex_by_name(const char *path);++/* ---------------------------------------------------------------- Wiggler, SineWave */+void wiggler_init(Wiggler *w, float duration, float freq) {+ w->counter = w->sine_counter = 0;+ w->increment = 1 / duration;+ w->sine_add = PI_F * 2 * freq;+ w->active = false;+}+void wiggler_restart(Wiggler *w) {+ w->counter = 1;+ if (w->start_zero) w->sine_counter = PI_F / 2, w->value = 0;+ else w->sine_counter = 0, w->value = 1;+ w->active = true;+}+void wiggler_start(Wiggler *w, float duration, float freq) {+ w->increment = 1 / duration;+ w->sine_add = PI_F * 2 * freq;+ wiggler_restart(w);+}+void wiggler_update(Wiggler *w) {+ if (!w->active) return;+ w->sine_counter += w->sine_add * DT;+ w->counter -= w->increment * DT;+ if (w->counter <= 0) {+ w->counter = 0;+ w->active = false;+ }+ w->value = cosf(w->sine_counter) * w->counter;+}+void sine_set(SineWave *s, float counter) {+ s->counter = fmodf(counter + PI_F * 8, PI_F * 8);+ s->value = sinf(s->counter);+ s->value_over_two = sinf(s->counter / 2);+ s->two_value = sinf(s->counter * 2);+}+void sine_randomize(SineWave *s) { sine_set(s, rndf() * (PI_F * 2) * 2); }+void sine_update(SineWave *s) { sine_set(s, s->counter + PI_F * 2 * s->freq * DT); }+void tween_start(Tween *t, float duration) {+ t->duration = duration;+ t->time_left = duration;+ t->percent = 0;+ t->active = true;+}+bool tween_update(Tween *t) {+ if (!t->active) return false;+ t->time_left -= DT;+ t->percent = 1 - fmaxf(0, t->time_left) / t->duration;+ if (t->time_left <= 0) {+ t->time_left = 0;+ t->active = false;+ return true;+ }+ return false;+}++/* ---------------------------------------------------------------- spawn points */+#define MAX_SPAWNS 48+static V2 spawns[2][MAX_SPAWNS];+static int nspawns[2];++V2 level_closest_spawn(V2 at) {+ int s = g_level.room_slot;+ if (!nspawns[s]) return at;+ V2 best = spawns[s][0];+ float bd = 1e30f;+ for (int i = 0; i < nspawns[s]; i++) {+ float dx = spawns[s][i].x - at.x, dy = spawns[s][i].y - at.y, d = dx * dx + dy * dy;+ if (d < bd) bd = d, best = spawns[s][i];+ }+ return best;+}++/* DashListener.OnDash, for each that listens */+void level_dash_listeners(V2 dir) {+ for (int i = 0; i < g_nents; i++) {+ Ent *e = &g_ents[i];+ if (e->cls && e->dead != 1 && e->cls->on_dash) e->cls->on_dash(e, dir);+ }+}+WEAK void level_booster_boosted(Ent *b, V2 dir) { (void)b, (void)dir; }+/* Holdables (Theo's crystal, src/ch5.c): the player picks up, carries, throws */+WEAK Ent *level_holdable_check(void) { return NULL; }+WEAK void holdable_carry(Ent *h, V2 at) { (void)h, (void)at; }+WEAK void holdable_release(Ent *h, V2 force) { (void)h, (void)force; }+bool level_is_dash_block(Ent *e) { return e->cls && !strcmp(e->cls->name, "dashBlock"); }++/* ---------------------------------------------------------------- JumpthruPlatform */+typedef struct { uint16_t tex; uint8_t cols, n, first_row, last_row; uint32_t seed; } JumpThru;+/* the middle columns' pieces were Calc.Random picks: a hash of the place */+static void jt_piece(JumpThru *j, int i, int *col, int *row) {+ if (i == 0) *col = 0, *row = j->first_row;+ else if (i == j->cols - 1) *col = j->n - 1, *row = j->last_row;+ else {+ uint32_t h = (j->seed + (uint32_t)i * 2654435761u) ^ 0x9E3779B9u;+ h ^= h >> 15, h *= 0x2C1B3C6Du, h ^= h >> 12;+ *col = 1 + (int)(h % (uint32_t)(j->n > 2 ? j->n - 2 : 1));+ *row = (int)((h >> 8) & 1);+ }+}+static void jumpthru_awake(Ent *e) {+ JumpThru *j = ST(e, JumpThru);+ Tex t;+ j->n = tex_get(j->tex, &t) ? (uint8_t)(t.fw / 8) : 3;+ j->first_row = !collide_solid(e, e->x - 1, e->y);+ j->last_row = !collide_solid(e, e->x + 1, e->y);+ j->seed = (uint32_t)(int)e->x * 73856093u ^ (uint32_t)(int)e->y * 19349663u;+}+static void jumpthru_render(Ent *e) {+ JumpThru *j = ST(e, JumpThru);+ for (int i = 0; i < j->cols; i++) {+ int col, row;+ jt_piece(j, i, &col, &row);+ gfx_tex_part(j->tex, e->x + i * 8, e->y, col * 8, row * 8, 8, 8, 0, 0xFFFF, 255);+ }+}+static void jumpthru_update(Ent *e) { plat_update(e); }+static const EntClass JUMPTHRU = {.size = sizeof(JumpThru), .name = "jumpThru", .update = jumpthru_update, .render = jumpthru_render,+ .awake = jumpthru_awake, .kind = KIND_JUMPTHRU};++static void new_jumpthru(const EData *d) {+ int w = (int)EA(d, jumpThru, width);+ Ent *e = ent_new(&JUMPTHRU, d->x, d->y);+ if (!e) return;+ ent_box(e, (float)w, 5, 0, 0);+ e->safe = 1;+ e->depth = -60;+ JumpThru *j = ST(e, JumpThru);+ j->cols = (uint8_t)(w / 8);+ const char *tx = EAS(d, jumpThru, texture);+ char path[48];+ path2(path, "objects/jumpthru/", (*tx && strcmp(tx, "default")) ? tx : area_jumpthru(), -1);+ j->tex = tex_by_name(path);+}++/* ---------------------------------------------------------------- Spikes */+enum { DIR_UP, DIR_DOWN, DIR_LEFT, DIR_RIGHT };+typedef struct {+ uint8_t dir, n, cassette, on;+ uint16_t tex, tint, tint_off; /* on a cassette block: its colors (enabled, disabled) */+ int16_t gox, goy; /* and its group's origin (SetOrigins), from the spikes */+} Spikes;+static void spikes_on_player(Ent *e, Player *p) {+ Spikes *s = ST(e, Spikes);+ switch (s->dir) {+ case DIR_UP: if (p->speed.y >= 0 && e_bottom(p->ent) <= e_bottom(e)) player_die(p, v2(0, -1), false); break;+ case DIR_DOWN: if (p->speed.y <= 0) player_die(p, v2(0, 1), false); break;+ case DIR_LEFT: if (p->speed.x >= 0) player_die(p, v2(-1, 0), false); break;+ case DIR_RIGHT: if (p->speed.x <= 0) player_die(p, v2(1, 0), false); break;+ }+}+static bool spikes_riding(Ent *e, Ent *p) {+ Spikes *s = ST(e, Spikes);+ if (p->kind & KIND_JUMPTHRU) return s->dir == DIR_UP && collide_ent_at(e, e->x, e->y + 1, p);+ float dx = 0, dy = 0;+ switch (s->dir) {+ case DIR_UP: dy = 1; break;+ case DIR_DOWN: dy = -1; break;+ case DIR_LEFT: dx = 1; break;+ case DIR_RIGHT: dx = -1; break;+ }+ return collide_ent_at(e, e->x + dx, e->y + dy, p) && !collide_ent_at(e, e->x, e->y, p);+}+static void spikes_render(Ent *e) {+ Spikes *s = ST(e, Spikes);+ Tex t;+ if (!tex_get(s->tex, &t)) return;+ for (int j = 0; j < s->n; j++) {+ float x = e->x, y = e->y, ox = 0, oy = 0;+ switch (s->dir) {+ case DIR_UP: ox = t.fw * .5f, oy = (float)t.fh, x += (j + .5f) * 8, y += 1; break;+ case DIR_DOWN: ox = t.fw * .5f, oy = 0, x += (j + .5f) * 8, y -= 1; break;+ case DIR_RIGHT: ox = 0, oy = t.fh * .5f, y += (j + .5f) * 8, x -= 1; break;+ case DIR_LEFT: ox = (float)t.fw, oy = t.fh * .5f, y += (j + .5f) * 8, x += 1; break;+ }+ if (s->cassette) { /* scaled with the block's group around its origin */+ V2 o, k;+ if (!cassette_block_scale(ent_platform(e), &o, &k)) k = v2(1, 1);+ float gx = e->x + s->gox, gy = e->y + s->goy;+ gfx_tex_ex(s->tex, gx + e->shakex, gy + e->shakey, ox + gx - x, oy + gy - y, k.x, k.y, 0, s->on ? s->tint : s->tint_off,+ 255, 0);+ } else+ gfx_tex_ex(s->tex, x + e->shakex, y + e->shakey, ox, oy, 1, 1, 0, 0xFFFF, 255, 0);+ }+}+/* StaticMover.OnEnable / OnDisable (VisibleWhenDisabled on cassette blocks) */+static void spikes_sm_enable(Ent *e, bool on) {+ Spikes *s = ST(e, Spikes);+ e->active = e->collidable = on;+ if (on) e->visible = 1;+ else if (!s->cassette) e->visible = 0;+ s->on = on; /* the color: enabled or disabled */+}+void spikes_set_cassette(Ent *e, uint16_t on, uint16_t off, V2 origin) {+ Spikes *s = ST(e, Spikes);+ s->cassette = 1;+ s->tint = on, s->tint_off = off;+ s->on = e->collidable;+ s->gox = (int16_t)(origin.x - e->x), s->goy = (int16_t)(origin.y - e->y);+}+static void spikes_sm_shake(Ent *e, V2 a) { e->shakex = (int8_t)(e->shakex + a.x), e->shakey = (int8_t)(e->shakey + a.y); }+static const EntClass SPIKES = {.size = sizeof(Spikes), .name = "spikes", .render = spikes_render, .on_player = spikes_on_player,+ .sm_riding = spikes_riding, .sm_shake = spikes_sm_shake, .sm_enable = spikes_sm_enable,+ .kind = KIND_PCOLLIDE | KIND_STATICMOVER | KIND_SPIKES};++static void new_spikes(const EData *d, int dir) {+ int size;+ const char *type;+ if (dir == DIR_UP) size = (int)EA(d, spikesUp, width), type = EAS(d, spikesUp, type);+ else if (dir == DIR_DOWN) size = (int)EA(d, spikesDown, width), type = EAS(d, spikesDown, type);+ else if (dir == DIR_LEFT) size = (int)EA(d, spikesLeft, height), type = EAS(d, spikesLeft, type);+ else size = (int)EA(d, spikesRight, height), type = EAS(d, spikesRight, type);+ Ent *e = ent_new(&SPIKES, d->x, d->y);+ if (!e) return;+ e->depth = -1;+ switch (dir) {+ case DIR_UP: ent_box(e, (float)size, 3, 0, -3); break;+ case DIR_DOWN: ent_box(e, (float)size, 3, 0, 0); break;+ case DIR_LEFT: ent_box(e, 3, (float)size, -3, 0); break;+ case DIR_RIGHT: ent_box(e, 3, (float)size, 0, 0); break;+ }+ Spikes *s = ST(e, Spikes);+ s->dir = (uint8_t)dir;+ s->n = (uint8_t)(size / 8);+ static const char *names[] = {"default", "outline", "cliffside", "reflection"};+ static const char *dirs[] = {"up", "down", "left", "right"};+ const char *t = (*type && strcmp(type, "default")) ? type : names[area_spike()];+ char path[48], tmp[24];+ path2(tmp, t, "_", -1);+ path2(path, "danger/spikes/", path2(tmp + 12 - 12, tmp, dirs[dir], -1), 0);+ s->tex = tex_by_name(path);+}++/* ---------------------------------------------------------------- Spring */+typedef struct { uint8_t orient, can_use; Sprite spr; Wiggler wig; } Spring;+enum { SPRING_FLOOR, SPRING_WALLLEFT, SPRING_WALLRIGHT };+static uint16_t spring_tex[7];++static void spring_on_player(Ent *e, Player *p) {+ Spring *s = ST(e, Spring);+ if (p->state == ST_DREAMDASH || !s->can_use) return;+ bool bounce = false;+ if (s->orient == SPRING_FLOOR) {+ if (p->speed.y >= 0) bounce = true, player_super_bounce(p, e_top(e));+ } else if (s->orient == SPRING_WALLLEFT) {+ bounce = true;+ player_side_bounce(p, 1, e_right(e), e_cym(e));+ } else {+ bounce = true;+ player_side_bounce(p, -1, e_left(e), e_cym(e));+ }+ if (bounce) {+ if (ent_platform(e)) plat_static_movers_trigger(ent_platform(e));+ s->spr.frame = 0;+ s->spr.timer = 0;+ s->spr.playing = 1;+ wiggler_start(&s->wig, 1, 4);+ }+}+static const uint8_t SPRING_SEQ[] = {0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 5};+static void spring_update(Ent *e) {+ Spring *s = ST(e, Spring);+ if (s->spr.playing) {+ s->spr.timer += DT;+ while (s->spr.timer >= 0.07f && s->spr.playing) {+ s->spr.timer -= 0.07f;+ if (++s->spr.frame >= sizeof SPRING_SEQ) s->spr.frame = 0, s->spr.playing = 0;+ }+ }+ wiggler_update(&s->wig);+}+static void spring_render(Ent *e) {+ Spring *s = ST(e, Spring);+ int f = s->spr.playing ? SPRING_SEQ[s->spr.frame] : 0;+ uint16_t t = s->can_use ? spring_tex[f] : spring_tex[6];+ float sy = 1 + s->wig.value * 0.2f;+ float rot = s->orient == SPRING_WALLLEFT ? PI_F / 2 : s->orient == SPRING_WALLRIGHT ? -PI_F / 2 : 0;+ gfx_tex_ex(t, e->x, e->y, 8, 16, 1, sy, rot, 0xFFFF, 255, 0);+}+static bool spring_riding(Ent *e, Ent *p) {+ Spring *s = ST(e, Spring);+ float dx = s->orient == SPRING_WALLLEFT ? -1 : s->orient == SPRING_WALLRIGHT ? 1 : 0;+ float dy = s->orient == SPRING_FLOOR ? 1 : 0;+ return collide_ent_at(e, e->x + dx, e->y + dy, p);+}+static void spring_attach(Ent *e, Ent *p) {+ e->depth = (int16_t)(p->depth + 1);+ ents_mark_unsorted();+}+static const EntClass SPRING = {.size = sizeof(Spring), .name = "spring", .update = spring_update, .render = spring_render,+ .on_player = spring_on_player, .sm_riding = spring_riding, .sm_attach = spring_attach,+ .kind = KIND_PCOLLIDE | KIND_STATICMOVER};++static void new_spring(const EData *d, int orient, bool can_use) {+ if (!spring_tex[0]) {+ char p[32];+ for (int i = 0; i < 6; i++) path2(p, "objects/spring/", NULL, i), spring_tex[i] = tex_by_name(p);+ spring_tex[6] = tex_by_name("objects/spring/white");+ }+ Ent *e = ent_new(&SPRING, d->x, d->y);+ if (!e) return;+ e->depth = -8501;+ Spring *s = ST(e, Spring);+ s->orient = (uint8_t)orient;+ s->can_use = can_use;+ if (orient == SPRING_FLOOR) ent_box(e, 16, 6, -8, -6);+ else if (orient == SPRING_WALLLEFT) ent_box(e, 6, 16, 0, -8);+ else ent_box(e, 6, 16, -6, -8);+}++/* ---------------------------------------------------------------- Refill */+typedef struct {+ uint8_t two, one_use, visible, outline, flash_on, step;+ float respawn, flash_t, co_wait, frame_t;+ int frame, flash_frame;+ SineWave sine;+ Wiggler wig;+ uint16_t idle[5], flash[6], outline_tex;+} Refill;++static void refill_on_player(Ent *e, Player *p) {+ Refill *r = ST(e, Refill);+ if (player_use_refill(p, r->two)) {+ e->collidable = 0;+ r->respawn = 2.5f;+ r->step = 1; /* RefillRoutine */+ level_freeze(0.05f);+ }+}+static void refill_update(Ent *e) {+ Refill *r = ST(e, Refill);+ if (r->step == 1) { /* yield null after the freeze */+ r->step = 2;+ } else if (r->step == 2) {+ level_shake(.3f);+ r->visible = 0;+ r->flash_on = 0;+ if (!r->one_use) r->outline = 1;+ e->depth = 8999;+ ents_mark_unsorted();+ r->co_wait = 0.05f;+ r->step = 3;+ } else if (r->step == 3) {+ if ((r->co_wait -= DT) <= 0) {+ Player *p = level_player();+ float a = p ? atan2f(p->speed.y, p->speed.x) : 0;+ particles_emit(PL_FG, (r->two ? &P_Refill_P_ShatterTwo : &P_Refill_P_Shatter), 5, v2(e->x, e->y), v2(4, 4), a - PI_F / 2);+ particles_emit(PL_FG, (r->two ? &P_Refill_P_ShatterTwo : &P_Refill_P_Shatter), 5, v2(e->x, e->y), v2(4, 4), a + PI_F / 2);+ r->step = 0;+ if (r->one_use) ent_remove(e);+ }+ }+ if (r->respawn > 0) {+ r->respawn -= DT;+ if (r->respawn <= 0 && !e->collidable) {+ e->collidable = 1;+ r->visible = 1;+ r->outline = 0;+ e->depth = -100;+ ents_mark_unsorted();+ wiggler_start(&r->wig, 1, 4);+ particles_emit(PL_FG, (r->two ? &P_Refill_P_RegenTwo : &P_Refill_P_Regen), 16, v2(e->x, e->y), v2(2, 2), 0);+ }+ } else if (level_on_interval(0.1f) && r->visible)+ particles_emit(PL_FG, (r->two ? &P_Refill_P_GlowTwo : &P_Refill_P_Glow), 1, v2(e->x, e->y), v2(5, 5), 0);+ sine_update(&r->sine);+ wiggler_update(&r->wig);+ r->frame_t += DT;+ if (r->frame_t >= 0.1f) r->frame_t -= 0.1f, r->frame = (r->frame + 1) % 5;+ if (r->flash_on) {+ r->flash_t += DT;+ if (r->flash_t >= 0.05f) {+ r->flash_t -= 0.05f;+ if (++r->flash_frame >= 6) r->flash_on = 0;+ }+ }+ if (level_on_interval(2) && r->visible) r->flash_on = 1, r->flash_frame = 0, r->flash_t = 0;+}+static void refill_render(Ent *e) {+ Refill *r = ST(e, Refill);+ float y = e->y + r->sine.value * 2, s = 1 + r->wig.value * 0.2f;+ if (r->outline) gfx_tex_ex(r->outline_tex, e->x, e->y, 8, 8, 1, 1, 0, 0xFFFF, 255, 0);+ if (r->visible) gfx_tex_ex(r->idle[r->frame], e->x, y, 8, 8, s, s, 0, 0xFFFF, 255, 0);+ if (r->visible && r->flash_on) gfx_tex_ex(r->flash[r->flash_frame], e->x, y, 8, 8, s, s, 0, 0xFFFF, 255, 0);+}+static const EntClass REFILL = {.size = sizeof(Refill), .name = "refill", .update = refill_update, .render = refill_render,+ .on_player = refill_on_player, .kind = KIND_PCOLLIDE};+static void new_refill(const EData *d) {+ Ent *e = ent_new(&REFILL, d->x, d->y);+ if (!e) return;+ ent_box(e, 16, 16, -8, -8);+ e->depth = -100;+ Refill *r = ST(e, Refill);+ r->two = EAB(d, refill, twoDash);+ r->one_use = EAB(d, refill, oneUse);+ r->visible = 1;+ r->sine.freq = 0.6f;+ sine_randomize(&r->sine);+ const char *base = r->two ? "objects/refillTwo/" : "objects/refill/";+ char p[48];+ for (int i = 0; i < 5; i++) path2(p, base, "idle", i), r->idle[i] = tex_by_name(p);+ for (int i = 0; i < 6; i++) path2(p, base, "flash", i), r->flash[i] = tex_by_name(p);+ path2(p, base, "outline", -1);+ r->outline_tex = tex_by_name(p);+}++/* ---------------------------------------------------------------- level-wide entities */+/* effects that live as long as the level (SlashFx and the like) */+static void fx_entity_update(Ent *e) {+ (void)e;+ fx_update();+}+static const EntClass FX = {.name = "fx", .update = fx_entity_update};++/* FormationBackdrop: darkens the level behind hearts, cassettes, seeds being put together */+static void formation_update(Ent *e) {+ (void)e;+ g_level.formation_fade = approach(g_level.formation_fade, g_level.formation ? 1.f : 0.f, DT * 3);+}+static void formation_render(Ent *e) {+ (void)e;+ float a = g_level.formation_fade * g_level.formation_alpha * 0.85f;+ if (a > 0) gfx_rect(g_level.cam.x - 1, g_level.cam.y - 1, 322, 182, 0, (uint8_t)(a * 255));+}+static const EntClass FORMATION = {.name = "formationBackdrop", .update = formation_update, .render = formation_render};++/* ---------------------------------------------------------------- CrumblePlatform */+#define CRUMBLE_MAX 40+typedef struct {+ uint8_t n, state, on_top, fell; /* fell: 0 standing, 1 falling out, 2 coming back */+ float timer, outline_a, fade_from, fade_to, fade_t, wait, tiles_t;+ int step;+ uint16_t tex, outline;+ uint8_t order[CRUMBLE_MAX]; /* fall order: tile k falls (order[k] % 4) * 0.05 s late */+} Crumble;++static float crumble_delay(Crumble *c, int img) {+ for (int k = 0; k < c->n; k++)+ if (c->order[k] == img) return (k % 4) * 0.05f;+ return 0;+}+static void crumble_emit(Ent *e, Crumble *c) {+ for (int i = 0; i < c->n; i++) particles_emit(PL_MID, &P_CrumblePlatform_P_Crumble, 2, v2(e->x + 4 + i * 8, e->y + 6), v2(3, 3), 0);+}+static void crumble_update(Ent *e) {+ Crumble *c = ST(e, Crumble);+ plat_update(e);+ if (c->fade_t < 1) {+ c->fade_t += DT * 2;+ c->outline_a = c->fade_from + (c->fade_to - c->fade_from) * ease_cube_inout(fminf(c->fade_t, 1));+ }+ c->tiles_t += DT;+ switch (c->step) {+ case 0: { /* waiting for the player */+ bool top = solid_has_player_on_top(e);+ if (!top && !solid_has_player_climbing(e)) return;+ c->on_top = top;+ c->timer = top ? 0.6f : 1.f; /* ShakeFor */+ crumble_emit(e, c);+ c->state = top ? 1 : 3;+ c->wait = 0.2f;+ c->step = 1;+ break;+ }+ case 1: /* bursts every 0.2 s */+ c->timer -= DT;+ if ((c->wait -= DT) <= 0) {+ crumble_emit(e, c);+ if (--c->state == 0) c->step = 2, c->wait = 0.4f;+ else c->wait = 0.2f;+ }+ break;+ case 2: /* 0.4 s more (while the player stays on top) */+ c->timer -= DT;+ c->wait -= DT;+ if (c->wait <= 0 || (c->on_top && !solid_has_player_on_top(e))) {+ c->fade_from = 0, c->fade_to = 1, c->fade_t = 0;+ e->collidable = 0;+ c->fell = 1;+ c->tiles_t = 0;+ c->step = 3;+ c->wait = 2;+ }+ break;+ case 3:+ if ((c->wait -= DT) > 0) break;+ {+ bool blocked = false;+ e->collidable = 1;+ for (int i = 0; i < g_nents && !blocked; i++) {+ Ent *o = &g_ents[i];+ if (o != e && o->cls && o->dead != 1 && (o->kind & (KIND_ACTOR | KIND_SOLID)) && o->collidable && collide_ent_at(e, e->x, e->y, o))+ blocked = true;+ }+ e->collidable = 0;+ if (blocked) break;+ }+ c->fade_from = 1, c->fade_to = 0, c->fade_t = 0;+ e->collidable = 1;+ c->fell = 2;+ c->tiles_t = 0;+ c->step = 0;+ break;+ }+}+static void crumble_render(Ent *e) {+ Crumble *c = ST(e, Crumble);+ if (c->outline_a > 0) {+ uint8_t a = (uint8_t)(c->outline_a * 255);+ for (int i = 0; i < c->n; i++) {+ int col = c->n == 1 ? 3 : i == 0 ? 0 : i < c->n - 1 ? 1 : 2;+ gfx_tex_part(c->outline, e->x + i * 8, e->y, col * 8, 0, 8, 8, 0, 0xFFFF, a);+ }+ }+ bool shaking = c->timer > 0 && (c->step == 1 || c->step == 2);+ for (int i = 0; i < c->n; i++) {+ int col = (int)((fabsf(e->x) + i * 8) / 8) % 4;+ float x = e->x + i * 8, y = e->y;+ uint16_t tint = 0xFFFF;+ uint8_t a = 255;+ float t = c->tiles_t - crumble_delay(c, i);+ if (c->fell == 1) { /* TileOut: grey, then falls away */+ tint = 0x8410;+ if (t > 0) {+ float k = t / 0.25f;+ if (k >= 1) continue;+ a = (uint8_t)(255 * (1 - k));+ y += k * k * 12;+ }+ } else if (c->fell == 2) { /* TileIn */+ if (t < 0) continue;+ }+ if (shaking) x += (float)(rndi(3) - 1), y += (float)(rndi(3) - 1);+ if (c->fell == 2 && t < 0.25f) {+ float sc = 1 + ease_bounce_out(1 - t / 0.25f) * 0.2f;+ gfx_tex_ex(c->tex, x + 4, y + 4, (float)(col * 8 + 4), 4, sc, sc, 0, tint, a, 0);+ } else+ gfx_tex_part(c->tex, x, y, col * 8, 0, 8, 8, 0, tint, a);+ }+}+static const EntClass CRUMBLE = {.size = sizeof(Crumble), .name = "crumbleBlock", .update = crumble_update, .render = crumble_render, .kind = KIND_SOLID};+static void new_crumble(const EData *d) {+ Ent *e = ent_new(&CRUMBLE, d->x, d->y);+ if (!e) return;+ int w = (int)EA(d, crumbleBlock, width);+ ent_box(e, (float)w, 8, 0, 0);+ Crumble *c = ST(e, Crumble);+ c->n = (uint8_t)(w / 8 > CRUMBLE_MAX ? CRUMBLE_MAX : w / 8);+ char p[48];+ path2(p, "objects/crumbleBlock/", area_crumble(), -1);+ c->tex = tex_by_name(p);+ c->outline = tex_by_name("objects/crumbleBlock/outline");+ c->fade_t = 1;+ for (int i = 0; i < c->n; i++) c->order[i] = (uint8_t)i;+ for (int i = c->n - 1; i > 0; i--) {+ int j = rndi(i + 1);+ uint8_t t = c->order[i];+ c->order[i] = c->order[j], c->order[j] = t;+ }+}++/* ---------------------------------------------------------------- ZipMover */+typedef struct {+ V2 start, target;+ float percent, at, wait;+ int step, light;+ uint16_t cog, block, light_tex[4], inner[12];+ int ninner;+} Zip;++static void zip_update(Ent *e) {+ Zip *z = ST(e, Zip);+ plat_update(e);+ switch (z->step) {+ case 0:+ if (!solid_has_player_rider(e)) break;+ plat_start_shaking(e, 0.1f);+ z->wait = 0.1f;+ z->step = 1;+ break;+ case 1:+ if ((z->wait -= DT) > 0) break;+ z->light = 3;+ z->at = 0;+ z->step = 2;+ break;+ case 2: /* yield null, then move */+ z->at = approach(z->at, 1, 2 * DT);+ z->percent = ease_sine_in(z->at);+ plat_move_to(e, lerpf(z->start.x, z->target.x, z->percent), lerpf(z->start.y, z->target.y, z->percent));+ if (z->at >= 1) {+ plat_start_shaking(e, 0.2f);+ level_shake(.3f);+ z->wait = 0.5f;+ z->step = 3;+ }+ break;+ case 3:+ if ((z->wait -= DT) > 0) break;+ z->light = 2;+ z->at = 0;+ z->step = 4;+ break;+ case 4:+ z->at = approach(z->at, 1, 0.5f * DT);+ z->percent = 1 - ease_sine_in(z->at);+ plat_move_to(e, lerpf(z->target.x, z->start.x, ease_sine_in(z->at)), lerpf(z->target.y, z->start.y, ease_sine_in(z->at)));+ if (z->at >= 1) {+ plat_start_shaking(e, 0.2f);+ z->light = 1;+ z->wait = 0.5f;+ z->step = 5;+ }+ break;+ case 5:+ if ((z->wait -= DT) > 0) break;+ z->step = 0;+ break;+ }+}+static float fmod1(float x) { return x - floorf(x); }+static void zip_render(Ent *e) {+ Zip *z = ST(e, Zip);+ float x = e->x + e->shakex, y = e->y + e->shakey, w = e->cw, h = e->ch;+ gfx_rect(x + 1, y + 1, w - 2, h - 2, 0, 255);+ int num = 1;+ float num2 = 0;+ for (int i = 4; i <= h - 4; i += 8) {+ int num3 = num;+ for (int j = 4; j <= w - 4; j += 8) {+ int idx = (int)(fmod1((num2 + num * z->percent * PI_F * 4) / (PI_F / 2)) * z->ninner);+ if (idx >= z->ninner) idx = z->ninner - 1;+ uint16_t t = z->inner[idx];+ int sx = 0, sy = 0, sw = 12, sh = 12;+ float zx = 0, zy = 0;+ if (j <= 4) zx = 2, sx = 2, sw -= 2;+ else if (j >= w - 4) zx = -2, sw -= 2;+ if (i <= 4) zy = 2, sy = 2, sh -= 2;+ else if (i >= h - 4) zy = -2, sh -= 2;+ /* DrawCentered of the sub-rect */+ gfx_tex_part(t, x + j + zx - sw / 2.f, y + i + zy - sh / 2.f, sx, sy, sw, sh, 0, num < 0 ? 0x8410 : 0xFFFF, 255);+ num = -num;+ num2 += PI_F / 3;+ }+ if (num3 == num) num = -num;+ }+ int cw = (int)(w / 8), ch = (int)(h / 8);+ for (int k = 0; k < cw; k++)+ for (int l = 0; l < ch; l++) {+ int a = k == 0 ? 0 : k != cw - 1 ? 1 : 2, b = l == 0 ? 0 : l != ch - 1 ? 1 : 2;+ if (a != 1 || b != 1) gfx_tex_part(z->block, x + k * 8, y + l * 8, a * 8, b * 8, 8, 8, 0, 0xFFFF, 255);+ }+ gfx_tex(z->light_tex[z->light], x + w / 2 - 4, y, 0, 0xFFFF, 255);+}++/* the path between the two places (ZipMoverPathRenderer, depth 5000) */+typedef struct { Ent *zip; } ZipPath;+static void zip_cogs(Zip *z, Ent *zip, V2 off, bool black) {+ V2 from = v2(z->start.x + zip->cw / 2, z->start.y + zip->ch / 2), to = v2(z->target.x + zip->cw / 2, z->target.y + zip->ch / 2);+ V2 d = v2norm(v2sub(to, from)), perp = v2(d.y, -d.x);+ V2 v1 = v2mul(perp, 3), v2_ = v2mul(perp, -4);+ uint16_t rope = black ? 0 : rgb(0x663931), light = black ? 0 : rgb(0x9B6157);+ gfx_line(from.x + v1.x + off.x, from.y + v1.y + off.y, to.x + v1.x + off.x, to.y + v1.y + off.y, rope, 255);+ gfx_line(from.x + v2_.x + off.x, from.y + v2_.y + off.y, to.x + v2_.x + off.x, to.y + v2_.y + off.y, rope, 255);+ float len = v2len(v2sub(to, from));+ for (float n = 4 - fmodf(z->percent * PI_F * 8, 4); n < len; n += 4) {+ V2 a = v2add(v2add(v2add(from, v1), perp), v2mul(d, n));+ V2 b = v2sub(v2add(to, v2_), v2mul(d, n));+ gfx_line(a.x + off.x, a.y + off.y, a.x + d.x * 2 + off.x, a.y + d.y * 2 + off.y, light, 255);+ gfx_line(b.x + off.x, b.y + off.y, b.x - d.x * 2 + off.x, b.y - d.y * 2 + off.y, light, 255);+ }+ float rot = z->percent * PI_F * 2;+ uint8_t f = black ? GF_SILHOUETTE : 0;+ gfx_tex_ex(z->cog, from.x + off.x, from.y + off.y, 6, 6, 1, 1, rot, black ? 0 : 0xFFFF, 255, f);+ gfx_tex_ex(z->cog, to.x + off.x, to.y + off.y, 6, 6, 1, 1, rot, black ? 0 : 0xFFFF, 255, f);+}+static void zippath_render(Ent *e) {+ Ent *zip = ST(e, ZipPath)->zip;+ if (!zip->cls) return;+ Zip *z = ST(zip, Zip);+ zip_cogs(z, zip, v2(0, 1), true);+ zip_cogs(z, zip, v2(0, 0), false);+ gfx_rect(floorf(zip->x + zip->shakex - 1), floorf(zip->y + zip->shakey - 1), zip->cw + 2, zip->ch + 2, 0, 255);+}+static const EntClass ZIPPATH = {.size = sizeof(ZipPath), .name = "zipPath", .render = zippath_render};+static const EntClass ZIP = {.size = sizeof(Zip), .name = "zipMover", .update = zip_update, .render = zip_render, .kind = KIND_SOLID};+static void new_zip(const EData *d) {+ Ent *e = ent_new(&ZIP, d->x, d->y);+ if (!e) return;+ ent_box(e, EA(d, zipMover, width), EA(d, zipMover, height), 0, 0);+ e->depth = -9999;+ Zip *z = ST(e, Zip);+ z->start = v2(d->x, d->y);+ z->target = ed_node(d, 0);+ z->light = 1;+ z->cog = tex_by_name("objects/zipmover/cog");+ z->block = tex_by_name("objects/zipmover/block");+ char p[40];+ for (int i = 0; i < 4; i++) path2(p, "objects/zipmover/light", NULL, i), z->light_tex[i] = tex_by_name(p);+ for (int i = 0; i < 12; i++) path2(p, "objects/zipmover/innercog", NULL, i), z->inner[i] = tex_by_name(p);+ z->ninner = 12;+ Ent *path = ent_new(&ZIPPATH, 0, 0);+ if (path) {+ path->depth = 5000;+ path->collidable = 0;+ ST(path, ZipPath)->zip = e;+ }+}++/* ---------------------------------------------------------------- tile blocks */+/* the tiles of blocks come from a pool, one half per room slot */+#define POOL_TILES 400+static TileQ tile_pool[2][POOL_TILES];+static int tile_pool_n[2];+static TileQ *pool_tiles(int slot, int n) {+ if (tile_pool_n[slot] + n > POOL_TILES) return NULL;+ TileQ *q = tile_pool[slot] + tile_pool_n[slot];+ tile_pool_n[slot] += n;+ return q;+}+typedef struct {+ char type;+ uint8_t w, h, mode;+ uint8_t flags; /* fallingBlock: climbFall; dashBlock: permanent, canDash */+ int step;+ float timer, speed, alpha;+ bool triggered;+ uint32_t hash;+ TileQ *q;+} Block;++static void block_render(Ent *e) {+ Block *b = ST(e, Block);+ if (!b->q) return;+ tiles_draw(b->q, b->w, b->h, e->x + e->shakex, e->y + e->shakey, 0xFFFF, (uint8_t)(b->alpha * 255));+}++/* FallingBlock */+static bool fall_player_check(Ent *e, Block *b) { return (b->flags & 1) ? solid_has_player_rider(e) : solid_has_player_on_top(e); }+static bool fall_wait_check(Ent *e, Block *b) {+ if (b->triggered || fall_player_check(e, b)) return true;+ if (b->flags & 1) {+ Ent *p = level_player_ent();+ return p && (collide_ent_at(e, e->x - 1, e->y, p) || collide_ent_at(e, e->x + 1, e->y, p));+ }+ return false;+}+static void falling_update(Ent *e) {+ Block *b = ST(e, Block);+ plat_update(e);+ switch (b->step) {+ case 0:+ if (b->triggered || fall_player_check(e, b)) b->step = 1;+ break;+ case 1: /* shake 0.2 s */+ plat_start_shaking(e, 0);+ b->timer = 0.2f;+ b->step = 2;+ break;+ case 2:+ if ((b->timer -= DT) > 0) break;+ b->timer = 0.4f;+ b->step = 3;+ /* fall through */+ case 3:+ if (b->timer > 0 && fall_wait_check(e, b)) {+ b->timer -= DT;+ break;+ }+ plat_stop_shaking(e);+ for (int i = 2; i < e->cw; i += 4) particles_emit(PL_MID, &P_FallingBlock_P_FallDustB, 2, v2(e->x + i, e->y), v2(4, 4), PI_F / 2);+ b->speed = 0;+ b->step = 4;+ break;+ case 4: {+ Room *rm = g_level.room;+ b->speed = approach(b->speed, 160, 500 * DT);+ if (plat_move_v_collide_solids(e, b->speed * DT, true)) {+ level_dir_shake(v2(0, 1), 0.3f);+ plat_start_shaking(e, 0);+ b->timer = 0.2f;+ b->step = 5;+ break;+ }+ if (e_top(e) > rm->y + rm->h + 16 || (e_top(e) > rm->y + rm->h - 1 && collide_solid(e, e->x, e->y + 1))) {+ e->collidable = e->visible = 0;+ plat_static_movers_destroy(e);+ ent_remove(e);+ }+ break;+ }+ case 5:+ if ((b->timer -= DT) > 0) break;+ plat_stop_shaking(e);+ if (tiles_solid_rect(e_left(e), e_bottom(e), e_right(e), e_bottom(e) + 1)) {+ b->step = 7;+ e->safe = 1;+ break;+ }+ b->step = 6;+ b->timer = 0;+ /* fall through */+ case 6:+ if ((b->timer -= DT) > 0) break;+ if (collide_solid(e, e->x, e->y + 1) || collide_first_jumpthru_outside(e, e->x, e->y + 1)) {+ b->timer = 0.1f;+ break;+ }+ b->step = 1;+ break;+ default: break;+ }+}+static void falling_trigger(Ent *e, Ent *m) {+ (void)m;+ ST(e, Block)->triggered = true;+}+static void block_shake(Ent *e, V2 a) { plat_static_movers_shake(e, a); }+static const EntClass FALLING = {.size = sizeof(Block), .name = "fallingBlock", .update = falling_update, .render = block_render,+ .on_staticmover_trigger = falling_trigger, .on_shake = block_shake, .kind = KIND_SOLID};++static Ent *new_block(const EntClass *cls, const EData *d, float w, float h, char type) {+ Ent *e = ent_new(cls, d->x, d->y);+ if (!e) return NULL;+ ent_box(e, w, h, 0, 0);+ Block *b = ST(e, Block);+ b->type = type;+ b->w = (uint8_t)(w / 8), b->h = (uint8_t)(h / 8);+ b->alpha = 1;+ b->hash = level_entity_hash(d);+ b->q = pool_tiles(g_level.room_slot, b->w * b->h);+ if (b->q) tiles_box(type, b->w, b->h, b->q);+ return e;+}+static char tile_char(float v, const char *s) {+ if (s && *s) return s[0];+ return (char)('0' + (int)v);+}++/* DashBlock */+static int dash_block_hit(Ent *e, Player *p, V2 dir);+static const EntClass DASHBLOCK = {.size = sizeof(Block), .name = "dashBlock", .update = plat_update, .render = block_render,+ .on_dash_collide = dash_block_hit, .kind = KIND_SOLID};+void level_break_dash_block(Ent *e, V2 dir) {+ (void)dir;+ Block *b = ST(e, Block);+ for (int i = 0; i < b->w; i++)+ for (int j = 0; j < b->h; j++) level_debris(e->x + 4 + i * 8, e->y + 4 + j * 8, b->type, player_center(&g_player));+ e->collidable = 0;+ if (b->flags & 1) level_set_do_not_load(b->hash);+ ent_remove(e);+}+static int dash_block_hit(Ent *e, Player *p, V2 dir) {+ Block *b = ST(e, Block);+ if (!(b->flags & 2) && p->state != ST_REDDASH && p->state != ST_SUMMITLAUNCH) return DASH_NORMAL;+ level_break_dash_block(e, dir);+ return DASH_REBOUND;+}++/* FakeWall, CoverupWall, ExitBlock: tiles that fade */+static void fakewall_update(Ent *e) {+ Block *b = ST(e, Block);+ Ent *p = level_player_ent();+ if (b->mode == 1) { /* fading */+ b->alpha = approach(b->alpha, 0, 2 * DT);+ if (b->alpha <= 0) ent_remove(e);+ return;+ }+ if (p && collide_ent_at(e, e->x, e->y, p) && g_player.state != ST_DREAMDASH) {+ level_set_do_not_load(b->hash);+ b->mode = 1;+ }+}+static const EntClass FAKEWALL = {.size = sizeof(Block), .name = "fakeWall", .update = fakewall_update, .render = block_render};+static void coverup_update(Ent *e) {+ Block *b = ST(e, Block);+ Ent *p = level_player_ent();+ bool in = p && collide_ent_at(e, e->x, e->y, p);+ b->alpha = approach(b->alpha, in ? 0 : 1, 4 * DT);+}+static const EntClass COVERUP = {.size = sizeof(Block), .name = "coverupWall", .update = coverup_update, .render = block_render};+static void exit_update(Ent *e) {+ Block *b = ST(e, Block);+ Ent *p = level_player_ent();+ if (!e->collidable) {+ e->collidable = 1;+ bool in = p && collide_ent_at(e, e->x, e->y, p);+ e->collidable = !in;+ if (!in) b->mode = 1;+ }+ if (b->mode == 1) b->alpha = approach(b->alpha, 1, 2 * DT);+ plat_update(e);+}+static const EntClass EXITBLOCK = {.size = sizeof(Block), .name = "exitBlock", .update = exit_update, .render = block_render, .kind = KIND_SOLID};++/* Debris: bits of broken blocks */+typedef struct { uint16_t tex; V2 speed; float life, rot, spin; } Debris;+static void debris_update(Ent *e) {+ Debris *d = ST(e, Debris);+ d->speed.y = approach(d->speed.y, 200, 600 * DT);+ d->speed.x = approach(d->speed.x, 0, 200 * DT);+ e->x += d->speed.x * DT, e->y += d->speed.y * DT;+ d->rot += d->spin * DT;+ if ((d->life -= DT) <= 0) ent_remove(e);+}+static void debris_render(Ent *e) {+ Debris *d = ST(e, Debris);+ gfx_tex_ex(d->tex, e->x, e->y, 4, 4, 1, 1, d->rot, 0xFFFF, (uint8_t)(255 * fminf(1, d->life * 2)), 0);+}+static const EntClass DEBRIS = {.size = sizeof(Debris), .name = "debris", .update = debris_update, .render = debris_render};+void level_debris(float x, float y, char type, V2 from) {+ Ent *e = ent_new(&DEBRIS, x, y);+ if (!e) return;+ e->collidable = 0;+ e->depth = -9000;+ Debris *d = ST(e, Debris);+ char p[16], t[2] = {type, 0};+ path2(p, "debris/", t, -1);+ d->tex = tex_by_name(p);+ if (d->tex == 0xFFFF) d->tex = tex_by_name("debris/1");+ V2 dir = v2norm(v2sub(v2(x, y), from));+ float sp = rnd_rangef(60, 120);+ d->speed = v2add(v2mul(dir, sp), v2(0, -60));+ d->life = rnd_rangef(1, 1.5f);+ d->spin = rnd_rangef(-6, 6);+}++/* ---------------------------------------------------------------- simple scenery */+typedef struct { Sprite spr; float t; uint16_t tex; uint8_t flag; } Simple;+static void simple_update(Ent *e) {+ Simple *s = ST(e, Simple);+ s->t += DT;+ spr_update(&s->spr);+}+static void simple_render(Ent *e) { spr_draw(&ST(e, Simple)->spr, e->x, e->y); }+static const EntClass SIMPLE_SPRITE = {.size = sizeof(Simple), .name = "sprite", .update = simple_update, .render = simple_render};+static Ent *new_sprite_ent(const EData *d, int bank, int anim, int depth) {+ Ent *e = ent_new(&SIMPLE_SPRITE, d->x, d->y);+ if (!e) return NULL;+ e->collidable = 0;+ e->depth = (int16_t)depth;+ spr_init(&ST(e, Simple)->spr, bank);+ if (anim >= 0) spr_play(&ST(e, Simple)->spr, anim, true);+ return e;+}++/* Checkpoint's background picture */+static void checkpoint_render(Ent *e) { gfx_tex_ex(ST(e, Simple)->tex, e->x, e->y, 12, 24, 1, 1, 0, 0xFFFF, 255, 0); }+static const EntClass CHECKPOINT = {.size = sizeof(Simple), .name = "checkpoint", .render = checkpoint_render};++/* LightBeam */+typedef struct { float w, h, rot, alpha, t; } Beam;+static void beam_update(Ent *e) {+ Beam *b = ST(e, Beam);+ b->t += DT;+ Ent *p = level_player_ent();+ float target = 1;+ if (p) {+ float d = fabsf(p->x - e->x);+ target = clampf((d - 8) / 32, 0, 1) * 0 + 1;+ }+ b->alpha = approach(b->alpha, target, DT);+}+static void beam_render(Ent *e) {+ Beam *b = ST(e, Beam);+ float a = b->alpha * 0.5f;+ /* stripes of util/lightbeam stretched along the beam */+ for (float x = 0; x < b->w; x += 4) {+ float k = sinf(b->t * 2 + x * 0.2f) * 0.25f + 0.75f;+ float px = e->x + cosf(b->rot + PI_F / 2) * 0 + cosf(b->rot) * (x - b->w / 2);+ float py = e->y + sinf(b->rot) * (x - b->w / 2);+ gfx_tex_ex(T_util_lightbeam, px, py, 0, 0.5f, b->h / 80.f, 4, b->rot + PI_F / 2, 0xFFF7, (uint8_t)(a * k * 120), GF_ADD);+ }+}+static const EntClass BEAM = {.size = sizeof(Beam), .name = "lightbeam", .update = beam_update, .render = beam_render};++/* ---------------------------------------------------------------- triggers */+typedef struct { V2 a; float b; int mode; bool xonly, yonly; char kind; } Trig;+static void camoff_enter(Ent *e, Player *p) {+ (void)p;+ Trig *t = ST(e, Trig);+ g_level.cam_offset = v2(t->a.x * 48, t->a.y * 32);+}+static float pos_lerp(Ent *e, Player *p, int mode) {+ float px = e_cxm(p->ent), py = e_cym(p->ent);+ float l = e_left(e), r = e_right(e), t = e_top(e), b = e_bottom(e), cx = e_cxm(e), cy = e_cym(e);+#define CMAP(v, a, bb) clampf(((v) - (a)) / ((bb) - (a)), 0, 1)+ switch (mode) {+ case 1: return CMAP(px, l, r);+ case 2: return CMAP(px, r, l);+ case 3: return CMAP(py, t, b);+ case 4: return CMAP(py, b, t);+ case 5: return fminf(CMAP(px, l, cx), CMAP(px, r, cx));+ case 6: return fminf(CMAP(py, t, cy), CMAP(py, b, cy));+ default: return 1;+ }+#undef CMAP+}+static void camtarget_stay(Ent *e, Player *p) {+ Trig *t = ST(e, Trig);+ p->cam_anchor = v2sub(t->a, v2(160, 90));+ float l = clampf(t->b * pos_lerp(e, p, t->mode), 0, 1);+ p->cam_anchor_lerp = v2(l, l);+ p->cam_anchor_ignore_x = t->yonly;+ p->cam_anchor_ignore_y = t->xonly;+}+static void camtarget_leave(Ent *e, Player *p) {+ (void)e;+ bool other = false;+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o != e && o->cls && o->cls->on_stay == camtarget_stay && o->triggered) other = true;+ }+ if (!other) {+ p->cam_anchor_lerp = v2(0, 0);+ }+}+static void respawn_enter(Ent *e, Player *p) {+ (void)p;+ Trig *t = ST(e, Trig);+ if (!point_solid(t->a.x, t->a.y - 4)) {+ g_session.rx = (int16_t)t->a.x, g_session.ry = (int16_t)t->a.y;+ }+}+static const EntClass CAMOFF = {.size = sizeof(Trig), .name = "cameraOffsetTrigger", .on_enter = camoff_enter, .kind = KIND_TRIGGER};+static const EntClass CAMTARGET = {.size = sizeof(Trig), .name = "cameraTargetTrigger", .on_stay = camtarget_stay, .on_leave = camtarget_leave, .kind = KIND_TRIGGER};+static const EntClass RESPAWN = {.size = sizeof(Trig), .name = "changeRespawnTrigger", .on_enter = respawn_enter, .kind = KIND_TRIGGER};+static const EntClass KILLBOX = {.size = sizeof(int), .name = "killbox", .kind = KIND_KILLBOX};++/* HeartGem.removeCameraTriggers: every CameraOffsetTrigger goes */+void level_remove_camera_offset_triggers(void) {+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &CAMOFF && g_ents[i].dead != 1) ent_remove(&g_ents[i]);+}++static Ent *new_trigger(const EntClass *cls, const EData *d, float w, float h) {+ Ent *e = ent_new(cls, d->x, d->y);+ if (!e) return NULL;+ ent_box(e, w, h, 0, 0);+ e->visible = 0;+ return e;+}++bool trig_create(const EData *d) {+ Ent *e;+ if (berry_trigger(d)) return true;+ if (trigs_ch1(d) || trigs_ch2(d) || trigs_ch3(d) || trigs_ch4(d) || trigs_ch5(d) || trigs_ch6(d) || trigs_ch7(d) ||+ trigs_ch8(d) || trigs_ch9(d))+ return true;+ switch (d->type) {+ case TT_cameraOffsetTrigger:+ e = new_trigger(&CAMOFF, d, EA(d, cameraOffsetTrigger, width), EA(d, cameraOffsetTrigger, height));+ if (e) ST(e, Trig)->a = v2(EA(d, cameraOffsetTrigger, cameraX), EA(d, cameraOffsetTrigger, cameraY));+ return true;+ case TT_cameraTargetTrigger: {+ e = new_trigger(&CAMTARGET, d, EA(d, cameraTargetTrigger, width), EA(d, cameraTargetTrigger, height));+ if (!e) return true;+ Trig *t = ST(e, Trig);+ t->a = ed_node(d, 0);+ t->b = EA(d, cameraTargetTrigger, lerpStrength);+ const char *m = EAS(d, cameraTargetTrigger, positionMode);+ static const char *modes[] = {"NoEffect", "LeftToRight", "RightToLeft", "TopToBottom", "BottomToTop", "HorizontalCenter", "VerticalCenter"};+ t->mode = 0;+ for (int i = 0; i < 7; i++)+ if (!strcmp(m, modes[i])) t->mode = i;+ t->xonly = EAB(d, cameraTargetTrigger, xOnly);+ t->yonly = EAB(d, cameraTargetTrigger, yOnly);+ return true;+ }+ case TT_changeRespawnTrigger: {+ e = new_trigger(&RESPAWN, d, EA(d, changeRespawnTrigger, width), EA(d, changeRespawnTrigger, height));+ if (!e) return true;+ V2 target = d->nnodes ? ed_node(d, 0) : e_center(e);+ ST(e, Trig)->a = level_closest_spawn(target);+ if (d->nnodes) ST(e, Trig)->a = target;+ return true;+ }+ }+ return false;+}++/* ---------------------------------------------------------------- the factory */+static uint16_t tex_by_name(const char *path) { return res_tex_by_name(path); }++/* each chapter's own entities (src/chN.c); absent files: none */+WEAK bool ents_ch0(const EData *d) { (void)d; return false; }+WEAK bool ents_ch1(const EData *d) { (void)d; return false; }+WEAK bool ents_ch8(const EData *d) { (void)d; return false; }+WEAK bool trigs_ch1(const EData *d) { (void)d; return false; }+WEAK bool trigs_ch8(const EData *d) { (void)d; return false; }+WEAK bool ents_ch2(const EData *d) { (void)d; return false; }+WEAK bool ents_ch3(const EData *d) { (void)d; return false; }+WEAK bool ents_ch4(const EData *d) { (void)d; return false; }+WEAK bool ents_ch5(const EData *d) { (void)d; return false; }+WEAK bool ents_ch6(const EData *d) { (void)d; return false; }+WEAK bool ents_ch7(const EData *d) { (void)d; return false; }+WEAK bool ents_ch9(const EData *d) { (void)d; return false; }+WEAK bool trigs_ch2(const EData *d) { (void)d; return false; }+WEAK bool trigs_ch3(const EData *d) { (void)d; return false; }+WEAK bool trigs_ch4(const EData *d) { (void)d; return false; }+WEAK bool trigs_ch5(const EData *d) { (void)d; return false; }+WEAK bool trigs_ch6(const EData *d) { (void)d; return false; }+WEAK bool trigs_ch7(const EData *d) { (void)d; return false; }+WEAK bool trigs_ch9(const EData *d) { (void)d; return false; }++bool ent_create(const EData *d) {+ if (berry_create(d) || props_create(d) || heart_create(d) || cassette_create(d) || dust_create(d)) return true;+ if (ents_ch0(d) || ents_ch1(d) || ents_ch2(d) || ents_ch3(d) || ents_ch4(d) || ents_ch5(d) || ents_ch6(d) ||+ ents_ch7(d) || ents_ch8(d) || ents_ch9(d))+ return true;+ int slot = g_level.room_slot;+ switch (d->type) {+ case ET_player:+ if (nspawns[slot] < MAX_SPAWNS) spawns[slot][nspawns[slot]++] = v2(d->x, d->y);+ return true;+ case ET_jumpThru: new_jumpthru(d); return true;+ case ET_spikesUp: new_spikes(d, DIR_UP); return true;+ case ET_spikesDown: new_spikes(d, DIR_DOWN); return true;+ case ET_spikesLeft: new_spikes(d, DIR_LEFT); return true;+ case ET_spikesRight: new_spikes(d, DIR_RIGHT); return true;+ case ET_spring: new_spring(d, SPRING_FLOOR, EAB(d, spring, playerCanUse)); return true;+ case ET_wallSpringLeft: new_spring(d, SPRING_WALLLEFT, EAB(d, wallSpringLeft, playerCanUse)); return true;+ case ET_wallSpringRight: new_spring(d, SPRING_WALLRIGHT, EAB(d, wallSpringRight, playerCanUse)); return true;+ case ET_refill: new_refill(d); return true;+ case ET_crumbleBlock: new_crumble(d); return true;+ case ET_zipMover: new_zip(d); return true;+ case ET_fallingBlock: {+ Ent *e = new_block(&FALLING, d, EA(d, fallingBlock, width), EA(d, fallingBlock, height),+ tile_char(EA(d, fallingBlock, tiletype), NULL));+ if (!e) return true;+ if (EAB(d, fallingBlock, behind)) e->depth = 5000;+ ST(e, Block)->flags = EAB(d, fallingBlock, climbFall) ? 1 : 0;+ return true;+ }+ case ET_dashBlock: {+ uint32_t h = level_entity_hash(d);+ if (level_do_not_load(h)) return true;+ char t = tile_char(EA(d, dashBlock, tiletype), NULL);+ Ent *e = new_block(&DASHBLOCK, d, EA(d, dashBlock, width), EA(d, dashBlock, height), t);+ if (!e) return true;+ e->depth = -12999;+ e->safe = 1;+ Block *b = ST(e, Block);+ b->flags = (EAB(d, dashBlock, permanent) ? 1 : 0) | (EAB(d, dashBlock, canDash) ? 2 : 0);+ if (EAB(d, dashBlock, blendin)) {+ e->depth = -10501;+ if (b->q) tiles_overlay(t, (int)(d->x / 8), (int)(d->y / 8), b->w, b->h, b->q);+ }+ return true;+ }+ case ET_fakeWall: {+ uint32_t h = level_entity_hash(d);+ if (level_do_not_load(h)) return true;+ char t = tile_char(EA(d, fakeWall, tiletype), NULL);+ Ent *e = new_block(&FAKEWALL, d, EA(d, fakeWall, width), EA(d, fakeWall, height), t);+ if (!e) return true;+ e->depth = -13000;+ Block *b = ST(e, Block);+ if (b->q) tiles_overlay(t, (int)(d->x / 8), (int)(d->y / 8), b->w, b->h, b->q);+ return true;+ }+ case ET_coverupWall: {+ char t = tile_char(EA(d, coverupWall, tiletype), NULL);+ Ent *e = new_block(&COVERUP, d, EA(d, coverupWall, width), EA(d, coverupWall, height), t);+ if (!e) return true;+ e->depth = -13000;+ Block *b = ST(e, Block);+ if (b->q) tiles_overlay(t, (int)(d->x / 8), (int)(d->y / 8), b->w, b->h, b->q);+ return true;+ }+ case ET_exitBlock: {+ char t = tile_char(EA(d, exitBlock, tileType), NULL);+ Ent *e = new_block(&EXITBLOCK, d, EA(d, exitBlock, width), EA(d, exitBlock, height), t);+ if (!e) return true;+ e->depth = -13000;+ e->collidable = 0;+ Block *b = ST(e, Block);+ b->alpha = 0;+ if (b->q) tiles_overlay(t, (int)(d->x / 8), (int)(d->y / 8), b->w, b->h, b->q);+ return true;+ }+ case ET_killbox: {+ Ent *e = ent_new(&KILLBOX, d->x, d->y);+ if (e) ent_box(e, EA(d, killbox, width), 32, 0, 0), e->visible = 0;+ return true;+ }+ case ET_checkpoint: {+ Ent *e = ent_new(&CHECKPOINT, d->x, d->y);+ if (!e) return true;+ e->depth = 9990;+ e->collidable = 0;+ const char *bg = EAS(d, checkpoint, bg);+ char p[48];+ char num[4] = {(char)('0' + g_session.area), 0};+ path2(p, "objects/checkpoint/bg/", *bg ? bg : num, -1);+ ST(e, Simple)->tex = tex_by_name(p);+ return true;+ }+ case ET_bonfire: {+ const char *mode = EAS(d, bonfire, mode);+ Ent *e = new_sprite_ent(d, SB_campfire, !strcmp(mode, "lit") ? A_campfire_burn : !strcmp(mode, "smoking") ? A_campfire_smoking : A_campfire_idle, -5);+ (void)e;+ return true;+ }+ case ET_lightbeam: {+ Ent *e = ent_new(&BEAM, d->x, d->y);+ if (!e) return true;+ e->collidable = 0;+ e->depth = -9998;+ Beam *b = ST(e, Beam);+ b->w = EA(d, lightbeam, width), b->h = EA(d, lightbeam, height);+ b->rot = EA(d, lightbeam, rotation) * PI_F / 180;+ b->alpha = 1;+ return true;+ }+ }+ return false;+}++void entities_load(Room *rm, const uint8_t *blob, int slot) {+ nspawns[slot] = 0;+ tile_pool_n[slot] = 0;+ EData d;+ d.room = rm->index;+ d.rx = (float)rm->x, d.ry = (float)rm->y;+ for (int pass = 0; pass < 2; pass++) {+ const uint8_t *p = blob + rd16(blob + 2 * (pass ? RB_TRIGS : RB_ENTS));+ int n = rd16(p);+ p += 2;+ for (int i = 0; i < n; i++) {+ d.type = p[0];+ d.nnodes = p[1];+ d.id = rd16(p + 2);+ d.x = rm->x + (float)rds16(p + 4);+ d.y = rm->y + (float)rds16(p + 6);+ d.attrs = p + 8;+ int size = pass ? trig_attr_size(d.type) : ent_attr_size(d.type);+ d.nodes = d.attrs + size;+ g_new_eid = (uint16_t)d.id;+ if (pass) trig_create(&d);+ else if (!leader_has_id(level_entity_id(rm->index, d.id))) /* what follows the player is there already */+ ent_create(&d);+ g_new_eid = 0xFFFF;+ p = d.nodes + 4 * d.nnodes;+ if ((uintptr_t)(p - blob) & 1) p++;+ }+ }+ /* what lives as long as the level */+ bool have = false;+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &FX) have = true;+ if (!have) {+ Ent *e = ent_new(&FX, 0, 0);+ if (e) e->tags = TAG_GLOBAL | TAG_TRANSITION_UPDATE, e->collidable = 0, e->visible = 0, e->dead = 0;+ e = ent_new(&FORMATION, 0, 0);+ if (e) e->tags = TAG_GLOBAL | TAG_FROZEN_UPDATE, e->depth = -1999900, e->collidable = 0, e->dead = 0;+ }+}++int ent_attr_size(int type) { return type < (int)sizeof ENT_ATTR_SIZE ? ENT_ATTR_SIZE[type] : 0; }+int trig_attr_size(int type) { return type < (int)sizeof TRIG_ATTR_SIZE ? TRIG_ATTR_SIZE[type] : 0; }diff --git a/games/celeste/src/entities.h b/games/celeste/src/entities.hnew file mode 100644index 00000000..128bfacf--- /dev/null+++ b/games/celeste/src/entities.h@@ -0,0 +1,119 @@+/* Building entities from a room's records (tools/pack.py write_entity). */+#ifndef ENTITIES_H+#define ENTITIES_H+#include "level.h"+#include "player.h"+#include "fx.h"++typedef struct {+ int type, nnodes, id;+ float x, y; /* world position (room offset added) */+ const uint8_t *attrs, *nodes;+ int room; /* the room's index in the chapter */+ float rx, ry; /* the room's offset */+} EData;++float ea_num(const EData *d, int off, char kind);+static inline bool ea_bool(const EData *d, int off, char kind) { return ea_num(d, off, kind) != 0; }+const char *ea_str(const EData *d, int off);+V2 ed_node(const EData *d, int i);+#define EA(d, ent, attr) ea_num(d, EA_##ent##_##attr, EK_##ent##_##attr)+#define EAB(d, ent, attr) (EA(d, ent, attr) != 0)+#define EAS(d, ent, attr) ea_str(d, EA_##ent##_##attr)++/* per-type state: ST(e, T) (ent.h); the class's .size must be sizeof(T) */++/* the area's look (AreaData): jumpthru, spikes, crumble blocks */+const char *area_jumpthru(void);+const char *area_crumble(void);+uint32_t level_entity_hash(const EData *d);++/* factories: entities.c and the per-chapter files */+bool ent_create(const EData *d);+/* each chapter's own entities and triggers (src/chN.c): true if it made it */+bool ents_ch0(const EData *d);+bool ents_ch1(const EData *d);+bool ents_ch8(const EData *d);+bool trigs_ch1(const EData *d);+bool trigs_ch8(const EData *d);+bool ents_ch2(const EData *d);+bool ents_ch3(const EData *d);+bool ents_ch4(const EData *d);+bool ents_ch5(const EData *d);+bool ents_ch6(const EData *d);+bool ents_ch7(const EData *d);+bool ents_ch9(const EData *d);+bool trigs_ch2(const EData *d);+bool trigs_ch3(const EData *d);+bool trigs_ch4(const EData *d);+bool trigs_ch5(const EData *d);+bool trigs_ch6(const EData *d);+bool trigs_ch7(const EData *d);+bool trigs_ch9(const EData *d);+bool trig_create(const EData *d);+Ent *level_holdable_check(void); /* a holdable the player can grab now, picked up (Holdable.Pickup) */+void holdable_carry(Ent *h, V2 at); /* Holdable.Carry */+void holdable_release(Ent *h, V2 force); /* Holdable.Release */+V2 level_closest_spawn(V2 at);+void level_dash_listeners(V2 dir);+void level_booster_boosted(Ent *booster, V2 dir);++void level_debris(float x, float y, char type, V2 from);+void level_break_dash_block(Ent *e, V2 dir);+/* the player's followers (Leader, Follower: berry.c): strawberries, keys, seeds trail behind it.+ * A follower calls leader_tick(e) where its components update (Follower.Update); the class's+ * on_gain_leader / on_lose_leader are Follower.OnGainLeader / OnLoseLeader */+bool leader_gain(Ent *f, float follow_delay, bool persistent); /* GainFollower (FollowDelay, PersistentFollow) */+void leader_lose(Ent *f); /* LoseFollower */+void leader_transfer(void); /* TransferFollowers */+int leader_count(void);+Ent *leader_follower(int i);+int leader_index(const Ent *f); /* FollowIndex: -1 without a leader */+bool leader_has(const Ent *f);+bool leader_has_id(uint32_t id);+float leader_delay(const Ent *f); /* DelayTimer */+void leader_tick(const Ent *f);+void leader_set_move(const Ent *f, bool move); /* MoveTowardsLeader */+void leader_update(V2 at);+void leader_reset(void);+bool berry_create(const EData *d);+bool heart_create(const EData *d); /* heart.c: HeartGem */+bool cassette_create(const EData *d); /* cassette.c: Cassette, CassetteBlock */+bool dust_create(const EData *d); /* dust.c: Rotate/TrackSpinner */+void dust_entities(void); /* the dust layer (DustEdges) */+void dust_hit(float x, float y); /* the dust bunny there killed Madeline */+void spinners_each(const Room *rm, float x0, float y0, float x1, float y1,+ void (*fn)(float x, float y, uint16_t nodes, void *ctx), void *ctx);+void cassette_level_start(bool transition); /* the end of LoadLevel; OnOutBegin */+bool cassette_block_scale(const Ent *block, V2 *origin, V2 *scale);+void cassette_blocks_finish(void);+void spikes_set_cassette(Ent *spikes, uint16_t on, uint16_t off, V2 origin);+typedef struct { V2 a, b, c; float lerp; } CassetteFly; /* Player.cassetteFlyCurve, cassetteFlyLerp */+CassetteFly *cassette_fly(void);+Ent *absorb_orb_new(V2 at, Ent *into); /* AbsorbOrb: into the player when NULL */+void absorb_orbs_remove(void);+void level_remove_camera_offset_triggers(void);+bool berry_trigger(const EData *d);+void berries_collect_all(void);+bool level_gold_collect_check(const Ent *player);+int ent_attr_size(int type);+int trig_attr_size(int type);++/* Monocle's Wiggler and SineWave components */+typedef struct {+ float counter, sine_counter, increment, sine_add, value;+ bool active, start_zero;+} Wiggler;+void wiggler_init(Wiggler *w, float duration, float freq); /* Wiggler.Create */+void wiggler_restart(Wiggler *w); /* Start() */+void wiggler_start(Wiggler *w, float duration, float freq); /* Start(duration, frequency) */+void wiggler_update(Wiggler *w);+typedef struct { float counter, freq, value, value_over_two, two_value; } SineWave;+void sine_set(SineWave *s, float counter); /* the Counter setter */+void sine_randomize(SineWave *s);+void sine_update(SineWave *s);+/* Monocle's Tween: percent goes 0 to 1 over the duration */+typedef struct { float time_left, duration, percent; bool active; } Tween;+void tween_start(Tween *t, float duration);+bool tween_update(Tween *t); /* true on the frame it ends */+#endifdiff --git a/games/celeste/src/font.c b/games/celeste/src/font.cnew file mode 100644index 00000000..68b286cd--- /dev/null+++ b/games/celeste/src/font.c@@ -0,0 +1,103 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* Renogare, the game's font, from data.bin's FONTS (tools/textdata.py): 4-bit+ * glyphs at the sizes the 1920x1080 interface has on this screen (1/6). */+#include "celeste.h"++/* per size: u16 nglyphs, u16 line height x16, u16 base x16, u16 nkern,+ * glyphs (u16 code, s16 xo x16, s16 yo, u8 w, u8 h, u16 advance x16, u32 bitmap), kerning (u16 a, u16 b, s16 x16) */+static const uint8_t *face(int size) {+ const uint8_t *s = section(SEC_FONTS);+ return s + rd32(s + 4 + 4 * size);+}+static const uint8_t *glyph(const uint8_t *f, uint32_t code) {+ int n = rd16(f), lo = 0, hi = n - 1;+ while (lo <= hi) {+ int m = (lo + hi) / 2;+ const uint8_t *g = f + 8 + 14 * m;+ uint32_t c = rd16(g);+ if (c == code) return g;+ if (c < code) lo = m + 1;+ else hi = m - 1;+ }+ return NULL;+}+static int kerning(const uint8_t *f, uint32_t a, uint32_t b) {+ int n = rd16(f), nk = rd16(f + 6);+ const uint8_t *k = f + 8 + 14 * n;+ for (int i = 0; i < nk; i++, k += 6)+ if (rd16(k) == a && rd16(k + 2) == b) return rds16(k + 4);+ return 0;+}++uint32_t utf8_next(const char **sp, const char *end) {+ const uint8_t *s = (const uint8_t *)*sp;+ uint32_t c = *s++;+ if (c >= 0xC0 && (const char *)s < end) {+ int extra = c >= 0xF0 ? 3 : c >= 0xE0 ? 2 : 1;+ c &= 0x3F >> extra;+ while (extra-- && (const char *)s < end) c = c << 6 | (*s++ & 0x3F);+ }+ *sp = (const char *)s;+ return c;+}++float font_line_height(int size) { return rd16(face(size) + 2) / 16.f; }++/* raw access for FancyText: the glyph record, its kerning with b (both x16 screen pixels), its bitmap */+const uint8_t *font_glyph_rec(int size, uint32_t code) { return glyph(face(size), code); }+int font_kerning_x16(int size, uint32_t a, uint32_t b) { return kerning(face(size), a, b); }+const uint8_t *font_glyph_bits(int size, const uint8_t *g) { return face(size) + rd32(g + 10); }++float font_glyph_advance(int size, uint32_t code, uint32_t next) {+ const uint8_t *f = face(size), *g = glyph(f, code);+ if (!g) return 0;+ return (rd16(g + 8) + (next ? kerning(f, code, next) : 0)) / 16.f;+}++float font_measure(const char *s, int n, int size) {+ const char *end = s + n;+ float w = 0;+ while (s < end) {+ uint32_t c = utf8_next(&s, end);+ const char *t = s;+ uint32_t next = s < end ? utf8_next(&t, end) : 0;+ w += font_glyph_advance(size, c, next);+ }+ return w;+}++void font_draw_glyph(int size, uint32_t code, float x, float y, uint16_t col, uint8_t alpha) {+ const uint8_t *f = face(size), *g = glyph(f, code);+ if (!g || !g[6]) return;+ gfx_mask4(f + rd32(g + 10), g[6], g[7], floorf(x + rds16(g + 2) / 16.f + 0.5f), y + rds16(g + 4), col, alpha);+}++float font_draw(const char *s, int n, float x, float y, int size, uint16_t col, uint8_t alpha) {+ const char *end = s + n;+ float x0 = x;+ y = floorf(y + 0.5f);+ while (s < end) {+ uint32_t c = utf8_next(&s, end);+ const char *t = s;+ uint32_t next = s < end ? utf8_next(&t, end) : 0;+ font_draw_glyph(size, c, x, y, col, alpha);+ x += font_glyph_advance(size, c, next);+ }+ return x - x0;+}++void font_draw_outline(const char *s, int n, float x, float y, int size, uint16_t col, uint16_t outline, uint8_t alpha) {+ font_draw(s, n, x - 1, y, size, outline, alpha);+ font_draw(s, n, x + 1, y, size, outline, alpha);+ font_draw(s, n, x, y - 1, size, outline, alpha);+ font_draw(s, n, x, y + 1, size, outline, alpha);+ font_draw(s, n, x, y, size, col, alpha);+}++void font_draw_justified(const char *s, float x, float y, float jx, float jy, int size, uint16_t col, uint8_t alpha) {+ int n = (int)strlen(s);+ float w = font_measure(s, n, size), h = font_line_height(size);+ font_draw(s, n, x - w * jx, y - h * jy, size, col, alpha);+}diff --git a/games/celeste/src/fx.c b/games/celeste/src/fx.cnew file mode 100644index 00000000..2fa36e7d--- /dev/null+++ b/games/celeste/src/fx.c@@ -0,0 +1,150 @@+/* Particles (Monocle.ParticleSystem), afterimages (TrailManager), Dust. */+#include "fx.h"+#include "level.h"++typedef struct {+ const PType *type;+ uint8_t active, layer;+ uint16_t src;+ V2 pos, speed;+ float life, start_life, size, rot, spin;+ uint32_t color, start_color;+} Particle;++#define MAX_PARTICLES 128+static Particle parts[MAX_PARTICLES];+static int next_part;++void particles_clear(void) { memset(parts, 0, sizeof parts); }++static uint32_t lerp_rgb(uint32_t a, uint32_t b, float t) {+ int r = (int)(((a >> 16) & 255) + (((int)((b >> 16) & 255) - (int)((a >> 16) & 255)) * t));+ int g = (int)(((a >> 8) & 255) + (((int)((b >> 8) & 255) - (int)((a >> 8) & 255)) * t));+ int bl = (int)((a & 255) + (((int)(b & 255) - (int)(a & 255)) * t));+ return (uint32_t)(r << 16 | g << 8 | bl);+}++static void create(int layer, const PType *t, V2 pos, uint32_t color, float dir) {+ Particle *p = &parts[next_part];+ next_part = (next_part + 1) % MAX_PARTICLES;+ p->type = t;+ p->active = 1;+ p->layer = (uint8_t)layer;+ p->pos = pos;+ p->src = t->nsrc ? t->src[t->nsrc > 1 ? rndi(t->nsrc) : 0] : 0xFFFF;+ p->size = t->size_range != 0 ? t->size - t->size_range * .5f + rndf() * t->size_range : t->size;+ p->start_color = t->color_mode == PC_CHOOSE ? (rndi(2) ? t->color2 : color) : color;+ p->color = p->start_color;+ float a = dir - t->dir_range / 2 + rndf() * t->dir_range;+ float sp = rnd_rangef(t->speed_min, t->speed_max);+ p->speed = v2(cosf(a) * sp, sinf(a) * sp);+ p->start_life = p->life = rnd_rangef(t->life_min, t->life_max);+ p->rot = t->rot_mode == PR_RANDOM ? rndf() * 2 * PI_F : t->rot_mode == PR_SAMEASDIR ? a : 0;+ p->spin = rnd_rangef(t->spin_min, t->spin_max);+ if (t->spin_flip && rndi(2)) p->spin = -p->spin;+}++void particles_emit_c(int layer, const PType *t, int n, V2 pos, V2 range, uint32_t color, float dir) {+ for (int i = 0; i < n; i++)+ create(layer, t, v2(pos.x + rnd_rangef(-range.x, range.x), pos.y + rnd_rangef(-range.y, range.y)), color, dir);+}+void particles_emit(int layer, const PType *t, int n, V2 pos, V2 range, float dir) {+ particles_emit_c(layer, t, n, pos, range, t->color, dir);+}+void particles_emit1(int layer, const PType *t, V2 pos, float dir) { create(layer, t, pos, t->color, dir); }++/* Monocle's Particle.Update; the color keeps its alpha in the top byte, times the fade */+void particles_update(void) {+ for (int i = 0; i < MAX_PARTICLES; i++) {+ Particle *p = &parts[i];+ if (!p->active) continue;+ const PType *t = p->type;+ float dt = DT;+ float k = p->life / p->start_life;+ p->life -= dt;+ if (p->life <= 0) {+ p->active = 0;+ continue;+ }+ if (t->rot_mode == PR_SAMEASDIR) {+ if (p->speed.x || p->speed.y) p->rot = atan2f(p->speed.y, p->speed.x);+ } else+ p->rot += p->spin * dt;+ float fade = t->fade_mode == PF_LINEAR ? k : t->fade_mode == PF_LATE ? fminf(1, k / .25f)+ : t->fade_mode == PF_INOUT ? (k > .75f ? 1 - (k - .75f) / .25f : k < .25f ? k / .25f : 1) : 1;+ uint32_t c;+ if (t->color_mode == PC_FADE) c = lerp_rgb(t->color2, p->start_color, k) | (p->start_color & 0xFF000000u);+ else if (t->color_mode == PC_BLINK) c = fmodf(p->life, .2f) < .1f ? p->start_color : t->color2; /* Calc.BetweenInterval(Life, 0.1) */+ else c = p->start_color;+ uint32_t a = (uint32_t)((c >> 24) * fade);+ p->color = (c & 0xFFFFFF) | a << 24;+ p->pos = v2add(p->pos, v2mul(p->speed, dt));+ p->speed = v2add(p->speed, v2mul(t->accel, dt));+ p->speed.x = approach(p->speed.x, 0, t->friction * dt); /* Calc.Approach(Vector2) */+ p->speed.y = approach(p->speed.y, 0, t->friction * dt);+ if (t->speed_mult != 1) p->speed = v2mul(p->speed, powf(t->speed_mult, dt));+ if (t->scale_out) p->size = t->size * ease_cube_out(k);+ }+}++void particles_render(int layer) {+ for (int i = 0; i < MAX_PARTICLES; i++) {+ Particle *p = &parts[i];+ uint8_t a = (uint8_t)(p->color >> 24);+ if (!p->active || p->layer != layer || !a) continue;+ float x = (float)(int)p->pos.x, y = (float)(int)p->pos.y;+ if (p->src == 0xFFFF) {+ int s = (int)(p->size + 0.5f);+ if (s < 1) continue;+ gfx_rect(x - s / 2, y - s / 2, (float)s, (float)s, rgb(p->color & 0xFFFFFF), a);+ } else {+ Tex t;+ if (!tex_get(p->src, &t)) continue;+ gfx_tex_ex(p->src, x, y, t.fw / 2.f, t.fh / 2.f, p->size, p->size, p->rot, rgb(p->color & 0xFFFFFF), a, 0);+ }+ }+}++/* Celeste's Dust.Burst and BurstFG */+void dust_burst(V2 pos, float dir, int n) {+ V2 v = v2(fabsf(cosf(dir - PI_F / 2) * 4), fabsf(sinf(dir - PI_F / 2) * 4));+ particles_emit(PL_MID, &P_Dust, n, pos, v, dir);+}+void dust_burst_fg(V2 pos, float dir, int n, float range) {+ V2 v = v2(fabsf(cosf(dir - PI_F / 2) * range), fabsf(sinf(dir - PI_F / 2) * range));+ particles_emit(PL_FG, &P_Dust, n, pos, v, dir);+}++/* ---------------------------------------------------------------- trails */+typedef struct {+ float x, y, ox, oy, sx, sy, t, dur;+ uint16_t tex;+ uint32_t color;+ uint8_t on;+} Trail;+static Trail trails[12];++void trail_add(float x, float y, uint16_t tex, float ox, float oy, float sx, float sy, uint32_t color, float dur) {+ for (int i = 0; i < 12; i++)+ if (!trails[i].on) {+ trails[i] = (Trail){x, y, ox, oy, sx, sy, 0, dur, tex, color, 1};+ return;+ }+}+void trail_update(void) {+ for (int i = 0; i < 12; i++)+ if (trails[i].on && (trails[i].t += DT) >= trails[i].dur) trails[i].on = 0;+}+void trail_render(void) {+ for (int i = 0; i < 12; i++) {+ Trail *t = &trails[i];+ if (!t->on) continue;+ float a = 1 - t->t / t->dur;+ gfx_tex_ex(t->tex, t->x, t->y, t->ox, t->oy, t->sx, t->sy, 0, rgb(t->color), (uint8_t)(a * 255 * 0.75f), GF_SILHOUETTE);+ }+}+void trail_clear(void) { memset(trails, 0, sizeof trails); }+void fx_update(void) {+ particles_update();+ trail_update();+}diff --git a/games/celeste/src/fx.h b/games/celeste/src/fx.hnew file mode 100644index 00000000..ad2b805d--- /dev/null+++ b/games/celeste/src/fx.h@@ -0,0 +1,44 @@+/* Particles (Monocle's ParticleSystem and Celeste's ParticleTypes), the dash+ * trail, and Dust. */+#ifndef FX_H+#define FX_H+#include "celeste.h"++enum { PC_STATIC, PC_CHOOSE, PC_BLINK, PC_FADE };+enum { PF_NONE, PF_LINEAR, PF_LATE, PF_INOUT };+enum { PR_NONE, PR_RANDOM, PR_SAMEASDIR };+typedef struct {+ uint32_t color, color2; /* 0xAARRGGBB, unpremultiplied */+ uint8_t color_mode, fade_mode, rot_mode, scale_out;+ float size, size_range;+ float speed_min, speed_max, speed_mult;+ float life_min, life_max;+ float direction, dir_range;+ float spin_min, spin_max;+ uint8_t spin_flip;+ V2 accel;+ float friction;+ uint16_t src[4]; /* textures; none: a 1x1 pixel */+ uint8_t nsrc, raw_dt;+} PType;+enum { PL_BG, PL_MID, PL_FG }; /* ParticlesBG, Particles, ParticlesFG */+void particles_clear(void);+void particles_emit(int layer, const PType *t, int n, V2 pos, V2 range, float dir);+void particles_emit_c(int layer, const PType *t, int n, V2 pos, V2 range, uint32_t color, float dir);+void particles_emit1(int layer, const PType *t, V2 pos, float dir);+void particles_update(void);+void particles_render(int layer);++void dust_burst(V2 pos, float dir, int n);+void dust_burst_fg(V2 pos, float dir, int n, float range);++/* TrailManager: afterimages */+void trail_add(float x, float y, uint16_t tex, float ox, float oy, float sx, float sy, uint32_t color, float duration);+void trail_update(void);+void trail_render(void);+void trail_clear(void);++/* SlashFx and the like: short sprite effects */+void fx_update(void);+#include "ptypes.h"+#endifdiff --git a/games/celeste/src/game.c b/games/celeste/src/game.cnew file mode 100644index 00000000..35c09235--- /dev/null+++ b/games/celeste/src/game.c@@ -0,0 +1,104 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* The game: the level, the death wipe, and the frame loop's steps. */+#include "level.h"+#include "player.h"+#include "fx.h"+#include "wipe.h"++uint32_t g_frame;+float g_dt = RAW_DT, g_time_rate = 1;+void game_play(int chapter, int checkpoint);+bool g_running = true;++bool g_in_level; /* a level is on (the menus can be over it: pause) */++/* start chapter `chapter` (in data.bin) at a checkpoint (-1: its start), or carry on the saved session */+void game_play(int chapter, int checkpoint) {+ bool resume = chapter < 0;+ if (!resume) session_start(chapter, checkpoint);+ g_save.has_session = 1;+ g_in_level = true;+ g_menu = 0;+ hud_reset();+ level_start(resume ? INTRO_RESPAWN : session_intro(true));+}++void game_init(void) {+ res_init();+ rnd_seed(&g_rnd, 0);+ save_load();+#ifdef PERF_ROOM /* speed tests (tools/emu.py): straight into a room */+ session_start(PERF_CHAPTER, -1);+ g_session.level = (uint8_t)chapter_find_room(PERF_CHAPTER, PERF_ROOM);+ g_in_level = true;+ level_start(INTRO_NONE);+ return;+#endif+ menu_open_title(); /* the key sheet first, the first time */+}++/* LevelExit: the save written, then the chapter's end, the map or the main menu, or the chapter again */+void game_level_exit(int mode) {+ int area = g_session.area;+ switch (mode) {+ case LEXIT_RESTART: /* Session.Restart: from where it began */+ game_play(g_session.chapter, g_session.start_checkpoint);+ return;+ case LEXIT_SAVEQUIT: g_save.has_session = 1; break;+ default: g_save.has_session = 0; break;+ }+ g_save.last_area = (uint8_t)area, g_save.last_mode = g_session.mode;+ save_write();+ g_in_level = false;+ wipe_start(WIPE_FADE, true, NULL);+ if (mode == LEXIT_SAVEQUIT) menu_open_main();+ else menu_open_overworld(mode == LEXIT_COMPLETED && area != 0 && area != 8);+}++/* Home: the run is kept (Save & Quit) */+void game_save(void) {+ if (g_in_level) g_save.has_session = g_session.in_area; /* (from the menus, the run Save & Quit kept stays) */+ save_write();+}++void game_frame(void) {+ g_dt = RAW_DT * g_time_rate;+ input_update(plat_keys());+ if (g_in.keys & K_HOME) {+ g_running = false;+ return;+ }+ if (g_menu) menu_update();+ if (g_in_level) level_update(), hud_update();+ else wipe_update();+ g_frame++;+}++void game_draw(void) {+ gfx_begin();+ gfx_clear(0);+ if (g_in_level) {+ /* Level.Render: the point that stays put is (focus * target - (160, 90)) / (target - 1) */+ float zt = g_level.zoom_target;+ V2 fp = zt != 1 ? v2((g_level.zoom_focus.x * zt - 160) / (zt - 1), (g_level.zoom_focus.y * zt - 90) / (zt - 1)) : v2(0, 0);+ gfx_zoom(g_level.zoom, fp.x, fp.y);+ gfx_camera(g_level.cam.x + g_level.shake_vec.x, g_level.cam.y + g_level.shake_vec.y);+ style_render(false);+ ents_render_between(1 << 30, -(1 << 30));+ style_render(true);+ if (g_level.flash > 0) {+ gfx_screen(true);+ gfx_rect(0, 0, VIEW_W, VIEW_H, g_level.flash_color, (uint8_t)(g_level.flash * g_level.flash_alpha));+ gfx_screen(false);+ Ent *p = level_player_ent();+ if (g_level.flash_draw_player && p && p->visible) p->cls->render(p);+ }+ ents_render_hud();+ } else+ gfx_zoom(1, 0, 0);+ menu_render();+ wipe_render();+ gfx_end();+}diff --git a/games/celeste/src/gfx.c b/games/celeste/src/gfx.cnew file mode 100644index 00000000..90591903--- /dev/null+++ b/games/celeste/src/gfx.c@@ -0,0 +1,910 @@+/* The 320x180 view, drawn in strips.+ *+ * Draw calls during a frame only record commands (in call order, which is+ * depth order: the level renders entities sorted by depth). gfx_end() then+ * fills one 20-row strip at a time, runs every command that touches it, and+ * pushes the strip to the screen. */+#include <stdlib.h>+#include "celeste.h"++#define STRIP_H 15+#define NSTRIPS (VIEW_H / STRIP_H)+#define MAX_CMDS 400+#define MAX_AFFINE 48++uint16_t g_strip[VIEW_W * STRIP_H];+int g_camx, g_camy;+static float camx, camy;+static bool hud, ui; /* hud: screen coordinates; ui: the interface (drawn after the zoom) */+static uint16_t clear_color;+static bool letterbox_dirty = true;++enum { OP_TEX, OP_PART, OP_AFFINE, OP_RECT, OP_LINE, OP_PIXEL, OP_CUSTOM, OP_SCALED, OP_MASK };++typedef struct {+ uint8_t op, flags, alpha, extra;+ uint16_t tex, tint;+ int16_t x, y;+ uint8_t y0, y1; /* view rows covered: [y0, y1) */+ uint16_t a, b;+} Cmd;++typedef struct {+ float px, py; /* screen position of the origin */+ float ox, oy; /* origin in frame pixels */+ float sx, sy, rot;+ int16_t cx0, cy0, cx1, cy1; /* the part of the frame drawn (a subtexture) */+} Affine;++typedef struct { StripFn fn; void *ctx; } Custom;++static Cmd cmds[MAX_CMDS];+static int ncmds;+static Affine affs[MAX_AFFINE];+static int naffs;+static Custom customs[16];+static int ncustoms;++void gfx_camera(float x, float y) {+ camx = x, camy = y;+ g_camx = (int)floorf(x);+ g_camy = (int)floorf(y);+}+void gfx_hud(bool on) { hud = ui = on; }+/* screen coordinates for the gameplay's own layers (stylegrounds): zoomed with the world */+void gfx_screen(bool on) { hud = on, ui = false; }+void gfx_clear(uint16_t c) { clear_color = c; }+void gfx_present_all(void) { letterbox_dirty = true; }++void gfx_begin(void) {+#ifdef HOST+ extern void res_debug_working_set(void);+ res_debug_working_set();+#endif+ g_res_frame++;+ g_res_drawing = true;+ ncmds = 0;+ naffs = 0;+ ncustoms = 0;+ hud = false;+}++/* the interface keeps the last HUD_CMDS commands and HUD_AFFS affine ones: a busy room's world can't take them */+#define HUD_CMDS 48+#define HUD_AFFS 8+static Cmd *add(uint8_t op, int y0, int y1) {+ if (y1 <= 0 || y0 >= VIEW_H || ncmds >= (ui ? MAX_CMDS : MAX_CMDS - HUD_CMDS)) return NULL;+ Cmd *c = &cmds[ncmds++];+ c->op = op;+ c->extra = ui ? 1 : 0; /* the interface's: not zoomed */+ c->y0 = (uint8_t)(y0 < 0 ? 0 : y0);+ c->y1 = (uint8_t)(y1 > VIEW_H ? VIEW_H : y1);+ c->flags = 0;+ c->alpha = 255;+ c->tint = 0xFFFF;+ return c;+}++static inline int sx_(float x) { return (int)floorf(x + 0.5f) - (hud ? 0 : g_camx); }+static inline int sy_(float y) { return (int)floorf(y + 0.5f) - (hud ? 0 : g_camy); }++/* ---------------------------------------------------------------- color math */+uint16_t blend565(uint16_t d, uint16_t s, int a) {+ /* s premultiplied: s + d * (1 - a), a in 0..256 */+ uint32_t ia = 256 - a;+ uint32_t r = (s >> 11) + (((d >> 11) * ia) >> 8);+ uint32_t g = ((s >> 5) & 63) + ((((d >> 5) & 63) * ia) >> 8);+ uint32_t b = (s & 31) + (((d & 31) * ia) >> 8);+ if (r > 31) r = 31;+ if (g > 63) g = 63;+ if (b > 31) b = 31;+ return (uint16_t)(r << 11 | g << 5 | b);+}+/* saturating add of two RGB565 colors: the fields spread out with room to overflow */+static inline uint16_t add565(uint16_t d, uint16_t s) {+ uint32_t x = (d | (uint32_t)d << 16) & 0x07E0F81Fu, y = (s | (uint32_t)s << 16) & 0x07E0F81Fu;+ uint32_t t = x + y, ov = t & 0x08010020u;+ uint32_t lo = ov & 0x00010020u, hi = ov & 0x08000000u;+ t |= (lo - (lo >> 5)) | (hi - (hi >> 6));+ t &= 0x07E0F81Fu;+ return (uint16_t)(t | t >> 16);+}+uint16_t mul565(uint16_t c, uint16_t t) {+ uint32_t r = ((c >> 11) * ((t >> 11) + 1)) >> 5;+ uint32_t g = (((c >> 5) & 63) * (((t >> 5) & 63) + 1)) >> 6;+ uint32_t b = ((c & 31) * ((t & 31) + 1)) >> 5;+ return (uint16_t)(r << 11 | g << 5 | b);+}++/* the palette a command draws with: tint, alpha and blending folded in. Drawn as it is (no tint,+ * opaque, no blending: most draws), the palette is used from flash as it is, nothing computed. */+static uint16_t epal[256];+static uint16_t ealpha[256]; /* 0..256 */+static uint16_t ep_pal = 0xFFFF, ep_tint;+static uint8_t ep_alpha, ep_flags;+static bool ep_opaque; /* every entry fully opaque, nothing to blend */+static const uint16_t *EC; /* the colors (by index: 1 the palette's first) */+static const uint8_t *EA; /* plain: the palette's own alphas (0..255), else NULL (ealpha) */++static void prep(uint16_t pal, uint16_t tint, uint8_t alpha, uint8_t flags) {+ flags &= GF_ADD | GF_SILHOUETTE;+ if (pal == ep_pal && tint == ep_tint && alpha == ep_alpha && flags == ep_flags) return;+ ep_pal = pal, ep_tint = tint, ep_alpha = alpha, ep_flags = flags;+ int n;+ const uint16_t *c = pal_colors(pal, &n);+ const uint8_t *a = pal_alpha(pal);+ if (tint == 0xFFFF && alpha == 255 && !flags) { /* as it is */+ EC = c - 1, EA = a - 1;+ ep_opaque = pal_opaque(pal);+ return;+ }+ EC = epal, EA = NULL;+#ifdef HOST+ { extern long g_dbg_prep, g_dbg_prep_n; g_dbg_prep++, g_dbg_prep_n += n; }+#endif+ ep_opaque = alpha == 255 && !(flags & GF_ADD);+ int ga = alpha + (alpha >> 7);+ if (flags & GF_SILHOUETTE) {+ for (int i = 0; i < n; i++) {+ int aa = a[i] + (a[i] >> 7);+ uint16_t col = aa >= 256 ? tint : scale565(tint, aa);+ if (ga != 256) col = scale565(col, ga), aa = (aa * ga) >> 8;+ epal[i + 1] = col;+ ealpha[i + 1] = (uint16_t)aa;+ if (aa != 256) ep_opaque = false;+ }+ return;+ }+ /* each channel through a table: the tint (mul565) and the fade (scale565) at once */+ uint8_t lr[32], lg[64], lb[32];+ int tr = tint >> 11, tg = tint >> 5 & 63, tb = tint & 31;+ for (int v = 0; v < 32; v++) {+ lr[v] = (uint8_t)((((v * (tr + 1)) >> 5) * ga) >> 8);+ lb[v] = (uint8_t)((((v * (tb + 1)) >> 5) * ga) >> 8);+ }+ for (int v = 0; v < 64; v++) lg[v] = (uint8_t)((((v * (tg + 1)) >> 6) * ga) >> 8);+ for (int i = 0; i < n; i++) {+ uint16_t col = c[i];+ int aa = a[i] + (a[i] >> 7);+ if (ga != 256) aa = (aa * ga) >> 8;+ epal[i + 1] = (uint16_t)(lr[col >> 11] << 11 | lg[col >> 5 & 63] << 5 | lb[col & 31]);+ ealpha[i + 1] = (uint16_t)aa;+ if (aa != 256) ep_opaque = false;+ }+}+static inline int alpha_of(uint8_t idx) { /* 0..256 */+ if (EA) return EA[idx] + (EA[idx] >> 7);+ return ealpha[idx];+}++static inline void plot(uint16_t *d, uint8_t idx) {+ if (ep_opaque) {+ *d = EC[idx];+ return;+ }+ if (ep_flags & GF_ADD) {+ *d = add565(*d, EC[idx]);+ return;+ }+ int a = alpha_of(idx);+ *d = a >= 256 ? EC[idx] : blend565(*d, EC[idx], a);+}++/* n pixels from d on, one step (+1 or -1) apart: one index (run) or n indices (literals) */+static inline void span_run(uint16_t *d, int n, int step, uint8_t v) {+ uint16_t c = EC[v];+ if (ep_opaque) {+ if (step > 0)+ while (n--) *d++ = c;+ else+ while (n--) *d-- = c;+ } else if (ep_flags & GF_ADD) {+ for (; n--; d += step) *d = add565(*d, c);+ } else {+ int a = alpha_of(v);+ if (a >= 256)+ for (; n--; d += step) *d = c;+ else+ for (; n--; d += step) *d = blend565(*d, c, a);+ }+}+static inline void span_lit(uint16_t *d, int n, int step, const uint8_t *s) {+ if (ep_opaque) {+ if (step > 0)+ while (n--) *d++ = EC[*s++];+ else+ while (n--) *d-- = EC[*s++];+ } else if (ep_flags & GF_ADD) {+ for (; n--; d += step) *d = add565(*d, EC[*s++]);+ } else+ for (; n--; d += step, s++) {+ int a = alpha_of(*s);+ *d = a >= 256 ? EC[*s] : blend565(*d, EC[*s], a);+ }+}++/* ---------------------------------------------------------------- blits */+/* an RLE texture's row r: its ops [*begin, *end). TF_ROW8 rows are found by adding the lengths+ * up, from the last row asked for when it is the same texture */+static const uint8_t *row_ops(const Tex *t, int r, const uint8_t **end) {+ if (!(t->fmt & TF_ROW8)) {+ const uint16_t *offs = (const uint16_t *)(const void *)t->px;+ *end = t->px + offs[r + 1];+ return t->px + offs[r];+ }+ static const uint8_t *last_px, *last_p;+ static int last_r;+ static uint16_t last_gen;+ extern uint16_t g_res_gen;+ const uint8_t *lens = t->px, *p;+ int i;+ if (last_px == t->px && last_r <= r && last_gen == g_res_gen) p = last_p, i = last_r;+ else p = t->px + t->h, i = 0;+ for (; i < r; i++) p += lens[i];+ last_px = t->px, last_r = r, last_p = p, last_gen = g_res_gen;+ *end = p + lens[r];+ return p;+}+/* TF_NIB: n literals (two a byte) as palette indices */+static uint8_t litbuf[128];+static const uint8_t *nib_lits(const Tex *t, const uint8_t *op, int n) {+ for (int i = 0; i < n; i++) litbuf[i] = t->map[(op[i >> 1] >> ((i & 1) * 4)) & 15];+ return litbuf;+}++/* a texture's stored pixels with their top-left at strip-relative (x, y) */+void blit_tex(uint16_t *strip, int sy0, int sy1, const Tex *t, int x, int y, uint8_t flags, uint16_t tint, uint8_t alpha) {+ prep(t->pal, tint, alpha, flags);+ int h = t->h, w = t->w;+ int r0 = sy0 - y, r1 = sy1 - y; /* rows of the texture inside the strip */+ if (r0 < 0) r0 = 0;+ if (r1 > h) r1 = h;+ if (x >= VIEW_W || x + w <= 0) return;+ bool fx = flags & GF_FLIPX, fy = flags & GF_FLIPY, nib = t->fmt & TF_NIB;+ for (int r = r0; r < r1; r++) {+ int src = fy ? h - 1 - r : r;+ uint16_t *row = strip + (y + r - sy0) * VIEW_W;+ if (t->fmt == TF_RAW4) {+ for (int i = 0; i < w; i++) {+ uint32_t at = (uint32_t)src * w + i;+ uint8_t v = (t->px[at >> 1] >> ((at & 1) * 4)) & 15;+ int dx = fx ? x + w - 1 - i : x + i;+ if ((unsigned)dx >= VIEW_W || !v) continue;+ plot(row + dx, v);+ }+ continue;+ }+ const uint8_t *end, *op = row_ops(t, src, &end);+ /* i: texture column; pixel i lands at x0 + i * step */+ int x0 = fx ? x + w - 1 : x, step = fx ? -1 : 1;+ int i = 0;+ while (op < end) {+ uint8_t o = *op++;+ int n;+ if (o < 0x40) {+ i += o + 1;+ continue;+ }+ n = o < 0x80 ? o - 0x3F : o - 0x7F;+ /* the part of [i, i + n) whose pixels fall inside the view */+ int a = i, b = i + n;+ int da = x0 + a * step, db = x0 + (b - 1) * step;+ if (step > 0) {+ if (da < 0) a += -da;+ if (db >= VIEW_W) b -= db - (VIEW_W - 1);+ } else {+ if (da >= VIEW_W) a += da - (VIEW_W - 1);+ if (db < 0) b -= -db;+ }+ if (o < 0x80) {+ if (a < b) span_run(row + x0 + a * step, b - a, step, nib ? t->map[*op] : *op);+ op++;+ } else if (nib) {+ if (a < b) span_lit(row + x0 + a * step, b - a, step, nib_lits(t, op, n) + (a - i));+ op += (n + 1) >> 1;+ } else {+ if (a < b) span_lit(row + x0 + a * step, b - a, step, op + (a - i));+ op += n;+ }+ i += n;+ }+ }+}++/* one row of a texture as indices (for scaled and partial draws) */+void tex_row(const Tex *t, int r, uint8_t *out) {+ memset(out, 0, t->w);+ if (t->fmt == TF_RAW4) {+ for (int i = 0; i < t->w; i++) {+ uint32_t at = (uint32_t)r * t->w + i;+ out[i] = (t->px[at >> 1] >> ((at & 1) * 4)) & 15;+ }+ return;+ }+ bool nib = t->fmt & TF_NIB;+ const uint8_t *end, *op = row_ops(t, r, &end);+ int i = 0;+ while (op < end && i < t->w) {+ uint8_t o = *op++;+ if (o < 0x40) i += o + 1;+ else if (o < 0x80) {+ uint8_t v = nib ? t->map[*op] : *op;+ op++;+ for (int k = o - 0x3F; k > 0 && i < t->w; k--) out[i++] = v;+ } else if (nib) {+ int n = o - 0x7F;+ for (int k = 0; k < n; k++) {+ uint8_t v = t->map[(op[k >> 1] >> ((k & 1) * 4)) & 15];+ if (i < t->w) out[i++] = v;+ }+ op += (n + 1) >> 1;+ } else+ for (int k = o - 0x7F; k > 0; k--) {+ uint8_t v = *op++;+ if (i < t->w) out[i++] = v;+ }+ }+}++static uint8_t rowbuf[1024];+static const uint8_t *turned_src; /* the texture blit_turned left in rowbuf (32 a row) */+static uint16_t turned_gen;++/* sub-rect (sx, sy, w, h) of the frame, at strip-relative (x, y) */+void blit_part_ex(uint16_t *strip, int sy0, int sy1, const Tex *t, int x, int y, int sx, int sy, int w, int h,+ uint8_t flags, uint16_t tint, uint8_t alpha) {+ prep(t->pal, tint, alpha, flags);+ bool fx = flags & GF_FLIPX, fy = flags & GF_FLIPY;+ for (int r = 0; r < h; r++) {+ int vy = y + r;+ if (vy < sy0 || vy >= sy1) continue;+ int fr = sy + (fy ? h - 1 - r : r) - t->oy; /* stored row */+ if (fr < 0 || fr >= t->h) continue;+ uint16_t *row = strip + (vy - sy0) * VIEW_W;+ turned_src = NULL, tex_row(t, fr, rowbuf);+ for (int i = 0; i < w; i++) {+ int c = sx + (fx ? w - 1 - i : i) - t->ox;+ int dx = x + i;+ if ((unsigned)dx >= VIEW_W || c < 0 || c >= t->w || !rowbuf[c]) continue;+ plot(row + dx, rowbuf[c]);+ }+ }+}++/* t's frame (square, 32 at most) turned q quarter turns clockwise around its center, the frame's top-left at+ * strip-relative (x, y) */+void blit_turned(uint16_t *strip, int sy0, int sy1, const Tex *t, int x, int y, int q, uint8_t flags, uint16_t tint) {+ uint8_t *px = rowbuf; /* the texture, 32 a row */+ int fw = t->fw, w = t->w, h = t->h;+ if (fw > 32 || w > 32 || h > 32 || y >= sy1 || y + fw <= sy0 || x >= VIEW_W || x + fw <= 0) return;+ prep(t->pal, tint, 255, flags);+ extern uint16_t g_res_gen;+ if (turned_src != t->px || turned_gen != g_res_gen) { /* (the same one again: still there) */+ for (int r = 0; r < h; r++) tex_row(t, r, px + r * 32);+ turned_src = t->px, turned_gen = g_res_gen;+ }+ for (int dy = 0; dy < fw; dy++) {+ int vy = y + dy;+ if (vy < sy0 || vy >= sy1) continue;+ uint16_t *row = strip + (vy - sy0) * VIEW_W;+ for (int dx = 0; dx < fw; dx++) {+ int vx = x + dx, a, b;+ if ((unsigned)vx >= VIEW_W) continue;+ switch (q & 3) {+ case 0: a = dx, b = dy; break;+ case 1: a = dy, b = fw - 1 - dx; break;+ case 2: a = fw - 1 - dx, b = fw - 1 - dy; break;+ default: a = fw - 1 - dy, b = dx; break;+ }+ a -= t->ox, b -= t->oy;+ if (a < 0 || b < 0 || a >= w || b >= h || !px[b * 32 + a]) continue;+ plot(row + vx, px[b * 32 + a]);+ }+ }+}++/* a grid of 8x8 tiles of t (per nibble: tx | ty << 2, 12 for none) with its top-left at screen (x, y),+ * scaled by (scx, scy) around screen (gx, gy) (CassetteBlock's images) */+void blit_cells(uint16_t *strip, int sy0, int sy1, const Tex *t, float x, float y, int ncx, int ncy, const uint8_t *cells,+ float gx, float gy, float scx, float scy, uint16_t tint) {+ prep(t->pal, tint, 255, 0);+ float l = gx + (x - gx) * scx, r = gx + (x + ncx * 8 - gx) * scx;+ float top = gy + (y - gy) * scy, bot = gy + (y + ncy * 8 - gy) * scy;+ int r0 = (int)floorf(top), r1 = (int)ceilf(bot), c0 = (int)floorf(l), c1 = (int)ceilf(r);+ if (r0 < sy0) r0 = sy0;+ if (r1 > sy1) r1 = sy1;+ if (c0 < 0) c0 = 0;+ if (c1 > VIEW_W) c1 = VIEW_W;+ for (int vy = r0; vy < r1; vy++) {+ float ly = (vy + 0.5f - gy) / scy + gy - y;+ if (ly < 0 || ly >= ncy * 8) continue;+ int cy = (int)ly >> 3, py = (int)ly & 7, cached = -1;+ uint16_t *row = strip + (vy - sy0) * VIEW_W;+ for (int vx = c0; vx < c1; vx++) {+ float lx = (vx + 0.5f - gx) / scx + gx - x;+ if (lx < 0 || lx >= ncx * 8) continue;+ int cx = (int)lx >> 3, i = cy * ncx + cx, tile = cells[i >> 1] >> ((i & 1) * 4) & 15;+ if (tile == 12) continue;+ int sr = (tile >> 2) * 8 + py - t->oy, sc = (tile & 3) * 8 + ((int)lx & 7) - t->ox;+ if (sr < 0 || sr >= t->h || sc < 0 || sc >= t->w) continue;+ if (sr != cached) turned_src = NULL, tex_row(t, sr, rowbuf), cached = sr;+ if (rowbuf[sc]) plot(row + vx, rowbuf[sc]);+ }+ }+}++/* a palette's first 16 colors as drawn (tint folded in) and their alphas (0..256) */+void pal_lut(uint16_t pal, uint16_t tint, uint16_t *col, uint16_t *alpha) {+ int n;+ const uint16_t *c = pal_colors(pal, &n);+ const uint8_t *a = pal_alpha(pal);+ if (n > 15) n = 15;+ for (int i = 0; i < n; i++) {+ col[i + 1] = tint != 0xFFFF ? mul565(c[i], tint) : c[i];+ alpha[i + 1] = (uint16_t)(a[i] + (a[i] >> 7));+ }+}++/* 4-bit textures (TF_RAW4) rotated and scaled around screen points, the first opaque one on top, in+ * one go (DustGraphic): within the box [x0, x1) x [y0, y1); where nothing is but a neighbour is, the+ * outline's color (outline: NULL for none), or what is covered marked in mask (blit_edges draws it) */+void blit_layers(uint16_t *strip, int sy0, int sy1, const Layer *l, int n, int x0, int y0, int x1, int y1,+ uint16_t (*outline)(int x, int y, void *ctx), void *ctx, uint32_t *mask) {+ if (x0 < 0) x0 = 0;+ if (x1 > VIEW_W) x1 = VIEW_W;+ if (x1 - x0 > 32) x1 = x0 + 32;+ bool edges = outline || mask;+ int r0 = y0 > sy0 - edges ? y0 : sy0 - edges, r1 = y1 < sy1 + edges ? y1 : sy1 + edges;+ if (r1 - r0 > 48) r1 = r0 + 48;+ if (r0 >= r1 || x0 >= x1 || !n || n > 9) return;+#ifdef HOST+ extern long g_dbg_layers, g_dbg_pixels;+ g_dbg_layers++, g_dbg_pixels += (long)(r1 - r0) * (x1 - x0);+#endif+ uint32_t cover[48], all = x1 - x0 == 32 ? 0xFFFFFFFFu : (1u << (x1 - x0)) - 1;+ int32_t du[9], dv[9];+ float rad2[9];+ for (int k = 0; k < n; k++) { /* 16.16 texture coordinates along the row; the circle around each */+ du[k] = (int32_t)(l[k].cs * l[k].inv * 65536), dv[k] = (int32_t)(-l[k].sn * l[k].inv * 65536);+ float hx = fmaxf(l[k].ox - l[k].t->ox, l[k].t->ox + l[k].t->w - l[k].ox), hy = fmaxf(l[k].oy - l[k].t->oy, l[k].t->oy + l[k].t->h - l[k].oy);+ rad2[k] = (hx * hx + hy * hy) / (l[k].inv * l[k].inv);+ }+ for (int y = r0; y < r1; y++) {+ float py = y + 0.5f;+ bool draw = y >= sy0 && y < sy1;+ uint16_t *row = strip + (y - sy0) * VIEW_W;+ uint32_t filled = 0, bits = 0;+ if (mask) { /* covered by ones drawn before: they stay on top */+ const uint32_t *m = mask + (y - sy0 + 1) * 10;+ int s0 = x0 & 31;+ uint64_t two = (uint64_t)m[x0 >> 5] | (x0 >> 5 < 9 ? (uint64_t)m[(x0 >> 5) + 1] << 32 : 0);+ filled = (uint32_t)(two >> s0) & all;+ }+ for (int k = 0; k < n && filled != all; k++) { /* the top one first: each only where nothing above is */+ float dy = py - l[k].cy, r2 = rad2[k] - dy * dy;+ if (r2 <= 0) continue;+ float half = sqrtf(r2);+ int xa = (int)floorf(l[k].cx - half), xb = (int)ceilf(l[k].cx + half);+ if (xa < x0) xa = x0;+ if (xb > x1) xb = x1;+ if (xa >= xb) continue;+ uint32_t span = (xb - x0 == 32 ? 0xFFFFFFFFu : (1u << (xb - x0)) - 1) & ~((1u << (xa - x0)) - 1);+ uint32_t todo = span & ~filled;+ if (!todo) continue;+ float dx = x0 + 0.5f - l[k].cx;+ int32_t u0 = (int32_t)(((dx * l[k].cs + dy * l[k].sn) * l[k].inv + l[k].ox - l[k].t->ox) * 65536);+ int32_t v0 = (int32_t)(((-dx * l[k].sn + dy * l[k].cs) * l[k].inv + l[k].oy - l[k].t->oy) * 65536);+ const uint8_t *px = l[k].t->px;+ uint32_t w = l[k].t->w, h = l[k].t->h;+ while (todo) {+ int i = __builtin_ctz(todo);+ todo &= todo - 1;+ uint32_t iu = (uint32_t)((u0 + du[k] * i) >> 16), iv = (uint32_t)((v0 + dv[k] * i) >> 16);+ if (iu >= w || iv >= h) continue;+ uint32_t at = iv * w + iu;+ int c = (px[at >> 1] >> ((at & 1) * 4)) & 15;+ if (!c) continue;+ filled |= 1u << i, bits |= 1u << i;+ if (draw) {+ int a = l[k].la[c];+ uint16_t *d = row + x0 + i;+ *d = a >= 256 ? l[k].lc[c] : blend565(*d, l[k].lc[c], a);+ }+ }+ }+ cover[y - r0] = bits;+ if (mask && bits) { /* rows sy0 - 1 .. sy1 of the screen, 10 words each */+ uint32_t *m = mask + (y - sy0 + 1) * 10;+ int s0 = x0 & 31;+ m[x0 >> 5] |= bits << s0;+ if (s0 && x0 >> 5 < 9) m[(x0 >> 5) + 1] |= bits >> (32 - s0);+ }+ }+ if (!outline || mask) return;+ for (int y = r0 > sy0 ? r0 : sy0; y < r1 && y < sy1; y++) {+ uint16_t *row = strip + (y - sy0) * VIEW_W;+ uint32_t c = cover[y - r0], up = y > r0 ? cover[y - r0 - 1] : 0, dn = y + 1 < r1 ? cover[y + 1 - r0] : 0;+ uint32_t e = (up | dn | c << 1 | c >> 1) & ~c & all;+ while (e) {+ int i = __builtin_ctz(e);+ e &= e - 1;+ row[x0 + i] = outline(x0 + i, y, ctx);+ }+ }+}+/* a 4-bit texture (TF_RAW4) as it is, its top-left at screen (x, y), in pal_lut's colors */+void blit_raw4(uint16_t *strip, int sy0, int sy1, const Tex *t, int x, int y, const uint16_t *lc, const uint16_t *la) {+ x += t->ox, y += t->oy;+ for (int r = 0; r < t->h; r++) {+ int vy = y + r;+ if (vy < sy0 || vy >= sy1) continue;+ uint16_t *row = strip + (vy - sy0) * VIEW_W;+ for (int i = 0; i < t->w; i++) {+ int vx = x + i;+ uint32_t at = (uint32_t)r * t->w + (uint32_t)i;+ int c = (t->px[at >> 1] >> ((at & 1) * 4)) & 15;+ if (!c || (unsigned)vx >= VIEW_W) continue;+ row[vx] = la[c] >= 256 ? lc[c] : blend565(row[vx], lc[c], la[c]);+ }+ }+}+/* the outline of what blit_layers marked (mask: rows sy0 - 1 .. sy1, 10 words each) */+void blit_edges(uint16_t *strip, int sy0, int sy1, const uint32_t *mask, uint16_t (*outline)(int x, int y, void *ctx), void *ctx) {+ for (int y = sy0; y < sy1; y++) {+ const uint32_t *up = mask + (y - sy0) * 10, *c = up + 10, *dn = c + 10;+ uint16_t *row = strip + (y - sy0) * VIEW_W;+ for (int w = 0; w < 10; w++) {+ uint32_t left = w ? c[w - 1] >> 31 : 0, right = w < 9 ? c[w + 1] << 31 : 0;+ uint32_t e = (up[w] | dn[w] | c[w] << 1 | left | c[w] >> 1 | right) & ~c[w];+ while (e) {+ int b = __builtin_ctz(e);+ e &= e - 1;+ row[w * 32 + b] = outline(w * 32 + b, y, ctx);+ }+ }+ }+}++/* a texture stored k times smaller, drawn k times bigger at (x, y) */+static void blit_scaled(uint16_t *strip, int sy0, int sy1, const Tex *t, int x, int y, uint8_t flags, uint16_t tint, uint8_t alpha) {+ prep(t->pal, tint, alpha, flags);+ int k = t->scale, w = t->w * k, h = t->h * k;+ int r0 = sy0 - y, r1 = sy1 - y;+ if (r0 < 0) r0 = 0;+ if (r1 > h) r1 = h;+ int cached = -1;+ for (int r = r0; r < r1; r++) {+ int src = r / k;+ if (src != cached) turned_src = NULL, tex_row(t, src, rowbuf), cached = src;+ uint16_t *row = strip + (y + r - sy0) * VIEW_W;+ int i0 = x < 0 ? -x : 0, i1 = x + w > VIEW_W ? VIEW_W - x : w;+ for (int i = i0; i < i1;) {+ int s = i / k;+ uint8_t v = rowbuf[s];+ int s2 = s + 1;+ while (s2 < t->w && rowbuf[s2] == v) s2++; /* equal neighbours make one span */+ int e = s2 * k;+ if (e > i1) e = i1;+ if (v) span_run(row + x + i, e - i, 1, v);+ i = e;+ }+ }+}++static void blit_affine(uint16_t *strip, int sy0, int sy1, const Tex *t, const Affine *a, uint16_t tint, uint8_t alpha, uint8_t flags) {+ prep(t->pal, tint, alpha, flags);+ float cs = cosf(a->rot), sn = sinf(a->rot);+ if (a->sx == 0 || a->sy == 0) return;+ float isx = 1.f / a->sx, isy = 1.f / a->sy;+ /* bounds of the transformed stored rect */+ /* the stored rect within the drawn part */+ float l = fmaxf((float)t->ox, a->cx0), r = fminf((float)(t->ox + t->w), a->cx1);+ float tp = fmaxf((float)t->oy, a->cy0), bt = fminf((float)(t->oy + t->h), a->cy1);+ if (l >= r || tp >= bt) return;+ float cx[4] = {l, r, l, r};+ float cy[4] = {tp, tp, bt, bt};+ float minx = 1e9f, maxx = -1e9f, miny = 1e9f, maxy = -1e9f;+ for (int i = 0; i < 4; i++) {+ float lx = (cx[i] - a->ox) * a->sx, ly = (cy[i] - a->oy) * a->sy;+ float X = a->px + lx * cs - ly * sn, Y = a->py + lx * sn + ly * cs;+ if (X < minx) minx = X;+ if (X > maxx) maxx = X;+ if (Y < miny) miny = Y;+ if (Y > maxy) maxy = Y;+ }+ int x0 = (int)floorf(minx), x1 = (int)ceilf(maxx), y0 = (int)floorf(miny), y1 = (int)ceilf(maxy);+ if (x0 < 0) x0 = 0;+ if (x1 > VIEW_W) x1 = VIEW_W;+ if (y0 < sy0) y0 = sy0;+ if (y1 > sy1) y1 = sy1;+ int cached = -1;+ for (int Y = y0; Y < y1; Y++) {+ uint16_t *row = strip + (Y - sy0) * VIEW_W;+ for (int X = x0; X < x1; X++) {+ float dx = X + 0.5f - a->px, dy = Y + 0.5f - a->py;+ float lx = (dx * cs + dy * sn) * isx + a->ox, ly = (-dx * sn + dy * cs) * isy + a->oy;+ if (lx < a->cx0 || lx >= a->cx1 || ly < a->cy0 || ly >= a->cy1) continue;+ int u = (int)floorf(lx) - t->ox, v = (int)floorf(ly) - t->oy;+ if ((unsigned)u >= t->w || (unsigned)v >= t->h) continue;+ if (v != cached) {+ turned_src = NULL, tex_row(t, v, rowbuf);+ cached = v;+ }+ if (rowbuf[u]) plot(row + X, rowbuf[u]);+ }+ }+}++static void fill(uint16_t *strip, int sy0, int sy1, int x, int y, int w, int h, uint16_t c, uint8_t alpha) {+ int x0 = x < 0 ? 0 : x, x1 = x + w > VIEW_W ? VIEW_W : x + w;+ int y0 = y < sy0 ? sy0 : y, y1 = y + h > sy1 ? sy1 : y + h;+ if (x0 >= x1 || y0 >= y1) return;+ int a = alpha + (alpha >> 7);+ uint16_t pc = a >= 256 ? c : scale565(c, a);+ for (int r = y0; r < y1; r++) {+ uint16_t *d = strip + (r - sy0) * VIEW_W + x0;+ if (a >= 256)+ for (int i = x0; i < x1; i++) *d++ = c;+ else+ for (int i = x0; i < x1; i++, d++) *d = blend565(*d, pc, a);+ }+}++static void line(uint16_t *strip, int sy0, int sy1, int x0, int y0, int x1, int y1, uint16_t c, uint8_t alpha) {+ int dx = abs(x1 - x0), dy = -abs(y1 - y0), sx = x0 < x1 ? 1 : -1, sy = y0 < y1 ? 1 : -1, err = dx + dy;+ int a = alpha + (alpha >> 7);+ uint16_t pc = a >= 256 ? c : scale565(c, a);+ for (int guard = 0; guard < 4096; guard++) {+ if (y0 >= sy0 && y0 < sy1 && (unsigned)x0 < VIEW_W) {+ uint16_t *d = strip + (y0 - sy0) * VIEW_W + x0;+ *d = a >= 256 ? c : blend565(*d, pc, a);+ }+ if (x0 == x1 && y0 == y1) break;+ int e2 = 2 * err;+ if (e2 >= dy) err += dy, x0 += sx;+ if (e2 <= dx) err += dx, y0 += sy;+ }+}++/* ---------------------------------------------------------------- recording */+void gfx_tex(uint16_t tex, float x, float y, uint8_t flags, uint16_t tint, uint8_t alpha) {+ Tex t;+ if (!tex_get(tex, &t) || !alpha) return;+ if (t.scale > 1) {+ int k = t.scale, X = sx_(x) + t.ox * k, Y = sy_(y) + t.oy * k;+ Cmd *c = add(OP_SCALED, Y, Y + t.h * k);+ if (!c) return;+ c->tex = tex, c->x = (int16_t)X, c->y = (int16_t)Y, c->flags = flags, c->tint = tint, c->alpha = alpha;+ return;+ }+ int X = sx_(x) + (flags & GF_FLIPX ? t.fw - t.ox - t.w : t.ox);+ int Y = sy_(y) + (flags & GF_FLIPY ? t.fh - t.oy - t.h : t.oy);+ Cmd *c = add(OP_TEX, Y, Y + t.h);+ if (!c) return;+ if (X >= VIEW_W || X + t.w <= 0) {+ ncmds--;+ return;+ }+ c->tex = tex, c->x = (int16_t)X, c->y = (int16_t)Y, c->flags = flags, c->tint = tint, c->alpha = alpha;+}++void gfx_tex_ex(uint16_t tex, float x, float y, float ox, float oy, float sx, float sy, float rot, uint16_t tint, uint8_t alpha, uint8_t flags) {+ if (!alpha) return;+ Tex t;+ if (!tex_get(tex, &t)) return;+ int k = t.scale > 1 ? t.scale : 1; /* stored k times smaller: the origin is in drawn pixels */+ if (rot == 0 && (sx == 1 || sx == -1) && (sy == 1 || sy == -1)) {+ uint8_t f = flags;+ float px = x - (sx > 0 ? ox : t.fw * k - ox), py = y - (sy > 0 ? oy : t.fh * k - oy);+ if (sx < 0) f ^= GF_FLIPX;+ if (sy < 0) f ^= GF_FLIPY;+ gfx_tex(tex, px, py, f, tint, alpha);+ return;+ }+ if (naffs >= (ui ? MAX_AFFINE : MAX_AFFINE - HUD_AFFS)) return;+ Affine *a = &affs[naffs];+ a->px = floorf(x + 0.5f) - (hud ? 0 : g_camx), a->py = floorf(y + 0.5f) - (hud ? 0 : g_camy);+ a->ox = ox / k, a->oy = oy / k, a->sx = sx * k, a->sy = sy * k, a->rot = rot;+ a->cx0 = a->cy0 = -32768, a->cx1 = a->cy1 = 32767;+ if (flags & GF_FLIPX) a->sx = -a->sx;+ if (flags & GF_FLIPY) a->sy = -a->sy;+ float r = (fabsf(a->sx) + fabsf(a->sy)) * (t.fw + t.fh + 2);+ Cmd *c = add(OP_AFFINE, (int)(a->py - r), (int)(a->py + r) + 1);+ if (!c) return;+ naffs++;+ c->tex = tex, c->a = (uint16_t)(naffs - 1), c->tint = tint, c->alpha = alpha, c->flags = flags;+}++/* a subtexture (frame rect sx, sy, w, h) drawn like MTexture.Draw with an origin (in the part), scale and rotation */+void gfx_tex_part_ex(uint16_t tex, float x, float y, int sx, int sy, int w, int h, float ox, float oy, float scx, float scy,+ float rot, uint16_t tint, uint8_t alpha, uint8_t flags) {+ Tex t;+ if (!alpha || !tex_get(tex, &t) || naffs >= (ui ? MAX_AFFINE : MAX_AFFINE - HUD_AFFS)) return;+ Affine *a = &affs[naffs];+ a->px = floorf(x + 0.5f) - (hud ? 0 : g_camx), a->py = floorf(y + 0.5f) - (hud ? 0 : g_camy);+ a->ox = sx + ox, a->oy = sy + oy, a->sx = scx, a->sy = scy, a->rot = rot;+ if (flags & GF_FLIPX) a->sx = -a->sx, a->ox = sx + w - ox;+ if (flags & GF_FLIPY) a->sy = -a->sy, a->oy = sy + h - oy;+ a->cx0 = (int16_t)sx, a->cy0 = (int16_t)sy, a->cx1 = (int16_t)(sx + w), a->cy1 = (int16_t)(sy + h);+ float r = (fabsf(scx) + fabsf(scy)) * (w + h + 2);+ Cmd *c = add(OP_AFFINE, (int)(a->py - r), (int)(a->py + r) + 1);+ if (!c) return;+ naffs++;+ c->tex = tex, c->a = (uint16_t)(naffs - 1), c->tint = tint, c->alpha = alpha, c->flags = flags & ~(GF_FLIPX | GF_FLIPY);+}++void gfx_tex_part(uint16_t tex, float x, float y, int sx, int sy, int w, int h, uint8_t flags, uint16_t tint, uint8_t alpha) {+ Tex t;+ if (!tex_get(tex, &t) || !alpha) return;+ int X = sx_(x), Y = sy_(y);+ if (X >= VIEW_W || X + w <= 0) return;+ Cmd *c = add(OP_PART, Y, Y + h);+ if (!c) return;+ c->tex = tex, c->x = (int16_t)X, c->y = (int16_t)Y, c->flags = flags, c->tint = tint, c->alpha = alpha;+ c->a = (uint16_t)(sx | sy << 8), c->b = (uint16_t)(w | h << 8);+}++void gfx_rect(float x, float y, float w, float h, uint16_t col, uint8_t alpha) {+ if (!alpha) return;+ int X = sx_(x), Y = sy_(y), W_ = (int)floorf(w + 0.5f), H_ = (int)floorf(h + 0.5f);+ if (W_ <= 0 || H_ <= 0 || X >= VIEW_W || X + W_ <= 0) return;+ Cmd *c = add(OP_RECT, Y, Y + H_);+ if (!c) return;+ c->x = (int16_t)X, c->y = (int16_t)Y, c->a = (uint16_t)W_, c->b = (uint16_t)H_, c->tint = col, c->alpha = alpha;+}++void gfx_hollow_rect(float x, float y, float w, float h, uint16_t c, uint8_t alpha) {+ gfx_rect(x, y, w, 1, c, alpha);+ gfx_rect(x, y + h - 1, w, 1, c, alpha);+ gfx_rect(x, y + 1, 1, h - 2, c, alpha);+ gfx_rect(x + w - 1, y + 1, 1, h - 2, c, alpha);+}++void gfx_line(float x0, float y0, float x1, float y1, uint16_t col, uint8_t alpha) {+ int X0 = sx_(x0), Y0 = sy_(y0), X1 = sx_(x1), Y1 = sy_(y1);+ Cmd *c = add(OP_LINE, Y0 < Y1 ? Y0 : Y1, (Y0 > Y1 ? Y0 : Y1) + 1);+ if (!c) return;+ c->x = (int16_t)X0, c->y = (int16_t)Y0, c->a = (uint16_t)(int16_t)X1, c->b = (uint16_t)(int16_t)Y1, c->tint = col, c->alpha = alpha;+}++void gfx_pixel(float x, float y, uint16_t col, uint8_t alpha) { gfx_rect(x, y, 1, 1, col, alpha); }++void gfx_circle(float x, float y, float r, uint16_t col, uint8_t alpha, int res) {+ float px = x + r, py = y;+ for (int i = 1; i <= res; i++) {+ float a = i * 2 * PI_F / res;+ float nx = x + cosf(a) * r, ny = y + sinf(a) * r;+ gfx_line(px, py, nx, ny, col, alpha);+ px = nx, py = ny;+ }+}++/* a 4-bit alpha mask (fonts) in data.bin: w x h, rows padded to bytes, drawn in one color */+void gfx_mask4(const uint8_t *bits, int w, int h, float x, float y, uint16_t col, uint8_t alpha) {+ int X = sx_(x), Y = sy_(y);+ if (X >= VIEW_W || X + w <= 0 || !alpha) return;+ Cmd *c = add(OP_MASK, Y, Y + h);+ if (!c) return;+ uint32_t off = (uint32_t)(bits - cel_bin);+ c->x = (int16_t)X, c->y = (int16_t)Y, c->tint = col, c->alpha = alpha;+ c->a = (uint16_t)(off & 0xFFFF), c->b = (uint16_t)(off >> 16);+ c->tex = (uint16_t)(w | h << 8);+}+static void blit_mask(uint16_t *strip, int sy0, int sy1, const uint8_t *bits, int w, int h, int x, int y, uint16_t col, uint8_t alpha) {+ int stride = (w + 1) / 2, ga = alpha + (alpha >> 7);+ for (int r = 0; r < h; r++) {+ int Y = y + r;+ if (Y < sy0 || Y >= sy1) continue;+ const uint8_t *p = bits + r * stride;+ uint16_t *row = strip + (Y - sy0) * VIEW_W;+ for (int i = 0; i < w; i++) {+ int X = x + i;+ if ((unsigned)X >= VIEW_W) continue;+ int v = (p[i >> 1] >> ((i & 1) * 4)) & 15;+ if (!v) continue;+ int a = (v * 17 * ga) >> 8;+ row[X] = a >= 255 ? col : blend565(row[X], scale565(col, a + 1), a + 1);+ }+ }+}++void gfx_custom(StripFn fn, void *ctx, int y0, int y1) {+ if (ncustoms >= 16) return;+ Cmd *c = add(OP_CUSTOM, y0, y1);+ if (!c) return;+ customs[ncustoms] = (Custom){fn, ctx};+ c->a = (uint16_t)ncustoms++;+}++/* ---------------------------------------------------------------- presenting */+/* the commands crossing rows [y0, y1) drawn into the strip (which holds those rows); pass: 0 the world's,+ * 1 the interface's, 2 all */+static void replay(int y0, int y1, int pass) {+ for (int i = 0; i < ncmds; i++) {+ Cmd *c = &cmds[i];+ if (c->y1 <= y0 || c->y0 >= y1) continue;+ if (pass != 2 && (c->extra & 1) != pass) continue;+ Tex t;+ switch (c->op) {+ case OP_TEX:+ if (tex_get(c->tex, &t)) blit_tex(g_strip, y0, y1, &t, c->x, c->y, c->flags, c->tint, c->alpha);+ break;+ case OP_PART:+ if (tex_get(c->tex, &t))+ blit_part_ex(g_strip, y0, y1, &t, c->x, c->y, c->a & 0xFF, c->a >> 8, c->b & 0xFF, c->b >> 8, c->flags, c->tint, c->alpha);+ break;+ case OP_MASK:+ blit_mask(g_strip, y0, y1, cel_bin + (c->a | (uint32_t)c->b << 16), c->tex & 0xFF, c->tex >> 8, c->x, c->y, c->tint, c->alpha);+ break;+ case OP_SCALED:+ if (tex_get(c->tex, &t)) blit_scaled(g_strip, y0, y1, &t, c->x, c->y, c->flags, c->tint, c->alpha);+ break;+ case OP_AFFINE:+ if (tex_get(c->tex, &t)) blit_affine(g_strip, y0, y1, &t, &affs[c->a], c->tint, c->alpha, c->flags);+ break;+ case OP_RECT: fill(g_strip, y0, y1, c->x, c->y, c->a, c->b, c->tint, c->alpha); break;+ case OP_LINE: line(g_strip, y0, y1, c->x, c->y, (int16_t)c->a, (int16_t)c->b, c->tint, c->alpha); break;+ case OP_CUSTOM: customs[c->a].fn(g_strip, y0, y1, customs[c->a].ctx); break;+ }+ }+}++/* Level.Zoom: the gameplay drawn larger around a point of the screen */+static float zoom = 1, zoom_fx, zoom_fy;+void gfx_zoom(float z, float fx, float fy) { zoom = z, zoom_fx = fx, zoom_fy = fy; }++/* the world's rows [sa, sb) are in the strip: make them rows [y0, y1) seen through the zoom, in place+ * (each pixel comes from nearer the focus, so working away from it never reads one already written) */+static void zoom_strip(int y0, int y1, int sa) {+ float inv = 1 / zoom;+ int n = y1 - y0;+ int16_t src_x[VIEW_W];+ for (int x = 0; x < VIEW_W; x++) {+ int sx = (int)floorf(zoom_fx + (x + 0.5f - zoom_fx) * inv);+ src_x[x] = (int16_t)(sx < 0 ? 0 : sx >= VIEW_W ? VIEW_W - 1 : sx);+ }+ int fx = (int)zoom_fx;+ if (fx < 0) fx = 0;+ if (fx > VIEW_W) fx = VIEW_W;+ for (int r = n - 1; r >= 0; r--) {+ int sy = (int)floorf(zoom_fy + (y0 + r + 0.5f - zoom_fy) * inv) - sa;+ if (sy < 0) sy = 0;+ if (sy > STRIP_H - 1) sy = STRIP_H - 1;+ const uint16_t *src = g_strip + sy * VIEW_W;+ uint16_t *dst = g_strip + r * VIEW_W;+ for (int x = 0; x < fx; x++) dst[x] = src[src_x[x]];+ for (int x = VIEW_W - 1; x >= fx; x--) dst[x] = src[src_x[x]];+ }+}++void gfx_end(void) {+ if (letterbox_dirty) {+ plat_fill(0, 0, SCREEN_W, VIEW_Y, 0);+ plat_fill(0, VIEW_Y + VIEW_H, SCREEN_W, SCREEN_H - VIEW_Y - VIEW_H, 0);+ letterbox_dirty = false;+ }+ ep_pal = 0xFFFF;+ g_res_can_load = false; /* the strip is the LZMA ring: nothing loads while strips are drawn */+ if (zoom > 1.001f) {+ /* 14 rows at a time: the world rows they need (at most 15) first, then enlarged, then the interface */+ for (int y0 = 0; y0 < VIEW_H; y0 += 14) {+ int y1 = y0 + 14 > VIEW_H ? VIEW_H : y0 + 14;+ int sa = (int)floorf(zoom_fy + (y0 + 0.5f - zoom_fy) / zoom);+ int sb = (int)floorf(zoom_fy + (y1 - 0.5f - zoom_fy) / zoom) + 1;+ if (sb > sa + STRIP_H) sb = sa + STRIP_H;+ for (int i = 0; i < VIEW_W * STRIP_H; i++) g_strip[i] = clear_color;+ replay(sa, sb, 0);+ zoom_strip(y0, y1, sa);+ replay(y0, y1, 1);+ plat_push(0, VIEW_Y + y0, VIEW_W, y1 - y0, g_strip);+ }+ } else+ for (int s = 0; s < NSTRIPS; s++) {+ int y0 = s * STRIP_H, y1 = y0 + STRIP_H;+ for (int i = 0; i < VIEW_W * STRIP_H; i++) g_strip[i] = clear_color;+ replay(y0, y1, 2);+ plat_push(0, VIEW_Y + y0, VIEW_W, STRIP_H, g_strip);+ }+ g_res_can_load = true;+ g_res_drawing = false;+}diff --git a/games/celeste/src/heart.c b/games/celeste/src/heart.cnew file mode 100644index 00000000..0300e6d0--- /dev/null+++ b/games/celeste/src/heart.c@@ -0,0 +1,669 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* Crystal hearts: HeartGem, its Poem and the AbsorbOrbs it bursts into.+ * Line by line from the game's code (the fake heart is Farewell's: not here). */+#include "cutscene.h"+#include "text.h"+++/* ---------------------------------------------------------------- AbsorbOrb */+typedef struct {+ V2 a, b, c; /* SimpleCurve: begin, end, control */+ V2 burst_dir, scale;+ float duration, percent, consume_delay, burst_speed, alpha, rot;+ Ent *into;+ uint8_t curve; /* the curve is set (consumeDelay ran out) */+} Orb;++static V2 curve_at(const Orb *o, float t) {+ float u = 1 - t;+ return v2(u * u * o->a.x + 2 * u * t * o->c.x + t * t * o->b.x, u * u * o->a.y + 2 * u * t * o->c.y + t * t * o->b.y);+}+static void orb_scale(Orb *o, float k) {+ o->scale = v2(fminf(2, 0.5f + k * 0.02f), fmaxf(0.05f, 0.5f - k * 0.004f));+}+static void orb_update(Ent *e) {+ Orb *o = ST(e, Orb);+ V2 to = v2(0, 0);+ bool gone;+ if (o->into) {+ to = v2(e_cxm(o->into), e_cym(o->into));+ gone = o->into->dead || (o->into == level_player_ent() && g_player.dead);+ } else {+ Ent *p = level_player_ent();+ if (p) to = player_center(&g_player);+ gone = !p || g_player.dead;+ }+ V2 pos = v2(e->x, e->y);+ if (gone) {+ e->x += o->burst_dir.x * o->burst_speed * RAW_DT, e->y += o->burst_dir.y * o->burst_speed * RAW_DT;+ o->burst_speed = approach(o->burst_speed, 800, RAW_DT * 200);+ o->rot = atan2f(o->burst_dir.y, o->burst_dir.x);+ orb_scale(o, o->burst_speed);+ o->alpha = approach(o->alpha, 0, DT);+ } else if (o->consume_delay > 0) {+ e->x += o->burst_dir.x * o->burst_speed * RAW_DT, e->y += o->burst_dir.y * o->burst_speed * RAW_DT;+ o->burst_speed = approach(o->burst_speed, 0, RAW_DT * 120);+ o->rot = atan2f(o->burst_dir.y, o->burst_dir.x);+ orb_scale(o, o->burst_speed);+ o->consume_delay -= RAW_DT;+ if (o->consume_delay <= 0) {+ pos = v2(e->x, e->y);+ V2 mid = v2((pos.x + to.x) / 2, (pos.y + to.y) / 2);+ V2 n = safe_norm(v2sub(to, pos), 1), perp = v2(n.y, -n.x);+ float len = v2len(v2sub(pos, to)) * (0.05f + rndf() * 0.45f);+ V2 off = v2(perp.x * len, perp.y * len);+ float dx = to.x - pos.x, dy = to.y - pos.y;+ /* (the game compares |dy| with itself: only the first test can pass) */+ if (fabsf(dx) > fabsf(dy) && signf(off.x) != signf(dx)) off = v2(-off.x, -off.y);+ o->a = pos, o->b = to, o->c = v2add(mid, off);+ o->curve = 1;+ o->duration = 0.3f + rndf() * 0.25f;+ }+ } else {+ o->b = to;+ if (o->percent >= 1) {+ ent_remove(e);+ return;+ }+ o->percent = approach(o->percent, 1, RAW_DT / o->duration);+ float t = ease_cube_in(o->percent);+ V2 p = curve_at(o, t);+ e->x = p.x, e->y = p.y;+ float len = 0; /* GetLengthParametric(10) */+ V2 q = o->a;+ for (int i = 1; i <= 10; i++) {+ V2 r = curve_at(o, i / 10.f);+ len += v2len(v2sub(r, q));+ q = r;+ }+ orb_scale(o, (t <= 0.5f ? t * 2 : 1 - (t - 0.5f) * 2) * len);+ o->alpha = 1 - t;+ V2 nx = curve_at(o, ease_cube_in(o->percent + 0.01f));+ o->rot = atan2f(nx.y - e->y, nx.x - e->x);+ }+}+static void orb_render(Ent *e) {+ Orb *o = ST(e, Orb);+ Tex t;+ if (tex_get(T_collectables_heartGem_orb, &t))+ gfx_tex_ex(T_collectables_heartGem_orb, e->x, e->y, t.fw / 2.f, t.fh / 2.f, o->scale.x, o->scale.y, o->rot, 0xFFFF,+ (uint8_t)(o->alpha * 255), 0);+ bloom_add(e->x, e->y, 1, 16);+}+static const EntClass ORB = {.name = "absorbOrb", .size = sizeof(Orb), .update = orb_update, .render = orb_render};++/* new AbsorbOrb(position, into): into the player when NULL */+Ent *absorb_orb_new(V2 at, Ent *into) {+ Ent *e = ent_new(&ORB, at.x, at.y);+ if (!e) return NULL;+ Orb *o = ST(e, Orb);+ e->tags = TAG_FROZEN_UPDATE;+ e->depth = -2000000;+ o->into = into;+ o->consume_delay = 0.7f + rndf() * 0.3f;+ o->burst_speed = 80 + rndf() * 40;+ o->burst_dir = angle_vec(rndf() * PI_F * 2, 1);+ o->alpha = 1;+ orb_scale(o, o->burst_speed);+ return e;+}++void absorb_orbs_remove(void) {+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &ORB) ent_remove(&g_ents[i]);+}++/* ---------------------------------------------------------------- the collection: one at a time */+#define POEM_PARTS 80+typedef struct {+ Co co;+ float t;+ Ent *heart, *poem, *walls[3];+ bool complete;+ uint8_t mode;+ /* Poem */+ float alpha, text_alpha, timer;+ Sprite spr;+ struct { float ang, pct, dur; } parts[POEM_PARTS];+ char text[160];+ TextDraw td[2];+} HeartRam;+#define HR (*(HeartRam *)(void *)g_chram[15])+uint32_t heart_ram(void) { return sizeof(HeartRam); }++/* ---------------------------------------------------------------- Poem */+static void part_reset(int i, float pct) {+ HR.parts[i].ang = rndf() * PI_F * 2;+ HR.parts[i].pct = pct;+ HR.parts[i].dur = 0.5f + rndf() * 0.5f;+}+static void poem_update(Ent *e) {+ (void)e;+ HR.timer += DT;+ for (int i = 0; i < POEM_PARTS; i++) {+ HR.parts[i].pct += DT / HR.parts[i].dur;+ if (HR.parts[i].pct > 1) part_reset(i, 0);+ }+ spr_update(&HR.spr);+}+static void poem_render(Ent *e) {+ (void)e;+ static const uint32_t colors[3] = {0x8cc7fa, 0xff668a, 0xfffc24};+ if (g_level.paused || HR.alpha <= 0) return;+ uint16_t col = rgb(colors[HR.mode]);+ gfx_hud(true);+ Tex t;+ /* the streaks into the heart (OVR "snow", stretched) */+ if (tex_get(T__snow, &t))+ for (int i = 0; i < POEM_PARTS; i++) {+ float n = ease_sine_in(HR.parts[i].pct), r = (1 - n) * 1920 / 6;+ V2 d = angle_vec(HR.parts[i].ang, 1);+ float a = (1 - n) * HR.alpha;+ if (a <= 0.01f) continue;+ gfx_tex_ex(T__snow, 160 + d.x * r, 90 + d.y * r, t.fw * t.scale / 2.f, t.fh * t.scale / 2.f, 1 + n * 2,+ 0.25f * (0.25f + (1 - n) * 0.75f), HR.parts[i].ang + PI_F, col, (uint8_t)(a * 255), 0);+ }+ Sprite s = HR.spr;+ s.alpha = (uint8_t)(s.alpha * HR.alpha);+ spr_draw(&s, 160, 90);+ if (HR.text[0] && HR.text_alpha > 0) {+ float w = text_measure(HR.text) * 1.5f;+ uint8_t a = (uint8_t)(HR.text_alpha * HR.alpha * 255);+ if (tex_get(T__poemside, &t))+ for (int side = -1; side <= 1; side += 2)+ gfx_tex_ex(T__poemside, (960 + side * (w / 2 + 64)) / 6, 90, t.fw * t.scale / 2.f, t.fh * t.scale / 2.f, 1, 1, 0,+ col, a, 0);+ HR.td[0] = (TextDraw){HR.text, 960 + 2, 540 + 2, 0.5f, 0.5f, 1.5f, 0, (uint8_t)(a / 2)};+ HR.td[1] = (TextDraw){HR.text, 960, 540, 0.5f, 0.5f, 1.5f, col, a};+ text_draw(&HR.td[0]);+ text_draw(&HR.td[1]);+ }+ gfx_hud(false);+}+static const EntClass POEM = {.name = "poem", .update = poem_update, .render = poem_render};++/* ---------------------------------------------------------------- HeartGem */+typedef struct {+ Sprite spr;+ Wiggler scale_wig, move_wig;+ float timer;+ int8_t mdx, mdy; /* moveWiggleDir x 127 */+ uint8_t ghost, collected, white, remove_cam;+} Heart;++static void heart_end(Ent *e) { /* EndCutscene */+ g_level.frozen = false;+ g_level.no_retry = false;+ g_level.formation = false;+ g_time_rate = 1;+ if (HR.poem) ent_remove(HR.poem);+ for (int i = 0; i < 3; i++)+ if (HR.walls[i]) ent_remove(HR.walls[i]);+ HR.poem = NULL;+ memset(HR.walls, 0, sizeof HR.walls);+ HR.heart = NULL;+ ent_remove(e);+}++static const EntClass WALL = {.name = "invisibleBarrier", .update = plat_update, .kind = KIND_SOLID};+static Ent *wall_new(float x, float y, float w, float h) { /* InvisibleBarrier */+ Ent *e = ent_new(&WALL, x, y);+ if (!e) return NULL;+ ent_box(e, w, h, 0, 0);+ e->visible = 0;+ e->safe = 1;+ e->tags = TAG_TRANSITION_UPDATE;+ return e;+}++/* CollectRoutine (raw time) */+static void heart_collect_routine(Ent *e) {+ Heart *h = ST(e, Heart);+ Co *c = &HR.co;+ Player *p = &g_player;+ Ent *pe = level_player_ent();+ CO_BEGIN_DT(c, RAW_DT);+ HR.complete = g_session.mode != M_A || g_session.area == 9;+ g_level.no_retry = true;+ if (HR.complete) berries_collect_all();+ {+ const Room *rm = g_level.room;+ HR.walls[0] = wall_new(rm->x + rm->w, rm->y, 8, rm->h);+ HR.walls[1] = wall_new(rm->x - 8, rm->y, 8, rm->h);+ HR.walls[2] = wall_new(rm->x, rm->y - 8, rm->w, 8);+ }+ h->white = 1;+ e->depth = -2000000;+ CO_YIELD(c);+ level_freeze(0.2f);+ CO_YIELD(c);+ g_time_rate = 0.5f;+ if (pe) pe->depth = -2000000;+ for (int i = 0; i < 10; i++) absorb_orb_new(v2(e->x, e->y), NULL);+ level_shake(0.3f);+ level_flash(0xFFFF, false);+ g_level.formation = true;+ g_level.formation_alpha = 1;+ e->visible = 0;+ for (HR.t = 0; HR.t < 2; HR.t += RAW_DT) {+ g_time_rate = approach(g_time_rate, 0, RAW_DT * 0.25f);+ CO_YIELD(c);+ }+ CO_YIELD(c);+ if (p->dead) CO_WAIT(c, 100);+ g_time_rate = 1;+ e->tags = TAG_FROZEN_UPDATE;+ g_level.frozen = true;+ /* RegisterAsCollected */+ g_session.heart = 1;+ g_session.dashes_at_level_start = g_session.dashes;+ {+ int before = save_unlocked_modes();+ save_register_heart();+ if (before < 3 && save_unlocked_modes() >= 3) g_session.unlocked_cside = 1;+ }+ if (HR.complete) {+ g_level.timer_stopped = true;+ level_register_complete();+ }+ /* the Poem */+ {+ static const char *const ids[10][3] = {+ {0}, {"fc", "fcr", "fcz"}, {"os", "osr", "osz"}, {"cr", "crr", "crz"}, {"cs", "csr", "csz"},+ {"t", "tr", "tz"}, {"tf", "tfr", "tfz"}, {"ts", "tsr", "tsz"}, {0}, {"mc", "mcr", "mcz"}};+ const char *id = g_session.area < 10 ? ids[g_session.area][g_session.mode] : NULL;+ HR.text[0] = 0;+ if (id) {+ char key[16] = "poem_";+ strcat(key, id);+ dialog_clean(key, HR.text, sizeof HR.text);+ text_auto_newline(HR.text, sizeof HR.text, 1024);+ }+ HR.mode = (uint8_t)g_session.mode;+ HR.alpha = 0;+ HR.text_alpha = 1;+ spr_init(&HR.spr, SB_gui_heartgem0 + HR.mode);+ spr_play(&HR.spr, A_gui_heartgem0_spin, true);+ HR.spr.alpha = (uint8_t)((g_session.mode == M_C ? 1 : 0.6f) * 255);+ for (int i = 0; i < POEM_PARTS; i++) part_reset(i, rndf());+ HR.poem = ent_new(&POEM, 0, 0);+ if (HR.poem) HR.poem->tags = TAG_HUD | TAG_FROZEN_UPDATE;+ }+ for (HR.t = 0; HR.t < 1; HR.t += RAW_DT) {+ HR.alpha = ease_cube_out(HR.t);+ CO_YIELD(c);+ }+ while (!btn_pressed(&g_in.confirm) && !btn_pressed(&g_in.back)) CO_YIELD(c);+ if (!HR.complete) {+ g_level.formation = false;+ for (HR.t = 0; HR.t < 1; HR.t += RAW_DT * 2) {+ HR.alpha = ease_cube_in(1 - HR.t);+ CO_YIELD(c);+ }+ if (pe) pe->depth = 0;+ heart_end(e);+ return;+ }+ wipe_start(WIPE_FADE, false, NULL);+ g_wipe.duration = 3.25f;+ CO_WAIT(c, 3.25f);+ level_complete_area(false, true);+ CO_END(c);+}++static void heart_update(Ent *e) {+ Heart *h = ST(e, Heart);+ h->timer += DT;+ /* sprite.Position: the bob and the bounce */+ if (h->collected && (!level_player_ent() || g_player.dead) && HR.heart == e) {+ heart_end(e);+ return;+ }+ int before = h->spr.frame;+ spr_update(&h->spr);+ if (h->spr.frame < before && h->spr.anim == A_heartgem0_spin && e->visible) wiggler_restart(&h->scale_wig); /* OnLoop */+ wiggler_update(&h->scale_wig);+ h->spr.sx = h->spr.sy = 1 + h->scale_wig.value * 0.25f;+ if (h->collected && HR.heart == e) heart_collect_routine(e);+ if (e->dead) return;+ wiggler_update(&h->move_wig);+ if (!h->collected && level_on_interval(0.1f)) {+ static const PType *const shine[3] = {&P_HeartGem_P_BlueShine, &P_HeartGem_P_RedShine, &P_HeartGem_P_GoldShine};+ particles_emit(PL_MID, shine[g_session.mode % 3], 1, v2(e->x, e->y), v2(8, 8), 0);+ }+}++static void heart_collect(Ent *e) {+ Heart *h = ST(e, Heart);+ memset(&HR.co, 0, sizeof HR.co);+ HR.heart = e;+ h->collected = 1;+ if (h->remove_cam) level_remove_camera_offset_triggers();+}++static void heart_on_player(Ent *e, Player *p) {+ Heart *h = ST(e, Heart);+ if (h->collected || g_level.frozen) return;+ if (player_dash_attacking(p)) {+ heart_collect(e);+ return;+ }+ player_point_bounce(p, v2(e->x, e->y));+ wiggler_restart(&h->move_wig);+ wiggler_restart(&h->scale_wig);+ V2 d = safe_norm(v2sub(v2(e->x, e->y), player_center(p)), 1);+ if (d.x == 0 && d.y == 0) d = v2(0, 1);+ h->mdx = (int8_t)(d.x * 127), h->mdy = (int8_t)(d.y * 127);+}++static void heart_render(Ent *e) {+ Heart *h = ST(e, Heart);+ float m = h->move_wig.value * -8 / 127.f;+ float x = e->x + h->mdx * m, y = e->y + sinf(h->timer * 2) * 2 + h->mdy * m;+ spr_draw(&h->spr, x, y);+ if (h->white) {+ Sprite w = h->spr;+ w.bank = SB_heartGemWhite;+ spr_draw(&w, x, y);+ }+ if (!h->collected) {+ static const uint32_t light[3] = {0x7FFFFF, 0xFF7F7F, 0xFFEB7F};+ light_add(e->x, e->y, light[g_session.mode % 3], 1, 32, 64);+ bloom_add(e->x, e->y, 0.75f, 16);+ }+}++static const EntClass HEART = {.name = "blackGem", .size = sizeof(Heart), .update = heart_update, .render = heart_render,+ .on_player = heart_on_player, .kind = KIND_PCOLLIDE};++/* new HeartGem(position) */+Ent *heart_spawn(V2 at) {+ Ent *e = ent_new(&HEART, at.x, at.y);+ if (!e) return NULL;+ Heart *h = ST(e, Heart);+ /* Awake */+ h->ghost = (save_mode()->flags & MS_HEART) != 0;+ static const uint8_t banks[3] = {SB_heartgem0, SB_heartgem1, SB_heartgem2};+ spr_init(&h->spr, h->ghost ? SB_heartGemGhost : banks[g_session.mode % 3]);+ spr_play(&h->spr, h->ghost ? A_heartGemGhost_spin : A_heartgem0_spin, true);+ if (h->ghost) h->spr.alpha = 204;+ ent_box(e, 16, 16, -8, -8);+ wiggler_init(&h->scale_wig, 0.5f, 4);+ wiggler_init(&h->move_wig, 0.8f, 2);+ h->move_wig.start_zero = true;+ return e;+}+static bool heart_new(const EData *d) {+ Ent *e = heart_spawn(v2(d->x, d->y));+ if (e) ST(e, Heart)->remove_cam = EAB(d, blackGem, removeCameraTriggers);+ return true;+}++/* ---------------------------------------------------------------- ForsakenCitySatellite */+enum { C_U, C_L, C_DR, C_UR, C_UL, NCODES };+static const uint32_t CODE_COLORS[NCODES] = {0xf0f0f0, 0x9171f2, 0x0a44e0, 0xb32d00, 0xffcd37};+static const uint8_t CODE[6] = {C_U, C_L, C_DR, C_UR, C_L, C_UL};+static const int8_t CODE_DIR[NCODES][2] = {{0, -1}, {-1, 0}, {1, 1}, {1, -1}, {-1, -1}};++typedef struct { /* CodeBird */+ Co co;+ V2 speed, origin, target, from, to;+ float timer, reset, t, duration, heart_scale, sx, anim;+ uint16_t color, color_from;+ uint8_t code, routine, frame; /* routine: aimless, dash, transform */+} Bird;+static void bird_render(Ent *e) {+ Bird *b = ST(e, Bird);+ Tex t;+ uint16_t tex = (uint16_t)(T_scenery_flutterbird_flap00 + b->frame);+ float y = e->y + sinf(b->timer * 2);+ if (tex_get(tex, &t))+ gfx_tex_ex(tex, e->x, y, t.fw / 2.f, t.fh / 2.f, b->sx, fabsf(b->sx) > 0 ? 1 - b->heart_scale : 1, 0, b->color, 255, 0);+ if (b->heart_scale > 0 && tex_get(T_collectables_heartGem_shape, &t))+ gfx_tex_ex(T_collectables_heartGem_shape, e->x, e->y, t.fw / 2.f, t.fh / 2.f, b->heart_scale, b->heart_scale, 0, 0xFFFF,+ 255, 0);+}+static void bird_aim(Ent *e, Bird *b, V2 d) {+ if (signf(d.x) != 0) b->sx = signf(d.x) * (b->routine == 2 ? 1 - b->heart_scale : 1);+}+static void bird_routine(Ent *e) {+ Bird *b = ST(e, Bird);+ Co *c = &b->co;+ CO_BEGIN(c);+ if (b->routine == 1) goto dash;+ if (b->routine == 2) goto transform;+ /* AimlessFlightRoutine */+ b->speed = v2(0, 0);+ for (;;) {+ b->target = v2add(b->origin, angle_vec(rndf() * PI_F * 2, 16 + rndf() * 40));+ for (b->reset = 0; b->reset < 1;) {+ if (v2len(v2sub(b->target, v2(e->x, e->y))) <= 8) break;+ V2 d = safe_norm(v2sub(b->target, v2(e->x, e->y)), 1);+ b->speed = v2add(b->speed, v2mul(d, 420 * DT));+ if (v2len(b->speed) > 90) b->speed = safe_norm(b->speed, 90);+ e->x += b->speed.x * DT, e->y += b->speed.y * DT;+ b->reset += DT;+ bird_aim(e, b, d);+ CO_YIELD(c);+ }+ }+dash: /* DashRoutine */+ for (b->t = 0.25f; b->t > 0; b->t -= DT) {+ b->speed = approach_v(b->speed, v2(0, 0), 200 * DT);+ e->x += b->speed.x * DT, e->y += b->speed.y * DT;+ CO_YIELD(c);+ }+ {+ V2 dash = safe_norm(v2(CODE_DIR[b->code][0], CODE_DIR[b->code][1]), 1);+ b->from = v2(e->x, e->y);+ b->to = v2add(b->origin, v2mul(dash, 8));+ if (signf(b->to.x - b->from.x) != 0) b->sx = signf(b->to.x - b->from.x);+ }+ for (b->t = 0; b->t < 1; b->t += DT * 1.5f) {+ float k = ease_cube_inout(b->t);+ e->x = b->from.x + (b->to.x - b->from.x) * k, e->y = b->from.y + (b->to.y - b->from.y) * k;+ CO_YIELD(c);+ }+ e->x = b->to.x, e->y = b->to.y;+ CO_WAIT(c, 0.2f);+ {+ V2 dash = safe_norm(v2(CODE_DIR[b->code][0], CODE_DIR[b->code][1]), 1);+ if (dash.x != 0) b->sx = signf(dash.x);+ b->speed = v2mul(dash, 300);+ }+ for (b->t = 0.4f; b->t > 0; b->t -= DT) {+ V2 dash = safe_norm(v2(CODE_DIR[b->code][0], CODE_DIR[b->code][1]), 1);+ if (b->t > 0.1f && level_on_interval(0.02f))+ particles_emit_c(PL_BG, &P_Player_P_DashA, 1, v2(e->x, e->y), v2(2, 2), CODE_COLORS[b->code] | 0xFF000000u,+ atan2f(dash.y, dash.x));+ b->speed = approach_v(b->speed, v2(0, 0), 800 * DT);+ e->x += b->speed.x * DT, e->y += b->speed.y * DT;+ CO_YIELD(c);+ }+ CO_WAIT(c, 0.4f);+ b->routine = 0;+ b->co = (Co){0};+ return;+transform: /* TransformRoutine */+ b->color_from = b->color;+ for (b->t = 0; b->t < 1; b->t += DT / b->duration) {+ V2 d = safe_norm(v2sub(b->origin, v2(e->x, e->y)), 1);+ b->speed = v2add(b->speed, v2mul(d, 400 * DT));+ float mx = fmaxf(20, (1 - b->t) * 200);+ if (v2len(b->speed) > mx) b->speed = safe_norm(b->speed, mx);+ e->x += b->speed.x * DT, e->y += b->speed.y * DT;+ b->color = blend565(b->color_from, 0xFFFF, (int)(b->t * 256));+ b->heart_scale = fmaxf(0, (b->t - 0.75f) * 4);+ if (d.x != 0) b->sx = fabsf(b->sx) * signf(d.x);+ b->sx = signf(b->sx) * (1 - b->heart_scale);+ CO_YIELD(c);+ }+ CO_END(c);+}+static void bird_update(Ent *e) {+ Bird *b = ST(e, Bird);+ b->timer += DT;+ if ((b->anim += DT) >= 0.08f) b->anim -= 0.08f, b->frame ^= 1; /* "flap" */+ bird_routine(e);+}+static const EntClass CODEBIRD = {.name = "codeBird", .size = sizeof(Bird), .update = bird_update, .render = bird_render};++typedef struct {+ Co co, pulse_co;+ V2 bird_at, gem_at;+ float t, bloom, noise_t;+ Ent *gem;+ uint16_t pulse_color;+ uint8_t enabled, pulse_on, inputs[6], ninputs, i, unlocking, noise, birds[NCODES], order[NCODES];+} Sat;++static void sat_unlock(Ent *e) { /* UnlockGem */+ Sat *s = ST(e, Sat);+ Co *c = &s->co;+ CO_BEGIN(c);+ level_set_flag("unlocked_satellite", true);+ s->enabled = 0;+ CO_WAIT(c, 0.25f);+ CO_YIELD(c);+ g_level.frozen = true;+ e->tags = TAG_FROZEN_UPDATE;+ s->bloom = 0;+ for (int i = 0; i < NCODES; i++) {+ Ent *b = &g_ents[s->birds[i]];+ if (b->cls != &CODEBIRD) continue;+ Bird *bd = ST(b, Bird);+ b->tags = TAG_FROZEN_UPDATE;+ bd->routine = 2, bd->duration = 3, bd->co = (Co){0};+ }+ while (s->bloom < 1) {+ s->bloom += DT / 3;+ CO_YIELD(c);+ }+ CO_WAIT(c, 0.25f);+ for (int i = 0; i < NCODES; i++)+ if (g_ents[s->birds[i]].cls == &CODEBIRD) ent_remove(&g_ents[s->birds[i]]);+ particles_emit(PL_FG, &P_BirdNPC_P_Feather, 24, s->bird_at, v2(4, 4), 0);+ s->gem = heart_spawn(s->bird_at);+ if (s->gem) s->gem->tags = TAG_FROZEN_UPDATE;+ CO_YIELD(c);+ if (s->gem) wiggler_restart(&ST(s->gem, Heart)->scale_wig);+ CO_WAIT(c, 0.85f);+ for (s->t = 0; s->t < 1; s->t += DT) {+ CO_YIELD(c);+ if (s->gem) { /* SimpleCurve from where it was to its spot, 64 above the middle */+ V2 a = s->bird_at, b = s->gem_at, m = v2((a.x + b.x) / 2, (a.y + b.y) / 2 - 64);+ float k = ease_cube_inout(s->t), u = 1 - k;+ s->gem->x = u * u * a.x + 2 * u * k * m.x + k * k * b.x;+ s->gem->y = u * u * a.y + 2 * u * k * m.y + k * k * b.y;+ }+ }+ CO_WAIT(c, 0.5f);+ s->bloom = 0;+ g_level.frozen = false;+ s->unlocking = 0;+ CO_END(c);+}++static void sat_pulse(Ent *e) { /* PulseRoutine */+ Sat *s = ST(e, Sat);+ Co *c = &s->pulse_co;+ CO_BEGIN(c);+ s->pulse_on = 0;+ while (s->enabled) {+ CO_WAIT(c, 2);+ for (s->i = 0; s->i < 6 && s->enabled; s->i++) {+ s->pulse_color = rgb(CODE_COLORS[CODE[s->i]]);+ s->pulse_on = 1;+ CO_WAIT(c, 0.5f);+ s->pulse_on = 0;+ CO_WAIT(c, 0.2f);+ }+ {+ uint8_t order[NCODES]; /* birds.Shuffle() */+ for (int i = 0; i < NCODES; i++) order[i] = (uint8_t)i;+ for (int i = NCODES - 1; i > 0; i--) {+ int j = rndi(i + 1);+ uint8_t t = order[i];+ order[i] = order[j], order[j] = t;+ }+ memcpy(s->order, order, NCODES);+ }+ for (s->i = 0; s->i < NCODES && s->enabled; s->i++) {+ Ent *b = &g_ents[s->birds[s->order[s->i]]];+ if (b->cls == &CODEBIRD) ST(b, Bird)->routine = 1, ST(b, Bird)->co = (Co){0};+ CO_WAIT(c, 0.02f);+ }+ }+ s->pulse_on = 0;+ CO_END(c);+}++static void sat_update(Ent *e) {+ Sat *s = ST(e, Sat);+ if (s->pulse_co.co != -1) sat_pulse(e);+ if (s->unlocking) {+ sat_unlock(e);+ if (g_level.frozen) particles_update(); /* (the feathers' own system updates while frozen) */+ }+ if ((s->noise_t += DT) >= 0.05f) s->noise_t -= 0.05f, s->noise = (uint8_t)((s->noise + 1) % 3); /* "static" */+}+static void sat_on_dash(Ent *e, V2 dir) {+ Sat *s = ST(e, Sat);+ int code = dir.y < 0 ? (dir.x < 0 ? C_UL : dir.x > 0 ? C_UR : C_U) : dir.y > 0 ? (dir.x > 0 ? C_DR : 255) : dir.x < 0 ? C_L : 255;+ if (s->unlocking) return;+ /* currentInputs: the last six */+ if (s->ninputs == 6) memmove(s->inputs, s->inputs + 1, 5), s->ninputs = 5;+ s->inputs[s->ninputs++] = (uint8_t)code;+ if (s->ninputs == 6 && !memcmp(s->inputs, CODE, 6) && g_level.cam.x + 32 < s->gem_at.x && s->enabled) {+ s->unlocking = 1;+ s->co = (Co){0};+ }+}+static void sat_render(Ent *e) {+ Sat *s = ST(e, Sat);+ Tex t;+ if (tex_get(T_objects_citysatellite_dish, &t)) gfx_tex(T_objects_citysatellite_dish, e->x - t.fw / 2.f, e->y - t.fh, 0, 0xFFFF, 255);+ if (s->pulse_on && tex_get(T_objects_citysatellite_light, &t))+ gfx_tex(T_objects_citysatellite_light, e->x - t.fw / 2.f, e->y - t.fh, 0, s->pulse_color, 255);+ gfx_tex(T_objects_citysatellite_computer, e->x + 8, e->y + 8, 0, 0xFFFF, 255);+ if (s->pulse_on) gfx_tex(T_objects_citysatellite_computerscreen, e->x + 8, e->y + 8, 0, s->pulse_color, 255);+ else gfx_tex((uint16_t)(T_objects_citysatellite_computerScreenNoise00 + s->noise), e->x + 8, e->y + 8, 0, 0xFFFF, 255);+ gfx_tex(T_objects_citysatellite_computerscreenShine, e->x + 8, e->y + 8, 0, 0xFFFF, 255);+ if (s->pulse_on) bloom_add(e->x - 12, e->y - 44, 1, 8), bloom_add(e->x + 32, e->y + 20, 1, 8);+ if (s->bloom > 0) bloom_add(s->bird_at.x, s->bird_at.y, s->bloom, 32);+}+static const EntClass SATELLITE = {.name = "birdForsakenCityGem", .size = sizeof(Sat), .update = sat_update,+ .render = sat_render, .on_dash = sat_on_dash};++static bool sat_new(const EData *d) {+ Ent *e = ent_new(&SATELLITE, d->x, d->y);+ if (!e) return true;+ Sat *s = ST(e, Sat);+ e->depth = 8999;+ s->bird_at = ed_node(d, 0), s->gem_at = ed_node(d, 1);+ /* Added */+ bool unlocked = level_get_flag("unlocked_satellite");+ s->enabled = !g_session.heart && !unlocked;+ if (s->enabled)+ for (int i = 0; i < NCODES; i++) {+ Ent *b = ent_new(&CODEBIRD, s->bird_at.x, s->bird_at.y);+ if (!b) continue;+ Bird *bd = ST(b, Bird);+ bd->code = (uint8_t)i;+ bd->origin = s->bird_at;+ bd->timer = rndf();+ bd->color = rgb(CODE_COLORS[i]);+ bd->sx = 1;+ s->birds[i] = (uint8_t)(b - g_ents);+ }+ if (!g_session.heart && unlocked) heart_spawn(s->gem_at);+ return true;+}++bool heart_create(const EData *d) {+ if (d->type == ET_blackGem) return heart_new(d);+ if (d->type == ET_birdForsakenCityGem) return sat_new(d);+ return false;+}diff --git a/games/celeste/src/icon.png b/games/celeste/src/icon.pngnew file mode 100644index 00000000..3a49a8abBinary files /dev/null and b/games/celeste/src/icon.png differdiff --git a/games/celeste/src/level.c b/games/celeste/src/level.cnew file mode 100644index 00000000..0c667abc--- /dev/null+++ b/games/celeste/src/level.c@@ -0,0 +1,746 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* The level: loading rooms out of data.bin, the camera, room transitions,+ * death and respawn. Follows Celeste's Level and LevelLoader. */+#include "level.h"+#include "player.h"+#include "fx.h"+#include "wipe.h"+#include "entities.h"++Level g_level;++/* ---------------------------------------------------------------- chapter data */+static const uint8_t *chapter_rec(int c) {+ const uint8_t *s = section(SEC_CHAPTERS);+ return s + rd32(s + 4 + 4 * c);+}+static const uint8_t *room_rec(int i) {+ const uint8_t *c = g_level.ch;+ return c + rd32(c + CH_ROOMS + 4 * i);+}+/* room record: u16 name, u16 pack, u32 off, u32 size, s32 x, s32 y, u16 w, u16 h, u8 flags, u8 wind,+ * s8 camx, s8 camy, u32 style mask lo, hi, u16 music, u8 enforce dashes, u8 pad, u16 nneed, u16 need[] */+#define RR_NAME 0+#define RR_PACK 2+#define RR_OFF 4+#define RR_SIZE 8+#define RR_X 12+#define RR_Y 16+#define RR_W 20+#define RR_H 22+#define RR_FLAGS 24+#define RR_WIND 25+#define RR_CAMX 26+#define RR_CAMY 27+#define RR_STYLE 28++int chapter_find_room(int chapter, const char *name) {+ const uint8_t *c = chapter_rec(chapter);+ for (int i = 0; i < rd16(c + 2); i++)+ if (!strcmp(str(rd16(c + rd32(c + CH_ROOMS + 4 * i) + RR_NAME)), name)) return i;+ return -1;+}+const char *chapter_room_name(int chapter, int i) { /* NULL past its last room */+ const uint8_t *c = chapter_rec(chapter);+ return i < rd16(c + 2) ? str(rd16(c + rd32(c + CH_ROOMS + 4 * i) + RR_NAME)) : NULL;+}+const char *level_room_name_of(int index) { return str(rd16(room_rec(index) + RR_NAME)); }+const char *level_room_name(void) { return g_level.room && g_level.room->info ? str(rd16(g_level.room->info)) : ""; }++/* ---------------------------------------------------------------- loading a room */+typedef struct { uint8_t *dst; uint32_t n, cap; } Copy;+static void copy_sink(const uint8_t *p, uint32_t n, void *ctx) {+ Copy *c = ctx;+ if (c->n + n > c->cap) n = c->cap > c->n ? c->cap - c->n : 0;+ memcpy(c->dst + c->n, p, n);+ c->n += n;+}++/* decodes a room's blob into scratch RAM; NULL if it does not fit */+static const uint8_t *room_blob(int index, uint32_t *size) {+ const uint8_t *r = room_rec(index);+ uint32_t cap;+ uint32_t n = rd32(r + RR_SIZE);+ uint8_t *scratch = res_scratch(n, &cap);+ if (n > cap) return NULL;+ Copy c = {scratch, 0, cap};+ res_stream(rd16(r + RR_PACK), rd32(r + RR_OFF), n, copy_sink, &c);+ *size = n;+ return scratch;+}++/* both loaded rooms live in one pool: slot 0 from the start, slot 1 from the end */+static uint32_t room_pool[ROOM_POOL_BYTES / 4];++static void setup_layer(TileLayer *L, const uint8_t *p, int th) {+ L->bits = p[1];+ L->types = p + 2;+ const uint8_t *rows = p + ((2 + p[0] + 1) & ~1);+ L->rows = (const uint16_t *)(const void *)rows;+ L->data = rows + 2 * th;+}++/* a tile layer as stored (its rows one after another) -> as kept (row offsets, each different row once) */+static void tiles_unpack(uint8_t *dst, const uint8_t *src, int tw, int th) {+ int nt = src[0], bits = src[1], mask = (1 << bits) - 1;+ memcpy(dst, src, 2u + nt);+ uint16_t *rows = (uint16_t *)(void *)(dst + ((2 + nt + 1) & ~1));+ uint8_t *data = (uint8_t *)(rows + th);+ const uint8_t *p = src + 2 + nt;+ uint32_t n = 0;+ for (int y = 0; y < th; y++) {+ int len = 0;+ for (int x = 0; x < tw; len++) x += (p[len] & mask) + 1;+ int j = 0;+ for (; j < y; j++) { /* the same row as one before? */+ const uint8_t *q = data + rows[j];+ int k = 0;+ while (k < len && q[k] == p[k]) k++;+ if (k == len) break;+ }+ if (j < y) rows[y] = rows[j];+ else {+ rows[y] = (uint16_t)n;+ memcpy(data + n, p, (size_t)len);+ n += (uint32_t)len;+ }+ p += len;+ }+}++static bool room_load(int slot, int index) {+ Room *rm = &g_level.rooms[slot];+ rm->index = -1;+ uint32_t size;+ const uint8_t *blob = room_blob(index, &size);+ if (!blob) return false;+ const uint8_t *r = room_rec(index);+ /* what stays: everything before the entities (the tiles unpacked: what follows them moves by `shift`),+ * and a bit per spinner */+ uint32_t nspin = rd16(blob + rd16(blob + 2 * RB_SPIN));+ int shift = (int16_t)rd16(blob + 2 * RB_SHIFT);+ uint32_t from = rd16(blob + 2 * RB_EXTRAS), keep = rd16(blob + 2 * RB_ENTS) + shift;+ uint32_t need = keep + (((nspin + 7) / 8 + 3) & ~3u);+ const Room *other = &g_level.rooms[slot ^ 1];+ uint8_t *pool = (uint8_t *)room_pool, *mem;+ if (slot == 0) {+ uint32_t free = other->index >= 0 ? (uint32_t)(other->mem - pool) : ROOM_POOL_BYTES;+ if (need > free) return false;+ mem = pool;+ } else {+ uint32_t free = ROOM_POOL_BYTES - (other->index >= 0 ? other->used : 0);+ if (need > free) return false;+ mem = pool + ROOM_POOL_BYTES - need;+ }+ rm->mem = mem;+ rm->used = need;+ rm->info = r;+ rm->x = rds32(r + RR_X), rm->y = rds32(r + RR_Y), rm->w = rd16(r + RR_W), rm->h = rd16(r + RR_H);+ rm->tx = rm->x / 8 - MARGIN, rm->ty = rm->y / 8 - MARGIN;+ rm->tw = rm->w / 8 + 2 * MARGIN, rm->th = rm->h / 8 + 2 * MARGIN;+ uint16_t *hdr = (uint16_t *)(void *)mem;+ memcpy(hdr, blob, 2 * RB_HEADER);+ hdr[RB_BG] = hdr[RB_BG_RAM];+ for (int k = RB_EXTRAS; k <= RB_END; k++) hdr[k] = (uint16_t)(hdr[k] + shift);+ tiles_unpack(mem + hdr[RB_FG], blob + rd16(blob + 2 * RB_FG), rm->tw, rm->th);+ tiles_unpack(mem + hdr[RB_BG], blob + rd16(blob + 2 * RB_BG), rm->tw, rm->th);+ memcpy(mem + hdr[RB_EXTRAS], blob + from, keep - hdr[RB_EXTRAS]);+ setup_layer(&rm->layer[0], mem + rd16(mem + 2 * RB_FG), rm->th);+ setup_layer(&rm->layer[1], mem + rd16(mem + 2 * RB_BG), rm->th);+ /* extras: objtiles, then scenery over fg and bg */+ uint8_t *o = mem + rd16(mem + 2 * RB_EXTRAS);+ rm->nobj = rd16(o);+ rm->obj = o + 2;+ o += 2 + rm->nobj * 6u;+ for (int k = 0; k < 2; k++) {+ rm->nscen[k] = rd16(o);+ rm->scen[k] = o + 2;+ o += 2 + rm->nscen[k] * 6u;+ }+ /* decals: u16 count, then (u16 tex | flips, s16 x, s16 y) */+ uint8_t *d = mem + rd16(mem + 2 * RB_DFG);+ rm->nfg = rd16(d);+ rm->decals_fg = d + 2; /* u8 textures, u16 ids, then 5-byte records */+ d = mem + rd16(mem + 2 * RB_DBG);+ rm->nbg = rd16(d);+ rm->decals_bg = d + 2;+ /* spinners */+ const uint8_t *sp = mem + rd16(mem + 2 * RB_SPIN);+ rm->nspin = (int)nspin;+ rm->spin_row0 = rds16(sp + 2);+ rm->spin_rows = rd16(sp + 4);+ rm->spin_first = (const uint16_t *)(const void *)(sp + 6);+ rm->spin = rm->spin_first + rm->spin_rows + 1;+ rm->spin_mask = (const uint8_t *)(rm->spin + nspin);+ { /* Level.LoadLevel: the Celestial Resort's spinners, and the Summit's d- rooms', are dust */+ const char *nm = str(rd16(room_rec(index) + RR_NAME));+ bool dusty = g_session.area == 3 || (g_session.area == 7 && nm[0] == 'd' && nm[1] == '-');+ rm->spin_dust = dusty ? rm->spin_mask + (nspin + 1) / 2 : NULL;+ }+ rm->spin_gone = mem + keep;+ rm->need = mem + rd16(mem + 2 * RB_NEED);+ memset(rm->spin_gone, 0, (nspin + 7) / 8);+ rm->index = index;+ /* entities and triggers */+ int was = g_level.room_slot;+ g_level.room_slot = slot;+ g_res_can_load = false; /* the room's data is in the cache's free space */+ g_level.has_cassette_blocks = false, g_level.cassette_beats = 2;+ g_level.cam_lock = 0, g_level.cam_locker = NULL; /* Level.LoadLevel: CameraLockMode = None */+ entities_load(rm, blob, slot);+ g_res_can_load = true;+ g_level.room_slot = was;+ return true;+}++/* textures beyond the rooms' (a textbox's portrait) */+static const uint16_t *extra_tex;+static int nextra_tex;+static void need_textures(void) {+ res_begin_need();+ for (int s = 0; s < 2; s++) {+ Room *rm = &g_level.rooms[s];+ if (rm->index >= 0) res_need_list(rm->need + 2, rd16(rm->need));+ }+ for (int i = 0; i < nextra_tex; i++) res_need(extra_tex[i]);+ res_load_needed();+ tiles_invalidate();+}+void level_extra_textures(const uint16_t *ids, int n) {+ extra_tex = ids, nextra_tex = n;+ need_textures();+}++/* ---------------------------------------------------------------- tiles of the room */+static char rle_at(const Room *rm, int layer, int cx, int cy) {+ int lx = cx - rm->tx, ly = cy - rm->ty;+ if (lx < 0 || ly < 0 || lx >= rm->tw || ly >= rm->th) return '0';+ const TileLayer *L = &rm->layer[layer];+ const uint8_t *p = L->data + L->rows[ly];+ int bits = L->bits, mask = (1 << bits) - 1;+ for (;; p++) {+ int n = (*p & mask) + 1;+ if (lx < n) return (char)L->types[*p >> bits];+ lx -= n;+ }+}++char level_tile_type(int layer, int cx, int cy) {+ Room *rm = g_level.room;+ if (!rm) return '0';+ char c = rle_at(rm, layer, cx, cy);+ if (g_level.transitioning) {+ Room *o = &g_level.rooms[g_level.room_slot ^ 1];+ if (o->index >= 0) {+ int px = cx * 8, py = cy * 8;+ bool in_cur = px >= rm->x && px < rm->x + rm->w && py >= rm->y && py < rm->y + rm->h;+ if (!in_cur && px >= o->x && px < o->x + o->w && py >= o->y && py < o->y + o->h) c = rle_at(o, layer, cx, cy);+ }+ }+ return c;+}++/* any solid tile in the cells [cx0, cx1] x [cy0, cy1] (inclusive) */+bool level_solid_cells(int cx0, int cy0, int cx1, int cy1) {+ Room *rm = g_level.room;+ if (!rm) return false;+ const TileLayer *L = &rm->layer[0];+ int bits = L->bits, mask = (1 << bits) - 1;+ for (int cy = cy0; cy <= cy1; cy++) {+ int ly = cy - rm->ty;+ if (ly < 0 || ly >= rm->th) continue;+ const uint8_t *p = L->data + L->rows[ly];+ for (int x = rm->tx, end = rm->tx + rm->tw; x < end && x <= cx1; p++) {+ int x2 = x + (*p & mask) + 1;+ if (L->types[*p >> bits] != '0' && x2 > cx0) return true;+ x = x2;+ }+ }+ return false;+}++bool level_grid_collide(const Ent *grid, float l, float t, float r, float b) {+ (void)grid, (void)l, (void)t, (void)r, (void)b;+ return false;+}++/* ---------------------------------------------------------------- flags and ids */+static uint32_t hash_str(const char *s) {+ uint32_t h = 2166136261u;+ while (*s) h = (h ^ (uint8_t)*s++) * 16777619u;+ return h;+}+void level_set_flag(const char *flag, bool on) {+ Session *ss = &g_session;+ uint32_t h = hash_str(flag);+ for (int i = 0; i < ss->nflags; i++)+ if (ss->flags[i] == h) {+ if (!on) ss->flags[i] = ss->flags[--ss->nflags];+ return;+ }+ if (on && ss->nflags < 32) ss->flags[ss->nflags++] = h;+}+bool level_get_flag(const char *flag) {+ uint32_t h = hash_str(flag);+ for (int i = 0; i < g_session.nflags; i++)+ if (g_session.flags[i] == h) return true;+ return false;+}+uint32_t level_entity_id(int room, int eid) { return (uint32_t)room << 16 | (uint16_t)eid; }+bool level_do_not_load(uint32_t id) {+ for (int i = 0; i < g_session.ndnl; i++)+ if (g_session.dnl[i] == id) return true;+ return false;+}+void level_set_do_not_load(uint32_t id) {+ if (!level_do_not_load(id) && g_session.ndnl < 32) g_session.dnl[g_session.ndnl++] = id;+}++/* ---------------------------------------------------------------- the player */+static Player *player_of(void) { return g_player.ent && g_player.ent->cls ? &g_player : NULL; }+Ent *level_player_ent(void) { return player_of() ? g_player.ent : NULL; }+Player *level_player(void) { return player_of(); }+float level_player_speed_x(void) { return g_player.speed.x; }+bool level_player_climbing(void) { return g_player.state == ST_CLIMB; }+int level_player_facing(void) { return g_player.facing; }++/* ---------------------------------------------------------------- time */+bool level_on_interval(float interval) {+ return floorf((g_level.time_active - DT) / interval) < floorf(g_level.time_active / interval);+}+bool level_on_raw_interval(float interval) {+ return floorf((g_level.raw_time_active - DT) / interval) < floorf(g_level.raw_time_active / interval);+}+void level_shake(float t) {+ if (g_save.options & 1) return; /* Settings: Screen Shake Effects off */+ g_level.shake_dir = v2(0, 0);+ g_level.shake_timer = fmaxf(g_level.shake_timer, t);+}+void level_dir_shake(V2 dir, float t) {+ if (g_save.options & 1) return;+ g_level.shake_dir = v2norm(dir);+ g_level.shake_timer = fmaxf(g_level.shake_timer, t);+}+void level_freeze(float t) {+ if (t > g_level.freeze) g_level.freeze = t;+}++/* ---------------------------------------------------------------- spawn points */+V2 level_spawn_near(V2 at) {+ /* LevelData.Spawns.ClosestTo: the room's player entities */+ return player_spawn_near(at);+}++bool level_in_bounds(V2 p, float pad) {+ Room *rm = g_level.room;+ return p.x >= rm->x + pad && p.x < rm->x + rm->w - pad && p.y >= rm->y + pad && p.y < rm->y + rm->h - pad;+}++static int room_at(V2 p) {+ for (int i = 0; i < g_level.nrooms; i++) {+ const uint8_t *r = room_rec(i);+ int x = rds32(r + RR_X), y = rds32(r + RR_Y), w = rd16(r + RR_W), h = rd16(r + RR_H);+ if (p.x >= x && p.x < x + w && p.y >= y && p.y < y + h) return i;+ }+ return -1;+}++/* ---------------------------------------------------------------- level start / reload */+/* Level.LoadLevel's bookkeeping in the session for room `index` */+static void session_enter(int index, int intro) {+ Session *ss = &g_session;+ ss->level = (uint8_t)index;+ if (intro != INTRO_FALL || !strcmp(str(rd16(room_rec(index) + RR_NAME)), "0")) {+ ss->visited[index >> 3] |= (uint8_t)(1 << (index & 7)); /* LevelFlags */+ ss->dashes_at_level_start = ss->dashes; /* UpdateLevelStartDashes */+ }+}++static float spawn_fx = 0, spawn_fy = 1; /* LoadLevel's spawn: the one nearest this point of the room (fractions) */+static void load_into_current(int index, int intro) {+ ents_clear(false);+ g_level.rooms[0].index = g_level.rooms[1].index = -1;+ g_level.room_slot = 0;+ g_level.room = &g_level.rooms[0];+ level_tiles_entities();+ spinners_entities();+ dust_entities();+ if (!room_load(0, index)) { /* no room to read it: everything loaded goes first */+ res_flush();+ room_load(0, index);+ }+ need_textures();+ g_level.room = &g_level.rooms[0];+ Room *rm = g_level.room;+ g_level.core_mode = g_session.core_mode;+ session_enter(index, intro);+ if (!g_session.has_respawn) { /* DefaultSpawnPoint, or the one LoadLevel was given */+ V2 at = player_spawn_near(v2(rm->x + rm->w * spawn_fx, rm->y + rm->h * spawn_fy));+ spawn_fx = 0, spawn_fy = 1;+ g_session.rx = (int32_t)at.x, g_session.ry = (int32_t)at.y;+ g_session.has_respawn = 1;+ }+ player_spawn(v2((float)g_session.rx, (float)g_session.ry), intro);+ ents_awake_new();+ cassette_level_start(false);+ g_level.cam_offset = v2(rds8(rm->info + RR_CAMX) * 48.f, rds8(rm->info + RR_CAMY) * 32.f);+ g_level.cam = player_camera_target(&g_player);+ g_level.cam_upward_max_y = g_level.cam.y + 180;+ /* the wipe in: a spotlight on Madeline when the level begins, the area's own after a death */+ if (intro == INTRO_RESPAWN || intro == INTRO_FALL) wipe_area(true, NULL);+ else {+ wipe_start(WIPE_SPOTLIGHT, true, NULL);+ }+ g_wipe.focus = v2((float)g_session.rx - g_level.cam.x, (float)g_session.ry - g_level.cam.y);+ g_level.wind_pattern = rm->info[RR_WIND];+ g_level.transitioning = false;+ tiles_invalidate();+}++bool level_visited(const char *room) {+ int i = chapter_find_room(g_session.chapter, room);+ return i >= 0 && (g_session.visited[i >> 3] >> (i & 7) & 1);+}++int level_start_room(void) {+ int i = room_at(v2(0, 0));+ return i < 0 ? 0 : i;+}++/* Level.RegisterAreaComplete and CompleteArea: a wipe, then the chapter's end (LevelExit) */+void level_register_complete(void) {+ if (g_level.completed) return;+ berries_collect_all();+ g_level.completed = true;+ save_register_completion();+}+static void exit_completed(void) { game_level_exit(LEXIT_COMPLETED); }+/* the pause menu's ways out, behind the area's wipe (DoScreenWipe) */+static uint8_t exit_mode;+static void exit_now(void) { game_level_exit(exit_mode); }+void level_save_and_quit(void) {+ exit_mode = LEXIT_SAVEQUIT;+ g_level.pause_lock = true;+ wipe_area(false, exit_now);+}+void level_give_up(bool restart) {+ exit_mode = restart ? LEXIT_RESTART : LEXIT_GIVEUP;+ g_level.pause_lock = true;+ wipe_area(false, exit_now);+}+void level_complete_area(bool spotlight, bool skip_wipe) {+ level_register_complete();+ g_level.pause_lock = true;+ if (!g_level.skipping_cutscene && !skip_wipe) {+ if (spotlight) {+ wipe_start(WIPE_SPOTLIGHT, false, exit_completed);+ g_wipe.focus = v2(g_player.ent->x - g_level.cam.x, g_player.ent->y - g_level.cam.y - 8);+ } else+ wipe_start(WIPE_FADE, false, exit_completed);+ return;+ }+ exit_completed();+}++/* the memory each chapter file's code keeps (chN.c), 0 by default */+WEAK uint32_t ch1_ram(void) { return 0; }+WEAK uint32_t ch8_ram(void) { return 0; }+WEAK uint32_t ch2_ram(void) { return 0; }+WEAK uint32_t ch3_ram(void) { return 0; }+WEAK uint32_t ch4_ram(void) { return 0; }+WEAK uint32_t ch5_ram(void) { return 0; }+WEAK uint32_t ch6_ram(void) { return 0; }+WEAK uint32_t ch7_ram(void) { return 0; }+WEAK uint32_t ch9_ram(void) { return 0; }+WEAK uint32_t heart_ram(void) { return 0; }+WEAK uint32_t cassette_ram(void) { return 0; }+WEAK uint32_t dust_ram(void) { return 0; }+uint8_t *g_chram[16];+/* the files whose entities the chapter has get their memory side by side, from the top of the cache */+static void chapter_memory(const uint8_t *ch) {+ uint32_t (*const RAM[16])(void) = {[1] = ch1_ram, [2] = ch2_ram, [3] = ch3_ram, [4] = ch4_ram, [5] = ch5_ram,+ [6] = ch6_ram, [7] = ch7_ram, [8] = ch8_ram, [9] = ch9_ram,+ [13] = dust_ram, [14] = cassette_ram, [15] = heart_ram};+ uint16_t files = rd16(ch + CH_FILES) | 0xC000; /* 14, 15: every chapter's (cassettes, hearts) */+ if (ch[CH_AREA] == 3 || ch[CH_AREA] == 7) files |= 1 << 13; /* 13: the dust's (dust.c) */+ uint32_t total = 0, at[16] = {0};+ for (int i = 0; i < 16; i++)+ if ((files >> i & 1) && RAM[i]) {+ at[i] = total;+ total += (RAM[i]() + 7) & ~7u;+ }+ res_chapter_ram(total);+ for (int i = 0; i < 16; i++) g_chram[i] = g_chapter_ram + at[i];+}++/* LevelLoader: the session's chapter, at its level */+void level_start(int intro) {+ memset(&g_level, 0, sizeof g_level);+ g_level.chapter = g_session.chapter;+ g_level.ch = chapter_rec(g_session.chapter);+ chapter_memory(g_level.ch);+ g_level.nrooms = rd16(g_level.ch + 2);+ g_level.rooms[0].index = g_level.rooms[1].index = -1;+ g_level.can_retry = true;+ g_level.tr_duration = 0.65f;+ g_level.zoom = g_level.zoom_target = 1; /* ResetZoom */+ g_level.zoom_focus = v2(160, 90);+ int idx = g_session.level;+ if (idx >= g_level.nrooms) idx = g_session.level = (uint8_t)level_start_room(); /* MapData.StartLevel */+ load_into_current(idx, intro);+ style_init();+}++/* Level.Reload: after a death */+void level_reload(void) {+ Session *ss = &g_session;+ if (ss->first_level && !ss->berries && !ss->cassette && !ss->heart && !ss->hit_checkpoint) {+ ss->time = 0, ss->deaths = 0;+ g_level.timer_started = false;+ }+ ss->dashes = ss->dashes_at_level_start;+ g_time_rate = 1; /* Engine.TimeRate */+ particles_clear();+ trail_clear();+ int idx = g_level.room ? g_level.room->index : 0;+ load_into_current(idx, INTRO_RESPAWN);+ ss->first_level = 0;+ ss->deaths_in_current_level = 0;+}++/* ---------------------------------------------------------------- transitions */+static void transition_to(int index, V2 dir) {+ int slot = g_level.room_slot ^ 1;+ ents_remove_room(slot);+ if (!room_load(slot, index)) return;+ Room *old = g_level.room;+ g_level.room_slot = slot;+ g_level.room = &g_level.rooms[slot];+ need_textures();+ g_session.first_level = 0;+ g_session.deaths_in_current_level = 0;+ session_enter(index, INTRO_TRANSITION);+ ents_awake_new();+ cassette_level_start(true);+ Room *rm = g_level.room;+ g_level.transitioning = true;+ g_level.tr_dir = dir;+ g_level.tr_at = 0;+ g_level.tr_cam_from = g_level.cam;+ V2 pad = v2mul(dir, dir.y > 0 ? 12.f : 4.f);+ Ent *pe = g_player.ent;+ V2 to = v2(pe->x, pe->y);+ if (dir.x != 0)+ while (to.y >= rm->y + rm->h) to.y -= 1;+ for (int guard = 0; guard < 400; guard++) {+ bool in = to.x >= rm->x + pad.x * 0 && level_in_bounds(v2add(to, pad), 0);+ if (in) break;+ to = v2add(to, dir);+ }+ g_level.tr_player_to = to;+ V2 was = v2(pe->x, pe->y);+ pe->x = to.x, pe->y = to.y;+ g_level.cam_offset = v2(rds8(rm->info + RR_CAMX) * 48.f, rds8(rm->info + RR_CAMY) * 32.f);+ g_level.tr_cam_to = player_camera_target(&g_player);+ pe->x = was.x, pe->y = was.y;+ (void)old;+}++static void transition_update(void) {+ Ent *pe = g_player.ent;+ bool arrived = player_transition_to(&g_player, g_level.tr_player_to);+ g_level.tr_at = approach(g_level.tr_at, 1, DT / g_level.tr_duration);+ if (g_level.tr_at > 0.9f) g_level.cam = g_level.tr_cam_to;+ else g_level.cam = v2add(g_level.tr_cam_from, v2mul(v2sub(g_level.tr_cam_to, g_level.tr_cam_from), ease_cube_out(g_level.tr_at)));+ if (arrived && g_level.tr_at >= 1) {+ int old = g_level.room_slot ^ 1;+ ents_remove_room(old);+ g_level.rooms[old].index = -1;+ V2 sp = player_spawn_near(v2(pe->x, pe->y)); /* Session.RespawnPoint = the closest spawn */+ g_session.rx = (int32_t)sp.x, g_session.ry = (int32_t)sp.y;+ player_on_transition(&g_player);+ g_level.cam_upward_max_y = g_level.cam.y + 180;+ g_level.tr_duration = 0.65f;+ g_level.transitioning = false;+ g_level.wind_pattern = g_level.room->info[RR_WIND];+ need_textures();+ }+}++/* Level.EnforceBounds */+void level_enforce_bounds(Player *p) {+ Ent *e = p->ent;+ Room *rm = g_level.room;+ if (g_level.transitioning) return;+ float bl = (float)rm->x, bt = (float)rm->y, br = (float)(rm->x + rm->w), bb = (float)(rm->y + rm->h);+ float cl = (float)(int)g_level.cam.x, ct = (float)(int)g_level.cam.y, cr = cl + 320, cb = ct + 180;+ int lock = g_level.cam_lock;+ if (lock == 2 && e_left(e) < cl) { /* FinalBoss: the camera's edges hold */+ e->x += cl - e_left(e);+ player_on_bounds_h(p);+ } else if (e_left(e) < bl) {+ V2 at = v2(e_cxm(e) - 8, e_cym(e));+ int next = room_at(at);+ if (e_top(e) >= bt && e_bottom(e) < bb && next >= 0 && next != rm->index) {+ transition_to(next, v2(-1, 0));+ return;+ }+ e->x += bl - e_left(e);+ player_on_bounds_h(p);+ }+ if (lock == 2 && e_right(e) > cr && cr < br - 4) {+ e->x += cr - e_right(e);+ player_on_bounds_h(p);+ } else if (e_right(e) > br) {+ V2 at = v2(e_cxm(e) + 8, e_cym(e));+ int next = room_at(at);+ if (e_top(e) >= bt && e_bottom(e) < bb && next >= 0 && next != rm->index) {+ transition_to(next, v2(1, 0));+ return;+ }+ e->x += br - e_right(e);+ player_on_bounds_h(p);+ }+ if (lock && e_top(e) < ct) {+ e->y += ct - e_top(e);+ player_on_bounds_v(p);+ } else if (e_cym(e) < bt) {+ V2 at = v2(e_cxm(e), e_cym(e) - 12);+ int next = room_at(at);+ if (next >= 0 && next != rm->index) {+ player_before_up_transition(p);+ transition_to(next, v2(0, -1));+ return;+ }+ if (e_top(e) < bt - 24) {+ e->y += (bt - 24) - e_top(e);+ player_on_bounds_v(p);+ }+ }+ if (lock && cb < bb - 4 && e_top(e) > cb) { /* below a locked camera: dead */+ player_die(p, v2(0, 0), false);+ return;+ }+ if (e_bottom(e) > bb) {+ V2 at = v2(e_cxm(e), e_cym(e) + 12);+ int next = room_at(at);+ bool down_ok = !(rm->info[RR_FLAGS] & 16);+ if (next >= 0 && next != rm->index && down_ok) {+ if (!collide_solid(e, e->x, e->y + 4)) {+ player_before_down_transition(p);+ transition_to(next, v2(0, 1));+ }+ return;+ }+ }+ if (e_top(e) > bb + 4) player_die(p, v2(0, 0), false);+}++/* ---------------------------------------------------------------- update / render */+/* Level.UpdateTime: the save's time always, the session's once the player can move */+static void update_time(void) {+ if (g_level.in_credits || g_session.area == 8 || g_level.timer_stopped) return;+ save_add_time(1);+ if (!g_level.timer_started && !g_level.in_cutscene) {+ Player *p = level_player();+ int st = p ? p->state : 0;+ if (p && !p->dead && st != ST_SUMMITLAUNCH && !(st >= ST_INTROWALK && st <= ST_INTROWAKEUP) && st != ST_INTROTHINKFORABIT)+ g_level.timer_started = true;+ }+ if (!g_level.completed && g_level.timer_started) g_session.time++;+}++void level_camera_locker(Ent *e, int mode, float max_dx, float max_dy) {+ g_level.cam_lock = mode;+ g_level.cam_locker = e, g_level.cam_lock_dx = max_dx, g_level.cam_lock_dy = max_dy;+}++/* Level.LoadLevel into another room with an intro, at the end of the frame (OnEndOfFrame) */+static int pending_room = -1, pending_intro;+void level_load_room(int index, int intro) { level_load_room_near(index, intro, 0, 1); }+void level_load_room_near(int index, int intro, float fx, float fy) {+ pending_room = index, pending_intro = intro;+ spawn_fx = fx, spawn_fy = fy;+}++void level_flash(uint16_t color, bool draw_player_over) { level_flash_a(color, 1, draw_player_over); }+void level_flash_a(uint16_t color, float alpha, bool draw_player_over) {+ if (g_save.options & 2) return; /* Photosensitive Mode */+ g_level.do_flash = true;+ g_level.flash_draw_player = draw_player_over;+ g_level.flash = 1;+ g_level.flash_color = color;+ g_level.flash_alpha = (uint8_t)(alpha * 255);+}++void level_update(void) {+ if (g_level.paused) { /* only what updates while paused (Tags.PauseUpdate) */+ ents_update();+ ents_flush_removed();+ return;+ }+ /* CanPause: Back (Input.Pause) */+ Player *pp = level_player();+ if (btn_pressed(&g_in.pause) && pp && !pp->dead && !g_level.pause_lock && !g_level.skipping_cutscene &&+ !g_level.transitioning && !g_wipe.active) {+ btn_consume(&g_in.pause);+ menu_pause();+ return;+ }+ if (g_level.freeze > 0) {+ g_level.freeze = fmaxf(g_level.freeze - DT, 0);+ return;+ }+ update_time();+ wipe_update();+ if (g_level.ending_delay > 0 && (g_level.ending_delay -= DT) <= 0) level_complete_area(false, false);+ g_level.prev_time_active = g_level.time_active;+ g_level.time_active += DT;+ g_level.raw_time_active += DT;+ if (g_level.shake_timer > 0) {+ if (level_on_raw_interval(0.04f)) {+ if (g_level.shake_dir.x == 0 && g_level.shake_dir.y == 0)+ g_level.shake_vec = v2((float)(rndi(3) - 1), (float)(rndi(3) - 1));+ else {+ int s = rndi(2) ? 1 : -1;+ g_level.shake_vec = v2(roundf(g_level.shake_dir.x * s), roundf(g_level.shake_dir.y * s));+ }+ }+ g_level.shake_timer -= DT;+ if (g_level.shake_timer <= 0) g_level.shake_vec = v2(0, 0);+ }+ if (g_level.do_flash) {+ g_level.flash = approach(g_level.flash, 1, DT * 10);+ if (g_level.flash >= 1) g_level.do_flash = false;+ } else if (g_level.flash > 0)+ g_level.flash = approach(g_level.flash, 0, DT * 3);+ if (g_level.transitioning) {+ transition_update();+ ents_update(); /* TransitionUpdate entities only */+ } else {+ ents_update();+ }+ player_after_update(&g_player);+ ents_flush_removed();+ ents_awake_new();+ style_update();+ if (pending_room >= 0) {+ int r = pending_room;+ pending_room = -1;+ g_session.has_respawn = 0; /* the new room's own spawn */+ load_into_current(r, pending_intro);+ return;+ }+ if (g_level.dead_reload) {+ g_level.dead_reload = false;+ int golden = g_player.golden_room;+ if (golden >= 0) { /* LevelExit.Mode.GoldenBerryRestart */+ session_restart(golden);+ level_start(INTRO_RESPAWN);+ } else+ level_reload();+ }+}+diff --git a/games/celeste/src/level.h b/games/celeste/src/level.hnew file mode 100644index 00000000..b7be59cd--- /dev/null+++ b/games/celeste/src/level.h@@ -0,0 +1,303 @@+/* The level: a chapter's rooms, the camera, transitions between rooms,+ * deaths and respawns (Celeste's Level, LevelLoader and Session). */+#ifndef LEVEL_H+#define LEVEL_H+#include "celeste.h"+#include "ent.h"++#define MARGIN 2 /* tiles kept around each room (tools/pack.py) */+/* room blob header (tools/pack.py room_blob): u16 offsets of the parts, then where the background tiles+ * go in RAM and how far what follows the tiles moves there; everything before RB_ENTS stays in RAM */+enum { RB_FG, RB_BG, RB_EXTRAS, RB_DFG, RB_DBG, RB_SPIN, RB_NEED, RB_ENTS, RB_TRIGS, RB_END, RB_BG_RAM, RB_SHIFT,+ RB_HEADER };+#define SPIN_X0 128++/* chapter record (tools/pack.py): u16 name, u16 nrooms, s16 x0, s16 y0, u16 tw, u16 th, u8 nbg, u8 nfg,+ * u8 area, u8 mode, u8 inventory, u8 ncheckpoints, u8 nberries, u8 detected strawberries,+ * u16 berries, u16 checkpoints (offsets in the record), u16 chapter files, u16 0, u32 room offsets[nrooms],+ * u32 styleground offsets[nbg + nfg].+ * berry: u16 room, u16 entity id, u8 checkpoint, u8 flags (BF_); checkpoint: u16 room, u8 inventory+ * (255: the mode's), u8 flags (CPF_) */+#define CH_AREA 14+#define CH_MODE 15+#define CH_INVENTORY 16+#define CH_NCHECKPOINTS 17+#define CH_NBERRIES 18+#define CH_DETECTED 19+#define CH_BERRIES 20+#define CH_CHECKPOINTS 22+#define CH_FILES 24 /* u16: the chapter files (src/chN.c) whose entities it has, bit N */+#define CH_ROOMS 28+enum { BF_GOLDEN = 1, BF_MOON = 2, BF_WINGED = 4 };+enum { CPF_DREAMING = 1, CPF_COLD = 2, CPF_FEELINGDOWN = 4, CPF_BADELINE = 8 };+enum { INV_PROLOGUE, INV_DEFAULT, INV_OLDSITE, INV_CH6END, INV_THESUMMIT, INV_CORE, INV_FAREWELL };++/* a layer of tiles: rows of runs, each a byte (type index << bits | count - 1) */+typedef struct {+ const uint8_t *types, *data;+ const uint16_t *rows;+ uint8_t bits;+} TileLayer;++typedef struct {+ int index; /* in the chapter, -1: none */+ const uint8_t *info; /* the chapter's room record (flash) */+ int x, y, w, h; /* bounds, pixels */+ int tx, ty, tw, th; /* tile grid with its margin: tile coordinates */+ TileLayer layer[2]; /* fg, bg */+ uint8_t *decals_fg, *decals_bg;+ int nfg, nbg;+ uint8_t *obj; /* objtiles (tiles that blocks take): u16 x, y, tile */+ int nobj;+ uint8_t *scen[2]; /* scenery tiles drawn over fg / bg: u16 x, y, tile */+ int nscen[2];+ const uint16_t *spin_first; /* spinners not attached to solids: first index of each tile row */+ const uint16_t *spin; /* cell x + SPIN_X0 | x % 8 << 10 | y % 8 << 13 */+ int spin_row0, spin_rows; /* their rows (room tile rows; some are outside the room) */+ const uint8_t *spin_mask; /* a nibble each: quarters inside solid tiles */+ const uint8_t *spin_dust; /* dust rooms (DustStaticSpinner): u16 each, the DustGraphic's nodes (pack.py) */+ int nspin;+ uint8_t *spin_gone; /* destroyed ones */+ const uint8_t *need; /* the textures loaded with it: u16 n, ids */+ uint8_t *mem; /* in the room pool */+ uint32_t used;+} Room;++typedef struct {+ int chapter; /* index into data.bin's chapters */+ const uint8_t *ch; /* chapter record */+ int nrooms;+ Room rooms[2];+ int room_slot; /* the current room's slot */+ Room *room;+ /* camera */+ V2 cam;+ V2 cam_offset; /* Level.CameraOffset (triggers) */+ int cam_lock; /* CameraLockModes: 0 none, 1 BoostSequence, 2 FinalBoss, 3 FinalBossNoY */+ Ent *cam_locker; /* the CameraLocker's entity, its MaxXOffset and MaxYOffset */+ float cam_lock_dx, cam_lock_dy;+ float cam_upward_max_y;+ V2 shake_vec, shake_dir;+ float flash; /* Level.Flash: the screen in flash_color */+ uint16_t flash_color;+ uint8_t flash_alpha; /* the color's own alpha (White * 0.5) */+ bool do_flash, flash_draw_player, no_retry; /* no_retry: !Level.CanRetry */+ bool has_cassette_blocks; /* Level.HasCassetteBlocks, CassetteBlockBeats (the room's) */+ uint8_t cassette_beats;+ float shake_timer;+ /* time */+ float time_active, raw_time_active, prev_time_active;+ float freeze; /* Celeste.Freeze */+ /* transitions */+ bool transitioning;+ V2 tr_dir, tr_cam_from, tr_cam_to, tr_player_to;+ float tr_at;+ float tr_duration;+ /* respawn */+ V2 respawn;+ bool dead_reload;+ bool in_cutscene;+ bool skipping_cutscene;+ Ent *cutscene; /* the CutsceneEntity running (its OnEnd on skip) */+ uint8_t skip_step;+ float zoom, zoom_target; /* Level.Zoom, ZoomTarget */+ V2 zoom_focus; /* ZoomFocusPoint, screen pixels */+ bool paused;+ bool frozen; /* Level.Frozen: only FrozenUpdate entities */+ bool formation; /* FormationBackdrop.Display */+ float formation_alpha, formation_fade;+ bool can_retry;+ bool in_space;+ int core_mode;+ V2 wind;+ int wind_pattern;+ float wind_sine_timer, wind_sine; /* WindSineTimer, WindSine */+ float lighting, lighting_target;+ float bloom;+ bool timer_started, timer_stopped, completed, in_credits;+ bool pause_lock; /* PauseLock */+ float ending_delay; /* EndingCutsceneDelay: the area completes when it runs out */+ float ending_text_y;+} Level;+extern Level g_level;++/* ---------------------------------------------------------------- Session and SaveData (save.c) */+#define AREAS 11 /* prologue ... core, farewell */+enum { M_A, M_B, M_C };+enum { MS_COMPLETED = 1, MS_SINGLERUN = 2, MS_FULLCLEAR = 4, MS_HEART = 8 };+/* color grades (Session.ColorGrade) */+enum { CG_NONE, CG_FEELINGDOWN, CG_OLDSITE, CG_REFLECTION, CG_PANICATTACK, CG_TEMPLEVOID, CG_HOT, CG_COLD, CG_GOLDEN,+ CG_CREDITS, CG_COUNT };+/* AreaModeStats; times in frames (1/60 s, Celeste's fixed step) */+typedef struct {+ uint64_t berries; /* Strawberries, by index in the chapter's list (CH_BERRIES) */+ uint32_t deaths, time, best_time, best_fc_time;+ uint16_t best_dashes, best_deaths;+ uint8_t flags; /* MS_ */+ uint8_t checkpoints; /* Checkpoints reached, by index */+ uint8_t pad[2];+} ModeStats;++/* Session: one go at a chapter side */+typedef struct {+ uint8_t chapter; /* in data.bin */+ uint8_t area, mode;+ uint8_t level; /* the room (Session.Level) */+ int8_t start_checkpoint; /* StartCheckpoint, -1: the start */+ uint8_t inv_dashes, dreamdash, backpack, no_refills; /* Inventory */+ uint8_t has_respawn;+ uint8_t started_from_beginning, first_level, in_area, cassette, heart, dreaming;+ uint8_t core_mode; /* CoreModes: 0 none, 1 hot, 2 cold */+ uint8_t grabbed_golden, hit_checkpoint, beat_best_time, unlocked_cside, summit_gems;+ uint8_t color_grade;+ uint8_t nflags, ndnl, nkeys;+ int32_t rx, ry; /* RespawnPoint */+ uint32_t time;+ uint32_t deaths, dashes, dashes_at_level_start, deaths_in_current_level;+ float lighting_alpha_add, bloom_base_add, dark_room_alpha;+ uint64_t berries; /* Strawberries */+ uint32_t flags[32]; /* Flags, hashed */+ uint32_t dnl[32]; /* DoNotLoad: room << 16 | entity id */+ uint32_t keys[4]; /* Keys */+ uint8_t visited[32]; /* LevelFlags: a bit per room */+ struct { uint32_t key; int32_t value; } counters[3];+ ModeStats old_stats; /* OldStats: the side's stats before this go */+} Session;++typedef struct {+ uint32_t magic;+ uint16_t version, size;+ ModeStats modes[AREAS][3];+ uint16_t cassettes; /* AreaStats.Cassette, a bit per area */+ uint8_t unlocked_areas, last_area, last_mode, revealed_ch9, summit_gems, key_sheet_seen;+ uint8_t has_session, assists, options, flags; /* options: 1 no screen shake, 2 no flashes, 12 speedrun clock;+ flags (SaveData.Flags): 1 MetTheo, 2 TheoKnowsName */+ uint32_t total_deaths, total_golden, total_jumps, total_wall_jumps, total_dashes, time;+ uint8_t bind[4]; /* jump, dash, grab, talk: EADK keys */+ Session session; /* CurrentSession, and the one being played */+ uint32_t checksum;+} SaveData;+extern SaveData g_save;+#define g_session (g_save.session)++void save_load(void);+bool save_write(void); /* false: storage full */+ModeStats *save_mode(void); /* the current side's */+bool save_check_berry(int index); /* SaveData.CheckStrawberry */+void save_add_berry(int index, bool golden);+void save_add_death(void);+void save_add_time(uint32_t frames);+bool save_set_checkpoint(int index);+void save_register_heart(void);+int save_unlocked_modes(void);+int save_total_berries(void); /* SaveData.TotalStrawberries */+bool save_flag(int bit); /* SaveData.HasFlag: 0 MetTheo, 1 TheoKnowsName */+void save_set_flag(int bit);+void save_register_cassette(void);+void save_register_completion(void);+void session_start(int chapter, int checkpoint); /* new Session(area, checkpoint) */+void session_restart(int room); /* Session.Restart(into room), -1 for its start */+int session_intro(bool just_started); /* INTRO_ for LevelLoader */+int level_start_room(void);+void level_register_complete(void);+void level_flash(uint16_t color, bool draw_player_over);+void level_flash_a(uint16_t color, float alpha, bool draw_player_over); /* Level.Flash(color * alpha) */+void level_camera_locker(Ent *e, int mode, float max_dx, float max_dy); /* new CameraLocker(mode, dx, dy), added */+void level_load_room(int index, int intro); /* LoadLevel(intro) into that room, at the frame's end */+/* the same, at the spawn nearest a point of the room (fx, fy: fractions of its width and height) */+void level_load_room_near(int index, int intro, float fx, float fy);+void level_complete_area(bool spotlight_wipe, bool skip_wipe);+enum { LEXIT_COMPLETED, LEXIT_SAVEQUIT, LEXIT_RESTART, LEXIT_GIVEUP, LEXIT_GOLDEN_RESTART };+void game_level_exit(int mode); /* game.c: LevelExit */+void level_extra_textures(const uint16_t *ids, int n); /* kept loaded with the rooms' (n = 0: none) */+int chapter_find_room(int chapter, const char *name); /* -1 if none */+const char *chapter_room_name(int chapter, int i); /* NULL past its last room */+bool level_visited(const char *room); /* Session.GetLevelFlag */+static inline float level_visual_wind(void) { return g_level.wind.x + g_level.wind_sine; }+int session_berry_index(int room, int eid); /* in the chapter's list, -1 if none */+int chapter_index(int area, int mode); /* in data.bin, -1 if not there */+const uint8_t *chapter_at(int c); /* its record */+int chapter_count(void);+void level_save_and_quit(void); /* LevelExit.Mode.SaveAndQuit */+void level_give_up(bool restart); /* GiveUp: the chapter again from its start, or the map */+/* the menus (menu.c) */+extern uint8_t g_menu; /* a menu is on (0: none) */+void menu_update(void);+void menu_render(void);+void menu_pause(void);+void menu_open_title(void);+void menu_open_overworld(bool completed);+void menu_open_main(void);+void hud_update(void); /* TotalStrawberriesDisplay */+void hud_reset(void);+extern bool g_in_level;+void game_play(int chapter, int checkpoint); /* game.c: a chapter from a checkpoint (-1: start), or the saved session (chapter -1) */++void level_start(int intro); /* the session's chapter, at its level */+void level_update(void);+void level_reload(void); /* after death: back to the respawn point */+bool level_on_interval(float interval);+bool level_on_raw_interval(float interval);+void level_shake(float t);+void level_dir_shake(V2 dir, float t);+void level_freeze(float t);+Ent *level_player_ent(void);+Player *level_player(void);+float level_player_speed_x(void);+bool level_player_climbing(void);+int level_player_facing(void);+bool level_solid_cells(int cx0, int cy0, int cx1, int cy1);+bool level_grid_collide(const Ent *grid, float l, float t, float r, float b);+char level_tile_type(int layer, int cx, int cy);+bool level_is_dash_block(Ent *e);+void level_break_dash_block(Ent *e, V2 dir);+void level_enforce_bounds(Player *p);+V2 level_spawn_near(V2 at);+const char *level_room_name(void);+const char *level_room_name_of(int index);+bool level_in_bounds(V2 p, float pad);+void level_set_flag(const char *flag, bool on);+bool level_get_flag(const char *flag);+uint32_t level_entity_id(int room, int eid);+bool level_do_not_load(uint32_t id);+void level_set_do_not_load(uint32_t id);++/* tiles (tiles.c) */+typedef struct {+ uint8_t terrain; /* 255: none */+ uint8_t quad; /* ty * 8 + tx in the tile sheet */+} TileQ;+int autotile(int layer, char (*get)(int x, int y, void *ctx), void *ctx, int x, int y, uint8_t *quad, int variant);+void tiles_render_layer(int layer, int depth);+void tiles_invalidate(void);+int terrain_of(int layer, char c);+uint16_t terrain_tex(int t);+/* a box of tiles of one type, as Celeste's GenerateBox (falling blocks...) */+void tiles_box(char type, int w, int h, TileQ *out);+void tiles_overlay(char type, int x, int y, int w, int h, TileQ *out); /* blended into the room (dash blocks) */+void tiles_draw(const TileQ *q, int w, int h, float x, float y, uint16_t tint, uint8_t alpha);++/* stylegrounds (style.c) */+void style_init(void);+void style_update(void);+void style_render(bool fg);++void level_tiles_entities(void);++/* lights (light.c): call while rendering */+void light_add(float x, float y, uint32_t color, float alpha, float start_fade, float end_fade);+void bloom_add(float x, float y, float alpha, float radius);+void lights_begin(void);++/* crystal and dust spinners that do not move (spinner.c) */+void spinners_entities(void);+bool spinners_hit_rect(float l, float t, float r, float b); /* the hitboxes of spinners overlap a rect */+void spinners_destroy_near(float x, float y, float r); /* Reflection's falls and the boss */++/* decals */+void decals_render(bool fg);++/* entities (entities.c) */+void entities_load(Room *r, const uint8_t *blob, int room_slot);+void entities_triggers(Room *r, const uint8_t *blob);+#endifdiff --git a/games/celeste/src/light.c b/games/celeste/src/light.cnew file mode 100644index 00000000..43411801--- /dev/null+++ b/games/celeste/src/light.c@@ -0,0 +1,17 @@+/* Lights and bloom: VertexLight and BloomPoint components register here+ * while their entities render; the lighting layer darkens the view outside+ * them (Celeste's LightingRenderer). */+#include "level.h"++#define MAX_LIGHTS 24+typedef struct { float x, y, alpha, start, end; uint32_t color; } Light;+static Light lights[MAX_LIGHTS];+static int nlights;++void light_add(float x, float y, uint32_t color, float alpha, float start_fade, float end_fade) {+ if (nlights >= MAX_LIGHTS || alpha <= 0) return;+ lights[nlights++] = (Light){x, y, alpha, start_fade, end_fade, color};+}+void bloom_add(float x, float y, float alpha, float radius) { (void)x, (void)y, (void)alpha, (void)radius; }+void lights_begin(void) { nlights = 0; }+int lights_count(void) { return nlights; }diff --git a/games/celeste/src/lzma/7zTypes.h b/games/celeste/src/lzma/7zTypes.hnew file mode 100644index 00000000..4977cdaa--- /dev/null+++ b/games/celeste/src/lzma/7zTypes.h@@ -0,0 +1,374 @@+/* 7zTypes.h -- Basic types+2017-07-17 : Igor Pavlov : Public domain */++#ifndef __7Z_TYPES_H+#define __7Z_TYPES_H++#ifdef _WIN32+/* #include <windows.h> */+#endif++#include <stddef.h>++#ifndef EXTERN_C_BEGIN+#ifdef __cplusplus+#define EXTERN_C_BEGIN extern "C" {+#define EXTERN_C_END }+#else+#define EXTERN_C_BEGIN+#define EXTERN_C_END+#endif+#endif++EXTERN_C_BEGIN++#define SZ_OK 0++#define SZ_ERROR_DATA 1+#define SZ_ERROR_MEM 2+#define SZ_ERROR_CRC 3+#define SZ_ERROR_UNSUPPORTED 4+#define SZ_ERROR_PARAM 5+#define SZ_ERROR_INPUT_EOF 6+#define SZ_ERROR_OUTPUT_EOF 7+#define SZ_ERROR_READ 8+#define SZ_ERROR_WRITE 9+#define SZ_ERROR_PROGRESS 10+#define SZ_ERROR_FAIL 11+#define SZ_ERROR_THREAD 12++#define SZ_ERROR_ARCHIVE 16+#define SZ_ERROR_NO_ARCHIVE 17++typedef int SRes;+++#ifdef _WIN32++/* typedef DWORD WRes; */+typedef unsigned WRes;+#define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x)++#else++typedef int WRes;+#define MY__FACILITY_WIN32 7+#define MY__FACILITY__WRes MY__FACILITY_WIN32+#define MY_SRes_HRESULT_FROM_WRes(x) ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : ((HRESULT) (((x) & 0x0000FFFF) | (MY__FACILITY__WRes << 16) | 0x80000000)))++#endif+++#ifndef RINOK+#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }+#endif++typedef unsigned char Byte;+typedef short Int16;+typedef unsigned short UInt16;++#ifdef _LZMA_UINT32_IS_ULONG+typedef long Int32;+typedef unsigned long UInt32;+#else+typedef int Int32;+typedef unsigned int UInt32;+#endif++#ifdef _SZ_NO_INT_64++/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.+ NOTES: Some code will work incorrectly in that case! */++typedef long Int64;+typedef unsigned long UInt64;++#else++#if defined(_MSC_VER) || defined(__BORLANDC__)+typedef __int64 Int64;+typedef unsigned __int64 UInt64;+#define UINT64_CONST(n) n+#else+typedef long long int Int64;+typedef unsigned long long int UInt64;+#define UINT64_CONST(n) n ## ULL+#endif++#endif++#ifdef _LZMA_NO_SYSTEM_SIZE_T+typedef UInt32 SizeT;+#else+typedef size_t SizeT;+#endif++typedef int Bool;+#define True 1+#define False 0+++#ifdef _WIN32+#define MY_STD_CALL __stdcall+#else+#define MY_STD_CALL+#endif++#ifdef _MSC_VER++#if _MSC_VER >= 1300+#define MY_NO_INLINE __declspec(noinline)+#else+#define MY_NO_INLINE+#endif++#define MY_FORCE_INLINE __forceinline++#define MY_CDECL __cdecl+#define MY_FAST_CALL __fastcall++#else++#define MY_NO_INLINE+#define MY_FORCE_INLINE+#define MY_CDECL+#define MY_FAST_CALL++/* inline keyword : for C++ / C99 */++/* GCC, clang: */+/*+#if defined (__GNUC__) && (__GNUC__ >= 4)+#define MY_FORCE_INLINE __attribute__((always_inline))+#define MY_NO_INLINE __attribute__((noinline))+#endif+*/++#endif+++/* The following interfaces use first parameter as pointer to structure */++typedef struct IByteIn IByteIn;+struct IByteIn+{+ Byte (*Read)(const IByteIn *p); /* reads one byte, returns 0 in case of EOF or error */+};+#define IByteIn_Read(p) (p)->Read(p)+++typedef struct IByteOut IByteOut;+struct IByteOut+{+ void (*Write)(const IByteOut *p, Byte b);+};+#define IByteOut_Write(p, b) (p)->Write(p, b)+++typedef struct ISeqInStream ISeqInStream;+struct ISeqInStream+{+ SRes (*Read)(const ISeqInStream *p, void *buf, size_t *size);+ /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.+ (output(*size) < input(*size)) is allowed */+};+#define ISeqInStream_Read(p, buf, size) (p)->Read(p, buf, size)++/* it can return SZ_ERROR_INPUT_EOF */+SRes SeqInStream_Read(const ISeqInStream *stream, void *buf, size_t size);+SRes SeqInStream_Read2(const ISeqInStream *stream, void *buf, size_t size, SRes errorType);+SRes SeqInStream_ReadByte(const ISeqInStream *stream, Byte *buf);+++typedef struct ISeqOutStream ISeqOutStream;+struct ISeqOutStream+{+ size_t (*Write)(const ISeqOutStream *p, const void *buf, size_t size);+ /* Returns: result - the number of actually written bytes.+ (result < size) means error */+};+#define ISeqOutStream_Write(p, buf, size) (p)->Write(p, buf, size)++typedef enum+{+ SZ_SEEK_SET = 0,+ SZ_SEEK_CUR = 1,+ SZ_SEEK_END = 2+} ESzSeek;+++typedef struct ISeekInStream ISeekInStream;+struct ISeekInStream+{+ SRes (*Read)(const ISeekInStream *p, void *buf, size_t *size); /* same as ISeqInStream::Read */+ SRes (*Seek)(const ISeekInStream *p, Int64 *pos, ESzSeek origin);+};+#define ISeekInStream_Read(p, buf, size) (p)->Read(p, buf, size)+#define ISeekInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)+++typedef struct ILookInStream ILookInStream;+struct ILookInStream+{+ SRes (*Look)(const ILookInStream *p, const void **buf, size_t *size);+ /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.+ (output(*size) > input(*size)) is not allowed+ (output(*size) < input(*size)) is allowed */+ SRes (*Skip)(const ILookInStream *p, size_t offset);+ /* offset must be <= output(*size) of Look */++ SRes (*Read)(const ILookInStream *p, void *buf, size_t *size);+ /* reads directly (without buffer). It's same as ISeqInStream::Read */+ SRes (*Seek)(const ILookInStream *p, Int64 *pos, ESzSeek origin);+};++#define ILookInStream_Look(p, buf, size) (p)->Look(p, buf, size)+#define ILookInStream_Skip(p, offset) (p)->Skip(p, offset)+#define ILookInStream_Read(p, buf, size) (p)->Read(p, buf, size)+#define ILookInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)+++SRes LookInStream_LookRead(const ILookInStream *stream, void *buf, size_t *size);+SRes LookInStream_SeekTo(const ILookInStream *stream, UInt64 offset);++/* reads via ILookInStream::Read */+SRes LookInStream_Read2(const ILookInStream *stream, void *buf, size_t size, SRes errorType);+SRes LookInStream_Read(const ILookInStream *stream, void *buf, size_t size);++++typedef struct+{+ ILookInStream vt;+ const ISeekInStream *realStream;++ size_t pos;+ size_t size; /* it's data size */++ /* the following variables must be set outside */+ Byte *buf;+ size_t bufSize;+} CLookToRead2;++void LookToRead2_CreateVTable(CLookToRead2 *p, int lookahead);++#define LookToRead2_Init(p) { (p)->pos = (p)->size = 0; }+++typedef struct+{+ ISeqInStream vt;+ const ILookInStream *realStream;+} CSecToLook;++void SecToLook_CreateVTable(CSecToLook *p);++++typedef struct+{+ ISeqInStream vt;+ const ILookInStream *realStream;+} CSecToRead;++void SecToRead_CreateVTable(CSecToRead *p);+++typedef struct ICompressProgress ICompressProgress;++struct ICompressProgress+{+ SRes (*Progress)(const ICompressProgress *p, UInt64 inSize, UInt64 outSize);+ /* Returns: result. (result != SZ_OK) means break.+ Value (UInt64)(Int64)-1 for size means unknown value. */+};+#define ICompressProgress_Progress(p, inSize, outSize) (p)->Progress(p, inSize, outSize)++++typedef struct ISzAlloc ISzAlloc;+typedef const ISzAlloc * ISzAllocPtr;++struct ISzAlloc+{+ void *(*Alloc)(ISzAllocPtr p, size_t size);+ void (*Free)(ISzAllocPtr p, void *address); /* address can be 0 */+};++#define ISzAlloc_Alloc(p, size) (p)->Alloc(p, size)+#define ISzAlloc_Free(p, a) (p)->Free(p, a)++/* deprecated */+#define IAlloc_Alloc(p, size) ISzAlloc_Alloc(p, size)+#define IAlloc_Free(p, a) ISzAlloc_Free(p, a)++++++#ifndef MY_offsetof+ #ifdef offsetof+ #define MY_offsetof(type, m) offsetof(type, m)+ /*+ #define MY_offsetof(type, m) FIELD_OFFSET(type, m)+ */+ #else+ #define MY_offsetof(type, m) ((size_t)&(((type *)0)->m))+ #endif+#endif++++#ifndef MY_container_of++/*+#define MY_container_of(ptr, type, m) container_of(ptr, type, m)+#define MY_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m)+#define MY_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m)))+#define MY_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m))))+*/++/*+ GCC shows warning: "perhaps the 'offsetof' macro was used incorrectly"+ GCC 3.4.4 : classes with constructor+ GCC 4.8.1 : classes with non-public variable members"+*/++#define MY_container_of(ptr, type, m) ((type *)((char *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m)))+++#endif++#define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(ptr))++/*+#define CONTAINER_FROM_VTBL(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)+*/+#define CONTAINER_FROM_VTBL(ptr, type, m) MY_container_of(ptr, type, m)++#define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)+/*+#define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL(ptr, type, m)+*/++++#ifdef _WIN32++#define CHAR_PATH_SEPARATOR '\\'+#define WCHAR_PATH_SEPARATOR L'\\'+#define STRING_PATH_SEPARATOR "\\"+#define WSTRING_PATH_SEPARATOR L"\\"++#else++#define CHAR_PATH_SEPARATOR '/'+#define WCHAR_PATH_SEPARATOR L'/'+#define STRING_PATH_SEPARATOR "/"+#define WSTRING_PATH_SEPARATOR L"/"++#endif++EXTERN_C_END++#endifdiff --git a/games/celeste/src/lzma/LzmaDec.c b/games/celeste/src/lzma/LzmaDec.cnew file mode 100644index 00000000..962b94bb--- /dev/null+++ b/games/celeste/src/lzma/LzmaDec.c@@ -0,0 +1,1185 @@+/* LzmaDec.c -- LZMA Decoder+2018-02-28 : Igor Pavlov : Public domain */++#include "Precomp.h"++/* #include "CpuArch.h" */+#include "LzmaDec.h"++#include <string.h>++#define kNumTopBits 24+#define kTopValue ((UInt32)1 << kNumTopBits)++#define kNumBitModelTotalBits 11+#define kBitModelTotal (1 << kNumBitModelTotalBits)+#define kNumMoveBits 5++#define RC_INIT_SIZE 5++#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); }++#define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)+#define UPDATE_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));+#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits));+#define GET_BIT2(p, i, A0, A1) IF_BIT_0(p) \+ { UPDATE_0(p); i = (i + i); A0; } else \+ { UPDATE_1(p); i = (i + i) + 1; A1; }++#define TREE_GET_BIT(probs, i) { GET_BIT2(probs + i, i, ;, ;); }++#define REV_BIT(p, i, A0, A1) IF_BIT_0(p + i) \+ { UPDATE_0(p + i); A0; } else \+ { UPDATE_1(p + i); A1; }+#define REV_BIT_VAR( p, i, m) REV_BIT(p, i, i += m; m += m, m += m; i += m; )+#define REV_BIT_CONST(p, i, m) REV_BIT(p, i, i += m; , i += m * 2; )+#define REV_BIT_LAST( p, i, m) REV_BIT(p, i, i -= m , ; )++#define TREE_DECODE(probs, limit, i) \+ { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; }++/* #define _LZMA_SIZE_OPT */++#ifdef _LZMA_SIZE_OPT+#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)+#else+#define TREE_6_DECODE(probs, i) \+ { i = 1; \+ TREE_GET_BIT(probs, i); \+ TREE_GET_BIT(probs, i); \+ TREE_GET_BIT(probs, i); \+ TREE_GET_BIT(probs, i); \+ TREE_GET_BIT(probs, i); \+ TREE_GET_BIT(probs, i); \+ i -= 0x40; }+#endif++#define NORMAL_LITER_DEC TREE_GET_BIT(prob, symbol)+#define MATCHED_LITER_DEC \+ matchByte += matchByte; \+ bit = offs; \+ offs &= matchByte; \+ probLit = prob + (offs + bit + symbol); \+ GET_BIT2(probLit, symbol, offs ^= bit; , ;)++++#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }++#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)+#define UPDATE_0_CHECK range = bound;+#define UPDATE_1_CHECK range -= bound; code -= bound;+#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \+ { UPDATE_0_CHECK; i = (i + i); A0; } else \+ { UPDATE_1_CHECK; i = (i + i) + 1; A1; }+#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;)+#define TREE_DECODE_CHECK(probs, limit, i) \+ { i = 1; do { GET_BIT_CHECK(probs + i, i) } while (i < limit); i -= limit; }+++#define REV_BIT_CHECK(p, i, m) IF_BIT_0_CHECK(p + i) \+ { UPDATE_0_CHECK; i += m; m += m; } else \+ { UPDATE_1_CHECK; m += m; i += m; }+++#define kNumPosBitsMax 4+#define kNumPosStatesMax (1 << kNumPosBitsMax)++#define kLenNumLowBits 3+#define kLenNumLowSymbols (1 << kLenNumLowBits)+#define kLenNumHighBits 8+#define kLenNumHighSymbols (1 << kLenNumHighBits)++#define LenLow 0+#define LenHigh (LenLow + 2 * (kNumPosStatesMax << kLenNumLowBits))+#define kNumLenProbs (LenHigh + kLenNumHighSymbols)++#define LenChoice LenLow+#define LenChoice2 (LenLow + (1 << kLenNumLowBits))++#define kNumStates 12+#define kNumStates2 16+#define kNumLitStates 7++#define kStartPosModelIndex 4+#define kEndPosModelIndex 14+#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))++#define kNumPosSlotBits 6+#define kNumLenToPosStates 4++#define kNumAlignBits 4+#define kAlignTableSize (1 << kNumAlignBits)++#define kMatchMinLen 2+#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols * 2 + kLenNumHighSymbols)++/* External ASM code needs same CLzmaProb array layout. So don't change it. */++/* (probs_1664) is faster and better for code size at some platforms */+/*+#ifdef MY_CPU_X86_OR_AMD64+*/+#define kStartOffset 1664+#define GET_PROBS p->probs_1664+/*+#define GET_PROBS p->probs + kStartOffset+#else+#define kStartOffset 0+#define GET_PROBS p->probs+#endif+*/++#define SpecPos (-kStartOffset)+#define IsRep0Long (SpecPos + kNumFullDistances)+#define RepLenCoder (IsRep0Long + (kNumStates2 << kNumPosBitsMax))+#define LenCoder (RepLenCoder + kNumLenProbs)+#define IsMatch (LenCoder + kNumLenProbs)+#define Align (IsMatch + (kNumStates2 << kNumPosBitsMax))+#define IsRep (Align + kAlignTableSize)+#define IsRepG0 (IsRep + kNumStates)+#define IsRepG1 (IsRepG0 + kNumStates)+#define IsRepG2 (IsRepG1 + kNumStates)+#define PosSlot (IsRepG2 + kNumStates)+#define Literal (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))+#define NUM_BASE_PROBS (Literal + kStartOffset)++#if Align != 0 && kStartOffset != 0+ #error Stop_Compiling_Bad_LZMA_kAlign+#endif++#if NUM_BASE_PROBS != 1984+ #error Stop_Compiling_Bad_LZMA_PROBS+#endif+++#define LZMA_LIT_SIZE 0x300++#define LzmaProps_GetNumProbs(p) (NUM_BASE_PROBS + ((UInt32)LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))+++#define CALC_POS_STATE(processedPos, pbMask) (((processedPos) & (pbMask)) << 4)+#define COMBINED_PS_STATE (posState + state)+#define GET_LEN_STATE (posState)++#define LZMA_DIC_MIN (1 << 12)++/*+p->remainLen : shows status of LZMA decoder:+ < kMatchSpecLenStart : normal remain+ = kMatchSpecLenStart : finished+ = kMatchSpecLenStart + 1 : need init range coder+ = kMatchSpecLenStart + 2 : need init range coder and state+*/++/* ---------- LZMA_DECODE_REAL ---------- */+/*+LzmaDec_DecodeReal_3() can be implemented in external ASM file.+3 - is the code compatibility version of that function for check at link time.+*/++#define LZMA_DECODE_REAL LzmaDec_DecodeReal_3++/*+LZMA_DECODE_REAL()+In:+ RangeCoder is normalized+ if (p->dicPos == limit)+ {+ LzmaDec_TryDummy() was called before to exclude LITERAL and MATCH-REP cases.+ So first symbol can be only MATCH-NON-REP. And if that MATCH-NON-REP symbol+ is not END_OF_PAYALOAD_MARKER, then function returns error code.+ }++Processing:+ first LZMA symbol will be decoded in any case+ All checks for limits are at the end of main loop,+ It will decode new LZMA-symbols while (p->buf < bufLimit && dicPos < limit),+ RangeCoder is still without last normalization when (p->buf < bufLimit) is being checked.++Out:+ RangeCoder is normalized+ Result:+ SZ_OK - OK+ SZ_ERROR_DATA - Error+ p->remainLen:+ < kMatchSpecLenStart : normal remain+ = kMatchSpecLenStart : finished+*/+++#ifdef _LZMA_DEC_OPT++int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit);++#else++static+int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit)+{+ CLzmaProb *probs = GET_PROBS;+ unsigned state = (unsigned)p->state;+ UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3];+ unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;+ unsigned lc = p->prop.lc;+ unsigned lpMask = ((unsigned)0x100 << p->prop.lp) - ((unsigned)0x100 >> lc);++ Byte *dic = p->dic;+ SizeT dicBufSize = p->dicBufSize;+ SizeT dicPos = p->dicPos;++ UInt32 processedPos = p->processedPos;+ UInt32 checkDicSize = p->checkDicSize;+ unsigned len = 0;++ const Byte *buf = p->buf;+ UInt32 range = p->range;+ UInt32 code = p->code;++ do+ {+ CLzmaProb *prob;+ UInt32 bound;+ unsigned ttt;+ unsigned posState = CALC_POS_STATE(processedPos, pbMask);++ prob = probs + IsMatch + COMBINED_PS_STATE;+ IF_BIT_0(prob)+ {+ unsigned symbol;+ UPDATE_0(prob);+ prob = probs + Literal;+ if (processedPos != 0 || checkDicSize != 0)+ prob += (UInt32)3 * ((((processedPos << 8) + dic[(dicPos == 0 ? dicBufSize : dicPos) - 1]) & lpMask) << lc);+ processedPos++;++ if (state < kNumLitStates)+ {+ state -= (state < 4) ? state : 3;+ symbol = 1;+ #ifdef _LZMA_SIZE_OPT+ do { NORMAL_LITER_DEC } while (symbol < 0x100);+ #else+ NORMAL_LITER_DEC+ NORMAL_LITER_DEC+ NORMAL_LITER_DEC+ NORMAL_LITER_DEC+ NORMAL_LITER_DEC+ NORMAL_LITER_DEC+ NORMAL_LITER_DEC+ NORMAL_LITER_DEC+ #endif+ }+ else+ {+ unsigned matchByte = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];+ unsigned offs = 0x100;+ state -= (state < 10) ? 3 : 6;+ symbol = 1;+ #ifdef _LZMA_SIZE_OPT+ do+ {+ unsigned bit;+ CLzmaProb *probLit;+ MATCHED_LITER_DEC+ }+ while (symbol < 0x100);+ #else+ {+ unsigned bit;+ CLzmaProb *probLit;+ MATCHED_LITER_DEC+ MATCHED_LITER_DEC+ MATCHED_LITER_DEC+ MATCHED_LITER_DEC+ MATCHED_LITER_DEC+ MATCHED_LITER_DEC+ MATCHED_LITER_DEC+ MATCHED_LITER_DEC+ }+ #endif+ }++ dic[dicPos++] = (Byte)symbol;+ continue;+ }++ {+ UPDATE_1(prob);+ prob = probs + IsRep + state;+ IF_BIT_0(prob)+ {+ UPDATE_0(prob);+ state += kNumStates;+ prob = probs + LenCoder;+ }+ else+ {+ UPDATE_1(prob);+ /*+ // that case was checked before with kBadRepCode+ if (checkDicSize == 0 && processedPos == 0)+ return SZ_ERROR_DATA;+ */+ prob = probs + IsRepG0 + state;+ IF_BIT_0(prob)+ {+ UPDATE_0(prob);+ prob = probs + IsRep0Long + COMBINED_PS_STATE;+ IF_BIT_0(prob)+ {+ UPDATE_0(prob);+ dic[dicPos] = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];+ dicPos++;+ processedPos++;+ state = state < kNumLitStates ? 9 : 11;+ continue;+ }+ UPDATE_1(prob);+ }+ else+ {+ UInt32 distance;+ UPDATE_1(prob);+ prob = probs + IsRepG1 + state;+ IF_BIT_0(prob)+ {+ UPDATE_0(prob);+ distance = rep1;+ }+ else+ {+ UPDATE_1(prob);+ prob = probs + IsRepG2 + state;+ IF_BIT_0(prob)+ {+ UPDATE_0(prob);+ distance = rep2;+ }+ else+ {+ UPDATE_1(prob);+ distance = rep3;+ rep3 = rep2;+ }+ rep2 = rep1;+ }+ rep1 = rep0;+ rep0 = distance;+ }+ state = state < kNumLitStates ? 8 : 11;+ prob = probs + RepLenCoder;+ }++ #ifdef _LZMA_SIZE_OPT+ {+ unsigned lim, offset;+ CLzmaProb *probLen = prob + LenChoice;+ IF_BIT_0(probLen)+ {+ UPDATE_0(probLen);+ probLen = prob + LenLow + GET_LEN_STATE;+ offset = 0;+ lim = (1 << kLenNumLowBits);+ }+ else+ {+ UPDATE_1(probLen);+ probLen = prob + LenChoice2;+ IF_BIT_0(probLen)+ {+ UPDATE_0(probLen);+ probLen = prob + LenLow + GET_LEN_STATE + (1 << kLenNumLowBits);+ offset = kLenNumLowSymbols;+ lim = (1 << kLenNumLowBits);+ }+ else+ {+ UPDATE_1(probLen);+ probLen = prob + LenHigh;+ offset = kLenNumLowSymbols * 2;+ lim = (1 << kLenNumHighBits);+ }+ }+ TREE_DECODE(probLen, lim, len);+ len += offset;+ }+ #else+ {+ CLzmaProb *probLen = prob + LenChoice;+ IF_BIT_0(probLen)+ {+ UPDATE_0(probLen);+ probLen = prob + LenLow + GET_LEN_STATE;+ len = 1;+ TREE_GET_BIT(probLen, len);+ TREE_GET_BIT(probLen, len);+ TREE_GET_BIT(probLen, len);+ len -= 8;+ }+ else+ {+ UPDATE_1(probLen);+ probLen = prob + LenChoice2;+ IF_BIT_0(probLen)+ {+ UPDATE_0(probLen);+ probLen = prob + LenLow + GET_LEN_STATE + (1 << kLenNumLowBits);+ len = 1;+ TREE_GET_BIT(probLen, len);+ TREE_GET_BIT(probLen, len);+ TREE_GET_BIT(probLen, len);+ }+ else+ {+ UPDATE_1(probLen);+ probLen = prob + LenHigh;+ TREE_DECODE(probLen, (1 << kLenNumHighBits), len);+ len += kLenNumLowSymbols * 2;+ }+ }+ }+ #endif++ if (state >= kNumStates)+ {+ UInt32 distance;+ prob = probs + PosSlot ++ ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);+ TREE_6_DECODE(prob, distance);+ if (distance >= kStartPosModelIndex)+ {+ unsigned posSlot = (unsigned)distance;+ unsigned numDirectBits = (unsigned)(((distance >> 1) - 1));+ distance = (2 | (distance & 1));+ if (posSlot < kEndPosModelIndex)+ {+ distance <<= numDirectBits;+ prob = probs + SpecPos;+ {+ UInt32 m = 1;+ distance++;+ do+ {+ REV_BIT_VAR(prob, distance, m);+ }+ while (--numDirectBits);+ distance -= m;+ }+ }+ else+ {+ numDirectBits -= kNumAlignBits;+ do+ {+ NORMALIZE+ range >>= 1;++ {+ UInt32 t;+ code -= range;+ t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */+ distance = (distance << 1) + (t + 1);+ code += range & t;+ }+ /*+ distance <<= 1;+ if (code >= range)+ {+ code -= range;+ distance |= 1;+ }+ */+ }+ while (--numDirectBits);+ prob = probs + Align;+ distance <<= kNumAlignBits;+ {+ unsigned i = 1;+ REV_BIT_CONST(prob, i, 1);+ REV_BIT_CONST(prob, i, 2);+ REV_BIT_CONST(prob, i, 4);+ REV_BIT_LAST (prob, i, 8);+ distance |= i;+ }+ if (distance == (UInt32)0xFFFFFFFF)+ {+ len = kMatchSpecLenStart;+ state -= kNumStates;+ break;+ }+ }+ }++ rep3 = rep2;+ rep2 = rep1;+ rep1 = rep0;+ rep0 = distance + 1;+ state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;+ if (distance >= (checkDicSize == 0 ? processedPos: checkDicSize))+ {+ p->dicPos = dicPos;+ return SZ_ERROR_DATA;+ }+ }++ len += kMatchMinLen;++ {+ SizeT rem;+ unsigned curLen;+ SizeT pos;++ if ((rem = limit - dicPos) == 0)+ {+ p->dicPos = dicPos;+ return SZ_ERROR_DATA;+ }++ curLen = ((rem < len) ? (unsigned)rem : len);+ pos = dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0);++ processedPos += curLen;++ len -= curLen;+ if (curLen <= dicBufSize - pos)+ {+ Byte *dest = dic + dicPos;+ ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;+ const Byte *lim = dest + curLen;+ dicPos += curLen;+ do+ *(dest) = (Byte)*(dest + src);+ while (++dest != lim);+ }+ else+ {+ do+ {+ dic[dicPos++] = dic[pos];+ if (++pos == dicBufSize)+ pos = 0;+ }+ while (--curLen != 0);+ }+ }+ }+ }+ while (dicPos < limit && buf < bufLimit);++ NORMALIZE;++ p->buf = buf;+ p->range = range;+ p->code = code;+ p->remainLen = len;+ p->dicPos = dicPos;+ p->processedPos = processedPos;+ p->reps[0] = rep0;+ p->reps[1] = rep1;+ p->reps[2] = rep2;+ p->reps[3] = rep3;+ p->state = state;++ return SZ_OK;+}+#endif++static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)+{+ if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart)+ {+ Byte *dic = p->dic;+ SizeT dicPos = p->dicPos;+ SizeT dicBufSize = p->dicBufSize;+ unsigned len = (unsigned)p->remainLen;+ SizeT rep0 = p->reps[0]; /* we use SizeT to avoid the BUG of VC14 for AMD64 */+ SizeT rem = limit - dicPos;+ if (rem < len)+ len = (unsigned)(rem);++ if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)+ p->checkDicSize = p->prop.dicSize;++ p->processedPos += len;+ p->remainLen -= len;+ while (len != 0)+ {+ len--;+ dic[dicPos] = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];+ dicPos++;+ }+ p->dicPos = dicPos;+ }+}+++#define kRange0 0xFFFFFFFF+#define kBound0 ((kRange0 >> kNumBitModelTotalBits) << (kNumBitModelTotalBits - 1))+#define kBadRepCode (kBound0 + (((kRange0 - kBound0) >> kNumBitModelTotalBits) << (kNumBitModelTotalBits - 1)))+#if kBadRepCode != (0xC0000000 - 0x400)+ #error Stop_Compiling_Bad_LZMA_Check+#endif++static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)+{+ do+ {+ SizeT limit2 = limit;+ if (p->checkDicSize == 0)+ {+ UInt32 rem = p->prop.dicSize - p->processedPos;+ if (limit - p->dicPos > rem)+ limit2 = p->dicPos + rem;++ if (p->processedPos == 0)+ if (p->code >= kBadRepCode)+ return SZ_ERROR_DATA;+ }++ RINOK(LZMA_DECODE_REAL(p, limit2, bufLimit));++ if (p->checkDicSize == 0 && p->processedPos >= p->prop.dicSize)+ p->checkDicSize = p->prop.dicSize;++ LzmaDec_WriteRem(p, limit);+ }+ while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);++ return 0;+}++typedef enum+{+ DUMMY_ERROR, /* unexpected end of input stream */+ DUMMY_LIT,+ DUMMY_MATCH,+ DUMMY_REP+} ELzmaDummy;++static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)+{+ UInt32 range = p->range;+ UInt32 code = p->code;+ const Byte *bufLimit = buf + inSize;+ const CLzmaProb *probs = GET_PROBS;+ unsigned state = (unsigned)p->state;+ ELzmaDummy res;++ {+ const CLzmaProb *prob;+ UInt32 bound;+ unsigned ttt;+ unsigned posState = CALC_POS_STATE(p->processedPos, (1 << p->prop.pb) - 1);++ prob = probs + IsMatch + COMBINED_PS_STATE;+ IF_BIT_0_CHECK(prob)+ {+ UPDATE_0_CHECK++ /* if (bufLimit - buf >= 7) return DUMMY_LIT; */++ prob = probs + Literal;+ if (p->checkDicSize != 0 || p->processedPos != 0)+ prob += ((UInt32)LZMA_LIT_SIZE *+ ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) ++ (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));++ if (state < kNumLitStates)+ {+ unsigned symbol = 1;+ do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);+ }+ else+ {+ unsigned matchByte = p->dic[p->dicPos - p->reps[0] ++ (p->dicPos < p->reps[0] ? p->dicBufSize : 0)];+ unsigned offs = 0x100;+ unsigned symbol = 1;+ do+ {+ unsigned bit;+ const CLzmaProb *probLit;+ matchByte += matchByte;+ bit = offs;+ offs &= matchByte;+ probLit = prob + (offs + bit + symbol);+ GET_BIT2_CHECK(probLit, symbol, offs ^= bit; , ; )+ }+ while (symbol < 0x100);+ }+ res = DUMMY_LIT;+ }+ else+ {+ unsigned len;+ UPDATE_1_CHECK;++ prob = probs + IsRep + state;+ IF_BIT_0_CHECK(prob)+ {+ UPDATE_0_CHECK;+ state = 0;+ prob = probs + LenCoder;+ res = DUMMY_MATCH;+ }+ else+ {+ UPDATE_1_CHECK;+ res = DUMMY_REP;+ prob = probs + IsRepG0 + state;+ IF_BIT_0_CHECK(prob)+ {+ UPDATE_0_CHECK;+ prob = probs + IsRep0Long + COMBINED_PS_STATE;+ IF_BIT_0_CHECK(prob)+ {+ UPDATE_0_CHECK;+ NORMALIZE_CHECK;+ return DUMMY_REP;+ }+ else+ {+ UPDATE_1_CHECK;+ }+ }+ else+ {+ UPDATE_1_CHECK;+ prob = probs + IsRepG1 + state;+ IF_BIT_0_CHECK(prob)+ {+ UPDATE_0_CHECK;+ }+ else+ {+ UPDATE_1_CHECK;+ prob = probs + IsRepG2 + state;+ IF_BIT_0_CHECK(prob)+ {+ UPDATE_0_CHECK;+ }+ else+ {+ UPDATE_1_CHECK;+ }+ }+ }+ state = kNumStates;+ prob = probs + RepLenCoder;+ }+ {+ unsigned limit, offset;+ const CLzmaProb *probLen = prob + LenChoice;+ IF_BIT_0_CHECK(probLen)+ {+ UPDATE_0_CHECK;+ probLen = prob + LenLow + GET_LEN_STATE;+ offset = 0;+ limit = 1 << kLenNumLowBits;+ }+ else+ {+ UPDATE_1_CHECK;+ probLen = prob + LenChoice2;+ IF_BIT_0_CHECK(probLen)+ {+ UPDATE_0_CHECK;+ probLen = prob + LenLow + GET_LEN_STATE + (1 << kLenNumLowBits);+ offset = kLenNumLowSymbols;+ limit = 1 << kLenNumLowBits;+ }+ else+ {+ UPDATE_1_CHECK;+ probLen = prob + LenHigh;+ offset = kLenNumLowSymbols * 2;+ limit = 1 << kLenNumHighBits;+ }+ }+ TREE_DECODE_CHECK(probLen, limit, len);+ len += offset;+ }++ if (state < 4)+ {+ unsigned posSlot;+ prob = probs + PosSlot ++ ((len < kNumLenToPosStates - 1 ? len : kNumLenToPosStates - 1) <<+ kNumPosSlotBits);+ TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);+ if (posSlot >= kStartPosModelIndex)+ {+ unsigned numDirectBits = ((posSlot >> 1) - 1);++ /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */++ if (posSlot < kEndPosModelIndex)+ {+ prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits);+ }+ else+ {+ numDirectBits -= kNumAlignBits;+ do+ {+ NORMALIZE_CHECK+ range >>= 1;+ code -= range & (((code - range) >> 31) - 1);+ /* if (code >= range) code -= range; */+ }+ while (--numDirectBits);+ prob = probs + Align;+ numDirectBits = kNumAlignBits;+ }+ {+ unsigned i = 1;+ unsigned m = 1;+ do+ {+ REV_BIT_CHECK(prob, i, m);+ }+ while (--numDirectBits);+ }+ }+ }+ }+ }+ NORMALIZE_CHECK;+ return res;+}+++void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)+{+ p->remainLen = kMatchSpecLenStart + 1;+ p->tempBufSize = 0;++ if (initDic)+ {+ p->processedPos = 0;+ p->checkDicSize = 0;+ p->remainLen = kMatchSpecLenStart + 2;+ }+ if (initState)+ p->remainLen = kMatchSpecLenStart + 2;+}++void LzmaDec_Init(CLzmaDec *p)+{+ p->dicPos = 0;+ LzmaDec_InitDicAndState(p, True, True);+}+++SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,+ ELzmaFinishMode finishMode, ELzmaStatus *status)+{+ SizeT inSize = *srcLen;+ (*srcLen) = 0;++ *status = LZMA_STATUS_NOT_SPECIFIED;++ if (p->remainLen > kMatchSpecLenStart)+ {+ for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)+ p->tempBuf[p->tempBufSize++] = *src++;+ if (p->tempBufSize != 0 && p->tempBuf[0] != 0)+ return SZ_ERROR_DATA;+ if (p->tempBufSize < RC_INIT_SIZE)+ {+ *status = LZMA_STATUS_NEEDS_MORE_INPUT;+ return SZ_OK;+ }+ p->code =+ ((UInt32)p->tempBuf[1] << 24)+ | ((UInt32)p->tempBuf[2] << 16)+ | ((UInt32)p->tempBuf[3] << 8)+ | ((UInt32)p->tempBuf[4]);+ p->range = 0xFFFFFFFF;+ p->tempBufSize = 0;++ if (p->remainLen > kMatchSpecLenStart + 1)+ {+ SizeT numProbs = LzmaProps_GetNumProbs(&p->prop);+ SizeT i;+ CLzmaProb *probs = p->probs;+ for (i = 0; i < numProbs; i++)+ probs[i] = kBitModelTotal >> 1;+ p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;+ p->state = 0;+ }++ p->remainLen = 0;+ }++ LzmaDec_WriteRem(p, dicLimit);++ while (p->remainLen != kMatchSpecLenStart)+ {+ int checkEndMarkNow = 0;++ if (p->dicPos >= dicLimit)+ {+ if (p->remainLen == 0 && p->code == 0)+ {+ *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK;+ return SZ_OK;+ }+ if (finishMode == LZMA_FINISH_ANY)+ {+ *status = LZMA_STATUS_NOT_FINISHED;+ return SZ_OK;+ }+ if (p->remainLen != 0)+ {+ *status = LZMA_STATUS_NOT_FINISHED;+ return SZ_ERROR_DATA;+ }+ checkEndMarkNow = 1;+ }++ if (p->tempBufSize == 0)+ {+ SizeT processed;+ const Byte *bufLimit;+ if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)+ {+ int dummyRes = LzmaDec_TryDummy(p, src, inSize);+ if (dummyRes == DUMMY_ERROR)+ {+ memcpy(p->tempBuf, src, inSize);+ p->tempBufSize = (unsigned)inSize;+ (*srcLen) += inSize;+ *status = LZMA_STATUS_NEEDS_MORE_INPUT;+ return SZ_OK;+ }+ if (checkEndMarkNow && dummyRes != DUMMY_MATCH)+ {+ *status = LZMA_STATUS_NOT_FINISHED;+ return SZ_ERROR_DATA;+ }+ bufLimit = src;+ }+ else+ bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;+ p->buf = src;+ if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)+ return SZ_ERROR_DATA;+ processed = (SizeT)(p->buf - src);+ (*srcLen) += processed;+ src += processed;+ inSize -= processed;+ }+ else+ {+ unsigned rem = p->tempBufSize, lookAhead = 0;+ while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)+ p->tempBuf[rem++] = src[lookAhead++];+ p->tempBufSize = rem;+ if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)+ {+ int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);+ if (dummyRes == DUMMY_ERROR)+ {+ (*srcLen) += lookAhead;+ *status = LZMA_STATUS_NEEDS_MORE_INPUT;+ return SZ_OK;+ }+ if (checkEndMarkNow && dummyRes != DUMMY_MATCH)+ {+ *status = LZMA_STATUS_NOT_FINISHED;+ return SZ_ERROR_DATA;+ }+ }+ p->buf = p->tempBuf;+ if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)+ return SZ_ERROR_DATA;++ {+ unsigned kkk = (unsigned)(p->buf - p->tempBuf);+ if (rem < kkk)+ return SZ_ERROR_FAIL; /* some internal error */+ rem -= kkk;+ if (lookAhead < rem)+ return SZ_ERROR_FAIL; /* some internal error */+ lookAhead -= rem;+ }+ (*srcLen) += lookAhead;+ src += lookAhead;+ inSize -= lookAhead;+ p->tempBufSize = 0;+ }+ }++ if (p->code != 0)+ return SZ_ERROR_DATA;+ *status = LZMA_STATUS_FINISHED_WITH_MARK;+ return SZ_OK;+}+++SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)+{+ SizeT outSize = *destLen;+ SizeT inSize = *srcLen;+ *srcLen = *destLen = 0;+ for (;;)+ {+ SizeT inSizeCur = inSize, outSizeCur, dicPos;+ ELzmaFinishMode curFinishMode;+ SRes res;+ if (p->dicPos == p->dicBufSize)+ p->dicPos = 0;+ dicPos = p->dicPos;+ if (outSize > p->dicBufSize - dicPos)+ {+ outSizeCur = p->dicBufSize;+ curFinishMode = LZMA_FINISH_ANY;+ }+ else+ {+ outSizeCur = dicPos + outSize;+ curFinishMode = finishMode;+ }++ res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);+ src += inSizeCur;+ inSize -= inSizeCur;+ *srcLen += inSizeCur;+ outSizeCur = p->dicPos - dicPos;+ memcpy(dest, p->dic + dicPos, outSizeCur);+ dest += outSizeCur;+ outSize -= outSizeCur;+ *destLen += outSizeCur;+ if (res != 0)+ return res;+ if (outSizeCur == 0 || outSize == 0)+ return SZ_OK;+ }+}++void LzmaDec_FreeProbs(CLzmaDec *p, ISzAllocPtr alloc)+{+ ISzAlloc_Free(alloc, p->probs);+ p->probs = NULL;+}++static void LzmaDec_FreeDict(CLzmaDec *p, ISzAllocPtr alloc)+{+ ISzAlloc_Free(alloc, p->dic);+ p->dic = NULL;+}++void LzmaDec_Free(CLzmaDec *p, ISzAllocPtr alloc)+{+ LzmaDec_FreeProbs(p, alloc);+ LzmaDec_FreeDict(p, alloc);+}++SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)+{+ UInt32 dicSize;+ Byte d;++ if (size < LZMA_PROPS_SIZE)+ return SZ_ERROR_UNSUPPORTED;+ else+ dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);++ if (dicSize < LZMA_DIC_MIN)+ dicSize = LZMA_DIC_MIN;+ p->dicSize = dicSize;++ d = data[0];+ if (d >= (9 * 5 * 5))+ return SZ_ERROR_UNSUPPORTED;++ p->lc = (Byte)(d % 9);+ d /= 9;+ p->pb = (Byte)(d / 5);+ p->lp = (Byte)(d % 5);++ return SZ_OK;+}++static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAllocPtr alloc)+{+ UInt32 numProbs = LzmaProps_GetNumProbs(propNew);+ if (!p->probs || numProbs != p->numProbs)+ {+ LzmaDec_FreeProbs(p, alloc);+ p->probs = (CLzmaProb *)ISzAlloc_Alloc(alloc, numProbs * sizeof(CLzmaProb));+ if (!p->probs)+ return SZ_ERROR_MEM;+ p->probs_1664 = p->probs + 1664;+ p->numProbs = numProbs;+ }+ return SZ_OK;+}++SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAllocPtr alloc)+{+ CLzmaProps propNew;+ RINOK(LzmaProps_Decode(&propNew, props, propsSize));+ RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));+ p->prop = propNew;+ return SZ_OK;+}++SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAllocPtr alloc)+{+ CLzmaProps propNew;+ SizeT dicBufSize;+ RINOK(LzmaProps_Decode(&propNew, props, propsSize));+ RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));++ {+ UInt32 dictSize = propNew.dicSize;+ SizeT mask = ((UInt32)1 << 12) - 1;+ if (dictSize >= ((UInt32)1 << 30)) mask = ((UInt32)1 << 22) - 1;+ else if (dictSize >= ((UInt32)1 << 22)) mask = ((UInt32)1 << 20) - 1;;+ dicBufSize = ((SizeT)dictSize + mask) & ~mask;+ if (dicBufSize < dictSize)+ dicBufSize = dictSize;+ }++ if (!p->dic || dicBufSize != p->dicBufSize)+ {+ LzmaDec_FreeDict(p, alloc);+ p->dic = (Byte *)ISzAlloc_Alloc(alloc, dicBufSize);+ if (!p->dic)+ {+ LzmaDec_FreeProbs(p, alloc);+ return SZ_ERROR_MEM;+ }+ }+ p->dicBufSize = dicBufSize;+ p->prop = propNew;+ return SZ_OK;+}++SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,+ const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,+ ELzmaStatus *status, ISzAllocPtr alloc)+{+ CLzmaDec p;+ SRes res;+ SizeT outSize = *destLen, inSize = *srcLen;+ *destLen = *srcLen = 0;+ *status = LZMA_STATUS_NOT_SPECIFIED;+ if (inSize < RC_INIT_SIZE)+ return SZ_ERROR_INPUT_EOF;+ LzmaDec_Construct(&p);+ RINOK(LzmaDec_AllocateProbs(&p, propData, propSize, alloc));+ p.dic = dest;+ p.dicBufSize = outSize;+ LzmaDec_Init(&p);+ *srcLen = inSize;+ res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);+ *destLen = p.dicPos;+ if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)+ res = SZ_ERROR_INPUT_EOF;+ LzmaDec_FreeProbs(&p, alloc);+ return res;+}diff --git a/games/celeste/src/lzma/LzmaDec.h b/games/celeste/src/lzma/LzmaDec.hnew file mode 100644index 00000000..28ce60c3--- /dev/null+++ b/games/celeste/src/lzma/LzmaDec.h@@ -0,0 +1,234 @@+/* LzmaDec.h -- LZMA Decoder+2018-04-21 : Igor Pavlov : Public domain */++#ifndef __LZMA_DEC_H+#define __LZMA_DEC_H++#include "7zTypes.h"++EXTERN_C_BEGIN++/* #define _LZMA_PROB32 */+/* _LZMA_PROB32 can increase the speed on some CPUs,+ but memory usage for CLzmaDec::probs will be doubled in that case */++typedef+#ifdef _LZMA_PROB32+ UInt32+#else+ UInt16+#endif+ CLzmaProb;+++/* ---------- LZMA Properties ---------- */++#define LZMA_PROPS_SIZE 5++typedef struct _CLzmaProps+{+ Byte lc;+ Byte lp;+ Byte pb;+ Byte _pad_;+ UInt32 dicSize;+} CLzmaProps;++/* LzmaProps_Decode - decodes properties+Returns:+ SZ_OK+ SZ_ERROR_UNSUPPORTED - Unsupported properties+*/++SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);+++/* ---------- LZMA Decoder state ---------- */++/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.+ Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */++#define LZMA_REQUIRED_INPUT_MAX 20++typedef struct+{+ /* Don't change this structure. ASM code can use it. */+ CLzmaProps prop;+ CLzmaProb *probs;+ CLzmaProb *probs_1664;+ Byte *dic;+ SizeT dicBufSize;+ SizeT dicPos;+ const Byte *buf;+ UInt32 range;+ UInt32 code;+ UInt32 processedPos;+ UInt32 checkDicSize;+ UInt32 reps[4];+ UInt32 state;+ UInt32 remainLen;++ UInt32 numProbs;+ unsigned tempBufSize;+ Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];+} CLzmaDec;++#define LzmaDec_Construct(p) { (p)->dic = NULL; (p)->probs = NULL; }++void LzmaDec_Init(CLzmaDec *p);++/* There are two types of LZMA streams:+ - Stream with end mark. That end mark adds about 6 bytes to compressed size.+ - Stream without end mark. You must know exact uncompressed size to decompress such stream. */++typedef enum+{+ LZMA_FINISH_ANY, /* finish at any point */+ LZMA_FINISH_END /* block must be finished at the end */+} ELzmaFinishMode;++/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!++ You must use LZMA_FINISH_END, when you know that current output buffer+ covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.++ If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,+ and output value of destLen will be less than output buffer size limit.+ You can check status result also.++ You can use multiple checks to test data integrity after full decompression:+ 1) Check Result and "status" variable.+ 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.+ 3) Check that output(srcLen) = compressedSize, if you know real compressedSize.+ You must use correct finish mode in that case. */++typedef enum+{+ LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */+ LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */+ LZMA_STATUS_NOT_FINISHED, /* stream was not finished */+ LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */+ LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */+} ELzmaStatus;++/* ELzmaStatus is used only as output value for function call */+++/* ---------- Interfaces ---------- */++/* There are 3 levels of interfaces:+ 1) Dictionary Interface+ 2) Buffer Interface+ 3) One Call Interface+ You can select any of these interfaces, but don't mix functions from different+ groups for same object. */+++/* There are two variants to allocate state for Dictionary Interface:+ 1) LzmaDec_Allocate / LzmaDec_Free+ 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs+ You can use variant 2, if you set dictionary buffer manually.+ For Buffer Interface you must always use variant 1.++LzmaDec_Allocate* can return:+ SZ_OK+ SZ_ERROR_MEM - Memory allocation error+ SZ_ERROR_UNSUPPORTED - Unsupported properties+*/++SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAllocPtr alloc);+void LzmaDec_FreeProbs(CLzmaDec *p, ISzAllocPtr alloc);++SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAllocPtr alloc);+void LzmaDec_Free(CLzmaDec *p, ISzAllocPtr alloc);++/* ---------- Dictionary Interface ---------- */++/* You can use it, if you want to eliminate the overhead for data copying from+ dictionary to some other external buffer.+ You must work with CLzmaDec variables directly in this interface.++ STEPS:+ LzmaDec_Construct()+ LzmaDec_Allocate()+ for (each new stream)+ {+ LzmaDec_Init()+ while (it needs more decompression)+ {+ LzmaDec_DecodeToDic()+ use data from CLzmaDec::dic and update CLzmaDec::dicPos+ }+ }+ LzmaDec_Free()+*/++/* LzmaDec_DecodeToDic++ The decoding to internal dictionary buffer (CLzmaDec::dic).+ You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!++finishMode:+ It has meaning only if the decoding reaches output limit (dicLimit).+ LZMA_FINISH_ANY - Decode just dicLimit bytes.+ LZMA_FINISH_END - Stream must be finished after dicLimit.++Returns:+ SZ_OK+ status:+ LZMA_STATUS_FINISHED_WITH_MARK+ LZMA_STATUS_NOT_FINISHED+ LZMA_STATUS_NEEDS_MORE_INPUT+ LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK+ SZ_ERROR_DATA - Data error+*/++SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,+ const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);+++/* ---------- Buffer Interface ---------- */++/* It's zlib-like interface.+ See LzmaDec_DecodeToDic description for information about STEPS and return results,+ but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need+ to work with CLzmaDec variables manually.++finishMode:+ It has meaning only if the decoding reaches output limit (*destLen).+ LZMA_FINISH_ANY - Decode just destLen bytes.+ LZMA_FINISH_END - Stream must be finished after (*destLen).+*/++SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,+ const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);+++/* ---------- One Call Interface ---------- */++/* LzmaDecode++finishMode:+ It has meaning only if the decoding reaches output limit (*destLen).+ LZMA_FINISH_ANY - Decode just destLen bytes.+ LZMA_FINISH_END - Stream must be finished after (*destLen).++Returns:+ SZ_OK+ status:+ LZMA_STATUS_FINISHED_WITH_MARK+ LZMA_STATUS_NOT_FINISHED+ LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK+ SZ_ERROR_DATA - Data error+ SZ_ERROR_MEM - Memory allocation error+ SZ_ERROR_UNSUPPORTED - Unsupported properties+ SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).+*/++SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,+ const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,+ ELzmaStatus *status, ISzAllocPtr alloc);++EXTERN_C_END++#endifdiff --git a/games/celeste/src/lzma/Precomp.h b/games/celeste/src/lzma/Precomp.hnew file mode 100644index 00000000..fdaa2452--- /dev/null+++ b/games/celeste/src/lzma/Precomp.h@@ -0,0 +1,5 @@+/* Precomp.h -- StdAfx+2013-11-12 : Igor Pavlov : Public domain */+#ifndef __7Z_PRECOMP_H+#define __7Z_PRECOMP_H+#endifdiff --git a/games/celeste/src/main.c b/games/celeste/src/main.cnew file mode 100644index 00000000..fe31e46b--- /dev/null+++ b/games/celeste/src/main.c@@ -0,0 +1,47 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* Celeste for the NumWorks calculator.+ *+ * Inspired by Celeste, not affiliated with Maddy Makes Games.+ * Made by Mason Chen as part of NumPlay. */+#include "celeste.h"++#ifndef HOST+const char eadk_app_name[] __attribute__((section(".rodata.eadk_app_name"))) = "Celeste";+const uint32_t eadk_api_level __attribute__((section(".rodata.eadk_api_level"))) = 0;+extern const uint8_t cel_data[];++void plat_begin(void);+int plat_end(void);++uint32_t perf_frames __attribute__((used)); /* read by tools/emu.py */+uint32_t perf_updates __attribute__((used));++int main(void) {+ plat_begin();+ cel_bin = cel_data;+ game_init();+ uint32_t next = plat_millis() * 3; /* in thirds of a millisecond: 50 per update */+ while (g_running) {+ /* 60 updates a second; draw when caught up (at most 2 updates per frame) */+ int n = 0;+ uint32_t now = plat_millis() * 3;+ while ((int32_t)(now - next) >= 0 && n < 2 && g_running) {+ game_frame();+ perf_updates++;+ next += 50;+ n++;+ }+ if (!g_running) break;+ if ((int32_t)(now - next) > 300) next = now; /* far behind: do not rush */+ if (n) {+ game_draw();+ perf_frames++;+ } else+ plat_sleep(1);+ }+ game_save();+ return plat_end();+}+#endifdiff --git a/games/celeste/src/menu.c b/games/celeste/src/menu.cnew file mode 100644index 00000000..4f1616e4--- /dev/null+++ b/games/celeste/src/menu.c@@ -0,0 +1,714 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* The menus, like the game's own: the title (OuiTitleScreen), the main menu+ * (OuiMainMenu), the chapter select (OuiChapterSelect, OuiChapterPanel),+ * options with the key bindings, the key sheet, the credits, the chapter's end+ * (AreaComplete) and the pause menu (Level.Pause, TextMenu). Words come from+ * the dialog (UISTR) and are drawn straight into the strips: nothing is kept. */+#include "cutscene.h"+#include "text.h"++enum { S_NONE, S_SHEET, S_TITLE, S_MAIN, S_CHAPTERS, S_PANEL, S_OPTIONS, S_KEYS, S_CREDITS, S_COMPLETE, S_PAUSE, S_CONFIRM };+static struct {+ uint8_t screen, back; /* back: where Back goes from the options (S_PAUSE or S_MAIN) */+ int8_t sel, area, mode, cp, binding, confirm;+ uint8_t hold, last_dir; /* the arrows' repeat */+ float t, wig, repeat;+} M;+uint8_t g_menu; /* the screen on (S_NONE while playing) */++/* ---------------------------------------------------------------- drawing: pictures, then words */+static int pass; /* 0: pictures and boxes (commands), 1: words (into the strip) */+static uint16_t *strip_;+static int sy0_, sy1_;+static void say(const char *s, float x, float y, float jx, float jy, float sc, uint16_t col, uint8_t a) {+ if (pass && a) text_into(strip_, sy0_, sy1_, s, x, y, jx, jy, sc, col, a);+}+static void pic(uint16_t tex, float x, float y, float jx, float jy, float sc, uint16_t tint, uint8_t a) {+ Tex t;+ if (pass || !a || !tex_get(tex, &t)) return;+ gfx_tex_ex(tex, x / 6, y / 6, t.fw * t.scale * jx, t.fh * t.scale * jy, sc, sc, 0, tint, a, 0);+}+static void box(float x, float y, float w, float h, uint16_t col, uint8_t a) {+ if (!pass) gfx_rect(x / 6, y / 6, w / 6, h / 6, col, a);+}+static uint16_t highlight(void) { /* TextMenu.HighlightColor: A and B in turn */+ return fmodf(g_level.raw_time_active + M.t, 0.2f) < 0.1f ? rgb(0x84FF54) : rgb(0xFCFF59);+}+#define WHITE 0xFFFF+#define GRAY rgb(0x808080)+#define SLATE rgb(0x2F4F4F)++/* the overworld behind the menus: a night sky and HiresSnow (50 flakes blown left) */+static void backdrop(void) {+ if (pass) return;+ static const uint32_t sky[6] = {0x0b0d24, 0x121633, 0x1a1e45, 0x262759, 0x35306a, 0x45376f};+ for (int i = 0; i < 6; i++) gfx_rect(0, i * 30, VIEW_W, 30, rgb(sky[i]), 255);+ Tex t;+ if (!tex_get(T__snow, &t)) return;+ float time = M.t + 100;+ for (int i = 0; i < 24; i++) {+ uint32_t h = (uint32_t)i * 2654435761u;+ float n = (h >> 8 & 255) / 255.f;+ n = n * n * n * n;+ float sc = 0.05f + n * 0.75f, speed = sc * (2500 + (h >> 16 & 255) * 10);+ float x = 2176 - fmodf(time * speed + (h & 0xFFFF), 2176) - 128, y = (h >> 4 & 1023) + sinf(time + i) * 100;+ gfx_tex_ex(T__snow, x / 6, fmodf(y, 1080) / 6, t.fw * t.scale / 2.f, t.fh * t.scale / 2.f, sc, sc, 0, WHITE,+ (uint8_t)(255 * (1 - n * 0.8f) * 0.6f), GF_ADD);+ }+}++/* ---------------------------------------------------------------- input: confirm, cancel, the arrows with repeat */+static bool confirm(void) { return btn_pressed(&g_in.confirm); }+static bool cancel(void) { return btn_pressed(&g_in.back); }+static int dir_pressed(int axis) { /* -1, 0, 1: the arrows, repeating while held (MenuUp/MenuDown) */+ int d = axis ? g_in.move_y : g_in.move_x;+ uint8_t code = (uint8_t)(d ? (axis ? 3 : 1) + (d > 0) * 4 : 0);+ if (!d) return 0;+ if (M.last_dir != code) {+ M.last_dir = code, M.repeat = 0.4f;+ return d;+ }+ if ((M.repeat -= RAW_DT) <= 0) {+ M.repeat = 0.1f;+ return d;+ }+ return 0;+}+static void inputs_end(void) {+ if (!g_in.move_x && !g_in.move_y) M.last_dir = 0;+}+static void go(int screen, int sel) {+ M.screen = (uint8_t)screen, M.sel = (int8_t)sel, M.t = 0, M.wig = 0;+ g_menu = (uint8_t)screen;+ btn_consume(&g_in.confirm);+ btn_consume(&g_in.back);+}++/* ---------------------------------------------------------------- chapters: what the save has */+int chapter_count(void) { return rd16(section(SEC_CHAPTERS)); }+static uint16_t area_icon(int a) {+ static const uint16_t ids[10] = {T__areas_intro, T__areas_city, T__areas_oldsite, T__areas_resort, T__areas_cliffside,+ T__areas_temple, T__areas_reflection, T__areas_Summit, T__areas_intro, T__areas_core};+ return ids[a];+}+static const uint32_t TITLE_BASE[10] = {0x383838, 0x6c7c81, 0x247F35, 0xb93c27, 0xFF7F83, 0x8314bc, 0x359FE0, 0xFFD819, 0x383838, 0x761008};+static const uint32_t TITLE_ACCENT[10] = {0x50AFAE, 0x2f344b, 0xE4EF69, 0xffdd42, 0x6D54B7, 0xdf72f9, 0x3C5CBC, 0x197DB7, 0x50AFAE, 0xE0201D};+static bool interlude(int a) { return a == 0 || a == 8; }+static int max_area(void) { /* the last chapter there is, up to the ones unlocked */+ int m = 0;+ for (int a = 0; a <= 9; a++)+ if (chapter_index(a, M_A) >= 0 && a <= g_save.unlocked_areas) m = a;+ return m;+}+static bool has_mode(int a, int mode) {+ if (chapter_index(a, mode) < 0 || interlude(a)) return mode == M_A && chapter_index(a, M_A) >= 0;+ if (mode == M_B) return (g_save.cassettes >> a & 1) != 0;+ if (mode == M_C) return save_unlocked_modes() >= 3;+ return true;+}+static int popcount64(uint64_t v) {+ int n = 0;+ for (; v; v &= v - 1) n++;+ return n;+}+static bool session_here(void) {+ return g_save.has_session && g_session.in_area && g_session.area == M.area && g_session.mode == M.mode;+}+/* the panel's start points: Continue (a session here), Start, then the checkpoints reached */+static int start_count(int *ncp) {+ int ch = chapter_index(M.area, M.mode);+ *ncp = 0;+ if (ch < 0) return 0;+ const uint8_t *c = chapter_at(ch);+ int n = c[CH_NCHECKPOINTS], k = 0;+ for (int i = 0; i < n; i++)+ if (g_save.modes[M.area][M.mode].checkpoints >> i & 1) k++;+ *ncp = k;+ return (session_here() ? 1 : 0) + 1 + k;+}+static int nth_checkpoint(int k) { /* the k-th checkpoint reached */+ for (int i = 0; i < 8; i++)+ if (g_save.modes[M.area][M.mode].checkpoints >> i & 1 && k-- == 0) return i;+ return 0;+}+static void checkpoint_name(int i, char *out) { /* Dialog checkpoint_{area}{h}_{i} (Core's are 8's) */+ static const char *const ids[10] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "8"};+ char k[24] = "checkpoint_";+ strcat(k, ids[M.area]);+ if (M.mode == M_B) strcat(k, M.area >= 7 ? "H" : "h");+ int n = (int)strlen(k);+ k[n] = '_', k[n + 1] = (char)('0' + i), k[n + 2] = 0;+ strcpy(out, ui_str(k));+}++/* ---------------------------------------------------------------- game flow */+static void play_chapter(int start) { /* the panel's choice: Continue, Start or a checkpoint */+ int ncp;+ int n = start_count(&ncp);+ (void)n;+ g_menu = M.screen = S_NONE;+ if (session_here() && start == 0) {+ game_play(-1, -1);+ return;+ }+ int k = start - (session_here() ? 1 : 0);+ game_play(chapter_index(M.area, M.mode), k == 0 ? -1 : nth_checkpoint(k - 1));+}+void menu_open_overworld(bool completed) { /* the chapter select: after a chapter, its end first */+ M.area = (int8_t)(g_save.last_area <= 9 ? g_save.last_area : 1);+ M.mode = (int8_t)g_save.last_mode;+ if (M.area > max_area()) M.area = (int8_t)max_area();+ go(completed ? S_COMPLETE : S_CHAPTERS, 0);+}+void menu_open_title(void) { go(g_save.key_sheet_seen ? S_TITLE : S_SHEET, 0); }+void menu_open_main(void) { go(S_MAIN, 0); }++/* ---------------------------------------------------------------- the key sheet (as NumBlocks has it) */+static const char *key_name(int k) {+ static const char *const names[53] = {+ [4] = "OK", [5] = "Back", [6] = "Home", [12] = "shift", [13] = "alpha", [14] = "x,n,t", [15] = "var", [16] = "toolbox",+ [17] = "<x", [18] = "e^x", [19] = "ln", [20] = "log", [21] = "i", [22] = ",", [23] = "x^y", [24] = "sin",+ [25] = "cos", [26] = "tan", [27] = "pi", [28] = "sqrt", [29] = "x^2", [30] = "7", [31] = "8", [32] = "9",+ [33] = "(", [34] = ")", [36] = "4", [37] = "5", [38] = "6", [39] = "x", [40] = "/", [42] = "1", [43] = "2",+ [44] = "3", [45] = "+", [46] = "-", [48] = "0", [49] = ".", [50] = "x10^x", [51] = "ans", [52] = "EXE"};+ return k < 53 && names[k] ? names[k] : "?";+}+static const char *const ACTION_KEYS[4] = {"KEY_CONFIG_JUMP", "KEY_CONFIG_DASH", "KEY_CONFIG_GRAB", "KEY_CONFIG_TALK"};+static const char *action_on(int k) {+ for (int a = 0; a < 4; a++)+ if (g_bind[a] == k) return ui_str(ACTION_KEYS[a]);+ return NULL;+}+static void key_cap(float x, float y, float w, int k, const char *what) { /* a key: bright with what it does */+ box(x, y, w, 174, what ? rgb(0xA0A0A0) : rgb(0x505050), 255);+ box(x + 6, y + 6, w - 12, 162, what ? rgb(0x282828) : rgb(0x181818), 255);+ say(key_name(k), x + w / 2, y + (what ? 52 : 87), 0.5f, 0.5f, 0.8f, what ? WHITE : rgb(0x707070), 255);+ if (what) say(what, x + w / 2, y + 124, 0.5f, 0.5f, 0.8f, rgb(0xFFFFA0), 255);+}+static void sheet_draw(void) {+ say("Controls", 960, 40, 0.5f, 0.5f, 1, WHITE, 255);+ /* the arrows' pad */+ if (!pass) {+ gfx_circle(40, 52, 26, rgb(0xA0A0A0), 255, 24);+ gfx_circle(40, 52, 24, rgb(0x282828), 255, 24);+ }+ say("Move", 240, 312, 0.5f, 0.5f, 0.8f, rgb(0xFFFFA0), 255);+ key_cap(780, 160, 360, 6, "Save, quit");+ key_cap(1416, 80, 480, 4, action_on(4));+ key_cap(1416, 272, 480, 5, ui_str("KEY_CONFIG_PAUSE"));+ for (int r = 0; r < 3; r++)+ for (int c = 0; c < 6; c++) {+ int k = 12 + r * 6 + c;+ key_cap(c < 2 ? 30 + c * 222 : 474 + (c - 2) * 360, 480 + r * 192, c < 2 ? 204 : 342, k, action_on(k));+ }+ say("Menus: OK or EXE confirm, Back cancels.", 960, 1050, 0.5f, 0.5f, 0.8f, WHITE, 255);+}+static void sheet_update(void) {+ if (confirm() || cancel()) {+ if (!g_save.key_sheet_seen) g_save.key_sheet_seen = 1, save_write();+ go(M.back == S_OPTIONS ? S_OPTIONS : S_TITLE, M.back == S_OPTIONS ? 1 : 0);+ }+}++/* ---------------------------------------------------------------- title and main menu */+static void title_draw(void) {+ backdrop();+ float a = fminf(1, M.t * 2);+ pic(T__title, 960, 400, 0.5f, 0.5f, 1, WHITE, (uint8_t)(a * 255));+ if (fmodf(M.t, 1) < 0.75f) pic(T__textboxbutton, 1824, 984, 0.5f, 0.5f, 1, WHITE, (uint8_t)(a * 255));+}+static void title_update(void) {+ if (M.t > 0.3f && (confirm() || cancel())) go(S_MAIN, 0);+}++static void main_draw(void) {+ static const char *const words[4] = {"MENU_BEGIN", "MENU_OPTIONS", "MENU_CREDITS", "MENU_EXIT"};+ static const uint16_t icons[4] = {T__menu_start, T__menu_options, T__menu_credits, T__menu_exit};+ backdrop();+ for (int i = 0; i < 4; i++) {+ bool on = M.sel == i;+ float x = 300 + (on ? 24 : 0), y = i == 0 ? 360 : 560 + (i - 1) * 140;+ float sc = i == 0 ? 1 : 0.6f;+ pic(icons[i], x + (i ? 50 : 100), y, 0.5f, 0.5f, sc, WHITE, 255);+ say(ui_str(words[i]), x + (i ? 120 : 230), y, 0, 0.5f, i == 0 ? 2 : 1, on ? highlight() : WHITE, 255);+ }+}+static void main_update(void) {+ int d = dir_pressed(1);+ if (d) M.sel = (int8_t)((M.sel + d + 4) % 4), M.wig = 0;+ if (cancel()) go(S_TITLE, 0);+ else if (confirm()) switch (M.sel) {+ case 0:+ M.area = (int8_t)(g_save.last_area <= max_area() ? g_save.last_area : max_area());+ M.mode = (int8_t)g_save.last_mode;+ go(S_CHAPTERS, 0);+ if (g_save.has_session && g_session.in_area) go(S_PANEL, 0); /* (the run Home saved: Continue first) */+ break;+ case 1: M.back = S_MAIN, go(S_OPTIONS, 0); break;+ case 2: go(S_CREDITS, 0); break;+ case 3: g_running = false; break;+ }+}++/* ---------------------------------------------------------------- chapter select and panel */+static void banner(float x, float y, int a, float alpha) { /* the title: areaselect/title and accent, chapter and name */+ uint8_t al = (uint8_t)(alpha * 255);+ pic(T__areaselect_title, x, y, 0, 0, 1, rgb(TITLE_BASE[a]), al);+ pic(T__areaselect_accent, x, y, 0, 0, 1, rgb(TITLE_ACCENT[a]), al);+ char name[16] = "AREA_";+ name[5] = (char)('0' + a), name[6] = 0;+ uint16_t text = a == 7 ? 0 : WHITE;+ if (interlude(a)) say(ui_str(name), x + 816, y + 86, 1, 0.5f, 1, text, (uint8_t)(al * 0.8f));+ else {+ char chapter[24];+ const char *c = ui_str("AREA_CHAPTER");+ int n = 0;+ for (; *c && n < 20; c++) { /* "Chapter {x}" */+ if (*c == '{') {+ while (*c && *c != '}') c++;+ chapter[n++] = (char)('0' + (a == 9 ? 8 : a));+ continue;+ }+ chapter[n++] = *c;+ }+ chapter[n] = 0;+ say(chapter, x + 816, y + 84, 1, 1, 0.6f, rgb(TITLE_ACCENT[a]), (uint8_t)(al * 0.8f));+ say(ui_str(name), x + 816, y + 66, 1, 0, 1, text, (uint8_t)(al * 0.8f));+ }+}+static void chapters_draw(void) {+ backdrop();+ int top = max_area();+ for (int a = 0; a <= top; a++) { /* the icons across the top, the chosen one bigger and lower */+ if (chapter_index(a, M_A) < 0) continue;+ bool on = a == M.area;+ float x = 960 + (a - M.area) * 220, y = on ? 360 : 200;+ pic(area_icon(a), x, y, 0.5f, 0.5f, on ? 1.25f + sinf(M.wig * 20) * 0.04f * fmaxf(0, 1 - M.wig * 3) : 0.75f, WHITE, 255);+ }+ banner(552, 620, M.area, 1);+ ModeStats *ms = &g_save.modes[M.area][M_A];+ if (!interlude(M.area) && (ms->berries || (ms->flags & MS_COMPLETED))) {+ char b[16];+ int ch = chapter_index(M.area, M_A), total = ch >= 0 ? chapter_at(ch)[CH_DETECTED] : 0;+ int got = popcount64(ms->berries);+ pic(T__collectables_strawberry, 840, 880, 0.5f, 0.5f, 0.6f, WHITE, 255);+ b[0] = 0;+ char *p = b;+ p += uitoa(got, p);+ *p++ = '/';+ uitoa(total, p);+ say(b, 890, 880, 0, 0.5f, 1, WHITE, 255);+ }+}+static void chapters_update(void) {+ int d = dir_pressed(0);+ if (d) {+ int a = M.area + d;+ while (a >= 0 && a <= max_area() && chapter_index(a, M_A) < 0) a += d;+ if (a >= 0 && a <= max_area()) M.area = (int8_t)a, M.wig = 0;+ }+ if (cancel()) go(S_MAIN, 0);+ else if (confirm()) {+ M.mode = M_A;+ go(S_PANEL, session_here() ? 0 : 0);+ }+}++static void panel_draw(void) {+ backdrop();+ float x = 900, y = 160;+ box(x - 24, y - 24, 1000, 880, rgb(0xE8E4DC), 255); /* the card */+ box(x - 24, y - 24, 1000, 20, rgb(0xC8C4BC), 255);+ banner(x - 60, y, M.area, 1);+ pic(area_icon(M.area), x + 860, y + 86, 0.5f, 0.5f, 0.8f, WHITE, 255);+ /* the sides: A, B, C */+ static const char *const modes[3] = {"OVERWORLD_NORMAL", "OVERWORLD_REMIX", "OVERWORLD_REMIX2"};+ float mx = x + 40;+ for (int m = 0; m < 3; m++) {+ if (!has_mode(M.area, m)) continue;+ const char *w = interlude(M.area) ? ui_str("FILE_BEGIN") : ui_str(modes[m]);+ say(w, mx, y + 280, 0, 0.5f, 0.8f, m == M.mode ? rgb(0x101010) : rgb(0x808080), 255);+ if (m == M.mode) box(mx, y + 314, text_measure(w) * 0.8f, 8, rgb(TITLE_BASE[M.area]), 255);+ mx += text_measure(w) * 0.8f + 60;+ }+ /* where to start */+ int ncp, n = start_count(&ncp);+ bool cont = session_here();+ for (int i = 0; i < n; i++) {+ char name[48];+ if (cont && i == 0) strcpy(name, ui_str("FILE_CONTINUE"));+ else if (i == (cont ? 1 : 0)) strcpy(name, ui_str("OVERWORLD_START"));+ else checkpoint_name(nth_checkpoint(i - (cont ? 2 : 1)), name);+ say(name, x + 60, y + 400 + i * 72, 0, 0.5f, 0.9f, i == M.sel ? highlight() : rgb(0x303030), 255);+ }+ /* the stats: strawberries, deaths, the heart, the cassette */+ ModeStats *ms = &g_save.modes[M.area][M.mode];+ if (!interlude(M.area)) {+ char b[24], *p = b;+ int ch = chapter_index(M.area, M.mode), total = ch >= 0 ? chapter_at(ch)[CH_DETECTED] : 0;+ p += uitoa(popcount64(ms->berries), p);+ *p++ = '/';+ uitoa(total, p);+ pic(T__collectables_strawberry, x + 80, y + 790, 0.5f, 0.5f, 0.6f, WHITE, 255);+ say(b, x + 130, y + 790, 0, 0.5f, 0.8f, rgb(0x303030), 255);+ p = b;+ uitoa((int)ms->deaths, p);+ pic(T__collectables_skullBlue, x + 420, y + 790, 0.5f, 0.5f, 0.6f, WHITE, 255);+ say(b, x + 460, y + 790, 0, 0.5f, 0.8f, rgb(0x303030), 255);+ if (ms->flags & MS_HEART) {+ static const uint16_t hearts[3] = {SB_gui_heartgem0, SB_gui_heartgem1, SB_gui_heartgem2};+ Sprite s;+ spr_init(&s, hearts[M.mode]);+ s.sx = s.sy = 0.4f;+ if (!pass) gfx_hud(true), spr_draw(&s, (x + 760) / 6, (y + 790) / 6);+ }+ if (M.mode == M_A && (g_save.cassettes >> M.area & 1)) pic(T__collectables_cassette, x + 880, y + 790, 0.5f, 0.5f, 0.25f, WHITE, 255);+ }+}+static void panel_update(void) {+ int ncp, n = start_count(&ncp);+ int d = dir_pressed(1);+ if (d && n) M.sel = (int8_t)((M.sel + d + n) % n);+ d = dir_pressed(0);+ if (d) {+ int m = M.mode + d;+ while (m >= 0 && m < 3 && !has_mode(M.area, m)) m += d;+ if (m >= 0 && m < 3) M.mode = (int8_t)m, M.sel = 0;+ }+ if (cancel()) go(S_CHAPTERS, 0);+ else if (confirm() && n) play_chapter(M.sel);+}++/* ---------------------------------------------------------------- options and keys (TextMenu) */+#define OPT_SHAKE 1+#define OPT_FLASH 2+static const char *on_off(bool on) { return ui_str(on ? "OPTIONS_ON" : "OPTIONS_OFF"); }+static void menu_item(const char *w, const char *value, int i, float y, bool disabled) {+ uint16_t col = disabled ? SLATE : i == M.sel ? highlight() : WHITE;+ if (value) {+ say(w, 560, y, 0, 0.5f, 1, col, 255);+ say(value, 1360, y, 0.5f, 0.5f, 0.8f, col, 255);+ } else+ say(w, 960, y, 0.5f, 0.5f, 1, col, 255);+}+static void options_draw(void) {+ if (M.back == S_MAIN) backdrop();+ else box(0, 0, 1920, 1080, 0, 178);+ say(ui_str("OPTIONS_TITLE"), 960, 200, 0.5f, 0.5f, 2, GRAY, 255);+ static const char *const clocks[3] = {"OPTIONS_OFF", "OPTIONS_SPEEDRUN_CHAPTER", "OPTIONS_SPEEDRUN_FILE"};+ menu_item(ui_str("OPTIONS_KEYCONFIG"), NULL, 0, 380, false);+ menu_item("Key Sheet", NULL, 1, 448, false);+ menu_item(ui_str("OPTIONS_DISABLE_SHAKE"), on_off(!(g_save.options & OPT_SHAKE)), 2, 560, false);+ menu_item(ui_str("OPTIONS_DISABLE_FLASH"), on_off(g_save.options & OPT_FLASH), 3, 628, false);+ menu_item(ui_str("OPTIONS_SPEEDRUN"), ui_str(clocks[g_save.options >> 2 & 3]), 4, 696, false);+}+static void options_update(void) {+ int d = dir_pressed(1);+ if (d) M.sel = (int8_t)((M.sel + d + 5) % 5);+ int h = dir_pressed(0);+ bool ok = confirm();+ if (M.sel == 2 && (h || ok)) g_save.options ^= OPT_SHAKE;+ if (M.sel == 3 && (h || ok)) g_save.options ^= OPT_FLASH;+ if (M.sel == 4 && (h || ok)) {+ int c = ((g_save.options >> 2 & 3) + (h < 0 ? 2 : 1)) % 3;+ g_save.options = (uint8_t)((g_save.options & ~12) | c << 2);+ }+ if (ok && M.sel == 0) go(S_KEYS, 0), M.binding = -1;+ else if (ok && M.sel == 1) {+ uint8_t b = M.back;+ go(S_SHEET, 0);+ M.back = S_OPTIONS;+ (void)b;+ } else if (cancel()) {+ save_write();+ if (M.back == S_PAUSE) go(S_PAUSE, 0);+ else go(S_MAIN, 1);+ }+}+static bool bindable(int k) { return k == 4 || (k >= 12 && k <= 51 && k != 35 && k != 41 && k != 47); }+static void keys_draw(void) {+ if (M.back == S_MAIN) backdrop();+ else box(0, 0, 1920, 1080, 0, 178);+ say(ui_str("KEY_CONFIG_TITLE"), 960, 200, 0.5f, 0.5f, 2, GRAY, 255);+ say(ui_str("KEY_CONFIG_GAMEPLAY"), 960, 330, 0.5f, 0.5f, 0.6f, GRAY, 255);+ for (int a = 0; a < 4; a++) menu_item(ui_str(ACTION_KEYS[a]), M.binding == a ? "..." : key_name(g_bind[a]), a, 400 + a * 68, false);+ menu_item(ui_str("KEY_CONFIG_RESET"), NULL, 4, 700, false);+ if (M.binding >= 0) {+ char w[48];+ strcpy(w, ui_str("KEY_CONFIG_CHANGING"));+ strcat(w, " ");+ strcat(w, ui_str(ACTION_KEYS[M.binding]));+ say(w, 960, 860, 0.5f, 0.5f, 0.8f, WHITE, 255);+ }+}+static void keys_update(void) {+ if (M.binding >= 0) { /* the next key pressed */+ int k = plat_key_pressed();+ if (k < 0) return;+ if (bindable(k)) g_bind[M.binding] = (uint8_t)k, memcpy(g_save.bind, g_bind, 4), save_write();+ M.binding = -1;+ btn_consume(&g_in.confirm);+ return;+ }+ int d = dir_pressed(1);+ if (d) M.sel = (int8_t)((M.sel + d + 5) % 5);+ if (confirm()) {+ if (M.sel < 4) M.binding = M.sel, plat_key_pressed();+ else plat_default_binds(), memcpy(g_save.bind, g_bind, 4), save_write();+ } else if (cancel())+ go(S_OPTIONS, 0);+}++/* ---------------------------------------------------------------- credits */+static void credits_draw(void) {+ backdrop();+ pic(T__title, 960, 380, 0.5f, 0.5f, 0.8f, WHITE, 255);+ say("Inspired by Celeste, not affiliated with Maddy Makes Games", 960, 620, 0.5f, 0.5f, 0.8f, WHITE, 255);+ say("Made by Mason Chen as part of NumPlay", 960, 720, 0.5f, 0.5f, 0.8f, WHITE, 255);+}+static void credits_update(void) {+ if (confirm() || cancel()) go(S_MAIN, 2);+}++/* ---------------------------------------------------------------- the chapter's end (AreaComplete) */+static void complete_draw(void) {+ int a = M.area;+ box(0, 0, 1920, 1080, rgb(TITLE_BASE[a]), 255);+ box(0, 760, 1920, 320, rgb(TITLE_ACCENT[a]), 255);+ pic(area_icon(a), 960, 300, 0.5f, 0.5f, 1.5f, WHITE, 255);+ ModeStats *ms = &g_save.modes[a][M.mode];+ const char *head = M.mode == M_B ? "AREACOMPLETE_BSIDE" : M.mode == M_C ? "AREACOMPLETE_CSIDE"+ : (ms->flags & MS_FULLCLEAR) ? "AREACOMPLETE_NORMAL_FULLCLEAR" : "AREACOMPLETE_NORMAL";+ say(ui_str(head), 960, 560, 0.5f, 0.5f, 2, a == 7 ? 0 : WHITE, 255);+ char b[32], *p = b;+ int ch = chapter_index(a, M.mode);+ p += uitoa(popcount64(ms->berries), p);+ *p++ = '/';+ uitoa(ch >= 0 ? chapter_at(ch)[CH_DETECTED] : 0, p);+ if (!interlude(a)) {+ pic(T__collectables_strawberry, 640, 900, 0.5f, 0.5f, 0.8f, WHITE, 255);+ say(b, 700, 900, 0, 0.5f, 1, WHITE, 255);+ p = b;+ uitoa((int)g_session.deaths, p);+ pic(T__collectables_skullBlue, 1060, 900, 0.5f, 0.5f, 0.8f, WHITE, 255);+ say(b, 1110, 900, 0, 0.5f, 1, WHITE, 255);+ }+ time_text(g_session.time, b);+ say(b, 960, 1000, 0.5f, 0.5f, 0.8f, WHITE, 255);+ if (M.t > 1 && fmodf(M.t, 1) < 0.75f) pic(T__textboxbutton, 1824, 984, 0.5f, 0.5f, 1, WHITE, 255);+}+static void complete_update(void) {+ if (M.t > 1 && (confirm() || cancel())) {+ M.area = (int8_t)(g_save.unlocked_areas <= max_area() ? g_save.unlocked_areas : max_area());+ M.mode = M_A;+ go(S_CHAPTERS, 0);+ }+}++/* ---------------------------------------------------------------- the pause menu (Level.Pause) */+enum { P_RESUME, P_SKIP, P_RETRY, P_OPTIONS, P_SAVEQUIT, P_RESTART, P_RETURN, P_COUNT };+static int pause_items(int8_t *items) {+ int n = 0;+ items[n++] = P_RESUME;+ if (g_level.in_cutscene && !g_level.skipping_cutscene) items[n++] = P_SKIP;+ if (!g_level.in_cutscene && !g_level.skipping_cutscene) items[n++] = P_RETRY;+ items[n++] = P_OPTIONS;+ items[n++] = P_SAVEQUIT;+ items[n++] = P_RESTART;+ if (g_save.modes[0][0].flags & MS_COMPLETED) items[n++] = P_RETURN;+ return n;+}+static bool pause_disabled(int item) {+ if (item == P_RETRY) return g_level.no_retry || g_level.frozen || g_level.completed || g_player.dead;+ if (item == P_SAVEQUIT) return g_player.state == ST_REFLECTIONFALL;+ return false;+}+static void pause_draw(void) {+ static const char *const words[P_COUNT] = {"MENU_PAUSE_RESUME", "MENU_PAUSE_SKIP_CUTSCENE", "MENU_PAUSE_RETRY",+ "MENU_PAUSE_OPTIONS", "MENU_PAUSE_SAVEQUIT", "MENU_PAUSE_RESTARTAREA",+ "MENU_PAUSE_RETURN"};+ box(0, 0, 1920, 1080, 0, 178); /* HudRenderer.BackgroundFade */+ int8_t items[P_COUNT];+ int n = pause_items(items);+ float h = 128 + n * 68 + 40, y = 540 - h / 2 + 64;+ say(ui_str("MENU_PAUSE_TITLE"), 960, y, 0.5f, 0.5f, 2, GRAY, 255);+ y += 64 + 34;+ for (int i = 0; i < n; i++) {+ if (items[i] == P_RESTART) y += 40; /* SubHeader("") */+ menu_item(ui_str(words[items[i]]), NULL, i, y + 34, pause_disabled(items[i]));+ y += 68;+ }+}+static void confirm_draw(void) {+ box(0, 0, 1920, 1080, 0, 178);+ bool restart = M.confirm == 0;+ say(ui_str(restart ? "MENU_RESTART_TITLE" : "MENU_RETURN_TITLE"), 960, 360, 0.5f, 0.5f, 2, GRAY, 255);+ menu_item(ui_str(restart ? "MENU_RESTART_CONTINUE" : "MENU_RETURN_CONTINUE"), NULL, 0, 520, false);+ menu_item(ui_str(restart ? "MENU_RESTART_CANCEL" : "MENU_RETURN_CANCEL"), NULL, 1, 588, false);+}+void menu_pause(void) { /* Level.Pause */+ g_level.paused = true;+ go(S_PAUSE, 0);+}+static void unpause(void) {+ g_level.paused = false;+ g_menu = M.screen = S_NONE;+ level_freeze(0.15f); /* Engine.FreezeTimer */+ btn_consume(&g_in.jump);+ btn_consume(&g_in.dash);+}+static void pause_update(void) {+ int8_t items[P_COUNT];+ int n = pause_items(items);+ int d = dir_pressed(1);+ if (d)+ for (int k = 0; k < n; k++) { /* (disabled ones are skipped) */+ M.sel = (int8_t)((M.sel + d + n) % n);+ if (!pause_disabled(items[M.sel])) break;+ }+ if (cancel() || btn_pressed(&g_in.pause)) {+ unpause();+ return;+ }+ if (!confirm() || pause_disabled(items[M.sel])) return;+ switch (items[M.sel]) {+ case P_RESUME: unpause(); break;+ case P_SKIP:+ unpause();+ level_skip_cutscene();+ break;+ case P_RETRY:+ unpause();+ g_time_rate = 1;+ g_level.in_cutscene = g_level.skipping_cutscene = false;+ player_die_ex(&g_player, v2(0, 0), true, true);+ break;+ case P_OPTIONS: M.back = S_PAUSE, go(S_OPTIONS, 0); break;+ case P_SAVEQUIT: /* the session kept, a death counted: on to the map */+ g_level.paused = false;+ g_session.deaths++, g_session.deaths_in_current_level++;+ save_add_death();+ g_menu = M.screen = S_NONE;+ level_save_and_quit();+ break;+ case P_RESTART: M.confirm = 0, go(S_CONFIRM, 1); break;+ case P_RETURN: M.confirm = 1, go(S_CONFIRM, 1); break;+ }+}+static void confirm_update(void) {+ int d = dir_pressed(1);+ if (d) M.sel = (int8_t)((M.sel + d + 2) % 2);+ if (cancel() || (confirm() && M.sel == 1)) {+ go(S_PAUSE, 0);+ return;+ }+ if (!confirm()) return;+ g_level.paused = false;+ g_menu = M.screen = S_NONE;+ level_give_up(M.confirm == 0); /* GiveUp: the chapter again, or the map */+}++/* ---------------------------------------------------------------- the level's HUD: TotalStrawberriesDisplay, the speedrun clock */+static struct { float lerp, update, wait, y; int amount; bool started; } H;+int save_total_berries(void) { /* SaveData.TotalStrawberries */+ int n = 0;+ for (int a = 0; a < AREAS; a++)+ for (int m = 0; m < 3; m++) n += popcount64(g_save.modes[a][m].berries);+ return n;+}+void hud_update(void) {+ int total = save_total_berries();+ if (!H.started) H.started = true, H.amount = total, H.y = 96;+ if (total > H.amount && H.update <= 0) H.update = 0.4f;+ if (total > H.amount || H.update > 0 || H.wait > 0 || g_level.paused) H.lerp = approach(H.lerp, 1, 1.2f * RAW_DT);+ else H.lerp = approach(H.lerp, 0, 2 * RAW_DT);+ if (H.wait > 0) H.wait -= RAW_DT;+ if (H.update > 0 && H.lerp == 1) {+ H.update -= RAW_DT;+ if (H.update <= 0) {+ if (H.amount < total) H.amount++;+ H.wait = 2;+ if (H.amount < total) H.update = 0.3f;+ }+ }+ int clock = g_save.options >> 2 & 3;+ H.y = approach(H.y, 96.f + (clock == 1 ? 58 : clock == 2 ? 78 : 0), DT * 800);+}+void hud_reset(void) { H.started = false, H.lerp = 0; }+static void hud_draw(void) {+ int clock = g_save.options >> 2 & 3;+ if (clock) { /* SpeedrunTimerDisplay */+ char b[16];+ pic(T__strawberryCountBG, -96, 12, 0, 0, 1, WHITE, 255);+ time_text(clock == 2 ? g_save.time + g_session.time : g_session.time, b);+ say(b, 32, 44, 0, 0.5f, 1, g_level.completed ? rgb(0x00FF00) : WHITE, 255);+ }+ if (H.lerp <= 0) return;+ Tex bg;+ float w = tex_get(T__strawberryCountBG, &bg) ? bg.fw * 6.f : 288;+ float x = roundf(-w + (32 + w) * ease_cube_out(H.lerp)), y = roundf(H.y);+ pic(T__strawberryCountBG, x - 96, y + 12 - 19, 0, 0, 1, WHITE, 255);+ pic(T__collectables_strawberry, x + 30, y, 0.5f, 0.5f, 1, WHITE, 255);+ Tex tx;+ float xw = tex_get(T__x, &tx) ? tx.fw * 6.f : 24;+ pic(T__x, x + 62 + xw / 2, y + 2, 0.5f, 0.5f, 1, WHITE, 255);+ char n[8];+ uitoa(H.amount, n);+ say(n, x + 62 + xw + 2 + text_measure(n) / 2, y, 0.5f, 0.5f, 1, WHITE, 255);+}++/* ---------------------------------------------------------------- the frame */+void menu_update(void) {+ M.t += RAW_DT, M.wig += RAW_DT;+ switch (M.screen) {+ case S_SHEET: sheet_update(); break;+ case S_TITLE: title_update(); break;+ case S_MAIN: main_update(); break;+ case S_CHAPTERS: chapters_update(); break;+ case S_PANEL: panel_update(); break;+ case S_OPTIONS: options_update(); break;+ case S_KEYS: keys_update(); break;+ case S_CREDITS: credits_update(); break;+ case S_COMPLETE: complete_update(); break;+ case S_PAUSE: pause_update(); break;+ case S_CONFIRM: confirm_update(); break;+ }+ inputs_end();+}+static void draw_screen(void) {+ switch (M.screen) {+ case S_SHEET: sheet_draw(); break;+ case S_TITLE: title_draw(); break;+ case S_MAIN: main_draw(); break;+ case S_CHAPTERS: chapters_draw(); break;+ case S_PANEL: panel_draw(); break;+ case S_OPTIONS: options_draw(); break;+ case S_KEYS: keys_draw(); break;+ case S_CREDITS: credits_draw(); break;+ case S_COMPLETE: complete_draw(); break;+ case S_PAUSE: pause_draw(); break;+ case S_CONFIRM: confirm_draw(); break;+ }+}+static void words_strip(uint16_t *strip, int y0, int y1, void *ctx) {+ (void)ctx;+ pass = 1, strip_ = strip, sy0_ = y0, sy1_ = y1;+ if (g_in_level && !g_level.in_credits) hud_draw();+ draw_screen();+ pass = 0;+}+/* drawn over the level (its HUD, the pause) or alone (the overworld): pictures, then a layer of words */+void menu_render(void) {+ if (!g_menu) M.screen = S_NONE; /* (a level started elsewhere closes them) */+ bool hud = g_in_level && !g_level.in_credits && (H.lerp > 0 || (g_save.options & 12));+ if (M.screen == S_NONE && !hud) return;+ gfx_hud(true);+ pass = 0;+ if (hud) hud_draw();+ draw_screen();+ gfx_hud(true);+ gfx_custom(words_strip, NULL, 0, VIEW_H);+ gfx_hud(false);+}diff --git a/games/celeste/src/npc.c b/games/celeste/src/npc.cnew file mode 100644index 00000000..851222d0--- /dev/null+++ b/games/celeste/src/npc.c@@ -0,0 +1,648 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* Characters and props found in many chapters: BirdNPC (and its tutorial+ * bubbles), FlutterBird, Lamp, Wire, Hahaha, and NPC's helpers. Line by line+ * from the game's code. */+#include "npc.h"++/* ---------------------------------------------------------------- Lamp */+typedef struct { uint8_t broken; } Lamp;+static void lamp_render(Ent *e) {+ Lamp *l = ST(e, Lamp);+ /* scenery/lamp, a 16 x 80 half: the image's origin at its bottom middle */+ gfx_tex_part_ex(T_scenery_lamp, e->x, e->y, l->broken ? 16 : 0, 0, 16, 80, 8, 80, 1, 1, 0, 0xFFFF, 255, 0);+ if (!l->broken) bloom_add(e->x, e->y - 66, 1, 16);+}+static const EntClass LAMP = {.size = sizeof(Lamp), .name = "lamp", .render = lamp_render};++/* ---------------------------------------------------------------- Wire */+typedef struct { V2 from, to; float sine_x, sine_y; } WireS;+static void wire_render(Ent *e) {+ WireS *w = ST(e, WireS);+ float k = 8 * level_visual_wind();+ V2 sway = v2(sinf(w->sine_x + g_level.wind_sine_timer * 2) * k, sinf(w->sine_y + g_level.wind_sine_timer * 2.8f) * k);+ V2 c = v2add(v2add(v2mul(v2add(w->from, w->to), 0.5f), v2(0, 24)), sway);+ V2 prev = w->from;+ for (int i = 1; i <= 16; i++) {+ float t = i / 16.f, u = 1 - t;+ V2 p = v2(u * u * w->from.x + 2 * u * t * c.x + t * t * w->to.x, u * u * w->from.y + 2 * u * t * c.y + t * t * w->to.y);+ gfx_line(prev.x, prev.y, p.x, p.y, 0x5ACC /* 595866 */, 255);+ prev = p;+ }+}+static const EntClass WIRE = {.size = sizeof(WireS), .name = "wire", .render = wire_render};+V2 *wire_curve_begin(Ent *e) { return e && e->cls == &WIRE ? &ST(e, WireS)->from : NULL; } /* Wire.Curve.Begin */++/* ---------------------------------------------------------------- FlutterBird */+typedef struct {+ Sprite spr;+ V2 start, from, to, ctl;+ float delay, p, fly_delay;+ Co co;+ int8_t dir;+ uint8_t flying, routine; /* routine 0: IdleRoutine, 1: FlyAwayRoutine */+} Flutter;+static const EntClass FLUTTER;+static void flutter_fly_away(Ent *e, int dir, float delay) {+ Flutter *f = ST(e, Flutter);+ if (f->flying) return;+ f->flying = 1;+ f->routine = 1;+ f->dir = (int8_t)dir;+ f->fly_delay = delay;+ memset(&f->co, 0, sizeof f->co); /* the idle routine is removed, the fly away one added */+}+static void flutter_idle(Ent *e, Flutter *f) {+ Player *pl;+ CO_BEGIN(&f->co);+ for (;;) {+ f->delay = 0.25f + rndf();+ for (f->p = 0; f->p < f->delay; f->p += DT) {+ pl = level_player();+ if (pl && !pl->dead && fabsf(pl->ent->x - e->x) < 48 && pl->ent->y > e->y - 40 && pl->ent->y < e->y + 8)+ flutter_fly_away(e, (int)signf(e->x - pl->ent->x), rndf() * 0.2f);+ if (f->routine) return;+ CO_YIELD(&f->co);+ }+ f->to = v2add(f->start, v2(-4 + rndf() * 8, 0));+ f->from = v2(e->x, e->y);+ f->spr.sx = signf(f->to.x - e->x);+ f->ctl = v2sub(v2mul(v2add(f->from, f->to), 0.5f), v2(0, 14));+ for (f->p = 0; f->p < 1; f->p += DT * 4) {+ {+ float t = f->p, u = 1 - t;+ e->x = u * u * f->from.x + 2 * u * t * f->ctl.x + t * t * f->to.x;+ e->y = u * u * f->from.y + 2 * u * t * f->ctl.y + t * t * f->to.y;+ }+ CO_YIELD(&f->co);+ }+ f->spr.sx = signf(f->spr.sx) * 1.4f;+ f->spr.sy = 0.6f;+ e->x = f->to.x, e->y = f->to.y;+ }+ CO_END(&f->co);+}+static void flutter_away(Ent *e, Flutter *f) {+ CO_BEGIN(&f->co);+ CO_WAIT(&f->co, f->fly_delay);+ spr_play(&f->spr, A_flutterBird_fly, false);+ f->spr.sx = -f->dir * 1.25f;+ f->spr.sy = 1.25f;+ {+ const PType *d = rndi(2) ? &P_Dust : &P_Dust; /* Calc.Random.Choose(ParticleTypes.Dust) */+ particles_emit1(PL_FG, d, v2(e->x, e->y), -PI_F / 2);+ }+ f->from = v2(e->x, e->y);+ f->to = v2add(f->from, v2(f->dir * 4.f, -8));+ for (f->p = 0; f->p < 1; f->p += DT * 3) {+ e->x = f->from.x + (f->to.x - f->from.x) * ease_cube_out(f->p);+ e->y = f->from.y + (f->to.y - f->from.y) * ease_cube_out(f->p);+ CO_YIELD(&f->co);+ }+ e->depth = -10001;+ ents_mark_unsorted();+ f->spr.sx = -f->spr.sx;+ f->to = v2(f->dir * 8.f, -32); /* the speed now */+ while (e->y + 8 > g_level.room->y) {+ f->to = v2add(f->to, v2(f->dir * 64 * DT, -128 * DT));+ e->x += f->to.x * DT, e->y += f->to.y * DT;+ if (level_on_interval(0.1f) && e->y > g_level.cam.y + 32)+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o->cls == &FLUTTER && o->dead != 1 && fabsf(e->x - o->x) < 48 && fabsf(e->y - o->y) < 48 && !ST(o, Flutter)->flying)+ flutter_fly_away(o, f->dir, rndf() * 0.25f);+ }+ CO_YIELD(&f->co);+ }+ ent_remove(e);+ CO_END(&f->co);+}+static void flutter_update(Ent *e) {+ Flutter *f = ST(e, Flutter);+ f->spr.sx = approach(f->spr.sx, signf(f->spr.sx), 4 * DT);+ f->spr.sy = approach(f->spr.sy, 1, 4 * DT);+ spr_update(&f->spr);+ if (f->routine) flutter_away(e, f);+ else flutter_idle(e, f);+}+static void flutter_render(Ent *e) {+ Flutter *f = ST(e, Flutter);+ Sprite s = f->spr;+ s.flipx = s.sx < 0;+ s.sx = fabsf(s.sx);+ spr_draw(&s, e->x, e->y);+}+static const EntClass FLUTTER = {.size = sizeof(Flutter), .name = "flutterbird", .update = flutter_update, .render = flutter_render};++/* ---------------------------------------------------------------- Hahaha */+#define MAX_HA 6+/* each "ha": characters/oldlady/ha, frames 0,1,0,1,0,1,0,1,0,1,2..9 at 0.15 s, rising as it goes */+static const uint8_t HA_FRAMES[18] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};+typedef struct {+ float has[MAX_HA]; /* each one's Percent */+ int nhas, counter;+ float timer;+ const char *ifset; /* the flag that turns it on */+ uint8_t enabled;+} Haha;+void hahaha_enable(Ent *e, bool on) {+ Haha *h = ST(e, Haha);+ if (!h->enabled && on) h->timer = 0, h->counter = 0;+ h->enabled = on;+}+static void haha_update(Ent *e) {+ Haha *h = ST(e, Haha);+ if (h->enabled) {+ h->timer -= DT;+ if (h->timer <= 0) {+ if (h->nhas < MAX_HA) h->has[h->nhas++] = 0;+ h->counter++;+ if (h->counter >= 3) h->counter = 0, h->timer = 1.5f;+ else h->timer = 0.6f;+ }+ }+ for (int i = h->nhas - 1; i >= 0; i--) {+ if (h->has[i] > 1) {+ memmove(&h->has[i], &h->has[i + 1], sizeof h->has[0] * (size_t)(h->nhas - i - 1));+ h->nhas--;+ } else+ h->has[i] += DT / (18 * 0.15f); /* Duration: its 18 frames */+ }+ if (!h->enabled && h->ifset && *h->ifset && level_get_flag(h->ifset)) hahaha_enable(e, true);+}+static void haha_render(Ent *e) {+ Haha *h = ST(e, Haha);+ for (int i = 0; i < h->nhas; i++) {+ float p = h->has[i];+ int f = (int)(p * 18);+ uint16_t tex = (uint16_t)(T_characters_oldlady_ha00 + HA_FRAMES[f > 17 ? 17 : f]);+ Tex t;+ if (!tex_get(tex, &t)) continue;+ gfx_tex_ex(tex, e->x + p * 60, e->y - 10 - sinf(p * 13) * 4 + p * -16, t.fw / 2.f, t.fh / 2.f, 1, 1, 0, 0xFFFF, 255, 0);+ }+}+static const EntClass HAHAHA = {.size = sizeof(Haha), .name = "hahaha", .update = haha_update, .render = haha_render};+Ent *hahaha_new(V2 at, const char *ifset) {+ Ent *e = ent_new(&HAHAHA, at.x, at.y);+ if (!e) return NULL;+ e->depth = -10001;+ e->collidable = 0;+ ST(e, Haha)->ifset = ifset;+ ST(e, Haha)->enabled = 1;+ if (ifset && *ifset && !level_get_flag(ifset)) ST(e, Haha)->enabled = 0;+ return e;+}++/* ---------------------------------------------------------------- BirdTutorialGui */+Tutorial g_tuts[2]; /* (one bird shows its bubbles at a time) */+/* the calculator's keys (Input.GuiButton): a key cap with its name */+static const char *key_name(int action) {+ switch (action) {+ case IN_JUMP: return "OK";+ case IN_DASH: return "Backspace";+ case IN_GRAB: return "Toolbox";+ case IN_TALK: return "Backspace";+ default: return "Back";+ }+}+/* the width of a control in interface pixels */+static float control_width(const GuiControl *c) {+ switch (c->kind) {+ case GC_BUTTON: return font_measure(key_name(c->v), (int)strlen(key_name(c->v)), FONT_S) * 6 + 48 + 16;+ case GC_DIR: return 64 + 16;+ case GC_TEXT: return font_measure(c->text, (int)strlen(c->text), FONT_S) * 6;+ default: return 0;+ }+}+void tutorial_init(Tutorial *t, Ent *bird, V2 offset, const char *info_key, const GuiControl *controls, int n) {+ memset(t, 0, sizeof *t);+ t->bird = (uint16_t)(bird - g_ents);+ t->offset = offset;+ dialog_clean(info_key, t->info, sizeof t->info);+ t->info_w = font_measure(t->info, (int)strlen(t->info), FONT_S) * 6;+ t->n = (uint8_t)(n > 4 ? 4 : n);+ memcpy(t->controls, controls, sizeof(GuiControl) * t->n);+ for (int i = 0; i < t->n; i++) t->controls_w += control_width(&t->controls[i]);+}+void tutorial_update(Tutorial *t) {+ if (!t->added) return;+ t->scale = approach(t->scale, t->open ? 1.f : 0.f, RAW_DT * 8);+}++/* a key cap: a light frame, dark inside, its name */+static void draw_key(float x, float y, const char *name, float sx) {+ float w = (font_measure(name, (int)strlen(name), FONT_S) * 6 + 48) * sx;+ float h = 64;+ gfx_rect((x) / 6, (y - h / 2) / 6, w / 6, h / 6, 0xFFFF, 255);+ gfx_rect((x + 6) / 6, (y - h / 2 + 6) / 6, (w - 12) / 6, (h - 12) / 6, 0x2104, 255);+ if (sx > 0.5f) font_draw(name, (int)strlen(name), (x + w / 2) / 6 - font_measure(name, (int)strlen(name), FONT_S) / 2,+ (y) / 6 - font_line_height(FONT_S) / 2, FONT_S, 0xFFFF, 255);+}+/* an arrow (Input.GuiDirection) */+static void draw_dir(float x, float y, V2 d, float sx) {+ float cx = (x + 32 * sx) / 6, cy = y / 6;+ V2 n = v2norm(d), p = v2(-n.y, n.x);+ for (int i = -1; i <= 1; i++) {+ float o = i * 0.5f;+ gfx_line(cx - n.x * 4 + p.x * o, cy - n.y * 4 + p.y * o, cx + n.x * 4 + p.x * o, cy + n.y * 4 + p.y * o, 0xFFFF, 255);+ }+ V2 tip = v2(cx + n.x * 5, cy + n.y * 5);+ gfx_line(tip.x, tip.y, tip.x - n.x * 3 + p.x * 3, tip.y - n.y * 3 + p.y * 3, 0xFFFF, 255);+ gfx_line(tip.x, tip.y, tip.x - n.x * 3 - p.x * 3, tip.y - n.y * 3 - p.y * 3, 0xFFFF, 255);+}++void tutorial_render(Tutorial *t) {+ if (!t->added || t->scale <= 0 || g_level.frozen || g_level.paused) return;+ Ent *b = &g_ents[t->bird];+ float px = (b->x + t->offset.x - floorf(g_level.cam.x)) * 6, py = (b->y + t->offset.y - floorf(g_level.cam.y)) * 6;+ float lh = 64;+ float w = (fmaxf(t->controls_w, t->info_w) + 64) * t->scale;+ float h = lh + lh + 32; /* infoHeight is the line height for text */+ float x = px - w / 2, y = py - h - 32;+ gfx_hud(true);+ gfx_rect((x - 6) / 6, (y - 6) / 6, (w + 12) / 6, (h + 12) / 6, 0xFFFF, 255);+ gfx_rect(x / 6, y / 6, w / 6, h / 6, 0x00A4 /* 061526 */, 255);+ for (int i = 0; i <= 36; i += 6) { /* the bubble's tail, a screen pixel at a time */+ float n5 = (73 - i * 2) * t->scale;+ gfx_rect((px - n5 / 2) / 6, (y + h + i) / 6, n5 / 6, 1, 0xFFFF, 255);+ if (n5 > 12) gfx_rect((px - n5 / 2 + 6) / 6, (y + h + i) / 6, (n5 - 12) / 6, 1, 0x00A4, 255);+ }+ if (w > 3) {+ float cx = px, cy = y + 16;+ if (t->scale > 0.5f) font_draw(t->info, (int)strlen(t->info), cx / 6 - t->info_w / 12 * t->scale, cy / 6, FONT_S, 0x63DC, 255);+ cy += lh + lh * 0.5f;+ float ox = -t->controls_w / 2;+ for (int i = 0; i < t->n; i++) {+ GuiControl *c = &t->controls[i];+ if (c->kind == GC_BUTTON) {+ ox += 8;+ draw_key(cx + ox * t->scale, cy, key_name(c->v), t->scale);+ ox += control_width(c) - 16 + 8;+ } else if (c->kind == GC_DIR) {+ ox += 8;+ draw_dir(cx + ox * t->scale, cy, c->dir, t->scale);+ ox += 64 + 8;+ } else if (c->kind == GC_TEXT) {+ float tw = control_width(c);+ if (t->scale > 0.5f) {+ font_draw(c->text, (int)strlen(c->text), (cx + ox * t->scale) / 6, cy / 6 - 6 + 0.33f, FONT_S, 0x63DC, 255);+ font_draw(c->text, (int)strlen(c->text), (cx + ox * t->scale) / 6, cy / 6 - 6 - 0.33f, FONT_S, 0xFFFF, 255);+ }+ ox += tw + 1;+ }+ }+ }+ gfx_hud(false);+}++/* ---------------------------------------------------------------- BirdNPC */+static const EntClass BIRD;+static void bird_set_mode(Ent *e, int mode);++/* nested coroutines of the bird: each returns true while it runs (its state in Bird.sub) */+bool bird_caw(Ent *e) { /* Caw */+ Bird *b = ST(e, Bird);+ if (!b->sub_started) {+ b->sub_started = 1;+ spr_play(&b->spr, A_bird_croak, false);+ }+ if (b->spr.anim == A_bird_croak && b->spr.frame < 9) return true;+ b->sub_started = 0;+ return false;+}+/* ShowTutorial: caw first if asked, then the bubble opens */+bool bird_show_tutorial(Ent *e, Tutorial *t, bool caw) {+ Bird *b = ST(e, Bird);+ if (b->sub_step == 0) {+ b->sub_step = caw ? 1 : 2;+ if (caw) {+ b->sub_started = 0;+ bird_caw(e);+ return true;+ }+ }+ if (b->sub_step == 1) {+ if (bird_caw(e)) return true;+ b->sub_step = 2;+ return true; /* the nested Caw ends: an update */+ }+ if (b->sub_step == 2) {+ b->gui = t;+ t->open = true;+ t->added = true;+ b->sub_step = 3;+ }+ if (t->scale < 1) return true;+ b->sub_step = 0;+ return false;+}+bool bird_hide_tutorial(Ent *e) {+ Bird *b = ST(e, Bird);+ if (!b->gui) return false;+ b->gui->open = false;+ if (b->gui->scale > 0) return true;+ b->gui->added = false;+ b->gui = NULL;+ return false;+}+/* Startle: dust, a jump back, feathers */+bool bird_startle(Ent *e, float duration, V2 mult) {+ Bird *b = ST(e, Bird);+ if (!b->sub_started) {+ b->sub_started = 1;+ dust_burst(v2(e->x, e->y), -PI_F / 2, 8);+ spr_play(&b->spr, A_bird_jump, false);+ tween_start(&b->tween, duration);+ b->tween_new = 1;+ return true;+ }+ if (b->tween.active) return true;+ b->sub_started = 0;+ return false;+}+/* FlyAway: up and away, until above the room */+bool bird_fly_away(Ent *e, float up) {+ Bird *b = ST(e, Bird);+ if (!b->sub_started) {+ b->sub_started = 1;+ spr_play(&b->spr, A_bird_fly, false);+ b->facing = -b->facing;+ b->speed = v2(b->facing * 20.f, -40 * up);+ }+ if (e->y > g_level.room->y) {+ b->speed = v2add(b->speed, v2(b->facing * 140 * DT, -120 * up * DT));+ e->x += b->speed.x * DT, e->y += b->speed.y * DT;+ return true;+ }+ ent_remove(e);+ return false;+}+/* StartleAndFlyAway */+bool bird_startle_and_fly(Ent *e) {+ Bird *b = ST(e, Bird);+ switch (b->fly_step) {+ case 0:+ e->depth = -1000000;+ ents_mark_unsorted();+ {+ char flag[40];+ path2(flag, "bird_fly_away_", level_room_name(), -1);+ level_set_flag(flag, true);+ }+ b->sub_started = 0;+ b->fly_step = 1;+ return true; /* yield return Startle(): it starts on the next update */+ case 1:+ if (bird_startle(e, 0.8f, v2(1, 1))) return true;+ b->fly_step = 2;+ return true;+ case 2:+ b->fly_step = 3;+ b->sub_started = 0;+ return true;+ default:+ return bird_fly_away(e, 1);+ }+}++static void bird_update(Ent *e) {+ Bird *b = ST(e, Bird);+ b->spr.sx = (float)b->facing;+ /* base.Update(): the sprite (raw time), then the routine, then tweens added before */+ spr_update(&b->spr);+ if (b->tween.active && !b->tween_new) { /* Startle's tween */+ tween_update(&b->tween);+ float k = ease_cube_out(b->tween.percent);+ if (k < 0.5f && level_on_interval(0.05f)) particles_emit(PL_MID, &P_BirdNPC_P_Feather, 2, v2(e->x, e->y - 6), v2(4, 4), P_BirdNPC_P_Feather.direction);+ V2 v = v2(100 + (20 - 100) * k, -100 + (-20 + 100) * k);+ v.x *= -b->facing;+ e->x += v.x * DT, e->y += v.y * DT;+ }+ b->tween_new = 0;+ if (b->routine) b->routine(e);+ if (b->hide_then_fly && !bird_hide_tutorial(e)) b->hide_then_fly = 0;+ if (b->fly_now) {+ if (b->fly_now == 1) b->fly_step = 0, b->sub_started = 0, b->fly_now = 2;+ if (!bird_startle_and_fly(e)) b->fly_now = 0;+ }+ if (b->gui) tutorial_update(b->gui);+}+static void bird_render(Ent *e) {+ Bird *b = ST(e, Bird);+ Sprite s = b->spr;+ s.flipx = s.sx < 0;+ s.sx = fabsf(s.sx);+ spr_draw(&s, e->x, e->y);+ light_add(e->x, e->y - 8, 0xFFFFFF, 1, 8, 32);+ if (b->gui) tutorial_render(b->gui);+}+static const EntClass BIRD = {.size = sizeof(Bird), .name = "bird", .update = bird_update, .render = bird_render, .kind = KIND_ACTOR};++/* ClimbingTutorial */+static void climbing_tutorial(Ent *e) {+ Bird *b = ST(e, Bird);+ Player *p = &g_player;+ CO_BEGIN(&b->co);+ CO_WAIT(&b->co, 0.25f);+ while (fabsf(p->ent->x - e->x) > 120) CO_YIELD(&b->co);+ {+ /* tut1: "Climb", then "Hold" and the grab key; tut2: "Climb", the grab key + up */+ GuiControl a[2] = {{GC_TEXT, 0, {0, 0}, ""}, {GC_BUTTON, IN_GRAB, {0, 0}, ""}};+ dialog_clean("tutorial_hold", a[0].text, sizeof a[0].text);+ tutorial_init(&g_tuts[0], e, v2(0, -16), "tutorial_climb", a, 2);+ GuiControl c[3] = {{GC_BUTTON, IN_GRAB, {0, 0}, ""}, {GC_TEXT, 0, {0, 0}, "+"}, {GC_DIR, 0, {0, -1}, ""}};+ tutorial_init(&g_tuts[1], e, v2(0, -16), "tutorial_climb", c, 3);+ }+ b->first = 1;+ do {+ b->sub_step = 0;+ CO_NEST(&b->co, bird_show_tutorial(e, &g_tuts[0], b->first));+ b->first = 0;+ while (p->state != ST_CLIMB && p->ent->y > e->y) CO_YIELD(&b->co);+ if (p->ent->y > e->y) {+ CO_NEST(&b->co, bird_hide_tutorial(e));+ b->sub_step = 0;+ CO_NEST(&b->co, bird_show_tutorial(e, &g_tuts[1], false));+ }+ while (!p->dead && (!p->on_ground || p->state == ST_CLIMB)) CO_YIELD(&b->co);+ b->will_end = p->ent->y <= e->y + 4;+ CO_NEST(&b->co, bird_hide_tutorial(e));+ } while (!b->will_end);+ b->fly_step = 0;+ CO_NEST(&b->co, bird_startle_and_fly(e));+ CO_END(&b->co);+}++/* WaitRoutine (FlyAway) */+static void wait_routine(Ent *e) {+ Bird *b = ST(e, Bird);+ Player *p;+ CO_BEGIN(&b->co);+ for (;;) {+ if (b->auto_fly) break;+ p = level_player();+ if (p && !p->dead && fabsf(p->ent->x - e->x) < 120) break;+ CO_YIELD(&b->co);+ }+ b->sub_started = 0;+ CO_NEST(&b->co, bird_caw(e));+ for (;;) {+ if (b->auto_fly) break;+ p = level_player();+ if (p && !p->dead && v2len(v2sub(player_center(p), v2(e->x, e->y))) < 32) break;+ CO_YIELD(&b->co);+ }+ b->fly_step = 0;+ CO_NEST(&b->co, bird_startle_and_fly(e));+ CO_END(&b->co);+}++/* DashingTutorial: from the top of the room, until Madeline comes; then the prologue's end */+static void dashing_tutorial(Ent *e) {+ Bird *b = ST(e, Bird);+ Player *p;+ CO_BEGIN(&b->co);+ e->y = (float)g_level.room->y;+ e->x += 32;+ CO_WAIT(&b->co, 1);+ for (;;) {+ p = level_player();+ if (p && p->ent->x > b->start.x - 92 && p->ent->y > b->start.y - 20 && p->ent->y < b->start.y - 10) break;+ CO_YIELD(&b->co);+ }+ prologue_ending_start(level_player(), e);+ CO_END(&b->co);+}++static void bird_set_mode(Ent *e, int mode) {+ Bird *b = ST(e, Bird);+ b->mode = (uint8_t)mode;+ memset(&b->co, 0, sizeof b->co);+ b->routine = NULL;+ switch (mode) {+ case BIRD_CLIMBING: b->routine = climbing_tutorial; break;+ case BIRD_DASHING: b->routine = dashing_tutorial; break;+ case BIRD_FLYAWAY: b->routine = wait_routine; break;+ case BIRD_SLEEPING:+ spr_play(&b->spr, A_bird_sleep, false);+ b->facing = 1;+ break;+ default: b->routine = bird_mode_routine(mode); break;+ }+}++Ent *bird_new(V2 at, int mode) {+ Ent *e = ent_new(&BIRD, at.x, at.y);+ if (!e) return NULL;+ Bird *b = ST(e, Bird);+ b->facing = -1;+ spr_init(&b->spr, SB_bird);+ b->spr.raw = 1;+ b->spr.sx = (float)b->facing;+ b->start = at;+ ent_box(e, 0, 0, 0, 0);+ e->ctype = COL_NONE;+ bird_set_mode(e, mode);+ return e;+}++/* ---------------------------------------------------------------- NPC helpers */+/* NPC.PlayerApproach: Madeline walks up to `npc`, `spacing` away on `side` (0: hers), and faces it */+bool npc_approach(NpcWalk *w, Ent *npc, Sprite *spr, float spacing, int side) {+ Player *p = &g_player;+ switch (w->step) {+ case 0:+ w->side = (int8_t)(side ? side : (int)signf(p->ent->x - npc->x));+ if (!w->side) w->side = 1;+ player_set_state(p, ST_DUMMY);+ p->state_locked = true;+ if (spacing > 0) w->walk = walk_exact((int)(npc->x + w->side * spacing));+ else if (fabsf(npc->x - p->ent->x) < 12 || signf(p->ent->x - npc->x) != w->side)+ w->walk = walk_exact((int)(npc->x + w->side * 12));+ else {+ w->step = 3;+ goto face;+ }+ w->step = 1;+ return true; /* yield return the walk */+ case 1:+ if (player_walk(p, &w->walk)) return true;+ w->step = 2;+ return true;+ case 2:+ w->step = 3;+ face:+ p->facing = -w->side;+ if (spr) spr->sx = (float)w->side;+ return true; /* yield return null */+ default:+ w->step = 0;+ return false;+ }+}++/* the modes of later chapters (DreamJumpTutorial and the rest): ported with them */+WEAK void (*bird_mode_routine(int mode))(Ent *e) {+ (void)mode;+ return NULL;+}++/* ---------------------------------------------------------------- the factory */+bool props_create(const EData *d) {+ Ent *e;+ switch (d->type) {+ case ET_lamp:+ e = ent_new(&LAMP, d->x, d->y);+ if (e) e->depth = 5, e->collidable = 0, ST(e, Lamp)->broken = EAB(d, lamp, broken);+ return true;+ case ET_wire: {+ if (!d->nnodes) return true;+ e = ent_new(&WIRE, d->x, d->y);+ if (!e) return true;+ WireS *w = ST(e, WireS);+ w->from = v2(d->x, d->y);+ w->to = ed_node(d, 0);+ e->depth = EAB(d, wire, above) ? -8500 : 2000;+ e->collidable = 0;+ NetRandom r; /* new Random((int)Math.Min(from.X, to.X)) */+ rnd_seed(&r, (int)fminf(w->from.x, w->to.x));+ w->sine_x = rnd_float(&r) * 4;+ w->sine_y = rnd_float(&r) * 4;+ return true;+ }+ case ET_flutterbird: {+ e = ent_new(&FLUTTER, d->x, d->y);+ if (!e) return true;+ Flutter *f = ST(e, Flutter);+ e->depth = -9999;+ e->collidable = 0;+ f->start = v2(d->x, d->y);+ spr_init(&f->spr, SB_flutterBird);+ static const uint32_t cols[4] = {0x89fbff, 0xf0fc6c, 0xf493ff, 0x93baff};+ f->spr.tint = rgb(cols[rndi(4)]);+ return true;+ }+ case ET_bird: {+ static const char *modes[] = {"ClimbingTutorial", "DashingTutorial", "DreamJumpTutorial", "SuperWallJumpTutorial",+ "HyperJumpTutorial", "FlyAway", "None", "Sleeping", "MoveToNodes", "WaitForLightningOff"};+ const char *m = EAS(d, bird, mode);+ int mode = BIRD_NONE;+ for (int i = 0; i < 10; i++)+ if (!strcmp(m, modes[i])) mode = i;+ /* Added: gone if Madeline has been past the climbing tutorial's room, or it flew away already */+ if (mode == BIRD_CLIMBING && level_visited("2")) return true;+ if (mode == BIRD_FLYAWAY) {+ char flag[40];+ path2(flag, "bird_fly_away_", level_room_name(), -1);+ if (level_get_flag(flag)) return true;+ }+ bird_new(v2(d->x, d->y), mode);+ return true;+ }+ case ET_hahaha:+ hahaha_new(v2(d->x, d->y), EAS(d, hahaha, ifset));+ return true;+ }+ return false;+}diff --git a/games/celeste/src/npc.h b/games/celeste/src/npc.hnew file mode 100644index 00000000..ffe47152--- /dev/null+++ b/games/celeste/src/npc.h@@ -0,0 +1,60 @@+/* Characters and props of many chapters (npc.c). */+#ifndef NPC_H+#define NPC_H+#include "cutscene.h"++/* ---------------------------------------------------------------- BirdTutorialGui */+enum { GC_TEXT, GC_BUTTON, GC_DIR };+enum { IN_JUMP, IN_DASH, IN_GRAB, IN_TALK, IN_PAUSE };+typedef struct {+ uint8_t kind, v; /* GC_BUTTON: an IN_ action */+ V2 dir; /* GC_DIR */+ char text[16]; /* GC_TEXT */+} GuiControl;+typedef struct {+ uint16_t bird; /* g_ents index of what it points at */+ V2 offset;+ char info[32];+ float info_w, controls_w, scale;+ bool open, added;+ uint8_t n;+ GuiControl controls[4];+} Tutorial;+extern Tutorial g_tuts[2];+void tutorial_init(Tutorial *t, Ent *bird, V2 offset, const char *info_key, const GuiControl *controls, int n);+void tutorial_update(Tutorial *t);+void tutorial_render(Tutorial *t);++/* ---------------------------------------------------------------- BirdNPC */+enum { BIRD_CLIMBING, BIRD_DASHING, BIRD_DREAMJUMP, BIRD_SUPERWALLJUMP, BIRD_HYPERJUMP, BIRD_FLYAWAY, BIRD_NONE,+ BIRD_SLEEPING, BIRD_MOVETONODES, BIRD_WAITLIGHTNING };+typedef struct {+ Sprite spr;+ V2 start, speed;+ Co co;+ Tween tween;+ Tutorial *gui;+ void (*routine)(Ent *e);+ int8_t facing;+ uint8_t mode, auto_fly, first, will_end, sub_started, sub_step, fly_step, tween_new;+ uint8_t hide_then_fly, fly_now; /* coroutines added from outside (CS00_Ending) */+} Bird;+Ent *bird_new(V2 at, int mode);+bool bird_caw(Ent *e);+bool bird_show_tutorial(Ent *e, Tutorial *t, bool caw);+bool bird_hide_tutorial(Ent *e);+bool bird_startle(Ent *e, float duration, V2 mult);+bool bird_fly_away(Ent *e, float up);+bool bird_startle_and_fly(Ent *e);+void (*bird_mode_routine(int mode))(Ent *e); /* the other chapters' modes */+void prologue_ending_start(Player *p, Ent *bird); /* ch0.c: CS00_Ending */++/* ---------------------------------------------------------------- NPC */+typedef struct { uint8_t step; int8_t side; Walk walk; } NpcWalk;+bool npc_approach(NpcWalk *w, Ent *npc, Sprite *spr, float spacing, int side); /* PlayerApproach */++Ent *hahaha_new(V2 at, const char *ifset);+void hahaha_enable(Ent *e, bool on);+bool props_create(const EData *d);+V2 *wire_curve_begin(Ent *wire); /* its curve's start (the payphone's cutscene drops it) */ /* lamp, wire, flutterbird, bird, hahaha */+#endifdiff --git a/games/celeste/src/plat_eadk.c b/games/celeste/src/plat_eadk.cnew file mode 100644index 00000000..2a7aeba1--- /dev/null+++ b/games/celeste/src/plat_eadk.c@@ -0,0 +1,51 @@+/* The calculator: EADK display, keyboard, time and files. */+#include <eadk.h>+#include "../../common/epsilon_app.h"+#include "../../common/epsilon_files.h"+#include "celeste.h"++#define KEY(k) ((uint64_t)1 << (k))++/* key bindings: one EADK key per game action (settings can change them) */+uint8_t g_bind[4]; /* jump, dash, grab, talk */+void plat_default_binds(void) {+ g_bind[0] = eadk_key_ok, g_bind[1] = eadk_key_backspace, g_bind[2] = eadk_key_toolbox, g_bind[3] = eadk_key_backspace;+}+static uint64_t scan, scan_prev;+/* the key that went down this frame (an EADK key), -1 if none */+int plat_key_pressed(void) {+ uint64_t d = scan & ~scan_prev;+ return d ? __builtin_ctzll(d) : -1;+}++uint32_t plat_keys(void) {+ uint64_t k = eadk_keyboard_scan();+ scan_prev = scan, scan = k;+ uint32_t r = 0;+ if (k & KEY(eadk_key_left)) r |= K_LEFT;+ if (k & KEY(eadk_key_right)) r |= K_RIGHT;+ if (k & KEY(eadk_key_up)) r |= K_UP;+ if (k & KEY(eadk_key_down)) r |= K_DOWN;+ if (k & KEY(g_bind[0])) r |= K_JUMP;+ if (k & KEY(g_bind[1])) r |= K_DASH;+ if (k & KEY(g_bind[2])) r |= K_GRAB;+ if (k & KEY(g_bind[3])) r |= K_TALK;+ if (k & (KEY(eadk_key_ok) | KEY(eadk_key_exe))) r |= K_OK;+ if (k & KEY(eadk_key_back)) r |= K_BACK | K_PAUSE;+ if (k & (KEY(eadk_key_home) | KEY(eadk_key_on_off))) r |= K_HOME;+ if (k) r |= K_ANY;+ return r;+}++uint32_t plat_millis(void) { return (uint32_t)eadk_timing_millis(); }+void plat_sleep(uint32_t ms) { eadk_timing_msleep(ms); }+void plat_push(int x, int y, int w, int h, const uint16_t *px) {+ eadk_display_push_rect((eadk_rect_t){(uint16_t)x, (uint16_t)y, (uint16_t)w, (uint16_t)h}, px);+}+void plat_fill(int x, int y, int w, int h, uint16_t c) {+ if (w > 0 && h > 0) eadk_display_push_rect_uniform((eadk_rect_t){(uint16_t)x, (uint16_t)y, (uint16_t)w, (uint16_t)h}, c);+}+bool plat_save(const char *name, const void *data, uint32_t len) { return ef_write(name, data, len); }+const uint8_t *plat_load(const char *name, uint32_t *len) { return ef_read(name, len); }+void plat_begin(void) { np_app_begin(); }+int plat_end(void) { return np_app_end(); }diff --git a/games/celeste/src/plat_host.c b/games/celeste/src/plat_host.cnew file mode 100644index 00000000..5d333dc5--- /dev/null+++ b/games/celeste/src/plat_host.c@@ -0,0 +1,60 @@+/* A computer: the screen goes to a frame buffer that tests save as images,+ * keys come from a script, time is simulated. */+#include <stdio.h>+#include <stdlib.h>+#include "celeste.h"++uint16_t host_fb[SCREEN_W * SCREEN_H];+uint32_t host_time, host_keys;++uint32_t plat_keys(void) { return host_keys; }+uint8_t g_bind[4];+void plat_default_binds(void) { g_bind[0] = 4, g_bind[1] = 17, g_bind[2] = 16, g_bind[3] = 17; }+int plat_key_pressed(void) { return -1; }+uint32_t plat_millis(void) { return host_time; }+void plat_sleep(uint32_t ms) { host_time += ms; }+void plat_push(int x, int y, int w, int h, const uint16_t *px) {+ for (int r = 0; r < h; r++)+ for (int c = 0; c < w; c++)+ if ((unsigned)(x + c) < SCREEN_W && (unsigned)(y + r) < SCREEN_H) host_fb[(y + r) * SCREEN_W + x + c] = px[r * w + c];+}+void plat_fill(int x, int y, int w, int h, uint16_t c) {+ for (int r = 0; r < h; r++)+ for (int k = 0; k < w; k++)+ if ((unsigned)(x + k) < SCREEN_W && (unsigned)(y + r) < SCREEN_H) host_fb[(y + r) * SCREEN_W + x + k] = c;+}+static char save_dir[256] = "build/host-saves";+void host_save_dir(const char *d) { snprintf(save_dir, sizeof save_dir, "%s", d); }+bool plat_save(const char *name, const void *data, uint32_t len) {+ char p[512];+ snprintf(p, sizeof p, "%s/%s", save_dir, name);+ FILE *f = fopen(p, "wb");+ if (!f) return false;+ fwrite(data, 1, len, f);+ fclose(f);+ return true;+}+static uint8_t loaded[65536];+const uint8_t *plat_load(const char *name, uint32_t *len) {+ char p[512];+ snprintf(p, sizeof p, "%s/%s", save_dir, name);+ FILE *f = fopen(p, "rb");+ if (!f) return NULL;+ *len = (uint32_t)fread(loaded, 1, sizeof loaded, f);+ fclose(f);+ return loaded;+}+void plat_begin(void) {}+int plat_end(void) { return 0; }++void host_shot(const char *path) {+ FILE *f = fopen(path, "wb");+ if (!f) return;+ fprintf(f, "P6\n%d %d\n255\n", SCREEN_W, SCREEN_H);+ for (int i = 0; i < SCREEN_W * SCREEN_H; i++) {+ uint16_t c = host_fb[i];+ uint8_t rgb[3] = {(uint8_t)((c >> 11) * 255 / 31), (uint8_t)(((c >> 5) & 63) * 255 / 63), (uint8_t)((c & 31) * 255 / 31)};+ fwrite(rgb, 1, 3, f);+ }+ fclose(f);+}diff --git a/games/celeste/src/player.c b/games/celeste/src/player.cnew file mode 100644index 00000000..86c50a81--- /dev/null+++ b/games/celeste/src/player.c@@ -0,0 +1,2871 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* Madeline. A line-by-line port of Player.cs (NoelFB/Celeste, MIT): the same+ * constants, states and order of operations, with Monocle's coroutines+ * written as steps. */+#include "player.h"+#include "level.h"+#include "fx.h"+#include "entities.h"+#include "wipe.h"+#include "talk.h"+#include "cutscene.h"++Player g_player;++#define MaxFall 160.f+#define Gravity 900.f+#define HalfGravThreshold 40.f+#define FastMaxFall 240.f+#define FastMaxAccel 300.f+#define MaxRun 90.f+#define RunAccel 1000.f+#define RunReduce 400.f+#define AirMult .65f+#define HoldingMaxRun 70.f+#define HoldMinTime .35f+#define BounceAutoJumpTime .1f+#define DuckFriction 500.f+#define DuckCorrectCheck 4+#define DuckCorrectSlide 50.f+#define DodgeSlideSpeedMult 1.2f+#define DuckSuperJumpXMult 1.25f+#define DuckSuperJumpYMult .5f+#define JumpGraceTime 0.1f+#define JumpSpeed -105.f+#define JumpHBoost 40.f+#define VarJumpTime .2f+#define CeilingVarJumpGrace .05f+#define UpwardCornerCorrection 4+#define WallSpeedRetentionTime .06f+#define WallJumpCheckDist 3+#define WallJumpForceTime .16f+#define WallJumpHSpeed (MaxRun + JumpHBoost)+#define WallSlideStartMax 20.f+#define WallSlideTime 1.2f+#define BounceVarJumpTime .2f+#define BounceSpeed -140.f+#define SuperBounceVarJumpTime .2f+#define SuperBounceSpeed -185.f+#define SuperJumpSpeed JumpSpeed+#define SuperJumpH 260.f+#define SuperWallJumpSpeed -160.f+#define SuperWallJumpVarTime .25f+#define SuperWallJumpForceTime .2f+#define SuperWallJumpH (MaxRun + JumpHBoost * 2)+#define DashSpeed 240.f+#define EndDashSpeed 160.f+#define EndDashUpMult .75f+#define DashTime .15f+#define DashCooldown .2f+#define DashRefillCooldown .1f+#define DashHJumpThruNudge 6+#define DashCornerCorrection 4+#define DashVFloorSnapDist 3+#define DashAttackTime .3f+#define BoostMoveSpeed 80.f+#define BoostTime .25f+#define DuckWindMult 0.f+#define WindWallDistance 3+#define ReboundSpeedX 120.f+#define ReboundSpeedY -120.f+#define ReboundVarJumpTime .15f+#define ReflectBoundSpeed 220.f+#define DreamDashSpeed DashSpeed+#define DreamDashEndWiggle 5+#define DreamDashMinTime .1f+#define ClimbMaxStamina 110.f+#define ClimbUpCost (100 / 2.2f)+#define ClimbStillCost (100 / 10.f)+#define ClimbJumpCost (110 / 4.f)+#define ClimbCheckDist 2+#define ClimbUpCheckDist 2+#define ClimbNoMoveTime .1f+#define ClimbTiredThreshold 20.f+#define ClimbUpSpeed -45.f+#define ClimbDownSpeed 80.f+#define ClimbSlipSpeed 30.f+#define ClimbAccel 900.f+#define ClimbGrabYMult .2f+#define ClimbHopY -120.f+#define ClimbHopX 100.f+#define ClimbHopForceTime .2f+#define ClimbJumpBoostTime .2f+#define ClimbHopNoWindTime .3f+#define LaunchSpeed 280.f+#define LaunchCancelThreshold 220.f+#define LiftYCap -130.f+#define LiftXCap 250.f+#define JumpThruAssistSpeed -40.f+#define ThrowRecoil 80.f+#define WalkSpeed 64.f+#define SpacePhysicsMult .6f+#define SwimYSpeedMult .5f+#define SwimMaxRise -60.f+#define SwimVDeccel 600.f+#define SwimMax 80.f+#define SwimUnderwaterMax 60.f+#define SwimAccel 600.f+#define SwimReduce 400.f+#define SwimDashSpeedMult .75f+#define HitSquashNoMoveTime .1f+#define HitSquashFriction 800.f+#define StarFlyTransformDeccel 1000.f+#define StarFlyTime 2.f+#define StarFlyStartSpeed 250.f+#define StarFlyTargetSpeed 140.f+#define StarFlyMaxSpeed 190.f+#define StarFlyMaxLerpTime 1.f+#define StarFlySlowSpeed (StarFlyTargetSpeed * .65f)+#define StarFlyAccel 1000.f+#define StarFlyRotateSpeed (320 * PI_F / 180)+#define StarFlyEndFlashDuration 0.5f+#define StarFlyEndNoBounceTime .2f+#define StarFlyWallBounce -.5f+#define StarFlyMaxExitY 0.f+#define StarFlyMaxExitX 140.f+#define StarFlyExitUp -100.f+#define WallBoosterSpeed -160.f+#define WallBoosterLiftSpeed -80.f+#define WallBoosterAccel 600.f++#define NormalHairColor 0xAC3232+#define FlyPowerHairColor 0xF2EB6D+#define UsedHairColor 0x44B7FF+#define FlashHairColor 0xFFFFFF+#define TwoDashesHairColor 0xFF6DEF+#define StarFlyColor 0xFFD65C++/* hitboxes: w, h, x, y */+static const float HB_NORMAL[4] = {8, 11, -4, -11}, HB_DUCK[4] = {8, 6, -4, -6};+static const float HB_NORMAL_HURT[4] = {8, 9, -4, -11}, HB_DUCK_HURT[4] = {8, 4, -4, -6};+static const float HB_STARFLY[4] = {8, 8, -4, -10}, HB_STARFLY_HURT[4] = {6, 6, -3, -9};+static const float *hurtbox = HB_NORMAL_HURT;++static Ent *E; /* the player's entity, during an update */+#define P (&g_player)++static void set_box(const float *b) { ent_box(E, b[0], b[1], b[2], b[3]); }+static bool box_is(const float *b) { return E->cw == b[0] && E->ch == b[1] && E->cx == b[2] && E->cy == b[3]; }+static void on_collide_h(Ent *e, Collision *c);+static void on_collide_v(Ent *e, Collision *c);++/* ---------------------------------------------------------------- small helpers */+static bool solid_at(float dx, float dy) { return collide_solid(E, E->x + dx, E->y + dy); }+static bool jumpthru_outside_at(float dx, float dy) { return collide_first_jumpthru_outside(E, E->x + dx, E->y + dy) != NULL; }+static V2 center(void) { return e_center(E); }+static V2 bottom_center(void) { return v2(e_cxm(E), e_bottom(E)); }+V2 player_center(const Player *p) { return e_center(p->ent); }+static float angle_of(V2 v) { return atan2f(v.y, v.x); }+static uint32_t lerp_color(uint32_t a, uint32_t b, float t) {+ t = clampf(t, 0, 1);+ int r = (int)(((a >> 16) & 255) + (((int)((b >> 16) & 255) - (int)((a >> 16) & 255)) * t));+ int g = (int)(((a >> 8) & 255) + (((int)((b >> 8) & 255) - (int)((a >> 8) & 255)) * t));+ int bl = (int)((a & 255) + (((int)(b & 255) - (int)(a & 255)) * t));+ return (uint32_t)(r << 16 | g << 8 | bl);+}+static uint32_t hair_rgb;++static void play(int anim) { spr_play(&P->spr, anim, false); }+static void play_r(int anim) { spr_play(&P->spr, anim, true); }+static int last_anim(void) { return P->spr.last_goto; }++int player_max_dashes(const Player *p) { return p->inventory_dashes; }+bool player_dash_attacking(const Player *p) { return p->dash_attack_timer > 0 || p->state == ST_REDDASH; }+bool player_ducking(const Player *p) { (void)p; return box_is(HB_DUCK); }+void player_set_ducking(Player *p, bool d) {+ (void)p;+ if (d) set_box(HB_DUCK), hurtbox = HB_DUCK_HURT;+ else set_box(HB_NORMAL), hurtbox = HB_NORMAL_HURT;+}+#define Ducking player_ducking(P)+static void set_ducking(bool d) { player_set_ducking(P, d); }++static bool can_unduck(void) {+ if (!Ducking) return true;+ float w[4] = {E->cw, E->ch, E->cx, E->cy};+ set_box(HB_NORMAL);+ bool ok = !solid_at(0, 0);+ ent_box(E, w[0], w[1], w[2], w[3]);+ return ok;+}+static bool can_unduck_at(float x, float y) {+ float ox = E->x, oy = E->y;+ E->x = x, E->y = y;+ bool r = can_unduck();+ E->x = ox, E->y = oy;+ return r;+}+static bool duck_free_at(float x, float y) {+ float ox = E->x, oy = E->y, w[4] = {E->cw, E->ch, E->cx, E->cy};+ E->x = x, E->y = y;+ set_box(HB_DUCK);+ bool r = !solid_at(0, 0);+ E->x = ox, E->y = oy;+ ent_box(E, w[0], w[1], w[2], w[3]);+ return r;+}++static V2 lift_boost(void) {+ V2 v = actor_lift(E);+ if (fabsf(v.x) > LiftXCap) v.x = LiftXCap * signf(v.x);+ if (v.y > 0) v.y = 0;+ else if (v.y < LiftYCap) v.y = LiftYCap;+ return v;+}++bool player_in_control(const Player *p) {+ switch (p->state) {+ case ST_INTROJUMP: case ST_INTROWALK: case ST_INTROWAKEUP: case ST_INTRORESPAWN: case ST_DUMMY: case ST_FROZEN:+ case ST_BIRDDASHTUTORIAL: return false;+ default: return true;+ }+}++static bool is_tired(void) { return (P->wall_boost_timer > 0 ? P->stamina + ClimbJumpCost : P->stamina) < ClimbTiredThreshold; }+bool player_refill_dash(Player *p) {+ if (p->dashes < player_max_dashes(p)) {+ p->dashes = player_max_dashes(p);+ return true;+ }+ return false;+}+bool player_use_refill(Player *p, bool two) {+ int max = two ? 2 : player_max_dashes(p);+ if (p->dashes < max || p->stamina < ClimbTiredThreshold) {+ p->dashes = max;+ player_refill_stamina(p);+ return true;+ }+ return false;+}+void player_refill_stamina(Player *p) { p->stamina = ClimbMaxStamina; }++static bool climb_bounds_check(int dir) {+ Room *rm = g_level.room;+ return e_left(E) + dir * ClimbCheckDist >= rm->x && e_right(E) + dir * ClimbCheckDist < rm->x + rm->w;+}+static bool climb_blocker(float x, float y) {+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if ((o->kind & KIND_CLIMBBLOCKER) && o->cls && o->collidable && o->dead != 1 && collide_ent_at(E, x, y, o)) return true;+ }+ return false;+}+static bool climb_check(int dir, int yadd) {+ return climb_bounds_check(dir) && !climb_blocker(E->x + ClimbCheckDist * P->facing, E->y + yadd) &&+ solid_at(dir * ClimbCheckDist, yadd);+}+static bool wall_jump_check(int dir) { return climb_bounds_check(dir) && solid_at(dir * WallJumpCheckDist, 0); }+static bool water_at(float dx, float dy) { return collide_first_kind(E, E->x + dx, E->y + dy, KIND_WATER) != NULL; }+static bool swim_check(void) { return water_at(0, -8) && water_at(0, 0); }+static bool swim_underwater_check(void) { return water_at(0, -9); }+static bool swim_jump_check(void) { return !water_at(0, -14); }+static bool swim_rise_check(void) { return !water_at(0, -18); }++static V2 aim_vector(void) {+ int x = g_in.aim_x, y = g_in.aim_y;+ if (!x && !y) return v2((float)P->facing, 0);+ if (x && y) return v2(x * 0.70710677f, y * 0.70710677f);+ return v2((float)x, (float)y);+}++/* ---------------------------------------------------------------- states */+static int normal_update(void), climb_update(void), dash_update(void), swim_update(void), boost_update(void),+ red_dash_update(void), hit_squash_update(void), launch_update(void), dream_dash_update(void),+ summit_launch_update(void), dummy_update(void), star_fly_update(void), attract_update(void), frozen_update(void),+ temple_fall_update(void), reflection_fall_update(void), bird_update(void), cassette_update(void);+static void bird_begin(void);+static void normal_begin(void), normal_end(void), climb_begin(void), climb_end(void), dash_begin(void), dash_end(void),+ swim_begin(void), boost_begin(void), boost_end(void), red_dash_begin(void), red_dash_end(void),+ hit_squash_begin(void), launch_begin(void), dream_dash_begin(void), dream_dash_end(void),+ summit_launch_begin(void), dummy_begin(void), intro_respawn_begin(void), intro_respawn_end(void),+ star_fly_begin(void), star_fly_end(void), attract_begin(void), cassette_fly_begin(void), reflection_fall_begin(void),+ reflection_fall_end(void);+static float co_dash(void), co_boost(void), co_red_dash(void), co_pickup(void), co_intro_walk(void),+ co_intro_jump(void), co_intro_wakeup(void), co_star_fly(void), co_temple_fall(void), co_bird(void),+ co_cassette_fly(void), co_reflection_fall(void);++typedef int (*UpdFn)(void);+typedef void (*VFn)(void);+typedef float (*CoFn)(void);+static const UpdFn UPD[ST_COUNT] = {+ normal_update, climb_update, dash_update, swim_update, boost_update, red_dash_update, hit_squash_update,+ launch_update, NULL, dream_dash_update, summit_launch_update, dummy_update, NULL, NULL, NULL, NULL, bird_update,+ frozen_update, reflection_fall_update, star_fly_update, temple_fall_update, cassette_update, attract_update};+static const VFn BEGIN[ST_COUNT] = {+ normal_begin, climb_begin, dash_begin, swim_begin, boost_begin, red_dash_begin, hit_squash_begin, launch_begin,+ NULL, dream_dash_begin, summit_launch_begin, dummy_begin, NULL, NULL, intro_respawn_begin, NULL, bird_begin,+ NULL, reflection_fall_begin, star_fly_begin, NULL, cassette_fly_begin, attract_begin};+static const VFn END[ST_COUNT] = {+ normal_end, climb_end, dash_end, NULL, boost_end, red_dash_end, NULL, NULL, NULL, dream_dash_end, NULL, NULL,+ NULL, NULL, intro_respawn_end, NULL, NULL, NULL, reflection_fall_end, star_fly_end, NULL, NULL, NULL};+static const CoFn CO[ST_COUNT] = {+ NULL, NULL, co_dash, NULL, co_boost, co_red_dash, NULL, NULL, co_pickup, NULL, NULL, NULL, co_intro_walk,+ co_intro_jump, NULL, co_intro_wakeup, co_bird, NULL, co_reflection_fall, co_star_fly, co_temple_fall, co_cassette_fly,+ NULL};++void player_set_state(Player *p, int st) {+ if (p->state_locked || p->state == st) return;+ p->prev_state = p->state;+ p->state = st;+ if (p->prev_state >= 0 && END[p->prev_state]) END[p->prev_state]();+ if (BEGIN[st]) BEGIN[st]();+ if (CO[st]) {+ p->co_active = true;+ p->co_step = 0;+ p->co_wait = 0;+ p->co_t = 0;+ } else+ p->co_active = false;+}+#define SET(st) player_set_state(P, st)++static void co_update(void) {+ if (!P->co_active) return;+ if (P->co_wait > 0) {+ P->co_wait -= DT;+ return;+ }+ int st = P->state;+ float r = CO[st]();+ if (P->state != st || !P->co_active) return; /* replaced or cancelled */+ if (r < 0) P->co_active = false;+ else P->co_wait = r;+}++/* ---------------------------------------------------------------- jumps */+void player_jump(Player *p, bool particles, bool sfx) {+ (void)sfx;+ btn_consume_buffer(&g_in.jump);+ p->jump_grace_timer = 0;+ p->var_jump_timer = VarJumpTime;+ p->auto_jump = false;+ p->dash_attack_timer = 0;+ p->wall_slide_timer = WallSlideTime;+ p->wall_boost_timer = 0;+ p->speed.x += JumpHBoost * p->move_x;+ p->speed.y = JumpSpeed;+ p->speed = v2add(p->speed, lift_boost());+ p->var_jump_speed = p->speed.y;+ V2 lb = lift_boost();+ p->launched = (lb.x * lb.x + lb.y * lb.y >= 100 * 100 && p->speed.x * p->speed.x + p->speed.y * p->speed.y >= 220 * 220);+ p->spr.sx = .6f, p->spr.sy = 1.4f;+ if (particles) dust_burst(bottom_center(), -PI_F / 2, 4);+}+static void jump(void) { player_jump(P, true, true); }++static void super_jump(void) {+ btn_consume_buffer(&g_in.jump);+ P->jump_grace_timer = 0;+ P->var_jump_timer = VarJumpTime;+ P->auto_jump = false;+ P->dash_attack_timer = 0;+ P->wall_slide_timer = WallSlideTime;+ P->wall_boost_timer = 0;+ P->speed.x = SuperJumpH * P->facing;+ P->speed.y = JumpSpeed;+ P->speed = v2add(P->speed, lift_boost());+ if (Ducking) {+ set_ducking(false);+ P->speed.x *= DuckSuperJumpXMult;+ P->speed.y *= DuckSuperJumpYMult;+ }+ P->var_jump_speed = P->speed.y;+ P->launched = true;+ P->spr.sx = .6f, P->spr.sy = 1.4f;+ dust_burst(bottom_center(), -PI_F / 2, 4);+}++static void wall_jump(int dir) {+ set_ducking(false);+ btn_consume_buffer(&g_in.jump);+ P->jump_grace_timer = 0;+ P->var_jump_timer = VarJumpTime;+ P->auto_jump = false;+ P->dash_attack_timer = 0;+ P->wall_slide_timer = WallSlideTime;+ P->wall_boost_timer = 0;+ if (P->move_x != 0) {+ P->force_move_x = dir;+ P->force_move_x_timer = WallJumpForceTime;+ }+ if (actor_lift(E).x == 0 && actor_lift(E).y == 0) {+ Ent *wall = collide_first_solid(E, E->x + WallJumpCheckDist, E->y);+ if (wall) actor_set_lift(E, wall->lift);+ }+ P->speed.x = WallJumpHSpeed * dir;+ P->speed.y = JumpSpeed;+ P->speed = v2add(P->speed, lift_boost());+ P->var_jump_speed = P->speed.y;+ V2 lb = lift_boost();+ P->launched = (lb.x * lb.x + lb.y * lb.y >= 100 * 100 && P->speed.x * P->speed.x + P->speed.y * P->speed.y >= 220 * 220);+ P->spr.sx = .6f, P->spr.sy = 1.4f;+ if (dir == -1) dust_burst(v2add(center(), v2(2, 0)), -3 * PI_F / 4, 4);+ else dust_burst(v2add(center(), v2(-2, 0)), -PI_F / 4, 4);+}++static void super_wall_jump(int dir) {+ set_ducking(false);+ btn_consume_buffer(&g_in.jump);+ P->jump_grace_timer = 0;+ P->var_jump_timer = SuperWallJumpVarTime;+ P->auto_jump = false;+ P->dash_attack_timer = 0;+ P->wall_slide_timer = WallSlideTime;+ P->wall_boost_timer = 0;+ P->speed.x = SuperWallJumpH * dir;+ P->speed.y = SuperWallJumpSpeed;+ P->speed = v2add(P->speed, lift_boost());+ P->var_jump_speed = P->speed.y;+ P->launched = true;+ P->spr.sx = .6f, P->spr.sy = 1.4f;+ if (dir == -1) dust_burst(v2add(center(), v2(2, 0)), -3 * PI_F / 4, 4);+ else dust_burst(v2add(center(), v2(-2, 0)), -PI_F / 4, 4);+}++static void climb_jump(void) {+ if (!P->on_ground) {+ P->stamina -= ClimbJumpCost;+ spr_play(&P->sweat, A_player_sweat_jump, true);+ }+ P->dream_jump = false;+ player_jump(P, false, false);+ if (P->move_x == 0) {+ P->wall_boost_dir = -P->facing;+ P->wall_boost_timer = ClimbJumpBoostTime;+ }+ if (P->facing == 1) dust_burst(v2add(center(), v2(2, 0)), -3 * PI_F / 4, 4);+ else dust_burst(v2add(center(), v2(-2, 0)), -PI_F / 4, 4);+}++void player_bounce(Player *p, float from_y) {+ float w[4] = {E->cw, E->ch, E->cx, E->cy};+ set_box(HB_NORMAL);+ actor_move_v_exact(E, (int)(from_y - e_bottom(E)), NULL, NULL);+ if (!p->inventory_norefills) player_refill_dash(p);+ player_refill_stamina(p);+ player_set_state(p, ST_NORMAL);+ p->jump_grace_timer = 0;+ p->var_jump_timer = BounceVarJumpTime;+ p->auto_jump = true;+ p->auto_jump_timer = BounceAutoJumpTime;+ p->dash_attack_timer = 0;+ p->wall_slide_timer = WallSlideTime;+ p->wall_boost_timer = 0;+ p->var_jump_speed = p->speed.y = BounceSpeed;+ p->launched = false;+ p->spr.sx = .6f, p->spr.sy = 1.4f;+ ent_box(E, w[0], w[1], w[2], w[3]);+}++void player_super_bounce(Player *p, float from_y) {+ float w[4] = {E->cw, E->ch, E->cx, E->cy};+ set_box(HB_NORMAL);+ actor_move_v(E, from_y - e_bottom(E), NULL, NULL);+ if (!p->inventory_norefills) player_refill_dash(p);+ player_refill_stamina(p);+ player_set_state(p, ST_NORMAL);+ p->jump_grace_timer = 0;+ p->var_jump_timer = SuperBounceVarJumpTime;+ p->auto_jump = true;+ p->auto_jump_timer = 0;+ p->dash_attack_timer = 0;+ p->wall_slide_timer = WallSlideTime;+ p->wall_boost_timer = 0;+ p->speed.x = 0;+ p->var_jump_speed = p->speed.y = SuperBounceSpeed;+ p->launched = false;+ level_dir_shake(v2(0, -1), .1f);+ p->spr.sx = .5f, p->spr.sy = 1.5f;+ ent_box(E, w[0], w[1], w[2], w[3]);+}++void player_side_bounce(Player *p, int dir, float from_x, float from_y) {+ float w[4] = {E->cw, E->ch, E->cx, E->cy};+ set_box(HB_NORMAL);+ actor_move_v(E, clampf(from_y - e_bottom(E), -4, 4), NULL, NULL);+ if (dir > 0) actor_move_h(E, from_x - e_left(E), NULL, NULL);+ else if (dir < 0) actor_move_h(E, from_x - e_right(E), NULL, NULL);+ if (!p->inventory_norefills) player_refill_dash(p);+ player_refill_stamina(p);+ player_set_state(p, ST_NORMAL);+ p->jump_grace_timer = 0;+ p->var_jump_timer = BounceVarJumpTime;+ p->auto_jump = true;+ p->auto_jump_timer = 0;+ p->dash_attack_timer = 0;+ p->wall_slide_timer = WallSlideTime;+ p->force_move_x = dir;+ p->force_move_x_timer = .3f;+ p->wall_boost_timer = 0;+ p->launched = false;+ p->speed.x = 240 * dir;+ p->var_jump_speed = p->speed.y = BounceSpeed;+ level_dir_shake(v2((float)dir, 0), .1f);+ p->spr.sx = 1.5f, p->spr.sy = .5f;+ ent_box(E, w[0], w[1], w[2], w[3]);+}++void player_rebound(Player *p, int dir) {+ p->speed.x = dir * ReboundSpeedX;+ p->speed.y = ReboundSpeedY;+ p->var_jump_speed = p->speed.y;+ p->var_jump_timer = ReboundVarJumpTime;+ p->auto_jump = true;+ p->auto_jump_timer = 0;+ p->dash_attack_timer = 0;+ p->wall_slide_timer = WallSlideTime;+ p->wall_boost_timer = 0;+ p->launched = false;+ p->force_move_x_timer = 0;+ player_set_state(p, ST_NORMAL);+}++static void reflect_bounce(V2 dir) {+ if (dir.x != 0) P->speed.x = dir.x * ReflectBoundSpeed;+ if (dir.y != 0) P->speed.y = dir.y * ReflectBoundSpeed;+ P->auto_jump_timer = 0;+ P->dash_attack_timer = 0;+ P->wall_slide_timer = WallSlideTime;+ P->wall_boost_timer = 0;+ P->launched = false;+ P->force_move_x_timer = 0;+ SET(ST_NORMAL);+}++void player_point_bounce(Player *p, V2 from) {+ if (p->state == ST_BOOST && p->current_booster) p->current_booster = NULL;+ player_refill_dash(p);+ player_refill_stamina(p);+ V2 d = v2sub(center(), from);+ float l = v2len(d);+ p->speed = l > 0 ? v2mul(d, 200 / l) : v2(0, 0);+ p->speed.x *= 1.2f;+ if (fabsf(p->speed.x) < 120) {+ if (p->speed.x == 0) p->speed.x = -p->facing * 120.f;+ else p->speed.x = signf(p->speed.x) * 120;+ }+}++bool player_bounce_check(const Player *p, float y) { return e_bottom(p->ent) <= y + 3; }++/* ---------------------------------------------------------------- death */+void player_die_ex(Player *p, V2 dir, bool even, bool stats) {+ (void)even;+ if (p->dead || p->state == ST_REFLECTIONFALL) return;+ if (stats) {+ g_session.deaths++;+ g_session.deaths_in_current_level++;+ save_add_death();+ }+ int golden = berry_golden_room(); /* holding the golden: back to where it was found */+ p->dead = true;+ leader_lose_all();+ p->speed = v2(0, 0);+ p->state_locked = true;+ E = p->ent;+ if (p->holding) holdable_release(p->holding, v2(0, 0)), p->holding = NULL;+ E->collidable = 0;+ E->depth = D_TOP;+ ents_mark_unsorted();+ level_shake(.3f);+ /* PlayerDeadBody */+ p->body = true;+ p->body_bounce = dir;+ p->body_t = 0;+ p->body_step = 0;+ p->body_scale = 1;+ p->death_effect = -1;+ p->death_color = (uint16_t)rgb(hair_rgb);+ p->death_finished = false;+ p->golden_room = golden;+ p->co_active = false;+ btn_consume_buffer(&g_in.dash);+ btn_consume_buffer(&g_in.jump);+}++static void death_wiped(void) { g_level.dead_reload = true; }++/* PlayerDeadBody.DeathRoutine, a frame at a time */+static void body_update(void) {+ Player *p = P;+ if (p->body_step == 0) {+ if (p->body_bounce.x != 0 || p->body_bounce.y != 0) {+ p->body_scale = 1.5f;+ level_freeze(0.05f);+ p->body_step = 1;+ p->respawn_from = v2(E->x, E->y);+ return;+ }+ p->body_step = 3;+ }+ if (p->body_step == 1) { /* the bounce tween, 0.5 s, stopped at 75% */+ p->body_t += DT;+ float t = fminf(p->body_t / 0.5f, 1);+ float eased = ease_cube_out(t);+ E->x = p->respawn_from.x + p->body_bounce.x * 24 * eased;+ E->y = p->respawn_from.y + p->body_bounce.y * 24 * eased;+ p->body_scale = 1.5f - eased * 0.5f;+ p->spr.rot = floorf(eased * 4) * 6.2831855f;+ if (p->body_t >= 0.5f * 0.75f) p->body_step = 3;+ return;+ }+ if (p->body_step == 3) {+ E->y -= 5;+ level_shake(.3f);+ p->death_effect = 0;+ p->body_step = 4;+ p->body_t = 0;+ return;+ }+ if (p->body_step == 4) {+ p->death_effect += DT / 0.834f;+ p->body_t += DT;+ if (p->body_t >= 0.834f * 0.65f) { /* End(): the area's wipe, then the reload (or the golden's restart) */+ p->body_step = 5;+ wipe_area(false, death_wiped);+ }+ return;+ }+ if (p->body_step == 5) p->death_effect += DT / 0.834f;+}++/* DeathEffect.Draw */+static void death_effect_draw(V2 pos, uint16_t color, float ease) {+ uint16_t c2 = ((int)floorf(ease * 10) % 2 == 0) ? color : 0xFFFF;+ float s = ease < 0.5f ? 0.5f + ease : ease_cube_out(1 - (ease - 0.5f) * 2);+ for (int pass = 0; pass < 2; pass++)+ for (int i = 0; i < 8; i++) {+ V2 v = angle_vec((i / 8.f + ease * 0.25f) * 2 * PI_F, ease_cube_out(ease) * 24);+ V2 at = v2add(pos, v);+ if (!pass) {+ gfx_tex_ex(T_characters_player_hair00, at.x - 1, at.y, 5, 5, s, s, 0, 0, 255, GF_SILHOUETTE);+ gfx_tex_ex(T_characters_player_hair00, at.x + 1, at.y, 5, 5, s, s, 0, 0, 255, GF_SILHOUETTE);+ gfx_tex_ex(T_characters_player_hair00, at.x, at.y - 1, 5, 5, s, s, 0, 0, 255, GF_SILHOUETTE);+ gfx_tex_ex(T_characters_player_hair00, at.x, at.y + 1, 5, 5, s, s, 0, 0, 255, GF_SILHOUETTE);+ } else+ gfx_tex_ex(T_characters_player_hair00, at.x, at.y, 5, 5, s, s, 0, c2, 255, GF_SILHOUETTE);+ }+}++/* ---------------------------------------------------------------- collisions */+static bool dream_dash_check(V2 dir);++static void on_collide_h(Ent *e, Collision *c) {+ (void)e;+ if (P->state == ST_STARFLY) {+ if (P->star_fly_timer < StarFlyEndNoBounceTime) P->speed.x = 0;+ else P->speed.x *= StarFlyWallBounce;+ return;+ }+ if (P->state == ST_DREAMDASH) return;+ if (player_dash_attacking(P) && c->hit && c->hit->cls->on_dash_collide && c->dir.x == signf(P->dash_dir.x)) {+ int r = c->hit->cls->on_dash_collide(c->hit, P, c->dir);+ if (P->state == ST_REDDASH) r = DASH_IGNORE;+ if (r == DASH_REBOUND) { player_rebound(P, -(int)signf(P->speed.x)); return; }+ if (r == DASH_BOUNCE) { reflect_bounce(v2(-signf(P->speed.x), 0)); return; }+ if (r == DASH_IGNORE) return;+ }+ if (P->state == ST_DASH || P->state == ST_REDDASH) {+ if (P->on_ground && duck_free_at(E->x + signf(P->speed.x), E->y)) {+ set_ducking(true);+ return;+ } else if (P->speed.y == 0 && P->speed.x != 0) {+ for (int i = 1; i <= DashCornerCorrection; i++)+ for (int j = 1; j >= -1; j -= 2)+ if (!solid_at(signf(P->speed.x), (float)(i * j))) {+ actor_move_v_exact(E, i * j, NULL, NULL);+ actor_move_h_exact(E, (int)signf(P->speed.x), NULL, NULL);+ return;+ }+ }+ }+ if (dream_dash_check(v2(signf(P->speed.x), 0))) {+ SET(ST_DREAMDASH);+ P->dash_attack_timer = 0;+ return;+ }+ if (P->wall_speed_retention_timer <= 0) {+ P->wall_speed_retained = P->speed.x;+ P->wall_speed_retention_timer = WallSpeedRetentionTime;+ }+ if (c->hit && c->hit->cls->on_collide) c->hit->cls->on_collide(c->hit, c->dir);+ P->speed.x = 0;+ P->dash_attack_timer = 0;+ if (P->state == ST_REDDASH) SET(ST_HITSQUASH);+}++static void on_collide_v(Ent *e, Collision *c) {+ (void)e;+ if (P->state == ST_STARFLY) {+ if (P->star_fly_timer < StarFlyEndNoBounceTime) P->speed.y = 0;+ else P->speed.y *= StarFlyWallBounce;+ return;+ }+ if (P->state == ST_SWIM) {+ P->speed.y = 0;+ return;+ }+ if (P->state == ST_DREAMDASH) return;+ if (c->hit && c->hit->cls->on_dash_collide) {+ if (player_dash_attacking(P) && c->dir.y == signf(P->dash_dir.y)) {+ int r = c->hit->cls->on_dash_collide(c->hit, P, c->dir);+ if (P->state == ST_REDDASH) r = DASH_IGNORE;+ if (r == DASH_REBOUND) { player_rebound(P, 0); return; }+ if (r == DASH_BOUNCE) { reflect_bounce(v2(0, -signf(P->speed.y))); return; }+ if (r == DASH_IGNORE) return;+ } else if (P->state == ST_SUMMITLAUNCH) {+ c->hit->cls->on_dash_collide(c->hit, P, c->dir);+ return;+ }+ }+ if (P->speed.y > 0) {+ if ((P->state == ST_DASH || P->state == ST_REDDASH) && !P->dash_started_on_ground) {+ if (P->speed.x <= 0)+ for (int i = -1; i >= -DashCornerCorrection; i--)+ if (!actor_on_ground_at(E, E->x + i, E->y, 1)) {+ actor_move_h_exact(E, i, NULL, NULL);+ actor_move_v_exact(E, 1, NULL, NULL);+ return;+ }+ if (P->speed.x >= 0)+ for (int i = 1; i <= DashCornerCorrection; i++)+ if (!actor_on_ground_at(E, E->x + i, E->y, 1)) {+ actor_move_h_exact(E, i, NULL, NULL);+ actor_move_v_exact(E, 1, NULL, NULL);+ return;+ }+ }+ if (dream_dash_check(v2(0, signf(P->speed.y)))) {+ SET(ST_DREAMDASH);+ P->dash_attack_timer = 0;+ return;+ }+ if (P->dash_dir.x != 0 && P->dash_dir.y > 0 && P->speed.y > 0) {+ P->dash_dir.x = signf(P->dash_dir.x);+ P->dash_dir.y = 0;+ P->speed.y = 0;+ P->speed.x *= DodgeSlideSpeedMult;+ set_ducking(true);+ }+ if (P->state != ST_CLIMB) {+ float squish = fminf(P->speed.y / FastMaxFall, 1);+ P->spr.sx = lerpf(1, 1.6f, squish);+ P->spr.sy = lerpf(1, .4f, squish);+ if (P->speed.y >= MaxFall / 2) dust_burst(v2(E->x, E->y), -PI_F / 2, 8);+ if (P->highest_air_y < E->y - 50 && P->speed.y >= MaxFall && fabsf(P->speed.x) >= MaxRun) play(A_player_runStumble);+ P->play_footstep_on_land = 0;+ }+ } else {+ if (P->speed.y < 0) {+ if (P->speed.x <= 0)+ for (int i = 1; i <= UpwardCornerCorrection; i++)+ if (!solid_at((float)-i, -1)) {+ E->x -= i, E->y -= 1;+ return;+ }+ if (P->speed.x >= 0)+ for (int i = 1; i <= UpwardCornerCorrection; i++)+ if (!solid_at((float)i, -1)) {+ E->x += i, E->y -= 1;+ return;+ }+ if (P->var_jump_timer < VarJumpTime - CeilingVarJumpGrace) P->var_jump_timer = 0;+ }+ if (dream_dash_check(v2(0, signf(P->speed.y)))) {+ SET(ST_DREAMDASH);+ P->dash_attack_timer = 0;+ return;+ }+ }+ if (c->hit && c->hit->cls->on_collide) c->hit->cls->on_collide(c->hit, c->dir);+ P->dash_attack_timer = 0;+ P->speed.y = 0;+ if (P->state == ST_REDDASH) SET(ST_HITSQUASH);+}++static bool solid_or_dream_at(float x, float y) {+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if ((o->kind & KIND_SOLID) && !(o->kind & KIND_DREAMBLOCK) && o->cls && o != E && o->collidable && o->dead != 1 &&+ collide_ent_at(E, x, y, o))+ return true;+ }+ return false;+}++static bool dream_dash_check(V2 dir) {+ if (!(P->inventory_dreamdash && player_dash_attacking(P) && (dir.x == signf(P->dash_dir.x) || dir.y == signf(P->dash_dir.y))))+ return false;+ Ent *block = collide_first_kind(E, E->x + dir.x, E->y + dir.y, KIND_DREAMBLOCK);+ if (!block) return false;+ if (solid_or_dream_at(E->x + dir.x, E->y + dir.y)) {+ V2 side = v2(fabsf(dir.y), fabsf(dir.x));+ bool neg, pos;+ if (dir.x != 0) neg = P->speed.y <= 0, pos = P->speed.y >= 0;+ else neg = P->speed.x <= 0, pos = P->speed.x >= 0;+ if (neg)+ for (int i = -1; i >= -DashCornerCorrection; i--)+ if (!solid_or_dream_at(E->x + dir.x + side.x * i, E->y + dir.y + side.y * i)) {+ E->x += side.x * i, E->y += side.y * i;+ P->dream_block = block;+ return true;+ }+ if (pos)+ for (int i = 1; i <= DashCornerCorrection; i++)+ if (!solid_or_dream_at(E->x + dir.x + side.x * i, E->y + dir.y + side.y * i)) {+ E->x += side.x * i, E->y += side.y * i;+ P->dream_block = block;+ return true;+ }+ return false;+ }+ P->dream_block = block;+ return true;+}++void player_on_bounds_h(Player *p) {+ p->speed.x = 0;+ if (p->state == ST_REDDASH) player_set_state(p, ST_NORMAL);+}+void player_on_bounds_v(Player *p) {+ p->speed.y = 0;+ if (p->state == ST_REDDASH) player_set_state(p, ST_NORMAL);+}++static void on_squish(Ent *e, Collision *c) {+ E = e;+ bool ducked = false;+ if (!Ducking) {+ ducked = true;+ set_ducking(true);+ if (c->pusher) c->pusher->collidable = 1;+ if (!solid_at(0, 0)) {+ if (c->pusher) c->pusher->collidable = 0;+ return;+ }+ float wx = E->x, wy = E->y;+ E->x = c->target.x, E->y = c->target.y;+ if (!solid_at(0, 0)) {+ if (c->pusher) c->pusher->collidable = 0;+ return;+ }+ E->x = wx, E->y = wy;+ if (c->pusher) c->pusher->collidable = 0;+ }+ if (!actor_try_squish_wiggle(E, c)) player_die(P, v2(0, 0), false);+ else if (ducked && can_unduck()) set_ducking(false);+}++static bool is_riding_solid(Ent *e, Ent *s) {+ if (P->state == ST_DREAMDASH) return collide_ent_at(e, e->x, e->y, s);+ if (P->state == ST_CLIMB || P->state == ST_HITSQUASH) return collide_ent_at(e, e->x + P->facing, e->y, s);+ return collide_ent_at(e, e->x, e->y + 1, s);+}+static bool is_riding_jumpthru(Ent *e, Ent *j) {+ if (P->state == ST_DREAMDASH) return false;+ return P->state != ST_CLIMB && P->speed.y >= 0 && !e->ignore_jumpthrus && collide_ent_at(e, e->x, e->y + 1, j) &&+ !collide_ent_at(e, e->x, e->y, j);+}++/* ---------------------------------------------------------------- normal */+static void normal_begin(void) { P->max_fall = MaxFall; }+static void normal_end(void) {+ P->wall_boost_timer = 0;+ P->wall_speed_retention_timer = 0;+ P->hop_wait_x = 0;+}++/* CanDash: not when Madeline stands where she can talk and the talk key is pressed */+static bool can_dash(void) {+ return btn_pressed(&g_in.dash) && P->dash_cooldown_timer <= 0 && P->dashes > 0 && (!g_talk_over || !btn_pressed(&g_in.talk));+}+static int start_dash(void) {+ P->was_dash_b = P->dashes == 2;+ P->dashes = P->dashes - 1 < 0 ? 0 : P->dashes - 1;+ btn_consume_buffer(&g_in.dash);+ return ST_DASH;+}++static void wall_slide_particles(int dir) {+ if (level_on_interval(.01f)) {+ V2 at = center();+ at = v2add(at, v2(dir == 1 ? 5.f : -5.f, 4));+ dust_burst(at, -PI_F / 2, 1);+ }+}++static Ent *holdable_check(void);++static int normal_update(void) {+ if (lift_boost().y < 0 && P->was_on_ground && !P->on_ground && P->speed.y >= 0) P->speed.y = lift_boost().y;+ if (!P->holding) {+ if (g_in.grab.check && !is_tired() && !Ducking) {+ Ent *h = holdable_check();+ if (h) {+ set_ducking(false);+ P->holding = h;+ P->min_hold_timer = HoldMinTime;+ return ST_PICKUP;+ }+ if (P->speed.y >= 0 && signf(P->speed.x) != -P->facing) {+ if (climb_check(P->facing, 0)) {+ set_ducking(false);+ return ST_CLIMB;+ }+ if (g_in.move_y < 1 && g_level.wind.y <= 0)+ for (int i = 1; i <= ClimbUpCheckDist; i++)+ if (!solid_at(0, (float)-i) && climb_check(P->facing, -i)) {+ actor_move_v_exact(E, -i, NULL, NULL);+ set_ducking(false);+ return ST_CLIMB;+ }+ }+ }+ if (can_dash()) {+ P->speed = v2add(P->speed, lift_boost());+ return start_dash();+ }+ if (Ducking) {+ if (P->on_ground && g_in.move_y != 1) {+ if (can_unduck()) {+ set_ducking(false);+ P->spr.sx = .8f, P->spr.sy = 1.2f;+ } else if (P->speed.x == 0) {+ for (int i = DuckCorrectCheck; i > 0; i--) {+ if (can_unduck_at(E->x + i, E->y)) {+ actor_move_h(E, DuckCorrectSlide * DT, on_collide_h, NULL);+ break;+ } else if (can_unduck_at(E->x - i, E->y)) {+ actor_move_h(E, -DuckCorrectSlide * DT, on_collide_h, NULL);+ break;+ }+ }+ }+ }+ } else if (P->on_ground && g_in.move_y == 1 && P->speed.y >= 0) {+ set_ducking(true);+ P->spr.sx = 1.4f, P->spr.sy = .6f;+ }+ } else {+ if (!g_in.grab.check && P->min_hold_timer <= 0) { /* Throw */+ if (g_in.move_y == 1) holdable_release(P->holding, v2(0, 0));+ else {+ holdable_release(P->holding, v2((float)P->facing, 0));+ P->speed.x += ThrowRecoil * -P->facing;+ }+ play(A_player_throw);+ P->holding = NULL;+ }+ if (!Ducking && P->on_ground && g_in.move_y == 1 && P->speed.y >= 0) { /* Drop */+ holdable_release(P->holding, v2(0, 0));+ P->holding = NULL;+ set_ducking(true);+ P->spr.sx = 1.4f, P->spr.sy = .6f;+ }+ }+ if (Ducking && P->on_ground) P->speed.x = approach(P->speed.x, 0, DuckFriction * DT);+ else {+ float mult = P->on_ground ? 1 : AirMult;+ if (P->on_ground && g_level.core_mode == 2) mult *= .3f;+ float max = P->holding ? HoldingMaxRun : MaxRun;+ if (g_level.in_space) max *= SpacePhysicsMult;+ if (fabsf(P->speed.x) > max && signf(P->speed.x) == P->move_x)+ P->speed.x = approach(P->speed.x, max * P->move_x, RunReduce * mult * DT);+ else+ P->speed.x = approach(P->speed.x, max * P->move_x, RunAccel * mult * DT);+ }+ {+ float mf = MaxFall, fmf = FastMaxFall;+ if (g_level.in_space) mf *= SpacePhysicsMult, fmf *= SpacePhysicsMult;+ if (g_in.move_y == 1 && P->speed.y >= mf) {+ P->max_fall = approach(P->max_fall, fmf, FastMaxAccel * DT);+ float half = mf + (fmf - mf) * .5f;+ if (P->speed.y >= half) {+ float l = fminf(1, (P->speed.y - half) / (fmf - half));+ P->spr.sx = lerpf(1, .5f, l);+ P->spr.sy = lerpf(1, 1.5f, l);+ }+ } else+ P->max_fall = approach(P->max_fall, mf, FastMaxAccel * DT);+ }+ if (!P->on_ground) {+ float max = P->max_fall;+ if ((P->move_x == P->facing || (P->move_x == 0 && g_in.grab.check)) && g_in.move_y != 1) {+ if (P->speed.y >= 0 && P->wall_slide_timer > 0 && !P->holding && climb_bounds_check(P->facing) &&+ solid_at((float)P->facing, 0) && can_unduck()) {+ set_ducking(false);+ P->wall_slide_dir = P->facing;+ }+ if (P->wall_slide_dir != 0) {+ if (P->wall_slide_timer > WallSlideTime * .5f && climb_blocker(E->x + P->wall_slide_dir, E->y))+ P->wall_slide_timer = WallSlideTime * .5f;+ max = lerpf(MaxFall, WallSlideStartMax, P->wall_slide_timer / WallSlideTime);+ if (P->wall_slide_timer / WallSlideTime > .65f) wall_slide_particles(P->wall_slide_dir);+ }+ }+ float mult = (fabsf(P->speed.y) < HalfGravThreshold && (g_in.jump.check || P->auto_jump)) ? .5f : 1.f;+ if (g_level.in_space) mult *= SpacePhysicsMult;+ P->speed.y = approach(P->speed.y, max, Gravity * mult * DT);+ }+ if (P->var_jump_timer > 0) {+ if (P->auto_jump || g_in.jump.check) P->speed.y = fminf(P->speed.y, P->var_jump_speed);+ else P->var_jump_timer = 0;+ }+ if (btn_pressed(&g_in.jump)) {+ if (P->jump_grace_timer > 0) jump();+ else if (can_unduck()) {+ if (wall_jump_check(1)) {+ if (P->facing == 1 && g_in.grab.check && P->stamina > 0 && !P->holding && !climb_blocker(E->x + WallJumpCheckDist, E->y))+ climb_jump();+ else if (player_dash_attacking(P) && P->dash_dir.x == 0 && P->dash_dir.y == -1)+ super_wall_jump(-1);+ else+ wall_jump(-1);+ } else if (wall_jump_check(-1)) {+ if (P->facing == -1 && g_in.grab.check && P->stamina > 0 && !P->holding && !climb_blocker(E->x - WallJumpCheckDist, E->y))+ climb_jump();+ else if (player_dash_attacking(P) && P->dash_dir.x == 0 && P->dash_dir.y == -1)+ super_wall_jump(1);+ else+ wall_jump(1);+ } else if (water_at(0, 2))+ jump();+ }+ }+ return ST_NORMAL;+}++/* ---------------------------------------------------------------- climb */+static void climb_begin(void) {+ P->auto_jump = false;+ P->speed.x = 0;+ P->speed.y *= ClimbGrabYMult;+ P->wall_slide_timer = WallSlideTime;+ P->climb_no_move_timer = ClimbNoMoveTime;+ P->wall_boost_timer = 0;+ P->last_climb_move = 0;+ for (int i = 0; i < ClimbCheckDist; i++)+ if (!solid_at((float)P->facing, 0)) E->x += P->facing;+ else break;+}+static void climb_end(void) {+ P->wall_speed_retention_timer = 0;+ if (!spr_is(&P->sweat, A_player_sweat_jump)) spr_play(&P->sweat, A_player_sweat_idle, false);+}++static void climb_hop(void) {+ P->climb_hop_solid = collide_first_solid(E, E->x + P->facing, E->y);+ P->play_footstep_on_land = 0.5f;+ if (P->climb_hop_solid) {+ P->climb_hop_solid_pos = v2(P->climb_hop_solid->x, P->climb_hop_solid->y);+ P->hop_wait_x = P->facing;+ P->hop_wait_x_speed = P->facing * ClimbHopX;+ } else {+ P->hop_wait_x = 0;+ P->speed.x = P->facing * ClimbHopX;+ }+ P->speed.y = fminf(P->speed.y, ClimbHopY);+ P->force_move_x = 0;+ P->force_move_x_timer = ClimbHopForceTime;+ P->fast_jump = false;+ P->no_wind_timer = ClimbHopNoWindTime;+}++static bool slip_check(float add_y) {+ float ax, ay;+ if (P->facing == 1) ax = e_right(E), ay = e_top(E) + 4 + add_y;+ else ax = e_left(E) - 1, ay = e_top(E) + 4 + add_y;+ return !point_solid(ax, ay) && !point_solid(ax, ay + (-4 + add_y));+}++static bool climb_hop_blocked_check(void) {+ if (solid_at(0, -6)) return true;+ return false;+}++static void sweat_danger(int anim) {+ if (P->stamina <= ClimbTiredThreshold) spr_play(&P->sweat, A_player_sweat_danger, false);+ else spr_play(&P->sweat, anim, false);+}++/* WallBoosterCheck: a wall booster on the side Madeline faces, unless a climb blocker is there */+static Ent *wall_booster_check(void) {+ if (climb_blocker(E->x + P->facing, E->y)) return NULL;+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (!o->cls || o->dead == 1 || !o->collidable || !o->cls->name || strcmp(o->cls->name, "wallBooster")) continue;+ int facing = o->cx == 0 ? -1 : 1; /* (core's walls: Hitbox(2, h) on the left, (2, h, 6, 0) on the right) */+ if (facing == P->facing && collide_ent_at(E, E->x, E->y, o)) return o;+ }+ return NULL;+}++static int climb_update(void) {+ P->climb_no_move_timer -= DT;+ if (P->on_ground) P->stamina = ClimbMaxStamina;+ if (btn_pressed(&g_in.jump) && (!Ducking || can_unduck())) {+ if (P->move_x == -P->facing) wall_jump(-P->facing);+ else climb_jump();+ return ST_NORMAL;+ }+ if (can_dash()) {+ P->speed = v2add(P->speed, lift_boost());+ return start_dash();+ }+ if (!g_in.grab.check) {+ P->speed = v2add(P->speed, lift_boost());+ return ST_NORMAL;+ }+ if (!solid_at((float)P->facing, 0)) {+ if (P->speed.y < 0) climb_hop();+ return ST_NORMAL;+ }+ Ent *booster = wall_booster_check();+ if (P->climb_no_move_timer <= 0 && booster) {+ P->speed.y = approach(P->speed.y, WallBoosterSpeed, WallBoosterAccel * DT);+ actor_set_lift(E, v2(0, fmaxf(P->speed.y, WallBoosterLiftSpeed)));+ } else {+ float target = 0;+ bool try_slip = false;+ if (P->climb_no_move_timer <= 0) {+ if (climb_blocker(E->x + P->facing, E->y)) try_slip = true;+ else if (g_in.move_y == -1) {+ target = ClimbUpSpeed;+ if (solid_at(0, -1) || (climb_hop_blocked_check() && slip_check(-1))) {+ if (P->speed.y < 0) P->speed.y = 0;+ target = 0;+ try_slip = true;+ } else if (slip_check(0)) {+ climb_hop();+ return ST_NORMAL;+ }+ } else if (g_in.move_y == 1) {+ target = ClimbDownSpeed;+ if (P->on_ground) {+ if (P->speed.y > 0) P->speed.y = 0;+ target = 0;+ } else+ wall_slide_particles(P->facing);+ } else+ try_slip = true;+ } else+ try_slip = true;+ P->last_climb_move = (int)signf(target);+ if (try_slip && slip_check(0)) target = ClimbSlipSpeed;+ P->speed.y = approach(P->speed.y, target, ClimbAccel * DT);+ }+ if (g_in.move_y != 1 && P->speed.y > 0 && !solid_at((float)P->facing, 1)) P->speed.y = 0;+ if (P->climb_no_move_timer <= 0) {+ if (P->last_climb_move == -1) {+ P->stamina -= ClimbUpCost * DT;+ if (P->stamina <= ClimbTiredThreshold) spr_play(&P->sweat, A_player_sweat_danger, false);+ else if (!spr_is(&P->sweat, A_player_sweat_climbLoop)) spr_play(&P->sweat, A_player_sweat_climb, false);+ } else {+ if (P->last_climb_move == 0) P->stamina -= ClimbStillCost * DT;+ if (!P->on_ground) sweat_danger(A_player_sweat_still);+ else sweat_danger(A_player_sweat_idle);+ }+ } else+ sweat_danger(A_player_sweat_idle);+ if (P->stamina <= 0) {+ P->speed = v2add(P->speed, lift_boost());+ return ST_NORMAL;+ }+ return ST_CLIMB;+}++/* ---------------------------------------------------------------- dash */+static void create_trail(void) {+ uint16_t t = spr_tex(&P->spr);+ if (t == 0xFFFF) return;+ trail_add(floorf(E->x), floorf(E->y), t, P->spr.ox, P->spr.oy, P->spr.sx * P->facing, P->spr.sy,+ P->was_dash_b ? NormalHairColor : UsedHairColor, 0.5f);+}++static void dash_begin(void) {+ P->called_dash_events = false;+ P->dash_started_on_ground = P->on_ground;+ P->launched = false;+ level_freeze(.05f);+ P->dash_cooldown_timer = DashCooldown;+ P->dash_refill_cooldown_timer = DashRefillCooldown;+ P->started_dashing = true;+ P->wall_slide_timer = WallSlideTime;+ P->dash_trail_timer = 0;+ P->dash_attack_timer = DashAttackTime;+ P->before_dash_speed = P->speed;+ P->speed = v2(0, 0);+ P->dash_dir = v2(0, 0);+ if (!P->on_ground && Ducking && can_unduck()) set_ducking(false);+}+static void call_dash_events(void) {+ if (!P->called_dash_events) {+ P->called_dash_events = true;+ if (!P->current_booster) {+ g_save.total_dashes++;+ g_session.dashes++;+ level_dash_listeners(P->dash_dir);+ } else {+ level_booster_boosted(P->current_booster, P->dash_dir);+ P->current_booster = NULL;+ }+ }+}+static void dash_end(void) { call_dash_events(); }++static int dash_update(void) {+ P->started_dashing = false;+ if (P->dash_trail_timer > 0) {+ P->dash_trail_timer -= DT;+ if (P->dash_trail_timer <= 0) create_trail();+ }+ if (!P->holding && g_in.grab.check && !is_tired() && can_unduck()) {+ Ent *h = holdable_check();+ if (h) {+ set_ducking(false);+ P->holding = h;+ P->min_hold_timer = HoldMinTime;+ return ST_PICKUP;+ }+ }+ if (P->dash_dir.y == 0) {+ for (int i = 0; i < g_nents; i++) {+ Ent *jt = &g_ents[i];+ if ((jt->kind & KIND_JUMPTHRU) && jt->cls && jt->collidable && jt->dead != 1 && collide_ent_at(E, E->x, E->y, jt) &&+ e_bottom(E) - e_top(jt) <= DashHJumpThruNudge)+ actor_move_v_exact(E, (int)(e_top(jt) - e_bottom(E)), NULL, NULL);+ }+ if (can_unduck() && btn_pressed(&g_in.jump) && P->jump_grace_timer > 0) {+ super_jump();+ return ST_NORMAL;+ }+ }+ if (P->dash_dir.x == 0 && P->dash_dir.y == -1) {+ if (btn_pressed(&g_in.jump) && can_unduck()) {+ if (wall_jump_check(1)) { super_wall_jump(-1); return ST_NORMAL; }+ if (wall_jump_check(-1)) { super_wall_jump(1); return ST_NORMAL; }+ }+ } else if (btn_pressed(&g_in.jump) && can_unduck()) {+ if (wall_jump_check(1)) { wall_jump(-1); return ST_NORMAL; }+ if (wall_jump_check(-1)) { wall_jump(1); return ST_NORMAL; }+ }+ if ((P->speed.x != 0 || P->speed.y != 0) && level_on_interval(0.02f))+ particles_emit(PL_FG, P->was_dash_b ? &P_Player_P_DashB : &P_Player_P_DashA, 1, center(), v2(2, 2), angle_of(P->dash_dir));+ return ST_DASH;+}++static float co_dash(void) {+ switch (P->co_step) {+ case 0:+ P->co_step = 1;+ return 0; /* yield null */+ case 1: {+ V2 dir = P->last_aim;+ V2 ns = v2mul(dir, DashSpeed);+ if (signf(P->before_dash_speed.x) == signf(ns.x) && fabsf(P->before_dash_speed.x) > fabsf(ns.x)) ns.x = P->before_dash_speed.x;+ P->speed = ns;+ if (water_at(0, 0)) P->speed = v2mul(P->speed, SwimDashSpeedMult);+ P->dash_dir = dir;+ level_dir_shake(dir, .2f);+ if (dir.x != 0) P->facing = (int)signf(dir.x);+ call_dash_events();+ if (P->on_ground && P->dash_dir.x != 0 && P->dash_dir.y > 0 && P->speed.y > 0 &&+ (!P->inventory_dreamdash || !collide_first_kind(E, E->x, E->y + 1, KIND_DREAMBLOCK))) {+ P->dash_dir.x = signf(P->dash_dir.x);+ P->dash_dir.y = 0;+ P->speed.y = 0;+ P->speed.x *= DodgeSlideSpeedMult;+ set_ducking(true);+ }+ create_trail();+ P->dash_trail_timer = .08f;+ P->swap_cancel = v2(1, 1);+ P->co_step = 2;+ return DashTime;+ }+ case 2:+ create_trail();+ P->auto_jump = true;+ P->auto_jump_timer = 0;+ if (P->dash_dir.y <= 0) {+ P->speed = v2mul(P->dash_dir, EndDashSpeed);+ P->speed.x *= P->swap_cancel.x;+ P->speed.y *= P->swap_cancel.y;+ }+ if (P->speed.y < 0) P->speed.y *= EndDashUpMult;+ SET(ST_NORMAL);+ return -1;+ }+ return -1;+}++/* ---------------------------------------------------------------- swim */+static void swim_begin(void) {+ if (P->speed.y > 0) P->speed.y *= SwimYSpeedMult;+ P->stamina = ClimbMaxStamina;+}+static int swim_update(void) {+ if (!swim_check()) return ST_NORMAL;+ if (can_unduck()) set_ducking(false);+ if (can_dash()) {+ btn_consume_buffer(&g_in.dash);+ return ST_DASH;+ }+ bool under = swim_underwater_check();+ if (!under && P->speed.y >= 0 && g_in.grab.check && !is_tired() && can_unduck()) {+ if (signf(P->speed.x) != -P->facing && climb_check(P->facing, 0))+ if (!actor_move_v_exact(E, -1, NULL, NULL)) {+ set_ducking(false);+ return ST_CLIMB;+ }+ }+ V2 move = v2((float)g_in.aim_x, (float)g_in.aim_y);+ move = v2norm(move);+ float maxx = under ? SwimUnderwaterMax : SwimMax, maxy = SwimMax;+ if (fabsf(P->speed.x) > SwimMax && signf(P->speed.x) == signf(move.x))+ P->speed.x = approach(P->speed.x, maxx * move.x, SwimReduce * DT);+ else+ P->speed.x = approach(P->speed.x, maxx * move.x, SwimAccel * DT);+ if (move.y == 0 && swim_rise_check())+ P->speed.y = approach(P->speed.y, SwimMaxRise, SwimAccel * DT);+ else if (move.y >= 0 || swim_underwater_check()) {+ if (fabsf(P->speed.y) > SwimMax && signf(P->speed.y) == signf(move.y))+ P->speed.y = approach(P->speed.y, maxy * move.y, SwimReduce * DT);+ else+ P->speed.y = approach(P->speed.y, maxy * move.y, SwimAccel * DT);+ }+ if (!under && P->move_x != 0 && solid_at((float)P->move_x, 0) && !solid_at((float)P->move_x, -3)) climb_hop();+ if (btn_pressed(&g_in.jump) && swim_jump_check()) {+ jump();+ return ST_NORMAL;+ }+ return ST_SWIM;+}++/* ---------------------------------------------------------------- boost (bubbles) */+void player_boost(Player *p, Ent *booster, bool red) {+ player_set_state(p, ST_BOOST);+ p->speed = v2(0, 0);+ p->boost_target = e_center(booster);+ p->boost_red = red;+ p->last_booster = p->current_booster = booster;+}+static void boost_begin(void) {+ player_refill_dash(P);+ player_refill_stamina(P);+}+static void boost_end(void) {+ V2 to = v2(floorf(P->boost_target.x - (E->cx + E->cw / 2)), floorf(P->boost_target.y - (E->cy + E->ch / 2)));+ actor_move_to_x(E, to.x, NULL);+ actor_move_to_y(E, to.y, NULL);+}+static int boost_update(void) {+ V2 add = v2(g_in.aim_x * 3.f, g_in.aim_y * 3.f);+ V2 target = v2add(v2sub(P->boost_target, v2(E->cx + E->cw / 2, E->cy + E->ch / 2)), add);+ V2 ex = v2(E->x + E->remx, E->y + E->remy);+ V2 d = v2sub(target, ex);+ float l = v2len(d), m = BoostMoveSpeed * DT;+ V2 to = l <= m ? target : v2add(ex, v2mul(d, m / l));+ actor_move_to_x(E, to.x, NULL);+ actor_move_to_y(E, to.y, NULL);+ if (btn_pressed(&g_in.dash)) {+ btn_consume(&g_in.dash);+ return P->boost_red ? ST_REDDASH : ST_DASH;+ }+ return ST_BOOST;+}+static float co_boost(void) {+ if (P->co_step == 0) {+ P->co_step = 1;+ return BoostTime;+ }+ SET(P->boost_red ? ST_REDDASH : ST_DASH);+ return -1;+}++/* ---------------------------------------------------------------- red dash */+static void red_dash_begin(void) {+ P->called_dash_events = false;+ P->dash_started_on_ground = false;+ level_freeze(.05f);+ dust_burst(v2(E->x, E->y), angle_of(v2(-P->dash_dir.x, -P->dash_dir.y)), 8);+ P->dash_cooldown_timer = DashCooldown;+ P->dash_refill_cooldown_timer = DashRefillCooldown;+ P->started_dashing = true;+ P->dash_attack_timer = DashAttackTime;+ P->speed = v2(0, 0);+ if (!P->on_ground && Ducking && can_unduck()) set_ducking(false);+}+static void red_dash_end(void) { call_dash_events(); }+static int red_dash_update(void) {+ P->started_dashing = false;+ if (can_dash()) return start_dash();+ if (P->dash_dir.y == 0) {+ for (int i = 0; i < g_nents; i++) {+ Ent *jt = &g_ents[i];+ if ((jt->kind & KIND_JUMPTHRU) && jt->cls && jt->collidable && jt->dead != 1 && collide_ent_at(E, E->x, E->y, jt) &&+ e_bottom(E) - e_top(jt) <= DashHJumpThruNudge)+ actor_move_v_exact(E, (int)(e_top(jt) - e_bottom(E)), NULL, NULL);+ }+ if (can_unduck() && btn_pressed(&g_in.jump) && P->jump_grace_timer > 0) {+ super_jump();+ return ST_NORMAL;+ }+ } else if (P->dash_dir.x == 0 && P->dash_dir.y == -1) {+ if (btn_pressed(&g_in.jump) && can_unduck()) {+ if (wall_jump_check(1)) { super_wall_jump(-1); return ST_NORMAL; }+ if (wall_jump_check(-1)) { super_wall_jump(1); return ST_NORMAL; }+ }+ } else if (btn_pressed(&g_in.jump) && can_unduck()) {+ if (wall_jump_check(1)) { wall_jump(-1); return ST_NORMAL; }+ if (wall_jump_check(-1)) { wall_jump(1); return ST_NORMAL; }+ }+ return ST_REDDASH;+}+static float co_red_dash(void) {+ if (P->co_step == 0) {+ P->co_step = 1;+ return 0;+ }+ P->speed = v2mul(P->last_aim, DashSpeed);+ P->dash_dir = P->last_aim;+ level_dir_shake(P->dash_dir, .2f);+ call_dash_events();+ return -1;+}++/* ---------------------------------------------------------------- hit squash, launch */+static void hit_squash_begin(void) { P->hit_squash_no_move_timer = HitSquashNoMoveTime; }+static int hit_squash_update(void) {+ P->speed.x = approach(P->speed.x, 0, HitSquashFriction * DT);+ P->speed.y = approach(P->speed.y, 0, HitSquashFriction * DT);+ if (btn_pressed(&g_in.jump)) {+ if (P->on_ground) jump();+ else if (wall_jump_check(1)) wall_jump(-1);+ else if (wall_jump_check(-1)) wall_jump(1);+ else btn_consume_buffer(&g_in.jump);+ return ST_NORMAL;+ }+ if (can_dash()) return start_dash();+ if (g_in.grab.check && climb_check(P->facing, 0)) return ST_CLIMB;+ if (P->hit_squash_no_move_timer > 0) P->hit_squash_no_move_timer -= DT;+ else return ST_NORMAL;+ return ST_HITSQUASH;+}++V2 player_explode_launch(Player *p, V2 from, bool snap_up) {+ level_freeze(.1f);+ p->has_launch_approach = false;+ V2 d = v2sub(player_center(p), from);+ float l = v2len(d);+ V2 n = l > 0 ? v2mul(d, 1 / l) : v2(0, -1);+ float dot = n.y;+ if (snap_up && dot <= -.7f) n = v2(0, -1);+ else if (dot <= .55f && dot >= -.55f) n = v2(signf(n.x), 0);+ p->speed = v2mul(n, LaunchSpeed);+ if (p->speed.y <= 50) {+ p->speed.y = fminf(-150, p->speed.y);+ p->auto_jump = true;+ }+ if (g_in.move_x == signf(p->speed.x)) p->speed.x *= 1.2f;+ if (!p->inventory_norefills) player_refill_dash(p);+ player_refill_stamina(p);+ p->dash_cooldown_timer = DashCooldown;+ player_set_state(p, ST_LAUNCH);+ return n;+}+static void launch_begin(void) { P->launched = true; }+static int launch_update(void) {+ if (P->has_launch_approach) actor_move_towards_x(E, P->launch_approach_x, 60 * DT, NULL);+ if (can_dash()) return start_dash();+ if (P->speed.y < 0) P->speed.y = approach(P->speed.y, MaxFall, Gravity * .5f * DT);+ else P->speed.y = approach(P->speed.y, MaxFall, Gravity * .25f * DT);+ P->speed.x = approach(P->speed.x, 0, RunAccel * .2f * DT);+ if (v2len(P->speed) < LaunchCancelThreshold) return ST_NORMAL;+ return ST_LAUNCH;+}++/* ---------------------------------------------------------------- summit launch */+static void summit_launch_begin(void) {+ P->wall_boost_timer = 0;+ play(A_player_launch);+ P->speed = v2(0, -DashSpeed);+ P->summit_particle_timer = .4f;+}+static int summit_launch_update(void) {+ P->summit_particle_timer -= DT;+ P->facing = 1;+ actor_move_towards_x(E, P->summit_target_x, 20 * DT, NULL);+ P->speed = v2(0, -DashSpeed);+ return ST_SUMMITLAUNCH;+}++/* ---------------------------------------------------------------- pickup (Theo's crystal) */+static Ent *holdable_check(void) { return level_holdable_check(); }+static float co_pickup(void) {+ switch (P->co_step) {+ case 0:+ P->before_dash_speed = P->speed; /* oldSpeed */+ P->co_t = P->var_jump_timer;+ P->speed = v2(0, 0);+ P->co_step = 1;+ return 0.16f;+ default:+ P->carry_offset = v2(0, -12);+ P->speed = P->before_dash_speed;+ P->speed.y = fminf(P->speed.y, 0);+ P->var_jump_timer = P->co_t;+ SET(ST_NORMAL);+ return -1;+ }+}++/* ---------------------------------------------------------------- dream dash */+static void dream_dash_begin(void) {+ P->speed = v2mul(P->dash_dir, DreamDashSpeed);+ E->treat_naive = 1;+ E->depth = D_PLAYERDREAMDASHING;+ ents_mark_unsorted();+ P->dream_dash_can_end_timer = DreamDashMinTime;+ P->stamina = ClimbMaxStamina;+ P->dream_jump = false;+}+static void dream_dash_end(void) {+ E->depth = D_PLAYER;+ ents_mark_unsorted();+ if (!P->dream_jump) {+ P->auto_jump = true;+ P->auto_jump_timer = 0;+ }+ if (!P->inventory_norefills) player_refill_dash(P);+ player_refill_stamina(P);+ E->treat_naive = 0;+ if (P->dream_block) {+ if (P->dash_dir.x != 0) {+ P->jump_grace_timer = JumpGraceTime;+ P->dream_jump = true;+ } else+ P->jump_grace_timer = 0;+ P->dream_block = NULL;+ }+}+static bool dream_dashed_into_solid(void) {+ if (solid_at(0, 0)) {+ for (int x = 1; x <= DreamDashEndWiggle; x++)+ for (int xm = -1; xm <= 1; xm += 2)+ for (int y = 1; y <= DreamDashEndWiggle; y++)+ for (int ym = -1; ym <= 1; ym += 2)+ if (!solid_at((float)(x * xm), (float)(y * ym))) {+ E->x += x * xm, E->y += y * ym;+ return false;+ }+ return true;+ }+ return false;+}+static int dream_dash_update(void) {+ actor_naive_move(E, v2mul(P->speed, DT));+ if (P->dream_dash_can_end_timer > 0) P->dream_dash_can_end_timer -= DT;+ Ent *block = collide_first_kind(E, E->x, E->y, KIND_DREAMBLOCK);+ if (!block) {+ if (dream_dashed_into_solid()) player_die(P, v2(0, 0), false);+ else if (P->dream_dash_can_end_timer <= 0) {+ level_freeze(.05f);+ if (btn_pressed(&g_in.jump) && P->dash_dir.x != 0) {+ P->dream_jump = true;+ jump();+ } else {+ bool l = climb_check(-1, 0), r = climb_check(1, 0);+ if (g_in.grab.check && (P->dash_dir.y >= 0 || P->dash_dir.x != 0) && ((P->move_x == 1 && r) || (P->move_x == -1 && l))) {+ P->facing = P->move_x;+ return ST_CLIMB;+ }+ }+ return ST_NORMAL;+ }+ } else {+ P->dream_block = block;+ if (level_on_interval(0.1f)) create_trail();+ }+ return ST_DREAMDASH;+}++/* ---------------------------------------------------------------- star fly (feathers) */+bool player_start_star_fly(Player *p) {+ player_refill_stamina(p);+ if (p->state == ST_REFLECTIONFALL) return false;+ if (p->state == ST_STARFLY) {+ p->star_fly_timer = StarFlyTime;+ p->spr.tint = rgb(StarFlyColor);+ } else+ player_set_state(p, ST_STARFLY);+ return true;+}+static void star_fly_begin(void) {+ play(A_player_startStarFly);+ P->star_fly_transforming = true;+ P->star_fly_timer = StarFlyTime;+ P->star_fly_speed_lerp = 0;+ P->jump_grace_timer = 0;+ set_box(HB_STARFLY);+ hurtbox = HB_STARFLY_HURT;+}+static void star_fly_return_to_normal_hitbox(void) {+ set_box(HB_NORMAL);+ hurtbox = HB_NORMAL_HURT;+ if (solid_at(0, 0)) {+ float sy = E->y;+ E->y -= (HB_NORMAL[1] + HB_NORMAL[3]) - (HB_STARFLY[1] + HB_STARFLY[3]);+ if (solid_at(0, 0)) E->y = sy;+ else return;+ set_ducking(true);+ E->y -= (HB_DUCK[1] + HB_DUCK[3]) - (HB_STARFLY[1] + HB_STARFLY[3]);+ if (solid_at(0, 0)) E->y = sy;+ }+}+static void star_fly_end(void) {+ P->hair_outline = false;+ P->spr.tint = 0xFFFF;+ P->hair_count = P->start_hair_count;+ star_fly_return_to_normal_hitbox();+}+static float co_star_fly(void) {+ switch (P->co_step) {+ case 0:+ if (P->spr.anim == A_player_startStarFly) return 0;+ P->co_step = 1;+ /* fall through */+ case 1:+ if (P->speed.x != 0 || P->speed.y != 0) return 0;+ P->co_step = 2;+ return .1f;+ case 2: {+ P->spr.tint = rgb(StarFlyColor);+ P->hair_count = 7;+ P->hair_outline = true;+ P->star_fly_transforming = false;+ P->star_fly_timer = StarFlyTime;+ player_refill_dash(P);+ player_refill_stamina(P);+ V2 dir = v2((float)g_in.aim_x, (float)g_in.aim_y);+ if (dir.x == 0 && dir.y == 0) dir = v2((float)P->facing, 0);+ dir = v2norm(dir);+ P->speed = v2mul(dir, StarFlyStartSpeed);+ P->star_fly_last_dir = dir;+ level_dir_shake(dir, .3f);+ P->co_step = 3;+ return 0;+ }+ }+ return -1;+}+static V2 rotate_towards(V2 v, float target, float max) {+ float a = angle_of(v), d = target - a;+ while (d > PI_F) d -= 2 * PI_F;+ while (d < -PI_F) d += 2 * PI_F;+ if (fabsf(d) > max) d = max * signf(d);+ float l = v2len(v);+ return angle_vec(a + d, l);+}+static int star_fly_update(void) {+ if (P->star_fly_transforming) {+ float l = v2len(P->speed), nl = approach(l, 0, StarFlyTransformDeccel * DT);+ P->speed = l > 0 ? v2mul(P->speed, nl / l) : P->speed;+ } else {+ V2 aim = v2((float)g_in.aim_x, (float)g_in.aim_y);+ bool slow = false;+ if (aim.x == 0 && aim.y == 0) {+ slow = true;+ aim = P->star_fly_last_dir;+ }+ aim = v2norm(aim);+ V2 cur = v2norm(P->speed);+ if (cur.x == 0 && cur.y == 0) cur = aim;+ else cur = rotate_towards(cur, angle_of(aim), StarFlyRotateSpeed * DT);+ P->star_fly_last_dir = cur;+ float max;+ if (slow) {+ P->star_fly_speed_lerp = 0;+ max = StarFlySlowSpeed;+ } else if ((cur.x != 0 || cur.y != 0) && cur.x * aim.x + cur.y * aim.y >= .45f) {+ P->star_fly_speed_lerp = approach(P->star_fly_speed_lerp, 1, DT / StarFlyMaxLerpTime);+ max = lerpf(StarFlyTargetSpeed, StarFlyMaxSpeed, P->star_fly_speed_lerp);+ } else {+ P->star_fly_speed_lerp = 0;+ max = StarFlyTargetSpeed;+ }+ float s = approach(v2len(P->speed), max, StarFlyAccel * DT);+ P->speed = v2mul(cur, s);+ if (btn_pressed(&g_in.jump)) {+ if (actor_on_ground(E, 3)) { jump(); return ST_NORMAL; }+ if (wall_jump_check(-1)) { wall_jump(1); return ST_NORMAL; }+ if (wall_jump_check(1)) { wall_jump(-1); return ST_NORMAL; }+ }+ if (g_in.grab.check) {+ if (g_in.move_x != -1 && climb_check(1, 0)) { P->facing = 1; return ST_CLIMB; }+ if (g_in.move_x != 1 && climb_check(-1, 0)) { P->facing = -1; return ST_CLIMB; }+ }+ if (can_dash()) return start_dash();+ P->star_fly_timer -= DT;+ if (P->star_fly_timer <= 0) {+ if (g_in.move_y == -1) P->speed.y = StarFlyExitUp;+ if (g_in.move_y < 1) {+ P->var_jump_speed = P->speed.y;+ P->auto_jump = true;+ P->auto_jump_timer = 0;+ P->var_jump_timer = VarJumpTime;+ }+ if (P->speed.y > StarFlyMaxExitY) P->speed.y = StarFlyMaxExitY;+ if (fabsf(P->speed.x) > StarFlyMaxExitX) P->speed.x = StarFlyMaxExitX * signf(P->speed.x);+ return ST_NORMAL;+ }+ if (P->star_fly_timer < StarFlyEndFlashDuration && level_on_interval(0.05f))+ P->spr.tint = P->spr.tint == rgb(StarFlyColor) ? rgb(NormalHairColor) : rgb(StarFlyColor);+ }+ return ST_STARFLY;+}++/* ---------------------------------------------------------------- attract, dummy, frozen, intros */+void player_start_attract(Player *p, V2 to) {+ p->attract_to = v2(roundf(to.x), roundf(to.y));+ player_set_state(p, ST_ATTRACT);+}+static void attract_begin(void) { P->speed = v2(0, 0); }+static int attract_update(void) {+ V2 ex = v2(E->x + E->remx, E->y + E->remy);+ V2 d = v2sub(P->attract_to, ex);+ if (v2len(d) <= 1.5f) {+ E->x = P->attract_to.x, E->y = P->attract_to.y;+ E->remx = E->remy = 0;+ } else {+ float l = v2len(d), m = 200 * DT;+ V2 at = l <= m ? P->attract_to : v2add(ex, v2mul(d, m / l));+ actor_move_to_x(E, at.x, NULL);+ actor_move_to_y(E, at.y, NULL);+ }+ return ST_ATTRACT;+}+static void dummy_begin(void) {+ P->dummy_moving = false;+ P->dummy_gravity = true;+ P->dummy_auto_animate = true;+}+static int dummy_update(void) {+ if (can_unduck()) set_ducking(false);+ if (!P->on_ground && P->dummy_gravity) {+ float mult = (fabsf(P->speed.y) < HalfGravThreshold && (g_in.jump.check || P->auto_jump)) ? .5f : 1.f;+ if (g_level.in_space) mult *= SpacePhysicsMult;+ P->speed.y = approach(P->speed.y, MaxFall, Gravity * mult * DT);+ }+ if (P->var_jump_timer > 0) {+ if (P->auto_jump || g_in.jump.check) P->speed.y = fminf(P->speed.y, P->var_jump_speed);+ else P->var_jump_timer = 0;+ }+ if (!P->dummy_moving) {+ if (fabsf(P->speed.x) > MaxRun && P->dummy_maxspeed) P->speed.x = approach(P->speed.x, MaxRun * signf(P->speed.x), RunAccel * 2.5f * DT);+ if (P->dummy_friction) P->speed.x = approach(P->speed.x, 0, RunAccel * DT);+ }+ if (P->dummy_auto_animate) {+ if (P->on_ground) play(P->speed.x == 0 ? A_player_idle : A_player_walk);+ else play(P->speed.y < 0 ? A_player_jumpSlow : A_player_fallSlow);+ }+ return ST_DUMMY;+}+static int frozen_update(void) { return ST_FROZEN; }+static int cassette_update(void) { return ST_CASSETTEFLY; }+/* StartCassetteFly: back to the start in a bubble, along a curve */+void player_start_cassette_fly(Player *p, V2 target, V2 control) {+ CassetteFly *f = cassette_fly();+ player_set_state(p, ST_CASSETTEFLY);+ f->a = v2(p->ent->x, p->ent->y), f->b = target, f->c = control;+ f->lerp = 0;+ p->speed = v2(0, 0);+ if (p->holding) holdable_release(p->holding, v2(0, 0)), p->holding = NULL; /* Drop */+}+static void cassette_fly_begin(void) {+ play(A_player_bubble);+ P->spr_dy += 5;+}+static float co_cassette_fly(void) {+ CassetteFly *f = cassette_fly();+ switch (P->co_step) {+ case 0:+ g_level.no_retry = true;+ g_level.formation = true;+ g_level.formation_alpha = 0.5f;+ P->spr.sx = P->spr.sy = 1.25f;+ E->depth = -2000000;+ P->co_step = 1;+ return 0.4f;+ case 1:+ if (f->lerp < 1) {+ if (level_on_interval(0.03f)) particles_emit(PL_MID, &P_Player_P_CassetteFly, 2, center(), v2(4, 4), 0);+ f->lerp = approach(f->lerp, 1, 1.6f * DT);+ float t = ease_sine_inout(f->lerp), u = 1 - t;+ E->x = u * u * f->a.x + 2 * u * t * f->c.x + t * t * f->b.x;+ E->y = u * u * f->a.y + 2 * u * t * f->c.y + t * t * f->b.y;+ g_level.cam = player_camera_target(P);+ return 0;+ }+ E->x = f->b.x, E->y = f->b.y;+ P->spr.sx = P->spr.sy = 1.25f;+ P->spr_dy -= 5;+ play(A_player_fallFast);+ P->co_step = 2;+ return 0.2f;+ case 2:+ g_level.no_retry = false;+ g_level.formation = false;+ g_level.formation_alpha = 0.5f;+ SET(ST_NORMAL);+ E->depth = 0;+ return -1;+ }+ return -1;+}+static int bird_update(void) { return ST_BIRDDASHTUTORIAL; }+/* IntroTypes.Fall (Reflection, after the dream): FallEffects is not drawn */+static void reflection_fall_begin(void) { E->ignore_jumpthrus = 1; }+static void reflection_fall_end(void) { E->ignore_jumpthrus = 0; }+static int reflection_fall_update(void) {+ P->facing = 1;+ if (level_on_interval(0.05f)) {+ P->was_dash_b = true;+ create_trail();+ }+ if (water_at(0, 0)) P->speed.y = approach(P->speed.y, -20, 400 * DT);+ else P->speed.y = approach(P->speed.y, MaxFall * 2, Gravity * 0.25f * DT);+ for (int i = 0; i < g_nents; i++) { /* the feathers go */+ Ent *o = &g_ents[i];+ if (o->cls && o->cls->name && (!strcmp(o->cls->name, "infiniteStar") || !strcmp(o->cls->name, "flyFeather"))) ent_remove(o);+ }+ if (spinners_hit_rect(E->x - 6, E->y - 6, E->x + 6, E->y + 6)) { /* a crystal in the way breaks */+ spinners_destroy_near(E->x, E->y, 12);+ level_shake(0.3f);+ level_freeze(0.01f);+ }+ return ST_REFLECTIONFALL;+}+/* Level.StartCutscene(OnReflectionFallSkip): skipped, the level goes on in room 00 */+typedef struct { Cutscene cs; } FallScene;+static const EntClass FALLSCENE = {.name = "reflectionFall", .size = sizeof(FallScene)};+static Ent *fall_scene;+static void fall_scene_end(Ent *e, bool skipped) {+ (void)e;+ fall_scene = NULL;+ int r = skipped ? chapter_find_room(g_level.chapter, "00") : -1;+ if (r >= 0) level_load_room_near(r, INTRO_NONE, 0, 1);+}+static float co_reflection_fall(void) {+ switch (P->co_step) {+ case 0:+ play(A_player_bigFall);+ fall_scene = ent_new(&FALLSCENE, 0, 0);+ if (fall_scene) fall_scene->visible = 0, fall_scene->collidable = 0, cutscene_start(fall_scene, fall_scene_end, true, false);+ P->co_t = 0;+ P->co_step = 1;+ /* fall through */+ case 1: /* held up for 2 s */+ P->speed.y = 0;+ if ((P->co_t += DT) < 2) return 0;+ P->speed.y = 320;+ P->co_step = 2;+ return 0;+ case 2:+ if (!water_at(0, 0)) return 0;+ play(A_player_bigFallRecover);+ if (fall_scene && fall_scene->cls == &FALLSCENE) cutscene_end(fall_scene);+ P->co_step = 3;+ return 1.2f;+ default:+ SET(ST_NORMAL);+ return -1;+ }+}+static int temple_fall_update(void) {+ P->facing = 1;+ if (!P->on_ground) {+ float c = g_level.room->x + 160.f;+ int mx = fabsf(c - E->x) > 4 ? (int)signf(c - E->x) : 0;+ P->speed.x = approach(P->speed.x, MaxRun * .6f * mx, RunAccel * .5f * AirMult * DT);+ }+ if (!P->on_ground && P->dummy_gravity) P->speed.y = approach(P->speed.y, MaxFall * 2, Gravity * 0.25f * DT);+ return ST_TEMPLEFALL;+}+static float co_temple_fall(void) {+ switch (P->co_step) {+ case 0:+ play(A_player_fallFast);+ P->co_step = 1;+ /* fall through */+ case 1:+ if (!P->on_ground) return 0;+ play(P->dashes <= 1 ? A_player_fallPose : A_player_idle);+ P->spr.sy = 0.7f;+ level_dir_shake(v2(0, 1), 0.5f);+ P->speed.x = 0;+ P->co_t = 0;+ P->co_step = 2;+ return 0;+ case 2:+ P->co_t += DT;+ if (P->co_t < 1) return 0;+ SET(ST_NORMAL);+ return -1;+ }+ return -1;+}+/* BirdDashTutorialCoroutine: the prologue's first dash, up and right, onto the cliff */+static float co_bird(void) {+ Player *p = P;+ switch (p->co_step) {+ case 0:+ p->co_step = 1;+ return 0;+ case 1: {+ create_trail();+ p->bird_trails = 2; /* the alarms at 0.08 and 0.15 */+ p->bird_trail_t = 0;+ p->co_t = 0;+ V2 d = v2norm(v2(1, -1));+ p->facing = 1;+ p->speed = v2mul(d, 240);+ p->dash_dir = d;+ level_dir_shake(d, 0.2f);+ p->co_step = 2;+ }+ /* fall through */+ case 2:+ if (p->co_t < 0.15f) {+ if ((p->speed.x != 0 || p->speed.y != 0) && level_on_interval(0.02f))+ particles_emit1(PL_FG, &P_Player_P_DashA, v2add(center(), v2(rnd_rangef(-2, 2), rnd_rangef(-2, 2))), angle_of(p->dash_dir));+ p->co_t += DT;+ return 0;+ }+ p->auto_jump = true;+ p->auto_jump_timer = 0;+ if (p->dash_dir.y <= 0) p->speed = v2mul(p->dash_dir, 160);+ if (p->speed.y < 0) p->speed.y *= 0.75f;+ play(A_player_fallFast);+ p->bird_climbing = false;+ p->co_step = 3;+ /* fall through */+ case 3:+ if (!actor_on_ground(E, 1) && !p->bird_climbing) {+ p->speed.y = approach(p->speed.y, 160, 900 * DT);+ if (solid_at(1, 0)) p->bird_climbing = true;+ if (e_top(E) > g_level.room->y + g_level.room->h) {+ g_level.in_cutscene = false; /* CancelCutscene */+ g_level.skipping_cutscene = false;+ player_die(p, v2(0, 0), false);+ }+ return 0;+ }+ if (p->bird_climbing) {+ play(A_player_wallslide);+ dust_burst(v2add(v2(E->x, E->y), v2(4, -6)), PI_F, 1);+ p->speed.y = 0;+ p->co_step = 4;+ return 0.2f;+ }+ play(A_player_tired);+ p->speed.y = 0;+ p->co_step = 7;+ return 0;+ case 4:+ play(A_player_climbup);+ p->co_step = 5;+ /* fall through */+ case 5:+ if (solid_at(1, 0)) {+ E->y += -45 * DT;+ return 0;+ }+ E->y = roundf(E->y);+ play(A_player_jumpFast);+ p->speed.y = -105;+ p->co_step = 6;+ /* fall through */+ case 6:+ if (!actor_on_ground(E, 1)) {+ p->speed.y = approach(p->speed.y, 160, 900 * DT);+ p->speed.x = 20;+ return 0;+ }+ p->speed = v2(0, 0);+ play(A_player_walk);+ p->co_t = 0;+ p->co_step = 8;+ /* fall through */+ case 8:+ if (p->co_t < 0.5f) {+ E->x += 32 * DT;+ p->co_t += DT;+ return 0;+ }+ play(A_player_tired);+ return -1;+ case 7:+ if (p->speed.x != 0) {+ p->speed.x = approach(p->speed.x, 0, 240 * DT);+ if (level_on_interval(0.04f)) dust_burst(v2add(bottom_center(), v2(0, -2)), PI_F * -3 / 4, 1);+ return 0;+ }+ return -1;+ }+ return -1;+}+static void bird_begin(void) {+ dash_begin();+ play(A_player_dash);+}++static V2 intro_start;+static float co_intro_walk(void) {+ switch (P->co_step) {+ case 0:+ intro_start = v2(E->x, E->y);+ if (P->intro == INTRO_WALKINRIGHT) E->x = g_level.room->x - 16.f, P->facing = 1;+ else E->x = g_level.room->x + g_level.room->w + 16.f, P->facing = -1;+ P->co_step = 1;+ return .3f;+ case 1:+ play(A_player_runSlow);+ P->co_step = 2;+ /* fall through */+ case 2:+ if (fabsf(E->x - intro_start.x) > 2 && !solid_at((float)P->facing, 0)) {+ actor_move_towards_x(E, intro_start.x, 64 * DT, NULL);+ return 0;+ }+ E->x = intro_start.x, E->y = intro_start.y;+ play(A_player_idle);+ P->co_step = 3;+ return .2f;+ default:+ SET(ST_NORMAL);+ return -1;+ }+}+static float co_intro_jump(void) {+ switch (P->co_step) {+ case 0:+ intro_start = v2(E->x, E->y);+ E->depth = D_TOP;+ ents_mark_unsorted();+ P->facing = 1;+ E->y = g_level.room->y + g_level.room->h + 16.f;+ P->co_step = 1;+ return .5f;+ case 1:+ play(A_player_jumpSlow);+ P->co_step = 2;+ /* fall through */+ case 2:+ if (E->y > intro_start.y - 8) {+ E->y += -120 * DT;+ return 0;+ }+ P->speed.y = -100;+ P->co_step = 3;+ /* fall through */+ case 3:+ if (P->speed.y < 0) {+ P->speed.y += DT * 800;+ return 0;+ }+ P->speed.y = 0;+ P->co_step = 4;+ return .1f;+ case 4:+ play(A_player_fallSlow);+ P->co_step = 5;+ /* fall through */+ case 5:+ if (!P->on_ground) {+ P->speed.y += DT * 800;+ return 0;+ }+ E->x = intro_start.x, E->y = intro_start.y;+ E->depth = D_PLAYER;+ ents_mark_unsorted();+ level_dir_shake(v2(0, 1), .3f);+ SET(ST_NORMAL);+ return -1;+ }+ return -1;+}+static float co_intro_wakeup(void) {+ switch (P->co_step) {+ case 0:+ play(A_player_asleep);+ P->co_step = 1;+ return .5f;+ case 1:+ play_r(A_player_wakeUp);+ P->co_step = 2;+ /* fall through */+ case 2:+ if (P->spr.anim == A_player_wakeUp) return 0;+ P->co_step = 3;+ return .2f;+ default:+ SET(ST_NORMAL);+ return -1;+ }+}++static void intro_respawn_begin(void) {+ E->depth = D_TOP;+ ents_mark_unsorted();+ P->intro_ease = 1;+ Room *rm = g_level.room;+ V2 from = v2(E->x, E->y);+ from.x = clampf(from.x, rm->x + 40.f, rm->x + rm->w - 40.f);+ from.y = clampf(from.y, rm->y + 40.f, rm->y + rm->h - 40.f);+ P->dead_offset = from;+ P->respawn_from = v2sub(from, v2(E->x, E->y));+ P->respawn_t = 0;+ P->respawn_tween_on = 1;+}+static void intro_respawn_end(void) {+ E->depth = D_PLAYER;+ ents_mark_unsorted();+ P->dead_offset = v2(0, 0);+ P->respawn_tween_on = 0;+}+static void respawn_tween(void) {+ if (!P->respawn_tween_on) return;+ P->respawn_t += DT;+ float t = fminf(P->respawn_t / .6f, 1);+ P->dead_offset = v2mul(P->respawn_from, 1 - t);+ P->intro_ease = 1 - t;+ if (t >= 1) {+ P->respawn_tween_on = 0;+ if (P->state == ST_INTRORESPAWN) {+ SET(ST_NORMAL);+ P->spr.sx = 1.5f, P->spr.sy = .5f;+ }+ }+}++/* ---------------------------------------------------------------- the sprite */+static bool sprite_running(void) {+ int a = last_anim();+ return a == A_player_flip || a == A_player_runSlow || a == A_player_runFast || a == A_player_runStumble ||+ a == A_player_runWind || a == A_player_runSlow_carry;+}+static bool sprite_dream_dashing(void) {+ int a = last_anim();+ return a == A_player_dreamDashIn || a == A_player_dreamDashLoop || a == A_player_dreamDashOut;+}+static bool anim_idle_family(void) {+ int a = P->spr.anim;+ return a == A_player_idle || a == A_player_idleA || a == A_player_idleB || a == A_player_idleC || a == A_player_idle_carry;+}++static void update_sprite(void) {+ P->spr.sx = approach(P->spr.sx, 1, 1.75f * DT);+ P->spr.sy = approach(P->spr.sy, 1, 1.75f * DT);+ if (player_in_control(P) && P->spr.anim != A_player_throw && P->state != ST_TEMPLEFALL && P->state != ST_REFLECTIONFALL &&+ P->state != ST_STARFLY && P->state != ST_CASSETTEFLY) {+ if (P->state == ST_ATTRACT) play(A_player_fallFast);+ else if (P->state == ST_SUMMITLAUNCH) play(A_player_launch);+ else if (P->state == ST_PICKUP) play(A_player_pickUp);+ else if (P->state == ST_SWIM) {+ if (g_in.move_y > 0) play(A_player_swimDown);+ else if (g_in.move_y < 0) play(A_player_swimUp);+ else play(A_player_swimIdle);+ } else if (P->state == ST_DREAMDASH) {+ if (P->spr.anim != A_player_dreamDashIn && P->spr.anim != A_player_dreamDashLoop) play(A_player_dreamDashIn);+ } else if (sprite_dream_dashing() && last_anim() != A_player_dreamDashOut) {+ play(A_player_dreamDashOut);+ } else if (P->spr.anim != A_player_dreamDashOut) {+ if (player_dash_attacking(P)) {+ if (P->on_ground && P->dash_dir.y == 0 && !Ducking && P->speed.x != 0 && P->move_x == -signf(P->speed.x)) {+ if (level_on_interval(.02f)) dust_burst(v2(E->x, E->y), -PI_F / 2, 1);+ play(A_player_skid);+ } else+ play(A_player_dash);+ } else if (P->state == ST_CLIMB) {+ if (P->last_climb_move < 0) play(A_player_climbup);+ else if (P->last_climb_move > 0) play(A_player_wallslide);+ else if (!solid_at((float)P->facing, 6)) play(A_player_dangling);+ else if (g_in.move_x == -P->facing) {+ if (P->spr.anim != A_player_climbLookBack) play(A_player_climbLookBackStart);+ } else+ play(A_player_wallslide);+ } else if (Ducking && P->state == ST_NORMAL) {+ play(A_player_duck);+ } else if (P->on_ground) {+ P->fast_jump = false;+ if (!P->holding && P->move_x != 0 && solid_at((float)P->move_x, 0)) play(A_player_push);+ else if (fabsf(P->speed.x) <= RunAccel / 40 && P->move_x == 0) {+ if (P->holding) play(A_player_idle_carry);+ else if (!rect_solid(E->x + P->facing * 1, E->y + 2, E->x + P->facing * 1 + 1, E->y + 3) &&+ !rect_solid(E->x + P->facing * 4, E->y + 2, E->x + P->facing * 4 + 1, E->y + 3) &&+ !collide_jumpthru(E, E->x + P->facing * 4, E->y + 2))+ play(A_player_edge);+ else if (!rect_solid(E->x - P->facing * 1, E->y + 2, E->x - P->facing * 1 + 1, E->y + 3) &&+ !rect_solid(E->x - P->facing * 4, E->y + 2, E->x - P->facing * 4 + 1, E->y + 3) &&+ !collide_jumpthru(E, E->x - P->facing * 4, E->y + 2))+ play(A_player_edgeBack);+ else if (g_in.move_y == -1) {+ if (last_anim() != A_player_lookUp) play(A_player_lookUp);+ } else if (P->spr.anim != 255 && !anim_idle_family())+ play(A_player_idle);+ } else if (P->holding)+ play(A_player_runSlow_carry);+ else if (signf(P->speed.x) == -P->move_x && P->move_x != 0) {+ if (fabsf(P->speed.x) > MaxRun) play(A_player_skid);+ else if (P->spr.anim != A_player_skid) play(A_player_flip);+ } else if (P->wind_dir.x != 0 && P->wind_timeout > 0 && P->facing == -signf(P->wind_dir.x))+ play(A_player_runWind);+ else if (!sprite_running()) {+ if (fabsf(P->speed.x) < MaxRun * .5f) play(A_player_runSlow);+ else play(A_player_runFast);+ }+ } else if (P->wall_slide_dir != 0 && !P->holding) {+ play(A_player_wallslide);+ } else if (P->speed.y < 0) {+ if (P->holding) play(A_player_jumpSlow_carry);+ else if (P->fast_jump || fabsf(P->speed.x) > MaxRun) {+ P->fast_jump = true;+ play(A_player_jumpFast);+ } else+ play(A_player_jumpSlow);+ } else {+ if (P->holding) play(A_player_fallSlow_carry);+ else if (P->fast_jump || P->speed.y >= MaxFall || g_level.in_space) {+ P->fast_jump = true;+ if (last_anim() != A_player_fallFast) play(A_player_fallFast);+ } else+ play(A_player_fallSlow);+ }+ }+ }+ if (P->state != ST_DUMMY) P->spr.rate = g_level.in_space ? .5f : 1;+}++/* the idle animations' random variants (Sprite.OnLastFrame) */+static void sprite_advance(void) {+ int before = P->spr.anim, frame = P->spr.frame;+ spr_update(&P->spr);+ /* OnLastFrame of "idle": the anim looped back */+ if (before == A_player_idle && P->spr.anim == A_player_idle && P->spr.frame == 0 && frame != 0 && !g_level.in_cutscene &&+ P->idle_timer > 3) {+ if (rndf() < 0.2f) {+ float r = rndf();+ int next;+ if (!P->no_backpack) {+ if (g_level.core_mode == 1) next = r * 8 < 5 ? A_player_idleA : A_player_idleB;+ else next = r * 9 < 5 ? A_player_idleA : r * 9 < 8 ? A_player_idleB : A_player_idleC;+ } else+ next = r * 7 < 1 ? A_player_idleA : r * 7 < 4 ? A_player_idleB : A_player_idleC;+ play(next);+ }+ }+}++/* PlayerSprite metadata: hair offset and frame */+void hair_meta(uint16_t tex, int *hx, int *hy, int *frame, bool *has, int *carry) {+ const uint8_t *s = section(SEC_PMETA);+ int n = rd16(s), lo = 0, hi = n - 1;+ *hx = 0, *hy = 0, *frame = 0, *has = true, *carry = 0;+ while (lo <= hi) {+ int mid = (lo + hi) / 2;+ const uint8_t *r = s + 4 + 6 * mid;+ uint16_t t = rd16(r);+ if (t == tex) {+ *hx = (int8_t)r[2], *hy = (int8_t)r[3], *frame = r[4] & 0x7F, *has = r[4] & 0x80, *carry = (int8_t)r[5];+ return;+ }+ if (t < tex) lo = mid + 1;+ else hi = mid - 1;+ }+}++/* PlayerHair.AfterUpdate */+static void hair_after_update(void) {+ int hx, hy, fr, carry;+ bool has;+ hair_meta(spr_tex(&P->spr), &hx, &hy, &fr, &has, &carry);+ V2 off = v2((float)hx * P->facing, (float)hy);+ P->hair[0] = v2add(v2(E->x, E->y - 9 * P->spr.sy), off);+ V2 target = v2add(P->hair[0], v2(-P->facing * P->hair_step_facing * 2, sinf(P->hair_wave) * P->hair_step_ysine));+ target = v2add(target, P->hair_step);+ V2 prev = P->hair[0];+ for (int i = 1; i < P->hair_count && i < HAIR_NODES; i++) {+ if (P->hair_simulate) {+ float m = (1 - (float)i / P->hair_count * 0.5f) * P->hair_step_approach;+ V2 d = v2sub(target, P->hair[i]);+ float l = v2len(d), mv = m * DT;+ P->hair[i] = l <= mv ? target : v2add(P->hair[i], v2mul(d, mv / l));+ }+ V2 d = v2sub(P->hair[i], prev);+ if (v2len(d) > 3) P->hair[i] = v2add(prev, v2mul(v2norm(d), 3));+ target = v2add(P->hair[i], v2(-P->facing * P->hair_step_facing, sinf(P->hair_wave + i * 0.8f) * P->hair_step_ysine));+ target = v2add(target, P->hair_step);+ prev = P->hair[i];+ }+}++static void update_hair(bool gravity) {+ if (P->state == ST_STARFLY) {+ hair_rgb = P->spr.tint == rgb(StarFlyColor) ? StarFlyColor : NormalHairColor;+ gravity = false;+ } else if (P->dashes == 0 && P->dashes < player_max_dashes(P)) {+ hair_rgb = lerp_color(hair_rgb, UsedHairColor, 6 * DT);+ } else {+ uint32_t c;+ if (P->last_dashes != P->dashes) {+ c = FlashHairColor;+ P->hair_flash_timer = .12f;+ } else if (P->hair_flash_timer > 0) {+ c = FlashHairColor;+ P->hair_flash_timer -= DT;+ } else if (P->dashes == 2)+ c = TwoDashesHairColor;+ else+ c = NormalHairColor;+ hair_rgb = c;+ }+ P->hair_simulate = gravity;+ P->last_dashes = P->dashes;+}++/* ---------------------------------------------------------------- the update */+static void trigger_check(void);++static void player_update(Ent *e) {+ E = e;+ Player *p = P;+ if (p->body) {+ body_update();+ if (p->body_step >= 4) return;+ spr_update(&p->spr);+ return;+ }+ p->prev_pos = v2(E->x, E->y);+ p->strawb_reset_timer -= DT;+ if (p->strawb_reset_timer <= 0) p->strawb_index = 0;+ p->idle_timer += DT;+ if (g_level.in_cutscene) p->idle_timer = -5;+ else if (p->speed.x != 0 || p->speed.y != 0) p->idle_timer = 0;+ if (p->just_respawned && (p->speed.x != 0 || p->speed.y != 0)) p->just_respawned = false;+ if (p->state == ST_DREAMDASH) p->on_ground = p->on_safe_ground = false;+ else if (p->speed.y >= 0) {+ Ent *first = collide_first_solid(E, E->x, E->y + 1);+ if (!first) first = collide_first_jumpthru_outside(E, E->x, E->y + 1);+ if (first) {+ p->on_ground = true;+ p->on_safe_ground = first->safe;+ } else+ p->on_ground = p->on_safe_ground = false;+ } else+ p->on_ground = p->on_safe_ground = false;+ if (p->state == ST_SWIM) p->on_safe_ground = true;+ p->play_footstep_on_land -= DT;+ if (p->on_ground) p->highest_air_y = E->y;+ else p->highest_air_y = fminf(E->y, p->highest_air_y);+ if (level_on_interval(.05f)) p->flash = !p->flash;+ if (p->wall_slide_dir != 0) {+ p->wall_slide_timer = fmaxf(p->wall_slide_timer - DT, 0);+ p->wall_slide_dir = 0;+ }+ if (p->wall_boost_timer > 0) {+ p->wall_boost_timer -= DT;+ if (p->move_x == p->wall_boost_dir) {+ p->speed.x = WallJumpHSpeed * p->move_x;+ p->stamina += ClimbJumpCost;+ p->wall_boost_timer = 0;+ spr_play(&p->sweat, A_player_sweat_idle, false);+ }+ }+ if (p->on_ground && p->state != ST_CLIMB) {+ p->auto_jump = false;+ p->stamina = ClimbMaxStamina;+ p->wall_slide_timer = WallSlideTime;+ }+ if (p->dash_attack_timer > 0) p->dash_attack_timer -= DT;+ if (p->on_ground) {+ p->dream_jump = false;+ p->jump_grace_timer = JumpGraceTime;+ } else if (p->jump_grace_timer > 0)+ p->jump_grace_timer -= DT;+ if (p->dash_cooldown_timer > 0) p->dash_cooldown_timer -= DT;+ if (p->dash_refill_cooldown_timer > 0) p->dash_refill_cooldown_timer -= DT;+ else if (!p->inventory_norefills) {+ if (p->state == ST_SWIM) player_refill_dash(p);+ else if (p->on_ground)+ if (solid_at(0, 1) || jumpthru_outside_at(0, 1))+ if (!collide_first_kind(E, E->x, E->y, KIND_SPIKES)) player_refill_dash(p);+ }+ if (p->var_jump_timer > 0) p->var_jump_timer -= DT;+ if (p->auto_jump_timer > 0) {+ if (p->auto_jump) {+ p->auto_jump_timer -= DT;+ if (p->auto_jump_timer <= 0) p->auto_jump = false;+ } else+ p->auto_jump_timer = 0;+ }+ if (p->force_move_x_timer > 0) {+ p->force_move_x_timer -= DT;+ p->move_x = p->force_move_x;+ } else {+ p->move_x = g_in.move_x;+ p->climb_hop_solid = NULL;+ }+ if (p->climb_hop_solid && !p->climb_hop_solid->collidable) p->climb_hop_solid = NULL;+ else if (p->climb_hop_solid && (p->climb_hop_solid->x != p->climb_hop_solid_pos.x || p->climb_hop_solid->y != p->climb_hop_solid_pos.y)) {+ V2 mv = v2sub(v2(p->climb_hop_solid->x, p->climb_hop_solid->y), p->climb_hop_solid_pos);+ p->climb_hop_solid_pos = v2(p->climb_hop_solid->x, p->climb_hop_solid->y);+ actor_move_h_exact(E, (int)mv.x, NULL, NULL);+ actor_move_v_exact(E, (int)mv.y, NULL, NULL);+ }+ if (p->no_wind_timer > 0) p->no_wind_timer -= DT;+ if (p->move_x != 0 && player_in_control(p) && p->state != ST_CLIMB && p->state != ST_PICKUP && p->state != ST_REDDASH &&+ p->state != ST_HITSQUASH) {+ if (p->move_x != p->facing && Ducking) p->spr.sx = .8f, p->spr.sy = 1.2f;+ p->facing = p->move_x;+ }+ p->last_aim = aim_vector();+ if (p->wall_speed_retention_timer > 0) {+ if (signf(p->speed.x) == -signf(p->wall_speed_retained)) p->wall_speed_retention_timer = 0;+ else if (!solid_at(signf(p->wall_speed_retained), 0)) {+ p->speed.x = p->wall_speed_retained;+ p->wall_speed_retention_timer = 0;+ } else+ p->wall_speed_retention_timer -= DT;+ }+ if (p->hop_wait_x != 0) {+ if (signf(p->speed.x) == -p->hop_wait_x || p->speed.y > 0) p->hop_wait_x = 0;+ else if (!solid_at((float)p->hop_wait_x, 0)) {+ p->speed.x = p->hop_wait_x_speed;+ p->hop_wait_x = 0;+ }+ }+ if (p->wind_timeout > 0) p->wind_timeout -= DT;+ {+ V2 wd = p->wind_dir;+ if (p->wind_timeout > 0 && wd.x != 0) {+ p->wind_hair_timer += DT * 8;+ p->hair_step = v2(wd.x * 5, sinf(p->wind_hair_timer));+ p->hair_step_facing = 0;+ p->hair_step_approach = 128;+ p->hair_step_ysine = 0;+ } else if (p->dashes > 1) {+ p->hair_step = v2(sinf(g_level.time_active * 2) * 0.7f - p->facing * 3, sinf(g_level.time_active * 1));+ p->hair_step_facing = 0;+ p->hair_step_approach = 90;+ p->hair_step_ysine = 1;+ p->hair_step.y += wd.y * 2;+ } else {+ p->hair_step = v2(0, 2);+ p->hair_step_facing = 0.5f;+ p->hair_step_approach = 64;+ p->hair_step_ysine = 0;+ p->hair_step.y += wd.y * 0.5f;+ }+ }+ if (p->state == ST_REDDASH) p->hair_count = 1;+ else if (p->state != ST_STARFLY) p->hair_count = p->dashes > 1 ? 5 : p->start_hair_count;+ if (p->min_hold_timer > 0) p->min_hold_timer -= DT;+ if (p->launched) {+ float sq = p->speed.x * p->speed.x + p->speed.y * p->speed.y;+ if (sq < 140 * 140) p->launched = false;+ else {+ p->launched_timer += DT;+ if (p->launched_timer >= .5f) p->launched = false, p->launched_timer = 0;+ }+ } else+ p->launched_timer = 0;+ p->was_tired = is_tired();++ /* base.Update(): components (hair wave, sprite, sweat, state machine), then the actor's lift */+ p->hair_wave += DT * 4;+ sprite_advance();+ spr_update(&p->sweat);+ respawn_tween();+ if (UPD[p->state]) {+ int next = UPD[p->state]();+ player_set_state(p, next);+ }+ co_update();+ if (p->bird_trails) { /* BirdDashTutorial's two alarms */+ p->bird_trail_t += DT;+ if (p->bird_trails == 2 && p->bird_trail_t >= 0.08f) create_trail(), p->bird_trails = 1;+ if (p->bird_trails == 1 && p->bird_trail_t >= 0.15f) create_trail(), p->bird_trails = 0;+ }+ leader_update(v2(E->x, E->y - 8)); /* the Leader component, at (0, -8) */+ actor_update_lift(E);++ if (!p->on_ground && p->speed.y <= 0 && (p->state != ST_CLIMB || p->last_climb_move == -1) && collide_jumpthru(E, E->x, E->y))+ actor_move_v(E, JumpThruAssistSpeed * DT, NULL, NULL);+ if (!p->on_ground && player_dash_attacking(p) && p->dash_dir.y == 0)+ if (solid_at(0, DashVFloorSnapDist) || jumpthru_outside_at(0, DashVFloorSnapDist)) actor_move_v_exact(E, DashVFloorSnapDist, NULL, NULL);+ if (p->speed.y > 0 && can_unduck() && !box_is(HB_STARFLY) && !p->on_ground) set_ducking(false);+ if (p->state != ST_DREAMDASH && p->state != ST_ATTRACT) actor_move_h(E, p->speed.x * DT, on_collide_h, NULL);+ if (p->state != ST_DREAMDASH && p->state != ST_ATTRACT) actor_move_v(E, p->speed.y * DT, on_collide_v, NULL);+ if (p->dead) return;+ if (p->state == ST_SWIM) {+ if (p->speed.y < 0 && p->speed.y >= SwimMaxRise)+ while (!swim_check()) {+ p->speed.y = 0;+ if (actor_move_v_exact(E, 1, NULL, NULL)) break;+ }+ } else if (p->state == ST_NORMAL && swim_check())+ SET(ST_SWIM);+ else if (p->state == ST_CLIMB && swim_check()) {+ Ent *w = collide_first_kind(E, E->x, E->y, KIND_WATER);+ if (w && e_cym(E) < e_cym(w)) {+ while (swim_check())+ if (actor_move_v_exact(E, -1, NULL, NULL)) break;+ if (swim_check()) SET(ST_SWIM);+ } else+ SET(ST_SWIM);+ }+ update_sprite();+ if (p->holding) { /* UpdateCarry */+ int hx, hy, fr, carry;+ bool has;+ hair_meta(spr_tex(&p->spr), &hx, &hy, &fr, &has, &carry);+ holdable_carry(p->holding, v2(E->x + p->carry_offset.x, E->y + p->carry_offset.y + carry));+ }+ if (p->state != ST_REFLECTIONFALL) trigger_check();+ p->strawberries_blocked = collide_first_kind(E, E->x, E->y, KIND_BLOCKFIELD) != NULL;+ if (player_in_control(p) || p->force_camera_update) {+ V2 from = g_level.cam, target = player_camera_target(p);+ float mult = p->state == ST_TEMPLEFALL ? 8 : 1.f;+ float k = 1 - powf(0.01f / mult, DT);+ g_level.cam = v2add(from, v2mul(v2sub(target, from), k));+ }+ if (!p->dead && p->state != ST_CASSETTEFLY) {+ float was[4] = {E->cw, E->ch, E->cx, E->cy};+ set_box(hurtbox);+ for (int i = 0; i < g_nents && !p->dead; i++) {+ Ent *o = &g_ents[i];+ if (!(o->kind & KIND_PCOLLIDE) || !o->cls || o->dead == 1 || !o->collidable || !o->cls->on_player) continue;+ if (collide_ent_at(E, E->x, E->y, o)) o->cls->on_player(o, p);+ }+ if (p->dead) return;+ if (box_is(hurtbox)) ent_box(E, was[0], was[1], was[2], was[3]);+ }+ if (player_in_control(p) && !p->dead && p->state != ST_DREAMDASH) level_enforce_bounds(p);+ update_hair(true);+ if (p->was_ducking != Ducking) p->was_ducking = Ducking;+ p->was_on_ground = p->on_ground;+}++static void trigger_check(void) {+ for (int i = 0; i < g_nents; i++) {+ Ent *t = &g_ents[i];+ if (!(t->kind & KIND_TRIGGER) || !t->cls || t->dead == 1 || !t->collidable) continue;+ if (collide_ent_at(E, E->x, E->y, t)) {+ if (!t->triggered) {+ t->triggered = 1;+ if (t->cls->on_enter) t->cls->on_enter(t, P);+ }+ if (t->cls->on_stay) t->cls->on_stay(t, P);+ } else if (t->triggered) {+ t->triggered = 0;+ if (t->cls->on_leave) t->cls->on_leave(t, P);+ }+ }+}++void player_after_update(Player *p) {+ if (!p->ent || !p->ent->cls) return;+ E = p->ent;+ if (!p->body || p->body_step < 4) hair_after_update();+}++/* ---------------------------------------------------------------- camera */+V2 player_camera_target(Player *p) {+ Ent *e = p->ent;+ Room *rm = g_level.room;+ V2 t = v2(e->x - 160, e->y - 90);+ if (p->state != ST_REFLECTIONFALL) t = v2add(t, g_level.cam_offset);+ if (p->state == ST_STARFLY) t.x += .2f * p->speed.x, t.y += .2f * p->speed.y;+ else if (p->state == ST_REDDASH) t.x += 48 * signf(p->speed.x), t.y += 48 * signf(p->speed.y);+ else if (p->state == ST_SUMMITLAUNCH) t.y -= 64;+ else if (p->state == ST_REFLECTIONFALL) t.y += 32;+ if (v2len(p->cam_anchor_lerp) > 0) {+ if (p->cam_anchor_ignore_x && !p->cam_anchor_ignore_y) t.y = lerpf(t.y, p->cam_anchor.y, p->cam_anchor_lerp.y);+ else if (!p->cam_anchor_ignore_x && p->cam_anchor_ignore_y) t.x = lerpf(t.x, p->cam_anchor.x, p->cam_anchor_lerp.x);+ else if (p->cam_anchor_lerp.x == p->cam_anchor_lerp.y) {+ t.x = lerpf(t.x, p->cam_anchor.x, p->cam_anchor_lerp.x);+ t.y = lerpf(t.y, p->cam_anchor.y, p->cam_anchor_lerp.x);+ } else {+ t.x = lerpf(t.x, p->cam_anchor.x, p->cam_anchor_lerp.x);+ t.y = lerpf(t.y, p->cam_anchor.y, p->cam_anchor_lerp.y);+ }+ }+ V2 at;+ at.x = clampf(t.x, (float)rm->x, (float)(rm->x + rm->w - 320));+ at.y = clampf(t.y, (float)rm->y, (float)(rm->y + rm->h - 180));+ int lock = g_level.cam_lock;+ Ent *lk = g_level.cam_locker;+ if (lock && lk && (lk->dead == 1 || !lk->cls)) lk = NULL;+ if (lock) {+ if (lock != 1) {+ at.x = fmaxf(at.x, g_level.cam.x);+ if (lk) at.x = fminf(at.x, fmaxf((float)rm->x, lk->x - g_level.cam_lock_dx));+ }+ if (lock == 2) {+ at.y = fmaxf(at.y, g_level.cam.y);+ if (lk) at.y = fminf(at.y, fmaxf((float)rm->y, lk->y - g_level.cam_lock_dy));+ } else if (lock == 1) {+ g_level.cam_upward_max_y = fminf(g_level.cam.y + 180, g_level.cam_upward_max_y);+ at.y = fminf(at.y, g_level.cam_upward_max_y);+ if (lk) at.y = fmaxf(at.y, fminf((float)(rm->y + rm->h - 180), lk->y - g_level.cam_lock_dy));+ }+ }+ for (int i = 0; i < g_nents; i++) {+ Ent *k = &g_ents[i];+ if ((k->kind & KIND_KILLBOX) && k->cls && k->collidable && e_top(e) < e_bottom(k) && e_right(e) > e_left(k) && e_left(e) < e_right(k))+ at.y = fminf(at.y, e_top(k) - 180);+ }+ return at;+}++/* ---------------------------------------------------------------- transitions */+bool player_transition_to(Player *p, V2 target) {+ E = p->ent;+ actor_move_towards_x(E, target.x, 60 * DT, NULL);+ actor_move_towards_y(E, target.y, 60 * DT, NULL);+ update_hair(false);+ hair_after_update();+ if (E->x == target.x && E->y == target.y) {+ E->remx = E->remy = 0;+ p->speed.x = (float)roundi(p->speed.x);+ p->speed.y = (float)roundi(p->speed.y);+ return true;+ }+ return false;+}+void player_on_transition(Player *p) {+ p->wall_slide_timer = WallSlideTime;+ p->jump_grace_timer = 0;+ p->force_move_x_timer = 0;+ player_refill_dash(p);+ player_refill_stamina(p);+ leader_transfer();+}+void player_before_up_transition(Player *p) {+ p->speed.x = 0;+ if (p->state != ST_REDDASH && p->state != ST_REFLECTIONFALL && p->state != ST_STARFLY) {+ p->var_jump_speed = p->speed.y = JumpSpeed;+ player_set_state(p, p->state == ST_SUMMITLAUNCH ? ST_INTROJUMP : ST_NORMAL);+ p->auto_jump = true;+ p->auto_jump_timer = 0;+ p->var_jump_timer = VarJumpTime;+ }+ p->dash_cooldown_timer = 0.2f;+}+void player_before_down_transition(Player *p) {+ if (p->state != ST_REDDASH && p->state != ST_REFLECTIONFALL && p->state != ST_STARFLY) {+ player_set_state(p, ST_NORMAL);+ p->speed.y = fmaxf(0, p->speed.y);+ p->auto_jump = false;+ p->var_jump_timer = 0;+ }+}++/* ---------------------------------------------------------------- rendering */+static void hair_render(void) {+ int hx, hy, fr, carry;+ bool has;+ hair_meta(spr_tex(&P->spr), &hx, &hy, &fr, &has, &carry);+ if (!has) return;+ uint16_t col = rgb(hair_rgb);+ P->hair[0] = v2(floorf(P->hair[0].x), floorf(P->hair[0].y));+ uint16_t bangs = (uint16_t)(T_characters_player_bangs00 + 0);+ uint16_t bang_tex[3] = {T_characters_player_bangs00, T_characters_player_bangs01, T_characters_player_bangs02};+ (void)bangs;+ int n = P->hair_count;+ for (int i = 0; i < n; i++) {+ uint16_t t = i == 0 ? bang_tex[fr < 3 ? fr : 0] : T_characters_player_hair00;+ float num = 0.25f + (1 - (float)i / n) * 0.75f;+ float sx = (i == 0 ? (float)P->facing : num) * fabsf(P->spr.sx), sy = num;+ V2 at = P->hair[i];+ gfx_tex_ex(t, at.x - 1, at.y, 5, 5, sx, sy, 0, 0, 255, GF_SILHOUETTE);+ gfx_tex_ex(t, at.x + 1, at.y, 5, 5, sx, sy, 0, 0, 255, GF_SILHOUETTE);+ gfx_tex_ex(t, at.x, at.y - 1, 5, 5, sx, sy, 0, 0, 255, GF_SILHOUETTE);+ gfx_tex_ex(t, at.x, at.y + 1, 5, 5, sx, sy, 0, 0, 255, GF_SILHOUETTE);+ }+ for (int i = n - 1; i >= 0; i--) {+ uint16_t t = i == 0 ? bang_tex[fr < 3 ? fr : 0] : T_characters_player_hair00;+ float num = 0.25f + (1 - (float)i / n) * 0.75f;+ float sx = (i == 0 ? (float)P->facing : num) * fabsf(P->spr.sx), sy = num;+ gfx_tex_ex(t, P->hair[i].x, P->hair[i].y, 5, 5, sx, sy, 0, col, 255, GF_SILHOUETTE);+ }+}++static void player_render(Ent *e) {+ E = e;+ Player *p = P;+ float rx = floorf(e->x), ry = floorf(e->y);+ if (p->body) {+ if (p->body_step < 4) {+ Sprite s = p->spr;+ s.sx = p->body_scale * p->facing, s.sy = p->body_scale;+ spr_draw(&s, rx, ry);+ } else if (p->death_effect >= 0 && p->death_effect <= 1)+ death_effect_draw(v2add(v2(rx, ry), v2(0, -6)), p->death_color, p->death_effect);+ return;+ }+ if (p->state == ST_INTRORESPAWN) {+ death_effect_draw(v2add(center(), p->dead_offset), rgb(hair_rgb), p->intro_ease);+ return;+ }+ if (p->state != ST_STARFLY) p->spr.tint = (is_tired() && p->flash) ? 0xF800 : 0xFFFF;+ hair_render();+ Sprite s = p->spr;+ s.sx *= p->facing;+ spr_draw(&s, rx, ry + p->spr_dy);+ if (P->sweat.visible && (P->state == ST_CLIMB || spr_is(&P->sweat, A_player_sweat_jump))) {+ Sprite w = p->sweat;+ w.sx = p->facing;+ spr_draw(&w, rx, ry - 8);+ }+}+++/* ---------------------------------------------------------------- spawning */+static const EntClass PLAYER_CLASS = {+ .name = "player", .size = sizeof(ActorExt), .update = player_update, .render = player_render,+ .on_squish = on_squish, .is_riding_solid = is_riding_solid, .is_riding_jumpthru = is_riding_jumpthru,+ .kind = KIND_ACTOR | KIND_PLAYER};++void player_spawn(V2 at, int intro) {+ Player *p = P;+ memset(p, 0, sizeof *p);+ p->golden_room = -1;+ leader_reset();+ Ent *e = ent_new(&PLAYER_CLASS, (float)(int)at.x, (float)(int)at.y);+ E = e;+ p->ent = e;+ e->depth = D_PLAYER;+ e->tags = TAG_PERSISTENT; /* (between rooms, only TransitionTo moves her) */+ e->dead = 0;+ p->no_backpack = !g_session.backpack;+ spr_init(&p->spr, p->no_backpack ? SB_player_no_backpack : SB_player);+ spr_init(&p->sweat, SB_player_sweat);+ p->hair_count = p->start_hair_count = 4;+ hair_rgb = NormalHairColor;+ p->hair_step = v2(0, 2);+ p->hair_step_facing = 0.5f;+ p->hair_step_approach = 64;+ p->hair_simulate = true;+ p->inventory_dashes = g_session.inv_dashes;+ p->inventory_dreamdash = g_session.dreamdash;+ set_box(HB_NORMAL);+ hurtbox = HB_NORMAL_HURT;+ p->last_aim = v2(1, 0);+ p->facing = 1;+ p->stamina = ClimbMaxStamina;+ p->wall_slide_timer = WallSlideTime;+ p->max_fall = MaxFall;+ p->dummy_gravity = p->dummy_friction = p->dummy_maxspeed = p->dummy_auto_animate = true;+ p->state = -1;+ p->prev_state = -1;+ p->dashes = p->last_dashes = player_max_dashes(p);+ p->intro = intro;+ if (e->x > g_level.room->x + g_level.room->w / 2 && intro != INTRO_NONE) p->facing = -1;+ switch (intro) {+ case INTRO_RESPAWN: player_set_state(p, ST_INTRORESPAWN), p->just_respawned = true; break;+ case INTRO_WALKINRIGHT: case INTRO_WALKINLEFT: player_set_state(p, ST_INTROWALK); break;+ case INTRO_JUMP: player_set_state(p, ST_INTROJUMP); break;+ case INTRO_WAKEUP: play(A_player_asleep), p->facing = 1, player_set_state(p, ST_INTROWAKEUP); break;+ case INTRO_FALL: player_set_state(p, ST_REFLECTIONFALL); break;+ case INTRO_TEMPLEMIRRORVOID: /* StartTempleMirrorVoidSleep */+ play(A_player_asleep), p->facing = 1, player_set_state(p, ST_DUMMY), p->state_locked = true;+ p->dummy_auto_animate = p->dummy_gravity = false;+ break;+ default: player_set_state(p, ST_NORMAL); break;+ }+ if (p->state < 0) player_set_state(p, ST_NORMAL);+ p->intro = intro;+ /* PlayerHair.Start */+ for (int i = 0; i < HAIR_NODES; i++) p->hair[i] = v2(e->x - p->facing * 200, e->y + 200);+ update_hair(true);+ hair_after_update();+ p->prev_pos = v2(e->x, e->y);+}++V2 player_spawn_near(V2 at) { return level_closest_spawn(at); }++/* ---------------------------------------------------------------- cutscene walks */+/* DummyWalkTo, DummyWalkToExact and DummyRunTo, an update at a time */+bool player_walk(Player *p, Walk *w) {+ Ent *e = p->ent;+ E = e;+ if (w->phase == 0) {+ player_set_state(p, ST_DUMMY);+ w->phase = 1;+ if (w->mode == WALK_EXACT) {+ if (e->x == w->x) return false;+ p->dummy_moving = true;+ if (w->flags & WALK_BACKWARDS) {+ p->spr.rate = -1;+ p->facing = (int)signf(e->x - w->x);+ } else+ p->facing = (int)signf(w->x - e->x);+ w->last = (int8_t)signf(e->x - w->x);+ } else if (w->mode == RUN_TO) {+ if (fabsf(e->x - w->x) <= 4) return false;+ p->dummy_moving = true;+ if (w->flags & RUN_FAST) spr_play(&p->spr, A_player_runFast, false);+ else if (p->spr.last_goto != A_player_runSlow && p->spr.last_goto != A_player_runFast &&+ p->spr.last_goto != A_player_runStumble && p->spr.last_goto != A_player_runWind)+ spr_play(&p->spr, A_player_runSlow, false);+ p->facing = signf(w->x - e->x) > 0 ? 1 : -1;+ } else {+ if (!(fabsf(e->x - w->x) > 4 && !p->dead)) return false;+ p->dummy_moving = true;+ if (w->flags & WALK_BACKWARDS) {+ p->spr.rate = -1;+ p->facing = signf(e->x - w->x) > 0 ? 1 : -1;+ } else+ p->facing = signf(w->x - e->x) > 0 ? 1 : -1;+ }+ }+ if (w->mode == WALK_EXACT) {+ if (!p->dead && e->x != w->x && !collide_solid(e, e->x + p->facing, e->y) &&+ (!(w->flags & WALK_CANCEL_ON_FALL) || actor_on_ground(e, 1))) {+ p->speed.x = approach(p->speed.x, signf(w->x - e->x) * 64 * w->mult, 1000 * DT);+ int now = (int)signf(e->x - w->x);+ if (now != w->last) e->x = w->x;+ else {+ w->last = (int8_t)now;+ return true;+ }+ }+ p->speed.x = 0;+ p->spr.rate = 1;+ spr_play(&p->spr, A_player_idle, false);+ p->dummy_moving = false;+ return false;+ }+ if (w->mode == RUN_TO) {+ if (fabsf(e->x - w->x) > 4) {+ p->speed.x = approach(p->speed.x, signf(w->x - e->x) * 90, 1000 * DT);+ return true;+ }+ spr_play(&p->spr, A_player_idle, false);+ p->dummy_moving = false;+ return false;+ }+ if (fabsf(w->x - e->x) > 4 && ((w->flags & WALK_INTO_WALLS) || !collide_solid(e, e->x + signf(w->x - e->x), e->y))) {+ p->speed.x = approach(p->speed.x, signf(w->x - e->x) * 64 * w->mult, 1000 * DT);+ return true;+ }+ p->spr.rate = 1;+ spr_play(&p->spr, A_player_idle, false);+ p->dummy_moving = false;+ return false;+}diff --git a/games/celeste/src/player.h b/games/celeste/src/player.hnew file mode 100644index 00000000..aef2f776--- /dev/null+++ b/games/celeste/src/player.h@@ -0,0 +1,181 @@+/* Madeline: a port of Player.cs (NoelFB/Celeste, MIT). */+#ifndef PLAYER_H+#define PLAYER_H+#include "ent.h"++enum {+ ST_NORMAL, ST_CLIMB, ST_DASH, ST_SWIM, ST_BOOST, ST_REDDASH, ST_HITSQUASH, ST_LAUNCH, ST_PICKUP, ST_DREAMDASH,+ ST_SUMMITLAUNCH, ST_DUMMY, ST_INTROWALK, ST_INTROJUMP, ST_INTRORESPAWN, ST_INTROWAKEUP, ST_BIRDDASHTUTORIAL,+ ST_FROZEN, ST_REFLECTIONFALL, ST_STARFLY, ST_TEMPLEFALL, ST_CASSETTEFLY, ST_ATTRACT, ST_INTROMOONJUMP, ST_FLINGBIRD,+ ST_INTROTHINKFORABIT, ST_COUNT+};+enum { INTRO_TRANSITION, INTRO_RESPAWN, INTRO_WALKINRIGHT, INTRO_WALKINLEFT, INTRO_JUMP, INTRO_WAKEUP, INTRO_FALL,+ INTRO_TEMPLEMIRRORVOID, INTRO_NONE, INTRO_THINKFORABIT };++#define HAIR_NODES 10++struct Player {+ Ent *ent;+ V2 speed;+ int facing; /* 1 right, -1 left */+ Sprite spr;+ int8_t spr_dy; /* Sprite.Y */+ int hair_count, start_hair_count;+ V2 hair[HAIR_NODES];+ uint16_t hair_color; /* RGB565 */+ float hair_r, hair_g, hair_b; /* Hair.Color, for Color.Lerp */+ V2 hair_step;+ float hair_step_facing, hair_step_approach, hair_step_ysine, hair_wave;+ bool hair_simulate, hair_outline;+ float hair_alpha;+ int dashes, last_dashes, max_dashes;+ float stamina;+ int state, prev_state;+ bool state_locked;+ /* the state's coroutine: a step and a wait timer */+ int co_step;+ float co_wait;+ bool co_active;+ float co_t;+ bool on_ground, was_on_ground, on_safe_ground;+ int move_x;+ bool flash, was_ducking, ducking;+ float idle_timer;+ float jump_grace_timer;+ bool auto_jump;+ float auto_jump_timer;+ float var_jump_speed, var_jump_timer;+ int force_move_x;+ float force_move_x_timer;+ int hop_wait_x;+ float hop_wait_x_speed;+ V2 last_aim;+ float dash_cooldown_timer, dash_refill_cooldown_timer;+ V2 dash_dir;+ float wall_slide_timer;+ int wall_slide_dir;+ float climb_no_move_timer;+ V2 carry_offset;+ V2 dead_offset;+ float intro_ease;+ float wall_speed_retention_timer, wall_speed_retained;+ int wall_boost_dir;+ float wall_boost_timer;+ float max_fall;+ float dash_attack_timer;+ bool was_tired;+ float highest_air_y;+ bool dash_started_on_ground, fast_jump;+ int last_climb_move;+ float no_wind_timer;+ float dream_dash_can_end_timer;+ Ent *climb_hop_solid;+ V2 climb_hop_solid_pos;+ float play_footstep_on_land;+ float min_hold_timer;+ bool called_dash_events;+ bool launched;+ float launched_timer;+ float dash_trail_timer;+ bool was_dash_b;+ V2 before_dash_speed;+ bool started_dashing;+ float hair_flash_timer;+ V2 wind_dir;+ float wind_timeout, wind_hair_timer;+ bool dead, just_respawned;+ int intro;+ bool dummy_moving, dummy_gravity, dummy_friction, dummy_maxspeed, dummy_auto_animate;+ float hit_squash_no_move_timer;+ bool dream_jump;+ Ent *dream_block;+ Ent *holding;+ V2 swap_cancel;+ int golden_room;+ uint8_t bird_trails; /* BirdDashTutorial */+ bool bird_climbing;+ float bird_trail_t; /* PlayerDeadBody.HasGolden: the golden's room, -1 none */+ float strawb_reset_timer;+ int strawb_index;+ bool strawberries_blocked;+ V2 prev_pos;+ int16_t respawn_tween_on;+ float respawn_t;+ V2 respawn_from;+ bool force_camera_update;+ V2 cam_anchor, cam_anchor_lerp;+ bool cam_anchor_ignore_x, cam_anchor_ignore_y;+ /* the dead body */+ bool body;+ V2 body_bounce;+ float body_t, body_scale;+ int body_step;+ float death_effect;+ uint16_t death_color;+ bool death_finished;+ float launch_approach_x;+ bool has_launch_approach;+ float star_fly_timer, star_fly_speed_lerp;+ bool star_fly_transforming;+ V2 star_fly_last_dir;+ V2 boost_target;+ bool boost_red;+ Ent *current_booster, *last_booster;+ V2 attract_to;+ float summit_target_x, summit_particle_timer;+ Sprite sweat;+ bool no_backpack;+ bool inventory_dreamdash, inventory_norefills;+ int inventory_dashes;+ uint8_t triggers_inside[16];+ int ntriggers_inside;+};+extern Player g_player;++/* PlayerSprite's frame metadata (SEC_PMETA): hair offset, bangs frame, has hair, carry offset */+void hair_meta(uint16_t tex, int *hx, int *hy, int *frame, bool *has, int *carry);+void player_spawn(V2 at, int intro);+V2 player_spawn_near(V2 at);+void player_start_cassette_fly(Player *p, V2 target, V2 control);+V2 player_camera_target(Player *p);+bool player_transition_to(Player *p, V2 target);+void player_on_transition(Player *p);+void player_before_up_transition(Player *p);+void player_before_down_transition(Player *p);+void player_on_bounds_h(Player *p);+void player_on_bounds_v(Player *p);+void player_die_ex(Player *p, V2 dir, bool even_if_invincible, bool register_death); /* Player.Die */+static inline void player_die(Player *p, V2 dir, bool even_if_invincible) { player_die_ex(p, dir, even_if_invincible, true); }+int berry_golden_room(void);+/* cutscene walks (Player.DummyWalkTo, DummyWalkToExact, DummyRunTo) as nested steps: true while walking;+ * a Walk starts with phase 0 */+enum { WALK_TO, WALK_EXACT, RUN_TO };+enum { WALK_BACKWARDS = 1, WALK_INTO_WALLS = 2, WALK_CANCEL_ON_FALL = 4, RUN_FAST = 8 };+typedef struct { float x, mult; uint8_t mode, flags, phase; int8_t last; } Walk;+static inline Walk walk_to(float x) { return (Walk){x, 1, WALK_TO, 0, 0, 0}; }+static inline Walk walk_exact(int x) { return (Walk){(float)x, 1, WALK_EXACT, 0, 0, 0}; }+bool player_walk(Player *p, Walk *w); /* the room of a golden strawberry (not winged) following the player, -1 */+void leader_lose_all(void);+void player_after_update(Player *p);+void player_set_state(Player *p, int st);+bool player_refill_dash(Player *p);+bool player_use_refill(Player *p, bool two);+void player_refill_stamina(Player *p);+void player_bounce(Player *p, float from_y);+void player_super_bounce(Player *p, float from_y);+void player_side_bounce(Player *p, int dir, float from_x, float from_y);+void player_rebound(Player *p, int dir);+void player_point_bounce(Player *p, V2 from);+bool player_dash_attacking(const Player *p);+bool player_in_control(const Player *p);+V2 player_explode_launch(Player *p, V2 from, bool snap_up);+bool player_start_star_fly(Player *p);+void player_boost(Player *p, Ent *booster, bool red);+V2 player_center(const Player *p);+bool player_bounce_check(const Player *p, float y);+bool player_ducking(const Player *p);+void player_set_ducking(Player *p, bool d);+int player_max_dashes(const Player *p);+void player_jump(Player *p, bool particles, bool sfx);+void player_start_attract(Player *p, V2 to);+#endifdiff --git a/games/celeste/src/ptypes.c b/games/celeste/src/ptypes.cnew file mode 100644index 00000000..093411f0--- /dev/null+++ b/games/celeste/src/ptypes.c@@ -0,0 +1,124 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* Generated by tools/gen_particles.py from the game's ParticleTypes. */+#include "fx.h"++const PType P_Dust = {0xFFFFFFFF, 0xFFFFFFFF, PC_STATIC, PF_NONE, PR_RANDOM, 1, 0.7f, 0.2f, 5.0f, 15.0f, 1.0f, 0.3f, 0.5f, 1.570796f, 0.5f, 0.0f, 0.0f, 0, {0.0f, 4.0f}, 0.0f, {T_particles_smoke0, T_particles_smoke1, T_particles_smoke2, T_particles_smoke3}, 4, 1};+const PType P_SparkyDust = {0xFF5BE1CD, 0xFFAAFAB6, PC_BLINK, PF_NONE, PR_RANDOM, 1, 0.7f, 0.2f, 5.0f, 15.0f, 1.0f, 0.3f, 0.5f, 1.570796f, 0.5f, 0.0f, 0.0f, 0, {0.0f, 4.0f}, 0.0f, {T_particles_zappysmoke00, T_particles_zappysmoke01, T_particles_zappysmoke02, T_particles_zappysmoke03}, 4, 1};+const PType P_Chimney = {0xFFFFFFFF, 0xFFD3D3D3, PC_CHOOSE, PF_NONE, PR_RANDOM, 1, 1.0f, 0.25f, 4.0f, 12.0f, 1.0f, 2.0f, 4.0f, 1.570796f, 0.5f, 0.0f, 0.0f, 0, {-4.0f, 1.0f}, 0.0f, {T_particles_smoke0, T_particles_smoke1, T_particles_smoke2, T_particles_smoke3}, 4, 0};+const PType P_Steam = {0x33FFFFFF, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_RANDOM, 1, 0.5f, 0.0f, 4.0f, 12.0f, 1.0f, 2.0f, 4.0f, -1.570796f, 0.5f, 0.0f, 0.0f, 0, {0.0f, -4.0f}, 0.0f, {T_particles_smoke0, T_particles_smoke1, T_particles_smoke2, T_particles_smoke3}, 4, 0};+const PType P_VentDust = {0xFFD3D3D3, 0xFFFFFFFF, PC_STATIC, PF_LINEAR, PR_NONE, 0, 1.0f, 0.0f, 20.0f, 40.0f, 1.0f, 0.4f, 0.8f, 1.570796f, 0.05f, 0.0f, 0.0f, 0, {0.0f, 20.0f}, 0.0f, {0}, 0, 0};+const PType P_Player_P_DashA = {0xFF44B7FF, 0xFF75C9FF, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 10.0f, 20.0f, 1.0f, 1.0f, 1.8f, 0.0f, 1.047198f, 0.0f, 0.0f, 0, {0.0f, 8.0f}, 0.0f, {0}, 0, 0};+const PType P_Player_P_DashB = {0xFFAC3232, 0xFFE05959, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 10.0f, 20.0f, 1.0f, 1.0f, 1.8f, 0.0f, 1.047198f, 0.0f, 0.0f, 0, {0.0f, 8.0f}, 0.0f, {0}, 0, 0};+const PType P_Player_P_DashBadB = {0xFF9B3FB5, 0xFFCC8EE2, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 10.0f, 20.0f, 1.0f, 1.0f, 1.8f, 0.0f, 1.047198f, 0.0f, 0.0f, 0, {0.0f, 8.0f}, 0.0f, {0}, 0, 0};+const PType P_Player_P_CassetteFly = {0x99FFFFFF, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_NONE, 0, 1.0f, 0.5f, 8.0f, 16.0f, 1.0f, 0.4f, 1.0f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, -24.0f}, 0.0f, {T_particles_bubble}, 1, 0};+const PType P_Player_P_Split = {0xFFFF6DEF, 0xFFE256D3, PC_CHOOSE, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 60.0f, 80.0f, 0.1f, 0.6f, 0.9f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_Player_P_SummitLandA = {0xFFFFFFFF, 0xFFFFFFFF, PC_STATIC, PF_NONE, PR_RANDOM, 1, 0.7f, 0.2f, 5.0f, 10.0f, 1.0f, 0.4f, 0.8f, 1.570796f, 1.396263f, 0.0f, 0.0f, 0, {0.0f, 4.0f}, 0.0f, {T_particles_smoke0, T_particles_smoke1, T_particles_smoke2, T_particles_smoke3}, 4, 1};+const PType P_Player_P_SummitLandB = {0xFFFFFFFF, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_RANDOM, 0, 0.8f, 0.4f, 20.0f, 60.0f, 0.1f, 0.8f, 1.2f, 0.0f, 0.5235988f, 0.0f, 0.0f, 0, {-0.0f, -60.0f}, 0.0f, {T_particles_smoke0, T_particles_smoke1, T_particles_smoke2, T_particles_smoke3}, 4, 0};+const PType P_Player_P_SummitLandC = {0xFFFF6DEF, 0xFFFFB6F7, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 40.0f, 140.0f, 0.1f, 0.8f, 1.6f, -1.570796f, 1.745329f, 0.0f, 0.0f, 0, {0.0f, 20.0f}, 0.0f, {0}, 0, 0};+const PType P_Torch_P_OnLight = {0xFF6385FF, 0xFFFFFFFF, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 80.0f, 90.0f, 0.03f, 0.6f, 0.8f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_Cloud_P_Cloud = {0xFF2C5FCC, 0xFFFFFFFF, PC_STATIC, PF_NONE, PR_NONE, 1, 0.7f, 0.25f, 10.0f, 20.0f, 0.01f, 0.25f, 0.3f, 4.712389f, 0.1745329f, 0.0f, 0.0f, 0, {0.0f, 90.0f}, 0.0f, {T_particles_cloud}, 1, 0};+const PType P_Cloud_P_FragileCloud = {0xFF5E22AE, 0xFFFFFFFF, PC_STATIC, PF_NONE, PR_NONE, 1, 0.7f, 0.25f, 10.0f, 20.0f, 0.01f, 0.25f, 0.3f, 4.712389f, 0.1745329f, 0.0f, 0.0f, 0, {0.0f, 90.0f}, 0.0f, {T_particles_cloud}, 1, 0};+const PType P_Booster_P_Burst = {0xFF2C956E, 0xFFFFFFFF, PC_STATIC, PF_NONE, PR_NONE, 1, 0.7f, 0.25f, 10.0f, 20.0f, 0.01f, 0.5f, 0.8f, 4.712389f, 0.1745329f, 0.0f, 0.0f, 0, {0.0f, 90.0f}, 0.0f, {T_particles_blob}, 1, 0};+const PType P_Booster_P_BurstRed = {0xFF942C3E, 0xFFFFFFFF, PC_STATIC, PF_NONE, PR_NONE, 1, 0.7f, 0.25f, 10.0f, 20.0f, 0.01f, 0.5f, 0.8f, 4.712389f, 0.1745329f, 0.0f, 0.0f, 0, {0.0f, 90.0f}, 0.0f, {T_particles_blob}, 1, 0};+const PType P_Booster_P_Appear = {0xFF4ACFC6, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 40.0f, 50.0f, 0.25f, 0.6f, 1.0f, 0.0f, 0.1047198f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_Booster_P_RedAppear = {0xFFFF594A, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 40.0f, 50.0f, 0.25f, 0.6f, 1.0f, 0.0f, 0.1047198f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_TouchSwitch_P_Fire = {0xFFF141DF, 0xFFFFFFFF, PC_FADE, PF_LATE, PR_NONE, 1, 0.5f, 0.4f, 12.0f, 10.0f, 0.2f, 0.8f, 1.2f, -1.570796f, 0.5235988f, 0.0f, 0.0f, 0, {0.0f, -40.0f}, 0.0f, {T_particles_fire}, 1, 0};+const PType P_TouchSwitch_P_FireWhite = {0xFFFFFFFF, 0xFFFFFFFF, PC_FADE, PF_LATE, PR_NONE, 1, 0.5f, 0.4f, 12.0f, 10.0f, 0.2f, 0.8f, 1.2f, -1.570796f, 0.5235988f, 0.0f, 0.0f, 0, {0.0f, -40.0f}, 0.0f, {T_particles_fire}, 1, 0};+const PType P_Water_P_Splash = {0xCC87CDFA, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_RANDOM, 1, 0.8333333f, 0.3333333f, 30.0f, 24.0f, 0.98f, 0.35f, 0.2f, -1.570796f, 0.6981317f, 0.0f, 0.0f, 0, {0.0f, 20.0f}, 0.0f, {T_particles_feather}, 1, 0};+const PType P_Strawberry_P_Glow = {0xFFFF8563, 0xFFFFF4A8, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 2.0f, 8.0f, 1.0f, 1.0f, 1.5f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_Strawberry_P_GhostGlow = {0xFF6385FF, 0xFF72F0FF, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 2.0f, 8.0f, 1.0f, 1.0f, 1.5f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_Strawberry_P_GoldGlow = {0xFFFFDD62, 0xFFFFF7C4, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 2.0f, 8.0f, 1.0f, 1.0f, 1.5f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_Strawberry_P_MoonGlow = {0xFF5CFF6F, 0xFFE1FF6B, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 2.0f, 8.0f, 1.0f, 1.0f, 1.5f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_Strawberry_P_WingsBurst = {0xFFFFFFFF, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_RANDOM, 0, 0.5f, 0.3333333f, 36.0f, 12.0f, 0.98f, 1.0f, 0.3f, -1.570796f, 2.792527f, 0.0f, 0.0f, 0, {0.0f, 1.2f}, 0.0f, {T_particles_feather}, 1, 0};+const PType P_BirdNPC_P_Feather = {0xFF639BFF, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_RANDOM, 0, 0.5f, 0.3333333f, 36.0f, 12.0f, 0.98f, 2.0f, 0.3f, -1.570796f, 2.792527f, 0.0f, 0.0f, 0, {0.0f, 1.2f}, 0.0f, {T_particles_feather}, 1, 0};+const PType P_FlingBird_P_Feather = {0xFF639BFF, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_RANDOM, 0, 0.5f, 0.3333333f, 36.0f, 12.0f, 0.98f, 2.0f, 0.3f, -1.570796f, 2.792527f, 0.0f, 0.0f, 0, {0.0f, 1.2f}, 0.0f, {T_particles_feather}, 1, 0};+const PType P_Key_P_Shimmer = {0xFFE2D926, 0xFFFFFEEF, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 1.0f, 2.0f, 1.0f, 0.5f, 0.8f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_Key_P_Insert = {0xFFE2D926, 0xFFFFFEEF, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 40.0f, 60.0f, 0.05f, 0.5f, 0.8f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_Key_P_Collect = {0xFFE2D926, 0xFFFFFEEF, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 40.0f, 60.0f, 0.05f, 0.5f, 0.8f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_Refill_P_Shatter = {0xFFD3FFD4, 0xFF85FC87, PC_STATIC, PF_LATE, PR_RANDOM, 0, 1.0f, 0.0f, 140.0f, 210.0f, 0.005f, 0.25f, 0.4f, 4.712389f, 0.8726646f, 1.570796f, 4.712389f, 1, {0.0f, 0.0f}, 0.0f, {T_particles_triangle}, 1, 0};+const PType P_Refill_P_Glow = {0xFFA5FFF7, 0xFF6DE081, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 4.0f, 8.0f, 1.0f, 0.4f, 0.6f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_Refill_P_Regen = {0xFFA5FFF7, 0xFF6DE081, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 30.0f, 40.0f, 0.2f, 0.4f, 0.6f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_Refill_P_ShatterTwo = {0xFFFFD3F9, 0xFFEF94E3, PC_STATIC, PF_LATE, PR_RANDOM, 0, 1.0f, 0.0f, 140.0f, 210.0f, 0.005f, 0.25f, 0.4f, 4.712389f, 0.8726646f, 1.570796f, 4.712389f, 1, {0.0f, 0.0f}, 0.0f, {T_particles_triangle}, 1, 0};+const PType P_Refill_P_GlowTwo = {0xFFFFA5AA, 0xFFDD6CCA, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 4.0f, 8.0f, 1.0f, 0.4f, 0.6f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_Refill_P_RegenTwo = {0xFFFFA5AA, 0xFFDD6CCA, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 40.0f, 60.0f, 0.2f, 0.4f, 0.6f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_DashSwitch_P_PressA = {0xFF99E550, 0xFFD9FFB5, PC_BLINK, PF_NONE, PR_NONE, 0, 1.0f, 0.0f, 60.0f, 80.0f, 0.2f, 0.8f, 1.2f, 0.0f, 0.6981317f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_DashSwitch_P_PressB = {0xFF99E550, 0xFFD9FFB5, PC_BLINK, PF_NONE, PR_NONE, 0, 1.0f, 0.0f, 100.0f, 110.0f, 0.2f, 0.8f, 1.2f, 0.0f, 0.3490658f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_DashSwitch_P_PressAMirror = {0xFFDCE304, 0xFFFBFFAF, PC_BLINK, PF_NONE, PR_NONE, 0, 1.0f, 0.0f, 60.0f, 80.0f, 0.2f, 0.8f, 1.2f, 0.0f, 0.6981317f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_DashSwitch_P_PressBMirror = {0xFFDCE304, 0xFFFBFFAF, PC_BLINK, PF_NONE, PR_NONE, 0, 1.0f, 0.0f, 100.0f, 110.0f, 0.2f, 0.8f, 1.2f, 0.0f, 0.3490658f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_FallingBlock_P_FallDustA = {0xFFFFFFFF, 0xFFFFFFFF, PC_STATIC, PF_NONE, PR_RANDOM, 1, 0.7f, 0.2f, 5.0f, 15.0f, 1.0f, 0.3f, 0.5f, 1.570796f, 0.5f, 0.0f, 0.0f, 0, {0.0f, 4.0f}, 0.0f, {T_particles_smoke0, T_particles_smoke1, T_particles_smoke2, T_particles_smoke3}, 4, 1};+const PType P_FallingBlock_P_FallDustB = {0xFFFFFFFF, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 5.0f, 25.0f, 1.0f, 0.8f, 1.0f, 1.570796f, 0.0f, 0.0f, 0.0f, 0, {0.0f, 20.0f}, 0.0f, {0}, 0, 0};+const PType P_FallingBlock_P_LandDust = {0xFFFFFFFF, 0xFFFFFFFF, PC_STATIC, PF_NONE, PR_RANDOM, 1, 0.7f, 0.2f, 40.0f, 50.0f, 0.6f, 0.6f, 0.8f, 1.570796f, 0.1745329f, 0.0f, 0.0f, 0, {-0.0f, -30.0f}, 0.0f, {T_particles_smoke0, T_particles_smoke1, T_particles_smoke2, T_particles_smoke3}, 4, 1};+const PType P_LockBlock_P_Appear = {0xFFFF3D63, 0xFFFF75DE, PC_BLINK, PF_NONE, PR_NONE, 0, 1.0f, 0.0f, 30.0f, 70.0f, 0.6f, 0.4f, 1.2f, 0.0f, 0.4363323f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_SwitchGate_P_Behind = {0xFFFFEB6B, 0xFFD39332, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 5.0f, 10.0f, 1.0f, 1.0f, 1.5f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 6.0f}, 0.0f, {0}, 0, 0};+const PType P_SwitchGate_P_Dust = {0xFFFFFFFF, 0xFFFFFFFF, PC_STATIC, PF_NONE, PR_RANDOM, 1, 0.7f, 0.2f, 2.0f, 4.0f, 1.0f, 0.5f, 1.0f, 1.570796f, 0.5f, 0.0f, 0.0f, 0, {0.0f, 4.0f}, 0.0f, {T_particles_smoke0, T_particles_smoke1, T_particles_smoke2, T_particles_smoke3}, 4, 1};+const PType P_CrumblePlatform_P_Crumble = {0xFF847E87, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 5.0f, 25.0f, 1.0f, 0.8f, 1.0f, 1.570796f, 0.0f, 0.0f, 0.0f, 0, {0.0f, 20.0f}, 0.0f, {0}, 0, 0};+const PType P_ZipMover_P_Scrape = {0xFFFFFFFF, 0xFFFFFFFF, PC_STATIC, PF_NONE, PR_RANDOM, 1, 0.7f, 0.2f, 5.0f, 15.0f, 1.0f, 0.3f, 0.1f, 1.570796f, 0.5f, 0.0f, 0.0f, 0, {0.0f, 4.0f}, 0.0f, {T_particles_smoke0, T_particles_smoke1, T_particles_smoke2, T_particles_smoke3}, 4, 1};+const PType P_ZipMover_P_Sparks = {0xFFFFF538, 0xFFFFFFFF, PC_STATIC, PF_NONE, PR_NONE, 0, 1.0f, 0.0f, 15.0f, 20.0f, 1.0f, 0.15f, 0.25f, 0.0f, 1.396263f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_NPC01_Theo_P_YOLO = {0xFF8EED80, 0xFF37946E, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 10.0f, 20.0f, 1.0f, 0.3f, 0.6f, -1.570796f, 0.7853982f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_ClutterSwitch_P_Pressed = {0xFFFFFFFF, 0xFF00FFFF, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 30.0f, 60.0f, 0.2f, 0.8f, 1.2f, -1.570796f, 0.7853982f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_ClutterSwitch_P_ClutterFly = {0xFFFFFFFF, 0xFF00FFFF, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 10.0f, 20.0f, 0.1f, 0.8f, 1.2f, -1.570796f, 0.7853982f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_BadelineOldsite_P_Vanish = {0xFF6F2399, 0xFFEC76F7, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 5.0f, 10.0f, 0.3f, 0.6f, 1.2f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_DreamMirror_P_Shatter = {0xFFBDEFF9, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_RANDOM, 0, 1.0f, 0.0f, 110.0f, 130.0f, 0.05f, 0.4f, 0.8f, 4.712389f, 0.8726646f, 1.570796f, 4.712389f, 1, {0.0f, 40.0f}, 0.0f, {T_particles_triangle}, 1, 0};+const PType P_NPC03_Oshiro_Lobby_P_AppearSpark = {0xFF5FCDE4, 0xFFFFFFFF, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 40.0f, 60.0f, 0.1f, 0.4f, 0.8f, 0.0f, 0.0f, 0.0f, 0.0f, 0, {0.0f, 10.0f}, 0.0f, {0}, 0, 0};+const PType P_DustStaticSpinner_P_Move = {0xFF000000, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_RANDOM, 0, 0.5f, 0.2f, 5.0f, 10.0f, 1.0f, 0.4f, 0.8f, 0.0f, 6.283185f, 0.6981317f, 1.396263f, 1, {0.0f, 0.0f}, 0.0f, {T_particles_smoke0, T_particles_smoke1, T_particles_smoke2, T_particles_smoke3}, 4, 0};+const PType P_BladeTrackSpinner_P_Trail = {0xFF696A6A, 0xFF700808, PC_CHOOSE, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 4.0f, 8.0f, 0.8f, 0.3f, 0.6f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_StrawberrySeed_P_Burst = {0xFFFFFFFF, 0xFFFFFFFF, PC_FADE, PF_NONE, PR_SAMEASDIR, 1, 0.8f, 0.3f, 100.0f, 140.0f, 1e-05f, 0.3f, 0.4f, 0.0f, 0.0f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {T_particles_shatter}, 1, 0};+const PType P_SummitGem_P_Shatter = {0xFFFFFFFF, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_RANDOM, 0, 1.0f, 0.0f, 140.0f, 210.0f, 0.005f, 0.25f, 0.4f, 4.712389f, 0.8726646f, 1.570796f, 4.712389f, 1, {0.0f, 0.0f}, 0.0f, {T_particles_triangle}, 1, 0};+const PType P_Payphone_P_Snow = {0xFFFFFFFF, 0xFFFFFFFF, PC_STATIC, PF_NONE, PR_RANDOM, 1, 0.7f, 0.2f, 20.0f, 36.0f, 1.0f, 1.0f, 1.6f, -1.570796f, 0.5f, 0.0f, 0.0f, 0, {0.0f, 12.0f}, 0.0f, {T_particles_smoke0, T_particles_smoke1, T_particles_smoke2, T_particles_smoke3}, 4, 1};+const PType P_Payphone_P_SnowB = {0xFFFFFFFF, 0xFFFFFFFF, PC_STATIC, PF_NONE, PR_RANDOM, 1, 0.7f, 0.2f, 8.0f, 18.0f, 1.0f, 1.0f, 1.6f, -1.570796f, 0.5f, 0.0f, 0.0f, 0, {0.0f, 12.0f}, 0.0f, {T_particles_smoke0, T_particles_smoke1, T_particles_smoke2, T_particles_smoke3}, 4, 1};+const PType P_TempleMirrorPortal_P_CurtainDrop = {0xFFFF0000, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 5.0f, 10.0f, 1.0f, 0.6f, 2.0f, -1.570796f, 0.7853982f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_LightBeam_P_Glow = {0x66FAF8DC, 0xFFFFFFFF, PC_STATIC, PF_INOUT, PR_SAMEASDIR, 0, 1.0f, 0.0f, 16.0f, 20.0f, 1.0f, 1.4f, 2.8f, 0.0f, 0.0f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {T_particles_rect}, 1, 0};+const PType P_BadelineBoost_P_Move = {0xFFFFFFFF, 0xFFE0A8D8, PC_BLINK, PF_LATE, PR_RANDOM, 0, 0.8f, 0.4f, 20.0f, 40.0f, 0.2f, 0.4f, 0.6f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {T_particles_shard}, 1, 0};+const PType P_BadelineBoost_P_Ambience = {0xFFF78AE7, 0xFFFFCCF7, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 20.0f, 40.0f, 0.2f, 0.6f, 1.0f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_FlyFeather_P_Collect = {0xFFF2EB6D, 0xFFFFF200, PC_BLINK, PF_LATE, PR_RANDOM, 0, 1.0f, 0.0f, 60.0f, 70.0f, 0.1f, 0.6f, 0.9f, 0.0f, 6.283185f, 0.5235988f, 1.396263f, 1, {0.0f, 0.0f}, 0.0f, {T_particles_feather}, 1, 0};+const PType P_FlyFeather_P_Boost = {0xFFF2EB6D, 0xFFFFF200, PC_BLINK, PF_LATE, PR_RANDOM, 0, 1.0f, 0.0f, 20.0f, 80.0f, 0.2f, 0.6f, 0.9f, 0.0f, 1.396263f, 0.5235988f, 1.396263f, 1, {0.0f, 0.0f}, 0.0f, {T_particles_feather}, 1, 0};+const PType P_FlyFeather_P_Flying = {0xFFF2EB6D, 0xFFFFF200, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 60.0f, 70.0f, 0.25f, 0.4f, 0.8f, 0.0f, 1.047198f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_FlyFeather_P_Respawn = {0xFFFFDCA4, 0xFFFFE95E, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 30.0f, 40.0f, 0.2f, 0.4f, 0.6f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_CrushBlock_P_Impact = {0xFFFFFFFF, 0xFFFFFFFF, PC_STATIC, PF_NONE, PR_RANDOM, 1, 1.2f, 0.5f, 8.0f, 12.0f, 1.0f, 0.8f, 1.6f, 1.570796f, 0.5f, 0.0f, 0.0f, 0, {0.0f, 4.0f}, 0.0f, {T_particles_smoke0, T_particles_smoke1, T_particles_smoke2, T_particles_smoke3}, 4, 1};+const PType P_CrushBlock_P_Crushing = {0xFFFF66E2, 0xFF68FCFF, PC_BLINK, PF_LATE, PR_SAMEASDIR, 0, 0.5f, 0.2f, 30.0f, 50.0f, 0.4f, 0.5f, 1.2f, 0.0f, 0.5235988f, 0.0f, 0.0f, 0, {0.0f, 10.0f}, 0.0f, {T_particles_rect}, 1, 0};+const PType P_CrushBlock_P_Activate = {0xFF5FCDE4, 0xFFFFFFFF, PC_BLINK, PF_LATE, PR_SAMEASDIR, 0, 0.5f, 0.2f, 60.0f, 100.0f, 0.2f, 0.5f, 1.1f, 0.0f, 0.5235988f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {T_particles_rect}, 1, 0};+const PType P_Bumper_P_Ambience = {0xFF47B5CC, 0xFFC4F4FF, PC_BLINK, PF_INOUT, PR_SAMEASDIR, 0, 0.5f, 0.2f, 10.0f, 20.0f, 1.0f, 0.2f, 0.4f, 0.0f, 0.5235988f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {T_particles_rect}, 1, 0};+const PType P_Bumper_P_FireAmbience = {0xFFFFA808, 0xFFC4F4FF, PC_STATIC, PF_INOUT, PR_SAMEASDIR, 0, 0.5f, 0.2f, 10.0f, 20.0f, 1.0f, 0.3f, 0.6f, 0.0f, 0.8726646f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {T_particles_rect}, 1, 0};+const PType P_Bumper_P_Launch = {0xFF47B5CC, 0xFFC4F4FF, PC_BLINK, PF_LATE, PR_RANDOM, 0, 0.5f, 0.2f, 40.0f, 140.0f, 0.1f, 0.6f, 1.2f, 0.0f, 0.6981317f, 0.0f, 0.0f, 0, {0.0f, 10.0f}, 0.0f, {T_particles_rect}, 1, 0};+const PType P_Bumper_P_FireHit = {0xFFFFA808, 0xFFC4F4FF, PC_STATIC, PF_LATE, PR_RANDOM, 0, 0.5f, 0.2f, 30.0f, 100.0f, 0.1f, 0.8f, 1.6f, 0.0f, 1.396263f, 0.0f, 0.0f, 0, {0.0f, -40.0f}, 0.0f, {T_particles_rect}, 1, 0};+const PType P_SwapBlock_P_Move = {0xFFFBF236, 0xFF6ABE30, PC_BLINK, PF_NONE, PR_NONE, 0, 1.0f, 0.0f, 10.0f, 20.0f, 0.3f, 0.3f, 0.5f, 0.0f, 0.6981317f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_MoveBlock_P_Activate = {0xFF000000, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 20.0f, 40.0f, 0.25f, 0.4f, 0.6f, 0.0f, 0.3490658f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_MoveBlock_P_Break = {0xFF000000, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 20.0f, 40.0f, 0.25f, 0.4f, 0.6f, 0.0f, 0.3490658f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_MoveBlock_P_Move = {0xFF000000, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 20.0f, 40.0f, 0.25f, 0.4f, 0.6f, 0.0f, 0.3490658f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_Seeker_P_BreakOut = {0xFF643E73, 0xFF3E2854, PC_CHOOSE, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 10.0f, 30.0f, 1.0f, 0.3f, 0.6f, 0.0f, 1.396263f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_Seeker_P_Attack = {0xFF99E550, 0xFFDDFFBC, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 20.0f, 40.0f, 0.4f, 0.6f, 1.2f, 0.0f, 1.745329f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_Seeker_P_Stomp = {0xFF99E550, 0xFFDDFFBC, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 20.0f, 40.0f, 0.4f, 0.6f, 1.2f, -1.570796f, 1.745329f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_Seeker_P_HitWall = {0xFF99E550, 0xFFDDFFBC, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 30.0f, 60.0f, 0.4f, 0.6f, 1.2f, 0.0f, 1.745329f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_Seeker_P_Regen = {0xFFCBDBFC, 0xFF575FD9, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 20.0f, 100.0f, 0.4f, 0.4f, 1.2f, 0.0f, 1.047198f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_WaterInteraction_P_Drip = {0xCC87CDFA, 0xFFFFFFFF, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 10.0f, 12.0f, 2.0f, 0.4f, 0.8f, 1.570796f, 0.05f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_FireBarrier_P_Deactivate = {0xFFFF8933, 0xFFD01C01, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 5.0f, 25.0f, 1.0f, 0.3f, 0.8f, 0.0f, 0.5235988f, 0.0f, 0.0f, 0, {0.0f, -20.0f}, 0.0f, {0}, 0, 0};+const PType P_IceBlock_P_Deactivate = {0xFF33FFE7, 0xFF0151D0, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 5.0f, 25.0f, 1.0f, 0.3f, 0.8f, 0.0f, 0.5235988f, 0.0f, 0.0f, 0, {0.0f, 15.0f}, 0.0f, {0}, 0, 0};+const PType P_BounceBlock_P_Reform = {0xFFFFFFFF, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 20.0f, 50.0f, 0.1f, 0.4f, 0.8f, 0.0f, 0.5235988f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_BounceBlock_P_FireBreak = {0xFFFF8933, 0xFFD01C01, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 40.0f, 80.0f, 0.1f, 0.3f, 0.8f, 0.0f, 0.5235988f, 0.0f, 0.0f, 0, {0.0f, -20.0f}, 0.0f, {0}, 0, 0};+const PType P_BounceBlock_P_IceBreak = {0xFF33FFE7, 0xFF0151D0, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 5.0f, 25.0f, 1.0f, 0.3f, 0.8f, 0.0f, 0.5235988f, 0.0f, 0.0f, 0, {0.0f, 15.0f}, 0.0f, {0}, 0, 0};+const PType P_FireBall_P_IceBreak = {0xFF33FFE7, 0xFF0151D0, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 20.0f, 50.0f, 0.2f, 0.3f, 0.8f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 15.0f}, 0.0f, {0}, 0, 0};+const PType P_FireBall_P_FireTrail = {0xFFFF8933, 0xFFD01C01, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 4.0f, 8.0f, 1.0f, 0.6f, 1.2f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, -5.0f}, 0.0f, {0}, 0, 0};+const PType P_FireBall_P_IceTrail = {0xFF33FFE7, 0xFF0151D0, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 4.0f, 8.0f, 1.0f, 0.6f, 1.2f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 5.0f}, 0.0f, {0}, 0, 0};+const PType P_CrystalDebris_P_Dust = {0xFFFFFFFF, 0xFFFF77A8, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 2.0f, 8.0f, 1.0f, 0.25f, 0.6f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_FinalBossShot_P_Trail = {0xFFFFCED5, 0xFFFF4F7D, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 10.0f, 30.0f, 1.0f, 0.3f, 0.6f, 0.0f, 0.6981317f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_FinalBossBeam_P_Dissipate = {0xFFE60022, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 15.0f, 30.0f, 1.0f, 0.3f, 0.6f, 0.0f, 1.047198f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_FinalBossMovingBlock_P_Stop = {0xFFFFE0D3, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 40.0f, 100.0f, 0.1f, 0.5f, 1.2f, 0.0f, 0.6981317f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_FinalBossMovingBlock_P_Break = {0xFFFFE0D3, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 20.0f, 40.0f, 0.1f, 0.4f, 0.8f, 0.0f, 0.6981317f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_FinalBoss_P_Burst = {0xFFFF00B0, 0xFFFF84D9, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 40.0f, 100.0f, 0.2f, 0.4f, 0.8f, 0.0f, 1.047198f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_Cassette_P_Shine = {0xFF49AAF0, 0xFFF049BE, PC_BLINK, PF_INOUT, PR_NONE, 0, 1.0f, 0.0f, 5.0f, 10.0f, 1.0f, 0.6f, 1.0f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_TheoCrystal_P_Impact = {0xFFCBDBFC, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 10.0f, 20.0f, 0.1f, 0.3f, 0.8f, 0.0f, 1.745329f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_HeartGem_P_BlueShine = {0xFF5CAEFA, 0xFFFFFFFF, PC_BLINK, PF_INOUT, PR_NONE, 0, 1.0f, 0.0f, 5.0f, 10.0f, 1.0f, 0.6f, 1.0f, -1.570796f, 1.396263f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_HeartGem_P_RedShine = {0xFFFF2457, 0xFFFFFFFF, PC_BLINK, PF_INOUT, PR_NONE, 0, 1.0f, 0.0f, 5.0f, 10.0f, 1.0f, 0.6f, 1.0f, -1.570796f, 1.396263f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_HeartGem_P_GoldShine = {0xFFFFFC24, 0xFFFFFFFF, PC_BLINK, PF_INOUT, PR_NONE, 0, 1.0f, 0.0f, 5.0f, 10.0f, 1.0f, 0.6f, 1.0f, -1.570796f, 1.396263f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_HeartGem_P_FakeShine = {0xFFBEBDB8, 0xFFFFFFFF, PC_BLINK, PF_INOUT, PR_NONE, 0, 1.0f, 0.0f, 5.0f, 10.0f, 1.0f, 2.0f, 4.0f, 1.570796f, 0.3490658f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_HeartGemDoor_P_Slice = {0xFFFFFFFF, 0xA5FFFFFF, PC_CHOOSE, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 0.0f, 30.0f, 1.0f, 0.4f, 1.8f, -1.570796f, 0.0f, 0.0f, 0.0f, 0, {0.0f, 20.0f}, 0.0f, {0}, 0, 0};+const PType P_Lightning_P_Shatter = {0xFFB9FEFE, 0xFFFFF263, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 5.0f, 30.0f, 1.0f, 0.8f, 2.0f, -1.570796f, 1.570796f, 0.0f, 0.0f, 0, {0.0f, 20.0f}, 0.0f, {0}, 0, 0};+const PType P_Glider_P_Glide = {0xFF4FFFF3, 0xFFFFF899, PC_BLINK, PF_LATE, PR_SAMEASDIR, 0, 0.5f, 0.2f, 30.0f, 40.0f, 1.0f, 0.6f, 1.2f, -1.570796f, 1.570796f, 0.0f, 0.0f, 0, {0.0f, 60.0f}, 0.0f, {T_particles_rect}, 1, 0};+const PType P_Glider_P_GlideUp = {0xFF4FFFF3, 0xFFFFF899, PC_BLINK, PF_LATE, PR_SAMEASDIR, 0, 0.5f, 0.2f, 50.0f, 60.0f, 1.0f, 0.6f, 1.2f, -1.570796f, 1.570796f, 0.0f, 0.0f, 0, {-0.0f, -10.0f}, 0.0f, {T_particles_rect}, 1, 0};+const PType P_Glider_P_Platform = {0xFFFFFFFF, 0xFFFFFFFF, PC_STATIC, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 5.0f, 20.0f, 1.0f, 0.6f, 1.4f, -1.570796f, 0.0f, 0.0f, 0.0f, 0, {0.0f, 60.0f}, 0.0f, {0}, 0, 0};+const PType P_Glider_P_Glow = {0xFFB7F3FF, 0xFFF4FDFF, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 8.0f, 16.0f, 1.0f, 0.4f, 0.8f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_Glider_P_Expand = {0xFFB7F3FF, 0xFFF4FDFF, PC_BLINK, PF_LATE, PR_NONE, 0, 1.0f, 0.0f, 40.0f, 80.0f, 0.2f, 0.6f, 1.2f, 0.0f, 2.356194f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {0}, 0, 0};+const PType P_LightningBreakerBox_P_Smash = {0xFFFFFC75, 0xFF6BFFFF, PC_BLINK, PF_LATE, PR_SAMEASDIR, 0, 0.5f, 0.2f, 50.0f, 150.0f, 0.2f, 0.6f, 1.2f, 0.0f, 0.6981317f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {T_particles_rect}, 1, 0};+const PType P_LightningBreakerBox_P_Sparks = {0xFFFFFC75, 0xFF6BFFFF, PC_BLINK, PF_LATE, PR_SAMEASDIR, 0, 0.4f, 0.1f, 30.0f, 40.0f, 0.8f, 0.1f, 0.2f, 0.0f, 6.283185f, 0.0f, 0.0f, 0, {0.0f, 0.0f}, 0.0f, {T_particles_rect}, 1, 0};diff --git a/games/celeste/src/ptypes.h b/games/celeste/src/ptypes.hnew file mode 100644index 00000000..392dcd7e--- /dev/null+++ b/games/celeste/src/ptypes.h@@ -0,0 +1,123 @@+/* Generated by tools/gen_particles.py from the game's ParticleTypes. */+#ifndef PTYPES_H+#define PTYPES_H+#include "fx.h"+extern const PType P_Dust;+extern const PType P_SparkyDust;+extern const PType P_Chimney;+extern const PType P_Steam;+extern const PType P_VentDust;+extern const PType P_Player_P_DashA;+extern const PType P_Player_P_DashB;+extern const PType P_Player_P_DashBadB;+extern const PType P_Player_P_CassetteFly;+extern const PType P_Player_P_Split;+extern const PType P_Player_P_SummitLandA;+extern const PType P_Player_P_SummitLandB;+extern const PType P_Player_P_SummitLandC;+extern const PType P_Torch_P_OnLight;+extern const PType P_Cloud_P_Cloud;+extern const PType P_Cloud_P_FragileCloud;+extern const PType P_Booster_P_Burst;+extern const PType P_Booster_P_BurstRed;+extern const PType P_Booster_P_Appear;+extern const PType P_Booster_P_RedAppear;+extern const PType P_TouchSwitch_P_Fire;+extern const PType P_TouchSwitch_P_FireWhite;+extern const PType P_Water_P_Splash;+extern const PType P_Strawberry_P_Glow;+extern const PType P_Strawberry_P_GhostGlow;+extern const PType P_Strawberry_P_GoldGlow;+extern const PType P_Strawberry_P_MoonGlow;+extern const PType P_Strawberry_P_WingsBurst;+extern const PType P_BirdNPC_P_Feather;+extern const PType P_FlingBird_P_Feather;+extern const PType P_Key_P_Shimmer;+extern const PType P_Key_P_Insert;+extern const PType P_Key_P_Collect;+extern const PType P_Refill_P_Shatter;+extern const PType P_Refill_P_Glow;+extern const PType P_Refill_P_Regen;+extern const PType P_Refill_P_ShatterTwo;+extern const PType P_Refill_P_GlowTwo;+extern const PType P_Refill_P_RegenTwo;+extern const PType P_DashSwitch_P_PressA;+extern const PType P_DashSwitch_P_PressB;+extern const PType P_DashSwitch_P_PressAMirror;+extern const PType P_DashSwitch_P_PressBMirror;+extern const PType P_FallingBlock_P_FallDustA;+extern const PType P_FallingBlock_P_FallDustB;+extern const PType P_FallingBlock_P_LandDust;+extern const PType P_LockBlock_P_Appear;+extern const PType P_SwitchGate_P_Behind;+extern const PType P_SwitchGate_P_Dust;+extern const PType P_CrumblePlatform_P_Crumble;+extern const PType P_ZipMover_P_Scrape;+extern const PType P_ZipMover_P_Sparks;+extern const PType P_NPC01_Theo_P_YOLO;+extern const PType P_ClutterSwitch_P_Pressed;+extern const PType P_ClutterSwitch_P_ClutterFly;+extern const PType P_BadelineOldsite_P_Vanish;+extern const PType P_DreamMirror_P_Shatter;+extern const PType P_NPC03_Oshiro_Lobby_P_AppearSpark;+extern const PType P_DustStaticSpinner_P_Move;+extern const PType P_BladeTrackSpinner_P_Trail;+extern const PType P_StrawberrySeed_P_Burst;+extern const PType P_SummitGem_P_Shatter;+extern const PType P_Payphone_P_Snow;+extern const PType P_Payphone_P_SnowB;+extern const PType P_TempleMirrorPortal_P_CurtainDrop;+extern const PType P_LightBeam_P_Glow;+extern const PType P_BadelineBoost_P_Move;+extern const PType P_BadelineBoost_P_Ambience;+extern const PType P_FlyFeather_P_Collect;+extern const PType P_FlyFeather_P_Boost;+extern const PType P_FlyFeather_P_Flying;+extern const PType P_FlyFeather_P_Respawn;+extern const PType P_CrushBlock_P_Impact;+extern const PType P_CrushBlock_P_Crushing;+extern const PType P_CrushBlock_P_Activate;+extern const PType P_Bumper_P_Ambience;+extern const PType P_Bumper_P_FireAmbience;+extern const PType P_Bumper_P_Launch;+extern const PType P_Bumper_P_FireHit;+extern const PType P_SwapBlock_P_Move;+extern const PType P_MoveBlock_P_Activate;+extern const PType P_MoveBlock_P_Break;+extern const PType P_MoveBlock_P_Move;+extern const PType P_Seeker_P_BreakOut;+extern const PType P_Seeker_P_Attack;+extern const PType P_Seeker_P_Stomp;+extern const PType P_Seeker_P_HitWall;+extern const PType P_Seeker_P_Regen;+extern const PType P_WaterInteraction_P_Drip;+extern const PType P_FireBarrier_P_Deactivate;+extern const PType P_IceBlock_P_Deactivate;+extern const PType P_BounceBlock_P_Reform;+extern const PType P_BounceBlock_P_FireBreak;+extern const PType P_BounceBlock_P_IceBreak;+extern const PType P_FireBall_P_IceBreak;+extern const PType P_FireBall_P_FireTrail;+extern const PType P_FireBall_P_IceTrail;+extern const PType P_CrystalDebris_P_Dust;+extern const PType P_FinalBossShot_P_Trail;+extern const PType P_FinalBossBeam_P_Dissipate;+extern const PType P_FinalBossMovingBlock_P_Stop;+extern const PType P_FinalBossMovingBlock_P_Break;+extern const PType P_FinalBoss_P_Burst;+extern const PType P_Cassette_P_Shine;+extern const PType P_TheoCrystal_P_Impact;+extern const PType P_HeartGem_P_BlueShine;+extern const PType P_HeartGem_P_RedShine;+extern const PType P_HeartGem_P_GoldShine;+extern const PType P_HeartGem_P_FakeShine;+extern const PType P_HeartGemDoor_P_Slice;+extern const PType P_Lightning_P_Shatter;+extern const PType P_Glider_P_Glide;+extern const PType P_Glider_P_GlideUp;+extern const PType P_Glider_P_Platform;+extern const PType P_Glider_P_Glow;+extern const PType P_Glider_P_Expand;+extern const PType P_LightningBreakerBox_P_Smash;+extern const PType P_LightningBreakerBox_P_Sparks;+#endifdiff --git a/games/celeste/src/res.c b/games/celeste/src/res.cnew file mode 100644index 00000000..4dc133b4--- /dev/null+++ b/games/celeste/src/res.c@@ -0,0 +1,618 @@+/* data.bin: sections, textures, palettes, and the texture cache.+ *+ * Textures are either "direct" (row RLE in flash, drawn from there) or+ * packed: LZMA streams of raw 8-bit pixels (see tools/pack.py), decoded+ * through a small ring buffer when a room needs them and kept in the cache as+ * row RLE (tile sheets stay raw: tiles are cut from them). */+#include "celeste.h"+#include "lzma/LzmaDec.h"++const uint8_t *cel_bin;++const uint8_t *section(int s) { return cel_bin + rd32(cel_bin + 4 + 4 * s); }++const char *str(uint16_t id) {+ const uint8_t *s = section(SEC_STRINGS);+ if (id >= rd32(s)) return "";+ return (const char *)s + rd32(s + 4 + 4 * id);+}++const uint16_t *pal_colors(uint16_t pal, int *n) {+ const uint8_t *s = section(SEC_PAL);+ const uint8_t *p = s + rd32(s + 4 + 4 * pal);+ if (n) *n = rd16(p) & 0x7FFF;+ return (const uint16_t *)(const void *)(p + 2);+}+const uint8_t *pal_alpha(uint16_t pal) {+ const uint8_t *s = section(SEC_PAL);+ const uint8_t *p = s + rd32(s + 4 + 4 * pal);+ return p + 2 + 2 * (rd16(p) & 0x7FFF);+}+bool pal_opaque(uint16_t pal) {+ const uint8_t *s = section(SEC_PAL);+ return rd16(s + rd32(s + 4 + 4 * pal)) >> 15;+}++/* ---------------------------------------------------------------- LZMA streams */+#define DICT_SIZE 8192+extern uint16_t g_strip[]; /* gfx.c: the ring buffer borrows the strip */+static CLzmaProb probs[1984 + 768]; /* NUM_BASE_PROBS + LZMA_LIT_SIZE << (lc + lp) */++static void pack_info(uint16_t p, const uint8_t **data, uint32_t *comp, uint32_t *raw) {+ const uint8_t *s = section(SEC_PACKS) + 4 + 12 * p;+ *data = section(SEC_BLOBS) + rd32(s);+ *comp = rd32(s + 4);+ *raw = rd32(s + 8);+}++/* decodes pack p from its start, giving bytes [from, to) to sink */+static void lz_run(uint16_t p, uint32_t from, uint32_t to, Sink sink, void *ctx) {+ const uint8_t *src;+ uint32_t comp, raw;+ pack_info(p, &src, &comp, &raw);+ if (to > raw) to = raw;+ CLzmaDec dec;+ memset(&dec, 0, sizeof dec);+ dec.prop.lc = 0, dec.prop.lp = 0, dec.prop.pb = 0, dec.prop.dicSize = DICT_SIZE;+ dec.probs = probs;+ dec.probs_1664 = probs + 1664;+ dec.numProbs = 1984 + 768;+ dec.dic = (Byte *)(void *)g_strip;+ dec.dicBufSize = DICT_SIZE;+ LzmaDec_Init(&dec);+ uint32_t pos = 0, in = 0;+ while (pos < to) {+ if (dec.dicPos == dec.dicBufSize) dec.dicPos = 0;+ SizeT start = dec.dicPos, inlen = comp - in;+ ELzmaStatus st;+ SizeT limit = dec.dicBufSize;+ if (limit - start > to - pos) limit = start + (to - pos);+ if (LzmaDec_DecodeToDic(&dec, limit, src + in, &inlen, LZMA_FINISH_ANY, &st) != SZ_OK) return;+ in += (uint32_t)inlen;+ uint32_t got = (uint32_t)(dec.dicPos - start);+ if (!got) return;+ /* the part of [pos, pos + got) inside [from, to) */+ uint32_t a = pos < from ? from : pos, b = pos + got;+ if (b > a) sink(dec.dic + start + (a - pos), b - a, ctx);+ pos += got;+ }+}++void res_stream(uint16_t pack, uint32_t off, uint32_t size, Sink sink, void *ctx) {+ lz_run(pack, off, off + size, sink, ctx);+}++/* ---------------------------------------------------------------- the cache */+#define CACHE_BYTES (46 * 1024)+#define HASH 512+typedef struct {+ uint16_t tex, pal;+ uint16_t w, h;+ int16_t ox, oy;+ uint16_t fw, fh;+ uint8_t fmt, mark; /* mark: wanted by the rooms now (marks_gen); 0: evicted */+ uint8_t scale, pad;+ uint16_t used; /* the frame it was last drawn */+ uint16_t bytes; /* data after this header */+} CEnt;+static uint32_t cent_map_bytes(const CEnt *e) { /* a TF_NIB texture's colors at the start of its data */+ return e->fmt & TF_NIB ? (1u + ((const uint8_t *)(e + 1))[0] + 1) & ~1u : 0;+}+static uint32_t cache_words[CACHE_BYTES / 4];+static uint32_t cache_limit = CACHE_BYTES; /* below the chapter's own memory (res_chapter_ram) */+#define cache ((uint8_t *)cache_words)+static uint32_t cache_top;+static uint16_t hash_tex[HASH];+static uint16_t hash_at[HASH]; /* offset / 4 */+static uint8_t marks_gen = 1;+uint16_t g_res_frame; /* gfx_begin counts frames: what was drawn this frame stays while drawing */+bool g_res_drawing; /* between gfx_begin and gfx_end */+bool g_res_can_load = true; /* false while drawing strips: the LZMA ring is the strip */+static bool load_one(uint16_t id);+static struct { uint16_t id, frame; } failed[8]; /* loads that found no room, lately */+static int nfailed;++static uint32_t tex_entry(uint16_t id) { return rd32(section(SEC_TEX) + 4 + 4 * id); }+int tex_half_extent(uint16_t id) {+ int v = section(SEC_TEXDIM)[id];+ return v == 255 ? 4096 : v * 2;+}++static int hash_find(uint16_t tex) {+ uint32_t h = (tex * 2654435761u) >> 23;+ for (int i = 0; i < HASH; i++) {+ uint32_t k = (h + i) & (HASH - 1);+ if (hash_tex[k] == 0xFFFF) return -1;+ if (hash_tex[k] == tex) return (int)k;+ }+ return -1;+}+static void hash_put(uint16_t tex, uint32_t at) {+ uint32_t h = (tex * 2654435761u) >> 23;+ for (int i = 0; i < HASH; i++) {+ uint32_t k = (h + i) & (HASH - 1);+ if (hash_tex[k] == 0xFFFF || hash_tex[k] == tex) {+ hash_tex[k] = tex;+ hash_at[k] = (uint16_t)(at / 4);+ return;+ }+ }+}+static void hash_rebuild(void) {+ memset(hash_tex, 0xFF, sizeof hash_tex);+ for (uint32_t at = 0; at < cache_top;) {+ CEnt *e = (CEnt *)(void *)(cache + at);+ hash_put(e->tex, at);+ at += (sizeof(CEnt) + e->bytes + 3) & ~3u;+ }+}++void res_init(void) {+ cache_top = 0;+ hash_rebuild();+}++bool tex_get(uint16_t id, Tex *t) {+ if (id >= rd16(section(SEC_TEX))) return false; /* none (0xFFFF) */+ uint32_t e = tex_entry(id);+ if (e == 0xFFFFFFFF) return false; /* not in this data */+ if (e >> 30 == 1) {+ const uint8_t *p = section(SEC_DIRECT) + (e & 0x3FFFFFFF);+ t->w = rd16(p), t->h = rd16(p + 2);+ t->ox = rds16(p + 4), t->oy = rds16(p + 6);+ t->fw = rd16(p + 8), t->fh = rd16(p + 10);+ t->pal = rd16(p + 12);+ t->fmt = p[14];+ t->scale = p[15];+ t->px = p + 20;+ t->map = NULL;+ if (t->fmt & TF_NIB) t->map = t->px, t->px += 1 + t->map[0];+ if (t->fmt & TF_SHARED) t->px = section(SEC_DIRECT) + rd32(t->px), t->fmt &= ~TF_SHARED; /* another's pixels */+ else if ((t->fmt & TF_NIB) && !(t->fmt & TF_ROW8) && ((1 + t->map[0]) & 1)) t->px++;+ return true;+ }+ int k = hash_find(id);+ if (k < 0) { /* not loaded: now, if it can be (not again for a while when it could not: no room) */+ for (int i = 0; i < 8; i++)+ if (failed[i].id == id && (uint16_t)(g_res_frame - failed[i].frame) < 30) return false;+ if (!g_res_can_load) return false;+ if (!load_one(id) || (k = hash_find(id)) < 0) {+ failed[nfailed].id = id, failed[nfailed].frame = g_res_frame;+ nfailed = (nfailed + 1) & 7;+ return false;+ }+ }+ CEnt *c = (CEnt *)(void *)(cache + hash_at[k] * 4);+ c->used = g_res_frame;+ t->w = c->w, t->h = c->h, t->ox = c->ox, t->oy = c->oy, t->fw = c->fw, t->fh = c->fh;+ t->pal = c->pal, t->fmt = c->fmt;+ t->scale = c->scale ? c->scale : 1;+ t->px = (const uint8_t *)(c + 1);+ t->map = NULL;+ if (c->fmt & TF_NIB) t->map = t->px, t->px += cent_map_bytes(c);+ return true;+}++/* ---------------------------------------------------------------- what rooms need */+#define MAX_MISSING 512+static uint16_t missing[MAX_MISSING];+static int nmissing;++void res_begin_need(void) {+ marks_gen++;+ if (marks_gen < 2) marks_gen = 2; /* 0: evicted, 1: loaded, not wanted */+ nmissing = 0;+}++void res_need(uint16_t id) {+ if (id >= rd16(section(SEC_TEX))) return;+ uint32_t e = tex_entry(id);+ if (e >> 30 == 1 || e == 0xFFFFFFFF) return;+ int k = hash_find(id);+ if (k >= 0) {+ ((CEnt *)(void *)(cache + hash_at[k] * 4))->mark = marks_gen;+ return;+ }+ for (int i = 0; i < nmissing; i++)+ if (missing[i] == id) return;+ if (nmissing < MAX_MISSING) missing[nmissing++] = id;+}++void res_need_list(const uint8_t *ids, int n) {+ for (int i = 0; i < n; i++) res_need(rd16(ids + 2 * i));+}++/* slides the entries still alive (mark != 0) down to the bottom */+uint16_t g_res_gen; /* changes whenever textures can move in the cache (drawing's row lookups start over) */+static void compact(void) {+ uint32_t dst = 0;+ g_res_gen++;+ for (uint32_t at = 0; at < cache_top;) {+ CEnt *e = (CEnt *)(void *)(cache + at);+ uint32_t size = (sizeof(CEnt) + e->bytes + 3) & ~3u;+ if (e->mark) {+ if (dst != at) memmove(cache + dst, cache + at, size);+ dst += size;+ }+ at += size;+ }+ cache_top = dst;+ hash_rebuild();+}++/* frees `need` bytes at the top: what was drawn longest ago goes first (what the rooms want gets 8 frames more), never+ * what was drawn this frame; false if that is not enough */+static bool make_room_ex(uint32_t need, bool force) {+ if (cache_top + need <= cache_limit) return true;+ uint32_t freed = 0, want = cache_top + need - cache_limit;+ while (freed < want) {+ CEnt *old = NULL;+ uint32_t oldest = 0;+ for (uint32_t at = 0; at < cache_top;) {+ CEnt *e = (CEnt *)(void *)(cache + at);+ at += (sizeof(CEnt) + e->bytes + 3) & ~3u;+ /* what this frame draws stays while it is drawn, unless a tile sheet needs the room */+ if (!e->mark || (g_res_drawing && e->used == g_res_frame && (!force || e->fmt == TF_RAW4))) continue;+ uint32_t age = (uint32_t)(uint16_t)(g_res_frame - e->used) * 2u + (e->mark == marks_gen ? 0 : 17u);+ if (!old || age > oldest) old = e, oldest = age;+ }+ if (!old) break;+ old->mark = 0;+ freed += (sizeof(CEnt) + old->bytes + 3) & ~3u;+ }+ compact();+ return cache_top + need <= cache_limit;+}+static bool make_room(uint32_t need) { return make_room_ex(need, false); }++/* RLE of one row of 8-bit pixels (see tools/pack.py rle()); nib: literals two a byte (local colors, TF_NIB) */+static uint32_t rle_row(const uint8_t *row, int w, uint8_t *out, bool nib) {+ int end = w;+ while (end > 0 && !row[end - 1]) end--;+ uint8_t *o = out;+ int x = 0;+ while (x < end) {+ uint8_t v = row[x];+ int n = 1;+ while (x + n < end && row[x + n] == v) n++;+ if (!v) {+ while (n > 0) {+ int k = n < 64 ? n : 64;+ *o++ = (uint8_t)(k - 1);+ n -= k, x += k;+ }+ continue;+ }+ if (n >= 3) {+ while (n >= 3) {+ int k = n < 64 ? n : 64;+ *o++ = (uint8_t)(0x40 + k - 1);+ *o++ = v;+ n -= k, x += k;+ }+ continue;+ }+ int s = x;+ while (x < end && x - s < 128) {+ uint8_t u = row[x];+ int m = 1;+ while (x + m < end && row[x + m] == u) m++;+ if (!u || m >= 3) break;+ x += m < 128 - (x - s) ? m : 128 - (x - s);+ }+ *o++ = (uint8_t)(0x80 + (x - s) - 1);+ if (nib)+ for (int i = s; i < x; i += 2) *o++ = (uint8_t)(row[i] | (i + 1 < x ? row[i + 1] << 4 : 0));+ else+ for (int i = s; i < x; i++) *o++ = row[i];+ }+ return (uint32_t)(o - out);+}++/* the texture being read out of a pack stream */+typedef struct {+ uint32_t pos; /* stream position of the next byte */+ int cur; /* index into the wanted list */+ int n;+ const uint16_t *want; /* texture ids, by increasing offset */+ uint8_t hdr[20 + 16]; /* the header, then a TF_NIB texture's colors (count, then their indices) */+ int hdr_n;+ CEnt *e;+ uint32_t px_n; /* pixels received */+ uint8_t row[1024];+ int row_n;+ uint8_t *out;+ bool skip; /* not enough room: drop it */+ uint8_t mark; /* what the loaded entries are marked */+ bool soft; /* all but `hard` only if there is room for them as it is */+ uint16_t hard;+} Reader;++static uint32_t entry_offset(uint16_t id) { return tex_entry(id) & 0x3FFFF; }++#ifdef HOST+#include <stdio.h>+#include <stdlib.h>+#endif+static void finish_tex(Reader *r) {+#ifdef HOST+ if (getenv("RESDEBUG")) printf("tex %d %dx%d %s %u bytes (top %u)\n", r->want[r->cur], rd16(r->hdr), rd16(r->hdr + 2),+ r->skip ? "SKIPPED" : "", r->e ? (unsigned)r->e->bytes : 0, (unsigned)cache_top);+#endif+ if (!r->skip && r->e) {+ CEnt *e = r->e;+ if (e->fmt != TF_RAW4) {+ uint8_t *data = (uint8_t *)(e + 1);+ uint32_t ms = cent_map_bytes(e);+ uint16_t *rows = (uint16_t *)(void *)(data + ms);+ rows[e->h] = (uint16_t)(r->out - (uint8_t *)rows);+ e->bytes = (uint16_t)(r->out - data);+ /* rows all shorter than 256 bytes: a byte each for their lengths (TF_ROW8) */+ bool small = true;+ for (int y = 0; y < e->h && small; y++) small = rows[y + 1] - rows[y] < 256;+ if (small) {+ uint8_t *lens = (uint8_t *)rows;+ uint32_t ops = 2u * (e->h + 1), n = rows[e->h] - ops;+ for (int y = 0; y < e->h; y++) lens[y] = (uint8_t)(rows[y + 1] - rows[y]);+ memmove(lens + e->h, (uint8_t *)rows + ops, n);+ e->bytes = (uint16_t)(ms + e->h + n);+ e->fmt |= TF_ROW8;+ }+ }+ e->mark = r->mark;+ e->used = g_res_frame;+ hash_put(e->tex, (uint32_t)((uint8_t *)e - cache));+ cache_top += (sizeof(CEnt) + e->bytes + 3) & ~3u;+ }+ g_res_gen++;+ r->e = NULL;+ r->cur++;+ r->hdr_n = 0;+ r->px_n = 0;+ r->row_n = 0;+}++static void start_tex(Reader *r) {+ uint16_t id = r->want[r->cur];+ const uint8_t *h = r->hdr;+ uint16_t w = rd16(h), hh = rd16(h + 2);+ uint8_t fmt = h[14] == 2 ? TF_RAW4 : (h[14] & TF_NIB);+ uint32_t ms = fmt & TF_NIB ? (1u + h[20] + 1) & ~1u : 0; /* the colors, kept even (the row table) */+ uint32_t need = rd32(h + 16) + (fmt != TF_RAW4 ? 2 * (hh + 1u) + ms : 0);+ bool soft = r->soft && r->want[r->cur] != r->hard; /* an animation's other frames: only into free room */+ r->skip = soft ? cache_top + sizeof(CEnt) + need + 4 > cache_limit : !make_room_ex(sizeof(CEnt) + need + 4, fmt == TF_RAW4);+ r->e = NULL;+ if (r->skip) return;+ CEnt *e = (CEnt *)(void *)(cache + cache_top);+ e->tex = id, e->w = w, e->h = hh;+ e->ox = rds16(h + 4), e->oy = rds16(h + 6), e->fw = rd16(h + 8), e->fh = rd16(h + 10), e->pal = rd16(h + 12);+ e->fmt = fmt;+ e->scale = h[15];+ e->bytes = (uint16_t)(fmt == TF_RAW4 ? ((uint32_t)w * hh + 1) / 2 : 0);+ r->e = e;+ if (ms) memcpy(e + 1, h + 20, 1u + h[20]);+ r->out = (uint8_t *)(e + 1) + (fmt != TF_RAW4 ? ms + 2 * (hh + 1) : 0);+}++static void reader_sink(const uint8_t *p, uint32_t n, void *ctx) {+ Reader *r = ctx;+ while (n && r->cur < r->n) {+ uint32_t at = entry_offset(r->want[r->cur]);+#ifdef HOST+ if (r->pos > at && r->hdr_n == 0) { /* (the list goes by offset: never past one) */+ fprintf(stderr, "res: texture %d at %u read from %u\n", r->want[r->cur], (unsigned)at, (unsigned)r->pos);+ abort();+ }+#endif+ if (r->pos < at) { /* skip to the next wanted texture */+ uint32_t k = at - r->pos;+ if (k > n) k = n;+ p += k, n -= k, r->pos += k;+ continue;+ }+ int hn = 20;+ if (r->hdr_n >= 20 && (r->hdr[14] & TF_NIB)) hn = r->hdr_n > 20 ? 21 + r->hdr[20] : 21;+ if (r->hdr_n < hn) {+ r->hdr[r->hdr_n++] = *p++;+ n--, r->pos++;+ int done = r->hdr_n < 20 ? 0 : !(r->hdr[14] & TF_NIB) ? 20 : r->hdr_n > 20 ? 21 + r->hdr[20] : 0;+ if (r->hdr_n == done) {+ start_tex(r);+ if (rd16(r->hdr) * rd16(r->hdr + 2) == 0) finish_tex(r);+ }+ continue;+ }+ uint16_t w = rd16(r->hdr), h = rd16(r->hdr + 2);+ uint32_t total = (uint32_t)w * h;+ uint32_t k = total - r->px_n;+ if (k > n) k = n;+ if (r->e && !r->skip) {+ CEnt *e = r->e;+ if (e->fmt == TF_RAW4) {+ uint8_t *dst = (uint8_t *)(e + 1);+ for (uint32_t i = 0; i < k; i++) {+ uint32_t at = r->px_n + i;+ if (at & 1) dst[at >> 1] |= (uint8_t)(p[i] << 4);+ else dst[at >> 1] = p[i] & 15;+ }+ } else {+ uint16_t *rows = (uint16_t *)(void *)((uint8_t *)(e + 1) + cent_map_bytes(e));+ for (uint32_t i = 0; i < k; i++) {+ if (r->row_n < (int)sizeof r->row) r->row[r->row_n] = p[i];+ r->row_n++;+ if (r->row_n == w) {+ int y = (int)((r->px_n + i) / w);+ rows[y] = (uint16_t)(r->out - (uint8_t *)rows);+ r->out += rle_row(r->row, w < (int)sizeof r->row ? w : (int)sizeof r->row, r->out, (e->fmt & TF_NIB) != 0);+ r->row_n = 0;+ }+ }+ }+ }+ r->px_n += k;+ p += k, n -= k, r->pos += k;+ if (r->px_n == total) finish_tex(r);+ }+ r->pos += n;+}++static int cmp_offset(const void *a, const void *b) { /* by pack, then offset (not by kind: tile sheets are in packs too) */+ uint32_t x = tex_entry(*(const uint16_t *)a) & 0x3FFFFFFF, y = tex_entry(*(const uint16_t *)b) & 0x3FFFFFFF;+ return x < y ? -1 : x > y;+}++/* loads the textures in `ids` (by pack, then offset: one pass over each pack), marked `mark` */+static void load_list_ex(uint16_t *ids, int n, uint8_t mark, int hard);+static void load_list(uint16_t *ids, int n, uint8_t mark) { load_list_ex(ids, n, mark, -1); }+static void load_list_ex(uint16_t *ids, int n, uint8_t mark, int hard) {+ for (int i = 1; i < n; i++)+ for (int j = i; j > 0 && cmp_offset(&ids[j - 1], &ids[j]) > 0; j--) {+ uint16_t t = ids[j];+ ids[j] = ids[j - 1];+ ids[j - 1] = t;+ }+ int i = 0;+ while (i < n) {+ uint32_t pack = (tex_entry(ids[i]) >> 18) & 0xFFF;+ int j = i;+ while (j < n && ((tex_entry(ids[j]) >> 18) & 0xFFF) == pack) j++;+ Reader rd;+ memset(&rd, 0, sizeof rd);+ rd.want = ids + i;+ rd.n = j - i;+ rd.mark = mark;+ rd.soft = hard >= 0, rd.hard = (uint16_t)hard;+ uint32_t last = entry_offset(ids[j - 1]);+ lz_run((uint16_t)pack, 0, last + 20 + 4096u * 4096u, reader_sink, &rd);+ i = j;+ }+}++/* what the rooms want: what was wanted before and is not now can go when room is needed */+void res_load_needed(void) {+ /* the old marks: just evictable now (1 is never a current marks_gen: see res_begin_need) */+ for (uint32_t at = 0; at < cache_top;) {+ CEnt *e = (CEnt *)(void *)(cache + at);+ if (e->mark && e->mark != marks_gen) e->mark = 1;+ at += (sizeof(CEnt) + e->bytes + 3) & ~3u;+ }+ if (nmissing) load_list(missing, nmissing, marks_gen);+ nmissing = 0;+}++/* a texture being drawn that is not loaded */+static bool load_one(uint16_t id) {+ uint32_t e = tex_entry(id);+ if (e >> 30 == 1 || e == 0xFFFFFFFF) return false;+ uint16_t one = id;+ load_list(&one, 1, 1);+ return hash_find(id) >= 0;+}+/* several (an animation's frames), in one pass: `hard` surely (if it can be), the others if there is+ * room for them without making any */+void res_load_frames(const uint16_t *ids, int n, uint16_t hard) {+ uint16_t todo[32];+ int k = 0;+ for (int i = 0; i < n && k < 32; i++) {+ if (ids[i] >= rd16(section(SEC_TEX))) continue;+ uint32_t e = tex_entry(ids[i]);+ if (e >> 30 == 1 || e == 0xFFFFFFFF || hash_find(ids[i]) >= 0) continue;+ bool dup = false;+ for (int j = 0; j < k; j++) dup |= todo[j] == ids[i];+ if (!dup) todo[k++] = ids[i];+ }+ if (k && g_res_can_load) load_list_ex(todo, k, 1, hard);+}+void res_load(const uint16_t *ids, int n) {+ uint16_t todo[32];+ int k = 0;+ for (int i = 0; i < n && k < 32; i++) {+ if (ids[i] >= rd16(section(SEC_TEX))) continue;+ uint32_t e = tex_entry(ids[i]);+ if (e >> 30 == 1 || e == 0xFFFFFFFF || hash_find(ids[i]) >= 0) continue;+ bool dup = false;+ for (int j = 0; j < k; j++) dup |= todo[j] == ids[i];+ if (!dup) todo[k++] = ids[i];+ }+ if (k && g_res_can_load) load_list(todo, k, 1);+}+#ifdef HOST+/* CACHEWS=1: the bytes of what the frame drew from the cache, and what is in it */+void res_debug_working_set(void) {+ if (!getenv("CACHEWS")) return;+ uint32_t drawn = 0, all = 0;+ int n = 0;+ char list[600];+ int k = 0;+ for (uint32_t at = 0; at < cache_top;) {+ CEnt *e = (CEnt *)(void *)(cache + at);+ uint32_t size = (sizeof(CEnt) + e->bytes + 3) & ~3u;+ all += size;+ if (e->mark && e->used == g_res_frame) {+ drawn += size, n++;+ if (k < 560) k += snprintf(list + k, sizeof list - k, " %d:%u", e->tex, (unsigned)size);+ }+ at += size;+ }+ list[k] = 0;+ printf("ws frame %u drawn %u in %d, cache %u of %u:%s\n", (unsigned)g_res_frame, (unsigned)drawn, n, (unsigned)all,+ (unsigned)cache_limit, list);+}+#endif+bool res_cached(uint16_t id) {+ if (id >= rd16(section(SEC_TEX))) return true;+ uint32_t e = tex_entry(id);+ return e >> 30 == 1 || hash_find(id) >= 0;+}++/* free memory at the top of the cache for something passing (a room being read, a dialog): at least+ * `need` bytes if it can be made */+uint8_t *res_scratch(uint32_t need, uint32_t *size) {+ make_room(need);+ *size = cache_limit - cache_top;+ return cache + cache_top;+}++/* a chapter's own tables (its pools of torches, clutter...) take the top of the cache while it is played:+ * `bytes` of zeroes, everything loaded before forgotten */+uint8_t *g_chapter_ram;+void res_chapter_ram(uint32_t bytes) {+ bytes = (bytes + 7) & ~7u;+ if (bytes > CACHE_BYTES / 2) bytes = CACHE_BYTES / 2;+ cache_top = 0;+ g_res_gen++;+ hash_rebuild();+ cache_limit = CACHE_BYTES - bytes;+ g_chapter_ram = cache + cache_limit;+ memset(g_chapter_ram, 0, bytes);+}++/* every loaded texture forgotten (the chapter's memory stays) */+void res_flush(void) {+ cache_top = 0;+ g_res_gen++;+ hash_rebuild();+}++uint8_t *arena_scratch(uint32_t *size) {+ *size = cache_limit - cache_top;+ return cache + cache_top;+}++uint16_t res_tex_by_name(const char *path) { /* (tools/pack.py: FNV-1a folded to 24 bits, then the ids) */+ const uint8_t *t = section(SEC_TEXNAMES);+ uint32_t h = rd32(t + 4);+ for (const char *s = path; *s; s++) h = (h ^ (uint8_t)*s) * 16777619u;+ h = (h ^ (h >> 24)) & 0xFFFFFF;+ int n = rd16(t), lo = 0, hi = n - 1;+ const uint8_t *ids = t + 8 + ((3u * n + 1) & ~1u);+ while (lo <= hi) {+ int m = (lo + hi) / 2;+ const uint8_t *e = t + 8 + 3 * m;+ uint32_t v = e[0] | e[1] << 8 | (uint32_t)e[2] << 16;+ if (v == h) return rd16(ids + 2 * m);+ if (v < h) lo = m + 1;+ else hi = m - 1;+ }+ return 0xFFFF;+}diff --git a/games/celeste/src/save.c b/games/celeste/src/save.cnew file mode 100644index 00000000..600be1d7--- /dev/null+++ b/games/celeste/src/save.c@@ -0,0 +1,278 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* The save file: Celeste's SaveData (strawberries, hearts, deaths and times of+ * every chapter side) with the Session being played inside it, so leaving+ * with Home keeps the run like the game's Save & Quit. One storage record. */+#include "level.h"+#include "player.h"++#define SAVE_NAME "celeste.sav"+#define SAVE_MAGIC 0x43454C53u /* "CELS" */+#define SAVE_VERSION 1++SaveData g_save;++static uint32_t checksum(void) {+ const uint8_t *p = (const uint8_t *)&g_save;+ uint32_t h = 2166136261u;+ for (uint32_t i = 0; i < offsetof(SaveData, checksum); i++) h = (h ^ p[i]) * 16777619u;+ return h;+}++static void save_new(void) {+ memset(&g_save, 0, sizeof g_save);+ g_save.magic = SAVE_MAGIC;+ g_save.version = SAVE_VERSION;+ g_save.size = sizeof g_save;+ plat_default_binds();+ memcpy(g_save.bind, g_bind, 4);+}++/* The copy: installing apps from the NumWorks website keeps only Python scripts, so the save is+ * also kept in one, as a comment line "#>celeste.sav:base64" (the way NumPlay keeps its games'+ * saves), and comes back from it when the save itself is gone. */+#define COPY_NAME "celeste_saves.py"+static const char copy_head[] =+ "# Celeste keeps a copy of your progress here, so that\n"+ "# reinstalling it doesn't erase it. If you delete this file,\n"+ "# Celeste writes it again: your progress stays either way.\n";+static const char tag[] = "#>" SAVE_NAME ":";+static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";+static void save_copy(void) {+ const uint8_t *d = (const uint8_t *)&g_save;+ uint32_t n = sizeof g_save, cap, total = 1 + (sizeof copy_head - 1) + (sizeof tag - 1) + (n + 2) / 3 * 4 + 2;+ uint8_t *o = res_scratch(total, &cap), *p = o;+ if (cap < total) return;+ *p++ = 0; /* the script's status byte: not imported */+ memcpy(p, copy_head, sizeof copy_head - 1), p += sizeof copy_head - 1;+ memcpy(p, tag, sizeof tag - 1), p += sizeof tag - 1;+ for (uint32_t i = 0; i < n; i += 3, p += 4) {+ uint32_t left = n - i, v = (uint32_t)d[i] << 16 | (left > 1 ? d[i + 1] << 8 : 0) | (left > 2 ? d[i + 2] : 0);+ p[0] = (uint8_t)b64[v >> 18 & 63];+ p[1] = (uint8_t)b64[v >> 12 & 63];+ p[2] = left > 1 ? (uint8_t)b64[v >> 6 & 63] : '=';+ p[3] = left > 2 ? (uint8_t)b64[v & 63] : '=';+ }+ *p++ = '\n';+ *p++ = 0;+ plat_save(COPY_NAME, o, (uint32_t)(p - o));+}+static int b64_value(uint8_t c) {+ for (int i = 0; i < 64; i++)+ if ((uint8_t)b64[i] == c) return i;+ return -1;+}+/* the save from the copy (after the app was installed again): true if it was there and whole */+static bool restore_copy(void) {+ uint32_t n;+ const uint8_t *c = plat_load(COPY_NAME, &n), *l = NULL;+ if (!c) return false;+ for (uint32_t i = 0; i + sizeof tag - 1 <= n; i++)+ if (!memcmp(c + i, tag, sizeof tag - 1)) {+ l = c + i + sizeof tag - 1;+ break;+ }+ if (!l) return false;+ uint32_t len = 0, o = 0;+ while (l + len < c + n && l[len] != '\n' && l[len]) len++;+ if (!len || len % 4 || len / 4 * 3 < sizeof g_save) return false;+ uint8_t *out = (uint8_t *)&g_save;+ for (uint32_t i = 0; i < len && o < sizeof g_save; i += 4) {+ int v[4];+ for (int k = 0; k < 4; k++) v[k] = l[i + k] == '=' ? 0 : b64_value(l[i + k]);+ if (v[0] < 0 || v[1] < 0 || v[2] < 0 || v[3] < 0) return false;+ uint32_t w = (uint32_t)(v[0] << 18 | v[1] << 12 | v[2] << 6 | v[3]);+ for (int k = 0; k < 3 && o < sizeof g_save; k++) out[o++] = (uint8_t)(w >> (16 - 8 * k));+ }+ return true;+}++void save_load(void) {+ uint32_t len = 0;+ const uint8_t *p = plat_load(SAVE_NAME, &len);+ save_new();+ if (p && len == sizeof g_save) memcpy(&g_save, p, sizeof g_save); /* the record is not aligned: copy it */+ else if (!restore_copy()) save_new();+ if (g_save.magic != SAVE_MAGIC || g_save.version != SAVE_VERSION || g_save.size != sizeof g_save ||+ g_save.checksum != checksum())+ save_new();+ if (g_save.bind[0] && g_save.bind[1] && g_save.bind[2] && g_save.bind[3]) memcpy(g_bind, g_save.bind, 4);+ else plat_default_binds(), memcpy(g_save.bind, g_bind, 4);+}++bool save_write(void) {+ g_save.checksum = checksum();+ bool ok = plat_save(SAVE_NAME, &g_save, sizeof g_save);+ save_copy();+ return ok;+}++ModeStats *save_mode(void) { return &g_save.modes[g_session.area][g_session.mode]; }++bool save_check_berry(int index) { return index >= 0 && (save_mode()->berries >> index & 1); }++void save_add_berry(int index, bool golden) {+ if (index < 0) return;+ ModeStats *m = save_mode();+ if (!(m->berries >> index & 1)) {+ m->berries |= (uint64_t)1 << index;+ if (golden) g_save.total_golden++;+ }+}++void save_add_death(void) {+ g_save.total_deaths++;+ save_mode()->deaths++;+}++void save_add_time(uint32_t frames) {+ g_save.time += frames;+ save_mode()->time += frames;+}++bool save_set_checkpoint(int index) {+ ModeStats *m = save_mode();+ if (m->checkpoints >> index & 1) return false;+ m->checkpoints |= (uint8_t)(1 << index);+ return true;+}++void save_register_heart(void) { save_mode()->flags |= MS_HEART; }+bool save_flag(int bit) { return g_save.flags >> bit & 1; }+void save_set_flag(int bit) { g_save.flags |= (uint8_t)(1 << bit); }+/* SaveData.UnlockedModes: B-sides after a cassette, C-sides after 16 hearts */+int save_unlocked_modes(void) {+ int hearts = 0;+ for (int a = 0; a < AREAS; a++)+ for (int m = 0; m < 3; m++) hearts += (g_save.modes[a][m].flags & MS_HEART) != 0;+ if (hearts >= 16) return 3;+ return (g_save.cassettes & 0x7FE) ? 2 : 1;+}+void save_register_cassette(void) { g_save.cassettes |= (uint16_t)(1 << g_session.area); }++/* the chapter's strawberries (CH_BERRIES): Session.FullClear needs them all */+static int detected_berries(void) { return g_level.ch ? g_level.ch[CH_DETECTED] : 0; }+static int popcount64(uint64_t v) {+ int n = 0;+ for (; v; v &= v - 1) n++;+ return n;+}+static bool full_clear(void) {+ if (g_session.mode != M_A || !g_session.cassette || !g_session.heart) return false;+ if (popcount64(g_session.berries) < detected_berries()) return false;+ if (g_session.area == 7) return g_session.summit_gems == 0x3F; /* HasAllSummitGems */+ return true;+}++/* SaveData.RegisterCompletion */+void save_register_completion(void) {+ ModeStats *m = save_mode();+ Session *s = &g_session;+ if (s->grabbed_golden) m->best_deaths = 0;+ if (s->started_from_beginning) {+ m->flags |= MS_SINGLERUN;+ if (m->best_time == 0 || s->deaths < m->best_deaths) m->best_deaths = (uint16_t)(s->deaths > 0xFFFF ? 0xFFFF : s->deaths);+ if (m->best_time == 0 || s->dashes < m->best_dashes) m->best_dashes = (uint16_t)(s->dashes > 0xFFFF ? 0xFFFF : s->dashes);+ if (m->best_time == 0 || s->time < m->best_time) {+ if (m->best_time > 0) s->beat_best_time = 1;+ m->best_time = s->time;+ }+ if (s->mode == M_A && full_clear()) {+ m->flags |= MS_FULLCLEAR;+ if (m->best_fc_time == 0 || s->time < m->best_fc_time) m->best_fc_time = s->time;+ }+ }+ if (s->area + 1 > g_save.unlocked_areas && s->area < AREAS - 1) g_save.unlocked_areas = (uint8_t)(s->area + 1);+ m->flags |= MS_COMPLETED;+ s->in_area = 0;+}++/* ---------------------------------------------------------------- chapters in data.bin */+const uint8_t *chapter_at(int c) {+ const uint8_t *s = section(SEC_CHAPTERS);+ return s + rd32(s + 4 + 4 * c);+}+int chapter_index(int area, int mode) {+ const uint8_t *s = section(SEC_CHAPTERS);+ int n = rd16(s);+ for (int c = 0; c < n; c++) {+ const uint8_t *ch = chapter_at(c);+ if (ch[CH_AREA] == area && ch[CH_MODE] == mode) return c;+ }+ return -1;+}+int session_berry_index(int room, int eid) {+ const uint8_t *ch = g_level.ch;+ const uint8_t *b = ch + rd16(ch + CH_BERRIES);+ for (int i = 0; i < ch[CH_NBERRIES]; i++, b += 6)+ if (rd16(b) == room && rd16(b + 2) == (uint16_t)eid) return i;+ return -1;+}++/* PlayerInventory presets */+static void set_inventory(int inv) {+ static const uint8_t dashes[] = {0, 1, 1, 2, 2, 2, 1}, dream[] = {0, 1, 0, 1, 1, 1, 1},+ pack[] = {1, 1, 1, 1, 0, 1, 0}, norefill[] = {0, 0, 0, 0, 0, 1, 0};+ g_session.inv_dashes = dashes[inv];+ g_session.dreamdash = dream[inv];+ g_session.backpack = pack[inv];+ g_session.no_refills = norefill[inv];+}++/* new Session(area, checkpoint): checkpoint -1 is the start */+void session_start(int chapter, int checkpoint) {+ const uint8_t *ch = chapter_at(chapter);+ Session *s = &g_session;+ memset(s, 0, sizeof *s);+ s->chapter = (uint8_t)chapter;+ s->area = ch[CH_AREA];+ s->mode = ch[CH_MODE];+ s->start_checkpoint = (int8_t)checkpoint;+ /* AreaData: Dreaming, CoreMode */+ s->dreaming = s->area == 2;+ s->core_mode = s->area == 9 ? 1 : 0;+ s->first_level = 1;+ s->dark_room_alpha = 0.75f;+ s->in_area = 1;+ int inv = ch[CH_INVENTORY];+ if (checkpoint < 0) {+ s->level = 0xFF; /* the room at (0, 0): level_start finds it */+ s->started_from_beginning = 1;+ } else {+ const uint8_t *cp = ch + rd16(ch + CH_CHECKPOINTS) + 4 * checkpoint;+ s->level = (uint8_t)rd16(cp);+ if (cp[2] != 255) inv = cp[2];+ s->dreaming = (cp[3] & CPF_DREAMING) != 0;+ if (cp[3] & CPF_COLD) s->core_mode = 2;+ if (cp[3] & CPF_FEELINGDOWN) s->color_grade = CG_FEELINGDOWN;+ }+ set_inventory(inv);+ s->old_stats = g_save.modes[s->area][s->mode];+ if (checkpoint >= 0 && (ch[rd16(ch + CH_CHECKPOINTS) + 4 * checkpoint + 3] & CPF_BADELINE))+ level_set_flag("badeline_connection", true);+ g_save.last_area = s->area;+ g_save.last_mode = s->mode;+}++/* Session.Restart(intoLevel) */+void session_restart(int room) {+ Session old = g_session;+ session_start(old.chapter, old.start_checkpoint);+ g_session.old_stats = old.old_stats;+ g_session.unlocked_cside = old.unlocked_cside;+ if (room >= 0) {+ g_session.level = (uint8_t)room;+ if (room != level_start_room()) g_session.started_from_beginning = 0;+ }+}++/* the player's entrance when a chapter loads (LevelLoader) */+int session_intro(bool just_started) {+ static const uint8_t intro[AREAS] = {INTRO_WALKINRIGHT, INTRO_JUMP, INTRO_WAKEUP, INTRO_WALKINRIGHT, INTRO_WALKINRIGHT,+ INTRO_WAKEUP, INTRO_NONE, INTRO_NONE, INTRO_WALKINLEFT, INTRO_WALKINRIGHT,+ INTRO_THINKFORABIT};+ Session *s = &g_session;+ if (!s->first_level || !s->started_from_beginning || !just_started) return INTRO_RESPAWN;+ return s->mode != M_C ? intro[s->area] : INTRO_WALKINRIGHT;+}diff --git a/games/celeste/src/spinner.c b/games/celeste/src/spinner.cnew file mode 100644index 00000000..86a4ba3d--- /dev/null+++ b/games/celeste/src/spinner.c@@ -0,0 +1,228 @@+/* Crystal spinners (CrystalStaticSpinner) that are not attached to solids,+ * kept as compact records with the room's tiles (by tile row): a room can have over a thousand. One layer+ * entity draws them (with their fillers and black border) and checks the+ * player against them, like each spinner's own PlayerCollider would. */+#include "entities.h"++enum { SC_BLUE, SC_RED, SC_PURPLE };+static uint16_t fg_tex[3][4], bg_tex[3][4], fgb_tex[3][4], bgb_tex[3][4]; /* (b: their borders, tools/pack.py) */+static int nfg[3], nbg[3];++static int area_color(void) {+ int a = g_session.area;+ if (a == 5) return SC_RED;+ if (a == 6) return SC_PURPLE;+ if (a == 9) return g_level.core_mode == 2 ? SC_BLUE : SC_RED; /* Core: blue when cold */+ return SC_BLUE;+}++static void load_textures(void) {+ static const char *cols[3] = {"blue", "red", "purple"};+ char p[48], q[56];+ for (int c = 0; c < 3; c++) {+ nfg[c] = nbg[c] = 0;+ for (int i = 0; i < 4; i++) {+ char b[24];+ path2(b, "fg_", cols[c], -1);+ path2(p, "danger/crystal/", b, i);+ uint16_t t = res_tex_by_name(p);+ if (t != 0xFFFF) fgb_tex[c][nfg[c]] = res_tex_by_name(path2(q, p, "_border", -1)), fg_tex[c][nfg[c]++] = t;+ path2(b, "bg_", cols[c], -1);+ path2(p, "danger/crystal/", b, i);+ t = res_tex_by_name(p);+ if (t != 0xFFFF) bgb_tex[c][nbg[c]] = res_tex_by_name(path2(q, p, "_border", -1)), bg_tex[c][nbg[c]++] = t;+ }+ }+}++static inline uint32_t hash2(int a, int b) {+ uint32_t h = (uint32_t)a * 0x9E3779B1u ^ (uint32_t)b * 0x85EBCA77u;+ h ^= h >> 15;+ h *= 0x2C1B3C6Du;+ return h ^ (h >> 12);+}++typedef struct { const Room *rm; int i, row; float x, y; uint8_t mask; } Sp;+static void at(const Room *rm, int i, int row, Sp *s) {+ uint16_t v = rm->spin[i];+ s->rm = rm, s->i = i, s->row = row;+ s->x = (float)(rm->x + ((v & 1023) - SPIN_X0) * 8 + ((v >> 10) & 7));+ s->y = (float)(rm->y + (row + rm->spin_row0) * 8 + (v >> 13));+ s->mask = (rm->spin_mask[i >> 1] >> ((i & 1) * 4)) & 15;+}+static inline bool gone(const Room *rm, int i) { return rm->spin_gone[i >> 3] & (1 << (i & 7)); }+/* the rows of spinners whose y can be in [y0, y1] */+static void rows(const Room *rm, float y0, float y1, int *r0, int *r1) {+ *r0 = (int)floorf((y0 - rm->y) / 8) - rm->spin_row0 - 1;+ *r1 = (int)floorf((y1 - rm->y) / 8) - rm->spin_row0 + 2;+ if (*r0 < 0) *r0 = 0;+ if (*r1 > rm->spin_rows) *r1 = rm->spin_rows;+}+/* the room's spinners still there with x in [x0, x1], in the rows around [y0, y1] */+#define FOR_SPINNERS(rm, x0, y0, x1, y1, sp) \+ for (int r0_, r1_, row_ = (rows(rm, y0, y1, &r0_, &r1_), r0_); row_ < r1_; row_++) \+ for (int i_ = rm->spin_first[row_]; i_ < rm->spin_first[row_ + 1]; i_++) \+ if (!gone(rm, i_) && (at(rm, i_, row_, &sp), sp.x >= (x0) && sp.x <= (x1)))++/* the sprites of one spinner (CreateSprites), drawn into the strip: four quarters of an fg texture, fillers towards+ * neighbours less than 24 px away on its right; pass 0 draws them black, a pixel around (Border) */+typedef struct { Tex fg[4], bg[4], fgb[4], bgb[4]; int nf, nb; bool borders; } Look;+/* a texture's frame centered at strip-relative (cx, cy), turned q quarter turns */+static void blit_centered(uint16_t *strip, int sy0, int sy1, const Tex *t, int cx, int cy, int q, uint8_t f, uint16_t tint) {+ int x0 = cx - t->fw / 2, y0 = cy - t->fh / 2;+ if (q == 0) blit_tex(strip, sy0, sy1, t, x0 + t->ox, y0 + t->oy, f, tint, 255);+ else if (q == 2) /* half a turn: both flips */+ blit_tex(strip, sy0, sy1, t, x0 + t->fw - t->ox - t->w, y0 + t->fh - t->oy - t->h, f | GF_FLIPX | GF_FLIPY, tint, 255);+ else blit_turned(strip, sy0, sy1, t, x0, y0, q, f, tint);+}+static const int8_t SHIFT_X[4] = {0, 0, -1, 1}, SHIFT_Y[4] = {-1, 1, 0, 0};+/* the sprites of one spinner (CreateSprites), drawn into the strip: four quarters of an fg texture, fillers towards+ * neighbours less than 24 px away on its right; pass 0 draws them black, a pixel around (Border: from their own+ * border textures, but for spinners missing quarters) */+static void draw_spinner(uint16_t *strip, int sy0, int sy1, const Sp *s, const Look *lk, int pass) {+ int fi = (int)(hash2((int)s->x, (int)s->y) % (uint32_t)lk->nf);+ const Tex *fg = &lk->fg[fi];+ static const int8_t qx[4] = {0, 10, 10, 0}, qy[4] = {0, 0, 10, 10}, ox[4] = {12, 2, 2, 12}, oy[4] = {12, 12, 2, 2};+ int X = (int)s->x - g_camx, Y = (int)s->y - g_camy, shifts = pass ? 1 : 4;+ uint8_t f = pass ? 0 : GF_SILHOUETTE;+ uint16_t tint = pass ? 0xFFFF : 0;+ if (pass == 0 && lk->borders && !s->mask) blit_centered(strip, sy0, sy1, &lk->fgb[fi], X, Y, 0, 0, 0xFFFF);+ else if (pass != 1)+ for (int k = 0; k < shifts; k++) {+ int bx = pass ? 0 : SHIFT_X[k], by = pass ? 0 : SHIFT_Y[k];+ if (!s->mask) /* the four quarters make the whole texture (it is opaque: their overlaps change nothing) */+ blit_centered(strip, sy0, sy1, fg, X + bx, Y + by, 0, f, tint);+ else+ for (int q = 0; q < 4; q++)+ if (!(s->mask & (1 << q)))+ blit_part_ex(strip, sy0, sy1, fg, X - ox[q] + bx, Y - oy[q] + by, qx[q], qy[q], 14, 14, f, tint, 255);+ }+ if (pass == 2 || !lk->nb) return;+ /* each pair once: from the one first in (row, x) order */+ const Room *rm = s->rm;+ for (int row = s->row; row < s->row + 4 && row < rm->spin_rows; row++)+ for (int j = row == s->row ? s->i + 1 : rm->spin_first[row]; j < rm->spin_first[row + 1]; j++) {+ if (gone(rm, j)) continue;+ Sp o;+ at(rm, j, row, &o);+ float ddx = o.x - s->x, ddy = o.y - s->y;+ if (ddx * ddx + ddy * ddy >= 24 * 24) continue;+ uint32_t k = hash2((int)(s->x + o.x), (int)(s->y + o.y) * 7 + 3);+ int bi = (int)(k % (uint32_t)lk->nb), q = (int)((k >> 8) & 3);+ int mx = (int)floorf((s->x + o.x) / 2 + 0.5f) - g_camx, my = (int)floorf((s->y + o.y) / 2 + 0.5f) - g_camy;+ if (my + 14 < sy0 || my - 14 >= sy1) continue;+ if (pass == 0 && lk->borders) blit_centered(strip, sy0, sy1, &lk->bgb[bi], mx, my, q, 0, 0xFFFF);+ else+ for (int n = 0; n < shifts; n++)+ blit_centered(strip, sy0, sy1, &lk->bg[bi], mx + (pass ? 0 : SHIFT_X[n]), my + (pass ? 0 : SHIFT_Y[n]), q, f, tint);+ }+}++/* the dust bunnies (dust.c draws them): those whose x is in [x0, x1], y in [y0, y1] */+void spinners_each(const Room *rm, float x0, float y0, float x1, float y1, void (*fn)(float x, float y, uint16_t nodes, void *ctx),+ void *ctx) {+ Sp sp;+ FOR_SPINNERS(rm, x0, y0, x1, y1, sp) if (sp.y >= y0 && sp.y <= y1) fn(sp.x, sp.y, rd16(rm->spin_dust + 2 * sp.i), ctx);+}++/* each pass draws every spinner in view straight into the strips (a room can show hundreds: too many to queue) */+static void layer_strip(uint16_t *strip, int sy0, int sy1, void *ctx) {+ int pass = (int)(intptr_t)ctx, col = area_color();+ Look look, *lk = &look; /* (the cache can have moved them since the frame began: their places now) */+ lk->nf = lk->nb = 0;+ lk->borders = pass == 0;+ for (int i = 0; i < nfg[col]; i++)+ if (tex_get(fg_tex[col][i], &lk->fg[lk->nf])) lk->borders &= tex_get(fgb_tex[col][i], &lk->fgb[lk->nf++]);+ for (int i = 0; i < nbg[col]; i++)+ if (tex_get(bg_tex[col][i], &lk->bg[lk->nb])) lk->borders &= tex_get(bgb_tex[col][i], &lk->bgb[lk->nb++]);+ if (!lk->nf) return;+ float cx = g_level.cam.x, cy = g_level.cam.y, wy0 = (float)(sy0 + g_camy), wy1 = (float)(sy1 + g_camy);+ for (int s = 0; s < 2; s++) {+ const Room *rm = &g_level.rooms[s];+ if (rm->index < 0 || !rm->nspin || rm->spin_dust) continue;+ Sp sp;+ /* InView: within the camera plus 16; those whose sprites (and fillers, 24 px on) reach the strip */+ FOR_SPINNERS(rm, cx - 16, wy0 - 40, cx + 336, wy1 + 16, sp) {+ if (sp.y <= cy - 16 || sp.y >= cy + 196 || sp.x <= cx - 16 || sp.x >= cx + 336) continue;+ if (sp.y + 14 < wy0 - 26 || sp.y - 14 >= wy1) continue;+ draw_spinner(strip, sy0, sy1, &sp, lk, pass);+ }+ }+}+static void layer_render(Ent *e) {+ int pass = (int)e->eid; /* 0: border (depth -8498), 1: fillers (-8499), 2: crystals (-8500) */+ int col = area_color();+ bool any = false;+ for (int s = 0; s < 2; s++) any |= g_level.rooms[s].index >= 0 && g_level.rooms[s].nspin && !g_level.rooms[s].spin_dust;+ if (!any) return;+ Tex t; /* loaded now (nothing loads while the strips are drawn), and kept for this frame */+ for (int i = 0; i < nfg[col]; i++) tex_get(pass ? fg_tex[col][i] : fgb_tex[col][i], &t), tex_get(fg_tex[col][i], &t);+ for (int i = 0; i < nbg[col]; i++) tex_get(pass ? bg_tex[col][i] : bgb_tex[col][i], &t), tex_get(bg_tex[col][i], &t);+ gfx_custom(layer_strip, (void *)(intptr_t)(pass == 0 ? 0 : pass == 1 ? 1 : 2), 0, VIEW_H);+}++/* the collider: Circle(6) and Hitbox(16, 4, -8, -3) */+static bool hits(const Sp *s, float l, float t, float r, float b) {+ float nx = clampf(s->x, l, r), ny = clampf(s->y, t, b), dx = s->x - nx, dy = s->y - ny;+ if (dx * dx + dy * dy < 36) return true;+ return r > s->x - 8 && l < s->x + 8 && b > s->y - 3 && t < s->y + 1;+}++bool spinners_hit_rect(float l, float t, float r, float b) {+ for (int s = 0; s < 2; s++) {+ const Room *rm = &g_level.rooms[s];+ if (rm->index < 0 || !rm->nspin) continue;+ Sp sp;+ FOR_SPINNERS(rm, l - 8, t - 8, r + 8, b + 8, sp) if (hits(&sp, l, t, r, b)) return true;+ }+ return false;+}++static void layer_update(Ent *e) {+ if (e->eid != 2) return;+ Player *p = level_player();+ if (!p || p->dead || p->state == ST_CASSETTEFLY) return;+ Ent *pe = p->ent;+ /* the hurtbox, as the player's PlayerCollider check sees it (8 x 9 above the feet; ducking 8 x 4) */+ float l = pe->x - 4, r = pe->x + 4, t = pe->y - (player_ducking(p) ? 6.f : 11.f);+ float b = t + (player_ducking(p) ? 4.f : 9.f);+ for (int s = 0; s < 2; s++) {+ const Room *rm = &g_level.rooms[s];+ if (rm->index < 0 || !rm->nspin) continue;+ Sp sp;+ FOR_SPINNERS(rm, l - 8, t - 8, r + 8, b + 8, sp) {+ /* Collidable only near the player (within 128) */+ if (fabsf(pe->x - sp.x) >= 128 || fabsf(pe->y - sp.y) >= 128) continue;+ if (hits(&sp, l, t, r, b)) {+ V2 d = v2norm(v2(pe->x - sp.x, pe->y - sp.y));+ player_die(p, d, false);+ if (rm->spin_dust && p->dead) dust_hit(sp.x, sp.y); /* DustGraphic.OnHitPlayer */+ return;+ }+ }+ }+}++void spinners_destroy_near(float x, float y, float rad) {+ for (int s = 0; s < 2; s++) {+ Room *rm = &g_level.rooms[s];+ if (rm->index < 0 || !rm->nspin) continue;+ Sp sp;+ FOR_SPINNERS(rm, x - rad, y - rad, x + rad, y + rad, sp)+ if (fabsf(sp.x - x) < rad && fabsf(sp.y - y) < rad) rm->spin_gone[sp.i >> 3] |= (uint8_t)(1 << (sp.i & 7));+ }+}++static const EntClass LAYER = {.name = "spinners", .size = 0, .update = layer_update, .render = layer_render};+void spinners_entities(void) {+ load_textures();+ for (int k = 0; k < 3; k++) {+ Ent *e = ent_new(&LAYER, 0, 0);+ if (!e) return;+ e->eid = (uint16_t)k;+ e->depth = k == 0 ? -8498 : k == 1 ? -8499 : -8500;+ e->tags = TAG_GLOBAL | TAG_TRANSITION_UPDATE;+ e->collidable = 0;+ e->dead = 0;+ }+}diff --git a/games/celeste/src/style.c b/games/celeste/src/style.cnew file mode 100644index 00000000..ee062d2c--- /dev/null+++ b/games/celeste/src/style.c@@ -0,0 +1,102 @@+/* Stylegrounds: the chapter's parallax backgrounds and effects (Celeste's+ * Backdrop, Parallax, Snow, ...), drawn in screen space behind and in front of+ * the level. */+#include "level.h"++#define MAX_SG 64+typedef struct {+ float x, y; /* Position (moves with speed) */+ float fade; /* fadeIn */+ bool visible;+} SgState;+static SgState sg[MAX_SG];+static int nbg, nfg;++/* record: u8 effect, u8 flags, u16 tex, f32 x, y, scrollx, scrolly, speedx, speedy, alpha, u32 color,+ * u16 flag, notflag, tag, fadex, fadey, only */+static const uint8_t *rec(int i) {+ const uint8_t *c = g_level.ch;+ int nrooms = rd16(c + 2);+ return c + rd32(c + CH_ROOMS + 4 * nrooms + 4 * i);+}+enum { SF_LOOPX = 1, SF_LOOPY = 2, SF_FLIPX = 4, SF_FLIPY = 8, SF_INSTANTIN = 16, SF_INSTANTOUT = 32, SF_FADEIN = 64, SF_ADD = 128 };++static bool is_visible(int i) {+ const uint8_t *r = rec(i);+ const uint8_t *info = g_level.room->info;+ uint32_t lo = rd32(info + 28), hi = rd32(info + 32);+ bool in_room = i < 32 ? (lo >> i) & 1 : (hi >> (i - 32)) & 1;+ if (!in_room) return false;+ const char *flag = str(rd16(r + 36)), *notflag = str(rd16(r + 38));+ if (*flag && !level_get_flag(flag)) return false;+ if (*notflag && level_get_flag(notflag)) return false;+ return true;+}++void style_init(void) {+ const uint8_t *c = g_level.ch;+ nbg = c[12], nfg = c[13];+ for (int i = 0; i < nbg + nfg && i < MAX_SG; i++) {+ const uint8_t *r = rec(i);+ sg[i].x = rdf(r + 4), sg[i].y = rdf(r + 8);+ sg[i].visible = is_visible(i);+ sg[i].fade = sg[i].visible ? 1 : 0;+ }+}++void style_update(void) {+ for (int i = 0; i < nbg + nfg && i < MAX_SG; i++) {+ const uint8_t *r = rec(i);+ sg[i].visible = is_visible(i);+ sg[i].x += rdf(r + 20) * DT + g_level.wind.x * DT * 0;+ sg[i].y += rdf(r + 24) * DT;+ if (r[1] & SF_FADEIN) sg[i].fade = approach(sg[i].fade, sg[i].visible ? 1 : 0, DT);+ else sg[i].fade = sg[i].visible ? 1 : 0;+ }+}++static void parallax(int i) {+ const uint8_t *r = rec(i);+ uint16_t tex = rd16(r + 2);+ Tex t;+ if (tex == 0xFFFF || !tex_get(tex, &t)) return;+ float camx = floorf(g_level.cam.x), camy = floorf(g_level.cam.y);+ float px = floorf(sg[i].x - camx * rdf(r + 12)), py = floorf(sg[i].y - camy * rdf(r + 16));+ float alpha = sg[i].fade * rdf(r + 28);+ uint32_t col = rd32(r + 32);+ uint16_t tint = col == 0xFFFFFF ? 0xFFFF : rgb(col);+ if (alpha <= 1 / 255.f) return;+ uint8_t flags = r[1];+ int fw = t.fw * t.scale, fh = t.fh * t.scale;+ if (flags & SF_LOOPX) {+ while (px < 0) px += fw;+ while (px > 0) px -= fw;+ }+ if (flags & SF_LOOPY) {+ while (py < 0) py += fh;+ while (py > 0) py -= fh;+ }+ uint8_t gf = (flags & SF_FLIPX ? GF_FLIPX : 0) | (flags & SF_FLIPY ? GF_FLIPY : 0) | (flags & SF_ADD ? GF_ADD : 0);+ uint8_t a = (uint8_t)(alpha * 255);+ for (float x = px; x < 320; x += fw) {+ for (float y = py; y < 180; y += fh) {+ gfx_tex(tex, x, y, gf, tint, a);+ if (!(flags & SF_LOOPY)) break;+ }+ if (!(flags & SF_LOOPX)) break;+ }+}++void style_render(bool fg) {+ gfx_screen(true);+ int from = fg ? nbg : 0, to = fg ? nbg + nfg : nbg;+ for (int i = from; i < to && i < MAX_SG; i++) {+ const uint8_t *r = rec(i);+ if (sg[i].fade <= 0) continue;+ switch (r[0]) {+ case SG_parallax: parallax(i); break;+ default: break;+ }+ }+ gfx_screen(false);+}diff --git a/games/celeste/src/talk.c b/games/celeste/src/talk.cnew file mode 100644index 00000000..59c0672d--- /dev/null+++ b/games/celeste/src/talk.c@@ -0,0 +1,112 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* TalkComponent and TalkComponentUI, line by line from the game's code. */+#include "talk.h"++Ent *g_talk_over;++void talk_init(Talk *t, int x, int y, int w, int h, V2 draw_at) {+ memset(t, 0, sizeof *t);+ t->bx = (int16_t)x, t->by = (int16_t)y, t->bw = (int16_t)w, t->bh = (int16_t)h;+ t->draw_at = draw_at;+ t->enabled = t->must_face = true;+ t->alpha = 1;+ wiggler_init(&t->wig, 0.25f, 4);+}++/* a fake wall over the point (the prompt behind it shows once it is gone) */+static bool in_fake_wall(float x, float y) {+ for (int i = 0; i < g_nents; i++) {+ Ent *o = &g_ents[i];+ if (o->cls && o->dead != 1 && o->collidable && o->cls->name && !strcmp(o->cls->name, "fakeWall") &&+ collide_rect(o, x, y, x + 1, y + 1))+ return true;+ }+ return false;+}++static bool textbox_up(void) {+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls && g_ents[i].dead != 1 && g_ents[i].cls->name && !strcmp(g_ents[i].cls->name, "textbox")) return true;+ return false;+}+/* TalkComponentUI.Display */+static bool display(const Talk *t) {+ Player *p = level_player();+ return t->enabled && !textbox_up() && p && !p->dead && p->state != ST_DUMMY && !g_level.frozen && !g_level.paused;+}++bool talk_update(Talk *t, Ent *e) {+ Player *p = level_player();+ bool talked = false;+ if (!t->inited) { /* the UI comes with the first update (and starts hidden behind a fake wall) */+ t->inited = true;+ if (in_fake_wall(e->x, e->y)) t->alpha = 0;+ }+ bool over = false;+ if (t->disable_delay < 0.05f && p && !p->dead) {+ Ent *pe = p->ent;+ float l = (float)(int)(e->x + t->bx), tp = (float)(int)(e->y + t->by);+ over = collide_rect(pe, l, tp, l + t->bw, tp + t->bh) && p->on_ground && e_bottom(pe) < e->y + t->by + t->bh + 4 &&+ p->state == ST_NORMAL &&+ (!t->must_face || fabsf(pe->x - e->x) <= 16 || p->facing == (int)signf(e->x - pe->x)) &&+ (!g_talk_over || g_talk_over == e);+ }+ if (over) t->hover_timer += DT;+ else if (display(t)) t->hover_timer = 0;+ if (g_talk_over == e && !over) g_talk_over = NULL;+ else if (over) g_talk_over = e;+ if (over && t->cooldown <= 0 && p->state == ST_NORMAL && btn_pressed(&g_in.talk) && t->enabled && !g_level.paused) {+ t->cooldown = 0.1f;+ talked = true;+ }+ if (over && p->state == ST_NORMAL) t->cooldown -= DT;+ if (!t->enabled) t->disable_delay += DT;+ else t->disable_delay = 0;+ bool hl = over && t->hover_timer > 0.1f;+ if (hl != t->highlighted && display(t)) { /* Highlighted's setter */+ t->highlighted = hl;+ wiggler_restart(&t->wig);+ }+ /* the UI's update */+ t->timer += DT;+ t->slide = approach(t->slide, display(t) ? 1.f : 0.f, DT * 4);+ if (t->alpha < 1 && !in_fake_wall(e->x, e->y)) t->alpha = approach(t->alpha, 1, 2 * DT);+ wiggler_update(&t->wig);+ return talked;+}++void talk_removed(Ent *e) {+ if (g_talk_over == e) g_talk_over = NULL;+}++/* the talk key's cap (the calculator's Backspace) */+static void key_icon(float x, float y, float s, uint8_t a) {+ /* a backspace key: an arrow-shaped outline, an x in it */+ float w = 9 * s, h = 6 * s;+ float l = x - w / 2, r = x + w / 2, t = y - h / 2, b = y + h / 2, tip = l - 3 * s;+ gfx_line(tip, y, l, t, 0, a), gfx_line(tip, y, l, b, 0, a);+ gfx_line(l, t, r, t, 0, a), gfx_line(l, b, r, b, 0, a), gfx_line(r, t, r, b, 0, a);+ gfx_line(tip + 1, y, l + 1, t + 1, 0xFFFF, a), gfx_line(tip + 1, y, l + 1, b - 1, 0xFFFF, a);+ gfx_line(l + 1, t + 1, r - 1, t + 1, 0xFFFF, a), gfx_line(l + 1, b - 1, r - 1, b - 1, 0xFFFF, a);+ gfx_line(r - 1, t + 1, r - 1, b - 1, 0xFFFF, a);+ float cx = x + 0.5f * s;+ gfx_line(cx - 1.5f * s, y - 1.5f * s, cx + 1.5f * s, y + 1.5f * s, 0xFFFF, a);+ gfx_line(cx - 1.5f * s, y + 1.5f * s, cx + 1.5f * s, y - 1.5f * s, 0xFFFF, a);+}++void talk_render(Talk *t, Ent *e) {+ if (g_level.frozen || g_level.paused || !(t->slide > 0)) return;+ float x = (e->x + t->draw_at.x - floorf(g_level.cam.x)) * 6, y = (e->y + t->draw_at.y - floorf(g_level.cam.y)) * 6;+ y += sinf(t->timer * 4) * 12 + 64 * (1 - ease_cube_out(t->slide));+ float k = !t->highlighted ? 1 + t->wig.value * 0.5f : 1 - t->wig.value * 0.5f;+ float a = ease_cube_inout(t->slide) * t->alpha;+ uint8_t al = (uint8_t)(a * t->alpha * 255);+ uint16_t tex = t->highlighted ? T__hover_highlight : T__hover_idle;+ Tex tx;+ gfx_hud(true);+ if (tex_get(tex, &tx)) gfx_tex_ex(tex, x / 6, y / 6, tx.fw * tx.scale * 0.5f, (float)tx.fh * tx.scale, k, k, 0, 0xFFFF, al, 0);+ if (t->highlighted) key_icon(x / 6, (y - 75 * k) / 6, k, (uint8_t)(a * 255));+ gfx_hud(false);+}diff --git a/games/celeste/src/talk.h b/games/celeste/src/talk.hnew file mode 100644index 00000000..d79244ce--- /dev/null+++ b/games/celeste/src/talk.h@@ -0,0 +1,20 @@+/* TalkComponent: a spot where Madeline can talk or interact, with its prompt above. */+#ifndef TALK_H+#define TALK_H+#include "entities.h"++typedef struct {+ int16_t bx, by, bw, bh; /* Bounds, from the entity */+ V2 draw_at; /* DrawAt */+ float cooldown, hover_timer, disable_delay, slide, timer, alpha;+ Wiggler wig;+ bool enabled, must_face, highlighted, inited;+} Talk;+extern Ent *g_talk_over; /* TalkComponent.PlayerOver: whose spot Madeline stands in */++void talk_init(Talk *t, int x, int y, int w, int h, V2 draw_at);+/* TalkComponent.Update and its UI's: true on the update Madeline talks (OnTalk) */+bool talk_update(Talk *t, Ent *owner);+void talk_render(Talk *t, Ent *owner); /* TalkComponentUI.Render (the interface's) */+void talk_removed(Ent *owner); /* Dispose */+#endifdiff --git a/games/celeste/src/text.c b/games/celeste/src/text.cnew file mode 100644index 00000000..78719eb6--- /dev/null+++ b/games/celeste/src/text.c@@ -0,0 +1,1162 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* not drawn every frame: smaller over faster */+#endif+/* Dialog: Celeste's Textbox, FancyText and the portraits, line by line from+ * the game's code. The text is laid out in the game's 1920x1080 interface+ * units (exactly, from the font's own advances) and drawn at 1/6.+ *+ * The dialog comes from data.bin's DIALOG, decoded into the texture cache's+ * free space when a page is laid out; only the current page's nodes are kept. */+#include "text.h"+#include "level.h"+#include "entities.h"++/* ---------------------------------------------------------------- the dialog in data.bin */+/* DIALOG: u16 n, u16 0, u32 key hashes (sorted), then per key u16 pack, u16 length, u32 offset */+static bool dialog_find(const char *key, uint16_t *pack, uint16_t *len, uint32_t *off) {+ uint32_t h = 2166136261u;+ for (const char *s = key; *s; s++) {+ char c = *s >= 'a' && *s <= 'z' ? (char)(*s - 32) : *s;+ h = (h ^ (uint8_t)c) * 16777619u;+ }+ const uint8_t *d = section(SEC_DIALOG);+ int n = rd16(d), lo = 0, hi = n - 1;+ while (lo <= hi) {+ int m = (lo + hi) / 2;+ uint32_t v = rd32(d + 4 + 4 * m);+ if (v == h) {+ const uint8_t *p = d + 4 + 4 * n + 8 * m;+ *pack = rd16(p), *len = rd16(p + 2), *off = rd32(p + 4);+ return true;+ }+ if (v < h) lo = m + 1;+ else hi = m - 1;+ }+ return false;+}+bool dialog_has(const char *key) {+ uint16_t p, l;+ uint32_t o;+ return dialog_find(key, &p, &l, &o);+}+typedef struct { uint8_t *dst; uint32_t n; } CopySink;+static void copy_sink(const uint8_t *p, uint32_t n, void *ctx) {+ CopySink *c = ctx;+ memcpy(c->dst + c->n, p, n);+ c->n += n;+}+/* the text of a key, in scratch memory (good until textures load); Dialog.Get's "[KEY]" if missing */+static const char *dialog_text(const char *key, int *len) {+ uint16_t pack, n;+ uint32_t off, cap;+ if (!dialog_find(key, &pack, &n, &off)) {+ static char missing[48];+ path2(missing, "[", key, -1);+ size_t k = strlen(missing);+ missing[k] = ']', missing[k + 1] = 0;+ *len = (int)k + 1;+ return missing;+ }+ uint8_t *buf = res_scratch(n, &cap);+ if (cap < n) n = (uint16_t)cap;+ CopySink c = {buf, 0};+ res_stream(pack, off, n, copy_sink, &c);+ *len = n;+ return (const char *)buf;+}++/* Dialog.Clean: the text without its commands */+int dialog_clean(const char *key, char *out, int cap) {+ int n, k = 0;+ const char *s = dialog_text(key, &n);+ for (int i = 0; i < n && k < cap - 1; i++) {+ if (s[i] == '{') {+ if ((i + 2 < n && s[i + 1] == 'n' && s[i + 2] == '}') || (i + 6 < n && !memcmp(s + i, "{break}", 7))) out[k++] = '\n';+ while (i < n && s[i] != '}') i++;+ continue;+ }+ if (s[i] == '\\') continue;+ out[k++] = s[i];+ }+ out[k] = 0;+ return k;+}++/* ---------------------------------------------------------------- FancyText */+enum { N_CHAR, N_NEWLINE, N_NEWPAGE, N_WAIT, N_TRIGGER, N_PORTRAIT, N_ANCHOR };+enum { CF_SHAKE = 1, CF_WAVE = 2, CF_IMPACT = 4, CF_PUNCT = 8, CF_BIG = 16, CF_ROTNEG = 32, CF_ROTBIG = 64, CF_MESSED = 128 };+typedef struct {+ uint8_t type, flags;+ uint16_t v; /* char: its code; wait: ms; trigger: index | 0x8000 silent; anchor: 0 top 1 middle 2 bottom;+ portrait: its slot */+ int16_t pos; /* Position: interface pixels x4 */+ uint16_t width; /* LineWidth x4 */+ uint16_t color;+ uint16_t delay; /* Delay x 10000 */+ uint16_t index; /* Index (waves) */+ uint8_t fade; /* Fade x 255 */+ int8_t yoff; /* YOffset (messed up text) */+} TNode;+typedef struct {+ uint8_t bank, begin, idle, talk; /* 255: none; bank 254: {portrait none} */+ int8_t side;+ uint8_t flags; /* 1 upside down, 2 flipped, 4 pop, 8 glitchy */+ uint16_t textbox, overlay;+} Port;+#define MAX_NODES 176+#define MAX_PORTS 8+static TNode nodes[MAX_NODES];+static int nnodes; /* in the buffer */+static int base; /* global index of nodes[0] */+static Port ports[MAX_PORTS];+static int nports;++/* the textbox's sizes (interface pixels) */+#define LINE_H 63 /* Renogare 64's LineHeight - 1 */+#define LINES 3 /* (int)(240 / LINE_H) */+#define PAD 41.5f /* (272 - LINE_H * LINES) / 2 */+#define MAXW_NOPORT 1605 /* 1688 - PAD * 2 */+#define MAXW 1333 /* MAXW_NOPORT - 240 - 32 */++typedef struct {+ char key[40];+ int src_pos, src_len; /* the parse: how far in the text */+ bool done;+ float pos; /* currentPosition */+ int line, page, char_index;+ uint16_t color, colors[8];+ int ncolors;+ float scale, delay;+ bool shake, wave, impact, messed;+ int last_port[2];+} Parser;+static Parser P;++/* the 64 px face's advance and kerning in interface pixels (the data keeps them x16 at 1/6) */+static int adv(uint32_t c) {+ const uint8_t *g = font_glyph_rec(FONT_S, c);+ return g ? (int)((rd16(g + 8) * 6 + 8) / 16) : -1;+}+static int kern(uint32_t a, uint32_t b) {+ int k = font_kerning_x16(FONT_S, a, b);+ return k >= 0 ? (k * 6 + 8) / 16 : -((-k * 6 + 8) / 16);+}++static TNode *add_node(int type) {+ if (nnodes >= MAX_NODES) return NULL;+ TNode *n = &nodes[nnodes++];+ memset(n, 0, sizeof *n);+ n->type = (uint8_t)type;+ return n;+}++static void calc_line_width(void) {+ int i = nnodes - 1;+ TNode *last = NULL;+ for (; i >= 0 && !last; i--) {+ if (nodes[i].type == N_CHAR) last = &nodes[i];+ else if (nodes[i].type == N_NEWLINE || nodes[i].type == N_NEWPAGE) return;+ }+ if (!last) return;+ float sc = (last->flags & CF_BIG) ? 1.5f : 1;+ uint16_t w = (uint16_t)(last->pos + adv(last->v) * sc * 4);+ last->width = w;+ for (; i >= 0 && nodes[i].type != N_NEWLINE && nodes[i].type != N_NEWPAGE; i--)+ if (nodes[i].type == N_CHAR) nodes[i].width = w;+}++static void add_new_line(void) {+ calc_line_width();+ P.line++;+ P.pos = 0;+ if (P.line > LINES) {+ P.page++;+ P.line = 0;+ add_node(N_NEWPAGE);+ } else+ add_node(N_NEWLINE);+}++static bool is_comma(uint32_t c) { return c == ','; }+static bool is_period(uint32_t c) { return c == '.' || c == '!' || c == '?'; }++/* AddWord */+static void add_word(const char *w, int n, int maxw) {+ /* size.Measure: advances and kerning with the next character */+ float width = 0;+ for (const char *s = w, *end = w + n; s < end;) {+ uint32_t c = utf8_next(&s, end);+ int a = adv(c);+ if (a < 0) continue;+ width += a;+ if (s < end) {+ const char *t = s;+ width += kern(c, utf8_next(&t, end));+ }+ }+ if (P.pos + width * P.scale > maxw) add_new_line();+ uint32_t prev = 0;+ for (const char *s = w, *end = w + n; s < end;) {+ uint32_t c = utf8_next(&s, end);+ bool last = s >= end;+ uint32_t before = prev;+ prev = c;+ if ((P.pos == 0 && c == ' ') || c == '\\') continue;+ int a = adv(c);+ if (a < 0) continue;+ float d = 0;+ if (last && before != '\\') {+ if (is_comma(c)) d = 0.15f;+ else if (is_period(c)) d = 0.3f;+ }+ TNode *nd = add_node(N_CHAR);+ if (!nd) return;+ nd->v = (uint16_t)c;+ nd->index = (uint16_t)P.char_index++;+ nd->pos = (int16_t)(P.pos * 4);+ nd->color = P.color;+ float delay = P.impact ? 0.0034999999f : P.delay + d;+ nd->delay = (uint16_t)(delay * 10000 + 0.5f);+ nd->flags = (uint8_t)((P.shake ? CF_SHAKE : 0) | (P.wave ? CF_WAVE : 0) | (P.impact ? CF_IMPACT : 0) |+ (is_comma(c) || is_period(c) ? CF_PUNCT : 0) | (P.scale > 1 ? CF_BIG : 0));+ if (P.messed) {+ nd->flags |= CF_MESSED | (rndi(2) ? CF_ROTNEG : 0) | (rndi(2) ? CF_ROTBIG : 0);+ static const int8_t yo[4] = {-3, -6, 3, 6};+ nd->yoff = yo[rndi(4)];+ }+ P.pos += a * P.scale;+ if (!last) P.pos += kern(c, c) * P.scale; /* the game looks up the kerning with the same character */+ }+}++static float parse_float(const char *s, int n, bool *ok) {+ float v = 0, frac = 0, k = 1;+ bool dot = false, neg = false, any = false;+ for (int i = 0; i < n; i++) {+ char c = s[i];+ if (i == 0 && c == '-') neg = true;+ else if (c == '.' && !dot) dot = true;+ else if (c >= '0' && c <= '9') {+ any = true;+ if (dot) k *= 0.1f, frac += (c - '0') * k;+ else v = v * 10 + (c - '0');+ } else {+ *ok = false;+ return 0;+ }+ }+ *ok = any;+ return (neg ? -1 : 1) * (v + frac);+}+static uint16_t hex_color(const char *s, int n) {+ uint32_t v = 0;+ for (int i = 0; i < 6 && i < n; i++) {+ char c = s[i];+ v = v << 4 | (uint32_t)(c >= 'a' ? c - 'a' + 10 : c >= 'A' ? c - 'A' + 10 : c - '0');+ }+ return rgb(v);+}+static bool tok_is(const char *t, int n, const char *s) { return (int)strlen(s) == n && !memcmp(t, s, (size_t)n); }+static bool is_space(char c) { return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' || c == '\v'; }+/* Regex.Split(text, "(\s|\{|\})"): a whitespace character, a brace, or a run of anything else */+static int token(const char *src, int len, int *at, const char **t) {+ int i = *at;+ if (i >= len) return 0;+ *t = src + i;+ if (is_space(src[i]) || src[i] == '{' || src[i] == '}') {+ *at = i + 1;+ return 1;+ }+ int j = i;+ while (j < len && !is_space(src[j]) && src[j] != '{' && src[j] != '}') j++;+ *at = j;+ return j - i;+}++/* FancyText.Parse, going on until the buffer holds the next page (or the text ends) */+static int parse_maxw = MAXW; /* the lines' width (interface pixels) */+static void parse_more(void) {+ if (P.done || !g_res_can_load) return; /* (never while strips are drawn: the decoder uses the strip) */+ int len;+ const char *src = dialog_text(P.key, &len);+ int maxw = parse_maxw;+ for (;;) {+ /* enough: a page beyond what is shown is complete */+ int pages_ahead = 0;+ for (int i = 0; i < nnodes; i++)+ if (nodes[i].type == N_NEWPAGE) pages_ahead++;+ if (pages_ahead >= 2 || nnodes > MAX_NODES - 48) return;+ const char *t;+ int n = token(src, len, &P.src_pos, &t);+ if (!n) break;+ if (!(n == 1 && t[0] == '{')) {+ add_word(t, n, maxw);+ continue;+ }+ /* a command: its name, then its words up to the brace */+ const char *name;+ int nn = token(src, len, &P.src_pos, &name);+ const char *arg[6];+ int argn[6], nargs = 0;+ for (;;) {+ const char *a;+ int an = token(src, len, &P.src_pos, &a);+ if (!an || (an == 1 && a[0] == '}')) break;+ if (an == 1 && is_space(a[0])) continue;+ if (nargs < 6) arg[nargs] = a, argn[nargs++] = an;+ }+ bool ok;+ float f = parse_float(name, nn, &ok);+ if (ok) {+ TNode *w = add_node(N_WAIT);+ if (w) w->v = (uint16_t)(f * 1000 + 0.5f);+ continue;+ }+ if (name[0] == '#') {+ const char *c = nn > 1 ? name + 1 : nargs ? arg[0] : NULL;+ int cn = nn > 1 ? nn - 1 : nargs ? argn[0] : 0;+ if (!cn) {+ P.color = P.ncolors ? P.colors[--P.ncolors] : 0xD69A; /* LightGray */+ continue;+ }+ if (P.ncolors < 8) P.colors[P.ncolors++] = P.color;+ if (tok_is(c, cn, "red")) P.color = 0xF800;+ else if (tok_is(c, cn, "green")) P.color = 0x0400;+ else if (tok_is(c, cn, "blue")) P.color = 0x001F;+ else P.color = hex_color(c, cn);+ continue;+ }+ if (tok_is(name, nn, "break")) {+ calc_line_width();+ P.page++;+ P.line = 0;+ P.pos = 0;+ add_node(N_NEWPAGE);+ } else if (tok_is(name, nn, "n")) {+ add_new_line();+ } else if (tok_is(name, nn, ">>")) {+ float k = nargs ? parse_float(arg[0], argn[0], &ok) : 0;+ P.delay = nargs && ok ? 0.01f / k : 0.01f;+ } else if (tok_is(name, nn, "/>>")) {+ P.delay = 0.01f;+ } else if (tok_is(name, nn, "anchor")) {+ TNode *a = add_node(N_ANCHOR);+ if (a && nargs) a->v = (argn[0] && (arg[0][0] | 32) == 'b') ? 2 : (argn[0] && (arg[0][0] | 32) == 'm') ? 1 : 0;+ } else if (tok_is(name, nn, "portrait") || tok_is(name, nn, "left") || tok_is(name, nn, "right")) {+ int slot;+ if (name[0] == 'p') {+ slot = nports++ % MAX_PORTS;+ Port *pt = &ports[slot];+ memset(pt, 0, sizeof *pt);+ if (nargs && tok_is(arg[0], argn[0], "none")) {+ pt->bank = 254;+ } else if (nargs) {+ int v[8] = {255, 255, 255, 255, 0, 0, 65535, 65535}, k = 0, cur = 0, neg = 0;+ for (int i = 0; i <= argn[0] && k < 8; i++) {+ char c = i < argn[0] ? arg[0][i] : ',';+ if (c == '-') neg = 1;+ else if (c == ',') v[k++] = neg ? -cur : cur, cur = 0, neg = 0;+ else cur = cur * 10 + (c - '0');+ }+ pt->bank = (uint8_t)v[0], pt->begin = (uint8_t)v[1], pt->idle = (uint8_t)v[2], pt->talk = (uint8_t)v[3];+ pt->side = (int8_t)v[4], pt->flags = (uint8_t)v[5], pt->textbox = (uint16_t)v[6], pt->overlay = (uint16_t)v[7];+ P.last_port[pt->side > 0] = slot;+ }+ } else+ slot = P.last_port[name[0] == 'r'];+ TNode *pn = add_node(N_PORTRAIT);+ if (pn) pn->v = (uint16_t)slot;+ } else if (tok_is(name, nn, "trigger") || tok_is(name, nn, "silent_trigger")) {+ int k = 0;+ if (nargs) {+ for (int i = 0; i < argn[0]; i++) k = k * 10 + (arg[0][i] - '0');+ TNode *tn = add_node(N_TRIGGER);+ if (tn) tn->v = (uint16_t)(k | (name[0] == 's' ? 0x8000 : 0));+ }+ } else if (tok_is(name, nn, "*")) P.shake = true;+ else if (tok_is(name, nn, "/*")) P.shake = false;+ else if (tok_is(name, nn, "~")) P.wave = true;+ else if (tok_is(name, nn, "/~")) P.wave = false;+ else if (tok_is(name, nn, "!")) P.impact = true;+ else if (tok_is(name, nn, "/!")) P.impact = false;+ else if (tok_is(name, nn, "%")) P.messed = true;+ else if (tok_is(name, nn, "/%")) P.messed = false;+ else if (tok_is(name, nn, "big")) P.scale = 1.5f;+ else if (tok_is(name, nn, "/big")) P.scale = 1;+ else if (tok_is(name, nn, "s")) {+ int k = 1;+ if (nargs) {+ k = 0;+ for (int i = 0; i < argn[0]; i++) k = k * 10 + (arg[0][i] - '0');+ }+ P.pos += 5 * k;+ } else if (tok_is(name, nn, "savedata")) {+ add_word("Madeline", 8, maxw);+ }+ }+ calc_line_width();+ P.done = true;+}++static void parse_start(const char *key) {+ memset(&P, 0, sizeof P);+ parse_maxw = MAXW;+ strncpy(P.key, key, sizeof P.key - 1);+ P.color = 0xD69A; /* FancyText.DefaultColor: LightGray */+ P.scale = 1;+ P.delay = 0.01f;+ nnodes = base = nports = 0;+ parse_more();+}+/* drops the nodes before the global index `upto` (a page that is done) */+static void drop_before(int upto) {+ int k = upto - base;+ if (k <= 0) return;+ if (k > nnodes) k = nnodes;+ memmove(nodes, nodes + k, sizeof(TNode) * (size_t)(nnodes - k));+ nnodes -= k;+ base += k;+ parse_more();+}+static int node_count(void) { return P.done ? base + nnodes : 1 << 30; }+static TNode *node_at(int i) {+ if (i - base >= nnodes) parse_more();+ return i >= base && i - base < nnodes ? &nodes[i - base] : NULL;+}++/* ---------------------------------------------------------------- Textbox */+typedef struct {+ TextEvent events;+ void *ctx;+ int index, start, page;+ int last; /* the type of the last node done, -1 none */+ float ease, gradient, timer, delay, buildup;+ int co, sub; /* RunRoutine's place, and an inner coroutine's */+ float wait;+ uint8_t anchor, waiting, disable_input, in_trigger, can_skip, easing_open, easing_close, opened, finished;+ uint8_t skip_started, frozen;+ int8_t port; /* the portrait slot shown, -1 none */+ uint8_t port_exists, port_idling;+ Sprite spr;+ Wiggler wiggle;+ uint16_t textbox, overlay;+ uint32_t shake_seed;+ Port cur; /* this.portrait */+ int8_t has_cur;+ int ev;+} Box;+static const EntClass TEXTBOX;+static uint16_t port_tex[48];+static int nport_tex;++static void idle_anim(Box *b) {+ if (!b->port_idling && b->has_cur && b->cur.idle != 255) {+ spr_play(&b->spr, b->cur.idle, false);+ b->port_idling = 1;+ }+}+static void talk_anim(Box *b) {+ if (b->port_idling && b->has_cur && b->cur.talk != 255) {+ spr_play(&b->spr, b->cur.talk, false);+ b->port_idling = 0;+ }+}+static bool continue_pressed(Box *b) {+ uint32_t edge = g_in.keys & ~g_in.prev;+ if (edge & (K_OK | K_JUMP | K_DASH)) return !b->disable_input; /* MenuConfirm, MenuCancel */+ return false;+}++/* the portrait's frames, and those of the animations they go to, kept loaded */+static void load_portrait(const Port *p) {+ nport_tex = 0;+ uint16_t todo[16];+ int ntodo = 0;+ uint8_t seen[32] = {0};+ if (p->begin != 255) todo[ntodo++] = p->begin;+ if (p->idle != 255) todo[ntodo++] = p->idle;+ if (p->talk != 255) todo[ntodo++] = p->talk;+ while (ntodo) {+ uint16_t a = todo[--ntodo];+ if (a < 256 && (seen[a >> 3] >> (a & 7) & 1)) continue;+ if (a < 256) seen[a >> 3] |= (uint8_t)(1 << (a & 7));+ uint16_t tex[32], gotos[8];+ int ng = 0, n = bank_anim_textures(p->bank, a, tex, 32, gotos, &ng);+ for (int i = 0; i < n; i++) {+ bool have = false;+ for (int j = 0; j < nport_tex; j++) have |= port_tex[j] == tex[i];+ if (!have && nport_tex < 48) port_tex[nport_tex++] = tex[i];+ }+ for (int i = 0; i < ng && ntodo < 16; i++)+ if (gotos[i] != 0xFFFF) todo[ntodo++] = gotos[i];+ }+ if (p->textbox != 65535 && nport_tex < 48) port_tex[nport_tex++] = p->textbox;+ if (p->overlay != 65535 && nport_tex < 48) port_tex[nport_tex++] = p->overlay;+ level_extra_textures(port_tex, nport_tex);+}++/* the coroutine: CO_YIELD ends this update; a wait first runs down (Monocle's waitTimer) */+#define CO_BEGIN switch (b->co) { case 0:+#define CO_YIELD do { b->co = __LINE__; return; case __LINE__:; } while (0)+#define CO_WAIT(t) do { b->wait = (t); CO_YIELD; } while (0)+#define CO_END } b->finished = 1++/* EaseOpen / EaseClose as nested coroutines: true while running (an extra update before and after) */+static bool ease_open(Box *b) {+ switch (b->sub) {+ case 0:+ b->sub = 1;+ return true;+ case 1:+ if (b->ease < 1) {+ b->easing_open = 1;+ b->sub = 2;+ } else {+ b->sub = 3;+ return true;+ }+ /* fall through */+ case 2:+ if ((b->ease += RAW_DT / 0.4f) < 1) {+ b->gradient = fmaxf(b->gradient, b->ease);+ return true;+ }+ b->ease = b->gradient = 1;+ b->easing_open = 0;+ b->sub = 3;+ return true;+ default:+ b->sub = 0;+ return false;+ }+}+static bool ease_close(Box *b, bool final) {+ switch (b->sub) {+ case 0:+ b->sub = 1;+ return true;+ case 1:+ b->easing_close = 1;+ b->sub = 2;+ /* fall through */+ case 2:+ if ((b->ease -= RAW_DT / 0.4f) > 0) {+ if (final) b->gradient = b->ease;+ return true;+ }+ b->ease = 0;+ b->easing_close = 0;+ b->sub = 3;+ return true;+ default:+ b->sub = 0;+ return false;+ }+}+#define CO_OPEN do { while (ease_open(b)) CO_YIELD; } while (0)+#define CO_CLOSE(f) do { while (ease_close(b, f)) CO_YIELD; } while (0)++/* RunRoutine: one update of it */+static void run_update(Ent *e) {+ Box *b = ST(e, Box);+ if (b->wait > 0) { /* (the textbox runs on raw time) */+ b->wait -= RAW_DT;+ return;+ }+ TNode *cur;+ CO_BEGIN;+ b->last = -1;+ b->buildup = 0;+ while (b->index < node_count()) {+ cur = node_at(b->index);+ if (!cur) break;+ b->delay = 0;+ if (cur->type == N_ANCHOR) {+ if (b->ease >= 1 && cur->v != b->anchor) CO_CLOSE(false);+ b->anchor = (uint8_t)node_at(b->index)->v;+ } else if (cur->type == N_PORTRAIT) {+ b->port = (int8_t)cur->v;+ {+ Port *next = &ports[b->port];+ if (b->ease >= 1 && (!b->has_cur || next->bank != b->cur.bank || next->side != b->cur.side)) CO_CLOSE(false);+ }+ {+ Port *next = &ports[b->port];+ b->textbox = T__textbox_default;+ b->overlay = 0xFFFF;+ b->port_exists = next->bank < 254;+ if (b->port_exists) {+ if (!b->has_cur || next->bank != b->cur.bank) spr_init(&b->spr, next->bank);+ load_portrait(next);+ b->textbox = next->textbox;+ b->overlay = next->overlay;+ b->can_skip = 0;+ bool changed = !b->has_cur || b->cur.bank != next->bank || b->cur.idle != next->idle ||+ b->cur.talk != next->talk || b->cur.begin != next->begin;+ b->cur = *next;+ b->has_cur = 1;+ if (next->flags & 4) wiggler_restart(&b->wiggle);+ if (!changed) goto opened;+ if (next->begin == 255) goto begun;+ spr_play(&b->spr, next->begin, true);+ } else {+ b->has_cur = 0;+ goto plain;+ }+ }+ CO_OPEN;+ while (b->spr.anim == b->cur.begin && b->spr.playing) CO_YIELD;+ begun:+ if (b->cur.idle != 255) {+ b->port_idling = 1;+ spr_play(&b->spr, b->cur.idle, true);+ }+ opened:+ CO_OPEN;+ b->can_skip = 1;+ goto next_node;+ plain:+ CO_OPEN;+ } else if (cur->type == N_NEWPAGE) {+ idle_anim(b);+ if (b->ease >= 1) {+ b->waiting = 1;+ CO_WAIT(0.1f);+ while (!continue_pressed(b)) CO_YIELD;+ b->waiting = 0;+ }+ b->start = b->index + 1;+ b->page++;+ drop_before(b->start);+ } else if (cur->type == N_WAIT) {+ idle_anim(b);+ b->delay = cur->v / 1000.f;+ } else if (cur->type == N_TRIGGER) {+ b->in_trigger = 1;+ idle_anim(b);+ if (!(node_at(b->index)->v & 0x8000)) CO_CLOSE(false);+ b->ev = node_at(b->index)->v & 0x7FFF;+ if (b->events) { /* yield return events[n](): a nested coroutine */+ CO_YIELD;+ while (!b->events(b->ctx, b->ev)) CO_YIELD;+ CO_YIELD;+ }+ b->in_trigger = 0;+ } else if (cur->type == N_CHAR) {+ if (b->ease < 1) CO_OPEN;+ cur = node_at(b->index);+ {+ bool flag = false;+ if (b->index - 5 > b->start)+ for (int i = b->index; i < b->index + 4 && i < node_count(); i++) {+ TNode *t = node_at(i);+ if (t && t->type == N_NEWPAGE) {+ flag = true;+ idle_anim(b);+ }+ }+ if (!flag && !(cur->flags & CF_PUNCT)) talk_anim(b);+ }+ if (b->last == N_NEWPAGE) {+ b->index--;+ CO_WAIT(0.2f);+ b->index++;+ }+ b->delay = node_at(b->index)->delay / 10000.f + b->buildup;+ }+ next_node:+ b->last = node_at(b->index) ? node_at(b->index)->type : -1;+ b->index++;+ if (b->delay < 0.016f) {+ b->buildup += b->delay;+ continue;+ }+ b->buildup = 0;+ if (b->delay > 0.5f) idle_anim(b);+ CO_WAIT(b->delay);+ }+ idle_anim(b);+ if (b->ease > 0) {+ b->waiting = 1;+ while (!continue_pressed(b)) CO_YIELD;+ b->waiting = 0;+ b->start = node_count();+ CO_CLOSE(true);+ }+ b->opened = 0;+ ent_remove(e);+ level_extra_textures(NULL, 0);+ CO_END;+}++/* SkipDialog */+static void skip_update(Ent *e) {+ Box *b = ST(e, Box);+ if (b->skip_started) b->disable_input = 0;+ b->skip_started = 1;+ if (!b->waiting && b->can_skip && !b->easing_open && !b->easing_close && continue_pressed(b)) {+ b->disable_input = 1;+ for (int guard = 0; guard < 4000 && !b->waiting && b->can_skip && !b->easing_open && !b->easing_close &&+ !b->in_trigger && !b->finished && b->opened;+ guard++)+ run_update(e);+ }+}++static void box_update(Ent *e) {+ Box *b = ST(e, Box);+ if (g_level.frozen || g_level.paused) return; /* FrozenOrPaused */+ skip_update(e);+ if (!b->opened) return;+ run_update(e);+ if (!b->opened) return;+ if (level_on_interval(0.05f)) b->shake_seed = (uint32_t)rndi(1 << 30);+ if (b->port_exists && b->ease >= 1) spr_update(&b->spr);+ b->timer += DT;+ wiggler_update(&b->wiggle);+ int n = b->index < node_count() ? b->index : node_count();+ for (int i = b->start; i < n; i++) {+ TNode *t = node_at(i);+ if (t && t->type == N_CHAR && t->fade < 255) {+ int f = t->fade + (int)(8 * DT * 255 + 0.5f);+ t->fade = (uint8_t)(f > 255 ? 255 : f);+ }+ }+}++/* ---------------------------------------------------------------- drawing */+typedef struct {+ float x, y, sx, sy, alpha; /* the text's origin (screen), scale, alpha */+ int start;+ uint32_t seed;+} FancyDraw;+static FancyDraw TD;++static void blend_px(uint16_t *row, int x, uint16_t col, int a) {+ if ((unsigned)x >= VIEW_W || a <= 0) return;+ row[x] = a >= 255 ? col : blend565(row[x], col, a + 1);+}+/* a glyph of `size` at screen (x, y) (its top-left), scaled by k (nearest pixels) */+static void glyph_strip(uint16_t *strip, int sy0, int sy1, int size, const uint8_t *g, float x, float y, float k,+ uint16_t col, int alpha) {+ int w = g[6], h = g[7];+ if (!w) return;+ const uint8_t *bits = font_glyph_bits(size, g);+ int stride = (w + 1) / 2;+ int W = (int)ceilf(w * k), H = (int)ceilf(h * k);+ int X0 = (int)floorf(x + 0.5f), Y0 = (int)floorf(y + 0.5f);+ for (int r = 0; r < H; r++) {+ int Y = Y0 + r;+ if (Y < sy0 || Y >= sy1) continue;+ int gy = (int)(r / k);+ if (gy >= h) continue;+ uint16_t *row = strip + (Y - sy0) * VIEW_W;+ for (int c = 0; c < W; c++) {+ int gx = (int)(c / k);+ if (gx >= w) continue;+ int v = (bits[gy * stride + (gx >> 1)] >> ((gx & 1) * 4)) & 15;+ if (v) blend_px(row, X0 + c, col, v * 17 * alpha / 255);+ }+ }+}++/* ActiveFont.Draw(text, position, justify, scale, color), in interface units: each line justified+ * by its own width, the block by its height */+static float line_width(const char *s, const char *end, int size) {+ float w = 0;+ while (s < end && *s != '\n') {+ uint32_t c = utf8_next(&s, end);+ const char *q = s;+ uint32_t next = q < end && *q != '\n' ? utf8_next(&q, end) : 0;+ w += font_glyph_advance(size, c, next);+ }+ return w;+}+void text_into(uint16_t *strip, int sy0, int sy1, const char *s, float px, float py, float jx, float jy, float scale,+ uint16_t col, uint8_t alpha) {+ int size = scale > 1.01f ? FONT_M : FONT_S; /* the 64 face, or the 192 one at 1/9 (scale 2) */+ float k = size == FONT_M ? scale / 2 : scale;+ const char *end = s + strlen(s);+ float lh = font_line_height(size), lines = 1;+ for (const char *q = s; q < end; q++) lines += *q == '\n';+ float x0 = px / 6, y = py / 6 - lines * lh * k * jy;+ if (y > sy1 || y + lines * lh * k < sy0) return;+ float x = x0 - line_width(s, end, size) * k * jx;+ while (s < end) {+ uint32_t c = utf8_next(&s, end);+ if (c == '\n') {+ y += lh * k;+ x = x0 - line_width(s, end, size) * k * jx;+ continue;+ }+ const uint8_t *g = font_glyph_rec(size, c);+ if (!g) continue;+ if (y + lh * k >= sy0 && y < sy1)+ glyph_strip(strip, sy0, sy1, size, g, x + rds16(g + 2) / 16.f * k, y + (int16_t)rd16(g + 4) * k, k, col, alpha);+ const char *q = s;+ x += font_glyph_advance(size, c, q < end && *q != '\n' ? utf8_next(&q, end) : 0) * k;+ }+}+static void draw_strip(uint16_t *strip, int sy0, int sy1, void *ctx) {+ const TextDraw *d = ctx;+ text_into(strip, sy0, sy1, d->s, d->x, d->y, d->jx, d->jy, d->scale, d->col, d->alpha);+}+void text_draw(const TextDraw *d) {+ if (!d->s || !d->alpha) return;+ int lines = 1;+ for (const char *q = d->s; *q; q++) lines += *q == '\n';+ int size = d->scale > 1.01f ? FONT_M : FONT_S;+ float k = size == FONT_M ? d->scale / 2 : d->scale, h = lines * font_line_height(size) * k;+ float y = d->y / 6 - h * d->jy;+ gfx_custom(draw_strip, (void *)d, (int)floorf(y) - 1, (int)ceilf(y + h) + 1);+}+/* UISTR: a menu's word from the dialog, straight from flash ("" when there is none) */+const char *ui_str(const char *key) {+ uint32_t h = 2166136261u;+ for (const char *s = key; *s; s++) h = (h ^ (uint8_t)(*s >= 'a' && *s <= 'z' ? *s - 32 : *s)) * 16777619u;+ const uint8_t *d = section(SEC_UISTR);+ int n = rd16(d), lo = 0, hi = n - 1;+ while (lo <= hi) {+ int m = (lo + hi) / 2;+ uint32_t v = rd32(d + 4 + 4 * m);+ if (v == h) return (const char *)d + 4 + 6 * n + rd16(d + 4 + 4 * n + 2 * m);+ if (v < h) lo = m + 1;+ else hi = m - 1;+ }+ return "";+}++/* ActiveFont.Measure(text).X, in interface units at scale 1 */+float text_measure(const char *s) {+ float w = 0;+ const char *end = s + strlen(s);+ while (s < end) {+ float lw = line_width(s, end, FONT_M) * 3; /* the 192 face at 1/9 is the 64 one at 1/3 */+ if (lw > w) w = lw;+ while (s < end && *s != '\n') s++;+ if (s < end) s++;+ }+ return w;+}+/* PixelFontSize.AutoNewline(text, width), in place (the text grows by nothing: spaces become newlines,+ * words wider than the width get one inserted, up to cap) */+void text_auto_newline(char *s, int cap, float width) {+ char out[256];+ int n = 0;+ float num = 0;+ const char *p = s;+ while (*p && n < (int)sizeof out - 2) {+ const char *w = p; /* a word, or one whitespace character (Regex.Split "(\s)") */+ if (*p == ' ' || *p == '\n') p++;+ else+ while (*p && *p != ' ' && *p != '\n') p++;+ char word[128];+ int wl = (int)(p - w) < 127 ? (int)(p - w) : 127;+ memcpy(word, w, (size_t)wl);+ word[wl] = 0;+ float x = text_measure(word);+ if (x + num > width) {+ out[n++] = '\n';+ num = 0;+ if (wl == 1 && word[0] == ' ') continue;+ }+ for (int i = 0; i < wl && n < (int)sizeof out - 1; i++) out[n++] = word[i];+ num += x;+ }+ if (n > cap - 1) n = cap - 1;+ memcpy(s, out, (size_t)n);+ s[n] = 0;+}++/* FancyText.Text.Draw from `start` to its page's end, justified (0.5, 0.5) at TD's origin */+static void text_strip(uint16_t *strip, int sy0, int sy1, void *ctx) {+ (void)ctx;+ int end = node_count();+ float widest = 0, lines = 0, cur = 0;+ for (int i = TD.start; i < end; i++) {+ TNode *t = node_at(i);+ if (!t || t->type == N_NEWPAGE) break;+ if (t->type == N_NEWLINE) {+ if (cur == 0) cur = 1;+ lines += cur;+ cur = 0;+ } else if (t->type == N_CHAR) {+ if (t->width / 4.f > widest) widest = (float)(int)(t->width / 4);+ cur = fmaxf(cur, (t->flags & CF_BIG) ? 1.5f : 1);+ }+ }+ lines += cur;+ /* in interface units, then to the screen */+ float px = TD.x - 0.5f * widest * TD.sx, py = TD.y - 0.5f * lines * 64 * TD.sy;+ cur = 0;+ uint32_t seed = TD.seed;+ for (int i = TD.start; i < end; i++) {+ TNode *t = node_at(i);+ if (!t || t->type == N_NEWPAGE) break;+ if (t->type == N_NEWLINE) {+ if (cur == 0) cur = 1;+ py += 64 * cur * TD.sy;+ cur = 0;+ }+ if (t->type != N_CHAR) continue;+ float fade = t->fade / 255.f, scale = (t->flags & CF_BIG) ? 1.5f : 1;+ cur = fmaxf(cur, scale);+ float num = ((t->flags & CF_IMPACT) ? 2 - fade : 1) * scale;+ float vx = TD.sx * num, vy = TD.sy * num, v = fmaxf(vx, vy);+ float zx = 0, zy = 0;+ if (t->flags & CF_SHAKE) {+ seed = seed * 1103515245u + 12345u;+ zx = (float)((int)((seed >> 16) % 3) - 1) * 2;+ seed = seed * 1103515245u + 12345u;+ zy = (float)((int)((seed >> 16) % 3) - 1) * 2;+ }+ if (t->flags & CF_WAVE) zy += sinf(t->index * 0.25f + g_level.raw_time_active * 8) * 4;+ zy += -8 * (1 - fade) + t->yoff * fade;+ float x = px + t->pos / 4.f * TD.sx;+ /* the 64 face up to its size, the 192 face (shown at 1/6, 32 px) above */+ int size = v > 1.01f ? FONT_M : FONT_S;+ float k = size == FONT_M ? v / 2 : v;+ const uint8_t *g = font_glyph_rec(size, t->v);+ if (!g) continue;+ float gx = (x + zx * vx) / 6 + rds16(g + 2) / 16.f * k, gy = (py + zy * vy) / 6 + (int16_t)rd16(g + 4) * k;+ int a = (int)(fade * TD.alpha * 255);+ glyph_strip(strip, sy0, sy1, size, g, gx, gy, k, t->color, a);+ }+}++static void box_render(Ent *e) {+ Box *b = ST(e, Box);+ if (g_level.frozen || g_level.paused) return;+ float num = ease_cube_inout(b->ease);+ if (num < 0.05f) return;+ float vx = 116, vy = 58; /* interface units */+ if (b->anchor == 2) vy = 1080 - 58 - 272;+ else if (b->anchor == 1) vy = 404;+ vy += (int)(136 * (1 - num));+ gfx_hud(true);+ /* the box, squashed while it opens */+ float cx = (vx + 844) / 6, cy = (vy + 272 * num / 2) / 6;+ Tex t;+ if (tex_get(b->textbox, &t))+ gfx_tex_ex(b->textbox, cx, cy, t.fw * t.scale / 2.f, t.fh * t.scale / 2.f, 1, num, 0, 0xFFFF, 255, 0);+ else if (tex_get(T__textbox_default, &t))+ gfx_tex_ex(T__textbox_default, cx, cy, t.fw / 2.f, t.fh / 2.f, 1, num, 0, 0xFFFF, 255, 0);+ if (b->waiting) {+ float w = (!b->has_cur || b->cur.side < 0) ? 1688 : 1432;+ float bx = vx + w - 48, by = vy + 272 - 40 + (fmodf(b->timer, 1) < 0.25f ? 6 : 0);+ if (tex_get(T__textboxbutton, &t)) gfx_tex_ex(T__textboxbutton, bx / 6, by / 6, t.fw / 2.f, t.fh / 2.f, 1, 1, 0, 0xFFFF, 255, 0);+ }+ if (b->port_exists && b->has_cur) {+ Sprite s = b->spr;+ float px = b->cur.side > 0 ? vx + 1688 - 240 - 16 : vx + 16;+ float sx = b->cur.side > 0 ? -1.f : 1.f; /* (the frames are stored at the portrait's 1.5 scale) */+ if (b->cur.flags & 2) sx = -sx;+ float sy = ((272 * num - 32) / 240) * ((b->cur.flags & 1) ? -1 : 1);+ float w = 0.9f + b->wiggle.value * 0.1f;+ s.sx = sx * w, s.sy = sy * w;+ s.flipx = s.sx < 0, s.flipy = s.sy < 0;+ s.sx = fabsf(s.sx), s.sy = fabsf(s.sy);+ s.alpha = (uint8_t)(255 * num);+ if (fabsf(sy * w) > 0.05f) spr_draw(&s, (px + 120) / 6, (vy + 272 * num * 0.5f) / 6);+ }+ if (b->overlay != 0xFFFF && tex_get(b->overlay, &t)) {+ int f = b->has_cur && b->cur.side > 0 ? GF_FLIPX : 0;+ gfx_tex_ex(b->overlay, cx, cy, t.fw / 2.f, t.fh / 2.f, 1, num, 0, 0xFFFF, 255, (uint8_t)f);+ }+ /* the text */+ int lines = 1;+ for (int i = b->start; i < node_count(); i++) {+ TNode *n = node_at(i);+ if (!n || n->type == N_NEWPAGE) break;+ if (n->type == N_NEWLINE) lines++;+ }+ float ox = PAD + (b->has_cur && b->cur.side < 0 ? 256 : 0), oy = PAD;+ float hx = (!b->has_cur ? MAXW_NOPORT : MAXW) / 2.f, hy = LINES * LINE_H * num / 2;+ float k = lines >= 4 ? 0.75f : 1;+ TD = (FancyDraw){vx + ox + hx, vy + oy + hy, k, num * k, num, b->start, b->shake_seed};+ gfx_custom(text_strip, NULL, (int)((vy) / 6) - 4, (int)((vy + 272) / 6) + 8);+ gfx_hud(false);+}++static const EntClass TEXTBOX = {.size = sizeof(Box), .name = "textbox", .update = box_update, .render = box_render};++Ent *textbox_say(const char *key, TextEvent events, void *ctx) {+ for (int i = 0; i < g_nents; i++) /* one at a time: the nodes are shared */+ if (g_ents[i].cls == &TEXTBOX && g_ents[i].dead != 1) ent_remove(&g_ents[i]);+ Ent *e = ent_new(&TEXTBOX, 0, 0);+ if (!e) return NULL;+ e->tags = TAG_PAUSE_UPDATE | TAG_HUD;+ e->collidable = 0;+ Box *b = ST(e, Box);+ b->events = events, b->ctx = ctx;+ b->opened = 1;+ b->can_skip = 1;+ b->port = -1;+ b->textbox = T__textbox_default;+ b->overlay = 0xFFFF;+ wiggler_init(&b->wiggle, 0.4f, 4);+ parse_start(key);+ return e;+}+/* Textbox.PortraitName / PortraitAnimation: the shown portrait's bank and its idle animation */+bool textbox_portrait(int *bank, int *idle) {+ for (int i = 0; i < g_nents; i++) {+ Ent *e = &g_ents[i];+ if (e->cls != &TEXTBOX || e->dead == 1) continue;+ Box *b = ST(e, Box);+ if (!b->has_cur || b->cur.bank >= 254) return false;+ *bank = b->cur.bank, *idle = b->cur.idle;+ return true;+ }+ return false;+}+bool textbox_opened(const Ent *e) { return e && e->cls == &TEXTBOX && e->dead != 1 && ST(e, Box)->opened; }+void textbox_set_frozen(Ent *e) {+ if (e) e->tags |= TAG_FROZEN_UPDATE;+}++/* ---------------------------------------------------------------- MiniTextbox */+/* a line or two at the top of the screen, a portrait beside, while the game goes on; it closes by itself */+#define MINI_LEN 120+typedef struct {+ float ease, wait;+ uint8_t co, closing, has_port, nlines;+ int index, len;+ Port port;+ Sprite spr;+ uint16_t box;+ char text[MINI_LEN]; /* UTF-8, '\n' between the lines */+ uint8_t delay[MINI_LEN]; /* each character's delay, in 2 ms */+ char line[3][MINI_LEN / 2];+ TextDraw td[3];+} Mini;+static const EntClass MINI;+static int utf8_len(uint8_t c) { return c < 0x80 ? 1 : c < 0xE0 ? 2 : c < 0xF0 ? 3 : 4; }+static void mini_update(Ent *e) {+ Mini *m = ST(e, Mini);+ if (!m->closing && (g_player.dead || g_level.transitioning)) m->closing = 1; /* RetryPlayerCorpse; OnOutBegin */+ if (m->has_port) spr_update(&m->spr);+ if (m->closing) {+ if ((m->ease -= RAW_DT * 4) <= 0) ent_remove(e);+ return;+ }+ if (m->wait > 0) { /* (on raw time) */+ m->wait -= RAW_DT;+ return;+ }+ switch (m->co) {+ case 0:+ if ((m->ease += RAW_DT * 4) < 1) return;+ m->ease = 1;+ m->co = 1;+ if (m->has_port && m->port.begin != 255) {+ spr_play(&m->spr, m->port.begin, false);+ return;+ }+ /* fall through */+ case 1:+ if (m->has_port && m->port.begin != 255 && m->spr.anim == m->port.begin && m->spr.playing) return;+ if (m->has_port && m->port.talk != 255) spr_play(&m->spr, m->port.talk, false);+ m->co = 2;+ /* fall through */+ case 2: {+ float num = 0;+ while (m->index < m->len) {+ num += m->delay[m->index++] * 0.002f;+ if (num > 0.016f) {+ m->wait = num;+ return;+ }+ }+ if (m->has_port && m->port.idle != 255) spr_play(&m->spr, m->port.idle, false);+ m->wait = 3;+ m->co = 3;+ return;+ }+ default: m->closing = 1; return;+ }+}+static void mini_render(Ent *e) {+ Mini *m = ST(e, Mini);+ if (m->ease <= 0 || g_level.frozen || g_level.paused || g_player.dead || g_level.skipping_cutscene) return;+ gfx_hud(true);+ Tex t;+ float cy = 130; /* 72 + (1920 - 1688) / 4 */+ if (tex_get(m->box, &t)) gfx_tex_ex(m->box, 160, cy / 6, t.fw * t.scale / 2.f, t.fh * t.scale / 2.f, 1, m->ease, 0, 0xFFFF, 255, 0);+ if (m->has_port) { /* 112 interface pixels (the frames are kept for 240) */+ Sprite s = m->spr;+ s.sx = 112.f / 240, s.sy = 112.f / 240 * m->ease;+ spr_draw(&s, 188 / 6.f, cy / 6);+ }+ /* the characters shown so far, a line at a time (the text keeps its place as it grows) */+ int l = 0, k = 0, c = 0;+ for (int i = 0; i < 3; i++) m->line[i][0] = 0;+ for (const char *p = m->text; *p && c < m->index && l < 3; c++) {+ if (*p == '\n') {+ m->line[l][k] = 0;+ l++, k = 0, p++;+ continue;+ }+ int n = utf8_len((uint8_t)*p);+ if (k + n < MINI_LEN / 2) memcpy(&m->line[l][k], p, (size_t)n), k += n;+ p += n;+ }+ if (l < 3) m->line[l][k] = 0;+ float lh = LINE_H * 0.75f * m->ease;+ for (int i = 0; i < m->nlines && i < 3; i++) {+ if (!m->line[i][0]) continue;+ m->td[i] = (TextDraw){m->line[i], 276, cy - m->nlines * lh / 2 + i * lh, 0, 0, 0.75f, 0xD69A, 255};+ text_draw(&m->td[i]);+ }+ gfx_hud(false);+}+static const EntClass MINI = {.size = sizeof(Mini), .name = "miniTextbox", .update = mini_update, .render = mini_render};++Ent *mini_textbox(const char *key) {+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &TEXTBOX && g_ents[i].dead != 1) return NULL; /* (the nodes are the textbox's) */+ bool others = false;+ for (int i = 0; i < g_nents; i++)+ if (g_ents[i].cls == &MINI && g_ents[i].dead != 1) ST(&g_ents[i], Mini)->closing = 1, others = true;+ Ent *e = ent_new(&MINI, 0, 0);+ if (!e) return NULL;+ e->tags = TAG_HUD | TAG_TRANSITION_UPDATE;+ e->collidable = 0;+ Mini *m = ST(e, Mini);+ m->box = T__textbox_default_mini;+ m->wait = others ? 0.3f : 0;+ memset(&P, 0, sizeof P); /* FancyText.Parse(text, 1688 - 112 - 32, 2) */+ strncpy(P.key, key, sizeof P.key - 1);+ P.color = 0xD69A, P.scale = 1, P.delay = 0.01f;+ nnodes = base = nports = 0;+ parse_maxw = 1544;+ parse_more();+ parse_maxw = MAXW;+ int at = 0;+ m->nlines = 1;+ for (int i = 0; i < nnodes; i++) {+ TNode *n = &nodes[i];+ if (n->type == N_NEWPAGE) break;+ if (n->type == N_PORTRAIT && !m->has_port && ports[n->v].bank < 254) {+ m->port = ports[n->v];+ m->has_port = 1;+ spr_init(&m->spr, m->port.bank);+ if (m->port.idle != 255) spr_play(&m->spr, m->port.idle, false);+ m->box = m->port.textbox == T__textbox_theo ? T__textbox_theo_mini+ : m->port.textbox == T__textbox_badeline ? T__textbox_badeline_mini : T__textbox_default_mini;+ } else if ((n->type == N_CHAR || n->type == N_NEWLINE) && at < MINI_LEN - 4 && m->len < MINI_LEN) {+ uint32_t c = n->type == N_NEWLINE ? '\n' : n->v;+ if (c == '\n') {+ if (!at || m->nlines >= 3) continue;+ m->nlines++;+ }+ if (c < 0x80) m->text[at++] = (char)c;+ else if (c < 0x800) m->text[at++] = (char)(0xC0 | c >> 6), m->text[at++] = (char)(0x80 | (c & 63));+ else m->text[at++] = (char)(0xE0 | c >> 12), m->text[at++] = (char)(0x80 | (c >> 6 & 63)), m->text[at++] = (char)(0x80 | (c & 63));+ m->delay[m->len++] = n->type == N_CHAR ? (uint8_t)(n->delay < 5100 ? n->delay / 20 : 255) : 0;+ }+ }+ m->text[at] = 0;+ P.done = true, nnodes = 0; /* (the next textbox starts over) */+ return e;+}diff --git a/games/celeste/src/text.h b/games/celeste/src/text.hnew file mode 100644index 00000000..5abd26c2--- /dev/null+++ b/games/celeste/src/text.h@@ -0,0 +1,35 @@+/* Dialog: Celeste's Textbox (with portraits) laying out its text like+ * FancyText, from the English dialog in data.bin. */+#ifndef TEXT_H+#define TEXT_H+#include "ent.h"++/* a {trigger n} in the dialog runs the cutscene's event n: called every frame until it returns true */+typedef bool (*TextEvent)(void *ctx, int index);++/* Textbox.Say: opens a textbox (an entity); it is done when textbox_opened() is false */+Ent *textbox_say(const char *key, TextEvent events, void *ctx);+bool textbox_opened(const Ent *tb);+bool textbox_portrait(int *bank, int *idle); /* Textbox.PortraitName/PortraitAnimation: the portrait's bank, idle anim */+void textbox_set_frozen(Ent *tb); /* SayWhileFrozen */+Ent *mini_textbox(const char *key); /* new MiniTextbox(dialogId): at the top, while playing */++/* Dialog.Get / Dialog.Clean: the text of a key (cleaned of its commands), into buf */+int dialog_clean(const char *key, char *buf, int cap);+bool dialog_has(const char *key);+/* ActiveFont.Draw: s at (x, y) in interface units (1920x1080), justified, scaled; d must live until+ * the frame is drawn (its strips are drawn at gfx_end) */+typedef struct {+ const char *s;+ float x, y, jx, jy, scale;+ uint16_t col;+ uint8_t alpha;+} TextDraw;+void text_draw(const TextDraw *d);+float text_measure(const char *s); /* ActiveFont.Measure(s).X */+/* ActiveFont.Draw into a strip, from a gfx_custom callback (nothing kept: menus redraw their words per strip) */+void text_into(uint16_t *strip, int sy0, int sy1, const char *s, float x, float y, float jx, float jy, float scale,+ uint16_t col, uint8_t alpha);+const char *ui_str(const char *key); /* the menus' words (UISTR) */+void text_auto_newline(char *s, int cap, float width); /* PixelFontSize.AutoNewline */+#endifdiff --git a/games/celeste/src/tiles.c b/games/celeste/src/tiles.cnew file mode 100644index 00000000..a3d1c9b7--- /dev/null+++ b/games/celeste/src/tiles.c@@ -0,0 +1,395 @@+/* Tiles: Celeste's autotiler (ForegroundTiles.xml, BackgroundTiles.xml, as+ * converted by tools/pack.py) run on the room's tile types, the visible tiles+ * cached between frames, and the tile layers and decals as entities. */+#include "level.h"++/* ---------------------------------------------------------------- terrain tables */+static const uint8_t *terrain(int t) {+ const uint8_t *s = section(SEC_TILESETS);+ return s + rd32(s + 260 + 4 * t);+}+int terrain_of(int layer, char c) {+ if ((uint8_t)c >= 128) return -1;+ uint8_t t = section(SEC_TILESETS)[layer * 128 + (uint8_t)c];+ return t == 255 ? -1 : t;+}+uint16_t terrain_tex(int t) { return rd16(terrain(t)); }+/* the cache keeps a layer's own terrain numbers (5 bits): the bg's start after the fg's */+static int layer_base(int layer) {+ static int fg_count = -1;+ if (!layer) return 0;+ if (fg_count < 0) {+ const uint8_t *tab = section(SEC_TILESETS);+ fg_count = 0;+ for (int i = 0; i < 128; i++)+ if (tab[i] != 255 && tab[i] + 1 > fg_count) fg_count = tab[i] + 1;+ }+ return fg_count;+}++static bool ignores(const uint8_t *T, char self_type, char c) {+ /* TerrainType.Ignore: other types in the list, or all with '*' */+ int n = T[2];+ if (c == self_type) return false;+ bool all = false;+ for (int i = 0; i < n; i++) {+ if (T[3 + i] == (uint8_t)c) return true;+ if (T[3 + i] == '*') all = true;+ }+ return all;+}++static inline uint32_t hash3(int x, int y, int z) {+ uint32_t h = (uint32_t)x * 73856093u ^ (uint32_t)y * 19349663u ^ (uint32_t)z * 83492791u;+ h ^= h >> 13;+ h *= 0x5bd1e995u;+ return h ^ (h >> 15);+}++/* tile types around (x, y) come from get(); in_level(x, y) tells whether a cell+ * belongs to the same room (PaddingIgnoreOutOfLevel). Returns the quad or -1,+ * and the overlay sprite (0: none) in *ov. */+typedef char (*GetFn)(int x, int y, void *ctx);+typedef struct { GetFn get; void *ctx; bool (*in_level)(int x, int y, void *ctx); bool edges_ignore_out; } AutoCtx;++static int autotile_at(int layer, char c, const AutoCtx *a, int x, int y, int *ov, int salt) {+ int t = terrain_of(layer, c);+ if (t < 0) return -1;+ const uint8_t *T = terrain(t);+ int nign = T[2];+ const uint8_t *p = T + 3 + nign;+ int nmask = p[0], npad = p[1], ncen = p[2];+ p += 3;+ static const int8_t dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1}, dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};+ uint8_t adj = 0;+ for (int k = 0; k < 8; k++) {+ char n = a->get(x + dx[k], y + dy[k], a->ctx);+ bool on = n != '0' && n != 0 && !ignores(T, c, n);+ if (!on && a->edges_ignore_out && a->in_level && !a->in_level(x + dx[k], y + dy[k], a->ctx)) on = true;+ if (on) adj |= (uint8_t)(1 << (7 - k));+ }+ *ov = 0;+ uint32_t h = hash3(x, y, layer * 7 + salt);+ if (adj == 0xFF) {+ /* padding where a tile two away (in this room) is empty */+ static const int8_t px[4] = {-2, 2, 0, 0}, py[4] = {0, 0, -2, 2};+ bool padded = false;+ for (int k = 0; k < 4 && !padded; k++) {+ char n = a->get(x + px[k], y + py[k], a->ctx);+ bool on = n != '0' && n != 0 && !ignores(T, c, n);+ if (!on && (!a->in_level || a->in_level(x + px[k], y + py[k], a->ctx))) padded = true;+ }+ const uint8_t *m = p;+ for (int i = 0; i < nmask; i++) m += 4 + m[2];+ if (padded) return npad ? m[h % npad] : -1;+ return ncen ? m[npad + h % ncen] : -1;+ }+ for (int i = 0; i < nmask; i++) {+ uint8_t bits = p[0], care = p[1], n = p[2];+ if (((bits ^ adj) & care) == 0) {+ *ov = p[3];+ return n ? p[4 + h % n] : -1;+ }+ p += 4 + n;+ }+ return -1;+}++int autotile(int layer, char (*get)(int x, int y, void *ctx), void *ctx, int x, int y, uint8_t *quad, int variant) {+ AutoCtx a = {get, ctx, NULL, false};+ int ov;+ int q = autotile_at(layer, get(x, y, ctx), &a, x, y, &ov, variant);+ if (q < 0) return 0;+ *quad = (uint8_t)q;+ return 1;+}++/* ---------------------------------------------------------------- the room's tiles, cached */+#define TC_W 42+#define TC_H 25+typedef struct {+ int cx, cy; /* top-left cell */+ bool valid;+ uint16_t cell[TC_H][TC_W]; /* terrain (5 bits; 31 none, 30 scenery) | quad << 5 (9 bits) | overlay << 14 */+} TileCache;+#define C_TERR(v) ((v) & 31)+#define C_QUAD(v) (((v) >> 5) & 511)+#define C_OV(v) ((v) >> 14)+#define TERR_SCENERY 30+static TileCache tcache[2];++void tiles_invalidate(void) { tcache[0].valid = tcache[1].valid = false; }++typedef struct { int layer; const Room *room; } RoomCtx;+static char room_get(int x, int y, void *ctx) { return level_tile_type(((RoomCtx *)ctx)->layer, x, y); }+static bool in_room(const Room *rm, int x, int y) {+ int px = x * 8, py = y * 8;+ return rm && px >= rm->x && px < rm->x + rm->w && py >= rm->y && py < rm->y + rm->h;+}+/* CheckForSameLevel: the other cell is in the room of the cell being tiled */+static bool room_in_level(int x, int y, void *ctx) { return in_room(((RoomCtx *)ctx)->room, x, y); }++static void fill_cache(int layer, int cx, int cy) {+ TileCache *c = &tcache[layer];+ c->cx = cx, c->cy = cy, c->valid = true;+ RoomCtx rc = {layer, NULL};+ /* padding looks only inside the cell's room for the fg (PaddingIgnoreOutOfLevel), anywhere for the bg */+ AutoCtx a = {room_get, &rc, layer == 0 ? room_in_level : NULL, false};+ for (int r = 0; r < TC_H; r++)+ for (int k = 0; k < TC_W; k++) {+ int x = cx + k, y = cy + r;+ char t = level_tile_type(layer, x, y);+ c->cell[r][k] = 31;+ if (t == '0') continue;+ rc.room = in_room(g_level.room, x, y) ? g_level.room : &g_level.rooms[g_level.room_slot ^ 1];+ if (rc.room->index < 0 || !in_room(rc.room, x, y)) rc.room = g_level.room;+ int ov;+ int q = autotile_at(layer, t, &a, x, y, &ov, 0);+ if (q < 0) continue;+ c->cell[r][k] = (uint16_t)((terrain_of(layer, t) - layer_base(layer)) | q << 5 | (ov & 3) << 14);+ }+ /* scenery tiles over the autotiled ones (fgtiles, bgtiles) */+ for (int s = 0; s < 2; s++) {+ Room *rm = &g_level.rooms[s];+ if (rm->index < 0) continue;+ const uint8_t *p = rm->scen[layer];+ for (int i = 0; i < rm->nscen[layer]; i++, p += 6) {+ int x = rm->x / 8 + rd16(p) - cx, y = rm->y / 8 + rd16(p + 2) - cy;+ if ((unsigned)x < TC_W && (unsigned)y < TC_H) c->cell[y][x] = (uint16_t)(TERR_SCENERY | rd16(p + 4) << 5);+ }+ }+}++/* one 8x8 tile of a 4-bit tile sheet; pal: the sheet's 16 colors, opaque: no+ * see-through colors besides index 0 */+static void blit_tile(uint16_t *strip, int sy0, int sy1, const Tex *t, const uint16_t *pal, const uint8_t *alpha, bool opaque,+ int q, int x, int y) {+ int tx = (q & 7) * 8, ty = (q >> 3) * 8;+ int r0 = sy0 - y, r1 = sy1 - y;+ if (r0 < 0) r0 = 0;+ if (r1 > 8) r1 = 8;+ int stride = t->w >> 1;+ const uint8_t *src = t->px + (ty + r0) * stride + (tx >> 1);+ uint16_t *d = strip + (y + r0 - sy0) * VIEW_W + x;+ bool clip = x < 0 || x > VIEW_W - 8;+ for (int r = r0; r < r1; r++, src += stride, d += VIEW_W) {+ uint32_t v = src[0] | src[1] << 8 | src[2] << 16 | (uint32_t)src[3] << 24;+ if (!v) continue;+ if (!clip && opaque) {+ for (int i = 0; i < 8; i++, v >>= 4)+ if (v & 15) d[i] = pal[v & 15];+ continue;+ }+ for (int i = 0; i < 8; i++, v >>= 4) {+ int c = v & 15;+ if (!c || (unsigned)(x + i) >= VIEW_W) continue;+ if (alpha[c] == 255) d[i] = pal[c];+ else d[i] = blend565(d[i], pal[c], alpha[c] + 1);+ }+ }+}++void blit_part_ex(uint16_t *strip, int sy0, int sy1, const Tex *t, int x, int y, int sx, int sy, int w, int h, uint8_t flags,+ uint16_t tint, uint8_t alpha);+static void scenery_tile(uint16_t *strip, int y0, int y1, const Tex *t, int sx, int sy, int x, int y) {+ blit_part_ex(strip, y0, y1, t, x, y, sx, sy, 8, 8, 0, 0xFFFF, 255);+}++static void layer_strip(uint16_t *strip, int y0, int y1, void *ctx) {+ int layer = (int)(intptr_t)ctx;+ TileCache *c = &tcache[layer];+ int ox = c->cx * 8 - g_camx, oy = c->cy * 8 - g_camy;+ Tex texs[4];+ uint16_t pals[4][16];+ uint8_t alphas[4][16];+ bool opaque[4];+ int tids[4] = {-1, -1, -1, -1};+ for (int r = 0; r < TC_H; r++) {+ int y = oy + r * 8;+ if (y + 8 <= y0 || y >= y1) continue;+ for (int k = 0; k < TC_W; k++) {+ uint16_t v = c->cell[r][k];+ uint8_t t = C_TERR(v);+ if (t == 31) continue;+ if (t == TERR_SCENERY) {+ Tex sc;+ if (tex_get(T_tilesets_scenery, &sc)) {+ int q = C_QUAD(v);+ scenery_tile(strip, y0, y1, &sc, (q % 30) * 8, (q / 30) * 8, ox + k * 8, y);+ }+ continue;+ }+ int slot = t & 3;+ if (tids[slot] != t) {+ if (!tex_get(terrain_tex(t + layer_base(layer)), &texs[slot])) continue;+ tids[slot] = t;+ int n;+ const uint16_t *pc = pal_colors(texs[slot].pal, &n);+ const uint8_t *pa = pal_alpha(texs[slot].pal);+ opaque[slot] = true;+ for (int i = 0; i < 15; i++) {+ pals[slot][i + 1] = i < n ? pc[i] : 0;+ alphas[slot][i + 1] = i < n ? pa[i] : 255;+ if (i < n && pa[i] != 255) opaque[slot] = false;+ }+ }+ blit_tile(strip, y0, y1, &texs[slot], pals[slot], alphas[slot], opaque[slot], C_QUAD(v), ox + k * 8, y);+ }+ }+}++static float anim_time;++void tiles_render_layer(int layer, int depth) {+ (void)depth;+ int cx = (int)floorf(g_camx / 8.f), cy = (int)floorf(g_camy / 8.f);+ TileCache *c = &tcache[layer];+ if (!c->valid || c->cx != cx || c->cy != cy) fill_cache(layer, cx, cy);+ /* the tile sheets in view, loaded now (the strips are drawn from the cache, where nothing can load) */+ uint32_t terrains = 0;+ for (int r = 0; r < TC_H; r++)+ for (int k = 0; k < TC_W; k++) terrains |= 1u << C_TERR(c->cell[r][k]);+ Tex t;+ for (int k = 0; k < 30; k++)+ if (terrains >> k & 1) tex_get(terrain_tex(k + layer_base(layer)), &t);+ if (terrains >> TERR_SCENERY & 1) tex_get(T_tilesets_scenery, &t);+ gfx_custom(layer_strip, (void *)(intptr_t)layer, 0, VIEW_H);+ /* animated overlays (grass) */+ const uint8_t *at = section(SEC_ANIMTILES);+ int n = rd16(at);+ if (!n) return;+ for (int r = 0; r < TC_H; r++)+ for (int k = 0; k < TC_W; k++) {+ int ov = C_OV(c->cell[r][k]);+ if (!ov || C_TERR(c->cell[r][k]) == 31 || ov > n) continue;+ const uint8_t *a = at + 4;+ for (int i = 1; i < ov; i++) a += 10 + 2 * rd16(a + 8);+ float delay = rdf(a);+ int frames = rd16(a + 8);+ if (!frames) continue;+ uint32_t h = hash3(c->cx + k, c->cy + r, 99);+ int f = ((int)(anim_time / delay) + (int)(h % frames)) % frames;+ uint16_t tex = rd16(a + 10 + 2 * f);+ float x = (c->cx + k) * 8.f + (int8_t)a[4] + 4, y = (c->cy + r) * 8.f + (int8_t)a[5] + 4;+ gfx_tex_ex(tex, x, y, (float)(int8_t)a[6], (float)(int8_t)a[7], (h & 1) ? -1.f : 1.f, 1, 0, 0xFFFF, 255, 0);+ }+}++/* ---------------------------------------------------------------- boxes of tiles (blocks) */+typedef struct { char type; int w, h; } BoxCtx;+static char box_get(int x, int y, void *ctx) {+ BoxCtx *b = ctx;+ return x >= 0 && y >= 0 && x < b->w && y < b->h ? b->type : '0';+}+void tiles_box(char type, int w, int h, TileQ *out) {+ BoxCtx b = {type, w, h};+ AutoCtx a = {box_get, &b, NULL, false};+ int t = terrain_of(0, type);+ for (int y = 0; y < h; y++)+ for (int x = 0; x < w; x++) {+ int ov;+ int q = autotile_at(0, type, &a, x, y, &ov, 3);+ out[y * w + x].terrain = q < 0 ? 255 : (uint8_t)t;+ out[y * w + x].quad = q < 0 ? 0 : (uint8_t)q;+ }+}++typedef struct { char type; int x, y, w, h; } OverCtx;+static char over_get(int x, int y, void *ctx) {+ OverCtx *o = ctx;+ if (x >= o->x && y >= o->y && x < o->x + o->w && y < o->y + o->h) return o->type;+ return level_tile_type(0, x, y);+}+static bool over_in(int x, int y, void *ctx) {+ (void)ctx;+ return in_room(g_level.room, x, y);+}+void tiles_overlay(char type, int x, int y, int w, int h, TileQ *out) {+ OverCtx o = {type, x, y, w, h};+ AutoCtx a = {over_get, &o, over_in, true};+ int t = terrain_of(0, type);+ for (int j = 0; j < h; j++)+ for (int i = 0; i < w; i++) {+ int ov;+ int q = autotile_at(0, type, &a, x + i, y + j, &ov, 0);+ out[j * w + i].terrain = q < 0 ? 255 : (uint8_t)t;+ out[j * w + i].quad = q < 0 ? 0 : (uint8_t)q;+ }+}++void tiles_draw(const TileQ *q, int w, int h, float x, float y, uint16_t tint, uint8_t alpha) {+ for (int j = 0; j < h; j++)+ for (int i = 0; i < w; i++) {+ const TileQ *t = &q[j * w + i];+ if (t->terrain == 255) continue;+ uint16_t tex = terrain_tex(t->terrain);+ gfx_tex_part(tex, x + i * 8, y + j * 8, (t->quad & 7) * 8, (t->quad >> 3) * 8, 8, 8, 0, tint, alpha);+ }+}++/* ---------------------------------------------------------------- decals */+static int decal_frames(uint16_t tex) {+ const uint8_t *s = section(SEC_DECALANIM);+ int n = rd16(s), lo = 0, hi = n - 1;+ while (lo <= hi) {+ int m = (lo + hi) / 2;+ uint16_t t = rd16(s + 2 + 4 * m);+ if (t == tex) return rd16(s + 4 + 4 * m);+ if (t < tex) lo = m + 1;+ else hi = m - 1;+ }+ return 1;+}++void decals_render(bool fg) {+ for (int s = 0; s < 2; s++) {+ Room *rm = &g_level.rooms[s];+ if (rm->index < 0) continue;+ int n = fg ? rm->nfg : rm->nbg;+ const uint8_t *tab = fg ? rm->decals_fg : rm->decals_bg; /* u8 textures, (pad), u16 ids, x[n], y[n], v[n] */+ const uint8_t *ids = tab + 2, *xs = ids + 2 * tab[0], *ys = xs + 2 * n, *vs = ys + 2 * n;+ for (int i = 0; i < n; i++) {+ uint8_t v = vs[i];+ uint16_t tex = rd16(ids + 2 * (v & 63));+ float x = rm->x + (float)rds16(xs + 2 * i), y = rm->y + (float)rds16(ys + 2 * i);+ int frames = decal_frames(tex);+ if (frames > 1) tex = (uint16_t)(tex + (int)(anim_time * 12) % frames);+ /* cull by the frame's size (TEXDIM), before loading it */+ float r = (float)tex_half_extent(tex);+ if (x + r < g_camx || x - r > g_camx + 320 || y + r < g_camy || y - r > g_camy + 180) continue;+ Tex t;+ if (!tex_get(tex, &t)) continue;+ float hw = t.fw * t.scale / 2.f, hh = t.fh * t.scale / 2.f;+ gfx_tex_ex(tex, x, y, hw, hh, (v & 0x40) ? -1.f : 1.f, (v & 0x80) ? -1.f : 1.f, 0, 0xFFFF, 255, 0);+ }+ }+}++/* ---------------------------------------------------------------- the layers as entities */+static void bg_render(Ent *e) { (void)e; tiles_render_layer(1, D_BGTERRAIN); }+static void fg_render(Ent *e) {+ (void)e;+ tiles_render_layer(0, D_FGTERRAIN);+}+static void fgdecal_render(Ent *e) { (void)e; decals_render(true); }+static void bgdecal_render(Ent *e) { (void)e; decals_render(false); }+static void timer_update(Ent *e) { (void)e; anim_time += DT; }++static const EntClass BGTILES = {.size = 0, .name = "bgtiles", .render = bg_render, .update = timer_update};+static const EntClass SOLIDTILES = {.size = 0, .name = "solidtiles", .render = fg_render, .kind = KIND_SOLID};+static const EntClass FGDECALS = {.size = 0, .name = "fgdecals", .render = fgdecal_render};+static const EntClass BGDECALS = {.size = 0, .name = "bgdecals", .render = bgdecal_render};++void level_tiles_entities(void) {+ Ent *e = ent_new(&BGTILES, 0, 0);+ e->depth = D_BGTERRAIN, e->tags = TAG_GLOBAL | TAG_TRANSITION_UPDATE, e->dead = 0, e->collidable = 0;+ e = ent_new(&BGDECALS, 0, 0);+ e->depth = D_BGDECALS, e->tags = TAG_GLOBAL, e->dead = 0, e->collidable = 0;+ e = ent_new(&SOLIDTILES, 0, 0);+ e->depth = D_FGTERRAIN, e->tags = TAG_GLOBAL, e->dead = 0;+ e->ctype = COL_GRID;+ e->safe = 1;+ g_solidtiles = e;+ e = ent_new(&FGDECALS, 0, 0);+ e->depth = D_FGDECALS, e->tags = TAG_GLOBAL, e->dead = 0, e->collidable = 0;+}diff --git a/games/celeste/src/util.c b/games/celeste/src/util.cnew file mode 100644index 00000000..0a55fb4f--- /dev/null+++ b/games/celeste/src/util.c@@ -0,0 +1,359 @@+/* Calc.Random (.NET's System.Random), Monocle's eases, the input buttons,+ * and sprite animation (Monocle.Sprite). */+#include "celeste.h"++/* ---------------------------------------------------------------- System.Random */+#define MBIG 2147483647+#define MSEED 161803398+NetRandom g_rnd;++void rnd_seed(NetRandom *r, int32_t seed) {+ int32_t sub = seed == INT32_MIN ? INT32_MAX : (seed < 0 ? -seed : seed);+ int32_t mj = MSEED - sub, mk = 1;+ r->seed[55] = mj;+ for (int i = 1; i < 55; i++) {+ int ii = (21 * i) % 55;+ r->seed[ii] = mk;+ mk = mj - mk;+ if (mk < 0) mk += MBIG;+ mj = r->seed[ii];+ }+ for (int k = 1; k < 5; k++)+ for (int i = 1; i < 56; i++) {+ r->seed[i] -= r->seed[1 + (i + 30) % 55];+ if (r->seed[i] < 0) r->seed[i] += MBIG;+ }+ r->inext = 0;+ r->inextp = 21;+}++int32_t rnd_next(NetRandom *r) {+ int a = r->inext, b = r->inextp;+ if (++a >= 56) a = 1;+ if (++b >= 56) b = 1;+ int32_t v = r->seed[a] - r->seed[b];+ if (v == MBIG) v--;+ if (v < 0) v += MBIG;+ r->seed[a] = v;+ r->inext = a, r->inextp = b;+ return v;+}++int32_t rnd_range(NetRandom *r, int32_t max) { return (int32_t)(rnd_next(r) * (1.0 / MBIG) * max); }+float rnd_float(NetRandom *r) { return (float)(rnd_next(r) * (1.0 / MBIG)); }++/* ---------------------------------------------------------------- Ease */+float ease_sine_in(float t) { return -cosf(PI_F / 2 * t) + 1; }+float ease_sine_out(float t) { return sinf(PI_F / 2 * t); }+float ease_sine_inout(float t) { return -cosf(PI_F * t) / 2 + .5f; }+float ease_quad_in(float t) { return t * t; }+float ease_quad_out(float t) { return 1 - (1 - t) * (1 - t); }+float ease_cube_in(float t) { return t * t * t; }+float ease_cube_out(float t) { float u = 1 - t; return 1 - u * u * u; }+float ease_cube_inout(float t) { return t <= .5f ? ease_cube_in(t * 2) / 2 : ease_cube_out(t * 2 - 1) / 2 + .5f; }+float ease_back_in(float t) { return t * t * (2.70158f * t - 1.70158f); }+float ease_back_out(float t) { return 1 - ease_back_in(1 - t); }+float ease_big_back_in(float t) { return t * t * (4 * t - 3); }+float ease_expo_out(float t) { return 1 - powf(2, 10 * ((1 - t) - 1)); }+static float elastic_in(float t) {+ float ts = t * t, tc = ts * t;+ return 33 * tc * ts + -59 * ts * ts + 32 * tc + -5 * ts;+}+float ease_elastic_out(float t) { return 1 - elastic_in(1 - t); }+float ease_bounce_out(float t) {+ const float b1 = 1 / 2.75f, b2 = 2 / 2.75f, b3 = 1.5f / 2.75f, b4 = 2.5f / 2.75f, b5 = 2.25f / 2.75f, b6 = 2.625f / 2.75f;+ if (t < b1) return 7.5625f * t * t;+ if (t < b2) { t -= b3; return 7.5625f * t * t + .75f; }+ if (t < b4) { t -= b5; return 7.5625f * t * t + .9375f; }+ t -= b6;+ return 7.5625f * t * t + .984375f;+}++/* ---------------------------------------------------------------- Input */+Input g_in;+static int last_x, last_y; /* TakeNewer: the direction pressed last wins */++static void button(Button *b, bool down, bool was) {+ b->consumed = false;+ b->buffer -= DT;+ b->edge = down && !was;+ b->released = !down && was;+ b->check = down;+ if (b->edge) b->buffer = b->buffer_time;+ if (!down) b->buffer = 0;+}++void input_update(uint32_t keys) {+ uint32_t prev = g_in.keys;+ g_in.prev = prev;+ g_in.keys = keys;+ if (!g_in.jump.buffer_time) g_in.jump.buffer_time = g_in.dash.buffer_time = g_in.talk.buffer_time = 0.08f;+ button(&g_in.jump, keys & K_JUMP, prev & K_JUMP);+ button(&g_in.dash, keys & K_DASH, prev & K_DASH);+ button(&g_in.grab, keys & K_GRAB, prev & K_GRAB);+ button(&g_in.talk, keys & K_TALK, prev & K_TALK);+ button(&g_in.pause, keys & K_PAUSE, prev & K_PAUSE);+ button(&g_in.confirm, keys & K_OK, prev & K_OK);+ button(&g_in.back, keys & K_BACK, prev & K_BACK);+ bool l = keys & K_LEFT, r = keys & K_RIGHT, u = keys & K_UP, d = keys & K_DOWN;+ if (l && !(prev & K_LEFT)) last_x = -1;+ if (r && !(prev & K_RIGHT)) last_x = 1;+ if (u && !(prev & K_UP)) last_y = -1;+ if (d && !(prev & K_DOWN)) last_y = 1;+ g_in.move_x = l && r ? last_x : l ? -1 : r ? 1 : 0;+ g_in.move_y = u && d ? last_y : u ? -1 : d ? 1 : 0;+ g_in.aim_x = g_in.move_x, g_in.aim_y = g_in.move_y;+ g_in.feather_x = g_in.move_x, g_in.feather_y = g_in.move_y;+}++/* ---------------------------------------------------------------- Sprite */+static const uint8_t *bank_at(int b) {+ const uint8_t *s = section(SEC_BANKS);+ return s + rd32(s + 4 + 4 * b);+}+/* an animation: f32 delay, u8 loop, u8 ngoto, u16 nframes, (u16 anim, u16 weight) * ngoto, u16 frames */+static const uint8_t *anim_at(int b, int a) {+ const uint8_t *p = bank_at(b);+ if (a >= rd16(p + 2)) return NULL;+ const uint8_t *tab = p + 16;+ return tab + rd16(tab + 2 * a);+}+int bank_anim_count(int b) { return rd16(bank_at(b) + 2); }+/* the textures an animation shows and where it goes after: for loading them */+int bank_anim_textures(int b, int a, uint16_t *out, int max, uint16_t *gotos, int *ngotos) {+ const uint8_t *an = anim_at(b, a);+ if (!an) return 0;+ int n = rd16(an + 6), k = 0;+ for (int i = 0; i < n && k < max; i++) out[k++] = rd16(an + 8 + 4 * an[5] + 2 * i);+ *ngotos = an[5];+ for (int i = 0; i < an[5]; i++) gotos[i] = rd16(an + 8 + 4 * i);+ return k;+}++static uint16_t frame_tex(const uint8_t *an, int f) {+ return rd16(an + 8 + 4 * an[5] + 2 * f);+}++static void set_origin(Sprite *s) {+ if (!s->justify) return;+ Tex t;+ uint16_t tex = spr_tex(s);+ if (tex == 0xFFFF) return;+ /* the frame size is known without loading the pixels for direct textures; cached ones too */+ if (tex_get(tex, &t)) s->ox = t.fw * t.scale * s->jx, s->oy = t.fh * t.scale * s->jy;+}++void spr_init(Sprite *s, int bank) {+ memset(s, 0, sizeof *s);+ s->bank = (uint8_t)bank;+ s->anim = 255;+ s->rate = 1;+ s->sx = s->sy = 1;+ s->tint = 0xFFFF;+ s->alpha = 255;+ s->visible = 1;+ const uint8_t *p = bank_at(bank);+ if (p[0] == 1) s->ox = rdf(p + 4), s->oy = rdf(p + 8);+ else if (p[0] == 2) s->justify = 1, s->jx = rdf(p + 4), s->jy = rdf(p + 8);+ uint16_t start = rd16(p + 12);+ s->last_goto = -1;+ if (start != 0xFFFF) spr_play(s, start, false);+}++/* the current texture: kept in the frame field as a texture once an animation ends */+static uint16_t tex_of(const Sprite *s, int anim, int frame) {+ const uint8_t *an = anim_at(s->bank, anim);+ if (!an || !rd16(an + 6)) return 0xFFFF;+ if (frame >= rd16(an + 6)) frame = rd16(an + 6) - 1;+ return frame_tex(an, frame);+}++void spr_play(Sprite *s, int anim, bool restart) {+ if (s->anim == anim && !restart) return;+ const uint8_t *an = anim_at(s->bank, anim);+ if (!an) return;+ s->anim = (uint8_t)anim;+ s->last_goto = (int8_t)anim;+ s->playing = rdf(an) > 0;+ s->timer = 0;+ s->frame = 0;+ set_origin(s);+}++void spr_play_offset(Sprite *s, int anim, int frame) {+ spr_play(s, anim, true);+ const uint8_t *an = anim_at(s->bank, anim);+ if (an && frame < rd16(an + 6)) s->frame = (uint8_t)frame;+}++bool spr_is(const Sprite *s, int anim) { return s->anim == anim; }++int spr_frames(const Sprite *s) {+ const uint8_t *an = anim_at(s->bank, s->anim == 255 ? (s->last_goto < 0 ? 0 : s->last_goto) : s->anim);+ return an ? rd16(an + 6) : 0;+}++uint16_t spr_tex(const Sprite *s) {+ int a = s->anim != 255 ? s->anim : s->last_goto;+ if (a < 0) return 0xFFFF;+ return tex_of(s, a, s->frame);+}++float spr_anim_duration(int bank, int anim) {+ const uint8_t *an = anim_at(bank, anim);+ return an ? rdf(an) * rd16(an + 6) : 0;+}++int uitoa(int v, char *out) {+ char t[12];+ int n = 0;+ if (v < 0) v = 0;+ do t[n++] = (char)('0' + v % 10), v /= 10;+ while (v);+ for (int i = 0; i < n; i++) out[i] = t[n - 1 - i];+ out[n] = 0;+ return n;+}+void time_text(uint32_t frames, char *out) { /* TimeSpan: [h:]mm:ss.fff, as the stats show it */+ uint32_t ms = frames * 1000u / 60u, s = ms / 1000, m = s / 60, h = m / 60;+ char *p = out;+ if (h) p += uitoa((int)h, p), *p++ = ':';+ if (h || m >= 10) *p++ = (char)('0' + m % 60 / 10);+ *p++ = (char)('0' + m % 10);+ *p++ = ':', *p++ = (char)('0' + s % 60 / 10), *p++ = (char)('0' + s % 10), *p++ = '.';+ *p++ = (char)('0' + ms % 1000 / 100), *p++ = (char)('0' + ms % 100 / 10), *p++ = (char)('0' + ms % 10);+ *p = 0;+}++void spr_update(Sprite *s) {+ if (!s->playing || s->anim == 255) return;+ const uint8_t *an = anim_at(s->bank, s->anim);+ float delay = rdf(an);+ int n = rd16(an + 6);+ s->timer += (s->raw ? RAW_DT : DT) * s->rate;+ if (fabsf(s->timer) < delay) return;+ int dir = s->timer > 0 ? 1 : -1;+ int f = s->frame + dir;+ s->timer -= dir * delay;+ if (f >= 0 && f < n) {+ s->frame = (uint8_t)f;+ set_origin(s);+ return;+ }+ int ngoto = an[5];+ if (!ngoto && an[4]) { /* a Loop: back to its first frame */+ s->frame = (uint8_t)(f < 0 ? n - 1 : 0);+ set_origin(s);+ return;+ }+ if (ngoto) {+ int pick = 0;+ if (ngoto > 1) {+ int total = 0;+ for (int i = 0; i < ngoto; i++) total += rd16(an + 8 + 4 * i + 2);+ float r = rndf() * total;+ for (int i = 0; i < ngoto; i++) {+ r -= rd16(an + 8 + 4 * i + 2);+ if (r < 0) { pick = i; break; }+ }+ }+ uint16_t next = rd16(an + 8 + 4 * pick);+ if (next == 0xFFFF) next = s->anim;+ s->anim = (uint8_t)next;+ s->last_goto = (int8_t)next;+ const uint8_t *an2 = anim_at(s->bank, next);+ s->frame = (uint8_t)(f < 0 ? rd16(an2 + 6) - 1 : 0);+ s->playing = rdf(an2) > 0;+ set_origin(s);+ } else {+ s->frame = (uint8_t)(f < 0 ? 0 : n - 1);+ s->playing = 0;+ s->last_goto = (int8_t)s->anim;+ s->anim = 255; /* CurrentAnimationID = "": the last frame stays */+ }+}++void spr_draw(const Sprite *s, float x, float y) {+ if (!s->visible) return;+ uint16_t t = spr_tex(s);+ if (t == 0xFFFF) return;+ if (!res_cached(t)) { /* an animation not loaded yet: all its frames at once */+ uint16_t ids[32], gotos[8];+ int ng, a = s->anim != 255 ? s->anim : s->last_goto;+ int n = bank_anim_textures(s->bank, a, ids, 32, gotos, &ng);+ res_load_frames(ids, n, t);+ }+ uint8_t f = (s->flipx ? GF_FLIPX : 0) | (s->flipy ? GF_FLIPY : 0);+ float ox = s->ox, oy = s->oy;+ Tex tx;+ if (s->justify && tex_get(t, &tx)) ox = tx.fw * tx.scale * s->jx, oy = tx.fh * tx.scale * s->jy; /* Justify */+ gfx_tex_ex(t, x, y, ox, oy, s->sx, s->sy, s->rot, s->tint, s->alpha, f);+}++char *path2(char *buf, const char *a, const char *b, int n) {+ char *o = buf;+ while (*a) *o++ = *a++;+ while (b && *b) *o++ = *b++;+ if (n >= 0) {+ if (n >= 100) *o++ = (char)('0' + n / 100);+ *o++ = (char)('0' + (n / 10) % 10);+ *o++ = (char)('0' + n % 10);+ }+ *o = 0;+ return buf;+}++/* ---------------------------------------------------------------- sinf, cosf, powf */+/* to a quarter turn's eighth: x = k pi/2 + r, |r| <= pi/4 (pi/2 in two parts for the products' rounding) */+static float quarter(float x, int *k) {+ float n = rintf(x * 0.636619772f);+ *k = (int)n;+ return (x - n * 1.57079637f) - n * -4.37113883e-08f;+}+static float sin_r(float r) {+ float r2 = r * r;+ return r + r * r2 * (-0.166666667f + r2 * (8.33333333e-3f + r2 * -1.98412698e-4f));+}+static float cos_r(float r) {+ float r2 = r * r;+ return 1 + r2 * (-0.5f + r2 * (4.16666667e-2f + r2 * (-1.38888889e-3f + r2 * 2.48015873e-5f)));+}+void c_sincosf(float x, float *s, float *c) {+ int k;+ float r = quarter(x, &k), sr = sin_r(r), cr = cos_r(r);+ switch (k & 3) {+ case 0: *s = sr, *c = cr; break;+ case 1: *s = cr, *c = -sr; break;+ case 2: *s = -sr, *c = -cr; break;+ default: *s = -cr, *c = sr; break;+ }+}+float c_sinf(float x) {+ int k;+ float r = quarter(x, &k), v = (k & 1) ? cos_r(r) : sin_r(r);+ return (k & 2) ? -v : v;+}+float c_cosf(float x) {+ int k;+ float r = quarter(x, &k), v = (k & 1) ? sin_r(r) : cos_r(r);+ return ((k + 1) & 2) ? -v : v;+}+/* a^b = 2^(b log2 a), for a >= 0 */+float c_powf(float a, float b) {+ if (a <= 0) return b > 0 ? 0 : 1;+ if (b == 0 || a == 1) return 1;+ union { float f; uint32_t u; } v = {a};+ int e = (int)(v.u >> 23) - 127;+ v.u = (v.u & 0x007FFFFF) | 0x3F800000; /* the mantissa, in [1, 2) */+ float m = v.f;+ if (m > 1.41421356f) m *= 0.5f, e++; /* in [sqrt(1/2), sqrt(2)) */+ float t = (m - 1) / (m + 1), t2 = t * t;+ float l2 = e + 2.88539008f * t * (1 + t2 * (0.333333333f + t2 * (0.2f + t2 * 0.142857143f))); /* log2 */+ float y = b * l2;+ if (y > 127) return INFINITY;+ if (y < -126) return 0;+ float n = rintf(y), f = (y - n) * 0.693147181f;+ float p = 1 + f * (1 + f * (0.5f + f * (0.166666667f + f * (4.16666667e-2f + f * (8.33333333e-3f + f * 1.38888889e-3f)))));+ v.u = (uint32_t)((int)n + 127) << 23; /* 2^n */+ return p * v.f;+}diff --git a/games/celeste/src/wipe.c b/games/celeste/src/wipe.cnew file mode 100644index 00000000..99021d86--- /dev/null+++ b/games/celeste/src/wipe.c@@ -0,0 +1,174 @@+/* Screen wipes (ScreenWipe and the chapters' own): black shapes over the+ * screen, drawn like the game does, as triangles in its 1920x1080 interface. */+#include "wipe.h"+#include "level.h"++Wipe g_wipe;++/* ---------------------------------------------------------------- triangles over the strips */+#define MAX_TRIS 136+typedef struct { int16_t x[3], y[3]; } Tri; /* quarter screen pixels */+static Tri tris[MAX_TRIS];+static int ntris;+static uint8_t fade_alpha; /* FadeWipe: the whole screen at this alpha */++static void tri(float x0, float y0, float x1, float y1, float x2, float y2) {+ if (ntris >= MAX_TRIS) return;+ Tri *t = &tris[ntris++];+ /* interface pixels to quarter screen pixels (clamped: far points only need to be off screen) */+#define Q(v) (int16_t)fmaxf(-8000, fminf(8000, (v) * 4 / 6))+ t->x[0] = Q(x0), t->y[0] = Q(y0), t->x[1] = Q(x1), t->y[1] = Q(y1), t->x[2] = Q(x2), t->y[2] = Q(y2);+#undef Q+}+static void quad(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) {+ tri(x0, y0, x1, y1, x2, y2);+ tri(x0, y0, x2, y2, x3, y3);+}++static void fill_tri(uint16_t *strip, int sy0, int sy1, const Tri *q) {+ struct { float x[3], y[3]; } tt, *t = &tt;+ for (int i = 0; i < 3; i++) t->x[i] = q->x[i] / 4.f, t->y[i] = q->y[i] / 4.f;+ float ymin = fminf(t->y[0], fminf(t->y[1], t->y[2])), ymax = fmaxf(t->y[0], fmaxf(t->y[1], t->y[2]));+ int r0 = (int)ceilf(ymin - 0.5f), r1 = (int)ceilf(ymax - 0.5f);+ if (r0 < sy0) r0 = sy0;+ if (r1 > sy1) r1 = sy1;+ for (int y = r0; y < r1; y++) {+ float py = y + 0.5f, xl = 1e9f, xr = -1e9f;+ for (int i = 0; i < 3; i++) { /* the row's crossing with each edge */+ float ax = t->x[i], ay = t->y[i], bx = t->x[(i + 1) % 3], by = t->y[(i + 1) % 3];+ if ((ay <= py && by > py) || (by <= py && ay > py)) {+ float x = ax + (py - ay) * (bx - ax) / (by - ay);+ xl = fminf(xl, x), xr = fmaxf(xr, x);+ }+ }+ int a = (int)ceilf(xl - 0.5f), b = (int)ceilf(xr - 0.5f);+ if (a < 0) a = 0;+ if (b > VIEW_W) b = VIEW_W;+ uint16_t *row = strip + (y - sy0) * VIEW_W;+ for (int x = a; x < b; x++) row[x] = 0;+ }+}++static void wipe_strip(uint16_t *strip, int sy0, int sy1, void *ctx) {+ (void)ctx;+ if (fade_alpha) {+ uint16_t *p = strip, *end = strip + (sy1 - sy0) * VIEW_W;+ int k = fade_alpha + (fade_alpha >> 7); /* black over it: the picture * (1 - alpha) */+ for (; p < end; p++) *p = blend565(*p, 0, k);+ }+ for (int i = 0; i < ntris; i++) fill_tri(strip, sy0, sy1, &tris[i]);+}++/* ---------------------------------------------------------------- the wipes' shapes */+static void fade_shape(float p, bool in) {+ float a = in ? 1 - ease_cube_in(p) : ease_cube_out(p);+ fade_alpha = (uint8_t)(a * 255 + 0.5f);+}++static void angled_shape(float p, bool in) {+ const float h = 183.33333f, x0 = -64, w = 1984;+ for (int i = 0; i < 6; i++) {+ float y = -10 + i * h, k = 0, start = (in ? 1 - i / 6.f : i / 6.f) * 0.3f;+ if (p > start) k = fminf(1, (p - start) / 0.7f);+ if (in) k = 1 - k;+ float len = w * k;+ float v[6][2] = {{x0, y}, {x0 + len, y}, {x0, y + h}, {x0 + len, y}, {x0 + len + 64, y + h}, {x0, y + h}};+ if (in)+ for (int j = 0; j < 6; j++) v[j][0] = 1920 - v[j][0], v[j][1] = 1080 - v[j][1];+ tri(v[0][0], v[0][1], v[1][0], v[1][1], v[2][0], v[2][1]);+ tri(v[3][0], v[3][1], v[4][0], v[4][1], v[5][0], v[5][1]);+ }+}++static V2 curve(V2 a, V2 b, V2 c, float t) { /* SimpleCurve: begin a, end b, control c */+ float u = 1 - t;+ return v2(u * u * a.x + 2 * u * t * c.x + t * t * b.x, u * u * a.y + 2 * u * t * c.y + t * t * b.y);+}+static void curtain_shape(float p, bool in) {+ float num = ease_cube_inout(in ? 1 - p : p);+ float n2 = fminf(1, num / 0.3f), n3 = fmaxf(0, fminf(1, (num - 0.1f) / 0.9f / 0.9f));+ V2 a = v2(0, 540 * n2), b = v2(960, 796), ctl = v2((a.x + b.x) / 2, (a.y + b.y) / 2 + 270);+ V2 top = v2(896 + 200 * num, -350 + 256 * n2);+ V2 pt = curve(a, b, ctl, n3);+ V2 bot = v2(pt.x + 64 * num, 1080);+ for (int side = 0; side < 2; side++) {+#define X(v) (side ? 1920 - (v) : (v))+ tri(X(-10), -10, X(top.x), -10, X(top.x), top.y);+ tri(X(-10), -10, X(-10), pt.y, X(pt.x), pt.y);+ tri(X(pt.x), pt.y, X(-10), pt.y, X(-10), 1090);+ tri(X(pt.x), pt.y, X(-10), 1090, X(bot.x), bot.y + 10);+ /* the curtain's edge: a fan from the corner along a curve */+ V2 prev = top, c2 = v2((top.x + pt.x) / 2, (top.y + pt.y) / 2 + 384 * n3);+ const int n = 30;+ for (int i = 1; i <= n; i++) {+ V2 q = curve(top, pt, c2, (float)i / n);+ tri(X(-10), -10, X(prev.x), prev.y, X(q.x), q.y);+ prev = q;+ }+#undef X+ }+}++/* SpotlightWipe: all but a circle around the focus */+static void spotlight_shape(float p, bool in) {+ float num = in ? p : 1 - p;+ float small = 288 + g_wipe.modifier, r;+ if (g_wipe.linear) r = ease_cube_inout(num) * 1920;+ else if (num < 0.2f) r = ease_cube_inout(num / 0.2f) * small;+ else if (num < 0.8f) r = small;+ else r = small + (num - 0.8f) / 0.2f * (1920 - small);+ V2 f = v2(g_wipe.focus.x * 6, g_wipe.focus.y * 6);+ const int n = 32;+ V2 a = v2(1, 0);+ for (int i = 1; i <= n; i++) {+ V2 b = angle_vec((float)i / n * PI_F * 2, 1);+ quad(f.x + a.x * 5000, f.y + a.y * 5000, f.x + a.x * r, f.y + a.y * r, f.x + b.x * r, f.y + b.y * r, f.x + b.x * 5000,+ f.y + b.y * 5000);+ a = b;+ }+}++/* ---------------------------------------------------------------- the wipe */+void wipe_start(int type, bool in, WipeDone done) {+ memset(&g_wipe, 0, sizeof g_wipe);+ g_wipe.type = (uint8_t)type;+ g_wipe.in = in;+ g_wipe.active = true;+ g_wipe.duration = type == WIPE_SPOTLIGHT ? 1.8f : 0.5f;+ g_wipe.done = done;+}+/* the area's own (AreaData.Wipe) */+void wipe_area(bool in, WipeDone done) {+ static const uint8_t types[AREAS] = {WIPE_CURTAIN, WIPE_ANGLED, WIPE_DREAM, WIPE_KEYDOOR, WIPE_WIND, WIPE_DROP,+ WIPE_FALL, WIPE_MOUNTAIN, WIPE_CURTAIN, WIPE_HEART, WIPE_STARFIELD};+ wipe_start(types[g_session.area < AREAS ? g_session.area : 1], in, done);+}++void wipe_update(void) {+ Wipe *w = &g_wipe;+ if (!w->active) return;+ if (!w->completed) {+ if (w->percent < 1) w->percent = approach(w->percent, 1, RAW_DT / w->duration);+ else if (w->end_timer > 0) w->end_timer -= RAW_DT;+ else w->completed = true;+ } else {+ w->active = false;+ if (w->done) w->done();+ }+}++void wipe_render(void) {+ Wipe *w = &g_wipe;+ if (!w->active) return;+ ntris = 0;+ fade_alpha = 0;+ switch (w->type) {+ case WIPE_FADE: fade_shape(w->percent, w->in); break;+ case WIPE_SPOTLIGHT: spotlight_shape(w->percent, w->in); break;+ case WIPE_CURTAIN: curtain_shape(w->percent, w->in); break;+ default: angled_shape(w->percent, w->in); break;+ }+ gfx_hud(true); /* over everything, not zoomed */+ gfx_custom(wipe_strip, NULL, 0, VIEW_H);+ gfx_hud(false);+}diff --git a/games/celeste/src/wipe.h b/games/celeste/src/wipe.hnew file mode 100644index 00000000..559487b4--- /dev/null+++ b/games/celeste/src/wipe.h@@ -0,0 +1,22 @@+/* Screen wipes: ScreenWipe and the chapters' own (AreaData.Wipe). */+#ifndef WIPE_H+#define WIPE_H+#include "celeste.h"++enum { WIPE_FADE, WIPE_SPOTLIGHT, WIPE_CURTAIN, WIPE_ANGLED, WIPE_DREAM, WIPE_KEYDOOR, WIPE_WIND, WIPE_DROP, WIPE_FALL,+ WIPE_MOUNTAIN, WIPE_HEART, WIPE_STARFIELD };+typedef void (*WipeDone)(void);+typedef struct {+ uint8_t type;+ bool in, active, completed, linear;+ float percent, duration, end_timer, modifier;+ V2 focus; /* SpotlightWipe.FocusPoint, screen pixels */+ WipeDone done;+} Wipe;+extern Wipe g_wipe; /* Level.Wipe */++void wipe_start(int type, bool in, WipeDone done);+void wipe_area(bool in, WipeDone done); /* Level.DoScreenWipe */+void wipe_update(void);+void wipe_render(void);+#endifdiff --git a/games/celeste/tests/check.py b/games/celeste/tests/check.pynew file mode 100644index 00000000..f3bf619f--- /dev/null+++ b/games/celeste/tests/check.py@@ -0,0 +1,86 @@+#!/usr/bin/env python3+"""Checks of Celeste on a computer (make test): the host build, with+AddressSanitizer and UBSan, through the menus, the saves and every room.++ python3 tests/check.py build/play src/data.bin [--quick]++--quick skips playing every room (the longest part)."""+import os+import re+import shutil+import subprocess+import sys+import tempfile++PLAY = sys.argv[1] if len(sys.argv) > 1 else "build/play"+DATA = sys.argv[2] if len(sys.argv) > 2 else "src/data.bin"+QUICK = "--quick" in sys.argv+failures = []+ENV = dict(os.environ, ASAN_OPTIONS="detect_leaks=0", UBSAN_OPTIONS="halt_on_error=1:print_stacktrace=1")+++def run(args, frames, keys="", saves=None, env=None, what=""):+ """Plays (from a save folder, a new one if None); returns its output (the session line)."""+ own = saves is None+ if own:+ saves = tempfile.mkdtemp(prefix="celeste_check_")+ e = dict(ENV)+ e.update(env or {})+ p = subprocess.run([PLAY, DATA, "--saves", saves, "--frames", str(frames), "--keys", keys] + args,+ capture_output=True, text=True, env=e, timeout=600)+ if own:+ shutil.rmtree(saves, ignore_errors=True)+ if p.returncode or "runtime error" in p.stderr or "AddressSanitizer" in p.stderr:+ failures.append(f"{what or args}: crashed or a sanitizer error\n{p.stderr[-2000:]}")+ return p.stdout+++def session(out):+ m = re.search(r"session: chapter (\d+) area (\d+) mode (\d+) deaths (\d+) time (\d+)", out)+ return tuple(int(v) for v in m.groups()) if m else None+++def check(cond, msg):+ if not cond:+ failures.append(msg)+++# the first time: the key sheet, the title, the main menu, Climb, the chapter, Start: the Prologue+MENU_TO_PLAY = "40-41:o,100-101:o,160-161:o,220-221:o,280-281:o"+d = tempfile.mkdtemp(prefix="celeste_check_")+out = run([], 500, MENU_TO_PLAY + ",400-450:r", saves=d, what="the menus to the Prologue")+s = session(out)+check(s and s[1] == 0 and s[4] > 100, f"the menus did not start the Prologue: {s}")++# Home saves and leaves; Climb then shows Continue, which carries on the same run+out = run([], 700, MENU_TO_PLAY + ",600-601:h", saves=d, what="Home in the Prologue")+check(os.path.exists(d + "/celeste.sav") and os.path.exists(d + "/celeste_saves.py"), "Home did not save")+t0 = session(out)[4] if session(out) else 0+out = run([], 300, "40-41:o,100-101:o,160-161:o", saves=d, what="Continue after Home")+s = session(out)+check(s and s[4] > t0, f"Continue did not carry on the run ({t0} frames before): {s}")++# the copy in the Python script brings the save back when it is gone+os.remove(d + "/celeste.sav")+out = run([], 10, saves=d, what="the save from its copy")+s2 = session(out)+check(s2 and s2[4] >= t0, f"the save did not come back from celeste_saves.py: {s2}")+shutil.rmtree(d, ignore_errors=True)++# the pause menu: Retry is a death+out = run(["--chapter", "1", "--room", "1"], 300, "200-201:p,215-216:d,230-231:o", what="Retry from the pause menu")+s = session(out)+check(s and s[3] == 1, f"Retry did not count a death: {s}")++# a chapter's end: its screen, then the chapter select+out = run(["--chapter", "1", "--room", "1"], 500, "400-401:o", env={"COMPLETE_AT": "60"}, what="a chapter's end")++# every room, moving and dashing about, drawn every frame+if not QUICK:+ rooms = subprocess.run([PLAY, DATA, "--list"], capture_output=True, text=True).stdout.split("\n")+ for line in filter(None, rooms):+ c, r = line.split(" ", 1)+ run(["--chapter", c, "--room", r, "--draw", "1"], 150, "10-140:r,30-36:j,50:x,70-90:l,80-86:j,100:x", what=f"room {c} {r}")++print("\n".join(failures) if failures else "all good")+sys.exit(1 if failures else 0)diff --git a/games/celeste/tests/play.c b/games/celeste/tests/play.cnew file mode 100644index 00000000..94419e92--- /dev/null+++ b/games/celeste/tests/play.c@@ -0,0 +1,171 @@+/* Host runner: plays the game with scripted keys and saves screenshots.+ * play DATA.bin [--frames N] [--keys "F0-F1:keys,..."] [--shot F:path ...] [--room NAME] [--chapter N]+ * [--draw N: draw every N frames (else only for shots and the last frame)]+ * [--load F:ROOM:INTRO:FX:FY: at frame F, LoadLevel(INTRO) into ROOM at the spawn nearest (FX, FY) of it]+ * [--record A-B:DIR: every frame from A to B as DIR/NNNNN.ppm (for the README's GIFs)]+ * keys: l r u d j(ump) x(dash) g(rab) p(ause) o(k) b(ack) */+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include "../src/celeste.h"+#include "../src/level.h"+#include "../src/text.h"+#include "../src/player.h"+#include "../src/entities.h"++extern uint32_t host_keys, host_time;+void host_shot(const char *path);+void host_save_dir(const char *d);+extern bool g_running;+void game_save(void);++static uint32_t parse_keys(const char *s) {+ uint32_t k = 0;+ for (; *s && *s != ','; s++) switch (*s) {+ case 'l': k |= K_LEFT; break;+ case 'r': k |= K_RIGHT; break;+ case 'u': k |= K_UP; break;+ case 'd': k |= K_DOWN; break;+ case 'j': k |= K_JUMP; break;+ case 'x': k |= K_DASH | K_TALK; break;+ case 'g': k |= K_GRAB; break;+ case 'p': k |= K_PAUSE | K_BACK; break;+ case 'o': k |= K_OK; break;+ case 'h': k |= K_HOME; break;+ }+ return k;+}++long g_dbg_layers, g_dbg_pixels, g_dbg_prep, g_dbg_prep_n;+int main(int argc, char **argv) {+ if (argc < 2) return 1;+ FILE *f = fopen(argv[1], "rb");+ if (!f) return 1;+ fseek(f, 0, SEEK_END);+ long n = ftell(f);+ fseek(f, 0, SEEK_SET);+ uint8_t *data = malloc(n);+ fread(data, 1, n, f);+ fclose(f);+ cel_bin = data;+ int frames = 120, chapter = -1, area = -1, checkpoint = -1, at_set = 0, dash_code = 0, list = 0, draw = 0, load_at = -1, load_intro = 0;+ const char *load_room = NULL, *rec_dir = NULL;+ int rec_from = -1, rec_to = -1;+ float load_fx = 0, load_fy = 1;+ float at_x = 0, at_y = 0;+ const char *keys = "", *room = NULL, *saves = "build/no-saves", *say = NULL;+ const char *shots[64];+ int shot_at[64], nshots = 0;+ for (int i = 2; i < argc; i++) {+ if (!strcmp(argv[i], "--frames")) frames = atoi(argv[++i]);+ else if (!strcmp(argv[i], "--keys")) keys = argv[++i];+ else if (!strcmp(argv[i], "--room")) room = argv[++i];+ else if (!strcmp(argv[i], "--chapter")) chapter = atoi(argv[++i]);+ else if (!strcmp(argv[i], "--area")) area = atoi(argv[++i]); /* (the chapter knows its area) */+ else if (!strcmp(argv[i], "--checkpoint")) checkpoint = atoi(argv[++i]);+ else if (!strcmp(argv[i], "--saves")) saves = argv[++i];+ else if (!strcmp(argv[i], "--say")) say = argv[++i];+ else if (!strcmp(argv[i], "--dash-code")) dash_code = 1;+ else if (!strcmp(argv[i], "--draw")) draw = atoi(argv[++i]);+ else if (!strcmp(argv[i], "--record")) {+ char *a = argv[++i];+ rec_from = atoi(a);+ rec_to = atoi(strchr(a, '-') + 1);+ rec_dir = strchr(a, ':') + 1;+ } else if (!strcmp(argv[i], "--load")) {+ char *a = argv[++i];+ load_at = atoi(a);+ a = strchr(a, ':') + 1;+ char *b = strchr(a, ':');+ *b = 0;+ load_room = a;+ sscanf(b + 1, "%d:%f:%f", &load_intro, &load_fx, &load_fy);+ }+ else if (!strcmp(argv[i], "--list")) list = 1;+ else if (!strcmp(argv[i], "--at")) sscanf(argv[++i], "%f,%f", &at_x, &at_y), at_set = 1;+ else if (!strcmp(argv[i], "--shot")) {+ char *s = argv[++i], *c = strchr(s, ':');+ shot_at[nshots] = atoi(s);+ shots[nshots++] = c + 1;+ }+ }+ (void)area;+ host_save_dir(saves); /* --saves DIR: load and keep the save there (none by default) */+ game_init();+ if (list) { /* --list: every chapter's rooms, "chapter room" a line */+ for (int c = 0; c < chapter_count(); c++)+ for (int i = 0; chapter_room_name(c, i); i++) printf("%d %s\n", c, chapter_room_name(c, i));+ return 0;+ }+ /* --chapter: the chapter's index in data.bin (the order of MAPS); --room NAME, --checkpoint K */+ if (room || chapter >= 0 || checkpoint >= 0) {+ int c = chapter >= 0 ? chapter : g_session.chapter;+ session_start(c, checkpoint);+ if (room) {+ int r = chapter_find_room(c, room);+ if (r >= 0) g_session.level = (uint8_t)r;+ }+ level_start(room ? INTRO_NONE : session_intro(true));+ g_in_level = true, g_menu = 0;+ }+ if (at_set) { /* --at X,Y: the player there (in the room) */+ g_player.ent->x = g_level.room->x + at_x, g_player.ent->y = g_level.room->y + at_y;+ g_level.cam = player_camera_target(&g_player);+ }+ if (say) textbox_say(say, NULL, NULL); /* --say KEY: that dialog in a textbox */+ for (int fr = 0; fr < frames; fr++) {+ host_keys = 0;+ for (const char *p = keys; *p;) {+ int a = atoi(p), b = a;+ const char *dash = strchr(p, '-'), *colon = strchr(p, ':');+ if (!colon) break;+ if (dash && dash < colon) b = atoi(dash + 1);+ if (fr >= a && fr <= b) host_keys |= parse_keys(colon + 1);+ const char *comma = strchr(colon, ',');+ if (!comma) break;+ p = comma + 1;+ }+ if (getenv("COMPLETE_AT") && fr == atoi(getenv("COMPLETE_AT"))) level_complete_area(false, false); /* the chapter's end */+ if (dash_code && fr >= 120 && fr < 126) { /* --dash-code: the dash listeners hear U, L, DR, UR, L, UL */+ static const float d[6][2] = {{0, -1}, {-1, 0}, {0.7071f, 0.7071f}, {0.7071f, -0.7071f}, {-1, 0}, {-0.7071f, -0.7071f}};+ level_dash_listeners(v2(d[fr - 120][0], d[fr - 120][1]));+ }+ if (fr == load_at) level_load_room_near(chapter_find_room(g_session.chapter, load_room), load_intro, load_fx, load_fy);+ game_frame();+ if (getenv("DUSTDBG") && fr % 30 == 0) {+ g_dbg_layers = g_dbg_pixels = g_dbg_prep = g_dbg_prep_n = 0;+ game_draw();+ printf("f%d preps %ld entries %ld blit_layers %ld pixels %ld cam %.0f,%.0f player %.0f,%.0f\n", fr, g_dbg_prep, g_dbg_prep_n, g_dbg_layers, g_dbg_pixels, g_level.cam.x,+ g_level.cam.y, g_player.ent->x, g_player.ent->y);+ }+ host_time += 17;+ if (!g_running) { /* Home: saved, and out */+ game_save();+ break;+ }+ if (getenv("TRACE") && g_player.ent)+ printf("f%d pos %.0f,%.0f sp %.1f,%.1f st %d gr %d dash %d stam %.0f anim %d keys %x\n", fr, g_player.ent->x, g_player.ent->y,+ g_player.speed.x, g_player.speed.y, g_player.state, g_player.on_ground, g_player.dashes, g_player.stamina,+ g_player.spr.anim, host_keys);+ bool want = false;+ for (int i = 0; i < nshots; i++)+ if (shot_at[i] == fr) want = true;+ bool rec = rec_dir && fr >= rec_from && fr <= rec_to;+ if (want || rec || fr == frames - 1 || (draw && fr % draw == 0)) {+ game_draw();+ if (rec) {+ char path[512];+ snprintf(path, sizeof path, "%s/%05d.ppm", rec_dir, fr);+ host_shot(path);+ }+ for (int i = 0; i < nshots; i++)+ if (shot_at[i] == fr) host_shot(shots[i]);+ }+ }+ printf("room %s player %.0f,%.0f state %d dead %d\n", level_room_name(), g_player.ent ? g_player.ent->x : 0,+ g_player.ent ? g_player.ent->y : 0, g_player.state, g_player.dead);+ printf("session: chapter %d area %d mode %d deaths %u time %u berries %llx; save berries %llx deaths %u\n",+ g_session.chapter, g_session.area, g_session.mode, g_session.deaths, g_session.time,+ (unsigned long long)g_session.berries, (unsigned long long)save_mode()->berries, save_mode()->deaths);+ return 0;+}diff --git a/games/celeste/tools/assets_ch1.py b/games/celeste/tools/assets_ch1.pynew file mode 100644index 00000000..451c8410--- /dev/null+++ b/games/celeste/tools/assets_ch1.py@@ -0,0 +1,10 @@+"""Forsaken City (chapter 1): what src/ch1.c's entities draw (Theo's sprite comes with the npc entity)."""++ASSETS = {+ "memorial": ["tex:scenery/memorial/memorial"],+ "bonfire": ["bank:campfire"],+}+# the dreamy memorial (Old Site's start, while dreaming)+VARIANTS = {+ "memorial": ("dreaming", {True: ["fam:scenery/memorial/floatytext"]}),+}diff --git a/games/celeste/tools/assets_ch2.py b/games/celeste/tools/assets_ch2.pynew file mode 100644index 00000000..f47e3370--- /dev/null+++ b/games/celeste/tools/assets_ch2.py@@ -0,0 +1,19 @@+"""Old Site (chapter 2): what src/ch2.c's entities draw."""++ASSETS = {+ "dreamBlock": [], # drawn with shapes (objects/dreamblock/particles is three tiny stars)+ "darkChaser": [], # Badeline's sprite and hair are direct textures+ "touchSwitch": ["tex:objects/touchswitch/container", "fam:objects/touchswitch/icon"],+ "switchGate": ["tex:objects/switchgate/block", "tex:objects/switchgate/mirror", "tex:objects/switchgate/temple",+ "tex:objects/switchgate/stars", "fam:objects/switchgate/icon"],+ "hanginglamp": ["tex:objects/hanginglamp"],+ "floatingDebris": ["tex:scenery/debris"],+ "foregroundDebris": ["fam:scenery/fgdebris/rock_a", "fam:scenery/fgdebris/rock_b"],+ "invisibleBarrier": [],+ # the sprite "payphone": its idle frame loads with the room, the rest (pickUp ... eat) when first drawn+ "payphone": ["bank:payphone", "tex:cutscenes/payphone/blink"],+ # src/ch2.c plays the sprite "lookout" from a table, loading an animation when first drawn (the room+ # loads the bank's first one, "idle")+ "towerviewer": ["bank:lookout"],+ "dreammirror": ["bank:glass", "tex:objects/mirror/frame", "tex:objects/mirror/glassbg", "tex:objects/mirror/glassfg"],+}diff --git a/games/celeste/tools/assets_ch3.py b/games/celeste/tools/assets_ch3.pynew file mode 100644index 00000000..306fff17--- /dev/null+++ b/games/celeste/tools/assets_ch3.py@@ -0,0 +1,61 @@+"""Celestial Resort (chapter 3): what src/ch3.c's entities draw.++VARIANTS: assets that depend on an entity's attribute, {name: (attribute, {value: assets})}: a room+loads only the sprites its entities use (the texture cache is 48 KB). entities.needs() adds them."""++CLUTTER = ["fam:objects/resortclutter/red_", "fam:objects/resortclutter/green_", "fam:objects/resortclutter/yellow_"]++ASSETS = {+ "redBlocks": ["fam:objects/resortclutter/red_"],+ "greenBlocks": ["fam:objects/resortclutter/green_"],+ "yellowBlocks": ["fam:objects/resortclutter/yellow_"],+ "clutterCabinet": ["bank:clutterCabinet"],+ # the absorbed clutter flies in from offscreen, in the switch's color+ "colorSwitch": ["bank:clutterSwitch", "tex:objects/resortclutter/icon_red", "tex:objects/resortclutter/icon_green",+ "tex:objects/resortclutter/icon_yellow"] + CLUTTER,+ "clutterDoor": ["bank:ghost_door"],+ "oshirodoor": ["bank:ghost_door"],+ "resortLantern": ["tex:objects/resortLantern/holder", "fam:objects/resortLantern/lantern"],+ "cobweb": [],+ "triggerSpikesUp": ["fam:danger/triggertentacle/wiggle_v", "fam:danger/dustcreature/base"],+ "triggerSpikesDown": ["fam:danger/triggertentacle/wiggle_v", "fam:danger/dustcreature/base"],+ "triggerSpikesLeft": ["fam:danger/triggertentacle/wiggle_h", "fam:danger/dustcreature/base"],+ "triggerSpikesRight": ["fam:danger/triggertentacle/wiggle_h", "fam:danger/dustcreature/base"],+ "door": [],+ "trapdoor": ["bank:trapdoor"],+ "sinkingPlatform": ["tex:objects/woodPlatform/default", "tex:objects/woodPlatform/cliffside"],+ "movingPlatform": ["tex:objects/woodPlatform/default", "tex:objects/woodPlatform/cliffside"],+ "clothesline": [],+ "water": [],+ "waterfall": [],+ # src/ch3.c plays oshiro_boss from a table and loads an animation when first drawn: the room loads "idle"+ # (and the banks' first animations)+ "friendlyGhost": ["bank:oshiro_boss", "bank:oshiro_boss_lightning"]+ + ["tex:characters/oshiro/boss%02d" % i for i in range(13, 21)],+ # (the suite's cutscene breaks it: the sprite "glass")+ "resortmirror": ["tex:objects/mirror/resortframe", "tex:objects/mirror/glassbg", "tex:objects/mirror/glassbreak09",+ "tex:objects/mirror/glassfg", "lazy:bank:glass"],+ "picoconsole": ["tex:objects/pico8Console"],+ "key": ["bank:key"],+ "lockBlock": [],+ "blockField": [],+ "killbox": [],+ "resortRoofEnding": ["tex:decals/3-resort/roofCenter", "tex:decals/3-resort/roofCenter_b",+ "tex:decals/3-resort/roofCenter_c", "tex:decals/3-resort/roofCenter_d",+ "tex:decals/3-resort/roofEdge", "tex:decals/3-resort/roofEdge_d",+ "tex:decals/3-resort/roofCenter_snapped_a", "tex:decals/3-resort/roofCenter_snapped_b",+ "tex:decals/3-resort/roofCenter_snapped_c", "bank:oshiro"],+}++# the npcs by their names: Theo's grates; the rooftop's Oshiro turns into the boss+NPC_ASSETS = {+ "theo_03": ["tex:scenery/grate"],+ "oshiro_03_rooftop": ["bank:oshiro_boss"],+}++VARIANTS = {+ "door": ("type", {"wood": ["bank:door"], "metal": ["bank:metaldoor"]}),+ "lockBlock": ("sprite", {"wood": ["bank:lockdoor_wood"], "temple_a": ["bank:lockdoor_temple_a"],+ "temple_b": ["bank:lockdoor_temple_b"], "moon": ["bank:lockdoor_moon"]}),+}+diff --git a/games/celeste/tools/assets_ch4.py b/games/celeste/tools/assets_ch4.pynew file mode 100644index 00000000..aaaba520--- /dev/null+++ b/games/celeste/tools/assets_ch4.py@@ -0,0 +1,34 @@+"""Golden Ridge (chapter 4): what src/ch4.c's entities draw.++VARIANTS: assets that depend on an entity's attribute, {name: (attribute, {value: assets})}, so a room+loads the green or the red booster, not both (the texture cache is 48 KB); entities.needs() adds+them."""++ASSETS = {+ "booster": ["tex:objects/booster/outline"],+ "moveBlock": ["tex:objects/moveBlock/base", "tex:objects/moveBlock/base_h", "tex:objects/moveBlock/base_v",+ "tex:objects/moveBlock/button", "fam:objects/moveBlock/arrow", "tex:objects/moveBlock/x",+ "fam:objects/moveBlock/debris"],+ "cloud": [],+ "ridgeGate": ["tex:objects/ridgeGate"],+ "whiteblock": ["tex:objects/whiteblock"],+ "gondola": ["bank:gondola", "tex:objects/gondola/top", "tex:objects/gondola/back", "tex:objects/gondola/cliffsideLeft",+ "tex:objects/gondola/cliffsideRight", "fam:objects/gondola/lever"],+ "cliffside_flag": ["fam:scenery/cliffside/flag"],+ "cliffflag": [],+ # the Snowball of a windAttackTrigger+ "windAttackTrigger": ["bank:snowball"],+}++# the npcs by their names: CS04_Gondola's clouds (two Parallax it adds) and the breathing's feather (the+# GUI's is not packed: the gameplay's flyFeather), loaded when drawn+NPC_ASSETS = {+ "theo_04_cliffside": ["lazy:tex:bgs/04/bgCloudLoop", "lazy:tex:bgs/04/bgCloud", "lazy:bank:flyFeather"],+}++VARIANTS = {+ "booster": ("red", {True: ["bank:boosterRed"], False: ["bank:booster"]}),+ # (B and C sides use the Remix clouds: the map is not known here, so both)+ "cloud": ("fragile", {True: ["bank:cloudFragile", "bank:cloudFragileRemix"], False: ["bank:cloud", "bank:cloudRemix"]}),+}+diff --git a/games/celeste/tools/assets_ch5.py b/games/celeste/tools/assets_ch5.pynew file mode 100644index 00000000..cfe82e26--- /dev/null+++ b/games/celeste/tools/assets_ch5.py@@ -0,0 +1,61 @@+"""What the Mirror Temple's own entities draw (src/ch5.c). "lazy:" assets: only their first texture is+loaded with the room, the rest when drawn."""++ASSETS = {+ "torch": ["lazy:fam:objects/temple/torch", "lazy:fam:objects/temple/litTorch"],+ "templeEye": ["tex:scenery/temple/eye/bg_eye", "tex:scenery/temple/eye/bg_pupil", "tex:scenery/temple/eye/fg_eye",+ "tex:scenery/temple/eye/fg_pupil", "fam:scenery/temple/eye/bg_lid", "fam:scenery/temple/eye/fg_lid"],+ "templeGate": [], # NEEDS: one door (10 KB each)+ "dashSwitchH": [], # NEEDS: one look+ "dashSwitchV": [],+ "swapBlock": ["tex:objects/swapblock/block", "tex:objects/swapblock/blockRed", "tex:objects/swapblock/target",+ "tex:objects/swapblock/pathH", "tex:objects/swapblock/pathV", "fam:objects/swapblock/midBlock",+ "fam:objects/swapblock/midBlockRed"],+ "templeCrackedBlock": ["lazy:fam:objects/temple/breakBlock", "tex:debris/1"],+ "seekerBarrier": [],+ "seeker": ["bank:seeker", "lazy:bank:seekerShockWave"], # the shockwave: 19 frames of 96x96, when it recovers+ "seekerStatue": ["bank:seeker", "lazy:bank:seekerShockWave"],+ "playerSeeker": ["bank:seeker"],+ "theoCrystal": ["fam:characters/theoCrystal/idle"], # its shatter only plays by the big eyeball+ "theoCrystalPedestal": ["tex:characters/theoCrystal/pedestal"],+ "conditionBlock": [],+ "templeMirror": ["tex:scenery/templemirror"],+ "templeMirrorPortal": ["tex:objects/temple/portal/portalframe", "tex:objects/temple/portal/surface",+ "bank:temple_portal_curtain", "lazy:fam:objects/temple/portal/portaltorch"],+ "templeBigEyeball": ["bank:temple_eyeball", "tex:danger/templeeye/pupil", "bank:theo_crystal",+ "lazy:fam:scenery/temple/eye/bg_burst", "lazy:fam:scenery/temple/eye/fg_burst"],+}+++# the game never loads it: Level.LoadLevel has no case for it+DROP = {"theoCrystalHoldingBarrier"}+++def _gate(e):+ # Sprites.xml says objects/door/templeDoor, the atlas has TempleDoor (Monocle's lookups ignore case)+ s = str(e.get("sprite", "default")).lower()+ return ["lazy:fam:objects/door/TempleDoor" + {"mirror": "B", "theo": "C"}.get(s, "")]+++def _dash_switch(e):+ s = e.get("sprite", "default") or "default"+ return ["bank:dashSwitch_" + ("default" if s == "default" else "mirror")]+++def _swap(e):+ if e.get("theme", "Normal") == "Moon":+ return ["tex:objects/swapblock/moon/block", "tex:objects/swapblock/moon/blockRed",+ "tex:objects/swapblock/moon/target", "fam:objects/swapblock/moon/midBlock",+ "fam:objects/swapblock/moon/midBlockRed"]+ return []+++# assets that depend on an entity's attributes: name -> function(entity) -> list+NEEDS = {"templeGate": _gate, "dashSwitchH": _dash_switch, "dashSwitchV": _dash_switch, "swapBlock": _swap}++# the story (CS05_TheoPhone): the phone the interact trigger of ch5_theo_phone puts down+VARIANTS = {"interactTrigger": ("event", {"ch5_theo_phone": ["tex:characters/theo/phone"]})}++++diff --git a/games/celeste/tools/assets_ch6.py b/games/celeste/tools/assets_ch6.pynew file mode 100644index 00000000..b217d193--- /dev/null+++ b/games/celeste/tools/assets_ch6.py@@ -0,0 +1,34 @@+"""What Reflection's own entities draw (src/ch6.c)."""++HEART = ["bank:heartgem0", "bank:heartgem1", "bank:heartgem2", "bank:heartgem3", "bank:heartGemGhost"]++ASSETS = {+ # Sprites.xml says objects/bumper/ and objects/badelineBoost/, the atlas has other cases: the frames are+ # listed as families ("lazy:": only the first is loaded with the room)+ "bigSpinner": ["lazy:fam:objects/Bumper/Idle", "lazy:fam:objects/Bumper/Evil"],+ "infiniteStar": ["bank:flyFeather", "tex:objects/flyFeather/outline"],+ "starJumpBlock": ["fam:objects/starjumpBlock/corner", "fam:objects/starjumpBlock/edgeH",+ "fam:objects/starjumpBlock/edgeV", "fam:objects/starjumpBlock/leftrailing",+ "fam:objects/starjumpBlock/railing", "fam:objects/starjumpBlock/rightrailing"],+ "plateau": ["tex:scenery/fallplateau"],+ "crushBlock": ["fam:objects/crushblock/block", "tex:objects/crushblock/lit_left", "tex:objects/crushblock/lit_right",+ "tex:objects/crushblock/lit_top", "tex:objects/crushblock/lit_bottom",+ "bank:crushblock_face", "bank:giant_crushblock_face"],+ "bigWaterfall": [],+ "badelineBoost": ["lazy:fam:objects/badelineboost/idle", "tex:objects/badelineboost/stretch", "bank:badeline"],+ "reflectionHeartStatue": ["tex:objects/reflectionHeart/statue", "tex:objects/reflectionHeart/gem",+ "fam:objects/reflectionHeart/torch", "fam:objects/reflectionHeart/hint",+ "tex:collectables/heartGem/white00", "tex:collectables/heartGem/orb"] + HEART,+ "finalBoss": ["bank:badeline_boss", "bank:badeline_projectile", "bank:badeline_beam", "bank:badeline_beam_start",+ "bank:badeline"],+ # their tiles: 'g' (reflection) and, highlighted, 'G' (reflectionAlt)+ "finalBossFallingBlock": ["tex:tilesets/reflection", "tex:tilesets/reflectionAlt"],+ "finalBossMovingBlock": ["tex:tilesets/reflection", "tex:tilesets/reflectionAlt", "tex:debris/f"],+ "tentacles": [],+}++# the story's own: Badeline crying after the fight, her orbs and the level up (CS06_BossEnd)+NPC_ASSETS = {+ "06_crying": ["bank:badeline_boss", "tex:characters/badelineBoss/calm_white", "tex:characters/badeline/orb",+ "bank:player_level_up"],+}diff --git a/games/celeste/tools/assets_ch7.py b/games/celeste/tools/assets_ch7.pynew file mode 100644index 00000000..b25ae842--- /dev/null+++ b/games/celeste/tools/assets_ch7.py@@ -0,0 +1,30 @@+"""What the Summit's own entities draw (src/ch7.c): its checkpoints, gems, clouds, the ascent between its parts+(SummitBackgroundManager: AscendManager), and the credits' rooms."""+import sys as _sys++_GEMS = ["fam:collectables/summitgems/%d/gem" % i for i in range(6)]++ASSETS = {+ "summitcheckpoint": ["tex:scenery/summitcheckpoints/base00", "tex:scenery/summitcheckpoints/base01",+ "tex:scenery/summitcheckpoints/base02", "fam:scenery/summitcheckpoints/numberbg",+ "fam:scenery/summitcheckpoints/number"],+ "summitgem": ["tex:collectables/heartGem/orb"], # NEEDS: its own gem+ "summitGemManager": _GEMS + ["tex:collectables/summitgems/%d/bg" % i for i in range(6)],+ "summitcloud": ["tex:scenery/summitclouds/cloud00", "tex:scenery/summitclouds/cloud01"],+ "SummitBackgroundManager": ["fam:scenery/launch/slice", "tex:scenery/launch/cloud00", "tex:scenery/launch/cloud01"],+ "creditsTrigger": [], # VARIANTS: the credits' Oshiro+}++NEEDS = {"summitgem": lambda e: [_GEMS[int(e.get("gem", 0)) % 6]]}++# the credits' resort: Oshiro sweeping, his broom, the dust bunnies and their boxes+VARIANTS = {"creditsTrigger": ("event", {"Oshiro": ["bank:oshiro", "tex:characters/oshiro/broom",+ "tex:decals/3-resort/brokenbox_a", "tex:decals/3-resort/brokenbox_b",+ "tex:decals/3-resort/brokenbox_c", "fam:danger/dustcreature/base",+ "fam:danger/dustcreature/center", "fam:danger/dustcreature/eyes"]})}++# SummitBackgroundManager is the game's AscendManager (Level.LoadLevel): the Summit's climbs between its parts and their+# cutscenes (CS07_Ascend). tools/entities.py drops it with the sound-only entities; it is kept here.+_E = _sys.modules.get("entities")+if _E is not None:+ _E.DROP.discard("SummitBackgroundManager")diff --git a/games/celeste/tools/assets_ch8.py b/games/celeste/tools/assets_ch8.pynew file mode 100644index 00000000..a8e30629--- /dev/null+++ b/games/celeste/tools/assets_ch8.py@@ -0,0 +1,11 @@+"""What the Epilogue's own entities draw (src/ch8.c): the fixed bridge (the Summit's credits have it too) and,+in the cabin, the Oshiro of CS08_Ending (Granny and Theo come with the npc entity's own assets)."""++ASSETS = {+ "bridgeFixed": ["tex:scenery/bridge_fixed"],+}++# npc names containing these: granny_08_inside, theo_08_inside+NPC_ASSETS = {+ "08_inside": ["bank:oshiro"],+}diff --git a/games/celeste/tools/assets_ch9.py b/games/celeste/tools/assets_ch9.pynew file mode 100644index 00000000..6b30ea6b--- /dev/null+++ b/games/celeste/tools/assets_ch9.py@@ -0,0 +1,20 @@+"""What Core's own entities draw (src/ch9.c)."""++ASSETS = {+ "coreModeToggle": ["bank:coreFlipSwitch"],+ "fireBall": ["bank:fireball"],+ "wallBooster": ["fam:objects/wallBooster/fireTop", "fam:objects/wallBooster/fireMid",+ "fam:objects/wallBooster/fireBottom", "fam:objects/wallBooster/iceTop",+ "fam:objects/wallBooster/iceMid", "fam:objects/wallBooster/iceBottom"],+ # the code says objects/bumpblocknew, the atlas BumpBlockNew (Monocle's lookups ignore case)+ "bounceBlock": ["tex:objects/BumpBlockNew/fire00", "tex:objects/BumpBlockNew/ice00",+ "fam:objects/BumpBlockNew/fire_rubble", "fam:objects/BumpBlockNew/ice_rubble",+ "bank:bumpBlockCenterFire", "bank:bumpBlockCenterIce"],+ "fireBarrier": ["fam:danger/lava/bubble_a"],+ "iceBlock": [],+ "risingLava": ["fam:danger/lava/bubble_a"],+ "sandwichLava": ["fam:danger/lava/bubble_a"],+ "heartGemDoor": ["fam:objects/heartdoor/icon", "tex:objects/heartdoor/edge", "tex:objects/heartdoor/top",+ "tex:objects/heartdoor/mist"],+ "coreMessage": [],+}diff --git a/games/celeste/tools/cel.py b/games/celeste/tools/cel.pynew file mode 100644index 00000000..9fb94015--- /dev/null+++ b/games/celeste/tools/cel.py@@ -0,0 +1,218 @@+"""Readers for Celeste's content files (maps, atlases), used by the converter.++CELESTE points at the game's Content folder (the one with Maps/ and Graphics/).+"""+import os+import struct+import numpy as np++CELESTE = os.environ.get("CELESTE", os.path.expanduser("~/Documents/Assets/gamesrc/celeste/Celeste"))+++class Reader:+ def __init__(self, data):+ self.d = data+ self.p = 0++ def u8(self):+ v = self.d[self.p]+ self.p += 1+ return v++ def i16(self):+ v = struct.unpack_from("<h", self.d, self.p)[0]+ self.p += 2+ return v++ def i32(self):+ v = struct.unpack_from("<i", self.d, self.p)[0]+ self.p += 4+ return v++ def f32(self):+ v = struct.unpack_from("<f", self.d, self.p)[0]+ self.p += 4+ return v++ def str(self):+ n = shift = 0+ while True:+ b = self.u8()+ n |= (b & 0x7F) << shift+ shift += 7+ if b < 0x80:+ break+ s = self.d[self.p:self.p + n].decode("utf-8")+ self.p += n+ return s+++class Element:+ __slots__ = ("name", "attr", "children")++ def __init__(self, name):+ self.name = name+ self.attr = {}+ self.children = []++ def child(self, name):+ for c in self.children:+ if c.name == name:+ return c+ return None++ def __getitem__(self, k):+ return self.attr[k]++ def get(self, k, default=None):+ return self.attr.get(k, default)++ def __repr__(self):+ return f"<{self.name} {self.attr} [{len(self.children)}]>"+++def read_map(path):+ """A map (.bin, BinaryPacker format) as an Element tree; returns (package, root)."""+ r = Reader(open(path, "rb").read())+ assert r.str() == "CELESTE MAP"+ package = r.str()+ lookup = [r.str() for _ in range(r.i16())]++ def element():+ e = Element(lookup[r.i16()])+ for _ in range(r.u8()):+ k = lookup[r.i16()]+ t = r.u8()+ if t == 0:+ v = r.u8() != 0+ elif t == 1:+ v = r.u8()+ elif t == 2:+ v = r.i16()+ elif t == 3:+ v = r.i32()+ elif t == 4:+ v = r.f32()+ elif t == 5:+ v = lookup[r.i16()]+ elif t == 6:+ v = r.str()+ elif t == 7:+ n = r.i16()+ raw = r.d[r.p:r.p + n]+ r.p += n+ v = "".join(chr(raw[i + 1]) * raw[i] for i in range(0, n, 2))+ else:+ raise ValueError(t)+ e.attr[k] = v+ for _ in range(r.i16()):+ e.children.append(element())+ return e++ return package, element()+++class Sub:+ """A texture in an atlas: where it is in its page, and its frame (trim offsets)."""+ __slots__ = ("atlas", "page", "path", "x", "y", "w", "h", "fx", "fy", "fw", "fh")++ def __repr__(self):+ return f"<{self.path} {self.w}x{self.h} frame {self.fx},{self.fy} {self.fw}x{self.fh}>"++ def image(self):+ """RGBA numpy array (premultiplied alpha), with the trim restored (fw x fh)."""+ out = np.zeros((self.fh, self.fw, 4), np.uint8)+ out[-self.fy:-self.fy + self.h, -self.fx:-self.fx + self.w] = self.trimmed()+ return out++ def trimmed(self):+ own = os.path.join(self.atlas.dir, self.atlas.name, self.path + ".data")+ if not os.path.exists(os.path.join(self.atlas.dir, self.page + ".data")) and os.path.exists(own):+ return read_data(own)[self.y:self.y + self.h, self.x:self.x + self.w]+ page = self.atlas.page(self.page)+ return page[self.y:self.y + self.h, self.x:self.x + self.w]+++def read_data(path):+ """An atlas page (.data: RLE coded) as an RGBA numpy array."""+ d = open(path, "rb").read()+ w, h = struct.unpack_from("<ii", d, 0)+ alpha = d[8] != 0+ out = np.zeros(w * h * 4, np.uint8)+ p, o, end = 9, 0, w * h * 4+ # runs: count, then [alpha], then BGR when visible+ mv = memoryview(d)+ while o < end:+ n = d[p]+ p += 1+ if alpha:+ a = d[p]+ p += 1+ if a:+ b, g, r = d[p], d[p + 1], d[p + 2]+ p += 3+ px = bytes((r, g, b, a)) * n+ else:+ px = bytes(4 * n)+ else:+ b, g, r = d[p], d[p + 1], d[p + 2]+ p += 3+ px = bytes((r, g, b, 255)) * n+ out[o:o + 4 * n] = np.frombuffer(px, np.uint8)+ o += 4 * n+ return out.reshape(h, w, 4)+++class Atlas:+ def __init__(self, name):+ self.name = name+ self.dir = os.path.join(CELESTE, "Graphics", "Atlases")+ r = Reader(open(os.path.join(self.dir, name + ".meta"), "rb").read())+ r.i32()+ r.str()+ r.i32()+ self.subs = {}+ self.pages = []+ self._pages = {}+ for _ in range(r.i16()):+ page = r.str()+ self.pages.append(page)+ for _ in range(r.i16()):+ s = Sub()+ s.atlas, s.page = self, page+ s.path = r.str().replace("\\", "/")+ s.x, s.y, s.w, s.h = r.i16(), r.i16(), r.i16(), r.i16()+ s.fx, s.fy, s.fw, s.fh = r.i16(), r.i16(), r.i16(), r.i16()+ self.subs[s.path] = s++ def page(self, name):+ if name not in self._pages:+ cache = os.path.join(os.environ.get("CELESTE_CACHE", "/tmp/celeste_cache"), self.name + "_" + name.replace("/", "_") + ".npy")+ if os.path.exists(cache):+ self._pages[name] = np.load(cache)+ else:+ self._pages[name] = read_data(os.path.join(self.dir, name + ".data"))+ os.makedirs(os.path.dirname(cache), exist_ok=True)+ np.save(cache, self._pages[name])+ return self._pages[name]++ # Monocle's atlases ignore case+ def _lower(self):+ if not hasattr(self, "_low"):+ self._low = {k.lower(): v for k, v in self.subs.items()}+ return self._low++ def __getitem__(self, path):+ return self.subs[path] if path in self.subs else self._lower()[path.lower()]++ def __contains__(self, path):+ return path in self.subs or path.lower() in self._lower()++ def prefix(self, pre):+ """Subtextures named pre + digits, in number order (Celeste's GetAtlasSubtextures)."""+ out = []+ low = pre.lower()+ for k, s in self.subs.items():+ if k.lower().startswith(low) and k[len(pre):].isdigit():+ out.append((int(k[len(pre):]), s))+ return [s for _, s in sorted(out, key=lambda t: t[0])]diff --git a/games/celeste/tools/entities.py b/games/celeste/tools/entities.pynew file mode 100644index 00000000..4d7f9569--- /dev/null+++ b/games/celeste/tools/entities.py@@ -0,0 +1,142 @@+"""What each Celeste entity needs from the art, for the converter.++ASSETS[name] lists what a room with that entity must have loaded:+ "bank:NAME" a sprite from Sprites.xml (all its animations' frames)+ "fam:PATH" a family of textures PATH00, PATH01... (or PATH itself)+ "tex:PATH" one texture+Entities in DROP are left out of the rooms (sound-only, editor-only, music)."""++DROP = {+ "soundSource", "SummitBackgroundManager", "cutsceneNode",+}+DROP_TRIGGERS = {+ "musicFadeTrigger", "musicTrigger", "altMusicTrigger", "ambienceParamTrigger", "audioFadeTrigger",+}++SPIKE_TYPES = ("default", "outline", "cliffside", "reflection")+++def spikes(direction):+ return ["fam:danger/spikes/%s_%s" % (t, direction) for t in SPIKE_TYPES]+++ASSETS = {+ "player": [],+ # Blade/Dust Rotate/TrackSpinner (src/dust.c): blades outside the dust rooms (those get pack.py's DUST_TEX)+ "rotateSpinner": ["lazy:bank:templeBlade"],+ "trackSpinner": ["lazy:bank:templeBlade"],+ "spikesUp": spikes("up"),+ "spikesDown": spikes("down"),+ "spikesLeft": spikes("left"),+ "spikesRight": spikes("right"),+ "jumpThru": ["tex:objects/jumpthru/wood", "tex:objects/jumpthru/dream", "tex:objects/jumpthru/temple",+ "tex:objects/jumpthru/templeB", "tex:objects/jumpthru/cliffside", "tex:objects/jumpthru/reflection",+ "tex:objects/jumpthru/core", "tex:objects/jumpthru/moon"],+ "spring": ["fam:objects/spring/", "fam:objects/spring/white"],+ "wallSpringLeft": ["fam:objects/spring/", "fam:objects/spring/white"],+ "wallSpringRight": ["fam:objects/spring/", "fam:objects/spring/white"],+ "refill": ["fam:objects/refill/idle", "fam:objects/refill/flash", "tex:objects/refill/outline",+ "fam:objects/refillTwo/idle", "fam:objects/refillTwo/flash", "tex:objects/refillTwo/outline"],+ "strawberry": ["bank:strawberry", "bank:ghostberry", "bank:strawberrySeed", "bank:ghostberrySeed",+ "bank:goldberrySeed"],+ "goldenBerry": ["bank:goldberry", "bank:goldghostberry", "bank:strawberry"],+ "memorialTextController": ["bank:goldberry", "bank:goldghostberry", "bank:strawberry"],+ "crumbleBlock": ["tex:objects/crumbleBlock/default", "tex:objects/crumbleBlock/outline",+ "tex:objects/crumbleBlock/cliffside", "tex:objects/crumbleBlock/reflection",+ "tex:objects/crumbleBlock/summit", "tex:objects/crumbleBlock/core",+ "tex:objects/crumbleBlock/dream", "tex:objects/crumbleBlock/temple"],+ "zipMover": ["tex:objects/zipmover/block", "fam:objects/zipmover/light", "tex:objects/zipmover/cog",+ "fam:objects/zipmover/innercog"],+ "cassetteBlock": ["tex:objects/cassetteblock/solid", "fam:objects/cassetteblock/pressed"],+ "cassette": ["bank:cassette", "lazy:bank:cassetteGhost"],+ "fallingBlock": [],+ "fakeWall": [],+ "dashBlock": [],+ "coverupWall": [],+ "exitBlock": [],+ "lightbeam": ["tex:util/lightbeam"],+ "checkpoint": ["fam:objects/checkpoint/bg/"],+ "bonfire": ["bank:campfire"],+ "flutterbird": ["bank:flutterBird"],+ "bird": ["bank:bird"],+ "npc": [],+ "wire": [],+ "lamp": ["tex:scenery/lamp"],+ "memorial": ["tex:scenery/memorial/memorial", "tex:scenery/memorial/memorial_dreaming"],+ "introCar": ["tex:scenery/car/body", "tex:scenery/car/wheels", "tex:scenery/car/pavement", "tex:scenery/car/barrier"],+ "introCrusher": [],+ "bridge": ["tex:scenery/bridge"],+ "hahaha": ["fam:characters/oldlady/ha"],+ # ForsakenCitySatellite: the dish, its computer, the code birds, and the heart they make+ "birdForsakenCityGem": ["tex:objects/citysatellite/dish", "tex:objects/citysatellite/light",+ "tex:objects/citysatellite/computer", "tex:objects/citysatellite/computerscreen",+ "fam:objects/citysatellite/computerScreenNoise", "tex:objects/citysatellite/computerscreenShine",+ "fam:scenery/flutterbird/flap", "tex:collectables/heartGem/shape", "bank:heartgem0",+ "lazy:bank:heartGemWhite", "tex:collectables/heartGem/orb"],+ "towerviewer": ["bank:lookout"],+ "touchSwitch": ["tex:objects/touchswitch/container", "fam:objects/touchswitch/icon"],+ "switchGate": ["tex:objects/switchgate/block", "fam:objects/switchgate/icon"],+ "blackGem": ["bank:heartgem0", "lazy:bank:heartgem1", "lazy:bank:heartgem2", "lazy:bank:heartGemGhost",+ "lazy:bank:heartGemWhite", "tex:collectables/heartGem/orb"],+}++# NPC sprites by the npc attribute's prefix+NPC_ASSETS = {+ "granny": ["bank:granny"],+ "theo": ["bank:theo"],+ "oshiro": ["bank:oshiro"],+ "badeline": ["bank:badeline"],+}+++def keep(name):+ return name not in DROP+++def keep_trigger(name):+ return name not in DROP_TRIGGERS+++NEEDS = {} # name -> function(entity) -> assets that depend on its attributes (chapter files add them)+OWNER = {} # name -> the chapter file (src/chN.c) that makes it+++def needs(entity):+ """Assets one entity needs (the npc entity depends on which npc it is)."""+ out = list(ASSETS.get(entity.name, []))+ if entity.name in NEEDS:+ out += NEEDS[entity.name](entity)+ if entity.name == "npc":+ who = entity.get("npc", "")+ for k, v in NPC_ASSETS.items():+ if k in who:+ out += v+ return out+++def direct_textures(tex):+ """Textures drawn straight from flash, needed everywhere."""+ for fam in ("characters/player/", "characters/player_no_backpack/", "characters/badeline/"):+ pass+++# per-chapter asset lists (tools/assets_*.py), each with ASSETS and maybe NPC_ASSETS+def _load_chapter_assets():+ import glob+ import importlib.util+ import os+ for f in sorted(glob.glob(os.path.join(os.path.dirname(os.path.abspath(__file__)), "assets_*.py"))):+ spec = importlib.util.spec_from_file_location(os.path.basename(f)[:-3], f)+ mod = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(mod)+ ASSETS.update(getattr(mod, "ASSETS", {}))+ for k in getattr(mod, "ASSETS", {}):+ OWNER.setdefault(k, int(os.path.basename(f)[len("assets_ch"):-3]))+ NPC_ASSETS.update(getattr(mod, "NPC_ASSETS", {}))+ DROP.update(getattr(mod, "DROP", set()))+ NEEDS.update(getattr(mod, "NEEDS", {}))+ for name, (attr, table) in getattr(mod, "VARIANTS", {}).items(): # {name: (attribute, {value: assets})}+ NEEDS[name] = (lambda attr, table: lambda e: table.get(e.get(attr, ""), []))(attr, table)+++_load_chapter_assets()diff --git a/games/celeste/tools/gen_particles.py b/games/celeste/tools/gen_particles.pynew file mode 100644index 00000000..0e691c09--- /dev/null+++ b/games/celeste/tools/gen_particles.py@@ -0,0 +1,168 @@+#!/usr/bin/env python3+"""Celeste's particle types (ParticleTypes.Load in the game's code) -> src/ptypes.c / ptypes.h.++ CELESTE_SRC=<the game's code, decompiled with ILSpy> python3 tools/gen_particles.py++Each `X.Y = new ParticleType(base) { ... }` becomes a PType named P_X_Y (P_Y for+ParticleTypes' own). Colors are stored unpremultiplied with their alpha."""+import math+import os+import re++SRC = os.environ.get("CELESTE_SRC", os.path.expanduser("~/Documents/Assets/gamesrc/celeste-src"))+HERE = os.path.dirname(os.path.abspath(__file__))++XNA = {"LightSkyBlue": (135, 206, 250, 255), "White": (255, 255, 255, 255), "Black": (0, 0, 0, 255), "LightGray": (211, 211, 211, 255),+ "Aqua": (0, 255, 255, 255), "Red": (255, 0, 0, 255), "Transparent": (0, 0, 0, 0)}+CONSTS = {"Player.TwoDashesHairColor": (0xFF, 0x6D, 0xEF, 255), "Player.NormalHairColor": (0xAC, 0x32, 0x32, 255),+ "Player.UsedHairColor": (0x44, 0xB7, 0xFF, 255), "Player.FlyPowerHairColor": (0xF2, 0xEB, 0x6D, 255),+ "Water.SurfaceColor": (int(135 * .8), int(206 * .8), int(250 * .8), int(255 * .8)),+ "RisingLava.Hot[0]": (0xFF, 0x89, 0x33, 255), "RisingLava.Hot[1]": (0xF2, 0x5E, 0x29, 255),+ "RisingLava.Hot[2]": (0xD0, 0x1C, 0x01, 255), "RisingLava.Cold[0]": (0x33, 0xFF, 0xE7, 255),+ "RisingLava.Cold[1]": (0x4C, 0xA2, 0xEB, 255), "RisingLava.Cold[2]": (0x01, 0x51, 0xD0, 255)}+++class Col:+ def __init__(self, r, g, b, a=255):+ self.v = (r, g, b, a)++ def __mul__(self, k):+ r, g, b, a = self.v+ return Col(int(r * k), int(g * k), int(b * k), int(a * k))+++def hexcol(h):+ h = h.lstrip("#")+ return Col(int(h[0:2], 16), int(h[2:4], 16), int(h[4:6], 16), int(h[6:8], 16) if len(h) >= 8 else 255)+++def lerp(a, b, t):+ return Col(*(int(x + (y - x) * t) for x, y in zip(a.v, b.v)))+++def py_expr(e):+ e = e.strip()+ e = re.sub(r"(\d+(\.\d+)?)f\b", r"\1", e)+ e = e.replace("(float)Math.PI", "math.pi").replace("Math.PI", "math.pi").replace("(float)", "")+ e = re.sub(r'Calc\.HexToColor\("([0-9A-Fa-f]+)"\)', r'hexcol("\1")', e)+ e = re.sub(r"Color\.Lerp\(", "lerp(", e)+ for k, v in CONSTS.items():+ e = e.replace(k, "Col(%d,%d,%d,%d)" % v)+ e = e.replace("Color.White * ", "Col(255,255,255,255) * ")+ e = re.sub(r"Color\.(\w+)", lambda m: "Col(%d,%d,%d,%d)" % XNA[m.group(1)], e)+ e = re.sub(r"new Vector2\(([^,]+),([^)]+)\)", r"(\1,\2)", e)+ e = e.replace("Vector2.UnitY", "(0,1)").replace("Vector2.UnitX", "(1,0)").replace("Vector2.Zero", "(0,0)")+ e = re.sub(r"ParticleType\.\w+\.(\w+)", r'"\1"', e)+ e = e.replace("true", "True").replace("false", "False")+ return e+++def vmul(a, k):+ return (a[0] * k, a[1] * k)+++def evaluate(e, choosers):+ pe = py_expr(e)+ m = re.match(r'GFX\.Game\["([^"]+)"\]', pe)+ if m:+ return ("tex", [m.group(1)])+ if pe in choosers:+ return ("tex", choosers[pe])+ m = re.match(r"\((-?[\d.]+), *(-?[\d.]+)\) *\* *(-?[\d.]+)", pe)+ if m:+ return (float(m.group(1)) * float(m.group(3)), float(m.group(2)) * float(m.group(3)))+ return eval(pe, {"math": math, "hexcol": hexcol, "lerp": lerp, "Col": Col})+++DEFAULTS = dict(Color=Col(255, 255, 255), Color2=Col(255, 255, 255), ColorMode="Static", FadeMode="None",+ SpeedMin=0, SpeedMax=0, SpeedMultiplier=1, Acceleration=(0, 0), Friction=0, Direction=0,+ DirectionRange=0, LifeMin=0, LifeMax=0, Size=2, SizeRange=0, SpinMin=0, SpinMax=0,+ SpinFlippedChance=False, RotationMode="None", ScaleOut=False, UseActualDeltaTime=False,+ Source=None)+++def main():+ text = open(os.path.join(SRC, "Celeste", "ParticleTypes.cs")).read()+ body = text[text.index("public static void Load()"):]+ choosers = {}+ for m in re.finditer(r"Chooser<MTexture> (\w+) = new Chooser<MTexture>\(([^;]+)\);", body):+ choosers[m.group(1)] = re.findall(r'GFX\.Game\["([^"]+)"\]', m.group(2))+ types = {}+ order = []+ # statements of Load(), split at top-level semicolons+ stmts, depth, cur = [], 0, ""+ for ch in body[body.index("{") + 1:]:+ if ch in "({":+ depth += 1+ elif ch in ")}":+ depth -= 1+ if ch == ";" and depth == 0:+ stmts.append(cur.strip())+ cur = ""+ else:+ cur += ch+ for st in stmts:+ m = re.match(r"([\w.]+) = new ParticleType(\(([\w.]+)\))?\s*(\{(.*)\})?$", st, re.S)+ if m:+ name, base, fields = m.group(1), m.group(3), m.group(5) or ""+ t = dict(types[base]) if base else dict(DEFAULTS)+ for fm in re.finditer(r"(\w+) = (.+?),?\n", fields + "\n"):+ k, v = fm.group(1), fm.group(2).rstrip(",")+ if k == "SourceChooser":+ k = "Source"+ t[k] = evaluate(v, choosers)+ types[name] = t+ if name not in order:+ order.append(name)+ continue+ m = re.match(r"([\w.]+) = ([\w.]+)$", st)+ if m and m.group(2) in types:+ types[m.group(1)] = dict(types[m.group(2)])+ order.append(m.group(1))+ continue+ m = re.match(r"([\w.]+)\.(\w+) = (.+)$", st, re.S)+ if m and m.group(1) in types:+ k = "Source" if m.group(2) == "SourceChooser" else m.group(2)+ types[m.group(1)][k] = evaluate(m.group(3), choosers)+ textures = set()+ H = ["/* Generated by tools/gen_particles.py from the game's ParticleTypes. */", "#ifndef PTYPES_H",+ "#define PTYPES_H", '#include "fx.h"']+ C = ["/* Generated by tools/gen_particles.py from the game's ParticleTypes. */", '#include "fx.h"', ""]+ modes_c = {"Static": "PC_STATIC", "Choose": "PC_CHOOSE", "Blink": "PC_BLINK", "Fade": "PC_FADE"}+ modes_f = {"None": "PF_NONE", "Linear": "PF_LINEAR", "Late": "PF_LATE", "InAndOut": "PF_INOUT"}+ modes_r = {"None": "PR_NONE", "Random": "PR_RANDOM", "SameAsDirection": "PR_SAMEASDIR"}++ def col(c):+ r, g, b, a = c.v+ if a:+ r, g, b = (min(255, round(x * 255 / a)) for x in (r, g, b))+ return "0x%02X%02X%02X%02X" % (a, r, g, b)++ def f(x):+ v = "%.7g" % x+ if "." not in v and "e" not in v:+ v += ".0"+ return v + "f"+ for name in order:+ t = types[name]+ cname = "P_" + name.replace("ParticleTypes.", "").replace(".", "_")+ src = t["Source"][1] if t["Source"] else []+ textures.update(src)+ srcs = ", ".join("T_" + re.sub(r"[^A-Za-z0-9]", "_", s) for s in src) or "0"+ H.append("extern const PType %s;" % cname)+ C.append("const PType %s = {%s, %s, %s, %s, %s, %d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, {%s, %s}, %s, {%s}, %d, %d};" % (+ cname, col(t["Color"]), col(t["Color2"]), modes_c[t["ColorMode"]], modes_f[t["FadeMode"]],+ modes_r[t["RotationMode"]], 1 if t["ScaleOut"] else 0, f(t["Size"]), f(t["SizeRange"]),+ f(t["SpeedMin"]), f(t["SpeedMax"]), f(t["SpeedMultiplier"]), f(t["LifeMin"]), f(t["LifeMax"]),+ f(t["Direction"]), f(t["DirectionRange"]), f(t["SpinMin"]), f(t["SpinMax"]),+ 1 if t["SpinFlippedChance"] else 0, f(t["Acceleration"][0]), f(t["Acceleration"][1]), f(t["Friction"]),+ srcs, len(src), 1 if t["UseActualDeltaTime"] else 0))+ H.append("#endif")+ open(os.path.join(HERE, "..", "src", "ptypes.h"), "w").write("\n".join(H) + "\n")+ open(os.path.join(HERE, "..", "src", "ptypes.c"), "w").write("\n".join(C) + "\n")+ open(os.path.join(HERE, "ptype_textures.txt"), "w").write("\n".join(sorted(textures)) + "\n")+ print(len(order), "particle types,", len(textures), "textures")+++if __name__ == "__main__":+ main()diff --git a/games/celeste/tools/pack.py b/games/celeste/tools/pack.pynew file mode 100644index 00000000..a8697f4c--- /dev/null+++ b/games/celeste/tools/pack.py@@ -0,0 +1,2317 @@+#!/usr/bin/env python3+"""Celeste's content (maps, art, animations, text) -> src/data.bin + src/data.h.++ CELESTE=<the game's Content folder> python3 tools/pack.py++data.bin layout: a header of section offsets (see SECTIONS), then the+sections. Art the game draws all the time (Madeline, her hair, the HUD font)+is stored "direct" (row-RLE the engine draws straight from flash); everything+else is in LZMA packs that the engine decodes into its texture cache when a+room needs them. See src/res.c for the reader."""+import collections+import glob+import lzma+import os+import re+import struct+import sys+import xml.etree.ElementTree as ET++import numpy as np++sys.path.insert(0, os.path.dirname(__file__))+from cel import CELESTE, Atlas, read_map # noqa: E402+import tiles as T # noqa: E402+import entities as E # noqa: E402++HERE = os.path.dirname(os.path.abspath(__file__))+OUT_BIN = os.path.join(HERE, "..", "src", "data.bin")+OUT_H = os.path.join(HERE, "..", "src", "data.h")++MAP_AREA = {"0-Intro": 0, "1-ForsakenCity": 1, "1H-ForsakenCity": 1, "1X-ForsakenCity": 1, "2-OldSite": 2,+ "2H-OldSite": 2, "2X-OldSite": 2, "3-CelestialResort": 3, "3H-CelestialResort": 3,+ "3X-CelestialResort": 3, "4-GoldenRidge": 4, "4H-GoldenRidge": 4, "4X-GoldenRidge": 4,+ "5-MirrorTemple": 5, "5H-MirrorTemple": 5, "5X-MirrorTemple": 5, "6-Reflection": 6,+ "6H-Reflection": 6, "6X-Reflection": 6, "7-Summit": 7, "7H-Summit": 7, "7X-Summit": 7,+ "8-Epilogue": 8, "9-Core": 9, "9H-Core": 9, "9X-Core": 9, "LostLevels": 10}+ALL_MAPS = ["0-Intro", "1-ForsakenCity", "1H-ForsakenCity", "1X-ForsakenCity", "2-OldSite", "2H-OldSite",+ "2X-OldSite", "3-CelestialResort", "3H-CelestialResort", "3X-CelestialResort", "4-GoldenRidge",+ "4H-GoldenRidge", "4X-GoldenRidge", "5-MirrorTemple", "5H-MirrorTemple", "5X-MirrorTemple",+ "6-Reflection", "6H-Reflection", "6X-Reflection", "7-Summit", "7H-Summit", "7X-Summit",+ "8-Epilogue", "9-Core", "9H-Core", "9X-Core"]+MAPS = os.environ.get("MAPS", ",".join(ALL_MAPS)).split(",") # MAPS=0-Intro,1-ForsakenCity: a few, for tests++PACK_RAW = 24 * 1024 # raw bytes per texture pack+# Madeline's and Badeline's animations only cutscenes play: packed, not straight in flash+CUTSCENE_ANIMS = {"tentacle_grab", "tentacle_grabbed", "tentacle_pull", "tentacle_dangling", "sleep", "asleep",+ "halfWakeUp", "wakeUp", "carryTheoWalk", "carryTheoCollapse", "sitDown", "fallPose", "bagdown",+ "bigFallRecover", "roll", "rollGetUp", "downed", "faint", "fainted", "hug", "spawn", "angry",+ "laugh", "pretendDead"}+LAZY_ANIMS = []+DICT = 8 * 1024 # LZMA dictionary: the engine decodes through a ring buffer this big+MARGIN = 2 # tiles kept around each room for the autotiler++# ------------------------------------------------------------------ writers++class W:+ def __init__(self):+ self.b = bytearray()++ def u8(self, v):+ self.b += struct.pack("<B", v & 0xFF)++ def s8(self, v):+ self.b += struct.pack("<b", v)++ def u16(self, v):+ assert 0 <= v < 65536, v+ self.b += struct.pack("<H", v)++ def s16(self, v):+ assert -32768 <= v < 32768, v+ self.b += struct.pack("<h", v)++ def u32(self, v):+ self.b += struct.pack("<I", v)++ def s32(self, v):+ self.b += struct.pack("<i", v)++ def f32(self, v):+ self.b += struct.pack("<f", v)++ def raw(self, b):+ self.b += b++ def align(self, n=4):+ while len(self.b) % n:+ self.b.append(0)++ def __len__(self):+ return len(self.b)+++def lz(data):+ return lzma.compress(bytes(data), format=lzma.FORMAT_RAW, filters=[+ {"id": lzma.FILTER_LZMA1, "preset": 9 | lzma.PRESET_EXTREME, "lc": 0, "lp": 0, "pb": 0, "dict_size": DICT}])+++class Strings:+ def __init__(self):+ self.ids = {}+ self.list = []++ def __call__(self, s):+ if s not in self.ids:+ self.ids[s] = len(self.list)+ self.list.append(s)+ return self.ids[s]+++STR = Strings()+STR("")++# ------------------------------------------------------------------ textures++def to565(img):+ r = img[..., 0].astype(np.uint32)+ g = img[..., 1].astype(np.uint32)+ b = img[..., 2].astype(np.uint32)+ return (r >> 3) << 11 | (g >> 2) << 5 | (b >> 3)+++class Tex:+ """A texture the game uses: its pixels as 8-bit indices into a palette.+ Index 0 is transparent. kind: 0 packed RLE, 1 direct RLE, 2 packed raw (tilesets)."""++ def __init__(self, tid, path, sub):+ self.id = tid+ self.path = path+ self.sub = sub+ self.kind = 0+ self.pal = None+ self.data = None+ self.pack = -1+ self.offset = 0+ self.scale = 1+++class Textures:+ def __init__(self):+ self.atlases = [Atlas("Gameplay"), Atlas("Misc")]+ self.list = []+ self.by_path = {}++ def find(self, path):+ for a in self.atlases:+ if path in a:+ return a[path]+ return None++ def __call__(self, path, kind=0):+ """Id of a texture (added on first use), or None if the game has no such texture."""+ if path in self.by_path:+ t = self.list[self.by_path[path]]+ if kind == 1:+ t.kind = 1+ return t.id+ sub = self.find(path)+ if sub is None:+ return None+ t = Tex(len(self.list), path, sub)+ t.kind = kind+ self.list.append(t)+ self.by_path[path] = t.id+ return t.id++ def family(self, prefix, kind=0):+ """Ids of prefix + number textures, in number order (an animation's frames)."""+ out = []+ for a in self.atlases:+ for s in a.prefix(prefix):+ out.append(self(s.path, kind))+ if out:+ break+ if not out and self.find(prefix):+ out.append(self(prefix, kind))+ return out+++TEX = Textures()+++class Palettes:+ """Palettes of RGB565 colors + alpha, 256 entries max, shared when they fit."""++ def __init__(self):+ self.list = [] # list of lists of (c565, a)++ def assign(self, colors):+ """colors: set of (c565, a). Returns (palette id, {color: index})."""+ for i, p in enumerate(self.list):+ have = set(p)+ if colors <= have:+ return i, {c: p.index(c) + 1 for c in colors}+ for i, p in enumerate(self.list):+ have = set(p)+ if len(have | colors) <= 255 and i >= len(self.list) - 1:+ for c in sorted(colors - have):+ p.append(c)+ return i, {c: p.index(c) + 1 for c in colors}+ p = sorted(colors)+ self.list.append(p)+ return len(self.list) - 1, {c: p.index(c) + 1 for c in colors}+++PALS = Palettes()+++GRADIENTS = {"purplesunset": 4, "mist": 4, "darkswamp": 4, "vignette": 4, "northernlights": 2}+++def quantize(t):+ """Texture pixels -> (palette id, indices uint8 array h x w). Premultiplied alpha:+ fully transparent pixels become index 0. Tile sheets get their own palette+ (15 colors at most: they are cached at 4 bits a pixel); smooth gradients are+ stored smaller and drawn scaled up."""+ img = t.sub.trimmed()+ if t.scale > 1 and not isinstance(t.sub, HudSub):+ k = t.scale+ h, w = img.shape[0] // k * k, img.shape[1] // k * k+ img = img[:h, :w].astype(np.float32).reshape(h // k, k, w // k, k, 4).mean(axis=(1, 3)).round().astype(np.uint8)+ if len(np.unique(to565(img) | (img[..., 3].astype(np.uint32) >> 4) << 16)) > 255:+ # gradients: fewest colors that keep them smooth on a 16-bit screen+ from PIL import Image+ q = Image.fromarray(img, "RGBA").quantize(colors=255, method=Image.Quantize.FASTOCTREE, dither=Image.Dither.NONE)+ img = np.array(q.convert("RGBA"))+ print("quantized", t.path)+ a = img[..., 3].astype(np.uint32)+ # un-premultiply for the 565 color, keep alpha in 0..255 (quantized to 16 levels)+ rgb = img[..., :3].astype(np.float32)+ keyed = (a >> 4) # 0..15+ c = to565(img).astype(np.uint32)+ key = np.where(keyed == 0, 0xFFFFFFFF, c | (keyed << 16))+ uniq = [int(k) for k in np.unique(key) if k != 0xFFFFFFFF]+ colors = set((k & 0xFFFF, k >> 16) for k in uniq)+ if t.kind == 2:+ assert len(colors) <= 15, t.path+ p = sorted(colors)+ PALS.list.append(p)+ pid, idx = len(PALS.list) - 1, {c: p.index(c) + 1 for c in colors}+ else:+ pid, idx = PALS.assign(colors)+ lut = {k: idx[(k & 0xFFFF, k >> 16)] for k in uniq}+ lut[0xFFFFFFFF] = 0+ u, inv = np.unique(key, return_inverse=True)+ out = np.array([lut[int(v)] for v in u], np.uint8)[inv].reshape(key.shape)+ return pid, out+++def rle(idx):+ """Row RLE: per row, ops until the next row's offset.+ 0x00-0x3F skip n+1, 0x40-0x7F repeat n+1 of the next byte, 0x80-0xFF n+1 literals."""+ h, w = idx.shape+ rows = []+ body = bytearray()+ for y in range(h):+ rows.append(len(body))+ row = idx[y]+ # trailing transparent pixels need nothing+ end = w+ while end > 0 and row[end - 1] == 0:+ end -= 1+ x = 0+ while x < end:+ v = row[x]+ n = 1+ while x + n < end and row[x + n] == v:+ n += 1+ if v == 0:+ while n > 0:+ k = min(n, 64)+ body.append(k - 1)+ n -= k+ x += k+ continue+ if n >= 3:+ while n >= 3:+ k = min(n, 64)+ body += bytes((0x40 + k - 1, v))+ n -= k+ x += k+ continue+ # literals until a transparent pixel or a run of 3+ s = x+ while x < end and x - s < 128:+ v = row[x]+ n = 1+ while x + n < end and row[x + n] == v:+ n += 1+ if v == 0 or n >= 3:+ break+ x += min(n, 128 - (x - s))+ body.append(0x80 + (x - s) - 1)+ body += bytes(row[s:x].tolist())+ rows.append(len(body))+ hdr = bytearray()+ for r in rows:+ hdr += struct.pack("<H", r + 2 * (h + 1))+ return bytes(hdr + body)+++def rle_direct(idx):+ """A texture drawn straight from flash, as small as it goes: (format flags, bytes)."""+ flags, colors, body = rle_direct_parts(idx)+ return flags, colors + (b"\0" if colors and not flags & 4 and len(colors) & 1 else b"") + body+++def rle_direct_parts(idx):+ """(format flags, local palette, pixels). With 15 colors or fewer (flag 8), a local palette (count,+ then the colors' indices, in the order the pixels first have them: textures alike but for their+ colors get the same pixels) and the literals two pixels a byte (low nibble first), runs' values+ local too; rows whose ops all fit in a byte (flag 4) get a byte each (their lengths) instead of+ u16 offsets (kept even, from the table's start)."""+ flat = idx.ravel()+ _, first = np.unique(flat, return_index=True)+ uniq = [int(flat[i]) for i in sorted(first) if flat[i] != 0]+ nib = len(uniq) <= 15+ if nib:+ lut = np.zeros(256, np.uint8)+ for i, v in enumerate(uniq):+ lut[v] = i + 1+ idx = lut[idx]+ h, w = idx.shape+ rows = []+ for y in range(h):+ body = bytearray()+ row = idx[y]+ end = w+ while end > 0 and row[end - 1] == 0:+ end -= 1+ x = 0+ while x < end:+ v = row[x]+ n = 1+ while x + n < end and row[x + n] == v:+ n += 1+ if v == 0:+ while n > 0:+ k = min(n, 64)+ body.append(k - 1)+ n -= k+ x += k+ continue+ if n >= 3:+ while n >= 3:+ k = min(n, 64)+ body += bytes((0x40 + k - 1, int(v)))+ n -= k+ x += k+ continue+ st = x+ while x < end and x - st < 128:+ v = row[x]+ n = 1+ while x + n < end and row[x + n] == v:+ n += 1+ if v == 0 or n >= 3:+ break+ x += min(n, 128 - (x - st))+ body.append(0x80 + (x - st) - 1)+ lits = row[st:x].tolist()+ if nib:+ for i in range(0, len(lits), 2):+ body.append(lits[i] | ((lits[i + 1] if i + 1 < len(lits) else 0) << 4))+ else:+ body += bytes(lits)+ rows.append(bytes(body))+ flags = 0+ colors = b""+ out = bytearray()+ if nib:+ flags |= 8+ colors = bytes([len(uniq)] + uniq)+ if all(len(r) < 256 for r in rows):+ flags |= 4+ out += bytes(len(r) for r in rows)+ else:+ off = 2 * (h + 1)+ for r in rows:+ out += struct.pack("<H", off)+ off += len(r)+ out += struct.pack("<H", off)+ for r in rows:+ out += r+ return flags, colors, bytes(out)+++# ------------------------------------------------------------------ maps++def grid_from(text, w, h):+ g = [["0"] * w for _ in range(h)]+ if text:+ for y, row in enumerate(text.replace("\r", "").split("\n")[:h]):+ for x, c in enumerate(row[:w]):+ g[y][x] = c+ return g+++class Room:+ pass+++class Chapter:+ def __init__(self, name):+ self.name = name+ self.package, self.root = read_map(os.path.join(CELESTE, "Maps", name + ".bin"))+ self.rooms = []+ for l in self.root.child("levels").children:+ r = Room()+ r.e = l+ r.name = l["name"]+ if r.name.startswith("lvl_"):+ r.name = r.name[4:]+ r.x, r.y, r.w, r.h = l["x"], l["y"], l["width"], l["height"]+ self.rooms.append(r)+ self.fillers = [(f["x"], f["y"], f["w"], f["h"]) for f in self.root.child("Filler").children] \+ if self.root.child("Filler") else []+ self.build_grids()++ def build_grids(self):+ """The map's tile grids and their tiles, as Celeste's LevelLoader builds them."""+ import re as _re+ x0 = min(r.x for r in self.rooms)+ y0 = min(r.y for r in self.rooms)+ x1 = max(r.x + r.w for r in self.rooms)+ y1 = max(r.y + r.h for r in self.rooms)+ for fx, fy, fw, fh in self.fillers: # fillers are in tiles+ x0, y0 = min(x0, fx * 8), min(y0, fy * 8)+ x1, y1 = max(x1, (fx + fw) * 8), max(y1, (fy + fh) * 8)+ pad = 64+ bx, by, bw, bh = x0 - pad, y0 - pad, x1 - x0 + 2 * pad, y1 - y0 + 2 * pad+ tb = (bx // 8, by // 8, -(-bw // 8), -(-bh // 8))+ self.tb = tb+ TX, TY, TW, TH = tb+ bg = T.VMap(TW, TH, "0")+ fg = T.VMap(TW, TH, "0")+ inl = T.VMap(TW, TH, False)+ level_bounds = []+ split = _re.compile("\\r\\n|\\n\\r|\\n|\\r")+ for r in self.rooms:+ left, top = r.x // 8, r.y // 8+ tw, th = -(-r.w // 8), -(-r.h // 8)+ for name, dst in (("bg", bg), ("solids", fg)):+ text = r.e.child(name).get("innerText", "") if r.e.child(name) else ""+ rows = split.split(text)+ for i, row in enumerate(rows):+ for j, c in enumerate(row):+ dst[left + j - TX, top + i - TY] = c+ for xx in range(left, left + tw):+ for yy in range(top, top + th):+ inl[xx - TX, yy - TY] = True+ level_bounds.append((left - TX, top - TY, tw, th))+ for fx, fy, fw, fh in self.fillers:+ for m in range(fx, fx + fw):+ for n in range(fy, fy + fh):+ c = "0"+ if fy - TY > 0:+ c2 = fg[m - TX, fy - TY - 1]+ if c2 != "0":+ c = c2+ if c == "0" and fx - TX > 0:+ c3 = fg[fx - TX - 1, n - TY]+ if c3 != "0":+ c = c3+ if c == "0" and fx + fw - TX < TW - 1:+ c4 = fg[fx + fw - TX, n - TY]+ if c4 != "0":+ c = c4+ if c == "0" and fy + fh - TY < TH - 1:+ c5 = fg[m - TX, fy + fh - TY]+ if c5 != "0":+ c = c5+ if c == "0":+ c = "1"+ fg[m - TX, n - TY] = c+ inl[m - TX, n - TY] = True++ def extend(vm, r):+ left, top = r.x // 8, r.y // 8+ right, bottom = left + -(-r.w // 8), top + -(-r.h // 8)+ for xx in range(left, right):+ v = vm[xx - TX, top - TY]+ k = 1+ while k < 4 and not inl[xx - TX, top - TY - k]:+ vm[xx - TX, top - TY - k] = v+ k += 1+ v = vm[xx - TX, bottom - 1 - TY]+ k = 1+ while k < 4 and not inl[xx - TX, bottom - 1 - TY + k]:+ vm[xx - TX, bottom - 1 - TY + k] = v+ k += 1+ for yy in range(top - 4, bottom + 4):+ v = vm[left - TX, yy - TY]+ k = 1+ while k < 4 and not inl[left - TX - k, yy - TY]:+ vm[left - TX - k, yy - TY] = v+ k += 1+ v = vm[right - 1 - TX, yy - TY]+ k = 1+ while k < 4 and not inl[right - 1 - TX + k, yy - TY]:+ vm[right - 1 - TX + k, yy - TY] = v+ k += 1+ for r in self.rooms:+ extend(bg, r)+ for r in self.rooms:+ left, top = r.x // 8, r.y // 8+ right, bottom = left + -(-r.w // 8), top + -(-r.h // 8)+ for xx in range(left, right):+ if fg[xx - TX, top - TY] == "0":+ for k in range(1, 8):+ inl[xx - TX, top - TY - k] = True+ if fg[xx - TX, bottom - 1 - TY] == "0":+ for k in range(1, 8):+ inl[xx - TX, bottom - 1 - TY + k] = True+ for r in self.rooms:+ extend(fg, r)+ self.bgmap, self.fgmap = bg, fg+ self.fg = [bytearray(ord(c) for c in row) for row in fg.data]+ self.bg = [bytearray(ord(c) for c in row) for row in bg.data]+ self.level_bounds = level_bounds++ def generate(self, fgsets, bgsets, anim_frames):+ """Celeste's Autotiler over the whole map, seeded like LevelLoader (area name)."""+ area = MAP_AREA[self.name]+ seed = sum(ord(c) for c in "area_%d" % area)+ rnd = T.NetRandom(seed)+ self.bgt = T.generate(bgsets, self.bgmap, T.Behaviour(True, False, False), self.level_bounds, rnd, anim_frames)+ self.fgt = T.generate(fgsets, self.fgmap, T.Behaviour(True, False, True), self.level_bounds, rnd, anim_frames)++ def cell(self, grid, x, y):+ """GetTile with EdgesExtend: map-wide tile coordinates."""+ x0, y0, W_, H_ = self.tb+ gx = min(max(x - x0, 0), W_ - 1)+ gy = min(max(y - y0, 0), H_ - 1)+ return chr(grid[gy][gx])+++TERRAIN_INDEX = {} # (layer, char) -> combined terrain index (the TILESETS order)+++def room_cells_rle(ch, r, layer):+ """A room's final tiles (the game's autotiler, exact) with MARGIN cells around, as row RLE of+ (count u8, cell u16): 0 air, 63 solid without a tile, else terrain + 1 | quad << 6, bit 14: overlay."""+ tiles = ch.fgt if layer == 0 else ch.bgt+ vm = ch.fgmap if layer == 0 else ch.bgmap+ TX, TY, TW, TH = ch.tb+ tx, ty, tw, th = r.x // 8 - MARGIN, r.y // 8 - MARGIN, r.w // 8 + 2 * MARGIN, r.h // 8 + 2 * MARGIN+ rows = []+ body = bytearray()+ ovs = []+ for y in range(th):+ rows.append(len(body))+ line = []+ for x in range(tw):+ gx, gy = tx + x - TX, ty + y - TY+ c = vm[gx, gy]+ if is_air(c):+ line.append(0)+ continue+ t = tiles.get((gx, gy))+ if not t or t[0] is None:+ line.append(63)+ continue+ (qx, qy), ov = t[0], t[1]+ v = (TERRAIN_INDEX[(layer, c)] + 1) | (qy * 8 + qx) << 6+ if ov:+ v |= 1 << 14+ ovs.append((x, y, ov))+ line.append(v)+ x = 0+ while x < tw:+ v = line[x]+ n = 1+ while x + n < tw and line[x + n] == v and n < 255:+ n += 1+ body += struct.pack("<BH", n, v)+ x += n+ rows.append(len(body))+ return rows, bytes(body), ovs+++def is_air(c):+ return c == "0" or c == "\0"+++# ------------------------------------------------------------------ the room blob++def attr_kind(v):+ if isinstance(v, bool):+ return "b"+ if isinstance(v, int):+ return "i"+ if isinstance(v, float):+ return "f"+ return "s"+++class Schema:+ """Per entity/trigger name: its attributes, each stored in a fixed slot."""++ def __init__(self):+ self.attrs = collections.OrderedDict() # name -> OrderedDict(attr -> kind)+ self.ints = collections.defaultdict(lambda: (0, 0))++ def see(self, e):+ a = self.attrs.setdefault(e.name, collections.OrderedDict())+ for k, v in e.attr.items():+ if k in ("id", "x", "y", "originX", "originY"):+ continue+ kind = attr_kind(v)+ old = a.get(k)+ if old is None:+ a[k] = kind+ elif old != kind:+ if {old, kind} == {"i", "f"}:+ a[k] = "f"+ elif "s" in (old, kind):+ a[k] = "s"+ else:+ a[k] = "f"+ if kind == "i":+ lo, hi = self.ints[(e.name, k)]+ self.ints[(e.name, k)] = (min(lo, v), max(hi, v))++ def layout(self, name):+ """[(attr, kind, offset, size)], record size."""+ out = []+ off = 0+ for k, kind in self.attrs.get(name, {}).items():+ if kind == "b":+ size = 1+ elif kind == "s":+ size = 2+ elif kind == "i":+ lo, hi = self.ints[(name, k)]+ size = 2 if -32768 <= lo and hi < 32768 else 4+ else:+ size = 4+ if size > 1 and off % 2:+ off += 1+ if size == 4 and off % 4 == 2:+ off += 2+ out.append((k, kind if not (kind == "i" and size == 4) else "I", off, size))+ off += size+ if off % 2:+ off += 1+ return out, off+++SCHEMA = Schema()+++def write_attrs(w, e):+ lay, size = SCHEMA.layout(e.name)+ rec = bytearray(size)+ for k, kind, off, sz in lay:+ v = e.attr.get(k)+ if kind == "b":+ struct.pack_into("<B", rec, off, 1 if v else 0)+ elif kind == "i":+ struct.pack_into("<h", rec, off, int(v or 0))+ elif kind == "I":+ struct.pack_into("<i", rec, off, int(v or 0))+ elif kind == "f":+ struct.pack_into("<f", rec, off, float(v or 0))+ else:+ struct.pack_into("<H", rec, off, STR(str(v) if v is not None else ""))+ w.raw(bytes(rec))+++ENT_IDS = {}+TRIG_IDS = {}+ANIM_NAMES = ["grass_top_a", "dead_top_a"]+DECAL_ANIMS = {}+++def ent_type(name, table):+ if name not in table:+ table[name] = len(table)+ return table[name]+++def decal_tex(path):+ p = "decals/" + path.replace("\\", "/")+ if p.endswith(".png"):+ p = p[:-4]+ ids = TEX.family(p)+ if not ids:+ print("missing decal", p)+ return ids+++# AreaData: inventories (PlayerInventory), each mode's, and the checkpoints (level, inventory, flags:+# 1 dreaming, 2 core mode cold, 4 color grade feelingdown, 8 flag badeline_connection)+INVENTORIES = ["Prologue", "Default", "OldSite", "CH6End", "TheSummit", "Core", "Farewell"]+MODE_INVENTORY = {"0-Intro": "Prologue", "2-OldSite": "OldSite", "7-Summit": "TheSummit", "7H-Summit": "TheSummit",+ "7X-Summit": "TheSummit", "8-Epilogue": "TheSummit", "9-Core": "Core", "9H-Core": "Core",+ "9X-Core": "Core", "LostLevels": "Farewell"}+for _m in ALL_MAPS:+ MODE_INVENTORY.setdefault(_m, "Default")+_C = lambda *lv: [(x, None, 0) for x in lv]+CHECKPOINTS = {+ "1-ForsakenCity": _C("6", "9b"), "1H-ForsakenCity": _C("04", "08"),+ "2-OldSite": [("3", "Default", 1), ("end_3", None, 0)], "2H-OldSite": [("03", None, 1), ("08b", None, 1)],+ "3-CelestialResort": _C("08-a", "09-d", "00-d"), "3H-CelestialResort": _C("06", "11", "16"),+ "4-GoldenRidge": _C("b-00", "c-00", "d-00"), "4H-GoldenRidge": _C("b-00", "c-00", "d-00"),+ "5-MirrorTemple": [("b-00", None, 0), ("c-00", None, 1), ("d-00", None, 1), ("e-00", None, 1)],+ "5H-MirrorTemple": _C("b-00", "c-00", "d-00"),+ "6-Reflection": _C("00", "04", "b-00", "boss-00") + [("after-00", "CH6End", 8)],+ "6H-Reflection": _C("b-00", "c-00", "d-00"),+ "7-Summit": _C("b-00", "c-00", "d-00", "e-00b", "f-00", "g-00"),+ "7H-Summit": _C("b-00", "c-01", "d-00", "e-00", "f-00", "g-00"),+ "9-Core": [("a-00", None, 0), ("c-00", None, 2), ("d-00", None, 0)], "9H-Core": _C("a-00", "b-00", "c-01"),+ "LostLevels": _C("a-00", "c-00", "e-00z", "f-door", "h-00b") + [("i-00", None, 4), ("j-00", None, 4), ("j-16", None, 0)],+}+++def room_tiles(ch, grid, r):+ """A room's tile types with MARGIN cells around, as stored and as in RAM (level.c room_load builds it).+ Stored: u8 ntypes, u8 bits, the type chars, then the rows; a row is bytes (type index << bits | count - 1)+ up to the room's width. In RAM, after the type chars (align 2): u16 row offsets[th] into the row data,+ then the rows, each different row once (a row the same as one before is that one's)."""+ tx, ty, tw, th = r.x // 8 - MARGIN, r.y // 8 - MARGIN, r.w // 8 + 2 * MARGIN, r.h // 8 + 2 * MARGIN+ lines = [[ch.cell(grid, tx + i, ty + y) for i in range(tw)] for y in range(th)]+ types = sorted(set(c for line in lines for c in line))+ assert len(types) <= 16, (ch.name, r.name, types)+ bits = 6 if len(types) <= 4 else 5 if len(types) <= 8 else 4+ head = bytes([len(types), bits]) + bytes(ord(c) for c in types)+ stored = bytearray(head)+ data = bytearray()+ seen = {}+ rows = []+ for line in lines:+ out = bytearray()+ x = 0+ while x < tw:+ c = line[x]+ n = 1+ while x + n < tw and line[x + n] == c and n < (1 << bits):+ n += 1+ out.append(types.index(c) << bits | (n - 1))+ x += n+ out = bytes(out)+ stored += out+ if out not in seen:+ seen[out] = len(data)+ data += out+ rows.append(seen[out])+ w = W()+ w.raw(head)+ w.align(2)+ for o in rows:+ w.u16(o)+ w.raw(bytes(data))+ w.align(2)+ return bytes(stored), bytes(w.b)+++SPIN_X0 = 128 # cell x bias: spinners can be outside the room+++def room_spinners(ch, r):+ """Crystal and dust spinners not attached to solids, by tile row (some are outside the room):+ u16 n, s16 first row, u16 rows, u16 first[rows + 1], then per spinner+ u16 cell x + SPIN_X0 | x % 8 << 10 | y % 8 << 13 (by row, then x), then a nibble per spinner:+ which of its quarters are inside solid tiles (CreateSprites' SolidCheck)."""+ ents = r.e.child("entities").children if r.e.child("entities") else []+ recs = []+ for e in ents:+ if e.name != "spinner" or e.get("attachToSolid", False):+ continue+ x, y = int(e["x"]), int(e["y"])+ cx, cy = x // 8 + SPIN_X0, y // 8+ assert 0 <= cx < 1024, (r.name, x, y)+ mask = 0+ for bit, (dx, dy) in enumerate(((-4, -4), (4, -4), (4, 4), (-4, 4))):+ if ch.cell(ch.fg, (r.x + x + dx) // 8, (r.y + y + dy) // 8) != "0":+ mask |= 1 << bit+ recs.append((cy, cx, x % 8, y % 8, mask))+ recs.sort()+ row0 = recs[0][0] if recs else 0+ rows = recs[-1][0] - row0 + 1 if recs else 0+ w = W()+ w.u16(len(recs))+ w.s16(row0)+ w.u16(rows)+ i = 0+ for row in range(rows + 1):+ while i < len(recs) and recs[i][0] - row0 < row:+ i += 1+ w.u16(i)+ for cy, cx, dx, dy, mask in recs:+ w.u16(cx | dx << 10 | dy << 13)+ for k in range(0, len(recs), 2):+ w.u8(recs[k][4] | (recs[k + 1][4] << 4 if k + 1 < len(recs) else 0))+ if dust_room(ch, r):+ # DustStaticSpinner: its DustGraphic's nodes (AddDustNodesIfInCamera, autoExpandDust), from the tiles:+ # per spinner u16: enabled (4 bits), expanded in x (4), in y (4), nodes up-left, up-right, down-left, down-right+ pos = [(r.x + (cx - SPIN_X0) * 8 + dx, r.y + cy * 8 + dy) for cy, cx, dx, dy, _ in recs]++ def solid_rect(x, y, w_, h_):+ for gy in range(y // 8, (y + h_ - 1) // 8 + 1):+ for gx in range(x // 8, (x + w_ - 1) // 8 + 1):+ if ch.cell(ch.fg, gx, gy) != "0":+ return True+ return False++ def dust_rect(me, x, y, w_, h_): # another DustStaticSpinner's Circle(6) or Hitbox(16, 4, -8, -3)+ for k, (sx, sy) in enumerate(pos):+ if k == me:+ continue+ nx, ny = min(max(sx, x), x + w_), min(max(sy, y), y + h_)+ if (sx - nx) ** 2 + (sy - ny) ** 2 < 36:+ return True+ if x < sx + 8 and x + w_ > sx - 8 and y < sy + 1 and y + h_ > sy - 3:+ return True+ return False++ for k, (x, y) in enumerate(pos):+ v = 0+ for bit, (nx, ny) in enumerate(((-1, -1), (1, -1), (-1, 1), (1, 1))):+ if not solid_rect(x - 8 if nx < 0 else x, y - 8 if ny < 0 else y, 8, 8):+ v |= 1 << bit+ rx, ry = x - 4 + nx * 16, y - 4 + ny * 4+ if solid_rect(rx, ry, 8, 8) or dust_rect(k, rx, ry, 8, 8):+ v |= 1 << (4 + bit)+ rx, ry = x - 4 + nx * 4, y - 4 + ny * 16+ if solid_rect(rx, ry, 8, 8) or dust_rect(k, rx, ry, 8, 8):+ v |= 1 << (8 + bit)+ w.u16(v)+ return bytes(w.b), len(recs)+++def dust_room(ch, r):+ """Level.LoadLevel: spinners are dust in the Celestial Resort and the Summit's d- rooms."""+ area = MAP_AREA.get(ch.name, 0)+ return area == 3 or (area == 7 and r.name.startswith("d-"))+++DUST_TEX = [] # DustGraphic's textures (dust.c samples them as 4-bit pixels)+JUMPTHRU = ["wood", "wood", "wood", "wood", "cliffside", "temple", "reflection", "temple", "wood", "core", "wood"]+UI_PREFIXES = ("MENU_", "OPTIONS_", "KEY_CONFIG_", "OVERWORLD_", "AREA_", "AREACOMPLETE_", "CHECKPOINT_", "FILE_", "UI_",+ "POEM_")+ROOM_SIZES = {} # (chapter, room) -> bytes resident in RAM+BLOB_PARTS = collections.Counter()+BLOB_BYTES = {}+ROOM_POOL_FULL = 19092+++def room_blob(ch, r):+ """Everything a room needs; the first part (up to RB_ENTS) stays in RAM while the room is loaded+ (level.c room_load), the entities and triggers are read once."""+ w = W()+ hdr_at = len(w)+ for _ in range(12): # the parts' offsets (RB_FG .. RB_END), then RB_BG_RAM, RB_SHIFT+ w.u16(0)+ offs = []+ offs.append(len(w))+ fg, fg_ram = room_tiles(ch, ch.fg, r)+ w.raw(fg)+ offs.append(len(w))+ bg, bg_ram = room_tiles(ch, ch.bg, r)+ w.raw(bg)+ w.align(2)+ # in RAM the tiles take more (row offsets) or less (rows once): what follows them moves by `shift`+ bg_at = offs[0] + len(fg_ram)+ shift = (bg_at + len(bg_ram) - len(w) + 3) & ~3+ # extras: objtiles (tiles entities take), scenery tiles over fg and bg: u16 n, then (u16 x, y, tile)+ offs.append(len(w))++ def csv_cells(name):+ out = []+ el = r.e.child(name)+ if el is not None and el.get("innerText"):+ for y, row in enumerate(el.get("innerText").replace("\r", "").split("\n")):+ for x, v in enumerate(row.split(",")):+ v = v.strip()+ if v and v != "-1":+ out.append((x, y, int(v)))+ return out+ for lst in (csv_cells("objtiles"), csv_cells("fgtiles"), csv_cells("bgtiles")):+ w.u16(len(lst))+ for x, y, v in lst:+ w.u16(x)+ w.u16(y)+ w.u16(v)+ # decals: u16 n, u8 textures, u16 ids[textures], (align 2), then in columns: s16 x[n], s16 y[n],+ # u8 texture index | flip x << 6 | flip y << 7 [n]; in the map's order (it is the drawing order)+ for layer in ("fgdecals", "bgdecals"):+ offs.append(len(w))+ ds = r.e.child(layer).children if r.e.child(layer) else []+ recs = []+ texs = []+ for d in ds:+ ids = decal_tex(d["texture"])+ if not ids:+ continue+ if len(ids) > 1:+ DECAL_ANIMS[ids[0]] = len(ids)+ if ids[0] not in texs:+ texs.append(ids[0])+ fl = (1 << 6 if d.get("scaleX", 1) < 0 else 0) | (1 << 7 if d.get("scaleY", 1) < 0 else 0)+ recs.append((texs.index(ids[0]) | fl, int(round(d["x"])), int(round(d["y"]))))+ assert len(texs) <= 64, (ch.name, r.name, layer, len(texs))+ w.u16(len(recs))+ w.u8(len(texs))+ w.align(2)+ for t in texs:+ w.u16(t)+ for tid, x, y in recs:+ w.s16(x)+ for tid, x, y in recs:+ w.s16(y)+ for tid, x, y in recs:+ w.u8(tid)+ w.align(2)+ offs.append(len(w))+ spin, nspin = room_spinners(ch, r)+ w.raw(spin)+ w.align(2)+ # the textures loaded with the room: u16 n, ids+ offs.append(len(w))+ w.u16(len(r.need))+ for t in r.need:+ w.u16(t)+ w.align(4)+ # entities and triggers+ offs.append(len(w))+ resident = len(w) + ((nspin + 7) // 8 + 3 & ~3) # and a bit per spinner, once destroyed+ ents = r.e.child("entities").children if r.e.child("entities") else []+ ents = [e for e in ents if E.keep(e.name) and not (e.name == "spinner" and not e.get("attachToSolid", False))]+ w.u16(len(ents))+ for e in ents:+ write_entity(w, e, ent_type(e.name, ENT_IDS))+ offs.append(len(w))+ trigs = r.e.child("triggers").children if r.e.child("triggers") else []+ trigs = [e for e in trigs if E.keep_trigger(e.name)]+ w.u16(len(trigs))+ for e in trigs:+ write_entity(w, e, ent_type(e.name, TRIG_IDS))+ offs.append(len(w))+ assert len(w) < 65536+ for i, o in enumerate(offs):+ struct.pack_into("<H", w.b, hdr_at + 2 * i, o)+ struct.pack_into("<Hh", w.b, hdr_at + 2 * len(offs), bg_at, shift)+ assert resident + shift < 65536+ ROOM_SIZES[(ch.name, r.name)] = resident + shift+ for k, (a, b) in enumerate(zip(offs, offs[1:])):+ name = ("fg", "bg", "extras", "dfg", "dbg", "spin", "need", "ents", "trigs")[k]+ BLOB_PARTS[name] += b - a+ BLOB_BYTES.setdefault(name, bytearray()).extend(w.b[a:b])+ return bytes(w.b)+++def room_pool_size(chapters):+ """RAM for two rooms at once: the biggest pair of rooms that touch (a transition), or one room."""+ best = (0, "")+ for ch in chapters:+ rs = ch.rooms+ for i, a in enumerate(rs):+ sa = ROOM_SIZES[(ch.name, a.name)]+ if sa > best[0]:+ best = (sa, "%s:%s" % (ch.name, a.name))+ for b in rs[i + 1:]:+ if a.x <= b.x + b.w and b.x <= a.x + a.w and a.y <= b.y + b.h and b.y <= a.y + a.h:+ sb = ROOM_SIZES[(ch.name, b.name)]+ if sa + sb > best[0]:+ best = (sa + sb, "%s:%s+%s" % (ch.name, a.name, b.name))+ return best+++def write_entity(w, e, tid):+ nodes = [(n["x"], n["y"]) for n in e.children if n.name == "node"]+ w.u8(tid)+ w.u8(len(nodes))+ w.u16(e.get("id", 0) & 0xFFFF)+ w.s16(int(e.get("x", 0)))+ w.s16(int(e.get("y", 0)))+ write_attrs(w, e)+ for x, y in nodes:+ w.s16(int(x))+ w.s16(int(y))+ w.align(2)+++# ------------------------------------------------------------------ sprite banks (Sprites.xml)++def parse_frames(spec, n):+ """Celeste's frame lists: "0-3,5,7*4" (* repeats); empty = all."""+ if spec is None or spec == "":+ return list(range(n))+ out = []+ for part in spec.split(","):+ part = part.strip()+ if not part:+ continue+ rep = 1+ if "*" in part:+ part, r = part.split("*")+ rep = int(r)+ if "-" in part:+ a, b = (int(v) for v in part.split("-"))+ rng = range(a, b + 1) if a <= b else range(a, b - 1, -1)+ out += [v for v in rng for _ in range(rep)]+ else:+ out += [int(part)] * rep+ return out+++class Bank:+ def __init__(self, name):+ self.name = name+ self.path = ""+ self.origin = (0, 0, 0) # mode (0 none, 1 origin px, 2 justify), x, y+ self.start = None+ self.anims = collections.OrderedDict() # id -> dict(frames=[tex], delay, loop, goto=[(name, w)])+ self.meta = {}+++SPRITE_XML = ET.parse(os.path.join(CELESTE, "Graphics", "Sprites.xml")).getroot()+SPRITE_EL = {c.tag: c for c in SPRITE_XML}+BANKS = collections.OrderedDict()+++def _bank_add(b, el, path, fallback):+ for c in el:+ if c.tag == "Origin":+ b.origin = (1, float(c.get("x")), float(c.get("y")))+ elif c.tag == "Justify":+ b.origin = (2, float(c.get("x")), float(c.get("y")))+ elif c.tag == "Center":+ b.origin = (2, 0.5, 0.5)+ elif c.tag in ("Anim", "Loop"):+ p = c.get("path", "")+ fam = TEX.family(path + p)+ if not fam and fallback:+ fam = TEX.family(fallback + p)+ frames = parse_frames(c.get("frames"), len(fam))+ texs = [fam[i] for i in frames if i < len(fam)]+ if len(texs) != len(frames):+ print("bank", b.name, "anim", c.get("id"), "missing frames", path + p)+ goto = []+ if c.get("goto"):+ for g in c.get("goto").split(","):+ if ":" in g:+ n, wgt = g.split(":")+ goto.append((n.strip(), int(wgt)))+ else:+ goto.append((g.strip(), 1))+ b.anims[c.get("id")] = dict(frames=texs, delay=float(c.get("delay", "0")), loop=c.tag == "Loop", goto=goto)+ elif c.tag == "Metadata":+ for f in c:+ if f.tag == "Frames":+ b.meta[f.get("path")] = (f.get("hair"), f.get("carry"))+++def bank(name):+ if name in BANKS:+ return BANKS[name]+ el = SPRITE_EL[name]+ b = Bank(name)+ b.path = el.get("path", "")+ if el.get("copy"):+ base = SPRITE_EL[el.get("copy")]+ _bank_add(b, base, b.path, base.get("path", ""))+ b.meta.update(bank(el.get("copy")).meta)+ _bank_add(b, el, b.path, SPRITE_EL[el.get("copy")].get("path", "") if el.get("copy") else None)+ b.start = el.get("start")+ BANKS[name] = b+ return b+++def player_metadata():+ """Per texture of Madeline's banks: hair offset, hair frame, has hair, carry offset."""+ meta = {}+ for bname in ("player", "player_no_backpack", "player_badeline", "player_playback", "badeline"):+ if bname not in BANKS:+ continue+ b = BANKS[bname]+ for path, (hair, carry) in b.meta.items():+ for root in (b.path, "characters/player/"):+ fam = TEX.family(root + path)+ if fam:+ break+ hairs = hair.split("|") if hair is not None else []+ carries = carry.split(",") if carry else []+ for i, tid in enumerate(fam):+ m = [0, 0, 0, True, 0]+ if i < len(hairs):+ h = hairs[i].strip()+ if h == "x":+ m[3] = False+ elif h:+ if ":" in h:+ h, fr = h.split(":")+ m[2] = int(fr)+ hx, hy = h.split(",")+ m[0], m[1] = int(hx), int(hy)+ if i < len(carries):+ m[4] = int(carries[i])+ meta[tid] = m+ return meta++++# ------------------------------------------------------------------ the interface (1920x1080, shown at 1/6)++class HudSub:+ """A texture of the 1920x1080 interface (Gui and Portraits atlases) made screen sized:+ scaled by k, its colors cut down (shared by a family of frames), trimmed."""++ def __init__(self, path, img, fx, fy, fw, fh):+ self.path, self.img, self.fx, self.fy, self.fw, self.fh = path, img, fx, fy, fw, fh++ def trimmed(self):+ return self.img+++def crystal_borders(col):+ """The crystal spinners' black border (the Border entity draws each sprite four times, a pixel up, down, left+ and right) as textures of their own, a pixel bigger all around: src/spinner.c draws each once."""+ out = []+ for fam in ("fg_", "bg_"):+ for tid in TEX.family("danger/crystal/" + fam + col):+ t = TEX.list[tid]+ name = t.path + "_border"+ if name not in TEX.by_path:+ img = t.sub.image()+ h, w = img.shape[:2]+ on = np.zeros((h + 2, w + 2), bool)+ a = img[..., 3] > 0+ on[1:h + 1, 0:w] |= a+ on[1:h + 1, 2:w + 2] |= a+ on[0:h, 1:w + 1] |= a+ on[2:h + 2, 1:w + 1] |= a+ full = np.zeros((h + 2, w + 2, 4), np.uint8)+ full[on, 3] = 255+ ys, xs = np.nonzero(on)+ y0, y1, x0, x1 = ys.min(), ys.max() + 1, xs.min(), xs.max() + 1+ b = Tex(len(TEX.list), name, HudSub(name, full[y0:y1, x0:x1], -int(x0), -int(y0), w + 2, h + 2))+ TEX.list.append(b)+ TEX.by_path[name] = b.id+ out.append(TEX.by_path[name])+ return out+++def hud_family(atlas, paths, k, ncolors, div=1, hard=False, nib=False):+ """HUD textures for these atlas paths, scaled by k, with ncolors colors shared between them+ and 4 levels of transparency (hard: none); div > 1 stores them that many times smaller (drawn scaled up);+ nib: fewer colors if it takes that for each to be 15 colors or fewer (4 bits a pixel in the cache).+ Returns texture ids."""+ if nib:+ while ncolors > 4 and not hud_family_(atlas, paths, k, ncolors, div, hard, probe=True):+ ncolors -= 1+ return hud_family_(atlas, paths, k, ncolors, div, hard)+++def hud_family_(atlas, paths, k, ncolors, div=1, hard=False, probe=False):+ from PIL import Image+ scaled = []+ for path in paths:+ sub = atlas[path]+ im = Image.fromarray(sub.image(), "RGBA") # premultiplied: resampling it is right+ fw, fh = max(1, round(sub.fw * k / div)), max(1, round(sub.fh * k / div))+ a = np.array(im.resize((fw, fh), Image.LANCZOS)).astype(np.float32)+ scaled.append((path, a))+ # one palette for the family: un-premultiplied colors of the visible pixels+ lim = 128 if hard else 32+ vis = []+ for _, a in scaled:+ m = a[..., 3] >= lim+ rgb = a[..., :3][m] * 255 / a[..., 3][m][:, None]+ vis.append(np.clip(rgb, 0, 255).astype(np.uint8))+ allv = np.concatenate(vis) if vis else np.zeros((1, 3), np.uint8)+ pal_img = Image.fromarray(allv.reshape(1, -1, 3), "RGB").quantize(colors=ncolors, method=Image.Quantize.MEDIANCUT,+ dither=Image.Dither.NONE)+ ids = []+ for (path, a), v in zip(scaled, vis):+ m = a[..., 3] >= lim+ q = np.array(Image.fromarray(v.reshape(1, -1, 3), "RGB").quantize(palette=pal_img, dither=Image.Dither.NONE).convert("RGB")).reshape(-1, 3)+ alpha = np.full(m.sum(), 255.0) if hard else np.clip(np.round(a[..., 3][m] / 85) * 85, 85, 255)+ out = np.zeros(a.shape, np.uint8)+ out[m, :3] = (q.astype(np.float32) * alpha[:, None] / 255).round().astype(np.uint8)+ out[m, 3] = alpha.astype(np.uint8)+ if probe: # its colors as quantize() keys them+ keys = np.unique((to565(out) | (out[..., 3].astype(np.uint32) >> 4) << 16)[out[..., 3] > 0])+ if len(keys) > 15:+ return False+ continue+ ys, xs = np.nonzero(out[..., 3])+ if len(ys):+ y0, y1, x0, x1 = ys.min(), ys.max() + 1, xs.min(), xs.max() + 1+ else:+ y0 = x0 = 0+ y1 = x1 = 1+ sub = HudSub("@" + path, out[y0:y1, x0:x1], -int(x0) * div, -int(y0) * div, a.shape[1] * div, a.shape[0] * div)+ name = "@" + path+ if name in TEX.by_path:+ ids.append(TEX.by_path[name])+ continue+ t = Tex(len(TEX.list), name, sub)+ t.scale = div+ TEX.list.append(t)+ TEX.by_path[name] = t.id+ HUD_TEX.append(t.id)+ ids.append(t.id)+ return True if probe else ids+++HUD_TEX = [] # interface textures, packed after the rooms' (in this order)+PORTRAIT_EL = {}+++def portrait_bank(name):+ """A portrait (Portraits.xml) as a sprite bank, its frames at the size the textbox shows them:+ 240 interface pixels for `size` pixels (160 by default), so 40 / size on screen."""+ if name in BANKS:+ return BANKS[name]+ from cel import Atlas as _A+ atlas = PORTRAIT_ATLAS[0]+ el = PORTRAIT_EL[name]+ src = PORTRAIT_EL[el.get("copy")] if el.get("copy") else el+ b = Bank(name)+ b.path = el.get("path", src.get("path", ""))+ k = 40 / float(src.get("size", 160))+ for c in list(src) + ([c for c in el] if el is not src else []):+ if c.tag == "Center":+ b.origin = (2, 0.5, 0.5)+ elif c.tag in ("Anim", "Loop"):+ fam = atlas.prefix(b.path + c.get("path", ""))+ paths = [s.path for s in fam]+ # the big frames (Badeline climbing out of her box) are kept at half that+ big = paths and atlas[paths[0]].fw >= 320+ ids = hud_family(atlas, paths, k, 15, 2 if big else 1, True) if paths else []+ frames = parse_frames(c.get("frames"), len(ids))+ goto = []+ if c.get("goto"):+ for g in c.get("goto").split(","):+ n, _, wgt = g.partition(":")+ goto.append((n.strip(), int(wgt) if wgt else 1))+ b.anims[c.get("id")] = dict(frames=[ids[i] for i in frames if i < len(ids)], delay=float(c.get("delay", "0")),+ loop=c.tag == "Loop", goto=goto)+ b.meta = {"textbox": el.get("textbox", src.get("textbox", "default")), "glitchy": el.get("glitchy", src.get("glitchy"))}+ BANKS[name] = b+ return b+++def gui_bank(atlas, name, ncolors=16):+ """A sprite of SpritesGui.xml (the interface's) as bank "gui_NAME", its frames at 1/6."""+ key = "gui_" + name+ if key in BANKS:+ return BANKS[key]+ el = ET.parse(os.path.join(CELESTE, "Graphics", "SpritesGui.xml")).getroot().find(name)+ b = Bank(key)+ b.path = el.get("path", "")+ b.start = el.get("start")+ for c in el:+ if c.tag == "Center":+ b.origin = (2, 0.5, 0.5)+ elif c.tag == "Justify":+ b.origin = (2, float(c.get("x")), float(c.get("y")))+ elif c.tag in ("Anim", "Loop"):+ fam = atlas.prefix(b.path + c.get("path", ""))+ ids = hud_family(atlas, [s.path for s in fam], 1 / 6, ncolors) if fam else []+ frames = parse_frames(c.get("frames"), len(ids))+ goto = [(g.strip(), 1) for g in c.get("goto", "").split(",") if g.strip()]+ b.anims[c.get("id")] = dict(frames=[ids[i] for i in frames if i < len(ids)], delay=float(c.get("delay", "0")),+ loop=c.tag == "Loop", goto=goto)+ BANKS[key] = b+ return b+++PORTRAIT_ATLAS = []+TEXTBOXES = ["default", "madeline", "theo", "badeline", "granny", "oshiro", "oshiro_overlay", "default_mini",+ "theo_mini", "badeline_mini", "madeline_ask", "theo_ask"]+++def hud_assets():+ """Portraits, textboxes and interface pieces the text needs."""+ from cel import Atlas as _A+ PORTRAIT_ATLAS.append(_A("Portraits"))+ gui = _A("Gui")+ root = ET.parse(os.path.join(CELESTE, "Graphics", "Portraits.xml")).getroot()+ for c in root:+ PORTRAIT_EL[c.tag] = c+ for tb in TEXTBOXES:+ hud_family(PORTRAIT_ATLAS[0], ["textbox/" + tb], 1 / 6, 32, nib=True)+ hud_family(gui, ["textboxbutton"], 1 / 6, 16)+ # the story's pictures: Reflection's hug (CS06_BossEnd), Theo's selfies (Selfie), the breathing minigame+ for pic in ("hug1", "hug2", "hug-light2a", "hug-light2b", "hug-light2c", "selfie", "selfieFilter", "selfieGondola",+ "selfieCampfire"):+ hud_family(PORTRAIT_ATLAS[0], [pic], 1 / 6, 32, nib=True)+ for pic in ("finalbg", "final1", "final2", "final3", "final4", "final5"): # the Epilogue's end (CS08_Ending)+ hud_family(PORTRAIT_ATLAS[0], [pic], 1 / 6, 32, div=2, nib=True)+ hud_family(gui, ["feather/" + n for n in ("border", "box", "feather0", "feather1", "feather2", "feather3",+ "feather_half0", "feather_half1", "particle", "slice")], 1 / 6, 15, nib=True)+ hud_family(gui, ["hover/idle", "hover/highlight"], 1 / 6, 16)+ # the crystal heart's poem (Poem): the big hearts, the poem's sides, the streaks+ for i in range(3):+ gui_bank(gui, "heartgem%d" % i)+ hud_family(gui, ["poemside"], 1 / 6, 16)+ hud_family(_A("Overworld"), ["snow"], 1 / 6, 4)+ hud_family(gui, ["collectables/cassette"], 1 / 6, 16) # the cassette's message (Cassette.UnlockedBSide)+ # the menus (menu.c): the chapters' icons, their title banner, the main menu's icons, the logo, the stats' icons+ for icon in ("intro", "city", "oldsite", "resort", "cliffside", "temple", "reflection", "Summit", "core", "lock"):+ hud_family(gui, ["areas/" + icon], 1 / 6, 24)+ hud_family(gui, ["areaselect/title", "areaselect/accent"], 1 / 6, 8)+ for icon in ("start", "options", "credits", "exit"):+ hud_family(gui, ["menu/" + icon], 1 / 6, 16)+ hud_family(gui, ["title"], 1 / 6, 16)+ for icon in ("strawberry", "goldberry", "skullBlue"):+ hud_family(gui, ["collectables/" + icon], 1 / 6, 16)+ hud_family(gui, ["strawberryCountBG"], 1 / 6, 4)+ hud_family(gui, ["x"], 1 / 6, 4)+ hud_family(PORTRAIT_ATLAS[0], ["noise/%s" % s.path.split("/")[-1] for s in PORTRAIT_ATLAS[0].prefix("noise/")], 40 / 160, 8)+ for n in PORTRAIT_EL:+ if n.startswith("portrait_"):+ portrait_bank(n)+++def portrait_command(content):+ """{portrait ...} (FancyText) as numbers: bank, begin, idle, talk animations (255: none), side,+ flags (1 upside down, 2 flipped, 4 pop, 8 glitchy), textbox, overlay textures (65535: none)."""+ words = content.split()+ if words and words[0] == "none":+ return "{portrait none}"+ side, flags, sprite, anim = 0, 0, None, None+ for w_ in words:+ if w_ == "upsidedown":+ flags |= 1+ elif w_ == "flip":+ flags |= 2+ elif w_ == "left":+ side = -1+ elif w_ == "right":+ side = 1+ elif w_ == "pop":+ flags |= 4+ elif sprite is None:+ sprite = w_+ else:+ anim = w_+ names = {n.lower(): n for n in BANKS if n.startswith("portrait_")}+ bname = names.get(("portrait_" + (sprite or "")).lower())+ if bname is None:+ return "{portrait 255,255,255,255,%d,%d,65535,65535}" % (side, flags)+ b = BANKS[bname]+ an = list(b.anims)+ pick = lambda pre: an.index(pre + (anim or "")) if pre + (anim or "") in an else 255+ if b.meta.get("glitchy") == "true":+ flags |= 8+ tb = b.meta.get("textbox") or "default"+ t1 = TEX.by_path.get("@textbox/" + tb, TEX.by_path["@textbox/default"])+ t2 = TEX.by_path.get("@textbox/" + tb + "_overlay", 65535)+ return "{portrait %d,%d,%d,%d,%d,%d,%d,%d}" % (list(BANKS).index(bname), pick("begin_"), pick("idle_"), pick("talk_"),+ side, flags, t1, t2)+++# ------------------------------------------------------------------ assets per room++def asset_prefetch(a):+ """What of an asset is loaded with its room: a sprite's first animation (the rest loads when drawn);+ "lazy:" before an asset: only its first texture."""+ if a.startswith("lazy:"):+ return asset_textures(a[5:])[:1]+ kind, _, what = a.partition(":")+ if kind == "bank":+ b = bank(what)+ an = b.start if b.start in b.anims else ("idle" if "idle" in b.anims else next(iter(b.anims), None))+ return list(b.anims[an]["frames"]) if an else []+ return asset_textures(a)+++def asset_textures(a):+ if a.startswith("lazy:"):+ a = a[5:]+ kind, _, what = a.partition(":")+ if kind == "bank":+ b = bank(what)+ return [t for an in b.anims.values() for t in an["frames"]]+ if kind == "fam":+ return TEX.family(what)+ if kind == "tex":+ t = TEX(what)+ return [t] if t is not None else []+ raise ValueError(a)+++def styleground_list(ch):+ """The chapter's stylegrounds in draw order, with 'apply' attributes folded in.+ Returns (backgrounds, foregrounds): lists of (name, attrs)."""+ out = []+ style = ch.root.child("Style")+ for layer in ("Backgrounds", "Foregrounds"):+ items = []+ el = style.child(layer) if style else None++ def walk(e, inherited):+ for c in e.children:+ a = dict(inherited)+ a.update(c.attr)+ if c.name == "apply":+ walk(c, a)+ else:+ items.append((c.name, a))+ if el:+ walk(el, {})+ out.append(items)+ return out+++def room_matches(pattern, room):+ """Celeste's IsVisible room lists: comma separated, '*' wildcards, names without lvl_."""+ import fnmatch+ for p in pattern.split(","):+ p = p.strip()+ if not p:+ continue+ if fnmatch.fnmatchcase(room, p) or fnmatch.fnmatchcase("lvl_" + room, p):+ return True+ return False+++# ------------------------------------------------------------------ main++SECTIONS = ["TEX", "PAL", "PACKS", "DIRECT", "BANKS", "PMETA", "TILESETS", "CHAPTERS", "STRINGS", "BLOBS", "ANIMTILES",+ "DECALANIM", "TEXNAMES", "FONTS", "DIALOG", "TEXDIM", "UISTR"]+++def fnv24(s, basis=2166136261):+ """FNV-1a of a name, xor-folded to 24 bits (src/res.c res_tex_by_name)."""+ h = basis+ for c in s.encode():+ h = ((h ^ c) * 16777619) & 0xFFFFFFFF+ return (h ^ (h >> 24)) & 0xFFFFFF++++STYLE_EFFECTS = ["parallax", "snowFg", "snowBg", "windsnow", "stars", "reflectionfg", "godrays", "heatwave",+ "corestarsfg", "mirrorfg", "bossStarField", "petals", "northernlights", "dreamstars", "planets",+ "rain", "tentacles", "blackhole", "starfield"]++ROOM_ATTRS = ["dark", "space", "underwater", "whisper", "disableDownTransition"]+WIND = ["None", "Left", "Right", "LeftStrong", "RightStrong", "LeftOnOff", "RightOnOff", "LeftOnOffFast",+ "RightOnOffFast", "Alternating", "LeftGemsOnly", "RightCrazy", "Down", "Up", "Space"]+++def tex_header(t, w):+ """w, h, ox, oy, fw, fh (in stored pixels: divided by scale), palette, format, scale,+ and the bytes the engine's cache needs for it."""+ s = t.sub+ k = t.scale+ h_, w_ = t.idx.shape+ w.u16(w_)+ w.u16(h_)+ w.s16(-s.fx // k)+ w.s16(-s.fy // k)+ w.u16(s.fw // k)+ w.u16(s.fh // k)+ w.u16(t.pal)+ fmt = 2 if t.kind == 2 else rle_direct(t.idx)[0] if t.kind == 1 else (8 if local_colors(t.idx) else 0)+ w.u8(fmt)+ w.u8(k)+ w.u32((w_ * h_ + 1) // 2 if fmt == 2 else len(rle(t.idx)))+++def local_colors(idx):+ """A texture's colors when it has 15 or fewer (index 0 aside): the cache keeps it 4 bits a pixel (TF_NIB)."""+ uniq = sorted(set(np.unique(idx).tolist()) - {0})+ return uniq if 0 < len(uniq) <= 15 else None+++def packed_body(t):+ """A packed texture's bytes after its header: its pixels, or with TF_NIB its colors (count, then+ their indices) and its pixels as indices into them."""+ uniq = local_colors(t.idx) if t.kind == 0 else None+ if not uniq:+ return t.idx.tobytes()+ lut = np.zeros(256, np.uint8)+ for i, v in enumerate(uniq):+ lut[v] = i + 1+ return bytes([len(uniq)] + uniq) + lut[t.idx].tobytes()+++def main():+ fgsets = T.read_tilesets("ForegroundTiles")+ bgsets = T.read_tilesets("BackgroundTiles")+ k = 0+ for layer, sets in ((0, fgsets), (1, bgsets)):+ for c in sets:+ if c != "z":+ TERRAIN_INDEX[(layer, c)] = k+ k += 1+ at = ET.parse(os.path.join(CELESTE, "Graphics", "AnimatedTiles.xml")).getroot()+ anim_frames = {sp.get("name"): len(TEX.family(sp.get("path"))) for sp in at.iter("sprite")}+ chapters = [Chapter(m) for m in MAPS]++ for m in ALL_MAPS:+ _, root = read_map(os.path.join(CELESTE, "Maps", m + ".bin"))+ for l in root.child("levels").children:+ for k, table, keep in (("entities", ENT_IDS, E.keep), ("triggers", TRIG_IDS, E.keep_trigger)):+ if l.child(k):+ for e in l.child(k).children:+ SCHEMA.see(e)+ if keep(e.name):+ ent_type(e.name, table)+ if keep(e.name): # every texture the code can name has its id+ for a in E.needs(e):+ asset_textures(a)++ # every bank some entity uses, so the code always has its SB_/A_ names (textures only go in when a room needs them)+ for lst in list(E.ASSETS.values()) + list(E.NPC_ASSETS.values()):+ for a in lst:+ b = a[5:] if a.startswith("lazy:") else a+ if b.startswith("bank:") and b[5:] in SPRITE_EL:+ bank(b[5:])+ # banks every chapter needs; Madeline is drawn straight from flash, but for her cutscene poses, packed+ # (loaded when played: src/util.c spr_draw)+ keep = set()+ for b in ("player", "player_no_backpack", "badeline"):+ for name, an in bank(b).anims.items():+ if name not in CUTSCENE_ANIMS:+ keep.update(an["frames"])+ for t in keep:+ TEX.list[t].kind = 1+ LAZY_ANIMS[:] = [[t for t in an["frames"] if t not in keep]+ for b in ("player", "player_no_backpack", "badeline")+ for name, an in bank(b).anims.items() if name in CUTSCENE_ANIMS]+ lazy = {t for frames in LAZY_ANIMS for t in frames}+ for p in ("characters/player/hair00", "characters/player/bangs", "particles/smoke", "particles/zappysmoke",+ "particles/stars/", "particles/starfield/"):+ TEX.family(p, 1)+ for p in ("particles/blob", "particles/bubble", "particles/circle", "particles/cloud", "particles/confetti",+ "particles/feather", "particles/fire", "particles/petal", "particles/rect", "particles/shard",+ "particles/shatter", "particles/snow", "particles/triangle", "particles/triggerspike"):+ TEX(p, 1)+ for an in bank("player_sweat").anims.values():+ for t in an["frames"]:+ TEX.list[t].kind = 1+ hud_assets()+ pmeta = player_metadata()++ # tilesets: their images are packed raw+ for sets in (fgsets, bgsets):+ for t in sets.values():+ tid = TEX(t.path)+ if tid is not None:+ TEX.list[tid].kind = 2+ TEX("tilesets/scenery")+ DUST_TEX[:] = [TEX(p) for p in ("danger/dustcreature/base00", "danger/dustcreature/base01",+ "danger/dustcreature/base02", "danger/dustcreature/overlay00",+ "danger/dustcreature/overlay01", "danger/dustcreature/overlay02",+ "danger/dustcreature/center00", "danger/dustcreature/eyes00",+ "danger/dustcreature/eyes01", "danger/dustcreature/eyes02",+ "danger/dustcreature/templeeyes00", "danger/dustcreature/templeeyes01",+ "danger/dustcreature/templeeyes02", "danger/dustcreature/deadEyes")]+ for t in DUST_TEX:+ TEX.list[t].kind = 2++ # what each room needs+ for ch in chapters:+ ch.bgs, ch.fgs = styleground_list(ch)+ ch.style_tex = []+ for name, a in ch.bgs + ch.fgs:+ tid = TEX(a["texture"], 1) if name == "parallax" and "texture" in a else None+ if tid is not None and a["texture"] in GRADIENTS:+ TEX.list[tid].scale = GRADIENTS[a["texture"]]+ if name == "parallax" and tid is None:+ print("missing styleground texture", a.get("texture"))+ ch.style_tex.append(tid)+ for ch in chapters: # (once every styleground is known: one can be some room's entity's too)+ for r in ch.rooms:+ need = []+ for k in ("solids", "bg"):+ grid = r.e.child(k).get("innerText", "") if r.e.child(k) else ""+ sets = fgsets if k == "solids" else bgsets+ for c in sorted(set(grid) - set("0\r\n")):+ if c in sets:+ need.append(TEX(sets[c].path, 2))+ ents = r.e.child("entities").children if r.e.child("entities") else []+ trigs = r.e.child("triggers").children if r.e.child("triggers") else []+ uses = []+ for e in ents + [t for t in trigs if E.keep_trigger(t.name)]:+ if e.name == "jumpThru": # its own look, or the area's (AreaData.Jumpthru): not every one+ tx = e.get("texture", "default")+ tx = tx if tx != "default" else JUMPTHRU[MAP_AREA.get(ch.name, 0)]+ t_ = TEX("objects/jumpthru/" + tx)+ uses.append(t_)+ need.append(t_)+ continue+ for a in E.needs(e):+ uses += asset_textures(a)+ need += asset_prefetch(a)+ if "tiletype" in e.attr:+ c = str(e["tiletype"])+ if c in fgsets:+ need.append(TEX(fgsets[c].path))+ for layer in ("fgdecals", "bgdecals"):+ for d in (r.e.child(layer).children if r.e.child(layer) else []):+ need += decal_tex(d["texture"])+ r.style_mask = 0+ for i, (name, a) in enumerate(ch.bgs + ch.fgs):+ vis = True+ if a.get("only") and not room_matches(a["only"], r.name):+ vis = False+ if a.get("exclude") and room_matches(a["exclude"], r.name):+ vis = False+ if vis:+ r.style_mask |= 1 << i+ if ch.style_tex[i] is not None:+ need.append(ch.style_tex[i])+ dusty = dust_room(ch, r)+ if any(e.name in ("spinner", "rotateSpinner", "trackSpinner") for e in ents) and dusty:+ need += DUST_TEX # src/dust.c draws the DustGraphics from 4-bit pixels+ elif any(e.name == "spinner" for e in ents):+ area = MAP_AREA[ch.name]+ for col in {5: ("red",), 6: ("purple",), 9: ("blue", "red")}.get(area, ("blue",)):+ need += TEX.family("danger/crystal/fg_" + col) + TEX.family("danger/crystal/bg_" + col) + crystal_borders(col)+ if any(o for o in [r.e.child("objtiles")] if o is not None and o.get("innerText", "").strip(" \n-1,")):+ need.append(TEX("tilesets/scenery"))+ seen = set()+ seen |= lazy+ r.need = [t for t in need if t is not None and TEX.list[t].kind != 1 and not (t in seen or seen.add(t))]+ r.uses = r.need + [t for t in uses if t is not None and TEX.list[t].kind != 1 and not (t in seen or seen.add(t))]++ # pixels+ for t in TEX.list:+ t.pal, t.idx = quantize(t)++ # the texture cache a room needs (res.c: a 20-byte header, then RLE rows or 4-bit pixels)+ def cache_bytes(tid):+ t = TEX.list[tid]+ h_, w_ = t.idx.shape+ n = (w_ * h_ + 1) // 2 if t.kind == 2 else len(rle(t.idx)) + 2 * (h_ + 1)+ return (20 + n + 3) & ~3+ best = (0, "")+ for ch in chapters:+ sizes = [sum(cache_bytes(t) for t in r.need) for r in ch.rooms]+ for i, a in enumerate(ch.rooms):+ if sizes[i] > best[0]:+ best = (sizes[i], ch.name + ":" + a.name)+ for j in range(i + 1, len(ch.rooms)):+ b = ch.rooms[j]+ if a.x <= b.x + b.w and b.x <= a.x + a.w and a.y <= b.y + b.h and b.y <= a.y + a.h:+ both = sum(cache_bytes(t) for t in set(a.need) | set(b.need))+ if both > best[0]:+ best = (both, "%s:%s+%s" % (ch.name, a.name, b.name))+ print("texture cache needed", best)+ if os.environ.get("CACHE_REPORT"):+ rows = []+ for ch in chapters:+ for r in ch.rooms:+ tot = sum(cache_bytes(t) for t in r.need)+ fams = collections.Counter()+ for t in r.need:+ fams[TEX.list[t].path.split("/")[0] + "/" + (TEX.list[t].path.split("/")[1] if "/" in TEX.list[t].path else "")] += cache_bytes(t)+ rows.append((tot, ch.name, r.name, fams.most_common(4)))+ rows.sort()+ for x in rows[-15:]:+ print(x)+ print("rooms over 40K", sum(1 for x in rows if x[0] > 40000), "over 24K", sum(1 for x in rows if x[0] > 24000), "of", len(rows))++ # packs: each packed texture goes to the pack of the first room that needs it+ packs = [] # list of (raw bytes, [tex ids])+ cur = bytearray()+ cur_ids = []+ done = set()++ def flush():+ nonlocal cur, cur_ids+ if cur_ids:+ packs.append((bytes(cur), cur_ids))+ cur, cur_ids = bytearray(), []++ for ch in chapters:+ for r in ch.rooms:+ for tid in r.uses:+ if tid in done:+ continue+ done.add(tid)+ t = TEX.list[tid]+ hw = W()+ tex_header(t, hw)+ body = packed_body(t)+ if len(cur) + len(hw) + len(body) > PACK_RAW and cur_ids:+ flush()+ t.pack = len(packs)+ t.offset = len(cur)+ cur += hw.b + body+ cur_ids.append(tid)+ flush()+ if os.environ.get("HUD_REPORT"):+ fams = collections.Counter()+ for tid in HUD_TEX:+ t = TEX.list[tid]+ fams[re.sub(r"\d+$", "", t.path)] += t.idx.size+ print("hud bytes by family", fams.most_common(40), sum(fams.values()))+ groups = collections.defaultdict(bytearray)+ for tid in HUD_TEX:+ t = TEX.list[tid]+ groups["textbox" if "textbox" in t.path else "portraits"] += t.idx.tobytes()+ print("hud compressed", {k: len(lz(bytes(v))) for k, v in groups.items()})+ # the interface's textures, by family+ for tid in HUD_TEX:+ t = TEX.list[tid]+ if t.pack >= 0 or t.kind != 0:+ continue+ hw = W()+ tex_header(t, hw)+ body = packed_body(t)+ if len(cur) + len(hw) + len(body) > 2 * PACK_RAW and cur_ids: # loaded a family at a time+ flush()+ t.pack = len(packs)+ t.offset = len(cur)+ cur += hw.b + body+ cur_ids.append(tid)+ flush()+ # Madeline's and Badeline's cutscene poses, an animation or a few to a pack+ for frames in LAZY_ANIMS:+ if len(cur) > PACK_RAW // 3:+ flush()+ for tid in frames:+ t = TEX.list[tid]+ if t.pack >= 0:+ continue+ hw = W()+ tex_header(t, hw)+ t.pack = len(packs)+ t.offset = len(cur)+ cur += hw.b + packed_body(t)+ cur_ids.append(tid)+ flush()++ if os.environ.get("DIRECT_REPORT"): # bytes of direct textures by family, and those with more than 15 colors+ fam = collections.Counter()+ many = collections.Counter()+ for t in TEX.list:+ if t.kind == 1:+ f, b_ = rle_direct(t.idx)+ k = "/".join(t.path.split("/")[:2])+ fam[k] += len(b_) + 20+ if not f & 8:+ many[k] += len(b_) + 20+ print("DIRECT", fam.most_common(14))+ print("DIRECT >15 colors", many.most_common(14))+ # direct textures (the same picture twice is stored once; the same pixels in other colors, once too:+ # TF_SHARED, then where they are)+ direct = W()+ same = {}+ bodies = {}+ for t in TEX.list:+ if t.kind == 1:+ hw = W()+ tex_header(t, hw)+ key = (bytes(hw.b), t.pal, t.idx.tobytes())+ if key in same:+ t.offset = same[key]+ continue+ direct.align(2)+ t.offset = len(direct)+ same[key] = t.offset+ flags, colors, body = rle_direct_parts(t.idx)+ if (flags, body) in bodies and len(body) > 8:+ hw.b[14] |= 16+ direct.raw(hw.b)+ direct.raw(colors)+ direct.u32(bodies[(flags, body)])+ continue+ direct.raw(hw.b)+ direct.raw(colors)+ if colors and not flags & 4 and len(colors) & 1:+ direct.u8(0)+ bodies[(flags, body)] = len(direct)+ direct.raw(body)+ byfam = collections.Counter()+ for t in TEX.list:+ if t.kind == 1:+ byfam["/".join(t.path.split("/")[:2])] += len(rle(t.idx)) + 14+ print("direct by family", byfam.most_common())+ print("textures", len(TEX.list), "direct", sum(t.kind == 1 for t in TEX.list), "bytes", len(direct),+ "packs", len(packs), "raw", sum(len(p[0]) for p in packs))++ sec = {}+ blobs = W()++ # ---- TEX: u16 count, then u32 per texture: kind<<30 | pack<<18 | offset (packed) or offset (direct)+ w = W()+ w.u16(len(TEX.list))+ w.u16(0)+ for t in TEX.list:+ if t.kind == 1:+ w.u32(1 << 30 | t.offset)+ elif t.pack >= 0:+ assert t.offset < (1 << 18) and t.pack < (1 << 12)+ w.u32((t.kind & 3) << 30 | t.pack << 18 | t.offset)+ else:+ w.u32(0xFFFFFFFF)+ sec["TEX"] = w+ # ---- TEXDIM: u8 per texture, half the bigger side of its frame in 2 px (to cull before loading it), 255: more+ w = W()+ for t in TEX.list:+ w.u8(min(255, ((max(t.sub.fw, t.sub.fh) + 1) // 2 + 1) // 2))+ sec["TEXDIM"] = w++ # ---- PAL: u16 count, u32 offsets; each: u16 n (| 0x8000 if every color is opaque), u16 c565[n], u8 a[n]+ w = W()+ w.u16(len(PALS.list))+ w.u16(0)+ base = 4 + 4 * len(PALS.list)+ body = W()+ offs = []+ for p in PALS.list:+ body.align(2)+ offs.append(base + len(body))+ body.u16(len(p) | (0x8000 if all(a == 15 for c, a in p) else 0))+ for c, a in p:+ body.u16(c)+ for c, a in p:+ body.u8(a * 17)+ for o in offs:+ w.u32(o)+ w.raw(body.b)+ sec["PAL"] = w++ # ---- PACKS: u16 count; each: u32 blob offset, u32 compressed size, u32 raw size+ w = W()+ w.u16(len(packs))+ w.u16(0)+ comp_total = 0+ for raw, ids in packs:+ z = lz(raw)+ comp_total += len(z)+ w.u32(len(blobs))+ w.u32(len(z))+ w.u32(len(raw))+ blobs.raw(z)+ blobs.align(4)+ sec["PACKS"] = w+ print("texture packs compressed", comp_total)++ sec["DIRECT"] = direct++ # ---- BANKS+ w = W()+ names = list(BANKS)+ w.u16(len(names))+ w.u16(0)+ base = 4 + 4 * len(names)+ body = W()+ offs = []+ for n in names:+ b = BANKS[n]+ body.align(4)+ offs.append(base + len(body))+ body.u8(b.origin[0])+ body.u8(0)+ anames = list(b.anims)+ body.u16(len(anames))+ body.f32(b.origin[1])+ body.f32(b.origin[2])+ body.u16(anames.index(b.start) if b.start in anames else 0xFFFF)+ body.u16(0)+ aoffs_at = len(body)+ for _ in anames:+ body.u16(0)+ body.align(4)+ for i, an in enumerate(anames):+ a = b.anims[an]+ body.align(4)+ struct.pack_into("<H", body.b, aoffs_at + 2 * i, len(body) - aoffs_at + 2 * len(anames) * 0)+ body.f32(a["delay"])+ body.u8(1 if a["loop"] else 0)+ body.u8(len(a["goto"]))+ body.u16(len(a["frames"]))+ for g, wgt in a["goto"]:+ body.u16(anames.index(g) if g in anames else 0xFFFF)+ body.u16(wgt)+ for f in a["frames"]:+ body.u16(f)+ for o in offs:+ w.u32(o)+ w.raw(body.b)+ sec["BANKS"] = w++ # ---- PMETA: per Madeline texture: u16 tex, s8 hair x, s8 hair y, u8 frame | hashair<<7, s8 carry (sorted by tex)+ w = W()+ w.u16(len(pmeta))+ w.u16(0)+ for tid in sorted(pmeta):+ hx, hy, fr, has, carry = pmeta[tid]+ w.u16(tid)+ w.s8(hx)+ w.s8(hy)+ w.u8(fr | (0x80 if has else 0))+ w.s8(carry)+ sec["PMETA"] = w++ # ---- TILESETS: two 128-byte maps char -> terrain index, then terrains+ w = W()+ terrains = []+ maps = []+ for sets in (fgsets, bgsets):+ m = bytearray([255] * 128)+ for c, t in sets.items():+ if c == "z":+ continue+ m[ord(c)] = len(terrains)+ terrains.append(t)+ maps.append(m)+ w.raw(maps[0])+ w.raw(maps[1])+ w.u16(len(terrains))+ w.u16(0)+ base = len(w) + 4 * len(terrains)+ body = W()+ offs = []++ def tile_list(lst):+ for tx, ty in lst:+ body.u8(ty * 8 + tx)++ anim_names = ANIM_NAMES+ for t in terrains:+ body.align(2)+ offs.append(base + len(body))+ body.u16(TEX(t.path))+ ign = "".join(sorted(t.ignores))+ body.u8(len(ign))+ for c in ign:+ body.u8(ord(c))+ body.u8(len(t.masks))+ body.u8(len(t.padded))+ body.u8(len(t.center))+ for m_, tl, sprites in t.masks:+ bits = care = 0+ order = [0, 1, 2, 3, 5, 6, 7, 8]+ for k, i in enumerate(order):+ if m_[i] != 2:+ care |= 1 << (7 - k)+ if m_[i] == 1:+ bits |= 1 << (7 - k)+ body.u8(bits)+ body.u8(care)+ body.u8(len(tl))+ ov = 0+ if sprites:+ if sprites[0] not in anim_names:+ anim_names.append(sprites[0])+ ov = anim_names.index(sprites[0]) + 1+ body.u8(ov)+ tile_list(tl)+ tile_list(t.padded)+ tile_list(t.center)+ for o in offs:+ w.u32(o)+ w.raw(body.b)+ sec["TILESETS"] = w++ # ---- ANIMTILES: animated tile overlays (AnimatedTiles.xml)+ w = W()+ at = ET.parse(os.path.join(CELESTE, "Graphics", "AnimatedTiles.xml")).getroot()+ defs = {s.get("name"): s for s in at.iter("sprite")}+ w.u16(len(anim_names))+ w.u16(0)+ for n in anim_names:+ s = defs[n]+ fam = TEX.family(s.get("path"))+ w.f32(float(s.get("delay")))+ w.s8(int(s.get("posX")))+ w.s8(int(s.get("posY")))+ w.s8(int(s.get("origX")))+ w.s8(int(s.get("origY")))+ w.u16(len(fam))+ for f in fam:+ w.u16(f)+ sec["ANIMTILES"] = w++ # ---- CHAPTERS+ room_packs = []+ w = W()+ w.u16(len(chapters))+ w.u16(0)+ base = 4 + 4 * len(chapters)+ body = W()+ offs = []+ rp_cur = bytearray()+ rp_ids = []+ room_locs = {}+ for ci, ch in enumerate(chapters):+ for ri, r in enumerate(ch.rooms):+ blob = room_blob(ch, r)+ if len(rp_cur) + len(blob) > 32 * 1024 and rp_cur:+ room_packs.append(bytes(rp_cur))+ rp_cur = bytearray()+ room_locs[(ci, ri)] = (len(room_packs), len(rp_cur), len(blob))+ rp_cur += blob+ if rp_cur:+ room_packs.append(bytes(rp_cur))+ rp_cur = bytearray()+ pack_base = len(packs)+ rcomp = 0+ room_pack_index = []+ for raw in room_packs:+ z = lz(raw)+ rcomp += len(z)+ room_pack_index.append((len(blobs), len(z), len(raw)))+ blobs.raw(z)+ blobs.align(4)+ # append room packs to the PACKS table+ pw = sec["PACKS"]+ struct.pack_into("<H", pw.b, 0, len(packs) + len(room_packs))+ for o, c, n in room_pack_index:+ pw.u32(o)+ pw.u32(c)+ pw.u32(n)+ print("rooms raw", sum(len(p) for p in room_packs), "compressed", rcomp, dict(BLOB_PARTS))+ if os.environ.get("PARTS_REPORT"):+ print("parts compressed", {k: len(lz(v)) for k, v in BLOB_BYTES.items()})++ global ROOM_POOL+ ROOM_POOL = room_pool_size(chapters)+ # the whole game needs this much (7-Summit g-00b + g-01): RAM is counted for it even with fewer maps+ if ROOM_POOL[0] < ROOM_POOL_FULL:+ ROOM_POOL = (ROOM_POOL_FULL, "the whole game")+ print("room pool", ROOM_POOL)+ for ci, ch in enumerate(chapters):+ body.align(4)+ offs.append(base + len(body))+ ch_start = len(body)+ body.u16(STR(ch.name))+ body.u16(len(ch.rooms))+ x0, y0, tw, th = ch.tb+ body.s16(x0)+ body.s16(y0)+ body.u16(tw)+ body.u16(th)+ styles = ch.bgs + ch.fgs+ body.u8(len(ch.bgs))+ body.u8(len(ch.fgs))+ # AreaData: the area, its mode, the inventory, checkpoints and strawberries (SaveData keeps them by index)+ mode = 2 if ch.name[1:2] == "X" or ch.name[2:3] == "X" else 1 if ch.name[1:2] == "H" or ch.name[2:3] == "H" else 0+ body.u8(MAP_AREA[ch.name])+ body.u8(mode)+ cps = CHECKPOINTS.get(ch.name, [])+ rnames = [r.name for r in ch.rooms]+ berries = []+ for ri, r in enumerate(ch.rooms):+ for e in (r.e.child("entities").children if r.e.child("entities") else []):+ if e.name in ("strawberry", "goldenBerry", "memorialTextController"):+ golden = e.name != "strawberry"+ fl = (1 if golden else 0) | (2 if e.get("moon", False) else 0) | \+ (4 if e.get("winged", False) or e.name == "memorialTextController" else 0)+ berries.append((golden, int(e.get("checkpointID", 0)), int(e.get("order", 0)), ri,+ e.get("id", 0) & 0xFFFF, fl))+ berries.sort()+ assert len(berries) <= 64, ch.name+ body.u8(INVENTORIES.index(MODE_INVENTORY[ch.name]))+ body.u8(len(cps))+ body.u8(len(berries))+ body.u8(sum(1 for b in berries if not b[0])) # MapData.DetectedStrawberries+ extra_at = len(body)+ body.u16(0)+ body.u16(0)+ # the chapter files (src/chN.c) whose entities this map has: a bit each, N = 0..15+ files = 0+ for r in ch.rooms:+ for e in (r.e.child("entities").children if r.e.child("entities") else []) + \+ (r.e.child("triggers").children if r.e.child("triggers") else []):+ if e.name in E.OWNER:+ files |= 1 << E.OWNER[e.name]+ body.u16(files)+ body.u16(0)+ rooms_at = len(body)+ for r in ch.rooms:+ body.u32(0)+ sg_at = len(body)+ for _ in styles:+ body.u32(0)+ for i, (name, a) in enumerate(styles):+ body.align(4)+ struct.pack_into("<I", body.b, sg_at + 4 * i, len(body) - ch_start)+ body.u8(STYLE_EFFECTS.index(name) if name in STYLE_EFFECTS else 255)+ flags = 0+ for bit, k in enumerate(("loopx", "loopy", "flipx", "flipy", "instantIn", "instantOut", "fadeIn")):+ if a.get(k, k in ("loopx", "loopy")):+ flags |= 1 << bit+ if a.get("blendmode", "") == "additive":+ flags |= 1 << 7+ body.u8(flags)+ tid = ch.style_tex[i]+ body.u16(tid if tid is not None else 0xFFFF)+ body.f32(float(a.get("x", 0)))+ body.f32(float(a.get("y", 0)))+ body.f32(float(a.get("scrollx", 1)))+ body.f32(float(a.get("scrolly", 1)))+ body.f32(float(a.get("speedx", 0)))+ body.f32(float(a.get("speedy", 0)))+ body.f32(float(a.get("alpha", 1)))+ body.u32(int(str(a.get("color", "ffffff")), 16) if a.get("color") else 0xFFFFFF)+ body.u16(STR(a.get("flag", "")))+ body.u16(STR(a.get("notflag", "")))+ body.u16(STR(a.get("tag", "")))+ body.u16(STR(a.get("fadex", "")))+ body.u16(STR(a.get("fadey", "")))+ body.u16(STR(a.get("only", "")))+ for ri, r in enumerate(ch.rooms):+ body.align(4)+ struct.pack_into("<I", body.b, rooms_at + 4 * ri, len(body) - ch_start)+ pk, off, size = room_locs[(ci, ri)]+ body.u16(STR(r.name))+ body.u16(pack_base + pk)+ body.u32(off)+ body.u32(size)+ body.s32(r.x)+ body.s32(r.y)+ body.u16(r.w)+ body.u16(r.h)+ fl = 0+ for bit, k in enumerate(ROOM_ATTRS):+ if r.e.get(k):+ fl |= 1 << bit+ body.u8(fl)+ body.u8(WIND.index(r.e.get("windPattern", "None")) if r.e.get("windPattern", "None") in WIND else 0)+ body.s8(int(r.e.get("cameraOffsetX", 0) or 0))+ body.s8(int(r.e.get("cameraOffsetY", 0) or 0))+ body.u32(r.style_mask & 0xFFFFFFFF)+ body.u32(r.style_mask >> 32)+ body.u16(STR(r.e.get("music", "") or ""))+ body.u8(int(r.e.get("enforceDashNumber", 0) or 0))+ body.u8(0)+ body.align(2)+ struct.pack_into("<H", body.b, extra_at, len(body) - ch_start)+ for golden, cp, order, ri, eid, fl in berries:+ body.u16(ri)+ body.u16(eid)+ body.u8(cp)+ body.u8(fl)+ struct.pack_into("<H", body.b, extra_at + 2, len(body) - ch_start)+ for level, inv, flags in cps:+ body.u16(rnames.index(level))+ body.u8(INVENTORIES.index(inv) if inv else 255)+ body.u8(flags)+ for o in offs:+ w.u32(o)+ w.raw(body.b)+ sec["CHAPTERS"] = w+ sec["BLOBS"] = blobs+ w = W()+ w.u16(len(DECAL_ANIMS))+ for t in sorted(DECAL_ANIMS):+ w.u16(t)+ w.u16(DECAL_ANIMS[t])+ sec["DECALANIM"] = w+ # names of the textures entities look up at run time: FNV-1a hashes folded to 24 bits (from the first offset+ # basis that tells them all apart), sorted; then their ids+ paths = [(t.path, t.id) for t in TEX.list if not t.path.startswith("@")+ if not t.path.startswith(("decals/", "bgs/", "characters/player", "characters/badeline"))]+ for basis in range(2166136261, 2166136261 + 1000):+ named = sorted((fnv24(p_, basis), i) for p_, i in paths)+ if len(set(h for h, _ in named)) == len(named):+ break+ else:+ raise SystemExit("no 24-bit hash tells the texture names apart")+ w = W()+ w.u16(len(named))+ w.u16(0)+ w.u32(basis)+ for h_, i in named:+ w.raw(struct.pack("<I", h_)[:3])+ w.align(2)+ for h_, i in named:+ w.u16(i)+ sec["TEXNAMES"] = w++ # ---- FONTS and DIALOG (textdata.py)+ import textdata+ dialog = textdata.read_dialog()+ for k_ in list(dialog): # what nothing here shows: Farewell's (CH9_), its wavedash pages, the platforms', the journal+ if k_.startswith(("CH9_", "WAVEDASH", "POSTCARD", "ASSIST", "AUTOSAVING", "XB1", "BTN_", "JOURNAL", "STAT",+ "PICO8", "SAVEFAILED", "LOADFAILED")):+ del dialog[k_]+ codes = set(range(32, 127))+ for v in dialog.values():+ codes.update(ord(c) for c in v)+ sec["FONTS"] = textdata.font_section(W, codes)+ # dialog: entries in LZMA packs of about 12 KB; table of key hashes (sorted) and places+ for k_ in dialog:+ dialog[k_] = re.sub(r"\{portrait ([^}]*)\}", lambda m: portrait_command(m.group(1)), dialog[k_])+ items = sorted((textdata.fnv(k), k) for k in dialog)+ assert len(set(h for h, _ in items)) == len(items)+ dpacks = []+ cur = bytearray()+ places = []+ for h_, k in items:+ b = dialog[k].encode("utf-8")+ if len(cur) + len(b) > 12 * 1024 and cur:+ dpacks.append(bytes(cur))+ cur = bytearray()+ places.append((len(dpacks), len(cur), len(b)))+ cur += b+ if cur:+ dpacks.append(bytes(cur))+ pw = sec["PACKS"]+ first = struct.unpack_from("<H", pw.b, 0)[0]+ struct.pack_into("<H", pw.b, 0, first + len(dpacks))+ dz = 0+ for raw in dpacks:+ z = lz(raw)+ dz += len(z)+ pw.u32(len(blobs))+ pw.u32(len(z))+ pw.u32(len(raw))+ blobs.raw(z)+ blobs.align(4)+ w = W()+ w.u16(len(items))+ w.u16(0)+ for h_, k in items:+ w.u32(h_)+ for pk, off, n in places:+ w.u16(first + pk)+ w.u16(n)+ w.u32(off)+ sec["DIALOG"] = w+ # ---- UISTR: the menus' words, read straight from flash: u16 n, u16 0, u32 key hashes (sorted),+ # u16 offsets, then the texts (0-terminated)+ ui = sorted((textdata.fnv(k), k) for k in dialog if k.startswith(UI_PREFIXES))+ w = W()+ w.u16(len(ui))+ w.u16(0)+ for h_, k in ui:+ w.u32(h_)+ texts = bytearray()+ offs = []+ for h_, k in ui:+ offs.append(len(texts))+ texts += dialog[k].encode("utf-8") + b"\0"+ for o in offs:+ w.u16(o)+ w.raw(bytes(texts))+ sec["UISTR"] = w+ print("dialog", len(items), "entries, compressed", dz, "fonts", len(sec["FONTS"]))++ # ---- STRINGS: u16 count, u16 offsets (from section start, 32-bit), NUL-terminated+ w = W()+ data = bytearray()+ offs = []+ for s_ in STR.list:+ offs.append(len(data))+ data += s_.encode("utf-8") + b"\0"+ w.u32(len(STR.list))+ base = 4 + 4 * len(STR.list)+ for o in offs:+ w.u32(base + o)+ w.raw(data)+ sec["STRINGS"] = w++ # ---- write+ out = W()+ out.raw(b"CLST")+ hdr = len(out)+ for _ in SECTIONS:+ out.u32(0)+ for i, name in enumerate(SECTIONS):+ out.align(4)+ struct.pack_into("<I", out.b, hdr + 4 * i, len(out))+ out.raw(sec[name].b)+ print("%-10s %8d" % (name, len(sec[name])))+ out.align(4)+ open(OUT_BIN, "wb").write(out.b)+ print("data.bin", len(out))+ write_header(names)+++def cname(s):+ return "".join(c if c.isalnum() else "_" for c in s)+++def write_header(bank_names):+ L = ["/* Generated by tools/pack.py: ids into data.bin. */", "#ifndef DATA_H", "#define DATA_H", ""]+ for i, s in enumerate(SECTIONS):+ L.append("#define SEC_%s %d" % (s, i))+ L.append("")+ for i, b in enumerate(bank_names):+ L.append("#define SB_%s %d" % (cname(b), i))+ for j, an in enumerate(BANKS[b].anims):+ L.append("#define A_%s_%s %d" % (cname(b), cname(an), j))+ L.append("")+ for n, i in ENT_IDS.items():+ L.append("#define ET_%s %d" % (cname(n), i))+ L.append("#define ET_COUNT %d" % len(ENT_IDS))+ for n, i in TRIG_IDS.items():+ L.append("#define TT_%s %d" % (cname(n), i))+ L.append("#define TT_COUNT %d" % len(TRIG_IDS))+ L.append("")+ for name in list(ENT_IDS) + list(TRIG_IDS):+ lay, size = SCHEMA.layout(name)+ for k, kind, off, sz in lay:+ L.append("#define EA_%s_%s %d" % (cname(name), cname(k), off))+ L.append("#define EK_%s_%s '%s'" % (cname(name), cname(k), kind))+ L.append("#define EA_%s__size %d" % (cname(name), size))+ L.append("static const uint8_t ENT_ATTR_SIZE[] = {" + ",".join(str(SCHEMA.layout(n)[1]) for n in ENT_IDS) + "};")+ L.append("static const uint8_t TRIG_ATTR_SIZE[] = {" + ",".join(str(SCHEMA.layout(n)[1]) for n in TRIG_IDS) + "};")+ L.append("")+ for t in TEX.list:+ L.append("#define T_%s %d" % (cname(t.path), t.id))+ L.append("#define TEX_COUNT %d" % len(TEX.list))+ L.append("#define ROOM_POOL_BYTES %d /* %s */" % ((ROOM_POOL[0] + 64 + 3) & ~3, ROOM_POOL[1]))+ for i, s in enumerate(STYLE_EFFECTS):+ L.append("#define SG_%s %d" % (s, i))+ L.append("")+ L.append("#endif")+ open(OUT_H, "w").write("\n".join(L) + "\n")+++if __name__ == "__main__":+ main()diff --git a/games/celeste/tools/ptype_textures.txt b/games/celeste/tools/ptype_textures.txtnew file mode 100644index 00000000..fa980ae1--- /dev/null+++ b/games/celeste/tools/ptype_textures.txt@@ -0,0 +1,17 @@+particles/blob+particles/bubble+particles/cloud+particles/feather+particles/fire+particles/rect+particles/shard+particles/shatter+particles/smoke0+particles/smoke1+particles/smoke2+particles/smoke3+particles/triangle+particles/zappysmoke00+particles/zappysmoke01+particles/zappysmoke02+particles/zappysmoke03diff --git a/games/celeste/tools/textdata.py b/games/celeste/tools/textdata.pynew file mode 100644index 00000000..7370d12e--- /dev/null+++ b/games/celeste/tools/textdata.py@@ -0,0 +1,161 @@+"""Celeste's fonts (Renogare, at the sizes the engine draws: the game's 1920x1080+interface shown at 1/6) and its English dialog, for pack.py."""+import os+import re+import struct++import numpy as np+from PIL import Image++from cel import CELESTE, Atlas++# (face file, scale): body text (64 / 6 = 10.7 px), and the 192 face at 2x and 3x the body+FONT_SIZES = [("renogare64", 1 / 6), ("renogare192", 1 / 9)]+++def read_fnt(name):+ t = open(os.path.join(CELESTE, "Dialog", "Fonts", name + ".fnt")).read()+ chars = {}+ for m in re.finditer(r'<char id="(\d+)" x="(\d+)" y="(\d+)" width="(\d+)" height="(\d+)" xoffset="(-?\d+)" '+ r'yoffset="(-?\d+)" xadvance="(-?\d+)"', t):+ chars[int(m.group(1))] = tuple(int(v) for v in m.groups()[1:])+ kern = {}+ for m in re.finditer(r'<kerning first="(\d+)" second="(\d+)" amount="(-?\d+)"', t):+ kern[(int(m.group(1)), int(m.group(2)))] = int(m.group(3))+ common = re.search(r'lineHeight="(\d+)" base="(\d+)"', t)+ return chars, kern, int(common.group(1)), int(common.group(2))+++def font_section(W, codes):+ """FONTS: u16 count, u32 offsets; per size: u16 nglyphs, u16 line height x16, u16 base x16, u16 nkern,+ glyphs (u16 code, s16 xo x16, s16 yo, u8 w, u8 h, u16 advance x16, u32 bitmap offset), kerning (u16 a, u16 b, s16 x16),+ then 4-bit alpha bitmaps (rows padded to bytes)."""+ gui = Atlas("Gui")+ out = []+ for face, scale in FONT_SIZES:+ chars, kern, line_h, base = read_fnt(face)+ page = gui[face + "_0"].image()[..., 3]+ glyphs = []+ bitmaps = bytearray()+ for code in sorted(codes):+ if code not in chars:+ continue+ x, y, w, h, xo, yo, xa = chars[code]+ if w and h:+ g = page[y:y + h, x:x + w].astype(np.float32)+ # place at the scaled offset's fraction, then area-scale+ fx, fy = xo * scale - np.floor(xo * scale), yo * scale - np.floor(yo * scale)+ ow, oh = int(np.ceil(w * scale + fx)) + 1, int(np.ceil(h * scale + fy)) + 1+ big = np.zeros((int(round(oh / scale)) + 2, int(round(ow / scale)) + 2), np.float32)+ ox, oy = int(round(fx / scale)), int(round(fy / scale))+ big[oy:oy + h, ox:ox + w] = g+ im = Image.fromarray(big).resize((ow, oh), Image.BOX)+ a = np.array(im)+ # trim+ rows = np.where(a.max(axis=1) > 8)[0]+ cols = np.where(a.max(axis=0) > 8)[0]+ if len(rows) and len(cols):+ a = a[rows[0]:rows[-1] + 1, cols[0]:cols[-1] + 1]+ gx, gy = int(np.floor(xo * scale)) + cols[0], int(np.floor(yo * scale)) + rows[0]+ else:+ a = np.zeros((0, 0))+ gx = gy = 0+ else:+ a = np.zeros((0, 0))+ gx = gy = 0+ q = np.clip(np.round(a / 255 * 15), 0, 15).astype(np.uint8)+ off = len(bitmaps)+ for row in q:+ r = list(row) + ([0] if len(row) % 2 else [])+ bitmaps += bytes(r[i] | r[i + 1] << 4 for i in range(0, len(r), 2))+ glyphs.append((code, gx, gy, q.shape[1] if q.size else 0, q.shape[0] if q.size else 0,+ int(round(xa * scale * 16)), off))+ kerns = [(a, b, int(round(v * scale * 16))) for (a, b), v in kern.items() if a in codes and b in codes]+ w = W()+ w.u16(len(glyphs))+ w.u16(int(round(line_h * scale * 16)))+ w.u16(int(round(base * scale * 16)))+ w.u16(len(kerns))+ head = 8 + 14 * len(glyphs) + 6 * len(kerns)+ for code, gx, gy, gw, gh, adv, off in glyphs:+ w.u16(code)+ w.s16(gx * 16)+ w.s16(gy)+ w.u8(gw)+ w.u8(gh)+ w.u16(adv)+ w.u32(head + off)+ for a, b, v in kerns:+ w.u16(a)+ w.u16(b)+ w.s16(v)+ w.raw(bitmaps)+ out.append(w)+ sec = W()+ sec.u16(len(out))+ sec.u16(0)+ base = 4 + 4 * len(out)+ body = W()+ offs = []+ for w in out:+ body.align(4)+ offs.append(base + len(body))+ body.raw(w.b)+ for o in offs:+ sec.u32(o)+ sec.raw(body.b)+ return sec+++def read_dialog():+ """Language.FromTxt for English.txt: {key: text}, inserts resolved, portraits as {portrait ...}."""+ command = re.compile(r"\{(.*?)\}")+ insert = re.compile(r"\{\+\s*(.*?)\}")+ variable = re.compile(r"^\w+\=.*")+ portrait = re.compile(r"\[(?P<content>[^\[\\]*(?:\\.[^\]\\]*)*)\]")+ dialog = {}+ key = ""+ buf = ""+ prev = ""+ for line in open(os.path.join(CELESTE, "Dialog", "English.txt"), encoding="utf-8-sig"):+ t = line.strip()+ if not t or t[0] == "#":+ continue+ if "[" in t:+ t = portrait.sub(lambda m: "{portrait " + m.group("content") + "}", t)+ t = t.replace("\\#", "#")+ if not t:+ continue+ if variable.match(t):+ if key:+ dialog[key] = buf+ k, _, v = t.partition("=")+ k, v = k.strip(), v.strip()+ if k.lower() in ("language", "icon", "order", "font", "split_regex", "commas", "periods"):+ continue+ key = k.upper()+ buf = v+ else:+ if buf and not buf.endswith("{break}") and not buf.endswith("{n}") and command.sub("", prev):+ buf += "{break}"+ buf += t+ prev = t+ if key:+ dialog[key] = buf+ for k in list(dialog):+ v = dialog[k]+ while True:+ ms = list(insert.finditer(v))+ if not ms:+ break+ for m in ms:+ v = v.replace(m.group(0), dialog.get(m.group(1).upper(), "[XXX]"))+ dialog[k] = v+ return dialog+++def fnv(s):+ h = 2166136261+ for c in s.encode():+ h = ((h ^ c) * 16777619) & 0xFFFFFFFF+ return hdiff --git a/games/celeste/tools/tiles.py b/games/celeste/tools/tiles.pynew file mode 100644index 00000000..4f0233bf--- /dev/null+++ b/games/celeste/tools/tiles.py@@ -0,0 +1,316 @@+"""Celeste's autotiler rules (ForegroundTiles.xml, BackgroundTiles.xml), read+the way the game reads them, and a reference autotiler for tests.++The game sorts each tileset's masks with List<T>.Sort, an unstable introsort,+so the same sort is done here to get the same order."""+import os+import xml.etree.ElementTree as ET+from cel import CELESTE+++def _floor_log2(n):+ r = 0+ while n >= 1:+ r += 1+ n //= 2+ return r+++def net_sort(items, cmp, capacity=None):+ """.NET Framework 4.5's Array.Sort<T> (IntrospectiveSort) on a list, in place."""+ a = items+ n = len(a)+ if n < 2:+ return++ def swap_if_greater(i, j):+ if i != j and cmp(a[i], a[j]) > 0:+ a[i], a[j] = a[j], a[i]++ def insertion(lo, hi):+ for i in range(lo, hi):+ j = i+ t = a[i + 1]+ while j >= lo and cmp(t, a[j]) < 0:+ a[j + 1] = a[j]+ j -= 1+ a[j + 1] = t++ def down_heap(i, n_, lo):+ d = a[lo + i - 1]+ while i <= n_ // 2:+ child = 2 * i+ if child < n_ and cmp(a[lo + child - 1], a[lo + child]) < 0:+ child += 1+ if not cmp(d, a[lo + child - 1]) < 0:+ break+ a[lo + i - 1] = a[lo + child - 1]+ i = child+ a[lo + i - 1] = d++ def heapsort(lo, hi):+ n_ = hi - lo + 1+ for i in range(n_ // 2, 0, -1):+ down_heap(i, n_, lo)+ for i in range(n_, 1, -1):+ a[lo], a[lo + i - 1] = a[lo + i - 1], a[lo]+ down_heap(1, i - 1, lo)++ def partition(lo, hi):+ mid = lo + ((hi - lo) >> 1)+ swap_if_greater(lo, mid)+ swap_if_greater(lo, hi)+ swap_if_greater(mid, hi)+ pivot = a[mid]+ a[mid], a[hi - 1] = a[hi - 1], a[mid]+ left, right = lo, hi - 1+ while left < right:+ left += 1+ while cmp(a[left], pivot) < 0:+ left += 1+ right -= 1+ while cmp(pivot, a[right]) < 0:+ right -= 1+ if left >= right:+ break+ a[left], a[right] = a[right], a[left]+ a[left], a[hi - 1] = a[hi - 1], a[left]+ return left++ def intro(lo, hi, depth):+ while hi > lo:+ size = hi - lo + 1+ if size <= 16:+ if size == 1:+ return+ if size == 2:+ swap_if_greater(lo, hi)+ return+ if size == 3:+ swap_if_greater(lo, hi - 1)+ swap_if_greater(lo, hi)+ swap_if_greater(hi - 1, hi)+ return+ insertion(lo, hi)+ return+ if depth == 0:+ heapsort(lo, hi)+ return+ depth -= 1+ p = partition(lo, hi)+ intro(p + 1, hi, depth)+ hi = p - 1++ intro(0, n - 1, 2 * _floor_log2(capacity or n))+++def list_capacity(n):+ """Capacity of a List<T> after n Adds (0, then 4, 8, 16...)."""+ c = 0+ while c < n:+ c = c * 2 if c else 4+ return c+++class Terrain:+ def __init__(self, ident, path):+ self.id = ident+ self.path = path+ self.masks = [] # (mask[9] of 0/1/2, tiles[(x,y)], sprites[])+ self.padded = []+ self.center = []+ self.ignores = set()++ def ignore(self, c):+ if self.id != c:+ if c not in self.ignores:+ return '*' in self.ignores+ return True+ return False+++def _read_into(t, element):+ for s in element:+ if s.tag != "set":+ continue+ mask = s.get("mask")+ tiles = [tuple(int(v) for v in p.split(",")) for p in s.get("tiles").split(";")]+ if mask == "center":+ t.center += tiles+ elif mask == "padding":+ t.padded += tiles+ else:+ m = [0 if c == "0" else 1 if c == "1" else 2 for c in mask if c in "01xX"]+ sprites = s.get("sprites").split(",") if s.get("sprites") else []+ t.masks.append((m, tiles, sprites))+ cap = list_capacity(len(t.masks))+ net_sort(t.masks, lambda a, b: a[0].count(2) - b[0].count(2), cap)+++def read_tilesets(name):+ """{id char: Terrain} for ForegroundTiles or BackgroundTiles, in file order."""+ root = ET.parse(os.path.join(CELESTE, "Graphics", name + ".xml")).getroot()+ elements = {}+ out = {}+ for e in root.iter("Tileset"):+ c = e.get("id")+ t = Terrain(c, "tilesets/" + e.get("path"))+ _read_into(t, e)+ if e.get("copy"):+ _read_into(t, elements[e.get("copy")])+ if e.get("ignores"):+ for i in e.get("ignores").split(","):+ if i:+ t.ignores.add(i[0])+ elements[c] = e+ out[c] = t+ return out+++def is_empty(c):+ return c == "0" or c == "\0"+++class Behaviour:+ def __init__(self, edges_extend=True, edges_ignore_out=False, padding_ignore_out=False):+ self.edges_extend = edges_extend+ self.edges_ignore_out = edges_ignore_out+ self.padding_ignore_out = padding_ignore_out+++FG_BEHAVIOUR = Behaviour(True, False, True)+BG_BEHAVIOUR = Behaviour(True, False, True)+++# ---------------------------------------------------------------- the game's own generation++class NetRandom:+ """.NET Framework System.Random."""+ MBIG = 2147483647++ def __init__(self, seed):+ sub = 2147483647 if seed == -2147483648 else abs(seed)+ mj = 161803398 - sub+ sa = [0] * 56+ sa[55] = mj+ mk = 1+ for i in range(1, 55):+ ii = (21 * i) % 55+ sa[ii] = mk+ mk = mj - mk+ if mk < 0:+ mk += self.MBIG+ mj = sa[ii]+ for _ in range(1, 5):+ for i in range(1, 56):+ sa[i] -= sa[1 + (i + 30) % 55]+ if sa[i] < 0:+ sa[i] += self.MBIG+ self.sa = sa+ self.inext = 0+ self.inextp = 21++ def sample_int(self):+ a = self.inext + 1+ if a >= 56:+ a = 1+ b = self.inextp + 1+ if b >= 56:+ b = 1+ v = self.sa[a] - self.sa[b]+ if v == self.MBIG:+ v -= 1+ if v < 0:+ v += self.MBIG+ self.sa[a] = v+ self.inext, self.inextp = a, b+ return v++ def next(self, n):+ return int(self.sample_int() * (1.0 / self.MBIG) * n)+++class VMap:+ """Monocle's VirtualMap: 50x50 segments, allocated by any write."""++ def __init__(self, w, h, empty):+ self.w, self.h, self.empty = w, h, empty+ self.data = [[empty] * w for _ in range(h)]+ self.seg = set()++ def __getitem__(self, xy):+ x, y = xy+ if 0 <= x < self.w and 0 <= y < self.h:+ return self.data[y][x]+ return self.empty++ def __setitem__(self, xy, v):+ x, y = xy+ if 0 <= x < self.w and 0 <= y < self.h:+ self.seg.add((x // 50, y // 50))+ self.data[y][x] = v+++def generate(sets, vmap, behaviour, level_bounds, rnd, anim_frames):+ """Autotiler.Generate over the whole map: {(x, y): (tile (tx, ty), overlay name or None, frame)}."""+ out = {}++ def check_tile(t, x, y):+ if x < 0 or y < 0 or x >= vmap.w or y >= vmap.h:+ if not behaviour.edges_extend:+ return False+ c = vmap[min(max(x, 0), vmap.w - 1), min(max(y, 0), vmap.h - 1)]+ else:+ c = vmap.data[y][x]+ return not is_empty(c) and not t.ignore(c)++ def same_level(x1, y1, x2, y2):+ for (lx, ly, lw, lh) in level_bounds:+ if lx <= x1 < lx + lw and ly <= y1 < ly + lh and lx <= x2 < lx + lw and ly <= y2 < ly + lh:+ return True+ return False++ def handler(x, y):+ c = vmap.data[y][x]+ if is_empty(c):+ return None+ t = sets[c]+ adj = []+ full = True+ for i in (-1, 0, 1):+ for j in (-1, 0, 1):+ f = check_tile(t, x + j, y + i)+ if not f and behaviour.edges_ignore_out and not same_level(x, y, x + j, y + i):+ f = True+ adj.append(1 if f else 0)+ if not f:+ full = False+ if full:+ if behaviour.padding_ignore_out:+ pad = any(not check_tile(t, x + dx, y + dy) and same_level(x, y, x + dx, y + dy)+ for dx, dy in ((-2, 0), (2, 0), (0, -2), (0, 2)))+ else:+ pad = any(not check_tile(t, x + dx, y + dy) for dx, dy in ((-2, 0), (2, 0), (0, -2), (0, 2)))+ return (t.padded, []) if pad else (t.center, [])+ for m, tl, sprites in t.masks:+ if all(m[k] == 2 or m[k] == adj[k] for k in range(9)):+ return (tl, sprites)+ return None++ for i in range(0, vmap.w, 50):+ for j in range(0, vmap.h, 50):+ if (i // 50, j // 50) not in vmap.seg:+ continue+ for k in range(i, min(i + 50, vmap.w)):+ for l in range(j, min(j + 50, vmap.h)):+ r = handler(k, l)+ if r is None:+ continue+ tiles, sprites = r+ tile = tiles[rnd.next(len(tiles))] if tiles else None+ ov = None+ if sprites:+ ov = sprites[rnd.next(len(sprites))]+ ov = (ov, rnd.next(anim_frames[ov]))+ out[(k, l)] = (tile, ov, len(tiles))+ return outdiff --git a/tests/test_games.py b/tests/test_games.pyindex bc9e6b8b..59b3c8de 100644--- a/tests/test_games.py+++ b/tests/test_games.py@@ -107,6 +107,10 @@ GAMES = {presses((3000, "ok"), (3600, "ok"), (4200, "ok"), (4800, "down"), (5100, "down"), (5400, "down"),(5700, "down"), (6000, "down"), (6300, "ok"), (8700, "comma", 1500)), 12200,presses((3000, "ok"), (3600, "ok")), 8000),+ # past the key sheet, the title, Climb, the chapter select and Start: the Prologue, walking; then Continue+ "celeste": ("Celeste.nwa", "celeste.sav",+ presses((2500, "ok"), (4000, "ok"), (5500, "ok"), (7000, "ok"), (8500, "ok"), (11000, "right", 2500)), 15000,+ presses((2500, "ok"), (4000, "ok"), (5500, "ok"), (7500, "right", 1500)), 11000),# a level, its message, then play; then back to the level select"portal": ("PortalReturns.nwa", "portal.sav",presses((1500, "ok"), (2500, "ok"), (3500, "ok")) + every(4000, 7000, 400, "right", 300), 8000,@@ -133,11 +137,14 @@ SEEDS = {# games that keep a copy of their save in a Python script (the only files the# NumWorks installer keeps): before the second session, as after installing# the app again, only the scripts are left, and the save must come back-COPIES = {"championisland": "champion_saves.py", "numblocks": "numblocks_saves.py"}+COPIES = {"championisland": "champion_saves.py", "numblocks": "numblocks_saves.py", "celeste": "celeste_saves.py"}CHECKS = {# the island remembers where Lucky was; after the reinstall, from the copy"championisland": (lambda v: v[:3] == b"CI1" and b"PLAYER_LOC" in v,) * 2,"numdrive": (lambda v: v[27] == 1, lambda v: v[27] == 0), # last played level+ # a session saved (has_session at 1072, the play time at 1096); after the reinstall, from the copy, it goes on+ "celeste": (lambda v: v[:4] == b"SLEC" and v[1072] == 1 and struct.unpack_from("<I", v, 1096)[0] > 0,+ lambda v: v[:4] == b"SLEC" and v[1072] == 1 and struct.unpack_from("<I", v, 1096)[0] > 60),"chess": (lambda v: v == SEEDS["chess"],) * 2, # read back and kept"numvisuals": (lambda v: v[:2] == b"V\1" and v[3] == 4 and struct.unpack_from("<i", v, 8)[0] == 2,lambda v: struct.unpack_from("<i", v, 8)[0] == 3), # the add-on and its countdiff --git a/tools/release.py b/tools/release.pyindex ffa2d539..0b10d72e 100644--- a/tools/release.py+++ b/tools/release.py@@ -21,10 +21,13 @@ ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")REPO = "https://github.com/Mason363/NumPlay"# in games.json, but not gamesEXTRAS = {"numvisuals"}-# games too big to fit next to NumPlay on the calculator: only on their own+# games too big to fit next to NumPlay on the calculator: only on their own (after: listed after that game, else+# in a section of their own)ALONE = {+ "celeste": ("Celeste", "the whole climb up Celeste Mountain. Too big to share the calculator with NumPlay: install it "+ "on its own", "numblocks"),"championisland": ("Champion Island", "the Doodle Champion Island Games. Too big to share the calculator with "- "NumPlay: install it on its own"),+ "NumPlay: install it on its own", None),}VARIANTS = [("NumPlay-Invisible.nwa", "The same app, hidden: a blank icon with no name"),@@ -65,6 +68,12 @@ def main():files.append((os.path.join(a.build, name), f"{name} · {what}"))notes.append(f"| {link(name)} | {what} |")notes += ["", "### Each one on its own", "", "In the launcher's order.", "", "| File | |", "| --- | --- |"]+ def alone_entry(gid):+ title, what, _ = ALONE[gid]+ name, what = apps[gid], f"{title}: {what}"+ files.append((os.path.join(a.build, "apps", name), f"{name} · {what}"))+ notes.append(f"| {link(name)} | {what} |")+for g in games:name = g.get("app") or apps.get(g["id"])if not name:@@ -73,14 +82,14 @@ def main():what = f"Only {g['title']}: {tagline}"files.append((os.path.join(a.build, "apps", name), f"{name} · {what}"))notes.append(f"| {link(name)} | {what} |")- alone = [(gid, apps[gid]) for gid in ALONE if gid in apps]+ for gid in ALONE:+ if ALONE[gid][2] == g["id"] and gid in apps:+ alone_entry(gid)+ alone = [gid for gid in ALONE if gid in apps and not ALONE[gid][2]]if alone:notes += ["", "### Too big for NumPlay", "", "| File | |", "| --- | --- |"]- for gid, name in alone:- title, what = ALONE[gid]- what = f"{title}: {what}"- files.append((os.path.join(a.build, "apps", name), f"{name} · {what}"))- notes.append(f"| {link(name)} | {what} |")+ for gid in alone:+ alone_entry(gid)notes += ["", "<sub>The file list below is sorted A to Z by GitHub. Each file's label says what it is.</sub>"]intro = open(os.path.join(ROOT, ".github", "release.md")).read().rstrip()