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.

Google's Snake, Solitaire and Block Breaker; NumDance on a rooftop

Mason3639e2ba6bdc93e
diff --git a/.github/release.md b/.github/release.md
index 9c22c3ad..f7800438 100644
--- a/.github/release.md
+++ b/.github/release.md
@@ -12,11 +12,11 @@
| NumChess.nwa | Only Chess: bots, puzzles, 2 players |
| FlappyBird.nwa | Only Flappy Bird: flap through the pipes |
| PacMan.nwa | Only Pac-Man: eat dots, dodge ghosts |
-| Snake.nwa | Only Snake: eat apples, grow long |
+| Snake.nwa | Only Snake: Google's snake, with its 12 modes |
| ConnectFour.nwa | Only Connect Four: four in a row wins |
-| Solitaire.nwa | Only Solitaire: the classic card game |
+| Solitaire.nwa | Only Solitaire: the classic card game, the way Google plays it |
| NumDance.nwa | Only NumDance: hit the arrows on the beat |
| 2048.nwa | Only 2048: slide, merge, reach 2048 |
| Minesweeper.nwa | Only Minesweeper: clear the field, flag the mines |
-| Breakout.nwa | Only Breakout: break every brick |
+| BlockBreaker.nwa | Only Block Breaker: break every brick, set off the power-ups |
| NumVisuals.nwa | Only NumVisuals: backgrounds, clocks, timers |
diff --git a/README.md b/README.md
index 5a28d798..479194c8 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@
<p align="center">
<b>14 free games for your NumWorks calculator, in one app.</b><br>
- NumDash, Crossy Road, NumDrive, Tetris, Chess, Flappy Bird, Pac-Man, Snake, Connect Four, Solitaire, NumDance, 2048, Minesweeper and Breakout, plus NumVisuals: moving backgrounds with a clock, a timer and more.
+ NumDash, Crossy Road, NumDrive, Tetris, Chess, Flappy Bird, Pac-Man, Snake, Connect Four, Solitaire, NumDance, 2048, Minesweeper and Block Breaker, plus NumVisuals: moving backgrounds with a clock, a timer and more.
</p>
<p align="center">
@@ -76,7 +76,7 @@ Click a file to download it. Not sure which one? Take the first.
</tr>
<tr>
<td width="120" align="center"><img src="docs/media/thumb_snake.png" width="112" alt="Snake"></td>
- <td><a href="https://github.com/Mason363/NumPlay/releases/latest/download/Snake.nwa">Snake.nwa</a><br>Only Snake: eat apples, grow long</td>
+ <td><a href="https://github.com/Mason363/NumPlay/releases/latest/download/Snake.nwa">Snake.nwa</a><br>Only Snake: Google's snake, with its 12 modes</td>
</tr>
<tr>
<td width="120" align="center"><img src="docs/media/thumb_connectfour.png" width="112" alt="Connect Four"></td>
@@ -84,7 +84,7 @@ Click a file to download it. Not sure which one? Take the first.
</tr>
<tr>
<td width="120" align="center"><img src="docs/media/thumb_solitaire.png" width="112" alt="Solitaire"></td>
- <td><a href="https://github.com/Mason363/NumPlay/releases/latest/download/Solitaire.nwa">Solitaire.nwa</a><br>Only Solitaire: the classic card game</td>
+ <td><a href="https://github.com/Mason363/NumPlay/releases/latest/download/Solitaire.nwa">Solitaire.nwa</a><br>Only Solitaire: the classic card game, the way Google plays it</td>
</tr>
<tr>
<td width="120" align="center"><img src="docs/media/thumb_numdance.png" width="112" alt="NumDance"></td>
@@ -99,8 +99,8 @@ Click a file to download it. Not sure which one? Take the first.
<td><a href="https://github.com/Mason363/NumPlay/releases/latest/download/Minesweeper.nwa">Minesweeper.nwa</a><br>Only Minesweeper: clear the field, flag the mines</td>
</tr>
<tr>
- <td width="120" align="center"><img src="docs/media/thumb_breakout.png" width="112" alt="Breakout"></td>
- <td><a href="https://github.com/Mason363/NumPlay/releases/latest/download/Breakout.nwa">Breakout.nwa</a><br>Only Breakout: break every brick</td>
+ <td width="120" align="center"><img src="docs/media/thumb_breakout.png" width="112" alt="Block Breaker"></td>
+ <td><a href="https://github.com/Mason363/NumPlay/releases/latest/download/BlockBreaker.nwa">BlockBreaker.nwa</a><br>Only Block Breaker: break every brick, set off the power-ups</td>
</tr>
<tr>
<td width="120" align="center"><img src="docs/media/thumb_numvisuals.png" width="112" alt="NumVisuals"></td>
@@ -161,7 +161,7 @@ You need your calculator, its USB cable, and a computer with **Google Chrome** o
</tr>
<tr>
<td><img src="games/minesweeper/docs/shot.png" width="100%" alt="Minesweeper"></td>
- <td><img src="games/breakout/docs/shot.png" width="100%" alt="Breakout"></td>
+ <td><img src="games/breakout/docs/shot.png" width="100%" alt="Block Breaker"></td>
</tr>
</table>
@@ -169,7 +169,8 @@ You need your calculator, its USB cable, and a computer with **Google Chrome** o
- **[Tatone26](https://github.com/Tatone26/Numworks-games)** made Tetris and **All the Apps**, and released them into the public domain. NumPlay's Flappy Bird, Pac-Man, Snake, Connect Four and Solitaire are rewritten in C from All the Apps and keep its options, and our 2048 started from Tatone26's Python version.
- **[Gabriele Cirulli](https://github.com/gabrielecirulli/2048)** made 2048.
+- Snake, Solitaire and Block Breaker look and play like **Google's games** in Search, and NumDance takes its idea and scoring from the Artistic Swimming event of Google's **Doodle Champion Island Games**. They are drawn from scratch; nothing is taken from Google.
- **[gd3ds](https://github.com/AleFunky/gd3ds)** by AleFunky and friends, whose research into Geometry Dash made NumDash possible.
- The **Nunito** and **Rammetto One** fonts, under the SIL Open Font License ([LICENSES](LICENSES)).
-<sub>Unofficial fan games, not affiliated with NumWorks, RobTop Games (Geometry Dash), Hipster Whale (Crossy Road), the makers of Drive Mad, .GEARS (Flappy Bird), Bandai Namco (Pac-Man), Hasbro (Connect Four), Atari (Breakout) or Microsoft (Solitaire, Minesweeper). Tetris is a trademark of The Tetris Company, Pac-Man of Bandai Namco, Connect Four of Hasbro and Breakout of Atari.</sub>
+<sub>Unofficial fan games, not affiliated with NumWorks, RobTop Games (Geometry Dash), Hipster Whale (Crossy Road), the makers of Drive Mad, .GEARS (Flappy Bird), Bandai Namco (Pac-Man), Hasbro (Connect Four), Google (Snake, Solitaire, Block Breaker, Doodle Champion Island Games) or Microsoft (Minesweeper). Tetris is a trademark of The Tetris Company, Pac-Man of Bandai Namco and Connect Four of Hasbro.</sub>
diff --git a/docs/media/thumb_breakout.png b/docs/media/thumb_breakout.png
index fc9db0b4..c01671c9 100644
Binary files a/docs/media/thumb_breakout.png and b/docs/media/thumb_breakout.png differ
diff --git a/docs/media/thumb_connectfour.png b/docs/media/thumb_connectfour.png
index c66d0f5d..57c88a24 100644
Binary files a/docs/media/thumb_connectfour.png and b/docs/media/thumb_connectfour.png differ
diff --git a/docs/media/thumb_numdance.png b/docs/media/thumb_numdance.png
index 9fab8f1f..687754da 100644
Binary files a/docs/media/thumb_numdance.png and b/docs/media/thumb_numdance.png differ
diff --git a/docs/media/thumb_snake.png b/docs/media/thumb_snake.png
index 3c51963e..590b190a 100644
Binary files a/docs/media/thumb_snake.png and b/docs/media/thumb_snake.png differ
diff --git a/docs/media/thumb_solitaire.png b/docs/media/thumb_solitaire.png
index 870e6491..55bf3d15 100644
Binary files a/docs/media/thumb_solitaire.png and b/docs/media/thumb_solitaire.png differ
diff --git a/docs/play.md b/docs/play.md
index 0ffc8bbc..c6e95eae 100644
--- a/docs/play.md
+++ b/docs/play.md
@@ -127,9 +127,10 @@ The arcade maze and its four ghosts, each with its own way of hunting you. Leave
| Key | What it does |
| --- | --- |
| **Arrows** | Turn (two turns can wait in line) |
+| **Left / Right** (Settings) | Change a setting |
| **Back** | Pause menu (with Quit game) |
-Settings: speed, board size, 1, 3 or 5 apples, walls, wrapping through the edges, and portals (eat one apple of a pair to come out of the other).
+Google's Snake, with its settings: 6 fruits, 12 modes (Classic, Wall, Portal, Cheese, Borderless, Twin, Winged, Yin Yang, Statue, Light, Magnet, Peaceful), 1, 3 or 5 fruits at a time, 3 speeds, 3 board sizes, 8 snake colors and 4 themes. **Shuffle** picks them all at random.
<br clear="right">
@@ -154,7 +155,7 @@ Against a friend, or the computer at three strengths, or three players at once.
| Key | What it does |
| --- | --- |
-| **Arrows** | Move (Up / Down on a column picks how many cards) |
+| **Arrows** | Move (Up / Down on a column picks how many cards; the side columns hold the deck, Undo, New and the foundations) |
| **OK** | Pick up, put down; twice sends a card home |
| **EXE** | Draw |
| **Toolbox** | Send every card you can home |
@@ -162,7 +163,7 @@ Against a friend, or the computer at three strengths, or three players at once.
| **Shift** | Hint |
| **Back** | Put cards back, or the pause menu |
-Klondike like Windows: draw 1 or 3, Standard or Vegas scoring, and the bouncing cards when you win. Your game is kept for next time.
+Klondike the way Google Solitaire looks and plays: **Easy** draws 1 card, **Hard** draws 3. Options add Standard or Vegas scoring, a timed game and four card backs, and the cards bounce when you win. Your game is kept for next time.
<br clear="right">
@@ -172,10 +173,10 @@ Klondike like Windows: draw 1 or 3, Standard or Vegas scoring, and the bouncing
| Key | What it does |
| --- | --- |
-| **Arrows**, or **4 5 8 6**, or **1 2 3 +** | Hit the arrows as they land on the gray targets; hold along trails |
+| **Arrows**, or **4 5 8 6**, or **1 2 3 +** | Hit the arrows as they land on their rings |
| **Back** | Pause (with Quit game) |
-Arrows fall down four lanes: press the matching key as each one reaches its target. 6 songs, each in Easy, Normal, Hard and Expert, and an Endless mode. The calculator has no speaker, so the beat is in the lights and the stage. Options: scroll speed, timing offset (with a calibration), direction, no-fail.
+Arrows fall down four lanes: press the matching key as each one reaches its ring, while a robot, a fox, a penguin and a frog dance on a rooftop. **Perfect!** is 100 points, **Good!** 50, a miss takes 5 and turns the sky red. 7 songs, each in Easy, Normal, Hard and Expert, and an Endless mode. The calculator has no speaker, so the beat is in the dancers and the stars. Options: scroll speed, timing offset (with a calibration), direction, no-fail.
<br clear="right">
@@ -205,21 +206,21 @@ Merge equal tiles to reach 2048, then keep going. Each board size keeps its game
| **Shift**, **⌫** or **0** | Flag |
| **Back** | Pause menu (with Help and Quit game) |
-Beginner, Intermediate, Expert or your own size. The first square is always safe. Options: **No guessing** (only boards you can solve by logic) and ? marks.
+Beginner, Intermediate, Expert or your own size and number of mines. The first square is always safe. Options: **No guessing** (only boards you can solve by logic), ? marks, whether the first square opens an area, and whether the cursor wraps around the edges.
<br clear="right">
-## Breakout
+## Block Breaker
-<img src="../games/breakout/docs/shot.png" width="320" align="right" alt="Breakout">
+<img src="../games/breakout/docs/shot.png" width="320" align="right" alt="Block Breaker">
| Key | What it does |
| --- | --- |
| **Left / Right** | Move the paddle (hold to speed up) |
-| **OK** or **Up** | Launch, fire the laser |
+| **OK** or **Up** | Launch the ball |
| **Back** | Pause menu (with Quit game) |
-**Classic** is the 1976 arcade game. **Arcade+** has hand-made rounds, tough bricks and power-ups: wide paddle, three balls, slow ball, catch, laser and an extra life.
+Google's brick breaker: seven bricks across in blue, red, yellow and green, wall after wall, each a little faster. Bricks with a sign hold a power-up: **TNT** blows up its neighbors, **+** gives a ball, **O** splits the ball in three, **<->** widens the paddle, a **flame** makes a fireball and **beams** fire lasers. Settings: speed and screen shake.
<br clear="right">
diff --git a/games/breakout/Makefile b/games/breakout/Makefile
index 82e0eebc..26a01cbf 100644
--- a/games/breakout/Makefile
+++ b/games/breakout/Makefile
@@ -1,4 +1,4 @@
-# Breakout — the Atari classic, and an Arcade+ mode with rounds and power-ups.
+# Block Breaker — Google's brick breaker, with power-up bricks and wall after wall.
# make build output/breakout.nwa
# make check link the app like the calculator does (output/breakout.bin)
Q ?= @
diff --git a/games/breakout/README.md b/games/breakout/README.md
index ee9aeb3f..7cf20bda 100644
--- a/games/breakout/README.md
+++ b/games/breakout/README.md
@@ -1,28 +1,33 @@
-# Breakout
+# Block Breaker
-The brick breaker, for the NumWorks calculator: Atari's 1976 arcade game as it was, and an **Arcade+** mode in the spirit of Arkanoid.
+Google's Block Breaker, the brick breaker you get when you search for "block breaker", on the NumWorks calculator: the dark pixel-art field, seven bricks across in blue, red, yellow and green, bricks that hold a power-up, the big white ball and paddle, your lives as circles and the score in segments. Wall after wall, each one a little faster.
-<img src="docs/shot.png" width="320" alt="Classic Breakout: the wall of bricks, the ball and the paddle">
+<img src="docs/shot.png" width="320" alt="The first wall, with its power-up bricks">
-- **Classic** plays like the arcade: eight rows of bricks in red, orange, green and yellow (7, 5, 3 and 1 points), three balls, and a second wall once you clear the first. The ball speeds up after 4 and 12 hits and when it reaches the orange and red rows, and your paddle shrinks to half once the ball breaks through to the top wall. Like on the real cabinet, where colour came from strips of film on the screen, the ball takes the colour of the rows it flies through.
-- **Arcade+** has 12 hand-made rounds with silver bricks that take a few hits, gold ones that never break, and capsules that fall from broken bricks: **E**nlarge, **C**atch, **L**aser, **S**low, **D**isruption (three balls), **P**layer (an extra life) and **B**reak, which opens a way out to the next round. Pick any round you have reached from the title screen.
-
-Where the ball lands on the paddle decides where it goes. Bricks burst into sparks and the wall rattles when you hit it, the whole screen shakes when you lose a ball, and the ball leaves a short trail.
+- **Google's first wall,** then eleven more of the same kind, and after that they come round again, faster, with power-ups in new places.
+- **Power-up bricks,** each with its sign:
+ - **TNT** blows up the bricks around it (and sets off the TNT next to it).
+ - **+** gives you a ball (up to five).
+ - **O** splits your ball into three.
+ - **<->** makes the paddle wider for a while.
+ - **Flame:** a fireball goes straight through bricks for a few seconds.
+ - **Beams:** the paddle fires lasers for a few seconds.
+- **Where the ball meets the paddle decides where it goes,** like the original: the edges send it off at a sharp angle.
+- **Settings:** the speed (slow, normal, fast) and the screen shake. Start from any wall you've reached; your best score is kept.
## Controls
| Key | Action |
| --- | --- |
-| Left / Right, or 4 / 6 | Move the paddle (tap to nudge it, hold to speed up) |
-| OK or Up | Launch the ball, fire the laser, let go of a caught ball |
-| Back | Pause: Resume, Restart, Quit game |
-
-**Settings:** difficulty (Easy, Normal, Hard: the ball's speed and the paddle's size), screen shake, and the ball's trail. Your best score in each mode, the rounds you have reached and your settings are kept for next time (`breakout.sav`).
-
-It comes inside [NumPlay](../../README.md), or on its own as `Breakout.nwa` from the [latest release](https://github.com/Mason363/NumPlay/releases/latest).
+| Left, Right (or 4, 6) | Move the paddle (hold to go faster) |
+| OK, EXE or Up | Launch the ball |
+| Back | Pause (Resume, Restart, Quit game) |
+| Home | Quit |
## Credits
-Inspired by *Breakout* (Atari, 1976; designed by Nolan Bushnell and Steve Bristow, with a prototype built by Steve Wozniak) and its home version for the Atari 2600, and by *Arkanoid* (Taito, 1986) for the Arcade+ mode. Written from scratch in C for NumPlay; everything is drawn with code, so the whole game is about 14 KB.
+The look and the power-ups follow **Google's Block Breaker** (Google Search, 2025), itself a tribute to Atari's Breakout (1976). This is an independent fan version, drawn from shapes (no images from Google), and it isn't affiliated with or endorsed by Google.
+
+It comes inside [NumPlay](https://github.com/Mason363/NumPlay), or on its own as `BlockBreaker.nwa` from the [latest release](https://github.com/Mason363/NumPlay/releases/latest).
Build: `make` (needs `arm-none-eabi-gcc` and Node.js for nwlink).
diff --git a/games/breakout/docs/shot.png b/games/breakout/docs/shot.png
index f66bcec2..4240fe7f 100644
Binary files a/games/breakout/docs/shot.png and b/games/breakout/docs/shot.png differ
diff --git a/games/breakout/src/main.c b/games/breakout/src/main.c
index 7f3e0e1a..d5680f01 100644
--- a/games/breakout/src/main.c
+++ b/games/breakout/src/main.c
@@ -1,10 +1,14 @@
-/* Breakout: Atari's 1976 brick breaker, and an Arcade+ mode in the spirit of
- * Arkanoid (hand-made rounds, silver and gold bricks, power-up capsules).
+/* Block Breaker: Google's brick breaker (the game in Search) for the NumWorks
+ * calculator. The dark pixel-art field, seven bricks across in Google's blue,
+ * red, yellow and green, bricks that hold a power-up (TNT, an extra ball,
+ * three balls, a wider paddle, a fireball, a laser), the big white ball and
+ * paddle, the lives as circles and the score in segments; wall after wall,
+ * each a little faster.
*
* Nothing is drawn straight to the screen: whatever moves or changes marks
* the rectangle it covers, and each marked rectangle is composed in a small
- * buffer (background, walls, bricks, paddle, balls, particles, text) and
- * pushed once. A frame costs a few thousand pixels and nothing flickers. */
+ * buffer (background, bricks, paddle, balls, sparks, text) and pushed once.
+ * A frame costs a few thousand pixels and nothing flickers. */
#include <eadk.h>
#include <stdbool.h>
#include <stdint.h>
@@ -12,7 +16,7 @@
#include "../../common/epsilon_files.h"
#ifdef __ELF__ /* app name and API level, for the calculator's installer */
-const char eadk_app_name[] __attribute__((section(".rodata.eadk_app_name"))) = "Breakout";
+const char eadk_app_name[] __attribute__((section(".rodata.eadk_app_name"))) = "Block Breaker";
const uint32_t eadk_api_level __attribute__((section(".rodata.eadk_api_level"))) = 0;
#endif
@@ -21,23 +25,24 @@ const uint32_t eadk_api_level __attribute__((section(".rodata.eadk_api_level")))
typedef uint16_t color;
#define RGB(c) (color)((((c) >> 8) & 0xF800) | (((c) >> 5) & 0x07E0) | (((c) >> 3) & 0x1F))
#define WHITE 0xFFFF
-#define GRAY RGB(0x8E8E8E)
-#define BLUE RGB(0x4A6CE8)
-#define DIM RGB(0xB0B0B0)
+#define BG RGB(0x1C181F) /* Google's night */
+#define GREY RGB(0x8E8A92) /* the score */
+#define DIM RGB(0x555257)
+#define PALE RGB(0xC9C6CC)
#define KEY(k) (1ull << (k))
-/* the playfield */
-#define FX0 10 /* inside of the side walls */
-#define FX1 310
-#define TOP 28 /* the top wall, 8 pixels thick */
-#define FY0 36
-#define COLS 15
-#define ROWS 12
-#define CW 20 /* a brick's cell */
-#define CH 8
-#define BY0 52 /* the first row of bricks */
-#define PY 222 /* the top of the paddle */
-#define BS 5 /* the ball's size */
+/* the playfield: seven bricks of 30 x 16 across, 2 pixels apart */
+#define TOP 24 /* the ball bounces here, under the score */
+#define COLS 7
+#define ROWS 7
+#define BW 30
+#define BH 16
+#define GAP 2
+#define BX0 49 /* the first brick */
+#define BY0 31
+#define PY 222 /* the top of the paddle */
+#define PH 6
+#define BS 12 /* the ball's size */
#define ONE 256 /* positions and speeds are in 256ths of a pixel */
static int imin(int a, int b) { return a < b ? a : b; }
@@ -61,118 +66,78 @@ static color mix(color f, color b, int a) {
}
/* ------------------------------------------------------------------ bricks */
-enum {
- K_NONE, K_RED, K_ORANGE, K_GREEN, K_YELLOW, /* the classic wall */
- K_WHITE, K_ORANGE2, K_CYAN, K_GREEN2, K_RED2, K_BLUE, K_PINK, K_YELLOW2, K_SILVER, K_GOLD, K_RAINBOW
+/* Google's four colors: the face, the rim, and the icon of a power-up */
+static const color BRICK[4][3] = {
+ {RGB(0x5784E6), RGB(0x4B70C3), RGB(0x375491)}, /* blue */
+ {RGB(0xCA423E), RGB(0xAB3934), RGB(0x7E2622)}, /* red */
+ {RGB(0xECC444), RGB(0xC7A63A), RGB(0x8E7420)}, /* yellow */
+ {RGB(0x3B854B), RGB(0x326F3F), RGB(0x1F4A2A)}, /* green */
};
-static const color kcol[15] = {
- 0, RGB(0xC84848), RGB(0xC66C3A), RGB(0x48A048), RGB(0xA2A22A),
- RGB(0xF4F4F4), RGB(0xFF8A1C), RGB(0x30D8F0), RGB(0x3CD040), RGB(0xF03C3C), RGB(0x3868F8), RGB(0xF058D0),
- RGB(0xF8E040), RGB(0xA8B0BC), RGB(0xD8A030)};
-/* a round's "rainbow" bricks take their colour from their row */
-static const uint8_t rainbow[ROWS] = {K_WHITE, K_ORANGE2, K_RED2, K_YELLOW2, K_BLUE, K_PINK,
- K_GREEN2, K_CYAN, K_ORANGE2, K_RED2, K_YELLOW2, K_BLUE};
+enum { U_NONE, U_TNT, U_LIFE, U_MULTI, U_WIDE, U_FIRE, U_LASER, NU };
-/* Arcade+ rounds, all symmetric: a row is its 8 left cells (the 8th is the
- middle one), 2 bits each, picking one of the round's 3 kinds. Q() reads
- them as digits after a leading 1. */
-#define QD(n, p) ((n) / (p) % 10)
-#define Q(n) (uint16_t)(QD(n, 10000000) | QD(n, 1000000) << 2 | QD(n, 100000) << 4 | QD(n, 10000) << 6 | \
- QD(n, 1000) << 8 | QD(n, 100) << 10 | QD(n, 10) << 12 | QD(n, 1) << 14)
-#define PAL(a, b, c) (uint16_t)((a) | (b) << 4 | (c) << 8)
-typedef struct {
- uint16_t pal, row[ROWS];
-} round_t;
-static const round_t rounds[] = {
- {PAL(K_RAINBOW, K_SILVER, 0), /* welcome */
- {0, Q(122222222), Q(111111111), Q(111111111), Q(111111111), Q(111111111), Q(111111111)}},
- {PAL(K_RAINBOW, K_GOLD, 0), /* pyramid */
- {Q(100000001), Q(100000011), Q(100000111), Q(100001111), Q(100011111), Q(100111111), Q(101111111),
- Q(111111111), 0, Q(120002000)}},
- {PAL(K_CYAN, K_PINK, K_SILVER), /* checkers */
- {0, Q(133333333), Q(112121212), Q(121212121), Q(112121212), Q(121212121), Q(112121212), Q(121212121)}},
- {PAL(K_GREEN2, K_SILVER, 0), /* invader */
- {0, Q(100001000), Q(100000100), Q(100001111), Q(100011011), Q(100111111), Q(100101111), Q(100101000),
- Q(100000110), 0, Q(102200220)}},
- {PAL(K_RAINBOW, K_SILVER, K_GOLD), /* gates */
- {0, Q(111111111), Q(111111111), 0, Q(133333302), 0, Q(111111111), 0, Q(130333333)}},
- {PAL(K_RAINBOW, K_SILVER, K_GOLD), /* diamond */
- {Q(130000002), Q(100000021), Q(100000211), Q(100002111), Q(100021111), Q(100002111), Q(100000211),
- Q(100000021), Q(130000002)}},
- {PAL(K_BLUE, K_SILVER, K_GOLD), /* pillars */
- {Q(122222222), Q(110101010), Q(110101010), Q(110101010), Q(110101010), Q(110101010), Q(110101010),
- Q(110101010), Q(130003000)}},
- {PAL(K_CYAN, K_PINK, K_YELLOW2), /* chevrons */
- {0, Q(112312312), Q(123123123), Q(131231231), Q(112312312), Q(123123123), Q(131231231), Q(112312312),
- Q(123123123)}},
- {PAL(K_RED2, K_SILVER, K_GOLD), /* fortress */
- {Q(111111111), 0, Q(100333333), Q(100311111), Q(100312221), Q(100312221), Q(100311111), Q(100333000), 0,
- Q(111000111)}},
- {PAL(K_BLUE, K_ORANGE2, K_SILVER), /* target */
- {0, Q(111111111), Q(112222222), Q(112111111), Q(112133333), Q(112131111), Q(112133333), Q(112111111),
- Q(112222222), Q(111111111)}},
- {PAL(K_RED2, K_PINK, K_GOLD), /* heart */
- {Q(130000000), Q(100022200), Q(100211110), Q(100111111), Q(100111111), Q(100011111), Q(100001111),
- Q(100000111), Q(100000011), Q(100000001), Q(130000000)}},
- {PAL(K_RAINBOW, K_SILVER, K_GOLD), /* the last one */
- {Q(122222222), Q(111111111), Q(131111111), Q(122222222), Q(111111111), Q(111133111), Q(111111111),
- Q(122222222), 0, Q(130303030)}},
+/* The walls, 7 x 7 at most: '.' nothing, 'b' 'r' 'y' 'g' a brick of that
+ color, '#' a brick in the row's color (blue, red, yellow, green, then
+ again), and a power-up in the row's color: T TNT, + a ball, o three balls,
+ w a wider paddle, f a fireball, l a laser. The first is Google's. */
+static const char *const WALLS[][ROWS] = {
+ {"#T####+", "##+##wT", "#####o#", "###o###"},
+ {"..#w#..", ".##T##.", "###+###", "o#####o", ".#####.", "..###.."},
+ {"#.#.#.#", "T#o#l#T", "#.#.#.#", ".#.#.#.", "#.#f#.#"},
+ {"bbbbbbb", "r.....r", "r.yTy.r", "r.ywy.r", "r.....r", "ggg+ggg"},
+ {"#######", "#T###T#", "..#o#..", "#######", "..#l#..", "#w###f#"},
+ {"...#...", "..#T#..", ".#+#o#.", "#w#f#l#", ".#####.", "..###..", "...#..."},
+ {"b.r.y.g", ".T.o.T.", "g.y.r.b", ".w.f.l.", "b.r.y.g", ".......", "#+###+#"},
+ {"#######", "#.....#", "#.#T#.#", "#.#o#.#", "#.....#", "###w###"},
+ {"TTT.TTT", "#######", "##f#l##", "#######", "+#####+"},
+ {"#.#.#.#", "#.#.#.#", "#o#T#w#", "#.#.#.#", "#f#.#l#", "#######"},
+ {"yyyTyyy", "gggwggg", "bbbobbb", "rrrfrrr", "yyylyyy", "ggg+ggg", "bbbbbbb"},
+ {"T#####T", "#o#l#f#", "#######", "#w#+#w#", "#######", "T#####T"},
};
-#define NROUNDS (int)(sizeof rounds / sizeof rounds[0])
+#define NWALLS (int)(sizeof WALLS / sizeof WALLS[0])
-/* a brick: its kind (4 bits), hits left (2 bits), and a flash when hit (2 bits) */
+/* a brick: its color + 1 (3 bits), its power-up (3 bits); 0 none */
static uint8_t brick[ROWS][COLS];
+static uint8_t flash[ROWS][COLS]; /* white for a moment when it breaks next door (TNT) */
/* ------------------------------------------------------------------ the game */
-enum { CLASSIC, ARCADE };
enum { S_TITLE, S_SET, S_READY, S_PLAY, S_LOST, S_CLEAR, S_PAUSE, S_QUIT, S_OVER };
-enum { P_NONE, P_ENLARGE, P_CATCH, P_LASER };
-/* capsules: Slow, Catch, Laser, Enlarge, Disruption (three balls), Player (a
- life) and Break (a way out to the next round), in Arkanoid's colours */
-static const char cap_letter[7] = {16, 11, 14, 13, 12, 15, 10}; /* in mini[] */
-static const color cap_col[7] = {RGB(0xF08C20), RGB(0x38C848), RGB(0xE83838), RGB(0x3C6CF0), RGB(0x30C8E8),
- RGB(0x9098A8), RGB(0xE858C8)};
-static const uint8_t cap_odds[7] = {20, 18, 18, 20, 14, 4, 6};
typedef struct {
int32_t x, y, vx, vy;
- int16_t off; /* where it sits on the paddle when caught, in pixels */
- int16_t tx[3], ty[3]; /* the trail */
+ int16_t off; /* where it sits on the paddle before the serve, in pixels */
+ int16_t tx[4], ty[4]; /* the trail of a fireball */
uint8_t on, stuck;
} ball_t;
typedef struct {
int16_t x, y; /* in 16ths of a pixel */
int8_t vx, vy;
color c;
- uint8_t life, max;
+ uint8_t life, max, size;
} part_t;
typedef struct {
int16_t x, y;
- uint8_t on, type;
-} thing_t; /* a capsule or a laser shot */
+ uint8_t on;
+} shot_t;
-#define NBALL 3
-#define NPART 48
+#define NBALL 5
+#define NPART 64
#define NSHOT 6
static ball_t ball[NBALL];
static part_t part[NPART];
-static thing_t cap, shot[NSHOT];
-static int mode, state, resume_state, st_t, tk, sel, tsel, round_no, start_round, bricks_left, rows_shown;
+static shot_t shot[NSHOT];
+static int state, resume_state, st_t, tk, sel, tsel, level, bricks_left, start_lv = 1;
static int32_t score;
-static int lives, wall, hits, power, laser_cd, catch_t, warp;
-static bool demo, got_orange, got_red, shrunk, won, fresh_best, full;
+static int lives, laser_cd, wide_t, fire_t, laser_t;
+static bool demo, fresh_best, full, hinted;
static int px, pv, spd, spd0; /* the paddle's centre and speed, the balls' speed (in 256ths) */
static int pw, pw_to; /* the paddle's width, and the width it is going to */
static int demo_aim; /* where the self-playing paddle aims */
-/* the shake: time left, strength, and the offsets of the bricks (bx, by) and of
- everything else (sx, sy), which only moves in a big shake */
-static int shake_t, shake_a, bx, by, sx, sy;
-static bool shake_all;
+static int shake_t, shake_a, sx, sy; /* the shake: time left, strength, and the bricks' offset */
/* ------------------------------------------------------------------ save */
static struct {
- uint8_t magic, version, reached, diff, shake, trail, pad[2];
- uint32_t best[2];
+ uint8_t magic, version, reached, speed, shake, pad[3];
+ uint32_t best;
} sv, saved;
#define SAVE_NAME "breakout.sav"
@@ -185,15 +150,12 @@ static void save(void) {
static void load(void) {
uint32_t n = 0;
const uint8_t *d = ef_read(SAVE_NAME, &n);
- sv.magic = 'B', sv.version = 1, sv.reached = 1, sv.diff = 1, sv.shake = 1, sv.trail = 1;
- if (d && n == sizeof sv && d[0] == 'B' && d[1] == 1 && d[2] >= 1 && d[2] <= NROUNDS && d[3] < 3 && d[4] < 2 &&
- d[5] < 2) {
+ sv.magic = 'B', sv.version = 2, sv.reached = 1, sv.speed = 1, sv.shake = 1;
+ if (d && n == sizeof sv && d[0] == 'B' && d[1] == 2 && d[2] >= 1 && d[2] <= 99 && d[3] < 3 && d[4] < 2) {
for (uint32_t i = 0; i < n; i++) ((uint8_t *)&sv)[i] = d[i];
- for (int m = 0; m < 2; m++)
- if (sv.best[m] > 999999) sv.best[m] = 0;
+ if (sv.best > 99999) sv.best = 0;
saved = sv;
}
- start_round = sv.reached;
}
/* ------------------------------------------------------------------ dirty rectangles */
@@ -227,26 +189,39 @@ static void mark(int x0, int y0, int x1, int y1) {
}
dirty[ndirty++] = (rect_t){(int16_t)x0, (int16_t)y0, (int16_t)x1, (int16_t)y1};
}
-/* something in the playfield, which shakes */
-static void mark_at(int x, int y, int w, int h) { mark(x + sx, y + sy, x + sx + w, y + sy + h); }
-static void mark_cell(int r, int c) { /* however it shakes, and its shadow */
- int x = FX0 + c * CW, y = BY0 + r * CH;
- mark(x - 4, y - 4, x + CW + 7, y + CH + 7);
-}
+static void mark_at(int x, int y, int w, int h) { mark(x - 2, y - 2, x + w + 2, y + h + 2); }
+static int brick_x(int c) { return BX0 + c * (BW + GAP); }
+static int brick_y(int r) { return BY0 + r * (BH + GAP); }
+static void mark_brick(int r, int c) { mark_at(brick_x(c) + sx, brick_y(r) + sy, BW, BH); } /* bricks shake */
/* ------------------------------------------------------------------ drawing */
#define BUFN (W * 16)
static color buf[BUFN];
static int rx0, ry0, rx1, ry1, rw; /* the area buf holds */
-static int cx0, cx1; /* and the columns drawing may touch */
static void rect(int x, int y, int w, int h, color c, int a) {
- int x0 = imax(x, cx0), x1 = imin(x + w, cx1), y0 = imax(y, ry0), y1 = imin(y + h, ry1);
+ int x0 = imax(x, rx0), x1 = imin(x + w, rx1), y0 = imax(y, ry0), y1 = imin(y + h, ry1);
for (int j = y0; j < y1; j++)
for (color *p = buf + (j - ry0) * rw + x0 - rx0, *e = p + x1 - x0; p < e; p++) *p = a >= 32 ? c : mix(c, *p, a);
}
static __attribute__((noinline)) void fill(int x, int y, int w, int h, color c) { rect(x, y, w, h, c, 32); }
static bool seen(int x, int y, int w, int h) { return x < rx1 && x + w > rx0 && y < ry1 && y + h > ry0; }
+/* a pixel-art circle, d pixels across */
+static void round_(int x, int y, int d, color c) {
+ for (int j = 0; j < d; j++) {
+ int t = 2 * j + 1 - d, e = 0;
+ while ((2 * e + 1 - d) * (2 * e + 1 - d) + t * t > d * d) e++;
+ fill(x + e, y + j, d - 2 * e, 1, c);
+ }
+}
+static void ring_(int x, int y, int d, color c) {
+ for (int j = 0; j < d; j++) {
+ int t = 2 * j + 1 - d, e = 0;
+ while ((2 * e + 1 - d) * (2 * e + 1 - d) + t * t > d * d) e++;
+ if (j == 0 || j == d - 1) fill(x + e, y + j, d - 2 * e, 1, c);
+ else fill(x + e, y + j, 1, 1, c), fill(x + d - 1 - e, y + j, 1, 1, c);
+ }
+}
/* ASCII 32..90 (lowercase is drawn as capitals), columns of 7 bits, top bit first */
static const uint8_t font[59][5] = {
@@ -266,11 +241,6 @@ static const uint8_t font[59][5] = {
{0x01,0x01,0x7F,0x01,0x01},{0x3F,0x40,0x40,0x40,0x3F},{0x1F,0x20,0x40,0x20,0x1F},{0x3F,0x40,0x38,0x40,0x3F},
{0x63,0x14,0x08,0x14,0x63},{0x07,0x08,0x70,0x08,0x07},{0x61,0x51,0x49,0x45,0x43},
};
-/* 3x5 blocky figures, like the arcade's score, then the capsule letters
- B C D E L P S: five rows of three bits (an octal digit each) */
-static const uint16_t mini[17] = {075557, 026227, 071747, 071717, 055711, 074717, 074757, 071111, 075757,
- 075717, 065656, 074447, 065556, 074647, 044447, 065644, 034216};
-
static int glyph_of(char ch) {
if (ch >= 'a' && ch <= 'z') ch = (char)(ch - 32);
return ch < 32 || ch > 'Z' ? '?' - 32 : ch - 32;
@@ -281,25 +251,16 @@ static int slen(const char *s) {
return n;
}
static int tw(const char *s, int k) { return slen(s) * 6 * k - k; }
-/* text from x, with a dark shadow so it reads over anything */
static void text(const char *s, int x, int y, int k, color c) {
if (!seen(x, y, tw(s, k) + k, 8 * k)) return;
- for (int pass = 0; pass < 2; pass++)
- for (int n = 0; s[n]; n++) {
- const uint8_t *g = font[glyph_of(s[n])];
- int o = pass ? 0 : (k + 1) / 2;
- for (int i = 0; i < 5; i++)
- for (int j = 0, b = g[i]; b; j++, b >>= 1)
- if (b & 1) rect(x + n * 6 * k + i * k + o, y + j * k + o, k, k, pass ? c : 0, pass ? 32 : 20);
- }
+ for (int n = 0; s[n]; n++) {
+ const uint8_t *g = font[glyph_of(s[n])];
+ for (int i = 0; i < 5; i++)
+ for (int j = 0, b = g[i]; b; j++, b >>= 1)
+ if (b & 1) fill(x + n * 6 * k + i * k, y + j * k, k, k, c);
+ }
}
static void ctext(const char *s, int y, int k, color c) { text(s, 160 - tw(s, k) / 2, y, k, c); } /* centred */
-
-static void mini_glyph(int g, int x, int y, int kx, int ky, color c) {
- for (int j = 0; j < 5; j++)
- for (int i = 0; i < 3; i++)
- if (mini[g] >> (14 - j * 3 - i) & 1) fill(x + i * kx, y + j * ky, kx, ky, c);
-}
static char *cat(char *o, const char *t) {
while ((*o = *t++)) o++;
return o;
@@ -312,307 +273,244 @@ static char *itoa_(char *o, int32_t v) {
*o = 0;
return o;
}
-/* a number in blocky figures along the top, at least `pad` of them, from x
- (or ending at x when right-aligned) */
-static void figures(int32_t v, int pad, int x, color c, bool right) {
- char s[12];
- int n = (int)(itoa_(s, v) - s), z = imax(pad - n, 0), all = n + z;
- if (right) x -= all * 16 - 4;
- for (int i = 0; i < all; i++) mini_glyph(i < z ? 0 : s[i - z] - '0', x + i * 16, 4, 4, 4, c);
-}
-
-/* ------------------------------------------------------------------ the scene */
-static color bg_lo, bg_mid, bg_hi; /* Arcade+ backgrounds, a colour per round */
-static bool fancy(void) { return mode == ARCADE && !demo; }
-
-static void background(void) {
- if (!fancy()) {
- for (color *p = buf, *e = buf + rw * (ry1 - ry0); p < e; p++) *p = 0;
- return;
- }
- /* bevelled tiles, turned into diamonds every other round: a row of one
- tile, repeated */
- for (int y = ry0; y < ry1; y++) {
- color *p = buf + (y - ry0) * rw, t[16];
- int v = (y - FY0) & 15;
- for (int u = 0; u < 16; u++) {
- int d = iabs(u - 8) + iabs(v - 8);
- t[u] = round_no & 1 ? (d == 8 ? bg_hi : d == 7 || d < 2 ? bg_lo : bg_mid)
- : !u || !v ? bg_hi : u == 15 || v == 15 ? bg_lo : bg_mid;
- }
- for (int x = rx0; x < rx1; x++) *p++ = y >= FY0 && x >= FX0 && x < FX1 ? t[(x - FX0) & 15] : 0;
- }
-}
-static color pipe_shade(int i, int n) { /* a metal pipe, lit from the top left */
- int t = i * 2 - n / 2;
- return mix(RGB(0xECF0FA), RGB(0x2A3244), imin(iabs(t) * 32 / n + 2, 32));
+/* Google's score: figures of seven segments, 9 x 15 */
+static const uint8_t SEG[10] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};
+static void segments(int d, int x, int y, color c) {
+ int m = SEG[d];
+ if (m & 1) fill(x + 2, y, 5, 2, c);
+ if (m & 2) fill(x + 7, y + 2, 2, 4, c);
+ if (m & 4) fill(x + 7, y + 9, 2, 4, c);
+ if (m & 8) fill(x + 2, y + 13, 5, 2, c);
+ if (m & 16) fill(x, y + 9, 2, 4, c);
+ if (m & 32) fill(x, y + 2, 2, 4, c);
+ if (m & 64) fill(x + 2, y + 6, 5, 3, c);
}
-static void walls(void) {
- int ox = sx, oy = sy;
- if (!fancy()) {
- fill(ox, oy + TOP, W, 8, GRAY);
- for (int e = 0; e <= FX1; e += FX1) /* both sides, with the arcade's blue strip where the paddle plays */
- fill(ox + e, oy + TOP, FX0, H - TOP, GRAY), fill(ox + e, oy + PY - 8, FX0, 22, BLUE);
- return;
- }
- for (int i = 0; i < 8; i++) fill(ox, oy + TOP + i, W, 1, pipe_shade(i, 8));
- for (int x = 40; x < W; x += 80) rect(ox + x, oy + TOP, 3, 8, 0, 14);
- for (int e = 0; e <= FX1; e += FX1) {
- for (int i = 0; i < FX0; i++) fill(ox + e + i, oy + FY0, 1, H - FY0, pipe_shade(i, FX0));
- for (int y = FY0 + 36; y < H; y += 56) /* joints, with a lamp */
- rect(ox + e, oy + y, FX0, 3, 0, 14), fill(ox + e + 3, oy + y + 7, 4, 10, RGB(0x2A60D0));
- }
- if (warp) { /* the way out, blinking */
- fill(ox + FX1, oy + PY - 10, FX0, 22, 0);
- for (int j = 0; j < 3; j++)
- rect(ox + FX1 + 2, oy + PY - 7 + j * 6, 6, 3, RGB(0xF058D0), ((tk >> 3) + j) % 3 ? 10 : 32);
- }
+static void score_at(int32_t v, int x, int y, color c) {
+ for (int i = 4; i >= 0; i--, v /= 10) segments((int)(v % 10), x + i * 12, y, c);
}
-static void draw_brick(int r, int c, int x, int y) {
- uint8_t v = brick[r][c];
- int k = v & 15, f = v >> 6;
- color col = kcol[k];
- if (!fancy()) {
- fill(x, y + 1, CW - 2, CH - 2, col);
- return;
+/* ------------------------------------------------------------------ the scene */
+/* a power-up's icon on a brick, in the brick's darkest shade */
+static void icon(int u, int x, int y, color c) {
+ int cx = x + BW / 2, cy = y + BH / 2;
+ switch (u) {
+ case U_TNT: /* TNT in tiny letters */
+ for (int i = 0; i < 3; i++) {
+ int lx = cx - 8 + i * 6;
+ if (i != 1) fill(lx, cy - 3, 5, 1, c), fill(lx + 2, cy - 2, 1, 5, c);
+ else fill(lx, cy - 3, 1, 6, c), fill(lx + 4, cy - 3, 1, 6, c), fill(lx + 1, cy - 2, 1, 1, c), fill(lx + 2, cy - 1, 1, 1, c), fill(lx + 3, cy, 1, 1, c);
+ }
+ break;
+ case U_LIFE: fill(cx - 1, cy - 4, 3, 9, c), fill(cx - 4, cy - 1, 9, 3, c); break;
+ case U_MULTI: ring_(cx - 4, cy - 4, 9, c), ring_(cx - 3, cy - 3, 7, c); break;
+ case U_WIDE: /* <-> with dots */
+ fill(cx - 7, cy, 15, 1, c);
+ for (int i = 1; i < 4; i++) fill(cx - 7 + i, cy - i, 1, 2 * i + 1, c), fill(cx + 7 - i, cy - i, 1, 2 * i + 1, c);
+ fill(cx - 12, cy - 1, 2, 2, c), fill(cx + 11, cy - 1, 2, 2, c);
+ break;
+ case U_FIRE: /* a flame */
+ for (int j = 0; j < 9; j++) {
+ int w = j < 4 ? j / 2 : j < 7 ? 2 + (j - 4) / 2 : 3 - (j - 7);
+ fill(cx - w, cy - 4 + j, 2 * w + 1, 1, c);
+ }
+ break;
+ case U_LASER: /* two beams */
+ fill(cx - 5, cy - 4, 2, 9, c), fill(cx + 4, cy - 4, 2, 9, c), fill(cx - 1, cy - 1, 3, 3, c);
+ break;
}
- fill(x, y, CW - 1, CH - 1, col);
- rect(x, y, CW - 1, 1, WHITE, k >= K_SILVER ? 22 : 14);
- rect(x, y + 1, 1, CH - 2, WHITE, 8);
- rect(x + 1, y + CH - 2, CW - 2, 1, 0, 12);
- rect(x + CW - 2, y + 1, 1, CH - 2, 0, 10);
- if (k >= K_SILVER) rect(x + 3, y + 2, 3, 2, WHITE, 24); /* a shine */
- if (f) rect(x + (3 - f) * 6, y, 6, CH - 1, WHITE, 24); /* a glint runs across when hit */
+}
+static void draw_brick(int r, int c) {
+ int v = brick[r][c], x = brick_x(c) + sx, y = brick_y(r) + sy;
+ if (!v || !seen(x, y, BW, BH)) return;
+ const color *k = BRICK[(v & 7) - 1];
+ color face = flash[r][c] ? mix(WHITE, k[0], flash[r][c] * 4) : k[0];
+ fill(x + 1, y, BW - 2, BH, k[1]); /* the rim, corners cut */
+ fill(x, y + 1, BW, BH - 2, k[1]);
+ fill(x + 2, y + 2, BW - 4, BH - 4, face);
+ if (v >> 3) icon(v >> 3, x, y, k[2]);
}
static void bricks(void) {
- int ox = bx + FX0, oy = by + BY0;
- int r0 = imax((ry0 - oy - CH - 3) / CH, 0), r1 = imin((ry1 - oy) / CH + 1, rows_shown);
- int c0 = imax((rx0 - ox - CW - 3) / CW, 0), c1 = imin((rx1 - ox) / CW + 1, COLS);
- if (ry1 <= oy - 4) return;
- cx0 = imax(rx0, FX0), cx1 = imin(rx1, FX1); /* shaken bricks slide under the walls */
- if (fancy()) /* shadows first, so the bricks cover the ones that fall on bricks */
- for (int r = r0; r < r1; r++)
- for (int c = c0; c < c1; c++)
- if (brick[r][c]) rect(ox + c * CW + 3, oy + r * CH + 3, CW - 1, CH - 1, 0, 15);
- for (int r = r0; r < r1; r++)
- for (int c = c0; c < c1; c++)
- if (brick[r][c]) draw_brick(r, c, ox + c * CW, oy + r * CH);
- cx0 = rx0, cx1 = rx1;
+ for (int r = 0; r < ROWS; r++)
+ if (seen(0, brick_y(r) + sy - 2, W, BH + 4))
+ for (int c = 0; c < COLS; c++) draw_brick(r, c);
}
-static bool paddle_shown(void) { return state != S_LOST && (state != S_OVER || won); }
+static bool paddle_shown(void) { return state != S_LOST && state != S_OVER; }
static void paddle(void) {
if (!paddle_shown()) return;
- int x = ((px + ONE / 2) >> 8) - pw / 2 + sx, y = PY + sy;
- if (!seen(x, y - 3, pw, 10)) return;
- if (!fancy()) {
- fill(x, y, pw, 4, BLUE);
- return;
- }
- /* the Vaus: a silver capsule with red ends, lit from above */
- static const uint8_t inset[7] = {2, 1, 0, 0, 0, 1, 2}, lit[7] = {20, 31, 25, 18, 12, 7, 3};
- for (int j = 0; j < 7; j++) {
- int i = inset[j];
- color red = mix(RGB(0xFF6060), RGB(0x400808), lit[j]);
- fill(x + i, y + j, pw - 2 * i, 1, mix(WHITE, RGB(0x303848), lit[j]));
- fill(x + i, y + j, 7 - i, 1, red);
- fill(x + pw - 7, y + j, 7 - i, 1, red);
+ int x = ((px + ONE / 2) >> 8) - pw / 2, y = PY;
+ if (!seen(x - 4, y - 4, pw + 8, PH + 4)) return;
+ fill(x + 1, y, pw - 2, PH, WHITE);
+ fill(x, y + 1, pw, PH - 2, WHITE);
+ if (laser_t) { /* two cannons, red */
+ fill(x + 3, y - 4, 4, 4, RGB(0xE8453C));
+ fill(x + pw - 7, y - 4, 4, 4, RGB(0xE8453C));
}
- rect(x + 7, y + 1, 1, 5, 0, 12);
- rect(x + pw - 8, y + 1, 1, 5, 0, 12);
- rect(x + pw / 2 - 3, y + 2, 6, 3, RGB(0x40A0F8), power == P_CATCH ? 32 : 12);
- if (power == P_LASER) { /* two cannons */
- fill(x + 2, y - 3, 3, 3, RGB(0x505868));
- fill(x + pw - 5, y - 3, 3, 3, RGB(0x505868));
- }
-}
-
-/* in the arcade, colour came from strips of film on the screen: the ball
- takes the colour of the rows it flies through */
-static color ball_col(int y) {
- if (fancy()) return RGB(0xE8F0FF);
- if (y + 2 >= PY - 8) return BLUE;
- int r = (y + 2 - BY0) / CH;
- if (!demo && y + 2 >= BY0 + CH && r <= 8) return kcol[(r + 1) / 2];
- return WHITE;
}
+static color ball_color(void) { return fire_t ? RGB(0xFF8A3D) : WHITE; }
static void balls(void) {
for (int i = 0; i < NBALL; i++) {
ball_t *b = &ball[i];
if (!b->on) continue;
- if (sv.trail && !b->stuck)
- for (int t = 2; t >= 0; t--) {
- int s = BS - 1 - t / 2;
- rect(b->tx[t] + sx + (BS - s) / 2, b->ty[t] + sy + (BS - s) / 2, s, s, ball_col(b->ty[t]), 16 - t * 5);
+ if (fire_t && !b->stuck)
+ for (int t = 3; t >= 0; t--) { /* the fireball's trail */
+ int s = BS - 2 - t * 2;
+ round_(b->tx[t] + (BS - s) / 2, b->ty[t] + (BS - s) / 2, s, mix(RGB(0xFFD54F), BG, 20 - t * 4));
}
- int x = (b->x >> 8) + sx, y = (b->y >> 8) + sy;
- color c = ball_col(b->y >> 8);
- if (!fancy()) {
- fill(x, y, BS, BS, c);
- } else {
- fill(x + 1, y, BS - 2, BS, c);
- fill(x, y + 1, BS, BS - 2, c);
- fill(x + BS - 2, y + BS - 2, 1, 1, RGB(0x8090B0));
- fill(x + 1, y + 1, 1, 1, WHITE);
- }
+ round_(b->x >> 8, b->y >> 8, BS, ball_color());
}
}
static void things(void) {
- if (cap.on) { /* a capsule: a little lit pill with its letter, and a shine going round */
- static const uint8_t inset[8] = {2, 1, 0, 0, 0, 0, 1, 2}, lit[8] = {14, 8, 0, 0, 4, 9, 14, 18};
- int x = cap.x + sx, y = cap.y + sy, sh = (st_t >> 1) & 31;
- color c = cap_col[cap.type];
- for (int j = 0; j < 8; j++)
- fill(x + inset[j], y + j, 16 - 2 * inset[j], 1, j < 2 ? mix(WHITE, c, lit[j]) : mix(0, c, lit[j]));
- if (sh < 14) rect(x + 1 + sh, y + 1, 2, 6, WHITE, 12);
- mini_glyph(cap_letter[cap.type], x + 7, y + 2, 1, 1, mix(0, c, 20));
- mini_glyph(cap_letter[cap.type], x + 6, y + 1, 1, 1, WHITE);
- }
for (int i = 0; i < NSHOT; i++)
- if (shot[i].on) {
- fill(shot[i].x + sx, shot[i].y + sy, 2, 7, RGB(0xFF5030));
- fill(shot[i].x + sx, shot[i].y + sy, 2, 3, RGB(0xFFF0A0));
- }
+ if (shot[i].on) fill(shot[i].x, shot[i].y, 2, 8, RGB(0xFF6E5A)), fill(shot[i].x, shot[i].y, 2, 3, WHITE);
for (int i = 0; i < NPART; i++) {
part_t *p = &part[i];
- if (p->life) rect((p->x >> 4) + sx, (p->y >> 4) + sy, 2, 2, p->c, 8 + 24 * p->life / p->max);
+ if (p->life) rect(p->x >> 4, p->y >> 4, p->size, p->size, p->c, 8 + 24 * p->life / p->max);
}
}
+/* the lives as circles, the score in segments, the wall's number */
static void hud(void) {
if (ry0 >= TOP) return;
- int32_t best = (int32_t)sv.best[mode] > score ? (int32_t)sv.best[mode] : score;
- if (mode == CLASSIC) { /* score, ball, best: like the arcade's two scores and ball; the
- title shows the last game's score, as arcades do */
- figures(score, 3, 18, GRAY, false);
- if (!demo) figures(4 - imax(lives, 1), 1, 154, GRAY, false);
- figures(best, 3, 302, mix(GRAY, 0, 18), true);
- return;
+ int n = demo ? 3 : imax(lives, 0);
+ for (int i = 0; i < imax(3, n); i++) {
+ if (i < n) round_(8 + i * 15, 6, 11, PALE);
+ else ring_(8 + i * 15, 6, 11, DIM);
}
- char s[12] = "HI ";
- figures(score, 1, 18, WHITE, false);
- int x = 160 - (round_no >= 9 ? 31 : 23);
- text("ROUND", x, 17, 1, RGB(0xF05050));
- figures(round_no + 1, 1, x + 34, RGB(0xF05050), false);
- itoa_(s + 3, best);
- text(s, 302 - tw(s, 1), 4, 1, RGB(0xA0A0A0));
- for (int i = 0; i < imin(lives - 1, 6); i++) { /* spare lives, as little paddles */
- int x = 294 - i * 13;
- fill(x, 16, 10, 4, RGB(0xB8C0CC));
- fill(x, 16, 2, 4, RGB(0xE03030));
- fill(x + 8, 16, 2, 4, RGB(0xE03030));
+ score_at(demo ? (int32_t)sv.best : score, 130, 5, GREY);
+ char s[8];
+ itoa_(cat(s, "LV "), demo ? sv.reached : level + 1);
+ text(s, 312 - tw(s, 1), 9, 1, DIM);
+}
+
+/* the floor: a darker band at the bottom */
+static void background(void) {
+ for (int y = ry0; y < ry1; y++) {
+ color c = y < 228 ? BG : y < 232 ? RGB(0x18151B) : y < 235 ? RGB(0x151217) : y < 238 ? RGB(0x121014) : RGB(0x100E12);
+ for (color *p = buf + (y - ry0) * rw, *e = p + rw; p < e; p++) *p = c;
}
}
/* ------------------------------------------------------------------ overlays */
-static const char *const diff_names[3] = {"EASY", "NORMAL", "HARD"};
+static const char *const speed_names[3] = {"SLOW", "NORMAL", "FAST"};
/* where each screen's text is, so a change redraws only that */
static void ui_area(int s) {
- if (s <= S_SET) mark(20, 100, 300, 214);
- else if (s < S_PAUSE) mark(40, 146, 280, 196); /* the banner */
- else full = true; /* a menu over the dimmed game */
+ if (s <= S_SET) mark(0, 30, W, 232);
+ else if (s < S_PAUSE) mark(40, 120, 280, 200);
+ else full = true; /* a menu over the dimmed game */
}
+/* a pixel-art panel: dark, with a white rim and corners cut */
static void panel(int x, int y, int w, int h) {
- fill(x, y, w, h, GRAY);
- fill(x + 3, y + 3, w - 6, h - 6, 0);
+ fill(x + 2, y, w - 4, h, WHITE);
+ fill(x, y + 2, w, h - 4, WHITE);
+ fill(x + 1, y + 1, w - 2, h - 2, WHITE);
+ fill(x + 2, y + 2, w - 4, h - 4, RGB(0x26222B));
}
static void item(const char *s, int cy, bool on) {
- if (on) {
- fill(100, cy - 4, 120, 22, BLUE);
+ if (on) fill(92, cy - 5, 136, 24, WHITE), fill(90, cy - 3, 140, 20, WHITE);
+ ctext(s, cy, 2, on ? BG : PALE);
+}
+/* the keys, like Google's hint: left and right, and OK above */
+static void keys_hint(int y) {
+ panel(128, y, 64, 64);
+ for (int i = 0; i < 3; i++) {
+ int kx = 136 + i * 16, ky = y + (i == 1 ? 12 : 30);
+ if (i == 1) fill(kx, ky - 1, 16, 16, WHITE), fill(kx + 2, ky + 1, 12, 12, RGB(0x26222B));
+ else fill(kx, ky + 17, 16, 14, WHITE);
+ if (i != 1) /* an arrow */
+ for (int t = 0; t < 4; t++) fill(kx + (i ? 10 - t : 5 + t), ky + 24 - t, 1, 2 * t + 1, RGB(0x26222B));
}
- ctext(s, cy, 2, on ? WHITE : DIM);
+ fill(152, y + 47, 16, 14, WHITE), fill(154, y + 49, 12, 10, RGB(0x26222B));
}
-static void logo(void) {
- /* BREAKOUT in bold letters built of bricks, in the four colours of the wall */
- static const char name[] = "BREAKOUT";
- int x0 = 23, y0 = 46;
- if (!seen(x0, y0, 275, 42)) return;
- for (int n = 0; n < 8; n++) {
- const uint8_t *g = font[name[n] - 32];
- for (int i = 0; i < 6; i++) {
- int b = (i < 5 ? g[i] : 0) | (i ? g[i - 1] : 0);
+static void logo(int y) {
+ /* BLOCK BREAKER in bricks of Google's four colors */
+ static const char name[] = "BLOCK BREAKER";
+ int x0 = 160 - 13 * 18 / 2 + 2;
+ if (!seen(x0 - 2, y - 2, 13 * 18 + 4, 28)) return;
+ for (int n = 0; n < 13; n++) {
+ const uint8_t *g = font[glyph_of(name[n])];
+ for (int i = 0; i < 5; i++)
for (int j = 0; j < 7; j++)
- if (b >> j & 1) fill(x0 + (n * 7 + i) * 5, y0 + j * 6, 5, 5, kcol[1 + j * 4 / 7]);
- }
+ if (g[i] >> j & 1) fill(x0 + n * 18 + i * 3, y + j * 3, 3, 3, BRICK[(n + (n > 5)) & 3][0]);
}
- for (int j = 0; j < 7; j++) /* the mortar between bricks */
- for (int x = x0 + (j & 1) * 5 + 9; x < x0 + 275; x += 10) fill(x, y0 + j * 6, 1, 5, 0);
}
static void overlay(void) {
char s[24];
if (state == S_TITLE || state == S_SET) {
- logo();
+ logo(112);
if (state == S_TITLE) {
- static const char *const items[3] = {"CLASSIC", "ARCADE+", "SETTINGS"};
- for (int i = 0; i < 3; i++) item(items[i], 108 + i * 28, tsel == i);
- char *o = s;
- if (tsel == 1) /* the round to start from, among those reached */
- o = cat(itoa_(cat(s, sv.reached > 1 ? "< ROUND " : "ROUND "), start_round), sv.reached > 1 ? " > " : " ");
- itoa_(cat(o, "BEST "), (int32_t)sv.best[tsel & 1]);
- if (tsel < 2) ctext(s, 198, 1, DIM);
+ static const char *const items[2] = {"PLAY", "SETTINGS"};
+ for (int i = 0; i < 2; i++) item(items[i], 150 + i * 28, tsel == i);
+ if (tsel == 0 && sv.reached > 1) {
+ cat(itoa_(cat(s, "< LEVEL "), (int32_t)start_lv), " >");
+ ctext(s, 202, 1, PALE);
+ }
+ itoa_(cat(s, "BEST "), (int32_t)sv.best);
+ ctext(s, 214, 1, DIM);
} else {
- static const char *const names[3] = {"DIFFICULTY", "SCREEN SHAKE", "BALL TRAIL"};
- for (int i = 0; i < 3; i++) {
- color c = sel == i ? WHITE : DIM;
- if (sel == i) fill(24, 104 + i * 28, 272, 22, BLUE);
- text(names[i], 32, 108 + i * 28, 2, c);
- const char *v = i == 0 ? diff_names[sv.diff] : (i == 1 ? sv.shake : sv.trail) ? "ON" : "OFF";
- text(v, 288 - tw(v, 2), 108 + i * 28, 2, c);
+ static const char *const names[2] = {"SPEED", "SHAKE"};
+ for (int i = 0; i < 2; i++) {
+ bool on = sel == i;
+ if (on) fill(40, 145 + i * 28, 240, 24, WHITE);
+ text(names[i], 50, 150 + i * 28, 2, on ? BG : PALE);
+ const char *v = i == 0 ? speed_names[sv.speed] : sv.shake ? "ON" : "OFF";
+ text(v, 270 - tw(v, 2), 150 + i * 28, 2, on ? BG : PALE);
}
- ctext("LEFT/RIGHT: CHANGE BACK: DONE", 198, 1, DIM);
+ ctext("LEFT/RIGHT: CHANGE BACK: DONE", 210, 1, DIM);
}
return;
}
- if (state == S_CLEAR) ctext(mode == CLASSIC ? "WALL CLEARED" : warp ? "WARP!" : "ROUND CLEAR", 152, 2, WHITE);
+ if (state == S_CLEAR) {
+ itoa_(cat(s, "LEVEL "), level + 1);
+ cat(s + slen(s), " CLEAR");
+ ctext(s, 146, 2, WHITE);
+ }
if (state == S_READY && !demo) {
- itoa_(cat(s, mode == CLASSIC ? (wall == 2 ? "WALL 2 BALL " : "BALL ") : "ROUND "),
- mode == CLASSIC ? 4 - lives : round_no + 1);
- ctext(s, 152, 2, WHITE);
- if (st_t > 20) ctext("OK: LAUNCH", 176, 1, DIM);
+ if (!hinted) keys_hint(104);
+ else if (st_t > 20) ctext("OK: LAUNCH", 160, 1, PALE);
}
if (state == S_PAUSE) {
static const char *const items[3] = {"RESUME", "RESTART", "QUIT GAME"};
- panel(84, 62, 152, 116);
- ctext("PAUSED", 74, 2, kcol[K_YELLOW]);
- for (int i = 0; i < 3; i++) item(items[i], 104 + i * 24, sel == i);
+ panel(80, 58, 160, 124);
+ ctext("PAUSED", 70, 2, WHITE);
+ for (int i = 0; i < 3; i++) item(items[i], 104 + i * 26, sel == i);
} else if (state == S_QUIT) {
- panel(84, 74, 152, 92);
+ panel(80, 74, 160, 92);
ctext("QUIT GAME?", 88, 2, WHITE);
for (int i = 0; i < 2; i++) {
- int x = 102 + i * 62;
- if (sel == i) fill(x, 124, 54, 24, i ? RGB(0xC84848) : BLUE);
- text(i ? "YES" : "NO", x + 16 - i * 6, 129, 2, sel == i ? WHITE : DIM);
+ int x = 98 + i * 66;
+ if (sel == i) fill(x, 123, 58, 24, WHITE);
+ text(i ? "YES" : "NO", x + 17 - i * 6, 128, 2, sel == i ? BG : PALE);
}
} else if (state == S_OVER) {
- panel(50, 50, 220, 140);
- ctext(won ? (mode == CLASSIC ? "YOU WIN!" : "ALL CLEAR!") : "GAME OVER", 64, 3, won ? RGB(0xA2E22A) : RGB(0xE05050));
+ panel(60, 50, 200, 140);
+ ctext("GAME OVER", 64, 3, WHITE);
itoa_(cat(s, "SCORE "), score);
- ctext(s, 104, 2, WHITE);
- itoa_(cat(s, "BEST "), (int32_t)sv.best[mode]);
- if (fresh_best) cat(s, st_t & 16 ? "NEW BEST!" : "");
- ctext(s, 128, 2, fresh_best ? kcol[K_YELLOW2] : DIM);
- ctext("OK: PLAY AGAIN BACK: MENU", 166, 1, DIM);
+ ctext(s, 100, 2, PALE);
+ itoa_(cat(s, "BEST "), (int32_t)sv.best);
+ ctext(s, 124, 2, fresh_best && (st_t & 16) ? BRICK[2][0] : DIM);
+ if (fresh_best) ctext("NEW BEST!", 146, 1, BRICK[2][0]);
+ ctext("OK: PLAY AGAIN BACK: MENU", 170, 1, DIM);
}
}
/* one area of the screen, in layers */
static void render(void) {
background();
- walls();
bricks();
things();
paddle();
balls();
hud();
- if (state >= S_PAUSE) /* dimmed under a menu */
- for (color *p = buf, *e = buf + rw * (ry1 - ry0); p < e; p++) *p = (color)((*p >> 1 & 0x7BEF) + (*p >> 2 & 0x39E7));
+ bool dimmed = state >= S_PAUSE || state <= S_SET || (state == S_READY && !hinted && !demo);
+ if (dimmed) /* dimmed under a menu */
+ for (color *p = buf, *e = buf + rw * (ry1 - ry0); p < e; p++) *p = mix(0, *p, 16);
overlay();
}
@@ -622,7 +520,7 @@ static void flush(void) {
rect_t r = dirty[i];
int w = r.x1 - r.x0, band = BUFN / w;
for (int y = r.y0; y < r.y1; y += band) {
- cx0 = rx0 = r.x0, cx1 = rx1 = r.x1, ry0 = y, ry1 = imin(y + band, r.y1), rw = w;
+ rx0 = r.x0, rx1 = r.x1, ry0 = y, ry1 = imin(y + band, r.y1), rw = w;
render();
eadk_display_push_rect((eadk_rect_t){(uint16_t)rx0, (uint16_t)ry0, (uint16_t)w, (uint16_t)(ry1 - ry0)}, buf);
}
@@ -637,43 +535,42 @@ static void mark_moving(void) {
ball_t *b = &ball[i];
if (!b->on) continue;
int x0 = b->x >> 8, y0 = b->y >> 8, x1 = x0 + BS, y1 = y0 + BS;
- if (sv.trail)
- for (int t = 0; t < 3; t++)
+ if (fire_t)
+ for (int t = 0; t < 4; t++)
x0 = imin(x0, b->tx[t]), y0 = imin(y0, b->ty[t]), x1 = imax(x1, b->tx[t] + BS), y1 = imax(y1, b->ty[t] + BS);
mark_at(x0, y0, x1 - x0, y1 - y0);
}
- if (cap.on) mark_at(cap.x, cap.y, 16, 8);
for (int i = 0; i < NSHOT; i++)
- if (shot[i].on) mark_at(shot[i].x, shot[i].y, 2, 7);
+ if (shot[i].on) mark_at(shot[i].x, shot[i].y, 2, 8);
for (int i = 0; i < NPART; i++)
- if (part[i].life) mark_at(part[i].x >> 4, part[i].y >> 4, 2, 2);
+ if (part[i].life) mark_at(part[i].x >> 4, part[i].y >> 4, part[i].size, part[i].size);
/* the paddle, only when it changed: where it was drawn, and where it is */
- int x = (px + ONE / 2) >> 8, key = x | pw << 9 | power << 16 | paddle_shown() << 18 | (sx + 8) << 20 | (sy + 8) << 25;
+ int x = (px + ONE / 2) >> 8, key = x | pw << 9 | !!laser_t << 17 | paddle_shown() << 18;
if (key != paddle_key) {
x -= pw / 2;
- mark(paddle_mx, PY - 3 - 4, paddle_mx + (paddle_key >> 9 & 127) + 8, PY + 7 + 4);
- mark_at(x, PY - 3, pw, 10);
- paddle_key = key, paddle_mx = x + sx - 4;
+ mark(paddle_mx, PY - 6, paddle_mx + (paddle_key >> 9 & 255) + 12, PY + PH + 6);
+ mark_at(x, PY - 4, pw, PH + 4);
+ paddle_key = key, paddle_mx = x - 6;
}
}
/* ------------------------------------------------------------------ effects */
-/* n sparks flying out of an area; f: how hard, in 16ths of a pixel a tick */
+/* n bits flying out of an area; f: how hard, in 16ths of a pixel a tick */
static void burst(int x, int y, int w, int h, color c, int n, int f) {
static int next;
while (n--) {
part_t *p = &part[next];
next = (next + 1) % NPART;
- if (p->life) mark_at(p->x >> 4, p->y >> 4, 2, 2);
+ if (p->life) mark_at(p->x >> 4, p->y >> 4, p->size, p->size);
p->x = (int16_t)((x + rndi(w)) * 16), p->y = (int16_t)((y + rndi(h)) * 16);
p->vx = (int8_t)(rndi(2 * f + 1) - f), p->vy = (int8_t)(rndi(2 * f + 1) - f * 13 / 10);
- p->c = c;
+ p->c = c, p->size = (uint8_t)(2 + rndi(3));
p->max = p->life = (uint8_t)(16 + rndi(20));
}
}
static void shake(int a, int t) {
if (!sv.shake) return;
- shake_a = imax(shake_a, a), shake_t = imax(shake_t, t), shake_all |= a > 2;
+ shake_a = imax(shake_a, a), shake_t = imax(shake_t, t);
}
/* ------------------------------------------------------------------ rules */
@@ -686,39 +583,29 @@ static void set_speed(int s) {
if (l) b->vx = b->vx * s / l, b->vy = b->vy * s / l;
}
}
-static int diff_k(void) { return sv.diff == 0 ? 82 : sv.diff == 2 ? 118 : 100; } /* percent */
-static void classic_speed(void) { /* faster after 4 and 12 hits, and at the orange and red rows */
- set_speed(spd0 * (100 + 17 * ((hits >= 4) + (hits >= 12) + got_orange + got_red)) / 100);
-}
-
-static int base_width(void) { return (mode == ARCADE ? 40 : 38) + (sv.diff == 0 ? 8 : sv.diff == 2 ? -6 : 0); }
static void load_wall(void) {
bricks_left = 0;
+ const char *const *w = WALLS[level % NWALLS];
for (int r = 0; r < ROWS; r++)
for (int c = 0; c < COLS; c++) {
- int k = 0;
- if (demo) {
- } else if (mode == CLASSIC) {
- if (r >= 1 && r <= 8) k = (r + 1) / 2;
- } else {
- const round_t *rd = &rounds[round_no];
- int v = rd->row[r] >> 2 * (c < 8 ? c : 14 - c) & 3;
- if (v) k = rd->pal >> 4 * (v - 1) & 15;
- if (k == K_RAINBOW) k = rainbow[r];
- }
- int hp = k == K_SILVER ? 2 + (round_no >= 6) : 1;
- brick[r][c] = (uint8_t)(k ? k | hp << 4 : 0);
- bricks_left += k && k != K_GOLD;
+ char ch = w[r] ? w[r][c] : '.';
+ int k = r % 4 + 1, u = U_NONE;
+ static const char U[] = " T+owfl";
+ if (ch == '.') k = 0;
+ else if (ch == 'b') k = 1;
+ else if (ch == 'r') k = 2;
+ else if (ch == 'y') k = 3;
+ else if (ch == 'g') k = 4;
+ for (int i = 1; i < NU; i++)
+ if (ch == U[i]) u = i;
+ if (level >= NWALLS && u == U_NONE && k && !rndi(12)) u = 1 + rndi(NU - 1); /* again: new surprises */
+ brick[r][c] = (uint8_t)(k ? k | u << 3 : 0), flash[r][c] = 0;
+ bricks_left += !!k;
}
- rows_shown = 0;
- if (mode == ARCADE) { /* this round's background colour */
- static const uint32_t hue[4] = {0x14286C, 0x0C4A3A, 0x4A1848, 0x3A2A10};
- color b = RGB(hue[round_no & 3]);
- bg_mid = mix(b, 0, 16), bg_hi = mix(b, 0, 22), bg_lo = mix(b, 0, 8);
- }
}
+static int base_width(void) { return 60; }
static void ball_tick(ball_t *b);
static void serve(void) { /* a new ball, on the paddle */
for (int i = 0; i < NBALL; i++) ball[i].on = 0;
@@ -727,18 +614,11 @@ static void serve(void) { /* a new ball, on the paddle */
b->off = (int16_t)(demo ? 0 : rndi(9) - 4);
b->vx = 154, b->vy = -ONE;
pw = pw_to = base_width(), demo_aim = 0;
- power = P_NONE;
- if (warp) warp = 0, mark_at(FX1, PY - 10, FX0, 22); /* the gate closes */
- cap.on = 0;
+ wide_t = fire_t = laser_t = 0;
for (int i = 0; i < NSHOT; i++) shot[i].on = 0;
- if (mode == CLASSIC) {
- hits = 0, got_orange = got_red = shrunk = false;
- spd0 = 589 * diff_k() / 100; /* 2.3 pixels a tick */
- classic_speed();
- } else {
- spd0 = (538 + 20 * imin(round_no, 10)) * diff_k() / 100;
- set_speed(spd0);
- }
+ static const int SPEED[3] = {500, 610, 740}; /* 2 to 3 pixels a tick, a little faster each wall */
+ spd0 = SPEED[sv.speed] * (100 + imin(level, 16) * 5) / 100;
+ set_speed(spd0);
ball_tick(b);
}
@@ -748,25 +628,25 @@ static void set_state(int s) {
ui_area(state);
}
-static void start_round_(void) {
+static void start_wall(void) {
load_wall();
serve();
set_state(S_READY);
- if (mode == ARCADE && round_no + 1 > sv.reached) sv.reached = (uint8_t)(round_no + 1), save();
+ full = true;
+ if (!demo && level + 1 > sv.reached && level + 1 <= 99) sv.reached = (uint8_t)(level + 1), save();
}
-static void new_game(int m) {
- mode = m, demo = false;
- score = 0, lives = 3, wall = 1, fresh_best = false, won = false;
- round_no = m == ARCADE ? start_round - 1 : 0;
+static void new_game(void) {
+ demo = false;
+ score = 0, lives = 3, fresh_best = false, hinted = false;
+ level = start_lv - 1;
for (int i = 0; i < NPART; i++) part[i].life = 0;
- px = (FX0 + FX1) / 2 * ONE;
- start_round_();
- full = true;
+ px = W / 2 * ONE;
+ start_wall();
}
static void title(void) {
- mode = CLASSIC, demo = true;
+ demo = true, level = 0;
load_wall();
serve();
set_state(S_TITLE);
@@ -775,64 +655,56 @@ static void title(void) {
/* keeps the best score, for a finished or abandoned game */
static void keep_best(void) {
- if (!demo && (uint32_t)score > sv.best[mode]) sv.best[mode] = (uint32_t)score, fresh_best = true;
+ if (!demo && (uint32_t)score > sv.best) sv.best = (uint32_t)score, fresh_best = true;
save();
}
static void add_score(int n) {
score += n;
- if (score > 999999) score = 999999;
+ if (score > 99999) score = 99999;
mark(0, 0, W, TOP);
}
-#ifndef CAP_CHANCE
-#define CAP_CHANCE 22 /* percent of bricks that drop a capsule */
-#endif
-static void drop_capsule(int x, int y) {
- if (cap.on || rndi(100) >= CAP_CHANCE) return;
- int r = rndi(100), t = 0;
- while (r >= cap_odds[t]) r -= cap_odds[t++];
- if (t == 4 && (ball[1].on || ball[2].on)) t = 3;
- cap = (thing_t){(int16_t)(x + 2), (int16_t)y, 1, (uint8_t)t};
-}
-
-static void hit_brick(int r, int c) {
- uint8_t v = brick[r][c];
- int k = v & 15, hp = v >> 4 & 3;
- mark_cell(r, c);
- if (k == K_GOLD || hp > 1) { /* it holds, and shines */
- brick[r][c] = (uint8_t)(k | (k == K_GOLD ? hp : hp - 1) << 4 | 3 << 6);
- shake(1, 3);
- return;
- }
- brick[r][c] = 0;
+static void power_up(int u, int x, int y);
+/* a brick breaks: bits fly, its power-up goes off */
+static void break_brick(int r, int c) {
+ int v = brick[r][c];
+ if (!v) return;
+ brick[r][c] = 0, flash[r][c] = 0;
bricks_left--;
- int x = FX0 + c * CW, y = BY0 + r * CH;
- burst(x, y, CW - 2, CH - 2, kcol[k], 9, 22);
- shake(1 + (k >= K_SILVER), 5);
+ mark_brick(r, c);
+ int x = brick_x(c), y = brick_y(r);
+ const color *k = BRICK[(v & 7) - 1];
+ burst(x, y, BW, BH, k[0], 7, 20);
+ burst(x, y, BW, BH, k[1], 4, 14);
+ shake(1, 5);
if (demo) return;
- if (mode == CLASSIC) {
- add_score(9 - 2 * k);
- hits++;
- if (k == K_ORANGE) got_orange = true;
- if (k == K_RED) got_red = true;
- classic_speed();
- } else {
- add_score(k == K_SILVER ? 50 * (round_no + 1) : 50 + 10 * (k - K_WHITE));
- if (k != K_SILVER) drop_capsule(x, y);
+ add_score(v >> 3 ? 50 : 10);
+ if (v >> 3) power_up(v >> 3, x, y), (void)r;
+ if (v >> 3 == U_TNT) { /* it goes off: the bricks around break too */
+ shake(4, 12);
+ burst(x - 8, y - 6, BW + 16, BH + 12, RGB(0xFFB040), 14, 30);
+ for (int dr = -1; dr <= 1; dr++)
+ for (int dc = -1; dc <= 1; dc++) {
+ int rr = r + dr, cc = c + dc;
+ if ((dr || dc) && rr >= 0 && rr < ROWS && cc >= 0 && cc < COLS && brick[rr][cc]) break_brick(rr, cc);
+ }
}
}
-/* the brick under the ball, if any: hit it */
-static bool hit_bricks(const ball_t *b) {
- int x0 = (b->x >> 8) - FX0, y0 = (b->y >> 8) - BY0;
- if (y0 + BS <= 0 || y0 >= ROWS * CH) return false;
- for (int r = imax(y0, 0) / CH; r <= imin(y0 + BS - 1, ROWS * CH - 1) / CH; r++)
- for (int c = imax(x0, 0) / CW; c <= imin(x0 + BS - 1, COLS * CW - 1) / CW; c++)
- if (brick[r][c]) {
- hit_brick(r, c);
+/* the brick the ball is over, if any (a gap between bricks is empty) */
+static bool touch_bricks(const ball_t *b, int *hr, int *hc) {
+ int x0 = (b->x >> 8) - BX0, y0 = (b->y >> 8) - BY0, x1 = x0 + BS - 1, y1 = y0 + BS - 1;
+ const int sw = BW + GAP, shh = BH + GAP;
+ if (y1 < 0 || y0 >= ROWS * shh || x1 < 0 || x0 >= COLS * sw) return false;
+ for (int r = imax(y0, 0) / shh; r <= imin(y1 / shh, ROWS - 1); r++)
+ for (int c = imax(x0, 0) / sw; c <= imin(x1 / sw, COLS - 1); c++) {
+ int bx = c * sw, by = r * shh;
+ if (brick[r][c] && x1 >= bx && x0 < bx + BW && y1 >= by && y0 < by + BH) {
+ *hr = r, *hc = c;
return true;
}
+ }
return false;
}
@@ -842,8 +714,8 @@ static void aim(ball_t *b, int a) {
b->vx = spd * s / 256, b->vy = -spd * isqrt(65536 - s * s) / 256;
}
static int untouched; /* ticks since a ball last met the paddle */
-/* Long without the paddle, a bounce turns the ball about 6 degrees, so it
- can't loop forever between the walls and gold bricks. */
+/* Long without the paddle, a bounce turns the ball a little, so it can't
+ loop forever. */
static void nudge(ball_t *b) {
if (untouched < 600) return;
untouched = 420;
@@ -862,51 +734,69 @@ static void launch(ball_t *b) {
aim(b, (o < 0 ? -90 : 90) + o / 2);
}
+static void power_up(int u, int x, int y) {
+ color c = RGB(0xFFFFFF);
+ if (u == U_LIFE && lives < 5) lives++, mark(0, 0, W, TOP);
+ if (u == U_MULTI) { /* two more balls from the last one */
+ ball_t *b = 0;
+ for (int i = 0; i < NBALL; i++)
+ if (ball[i].on && !ball[i].stuck) b = &ball[i];
+ for (int i = 0, n = 0; b && i < NBALL && n < 2; i++)
+ if (!ball[i].on) {
+ ball[i] = *b;
+ int a = b->vx * 256 / (spd ? spd : 1) + (n++ ? 100 : -100);
+ a = imax(-282, imin(282, a));
+ if (a > -56 && a < 56) a = a < 0 ? -56 : 56;
+ aim(&ball[i], a);
+ if (b->vy > 0) ball[i].vy = -ball[i].vy;
+ }
+ }
+ if (u == U_WIDE) wide_t = 60 * 12, pw_to = 90;
+ if (u == U_FIRE) fire_t = 60 * 8;
+ if (u == U_LASER) laser_t = 60 * 8;
+ burst(x, y, BW, BH, c, 6, 24);
+}
+
static void lose_life(void) {
shake(4, 14);
- burst((px >> 8) - pw / 2, PY, pw, 5, fancy() ? RGB(0xC0C8D8) : BLUE, 16, 35);
+ burst((px >> 8) - pw / 2, PY, pw, PH, WHITE, 16, 35);
set_state(S_LOST);
}
static void ball_tick(ball_t *b) {
- for (int t = 2; t > 0; t--) b->tx[t] = b->tx[t - 1], b->ty[t] = b->ty[t - 1];
+ for (int t = 3; t > 0; t--) b->tx[t] = b->tx[t - 1], b->ty[t] = b->ty[t - 1];
b->tx[0] = (int16_t)(b->x >> 8), b->ty[0] = (int16_t)(b->y >> 8);
if (b->stuck) {
int x = (px >> 8) + b->off - BS / 2;
- x = x < FX0 ? FX0 : x > FX1 - BS ? FX1 - BS : x;
+ x = x < 0 ? 0 : x > W - BS ? W - BS : x;
b->x = x * ONE, b->y = (PY - BS) * ONE;
- for (int t = 0; t < 3; t++) b->tx[t] = (int16_t)x, b->ty[t] = PY - BS;
+ for (int t = 0; t < 4; t++) b->tx[t] = (int16_t)x, b->ty[t] = PY - BS;
return;
}
- int n = imax(iabs(b->vx), iabs(b->vy)) / ONE + 1; /* steps of a pixel at most */
+ int n = imax(iabs(b->vx), iabs(b->vy)) / ONE + 1, r, c; /* steps of a pixel at most */
for (int i = 0; i < n; i++) {
int dx = b->vx / n, dy = b->vy / n;
b->x += dx;
- if (b->x < FX0 * ONE) b->x = FX0 * ONE, b->vx = iabs(b->vx), nudge(b);
- else if (b->x > (FX1 - BS) * ONE) b->x = (FX1 - BS) * ONE, b->vx = -iabs(b->vx), nudge(b);
- else if (hit_bricks(b)) b->x -= dx, b->vx = -b->vx, nudge(b);
+ if (b->x < 0) b->x = 0, b->vx = iabs(b->vx), nudge(b);
+ else if (b->x > (W - BS) * ONE) b->x = (W - BS) * ONE, b->vx = -iabs(b->vx), nudge(b);
+ else if (touch_bricks(b, &r, &c)) {
+ break_brick(r, c);
+ if (!fire_t) b->x -= dx, b->vx = -b->vx, nudge(b);
+ }
b->y += dy;
- if (b->y < FY0 * ONE) {
- b->y = FY0 * ONE, b->vy = iabs(b->vy), nudge(b);
- if (mode == CLASSIC && !demo && !shrunk) { /* broke through: the paddle shrinks to half */
- shrunk = true, pw_to = base_width() / 2;
- shake(2, 8);
- }
- } else if (hit_bricks(b)) {
- b->y -= dy, b->vy = -b->vy, nudge(b);
+ if (b->y < TOP * ONE) {
+ b->y = TOP * ONE, b->vy = iabs(b->vy), nudge(b);
+ } else if (touch_bricks(b, &r, &c)) {
+ break_brick(r, c);
+ if (!fire_t) b->y -= dy, b->vy = -b->vy, nudge(b);
}
int half = pw * ONE / 2, bot = b->y + BS * ONE, mid = b->x + BS * ONE / 2 - px;
if (b->vy > 0 && bot >= PY * ONE && bot - dy <= (PY + 1) * ONE && mid > -half - BS * ONE / 2 &&
mid < half + BS * ONE / 2) { /* the paddle: where it lands decides where it goes */
b->y = (PY - BS) * ONE, untouched = 0;
- if (mode == ARCADE && !demo && spd < spd0 * 17 / 10) spd = spd * 65 / 64;
- if (power == P_CATCH) {
- b->stuck = 1, b->off = (int16_t)(mid / ONE), catch_t = 0;
- } else { /* up to 1.1 radians off vertical, and never too steep */
- int a = mid * 282 / (half + BS * ONE / 2);
- if (a > -56 && a < 56) a = b->vx < 0 ? -56 : 56;
- aim(b, a);
- }
+ int a = mid * 282 / (half + BS * ONE / 2); /* up to 1.1 radians off vertical, and never too steep */
+ if (a > -56 && a < 56) a = b->vx < 0 ? -56 : 56;
+ aim(b, a);
demo_aim = rndi(pw * 4 / 5 + 1) - pw * 2 / 5;
return;
}
@@ -917,72 +807,32 @@ static void ball_tick(ball_t *b) {
}
}
-static void clear_round(void) {
+static void clear_wall(void) {
for (int i = 0; i < NBALL; i++) ball[i].on = 0;
for (int i = 0; i < NSHOT; i++) shot[i].on = 0;
- cap.on = 0;
+ add_score(100 * (level + 1));
set_state(S_CLEAR);
}
-static void catch_capsule(int t) {
- add_score(1000);
- burst(cap.x, PY - 2, 16, 4, cap_col[t], 8, 19);
- if (t == 0) set_speed(spd0); /* slow */
- if (t == 4) { /* three balls */
- ball_t *b = &ball[0];
- for (int i = 0; i < NBALL; i++)
- if (ball[i].on) b = &ball[i];
- b->stuck = 0;
- int a = b->vx * 256 / spd;
- for (int i = 0; i < NBALL; i++)
- if (!ball[i].on) {
- ball[i] = *b;
- a += 128;
- int t = a > 282 ? a - 564 : a;
- if (t > -56 && t < 56) t = t < 0 ? -56 : 56; /* never steeper than the paddle sends it */
- aim(&ball[i], t);
- }
- }
- if (t == 5 && lives < 9) lives++, mark(0, 0, W, TOP);
- if (t == 6) warp = 1, mark_at(FX1, PY - 10, FX0, 22);
- if (t == 1 || t == 2 || t == 3) {
- power = t == 1 ? P_CATCH : t == 2 ? P_LASER : P_ENLARGE;
- pw_to = t == 3 ? base_width() * 8 / 5 : base_width();
- } else if (t != 5) {
- power = P_NONE, pw_to = base_width();
- }
- if (power != P_CATCH)
- for (int i = 0; i < NBALL; i++)
- if (ball[i].stuck && ball[i].on && state == S_PLAY) launch(&ball[i]);
-}
-
/* one 60th of a second of play; d is the paddle's direction, fire is OK */
static void play_tick(int d, bool fire) {
/* the paddle: a tap nudges it, holding speeds it up */
if (!d) pv = 0;
- else if (pv * d <= 0) pv = d * 282;
- else if ((pv += d * 115) * d > 7 * ONE) pv = d * 7 * ONE;
+ else if (pv * d <= 0) pv = d * 300;
+ else if ((pv += d * 120) * d > 7 * ONE) pv = d * 7 * ONE;
px += pv;
if (pw != pw_to) pw += pw < pw_to ? 1 : -1;
- int lo = (FX0 * 2 + pw) * ONE / 2, hi = (FX1 * 2 - pw) * ONE / 2;
- if (warp && d > 0 && px >= hi - ONE / 2 && state == S_PLAY) { /* out through the gate */
- add_score(10000);
- clear_round();
- return;
- }
+ int lo = pw * ONE / 2, hi = (W * 2 - pw) * ONE / 2;
if (px < lo) px = lo, pv = 0;
if (px > hi) px = hi, pv = 0;
-
if (demo ? ball[0].stuck : state == S_READY) {
ball_tick(&ball[0]);
- if (rows_shown < ROWS && !(st_t & 1)) { /* the wall builds up, row by row */
- mark_at(FX0 - 3, BY0 + rows_shown * CH - 3, COLS * CW + 6, CH + 7);
- rows_shown++;
- }
if (fire) {
launch(&ball[0]);
- if (rows_shown < ROWS) rows_shown = ROWS, full = true;
- if (!demo) set_state(S_PLAY);
+ if (!demo) {
+ if (!hinted) hinted = true, full = true;
+ set_state(S_PLAY);
+ }
}
return;
}
@@ -998,38 +848,33 @@ static void play_tick(int d, bool fire) {
else lose_life();
return;
}
- /* catch: OK lets go, or it goes by itself */
- if (power == P_CATCH)
- for (int i = 0; i < NBALL; i++)
- if (ball[i].on && ball[i].stuck && (fire || ++catch_t > 150)) launch(&ball[i]);
- if (power == P_LASER && fire && laser_cd <= 0) {
- int x = (px >> 8) - pw / 2;
- for (int k = 0, i = 0; k < 2 && i < NSHOT; i++)
- if (!shot[i].on) shot[i] = (thing_t){(int16_t)(k++ ? x + pw - 5 : x + 3), PY - 9, 1, 0};
- laser_cd = 12;
+ if (wide_t && !--wide_t) pw_to = base_width();
+ if (fire_t) fire_t--;
+ if (laser_t) { /* the laser fires by itself */
+ laser_t--;
+ if (--laser_cd <= 0) {
+ int x = (px >> 8) - pw / 2;
+ for (int k = 0, i = 0; k < 2 && i < NSHOT; i++)
+ if (!shot[i].on) shot[i] = (shot_t){(int16_t)(k++ ? x + pw - 6 : x + 4), PY - 12, 1};
+ laser_cd = 24;
+ }
}
- laser_cd--;
for (int i = 0; i < NSHOT; i++) {
- thing_t *s = &shot[i];
+ shot_t *s = &shot[i];
if (!s->on) continue;
s->y -= 6;
- if (s->y < FY0) {
+ if (s->y < TOP) {
s->on = 0;
continue;
}
- int r = (s->y - BY0) / CH, c = (s->x - FX0) / CW;
- if (s->y >= BY0 && r < ROWS && brick[r][c]) hit_brick(r, c), s->on = 0;
- }
- if (cap.on && (cap.y += (st_t & 1) + 1) > H) cap.on = 0;
- int pl = (px >> 8) - pw / 2;
- if (cap.on && cap.y + 8 >= PY && cap.y <= PY + 6 && cap.x + 16 > pl && cap.x < pl + pw) {
- cap.on = 0;
- catch_capsule(cap.type);
+ int r = (s->y - BY0) / (BH + GAP), c = (s->x - BX0) / (BW + GAP);
+ if (s->y >= BY0 && r < ROWS && s->x >= BX0 && c < COLS && brick[r][c] && (s->x - BX0) % (BW + GAP) < BW) break_brick(r, c), s->on = 0;
}
if (!bricks_left && !demo) {
shake(3, 10);
- clear_round();
+ clear_wall();
}
+ if (demo && !bricks_left) load_wall();
}
/* the title screen's paddle plays by itself, after the lowest ball */
@@ -1046,13 +891,9 @@ static void tick(int d, bool fire) {
if (shake_t) {
shake_t--;
int a = imin(shake_a, shake_t / 2 + 1);
- bx = shake_t ? rndi(2 * a + 1) - a : 0, by = shake_t ? rndi(2 * a + 1) - a : 0;
- sx = shake_all ? bx : 0, sy = shake_all ? by : 0;
- if (!shake_t) shake_a = 0, shake_all = false;
+ sx = shake_t ? rndi(2 * a + 1) - a : 0, sy = shake_t ? rndi(2 * a + 1) - a : 0;
+ if (!shake_t) shake_a = 0;
}
- for (int r = 0; r < ROWS; r++) /* glints fade */
- for (int c = 0; c < COLS; c++)
- if (brick[r][c] >> 6 && !(st_t & 1)) brick[r][c] = (uint8_t)(brick[r][c] - 64), mark_cell(r, c);
for (int i = 0; i < NPART; i++) {
part_t *p = &part[i];
if (!p->life) continue;
@@ -1064,40 +905,29 @@ static void tick(int d, bool fire) {
if (state == S_READY || state == S_PLAY) d = demo_dir(), fire = fire || !(st_t & 31);
#endif
if (state == S_READY && st_t == 21) ui_area(S_READY); /* the hint shows up */
- if (warp && !(tk & 7)) mark_at(FX1, PY - 10, FX0, 22); /* the gate's lights */
if (demo || state == S_READY || state == S_PLAY) play_tick(d, fire);
- bool over = false;
if (state == S_LOST && st_t > 70) {
if (--lives > 0) serve(), set_state(S_READY), mark(0, 0, W, TOP);
- else over = true;
+ else keep_best(), set_state(S_OVER);
}
- if (state == S_CLEAR && st_t > 100) {
- if (mode == CLASSIC ? wall == 2 : round_no + 1 == NROUNDS) won = over = true;
- else wall++, round_no += mode == ARCADE, start_round_(), full = true;
- }
- if (over) keep_best(), set_state(S_OVER);
+ if (state == S_CLEAR && st_t > 100) level++, start_wall();
}
/* n ticks of play, and the areas they change */
static void frame(int n, int d, bool fire) {
mark_moving();
- int psx = sx, psy = sy, pbx = bx, pby = by;
+ int psx = sx, psy = sy;
while (n-- > 0) {
tick(d, fire);
fire = false;
}
mark_moving();
- if (sx != psx || sy != psy) { /* the walls shake */
- mark(0, TOP - 4, W, FY0 + 4);
- mark(0, FY0, FX0 + 4, H);
- mark(FX1 - 4, FY0, W, H);
- }
- if (bx != pbx || by != pby) { /* the bricks shake */
- int r0 = ROWS, r1 = 0;
+ if (sx != psx || sy != psy) { /* the bricks shake: where there are some */
+ int r1 = 0;
for (int r = 0; r < ROWS; r++)
for (int c = 0; c < COLS; c++)
- if (brick[r][c]) r0 = imin(r0, r), r1 = r + 1;
- if (r1) mark(FX0, BY0 + r0 * CH - 4, FX1, BY0 + r1 * CH + 8);
+ if (brick[r][c]) r1 = r + 1;
+ if (r1) mark(BX0 - 8, BY0 - 8, BX0 + COLS * (BW + GAP) + 8, brick_y(r1) + 8);
}
}
@@ -1107,25 +937,24 @@ static void menu_input(uint64_t hit) {
bool ok = hit & (KEY(eadk_key_ok) | KEY(eadk_key_exe)), back = hit & KEY(eadk_key_back);
int ud = (hit & KEY(eadk_key_down) ? 1 : 0) - (hit & KEY(eadk_key_up) ? 1 : 0);
int lr = (hit & KEY(eadk_key_right) ? 1 : 0) - (hit & KEY(eadk_key_left) ? 1 : 0);
- int before = sel + tsel * 4 + start_round * 16;
+ int before = sel + tsel * 4 + start_lv * 16;
switch (state) {
case S_TITLE:
- tsel = (tsel + ud + 3) % 3;
- if (tsel == 1 && lr) start_round = (start_round + lr + sv.reached - 1) % sv.reached + 1;
+ tsel = (tsel + ud + 2) % 2;
+ if (tsel == 0 && lr) start_lv = (start_lv + lr + sv.reached - 1) % sv.reached + 1;
if (back) {
ask_title = true, sel = 0;
set_state(S_QUIT);
} else if (ok) {
- if (tsel == 2) set_state(S_SET);
- else new_game(tsel);
+ if (tsel == 1) set_state(S_SET);
+ else new_game();
}
break;
case S_SET:
- sel = (sel + ud + 3) % 3;
+ sel = (sel + ud + 2) % 2;
if (lr || ok) {
- if (sel == 0) sv.diff = (uint8_t)((sv.diff + (lr ? lr : 1) + 3) % 3);
- else if (sel == 1) sv.shake ^= 1;
- else sv.trail ^= 1;
+ if (sel == 0) sv.speed = (uint8_t)((sv.speed + (lr ? lr : 1) + 3) % 3);
+ else sv.shake ^= 1;
ui_area(S_SET);
}
if (back) {
@@ -1143,7 +972,7 @@ static void menu_input(uint64_t hit) {
state = resume_state, st_t = 30, full = true;
} else if (ok && sel == 1) {
keep_best();
- new_game(mode);
+ new_game();
} else if (ok) {
set_state(S_QUIT);
}
@@ -1158,16 +987,17 @@ static void menu_input(uint64_t hit) {
}
break;
case S_OVER:
- if (ok) new_game(mode);
+ if (ok) new_game();
else if (back) title();
break;
}
- if (before != sel + tsel * 4 + start_round * 16) ui_area(state);
+ if (before != sel + tsel * 4 + start_lv * 16) ui_area(state);
}
int main(void) {
np_app_begin();
load();
+ start_lv = sv.reached;
seed ^= (uint32_t)eadk_timing_millis() * 2654435761u;
title();
uint64_t ignore = eadk_keyboard_scan(), held = 0;
@@ -1203,7 +1033,7 @@ int main(void) {
} else {
ticks = due, fire_due = false;
st_t++;
- if (state == S_OVER && !(st_t & 15) && fresh_best) mark(60, 124, 260, 148);
+ if (state == S_OVER && !(st_t & 15) && fresh_best) mark(60, 120, 260, 156);
}
eadk_display_wait_for_vblank();
flush();
diff --git a/games/connectfour/README.md b/games/connectfour/README.md
index 6b727f9c..621ad2c3 100644
--- a/games/connectfour/README.md
+++ b/games/connectfour/README.md
@@ -8,7 +8,7 @@ The classic four-in-a-row game for the NumWorks calculator. Drop red and yellow
- **Against a friend or the computer**, at three levels. Weak makes mistakes, Normal looks a few moves ahead, and Strong is hard to beat: it thinks for up to a second and knows the row-parity rules that decide endgames.
- **Two or three players.** Three players (red, yellow and green) play on a wider grid, 8 columns instead of 7. Against the computer, you play red against two of them.
-- **The real thing**: the blue plastic grid with its round holes and stand, discs with a raised rim that fall behind the grid with a little bounce, the winning four lit up, and all the discs dropping out of the bottom before the next round.
+- **The real thing**: the blue plastic grid with its round holes, discs with a raised rim that fall behind the grid with a little bounce, the winning four lit up, and all the discs dropping out of the bottom before the next round.
- **A tally** of wins for each player, kept between sessions (it starts over when you change the opponent, the players or the level). Who starts takes turns each round.
- **Undo** a move you regret, and a **dark theme**.
@@ -29,7 +29,7 @@ In the menu, Up and Down pick a line and Left / Right change it.
Rewritten in C for NumPlay from **[Tatone26](https://github.com/Tatone26)**'s version in [Numworks-games](https://github.com/Tatone26/Numworks-games/tree/main/apps/connectfour) (All the Apps), which is released into the public domain ([UNLICENSE](UNLICENSE)). Its modes are all here: solo or not, two or three players on the same grid sizes, three computer levels, and the dark mode. What changed:
-- It looks like the Milton Bradley / Hasbro game (invented by Howard Wexler and Ned Strongin, 1974): the blue grid and stand, embossed discs that fall with gravity, instead of flat discs on a plain grid.
+- It looks like the Milton Bradley / Hasbro game (invented by Howard Wexler and Ned Strongin, 1974): the blue grid, embossed discs that fall with gravity, instead of flat discs on a plain grid.
- A new computer player: bitboards, alpha-beta search with a transposition table, moves that make threats tried first, and an evaluation that knows which rows win endgames. It answers in under a second (the original's strongest level could take many seconds), and a disc sways over the board while it thinks.
- Undo, a tally of wins, alternating first player, the winning four highlighted, the discs dropping out between rounds, a pause menu, and saved settings.
diff --git a/games/connectfour/docs/shot.png b/games/connectfour/docs/shot.png
index 060daa4a..f5a59092 100644
Binary files a/games/connectfour/docs/shot.png and b/games/connectfour/docs/shot.png differ
diff --git a/games/connectfour/src/main.c b/games/connectfour/src/main.c
index 53c7964e..cf40993e 100644
--- a/games/connectfour/src/main.c
+++ b/games/connectfour/src/main.c
@@ -128,7 +128,7 @@ static int8_t gcol[320], gdx[320], grow[240], gdy[240];
static void layout(void) {
np = V.players, NC = np + 5, C = np == 3 ? 28 : 30, R = C * 2 / 5, rr = 2 * R;
- BX = (320 - NC * C) / 2, BY = 240 - 14 - F - 6 * C, HY = BY - F - R - 3;
+ BX = (320 - NC * C) / 2, BY = 240 - 10 - F - 6 * C, HY = BY - F - R - 3;
for (int i = 0; i < 320; i++) {
int g = i - BX, h = i - BY;
gcol[i] = (int8_t)(g >= 0 && g < NC * C ? g / C : -1), gdx[i] = (int8_t)(g % C);
@@ -240,10 +240,6 @@ static void row_game(color *p, int y, int x0, int x1) {
int ex = x < fx0 + 8 ? fx0 + 8 - x : x > fx1 - 9 ? x - (fx1 - 9) : 0;
if (x < fx0 || x >= fx1 || ex * ex + ey2 > 70) {
if ((x >= fx1 || y >= fy1) && x >= fx0 + 6 && x < fx1 + 6 && y >= fy0 + 6 && y < fy1 + 4) c = mix(0, c, 3); /* the board's shadow */
- /* the stand: a post on each side, on a foot */
- int o = x < 160 ? fx0 - 1 - x : x - fx1, f = x < 160 ? x - (fx0 - 4) : x - (fx1 + 3);
- if (o >= 0 && o < 6 && y > fy0 + 12 && y < 232) c = pl[o < 2 ? 26 : o > 3 ? 10 : 20];
- if (y >= 229 && y < 239 && f * f + (y - 229) * (y - 229) * 3 < 300) c = pl[y < 231 ? 36 : 14];
if (mrow) c = over_disc(c, 2 * x + 1 - mx2, md, rr, cur, 0);
} else {
int s = sy + (x < fx0 + 2 ? 10 : x >= fx1 - 2 ? -12 : 0), col = gcol[x];
diff --git a/games/games.json b/games/games.json
index 331af580..efa5961d 100644
--- a/games/games.json
+++ b/games/games.json
@@ -160,9 +160,9 @@
"title": "Solitaire",
"tagline": "The classic card game",
"credit": "From All the Apps by Tatone26",
- "top": "0x17964A",
- "bottom": "0x053A1B",
- "accent": "0xD62828",
+ "top": "0x34A249",
+ "bottom": "0x123F20",
+ "accent": "0x1A73E8",
"records": [
"solitaire.sav"
],
@@ -177,9 +177,9 @@
"title": "NumDance",
"tagline": "Hit the arrows on the beat",
"credit": null,
- "top": "0xC24B99",
- "bottom": "0x1E0A33",
- "accent": "0x2FE3FF",
+ "top": "0x1E5A6E",
+ "bottom": "0x0A1030",
+ "accent": "0xFFC23F",
"records": [
"numdance.sav"
],
@@ -225,19 +225,19 @@
},
{
"id": "breakout",
- "title": "Breakout",
+ "title": "Block Breaker",
"tagline": "Break every brick",
"credit": null,
- "top": "0xD24B3A",
- "bottom": "0x1C0A08",
- "accent": "0xE8C43A",
+ "top": "0x3A3440",
+ "bottom": "0x0E0B10",
+ "accent": "0x5784E6",
"records": [
"breakout.sav"
],
"shots": [
"docs/shot.png"
],
- "app": "Breakout.nwa",
+ "app": "BlockBreaker.nwa",
"repo": "https://github.com/Mason363/NumPlay/tree/main/games/breakout"
},
{
diff --git a/games/minesweeper/README.md b/games/minesweeper/README.md
index a7e90daf..a485aa7d 100644
--- a/games/minesweeper/README.md
+++ b/games/minesweeper/README.md
@@ -5,12 +5,12 @@ The Windows classic for the NumWorks calculator: the gray field, the red LED cou
<img src="docs/shot.png" width="320" alt="A game of Beginner in progress">
- **Beginner** (9 x 9, 10 mines), **Intermediate** (16 x 16, 40) and **Expert** (30 x 16, 99), or a **Custom** field up to 30 x 16. Every size fits the screen whole.
-- **Your first square is always safe** and opens an area.
+- **Your first square is always safe** and opens an area (or, in Options, is only safe, like Windows).
- **No guessing** (in Options): every field you get can be cleared by logic alone, so a loss is always your mistake, never bad luck. (Very crowded custom fields are the exception: after a second of looking, you get a normal one.)
-- **Marks (?)** like the original, if you want them.
+- **Marks (?)** like the original, if you want them, and a cursor that wraps around the edges or stops at them.
- Best times and games won for each level, and your game is kept when you leave, to finish later. Starting another field doesn't lose it until you open that field's first square.
-Open a number whose mines are all flagged to open everything around it at once, like clicking both buttons on Windows; hold OK on a number to see the squares around it pressed down. The cursor wraps around the edges.
+Open a number whose mines are all flagged to open everything around it at once, like clicking both buttons on Windows; hold OK on a number to see the squares around it pressed down.
## Controls
diff --git a/games/minesweeper/src/main.c b/games/minesweeper/src/main.c
index 7bc6e5da..07cc3d06 100644
--- a/games/minesweeper/src/main.c
+++ b/games/minesweeper/src/main.c
@@ -433,9 +433,10 @@ static bool solvable(int first) {
}
return !todo;
}
-/* mines go in anywhere but around the first square opened */
-static void deal(int first, bool sure) {
- int n = bw * bh, fx = first % bw, fy = first / bw;
+/* mines go in anywhere but the first square opened, and (area) around it;
+ no guessing needs the area */
+static void deal(int first, bool sure, bool area) {
+ int n = bw * bh, fx = first % bw, fy = first / bw, around = sure || area;
uint32_t t0 = eadk_timing_millis();
seed ^= t0 * 2654435761u;
for (bool again = true;;) {
@@ -443,7 +444,7 @@ static void deal(int first, bool sure) {
for (int i = 0; i < n; i++) cell[i] &= 0xE0;
for (int k = 0; k < nm;) {
int i = (int)(rnd() % (uint32_t)n), dx = i % bw - fx, dy = i / bw - fy;
- if (cell[i] & MINE || (dx * dx <= 1 && dy * dy <= 1)) continue;
+ if (cell[i] & MINE || (around ? dx * dx <= 1 && dy * dy <= 1 : i == first)) continue;
cell[i] |= MINE, k++;
}
}
@@ -468,7 +469,7 @@ static void deal(int first, bool sure) {
/* ------------------------------------------------------------------ the game */
static struct {
- uint8_t magic, version, diff, opts; /* diff: 0-2, 3 custom; opts: 1 marks (?), 2 no guessing */
+ uint8_t magic, version, diff, opts; /* diff: 0-2, 3 custom; opts: O_ bits */
uint32_t elapsed; /* the game in progress (ms) */
uint16_t best[3], played[3], won[3]; /* best: tenths of a second, 0 for none */
uint16_t cmines, gmines; /* custom mines; the game's mines */
@@ -476,8 +477,10 @@ static struct {
uint8_t board[MW * MH / 2]; /* the game, a nibble a cell: mine | state << 1 */
} V;
#define SAVE_NAME "mines.sav"
-#define O_MARKS 1
-#define O_SURE 2
+#define O_MARKS 1 /* right-clicks go flag, ?, hidden */
+#define O_SURE 2 /* no guessing */
+#define O_BARE 4 /* the first square is only safe, like Windows: no area around it */
+#define O_EDGE 8 /* the cursor stops at the edges */
static void save(void) {
V.magic = 'M', V.version = 1;
@@ -521,7 +524,7 @@ static void load(void) {
bool ok = d && n == sizeof V && d[0] == 'M' && d[1] == 1;
for (uint32_t i = 0; i < sizeof V; i++) ((uint8_t *)&V)[i] = ok ? d[i] : 0;
if (V.diff > 3) V.diff = 0;
- V.opts &= 3;
+ V.opts &= 15;
if (V.cw < 8 || V.cw > MW || V.ch < 8 || V.ch > MH) V.cw = 16, V.ch = 12;
if (!V.cmines || V.cmines > (V.cw - 1) * (V.ch - 1)) V.cmines = (uint16_t)(V.cw * V.ch / 6);
for (int k = 0; k < 3; k++) {
@@ -708,7 +711,7 @@ static void play(int i) {
if (st == FLAG) return;
if (gs == G_NEW) {
update(shown[0], shown[1], F_OH); /* dealing a no-guessing field can take a moment */
- deal(i, V.opts & O_SURE);
+ deal(i, V.opts & O_SURE, !(V.opts & O_BARE));
gs = G_PLAY, last = (uint32_t)eadk_timing_millis(), V.gw = 0; /* this game replaces the saved one */
int lv = level();
if (lv < 3) V.played[lv]++;
@@ -884,15 +887,23 @@ static void draw_help(void) {
text("Original by Robert Donner & Curt Johnson", wx0 + 8, wy0 + 142, BLACK, GRAY);
button(wx0 + 114, wy0 + 170, 68, 22, "OK", true);
}
+static const char *const OPTS[4] = {"Marks (?)", "No guessing", "Open an area first", "Cursor wraps around"};
+static const char *const HINTS[4][2] = {
+ {"Flag, then ?, then nothing:", "for squares you are unsure of."},
+ {"Every field can be cleared", "by logic alone."},
+ {"The first square opens an area.", "Off: only safe, like Windows."},
+ {"Off: the cursor stops at", "the edges of the field."},
+};
+/* the options on, as the rows show them (the last two are kept inverted) */
+static bool opt_on(int k) { return (V.opts >> k & 1) ^ (k >= 2); }
static void draw_options(void) {
- static const char *const o[2] = {"Marks (?)", "No guessing"};
- if (whole) {
- dialog(236, 132, "Options");
- text("No guessing: every field can", wx0 + 10, wy0 + 50, BLACK, GRAY);
- text("be cleared by logic alone.", wx0 + 10, wy0 + 66, BLACK, GRAY);
- text("OK: on/off Back: done", wx0 + 10, wy0 + 88, BLACK, GRAY);
- }
- for (int k = 0; k < 2; k++) row(wx0 + 8, wy0 + 8 + k * 18, 212, o[k], 0, 0, k == sel, V.opts >> k & 1);
+ if (whole) dialog(252, 172, "Options");
+ for (int k = 0; k < 4; k++) row(wx0 + 8, wy0 + 8 + k * 18, 228, OPTS[k], 0, 0, k == sel, opt_on(k));
+ bool forced = sel == 2 && (V.opts & O_SURE);
+ fill(wx0 + 8, wy0 + 88, 228, 32, GRAY);
+ text(HINTS[sel][0], wx0 + 12, wy0 + 88, BLACK, GRAY);
+ text(forced ? "Always on with no guessing." : HINTS[sel][1], wx0 + 12, wy0 + 104, forced ? NAVY : BLACK, GRAY);
+ if (whole) text("OK: on/off Back: done", wx0 + 12, wy0 + 126, BLACK, GRAY);
}
static int cf[3]; /* the custom field: height, width, mines */
static void draw_custom(void) {
@@ -1023,7 +1034,7 @@ int main(void) {
int x = cur % bw + lr, y = cur / bw + ud;
/* a new press wraps around the edge, a held key stops there */
if ((unsigned)x < (unsigned)bw && (unsigned)y < (unsigned)bh) move_to(y * bw + x);
- else if (fresh & arrows) move_to((y + bh) % bh * bw + (x + bw) % bw);
+ else if ((fresh & arrows) && !(V.opts & O_EDGE)) move_to((y + bh) % bh * bw + (x + bw) % bw);
}
if (ok) {
if (gs < G_WON) grip = state(cur) == OPEN ? cur : -1, play(cur);
@@ -1049,7 +1060,7 @@ int main(void) {
if (back || (ok && sel)) close_dialog();
else if (ok) leave = true;
} else if (dlg == D_OPTIONS) {
- if (ud) sel = !sel;
+ if (ud) sel = (sel + ud + 4) % 4;
if (ok) V.opts ^= (uint8_t)(1 << sel);
if (ud || ok) draw_dialog(false);
if (back) save(), close_dialog();
diff --git a/games/numdance/README.md b/games/numdance/README.md
index b9c0f769..3beac977 100644
--- a/games/numdance/README.md
+++ b/games/numdance/README.md
@@ -1,16 +1,16 @@
# NumDance
-A rhythm game for the NumWorks calculator, in the style of Friday Night Funkin' and Dance Dance Revolution. Arrows fall toward a row of gray targets: press the matching key just as each one lands.
+A rhythm game for the NumWorks calculator, on the idea of the Artistic Swimming event in Google's Doodle Champion Island Games: arrows fall down four lanes onto their targets, and you press the matching key just as each one lands, while a crew dances in step beside the lanes. Here the crew is a robot, a fox, a penguin and a frog, dancing on a city rooftop at night.
<img src="docs/shot.png" width="320" alt="NumDance in the middle of a song">
+- **Champion Island's scoring:** **Perfect!** is 100 points, **Good!** 50, and a **Miss** takes 5 away (never below 0). The score and your combo sit in the top corner, and when misses pile up, the sky turns red.
+- **The rooftop, in pixel art:** the moon, clouds going by, stars that twinkle on the beat, the city with its lit windows and the red lights on its masts, and the crew, who change moves together on every beat.
- **7 songs and Endless:** Warm Up, Slow Jam, Bubble Pop, Neon Nights, Starlight, Hyperdrive and Boss Rush, from 84 to 180 BPM and about a minute each, plus Endless, which never stops and gets faster.
-- **4 difficulties** for every song: Easy, Normal, Hard and Expert.
-- **Taps, holds and jumps:** keep the key down along a trail, and press two keys at once for a jump.
-- **Judgments** Perfect, Great, Good and Miss, with Early or Late when you are off, a combo counter, a health bar, your score and accuracy.
+- **4 difficulties** for every song: Easy, Normal, Hard and Expert. Jumps (two arrows at once) come in on the harder ones.
- **A grade at the end** (S+, S, A, B, C or D), with your best score, grade and full combos kept for every song and difficulty.
-The calculator has no speaker, so the music is something you see: the stage lights, the speakers, the LED bars, the health icons and the targets all pulse on the beat, a faint line scrolls by on every beat, and every chart sits on the beat grid, so the arrows themselves feel like a song.
+The calculator has no speaker, so the music is something you see: the crew moves on every beat, the stars and the masts blink with it, and every chart sits on the beat grid, so the arrows themselves feel like a song.
## Controls
@@ -30,15 +30,17 @@ In the song list, **Up / Down** picks a song and **Left / Right** the difficulty
- **Scroll speed** from 1x to 4x.
- **Direction:** arrows falling down (the default) or rising up.
- **Offset:** moves every key press earlier or later by up to 120 ms. **Calibrate offset** measures it for you: press as eight arrows land, and it keeps the average.
-- **No-fail:** the song goes on even when the health bar is empty.
+- **No-fail** (on at first, like Champion Island): turn it off and a song ends once the sky is at its reddest.
## How the songs are made
-Each song is a few bytes: a tempo, a seed and a list of sections (intro, verse, build-up, chorus, break, drop, outro). The notes are made bar by bar from them, so a chorus comes back the same every time (mirrored the second time), and the difficulties share one rhythm: Easy plays the strong beats, Expert fills in the rest. The patterns are streams, staircases, trills, shapes and jacks, with jumps and holds, and they are checked to be playable with two thumbs: never more than two keys at once, enough time between notes for the difficulty, and no fast repeats on one key.
+Each song is a few bytes: a tempo, a seed and a list of sections (intro, verse, build-up, chorus, break, drop, outro). The notes are made bar by bar from them, so a chorus comes back the same every time (mirrored the second time), and the difficulties share one rhythm: Easy plays the strong beats, Expert fills in the rest. The patterns are streams, staircases, trills, shapes and jacks, with jumps, and they are checked to be playable with two thumbs: never more than two keys at once, enough time between notes for the difficulty, and no fast repeats on one key.
## Credits
-A new game, inspired by [Friday Night Funkin'](https://github.com/FunkinCrew/Funkin) by ninjamuffin99, PhantomArcade, evilsk8r and Kawai Sprite (the arrow colours, the gray targets, the health bar with its two faces, "Ready? Set Go!") and by Konami's Dance Dance Revolution (the judgments, the combo and the grades). No code, art or music comes from either.
+A new game. The idea and the scoring come from the Artistic Swimming event of **Doodle Champion Island Games** (Google, 2021); the setting, the characters and the look are NumDance's own, and it isn't affiliated with or endorsed by Google. The countdown and the grades come from Friday Night Funkin' and Dance Dance Revolution. No code, art or music comes from any of them.
+
+The crew is drawn from pixel maps in [tools/dancers.py](tools/dancers.py), which packs them at 4 bits a pixel.
It comes inside [NumPlay](https://github.com/Mason363/NumPlay), or on its own as `NumDance.nwa` from the [latest release](https://github.com/Mason363/NumPlay/releases/latest).
diff --git a/games/numdance/docs/shot.png b/games/numdance/docs/shot.png
index 8036abc5..68f02604 100644
Binary files a/games/numdance/docs/shot.png and b/games/numdance/docs/shot.png differ
diff --git a/games/numdance/src/main.c b/games/numdance/src/main.c
index f5ac4a22..3533d3cd 100644
--- a/games/numdance/src/main.c
+++ b/games/numdance/src/main.c
@@ -1,12 +1,15 @@
-/* NumDance: a rhythm game in the style of Friday Night Funkin' and Dance
- * Dance Revolution. Arrows scroll to a row of gray targets; press the
- * matching key just as each one lands.
+/* NumDance: a rhythm game on the idea of Doodle Champion Island's Artistic
+ * Swimming (Google, 2021): arrows fall down four lanes onto their targets;
+ * press the matching key just as each one lands, while a crew of four
+ * dances in step beside the lanes. Perfect! gives 100 points, Good! 50, and
+ * a miss takes 5 and turns the sky a little redder. The setting is its own:
+ * a city rooftop at night, with a robot, a fox, a penguin and a frog.
*
* The calculator has no speaker, so the music is something you see: the
- * stage pulses on every beat and every chart sits on the beat grid. A song is
- * a list of sections (verse, chorus, break...) that becomes notes bar by bar
- * from a seed, so a whole song takes a few bytes and its choruses come back
- * like in a real song.
+ * crew changes moves on every beat, the stars twinkle with it, and every
+ * chart sits on the beat grid. A song is a list of sections (verse, chorus,
+ * break...) that becomes notes bar by bar from a seed, so a whole song takes
+ * a few bytes and its choruses come back like in a real song.
*
* Only what changes is redrawn. The screen is cut into sixteen columns of 20
* pixels with a bit per row that says "repaint me"; marked parts are composed
@@ -93,80 +96,94 @@ static void disc(int cx, int cy, int r, int t, color c, int a) {
}
/* ------------------------------------------------------------------ arrows */
-/* One arrow shape (pointing up) drawn at four sizes when the app starts:
- 0 empty, 1-15 the soft outer edge, 16 outline, 17 inner rim, 18-49 body
- from the tip to the tail. Palettes give it colours; the other directions
- read the same pixels turned. */
-static const uint8_t SZ[4] = {32, 36, 38, 40};
-static uint16_t soff[4];
-static uint8_t spr[32 * 32 + 36 * 36 + 38 * 38 + 40 * 40];
-enum { P_NOTE, P_PRESS = 4, P_CONF = 8, P_STRUM = 12, P_BEAT, P_MISS, NPAL };
+/* One pixel-art arrow pointing up, 15 x 15, drawn twice as big: 0 empty, 16
+ outline, 17 inner rim, 18-49 body from the tip to the tail. Palettes give
+ it colors; the other directions read the same pixels turned. */
+#define AN 15
+static uint8_t spr[AN * AN];
+enum { P_NOTE, P_MISS = 4, NPAL };
static color pal[NPAL][50];
-static const color lanec[4] = {RGB(0xC24B99), RGB(0x00FFFF), RGB(0x12FA05), RGB(0xF9393F)};
+/* left, down, up, right: coral, gold, teal and blue */
+static const color lanec[4] = {RGB(0xFF6F59), RGB(0xFFC23F), RGB(0x3DD6C6), RGB(0x5A8CFF)};
static void make_arrows(void) {
static const int8_t vx[7] = {0, 88, 37, 37, -37, -37, -88}, vy[7] = {-88, 2, 2, 86, 86, 2, 2};
- int o = 0;
- for (int s = 0; s < 4; s++) {
- int n = SZ[s];
- float h = n * .5f, ol = n * .075f;
- soff[s] = (uint16_t)o;
- for (int j = 0; j < n; j++)
- for (int i = 0; i < n; i++) {
- float x = (i + .5f) / h - 1, y = (j + .5f) / h - 1, dd = 9;
- bool in = false;
- for (int k = 0, l = 6; k < 7; l = k++) { /* distance to the outline, and inside or not */
- float ax = vx[k] * .01f, ay = vy[k] * .01f, ex = vx[l] * .01f - ax, ey = vy[l] * .01f - ay;
- float wx = x - ax, wy = y - ay, u = (wx * ex + wy * ey) / (ex * ex + ey * ey);
- u = u < 0 ? 0 : u > 1 ? 1 : u;
- float qx = wx - ex * u, qy = wy - ey * u;
- if (qx * qx + qy * qy < dd) dd = qx * qx + qy * qy;
- if ((ay > y) != (ay + ey > y) && x < ax + ex * (y - ay) / ey) in = !in;
- }
- float d = __builtin_sqrtf(dd) * h * (in ? -1 : 1) - n * .07f; /* in pixels, corners rounded */
- int q = d > .5f ? 0 : d > -.5f ? 1 + (int)((.5f - d) * 14.9f) : d > -ol ? 16 : d > -ol - 1.4f ? 17 : 18 + clamp((int)((y + 1) * 16), 0, 31);
- spr[o++] = (uint8_t)q;
+ float h = AN * .5f;
+ for (int j = 0; j < AN; j++)
+ for (int i = 0; i < AN; i++) {
+ float x = (i + .5f) / h - 1, y = (j + .5f) / h - 1, dd = 9;
+ bool in = false;
+ for (int k = 0, l = 6; k < 7; l = k++) { /* distance to the outline, and inside or not */
+ float ax = vx[k] * .01f, ay = vy[k] * .01f, ex = vx[l] * .01f - ax, ey = vy[l] * .01f - ay;
+ float wx = x - ax, wy = y - ay, u = (wx * ex + wy * ey) / (ex * ex + ey * ey);
+ u = u < 0 ? 0 : u > 1 ? 1 : u;
+ float qx = wx - ex * u, qy = wy - ey * u;
+ if (qx * qx + qy * qy < dd) dd = qx * qx + qy * qy;
+ if ((ay > y) != (ay + ey > y) && x < ax + ex * (y - ay) / ey) in = !in;
}
- }
+ float d = __builtin_sqrtf(dd) * h * (in ? -1 : 1) - .35f; /* in source pixels */
+ spr[j * AN + i] = (uint8_t)(d > 0 ? 0 : d > -1 ? 16 : d > -2 ? 17 : 18 + clamp((int)((y + 1) * 16), 0, 31));
+ }
}
static void mkpal(int i, color out, color rim, color hi, color lo) {
pal[i][16] = out, pal[i][17] = rim;
for (int k = 0; k < 32; k++) pal[i][18 + k] = mix(lo, hi, k);
}
-
static void make_palettes(void) {
- color gray = RGB(0x87A3AD);
- for (int l = 0; l < 4; l++) {
- color c = lanec[l], pc = mix(c, gray, 12);
- mkpal(P_NOTE + l, mix(0, c, 26), mix(WHITE, c, 15), mix(WHITE, c, 6), mix(0, c, 10));
- mkpal(P_PRESS + l, RGB(0x1B2127), mix(WHITE, pc, 8), pc, mix(0, pc, 12));
- mkpal(P_CONF + l, mix(0, c, 14), WHITE, mix(WHITE, c, 22), mix(WHITE, c, 6));
- }
- mkpal(P_STRUM, RGB(0x1C242B), RGB(0xC6D6DC), RGB(0xA0B6BF), RGB(0x6B838D));
- mkpal(P_BEAT, RGB(0x26313A), RGB(0xEEF5F8), RGB(0xC2D4DB), RGB(0x8AA2AC));
- mkpal(P_MISS, INK, RGB(0x5A5A70), RGB(0x46465A), RGB(0x2A2A38));
-}
-
-static void arrow(int dir, int cx, int cy, int s, const color *pl, int a) {
- int n = SZ[s], x0 = cx - n / 2, y0 = cy - n / 2, sx, sy, base;
- switch (dir) {
- case 0: sx = n, sy = -1, base = n - 1; break;
- case 1: sx = 1, sy = -n, base = n * (n - 1); break;
- case 2: sx = 1, sy = n, base = 0; break;
- default: sx = -n, sy = 1, base = n * (n - 1);
- }
- int xa = maxi(x0, bx), xb = mini(x0 + n, bx + bw), ya = maxi(y0, by), yb = mini(y0 + n, by + bh);
- for (int y = ya; y < yb; y++) {
- color *p = buf + (y - by) * bw + xa - bx;
- const uint8_t *q = spr + soff[s] + base + (y - y0) * sy + (xa - x0) * sx;
- for (int x = xa; x < xb; x++, p++, q += sx) {
- int v = *q;
- if (v) *p = v < 16 ? mix(pl[16], *p, v * a >> 4) : a >= 32 ? pl[v] : mix(pl[v], *p, a);
+ for (int l = 0; l < 4; l++) mkpal(P_NOTE + l, RGB(0x0E1428), WHITE, mix(WHITE, lanec[l], 14), mix(0, lanec[l], 6));
+ mkpal(P_MISS, RGB(0x0E1428), RGB(0x6E7890), RGB(0x58627A), RGB(0x363E52));
+}
+
+/* the arrow for a lane (left, down, up, right), 30 pixels, centred on (cx, cy) */
+static void arrow(int dir, int cx, int cy, const color *pl, int a) {
+ int x0 = cx - AN, y0 = cy - AN;
+ if (x0 >= bx + bw || x0 + 2 * AN <= bx || y0 >= by + bh || y0 + 2 * AN <= by) return;
+ for (int j = 0; j < AN; j++)
+ for (int i = 0; i < AN; i++) {
+ int v = spr[dir == 2 ? j * AN + i : dir == 1 ? (AN - 1 - j) * AN + i : dir == 0 ? i * AN + j : (AN - 1 - i) * AN + j];
+ if (v) rect(x0 + 2 * i, y0 + 2 * j, 2, 2, pl[v], a);
}
- }
}
+/* dancers: art begin (made by tools/dancers.py from its pixel maps, 4 bits a pixel) */
+#define DPN 7 /* colors in a palette */
+static const uint32_t DPAL[4][DPN] = {
+ {0xC3CEDA, 0x7C8C9F, 0x2E3A4C, 0x15202E, 0x5FF3FF, 0xFF5A5A, 0xFFD23F},
+ {0xF28C38, 0xB85A1C, 0xFFF4E6, 0x2B1D1A, 0x2EC4B6, 0x000000, 0x000000},
+ {0x1E2433, 0xF4F8FF, 0xFFA62B, 0xE84A5F, 0x46547A, 0x000000, 0x000000},
+ {0x5CC25A, 0x2E8B3E, 0xD4F5A3, 0xFFFFFF, 0x1E2433, 0xFF5A7A, 0x000000},
+};
+static const struct { uint8_t w, h; uint16_t off; } DSPR[4] = {{16, 23, 0}, {14, 21, 184}, {14, 19, 331}, {14, 19, 464}};
+static const uint8_t DPIX[597] = {
+ 0x00,0x00,0x00,0x60,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x10,0x11,0x11,0x11,0x11,0x01,0x00,
+ 0x00,0x11,0x44,0x44,0x44,0x44,0x11,0x00,0x00,0x11,0x54,0x45,0x54,0x45,0x11,0x00,0x00,0x11,0x44,0x44,0x44,0x44,0x11,0x00,
+ 0x00,0x10,0x11,0x11,0x11,0x11,0x01,0x00,0x00,0x10,0x12,0x12,0x12,0x12,0x01,0x00,0x00,0x00,0x20,0x22,0x22,0x02,0x00,0x00,
+ 0x00,0x00,0x11,0x11,0x11,0x11,0x00,0x00,0x00,0x10,0x11,0x11,0x11,0x11,0x01,0x00,0x00,0x10,0x31,0x33,0x33,0x13,0x01,0x00,
+ 0x00,0x10,0x31,0x37,0x36,0x15,0x01,0x00,0x00,0x10,0x31,0x33,0x33,0x13,0x01,0x00,0x00,0x10,0x11,0x11,0x11,0x11,0x01,0x00,
+ 0x00,0x00,0x11,0x11,0x11,0x11,0x00,0x00,0x00,0x00,0x22,0x22,0x22,0x22,0x00,0x00,0x00,0x00,0x20,0x02,0x20,0x02,0x00,0x00,
+ 0x00,0x00,0x10,0x01,0x10,0x01,0x00,0x00,0x00,0x00,0x10,0x01,0x10,0x01,0x00,0x00,0x00,0x00,0x20,0x02,0x20,0x02,0x00,0x00,
+ 0x00,0x00,0x11,0x01,0x10,0x11,0x00,0x00,0x00,0x00,0x33,0x03,0x30,0x33,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x40,0x00,0x00,
+ 0x41,0x00,0x00,0x00,0x14,0x00,0x00,0x11,0x04,0x00,0x40,0x11,0x00,0x00,0x11,0x11,0x11,0x11,0x11,0x00,0x10,0x11,0x11,0x11,
+ 0x11,0x11,0x01,0x10,0x41,0x11,0x11,0x11,0x14,0x01,0x10,0x11,0x31,0x33,0x13,0x11,0x01,0x00,0x31,0x33,0x44,0x33,0x13,0x00,
+ 0x00,0x30,0x33,0x33,0x33,0x03,0x00,0x00,0x00,0x33,0x33,0x33,0x00,0x00,0x00,0x00,0x50,0x55,0x05,0x00,0x00,0x00,0x00,0x55,
+ 0x55,0x55,0x00,0x00,0x00,0x00,0x11,0x33,0x11,0x00,0x00,0x00,0x10,0x11,0x33,0x11,0x01,0x30,0x00,0x10,0x11,0x33,0x11,0x01,
+ 0x31,0x00,0x10,0x11,0x33,0x11,0x11,0x01,0x00,0x00,0x11,0x11,0x11,0x11,0x00,0x00,0x00,0x22,0x00,0x22,0x00,0x00,0x00,0x00,
+ 0x11,0x00,0x11,0x00,0x00,0x00,0x00,0x11,0x00,0x11,0x00,0x00,0x00,0x40,0x44,0x00,0x44,0x04,0x00,0x00,0x00,0x10,0x11,0x01,
+ 0x00,0x00,0x00,0x10,0x11,0x11,0x11,0x01,0x00,0x00,0x11,0x11,0x11,0x11,0x11,0x00,0x00,0x21,0x12,0x11,0x21,0x12,0x00,0x00,
+ 0x21,0x21,0x11,0x12,0x12,0x00,0x00,0x21,0x22,0x33,0x22,0x12,0x00,0x00,0x11,0x32,0x33,0x23,0x11,0x00,0x00,0x11,0x11,0x33,
+ 0x11,0x11,0x00,0x00,0x10,0x11,0x11,0x11,0x01,0x00,0x00,0x11,0x42,0x44,0x24,0x11,0x00,0x00,0x11,0x22,0x44,0x22,0x11,0x00,
+ 0x10,0x21,0x22,0x22,0x22,0x12,0x01,0x10,0x21,0x22,0x22,0x22,0x12,0x01,0x10,0x21,0x22,0x22,0x22,0x12,0x01,0x10,0x21,0x22,
+ 0x22,0x22,0x12,0x01,0x00,0x11,0x22,0x22,0x22,0x11,0x00,0x00,0x10,0x21,0x22,0x12,0x01,0x00,0x00,0x00,0x11,0x11,0x11,0x00,
+ 0x00,0x00,0x30,0x33,0x00,0x33,0x03,0x00,0x00,0x11,0x01,0x00,0x10,0x11,0x00,0x10,0x44,0x14,0x00,0x41,0x44,0x01,0x10,0x54,
+ 0x14,0x00,0x41,0x45,0x01,0x10,0x11,0x11,0x11,0x11,0x11,0x01,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
+ 0x11,0x11,0x21,0x11,0x11,0x11,0x11,0x11,0x12,0x10,0x22,0x22,0x22,0x22,0x22,0x01,0x00,0x11,0x11,0x11,0x11,0x11,0x00,0x00,
+ 0x60,0x66,0x66,0x66,0x06,0x00,0x00,0x11,0x33,0x33,0x33,0x11,0x00,0x00,0x11,0x33,0x33,0x33,0x11,0x00,0x00,0x11,0x33,0x33,
+ 0x33,0x11,0x00,0x00,0x11,0x33,0x33,0x33,0x11,0x00,0x00,0x10,0x31,0x33,0x13,0x01,0x00,0x00,0x00,0x11,0x11,0x11,0x00,0x00,
+ 0x00,0x10,0x11,0x00,0x11,0x01,0x00,0x00,0x11,0x11,0x00,0x11,0x11,0x00,0x20,0x22,0x02,0x00,0x20,0x22,0x02,
+};
+/* art end */
+
/* ------------------------------------------------------------------ text */
/* ASCII 32..95, columns of 7 bits, top bit first; lower case is drawn upper */
static const uint8_t font[64][5] = {
@@ -226,8 +243,8 @@ static void item(const char *t, int cx, int y, bool on) {
ctext(t, cx, y, 2, on ? 2 : 1, on ? WHITE : RGB(0x8A82A8), on ? RGB(0xFFE070) : RGB(0x6A6288));
if (on) {
int d = tw(t, 2) / 2 + 20;
- arrow(3, cx - d, y + 6, 0, pal[P_NOTE + 3], 32);
- arrow(0, cx + d, y + 6, 0, pal[P_NOTE], 32);
+ arrow(3, cx - d, y + 6, pal[P_NOTE + 3], 32);
+ arrow(0, cx + d, y + 6, pal[P_NOTE], 32);
}
}
@@ -312,7 +329,7 @@ typedef struct {
int32_t key;
uint8_t wait; /* frames the stage has been kept waiting */
} watch_t;
-#define NW 26 /* 0-11 the play screen or menus, 12-19 and 24-25 the stage, 20-23 the rest */
+#define NW 29 /* 0-11 the play screen or menus, 12-19 and 24-28 the stage, 20-23 the rest */
static watch_t wt[NW];
static void watch(int i, int x, int y, int w, int h, int32_t key) {
watch_t *o = &wt[i];
@@ -352,7 +369,7 @@ static void load(void) {
}
} else {
zero(&S, sizeof S);
- S.speed = 2, S.diff = 1;
+ S.speed = 2, S.diff = 1, S.nofail = 1; /* like Champion Island: misses only cost points */
}
}
static void save(void) {
@@ -533,7 +550,7 @@ static void gen_bar(void) {
if (brk) m = d >= 2 ? 0x0101 : 1;
G.fam = type == BUILD ? STAIRS : crand() % 3 ? (style & 7) : (int)(crand() % 5);
G.ta = (int)(crand() & 3), G.tb = (G.ta + 1 + (int)(crand() % 3)) & 3, G.shape = (int)(crand() & 3), G.idx = 0;
- int holdp = (style >> 3 & 3) + (brk ? 8 : 0);
+ int holdp = 0; /* all taps, like Champion Island's */
int jumpp = type == CHORUS || type == DROP ? (style >> 5 & 3) + 1 + (d == 3) : type == VERSE ? (style >> 5 & 3) / 2 : 0;
int steps[17], ns = 0, prev = -8;
for (int k = 0; k < 16; k++)
@@ -633,110 +650,188 @@ static int ud(void) { return pressed(eadk_key_down) - pressed(eadk_key_up); }
static int lr(void) { return pressed(eadk_key_right) - pressed(eadk_key_left); }
/* ------------------------------------------------------------------ the stage */
-static color bgrow[H], lanerow[H];
-
+/* A city rooftop at night, in pixel art: the sky from deep blue to teal, the
+ moon, stars that twinkle on the beat, clouds going by, the city behind with
+ its lit windows and red lights on two masts, and the crew on the roof.
+ Misses turn the sky red (tint 0 to 4). */
+#define FEET 198 /* where the crew stands */
+#define ROOF 186 /* where the roof starts */
+static color bgrow[H];
+static int tint;
static void make_stage(void) {
for (int y = 0; y < H; y++) {
- color c = y < 212 ? mix(RGB(0x331552), RGB(0x0A0514), y * 32 / 212) : y == 212 ? RGB(0x6E48A8) : mix(RGB(0x0C0714), RGB(0x2A1A40), (y - 213) * 32 / 27);
+ color c = y < ROOF ? mix(RGB(0x1E5A6E), RGB(0x0A1030), y * 32 / ROOF) : y == ROOF ? RGB(0x5A667E)
+ : mix(RGB(0x1A2130), RGB(0x2C3446), (y - ROOF) * 32 / (H - ROOF));
+ if (tint && y < ROOF) c = mix(RGB(0xC8203A), c, tint * 5);
bgrow[y] = c;
- lanerow[y] = mix(RGB(0x05030A), c, 21);
}
}
-/* a speaker cone in one pass: rim, surround, cone, dust cap and its shine */
-static void cone(int cx, int cy, int r, int glow) {
- int R = r + 3, x0 = maxi(cx - R, bx), x1 = mini(cx + R + 1, bx + bw), y0 = maxi(cy - R, by), y1 = mini(cy + R + 1, by + bh);
- int cap = (r / 3 + 1) * (r / 3 + 1), in = (r - 1) * (r - 1), out = (r + 1) * (r + 1), fold = r * r * 4 / 9;
- int grad = (26 << 16) / (in - cap), hl = r / 7 + 1;
- color sur = mix(RGB(0x6E62A0), RGB(0x2B2440), glow), body = mix(RGB(0x544A80), RGB(0x2A2340), glow);
- color capc = mix(RGB(0xA89EDA), RGB(0x585080), glow);
- for (int y = y0; y < y1; y++)
- for (int x = x0; x < x1; x++) {
- int dx = x - cx, dy = y - cy, d = dx * dx + dy * dy;
- if (d > R * R) continue;
- color c = d > out ? RGB(0x07050B) : d > in ? sur : d > cap ? mix(RGB(0x100C18), body, (d - cap) * grad >> 16) : capc;
- if (iabs(d - fold) < 2 * r) c = mix(0, c, 12);
- if ((dx + r / 9) * (dx + r / 9) + (dy + r / 9) * (dy + r / 9) <= hl * hl) c = mix(WHITE, c, 18);
- buf[(y - by) * bw + x - bx] = c;
+static int beat_n, beat_ph, beat_type, rbeat;
+static void pulses(void) { rbeat = beat_ph < 120 && beat_n >= 0; }
+
+/* the crew: the robot, the fox, the penguin and the frog */
+static const int16_t DX[4] = {10, 56, 236, 280};
+static int dancer_y(int k) { return FEET - DSPR[k].h * 2 - rbeat * 2; }
+/* a move for each beat, arm by arm: 0 up, 1 out, 2 down; all in step */
+static int move_of(int k, int side) {
+ static const uint8_t M[4][2] = {{0, 0}, {1, 1}, {0, 2}, {2, 0}};
+ return beat_n < 0 ? 2 : M[(beat_n + (k & 1)) & 3][side];
+}
+static void dancer(int k) {
+ /* the left shoulder (x, y), the arm's length, its color and the hand's (palette indices) */
+ static const int8_t ARM[4][5] = {{3, 10, 6, 1, 2}, {4, 12, 5, 1, 4}, {2, 10, 5, 5, 5}, {2, 10, 5, 1, 3}};
+ static const int8_t PATH[3][6][2] = {
+ {{-1, -1}, {-1, -2}, {-2, -3}, {-2, -4}, {-2, -5}, {-3, -6}},
+ {{-1, 0}, {-2, 0}, {-3, -1}, {-4, -1}, {-5, -2}, {-6, -2}},
+ {{-1, 1}, {-1, 2}, {-2, 3}, {-2, 4}, {-2, 5}, {-2, 6}},
+ };
+ int w = DSPR[k].w, h = DSPR[k].h, x0 = DX[k], y0 = dancer_y(k);
+ if (x0 - 16 >= bx + bw || x0 + 2 * w + 16 <= bx || y0 - 16 >= by + bh || y0 + 2 * h <= by) return;
+ const uint8_t *px = DPIX + DSPR[k].off;
+ color c[DPN + 1];
+ for (int i = 0; i < DPN; i++) c[i + 1] = RGB(DPAL[k][i]);
+ for (int j = 0, n = 0; j < h; j++)
+ for (int i = 0; i < w; i++, n++) {
+ int v = px[n >> 1] >> (n & 1) * 4 & 15;
+ if (v) rect(x0 + 2 * i, y0 + 2 * j, 2, 2, c[v], 32);
+ }
+ const int8_t *a = ARM[k];
+ for (int s = 0; s < 2; s++) {
+ int sx = s ? w - 1 - a[0] : a[0], m = move_of(k, s);
+ for (int i = 0; i < a[2]; i++) {
+ int ax = sx + (s ? -PATH[m][i][0] : PATH[m][i][0]), ay = a[1] + PATH[m][i][1];
+ rect(x0 + 2 * ax - s, y0 + 2 * ay, 3, 3, c[i == a[2] - 1 ? a[4] : a[3]], 32); /* 3 pixels thick */
}
+ }
}
-/* what the beat does to the stage, a frame apart so it doesn't all repaint at once */
-static int beat_n, beat_ph, beat_type, spk, bop, rbeat;
-static uint8_t lamp[4];
-static void pulses(void) {
- spk = beat_ph >= 16 && beat_ph < 116 ? 2 : 0;
- bop = beat_ph >= 33 && beat_ph < 133 ? 2 : 0;
- rbeat = beat_ph < 90;
- for (int l = 0; l < 4; l++) /* the beat's lamp flashes; in a chorus the others stay on */
- lamp[l] = (uint8_t)((beat_n & 3) == l ? (beat_ph < 150 ? 2 : beat_ph < 300) : beat_type == CHORUS || beat_type == DROP);
+/* the city: tall buildings far away, lower ones near, with windows */
+typedef struct {
+ int16_t x;
+ uint8_t w, top;
+} bld_t;
+static const bld_t FAR[14] = {{0, 26, 124}, {22, 20, 100}, {40, 30, 132}, {66, 18, 108}, {80, 36, 120}, {112, 24, 96}, {132, 30, 128},
+ {158, 22, 104}, {176, 34, 122}, {206, 20, 100}, {222, 28, 130}, {246, 24, 110}, {266, 32, 126}, {294, 26, 102}};
+static const bld_t NEAR[13] = {{-4, 30, 150}, {24, 22, 160}, {44, 26, 142}, {68, 30, 154}, {96, 20, 146}, {114, 34, 162}, {146, 24, 140},
+ {168, 28, 156}, {194, 22, 148}, {214, 32, 164}, {244, 26, 144}, {268, 24, 158}, {290, 34, 150}};
+static const uint8_t MAST[2] = {1, 13}; /* the far buildings with a mast and a red light */
+static int mast_on(int i) { return beat_n >= 0 && (beat_n & 1) == i && beat_ph < 250; }
+static void city(void) {
+ if (by + bh <= 84 || by >= ROOF) return;
+ for (int i = 0; i < 14; i++) {
+ const bld_t *b = &FAR[i];
+ rect(b->x, b->top, b->w, ROOF - b->top, RGB(0x17263F), 32);
+ for (int y = b->top + 5; y < ROOF - 30; y += 7) /* a few dim windows */
+ for (int x = b->x + 3; x + 1 < b->x + b->w - 2; x += 6)
+ if (((x * 7 + y * 3) & 15) < 3) rect(x, y, 2, 2, RGB(0x6C7FA8), 32);
+ }
+ for (int i = 0; i < 2; i++) {
+ const bld_t *b = &FAR[MAST[i]];
+ int mx = b->x + b->w / 2;
+ rect(mx, b->top - 14, 1, 14, RGB(0x17263F), 32);
+ rect(mx - 1, b->top - 17, 3, 3, mast_on(i) ? RGB(0xFF4050) : RGB(0x5A2030), 32);
+ }
+ for (int i = 0; i < 13; i++) {
+ const bld_t *b = &NEAR[i];
+ rect(b->x, b->top, b->w, ROOF - b->top, RGB(0x0B1424), 32);
+ rect(b->x, b->top, b->w, 1, RGB(0x223452), 32); /* the edge of its roof */
+ for (int y = b->top + 5; y + 3 < ROOF; y += 7)
+ if (y + 3 > by && y < by + bh)
+ for (int x = b->x + 3; x + 2 < b->x + b->w - 1; x += 5) {
+ unsigned hsh = (unsigned)(x * 73 + y * 151) * 2654435761u >> 28;
+ rect(x, y, 2, 3, hsh < 5 ? RGB(0xFFC857) : hsh < 7 ? RGB(0xF28C5A) : RGB(0x16223A), 32);
+ }
+ }
}
-/* LED bars on the floor: they jump on the beat and fall */
-static int vu(int i) {
- int top = 3 + (int)(((uint32_t)(beat_n * 12 + i) * 2654435761u >> 28) % 5);
- return clamp(top - beat_ph / 60, 1, 7);
+/* the moon, and clouds going by */
+static void moon(void) {
+ if (by > 76 || bx > 84) return;
+ disc(54, 48, 24, 0, RGB(0xF4EFD6), 4); /* its glow */
+ disc(54, 48, 15, 0, RGB(0xF4EFD6), 32);
+ disc(49, 44, 4, 0, RGB(0xDCD4B4), 32);
+ disc(59, 53, 3, 0, RGB(0xDCD4B4), 32);
+ disc(58, 40, 2, 0, RGB(0xDCD4B4), 32);
+}
+static int cloud_x(int k) { int t = (int)(now / 45 + (uint32_t)k * 211) % 440 - 60; return k ? 380 - t : t; }
+static int cloud_y(int k) { return 26 + 44 * k; }
+static void cloud(int k) {
+ int x = cloud_x(k), y = cloud_y(k);
+ if (x - 36 >= bx + bw || x + 36 <= bx || y - 12 >= by + bh || y + 10 <= by) return;
+ color c = RGB(0x3A5A7E);
+ rect(x - 30, y + 2, 60, 6, c, 12);
+ rect(x - 22, y - 4, 30, 6, c, 12);
+ rect(x - 4, y - 8, 22, 10, c, 12);
+}
+
+/* stars: some twinkle on the beat */
+static const int16_t STAR[12][2] = {{96, 14}, {130, 40}, {150, 8}, {182, 30}, {214, 12}, {252, 44}, {300, 20},
+ {18, 90}, {104, 64}, {204, 72}, {272, 80}, {10, 22}};
+static int star_s(int i) { return i >= 5 ? 0 : 1 + ((beat_n + i * 3) & 3) - (beat_ph > 250); }
+static void stars(void) {
+ for (int i = 0; i < 12; i++) {
+ int x = STAR[i][0], y = STAR[i][1], z = star_s(i);
+ if (x + 5 < bx || x - 5 >= bx + bw || y + 5 < by || y - 5 >= by + bh) continue;
+ if (z <= 0) {
+ rect(x, y, 1, 1, RGB(0xC8D6F0), 32);
+ continue;
+ }
+ rect(x - z, y, 2 * z + 1, 1, RGB(0xFFF4C8), 32);
+ rect(x, y - z, 1, 2 * z + 1, RGB(0xFFF4C8), 32);
+ rect(x - 1, y - 1, 3, 3, WHITE, 20);
+ }
}
-/* lamps sit in the middle of 40-pixel columns: a flash repaints just those */
-static int lamp_x(int l) { return 20 + 40 * l + (l >> 1) * 160; }
+/* the roof: seams in the concrete, and a vent or two */
+static void roof(void) {
+ if (by + bh <= ROOF) return;
+ for (int y = ROOF + 14; y < H; y += 18) rect(0, y, W, 1, RGB(0x3A4458), 32);
+ for (int i = 0; i < 2; i++) {
+ int x = i ? 290 : 4;
+ rect(x, ROOF + 18, 24, 14, RGB(0x6A7488), 32);
+ rect(x, ROOF + 18, 24, 2, RGB(0x8A94A8), 32);
+ for (int k = 0; k < 4; k++) rect(x + 3 + k * 5, ROOF + 22, 3, 8, RGB(0x3A4458), 32);
+ }
+}
-/* the stage: a back wall, a floor with LED bars, a speaker each side, four lamps */
+/* the lanes, dark glass over the city, and their targets */
+static int lane_x(int l) { return 111 + 33 * l; }
static void stage(bool lanes_on) {
- int a = lanes_on ? clamp(80 - bx, 0, bw) : bw, b = lanes_on ? clamp(240 - bx, 0, bw) : bw;
- for (int j = 0; j < bh; j++) {
- color *p = buf + j * bw, c = bgrow[by + j];
- fill(p, a, c);
- fill(p + a, b - a, lanerow[by + j]);
- fill(p + b, bw - b, c);
- }
- for (int s = 0; s < 2; s++) {
- int cx = s ? 280 : 40;
- if (bx >= cx + 32 || bx + bw <= cx - 32) continue;
- rect(cx - 30, 102, 60, 111, RGB(0x2E2742), 32);
- rect(cx - 28, 104, 56, 107, RGB(0x17131F), 32);
- rect(cx - 30, 102, 60, 1, RGB(0x4A3F66), 32);
- cone(cx, 132, 12 + spk / 2, spk * 12);
- cone(cx, 180, 20 + spk, spk * 12);
- for (int i = 0; i < 6; i++)
- for (int k = 0, n = vu(s * 6 + i); k < n; k++)
- rect(cx - 27 + i * 9, 234 - k * 3, 7, 2, k > 5 ? RGB(0xFF3B4A) : k > 3 ? RGB(0xFFD23A) : RGB(0x3BE37A), 32);
- }
- /* lamps on a bar: the one of this beat is lit, all of them in a chorus */
- rect(0, 0, 80, 5, RGB(0x2A2A36), 32);
- rect(240, 0, 80, 5, RGB(0x2A2A36), 32);
- for (int l = 0; l < 4; l++) {
- int lx = lamp_x(l), lv = lamp[l];
- if (bx >= lx + 22 || bx + bw <= lx - 22) continue;
- if (lv) /* the beam */
- for (int y = maxi(by, 12); y < mini(by + bh, 100); y++) {
- int hw = 2 + (y - 12) / 5;
- rect(lx - hw, y, 2 * hw + 1, 1, lanec[l], (100 - y) * lv / 22);
- }
- disc(lx, 9, 7, 0, RGB(0x15141C), 32);
- disc(lx, 10, 4, 0, lv ? mix(WHITE, lanec[l], lv == 2 ? 16 : 4) : mix(0, lanec[l], 22), 32);
- }
+ for (int j = 0; j < bh; j++) fill(buf + j * bw, bw, bgrow[by + j]);
+ moon();
+ stars();
+ for (int k = 0; k < 2; k++) cloud(k);
+ city();
+ roof();
+ for (int k = 0; k < 4; k++) dancer(k);
if (lanes_on)
- for (int k = 0; k < 5; k++) rect(80 + 40 * k - (k == 4), 0, 1, H, WHITE, k % 4 ? 2 : 4);
+ for (int l = 0; l < 4; l++) {
+ int x0 = lane_x(l) - 15;
+ if (x0 >= bx + bw || x0 + 30 <= bx) continue;
+ rect(x0, by, 30, bh, RGB(0x05070F), 17);
+ rect(x0, by, 1, bh, lanec[l], 12), rect(x0 + 29, by, 1, bh, lanec[l], 12);
+ }
}
static void stage_watches(void) {
pulses();
- for (int s = 0; s < 2; s++) {
- int cx = s ? 280 : 40;
- watch(16 + s * 2, cx - 26, 154, 52, 52, spk);
- watch(17 + s * 2, cx - 17, 115, 34, 34, spk);
- int key = 0;
- for (int i = 0; i < 6; i++) key = key << 3 | vu(s * 6 + i);
- watch(24 + s, cx - 27, 214, 54, 22, key);
+ for (int k = 0; k < 4; k++) {
+ int w = DSPR[k].w * 2, h = DSPR[k].h * 2;
+ watch(12 + k, DX[k] - 16, FEET - h - 16, w + 32, h + 16, move_of(k, 0) | move_of(k, 1) << 2 | rbeat << 4);
}
- for (int l = 0; l < 4; l++) watch(12 + l, lamp_x(l) - 20, 0, 40, 100, lamp[l]);
+ for (int k = 0; k < 2; k++) watch(16 + k, cloud_x(k) - 36, cloud_y(k) - 12, 72, 22, cloud_x(k));
+ for (int i = 0; i < 2; i++) {
+ const bld_t *b = &FAR[MAST[i]];
+ watch(18 + i, b->x + b->w / 2 - 1, b->top - 17, 3, 3, mast_on(i));
+ }
+ for (int i = 0; i < 5; i++) watch(24 + i, STAR[i][0] - 5, STAR[i][1] - 5, 11, 11, star_s(i));
}
/* ------------------------------------------------------------------ playing */
#define WIN 140 /* later than this, a note is missed */
-static const char *const judge_name[4] = {"Perfect", "Great", "Good", "Miss"};
-static const color judge_c[4][2] = {{RGB(0xFFF4A8), RGB(0xFFA800)}, {RGB(0xC6FFB0), RGB(0x2BD35A)}, {RGB(0x9FE8FF), RGB(0x2E7BFF)}, {RGB(0xFFB0B8), RGB(0xE0203A)}};
+static const char *const judge_name[3] = {"Perfect!", "Good!", "Miss"};
+static const color judge_c[3][2] = {{RGB(0xFFF0A0), RGB(0xFFA92E)}, {RGB(0xC4FFF6), RGB(0x2EC4B6)}, {RGB(0xFFC4C4), RGB(0xE84A5F)}};
static struct {
int32_t t0; /* millis at song time 0 */
@@ -753,7 +848,6 @@ static int info_notes, info_len;
static int pxms(void) { return (2 + S.speed) * 31 / 2; } /* 1/256 pixel per ms */
static int note_y(int32_t dt) { return P.ry - P.sgn * (int)(dt * P.pxms >> 8); }
-static int lane_x(int l) { return 100 + 40 * l; }
static bool gone(int y) { return P.sgn > 0 ? y > H + 24 : y < -24; }
static bool not_yet(int y) { return P.sgn > 0 ? y < -24 : y > H + 24; }
@@ -772,12 +866,13 @@ static void note_mark_all(const note_t *n) {
static void start_song(void) {
int song = S.song, d = S.diff;
zero(&P, sizeof P);
- P.song = song, P.d = d, P.health = 500;
+ P.song = song, P.d = d, P.health = 1000;
+ if (tint) tint = 0, make_stage();
gen_start(song, d);
gen_bar(); /* the first bar gives the beat of the count-in */
P.pxms = pxms();
P.sgn = S.up ? -1 : 1;
- P.ry = S.up ? 40 : 200;
+ P.ry = S.up ? 44 : 204;
P.ahead = 250 * 256 / P.pxms;
int beat = 60000 / G.bpm, lead = maxi(4, (P.ahead + 300) / beat + 1) * beat;
P.t = P.pt = -lead;
@@ -792,16 +887,16 @@ static void start_song(void) {
static void judge_show(int k, int late) {
P.jk = k, P.late = late, P.jt = now;
- if (k < 3) P.combo++, P.ct = now;
+ if (k < 2) P.combo++, P.ct = now;
else P.combo = 0;
P.maxc = maxi(P.maxc, P.combo);
}
+/* Champion Island's points: Perfect! 100, Good! 50, a miss -5 (never below 0) */
static void hit_note(note_t *n, int d) {
- static const int16_t pts[3] = {350, 200, 100}, hp[3] = {20, 14, 5}, acc[3] = {100, 75, 40};
- int ad = iabs(d), k = ad <= 45 ? 0 : ad <= 90 ? 1 : 2;
- P.cnt[k]++, P.judged++, P.acc += acc[k], P.score += pts[k];
- P.health = mini(P.health + hp[k], 1000);
+ int ad = iabs(d), k = ad > 60;
+ P.cnt[k]++, P.judged++, P.acc += k ? 50 : 100, P.score += k ? 50 : 100;
+ P.health = mini(P.health + (k ? 10 : 20), 1000);
judge_show(k, k ? (d > 0 ? 2 : 1) : 0);
P.ht[n->lane] = now, P.hk[n->lane] = k;
note_mark_all(n);
@@ -809,9 +904,9 @@ static void hit_note(note_t *n, int d) {
}
static void miss(void) {
- P.cnt[3]++, P.judged++;
- P.health -= P.d ? 40 : 25; /* a dozen misses in a row from the start fail a song */
- judge_show(3, 0);
+ P.cnt[2]++, P.judged++, P.score = maxi(P.score - 5, 0);
+ P.health -= 60; /* the sky reddens; with No-fail off, some 17 misses in a row fail a song */
+ judge_show(2, 0);
}
static void press_lane(int l, int32_t tp) {
@@ -835,8 +930,8 @@ static void end_hold(note_t *n, int32_t tr) {
P.ht[n->lane] = now;
} else { /* let go: the rest of the trail goes gray */
n->len = (uint16_t)(n->t + n->len - tr), n->t = tr, n->st = N_DROP;
- P.cnt[3]++, P.judged++, P.health -= 25;
- judge_show(3, 0);
+ P.cnt[2]++, P.judged++, P.health -= 25;
+ judge_show(2, 0);
note_mark_all(n);
}
}
@@ -864,6 +959,10 @@ static void play_update(void) {
nev = 0;
bool left = false;
P.held_mask = 0;
+#ifdef AUTOPLAY /* a test build that plays by itself, not always perfectly */
+ for (int i = nt; i != nh; i = (i + 1) & (NR - 1))
+ if (notes[i].st == N_WAIT && tj - notes[i].t >= (int)(notes[i].t % 7) * 12 - 20) hit_note(&notes[i], (int)(tj - notes[i].t));
+#endif
for (int i = nt; i != nh; i = (i + 1) & (NR - 1)) {
note_t *n = &notes[i];
if (n->st == N_WAIT && tj - n->t > WIN) {
@@ -884,13 +983,8 @@ static void play_update(void) {
if (n->st == N_DONE || (n->st >= N_MISS && gone(note_y(n->t + n->len - P.t)))) nt = (nt + 1) & (NR - 1);
else break;
}
- /* beat lines */
- for (int i = maxi(0, nbars - 8); i < nbars; i++)
- for (int k = i ? 0 : -8; k < 4; k++) {
- int32_t tb = (bars[i & 7].t16 + k * bars[i & 7].beat16) >> 4;
- mark(80, note_y(tb - P.t), 160, 1);
- mark(80, note_y(tb - P.pt), 160, 1);
- }
+ int t = P.health >= 800 ? 0 : P.health >= 600 ? 1 : P.health >= 400 ? 2 : P.health >= 200 ? 3 : 4;
+ if (t != tint) tint = t, make_stage(), mark_all(); /* the sky reddens, or clears */
if (P.health <= 0) {
P.health = 0;
if (!S.nofail || !G.s) P.failed = true;
@@ -902,121 +996,68 @@ static void play_update(void) {
static void play_watches(void) {
for (int l = 0; l < 4; l++) {
int age = (int)(now - P.ht[l]), x = lane_x(l);
- int key = age < 160 || (P.held_mask >> l & 1) ? (age < 50 ? 3 : 2) | 8 : lanes >> l & 1 ? 16 : 1 + rbeat;
- watch(l, x - 20, P.ry - 20, 40, 40, key);
- watch(4 + l, x - 30, P.ry - 30, 60, 60, age < 170 && !P.hk[l] ? age / 34 : -1);
+ watch(l, x - 15, P.ry - 15, 30, 30, age < 160 ? 8 | P.hk[l] : lanes >> l & 1 ? 16 : 1);
+ watch(4 + l, x - 24, P.ry - 24, 48, 48, age < 200 && !P.hk[l] ? age / 40 : -1);
}
- int ja = (int)(now - P.jt), jy = S.up ? 118 : 96;
- char s[12];
- int w = tw(judge_name[P.jk], 3) + 8;
- watch(8, 160 - w / 2, jy - 14, w, 42, ja < 500 ? P.jk | P.late << 2 | (ja < 50) << 4 : -1);
- num(s, (uint32_t)P.combo);
- w = maxi(tw(s, 4), 30) + 8;
- watch(9, 160 - w / 2, jy + 24, w, 46, P.combo >= 4 ? P.combo << 4 | (now - P.ct < 80) : -1);
- int hy = S.up ? 222 : 4, split = 62 + 196 * (1000 - P.health) / 1000;
- watch(23, split - 25, hy - 8, 50, 27, split | bop << 10 | (P.health < 200) << 12 | (P.health > 800) << 13); /* and the bar */
- watch(11, 60, S.up ? 206 : 26, 200, 11, P.score * 7 + P.cnt[3] * 131 + P.acc * 3 + P.judged);
+ int ja = (int)(now - P.jt), jy = S.up ? 120 : 40, w = tw(judge_name[P.jk], 2) + 8;
+ watch(8, 160 - w / 2, jy - 4, w, 24, ja < 500 ? P.jk | (ja < 60) << 4 : -1);
+ watch(9, 236, 26, 84, 34, P.combo >= 2 ? P.combo << 1 | (now - P.ct < 80) : -1);
+ watch(11, 200, 2, 120, 22, P.score);
int n, ty, ph = beat_at(P.t, &n, &ty);
watch(20, 60, 90, 200, 40, P.t < 0 && n >= -3 && ph < 300 ? n * 4 + (ph < 50) : -1);
}
static void draw_notes(void) {
- for (int pass = 0; pass < 2; pass++)
- for (int i = nt; i != nh; i = (i + 1) & (NR - 1)) {
- const note_t *n = &notes[i];
- int x = lane_x(n->lane), y = note_y(n->t - P.t);
- if (not_yet(y)) break;
- if (n->st == N_DONE || x + 20 <= bx || x - 20 >= bx + bw) continue;
- if (!pass && n->len) { /* the trail */
- int ya = n->st == N_HOLD ? P.ry : y, yb = note_y(n->t + n->len - P.t), y0 = mini(ya, yb), y1 = maxi(ya, yb);
- color c = n->st >= N_MISS ? RGB(0x34344A) : lanec[n->lane]; /* gray once missed */
- rect(x - 6, y0, 12, y1 - y0, INK, 32);
- rect(x - 4, y0, 8, y1 - y0, c, 32);
- rect(x - 2, y0, 2, y1 - y0, mix(WHITE, c, 8), 32);
- disc(x, yb, 6, 0, INK, 32);
- disc(x, yb, 4, 0, c, 32);
- }
- if (pass && (n->st == N_WAIT || n->st == N_MISS))
- arrow(n->lane, x, y, 1, pal[n->st == N_MISS ? P_MISS : P_NOTE + n->lane], n->st == N_MISS ? 18 : 32);
- }
-}
-
-
-static void icon(int cx, int cy, int r, color c, bool sad) {
- disc(cx, cy, r + 2, 0, INK, 32);
- disc(cx, cy, r, 0, c, 32);
- rect(cx - r / 2 - 1, cy - r / 3, 3, 4, INK, 32);
- rect(cx + r / 2 - 1, cy - r / 3, 3, 4, INK, 32);
- int m = cy + r / 3 + 1, e = sad ? 2 : -2; /* the mouth's corners go up or down */
- rect(cx - 3, m, 7, 2, INK, 32);
- rect(cx - 5, m + e, 2, 2, INK, 32);
- rect(cx + 4, m + e, 2, 2, INK, 32);
+ for (int i = nt; i != nh; i = (i + 1) & (NR - 1)) {
+ const note_t *n = &notes[i];
+ int x = lane_x(n->lane), y = note_y(n->t - P.t);
+ if (not_yet(y)) break;
+ if (n->st == N_WAIT || n->st == N_MISS) arrow(n->lane, x, y, pal[n->st == N_MISS ? P_MISS : P_NOTE + n->lane], n->st == N_MISS ? 18 : 32);
+ }
}
+/* the score and the combo in the corner, and a pause sign (Back pauses) */
static void hud(void) {
- char s[48], *o;
- /* the health bar, with the two singers' faces where the colours meet */
- int hy = S.up ? 222 : 4, split = 62 + 196 * (1000 - P.health) / 1000;
- if (by < hy + 20 && by + bh > hy - 6) {
- rect(60, hy, 200, 10, INK, 32);
- rect(62, hy + 2, split - 62, 6, RGB(0xFF2A3D), 32);
- rect(split, hy + 2, 258 - split, 6, RGB(0x57F23B), 32);
- rect(62, hy + 2, 196, 2, WHITE, 6);
- icon(split - 11, hy + 5, 9 + bop, RGB(0xB164E8), P.health > 800);
- icon(split + 11, hy + 5, 9 + bop, RGB(0x39B8E6), P.health < 200);
+ char s[16];
+ num(s, (uint32_t)P.score);
+ if (by < 22) text(s, 312 - tw(s, 2), 5, 2, 1, WHITE, RGB(0xC8D6F0));
+ if (P.combo >= 2 && by < 60 && by + bh > 26) {
+ int pop = now - P.ct < 80;
+ ctext("Combo", 278, 27, 1, 1, RGB(0xFFC857), 0);
+ num(s, (uint32_t)P.combo);
+ ctext(s, 278, 40 - pop, 2, 1, WHITE, RGB(0xC8D6F0));
}
- int sy = S.up ? 207 : 27;
- if (by < sy + 10 && by + bh > sy - 2) {
- o = cat(s, "Score ");
- o = num(o, (uint32_t)P.score);
- o = cat(o, " Misses ");
- o = num(o, (uint32_t)P.cnt[3]);
- o = cat(o, " ");
- if (P.judged) pct(o, P.acc * 100 / P.judged);
- else cat(o, "--%");
- small(s, 160, sy, WHITE);
+ if (by < 30 && bx < 30) {
+ rect(4, 4, 20, 20, INK, 20);
+ rect(9, 9, 3, 10, WHITE, 32), rect(16, 9, 3, 10, WHITE, 32);
}
}
static void scene_play(void) {
stage(true);
- /* beat lines, brighter at the start of a bar */
- for (int i = maxi(0, nbars - 8); i < nbars; i++)
- for (int k = i ? 0 : -8; k < 4; k++) {
- int y = note_y(((bars[i & 7].t16 + k * bars[i & 7].beat16) >> 4) - P.t);
- rect(81, y, 158, 1, WHITE, k ? 3 : 6);
- }
- /* the targets */
+ /* the targets: a ring in the lane's color, filled while its key is held,
+ lit up by a hit (brighter for a perfect one) */
for (int l = 0; l < 4; l++) {
int age = (int)(now - P.ht[l]), x = lane_x(l);
- if (age < 160 || (P.held_mask >> l & 1)) arrow(l, x, P.ry, age < 50 ? 3 : 2, pal[P_CONF + l], 32);
- else if (lanes >> l & 1) arrow(l, x, P.ry, 0, pal[P_PRESS + l], 32);
- else arrow(l, x, P.ry, 1 + rbeat, pal[rbeat ? P_BEAT : P_STRUM], 32);
- }
- /* the judgment and the combo */
- int ja = (int)(now - P.jt), jy = S.up ? 118 : 96;
- if (ja < 500) {
- int y = jy + (ja < 50) * 3;
- ctext(judge_name[P.jk], 160, y, 3, 2, judge_c[P.jk][0], judge_c[P.jk][1]);
- if (P.late) small(P.late == 2 ? "Late" : "Early", 160, y - 11, P.late == 2 ? RGB(0xFFB070) : RGB(0x80C8FF));
- }
- if (P.combo >= 4) {
- char s[12];
- num(s, (uint32_t)P.combo);
- int pop = now - P.ct < 80;
- ctext(s, 160, jy + 30 - pop * 2, 4, 2, WHITE, RGB(0xC8C8DC));
- small("Combo", 160, jy + 60, RGB(0xD8D8E8));
+ disc(x, P.ry, 14, 3, lanec[l], 32);
+ if (age < 160) disc(x, P.ry, 11, 0, mix(WHITE, lanec[l], P.hk[l] ? 8 : 20), 32);
+ else if (lanes >> l & 1) disc(x, P.ry, 11, 0, lanec[l], 14);
}
draw_notes();
- /* a splash on a perfect hit */
+ /* sparks off a perfect hit */
for (int l = 0; l < 4; l++) {
int age = (int)(now - P.ht[l]);
- if (age >= 170 || P.hk[l]) continue;
- age = age / 34 * 34; /* in five steps */
- int r = 16 + age / 14, a = 30 - age * 30 / 170, x = lane_x(l);
- disc(x, P.ry, r, 3 - age / 60, mix(WHITE, lanec[l], 12), a);
- for (int k = 0; k < 4; k++) disc(x + (k & 1 ? r : -r) * 3 / 4, P.ry + (k & 2 ? r : -r) * 3 / 4, 2, 0, WHITE, a);
+ if (age >= 200 || P.hk[l]) continue;
+ age = age / 40 * 40;
+ for (int k = 0; k < 8; k++) {
+ static const int8_t D[8][2] = {{-18, 0}, {18, 0}, {0, -18}, {0, 18}, {-13, -13}, {13, -13}, {-13, 13}, {13, 13}};
+ int r = 100 + age;
+ rect(lane_x(l) + D[k][0] * r / 200 - 1, P.ry + D[k][1] * r / 200 - 1, 3, 3, k & 4 ? WHITE : lanec[l], 32 - age * 32 / 200);
+ }
}
+ /* the judgment, above the lanes */
+ int ja = (int)(now - P.jt), jy = S.up ? 120 : 40;
+ if (ja < 500) ctext(judge_name[P.jk], 160, jy + (ja < 60) * 2, 2, 2, judge_c[P.jk][0], judge_c[P.jk][1]);
hud();
/* ready, set, go! on the beats before the song */
int n, ty, ph = beat_at(P.t, &n, &ty);
@@ -1090,7 +1131,7 @@ static void results(void) {
int acc = P.judged ? P.acc * 100 / P.judged : 0, ty;
beat_at(P.t, &grade_bars, &ty);
grade_bars /= 4;
- bool fc = !P.cnt[3] && !P.failed;
+ bool fc = !P.cnt[2] && !P.failed;
static const int16_t need[5] = {7000, 8000, 9000, 9500, 9900}; /* accuracy for C, B, A, S, S+ */
grade = 1;
while (grade < 6 && acc >= need[grade - 1] && (grade < 5 || fc)) grade++;
@@ -1120,19 +1161,19 @@ static void scene_results(void) {
disc(80, 94, 52, 4, gc, 32);
if (P.failed && G.s) ctext("Failed", 80, 87, 2, 2, RGB(0xFFB0B8), RGB(0xE0203A));
else ctext(grade_name[grade], 80, 66, 8, 3, gc, mix(0, gc, 9));
- if (!P.cnt[3] && !P.failed) small("Full combo!", 80, 156, RGB(0x9FE8FF));
+ if (!P.cnt[2] && !P.failed) small("Full combo!", 80, 156, RGB(0x9FE8FF));
if (!G.s) {
o = cat(s, "Bars: ");
num(o, (uint32_t)grade_bars);
small(s, 80, 172, WHITE);
}
- static const char *const lbl[6] = {"Perfect", "Great", "Good", "Miss", "Max combo", "Accuracy"};
- rect(160, 34, 150, 100, INK, 18);
- for (int i = 0; i < 6; i++) {
- int y = 40 + i * 16;
- text(lbl[i], 168, y, 1, 1, i < 4 ? judge_c[i][0] : WHITE, i < 4 ? judge_c[i][1] : 0);
- if (i == 5) pct(s, P.judged ? P.acc * 100 / P.judged : 0);
- else num(s, (uint32_t)(i < 4 ? P.cnt[i] : P.maxc));
+ static const char *const lbl[5] = {"Perfect!", "Good!", "Miss", "Max combo", "Accuracy"};
+ rect(160, 34, 150, 92, INK, 18);
+ for (int i = 0; i < 5; i++) {
+ int y = 42 + i * 17;
+ text(lbl[i], 168, y, 1, 1, i < 3 ? judge_c[i][0] : WHITE, i < 3 ? judge_c[i][1] : 0);
+ if (i == 4) pct(s, P.judged ? P.acc * 100 / P.judged : 0);
+ else num(s, (uint32_t)(i < 3 ? P.cnt[i] : P.maxc));
text(s, 302 - tw(s, 1), y, 1, 1, WHITE, 0);
}
small("Score", 235, 142, RGB(0xC8C8DC));
@@ -1160,7 +1201,7 @@ static void scene_title(void) {
static const char *const words[2] = {"Num", "Dance"};
for (int w = 0, i = 0; w < 2; w++) {
const char *s = words[w];
- int x = 160 - tw(s, 6) / 2, y = 14 + w * 50;
+ int x = 160 - tw(s, 6) / 2, y = 30 + w * 48;
for (int k = 0; s[k]; k++, i++) {
int p = beat_ph - i * 30, hop = p >= 0 && p < 160 ? (p < 60 ? p / 8 : (160 - p) * 7 / 100) : 0;
char c[2] = {s[k], 0};
@@ -1170,7 +1211,7 @@ static void scene_title(void) {
}
for (int l = 0; l < 4; l++) {
bool on = (menu_beat & 3) == l && beat_ph < 250;
- arrow(l, 100 + 40 * l, 134, on ? 3 : 1, pal[on ? P_CONF + l : P_STRUM], 32);
+ arrow(l, lane_x(l), 132 - on * 3, pal[on ? P_NOTE + l : P_MISS], 32);
}
static const char *const items[3] = {"Play", "Options", "How to play"};
for (int i = 0; i < 3; i++) item(items[i], 160, 166 + i * 24, sel == i);
@@ -1186,14 +1227,8 @@ static void scene_title(void) {
static void scene_songs(void) {
int song = S.song;
color c = songs[song].c;
- for (int j = 0; j < bh; j++) {
- int y = by + j;
- color *p = buf + j * bw;
- for (int i = 0; i < bw; i++) {
- int x = bx + i;
- p[i] = mix(c, RGB(0x0C0614), (((x + y * 2) >> 4) & 1 ? 11 : 9) - y * 7 / H);
- }
- }
+ stage(false);
+ rect(0, 0, W, H, RGB(0x1A0C33), 20);
for (int i = 0; i < NSONG; i++) {
int off = i * 16 - lpos, y = 128 + off * 34 / 16, x = 20 + iabs(off) / 2;
if (y < 56 || y > H) continue;
@@ -1260,15 +1295,16 @@ static void scene_help(void) {
heading("How to play", 10);
static const char *const keys[4] = {"Left 4 1", "Down 5 2", "Up 8 3", "Right 6 +"};
for (int l = 0; l < 4; l++) {
- arrow(l, 70 + 60 * l, 62, 1, pal[P_NOTE + l], 32);
+ arrow(l, 70 + 60 * l, 62, pal[P_NOTE + l], 32);
small(keys[l], 70 + 60 * l, 86, WHITE);
}
- static const char *const lines[6] = {"Press an arrow's key just as it", "reaches the gray target. Keep holding",
- "the key along a trail. Misses drain", "the health bar; empty, the song fails.",
- "Back: pause Home: quit", "The beat shows on the stage lights."};
- for (int i = 0; i < 6; i++) small(lines[i], 160, 110 + i * 14 + (i > 3) * 6, i > 3 ? RGB(0xB8B0D0) : WHITE);
- static const uint16_t jx[4] = {49, 143, 219, 289};
- for (int k = 0; k < 4; k++) ctext(judge_name[k], jx[k], 212, 2, 1, judge_c[k][0], judge_c[k][1]);
+ static const char *const lines[6] = {"Press an arrow's key just as it", "lands on its ring.",
+ "Misses cost 5 points and turn", "the sky red, little by little.",
+ "Back: pause Home: quit", "The crew shows the beat: dance along!"};
+ for (int i = 0; i < 6; i++) small(lines[i], 160, 110 + i * 14 + (i > 3) * 6, i > 3 ? RGB(0xE8D8F8) : WHITE);
+ static const uint16_t jx[3] = {70, 160, 250};
+ static const char *const pts[3] = {"+100", "+50", "-5"};
+ for (int k = 0; k < 3; k++) ctext(judge_name[k], jx[k], 200, 2, 1, judge_c[k][0], judge_c[k][1]), small(pts[k], jx[k], 220, WHITE);
}
/* calibration: an arrow every half second, press as it lands */
@@ -1279,11 +1315,12 @@ static void scene_calib(void) {
stage(false);
rect(0, 0, W, H, 0, 20);
rect(120, 0, 80, H, 0, 14);
- int t = (int)(now - cal_t0), ry = S.up ? 40 : 200, sgn = S.up ? -1 : 1, px = pxms(), beat = t % 500 < 90;
- arrow(2, 160, ry, 1 + beat, pal[beat ? P_BEAT : P_STRUM], 32);
+ int t = (int)(now - cal_t0), ry = S.up ? 44 : 204, sgn = S.up ? -1 : 1, px = pxms(), beat = t % 500 < 90;
+ disc(160, ry, 14, 0, WHITE, 32);
+ disc(160, ry, 11, 0, beat ? RGB(0x7CE85A) : RGB(0xEEE8F8), 32);
for (int k = t / 500 - 1; k <= t / 500 + 8; k++) {
int y = ry - sgn * ((k * 500 - t) * px >> 8);
- if (k >= 2) arrow(2, 160, y, 1, pal[P_NOTE + 2], 32);
+ if (k >= 2) arrow(2, 160, y, pal[P_NOTE + 2], 32);
}
ctext("Calibrate", 60, 10, 2, 1, WHITE, RGB(0xFFE070));
if (cal_n) {
diff --git a/games/numdance/tools/dancers.py b/games/numdance/tools/dancers.py
new file mode 100644
index 00000000..45c62851
--- /dev/null
+++ b/games/numdance/tools/dancers.py
@@ -0,0 +1,131 @@
+"""Packs NumDance's dancers (pixel maps, 4 bits a pixel) into C arrays for src/main.c:
+ python3 tools/dancers.py (paste its output between the art markers)
+Each map pixel is drawn 2x2 on the calculator. '.' is transparent."""
+SPRITES = [
+ ("the robot", {
+ 'M': 0xC3CEDA, 'm': 0x7C8C9F, 'D': 0x2E3A4C, 'V': 0x15202E, 'C': 0x5FF3FF, 'R': 0xFF5A5A, 'Y': 0xFFD23F,
+ }, [
+ ".......RR.......",
+ "........m.......",
+ "...MMMMMMMMMM...",
+ "..MMVVVVVVVVMM..",
+ "..MMVCCVVCCVMM..",
+ "..MMVVVVVVVVMM..",
+ "...MMMMMMMMMM...",
+ "...MmMmMmMmMM...",
+ ".....mmmmmm.....",
+ "....MMMMMMMM....",
+ "...MMMMMMMMMM...",
+ "...MMDDDDDDMM...",
+ "...MMDYDRDCMM...",
+ "...MMDDDDDDMM...",
+ "...MMMMMMMMMM...",
+ "....MMMMMMMM....",
+ "....mmmmmmmm....",
+ ".....mm..mm.....",
+ ".....MM..MM.....",
+ ".....MM..MM.....",
+ ".....mm..mm.....",
+ "....MMM..MMM....",
+ "....DDD..DDD....",
+ ]),
+ ("the fox", {
+ 'O': 0xF28C38, 'o': 0xB85A1C, 'W': 0xFFF4E6, 'K': 0x2B1D1A, 'G': 0x2EC4B6,
+ }, [
+ "..K........K..",
+ "..OK......KO..",
+ "..OOK....KOO..",
+ "..OOOOOOOOOO..",
+ ".OOOOOOOOOOOO.",
+ ".OOKOOOOOOKOO.",
+ ".OOOOWWWWOOOO.",
+ "..OWWWKKWWWO..",
+ "...WWWWWWWW...",
+ "....WWWWWW....",
+ ".....GGGG.....",
+ "....GGGGGG....",
+ "....OOWWOO....",
+ "...OOOWWOOO..W",
+ "...OOOWWOOO.OW",
+ "...OOOWWOOOOO.",
+ "....OOOOOOOO..",
+ "....oo..oo....",
+ "....OO..OO....",
+ "....OO..OO....",
+ "...KKK..KKK...",
+ ]),
+ ("the penguin", {
+ 'K': 0x1E2433, 'W': 0xF4F8FF, 'Y': 0xFFA62B, 'B': 0xE84A5F, 'k': 0x46547A, # k: the flippers
+ }, [
+ ".....KKKK.....",
+ "...KKKKKKKK...",
+ "..KKKKKKKKKK..",
+ "..KWWKKKKWWK..",
+ "..KWKWKKWKWK..",
+ "..KWWWYYWWWK..",
+ "..KKWYYYYWKK..",
+ "..KKKKYYKKKK..",
+ "...KKKKKKKK...",
+ "..KKWBBBBWKK..",
+ "..KKWWBBWWKK..",
+ ".KKWWWWWWWWKK.",
+ ".KKWWWWWWWWKK.",
+ ".KKWWWWWWWWKK.",
+ ".KKWWWWWWWWKK.",
+ "..KKWWWWWWKK..",
+ "...KKWWWWKK...",
+ "....KKKKKK....",
+ "...YYY..YYY...",
+ ]),
+ ("the frog", {
+ 'G': 0x5CC25A, 'g': 0x2E8B3E, 'L': 0xD4F5A3, 'W': 0xFFFFFF, 'K': 0x1E2433, 'R': 0xFF5A7A,
+ }, [
+ "..GGG....GGG..",
+ ".GWWWG..GWWWG.",
+ ".GWKWG..GWKWG.",
+ ".GGGGGGGGGGGG.",
+ "GGGGGGGGGGGGGG",
+ "GGGGGGGGGGGGGG",
+ "GgGGGGGGGGGGgG",
+ ".GggggggggggG.",
+ "..GGGGGGGGGG..",
+ "...RRRRRRRR...",
+ "..GGLLLLLLGG..",
+ "..GGLLLLLLGG..",
+ "..GGLLLLLLGG..",
+ "..GGLLLLLLGG..",
+ "...GGLLLLGG...",
+ "....GGGGGG....",
+ "...GGG..GGG...",
+ "..GGGG..GGGG..",
+ ".gggg....gggg.",
+ ]),
+]
+
+out, pals, meta, off = [], [], [], 0
+for name, pal, rows in SPRITES:
+ keys = list(pal)
+ assert len(keys) <= 15, name
+ w, h = len(rows[0]), len(rows)
+ assert all(len(r) == w for r in rows), name
+ px = [0 if ch == '.' else keys.index(ch) + 1 for r in rows for ch in r]
+ if len(px) % 2: px.append(0)
+ data = [px[i] | px[i + 1] << 4 for i in range(0, len(px), 2)]
+ meta.append((w, h, off))
+ off += len(data)
+ out += data
+ pals.append([pal[k] for k in keys])
+
+print("/* dancers: art begin (made by tools/dancers.py from its pixel maps, 4 bits a pixel) */")
+n = max(map(len, pals))
+print("#define DPN %d /* colors in a palette */" % n)
+print("static const uint32_t DPAL[4][DPN] = {")
+for p in pals:
+ print(" {" + ", ".join("0x%06X" % c for c in p + [0] * (n - len(p))) + "},")
+print("};")
+print("static const struct { uint8_t w, h; uint16_t off; } DSPR[4] = {" + ", ".join("{%d, %d, %d}" % m for m in meta) + "};")
+print("static const uint8_t DPIX[%d] = {" % len(out))
+for i in range(0, len(out), 24):
+ print(" " + ",".join("0x%02X" % b for b in out[i:i + 24]) + ",")
+print("};")
+print("/* art end */")
diff --git a/games/snake/README.md b/games/snake/README.md
index d1f511b2..51339ef3 100644
--- a/games/snake/README.md
+++ b/games/snake/README.md
@@ -1,15 +1,26 @@
# Snake
-The snake game of Google's search page, for the NumWorks calculator: a blue snake glides over a checkered lawn, turns with round corners, looks where it goes and opens wide for apples.
-
-<img src="docs/shot.png" width="320" alt="The snake about to eat an apple on the small board">
-
-- **Smooth:** the snake moves at 60 frames a second, between cells rather than from one to the next.
-- **Options:** speed (Slow, Normal, Fast), board (Small, Medium, Large), 1, 3 or 5 apples, walls, wrapping and portals.
-- **Walls:** a new wall grows every two apples.
-- **Wrap:** leave by one edge, come back by the other.
-- **Portals:** apples come in pairs with the same colored ring. Eat one and you come out of the other, still going the same way.
-- **Best scores** for every board and speed, kept with your options.
+Google's Snake, the game you get when you search for "snake", on the NumWorks calculator: the checkered lawn, the blue snake with its big eyes and its shadow, the apple, the sky-blue menu card and the settings with all their little pictures.
+
+<img src="docs/shot.png" width="320" alt="The snake about to eat an apple">
+
+- **Google's boards:** Normal (17 x 15), Small (10 x 9) and Large (24 x 21).
+- **12 modes, like Google's:**
+ - **Classic**
+ - **Wall:** a wall grows for every fruit.
+ - **Portal:** fruit comes in pairs with the same colored ring. Eat one and you come out of the other, still going the same way.
+ - **Cheese:** the snake is full of holes, and you can go through them.
+ - **Borderless:** leave by one edge, come back by the other.
+ - **Twin:** each fruit swaps your head and tail, so you set off back the way you came.
+ - **Winged:** fruit flies around the lawn and bounces off the edges and the snake.
+ - **Yin Yang:** a black snake mirrors every move you make. Neither may crash.
+ - **Statue:** each fruit turns your body to stone behind you.
+ - **Light:** it's dark, except around your head; fruit lights it up for a while.
+ - **Magnet:** fruit near your head is pulled into your mouth.
+ - **Peaceful:** you can't crash.
+- **Settings, like Google's:** the fruit (apple, banana, pineapple, grapes, strawberry, cherries), 1, 3 or 5 fruits at a time, the speed (normal, fast, slow), the board, 8 snake colors and 4 themes (day, night, snow, volcano). **Shuffle** picks them all at random; **Reset** puts them back.
+- **Smooth:** the snake glides at 60 frames a second, turns with round corners and opens wide for fruit.
+- **Best scores** for every mode, number of fruits, speed and board, kept with your settings.
## Controls
@@ -17,19 +28,17 @@ The snake game of Google's search page, for the NumWorks calculator: a blue snak
| --- | --- |
| Arrows, or 8 4 6 2 | Turn (two turns can wait in line, and the snake never turns back on itself) |
| OK | Start, choose |
+| Left, Right | Change a setting |
| Back | Pause (Resume, Restart, Quit game); back one step in menus |
| Home | Quit |
## Credits
-Rewritten in C for NumPlay from **[Tatone26](https://github.com/Tatone26)**'s Snake in [Numworks-games](https://github.com/Tatone26/Numworks-games/tree/main/apps/snake) (All the Apps), which is released into the public domain ([UNLICENSE](UNLICENSE)). It keeps its options (speed, board size, walls every two apples, wrapping) and changes the rest:
+The look, the modes and the settings follow **Google's Snake** (Google Search, 2017 onwards). This is an independent fan version, drawn from shapes as it goes (no images from Google), and it isn't affiliated with or endorsed by Google.
-- the look and feel of Google's Snake, drawn from shapes as it goes (no images): the lawn, the blue snake with its eyes and mouth, the apples and the band with the score and best;
-- smooth movement, a two-turn input buffer, apples and walls that pop in, and a snake that stops and flashes when it crashes;
-- new options from Google's game: 3 or 5 apples, and portals;
-- a best score for each board and speed, and the options, saved as `snake.sav`.
+The code started from **[Tatone26](https://github.com/Tatone26)**'s Snake in [Numworks-games](https://github.com/Tatone26/Numworks-games/tree/main/apps/snake) (All the Apps), which is released into the public domain ([UNLICENSE](UNLICENSE)), rewritten in C for NumPlay. Its options (speed, board size, walls, wrapping) are all here, as Google's.
-Snake itself goes back to the arcade game Blockade (Gremlin, 1976) and was made famous by Nokia's phones; the look is that of Google's Snake.
+Snake itself goes back to the arcade game Blockade (Gremlin, 1976) and was made famous by Nokia's phones.
It comes inside [NumPlay](https://github.com/Mason363/NumPlay), or on its own as `Snake.nwa` from the [latest release](https://github.com/Mason363/NumPlay/releases/latest).
diff --git a/games/snake/docs/shot.png b/games/snake/docs/shot.png
index 8a02d0f4..42eec98b 100644
Binary files a/games/snake/docs/shot.png and b/games/snake/docs/shot.png differ
diff --git a/games/snake/src/main.c b/games/snake/src/main.c
index a3fb806b..c4a4f296 100644
--- a/games/snake/src/main.c
+++ b/games/snake/src/main.c
@@ -1,12 +1,14 @@
-/* Snake: the snake of Google's search page game, for the NumWorks calculator,
- * with the options of Tatone26's Snake from All the Apps (speed, board size,
- * walls, wrapping) and a few of Google's (more apples, portals).
+/* Snake: Google's Snake, the game in Search, for the NumWorks calculator.
+ * Its lawn, its blue snake with a shadow, its fruit, its menu card and its
+ * settings: 6 fruits, 12 modes, 1, 3 or 5 fruits at a time, 3 speeds, 3
+ * board sizes (17 x 15, 10 x 9, 24 x 21), 8 snake colors and 4 themes.
+ * Tatone26's Snake from All the Apps was the starting point.
*
* The snake is a chain of capsules through the centres of its cells, so it
* glides from cell to cell and turns with round corners. Each frame only the
- * cells around the head, the tail and the popping apples are drawn again: one
- * cell at a time, composed in a small buffer, then pushed. Menus are drawn in
- * bands of 20 rows. */
+ * cells that change are drawn again (around the heads and tails, fruit that
+ * moves or pops, the light in Light mode): a cell at a time, composed in a
+ * small buffer, then pushed. Menus are drawn in bands of 20 rows. */
#include <eadk.h>
#include <stdbool.h>
#include <stdint.h>
@@ -28,25 +30,35 @@ static uint32_t keys(void) {
return ((uint32_t)s & 0x800001FFu) | ((uint32_t)(s >> 32) & 0x00100850u) << 8;
}
-/* Google Snake's colours */
-#define C_BAR RGB(0x4A752C) /* the band on top, and the panels */
-#define C_EDGE RGB(0x578A34) /* around the field, and the walls */
-#define C_LIGHT RGB(0xAAD751) /* the checkerboard */
-#define C_DARK RGB(0xA2D149)
-#define C_SNAKE RGB(0x4E7CF6)
+/* Google Snake's colors */
#define C_APPLE RGB(0xE7471D)
#define C_GOLD RGB(0xFFC53D)
-#define C_PALE RGB(0xCFE6B0) /* small text on green */
-#define HDR 26 /* the band on top */
+#define C_CARD RGB(0x4DC1F9) /* the menu card */
+#define C_CARD2 RGB(0x35A7E3) /* the row in focus */
+#define C_BTN RGB(0x1A5CD7) /* a button */
+#define C_BTN2 RGB(0x2F4F9A) /* a button not in focus */
+#define HDR 24 /* the band on top */
+
+/* the themes: the band on top, around the field (and walls), the lawn */
+static const uint32_t THEME[4][4] = {
+ {0x4A752C, 0x578A34, 0xAAD751, 0xA2D149}, /* day */
+ {0x17222E, 0x22354A, 0x31475B, 0x2B4053}, /* night */
+ {0x55778F, 0x7FA2BB, 0xEEF5FB, 0xDEEAF4}, /* snow */
+ {0x3A1810, 0x5C2414, 0x5C4136, 0x52382E}, /* volcano */
+};
+static const uint32_t SNAKES[8] = {0x4E7CF6, 0x8E5CE6, 0xE8588F, 0xF48C2E, 0xF2C21E, 0x17A5A0, 0xF4F4F4, 0x2E2E2E};
+static color c_bar, c_edge, c_light, c_dark, c_slight, c_sdark; /* the theme's, and shadows on the lawn */
/* ------------------------------------------------------------------ drawing */
#define BUFPX (320 * 20)
static color buf[BUFPX];
static int rx, ry, rw, rh; /* the part of the screen in buf */
static int kx0, ky0, kx1, ky1; /* where drawing lands, inside it */
+static bool shade; /* blob() lays shadows on the lawn instead of painting */
static int imin(int a, int b) { return a < b ? a : b; }
static int imax(int a, int b) { return a > b ? a : b; }
+static int iabs(int v) { return v < 0 ? -v : v; }
static void clip(int x, int y, int w, int h) {
kx0 = imax(x, rx), ky0 = imax(y, ry), kx1 = imin(x + w, rx + rw), ky1 = imin(y + h, ry + rh);
@@ -64,9 +76,17 @@ static void fill(int x, int y, int w, int h, color c) {
for (int j = imax(y, ky0), j1 = imin(y + h, ky1); j < j1; j++)
for (int i = imax(x, kx0), i1 = imin(x + w, kx1); i < i1; i++) buf[(j - ry) * rw + i - rx] = c;
}
+/* the pixels of a rectangle, a of the way to c */
+static void wash(int x, int y, int w, int h, color c, int a) {
+ for (int j = imax(y, ky0), j1 = imin(y + h, ky1); j < j1; j++)
+ for (int i = imax(x, kx0), i1 = imin(x + w, kx1); i < i1; i++) {
+ color *p = buf + (j - ry) * rw + i - rx;
+ *p = mix(c, *p, a);
+ }
+}
/* A capsule from a to b, its radius going from ra to rb, with soft edges.
- Everything round is one: discs, the snake, letters, leaves. */
+ Everything round is one: discs, the snake, fruit, icons. */
static void blob(float ax, float ay, float bx, float by, float ra, float rb, color c) {
float dx = bx - ax, dy = by - ay, l = dx * dx + dy * dy, inv = l > 0 ? 1 / l : 0, r = (ra > rb ? ra : rb) + 2;
int x0 = imax(kx0, (int)((ax < bx ? ax : bx) - r)), x1 = imin(kx1, (int)((ax > bx ? ax : bx) + r));
@@ -79,6 +99,10 @@ static void blob(float ax, float ay, float bx, float by, float ra, float rb, col
t = t < 0 ? 0 : t > 1 ? 1 : t;
float ex = qx - t * dx, ey = qy - t * dy, e = ra + (rb - ra) * t + 0.5f, d = ex * ex + ey * ey;
if (d >= e * e) continue;
+ if (shade) { /* the same shadow however many shapes cast it */
+ p[x] = p[x] == c_light ? c_slight : p[x] == c_dark ? c_sdark : p[x];
+ continue;
+ }
float a = e - __builtin_sqrtf(d);
p[x] = a >= 1 ? c : mix(c, p[x], (int)(a * 32));
}
@@ -90,7 +114,16 @@ static void box(int x, int y, int w, int h, int r, color c) {
fill(x, y + r, w, h - 2 * r, c);
for (int i = 0; i < 4; i++) disc(x + r + (i & 1) * (w - 2 * r), y + r + (i >> 1) * (h - 2 * r), r, c);
}
-/* darkens everything under the band on top, behind a panel */
+/* a triangle pointing along (dx, dy) (one of them 0), its tip at (x, y), a
+ long, its base 2 s + 1 wide */
+static void tri(int x, int y, int dx, int dy, int a, int s, color c) {
+ for (int t = 0; t < a; t++) {
+ int w = s * t / a;
+ if (dx) fill(x - dx * t, y - w, 1, 2 * w + 1, c);
+ else fill(x - w, y - dy * t, 2 * w + 1, 1, c);
+ }
+}
+/* darkens everything under the band on top, behind a card */
static void dim(void) {
clip(0, HDR, 320, 240);
for (int j = ky0; j < ky1; j++)
@@ -99,45 +132,55 @@ static void dim(void) {
}
/* ------------------------------------------------------------------ the game */
-#define MAXN (25 * 17)
-static const uint8_t BW[3] = {15, 20, 25}, BH[3] = {10, 13, 17}, CS[3] = {20, 15, 12};
-static const uint8_t STEP_MS[3] = {190, 135, 90};
+#define MAXW 24
+#define MAXH 21
+#define MAXN (MAXW * MAXH)
+/* sizes in Google's order: normal, small, large; speeds: normal, fast, slow */
+static const uint8_t BW[3] = {17, 10, 24}, BH[3] = {15, 9, 21}, CS[3] = {14, 23, 10};
+static const uint8_t STEP_MS[3] = {135, 95, 190};
static const int8_t DX[4] = {1, 0, -1, 0}, DY[4] = {0, 1, 0, -1}; /* right, down, left, up */
+enum { O_FRUIT, O_MODE, O_COUNT, O_SPEED, O_SIZE, O_COLOR, O_THEME, NOPT };
+static const uint8_t OPT_N[NOPT] = {6, 12, 3, 3, 3, 8, 4};
+enum { M_CLASSIC, M_WALL, M_PORTAL, M_CHEESE, M_BORDERLESS, M_TWIN, M_WINGED, M_YINYANG, M_STATUE, M_LIGHT, M_MAGNET, M_PEACEFUL };
+#define NBEST (12 * 3 * 3 * 3)
+
/* everything kept between visits (snake.sav) */
static struct {
uint8_t magic, version;
- uint8_t opt[6]; /* speed, size, apples, walls, wrap, portals */
- uint16_t best[9]; /* per size and speed */
+ uint8_t opt[NOPT], pad;
+ uint16_t best[NBEST]; /* per mode, count, speed and size */
} V;
-static const uint8_t OPT_N[6] = {3, 3, 3, 2, 2, 2}, OPT_DEF[6] = {1, 1, 0, 0, 0, 0};
#define SAVE_NAME "snake.sav"
-#define O_SPEED V.opt[0]
-#define O_SIZE V.opt[1]
-#define O_APPLES V.opt[2]
-#define O_WALLS V.opt[3]
-#define O_WRAP V.opt[4]
-#define O_PORTAL V.opt[5]
+#define MODE V.opt[O_MODE]
static int bw, bh, cs, fx, fy; /* board in cells, cell size, where the field starts */
-static uint16_t body[MAXN]; /* the snake's cells (x | y << 8), a ring from tl to hd */
-static uint8_t ndir[MAXN]; /* the direction each was entered in */
-static uint8_t occ[MAXN]; /* per cell */
-#define O_BODY 1
-#define O_WALL 2
-static int hd, tl, len, grow, score, nq, hop, otail, acc, wpop, gate[3][2]; /* gate: each pair's portals last used */
-static uint8_t q[2]; /* turns asked for, not made yet */
-static bool tmove; /* the tail left otail in the last step */
-static uint32_t now, wborn, chew_t, seed;
+static uint8_t occ[MAXN]; /* per cell: snakes' solid parts, a wall, a statue */
+#define O_BODY 0x3F
+#define O_STONE 0x40
+#define O_WALL 0x80
typedef struct {
- uint16_t p;
- uint8_t kind; /* 0 an apple, else the pair of portals it belongs to */
- uint8_t eat; /* being eaten: steps left before it goes */
+ uint16_t body[MAXN]; /* its cells (x | y << 8), a ring from tl to hd */
+ uint8_t ndir[MAXN]; /* the way each was entered, | 4 for a hole (Cheese) */
+ int hd, tl, len, grow, otail, hop, nq, made;
+ uint8_t q[2]; /* turns asked for, not made yet */
+ bool tmove, flip; /* the tail moved in the last step; Twin: turn round first */
+} snake_t;
+static snake_t S[2];
+static int ns; /* 2 in Yin Yang: the second one mirrors the first */
+
+typedef struct {
+ uint16_t p, from; /* where it is, and where it was a step ago (it flies, or is pulled) */
+ uint8_t kind; /* 0 fruit, else the pair of portals it belongs to */
+ uint8_t eat; /* being eaten: steps left before it goes */
+ int8_t vx, vy; /* Winged: its flight */
bool live;
uint32_t born;
} apple_t;
static apple_t ap[8];
+static int score, wpop, gate[3][2], nstep, acc; /* gate: each pair's portals last used; acc: ms into the step */
+static uint32_t now, wborn, chew_t, lit_t, seed;
static uint32_t rnd(void) {
seed ^= seed << 13;
@@ -145,19 +188,24 @@ static uint32_t rnd(void) {
seed ^= seed << 5;
return seed;
}
-static int iabs(int v) { return v < 0 ? -v : v; }
static int at(int p) { return (p >> 8) * bw + (p & 255); }
-static int step_ms(void) { return STEP_MS[O_SPEED]; }
-static uint16_t *best(void) { return &V.best[O_SIZE * 3 + O_SPEED]; }
+static int step_ms(void) { return STEP_MS[V.opt[O_SPEED]]; }
+static uint16_t *best(void) {
+ return &V.best[((MODE * 3 + V.opt[O_COUNT]) * 3 + V.opt[O_SPEED]) * 3 + V.opt[O_SIZE]];
+}
+static bool solid(snake_t *s, int k) { return !(s->ndir[k % MAXN] & 4); }
+static bool wraps(void) { return MODE == M_BORDERLESS || MODE == M_PEACEFUL; }
static bool far(int p, int h) { return iabs((p & 255) - (h & 255)) + iabs((p >> 8) - (h >> 8)) > 2; }
-/* a cell for an apple or a wall: free, and (first try) not right by the head,
+/* a cell for fruit or a wall: free, and (first try) not right by a head,
or the portal it is about to come out of */
static bool vacant(int p, int pass) {
if (occ[at(p)]) return false;
for (int i = 0; i < 8; i++)
if (ap[i].live && ap[i].p == p) return false;
- return pass || (far(p, body[hd]) && (hop < 0 || far(p, hop)));
+ for (int k = 0; k < ns && !pass; k++)
+ if (!far(p, S[k].body[S[k].hd]) || (S[k].hop >= 0 && !far(p, S[k].hop))) return false;
+ return true;
}
/* the n-th vacant cell, or (1 << 20) less the number of them */
static int nth(int pass, int n) {
@@ -173,29 +221,47 @@ static int pick(void) {
}
return -1;
}
+static void put(int i, int p, int kind) {
+ ap[i] = (apple_t){(uint16_t)p, (uint16_t)p, (uint8_t)kind, 0, (int8_t)(rnd() & 1 ? 1 : -1), (int8_t)(rnd() & 1 ? 1 : -1), true, now};
+}
static bool spawn(int kind) {
int p = pick();
for (int i = 0; i < 8 && p >= 0; i++)
if (!ap[i].live) {
- ap[i] = (apple_t){(uint16_t)p, (uint8_t)kind, 0, true, now};
+ put(i, p, kind);
return true;
}
return false;
}
+static void set_theme(void) {
+ const uint32_t *t = THEME[V.opt[O_THEME]];
+ c_bar = RGB(t[0]), c_edge = RGB(t[1]), c_light = RGB(t[2]), c_dark = RGB(t[3]);
+ c_slight = mix(0, c_light, 4), c_sdark = mix(0, c_dark, 4);
+}
+
static void new_game(void) {
- bw = BW[O_SIZE], bh = BH[O_SIZE], cs = CS[O_SIZE];
+ int sz = V.opt[O_SIZE];
+ bw = BW[sz], bh = BH[sz], cs = CS[sz];
fx = (320 - bw * cs) / 2, fy = HDR + (240 - HDR - bh * cs) / 2;
+ set_theme();
for (int i = 0; i < MAXN; i++) occ[i] = 0;
for (int i = 0; i < 8; i++) ap[i].live = false;
- int row = bh / 2;
- for (int i = 0; i < 4; i++) body[i] = (uint16_t)((1 + i) | row << 8), ndir[i] = 0, occ[row * bw + 1 + i] = O_BODY;
+ ns = MODE == M_YINYANG ? 2 : 1;
+ int row = bh / 2 - (ns == 2) * (bh / 5); /* two snakes: rows apart, mirrored through the centre */
+ for (int k = 0; k < ns; k++) {
+ snake_t *s = &S[k];
+ for (int i = 0; i < 4; i++) {
+ int x = k ? bw - 2 - i : 1 + i, y = k ? bh - 1 - row : row;
+ s->body[i] = (uint16_t)(x | y << 8), s->ndir[i] = (uint8_t)(k * 2), occ[y * bw + x]++;
+ }
+ s->tl = 0, s->hd = 3, s->len = 4, s->grow = s->nq = s->made = 0, s->hop = -1, s->tmove = s->flip = false;
+ }
for (int i = 0; i < 6; i++) gate[i / 2][i & 1] = -1;
- tl = 0, hd = 3, len = 4, grow = score = nq = 0, hop = wpop = -1, tmove = false, acc = step_ms();
- chew_t = now - 1000;
- /* the first apple straight ahead, like Google's */
- int n = O_APPLES * 2 + 1, k = O_PORTAL;
- ap[0] = (apple_t){(uint16_t)((bw - 5) | row << 8), (uint8_t)k, 0, true, 0};
+ score = nstep = acc = 0, wpop = -1, chew_t = lit_t = now - 5000;
+ /* the first fruit straight ahead, like Google's */
+ int n = V.opt[O_COUNT] * 2 + 1, k = MODE == M_PORTAL;
+ put(0, (bw - 5) | row << 8, k);
if (k) {
spawn(1);
for (k = 2; k <= (n + 1) / 2; k++) spawn(k), spawn(k);
@@ -205,75 +271,173 @@ static void new_game(void) {
for (int i = 0; i < 8; i++) ap[i].born = 0; /* no popping in the menus */
}
-/* One cell forward; false if the snake crashes. */
-static bool step(void) {
- int h = body[hd], d = ndir[hd], np;
- if (hop >= 0) { /* out of the other portal, the same way */
- np = hop, hop = -1;
- } else {
- if (nq) d = q[0], q[0] = q[1], nq--;
- int x = (h & 255) + DX[d], y = (h >> 8) + DY[d];
- if (x < 0 || y < 0 || x >= bw || y >= bh) {
- if (!O_WRAP) return false;
- x = (x + bw) % bw, y = (y + bh) % bh;
- }
- np = x | y << 8;
+/* Twin: head and tail trade places, and it goes back the way it came */
+static void turn_round(snake_t *s) {
+ static uint16_t tb[MAXN];
+ static uint8_t td[MAXN];
+ int n = s->len;
+ for (int i = 0; i < n; i++) tb[i] = s->body[(s->tl + i) % MAXN], td[i] = s->ndir[(s->tl + i) % MAXN];
+ for (int j = 0; j < n; j++) {
+ int o = n - 1 - j, d = (j ? td[o + 1] : td[n - 1]) & 3;
+ s->body[j] = tb[o], s->ndir[j] = (uint8_t)((d ^ 2) | (td[o] & 4));
}
- int c = at(np);
- bool moving = !grow;
- if ((occ[c] & O_WALL) || ((occ[c] & O_BODY) && !(moving && np == body[tl]))) return false;
- for (int i = 0; i < 8; i++)
- if (ap[i].eat && !--ap[i].eat) ap[i].live = false, chew_t = now;
- if (moving) {
- otail = body[tl];
- occ[at(otail)] &= (uint8_t)~O_BODY;
- tl = (tl + 1) % MAXN, len--;
+ s->tl = 0, s->hd = n - 1, s->nq = 0, s->tmove = false, s->hop = -1;
+}
+
+/* Statue: all but the head turns to stone, and it starts again from 4 */
+static void statue(snake_t *s) {
+ for (int i = 0; i < s->len - 1; i++) {
+ int k = (s->tl + i) % MAXN, c = at(s->body[k]);
+ if (solid(s, k)) occ[c]--;
+ occ[c] |= O_STONE;
+ }
+ s->tl = s->hd, s->len = 1, s->grow += 3, s->tmove = false;
+}
+
+static void eat(int k, apple_t *a) {
+ snake_t *s = &S[k];
+ a->eat = 1, score++, s->grow++, lit_t = now;
+ if (a->kind) {
+ for (int j = 0; j < 8; j++)
+ if (&ap[j] != a && ap[j].live && !ap[j].eat && ap[j].kind == a->kind) s->hop = gate[a->kind - 1][1] = ap[j].p, ap[j].eat = 2;
+ gate[a->kind - 1][0] = a->p;
+ if (spawn(a->kind) && !spawn(a->kind)) /* no room for two: a plain fruit */
+ for (int j = 0; j < 8; j++)
+ if (ap[j].live && !ap[j].eat && ap[j].kind == a->kind) ap[j].kind = 0;
} else {
- grow--;
+ spawn(0);
}
- tmove = moving;
- hd = (hd + 1) % MAXN, len++;
- body[hd] = (uint16_t)np, ndir[hd] = (uint8_t)d, occ[c] |= O_BODY;
+ if (MODE == M_WALL) { /* Google's walls: one more for each fruit */
+ int w = pick();
+ if (w >= 0) occ[at(w)] |= O_WALL, wpop = w, wborn = now;
+ }
+ if (MODE == M_TWIN) s->flip = true;
+ if (MODE == M_STATUE) statue(s);
+}
+
+/* a cell fruit can move to */
+static bool open_for_fruit(int x, int y) {
+ if (x < 0 || y < 0 || x >= bw || y >= bh || occ[y * bw + x]) return false;
+ for (int i = 0; i < 8; i++)
+ if (ap[i].live && ap[i].p == (x | y << 8)) return false;
+ return true;
+}
+/* Winged: fruit flies on the diagonal, bouncing off the edges and the snake;
+ Magnet: fruit near a head is pulled into it */
+static void move_fruit(void) {
for (int i = 0; i < 8; i++) {
apple_t *a = &ap[i];
- if (!a->live || a->eat || a->p != np) continue;
- a->eat = 1, score++, grow++;
- if (a->kind) {
- for (int j = 0; j < 8; j++)
- if (j != i && ap[j].live && !ap[j].eat && ap[j].kind == a->kind) hop = gate[a->kind - 1][1] = ap[j].p, ap[j].eat = 2;
- gate[a->kind - 1][0] = np;
- if (spawn(a->kind) && !spawn(a->kind)) /* no room for two: a plain apple */
- for (int j = 0; j < 8; j++)
- if (ap[j].live && !ap[j].eat && ap[j].kind == a->kind) ap[j].kind = 0;
+ a->from = a->p;
+ if (!a->live || a->eat || a->kind) continue;
+ int x = a->p & 255, y = a->p >> 8;
+ if (MODE == M_WINGED && (nstep & 1)) {
+ for (int t = 0; t < 4; t++) {
+ int vx = t & 1 ? -a->vx : a->vx, vy = t & 2 ? -a->vy : a->vy;
+ if (open_for_fruit(x + vx, y + vy)) {
+ a->vx = (int8_t)vx, a->vy = (int8_t)vy, a->p = (uint16_t)((x + vx) | (y + vy) << 8);
+ break;
+ }
+ }
+ } else if (MODE == M_MAGNET) {
+ for (int k = 0; k < ns; k++) {
+ int h = S[k].body[S[k].hd], dx = (h & 255) - x, dy = (h >> 8) - y;
+ if (iabs(dx) > 2 || iabs(dy) > 2) continue;
+ int mx = iabs(dx) >= iabs(dy) ? (dx > 0) - (dx < 0) : 0, my = mx ? 0 : (dy > 0) - (dy < 0);
+ if ((x + mx) == (h & 255) && (y + my) == (h >> 8)) {
+ a->p = (uint16_t)h, eat(k, a); /* into the mouth */
+ } else if (open_for_fruit(x + mx, y + my)) {
+ a->p = (uint16_t)((x + mx) | (y + my) << 8);
+ }
+ break;
+ }
+ }
+ }
+}
+
+/* One cell forward for every snake; false if one crashes. */
+static bool step(void) {
+ int np[2], d[2], c[2];
+ bool moving[2];
+ for (int k = 0; k < ns; k++)
+ if (S[k].flip) turn_round(&S[k]), S[k].flip = false;
+ for (int k = 0; k < ns; k++) {
+ snake_t *s = &S[k];
+ int h = s->body[s->hd];
+ d[k] = s->ndir[s->hd] & 3;
+ if (s->hop >= 0) { /* out of the other portal, the same way */
+ np[k] = s->hop;
} else {
- spawn(0);
+ if (s->nq) d[k] = s->q[0];
+ int x = (h & 255) + DX[d[k]], y = (h >> 8) + DY[d[k]];
+ if (x < 0 || y < 0 || x >= bw || y >= bh) {
+ if (!wraps()) return false;
+ x = (x + bw) % bw, y = (y + bh) % bh;
+ }
+ np[k] = x | y << 8;
}
- if (O_WALLS && !(score & 1)) { /* Tatone26's walls: one more every two apples */
- int w = pick();
- if (w >= 0) occ[at(w)] |= O_WALL, wpop = w, wborn = now;
+ moving[k] = !s->grow;
+ c[k] = at(np[k]);
+ }
+ if (MODE != M_PEACEFUL) {
+ for (int k = 0; k < ns; k++) {
+ int n = occ[c[k]] & O_BODY;
+ for (int j = 0; j < ns; j++) /* a tail that goes away as the head comes */
+ if (moving[j] && S[j].body[S[j].tl] == np[k] && solid(&S[j], S[j].tl)) n--;
+ if ((occ[c[k]] & (O_WALL | O_STONE)) || n > 0) return false;
}
- break;
+ if (ns == 2 && np[0] == np[1]) return false;
}
+ for (int i = 0; i < 8; i++)
+ if (ap[i].eat && !--ap[i].eat) ap[i].live = false, chew_t = now;
+ nstep++;
+ for (int k = 0; k < ns; k++) {
+ snake_t *s = &S[k];
+ if (s->hop >= 0) s->hop = -1;
+ else if (s->nq) s->q[0] = s->q[1], s->nq--;
+ if (moving[k]) {
+ s->otail = s->body[s->tl];
+ if (solid(s, s->tl)) occ[at(s->otail)]--;
+ s->tl = (s->tl + 1) % MAXN, s->len--;
+ } else {
+ s->grow--;
+ }
+ s->tmove = moving[k];
+ }
+ for (int k = 0; k < ns; k++) {
+ snake_t *s = &S[k];
+ bool hole = MODE == M_CHEESE && ++s->made % 3 == 0;
+ s->hd = (s->hd + 1) % MAXN, s->len++;
+ s->body[s->hd] = (uint16_t)np[k], s->ndir[s->hd] = (uint8_t)(d[k] | hole * 4);
+ if (!hole) occ[c[k]]++;
+ }
+ for (int k = 0; k < ns; k++)
+ for (int i = 0; i < 8; i++)
+ if (ap[i].live && !ap[i].eat && ap[i].p == np[k]) {
+ eat(k, &ap[i]);
+ break;
+ }
+ move_fruit();
return true;
}
/* ------------------------------------------------------------------ the board */
-enum { S_TITLE, S_SET, S_READY, S_PLAY, S_PAUSE, S_QUIT, S_DIE, S_OVER };
-static int state, sel;
-static bool dead, newbest, won;
-static float prog, mouth; /* how far into the step; how open the mouth is */
-static color scol; /* the snake's colour (it flashes when it dies) */
+enum { S_TITLE, S_SET, S_READY, S_PLAY, S_PAUSE, S_QUIT, S_DIE };
+static int state, sel, row;
+static bool dead, newbest, won, played;
+static float prog, mouth, oy; /* how far into the step; how open the mouth is; the shadow's drop */
+static bool flash; /* the snake flashes when it dies */
static int qx0, qy0, qx1, qy1; /* the cells the drawn part of the screen touches */
static int fl(int v) { return (v + cs * 16) / cs - 16; } /* floor(v / cs) */
static bool near(int p) {
int x = p & 255, y = p >> 8;
- return x >= qx0 && x <= qx1 && y >= qy0 && y <= qy1;
+ return x >= qx0 && x <= qx1 && y >= qy0 - shade && y <= qy1;
}
static float ux(int p) { return fx + (p & 255) * cs + cs * 0.5f; }
-static float uy(int p) { return fy + (p >> 8) * cs + cs * 0.5f; }
-static void cellclip(int p) { clip(fx + (p & 255) * cs, fy + (p >> 8) * cs, cs, cs); }
+static float uy(int p) { return fy + (p >> 8) * cs + cs * 0.5f + oy; }
+static void cellclip(int p) { clip(fx + (p & 255) * cs, fy + (p >> 8) * cs + (int)oy, cs, cs); }
static void fieldclip(void) { clip(fx, fy, bw * cs, bh * cs); }
+static color checker(int p) { return ((p & 255) + (p >> 8)) & 1 ? c_dark : c_light; }
static void ground(void) {
for (int j = 0; j < rh; j++) {
@@ -282,27 +446,237 @@ static void ground(void) {
color *p = buf + j * rw;
for (int i = 0; i < rw; i++) {
if (rx + i >= e) cx++, e += cs;
- p[i] = y < HDR ? C_BAR : in && cx >= 0 && cx < bw ? ((cx + cy) & 1 ? C_DARK : C_LIGHT) : C_EDGE;
+ p[i] = y < HDR ? c_bar : in && cx >= 0 && cx < bw ? ((cx + cy) & 1 ? c_dark : c_light) : c_edge;
}
}
}
-static color checker(int p) { return ((p & 255) + (p >> 8)) & 1 ? C_DARK : C_LIGHT; }
+static const uint32_t RING[3] = {0x9A5CF6, 0xFF8A1E, 0x1EB8E8}; /* the portal pairs */
-/* an apple of s pixels centred on (x, y); a portal has a ring in its pair's
- colour (and only the ring once it is in use: kind | 8) */
-static const uint32_t ring[3] = {0x9A5CF6, 0xFF8A1E, 0x1EB8E8};
-static void apple(float x, float y, float s, int kind, color bg) {
- if (kind) { /* a ring, and a smaller apple in it */
- disc(x, y, s * 0.5f, RGB(ring[(kind & 3) - 1]));
- disc(x, y, s * 0.35f, bg);
- if (kind & 8) return;
- s *= 0.72f;
+/* ------------------------------------------------------------------ fruit and icons */
+static void leaf(float x, float y, float s) { blob(x, y, x + s * 0.22f, y - s * 0.1f, s * 0.08f, s * 0.03f, RGB(0x4E9F2D)); }
+static void stem(float x, float y, float x1, float y1, float s) { blob(x, y, x1, y1, s * 0.045f, s * 0.035f, RGB(0x6D4C2F)); }
+/* the fruit f, about s pixels, centred on (x, y) */
+static void fruit(int f, float x, float y, float s) {
+ switch (f) {
+ case 0: /* apple */
+ stem(x + s * 0.02f, y - s * 0.2f, x + s * 0.08f, y - s * 0.42f, s);
+ disc(x, y + s * 0.05f, s * 0.37f, C_APPLE);
+ disc(x - s * 0.14f, y - s * 0.05f, s * 0.09f, RGB(0xF58A67));
+ leaf(x + s * 0.1f, y - s * 0.34f, s);
+ break;
+ case 1: /* banana: a yellow crescent, brown at the ends */
+ for (int i = 0; i < 6; i++) {
+ float a0 = 0.35f + i * 0.4f, a1 = a0 + 0.4f; /* along a curve, in fifths of a half turn */
+ float c0 = 1 - a0 * a0 / 2 + a0 * a0 * a0 * a0 / 24, c1 = 1 - a1 * a1 / 2 + a1 * a1 * a1 * a1 / 24;
+ float s0 = a0 - a0 * a0 * a0 / 6, s1 = a1 - a1 * a1 * a1 / 6, w0 = i == 0 ? 0.05f : 0.13f, w1 = i == 5 ? 0.05f : 0.13f;
+ blob(x + c0 * s * 0.36f, y - s * 0.22f + s0 * s * 0.36f, x + c1 * s * 0.36f, y - s * 0.22f + s1 * s * 0.36f, s * w0, s * w1, RGB(0xF6D33C));
+ }
+ disc(x + s * 0.33f, y - s * 0.1f, s * 0.05f, RGB(0x6D4C2F));
+ break;
+ case 2: /* pineapple */
+ for (int i = -1; i <= 1; i++) blob(x, y - s * 0.2f, x + i * s * 0.16f, y - s * 0.46f, s * 0.07f, s * 0.03f, RGB(0x3E8E2A));
+ blob(x, y - s * 0.02f, x, y + s * 0.2f, s * 0.26f, s * 0.24f, RGB(0xF0A932));
+ for (int i = 0; i < 6; i++) disc(x + ((i % 3) - 1) * s * 0.14f + (i / 3) * s * 0.07f - s * 0.035f, y + (i / 3) * s * 0.16f, s * 0.035f, RGB(0xB8741F));
+ break;
+ case 3: /* grapes */
+ stem(x, y - s * 0.3f, x + s * 0.05f, y - s * 0.46f, s);
+ leaf(x + s * 0.04f, y - s * 0.38f, s);
+ for (int i = 0; i < 6; i++) {
+ int r = i < 3 ? 0 : i < 5 ? 1 : 2, c = i < 3 ? i : i < 5 ? i - 3 : 0;
+ disc(x + (c - (2 - r) * 0.5f) * s * 0.24f, y - s * 0.2f + r * s * 0.2f, s * 0.13f, RGB(0x8E47C4));
+ }
+ disc(x - s * 0.28f, y - s * 0.26f, s * 0.04f, RGB(0xC49AE8));
+ break;
+ case 4: /* strawberry */
+ blob(x, y - s * 0.06f, x, y + s * 0.3f, s * 0.3f, s * 0.07f, RGB(0xE53935));
+ for (int i = 0; i < 5; i++) disc(x + (i - 2) * s * 0.11f, y + ((i & 1) * 0.12f - 0.02f) * s, s * 0.028f, RGB(0xFFE08A));
+ for (int i = -1; i <= 1; i++) blob(x, y - s * 0.28f, x + i * s * 0.2f, y - s * 0.3f + !i * -s * 0.1f, s * 0.07f, s * 0.04f, RGB(0x3E8E2A));
+ break;
+ default: /* cherries */
+ stem(x - s * 0.18f, y + s * 0.12f, x + s * 0.06f, y - s * 0.38f, s);
+ stem(x + s * 0.2f, y + s * 0.06f, x + s * 0.06f, y - s * 0.38f, s);
+ leaf(x + s * 0.06f, y - s * 0.38f, s);
+ disc(x - s * 0.18f, y + s * 0.18f, s * 0.2f, RGB(0xD7263D));
+ disc(x + s * 0.2f, y + s * 0.12f, s * 0.2f, RGB(0xD7263D));
+ disc(x - s * 0.24f, y + s * 0.12f, s * 0.05f, RGB(0xF08A96));
+ break;
+ }
+}
+
+static void trophy(float x, float y, float k, color bg) {
+ for (int s = -1; s <= 1; s += 2) {
+ disc(x + 6 * k * s, y - 4 * k, 3 * k, C_GOLD);
+ disc(x + 6 * k * s, y - 4 * k, 1.4f * k, bg);
+ }
+ int ky = ky0;
+ clip(0, (int)(y - 7 * k), 320, 240);
+ ky0 = imax(ky0, ky);
+ blob(x, y - 7 * k, x, y, 7 * k, 2 * k, C_GOLD);
+ unclip();
+ fill((int)(x - k), (int)(y), (int)(2 * k + 1), (int)(4 * k), C_GOLD);
+ box((int)(x - 5 * k), (int)(y + 3 * k), (int)(10 * k), (int)(3 * k), (int)k, C_GOLD);
+}
+
+/* The head at (x, y), looking along (ax, ay), r its radius: an open mouth,
+ and eyes that look where it goes. */
+static void face(float x, float y, float ax, float ay, float r) {
+ if (mouth > 0.05f) {
+ float mx = x + ax * r * 0.5f, my = y + ay * r * 0.5f, w = r * 0.45f * mouth, m = r * 0.42f * mouth;
+ blob(mx - ay * w, my + ax * w, mx + ay * w, my - ax * w, m, m, RGB(0x7A1F1A));
+ }
+ for (int s = -1; s <= 1; s += 2) {
+ float ex = x - ax * r * 0.1f - ay * r * 0.5f * s, ey = y - ay * r * 0.1f + ax * r * 0.5f * s, k = r * 0.22f;
+ disc(ex, ey, r * 0.47f, WHITE);
+ if (dead) {
+ blob(ex - k, ey - k, ex + k, ey + k, r * 0.07f, r * 0.07f, 0);
+ blob(ex - k, ey + k, ex + k, ey - k, r * 0.07f, r * 0.07f, 0);
+ } else {
+ disc(ex + ax * r * 0.2f, ey + ay * r * 0.2f, r * 0.25f, RGB(0x1B1B1B));
+ }
+ }
+}
+
+static color snake_color(int k) {
+ color c = RGB(SNAKES[V.opt[O_COLOR]]);
+ if (k) c = V.opt[O_COLOR] == 7 ? RGB(0xF4F4F4) : RGB(0x2E2E2E); /* Yin Yang: black and white */
+ return flash ? mix(WHITE, c, 20) : c;
+}
+
+/* the icon of option o's value v, at (x, y) */
+static void icon(int o, int v, float x, float y, color bg) {
+ static const uint8_t CHECK[3] = {4, 3, 5};
+ switch (o) {
+ case O_FRUIT: fruit(v, x, y, 17); break;
+ case O_COUNT: { /* 1, 3 in a triangle, 5 like a die */
+ static const int8_t P[9][2] = {{0, 0}, {0, -4}, {-5, 4}, {5, 4}, {-4, -4}, {4, -4}, {0, 0}, {-4, 4}, {4, 4}};
+ for (int i = 0; i < v * 2 + 1; i++) fruit(V.opt[O_FRUIT], x + P[v * v + i][0], y + P[v * v + i][1], v ? 8.5f : 16);
+ break;
+ }
+ case O_SPEED:
+ if (v == 0) { /* a snake */
+ blob(x - 7, y + 4, x + 1, y + 4, 2.6f, 3.2f, RGB(0x4E7CF6));
+ blob(x + 1, y + 4, x + 5, y - 3, 3.2f, 3.8f, RGB(0x4E7CF6));
+ disc(x + 5, y - 4, 1.7f, WHITE);
+ } else if (v == 1) { /* a rabbit */
+ blob(x - 3, y - 1, x - 4, y - 8, 1.6f, 1.4f, WHITE);
+ blob(x + 1, y - 1, x + 2, y - 8, 1.6f, 1.4f, WHITE);
+ disc(x - 1, y + 3, 5, WHITE);
+ disc(x - 3, y + 2, 0.9f, RGB(0x333333));
+ disc(x + 1, y + 2, 0.9f, RGB(0x333333));
+ } else { /* a turtle */
+ disc(x + 6, y + 1, 2.4f, RGB(0x7CB342));
+ for (int i = -1; i <= 1; i += 2) disc(x + i * 4, y + 5, 1.8f, RGB(0x7CB342));
+ clip((int)x - 9, (int)y - 8, 18, 12);
+ disc(x - 1, y + 3, 6.5f, RGB(0x2E7D32));
+ disc(x - 1, y + 3, 3, RGB(0x4CAF50));
+ unclip();
+ }
+ break;
+ case O_SIZE: {
+ int n = CHECK[v], w = 16;
+ for (int j = 0; j < w; j++)
+ for (int i = 0; i < w; i++)
+ fill((int)x - 8 + i, (int)y - 8 + j, 1, 1, (i * n / w + j * n / w) & 1 ? RGB(0xA2D149) : RGB(0xAAD751));
+ break;
+ }
+ case O_COLOR:
+ disc(x, y, 7.5f, RGB(SNAKES[v]));
+ disc(x, y, 3.8f, bg);
+ break;
+ case O_THEME:
+ if (v == 0) {
+ for (int i = 0; i < 8; i++) {
+ static const int8_t R[8][2] = {{8, 0}, {6, 6}, {0, 8}, {-6, 6}, {-8, 0}, {-6, -6}, {0, -8}, {6, -6}};
+ blob(x, y, x + R[i][0], y + R[i][1], 1, 1, RGB(0xFFB300));
+ }
+ disc(x, y, 4.8f, RGB(0xFFCA28));
+ } else if (v == 1) {
+ disc(x, y, 7, RGB(0xF3E5AB));
+ disc(x + 4, y - 3, 6, bg);
+ } else if (v == 2) {
+ for (int i = 0; i < 3; i++) {
+ static const int8_t R[3][2] = {{8, 0}, {4, 7}, {-4, 7}};
+ blob(x - R[i][0], y - R[i][1], x + R[i][0], y + R[i][1], 1.1f, 1.1f, WHITE);
+ }
+ } else {
+ for (int t = 0; t < 12; t++) fill((int)x - 2 - t * 3 / 4, (int)y - 4 + t, 5 + t * 3 / 2, 1, RGB(0x6D4C41));
+ blob(x - 2, y - 5, x + 2, y - 5, 1.8f, 1.8f, RGB(0xFF5722));
+ disc(x, y - 8, 1.6f, RGB(0xFFA000));
+ }
+ break;
+ default: /* O_MODE */
+ switch (v) {
+ case M_CLASSIC: trophy(x, y - 1, 0.95f, bg); break;
+ case M_WALL:
+ box((int)x - 8, (int)y - 7, 16, 15, 2, RGB(0x3D6624));
+ box((int)x - 8, (int)y - 7, 16, 12, 2, RGB(0x578A34));
+ fill((int)x - 7, (int)y - 2, 14, 1, RGB(0x3D6624));
+ fill((int)x - 1, (int)y - 6, 1, 4, RGB(0x3D6624));
+ fill((int)x - 5, (int)y - 1, 1, 5, RGB(0x3D6624));
+ fill((int)x + 3, (int)y - 1, 1, 5, RGB(0x3D6624));
+ break;
+ case M_PORTAL:
+ disc(x, y, 8, RGB(RING[0]));
+ disc(x, y, 5.5f, bg);
+ fruit(0, x, y, 9);
+ break;
+ case M_CHEESE:
+ for (int t = 0; t < 12; t++) fill((int)x - 8, (int)y - 5 + t, 2 + t * 4 / 3, 1, RGB(0xFFCA28));
+ fill((int)x - 8, (int)y + 7, 16, 1, RGB(0xF9A825));
+ disc(x - 4, y + 3, 1.8f, RGB(0xF9A825));
+ disc(x + 1, y + 5, 1.3f, RGB(0xF9A825));
+ disc(x - 5, y - 1, 1.2f, RGB(0xF9A825));
+ break;
+ case M_BORDERLESS:
+ for (int i = 0; i < 4; i++) {
+ fill((int)x - 8 + i * 5, (int)y - 8, 3, 2, WHITE), fill((int)x - 8 + i * 5, (int)y + 7, 3, 2, WHITE);
+ fill((int)x - 8, (int)y - 8 + i * 5, 2, 3, WHITE), fill((int)x + 7, (int)y - 8 + i * 5, 2, 3, WHITE);
+ }
+ blob(x - 3, y, x + 3, y, 2.5f, 2.5f, RGB(0x4E7CF6));
+ break;
+ case M_TWIN:
+ blob(x - 6, y, x + 6, y, 3.4f, 3.4f, RGB(0x4E7CF6));
+ for (int i = -1; i <= 1; i += 2) disc(x + i * 6, y - 1.5f, 1.4f, WHITE), disc(x + i * 6, y + 1.5f, 1.4f, WHITE);
+ break;
+ case M_WINGED:
+ for (int i = -1; i <= 1; i += 2) blob(x + i * 4, y - 1, x + i * 8, y - 4, 2.2f, 1.2f, WHITE);
+ fruit(0, x, y + 1, 12);
+ break;
+ case M_YINYANG:
+ disc(x, y, 7.5f, RGB(0x222222));
+ disc(x, y, 6.5f, WHITE);
+ clip((int)x, (int)y - 8, 9, 17);
+ disc(x, y, 6.5f, RGB(0x222222));
+ unclip();
+ disc(x, y - 3.25f, 3.25f, WHITE), disc(x, y + 3.25f, 3.25f, RGB(0x222222));
+ disc(x, y - 3.25f, 1, RGB(0x222222)), disc(x, y + 3.25f, 1, WHITE);
+ break;
+ case M_STATUE:
+ blob(x - 7, y + 4, x + 2, y + 4, 2.8f, 3.4f, RGB(0x8D949B));
+ blob(x + 2, y + 4, x + 5, y - 3, 3.4f, 4, RGB(0x9EA5AC));
+ disc(x + 5, y - 4, 1.6f, RGB(0x6B7278));
+ break;
+ case M_LIGHT:
+ box((int)x - 8, (int)y - 8, 16, 16, 3, RGB(0x1E2A22));
+ disc(x, y, 5.5f, RGB(0xFFF3B0));
+ disc(x, y, 3, WHITE);
+ break;
+ case M_MAGNET:
+ blob(x - 5, y - 7, x - 5, y + 1, 2.2f, 2.2f, RGB(0xE53935));
+ blob(x + 5, y - 7, x + 5, y + 1, 2.2f, 2.2f, RGB(0xE53935));
+ for (int i = 0; i < 4; i++) {
+ static const float C[5][2] = {{-5, 1}, {-3.5f, 4.5f}, {0, 6}, {3.5f, 4.5f}, {5, 1}};
+ blob(x + C[i][0], y + C[i][1], x + C[i + 1][0], y + C[i + 1][1], 2.2f, 2.2f, RGB(0xE53935));
+ }
+ fill((int)x - 7, (int)y - 8, 5, 3, RGB(0xCFD8DC)), fill((int)x + 3, (int)y - 8, 5, 3, RGB(0xCFD8DC));
+ break;
+ default: /* peaceful: a heart */
+ disc(x - 3.2f, y - 2, 4, RGB(0xEC407A)), disc(x + 3.2f, y - 2, 4, RGB(0xEC407A));
+ for (int t = 0; t < 7; t++) fill((int)x - 7 + t, (int)y + t, 15 - 2 * t, 1, RGB(0xEC407A));
+ break;
+ }
}
- blob(x + s * 0.02f, y - s * 0.2f, x + s * 0.08f, y - s * 0.42f, s * 0.05f, s * 0.04f, RGB(0x6D4C2F));
- disc(x, y + s * 0.05f, s * 0.37f, C_APPLE);
- disc(x - s * 0.14f, y - s * 0.05f, s * 0.09f, RGB(0xF58A67));
- blob(x + s * 0.1f, y - s * 0.34f, x + s * 0.33f, y - s * 0.44f, s * 0.09f, s * 0.035f, RGB(0x4E9F2D));
}
static float ease(uint32_t born, int ms) { /* 0 to 1 with a little overshoot */
@@ -312,22 +686,50 @@ static float ease(uint32_t born, int ms) { /* 0 to 1 with a little overshoot */
return 1 + t * t * (2.70158f * t + 1.70158f);
}
+/* where fruit is drawn: between its last cell and this one */
+static float fx_of(apple_t *a) { return ux(a->from) + (ux(a->p) - ux(a->from)) * prog; }
+static float fy_of(apple_t *a) { return uy(a->from) + (uy(a->p) - uy(a->from)) * prog; }
+static bool fruit_near(apple_t *a) { return near(a->p) || near(a->from); }
+
+/* an item of fruit: a portal has a ring in its pair's color */
+static void apple(apple_t *a) {
+ float s = cs * ease(a->born, 260), x = fx_of(a), y = fy_of(a);
+ if (a->kind) { /* a ring, and a smaller fruit in it */
+ disc(x, y, s * 0.5f, RGB(RING[a->kind - 1]));
+ disc(x, y, s * 0.35f, checker(a->p));
+ s *= 0.72f;
+ }
+ if (MODE == M_WINGED && !a->kind) {
+ float f = (float)((now >> 5) & 7) / 7, w = s * (0.12f + 0.1f * (f > 0.5f ? 1 - f : f));
+ for (int i = -1; i <= 1; i += 2) blob(x + i * s * 0.22f, y - s * 0.1f, x + i * s * 0.48f, y - s * 0.3f, w, w * 0.6f, WHITE);
+ }
+ fruit(V.opt[O_FRUIT], x, y, s);
+}
+
static void items(void) {
- for (int y = imax(qy0, 0); y <= imin(qy1, bh - 1); y++)
- for (int x = imax(qx0, 0); x <= imin(qx1, bw - 1); x++)
- if (occ[y * bw + x] & O_WALL) { /* a block of hedge */
- int p = x | y << 8, m = (int)(cs * (1 - (p == wpop ? ease(wborn, 300) : 1)) / 2) + 1, w = cs - 2 * m;
- int bx = fx + x * cs + m, by = fy + y * cs + m;
- box(bx, by, w, w, cs / 5, RGB(0x3D6624));
- box(bx, by, w, w - cs / 7 - 1, cs / 5, C_EDGE);
+ for (int y = imax(qy0, 0); y <= imin(qy1, bh - 1) && !shade; y++)
+ for (int x = imax(qx0, 0); x <= imin(qx1, bw - 1); x++) {
+ int o = occ[y * bw + x];
+ if (!(o & (O_WALL | O_STONE))) continue;
+ int p = x | y << 8, m = (int)(cs * (1 - (p == wpop ? ease(wborn, 300) : 1)) / 2) + 1, w = cs - 2 * m;
+ int bx = fx + x * cs + m, by = fy + y * cs + m;
+ if (o & O_WALL) { /* a block of hedge */
+ box(bx, by, w, w, cs / 5, mix(0, c_edge, 22));
+ box(bx, by, w, w - cs / 7 - 1, cs / 5, c_edge);
+ } else { /* stone */
+ box(bx, by, w, w, cs / 4, RGB(0x7B8288));
+ box(bx, by, w, w - cs / 7 - 1, cs / 4, RGB(0x9EA5AC));
}
- for (int i = 0; i < 6; i++) { /* portals the snake is going through: a dark hole under it */
+ }
+ for (int i = 0; i < 6 && !shade; i++) { /* portals a snake is going through: a dark hole under it */
int g = gate[i / 2][i & 1];
- if (g >= 0 && near(g) && (occ[at(g)] & O_BODY)) disc(ux(g), uy(g), cs * 0.36f, mix(RGB(ring[i / 2]), 0, 16));
+ if (g >= 0 && near(g) && (occ[at(g)] & O_BODY)) disc(ux(g), uy(g), cs * 0.36f, mix(RGB(RING[i / 2]), 0, 16));
}
for (int i = 0; i < 8; i++) {
apple_t *a = &ap[i];
- if (a->live && near(a->p)) apple(ux(a->p), uy(a->p), cs * ease(a->born, 260), a->kind, checker(a->p));
+ if (!a->live || !fruit_near(a)) continue;
+ if (shade) disc(fx_of(a), fy_of(a), cs * 0.36f * ease(a->born, 260), 0);
+ else apple(a);
}
}
@@ -339,71 +741,97 @@ static void rings(void) {
if (g < 0 || !near(g) || !(occ[at(g)] & O_BODY)) continue;
float c = 1, sn = 0, r = cs * 0.43f;
for (int k = 0; k < 16; k++) { /* 16 dots around, turning by 22.5 degrees */
- disc(ux(g) + c * r, uy(g) + sn * r, cs * 0.085f, RGB(ring[i / 2]));
+ disc(ux(g) + c * r, uy(g) + sn * r, cs * 0.085f, RGB(RING[i / 2]));
float c2 = c * 0.92388f - sn * 0.38268f;
sn = sn * 0.92388f + c * 0.38268f, c = c2;
}
}
}
-/* The head at (x, y), looking along (ax, ay), r its radius: an open mouth,
- and eyes that look where it goes. */
-static void face(float x, float y, float ax, float ay, float r) {
- if (mouth > 0.05f) {
- float mx = x + ax * r * 0.5f, my = y + ay * r * 0.5f, w = r * 0.45f * mouth, m = r * 0.42f * mouth;
- blob(mx - ay * w, my + ax * w, mx + ay * w, my - ax * w, m, m, RGB(0x7A1F1A));
- }
- for (int s = -1; s <= 1; s += 2) {
- float ex = x - ax * r * 0.1f - ay * r * 0.5f * s, ey = y - ay * r * 0.1f + ax * r * 0.5f * s, k = r * 0.22f;
- disc(ex, ey, r * 0.47f, WHITE);
- if (dead) {
- blob(ex - k, ey - k, ex + k, ey + k, r * 0.07f, r * 0.07f, 0);
- blob(ex - k, ey + k, ex + k, ey - k, r * 0.07f, r * 0.07f, 0);
- } else {
- disc(ex + ax * r * 0.2f, ey + ay * r * 0.2f, r * 0.25f, RGB(0x1B1B1B));
- }
- }
-}
-
-static float rad(float s) { return cs * (s >= 1.5f ? 0.41f : 0.25f + 0.107f * s); } /* thinner near the tail */
+static float rad(float s) { return cs * (s >= 1.5f ? 0.45f : 0.27f + 0.12f * s); } /* thinner near the tail */
/* The snake from cell a to cell b (entered going d), from u0 to u1 of the
way. Across an edge (wrapping) or a portal, a and b are not side by side:
each gets its own half, cut at its cell's border. */
-static void piece(int a, int b, int d, float u0, float u1, float r0, float r1) {
+static void piece(int a, int b, int d, float u0, float u1, float r0, float r1, color c) {
float sx = DX[d] * cs, sy = DY[d] * cs, ax = ux(a), ay = uy(a);
bool side = (a & 255) + DX[d] == (b & 255) && (a >> 8) + DY[d] == (b >> 8);
if (!side) cellclip(a);
- blob(ax + sx * u0, ay + sy * u0, ax + sx * u1, ay + sy * u1, r0, r1, scol);
+ blob(ax + sx * u0, ay + sy * u0, ax + sx * u1, ay + sy * u1, r0, r1, c);
if (side) return;
ax = ux(b) - sx, ay = uy(b) - sy;
cellclip(b);
- blob(ax + sx * u0, ay + sy * u0, ax + sx * u1, ay + sy * u1, r0, r1, scol);
+ blob(ax + sx * u0, ay + sy * u0, ax + sx * u1, ay + sy * u1, r0, r1, c);
fieldclip();
}
-static void snake(void) {
+static void snake(int n) {
+ snake_t *s = &S[n];
+ color c = snake_color(n), tail = mix(0, c, 5);
+ float p = prog, sh = s->tmove ? 1 - p : 0;
+ int k = s->tl, L = s->len;
fieldclip();
- float p = prog, s = tmove ? 1 - p : 0;
- int k = tl;
- if (tmove && (near(otail) || near(body[tl]))) piece(otail, body[tl], ndir[tl], p, 1, rad(0), rad(s));
- for (int i = 0; i < len - 1; i++) {
+ if (s->tmove && solid(s, s->tl + MAXN - 1) && solid(s, s->tl) && (near(s->otail) || near(s->body[s->tl])))
+ piece(s->otail, s->body[s->tl], s->ndir[s->tl] & 3, p, 1, rad(0), rad(sh), tail);
+ for (int i = 0; i < L - 1; i++) {
int k1 = (k + 1) % MAXN;
- float u = i == len - 2 ? p : 1;
- if (near(body[k]) || near(body[k1])) piece(body[k], body[k1], ndir[k1], 0, u, rad(s + i), rad(s + i + u));
+ float u = i == L - 2 ? p : 1;
+ bool a = solid(s, k), b = solid(s, k1) || k1 == s->hd;
+ if ((near(s->body[k]) || near(s->body[k1])) && a) {
+ color ci = mix(c, tail, 32 * (i + 1) / L);
+ if (b) piece(s->body[k], s->body[k1], s->ndir[k1] & 3, 0, u, rad(sh + i), rad(sh + i + u), ci);
+ else if (MODE == M_CHEESE) disc(ux(s->body[k]), uy(s->body[k]), rad(sh + i), ci); /* round, by a hole */
+ }
k = k1;
}
- int h = body[hd], b = body[(hd + MAXN - 1) % MAXN], d = ndir[hd], d0 = ndir[(hd + MAXN - 1) % MAXN];
+ int h = s->body[s->hd], b = s->body[(s->hd + MAXN - 1) % MAXN], d = s->ndir[s->hd] & 3, d0 = s->ndir[(s->hd + MAXN - 1) % MAXN] & 3;
+ if (L == 1) b = s->tmove ? s->otail : h;
if (near(h) || near(b)) {
/* the head turns over the first third of a step */
float w = p * 3 > 1 ? 1 : p * 3, ax = DX[d0] + (DX[d] - DX[d0]) * w, ay = DY[d0] + (DY[d] - DY[d0]) * w;
- float n = 1 / __builtin_sqrtf(ax * ax + ay * ay), r = cs * 0.41f;
+ float nn = 1 / __builtin_sqrtf(ax * ax + ay * ay + 1e-6f), r = cs * 0.45f;
bool side = (b & 255) + DX[d] == (h & 255) && (b >> 8) + DY[d] == (h >> 8);
- if (!side) cellclip(h);
- face(ux(h) - DX[d] * cs * (1 - p), uy(h) - DY[d] * cs * (1 - p), ax * n, ay * n, r);
- if (!side) {
- cellclip(b);
- face(ux(b) + DX[d] * cs * p, uy(b) + DY[d] * cs * p, ax * n, ay * n, r);
+ if (L == 1 || !solid(s, s->hd + MAXN - 1)) { /* no neck: the head alone */
+ if (!side) cellclip(h);
+ disc(ux(h) - DX[d] * cs * (1 - p), uy(h) - DY[d] * cs * (1 - p), r, c);
+ fieldclip();
+ }
+ if (!shade) {
+ if (!side) cellclip(h);
+ face(ux(h) - DX[d] * cs * (1 - p), uy(h) - DY[d] * cs * (1 - p), ax * nn, ay * nn, r);
+ if (!side) {
+ cellclip(b);
+ face(ux(b) + DX[d] * cs * p, uy(b) + DY[d] * cs * p, ax * nn, ay * nn, r);
+ }
+ }
+ }
+ unclip();
+}
+
+/* Light: dark all over but around the heads, wider for a while after fruit */
+static float light_r(void) {
+ int a = (int)(now - lit_t);
+ return cs * (2.4f + (a < 3000 ? 2.6f * (3000 - a) / 3000 : 0));
+}
+static void darkness(void) {
+ float r = light_r(), r2 = r * r, e = cs * 0.8f, o2 = (r + e) * (r + e), hx[2], hy[2];
+ for (int k = 0; k < ns; k++) { /* where the heads are drawn */
+ snake_t *s = &S[k];
+ int d = s->ndir[s->hd] & 3;
+ hx[k] = ux(s->body[s->hd]) - DX[d] * cs * (1 - prog), hy[k] = uy(s->body[s->hd]) - DY[d] * cs * (1 - prog);
+ }
+ clip(fx, fy, bw * cs, bh * cs);
+ for (int y = ky0; y < ky1; y++) {
+ color *p = buf + (y - ry) * rw - rx;
+ for (int x = kx0; x < kx1; x++) {
+ float d2 = 1e9f;
+ for (int k = 0; k < ns; k++) {
+ float dx = x + 0.5f - hx[k], dy = y + 0.5f - hy[k], q = dx * dx + dy * dy;
+ if (q < d2) d2 = q;
+ }
+ if (d2 <= r2) continue;
+ int a = d2 >= o2 ? 27 : (int)(27 * (d2 - r2) / (o2 - r2));
+ p[x] = mix(RGB(0x07100A), p[x], a);
}
}
unclip();
@@ -423,22 +851,6 @@ static void lab(const char *s, int x, int y, int large, color fg, color bg) {
static void clab(const char *s, int cx, int y, int large, color fg, color bg) {
lab(s, cx - slen(s) * (large ? 10 : 7) / 2, y, large, fg, bg);
}
-static void button(const char *s, int x, int y, int w, int h, bool on) {
- color c = on ? C_SNAKE : C_EDGE;
- if (!pass) box(x, y, w, h, h / 2, c);
- clab(s, x + w / 2, y + (h - 18) / 2, 1, WHITE, c);
-}
-/* n buttons from names[0], the first at (x, y), the others dx, dy further */
-static void buttons(const char *const *names, int n, int x, int y, int w, int dx, int dy) {
- for (int i = 0; i < n; i++) button(names[i], x + i * dx, y + i * dy, w, 32, sel == i);
-}
-static const char *const BUTTONS[] = {"Play", "Settings", "Resume", "Restart", "Quit game", "No", "Yes", "Play", "Menu"};
-static void panel(int x, int y, int w, int h) {
- if (pass) return;
- dim();
- box(x, y + 3, w, h, 14, RGB(0x2A4A18));
- box(x, y, w, h, 14, C_BAR);
-}
static char *itoa(char *o, int v) {
char t[8];
int n = 0;
@@ -447,111 +859,157 @@ static char *itoa(char *o, int v) {
*o = 0;
return o;
}
-
-static void trophy(float x, float y, float k, color bg) {
- for (int s = -1; s <= 1; s += 2) {
- disc(x + 6 * k * s, y - 4 * k, 3 * k, C_GOLD);
- disc(x + 6 * k * s, y - 4 * k, 1.4f * k, bg);
- }
- clip(0, (int)(y - 7 * k), 320, 240);
- blob(x, y - 7 * k, x, y, 7 * k, 2 * k, C_GOLD);
- unclip();
- fill((int)(x - k), (int)(y), (int)(2 * k + 1), (int)(4 * k), C_GOLD);
- box((int)(x - 5 * k), (int)(y + 3 * k), (int)(10 * k), (int)(3 * k), (int)k, C_GOLD);
+static char *cat(char *o, const char *s) {
+ while (*s) *o++ = *s++;
+ *o = 0;
+ return o;
}
-/* SNAKE in the snake's own tube: points x << 4 | y on a 4 x 8 grid, 0xF0 lifts
- the pen, 0xF1 goes to the next letter */
-static const uint8_t LOGO[] = {
- 0x41, 0x30, 0x10, 0x01, 0x03, 0x14, 0x34, 0x45, 0x47, 0x38, 0x18, 0x07, 0xF1,
- 0x08, 0x00, 0x48, 0x40, 0xF1,
- 0x08, 0x02, 0x20, 0x42, 0x48, 0xF0, 0x05, 0x45, 0xF1,
- 0x00, 0x08, 0xF0, 0x40, 0x04, 0x48, 0xF1,
- 0x40, 0x00, 0x08, 0x48, 0xF0, 0x04, 0x34,
-};
-static void logo(int x, int y) {
- for (int k = 0; k < 2; k++) { /* a shadow, then the snake */
- float px = 0, py = 0, u = 4.5f;
- int lx = x, ly = y + 3 - 3 * k;
- bool pen = false;
- for (unsigned i = 0; i < sizeof LOGO; i++) {
- int c = LOGO[i];
- if (c >= 0xF0) {
- pen = false, lx += c & 1 ? 30 : 0;
- continue;
+static void card(int x, int y, int w, int h) {
+ if (pass) return;
+ box(x, y + 3, w, h, 10, RGB(0x1C6E9C));
+ box(x, y, w, h, 10, C_CARD);
+}
+/* a Google blue button, with an icon: 0 none, 1 play, 2 gear, 3 dice, 4 back */
+static void button(const char *s, int x, int y, int w, int h, bool on, int ic) {
+ color c = on ? C_BTN : C_BTN2;
+ int tx = x + w / 2 + (ic ? 8 : 0);
+ if (!pass) {
+ if (on) box(x - 2, y - 2, w + 4, h + 4, 8, WHITE);
+ box(x, y, w, h, 6, c);
+ int cx = tx - slen(s) * 5 - 16, cy = y + h / 2;
+ if (ic == 1) tri(cx + 4, cy, 1, 0, 9, 5, WHITE);
+ if (ic == 2) {
+ for (int i = 0; i < 8; i++) {
+ static const int8_t R[8][2] = {{6, 0}, {4, 4}, {0, 6}, {-4, 4}, {-6, 0}, {-4, -4}, {0, -6}, {4, -4}};
+ disc(cx + R[i][0], cy + R[i][1], 1.6f, WHITE);
}
- float nx = lx + (c >> 4) * u, ny = ly + (c & 15) * u;
- if (pen) blob(px, py, nx, ny, 4.6f, 4.6f, k ? C_SNAKE : RGB(0x2A4A18));
- px = nx, py = ny, pen = true;
+ disc(cx, cy, 4.6f, WHITE), disc(cx, cy, 2, c);
+ }
+ if (ic == 3) {
+ box(cx - 6, cy - 6, 12, 12, 2, WHITE);
+ disc(cx - 3, cy - 3, 1.2f, c), disc(cx + 3, cy + 3, 1.2f, c), disc(cx, cy, 1.2f, c);
+ }
+ if (ic == 4) {
+ blob(cx - 5, cy, cx + 5, cy, 1.1f, 1.1f, WHITE);
+ blob(cx - 5, cy, cx - 1, cy - 4, 1.1f, 1.1f, WHITE), blob(cx - 5, cy, cx - 1, cy + 4, 1.1f, 1.1f, WHITE);
}
}
- disc(x + 19, y + 4.5f, 6.5f, C_SNAKE); /* the head, on the S */
- mouth = 0, dead = false;
- face(x + 20, y + 4.5f, 1, 0, 6.5f);
+ clab(s, tx, y + (h - 18) / 2, 1, WHITE, c);
}
-static const char *const OPT_NAME[6] = {"Speed", "Size", "Apples", "Walls", "Wrap", "Portals"};
-static const char *const OPT_VAL[] = {"Slow", "Normal", "Fast", "Small", "Medium", "Large", "1", "3", "5", "Off", "On"};
+static const char *const ROWS[NOPT] = {"Fruit", "Mode", "Count", "Speed", "Size", "Color", "Theme"};
+static const char *const NAMES[] = {
+ "Apple", "Banana", "Pineapple", "Grapes", "Strawberry", "Cherries",
+ "Classic", "Wall", "Portal", "Cheese", "Borderless", "Twin", "Winged", "Yin Yang", "Statue", "Light", "Magnet", "Peaceful",
+ "1", "3", "5",
+ "Normal", "Fast", "Slow",
+ "Normal", "Small", "Large",
+ "Blue", "Purple", "Pink", "Orange", "Yellow", "Teal", "White", "Black",
+ "Day", "Night", "Snow", "Volcano",
+};
+static const char *name_of(int o, int v) {
+ int b = 0;
+ for (int i = 0; i < o; i++) b += OPT_N[i];
+ return NAMES[b + v];
+}
+
+/* the card of the title and of the end of a game: the scores, and the snake
+ lying on the lawn */
+static void title_card(void) {
+ char t[8];
+ const int X = 62, Y = 28, W = 195, H = 124, F = Y + H - 30; /* the lawn from F */
+ card(X, Y, W, H);
+ if (!pass) {
+ fruit(V.opt[O_FRUIT], 124, Y + 22, 30);
+ trophy(196, Y + 24, 1.35f, C_CARD);
+ clip(X, F, W, Y + H - F);
+ box(X, F - 10, W, Y + H - F + 10, 10, c_light);
+ for (int j = 0; j < 2; j++)
+ for (int i = j & 1; i < 13; i += 2) fill(X + i * 15, F + j * 15, 15, 15, c_dark); /* light in the round corners */
+ clip(X, Y, W, H);
+ color c = snake_color(0);
+ blob(X - 10, F - 5, X + 118, F - 5, 10, 10, mix(0, c, 5));
+ blob(X + 118, F - 5, X + 140, F - 17, 10, 12.5f, c);
+ mouth = 0, dead = false;
+ face(X + 142, F - 19, 0.9f, -0.45f, 12.5f);
+ unclip();
+ }
+ itoa(t, played ? score : 0);
+ clab(t, 124, Y + 40, 1, WHITE, C_CARD);
+ itoa(t, *best());
+ clab(t, 196, Y + 40, 1, WHITE, C_CARD);
+ if (played && (won || newbest)) clab(won ? "You win!" : "New best!", 150, Y + 62, 0, RGB(0xFFF59D), C_CARD);
+}
/* the band on top, and the panel of the moment */
static void ui(void) {
- char t[8];
- if (!pass) apple(15, 13, 24, 0, C_BAR), trophy(84, 13, 1, C_BAR);
+ char t[24];
+ if (!pass) fruit(V.opt[O_FRUIT], 14, 12, 20), trophy(84, 13, 0.95f, c_bar);
itoa(t, score);
- lab(t, 30, 4, 1, WHITE, C_BAR);
+ lab(t, 28, 3, 1, WHITE, c_bar);
itoa(t, *best());
- lab(t, 98, 4, 1, WHITE, C_BAR);
+ lab(t, 98, 3, 1, WHITE, c_bar);
+ clab(name_of(O_MODE, MODE), 262, 5, 0, mix(WHITE, c_bar, 20), c_bar);
switch (state) {
case S_READY: /* the arrow keys, until the first move */
if (pass) break;
- box(116, 104, 88, 58, 10, C_BAR);
+ box(116, 104, 88, 58, 10, mix(0, c_bar, 16));
for (int d = 0; d < 4; d++) {
int x = 160 + DX[d] * 26, y = d == 3 ? 119 : 146;
- box(x - 11, y - 11, 22, 22, 5, RGB(0xE4EEDA));
- for (int t = 0, a; (a = 5 - t) >= 0; t++) /* a triangle, one line at a time */
- fill(x + DX[d] * (t - 2) - a * !DX[d], y + DY[d] * (t - 2) - a * !DY[d], DX[d] ? 1 : 2 * a + 1, DX[d] ? 2 * a + 1 : 1, C_BAR);
+ box(x - 11, y - 11, 22, 22, 5, WHITE);
+ tri(x + DX[d] * 4 + !DX[d] * 0, y + DY[d] * 4, DX[d] ? DX[d] : 0, DY[d], 8, 5, mix(0, c_bar, 16));
}
break;
case S_TITLE:
- panel(46, 42, 228, 176);
- if (!pass) {
- logo(70, 56);
- apple(238, 72, 34, 0, C_BAR);
- }
- buttons(BUTTONS, 2, 85, 114, 150, 0, 42);
- clab("Based on Tatone26's version", 160, 196, 0, C_PALE, C_BAR);
+ if (!pass) dim();
+ title_card();
+ button("Play", 62, 160, 195, 26, sel == 0, 1);
+ button("Settings", 62, 192, 195, 26, sel == 1, 2);
+ if (!pass) box(62, 223, 195, 16, 8, mix(0, c_bar, 18));
+ clab("Based on Tatone26's version", 160, 224, 0, RGB(0xC8D6BE), mix(0, c_bar, 18));
break;
- case S_SET:
- panel(28, 34, 264, 200);
- clab("Settings", 160, 44, 1, WHITE, C_BAR);
- for (int i = 0; i < 6; i++) {
- int y = 70 + i * 26, on = sel == i;
- color c = on ? C_SNAKE : C_BAR;
- if (on && !pass) box(40, y, 240, 24, 12, C_SNAKE);
- lab(OPT_NAME[i], 54, y + 3, 1, WHITE, c);
- clab(OPT_VAL[(i < 3 ? i * 3 : 9) + V.opt[i]], 226, y + 3, 1, WHITE, c);
- if (on) lab("<", 174, y + 3, 1, WHITE, c), lab(">", 268, y + 3, 1, WHITE, c);
+ case S_SET: {
+ const int X = 24, Y = 28, W = 272;
+ if (!pass) dim();
+ card(X, Y, W, 172);
+ cat(cat(cat(t, ROWS[row < NOPT ? row : 0]), ": "), name_of(row < NOPT ? row : 0, V.opt[row < NOPT ? row : 0]));
+ if (row < NOPT) clab(t, 160, Y + 5, 1, WHITE, C_CARD);
+ else clab("Settings", 160, Y + 5, 1, WHITE, C_CARD);
+ if (!pass) {
+ blob(X + 14, Y + 14, X + 24, Y + 14, 1.3f, 1.3f, WHITE);
+ blob(X + 14, Y + 14, X + 19, Y + 9, 1.3f, 1.3f, WHITE), blob(X + 14, Y + 14, X + 19, Y + 19, 1.3f, 1.3f, WHITE);
+ for (int o = 0; o < NOPT; o++) {
+ int y = Y + 36 + o * 21, n = OPT_N[o], x0 = 160 - n * 21 / 2 + 10;
+ color bg = o == row ? C_CARD2 : C_CARD;
+ if (o == row) box(X + 6, y - 10, W - 12, 21, 6, C_CARD2);
+ for (int v = 0; v < n; v++) {
+ int x = x0 + v * 21;
+ bool on = V.opt[o] == v;
+ if (on) box(x - 10, y - 10, 21, 21, 5, o == row ? WHITE : RGB(0xB3E5FC));
+ icon(o, v, x + 0.5f, y + 0.5f, on ? (o == row ? WHITE : RGB(0xB3E5FC)) : bg);
+ if (!on) wash(x - 10, y - 10, 21, 21, bg, 15);
+ }
+ }
}
+ static const char *const B[3] = {"Play", "Shuffle", "Reset"};
+ for (int i = 0; i < 3; i++) button(B[i], 24 + i * 94, 208, 84, 26, row == NOPT && sel == i, i ? i + 2 : 1);
break;
+ }
case S_PAUSE:
- panel(80, 54, 160, 160);
- clab("Paused", 160, 66, 1, WHITE, C_BAR);
- buttons(BUTTONS + 2, 3, 95, 94, 130, 0, 40);
+ if (!pass) dim();
+ card(70, 44, 180, 164);
+ clab("Paused", 160, 56, 1, WHITE, C_CARD);
+ button("Resume", 86, 88, 148, 28, sel == 0, 1);
+ button("Restart", 86, 124, 148, 28, sel == 1, 0);
+ button("Quit game", 86, 160, 148, 28, sel == 2, 0);
break;
case S_QUIT:
- panel(80, 76, 160, 100);
- clab("Quit game?", 160, 92, 1, WHITE, C_BAR);
- buttons(BUTTONS + 5, 2, 94, 127, 62, 70, 0);
- break;
- case S_OVER:
- panel(64, 54, 192, 140);
- if (!pass) apple(104, 88, 36, 0, C_BAR), trophy(190, 88, 1.6f, C_BAR);
- itoa(t, score);
- lab(t, 126, 79, 1, WHITE, C_BAR);
- itoa(t, *best());
- lab(t, 212, 79, 1, WHITE, C_BAR);
- if (won || newbest) clab(won ? "You win!" : "New best!", 160, 114, 1, C_GOLD, C_BAR);
- buttons(BUTTONS + 7, 2, 78, 147, 80, 84, 0);
+ if (!pass) dim();
+ card(76, 72, 168, 104);
+ clab("Quit game?", 160, 88, 1, WHITE, C_CARD);
+ button("No", 92, 128, 60, 28, sel == 0, 0);
+ button("Yes", 168, 128, 60, 28, sel == 1, 0);
break;
}
}
@@ -565,9 +1023,14 @@ static void area(int x, int y, int w, int h) {
qx0 = fl(rx - fx), qx1 = fl(rx + rw - 1 - fx), qy0 = fl(ry - fy), qy1 = fl(ry + rh - 1 - fy);
unclip();
ground();
+ shade = true, oy = cs * 0.14f; /* the shadows first */
+ items();
+ for (int k = 0; k < ns; k++) snake(k);
+ shade = false, oy = 0;
items();
- snake();
+ for (int k = 0; k < ns; k++) snake(k);
rings();
+ if (MODE == M_LIGHT && state != S_TITLE && state != S_SET) darkness();
pass = 0;
ui();
eadk_display_push_rect((eadk_rect_t){(uint16_t)rx, (uint16_t)ry, (uint16_t)rw, (uint16_t)rh}, buf);
@@ -576,21 +1039,42 @@ static void area(int x, int y, int w, int h) {
}
/* In play: only the cells that change, and those that changed last time
- (so they are left in their final state). */
-static uint16_t dcur[24], dprev[24];
+ (so they are left in their final state); each with the one below, where
+ shadows fall. */
+static uint16_t dcur[MAXN], dprev[MAXN];
+static uint8_t seen[MAXN], frame; /* seen: the frame a cell was last marked in */
static int ncur, nprev;
static void mark(int p) {
- for (int i = 0; i < ncur; i++)
- if (dcur[i] == p) return;
- if (ncur < 24) dcur[ncur++] = (uint16_t)p;
+ if ((p & 255) >= bw || (p >> 8) >= bh || seen[at(p)] == frame) return;
+ seen[at(p)] = frame, dcur[ncur++] = (uint16_t)p;
}
+static void mark2(int p) { mark(p), mark(p + 256); }
static void cells(void) {
+ if (!++frame)
+ for (int i = 0; i < MAXN; i++) seen[i] = 0;
ncur = 0;
- for (int i = 0; i < 3 && i < len; i++) mark(body[(hd + MAXN - i) % MAXN]), mark(body[(tl + i) % MAXN]);
- if (tmove) mark(otail);
+ for (int k = 0; k < ns; k++) {
+ snake_t *s = &S[k];
+ for (int i = 0; i < 3 && i < s->len; i++) mark2(s->body[(s->hd + MAXN - i) % MAXN]), mark2(s->body[(s->tl + i) % MAXN]);
+ if (s->tmove) mark2(s->otail);
+ }
for (int i = 0; i < 8; i++)
- if (ap[i].live && (ap[i].eat || (int)(now - ap[i].born) < 300)) mark(ap[i].p);
+ if (ap[i].live && (ap[i].eat || ap[i].from != ap[i].p || (int)(now - ap[i].born) < 300)) mark2(ap[i].p), mark2(ap[i].from);
if (wpop >= 0 && (int)(now - wborn) < 350) mark(wpop);
+ if (MODE == M_LIGHT) { /* the edge of the light: the cells it crosses (inside and out, nothing changes) */
+ float lr = light_r() / cs, a = lr - 1.3f, b = lr + 2.1f;
+ int r = (int)b + 1;
+ for (int k = 0; k < ns; k++) {
+ snake_t *s = &S[k];
+ int h = s->body[s->hd], x0 = (h & 255), y0 = h >> 8, d = s->ndir[s->hd] & 3;
+ float cx = x0 - DX[d] * (1 - prog), cy = y0 - DY[d] * (1 - prog);
+ for (int y = imax(0, y0 - r); y <= imin(bh - 1, y0 + r); y++)
+ for (int x = imax(0, x0 - r); x <= imin(bw - 1, x0 + r); x++) {
+ float q = (x - cx) * (x - cx) + (y - cy) * (y - cy);
+ if (q >= a * a * (a > 0) && q <= b * b) mark(x | y << 8);
+ }
+ }
+ }
int n = ncur;
for (int i = 0; i < nprev; i++) mark(dprev[i]);
for (int i = 0; i < ncur; i++) {
@@ -601,13 +1085,23 @@ static void cells(void) {
}
static void save(void) {
- V.magic = 'S', V.version = 1;
+ V.magic = 'S', V.version = 2;
ef_write(SAVE_NAME, &V, sizeof V);
}
/* the arrow keys, or 6 2 4 8, as directions */
static const uint32_t DIR_KEYS[4] = {KEY(eadk_key_right) | KEY(eadk_key_six), KEY(eadk_key_down) | KEY(eadk_key_two),
KEY(eadk_key_left) | KEY(eadk_key_four), KEY(eadk_key_up) | KEY(eadk_key_eight)};
+static const uint8_t OPT_DEF[NOPT] = {0, 0, 0, 0, 0, 0, 0};
+
+/* a turn for snake k (Yin Yang: the second turns the other way) */
+static void ask(int i) {
+ for (int k = 0; k < ns; k++) {
+ snake_t *s = &S[k];
+ int d = k ? i ^ 2 : i, l = s->nq ? s->q[s->nq - 1] : s->ndir[s->hd] & 3;
+ if (s->nq < 2 && d != l && (d != (l ^ 2) || s->len == 1)) s->q[s->nq++] = (uint8_t)d;
+ }
+}
int main(void) {
np_app_begin();
@@ -616,17 +1110,17 @@ int main(void) {
if (!seed) seed = 1;
uint32_t n = 0;
const uint8_t *d = ef_read(SAVE_NAME, &n);
- if (d && n == sizeof V && d[0] == 'S' && d[1] == 1) {
+ if (d && n == sizeof V && d[0] == 'S' && d[1] == 2) {
for (uint32_t i = 0; i < n; i++) ((uint8_t *)&V)[i] = d[i];
- for (int i = 0; i < 9; i++)
+ for (int i = 0; i < NBEST; i++)
if (V.best[i] > MAXN) V.best[i] = 0;
}
- for (int i = 0; i < 6; i++)
- if (!d || V.opt[i] >= OPT_N[i]) V.opt[i] = OPT_DEF[i];
+ for (int i = 0; i < NOPT; i++)
+ if (V.opt[i] >= OPT_N[i]) V.opt[i] = OPT_DEF[i];
new_game();
- state = S_TITLE, scol = C_SNAKE;
+ state = S_TITLE;
bool full = true, hdr = false, dirty = false;
- int resume = S_PLAY, flash = -1;
+ int resume = S_PLAY, flashed = -1;
uint32_t last = now, die_t = 0, rep_t = 0;
uint32_t held = keys();
for (;;) {
@@ -646,18 +1140,27 @@ int main(void) {
switch (state) {
case S_TITLE:
if (dk == 1 || dk == 3) sel ^= 1;
- else if (ok) state = sel ? S_SET : S_READY, sel = 0;
+ else if (ok && sel) state = S_SET, row = 0, sel = 0;
+ else if (ok) state = S_READY, played = false, new_game();
else if (back) resume = S_TITLE, state = S_QUIT, sel = 0; /* "Quit game?" from the title */
else redraw = false;
break;
case S_SET:
if (dk == 1 || dk == 3) {
- sel = (sel + (dk == 1 ? 1 : 5)) % 6;
+ row = (row + (dk == 1 ? 1 : NOPT)) % (NOPT + 1);
+ } else if ((dk == 0 || dk == 2) && row == NOPT) {
+ sel = (sel + (dk ? 2 : 1)) % 3;
} else if (dk == 0 || dk == 2) {
- V.opt[sel] = (uint8_t)((V.opt[sel] + (dk ? OPT_N[sel] - 1 : 1)) % OPT_N[sel]);
+ V.opt[row] = (uint8_t)((V.opt[row] + (dk ? OPT_N[row] - 1 : 1)) % OPT_N[row]);
new_game(), dirty = true;
- } else if (ok || back) {
- state = S_TITLE, sel = 1;
+ } else if (ok && row == NOPT && sel) { /* Shuffle, Reset */
+ for (int i = 0; i < NOPT; i++) V.opt[i] = sel == 1 ? (uint8_t)(rnd() % OPT_N[i]) : OPT_DEF[i];
+ new_game(), dirty = true;
+ } else if (ok) {
+ state = S_READY, played = false, new_game();
+ if (dirty) save(), dirty = false;
+ } else if (back) {
+ state = S_TITLE, sel = 1, played = false;
if (dirty) save(), dirty = false;
} else {
redraw = false;
@@ -670,22 +1173,23 @@ int main(void) {
resume = state, state = S_PAUSE, sel = 0, redraw = true;
break;
}
- for (int i = 0; i < 4; i++) { /* up to two turns ahead, never straight back */
- int l = nq ? q[nq - 1] : ndir[hd];
- if ((edge & DIR_KEYS[i]) && nq < 2 && i != l && i != (l ^ 2)) q[nq++] = (uint8_t)i;
- }
+ for (int i = 0; i < 4; i++)
+ if (edge & DIR_KEYS[i]) ask(i);
if (state == S_READY) {
- if (!nq && !(edge & (arrows | KEY(eadk_key_ok) | KEY(eadk_key_exe)))) break;
+ if (!S[0].nq && !(edge & (arrows | KEY(eadk_key_ok) | KEY(eadk_key_exe)))) break;
state = S_PLAY, full = true;
}
- int ate = score;
- bool crash = false, left = false;
- for (acc += dt; acc >= step_ms() && !crash; acc -= step_ms()) crash = !step();
- hdr |= score != ate;
- for (int i = 0; i < 8; i++) left |= ap[i].live && !ap[i].eat;
- if (crash || !left) { /* crashed, or no room left for an apple: the board is full */
- state = S_DIE, die_t = now, acc = step_ms(), dead = crash, won = !crash, newbest = score > *best();
- if (newbest) *best() = (uint16_t)score, save();
+ {
+ int ate = score;
+ bool crash = false, left = false;
+ for (acc += dt; acc >= step_ms() && !crash; acc -= step_ms()) crash = !step();
+ hdr |= score != ate;
+ for (int i = 0; i < 8; i++) left |= ap[i].live && !ap[i].eat;
+ if (crash || !left) { /* crashed, or no room left for fruit: the board is full */
+ state = S_DIE, die_t = now, acc = step_ms(), dead = crash, won = !crash, newbest = score > *best(), played = true;
+ if (newbest) *best() = (uint16_t)score, save();
+ }
+ prog = (float)acc / step_ms();
}
break;
case S_PAUSE:
@@ -703,20 +1207,16 @@ int main(void) {
break;
case S_DIE:
redraw = (int)(now - die_t) > 1100;
- if (redraw) state = S_OVER, sel = 0, scol = C_SNAKE;
- break;
- case S_OVER:
- if (dk == 0 || dk == 2) sel ^= 1;
- else if (ok || back) state = ok && !sel ? S_READY : S_TITLE, sel = 0, new_game();
- else redraw = false;
+ if (redraw) state = S_TITLE, sel = 0, flash = false;
break;
}
- if (state != S_DIE && state != S_OVER) dead = won = false;
+ if (state == S_TITLE && !played) dead = won = false;
full |= redraw;
- prog = (float)acc / step_ms();
if (prog > 1) prog = 1;
- /* the mouth opens on an apple just ahead, and shuts after a bite */
- int h = body[hd], ahead = ((h & 255) + DX[ndir[hd]]) | ((h >> 8) + DY[ndir[hd]]) << 8;
+ if (state != S_PLAY && state != S_DIE && state != S_READY) prog = 0;
+ /* the mouth opens on fruit just ahead, and shuts after a bite */
+ snake_t *s = &S[0];
+ int h = s->body[s->hd], ahead = ((h & 255) + DX[s->ndir[s->hd] & 3]) | ((h >> 8) + DY[s->ndir[s->hd] & 3]) << 8;
mouth = 1 - (int)(now - chew_t) / 160.0f;
for (int i = 0; i < 8; i++)
if (ap[i].live && (ap[i].p == h || (ap[i].p == ahead && !ap[i].eat && prog > mouth))) mouth = ap[i].p == h ? 1 : prog;
@@ -724,11 +1224,11 @@ int main(void) {
eadk_display_wait_for_vblank();
if (full) {
area(0, 0, 320, 240);
- full = hdr = false, nprev = 0, flash = -1;
+ full = hdr = false, nprev = 0, flashed = -1;
} else if (state == S_DIE) {
int f = (int)(now - die_t) / 150;
- if (f != flash && f < 7) { /* the snake flashes */
- flash = f, scol = f & 1 ? RGB(0xC9D8FF) : C_SNAKE;
+ if (f != flashed && f < 7) { /* the snake flashes */
+ flashed = f, flash = f & 1;
area(0, HDR, 320, 240 - HDR);
}
} else if (state == S_PLAY || state == S_READY) {
diff --git a/games/solitaire/README.md b/games/solitaire/README.md
index 81d2d726..7bc8d558 100644
--- a/games/solitaire/README.md
+++ b/games/solitaire/README.md
@@ -1,31 +1,31 @@
# Solitaire
-Klondike for the NumWorks calculator, the way Windows Solitaire plays it: green felt, the blue lattice card backs, Draw One or Draw Three, Standard or Vegas scoring, and the famous ending where the cards bounce off the bottom of the screen.
+Klondike for the NumWorks calculator, the way Google Solitaire (the game you get when you search for "solitaire") looks and plays: the deck and the waste on the left, the four foundations marked with their suits on the right, the dark bar with the time, score and moves, flat cards with two-tone suits and blue sunburst backs, and a red king for Easy or a blue king for Hard.
<img src="docs/shot.png" width="320" alt="A game in progress">
-- **Windows rules:** draw 1, 2 or 3 cards (Easy, Normal, Hard), and Standard, Vegas or no scoring. Vegas starts at -$52, pays $5 a card and limits the passes through the deck (as many as the cards you draw); **Keep score** adds your Vegas games up.
-- **Timed game:** the clock starts with your first move. In Standard scoring you lose 2 points every 10 seconds, and a fast win earns Windows' bonus (700,000 divided by your time).
-- **Help when you want it:** unlimited Undo, a Hint, OK twice to send a card up like a double click, a key that plays everything it can to the foundations, and an automatic finish once every card is face up.
+- **Choose your difficulty,** like Google's: **Easy** draws one card, **Hard** draws three.
+- **Undo and New** under the deck, as in Google's game, plus a Hint, OK twice to send a card up, a key that plays everything it can to the foundations, and an automatic finish once every card is face up.
+- **More than Google's:** Standard, Vegas or no scoring (Vegas starts at -$52, pays $5 a card and limits the passes through the deck; **Keep score** adds your Vegas games up), a timed game (lose 2 points every 10 seconds in Standard, and a bonus for a fast win), four card backs, and the famous ending where the cards bounce off the bottom of the screen.
- **Saved as you go:** leave in the middle of a game and continue it later. Statistics count your games, wins, streaks, best time, best score and your Vegas bank.
-Every card is drawn from a few tiny bitmaps (pips, court figures and one small font), and only what changes is redrawn, so the whole game is about 15 KB.
+Every card is drawn as it goes: suits from tiny bitmaps, court figures from a few shapes, and only what changes is redrawn.
## Controls
| Key | Action |
| --- | --- |
-| Arrows | Move |
-| Up / Down on a column | Pick up more or fewer cards |
-| OK | Pick up, put down (on the deck: draw) |
-| OK twice | Send the card to a foundation |
+| Left, Right | Move across: the deck, the seven columns, the foundations |
+| Up, Down | Pick up more or fewer cards in a column; move in the side columns (deck, waste, Undo, New; the foundations) |
+| OK | Pick up, put down (on the deck: draw; on Undo, New: press) |
+| OK twice | Send the card to its foundation |
| EXE | Draw from the deck |
| Toolbox | Play all you can to the foundations |
| ⌫ | Undo |
| Shift | Hint |
| Back | Put the cards back, or pause |
-Picked-up cards turn dark, like a selection in Windows. When you put a run down, the game finds how many cards fit there.
+When you put a run down, the game finds how many cards fit there.
## Scoring
@@ -35,13 +35,13 @@ Picked-up cards turn dark, like a selection in Windows. When you put a run down,
| Waste to a column | +5 | |
| Turning a card over | +5 | |
| Foundation back to a column | -15 | -$5 |
-| Recycling the deck | -100 (draw 1), -20 after 3 passes | not after the last pass |
+| Recycling the deck | -100 (Easy), -20 after 3 passes | not after the last pass |
## Credits
-Rewritten in C for NumPlay from Tatone26's Solitaire in [Numworks-games](https://github.com/Tatone26/Numworks-games/tree/main/apps/solitaire) (All the Apps), released into the public domain ([UNLICENSE](UNLICENSE)). It keeps that version's Difficulty option (how many cards you draw) and adds the Windows look, the deal and win animations, Standard and Vegas scoring, the clock, Undo, Hint, the automatic finish and statistics.
+The look follows **Google Solitaire** (Google Search, 2016 onwards). This is an independent fan version, drawn from shapes (no images from Google), and it isn't affiliated with or endorsed by Google.
-The look and the rules follow Microsoft's Windows Solitaire (Wes Cherry, with cards by Susan Kare).
+The code was rewritten in C for NumPlay from Tatone26's Solitaire in [Numworks-games](https://github.com/Tatone26/Numworks-games/tree/main/apps/solitaire) (All the Apps), released into the public domain ([UNLICENSE](UNLICENSE)). It keeps that version's Difficulty option (how many cards you draw) and adds the deal and win animations, the scoring, the clock, Undo, Hint, the automatic finish and statistics. The scoring and the bouncing cards come from Microsoft's Windows Solitaire (Wes Cherry).
It comes inside [NumPlay](https://github.com/Mason363/NumPlay), or on its own as `Solitaire.nwa` from the [latest release](https://github.com/Mason363/NumPlay/releases/latest).
diff --git a/games/solitaire/docs/shot.png b/games/solitaire/docs/shot.png
index 9a4ccb86..b16e429e 100644
Binary files a/games/solitaire/docs/shot.png and b/games/solitaire/docs/shot.png differ
diff --git a/games/solitaire/src/main.c b/games/solitaire/src/main.c
index 6b852630..8f9e2c2a 100644
--- a/games/solitaire/src/main.c
+++ b/games/solitaire/src/main.c
@@ -1,10 +1,13 @@
-/* Solitaire: Klondike, the way Windows Solitaire plays it, for the NumWorks
- * calculator. Rewritten in C for NumPlay from Tatone26's Solitaire in All the
- * Apps, which is in the public domain.
+/* Solitaire: Klondike the way Google Solitaire (the game in Search) plays
+ * and looks, for the NumWorks calculator: the deck and the waste on the
+ * left, the foundations on the right, the dark bar with the time, score and
+ * moves, flat cards with two-tone suits and blue sunburst backs, and "Choose
+ * your difficulty" to start. Rewritten in C for NumPlay from Tatone26's
+ * Solitaire in All the Apps, which is in the public domain.
*
* The table is drawn only where something changed: each changed rectangle is
* composed in a small buffer, strip by strip, and pushed once, so nothing
- * flickers. Cards, pips and court figures come from a few tiny bitmaps. */
+ * flickers. Suits are tiny bitmaps; the court figures are drawn from shapes. */
#include <eadk.h>
#include <stdbool.h>
#include <stdint.h>
@@ -21,18 +24,24 @@ typedef uint16_t color;
#define RGB(c) (color)((((c) >> 8) & 0xF800) | (((c) >> 5) & 0x07E0) | (((c) >> 3) & 0x1F))
#define WHITE 0xFFFF
#define BLACK 0
-#define FELT RGB(0x008000)
-#define SLOT RGB(0x003800)
-#define RED RGB(0xD00000)
-#define FACE RGB(0xC0C0C0)
-#define LIGHT RGB(0xDFDFDF)
-#define SHADOW RGB(0x808080)
-#define NAVY RGB(0x000080)
-#define GOLD RGB(0xFFD800)
+/* Google Solitaire's colors */
+#define FELT RGB(0x34A249)
+#define SIDE RGB(0x2B7B3B) /* the columns of the deck and the foundations */
+#define BAR RGB(0x313131) /* the bar on top */
+#define SLOT RGB(0x3C8D4B) /* an empty place in a side column */
+#define SLOT2 RGB(0x57A566) /* the suit on it */
+#define EDGE RGB(0xC9CDD1) /* a card's outline */
+#define INK RGB(0x202124) /* text on white */
+#define GREY RGB(0x5F6368)
+#define PALE RGB(0xE8EAED)
+#define BLUE RGB(0x1A73E8)
+#define GOLD RGB(0xFDD835) /* the cursor */
#define KEY(k) (1ull << (k))
+/* suits: spades, hearts, clubs, diamonds; each a light and a dark shade */
+static const color SUIT_C[2][2] = {{RGB(0x2F3A58), RGB(0x141624)}, {RGB(0xEF5050), RGB(0xBB2026)}};
+
/* ------------------------------------------------------------------ art */
-/* art begin */
/* suits: spades, hearts, clubs, diamonds (left half and middle column of each row) */
static const uint8_t pip7[4][7] = {{0x01,0x03,0x07,0x0F,0x06,0x01,0x03}, {0x06,0x0F,0x0F,0x0F,0x07,0x03,0x01}, {0x03,0x03,0x06,0x0F,0x06,0x01,0x03}, {0x01,0x03,0x07,0x0F,0x07,0x03,0x01}};
static const uint8_t pip13[4][15] = {
@@ -40,12 +49,6 @@ static const uint8_t pip13[4][15] = {
{0x00,0x38,0x7C,0x7E,0x7F,0x7F,0x7F,0x7F,0x3F,0x1F,0x0F,0x07,0x03,0x01,0x00},
{0x00,0x03,0x07,0x07,0x07,0x33,0x79,0x7F,0x7F,0x79,0x31,0x01,0x03,0x0F,0x00},
{0x01,0x03,0x07,0x07,0x0F,0x1F,0x3F,0x7F,0x3F,0x1F,0x0F,0x07,0x07,0x03,0x01}};
-/* court figures, top half, 22x16 at 3 bits a pixel (see court()) */
-static const uint8_t figs[3][133] = {
- {0x00,0x00,0x20,0x49,0x92,0x04,0x00,0x00,0x00,0x00,0x10,0x49,0x92,0xA4,0x00,0x40,0x00,0x00,0x88,0x24,0x49,0x92,0x94,0x84,0x01,0x00,0x20,0x24,0x49,0x92,0x64,0x48,0x06,0x00,0x00,0xE4,0x6D,0xDB,0x3E,0x48,0x02,0x00,0x00,0xF0,0x37,0x6D,0x7A,0x00,0x00,0x00,0x00,0xC0,0xDF,0xB6,0xED,0x01,0x00,0x00,0x00,0x00,0x7F,0xDB,0xB6,0x05,0x00,0x00,0x00,0x00,0xFC,0xAD,0xA4,0x16,0x00,0x00,0x00,0x00,0x80,0xBF,0x6D,0x0B,0x00,0x01,0x00,0x00,0x00,0x90,0xB6,0x0D,0x80,0x30,0x00,0x00,0x00,0xD9,0x48,0x72,0x0B,0xC2,0x00,0x00,0x80,0x6C,0x1B,0xB9,0x6D,0x09,0x03,0x00,0x40,0x36,0x69,0xDB,0xA4,0x2D,0x0C,0x00,0x20,0x9B,0x24,0xCD,0x9E,0xA4,0x85,0x01,0x80,0x6C,0x93,0x36,0x7B,0x93,0x16,0x06},
- {0x00,0x00,0x00,0x41,0x12,0x04,0x00,0x00,0x00,0x00,0x00,0x84,0x49,0x18,0x00,0x00,0x00,0x00,0x00,0x1E,0x92,0x64,0x0E,0x00,0x00,0x00,0x00,0x7F,0x92,0x24,0xF9,0x01,0x00,0x00,0x00,0xFC,0x6D,0xDB,0xB6,0x3F,0x00,0x00,0x00,0xFE,0x37,0x6D,0xD3,0xFF,0x00,0x00,0x00,0xF8,0xDF,0xB6,0x6D,0xFB,0x1F,0x00,0x00,0xE0,0x7F,0x5B,0xB5,0xED,0x7F,0x00,0x00,0x80,0xFF,0x6F,0xDB,0xF6,0xFF,0x41,0x00,0x00,0xF0,0x3F,0x6D,0x1B,0xFC,0xA0,0x08,0x00,0x40,0x42,0xB6,0x2D,0x99,0x00,0x04,0x00,0x20,0x92,0x48,0x92,0x94,0x14,0x04,0x00,0x10,0x49,0x93,0x48,0x69,0x92,0x12,0x00,0x88,0xA4,0x6D,0x92,0xB4,0x4D,0x52,0x00,0x44,0xD2,0x66,0x7B,0xB3,0xBD,0x49,0x0A,0x10,0x69,0x9B,0xED,0xCD,0xF6,0x36,0x29},
- {0x00,0x00,0x00,0x41,0x10,0x04,0x00,0x00,0x00,0x00,0x00,0x84,0x61,0x18,0x00,0x00,0x00,0x00,0x00,0x10,0x92,0x64,0x00,0x00,0x00,0x00,0x00,0x40,0x28,0x8E,0x01,0x00,0x00,0x00,0x00,0x20,0x49,0x92,0x24,0x00,0x00,0x00,0x00,0x80,0xBC,0x6D,0xDB,0x07,0x00,0x00,0x00,0x00,0xDE,0xB4,0xE9,0x11,0x00,0x00,0x00,0x00,0x78,0xDB,0xB6,0x3D,0x02,0x00,0x00,0x00,0xFC,0x6D,0xD3,0xF6,0x47,0x00,0x00,0x00,0xF0,0xBF,0x92,0xFA,0x1F,0x01,0x00,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0x24,0x00,0x00,0x20,0xDB,0xFF,0xFF,0xDF,0xC2,0x00,0x00,0x90,0x6D,0xFC,0xFF,0x73,0x5B,0x02,0x00,0xC8,0xA6,0x8D,0x24,0xB9,0x69,0x0B,0x00,0x64,0x93,0xB4,0xD9,0xDE,0x24,0x6D,0x01,0x90,0x6D,0xDA,0x66,0x7B,0x9B,0xB6,0x05}};
-/* art end */
/* ASCII 32..122 (space to z), columns of 7 bits, top bit first */
static const uint8_t font[91][5] = {
@@ -84,28 +87,37 @@ static int rx, ry, rw, rh;
static int min(int a, int b) { return a < b ? a : b; }
static int max(int a, int b) { return a > b ? a : b; }
+/* f over b; a from 0 (all b) to 32 (all f) */
+static color mix(color f, color b, int a) {
+ uint32_t x = (f | (uint32_t)f << 16) & 0x07E0F81F, y = (b | (uint32_t)b << 16) & 0x07E0F81F;
+ y = (y + ((x - y) * (uint32_t)a >> 5)) & 0x07E0F81F;
+ return (color)(y | y >> 16);
+}
static void fill(int x, int y, int w, int h, color c) {
int x0 = max(x, rx), x1 = min(x + w, rx + rw), y0 = max(y, ry), y1 = min(y + h, ry + rh);
if (x0 >= x1) return;
for (int j = y0; j < y1; j++)
for (color *p = buf + (j - ry) * rw + (x0 - rx), *e = p + (x1 - x0); p < e; p++) *p = c;
}
+/* darkens a rectangle, a from 0 (not at all) to 32 (black) */
+static void shadow(int x, int y, int w, int h, int a) {
+ int x0 = max(x, rx), x1 = min(x + w, rx + rw), y0 = max(y, ry), y1 = min(y + h, ry + rh);
+ for (int j = y0; j < y1; j++)
+ for (color *p = buf + (j - ry) * rw + (x0 - rx), *e = p + max(x1 - x0, 0); p < e; p++) *p = mix(0, *p, a);
+}
static void px(int x, int y, color c) {
if ((unsigned)(x - rx) < (unsigned)rw && (unsigned)(y - ry) < (unsigned)rh) buf[(y - ry) * rw + x - rx] = c;
}
-static void frame(int x, int y, int w, int h, int t, color c) {
- fill(x, y, w, t, c), fill(x, y + h - t, w, t, c), fill(x, y, t, h, c), fill(x + w - t, y, t, h, c);
-}
-/* the top and left edges in one colour, the bottom and right in another */
-static void bevel(int x, int y, int w, int h, color tl, color br) {
- fill(x, y, w, 1, tl), fill(x, y, 1, h, tl), fill(x, y + h - 1, w, 1, br), fill(x + w - 1, y, 1, h, br);
-}
-/* a card's shape: rounded corners, an outline o, filled with f */
-static void rrect(int x, int y, int w, int h, color o, color f) {
- fill(x + 2, y, w - 4, h, o), fill(x + 1, y + 1, w - 2, h - 2, o), fill(x, y + 2, w, h - 4, o);
- fill(x + 2, y + 1, w - 4, h - 2, f), fill(x + 1, y + 2, w - 2, h - 4, f);
+/* a rounded rectangle, corners of radius r (up to 8), filled with c */
+static void rbox(int x, int y, int w, int h, int r, color c) {
+ static const uint8_t cut[8][8] = {{0}, {1}, {1, 0}, {2, 1, 0}, {2, 1, 0, 0}, {3, 2, 1, 1, 0}, {3, 2, 1, 1, 0, 0}, {4, 3, 2, 1, 1, 0, 0}};
+ r = min(r, 7);
+ for (int j = 0; j < h; j++) {
+ int e = j < r ? cut[r][j] : j >= h - r ? cut[r][h - 1 - j] : 0;
+ fill(x + e, y + j, w - 2 * e, 1, c);
+ }
}
-/* a ring between radii r0 and r1 (a disc when r0 is 0) */
+/* a disc of radius r (a ring from r0) */
static void ring(int cx, int cy, int r0, int r1, color c) {
for (int dy = -r1; dy <= r1; dy++)
for (int dx = -r1; dx <= r1; dx++) {
@@ -113,30 +125,26 @@ static void ring(int cx, int cy, int r0, int r1, color c) {
if (d >= r0 * r0 && d <= r1 * r1 + r1) px(cx + dx, cy + dy, c);
}
}
-/* a left-right symmetric bitmap: each row holds the left half and the middle
- column, first column in the top bit; upside down when flip */
-static void sym(const uint8_t *rows, int n, int half, int x, int y, color c, int flip) {
- for (int j = 0; j < n; j++) {
- int r = rows[flip ? n - 1 - j : j];
+/* A left-right symmetric bitmap: each row holds the left half and the middle
+ column, first column in the top bit. Two-tone like Google's suits: the left
+ half in a, the rest in b. */
+static void sym(const uint8_t *rows, int n, int half, int x, int y, color a, color b) {
+ for (int j = 0; j < n; j++)
for (int i = 0; i < half; i++)
- if (r >> (half - 1 - i) & 1) px(x + i, y + j, c), px(x + 2 * half - 2 - i, y + j, c);
- }
+ if (rows[j] >> (half - 1 - i) & 1) px(x + i, y + j, i < half - 1 ? a : b), px(x + 2 * half - 2 - i, y + j, b);
}
-/* a character of the 5x7 font, k times bigger, turned upside down when flip */
-static void glyph(int ch, int x, int y, int k, color c, int flip) {
+/* a character of the 5x7 font, k times bigger, bold (one more column) when b */
+static void glyph(int ch, int x, int y, int k, color c, int b) {
const uint8_t *g = font[(unsigned)(ch - 32) < 91 ? ch - 32 : '?' - 32];
for (int i = 0; i < 5; i++)
for (int j = 0; j < 7; j++)
- if (g[i] >> j & 1) fill(x + (flip ? 4 - i : i) * k, y + (flip ? 6 - j : j) * k, k, k, c);
+ if (g[i] >> j & 1) fill(x + i * k, y + j * k, k + b, k, c);
}
static int slen(const char *s) {
int n = 0;
while (s[n]) n++;
return n;
}
-static void text(const char *s, int x, int y, int k, color c) {
- for (; *s; s++, x += 6 * k) glyph(*s, x, y, k, c, 0);
-}
/* the firmware's fonts, straight to the screen: 7x14 or 10x18 cells */
static void str(const char *s, int x, int y, int large, color fg, color bg) {
eadk_display_draw_string(s, (eadk_point_t){(uint16_t)x, (uint16_t)y}, large, fg, bg);
@@ -157,7 +165,11 @@ static char *num(char *o, int32_t v) {
*o = 0;
return o;
}
-/* Vegas dollars, written like Windows: -$52 */
+static char *two(char *o, int v) { /* 00 to 59 */
+ *o++ = (char)('0' + v / 10), *o++ = (char)('0' + v % 10), *o = 0;
+ return o;
+}
+/* Vegas dollars: -$52 */
static char *money(char *o, int32_t v) {
char *s = o;
o = num(cat(o, "$"), v);
@@ -167,11 +179,12 @@ static char *money(char *o, int32_t v) {
/* ------------------------------------------------------------------ cards */
enum { STOCK, WASTE, F0, T0 = 6, NP = 13 }; /* the piles */
+enum { B_UNDO = -2, B_NEW = -3 }; /* the buttons under the deck, for the cursor */
/* everything kept between visits (solitaire.sav): options, statistics and
the game in progress */
static struct {
- uint8_t magic, version, draw, scoring; /* scoring: 0 Standard, 1 Vegas, 2 none */
+ uint8_t magic, version, draw, scoring; /* draw: 1 Easy, 3 Hard; scoring: 0 Standard, 1 Vegas, 2 none */
uint8_t timed, keep, live, started; /* live: a game to continue */
uint8_t gdraw, gscoring, gtimed, passes; /* the game's own options; recycled decks */
uint8_t wfan, back, pad[2]; /* cards spread on the waste; the card back */
@@ -187,100 +200,121 @@ static struct {
#define UP 0x80
#define RANK(c) (((c) & 63) >> 2)
#define SUIT(c) ((c) & 3)
-#define CW 40
-#define CH 54
-#define COLX(i) (5 + (i) * 45)
-#define TOPY 2
-#define TABY 60
-#define STY 230 /* the status bar */
-#define FAN 15 /* the waste's spread, drawing 2 or 3 */
-
-/* where the pips of 2..10 go: groups of pips on a 3x13 grid, and which groups
- each rank uses. A group: column (bits 6-7), row (0-3), mirrored across the
- middle column (bit 4) and the middle row (bit 5). */
-static const uint8_t pip_group[8] = {0x60, 0x46, 0x30, 0x16, 0x43, 0x49, 0x34, 0x62};
-static const uint8_t pip_ranks[9] = {0x01, 0x03, 0x04, 0x06, 0x0C, 0x1C, 0x3C, 0x46, 0xC4};
-
-static void pip(int s, int col, int row, int x, int y, color c) {
- sym(pip7[s], 7, 4, x + 9 + col * 8, y + 10 + row * 9 / 4, c, row > 6);
-}
-
-/* the index in a corner: the rank in bold and a small suit; flip draws the
- one in the bottom right corner, upside down */
-static void corner(int c, int x, int y, color ink, int flip) {
- int r = RANK(c), u = 3;
- const char *s = r == 9 ? "10" : &"A23456789?JQK"[r];
- for (int n = r == 9 ? 2 : 1, i = 0; i < n; i++) {
- int w = s[i] == '1' ? 4 : 6, gx = s[i] == '1' ? u - 1 : u; /* the 1 of 10 is narrow */
- for (int b = 0; b < 2; b++) glyph(s[i], x + (flip ? CW - gx - 6 : gx) + b, y + (flip ? CH - 9 : 2), 1, ink, flip);
- u += w + (n == 2 && !i);
- }
- u++;
- sym(pip7[SUIT(c)], 7, 4, x + (flip ? CW - u - 7 : u), y + (flip ? CH - 9 : 2), ink, flip);
-}
-
-/* a court card: a framed figure, the bottom half the top one turned round */
-static void court(int c, int x, int y, color ink, color inv) {
- const uint8_t *f = figs[RANK(c) - 10];
- color pal[8] = {WHITE, BLACK, RED, RGB(0x2040C0), RGB(0xF0C020), RGB(0xF8D8B0), ink ^ inv, RGB(0x8C5014)};
- frame(x + 8, y + 10, 24, 34, 1, ink);
- for (int b = 0; b < 22 * 16; b++) {
- int v = (f[b * 3 >> 3] | f[(b * 3 >> 3) + 1] << 8) >> (b * 3 & 7) & 7, i = b % 22, j = b / 22;
- if (v) px(x + 9 + i, y + 11 + j, pal[v] ^ inv), px(x + 30 - i, y + 42 - j, pal[v] ^ inv);
- }
-}
-
-/* the backs of the Deck dialog, inside a white border: the classic blue
- lattice, a red one, a basket weave and diamonds */
-static const color backs[4][2] = {{RGB(0x1830A8), RGB(0x7890F0)}, {RGB(0xA01010), RGB(0xF07070)},
- {RGB(0x005850), RGB(0x50C8B0)}, {RGB(0x704000), RGB(0xF0C040)}};
-/* How much of a covered back shows. Squeezed under 6 px, the border shrinks
- so the pattern still shows; under 3 px even the edge takes its colour. */
-static int sq = 6;
-static void back(int x, int y) {
- int s = V.back & 3, t = sq < 6;
- rrect(x, y, CW, CH, sq < 3 ? backs[s][0] : BLACK, WHITE);
- int x0 = max(x + 3 - t, rx), x1 = min(x + CW - 3 + t, rx + rw), y0 = max(y + 3 - 2 * t, ry), y1 = min(y + CH - 3, ry + rh);
+#define CW 31
+#define CH 43
+#define BARH 18 /* the bar on top */
+#define SIDEW 38 /* the side columns */
+#define COLX(i) (42 + (i) * 34) /* the columns of the table */
+#define TABY 24
+#define LX 4 /* the deck, the waste and the buttons */
+#define RX 285 /* the foundations */
+#define WASTEY 72
+#define FAN 12 /* the waste's spread, drawing 2 or 3, downwards */
+#define FY(i) (24 + (i) * 48)
+#define UNDOY 172 /* the buttons */
+#define NEWY 204
+
+/* the backs: Google's blue sunburst, and red, green and purple ones */
+static const uint32_t BACKS[4][2] = {{0x3F9CFB, 0x40B7FE}, {0xE0463C, 0xF77B6E}, {0x2E9D57, 0x55C27D}, {0x7D52D9, 0xA07CF0}};
+
+/* a card's shape: round corners, an outline o, filled with f */
+static void cardshape(int x, int y, color o, color f) {
+ fill(x + 3, y, CW - 6, CH, o), fill(x + 1, y + 1, CW - 2, CH - 2, o), fill(x, y + 3, CW, CH - 6, o);
+ fill(x + 3, y + 1, CW - 6, CH - 2, f), fill(x + 2, y + 2, CW - 4, CH - 4, f), fill(x + 1, y + 3, CW - 2, CH - 6, f);
+}
+
+
+/* the back: a white border, rays of two blues from the middle, a white disc
+ with a four-color ring (shows only the rows in view: covered, a strip) */
+static void back(int x, int y, int style) {
+ cardshape(x, y, EDGE, WHITE);
+ color c0 = RGB(BACKS[style][0]), c1 = RGB(BACKS[style][1]);
+ int cx = x + CW / 2, cy = y + CH / 2, x0 = max(x + 3, rx), x1 = min(x + CW - 3, rx + rw), y0 = max(y + 3, ry), y1 = min(y + CH - 3, ry + rh);
for (int j = y0; j < y1; j++)
for (int i = x0; i < x1; i++) {
- int a = i - x, b = j - y;
- buf[(j - ry) * rw + i - rx] = backs[s][s < 2 ? ((a + b) & 3) == 1 || ((a - b) & 3) == 1
- : s == 2 ? (((a >> 2) + (b >> 2)) & 1 ? a : b) & 1
- : ((a + b) & 7) < 2 || ((a - b) & 7) < 2];
+ int dx = i - cx, dy = j - cy, a = dx < 0 ? -dx : dx, b = dy < 0 ? -dy : dy, m = min(a, b), M = max(a, b), d = dx * dx + dy * dy;
+ int w = a >= b ? m * 1000 >= M * 414 : 2 + (m * 1000 < M * 414); /* which of 4 rays in a quarter */
+ color c = w & 1 ? c0 : c1;
+ if (d <= 30) {
+ static const uint32_t Q[4] = {0xEA4335, 0x4285F4, 0xFBBC05, 0x34A853};
+ c = d >= 12 && d <= 20 ? RGB(Q[(dx < 0) + 2 * (dy >= 0)]) : WHITE;
+ }
+ buf[(j - ry) * rw + i - rx] = c;
}
}
-/* a card at (x, y); inv shows it selected (colours inverted, as in Windows) */
-static void card(int c, int x, int y, color inv) {
+/* A court figure, flat and two-tone like Google's: a bust in a robe of the
+ suit's colors (a, b), 24 x 28 units of s pixels. r: 10 jack, 11 queen, 12 king. */
+#define SKIN RGB(0xF6C4A0)
+#define SKIN2 RGB(0xE0A47E)
+#define CROWN RGB(0xF9C22E)
+static void portrait(int r, int x, int y, int s, color a, color b) {
+#define P(u, v, w, h, c) fill(x + (u) * s, y + (v) * s, (w) * s, (h) * s, c)
+ color hair = r == 11 ? RGB(0x2B2B3A) : r == 10 ? RGB(0x8A5230) : RGB(0xB0B0B0);
+ if (r == 11) P(6, 7, 12, 15, hair), P(7, 5, 10, 2, hair); /* the queen's long hair */
+ for (int t = 0; t < 9; t++) { /* the robe, wider at the bottom */
+ int hw = 6 + t / 2;
+ P(12 - hw, 19 + t, hw, 1, a), P(12, 19 + t, hw, 1, b);
+ }
+ P(10, 15, 4, 4, SKIN2); /* the neck */
+ P(9, 19, 6, 2, r == 10 ? WHITE : CROWN), P(11, 21, 2, 3, r == 10 ? WHITE : CROWN); /* the collar */
+ ring(x + 12 * s, y + 11 * s, 0, 5 * s, SKIN);
+ P(12, 7, 5, 9, SKIN), P(7, 7, 5, 9, SKIN), fill(x + 17 * s - 1, y + 9 * s, 1, 4 * s, SKIN2);
+ P(9, 11, 1, 1, INK), P(14, 11, 1, 1, INK); /* the eyes */
+ P(11, 14, 2, 1, RGB(0xC0504D)); /* the mouth */
+ if (r == 12) { /* the king's beard and moustache */
+ P(8, 14, 8, 2, RGB(0xE9E9E9)), P(9, 16, 6, 1, RGB(0xE9E9E9)), P(10, 17, 4, 1, RGB(0xD5D5D5));
+ P(9, 13, 6, 1, RGB(0xBDBDBD));
+ }
+ if (r != 11) P(7, 6, 10, 2, hair), P(7, 8, 1, 3, hair), P(16, 8, 1, 3, hair);
+ if (r >= 11) { /* a crown with three points */
+ int w = r == 12 ? 10 : 8, u = 12 - w / 2;
+ P(u, 3, w, 3, CROWN), P(u, 1, 2, 2, CROWN), P(11, 0, 2, 3, CROWN), P(u + w - 2, 1, 2, 2, CROWN);
+ P(11, 4, 2, 1, b);
+ } else { /* the jack's cap, and a feather */
+ P(6, 4, 12, 3, a), P(12, 4, 6, 3, b), P(8, 2, 8, 2, a), P(16, 0, 2, 4, CROWN);
+ }
+#undef P
+}
+
+/* a card at (x, y): the rank in bold and a small suit at the top, a big suit
+ (or a figure) below */
+static void card(int c, int x, int y) {
if (x >= rx + rw || x + CW <= rx || y >= ry + rh || y + CH <= ry) return;
if (!(c & UP)) {
- back(x, y);
+ back(x, y, V.back & 3);
return;
}
- int s = SUIT(c), r = RANK(c);
- color ink = (s & 1 ? RED : BLACK) ^ inv;
- rrect(x, y, CW, CH, BLACK ^ inv, WHITE ^ inv);
- corner(c, x, y, ink, 0);
- corner(c, x, y, ink, 1);
- if (!r) {
- sym(pip13[s], 15, 7, x + 14, y + 20, ink, 0);
- } else if (r < 10) {
- for (int g = 0, m = pip_ranks[r - 1]; g < 8; g++) {
- if (!(m >> g & 1)) continue;
- int b = pip_group[g], col = b >> 6, row = b & 15;
- pip(s, col, row, x, y, ink);
- if (b & 0x10) pip(s, 2 - col, row, x, y, ink);
- if (b & 0x20) pip(s, col, 12 - row, x, y, ink);
- if ((b & 0x30) == 0x30) pip(s, 2 - col, 12 - row, x, y, ink);
- }
+ int s = SUIT(c), r = RANK(c), red = s & 1;
+ color a = SUIT_C[red][0], b = SUIT_C[red][1], ink = red ? b : a;
+ cardshape(x, y, EDGE, WHITE);
+ if (r == 9) glyph('1', x + 1, y + 3, 1, ink, 1), glyph('0', x + 7, y + 3, 1, ink, 1);
+ else glyph("A23456789?JQK"[r], x + 3, y + 3, 1, ink, 1);
+ sym(pip7[s], 7, 4, x + CW - 11, y + 3, a, b);
+ if (r < 10) sym(pip13[s], 15, 7, x + 9, y + 19, a, b);
+ else portrait(r, x + 4, y + 13, 1, a, b);
+}
+
+/* the suit each foundation takes, top to bottom, as Google marks them */
+static const uint8_t FSUIT[4] = {1, 3, 2, 0};
+/* an empty place: in a side column, a darker card with a suit (-1: none);
+ on the felt, an outline */
+static void slot(int x, int y, int s) {
+ if (x < SIDEW || x > 320 - SIDEW) {
+ rbox(x, y, CW, CH, 3, SLOT);
+ if (s >= 0) sym(pip13[s], 15, 7, x + 9, y + 14, SLOT2, SLOT2);
} else {
- court(c, x, y, ink, inv);
+ rbox(x, y, CW, CH, 3, RGB(0x4DB361));
+ rbox(x + 1, y + 1, CW - 2, CH - 2, 3, FELT);
}
}
-/* an empty place, etched in the felt */
-static void slot(int x, int y) {
- rrect(x, y, CW, CH, RGB(0x00A800), FELT);
- rrect(x, y, CW - 1, CH - 1, SLOT, FELT);
+/* a 2-pixel frame with round corners */
+static void rframe(int x, int y, int w, int h, color c) {
+ fill(x + 2, y, w - 4, 2, c), fill(x + 2, y + h - 2, w - 4, 2, c), fill(x, y + 2, 2, h - 4, c), fill(x + w - 2, y + 2, 2, h - 4, c);
+ px(x + 1, y + 1, c), px(x + w - 2, y + 1, c), px(x + 1, y + h - 2, c), px(x + w - 2, y + h - 2, c);
+}
+static void text(const char *s, int x, int y, color c) {
+ for (; *s; s++, x += 6) glyph(*s, x, y, 1, c, 0);
}
/* ------------------------------------------------------------------ state */
@@ -299,16 +333,16 @@ static uint32_t rnd(void) {
top card alone) */
static int fan(void) { return min(min(max(V.wfan, 1), V.gdraw), pn[WASTE]); }
-/* each column's spread, squeezed until it fits above the status bar */
+/* each column's spread, squeezed until it fits the screen */
static void relayout(void) {
for (int i = 0; i < 7; i++) {
- int n = pn[T0 + i], d = 0, a = 6, b = 13;
+ int n = pn[T0 + i], d = 0, a = 5, b = 13;
while (d < n && !(pl[T0 + i][d] & UP)) d++;
- /* face up to 9 px (the index still shows whole), face down to 3, face
- up to 8, then whatever it takes */
- while (d * a + max(n - d - 1, 0) * b > STY - 2 - TABY - CH) {
- if (b > 9 || (a < 4 && b > 8)) b--;
- else if (a > 1) a--;
+ /* face up to 11 px, face down to 2, face up to 10 (the rank still shows
+ whole), then whatever it takes */
+ while (d * a + max(n - d - 1, 0) * b > 240 - 2 - TABY - CH) {
+ if (b > 11 || (a < 3 && b > 10)) b--;
+ else if (a > 2) a--;
else if (b > 1) b--;
else break;
}
@@ -318,13 +352,12 @@ static void relayout(void) {
/* where card k of pile p lies (k may be the free place above the top) */
static void pos(int p, int k, int *x, int *y) {
- *y = TOPY;
if (p == STOCK) {
- *x = COLX(0);
+ *x = LX, *y = TABY;
} else if (p == WASTE) {
- *x = COLX(1) + max(k - (pn[WASTE] - fan()), 0) * FAN;
+ *x = LX, *y = WASTEY + max(k - (pn[WASTE] - fan()), 0) * FAN;
} else if (p < T0) {
- *x = COLX(p + 1);
+ *x = RX, *y = FY(p - F0);
} else {
int i = p - T0, d = fd[i];
*x = COLX(i);
@@ -334,6 +367,7 @@ static void pos(int p, int k, int *x, int *y) {
/* how many cards from the top can be picked up together */
static int run(int p) {
+ if (p < 0) return 0;
int n = pn[p], k = 1;
if (!n || !(pl[p][n - 1] & UP)) return 0;
if (p < T0) return 1;
@@ -348,7 +382,7 @@ static int run(int p) {
static int legal(int f, int n, int t) {
if (f == t || t < F0 || (f >= F0 && f < T0 && t < T0) || n < 1 || n > run(f)) return 0;
int c = pl[f][pn[f] - n], top = pn[t] ? pl[t][pn[t] - 1] : -1;
- if (t < T0) return n == 1 && (top < 0 ? RANK(c) == 0 : SUIT(top) == SUIT(c) && RANK(top) + 1 == RANK(c));
+ if (t < T0) return n == 1 && SUIT(c) == FSUIT[t - F0] && (top < 0 ? RANK(c) == 0 : RANK(top) + 1 == RANK(c));
return top < 0 ? RANK(c) == 12 : RANK(top) == RANK(c) + 1 && ((top ^ c) & 1);
}
@@ -356,9 +390,11 @@ static int legal(int f, int n, int t) {
static np_jump_t leave; /* Home and On/Off leave from anywhere through it */
static uint64_t held, pend, rep; /* keys down, presses not handled yet, arrows that repeat */
static uint32_t repeat_at, last_frame;
-static int layer; /* what the screen shows: 0 the table, 1 the title, 2 one widget */
+static int layer; /* what the screen shows: 0 the table, 1 the table under the start, 2 one widget */
static int ticking; /* the game's clock runs (not in dialogs) */
+static const char *msg;
static void scene(void);
+static void over_text(int x, int y, int w, int h);
/* draws the scene over a rectangle of the screen and pushes it */
static void paint(int x, int y, int w, int h) {
@@ -371,6 +407,7 @@ static void paint(int x, int y, int w, int h) {
scene();
eadk_display_push_rect((eadk_rect_t){(uint16_t)rx, (uint16_t)ry, (uint16_t)rw, (uint16_t)rh}, buf);
}
+ if (!layer) over_text(x, y, w, h);
}
/* rectangles to repaint at the next frame, merged when they overlap */
@@ -394,10 +431,14 @@ static void dirty(int x, int y, int w, int h) {
ndr++;
}
static void dirty_pile(int p) {
- if (p < T0) dirty(COLX(p == STOCK ? 0 : p == WASTE ? 1 : p + 1) - 2, 0, CW + 4 + (p == WASTE) * 2 * FAN, TABY - 2);
- else dirty(COLX(p - T0) - 2, TABY - 2, CW + 4, STY - TABY + 2);
+ if (p == STOCK) dirty(LX - 2, TABY - 2, CW + 6, CH + 6);
+ else if (p == WASTE) dirty(LX - 2, WASTEY - 2, CW + 4, CH + 4 + 2 * FAN);
+ else if (p < T0) dirty(RX - 2, FY(p - F0) - 2, CW + 4, CH + 4);
+ else dirty(COLX(p - T0) - 2, TABY - 2, CW + 4, 240 - TABY + 2);
}
-static void dirty_status(void) { dirty(0, STY, 320, 10); }
+static void dirty_bar(void) { dirty(0, 0, 320, BARH); }
+#define TOAST_Y 216 /* a message at the bottom of the table */
+static void dirty_toast(void) { dirty(SIDEW, TOAST_Y, 320 - 2 * SIDEW, 20); }
/* keys: presses since the last look, arrows repeating while held */
static void poll(void) {
@@ -434,66 +475,47 @@ static uint64_t take(void) {
#define OK_KEYS (KEY(eadk_key_ok) | KEY(eadk_key_exe))
/* ------------------------------------------------------------------ widgets */
-/* Windows 95 style: grey faces, bevelled edges, a navy title bar, and navy
- for the focus too. Widgets are painted one at a time (layer 2); their text
- is the firmware's font, drawn over them afterwards. */
-enum { W_WIN, W_BTN, W_RADIO, W_CHECK, W_GROUP, W_ITEM, W_BACK };
+/* Google's dialogs: white cards with round corners, pill buttons (blue when
+ in focus), round radio buttons and check boxes. Widgets are painted one at
+ a time (layer 2); their text is the firmware's font, drawn over them
+ afterwards. */
+enum { W_WIN, W_BTN, W_RADIO, W_CHECK, W_GROUP, W_BACK };
#define F_ON 1 /* a radio button or a box that is on */
#define F_FOCUS 2
#define F_OFF 4 /* greyed out */
static int wt, wx, wy, ww, wh, wf;
static const char *wl;
-static void button(int x, int y, int w, int h, int focus) {
- if (focus) frame(x, y, w, h, 1, BLACK), x++, y++, w -= 2, h -= 2;
- fill(x, y, w, h, focus ? NAVY : FACE);
- bevel(x, y, w, h, WHITE, BLACK);
- bevel(x + 1, y + 1, w - 2, h - 2, LIGHT, SHADOW);
-}
-/* a navy title bar and n of its buttons: close, maximize, minimize */
-static void caption(int x, int y, int w, int n) {
- fill(x, y, w, 20, NAVY);
- for (int i = 0; i < n; i++) {
- int bx = x + w - 18 - i * 16 - (i > 0) * 2;
- button(bx, y + 3, 16, 14, 0);
- if (!i) glyph('x', bx + 5, y + 6, 1, BLACK, 0);
- else if (i == 1) frame(bx + 3, y + 5, 9, 9, 1, BLACK), fill(bx + 3, y + 6, 9, 1, BLACK);
- else fill(bx + 4, y + 12, 6, 2, BLACK);
- }
-}
static void widget_draw(void) {
int x = wx, y = wy, f = wf & F_FOCUS;
- fill(x, y, ww, wh, wt == W_ITEM && f ? NAVY : FACE);
if (wt == W_WIN) {
- bevel(x, y, ww, wh, LIGHT, BLACK);
- bevel(x + 1, y + 1, ww - 2, wh - 2, WHITE, SHADOW);
- caption(x + 3, y + 3, ww - 6, 1);
+ rbox(x, y, ww, wh, 7, WHITE);
if (wf) { /* the question mark */
- ring(x + 30, y + 46, 0, 14, RGB(0x1040D0));
- ring(x + 30, y + 46, 13, 14, BLACK);
- glyph('?', x + 25, y + 39, 2, WHITE, 0);
+ ring(x + 30, y + 50, 0, 14, BLUE);
+ glyph('?', x + 25, y + 43, 2, WHITE, 0);
}
- } else if (wt == W_BTN) {
- button(x, y, ww, wh, f);
- } else if (wt == W_GROUP) {
- bevel(x, y + 7, ww - 1, wh - 8, SHADOW, WHITE);
- bevel(x + 1, y + 8, ww - 1, wh - 8, WHITE, SHADOW);
+ return;
+ }
+ fill(x, y, ww, wh, WHITE);
+ if (wt == W_BTN) {
+ rbox(x, y, ww, wh, 7, f ? BLUE : PALE);
} else if (wt == W_BACK) { /* a card back to pick, style in the high bits */
- int s = V.back;
- if (f) frame(x, y, ww, wh, 2, NAVY);
- V.back = (uint8_t)(wf >> 4), back(x + 4, y + 4), V.back = (uint8_t)s;
- } else if (wt != W_ITEM) {
+ if (f) rbox(x, y, ww, wh, 5, PALE);
+ if (wf & F_ON) rframe(x + 1, y + 1, ww - 2, wh - 2, BLUE);
+ back(x + 4, y + 4, wf >> 4);
+ } else if (wt != W_GROUP) {
+ if (f) rbox(x + 14, y - 1, slen(wl) * 7 + 10, 18, 5, PALE);
+ color c = wf & F_OFF ? PALE : wf & F_ON ? BLUE : GREY;
if (wt == W_RADIO) {
- ring(x + 6, y + 8, 0, 6, SHADOW);
- ring(x + 6, y + 8, 0, 5, WHITE);
- if (wf & F_ON) ring(x + 6, y + 8, 0, 2, BLACK);
+ ring(x + 6, y + 8, 0, 6, c);
+ ring(x + 6, y + 8, 0, 4, WHITE);
+ if (wf & F_ON) ring(x + 6, y + 8, 0, 2, c);
} else {
- bevel(x, y + 2, 13, 13, SHADOW, WHITE);
- bevel(x + 1, y + 3, 11, 11, BLACK, LIGHT);
- fill(x + 2, y + 4, 9, 9, wf & F_OFF ? FACE : WHITE);
- for (int i = 0; (wf & F_ON) && i < 7; i++) fill(x + 3 + i, y + 5 + (i <= 2 ? i + 2 : 6 - i), 1, 3, wf & F_OFF ? SHADOW : BLACK);
+ rbox(x, y + 2, 13, 13, 2, c);
+ if (wf & F_ON)
+ for (int i = 0; i < 7; i++) fill(x + 3 + i, y + 6 + (i <= 2 ? i + 2 : 6 - i), 1, 2, WHITE);
+ else rbox(x + 2, y + 4, 9, 9, 1, WHITE);
}
- if (f) fill(x + 16, y, slen(wl) * 7 + 4, 16, NAVY);
}
}
/* paints a widget, then its label */
@@ -503,14 +525,15 @@ static void widget(int t, int x, int y, int w, int h, const char *label, int f)
paint(x, y, w, h);
layer = l;
if (!label) return;
+ color bg = t == W_BTN ? (f & F_FOCUS ? BLUE : PALE) : f & F_FOCUS ? PALE : WHITE;
+ color fg = t == W_BTN && (f & F_FOCUS) ? WHITE : t == W_GROUP ? BLUE : f & F_OFF ? GREY : INK;
if (t == W_BTN) x += (w - slen(label) * 7) / 2 - 18, y += (h - 14) / 2 - 1;
- else if (t == W_GROUP) x -= 11, y--;
- else if (t == W_ITEM) y++;
- str(label, x + 18, y + 1, 0, f & F_OFF ? SHADOW : f & F_FOCUS ? WHITE : BLACK, f & F_FOCUS ? NAVY : FACE);
+ else if (t == W_GROUP) x -= 18, bg = WHITE;
+ str(label, x + 18, y + 1, 0, fg, bg);
}
static void win(int x, int y, int w, int h, const char *title, int icon) {
widget(W_WIN, x, y, w, h, 0, icon);
- str(title, x + 7, y + 6, 0, WHITE, NAVY);
+ str(title, x + 16, y + 9, 1, INK, WHITE);
}
/* A dialog box: text lines, then buttons (in a column when vert). Returns the
@@ -525,9 +548,9 @@ static int dialog(const char *title, const char *body, const char *const *btn, i
s += n + (s[n] == '\n');
}
for (int i = 0; i < nb; i++) bw = max(bw, slen(btn[i]) * 7 + 28);
- int bb = vert ? bw : nb * bw + (nb - 1) * 10, w = max(max(tw + ix, bb) + 36, slen(title) * 7 + 44);
- int th = max(lines * 16, icon ? 36 : 0), h = 34 + th + (th ? 12 : 0) + (vert ? nb * 30 - 6 : 24) + 12;
- int x = (320 - w) / 2, y = (240 - h) / 2, by = y + 34 + th + (th ? 12 : 0), f = 0;
+ int bb = vert ? bw : nb * bw + (nb - 1) * 10, w = max(max(tw + ix, bb) + 36, slen(title) * 10 + 36);
+ int th = max(lines * 16, icon ? 36 : 0), h = 38 + th + (th ? 12 : 0) + (vert ? nb * 30 - 6 : 24) + 14;
+ int x = (320 - w) / 2, y = (240 - h) / 2, by = y + 38 + th + (th ? 12 : 0), f = 0;
box[0] = (int16_t)x, box[1] = (int16_t)y, box[2] = (int16_t)w, box[3] = (int16_t)h;
ndr = 0, ticking = 0; /* nothing of the table shows through, and the clock stops */
win(x, y, w, h, title, icon);
@@ -535,7 +558,7 @@ static int dialog(const char *title, const char *body, const char *const *btn, i
for (int i = 0, n; body && *body; i++, body += n + (body[n] == '\n')) {
for (n = 0; body[n] && body[n] != '\n' && n < 47; n++) ln[n] = body[n];
ln[n] = 0;
- str(ln, x + 18 + ix, y + 34 + (th - lines * 16) / 2 + i * 16, 0, BLACK, FACE);
+ str(ln, x + 18 + ix, y + 38 + (th - lines * 16) / 2 + i * 16, 0, GREY, WHITE);
}
for (uint64_t e = 0;; e = take()) {
int d = (e & KEY(vert ? eadk_key_down : eadk_key_right) ? 1 : 0) - (e & KEY(vert ? eadk_key_up : eadk_key_left) ? 1 : 0);
@@ -551,12 +574,12 @@ static int dialog(const char *title, const char *body, const char *const *btn, i
}
/* ------------------------------------------------------------------ the table */
-static int cp = T0 + 3, cd = 1; /* the cursor: pile, and cards picked with Up in a column */
-static int sp = -1, sn; /* the cards picked up: pile and count */
-static int hint_p = -1; /* the pile a hint points to */
-static int nocur; /* hides the cursor: dealing, winning */
+static int cp = T0 + 3, cd = 1; /* the cursor: pile (or button), and cards picked with Up in a column */
+static int lastl = WASTE, lastr = F0; /* where the cursor was in the side columns */
+static int sp = -1, sn; /* the cards picked up: pile and count */
+static int hint_p = -1; /* the pile a hint points to */
+static int nocur; /* hides the cursor: dealing, winning */
static uint32_t hint_until, msg_until;
-static const char *msg;
/* cards in flight: they are hidden in their pile until they land */
typedef struct {
@@ -575,8 +598,12 @@ static void fly_pos(const fly_t *f, int *x, int *y) {
}
static int shown(int c) { return !(hid >> (c & 63) & 1); }
-/* the cursor's rectangle: the cards it points at */
+/* the cursor's rectangle: the cards (or the button) it points at */
static void cur_rect(int *x, int *y, int *h) {
+ if (cp < 0) {
+ *x = LX, *y = cp == B_UNDO ? UNDOY - 3 : NEWY - 3, *h = 30;
+ return;
+ }
int n = pn[cp], y1;
pos(cp, max(n - (cp >= T0 ? cd : 1), 0), x, y);
pos(cp, max(n - 1, 0), x, &y1);
@@ -585,80 +612,114 @@ static void cur_rect(int *x, int *y, int *h) {
static void dirty_cursor(void) {
int x, y, h;
cur_rect(&x, &y, &h);
- dirty(x - 2, y - 2, CW + 4, h + 4);
+ dirty(x - 3, y - 3, CW + 6, h + 6);
}
static void set_cursor(int p, int d) {
dirty_cursor();
cp = p, cd = p >= T0 ? max(min(d, run(p)), 1) : 1;
+ if (p < 0 || p <= WASTE) lastl = p;
+ else if (p < T0) lastr = p;
dirty_cursor();
}
static void say(const char *s) {
msg = s, msg_until = now + 1800;
- dirty_status();
+ dirty_toast();
}
/* with Keep score, Vegas shows the bank, which already holds a finished game */
static int32_t shown_score(void) { return V.gscoring == 1 && V.keep ? V.bank + (V.live ? V.score : 0) : V.score; }
+static int can_recycle(void) { return V.gscoring != 1 || V.passes < V.gdraw - 1; }
-static void status_bar(void) {
- char s[64], *o = s;
- fill(0, STY, 320, 10, FACE);
- fill(0, STY, 320, 1, WHITE);
- o = num(cat(o, "Moves: "), V.moves);
- if (V.gscoring < 2) o = (V.gscoring ? money : num)(cat(o, " Score: "), shown_score());
- if (V.gtimed) o = num(cat(o, " Time: "), (int32_t)(V.ms / 1000));
- text(s, 316 - (int)(o - s) * 6, STY + 2, 1, BLACK);
- if (msg) fill(0, STY + 1, slen(msg) * 6 + 8, 9, FACE), text(msg, 4, STY + 2, 1, BLACK);
+/* the text over the table: the bar's figures, and a message */
+static void over_text(int x, int y, int w, int h) {
+ char s[16], *o;
+ if (y < BARH) {
+ uint32_t t = V.live || V.ms ? V.ms / 1000 : 0;
+ o = num(s, (int32_t)(t / 3600));
+ o = two(cat(o, ":"), (int)(t / 60 % 60));
+ two(cat(o, ":"), (int)(t % 60));
+ str(s, 96, 2, 0, WHITE, BAR);
+ if (V.gscoring < 2) {
+ str("Score", 162, 2, 0, RGB(0x9AA0A6), BAR);
+ (V.gscoring ? money : num)(s, shown_score());
+ str(s, 204, 2, 0, WHITE, BAR);
+ }
+ str("Moves", 250, 2, 0, RGB(0x9AA0A6), BAR);
+ num(s, V.moves);
+ str(s, 292, 2, 0, WHITE, BAR);
+ }
+ if (msg && y + h > TOAST_Y && x < 320 - SIDEW && x + w > SIDEW) str(msg, 160 - slen(msg) * 7 / 2, TOAST_Y + 3, 0, WHITE, RGB(0x323232));
}
-static int can_recycle(void) { return V.gscoring != 1 || V.passes < V.gdraw - 1; }
-
static void game_scene(void) {
fill(rx, ry, rw, rh, FELT);
- if (ry < TABY) {
- int k = pn[STOCK] - 1, x, y;
- while (k >= 0 && !shown(pl[STOCK][k])) k--;
- if (k >= 0) { /* the deck, a little thicker when it holds more */
- for (int i = min(k / 8, 2); i; i--) fill(COLX(0) + CW - 1 + i, TOPY + 1 + i, 1, CH - 2, BLACK), fill(COLX(0) + 1 + i, TOPY + CH - 1 + i, CW - 2, 1, BLACK);
- card(pl[STOCK][k], COLX(0), TOPY, 0);
- } else { /* the empty stock: O to deal again, X when that is over */
- slot(COLX(0), TOPY);
- if (can_recycle()) {
- ring(COLX(0) + 19, TOPY + 26, 8, 11, RGB(0x30E030));
- } else {
- for (int i = -8; i <= 8; i++) fill(COLX(0) + 18 + i, TOPY + 25 + i, 3, 3, RED), fill(COLX(0) + 18 + i, TOPY + 25 - i, 3, 3, RED);
- }
+ if (ry < BARH) { /* the bar, and a king for the difficulty: red Easy, blue Hard */
+ fill(0, 0, 320, BARH, BAR);
+ int h = V.gdraw == 1 || !V.live ? 0 : 1;
+ portrait(12, 6, 1, 1, h ? RGB(0x5B7FD6) : RGB(0xEF5050), h ? RGB(0x2F4F9A) : RGB(0xBB2026));
+ }
+ fill(0, BARH, SIDEW, 240, SIDE);
+ fill(320 - SIDEW, BARH, SIDEW, 240, SIDE);
+ int k = pn[STOCK] - 1, x, y;
+ while (k >= 0 && !shown(pl[STOCK][k])) k--;
+ if (k >= 0) { /* the deck, a little thicker when it holds more */
+ for (int i = min(k / 8, 2); i; i--) fill(LX + 2, TABY + CH - 2 + i, CW - 4, 1, RGB(0x1E5A2A)), fill(LX + 1, TABY + CH - 3 + i, 1, 1, RGB(0x1E5A2A));
+ card(pl[STOCK][k], LX, TABY);
+ } else { /* the empty deck: a circle arrow to deal again */
+ slot(LX, TABY, -1);
+ if (V.live && can_recycle()) {
+ ring(LX + 15, TABY + 21, 6, 8, WHITE);
+ fill(LX + 15, TABY + 12, 9, 7, SLOT);
+ for (int i = 0; i < 5; i++) fill(LX + 15 + i, TABY + 11 + i, 1, 10 - 2 * i, WHITE);
}
- for (k = max(pn[WASTE] - fan() - 1, 0); k < pn[WASTE]; k++)
- if (shown(pl[WASTE][k])) pos(WASTE, k, &x, &y), card(pl[WASTE][k], x, y, sp == WASTE && k == pn[WASTE] - 1 ? 0xFFFF : 0);
- for (int p = F0; p < T0; p++) {
- k = pn[p] - 1;
- while (k >= 0 && !shown(pl[p][k])) k--;
- if (k >= 0) card(pl[p][k], COLX(p + 1), TOPY, sp == p && k == pn[p] - 1 ? 0xFFFF : 0);
- else slot(COLX(p + 1), TOPY);
+ }
+ for (k = max(pn[WASTE] - fan() - 1, 0); k < pn[WASTE]; k++)
+ if (shown(pl[WASTE][k])) pos(WASTE, k, &x, &y), card(pl[WASTE][k], x, y);
+ for (int p = F0; p < T0; p++) {
+ k = pn[p] - 1;
+ while (k >= 0 && !shown(pl[p][k])) k--;
+ if (k >= 0) card(pl[p][k], RX, FY(p - F0));
+ else slot(RX, FY(p - F0), FSUIT[p - F0]);
+ }
+ /* Undo and New, under the deck */
+ for (int i = 0; i < 2; i++) {
+ int by = i ? NEWY : UNDOY, cx = LX + CW / 2;
+ if (!i) { /* a round arrow */
+ ring(cx + 1, by + 6, 3, 5, WHITE);
+ fill(cx - 5, by + 1, 7, 6, SIDE);
+ for (int j = 0; j < 4; j++) fill(cx - 5 + j, by + 2 - j + 3, 1, 1 + 2 * j, WHITE);
+ } else { /* a star */
+ for (int j = 0; j < 9; j++) {
+ int w = j < 3 ? j / 2 : j < 5 ? 5 - (j - 3) : 2 + (j - 5) / 2;
+ fill(cx - w, by + j, 2 * w + 1, 1, WHITE);
+ }
+ fill(cx - 4, by + 8, 3, 2, WHITE), fill(cx + 2, by + 8, 3, 2, WHITE), fill(cx - 1, by + 8, 3, 1, SIDE);
}
+ text(i ? "NEW" : "UNDO", cx - (i ? 9 : 12), by + 13, WHITE);
}
for (int p = T0; p < NP; p++) {
- int x, y;
- if (!pn[p] || !shown(pl[p][0])) slot(COLX(p - T0), TABY);
- for (int k = 0; k < pn[p]; k++, sq = 6)
- if (shown(pl[p][k])) sq = k + 1 < pn[p] ? od[p - T0] : 6, pos(p, k, &x, &y), card(pl[p][k], x, y, p == sp && k >= pn[p] - sn ? 0xFFFF : 0);
+ if (!pn[p] || !shown(pl[p][0])) slot(COLX(p - T0), TABY, -1);
+ for (k = 0; k < pn[p]; k++)
+ if (shown(pl[p][k])) pos(p, k, &x, &y), card(pl[p][k], x, y);
+ }
+ if (sp >= 0) { /* the cards picked up, in Google blue */
+ int y1;
+ pos(sp, pn[sp] - sn, &x, &y);
+ pos(sp, pn[sp] - 1, &x, &y1);
+ rframe(x - 2, y - 2, CW + 4, y1 - y + CH + 4, BLUE);
}
if (hint_p >= 0 && (now / 200 & 1)) {
- int x, y;
pos(hint_p, max(pn[hint_p] - 1, 0), &x, &y);
- frame(x - 2, y - 2, CW + 4, CH + 4, 2, RGB(0x40E8FF));
+ rframe(x - 2, y - 2, CW + 4, CH + 4, RGB(0x40E8FF));
}
if (!nocur) {
- int x, y, h;
+ int h;
cur_rect(&x, &y, &h);
- frame(x - 2, y - 2, CW + 4, h + 4, 2, GOLD);
+ rframe(x - 3, y - 3, CW + 6, h + 6, GOLD);
}
- for (int i = 0; i < nfl; i++) {
- int x, y;
- if (fl[i].t >= 0) fly_pos(&fl[i], &x, &y), card(fl[i].c, x, y, 0);
- }
- if (ry + rh > STY) status_bar();
+ for (int i = 0; i < nfl; i++)
+ if (fl[i].t >= 0) fly_pos(&fl[i], &x, &y), card(fl[i].c, x, y);
+ if (msg) rbox(160 - slen(msg) * 7 / 2 - 8, TOAST_Y, slen(msg) * 7 + 16, 20, 6, RGB(0x323232));
}
/* ------------------------------------------------------------------ moves */
@@ -737,7 +798,7 @@ static int add_score(int d) { /* what actually changed: Standard stops at 0 */
if (!V.gscoring && s < 0) s = 0;
d = (int)(s - V.score);
V.score = s;
- dirty_status();
+ dirty_bar();
return d;
}
/* the clock, while a game is on; Standard loses 2 points every 10 seconds */
@@ -746,13 +807,13 @@ static void tick(uint32_t dt) {
uint32_t t0 = V.ms;
V.ms += dt;
if (V.ms / 10000 != t0 / 10000 && !V.gscoring && V.gtimed) add_score(-2);
- if (V.ms / 1000 != t0 / 1000 && V.gtimed) dirty_status();
+ if (V.ms / 1000 != t0 / 1000) dirty(90, 0, 60, BARH);
}
static void counted(void) {
if (!V.started) V.started = 1, V.played++;
V.moves++;
hint_p = -1;
- dirty_status();
+ dirty_bar();
}
static void deselect(void) {
if (sp >= 0) dirty_pile(sp);
@@ -860,8 +921,20 @@ found:
say("Hint");
}
-/* OK: pick up, put down, or draw */
+static int difficulty(int full);
+static void new_deal(uint32_t s);
+/* OK: pick up, put down, draw, or a button */
static void act(void) {
+ if (cp == B_UNDO) {
+ undo();
+ return;
+ }
+ if (cp == B_NEW) {
+ int d = difficulty(0);
+ dirty(0, 0, 320, 240);
+ if (d >= 0) V.draw = (uint8_t)(d ? 3 : 1), new_deal(rnd());
+ return;
+ }
if (cp == STOCK) {
draw_cards();
return;
@@ -920,7 +993,7 @@ static void deal_fly(void) {
for (int c = r; c < 7; c++, k++) {
int x, y;
pos(T0 + c, r, &x, &y);
- launch(pl[T0 + c][r], COLX(0), TOPY, x, y, -k * 2);
+ launch(pl[T0 + c][r], LX, TABY, x, y, -k * 2);
}
dirty(0, 0, 320, 240);
dur = 10;
@@ -940,11 +1013,11 @@ static void save(void) {
static void load(void) {
uint32_t n = 0;
const uint8_t *d = ef_read(SAVE_NAME, &n);
- V.draw = 3, V.timed = 1;
+ V.draw = 1, V.timed = 1;
if (!d || n != sizeof V || d[0] != 'S' || d[1] != 1) return;
for (uint32_t i = 0; i < n; i++) ((uint8_t *)&V)[i] = d[i];
- if (V.draw < 1 || V.draw > 3) V.draw = 3;
- V.scoring %= 3, V.timed &= 1, V.keep &= 1;
+ if (V.draw != 1 && V.draw != 3) V.draw = V.draw == 2 ? 3 : 1;
+ V.scoring %= 3, V.timed &= 1, V.keep &= 1, V.back &= 3;
uint64_t seen = 0;
int k = 0, ok = V.live == 1 && V.gdraw >= 1 && V.gdraw <= 3 && V.gscoring < 3 && V.gtimed < 2;
for (int p = 0; p < NP && ok; p++) {
@@ -952,7 +1025,7 @@ static void load(void) {
for (int i = 0; ok && i < V.n[p]; i++, k++) {
int c = V.cards[k] & 63, up = p == WASTE || (p >= F0 && p < T0) || (p >= T0 && (V.cards[k] & UP || i == V.n[p] - 1 || (i && pl[p][i - 1] & UP)));
if (c >= 52 || seen >> c & 1) ok = 0;
- if (p >= F0 && p < T0 && (RANK(c) != i || (i && SUIT(c) != SUIT(pl[p][0])))) ok = 0;
+ if (p >= F0 && p < T0 && (RANK(c) != i || SUIT(c) != FSUIT[p - F0])) ok = 0;
seen |= 1ull << c;
pl[p][i] = (uint8_t)(c | (up ? UP : 0));
}
@@ -974,14 +1047,15 @@ static void abandon(void) {
}
/* ------------------------------------------------------------------ the win */
-/* one card straight onto the screen, over whatever is there */
+/* one card straight onto the screen, over whatever is there (c < 0: the
+ empty foundation of suit -1 - c) */
static void stamp(int c, int x, int y) {
rx = max(x, 0), ry = max(y, 0), rw = min(x + CW, 320) - rx, rh = min(y + CH, 240) - ry;
if (rw <= 0 || rh <= 0) return;
eadk_rect_t r = {(uint16_t)rx, (uint16_t)ry, (uint16_t)rw, (uint16_t)rh};
eadk_display_pull_rect(r, buf);
- if (c < 0) fill(x, y, CW, CH, FELT), slot(x, y);
- else card(c, x, y, 0);
+ if (c < 0) fill(x, y, CW, CH, SIDE), slot(x, y, -1 - c);
+ else card(c, x, y);
eadk_display_push_rect(r, buf);
}
@@ -993,9 +1067,9 @@ static void bounce(void) {
for (int r = 12; r >= 0; r--)
for (int p = F0; p < T0; p++) {
if (!pn[p]) continue;
- int c = pl[p][--pn[p]], x = COLX(p + 1) * 16, y = TOPY * 16;
- int vx = (int)(rnd() % 40 + 20) * (rnd() & 1 ? 1 : -1), vy = -(int)(rnd() % 90);
- stamp(pn[p] ? pl[p][pn[p] - 1] : -1, COLX(p + 1), TOPY);
+ int c = pl[p][--pn[p]], x = RX * 16, y = FY(p - F0) * 16;
+ int vx = -(int)(rnd() % 40 + 20), vy = -(int)(rnd() % 90);
+ stamp(pn[p] ? pl[p][pn[p] - 1] : -1 - FSUIT[p - F0], RX, FY(p - F0));
while (x > -CW * 16 && x < 320 * 16) {
for (int s = 0; s < 5; s++) {
x += vx, vy += 9, y += vy;
@@ -1024,7 +1098,7 @@ static void finish(void) {
uint32_t secs = V.ms / 1000;
V.live = 0, V.won++, V.streak++;
if (V.streak > V.best_streak) V.best_streak = V.streak;
- if (!V.gscoring && V.gtimed && secs >= 30) V.score += (int32_t)(700000 / secs); /* Windows' bonus */
+ if (!V.gscoring && V.gtimed && secs >= 30) V.score += (int32_t)(700000 / secs); /* the bonus for speed */
if (V.gscoring == 1) V.bank += V.score;
if (!V.best_time || secs < V.best_time) V.best_time = (uint16_t)min((int)secs, 65535);
if (!V.gscoring && V.score > V.best_score) V.best_score = V.score;
@@ -1042,42 +1116,42 @@ static void new_deal(uint32_t s) {
deal_fly();
}
+/* the side column a pile is in: -1 the deck's, 7 the foundations', else a column */
+static int col(int p) { return p < 0 || p <= WASTE ? -1 : p < T0 ? 7 : p - T0; }
+
/* the game, until the player leaves it */
static void play(void) {
- static const char *const pause_items[] = {"Resume", "Restart", "New deal", "Quit game"};
- layer = 0, sp = -1, hint_p = -1, msg = 0;
+ static const char *const pause_items[] = {"Resume", "Restart", "New game", "Quit game"};
+ static const int8_t LEFT[4] = {STOCK, WASTE, B_UNDO, B_NEW};
+ layer = 0, sp = -1, hint_p = -1, msg = 0, ticking = 1;
relayout();
set_cursor(cp, cd);
dirty(0, 0, 320, 240);
- uint32_t last = now;
for (;;) {
next_frame();
+ ticking = 1;
uint64_t e = take();
- uint32_t dt = min((int)(now - last), 100);
- last = now;
- if (V.started) { /* the clock; Standard loses 2 points every 10 seconds */
- uint32_t t0 = V.ms;
- V.ms += dt;
- if (V.ms / 10000 != t0 / 10000 && !V.gscoring && V.gtimed) add_score(-2);
- if (V.ms / 1000 != t0 / 1000 && V.gtimed) dirty_status();
- }
- if (msg && (int32_t)(now - msg_until) > 0) msg = 0, dirty_status();
+ if (msg && (int32_t)(now - msg_until) > 0) msg = 0, dirty_toast();
if (hint_p >= 0) {
if ((int32_t)(now - hint_until) > 0) dirty_pile(hint_p), hint_p = -1;
- else if (now / 200 != (now - dt) / 200) dirty_pile(hint_p);
+ else if (now / 200 != (now - 16) / 200) dirty_pile(hint_p);
}
int lr = (e & KEY(eadk_key_right) ? 1 : 0) - (e & KEY(eadk_key_left) ? 1 : 0);
- if (lr) {
- if (cp >= T0) set_cursor(T0 + (cp - T0 + lr + 7) % 7, 1);
- else set_cursor((cp + lr + 6) % 6, 1); /* stock, waste, foundations */
- }
- if (e & KEY(eadk_key_up)) {
- if (cp >= T0 && sp < 0 && cd < run(cp)) set_cursor(cp, cd + 1);
- else if (cp >= T0) set_cursor(cp == T0 ? STOCK : cp < T0 + 3 ? WASTE : cp - 7, 1);
- }
- if (e & KEY(eadk_key_down)) {
- if (cp >= T0) set_cursor(cp, cd - 1);
- else set_cursor(cp == STOCK ? T0 : cp == WASTE ? T0 + 1 : cp + 7, 1);
+ int ud = (e & KEY(eadk_key_down) ? 1 : 0) - (e & KEY(eadk_key_up) ? 1 : 0);
+ if (lr) { /* across: the deck's column, the seven columns, the foundations' */
+ int c = col(cp) + lr;
+ c = c < -1 ? 7 : c > 7 ? -1 : c;
+ set_cursor(c == -1 ? lastl : c == 7 ? lastr : T0 + c, 1);
+ } else if (ud && col(cp) == -1) { /* up and down a side column */
+ int i = 0;
+ while (LEFT[i] != cp) i++;
+ set_cursor(LEFT[max(0, min(3, i + ud))], 1);
+ } else if (ud && col(cp) == 7) {
+ set_cursor(F0 + max(0, min(3, cp - F0 + ud)), 1);
+ } else if (ud < 0 && sp < 0 && cd < run(cp)) { /* in a column: pick more cards, or fewer */
+ set_cursor(cp, cd + 1);
+ } else if (ud > 0) {
+ set_cursor(cp, cd - 1);
}
if (e & KEY(eadk_key_ok)) act();
if (e & KEY(eadk_key_exe)) draw_cards();
@@ -1093,17 +1167,21 @@ static void play(void) {
deselect();
} else {
for (;;) {
+ layer = 1, paint(0, 0, 320, 240), layer = 0; /* the table, dimmed under the dialog */
int r = dialog("Paused", 0, pause_items, 4, 1, 0);
if (r == 3) {
if (!dialog("Solitaire", "Quit game?", yes_no, 2, 0, 1)) np_jump(leave); /* saves, then leaves */
- paint(0, 0, 320, 240);
continue;
}
+ if (r == 2) {
+ int d = difficulty(0);
+ if (d < 0) continue;
+ V.draw = (uint8_t)(d ? 3 : 1);
+ }
dirty(0, 0, 320, 240);
if (r == 1 || r == 2) new_deal(r == 1 ? V.seed : rnd());
break;
}
- last = now;
}
}
if (cp >= T0 && cd > max(run(cp), 1)) set_cursor(cp, cd); /* the column changed */
@@ -1111,76 +1189,122 @@ static void play(void) {
if (won() && V.live) {
char s[96], *o = s;
finish();
- o = num(cat(o, "You win!\nTime: "), (int32_t)(V.ms / 1000));
+ o = num(cat(o, "Time: "), (int32_t)(V.ms / 1000));
o = num(cat(o, " seconds\nMoves: "), V.moves);
if (V.gscoring < 2) o = (V.gscoring ? money : num)(cat(o, "\nScore: "), shown_score());
- cat(o, "\n\nDeal again?");
+ cat(o, "\n\nPlay again?");
next_frame();
- bounce();
- if (dialog("Solitaire", s, yes_no, 2, 0, 0)) return;
+ nocur = 1, bounce(), nocur = 0;
+ layer = 1, paint(0, 0, 320, 240), layer = 0;
+ if (dialog("You win!", s, yes_no, 2, 0, 0)) return;
new_deal(rnd());
- last = now;
}
}
}
-/* ------------------------------------------------------------------ menus */
-static const char *const menu_items[] = {"Continue", "New game", "Options", "Statistics", "How to play"};
-static int menu_first, menu_at;
-static int menu_y(int i) { return 131 - (5 - menu_first) * 15 + (i - menu_first) * 30; }
-
-static void title_scene(void) {
- static const uint8_t hand[5] = {0, (12 * 4 + 1) | UP, (11 * 4 + 2) | UP, (10 * 4 + 3) | UP, UP};
- fill(rx, ry, rw, rh, FELT);
- text("Solitaire", 57, 14, 4, RGB(0x004000));
- text("Solitaire", 54, 11, 4, WHITE);
- for (int i = 0; i < 5; i++) card(hand[i], 14 + i * 26, 96 + (i - 2) * (i - 2) * 3, 0);
- for (int i = menu_first; i < 5; i++) button(184, menu_y(i), 124, 24, i == menu_at);
- char m[24], *o = num(cat(m, "Draw "), V.draw);
- cat(o, V.scoring ? V.scoring == 1 ? ", Vegas" : "" : ", Standard");
- text("Based on Tatone26's version", 4, 229, 1, RGB(0x9CD89C));
- text(m, 316 - slen(m) * 6, 229, 1, RGB(0x9CD89C));
+/* ------------------------------------------------------------------ the start */
+/* Google's "Choose your difficulty", over the dimmed table: a red king for
+ Easy (draw 1), a blue one for Hard (draw 3). full adds Continue (with a
+ game to continue) and Options, Statistics and How to play. Returns 0 Easy,
+ 1 Hard, 2 Continue, 3 Options, 4 Statistics, 5 How to play, or -1 (Back). */
+static int drow, dsel;
+static void difficulty_draw(int full, int all) {
+ static const char *const LINKS[3] = {"Options", "Stats", "Help"};
+ int live = full && V.live, h = full ? (live ? 176 : 148) : 120, x = 48, y = (240 - h) / 2;
+ if (all) {
+ layer = 1, paint(0, 0, 320, 240), layer = 0;
+ widget(W_WIN, x, y, 224, h, 0, 0);
+ str("Choose your difficulty", 160 - 22 * 7 / 2, y + 8, 0, GREY, WHITE);
+ }
+ for (int i = 0; i < 2; i++) { /* the kings */
+ bool on = drow == 0 && dsel == i;
+ int kx = i ? 184 : 88, l = layer;
+ wt = W_WIN, wf = 0, layer = 3;
+ rx = kx - 4, ry = y + 26, rw = 56, rh = 86;
+ fill(rx, ry, rw, rh, WHITE);
+ if (on) rbox(rx, ry, rw, rh, 7, PALE);
+ portrait(12, kx, y + 30, 2, i ? RGB(0x5B7FD6) : RGB(0xEF5050), i ? RGB(0x2F4F9A) : RGB(0xBB2026));
+ eadk_display_push_rect((eadk_rect_t){(uint16_t)rx, (uint16_t)ry, (uint16_t)rw, (uint16_t)rh}, buf);
+ layer = l;
+ str(i ? "HARD" : "EASY", kx + 4, y + 90, 1, INK, on ? PALE : WHITE);
+ }
+ if (live) widget(W_BTN, 100, y + 118, 120, 22, "Continue", drow == 1 ? F_FOCUS : 0);
+ if (full)
+ for (int i = 0, lx = 160 - (7 * 16 + 3 * 16 + 2 * 8) / 2; i < 3; lx += slen(LINKS[i]) * 7 + 24, i++) {
+ bool on = drow == 2 && dsel == i;
+ int w = slen(LINKS[i]) * 7 + 16, ly = y + h - 30, l = layer;
+ layer = 3, rx = lx, ry = ly, rw = w, rh = 22;
+ fill(rx, ry, rw, rh, WHITE);
+ if (on) rbox(rx, ry, rw, rh, 7, BLUE);
+ eadk_display_push_rect((eadk_rect_t){(uint16_t)rx, (uint16_t)ry, (uint16_t)rw, (uint16_t)rh}, buf);
+ layer = l;
+ str(LINKS[i], lx + 8, ly + 4, 0, on ? WHITE : BLUE, on ? BLUE : WHITE);
+ }
}
-static void scene(void) {
- if (layer == 2) widget_draw();
- else if (layer == 1) title_scene();
- else game_scene();
+static int difficulty(int full) {
+ int live = full && V.live;
+ drow = live ? 1 : 0, dsel = V.draw == 3;
+ ndr = 0, ticking = 0;
+ difficulty_draw(full, 1);
+ for (uint64_t e = 0;; e = take()) {
+ int lr = (e & KEY(eadk_key_right) ? 1 : 0) - (e & KEY(eadk_key_left) ? 1 : 0);
+ int ud = (e & KEY(eadk_key_down) ? 1 : 0) - (e & KEY(eadk_key_up) ? 1 : 0);
+ if (ud && full) {
+ drow = max(0, min(2, drow + ud));
+ if (drow == 1 && !live) drow += ud;
+ drow = max(0, min(2, drow)), dsel = drow == 0 ? V.draw == 3 : 0;
+ }
+ if (lr) dsel = drow == 0 ? !dsel : drow == 2 ? (dsel + lr + 3) % 3 : 0;
+ if (lr || ud) difficulty_draw(full, 0);
+ if (e & OK_KEYS) return drow == 0 ? dsel : drow == 1 ? 2 : 3 + dsel;
+ if (e & KEY(eadk_key_back)) return -1;
+ next_frame();
+ }
}
-static void title_labels(void) {
- for (int i = menu_first; i < 5; i++)
- str(menu_items[i], 184 + (124 - slen(menu_items[i]) * 7) / 2, menu_y(i) + 5, 0, i == menu_at ? WHITE : BLACK,
- i == menu_at ? NAVY : FACE);
+
+static void scene(void) {
+ if (layer == 2) {
+ widget_draw();
+ } else {
+ game_scene();
+ if (layer == 1) shadow(rx, ry, rw, rh, 20); /* dimmed under a dialog */
+ }
}
static void options(void) {
- static const char *const lbl[8] = {"One (Easy)", "Two (Normal)", "Three (Hard)", "Timed game", "Standard", "Vegas", "None", "Keep score"};
- int x = 22, y = 28, f = 0;
+ static const char *const lbl[5] = {"Standard", "Vegas", "None", "Timed game", "Keep score"};
+ int x = 22, y = 9, f = 0;
ndr = 0;
- win(x, y, 276, 184, "Options", 0);
- widget(W_GROUP, x + 10, y + 32, 124, 80, "Draw", 0);
- widget(W_GROUP, x + 142, y + 32, 124, 80, "Scoring", 0);
+ layer = 1, paint(0, 0, 320, 240), layer = 0;
+ win(x, y, 276, 222, "Options", 0);
+ widget(W_GROUP, x + 16, y + 36, 110, 16, "Scoring", 0);
+ widget(W_GROUP, x + 146, y + 36, 110, 16, "Game", 0);
+ widget(W_GROUP, x + 16, y + 120, 110, 16, "Card back", 0);
for (uint64_t e = 0;; e = take()) {
int o = f;
- if (e & KEY(eadk_key_up)) f = f == 8 ? 3 : f % 4 ? f - 1 : f;
- if (e & KEY(eadk_key_down)) f = f == 8 ? 8 : f % 4 == 3 ? 8 : f + 1;
- if ((e & (KEY(eadk_key_left) | KEY(eadk_key_right))) && f < 8) f ^= 4;
+ if (e & (KEY(eadk_key_up) | KEY(eadk_key_left))) f = (f + 10) % 11;
+ if (e & (KEY(eadk_key_down) | KEY(eadk_key_right))) f = (f + 1) % 11;
if (e & OK_KEYS) {
- if (f == 8) break;
- if (f == 3) V.timed ^= 1;
- else if (f == 7) V.keep ^= 1;
- else if (f < 3) V.draw = (uint8_t)(f + 1);
- else V.scoring = (uint8_t)(f - 4);
+ if (f == 10) break;
+ if (f < 3) V.scoring = (uint8_t)f;
+ else if (f == 3) V.timed ^= 1;
+ else if (f == 4) V.keep ^= 1;
+ else if (f < 9) V.back = (uint8_t)(f - 5);
+ else f = 10;
}
if (e & KEY(eadk_key_back)) break;
- for (int i = 0; i < 9; i++) {
+ for (int i = 0; i < 11; i++) {
if (e && i != f && i != o && !(e & OK_KEYS)) continue;
- if (i == 8) {
- widget(W_BTN, x + 103, y + 150, 70, 24, "OK", f == 8);
- continue;
+ if (i == 10) {
+ widget(W_BTN, x + 196, y + 188, 64, 24, "OK", f == 10 ? F_FOCUS : 0);
+ } else if (i >= 5 && i < 9) {
+ for (int j = 5; j < 9 && (e & OK_KEYS); j++) /* the one on changed */
+ if (j != i) widget(W_BACK, x + 12 + (j - 5) * 42, y + 138, CW + 8, CH + 8, 0, (j == f) * F_FOCUS | (V.back == j - 5) * F_ON | (j - 5) << 4);
+ widget(W_BACK, x + 12 + (i - 5) * 42, y + 138, CW + 8, CH + 8, 0, (i == f) * F_FOCUS | (V.back == i - 5) * F_ON | (i - 5) << 4);
+ } else if (i < 9) {
+ int on = i == 3 ? V.timed : i == 4 ? V.keep : V.scoring == i;
+ widget(i < 3 ? W_RADIO : W_CHECK, x + (i < 3 ? 16 : 146), y + 56 + (i < 3 ? i : i - 3) * 20, 124, 16, lbl[i], on | (i == f) << 1);
}
- int on = i == 3 ? V.timed : i == 7 ? V.keep : i < 3 ? V.draw == i + 1 : V.scoring == i - 4;
- widget(i % 4 == 3 ? W_CHECK : W_RADIO, x + 20 + (i / 4) * 132, y + 50 + (i % 4) * 20 + (i % 4 == 3) * 10, 110, 16,
- lbl[i], on | (i == f) << 1);
}
next_frame();
}
@@ -1195,24 +1319,22 @@ static void stats(void) {
o = num(cat(o, "\nStreak: "), V.streak);
o = num(cat(o, " Best: "), V.best_streak);
o = cat(o, "\nBest time: ");
- if (V.best_time) {
- o = num(o, V.best_time / 60);
- *o++ = ':', *o++ = (char)('0' + V.best_time % 60 / 10), *o++ = (char)('0' + V.best_time % 10), *o = 0;
- } else {
- o = cat(o, "-");
- }
+ if (V.best_time) o = two(cat(num(o, V.best_time / 60), ":"), V.best_time % 60);
+ else o = cat(o, "-");
o = num(cat(o, "\nBest score: "), V.best_score);
money(cat(o, "\nVegas bank: "), V.bank);
+ layer = 1, paint(0, 0, 320, 240), layer = 0;
dialog("Statistics", s, ok_btn, 1, 0, 0);
}
static void help(void) {
+ layer = 1, paint(0, 0, 320, 240), layer = 0;
dialog("How to play",
- "Build four piles, ace to king, one\n"
- "suit each. In the columns, go down\n"
- "and alternate red and black.\n"
+ "Build the four suits up, ace to\n"
+ "king, on the right. In the columns,\n"
+ "go down, alternating red and black.\n"
"OK Pick up, put down\n"
- "OK twice Send to a foundation\n"
+ "OK twice Send to its foundation\n"
"Up, Down Pick more or fewer\n"
"EXE Draw from the deck\n"
"Toolbox Play all you can up\n"
@@ -1230,32 +1352,26 @@ int main(void) {
seed ^= eadk_random() ^ now;
load();
held = eadk_keyboard_scan();
+ nocur = 1;
for (;;) {
- menu_first = V.live ? 0 : 1;
- menu_at = max(menu_at, menu_first);
- if (menu_at > 4) menu_at = menu_first;
- layer = 1;
- paint(0, 0, 320, 240);
- title_labels();
- for (uint64_t e = 0;; e = take()) {
- int d = (e & KEY(eadk_key_down) ? 1 : 0) - (e & KEY(eadk_key_up) ? 1 : 0);
- if (d) {
- int o = menu_at;
- menu_at = menu_first + (menu_at - menu_first + d + 5 - menu_first) % (5 - menu_first);
- for (int i = 0; i < 2; i++) {
- int k = i ? menu_at : o;
- widget(W_BTN, 184, menu_y(k), 124, 24, menu_items[k], k == menu_at ? F_FOCUS : 0);
- }
- }
- if (e & OK_KEYS) break;
- if ((e & KEY(eadk_key_back)) && !dialog("Solitaire", "Quit game?", yes_no, 2, 0, 1)) np_jump(leave);
- if (e & KEY(eadk_key_back)) layer = 1, paint(0, 0, 320, 240), title_labels();
- next_frame();
+ relayout();
+ int a = difficulty(1);
+ if (a == 2) {
+ nocur = 0, play();
+ } else if (a == 0 || a == 1) {
+ V.draw = (uint8_t)(a ? 3 : 1), nocur = 0;
+ new_deal(rnd());
+ play();
+ } else if (a == 3) {
+ options();
+ } else if (a == 4) {
+ stats();
+ } else if (a == 5) {
+ help();
+ } else {
+ layer = 1, paint(0, 0, 320, 240), layer = 0;
+ if (!dialog("Solitaire", "Quit game?", yes_no, 2, 0, 1)) np_jump(leave);
}
- if (menu_at == 0) play();
- else if (menu_at == 1) new_deal(rnd()), play();
- else if (menu_at == 2) options();
- else if (menu_at == 3) stats();
- else help();
+ nocur = 1;
}
}
diff --git a/tests/test_games.py b/tests/test_games.py
index 278c4cc4..be9bdd4a 100644
--- a/tests/test_games.py
+++ b/tests/test_games.py
@@ -69,7 +69,7 @@ GAMES = {
"pacman": ("PacMan.nwa", "pacman.sav", presses((1500, "ok")), 8000,
presses((1500, "down"), (1800, "ok"), (2100, "right"), (2400, "back")), 3500),
# Play, straight through the first apple into the wall: a best of 1; next
- # time, Settings, Speed to Fast and back: saved, the best kept
+ # time, Settings, the fruit to a banana and back: saved, the best kept
"snake": ("Snake.nwa", "snake.sav", presses((1500, "ok"), (2000, "right")), 7000,
presses((1500, "down"), (1800, "ok"), (2100, "right"), (2400, "back")), 3500),
# vs the computer: the settings are saved; next time, the dark theme
@@ -89,10 +89,9 @@ GAMES = {
# new game from the pause menu and its first square
"minesweeper": ("Minesweeper.nwa", "mines.sav", presses((1500, "ok"), (2000, "ok"), (2400, "right")), 3000,
presses((1500, "ok"), (2000, "back"), (2300, "down"), (2600, "ok"), (3000, "ok")), 3600),
- # Classic, serve, a brick or more: the best is kept; next time, Settings, screen shake off, back
- "breakout": ("Breakout.nwa", "breakout.sav", presses((1500, "ok"), (2500, "ok")), 6000,
- presses((1500, "down"), (1800, "down"), (2100, "ok"), (2500, "down"), (2800, "ok"), (3200, "back")),
- 4500),
+ # Play, serve, a brick or more: the best is kept; next time, Settings, screen shake off, back
+ "breakout": ("BlockBreaker.nwa", "breakout.sav", presses((1500, "ok"), (2500, "ok")), 6000,
+ presses((1500, "down"), (1800, "ok"), (2100, "down"), (2400, "ok"), (2800, "back")), 4000),
}
@@ -123,9 +122,9 @@ CHECKS = {
"pacman": (lambda v: v[:2] == b"P\1" and v[12:14] == bytes([1, 2]) and struct.unpack_from("<I", v, 16)[0] > 5000
and struct.unpack_from("<I", v, 8)[0] == 9000 and sum(bin(b).count("1") for b in v[20:52]) < 244,
lambda v: v[2] == 2 and v[12:14] == bytes([1, 2]) and struct.unpack_from("<I", v, 16)[0] > 5000),
- # the default options, then the best for Medium at Normal speed
- "snake": (lambda v: len(v) == 26 and v[:8] == b"S\1\1\1\0\0\0\0" and struct.unpack_from("<H", v, 16)[0] == 1,
- lambda v: len(v) == 26 and v[2] == 2 and struct.unpack_from("<H", v, 16)[0] == 1),
+ # the default options and a best of 1 (Classic, 1 fruit, normal speed and size); then a banana
+ "snake": (lambda v: len(v) == 658 and v[:9] == b"S\2" + bytes(7) and struct.unpack_from("<H", v, 10)[0] == 1,
+ lambda v: len(v) == 658 and v[2] == 1 and struct.unpack_from("<H", v, 10)[0] == 1),
"connectfour": (lambda v: v == b"C\1\1\2\1\0\5\1" + bytes(8), # vs computer, 2 players, Normal, light
lambda v: v[5] == 1 and v[6] == 5), # dark now; the tally's settings read back
# the seeded options made a Vegas draw-1 game (-$52), counted as played; two moves, then three
@@ -144,7 +143,7 @@ CHECKS = {
"minesweeper": (lambda v: len(v) == 276 and v[:2] == b"M\1" and v[32:34] == bytes([9, 9]) and v[28] == 10
and v[34] == 5 and struct.unpack_from("<H", v, 14)[0] == 1,
lambda v: v[32] == 9 and struct.unpack_from("<H", v, 14)[0] == 2),
- "breakout": (lambda v: len(v) == 16 and v[:2] == b"B\1" and v[4] == 1 and struct.unpack_from("<I", v, 8)[0] >= 1,
+ "breakout": (lambda v: len(v) == 12 and v[:2] == b"B\2" and v[4] == 1 and struct.unpack_from("<I", v, 8)[0] >= 10,
lambda v: v[4] == 0 and struct.unpack_from("<I", v, 8)[0] >= 1), # best kept, shake off
}