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: Freddy waits for the monitor to come down

Mason36354f48e540cbd
diff --git a/games/fnaf/src/game.c b/games/fnaf/src/game.c
index 79e2a665..1502f999 100644
--- a/games/fnaf/src/game.c
+++ b/games/fnaf/src/game.c
@@ -12,7 +12,6 @@ uint32_t rnd(void) {
seed ^= seed << 13, seed ^= seed >> 17, seed ^= seed << 5;
return seed;
}
-float rndf(void) { return (float)(rnd() >> 8) / 16777216.0f; }
static bool pressed(uint32_t k) { return (g.pressed & k) != 0; }
diff --git a/games/fnaf/src/game.h b/games/fnaf/src/game.h
index 1bb1f907..c3eb45b5 100644
--- a/games/fnaf/src/game.h
+++ b/games/fnaf/src/game.h
@@ -39,11 +39,10 @@ typedef struct {
uint8_t freddy_state; /* 0 waits, 1 counts down, 2 goes at the next chance */
uint8_t foxy; /* 0 behind the curtain, 1 peeking, 2 out, 3 gone down the hall */
uint8_t foxy_pounds; /* times he hit the closed door */
- uint8_t foxy_seen; /* seen running in 2A */
uint8_t gold; /* Golden Freddy: 0 may come, 1 on 2B's poster, 2 seen there, 3 in the office, 4 gone */
uint8_t call_muted;
uint8_t dark; /* the power is out: 1 dark, 2 Freddy at the door, 3 all black */
- uint8_t pad[3];
+ uint8_t pad[4];
float t; /* seconds since 12 AM */
float hour_t;
float drain_t, penalty_t;
@@ -89,20 +88,17 @@ void game_init(void);
void game_step(uint32_t keys);
void game_draw(void);
uint32_t rnd(void);
-float rndf(void);
void start_night(int night);
void caption(const char *s);
/* night.c */
void night_begin(int night);
void night_step(void);
-bool night_power_out(void);
/* view.c */
void view_night(void);
void view_scare(void);
void view_captions(void);
-void view_clock(void);
/* calls.c: the phone call's line at t seconds into the night, or NULL; and when it ends */
const char *call_line(int night, float t);
diff --git a/games/fnaf/src/night.c b/games/fnaf/src/night.c
index 24027015..6e8a78c5 100644
--- a/games/fnaf/src/night.c
+++ b/games/fnaf/src/night.c
@@ -82,7 +82,6 @@ static void power_out(void) {
caption("*the power goes out*");
}
-bool night_power_out(void) { return N.dark != 0; }
/* ------------------------------------------------------------------ the office */
static bool side_in_view(int side) { return side == LEFT ? N.pan <= 24 : N.pan >= OFFICE_PAN - 24; }
@@ -276,7 +275,8 @@ static void wanderer(int who) {
static void freddy(void) {
uint8_t *pos = &N.pos[FREDDY];
- if (*pos == IN_OFFICE) { /* a try every second, 1 in 4 */
+ if (*pos == IN_OFFICE) { /* once the monitor is down: a try every second, 1 in 4 */
+ if (watching()) return;
N.freddy_try += DT;
if (N.freddy_try >= 1) {
N.freddy_try -= 1;
diff --git a/games/fnaf/src/view.c b/games/fnaf/src/view.c
index 4726581b..29461f7e 100644
--- a/games/fnaf/src/view.c
+++ b/games/fnaf/src/view.c
@@ -75,10 +75,10 @@ static bool wrap(int font, const char *s, int w, int k, const char **start, int
/* ------------------------------------------------------------------ around the view */
static void clock_and_night(void) {
- int h = N.hour ? N.hour : 12;
- int w = gfx_text_w(FONT_BIG, " AM") + gfx_text_w(FONT_CLOCK, h >= 10 ? "12" : "1");
- int x = 310 - w;
- x += gfx_text(FONT_CLOCK, x, 6, h >= 10 ? (h == 12 ? "12" : "10") : (char[]){(char)('0' + h), 0}, WHITE);
+ char h[3] = {'1', '2', 0}; /* 12 AM, then 1 to 5 */
+ if (N.hour) h[0] = (char)('0' + N.hour), h[1] = 0;
+ int x = 310 - gfx_text_w(FONT_BIG, " AM") - gfx_text_w(FONT_CLOCK, h);
+ x += gfx_text(FONT_CLOCK, x, 6, h, WHITE);
gfx_text(FONT_BIG, x, 8, " AM", WHITE);
int nx = 310 - gfx_text_w(FONT_HUD, "Night ") - gfx_text_w(FONT_PIXEL, "0");
nx += gfx_text(FONT_HUD, nx, 31, "Night ", WHITE);
@@ -209,7 +209,7 @@ static void camera_map(void) {
if (row[c >> 3] >> (c & 7) & 1) d[c] = WHITE;
}
const uint8_t *centres = m + 4 + size * stride;
- bool blink = (int)(g.t * 3) & 1 ? false : true;
+ bool blink = !((int)(g.t * 3) & 1);
for (int k = 0; k < CAM_COUNT; k++) {
int cx = mx + (int)rd16(centres + 4 * k), cy = my + (int)rd16(centres + 4 * k + 2);
bool sel = k == N.cam;
diff --git a/games/fnaf/tests/check.py b/games/fnaf/tests/check.py
index c092a568..2ce9180f 100644
--- a/games/fnaf/tests/check.py
+++ b/games/fnaf/tests/check.py
@@ -132,8 +132,9 @@ if s:
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")
+# with them gone he comes to the East Hall Corner, then in while the monitor looks elsewhere; he gets you once
+# it is down
+s, ev = run(["--night", "1", "--ai", "20,0,0,0", "--pos", "0,5,7", "--keys", "3000:8,3300:8"], 60 * 80, None, "Freddy")
if s:
check(any(e["kind"] == "scare" and int(e["who"]) == SCARE_FREDDY for e in ev), f"Freddy: {s} {ev}")