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.

Space Invaders: the arcade game, in NumPlay and on its own

Mason363243b9f830c14
diff --git a/games/games.json b/games/games.json
index a13dd7f5..6bb4767c 100644
--- a/games/games.json
+++ b/games/games.json
@@ -380,6 +380,24 @@
"app": "TwoPlayers.nwa",
"repo": "https://github.com/Mason363/NumPlay/tree/main/games/twoplayer"
},
+ {
+ "id": "invaders",
+ "title": "Space Invaders",
+ "tagline": "Stop the invasion, one cannon",
+ "credit": "Based on Space Invaders by Taito",
+ "top": "0x2B2F4A",
+ "bottom": "0x05060C",
+ "accent": "0x3CF03C",
+ "colors": 4,
+ "records": [
+ "invaders.sav"
+ ],
+ "shots": [
+ "docs/shot.png"
+ ],
+ "app": "SpaceInvaders.nwa",
+ "repo": "https://github.com/Mason363/NumPlay/tree/main/games/invaders"
+ },
{
"id": "numvisuals",
"title": "NumVisuals",
diff --git a/games/invaders/.gitignore b/games/invaders/.gitignore
new file mode 100644
index 00000000..342d9dda
--- /dev/null
+++ b/games/invaders/.gitignore
@@ -0,0 +1,2 @@
+output/
+build/
diff --git a/games/invaders/Makefile b/games/invaders/Makefile
new file mode 100644
index 00000000..dc599b4b
--- /dev/null
+++ b/games/invaders/Makefile
@@ -0,0 +1,83 @@
+# Space Invaders — Taito's arcade game of 1978, as on the Midway cabinet.
+# make build output/invaders.nwa
+# make check link the app like the calculator does (output/invaders.bin)
+#
+# In NumPlay the game draws with the launcher's strips, shapes and fonts and saves through its
+# file functions (module.o leaves them to the launcher); on its own it brings them along.
+Q ?= @
+CC = arm-none-eabi-gcc
+NWLINK ?= npx --yes -- [email protected]
+BUILD_DIR = output
+SRC = src/main.c
+HEADERS = ../common/epsilon_app.h ../common/epsilon_files.h ../common/np_text.h ../../launcher/src/gfx.h \
+ ../../launcher/src/np.h ../../launcher/src/font.h
+
+CFLAGS = -std=c11 $(shell $(NWLINK) eadk-cflags-device)
+CFLAGS += -Os -Wall -Wextra -Wno-unused-parameter -fno-math-errno -fsingle-precision-constant
+CFLAGS += -fno-tree-loop-distribute-patterns -flto -fno-fat-lto-objects -fwhole-program -fvisibility=internal
+LDFLAGS = -Wl,--relocatable -nostartfiles --specs=nano.specs
+LDFLAGS += -Wl,-e,main -Wl,-u,eadk_app_name -Wl,-u,eadk_app_icon -Wl,-u,eadk_api_level
+LDFLAGS += -Wl,--gc-sections -flinker-output=nolto-rel
+
+.PHONY: build check clean
+build: $(BUILD_DIR)/invaders.nwa
+
+check: $(BUILD_DIR)/invaders.nwa
+ $(Q) $(NWLINK) nwa-bin $< $(BUILD_DIR)/invaders.bin
+ @echo "BIN $(BUILD_DIR)/invaders.bin: $$(wc -c < $(BUILD_DIR)/invaders.bin) bytes"
+
+# compiled, then linked (the link options would upset the compiler)
+$(BUILD_DIR)/main.o: $(SRC) $(HEADERS) | $(BUILD_DIR)
+ @echo "CC $<"
+ $(Q) $(CC) $(CFLAGS) -c $(SRC) -o $@
+$(BUILD_DIR)/gfx.o: ../../launcher/src/gfx.c $(HEADERS) | $(BUILD_DIR)
+ $(Q) $(CC) $(CFLAGS) -c $< -o $@
+$(BUILD_DIR)/font_data.o: ../../launcher/src/font_data.c ../../launcher/src/font.h | $(BUILD_DIR)
+ $(Q) $(CC) $(CFLAGS) -c $< -o $@
+$(BUILD_DIR)/xfont.o: ../../launcher/src/xfont.c ../../launcher/src/np_xfont.h $(HEADERS) | $(BUILD_DIR)
+ $(Q) $(CC) $(CFLAGS) -c $< -o $@
+
+$(BUILD_DIR)/invaders.nwa: $(BUILD_DIR)/main.o $(BUILD_DIR)/gfx.o $(BUILD_DIR)/font_data.o $(BUILD_DIR)/xfont.o \
+ $(BUILD_DIR)/icon.o
+ @echo "LD $@"
+ $(Q) $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
+ $(Q) arm-none-eabi-strip --strip-unneeded $@
+
+$(BUILD_DIR)/icon.o: src/icon.png | $(BUILD_DIR)
+ @echo "ICON $<"
+ $(Q) $(NWLINK) png-icon-o $< $@
+
+$(BUILD_DIR):
+ $(Q) mkdir -p $@
+
+clean:
+ $(Q) rm -rf $(BUILD_DIR) build
+
+# on a computer, with the sanitizers: a bot plays an hour of the game (tests/play.c)
+HOST_FLAGS = -std=gnu11 -O1 -g -Wall -Wextra -Wno-unused-parameter -DPLATFORM_DEVICE=1 -DHOST \
+ $(shell $(NWLINK) eadk-cflags-simulator) -fsanitize=address,undefined -fno-sanitize-recover=undefined
+.PHONY: host test
+host: build/play
+build/play: $(SRC) tests/play.c $(HEADERS)
+ $(Q) mkdir -p build
+ $(Q) cc $(HOST_FLAGS) tests/play.c ../../launcher/src/gfx.c ../../launcher/src/font_data.c \
+ ../../launcher/src/xfont.c -lm -o $@
+ @echo "HOST $@"
+test: build/play
+ build/play test
+
+# NumPlay launcher: the app as a module (see ../../tools/npmodule.py) for the
+# calculator, and as a relocatable object for the simulator build.
+.PHONY: module sim-module
+module: $(BUILD_DIR)/module.o
+$(BUILD_DIR)/module-main.o: $(SRC) $(HEADERS) | $(BUILD_DIR)
+ $(Q) $(CC) $(CFLAGS) -DNP_MODULE=1 -c $(SRC) -o $@
+$(BUILD_DIR)/module.o: $(BUILD_DIR)/module-main.o
+ $(Q) $(CC) $(CFLAGS) -Wl,--relocatable -nostartfiles -nostdlib -Wl,-e,main -flinker-output=nolto-rel $< -o $@
+
+sim-module: $(BUILD_DIR)/sim-module.o
+$(BUILD_DIR)/sim-module.o: $(SRC) $(HEADERS) | $(BUILD_DIR)
+ $(Q) mkdir -p $(BUILD_DIR)/sim
+ $(Q) cc -std=c11 -O2 -fPIC $(shell $(NWLINK) eadk-cflags-simulator) -DNP_MODULE=1 -Dmain=np_invaders_main \
+ -c $(SRC) -o $(BUILD_DIR)/sim/main.o
+ $(Q) ld -r $(BUILD_DIR)/sim/main.o -exported_symbol _np_invaders_main -o $@
diff --git a/games/invaders/docs/shot.png b/games/invaders/docs/shot.png
new file mode 100644
index 00000000..13cc4d8c
Binary files /dev/null and b/games/invaders/docs/shot.png differ
diff --git a/games/invaders/lang/fr.txt b/games/invaders/lang/fr.txt
new file mode 100644
index 00000000..e3008ca9
--- /dev/null
+++ b/games/invaders/lang/fr.txt
@@ -0,0 +1,9 @@
+# Space Invaders in French: the English text as in the source, a tab, the translation (see tools/lang.py).
+Resume Reprendre
+Quit game Quitter le jeu
+No Non
+Yes Oui
+Paused Pause
+Quit game? Quitter le jeu ?
+Left Right: move OK, EXE, Up: fire Back: pause Gauche Droite : bouger OK, EXE, Haut : tirer Retour : pause
+Press OK to play Appuie sur OK pour jouer
diff --git a/games/invaders/lang/zh.txt b/games/invaders/lang/zh.txt
new file mode 100644
index 00000000..4be15d66
--- /dev/null
+++ b/games/invaders/lang/zh.txt
@@ -0,0 +1,9 @@
+# Space Invaders in Chinese: the English text as in the source, a tab, the translation (see tools/lang.py).
+Resume 继续
+Quit game 退出游戏
+No 否
+Yes 是
+Paused 暂停
+Quit game? 退出游戏?
+Left Right: move OK, EXE, Up: fire Back: pause 左右:移动 OK、EXE、上:射击 返回:暂停
+Press OK to play 按 OK 开始
diff --git a/games/invaders/src/icon.png b/games/invaders/src/icon.png
new file mode 100644
index 00000000..6dc2d887
Binary files /dev/null and b/games/invaders/src/icon.png differ
diff --git a/games/invaders/src/main.c b/games/invaders/src/main.c
new file mode 100644
index 00000000..d7556a2b
--- /dev/null
+++ b/games/invaders/src/main.c
@@ -0,0 +1,525 @@
+/* Space Invaders: Taito's arcade game of 1978, as it plays on the Midway cabinet.
+ *
+ * The arcade draws in a picture of one bit a pixel, 224 wide and 256 high, white on black, seen
+ * through strips of coloured film: red over the saucer, green over the bunkers, the cannon and the
+ * lives. Here it is the same picture, pixel for pixel, in the middle of the calculator's screen;
+ * only its empty margins at the top and the bottom are left out. It works the arcade's way:
+ * what moves is wiped and drawn again in the picture, a shot hits whatever it finds lit there, and
+ * a burst leaves its shape cut out when it goes, so the bunkers and the ground wear away. The rules
+ * are the arcade's:
+ * - the invaders move one at a time, one each frame, so the rack speeds up as it thins out; it
+ * drops 8 pixels at each edge, wipes out the bunkers it reaches, and each wave starts lower;
+ * - their three shots: the rolling one, from the column above the cannon, and the plunger and the
+ * squiggly one, from columns in a fixed order; a shot waits until the others have gone far
+ * enough, and less far as the score grows;
+ * - the mystery saucer is worth 50 to 300 points, from how many shots were fired: the 23rd shot,
+ * then every 15th, gets 300; a new cannon at 1500 points.
+ *
+ * Only the rows that change are sent to the screen, in the launcher's strips (launcher/src/gfx.c).
+ * Inside NumPlay it uses the launcher's shapes, fonts and files; on its own it brings them along. */
+#include <eadk.h>
+#include "../../../launcher/src/gfx.h"
+#include "../../common/np_text.h"
+
+#if NP_MODULE /* (np_file_read and np_file_write: NumPlay's, launcher/src/np.h) */
+#define np_app_begin()
+#define np_app_end() 0
+#else
+#include "../../common/epsilon_app.h"
+#include "../../common/epsilon_files.h"
+#define np_file_read ef_read
+#define np_file_write ef_write
+const char eadk_app_name[] __attribute__((section(".rodata.eadk_app_name"))) = "Space Invaders";
+const uint32_t eadk_api_level __attribute__((section(".rodata.eadk_api_level"))) = 0;
+void np_push(int x, int y, int w, int h, const color_t *px) {
+ eadk_display_push_rect((eadk_rect_t){(uint16_t)x, (uint16_t)y, (uint16_t)w, (uint16_t)h}, px);
+}
+#endif
+
+/* the keys used, in 32 bits: 4, 5, 6, 2 and EXE come down from the high word */
+#define KEY(k) (1u << ((k) - ((k) >= 32) * 24))
+#define X0 48 /* the arcade's 224 columns, in the middle of the screen */
+#define OFF 7 /* and its rows from row 7 on */
+#define TOPY 32 /* the cannon's shots burst here, at the top of the red film */
+#define UY 40 /* the saucer's row */
+#define SHY 192 /* the bunkers' top row */
+#define PY 216 /* the cannon's */
+#define GY 239 /* the ground */
+#define LY 240 /* the lives and the credits */
+#define ALL 0x3FFFFFFFu
+
+#define WHITE 0xFFFF
+#define RED HEX(0xFF4848)
+#define GREEN HEX(0x3CF03C)
+
+/* the arcade's pictures, a row of 16 pixels each, the top bit the leftmost */
+static const uint16_t art[][8] = {
+ {0x03C0, 0x1FF8, 0x3FFC, 0x399C, 0x3FFC, 0x0660, 0x0DB0, 0x300C}, /* the octopus, 10 points */
+ {0x03C0, 0x1FF8, 0x3FFC, 0x399C, 0x3FFC, 0x0E70, 0x1998, 0x0C30},
+ {0x0410, 0x0220, 0x07F0, 0x0DD8, 0x1FFC, 0x17F4, 0x1414, 0x0360}, /* the crab, 20 */
+ {0x0410, 0x1224, 0x17F4, 0x1DDC, 0x1FFC, 0x0FF8, 0x0410, 0x0808},
+ {0x0180, 0x03C0, 0x07E0, 0x0DB0, 0x0FF0, 0x0240, 0x05A0, 0x0A50}, /* the squid, 30 */
+ {0x0180, 0x03C0, 0x07E0, 0x0DB0, 0x0FF0, 0x05A0, 0x0810, 0x0420},
+ {0x0440, 0x2288, 0x1010, 0x0820, 0x600C, 0x0820, 0x1290, 0x2448}, /* an invader hit */
+ {0x0100, 0x0380, 0x0380, 0x3FF8, 0x7FFC, 0x7FFC, 0x7FFC, 0x7FFC}, /* the cannon */
+ {0x0100, 0x2048, 0x0A10, 0x4582, 0x0FD0, 0x3FF0, 0x7FFA, 0xFFFE}, /* the cannon hit, two pictures */
+ {0x1010, 0x0102, 0x4840, 0x0B88, 0x2FD0, 0x1FF2, 0x7FFC, 0xFFFF},
+ {0x07E0, 0x1FF8, 0x3FFC, 0x6DB6, 0xFFFF, 0x399C, 0x1008, 0x0000}, /* the saucer */
+ {0x2244, 0x8811, 0x15A8, 0x4FF2, 0x1FF8, 0x9B6D, 0x0A50, 0x2244}, /* the saucer hit */
+ {0x8900, 0x2200, 0x7E00, 0xFF00, 0xFF00, 0x7E00, 0x2400, 0x9100}, /* the cannon's shot bursting */
+ {0x2000, 0x8800, 0x3400, 0x7800, 0xB800, 0x7C00, 0xB800, 0x5400}, /* an invader's shot bursting */
+ {0x8000, 0x8000, 0x8000, 0x8000}, /* the cannon's shot */
+ {0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF}, /* a bunker, in four */
+ {0xC000, 0xE000, 0xF000, 0xF800, 0xFC00, 0xFC00, 0xFC00, 0xFC00},
+ {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFE01, 0xFC00, 0xF800, 0xF800},
+ {0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0x7C00, 0x7C00},
+ {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF}, /* a whole cell, to wipe it */
+ {0xFF00, 0xFF00, 0xFF00, 0xFF00, 0xFF00, 0xFF00, 0xFF00, 0xFF00}, /* a letter's */
+};
+enum { A_BOOM = 6, A_CANNON, A_WRECK, A_SAUCER = 10, A_SBOOM, A_PBOOM, A_ABOOM, A_SHOT, A_BUNKER, A_CELL = 19, A_LETTER };
+/* the arcade's letters, 5 columns of 7 pixels (the lowest bit on top) */
+static const char glyphs[] = "0123456789ABCDEGHILMNOPRSTVY<>-*=?";
+static const uint8_t font[][5] = {
+ {0x3E, 0x51, 0x49, 0x45, 0x3E}, {0x00, 0x42, 0x7F, 0x40, 0x00}, {0x62, 0x51, 0x49, 0x49, 0x46},
+ {0x22, 0x41, 0x49, 0x49, 0x36}, {0x18, 0x14, 0x12, 0x7F, 0x10}, {0x27, 0x45, 0x45, 0x45, 0x39},
+ {0x3C, 0x4A, 0x49, 0x49, 0x31}, {0x01, 0x71, 0x09, 0x05, 0x03}, {0x36, 0x49, 0x49, 0x49, 0x36},
+ {0x46, 0x49, 0x49, 0x29, 0x1E}, {0x7E, 0x11, 0x11, 0x11, 0x7E}, {0x7F, 0x49, 0x49, 0x49, 0x36},
+ {0x3E, 0x41, 0x41, 0x41, 0x22}, {0x7F, 0x41, 0x41, 0x41, 0x3E}, {0x7F, 0x49, 0x49, 0x49, 0x41},
+ {0x3E, 0x41, 0x49, 0x49, 0x7A}, {0x7F, 0x08, 0x08, 0x08, 0x7F}, {0x00, 0x41, 0x7F, 0x41, 0x00},
+ {0x7F, 0x40, 0x40, 0x40, 0x40}, {0x7F, 0x02, 0x0C, 0x02, 0x7F}, {0x7F, 0x04, 0x08, 0x10, 0x7F},
+ {0x3E, 0x41, 0x41, 0x41, 0x3E}, {0x7F, 0x09, 0x09, 0x09, 0x06}, {0x7F, 0x09, 0x19, 0x29, 0x46},
+ {0x26, 0x49, 0x49, 0x49, 0x32}, {0x01, 0x01, 0x7F, 0x01, 0x01}, {0x1F, 0x20, 0x40, 0x20, 0x1F},
+ {0x07, 0x08, 0x70, 0x08, 0x07}, {0x08, 0x14, 0x22, 0x41, 0x00}, {0x00, 0x41, 0x22, 0x14, 0x08},
+ {0x08, 0x08, 0x08, 0x08, 0x08}, {0x22, 0x14, 0x7F, 0x14, 0x22}, {0x14, 0x14, 0x14, 0x14, 0x14},
+ {0x02, 0x01, 0x51, 0x09, 0x06},
+};
+/* the attract screen, typed out a letter at a time, and where its lines go */
+static const char attract[] = "PLAY\0SPACE INVADERS\0*SCORE ADVANCE TABLE*\0=? MYSTERY\0=30 POINTS\0=20 POINTS\0=10 POINTS";
+static const uint8_t attract_at[7][2] = {{96, 64}, {56, 88}, {28, 112}, {80, 128}, {80, 144}, {80, 160}, {80, 176}};
+#define TYPED (int)(sizeof attract - 1)
+/* the saucer's points, tens of them, by how many shots were fired */
+static const uint8_t ufo[15] = {10, 5, 5, 10, 15, 10, 10, 5, 30, 10, 10, 10, 5, 15, 10};
+/* the columns the plunger shot (16) and the squiggly one (15) come from, in turn */
+static const uint8_t cols[31] = {1, 7, 1, 1, 1, 4, 11, 1, 6, 3, 1, 1, 11, 9, 2, 8,
+ 11, 1, 6, 3, 1, 1, 11, 9, 2, 8, 2, 11, 4, 7, 10};
+/* how high the rack starts, wave after wave (the arcade's numbers: the bottom row's top is 248 less it) */
+static const uint8_t starts[9] = {0x78, 0x60, 0x50, 0x48, 0x48, 0x48, 0x40, 0x40, 0x40};
+
+/* invaders.sav */
+static struct {
+ uint8_t magic, version, pad[2];
+ uint32_t hi;
+} sv;
+#define SAVE_NAME "invaders.sav"
+
+static color_t strip[SCREEN_W * STRIP_H];
+static uint8_t vram[240][30]; /* the picture from the arcade's row 7, a bit a pixel, the top bit the leftmost */
+static uint16_t pic[8]; /* a picture made on the spot: a letter, an invader's shot */
+enum { S_TITLE, S_PLAY, S_OVER };
+enum { OV_NONE, OV_PAUSE, OV_QUIT };
+static uint32_t dirty, frames;
+static int state, ov, sel, typed, line, col, t_over; /* typed: the letters shown, of a line, col */
+static int score, lives, wave, shots, bonus, clear_t;
+/* the cannon (the left of its 16 columns), its shot and the shot's burst */
+static int px, die, fire_x, fire_y, fire_held, pb_x, pb_y, pb_t;
+/* the rack: each invader's 16 x 8 cell, and whether it is alive (1) and which picture it shows (2) */
+static uint8_t ax[55], ay[55], st[55];
+static int live, spawn, cur, dir, rdx, rdy, edge, ref_x, boom_i, boom_t;
+/* the invaders' shots: rolling, plunger, squiggly */
+typedef struct {
+ uint8_t on, x, y, f, steps, t, bx, by; /* t: the frames its burst has left, at bx, by */
+} shot_t;
+static shot_t as[3];
+static int next[3]; /* where the plunger and squiggly shots are in cols[] */
+/* the saucer: where, which way, the frames until the next one; hit: its burst, then its points */
+static int ux, udx, u_wait, u_hit;
+
+/* ------------------------------------------------------------ the picture */
+/* a picture at x, y (the arcade's): lit, wiped, or only looked at; whether it met anything lit */
+enum { SET, CLEAR, TEST };
+static int blit(const uint16_t *a, int x, int y, int mode) {
+ int hit = 0;
+ for (int r = 0; r < 8; r++) {
+ unsigned row = (unsigned)(y + r - OFF);
+ uint32_t v = (uint32_t)a[r] << 16 >> (x & 7);
+ for (int k = 0; row < 240 && k < 3; k++, v <<= 8) {
+ uint8_t *p = &vram[row][(x >> 3) + k], b = (uint8_t)(v >> 24);
+ hit |= *p & b;
+ if (mode == SET) *p |= b;
+ if (mode == CLEAR) *p &= (uint8_t)~b;
+ }
+ }
+ if (mode != TEST) {
+ int a0 = (y - OFF) >> 3, a1 = (y + 7 - OFF) >> 3;
+ for (a0 = a0 < 0 ? 0 : a0; a0 <= a1 && a0 < 30; a0++) dirty |= 1u << a0;
+ }
+ return hit;
+}
+static void put(int a, int x, int y) { blit(art[a], x, y, SET); }
+static void wipe(int x, int y) { blit(art[A_CELL], x, y, CLEAR); }
+
+static void text(int x, int y, const char *s, int n) {
+ for (; *s && n-- > 0; s++, x += 8) {
+ int g = 0;
+ while (glyphs[g] && glyphs[g] != *s) g++;
+ for (int r = 0; r < 8; r++) {
+ pic[r] = 0;
+ for (int c = 0; glyphs[g] && c < 5; c++) pic[r] |= (uint16_t)((font[g][c] >> r & 1) << (15 - c));
+ }
+ blit(art[A_LETTER], x, y, CLEAR);
+ blit(pic, x, y, SET);
+ }
+}
+static void digits(int x, int y, int v, int n) {
+ char s[5] = {0};
+ while (n--) s[n] = (char)('0' + v % 10), v /= 10;
+ text(x, y, s, 4);
+}
+static void hud(void) {
+ digits(24, 24, score, 4), digits(96, 24, (int)sv.hi, 4);
+ if (state == S_TITLE) return;
+ digits(8, LY, lives, 1);
+ for (int k = 1; k < 7; k++) {
+ wipe(8 + 16 * k, LY);
+ if (k < lives) put(A_CANNON, 8 + 16 * k, LY);
+ }
+}
+static void screen(void) { /* a clean picture: the scores and the credits */
+ for (uint8_t *p = vram[0]; p < vram[240]; p++) *p = 0;
+ text(8, 8, "SCORE<1> HI-SCORE SCORE<2>", 26), text(168, 24, "0000", 4), text(136, LY, "CREDIT 00", 9);
+ dirty = ALL;
+ hud();
+}
+
+/* the invaders' shots, 3 pixels by 8 (the top row in the high bits) in four pictures: the rolling
+ one twists, the plunger's bar slides down it, the squiggly one wriggles */
+static const uint32_t shot_art[3][4] = {{0x593593, 0xC9AC9A, 0x4D64D6, 0x6B26B2},
+ {0x5D2492, 0x497492, 0x4925D2, 0x492497},
+ {0x88A88A, 0x454454, 0x2A22A2, 0x511511}};
+static const uint16_t *shot_pic(int k, int f) {
+ for (int r = 0; r < 8; r++) pic[r] = (uint16_t)((shot_art[k][f] >> (21 - 3 * r) & 7) << 13);
+ return pic;
+}
+
+static uint32_t keys(void) {
+ uint64_t s = eadk_keyboard_scan();
+ return ((uint32_t)s & 0x800001FFu) | ((uint32_t)(s >> 32) & 0x00100870u) << 8;
+}
+
+static const uint16_t *look(int i) { return art[i / 22 * 2 + (st[i] >> 1)]; }
+
+/* ------------------------------------------------------------ the screen */
+static const char *const items[2][2] = {{T("Resume"), T("Quit game")}, {T("No"), T("Yes")}};
+static void overlay(void) {
+ gfx_fill_alpha(0, 0, SCREEN_W, SCREEN_H, 0, 150);
+ gfx_rrect(70, 60, 180, 120, 8, 0, 256);
+ gfx_rrect_outline(70, 60, 180, 120, 8, 2, WHITE, 256);
+ gfx_text_center(&np_font_title, 160, 92, ov == OV_PAUSE ? T("Paused") : T("Quit game?"), WHITE, 256);
+ for (int i = 0; i < 2; i++) {
+ int y = 106 + 32 * i;
+ if (sel == i) gfx_rrect(100, y, 120, 24, 4, GREEN, 256);
+ gfx_text_center(&np_font_body, 160, y + 17, items[ov - 1][i], sel == i ? 0 : WHITE, 256);
+ }
+}
+
+/* the picture's rows in the strip, through the cabinet's film */
+static void scene(void *ctx) {
+ gfx_fill(0, gfx_y0, SCREEN_W, gfx_y1 - gfx_y0, 0);
+ for (int y = gfx_y0; y < gfx_y1; y++) {
+ int py = y + OFF;
+ color_t c = py >= TOPY && py < 64 ? RED : py >= 184 ? GREEN : WHITE, *o = gfx_buf + (y - gfx_y0) * SCREEN_W + X0;
+ for (int x = 0; x < 224; x++)
+ if (vram[y][x >> 3] << (x & 7) & 0x80) o[x] = py >= LY && x >= 136 ? WHITE : c;
+ }
+ if (state == S_TITLE && typed >= TYPED) { /* the keys, and the prompt blinking */
+ gfx_text_center(&np_font_small, 160, 222, T("Left Right: move OK, EXE, Up: fire Back: pause"), GREEN, 256);
+ if (!(frames / 32 & 1)) gfx_text_center(&np_font_body, 160, 204, T("Press OK to play"), WHITE, 256);
+ }
+ if (ov) overlay();
+}
+
+static void present(void) {
+ for (int b = 0, e; b < 30; b = e) {
+ for (e = b; e < 30 && dirty >> e & 1; e++) {}
+ if (e > b) gfx_render(scene, 0, b * 8, e * 8);
+ else e++;
+ }
+ dirty = 0;
+}
+
+/* ------------------------------------------------------------ the rules */
+static void save(void) {
+ sv.magic = 'I', sv.version = 1;
+ if ((uint32_t)score > sv.hi) sv.hi = (uint32_t)score;
+ np_file_write(SAVE_NAME, &sv, sizeof sv);
+}
+
+static void add(int pts) {
+ if ((score += pts) > 9999) score -= 10000; /* (the arcade's 4 digits roll over) */
+ if (!bonus && score >= 1500) bonus = 1, lives++;
+ hud();
+}
+
+static void kill_cannon(void) {
+ die = 1, lives--;
+ if (fire_y) blit(art[A_SHOT], fire_x, fire_y, CLEAR), fire_y = 0;
+ for (int k = 0; k < 3; k++)
+ if (as[k].on) blit(shot_pic(k, as[k].f), as[k].x, as[k].y, CLEAR), as[k].on = 0;
+ hud();
+}
+
+/* the cannon's shot: 4 pixels up a frame; what it meets, found from where it is */
+static void shoot(void) {
+ if (pb_t && !--pb_t) blit(art[A_PBOOM], pb_x, pb_y, CLEAR); /* the burst goes, its shape cut out */
+ if (!fire_y) return;
+ int x = fire_x, y = fire_y -= 4, k = 0, i = 0;
+ blit(art[A_SHOT], x, y + 4, CLEAR);
+ if (y >= TOPY && !blit(art[A_SHOT], x, y, TEST)) {
+ put(A_SHOT, x, y);
+ return;
+ }
+ fire_y = 0;
+ while (k < 3 && !(as[k].on && (unsigned)(x - as[k].x) < 3 && (unsigned)(y + 3 - as[k].y) < 11)) k++;
+ while (i < 55 && !(st[i] & 1 && (unsigned)(x - ax[i]) < 16 && (unsigned)(y + 3 - ay[i]) < 11)) i++;
+ if (k < 3) { /* two shots meet */
+ blit(shot_pic(k, as[k].f), as[k].x, as[k].y, CLEAR);
+ as[k].on = 0, as[k].t = 16, as[k].bx = (uint8_t)(as[k].x - 1), as[k].by = as[k].y;
+ put(A_ABOOM, as[k].bx, as[k].by);
+ } else if (y >= TOPY && i < 55) { /* an invader: it bursts, and the rack waits for it */
+ st[i] = 0, live--, boom_i = i, boom_t = 16;
+ wipe(ax[i], ay[i]), put(A_BOOM, ax[i], ay[i]);
+ add(10 * (i / 22 + 1));
+ return;
+ } else if (y >= TOPY && udx && !u_hit && y < UY + 8) { /* the saucer */
+ u_hit = 120;
+ wipe(ux, UY), put(A_SBOOM, ux, UY);
+ add(10 * ufo[shots % 15]);
+ return;
+ }
+ pb_x = x - 3, pb_y = y < TOPY ? TOPY : y - 4, pb_t = 16;
+ put(A_PBOOM, pb_x, pb_y);
+}
+
+/* one invader takes the rack's step; after the last one, the rack decides the next step */
+static void march(void) {
+ int i = cur;
+ wipe(ax[i], ay[i]);
+ ax[i] = (uint8_t)(ax[i] + rdx), ay[i] = (uint8_t)(ay[i] + rdy), st[i] ^= 2;
+ wipe(ax[i], ay[i]); /* (and what was there: the bunkers it reaches) */
+ blit(look(i), ax[i], ay[i], SET);
+ if ((rdx > 0 && ax[i] >= 200) || (rdx < 0 && ax[i] <= 8)) edge = 1;
+ if (ay[i] + 8 > PY && !die) lives = 1, kill_cannon(); /* landed */
+ for (;;) {
+ if (++i == 55) {
+ i = 0, ref_x += rdx;
+ if (rdy) rdy = 0;
+ else if (edge) edge = 0, dir = -dir, rdy = 8;
+ rdx = rdy ? 0 : dir > 0 && live == 1 ? 3 : 2 * dir;
+ }
+ if (st[i] & 1) break;
+ }
+ cur = i;
+}
+
+/* an invader's shot (each one moves every third frame): it bursts, moves, or may be fired */
+static void alien_shot(int k) {
+ shot_t *s = &as[k];
+ int x = s->x, y = s->y;
+ if (s->t) {
+ if (!--s->t) blit(art[A_ABOOM], s->bx, s->by, CLEAR);
+ return;
+ }
+ if (!s->on) {
+ int rate = score < 200 ? 48 : score < 1000 ? 16 : score < 2000 ? 11 : score < 3000 ? 8 : 7, c;
+ for (int j = 0; j < 3; j++)
+ if (j != k && as[j].on && as[j].steps < rate) return;
+ if ((k == 1 && live == 1) || (k == 2 && udx) || die || !live) return;
+ if (k) {
+ c = cols[next[k]] - 1;
+ if (++next[k] == (k == 1 ? 16 : 31)) next[k] = k == 1 ? 0 : 16;
+ } else {
+ c = (px + 8 - ref_x) >> 4; /* the column above the cannon */
+ }
+ for (int i = c; (unsigned)c < 11 && i < 55; i += 11)
+ if (st[i] & 1) {
+ s->on = 1, s->x = (uint8_t)(ax[i] + 6), s->y = (uint8_t)(ay[i] + 8), s->steps = 0;
+ blit(shot_pic(k, s->f), s->x, s->y, SET);
+ return;
+ }
+ return;
+ }
+ blit(shot_pic(k, s->f), x, y, CLEAR);
+ s->y = (uint8_t)(y += live > 8 ? 4 : 5), s->f = (uint8_t)((s->f + 1) & 3), s->steps++;
+ if (y + 7 < GY && !blit(shot_pic(k, s->f), x, y, TEST)) {
+ blit(pic, x, y, SET);
+ return;
+ }
+ s->on = 0;
+ if (!die && y + 8 > PY && y < PY + 8 && (unsigned)(x + 2 - px) < 18) { /* the cannon */
+ kill_cannon();
+ return;
+ }
+ if (fire_y && (unsigned)(fire_x - x) < 3 && (unsigned)(fire_y + 3 - y) < 11) { /* the cannon's shot */
+ blit(art[A_SHOT], fire_x, fire_y, CLEAR);
+ pb_x = fire_x - 3, pb_y = fire_y - 4, pb_t = 16, fire_y = 0;
+ put(A_PBOOM, pb_x, pb_y);
+ }
+ s->t = 16, s->bx = (uint8_t)(x - 1), s->by = (uint8_t)(y + 7 >= GY ? GY - 7 : y + 3);
+ put(A_ABOOM, s->bx, s->by);
+}
+
+static void saucer(void) {
+ if (u_hit) { /* its burst, then its points, then nothing */
+ if (--u_hit == 60) {
+ wipe(ux, UY);
+ int p = 10 * ufo[shots % 15];
+ digits(ux, UY, p, p < 100 ? 2 : 3);
+ }
+ if (!u_hit) udx = 0, text(ux, UY, " ", 3);
+ return;
+ }
+ if (!udx) {
+ if (--u_wait <= 0 && live >= 8 && !as[2].on)
+ udx = shots & 1 ? -1 : 1, ux = udx > 0 ? 8 : 200, u_wait = 0x600;
+ return;
+ }
+ wipe(ux, UY);
+ ux += udx;
+ if (ux < 8 || ux > 200) udx = 0;
+ else put(A_SAUCER, ux, UY);
+}
+
+static void new_wave(void) {
+ int base = 248 - starts[wave ? (wave - 1) % 8 + 1 : 0];
+ for (int i = 0; i < 55; i++) ax[i] = (uint8_t)(24 + i % 11 * 16), ay[i] = (uint8_t)(base - i / 11 * 16);
+ screen();
+ for (int k = 0; k < 4; k++)
+ for (int q = 0; q < 4; q++) put(A_BUNKER + q, 32 + 45 * k + (q & 1) * 16, SHY + (q & 2) * 4);
+ for (int k = 0; k < 28; k++) vram[GY - OFF][k] = 0xFF;
+ put(A_CANNON, px, PY);
+ for (int k = 0; k < 3; k++) as[k].on = as[k].t = 0;
+ for (int i = 0; i < 55; i++) st[i] = 0;
+ live = spawn = cur = rdy = edge = boom_t = clear_t = 0;
+ dir = 1, rdx = 2, ref_x = 24, udx = u_hit = 0, u_wait = 0x600, fire_y = pb_t = 0;
+ wave++;
+}
+
+static void title(void) {
+ state = S_TITLE, typed = line = col = 0;
+ screen();
+}
+
+static void start(void) {
+ state = S_PLAY, score = wave = shots = bonus = die = 0, lives = 3, px = 16;
+ next[1] = 0, next[2] = 16;
+ new_wave();
+}
+
+/* a frame of the game, 60 a second */
+static void tick(uint32_t keys) {
+ frames++;
+ if (state == S_TITLE) {
+ if (typed < TYPED && frames % 4 == 0) { /* the next letter; the table's pictures come with its title */
+ if (!attract[typed]) typed++, line++, col = 0;
+ text(attract_at[line][0] + 8 * col++, attract_at[line][1], attract + typed++, 1);
+ if (typed == TYPED) dirty = ALL; /* (the keys come under it) */
+ if (line == 3 && col == 1)
+ for (int k = 0; k < 4; k++) put(k ? 2 * (3 - k) : A_SAUCER, 60, 128 + 16 * k);
+ }
+ if (typed >= TYPED && frames % 32 == 0) dirty |= 0x0F000000u; /* the prompt blinks */
+ return;
+ }
+ if (state == S_OVER) {
+ if (typed < 9 && frames % 6 == 0) typed++, text(72, 48, "GAME OVER", typed);
+ if (++t_over > 300) title();
+ return;
+ }
+ if (spawn < 55) { /* a new rack, drawn an invader a frame */
+ st[spawn] = 1, blit(look(spawn), ax[spawn], ay[spawn], SET);
+ if (++spawn == 55) live = 55;
+ return;
+ }
+ if (die) { /* the cannon blows up, then the next one comes, or the game is over */
+ if (die % 5 == 0 && die <= 60) {
+ wipe(px, PY);
+ if (die < 60) put(A_WRECK + (die / 5 & 1), px, PY);
+ }
+ if (++die < 120) return;
+ die = 0, px = 16;
+ if (!lives) {
+ state = S_OVER, typed = t_over = 0;
+ save();
+ return;
+ }
+ put(A_CANNON, px, PY);
+ return;
+ }
+ int dx = !!(keys & (KEY(eadk_key_right) | KEY(eadk_key_six))) - !!(keys & (KEY(eadk_key_left) | KEY(eadk_key_four)));
+ if (dx && px + dx >= 16 && px + dx <= 192) wipe(px, PY), px += dx, put(A_CANNON, px, PY);
+ int fire = !!(keys & (KEY(eadk_key_ok) | KEY(eadk_key_exe) | KEY(eadk_key_up) | KEY(eadk_key_eight)));
+ if (fire && !fire_held && !fire_y && !pb_t) fire_x = px + 7, fire_y = PY, shots++; /* a new press each shot */
+ fire_held = fire;
+ shoot();
+ if (boom_t) {
+ if (!--boom_t) wipe(ax[boom_i], ay[boom_i]);
+ } else if (live) {
+ march();
+ } else if (++clear_t > 60) {
+ new_wave();
+ return;
+ }
+ alien_shot((int)(frames % 3));
+ saucer();
+}
+
+static void load(void) {
+ uint32_t len = 0;
+ const uint8_t *d = np_file_read(SAVE_NAME, &len);
+ if (d && len == sizeof sv && d[0] == 'I' && d[1] == 1)
+ for (uint32_t i = 0; i < sizeof sv; i++) ((uint8_t *)&sv)[i] = d[i];
+}
+
+int main(void) {
+ np_app_begin();
+ color_t *their_strip = gfx_buf;
+ gfx_buf = strip;
+ load();
+ title();
+ const uint32_t ok = KEY(eadk_key_ok) | KEY(eadk_key_exe) | KEY(eadk_key_five), back = KEY(eadk_key_back);
+ const uint32_t up = KEY(eadk_key_up) | KEY(eadk_key_eight), down = KEY(eadk_key_down) | KEY(eadk_key_two);
+ uint32_t held = keys(), stale = held; /* keys still down from the launcher wait to be let go */
+ uint32_t last = (uint32_t)eadk_timing_millis(), acc = 0;
+ dirty = ALL;
+ for (;;) {
+ uint32_t now = (uint32_t)eadk_timing_millis();
+ uint32_t k = keys(), hit = k & ~held;
+ stale &= k, held = k, k &= ~stale;
+ if (k & (KEY(eadk_key_home) | KEY(eadk_key_on_off))) break;
+ if (ov) {
+ if (hit & (up | down)) sel ^= 1;
+ if (hit & (ok | back)) {
+ if (hit & ok && sel && ov == OV_QUIT) break;
+ ov = hit & ok && sel ? OV_QUIT : OV_NONE, sel = 0;
+ }
+ if (hit) dirty = ALL;
+ } else if (hit & back) {
+ if (state == S_TITLE) break;
+ ov = OV_PAUSE, sel = 0, dirty = ALL;
+ } else if (state == S_TITLE && hit & ok) {
+ start();
+ fire_held = 1;
+ }
+ acc = ov ? 0 : acc + (now - last) * 3, last = now;
+ for (int n = 0; acc >= 50 && n < 4; acc -= 50, n++) tick(k);
+ if (acc >= 50) acc = 0; /* (too far behind: let it go) */
+ if (dirty) {
+ eadk_display_wait_for_vblank();
+ present();
+ } else {
+ eadk_timing_msleep(4);
+ }
+ }
+ save();
+ gfx_buf = their_strip;
+ return np_app_end();
+}
diff --git a/games/invaders/tests/play.c b/games/invaders/tests/play.c
new file mode 100644
index 00000000..9c8c8973
--- /dev/null
+++ b/games/invaders/tests/play.c
@@ -0,0 +1,121 @@
+/* Space Invaders on a computer, for tests and pictures (make host, make test).
+ *
+ * play test a bot plays for an hour of the game's time: it must clear a wave, hit the
+ * saucer, lose a game and be back on the attract screen, with the rack, the
+ * shots and the picture always agreeing
+ * play film DIR N S N frames of the bot's game from frame S, a picture every 2 frames
+ * (DIR/f_NNNN.ppm)
+ */
+#define main si_main
+#include "../src/main.c"
+#undef main
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static uint16_t fb[SCREEN_H][SCREEN_W];
+void eadk_display_push_rect(eadk_rect_t r, const eadk_color_t *p) {
+ for (int j = 0; j < r.height; j++)
+ for (int i = 0; i < r.width; i++) fb[r.y + j][r.x + i] = p[j * r.width + i];
+}
+void eadk_display_push_rect_uniform(eadk_rect_t r, eadk_color_t c) {
+ for (int j = 0; j < r.height; j++)
+ for (int i = 0; i < r.width; i++) fb[r.y + j][r.x + i] = c;
+}
+bool eadk_display_wait_for_vblank(void) { return true; }
+uint64_t eadk_keyboard_scan(void) { return 0; }
+uint64_t eadk_timing_millis(void) { return 0; }
+void eadk_timing_msleep(uint32_t ms) { (void)ms; }
+uint32_t eadk_random(void) { return 0x9E3779B9u; }
+void *np_alloc(uint32_t size) { return malloc(size); }
+
+static void picture(const char *path) {
+ FILE *f = fopen(path, "wb");
+ if (!f) exit(2);
+ fprintf(f, "P6 320 240 255\n");
+ for (int y = 0; y < SCREEN_H; y++)
+ for (int x = 0; x < SCREEN_W; x++) {
+ uint16_t c = fb[y][x];
+ fputc((c >> 11) * 255 / 31, f), fputc((c >> 5 & 63) * 255 / 63, f), fputc((c & 31) * 255 / 31, f);
+ }
+ fclose(f);
+}
+
+/* the bot: out of the way of the shots coming down, else under the lowest invader nearest (or where
+ the saucer will be), firing; a new press each shot */
+static void step(uint32_t k) { /* a frame, as main() runs it: OK on the attract screen starts a game */
+ if (state == S_TITLE && k & KEY(eadk_key_ok)) start(), fire_held = 1;
+ tick(k);
+}
+
+static uint32_t bot(void) {
+ static int press;
+ press ^= 1;
+ if (state != S_PLAY) return press && frames % 40 < 2 ? KEY(eadk_key_ok) : 0;
+ int c = px + 7, target = -1, best = 1 << 30;
+ for (int k = 0; k < 3; k++) /* a shot above the cannon and close: step aside */
+ if (as[k].on && as[k].y > PY - 70 && as[k].x + 4 > px - 2 && as[k].x < px + 18)
+ return as[k].x + 1 < c ? KEY(eadk_key_right) : KEY(eadk_key_left);
+ if (udx && !u_hit) target = ux + 8 + udx * 44;
+ for (int i = 0; target < 0 && i < 55; i++)
+ if (st[i] & 1) {
+ int d = abs(ax[i] + 7 - c) - 4 * ay[i];
+ if (d < best) best = d, target = ax[i] + 7;
+ }
+ if (target < 0) return 0;
+ if (target > c + 1) return KEY(eadk_key_right);
+ if (target < c - 1) return KEY(eadk_key_left);
+ return press ? KEY(eadk_key_ok) : 0;
+}
+
+/* the rack and the picture agree: every live invader is drawn where it is (a burst going may cut
+ into one, as in the arcade, until it moves again) */
+static int check(void) {
+ int n = 0;
+ for (int i = 0; i < 55; i++)
+ if (st[i] & 1 && spawn == 55 && state == S_PLAY) {
+ int lit = 0;
+ n++;
+ lit = blit(look(i), ax[i], ay[i], TEST);
+ if (!lit)
+ return printf("invader %d not drawn at %d, %d (cursor %d, saucer %d %d, burst %d %d %d, wave %d)\n", i, ax[i], ay[i],
+ cur, ux, udx, pb_x, pb_y, pb_t, wave), 1;
+ }
+ if (spawn == 55 && state == S_PLAY && n != live) return printf("%d alive, %d counted\n", n, live), 1;
+ if (score < 0 || score > 9999 || lives < 0 || lives > 9) return printf("score %d, lives %d\n", score, lives), 1;
+ return 0;
+}
+
+int main(int argc, char **argv) {
+ gfx_buf = strip;
+ load();
+ title();
+ if (argc >= 5 && !strcmp(argv[1], "film")) {
+ int n = atoi(argv[3]), s = atoi(argv[4]);
+ for (int f = 0; f < s + n; f++) {
+ step(bot());
+ if (f >= s && (f - s) % 2 == 0) {
+ char path[256];
+ present();
+ gfx_render(scene, 0, 0, SCREEN_H);
+ snprintf(path, sizeof path, "%s/f_%04d.ppm", argv[2], (f - s) / 2);
+ picture(path);
+ }
+ }
+ return 0;
+ }
+ int waves = 0, saucers = 0, overs = 0, titles = 0, was = state;
+ for (int f = 0; f < 60 * 60 * 60; f++) {
+ step(bot());
+ if (u_hit == 119) saucers++;
+ if (state == S_PLAY && wave > waves) waves = wave;
+ if (state != was) overs += state == S_OVER, titles += state == S_TITLE, was = state;
+ if (f % 7 == 0) present();
+ if (check()) return printf("frame %d\n", f), 1;
+ }
+ printf("waves reached %d, saucers hit %d, games over %d, back to the title %d, best %u\n", waves, saucers, overs,
+ titles, sv.hi);
+ if (waves < 2 || saucers < 1 || overs < 1 || titles < 1) return printf("FAIL\n"), 1;
+ printf("ok\n");
+ return 0;
+}
diff --git a/launcher/lang/fr.txt b/launcher/lang/fr.txt
index c1fe3f86..f4239505 100644
--- a/launcher/lang/fr.txt
+++ b/launcher/lang/fr.txt
@@ -99,6 +99,7 @@ Break every brick Casse toutes les briques
Pong and more, side by side Pong et plus, côte à côte
Backgrounds, clocks, timers Fonds, horloges, minuteurs
Reach the door, trust nothing Atteins la porte, ne te fie à rien
+Stop the invasion, one cannon Arrête l'invasion avec un seul canon
# (names that stay as they are)
NumDash NumDash
NumBlocks NumBlocks
@@ -106,6 +107,7 @@ NumDrive NumDrive
2048 2048
NumVisuals NumVisuals
Level Devil Level Devil
+Space Invaders Space Invaders
# the games' credits
Inspired by Minecraft, not affiliated with Mojang Inspiré de Minecraft, sans lien avec Mojang
By Tatone26, from All the Apps Par Tatone26, tiré d'All the Apps
@@ -113,6 +115,8 @@ Inspired by Tatone26's All the Apps Inspiré d'All the Apps de Tatone26
Based on 2048 by Gabriele Cirulli D'après 2048 de Gabriele Cirulli
Based on Block Blast! by Hungry Studio D'après Block Blast! de Hungry Studio
Based on Level Devil by Unept D'après Level Devil d'Unept
+Based on Cookie Clicker by Orteil D'après Cookie Clicker d'Orteil
+Based on Space Invaders by Taito D'après Space Invaders de Taito
# a game the RAM of the calculator's software is too small for
Needs Il manque
KB more memory Ko de mémoire
diff --git a/launcher/lang/zh.txt b/launcher/lang/zh.txt
index 73a97ed1..36870f70 100644
--- a/launcher/lang/zh.txt
+++ b/launcher/lang/zh.txt
@@ -98,6 +98,8 @@ Break every brick 打碎每一块砖
Pong and more, side by side Pong 等游戏,两人并肩玩
Backgrounds, clocks, timers 背景、时钟、计时器
Reach the door, trust nothing 走到门口,什么都别相信
+Space Invaders 太空侵略者
+Stop the invasion, one cannon 一门大炮,挡住入侵
# (names that stay as they are)
NumDash NumDash
NumBlocks NumBlocks
@@ -112,6 +114,8 @@ Inspired by Tatone26's All the Apps 灵感来自 Tatone26 的 All the Apps
Based on 2048 by Gabriele Cirulli 改编自 Gabriele Cirulli 的 2048
Based on Block Blast! by Hungry Studio 改编自 Hungry Studio 的 Block Blast!
Based on Level Devil by Unept 改编自 Unept 的 Level Devil
+Based on Cookie Clicker by Orteil 改编自 Orteil 的 Cookie Clicker
+Based on Space Invaders by Taito 改编自 Taito 的 Space Invaders
# a game the RAM of the calculator's software is too small for
Needs 内存还差
KB more memory KB
diff --git a/tests/test_games.py b/tests/test_games.py
index 0fec92a3..4a90ffcc 100644
--- a/tests/test_games.py
+++ b/tests/test_games.py
@@ -113,6 +113,12 @@ GAMES = {
"cookieclicker": ("CookieClicker.nwa", "cookieclicker.sav",
presses((1500, "ok"), (2000, "ok"), (2300, "ok"), (2600, "ok")), 4000,
presses((1500, "ok"), (1800, "ok")), 3000),
+ # a game: right to the gap between the first bunkers, and four shots up the third column; Home keeps the
+ # best. Next time another game, five shots, quit with On/Off: the best is read back and kept
+ "invaders": ("SpaceInvaders.nwa", "invaders.sav",
+ presses((1500, "ok"), (2600, "right", 700), (3500, "ok"), (4100, "ok"), (4700, "ok"), (5300, "ok")), 6000,
+ presses((1500, "ok"), (2600, "right", 700), (3500, "ok"), (4100, "ok"), (4700, "ok"), (5300, "ok"),
+ (5900, "ok")), 6500),
# the intro film is skipped (seen), Lucky walks up the dock and talks to the
# guardians; next time the game starts where it was left
"championisland": ("ChampionIsland.nwa", "champion.sav",
@@ -295,6 +301,9 @@ CHECKS = {
"cookieclicker": (lambda v: len(v) == 120 and v[:3] == b"C\1\1" and struct.unpack_from("<I", v, 44)[0] == 3
and struct.unpack_from("<d", v, 72)[0] >= 3,
lambda v: struct.unpack_from("<I", v, 44)[0] == 5 and struct.unpack_from("<d", v, 64)[0] >= 5),
+ # the best score ("I", version 1, the best at 4): some invaders shot; then more
+ "invaders": (lambda v: len(v) == 8 and v[:2] == b"I\1" and struct.unpack_from("<I", v, 4)[0] >= 20,
+ lambda v: len(v) == 8 and struct.unpack_from("<I", v, 4)[0] >= 30),
"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
# Air Hockey and the easy computer chosen; then the normal computer and Tanks, the tallies kept