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
Level Devil: sixteen levels of troll rooms
Mason3630f88f4299cbf
diff --git a/games/games.json b/games/games.jsonindex eb9f6c92..0e593687 100644--- a/games/games.json+++ b/games/games.json@@ -344,6 +344,24 @@"app": "BlockBreaker.nwa","repo": "https://github.com/Mason363/NumPlay/tree/main/games/breakout"},+ {+ "id": "leveldevil",+ "title": "Level Devil",+ "tagline": "Reach the door, trust nothing",+ "credit": "Based on Level Devil by Unept",+ "top": "0xF49F7E",+ "bottom": "0x634D40",+ "accent": "0xD9512C",+ "colors": 16,+ "records": [+ "leveldevil.sav"+ ],+ "shots": [+ "docs/shot.png"+ ],+ "app": "LevelDevil.nwa",+ "repo": "https://github.com/Mason363/NumPlay/tree/main/games/leveldevil"+ },{"id": "numvisuals","title": "NumVisuals",diff --git a/games/leveldevil/.gitignore b/games/leveldevil/.gitignorenew file mode 100644index 00000000..342d9dda--- /dev/null+++ b/games/leveldevil/.gitignore@@ -0,0 +1,2 @@+output/+build/diff --git a/games/leveldevil/Makefile b/games/leveldevil/Makefilenew file mode 100644index 00000000..83025cc8--- /dev/null+++ b/games/leveldevil/Makefile@@ -0,0 +1,92 @@+# Level Devil — run to the door; the level has other plans.+# make build output/leveldevil.nwa+# make check link the app like the calculator does (output/leveldevil.bin)+# make test every room played through on a computer with its solution (tests/play.c,+# tests/solutions.txt)+#+# The rooms are written in tools/rooms.py, which packs them into output/rooms.inc (Python 3).+# In NumPlay the game draws with the launcher's strips, shapes and fonts, saves through its file+# functions and unpacks its rooms with its inflater (module.o leaves them to the launcher); on its+# own it brings them along.+Q ?= @+CC = arm-none-eabi-gcc+NWLINK ?= npx --yes -- [email protected]+BUILD_DIR = output+SRC = src/main.c+ROOMS = $(BUILD_DIR)/rooms.inc+HEADERS = ../common/epsilon_app.h ../common/epsilon_files.h ../common/np_text.h ../../launcher/src/gfx.h \+ ../../launcher/src/np.h ../../launcher/src/font.h ../../launcher/src/inflate.h++CFLAGS = -std=c11 $(shell $(NWLINK) eadk-cflags-device) -I$(BUILD_DIR)+CFLAGS += -Os -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+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 test+build: $(BUILD_DIR)/leveldevil.nwa++check: $(BUILD_DIR)/leveldevil.nwa+ $(Q) $(NWLINK) nwa-bin $< $(BUILD_DIR)/leveldevil.bin+ @echo "BIN $(BUILD_DIR)/leveldevil.bin: $$(wc -c < $(BUILD_DIR)/leveldevil.bin) bytes"++$(ROOMS): tools/rooms.py | $(BUILD_DIR)+ $(Q) python3 tools/rooms.py $(BUILD_DIR)++# compiled, then linked (the link options would upset the compiler)+$(BUILD_DIR)/main.o: $(SRC) $(ROOMS) $(HEADERS) | $(BUILD_DIR)+ @echo "CC $<"+ $(Q) $(CC) $(CFLAGS) -c $(SRC) -o $@+$(BUILD_DIR)/gfx.o: ../../launcher/src/gfx.c $(HEADERS) | $(BUILD_DIR)+ $(Q) $(CC) $(CFLAGS) -c $< -o $@+$(BUILD_DIR)/font_data.o: ../../launcher/src/font_data.c ../../launcher/src/font.h | $(BUILD_DIR)+ $(Q) $(CC) $(CFLAGS) -c $< -o $@+$(BUILD_DIR)/xfont.o: ../../launcher/src/xfont.c ../../launcher/src/np_xfont.h $(HEADERS) | $(BUILD_DIR)+ $(Q) $(CC) $(CFLAGS) -c $< -o $@+$(BUILD_DIR)/inflate.o: ../../launcher/src/inflate.c ../../launcher/src/inflate.h | $(BUILD_DIR)+ $(Q) $(CC) $(CFLAGS) -c $< -o $@++$(BUILD_DIR)/leveldevil.nwa: $(BUILD_DIR)/main.o $(BUILD_DIR)/gfx.o $(BUILD_DIR)/font_data.o $(BUILD_DIR)/xfont.o \+ $(BUILD_DIR)/inflate.o $(BUILD_DIR)/icon.o+ @echo "LD $@"+ $(Q) $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@+ $(Q) arm-none-eabi-strip --strip-unneeded $@++$(BUILD_DIR)/icon.o: src/icon.png | $(BUILD_DIR)+ @echo "ICON $<"+ $(Q) $(NWLINK) png-icon-o $< $@++$(BUILD_DIR):+ $(Q) mkdir -p $@++clean:+ $(Q) rm -rf $(BUILD_DIR) build++# on a computer, with the sanitizers: the rooms played through, and pictures of them+HOST_FLAGS = -std=gnu11 -O1 -g -Wall -Wextra -Wno-unused-parameter -DPLATFORM_DEVICE=1 -DHOST -I$(BUILD_DIR) \+ $(shell $(NWLINK) eadk-cflags-simulator) -fsanitize=address,undefined -fno-sanitize-recover=undefined+host: build/play+build/play: $(SRC) $(ROOMS) tests/play.c $(HEADERS)+ $(Q) mkdir -p build+ $(Q) cc $(HOST_FLAGS) tests/play.c ../../launcher/src/gfx.c ../../launcher/src/font_data.c \+ ../../launcher/src/xfont.c ../../launcher/src/inflate.c -lm -o $@+ @echo "HOST $@"+test: build/play+ build/play solve++# NumPlay launcher: the app as a module (see ../../tools/npmodule.py) for the+# calculator, and as a relocatable object for the simulator build.+.PHONY: module sim-module+module: $(BUILD_DIR)/module.o+$(BUILD_DIR)/module-main.o: $(SRC) $(ROOMS) $(HEADERS) | $(BUILD_DIR)+ $(Q) $(CC) $(CFLAGS) -DNP_MODULE=1 -c $(SRC) -o $@+$(BUILD_DIR)/module.o: $(BUILD_DIR)/module-main.o+ $(Q) $(CC) $(CFLAGS) -Wl,--relocatable -nostartfiles -nostdlib -Wl,-e,main -flinker-output=nolto-rel $< -o $@++sim-module: $(BUILD_DIR)/sim-module.o+$(BUILD_DIR)/sim-module.o: $(SRC) $(ROOMS) $(HEADERS) | $(BUILD_DIR)+ $(Q) mkdir -p $(BUILD_DIR)/sim+ $(Q) cc -std=c11 -O2 -fPIC $(shell $(NWLINK) eadk-cflags-simulator) -I$(BUILD_DIR) -DNP_MODULE=1 \+ -Dmain=np_leveldevil_main -c $(SRC) -o $(BUILD_DIR)/sim/main.o+ $(Q) ld -r $(BUILD_DIR)/sim/main.o -exported_symbol _np_leveldevil_main -o $@diff --git a/games/leveldevil/lang/fr.txt b/games/leveldevil/lang/fr.txtnew file mode 100644index 00000000..96ed8270--- /dev/null+++ b/games/leveldevil/lang/fr.txt@@ -0,0 +1,28 @@+# Level Devil in French: the English text as in the source, a tab, the translation (see tools/lang.py).+Resume Reprendre+Restart Recommencer+Levels Niveaux+How to play Comment jouer+Quit game Quitter le jeu+Quit game? Quitter le jeu ?+No Non+Yes Oui+Paused Pause+Play Jouer+OK OK+Left Right Gauche Droite+run courir+Up, OK, EXE Haut, OK, EXE+jump (hold: higher) sauter (maintenir : plus haut)+Back Retour+pause pause+Reach the door. The level has other plans: trust nothing. Atteins la porte. Le niveau a d'autres projets : ne te fie à rien.+You beat the Devil! Tu as vaincu le Diable !+Every door of Level Devil is open behind you. Toutes les portes de Level Devil sont ouvertes derrière toi.+Deaths in all: Morts en tout :+Level Niveau+Level cleared! Deaths: Niveau réussi ! Morts :+Locked Verrouillé+Cleared. Fewest deaths: Réussi. Le moins de morts :+Not cleared yet Pas encore réussi+Deaths Mortsdiff --git a/games/leveldevil/lang/zh.txt b/games/leveldevil/lang/zh.txtnew file mode 100644index 00000000..39cc3c25--- /dev/null+++ b/games/leveldevil/lang/zh.txt@@ -0,0 +1,28 @@+# Level Devil in Chinese: the English text as in the source, a tab, the translation (see tools/lang.py).+Resume 继续+Restart 重来+Levels 关卡+How to play 玩法+Quit game 退出游戏+Quit game? 退出游戏?+No 否+Yes 是+Paused 暂停+Play 开始+OK OK+Left Right 左 右+run 跑+Up, OK, EXE 上、OK、EXE+jump (hold: higher) 跳(按住跳得更高)+Back 返回+pause 暂停+Reach the door. The level has other plans: trust nothing. 走到门口。关卡另有打算:什么都别相信。+You beat the Devil! 你打败了恶魔!+Every door of Level Devil is open behind you. Level Devil 的每一扇门都已在你身后打开。+Deaths in all: 总死亡次数:+Level 第+Level cleared! Deaths: 过关!死亡次数:+Locked 未解锁+Cleared. Fewest deaths: 已通过。最少死亡:+Not cleared yet 尚未通过+Deaths 死亡diff --git a/games/leveldevil/src/icon.png b/games/leveldevil/src/icon.pngnew file mode 100644index 00000000..72131093Binary files /dev/null and b/games/leveldevil/src/icon.png differdiff --git a/games/leveldevil/src/main.c b/games/leveldevil/src/main.cnew file mode 100644index 00000000..6e913c81--- /dev/null+++ b/games/leveldevil/src/main.c@@ -0,0 +1,723 @@+/* Level Devil: run to the door. The level has other plans.+ *+ * Unept's troll platformer (2023), its first world: sixteen doors of five short rooms in flat+ * colours, with its tiny black runner. Floors drop away under you, spikes pop up in front of the+ * door, walls slide out, the door runs off, the controls turn round, gravity flips... Every trap+ * waits for the runner to reach its spot, so a room catches you the first time and is easy once+ * you know it; some rooms change again after you die in them.+ *+ * A room is a list of objects (blocks, spikes, saws, springs, warps, switches and the door), each+ * with an optional trap: what sets it off (the runner crossing a line, touching it, the trap+ * before it, the room starting), after how many deaths it is there, and what it does (slide,+ * loop, chase, fall, appear or vanish). The rooms are written in tools/rooms.py, which packs them+ * (DEFLATE); they are unpacked into RAM when the game starts. The game steps 60 times a second+ * and only the rows that change are drawn again, in the launcher's strips (launcher/src/gfx.c).+ * Inside NumPlay it uses the launcher's shapes, fonts, files and inflater; on its own it brings+ * them along. */+#include <eadk.h>+#include "../../../launcher/src/gfx.h"+#include "../../../launcher/src/inflate.h"+#include "../../common/np_text.h"++#if NP_MODULE /* (np_file_read and np_file_write: NumPlay's, launcher/src/np.h) */+#define np_app_begin()+#define np_app_end() 0+#else+#include "../../common/epsilon_app.h"+#include "../../common/epsilon_files.h"+#define np_file_read ef_read+#define np_file_write ef_write+const char eadk_app_name[] __attribute__((section(".rodata.eadk_app_name"))) = "Level Devil";+const uint32_t eadk_api_level __attribute__((section(".rodata.eadk_api_level"))) = 0;+void np_push(int x, int y, int w, int h, const color_t *px) {+ eadk_display_push_rect((eadk_rect_t){(uint16_t)x, (uint16_t)y, (uint16_t)w, (uint16_t)h}, px);+}+#endif++#define KEY(k) (1ull << (k))+#define G 2 /* screen pixels to a pixel of the game, each way */+#define FW 160 /* the room, in the game's pixels */+#define FH 120+#define TOP 10 /* the ceiling: the band with the level, its rooms and the deaths */+#define WALL 4+#define PW 5 /* the runner's box */+#define PH 7+#define DW 11 /* the door */+#define DH 20+#define ROOMS 5+#define LEVELS 16++/* A room (tools/rooms.py): its modes (R_*), where the runner starts (x, and the y of its feet), how+ * many objects, then the objects. An object: its kind and flags, then x, y, w and h in pixels of the+ * game (a door: h 1 when it hangs from the ceiling; a warp: its two ends, w and h the second one's+ * x and y; a switch or a button: dx the modes it toggles). With F_TRAP, five more bytes, its trap: what+ * sets it off (T_* and a value: the line the runner crosses, how near it comes, the object whose+ * trap goes first), how many deaths in the room it waits for (1-3: there from that death on; 5-7:+ * there until death 1-3), how it moves (M_*), by how much (dx, dy, signed), how fast (speeds[]),+ * and after how many 4ths of 16 steps. */+enum { K_BLOCK, K_SECRET, K_SPIKE_U, K_SPIKE_D, K_SPIKE_L, K_SPIKE_R, K_DOOR, K_SAW, K_SPRING, K_WARP, K_SWITCH, K_BUTTON };+#define F_HIDDEN 0x10 /* not there until its trap goes off */+#define F_VANISH 0x20 /* gone when its trap goes off */+#define F_GHOST 0x40 /* drawn, but nothing to stand on (a fake block), or a fake door */+#define F_TRAP 0x80+enum { T_START, T_RIGHT, T_LEFT, T_UP, T_DOWN, T_TOUCH, T_AFTER, T_NEAR };+enum { M_ONCE, M_LOOP, M_CHASE, M_FALL };+/* the modes of a room, which switches and buttons toggle (their dx) */+#define R_BACK 1 /* left and right swapped */+#define R_ICE 2 /* the floor is slippery */+#define R_AIR 4 /* jump in the air as often as you like */+#define R_FLIP 8 /* gravity upwards */+#define R_WRAP 16 /* no side walls: out one side, in at the other */+#include "rooms.inc" /* rooms_z, ROOM_BYTES */+static uint8_t rooms[ROOM_BYTES];++/* each level's background and ground */+static const color_t colors[LEVELS][2] = {+ {HEX(0xF49F7E), HEX(0x634D40)}, {HEX(0xF68048), HEX(0xB8461E)}, {HEX(0xF2BD48), HEX(0xA9690A)},+ {HEX(0xA5CF55), HEX(0x2E5A45)}, {HEX(0x84C9E6), HEX(0x274F6E)}, {HEX(0xB9A3DE), HEX(0x46356B)},+ {HEX(0x8FD9B6), HEX(0x285C49)}, {HEX(0xF29BB5), HEX(0x7A2E4A)}, {HEX(0xE6CF9C), HEX(0x6B5235)},+ {HEX(0x6CC7C2), HEX(0x1D5052)}, {HEX(0xF7B58B), HEX(0x8A4B2A)}, {HEX(0xA3B5F0), HEX(0x2F3D7A)},+ {HEX(0xCDB2E8), HEX(0x5B2F73)}, {HEX(0xD3ECF4), HEX(0x3A6A82)}, {HEX(0xF07C6C), HEX(0x5E2420)},+ {HEX(0xC8452A), HEX(0x2A0A06)},+};++/* the runner, 256ths of a pixel a step (60 a second) */+#define RUN 280+#define GRAV 56+#define JUMP 770+#define FALL 900+#define SPRING 1180++#define WHITE 0xFFFF+#define BLACK 0+#define GREY HEX(0xC8C8C8)+#define HUB_BG HEX(0xF2BD48)+#define HUB_FG HEX(0xC47A0A)+#define RED HEX(0xD9512C)+#define DARK_RED HEX(0x6E1A0E)++/* leveldevil.sav */+static struct {+ uint8_t magic, version, flags, open; /* flags: 1 the keys were shown; open: the levels open, 1 to 16 */+ uint8_t level, room; /* the level last played, and the room reached in it */+ uint16_t done; /* the levels cleared, a bit each */+ uint32_t deaths; /* in all */+ uint16_t run, sel; /* deaths since that level began; the door picked last */+ uint16_t best[LEVELS]; /* the fewest deaths each level was cleared with */+} sv;+#define SAVE_NAME "leveldevil.sav"++typedef struct {+ const uint8_t *r; /* its record */+ int16_t x, y, v; /* where it is, in 16ths of a pixel; its speed falling */+ uint8_t i, st, t, on; /* its place in the room; its trap's state and delay left; there or not */+} obj_t;+enum { S_WAIT, S_DELAY, S_GO, S_DONE };+static obj_t ob[28];+static int no;++static color_t strip[SCREEN_W * STRIP_H];+static const uint8_t *room;+static int level, rnum, tries, mode, scr, ov, sel, banner, dlo, dhi, full;+static int32_t px, py, vx, vy; /* the runner: its box's top-left and its speed, in 256ths of a pixel */+static int face = 1, ground, coyote, buffer, held_in, anim, dead, won, warped, curtain;+static uint32_t found, seed, banner_t, now;+static const obj_t *skip_ob; /* left out of collisions (a block pushing the runner) */+static color_t bg, fg;+static struct {+ int16_t x, y;+ int8_t vx, vy;+} bits[14]; /* the runner, in pieces */+enum { SC_HUB, SC_PLAY };+enum { OV_NONE, OV_PAUSE, OV_HELP, OV_QUIT, OV_END };+enum { I_LEFT = 1, I_RIGHT = 2, I_JUMP = 4 };++static uint32_t rnd(void) {+ seed ^= seed << 13;+ seed ^= seed >> 17;+ return seed ^= seed << 5;+}+static int imin(int a, int b) { return a < b ? a : b; }+static int imax(int a, int b) { return a > b ? a : b; }+static int clampi(int v, int a, int b) { return v < a ? a : v > b ? b : v; }+static char *cat(char *o, const char *s) { /* s at o; returns its end */+ while (*s) *o++ = *s++;+ *o = 0;+ return o;+}+static char *num(char *o, uint32_t v) { /* v at o; returns its end */+ char t[10];+ int n = 0;+ do t[n++] = (char)('0' + v % 10); while (v /= 10);+ while (n) *o++ = t[--n];+ *o = 0;+ return o;+}+static char *label(char *o, const char *s, uint32_t v) { /* a text, then a number; returns o */+ num(cat(o, s), v);+ return o;+}+static void save(void) {+ sv.magic = 'L', sv.version = 1;+ np_file_write(SAVE_NAME, &sv, sizeof sv);+}++/* ------------------------------------------------------------ the room */+static const uint8_t *next_room(const uint8_t *p) {+ int n = p[3];+ for (p += 4; n--;) p += *p & F_TRAP ? 10 : 5;+ return p;+}+/* the box of an object, in pixels */+static void box(const obj_t *o, int *b) {+ const uint8_t *r = o->r;+ int k = r[0] & 15;+ b[0] = o->x >> 4, b[1] = o->y >> 4, b[2] = r[3], b[3] = r[4];+ if (k == K_DOOR) b[2] = DW, b[3] = DH;+ if (k == K_WARP) b[2] = 8, b[3] = 12;+}+static bool overlap(int x, int y, int w, int h, const int *b) {+ return x < b[0] + b[2] && b[0] < x + w && y < b[1] + b[3] && b[1] < y + h;+}+static bool solid(const obj_t *o) {+ int k = o->r[0] & 15;+ return o->on && (k == K_SECRET || (k == K_BLOCK && !(o->r[0] & F_GHOST)));+}+/* What the runner's box would hit at (x, y): a solid object, the walls (ob itself), or nothing. */+static const obj_t *blocked(int x, int y) {+ int b[4];+ if (y < TOP || (!(mode & R_WRAP) && (x < WALL || x + PW > FW - WALL))) return ob;+ for (int k = 0; k < no; k++) {+ obj_t *o = &ob[k];+ if (o == skip_ob || !solid(o)) continue;+ box(o, b);+ if (overlap(x, y, PW, PH, b)) {+ found |= 1u << o->i; /* a secret block, found by bumping into it */+ return o;+ }+ }+ return 0;+}+/* Moves the runner along one axis, a pixel at a time; true when something stopped it. */+static bool move(int32_t *p, int32_t d, int axis) {+ int a = *p >> 8, b = (*p + d) >> 8, s = b > a ? 1 : -1;+ for (; a != b; a += s)+ if (axis ? blocked(px >> 8, a + s) : blocked(a + s, py >> 8)) {+ *p = a * 256 + (s > 0 ? 255 : 0);+ return true;+ }+ *p += d;+ return false;+}+/* the runner's box, a pixel bigger all round, against an object */+static bool touching(const obj_t *o) {+ int b[4];+ box(o, b);+ return overlap((px >> 8) - 1, (py >> 8) - 1, PW + 2, PH + 2, b);+}++static void mark(int y, int h) { /* rows y to y + h (game pixels) to draw again */+ dlo = imin(dlo, clampi(y * G - 2, 0, SCREEN_H)), dhi = imax(dhi, clampi((y + h) * G + 2, 0, SCREEN_H));+}++static void reset(void) { /* the room as it starts, the runner at the start */+ const uint8_t *p = room;+ mode = p[0], px = p[1] * 256, py = (p[2] - PH) * 256, vx = vy = 0;+ ground = coyote = buffer = dead = won = warped = 0, face = 1;+ int n = p[3];+ no = 0, p += 4;+ for (int i = 0; i < n; i++) {+ const uint8_t *r = p;+ p += *r & F_TRAP ? 10 : 5;+ if (*r & F_TRAP) { /* there only after (or before) so many deaths */+ int d = r[5] >> 3 & 7;+ if ((d && d < 4 && tries < d) || (d > 4 && tries >= d - 4)) continue;+ }+ obj_t *o = &ob[no++];+ o->r = r, o->i = (uint8_t)i, o->x = (int16_t)(r[1] << 4), o->y = (int16_t)(r[2] << 4), o->v = 0;+ o->st = *r & F_TRAP ? S_WAIT : S_DONE, o->on = !(*r & F_HIDDEN), o->t = 0;+ }+ ground = blocked(px >> 8, (py >> 8) + 1) != 0, full = 1;+}+static void enter(void) { /* the room rnum of the level */+ room = rooms;+ for (int i = level * ROOMS + rnum; i--;) room = next_room(room);+ bg = colors[level][0], fg = colors[level][1];+ found = 0, tries = 0;+ reset();+}++static void die(void) {+ dead = 1;+ sv.deaths++, sv.run++;+ for (int i = 0; i < 14; i++) {+ bits[i].x = (int16_t)((px >> 4) + 32), bits[i].y = (int16_t)((py >> 4) + 48);+ bits[i].vx = (int8_t)((int)(rnd() % 41) - 20), bits[i].vy = (int8_t)(-(int)(rnd() % 36) - 6);+ }+ save();+}++/* has the trap of o gone off? */+static bool fired(const obj_t *o) {+ const uint8_t *r = o->r;+ int v = r[6], x = px >> 8, y = py >> 8, c;+ switch (r[5] & 7) {+ case T_START: return true;+ case T_RIGHT: return x + PW > v;+ case T_LEFT: return x < v;+ case T_UP: return y < v;+ case T_DOWN: return y + PH > v;+ case T_TOUCH: return touching(o);+ case T_AFTER:+ for (int k = 0; k < no; k++)+ if (ob[k].i == v) return ob[k].st >= S_GO;+ return false;+ default: /* T_NEAR */+ c = (o->x >> 4) + r[3] / 2 - x - PW / 2;+ return c < v && c > -v;+ }+}++/* Moves o to (x, y) (16ths), carrying the runner standing on it and pushing it when it runs+ into it; the runner crushed against something else dies. */+static void shift(obj_t *o, int x, int y) {+ int b[4], g = mode & R_FLIP ? -1 : 1, rx = px >> 8, ry = py >> 8;+ box(o, b);+ int ox = b[0], oy = b[1];+ bool on_it = solid(o) && (o->r[5] >> 6) != M_FALL && rx < b[0] + b[2] && b[0] < rx + PW &&+ (g > 0 ? ry + PH == b[1] : ry == b[1] + b[3]);+ mark(b[1], b[3]);+ o->x = (int16_t)x, o->y = (int16_t)y;+ box(o, b);+ mark(b[1], b[3]);+ int dx = b[0] - ox, dy = b[1] - oy;+ if ((!dx && !dy) || dead) return;+ skip_ob = o;+ if (on_it) move(&px, dx * 256, 0), move(&py, dy * 256, 1);+ if (solid(o) && overlap(px >> 8, py >> 8, PW, PH, b)) {+ if (dx) move(&px, (dx > 0 ? b[0] + b[2] - (px >> 8) : b[0] - PW - (px >> 8)) * 256, 0);+ if (dy) move(&py, (dy > 0 ? b[1] + b[3] - (py >> 8) : b[1] - PH - (py >> 8)) * 256, 1);+ if (overlap(px >> 8, py >> 8, PW, PH, b)) die();+ }+ skip_ob = 0;+}++static const uint8_t speeds[16] = {0, 2, 4, 6, 8, 12, 16, 20, 24, 32, 40, 48, 64, 80, 96, 128};+static void traps(void) {+ for (int k = 0; k < no; k++) {+ obj_t *o = &ob[k];+ const uint8_t *r = o->r;+ int kind = r[0] & 15, b[4];+ if (kind == K_SAW || o->t > 200) mark((o->y >> 4) - 1, r[4] + 2); /* turning, springing */+ if (kind == K_SPRING && o->t > 200 && ++o->t == 0) o->t = 0;+ if (kind == K_BUTTON && o->st == S_DONE && !touching(o)) o->st = S_WAIT, mark(o->y >> 4, r[4]);+ if (o->st == S_WAIT && !dead && !won && fired(o)) o->st = S_DELAY, o->t = (uint8_t)((r[9] >> 4) * 4);+ if (o->st == S_DELAY && !(o->t && o->t--)) {+ o->st = S_GO;+ box(o, b);+ mark(b[1], b[3]);+ if (*r & F_HIDDEN) o->on = 1;+ if (*r & F_VANISH) o->on = 0, o->st = S_DONE;+ if (kind == K_SWITCH || kind == K_BUTTON) mode ^= r[7], o->st = S_DONE, full = 1;+ if (o->on && solid(o) && overlap(px >> 8, py >> 8, PW, PH, b)) die(); /* a block appears on the runner */+ }+ if (o->st != S_GO) continue;+ int m = r[5] >> 6, s = speeds[r[9] & 15], tx = (r[1] + (int8_t)r[7]) * 16, ty = (r[2] + (int8_t)r[8]) * 16;+ if (!s) s = 4096;+ if (m == M_FALL) {+ o->v = (int16_t)imin(o->v + 4, 80);+ shift(o, o->x, o->y + o->v);+ if (o->y >> 4 > FH) o->on = 0, o->st = S_DONE;+ continue;+ }+ if (m == M_CHASE) /* towards the runner, along the axes it moves on */+ tx = r[7] ? (int)(px >> 4) + PW * 8 - r[3] * 8 : o->x, ty = r[8] ? (int)(py >> 4) + PH * 8 - r[4] * 8 : o->y;+ if (m == M_LOOP && o->v) tx = r[1] << 4, ty = r[2] << 4; /* on the way back */+ shift(o, o->x + clampi(tx - o->x, -s, s), o->y + clampi(ty - o->y, -s, s));+ if (o->x == tx && o->y == ty && m != M_CHASE) {+ if (m == M_LOOP) o->v = !o->v;+ else o->st = S_DONE;+ }+ }+}++/* what the runner touches: springs, warps, the door, what kills */+static void contacts(void) {+ int x = px >> 8, y = py >> 8, b[4], g = mode & R_FLIP ? -1 : 1, in_warp = 0;+ if (y > FH + 2 || y < -PH - 2) die();+ for (int k = 0; k < no && !dead; k++) {+ obj_t *o = &ob[k];+ int kind = o->r[0] & 15;+ if (!o->on) continue;+ box(o, b);+ if (kind >= K_SPIKE_U && kind <= K_SPIKE_R) { /* the points, a little inside the teeth */+ int u = kind == K_SPIKE_U, d = kind == K_SPIKE_D, l = kind == K_SPIKE_L, rr = kind == K_SPIKE_R;+ int hb[4] = {b[0] + (u || d ? 1 : 2 * l), b[1] + (l || rr ? 1 : 2 * u), b[2] - (u || d ? 2 : 2),+ b[3] - (l || rr ? 2 : 2)};+ if (overlap(x, y, PW, PH, hb)) die();+ } else if (kind == K_SAW) { /* the nearest point of the box to the middle of the saw */+ int c = b[2] / 2, cx = b[0] + c, cy = b[1] + c, dx = cx - clampi(cx, x, x + PW - 1), dy = cy - clampi(cy, y, y + PH - 1);+ if (dx * dx + dy * dy < (c - 1) * (c - 1)) die();+ } else if (kind == K_SPRING) {+ if (overlap(x, y + PH - 1, PW, 2, b) && vy * g >= 0) vy = -g * SPRING, o->t = 236, ground = 0;+ } else if (kind == K_WARP) {+ int e[4] = {o->r[3], o->r[4], 8, 12}, a = overlap(x, y, PW, PH, b), z = overlap(x, y, PW, PH, e);+ if ((a || z) && !warped) {+ mark(y, PH);+ px = ((z ? b[0] : e[0]) + 2) * 256, py = ((z ? b[1] : e[1]) + 12 - PH) * 256;+ mark(py >> 8, PH);+ }+ in_warp |= a | z;+ } else if (kind == K_DOOR && !(o->r[0] & F_GHOST)) {+ int in[4] = {b[0] + 3, b[1] + 4, DW - 6, DH - 4};+ if (overlap(x, y, PW, PH, in)) won = 1, mark(b[1], DH);+ }+ }+ warped = in_warp;+}++static void step(int in) {+ anim++;+ if (dead) {+ for (int i = 0; i < 14; i++) {+ mark(bits[i].y >> 4, 2);+ bits[i].x += bits[i].vx, bits[i].y += bits[i].vy, bits[i].vy = (int8_t)imin(bits[i].vy + 3, 60);+ mark(bits[i].y >> 4, 2);+ }+ if (++dead > 42) tries++, reset();+ return;+ }+ if (won) return;+ int g = mode & R_FLIP ? -1 : 1;+ mark((py >> 8) - 1, PH + 2);+ traps();+ if (dead) return;+ int dir = !!(in & I_RIGHT) - !!(in & I_LEFT);+ if (mode & R_BACK) dir = -dir;+ if (in & I_JUMP & ~held_in) buffer = 7;+ held_in = in;+ int ice = mode & R_ICE && ground, acc = ground ? (ice ? 5 : 60) : 40, dec = ground ? (ice ? 3 : 90) : 20;+ if (dir) vx = clampi(vx + dir * acc, -RUN, RUN), face = dir;+ else vx = vx > dec ? vx - dec : vx < -dec ? vx + dec : 0;+ if (buffer && (buffer--, coyote || mode & R_AIR)) vy = -g * JUMP, buffer = coyote = 0;+ vy += g * (vy * g < 0 && !(in & I_JUMP) ? 3 * GRAV : GRAV);+ if (vy * g > FALL) vy = g * FALL;+ if (move(&px, vx, 0)) vx = 0;+ if (move(&py, vy, 1)) vy = 0;+ if (mode & R_WRAP) px = (px + (FW << 8) + (PW << 7)) % (FW << 8) - (PW << 7); /* out one side, in at the other */+ ground = blocked(px >> 8, (py >> 8) + g) != 0;+ coyote = ground ? 6 : coyote ? coyote - 1 : 0;+ contacts();+ mark((py >> 8) - 1, PH + 2);+}++/* ------------------------------------------------------------ drawing */+static void fillg(int x, int y, int w, int h, color_t c) { gfx_fill(x * G, y * G, w * G, h * G, c); }++/* a picture of w x n pixels (a byte a row, its first pixel the top bit), s screen pixels each,+ turned round left to right and upside down as asked */+static void bitmap(const uint8_t *rows, int n, int w, int x, int y, int s, color_t c, int fx, int fy) {+ for (int j = 0; j < n; j++)+ for (int i = 0, v = rows[fy ? n - 1 - j : j]; i < w; i++)+ if (v >> (7 - (fx ? w - 1 - i : i)) & 1) gfx_fill(x + i * s, y + j * s, s, s, c);+}+/* the runner: standing, two steps running, jumping (6 x 7) */+static const uint8_t runner[4][7] = {+ {0x30, 0x30, 0x78, 0x78, 0x78, 0x48, 0x48},+ {0x30, 0x30, 0x78, 0x78, 0xF8, 0x8C, 0x04},+ {0x30, 0x30, 0x78, 0x78, 0x78, 0x30, 0x30},+ {0x18, 0x18, 0x78, 0x7C, 0x78, 0xCC, 0x80},+};+static const uint8_t skull[5] = {0x70, 0xF8, 0xA8, 0xF8, 0x50};+static const uint8_t horns[3] = {0x81, 0xC3, 0x66};++static void draw_runner(int x, int y, int f, int flip) {+ bitmap(runner[f], 7, 6, x - (face < 0) * G, y, G, BLACK, face < 0, flip);+}++/* a door, s screen pixels a pixel of the game; its window in w */+static void door(int x, int y, int s, color_t frame, color_t w, int up) {+ gfx_fill(x + s, y, 9 * s, s, frame);+ gfx_fill(x, y + s, 11 * s, 19 * s, frame);+ if (up) y += 10 * s; /* (hanging from the ceiling: the window at the bottom) */+ gfx_fill(x + 2 * s, y + s, 7 * s, 9 * s, w);+ gfx_fill(x + s, y + 2 * s, 9 * s, 7 * s, w);+}++static void spikes(int kind, int x, int y, int w, int h) {+ int n = (kind < K_SPIKE_L ? w : h) / 5;+ for (int t = 0; t < n; t++)+ for (int j = 0; j < 3; j++) { /* the three steps of a tooth, from its point */+ int a = 2 - j, l = 1 + 2 * j, d = j ? 2 * j - 1 : 0, e = j ? 2 : 1, u = t * 5 + a;+ if (kind == K_SPIKE_U) fillg(x + u, y + d, l, e, fg);+ if (kind == K_SPIKE_D) fillg(x + u, y + h - d - e, l, e, fg);+ if (kind == K_SPIKE_L) fillg(x + d, y + u, e, l, fg);+ if (kind == K_SPIKE_R) fillg(x + w - d - e, y + u, e, l, fg);+ }+}++static void draw_object(const obj_t *o, int blocks) {+ const uint8_t *r = o->r;+ int kind = r[0] & 15, b[4];+ if (!o->on || (kind == K_BLOCK || kind == K_SECRET) != blocks) return;+ box(o, b);+ if (b[1] * G >= gfx_y1 || (b[1] + b[3]) * G <= gfx_y0) {+ if (kind != K_WARP) return;+ }+ int x = b[0], y = b[1], w = b[2], h = b[3];+ if (kind == K_BLOCK) fillg(x, y, w, h, fg);+ else if (kind == K_SECRET) {+ if (found >> o->i & 1) fillg(x, y, w, h, fg);+ } else if (kind <= K_SPIKE_R) spikes(kind, x, y, w, h);+ else if (kind == K_DOOR) door(x * G, y * G, G, fg, won && !(r[0] & F_GHOST) ? fg : GREY, r[4] == 1);+ else if (kind == K_SAW) { /* a disc with eight teeth, turning */+ int c = w / 2, a = anim >> 1;+ gfx_circle((x + c) * G, (y + c) * G, c * G - 2, fg, 256);+ for (int t = 0; t < 8; t++) {+ static const int8_t sx[8] = {0, 7, 10, 7, 0, -7, -10, -7};+ int q = (t + a) & 7, z = c * G - 1;+ gfx_fill((x + c) * G + sx[q] * z / 10 - 2, (y + c) * G + sx[(q + 6) & 7] * z / 10 - 2, 4, 4, fg);+ }+ gfx_circle((x + c) * G, (y + c) * G, 3, bg, 256);+ } else if (kind == K_SPRING) {+ int up = o->t > 200 && o->t < 248 ? 1 : 2;+ fillg(x, y + 2, w, 1, fg);+ fillg(x + 1, y + 2 - up, 1, up, fg), fillg(x + w - 2, y + 2 - up, 1, up, fg);+ fillg(x, y + 1 - up, w, 1, fg);+ } else if (kind == K_WARP) { /* both of its ends: rings */+ for (int e = 0; e < 2; e++) {+ int ex = (e ? r[3] : x) * G + 8, ey = (e ? r[4] : y) * G + 12;+ gfx_rrect(ex - 8, ey - 12, 16, 24, 8, WHITE, 256);+ gfx_rrect(ex - 5, ey - 9, 10, 18, 5, fg, 256);+ }+ } else if (kind == K_BUTTON) { /* (a ghost one: on a ceiling) */+ int down = touching(o), up = r[0] & F_GHOST;+ fillg(x + 1, y + (up ? 0 : down), w - 2, h - down, RED);+ fillg(x, up ? y : y + h - 1, w, 1, fg);+ }+}++static void say(const np_font_t *f, int cx, int base, const char *s, color_t c, color_t shade) {+ gfx_text_center(f, cx + 1, base + 2, s, shade, 256);+ gfx_text_center(f, cx, base, s, c, 256);+}+static void button(int y, const char *s, bool on, color_t a, color_t b) {+ if (on) gfx_rrect(96, y, 128, 24, 12, a, 256);+ gfx_text_center(&np_font_body, 160, y + 17, s, on ? b : a, 256);+}++static const char *const pause_items[] = {T("Resume"), T("Restart"), T("Levels"), T("How to play"), T("Quit game")};+static void overlay(void) {+ color_t a = scr == SC_HUB ? HUB_BG : bg, b = scr == SC_HUB ? HUB_FG : fg;+ char s[24];+ gfx_fill_alpha(0, 0, SCREEN_W, SCREEN_H, BLACK, 100);+ if (ov == OV_PAUSE) {+ gfx_rrect(72, 28, 176, 190, 12, b, 256);+ gfx_text_center(&np_font_title, 160, 60, T("Paused"), a, 256);+ for (int i = 0; i < 5; i++) button(72 + 28 * i, pause_items[i], sel == i, a, b);+ } else if (ov == OV_QUIT) {+ gfx_rrect(72, 76, 176, 96, 12, b, 256);+ gfx_text_center(&np_font_title, 160, 110, T("Quit game?"), a, 256);+ for (int i = 0; i < 2; i++) {+ if (sel == i) gfx_rrect(92 + 72 * i, 128, 64, 24, 12, a, 256);+ gfx_text_center(&np_font_body, 124 + 72 * i, 145, i ? T("Yes") : T("No"), sel == i ? b : a, 256);+ }+ } else if (ov == OV_HELP) {+ static const char *const keys[][2] = {{T("Left Right"), T("run")}, {T("Up, OK, EXE"), T("jump (hold: higher)")},+ {T("Back"), T("pause")}};+ gfx_rrect(40, 30, 240, 180, 12, b, 256);+ gfx_text_center(&np_font_title, 160, 62, T("How to play"), a, 256);+ gfx_paragraph(&np_font_body, 160, 86, 208, 15, T("Reach the door. The level has other plans: trust nothing."), a,+ 256);+ for (int i = 0; i < 3; i++) {+ gfx_text_right(&np_font_body, 136, 136 + 18 * i, keys[i][0], WHITE, 256);+ gfx_text(&np_font_body, 146, 136 + 18 * i, keys[i][1], a, 256);+ }+ button(176, T("Play"), true, a, b);+ } else { /* OV_END: the Devil beaten */+ gfx_rrect(40, 40, 240, 160, 12, RED, 256);+ say(&np_font_title, 160, 82, T("You beat the Devil!"), WHITE, DARK_RED);+ gfx_paragraph(&np_font_body, 160, 108, 200, 15, T("Every door of Level Devil is open behind you."), WHITE, 256);+ gfx_text_center(&np_font_body, 160, 152, label(s, T("Deaths in all: "), sv.deaths), WHITE, 256);+ button(164, T("OK"), true, WHITE, RED);+ }+}++static void hud(void) {+ char s[16];+ fillg(0, 0, FW, TOP, fg);+ gfx_text(&np_font_small, 10, 14, label(s, T("Level "), (uint32_t)level + 1), bg, 256);+ for (int i = 0; i < ROOMS; i++) /* the rooms of the level: done, this one, still to come */+ gfx_circle(136 + 12 * i, 10, i == rnum ? 4 : 3, i <= rnum ? bg : gfx_mix(fg, bg, 12), 256);+ num(s, sv.run);+ gfx_text_right(&np_font_small, 310, 14, s, bg, 256);+ bitmap(skull, 5, 5, 298 - gfx_text_width(&np_font_small, s), 5, 2, bg, 0, 0);+}++static void play_scene(void *ctx) {+ fillg(0, TOP, FW, FH - TOP, bg);+ for (int pass = 0; pass < 2; pass++)+ for (int k = 0; k < no; k++) draw_object(&ob[k], pass);+ if (!(mode & R_WRAP)) fillg(0, 0, WALL, FH, fg), fillg(FW - WALL, 0, WALL, FH, fg);+ if (dead)+ for (int i = 0; i < 14; i++) gfx_fill((bits[i].x >> 4) * G, (bits[i].y >> 4) * G, G, G, BLACK);+ else if (!won) {+ int x = (px >> 8) * G, y = (py >> 8) * G, f = !ground ? 3 : vx ? 1 + (anim >> 3 & 1) : 0, flip = mode & R_FLIP;+ draw_runner(x, y, f, flip);+ if (mode & R_WRAP) draw_runner(x + (x < FW ? FW * G : -FW * G), y, f, flip);+ }+ hud();+ if (curtain) fillg(0, TOP, FW, (FH - TOP) * curtain / 16, fg);+ if (ov) overlay();+}+++/* the doors to the levels: two rows of eight, on two floors */+static void hub_door(int i, int *x, int *y) { *x = 13 + 38 * (i & 7), *y = 70 + 80 * (i >> 3); }+static void hub_scene(void *ctx) {+ char s[48];+ int sel_ = sv.sel, best = sv.best[sel_];+ gfx_fill(0, 0, SCREEN_W, SCREEN_H, HUB_BG);+ gfx_fill(0, 0, SCREEN_W, 44, RED);+ if (banner) say(&np_font_title, 160, 32, label(s, T("Level cleared! Deaths: "), (uint32_t)banner - 1), WHITE, DARK_RED);+ else say(&np_font_title, 160, 32, "LEVEL DEVIL", DARK_RED, HEX(0xA33219));+ for (int i = 0; i < LEVELS; i++) {+ int x, y, open = i < sv.open;+ hub_door(i, &x, &y);+ if (!(i & 7)) gfx_fill(0, y + 40, SCREEN_W, 8, HUB_FG);+ color_t frame = i == 15 ? RED : open ? HUB_FG : gfx_mix(HUB_FG, HUB_BG, 18);+ if (i == 15) bitmap(horns, 3, 8, x + 3, y - 5, 2, RED, 0, 0);+ door(x, y, 2, frame, sv.done >> i & 1 ? colors[i][0] : open ? GREY : frame, 0);+ num(s, (uint32_t)i + 1);+ gfx_text_center(&np_font_small, x + 11, y - 7 - 5 * (i == 15), s, frame, 256);+ if (i == sel_) draw_runner(x - 12, y + 26, 0, 0);+ }+ gfx_fill(0, 214, SCREEN_W, 26, HUB_FG);+ if (sel_ >= sv.open) cat(s, T("Locked"));+ else if (sv.done >> sel_ & 1) label(s, T("Cleared. Fewest deaths: "), best);+ else cat(s, T("Not cleared yet"));+ gfx_text(&np_font_body, 8, 232, s, HUB_BG, 256);+ gfx_text_right(&np_font_body, 312, 232, label(s, T("Deaths "), sv.deaths), HUB_BG, 256);+ if (ov) overlay();+}++/* ------------------------------------------------------------ the levels */+static void open_room(void) { /* the room rnum, behind a curtain that lifts */+ enter();+ curtain = 16;+}+static void start_level(int l) {+ if (l != sv.level || sv.room >= ROOMS) sv.room = 0, sv.run = 0;+ level = sv.level = (uint8_t)l, rnum = sv.room;+ scr = SC_PLAY;+ open_room();+ save();+}+static void level_done(void) {+ int first = !(sv.done >> level & 1);+ if (first || sv.run < sv.best[level]) sv.best[level] = sv.run;+ sv.done |= (uint16_t)(1u << level);+ sv.open = (uint8_t)imax(sv.open, imin(level + 2, LEVELS));+ banner = sv.run + 1, banner_t = now;+ sv.room = 0, sv.run = 0, sv.sel = (uint16_t)imin(level + 1, LEVELS - 1);+ scr = SC_HUB, full = 1;+ if (level == LEVELS - 1 && first) ov = OV_END;+ save();+}++/* a step of the room: the curtain, the door reached, or the runner */+static void tick(int in) {+ if (curtain && !won) {+ curtain--, full = 1;+ return;+ }+ if (won && ++won > 10) curtain = imin(won - 10, 16), full = 1;+ if (won > 28) {+ won = 0;+ if (++rnum == ROOMS) level_done();+ else sv.room = (uint8_t)rnum, save(), open_room();+ return;+ }+ step(in);+}++static void load(void) {+ uint32_t len = 0;+ const uint8_t *d = np_file_read(SAVE_NAME, &len);+ uint8_t *v = (uint8_t *)&sv;+ bool ok = d && len == sizeof sv && d[0] == 'L' && d[1] == 1;+ for (uint32_t i = 0; i < sizeof sv; i++) v[i] = ok ? d[i] : 0;+ sv.open = (uint8_t)clampi(sv.open, 1, LEVELS), sv.sel = (uint16_t)clampi(sv.sel, 0, LEVELS - 1);+ if (sv.level >= LEVELS) sv.level = 0;+}++int main(void) {+ np_app_begin();+ color_t *their_strip = gfx_buf;+ gfx_buf = strip;+ now = (uint32_t)eadk_timing_millis();+ seed = eadk_random() ^ now;+ if (!seed) seed = 1;+ np_inflate(rooms, ROOM_BYTES, rooms_z, sizeof rooms_z, (np_inflate_tables_t *)(void *)strip);+ load();+ if (!(sv.flags & 1)) ov = OV_HELP;+ full = 1, dlo = SCREEN_H;+ const uint64_t left = KEY(eadk_key_left) | KEY(eadk_key_four), right = KEY(eadk_key_right) | KEY(eadk_key_six);+ const uint64_t up = KEY(eadk_key_up) | KEY(eadk_key_eight), down = KEY(eadk_key_down) | KEY(eadk_key_two);+ const uint64_t ok = KEY(eadk_key_ok) | KEY(eadk_key_exe) | KEY(eadk_key_five), back = KEY(eadk_key_back);+ uint64_t held = eadk_keyboard_scan(), stale = held; /* keys still down from the launcher wait to be let go */+ uint32_t last = now, acc = 0;+ for (;;) {+ now = (uint32_t)eadk_timing_millis();+ uint64_t k = eadk_keyboard_scan(), hit = k & ~held;+ stale &= k, held = k, k &= ~stale;+ if (k & (KEY(eadk_key_home) | KEY(eadk_key_on_off))) break;+ int dx = !!(hit & right) - !!(hit & left), dy = !!(hit & down) - !!(hit & up), quit = 0;+ if (hit) full |= scr == SC_HUB || ov;+ if (ov) {+ if (ov == OV_PAUSE) sel = (sel + dy + 5) % 5;+ if (ov == OV_QUIT) sel ^= dx != 0;+ if (hit & ok) {+ if (ov == OV_PAUSE && sel == 1) { /* Restart: the runner bursts, as when it dies */+ ov = OV_NONE;+ if (!dead && !won) die();+ }+ else if (ov == OV_PAUSE && sel) ov = sel == 2 ? (scr = SC_HUB, save(), OV_NONE) : sel == 3 ? OV_HELP : OV_QUIT, sel = 0;+ else if (ov == OV_QUIT && sel) quit = 1;+ else ov = ov == OV_QUIT && scr == SC_PLAY ? (sel = 4, OV_PAUSE) : OV_NONE;+ if (!(sv.flags & 1)) sv.flags |= 1, save();+ } else if (hit & back) {+ ov = ov == OV_QUIT && scr == SC_PLAY ? (sel = 4, OV_PAUSE) : OV_NONE;+ }+ } else if (scr == SC_HUB) {+ sv.sel = (uint16_t)clampi(sv.sel + dx + 8 * dy, 0, LEVELS - 1);+ if (hit & ok && sv.sel < sv.open) start_level(sv.sel);+ if (hit & back) ov = OV_QUIT, sel = 0;+ } else if (hit & back) {+ ov = OV_PAUSE, sel = 0, full = 1;+ save();+ }+ if (quit) break;+ if (banner && now - banner_t > 2600) banner = 0, full = 1;+ acc += (now - last) * 3, last = now;+ if (scr == SC_PLAY && !ov) {+ int in = (k & left ? I_LEFT : 0) | (k & right ? I_RIGHT : 0) | (k & (up | ok) ? I_JUMP : 0);+ for (int n = 0; acc >= 50 && n < 4; acc -= 50, n++) tick(in);+ if (acc >= 50) acc = 0; /* (too far behind: let it go) */+ } else {+ acc = 0;+ }+ if (full || dlo < dhi) {+ eadk_display_wait_for_vblank();+ if (full) dlo = 0, dhi = SCREEN_H;+ gfx_render(scr == SC_HUB ? hub_scene : play_scene, 0, dlo & ~1, dhi);+ full = 0, dlo = SCREEN_H, dhi = 0;+ } else {+ eadk_timing_msleep(8);+ }+ }+ if (scr == SC_PLAY) sv.room = (uint8_t)rnum;+ save();+ gfx_buf = their_strip;+ return np_app_end();+}diff --git a/games/leveldevil/tests/play.c b/games/leveldevil/tests/play.cnew file mode 100644index 00000000..3daefca2--- /dev/null+++ b/games/leveldevil/tests/play.c@@ -0,0 +1,295 @@+/* Level Devil on a computer, for tests and pictures (make host, make test).+ *+ * play solve every room played through with its solutions (tests/solutions.txt): each+ * must reach the door without dying, as it starts and again after one, two+ * and three deaths (some rooms change)+ * play search L R [D] finds a way through a room (after D deaths), for tests/solutions.txt+ * play trace L R [D] where the runner goes with the solution+ * play rooms DIR a picture of every room as it starts (DIR/room_LL_R.ppm)+ * play film L R DIR [D] the solution of a room (after D deaths), a picture every 2 steps+ * (DIR/f_NNNN.ppm)+ */+#define main ld_main+#include "../src/main.c"+#undef main+#include <stdio.h>+#include <stdlib.h>+#include <string.h>++static uint16_t fb[SCREEN_H][SCREEN_W];+void eadk_display_push_rect(eadk_rect_t r, const eadk_color_t *p) {+ for (int j = 0; j < r.height; j++)+ for (int i = 0; i < r.width; i++) fb[r.y + j][r.x + i] = p[j * r.width + i];+}+void eadk_display_push_rect_uniform(eadk_rect_t r, eadk_color_t c) {+ for (int j = 0; j < r.height; j++)+ for (int i = 0; i < r.width; i++) fb[r.y + j][r.x + i] = c;+}+bool eadk_display_wait_for_vblank(void) { return true; }+uint64_t eadk_keyboard_scan(void) { return 0; }+uint64_t eadk_timing_millis(void) { return 0; }+void eadk_timing_msleep(uint32_t ms) { (void)ms; }+uint32_t eadk_random(void) { return 0x9E3779B9u; }+void *np_alloc(uint32_t size) { return malloc(size); }++/* tests/solutions.txt: a line a room, "LEVEL-ROOM: keys", with " | " between the keys for each+ number of deaths when the room changes (as it starts, after 1, 2, 3); "R40 RJ12 R30": the keys+ held, L R J or N for none, for so many steps */+static char *solutions[ROOM_COUNT][4];+static void read_solutions(void) {+ static char text[1 << 16];+ FILE *f = fopen("tests/solutions.txt", "r");+ size_t n = f ? fread(text, 1, sizeof text - 1, f) : 0;+ if (f) fclose(f);+ text[n] = 0;+ for (char *line = strtok(text, "\n"); line; line = strtok(0, "\n")) {+ int l, r, at;+ if (line[0] == '#' || sscanf(line, "%d-%d:%n", &l, &r, &at) < 2) continue;+ int i = (l - 1) * ROOMS + r - 1;+ if (i < 0 || i >= ROOM_COUNT) continue;+ char *p = line + at;+ for (int t = 0; t < 4; t++) {+ solutions[i][t] = p;+ char *bar = strchr(p, '|');+ if (bar) *bar = 0, p = bar + 1;+ }+ }+ for (int i = 0; i < ROOM_COUNT; i++)+ for (int t = 1; t < 4; t++)+ if (!solutions[i][t] || solutions[i][t] == solutions[i][t - 1]) solutions[i][t] = solutions[i][t - 1];+ for (int i = 0; i < ROOM_COUNT; i++)+ for (int t = 0; t < 4; t++)+ if (!solutions[i][t]) solutions[i][t] = "";+}++static void picture(const char *path) {+ FILE *f = fopen(path, "wb");+ if (!f) exit(2);+ fprintf(f, "P6 320 240 255\n");+ for (int y = 0; y < SCREEN_H; y++)+ for (int x = 0; x < SCREEN_W; x++) {+ uint16_t c = fb[y][x];+ fputc((c >> 11) * 255 / 31, f), fputc((c >> 5 & 63) * 255 / 63, f), fputc((c & 31) * 255 / 31, f);+ }+ fclose(f);+}+static void draw(void) { gfx_render(play_scene, 0, 0, SCREEN_H); }++static void setup(int l, int r, int deaths) {+ static int ready;+ if (!ready) {+ gfx_buf = strip, seed = 1, ready = 1;+ if (np_inflate(rooms, ROOM_BYTES, rooms_z, sizeof rooms_z, (np_inflate_tables_t *)(void *)strip) != ROOM_BYTES)+ exit(3);+ }+ scr = SC_PLAY, ov = 0, level = l, rnum = r;+ enter();+ tries = deaths;+ reset();+ curtain = 0;+}++/* plays a solution ("R30 RJ12 N8": the keys held, L R J or N for none, for so many steps);+ 1 the door reached, 0 dead, -1 neither */+static int run(const char *s, const char *film) {+ int frame = 0;+ char path[256];+ for (;;) {+ while (*s == ' ') s++;+ int in = 0, n = 240; /* (after the last keys, nothing for a while) */+ for (; *s >= 'A' && *s <= 'Z'; s++) in |= *s == 'L' ? I_LEFT : *s == 'R' ? I_RIGHT : *s == 'J' ? I_JUMP : 0;+ if (*s) {+ char *e;+ n = (int)strtol(s, &e, 10);+ if (e == s) return -1; /* (not keys) */+ s = e;+ }+ while (n--) {+ step(in);+ if (film && !(frame++ & 1)) {+ draw();+ snprintf(path, sizeof path, "%s/f_%04d.ppm", film, frame / 2);+ picture(path);+ }+ if (won || dead) return won ? 1 : 0;+ }+ if (!*s) return -1;+ }+}++/* ---- finding a solution: a best-first search over the keys held 4 steps at a time, from the room+ as it starts, through states not seen yet, the nearest to the door first */+typedef struct {+ obj_t ob[28];+ int no, face, ground, coyote, buffer, held_in, anim, mode, warped;+ int32_t px, py, vx, vy;+ uint32_t found;+} snap_t;+static void take(snap_t *s) {+ memcpy(s->ob, ob, sizeof ob);+ s->no = no, s->face = face, s->ground = ground, s->coyote = coyote, s->buffer = buffer, s->held_in = held_in;+ s->anim = anim, s->mode = mode, s->warped = warped, s->px = px, s->py = py, s->vx = vx, s->vy = vy;+ s->found = found;+}+static void give(const snap_t *s) {+ memcpy(ob, s->ob, sizeof ob);+ no = s->no, face = s->face, ground = s->ground, coyote = s->coyote, buffer = s->buffer, held_in = s->held_in;+ anim = s->anim, mode = s->mode, warped = s->warped, px = s->px, py = s->py, vx = s->vx, vy = s->vy;+ found = s->found, dead = won = 0;+}+static uint64_t key_of(void) { /* the state, roughly: the runner and every object */+ uint64_t h = (uint64_t)(px >> 8) * 1000003u ^ (uint64_t)(py >> 8) * 9176u ^ (uint64_t)((vx >> 7) + 64) * 131u ^+ (uint64_t)((vy >> 7) + 64) * 7u ^ (uint64_t)ground << 40 ^ (uint64_t)mode << 44 ^+ (uint64_t)(held_in & 4) << 50;+ for (int k = 0; k < no; k++)+ h = h * 1099511628211u ^ (uint64_t)(ob[k].st | ob[k].on << 2 | (ob[k].x >> 4) << 3 | (uint64_t)(ob[k].y >> 4) << 20);+ return h ? h : 1;+}+static int door_dist(void) { /* from the runner to the nearest real door, in 16ths of a pixel */+ int best = 1 << 30;+ for (int k = 0; k < no; k++)+ if ((ob[k].r[0] & 15) == K_DOOR && !(ob[k].r[0] & F_GHOST)) {+ int dx = ob[k].x + 88 - (int)(px >> 4) - 40, dy = ob[k].y + 200 - (int)(py >> 4) - 56;+ int d = (int)__builtin_sqrtf((float)(dx * dx + dy * dy));+ if (d < best) best = d;+ }+ return best;+}+#define SEEN (1 << 22)+#define NODES (1 << 20)+static uint64_t *seen;+static struct node {+ snap_t s;+ int parent, depth, f;+ uint8_t in;+} *nodes;+static int *heap, nheap;+static void push(int i) {+ int k = nheap++;+ for (; k && nodes[heap[(k - 1) / 2]].f > nodes[i].f; k = (k - 1) / 2) heap[k] = heap[(k - 1) / 2];+ heap[k] = i;+}+static int pop(void) {+ int top = heap[0], last = heap[--nheap], k = 0;+ for (;;) {+ int c = 2 * k + 1;+ if (c >= nheap) break;+ if (c + 1 < nheap && nodes[heap[c + 1]].f < nodes[heap[c]].f) c++;+ if (nodes[heap[c]].f >= nodes[last].f) break;+ heap[k] = heap[c], k = c;+ }+ heap[k] = last;+ return top;+}+static const uint8_t moves[6] = {I_RIGHT, I_RIGHT | I_JUMP, 0, I_LEFT, I_LEFT | I_JUMP, I_JUMP};+static int search(int i, int deaths) {+ if (!seen) seen = calloc(SEEN, 8), nodes = malloc(sizeof *nodes * NODES), heap = malloc(sizeof *heap * NODES);+ memset(seen, 0, (size_t)SEEN * 8);+ setup(i / ROOMS, i % ROOMS, deaths);+ int n = 1;+ take(&nodes[0].s), nodes[0].parent = -1, nodes[0].depth = 0, nodes[0].f = 0, nheap = 0;+ push(0);+ while (nheap && n < NODES - 8) {+ int at = pop();+ for (int m = 0; m < 6; m++) {+ give(&nodes[at].s);+ for (int k = 0; k < 4 && !dead && !won; k++) step(moves[m]);+ if (dead) continue;+ if (won) { /* the keys, back from here */+ static uint8_t ins[8192];+ int c = 0;+ ins[c++] = moves[m];+ for (int q = at; q > 0 && c < 8192; q = nodes[q].parent) ins[c++] = nodes[q].in;+ char out[16384], *o = out;+ for (int a = c - 1; a >= 0;) {+ int b = a;+ while (b >= 0 && ins[b] == ins[a]) b--;+ int in = ins[a];+ o += sprintf(o, "%s%s%s%s%d ", in & I_LEFT ? "L" : "", in & I_RIGHT ? "R" : "", in & I_JUMP ? "J" : "",+ in ? "" : "N", 4 * (a - b));+ a = b;+ }+ o[-1] = 0;+ printf("%s\n", out);+ return 1;+ }+ uint64_t k = key_of();+ uint32_t h = (uint32_t)(k % SEEN);+ while (seen[h] && seen[h] != k) h = (h + 1) % SEEN;+ if (seen[h]) continue;+ seen[h] = k;+ struct node *nd = &nodes[n];+ take(&nd->s), nd->parent = at, nd->in = moves[m], nd->depth = nodes[at].depth + 1;+ nd->f = nd->depth + 3 * door_dist() / 70;+ push(n++);+ }+ }+ printf("no way found (%d states)\n", n);+ return 0;+}++int main(int argc, char **argv) {+ char path[256];+ read_solutions();+ if (!strcmp(argc > 1 ? argv[1] : "", "check") && argc > 5) { /* do these keys clear the room? */+ int i = (atoi(argv[2]) - 1) * ROOMS + atoi(argv[3]) - 1;+ setup(i / ROOMS, i % ROOMS, atoi(argv[4]));+ int ok = run(argv[5], 0) == 1;+ printf(ok ? "ok\n" : "no\n");+ return !ok;+ }+ if (!strcmp(argc > 1 ? argv[1] : "", "search") && argc > 3)+ return !search((atoi(argv[2]) - 1) * ROOMS + atoi(argv[3]) - 1, argc > 4 ? atoi(argv[4]) : 0);+ if (!strcmp(argc > 1 ? argv[1] : "", "trace") && argc > 3) { /* where the runner goes with the solution */+ int i = (atoi(argv[2]) - 1) * ROOMS + atoi(argv[3]) - 1;+ setup(i / ROOMS, i % ROOMS, argc > 4 ? atoi(argv[4]) : 0);+ const char *s = solutions[i][argc > 4 ? atoi(argv[4]) & 3 : 0];+ for (int t = 0;; t++) {+ while (*s == ' ') s++;+ if (!*s) break;+ int in = 0;+ for (; *s >= 'A' && *s <= 'Z'; s++) in |= *s == 'L' ? I_LEFT : *s == 'R' ? I_RIGHT : *s == 'J' ? I_JUMP : 0;+ for (int n = (int)strtol(s, (char **)&s, 10); n--; t++) {+ step(in);+ if (!(t % 4) || dead || won) printf("%4d x %4.1f y %4.1f %s%s%s\n", t, px / 256.0, py / 256.0, ground ? "ground" : "",+ dead ? " DEAD" : "", won ? " DOOR" : "");+ if (dead || won) return 0;+ }+ }+ return 0;+ }+ if (argc < 2) return 2;+ if (!strcmp(argv[1], "rooms") && argc > 2) {+ for (int i = 0; i < ROOM_COUNT; i++) {+ setup(i / ROOMS, i % ROOMS, 0);+ draw();+ snprintf(path, sizeof path, "%s/room_%02d_%d.ppm", argv[2], i / ROOMS + 1, i % ROOMS + 1);+ picture(path);+ }+ return 0;+ }+ if (!strcmp(argv[1], "film") && argc > 4) {+ int i = (atoi(argv[2]) - 1) * ROOMS + atoi(argv[3]) - 1;+ if (i < 0 || i >= ROOM_COUNT) return 2;+ setup(i / ROOMS, i % ROOMS, argc > 5 ? atoi(argv[5]) : 0);+ return run(solutions[i][argc > 5 ? atoi(argv[5]) & 3 : 0], argv[4]) == 1 ? 0 : 1;+ }+ if (!strcmp(argv[1], "solve")) {+ int bad = 0;+ for (int i = 0; i < ROOM_COUNT; i++)+ for (int t = 0; t < 4; t++) { /* as it starts, then after 1, 2 and 3 deaths */+ setup(i / ROOMS, i % ROOMS, t);+ int got = run(solutions[i][t], 0);+ if (got != 1) {+ printf("level %d room %d (after %d deaths): %s at x %d y %d\n", i / ROOMS + 1, i % ROOMS + 1, t,+ got ? "stuck" : "dead", (int)(px >> 8), (int)(py >> 8));+ bad = 1;+ break;+ }+ }+ if (bad) printf("some rooms fail\n");+ else printf("all %d rooms solved\n", ROOM_COUNT);+ return bad;+ }+ return 2;+}diff --git a/games/leveldevil/tests/solutions.txt b/games/leveldevil/tests/solutions.txtnew file mode 100644index 00000000..c5d8f451--- /dev/null+++ b/games/leveldevil/tests/solutions.txt@@ -0,0 +1,82 @@+# The keys that clear each room (tests/play.c): "R40 RJ12 R30", the keys held, L R J or N for+# none, for so many steps; " | " between the keys for each number of deaths when the room changes.+1-1: R80 RJ4 R36 | R92 RJ8 R12 RJ4 R4+1-2: R36 RJ4 R44 RJ4 R32+1-3: R16 RJ4 R16 RJ4 R12 RJ4 R20 RJ4 R16 RJ4 R20+1-4: R28 RJ4 R24 RJ4 R20 RJ4 R16 RJ4 R16+1-5: R92 LJ4 R16+2-1: R92 RJ8 R12 RJ4 R4+2-2: R52 RJ4 R64+2-3: R12 RJ8 R16 RJ4 R20 RJ8 R12 RJ8 R32+2-4: R40 RJ4 J4 R20 RJ4 R48+2-5: R96 RJ4 R20+3-1: R52 RJ12 R20 RJ4 R32+3-2: R56 RJ8 R44+3-3: R60 RJ4 R56+3-4: R40 RJ4 R32 RJ8 R12 RJ4 R20+3-5: R40 RJ4 R32 RJ8 R12 RJ4 R20+4-1: R68 RJ4 L4 LJ8 L12 LJ8 N4 L32+4-2: R88 RJ4 R8 RJ4 R4+4-3: R32 RJ12 R76+4-4: N150 R32 RJ16 R30+4-5: R72 RJ4 J4 RJ8 N4 L4 LJ4 L4 N4 L12 LJ4 J4 L8 N4 L40+5-1: L48 LJ8 N4 L56 R4+5-2: R48 L12 LJ8 N4 L44 R4+5-3: L40 RJ4 J4 RJ4 R68+5-4: L36 LJ8 N4 L36 LJ4 L28 R4+5-5: R24 L12 LJ4 L20 R12 RJ4 R16 L8 LJ4 L12 R4+6-1: R44 RJ8 R12 RJ4 R52+6-2: R120+6-3: R100 RJ4 R16+6-4: R24 RJ4 R56 RJ4 R8 RJ4 R20+6-5: R16 RJ4 R20 RJ4 R20 LJ4 R8 N8 R12 RJ16 R8 RJ4 R8+7-1: RJ8 J4 RJ4 R4 RJ4 R4 RJ16 R4 L4 RJ24 R44+7-2: R68 RJ4 R48+7-3: R24 RJ8 R20 L8 RJ8 R20 N12 R4 RJ4 R28+7-4: RJ12 R12 J4 RJ12 R8 RJ16 R4 RJ28 R24+7-5: RJ4 R12 RJ8 J4 R8 N4 RJ20 R16 RJ8 R36+8-1: R60+8-2: R12 RJ4 R4 RJ4 R12+8-3: R28 RJ16 R32+8-4: RJ4 R44+8-5: R32 RJ4 R12 RJ4 R8+9-1: R40 RJ4 J4 R4 RJ16 R68+9-2: R28 RJ8 L4 J4 L4 J4 RJ4 R40 RJ4 R40+9-3: R32 L4 R92+9-4: R16 LJ8 R20 RJ4 J4 LJ4 R28 N4 RJ4 N4 J4 R24 LJ4 L4 R36+9-5: R24 RJ4 J4 RJ8 R24 L4 R60+10-1: R68 RJ8 R12 RJ4 R28+10-2: R60 RJ8 J4 R48+10-3: R72 L4 N4 J4 R20 RJ8 R12 RJ4 R4+10-4: R28 J4 N12 R24 RJ4 J4 N4 L4 N4 R28 LJ4 N4 R4 LJ4 N4 R28+10-5: R20 RJ4 R48 RJ4 LJ4 R40+11-1: R32 RJ4 R32 RJ4 R36+11-2: R44 RJ4 R72+11-3: RJ12 N4 J4 R4 LJ4 RJ12 R4 RJ8 R12 RJ12 R4 RJ8 R12 RJ16 R20+11-4: RJ8 J4 R12 RJ16 R8+11-5: R20 RJ4 R16 RJ4 R12 RJ4 R12 RJ4 R12 RJ4 R24+12-1: R16 RJ4 J4 N4 J4 R4 RJ8 N4 RJ8 R72+12-2: R36 RJ4 R12 RJ4 R12 RJ4 R12 RJ4 R32+12-3: R36 RJ4 R12 RJ4 R12 J4 L4 RJ16 R12 RJ4 R16+12-4: RJ12 N4 RJ12 N4 RJ12 R4 RJ8 R16+12-5: R16 RJ4 R12 RJ4 N8 R4 RJ4 R12 RJ4 R12 RJ4 R12 RJ4 R20+13-1: RJ4 R8 N4 R32 RJ4 R12 RJ4 R12 RJ4 R12 RJ4 R12 RJ4 R4+13-2: RJ4 R8 N4 R4 RJ4 R24 N4 RJ12 R8 J4 R44+13-3: R40 J4 LJ4 N4 R4 RJ12 R12 RJ4 R8 RJ4 R36+13-4: R28 RJ4 R4 LJ4 R4 J4 RJ4 J4 R28 RJ4 R36+13-5: R28 J4 LJ4 RJ4 R4 RJ4 R20 RJ8 R16 RJ4 R12 RJ4 R16+14-1: RJ4 R84 RJ8 R24+14-2: RJ4 R28 RJ4 R28 RJ4 R24 RJ4 R24+14-3: R76 RJ8 R12 RJ4 R20+14-4: RJ4 R48 RJ4 R32 RJ4 R28+14-5: RJ4 R60 RJ8 R32 RJ4 R12+15-1: LJ4 J4 L20 R4+15-2: RJ16 R20 N4 LJ4 L4 LJ8 RJ12 R12+15-3: RJ4 R12 RJ8 R4 RJ4 R4 RJ8 R8 RJ4 R4 RJ4 R4 RJ12 R24+15-4: L32+15-5: LJ12 L4 LJ4 J4 L4 LJ4 N4 L36 R4+16-1: R36 RJ8 R40 RJ8 R12 RJ4 R4+16-2: LJ4 L4 N4 LJ4 L4 N4 L4 N4 L4 N4 L8 LJ4 L8 R4 LJ12 L4 N4 L4 LJ4 L12 LJ4 N4 L4 R4 LJ4 R4+16-3: RJ4 R84 RJ8 R24+16-4: R24 RJ4 R20 RJ4 R8 RJ4 R12+16-5: R32 RJ4 L4 R8 LJ16 L56diff --git a/games/leveldevil/tools/rooms.py b/games/leveldevil/tools/rooms.pynew file mode 100644index 00000000..74853fda--- /dev/null+++ b/games/leveldevil/tools/rooms.py@@ -0,0 +1,409 @@+#!/usr/bin/env python3+"""Level Devil's rooms: sixteen levels of five, and how to clear each one.++Writes OUT/rooms.inc, the rooms packed (raw DEFLATE) for src/main.c, which unpacks them when the+game starts. The format is described in src/main.c; the numbers below (kinds, flags, triggers,+motions, modes) follow it. tests/solutions.txt has the keys that clear each room.++The room is 160 x 120 pixels of the game: the ceiling is the top 10 rows, the side walls 4 wide,+and most floors are at 100. The runner is 5 x 7 and starts at x 14 on the floor. It runs a+little over a pixel a step and jumps about 20 high and 30 across (60 steps a second).+++Usage: rooms.py OUT+"""+import os+import sys+import zlib++# kinds, flags, triggers, motions, modes (src/main.c)+BLOCK, SECRET, SPIKE_U, SPIKE_D, SPIKE_L, SPIKE_R, DOOR, SAW, SPRING, WARP, SWITCH, BUTTON = range(12)+HIDDEN, VANISH, GHOST, TRAP = 0x10, 0x20, 0x40, 0x80+START, RIGHT, LEFT, UP, DOWN, TOUCH, AFTER, NEAR = range(8)+ONCE, LOOP, CHASE, FALL = range(4)+BACK, ICE, AIR, FLIP, WRAP = 1, 2, 4, 8, 16+SPEEDS = [0, 2, 4, 6, 8, 12, 16, 20, 24, 32, 40, 48, 64, 80, 96, 128] # 16ths of a pixel a step+FLOOR_Y = 100+++class Obj:+ def __init__(self, kind, x, y, w, h, flags=0, trap=None):+ self.kind, self.x, self.y, self.w, self.h, self.flags, self.trap = kind, x, y, w, h, flags, trap+++def trap(when=START, at=0, does=ONCE, dx=0, dy=0, speed=0, delay=0, after=0, before=0):+ """What sets it off (when, at), how many deaths it waits for (after: there from death n on;+ before: there until death n), what it does: dx, dy at speed (pixels a step; 0 at once),+ delay in steps (rounded to fours)."""+ s = min(range(16), key=lambda i: abs(SPEEDS[i] - speed * 16)) if speed else 0+ gate = after if after else (before + 4 if before else 0)+ return dict(when=when, at=at, does=does, dx=dx, dy=dy, speed=s, delay=(delay + 3) // 4, gate=gate)+++# the usual traps+def falls(at, **k):+ """drops away once the runner's right side passes x = at"""+ return trap(RIGHT, at, FALL, **k)+++def pops(at, dy=-5, **k):+ """spikes out of the floor (or of whatever hides them) once the runner passes x = at"""+ return trap(RIGHT, at, ONCE, dy=dy, speed=4, **k)+++def block(x, y, w, h, trap=None, flags=0):+ return Obj(BLOCK, x, y, w, h, flags, trap)+++def floor(x, w, y=FLOOR_Y, **k):+ return block(x, y, w, 120 - y, **k)+++def spikes(x, y, n, side="u", trap=None, flags=0):+ """n teeth (5 pixels each) on a floor (u, pointing up), under a ceiling (d), on a wall (l: on its+ left side, pointing left; r: on its right side, pointing right)"""+ kind = {"u": SPIKE_U, "d": SPIKE_D, "l": SPIKE_L, "r": SPIKE_R}[side]+ w, h = (5 * n, 5) if side in "ud" else (5, 5 * n)+ return Obj(kind, x, y, w, h, flags, trap)+++def door(x, y=FLOOR_Y - 20, trap=None, fake=False, hanging=False, flags=0):+ return Obj(DOOR, x, y, 11, 1 if hanging else 20, flags | (GHOST if fake else 0), trap)+++def saw(x, y, size, trap=None, flags=0):+ """a saw of that size, its top-left at (x, y)"""+ return Obj(SAW, x, y, size, size, flags, trap)+++def spring(x, y=FLOOR_Y - 3, w=8, trap=None, flags=0):+ return Obj(SPRING, x, y, w, 3, flags, trap)+++def warp(a, b, trap=None, flags=0):+ """two ends, 8 x 12 each, their top-left corners"""+ return Obj(WARP, a[0], a[1], b[0], b[1], flags, trap)+++def switch(x, y, w, h, toggles, when=RIGHT, at=0, **k):+ """an invisible line that toggles modes once"""+ t = trap(when, at, ONCE, **k)+ t["dx"] = toggles+ return Obj(SWITCH, x, y, w, h, 0, t)+++def button(x, toggles, y=FLOOR_Y - 2, w=8, ceiling=False):+ """a button on the floor (or under a ceiling, y its top) that toggles modes each time it is touched"""+ t = trap(TOUCH, 0, ONCE)+ t["dx"] = toggles+ return Obj(BUTTON, x, y, w, 2, GHOST if ceiling else 0, t)+++ROOMS = [] # (modes, start, objects)+++def room(objs, modes=0, start=(14, FLOOR_Y)):+ ROOMS.append((modes, start, objs))+++def chain(objs, first, delay, does=FALL, **k):+ """each object's trap goes off a while after the one before it; the first one's when the runner+ passes x = first"""+ for i, o in enumerate(objs):+ o.trap = trap(AFTER if i else RIGHT, objs[i - 1] if i else first, does, delay=delay if i else 0, **k)+ return objs+++def popping(x, n, at, y=FLOOR_Y, **k):+ """spikes hidden in the floor at y, out once the runner passes x = at"""+ return spikes(x, y, n, trap=pops(at, **k))+++def always(**k):+ """no trap, but there only after (or before) so many deaths"""+ return trap(START, 0, ONCE, **k)+++DOOR_X = 140 # where most doors are, at the end of the floor++# ------------------------------------------------------------------ 1: the floor drops away+# the floor in front of the door drops; after a death it holds, and spikes come up where the runner lands+room([floor(0, 96), floor(96, 24, trap=falls(88, before=1)), floor(96, 24, trap=always(after=1)),+ popping(120, 3, 92, after=1), floor(120, 40), door(DOOR_X)])+room([floor(0, 50), floor(50, 22, trap=falls(44)), floor(72, 30), floor(102, 22, trap=falls(96)), floor(124, 36),+ door(DOOR_X)])+# the floor behind the runner drops away, a piece after the other: no stopping+room([floor(0, 24)] + chain([floor(24 + 20 * i, 20) for i in range(5)], 30, 18) + [floor(124, 36), door(DOOR_X)])+# stepping stones over a pit, dropping soon after they are stepped on+room([floor(0, 40)] + [block(52 + 30 * i, 100, 16, 6, trap=trap(TOUCH, 0, FALL, delay=14)) for i in range(3)]+ + [floor(140, 20), door(144)])+# the door's own floor drops when the runner comes near: jump into the door from afar+room([floor(0, 100), block(100, 100, 60, 20, trap=trap(NEAR, 22, FALL)), door(130, trap=trap(NEAR, 18, FALL))])++# ------------------------------------------------------------------ 2: spikes+# spikes come up in front of the door+room([floor(0, 160), popping(118, 3, 104), door(DOOR_X)])+# a low ceiling, whose spikes drop when the runner jumps: hop low over the spikes on the floor+room([floor(0, 160), block(50, 10, 60, 58), spikes(50, 63, 12, "d", trap=trap(UP, 90, ONCE, dy=5, speed=4)),+ spikes(76, 95, 2), door(DOOR_X)])+# spike pits, and more spikes come up where a long jump would land+room([floor(0, 160), spikes(30, 95, 3), popping(57, 2, 34), spikes(85, 95, 3), popping(112, 2, 89), door(DOOR_X)])+# a step: spikes come out of its side as the runner nears it, then out of its top+room([floor(0, 160), block(70, 84, 40, 16), spikes(70, 84, 3, "l", trap=trap(RIGHT, 56, ONCE, dx=-5, speed=4)),+ popping(90, 2, 78, y=84), door(DOOR_X)])+# spikes come up behind the runner, one after another, and in front of the door+room([floor(0, 160)] + chain([spikes(30 + 15 * i, 100, 3) for i in range(6)], 50, 14, does=ONCE, dy=-5, speed=4)+ + [popping(122, 2, 112), door(DOOR_X)])++# ------------------------------------------------------------------ 3: walls+# over the gap, a pillar comes up out of the floor where the runner would land+room([floor(0, 70), floor(80, 80), block(86, 100, 8, 20, trap=trap(RIGHT, 64, ONCE, dy=-16, speed=3)), door(DOOR_X)])+# a wall slides out of the right wall at the runner: jump it+room([floor(0, 160), block(148, 86, 12, 14, trap=trap(RIGHT, 40, ONCE, dx=-110, speed=1.5)), door(128)])+# a wall comes down from the ceiling, low enough to walk under but not to jump; then a crusher+room([floor(0, 160), block(66, 10, 14, 60, trap=trap(RIGHT, 50, ONCE, dy=22, speed=3)),+ block(100, 10, 14, 30, trap=trap(RIGHT, 76, LOOP, dy=60, speed=3)), door(DOOR_X)])+# the ceiling comes down on the whole room: hurry+room([floor(0, 160), block(4, 10, 152, 10, trap=trap(RIGHT, 20, ONCE, dy=78, speed=0.5)), spikes(60, 95, 2),+ spikes(100, 95, 3), door(DOOR_X)])+# the left wall comes after the runner+room([floor(0, 160), block(0, 10, 8, 90, trap=trap(RIGHT, 22, ONCE, dx=124, speed=1)), spikes(60, 95, 2),+ spikes(100, 95, 3), door(DOOR_X)])++# ------------------------------------------------------------------ 4: the door+# the door goes behind the runner, and spikes come up between+d = door(120, trap=trap(NEAR, 30, ONCE, dx=-96))+room([floor(0, 160), d, spikes(60, 100, 3, trap=trap(AFTER, d, ONCE, dy=-5, speed=4))])+# the door rises out of reach on a pillar: a ledge left behind helps+room([floor(0, 160), block(120, 100, 30, 20, trap=trap(NEAR, 26, ONCE, dy=-26, speed=1)),+ door(130, trap=trap(NEAR, 26, ONCE, dy=-26, speed=1)), block(76, 84, 20, 4)])+# a fake door: spikes under it; the real one shows up at the end+s = spikes(52, 100, 4, trap=trap(NEAR, 14, ONCE, dy=-5, speed=4))+room([floor(0, 160), door(56, fake=True), s, door(DOOR_X, flags=HIDDEN, trap=trap(AFTER, s, ONCE))])+# the door rides back and forth on a platform over a pit of spikes+room([floor(0, 44), block(48, 112, 108, 8), spikes(48, 107, 21),+ block(60, 94, 24, 4, trap=trap(START, 0, LOOP, dx=60, speed=0.5)),+ door(70, y=74, trap=trap(START, 0, LOOP, dx=60, speed=0.5))])+# the door jumps to the start, and the floor between drops away+d = door(130, trap=trap(NEAR, 22, ONCE, dx=-110))+room([floor(0, 70), floor(70, 26, trap=trap(AFTER, d, FALL, delay=8)), floor(96, 64), d])++# ------------------------------------------------------------------ 5: backwards+room([floor(0, 160), spikes(70, 95, 3), door(DOOR_X)], modes=BACK)+# the keys turn round halfway+room([floor(0, 160), switch(0, 0, 0, 0, BACK, at=66), spikes(84, 95, 3), door(DOOR_X)])+# back to front, and the right way round again in the middle of a jump+room([floor(0, 56), floor(84, 76), switch(0, 0, 0, 0, BACK, when=UP, at=90), door(DOOR_X)], modes=BACK)+# back to front over dropping floors+room([floor(0, 50), floor(50, 24, trap=falls(46)), floor(74, 26), floor(100, 24, trap=falls(96)), floor(124, 36),+ door(DOOR_X)], modes=BACK)+# the keys turn round, again and again+room([floor(0, 160), switch(0, 0, 0, 0, BACK, at=40), spikes(56, 95, 2), switch(0, 0, 0, 0, BACK, at=80),+ spikes(96, 95, 2), switch(0, 0, 0, 0, BACK, at=116), popping(126, 2, 116), door(DOOR_X)])++# ------------------------------------------------------------------ 6: fake ground+# a piece of floor that isn't there+room([floor(0, 60), floor(60, 26, flags=GHOST), floor(86, 74), door(DOOR_X)])+# no floor, but there is one: an invisible bridge; the platform over it is the fake+room([floor(0, 40), block(44, 112, 76, 8), spikes(44, 107, 15)] + [Obj(SECRET, 40 + 20 * i, 100, 20, 4) for i in range(4)]+ + [block(62, 76, 36, 4, flags=GHOST), floor(120, 40), door(DOOR_X)])+# a wall to the ceiling: it isn't there, but the pit behind it is+room([floor(0, 120), block(110, 10, 10, 90, flags=GHOST), floor(136, 24), door(DOOR_X)])+# floors, real and fake, side by side+room([floor(0, 40), floor(40, 20, flags=GHOST), floor(60, 20), floor(80, 20), floor(100, 20, flags=GHOST),+ floor(120, 40), door(DOOR_X)])+# platforms that vanish once stepped on, and the last one is fake+room([floor(0, 30), block(34, 112, 106, 8), spikes(34, 107, 21)]+ + [block(40 + 24 * i, 96, 14, 4, trap=trap(TOUCH, 0, ONCE, delay=10), flags=VANISH) for i in range(3)]+ + [block(112, 96, 14, 4, flags=GHOST), floor(140, 20), door(144)])++# ------------------------------------------------------------------ 7: springs+room([floor(0, 160), spring(60), block(100, 58, 56, 42), door(140, y=38)])+# a spring comes out under the runner, into the spikes on the ceiling+room([floor(0, 160), spring(70, flags=HIDDEN, trap=trap(RIGHT, 72)), block(56, 10, 40, 30), spikes(56, 40, 8, "d"),+ door(DOOR_X)])+# from spring to spring over the spikes+room([floor(0, 40), block(40, 108, 80, 12), spikes(40, 103, 16), block(62, 96, 10, 12), spring(63, y=93),+ block(96, 96, 10, 12), spring(97, y=93), floor(120, 40), door(DOOR_X)])+# the spring slides away as the runner comes+room([floor(0, 40), block(40, 108, 116, 12), spikes(40, 103, 23), block(56, 96, 40, 12),+ spring(60, y=93, trap=trap(NEAR, 12, ONCE, dx=26, speed=2)), block(120, 50, 36, 8), door(140, y=30)])+# up a spring, between the spikes of the ceiling+room([floor(0, 160), spring(46), spikes(30, 10, 3, "d"), spikes(60, 10, 8, "d"), block(84, 56, 72, 6),+ popping(100, 3, 100, y=56), door(DOOR_X, y=36)])++# ------------------------------------------------------------------ 8: warps+room([floor(0, 160), block(76, 10, 8, 90), warp((50, 88), (110, 88)), door(DOOR_X)])+# the warp moves as the runner comes+room([floor(0, 160), block(76, 10, 8, 90), warp((40, 88), (126, 88), trap=trap(NEAR, 10, ONCE, dx=16, speed=2)),+ spikes(30, 95, 2), door(DOOR_X)])+# out of the warp over spikes: keep running+room([floor(0, 160), block(56, 10, 8, 90), warp((30, 88), (70, 66)), block(66, 78, 20, 4), spikes(64, 95, 12),+ door(DOOR_X)])+# a warp comes up behind the runner over the gap, and takes it back to the start+room([floor(0, 60), floor(84, 76), warp((90, 76), (14, 88), flags=HIDDEN, trap=trap(UP, 90, ONCE)), door(DOOR_X)])+# warps, up and down+room([floor(0, 160), block(50, 10, 6, 90), block(104, 10, 6, 90), block(56, 52, 22, 4), block(84, 52, 20, 4),+ spikes(56, 95, 10), warp((36, 88), (62, 40)), warp((92, 40), (120, 88)), door(DOOR_X)])++# ------------------------------------------------------------------ 9: crushers+room([floor(0, 160), block(70, 10, 20, 30, trap=trap(RIGHT, 50, LOOP, dy=60, speed=2)), door(DOOR_X)])+# a piece of the ceiling falls as the runner passes+room([floor(0, 160), block(60, 10, 30, 14, trap=trap(RIGHT, 58, ONCE, dy=76, speed=4)), spikes(100, 95, 2),+ door(DOOR_X)])+# two crushers out of step+room([floor(0, 160), block(54, 10, 18, 30, trap=trap(RIGHT, 26, LOOP, dy=60, speed=2)),+ block(96, 10, 18, 30, trap=trap(RIGHT, 26, LOOP, dy=60, speed=2, delay=20)), door(DOOR_X)])+# pieces of the ceiling fall as the runner comes near: wait for each one+room([floor(0, 160)] + [block(36 + 26 * i, 10, 16, 14, trap=trap(NEAR, 28, FALL)) for i in range(4)] + [door(DOOR_X)])+# crushers over dropping floors+room([floor(0, 40), floor(40, 30, trap=falls(36)), floor(70, 90),+ block(90, 10, 16, 30, trap=trap(START, 0, LOOP, dy=60, speed=2.5)), door(DOOR_X)])++# ------------------------------------------------------------------ 10: saws+room([floor(0, 160), saw(50, 86, 14, trap=trap(START, 0, LOOP, dx=60, speed=1)), door(DOOR_X)])+# a saw comes up out of the floor+room([floor(0, 160), saw(84, 100, 16, trap=trap(RIGHT, 70, ONCE, dy=-12, speed=3)), door(DOOR_X)])+# a saw drops from the ceiling+room([floor(0, 160), saw(96, 10, 16, trap=trap(RIGHT, 84, FALL)), spikes(120, 95, 2), door(DOOR_X)])+# saws up and down+room([floor(0, 160), saw(50, 20, 14, trap=trap(START, 0, LOOP, dy=66, speed=1.5)),+ saw(84, 86, 14, trap=trap(START, 0, LOOP, dy=-66, speed=1.5)),+ saw(118, 20, 14, trap=trap(START, 0, LOOP, dy=66, speed=1.5)), door(DOOR_X)])+# the saw in the door's way follows it+room([floor(0, 160), saw(110, 84, 16, trap=trap(NEAR, 30, ONCE, dx=-40, speed=1.5)), spikes(40, 95, 2), door(DOOR_X)])++# ------------------------------------------------------------------ 11: chase+room([floor(0, 160), saw(0, 84, 16, trap=trap(RIGHT, 40, CHASE, dx=1, speed=0.9)), spikes(64, 95, 2),+ spikes(104, 95, 2), door(DOOR_X)], start=(26, FLOOR_Y))+# a wall of spikes+room([block(0, 10, 6, 90, trap=trap(RIGHT, 30, ONCE, dx=124, speed=1)),+ spikes(6, 10, 18, "r", trap=trap(RIGHT, 30, ONCE, dx=124, speed=1)), floor(60, 20, trap=falls(56)),+ floor(0, 60), floor(80, 80), door(DOOR_X)])+# a saw that follows the runner everywhere, slowly+room([floor(0, 160), block(40, 84, 30, 16), block(80, 68, 30, 32), block(120, 52, 36, 48),+ saw(10, 20, 14, trap=trap(START, 0, CHASE, dx=1, dy=1, speed=0.5, delay=20)), door(140, y=32)])+# saws from both sides+room([floor(0, 160), saw(0, 86, 14, trap=trap(RIGHT, 40, CHASE, dx=1, speed=0.7)),+ saw(146, 86, 14, trap=trap(RIGHT, 40, CHASE, dx=1, speed=0.7)), block(70, 82, 20, 4), door(75, y=62)],+ start=(26, FLOOR_Y))+# chased over dropping floors+room([floor(0, 30), saw(0, 84, 16, trap=trap(RIGHT, 36, CHASE, dx=1, speed=0.9))]+ + chain([floor(30 + 20 * i, 20) for i in range(5)], 44, 16) + [floor(130, 30), door(DOOR_X)], start=(22, FLOOR_Y))++# ------------------------------------------------------------------ 12: jumps in the air+room([floor(0, 160), block(70, 40, 12, 60), door(DOOR_X)], modes=AIR)+# careful: spikes on the ceiling+room([floor(0, 50), block(54, 112, 70, 8), spikes(54, 107, 14), floor(124, 36), spikes(40, 10, 18, "d"), door(DOOR_X)],+ modes=AIR)+# the jumps in the air stop over the pit+room([floor(0, 50), block(54, 112, 70, 8), spikes(54, 107, 14), floor(124, 36),+ switch(0, 0, 0, 0, AIR, at=96), door(DOOR_X)], modes=AIR)+# up a tower with spikes on its side, under spikes on the ceiling+room([floor(0, 160), block(70, 34, 30, 66), spikes(65, 44, 10, "l"), spikes(20, 10, 9, "d"), door(80, y=14)],+ modes=AIR)+# a wide pit, saws in the air+room([floor(0, 30), block(30, 112, 100, 8), spikes(30, 107, 20), floor(130, 30),+ saw(60, 40, 14, trap=trap(START, 0, LOOP, dy=40, speed=1)), saw(96, 70, 14, trap=trap(START, 0, LOOP, dy=-40, speed=1)),+ door(DOOR_X)], modes=AIR)++# ------------------------------------------------------------------ 13: gravity+room([floor(0, 40), block(40, 104, 116, 16), spikes(40, 99, 23), button(20, FLIP), door(140, y=10, hanging=True)])+# buttons on the floor and on the ceiling+room([floor(0, 40), block(40, 104, 60, 16), spikes(40, 99, 12), floor(100, 60), button(20, FLIP),+ spikes(52, 10, 3, "d"), button(84, FLIP, y=10, ceiling=True), spikes(100, 10, 6, "d"), door(DOOR_X)])+# gravity flips as the runner passes under the spikes+room([floor(0, 160), spikes(60, 10, 8, "d"), switch(0, 0, 0, 0, FLIP, at=64), switch(0, 0, 0, 0, FLIP, at=106),+ door(DOOR_X)])+# a jump flips gravity+room([floor(0, 160), switch(0, 0, 0, 0, FLIP, when=UP, at=92), spikes(50, 95, 3), spikes(74, 10, 5, "d"),+ button(58, FLIP, y=10, ceiling=True), door(DOOR_X)])+# up and down over the spikes, the door on the ceiling+room([floor(0, 30), block(30, 104, 126, 16), spikes(30, 99, 25), button(16, FLIP), block(50, 10, 20, 16),+ spikes(70, 10, 6, "d"), button(56, FLIP, y=26, ceiling=True), block(100, 50, 24, 4), door(140, y=10, hanging=True)])++# ------------------------------------------------------------------ 14: ice+room([floor(0, 100), block(100, 112, 30, 8), spikes(100, 107, 6), floor(130, 30), door(DOOR_X)], modes=ICE)+room([floor(0, 40), block(40, 112, 116, 8), spikes(40, 107, 23), block(60, 100, 14, 4), block(94, 100, 14, 4),+ floor(130, 30), door(DOOR_X)], modes=ICE)+# the floor turns to ice before the spikes+room([floor(0, 160), switch(0, 0, 0, 0, ICE, at=60), spikes(100, 95, 3), door(DOOR_X)])+room([floor(0, 50), floor(50, 30, trap=falls(60)), floor(80, 80), spikes(110, 95, 2), door(DOOR_X)], modes=ICE)+room([floor(0, 160), saw(60, 86, 14, trap=trap(START, 0, LOOP, dx=50, speed=1)), spikes(130, 95, 1), door(DOOR_X)],+ modes=ICE)++# ------------------------------------------------------------------ 15: round the edges+room([floor(0, 160), block(120, 10, 8, 90), door(DOOR_X)], modes=WRAP)+room([floor(0, 50), floor(110, 50), block(90, 10, 8, 90), door(60, y=60), block(50, 80, 30, 4)], modes=WRAP)+room([floor(0, 160), popping(140, 4, 120), block(30, 10, 8, 90), door(10)], modes=WRAP, start=(60, FLOOR_Y))+room([floor(0, 160), saw(110, 84, 16, trap=trap(LEFT, 60, CHASE, dx=1, speed=0.9)), block(4, 10, 10, 90),+ door(20)], modes=WRAP, start=(60, FLOOR_Y))+# a wall in the way, and a pit at the other edge: jump through the edge+room([floor(0, 50), block(50, 10, 6, 90), floor(56, 84), block(140, 112, 20, 8), spikes(140, 107, 4), door(100)],+ modes=WRAP, start=(24, FLOOR_Y))++# ------------------------------------------------------------------ 16: the Devil+room([floor(0, 50), floor(50, 24, trap=falls(44)), floor(74, 86), popping(110, 3, 100),+ door(DOOR_X, trap=trap(NEAR, 18, ONCE, dx=-16, speed=2))])+room([floor(0, 40), block(40, 104, 116, 16), spikes(40, 99, 23), button(20, FLIP), spikes(80, 10, 4, "d"),+ door(140, y=10, hanging=True)], modes=BACK)+room([floor(0, 160), block(60, 10, 20, 30, trap=trap(START, 0, LOOP, dy=60, speed=2)),+ saw(100, 86, 14, trap=trap(START, 0, LOOP, dx=26, speed=1)), door(DOOR_X)], modes=ICE)+room([floor(0, 40), floor(40, 20, flags=GHOST), floor(60, 100), block(90, 10, 8, 90), warp((70, 88), (110, 88)),+ popping(112, 2, 100), door(DOOR_X)])+s = spikes(66, 100, 5, trap=trap(NEAR, 16, ONCE, dy=-5, speed=4))+room([floor(0, 160), door(70, fake=True), s, switch(0, 0, 0, 0, BACK, when=AFTER, at=s),+ door(DOOR_X, flags=HIDDEN, trap=trap(AFTER, s, ONCE))])+++def pack_trap(t, index):+ at = t["at"]+ if isinstance(at, Obj):+ at = index[id(at)]+ return [t["when"] | t["gate"] << 3 | t["does"] << 6, at & 255, t["dx"] & 255, t["dy"] & 255,+ t["speed"] | t["delay"] << 4]+++def pack(modes, start, objs):+ out = [modes, start[0], start[1], len(objs)]+ index = {id(o): i for i, o in enumerate(objs)}+ for o in objs:+ for v in (o.x, o.y, o.w, o.h):+ assert 0 <= v < 256, (o.kind, o.x, o.y, o.w, o.h)+ out += [o.kind | o.flags | (TRAP if o.trap else 0), o.x, o.y, o.w, o.h]+ if o.trap:+ out += pack_trap(o.trap, index)+ return out+++def main():+ out = sys.argv[1]+ os.makedirs(out, exist_ok=True)+ data = []+ for modes, start, objs in ROOMS:+ assert len(objs) <= 28, "a room has 28 objects at most"+ data += pack(modes, start, objs)+ raw = bytes(data)+ c = zlib.compressobj(9, zlib.DEFLATED, -15, 9)+ z = c.compress(raw) + c.flush()+ try: # smaller still with zopfli, as tools/shots.py does (the zlib stream without its header and check)+ import zopfli.zlib+ z2 = zopfli.zlib.compress(raw, numiterations=60)[2:-4]+ if len(z2) < len(z):+ z = z2+ except ImportError:+ pass+ assert zlib.decompress(z, -15) == raw+ with open(os.path.join(out, "rooms.inc"), "w") as f:+ f.write(f"/* Made by tools/rooms.py: {len(ROOMS)} rooms, {len(raw)} bytes packed into {len(z)} */\n")+ f.write(f"#define ROOM_BYTES {len(raw)}\n")+ f.write(f"#define ROOM_COUNT {len(ROOMS)}\n")+ f.write(f"static const uint8_t rooms_z[{len(z)}] = {{\n")+ for i in range(0, len(z), 24):+ f.write(" " + ",".join(str(b) for b in z[i:i + 24]) + ",\n")+ f.write("};\n")+ print(f"rooms: {len(ROOMS)}, {len(raw)} bytes, packed {len(z)}")+++if __name__ == "__main__":+ main()diff --git a/launcher/lang/fr.txt b/launcher/lang/fr.txtindex 28fd6d58..a482cd49 100644--- a/launcher/lang/fr.txt+++ b/launcher/lang/fr.txt@@ -96,18 +96,21 @@ Clear the field, flag the mines Déblaie le terrain, pose les drapeauxBlock Breaker Casse-briquesBreak every brick Casse toutes les briquesBackgrounds, clocks, timers Fonds, horloges, minuteurs+Reach the door, trust nothing Atteins la porte, ne te fie à rien# (names that stay as they are)NumDash NumDashNumBlocks NumBlocksNumDrive NumDrive2048 2048NumVisuals NumVisuals+Level Devil Level Devil# the games' creditsInspired by Minecraft, not affiliated with Mojang Inspiré de Minecraft, sans lien avec MojangBy Tatone26, from All the Apps Par Tatone26, tiré d'All the AppsInspired by Tatone26's All the Apps Inspiré d'All the Apps de Tatone26Based on 2048 by Gabriele Cirulli D'après 2048 de Gabriele CirulliBased on Block Blast! by Hungry Studio D'après Block Blast! de Hungry Studio+Based on Level Devil by Unept D'après Level Devil d'Unept# a game the RAM of the calculator's software is too small forNeeds Il manqueKB more memory Ko de mémoirediff --git a/launcher/lang/zh.txt b/launcher/lang/zh.txtindex dfc156aa..6fce1a75 100644--- a/launcher/lang/zh.txt+++ b/launcher/lang/zh.txt@@ -95,18 +95,21 @@ Clear the field, flag the mines 清理雷区,标出地雷Block Breaker 打砖块Break every brick 打碎每一块砖Backgrounds, clocks, timers 背景、时钟、计时器+Reach the door, trust nothing 走到门口,什么都别相信# (names that stay as they are)NumDash NumDashNumBlocks NumBlocksNumDrive NumDrive2048 2048NumVisuals NumVisuals+Level Devil Level Devil# the games' creditsInspired by Minecraft, not affiliated with Mojang 灵感来自《我的世界》,与 Mojang 无关By Tatone26, from All the Apps 作者 Tatone26,出自 All the AppsInspired by Tatone26's All the Apps 灵感来自 Tatone26 的 All the AppsBased on 2048 by Gabriele Cirulli 改编自 Gabriele Cirulli 的 2048Based on Block Blast! by Hungry Studio 改编自 Hungry Studio 的 Block Blast!+Based on Level Devil by Unept 改编自 Unept 的 Level Devil# a game the RAM of the calculator's software is too small forNeeds 内存还差KB more memory KB