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
Subway Surfers: stations, tests, release and README
Mason363024b4b88fb6d
diff --git a/LICENSES/OFL-1.1-LilitaOne.txt b/LICENSES/OFL-1.1-LilitaOne.txtnew file mode 100644index 00000000..055594f2--- /dev/null+++ b/LICENSES/OFL-1.1-LilitaOne.txt@@ -0,0 +1,94 @@+Copyright (c) 2011 Juan Montoreano ([email protected]),+with Reserved Font Name Lilita++This Font Software is licensed under the SIL Open Font License, Version 1.1.+This license is copied below, and is also available with a FAQ at:+http://scripts.sil.org/OFL+++-----------------------------------------------------------+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007+-----------------------------------------------------------++PREAMBLE+The goals of the Open Font License (OFL) are to stimulate worldwide+development of collaborative font projects, to support the font creation+efforts of academic and linguistic communities, and to provide a free and+open framework in which fonts may be shared and improved in partnership+with others.++The OFL allows the licensed fonts to be used, studied, modified and+redistributed freely as long as they are not sold by themselves. The+fonts, including any derivative works, can be bundled, embedded,+redistributed and/or sold with any software provided that any reserved+names are not used by derivative works. The fonts and derivatives,+however, cannot be released under any other type of license. The+requirement for fonts to remain under this license does not apply+to any document created using the fonts or their derivatives.++DEFINITIONS+"Font Software" refers to the set of files released by the Copyright+Holder(s) under this license and clearly marked as such. This may+include source files, build scripts and documentation.++"Reserved Font Name" refers to any names specified as such after the+copyright statement(s).++"Original Version" refers to the collection of Font Software components as+distributed by the Copyright Holder(s).++"Modified Version" refers to any derivative made by adding to, deleting,+or substituting -- in part or in whole -- any of the components of the+Original Version, by changing formats or by porting the Font Software to a+new environment.++"Author" refers to any designer, engineer, programmer, technical+writer or other person who contributed to the Font Software.++PERMISSION & CONDITIONS+Permission is hereby granted, free of charge, to any person obtaining+a copy of the Font Software, to use, study, copy, merge, embed, modify,+redistribute, and sell modified and unmodified copies of the Font+Software, subject to the following conditions:++1) Neither the Font Software nor any of its individual components,+in Original or Modified Versions, may be sold by itself.++2) Original or Modified Versions of the Font Software may be bundled,+redistributed and/or sold with any software, provided that each copy+contains the above copyright notice and this license. These can be+included either as stand-alone text files, human-readable headers or+in the appropriate machine-readable metadata fields within text or+binary files as long as those fields can be easily viewed by the user.++3) No Modified Version of the Font Software may use the Reserved Font+Name(s) unless explicit written permission is granted by the corresponding+Copyright Holder. This restriction only applies to the primary font name as+presented to the users.++4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font+Software shall not be used to promote, endorse or advertise any+Modified Version, except to acknowledge the contribution(s) of the+Copyright Holder(s) and the Author(s) or with their explicit written+permission.++5) The Font Software, modified or unmodified, in part or in whole,+must be distributed entirely under this license, and must not be+distributed under any other license. The requirement for fonts to+remain under this license does not apply to any document created+using the Font Software.++TERMINATION+This license becomes null and void if any of the above conditions are+not met.++DISCLAIMER+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM+OTHER DEALINGS IN THE FONT SOFTWARE.diff --git a/Makefile b/Makefileindex c59933fd..60bd974b 100644--- a/Makefile+++ b/Makefile@@ -24,7 +24,7 @@ RAM_LIMIT = 148928# custom builds of Epsilon 25.2's source give apps less: 133652 bytes; every game fits there too, in NumPlay and on# its own (their big buffers are on the stack, 32 KB apart from that RAM, or in the RAM the software has left)CUSTOM_RAM = 133652-BIG_APPS = Celeste HollowKnight Undertale ChampionIsland FinalEarth2 NumPowder NumBlocks NumDrive+BIG_APPS = Celeste HollowKnight Undertale ChampionIsland FinalEarth2 NumPowder NumBlocks NumDrive SubwaySurfers# the calculator's space for installed apps (0x90200000 to 0x903F0000 in its flash)APP_SPACE = 2031616# Upsilon, the N0110 and N0115's custom software, gives .nwa apps less RAM: NumPlay-Upsilon.nwa has@@ -206,6 +206,7 @@ APP_celeste = games/celeste/output/celeste.nwa:Celeste.nwaAPP_championisland = games/championisland/output/championisland.nwa:ChampionIsland.nwaAPP_hollowknight = games/hollowknight/output/hollowknight.nwa:HollowKnight.nwaAPP_undertale = games/undertale/output/undertale.nwa:Undertale.nwa+APP_subway = games/subway/output/subway.nwa:SubwaySurfers.nwaAPP_finalearth2 = games/finalearth2/output/finalearth2.nwa:FinalEarth2.nwaAPP_numpowder = games/numpowder/output/numpowder.nwa:NumPowder.nwa@@ -222,6 +223,7 @@ apps: | $(B)$(MAKE) -C games/championisland build NWLINK="$(NWLINK)"$(MAKE) -C games/hollowknight build NWLINK="$(NWLINK)"$(MAKE) -C games/undertale build NWLINK="$(NWLINK)"+ $(MAKE) -C games/subway build NWLINK="$(NWLINK)"$(MAKE) -C games/finalearth2 build NWLINK="$(NWLINK)"$(MAKE) -C games/numpowder build NWLINK="$(NWLINK)"cd games/tetris/tetris && NWLINK="$(NWLINK)" $(CARGO) build --release --quiet@@ -238,6 +240,7 @@ apps: | $(B)cp $(word 1,$(subst :, ,$(APP_championisland))) $(B)/apps/$(word 2,$(subst :, ,$(APP_championisland)))cp $(word 1,$(subst :, ,$(APP_hollowknight))) $(B)/apps/$(word 2,$(subst :, ,$(APP_hollowknight)))cp $(word 1,$(subst :, ,$(APP_undertale))) $(B)/apps/$(word 2,$(subst :, ,$(APP_undertale)))+ cp $(word 1,$(subst :, ,$(APP_subway))) $(B)/apps/$(word 2,$(subst :, ,$(APP_subway)))cp $(word 1,$(subst :, ,$(APP_finalearth2))) $(B)/apps/$(word 2,$(subst :, ,$(APP_finalearth2)))cp $(word 1,$(subst :, ,$(APP_numpowder))) $(B)/apps/$(word 2,$(subst :, ,$(APP_numpowder)))arm-none-eabi-strip --strip-unneeded $(B)/apps/Tetris.nwa@@ -295,6 +298,7 @@ clean:-$(MAKE) -C games/championisland clean-$(MAKE) -C games/hollowknight clean-$(MAKE) -C games/undertale clean+ -$(MAKE) -C games/subway clean-$(MAKE) -C games/finalearth2 clean-$(MAKE) -C games/numpowder clean-cd games/tetris/tetris && $(CARGO) cleandiff --git a/games/subway/README.md b/games/subway/README.mdnew file mode 100644index 00000000..b24d0962--- /dev/null+++ b/games/subway/README.md@@ -0,0 +1,88 @@+> **Subway Surfers is a [NumPlay](../../README.md) game that comes on its own.** It is too big to sit next to NumPlay. Get `SubwaySurfers.nwa` from the [latest release](https://github.com/Mason363/NumPlay/releases/latest).++<p align="center">+ <img src="src/icon.png" width="84" alt="Subway Surfers icon">+</p>++<h1 align="center">Subway Surfers</h1>++<p align="center">+ <b>Dash down the subway's tracks, dodge the trains and outrun the Inspector, on the NumWorks calculator.</b><br>+ The endless run in 3D, seen from behind and above like on phones, with its coins, power-ups, hoverboards, missions and shop.+</p>++<p align="center">+ <a href="https://github.com/Mason363/NumPlay/releases/latest/download/SubwaySurfers.nwa"><b>Download SubwaySurfers.nwa</b></a>+ · <a href="#controls">Controls</a>+</p>++<p align="center">+ <img src="../../docs/media/subway.gif" width="640" alt="Running down the tracks between trains, jumping a barrier and flying with the jetpack">+</p>++## Highlights++* **Three tracks in real 3D:** trains standing on them and trains coming at you with their lights on, ramps up onto the roofs, low barriers to jump, high ones to roll under and big ones to go round. Running along the roofs and jumping from one train to the next is often the way through.+* **The yard as it should be:** walls covered in graffiti, signal gantries over the tracks, stations with their platforms, pillars and posters, the town's buildings behind, and tunnels into the dark.+* **The Inspector and his dog:** they chase you off at the start. Hit the side of a train or a barrier's edge and you stumble: they're right behind you, and if you stumble again before they give up, you're caught. Run into anything head-on and it's over.+* **Faster and faster:** the longer you run, the faster it goes, and the harder the tracks get.+* **Coins everywhere:** in lines down the tracks, in arcs over the barriers, up the ramps and along the roofs, and high in the sky for the jetpack.+* **Power-ups:** the **Jetpack** flies you over everything, **Super Sneakers** jump high enough to land on the trains, the **Coin Magnet** pulls in every coin near you and the **2x Multiplier** doubles your score. **Mystery boxes** hold coins, keys, hoverboards and more, and **keys** turn up now and then.+* **Hoverboards:** OK rides one for 30 seconds, and a crash only breaks the board. Three boards: the classic **Hoverboard**, the **Bouncer** (super jumps) and the **Daredevil** (faster).+* **Headstarts and score boosters:** at the start of a run, 1 flies you far ahead and 3 adds 5 to your score multiplier.+* **Save me!** Crashed? Spend a key to keep going: then 2, 4, 8...+* **Missions:** sets of three, like "Jump 25 times in one run" or "Run 150 m on top of trains". Finish a set and your score multiplier goes up, all the way to x30.+* **The shop:** upgrade each power-up to make it last longer (six levels, up to 30 seconds), buy hoverboards, headstarts, score boosters and mystery boxes, and unlock **Jake**, **Tricky**, **Fresh** and **Spike** and the boards.+* **Smooth:** the world is drawn in 3D, a band of the screen at a time, at 30 frames a second or more on every calculator.+* **Saved:** your coins, keys, best score, items, upgrades, characters, boards and missions. Home or On/Off in a run keeps the coins you've picked up. The save is also copied into `subway_saves.py`, so installing the app again doesn't erase it.++<table>+ <tr>+ <td align="center" width="50%"><img src="docs/title.png" width="100%" alt="The title: Jake between two trains"></td>+ <td align="center" width="50%"><img src="docs/run.png" width="100%" alt="Running between trains, coins down the free track"></td>+ </tr>+ <tr>+ <td align="center"><img src="docs/roofs.png" width="100%" alt="Up the ramp and along the roofs"></td>+ <td align="center"><img src="docs/jetpack.png" width="100%" alt="Flying with the jetpack over the tracks"></td>+ </tr>+ <tr>+ <td align="center"><img src="docs/tunnel.png" width="100%" alt="Into a tunnel"></td>+ <td align="center"><img src="docs/shop.png" width="100%" alt="The shop's characters, turning on their stand"></td>+ </tr>+</table>++## Controls++| Key | Action |+| --- | --- |+| Left, Right, or 4 6 | Change tracks |+| Up or 8 | Jump |+| Down or 2 | Roll; in the air, dive down and roll |+| OK, EXE or 5 | Ride a hoverboard; choose, buy |+| 1 | A headstart (at the start of a run) |+| 3 | A score booster (at the start of a run) |+| Back or ⌫ | Pause (Resume, Quit game); back in the menus |+| Home or On/Off | Save and quit |++On the title, OK plays, and Down goes to the **Shop**, the **Missions** and **Help**. In the shop, Left and Right go from shelf to shelf.++## Good to know++* **One app at a time:** Subway Surfers is too big to sit next to NumPlay or the other big games. Installing it from the NumWorks website swaps them out, and installing them again swaps it out. Your saves in each one are kept.+* **No clock, no daily rewards:** the calculator has no clock, so there are no daily challenges or word hunts.+* **No music or sound:** the calculator has no speaker.+* **Drawn from scratch:** the trains, the yard and the people are made of 3D shapes in the game's colours; nothing is taken from the game itself.++## Credits++Inspired by Subway Surfers by SYBO and Kiloo, not affiliated with them.++* The lettering is the **Lilita One** font by Juan Montoreano, under the SIL Open Font License ([license](../../LICENSES/OFL-1.1-LilitaOne.txt)).++Made by Mason Chen as part of NumPlay.++Build: `make` (needs `arm-none-eabi-gcc` and Node.js for nwlink); `make test` plays it on a computer.++## 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 font keeps its own license (see Credits).diff --git a/games/subway/src/scene.c b/games/subway/src/scene.cindex 66aaa762..474df70b 100644--- a/games/subway/src/scene.c+++ b/games/subway/src/scene.c@@ -331,11 +331,50 @@ static void building(int dir, float z0, float z1, float near_x, float depth, flo}}+/* a station: platforms on both sides under a roof on pillars, tiles, posters and the station's sign */+static void station_side(int dir, float z0, float dist, uint32_t hs) {+ float s = dir > 0 ? -1.0f : 1.0f; /* -1 on the left */+ float e = 4.3f * s, back = 6.7f * s, x0 = s < 0 ? back : e, x1 = s < 0 ? e : back;+ cube(x0, 0, z0, x1, 1.1f, z0 + BLOCK, 0xCFCAC0, 2 | (s < 0 ? 4 : 8));+ /* the yellow line along the edge */+ float y0 = s < 0 ? e - 0.45f : e + 0.15f, y1 = s < 0 ? e - 0.15f : e + 0.45f;+ V3 line[4] = {{y0, 1.101f, z0 + BLOCK}, {y1, 1.101f, z0 + BLOCK}, {y1, 1.101f, z0}, {y0, 1.101f, z0}};+ r_poly(line, 4, L(0xF2C230), P_DECAL, 0);+ /* the wall behind: tiles, posters, the sign */+ side(back, dir, z0, z0 + BLOCK, 1.1f, 6.4f, L(0xE9E2CF), 0);+ if (dist < 100) {+ for (int k = 0; k < 3; k++) {+ float pz = z0 + 2.5f + (float)k * 8;+ uint32_t c = spray[(hs >> (k * 3)) % 7];+ side(back + 0.01f * -s, dir, pz, pz + 2.2f, 2.0f, 4.2f, L(0x2A2A30), P_DECAL);+ side(back + 0.01f * -s, dir, pz + 0.12f, pz + 2.08f, 2.12f, 4.08f, L(c), P_DECAL2);+ side(back + 0.01f * -s, dir, pz + 0.4f, pz + 1.8f, 2.5f, 3.0f, L(0xF8F8F8), P_DECAL3);+ }+ side(back + 0.01f * -s, dir, z0 + 9.6f, z0 + 14.4f, 4.6f, 5.6f, L(0x2E5FA8), P_DECAL);+ side(back + 0.01f * -s, dir, z0 + 10.0f, z0 + 14.0f, 4.9f, 5.3f, L(0xF4F4F4), P_DECAL2);+ }+ /* pillars, and the roof on them */+ for (int k = 0; k < 3; k++) {+ float pz = z0 + 3.5f + (float)k * 8, px = 5.4f * s;+ cube(px - 0.22f, 1.1f, pz, px + 0.22f, 6.4f, pz + 0.44f, 0x7E8A96, 2);+ }+ float r0 = s < 0 ? back : 3.9f, r1 = s < 0 ? -3.9f : back;+ ceiling(6.4f, r0, r1, z0, z0 + BLOCK, L(0x5E6870));+ side(s < 0 ? -3.9f : 3.9f, -dir, z0, z0 + BLOCK, 6.4f, 7.0f, L(0x2E5FA8), 0);+ cube(r0, 6.4f, z0, r1, 7.0f, z0 + BLOCK, 0x2E5FA8, 1 | 2 | 4 | 8 | 32);+}+static void open_block(int b, float z0, float dist) {uint32_t h = world_hash((uint32_t)b * 7919u + 3 + world_seed);bool before_tunnel = world_tunnel(z0 + BLOCK + 1);+ /* now and then a station: two blocks in a row */+ bool station = !before_tunnel && !world_tunnel(z0 - 1) && world_hash((uint32_t)(b / 2) * 31u + world_seed) % 9 == 0 && z0 > 200;for (int dir = -1; dir <= 1; dir += 2) {uint32_t hs = world_hash(h + (uint32_t)(dir + 1));+ if (station) {+ station_side(dir, z0, dist, hs);+ continue;+ }float wx = dir > 0 ? -WALL_X : WALL_X; /* the wall's face towards the tracks: the left one faces +x */float wh = 3.4f + (float)(hs % 3) * 0.4f;static const uint32_t walls[6] = {0xB9B1A3, 0xA9A39A, 0xA65A42, 0xC9BFA8, 0x8E9AA3, 0xB46B4E};diff --git a/games/subway/tests/check.py b/games/subway/tests/check.pynew file mode 100644index 00000000..ace2f628--- /dev/null+++ b/games/subway/tests/check.py@@ -0,0 +1,156 @@+#!/usr/bin/env python3+"""Plays Subway Surfers on a computer (tests/play.c, built with the sanitizers) and checks it:++- a first start shows how to play, then the title; Home saves (subway.sav and its copy, subway_saves.py);+- runs played by the bot on many seeds: no fault, the world keeps coming, the score and coins add up;+- long runs where nothing hurts: minutes of track at full speed, tunnels, stations, every power-up;+- the shop: upgrades, items, characters and boards bought, coins taken, all kept;+- the save comes back from its copy when the file is gone (as after installing apps);+- Save me: keys spent, the run goes on; pause and Quit game: the coins are kept.++Usage: check.py build/play"""+import os+import shutil+import struct+import subprocess+import sys+import tempfile++PLAY = sys.argv[1] if len(sys.argv) > 1 else "build/play"+# subway.sav: magic, size, then the progress (game.h)+FMT = "<2I" + "4I4H4B8B3I16I"+FIELDS = ["magic", "size", "coins", "keys", "best", "runs", "boards", "headstarts", "boosters", "mystery",+ "u0", "u1", "u2", "u3", "chars", "ownboards", "character", "board", "mset", "mdone", "help", "pad",+ "b0", "b1", "b2"] + [f"t{i}" for i in range(16)]+failed = []+++def play(saves, *args):+ r = subprocess.run([PLAY, "--saves", saves, "--out", os.path.join(saves, "shots"), "--stats", *args],+ capture_output=True, text=True, timeout=1200)+ if r.returncode != 0 or "runtime error" in r.stderr or "AddressSanitizer" in r.stderr:+ raise AssertionError(f"play {' '.join(args)} failed:\n{r.stderr[-3000:]}")+ stats = {}+ for line in r.stdout.splitlines():+ if line.startswith("frames "):+ parts = line.split()+ for k, v in zip(parts[0::2], parts[1::2]):+ stats[k] = float(v)+ return stats+++def save(saves):+ data = open(os.path.join(saves, "subway.sav"), "rb").read()+ if len(data) != struct.calcsize(FMT):+ raise AssertionError(f"subway.sav is {len(data)} bytes")+ return dict(zip(FIELDS, struct.unpack(FMT, data)))+++def check(name, fn):+ d = tempfile.mkdtemp()+ try:+ fn(d)+ print(f"ok {name}")+ except AssertionError as e:+ failed.append(name)+ print(f"FAIL {name}: {e}")+ finally:+ shutil.rmtree(d)+++def first_start(d):+ # how to play, OK, the title, Home+ play(d, "--frames", "200", "--keys", "30:ok,150:home")+ s = save(d)+ assert s["magic"] == 0x31425553 and s["help"] == 1, s+ copy = open(os.path.join(d, "subway_saves.py"), "rb").read()+ assert copy[0] == 0 and b"#>subway.sav:" in copy, copy[:80]+ # the next start: no how to play, straight to the title (OK plays at once)+ st = play(d, "--frames", "400", "--keys", "30:ok,350:home")+ assert st["dist"] > 30, st+++def bot_runs(d):+ best = 0+ for seed in range(1, 9):+ shutil.rmtree(d, ignore_errors=True)+ os.makedirs(d)+ st = play(d, "--seed", str(seed), "--frames", "4000", "--keys", "30:ok,90:ok", "--bot", "100", "--draw-every", "7")+ assert st["dist"] > 120, (seed, st)+ assert st["coins"] > 10 and st["score"] >= st["dist"] * 4.5, (seed, st)+ best = max(best, st["dist"])+ assert best > 600, best+++def long_runs(d):+ for seed in (11, 12, 13):+ shutil.rmtree(d, ignore_errors=True)+ os.makedirs(d)+ st = play(d, "--seed", str(seed), "--god", "--frames", "20000", "--keys", "30:ok,90:ok,600:ok,8000:ok",+ "--bot", "100", "--power", "2000:0", "--power", "5000:1", "--power", "9000:2", "--power", "12000:3",+ "--draw-every", "9")+ assert st["dist"] > 6000 and not st["dead"], (seed, st)+ assert st["polys"] < 1500, st+ assert st["mset"] >= 1, st # (missions done along the way)+++def shop(d):+ # Down: the buttons, OK: the shop. Upgrades: OK five times on each line+ keys = ["30:ok", "60:down", "70:ok"]+ t = 100+ for row in range(4):+ for _ in range(5):+ keys.append(f"{t}:ok")+ t += 10+ keys.append(f"{t}:down")+ t += 10+ # items: a hoverboard twice, a headstart, a score booster, a mystery box+ keys += [f"{t}:right", f"{t + 10}:ok", f"{t + 20}:ok", f"{t + 30}:down", f"{t + 40}:ok", f"{t + 50}:down", f"{t + 60}:ok",+ f"{t + 70}:down", f"{t + 80}:ok"]+ t += 100+ # characters: Tricky, Fresh; boards: the Bouncer+ keys += [f"{t}:right", f"{t + 10}:down", f"{t + 20}:ok", f"{t + 30}:down", f"{t + 40}:ok", f"{t + 50}:right",+ f"{t + 60}:down", f"{t + 70}:ok", f"{t + 90}:back", f"{t + 110}:home"]+ play(d, "--coins", "400000", "--frames", str(t + 200), "--keys", ",".join(keys), "--shots", f"{t - 50},{t + 80}")+ s = save(d)+ assert [s["u0"], s["u1"], s["u2"], s["u3"]] == [5, 5, 5, 5], s+ assert s["boards"] >= 5 and s["headstarts"] >= 1 and s["boosters"] >= 1, s+ assert s["chars"] == 0b111 and s["character"] == 2, s+ assert s["ownboards"] == 0b11 and s["board"] == 1, s+ spent = 4 * (500 + 1000 + 3000 + 10000 + 60000) + 600 + 2000 + 3000 + 500 + 6000 + 12000 + 7500+ assert s["coins"] <= 400000 - spent + 20000, s # (a mystery box may give coins back)+++def copy_restore(d):+ play(d, "--frames", "500", "--keys", "30:ok,90:ok,450:home")+ before = save(d)+ assert before["runs"] == 1 and before["coins"] > 0, before+ os.remove(os.path.join(d, "subway.sav"))+ play(d, "--frames", "60")+ after = save(d)+ assert after == before, (before, after)+++def save_me(d):+ # no bot: the runner crashes into the first train or barrier; Save me, OK: one key, and on+ st = play(d, "--seed", "1", "--keys-owned", "3", "--frames", "1400", "--keys", "30:ok,90:ok,780:ok,1300:home")+ s = save(d)+ assert s["keys"] == 2, s+ assert st["dist"] > 130, st+++def pause_quit(d):+ # run a little, Back: pause, Quit game, Yes: the results, the coins kept+ play(d, "--god", "--frames", "800", "--keys", "30:ok,90:ok,500:back,520:down,540:ok,560:right,580:ok,700:home")+ s = save(d)+ assert s["runs"] == 1 and s["coins"] > 0 and s["best"] > 0, s+++check("first start", first_start)+check("bot runs", bot_runs)+check("long runs", long_runs)+check("shop", shop)+check("save copy", copy_restore)+check("save me", save_me)+check("pause, quit game", pause_quit)+sys.exit(1 if failed else 0)diff --git a/games/subway/tests/play.c b/games/subway/tests/play.cindex 4dd41658..1755aa08 100644--- a/games/subway/tests/play.c+++ b/games/subway/tests/play.c@@ -6,7 +6,8 @@* Keys: left right up down ok back one three home. "a-b:key" holds the key from frame a to b, "a:key" for one* frame (frames are the game's steps, 60 a second). --bot plays the run from frame FROM on: it reads the* tracks ahead and changes lanes, jumps and rolls (it is no expert: it stumbles and crashes now and then).- * Screenshots are DIR/shot_<frame>.ppm. */+ * Screenshots are DIR/shot_<frame>.ppm. --raw DIR:FROM-TO keeps the frames drawn from FROM to TO as raw RGB565+ * files for tools/record.py --frames (GIFs for the documentation). */#include <stdio.h>#include <stdlib.h>#include <string.h>@@ -134,7 +135,9 @@ int main(int argc, char **argv) {int frames = 600, draw_every = 1, bot_from = -1;const char *out = "build/shots", *shots = "", *saves = "build/host-saves";long coins = -1, keys_owned = -1;- bool stats = false, god = false; /* god: nothing hurts (long runs for tests) */+ bool stats = false, god = false;+ const char *raw = NULL;+ int raw_from = 0, raw_to = -1; /* god: nothing hurts (long runs for tests) */for (int i = 1; i < argc; i++) {const char *a = argv[i], *v = i + 1 < argc ? argv[i + 1] : "";if (!strcmp(a, "--frames")) frames = atoi(v), i++;@@ -149,6 +152,13 @@ int main(int argc, char **argv) {else if (!strcmp(a, "--draw-every")) draw_every = atoi(v), i++;else if (!strcmp(a, "--stats")) stats = true;else if (!strcmp(a, "--god")) god = true;+ else if (!strcmp(a, "--raw")) {+ static char dir[256];+ snprintf(dir, sizeof dir, "%s", v);+ char *c = strrchr(dir, ':');+ if (c) *c = 0, sscanf(c + 1, "%d-%d", &raw_from, &raw_to);+ raw = dir, i++;+ }else if (!strcmp(a, "--power") && npower < 8) {/* FRAME:KIND, KIND a power-up (0 jetpack, 1 sneakers, 2 magnet, 3 2x) */power_at[npower] = atoi(v), power_kind[npower] = atoi(strchr(v, ':') ? strchr(v, ':') + 1 : "0"), npower++, i++;@@ -200,10 +210,18 @@ int main(int argc, char **argv) {char list[8192];snprintf(list, sizeof list, ",%s,", shots);bool shot = all || strstr(list, name);- if (shot || f % draw_every == 0) {+ bool keep = raw && f >= raw_from && f <= raw_to && f % 4 == 0; /* (15 frames a second) */+ if (shot || keep || f % draw_every == 0) {app_draw();if ((int)perf_polys > max_polys) max_polys = (int)perf_polys;}+ if (keep) {+ char p[512];+ mkdir(raw, 0755);+ snprintf(p, sizeof p, "%s/%06d_%06d.raw", raw, f, (f - raw_from) * 50 / 3);+ FILE *o = fopen(p, "wb");+ if (o) fwrite(host_fb, 2, SCREEN_W * SCREEN_H, o), fclose(o);+ }if (shot) {char p[512];snprintf(p, sizeof p, "%s/shot_%05d.ppm", out, f);diff --git a/tests/test_games.py b/tests/test_games.pyindex f21de9a5..6a9692dd 100644--- a/tests/test_games.py+++ b/tests/test_games.py@@ -129,6 +129,10 @@ GAMES = {*[(5000 + 200 * i, "down") for i in range(8)], (6800, "right"), (7000, "right"),(7300, "ok"), (8300, "right"), (8600, "ok"), (10500, "right", 1500)), 13000,presses((1500, "left", 1000)), 4000),+ # how to play, the title, a run up the middle track through the first coins; Home banks them. Next time+ # straight from the title into another run, quit with On/Off+ "subway": ("SubwaySurfers.nwa", "subway.sav", presses((1500, "ok"), (2500, "ok")), 8000,+ presses((1500, "ok")), 6000),# the intro, then OK draws for a while (the autosave on Home); next time it comes back and more is drawn"numpowder": ("NumPowder.nwa", "numpowder.sav", presses((2000, "ok"), (3000, "ok", 1500)), 6000,presses((2000, "ok"), (2500, "right", 600), (3200, "ok", 800)), 5000),@@ -163,7 +167,8 @@ SEEDS = {# the app again, only the scripts are left, and the save must come backCOPIES = {"championisland": "champion_saves.py", "numblocks": "numblocks_saves.py", "celeste": "celeste_saves.py","hollowknight": "hollowknight_saves.py", "finalearth2": "finalearth2_saves.py",- "numpowder": "numpowder_saves.py", "undertale": "undertale_saves.py"}+ "numpowder": "numpowder_saves.py", "undertale": "undertale_saves.py",+ "subway": "subway_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,@@ -177,6 +182,9 @@ CHECKS = {# the moment kept ("UT01", the frames played at 52); after the reinstall, from the copy, it goes on"undertale": (lambda v: v[:4] == b"UT01" and struct.unpack_from("<I", v, 52)[0] > 0,lambda v: v[:4] == b"UT01" and struct.unpack_from("<I", v, 52)[0] > 60),+ # the progress ("SUB1"): a run played, its coins banked (offset 8), runs at 20; then a second run+ "subway": (lambda v: v[:4] == b"SUB1" and struct.unpack_from("<I", v, 8)[0] > 0 and struct.unpack_from("<I", v, 20)[0] == 1,+ lambda v: v[:4] == b"SUB1" and struct.unpack_from("<I", v, 20)[0] == 2),# a simulation saved ("NPWD"); after the reinstall, from the copy, it goes on and is saved again"numpowder": (lambda v: v[:4] == b"NPWD",) * 2,# a game saved ("HKSV", then the play time at 152); after the reinstall, from the copy, it goes ondiff --git a/tools/release.py b/tools/release.pyindex 9b2c73bd..599c5e11 100644--- a/tools/release.py+++ b/tools/release.py@@ -30,6 +30,9 @@ ALONE = {"undertale": ("Undertale", "the whole Underground, from the bed of golden flowers to the barrier and the neutral ""ending: the Ruins, Snowdin, Waterfall, Hotland, the CORE and New Home. Too big to share the calculator ""with NumPlay: install it on its own"),+ "subway": ("Subway Surfers", "the endless run down the subway's tracks in 3D: trains, ramps, barriers, coins, "+ "power-ups, hoverboards, the Inspector and his dog, the shop and the missions. Too big to share the "+ "calculator with NumPlay: install it on its own"),"championisland": ("Champion Island", "the Doodle Champion Island Games. Too big to share the calculator with ""NumPlay: install it on its own"),"numpowder": ("NumPowder", "The Powder Toy on the calculator: sand, water, fire, acid, electricity and nearly 200 "