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 2: the game's own pictures

Mason363f2ade04e6d22
diff --git a/README.md b/README.md
index 52d7a2d3..218098ac 100644
--- a/README.md
+++ b/README.md
@@ -390,7 +390,7 @@ NumPlay is a fan project, made out of love for these games and for the NumWorks
- **Snow Rider 3D** inspired NumPlay's Snow Rider 3D, which makes its slope, sleds, gifts and camera the way the game does, with its models, colours, numbers and logo read from its Unity project ([q8j-dev/snow-rider-3d](https://github.com/q8j-dev/snow-rider-3d)). **[dennisimoo](https://github.com/dennisimoo)** brought it to NumPlay. Not affiliated with its makers.
- **Temple Run** by Imangi Studios inspired NumPlay's Temple Run, which follows the game's rules and numbers (its path, piece for piece, and its pacing, speeds, coins, power-ups, upgrades and objectives) and uses its own models (Guy Dangerous, the demon monkeys, the path, the coins and the scenery, with fewer triangles), all read from its Android package (version 1.0.8), and the **Lilita One** font (SIL Open Font License, [license](LICENSES/OFL-1.1-LilitaOne.txt)). Not affiliated with Imangi Studios.
- **[Level Devil](https://store.steampowered.com/app/3242750/)** by Unept: NumPlay's Level Devil is written in C with no code from the game, but its 80 rooms (their tiles, traps and timing) are the game's own, taken from its web build by games/leveldevil/tools/fetch.py, and its runner is drawn from the game's sprites.
-- **Five Nights at Freddy's 2** by Scott Cawthon inspired NumPlay's Five Nights at Freddy's 2, which uses the game's own pictures, as the fan port [fnaf-2_html5](https://github.com/VocalNutria9174/fnaf-2_html5) (VocalNutria9174) keeps them, and the DejaVu fonts ([license](LICENSES/DejaVu.txt)). Its AI levels, paths, music box, flashlight and Withered Foxy follow what the game's players read out of its events, written down on the [Technical FNaF Wiki](https://technicalfnaf.fandom.com) and the [Five Nights at Freddy's Wiki](https://freddy-fazbears-pizza.fandom.com). Not affiliated with Scott Cawthon.
+- **Five Nights at Freddy's 2** by Scott Cawthon inspired NumPlay's Five Nights at Freddy's 2, which uses the game's own pictures, from its Clickteam HTML5 build as the fan port [fnaf-2_html5](https://github.com/VocalNutria9174/fnaf-2_html5) (VocalNutria9174) keeps it, two of them from fredtheking's [FNaF2-RaylibCs](https://github.com/fredtheking/FNaF2-RaylibCs), and the DejaVu fonts ([license](LICENSES/DejaVu.txt)). Its AI levels, paths, music box, flashlight and Withered Foxy follow what the game's players read out of its events, written down on the [Technical FNaF Wiki](https://technicalfnaf.fandom.com) and the [Five Nights at Freddy's Wiki](https://freddy-fazbears-pizza.fandom.com). Not affiliated with Scott Cawthon.
- **Pong** by Atari (1972) inspired NumPlay's 2 Players, with air hockey, tanks in a maze in the spirit of Tank Trouble and the light cycles of Tron. All four are written in C for NumPlay and drawn from shapes, with no code or art from them.
- **[Cookie Clicker](https://orteil.dashnet.org/cookieclicker/)** by Orteil and Opti (DashNet) inspired NumPlay's Cookie Clicker, which uses the game's own pictures, texts and numbers (version 2.058, from its public mirror [ozh/cookieclicker](https://github.com/ozh/cookieclicker)) and the **Merriweather**, **Kavoon** and **Noto Sans** fonts (SIL Open Font License: [Merriweather](LICENSES/OFL-1.1-Merriweather.txt), [Kavoon](LICENSES/OFL-1.1-Kavoon.txt), [Noto Sans](LICENSES/OFL-1.1-NotoSans.txt)). Not affiliated with Orteil or DashNet.
@@ -527,6 +527,6 @@ NumPlay is licensed under the [GNU General Public License v3.0](LICENSE). Copyri
<tr>
<td align="center"><img src="docs/media/gallery/snowrider.gif" alt="Snow Rider 3D: sledding through the snowmen and stumps"><br><a href="games/snowrider/README.md"><b>Snow Rider 3D</b></a></td>
<td align="center"><img src="docs/media/gallery/templerun.gif" alt="Temple Run: a run along the temple path, a corner, a gap jumped, coins"><br><a href="games/templerun/README.md"><b>Temple Run</b></a></td>
- <td align="center"><img src="docs/media/gallery/fnaf2.gif" alt="Five Nights at Freddy's 2: the music box wound on CAM 11, a light down the hallway, the mask on as someone comes in"><br><a href="games/fnaf2/README.md"><b>Five Nights at Freddy's 2</b></a></td>
+ <td align="center"><img src="docs/media/gallery/fnaf2.gif" alt="Five Nights at Freddy's 2: the light down the hallway, the music box wound on CAM 11, Toy Bonnie in the right vent and the mask on"><br><a href="games/fnaf2/README.md"><b>Five Nights at Freddy's 2</b></a></td>
</tr>
</table>
diff --git a/docs/media/gallery/fnaf2.gif b/docs/media/gallery/fnaf2.gif
new file mode 100644
index 00000000..3aa898d2
Binary files /dev/null and b/docs/media/gallery/fnaf2.gif differ
diff --git a/docs/media/thumb_fnaf2.png b/docs/media/thumb_fnaf2.png
new file mode 100644
index 00000000..1643c53d
Binary files /dev/null and b/docs/media/thumb_fnaf2.png differ
diff --git a/games/fnaf2/README.md b/games/fnaf2/README.md
index 91a7ab73..c47013e3 100644
--- a/games/fnaf2/README.md
+++ b/games/fnaf2/README.md
@@ -17,22 +17,37 @@
</p>
<p align="center">
- <img src="../../docs/media/gallery/fnaf2.gif" width="320" alt="Five Nights at Freddy's 2: the music box wound on CAM 11, a light down the hallway, the mask on as someone comes in">
+ <img src="../../docs/media/gallery/fnaf2.gif" width="320" alt="Five Nights at Freddy's 2: the light down the hallway, the music box wound on CAM 11, Toy Bonnie in the right vent and the mask on">
</p>
## Highlights
* **The whole game:** nights 1 to 5, the 6th once the 5th is beaten, then the Custom Night with its ten animatronics and its ten modes, from 20/20/20/20 to Golden Freddy. The paycheck, the overtime check and the pink slip, and the stars on the title screen.
* **The office as you know it:** no doors, a hallway in front and a vent on each side. Look left and right, light the hallway with the flashlight and the vents with their lights, and put on the Freddy mask.
-* **The twelve cameras,** the four party rooms and the two vents dark but for the camera's light, and the music box on CAM 11 to wind.
+* **The twelve cameras,** each room as the game shows it in the camera's light and without it, the wide ones panning, and the music box on CAM 11 to wind.
* **Everyone, as the game moves them:** the Toys, the Withereds, Mangle, Balloon Boy, the Puppet and Golden Freddy, with the AI levels each night sets at its hours and the game's caps. A movement opportunity every 5 seconds, each on its own path through the building to the hallway or a vent.
* **The mask, the light and the box:** whoever waits in the hallway or a vent comes in while the monitor is up, and is in the office when it comes down: the mask at once, or they get you. Mangle stays on the ceiling, Balloon Boy takes your lights, Withered Foxy only leaves for the flashlight, and the Puppet comes for anyone who lets the music box run down.
* **What the game makes you hear, written down:** the vents banging, Balloon Boy's voice, Mangle's radio static, the music box's tune.
* **Saved like in the game:** the night you reached, your stars and your last Custom Night. Home keeps the night as it is, and the next start puts you back in it, paused. Your saves are also copied into `fnaf2_saves.py`, so installing the app again doesn't erase them.
-<p align="center">
- <img src="docs/shot.png" width="390" alt="The office">
-</p>
+<table>
+ <tr>
+ <td align="center"><img src="docs/shot.png" width="390" alt="Toy Freddy far down the hallway, in the flashlight"><br><sub>The flashlight down the hallway</sub></td>
+ <td align="center"><img src="docs/vent.png" width="390" alt="Toy Bonnie in the right vent's light"><br><sub>The right vent: Toy Bonnie</sub></td>
+ </tr>
+ <tr>
+ <td align="center"><img src="docs/stage.png" width="390" alt="The Show Stage on camera"><br><sub>The Show Stage, on the monitor</sub></td>
+ <td align="center"><img src="docs/musicbox.png" width="390" alt="Winding the music box on CAM 11"><br><sub>Winding the music box</sub></td>
+ </tr>
+ <tr>
+ <td align="center"><img src="docs/partyroom4.png" width="390" alt="Toy Bonnie staring into the dark camera of Party Room 4"><br><sub>Party Room 4, in the dark</sub></td>
+ <td align="center"><img src="docs/jumpscare.png" width="390" alt="Toy Bonnie's jumpscare"><br><sub>Too late</sub></td>
+ </tr>
+ <tr>
+ <td align="center"><img src="docs/title.png" width="390" alt="The title screen"><br><sub>The title screen</sub></td>
+ <td align="center"><img src="docs/custom.png" width="390" alt="The Custom Night"><br><sub>The Custom Night</sub></td>
+ </tr>
+</table>
## How to play
@@ -67,13 +82,13 @@ The vent keys turn you to that side first if you're looking the other way. On th
* **No calls:** each of the game's calls runs a minute or two. The night's card gives a short tip instead.
* **Left out:** the minigames after a death and between nights, Shadow Freddy, Shadow Bonnie, the Endo, JJ and the prizes the Custom Night puts on the desk. None of them are part of surviving a night.
* **A few numbers are the port's own,** where nobody has read them out of the game yet: the music box winds full in about 6 seconds, you get a second to put the mask on, a fooled visitor stays 4 seconds, Mangle in the office attacks 1 time in 3 the monitor comes down, and Withered Foxy leaves after 5 flashes.
-* **The pictures are the game's,** at 240 pixels high: the office turns a little further, as the screen is 4:3.
+* **The pictures are the game's,** at 240 pixels high: the office turns a little further, as the screen is 4:3. The mask is drawn, with its eyes where the game's are.
## Credits
Inspired by Five Nights at Freddy's 2 by Scott Cawthon, not affiliated with him.
-* The pictures come from the game, as VocalNutria9174's fan port [fnaf-2_html5](https://github.com/VocalNutria9174/fnaf-2_html5) keeps them. `tools/fetch.py` gets it, `tools/pack.py` makes them into `src/data.bin`.
+* The pictures come from the game's Clickteam HTML5 build, as VocalNutria9174's fan port [fnaf-2_html5](https://github.com/VocalNutria9174/fnaf-2_html5) keeps it: `tools/fetch.py` reads which picture each of the game's objects shows from its application file, and `tools/pack.py` makes them into `src/data.bin`. Party Room 4's two empty pictures, missing from that build, come from fredtheking's [FNaF2-RaylibCs](https://github.com/fredtheking/FNaF2-RaylibCs).
* How the animatronics move, their AI levels, the music box, the flashlight and Withered Foxy follow what the game's players read out of its events, as the [Technical FNaF Wiki](https://technicalfnaf.fandom.com) and the [Five Nights at Freddy's Wiki](https://freddy-fazbears-pizza.fandom.com) write them down.
* The words are drawn in the DejaVu fonts ([license](../../LICENSES/DejaVu.txt)), and the paychecks with them.
diff --git a/games/fnaf2/docs/custom.png b/games/fnaf2/docs/custom.png
new file mode 100644
index 00000000..b262d48d
Binary files /dev/null and b/games/fnaf2/docs/custom.png differ
diff --git a/games/fnaf2/docs/jumpscare.png b/games/fnaf2/docs/jumpscare.png
new file mode 100644
index 00000000..3a465083
Binary files /dev/null and b/games/fnaf2/docs/jumpscare.png differ
diff --git a/games/fnaf2/docs/musicbox.png b/games/fnaf2/docs/musicbox.png
new file mode 100644
index 00000000..f9af3cbd
Binary files /dev/null and b/games/fnaf2/docs/musicbox.png differ
diff --git a/games/fnaf2/docs/partyroom4.png b/games/fnaf2/docs/partyroom4.png
new file mode 100644
index 00000000..1a146149
Binary files /dev/null and b/games/fnaf2/docs/partyroom4.png differ
diff --git a/games/fnaf2/docs/shot.png b/games/fnaf2/docs/shot.png
index 82f9cfb1..d18577d6 100644
Binary files a/games/fnaf2/docs/shot.png and b/games/fnaf2/docs/shot.png differ
diff --git a/games/fnaf2/docs/stage.png b/games/fnaf2/docs/stage.png
new file mode 100644
index 00000000..deb9c0f8
Binary files /dev/null and b/games/fnaf2/docs/stage.png differ
diff --git a/games/fnaf2/docs/title.png b/games/fnaf2/docs/title.png
new file mode 100644
index 00000000..21dd5552
Binary files /dev/null and b/games/fnaf2/docs/title.png differ
diff --git a/games/fnaf2/docs/vent.png b/games/fnaf2/docs/vent.png
new file mode 100644
index 00000000..c76fbc05
Binary files /dev/null and b/games/fnaf2/docs/vent.png differ
diff --git a/games/fnaf2/src/data.bin b/games/fnaf2/src/data.bin
index c08d163e..f00e5b00 100644
Binary files a/games/fnaf2/src/data.bin and b/games/fnaf2/src/data.bin differ
diff --git a/games/fnaf2/src/data.h b/games/fnaf2/src/data.h
index e76bc91e..5e16ebf2 100644
--- a/games/fnaf2/src/data.h
+++ b/games/fnaf2/src/data.h
@@ -42,142 +42,267 @@
#define PIC_CAM01_MANGLE 29
#define PIC_CAM01_PUPPET 30
#define PIC_CAM02_DARK 31
-#define PIC_CAM02_LIT 32
-#define PIC_CAM02_TB 33
-#define PIC_CAM02_WC 34
-#define PIC_CAM02_MANGLE 35
-#define PIC_CAM02_PUPPET 36
-#define PIC_CAM03_DARK 37
-#define PIC_CAM03_LIT 38
-#define PIC_CAM03_TB 39
-#define PIC_CAM03_WF 40
-#define PIC_CAM03_PUPPET 41
-#define PIC_CAM04_DARK 42
-#define PIC_CAM04_LIT 43
-#define PIC_CAM04_TB 44
-#define PIC_CAM04_WC 45
-#define PIC_CAM04_PUPPET 46
-#define PIC_CAM05_DARK 47
-#define PIC_CAM05_LIT 48
-#define PIC_CAM05_TC 49
-#define PIC_CAM05_BB 50
-#define PIC_CAM05_WB 51
-#define PIC_CAM06_DARK 52
-#define PIC_CAM06_LIT 53
-#define PIC_CAM06_TB 54
-#define PIC_CAM06_WC 55
-#define PIC_CAM06_MANGLE 56
-#define PIC_CAM07_EMPTY 57
-#define PIC_CAM07_TC 58
-#define PIC_CAM07_MANGLE 59
-#define PIC_CAM07_WF 60
-#define PIC_CAM07_WB 61
-#define PIC_CAM07_PUPPET 62
-#define PIC_CAM08_S0 63
-#define PIC_CAM08_S1 64
-#define PIC_CAM08_S2 65
-#define PIC_CAM08_S3 66
-#define PIC_CAM08_S4 67
-#define PIC_CAM08_S5 68
-#define PIC_CAM08_S6 69
-#define PIC_CAM08_S7 70
-#define PIC_CAM08_FOXY 71
-#define PIC_CAM09_S0 72
-#define PIC_CAM09_S1 73
-#define PIC_CAM09_S2 74
-#define PIC_CAM09_S3 75
-#define PIC_CAM09_S4 76
-#define PIC_CAM09_S5 77
-#define PIC_CAM09_S6 78
-#define PIC_CAM09_S7 79
-#define PIC_CAM10_EMPTY 80
-#define PIC_CAM10_TF 81
-#define PIC_CAM10_BB 82
-#define PIC_CAM10_MANGLE 83
-#define PIC_CAM11_P0 84
-#define PIC_CAM11_P1 85
-#define PIC_CAM11_P2 86
-#define PIC_CAM11_P3 87
-#define PIC_CAM11_EMPTY 88
-#define PIC_CAM11_MANGLE 89
-#define PIC_CAM12_MANGLE 90
-#define PIC_CAM12_EMPTY 91
-#define PIC_SCARE_TF0 92
-#define PIC_SCARE_TF1 93
-#define PIC_SCARE_TF2 94
-#define PIC_SCARE_TB0 95
-#define PIC_SCARE_TB1 96
-#define PIC_SCARE_TB2 97
-#define PIC_SCARE_TC0 98
-#define PIC_SCARE_TC1 99
-#define PIC_SCARE_TC2 100
-#define PIC_SCARE_MANGLE0 101
-#define PIC_SCARE_MANGLE1 102
-#define PIC_SCARE_MANGLE2 103
-#define PIC_SCARE_WF0 104
-#define PIC_SCARE_WF1 105
-#define PIC_SCARE_WF2 106
-#define PIC_SCARE_WB0 107
-#define PIC_SCARE_WB1 108
-#define PIC_SCARE_WB2 109
-#define PIC_SCARE_WC0 110
-#define PIC_SCARE_WC1 111
-#define PIC_SCARE_WC2 112
-#define PIC_SCARE_FOXY0 113
-#define PIC_SCARE_FOXY1 114
-#define PIC_SCARE_FOXY2 115
-#define PIC_SCARE_GF0 116
-#define PIC_SCARE_GF1 117
-#define PIC_SCARE_GF2 118
-#define PIC_SCARE_PUPPET0 119
-#define PIC_SCARE_PUPPET1 120
-#define PIC_SCARE_PUPPET2 121
-#define PIC_TITLE 122
-#define PIC_NEWSPAPER 123
-#define PIC_PAYCHECK 124
-#define PIC_OVERTIME 125
-#define PIC_PINKSLIP 126
-#define PIC_GAMEOVER 127
-#define PIC_FACE0 128
-#define PIC_FACE1 129
-#define PIC_FACE2 130
-#define PIC_FACE3 131
-#define PIC_FACE4 132
-#define PIC_FACE5 133
-#define PIC_FACE6 134
-#define PIC_FACE7 135
-#define PIC_FACE8 136
-#define PIC_FACE9 137
-#define PIC_COUNT 138
+#define PIC_CAM02_DWC 32
+#define PIC_CAM02_LIT 33
+#define PIC_CAM02_TB 34
+#define PIC_CAM02_WC 35
+#define PIC_CAM02_MANGLE 36
+#define PIC_CAM02_PUPPET 37
+#define PIC_CAM03_DARK 38
+#define PIC_CAM03_DWF 39
+#define PIC_CAM03_LIT 40
+#define PIC_CAM03_TB 41
+#define PIC_CAM03_WF 42
+#define PIC_CAM03_PUPPET 43
+#define PIC_CAM04_DARK 44
+#define PIC_CAM04_DTB 45
+#define PIC_CAM04_LIT 46
+#define PIC_CAM04_TB 47
+#define PIC_CAM04_WC 48
+#define PIC_CAM04_PUPPET 49
+#define PIC_CAM05_DARK 50
+#define PIC_CAM05_LIT 51
+#define PIC_CAM05_TC 52
+#define PIC_CAM05_BB 53
+#define PIC_CAM05_WB 54
+#define PIC_CAM06_DARK 55
+#define PIC_CAM06_LIT 56
+#define PIC_CAM06_TB 57
+#define PIC_CAM06_WC 58
+#define PIC_CAM06_MANGLE 59
+#define PIC_CAM07_DARK 60
+#define PIC_CAM07_EMPTY 61
+#define PIC_CAM07_TC 62
+#define PIC_CAM07_MANGLE 63
+#define PIC_CAM07_WF 64
+#define PIC_CAM07_WB 65
+#define PIC_CAM07_PUPPET 66
+#define PIC_CAM08_DARK 67
+#define PIC_CAM08_S0 68
+#define PIC_CAM08_S1 69
+#define PIC_CAM08_S2 70
+#define PIC_CAM08_S3 71
+#define PIC_CAM08_S4 72
+#define PIC_CAM08_S5 73
+#define PIC_CAM08_S6 74
+#define PIC_CAM08_S7 75
+#define PIC_CAM08_FOXY 76
+#define PIC_CAM09_S0 77
+#define PIC_CAM09_S1 78
+#define PIC_CAM09_S2 79
+#define PIC_CAM09_S3 80
+#define PIC_CAM09_S4 81
+#define PIC_CAM09_S5 82
+#define PIC_CAM09_S6 83
+#define PIC_CAM09_S7 84
+#define PIC_CAM09_D0 85
+#define PIC_CAM09_D1 86
+#define PIC_CAM09_D2 87
+#define PIC_CAM09_D3 88
+#define PIC_CAM09_D4 89
+#define PIC_CAM09_D5 90
+#define PIC_CAM09_D6 91
+#define PIC_CAM09_D7 92
+#define PIC_CAM10_DARK 93
+#define PIC_CAM10_EMPTY 94
+#define PIC_CAM10_TF 95
+#define PIC_CAM10_BB 96
+#define PIC_CAM10_TFBB 97
+#define PIC_CAM10_MANGLE 98
+#define PIC_CAM11_DARK 99
+#define PIC_CAM11_P0 100
+#define PIC_CAM11_P1 101
+#define PIC_CAM11_P2 102
+#define PIC_CAM11_P3 103
+#define PIC_CAM11_EMPTY 104
+#define PIC_CAM11_MANGLE 105
+#define PIC_CAM12_DARK 106
+#define PIC_CAM12_MANGLE 107
+#define PIC_CAM12_EMPTY 108
+#define PIC_SCARE_TF0 109
+#define PIC_SCARE_TF1 110
+#define PIC_SCARE_TF2 111
+#define PIC_SCARE_TF3 112
+#define PIC_SCARE_TF4 113
+#define PIC_SCARE_TF5 114
+#define PIC_SCARE_TF6 115
+#define PIC_SCARE_TF7 116
+#define PIC_SCARE_TF8 117
+#define PIC_SCARE_TF9 118
+#define PIC_SCARE_TF10 119
+#define PIC_SCARE_TF11 120
+#define PIC_SCARE_TB0 121
+#define PIC_SCARE_TB1 122
+#define PIC_SCARE_TB2 123
+#define PIC_SCARE_TB3 124
+#define PIC_SCARE_TB4 125
+#define PIC_SCARE_TB5 126
+#define PIC_SCARE_TB6 127
+#define PIC_SCARE_TB7 128
+#define PIC_SCARE_TB8 129
+#define PIC_SCARE_TB9 130
+#define PIC_SCARE_TB10 131
+#define PIC_SCARE_TB11 132
+#define PIC_SCARE_TB12 133
+#define PIC_SCARE_TC0 134
+#define PIC_SCARE_TC1 135
+#define PIC_SCARE_TC2 136
+#define PIC_SCARE_TC3 137
+#define PIC_SCARE_TC4 138
+#define PIC_SCARE_TC5 139
+#define PIC_SCARE_TC6 140
+#define PIC_SCARE_TC7 141
+#define PIC_SCARE_TC8 142
+#define PIC_SCARE_TC9 143
+#define PIC_SCARE_TC10 144
+#define PIC_SCARE_TC11 145
+#define PIC_SCARE_TC12 146
+#define PIC_SCARE_MANGLE0 147
+#define PIC_SCARE_MANGLE1 148
+#define PIC_SCARE_MANGLE2 149
+#define PIC_SCARE_MANGLE3 150
+#define PIC_SCARE_MANGLE4 151
+#define PIC_SCARE_MANGLE5 152
+#define PIC_SCARE_MANGLE6 153
+#define PIC_SCARE_MANGLE7 154
+#define PIC_SCARE_MANGLE8 155
+#define PIC_SCARE_MANGLE9 156
+#define PIC_SCARE_MANGLE10 157
+#define PIC_SCARE_MANGLE11 158
+#define PIC_SCARE_MANGLE12 159
+#define PIC_SCARE_MANGLE13 160
+#define PIC_SCARE_MANGLE14 161
+#define PIC_SCARE_MANGLE15 162
+#define PIC_SCARE_WF0 163
+#define PIC_SCARE_WF1 164
+#define PIC_SCARE_WF2 165
+#define PIC_SCARE_WF3 166
+#define PIC_SCARE_WF4 167
+#define PIC_SCARE_WF5 168
+#define PIC_SCARE_WF6 169
+#define PIC_SCARE_WF7 170
+#define PIC_SCARE_WF8 171
+#define PIC_SCARE_WF9 172
+#define PIC_SCARE_WF10 173
+#define PIC_SCARE_WF11 174
+#define PIC_SCARE_WF12 175
+#define PIC_SCARE_WB0 176
+#define PIC_SCARE_WB1 177
+#define PIC_SCARE_WB2 178
+#define PIC_SCARE_WB3 179
+#define PIC_SCARE_WB4 180
+#define PIC_SCARE_WB5 181
+#define PIC_SCARE_WB6 182
+#define PIC_SCARE_WB7 183
+#define PIC_SCARE_WB8 184
+#define PIC_SCARE_WB9 185
+#define PIC_SCARE_WB10 186
+#define PIC_SCARE_WB11 187
+#define PIC_SCARE_WB12 188
+#define PIC_SCARE_WB13 189
+#define PIC_SCARE_WB14 190
+#define PIC_SCARE_WB15 191
+#define PIC_SCARE_WC0 192
+#define PIC_SCARE_WC1 193
+#define PIC_SCARE_WC2 194
+#define PIC_SCARE_WC3 195
+#define PIC_SCARE_WC4 196
+#define PIC_SCARE_WC5 197
+#define PIC_SCARE_WC6 198
+#define PIC_SCARE_WC7 199
+#define PIC_SCARE_WC8 200
+#define PIC_SCARE_WC9 201
+#define PIC_SCARE_WC10 202
+#define PIC_SCARE_WC11 203
+#define PIC_SCARE_FOXY0 204
+#define PIC_SCARE_FOXY1 205
+#define PIC_SCARE_FOXY2 206
+#define PIC_SCARE_FOXY3 207
+#define PIC_SCARE_FOXY4 208
+#define PIC_SCARE_FOXY5 209
+#define PIC_SCARE_FOXY6 210
+#define PIC_SCARE_FOXY7 211
+#define PIC_SCARE_FOXY8 212
+#define PIC_SCARE_FOXY9 213
+#define PIC_SCARE_FOXY10 214
+#define PIC_SCARE_FOXY11 215
+#define PIC_SCARE_FOXY12 216
+#define PIC_SCARE_FOXY13 217
+#define PIC_SCARE_GF0 218
+#define PIC_SCARE_GF1 219
+#define PIC_SCARE_GF2 220
+#define PIC_SCARE_GF3 221
+#define PIC_SCARE_GF4 222
+#define PIC_SCARE_GF5 223
+#define PIC_SCARE_GF6 224
+#define PIC_SCARE_GF7 225
+#define PIC_SCARE_GF8 226
+#define PIC_SCARE_GF9 227
+#define PIC_SCARE_GF10 228
+#define PIC_SCARE_GF11 229
+#define PIC_SCARE_GF12 230
+#define PIC_SCARE_PUPPET0 231
+#define PIC_SCARE_PUPPET1 232
+#define PIC_SCARE_PUPPET2 233
+#define PIC_SCARE_PUPPET3 234
+#define PIC_SCARE_PUPPET4 235
+#define PIC_SCARE_PUPPET5 236
+#define PIC_SCARE_PUPPET6 237
+#define PIC_SCARE_PUPPET7 238
+#define PIC_SCARE_PUPPET8 239
+#define PIC_SCARE_PUPPET9 240
+#define PIC_SCARE_PUPPET10 241
+#define PIC_SCARE_PUPPET11 242
+#define PIC_SCARE_PUPPET12 243
+#define PIC_SCARE_PUPPET13 244
+#define PIC_SCARE_PUPPET14 245
+#define PIC_TITLE 246
+#define PIC_NEWSPAPER 247
+#define PIC_PAYCHECK 248
+#define PIC_OVERTIME 249
+#define PIC_PINKSLIP 250
+#define PIC_GAMEOVER 251
+#define PIC_FACE0 252
+#define PIC_FACE1 253
+#define PIC_FACE2 254
+#define PIC_FACE3 255
+#define PIC_FACE4 256
+#define PIC_FACE5 257
+#define PIC_FACE6 258
+#define PIC_FACE7 259
+#define PIC_FACE8 260
+#define PIC_FACE9 261
+#define PIC_COUNT 262
#define FONT_HUD 0
#define FONT_BIG 1
#define FONT_TEXT 2
#define FONT_CLOCK 3
#define FONT_HUGE 4
-#define SCARE_TF_N 3
-#define SCARE_TB_N 3
-#define SCARE_TC_N 3
-#define SCARE_MANGLE_N 3
-#define SCARE_WF_N 3
-#define SCARE_WB_N 3
-#define SCARE_WC_N 3
-#define SCARE_FOXY_N 3
-#define SCARE_GF_N 3
-#define SCARE_PUPPET_N 3
+#define CAM_PAN 180
+#define SCARE_TF_N 12
+#define SCARE_TB_N 13
+#define SCARE_TC_N 13
+#define SCARE_MANGLE_N 16
+#define SCARE_WF_N 13
+#define SCARE_WB_N 16
+#define SCARE_WC_N 12
+#define SCARE_FOXY_N 14
+#define SCARE_GF_N 13
+#define SCARE_PUPPET_N 15
#define IMG_TITLE 0
#define IMG_STAR 1
#define HALL_X 176
-#define HALL_Y 32
-#define LVENT_X 0
-#define LVENT_Y 112
-#define RVENT_X 404
-#define RVENT_Y 112
-#define OCC_X 160
-#define OCC_Y 48
-#define MANGLE_X 192
+#define HALL_Y 64
+#define LVENT_X 16
+#define LVENT_Y 128
+#define RVENT_X 368
+#define RVENT_Y 128
+#define OCC_X 80
+#define OCC_Y 0
+#define MANGLE_X 208
#define MANGLE_Y 0
-#define BBO_X 16
-#define BBO_Y 96
-#define STAND_INS 1
+#define BBO_X 80
+#define BBO_Y 80
+#define STAND_INS 0
#endif
diff --git a/games/fnaf2/src/game.c b/games/fnaf2/src/game.c
index 75bd4bcc..159b8dfa 100644
--- a/games/fnaf2/src/game.c
+++ b/games/fnaf2/src/game.c
@@ -186,7 +186,17 @@ static void intro_draw(void) {
gfx_fill(0, gfx_y0, SCREEN_W, BAND_H, BLACK);
gfx_text_c(FONT_HUGE, 160, 84, "12:00 AM", WHITE);
gfx_text_c(FONT_BIG, 160, 116, nth[g.n.night], WHITE);
- gfx_text_c(FONT_TEXT, 160, 150, hint[g.n.night], RGB(0x9A9A9A));
+ /* (a word too wide for the screen: a line a sentence) */
+ const char *h = hint[g.n.night], *stop = strstr(h, ". ");
+ if (gfx_text_w(FONT_TEXT, h) <= 300 || !stop) {
+ gfx_text_c(FONT_TEXT, 160, 150, h, RGB(0x9A9A9A));
+ } else {
+ char first[64];
+ int n = (int)(stop - h) + 1;
+ memcpy(first, h, (size_t)n), first[n] = 0;
+ gfx_text_c(FONT_TEXT, 160, 146, first, RGB(0x9A9A9A));
+ gfx_text_c(FONT_TEXT, 160, 162, stop + 2, RGB(0x9A9A9A));
+ }
if (g.t < 0.15f) gfx_static(0, gfx_y0, SCREEN_W, BAND_H, 20, rnd());
if (g.t > 2.2f) gfx_dim(0, gfx_y0, SCREEN_W, BAND_H, (int)((3.2f - g.t) * 32));
}
diff --git a/games/fnaf2/src/icon.png b/games/fnaf2/src/icon.png
index 72a2f788..22b36efd 100644
Binary files a/games/fnaf2/src/icon.png and b/games/fnaf2/src/icon.png differ
diff --git a/games/fnaf2/src/night.c b/games/fnaf2/src/night.c
index e0babc71..e6ecd334 100644
--- a/games/fnaf2/src/night.c
+++ b/games/fnaf2/src/night.c
@@ -38,6 +38,10 @@ static const uint8_t PATH[WALKERS][10] = {
};
static const uint8_t PATH_LEN[WALKERS] = {4, 6, 6, 9, 4, 4, 5, 4};
static const uint8_t BACK_TO[WALKERS] = {0, 1, 1, 3, 0, 1, 1, 1};
+/* who leaves the Show Stage or Parts/Service only once the other has: Toy Bonnie, Toy Chica, then Toy Freddy;
+ Withered Bonnie, Chica, then Freddy */
+static const int8_t LEAVES_AFTER[WALKERS] = {[TF] = TC, [TB] = -1, [TC] = TB, [MANGLE] = -1, [BB] = -1,
+ [WF] = WC, [WB] = -1, [WC] = WB};
/* who comes in first when several are waiting */
static const uint8_t ENTRY_ORDER[WALKERS] = {WF, WB, WC, TF, TB, TC, MANGLE, BB};
@@ -206,6 +210,9 @@ static void walkers(void) {
if (a <= 0 || in_office(who) || roll() > a) continue;
/* the Withereds stay in Parts/Service while its camera is watched */
if (who >= WF && N.step[who] == 0 && monitor_up() && N.cam == L_PARTS) continue;
+ /* the Show Stage and Parts/Service empty in the game's order (the custom night, without their cameras, doesn't
+ keep it) */
+ if (N.night < 7 && N.step[who] == 0 && LEAVES_AFTER[who] >= 0 && N.step[LEAVES_AFTER[who]] == 0) continue;
if (N.stun[who]) N.pending[who] = 1;
else advance(who);
}
diff --git a/games/fnaf2/src/view.c b/games/fnaf2/src/view.c
index 460b29c9..28d686b3 100644
--- a/games/fnaf2/src/view.c
+++ b/games/fnaf2/src/view.c
@@ -140,17 +140,16 @@ static int visitor_picture(void) {
return N.occ < WALKERS ? pics[N.occ] : -1;
}
-/* the Freddy mask: dark but for its eyes, coming down from the top */
+/* the Freddy mask: black but for its eyes (where the game's are), coming up from the bottom */
static void mask_view(void) {
- int bottom = (int)(N.mask_anim * SCREEN_H);
- int y0 = gfx_y0, y1 = gfx_y0 + BAND_H < bottom ? gfx_y0 + BAND_H : bottom;
- int top = bottom - SCREEN_H; /* the mask's top row */
+ int top = SCREEN_H - (int)(N.mask_anim * SCREEN_H); /* the mask's top row */
+ int y0 = gfx_y0 > top ? gfx_y0 : top, y1 = gfx_y0 + BAND_H;
for (int y = y0; y < y1; y++) {
int my = y - top; /* in the mask */
/* the eyes: two ellipses */
int spans[2][2], n = 0;
for (int e = 0; e < 2; e++) {
- int cx = e ? 214 : 106, cy = 104, rx = 50, ry = 34, dy = my - cy;
+ int cx = e ? 215 : 107, cy = 112, rx = 41, ry = 32, dy = my - cy;
if (dy * dy >= ry * ry) continue;
int w = (int)(rx * __builtin_sqrtf(1.0f - (float)(dy * dy) / (float)(ry * ry)));
spans[n][0] = cx - w, spans[n][1] = cx + w, n++;
@@ -159,11 +158,11 @@ static void mask_view(void) {
for (int k = 0; k <= n; k++) {
int end = k < n ? spans[k][0] : SCREEN_W;
if (end > x) {
- gfx_dim(x, y, end - x, 1, 3);
- gfx_blend(x, y, end - x, 1, RGB(0x2A1608), 10);
+ gfx_dim(x, y, end - x, 1, 1);
+ gfx_blend(x, y, end - x, 1, RGB(0x120808), 6);
}
if (k < n) {
- gfx_dim(spans[k][0], y, spans[k][1] - spans[k][0], 1, 22);
+ gfx_dim(spans[k][0], y, spans[k][1] - spans[k][0], 1, 26);
x = spans[k][1];
}
}
@@ -198,7 +197,8 @@ static const char *const cam_names[CAM_COUNT] = {
static bool at(int who, int loc) { return bot_at(who) == loc; }
static bool puppet_at(int loc) { return N.puppet >= 4 && N.puppet_at == loc; }
-/* the feed: the dark rooms (the party rooms, the vents) show nothing but in the light */
+/* the feed: each room as the game's pictures show it, in the camera's light or not (a few show who stands close
+ in the dark) */
static int cam_picture(bool lit) {
switch (N.cam) {
case L_PR1:
@@ -206,15 +206,15 @@ static int cam_picture(bool lit) {
return puppet_at(L_PR1) ? PIC_CAM01_PUPPET : at(WB, L_PR1) ? PIC_CAM01_WB : at(TC, L_PR1) ? PIC_CAM01_TC
: at(MANGLE, L_PR1) ? PIC_CAM01_MANGLE : PIC_CAM01_LIT;
case L_PR2:
- if (!lit) return PIC_CAM02_DARK;
+ if (!lit) return at(WC, L_PR2) ? PIC_CAM02_DWC : PIC_CAM02_DARK;
return puppet_at(L_PR2) ? PIC_CAM02_PUPPET : at(WC, L_PR2) ? PIC_CAM02_WC : at(TB, L_PR2) ? PIC_CAM02_TB
: at(MANGLE, L_PR2) ? PIC_CAM02_MANGLE : PIC_CAM02_LIT;
case L_PR3:
- if (!lit) return PIC_CAM03_DARK;
+ if (!lit) return at(WF, L_PR3) ? PIC_CAM03_DWF : PIC_CAM03_DARK;
return puppet_at(L_PR3) ? PIC_CAM03_PUPPET : at(WF, L_PR3) ? PIC_CAM03_WF : at(TB, L_PR3) ? PIC_CAM03_TB
: PIC_CAM03_LIT;
case L_PR4:
- if (!lit) return PIC_CAM04_DARK;
+ if (!lit) return at(TB, L_PR4) ? PIC_CAM04_DTB : PIC_CAM04_DARK;
return puppet_at(L_PR4) ? PIC_CAM04_PUPPET : at(WC, L_PR4) ? PIC_CAM04_WC : at(TB, L_PR4) ? PIC_CAM04_TB
: PIC_CAM04_LIT;
case L_LVENT:
@@ -226,21 +226,27 @@ static int cam_picture(bool lit) {
return at(WC, L_RVENT) ? PIC_CAM06_WC : at(TB, L_RVENT) ? PIC_CAM06_TB : at(MANGLE, L_RVENT) ? PIC_CAM06_MANGLE
: PIC_CAM06_LIT;
case L_MAIN:
+ if (!lit) return PIC_CAM07_DARK;
return puppet_at(L_MAIN) ? PIC_CAM07_PUPPET : at(WF, L_MAIN) ? PIC_CAM07_WF : at(WB, L_MAIN) ? PIC_CAM07_WB
: at(TC, L_MAIN) ? PIC_CAM07_TC : at(MANGLE, L_MAIN) ? PIC_CAM07_MANGLE : PIC_CAM07_EMPTY;
case L_PARTS: {
+ if (!lit) return PIC_CAM08_DARK;
int m = at(WF, L_PARTS) | at(WB, L_PARTS) << 1 | at(WC, L_PARTS) << 2;
if (!m && N.ai[FOXY] >= 0 && !N.foxy_hall) return PIC_CAM08_FOXY;
return PIC_CAM08_S0 + m;
}
- case L_STAGE: return PIC_CAM09_S0 + (at(TF, L_STAGE) | at(TB, L_STAGE) << 1 | at(TC, L_STAGE) << 2);
+ case L_STAGE:
+ return (lit ? PIC_CAM09_S0 : PIC_CAM09_D0) + (at(TF, L_STAGE) | at(TB, L_STAGE) << 1 | at(TC, L_STAGE) << 2);
case L_GAME:
+ if (!lit) return PIC_CAM10_DARK;
+ if (at(TF, L_GAME) && at(BB, L_GAME)) return PIC_CAM10_TFBB;
return at(TF, L_GAME) ? PIC_CAM10_TF : at(BB, L_GAME) ? PIC_CAM10_BB : at(MANGLE, L_GAME) ? PIC_CAM10_MANGLE
: PIC_CAM10_EMPTY;
case L_PRIZE:
+ if (!lit) return PIC_CAM11_DARK;
if (N.puppet < 4) return N.puppet == 0 && at(MANGLE, L_PRIZE) ? PIC_CAM11_MANGLE : PIC_CAM11_P0 + N.puppet;
return at(MANGLE, L_PRIZE) ? PIC_CAM11_MANGLE : PIC_CAM11_EMPTY;
- default: return at(MANGLE, L_KIDS) ? PIC_CAM12_MANGLE : PIC_CAM12_EMPTY;
+ default: return !lit ? PIC_CAM12_DARK : at(MANGLE, L_KIDS) ? PIC_CAM12_MANGLE : PIC_CAM12_EMPTY;
}
}
@@ -293,13 +299,21 @@ static void music_box(void) {
static void cameras(void) {
bool lit = N.cam_light;
- if (N.glitch > 0) {
+ /* (the custom night has no CAM 08 and CAM 09, as in the game) */
+ if (N.glitch > 0 || (N.night == 7 && (N.cam == L_PARTS || N.cam == L_STAGE))) {
gfx_fill(0, gfx_y0, SCREEN_W, BAND_H, BLACK);
gfx_static(0, gfx_y0, SCREEN_W, BAND_H, 18, f.seed);
} else {
- pic_draw(cam_picture(lit), 0, 0);
- bool dark_room = N.cam <= L_RVENT;
- if (lit && !dark_room) gfx_dim(0, gfx_y0, SCREEN_W, BAND_H, 46);
+ /* (CAM 07 to 12 are wider than the screen: the camera pans, 5 seconds across, 2 still, 5 back, 2 still) */
+ static float since;
+ static int was = -1;
+ if (N.cam != was || g.t < since) was = N.cam, since = g.t; /* (a new camera, or the clock started again) */
+ float c = g.t - since;
+ while (c >= 14) c -= 14;
+ float a = c < 5 ? c / 5 : c < 7 ? 1 : c < 12 ? 1 - (c - 7) / 5 : 0;
+ int pan = (int)(a * CAM_PAN);
+ if (N.cam >= L_MAIN) pic_part(cam_picture(lit), 0, 0, pan < 0 ? 0 : pan > CAM_PAN ? CAM_PAN : pan, 0, SCREEN_W, SCREEN_H);
+ else pic_draw(cam_picture(lit), 0, 0);
gfx_static(0, gfx_y0, SCREEN_W, BAND_H, f.noise + (N.cam == N.puppet_at && N.puppet >= 4 ? 8 : 0), f.seed);
}
if (g.blip > 0) gfx_blend(0, gfx_y0, SCREEN_W, BAND_H, WHITE, (int)(g.blip * 120));
diff --git a/games/fnaf2/tests/rules.c b/games/fnaf2/tests/rules.c
index 2d327f9e..c0a03303 100644
--- a/games/fnaf2/tests/rules.c
+++ b/games/fnaf2/tests/rules.c
@@ -236,12 +236,27 @@ static void paths(void) {
for (unsigned i = 0; i < sizeof first / sizeof first[0]; i++) {
begin(3);
quiet();
+ /* (the ones that leave the Show Stage or Parts/Service before them are gone) */
+ g.n.step[TB] = 1;
+ if (first[i].who != WB) g.n.step[WB] = 1;
+ if (first[i].who == TF) g.n.step[TC] = 1;
+ if (first[i].who == WF) g.n.step[WC] = 1;
g.n.ai[first[i].who] = 20;
for (int k = 0; k < 3; k++) {
int now = next_place(first[i].who);
CHECK(now == first[i].at[k], "%s's move %d: %d", BOT_NAMES[first[i].who], k + 1, now);
}
}
+ /* the Show Stage and Parts/Service empty in the game's order: Toy Chica not before Toy Bonnie, Withered Freddy not
+ before Withered Chica, whatever their levels; on the custom night they leave as they like */
+ for (int custom = 0; custom < 2; custom++) {
+ begin(custom ? 7 : 3);
+ quiet();
+ g.n.ai[TC] = g.n.ai[WF] = 20;
+ steps(60 * 60, 0);
+ CHECK((bot_at(TC) == L_STAGE && bot_at(WF) == L_PARTS) == !custom,
+ "night %d: Toy Chica at %d, Withered Freddy at %d", custom ? 7 : 3, bot_at(TC), bot_at(WF));
+ }
/* a move a 5 s opportunity, no sooner */
begin(3);
quiet();
diff --git a/games/fnaf2/tools/fetch.py b/games/fnaf2/tools/fetch.py
index c63e7adf..f0600e8e 100644
--- a/games/fnaf2/tools/fetch.py
+++ b/games/fnaf2/tools/fetch.py
@@ -1,52 +1,234 @@
#!/usr/bin/env python3
-"""Five Nights at Freddy's 2: gathers the public material tools/pack.py turns into src/data.bin.
+"""Five Nights at Freddy's 2: gathers the game's pictures tools/pack.py turns into src/data.bin.
- python3 tools/fetch.py REF (then fill in REF/map.txt, then: make data REF=REF)
+ python3 -I tools/fetch.py REF (then: make data REF=REF; Python + Pillow)
-The game's own pictures, as a fan web port keeps them in its repository, at the commit used:
-VocalNutria9174's fnaf-2_html5 (github.com/VocalNutria9174/fnaf-2_html5), the game's Clickteam HTML5 build,
-whose pictures are numbered files in resources/. It is cloned with git into REF/html5.
+The pictures are the game's own, from its Clickteam HTML5 build as a fan web port keeps it in its repository, at the
+commit used: VocalNutria9174's fnaf-2_html5 (github.com/VocalNutria9174/fnaf-2_html5), cloned with git into
+REF/html5. Its resources/*.cc1 holds the game's application (a zip of Application.ccj, Clickteam's chunks): the
+objects by name with their animations' pictures, the size of each picture and the mosaics the small ones are packed
+in (resources/M0001.png...); the others are resources/0001.png... by their number. Five pictures aren't in that build;
+two of them, Party Room 4 dark and lit, come from fredtheking's FNaF2-RaylibCs (github.com/fredtheking/FNaF2-RaylibCs),
+which keeps the game's pictures by camera.
-Then REF/map.txt is written (if it isn't there): a line for each picture pack.py needs, "NAME ?" and what it
-shows. Put the file each comes from in place of the "?" (from REF, html5/resources/0018.png say); a jumpscare
-gets a line for each of its frames, in order."""
+Every picture pack.py needs is written to REF/pics, as the game draws it (a visitor in the office over the office, a
+jumpscare over the office as the screen shows it), and REF/map.txt names them. Below, PICS says where each one comes
+from: an animation of the object that shows the office and the cameras ("Active 16", the game's own name), another
+object's picture, or a picture by its number."""
+import io
import os
+import struct
import subprocess
import sys
+import urllib.request
+import zipfile
-SOURCES = [
- ("html5", "https://github.com/VocalNutria9174/fnaf-2_html5", "9dce599551feb34bd5c2aca199b7a9dfde70f866"),
-]
-EXTRA = [("TITLE_TEXT", "the title's words, white on transparent"), ("STAR", "the title's star"),
- ("ICON", "a face for the app's icon (it is cut square)")]
+from PIL import Image
+
+HTML5 = ("https://github.com/VocalNutria9174/fnaf-2_html5", "9dce599551feb34bd5c2aca199b7a9dfde70f866")
+RAYLIB = ("https://raw.githubusercontent.com/fredtheking/FNaF2-RaylibCs/c67435924336ddb46c0ec00c9cce6b6281877625/"
+ "FNaF2-RaylibCs/Resources/Game/Main/Camera/")
+CC1 = "resources/Five Nights At Freddy's 2 Web Edition.cc1"
+
+VIEW = 109 # "Active 16": the office and the cameras, a picture an animation
+SCARES = 113 # "attack animation": the jumpscares, an animation each
+OFFICE = 92 # the office, its lights out
+
+# the office's states: an animation of VIEW (the whole office as the game shows it then)
+OFFICE_ANIMS = {
+ "HALL_LIT": 36, "HALL_TFFAR": 55, "HALL_TF": 56, "HALL_TC": 50, "HALL_MANGLE": 84, "HALL_WF": 73,
+ "HALL_WB": 58, "HALL_FOXY": 76, "HALL_GF": 93,
+ "LVENT_LIT": 37, "LVENT_TC": 53, "LVENT_BB": 82, "RVENT_LIT": 38, "RVENT_TB": 47, "RVENT_MANGLE": 83,
+ "OCC_WF": 74, "OCC_WB": 61, "OCC_WC": 69,
+}
+# the visitors the game draws over the office: their picture and where it goes (the top left, in the office's
+# 1600 x 768; from the objects' places and hot spots in the game's frame: "freddy under table", "Active 21",
+# "Active 20"; Toy Bonnie, Toy Chica and Golden Freddy are put in the middle, their hot spots at the screen's)
+OVER_OFFICE = {
+ "OCC_TF": (512, 814, 2), "OCC_TB": (187, 534, 0), "OCC_TC": (186, 393, 0), "OCC_GF": (520, 548, 268),
+ "OFFICE_MANGLE": (121, 700, 0), "OFFICE_BB": (221, 259, 256),
+}
+# the cameras' states: an animation of VIEW, or ("raylib", file). A state with no picture of its own in the game
+# shows the room as it is without them (Mangle on the ceiling, where the camera doesn't see her; the Puppet, who
+# never leaves the Prize Corner but for the office), and the Show Stage's and Parts/Service's states the game never
+# reaches (they empty in order) show the nearest one.
+CAM_ANIMS = {
+ "01": {"DARK": 27, "LIT": 28, "TC": 51, "WB": 59, "MANGLE": 28, "PUPPET": 28},
+ "02": {"DARK": 33, "DWC": 65, "LIT": 34, "TB": 44, "WC": 66, "MANGLE": 34, "PUPPET": 34},
+ "03": {"DARK": 29, "DWF": 71, "LIT": 30, "TB": 43, "WF": 72, "PUPPET": 30},
+ "04": {"DARK": ("raylib", "14.png"), "DTB": 90, "LIT": ("raylib", "16.png"), "TB": 91, "WC": 67,
+ "PUPPET": ("raylib", "16.png")},
+ "05": {"DARK": 13, "LIT": 14, "TC": 52, "BB": 100, "WB": 60},
+ "06": {"DARK": 15, "LIT": 16, "TB": 45, "WC": 68, "MANGLE": 81},
+ "07": {"DARK": 21, "EMPTY": 22, "TC": 49, "MANGLE": 22, "WF": 70, "WB": 57, "PUPPET": 22},
+ # Parts/Service: S + Withered Freddy 1, Bonnie 2, Chica 4 there
+ "08": {"DARK": 23, "S0": 64, "S1": 63, "S2": 24, "S3": 24, "S4": 62, "S5": 62, "S6": 24, "S7": 24, "FOXY": 75},
+ # the Show Stage: S lit, D dark, + Toy Freddy 1, Bonnie 2, Chica 4 there
+ "09": {"S0": 89, "S1": 42, "S2": 12, "S3": 12, "S4": 40, "S5": 40, "S6": 12, "S7": 12,
+ "D0": 89, "D1": 41, "D2": 46, "D3": 46, "D4": 39, "D5": 39, "D6": 46, "D7": 46},
+ "10": {"DARK": 85, "EMPTY": 87, "TF": 86, "BB": 18, "TFBB": 54, "MANGLE": 87},
+ # the Prize Corner: the Puppet in its box, peeking, out of it, gone
+ "11": {"DARK": 25, "P0": 26, "P1": 77, "P2": 78, "P3": 79, "EMPTY": 79, "MANGLE": 95},
+ "12": {"DARK": 19, "MANGLE": 20, "EMPTY": 80},
+}
+SCARE_ANIMS = {"WF": 12, "WB": 13, "WC": 14, "FOXY": 15, "TB": 16, "TC": 17, "TF": 18, "MANGLE": 19, "PUPPET": 20,
+ "GF": 21}
+# pictures by number: the title's (the "Active 2" faces, the words, the star), the help wanted ad, the game over, the
+# three endings, the custom night's faces (its "... icon" objects) and the app's icon (Toy Freddy's)
+PICTURES = {
+ "TITLE": 321, "TITLE_TEXT": 469, "STAR": 593, "NEWSPAPER": 272, "GAMEOVER": 226, "PAYCHECK": 587,
+ "OVERTIME": 590, "PINKSLIP": 622, "ICON": 352,
+ "FACE0": 551, "FACE1": 339, "FACE2": 338, "FACE3": 341, "FACE4": 344, "FACE5": 352, "FACE6": 346, "FACE7": 576,
+ "FACE8": 577, "FACE9": 578,
+}
+
+
+class Game:
+ """the game's application (Application.ccj) and its pictures"""
+
+ def __init__(self, root):
+ self.root = os.path.join(root, "resources")
+ d = zipfile.ZipFile(os.path.join(root, CC1)).read("Application.ccj")
+ assert d[:4] == b"PAMU", "not a Clickteam application"
+ self.chunks, p = {}, 16
+ while p + 8 <= len(d):
+ cid, _, size = struct.unpack_from("<HHI", d, p)
+ self.chunks.setdefault(cid, []).append(d[p + 8:p + 8 + size])
+ p += 8 + size
+ if cid == 0x7F7F:
+ break
+ # the objects: their animations' pictures (an Active's ObjectCommon, its animations at offset 12)
+ self.anims, self.names = {}, {}
+ b = self.chunks[0x2229][0]
+ q = 4
+ for _ in range(struct.unpack_from("<I", b, 0)[0]):
+ head = name = props = None
+ while True:
+ sid, _, size = struct.unpack_from("<HHI", b, q)
+ body = b[q + 8:q + 8 + size]
+ q += 8 + size
+ if sid == 0x4444:
+ head = struct.unpack_from("<Hh", body, 0)
+ elif sid == 0x4445:
+ name = body.decode("utf-16-le").split("\0")[0]
+ elif sid == 0x4446:
+ props = body
+ elif sid == 0x7F7F:
+ break
+ handle, kind = head
+ self.names[handle] = name
+ if kind == 2 and props:
+ self.anims[handle] = self._animations(props)
+ # the pictures' sizes, and where the small ones are in the mosaics (each frame's table)
+ b = self.chunks[0x6666][0]
+ self.size = {}
+ for i in range(struct.unpack_from("<H", b, 2)[0]):
+ h, w, hh = struct.unpack_from("<3H", b, 4 + 14 * i)
+ self.size[h] = (w, hh)
+ self.mosaic = {}
+ for frame in self.chunks[0x3333]:
+ q = 0
+ while q + 8 <= len(frame):
+ sid, _, size = struct.unpack_from("<HHI", frame, q)
+ if sid == 0x3348:
+ for h in range(size // 6):
+ m, x, y = struct.unpack_from("<3H", frame, q + 8 + 6 * h)
+ if m:
+ self.mosaic.setdefault(h, (m, x, y))
+ q += 8 + size
+ if sid == 0x7F7F:
+ break
+ self.sheets = {}
+
+ @staticmethod
+ def _animations(p):
+ at = struct.unpack_from("<H", p, 12)[0]
+ count = struct.unpack_from("<H", p, at + 2)[0]
+ out = {}
+ for a, off in enumerate(struct.unpack_from(f"<{count}H", p, at + 4)):
+ if not off:
+ continue
+ dirs = struct.unpack_from("<32H", p, at + off)
+ if dirs[0]:
+ q = at + off + dirs[0]
+ n = struct.unpack_from("<H", p, q + 6)[0]
+ out[a] = list(struct.unpack_from(f"<{n}H", p, q + 8))
+ return out
+
+ def picture(self, h):
+ f = os.path.join(self.root, f"{h:04d}.png")
+ if os.path.exists(f):
+ return Image.open(f).convert("RGBA")
+ if h not in self.mosaic:
+ raise SystemExit(f"fetch: picture {h} isn't in the build")
+ m, x, y = self.mosaic[h]
+ if m not in self.sheets:
+ self.sheets[m] = Image.open(os.path.join(self.root, f"M{m:04d}.png")).convert("RGBA")
+ w, hh = self.size[h]
+ return self.sheets[m].crop((x, y, x + w, y + hh))
+
+ def frames(self, obj, anim):
+ return self.anims[obj][anim]
+
+
+def raylib(ref, name):
+ path = os.path.join(ref, "raylib", name)
+ if not os.path.exists(path):
+ os.makedirs(os.path.dirname(path), exist_ok=True)
+ with urllib.request.urlopen(RAYLIB + name) as r:
+ open(path, "wb").write(r.read())
+ return Image.open(path).convert("RGBA")
def main():
if len(sys.argv) != 2:
raise SystemExit(__doc__)
ref = sys.argv[1]
- os.makedirs(ref, exist_ok=True)
- for name, url, commit in SOURCES:
- d = os.path.join(ref, name)
- if not os.path.isdir(os.path.join(d, ".git")):
- subprocess.run(["git", "clone", "--quiet", url, d], check=True)
- subprocess.run(["git", "-C", d, "checkout", "--quiet", commit], check=True)
- print(f"{name}: {commit[:10]}")
- path = os.path.join(ref, "map.txt")
- if os.path.exists(path):
- return
- sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
- from pack import PICTURES # noqa: E402 (the list of pictures, nothing else of it runs)
- with open(path, "w") as f:
- f.write("# NAME file (from this folder). A jumpscare: a line a frame, in order.\n")
- for name, kind, what in PICTURES:
- if kind == "face" or not kind.startswith("patch"):
- f.write(f"{name} ? # {what}\n")
- else:
- f.write(f"{name} ? # {what} (the whole office: pack.py cuts the part)\n")
- for name, what in EXTRA:
- f.write(f"{name} ? # {what}\n")
- print(f"wrote {path}: fill it in, then make data REF={ref}")
+ os.makedirs(os.path.join(ref, "pics"), exist_ok=True)
+ d = os.path.join(ref, "html5")
+ if not os.path.isdir(os.path.join(d, ".git")):
+ subprocess.run(["git", "clone", "--quiet", HTML5[0], d], check=True)
+ subprocess.run(["git", "-C", d, "checkout", "--quiet", HTML5[1]], check=True)
+ game = Game(d)
+ assert game.names[VIEW] == "Active 16" and game.names[SCARES] == "attack animation", "not the build expected"
+ lines = []
+
+ def save(name, im, k=None):
+ rel = f"pics/{name}.png" if k is None else f"pics/{name}_{k:02d}.png"
+ im.convert("RGB").save(os.path.join(ref, rel))
+ lines.append(f"{name} {rel}")
+
+ def view(anim):
+ return game.picture(game.frames(VIEW, anim)[0])
+
+ office = game.picture(OFFICE)
+ save("OFFICE", office)
+ for name, anim in OFFICE_ANIMS.items():
+ save(name, view(anim))
+ for name, (h, x, y) in OVER_OFFICE.items():
+ im = office.copy()
+ im.alpha_composite(game.picture(h), (x, y))
+ save(name, im)
+ for num, states in CAM_ANIMS.items():
+ for state, src in states.items():
+ save(f"CAM{num}_{state}", raylib(ref, src[1]) if isinstance(src, tuple) else view(src))
+ middle = office.crop((288, 0, 288 + 1024, 768)) # (the office as the screen shows it, looking ahead)
+ for who, anim in SCARE_ANIMS.items():
+ for k, h in enumerate(game.frames(SCARES, anim)):
+ im = middle.copy()
+ im.alpha_composite(game.picture(h))
+ save(f"SCARE_{who}", im, k)
+ for name, h in PICTURES.items():
+ im = game.picture(h)
+ if name in ("TITLE_TEXT", "STAR"): # (white or yellow on see-through, as they are)
+ rel = f"pics/{name}.png"
+ im.save(os.path.join(ref, rel))
+ lines.append(f"{name} {rel}")
+ else:
+ save(name, im)
+ with open(os.path.join(ref, "map.txt"), "w") as f:
+ f.write("# the game's pictures, as tools/fetch.py made them\n" + "\n".join(lines) + "\n")
+ print(f"{len(lines)} pictures in {ref}/pics, {ref}/map.txt written: make data REF={ref}")
if __name__ == "__main__":
diff --git a/games/fnaf2/tools/pack.py b/games/fnaf2/tools/pack.py
index bfbfaeb0..56ee614d 100644
--- a/games/fnaf2/tools/pack.py
+++ b/games/fnaf2/tools/pack.py
@@ -27,7 +27,7 @@ data.bin: "FNF2", the number of sections, their offsets, then the sections (SEC_
- MAP: the camera map: its width and height (u16), its walls (1 bit a pixel), where the 12 buttons are
The office is the game's 1600 x 768 at 240 high (500 x 240): the calculator shows 320 of it and turns. The
-cameras are its 1024 x 768 at 320 x 240."""
+cameras are its 1024 x 768 at 320 x 240, but CAM 07 to 12, 1600 x 768 as the office, which the camera pans across."""
import os
import struct
import sys
@@ -51,13 +51,14 @@ FONT_DIRS = [os.environ.get("FONTS", ""), "/usr/share/fonts/truetype/dejavu", "/
OW, OH = 500, 240 # the office on the calculator
CW, CH = 320, 240 # a camera
# the parts of the office that change, drawn over it (x, y, w, h in the 500 x 240 office)
+# (where the game's own pictures change: the hallway's light reaches the floor, Toy Freddy stands right of the desk)
PATCHES = {
- "HALL": (176, 32, 144, 128), # the hallway, in the flashlight
- "LVENT": (0, 112, 96, 80), # the left vent's blind spot, in its light
- "RVENT": (404, 112, 96, 80), # the right one
- "OCC": (160, 48, 176, 192), # whoever stands in front of the desk
- "MANGLE": (192, 0, 128, 64), # Mangle on the ceiling
- "BBO": (16, 96, 144, 144), # Balloon Boy in the office
+ "HALL": (176, 64, 128, 176), # the hallway, in the flashlight
+ "LVENT": (16, 128, 128, 112), # the left vent's blind spot, in its light
+ "RVENT": (368, 128, 128, 112), # the right one
+ "OCC": (80, 0, 336, 240), # whoever stands in front of the desk
+ "MANGLE": (208, 0, 176, 64), # Mangle on the ceiling
+ "BBO": (80, 80, 128, 144), # Balloon Boy in the office
}
WHO = {"TF": "Toy Freddy", "TB": "Toy Bonnie", "TC": "Toy Chica", "MANGLE": "Mangle", "BB": "Balloon Boy",
"WF": "Withered Freddy", "WB": "Withered Bonnie", "WC": "Withered Chica", "FOXY": "Withered Foxy",
@@ -83,19 +84,21 @@ PICTURES += [(f"OCC_{s}", "patch OCC", f"{WHO[s]} in the office, in front of the
for s in ("TF", "TB", "TC", "WF", "WB", "WC", "GF")]
PICTURES += [("OFFICE_MANGLE", "patch MANGLE", "Mangle on the office's ceiling"),
("OFFICE_BB", "patch BBO", "Balloon Boy standing in the office")]
+# Each camera's states, as its picture shows them; the states starting with D are with the camera's light off (a
+# few of the dark rooms show who stands close: DWC is Withered Chica in the dark, D0 to D7 the Show Stage's).
CAMS = [
("01", "Party Room 1", ["DARK", "LIT", "TC", "WB", "MANGLE", "PUPPET"]),
- ("02", "Party Room 2", ["DARK", "LIT", "TB", "WC", "MANGLE", "PUPPET"]),
- ("03", "Party Room 3", ["DARK", "LIT", "TB", "WF", "PUPPET"]),
- ("04", "Party Room 4", ["DARK", "LIT", "TB", "WC", "PUPPET"]),
+ ("02", "Party Room 2", ["DARK", "DWC", "LIT", "TB", "WC", "MANGLE", "PUPPET"]),
+ ("03", "Party Room 3", ["DARK", "DWF", "LIT", "TB", "WF", "PUPPET"]),
+ ("04", "Party Room 4", ["DARK", "DTB", "LIT", "TB", "WC", "PUPPET"]),
("05", "Left Air Vent", ["DARK", "LIT", "TC", "BB", "WB"]),
("06", "Right Air Vent", ["DARK", "LIT", "TB", "WC", "MANGLE"]),
- ("07", "Main Hall", ["EMPTY", "TC", "MANGLE", "WF", "WB", "PUPPET"]),
- ("08", "Parts/Service", [f"S{m}" for m in range(8)] + ["FOXY"]),
- ("09", "Show Stage", [f"S{m}" for m in range(8)]),
- ("10", "Game Area", ["EMPTY", "TF", "BB", "MANGLE"]),
- ("11", "Prize Corner", ["P0", "P1", "P2", "P3", "EMPTY", "MANGLE"]),
- ("12", "Kid's Cove", ["MANGLE", "EMPTY"]),
+ ("07", "Main Hall", ["DARK", "EMPTY", "TC", "MANGLE", "WF", "WB", "PUPPET"]),
+ ("08", "Parts/Service", ["DARK"] + [f"S{m}" for m in range(8)] + ["FOXY"]),
+ ("09", "Show Stage", [f"S{m}" for m in range(8)] + [f"D{m}" for m in range(8)]),
+ ("10", "Game Area", ["DARK", "EMPTY", "TF", "BB", "TFBB", "MANGLE"]),
+ ("11", "Prize Corner", ["DARK", "P0", "P1", "P2", "P3", "EMPTY", "MANGLE"]),
+ ("12", "Kid's Cove", ["DARK", "MANGLE", "EMPTY"]),
]
for num, room, states in CAMS:
for s in states:
@@ -416,15 +419,31 @@ def stand_in_room(num, room, lit, who=(), extra=None):
return grain(arr(im), 5)
+WIDE = ("07", "08", "09", "10", "11", "12") # (the cameras 1600 wide, which pan)
+
+
+def widen(num, a):
+ """a stand-in camera as wide as its camera's picture"""
+ return np.pad(a, ((0, 0), ((OW - CW) // 2, OW - CW - (OW - CW) // 2), (0, 0)), mode="edge") if num in WIDE else a
+
+
def stand_in_cams():
+ define("CAM_PAN", OW - CW)
for num, room, states in CAMS:
base = None
for s in states:
name = f"CAM{num}_{s}"
if s == "DARK":
- pic(name, stand_in_room(num, room, False))
+ pic(name, widen(num, stand_in_room(num, room, False)))
+ continue
+ if s in ("DWC", "DWF", "DTB") or (num == "09" and s.startswith("D")):
+ m = int(s[1:]) if num == "09" else 0
+ who = [["TF", "TB", "TC"][k] for k in range(3) if m >> k & 1] if num == "09" else [s[1:]]
+ pic(name, widen(num, stand_in_room(num, room, False, who)))
continue
- if num in ("08", "09") and s.startswith("S"):
+ if s == "TFBB":
+ who = ["TF", "BB"]
+ elif num in ("08", "09") and s.startswith("S"):
m = int(s[1:])
trio = ["WF", "WB", "WC"] if num == "08" else ["TF", "TB", "TC"]
who = [trio[k] for k in range(3) if m >> k & 1]
@@ -439,7 +458,7 @@ def stand_in_cams():
extra = ["in the box", "partly out", "mostly out", "out of the box"][int(s[1:])]
if num == "11" and s == "MANGLE":
extra = "the music box shut"
- a = stand_in_room(num, room, True, who, extra)
+ a = widen(num, stand_in_room(num, room, True, who, extra))
p = pic(name, a, base=base)
base = base or p
@@ -629,6 +648,7 @@ def cover(im, w, h):
def from_ref():
office = cover(ref_image("OFFICE"), OW, OH)
pic("OFFICE", office)
+ define("CAM_PAN", OW - CW)
bases = {}
for name, kind, _ in PICTURES:
if kind.startswith("patch"):
@@ -640,11 +660,12 @@ def from_ref():
bases[part] = p
elif kind == "cam":
num, state = name[3:5], name[6:]
- a = cover(ref_image(name), CW, CH)
- first = bases.get(num)
- p = pic(name, a, base=first if state not in ("DARK",) else None)
- if state != "DARK" and not first:
- bases[num] = p
+ a = cover(ref_image(name), OW if num in WIDE else CW, OH if num in WIDE else CH)
+ group = num + ("D" if state.startswith("D") else "") # (the dark pictures share with each other)
+ first = bases.get(group)
+ p = pic(name, a, base=first)
+ if not first:
+ bases[group] = p
for who in SCARES:
files = ref_files(f"SCARE_{who}")
first = prev = None
@@ -660,7 +681,7 @@ def from_ref():
elif kind == "face":
pic(name, cover(ref_image(name), 48, 48), "face")
t = ref_image("TITLE_TEXT").convert("RGBA")
- t = t.resize((190, int(t.height * 190 / t.width)), Image.LANCZOS)
+ t = t.resize((94, int(t.height * 94 / t.width)), Image.LANCZOS) # (the game's 300 x 280 on its 1024)
a = np.asarray(t).astype(np.float64)
img("TITLE", a[..., 3] * a[..., :3].mean(axis=2) / 255)
s = np.asarray(ref_image("STAR").convert("RGBA").resize((22, 21), Image.LANCZOS)).astype(np.float64)