Skip to content

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

Turbo Rush: taken out of NumPlay

Mason36346732ae0cf78
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index c651be51..fb6ba79c 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -91,7 +91,6 @@ jobs:
make -C games/coreball host test
make -C games/uno host test
make -C games/fnf host test BUILD_DIR=../../build/data/games/fnf
- make -C games/turborush host test BUILD_DIR=../../build/data/games/turborush
make -C games/angrybirds host test
make -C games/polytrack host test
make -C games/paperclips host test
diff --git a/Makefile b/Makefile
index f59a887b..bc105284 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@ PY ?= python3
CARGO ?= cargo
B = build/data
# Conventional games honor a configurable output directory; special layouts are kept local.
-GAMES_REDIRECT = angrybirds badtime balatro blockblast breakout buckshot celeste championisland chess connectfour cookieclicker coreball dinorun donkeykong doodlejump doom dune famidash finalearth2 flappybird flappydunk fnaf fnaf2 fnaf3 fnaf4 fnf g2048 hillclimb hollowknight invaders isaac jetpackjoyride leveldevil mahjong meowdoku minesweeper monkeymart numblocks numpowder numvisuals pacman paperclips polytrack portal pvz rider snake snowrider sokoban solitaire sonic stickmanhook subway sudoku suika templerun tombofthemask towerblock turborush twoplayer undertale uno uttt
+GAMES_REDIRECT = angrybirds badtime balatro blockblast breakout buckshot celeste championisland chess connectfour cookieclicker coreball dinorun donkeykong doodlejump doom dune famidash finalearth2 flappybird flappydunk fnaf fnaf2 fnaf3 fnaf4 fnf g2048 hillclimb hollowknight invaders isaac jetpackjoyride leveldevil mahjong meowdoku minesweeper monkeymart numblocks numpowder numvisuals pacman paperclips polytrack portal pvz rider snake snowrider sokoban solitaire sonic stickmanhook subway sudoku suika templerun tombofthemask towerblock twoplayer undertale uno uttt
GAMES_OUT = dinorun
GAME_REDIRECT_ARG = $(if $(filter $(1),$(GAMES_OUT)),OUT=../../$(B)/games/$(1),BUILD_DIR=../../$(B)/games/$(1))
# the RAM the oldest calculator software that runs apps gives them (23.2: 148928 bytes; 25.2 gives 153676).
@@ -29,7 +29,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 SubwaySurfers FiveNightsAtFreddys Doom BindingOfIsaac HillClimbRacing PlantsVsZombies SonicTheHedgehog CookieClicker LevelDevil JetpackJoyride StickmanHook DonkeyKong Dune MonkeyMart TombOfTheMask UNO FridayNightFunkin TurboRush AngryBirds PolyTrack UniversalPaperclips BadTimeSimulator Mahjong Rider SnowRider3D TempleRun FiveNightsAtFreddys2 FiveNightsAtFreddys3 FiveNightsAtFreddys4 Famidash UniversalPaperclips-French
+BIG_APPS = Celeste HollowKnight Undertale ChampionIsland FinalEarth2 NumPowder NumBlocks NumDrive SubwaySurfers FiveNightsAtFreddys Doom BindingOfIsaac HillClimbRacing PlantsVsZombies SonicTheHedgehog CookieClicker LevelDevil JetpackJoyride StickmanHook DonkeyKong Dune MonkeyMart TombOfTheMask UNO FridayNightFunkin AngryBirds PolyTrack UniversalPaperclips BadTimeSimulator Mahjong Rider SnowRider3D TempleRun FiveNightsAtFreddys2 FiveNightsAtFreddys3 FiveNightsAtFreddys4 Famidash UniversalPaperclips-French
# the calculator's space for installed apps: from the end of its software (64 KiB aligned) to 64 KiB before the
# end of its 4 MiB slot of flash, 0x903F0000. The software's size sets the start: 0x90200000 is the latest a
# NumPlay counts on (1.94 MB, APP_SPACE); Epsilon 26.4 on an N0120 ends at 0x90180000 (2.44 MB, the
@@ -47,7 +47,7 @@ XL_APP_SPACE = 6291456
# the spaces the customizer website offers (kit.json "spaces"; tools/kit.py links a NumPlay at each)
SPACES = std:$(APP_START):$(APP_END) e26:$(APP_START_26):$(APP_END) xl:$(APP_START):$(XL_END) xl26:$(APP_START_26):$(XL_END)
# big games that must install on their own without Enlarged Extra Apps: make check holds them to APP_SPACE
-APP_SPACE_APPS = HillClimbRacing FridayNightFunkin TurboRush AngryBirds PolyTrack UniversalPaperclips UniversalPaperclips-French BadTimeSimulator Mahjong SnowRider3D TempleRun Famidash
+APP_SPACE_APPS = HillClimbRacing FridayNightFunkin AngryBirds PolyTrack UniversalPaperclips UniversalPaperclips-French BadTimeSimulator Mahjong SnowRider3D TempleRun Famidash
# Upsilon, the N0110 and N0115's custom software, gives .nwa apps less RAM: NumPlay-Upsilon.nwa has
# the games that fit it (NumPlay draws their text there: see launcher/src/compat.c)
UPSILON_RAM = 107674
@@ -324,7 +324,6 @@ APP_monkeymart = $(B)/games/monkeymart/monkeymart.nwa:MonkeyMart.nwa
APP_tombofthemask = $(B)/games/tombofthemask/tombofthemask.nwa:TombOfTheMask.nwa
APP_uno = $(B)/games/uno/uno.nwa:UNO.nwa
APP_fnf = $(B)/games/fnf/fnf.nwa:FridayNightFunkin.nwa
-APP_turborush = $(B)/games/turborush/turborush.nwa:TurboRush.nwa
APP_angrybirds = $(B)/games/angrybirds/angrybirds.nwa:AngryBirds.nwa
APP_polytrack = $(B)/games/polytrack/polytrack.nwa:PolyTrack.nwa
APP_paperclips = $(B)/games/paperclips/paperclips.nwa:UniversalPaperclips.nwa
@@ -372,7 +371,6 @@ apps: | $(B)
$(MAKE) -C games/tombofthemask build NWLINK="$(NWLINK)" BUILD_DIR=../../$(B)/games/tombofthemask
$(MAKE) -C games/uno build NWLINK="$(NWLINK)" BUILD_DIR=../../$(B)/games/uno
$(MAKE) -C games/fnf build NWLINK="$(NWLINK)" BUILD_DIR=../../$(B)/games/fnf
- $(MAKE) -C games/turborush build NWLINK="$(NWLINK)" BUILD_DIR=../../$(B)/games/turborush
$(MAKE) -C games/angrybirds build NWLINK="$(NWLINK)" BUILD_DIR=../../$(B)/games/angrybirds
$(MAKE) -C games/polytrack build NWLINK="$(NWLINK)" BUILD_DIR=../../$(B)/games/polytrack
$(MAKE) -C games/paperclips build NWLINK="$(NWLINK)" BUILD_DIR=../../$(B)/games/paperclips
@@ -418,7 +416,6 @@ apps: | $(B)
cp $(word 1,$(subst :, ,$(APP_tombofthemask))) $(B)/apps/$(word 2,$(subst :, ,$(APP_tombofthemask)))
cp $(word 1,$(subst :, ,$(APP_uno))) $(B)/apps/$(word 2,$(subst :, ,$(APP_uno)))
cp $(word 1,$(subst :, ,$(APP_fnf))) $(B)/apps/$(word 2,$(subst :, ,$(APP_fnf)))
- cp $(word 1,$(subst :, ,$(APP_turborush))) $(B)/apps/$(word 2,$(subst :, ,$(APP_turborush)))
cp $(word 1,$(subst :, ,$(APP_angrybirds))) $(B)/apps/$(word 2,$(subst :, ,$(APP_angrybirds)))
cp $(word 1,$(subst :, ,$(APP_polytrack))) $(B)/apps/$(word 2,$(subst :, ,$(APP_polytrack)))
cp $(word 1,$(subst :, ,$(APP_paperclips))) $(B)/apps/$(word 2,$(subst :, ,$(APP_paperclips)))
@@ -506,7 +503,6 @@ clean:
-$(MAKE) -C games/tombofthemask clean
-$(MAKE) -C games/uno clean
-$(MAKE) -C games/fnf clean
- -$(MAKE) -C games/turborush clean
-$(MAKE) -C games/angrybirds clean
-$(MAKE) -C games/polytrack clean
-$(MAKE) -C games/paperclips clean
diff --git a/README.md b/README.md
index fa05c4c3..043333e2 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@
<p align="center">
<b>29 free games for your NumWorks calculator, in one app.</b><br>
- Plus 36 big games that install on their own. For the N0110, N0115 and N0120, in English, French and Chinese.
+ Plus 35 big games that install on their own. For the N0110, N0115 and N0120, in English, French and Chinese.
</p>
<p align="center">
@@ -134,30 +134,29 @@ These are too big to fit next to NumPlay, so each one is its own app. Install it
<tr>
<td align="center"><a href="games/uno/README.md"><img src="docs/media/thumb_uno.png" width="200" alt="UNO"><br><b>UNO</b></a><br><sub>The card game against one to three bots, to 500 points</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/UNO.nwa">Download</a></td>
<td align="center"><a href="games/fnf/README.md"><img src="docs/media/thumb_fnf.png" width="200" alt="Friday Night Funkin'"><br><b>Friday Night Funkin'</b></a><br><sub>Every week and its songs, on the beat, without the sound</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/FridayNightFunkin.nwa">Download</a></td>
- <td align="center"><a href="games/turborush/README.md"><img src="docs/media/thumb_turborush.png" width="200" alt="Turbo Rush"><br><b>Turbo Rush</b></a><br><sub>An arcade racer: six circuits, seven rivals and a Grand Prix</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/TurboRush.nwa">Download</a></td>
+ <td align="center"><a href="games/angrybirds/README.md"><img src="docs/media/thumb_angrybirds.png" width="200" alt="Angry Birds"><br><b>Angry Birds</b></a><br><sub>The Chrome edition: 429 levels, seven birds and the Mighty Eagle</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/AngryBirds.nwa">Download</a></td>
</tr>
<tr>
- <td align="center"><a href="games/angrybirds/README.md"><img src="docs/media/thumb_angrybirds.png" width="200" alt="Angry Birds"><br><b>Angry Birds</b></a><br><sub>The Chrome edition: 429 levels, seven birds and the Mighty Eagle</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/AngryBirds.nwa">Download</a></td>
<td align="center"><a href="games/polytrack/README.md"><img src="docs/media/thumb_polytrack.png" width="200" alt="PolyTrack"><br><b>PolyTrack</b></a><br><sub>Time trials on all 17 tracks, loops and wall rides included</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/PolyTrack.nwa">Download</a></td>
<td align="center"><a href="games/paperclips/README.md"><img src="docs/media/thumb_paperclips.png" width="200" alt="Universal Paperclips"><br><b>Universal Paperclips</b></a><br><sub>An AI making paperclips, from the first clip to the whole universe</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/UniversalPaperclips.nwa">Download</a></td>
+ <td align="center"><a href="games/badtime/README.md"><img src="docs/media/thumb_badtime.png" width="200" alt="Bad Time Simulator"><br><b>Bad Time Simulator</b></a><br><sub>The Sans fight: all 24 attacks, KR and the blue heart</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/BadTimeSimulator.nwa">Download</a></td>
</tr>
<tr>
- <td align="center"><a href="games/badtime/README.md"><img src="docs/media/thumb_badtime.png" width="200" alt="Bad Time Simulator"><br><b>Bad Time Simulator</b></a><br><sub>The Sans fight: all 24 attacks, KR and the blue heart</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/BadTimeSimulator.nwa">Download</a></td>
<td align="center"><a href="games/mahjong/README.md"><img src="docs/media/thumb_mahjong.png" width="200" alt="Mahjong"><br><b>Mahjong</b></a><br><sub>Mahjong solitaire: 144 tiles, four layouts, every deal winnable</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/Mahjong.nwa">Download</a></td>
<td align="center"><a href="games/rider/README.md"><img src="docs/media/thumb_rider.png" width="200" alt="Rider"><br><b>Rider</b></a><br><sub>The neon bike game: 48 levels, the endless run and 55 bikes</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/Rider.nwa">Download</a></td>
+ <td align="center"><a href="games/snowrider/README.md"><img src="docs/media/thumb_snowrider.png" width="200" alt="Snow Rider 3D"><br><b>Snow Rider 3D</b></a><br><sub>The endless sled run: its slope, 11 sleds and gifts to buy them</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/SnowRider3D.nwa">Download</a></td>
</tr>
<tr>
- <td align="center"><a href="games/snowrider/README.md"><img src="docs/media/thumb_snowrider.png" width="200" alt="Snow Rider 3D"><br><b>Snow Rider 3D</b></a><br><sub>The endless sled run: its slope, 11 sleds and gifts to buy them</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/SnowRider3D.nwa">Download</a></td>
<td align="center"><a href="games/templerun/README.md"><img src="docs/media/thumb_templerun.png" width="200" alt="Temple Run"><br><b>Temple Run</b></a><br><sub>Run from the temple: turn, jump, slide and lean</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/TempleRun.nwa">Download</a></td>
<td align="center"><a href="games/fnaf2/README.md"><img src="docs/media/thumb_fnaf2.png" width="200" alt="Five Nights at Freddy's 2"><br><b>Five Nights at Freddy's 2</b></a><br><sub>The new pizzeria: six nights, the mask, the music box and the Custom Night</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/FiveNightsAtFreddys2.nwa">Download</a></td>
+ <td align="center"><a href="games/famidash/README.md"><img src="docs/media/thumb_famidash.png" width="200" alt="Famidash"><br><b>Famidash</b></a><br><sub>Geometry Dash for the NES: 173 levels, every mode, practice mode</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/Famidash.nwa">Download</a></td>
</tr>
<tr>
- <td align="center"><a href="games/famidash/README.md"><img src="docs/media/thumb_famidash.png" width="200" alt="Famidash"><br><b>Famidash</b></a><br><sub>Geometry Dash for the NES: 173 levels, every mode, practice mode</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/Famidash.nwa">Download</a></td>
<td align="center"><a href="games/fnaf3/README.md"><img src="docs/media/thumb_fnaf3.png" width="200" alt="Five Nights at Freddy's 3"><br><b>Five Nights at Freddy's 3</b></a><br><sub>Fazbear's Fright: Springtrap, the phantoms, the vents and the 8-bit minigames</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/FiveNightsAtFreddys3.nwa">Download</a></td>
<td align="center"><a href="games/fnaf4/README.md"><img src="docs/media/thumb_fnaf4.png" width="200" alt="Five Nights at Freddy's 4"><br><b>Five Nights at Freddy's 4</b></a><br><sub>The bedroom: listen at the doors, the closet, the bed, Fun with Plushtrap</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/FiveNightsAtFreddys4.nwa">Download</a></td>
+ <td align="center"><a href="https://github.com/Mason363/NumWorks-Super-Mario-64"><b>Super Mario 64</b></a><br><sub>In a repository of its own: NumWorks-Super-Mario-64</sub></td>
</tr>
<tr>
- <td align="center"><a href="https://github.com/Mason363/NumWorks-Super-Mario-64"><b>Super Mario 64</b></a><br><sub>In a repository of its own: NumWorks-Super-Mario-64</sub></td>
<td align="center"><a href="https://github.com/Mason363/NumWorks-Super-Mario-Bros"><b>Super Mario Bros.</b></a><br><sub>All 32 stages, in a repository of its own: NumWorks-Super-Mario-Bros</sub></td>
<td align="center"><a href="#roadmap"><b>More on the way</b></a><br><sub>Minecraft 1.18.2 and more: see the roadmap</sub></td>
</tr>
@@ -396,7 +395,6 @@ NumPlay is a fan project, made out of love for these games and for the NumWorks
- **Tomb of the Mask** by Playgendary inspired NumPlay's Tomb of the Mask, which follows the rules of the game's web version and uses its stages, pictures and pixel font. **Bobydeluxe** brought it to NumPlay. Not affiliated with Playgendary.
- **UNO** by Mattel inspired NumPlay's UNO, which plays by the official rules with cards drawn for the calculator. **Bobydeluxe** brought it to NumPlay. Not affiliated with Mattel.
- **Friday Night Funkin'** by the Funkin' Crew (ninjamuffin99, PhantomArcade, evilsk8r, Kawai Sprite) inspired NumPlay's Friday Night Funkin', which follows the game's open source code (Apache-2.0) and builds its charts and pictures from the game's own files when it's built. **Bobydeluxe** brought it to NumPlay. Not affiliated with the Funkin' Crew.
-- **[Turbo Rush](https://jeux.w-production.fr/#/jeu/turborush)** by W Production inspired NumPlay's Turbo Rush, an arcade racer of its own written in C for NumPlay, with circuits, cars and landscapes made for it. **Bobydeluxe** brought it to NumPlay. Not affiliated with W Production.
- **Angry Birds** by Rovio Entertainment inspired NumPlay's Angry Birds, which plays the Chrome edition's 429 levels with its own pictures, read from its web build, and follows its rules and numbers. Its physics is **Box2D 2.2.1** by Erin Catto (zlib license, [license](games/angrybirds/src/box2d/License.txt)), the engine the game runs on. **Bobydeluxe** brought it to NumPlay. Not affiliated with Rovio.
- **[PolyTrack](https://www.kodub.com/apps/polytrack)** by Kodub inspired NumPlay's PolyTrack, which drives the game's 17 tracks with its own physics numbers, models, colours and logo, read from its web build. Its 3D engine grew out of **Boris-TH**'s PolyGT 3D. Not affiliated with Kodub.
- **[Universal Paperclips](https://www.decisionproblem.com/paperclips/)** by Frank Lantz (Everybody House Games), with combat programming by Bennett Foddy, inspired NumPlay's Universal Paperclips, which plays the whole game with its rules, numbers, projects and messages, read from its web build. Not affiliated with them.
@@ -438,7 +436,7 @@ NumPlay is a fan project, made out of love for these games and for the NumWorks
NumPlay is licensed under the [GNU General Public License v3.0](LICENSE). Copyright (c) 2026 Mason Chen. Code and fonts from others keep their own licenses: the `UNLICENSE` files in the games' folders and the [LICENSES](LICENSES) folder. The names, artwork and music of the games NumPlay is inspired by belong to their makers and are not covered by it.
-<sub>Unofficial fan games, not affiliated with NumWorks, RobTop Games (Geometry Dash), Hipster Whale (Crossy Road), the makers of Drive Mad, LocalThunk or Playstack (Balatro), Mike Klubnika or Critical Reflex (Buckshot Roulette), Hungry Studio (Block Blast!), Aladdin X (Suika Game), Voodoo (Flappy Dunk), Lima Sky (Doodle Jump), Mojang or Microsoft (Minecraft), Maddy Makes Games (Celeste), Team Cherry (Hollow Knight), Toby Fox (Undertale), jcw87 (Bad Time Simulator), Imangi Studios (Temple Run), id Software (Doom), Edmund McMillen, Florian Himsl or Nicalis (The Binding of Isaac), PopCap Games or Electronic Arts (Plants vs. Zombies), Scott Cawthon (Five Nights at Freddy's, Five Nights at Freddy's 2, Five Nights at Freddy's 3, Five Nights at Freddy's 4), SEGA (Sonic the Hedgehog, Master System, Game Gear, SG-1000), SYBO or Kiloo (Subway Surfers), Fingersoft (Hill Climb Racing), Unept (Level Devil), Halfbrick (Jetpack Joyride), Madbox (Stickman Hook), Nintendo (Donkey Kong, Game Boy, NES), Team Lava (Dune!), Inlogic Software (Dune Rider), TinyDobbins (Monkey Mart), Playgendary (Tomb of the Mask), Mattel (UNO), the Funkin' Crew (Friday Night Funkin'), W Production (Turbo Rush), Rovio Entertainment (Angry Birds), Kodub (PolyTrack), Frank Lantz or Everybody House Games (Universal Paperclips), the makers of Snow Rider 3D, Ketchapp (Rider), TFDSoft (Famidash), Brodie Lockard or Activision (Shanghai), Atari (Pong), Disney (Tron), Orteil or DashNet (Cookie Clicker), Taito or Midway (Space Invaders), Thinking Rabbit or Falcon (Sokoban), Oakever Games (Meowdoku), Florian van Strien (The Final Earth 2), The Powder Toy's developers (The Powder Toy), MateoConLechuga (Portal Returns), Valve (Portal), .GEARS (Flappy Bird), Bandai Namco (Pac-Man), Hasbro (Connect Four), Google (Snake, Solitaire, Block Breaker, Chrome Dino, Doodle Champion Island Games), STUDIO4°C or Microsoft (Minesweeper), ducalex (Retro-Go), Coleco (ColecoVision). Tetris is a trademark of The Tetris Company, Chrome of Google LLC, Minecraft of Mojang Synergies AB, Pac-Man of Bandai Namco, Connect Four of Hasbro, DOOM of ZeniMax Media, Sonic the Hedgehog, Master System, Game Gear and SG-1000 of SEGA, Space Invaders of Taito, UNO of Mattel, Angry Birds of Rovio Entertainment, and Donkey Kong, Game Boy, Game Boy Color and NES of Nintendo.</sub>
+<sub>Unofficial fan games, not affiliated with NumWorks, RobTop Games (Geometry Dash), Hipster Whale (Crossy Road), the makers of Drive Mad, LocalThunk or Playstack (Balatro), Mike Klubnika or Critical Reflex (Buckshot Roulette), Hungry Studio (Block Blast!), Aladdin X (Suika Game), Voodoo (Flappy Dunk), Lima Sky (Doodle Jump), Mojang or Microsoft (Minecraft), Maddy Makes Games (Celeste), Team Cherry (Hollow Knight), Toby Fox (Undertale), jcw87 (Bad Time Simulator), Imangi Studios (Temple Run), id Software (Doom), Edmund McMillen, Florian Himsl or Nicalis (The Binding of Isaac), PopCap Games or Electronic Arts (Plants vs. Zombies), Scott Cawthon (Five Nights at Freddy's, Five Nights at Freddy's 2, Five Nights at Freddy's 3, Five Nights at Freddy's 4), SEGA (Sonic the Hedgehog, Master System, Game Gear, SG-1000), SYBO or Kiloo (Subway Surfers), Fingersoft (Hill Climb Racing), Unept (Level Devil), Halfbrick (Jetpack Joyride), Madbox (Stickman Hook), Nintendo (Donkey Kong, Game Boy, NES), Team Lava (Dune!), Inlogic Software (Dune Rider), TinyDobbins (Monkey Mart), Playgendary (Tomb of the Mask), Mattel (UNO), the Funkin' Crew (Friday Night Funkin'), Rovio Entertainment (Angry Birds), Kodub (PolyTrack), Frank Lantz or Everybody House Games (Universal Paperclips), the makers of Snow Rider 3D, Ketchapp (Rider), TFDSoft (Famidash), Brodie Lockard or Activision (Shanghai), Atari (Pong), Disney (Tron), Orteil or DashNet (Cookie Clicker), Taito or Midway (Space Invaders), Thinking Rabbit or Falcon (Sokoban), Oakever Games (Meowdoku), Florian van Strien (The Final Earth 2), The Powder Toy's developers (The Powder Toy), MateoConLechuga (Portal Returns), Valve (Portal), .GEARS (Flappy Bird), Bandai Namco (Pac-Man), Hasbro (Connect Four), Google (Snake, Solitaire, Block Breaker, Chrome Dino, Doodle Champion Island Games), STUDIO4°C or Microsoft (Minesweeper), ducalex (Retro-Go), Coleco (ColecoVision). Tetris is a trademark of The Tetris Company, Chrome of Google LLC, Minecraft of Mojang Synergies AB, Pac-Man of Bandai Namco, Connect Four of Hasbro, DOOM of ZeniMax Media, Sonic the Hedgehog, Master System, Game Gear and SG-1000 of SEGA, Space Invaders of Taito, UNO of Mattel, Angry Birds of Rovio Entertainment, and Donkey Kong, Game Boy, Game Boy Color and NES of Nintendo.</sub>
## Gallery
@@ -531,25 +529,24 @@ NumPlay is licensed under the [GNU General Public License v3.0](LICENSE). Copyri
<tr>
<td align="center"><img src="docs/media/gallery/uno.gif" alt="UNO: a hand against three bots, a Draw Two and a colour called"><br><a href="games/uno/README.md"><b>UNO</b></a></td>
<td align="center"><img src="docs/media/gallery/fnf.gif" alt="Friday Night Funkin': Ready, Set, Go, then the first notes of a song"><br><a href="games/fnf/README.md"><b>Friday Night Funkin'</b></a></td>
- <td align="center"><img src="docs/media/gallery/turborush.gif" alt="Turbo Rush: racing along Sunset Coast, passing rivals before a bend"><br><a href="games/turborush/README.md"><b>Turbo Rush</b></a></td>
+ <td align="center"><img src="docs/media/gallery/angrybirds.gif" alt="Angry Birds: the first level, aimed, fired and knocked down with one bird"><br><a href="games/angrybirds/README.md"><b>Angry Birds</b></a></td>
</tr>
<tr>
- <td align="center"><img src="docs/media/gallery/angrybirds.gif" alt="Angry Birds: the first level, aimed, fired and knocked down with one bird"><br><a href="games/angrybirds/README.md"><b>Angry Birds</b></a></td>
<td align="center"><img src="docs/media/gallery/polytrack.gif" alt="PolyTrack: Desert 4, through the tube and on to the finish"><br><a href="games/polytrack/README.md"><b>PolyTrack</b></a></td>
<td align="center"><img src="docs/media/gallery/paperclips.gif" alt="Universal Paperclips: the first clips, a strategy tournament, the HypnoDrones, a battle against the drifters and the last clips"><br><a href="games/paperclips/README.md"><b>Universal Paperclips</b></a></td>
+ <td align="center"><img src="docs/media/gallery/badtime.gif" alt="Bad Time Simulator: Sans slams the blue heart into bones, then Gaster Blasters fire across the box"><br><a href="games/badtime/README.md"><b>Bad Time Simulator</b></a></td>
</tr>
<tr>
- <td align="center"><img src="docs/media/gallery/badtime.gif" alt="Bad Time Simulator: Sans slams the blue heart into bones, then Gaster Blasters fire across the box"><br><a href="games/badtime/README.md"><b>Bad Time Simulator</b></a></td>
<td align="center"><img src="docs/media/gallery/mahjong.gif" alt="Mahjong: pairs taken from the Turtle, a hint lights up two tiles, then a pair is undone"><br><a href="games/mahjong/README.md"><b>Mahjong</b></a></td>
<td align="center"><img src="docs/media/gallery/rider.gif" alt="Rider: the endless run, jumps off glowing ramps with double flips and perfect landings"><br><a href="games/rider/README.md"><b>Rider</b></a></td>
+ <td align="center"><img src="docs/media/gallery/snowrider.gif" alt="Snow Rider 3D: sledding through the snowmen and stumps"><br><a href="games/snowrider/README.md"><b>Snow Rider 3D</b></a></td>
</tr>
<tr>
- <td align="center"><img src="docs/media/gallery/snowrider.gif" alt="Snow Rider 3D: sledding through the snowmen and stumps"><br><a href="games/snowrider/README.md"><b>Snow Rider 3D</b></a></td>
<td align="center"><img src="docs/media/gallery/templerun.gif" alt="Temple Run: the runner bursts out of the temple's door and the camera goes after him along the path"><br><a href="games/templerun/README.md"><b>Temple Run</b></a></td>
<td align="center"><img src="docs/media/gallery/fnaf2.gif" alt="Five Nights at Freddy's 2: the light down the hallway, the music box wound on CAM 11, Toy Bonnie in the right vent and the mask on"><br><a href="games/fnaf2/README.md"><b>Five Nights at Freddy's 2</b></a></td>
+ <td align="center"><img src="docs/media/gallery/famidash.gif" alt="Famidash: in Stereo Madness the cube jumps from pillar to pillar, through a portal and past a coin"><br><a href="games/famidash/README.md"><b>Famidash</b></a></td>
</tr>
<tr>
- <td align="center"><img src="docs/media/gallery/famidash.gif" alt="Famidash: in Stereo Madness the cube jumps from pillar to pillar, through a portal and past a coin"><br><a href="games/famidash/README.md"><b>Famidash</b></a></td>
<td align="center"><img src="docs/media/gallery/fnaf3.gif" alt="Five Nights at Freddy's 3: the office, the monitor up, CAM 07 and the audio lure played"><br><a href="games/fnaf3/README.md"><b>Five Nights at Freddy's 3</b></a></td>
<td align="center"><img src="docs/media/gallery/fnaf4.gif" alt="Five Nights at Freddy's 4: the bedroom, a run to the left door, the flashlight down the hall, then the bed"><br><a href="games/fnaf4/README.md"><b>Five Nights at Freddy's 4</b></a></td>
</tr>
diff --git a/docs/media/gallery/turborush.gif b/docs/media/gallery/turborush.gif
deleted file mode 100644
index 478354d9..00000000
Binary files a/docs/media/gallery/turborush.gif and /dev/null differ
diff --git a/docs/media/thumb_turborush.png b/docs/media/thumb_turborush.png
deleted file mode 100644
index 591d33f0..00000000
Binary files a/docs/media/thumb_turborush.png and /dev/null differ
diff --git a/docs/play.md b/docs/play.md
index 5a02d196..d78934f4 100644
--- a/docs/play.md
+++ b/docs/play.md
@@ -613,23 +613,6 @@ Press each arrow as it reaches the line at the top. Sick, Good, Bad and Shit dep
<br clear="right">
-## Turbo Rush
-
-<img src="../games/turborush/docs/shot.png" width="320" align="right" alt="Turbo Rush">
-
-| Key | What it does |
-| --- | --- |
-| **Up** | Accelerate |
-| **Down** | Brake |
-| **Left, Right** | Steer |
-| **OK** | Nitro |
-| **+, -** | Change gear (manual gearbox) |
-| **Back** | Pause (with Restart race, How to play and Quit game) |
-
-Three laps against seven rivals. A bend pulls you outwards, more the faster you go, so brake before the sharp ones. The grass slows you, and trees, lamps and buildings stop you and damage the car. Races pay credits for the engine, tires, nitro and armor in the garage. Play one race, the six circuits as a Grand Prix, or Free Ride. Home saves the race, and Continue picks it up.
-
-<br clear="right">
-
## Angry Birds
<img src="../games/angrybirds/docs/shot.png" width="320" align="right" alt="Angry Birds">
diff --git a/games/games.json b/games/games.json
index b7116273..fd711ded 100644
--- a/games/games.json
+++ b/games/games.json
@@ -1153,27 +1153,7 @@
"default": false,
"xl": true
},
- {
- "id": "turborush",
- "rank": 22,
- "title": "Turbo Rush",
- "tagline": "Race seven rivals on six circuits",
- "credit": "A game by Bobydeluxe",
- "top": "0x3C8CCB",
- "bottom": "0x1A2630",
- "accent": "0xFFD052",
- "colors": 16,
- "records": [
- "turborush.sav",
- "turborush_saves.py"
- ],
- "shots": [
- "docs/shot.png"
- ],
- "repo": "https://github.com/Mason363/NumPlay/tree/main/games/turborush",
- "default": false,
- "xl": true
- },
+
{
"id": "angrybirds",
"rank": 5,
diff --git a/games/turborush/.gitignore b/games/turborush/.gitignore
deleted file mode 100644
index 342d9dda..00000000
--- a/games/turborush/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-output/
-build/
diff --git a/games/turborush/Makefile b/games/turborush/Makefile
deleted file mode 100644
index d03788e6..00000000
--- a/games/turborush/Makefile
+++ /dev/null
@@ -1,71 +0,0 @@
-# Turbo Rush on the NumWorks calculator.
-# make output/turborush.nwa
-# make check link it like the calculator does (output/turborush.bin)
-# make host build/play: the game on a computer, for tests and pictures
-# make test laps, crashes, the rivals finishing every circuit at every level, the Grand Prix and Free Ride,
-# saves (kept, damaged), random keys, the same race twice (with the sanitizers)
-#
-# The pictures are in art/ (indexed PNGs); tools/art.py packs them into $(BUILD_DIR)/gen (Python 3 with Pillow and
-# numpy).
-Q ?= @
-CC = arm-none-eabi-gcc
-NWLINK ?= npx --yes -- [email protected]
-PYTHON ?= python3
-BUILD_DIR = output
-GEN = $(BUILD_DIR)/gen
-L = ../../launcher/src
-
-SRC = src/main.c src/track.c src/race.c src/save.c src/view.c src/draw.c src/plat_eadk.c \
- $(L)/gfx.c $(L)/font_data.c $(L)/xfont.c $(GEN)/art.c
-HEADERS = $(wildcard src/*.h) $(GEN)/art.h $(L)/gfx.h $(L)/font.h $(L)/np.h ../common/epsilon_app.h \
- ../common/epsilon_files.h
-ART = $(wildcard art/*.png art/*/*.png)
-
-CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DPLATFORM_DEVICE=1 -DEPSILON_XL=1 -I$(L) -Isrc -I$(GEN)
-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
-CFLAGS += -ffunction-sections -fdata-sections
-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 art
-build: $(BUILD_DIR)/turborush.nwa
-
-# apps get 133652 bytes of RAM on custom builds of Epsilon 25.2 (148928 or more on official ones)
-check: $(BUILD_DIR)/turborush.nwa
- $(Q) $(NWLINK) nwa-bin --ram-length 133652 $< $(BUILD_DIR)/turborush.bin
- @echo "BIN $(BUILD_DIR)/turborush.bin: $$(wc -c < $(BUILD_DIR)/turborush.bin) bytes"
-
-$(BUILD_DIR)/turborush.nwa: $(SRC) $(HEADERS) $(BUILD_DIR)/icon.o
- @echo "LD $@"
- $(Q) $(CC) $(CFLAGS) $(LDFLAGS) $(SRC) $(BUILD_DIR)/icon.o -lm -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 $@
-
-$(GEN)/art.c: tools/art.py $(ART)
- @echo "ART $(GEN)"
- $(Q) $(PYTHON) -I tools/art.py art $(GEN)
-$(GEN)/art.h: $(GEN)/art.c
-art: $(GEN)/art.c
-
-# on a computer: tests/play.c drives races and the whole app, and saves pictures
-HOST_SRC = tests/play.c src/track.c src/race.c src/save.c src/view.c src/draw.c \
- $(L)/gfx.c $(L)/font_data.c $(L)/xfont.c $(GEN)/art.c
-HOST_FLAGS = -std=gnu11 -O2 -g -Wall -Wextra -Wno-unused-parameter -ffp-contract=off -Isrc -I$(L) -I$(GEN) -DHOST
-host: build/play
-build/play: $(HOST_SRC) src/main.c $(wildcard src/*.h) $(GEN)/art.h
- $(Q) mkdir -p build
- $(Q) cc $(HOST_FLAGS) -fsanitize=address,undefined -fno-sanitize-recover=undefined $(HOST_SRC) -lm -o $@
- @echo "HOST $@"
-test: build/play
- build/play test build
-
-clean:
- $(Q) rm -rf $(BUILD_DIR) build
diff --git a/games/turborush/README.md b/games/turborush/README.md
deleted file mode 100644
index 4822d6b2..00000000
--- a/games/turborush/README.md
+++ /dev/null
@@ -1,89 +0,0 @@
-> **Turbo Rush is a [NumPlay](../../README.md) game that comes on its own.** It is too big to fit next to NumPlay on the calculator. Get `TurboRush.nwa` from the [latest release](https://github.com/Mason363/NumPlay/releases/latest).
-
-<p align="center">
- <img src="src/icon.png" width="84" alt="Turbo Rush icon">
-</p>
-
-<h1 align="center">Turbo Rush</h1>
-
-<p align="center">
- <b>An arcade racer for the NumWorks calculator.</b><br>
- Six circuits, seven rivals, a Grand Prix and a garage.
-</p>
-
-<p align="center">
- <a href="https://github.com/Mason363/NumPlay/releases/latest/download/TurboRush.nwa"><b>Download TurboRush.nwa</b></a>
- &nbsp;·&nbsp; <a href="#controls">Controls</a>
-</p>
-
-<p align="center">
- <img src="../../docs/media/gallery/turborush.gif" width="640" alt="Turbo Rush: racing along Sunset Coast, passing a rival before a bend">
-</p>
-
-## Highlights
-
-* **Six circuits:** Sunset Coast, Pine Valley, Red Rock Run, Harbor Sprint, Alpine Pass and Metro Circuit, each with its own bends, hills and roadside.
-* **Seven rivals** who brake for the bends, pass each other and leave you room, at three levels: Easy, Normal and Expert.
-* **Grand Prix:** the six circuits in a row, with 15, 12, 10, 8, 6, 4, 2 and 1 points a race and a bonus for the top of the table.
-* **Single races and Free Ride:** one circuit against the field, or as long as you like in light, normal or busy traffic.
-* **The garage:** every race pays credits for the engine, tires, nitro and armor, four levels each. Eight paints and two bodies are free.
-* **Your way:** day, sunset or night, clear or rain, automatic or manual gears.
-* **Saved as you go:** Home saves and quits, even in the middle of a race, and Continue picks it up. Your progress is also copied into `turborush_saves.py`, so installing the app again doesn't erase it.
-
-<table>
- <tr>
- <td align="center"><img src="docs/shot.png" width="390" alt="Racing on Sunset Coast"><br><sub>Sunset Coast: seven rivals ahead</sub></td>
- <td align="center"><img src="docs/alpine.png" width="390" alt="Climbing Alpine Pass"><br><sub>Alpine Pass, its hairpins and climbs</sub></td>
- </tr>
- <tr>
- <td align="center"><img src="docs/desert.png" width="390" alt="Red Rock Run at sunset"><br><sub>Red Rock Run at sunset</sub></td>
- <td align="center"><img src="docs/night.png" width="390" alt="Metro Circuit at night"><br><sub>Metro Circuit at night</sub></td>
- </tr>
- <tr>
- <td align="center"><img src="docs/rain.png" width="390" alt="Pine Valley in the rain"><br><sub>Pine Valley in the rain</sub></td>
- <td align="center"><img src="docs/standings.png" width="390" alt="The Grand Prix table"><br><sub>The Grand Prix table after a race</sub></td>
- </tr>
- <tr>
- <td align="center"><img src="docs/garage.png" width="390" alt="The garage"><br><sub>The garage: upgrades, paint and body</sub></td>
- <td align="center"><img src="docs/setup.png" width="390" alt="Choosing a race"><br><sub>Choosing a race</sub></td>
- </tr>
-</table>
-
-## How to play
-
-You start at the back of the grid. Hold **Up** to accelerate, steer with **Left** and **Right**, and finish three laps ahead of as many rivals as you can. The map at the top right shows where everyone is.
-
-A bend pulls you outwards, more the faster you go: brake before the sharp ones (the blue arrows warn you) and steer into them. The grass slows you down, and trees, lamps and buildings stop you dead and damage the car; at 100% damage the race is over. Bumping a rival hurts too. **OK** burns nitro for a burst of speed, and it refills by itself.
-
-Every race pays credits, more the better you finish. Spend them in the garage: the engine raises your top speed, tires hold the bends better, nitro refills faster, and armor takes the sting out of crashes. With the engine and tires up, Expert rivals are yours to beat.
-
-## Controls
-
-| Key | What it does |
-| --- | --- |
-| Up | Accelerate |
-| Down | Brake |
-| Left and Right | Steer |
-| OK or EXE | Nitro |
-| + and - | Change gear, with the manual gearbox |
-| Back | Pause (Resume, Restart race, How to play, Quit game) |
-| Home | Save and quit |
-
-In the menus, the arrows choose, **OK** picks and **Back** goes back. 8, 4, 6, 2 and 5 work as the arrows and OK.
-
-## Good to know
-
-* **On its own:** Turbo Rush is too big to fit next to NumPlay. Installing it from the NumWorks website swaps out NumPlay and the other apps, and installing NumPlay again swaps it back out. Your progress in each one is kept.
-* **Quit game** in the pause menu asks first, and can take you back to the main menu instead. The race is kept either way.
-* There is no music or sound: the calculator has no speaker.
-
-## Credits
-
-A game by **Bobydeluxe**, made for NumPlay, inspired by [Turbo Rush](https://jeux.w-production.fr/#/jeu/turborush) by W Production. Not affiliated with W Production.
-
-* The cars, the roadside and the four landscapes were made for the game by Bobydeluxe.
-* The text uses NumPlay's **Nunito** font (SIL Open Font License).
-
-## License
-
-The game's code and pictures are licensed under the GNU General Public License v3.0: see the `LICENSE` file at the root of the repository. Nunito keeps the SIL Open Font License (`LICENSES/OFL-1.1-Nunito.txt`).
diff --git a/games/turborush/art/cars.png b/games/turborush/art/cars.png
deleted file mode 100644
index b6b96ad8..00000000
Binary files a/games/turborush/art/cars.png and /dev/null differ
diff --git a/games/turborush/art/scenery/cactus.png b/games/turborush/art/scenery/cactus.png
deleted file mode 100644
index dcfd16e6..00000000
Binary files a/games/turborush/art/scenery/cactus.png and /dev/null differ
diff --git a/games/turborush/art/scenery/lamp.png b/games/turborush/art/scenery/lamp.png
deleted file mode 100644
index c90120d2..00000000
Binary files a/games/turborush/art/scenery/lamp.png and /dev/null differ
diff --git a/games/turborush/art/scenery/palm.png b/games/turborush/art/scenery/palm.png
deleted file mode 100644
index 0d2fcb22..00000000
Binary files a/games/turborush/art/scenery/palm.png and /dev/null differ
diff --git a/games/turborush/art/scenery/pine.png b/games/turborush/art/scenery/pine.png
deleted file mode 100644
index 81e26dbf..00000000
Binary files a/games/turborush/art/scenery/pine.png and /dev/null differ
diff --git a/games/turborush/art/scenery/rock.png b/games/turborush/art/scenery/rock.png
deleted file mode 100644
index 0b2c83e3..00000000
Binary files a/games/turborush/art/scenery/rock.png and /dev/null differ
diff --git a/games/turborush/art/scenery/sign.png b/games/turborush/art/scenery/sign.png
deleted file mode 100644
index 5d22e566..00000000
Binary files a/games/turborush/art/scenery/sign.png and /dev/null differ
diff --git a/games/turborush/art/scenery/tower.png b/games/turborush/art/scenery/tower.png
deleted file mode 100644
index 2cdc267d..00000000
Binary files a/games/turborush/art/scenery/tower.png and /dev/null differ
diff --git a/games/turborush/art/scenery/villa.png b/games/turborush/art/scenery/villa.png
deleted file mode 100644
index b7986480..00000000
Binary files a/games/turborush/art/scenery/villa.png and /dev/null differ
diff --git a/games/turborush/art/sky/alps.png b/games/turborush/art/sky/alps.png
deleted file mode 100644
index 10f7b581..00000000
Binary files a/games/turborush/art/sky/alps.png and /dev/null differ
diff --git a/games/turborush/art/sky/city.png b/games/turborush/art/sky/city.png
deleted file mode 100644
index 1e80e115..00000000
Binary files a/games/turborush/art/sky/city.png and /dev/null differ
diff --git a/games/turborush/art/sky/coast.png b/games/turborush/art/sky/coast.png
deleted file mode 100644
index 7cb32b68..00000000
Binary files a/games/turborush/art/sky/coast.png and /dev/null differ
diff --git a/games/turborush/art/sky/desert.png b/games/turborush/art/sky/desert.png
deleted file mode 100644
index 9acd28b1..00000000
Binary files a/games/turborush/art/sky/desert.png and /dev/null differ
diff --git a/games/turborush/docs/alpine.png b/games/turborush/docs/alpine.png
deleted file mode 100644
index 0ec61392..00000000
Binary files a/games/turborush/docs/alpine.png and /dev/null differ
diff --git a/games/turborush/docs/desert.png b/games/turborush/docs/desert.png
deleted file mode 100644
index dccdf7a5..00000000
Binary files a/games/turborush/docs/desert.png and /dev/null differ
diff --git a/games/turborush/docs/garage.png b/games/turborush/docs/garage.png
deleted file mode 100644
index ba073fc3..00000000
Binary files a/games/turborush/docs/garage.png and /dev/null differ
diff --git a/games/turborush/docs/night.png b/games/turborush/docs/night.png
deleted file mode 100644
index d4c9796d..00000000
Binary files a/games/turborush/docs/night.png and /dev/null differ
diff --git a/games/turborush/docs/rain.png b/games/turborush/docs/rain.png
deleted file mode 100644
index f5f55df7..00000000
Binary files a/games/turborush/docs/rain.png and /dev/null differ
diff --git a/games/turborush/docs/setup.png b/games/turborush/docs/setup.png
deleted file mode 100644
index eae2e287..00000000
Binary files a/games/turborush/docs/setup.png and /dev/null differ
diff --git a/games/turborush/docs/shot.png b/games/turborush/docs/shot.png
deleted file mode 100644
index c4bf1565..00000000
Binary files a/games/turborush/docs/shot.png and /dev/null differ
diff --git a/games/turborush/docs/standings.png b/games/turborush/docs/standings.png
deleted file mode 100644
index 0545a2d5..00000000
Binary files a/games/turborush/docs/standings.png and /dev/null differ
diff --git a/games/turborush/docs/title.png b/games/turborush/docs/title.png
deleted file mode 100644
index 17d9b41e..00000000
Binary files a/games/turborush/docs/title.png and /dev/null differ
diff --git a/games/turborush/src/draw.c b/games/turborush/src/draw.c
deleted file mode 100644
index d753f16d..00000000
--- a/games/turborush/src/draw.c
+++ /dev/null
@@ -1,645 +0,0 @@
-/* Turbo Rush's screens: the title over a race of rivals, the race screen and the garage, the race's dials, and the
- * pause, results and standings over the race. Each has a line of plain keys at the bottom. */
-#include <string.h>
-#include "../../../launcher/src/gfx.h"
-#include "draw.h"
-#include "view.h"
-
-#define WHITE 0xFFFF
-#define INK HEX(0x0E1A26)
-#define PANEL HEX(0x13212F)
-#define GOLD HEX(0xFFD052)
-#define MUTED HEX(0xA9BDC6)
-#define DIM HEX(0x5F7480)
-#define RED HEX(0xFF6F55)
-
-/* the launcher's drawing (gfx.c) draws a strip of the screen at a time, and sends it here */
-void plat_push(int x, int y, int w, int h, const uint16_t *px);
-void np_push(int x, int y, int w, int h, const color_t *px) { plat_push(x, y, w, h, px); }
-static color_t strip[SCREEN_W * STRIP_H];
-
-const char *const tr_driver[TR_CARS] = {"You", "Rosa", "Kenji", "Marco", "Ines", "Theo", "Ava", "Luca"};
-static const char *const MODES[3] = {"Grand Prix", "Single race", "Free Ride"};
-static const char *const LEVELS[3] = {"Easy", "Normal", "Expert"};
-static const char *const TRAFFIC[3] = {"Light", "Normal", "Busy"};
-static const char *const MOODS[3] = {"Day", "Sunset", "Night"};
-static const char *const UPGRADES[4] = {"Engine", "Tires", "Nitro", "Armor"};
-static const char *const BODIES[2] = {"Coupe", "Supercar"};
-
-static const tr_file *F;
-static const tr_track *T;
-static const tr_race *R, *RP;
-static const tr_ui *U;
-static int A;
-
-/* ------------------------------------------------------------------ text */
-static char *cat(char *p, const char *s) {
- while (*s) *p++ = *s++;
- *p = 0;
- return p;
-}
-static char *num(char *p, uint32_t v) {
- char t[12];
- int n = 0;
- do t[n++] = (char)('0' + v % 10); while ((v /= 10) && n < 11);
- while (n) *p++ = t[--n];
- *p = 0;
- return p;
-}
-static char *clock_of(char *p, uint32_t ms) {
- p = num(p, ms / 60000);
- *p++ = ':', *p++ = (char)('0' + ms / 10000 % 6), *p++ = (char)('0' + ms / 1000 % 10), *p++ = '.';
- *p++ = (char)('0' + ms / 100 % 10), *p = 0;
- return p;
-}
-static char *ordinal(char *p, int n) {
- p = num(p, (uint32_t)n);
- return cat(p, n == 1 ? "st" : n == 2 ? "nd" : n == 3 ? "rd" : "th");
-}
-static char *km(char *p, uint32_t fx) {
- uint32_t m = fx / FX;
- p = num(p, m / 1000);
- *p++ = '.', *p++ = (char)('0' + m / 100 % 10);
- return cat(p, " km");
-}
-
-static void text(const np_font_t *f, int x, int y, const char *s, color_t c) { gfx_text(f, x, y, s, c, 256); }
-static void center(const np_font_t *f, int x, int y, const char *s, color_t c) { gfx_text_center(f, x, y, s, c, 256); }
-static void right(const np_font_t *f, int x, int y, const char *s, color_t c) { gfx_text_right(f, x, y, s, c, 256); }
-
-/* ------------------------------------------------------------------ pieces */
-/* a line of keys: "Up Down=choose|OK=open", each key in gold, what it does after it */
-static void key_line(int y, const char *s) {
- char buf[48];
- int w = 0;
- for (int pass = 0; pass < 2; pass++) {
- int x = 160 - w / 2;
- w = 0;
- const char *q = s;
- while (*q) {
- int k = 0;
- while (q[k] && q[k] != '=' && q[k] != '|' && k < (int)sizeof buf - 1) k++;
- memcpy(buf, q, (size_t)k), buf[k] = 0;
- bool key = q[k] == '=';
- int tw = gfx_text_width(&np_font_small, buf);
- if (pass) text(&np_font_small, x + w, y, buf, key ? GOLD : MUTED);
- w += tw + (key ? 4 : 0);
- q += k;
- if (*q == '=') q++;
- else if (*q == '|') q++, w += 11;
- }
- }
-}
-
-static void keys(const char *s) {
- gfx_fill(0, 222, 320, 18, INK);
- gfx_fill(0, 222, 320, 1, HEX(0x2A3D4C));
- key_line(235, s);
-}
-
-static void page(const char *title) {
- gfx_vgrad(0, 0, 320, 222, 0x0E1C29, 0x1D3747);
- text(&np_font_title, 14, 30, title, WHITE);
- char s[24];
- cat(num(s, F->p.credits), " credits");
- right(&np_font_small, 306, 28, s, GOLD);
-}
-
-static void button(int x, int y, int w, const char *s, bool on) {
- gfx_rrect(x, y, w, 26, 6, on ? GOLD : PANEL, 256);
- if (!on) gfx_rrect_outline(x, y, w, 26, 6, 1, HEX(0x2E4556), 256);
- center(&np_font_body, x + w / 2, y + 18, s, on ? INK : WHITE);
-}
-
-static void dim(void) { gfx_fill_alpha(0, 0, 320, 240, HEX(0x050A10), 150); }
-
-/* when the calculator's storage is full, say so above the keys */
-static void not_saved(void) {
- if (!U->save_failed) return;
- gfx_rrect(40, 204, 240, 17, 5, HEX(0x5A1E1A), 240);
- center(&np_font_small, 160, 216, "Storage full: progress not saved", WHITE);
-}
-
-static void bar(int x, int y, int w, int h, int v, int max, color_t c) {
- gfx_rrect(x, y, w, h, h / 2, HEX(0x24384A), 256);
- int f = v * w / max;
- if (f > 0) gfx_rrect(x, y, f < h ? h : f, h, h / 2, c, 256);
-}
-
-static void logo(int y) {
- const np_font_t *f = &np_font_title;
- const char *s = "TURBO RUSH";
- int w = gfx_text_width(f, s) * 2, x0 = (320 - w) / 2;
- for (int pass = 0; pass < 2; pass++) {
- int x = x0 + (pass ? 0 : 2), base = y + (pass ? 0 : 2);
- color_t c = pass ? GOLD : HEX(0x7A2A22);
- for (const char *q = s; *q; q++) {
- const np_glyph_t *g = &f->glyphs[(uint8_t)*q - f->first];
- const uint8_t *m = f->data + g->offset;
- for (int gy = 0; gy < g->h; gy++) {
- int yy = base + (g->y + gy) * 2;
- if (yy + 2 <= gfx_y0 || yy >= gfx_y1) continue;
- for (int gx = 0; gx < g->w; gx++) {
- int k = gy * g->w + gx, cov = (m[k / 2] >> ((k & 1) * 4)) & 15;
- /* a little slant: the top leans right */
- int lean = (g->h - gy) / 3;
- if (cov) gfx_fill_alpha(x + (g->x + gx) * 2 + lean, yy, 2, 2, c, cov * 17);
- }
- }
- x += g->advance * 2;
- }
- }
-}
-
-/* a circuit's outline: a soft edge, a light line, the start line */
-static void outline(int x, int y, const int16_t *mx, const int16_t *my) {
- for (int pass = 0; pass < 2; pass++)
- for (int i = 0; i < VIEW_MAP; i++) {
- int j = (i + 1) % VIEW_MAP, x0 = x + mx[i], y0 = y + my[i], x1 = x + mx[j], y1 = y + my[j];
- int n = NP_MAX(NP_MAX(x1 - x0, x0 - x1), NP_MAX(y1 - y0, y0 - y1));
- for (int k = 0; k <= n; k++) {
- int px = x0 + (n ? (x1 - x0) * k / n : 0), py = y0 + (n ? (y1 - y0) * k / n : 0);
- if (pass) gfx_fill(px, py, 1, 1, HEX(0xE6ECEF));
- else gfx_fill(px - 1, py - 1, 3, 3, HEX(0x8195A0));
- }
- }
- gfx_fill(x + mx[0] - 1, y + my[0] - 3, 2, 6, WHITE);
-}
-
-static void map(int x, int y, const tr_race *r, bool dots) {
- outline(x, y, view_map_x, view_map_y);
- int sx, sy;
- if (!dots || !r) return;
- for (int i = TR_CARS - 1; i >= 0; i--) {
- if (i && i > tr_traffic(r)) continue;
- view_map_at(T, r->car[i].z, &sx, &sy);
- if (i) gfx_circle(x + sx, y + sy, 2, view_paint(r->car[i].paint), 256);
- }
- view_map_at(T, r->car[0].z, &sx, &sy);
- gfx_circle(x + sx, y + sy, 4, WHITE, 256);
- gfx_circle(x + sx, y + sy, 3, view_paint(r->car[0].paint), 256);
-}
-
-/* ------------------------------------------------------------------ the race's dials */
-static void hud(void) {
- const tr_race *r = R;
- char s[40], *p;
- bool free = r->mode == MODE_FREE;
- /* place and lap, or distance and cars passed */
- gfx_rrect(6, 6, 98, 40, 6, INK, 215);
- if (free) {
- text(&np_font_small, 14, 19, "DISTANCE", MUTED);
- km(s, r->odometer);
- text(&np_font_body, 14, 38, s, WHITE);
- } else {
- text(&np_font_small, 14, 19, "POS", MUTED);
- text(&np_font_small, 62, 19, "LAP", MUTED);
- num(s, (uint32_t)tr_rank(r, 0));
- int w = gfx_text(&np_font_title, 14, 40, s, WHITE, 256);
- text(&np_font_body, 14 + w + 1, 40, "/8", MUTED);
- p = num(s, r->lap);
- cat(cat(p, "/"), "3");
- text(&np_font_body, 62, 40, s, WHITE);
- }
- /* the clock */
- gfx_rrect(112, 6, 96, free ? 26 : 40, 6, INK, 215);
- if (free) {
- p = cat(s, "Passed ");
- num(p, r->passes);
- center(&np_font_body, 160, 24, s, WHITE);
- } else {
- clock_of(s, r->time_ms);
- center(&np_font_body, 160, 23, s, WHITE);
- if (r->best_lap_ms) {
- p = cat(s, "BEST ");
- clock_of(p, r->best_lap_ms);
- center(&np_font_small, 160, 38, s, MUTED);
- } else {
- center(&np_font_small, 160, 38, tr_track_name[r->track], MUTED);
- }
- }
- /* the map */
- gfx_rrect(232, 6, 82, 62, 6, INK, 200);
- map(237, 11, r, true);
- /* the dials at the bottom: speed | gear | nitro | damage, then the keys */
- gfx_fill_alpha(0, 202, 320, 25, INK, 230);
- gfx_fill(0, 202, 320, 1, HEX(0x2E4556));
- gfx_fill(0, 227, 320, 13, HEX(0x08111A));
- for (int k = 0; k < 3; k++) gfx_fill((int[]){88, 124, 218}[k], 207, 1, 16, HEX(0x2E4556));
- num(s, (uint32_t)tr_kmh(r->car[0].v));
- right(&np_font_title, 52, 224, s, WHITE);
- text(&np_font_small, 56, 224, "km/h", MUTED);
- text(&np_font_small, 94, 213, "GEAR", MUTED);
- s[0] = (char)('0' + r->gear), s[1] = 0;
- center(&np_font_body, 106, 225, s, r->manual ? GOLD : WHITE);
- text(&np_font_small, 130, 213, "NITRO", MUTED);
- if (r->nitro_lock) right(&np_font_small, 212, 213, "refilling", DIM);
- bar(130, 216, 82, 7, r->nitro, 1000, r->boost ? HEX(0x9BE7FF) : r->nitro_lock ? HEX(0x47708C) : HEX(0x3FB6F0));
- if (free) {
- text(&np_font_small, 224, 213, "TRAFFIC", MUTED);
- center(&np_font_body, 268, 225, TRAFFIC[r->level], WHITE);
- } else {
- text(&np_font_small, 224, 213, "DAMAGE", MUTED);
- p = num(s, r->damage / 10u);
- cat(p, "%");
- right(&np_font_small, 312, 213, s, r->impact ? RED : WHITE);
- bar(224, 216, 88, 7, r->damage, 1000, r->damage > 700 ? RED : HEX(0xF0A94E));
- }
- key_line(237, r->manual ? "Up=gas|Down=brake|OK=nitro|+ -=gears|Back=pause" : "Up=gas|Down=brake|OK=nitro|Back=pause");
- /* the start, a lap, the finish */
- if (r->phase == PH_GRID || (U->hold && U->screen == V_RACE)) {
- int n = r->phase == PH_GRID ? (r->countdown + TR_HZ - 1) / TR_HZ : U->hold;
- gfx_rrect(110, 54, 100, 48, 8, INK, 225);
- if (n > 3) {
- center(&np_font_body, 160, 74, tr_track_name[r->track], WHITE);
- center(&np_font_small, 160, 92, "Get ready", MUTED);
- } else {
- s[0] = (char)('0' + n), s[1] = 0;
- center(&np_font_title, 160, 86, s, GOLD);
- }
- } else if (!free && r->phase == PH_RACE && r->time_ms < 1000) {
- gfx_rrect(110, 54, 100, 48, 8, INK, 225);
- center(&np_font_title, 160, 86, "GO!", GOLD);
- } else if (r->banner_t || r->phase == PH_DONE) {
- int b = r->banner_t ? r->banner : r->end == END_FINISH ? BANNER_FINISH : r->end == END_WRECK ? BANNER_WRECK : BANNER_TIME;
- const char *big = "";
- char t[24];
- t[0] = 0;
- if (b == BANNER_LAP || b == BANNER_FINAL) {
- if (b == BANNER_FINAL) big = "Final lap";
- else p = cat(s, "Lap "), num(p, r->banner_arg), big = s;
- clock_of(t, r->last_lap_ms);
- } else if (b == BANNER_FINISH) {
- big = "Finish!";
- ordinal(t, r->car[0].place);
- } else if (b == BANNER_WRECK) {
- big = "Wrecked";
- cat(t, "Too much damage");
- } else {
- big = "Time up";
- }
- gfx_rrect(90, 54, 140, t[0] ? 54 : 40, 8, INK, 225);
- center(&np_font_title, 160, 82, big, b == BANNER_WRECK || b == BANNER_TIME ? RED : GOLD);
- if (t[0]) center(&np_font_body, 160, 101, t, WHITE);
- }
-}
-
-/* ------------------------------------------------------------------ screens */
-static void title(void) {
- gfx_fill_alpha(0, 0, 320, 240, HEX(0x050A10), 70);
- for (int y = 0; y < 84; y += 4) gfx_fill_alpha(0, y, 320, 4, HEX(0x050A10), 150 - y * 150 / 84);
- logo(44);
- center(&np_font_small, 160, 64, "A game by Bobydeluxe", WHITE);
- static const char *const NAMES[5] = {"Continue", "Play", "Garage", "Records", "How to play"};
- int n = U->menu_n, y0 = 132 - n * 15;
- for (int i = 0; i < n; i++) {
- int item = U->menu[i];
- const char *s = NAMES[item];
- if (item == MENU_CONTINUE)
- s = !F->has_race ? "Next Grand Prix race" : F->race.mode == MODE_GP ? "Continue Grand Prix"
- : F->race.mode == MODE_FREE ? "Continue ride" : "Continue race";
- button(70, y0 + i * 30, 180, s, U->sel == i);
- }
- not_saved();
- keys("Up Down=choose|OK=open|Back=quit");
-}
-
-static void setup(void) {
- page("RACE");
- const tr_profile *p = &F->p;
- static const char *const NAMES[SET_ROWS] = {"Mode", "Circuit", "Rivals", "Time of day", "Weather", "Gearbox", ""};
- for (int i = 0; i < SET_START; i++) {
- int y = 40 + i * 24;
- bool on = U->sel == i, off = i == SET_TRACK && p->mode == MODE_GP;
- gfx_rrect(10, y, 186, 21, 5, on ? GOLD : PANEL, 256);
- color_t c = on ? INK : off ? DIM : WHITE;
- const char *name = i == SET_RIVALS && p->mode == MODE_FREE ? "Traffic" : NAMES[i];
- text(&np_font_small, 18, y + 15, name, c);
- const char *v = "";
- switch (i) {
- case SET_MODE: v = MODES[p->mode]; break;
- case SET_TRACK: v = p->mode == MODE_GP ? "All six" : tr_track_name[p->track]; break;
- case SET_RIVALS: v = p->mode == MODE_FREE ? TRAFFIC[p->traffic] : LEVELS[p->level]; break;
- case SET_TIME: v = MOODS[p->mood]; break;
- case SET_WEATHER: v = p->rain ? "Rain" : "Clear"; break;
- case SET_GEARS: v = p->manual ? "Manual" : "Automatic"; break;
- }
- right(&np_font_small, off ? 188 : 180, y + 15, v, c);
- if (!off) text(&np_font_small, 184, y + 15, ">", on ? INK : DIM);
- }
- /* the circuit */
- gfx_rrect(204, 40, 106, 141, 6, PANEL, 256);
- int track = p->mode == MODE_GP ? 0 : p->track;
- static int16_t mx[VIEW_MAP], my[VIEW_MAP];
- static int shown = -1;
- if (shown != track) tr_map(track, VIEW_MAP, mx, my, 72, 52), shown = track;
- center(&np_font_small, 257, 56, p->mode == MODE_GP ? "First race" : "Circuit", MUTED);
- outline(222, 66, mx, my);
- center(&np_font_small, 257, 136, tr_track_name[track], WHITE);
- center(&np_font_small, 257, 151, tr_track_note[track], MUTED);
- char s[24];
- if (F->p.best_ms[track]) {
- clock_of(cat(s, "Best "), F->p.best_ms[track]);
- center(&np_font_small, 257, 170, s, GOLD);
- }
- const char *go = p->mode == MODE_GP ? "Start Grand Prix" : p->mode == MODE_FREE ? "Start Free Ride" : "Start race";
- button(10, 190, 300, go, U->sel == SET_START);
- keys(U->sel == SET_START ? "OK=start|Up Down=choose|Back=menu" : "Left Right=change|Up Down=choose|Back=menu");
-}
-
-static void confirm_box(const char *q, const char *note, int n, const char *const *labels) {
- dim();
- int h = 70 + n * 32;
- gfx_rrect(40, 120 - h / 2, 240, h, 8, INK, 256);
- center(&np_font_body, 160, 120 - h / 2 + 28, q, WHITE);
- if (note) center(&np_font_small, 160, 120 - h / 2 + 46, note, MUTED);
- for (int i = 0; i < n; i++) button(60, 120 - h / 2 + 58 + i * 32, 200, labels[i], U->sel == i);
-}
-
-static void help_page(int k, bool guide) {
- page(guide ? "BEFORE YOU RACE" : "HOW TO PLAY");
- static const char *const TITLES[TR_HELP_PAGES] = {"Keys", "Racing", "Grand Prix and garage"};
- center(&np_font_body, 160, 56, TITLES[k], GOLD);
- if (k == 0) {
- static const char *const K[7][2] = {{"Up", "Accelerate"}, {"Down", "Brake"}, {"Left Right", "Steer"},
- {"OK or EXE", "Nitro"}, {"+ and -", "Gears, if manual"},
- {"Back", "Pause"}, {"Home", "Save and quit"}};
- for (int i = 0; i < 7; i++) {
- int y = 66 + i * 20;
- gfx_rrect(40, y, 240, 18, 4, PANEL, 256);
- text(&np_font_small, 50, y + 13, K[i][0], GOLD);
- text(&np_font_small, 140, y + 13, K[i][1], WHITE);
- }
- } else {
- static const char *const L[2][6] = {
- {"Three laps against seven rivals.", "Brake before the sharp bends,", "or the bend pulls you off the road.",
- "Grass slows you down. Trees, lamps", "and buildings stop you and hurt the car.", "At 100% damage the race is over."},
- {"Six circuits, one after the other:", "points 15 12 10 8 6 4 2 1.", "Every race pays credits:",
- "spend them in the garage.", "Free Ride: just you and the traffic,", "as long as you like."}};
- for (int i = 0; i < 6; i++) center(&np_font_small, 160, 84 + i * 21, L[k - 1][i], WHITE);
- }
- for (int i = 0; i < TR_HELP_PAGES; i++) gfx_circle(148 + i * 12, 212, 3, i == k ? GOLD : DIM, 256);
- keys(guide ? "OK=start the race|Left Right=page|Back=return" : "Left Right=page|Back=return");
-}
-
-static void garage(void) {
- page("GARAGE");
- const tr_profile *p = &F->p;
- gfx_vgrad(10, 38, 300, 58, 0x1A2E3C, 0x253F4F);
- gfx_fill(10, 88, 300, 8, HEX(0x1A2A35));
- view_car(160, 92, 96, p->paint, p->style, 1);
- char s[40], *q;
- for (int i = 0; i < 4; i++) {
- int y = 112 + i * 18;
- bool on = U->sel == i;
- gfx_rrect(10, y, 300, 16, 4, on ? GOLD : PANEL, 256);
- color_t c = on ? INK : WHITE;
- text(&np_font_small, 18, y + 12, UPGRADES[i], c);
- for (int k = 0; k < 4; k++)
- gfx_rrect(96 + k * 16, y + 5, 12, 7, 2, k < p->up[i] ? (on ? INK : GOLD) : (on ? HEX(0xB8952F) : HEX(0x3A5060)), 256);
- unsigned cost = tr_price(p, i);
- if (cost) cat(num(s, cost), " credits");
- else cat(s, "Full");
- right(&np_font_small, 302, y + 12, s, on ? INK : cost && cost > p->credits ? DIM : GOLD);
- }
- int y = 184;
- gfx_rrect(10, y, 300, 16, 4, U->sel == GAR_PAINT ? GOLD : PANEL, 256);
- text(&np_font_small, 18, y + 12, "Paint", U->sel == GAR_PAINT ? INK : WHITE);
- for (int i = 0; i < 8; i++) {
- int x = 96 + i * 26;
- if (i == p->paint) gfx_rrect(x - 2, y + 1, 22, 14, 3, U->sel == GAR_PAINT ? INK : WHITE, 256);
- gfx_rrect(x, y + 3, 18, 10, 2, view_paint(i), 256);
- }
- y = 202;
- gfx_rrect(10, y, 300, 16, 4, U->sel == GAR_BODY ? GOLD : PANEL, 256);
- text(&np_font_small, 18, y + 12, "Body", U->sel == GAR_BODY ? INK : WHITE);
- q = cat(s, "< ");
- q = cat(q, BODIES[p->style]);
- cat(q, " >");
- right(&np_font_small, 302, y + 12, s, U->sel == GAR_BODY ? INK : WHITE);
- /* what the chosen row does, or the garage's last word */
- const char *line = U->note;
- char d[48];
- if (!line[0]) {
- int i = U->sel, lv = i < 4 ? p->up[i] : 0;
- q = d;
- switch (i) {
- case GAR_ENGINE:
- q = cat(q, "Top speed ");
- q = num(q, (uint32_t)((61 + 3 * lv) * 36 / 10));
- if (lv < 4) q = cat(q, " > "), q = num(q, (uint32_t)((64 + 3 * lv) * 36 / 10));
- cat(q, " km/h");
- break;
- case GAR_TIRES:
- q = cat(q, "Grip in bends ");
- q = num(q, (uint32_t)(100 + 6 * lv));
- if (lv < 4) q = cat(q, "% > "), q = num(q, (uint32_t)(106 + 6 * lv));
- cat(q, "%");
- break;
- case GAR_NITRO:
- q = cat(q, "Refills in ");
- q = num(q, (uint32_t)(1000 / (2 + lv) / TR_HZ));
- if (lv < 4) q = cat(q, " s > "), q = num(q, (uint32_t)(1000 / (3 + lv) / TR_HZ));
- cat(q, " s");
- break;
- case GAR_ARMOR:
- q = cat(q, "Crash damage ");
- q = num(q, (uint32_t)((12 - 2 * lv) * 100 / 12));
- if (lv < 4) q = cat(q, "% > "), q = num(q, (uint32_t)((10 - 2 * lv) * 100 / 12));
- cat(q, "%");
- break;
- default: cat(q, "Free"); break;
- }
- line = d;
- }
- center(&np_font_small, 160, 107, line, U->note[0] ? GOLD : MUTED);
- keys(U->sel < 4 ? "OK=buy|Up Down=choose|Back=return" : "Left Right=change|Up Down=choose|Back=return");
-}
-
-static void records(void) {
- page("RECORDS");
- text(&np_font_small, 168, 50, "Race", MUTED);
- text(&np_font_small, 244, 50, "Lap", MUTED);
- char s[24];
- for (int i = 0; i < TR_TRACKS; i++) {
- int y = 56 + i * 24;
- gfx_rrect(10, y, 300, 21, 5, PANEL, 256);
- text(&np_font_small, 18, y + 15, tr_track_name[i], WHITE);
- if (F->p.best_ms[i]) clock_of(s, F->p.best_ms[i]);
- else cat(s, "-");
- text(&np_font_small, 168, y + 15, s, F->p.best_ms[i] ? GOLD : DIM);
- if (F->p.best_lap_ms[i]) clock_of(s, F->p.best_lap_ms[i]);
- else cat(s, "-");
- text(&np_font_small, 244, y + 15, s, F->p.best_lap_ms[i] ? GOLD : DIM);
- }
- char t[64], *q = cat(t, "Races ");
- q = num(q, F->p.races);
- q = cat(q, " Wins ");
- q = num(q, F->p.wins);
- q = cat(q, " Grand Prix won ");
- num(q, F->p.titles);
- center(&np_font_small, 160, 211, t, MUTED);
- keys("Back=menu");
-}
-
-static void result(void) {
- dim();
- gfx_rrect(30, 10, 260, 210, 8, INK, 256);
- char s[48], *q;
- const tr_race *r = R;
- if (r->end == END_FINISH) {
- q = ordinal(s, U->result_rank);
- cat(q, U->result_rank == 1 ? " place!" : " place");
- } else {
- cat(s, r->end == END_WRECK ? "Wrecked" : "Time up");
- }
- center(&np_font_title, 160, 38, s, r->end == END_FINISH ? GOLD : RED);
- center(&np_font_small, 160, 54, tr_track_name[r->track], MUTED);
- if (r->end == END_FINISH) {
- clock_of(cat(s, "Time "), r->car[0].finish_ms);
- center(&np_font_body, 160, 74, s, WHITE);
- }
- if (r->best_lap_ms) {
- clock_of(cat(s, "Best lap "), r->best_lap_ms);
- center(&np_font_small, 160, 90, s, WHITE);
- }
- q = cat(s, "+");
- q = num(q, U->prize);
- q = cat(q, " credits");
- if (r->mode == MODE_GP) {
- q = cat(q, " +");
- q = num(q, U->gained[0]);
- cat(q, U->gained[0] == 1 ? " point" : " points");
- }
- center(&np_font_body, 160, 109, s, GOLD);
- if ((U->new_best || U->new_lap) && !U->save_failed) center(&np_font_small, 160, 126, U->new_best ? "New circuit record!" : "New lap record!", GOLD);
- const char *a = r->mode == MODE_GP ? "Standings" : "Race again";
- int by = U->save_failed ? 120 : 134, gap = U->save_failed ? 27 : 29;
- button(50, by, 220, a, U->sel == 0);
- button(50, by + gap, 220, "Garage", U->sel == 1);
- button(50, by + 2 * gap, 220, "Main menu", U->sel == 2);
- if (U->save_failed) not_saved();
- keys("Up Down=choose|OK=select");
-}
-
-static void standings(void) {
- dim();
- gfx_rrect(16, 8, 288, 210, 8, INK, 256);
- char s[48], *q;
- bool final = U->round_done >= TR_TRACKS;
- if (final) {
- q = cat(s, "Grand Prix: ");
- ordinal(q, U->final_rank);
- } else {
- q = cat(s, "Grand Prix, race ");
- q = num(q, U->round_done);
- cat(q, " of 6");
- }
- center(&np_font_body, 160, 28, s, final && U->final_rank == 1 ? GOLD : WHITE);
- uint8_t order[TR_CARS];
- for (int i = 0; i < TR_CARS; i++) order[i] = (uint8_t)i;
- for (int i = 1; i < TR_CARS; i++) { /* by points; on a tie, the order of the table */
- uint8_t v = order[i];
- int j = i;
- while (j > 0 && U->points[order[j - 1]] < U->points[v]) order[j] = order[j - 1], j--;
- order[j] = v;
- }
- for (int k = 0; k < TR_CARS; k++) {
- int i = order[k], y = 36 + k * 17;
- bool you = i == 0;
- gfx_rrect(26, y, 268, 15, 3, you ? HEX(0x2C4A5E) : PANEL, 256);
- num(s, (uint32_t)k + 1);
- text(&np_font_small, 32, y + 11, s, MUTED);
- int paint = you ? F->p.paint : (F->p.paint + i) & 7;
- gfx_rrect(48, y + 4, 12, 7, 2, view_paint(paint), 256);
- text(&np_font_small, 66, y + 11, tr_driver[i], you ? GOLD : WHITE);
- if (U->gained[i]) {
- q = cat(s, "+");
- num(q, U->gained[i]);
- right(&np_font_small, 236, y + 11, s, MUTED);
- }
- num(s, U->points[i]);
- right(&np_font_small, 284, y + 11, s, you ? GOLD : WHITE);
- }
- if (final) {
- q = cat(s, "+");
- q = num(q, U->bonus);
- cat(q, " credits");
- center(&np_font_small, 160, 181, s, GOLD);
- }
- int nb = final ? 2 : 3;
- static const char *const MID[3] = {"Next race", "Garage", "Menu"};
- static const char *const END[2] = {"Main menu", "Garage"};
- for (int i = 0; i < nb; i++) {
- int w = nb == 3 ? 88 : 132, x = 26 + i * (w + (nb == 3 ? 2 : 4));
- button(x, 188, w, final ? END[i] : MID[i], U->sel == i);
- }
- keys("Left Right=choose|OK=select");
-}
-
-static void race_screen(void) {
- hud();
- if (U->screen == V_PAUSE) {
- static const char *const L[PAUSE_ROWS] = {"Resume", "Restart race", "How to play", "Quit game"};
- dim();
- gfx_rrect(60, 34, 200, 168, 8, INK, 256);
- center(&np_font_title, 160, 62, "PAUSED", WHITE);
- for (int i = 0; i < PAUSE_ROWS; i++) {
- const char *s = i == PAUSE_RESTART && R->mode == MODE_FREE ? "Restart ride" : L[i];
- button(80, 76 + i * 30, 160, s, U->sel == i);
- }
- keys("Up Down=choose|OK=select|Back=resume");
- } else if (U->screen == V_LEAVE) {
- static const char *const L[3] = {"Keep racing", "Main menu", "Quit Turbo Rush"};
- confirm_box(R->mode == MODE_FREE ? "Leave the ride?" : "Leave the race?", "It's kept: Continue picks it up.", 3, L);
- keys("Up Down=choose|OK=select|Back=pause");
- } else if (U->screen == V_RESULT) {
- result();
- } else if (U->screen == V_STANDINGS) {
- standings();
- }
-}
-
-static void scene(void *ctx) {
- (void)ctx;
- switch (U->screen) {
- case V_SETUP: setup(); break;
- case V_NEWRUN: {
- setup();
- static const char *const L[2] = {"Keep it", "Start new"};
- confirm_box("Start something new?", F->gp.on ? "The Grand Prix under way will end." : "The race you left will end.",
- 2, L);
- keys("Up Down=choose|OK=select|Back=return");
- break;
- }
- case V_GUIDE: help_page(U->page, true); break;
- case V_HELP: help_page(U->page, false); break;
- case V_GARAGE: garage(); break;
- case V_RECORDS: records(); break;
- case V_TITLE:
- case V_QUIT:
- view_draw();
- title();
- if (U->screen == V_QUIT) {
- static const char *const L[2] = {"Stay", "Quit"};
- confirm_box("Quit Turbo Rush?", NULL, 2, L);
- keys("Up Down=choose|OK=select|Back=return");
- }
- break;
- default:
- view_draw();
- race_screen();
- break;
- }
-}
-
-void tr_render(const tr_file *f, const tr_track *t, const tr_race *prev, const tr_race *race, int alpha, const tr_ui *ui) {
- F = f, T = t, R = race, RP = prev, U = ui, A = alpha;
- int s = ui->screen;
- if (s == V_TITLE || s == V_QUIT || s == V_RACE || s == V_PAUSE || s == V_LEAVE || s == V_RESULT || s == V_STANDINGS)
- view_frame(t, prev, race, alpha);
- color_t *old = gfx_buf;
- gfx_buf = strip;
- gfx_render(scene, 0, 0, 240);
- gfx_buf = old;
-}
diff --git a/games/turborush/src/draw.h b/games/turborush/src/draw.h
deleted file mode 100644
index 30a4fa5c..00000000
--- a/games/turborush/src/draw.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/* The screens (draw.c): menus, the race's dials, results. */
-#ifndef TR_DRAW_H
-#define TR_DRAW_H
-#include "game.h"
-#include "save.h"
-
-enum {
- V_TITLE, V_SETUP, V_NEWRUN, V_GUIDE, V_GARAGE, V_RECORDS, V_HELP, V_RACE, V_PAUSE, V_LEAVE, V_RESULT, V_STANDINGS,
- V_QUIT, V_SCREENS
-};
-enum { SET_MODE, SET_TRACK, SET_RIVALS, SET_TIME, SET_WEATHER, SET_GEARS, SET_START, SET_ROWS };
-enum { GAR_ENGINE, GAR_TIRES, GAR_NITRO, GAR_ARMOR, GAR_PAINT, GAR_BODY, GAR_ROWS };
-enum { PAUSE_RESUME, PAUSE_RESTART, PAUSE_HELP, PAUSE_QUIT, PAUSE_ROWS };
-enum { MENU_CONTINUE, MENU_PLAY, MENU_GARAGE, MENU_RECORDS, MENU_HELP };
-#define TR_HELP_PAGES 3
-
-typedef struct {
- uint8_t screen, sel, page, under; /* under: where Back goes from the garage or how to play */
- uint8_t menu[5], menu_n; /* the title's buttons */
- uint8_t result_rank, new_best, new_lap, final_rank;
- uint8_t gained[TR_CARS]; /* Grand Prix points from the last race */
- uint16_t points[TR_CARS]; /* the standings shown */
- uint8_t round_done; /* races of the Grand Prix driven, for the standings */
- uint8_t hold; /* a race going on again: 3, 2, 1 */
- uint32_t prize, bonus, clock;
- char note[48]; /* the garage's last word */
- bool save_failed;
-} tr_ui;
-
-extern const char *const tr_driver[TR_CARS];
-/* the whole screen; race: the race shown (the one going, the title's demo, or the last one) */
-void tr_render(const tr_file *f, const tr_track *t, const tr_race *prev, const tr_race *race, int alpha,
- const tr_ui *ui);
-#endif
diff --git a/games/turborush/src/game.h b/games/turborush/src/game.h
deleted file mode 100644
index 67d9d34b..00000000
--- a/games/turborush/src/game.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/* Turbo Rush's rules: the circuits (track.c) and the race (race.c), in whole numbers only, so that a race comes out
- * the same on the calculator and on every computer.
- *
- * Distances are in 1/256 metre and speeds in 1/256 metre a second (FX); the race moves on in steps of 20 ms. */
-#ifndef TR_GAME_H
-#define TR_GAME_H
-#include <stdbool.h>
-#include <stdint.h>
-
-#define FX 256
-#define TR_TRACKS 6
-#define TR_CARS 8
-#define TR_LAPS 3
-#define TR_SEG 5 /* metres of road per segment */
-#define TR_MAXSEG 600 /* segments in a lap, at most */
-#define TR_ROAD (7 * FX) /* half the road's width */
-#define TR_LANE (14 * FX / 3) /* the three lanes: -TR_LANE, 0 and TR_LANE */
-#define TR_OUT (20 * FX) /* how far from the road a car can go */
-#define TR_CAR_LEN (21 * FX / 5) /* cars touch nearer than this, front to back (4.2 m)... */
-#define TR_CAR_WID (23 * FX / 10) /* ...and side by side (2.3 m) */
-#define TR_TICK 20 /* ms per step */
-#define TR_HZ 50
-
-enum { MODE_GP, MODE_RACE, MODE_FREE };
-enum { LEVEL_EASY, LEVEL_NORMAL, LEVEL_EXPERT };
-enum { MOOD_DAY, MOOD_SUNSET, MOOD_NIGHT };
-enum { PH_GRID, PH_RACE, PH_DONE }; /* PH_DONE: you're over the line or out of the race */
-enum { END_NONE, END_FINISH, END_WRECK, END_TIME };
-enum { IN_GAS = 1, IN_BRAKE = 2, IN_LEFT = 4, IN_RIGHT = 8, IN_NITRO = 16 };
-enum { UP_ENGINE, UP_TIRES, UP_NITRO, UP_ARMOR };
-enum { SC_PALM, SC_PINE, SC_ROCK, SC_TOWER, SC_SIGN, SC_CACTUS, SC_VILLA, SC_LAMP, SC_KINDS };
-enum { SKY_COAST, SKY_ALPS, SKY_DESERT, SKY_CITY };
-enum { TH_COAST, TH_VALLEY, TH_DESERT, TH_HARBOR, TH_ALPINE, TH_METRO };
-
-/* ------------------------------------------------------------------ circuits (track.c) */
-typedef struct {
- uint16_t n; /* segments in a lap */
- int32_t length; /* n * TR_SEG * FX */
- uint8_t id, sky, theme;
- int8_t curve[TR_MAXSEG]; /* the bend: centimetres the road turns per segment, per segment (+ right) */
- int16_t y[TR_MAXSEG + 1]; /* height at the start of each segment, in centimetres */
- uint8_t limit[TR_MAXSEG]; /* the speed (m/s) a car with plain tyres can carry here, braking included */
- uint16_t heading[TR_MAXSEG + 1]; /* which way the road points, in 1/65536 of a turn */
-} tr_track;
-
-typedef struct {
- int8_t kind; /* SC_..., or -1: nothing */
- bool flip;
- int32_t x; /* across the road (FX) */
- int32_t half; /* half its width at the ground, for crashes (FX) */
- int32_t height; /* (FX) */
-} tr_thing;
-
-extern const char *const tr_track_name[TR_TRACKS];
-extern const char *const tr_track_note[TR_TRACKS];
-void tr_build(tr_track *t, int id);
-int tr_seg_of(const tr_track *t, int32_t z); /* the segment under z (any lap, negative too) */
-int tr_curve_at(const tr_track *t, int32_t z);
-int32_t tr_height_at(const tr_track *t, int32_t z); /* (FX) */
-tr_thing tr_scenery(const tr_track *t, int seg, int side); /* what stands at a segment, side -1 or 1 */
-int tr_map(int id, int n, int16_t *xs, int16_t *ys, int w, int h); /* the circuit's outline, fit in w x h */
-int32_t tr_wrap(const tr_track *t, int32_t dz); /* a gap brought into half a lap either way */
-
-/* ------------------------------------------------------------------ the race (race.c) */
-typedef struct {
- int32_t z; /* distance from the start line (negative on the grid) */
- int32_t x; /* across the road, 0 the middle, + right */
- int32_t v; /* speed */
- int32_t vx; /* sideways speed */
- int32_t lane; /* a rival: where it wants to be */
- int32_t cruise; /* Free Ride traffic: the speed it keeps */
- uint32_t finish_ms; /* race time at the finish line (0: not yet) */
- uint16_t think; /* a rival: steps to its next look round */
- uint16_t bump; /* steps before touching you hurts again */
- uint8_t paint, style, skill, place; /* place: finishing place, 0 before the line */
-} tr_car;
-
-typedef struct {
- uint8_t track, mode, level, mood, rain, manual, laps, phase;
- uint8_t end, gear, lap, boost; /* lap: yours, 1..laps; boost: nitro burning */
- uint8_t up[4], finished, offroad, banner, banner_arg;
- uint16_t countdown, nitro, damage, nitro_lock, impact, done, banner_t, spare;
- int16_t steer, cam_x;
- uint32_t ticks, time_ms, lap_ms, best_lap_ms, last_lap_ms, seed, odometer, passes;
- tr_car car[TR_CARS]; /* 0 is you */
- uint8_t ahead[TR_CARS]; /* Free Ride: that car is in front of you */
-} tr_race;
-
-enum { BANNER_NONE, BANNER_LAP, BANNER_FINAL, BANNER_FINISH, BANNER_WRECK, BANNER_TIME };
-
-typedef struct {
- uint8_t track, mode, level, mood, rain, manual, paint, style;
- uint8_t up[4];
- const uint8_t *skill; /* the rivals' skills (a Grand Prix keeps them), or NULL: shuffled */
-} tr_setup;
-void tr_new(tr_race *r, tr_track *t, const tr_setup *s, uint32_t seed);
-void tr_step(tr_race *r, const tr_track *t, unsigned input, int shift);
-bool tr_valid(const tr_race *r);
-int tr_top_speed(const uint8_t up[4]); /* m/s */
-int tr_kmh(int32_t v);
-int tr_rank(const tr_race *r, int car); /* 1..8: by finish, then by distance */
-void tr_order(const tr_race *r, uint8_t order[TR_CARS]); /* the cars, first to last */
-int tr_traffic(const tr_race *r); /* Free Ride: cars on the road with you */
-uint32_t tr_rng(uint32_t *s);
-#endif
diff --git a/games/turborush/src/icon.png b/games/turborush/src/icon.png
deleted file mode 100644
index 73383807..00000000
Binary files a/games/turborush/src/icon.png and /dev/null differ
diff --git a/games/turborush/src/main.c b/games/turborush/src/main.c
deleted file mode 100644
index f607f525..00000000
--- a/games/turborush/src/main.c
+++ /dev/null
@@ -1,482 +0,0 @@
-/* Turbo Rush, an arcade racer for the NumWorks calculator, by Bobydeluxe: six circuits, a Grand Prix, single
- * races and Free Ride, rivals at three levels and a garage. The rules are in race.c and track.c, the view in
- * view.c, the screens in draw.c and the save in save.c.
- *
- * Keys: Up accelerates, Down brakes, Left and Right steer, OK (or EXE) burns nitro, + and - change gear with the
- * manual gearbox, Back pauses; Home saves and quits, from anywhere. */
-#include <string.h>
-#include "draw.h"
-#include "game.h"
-#include "plat.h"
-#include "save.h"
-#include "view.h"
-
-static tr_file sv; /* what's kept: your profile, a Grand Prix, the race going on */
-static tr_track track; /* the circuit built (the race's, or the title's) */
-static tr_race prev, demo, demo_prev;
-static tr_ui ui;
-static uint32_t now, saved_at, hold_at, demo_at;
-static int32_t accum;
-static int pending_shift;
-static int shown_track = -1, shown_mood = -1, shown_rain = -1;
-static uint32_t frame_gap; /* the least ms between frames (the tests draw fewer) */
-/* frames drawn, the slowest (ms) and those over 33 ms: read by tools/emu.py */
-#ifndef HOST
-__attribute__((used, externally_visible))
-#endif
-uint32_t perf_frames, perf_max, perf_slow;
-
-static const uint16_t PRIZE[TR_CARS] = {500, 350, 250, 190, 140, 100, 75, 50};
-static const uint8_t POINTS[TR_CARS] = {15, 12, 10, 8, 6, 4, 2, 1};
-
-static char *cat(char *p, const char *s) {
- while (*s) *p++ = *s++;
- *p = 0;
- return p;
-}
-static char *num(char *p, uint32_t v) {
- char t[12];
- int n = 0;
- do t[n++] = (char)('0' + v % 10); while ((v /= 10) && n < 11);
- while (n) *p++ = t[--n];
- *p = 0;
- return p;
-}
-
-static void save(void) {
- ui.save_failed = !save_write(&sv);
- saved_at = now;
-}
-
-/* the circuit and its colours, when they change */
-static void show(const tr_race *r) {
- if (r->track != shown_track || track.id != r->track || track.n == 0) {
- tr_build(&track, r->track);
- shown_track = r->track, shown_mood = -1;
- }
- if (r->mood != shown_mood || r->rain != shown_rain) {
- view_setup(&track, r->mood, r->rain);
- shown_mood = r->mood, shown_rain = r->rain;
- }
-}
-
-static tr_setup setup_of(int mode, int id) {
- tr_setup s;
- memset(&s, 0, sizeof s);
- s.track = (uint8_t)id, s.mode = (uint8_t)mode;
- s.level = mode == MODE_FREE ? sv.p.traffic : sv.p.level;
- s.mood = sv.p.mood, s.rain = sv.p.rain, s.manual = sv.p.manual, s.paint = sv.p.paint, s.style = sv.p.style;
- memcpy(s.up, sv.p.up, 4);
- s.skill = mode == MODE_GP ? sv.gp.skill : NULL;
- return s;
-}
-
-/* ------------------------------------------------------------------ the title's race */
-static void demo_start(void) {
- tr_setup s = setup_of(MODE_RACE, sv.p.track);
- s.level = LEVEL_EXPERT;
- tr_new(&demo, &track, &s, 0x7A5Eu ^ now);
- shown_track = demo.track, shown_mood = -1;
- for (int i = 0; i < TR_CARS; i++) {
- tr_car *c = &demo.car[i];
- c->z = (40 + i * 22) * FX;
- c->x = c->lane = (i % 3 - 1) * TR_LANE;
- c->v = (44 + i) * FX;
- }
- demo.phase = PH_DONE, demo.end = END_FINISH, demo.countdown = 0, demo.time_ms = 2000;
- demo_prev = demo;
- demo_at = now;
- show(&demo);
-}
-
-static void title_menu(void) {
- int n = 0;
- if (sv.has_race || sv.gp.on) ui.menu[n++] = MENU_CONTINUE;
- ui.menu[n++] = MENU_PLAY, ui.menu[n++] = MENU_GARAGE, ui.menu[n++] = MENU_RECORDS, ui.menu[n++] = MENU_HELP;
- ui.menu_n = (uint8_t)n;
-}
-
-static void to_title(void) {
- ui.screen = V_TITLE, ui.sel = 0;
- title_menu();
- demo_start();
-}
-
-/* ------------------------------------------------------------------ races */
-static void race_begin(int mode, int id) {
- tr_setup s = setup_of(mode, id);
- tr_new(&sv.race, &track, &s, plat_random() ^ now);
- shown_track = sv.race.track, shown_mood = -1;
- show(&sv.race);
- prev = sv.race;
- sv.has_race = 1;
- ui.screen = V_RACE, ui.sel = 0, ui.hold = 0;
- accum = 0, pending_shift = 0;
- save();
-}
-
-static void gp_new(void) {
- memset(&sv.gp, 0, sizeof sv.gp);
- sv.gp.on = 1;
- uint32_t seed = plat_random() ^ now ^ 0x9E37u;
- for (int i = 0; i < TR_CARS - 1; i++) sv.gp.skill[i] = (uint8_t)i;
- for (int i = TR_CARS - 2; i > 0; i--) {
- int j = (int)(tr_rng(&seed) % (uint32_t)(i + 1));
- uint8_t x = sv.gp.skill[i];
- sv.gp.skill[i] = sv.gp.skill[j], sv.gp.skill[j] = x;
- }
-}
-
-/* what you picked on the race screen */
-static void start_new(void) {
- sv.has_race = 0;
- memset(&sv.gp, 0, sizeof sv.gp);
- if (sv.p.mode == MODE_GP) gp_new(), race_begin(MODE_GP, 0);
- else race_begin(sv.p.mode, sv.p.track);
-}
-
-static void start_or_guide(void) {
- if (!sv.p.guide) {
- ui.screen = V_GUIDE, ui.page = 0;
- return;
- }
- start_new();
-}
-
-static void resume_saved(void) {
- show(&sv.race);
- prev = sv.race;
- ui.screen = V_RACE, ui.hold = 3, accum = 0, pending_shift = 0;
- hold_at = now + 500;
-}
-
-static void finish_race(void) {
- tr_race *r = &sv.race;
- tr_profile *p = &sv.p;
- bool fin = r->end == END_FINISH;
- int rank = tr_rank(r, 0);
- ui.result_rank = (uint8_t)rank;
- ui.prize = fin ? PRIZE[rank - 1] : 25;
- p->credits = p->credits + ui.prize > TR_MAX_CREDITS ? TR_MAX_CREDITS : p->credits + ui.prize;
- if (p->races < 999999) p->races++;
- if (fin && rank == 1) p->wins++;
- ui.new_best = ui.new_lap = 0;
- int id = r->track;
- if (fin && (!p->best_ms[id] || r->car[0].finish_ms < p->best_ms[id])) p->best_ms[id] = r->car[0].finish_ms, ui.new_best = 1;
- if (r->best_lap_ms && (!p->best_lap_ms[id] || r->best_lap_ms < p->best_lap_ms[id]))
- p->best_lap_ms[id] = r->best_lap_ms, ui.new_lap = 1;
- memset(ui.gained, 0, sizeof ui.gained);
- if (r->mode == MODE_GP && sv.gp.on) {
- uint8_t order[TR_CARS];
- tr_order(r, order);
- int k = 0;
- for (int i = 0; i < TR_CARS; i++) {
- int car = order[i];
- if (car == 0 && !fin) continue; /* out of the race: no points, the others move up */
- ui.gained[car] = POINTS[k++];
- }
- for (int i = 0; i < TR_CARS; i++) sv.gp.points[i] = (uint16_t)(sv.gp.points[i] + ui.gained[i]);
- memcpy(ui.points, sv.gp.points, sizeof ui.points);
- ui.round_done = (uint8_t)(sv.gp.round + 1);
- if (ui.round_done >= TR_TRACKS) {
- int place = 1;
- for (int i = 1; i < TR_CARS; i++)
- if (sv.gp.points[i] > sv.gp.points[0]) place++;
- ui.final_rank = (uint8_t)place;
- ui.bonus = (uint32_t)(9 - place) * 200;
- p->credits = p->credits + ui.bonus > TR_MAX_CREDITS ? TR_MAX_CREDITS : p->credits + ui.bonus;
- if (place == 1 && p->titles < p->races) p->titles++;
- memset(&sv.gp, 0, sizeof sv.gp);
- } else {
- sv.gp.round++;
- }
- }
- sv.has_race = 0;
- ui.screen = V_RESULT, ui.sel = 0;
- save();
-}
-
-/* ------------------------------------------------------------------ keys, screen by screen */
-static void set_change(int row, int d) {
- tr_profile *p = &sv.p;
- switch (row) {
- case SET_MODE: p->mode = (uint8_t)((p->mode + 3 + d) % 3); break;
- case SET_TRACK:
- if (p->mode != MODE_GP) p->track = (uint8_t)((p->track + TR_TRACKS + d) % TR_TRACKS);
- break;
- case SET_RIVALS:
- if (p->mode == MODE_FREE) p->traffic = (uint8_t)((p->traffic + 3 + d) % 3);
- else p->level = (uint8_t)((p->level + 3 + d) % 3);
- break;
- case SET_TIME: p->mood = (uint8_t)((p->mood + 3 + d) % 3); break;
- case SET_WEATHER: p->rain ^= 1; break;
- case SET_GEARS: p->manual ^= 1; break;
- }
-}
-
-static void garage_buy(int item) {
- tr_profile *p = &sv.p;
- static const char *const NAMES[4] = {"Engine", "Tires", "Nitro", "Armor"};
- unsigned price = tr_price(p, item);
- char *q = ui.note;
- if (!price) {
- cat(q, "Already at its best");
- } else if (p->credits < price) {
- q = cat(q, "You need ");
- q = num(q, price - p->credits);
- cat(q, " more credits");
- } else {
- p->credits -= price;
- p->up[item]++;
- q = cat(q, NAMES[item]);
- q = cat(q, " level ");
- num(q, p->up[item]);
- }
-}
-
-static bool keys_menu(uint32_t hit) {
- int n;
- switch (ui.screen) {
- case V_TITLE:
- n = ui.menu_n;
- if (hit & TK_UP) ui.sel = (uint8_t)((ui.sel + n - 1) % n);
- if (hit & TK_DOWN) ui.sel = (uint8_t)((ui.sel + 1) % n);
- if (hit & TK_BACK) ui.screen = V_QUIT, ui.sel = 0;
- else if (hit & TK_OK) switch (ui.menu[ui.sel % n]) {
- case MENU_CONTINUE:
- if (sv.has_race) resume_saved();
- else race_begin(MODE_GP, sv.gp.round);
- break;
- case MENU_PLAY: ui.screen = V_SETUP, ui.sel = SET_START; break;
- case MENU_GARAGE: ui.screen = V_GARAGE, ui.sel = 0, ui.under = V_TITLE, ui.note[0] = 0; break;
- case MENU_RECORDS: ui.screen = V_RECORDS; break;
- default: ui.screen = V_HELP, ui.page = 0, ui.under = V_TITLE; break;
- }
- break;
- case V_QUIT:
- if (hit & (TK_UP | TK_DOWN)) ui.sel ^= 1;
- if (hit & TK_BACK) ui.screen = V_TITLE, ui.sel = 0;
- else if (hit & TK_OK) {
- if (ui.sel) return true;
- ui.screen = V_TITLE, ui.sel = 0;
- }
- break;
- case V_SETUP: {
- int d = (hit & TK_DOWN) ? 1 : (hit & TK_UP) ? -1 : 0;
- if (d) {
- ui.sel = (uint8_t)((ui.sel + SET_ROWS + d) % SET_ROWS);
- if (ui.sel == SET_TRACK && sv.p.mode == MODE_GP) ui.sel = (uint8_t)((ui.sel + SET_ROWS + d) % SET_ROWS);
- }
- int dx = (hit & TK_RIGHT) ? 1 : (hit & TK_LEFT) ? -1 : 0;
- if (dx && ui.sel < SET_START) set_change(ui.sel, dx);
- if (hit & TK_BACK) {
- save();
- to_title();
- ui.sel = (uint8_t)(ui.menu_n - 4);
- } else if (hit & TK_OK) {
- if (ui.sel < SET_START) set_change(ui.sel, 1);
- else if (sv.has_race || sv.gp.on) ui.screen = V_NEWRUN, ui.sel = 0;
- else start_or_guide();
- }
- break;
- }
- case V_NEWRUN:
- if (hit & (TK_UP | TK_DOWN)) ui.sel ^= 1;
- if ((hit & TK_BACK) || ((hit & TK_OK) && !ui.sel)) ui.screen = V_SETUP, ui.sel = SET_START;
- else if (hit & TK_OK) {
- sv.has_race = 0;
- memset(&sv.gp, 0, sizeof sv.gp);
- start_or_guide();
- }
- break;
- case V_GUIDE:
- if ((hit & TK_RIGHT) && ui.page + 1 < TR_HELP_PAGES) ui.page++;
- if ((hit & TK_LEFT) && ui.page) ui.page--;
- if (hit & TK_BACK) ui.screen = V_SETUP, ui.sel = SET_START;
- else if (hit & TK_OK) sv.p.guide = 1, start_new();
- break;
- case V_HELP:
- if ((hit & TK_RIGHT) && ui.page + 1 < TR_HELP_PAGES) ui.page++;
- if ((hit & TK_LEFT) && ui.page) ui.page--;
- if (hit & (TK_BACK | TK_OK)) {
- if (ui.under == V_PAUSE) ui.screen = V_PAUSE, ui.sel = PAUSE_HELP;
- else to_title(), ui.sel = (uint8_t)(ui.menu_n - 1);
- }
- break;
- case V_RECORDS:
- if (hit & (TK_BACK | TK_OK)) to_title(), ui.sel = (uint8_t)(ui.menu_n - 2);
- break;
- case V_GARAGE: {
- int d = (hit & TK_DOWN) ? 1 : (hit & TK_UP) ? -1 : 0;
- int dx = (hit & TK_RIGHT) ? 1 : (hit & TK_LEFT) ? -1 : 0;
- if (d || dx) ui.note[0] = 0;
- if (d) ui.sel = (uint8_t)((ui.sel + GAR_ROWS + d) % GAR_ROWS);
- if (ui.sel == GAR_PAINT && (dx || (hit & TK_OK))) sv.p.paint = (uint8_t)((sv.p.paint + 8 + (dx ? dx : 1)) % 8);
- if (ui.sel == GAR_BODY && (dx || (hit & TK_OK))) sv.p.style ^= 1;
- if (ui.sel < 4 && (hit & TK_OK)) garage_buy(ui.sel);
- if (hit & TK_BACK) {
- save();
- if (ui.under == V_RESULT || ui.under == V_STANDINGS) ui.screen = ui.under, ui.sel = 1;
- else to_title(), ui.sel = (uint8_t)(ui.menu_n - 3);
- }
- break;
- }
- case V_PAUSE:
- if (hit & TK_UP) ui.sel = (uint8_t)((ui.sel + PAUSE_ROWS - 1) % PAUSE_ROWS);
- if (hit & TK_DOWN) ui.sel = (uint8_t)((ui.sel + 1) % PAUSE_ROWS);
- if (hit & TK_BACK) ui.screen = V_RACE;
- else if (hit & TK_OK) switch (ui.sel) {
- case PAUSE_RESUME: ui.screen = V_RACE; break;
- case PAUSE_RESTART: race_begin(sv.race.mode, sv.race.track); break;
- case PAUSE_HELP: ui.screen = V_HELP, ui.page = 0, ui.under = V_PAUSE; break;
- default: ui.screen = V_LEAVE, ui.sel = 0; break;
- }
- break;
- case V_LEAVE:
- if (hit & TK_UP) ui.sel = (uint8_t)((ui.sel + 2) % 3);
- if (hit & TK_DOWN) ui.sel = (uint8_t)((ui.sel + 1) % 3);
- if (hit & TK_BACK) ui.screen = V_PAUSE, ui.sel = PAUSE_QUIT;
- else if (hit & TK_OK) {
- if (ui.sel == 0) ui.screen = V_RACE;
- else if (ui.sel == 1) save(), to_title();
- else return true;
- }
- break;
- case V_RESULT:
- if (hit & TK_UP) ui.sel = (uint8_t)((ui.sel + 2) % 3);
- if (hit & TK_DOWN) ui.sel = (uint8_t)((ui.sel + 1) % 3);
- if (hit & TK_OK) {
- if (ui.sel == 0) {
- if (sv.race.mode == MODE_GP) ui.screen = V_STANDINGS, ui.sel = 0;
- else race_begin(sv.race.mode, sv.race.track);
- } else if (ui.sel == 1) {
- ui.screen = V_GARAGE, ui.under = V_RESULT, ui.sel = 0, ui.note[0] = 0;
- } else {
- to_title();
- }
- }
- break;
- case V_STANDINGS: {
- bool final = ui.round_done >= TR_TRACKS;
- int nb = final ? 2 : 3;
- if (hit & (TK_LEFT | TK_UP)) ui.sel = (uint8_t)((ui.sel + nb - 1) % nb);
- if (hit & (TK_RIGHT | TK_DOWN)) ui.sel = (uint8_t)((ui.sel + 1) % nb);
- if (hit & TK_OK) {
- int b = ui.sel % nb;
- if (b == 1) ui.screen = V_GARAGE, ui.under = V_STANDINGS, ui.sel = 0, ui.note[0] = 0;
- else if (!final && b == 0 && sv.gp.on) race_begin(MODE_GP, sv.gp.round);
- else to_title();
- }
- break;
- }
- }
- return false;
-}
-
-/* ------------------------------------------------------------------ the loop */
-static unsigned race_input(uint32_t keys) {
- unsigned in = 0;
- if (keys & TK_UP) in |= IN_GAS;
- if (keys & TK_DOWN) in |= IN_BRAKE;
- if (keys & TK_LEFT) in |= IN_LEFT;
- if (keys & TK_RIGHT) in |= IN_RIGHT;
- if (keys & TK_OK) in |= IN_NITRO;
- return in;
-}
-
-int main(void) {
- plat_begin();
- memset(&ui, 0, sizeof ui);
- now = plat_millis();
- save_load(&sv);
- to_title();
- uint32_t stale = plat_keys(), prev_keys = stale, rep_at = 0, last = now, frame_at = 0;
- uint8_t shown = 0xFF;
- bool dirty = true;
- uint32_t min_frame = frame_gap ? frame_gap : plat_slow() ? 30 : 18;
- for (;;) {
- now = plat_millis();
- uint32_t dt = now - last;
- if (dt > 100) dt = 100;
- last = now;
- uint32_t keys = plat_keys();
- stale &= keys; /* keys still held from the screen before don't count */
- uint32_t live = keys & ~stale, hit = live & ~prev_keys;
- if (ui.screen != V_RACE) { /* in menus, a held arrow repeats */
- uint32_t arrows = live & (TK_UP | TK_DOWN | TK_LEFT | TK_RIGHT);
- if (hit & arrows) rep_at = now + 350;
- else if (arrows && (int32_t)(now - rep_at) >= 0) hit |= arrows, rep_at = now + 110;
- }
- prev_keys = live;
- if (keys & TK_HOME) break; /* Home (or On/Off): saved below, then out */
- if (hit) dirty = true;
- bool quit = false;
- if (ui.screen == V_RACE) {
- if (hit & TK_BACK) {
- ui.screen = V_PAUSE, ui.sel = PAUSE_RESUME;
- save();
- } else if (ui.hold) {
- if ((int32_t)(now - hold_at) >= 0) ui.hold--, hold_at = now + 500, dirty = true;
- prev = sv.race;
- } else {
- if (hit & TK_GEAR_UP) pending_shift = 1;
- if (hit & TK_GEAR_DOWN) pending_shift = -1;
- accum += (int32_t)dt;
- unsigned in = race_input(live);
- while (accum >= TR_TICK) {
- prev = sv.race;
- tr_step(&sv.race, &track, in, pending_shift);
- pending_shift = 0;
- accum -= TR_TICK;
- if (sv.race.mode != MODE_FREE && sv.race.phase == PH_DONE && sv.race.done >= 3 * TR_HZ) {
- finish_race();
- break;
- }
- }
- if (ui.screen == V_RACE && (int32_t)(now - saved_at) >= 30000) save();
- }
- } else {
- quit = keys_menu(hit);
- }
- if (quit) break;
- if (ui.screen == V_TITLE || ui.screen == V_QUIT) {
- accum += (int32_t)dt;
- while (accum >= TR_TICK) {
- demo_prev = demo;
- tr_step(&demo, &track, 0, 0);
- accum -= TR_TICK;
- }
- if ((int32_t)(now - demo_at) >= 90000 || demo.finished == TR_CARS) demo_start();
- }
- if (ui.screen != shown) {
- stale = keys, prev_keys = 0; /* a new screen starts with all keys up */
- if (ui.screen != V_RACE && ui.screen != V_TITLE && ui.screen != V_QUIT) accum = 0;
- shown = ui.screen;
- dirty = true;
- }
- bool moving = ui.screen == V_RACE || ui.screen == V_TITLE || ui.screen == V_QUIT;
- if (dirty || (moving && now - frame_at >= min_frame)) {
- uint32_t t0 = plat_millis();
- ui.clock = now;
- int alpha = accum >= TR_TICK ? 256 : accum * 256 / TR_TICK;
- bool title = ui.screen == V_TITLE || ui.screen == V_QUIT;
- if (title) show(&demo);
- else if (ui.screen == V_RACE || ui.screen == V_PAUSE || ui.screen == V_LEAVE || ui.screen == V_RESULT ||
- ui.screen == V_STANDINGS)
- show(&sv.race);
- if ((ui.screen != V_RACE && !title) || ui.hold) alpha = 256;
- plat_vblank();
- tr_render(&sv, &track, title ? &demo_prev : &prev, title ? &demo : &sv.race, alpha, &ui);
- uint32_t spent = plat_millis() - t0;
- perf_frames++;
- if (spent > perf_max) perf_max = spent;
- if (spent > 33) perf_slow++;
- frame_at = now;
- dirty = false;
- } else {
- plat_sleep(moving ? 2 : 10);
- }
- }
- save();
- return plat_end();
-}
diff --git a/games/turborush/src/plat.h b/games/turborush/src/plat.h
deleted file mode 100644
index 91619eaf..00000000
--- a/games/turborush/src/plat.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* What the game needs from the calculator (plat_eadk.c), or from a computer for the tests. */
-#ifndef TR_PLAT_H
-#define TR_PLAT_H
-#include <stdbool.h>
-#include <stdint.h>
-
-/* (TK_: NumPlay's np.h has K_ keys of its own) */
-enum {
- TK_OK = 1, TK_UP = 2, TK_DOWN = 4, TK_LEFT = 8, TK_RIGHT = 16, TK_BACK = 32, TK_HOME = 64, TK_NITRO = 128,
- TK_GEAR_UP = 256, TK_GEAR_DOWN = 512
-};
-uint32_t plat_keys(void);
-uint32_t plat_millis(void);
-void plat_sleep(uint32_t ms);
-void plat_push(int x, int y, int w, int h, const uint16_t *px);
-void plat_vblank(void);
-bool plat_save(const char *name, const void *data, uint32_t len);
-const uint8_t *plat_load(const char *name, uint32_t *len);
-uint32_t plat_random(void);
-bool plat_slow(void); /* an N0110 or N0115 */
-void plat_begin(void);
-int plat_end(void);
-#endif
diff --git a/games/turborush/src/plat_eadk.c b/games/turborush/src/plat_eadk.c
deleted file mode 100644
index 8ecc33b0..00000000
--- a/games/turborush/src/plat_eadk.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/* The calculator: keys, time, the screen and files (EADK, and NumPlay's careful file helpers). */
-#include <eadk.h>
-#include "../../common/epsilon_app.h"
-#include "../../common/epsilon_files.h"
-#include "plat.h"
-
-const char eadk_app_name[] __attribute__((section(".rodata.eadk_app_name"))) = "Turbo Rush";
-const uint32_t eadk_api_level __attribute__((section(".rodata.eadk_api_level"))) = 0;
-
-#define KEY(k) ((uint64_t)1 << (k))
-
-uint32_t plat_keys(void) {
- uint64_t k = eadk_keyboard_scan();
- uint32_t r = 0;
- if (k & (KEY(eadk_key_ok) | KEY(eadk_key_exe) | KEY(eadk_key_five))) r |= TK_OK;
- if (k & (KEY(eadk_key_up) | KEY(eadk_key_eight))) r |= TK_UP;
- if (k & (KEY(eadk_key_down) | KEY(eadk_key_two))) r |= TK_DOWN;
- if (k & (KEY(eadk_key_left) | KEY(eadk_key_four))) r |= TK_LEFT;
- if (k & (KEY(eadk_key_right) | KEY(eadk_key_six))) r |= TK_RIGHT;
- if (k & (KEY(eadk_key_back) | KEY(eadk_key_backspace))) r |= TK_BACK;
- if (k & (KEY(eadk_key_home) | KEY(eadk_key_on_off))) r |= TK_HOME;
- if (k & KEY(eadk_key_plus)) r |= TK_GEAR_UP;
- if (k & KEY(eadk_key_minus)) r |= TK_GEAR_DOWN;
- return r;
-}
-uint32_t plat_millis(void) { return (uint32_t)eadk_timing_millis(); }
-void plat_sleep(uint32_t ms) { eadk_timing_msleep(ms); }
-void plat_push(int x, int y, int w, int h, const uint16_t *px) {
- eadk_display_push_rect((eadk_rect_t){(uint16_t)x, (uint16_t)y, (uint16_t)w, (uint16_t)h}, (const eadk_color_t *)px);
-}
-void plat_vblank(void) { eadk_display_wait_for_vblank(); }
-bool plat_save(const char *name, const void *data, uint32_t len) { return ef_write(name, data, len); }
-const uint8_t *plat_load(const char *name, uint32_t *len) { return ef_read(name, len); }
-uint32_t plat_random(void) { return eadk_random(); }
-bool plat_slow(void) { return epsilon_slow_model(); }
-void plat_begin(void) { np_app_begin(); }
-int plat_end(void) { return np_app_end(); }
diff --git a/games/turborush/src/race.c b/games/turborush/src/race.c
deleted file mode 100644
index 73c68f6d..00000000
--- a/games/turborush/src/race.c
+++ /dev/null
@@ -1,453 +0,0 @@
-/* The race, step by step (20 ms): your car, the rivals (or the traffic in Free Ride), what they bump into, laps
- * and the finish. Whole numbers only. */
-#include <string.h>
-#include "game.h"
-
-#define M(x) ((int32_t)((x) * FX)) /* metres (or m/s) to FX */
-#define ABS(v) ((v) < 0 ? -(v) : (v))
-#define CLAMP(v, a, b) ((v) < (a) ? (a) : (v) > (b) ? (b) : (v))
-
-static const uint8_t GEAR_TOP[6] = {0, 30, 48, 66, 84, 100}; /* each gear's top, % of the car's */
-
-uint32_t tr_rng(uint32_t *s) {
- uint32_t x = *s ? *s : 0x2545F491u;
- x ^= x << 13, x ^= x >> 17, x ^= x << 5;
- return *s = x;
-}
-
-int tr_top_speed(const uint8_t up[4]) { return 61 + 3 * up[UP_ENGINE]; }
-int tr_kmh(int32_t v) { return (int)((int64_t)v * 36 / (FX * 10)); }
-int tr_traffic(const tr_race *r) { return r->mode == MODE_FREE ? 2 + 2 * r->level : TR_CARS - 1; }
-static bool active(const tr_race *r, int i) { return i == 0 || i <= tr_traffic(r); }
-static int32_t race_end(const tr_race *r, const tr_track *t) { return (int32_t)r->laps * t->length; }
-
-void tr_new(tr_race *r, tr_track *t, const tr_setup *s, uint32_t seed) {
- memset(r, 0, sizeof *r);
- tr_build(t, s->track);
- r->track = t->id, r->mode = s->mode <= MODE_FREE ? s->mode : MODE_RACE, r->level = s->level <= 2 ? s->level : 1;
- r->mood = s->mood <= 2 ? s->mood : 0, r->rain = s->rain & 1, r->manual = s->manual & 1;
- for (int k = 0; k < 4; k++) r->up[k] = s->up[k] <= 4 ? s->up[k] : 4;
- r->seed = seed ? seed : 1;
- r->laps = r->mode == MODE_FREE ? 0 : TR_LAPS;
- r->phase = r->mode == MODE_FREE ? PH_RACE : PH_GRID;
- r->countdown = r->mode == MODE_FREE ? 0 : 3 * TR_HZ + TR_HZ / 2;
- r->nitro = 1000, r->gear = 1, r->lap = 1;
- tr_car *me = &r->car[0];
- me->paint = s->paint & 7, me->style = s->style & 1;
- /* the rivals: the other seven paints, skills 0 (slowest) to 6 shuffled, both bodies */
- uint8_t skills[TR_CARS - 1];
- for (int i = 0; i < TR_CARS - 1; i++) skills[i] = (uint8_t)i;
- for (int i = TR_CARS - 2; i > 0; i--) {
- int j = (int)(tr_rng(&r->seed) % (uint32_t)(i + 1));
- uint8_t x = skills[i];
- skills[i] = skills[j], skills[j] = x;
- }
- if (s->skill)
- for (int i = 0; i < TR_CARS - 1; i++) skills[i] = s->skill[i] < TR_CARS - 1 ? s->skill[i] : (uint8_t)i;
- for (int i = 1; i < TR_CARS; i++) {
- tr_car *c = &r->car[i];
- c->paint = (uint8_t)((me->paint + i) & 7);
- c->style = (uint8_t)((i + me->style) & 1);
- c->skill = skills[i - 1];
- c->think = (uint16_t)(10 + i * 3);
- }
- if (r->mode == MODE_FREE) {
- me->z = 0, me->x = 0;
- for (int i = 1; i <= tr_traffic(r); i++) {
- tr_car *c = &r->car[i];
- c->z = M(90) + (i - 1) * M(130) + (int32_t)(tr_rng(&r->seed) % 40) * FX;
- c->x = c->lane = ((int32_t)(tr_rng(&r->seed) % 3) - 1) * TR_LANE;
- c->v = c->cruise = M(22) + (int32_t)(tr_rng(&r->seed) % 14) * FX;
- r->ahead[i] = 1;
- }
- return;
- }
- /* the grid, behind the line: the best rival on pole, you at the back */
- for (int i = 1; i < TR_CARS; i++) {
- tr_car *c = &r->car[i];
- int slot = 6 - c->skill;
- c->z = -M(6) - slot * M(6);
- c->x = c->lane = slot & 1 ? M(2.4) : -M(2.4);
- }
- me->z = -M(6) - 7 * M(6), me->x = M(2.4);
- r->cam_x = (int16_t)(me->x * 3 / 4);
-}
-
-int tr_rank(const tr_race *r, int i) {
- int rank = 1;
- const tr_car *a = &r->car[i];
- for (int j = 0; j < TR_CARS; j++) {
- if (j == i) continue;
- const tr_car *b = &r->car[j];
- bool ahead = b->place ? !a->place || b->place < a->place : !a->place && (b->z > a->z || (b->z == a->z && j < i));
- if (ahead) rank++;
- }
- return rank;
-}
-
-void tr_order(const tr_race *r, uint8_t order[TR_CARS]) {
- for (int i = 0; i < TR_CARS; i++) order[tr_rank(r, i) - 1] = (uint8_t)i;
-}
-
-/* ------------------------------------------------------------------ your car */
-static int32_t top_of(const tr_race *r) {
- int32_t top = M(tr_top_speed(r->up));
- if (r->damage > 300) top -= top * (r->damage - 300) * 15 / (700 * 100); /* up to 15% slower when wrecked */
- return top;
-}
-
-static int auto_gear(int32_t v, int32_t top) {
- int g = 1;
- while (g < 5 && v >= top * GEAR_TOP[g] * 92 / 10000) g++;
- return g;
-}
-
-static void hit(tr_race *r, int32_t speed, int scale) {
- if (r->mode == MODE_FREE || speed < M(4)) return;
- int dmg = (int)(speed / FX) * scale * (12 - 2 * r->up[UP_ARMOR]) / 12 / 10;
- r->damage = (uint16_t)CLAMP(r->damage + dmg, 0, 1000);
- r->impact = 30;
-}
-
-/* the roadside: a tree, a lamp or a building where you are is solid */
-static void scenery_crash(tr_race *r, const tr_track *t) {
- tr_car *c = &r->car[0];
- if (ABS(c->x) < TR_ROAD + M(1)) return;
- int32_t per = TR_SEG * FX;
- int32_t base = c->z >= 0 ? c->z / per : -((-c->z + per - 1) / per);
- for (int k = -1; k <= 1; k++) {
- int32_t oz = (base + k) * per + per / 2, dz = oz - c->z;
- if (ABS(dz) >= M(2.6)) continue;
- for (int side = -1; side <= 1; side += 2) {
- if ((side < 0) != (c->x < 0)) continue;
- tr_thing o = tr_scenery(t, (int)(base + k), side);
- if (o.kind < 0) continue;
- int32_t reach = o.half + M(1.1);
- if (ABS(c->x - o.x) >= reach) continue;
- int32_t before = c->v;
- c->v = c->v / 4;
- /* out the side you came from: the road's, or the far side when you're already past its middle */
- bool past = ABS(c->x) > ABS(o.x) && ABS(o.x) + reach + M(0.05) <= TR_OUT;
- c->x = o.x + (past ? side : -side) * (reach + M(0.05));
- c->vx = 0, r->steer = 0;
- hit(r, before, 30);
- if (before > M(4)) r->impact = 30;
- }
- }
-}
-
-static void drive_you(tr_race *r, const tr_track *t, unsigned in, int shift) {
- tr_car *c = &r->car[0];
- int32_t top = top_of(r), v = c->v;
- if (r->manual) r->gear = (uint8_t)CLAMP(r->gear + shift, 1, 5);
- else r->gear = (uint8_t)auto_gear(v, top);
- int32_t band = top * GEAR_TOP[r->gear] / 100, low = r->gear > 1 ? top * GEAR_TOP[r->gear - 1] * 60 / 10000 : 0;
- int32_t accel = M(8) + M(0.4) * r->up[UP_ENGINE] - (int32_t)((int64_t)M(6) * v / top);
- if (r->manual) accel = v < low ? accel * 2 / 5 : accel * 104 / 100;
- /* nitro: OK (or EXE) held, not braking; empty, it locks until a quarter is back */
- int drain = 6;
- bool want = (in & IN_NITRO) && !(in & IN_BRAKE) && r->phase == PH_RACE;
- r->boost = want && !r->nitro_lock && r->nitro >= drain && v > M(5);
- if (r->boost) {
- r->nitro = (uint16_t)(r->nitro - drain);
- if (r->nitro < drain) r->nitro_lock = 1;
- top += M(12), band = r->manual ? band + M(12) : top, accel += M(5);
- in |= IN_GAS;
- } else {
- r->nitro = (uint16_t)CLAMP(r->nitro + 2 + r->up[UP_NITRO], 0, 1000);
- if (r->nitro >= 250) r->nitro_lock = 0;
- }
- if (!r->manual) band = top;
- r->offroad = ABS(c->x) > TR_ROAD + M(0.6);
- int32_t cap = band < top ? band : top;
- if (r->offroad && cap > M(24)) cap = M(24);
- if (in & IN_BRAKE) v -= M(14) / TR_HZ;
- else if ((in & IN_GAS) && v < cap) v = v + accel / TR_HZ < cap ? v + accel / TR_HZ : cap;
- else if (!(in & IN_GAS)) v -= (M(1.5) + v / 40) / TR_HZ;
- if (v > cap) { /* over the gear's or the grass's limit, or the nitro gone: down gently */
- v -= (r->offroad ? M(12) : M(8)) / TR_HZ;
- if (v < cap && (in & IN_GAS)) v = cap;
- }
- /* hills: half of gravity along the slope */
- int32_t dh = tr_height_at(t, c->z + M(2.5)) - tr_height_at(t, c->z - M(2.5));
- v -= dh * 49 / 2500;
- c->v = v < 0 ? 0 : v;
- /* steering eases in and out; the bend pulls you outwards with the square of your speed */
- int target = ((in & IN_RIGHT) ? 1000 : 0) - ((in & IN_LEFT) ? 1000 : 0);
- r->steer = (int16_t)(r->steer + (target - r->steer) / 4);
- if (ABS(target - r->steer) < 8) r->steer = (int16_t)target;
- int32_t grip = 100 + 6 * r->up[UP_TIRES] - (r->rain ? 12 : 0);
- int32_t reach = c->v < M(30) ? c->v : M(30);
- int32_t authority = M(9) * grip / 100 * reach / M(30);
- int32_t drift = (int32_t)((int64_t)c->v * c->v * tr_curve_at(t, c->z) / 1905200);
- c->vx = r->steer * authority / 1000 - drift;
- c->x = CLAMP(c->x + c->vx / TR_HZ, -TR_OUT, TR_OUT);
- c->z += c->v / TR_HZ;
- scenery_crash(r, t);
-}
-
-/* after the line, or out of the race */
-static void coast(tr_race *r) {
- tr_car *c = &r->car[0];
- r->boost = 0, r->steer = 0, c->vx = 0;
- c->v = c->v > M(8) / TR_HZ ? c->v - M(8) / TR_HZ : 0;
- c->z += c->v / TR_HZ;
-}
-
-/* ------------------------------------------------------------------ rivals and traffic */
-static int32_t cruise_of(const tr_race *r, int i) {
- const tr_car *c = &r->car[i];
- static const uint8_t BASE[3] = {47, 52, 57};
- return M(BASE[r->level]) + c->skill * M(1.2);
-}
-
-/* room in a lane for car i: the distance to the first car ahead in it (up to 80 m), or -1 when a car is
- alongside there */
-static int32_t lane_room(const tr_race *r, const tr_track *t, int i, int32_t lane) {
- int32_t room = M(80);
- for (int j = 0; j < TR_CARS; j++) {
- if (j == i || !active(r, j)) continue;
- if (ABS(r->car[j].x - lane) >= TR_CAR_WID + M(0.4)) continue;
- int32_t dz = tr_wrap(t, r->car[j].z - r->car[i].z);
- if (dz > -M(7) && dz < M(7)) return -1;
- if (dz >= M(7) && dz < room) room = dz;
- }
- return room;
-}
-
-static void drive_rival(tr_race *r, const tr_track *t, int i) {
- tr_car *c = &r->car[i];
- bool traffic = r->mode == MODE_FREE && i != 0;
- int32_t target;
- if (traffic) {
- target = c->cruise;
- } else {
- /* their corner speeds, as a share of what the tyres hold (nobody drives on the very limit) */
- static const uint8_t GRIP[3] = {86, 92, 98};
- target = i == 0 ? M(42) : cruise_of(r, i);
- int32_t lim = (int32_t)t->limit[tr_seg_of(t, c->z + M(3))] * FX * GRIP[r->level] / 100;
- if (lim < target) target = lim;
- if (i != 0 && !c->place && r->car[0].place == 0) {
- int32_t gap = c->z - r->car[0].z; /* a little give and take with you */
- if (gap > M(220)) target = target * 95 / 100;
- else if (gap < -M(150)) target = target * 104 / 100;
- }
- if (c->place && i != 0) target = target * 3 / 4; /* over the line: a lap of honour */
- }
- /* the car in front, in my way */
- int block = -1;
- int32_t near = M(40);
- for (int j = 0; j < TR_CARS; j++) {
- if (j == i || !active(r, j)) continue;
- int32_t dz = tr_wrap(t, r->car[j].z - c->z);
- if (dz > 0 && dz < near && ABS(r->car[j].x - c->x) < TR_CAR_WID + M(0.3)) near = dz, block = j;
- }
- if (c->think) c->think--;
- bool slow = block >= 0 && r->car[block].v < target - (traffic ? target / 3 : M(1));
- if (!c->think || (slow && near < M(15) && c->think > 4)) {
- c->think = (uint16_t)(12 + (tr_rng(&r->seed) & 7));
- static const int32_t LANES[3] = {0, -TR_LANE, TR_LANE};
- int32_t room[3];
- for (int k = 0; k < 3; k++) room[k] = lane_room(r, t, i, LANES[k]);
- int now = 0;
- for (int k = 1; k < 3; k++)
- if (ABS(LANES[k] - c->lane) < ABS(LANES[now] - c->lane)) now = k;
- if (slow) {
- /* overtake: the lane with the most room; crossing the middle needs the middle clear */
- int best = now;
- for (int k = 0; k < 3; k++) {
- if (room[k] < 0 || (k && now && k != now && room[0] < 0)) continue;
- if (room[k] > room[best] + M(10) || (room[best] < 0 && room[k] >= 0)) best = k;
- }
- c->lane = LANES[best];
- } else if (!traffic && block < 0) {
- int32_t home = (c->skill % 3 - 1) * TR_LANE;
- if (ABS(c->lane - home) > M(0.5) && lane_room(r, t, i, home) >= M(30)) c->lane = home;
- }
- }
- if (block >= 0) {
- /* keep 6 m or so behind it: match its speed as the gap closes */
- int32_t want = r->car[block].v + (near - M(10)) * 2;
- if (want < target) target = want;
- }
- /* moving over to a lane with room: never so slow that it can't */
- if (ABS(c->lane - c->x) > M(0.5) && target < M(4) && lane_room(r, t, i, c->lane) > M(9)) target = M(4);
- if (target < 0) target = 0;
- int32_t step = M(3.5) / TR_HZ, dx = CLAMP(c->lane - c->x, -step, step);
- if (c->v < M(2)) dx = dx * c->v / M(2);
- c->x += dx;
- c->vx = dx * TR_HZ;
- int32_t lim = TR_ROAD - M(1.2);
- c->x = CLAMP(c->x, -lim, lim);
- if (c->v < target) {
- int32_t a = M(7) - (int32_t)((int64_t)M(4) * c->v / M(64));
- c->v = c->v + a / TR_HZ < target ? c->v + a / TR_HZ : target;
- } else {
- int32_t b = M(13) / TR_HZ;
- c->v = c->v - b > target ? c->v - b : target;
- }
- c->z += c->v / TR_HZ;
-}
-
-/* Free Ride: cars that fall behind come back far ahead, in a lane with room */
-static void respawn(tr_race *r, const tr_track *t, int i) {
- tr_car *c = &r->car[i], *me = &r->car[0];
- int32_t gap = tr_wrap(t, c->z - me->z);
- if (gap > -M(120) && gap < M(1000)) return;
- for (int tries = 0; tries < 8; tries++) {
- int32_t z = me->z + M(600) + (int32_t)(tr_rng(&r->seed) % 300) * FX;
- int32_t lane = ((int32_t)(tr_rng(&r->seed) % 3) - 1) * TR_LANE;
- bool ok = true;
- for (int j = 1; j <= tr_traffic(r); j++)
- if (j != i && ABS(tr_wrap(t, r->car[j].z - z)) < M(60) && ABS(r->car[j].x - lane) < TR_CAR_WID) ok = false;
- if (!ok && tries < 7) continue;
- c->z = z % t->length, c->x = c->lane = lane;
- c->cruise = M(22) + (int32_t)(tr_rng(&r->seed) % 14) * FX;
- c->v = c->cruise, c->think = 20, c->bump = 0;
- r->ahead[i] = 1;
- return;
- }
-}
-
-/* ------------------------------------------------------------------ touching */
-static void contacts(tr_race *r, const tr_track *t) {
- for (int i = 0; i < TR_CARS; i++) {
- if (!active(r, i)) continue;
- for (int j = i + 1; j < TR_CARS; j++) {
- if (!active(r, j)) continue;
- tr_car *a = &r->car[i], *b = &r->car[j];
- int32_t dz = tr_wrap(t, b->z - a->z), dx = b->x - a->x;
- if (ABS(dz) >= TR_CAR_LEN || ABS(dx) >= TR_CAR_WID) continue;
- int32_t pz = TR_CAR_LEN - ABS(dz), px = TR_CAR_WID - ABS(dx);
- bool you = i == 0;
- int32_t closing;
- if ((int64_t)px * TR_CAR_LEN < (int64_t)pz * TR_CAR_WID) {
- /* side by side: apart sideways */
- int32_t s = dx >= 0 ? 1 : -1, half = px / 2 + 1;
- a->x -= s * half, b->x += s * half;
- a->v -= a->v / 50, b->v -= b->v / 50;
- closing = ABS(a->vx - b->vx);
- if (you) r->steer = (int16_t)(r->steer / 2);
- } else {
- /* one behind the other: the one behind stops at the other's bumper */
- tr_car *front = dz > 0 ? b : a, *rear = dz > 0 ? a : b;
- rear->z -= pz;
- closing = rear->v - front->v;
- if (closing > 0) {
- front->v += closing * 2 / 5;
- rear->v = front->v - M(0.5) > 0 ? front->v - M(0.5) : 0;
- }
- closing = ABS(closing);
- }
- a->x = CLAMP(a->x, -TR_OUT, TR_OUT), b->x = CLAMP(b->x, -TR_OUT, TR_OUT);
- if (you && !b->bump && closing > M(1.5)) {
- hit(r, closing, 30);
- b->bump = 25;
- }
- }
- }
-}
-
-/* ------------------------------------------------------------------ a step */
-static void banner(tr_race *r, int b, int arg) { r->banner = (uint8_t)b, r->banner_arg = (uint8_t)arg, r->banner_t = 2 * TR_HZ; }
-
-void tr_step(tr_race *r, const tr_track *t, unsigned input, int shift) {
- if (t->id != r->track) return;
- r->ticks++;
- if (r->banner_t) r->banner_t--;
- if (r->impact) r->impact--;
- if (r->phase == PH_GRID) {
- if (r->countdown) r->countdown--;
- if (!r->countdown) r->phase = PH_RACE;
- r->steer = 0;
- return;
- }
- r->time_ms += TR_TICK;
- r->lap_ms += TR_TICK;
- if (r->phase == PH_DONE && r->done < 60000) r->done++;
- tr_car *me = &r->car[0];
- int32_t before = me->z;
- if (r->phase == PH_RACE) drive_you(r, t, input, shift);
- else if (r->end == END_FINISH) drive_rival(r, t, 0);
- else coast(r);
- for (int i = 1; i < TR_CARS; i++)
- if (active(r, i)) drive_rival(r, t, i);
- contacts(r, t);
- for (int i = 0; i < TR_CARS; i++)
- if (r->car[i].bump) r->car[i].bump--;
- if (r->mode == MODE_FREE) {
- r->damage = 0;
- int32_t moved = me->z - before;
- if (moved > 0) r->odometer += (uint32_t)moved;
- for (int i = 1; i <= tr_traffic(r); i++) {
- int32_t gap = tr_wrap(t, r->car[i].z - me->z);
- if (r->ahead[i] && gap < -M(5)) {
- r->ahead[i] = 0;
- if (r->passes < 99999) r->passes++;
- } else if (!r->ahead[i] && gap > M(5)) {
- r->ahead[i] = 1;
- }
- respawn(r, t, i);
- }
- for (int i = 0; i < TR_CARS; i++) {
- r->car[i].z %= t->length;
- if (r->car[i].z < 0) r->car[i].z += t->length;
- }
- } else {
- int32_t end = race_end(r, t);
- for (int i = 0; i < TR_CARS; i++) {
- tr_car *c = &r->car[i];
- if (!c->place && c->z >= end) c->place = ++r->finished, c->finish_ms = r->time_ms;
- }
- if (r->phase == PH_RACE) {
- int lap = me->z < 0 ? 1 : (int)(me->z / t->length) + 1;
- if (lap > r->lap && lap <= r->laps) {
- if (!r->best_lap_ms || r->lap_ms < r->best_lap_ms) r->best_lap_ms = r->lap_ms;
- r->last_lap_ms = r->lap_ms;
- banner(r, lap == r->laps ? BANNER_FINAL : BANNER_LAP, lap);
- r->lap = (uint8_t)lap, r->lap_ms = 0;
- }
- if (me->place) {
- if (!r->best_lap_ms || r->lap_ms < r->best_lap_ms) r->best_lap_ms = r->lap_ms;
- r->last_lap_ms = r->lap_ms;
- r->phase = PH_DONE, r->end = END_FINISH, r->boost = 0;
- banner(r, BANNER_FINISH, me->place);
- } else if (r->damage >= 1000) {
- r->phase = PH_DONE, r->end = END_WRECK, r->boost = 0;
- banner(r, BANNER_WRECK, 0);
- } else if (r->time_ms >= 10 * 60000) {
- r->phase = PH_DONE, r->end = END_TIME, r->boost = 0;
- banner(r, BANNER_TIME, 0);
- }
- }
- }
- int32_t goal = me->x * 3 / 4;
- r->cam_x = (int16_t)(r->cam_x + (goal - r->cam_x) / 6);
-}
-
-/* ------------------------------------------------------------------ a saved race is checked */
-bool tr_valid(const tr_race *r) {
- if (r->track >= TR_TRACKS || r->mode > MODE_FREE || r->level > 2 || r->mood > 2 || r->rain > 1 || r->manual > 1)
- return false;
- if (r->laps != (r->mode == MODE_FREE ? 0 : TR_LAPS) || r->phase > PH_DONE || r->end > END_TIME) return false;
- if ((r->phase == PH_DONE) != (r->end != END_NONE) || r->gear < 1 || r->gear > 5 || r->lap < 1 || r->lap > TR_LAPS)
- return false;
- if (r->boost > 1 || r->offroad > 1 || r->finished > TR_CARS || r->banner > BANNER_TIME || r->nitro_lock > 1) return false;
- for (int k = 0; k < 4; k++)
- if (r->up[k] > 4) return false;
- if (r->countdown > 4 * TR_HZ || r->nitro > 1000 || r->damage > 1000 || r->impact > 30 || r->banner_t > 2 * TR_HZ)
- return false;
- if (ABS(r->steer) > 1000 || ABS(r->cam_x) > TR_OUT || r->time_ms > 11 * 60000 || r->lap_ms > r->time_ms) return false;
- if (r->best_lap_ms > r->time_ms || r->last_lap_ms > r->time_ms || r->spare) return false;
- int places = 0;
- for (int i = 0; i < TR_CARS; i++) {
- const tr_car *c = &r->car[i];
- if (c->paint > 7 || c->style > 1 || c->skill > 6 || c->place > TR_CARS) return false;
- if (c->z < -M(100) || c->z > M(TR_LAPS * TR_MAXSEG * TR_SEG + 2000) || ABS(c->x) > TR_OUT) return false;
- if (c->v < 0 || c->v > M(100) || ABS(c->vx) > M(100) || ABS(c->lane) > TR_ROAD || c->think > 64 || c->bump > 25)
- return false;
- if (c->cruise < 0 || c->cruise > M(40)) return false;
- if (c->place) places++;
- }
- return places == r->finished;
-}
diff --git a/games/turborush/src/save.c b/games/turborush/src/save.c
deleted file mode 100644
index ed593a3d..00000000
--- a/games/turborush/src/save.c
+++ /dev/null
@@ -1,156 +0,0 @@
-/* The save (save.h): checked field by field; anything damaged, cut short or from elsewhere is not read: the copy in
- * the Python script is tried, then a fresh start. */
-#include <stddef.h>
-#include <string.h>
-#include "plat.h"
-#include "save.h"
-
-void tr_fresh(tr_profile *p, tr_gp *gp) {
- memset(p, 0, sizeof *p);
- p->level = LEVEL_NORMAL, p->traffic = 1;
- memset(gp, 0, sizeof *gp);
-}
-
-unsigned tr_price(const tr_profile *p, int item) {
- if (item < 0 || item > 3 || p->up[item] >= 4) return 0;
- return 400u + 250u * p->up[item] + 75u * (unsigned)item;
-}
-
-uint32_t tr_sum(const void *data, uint32_t n) {
- const uint8_t *p = data;
- uint32_t h = 2166136261u;
- for (uint32_t i = 0; i < n; i++) h = (h ^ p[i]) * 16777619u;
- return h;
-}
-
-static bool profile_ok(const tr_profile *p) {
- if (p->credits > TR_MAX_CREDITS || p->races > 999999 || p->wins > p->races || p->titles > p->races) return false;
- for (int i = 0; i < TR_TRACKS; i++) {
- if (p->best_ms[i] > 11 * 60000 || p->best_lap_ms[i] > 11 * 60000) return false;
- if (p->best_ms[i] && (!p->best_lap_ms[i] || p->best_lap_ms[i] > p->best_ms[i])) return false;
- }
- for (int k = 0; k < 4; k++)
- if (p->up[k] > 4) return false;
- return p->paint < 8 && p->style < 2 && p->mode <= MODE_FREE && p->track < TR_TRACKS && p->level <= 2 &&
- p->traffic <= 2 && p->mood <= 2 && p->rain <= 1 && p->manual <= 1 && p->guide <= 1 && !p->spare[0] &&
- !p->spare[1];
-}
-
-static bool gp_ok(const tr_gp *g) {
- if (g->on > 1 || g->round >= TR_TRACKS || g->spare) return false;
- if (!g->on) {
- for (const uint8_t *b = (const uint8_t *)g; b < (const uint8_t *)(g + 1); b++)
- if (*b) return false;
- return true;
- }
- unsigned seen = 0;
- for (int i = 0; i < TR_CARS - 1; i++) {
- if (g->skill[i] >= TR_CARS - 1 || seen & 1u << g->skill[i]) return false;
- seen |= 1u << g->skill[i];
- }
- for (int i = 0; i < TR_CARS; i++)
- if (g->points[i] > 15 * TR_TRACKS) return false;
- return true;
-}
-
-bool tr_file_ok(const tr_file *f) {
- if (f->magic != TR_MAGIC || f->version != TR_VERSION || f->size != sizeof *f) return false;
- if (f->sum != tr_sum(f, offsetof(tr_file, sum))) return false;
- for (int i = 0; i < 5; i++)
- if (f->spare[i]) return false;
- if (!profile_ok(&f->p) || !gp_ok(&f->gp) || f->has_race > 1) return false;
- if (!f->has_race) return true;
- const tr_race *r = &f->race;
- if (!tr_valid(r)) return false;
- /* a Grand Prix race goes with its Grand Prix */
- return r->mode != MODE_GP || (f->gp.on && r->track == f->gp.round);
-}
-
-static const char head[] = "# Turbo Rush's saves: keep this file\n";
-static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-static uint8_t copy[1 + sizeof head + 2 + sizeof TR_SAVE_NAME + 1 + (sizeof(tr_file) + 2) / 3 * 4 + 2];
-
-/* the copy: the file in base 64, in a comment line of a script */
-static bool copy_write(const tr_file *f) {
- const uint8_t *bytes = (const uint8_t *)f;
- uint32_t len = sizeof *f, nl = sizeof TR_SAVE_NAME - 1;
- uint8_t *p = copy;
- *p++ = 0; /* (a script's first byte: not imported) */
- memcpy(p, head, sizeof head - 1), p += sizeof head - 1;
- *p++ = '#', *p++ = '>';
- memcpy(p, TR_SAVE_NAME, nl), p += nl;
- *p++ = ':';
- for (uint32_t i = 0; i < len; i += 3, p += 4) {
- uint32_t left = len - i;
- uint32_t v = (uint32_t)bytes[i] << 16 | (left > 1 ? (uint32_t)bytes[i + 1] << 8 : 0) | (left > 2 ? bytes[i + 2] : 0);
- p[0] = (uint8_t)b64[v >> 18 & 63];
- p[1] = (uint8_t)b64[v >> 12 & 63];
- p[2] = left > 1 ? (uint8_t)b64[v >> 6 & 63] : '=';
- p[3] = left > 2 ? (uint8_t)b64[v & 63] : '=';
- }
- *p++ = '\n';
- return plat_save(TR_COPY_NAME, copy, (uint32_t)(p - copy));
-}
-
-static int b64v(uint8_t c) {
- for (int i = 0; i < 64; i++)
- if ((uint8_t)b64[i] == c) return i;
- return -1;
-}
-
-static bool copy_read(tr_file *f) {
- uint32_t n, nl = sizeof TR_SAVE_NAME - 1;
- const uint8_t *c = plat_load(TR_COPY_NAME, &n);
- if (!c) return false;
- for (uint32_t i = 0; i + nl + 3 <= n; i++) {
- if (c[i] != '#' || c[i + 1] != '>' || memcmp(c + i + 2, TR_SAVE_NAME, nl) || c[i + 2 + nl] != ':') continue;
- const uint8_t *l = c + i + 3 + nl;
- uint32_t m = 0;
- while (l + m < c + n && l[m] != '\n' && l[m]) m++;
- if (m != (sizeof *f + 2) / 3 * 4) return false;
- uint8_t *bytes = (uint8_t *)f;
- uint32_t o = 0;
- for (uint32_t k = 0; k < m; k += 4) {
- int v0 = b64v(l[k]), v1 = b64v(l[k + 1]), v2 = l[k + 2] == '=' ? 0 : b64v(l[k + 2]),
- v3 = l[k + 3] == '=' ? 0 : b64v(l[k + 3]);
- if (v0 < 0 || v1 < 0 || v2 < 0 || v3 < 0) return false;
- uint32_t w = (uint32_t)(v0 << 18 | v1 << 12 | v2 << 6 | v3);
- if (o < sizeof *f) bytes[o++] = (uint8_t)(w >> 16);
- if (o < sizeof *f) bytes[o++] = (uint8_t)(w >> 8);
- if (o < sizeof *f) bytes[o++] = (uint8_t)w;
- }
- return true;
- }
- return false;
-}
-
-bool save_load(tr_file *f) {
- uint32_t n;
- const uint8_t *d = plat_load(TR_SAVE_NAME, &n);
- bool ok = false;
- if (d && n == sizeof *f) {
- memcpy(f, d, sizeof *f);
- ok = tr_file_ok(f);
- }
- if (!ok && copy_read(f) && tr_file_ok(f)) {
- ok = true;
- plat_save(TR_SAVE_NAME, f, sizeof *f); /* back where it belongs */
- }
- if (!ok) {
- memset(f, 0, sizeof *f);
- tr_fresh(&f->p, &f->gp);
- }
- return ok;
-}
-
-static tr_file out; /* (static: the stack stays small) */
-bool save_write(const tr_file *f) {
- out = *f;
- out.magic = TR_MAGIC, out.version = TR_VERSION, out.size = sizeof out;
- memset(out.spare, 0, sizeof out.spare);
- if (!out.has_race) memset(&out.race, 0, sizeof out.race); /* (a race over is not kept) */
- out.sum = tr_sum(&out, offsetof(tr_file, sum));
- bool ok = plat_save(TR_SAVE_NAME, &out, sizeof out);
- copy_write(&out);
- return ok;
-}
diff --git a/games/turborush/src/save.h b/games/turborush/src/save.h
deleted file mode 100644
index a7a4450f..00000000
--- a/games/turborush/src/save.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/* What Turbo Rush keeps, in turborush.sav: your credits, car and records, the choices on the race screen, a Grand
- * Prix under way and the race you left. A copy goes into a Python script, turborush_saves.py (installing apps from
- * the NumWorks website keeps only scripts, so the save comes back from it). One format: a magic, a version, the
- * size and a checksum; anything else is not read, and the game starts afresh. */
-#ifndef TR_SAVE_H
-#define TR_SAVE_H
-#include "game.h"
-
-#define TR_SAVE_NAME "turborush.sav"
-#define TR_COPY_NAME "turborush_saves.py"
-#define TR_MAGIC 0x31555254u /* "TRU1" */
-#define TR_VERSION 1
-#define TR_MAX_CREDITS 9999999u
-
-typedef struct {
- uint32_t credits, races, wins, titles;
- uint32_t best_ms[TR_TRACKS], best_lap_ms[TR_TRACKS];
- uint8_t up[4];
- uint8_t paint, style, mode, track, level, traffic, mood, rain, manual, guide, spare[2];
-} tr_profile;
-
-typedef struct {
- uint8_t on, round; /* round: the race to drive next, 0..5 */
- uint8_t skill[TR_CARS - 1]; /* each rival's skill, the same all the way */
- uint8_t spare;
- uint16_t points[TR_CARS];
-} tr_gp;
-
-typedef struct {
- uint32_t magic;
- uint16_t version, size;
- tr_profile p;
- tr_gp gp;
- uint8_t has_race, spare[5];
- tr_race race;
- uint32_t sum; /* FNV-1a of everything before it */
-} tr_file;
-_Static_assert(sizeof(tr_file) == 492, "turborush.sav: 492 bytes");
-
-void tr_fresh(tr_profile *p, tr_gp *gp);
-unsigned tr_price(const tr_profile *p, int item); /* the next level of an upgrade (0: none left) */
-uint32_t tr_sum(const void *data, uint32_t n);
-bool tr_file_ok(const tr_file *f);
-bool save_load(tr_file *f); /* the save, its copy, or a fresh start (false) */
-bool save_write(const tr_file *f); /* with the magic, size and sum */
-#endif
diff --git a/games/turborush/src/track.c b/games/turborush/src/track.c
deleted file mode 100644
index 5bc16005..00000000
--- a/games/turborush/src/track.c
+++ /dev/null
@@ -1,237 +0,0 @@
-/* The six circuits: each a loop of pieces (so many segments, a bend, a climb), made into segments with smooth
- * bends and hills; what stands beside the road; and the outline drawn on the screens. */
-#include <math.h>
-#include "game.h"
-
-typedef struct {
- uint8_t len; /* segments */
- int8_t curve; /* the bend it settles into */
- int8_t hill; /* metres up (or down) over the piece */
-} piece;
-
-#define P(...) {__VA_ARGS__}
-static const piece COAST[] = {
- P(30, 0, 0), P(34, 12, 4), P(16, 0, 0), P(30, 22, -2), P(18, 0, -4), P(26, -16, 3), P(20, 0, 0), P(38, 20, 5),
- P(14, 0, 0), P(24, -14, -4), P(18, 0, -3), P(42, 26, 0), P(20, 0, 2), P(30, -10, 2), P(22, 0, -3), P(40, 18, 0),
- P(26, 0, 0)};
-static const piece VALLEY[] = {
- P(28, 0, 0), P(24, 0, 12), P(30, -24, 6), P(20, 0, -14), P(30, 26, -8), P(16, 0, 4), P(28, -20, 10), P(28, 24, 0),
- P(20, 0, -12), P(36, 30, -6), P(24, 0, 8), P(30, -18, 6), P(26, 0, -10), P(44, 22, -4), P(20, 0, 8), P(30, 26, 0),
- P(24, 0, 0)};
-static const piece DESERT[] = {
- P(44, 0, 0), P(30, 0, 16), P(26, 0, -16), P(34, 30, 0), P(40, 0, 10), P(20, 0, -10), P(30, -26, 0), P(24, 18, 4),
- P(46, 0, 14), P(24, 0, -22), P(36, 36, 0), P(30, 0, 6), P(28, -22, -2), P(24, 0, 0), P(36, 34, 0), P(22, 0, 0)};
-static const piece HARBOR[] = {
- P(40, 0, 0), P(14, 44, 0), P(30, 0, 0), P(14, 44, 0), P(20, 0, 1), P(12, -40, 0), P(16, 0, 0), P(12, 40, 0),
- P(44, 0, -1), P(16, 44, 0), P(26, 0, 0), P(12, -36, 0), P(14, 0, 0), P(12, 36, 0), P(28, 0, 0), P(16, 46, 0),
- P(34, 0, 0)};
-static const piece ALPINE[] = {
- P(30, 0, 0), P(30, 16, 18), P(14, 0, 8), P(16, -56, 4), P(20, 0, 14), P(16, 56, 6), P(24, 0, 10), P(30, -28, 0),
- P(20, 0, -16), P(18, 50, -12), P(24, 0, -14), P(16, -50, -8), P(30, 22, -12), P(20, 0, 4), P(36, 40, 6),
- P(24, 0, -8), P(26, -18, 0), P(20, 0, 0), P(30, 34, 0), P(22, 0, 0)};
-static const piece METRO[] = {
- P(32, 0, 0), P(18, 34, 0), P(14, 0, 2), P(10, -30, 0), P(10, 30, 0), P(26, 0, 3), P(22, 28, 0), P(30, 0, -3),
- P(14, -38, 0), P(16, 0, -2), P(24, 38, 0), P(14, 0, 0), P(10, 30, 0), P(10, -30, 0), P(24, 0, 2), P(26, 32, 0),
- P(20, 0, 0), P(18, 24, 0), P(22, 0, -2), P(20, 20, 0), P(18, 0, 0)};
-#undef P
-
-typedef struct {
- const piece *p;
- uint8_t n, sky, theme;
-} circuit;
-#define C(a, sky, theme) {a, sizeof a / sizeof a[0], sky, theme}
-static const circuit CIRCUITS[TR_TRACKS] = {C(COAST, SKY_COAST, TH_COAST), C(VALLEY, SKY_ALPS, TH_VALLEY),
- C(DESERT, SKY_DESERT, TH_DESERT), C(HARBOR, SKY_CITY, TH_HARBOR),
- C(ALPINE, SKY_ALPS, TH_ALPINE), C(METRO, SKY_CITY, TH_METRO)};
-#undef C
-const char *const tr_track_name[TR_TRACKS] = {"Sunset Coast", "Pine Valley", "Red Rock Run",
- "Harbor Sprint", "Alpine Pass", "Metro Circuit"};
-const char *const tr_track_note[TR_TRACKS] = {"Easy sweeping bends", "Rolling hills", "Fast, with big crests",
- "Sharp city corners", "Hairpins and climbs", "Tight and twisty"};
-
-/* how far a bend eases in from the one before */
-static int ease_of(int len) { return len / 2 < 8 ? len / 2 : 8; }
-
-static uint32_t isqrt(uint32_t v) {
- uint32_t r = 0, b = 1u << 30;
- while (b > v) b >>= 2;
- while (b) {
- if (v >= r + b) v -= r + b, r = (r >> 1) + b;
- else r >>= 1;
- b >>= 2;
- }
- return r;
-}
-
-/* the fastest a plain car takes a bend of this size: the sideways pull v*v*c grows past what the tyres hold */
-static int corner_speed(int c) {
- if (c < 0) c = -c;
- if (c <= 18) return 255;
- int v = (int)isqrt((uint32_t)(61 * 61 * 18 / c));
- return v < 255 ? v : 255;
-}
-
-void tr_build(tr_track *t, int id) {
- if (id < 0 || id >= TR_TRACKS) id = 0;
- const circuit *c = &CIRCUITS[id];
- t->id = (uint8_t)id, t->sky = c->sky, t->theme = c->theme;
- int n = 0, prev = c->p[c->n - 1].curve;
- int32_t y = 0;
- for (int k = 0; k < c->n && n < TR_MAXSEG; k++) {
- const piece *p = &c->p[k];
- int e = ease_of(p->len);
- for (int i = 0; i < p->len && n < TR_MAXSEG; i++, n++) {
- t->curve[n] = (int8_t)(i < e ? prev + (p->curve - prev) * (i + 1) / (e + 1) : p->curve);
- /* smoothstep: s = 3u^2 - 2u^3, u = i / len (in 1/4096) */
- int64_t u = (int64_t)i * 4096 / p->len, s = (3 * u * u * 4096 - 2 * u * u * u) / (4096 * 4096);
- t->y[n] = (int16_t)(y + (int64_t)p->hill * 100 * s / 4096);
- }
- y += p->hill * 100;
- prev = p->curve;
- }
- t->n = (uint16_t)n;
- /* a lap ends where it began: anything left over (there shouldn't be) is shared out along the way */
- for (int i = 0; i < n; i++) t->y[i] = (int16_t)(t->y[i] - (int64_t)y * i / n);
- t->y[n] = t->y[0];
- t->length = (int32_t)n * TR_SEG * FX;
- /* the corner speeds, braking for what comes (at 10 m/s^2), over the lap twice so the end sees the start; in
- squared speeds, so that nothing is lost to rounding on the way */
- uint32_t v2[TR_MAXSEG];
- for (int i = 0; i < n; i++) v2[i] = (uint32_t)(corner_speed(t->curve[i]) * corner_speed(t->curve[i]));
- for (int pass = 0; pass < 2; pass++)
- for (int i = n - 1; i >= 0; i--) {
- uint32_t v = v2[(i + 1) % n] + 2 * 10 * TR_SEG;
- if (v < v2[i]) v2[i] = v;
- }
- for (int i = 0; i < n; i++) {
- uint32_t v = isqrt(v2[i]);
- t->limit[i] = (uint8_t)(v < 255 ? v : 255);
- }
- /* the heading, scaled so that a lap turns exactly once */
- int64_t total = 0;
- for (int i = 0; i < n; i++) total += t->curve[i];
- if (!total) total = 1;
- int64_t sum = 0;
- for (int i = 0; i <= n; i++) {
- t->heading[i] = (uint16_t)(sum * 65536 / total);
- if (i < n) sum += t->curve[i];
- }
-}
-
-int tr_seg_of(const tr_track *t, int32_t z) {
- int32_t per = TR_SEG * FX, s = z >= 0 ? z / per : -((-z + per - 1) / per);
- s %= t->n;
- return s < 0 ? s + t->n : s;
-}
-
-int tr_curve_at(const tr_track *t, int32_t z) { return t->curve[tr_seg_of(t, z)]; }
-
-int32_t tr_height_at(const tr_track *t, int32_t z) {
- int32_t per = TR_SEG * FX;
- int s = tr_seg_of(t, z);
- int32_t f = z % per;
- if (f < 0) f += per;
- int32_t a = t->y[s], b = t->y[s + 1];
- return (a * FX + (b - a) * FX * f / per) / 100;
-}
-
-int32_t tr_wrap(const tr_track *t, int32_t dz) {
- dz %= t->length;
- if (dz >= t->length / 2) dz -= t->length;
- if (dz < -t->length / 2) dz += t->length;
- return dz;
-}
-
-/* ------------------------------------------------------------------ the roadside */
-/* heights in metres, and how much of the picture's width stands on the ground (in eighths) */
-static const uint8_t TALL[SC_KINDS] = {10, 12, 7, 30, 3, 5, 8, 8};
-static const uint8_t BASE[SC_KINDS] = {2, 3, 7, 7, 7, 2, 7, 1};
-/* the pictures' sizes (art/scenery), for their widths in metres */
-static const uint8_t PIC_W[SC_KINDS] = {80, 73, 80, 64, 47, 57, 80, 43};
-static const uint8_t PIC_H[SC_KINDS] = {114, 120, 67, 120, 77, 120, 57, 120};
-
-static uint32_t hash(uint32_t a) {
- a ^= a >> 16, a *= 0x7FEB352Du, a ^= a >> 15, a *= 0x846CA68Bu, a ^= a >> 16;
- return a;
-}
-
-static tr_thing thing(int kind, int32_t gap, bool flip, int side) {
- tr_thing o;
- o.kind = (int8_t)kind, o.flip = flip;
- o.height = TALL[kind] * FX;
- int32_t w = o.height * PIC_W[kind] / PIC_H[kind];
- o.half = w * BASE[kind] / 16;
- /* gap: from the road's edge to the thing's nearest side */
- o.x = side * (TR_ROAD + gap + o.half);
- return o;
-}
-
-tr_thing tr_scenery(const tr_track *t, int seg, int side) {
- tr_thing none = {-1, false, 0, 0, 0};
- int n = t->n;
- seg = ((seg % n) + n) % n;
- uint32_t h = hash((uint32_t)seg * 2654435761u ^ (uint32_t)(side + 2) * 40503u ^ (uint32_t)t->id * 977u);
- int c = t->curve[seg];
- /* arrows on the outside of a sharp bend, every few segments */
- if ((c >= 26 && side < 0) || (c <= -26 && side > 0)) {
- if (seg % 4 == 0) return thing(SC_SIGN, 2 * FX, c < 0, side);
- return none;
- }
- if (seg % n < 3 || seg % n >= n - 2) return none; /* the start line stays clear */
- int32_t jitter = (int32_t)(h >> 8 & 255) * 6; /* up to 6 metres */
- switch (t->theme) {
- case TH_COAST:
- if (seg % 19 == (side > 0 ? 7 : 16)) return thing(SC_VILLA, 9 * FX + jitter, h & 1, side);
- if (seg % 3 == (side > 0 ? 0 : 1)) return thing(SC_PALM, 3 * FX + jitter / 3, h >> 1 & 1, side);
- break;
- case TH_VALLEY:
- case TH_ALPINE:
- if (t->theme == TH_ALPINE && seg % 11 == (side > 0 ? 3 : 8)) return thing(SC_ROCK, 4 * FX + jitter, h & 1, side);
- if (seg % 2 == (side > 0 ? 0 : 1) && (h & 7) != 0) return thing(SC_PINE, 3 * FX + jitter / 2, h >> 3 & 1, side);
- break;
- case TH_DESERT:
- if (seg % 9 == (side > 0 ? 2 : 6)) return thing(SC_ROCK, 5 * FX + jitter * 2, h & 1, side);
- if (seg % 4 == (side > 0 ? 0 : 2) && (h & 3) != 0) return thing(SC_CACTUS, 3 * FX + jitter / 2, h >> 2 & 1, side);
- break;
- case TH_HARBOR:
- if (seg % 6 == 0) return thing(SC_LAMP, 2 * FX, side < 0, side);
- if (seg % 5 == (side > 0 ? 2 : 4)) return thing(SC_TOWER, 8 * FX + jitter, h & 1, side);
- break;
- case TH_METRO:
- if (seg % 5 == 0) return thing(SC_LAMP, 2 * FX, side < 0, side);
- if (seg % 4 == (side > 0 ? 1 : 3)) return thing(SC_TOWER, 5 * FX + jitter / 2, h & 1, side);
- break;
- }
- return none;
-}
-
-/* ------------------------------------------------------------------ the outline */
-int tr_map(int id, int n, int16_t *xs, int16_t *ys, int w, int h) {
- static tr_track t; /* (static: big) */
- tr_build(&t, id);
- float px[TR_MAXSEG + 1], py[TR_MAXSEG + 1];
- float x = 0, y = 0;
- for (int i = 0; i <= t.n; i++) {
- px[i] = x, py[i] = y;
- float a = (float)t.heading[i] * (6.2831853f / 65536.f);
- x += sinf(a), y -= cosf(a);
- }
- /* close the loop: what's left over is shared out along the way */
- float ex = px[t.n], ey = py[t.n];
- float x0 = 1e9f, x1 = -1e9f, y0 = 1e9f, y1 = -1e9f;
- for (int i = 0; i <= t.n; i++) {
- px[i] -= ex * (float)i / (float)t.n, py[i] -= ey * (float)i / (float)t.n;
- if (px[i] < x0) x0 = px[i];
- if (px[i] > x1) x1 = px[i];
- if (py[i] < y0) y0 = py[i];
- if (py[i] > y1) y1 = py[i];
- }
- float s = fminf((float)(w - 1) / fmaxf(x1 - x0, 1.f), (float)(h - 1) / fmaxf(y1 - y0, 1.f));
- float ox = ((float)(w - 1) - (x1 - x0) * s) / 2, oy = ((float)(h - 1) - (y1 - y0) * s) / 2;
- for (int k = 0; k < n; k++) {
- int i = k * t.n / n;
- xs[k] = (int16_t)lrintf((px[i] - x0) * s + ox);
- ys[k] = (int16_t)lrintf((py[i] - y0) * s + oy);
- }
- return t.n;
-}
diff --git a/games/turborush/src/view.c b/games/turborush/src/view.c
deleted file mode 100644
index 87f5235f..00000000
--- a/games/turborush/src/view.c
+++ /dev/null
@@ -1,434 +0,0 @@
-/* The view from behind your car, the classic way of the arcade racers: the road ahead is cut in segments, each
- * projected from near to far; a segment only fills the screen rows the nearer ones left (a crest hides what's
- * behind it), which gives each row of the screen one piece of road. The roadside and the cars are pictures scaled
- * to their distance, drawn far to near, each cut off below the crest in front of it.
- *
- * The frame is worked out once (view_frame), then drawn strip by strip (view_draw). */
-#include <math.h>
-#include <string.h>
-#include "../../../launcher/src/gfx.h"
-#include "art.h"
-#include "view.h"
-
-#define FOCAL 256.f /* pixels per metre at a metre */
-#define CAM_H 3.6f /* the camera's height over the road */
-#define CAM_D 9.f /* ...and how far behind your car */
-#define NEAR 1.f
-#define DRAW 170 /* segments ahead */
-#define SCENERY_SEGS 112 /* segments ahead with things beside the road */
-#define CAR_W 3.f /* metres the width of a car picture covers */
-#define MAX_SPRITES 128
-#define SEG ((float)TR_SEG)
-#define ROADW (TR_ROAD / (float)FX)
-
-enum { ROW_SKY, ROW_ROAD, ROW_FAR };
-typedef struct {
- float cx, hw; /* the road's middle and half width (pixels) */
- int32_t z; /* the distance along the race there (FX) */
- uint16_t depth; /* metres from the camera */
- uint8_t kind;
-} vrow;
-
-typedef struct {
- const art_img *img;
- const color_t *pal;
- int x0, top, w, h; /* where on the screen, and the size drawn */
- int clip; /* rows from here down are behind a crest */
- float depth;
- uint8_t flip, fog; /* fog: 0..32 */
- uint8_t shadow;
-} vsprite;
-
-static vrow rows[SCREEN_H];
-static vsprite spr[MAX_SPRITES];
-static int nspr, pan, stars_on, rain_on, frame_ticks, boost_style = -1;
-static float seg_x[DRAW + 1], seg_dx[DRAW + 1], seg_dz[DRAW + 1], seg_y[DRAW + 2];
-static int16_t seg_clip[DRAW + 1];
-
-/* colours for the circuit and the time of day */
-static color_t sky_pal[64], scene_pal[SC_KINDS][64], car_pal[ART_PAINTS][64];
-static color_t grass[2], grass_avg, road[2], road_avg, curb[2], curb_avg, line_c, haze;
-static const uint8_t *sky_px;
-static uint64_t sky_mask; /* the backdrop's colours that are sky, where stars may shine at night */
-static int32_t track_len; /* for the start line */
-int16_t view_map_x[VIEW_MAP], view_map_y[VIEW_MAP];
-
-/* ------------------------------------------------------------------ colours */
-static color_t rgb(uint32_t c) { return HEX(c); }
-static color_t mood(color_t c, int m, int rain, int kind) {
- /* kind: 0 ground and things, 1 the sky, 2 a light (barely dimmed at night) */
- if (m == MOOD_SUNSET) c = gfx_mix(c, rgb(0xFF9466), kind == 1 ? 9 : 6), c = gfx_mix(c, 0, kind == 1 ? 0 : 3);
- if (m == MOOD_NIGHT) c = gfx_mix(c, rgb(0x081226), kind == 2 ? 4 : kind == 1 ? 23 : 20);
- if (rain) c = gfx_mix(c, rgb(0x6E7884), kind == 2 ? 2 : kind == 1 ? 11 : 6);
- return c;
-}
-
-uint16_t view_paint(int paint) { return art_car_pal[(paint & 7) * 64 + 14]; }
-
-void view_setup(const tr_track *t, int m, int rain) {
- static const uint32_t GROUND[6][2] = {{0x5A9A4E, 0x50904A}, {0x3F7F44, 0x39773F}, {0xD3A464, 0xC8995A},
- {0x7D878C, 0x758085}, {0xE4EBF2, 0xD5DFE9}, {0x5F676E, 0x58606A}};
- static const uint32_t ROAD[6][2] = {{0x62676C, 0x5D6267}, {0x5C6166, 0x575C61}, {0x6E6863, 0x68625E},
- {0x575C62, 0x52575D}, {0x50565C, 0x4B5157}, {0x4C5157, 0x474C52}};
- int th = t->theme < 6 ? t->theme : 0;
- for (int i = 0; i < 2; i++) {
- grass[i] = mood(rgb(GROUND[th][i]), m, rain, 0);
- road[i] = mood(rgb(ROAD[th][i]), m, rain, 0);
- curb[i] = mood(rgb(i ? 0xE8E6DC : 0xC8403A), m, rain, 0);
- }
- grass_avg = gfx_mix(grass[0], grass[1], 16), road_avg = gfx_mix(road[0], road[1], 16);
- curb_avg = gfx_mix(curb[0], curb[1], 16);
- line_c = mood(rgb(0xEDEDE4), m, rain, m == MOOD_NIGHT ? 2 : 0);
- haze = m == MOOD_NIGHT ? rgb(0x121C30) : m == MOOD_SUNSET ? rgb(0xE6A890) : rgb(0xBCD0DC);
- if (rain) haze = gfx_mix(haze, rgb(0x8A949E), 14);
- int sky = t->sky & 3;
- sky_px = art_sky[sky];
- sky_mask = 0;
- for (int i = 0; i < 64; i++) {
- color_t c = art_sky_pal[sky * 64 + i];
- int r = c >> 11 << 3, g = (c >> 5 & 63) << 2, b = (c & 31) << 3;
- if (b > 180 && b > r + 50 && b > g) sky_mask |= (uint64_t)1 << i;
- sky_pal[i] = mood(c, m, rain, 1);
- }
- for (int k = 0; k < SC_KINDS; k++) {
- for (int i = 0; i < 64; i++) {
- color_t c = art_scenery_pal[k * 64 + i];
- if (k == SC_ROCK && th == TH_ALPINE) { /* grey granite in the Alps, not red sandstone */
- int r = c >> 11 << 3, g = (c >> 5 & 63) << 2, b = (c & 31) << 3, y = (r * 3 + g * 6 + b) / 10;
- c = RGB(y * 9 / 10, y * 19 / 20, y);
- }
- bool lit = m == MOOD_NIGHT && (art_scenery_glow[k] >> i & 1);
- scene_pal[k][i] = mood(c, m, rain, lit ? 2 : 0);
- }
- }
- for (int p = 0; p < ART_PAINTS; p++)
- for (int i = 0; i < 64; i++)
- car_pal[p][i] = mood(art_car_pal[p * 64 + i], m, rain, i >= 24 && i < 32 ? 2 : 0);
- stars_on = m == MOOD_NIGHT && !rain;
- rain_on = rain;
- track_len = t->length;
- tr_map(t->id, VIEW_MAP, view_map_x, view_map_y, 72, 52);
-}
-
-void view_map_at(const tr_track *t, int32_t z, int *x, int *y) {
- int32_t per = t->length / VIEW_MAP;
- int32_t w = z % t->length;
- if (w < 0) w += t->length;
- int i = (int)(w / per) % VIEW_MAP, j = (i + 1) % VIEW_MAP;
- int32_t f = (w - i * per) * 256 / per;
- *x = (view_map_x[i] * (256 - f) + view_map_x[j] * f) / 256;
- *y = (view_map_y[i] * (256 - f) + view_map_y[j] * f) / 256;
-}
-
-/* ------------------------------------------------------------------ working out the frame */
-static int32_t lerp_z(const tr_track *t, int32_t a, int32_t b, int alpha, bool wrap) {
- int32_t d = wrap ? tr_wrap(t, b - a) : b - a;
- if (d > 20 * FX || d < -20 * FX) return b; /* a jump (Free Ride traffic coming back): no sweep */
- return a + d * alpha / 256;
-}
-
-static void add_sprite(const art_sprite *s, const color_t *pal, float cx, float bottom, float w, float h, int clip,
- float depth, bool flip, bool shadow) {
- /* (the last place is kept for your car) */
- if (nspr >= MAX_SPRITES - (depth > 0 ? 1 : 0) || w < 1.5f || h < 1.5f) return;
- int iw = (int)(w + 0.5f), ih = (int)(h + 0.5f), x0 = (int)floorf(cx - w / 2 + 0.5f);
- int top = (int)floorf(bottom - h + 0.5f);
- if (x0 >= SCREEN_W || x0 + iw <= 0 || top >= clip || top >= SCREEN_H || iw > 4000 || ih > 4000) return;
- int level = 0;
- while (level < 2 && iw * 2 <= s->mip[level].w) level++;
- vsprite *p = &spr[nspr++];
- p->img = &s->mip[level], p->pal = pal;
- p->x0 = x0, p->top = top, p->w = iw, p->h = ih, p->clip = clip, p->depth = depth, p->flip = flip;
- p->shadow = shadow;
- float f = (depth - 140.f) / 26.f;
- p->fog = (uint8_t)(f < 0 ? 0 : f > 18 ? 18 : f);
-}
-
-static int fog_of(float depth) {
- float f = (depth - 120.f) / 22.f;
- return f < 0 ? 0 : f > 20 ? 20 : (int)f;
-}
-
-void view_frame(const tr_track *t, const tr_race *a, const tr_race *b, int alpha) {
- bool wrap = b->mode == MODE_FREE;
- boost_style = -1;
- frame_ticks = (int)b->ticks;
- int32_t me_z = lerp_z(t, a->car[0].z, b->car[0].z, alpha, wrap);
- int32_t me_x = a->car[0].x + (b->car[0].x - a->car[0].x) * alpha / 256;
- float camx = (float)(a->cam_x + (b->cam_x - a->cam_x) * alpha / 256) / FX;
- int32_t cam_z = me_z - (int32_t)(CAM_D * FX);
- int32_t per = TR_SEG * FX;
- int32_t base = cam_z >= 0 ? cam_z / per : -((-cam_z + per - 1) / per);
- float frac = (float)(cam_z - base * per) / (float)per;
- int n = t->n;
- /* the camera rides at a fixed height over your car, so your car stays put on the screen over crests */
- float cam_y = (float)tr_height_at(t, me_z) / FX + CAM_H;
- /* the backdrop turns with the road */
- int s0 = (int)(((base % n) + n) % n);
- int32_t hd = t->heading[s0] + (int32_t)((float)(int16_t)(t->heading[s0 + 1] - t->heading[s0]) * frac);
- pan = (int)((((uint32_t)hd & 0xFFFF) * 800u) >> 16);
- /* the road */
- float x = 0, dx = -(float)t->curve[s0] * frac;
- int maxy = SCREEN_H;
- for (int k = 0; k <= DRAW; k++) {
- int s = (int)(((base + k) % n + n) % n);
- float z1 = (float)k * SEG - frac * SEG, z2 = z1 + SEG;
- float y1w = (float)t->y[s] / 100.f, y2w = (float)t->y[s + 1] / 100.f;
- float x1 = x / 100.f, x2 = (x + dx) / 100.f;
- seg_x[k] = x1, seg_dx[k] = dx, seg_dz[k] = z1, seg_y[k] = y1w, seg_y[k + 1] = y2w, seg_clip[k] = (int16_t)maxy;
- x += dx, dx += (float)t->curve[s];
- if (k == DRAW || z2 <= NEAR || maxy <= 0) continue;
- if (z1 < NEAR) {
- float u = (NEAR - z1) / SEG;
- x1 += (x2 - x1) * u, y1w += (y2w - y1w) * u, z1 = NEAR;
- }
- float p1 = FOCAL / z1, p2 = FOCAL / z2;
- float sx1 = 160.f + (x1 - camx) * p1, sy1 = VIEW_HZ + (cam_y - y1w) * p1, w1 = ROADW * p1;
- float sx2 = 160.f + (x2 - camx) * p2, sy2 = VIEW_HZ + (cam_y - y2w) * p2, w2 = ROADW * p2;
- if (sy2 >= sy1) continue;
- int r0 = (int)ceilf(sy2 - 0.5f), r1 = (int)ceilf(sy1 - 0.5f);
- if (r0 < 0) r0 = 0;
- if (r1 > maxy) r1 = maxy;
- for (int r = r0; r < r1; r++) {
- float u = (sy1 - ((float)r + 0.5f)) / (sy1 - sy2), iz = (1 - u) / z1 + u / z2, zr = 1.f / iz;
- vrow *w = &rows[r];
- w->cx = sx1 + (sx2 - sx1) * u, w->hw = w1 + (w2 - w1) * u;
- w->z = cam_z + (int32_t)(zr * FX), w->depth = (uint16_t)(zr < 60000 ? zr : 60000), w->kind = ROW_ROAD;
- }
- if (r0 < r1) maxy = r0;
- }
- for (int r = 0; r < maxy; r++) rows[r].kind = r < VIEW_HZ ? ROW_SKY : ROW_FAR;
- /* the cars first: they always get a place */
- nspr = 0;
- for (int i = 1; i < TR_CARS; i++) {
- if (i > tr_traffic(b)) continue;
- const tr_car *c = &b->car[i];
- int32_t cz = lerp_z(t, a->car[i].z, c->z, alpha, true);
- float dz = (float)tr_wrap(t, cz - cam_z) / FX;
- if (dz < 2.f || dz >= (DRAW - 1) * SEG) continue;
- int k = (int)floorf((dz + frac * SEG) / SEG);
- if (k < 0 || k >= DRAW) continue;
- float u = (dz - seg_dz[k]) / SEG, xr = seg_x[k] + seg_dx[k] * u / 100.f;
- float yr = seg_y[k] + (seg_y[k + 1] - seg_y[k]) * u, p = FOCAL / dz;
- float cx = (float)(a->car[i].x + (c->x - a->car[i].x) * alpha / 256) / FX;
- float sx = 160.f + (xr + cx - camx) * p, sy = VIEW_HZ + (cam_y - yr) * p, w = CAR_W * p;
- float yaw = seg_dx[k] / (100.f * SEG) + (float)c->vx / (float)(c->v > 5 * FX ? c->v : 5 * FX);
- int angle = yaw < -0.06f ? 0 : yaw > 0.06f ? 2 : 1;
- add_sprite(&art_cars[(c->style & 1) * 3 + angle], car_pal[c->paint & 7], sx, sy, w, w * 64 / 96, seg_clip[k], dz,
- false, true);
- }
- /* the roadside, near to far, while there's room */
- for (int k = 1; k < SCENERY_SEGS; k++) {
- float zc = seg_dz[k] + SEG / 2;
- if (zc < 2.5f) continue;
- int s = (int)(base + k);
- float xc = seg_x[k] + seg_dx[k] / 200.f, yc = (seg_y[k] + seg_y[k + 1]) / 2, p = FOCAL / zc;
- for (int side = -1; side <= 1; side += 2) {
- tr_thing o = tr_scenery(t, s, side);
- if (o.kind < 0) continue;
- const art_sprite *as = &art_scenery[o.kind];
- float h = (float)o.height / FX * p, w = h * as->mip[0].w / as->mip[0].h;
- float sx = 160.f + (xc + (float)o.x / FX - camx) * p, sy = VIEW_HZ + (cam_y - yc) * p;
- add_sprite(as, scene_pal[o.kind], sx, sy, w, h, seg_clip[k], zc, o.flip, false);
- }
- }
- /* far to near; the order stays as made on ties */
- for (int i = 1; i < nspr; i++) {
- vsprite v = spr[i];
- int j = i;
- while (j > 0 && spr[j - 1].depth < v.depth) spr[j] = spr[j - 1], j--;
- spr[j] = v;
- }
- /* you, last */
- {
- int k = (int)floorf((CAM_D + frac * SEG) / SEG);
- float u = (CAM_D - seg_dz[k]) / SEG, xr = seg_x[k] + seg_dx[k] * u / 100.f, yr = seg_y[k] + (seg_y[k + 1] - seg_y[k]) * u;
- float p = FOCAL / CAM_D, w = CAR_W * p;
- float sx = 160.f + (xr + (float)me_x / FX - camx) * p, sy = VIEW_HZ + (cam_y - yr) * p;
- int steer = a->steer + (b->steer - a->steer) * alpha / 256;
- if (b->phase == PH_DONE && b->end == END_FINISH) steer = (int)(b->car[0].vx / 4);
- int angle = steer < -350 ? 0 : steer > 350 ? 2 : 1;
- if (b->offroad && b->car[0].v > 3 * FX && (b->ticks & 2)) sy -= 1;
- if (b->impact) sx += (float)((b->impact * 7) % 5 - 2);
- add_sprite(&art_cars[(b->car[0].style & 1) * 3 + angle], car_pal[b->car[0].paint & 7], sx, sy, w, w * 64 / 96,
- SCREEN_H, 0, false, true);
- boost_style = b->boost && angle == 1 ? b->car[0].style & 1 : b->boost ? 2 : -1;
- }
-}
-
-/* ------------------------------------------------------------------ drawing a strip */
-static inline void fill(color_t *row, int x0, int x1, color_t c) {
- if (x0 < 0) x0 = 0;
- if (x1 > SCREEN_W) x1 = SCREEN_W;
- for (int x = x0; x < x1; x++) row[x] = c;
-}
-
-static void draw_sky(color_t *dst, int r) {
- int sr = r - (VIEW_HZ - 100);
- if (sr < 0) sr = 0;
- const uint8_t *src = sky_px + sr * 400;
- int u = pan;
- for (int x = 0; x < SCREEN_W; x++, u++) {
- if (u >= 800) u -= 800;
- dst[x] = sky_pal[src[u < 400 ? u : 799 - u]];
- }
- if (stars_on && sr < 46) {
- for (int i = 0; i < 40; i++) {
- uint32_t h = (uint32_t)i * 2654435761u;
- if ((int)(h >> 26) % 46 != sr) continue;
- int sx = (int)((h >> 8) % 800), x = sx - pan;
- if (x < 0) x += 800;
- if (x >= SCREEN_W) continue;
- int px = src[sx < 400 ? sx : 799 - sx];
- if (sky_mask >> px & 1) dst[x] = (h & 0x300) ? HEX(0xC8D4E4) : HEX(0x8A9AB4);
- }
- }
-}
-
-static void draw_road(color_t *dst, const vrow *w) {
- int depth = w->depth, fog = fog_of((float)depth);
- /* bands every two segments; far away they blend into one colour (no shimmer) */
- int band = (int)(((w->z / (2 * TR_SEG * FX)) % 2 + 2) % 2);
- int k = depth < 110 ? 32 : depth > 260 ? 0 : (260 - depth) * 32 / 150;
- color_t g = gfx_mix(gfx_mix(grass_avg, grass[band], k), haze, fog);
- color_t rd = gfx_mix(gfx_mix(road_avg, road[band], k), haze, fog);
- color_t cb = gfx_mix(gfx_mix(curb_avg, curb[band], k), haze, fog);
- color_t ln = gfx_mix(line_c, haze, fog);
- float hw = w->hw, cx = w->cx;
- int l = (int)floorf(cx - hw + 0.5f), r = (int)floorf(cx + hw + 0.5f);
- float cw = hw * 0.11f;
- int cl = (int)floorf(cx - hw - cw + 0.5f), cr = (int)floorf(cx + hw + cw + 0.5f);
- fill(dst, 0, cl, g);
- fill(dst, cr, SCREEN_W, g);
- if (cl >= SCREEN_W || cr <= 0) return;
- fill(dst, cl, l, cb);
- fill(dst, r, cr, cb);
- fill(dst, l, r, rd);
- if (hw < 3) return;
- int lw = (int)(hw * 0.035f + 0.5f);
- if (lw < 1) lw = 1;
- fill(dst, l + lw, l + 2 * lw, ln);
- fill(dst, r - 2 * lw, r - lw, ln);
- if (depth < 230 && ((w->z / (FX * 3)) & 3) < 2) { /* dashes: 6 m painted, 6 m gap */
- int a = (int)floorf(cx - hw / 3 - lw / 2.f + 0.5f), b = (int)floorf(cx + hw / 3 - lw / 2.f + 0.5f);
- fill(dst, a, a + lw, ln);
- fill(dst, b, b + lw, ln);
- }
-}
-
-static void draw_start(color_t *dst, const vrow *w) {
- if (!track_len) return;
- int32_t m = w->z % track_len;
- if (m < 0) m += track_len;
- if (m >= 3 * FX) return;
- int fog = fog_of((float)w->depth);
- float hw = w->hw, cx = w->cx;
- int row = (int)(m * 2 / (3 * FX));
- for (int q = 0; q < 12; q++) {
- int a = (int)floorf(cx - hw + 2 * hw * q / 12 + 0.5f), b = (int)floorf(cx - hw + 2 * hw * (q + 1) / 12 + 0.5f);
- fill(dst, a, b, gfx_mix((q + row) & 1 ? HEX(0x15181C) : HEX(0xF0F0EA), haze, fog));
- }
-}
-
-static void draw_sprite(const vsprite *p) {
- int r0 = p->top > gfx_y0 ? p->top : gfx_y0;
- int r1 = p->top + p->h;
- if (r1 > gfx_y1) r1 = gfx_y1;
- if (r1 > p->clip) r1 = p->clip;
- if (r0 >= r1) return;
- const art_img *im = p->img;
- int sw = im->w, sh = im->h;
- uint32_t xs = ((uint32_t)sw << 16) / (uint32_t)p->w, ys = ((uint32_t)sh << 16) / (uint32_t)p->h;
- color_t fogged[64];
- const color_t *pal = p->pal;
- if (p->fog) {
- for (int i = 0; i < 63; i++) fogged[i] = gfx_mix(pal[i], haze, p->fog);
- pal = fogged;
- }
- for (int r = r0; r < r1; r++) {
- int sy = (int)(((uint32_t)(r - p->top) * ys + ys / 2) >> 16);
- if (sy >= sh) sy = sh - 1;
- const uint8_t *src = im->px + sy * sw;
- int a = im->span[sy * 2], b = im->span[sy * 2 + 1];
- if (a >= b) continue;
- if (p->flip) {
- int t = sw - b;
- b = sw - a, a = t;
- }
- int xa = p->x0 + (int)(((uint32_t)a * (uint32_t)p->w) / (uint32_t)sw);
- int xb = p->x0 + (int)(((uint32_t)b * (uint32_t)p->w + (uint32_t)sw - 1) / (uint32_t)sw);
- if (xa < 0) xa = 0;
- if (xb > SCREEN_W) xb = SCREEN_W;
- color_t *dst = gfx_buf + (r - gfx_y0) * SCREEN_W;
- uint32_t fx = (uint32_t)(xa - p->x0) * xs + xs / 2;
- for (int x = xa; x < xb; x++, fx += xs) {
- int sx = (int)(fx >> 16);
- if (sx >= sw) sx = sw - 1;
- if (p->flip) sx = sw - 1 - sx;
- uint8_t c = src[sx];
- if (c != ART_T) dst[x] = pal[c];
- }
- }
-}
-
-static void draw_shadow(const vsprite *p) {
- int h = p->h / 9 + 1, y = p->top + p->h - h + 1, w = p->w * 7 / 8;
- if (y + h > p->clip) return;
- gfx_rrect(p->x0 + (p->w - w) / 2, y, w, h, h / 2, HEX(0x0A0E12), 120);
-}
-
-/* nitro: a blue flame from each exhaust of your car (the last sprite) */
-static void draw_flames(void) {
- const vsprite *p = &spr[nspr - 1];
- static const uint8_t AT[3][2] = {{27, 34}, {25, 74}, {30, 70}}; /* % of the width: the coupe, the supercar, turning */
- int len = p->h / 6 + ((frame_ticks >> 1) & 1) * (p->h / 24 + 1), fw = p->w / 13 + 2;
- for (int k = 0; k < 2; k++) {
- int cx = p->x0 + p->w * AT[boost_style][k] / 100, y0 = p->top + p->h * 85 / 100;
- for (int j = 0; j < len; j++) { /* a flame: wide at the pipe, a point at its end, white at its heart */
- int w = fw * (len - j) / len + 1, core = w / 2;
- gfx_fill_alpha(cx - w / 2, y0 + j, w, 1, HEX(0x3FA9F5), 200 - j * 120 / len);
- if (j < len * 2 / 3 && core) gfx_fill_alpha(cx - core / 2, y0 + j, core, 1, HEX(0xEAF9FF), 230 - j * 150 / len);
- }
- }
-}
-
-static void draw_rain(void) {
- for (int i = 0; i < 46; i++) {
- int x = (int)((uint32_t)(i * 97 + frame_ticks * 5) % 340u) - 10;
- int y = (int)((uint32_t)(i * 53 + frame_ticks * 13) % 260u) - 10;
- for (int j = 0; j < 8; j++) {
- int yy = y + j, xx = x - j / 3;
- if (yy < gfx_y0 || yy >= gfx_y1 || xx < 0 || xx >= SCREEN_W) continue;
- color_t *d = gfx_buf + (yy - gfx_y0) * SCREEN_W + xx;
- *d = gfx_mix(*d, HEX(0xC8D2DC), 11);
- }
- }
-}
-
-void view_draw(void) {
- for (int r = gfx_y0; r < gfx_y1; r++) {
- color_t *dst = gfx_buf + (r - gfx_y0) * SCREEN_W;
- const vrow *w = &rows[r];
- if (w->kind == ROW_SKY) draw_sky(dst, r);
- else if (w->kind == ROW_FAR) fill(dst, 0, SCREEN_W, gfx_mix(grass_avg, haze, 20));
- else draw_road(dst, w), draw_start(dst, w);
- }
- for (int i = 0; i < nspr; i++) {
- if (spr[i].shadow) draw_shadow(&spr[i]);
- draw_sprite(&spr[i]);
- }
- if (boost_style >= 0 && nspr) draw_flames();
- if (rain_on) draw_rain();
-}
-
-void view_car(int x, int bottom, int width, int paint, int style, int angle) {
- vsprite v;
- const art_sprite *s = &art_cars[(style & 1) * 3 + (angle < 0 ? 0 : angle > 2 ? 2 : angle)];
- int level = 0;
- while (level < 2 && width * 2 <= s->mip[level].w) level++;
- v.img = &s->mip[level], v.pal = art_car_pal + (paint & 7) * 64;
- v.w = width, v.h = width * 64 / 96, v.x0 = x - width / 2, v.top = bottom - v.h, v.clip = SCREEN_H;
- v.flip = 0, v.fog = 0, v.depth = 0, v.shadow = 1;
- draw_shadow(&v);
- draw_sprite(&v);
-}
diff --git a/games/turborush/src/view.h b/games/turborush/src/view.h
deleted file mode 100644
index 3bb9fe23..00000000
--- a/games/turborush/src/view.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/* The road, the roadside and the cars, seen from behind your car (view.c). */
-#ifndef TR_VIEW_H
-#define TR_VIEW_H
-#include "game.h"
-
-#define VIEW_HZ 100 /* the horizon's row */
-#define VIEW_MAP 64 /* points in a circuit's outline */
-
-/* the colours for a circuit at a time of day (call before view_frame when either changes) */
-void view_setup(const tr_track *t, int mood, int rain);
-/* a frame of the race: between the step before (a) and the last one (b), alpha/256 of the way */
-void view_frame(const tr_track *t, const tr_race *a, const tr_race *b, int alpha);
-void view_draw(void); /* into the strip gfx_y0..gfx_y1 */
-/* a car on a menu: centred on x, standing on `bottom`, `width` pixels wide; angle 0 left, 1 ahead, 2 right */
-void view_car(int x, int bottom, int width, int paint, int style, int angle);
-/* the circuit's outline (view_setup), and where a distance is on it */
-extern int16_t view_map_x[VIEW_MAP], view_map_y[VIEW_MAP];
-void view_map_at(const tr_track *t, int32_t z, int *x, int *y);
-uint16_t view_paint(int paint); /* a paint's colour, for swatches */
-#endif
diff --git a/games/turborush/tests/play.c b/games/turborush/tests/play.c
deleted file mode 100644
index eacae52e..00000000
--- a/games/turborush/tests/play.c
+++ /dev/null
@@ -1,932 +0,0 @@
-/* Turbo Rush on a computer, for tests and pictures (make host, make test).
- *
- * play test DIR laps, crashes into the roadside and into cars, the rivals finishing every circuit at every
- * level, a driver finishing races, the Grand Prix and Free Ride through the whole app, saves
- * written and read back, damaged saves, a few hundred sessions of random keys, and the same
- * race twice, to the same hash on every computer
- * play shots DIR pictures of the screens (DIR/<name>.ppm)
- * play docs DIR the README's pictures (DIR/<name>.ppm)
- * play film DIR MS T [TIME] MS milliseconds of a race on circuit T (time of day 0..2), a bot driving
- * (DIR/<frame>_<ms>.raw, for tools/record.py --frames:
- * docs/media/gallery/turborush.gif is `play film DIR 24000 0`, 11000-20000)
- */
-#define main tr_app_main
-#include "../src/main.c"
-#undef main
-#include <math.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-/* ---------------------------------------------------------------- the calculator, on a computer */
-static uint16_t fb[240][320];
-static void (*on_frame)(void);
-void plat_push(int x, int y, int w, int h, const uint16_t *px) {
- for (int j = 0; j < h; j++)
- for (int i = 0; i < w; i++) fb[y + j][x + i] = px[j * w + i];
- if (on_frame && y + h == 240) on_frame();
-}
-void *np_alloc(uint32_t n) { (void)n; return 0; }
-static double clock_ms;
-static uint32_t (*script)(uint32_t frame);
-static uint32_t frame_no, quit_at;
-static void (*watch)(void);
-uint32_t plat_keys(void) {
- clock_ms += 5;
- frame_no++;
- if (watch) watch();
- if (frame_no >= quit_at) return TK_HOME;
- return script ? script(frame_no) : 0;
-}
-uint32_t plat_millis(void) { return (uint32_t)clock_ms; }
-void plat_sleep(uint32_t ms) { clock_ms += ms; }
-void plat_vblank(void) {}
-static uint32_t rnd_state = 1;
-uint32_t plat_random(void) { return tr_rng(&rnd_state); }
-bool plat_slow(void) { return false; }
-void plat_begin(void) {}
-int plat_end(void) { return 0; }
-
-static struct { char name[32]; uint8_t data[4096]; uint32_t len; bool on; } files[4];
-static bool storage_full;
-bool plat_save(const char *name, const void *data, uint32_t len) {
- if (storage_full) return false;
- int k = -1;
- for (int i = 0; i < 4; i++)
- if (files[i].on && !strcmp(files[i].name, name)) k = i;
- for (int i = 0; i < 4 && k < 0; i++)
- if (!files[i].on) k = i;
- if (k < 0 || len > sizeof files[k].data) return false;
- strcpy(files[k].name, name), memcpy(files[k].data, data, len), files[k].len = len, files[k].on = true;
- return true;
-}
-const uint8_t *plat_load(const char *name, uint32_t *len) {
- for (int i = 0; i < 4; i++)
- if (files[i].on && !strcmp(files[i].name, name)) return *len = files[i].len, files[i].data;
- return 0;
-}
-static void forget(const char *name) {
- for (int i = 0; i < 4; i++)
- if (files[i].on && !strcmp(files[i].name, name)) files[i].on = false;
-}
-static uint8_t *file_data(const char *name, uint32_t *len) {
- for (int i = 0; i < 4; i++)
- if (files[i].on && !strcmp(files[i].name, name)) return *len = files[i].len, files[i].data;
- return 0;
-}
-
-static void shot(const char *dir, const char *name) {
- char path[512];
- snprintf(path, sizeof path, "%s/%s.ppm", dir, name);
- FILE *f = fopen(path, "wb");
- if (!f) exit(2);
- fprintf(f, "P6 320 240 255\n");
- for (int y = 0; y < 240; y++)
- for (int x = 0; x < 320; 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 int fails;
-#define RACE_HASH 0xAF46D491u /* (made on a Mac with clang; Linux with GCC must agree) */
-#define CHECK(c, ...) do { if (!(c)) { fails++; printf("FAIL %s:%d: ", __FILE__, __LINE__); printf(__VA_ARGS__); printf("\n"); } } while (0)
-
-/* ---------------------------------------------------------------- a driver */
-/* steers for the middle of a free lane, cancels the bend's pull, brakes for what comes and burns nitro on
- straights; skill 0..100 (how much margin it keeps) */
-static uint64_t isqrt64(uint64_t v) {
- uint64_t r = 0, b = (uint64_t)1 << 62;
- while (b > v) b >>= 2;
- while (b) {
- if (v >= r + b) v -= r + b, r = (r >> 1) + b;
- else r >>= 1;
- b >>= 2;
- }
- return r;
-}
-
-static int bot_skill = 100;
-static int32_t bot_lane;
-static unsigned bot(const tr_race *r, const tr_track *t) {
- const tr_car *c = &r->car[0];
- int32_t v = c->v;
- /* the lane: stay in it, unless a slower car is close ahead; then the lane with the most room */
- static const int32_t L[3] = {0, -TR_LANE, TR_LANE};
- int32_t room[3], ahead = 1 << 30, ahead_v = 0;
- for (int k = 0; k < 3; k++) {
- room[k] = 90 * FX;
- for (int j = 1; j <= tr_traffic(r) && j < TR_CARS; j++) {
- int32_t dz = tr_wrap(t, r->car[j].z - c->z);
- if (abs(r->car[j].x - L[k]) >= TR_CAR_WID + FX / 2) continue;
- if (dz > -7 * FX && dz < 7 * FX) room[k] = -1;
- else if (dz >= 7 * FX && dz < room[k] && room[k] >= 0) room[k] = dz;
- }
- }
- for (int j = 1; j <= tr_traffic(r) && j < TR_CARS; j++) {
- int32_t dz = tr_wrap(t, r->car[j].z - c->z);
- if (dz > 0 && dz < ahead && abs(r->car[j].x - c->x) < TR_CAR_WID + FX / 2) ahead = dz, ahead_v = r->car[j].v;
- }
- int cur = 0;
- for (int k = 1; k < 3; k++)
- if (abs(L[k] - bot_lane) < abs(L[cur] - bot_lane)) cur = k;
- if (ahead < 50 * FX && ahead_v < v) {
- int best = cur;
- for (int k = 0; k < 3; k++)
- if (room[k] > room[best] + 8 * FX) best = k;
- bot_lane = L[best];
- }
- int32_t target = bot_lane;
- int32_t grip = 100 + 6 * r->up[UP_TIRES] - (r->rain ? 12 : 0);
- int32_t reach = v < 30 * FX ? v : 30 * FX;
- int32_t authority = 9 * FX * grip / 100 * reach / (30 * FX);
- int32_t drift = (int32_t)((int64_t)v * v * tr_curve_at(t, c->z + 4 * FX) / 1905200);
- int32_t want = (target - c->x) * 2 + drift;
- unsigned in = 0;
- if (authority > 0) {
- if (want > authority / 6) in |= IN_RIGHT;
- if (want < -authority / 6) in |= IN_LEFT;
- }
- /* speed: the slowest corner coming up, braking from here; and no faster than a car close ahead */
- int32_t lim = 255 * FX;
- for (int k = 0; k < 24; k++) {
- int s = tr_seg_of(t, c->z + k * TR_SEG * FX);
- int64_t vl = (int64_t)t->limit[s] * FX * (100 + 3 * r->up[UP_TIRES] - (r->rain ? 6 : 0)) / 100;
- vl = vl * (80 + bot_skill * 14 / 100) / 100;
- int64_t d = (int64_t)k * TR_SEG;
- int64_t allowed = (int64_t)isqrt64((uint64_t)(vl * vl) + (uint64_t)(2 * 12 * d) * FX * FX);
- if (allowed < lim) lim = (int32_t)allowed;
- }
- if (ahead < 14 * FX && ahead_v + 2 * FX < lim) lim = ahead_v + (ahead - 9 * FX) * 2;
- if (v > lim + FX) in |= IN_BRAKE;
- else in |= IN_GAS;
- if (!(in & IN_BRAKE) && lim >= 200 * FX && r->nitro > 600 && !r->nitro_lock && ahead > 30 * FX) in |= IN_NITRO;
- return in;
-}
-
-static uint32_t hash_race(const tr_race *r, uint32_t h) { return h ^ tr_sum(r, sizeof *r) * 16777619u; }
-
-/* ---------------------------------------------------------------- rules */
-static tr_track TT;
-static tr_setup plain(int mode, int id, int level) {
- tr_setup s;
- memset(&s, 0, sizeof s);
- s.mode = (uint8_t)mode, s.track = (uint8_t)id, s.level = (uint8_t)level;
- return s;
-}
-
-/* the rivals out of the way: half a lap off, at your speed */
-static void clear_field(tr_race *r) {
- for (int i = 1; i < TR_CARS; i++) {
- tr_car *c = &r->car[i];
- c->z = r->car[0].z - TT.length / 2 - i * 20 * FX, c->v = r->car[0].v, c->x = c->lane = 0, c->think = 60;
- }
-}
-
-/* a whole race driven by the bot; returns the steps it took (0: not finished in 10 minutes) */
-static int drive(tr_race *r, int id, int level, int mode, uint32_t seed, int skill, uint32_t *hash) {
- tr_setup s = plain(mode, id, level);
- tr_new(r, &TT, &s, seed);
- bot_skill = skill, bot_lane = r->car[0].x;
- int steps = 0;
- while (r->phase != PH_DONE && steps < 11 * 60 * TR_HZ) {
- tr_step(r, &TT, bot(r, &TT), 0);
- steps++;
- if (hash) *hash = hash_race(r, *hash);
- if (!tr_valid(r)) {
- CHECK(0, "race not valid at step %d on %s", steps, tr_track_name[id]);
- break;
- }
- }
- return r->end == END_FINISH ? steps : 0;
-}
-
-static void tracks(void) {
- for (int id = 0; id < TR_TRACKS; id++) {
- tr_build(&TT, id);
- CHECK(TT.n > 300 && TT.n <= TR_MAXSEG, "%s: %d segments", tr_track_name[id], TT.n);
- CHECK(TT.y[0] == 0 && TT.y[TT.n] == 0, "%s: the hills don't come back to the start", tr_track_name[id]);
- int32_t sum = 0;
- for (int i = 0; i < TT.n; i++) sum += TT.curve[i];
- CHECK(sum > 0, "%s: the bends don't turn one way overall", tr_track_name[id]);
- int bad = 0;
- for (int i = 0; i < TT.n; i++)
- if (abs(TT.y[i + 1] - TT.y[i]) > 160) bad++; /* no step of more than 1.6 m in 5 m, the line included */
- for (int i = 0; i < TT.n; i++) {
- int a = TT.curve[i], b = TT.curve[(i + 1) % TT.n];
- if (abs(a - b) > 12) bad++; /* bends ease in and out */
- }
- CHECK(!bad, "%s: %d segments too steep", tr_track_name[id], bad);
- printf(" %-14s %3d segments (%.2f km)\n", tr_track_name[id], TT.n, TT.n * TR_SEG / 1000.0);
- }
-}
-
-static void laps(void) {
- tr_race r;
- tr_setup s = plain(MODE_RACE, 0, LEVEL_EASY);
- tr_new(&r, &TT, &s, 5);
- CHECK(r.phase == PH_GRID && r.lap == 1 && tr_rank(&r, 0) == 8, "the start: on the grid, lap 1, last");
- int steps = 0, laps_seen = 1;
- while (r.phase == PH_GRID) tr_step(&r, &TT, IN_GAS, 0), steps++;
- CHECK(steps == 3 * TR_HZ + TR_HZ / 2, "the countdown took %d steps", steps);
- /* the rivals out of the way: one lap at a time */
- while (r.phase == PH_RACE && steps < 20000) {
- int before = r.lap;
- int32_t z = r.car[0].z;
- clear_field(&r);
- tr_step(&r, &TT, bot(&r, &TT), 0);
- steps++;
- if (r.lap != before) {
- CHECK(r.lap == before + 1, "lap %d to %d", before, r.lap);
- CHECK(z < (int32_t)before * TT.length && r.car[0].z >= (int32_t)before * TT.length, "the lap changed off the line");
- CHECK(r.banner == (r.lap == 3 ? BANNER_FINAL : BANNER_LAP), "the lap's banner");
- laps_seen++;
- }
- }
- CHECK(laps_seen == 3 && r.end == END_FINISH && r.car[0].place == 1, "three laps, then the finish (%d laps, end %d)",
- laps_seen, r.end);
- CHECK(r.car[0].z >= 3 * TT.length && r.car[0].finish_ms == r.time_ms, "finished at the line");
- CHECK(r.best_lap_ms > 20000 && r.best_lap_ms < r.time_ms, "a best lap (%u ms)", r.best_lap_ms);
- /* backwards isn't possible, and braking to a stop doesn't count laps */
- tr_new(&r, &TT, &s, 5);
- for (int i = 0; i < 2000; i++) tr_step(&r, &TT, IN_BRAKE, 0);
- CHECK(r.lap == 1 && r.car[0].v == 0, "standing still: still lap 1");
-}
-
-static void crashes(void) {
- tr_race r;
- /* into the roadside: Sunset Coast's palms, flat out to the right */
- tr_setup s = plain(MODE_RACE, 0, LEVEL_EASY);
- tr_new(&r, &TT, &s, 9);
- r.phase = PH_RACE, r.countdown = 0;
- r.car[0].z = 200 * FX, r.car[0].v = 55 * FX;
- int hits = 0, max_x = 0;
- for (int i = 0; i < 600; i++) {
- clear_field(&r);
- uint16_t d = r.damage;
- tr_step(&r, &TT, IN_GAS | IN_RIGHT, 0);
- if (r.damage > d) hits++;
- if (r.car[0].x > max_x) max_x = r.car[0].x;
- }
- CHECK(hits > 0 && r.damage > 0, "the palms are solid (%d hits)", hits);
- CHECK(max_x <= TR_OUT, "never past the edge (%d)", max_x);
- /* weaving off the road among the trees, from either side: never through one */
- int through = 0, bumps = 0;
- for (int id = 0; id < TR_TRACKS; id++) {
- s = plain(MODE_RACE, id, LEVEL_EASY);
- tr_new(&r, &TT, &s, 2);
- r.phase = PH_RACE, r.countdown = 0;
- uint32_t w = 99;
- for (int i = 0; i < 9000; i++) {
- clear_field(&r);
- r.damage = 0;
- if (i % 40 == 0) w = w * 1103515245u + 12345u;
- unsigned in = IN_GAS | ((w >> 16) & 1 ? IN_LEFT : IN_RIGHT) | (i % 300 < 20 ? IN_NITRO : 0);
- int32_t x0 = r.car[0].x, z0 = r.car[0].z;
- uint16_t imp = r.impact;
- tr_step(&r, &TT, in, 0);
- if (r.impact > imp) bumps++;
- int32_t per = TR_SEG * FX, base = z0 >= 0 ? z0 / per : -((-z0 + per - 1) / per);
- for (int k = -1; k <= 1; k++)
- for (int side = -1; side <= 1; side += 2) {
- tr_thing o = tr_scenery(&TT, (int)(base + k), side);
- if (o.kind < 0) continue;
- int32_t oz = (base + k) * per + per / 2;
- if (abs(oz - z0) >= 2 * FX || abs(oz - r.car[0].z) >= 2 * FX) continue;
- if ((x0 < o.x) != (r.car[0].x < o.x)) through++;
- }
- }
- }
- CHECK(!through && bumps > 50, "through the roadside %d times (%d bumps)", through, bumps);
- /* no car is ever inside another: a whole field driven with random keys */
- uint32_t lcg = 77;
- int inside = 0;
- for (int id = 0; id < TR_TRACKS; id++) {
- s = plain(MODE_RACE, id, LEVEL_EXPERT);
- tr_new(&r, &TT, &s, (uint32_t)id + 1);
- for (int i = 0; i < 6000 && r.phase != PH_DONE; i++) {
- lcg = lcg * 1103515245u + 12345u;
- unsigned in = (lcg >> 16) & 31;
- tr_step(&r, &TT, in | IN_GAS, 0);
- for (int a = 0; a < TR_CARS; a++)
- for (int b = a + 1; b < TR_CARS; b++) {
- int32_t dz = tr_wrap(&TT, r.car[b].z - r.car[a].z), dx = r.car[b].x - r.car[a].x;
- if (abs(dz) < TR_CAR_LEN - FX / 4 && abs(dx) < TR_CAR_WID - FX / 4) inside++;
- }
- }
- }
- CHECK(!inside, "cars inside each other %d times", inside);
- /* ramming the car in front: you stop at its bumper, it takes the knock */
- s = plain(MODE_RACE, 0, LEVEL_EASY);
- tr_new(&r, &TT, &s, 3);
- r.phase = PH_RACE, r.countdown = 0;
- r.car[0].z = 100 * FX, r.car[0].x = 0, r.car[0].v = 60 * FX;
- clear_field(&r);
- r.car[1].z = 108 * FX, r.car[1].x = 0, r.car[1].lane = 0, r.car[1].v = 20 * FX, r.car[1].think = 60;
- bool passed_through = false;
- for (int i = 0; i < 100; i++) {
- for (int k = 2; k < TR_CARS; k++) r.car[k].z = r.car[0].z - TT.length / 2, r.car[k].v = r.car[0].v;
- r.car[1].think = 60;
- tr_step(&r, &TT, IN_GAS, 0);
- if (r.car[0].z > r.car[1].z && abs(r.car[0].x - r.car[1].x) < TR_CAR_WID) passed_through = true;
- }
- CHECK(!passed_through, "drove through the car in front");
- CHECK(r.damage > 0, "the knock hurt");
- /* wrecked at 100%: out of the race, no prize but the minimum */
- tr_new(&r, &TT, &s, 3);
- r.phase = PH_RACE, r.countdown = 0, r.damage = 995;
- r.car[0].z = 200 * FX, r.car[0].v = 50 * FX;
- for (int i = 0; i < 800 && r.phase == PH_RACE; i++) tr_step(&r, &TT, IN_GAS | IN_RIGHT, 0);
- CHECK(r.phase == PH_DONE && r.end == END_WRECK, "wrecked at 100%% (end %d)", r.end);
-}
-
-static void rivals(void) {
- uint32_t h = 0;
- for (int id = 0; id < TR_TRACKS; id++) {
- for (int level = 0; level < 3; level++) {
- tr_race r;
- tr_setup s = plain(MODE_RACE, id, level);
- tr_new(&r, &TT, &s, (uint32_t)(id * 3 + level + 1));
- /* you sit on the grid: the rivals race on their own */
- int steps = 0;
- while (r.finished < TR_CARS - 1 && steps < 11 * 60 * TR_HZ) {
- tr_step(&r, &TT, 0, 0), steps++;
- h = hash_race(&r, h);
- }
- CHECK(r.finished == TR_CARS - 1, "%s, %s: %d of 7 rivals finished", tr_track_name[id], level ? level == 1 ? "normal" : "expert" : "easy",
- r.finished);
- uint32_t first = 0, last = 0;
- for (int i = 1; i < TR_CARS; i++) {
- if (r.car[i].place == 1) first = r.car[i].finish_ms;
- if (r.car[i].place == 7) last = r.car[i].finish_ms;
- }
- if (level == 1) printf(" %-14s rivals: %u:%04.1f to %u:%04.1f\n", tr_track_name[id], first / 60000, first % 60000 / 1000.0, last / 60000, last % 60000 / 1000.0);
- CHECK(last - first < 60000, "%s level %d: the field spread over %u ms", tr_track_name[id], level, last - first);
- }
- }
- printf(" rivals' hash %08x\n", h);
-}
-
-/* the bot against the field: stock car, every circuit and level */
-static void racing(void) {
- int wins[3] = {0}, finishes = 0;
- for (int level = 0; level < 3; level++)
- for (int id = 0; id < TR_TRACKS; id++) {
- tr_race r;
- int steps = drive(&r, id, level, MODE_RACE, (uint32_t)(100 + id + level * 7), 100, NULL);
- CHECK(steps > 0, "%s level %d: the bot didn't finish (end %d)", tr_track_name[id], level, r.end);
- if (steps) finishes++;
- if (tr_rank(&r, 0) == 1) wins[level]++;
- if (level == 1)
- printf(" %-14s L%d you %u:%04.1f, %d%s, damage %d%%\n", tr_track_name[id], level, r.time_ms / 60000, r.time_ms % 60000 / 1000.0,
- tr_rank(&r, 0), "", r.damage / 10);
- }
- printf(" the bot won %d easy, %d normal, %d expert races of 6 each\n", wins[0], wins[1], wins[2]);
- CHECK(finishes == 18, "%d of 18 races finished", finishes);
- CHECK(wins[0] >= 4, "easy should be easy (%d wins)", wins[0]);
-}
-
-
-/* the bot, fully upgraded, against Expert */
-static void upgraded(void) {
- int wins = 0;
- for (int id = 0; id < TR_TRACKS; id++) {
- tr_race r;
- tr_setup s = plain(MODE_RACE, id, LEVEL_EXPERT);
- for (int k = 0; k < 4; k++) s.up[k] = 4;
- tr_new(&r, &TT, &s, (uint32_t)(300 + id));
- bot_skill = 100, bot_lane = r.car[0].x;
- for (int steps = 0; r.phase != PH_DONE && steps < 11 * 60 * TR_HZ; steps++) tr_step(&r, &TT, bot(&r, &TT), 0);
- if (r.end == END_FINISH && tr_rank(&r, 0) == 1) wins++;
- }
- printf(" fully upgraded, the bot won %d of 6 Expert races\n", wins);
- CHECK(wins >= 3, "a full car should win against Expert (%d of 6)", wins);
-}
-
-/* Free Ride: traffic comes and goes, cars passed are counted, no damage, the odometer runs */
-static void free_ride(void) {
- tr_race r;
- tr_setup s = plain(MODE_FREE, 3, 2);
- tr_new(&r, &TT, &s, 8);
- CHECK(r.phase == PH_RACE && tr_traffic(&r) == 6, "Free Ride starts at once, busy: 6 cars");
- bot_skill = 100, bot_lane = 0;
- int inside = 0;
- for (int i = 0; i < 10 * 60 * TR_HZ; i++) {
- tr_step(&r, &TT, bot(&r, &TT), 0);
- CHECK(tr_valid(&r), "Free Ride not valid at %d", i);
- for (int a = 0; a <= tr_traffic(&r); a++)
- for (int b = a + 1; b <= tr_traffic(&r); b++) {
- int32_t dz = tr_wrap(&TT, r.car[b].z - r.car[a].z), dx = r.car[b].x - r.car[a].x;
- if (abs(dz) < TR_CAR_LEN - FX / 4 && abs(dx) < TR_CAR_WID - FX / 4) inside++;
- }
- if (!tr_valid(&r)) break;
- }
- printf(" Free Ride: %.1f km in 10 minutes, %u cars passed\n", r.odometer / 256000.0, r.passes);
- CHECK(r.phase == PH_RACE && r.damage == 0, "Free Ride never ends nor hurts");
- CHECK(r.passes > 40 && r.odometer > 15000 * FX, "Free Ride: traffic to pass (%u) and distance", r.passes);
- CHECK(!inside, "traffic inside each other %d times", inside);
-}
-
-/* the same race twice, to the same hash on every computer */
-static void same_twice(void) {
- uint32_t h1 = 0, h2 = 0;
- tr_race a, b;
- drive(&a, 4, LEVEL_NORMAL, MODE_GP, 2026, 100, &h1);
- drive(&b, 4, LEVEL_NORMAL, MODE_GP, 2026, 100, &h2);
- printf(" a race's hash %08X\n", h1);
- CHECK(h1 == h2 && h1 == RACE_HASH, "the same race twice, and as on every computer: %08X", h1);
-}
-
-/* ---------------------------------------------------------------- saves */
-static void saves(void) {
- memset(files, 0, sizeof files);
- tr_file a, b;
- memset(&a, 0, sizeof a);
- tr_fresh(&a.p, &a.gp);
- a.p.credits = 12345, a.p.races = 9, a.p.wins = 4, a.p.titles = 1, a.p.up[0] = 3, a.p.up[3] = 4, a.p.paint = 5;
- a.p.style = 1, a.p.mode = MODE_FREE, a.p.track = 4, a.p.mood = 2, a.p.rain = 1, a.p.manual = 1, a.p.guide = 1;
- a.p.best_ms[2] = 160000, a.p.best_lap_ms[2] = 51000, a.p.best_lap_ms[5] = 47000;
- a.gp.on = 1, a.gp.round = 3;
- for (int i = 0; i < TR_CARS - 1; i++) a.gp.skill[i] = (uint8_t)(6 - i);
- a.gp.points[0] = 30, a.gp.points[3] = 41;
- tr_setup s = plain(MODE_GP, 3, 2);
- tr_new(&a.race, &TT, &s, 4);
- for (int i = 0; i < 2500; i++) tr_step(&a.race, &TT, bot(&a.race, &TT), 0);
- a.has_race = 1;
- CHECK(save_write(&a), "saved");
- CHECK(save_load(&b) && !memcmp(&a.p, &b.p, sizeof a.p) && !memcmp(&a.gp, &b.gp, sizeof a.gp) && b.has_race &&
- !memcmp(&a.race, &b.race, sizeof a.race), "read back as written");
- /* the copy in the script brings it back when the save is gone */
- forget(TR_SAVE_NAME);
- CHECK(save_load(&b) && b.p.credits == 12345 && b.has_race, "back from turborush_saves.py");
- CHECK(plat_load(TR_SAVE_NAME, &(uint32_t){0}) != NULL, "and put back in turborush.sav");
- /* every byte damaged in turn: never read (with the copy gone, a fresh start) */
- uint32_t n;
- uint8_t good[sizeof(tr_file)];
- memcpy(good, file_data(TR_SAVE_NAME, &n), sizeof good);
- forget(TR_COPY_NAME);
- int bad = 0;
- for (uint32_t i = 0; i < sizeof good; i++) {
- uint8_t *d = file_data(TR_SAVE_NAME, &n);
- memcpy(d, good, sizeof good);
- d[i] ^= (uint8_t)(1 + i % 255);
- if (save_load(&b) || b.p.credits || b.has_race || b.gp.on) bad++;
- }
- CHECK(!bad, "%d damaged saves read", bad);
- /* cut short, too long, empty, another version: a fresh start */
- uint8_t *d = file_data(TR_SAVE_NAME, &n);
- memcpy(d, good, sizeof good);
- files[0].len = sizeof good - 1;
- for (int k = 0; k < 4; k++) if (files[k].on && !strcmp(files[k].name, TR_SAVE_NAME)) files[k].len = sizeof good - 1;
- CHECK(!save_load(&b) && b.p.level == LEVEL_NORMAL, "a short save: fresh");
- tr_file v = a;
- v.version = 2;
- v.sum = tr_sum(&v, offsetof(tr_file, sum));
- plat_save(TR_SAVE_NAME, &v, sizeof v);
- CHECK(!save_load(&b), "another version: fresh");
- /* a checksum that fits over values that don't: not read either */
- uint32_t lcg = 5;
- int read = 0;
- for (int k = 0; k < 400; k++) {
- tr_file x;
- memcpy(&x, good, sizeof x);
- uint8_t *p = (uint8_t *)&x;
- for (int j = 0; j < 3; j++) {
- lcg = lcg * 1103515245u + 12345u;
- uint32_t at = 8 + (lcg >> 8) % (offsetof(tr_file, sum) - 8);
- p[at] = (uint8_t)(lcg >> 24);
- }
- x.sum = tr_sum(&x, offsetof(tr_file, sum));
- plat_save(TR_SAVE_NAME, &x, sizeof x);
- if (save_load(&b)) {
- read++;
- /* whatever was accepted must race and draw safely */
- if (b.has_race) {
- tr_build(&TT, b.race.track);
- int went_bad = 0;
- for (int i = 0; i < 300; i++) {
- tr_step(&b.race, &TT, (unsigned)i & 31, 0);
- if (!tr_valid(&b.race)) went_bad++;
- }
- CHECK(!went_bad, "an accepted race went bad");
- }
- }
- }
- printf(" saves: %d of 400 changed saves with a fitting checksum were still in range\n", read);
- /* odd but possible races (cars on top of each other, flat out, stopped, wide): read, then raced and drawn */
- int odd = 0, odd_bad = 0;
- for (int k = 0; k < 200; k++) {
- tr_file x;
- memcpy(&x, good, sizeof x);
- for (int i = 0; i < TR_CARS; i++) {
- tr_car *c = &x.race.car[i];
- lcg = lcg * 1103515245u + 12345u;
- c->z = (int32_t)(lcg >> 9) % (3 * 1800 * FX);
- lcg = lcg * 1103515245u + 12345u;
- c->x = i ? ((int32_t)(lcg >> 8) % (2 * TR_ROAD)) - TR_ROAD : ((int32_t)(lcg >> 8) % (2 * TR_OUT)) - TR_OUT;
- c->lane = ((int32_t)(lcg >> 20) % 3 - 1) * TR_LANE;
- lcg = lcg * 1103515245u + 12345u;
- c->v = (int32_t)(lcg >> 8) % (90 * FX);
- c->vx = 0;
- }
- x.race.car[1].z = x.race.car[2].z, x.race.car[1].x = x.race.car[2].x; /* two cars in one place */
- x.sum = tr_sum(&x, offsetof(tr_file, sum));
- plat_save(TR_SAVE_NAME, &x, sizeof x);
- if (!save_load(&b) || !b.has_race) continue;
- odd++;
- tr_build(&TT, b.race.track);
- for (int i = 0; i < 400; i++) {
- tr_step(&b.race, &TT, bot(&b.race, &TT), 0);
- if (!tr_valid(&b.race)) odd_bad++;
- }
- view_setup(&TT, b.race.mood, b.race.rain);
- tr_render(&b, &TT, &b.race, &b.race, 256, &ui);
- }
- CHECK(odd > 150 && !odd_bad, "odd races: %d read, %d steps gone bad", odd, odd_bad);
- /* storage full: the game says so, and goes on */
- memset(files, 0, sizeof files);
- storage_full = true;
- CHECK(!save_write(&a), "a full storage fails the save");
- storage_full = false;
- memset(files, 0, sizeof files);
-}
-
-/* ---------------------------------------------------------------- the whole app, with keys */
-static int bad_frames;
-static void check_state(void) {
- if (ui.screen >= V_SCREENS) bad_frames++;
- if (sv.has_race && !tr_valid(&sv.race)) bad_frames++;
- if (sv.p.credits > TR_MAX_CREDITS || sv.p.wins > sv.p.races) bad_frames++;
- for (int k = 0; k < 4; k++) if (sv.p.up[k] > 4) bad_frames++;
- if (sv.gp.on && sv.gp.round >= TR_TRACKS) bad_frames++;
-}
-
-/* keys: a press every other frame for menus, or the bot's driving in a race */
-static uint32_t (*menu_keys)(uint32_t f);
-static uint32_t drive_keys(uint32_t f) {
- if (ui.screen == V_RACE && !ui.hold && sv.race.phase != PH_DONE) {
- unsigned in = bot(&sv.race, &track);
- uint32_t k = 0;
- if (in & IN_GAS) k |= TK_UP;
- if (in & IN_BRAKE) k |= TK_DOWN;
- if (in & IN_LEFT) k |= TK_LEFT;
- if (in & IN_RIGHT) k |= TK_RIGHT;
- if (in & IN_NITRO) k |= TK_OK;
- return k;
- }
- return menu_keys ? menu_keys(f) : 0;
-}
-
-/* the Grand Prix: Play, Start, the guide, six races driven by the bot, the standings after each, then the menu */
-static uint32_t gp_menu(uint32_t f) {
- if (f % 4) return 0;
- switch (ui.screen) {
- case V_TITLE: return ui.menu[ui.sel] == MENU_PLAY ? TK_OK : TK_DOWN;
- case V_SETUP: return ui.sel == SET_START ? TK_OK : TK_DOWN;
- case V_GUIDE: return TK_OK;
- case V_RESULT: return ui.sel == 0 ? TK_OK : TK_UP;
- case V_STANDINGS: return ui.sel == 0 ? TK_OK : TK_LEFT;
- default: return 0;
- }
-}
-
-static void grand_prix(void) {
- memset(files, 0, sizeof files);
- frame_gap = 60;
- script = drive_keys, menu_keys = gp_menu, watch = check_state;
- frame_no = 0, quit_at = 4000000, bad_frames = 0;
- void watch_gp(void); /* (it stops at the menu after the last race) */
- watch = watch_gp;
- tr_app_main();
- script = 0, menu_keys = 0, watch = 0;
- tr_file f;
- CHECK(save_load(&f), "the Grand Prix saved");
- CHECK(f.p.races == 6 && !f.gp.on && !f.has_race && f.p.guide == 1, "six races, the Grand Prix over (races %u, gp %d)",
- f.p.races, f.gp.on);
- CHECK(f.p.credits >= 6 * 50 + 200, "credits earned: %u", f.p.credits);
- printf(" Grand Prix through the keys: %u wins, %u credits, title %u, %u frames\n", f.p.wins, f.p.credits, f.p.titles,
- frame_no);
- CHECK(!bad_frames, "%d bad frames", bad_frames);
-}
-static int gp_phase;
-void watch_gp(void) {
- check_state();
- if (ui.screen == V_STANDINGS && ui.round_done >= TR_TRACKS) gp_phase = 1;
- if (gp_phase == 1 && ui.screen == V_TITLE) quit_at = frame_no + 2, gp_phase = 2;
-}
-
-/* Free Ride: chosen on the race screen, a minute of driving, pause, Quit game to the menu (kept), Continue, then
- Home: it's saved */
-static int fr_step;
-static uint32_t fr_menu(uint32_t f) {
- if (f % 4) return 0;
- switch (ui.screen) {
- case V_TITLE:
- if (fr_step >= 2) return ui.menu[ui.sel] == MENU_CONTINUE ? TK_OK : TK_UP;
- return ui.menu[ui.sel] == MENU_PLAY ? TK_OK : TK_DOWN;
- case V_SETUP:
- if (sv.p.mode != MODE_FREE) return ui.sel == SET_MODE ? TK_RIGHT : TK_UP;
- return ui.sel == SET_START ? TK_OK : TK_UP;
- case V_GUIDE: return TK_OK;
- case V_PAUSE: return ui.sel == PAUSE_QUIT ? TK_OK : TK_DOWN;
- case V_LEAVE: return ui.sel == 1 ? TK_OK : TK_DOWN;
- default: return 0;
- }
-}
-static uint32_t fr_keys(uint32_t f) {
- if (ui.screen == V_RACE && fr_step == 0 && sv.race.odometer > 1500 * FX) fr_step = 1;
- if (ui.screen == V_RACE && fr_step == 1) return f % 8 < 4 ? TK_BACK : 0;
- if (ui.screen == V_TITLE && fr_step == 1) fr_step = 2;
- if (ui.screen == V_RACE && fr_step == 2) fr_step = 3, quit_at = frame_no + 600;
- return drive_keys(f);
-}
-static void free_ride_app(void) {
- memset(files, 0, sizeof files);
- frame_gap = 60;
- fr_step = 0;
- script = fr_keys, menu_keys = fr_menu, watch = check_state;
- frame_no = 0, quit_at = 400000, bad_frames = 0;
- tr_app_main();
- script = 0, menu_keys = 0, watch = 0;
- tr_file f;
- CHECK(fr_step == 3, "the Free Ride steps (%d)", fr_step);
- CHECK(save_load(&f) && f.has_race && f.race.mode == MODE_FREE && f.race.odometer > 1500 * FX,
- "Free Ride kept on Home (%d)", f.has_race);
- CHECK(!bad_frames, "%d bad frames", bad_frames);
- printf(" Free Ride through the keys: %.1f km, kept on Home\n", f.race.odometer / 256000.0);
-}
-
-static uint32_t lcg_keys;
-static uint32_t rnd(void) { return lcg_keys = lcg_keys * 1103515245u + 12345u, lcg_keys >> 8; }
-static uint32_t held_keys, held_until;
-static uint32_t random_keys(uint32_t f) {
- if (f >= held_until) {
- static const uint32_t pick[] = {TK_OK, TK_OK, TK_OK, TK_LEFT, TK_RIGHT, TK_UP, TK_UP, TK_UP, TK_DOWN, TK_BACK,
- TK_GEAR_UP, TK_GEAR_DOWN, TK_UP | TK_OK, TK_UP | TK_LEFT, 0, 0};
- held_keys = pick[rnd() % (sizeof pick / sizeof pick[0])];
- held_until = f + 2 + rnd() % 40;
- }
- return held_keys;
-}
-
-static void fuzz(void) {
- memset(files, 0, sizeof files);
- frame_gap = 90;
- int sessions = 0, kept = 0;
- for (int s = 0; s < 300; s++) {
- lcg_keys = (uint32_t)s * 2654435761u + 1;
- if (s % 40 == 0) memset(files, 0, sizeof files);
- storage_full = s % 37 == 36;
- script = random_keys, watch = check_state;
- frame_no = 0, quit_at = 2000 + rnd() % 6000, held_until = 0, bad_frames = 0;
- tr_app_main();
- sessions++;
- storage_full = false;
- tr_file f;
- if (save_load(&f)) kept += f.has_race;
- CHECK(!bad_frames, "session %d: %d bad frames", s, bad_frames);
- }
- script = 0, watch = 0;
- printf(" keys: %d sessions of random keys, quit with Home each time (%d left a race going)\n", sessions, kept);
-}
-
-static void test(const char *dir) {
- printf("circuits\n");
- tracks();
- printf("laps\n");
- laps();
- printf("crashes\n");
- crashes();
- printf("rivals\n");
- rivals();
- printf("racing\n");
- racing();
- upgraded();
- printf("Free Ride\n");
- free_ride();
- printf("the same race\n");
- same_twice();
- printf("saves\n");
- saves();
- printf("the app\n");
- grand_prix();
- free_ride_app();
- fuzz();
- printf(fails ? "%d FAILED\n" : "all good\n", fails);
-}
-
-/* ---------------------------------------------------------------- pictures */
-static void picture(const char *dir, const char *name) {
- bool title = ui.screen == V_TITLE || ui.screen == V_QUIT;
- tr_render(&sv, &track, title ? &demo_prev : &prev, title ? &demo : &sv.race, 256, &ui);
- shot(dir, name);
-}
-
-static void race_at(int id, int mood, int rain, int level, float meters) {
- tr_setup s = plain(MODE_RACE, id, level);
- s.mood = (uint8_t)mood, s.rain = (uint8_t)rain, s.paint = sv.p.paint, s.style = sv.p.style;
- tr_new(&sv.race, &track, &s, 11);
- shown_track = -1;
- show(&sv.race);
- bot_skill = 100;
- while (sv.race.car[0].z < (int32_t)(meters * FX) && sv.race.phase != PH_DONE) {
- prev = sv.race;
- tr_step(&sv.race, &track, bot(&sv.race, &track), 0);
- }
- prev = sv.race;
- sv.has_race = 1;
-}
-
-static void shots(const char *dir) {
- memset(&sv, 0, sizeof sv);
- tr_fresh(&sv.p, &sv.gp);
- sv.p.credits = 2350, sv.p.up[0] = 2, sv.p.up[1] = 1, sv.p.races = 14, sv.p.wins = 5, sv.p.titles = 1;
- sv.p.best_ms[0] = 151300, sv.p.best_lap_ms[0] = 49200, sv.p.best_ms[2] = 163800, sv.p.best_lap_ms[2] = 53100;
- now = 1000;
- to_title();
- for (int i = 0; i < 400; i++) demo_prev = demo, tr_step(&demo, &track, 0, 0);
- picture(dir, "title");
- ui.screen = V_SETUP, ui.sel = SET_START;
- picture(dir, "setup");
- ui.screen = V_GARAGE, ui.sel = 0, ui.note[0] = 0;
- picture(dir, "garage");
- ui.screen = V_RECORDS;
- picture(dir, "records");
- for (int k = 0; k < TR_HELP_PAGES; k++) {
- ui.screen = V_HELP, ui.page = (uint8_t)k;
- char n[16];
- snprintf(n, sizeof n, "help%d", k);
- picture(dir, n);
- }
- ui.screen = V_RACE;
- race_at(0, MOOD_DAY, 0, 1, -10);
- picture(dir, "grid");
- static const float AT[6] = {700, 900, 1250, 600, 820, 700};
- for (int id = 0; id < TR_TRACKS; id++) {
- race_at(id, id == 5 ? MOOD_NIGHT : id == 2 ? MOOD_SUNSET : MOOD_DAY, 0, 1, AT[id]);
- char n[16];
- snprintf(n, sizeof n, "track%d", id);
- picture(dir, n);
- }
- race_at(2, MOOD_DAY, 0, 1, 300);
- sv.race.boost = 1, prev.boost = 1;
- picture(dir, "nitro");
- sv.p.style = 1;
- race_at(2, MOOD_DAY, 0, 1, 300);
- sv.race.boost = 1, prev.boost = 1;
- picture(dir, "nitro2");
- sv.p.style = 0;
- race_at(1, MOOD_DAY, 1, 1, 500);
- picture(dir, "rain");
- ui.screen = V_PAUSE, ui.sel = 0;
- picture(dir, "pause");
- ui.screen = V_LEAVE, ui.sel = 1;
- picture(dir, "leave");
- /* banners */
- ui.screen = V_RACE;
- race_at(0, MOOD_SUNSET, 0, 1, 2300);
- picture(dir, "banner_lap");
- race_at(4, MOOD_DAY, 0, 0, 4700);
- picture(dir, "banner_final");
- /* a Grand Prix race to the end, then the results and standings */
- memset(&sv.gp, 0, sizeof sv.gp);
- gp_new();
- tr_setup st = setup_of(MODE_GP, 0);
- tr_new(&sv.race, &track, &st, 21);
- shown_track = -1;
- show(&sv.race);
- sv.has_race = 1;
- while (!(sv.race.phase == PH_DONE && sv.race.done >= 3 * TR_HZ)) {
- prev = sv.race;
- tr_step(&sv.race, &track, bot(&sv.race, &track), 0);
- if (sv.race.phase == PH_DONE && sv.race.done == 20) {
- prev = sv.race;
- picture(dir, "banner_finish");
- }
- }
- finish_race();
- picture(dir, "result");
- ui.screen = V_STANDINGS, ui.sel = 0;
- picture(dir, "standings");
- /* Free Ride */
- ui.screen = V_RACE;
- sv.p.traffic = 2;
- race_begin(MODE_FREE, 3);
- for (int i = 0; i < 2600; i++) prev = sv.race, tr_step(&sv.race, &track, bot(&sv.race, &track), 0);
- prev = sv.race;
- picture(dir, "free");
- /* the confirmations */
- ui.screen = V_NEWRUN, ui.sel = 0;
- picture(dir, "newrun");
- to_title();
- for (int i = 0; i < 300; i++) demo_prev = demo, tr_step(&demo, &track, 0, 0);
- ui.screen = V_QUIT, ui.sel = 0;
- picture(dir, "quit");
- ui.screen = V_GARAGE, ui.sel = 3;
- garage_buy(3);
- picture(dir, "garage_buy");
- ui.screen = V_TITLE, ui.sel = 0, ui.save_failed = true;
- picture(dir, "title_full");
- ui.save_failed = false;
-}
-
-/* raw frames of a race, the bot driving, every 40 ms (for tools/record.py) */
-static void film(const char *dir, int ms, int id, int mood) {
- memset(&sv, 0, sizeof sv);
- tr_fresh(&sv.p, &sv.gp);
- sv.p.mood = (uint8_t)mood, sv.p.level = 1;
- now = 0;
- ui.screen = V_RACE;
- race_begin(MODE_RACE, id);
- bot_lane = sv.race.car[0].x;
- int frame = 0;
- for (int t = 0; t < ms; t += TR_TICK) {
- prev = sv.race;
- tr_step(&sv.race, &track, bot(&sv.race, &track), 0);
- if (t % 40) continue;
- tr_render(&sv, &track, &prev, &sv.race, 256, &ui);
- char path[512];
- snprintf(path, sizeof path, "%s/%06d_%06d.raw", dir, frame++, t);
- FILE *f = fopen(path, "wb");
- if (!f) exit(2);
- fwrite(fb, 2, 320 * 240, f);
- fclose(f);
- }
-}
-
-/* the README's pictures: a race on each circuit, taken once some rivals are close ahead */
-static void doc_race(const char *dir, const char *name, int id, int mood, int rain, int style, int paint, int after_ms) {
- memset(&sv, 0, sizeof sv);
- tr_fresh(&sv.p, &sv.gp);
- sv.p.mood = (uint8_t)mood, sv.p.rain = (uint8_t)rain, sv.p.style = (uint8_t)style, sv.p.paint = (uint8_t)paint;
- sv.p.level = 1, sv.p.guide = 1;
- now = 0, ui.screen = V_RACE;
- race_begin(MODE_RACE, id);
- bot_lane = sv.race.car[0].x;
- for (int t = 0; t < 4 * 60000; t += TR_TICK) {
- prev = sv.race;
- tr_step(&sv.race, &track, bot(&sv.race, &track), 0);
- if (t < after_ms || sv.race.offroad || sv.race.banner_t) continue;
- int close = 0;
- for (int i = 1; i < TR_CARS; i++) {
- int32_t dz = tr_wrap(&track, sv.race.car[i].z - sv.race.car[0].z);
- if (dz > 8 * FX && dz < 70 * FX) close++;
- }
- if (close >= 2) break;
- }
- prev = sv.race;
- picture(dir, name);
-}
-
-static void docs(const char *dir) {
- doc_race(dir, "shot", 0, MOOD_DAY, 0, 0, 0, 16000);
- doc_race(dir, "alpine", 4, MOOD_DAY, 0, 1, 2, 20000);
- doc_race(dir, "desert", 2, MOOD_SUNSET, 0, 0, 3, 24000);
- doc_race(dir, "night", 5, MOOD_NIGHT, 0, 1, 1, 18000);
- doc_race(dir, "rain", 1, MOOD_DAY, 1, 0, 4, 22000);
- /* the standings after the first Grand Prix race, the garage, the race screen and the title */
- memset(&sv, 0, sizeof sv);
- tr_fresh(&sv.p, &sv.gp);
- sv.p.guide = 1;
- now = 0;
- gp_new();
- race_begin(MODE_GP, 0);
- bot_lane = sv.race.car[0].x;
- while (!(sv.race.phase == PH_DONE && sv.race.done >= 3 * TR_HZ)) prev = sv.race, tr_step(&sv.race, &track, bot(&sv.race, &track), 0);
- finish_race();
- ui.screen = V_STANDINGS, ui.sel = 0;
- picture(dir, "standings");
- sv.p.credits = 1840, sv.p.up[0] = 2, sv.p.up[1] = 1, sv.p.up[2] = 1, sv.p.paint = 2;
- ui.screen = V_GARAGE, ui.sel = 0, ui.note[0] = 0;
- picture(dir, "garage");
- sv.p.mode = MODE_RACE, sv.p.track = 4, sv.p.best_ms[4] = 172400, sv.p.best_lap_ms[4] = 55100;
- ui.screen = V_SETUP, ui.sel = SET_START;
- picture(dir, "setup");
- sv.p.track = 0, sv.has_race = 0;
- memset(&sv.gp, 0, sizeof sv.gp);
- to_title();
- for (int i = 0; i < 500; i++) demo_prev = demo, tr_step(&demo, &track, 0, 0);
- picture(dir, "title");
-}
-
-int main(int argc, char **argv) {
- if (argc >= 3 && !strcmp(argv[1], "docs")) {
- docs(argv[2]);
- return 0;
- }
- if (argc >= 5 && !strcmp(argv[1], "film")) {
- film(argv[2], atoi(argv[3]), atoi(argv[4]), argc > 5 ? atoi(argv[5]) : 0);
- return 0;
- }
- if (argc >= 3 && !strcmp(argv[1], "test")) {
- test(argv[2]);
- return fails ? 1 : 0;
- }
- if (argc >= 3 && !strcmp(argv[1], "shots")) {
- shots(argv[2]);
- return 0;
- }
- fprintf(stderr, "usage: play test DIR | shots DIR | docs DIR | film DIR MS CIRCUIT [TIME]\n");
- return 2;
-}
diff --git a/games/turborush/tools/art.py b/games/turborush/tools/art.py
deleted file mode 100644
index 9bd36503..00000000
--- a/games/turborush/tools/art.py
+++ /dev/null
@@ -1,187 +0,0 @@
-#!/usr/bin/env python3
-"""Packs Turbo Rush's pictures (art/, indexed PNGs) into C: art.c and art.h in OUT.
-
- art.py ART_DIR OUT_DIR
-
-- cars.png: the six car pictures side by side (96 x 64: the coupe turning left, straight, right, then the
- supercar), index 63 transparent; palette entries 0-23 are the body paint from darkest to lightest, recoloured
- here for each of the eight paints, 24-31 the lights;
-- scenery/*.png: the roadside pictures, each with its own palette, index 63 transparent;
-- sky/*.png: the four 400 x 100 backdrops, 64 colours each.
-
-Each sprite also gets two smaller copies (half and quarter size) so that far away it doesn't shimmer. Everything
-here is integer arithmetic, so the output is the same on every computer.
-"""
-import sys
-from pathlib import Path
-
-import numpy as np
-from PIL import Image
-
-T = 63
-SCENERY = ["palm", "pine", "rock", "tower", "sign", "cactus", "villa", "lamp"]
-SKIES = ["coast", "alps", "desert", "city"]
-# the paints, as the body's middle shade (sRGB)
-PAINTS = [(206, 26, 30), (240, 186, 30), (30, 96, 206), (26, 150, 84), (226, 226, 220), (126, 70, 196),
- (236, 110, 24), (52, 56, 66)]
-
-
-def load(path):
- im = Image.open(path)
- assert im.mode == "P", path
- pal = im.getpalette()[:192]
- pal += [0] * (192 - len(pal))
- return np.array(im, dtype=np.int64), np.array(pal, dtype=np.int64).reshape(64, 3)
-
-
-def rgb565(c):
- r, g, b = (int(v) for v in c)
- return (r >> 3) << 11 | (g >> 2) << 5 | b >> 3
-
-
-def lum(c):
- return (299 * int(c[0]) + 587 * int(c[1]) + 114 * int(c[2])) // 1000
-
-
-def nearest(colors, pal, allowed):
- """For each colour (N x 3), the closest palette entry among `allowed` (lowest index on ties)."""
- cand = pal[allowed]
- d = ((colors[:, None, :] - cand[None, :, :]) ** 2).sum(-1)
- return np.array(allowed)[d.argmin(1)]
-
-
-def shrink(idx, pal, classes=None):
- """Half size: each 2 x 2 block becomes opaque when at least two of its pixels are, with the average colour of
- those, matched in the block's majority class (classes: an entry -> class table, the body paint averaging its
- shade instead)."""
- h, w = idx.shape
- h2, w2 = (h + 1) // 2, (w + 1) // 2
- pad = np.full((h2 * 2, w2 * 2), T, np.int64)
- pad[:h, :w] = idx
- out = np.full((h2, w2), T, np.int64)
- for y in range(h2):
- for x in range(w2):
- block = [v for v in pad[2 * y:2 * y + 2, 2 * x:2 * x + 2].flatten() if v != T]
- if len(block) < 2:
- continue
- if classes is None:
- c = pal[block].sum(0) // len(block)
- out[y, x] = nearest(c[None, :], pal, list(range(T)))[0]
- continue
- cls = [classes[v] for v in block]
- best = max(set(cls), key=lambda k: (cls.count(k), -k))
- mine = [v for v in block if classes[v] == best]
- if best == 0: # the paint: its shade
- out[y, x] = (sum(mine) + len(mine) // 2) // len(mine)
- else:
- c = pal[mine].sum(0) // len(mine)
- out[y, x] = nearest(c[None, :], pal, [i for i in range(T) if classes[i] == best])[0]
- return out
-
-
-class Out:
- def __init__(self):
- self.c, self.h = [], []
-
- def array(self, kind, name, values, per=24):
- vals = [int(v) for v in values]
- self.c.append(f"const {kind} {name}[{len(vals)}] = {{")
- for i in range(0, len(vals), per):
- self.c.append(" " + ",".join(str(v) for v in vals[i:i + per]) + ",")
- self.c.append("};")
- self.h.append(f"extern const {kind} {name}[{len(vals)}];")
-
-
-def sprite(out, name, idx, pal, classes=None):
- """A sprite and its two smaller copies: pixels row by row, and each row's first and last opaque pixel."""
- levels = [idx]
- for _ in range(2):
- levels.append(shrink(levels[-1], pal, classes))
- mips = []
- for k, im in enumerate(levels):
- h, w = im.shape
- spans = []
- for row in im:
- xs = np.where(row != T)[0]
- spans += [int(xs[0]), int(xs[-1]) + 1] if len(xs) else [0, 0]
- out.array("uint8_t", f"{name}_px{k}", im.flatten())
- out.array("uint8_t", f"{name}_sp{k}", spans)
- mips.append(f"{{{w}, {h}, {name}_px{k}, {name}_sp{k}}}")
- return "{{" + ", ".join(mips) + "}}"
-
-
-def main():
- art, dst = Path(sys.argv[1]), Path(sys.argv[2])
- dst.mkdir(parents=True, exist_ok=True)
- out = Out()
- out.c.append("/* Made by tools/art.py from the pictures in art/. */")
- out.c.append('#include "art.h"')
-
- # cars
- idx, pal = load(art / "cars.png")
- assert idx.shape == (64, 96 * 6)
- classes = [0] * 24 + [1] * 8 + [2] * (T - 32) + [3]
- cars = [sprite(out, f"car{k}", idx[:, k * 96:(k + 1) * 96], pal, classes) for k in range(6)]
- out.c.append(f"const art_sprite art_cars[6] = {{{', '.join(cars)}}};")
- shades = [lum(pal[k]) for k in range(24)]
- mid, top = shades[12], shades[23]
- paints = []
- for p in PAINTS:
- row = []
- for k in range(64):
- if k < 24:
- c = []
- for ch in range(3):
- if shades[k] <= mid:
- v = p[ch] * shades[k] // mid
- else:
- t = min(1000, (shades[k] - mid) * 1000 // max(1, top - mid))
- v = p[ch] + (255 - p[ch]) * t * 8 // 10000
- c.append(max(0, min(255, v)))
- row.append(rgb565(c))
- else:
- row.append(rgb565(pal[k]))
- paints += row
- out.array("uint16_t", "art_car_pal", paints, 16)
- out.h.append("#define ART_PAINTS 8")
-
- # scenery
- entries, pals, glow = [], [], []
- for name in SCENERY:
- idx, pal = load(art / "scenery" / f"{name}.png")
- entries.append(sprite(out, f"sc_{name}", idx, pal))
- pals += [rgb565(c) for c in pal]
- # lit windows and lamps: warm, bright and saturated; they stay lit at night
- bits = 0
- for k in range(T):
- r, g, b = (int(v) for v in pal[k])
- if r > 190 and g > 150 and b < 140 and r - b > 90:
- bits |= 1 << k
- glow.append(bits)
- out.c.append(f"const art_sprite art_scenery[{len(SCENERY)}] = {{{', '.join(entries)}}};")
- out.array("uint16_t", "art_scenery_pal", pals, 16)
- out.c.append("const uint64_t art_scenery_glow[%d] = {%s};" % (len(glow), ", ".join(f"{g}u" for g in glow)))
- out.h.append(f"extern const uint64_t art_scenery_glow[{len(glow)}];")
-
- # skies
- pals = []
- for k, name in enumerate(SKIES):
- idx, pal = load(art / "sky" / f"{name}.png")
- assert idx.shape == (100, 400), name
- out.array("uint8_t", f"art_sky{k}", idx.flatten(), 40)
- pals += [rgb565(c) for c in pal]
- out.c.append("const uint8_t *const art_sky[4] = {art_sky0, art_sky1, art_sky2, art_sky3};")
- out.array("uint16_t", "art_sky_pal", pals, 16)
-
- head = ["/* Made by tools/art.py. */", "#ifndef TR_ART_H", "#define TR_ART_H", "#include <stdint.h>",
- "#define ART_T 63 /* transparent */",
- "typedef struct { uint8_t w, h; const uint8_t *px, *span; } art_img;",
- "typedef struct { art_img mip[3]; } art_sprite;",
- "extern const art_sprite art_cars[6];", f"extern const art_sprite art_scenery[{len(SCENERY)}];",
- "extern const uint8_t *const art_sky[4];"]
- (dst / "art.h").write_text("\n".join(head + out.h + ["#endif"]) + "\n")
- (dst / "art.c").write_text("\n".join(out.c) + "\n")
-
-
-if __name__ == "__main__":
- main()
diff --git a/tests/test_games.py b/tests/test_games.py
index 749ec92d..a1b714c6 100644
--- a/tests/test_games.py
+++ b/tests/test_games.py
@@ -258,10 +258,6 @@ GAMES = {
# guide read. Next time, from the copy: Options, downscroll on (Back saves it), quit with On/Off
"fnf": ("FridayNightFunkin.nwa", "fnf.sav", presses((1500, "ok"), (2200, "ok"), (2900, "ok"), (3600, "back")), 7000,
presses((1500, "ok"), (2200, "down"), (2700, "down"), (3200, "ok"), (3900, "ok"), (4600, "back")), 6000),
- # the title's Play, Start, the first-run guide's OK, then the race: flat out, Back to pause, Home. Next time,
- # from the copy, Continue: the race again (after a 3, 2, 1), quit with On/Off
- "turborush": ("TurboRush.nwa", "turborush.sav", presses((1500, "ok"), (2200, "ok"), (2900, "ok"), (9500, "back"))
- + [(3500, 9000, K["up"])], 11000, presses((1500, "ok")) + [(3500, 6500, K["up"])], 7500),
# the title, Poached Eggs, its first level, the story, how to play (the first time), then a bird launched; Home
# keeps the play time. Next time, from the copy, the same level without the guide, quit with On/Off
"angrybirds": ("AngryBirds.nwa", "angrybirds.sav",
@@ -382,7 +378,7 @@ COPIES = {"championisland": "champion_saves.py", "numblocks": "numblocks_saves.p
"jetpackjoyride": "jetpackjoyride_saves.py", "stickmanhook": "stickmanhook_saves.py",
"donkeykong": "donkeykong_saves.py", "dune": "dune_saves.py", "monkeymart": "monkeymart_saves.py",
"tombofthemask": "tombofthemask_saves.py", "uno": "uno_saves.py",
- "fnf": "fnf_saves.py", "turborush": "turborush_saves.py",
+ "fnf": "fnf_saves.py",
"angrybirds": "angrybirds_saves.py", "polytrack": "polytrack_saves.py", "paperclips": "paperclips_saves.py",
"badtime": "badtime_saves.py", "mahjong": "mahjong_saves.py",
"rider": "rider_saves.py", "snowrider": "snowrider_saves.py", "templerun": "templerun_saves.py",
@@ -602,12 +598,6 @@ CHECKS = {
# on (at 8), the guide still read
"fnf": (lambda v: len(v) == 1552 and v[:4] == b"FNFS" and v[4] == 1 and v[9] == 1 and v[8] == 0,
lambda v: len(v) == 1552 and v[:4] == b"FNFS" and v[9] == 1 and v[8] == 1),
- # "TRU1", version 1, its size (492): the guide read (85), a race kept (114) and going (phase at 127), its clock
- # (164) running; after the reinstall, from the copy, the same race goes on
- "turborush": (lambda v: len(v) == 492 and v[:4] == b"TRU1" and v[85] == 1 and v[114] == 1 and v[127] == 1
- and struct.unpack_from("<I", v, 164)[0] >= 1000,
- lambda v: len(v) == 492 and v[:4] == b"TRU1" and v[114] == 1 and v[127] == 1
- and struct.unpack_from("<I", v, 164)[0] >= 4000),
# "ABS1", version 1, its size (3032): how to play shown (guide at 3014), the first level last played (3012), some
# seconds of play (3024); after the reinstall, from the copy, more of them
"angrybirds": (lambda v: len(v) == 3032 and v[:4] == b"ABS1" and v[3014] == 1
diff --git a/tools/release.py b/tools/release.py
index c930fa8d..4aad2758 100644
--- a/tools/release.py
+++ b/tools/release.py
@@ -51,7 +51,6 @@ ALONE = {
"tombofthemask": ("Tomb of the Mask", "dash through the tomb: the endless arcade climb and all 200 stages, with the 16 masks"),
"uno": ("UNO", "the card game against one to three bots, with the official rules and scoring to 500"),
"fnf": ("Friday Night Funkin'", "the Tutorial, Weeks 1 to 7, Weekend 1 and LE SSERAFIM, in story mode and freeplay"),
- "turborush": ("Turbo Rush", "an arcade racer by Bobydeluxe: six circuits, a Grand Prix, single races and Free Ride"),
"angrybirds": ("Angry Birds", "the 429 levels of the Chrome edition, its seven birds and the Mighty Eagle"),
"polytrack": ("PolyTrack", "Kodub's low-poly time trial racer: its 17 tracks, loops, wall rides and jumps, against your ghost"),
"paperclips": ("Universal Paperclips", "Frank Lantz's game of an AI making paperclips: business, the Earth, then the universe"),