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.

Five Nights at Freddy's: faster pictures, the screens around the nights, host checks

Mason3635ba62363a62a
diff --git a/games/fnaf/src/data.bin b/games/fnaf/src/data.bin
index 50c6b9b2..bebf3b10 100644
Binary files a/games/fnaf/src/data.bin and b/games/fnaf/src/data.bin differ
diff --git a/games/fnaf/src/game.c b/games/fnaf/src/game.c
index 90e592ce..79e2a665 100644
--- a/games/fnaf/src/game.c
+++ b/games/fnaf/src/game.c
@@ -64,7 +64,7 @@ static void title_step(void) {
/* Freddy's face twitches, and its light wavers */
face_t += DT, light_t += DT;
if (face_t >= 0.08f) face_t = 0, face = rnd() % 100 < 4 ? 1 + (int)(rnd() % 3) : 0;
- if (light_t >= 0.3f) light_t = 0, face_light = 14 + (int)(rnd() % 19);
+ if (light_t >= 0.3f) light_t = 0, face_light = 22 + (int)(rnd() % 17);
g.menu_n = (uint8_t)(2 + (g.stars & 1) + ((g.stars >> 1) & 1));
if (pressed(K_UP | K_DIGIT(8))) g.menu = (uint8_t)((g.menu + g.menu_n - 1) % g.menu_n);
if (pressed(K_DOWN | K_DIGIT(2))) g.menu = (uint8_t)((g.menu + 1) % g.menu_n);
@@ -87,7 +87,7 @@ static void title_draw(void) {
gfx_fill(0, gfx_y0, SCREEN_W, BAND_H, BLACK);
pic_draw(PIC_TITLE0 + face, 0, 0);
gfx_dim(0, gfx_y0, SCREEN_W, BAND_H, face_light);
- gfx_static(0, gfx_y0, SCREEN_W, BAND_H, 9, rnd());
+ gfx_static(0, gfx_y0, SCREEN_W, BAND_H, 7, rnd());
/* the slow white band going down, and lines that flash */
int sy = (int)(g.t / 20 * (SCREEN_H + 10)) % (SCREEN_H + 10) - 10;
gfx_blend(0, sy, SCREEN_W, 10, WHITE, 3);
@@ -264,7 +264,7 @@ static void six_draw(void) {
gfx_fill(110, cy + dh, 30, dh, BLACK);
}
gfx_text(FONT_HUGE, 148, cy, "AM", WHITE);
- if (g.t > 6.2f) gfx_text_c(FONT_TEXT, 160, 170, "*children cheering*", RGB(0xA0A0A0));
+ gfx_text_c(FONT_TEXT, 160, 170, g.t > 6.2f ? "*children cheering*" : "*chimes*", RGB(0xA0A0A0));
gfx_dim(0, gfx_y0, SCREEN_W, BAND_H, fade_in_out(g.t, 1, 10.5f, 1));
}
diff --git a/games/fnaf/src/gfx.c b/games/fnaf/src/gfx.c
index b65992ac..3a516a68 100644
--- a/games/fnaf/src/gfx.c
+++ b/games/fnaf/src/gfx.c
@@ -51,20 +51,32 @@ void gfx_frame_rect(int x, int y, int w, int h, uint16_t c) {
gfx_fill(x + w - 1, y, 1, h, c);
}
+/* static: grey noise, spread out for gfx_mix (made once) */
+static uint32_t noise[2048];
+
void gfx_static(int x, int y, int w, int h, int a, uint32_t seed) {
int x0, x1, r0, r1;
if (!clip(x, y, w, h, &x0, &x1, &r0, &r1) || a <= 0) return;
+ if (!noise[0]) {
+ uint32_t s = 0x2545F491u;
+ for (int i = 0; i < 2048; i++) {
+ s ^= s << 13, s ^= s >> 17, s ^= s << 5;
+ uint32_t g = (s >> 24) * 3 / 4;
+ uint32_t c = (g & 0xF8) << 8 | (g & 0xFC) << 3 | g >> 3;
+ noise[i] = ((c | c << 16) & 0x07E0F81F) | 1u << 31; /* (the top bit: made) */
+ }
+ }
for (int r = r0; r < r1; r++) {
uint32_t s = seed ^ (uint32_t)(gfx_y0 + r) * 0x9E3779B1u;
s ^= s >> 15, s *= 0x2C1B3C6Du, s ^= s >> 12;
/* a line now and then is brighter, as the game's static has */
- int la = (s & 31) == 0 ? a + 6 : a;
+ uint32_t la = (s & 31) == 0 ? (uint32_t)a + 6 : (uint32_t)a;
if (la > 32) la = 32;
+ const uint32_t *nz = noise + (s >> 16 & 1023);
for (uint16_t *p = gfx_band + r * SCREEN_W + x0, *e = gfx_band + r * SCREEN_W + x1; p < e; p++) {
- s ^= s << 13, s ^= s >> 17, s ^= s << 5;
- uint32_t g = (s >> 24) * 3 / 4;
- uint16_t n = (uint16_t)((g & 0xF8) << 8 | (g & 0xFC) << 3 | g >> 3);
- *p = gfx_mix(n, *p, la);
+ uint32_t n = *nz++ & 0x07E0F81F, b = (*p | (uint32_t)*p << 16) & 0x07E0F81F;
+ b = (b + ((n - b) * la >> 5)) & 0x07E0F81F;
+ *p = (uint16_t)(b | b >> 16);
}
}
}
@@ -75,7 +87,7 @@ void gfx_dim(int x, int y, int w, int h, int a) {
for (int r = r0; r < r1; r++)
for (uint16_t *p = gfx_band + r * SCREEN_W + x0, *e = gfx_band + r * SCREEN_W + x1; p < e; p++) {
if (a <= 32) {
- *p = gfx_mix(*p, BLACK, 32 - a);
+ *p = gfx_mix(*p, BLACK, a);
} else { /* brighter: each channel times a / 32, up to 2 */
uint32_t v = *p, R = (v >> 11) * (uint32_t)a >> 5, G = (v >> 5 & 63) * (uint32_t)a >> 5, B = (v & 31) * (uint32_t)a >> 5;
*p = (uint16_t)((R > 31 ? 31 : R) << 11 | (G > 63 ? 63 : G) << 5 | (B > 31 ? 31 : B));
diff --git a/games/fnaf/src/pic.c b/games/fnaf/src/pic.c
index 7e98403a..d6a95300 100644
--- a/games/fnaf/src/pic.c
+++ b/games/fnaf/src/pic.c
@@ -155,10 +155,18 @@ static void block(Bits *b, const Huff *dc, const Huff *ac, int *pred, const uint
}
/* ------------------------------------------------------------------ one square */
-static const uint8_t bayer[16] = {0, 8, 2, 10, 12, 4, 14, 6, 3, 11, 1, 9, 15, 7, 13, 5};
+#if defined(__ARM_FEATURE_SAT)
+#include <arm_acle.h>
+#define SAT8(v) __usat(v, 8)
+#else
+#define SAT8(v) ((v) < 0 ? 0 : (v) > 255 ? 255 : (v))
+#endif
+/* a 4 x 4 ordered dither: what is added to red and blue (0 to 7) and green (0 to 3) before they lose bits */
+static const uint8_t dither_rb[4][4] = {{0, 4, 1, 5}, {6, 2, 7, 3}, {1, 5, 0, 4}, {7, 3, 6, 2}};
+static const uint8_t dither_g[4][4] = {{0, 2, 0, 2}, {3, 1, 3, 1}, {0, 2, 0, 2}, {3, 1, 3, 1}};
-/* decodes the square at data into px (16 x 16, stride 16) */
-static void square(const uint8_t *data, int qset, uint16_t *px) {
+/* decodes the square at data into dst (16 x 16, rows stride apart) */
+static void square(const uint8_t *data, int qset, uint16_t *dst, int stride) {
static Huff h[4];
static const uint8_t *loaded;
if (loaded != fnaf_bin) {
@@ -174,22 +182,25 @@ static void square(const uint8_t *data, int qset, uint16_t *px) {
block(&b, &h[2], &h[3], &pred, qc, cb);
pred = 0;
block(&b, &h[2], &h[3], &pred, qc, cr);
- for (int r = 0; r < 16; r += 2)
- for (int c = 0; c < 16; c += 2) {
- int ci = (r >> 1) * 8 + (c >> 1), u = cb[ci] - 128, v = cr[ci] - 128;
- int dr = (91881 * v + 32768) >> 16, dg = (-22554 * u - 46802 * v + 32768) >> 16, db = (116130 * u + 32768) >> 16;
- for (int i = 0; i < 2; i++)
- for (int j = 0; j < 2; j++) {
- int rr = r + i, cc = c + j;
- int l = y[(rr >> 3) * 2 + (cc >> 3)][(rr & 7) * 8 + (cc & 7)];
- int d = bayer[(rr & 3) * 4 + (cc & 3)];
- int R = l + dr + (d >> 1), G = l + dg + (d >> 2), B = l + db + (d >> 1);
- R = R < 0 ? 0 : R > 255 ? 255 : R;
- G = G < 0 ? 0 : G > 255 ? 255 : G;
- B = B < 0 ? 0 : B > 255 ? 255 : B;
- px[rr * 16 + cc] = (uint16_t)((R & 0xF8) << 8 | (G & 0xFC) << 3 | B >> 3);
- }
+ for (int rp = 0; rp < 8; rp++) { /* two rows at a time, sharing their colours */
+ int dr[8], dg[8], db[8];
+ for (int c = 0; c < 8; c++) {
+ int u = cb[rp * 8 + c] - 128, v = cr[rp * 8 + c] - 128;
+ dr[c] = (91881 * v + 32768) >> 16;
+ dg[c] = (-22554 * u - 46802 * v + 32768) >> 16;
+ db[c] = (116130 * u + 32768) >> 16;
}
+ for (int r = 2 * rp; r < 2 * rp + 2; r++) {
+ const uint8_t *yl = y[(r >> 3) * 2] + (r & 7) * 8, *drb = dither_rb[r & 3], *dgg = dither_g[r & 3];
+ uint16_t *o = dst + r * stride;
+ for (int c = 0; c < 16; c++) {
+ if (c == 8) yl = y[(r >> 3) * 2 + 1] + (r & 7) * 8;
+ int l = yl[c & 7], k = c >> 1;
+ int R = SAT8(l + dr[k] + drb[c & 3]), G = SAT8(l + dg[k] + dgg[c & 3]), B = SAT8(l + db[k] + drb[(c + 2) & 3]);
+ o[c] = (uint16_t)((R & 0xF8) << 8 | (G & 0xFC) << 3 | B >> 3);
+ }
+ }
+ }
}
/* ------------------------------------------------------------------ pictures */
@@ -234,9 +245,14 @@ void pic_part(int id, int x, int y, int sx, int sy, int w, int h) {
int pr0 = y0 - y + sy, pr1 = y1 - y + sy, pc0 = x0 - x + sx, pc1 = x1 - x + sx;
for (int my = pr0 >> 4; my <= (pr1 - 1) >> 4 && my < in.mh; my++)
for (int mx = pc0 >> 4; mx <= (pc1 - 1) >> 4 && mx < in.mw; mx++) {
- square(bank + square_at(&in, my * in.mw + mx), in.q, px);
+ const uint8_t *data = bank + square_at(&in, my * in.mw + mx);
int r0 = my * 16 > pr0 ? my * 16 : pr0, r1 = my * 16 + 16 < pr1 ? my * 16 + 16 : pr1;
int c0 = mx * 16 > pc0 ? mx * 16 : pc0, c1 = mx * 16 + 16 < pc1 ? mx * 16 + 16 : pc1;
+ if (r1 - r0 == 16 && c1 - c0 == 16) { /* all of it shows: straight into the band */
+ square(data, in.q, gfx_band + (r0 - sy + y - gfx_y0) * SCREEN_W + (c0 - sx + x), SCREEN_W);
+ continue;
+ }
+ square(data, in.q, px, 16);
for (int r = r0; r < r1; r++) {
uint16_t *d = gfx_band + (r - sy + y - gfx_y0) * SCREEN_W + (c0 - sx + x);
const uint16_t *s = px + (r - my * 16) * 16 + (c0 - mx * 16);
diff --git a/games/fnaf/tests/check.py b/games/fnaf/tests/check.py
new file mode 100644
index 00000000..d17b4d36
--- /dev/null
+++ b/games/fnaf/tests/check.py
@@ -0,0 +1,190 @@
+#!/usr/bin/env python3
+"""Checks of Five Nights at Freddy's on a computer (make test): the host build, with AddressSanitizer and
+UBSan, through every picture, the menus, whole nights played by tests/play.c's own player, each animatronic's
+attack, the power going out, Golden Freddy, the custom night, pausing, Home and the saves.
+
+ python3 tests/check.py build/play build/pictures [--quick]
+
+--quick plays one whole night instead of three."""
+import os
+import re
+import shutil
+import subprocess
+import sys
+import tempfile
+
+PLAY = sys.argv[1] if len(sys.argv) > 1 else "build/play"
+PICTURES = sys.argv[2] if len(sys.argv) > 2 else "build/pictures"
+QUICK = "--quick" in sys.argv
+HERE = os.path.dirname(os.path.abspath(__file__))
+ENV = dict(os.environ, ASAN_OPTIONS="detect_leaks=0", UBSAN_OPTIONS="halt_on_error=1:print_stacktrace=1")
+failures = []
+SC_TITLE, SC_NIGHT, SC_SCARE, SC_SIX, SC_PAPER, SC_OVER, SC_CUSTOM = 0, 4, 5, 6, 7, 8, 9
+SCARE_BONNIE, SCARE_CHICA, SCARE_FREDDY, SCARE_FOXY, SCARE_DARK = range(5)
+IN_OFFICE = 12
+NIGHT = 60 * 535 + 200 # a night's steps, its card and a bit
+
+
+def run(args, frames, saves=None, what=""):
+ """Plays; returns the end state (a dict) and the events (6 AM, jumpscares) on the way"""
+ own = saves is None
+ if own:
+ saves = tempfile.mkdtemp(prefix="fnaf_check_")
+ shots = tempfile.mkdtemp(prefix="fnaf_shots_")
+ p = subprocess.run([PLAY, "--saves", saves, "--out", shots, "--frames", str(frames)] + args, capture_output=True,
+ text=True, env=ENV, timeout=1800)
+ shutil.rmtree(shots, ignore_errors=True)
+ if own:
+ shutil.rmtree(saves, ignore_errors=True)
+ if p.returncode or "runtime error" in p.stderr or "AddressSanitizer" in p.stderr:
+ failures.append(f"{what or args}: crashed or a sanitizer error\n{p.stderr[-2000:]}")
+ return None, []
+ m = re.search(r"END (.*)", p.stdout)
+ if not m:
+ failures.append(f"{what}: no end state\n{p.stdout[-500:]}")
+ return None, []
+ words = m.group(1).split()
+ s = {}
+ for k, v in zip(words[::2], words[1::2]):
+ s[k] = [int(x) for x in v.split(",")] if "," in v else float(v) if "." in v else int(v)
+ events = [dict(zip(e.split()[1::2], e.split()[2::2]), kind=e.split()[0])
+ for e in re.findall(r"EVENT (.*)", p.stdout)]
+ return s, events
+
+
+def check(cond, msg):
+ if not cond:
+ failures.append(msg)
+
+
+def record(saves, name):
+ p = os.path.join(saves, name)
+ return open(p, "rb").read() if os.path.exists(p) else None
+
+
+# every picture decodes
+d = tempfile.mkdtemp(prefix="fnaf_pics_")
+p = subprocess.run([PICTURES, d], capture_output=True, text=True, env=ENV, timeout=600)
+check(p.returncode == 0 and "runtime error" not in p.stderr, f"pictures: {p.stderr[-1500:]}")
+check(len(os.listdir(d)) > 200, f"pictures: only {len(os.listdir(d))} drawn")
+shutil.rmtree(d, ignore_errors=True)
+
+# the title, New Game, the newspaper (skipped), how to play, the first night's card, then the office
+saves = tempfile.mkdtemp(prefix="fnaf_check_")
+s, _ = run(["--keys", "60:ok,200:ok,700:ok"], 1400, saves, "a new game")
+if s:
+ check(s["scene"] == SC_NIGHT and s["night"] == 1 and s["keys_seen"] == 1, f"a new game: {s}")
+ check(record(saves, "fnaf.sav") is not None and record(saves, "fnaf_saves.py") is not None,
+ "a new game: no save, or no copy of it")
+# Back pauses; Quit night asks, and Yes goes back to the title
+s, _ = run(["--night", "1", "--keys", "400:back,430:down,450:down,470:ok,500:right,520:ok"], 600, saves, "quitting")
+if s:
+ check(s["scene"] == SC_TITLE, f"quitting a night: {s}")
+shutil.rmtree(saves, ignore_errors=True)
+
+# whole nights, played by the test's player: 6 AM, then the next night's card
+for n in ([1] if QUICK else [1, 2, 3]):
+ saves = tempfile.mkdtemp(prefix="fnaf_check_")
+ s, ev = run(["--night", str(n), "--bot"], NIGHT + 800, saves, f"night {n}")
+ if s:
+ six = [e for e in ev if e["kind"] == "six"]
+ check(six and int(six[0]["night"]) == n, f"night {n} not survived: {ev}")
+ check(s["reached"] == n + 1 and s["night"] == n + 1, f"night {n}: the next night not reached: {s}")
+ shutil.rmtree(saves, ignore_errors=True)
+
+# the fifth night's 6 AM: a star and the paycheck, then the title
+s, ev = run(["--night", "5", "--hour", "5", "--bot"], 89 * 60 + 2200, None, "night 5's end")
+if s:
+ check(any(e["kind"] == "six" for e in ev) and s["stars"] & 1 and s["scene"] == SC_TITLE,
+ f"night 5's end: {s} {ev}")
+
+# the doors' and lights' power: two doors and a light closed drain four points a second
+s, _ = run(["--night", "1", "--keys", "200:7,300:9,400-430:left,440:1"], 140 + 60 * 20, None, "power")
+if s:
+ check(s["doors"] == [1, 1] and 900 < s["power"] < 960, f"doors and lights: {s}")
+
+# the power goes out: Freddy's song, the dark, his jumpscare, the game over, the title
+s, ev = run(["--night", "1", "--power", "3"], 60 * 75, None, "power out")
+if s:
+ check(any(e["kind"] == "scare" and int(e["who"]) == SCARE_DARK for e in ev) and s["scene"] == SC_TITLE,
+ f"power out: {s} {ev}")
+
+# Bonnie and Chica come in while the monitor is up; it comes down by itself, and they get you
+s, ev = run(["--night", "1", "--ai", "0,20,20,0", "--keys", "300:8"], 60 * 80, None, "Bonnie and Chica")
+if s:
+ check(any(e["kind"] == "scare" and int(e["who"]) in (SCARE_BONNIE, SCARE_CHICA) for e in ev),
+ f"Bonnie and Chica: {s} {ev}")
+# a closed door sends them back
+s, ev = run(["--night", "1", "--ai", "0,20,20,0", "--keys", "200:7,300:9"], 60 * 60, None, "doors closed")
+if s:
+ check(not ev and s["pos"][1] != IN_OFFICE and s["pos"][2] != IN_OFFICE, f"doors closed: {s} {ev}")
+
+# Foxy: out of the cove with the cameras down, down the hall, in through the open door
+s, ev = run(["--night", "1", "--ai", "0,0,0,20"], 60 * 60, None, "Foxy")
+if s:
+ check(any(e["kind"] == "scare" and int(e["who"]) == SCARE_FOXY for e in ev), f"Foxy: {s} {ev}")
+# ... or banging on the closed one, for power
+s, ev = run(["--night", "1", "--ai", "0,0,0,20", "--keys", "200:7"], 60 * 60, None, "Foxy at the door")
+if s:
+ check(not ev and s["pounds"] >= 1, f"Foxy at the closed door: {s} {ev}")
+
+# Freddy stays on stage while Bonnie and Chica are on it
+s, ev = run(["--night", "1", "--ai", "20,0,0,0"], 60 * 40, None, "Freddy waits")
+if s:
+ check(s["pos"][0] == 0, f"Freddy left the stage before the others: {s}")
+# with them gone he comes to the East Hall Corner, then in while the monitor looks elsewhere
+s, ev = run(["--night", "1", "--ai", "20,0,0,0", "--pos", "0,5,7", "--keys", "3000:8"], 60 * 70, None, "Freddy")
+if s:
+ check(any(e["kind"] == "scare" and int(e["who"]) == SCARE_FREDDY for e in ev), f"Freddy: {s} {ev}")
+
+# Golden Freddy: his poster on 2B, then in the office, then the game is gone
+s, ev = run(["--night", "1", "--gold", "--keys", "300:8,360:2,400:2,480:8"], 1400, None, "Golden Freddy")
+if s:
+ check(any(e["kind"] == "golden" for e in ev) and s["running"] == 0, f"Golden Freddy: {s} {ev}")
+# ... unless the monitor goes up again
+s, ev = run(["--night", "1", "--gold", "--keys", "300:8,360:2,400:2,480:8,560:8"], 1400, None, "Golden Freddy gone")
+if s:
+ check(not ev and s["running"] == 1 and s["gold"] == 4, f"Golden Freddy gone: {s} {ev}")
+
+# the custom night: 1/9/8/7 is Golden Freddy's; 20/20/20/20 starts the night
+s, ev = run(["--stars", "3", "--keys", "100:down,120:down,140:down,160:ok,200-560:up,600:right,620-980:up,"
+ "1000:right,1020-1380:up,1400:right,1420-1780:up,1820:ok"], 2200, None, "custom night 20")
+if s:
+ check(s["scene"] == SC_NIGHT and s["night"] == 7 and s["ai"] == [20, 20, 20, 20], f"custom night 20/20/20/20: {s}")
+s, ev = run(["--stars", "3", "--keys", "100:down,120:down,140:down,160:ok,200:up,240:right,"
+ + ",".join(f"{260 + 12 * i}:up" for i in range(9)) + ",400:right,"
+ + ",".join(f"{420 + 12 * i}:up" for i in range(8)) + ",560:right,"
+ + ",".join(f"{580 + 12 * i}:up" for i in range(7)) + ",700:ok"], 1000, None, "custom night 1987")
+if s:
+ check(s["running"] == 0 and any(e["kind"] == "golden" for e in ev), f"custom night 1/9/8/7: {s} {ev}")
+
+# Home keeps the night: the next start is back in it, paused, at the same moment
+saves = tempfile.mkdtemp(prefix="fnaf_check_")
+s, _ = run(["--night", "2", "--keys", "200:7,1500:home"], 1600, saves, "Home")
+if s:
+ check(s["running"] == 0 and record(saves, "fnafres.sav") is not None, f"Home: {s}")
+ s2, _ = run([], 30, saves, "back after Home")
+ if s2:
+ check(s2["scene"] == SC_NIGHT and s2["paused"] == 1 and s2["night"] == 2 and abs(s2["t"] - s["t"]) < 0.5
+ and s2["doors"][0] == 1, f"back after Home: {s2} (left at {s})")
+ check(record(saves, "fnafres.sav") is None, "the kept night is read once")
+ # installing apps leaves only the scripts: the saves come back from the copy
+ for name in ("fnaf.sav", "fnafres.sav"):
+ if os.path.exists(os.path.join(saves, name)):
+ os.remove(os.path.join(saves, name))
+ s3, _ = run([], 30, saves, "after a reinstall")
+ if s3:
+ check(record(saves, "fnaf.sav") is not None, "after a reinstall: fnaf.sav not restored from fnaf_saves.py")
+shutil.rmtree(saves, ignore_errors=True)
+
+# the call: 0 mutes it
+s, _ = run(["--night", "1", "--keys", "600:0"], 800, None, "mute")
+if s:
+ check(s["muted"] == 1, f"mute: {s}")
+
+if failures:
+ print(f"{len(failures)} failures:")
+ for f in failures:
+ print("-", f)
+ sys.exit(1)
+print("all checks passed")
diff --git a/games/fnaf/tests/play.c b/games/fnaf/tests/play.c
index 21f43163..ae03c0b9 100644
--- a/games/fnaf/tests/play.c
+++ b/games/fnaf/tests/play.c
@@ -58,8 +58,10 @@ static uint32_t bot(int f) {
static int next_look, look_until;
bool up = n->flip >= 1;
bool bonnie = n->pos[BONNIE] == AT_DOOR, chica = n->pos[CHICA] == AT_DOOR;
- bool foxy = n->foxy >= 2, freddy = n->pos[FREDDY] == CAM_4B || n->pos[FREDDY] == CAM_4A;
- bool want_l = bonnie || foxy, want_r = chica || freddy;
+ /* the left door for Bonnie at it or Foxy gone from his cove; the right one for Chica, or for Freddy at
+ 4B while the monitor is up (he only comes in then) */
+ bool want_l = bonnie || n->foxy == 3;
+ bool want_r = chica || (n->pos[FREDDY] == CAM_4B && (n->monitor || f >= next_look - 40));
if (n->monitor) { /* on the cameras: look at Pirate Cove, then come down */
if (up && n->cam != CAM_1C && !(f & 1)) return K_DIGIT(1);
if (up && f >= look_until && !(f & 1)) return K_OK;
@@ -68,16 +70,17 @@ static uint32_t bot(int f) {
if (n->flip > 0 || (f & 1)) return 0;
if (n->door[LEFT] != want_l) return K_DIGIT(7);
if (n->door[RIGHT] != want_r) return K_DIGIT(9);
- if (f >= next_look && !n->dark) {
- next_look = f + 300 + (int)(rnd() % 400);
- look_until = f + 70;
+ if (f >= next_look && !n->dark) { /* a look at Pirate Cove: more often once Foxy peeks out */
+ next_look = f + (n->foxy >= 1 ? 200 : 360) + (int)(rnd() % 200);
+ look_until = f + 50;
return K_OK;
}
return k;
}
int main(int argc, char **argv) {
- int frames = 600, night = 0, power = -1, hour = -1, ai[4] = {-1, -1, -1, -1};
+ int frames = 600, night = 0, power = -1, hour = -1, ai[4] = {-1, -1, -1, -1}, gold = 0, stars = -1;
+ int pos[3] = {-1, -1, -1};
bool use_bot = false, all = false;
int every = 0;
const char *out = "build/shots", *saves = "build/host-saves";
@@ -103,6 +106,9 @@ int main(int argc, char **argv) {
unsigned s = (unsigned)atoi(argv[++i]);
for (unsigned k = 0; k < s % 1000; k++) rnd();
} else if (!strcmp(a, "--bot")) use_bot = true;
+ else if (!strcmp(a, "--gold")) gold = 1;
+ else if (!strcmp(a, "--pos")) sscanf(argv[++i], "%d,%d,%d", &pos[0], &pos[1], &pos[2]);
+ else if (!strcmp(a, "--stars")) stars = atoi(argv[++i]);
else {
fprintf(stderr, "unknown argument %s\n", a);
return 2;
@@ -116,6 +122,7 @@ int main(int argc, char **argv) {
fnaf_bin = fnaf_data;
host_time = 1000;
game_init();
+ if (stars >= 0) g.stars = (uint8_t)stars;
if (night) {
if (night == 7)
for (int k = 0; k < 4; k++) g.custom[k] = (int8_t)(ai[k] >= 0 ? ai[k] : 0);
@@ -130,6 +137,9 @@ int main(int argc, char **argv) {
if (ai[k] >= 0) g.n.ai[k] = (int8_t)ai[k];
if (power >= 0) g.n.power = (int16_t)power;
if (hour >= 0) g.n.hour = (uint8_t)hour, g.n.t = hour * 89.0f + 1;
+ if (gold) g.n.gold = 1;
+ for (int k = 0; k < 3; k++)
+ if (pos[k] >= 0) g.n.pos[k] = (uint8_t)pos[k];
}
uint32_t k = 0;
for (int i = 0; i < nholds; i++)
@@ -155,8 +165,9 @@ int main(int argc, char **argv) {
}
}
printf("END scene %d night %d hour %d power %d t %.1f frames %d running %d paused %d reached %d stars %d "
- "pos %d,%d,%d foxy %d gold %d dark %d\n",
+ "pos %d,%d,%d foxy %d gold %d dark %d muted %d ai %d,%d,%d,%d doors %d,%d cam %d keys_seen %d pounds %d\n",
g.scene, g.n.night, g.n.hour, g.n.power, g.n.t, f, g.running, g.paused, g.reached, g.stars, g.n.pos[0],
- g.n.pos[1], g.n.pos[2], g.n.foxy, g.n.gold, g.n.dark);
+ g.n.pos[1], g.n.pos[2], g.n.foxy, g.n.gold, g.n.dark, g.n.call_muted, g.n.ai[0], g.n.ai[1], g.n.ai[2],
+ g.n.ai[3], g.n.door[0], g.n.door[1], g.n.cam, g.keys_seen, g.n.foxy_pounds);
return 0;
}
diff --git a/games/fnaf/tools/pack.py b/games/fnaf/tools/pack.py
index 3a1571fb..ba48ecc0 100644
--- a/games/fnaf/tools/pack.py
+++ b/games/fnaf/tools/pack.py
@@ -320,7 +320,7 @@ def golden_office(office):
lum = a.mean(axis=2)
eyes = (lum > 150) & (a.max(axis=2) - a.min(axis=2) < 60)
alpha = np.clip((lum - 6) / 18, 0, 1)
- gold = np.stack([lum * 1.35, lum * 1.05, lum * 0.32], axis=2)
+ gold = np.stack([lum * 1.55, lum * 1.22, lum * 0.22], axis=2)
gold[eyes] = 0
rgba = np.dstack([np.clip(gold, 0, 255), alpha * 255]).astype(np.uint8)
sprite = Image.fromarray(rgba, "RGBA").rotate(-24, resample=Image.BICUBIC, expand=True)
@@ -331,7 +331,7 @@ def golden_office(office):
x0, y0 = 266 - sprite.width // 2, OH - h + 30
base = Image.fromarray(office.astype(np.uint8))
dim = sprite.copy()
- dim.putdata([(int(r * 0.55), int(g * 0.55), int(b * 0.55), al) for r, g, b, al in sprite.getdata()])
+ dim.putdata([(int(r * 0.72), int(g * 0.72), int(b * 0.72), al) for r, g, b, al in sprite.getdata()])
base.paste(dim, (x0, y0), dim)
gx0, gy0 = x0 // 16 * 16, y0 // 16 * 16
gx1 = min(OW, -(-(x0 + sprite.width) // 16) * 16)