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.

Subway Surfers: the game's own app icon; no trains running on under low roofs

Mason3638b47e99def6b
diff --git a/games/subway/Makefile b/games/subway/Makefile
index 5c2de10a..342606d0 100644
--- a/games/subway/Makefile
+++ b/games/subway/Makefile
@@ -4,8 +4,8 @@
# make host build/play: the game on a computer, for tests and screenshots
# make test the game played on a computer (tests/check.py, with the sanitizers)
# make assets src/assets.c again: the fonts (tools/assets.py: Python + Pillow + NumPy)
-# make data APK=DIR src/data.c and src/data.h again, from the game's own Android package unzipped in DIR
-# (tools/apk.py: Python + UnityPy + Pillow + NumPy; the package is only read)
+# make data APK=DIR src/data.c, src/data.h and src/icon.png again, from the game's own Android package unzipped
+# in DIR (tools/apk.py, tools/icon.py: Python + UnityPy + Pillow + NumPy; the package is only read)
Q ?= @
# the ARM toolchain on the PATH, or in TOOLCHAIN=<its bin folder>
TOOLCHAIN ?=
@@ -67,6 +67,8 @@ assets:
data:
python3 -I tools/apk.py $(APK)
+ python3 -I tools/icon.py $(APK) src/icon.png
+ python3 ../../tools/round_icons.py src/icon.png
clean:
$(Q) rm -rf $(BUILD_DIR) build
diff --git a/games/subway/src/app.c b/games/subway/src/app.c
index 30d2e0ce..b0d3d36e 100644
--- a/games/subway/src/app.c
+++ b/games/subway/src/app.c
@@ -166,12 +166,17 @@ static void shop_buy(void) {
static void camera_follow(void) {
float tx = pl.x * 0.75f, ty = CAM_Y + pl.ground * 0.85f + (pl.y - pl.ground) * 0.35f;
if (pl.fly > 0) ty = CAM_Y + pl.y * 0.8f;
- /* under a roof */
- float roof = world_roof(pl.z - CAM_BACK) < world_roof(pl.z + 4) ? world_roof(pl.z - CAM_BACK) : world_roof(pl.z + 4);
- if (ty > roof - 0.4f) ty = roof - 0.4f;
- /* (the game's follow speeds: 15 across, 7.5 up and down) */
+ /* under a roof: from a little before it (the game lowers its camera there) */
+ float roof = 1000;
+ for (float dz = -CAM_BACK; dz <= 16; dz += 2) {
+ float r = world_roof(pl.z + dz);
+ if (r < roof) roof = r;
+ }
+ if (ty > roof - 0.5f) ty = roof - 0.5f;
+ /* (the game's follow speeds: 15 across, 7.5 up and down; at once down under a roof) */
cam_x += (tx - cam_x) * (1 - 1 / (1 + 15 * DT));
cam_y += (ty - cam_y) * (1 - 1 / (1 + 7.5f * DT));
+ if (cam_y > roof - 0.5f) cam_y = roof - 0.5f;
}
void app_step(uint32_t keys, uint32_t pressed) {
diff --git a/games/subway/src/icon.png b/games/subway/src/icon.png
index e63f8dff..e0f2151a 100644
Binary files a/games/subway/src/icon.png and b/games/subway/src/icon.png differ
diff --git a/games/subway/src/r3d.c b/games/subway/src/r3d.c
index 8e86f7ce..284ee8f8 100644
--- a/games/subway/src/r3d.c
+++ b/games/subway/src/r3d.c
@@ -382,19 +382,29 @@ static void raster(const Poly *q) {
const Pos *pp = pos + q->v0;
const Attr *at = q->kind == K_SHADE || q->kind == K_TEX ? attr + q->at : NULL;
int n = q->n;
- Edge e[MAXN];
- int ne = 0;
+ /* the edges of each side (a convex polygon has a left side and a right side from its top to its bottom; which
+ * way it turns tells which edges go down which side), each side's from the top */
+ float area = 0;
+ for (int i = 0, j = n - 1; i < n; j = i++) area += (float)pp[j].x * (float)pp[i].y - (float)pp[i].x * (float)pp[j].y;
+ Edge e[2][MAXN];
+ int ne[2] = {0, 0};
for (int i = 0, j = n - 1; i < n; j = i++) {
float ay = pp[j].y * (1 / SUB), by = pp[i].y * (1 / SUB);
if (ay == by) continue;
int ka = j, kb = i;
- if (ay > by) {
+ bool down = by > ay;
+ if (!down) {
float t = ay;
ay = by, by = t;
ka = i, kb = j;
}
if (by <= (float)ya || ay >= (float)yb) continue;
- Edge *E = &e[ne++];
+ int side = (down == (area > 0)) ? 1 : 0; /* 1: right */
+ Edge *E = &e[side][ne[side]];
+ /* (kept in order from the top) */
+ int k = ne[side]++;
+ while (k > 0 && e[side][k - 1].y0 > ay) e[side][k] = e[side][k - 1], k--;
+ E = &e[side][k];
float h = 1 / (by - ay), xa = pp[ka].x * (1 / SUB), xb = pp[kb].x * (1 / SUB);
E->y0 = ay, E->y1 = by;
E->dx = (xb - xa) * h, E->x = xa - ay * E->dx;
@@ -407,7 +417,7 @@ static void raster(const Poly *q) {
E->dv = (vb - va) * h, E->v = va - ay * E->dv;
}
}
- if (ne < 2) return;
+ if (!ne[0] || !ne[1]) return;
#ifdef HOST
r_stat_polys++;
#endif
@@ -417,16 +427,20 @@ static void raster(const Poly *q) {
int alpha = q->alpha >> 3;
float qa = q->a > 30000 ? 30000 : q->a < -30000 ? -30000 : q->a; /* (seen nearly edge-on) */
int32_t da = (int32_t)(qa * 65536.0f);
+ int li = 0, ri = 0;
for (int y = ya; y < yb; y++) {
- float yc = (float)y + 0.5f, xl = 1e9f, xr = -1e9f;
- const Edge *L = NULL, *R = NULL;
- for (int k = 0; k < ne; k++) {
- if (yc < e[k].y0 || yc >= e[k].y1) continue;
- float x = e[k].x + yc * e[k].dx;
- if (x < xl) xl = x, L = &e[k];
- if (x > xr) xr = x, R = &e[k];
+ float yc = (float)y + 0.5f;
+ while (li < ne[0] - 1 && yc >= e[0][li].y1) li++;
+ while (ri < ne[1] - 1 && yc >= e[1][ri].y1) ri++;
+ const Edge *L = &e[0][li], *R = &e[1][ri];
+ if (yc < L->y0 || yc >= L->y1 || yc < R->y0 || yc >= R->y1) continue;
+ float xl = L->x + yc * L->dx, xr = R->x + yc * R->dx;
+ if (xl > xr) {
+ float t = xl;
+ xl = xr, xr = t;
+ const Edge *T = L;
+ L = R, R = T;
}
- if (!L || xl > xr) continue;
int x0 = xl <= -1 ? 0 : (int)(xl + 0.5f), x1 = xr >= SCREEN_W ? SCREEN_W : (int)(xr + 0.5f);
if (x0 < 0) x0 = 0;
if (x0 >= x1) continue;
diff --git a/games/subway/src/world.c b/games/subway/src/world.c
index 938a8b54..739a4070 100644
--- a/games/subway/src/world.c
+++ b/games/subway/src/world.c
@@ -213,7 +213,10 @@ static float pattern(float z, float speed) {
/* (easier ones while the run is young) */
if (patterns < 3) k = k % 40;
float end = z;
- if (world_covered(z) || world_covered(z + 60)) {
+ /* (no train may run on under a low roof: anything near one is barriers only) */
+ bool low = false;
+ for (float dz = -10; dz <= 130; dz += 10) low |= world_covered(z + dz);
+ if (low) {
end = covered_pattern(z, d, l);
patterns++;
return end;
diff --git a/games/subway/tests/play.c b/games/subway/tests/play.c
index d5e31c3c..6f71f683 100644
--- a/games/subway/tests/play.c
+++ b/games/subway/tests/play.c
@@ -274,8 +274,20 @@ int main(int argc, char **argv) {
}
bool keep = raw && f >= raw_from && f <= raw_to && f % 4 == 0; /* (15 frames a second) */
if (shot || keep || f % draw_every == 0) {
+ extern uint32_t r_stat[4], r_stat_rows;
+ uint32_t before = r_stat[1] + r_stat[2] + r_stat[3] + r_stat[0] / 3 + r_stat_rows * 6;
app_draw();
if ((int)perf_polys > max_polys) max_polys = (int)perf_polys;
+ uint32_t cost = r_stat[1] + r_stat[2] + r_stat[3] + r_stat[0] / 3 + r_stat_rows * 6 - before;
+ static uint32_t worst[5], worst_f[5];
+ for (int k = 0; k < 5; k++)
+ if (cost > worst[k]) {
+ for (int m = 4; m > k; m--) worst[m] = worst[m - 1], worst_f[m] = worst_f[m - 1];
+ worst[k] = cost, worst_f[k] = (uint32_t)f;
+ break;
+ }
+ if (stats && f == frames - 1)
+ for (int k = 0; k < 5; k++) printf("worst frame %u: %u\n", worst_f[k], worst[k]);
}
if (keep) {
char p[512];
diff --git a/games/subway/tools/icon.py b/games/subway/tools/icon.py
index 7043ed6e..b4eaf730 100644
--- a/games/subway/tools/icon.py
+++ b/games/subway/tools/icon.py
@@ -1,50 +1,27 @@
#!/usr/bin/env python3
-"""Draws src/icon.png, the calculator's 55x56 icon: a subway train coming head-on down its track under a
-blue sky, the way the game's trains look. Drawn 8x larger, then scaled down.
+"""Makes src/icon.png, the calculator's 55x56 icon: the game's own app icon (Jake with his spray can), from its
+Android package's adaptive icon (its background and foreground layers), the part a phone shows, full to the
+edges. tools/round_icons.py at the root gives it NumPlay's rounded corners afterwards.
-Usage: icon.py src/icon.png"""
+Usage: icon.py PACKAGE src/icon.png (the folder the package was unzipped into; it is only read)"""
import sys
+from pathlib import Path
-from PIL import Image, ImageDraw
+from PIL import Image
-S = 8
-W, H = 55 * S, 56 * S
-
-def main(out):
- im = Image.new("RGBA", (W, H), (0, 0, 0, 0))
- d = ImageDraw.Draw(im)
- # the rounded square: sky above, gravel below
- mask = Image.new("L", (W, H), 0)
- ImageDraw.Draw(mask).rounded_rectangle((0, 0, W - 1, H - 1), radius=12 * S, fill=255)
- bg = Image.new("RGBA", (W, H))
- bd = ImageDraw.Draw(bg)
- for y in range(H):
- t = y / H
- if t < 0.62:
- c = (int(60 + 140 * t), int(159 + 90 * t), int(232 + 20 * t))
- else:
- c = (134, 115, 95)
- bd.line((0, y, W, y), fill=c + (255,))
- # rails going away from the eye
- for x0, x1 in ((14, 22), (41, 33)):
- bd.polygon([(x0 * S - S, H), (x0 * S + S, H), (x1 * S + S // 2, int(0.62 * H)), (x1 * S - S // 2, int(0.62 * H))],
- fill=(201, 207, 214, 255))
- im.paste(bg, (0, 0), mask)
- # the train's face: yellow, a dark roof edge, two windows, two lamps
- x0, x1, y0, y1 = 9 * S, 46 * S, 8 * S, 50 * S
- d.rounded_rectangle((x0, y0, x1, y1), radius=6 * S, fill=(11, 42, 85, 255))
- d.rounded_rectangle((x0 + S, y0 + S, x1 - S, y1 - S), radius=5 * S, fill=(242, 194, 48, 255))
- d.rectangle((x0 + S, y0 + 30 * S, x1 - S, y0 + 33 * S), fill=(46, 95, 168, 255))
- for wx0, wx1 in ((13, 26), (29, 42)):
- d.rounded_rectangle((wx0 * S, 14 * S, wx1 * S, 27 * S), radius=2 * S, fill=(43, 66, 96, 255))
- d.polygon([(wx0 * S + 2 * S, 15 * S), (wx0 * S + 6 * S, 15 * S), (wx0 * S + 2 * S, 22 * S)], fill=(120, 170, 220, 255))
- for lx in (15, 40):
- d.ellipse((lx * S - 3 * S, 41 * S - 3 * S, lx * S + 3 * S, 41 * S + 3 * S), fill=(255, 250, 220, 255))
- d.rectangle((23 * S, 10 * S, 32 * S, 12 * S), fill=(30, 30, 36, 255))
- small = im.resize((55, 56), Image.LANCZOS)
- small.save(out)
+def main(package, out):
+ res = Path(package) / "res" / "mipmap-xxxhdpi-v4"
+ bg = Image.open(res / "ic_launcher_background.png").convert("RGBA")
+ fg = Image.open(res / "ic_launcher_foreground.png").convert("RGBA")
+ im = bg.copy()
+ im.alpha_composite(fg.resize(bg.size, Image.LANCZOS))
+ # an adaptive icon is 108 units across, the middle 72 shown
+ w, h = im.size
+ k = w * 18 // 108
+ im = im.crop((k, k, w - k, h - k))
+ im.resize((55, 56), Image.LANCZOS).save(out)
if __name__ == "__main__":
- main(sys.argv[1])
+ main(sys.argv[1], sys.argv[2])