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.

Undertale: Snowdin, from the Ruins door to the edge of Waterfall

Mason Chen8db8eb81b972
diff --git a/README.md b/README.md
index 3c865a1c..437d185a 100644
--- a/README.md
+++ b/README.md
@@ -79,7 +79,7 @@ These are too big to fit next to NumPlay, so each one is its own app. Install it
<tr>
<td align="center"><a href="games/celeste/README.md"><img src="docs/media/thumb_celeste.png" width="200" alt="Celeste"><br><b>Celeste</b></a><br><sub>The whole climb, with every B-side and C-side</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/Celeste.nwa">Download</a></td>
<td align="center"><a href="games/championisland/README.md"><img src="docs/media/thumb_championisland.png" width="200" alt="Champion Island"><br><b>Champion Island</b></a><br><sub>The whole island and its seven sports</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/ChampionIsland.nwa">Download</a></td>
- <td align="center"><a href="games/undertale/README.md"><img src="docs/media/thumb_undertale.png" width="200" alt="Undertale"><br><b>Undertale</b></a><br><sub>The Ruins, from the golden flowers to the door out</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/Undertale.nwa">Download</a></td>
+ <td align="center"><a href="games/undertale/README.md"><img src="docs/media/thumb_undertale.png" width="200" alt="Undertale"><br><b>Undertale</b></a><br><sub>The Ruins and Snowdin, from the golden flowers to the edge of Waterfall</sub><br><a href="https://github.com/Mason363/NumPlay/releases/latest/download/Undertale.nwa">Download</a></td>
</tr>
<tr>
<td align="center"><a href="#roadmap"><b>More on the way</b></a><br><sub>The rest of Undertale, The Binding of Isaac, Plants vs. Zombies, Doom and more: see the roadmap</sub></td>
@@ -174,7 +174,7 @@ Filmed on my own calculator, no emulator.
- [x] The Final Earth 2
- [x] The Powder Toy (NumPowder)
- [x] Block Blast
-- [ ] Undertale: the Ruins are out, Snowdin, Waterfall, Hotland and New Home are next
+- [ ] Undertale: the Ruins and Snowdin are out, Waterfall, Hotland and New Home are next
- [ ] The Binding of Isaac
- [ ] Plants vs. Zombies
- [ ] Doom
diff --git a/docs/play.md b/docs/play.md
index e133ea62..ef4dfbcb 100644
--- a/docs/play.md
+++ b/docs/play.md
@@ -268,7 +268,7 @@ Undertale comes as its own app, `Undertale.nwa`: it is too big to share the calc
| **toolbox**, **shift** or **var** | The menu: ITEM, STAT, CELL (C in the game) |
| **Home** | Keep the moment and quit |
-Name the fallen human, then walk and talk your way through the Ruins. In a battle, FIGHT attacks (press **OK** when the bar crosses the middle), ACT checks a monster or does something to it, ITEM eats, and MERCY spares a monster that no longer wants to fight, or flees. Then move your SOUL to dodge. Walk up to a star and press **OK** to SAVE. Home keeps the moment you were at, and the next start is back there. Your save is also copied into `undertale_saves.py`, so installing the app again doesn't erase it. For now the game ends at the door out of the Ruins.
+Name the fallen human, then walk and talk your way through the Ruins and Snowdin. In a battle, FIGHT attacks (press **OK** when the bar crosses the middle), ACT checks a monster or does something to it, ITEM eats, and MERCY spares a monster that no longer wants to fight, or flees. Then move your SOUL to dodge; when it turns blue, it falls, and **Up** jumps. On ice you slide until something stops you. In Snowdin Town, walk into the shop to buy, and into the inn to rest. Walk up to a star and press **OK** to SAVE. Home keeps the moment you were at, and the next start is back there. Your save is also copied into `undertale_saves.py`, so installing the app again doesn't erase it. For now the game ends on the way out of Snowdin, at the edge of Waterfall.
<br clear="right">
diff --git a/games/undertale/README.md b/games/undertale/README.md
index 96b4c53b..e690080b 100644
--- a/games/undertale/README.md
+++ b/games/undertale/README.md
@@ -8,7 +8,7 @@
<p align="center">
<b>Fall into the Underground as a human child, on the NumWorks calculator.</b><br>
- The Ruins, from the bed of golden flowers to the door out. The rest of the Underground is on the way.
+ The Ruins and Snowdin, from the bed of golden flowers to the edge of Waterfall. The rest of the Underground is on the way.
</p>
<p align="center">
@@ -24,8 +24,9 @@
* **The whole Ruins:** every room, from the golden flowers through Toriel's puzzles, the falling leaves, the spikes, the rocks, the cracked floors and the switches, to Toriel's home and the long corridor under it.
* **Its people, with all they have to say:** Flowey, Toriel and her phone calls, Napstablook, the talking rock, the Froggits who give advice, the spider bake sale, the snail facts, and every sign, bookshelf and mirror.
-* **Battles like in the game:** FIGHT with the timing bar, ACT, ITEM and MERCY, and your SOUL dodging each monster's own attacks in the box: Froggit, Whimsun, Moldsmal, Loox, Vegetoid, Migosp, Napstablook and Toriel.
-* **Spare or fight:** every monster can be spared, and Flowey at the door remembers what you did.
+* **Snowdin:** Sans and Papyrus, and every one of Papyrus's puzzles: the invisible electricity maze, the X and O tiles, the one on ice, the multicolor tiles and the Gauntlet. Then Snowdin Town, with its shop, inn, Grillby's, library and Papyrus's house.
+* **Battles like in the game:** FIGHT with the timing bar, ACT, ITEM and MERCY, and your SOUL dodging each monster's own attacks in the box: Froggit, Whimsun, Moldsmal, Loox, Vegetoid, Migosp, Napstablook and Toriel in the Ruins; Snowdrake, Ice Cap, Gyftrot, Jerry, Chilldrake, Glyde, Doggo, Lesser Dog, Dogamy and Dogaressa, Greater Dog and Papyrus, whose blue attack makes your SOUL fall, in Snowdin.
+* **Spare or fight:** every monster can be spared, and Flowey at the door remembers what you did. Lose to Papyrus and he only locks you in his shed.
* **Saved like in the game:** SAVE at the stars, with the room and the time played. The C menu has your ITEM, STAT and CELL. Home keeps the moment you were at, and your save is also copied into `undertale_saves.py`, so installing the app again doesn't erase it.
<table>
@@ -45,6 +46,22 @@
<td align="center"><img src="docs/toriel.png" width="390" alt="Toriel's fight"><br><sub>Toriel won't let you leave</sub></td>
<td align="center"><img src="docs/judgement.png" width="390" alt="Flowey at the door"><br><sub>Flowey waits at the door</sub></td>
</tr>
+ <tr>
+ <td align="center"><img src="docs/sans.png" width="390" alt="Sans in Snowdin Forest"><br><sub>Sans, on the road through Snowdin Forest</sub></td>
+ <td align="center"><img src="docs/maze.png" width="390" alt="The invisible electricity maze"><br><sub>Papyrus's invisible electricity maze</sub></td>
+ </tr>
+ <tr>
+ <td align="center"><img src="docs/ice.png" width="390" alt="The X and O puzzle on ice"><br><sub>The X and O puzzle on ice</sub></td>
+ <td align="center"><img src="docs/greaterdog.png" width="390" alt="Greater Dog"><br><sub>Greater Dog</sub></td>
+ </tr>
+ <tr>
+ <td align="center"><img src="docs/town.png" width="390" alt="Snowdin Town"><br><sub>Snowdin Town</sub></td>
+ <td align="center"><img src="docs/shop.png" width="390" alt="The shop"><br><sub>The shop</sub></td>
+ </tr>
+ <tr>
+ <td align="center"><img src="docs/papyrus.png" width="390" alt="Papyrus's blue attack"><br><sub>Papyrus's blue attack</sub></td>
+ <td align="center"><img src="docs/date.png" width="390" alt="Papyrus's room"><br><sub>Hanging out with Papyrus</sub></td>
+ </tr>
</table>
## How to play
@@ -53,7 +70,9 @@ A new game starts with the story of the war between humans and monsters, then th
Monsters jump out as you walk. In a battle, choose FIGHT to attack (press OK when the bar crosses the middle), ACT to check them, talk or do something else, ITEM to eat, and MERCY to spare them once they no longer want to fight, or to flee. Then move your SOUL, the red heart, to dodge what they throw at you. Each monster has its own way to be spared: try what ACT offers.
-Walk up to a star and press OK to SAVE and fill your HP. The C menu (toolbox) shows your items, your STAT and Toriel's phone number.
+Snowdin brings new things: when Papyrus turns your SOUL blue, it falls to the bottom of the box, and Up jumps over his bones. On ice you slide until something stops you. Snowdin Town's shop sells food and gear, and its inn gives you a night's rest.
+
+Walk up to a star and press OK to SAVE and fill your HP. The C menu (toolbox) shows your items, your STAT and the phone numbers you have.
## Controls
@@ -68,7 +87,7 @@ Walk up to a star and press OK to SAVE and fill your HP. The C menu (toolbox) sh
## Good to know
* **One app at a time:** Undertale is too big to sit next to NumPlay or the other big games. Installing it from the NumWorks website swaps them out, and installing them again swaps it out. Your saves in each one are kept.
-* **Only the Ruins, for now:** the door out of the Ruins ends the game, on a screen that says the rest of the Underground is still to come. Snowdin, Waterfall, Hotland and New Home come next, one at a time.
+* **The Ruins and Snowdin, for now:** the way out of Snowdin ends the game, on a screen that says the rest of the Underground is still to come. Waterfall, Hotland and New Home come next, one at a time.
* **No music or sound:** the calculator has no speaker.
* **The same Underground:** the rooms, pictures and words are the game's, and the puzzles and battles follow how the game plays them, at its 30 frames a second.
diff --git a/games/undertale/docs/date.png b/games/undertale/docs/date.png
new file mode 100644
index 00000000..b95de4df
Binary files /dev/null and b/games/undertale/docs/date.png differ
diff --git a/games/undertale/docs/greaterdog.png b/games/undertale/docs/greaterdog.png
new file mode 100644
index 00000000..918c653c
Binary files /dev/null and b/games/undertale/docs/greaterdog.png differ
diff --git a/games/undertale/docs/ice.png b/games/undertale/docs/ice.png
new file mode 100644
index 00000000..63836937
Binary files /dev/null and b/games/undertale/docs/ice.png differ
diff --git a/games/undertale/docs/maze.png b/games/undertale/docs/maze.png
new file mode 100644
index 00000000..5b75aad8
Binary files /dev/null and b/games/undertale/docs/maze.png differ
diff --git a/games/undertale/docs/papyrus.png b/games/undertale/docs/papyrus.png
new file mode 100644
index 00000000..f04f39e0
Binary files /dev/null and b/games/undertale/docs/papyrus.png differ
diff --git a/games/undertale/docs/sans.png b/games/undertale/docs/sans.png
new file mode 100644
index 00000000..23df68c1
Binary files /dev/null and b/games/undertale/docs/sans.png differ
diff --git a/games/undertale/docs/shop.png b/games/undertale/docs/shop.png
new file mode 100644
index 00000000..96162c75
Binary files /dev/null and b/games/undertale/docs/shop.png differ
diff --git a/games/undertale/docs/town.png b/games/undertale/docs/town.png
new file mode 100644
index 00000000..d5e918cd
Binary files /dev/null and b/games/undertale/docs/town.png differ
diff --git a/games/undertale/src/battle.c b/games/undertale/src/battle.c
index 9fe32d25..b677c8ea 100644
--- a/games/undertale/src/battle.c
+++ b/games/undertale/src/battle.c
@@ -54,6 +54,7 @@ static void box_step(void) {
/* ---------------------------------------------------------------- texts */
static void say(const char *s) {
if (s != bt.text) snprintf(bt.text, sizeof bt.text, "%s", s);
+ text_wrap_width(264);
writer_start(&bt.w, bt.text, 26, 133, FONT_MAIN);
bt.w.line_h = 16;
}
@@ -99,9 +100,11 @@ void battle_start(int form) {
if (!m->gold) m->gold = d->gold;
m->alive = true;
m->spare = d->flags & MF_SPARE_START;
+ m->spare_gold = d->spare_gold;
}
bt.x0 = bt.tx0 = BOX_X0, bt.y0 = bt.ty0 = BOX_Y0, bt.x1 = bt.tx1 = BOX_X1, bt.y1 = bt.ty1 = BOX_Y1;
bt.speed = 2 * FX;
+ soul_set_mode(SOUL_RED);
bt.hp_shown = sv.hp;
heart_x = pl.x + 10 - cam_x, heart_y = pl.y + 17 - cam_y;
prev_mode = g_mode;
@@ -294,11 +297,7 @@ static void do_spare(void) {
}
(void)any;
bt.text[0] = 0;
- if (all_gone()) {
- win();
- return;
- }
- after_player_turn();
+ after_player_turn(); /* (all spared: the battle's won, as BR_SPARED) */
}
static void do_flee(void) {
@@ -395,7 +394,14 @@ static void menu_input(uint32_t pressed) {
if (pressed & K_X) bt.phase = P_MENU;
if (pressed & K_Z) {
bt.last_action = 2;
- item_use(bt.item, bt.text, sizeof bt.text, 1);
+ /* a monster may answer the item (a dog and the Stick) */
+ bool answered = false;
+ for (int i = 0; i < bt.nmon && !answered; i++) {
+ Monster *m = &bt.mon[i];
+ if (m->alive && !m->gone && m->def->on_item)
+ answered = m->def->on_item(&bt, m, sv.items[bt.item], bt.text, sizeof bt.text);
+ }
+ if (!answered) item_use(bt.item, bt.text, sizeof bt.text, 1);
say(bt.text);
bt.phase = P_RESULT;
}
@@ -469,6 +475,10 @@ void battle_update(uint32_t keys, uint32_t pressed) {
if (m->killed && m->alive) {
m->alive = false, m->gone = true, m->dust = 1;
sv.kills++;
+ {
+ const RoomInfo *ri = world_room_info();
+ if (ri && (ri->area == AREA_SNOWDIN || ri->area == AREA_SNOWTOWN)) set_flag(F_KILLS_SNOWDIN, flag(F_KILLS_SNOWDIN) + 1);
+ }
}
after_player_turn();
}
@@ -514,6 +524,11 @@ void battle_update(uint32_t keys, uint32_t pressed) {
attack_run(&bt, bt.atk, bt.atk_t);
bullets_update();
soul_hit_test();
+ if (sv.hp <= 0 && bt.captures) {
+ sv.hp = 1;
+ battle_end(BR_SCRIPTED);
+ break;
+ }
if (sv.hp <= 0) {
bt.phase = P_DEATH, bt.t = 0;
break;
diff --git a/games/undertale/src/battle.h b/games/undertale/src/battle.h
index ce537418..05a57dcc 100644
--- a/games/undertale/src/battle.h
+++ b/games/undertale/src/battle.h
@@ -32,9 +32,10 @@ enum { BR_WON, BR_SPARED, BR_FLED, BR_DIED, BR_SCRIPTED };
struct Battle;
struct Monster;
-typedef struct {
+typedef struct MonDef {
const char *name;
int16_t hp, at, df, exp, gold;
+ int16_t spare_gold; /* the gold it gives when spared */
uint16_t spr_idle, spr_hurt; /* SPR_*: idle animation (its frames), hurt */
uint8_t idle_speed; /* frames between idle frames */
int8_t dx, dy; /* where it stands, from its slot */
@@ -55,6 +56,8 @@ typedef struct {
void (*draw)(struct Battle *b, struct Monster *m, int x, int y);
bool (*ends)(struct Battle *b, struct Monster *m); /* after its talk: true, it leaves the battle */
void (*on_spare)(struct Battle *b, struct Monster *m); /* spared while it isn't spareable (Toriel counts) */
+ /* an item used: true if it answers (the dogs and the Stick), its text in text */
+ bool (*on_item)(struct Battle *b, struct Monster *m, int item, char *text, int cap);
} MonDef;
enum {
MF_ONE_HIT = 1, /* dies in one hit (Whimsun) */
@@ -123,6 +126,7 @@ typedef struct Battle {
int bar_x, bar_dir; /* FIGHT: the bar, 1/16 px */
int strike_t, strike_dmg;
bool flee_ok, scripted, no_flee, no_buttons;
+ bool captures; /* no death: at 0 HP the battle ends, HP 1 (Papyrus captures you) */
int result;
int exp_won, gold_won;
int kr; /* (for later) */
@@ -152,6 +156,9 @@ void bullets_update(void);
void bullets_draw(void);
bool soul_hit_test(void); /* bullets touching the SOUL hurt it */
void soul_update(uint32_t keys);
+enum { SOUL_RED, SOUL_BLUE }; /* (the heart's frame too) */
+void soul_set_mode(int mode); /* blue: it falls, up jumps */
+void gfx_bone(int cx, int cy, int w, int h, uint16_t col, uint8_t a);
void soul_hurt(int dmg, int color);
void board_set(int w, int h); /* the board, centred, as the game resizes it */
void board_set_rect(int x0, int y0, int x1, int y1);
diff --git a/games/undertale/src/bullets.c b/games/undertale/src/bullets.c
index a4768b78..a34f7f5f 100644
--- a/games/undertale/src/bullets.c
+++ b/games/undertale/src/bullets.c
@@ -29,12 +29,33 @@ int soul_x(void) { return bt.sx / FX; }
int soul_y(void) { return bt.sy / FX; }
/* the SOUL: 8 x 8, moved inside the board by the arrows (X held: slower, as in the game) */
+/* the blue SOUL: it falls, and up jumps (higher while held), as the game's (halved) */
+static int32_t soul_vy;
+#define BLUE_JUMP (3 * FX)
+#define BLUE_GRAVITY 3 /* 1/16 px a frame, each frame */
+void soul_set_mode(int mode) {
+ bt.soul_mode = mode;
+ soul_vy = 0;
+}
void soul_update(uint32_t keys) {
int sp = bt.speed;
if (keys & K_X) sp /= 2;
int dx = ((keys & K_RIGHT) != 0) - ((keys & K_LEFT) != 0), dy = ((keys & K_DOWN) != 0) - ((keys & K_UP) != 0);
- bt.sx += dx * sp, bt.sy += dy * sp;
int x0 = (bt.x0 + 2 + 4) * FX, x1 = (bt.x1 - 2 - 4) * FX, y0 = (bt.y0 + 2 + 4) * FX, y1 = (bt.y1 - 2 - 4) * FX;
+ if (bt.soul_mode == SOUL_BLUE) {
+ bt.sx += dx * sp;
+ if (bt.sy >= y1) {
+ soul_vy = (keys & K_UP) ? -BLUE_JUMP : 0;
+ } else {
+ /* letting go of up cuts the jump short */
+ if (soul_vy < -FX / 2 && !(keys & K_UP)) soul_vy = -FX / 2;
+ soul_vy += BLUE_GRAVITY;
+ }
+ bt.sy += soul_vy;
+ if (bt.sy < y0) bt.sy = y0, soul_vy = 0;
+ } else {
+ bt.sx += dx * sp, bt.sy += dy * sp;
+ }
if (bt.sx < x0) bt.sx = x0;
if (bt.sx > x1) bt.sx = x1;
if (bt.sy < y0) bt.sy = y0;
@@ -87,11 +108,30 @@ void bullets_update(void) {
}
}
+/* a bone: its box w x h around (cx, cy), lying along its longer side; knobs at its ends */
+void gfx_bone(int cx, int cy, int w, int h, uint16_t col, uint8_t a) {
+ if (h >= w) {
+ int x = cx - w / 2, y = cy - h / 2, k = w / 2 > 1 ? w / 2 : 1;
+ gfx_rect(x + w / 4, y + k, w - 2 * (w / 4), h - 2 * k, col, a);
+ gfx_circle(x + k / 2 + 1, y + k, k, col, a), gfx_circle(x + w - k / 2 - 1, y + k, k, col, a);
+ gfx_circle(x + k / 2 + 1, y + h - k - 1, k, col, a), gfx_circle(x + w - k / 2 - 1, y + h - k - 1, k, col, a);
+ } else {
+ int x = cx - w / 2, y = cy - h / 2, k = h / 2 > 1 ? h / 2 : 1;
+ gfx_rect(x + k, y + h / 4, w - 2 * k, h - 2 * (h / 4), col, a);
+ gfx_circle(x + k, y + k / 2 + 1, k, col, a), gfx_circle(x + k, y + h - k / 2 - 1, k, col, a);
+ gfx_circle(x + w - k - 1, y + k / 2 + 1, k, col, a), gfx_circle(x + w - k - 1, y + h - k / 2 - 1, k, col, a);
+ }
+}
+
void bullets_draw(void) {
for (int i = 0; i < MAX_BULLETS; i++) {
const Bullet *b = &bullets[i];
if (b->kind == BK_NONE || (b->flags & BF_HIDDEN)) continue;
uint16_t color = b->color == BC_BLUE ? rgb565(0x14A9FF) : b->color == BC_ORANGE ? rgb565(0xFCA600) : b->color == BC_GREEN ? rgb565(0x00C000) : 0;
+ if (b->spr == SPR_BONE) {
+ gfx_bone(b->x / FX, b->y / FX, b->w, b->h, color ? color : C_WHITE, b->alpha);
+ continue;
+ }
if (b->angle) gfx_sprite_ex(b->spr, b->frame, b->x / FX, b->y / FX, 256, 256, b->angle, color, b->alpha);
else if (color) gfx_sprite_color(b->spr, b->frame, b->x / FX, b->y / FX, 0, color, b->alpha);
else gfx_sprite(b->spr, b->frame, b->x / FX, b->y / FX, 0, b->alpha);
diff --git a/games/undertale/src/data.bin b/games/undertale/src/data.bin
index b89314e3..a1f28878 100644
Binary files a/games/undertale/src/data.bin and b/games/undertale/src/data.bin differ
diff --git a/games/undertale/src/data.h b/games/undertale/src/data.h
index a8898290..8f703c29 100644
--- a/games/undertale/src/data.h
+++ b/games/undertale/src/data.h
@@ -126,47 +126,106 @@
#define SPR_O_TORIEL_RUFFLE 113
#define SPR_FROG_OW 114
#define SPR_NAPSTA_OW 115
-#define SPR_INTROIMAGE 116
-#define SPR_INTROLAST 117
-#define SPR_UNDERTALETITLE 118
-#define SPR_GAMEOVERBG 119
-#define SPR_FACE_TORIELTALK 120
-#define SPR_FACE_TORIELTALKSIDE 121
-#define SPR_FACE_TORIELHAPPYTALK 122
-#define SPR_FACE_TORIELWHAT 123
-#define SPR_FACE_TORIELWHATSIDE 124
-#define SPR_FACE_TORIELMAD 125
-#define SPR_FACE_TORIELCOLD 126
-#define SPR_FACE_TORIELSURPRISED 127
-#define SPR_FACE_TORIELEMBARRASSED 128
-#define SPR_FACE_TORIELGLASSES 129
-#define SPR_FACE_TORIELREVENGETALK 130
-#define SPR_FACE_TORIELSCARED 131
-#define SPR_FACE_TORIELBLINK 132
-#define SPR_FACE_TORIELHAPPYBLINK 133
-#define SPR_FACE_TORIELBODY 134
-#define SPR_FACE_SANS 135
-#define SPR_FACE_SANSCHUCKLE 136
-#define SPR_FACE_SANSWINK 137
-#define SPR_FACE_PAPYRUS 138
-#define SPR_FACE_PAPYRUSEVIL 139
-#define SPR_FACE_PAPYRUSLAUGH 140
-#define SPR_FACE_PAPYRUSMAD 141
-#define SPR_FACE_PAPYRUSSIDE 142
-#define SPR_FLOWEYNICE 143
-#define SPR_FLOWEYNICESIDE 144
-#define SPR_FLOWEYSASSY 145
-#define SPR_FLOWEYEVIL 146
-#define SPR_FLOWEYGRIN 147
-#define SPR_FLOWEYPLAIN 148
-#define SPR_FLOWEYPISSED 149
-#define SPR_FLOWEYWINK 150
-#define SPR_FLOWEYLAUGH 151
-#define SPR_FLOWEYHURT 152
-#define SPR_FLOWEYTORIEL 153
-#define SPR_FLOWEYTORIEL2 154
-#define SPR_FLOWEYSIDESHOCK 155
+#define SPR_PAPYRUS_R 116
+#define SPR_PAPYRUS_L 117
+#define SPR_PAPYRUS_D 118
+#define SPR_SANS_D 119
+#define SPR_DOGGO_OW 120
+#define SPR_DOGAMY_OW 121
+#define SPR_DOGARESSA_OW 122
+#define SPR_GREATERDOG_OW 123
+#define SPR_POFF 124
+#define SPR_DOG_OW 125
+#define SPR_DOG_BONE 126
+#define SPR_XTILE 127
+#define SPR_OTILE 128
+#define SPR_SNOWSPIKES 129
+#define SPR_SNOWSWITCH 130
+#define SPR_SNOWBALL 131
+#define SPR_LAMP 132
+#define SPR_PAPYRUS_ZAP 133
+#define SPR_FLAG_LIGHTBLUE 134
+#define SPR_FLAG_PURPLE 135
+#define SPR_FLAG_GREEN 136
+#define SPR_FLAG_BLUE 137
+#define SPR_FLAG_YELLOW 138
+#define SPR_FLAG_ORANGE 139
+#define SPR_FLAG_RED 140
+#define SPR_ORB 141
+#define SPR_SHOP_QC 142
+#define SPR_BONE 143
+#define SPR_SNOWFLAKE 144
+#define SPR_ICESHARD 145
+#define SPR_PRESENT 146
+#define SPR_KNIFE 147
+#define SPR_DOGPAW 148
+#define SPR_HEARTBULLET 149
+#define SPR_SNOWDRAKE_B 150
+#define SPR_SNOWDRAKE_HURT 151
+#define SPR_ICECAP_B 152
+#define SPR_ICECAP_HURT 153
+#define SPR_ICECAP_HATLESS 154
+#define SPR_GYFTROT_B 155
+#define SPR_GYFTROT_HURT 156
+#define SPR_DOGGO_B 157
+#define SPR_DOGGO_HURT 158
+#define SPR_LESSERDOG_B 159
+#define SPR_LESSERDOG_HURT 160
+#define SPR_GREATERDOG_B 161
+#define SPR_GREATERDOG_HURT 162
+#define SPR_DOGAMY_B 163
+#define SPR_DOGARESSA_B 164
+#define SPR_JERRY_B 165
+#define SPR_JERRY_HURT 166
+#define SPR_CHILLDRAKE_B 167
+#define SPR_GLYDE_B 168
+#define SPR_GLYDE_HURT 169
+#define SPR_PAPYRUS_B 170
+#define SPR_PAPYRUS_HURT 171
+#define SPR_PAPYRUS_CONFUSED 172
+#define SPR_INTROIMAGE 173
+#define SPR_INTROLAST 174
+#define SPR_UNDERTALETITLE 175
+#define SPR_GAMEOVERBG 176
+#define SPR_FACE_TORIELTALK 177
+#define SPR_FACE_TORIELTALKSIDE 178
+#define SPR_FACE_TORIELHAPPYTALK 179
+#define SPR_FACE_TORIELWHAT 180
+#define SPR_FACE_TORIELWHATSIDE 181
+#define SPR_FACE_TORIELMAD 182
+#define SPR_FACE_TORIELCOLD 183
+#define SPR_FACE_TORIELSURPRISED 184
+#define SPR_FACE_TORIELEMBARRASSED 185
+#define SPR_FACE_TORIELGLASSES 186
+#define SPR_FACE_TORIELREVENGETALK 187
+#define SPR_FACE_TORIELSCARED 188
+#define SPR_FACE_TORIELBLINK 189
+#define SPR_FACE_TORIELHAPPYBLINK 190
+#define SPR_FACE_TORIELBODY 191
+#define SPR_FACE_SANS 192
+#define SPR_FACE_SANSCHUCKLE 193
+#define SPR_FACE_SANSWINK 194
+#define SPR_FACE_PAPYRUS 195
+#define SPR_FACE_PAPYRUSEVIL 196
+#define SPR_FACE_PAPYRUSLAUGH 197
+#define SPR_FACE_PAPYRUSMAD 198
+#define SPR_FACE_PAPYRUSSIDE 199
+#define SPR_FLOWEYNICE 200
+#define SPR_FLOWEYNICESIDE 201
+#define SPR_FLOWEYSASSY 202
+#define SPR_FLOWEYEVIL 203
+#define SPR_FLOWEYGRIN 204
+#define SPR_FLOWEYPLAIN 205
+#define SPR_FLOWEYPISSED 206
+#define SPR_FLOWEYWINK 207
+#define SPR_FLOWEYLAUGH 208
+#define SPR_FLOWEYHURT 209
+#define SPR_FLOWEYTORIEL 210
+#define SPR_FLOWEYTORIEL2 211
+#define SPR_FLOWEYSIDESHOCK 212
#define AREA_RUINS 0
+#define AREA_SNOWDIN 1
+#define AREA_SNOWTOWN 2
#define ROOM_AREA1 0
#define ROOM_AREA1_2 1
#define ROOM_RUINS1 2
@@ -213,10 +272,49 @@
#define ROOM_BASEMENT2 43
#define ROOM_BASEMENT3 44
#define ROOM_RUINSEXIT 45
+#define ROOM_SNOWDIN1 46
+#define ROOM_SNOWDIN2 47
+#define ROOM_SNOWDIN3 48
+#define ROOM_SNOWDIN4 49
+#define ROOM_SNOWDIN5 50
+#define ROOM_BOXROAD 51
+#define ROOM_RIVER 52
+#define ROOM_PAPSENTRY 53
+#define ROOM_DOGGO 54
+#define ROOM_ICEFIELD 55
+#define ROOM_SNOWMAN 56
+#define ROOM_ELECMAZE 57
+#define ROOM_BALLGAME 58
+#define ROOM_DOGI 59
+#define ROOM_WORDSEARCH 60
+#define ROOM_SPAGHETTI 61
+#define ROOM_SNOWPUZZLE 62
+#define ROOM_XOXO1 63
+#define ROOM_XOXO2 64
+#define ROOM_TILEPUZZLE 65
+#define ROOM_DOGHOUSE 66
+#define ROOM_XOXO3 67
+#define ROOM_XOXOFAIL 68
+#define ROOM_POFFZONE 69
+#define ROOM_DANGERBRIDGE 70
+#define ROOM_DOORROOM 71
+#define ROOM_SOUTHCLIFF 72
+#define ROOM_SNOWTOWN 73
+#define ROOM_TOWNNORTH 74
+#define ROOM_TOWNDOCK 75
+#define ROOM_FOGROOM 76
+#define ROOM_INN1 77
+#define ROOM_INN2 78
+#define ROOM_GRILLBYS 79
+#define ROOM_LIBRARY 80
+#define ROOM_PSHOUSE 81
+#define ROOM_PAPROOM 82
+#define ROOM_SANSROOM 83
+#define ROOM_SHED 84
#define FONT_MAIN 0
#define FONT_MENU 1
#define FONT_SMALL 2
-#define NUM_SPRITES 156
-#define NUM_ROOMS 46
+#define NUM_SPRITES 213
+#define NUM_ROOMS 85
#define NUM_FONTS 3
#endif
diff --git a/games/undertale/src/events.c b/games/undertale/src/events.c
index c8ba2d84..753fe6c1 100644
--- a/games/undertale/src/events.c
+++ b/games/undertale/src/events.c
@@ -7,6 +7,7 @@
#include "game.h"
#include "menu.h"
#include "ruins.h"
+#include "snowdin.h"
static int ev_sign(Ev *c) {
EV_BEGIN;
@@ -37,6 +38,10 @@ static int ev_phone(Ev *c) {
static const char *const opts[] = {"Say Hello", "Puzzle Help", "About Yourself", "Call Her \"Mom\"", "Flirt"};
EV_BEGIN;
NARRATE("* Dialing...");
+ if (c->v[0] == 1) { /* Papyrus */
+ SAY(FACE_PAPYRUS, "`0* HELLO! THIS IS PAPYRUS!\n* HOW DID YOU GET THIS NUMBER?|`2* OH, RIGHT, I GAVE IT TO YOU!\n* NYEH HEH HEH!");
+ return 1;
+ }
CHOOSE(opts, 5);
switch (CHOSEN()) {
case 0:
@@ -81,6 +86,7 @@ static int ev_encounter(Ev *c) {
WAIT(18);
g_exclaim = 0;
BATTLE(c->v[0]);
+ snow_battle_done(c->v[0]);
EV_END;
}
@@ -97,5 +103,11 @@ int event_run(Ev *c) {
if (r >= 0) return r;
r = ruins3_event(c);
if (r >= 0) return r;
+ r = snow1_event(c);
+ if (r >= 0) return r;
+ r = snow2_event(c);
+ if (r >= 0) return r;
+ r = town_event(c);
+ if (r >= 0) return r;
return 1;
}
diff --git a/games/undertale/src/events.h b/games/undertale/src/events.h
index 82a1ac7e..5d8c3adc 100644
--- a/games/undertale/src/events.h
+++ b/games/undertale/src/events.h
@@ -5,7 +5,10 @@
enum {
ACTOR_NONE, ACTOR_TORIEL, ACTOR_FLOWEY, ACTOR_DUMMY, ACTOR_DOOR, ACTOR_SPIKES, ACTOR_SPIKES2, ACTOR_FROGGIT,
ACTOR_PILLAR, ACTOR_NAPSTA, ACTOR_ROCK, ACTOR_ROCK2, ACTOR_ROCK3, ACTOR_SWITCH, ACTOR_SWITCH2, ACTOR_SWITCH3,
- ACTOR_CANDY, ACTOR_TRIGGER, ACTOR_TRIGGER2, ACTOR_ITEM, ACTOR_CHAIR, ACTOR_PIE, ACTOR_ANY
+ ACTOR_CANDY, ACTOR_TRIGGER, ACTOR_TRIGGER2, ACTOR_ITEM, ACTOR_CHAIR, ACTOR_PIE, ACTOR_ANY,
+ /* Snowdin */
+ ACTOR_SANS, ACTOR_PAPYRUS, ACTOR_DOGGO, ACTOR_DOGAMY, ACTOR_DOGARESSA, ACTOR_GREATERDOG, ACTOR_BALL, ACTOR_ORB,
+ ACTOR_TILE, ACTOR_DOG, ACTOR_BLOCK, ACTOR_TRIGGER3
};
enum {
@@ -22,6 +25,14 @@ enum {
EV_FROGGIT, EV_ITEM, EV_ONE_SWITCH, EV_VEGGIE, EV_TORIEL_TREE,
/* ruins3.c */
EV_HOME_TOUR, EV_TORIEL_CHAIR, EV_BED, EV_STAIRS, EV_BASEMENT_TALK, EV_TORIEL_DOOR, EV_FLOWEY_END, EV_RUINS_DOOR,
+ /* snowdin1.c */
+ EV_BRANCH, EV_SANS_INTRO, EV_SANS_TALK, EV_PAP_SENTRY, EV_DOGGO, EV_DOGGO_BELL, EV_SNOWMAN, EV_ELECMAZE, EV_MAZE_ZAP,
+ EV_NICECREAM, EV_BALL_HOLE, EV_WORDSEARCH, EV_BOX, EV_FISHROD, EV_SNOW_TALKBACK,
+ /* snowdin2.c */
+ EV_SNOW_SWITCH, EV_DOGI, EV_XOXO_SWITCH, EV_PAP_XOXO, EV_TILES, EV_XOXO_FALL, EV_TREESLIDE, EV_POFF, EV_GREATERDOG,
+ EV_GAUNTLET, EV_MYSTERY_DOOR, EV_SNOW_SANS_CLIFF,
+ /* snowtown.c */
+ EV_SHOP, EV_INN, EV_GRILLBYS, EV_PAP_FIGHT, EV_PAP_HOUSE, EV_PAP_DATE, EV_TOWN_DOOR, EV_SNOW_END, EV_COUCH,
EV_COUNT
};
/* Toriel's calls on the way (EV_CALL's v[0]) */
diff --git a/games/undertale/src/flags.h b/games/undertale/src/flags.h
index 8a925eb1..32cb3e18 100644
--- a/games/undertale/src/flags.h
+++ b/games/undertale/src/flags.h
@@ -55,6 +55,46 @@ enum {
F_HOME_TOUR, /* Toriel showed Frisk the house */
F_SNAIL_TALK,
F_BED_SLEPT, /* 1 slept; 2 the pie taken */
+ /* Snowdin */
+ F_BRANCH, /* the branch broke behind Frisk */
+ F_SANS_MET, /* the gate, the lamp: Sans and Papyrus met */
+ F_SANS_FAVOR, /* Sans asked his favour */
+ F_PAP_SENTRY, /* Papyrus saw the human (not a rock) */
+ F_DOGGO, /* 1 spared, 2 killed */
+ F_SANS_HINT, /* the blue stop sign */
+ F_SNOWMAN, /* pieces taken */
+ F_ELECMAZE, /* 1 Papyrus zapped and gave the orb, 2 crossed */
+ F_SANS_COOL, /* 1 cool, 2 uncool */
+ F_NICECREAM, /* the Nice Cream guy met */
+ F_FRIED_SNOW, /* times Sans named his price */
+ F_BALLGAME, /* the flag won (1..7) */
+ F_WORDSEARCH, /* 1 crossword, 2 junior jumble */
+ F_SPAGHETTI,
+ F_SNOWPUZZLE, /* the switch under the snow */
+ F_DOGI, /* 1 spared, 2 killed */
+ F_XOXO1, F_XOXO2, F_XOXO3,
+ F_PAP_XOXO1, /* asked about the spaghetti */
+ F_TILES, /* the multicolor tiles explained */
+ F_LESSERDOG, /* 1 spared, 2 killed */
+ F_POFF_GOLD,
+ F_GREATERDOG, /* 1 spared, 2 killed */
+ F_GAUNTLET,
+ F_SNOW_SANS_TALK, /* Sans's talks along the way, a bit each */
+ F_PAPYRUS, /* 1 spared, 2 killed, 3 fled */
+ F_PAP_CAPTURED, /* times Papyrus captured Frisk */
+ F_PAP_DATE, /* 1 promised, 2 done */
+ F_GRILLBYS,
+ F_INN, /* nights at the inn */
+ F_KILLS_SNOWDIN,
+ F_BOX0, F_BOX1, F_BOX2, F_BOX3, F_BOX4, F_BOX5, F_BOX6, F_BOX7, F_BOX8, F_BOX9, /* the Dimensional Box */
+ F_SNOW_EXIT,
+ F_TOWN_HOUSE, /* Papyrus's house open */
+ F_SNOWDIN_BOSSES, /* boss fights (Bisicle's price) */
+ F_SNOW_SANS_LAMP, /* hidden behind the lamp */
+ F_COUCH_GOLD,
+ F_FISH, /* the fishing rod's note read */
+ F_SHOP_TALK,
+ F_SNOWDRAKE_DEAD, /* (then Chilldrake comes instead) */
FLAG_COUNT = 256
};
#endif
diff --git a/games/undertale/src/game.c b/games/undertale/src/game.c
index 87489290..6133943c 100644
--- a/games/undertale/src/game.c
+++ b/games/undertale/src/game.c
@@ -4,6 +4,7 @@
#include "battle.h"
#include "event.h"
#include "game.h"
+#include "shop.h"
#include "gfx.h"
#include "items.h"
#include "menu.h"
@@ -96,11 +97,11 @@ void game_frame(uint32_t keys) {
prev_keys = keys;
g_frame++;
if (keys & K_HOME) {
- if (g_mode == MODE_WORLD || g_mode == MODE_MENU || g_mode == MODE_BATTLE) game_quit_save();
+ if (g_mode == MODE_WORLD || g_mode == MODE_MENU || g_mode == MODE_BATTLE || g_mode == MODE_SHOP) game_quit_save();
g_running = false;
return;
}
- if (g_mode == MODE_WORLD || g_mode == MODE_BATTLE || g_mode == MODE_MENU) sv.time++;
+ if (g_mode == MODE_WORLD || g_mode == MODE_BATTLE || g_mode == MODE_MENU || g_mode == MODE_SHOP) sv.time++;
switch (g_mode) {
case MODE_WORLD:
world_update(keys, pressed);
@@ -111,6 +112,10 @@ void game_frame(uint32_t keys) {
battle_update(keys, pressed);
event_update();
break;
+ case MODE_SHOP:
+ shop_update(keys, pressed);
+ if (g_mode == MODE_WORLD) event_update();
+ break;
default:
menu_update(keys, pressed);
if (g_mode == MODE_WORLD) event_update();
@@ -132,6 +137,9 @@ void game_draw(void) {
case MODE_BATTLE:
battle_draw();
break;
+ case MODE_SHOP:
+ shop_draw();
+ break;
default:
menu_draw();
break;
diff --git a/games/undertale/src/game.h b/games/undertale/src/game.h
index d9cb1785..cc9ec665 100644
--- a/games/undertale/src/game.h
+++ b/games/undertale/src/game.h
@@ -13,7 +13,8 @@ static inline int clamp_i(int v, int a, int b) { return v < a ? a : v > b ? b :
static inline int min_i(int a, int b) { return a < b ? a : b; }
static inline int max_i(int a, int b) { return a > b ? a : b; }
-enum { MODE_TITLE, MODE_NAME, MODE_WORLD, MODE_BATTLE, MODE_MENU, MODE_SAVE, MODE_GAMEOVER, MODE_INTRO, MODE_END };
+enum { MODE_TITLE, MODE_NAME, MODE_WORLD, MODE_BATTLE, MODE_MENU, MODE_SAVE, MODE_GAMEOVER, MODE_INTRO, MODE_END,
+ MODE_SHOP };
#define NUM_ITEMS 8
typedef struct {
diff --git a/games/undertale/src/items.c b/games/undertale/src/items.c
index d04be764..ee0241da 100644
--- a/games/undertale/src/items.c
+++ b/games/undertale/src/items.c
@@ -22,6 +22,18 @@ static const ItemInfo items[ITEM_COUNT] = {
"* You ate the Snail Pie.\n* Your HP was maxed. Almost.", 350},
[ITEM_FADED_RIBBON] = {"Faded Ribbon", "Ribbon", IT_ARMOR, 0, 0, 3, "If you're cuter, monsters\n won't hit you as hard.", "", 0},
[ITEM_TOY_KNIFE] = {"Toy Knife", "Toy Knife", IT_WEAPON, 0, 3, 0, "Made of plastic.\n* A rarity nowadays.", "", 100},
+ [ITEM_TOUGH_GLOVE] = {"Tough Glove", "TuffGlove", IT_WEAPON, 0, 5, 0, "A worn pink leather glove.\n* For five-fingered folk.", "", 50},
+ [ITEM_MANLY_BANDANNA] = {"Manly Bandanna", "Mandanna", IT_ARMOR, 0, 0, 7, "It has seen some wear.\n* It has abs drawn on it.", "", 50},
+ [ITEM_SNOWMAN_PIECE] = {"Snowman Piece", "SnowPiece", IT_FOOD, 45, 0, 0, "Please take this to the\n ends of the earth.",
+ "* You ate the Snowman Piece.", 40},
+ [ITEM_NICE_CREAM] = {"Nice Cream", "NiceCream", IT_FOOD, 15, 0, 0, "Instead of a joke, the\n wrapper says something nice.",
+ "* You unwrapped the Nice Cream.", 2},
+ [ITEM_BISICLE] = {"Bisicle", "Bisicle", IT_FOOD, 11, 0, 0, "It's a two-pronged popsicle,\n so you can eat it twice.",
+ "* You eat one half of the\n Bisicle.", 5},
+ [ITEM_UNISICLE] = {"Unisicle", "Unisicle", IT_FOOD, 11, 0, 0, "It's a SINGLE-pronged popsicle.\n* Wait, that's just normal...",
+ "* You ate the Unisicle.", 2},
+ [ITEM_CINNAMON_BUNNY] = {"Cinnamon Bunny", "CinnaBun", IT_FOOD, 22, 0, 0, "A cinnamon roll in the\n shape of a bunny.",
+ "* You eat the Cinnamon Bunny.", 8},
};
const ItemInfo *item_info(int id) { return &items[id >= 0 && id < ITEM_COUNT ? id : 0]; }
@@ -82,7 +94,14 @@ void item_use(int slot, char *out, int cap, int in_battle) {
}
default: {
int n = snprintf(out, (size_t)cap, "%s", it->use);
- item_remove_at(slot);
+ if (id == ITEM_NICE_CREAM) { /* its wrapper's kind words */
+ static const char *const nice[] = {"You're just great!", "You look nice today!", "Are those claws natural?",
+ "You're super spiffy!", "Have a wonderful day!", "Is this as sweet as you?"};
+ n += snprintf(out + n, (size_t)(cap - n), "\n* \"%s\"", nice[rnd_n(6)]);
+ }
+ /* half a Bisicle is a Unisicle */
+ if (id == ITEM_BISICLE) sv.items[slot] = ITEM_UNISICLE;
+ else item_remove_at(slot);
if (it->heal >= 999) {
sv.hp = sv.maxhp;
snprintf(out + n, (size_t)(cap - n), "\n* Your HP was maxed out.");
diff --git a/games/undertale/src/items.h b/games/undertale/src/items.h
index 701691da..33abf15a 100644
--- a/games/undertale/src/items.h
+++ b/games/undertale/src/items.h
@@ -14,6 +14,14 @@ enum {
ITEM_SNAIL_PIE,
ITEM_FADED_RIBBON,
ITEM_TOY_KNIFE,
+ /* Snowdin */
+ ITEM_TOUGH_GLOVE,
+ ITEM_MANLY_BANDANNA,
+ ITEM_SNOWMAN_PIECE,
+ ITEM_NICE_CREAM,
+ ITEM_BISICLE,
+ ITEM_UNISICLE,
+ ITEM_CINNAMON_BUNNY,
ITEM_COUNT
};
enum { IT_FOOD, IT_WEAPON, IT_ARMOR, IT_SPECIAL };
diff --git a/games/undertale/src/menu.c b/games/undertale/src/menu.c
index 83da5f51..01d2f3f7 100644
--- a/games/undertale/src/menu.c
+++ b/games/undertale/src/menu.c
@@ -218,13 +218,18 @@ static void c_menu_input(uint32_t pressed) {
case M_STAT:
if (pressed & (K_X | K_Z)) st = M_MAIN;
break;
- case M_CELL:
+ case M_CELL: {
+ int n = flag(F_PAP_DATE) == 2 ? 2 : 1; /* Toriel's phone; Papyrus's once he gave it */
+ if (pressed & K_UP) sub = (sub + n - 1) % n;
+ if (pressed & K_DOWN) sub = (sub + 1) % n;
if (pressed & K_X) st = M_MAIN;
if (pressed & K_Z) {
menu_close();
event_start(EV_PHONE_MENU, NULL);
+ event_cur_arg(sub);
}
break;
+ }
}
}
@@ -298,7 +303,8 @@ static void draw_c_menu(void) {
if (st == M_CELL) {
panel(94, 26, 173, 60);
gfx_text(FONT_MENU, 116, 38, "Toriel's Phone", C_WHITE, 255);
- gfx_sprite(SPR_HEART, 0, 107, 44, 0, 255);
+ if (flag(F_PAP_DATE) == 2) gfx_text(FONT_MENU, 116, 56, "Papyrus's Phone", C_WHITE, 255);
+ gfx_sprite(SPR_HEART, 0, 107, 44 + sub * 18, 0, 255);
}
}
@@ -362,7 +368,7 @@ void menu_gameover_open(void) {
void menu_end_open(void) {
g_mode = MODE_END;
t = 0;
- writer_start(&w, "The RUINS are behind you.|The rest of the underground\nis still to come...", 52, 100, FONT_MAIN);
+ writer_start(&w, "Snowdin is behind you.|The rest of the underground\nis still to come...", 52, 100, FONT_MAIN);
w.speed = 2;
}
diff --git a/games/undertale/src/menu.h b/games/undertale/src/menu.h
index ff41316b..08c3e1b7 100644
--- a/games/undertale/src/menu.h
+++ b/games/undertale/src/menu.h
@@ -6,7 +6,7 @@ void menu_title_open(void);
void menu_open(void);
void menu_save_open(void);
void menu_gameover_open(void);
-void menu_end_open(void); /* the Ruins' door: what comes next isn't made yet */
+void menu_end_open(void); /* the way out of Snowdin: what comes next isn't made yet */
void menu_update(uint32_t keys, uint32_t pressed);
void menu_draw(void);
void game_new(const char *name);
diff --git a/games/undertale/src/monsters.c b/games/undertale/src/monsters.c
index 2f7f1867..ab7b083e 100644
--- a/games/undertale/src/monsters.c
+++ b/games/undertale/src/monsters.c
@@ -218,7 +218,7 @@ static bool hit_napsta(Battle *b, Monster *m, int dmg) {
}
/* ---------------------------------------------------------------- the monsters */
-static const MonDef defs[MON_COUNT] = {
+static const MonDef defs[MON_RUINS_COUNT] = {
[MON_DUMMY] = {
.name = "Dummy", .hp = 15, .at = 0, .df = -5, .exp = 0, .gold = 0, .spr_idle = SPR_DUMMY_B, .spr_hurt = SPR_DUMMY_B,
.check = "A cotton heart and a button\n eye\n* You are the apple of my eye",
@@ -280,15 +280,13 @@ static const MonDef defs[MON_COUNT] = {
};
extern const MonDef toriel_def;
-const MonDef *mon_def(int id) { return id == MON_TORIEL ? &toriel_def : &defs[id]; }
+const MonDef *mon_def(int id) {
+ if (id >= MON_RUINS_COUNT) return snow_mon_def(id);
+ return id == MON_TORIEL ? &toriel_def : &defs[id];
+}
/* ---------------------------------------------------------------- formations */
-typedef struct {
- uint8_t mon[MAX_MON];
- uint8_t n;
- const char *text;
-} Form;
-static const Form forms[FORM_COUNT] = {
+static const Form forms[FORM_RUINS_COUNT] = {
[FORM_DUMMY] = {{MON_DUMMY}, 1, "* You encountered the Dummy."},
[FORM_FROGGIT_FIRST] = {{MON_FROGGIT_FIRST}, 1, "* Froggit attacks you!"},
[FORM_FROGGIT] = {{MON_FROGGIT}, 1, "* Froggit hopped close!"},
@@ -311,7 +309,7 @@ static const Form forms[FORM_COUNT] = {
};
int form_setup(int form, Battle *b) {
- const Form *f = &forms[form];
+ const Form *f = form >= FORM_RUINS_COUNT ? snow_form(form) : &forms[form];
static const int16_t xs[3][3] = {{160}, {108, 212}, {70, 160, 250}};
b->nmon = f->n;
for (int i = 0; i < f->n; i++) {
@@ -321,10 +319,11 @@ int form_setup(int form, Battle *b) {
m->x = (int16_t)(xs[f->n - 1][i] + m->def->dx), m->y = (int16_t)(120 + m->def->dy);
}
/* Toriel and Flowey can't be fled from; Napstablook can */
- if (form == FORM_TORIEL || form == FORM_FLOWEY) b->no_flee = true;
+ if (form == FORM_TORIEL || form == FORM_FLOWEY || form == FORM_PAPYRUS) b->no_flee = true;
+ b->captures = form == FORM_PAPYRUS;
return 0;
}
-const char *form_text(int form) { return forms[form].text; }
+const char *form_text(int form) { return form >= FORM_RUINS_COUNT ? snow_form(form)->text : forms[form].text; }
/* ---------------------------------------------------------------- attacks */
/* the board's inside, in pixels */
@@ -644,14 +643,17 @@ static void atk_napsta_hat(int t) {
if (t == 70) bt.mon[0].spr_override = SPR_NAPSTA_HAT;
}
-static const int16_t lengths[ATK_COUNT] = {
+static const int16_t lengths[ATK_RUINS_COUNT] = {
[ATK_FROG_FLIES] = 150, [ATK_FROG_JUMP] = 150, [ATK_FROG_RAIN] = 150, [ATK_WHIM_RING] = 150, [ATK_WHIM_COLS] = 150,
[ATK_MOLD_ZIG] = 150, [ATK_MOLD_BURST] = 150, [ATK_LOOX_BOUNCE] = 160, [ATK_LOOX_WORM] = 150, [ATK_VEG_FALL] = 150,
[ATK_VEG_CARROT] = 150, [ATK_MIGOSP_ROACH] = 150, [ATK_MIGOSP_DANCE] = 180, [ATK_NAPSTA_TEARS] = 150,
[ATK_NAPSTA_WIGGLE] = 150, [ATK_NAPSTA_TEXT] = 120, [ATK_NAPSTA_HAT] = 100, [ATK_NAPSTA_FLOOD] = 150,
[ATK_TOR_HANDS] = 170, [ATK_TOR_WAVES] = 180, [ATK_TOR_HELIX] = 180, [ATK_TOR_FALTER] = 150, [ATK_IDLE] = 60,
};
-int attack_length(int atk) { return atk >= 0 && atk < ATK_COUNT && lengths[atk] ? lengths[atk] : 150; }
+int attack_length(int atk) {
+ if (atk >= ATK_RUINS_COUNT) return snow_attack_length(atk);
+ return atk >= 0 && lengths[atk] ? lengths[atk] : 150;
+}
void toriel_attack(int atk, int t); /* toriel.c */
@@ -677,7 +679,7 @@ void attack_run(Battle *b, int atk, int t) {
case ATK_NAPSTA_TEXT: atk_napsta_text(t); break;
case ATK_NAPSTA_HAT: atk_napsta_hat(t); break;
case ATK_TOR_HANDS: case ATK_TOR_WAVES: case ATK_TOR_HELIX: case ATK_TOR_FALTER: toriel_attack(atk, t); break;
- default: break;
+ default: if (atk >= ATK_RUINS_COUNT) snow_attack_run(b, atk, t); break;
}
}
@@ -694,4 +696,5 @@ void attack_draw(Battle *b, int atk, int t) {
}
}
if (atk >= ATK_TOR_HANDS && atk <= ATK_TOR_FALTER) toriel_draw_attack(atk, t);
+ if (atk >= ATK_RUINS_COUNT) snow_attack_draw(b, atk, t);
}
diff --git a/games/undertale/src/monsters.h b/games/undertale/src/monsters.h
index 68eaaa33..7820bf25 100644
--- a/games/undertale/src/monsters.h
+++ b/games/undertale/src/monsters.h
@@ -1,23 +1,49 @@
/* Undertale: the monsters, their formations and their attacks. */
#ifndef UT_MONSTERS_H
#define UT_MONSTERS_H
+#include <stdint.h>
enum {
MON_DUMMY, MON_FROGGIT_FIRST, MON_FROGGIT, MON_WHIMSUN, MON_MOLDSMAL, MON_LOOX, MON_VEGETOID, MON_MIGOSP,
- MON_NAPSTABLOOK, MON_TORIEL, MON_FLOWEY, MON_COUNT
+ MON_NAPSTABLOOK, MON_TORIEL, MON_FLOWEY, MON_RUINS_COUNT,
+ /* Snowdin (snowmon.c, papyrus.c) */
+ MON_SNOWDRAKE = MON_RUINS_COUNT, MON_ICECAP, MON_GYFTROT, MON_DOGGO, MON_LESSERDOG, MON_DOGAMY, MON_DOGARESSA,
+ MON_GREATERDOG, MON_JERRY, MON_CHILLDRAKE, MON_GLYDE, MON_PAPYRUS, MON_COUNT
};
/* formations: who is fought */
enum {
FORM_DUMMY, FORM_FROGGIT_FIRST, FORM_FROGGIT, FORM_WHIMSUN, FORM_FROGGIT_WHIMSUN, FORM_FROGGIT2, FORM_MOLDSMAL,
FORM_MOLDSMAL2, FORM_MOLDSMAL3, FORM_MOLDSMAL_MIGOSP, FORM_LOOX, FORM_LOOX2, FORM_VEGETOID, FORM_VEGETOID2,
- FORM_VEGETOID_MIGOSP, FORM_LOOX_VEG_MIGOSP, FORM_NAPSTABLOOK, FORM_TORIEL, FORM_FLOWEY, FORM_COUNT
+ FORM_VEGETOID_MIGOSP, FORM_LOOX_VEG_MIGOSP, FORM_NAPSTABLOOK, FORM_TORIEL, FORM_FLOWEY, FORM_RUINS_COUNT,
+ /* Snowdin */
+ FORM_SNOWDRAKE = FORM_RUINS_COUNT, FORM_ICECAP, FORM_LESSERDOG, FORM_CHILLDRAKE, FORM_ICECAP_JERRY,
+ FORM_ICECAP_JERRY_SNOWDRAKE, FORM_ICECAP_JERRY_CHILLDRAKE, FORM_GYFTROT, FORM_GLYDE, FORM_DOGGO, FORM_DOGI,
+ FORM_GREATERDOG, FORM_PAPYRUS, FORM_COUNT
};
enum {
ATK_NONE, ATK_FROG_FLIES, ATK_FROG_JUMP, ATK_FROG_RAIN, ATK_WHIM_RING, ATK_WHIM_COLS, ATK_MOLD_ZIG, ATK_MOLD_BURST,
ATK_LOOX_BOUNCE, ATK_LOOX_WORM, ATK_VEG_FALL, ATK_VEG_CARROT, ATK_MIGOSP_ROACH, ATK_MIGOSP_DANCE,
ATK_NAPSTA_TEARS, ATK_NAPSTA_WIGGLE, ATK_NAPSTA_TEXT, ATK_NAPSTA_HAT, ATK_NAPSTA_FLOOD,
- ATK_TOR_HANDS, ATK_TOR_WAVES, ATK_TOR_HELIX, ATK_TOR_FALTER, ATK_IDLE, ATK_COUNT
+ ATK_TOR_HANDS, ATK_TOR_WAVES, ATK_TOR_HELIX, ATK_TOR_FALTER, ATK_IDLE, ATK_RUINS_COUNT,
+ /* Snowdin */
+ ATK_DRAKE_ARCS = ATK_RUINS_COUNT, ATK_DRAKE_LINES, ATK_ICECAP_HATS, ATK_ICECAP_WAVES, ATK_GYFT_PRESENTS,
+ ATK_GYFT_SNOW, ATK_DOGGO_SWORD, ATK_LDOG_JUMP, ATK_LDOG_SPEARS, ATK_DOGI_AXES, ATK_DOGI_HEARTS, ATK_GDOG_SPEAR,
+ ATK_GDOG_BARK, ATK_GLYDE_STARS, ATK_PAP_FIRST, ATK_PAP_LAST = ATK_PAP_FIRST + 24, ATK_COUNT
};
+
+/* a formation: up to three monsters, and what the first turn says */
+typedef struct {
+ uint8_t mon[3];
+ uint8_t n;
+ const char *text;
+} Form;
+struct Battle;
+const Form *snow_form(int form); /* snowmon.c */
+const struct MonDef *snow_mon_def(int id);
+void snow_attack_run(struct Battle *b, int atk, int t);
+void snow_attack_draw(struct Battle *b, int atk, int t);
+int snow_attack_length(int atk);
+int snow_encounter(int room); /* a random encounter's formation there, -1 none */
#endif
diff --git a/games/undertale/src/papyrus.c b/games/undertale/src/papyrus.c
new file mode 100644
index 00000000..d9cecd34
--- /dev/null
+++ b/games/undertale/src/papyrus.c
@@ -0,0 +1,222 @@
+/* Papyrus, Snowdin's boss: his bones, the blue SOUL he gives you, his special attack and the dog that steals
+ * it (as the Undertale Wiki describes the fight). He never kills you: he captures you (the battle ends,
+ * snowtown.c takes it from there). */
+#include <stdio.h>
+#include <string.h>
+#include "battle.h"
+#include "game.h"
+#include "gfx.h"
+#include "monsters.h"
+#include "res.h"
+
+/* b->state[0]: 0 before he's FOUGHT or spared, 1 the blue attack next, 2 blue; [1] flirts, [2] insults;
+ * [3] blue turns; [4] FOUGHT (1) or spared (2) first; [5] he spares you; [6] his speech this turn */
+enum { PAP_RED, PAP_BLUE_NEXT, PAP_BLUE };
+
+static const char *const turn_lines[] = {
+ "BEHOLD!", "AND I HAVE A\n#RSPECIAL\nATTACK#X TOO!", "I CAN ALMOST\nHEAR THE\nCHEERING!!!", "PAPYRUS,\nROYAL\nGUARD!", "PAPYRUS,\nPASTA\nMASTER!",
+ "UNDYNE WILL\nBE SO\nPROUD!!", "THEY'LL MAKE\nA STATUE OF\nME! A BIG\nONE!!!", "SANS WILL...\nPROBABLY\nNAP THROUGH\nIT.",
+ "SO MANY\nFANS!!\nBUT...", "WILL THEY\nLIKE THE\nREAL ME???", "YOU'RE NOT\nLIKE MOST\nPEOPLE...", "ONCE YOU'RE\nCAPTURED...",
+ "THEY WON'T\nLET YOU\nGO, WILL\nTHEY...", "NO! GIVE UP\nALREADY!!", "OR FACE MY\n#RSPECIAL\nATTACK#X!!!", "IT'S COMING\nSOON! MY\n#RSPECIAL\nATTACK#X!",
+ "ANY TURN NOW\nTHE #RSPECIAL\nATTACK#X!!!", "LAST CHANCE\nBEFORE MY\n#RSPECIAL\nATTACK#X!!"};
+#define NTURNS (int)(sizeof turn_lines / sizeof turn_lines[0])
+#define SPECIAL_TURN NTURNS /* the dog steals it */
+#define NORMAL_TURN (NTURNS + 1)
+
+static void act_papyrus(Battle *b, Monster *m, int act, char *t, int cap) {
+ (void)m;
+ if (b->state[0] == PAP_BLUE) {
+ snprintf(t, (size_t)cap, act == 0 ? "* Papyrus is too busy FIGHTing to flirt back." : "* Papyrus is too busy FIGHTing to accept your insult.");
+ return;
+ }
+ if (act == 0) {
+ b->state[1]++;
+ snprintf(t, (size_t)cap, b->state[1] >= 3 ? "* You FLIRT, but to no avail.\n* Seems ACTing won't escalate this battle..." : "* You flirt with Papyrus.");
+ } else {
+ b->state[2]++;
+ snprintf(t, (size_t)cap, b->state[2] >= 4 ? "* You INSULT, but to no avail.\n* Seems ACTing won't escalate this battle..." : "* You insult Papyrus.");
+ }
+ b->state[6] = act + 1;
+}
+
+static const char *talk_papyrus(Battle *b, Monster *m) {
+ (void)m;
+ int said = b->state[6];
+ b->state[6] = 0;
+ /* the first FIGHT or MERCY: the blue attack comes */
+ if (b->state[0] == PAP_RED && (b->last_action == 0 || b->last_action == 3)) {
+ b->state[0] = PAP_BLUE_NEXT;
+ return b->last_action == 0 ? "OH, A FIGHT,\nIS IT?|THEN TRY MY\nLEGENDARY\nBLUE ATTACK!"
+ : "NO FIGHTING?\nHMPH!|THEN TRY MY\nLEGENDARY\nBLUE ATTACK!";
+ }
+ if (b->last_action == 2 && b->state[0] != PAP_BLUE) return "OOH, SNACKS!\nI SHOULD HAVE\nPACKED SOME.";
+ if (said == 1) {
+ if (b->state[1] == 1) return "FL-FLIRTING!?|I HAVE VERY\nHIGH\nSTANDARDS!!!|A DATE...\nAFTER THE\nCAPTURE!";
+ return "AFTER THE\nCAPTURE! THEN\nWE'LL SEE!";
+ }
+ if (said == 2) {
+ if (b->state[2] == 1) return "AH, I SEE!|YOU'RE BEING\nMEAN SO I\nFEEL OKAY\nFIGHTING YOU!";
+ if (b->state[2] == 2) return "PRICKLY\nOUTSIDE, SOFT\nINSIDE!\nLIKE A\nCACTUS!";
+ return "SAVE YOUR\nBREATH!";
+ }
+ if (b->state[0] != PAP_BLUE) return b->state[0] == PAP_RED ? "NYEH HEH\nHEH!" : NULL;
+ /* his absolutely normal attack done: he spares you (and one hit would end him now) */
+ if (m->state == 1) {
+ b->state[5] = 1, m->spare = true, m->state = 2;
+ m->df = (int16_t)(-2 * m->hp);
+ return "*HUFF*\nYOU CAN'T\nBEAT ME!\n*HUFF*|SO I'LL BE\nGENEROUS...|I #RSPARE#X\nYOU, HUMAN!|ACCEPT MY\n#RMERCY#X!";
+ }
+ if (b->state[5]) return NULL;
+ int k = b->state[3];
+ if (k < NTURNS) return turn_lines[k];
+ if (k == SPECIAL_TURN)
+ return "AND NOW...\nMY #RSPECIAL\nATTACK#X!|HEY!!!|THE DOG TOOK\nIT!!!|...|FINE. A\nREGULAR\nATTACK,\nTHEN.";
+ if (k == NORMAL_TURN) return "*SIGH*\nA PERFECTLY\nORDINARY\nATTACK.";
+ return NULL;
+}
+
+static const char *flavor_papyrus(Battle *b, Monster *m) {
+ (void)m;
+ if (b->state[5]) return "* Papyrus is sparing you.";
+ if (b->state[0] == PAP_BLUE && b->state[3] == 1) return "* You're blue now.";
+ if (b->state[3] > SPECIAL_TURN) return "* Papyrus is getting ready for a regular attack.";
+ if (b->state[1] && b->state[0] != PAP_BLUE) return "* Papyrus is thinking about what to wear for his date.";
+ return NULL;
+}
+
+static int attack_papyrus(Battle *b, Monster *m) {
+ if (b->state[5]) return -1;
+ if (b->state[0] == PAP_RED) return ATK_PAP_FIRST; /* bones low along the floor */
+ if (b->state[0] == PAP_BLUE_NEXT) {
+ b->state[0] = PAP_BLUE, b->state[3] = 0;
+ return ATK_PAP_FIRST + 1; /* the blue attack, then the SOUL goes blue */
+ }
+ int k = ++b->state[3];
+ if (k == SPECIAL_TURN) return ATK_PAP_FIRST + 9; /* the dog */
+ if (k == NORMAL_TURN) {
+ m->state = 1; /* (after it, he spares you) */
+ return ATK_PAP_FIRST + 10;
+ }
+ if (k <= 6) return ATK_PAP_FIRST + 1 + k; /* the wiki's patterns, in order */
+ return ATK_PAP_FIRST + 3 + rnd_n(6);
+}
+
+static bool hit_papyrus(Battle *b, Monster *m, int dmg) {
+ (void)b;
+ if (b->state[0] == PAP_RED) b->state[4] = 1;
+ (void)m, (void)dmg;
+ return false;
+}
+
+const MonDef papyrus_def = {
+ .name = "Papyrus", .hp = 680, .at = 8, .df = 2, .exp = 200, .gold = 0, .spr_idle = SPR_PAPYRUS_B,
+ .spr_hurt = SPR_PAPYRUS_HURT, .check = "He likes to say:\n* \"Nyeh heh heh!\"", .acts = {"Flirt", "Insult"}, .nacts = 2,
+ .neutral = {"* Papyrus is preparing a bone attack.", "* Papyrus is cackling.", "* Papyrus whispers \"Nyeh heh heh!\"",
+ "* Papyrus is rattling his bones.", "* Papyrus is trying hard to play it cool.",
+ "* Papyrus is considering his options."},
+ .flags = MF_BOSS, .act = act_papyrus, .talk = talk_papyrus, .attack = attack_papyrus, .flavor = flavor_papyrus,
+ .on_hit = hit_papyrus,
+};
+
+/* ---------------------------------------------------------------- his bones */
+#define P(v) ((v) * FX)
+static int bx0(void) { return bt.x0 + 3; }
+static int bx1(void) { return bt.x1 - 3; }
+static int by0(void) { return bt.y0 + 3; }
+static int by1(void) { return bt.y1 - 3; }
+
+/* a bone of a pattern: when (frames), how tall (from the floor, or hanging from the ceiling when negative),
+ * blue, fast, and from the right instead of the left */
+typedef struct {
+ uint16_t at;
+ uint8_t h, ceil, blue, fast, right;
+} Bone;
+static void bone(const Bone *k) {
+ bool right = k->right;
+ int sp = k->fast ? P(4) : P(2);
+ int y = k->ceil ? by0() + k->h / 2 : by1() - k->h / 2;
+ Bullet *b = bullet_new(SPR_BONE, P(right ? bx1() + 4 : bx0() - 4), P(y), right ? -sp : sp, 0);
+ if (!b) return;
+ b->flags |= BF_BOX, b->w = 5, b->h = k->h, b->owner = (uint8_t)bt.atk_owner;
+ if (k->blue) b->color = BC_BLUE;
+}
+
+/* the patterns (heights halved from the game's: small 10, medium 20, large 30): a floor bone F, one hanging from
+ * the ceiling C, a blue one BL, from the right R (C from the right: RC), fast from the right FR */
+#define F(at, h) {at, h, 0, 0, 0, 0}
+#define C(at, h) {at, h, 1, 0, 0, 0}
+#define BL(at) {at, 60, 0, 1, 0, 0}
+#define R(at, h) {at, h, 0, 0, 0, 1}
+#define RC(at, h) {at, h, 1, 0, 0, 1}
+#define FR(at, h) {at, h, 0, 0, 1, 1}
+static const Bone pat_red[] = {F(0, 8), F(16, 10), F(32, 12), F(48, 14), F(64, 16), F(80, 14), F(96, 12), F(112, 10), F(128, 8)};
+static const Bone pat_blue[] = {BL(0), BL(20), BL(40), BL(60), F(120, 10)};
+static const Bone pat_2[] = {F(0, 10), F(20, 10), F(40, 10), F(60, 10), F(90, 20)};
+static const Bone pat_3[] = {F(0, 10), F(30, 20), F(55, 20), F(80, 20), F(110, 30), F(140, 30), F(170, 30)};
+static const Bone pat_4[] = {F(0, 30), C(40, 30), F(70, 10), F(85, 10), F(100, 10), F(125, 20), C(160, 30)};
+static const Bone pat_5[] = {F(0, 30), F(35, 30), F(70, 30), BL(105), FR(140, 10)};
+static const Bone pat_6[] = {F(0, 12), C(0, 30), F(40, 12), C(40, 30), RC(80, 30), F(120, 8), F(126, 12), F(132, 16),
+ F(138, 20), F(144, 20), F(150, 16), F(156, 12), F(162, 8)};
+static const Bone pat_7[] = {F(0, 12), C(0, 30), F(25, 12), C(25, 30), F(60, 22), C(60, 22), F(85, 22), C(85, 22), BL(120),
+ R(150, 30), F(185, 12), C(185, 30), R(185, 12), RC(185, 30)};
+static const Bone pat_normal[] = {F(0, 10), F(15, 10), F(30, 20), F(50, 30), C(70, 30), FR(95, 10), F(110, 20), BL(125),
+ F(150, 12), C(150, 30), F(175, 12), C(175, 30), F(205, 8), F(210, 12), F(215, 16),
+ F(220, 20), F(225, 24), F(230, 20), F(235, 16), F(240, 12), F(245, 8), F(275, 30),
+ FR(300, 30), F(320, 10), F(330, 10), F(340, 10), F(350, 10)};
+typedef struct {
+ const Bone *bones;
+ int n, len;
+} Pattern;
+#define PAT(a, len) {a, (int)(sizeof a / sizeof a[0]), len}
+static const Pattern pats[] = {
+ PAT(pat_red, 200), PAT(pat_blue, 200), PAT(pat_2, 170), PAT(pat_3, 250), PAT(pat_4, 240), PAT(pat_5, 220),
+ PAT(pat_6, 240), PAT(pat_7, 270), PAT(pat_2, 170), {NULL, 0, 220}, PAT(pat_normal, 420)};
+
+int papyrus_attack_length(int atk) { return pats[atk - ATK_PAP_FIRST].len; }
+
+void papyrus_attack(int atk, int t) {
+ int k = atk - ATK_PAP_FIRST;
+ if (t == 0) {
+ /* his board: wide and low; the SOUL on the floor once it's blue */
+ if (k == 0) board_set(110, 60);
+ else board_set(140, 60);
+ if (k >= 2) soul_set_mode(SOUL_BLUE);
+ if (bt.soul_mode == SOUL_BLUE) bt.sy = P(by1() - 3);
+ }
+ if (k == 1 && t == 100) { /* the blue bones passed: now your SOUL's blue */
+ soul_set_mode(SOUL_BLUE);
+ }
+ const Pattern *p = &pats[k];
+ for (int i = 0; i < p->n; i++)
+ if (p->bones[i].at == t) bone(&p->bones[i]);
+ /* the dog: it trots in, takes the special attack's bone and runs off with it (harmless) */
+ if (k == 9) {
+ if (t == 20) {
+ Bullet *b = bullet_new(SPR_BONE, P((bx0() + bx1()) / 2), P(by1() - 12), 0, 0);
+ if (b) b->flags |= BF_BOX | BF_HARMLESS, b->w = 24, b->h = 6, b->kind = BK_SCRIPT, b->a = 1;
+ }
+ if (t == 60) {
+ Bullet *d = bullet_new(SPR_DOG_OW, P(bx1() + 10), P(by1() - 6), -P(1), 0);
+ if (d) d->flags |= BF_HARMLESS, d->anim = 6;
+ }
+ for (int i = 0; i < MAX_BULLETS; i++) {
+ Bullet *d = &bullets[i];
+ if (d->spr != SPR_DOG_OW || d->kind == BK_NONE) continue;
+ /* at the bone: it takes it and goes the other way */
+ if (d->vx < 0 && d->x <= P((bx0() + bx1()) / 2 + 6)) {
+ d->vx = P(2), d->spr = SPR_DOG_BONE;
+ for (int j = 0; j < MAX_BULLETS; j++)
+ if (bullets[j].kind == BK_SCRIPT && bullets[j].a == 1) bullets[j].kind = BK_NONE;
+ }
+ }
+ }
+ /* the normal attack's dog: it runs across, and it hurts */
+ if (k == 10 && t == 260) {
+ Bullet *d = bullet_new(SPR_DOG_OW, P(bx0() - 10), P(by1() - 6), P(3), 0);
+ if (d) d->owner = (uint8_t)bt.atk_owner, d->dmg = 3, d->r = 6, d->anim = 4;
+ }
+}
+
+void papyrus_attack_draw(int atk, int t) {
+ (void)atk, (void)t;
+}
diff --git a/games/undertale/src/res.c b/games/undertale/src/res.c
index 575c3a44..e81f146b 100644
--- a/games/undertale/src/res.c
+++ b/games/undertale/src/res.c
@@ -1,4 +1,5 @@
/* data.bin: sections, sprites, tiles, rooms and strings (see res.h). */
+#include <stddef.h>
#include "res.h"
const uint8_t *ut_bin;
@@ -56,6 +57,7 @@ void room_info(int room, RoomInfo *r) {
r->cw = rd16(p + 24), r->ch = rd16(p + 26);
r->area = p[28], r->flags = p[29];
r->name = rd16(p + 30);
+ r->ice = (r->flags & ROOM_ICE) ? r->coll + ((r->cw + 7) >> 3) * r->ch : NULL;
}
const char *str(uint16_t id) {
diff --git a/games/undertale/src/res.h b/games/undertale/src/res.h
index 8fa4a1e6..558cae8d 100644
--- a/games/undertale/src/res.h
+++ b/games/undertale/src/res.h
@@ -46,16 +46,19 @@ typedef struct {
uint16_t cw, ch; /* 4-pixel cells over the rectangle */
uint8_t area, flags;
uint16_t name; /* string: what SAVE shows */
+ const uint8_t *ice; /* the same bits for ice (Frisk slides), NULL none */
} RoomInfo;
+#define ROOM_ICE 1
void room_info(int room, RoomInfo *r);
/* a door of a room: walking into its rectangle takes Frisk to another room */
typedef struct {
int16_t x, y, w, h;
uint16_t room;
- int16_t tx, ty;
+ int16_t tx, ty; /* where Frisk lands; DOOR_KEEP: where he is */
uint16_t dir;
} Door;
+#define DOOR_KEEP (-32768)
int room_doors(int room, Door *out, int max);
const char *str(uint16_t id);
diff --git a/games/undertale/src/rooms.c b/games/undertale/src/rooms.c
index fe113eaa..2f8cf1f0 100644
--- a/games/undertale/src/rooms.c
+++ b/games/undertale/src/rooms.c
@@ -6,17 +6,37 @@
#include "game.h"
#include "monsters.h"
#include "ruins.h"
+#include "snowdin.h"
#include "world.h"
void room_setup(int room, int from) {
ruins1_setup(room, from);
ruins2_setup(room, from);
ruins3_setup(room, from);
+ snow1_setup(room, from);
+ snow2_setup(room, from);
+ town_setup(room, from);
}
/* each frame Frisk can walk: what a room watches (a rock on its switch, a cracked floor) */
void room_update(void) {
ruins2_update();
+ snow1_update();
+ snow2_update();
+}
+
+/* what a room draws on its floor, under everything (world.c) */
+void room_draw_floor(void) {
+ snow1_draw();
+ snow2_draw();
+}
+
+bool room_ice(int x, int y) {
+ const RoomInfo *ri = world_room_info();
+ if (!ri || !ri->ice) return false;
+ int cx = (x - ri->x) >> 2, cy = (y - ri->y) >> 2;
+ if (cx < 0 || cy < 0 || cx >= ri->cw || cy >= ri->ch) return false;
+ return ri->ice[cy * ((ri->cw + 7) >> 3) + (cx >> 3)] >> (cx & 7) & 1;
}
/* random encounters: a room's formations and how many steps between them (the game counts its steps,
@@ -47,9 +67,11 @@ void encounter_step(void) {
const Encounters *e = NULL;
for (unsigned i = 0; i < sizeof enc / sizeof enc[0]; i++)
if (enc[i].room == g_room) e = &enc[i];
- if (!e) return;
+ /* Snowdin's are snowmon.c's (who comes depends on what's happened) */
+ int snow = e ? -1 : snow_encounter(g_room);
+ if (!e && snow < 0) return;
if (--steps_left > 0) return;
steps_left = 100 + rnd_n(200);
event_start(EV_ENCOUNTER, NULL);
- event_cur_arg(e->forms[rnd_n(e->n)]);
+ event_cur_arg(e ? e->forms[rnd_n(e->n)] : snow);
}
diff --git a/games/undertale/src/ruins3.c b/games/undertale/src/ruins3.c
index e2ccb720..4a6562d8 100644
--- a/games/undertale/src/ruins3.c
+++ b/games/undertale/src/ruins3.c
@@ -297,10 +297,10 @@ static int ev_flowey_end(Ev *c) {
/* the door out of the Ruins: the rest of the underground is still to come */
static int ev_ruins_door(Ev *c) {
EV_BEGIN;
+ /* out of the Ruins: Snowdin's snow */
set_flag(F_RUINS_EXIT, 1);
- sv.room = (int16_t)g_room, sv.x = pl.x, sv.y = (int16_t)(pl.y + 30);
- save_write_auto();
- menu_end_open();
+ world_fade_hold(ROOM_SNOWDIN1, 34, 392, DIR_DOWN, 20);
+ WAIT_UNTIL(!world_fading());
EV_END;
}
diff --git a/games/undertale/src/shop.c b/games/undertale/src/shop.c
new file mode 100644
index 00000000..4686cbdc
--- /dev/null
+++ b/games/undertale/src/shop.c
@@ -0,0 +1,241 @@
+/* Shops, as the game shows them: the keeper's picture over a text box and Buy, Sell, Talk, Exit; and the
+ * Dimensional Box (an inventory you leave items in). Both are their own mode (MODE_SHOP). */
+#include <stdio.h>
+#include <string.h>
+#include "event.h"
+#include "game.h"
+#include "gfx.h"
+#include "items.h"
+#include "res.h"
+#include "shop.h"
+#include "text.h"
+
+typedef struct {
+ uint8_t item;
+ uint8_t price;
+} Ware;
+typedef struct {
+ uint16_t pic;
+ const char *hello, *again, *buying, *bought, *poor, *full, *nobuy, *sell;
+ Ware wares[4];
+ int nwares;
+ const char *topics[4];
+ const char *answers[4];
+ int ntopics;
+} Shop;
+
+static const Shop shops[SHOP_COUNT] = {
+ [SHOP_SNOWDIN] = {
+ .pic = SPR_SHOP_QC, .hello = "* Hello, traveller.\n* How can I help you?", .again = "* Take your time.",
+ .buying = "What would\nyou like\nto buy?", .bought = "Thanks for\nyour purchase.", .poor = "That's not\nenough money.",
+ .full = "You're\ncarrying\ntoo much.", .nobuy = "Just\nlooking?",
+ .sell = "* Huh? Sell somethin'?\n* Does this look like a pawn shop?",
+ .wares = {{ITEM_TOUGH_GLOVE, 50}, {ITEM_MANLY_BANDANNA, 50}, {ITEM_BISICLE, 15}, {ITEM_CINNAMON_BUNNY, 25}}, .nwares = 4,
+ .topics = {"Say hello", "What to do here", "Town history", "Your life"},
+ .answers = {"* Hello! Welcome to Snowdin!\n* I can't remember the last time I saw a new face around here.",
+ "* If you're tired, the inn's right next door. My sister runs it.|* And there's Grillby's, if you're hungry.",
+ "* Long ago, monsters lived in the RUINS back there.|* When we came here, the cold made it easy to get used to the snow.",
+ "* Life is the same as usual.\n* A little cold, though..."},
+ .ntopics = 4},
+};
+
+static int shop_id, st, sel, sub;
+static Writer w;
+static char buf[300];
+static const char *right_text;
+static bool is_box;
+enum { S_MENU, S_BUY, S_CONFIRM, S_TALK, S_SAY };
+
+static void left_say(const char *s) {
+ snprintf(buf, sizeof buf, "%s", s);
+ text_wrap_width(190);
+ writer_start(&w, buf, 12, 133, FONT_MAIN);
+ w.line_h = 16;
+}
+
+void shop_open(int id) {
+ shop_id = id, is_box = false;
+ st = S_MENU, sel = 0, sub = 0, right_text = NULL;
+ left_say(shops[id].hello);
+ g_mode = MODE_SHOP;
+}
+
+/* the Bisicle costs more after each boss fought (the game's 15G and up) */
+static int price_of(const Ware *wa) {
+ if (wa->item == ITEM_BISICLE) return min_i(70, wa->price + 5 * flag(F_SNOWDIN_BOSSES));
+ return wa->price;
+}
+
+/* ---------------------------------------------------------------- the Dimensional Box */
+#define BOX_SLOTS 10
+void box_open(void) {
+ is_box = true, sel = 0, sub = 0;
+ g_mode = MODE_SHOP;
+}
+static int box_item(int i) { return flag(F_BOX0 + i); }
+
+static void box_update(uint32_t pressed) {
+ int n = sub ? BOX_SLOTS : NUM_ITEMS;
+ if (pressed & K_UP) sel = (sel + n - 1) % n;
+ if (pressed & K_DOWN) sel = (sel + 1) % n;
+ if (pressed & (K_LEFT | K_RIGHT)) sub = !sub, sel = min_i(sel, (sub ? BOX_SLOTS : NUM_ITEMS) - 1);
+ if (pressed & K_Z) {
+ if (!sub && sv.items[sel]) {
+ for (int i = 0; i < BOX_SLOTS; i++)
+ if (!box_item(i)) {
+ set_flag(F_BOX0 + i, sv.items[sel]);
+ item_remove_at(sel);
+ break;
+ }
+ } else if (sub && box_item(sel) && item_add(box_item(sel))) {
+ /* the box keeps its order: the ones after move up */
+ for (int i = sel; i < BOX_SLOTS - 1; i++) set_flag(F_BOX0 + i, box_item(i + 1));
+ set_flag(F_BOX0 + BOX_SLOTS - 1, 0);
+ }
+ }
+ if (pressed & K_X) g_mode = MODE_WORLD;
+}
+
+static void panel(int x, int y, int w_, int h) {
+ gfx_rect(x, y, w_, h, C_BLACK, 255);
+ gfx_frame_rect(x, y, w_, h, 3, C_WHITE);
+}
+
+static void box_draw(void) {
+ gfx_rect(0, 0, SCREEN_W, SCREEN_H, C_BLACK, 255);
+ panel(8, 8, 304, 224);
+ gfx_text(FONT_MENU, 50, 18, "INVENTORY", C_WHITE, 255);
+ gfx_text(FONT_MENU, 210, 18, "BOX", C_WHITE, 255);
+ gfx_line(160, 20, 160, 210, C_WHITE);
+ for (int i = 0; i < NUM_ITEMS; i++) {
+ const char *nm = sv.items[i] ? item_info(sv.items[i])->name : "";
+ if (sv.items[i]) gfx_text(FONT_MENU, 36, 40 + i * 20, nm, C_WHITE, 255);
+ else gfx_rect(36, 48 + i * 20, 100, 1, rgb565(0xC00000), 255);
+ }
+ for (int i = 0; i < BOX_SLOTS; i++) {
+ if (box_item(i)) gfx_text(FONT_MENU, 190, 36 + i * 17, item_info(box_item(i))->name, C_WHITE, 255);
+ else gfx_rect(190, 44 + i * 17, 100, 1, rgb565(0xC00000), 255);
+ }
+ gfx_sprite(SPR_HEART, 0, sub ? 180 : 26, sub ? 42 + sel * 17 : 46 + sel * 20, 0, 255);
+ gfx_text(FONT_MENU, 120, 214, "Press [X] to Finish", C_WHITE, 255);
+}
+
+/* ---------------------------------------------------------------- the shop */
+void shop_update(uint32_t keys, uint32_t pressed) {
+ (void)keys;
+ if (is_box) {
+ box_update(pressed);
+ return;
+ }
+ const Shop *s = &shops[shop_id];
+ bool typing = writer_update(&w, st == S_SAY ? pressed : 0);
+ switch (st) {
+ case S_MENU:
+ if (pressed & K_UP) sel = (sel + 3) % 4;
+ if (pressed & K_DOWN) sel = (sel + 1) % 4;
+ if (pressed & K_Z) {
+ if (sel == 0) st = S_BUY, sub = 0, right_text = s->buying;
+ else if (sel == 1) st = S_SAY, left_say(s->sell);
+ else if (sel == 2) st = S_TALK, sub = 0;
+ else g_mode = MODE_WORLD;
+ }
+ break;
+ case S_BUY:
+ if (pressed & K_UP) sub = (sub + s->nwares) % (s->nwares + 1);
+ if (pressed & K_DOWN) sub = (sub + 1) % (s->nwares + 1);
+ if (pressed & K_X || ((pressed & K_Z) && sub == s->nwares)) {
+ st = S_MENU, left_say(s->again);
+ break;
+ }
+ if (pressed & K_Z) st = S_CONFIRM, sel = 0;
+ break;
+ case S_CONFIRM:
+ if (pressed & (K_UP | K_DOWN)) sel = !sel;
+ if (pressed & K_X) st = S_BUY, right_text = s->nobuy;
+ else if (pressed & K_Z) {
+ const Ware *wa = &s->wares[sub];
+ if (sel == 1) right_text = s->nobuy;
+ else if (sv.gold < price_of(wa)) right_text = s->poor;
+ else if (!item_add(wa->item)) right_text = s->full;
+ else sv.gold = (uint16_t)(sv.gold - price_of(wa)), right_text = s->bought;
+ st = S_BUY;
+ }
+ break;
+ case S_TALK:
+ if (pressed & K_UP) sub = (sub + s->ntopics) % (s->ntopics + 1);
+ if (pressed & K_DOWN) sub = (sub + 1) % (s->ntopics + 1);
+ if (pressed & K_X || ((pressed & K_Z) && sub == s->ntopics)) {
+ st = S_MENU, left_say(s->again);
+ break;
+ }
+ if (pressed & K_Z) st = S_SAY, left_say(s->answers[sub]);
+ break;
+ case S_SAY:
+ if (!typing) st = S_MENU, left_say(s->again);
+ break;
+ }
+}
+
+static void wares_list(const Shop *s, bool topics) {
+ int n = topics ? s->ntopics : s->nwares;
+ for (int i = 0; i <= n; i++) {
+ char line[48];
+ if (i == n) snprintf(line, sizeof line, "Exit");
+ else if (topics) snprintf(line, sizeof line, "%s", s->topics[i]);
+ else snprintf(line, sizeof line, "%dG - %s", price_of(&s->wares[i]), item_info(s->wares[i].item)->name);
+ gfx_text(FONT_MAIN, 30, 132 + i * 18, line, C_WHITE, 255);
+ }
+ if (!(st == S_CONFIRM)) gfx_sprite(SPR_HEART, 0, 20, 140 + sub * 18, 0, 255);
+}
+
+void shop_draw(void) {
+ if (is_box) {
+ box_draw();
+ return;
+ }
+ const Shop *s = &shops[shop_id];
+ gfx_rect(0, 0, SCREEN_W, SCREEN_H, C_BLACK, 255);
+ gfx_sprite(s->pic, 0, 0, 0, 0, 255);
+ panel(2, 121, 210, 117);
+ panel(212, 121, 106, 117);
+ char g[24];
+ snprintf(g, sizeof g, "%dG", sv.gold);
+ gfx_text(FONT_MAIN, 226, 214, g, C_WHITE, 255);
+ snprintf(g, sizeof g, "%d/8", item_count());
+ gfx_text(FONT_MAIN, 276, 214, g, C_WHITE, 255);
+ if (st == S_MENU || st == S_SAY) {
+ writer_draw(&w, C_WHITE);
+ static const char *const opts[] = {"Buy", "Sell", "Talk", "Exit"};
+ for (int i = 0; i < 4; i++) gfx_text(FONT_MAIN, 238, 132 + i * 20, opts[i], C_WHITE, 255);
+ if (st == S_MENU) gfx_sprite(SPR_HEART, 0, 228, 140 + sel * 20, 0, 255);
+ return;
+ }
+ wares_list(s, st == S_TALK);
+ if (st == S_CONFIRM) {
+ char q[40];
+ snprintf(q, sizeof q, "Buy it for\n%dG?", price_of(&s->wares[sub]));
+ gfx_text(FONT_MAIN, 222, 132, q, C_WHITE, 255);
+ gfx_text(FONT_MAIN, 238, 172, "Yes", C_WHITE, 255);
+ gfx_text(FONT_MAIN, 238, 190, "No", C_WHITE, 255);
+ gfx_sprite(SPR_HEART, 0, 228, 180 + sel * 18, 0, 255);
+ } else if (st == S_BUY) {
+ if (sub < s->nwares) {
+ /* what the item is: its kind and what it does */
+ const ItemInfo *it = item_info(s->wares[sub].item);
+ char info[64];
+ if (it->type == IT_WEAPON) snprintf(info, sizeof info, "Weapon:\nAT %d", it->at);
+ else if (it->type == IT_ARMOR) snprintf(info, sizeof info, "Armor:\nDF %d", it->df);
+ else snprintf(info, sizeof info, "Heals\n%d HP", it->heal);
+ gfx_text(FONT_MAIN, 222, 172, info, C_WHITE, 255);
+ }
+ if (right_text) gfx_text(FONT_SMALL, 222, 130, right_text, C_WHITE, 255);
+ }
+}
+
+/* the Dimensional Box as an event: it opens, and the event waits for it to close */
+int box_menu(Ev *c) {
+ EV_BEGIN;
+ box_open();
+ WAIT_UNTIL(g_mode == MODE_WORLD);
+ EV_END;
+}
diff --git a/games/undertale/src/shop.h b/games/undertale/src/shop.h
new file mode 100644
index 00000000..2d2bd970
--- /dev/null
+++ b/games/undertale/src/shop.h
@@ -0,0 +1,10 @@
+/* Undertale: shops and the Dimensional Box (shop.c). */
+#ifndef UT_SHOP_H
+#define UT_SHOP_H
+#include <stdint.h>
+enum { SHOP_SNOWDIN, SHOP_COUNT };
+void shop_open(int id); /* MODE_SHOP until Exit */
+void box_open(void);
+void shop_update(uint32_t keys, uint32_t pressed);
+void shop_draw(void);
+#endif
diff --git a/games/undertale/src/snowdin.h b/games/undertale/src/snowdin.h
new file mode 100644
index 00000000..26860774
--- /dev/null
+++ b/games/undertale/src/snowdin.h
@@ -0,0 +1,25 @@
+/* Undertale: Snowdin, the forest (snowdin1.c, snowdin2.c) and the town (snowtown.c), its monsters (snowmon.c),
+ * Papyrus (papyrus.c), the shops (shop.c). */
+#ifndef UT_SNOWDIN_H
+#define UT_SNOWDIN_H
+#include "event.h"
+void snow1_setup(int room, int from);
+int snow1_event(Ev *c); /* -1: not one of its */
+void snow1_update(void);
+void snow1_draw(void); /* what its rooms draw over the floor (footprints, the tiles) */
+void snow2_setup(int room, int from);
+int snow2_event(Ev *c);
+void snow2_update(void);
+void snow2_draw(void);
+void town_setup(int room, int from);
+int town_event(Ev *c);
+void snow_doggo_stick(void);
+void snow_battle_done(int form); /* snowmon.c: who was killed, who met */ /* Doggo was spared with the stick (his talk after) */
+/* Sans and Papyrus, their feet at (x, y) */
+Obj *obj_sans(int x, int y, int dir);
+Obj *obj_papyrus(int x, int y, int dir);
+/* the camera moves to (x, y) (its top-left), sp pixels a frame; true once there (it stays until world_enter or
+ * cam_free) */
+bool cam_pan(int x, int y, int sp);
+void cam_free(void);
+#endif
diff --git a/games/undertale/src/snowdin1.c b/games/undertale/src/snowdin1.c
new file mode 100644
index 00000000..b2e16c29
--- /dev/null
+++ b/games/undertale/src/snowdin1.c
@@ -0,0 +1,611 @@
+/* Snowdin Forest, from the Ruins' door to the word search: Sans and his brother Papyrus, Doggo, the ice, the
+ * Snowman, the Invisible Electricity Maze, the Ball Game, the Nice Cream guy. Signs and short lines are the
+ * game's (as the Undertale Wiki records them); the longer talks are kept short. */
+#include <stdio.h>
+#include <string.h>
+#include "battle.h"
+#include "event.h"
+#include "events.h"
+#include "game.h"
+#include "gfx.h"
+#include "items.h"
+#include "monsters.h"
+#include "snowdin.h"
+#include "world.h"
+
+/* ---------------------------------------------------------------- Sans and Papyrus */
+Obj *obj_sans(int x, int y, int dir) {
+ static const uint16_t s[4] = {SPR_SANS_D};
+ Obj *o = obj_npc(ACTOR_SANS, s, x, y, dir, 0);
+ if (o) o->flags &= (uint16_t)~OF_WALKANIM;
+ return o;
+}
+Obj *obj_papyrus(int x, int y, int dir) {
+ static const uint16_t s[4] = {SPR_PAPYRUS_D, SPR_PAPYRUS_D, SPR_PAPYRUS_L, SPR_PAPYRUS_R};
+ Obj *o = obj_npc(ACTOR_PAPYRUS, s, x, y, dir, 0);
+ if (o) o->anim_speed = 4;
+ return o;
+}
+static void gone(Obj *o) { o->kind = OBJ_NONE; }
+
+/* ---------------------------------------------------------------- the electricity maze */
+/* its path (the feet's middle), from the entrance to Papyrus at the exit */
+static const int16_t maze_path[][2] = {{5280, 380}, {5340, 380}, {5340, 340}, {5400, 340}, {5400, 440}, {5470, 440}};
+#define MAZE_POINTS 6
+/* the invisible walls: the maze's box but the path, 26 pixels wide */
+static const int16_t maze_walls[][4] = {
+ {5280, 270, 190, 57}, {5280, 327, 47, 40}, {5280, 393, 107, 73}, {5353, 353, 34, 40}, {5413, 327, 57, 100},
+ {5387, 453, 83, 13}};
+static int maze_prints; /* how far back from the exit Papyrus's footprints go (pixels) */
+static bool maze_growing; /* he's walking it, leaving them */
+static int maze_len(void) {
+ int n = 0;
+ for (int i = 1; i < MAZE_POINTS; i++)
+ n += abs_i(maze_path[i][0] - maze_path[i - 1][0]) + abs_i(maze_path[i][1] - maze_path[i - 1][1]);
+ return n;
+}
+
+/* ---------------------------------------------------------------- the Ball Game */
+#define BALL_X 5890
+#define BALL_Y 352
+#define HOLE_X 5961
+#define HOLE_Y 690
+static struct {
+ int vx, vy; /* 1/16 px a frame */
+ int t; /* frames since first kicked (0: not yet) */
+ bool sunk;
+} ball;
+
+static void ball_place(Obj *b) {
+ b->x = BALL_X, b->y = BALL_Y, b->frame = 0;
+ obj_set_box(b, -9, -9, 18, 18);
+ ball.vx = ball.vy = 0, ball.t = 0, ball.sunk = false;
+}
+
+static void ball_update(void) {
+ Obj *b = obj_find(ACTOR_BALL);
+ if (!b || ball.sunk) return;
+ int r = 10 - b->frame;
+ /* Frisk walking into it kicks it the way he faces */
+ int fx = pl.x + 3, fy = pl.y + 20;
+ if (pl.moving && fx < b->x + r + 2 && fx + 14 > b->x - r - 2 && fy < b->y + r + 2 && fy + 9 > b->y - r - 2) {
+ static const int8_t dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};
+ ball.vx = dx[pl.dir] * 4 * FX, ball.vy = dy[pl.dir] * 4 * FX;
+ if (!ball.t) ball.t = 1;
+ }
+ if (!ball.t) return;
+ ball.t++;
+ /* it melts as it goes: smaller every three seconds (faster on ice), then gone, then a new one */
+ bool ice = room_ice(b->x, b->y);
+ if (ball.t % (ice ? 45 : 90) == 0) {
+ if (b->frame >= 7) {
+ ball_place(b);
+ return;
+ }
+ b->frame++;
+ r = 10 - b->frame;
+ obj_set_box(b, -r + 1, -r + 1, 2 * r - 2, 2 * r - 2);
+ }
+ /* rolls on, slowing (less on ice); bounces off what stops it */
+ for (int axis = 0; axis < 2; axis++) {
+ int v = axis ? ball.vy : ball.vx;
+ if (!v) continue;
+ int nx = b->x + (axis ? 0 : v / FX), ny = b->y + (axis ? v / FX : 0);
+ if (world_walkable(nx - r + 1, ny - r + 1, 2 * r - 2, 2 * r - 2, (int)(b - objs))) b->x = (int16_t)nx, b->y = (int16_t)ny;
+ else if (axis) ball.vy = -ball.vy / 2;
+ else ball.vx = -ball.vx / 2;
+ }
+ int fr = ice ? 1 : 3;
+ ball.vx += ball.vx > 0 ? -fr : ball.vx < 0 ? fr : 0;
+ ball.vy += ball.vy > 0 ? -fr : ball.vy < 0 ? fr : 0;
+ if (abs_i(ball.vx) < fr) ball.vx = 0;
+ if (abs_i(ball.vy) < fr) ball.vy = 0;
+ /* in the hole */
+ if (abs_i(b->x - HOLE_X) < 7 && abs_i(b->y - HOLE_Y) < 6 && !event_running()) {
+ ball.sunk = true;
+ event_start(EV_BALL_HOLE, b);
+ }
+}
+
+/* ---------------------------------------------------------------- the rooms' things */
+void snow1_setup(int room, int from) {
+ (void)from;
+ switch (room) {
+ case ROOM_SNOWDIN1:
+ if (!flag(F_BRANCH)) obj_trigger(1026, 380, 20, 100, EV_BRANCH, ACTOR_TRIGGER);
+ else obj_sign(996, 384, 26, 30, "* (It's been smashed like it was nothing...)");
+ break;
+ case ROOM_SNOWDIN5: {
+ Obj *l = obj_deco(SPR_LAMP, 2960, 365, true);
+ if (l) {
+ l->name = ACTOR_BLOCK, l->flags |= OF_TALK, l->event = EV_SIGN, l->text = "* (It's a conveniently-shaped lamp.)";
+ obj_set_box(l, 2, 22, 15, 9);
+ }
+ obj_sign(3004, 300, 60, 66, "* (It's some sort of checkpoint or sentry-station.)|* (But there are bottles of ketchup, mustard, and relish sitting inside...)");
+ if (!flag(F_SANS_MET)) obj_trigger(2572, 380, 40, 100, EV_SANS_INTRO, ACTOR_TRIGGER);
+ break;
+ }
+ case ROOM_BOXROAD:
+ obj_save(3240, 376, "* (The convenience of that lamp still fills you with determination.)");
+ obj_sign(3420, 334, 20, 22, "* (This is a box.)|* (You can put an item inside or take an item out.)|* (The same box will appear later, so don't worry about coming back.)|* (Sincerely, a box lover.)");
+ {
+ Obj *b = obj_trigger(3444, 334, 26, 24, EV_BOX, ACTOR_ITEM);
+ if (b) b->flags = OF_TALK | OF_SOLID;
+ }
+ break;
+ case ROOM_RIVER: {
+ Obj *r = obj_trigger(3428, 116, 26, 34, EV_FISHROD, ACTOR_ITEM);
+ if (r) r->flags = OF_TALK;
+ break;
+ }
+ case ROOM_PAPSENTRY:
+ obj_sign(3966, 296, 52, 64, "* YOU OBSERVE THE WELL-CRAFTED SENTRY STATION.|* WHO COULD HAVE BUILT THIS, YOU PONDER...|* I BET IT WAS THAT VERY FAMOUS ROYAL GUARDSMAN!|* (NOTE: NOT YET A VERY FAMOUS ROYAL GUARDSMAN.)");
+ if (!flag(F_PAP_SENTRY)) {
+ obj_sans(3616, 414, DIR_RIGHT);
+ obj_papyrus(3660, 414, DIR_LEFT);
+ obj_trigger(3540, 370, 34, 110, EV_PAP_SENTRY, ACTOR_TRIGGER);
+ }
+ break;
+ case ROOM_DOGGO:
+ obj_sign(4204, 384, 22, 22, "* (Absolutely NO MOVING!!!)");
+ obj_sign(4486, 398, 26, 16, "* (It's a bag of smoked dog treats.)");
+ obj_sign(4296, 330, 88, 66, flag(F_DOGGO) == 2 ? "* (It's a sentry station. No one is inside.)" : "* (It's Doggo's sentry station.)");
+ if (!flag(F_DOGGO)) obj_trigger(4296, 398, 70, 80, EV_DOGGO, ACTOR_TRIGGER);
+ break;
+ case ROOM_ICEFIELD:
+ obj_sign(4864, 368, 24, 28, "* North: Ice\n South: Ice\n West: Ice|* East: Snowdin Town\n (... and ice)");
+ {
+ Obj *s = obj_sans(4686, 409, DIR_DOWN);
+ if (s) s->event = EV_SANS_TALK, s->arg = 1, s->flags |= OF_TALK;
+ }
+ break;
+ case ROOM_SNOWMAN: {
+ Obj *s = obj_trigger(4904, 60, 40, 44, EV_SNOWMAN, ACTOR_ITEM);
+ if (s) s->flags = OF_TALK | OF_SOLID;
+ break;
+ }
+ case ROOM_ELECMAZE:
+ if (flag(F_ELECMAZE) < 2) {
+ obj_papyrus(5484, 446, DIR_LEFT);
+ if (!flag(F_ELECMAZE)) obj_trigger(5200, 280, 30, 200, EV_ELECMAZE, ACTOR_TRIGGER);
+ else obj_trigger(5440, 420, 30, 40, EV_ELECMAZE, ACTOR_TRIGGER2);
+ }
+ if (flag(F_ELECMAZE) == 1)
+ for (unsigned i = 0; i < sizeof maze_walls / sizeof maze_walls[0]; i++)
+ obj_trigger(maze_walls[i][0], maze_walls[i][1], maze_walls[i][2], maze_walls[i][3], EV_MAZE_ZAP, ACTOR_BLOCK);
+ {
+ Obj *s = obj_sans(5464, 336, DIR_DOWN);
+ if (s) s->event = EV_SANS_TALK, s->arg = 2, s->flags |= OF_TALK;
+ }
+ maze_prints = flag(F_ELECMAZE) ? maze_len() : 0;
+ break;
+ case ROOM_BALLGAME: {
+ Obj *n = obj_trigger(5594, 280, 54, 30, EV_NICECREAM, ACTOR_ITEM);
+ if (n) n->flags = OF_TALK | OF_SOLID;
+ obj_sign(5682, 382, 18, 16, "* (It's a snowdecahedron.)");
+ obj_sign(HOLE_X - 11, HOLE_Y - 8, 22, 16, "* Ah! Wow! Woah!\n* It's a \"#RHole#X\".");
+ if (flag(F_KILLS_SNOWDIN) < 8) {
+ Obj *b = obj_deco(SPR_SNOWBALL, BALL_X, BALL_Y, true);
+ if (b) b->name = ACTOR_BALL, ball_place(b);
+ }
+ Obj *s = obj_sans(6136, 336, DIR_DOWN);
+ if (s) s->event = EV_SANS_TALK, s->arg = 3, s->flags |= OF_TALK;
+ break;
+ }
+ case ROOM_DOGI:
+ obj_sign(6426, 310, 24, 24, "* SMELL DANGER RATING|* Snow Smell - Snowman\n WHITE Rating\n Can become #YYELLOW#X Rating|* Unsuspicious Smell - Puppy\n #BBLUE#X Rating\n Smell of rolling around.|* Weird Smell - Humans\n #GGREEN#X Rating\n Destroy at all costs!");
+ break;
+ case ROOM_WORDSEARCH:
+ obj_sign(6434, 648, 18, 18, "* (It's a word search.)\n* (The top row says GIASFCLFUBREHBER.)");
+ if (!flag(F_WORDSEARCH)) {
+ obj_papyrus(6484, 652, DIR_LEFT);
+ obj_trigger(6300, 600, 30, 160, EV_WORDSEARCH, ACTOR_TRIGGER);
+ }
+ {
+ Obj *s = obj_sans(6536, 658, DIR_DOWN);
+ if (s) s->event = EV_SANS_TALK, s->arg = 4, s->flags |= OF_TALK;
+ }
+ break;
+ }
+}
+
+void snow1_update(void) {
+ if (g_room == ROOM_BALLGAME) ball_update();
+}
+
+/* (while a cutscene runs too) */
+static void snow1_scene_update(void) {
+ if (maze_growing && maze_prints < maze_len()) maze_prints += 2;
+}
+
+void snow1_draw(void) {
+ if (g_room != ROOM_ELECMAZE || !maze_prints) return;
+ /* Papyrus's footprints along the maze's path: two dents every 8 pixels */
+ snow1_scene_update();
+ int left = maze_prints;
+ for (int i = MAZE_POINTS - 1; i > 0 && left > 0; i--) {
+ int x0 = maze_path[i][0], y0 = maze_path[i][1], x1 = maze_path[i - 1][0], y1 = maze_path[i - 1][1];
+ int len = abs_i(x1 - x0) + abs_i(y1 - y0);
+ for (int d = 0; d < len && d < left; d += 8) {
+ int x = x0 + (x1 > x0 ? d : x1 < x0 ? -d : 0), y = y0 + (y1 > y0 ? d : y1 < y0 ? -d : 0);
+ int ox = y1 != y0 ? 3 : 0, oy = x1 != x0 ? 3 : 0;
+ gfx_rect(x - ox - 1 - cam_x, y - oy - 1 - cam_y, 3, 2, rgb565(0x55607F), 255);
+ gfx_rect(x + ox - 1 - cam_x, y + oy - cam_y, 3, 2, rgb565(0x55607F), 255);
+ }
+ left -= len;
+ }
+}
+
+/* ---------------------------------------------------------------- the events */
+static int ev_branch(Ev *c) {
+ EV_BEGIN;
+ /* behind Frisk, the branch snaps */
+ set_flag(F_BRANCH, 1);
+ g_shake = 10;
+ pl.frozen = true;
+ WAIT(12);
+ pl.dir = DIR_LEFT;
+ WAIT(30);
+ pl.dir = DIR_RIGHT;
+ pl.frozen = false;
+ if (c->self) gone(c->self);
+ obj_sign(996, 384, 26, 30, "* (It's been smashed like it was nothing...)");
+ EV_END;
+}
+
+static int ev_sans_intro(Ev *c) {
+ Obj *s = obj_get(ACTOR_SANS), *p = obj_get(ACTOR_PAPYRUS), *lamp = obj_get(ACTOR_BLOCK);
+ EV_BEGIN;
+ /* on the bridge, steps behind Frisk */
+ PL_WALK(2598, 392, 2);
+ pl.dir = DIR_RIGHT;
+ WAIT(20);
+ s = obj_sans(2556, 422, DIR_RIGHT);
+ if (s) s->flags |= OF_DARK;
+ s = obj_get(ACTOR_SANS);
+ WALK(s, 2584, 422, 1);
+ NARRATE("* Human.|* Don't you know how to greet a new pal?|* Turn around and shake my hand.");
+ pl.dir = DIR_LEFT;
+ WAIT(30);
+ g_shake = 4;
+ WAIT(20);
+ s->flags &= (uint16_t)~OF_DARK;
+ SAY(FACE_SANS, "`1* heh. never gets old.\n`0* i'm sans. sans the skeleton.|* i'm meant to be watching for humans... but i'm not big on capturing.|* my brother papyrus, though? he's really into it.|* speak of the devil. quick, go through the gate.\n* the bars are too wide to stop anyone anyway.");
+ /* through the gate, then behind the lamp */
+ WALK_TO(s, 2660, 432, 2);
+ PL_WALK(2720, 392, 2);
+ SAY(FACE_SANS, "* quick, behind that conveniently-shaped lamp.");
+ WALK_TO(s, 2920, 432, 3);
+ PL_WALK(2959, 392, 3);
+ PL_WALK(2959, 357, 2);
+ pl.dir = DIR_DOWN;
+ lamp->flags |= OF_FRONT;
+ WAIT_UNTIL(!s->walking);
+ s->dir = DIR_RIGHT;
+ /* Papyrus comes, scolds his brother and storms off */
+ p = obj_papyrus(3180, 432, DIR_LEFT);
+ p = obj_get(ACTOR_PAPYRUS);
+ WALK(p, 3000, 432, 3);
+ SAY(FACE_SANS, "* sup, bro?");
+ SAY(FACE_PAPYRUS, "`3* SANS!!! YOUR PUZZLES STILL AREN'T RECALIBRATED!\n* YOU'VE BEEN LAZING AROUND FOR DAYS!!!");
+ SAY(FACE_SANS, "* staring at this lamp. it's really cool.");
+ SAY(FACE_PAPYRUS, "`3* WHAT IF A HUMAN SHOWS UP!?!|`2* I'LL BE READY! I'LL CAPTURE THEM!\n* AND THEN THE ROYAL GUARD WILL HAVE TO LET ME IN!!!");
+ SAY(FACE_SANS, "* hmm... maybe this lamp will help you.");
+ SAY(FACE_PAPYRUS, "`3* SANS!!! YOU LAZYBONES!|* YOU GET LAZIER AND LAZIER EVERY DAY!!!");
+ SAY(FACE_SANS, "* hey, take it easy. i've gotten a ton of work done today.\n`2* a skele-ton.");
+ SAY(FACE_PAPYRUS, "`3* SANS!!!");
+ SAY(FACE_SANS, "`1* come on. you're smiling.");
+ SAY(FACE_PAPYRUS, "`3* I AM AND I HATE IT!|`3* UGH!!!\n`0* I WILL ATTEND TO MY PUZZLES...|* AS FOR YOUR WORK?\n`2* PUT A LITTLE MORE, \"BACKBONE\" INTO IT!!!!|* NYEH HEH HEH HEH HEH HEH!!!");
+ WALK(p, 3180, 432, 4);
+ gone(p);
+ WAIT(30);
+ p = obj_papyrus(3180, 432, DIR_LEFT);
+ p = obj_get(ACTOR_PAPYRUS);
+ WALK(p, 3140, 432, 4);
+ SAY(FACE_PAPYRUS, "`2* HEH!");
+ WALK(p, 3180, 432, 4);
+ gone(p);
+ SAY(FACE_SANS, "* ok, you can come out now.");
+ lamp->flags &= (uint16_t)~OF_FRONT;
+ PL_WALK(2959, 400, 2);
+ pl.dir = DIR_LEFT;
+ SAY(FACE_SANS, "* you should keep moving.\n`1* unless you want to hear more of my jokes.");
+ SAY(FACE_SANS, "`0* oh, one favor?|* my brother's never met a human. seeing you would make his day.|* he's harmless, promise. i'll be up ahead.");
+ set_flag(F_SANS_MET, 1);
+ set_flag(F_SANS_FAVOR, 1);
+ /* (the wrong way) */
+ WALK(s, 2556, 432, 2);
+ gone(s);
+ if (c->self) gone(c->self);
+ EV_END;
+}
+
+static int ev_sans_talk(Ev *c) {
+ int k = c->self ? c->self->arg : 0;
+ EV_BEGIN;
+ switch (k) {
+ case 1: /* by the ice: Papyrus's special attack */
+ if (!flag(F_SANS_HINT)) {
+ set_flag(F_SANS_HINT, 1);
+ SAY(FACE_SANS, "* a tip: my brother's got a #Bspecial attack#X.|* when it's #Lblue#X, stay still and it can't hurt you.|* think of a stop sign... but blue.");
+ } else {
+ SAY(FACE_SANS, "* remember... #Lblue#X stop sign.");
+ }
+ break;
+ case 2: /* by the maze: his brother's outfit */
+ if (flag(F_ELECMAZE) < 2) SAY(FACE_SANS, "* go on. he made this one just for you.");
+ else if (!flag(F_SANS_COOL)) {
+ SAY(FACE_SANS, "* thanks. he's having a blast.|* that outfit? party costume. he won't take it off.\n* calls it his \"battle body.\"|* cool brother, right?@Cool@Uncool");
+ set_flag(F_SANS_COOL, CHOICE() + 1);
+ if (CHOICE() == 0) SAY(FACE_SANS, "`1* you'd better tell him that.");
+ else SAY(FACE_SANS, "* hey, pal. sarcasm isn't funny, okay?\n* my brother's a real star.");
+ } else {
+ SAY(FACE_SANS, "* my brother's a real star.\n* he's the person who pushed me to get this sentry job.");
+ }
+ break;
+ case 3: /* by the Ball Game: fried snow, ever dearer, and then none */
+ set_flag(F_FRIED_SNOW, flag(F_FRIED_SNOW) + 1);
+ if (flag(F_FRIED_SNOW) == 1) SAY(FACE_SANS, "* hey. want some fried snow?\n* it's 5G.");
+ else if (flag(F_FRIED_SNOW) == 2) SAY(FACE_SANS, "* fried snow? 10G.");
+ else if (flag(F_FRIED_SNOW) == 3) SAY(FACE_SANS, "* fried snow? 50G.");
+ else SAY(FACE_SANS, "`1* actually, i'm all out of snow.");
+ break;
+ case 4: /* by the word search */
+ if (!flag(F_WORDSEARCH)) SAY(FACE_SANS, "* trust me. there's no way they can get past this one.");
+ else SAY(FACE_SANS, "* papyrus tried to solve yesterday's horoscope.\n`1* he says it was really tough.");
+ break;
+ }
+ EV_END;
+}
+
+static int ev_pap_sentry(Ev *c) {
+ Obj *s = obj_get(ACTOR_SANS), *p = obj_get(ACTOR_PAPYRUS);
+ EV_BEGIN;
+ pl.dir = DIR_RIGHT;
+ SAY(FACE_PAPYRUS, "`0* SO, AS I WAS SAYING ABOUT UNDYNE...");
+ SAY(FACE_SANS, "* hey, check it out.");
+ /* the double take */
+ for (c->v[0] = 0; c->v[0] < 6; c->v[0]++) {
+ p->dir = (uint8_t)(c->v[0] % 2 ? DIR_RIGHT : DIR_LEFT);
+ WAIT(c->v[0] < 4 ? 6 : 14);
+ }
+ p->dir = DIR_LEFT;
+ SAY(FACE_PAPYRUS, "`3* SANS!! OH MY GOD!!\n* IS THAT... A HUMAN!?!?");
+ SAY(FACE_SANS, "* uhhhh... actually, i think that's a rock.");
+ SAY(FACE_PAPYRUS, "`4* OH.");
+ SAY(FACE_SANS, "* hey, what's that in front of the rock?");
+ SAY(FACE_PAPYRUS, "`3* OH MY GOD!!! (IS THAT A HUMAN?)");
+ SAY(FACE_SANS, "* yes.");
+ SAY(FACE_PAPYRUS, "`2* SANS!!! IT'S A HUMAN!!! I'M GOING TO BE SO POPULAR!!!|`0* HUMAN! THE GREAT PAPYRUS WILL STOP YOU AND CAPTURE YOU!|`4* AND THEN... WELL, I'LL WORK THAT OUT LATER.|`2* ONWARD, IF YOU DARE!!! NYEH HEH HEH!!!");
+ WALK(p, 4140, 414, 6);
+ gone(p);
+ SAY(FACE_SANS, "* well, that went well.\n* don't sweat it, kid.|* i'll keep an eye out for ya.");
+ WALK(s, 4140, 414, 2);
+ gone(s);
+ set_flag(F_PAP_SENTRY, 1);
+ if (c->self) gone(c->self);
+ EV_END;
+}
+
+static bool doggo_stick; /* (snowmon.c: spared with the stick) */
+void snow_doggo_stick(void) { doggo_stick = true; }
+
+static int ev_doggo(Ev *c) {
+ Obj *d = obj_get(ACTOR_DOGGO);
+ EV_BEGIN;
+ d = obj_deco(SPR_DOGGO_OW, 4340, 386, false);
+ if (d) d->name = ACTOR_DOGGO, d->flags |= OF_FRONT;
+ NARRATE("* Something moved? Or did it?|* I only see things that move.\n* And moving humans don't stay moving for long!");
+ doggo_stick = false;
+ BATTLE(FORM_DOGGO);
+ set_flag(F_DOGGO, bt.mon[0].killed ? 2 : 1);
+ if (flag(F_DOGGO) == 1) {
+ if (doggo_stick) NARRATE("* A stick? Then... no stick?|* I'll need a dog treat to figure this out.");
+ else NARRATE("* S-S-S-Something pet me...\n* Something that isn't m-m-moving...|* I'm gonna need some dog treats for this!!!");
+ }
+ gone(d);
+ if (c->self) gone(c->self);
+ EV_END;
+}
+
+static int ev_snowman(Ev *c) {
+ EV_BEGIN;
+ {
+ bool has = false;
+ for (int i = 0; i < NUM_ITEMS; i++) has |= sv.items[i] == ITEM_SNOWMAN_PIECE;
+ c->v[0] = has;
+ }
+ if (c->v[0]) {
+ NARRATE("* Thank you... good luck!");
+ } else if (flag(F_SNOWMAN) >= 2) {
+ NARRATE("* If you keep taking pieces of me, there'll be nothing left...");
+ } else {
+ if (!flag(F_SNOWMAN)) NARRATE("* I'm a snowman, and I'd love to travel.|* Would you carry a piece of me far away?@Yes@No");
+ else NARRATE("* Did you lose my piece...?\n* Will you take another?@Yes@No");
+ if (CHOICE() == 0) {
+ if (item_add(ITEM_SNOWMAN_PIECE)) {
+ set_flag(F_SNOWMAN, flag(F_SNOWMAN) + 1);
+ NARRATE("* Thank you... good luck!\n* (You got the Snowman Piece.)");
+ } else {
+ NARRATE("* (You're carrying too much.)");
+ }
+ } else {
+ NARRATE("* I see... good journey, then.");
+ }
+ }
+ EV_END;
+}
+
+static int ev_elecmaze(Ev *c) {
+ Obj *p = obj_get(ACTOR_PAPYRUS);
+ EV_BEGIN;
+ if (flag(F_ELECMAZE) == 1) goto crossed;
+ pl.dir = DIR_RIGHT;
+ SAY(FACE_PAPYRUS, "`0* HUMAN!! BEHOLD: THE INVISIBLE ELECTRICITY MAZE!!!|* TOUCH A WALL, AND THIS ORB ZAPS YOU!\n`2* NYEH HEH HEH!!!");
+ /* Frisk steps in: Papyrus, holding the orb, gets the shock */
+ FREE(true);
+ WAIT_UNTIL(pl.x + 10 >= 5282);
+ FREE(false);
+ p->spr[DIR_LEFT] = SPR_PAPYRUS_ZAP, p->flags |= OF_ANIM, p->anim_speed = 3;
+ g_shake = 12;
+ WAIT(40);
+ p->spr[DIR_LEFT] = SPR_PAPYRUS_L, p->flags &= (uint16_t)~OF_ANIM, p->frame = 0;
+ SAY(FACE_PAPYRUS, "`3* SANS!!! WHAT HAPPENED???");
+ SAY(FACE_SANS, "* i think you have to hold the orb.");
+ SAY(FACE_PAPYRUS, "`4* OH, OKAY.");
+ /* he walks the maze to Frisk (his footprints show the way), gives the orb, and walks back */
+ maze_growing = true;
+ for (c->v[0] = MAZE_POINTS - 2; c->v[0] >= 0; c->v[0]--) WALK(p, maze_path[c->v[0]][0], maze_path[c->v[0]][1] + 6, 2);
+ maze_growing = false;
+ maze_prints = maze_len();
+ p->dir = DIR_LEFT;
+ SAY(FACE_PAPYRUS, "`0* HOLD THIS PLEASE.");
+ NARRATE("* (You got the orb.)");
+ for (c->v[0] = 1; c->v[0] < MAZE_POINTS; c->v[0]++) WALK(p, maze_path[c->v[0]][0] + (c->v[0] == MAZE_POINTS - 1 ? 14 : 0), maze_path[c->v[0]][1] + 6, 3);
+ p->dir = DIR_LEFT;
+ SAY(FACE_PAPYRUS, "`2* OKAY! TRY IT NOW!!!");
+ set_flag(F_ELECMAZE, 1);
+ if (c->self) gone(c->self);
+ for (unsigned i = 0; i < sizeof maze_walls / sizeof maze_walls[0]; i++)
+ obj_trigger(maze_walls[i][0], maze_walls[i][1], maze_walls[i][2], maze_walls[i][3], EV_MAZE_ZAP, ACTOR_BLOCK);
+ obj_trigger(5440, 420, 30, 40, EV_ELECMAZE, ACTOR_TRIGGER2);
+ return 1;
+crossed:
+ SAY(FACE_PAPYRUS, "`2* YOU SOLVED IT! FAR TOO EASILY...|`0* THE NEXT ONE WON'T BE SO KIND!!!\n`2* NYEH HEH HEH!!!");
+ WALK(p, 5520, 446, 5);
+ gone(p);
+ set_flag(F_ELECMAZE, 2);
+ for (int i = 0; i < MAX_OBJS; i++)
+ if (objs[i].event == EV_MAZE_ZAP || objs[i].event == EV_ELECMAZE) objs[i].kind = OBJ_NONE;
+ EV_END;
+}
+
+static int ev_maze_zap(Ev *c) {
+ EV_BEGIN;
+ /* the orb shocks Frisk (no harm) and he's back at the start */
+ g_shake = 10;
+ pl.frozen = true;
+ WAIT(20);
+ pl.x = 5258, pl.y = 356, pl.dir = DIR_RIGHT;
+ pl.frozen = false;
+ EV_END;
+}
+
+static int ev_nicecream(Ev *c) {
+ EV_BEGIN;
+ if (!flag(F_NICECREAM)) {
+ set_flag(F_NICECREAM, 1);
+ NARRATE("* Nobody wants something cold today. Odd...|* OH!!!! A CUSTOMER!!!");
+ NARRATE("* Hello! Would you like some Nice Cream?|* It's the frozen treat that warms your heart!\n* Now just 15G!@Yes@No");
+ } else {
+ NARRATE("* Nice Cream! It's the frozen treat that warms your heart!\n* Now just 15G!@Yes@No");
+ }
+ if (CHOICE() == 1) {
+ NARRATE("* Well then... Tell your friends...|* There's ice cream... Out in the middle of the woods...");
+ } else if (sv.gold < 15) {
+ NARRATE("* Huh? You don't have enough money...|* I wish I could make Nice Cream for free...");
+ } else if (!item_add(ITEM_NICE_CREAM)) {
+ NARRATE("* It looks like you're holding too much stuff! Oh well!");
+ } else {
+ sv.gold = (uint16_t)(sv.gold - 15);
+ NARRATE("* Here you go!\n* Have a super-duper day!\n* (You got the Nice Cream.)");
+ }
+ EV_END;
+}
+
+static char ball_text[260];
+static int ev_ball_hole(Ev *c) {
+ Obj *b = c->self;
+ EV_BEGIN;
+ if (b) b->flags |= OF_HIDDEN;
+ {
+ /* the flag that pops up: by how long the ball took, or how small it was */
+ int secs = ball.t / 30, g;
+ uint16_t spr;
+ const char *t;
+ if (secs < 6 && flag(F_BALLGAME) != 7) {
+ spr = SPR_FLAG_RED, g = 50, t = "* Bravery. Justice. Integrity. Kindness. Perseverance. Patience.|* Using these, you were able to win at \"Ball Game.\"";
+ } else if (secs < 6) {
+ spr = SPR_FLAG_RED, g = 10, t = "* #RRED#X - Try as you might, you continue to be yourself.";
+ } else if (b && b->frame >= 5) {
+ spr = SPR_FLAG_LIGHTBLUE, g = 4, t = "* #LLIGHT BLUE#X - \"Ball\" is \"Small.\"|* You waited, still, for this opportunity...\n* ... then dethroned \"Ball\" with a sharp attack.";
+ } else if (secs < 8) {
+ spr = SPR_FLAG_ORANGE, g = 5, t = "* #OORANGE#X - You are the kind of person who rushes fists-first through all obstacles.";
+ } else if (secs < 11) {
+ spr = SPR_FLAG_YELLOW, g = 3, t = "* #YYELLOW#X - Your sure-fire accuracy put an end to the mayhem of \"Ball.\"";
+ } else if (secs < 15) {
+ spr = SPR_FLAG_BLUE, g = 2, t = "* #BBLUE#X - Hopping and twirling, your original style pulled you through.";
+ } else if (secs < 20) {
+ spr = SPR_FLAG_GREEN, g = 1, t = "* #GGREEN#X - Your concern and care for \"Ball\" led you to a delicious victory.";
+ } else {
+ spr = SPR_FLAG_PURPLE, g = 2, t = "* #PPURPLE#X - Even when you felt trapped, you took notes and achieved the end of \"Ball.\"";
+ }
+ if (spr == SPR_FLAG_RED) set_flag(F_BALLGAME, 7);
+ else if (!flag(F_BALLGAME)) set_flag(F_BALLGAME, 1);
+ sv.gold = (uint16_t)min_i(9999, sv.gold + g);
+ snprintf(ball_text, sizeof ball_text, "%s|* (You won %dG.)", t, g);
+ Obj *f = obj_deco(spr, HOLE_X, HOLE_Y + 4, false);
+ if (f) f->name = ACTOR_DOG;
+ }
+ NARRATE(ball_text);
+ WAIT(30);
+ gone(obj_get(ACTOR_DOG));
+ if (b) b->flags &= (uint16_t)~OF_HIDDEN, ball_place(b);
+ EV_END;
+}
+
+static int ev_wordsearch(Ev *c) {
+ Obj *p = obj_get(ACTOR_PAPYRUS);
+ EV_BEGIN;
+ pl.dir = DIR_RIGHT;
+ SAY(FACE_PAPYRUS, "`0* HUMAN!!!\n* THE NEXT PUZZLE WILL NOT BE EASY!\n* IT IS DESIGNED BY MY BROTHER, SANS!");
+ SAY(FACE_SANS, "* it's right there. on the ground.\n* trust me. there's no way they can get past this one.");
+ FREE(true);
+ WAIT_UNTIL(pl.x >= 6440);
+ FREE(false);
+ pl.dir = DIR_RIGHT;
+ SAY(FACE_PAPYRUS, "`3* SANS!!! THE PUZZLE DIDN'T DO ANYTHING!!!");
+ SAY(FACE_SANS, "* whoops. i knew i should have used today's crossword instead.");
+ SAY(FACE_PAPYRUS, "`3* CROSSWORD!?\n* IN MY OPINION, JUNIOR JUMBLE IS EASILY THE HARDEST.");
+ SAY(FACE_SANS, "* what? really, dude? that easy-peasy word scramble?\n* that's for baby bones.");
+ SAY(FACE_PAPYRUS, "`3* UNBELIEVABLE!!!\n* HUMAN!! SOLVE THIS DISPUTE!@Crossword@Junior Jumble");
+ set_flag(F_WORDSEARCH, CHOICE() + 1);
+ if (CHOICE() == 0) SAY(FACE_PAPYRUS, "`3* HUMANS... YOU'RE ALL THE SAME!!!");
+ else SAY(FACE_PAPYRUS, "`2* HA! THE HUMAN AGREES WITH ME!!!");
+ SAY(FACE_PAPYRUS, "`2* NYEH HEH HEH HEH!!!");
+ WALK(p, 6640, 652, 6);
+ gone(p);
+ if (c->self) gone(c->self);
+ EV_END;
+}
+
+static int ev_fishrod(Ev *c) {
+ EV_BEGIN;
+ NARRATE("* (It's a fishing rod affixed to the ground.)\n* (Reel it in?)@Yes@No");
+ if (CHOICE() == 0) {
+ set_flag(F_FISH, 1);
+ NARRATE("* (You reeled in the line...)\n* (There's a note on the hook.)|* \"Call me! Here's my number!\"");
+ }
+ EV_END;
+}
+
+int box_menu(Ev *c); /* shop.c: the Dimensional Box */
+
+int snow1_event(Ev *c) {
+ switch (c->id) {
+ case EV_BRANCH: return ev_branch(c);
+ case EV_SANS_INTRO: return ev_sans_intro(c);
+ case EV_SANS_TALK: return ev_sans_talk(c);
+ case EV_PAP_SENTRY: return ev_pap_sentry(c);
+ case EV_DOGGO: return ev_doggo(c);
+ case EV_SNOWMAN: return ev_snowman(c);
+ case EV_ELECMAZE: return ev_elecmaze(c);
+ case EV_MAZE_ZAP: return ev_maze_zap(c);
+ case EV_NICECREAM: return ev_nicecream(c);
+ case EV_BALL_HOLE: return ev_ball_hole(c);
+ case EV_WORDSEARCH: return ev_wordsearch(c);
+ case EV_FISHROD: return ev_fishrod(c);
+ case EV_BOX: return box_menu(c);
+ }
+ return -1;
+}
diff --git a/games/undertale/src/snowdin2.c b/games/undertale/src/snowdin2.c
new file mode 100644
index 00000000..1248b37f
--- /dev/null
+++ b/games/undertale/src/snowdin2.c
@@ -0,0 +1,448 @@
+/* Snowdin Forest, from the spaghetti to the bridge into town: the snow puzzle and the Dogi, the XOXO puzzles,
+ * the Multicolor Tile Puzzle, the Dog House, the ice puzzle and the slide through the trees, the snow poffs and
+ * Greater Dog, the Gauntlet of Deadly Terror, the cliff below and the mysterious door. */
+#include <stdio.h>
+#include <string.h>
+#include "battle.h"
+#include "event.h"
+#include "events.h"
+#include "game.h"
+#include "gfx.h"
+#include "items.h"
+#include "monsters.h"
+#include "snowdin.h"
+#include "world.h"
+
+static void gone(Obj *o) { o->kind = OBJ_NONE; }
+
+/* ---------------------------------------------------------------- the XOXO puzzles */
+/* a puzzle's tiles (their top-left), its switch, its spikes */
+typedef struct {
+ const int16_t (*tiles)[2];
+ int n;
+ int16_t sw_x, sw_y;
+ int flag;
+} Xoxo;
+static const int16_t x1_tiles[][2] = {{7460, 1240}, {7540, 1240}};
+static const int16_t x2_tiles[][2] = {{8180, 1200}, {8240, 1200}, {8280, 1200}, {8240, 1220}, {8280, 1220}, {8200, 1240},
+ {8240, 1240}, {8260, 1240}, {8280, 1240}, {8180, 1260}, {8240, 1260}, {8180, 1280},
+ {8200, 1280}, {8220, 1280}, {8240, 1280}};
+static const int16_t x3_tiles[][2] = {{9540, 1160}, {9700, 1160}, {9540, 1180}, {9580, 1180}, {9660, 1180}, {9620, 1220},
+ {9580, 1240}, {9620, 1240}, {9580, 1260}, {9660, 1260}, {9540, 1300}, {9700, 1300}};
+static const Xoxo xoxos[3] = {
+ {x1_tiles, 2, 7500, 1196, F_XOXO1}, {x2_tiles, 15, 8098, 1240, F_XOXO2}, {x3_tiles, 12, 9743, 1224, F_XOXO3}};
+static const Xoxo *xo; /* the room's, or NULL */
+static uint8_t xo_state[16]; /* 0 X, 1 O */
+static int xo_on = -1; /* the tile under Frisk */
+static bool xo_kill; /* XOXO 2: the switch in the tree was pressed */
+
+static void xo_show(void) {
+ for (int i = 0; i < MAX_OBJS; i++) {
+ Obj *o = &objs[i];
+ if (o->kind != OBJ_DECO || o->name != ACTOR_TILE) continue;
+ bool solved = flag(xo->flag);
+ o->spr[0] = (uint16_t)(xo_state[o->arg] || solved ? SPR_OTILE : SPR_XTILE);
+ o->frame = solved ? 1 : 0;
+ }
+}
+
+static void xo_setup(int k) {
+ xo = &xoxos[k];
+ xo_on = -1, xo_kill = false;
+ memset(xo_state, 0, sizeof xo_state);
+ for (int i = 0; i < xo->n; i++) {
+ Obj *o = obj_deco(SPR_XTILE, xo->tiles[i][0], xo->tiles[i][1], false);
+ if (o) o->name = ACTOR_TILE, o->arg = (int16_t)i, o->flags |= OF_BACK, o->bh = 0;
+ }
+ Obj *sw = obj_deco(SPR_SNOWSWITCH, xo->sw_x, xo->sw_y, false);
+ if (sw) sw->flags |= OF_BACK | OF_TALK, sw->event = EV_XOXO_SWITCH, obj_set_box(sw, 0, 2, 24, 22), sw->name = ACTOR_SWITCH;
+ xo_show();
+}
+
+/* Frisk steps on a tile: X turns O, O turns back to X */
+static void xo_update(void) {
+ if (!xo || flag(xo->flag)) return;
+ int fx = pl.x + 10, fy = pl.y + 25, on = -1;
+ for (int i = 0; i < xo->n; i++)
+ if (fx >= xo->tiles[i][0] && fx < xo->tiles[i][0] + 20 && fy >= xo->tiles[i][1] && fy < xo->tiles[i][1] + 20) on = i;
+ if (on >= 0 && on != xo_on) {
+ xo_state[on] = !xo_state[on];
+ xo_show();
+ }
+ xo_on = on;
+}
+
+/* past the first XOXO, Papyrus waits by the spikes */
+static void pap_xoxo1(void) {
+ if (flag(F_PAP_XOXO1)) return;
+ obj_papyrus(7720, 1252, DIR_LEFT);
+ obj_trigger(7600, 1180, 30, 120, EV_PAP_XOXO, ACTOR_TRIGGER);
+}
+
+static int ev_xoxo_switch(Ev *c) {
+ EV_BEGIN;
+ if (!xo || flag(xo->flag)) {
+ NARRATE("* (The switch is already pressed.)");
+ return 1;
+ }
+ c->v[0] = 1;
+ for (int i = 0; i < xo->n; i++) c->v[0] &= xo_state[i];
+ if (c->v[0] || (xo == &xoxos[1] && xo_kill)) {
+ set_flag(xo->flag, 1);
+ xo_show();
+ /* the spikes go down, or (the ice puzzle) the bridge over to the trees is there */
+ for (int i = 0; i < MAX_OBJS; i++) {
+ if (objs[i].name == ACTOR_SPIKES) obj_spikes_set(&objs[i], false), objs[i].flags |= OF_HIDDEN;
+ if (objs[i].name == ACTOR_BLOCK) objs[i].flags &= (uint16_t)~OF_SOLID;
+ }
+ if (xo == &xoxos[0]) pap_xoxo1();
+ NARRATE("* (Click!)");
+ } else {
+ memset(xo_state, 0, sizeof xo_state);
+ xo_show();
+ NARRATE("* (Click...)\n* (The puzzle reset.)");
+ }
+ EV_END;
+}
+
+/* ---------------------------------------------------------------- the Multicolor Tile Puzzle */
+#define TILES_X 8660
+#define TILES_Y 1200
+#define TILES_W 8
+#define TILES_H 6
+static int tiles_t; /* frames left of its colours shuffling, -1 off */
+
+/* ---------------------------------------------------------------- the rooms' things */
+static Obj *spikes(int x, int y, int rows, bool raised) {
+ Obj *o = obj_spikes(x, y, 1, rows, raised, ACTOR_SPIKES);
+ if (o) o->spr[0] = SPR_SNOWSPIKES, o->frame = 0, o->flags |= OF_BACK;
+ if (o && !raised) o->flags |= OF_HIDDEN;
+ return o;
+}
+
+void snow2_setup(int room, int from) {
+ (void)from;
+ xo = NULL, tiles_t = -1;
+ switch (room) {
+ case ROOM_SPAGHETTI:
+ obj_save(6745, 695, "* (Knowing the mouse might one day find a way to heat up the spaghetti...)\n* (It fills you with determination.)");
+ obj_sign(6690, 658, 16, 20, "* HUMAN!! PLEASE ENJOY THIS SPAGHETTI.|* (LITTLE DO YOU KNOW, THIS SPAGHETTI IS A TRAP...)\n* (DESIGNED TO ENTICE YOU!!!)|* (YOU'LL BE SO BUSY EATING IT...)\n* (THAT YOU WON'T REALIZE THAT YOU AREN'T PROGRESSING!!)|* (THOROUGHLY JAPED AGAIN BY THE GREAT PAPYRUS!!!)\n* NYEH HEH HEH, PAPYRUS");
+ obj_sign(6734, 646, 38, 34, "* (It's a plate of frozen spaghetti.)\n* (It's so cold, it's stuck to the table.)");
+ obj_sign(6788, 644, 38, 36, "* (It's a microwave.)\n* (Its only setting is \"spaghetti.\")\n* (It's unplugged.)");
+ obj_sign(6742, 585, 18, 14, "* (Squeak!)");
+ break;
+ case ROOM_SNOWPUZZLE:
+ obj_sign(6984, 632, 20, 22, "* Warning: Dog Marriage|* (Yes, you read that correctly.)");
+ obj_sign(6980, 920, 80, 80, "* (It's a map of this room, drawn in the snow.)\n* (An X marks its top right.)");
+ {
+ Obj *sw = obj_trigger(7300, 650, 46, 68, EV_SNOW_SWITCH, ACTOR_SWITCH);
+ if (sw) sw->flags = OF_TALK;
+ }
+ spikes(7120, 940, 3, !flag(F_SNOWPUZZLE));
+ if (!flag(F_DOGI)) obj_trigger(7300, 900, 140, 140, EV_DOGI, ACTOR_TRIGGER);
+ break;
+ case ROOM_XOXO1:
+ obj_sign(7456, 1262, 20, 20, "* Turn every X into an O.\n* Then press the switch.");
+ xo_setup(0);
+ spikes(7680, 1220, 3, !flag(F_XOXO1));
+ if (flag(F_XOXO1)) pap_xoxo1();
+ break;
+ case ROOM_XOXO2:
+ obj_sign(8096, 1198, 20, 22, "* Turn every X into an O.\n* Then press the switch.");
+ xo_setup(1);
+ spikes(8360, 1160, 8, !flag(F_XOXO2));
+ {
+ /* the switch in the tree */
+ Obj *k = obj_trigger(7956, 1150, 30, 56, EV_XOXO_SWITCH, ACTOR_TRIGGER3);
+ if (k) k->flags = OF_TALK, k->arg = 1;
+ }
+ if (!flag(F_XOXO2)) {
+ Obj *p = obj_papyrus(7880, 1222, DIR_DOWN);
+ if (p) p->event = EV_PAP_XOXO, p->arg = 2, p->flags |= OF_TALK;
+ if (!flag(F_PAP_XOXO1) || flag(F_PAP_XOXO1) == 1) obj_trigger(7700, 1160, 30, 140, EV_PAP_XOXO, ACTOR_TRIGGER);
+ } else {
+ Obj *s = obj_sans(8390, 1216, DIR_DOWN);
+ if (s) s->event = EV_SNOW_SANS_CLIFF, s->arg = 1, s->flags |= OF_TALK;
+ }
+ break;
+ case ROOM_TILEPUZZLE:
+ obj_sign(8818, 1176, 26, 30, "* (The machine isn't working.)");
+ if (!flag(F_TILES)) {
+ obj_papyrus(8840, 1252, DIR_LEFT);
+ obj_trigger(8560, 1160, 30, 100, EV_TILES, ACTOR_TRIGGER);
+ /* (the tiles aren't there yet: nothing to walk on past the bridge) */
+ Obj *b = obj_trigger(8656, 1196, 8, 130, 0, ACTOR_BLOCK);
+ if (b) b->flags = OF_SOLID;
+ }
+ {
+ Obj *s = obj_sans(8834, 1290, DIR_DOWN);
+ if (s) s->event = EV_SNOW_SANS_CLIFF, s->arg = 2, s->flags |= OF_TALK;
+ }
+ break;
+ case ROOM_DOGHOUSE:
+ obj_save(9260, 1300, flag(F_LESSERDOG) == 2 ? "* (Snow can always be broken down and rebuilt into something more useful.)\n* (This simple fact fills you with determination.)"
+ : "* (Knowing the dog will never give up trying to make the perfect snowdog...)\n* (It fills you with determination.)");
+ obj_sign(9186, 1196, 20, 22, "* AWARE OF DOG\n* pleas pet dog");
+ obj_sign(9356, 1170, 26, 34, "* (Lesser Dog keeps building a snow dog...)\n* (It gets taller every time.)");
+ break;
+ case ROOM_XOXO3:
+ xo_setup(2);
+ if (!flag(F_XOXO3)) {
+ /* the gap to the trees, until the bridge comes */
+ Obj *b = obj_trigger(9776, 1206, 10, 40, 0, ACTOR_BLOCK);
+ if (b) b->flags = OF_SOLID;
+ }
+ /* off the ice's edge: down to the room below */
+ obj_trigger(9522, 1322, 262, 14, EV_XOXO_FALL, ACTOR_TRIGGER2);
+ break;
+ case ROOM_XOXOFAIL:
+ obj_sign(9520, 1440, 30, 40, "* (It's a snow Papyrus.)");
+ obj_sign(9636, 1466, 30, 20, "* (It's a lump of snow with \"Sans\" written on it.)");
+ break;
+ case ROOM_POFFZONE: {
+ static const int16_t poffs[][2] = {{10330, 1215}, {10485, 1235}, {10370, 1275}, {10465, 1285}, {10560, 1205},
+ {10620, 1245}, {10665, 1215}, {10570, 1290}, {10745, 1270}, {10882, 1284}};
+ for (int i = 0; i < 10; i++) {
+ Obj *p = obj_trigger(poffs[i][0] - 14, poffs[i][1] - 10, 30, 14, EV_POFF, ACTOR_ITEM);
+ if (p) p->flags = OF_TALK | OF_SOLID, p->arg = (int16_t)i;
+ }
+ obj_sign(10600, 1186, 18, 20, "* (Woof.)");
+ if (!flag(F_GREATERDOG)) obj_trigger(10840, 1200, 30, 110, EV_GREATERDOG, ACTOR_TRIGGER);
+ break;
+ }
+ case ROOM_DANGERBRIDGE:
+ if (!flag(F_GAUNTLET)) {
+ obj_papyrus(11830, 1236, DIR_LEFT);
+ obj_sans(11850, 1200, DIR_DOWN);
+ obj_trigger(11300, 1220, 30, 40, EV_GAUNTLET, ACTOR_TRIGGER);
+ } else {
+ Obj *s = obj_sans(11792, 1214, DIR_DOWN);
+ if (s) s->event = EV_SNOW_SANS_CLIFF, s->arg = 3, s->flags |= OF_TALK;
+ }
+ break;
+ case ROOM_SOUTHCLIFF: {
+ Obj *s = obj_sans(10552, 2312, DIR_DOWN);
+ if (s) s->event = EV_SNOW_SANS_CLIFF, s->arg = 4, s->flags |= OF_TALK;
+ break;
+ }
+ case ROOM_DOORROOM: {
+ Obj *d = obj_trigger(9890, 1636, 40, 54, EV_MYSTERY_DOOR, ACTOR_ITEM);
+ if (d) d->flags = OF_TALK | OF_SOLID;
+ break;
+ }
+ }
+}
+
+void snow2_update(void) {
+ xo_update();
+}
+
+void snow2_draw(void) {
+ /* the ice puzzle's bridge, once solved */
+ if (g_room == ROOM_XOXO3 && flag(F_XOXO3)) gfx_rect(9780 - cam_x, 1214 - cam_y, 60, 24, rgb565(0xCFDBFF), 255);
+ /* the tile puzzle: its colours shuffle, then settle (the map's red and pink) */
+ if (g_room == ROOM_TILEPUZZLE && tiles_t > 0) {
+ static const uint32_t cols[] = {0xFF4040, 0xFFC0C0, 0xFFFF40, 0x40C040, 0xFF8000, 0x4060FF, 0xA040FF};
+ for (int y = 0; y < TILES_H; y++)
+ for (int x = 0; x < TILES_W; x++)
+ gfx_rect(TILES_X + x * 20 - cam_x, TILES_Y + y * 20 - cam_y, 20, 20,
+ rgb565(cols[(x * 7 + y * 3 + tiles_t / 4) % 7]), 255);
+ tiles_t--;
+ } else if (g_room == ROOM_TILEPUZZLE && !flag(F_TILES)) {
+ /* (before the machine: plain grey tiles) */
+ gfx_rect(TILES_X - cam_x, TILES_Y - cam_y, TILES_W * 20, TILES_H * 20, rgb565(0x9090A0), 255);
+ }
+}
+
+/* ---------------------------------------------------------------- the events */
+/* XOXO 2's switch in the tree: then the puzzle's own switch solves it */
+static int ev_tree_switch(Ev *c) {
+ EV_BEGIN;
+ xo_kill = true;
+ NARRATE("* (There's a switch on this tree.)\n* (You press it.)");
+ EV_END;
+}
+
+static int ev_snow_switch(Ev *c) {
+ EV_BEGIN;
+ if (flag(F_SNOWPUZZLE)) {
+ NARRATE("* (The switch is already pressed.)");
+ } else {
+ NARRATE("* (There's a switch under the snow.)\n* (You press it.)");
+ set_flag(F_SNOWPUZZLE, 1);
+ for (int i = 0; i < MAX_OBJS; i++)
+ if (objs[i].name == ACTOR_SPIKES) obj_spikes_set(&objs[i], false), objs[i].flags |= OF_HIDDEN;
+ }
+ EV_END;
+}
+
+static int ev_dogi(Ev *c) {
+ Obj *a = obj_get(ACTOR_DOGAMY), *b = obj_get(ACTOR_DOGARESSA);
+ EV_BEGIN;
+ /* they come sniffing */
+ a = obj_deco(SPR_DOGAMY_OW, 7330, 900, false);
+ if (a) a->name = ACTOR_DOGAMY;
+ b = obj_deco(SPR_DOGARESSA_OW, 7410, 900, false);
+ if (b) b->name = ACTOR_DOGARESSA;
+ a = obj_get(ACTOR_DOGAMY), b = obj_get(ACTOR_DOGARESSA);
+ WALK_TO(a, pl.x - 8, pl.y + 26, 2);
+ WALK(b, pl.x + 30, pl.y + 26, 2);
+ NARRATE("* Sniff... sniff... a strange smell.|* (A strange smell must be... eliminated!)");
+ BATTLE(FORM_DOGI);
+ set_flag(F_DOGI, bt.mon[0].killed || bt.mon[1].killed ? 2 : 1);
+ gone(a), gone(b);
+ if (c->self) gone(c->self);
+ EV_END;
+}
+
+static int ev_pap_xoxo(Ev *c) {
+ Obj *p = obj_get(ACTOR_PAPYRUS);
+ int k = c->self && c->self->kind == OBJ_NPC ? c->self->arg : 0;
+ EV_BEGIN;
+ if (g_room == ROOM_XOXO1) {
+ /* past the first XOXO: the spaghetti */
+ pl.dir = DIR_RIGHT;
+ SAY(FACE_PAPYRUS, "`0* HUMAN!!! YOU SOLVED IT!\n* BUT... WHAT ABOUT THE SPAGHETTI?|* DID YOU EAT IT? OR LEAVE IT ALONE?@Ate it@Left it");
+ if (CHOICE() == 0) SAY(FACE_PAPYRUS, "`2* WOWIE!!! YOU ATE MY SPAGHETTI!!!|* IT MUST HAVE BEEN DELICIOUS!\n* NYEH HEH HEH!");
+ else SAY(FACE_PAPYRUS, "`4* YOU LEFT IT ALONE?|`0* SO THERE'S STILL SOME LEFT FOR ME?\n`2* NYEH HEH HEH!");
+ set_flag(F_PAP_XOXO1, 1);
+ WALK(p, 7740, 1252, 6);
+ gone(p);
+ if (c->self) gone(c->self);
+ return 1;
+ }
+ /* the second XOXO: his face, frozen in the snow */
+ if (k == 2) {
+ SAY(FACE_PAPYRUS, "`0* NEED HELP WITH THE PUZZLE?@Yes@No");
+ if (CHOICE() == 0) SAY(FACE_PAPYRUS, "`4* WELL... THERE MAY OR MAY NOT BE A SWITCH ON THAT TREE OVER THERE.");
+ else SAY(FACE_PAPYRUS, "`2* GOOD! A HUMAN WHO SOLVES PUZZLES!\n* NYEH HEH HEH!");
+ return 1;
+ }
+ pl.dir = DIR_RIGHT;
+ SAY(FACE_PAPYRUS, "`4* SO... WHILE I WAITED, I REDID THE SNOW TO LOOK LIKE MY FACE.|* THEN IT FROZE. THE PUZZLE CHANGED.\n`0* ASK ME IF YOU NEED A HINT!");
+ set_flag(F_PAP_XOXO1, 2);
+ if (c->self) gone(c->self);
+ EV_END;
+}
+
+static int ev_tiles(Ev *c) {
+ Obj *p = obj_get(ACTOR_PAPYRUS);
+ EV_BEGIN;
+ pl.dir = DIR_RIGHT;
+ SAY(FACE_PAPYRUS, "`0* HUMAN!!! THE MULTICOLOR TILE PUZZLE!\n* ONE PULL AND THE TILES CHANGE COLOR!|* EVERY COLOR DOES SOMETHING DIFFERENT!\n* RED: WALL. YELLOW: ZAP. GREEN: MONSTER. PINK: NOTHING.|* ORANGE, BLUE AND PURPLE... IT GETS COMPLICATED.|`2* GOT ALL THAT???@Yes@No");
+ if (CHOICE() == 1)
+ SAY(FACE_PAPYRUS, "`3* OKAY! AGAIN!\n* PINK TILES ARE... WAIT, NO...|`4* ...|`0* JUST TRY IT ON YOUR OWN!");
+ SAY(FACE_PAPYRUS, "`2* LET'S DO IT!!!");
+ /* the machine: the colours shuffle, then settle */
+ tiles_t = 90;
+ WAIT(95);
+ tiles_t = 0;
+ SAY(FACE_PAPYRUS, "`4* ...");
+ set_flag(F_TILES, 1);
+ for (int i = 0; i < MAX_OBJS; i++)
+ if (objs[i].name == ACTOR_BLOCK) objs[i].kind = OBJ_NONE;
+ /* he spins out of the room */
+ WALK(p, 8920, 1252, 8);
+ gone(p);
+ if (c->self) gone(c->self);
+ EV_END;
+}
+
+static int ev_xoxo_fall(Ev *c) {
+ EV_BEGIN;
+ /* off the ice's edge: down to the room under it */
+ FADE_TO(ROOM_XOXOFAIL, 9600, 1460, DIR_DOWN);
+ EV_END;
+}
+
+static int ev_poff(Ev *c) {
+ int k = c->self ? c->self->arg : 0;
+ EV_BEGIN;
+ if (k == 8 && !flag(F_POFF_GOLD)) {
+ set_flag(F_POFF_GOLD, 1);
+ sv.gold = (uint16_t)min_i(9999, sv.gold + 30);
+ NARRATE("* (It's a snow poff.)|* (There's 30G inside!)");
+ } else {
+ NARRATE("* (It's a snow poff.)");
+ }
+ EV_END;
+}
+
+static int ev_greaterdog(Ev *c) {
+ Obj *d = obj_get(ACTOR_GREATERDOG);
+ EV_BEGIN;
+ /* out of a poff it jumps */
+ d = obj_deco(SPR_GREATERDOG_OW, 10900, 1280, false);
+ if (d) d->name = ACTOR_GREATERDOG;
+ g_shake = 6;
+ WAIT(20);
+ BATTLE(FORM_GREATERDOG);
+ set_flag(F_GREATERDOG, bt.mon[0].killed ? 2 : 1);
+ set_flag(F_SNOWDIN_BOSSES, flag(F_SNOWDIN_BOSSES) + 1);
+ gone(obj_get(ACTOR_GREATERDOG));
+ if (c->self) gone(c->self);
+ EV_END;
+}
+
+static int ev_gauntlet(Ev *c) {
+ Obj *p = obj_get(ACTOR_PAPYRUS), *s = obj_get(ACTOR_SANS);
+ EV_BEGIN;
+ pl.dir = DIR_RIGHT;
+ SAY(FACE_PAPYRUS, "`0* HUMAN!!!\n* THIS IS YOUR FINAL AND MOST DANGEROUS CHALLENGE!!!|`2* BEHOLD!\n* THE GAUNTLET OF DEADLY TERROR!");
+ /* the gauntlet comes down: a spear, a spiked ball, a dog on a rope, a fire, a cannon */
+ g_shake = 8;
+ WAIT(40);
+ SAY(FACE_PAPYRUS, "`0* ONE WORD FROM ME AND IT ALL SWINGS INTO ACTION!!!|`3* HERE IT GOES!|`4* ...|* ANY MOMENT NOW...");
+ SAY(FACE_SANS, "* well? what's the holdup?");
+ SAY(FACE_PAPYRUS, "`3* I'M GETTING TO IT!!!|`4* ...ACTUALLY, IT'S TOO EASY. NOT FAIR AT ALL.\n`2* A SKELETON HAS STANDARDS! NYEH HEH HEH!!!");
+ WALK(p, 12000, 1236, 6);
+ gone(p);
+ SAY(FACE_SANS, "* ...|* i don't know what my brother's going to do.|* if i were you, i would keep going.");
+ WALK(s, 12000, 1200, 2);
+ gone(s);
+ set_flag(F_GAUNTLET, 1);
+ if (c->self) gone(c->self);
+ EV_END;
+}
+
+static int ev_sans_cliff(Ev *c) {
+ int k = c->self ? c->self->arg : 0;
+ EV_BEGIN;
+ switch (k) {
+ case 1: SAY(FACE_SANS, "* hey, you could have asked me for help.\n`2* i know a thing or two about trees."); break;
+ case 2: SAY(FACE_SANS, "* his cooking's getting better.\n* give it a year, it might even be food."); break;
+ case 3:
+ if (!flag(F_SNOW_SANS_TALK)) {
+ set_flag(F_SNOW_SANS_TALK, 1);
+ SAY(FACE_SANS, "* hey, buddy.\n* my brother's up ahead.|* remember: if you see a #Lblue#X attack, don't move.");
+ } else {
+ SAY(FACE_SANS, "* blue stop sign. got it?");
+ }
+ break;
+ case 4: SAY(FACE_SANS, "* hey.\n* nice view down here, huh?"); break;
+ }
+ EV_END;
+}
+
+static int ev_mystery_door(Ev *c) {
+ EV_BEGIN;
+ NARRATE("* (It's locked.)");
+ EV_END;
+}
+
+int snow2_event(Ev *c) {
+ switch (c->id) {
+ case EV_XOXO_SWITCH: return c->self && c->self->name == ACTOR_TRIGGER3 ? ev_tree_switch(c) : ev_xoxo_switch(c);
+ case EV_SNOW_SWITCH: return ev_snow_switch(c);
+ case EV_DOGI: return ev_dogi(c);
+ case EV_PAP_XOXO: return ev_pap_xoxo(c);
+ case EV_TILES: return ev_tiles(c);
+ case EV_XOXO_FALL: return ev_xoxo_fall(c);
+ case EV_POFF: return ev_poff(c);
+ case EV_GREATERDOG: return ev_greaterdog(c);
+ case EV_GAUNTLET: return ev_gauntlet(c);
+ case EV_SNOW_SANS_CLIFF: return ev_sans_cliff(c);
+ case EV_MYSTERY_DOOR: return ev_mystery_door(c);
+ }
+ return -1;
+}
diff --git a/games/undertale/src/snowmon.c b/games/undertale/src/snowmon.c
new file mode 100644
index 00000000..1a7bbc40
--- /dev/null
+++ b/games/undertale/src/snowmon.c
@@ -0,0 +1,896 @@
+/* Snowdin's monsters: stats, ACTs and texts (from the Undertale Wiki's records of the game), their formations,
+ * where they come out, and their attacks, as the wiki describes them. Papyrus is in papyrus.c. */
+#include <stdio.h>
+#include <string.h>
+#include "battle.h"
+#include "game.h"
+#include "gfx.h"
+#include "items.h"
+#include "monsters.h"
+#include "res.h"
+#include "snowdin.h"
+#include "world.h"
+
+#define PICK(arr) ((arr)[rnd_n((int)(sizeof(arr) / sizeof((arr)[0])))])
+
+/* whether the player ACTed on the monster this turn (else it's a "neutral" turn: Snowdrake tells a pun) */
+static bool acted_on(const Monster *m) { return m->state2 & 0x100; }
+static void mark_acted(Monster *m) { m->state2 = (int16_t)(m->state2 | 0x100); }
+static void clear_acted(Monster *m) { m->state2 = (int16_t)(m->state2 & ~0x100); }
+
+/* the drakes and Jerry: a joke makes the others laugh, and they can be spared */
+static void others_laugh(Battle *b, Monster *self) {
+ for (int i = 0; i < b->nmon; i++) {
+ Monster *o = &b->mon[i];
+ if (o == self || !o->alive || o->gone) continue;
+ o->spare = true, o->state = 9;
+ }
+}
+static bool others_here(Battle *b, Monster *self) {
+ for (int i = 0; i < b->nmon; i++)
+ if (&b->mon[i] != self && b->mon[i].alive && !b->mon[i].gone) return true;
+ return false;
+}
+
+/* ---------------------------------------------------------------- Snowdrake, Chilldrake */
+static void act_snowdrake(Battle *b, Monster *m, int act, char *t, int cap) {
+ mark_acted(m);
+ if (act == 0) { /* Heckle */
+ if (rnd_n(6) == 0) {
+ snprintf(t, (size_t)cap, "* You tell Snowdrake their jokes will never land.\n* Crushed, they slink away...");
+ m->gone = true, m->fade = 1;
+ } else {
+ snprintf(t, (size_t)cap, "* You boo Snowdrake.");
+ m->state = 3;
+ }
+ } else if (act == 1) { /* Laugh */
+ snprintf(t, (size_t)cap, m->state == 1 ? "* You laugh at Snowdrake's pun." : "* You laugh at nothing in particular.");
+ if (m->state == 1) m->spare = true, m->state = 2;
+ else m->state = 4;
+ } else { /* Joke */
+ if (others_here(b, m)) {
+ snprintf(t, (size_t)cap, "* You make an ice pun.\n* The other monsters think it's hilarious...");
+ others_laugh(b, m);
+ m->state = 5;
+ } else {
+ snprintf(t, (size_t)cap, "* You make an ice pun.\n* Snowdrake isn't impressed.");
+ m->state = 6;
+ }
+ }
+}
+static const char *talk_snowdrake(Battle *b, Monster *m) {
+ int s = m->state;
+ bool acted = acted_on(m);
+ clear_acted(m);
+ if (s == 2) { m->state = 7; return "See!? Laughs!\nDad was\nwrong!"; }
+ if (s == 3) { m->state = 0; return "THIS won't\nbe funny\neither!"; }
+ if (s == 4) { m->state = 0; return "What are YOU\nlaughin' at?!?"; }
+ if (s == 5) { m->state = 0; return "That's not\nlike me..."; }
+ if (s == 6) { m->state = 0; return PICK(((const char *const[]){"Is that s'posed\nto be funny?", "Ha... Ha...\nNice try.", "I've heard\nthat one."})); }
+ if (s == 7) return "Thanks, you're\nall great.";
+ /* a neutral turn: his next pun (laugh at it to spare him) */
+ if (!acted || s == 1) m->state = 1;
+ static const char *const puns[] = {"\"Ice\" to\nmeet you.", "Ice puns are\n\"snow\" problem", "Fights you in\n\"cold\" blood.",
+ "Better not\nsnow \"flake\"\nout!", "My fave ice\ncereals:\n\"frosted\"", "\"Chill\"\nout...",
+ "M.. m..\nmacaroni and\n\"freeze\""};
+ return PICK(puns);
+}
+static int attack_drake(Battle *b, Monster *m) { (void)b, (void)m; return rnd_n(2) ? ATK_DRAKE_ARCS : ATK_DRAKE_LINES; }
+
+static void act_chilldrake(Battle *b, Monster *m, int act, char *t, int cap) {
+ mark_acted(m);
+ if (act == 0) { /* Clash */
+ snprintf(t, (size_t)cap, "* You tell Chilldrake it's all wrong.");
+ m->state = 3;
+ } else if (act == 1) { /* Agree */
+ if (m->state == 1) {
+ snprintf(t, (size_t)cap, "* You agree with Chilldrake.\n* It seems to get very uncomfortable...");
+ m->spare = true, m->state = 2;
+ } else {
+ snprintf(t, (size_t)cap, "* You agree with Chilldrake before it gives its speech.");
+ m->state = 4;
+ }
+ } else { /* Joke */
+ if (others_here(b, m)) {
+ snprintf(t, (size_t)cap, "* You make fun of Chilldrake.\n* The other monsters think it's hilarious...");
+ others_laugh(b, m);
+ } else {
+ snprintf(t, (size_t)cap, "* You make fun of Chilldrake.");
+ }
+ m->state = 5;
+ }
+}
+static const char *talk_chilldrake(Battle *b, Monster *m) {
+ int s = m->state;
+ bool acted = acted_on(m);
+ clear_acted(m);
+ (void)b;
+ if (s == 2) { m->state = 6; return "To tell you\nthe truth..."; }
+ if (s == 3) { m->state = 0; return "WRONG! Let's\nfight and die."; }
+ if (s == 4) { m->state = 0; return "You don't\nknow my\ncause!"; }
+ if (s == 5) { m->state = 0; return "Only Snowy\ncan do that."; }
+ if (s == 6) return "Do you...\nreally...";
+ if (!acted || s == 1) m->state = 1;
+ static const char *const q[] = {"Brush my\nteeth? No way\nin heck!", "NEVER do your\nhomework !!", "No bedtime!\nOnly DEADTIME",
+ "*turns music\nup all the\nway*"};
+ return PICK(q);
+}
+
+/* ---------------------------------------------------------------- Ice Cap */
+static void act_icecap(Battle *b, Monster *m, int act, char *t, int cap) {
+ (void)b;
+ mark_acted(m);
+ if (m->spr_override) { /* "Ice" now */
+ snprintf(t, (size_t)cap, act == 0 ? "* You inform Ice Cap that it still looks fine..." : "* ...");
+ return;
+ }
+ if (act == 0) { /* Compliment */
+ snprintf(t, (size_t)cap, "* You inform Ice Cap that it has a great hat!");
+ m->state = 1;
+ } else if (act == 1) { /* Ignore */
+ m->state2 = (int16_t)(m->state2 + 1);
+ if ((m->state2 & 0xFF) >= 2) {
+ snprintf(t, (size_t)cap, "* You continue not looking at Ice Cap's hat.\n* It seems defeated...");
+ m->spare = true;
+ } else {
+ snprintf(t, (size_t)cap, "* You manage to tear your eyes away from Ice Cap's hat.\n* It looks annoyed...");
+ }
+ m->state = 2;
+ } else { /* Steal */
+ if (m->spare) {
+ snprintf(t, (size_t)cap, "* You tried to steal Ice Cap's hat...\n* And succeeded!\n* (It melts in your hands...)");
+ m->spr_override = SPR_ICECAP_HATLESS;
+ m->exp = 25, m->gold = 40, m->spare_gold = 35, m->at = 1, m->df = -100;
+ } else {
+ snprintf(t, (size_t)cap, "* You tried to steal Ice Cap's hat...\n* ... but it's not weakened enough!");
+ m->state = 3;
+ }
+ }
+}
+static const char *talk_icecap(Battle *b, Monster *m) {
+ (void)b;
+ clear_acted(m);
+ if (m->spr_override) return "I... I...";
+ int s = m->state;
+ m->state = 0;
+ if (s == 9) return "Haha! That was\nACTUALLY\nfunny!";
+ if (s == 1) return PICK(((const char *const[]){"DUH! Who\nDOESN'T know?", "Envious? TOO\nBAD!", "My hat's too\nloud for me to\nhear you."}));
+ if (s == 2) return (m->state2 & 0xFF) >= 2 ? "Fine!!! I\ndon't care!!!" : "HELLO??? My\nhat's up here.";
+ if (s == 3) return "I KNEW IT!!!\nTHIEF!!";
+ static const char *const q[] = {"Where's YOUR\nhat?", "Your head\nlooks so\n...NAKED", "What a great\nhat! (Mine)",
+ "Snow? No! It's\nhat residue.", "I just looove\nmy hat. OK?"};
+ return PICK(q);
+}
+static int attack_icecap(Battle *b, Monster *m) {
+ (void)b;
+ return m->spr_override ? ATK_IDLE : rnd_n(2) ? ATK_ICECAP_HATS : ATK_ICECAP_WAVES;
+}
+static const char *flavor_icecap(Battle *b, Monster *m) {
+ (void)b;
+ if (m->spr_override) return "* 'Ice Cap' is no more.";
+ if (m->spare) return "* Ice Cap is desperate for attention.";
+ return NULL;
+}
+
+/* ---------------------------------------------------------------- Jerry */
+static void act_jerry(Battle *b, Monster *m, int act, char *t, int cap) {
+ (void)act;
+ snprintf(t, (size_t)cap, "* You and the other monsters ditch Jerry when it looks away!");
+ m->gone = true, m->fade = 1, m->spare_gold = 0;
+ b->state[7] = 1;
+}
+static const char *talk_jerry(Battle *b, Monster *m) {
+ if (m->state == 9) { m->state = 0; return "Hahaha! Say\nsomething else\nfunny!"; }
+ if (!others_here(b, m)) return PICK(((const char *const[]){"Well... can YOU\ngive me a ride\nhome?", "Awkwarrrd.", "The wi-fi here\nsucks."}));
+ static const char *const q[] = {"Guys, it's\nCOLD. Does\nANYONE care?", "Why are we\ndoing this?\nWhat a fail.",
+ "Wow, you guys\nSUCK at this.", "Ka-SIGH."};
+ return PICK(q);
+}
+static bool hit_jerry(Battle *b, Monster *m, int dmg) {
+ (void)b;
+ /* it takes a fifth of every hit */
+ m->hp = (int16_t)(m->hp - (dmg + 4) / 5);
+ m->hurt = 30;
+ if (m->hp <= 0) m->hp = 0, m->killed = true;
+ return true;
+}
+
+/* ---------------------------------------------------------------- Gyftrot */
+static const char *const gyft_decor[] = {
+ "* You remove the striped cane that says \"I use this tiny cane to walk\" on it.",
+ "* You remove the box of non-dog-related raisins.",
+ "* You remove the lenticular bookmark of a smug teen winking.",
+ "* You remove the barbed wire made of pipe cleaners.",
+ "* You remove a small, confused dog.",
+ "* You remove a stocking filled with chicken nuggets."};
+static void act_gyftrot(Battle *b, Monster *m, int act, char *t, int cap) {
+ (void)b;
+ mark_acted(m);
+ /* state: decorations left (3 at first, kept as 3 - state2 & 7), state: what it says next */
+ int left = 3 - (m->state2 & 7);
+ if (act == 0) { /* Decorate */
+ snprintf(t, (size_t)cap, "* You add some googly eyes you found on the ground.");
+ m->state = left == 0 ? 5 : 1;
+ if (left == 0) m->state2 = (int16_t)(m->state2 | 0x10); /* decorated again: no gift now */
+ } else if (act == 1) { /* Undecorate */
+ if (left > 0) {
+ snprintf(t, (size_t)cap, "%s", gyft_decor[(m->state2 & 7) + rnd_n(3)]);
+ m->state2 = (int16_t)(m->state2 + 1);
+ m->state = left == 1 ? 3 : 2;
+ if (left == 1) m->spare = true;
+ } else {
+ snprintf(t, (size_t)cap, "* You try to undecorate...?");
+ m->state = 4;
+ }
+ } else { /* Gift */
+ if (left > 0 || (m->state2 & 0x10)) {
+ snprintf(t, (size_t)cap, "* Gyftrot refuses your gift.");
+ m->state = left > 0 ? 6 : 7;
+ } else {
+ snprintf(t, (size_t)cap, "* You give Gyftrot a gift.");
+ m->spare_gold = 75, m->state = 8;
+ }
+ }
+}
+static const char *talk_gyftrot(Battle *b, Monster *m) {
+ (void)b;
+ clear_acted(m);
+ int s = m->state;
+ m->state = 0;
+ switch (s) {
+ case 1: return "GOSHDARN\nTEENAGE GOOGLY\nEYES!!!";
+ case 2: return "That's a\nlittle better.";
+ case 3: return "A weight has\nbeen lifted.";
+ case 4: return "Er... Those\nare real.";
+ case 5: return "I WAS STARTING\nTO TRUST YOU!!!";
+ case 6: return "How do I know\nit's not a\ntrick?";
+ case 7: return "I don't want\nyour gift!";
+ case 8: return "Aw, you\nshouldn'\nhave...";
+ }
+ if (m->spare) return "Thanks.";
+ static const char *const q[] = {"Is this funny\nto you?", "Don't put any\nmore on me!", "Leave me\nalone...",
+ "Hohoho! Go\nahead and\nlaugh...", "Get this off\nof me..."};
+ return PICK(q);
+}
+static int attack_gyftrot(Battle *b, Monster *m) { (void)b, (void)m; return rnd_n(2) ? ATK_GYFT_PRESENTS : ATK_GYFT_SNOW; }
+
+/* ---------------------------------------------------------------- the dogs: the Stick spares them */
+static bool stick_dog(Battle *b, Monster *m, int item, char *t, int cap) {
+ if (item != ITEM_STICK) return false;
+ bool pair = m->def == mon_def(MON_DOGAMY) || m->def == mon_def(MON_DOGARESSA);
+ snprintf(t, (size_t)cap, pair ? "* You threw the stick and the dogs ran to get it.\n* You played fetch for a while."
+ : "* You threw the stick and the dog ran to get it.\n* You played fetch for a while.");
+ for (int i = 0; i < b->nmon; i++)
+ if (b->mon[i].alive && !b->mon[i].gone) b->mon[i].spare = true, b->mon[i].state = 20;
+ if (m->def == mon_def(MON_DOGGO)) snow_doggo_stick();
+ return true;
+}
+
+/* Doggo: he can be pet once he's survived an attack without seeing you move */
+static void act_doggo(Battle *b, Monster *m, int act, char *t, int cap) {
+ (void)act;
+ bool calm = b->turn >= 1 && sv.hp >= m->state2;
+ if (!calm && !m->spare) {
+ snprintf(t, (size_t)cap, "* Doggo is too suspicious of your movements.");
+ m->state = 1;
+ return;
+ }
+ m->acts[5]++;
+ snprintf(t, (size_t)cap, "* You pet Doggo.");
+ m->spare = true, m->state = 2;
+ if (m->acts[5] >= 5) m->df = 0;
+}
+static const char *talk_doggo(Battle *b, Monster *m) {
+ int s = m->state;
+ m->state = 0;
+ if (s == 20) return "HUH!!! A FUN\nSTICK APPEARS!";
+ if (s == 2) {
+ switch (m->acts[5]) {
+ case 1: return "WHAT!!! I'VE\nBEEN PET!!!|PET?|PAT?|POT?";
+ case 2: return "WHERE'S THAT\nCOMING FROM!";
+ case 3: return "THERE'S NO END\nTO IT!!";
+ case 4: return "WELL, THIS IS\nTHOROUGH !!!";
+ default: return "OK. That's\nenough.";
+ }
+ }
+ if (b->turn == 0) return "Don't move an\ninch!";
+ if (sv.hp < m->state2) return "MOVING?";
+ return "Will it move\nthis time?";
+}
+static int attack_doggo(Battle *b, Monster *m) {
+ (void)b;
+ m->state2 = sv.hp; /* (unhurt by this attack: calm enough to pet) */
+ return ATK_DOGGO_SWORD;
+}
+static const char *flavor_doggo(Battle *b, Monster *m) {
+ if (m->spare) return "* Doggo has been pet.";
+ if (b->turn >= 1 && sv.hp >= m->state2) return "* Doggo can't seem to find anything.";
+ return NULL;
+}
+
+/* Lesser Dog: a pet spares it; more pets raise its head ever higher */
+static void act_lesserdog(Battle *b, Monster *m, int act, char *t, int cap) {
+ (void)b, (void)act;
+ static const char *const pet[] = {
+ "* You barely lifted your hand and Lesser Dog got excited.",
+ "* You lightly touched the Dog.\n* It's already overexcited...",
+ "* You pet the Dog.\n* It raises its head up to meet your hand.",
+ "* You pet the Dog.\n* It was a good Dog.",
+ "* You pet the Dog.\n* Its excitement knows no bounds.",
+ "* Critical pet!\n* Dog excitement increased.",
+ "* You have to jump up to pet the Dog.",
+ "* You don't even pet it.\n* It gets more excited.",
+ "* There is no way to stop this madness.",
+ "* Lesser Dog enters the realm of the clouds.",
+ "* You call the Dog but it is too late.\n* It cannot hear you.",
+ "* ...",
+ "* You can reach Lesser Dog again."};
+ int n = m->acts[5]++;
+ if (n < 13) snprintf(t, (size_t)cap, "%s", pet[n]);
+ else if (n < 19) snprintf(t, (size_t)cap, "* You pet Lesser Dog.");
+ else if (n < 33) snprintf(t, (size_t)cap, "* It's possible that you may have a problem.");
+ else if (n < 44) snprintf(t, (size_t)cap, "* Lesser Dog is unpettable but appreciates the attempt.");
+ else snprintf(t, (size_t)cap, "* Perhaps mankind was not meant to pet this much.");
+ m->spare = true;
+ m->state = 1;
+}
+static const char *talk_lesserdog(Battle *b, Monster *m) {
+ (void)b;
+ int n = m->acts[5];
+ if (m->state == 20) { m->state = 0; return "(Wag wag)"; }
+ if (m->state == 1) {
+ m->state = 0;
+ if (n <= 3) return "(Pant! Pant!)";
+ if (n <= 6) return "(Excited\nnoises)";
+ static const char *const q[] = {"(Motor\nrevving)", "(Plane\ntakeoff)", "(Kettle\nwhistle)", "(...)", "(Faraway\nbark)", "(...)", "(Bark)"};
+ if (n <= 13) return q[n - 7];
+ return "(Pant pant)";
+ }
+ static const char *const q[] = {"(Pant pant)", "(Wag wag)", "(Thinks of\nfood)", "(Tiny bark)"};
+ return PICK(q);
+}
+static int attack_lesserdog(Battle *b, Monster *m) {
+ (void)b;
+ if (m->acts[5] >= 6) return ATK_IDLE; /* (a critical pet: too excited to attack) */
+ return rnd_n(2) ? ATK_LDOG_JUMP : ATK_LDOG_SPEARS;
+}
+static void draw_lesserdog(Battle *b, Monster *m, int x, int y) {
+ (void)b;
+ /* each pet lifts its head: its neck grows */
+ int neck = min_i(m->acts[5], 13) * 7;
+ if (m->acts[5] >= 34) neck = 0;
+ if (neck) gfx_rect(x - 4, y - 46 - neck, 9, neck + 4, C_WHITE, 255);
+ gfx_sprite(m->hurt ? SPR_LESSERDOG_HURT : SPR_LESSERDOG_B, m->hurt ? 0 : (int)(g_frame / 6), x, y - neck * 0, 0, 255);
+}
+
+/* the Dogi: roll in the snow, let them re-sniff you, then pet them both */
+static void act_dogi(Battle *b, Monster *m, int act, char *t, int cap) {
+ bool husband = m->def == mon_def(MON_DOGAMY);
+ /* b->state[0]: rolled around, [1]: re-sniffed after, [2], [3]: Dogamy, Dogaressa pet */
+ if (act == 0) { /* Pet */
+ if (!b->state[1]) {
+ snprintf(t, (size_t)cap, husband ? "* The Dogs are too suspicious of your smell." : "* The Dogaressa is too suspicious of your smell.");
+ } else {
+ snprintf(t, (size_t)cap, husband ? "* You pet Dogamy." : "* You pet the Dogaressa.");
+ b->state[husband ? 2 : 3] = 1;
+ m->state = 1;
+ /* both pet: their minds expanded */
+ if (b->state[2] && b->state[3])
+ for (int i = 0; i < b->nmon; i++) b->mon[i].spare = true;
+ else if (count_alive() == 1)
+ m->spare = true;
+ }
+ } else if (act == 1) { /* Re-sniff */
+ if (b->state[1]) snprintf(t, (size_t)cap, "* The Dogs already know you smell fine.");
+ else if (b->state[0]) snprintf(t, (size_t)cap, "* The Dogs sniff you again...\n* After rolling in the dirt, you smell all right!"), b->state[1] = 1;
+ else snprintf(t, (size_t)cap, "* The Dogs sniff you again...\n* But you smell just as weird as before!");
+ } else { /* Roll Around */
+ snprintf(t, (size_t)cap, "* You roll around in the dirt and snow.\n* You smell like a weird puppy.");
+ b->state[0] = 1;
+ }
+}
+static const char *talk_dogamy(Battle *b, Monster *m) {
+ if (count_alive() == 1) return "...";
+ if (b->state[2] && b->state[3]) return "Dogs can pet\nother dogs???";
+ if (m->state == 20) return "A stick!";
+ if (b->state[1]) return "Smells like a\nlittle puppy!";
+ if (b->state[0]) return "Hmm? Huh?";
+ static const char *const q[] = {"Hmm? Is that\na...", "Huh? What's\nthat smell?", "Don't touch\nmy wife!"};
+ return PICK(q);
+}
+static const char *talk_dogaressa(Battle *b, Monster *m) {
+ if (count_alive() == 1) return "...";
+ if (b->state[2] && b->state[3]) return "A new world\n... !";
+ if (m->state == 20) return "Fetch!!!";
+ if (b->state[1]) return "(A puppy?)";
+ static const char *const q[] = {"(I smell it\ntoo...)", "(Hands off\nmy hubby!)", "(Weird smell...)"};
+ return PICK(q);
+}
+static int attack_dogi(Battle *b, Monster *m) {
+ /* alone, each has its own: Dogamy's sad hearts, Dogaressa's angry axes; together they take turns */
+ if (count_alive() == 1) return m->def == mon_def(MON_DOGAMY) ? ATK_DOGI_HEARTS : ATK_DOGI_AXES;
+ return b->turn % 2 ? ATK_DOGI_HEARTS : ATK_DOGI_AXES;
+}
+
+/* Greater Dog: call it (or ignore it), pet it, play with it, pet it twice */
+static void act_greaterdog(Battle *b, Monster *m, int act, char *t, int cap) {
+ (void)b;
+ int s = m->state & 0xFF;
+ if (act == 0) { /* Pet */
+ if (s == 1) {
+ snprintf(t, (size_t)cap, "* Greater Dog flops into your lap for pets and dozes off...|* ...then bolts awake, thrilled!");
+ m->state = 2, m->df = -20;
+ } else if (s == 3) {
+ snprintf(t, (size_t)cap, "* You pet the dog. It leans all its weight on you.\n* More pets are needed...!");
+ m->state = 4;
+ } else if (s == 4) {
+ snprintf(t, (size_t)cap, "* One last, perfect pet.\n* The dog rolls over, completely satisfied.");
+ m->state = 5, m->spare = true;
+ } else if (s == 5) {
+ snprintf(t, (size_t)cap, "* Tummy rubs are forbidden.");
+ } else if (s == 2) {
+ snprintf(t, (size_t)cap, "* Greater Dog's excitement is creating a power field that prevents petting.");
+ } else {
+ snprintf(t, (size_t)cap, "* Greater Dog is too far away to pet.\n* You just pet the air.");
+ }
+ } else if (act == 1) { /* Beckon */
+ if (s == 0) snprintf(t, (size_t)cap, "* You call the Greater Dog.\n* It bounds towards you, flecking slobber into your face."), m->state = 1;
+ else snprintf(t, (size_t)cap, "* The Greater Dog's ears perk up.\n* Nothing else happens.");
+ } else if (act == 2) { /* Play */
+ if (s == 2) {
+ snprintf(t, (size_t)cap, "* You toss a snowball. It falls apart.|* Greater Dog fetches ALL the snow anyway.\n* Worn out, it rests its head on you...");
+ m->state = 3;
+ } else if (s >= 3) {
+ snprintf(t, (size_t)cap, "* Greater Dog is too tired to play.");
+ } else {
+ snprintf(t, (size_t)cap, "* Greater Dog is not excited enough to play with.");
+ }
+ } else { /* Ignore */
+ m->state2 = (int16_t)(m->state2 + 1);
+ if (m->state2 >= 4) {
+ snprintf(t, (size_t)cap, "* Greater Dog decides you are too boring.");
+ m->gone = true, m->fade = 1;
+ } else {
+ snprintf(t, (size_t)cap, "* Greater Dog inches closer.");
+ if (s == 0) m->state = 1;
+ }
+ }
+}
+static const char *flavor_greaterdog(Battle *b, Monster *m) {
+ (void)b;
+ switch (m->state & 0xFF) {
+ case 1: return "* Greater Dog just wants affection.";
+ case 2: return "* Greater Dog is patting the ground with its front paws.";
+ case 3: return "* Greater Dog wants some TLC.";
+ case 4: return "* Pet capacity is 40-percent.";
+ case 5: return "* Greater Dog is contented.";
+ }
+ return NULL;
+}
+static int attack_greaterdog(Battle *b, Monster *m) { (void)b, (void)m; return rnd_n(2) ? ATK_GDOG_SPEAR : ATK_GDOG_BARK; }
+
+/* ---------------------------------------------------------------- Glyde */
+static void act_glyde(Battle *b, Monster *m, int act, char *t, int cap) {
+ (void)b;
+ /* state: applause (to 2), state2: nothings after them */
+ if (act == 0) {
+ m->state++;
+ snprintf(t, (size_t)cap, m->state == 1 ? "* You clap really sloppily.\n* Glyde sucks up your praise like a vacuum cleaner."
+ : "* You clap like a gorilla.\n* Glyde is becoming addicted to your praise.");
+ m->state2 = 0;
+ } else if (act == 1) {
+ if (m->state >= 2 && m->state2 >= 2) {
+ snprintf(t, (size_t)cap, "* You boo loudly.\n* Glyde leaves to look elsewhere for praise.");
+ m->gone = true, m->fade = 1;
+ } else {
+ snprintf(t, (size_t)cap, "* You boo... but haters only make Glyde stronger.\n* Glyde ATTACK UP+DEFENSE DOWN.");
+ m->at = (int16_t)(m->at + 2), m->df = (int16_t)(m->df - 10);
+ }
+ } else {
+ if (m->state < 2) {
+ snprintf(t, (size_t)cap, "* You do nothing.\n* No effect.");
+ } else {
+ m->state2++;
+ if (m->state2 >= 3) snprintf(t, (size_t)cap, "* You do nothing.\n* Glyde leaves to look elsewhere for praise."), m->gone = true, m->fade = 1;
+ else if (m->state2 == 2) snprintf(t, (size_t)cap, "* You do nothing.\n* Glyde looks desperate for attention.");
+ else snprintf(t, (size_t)cap, "* You do nothing.\n* Glyde looks disappointed you aren't paying attention.");
+ }
+ }
+}
+static const char *talk_glyde(Battle *b, Monster *m) {
+ (void)b;
+ if (m->state == 1 && m->state2 == 0) return "OK! I rule!\nI admit it!";
+ if (m->state >= 2 && m->state2 == 0) return "What else do\nyou have to\nsay!?";
+ if (m->state >= 2 && m->state2 == 1) return "Eh? You forgot\nto clap.";
+ if (m->state >= 2 && m->state2 == 2) return "HELLO?? I'M\nRIGHT HERE!!!";
+ static const char *const q[] = {"How great\nI am.", "Look. Watch.\nObserve.", "Wow. Check out\nmy pecs.", "Sorry... for\nNOTHING\n*ollies*"};
+ return PICK(q);
+}
+static int attack_glyde(Battle *b, Monster *m) { (void)b, (void)m; return ATK_GLYDE_STARS; }
+
+/* ---------------------------------------------------------------- the table */
+extern const MonDef papyrus_def; /* papyrus.c */
+static const MonDef snow_defs[MON_COUNT - MON_RUINS_COUNT] = {
+ [MON_SNOWDRAKE - MON_RUINS_COUNT] = {
+ .name = "Snowdrake", .spare_gold = 12, .hp = 74, .at = 6, .df = 2, .exp = 22, .gold = 18, .spr_idle = SPR_SNOWDRAKE_B,
+ .spr_hurt = SPR_SNOWDRAKE_HURT, .idle_speed = 8, .check = "This teen comedian fights to keep a captive audience.",
+ .acts = {"Heckle", "Laugh", "Joke"}, .nacts = 3,
+ .neutral = {"* Snowdrake is assessing the crowd.", "* Snowdrake is practicing its next pun.",
+ "* Snowdrake is smiling at its own bad joke."},
+ .act = act_snowdrake, .talk = talk_snowdrake, .attack = attack_drake},
+ [MON_ICECAP - MON_RUINS_COUNT] = {
+ .name = "Ice Cap", .spare_gold = 13, .hp = 48, .at = 6, .df = 0, .exp = 17, .gold = 17, .spr_idle = SPR_ICECAP_B,
+ .spr_hurt = SPR_ICECAP_HURT, .idle_speed = 6, .check = "This teen wonders why it isn't named 'Ice Hat.'",
+ .acts = {"Compliment", "Ignore", "Steal"}, .nacts = 3,
+ .neutral = {"* It's snowing dandruff.", "* Ice Cap also wants a hat for its nose.",
+ "* Ice Cap makes sure its hat is still there.", "* Ice Cap is thinking about a certain article of clothing.",
+ "* Here comes that new clothes smell."},
+ .low_hp = "* Ice Cap's hat is loose.", .act = act_icecap, .talk = talk_icecap, .attack = attack_icecap,
+ .flavor = flavor_icecap},
+ [MON_GYFTROT - MON_RUINS_COUNT] = {
+ .name = "Gyftrot", .spare_gold = 20, .hp = 114, .at = 7, .df = 3, .exp = 35, .gold = 30, .spr_idle = SPR_GYFTROT_B,
+ .spr_hurt = SPR_GYFTROT_HURT, .idle_speed = 8, .check = "Some teens \"decorated\" it as a prank.",
+ .acts = {"Decorate", "Undecorate", "Gift"}, .nacts = 3,
+ .neutral = {"* Gyftrot laments its lack of hands.", "* Gyftrot eyes you with suspicion.",
+ "* Gyftrot distrusts your youthful demeanor.", "* Ah, the scent of fresh pine needles.",
+ "* Gyftrot tries vainly to remove its decorations."},
+ .act = act_gyftrot, .talk = talk_gyftrot, .attack = attack_gyftrot},
+ [MON_DOGGO - MON_RUINS_COUNT] = {
+ .name = "Doggo", .spare_gold = 30, .hp = 70, .at = 6, .df = 1, .exp = 30, .gold = 30, .spr_idle = SPR_DOGGO_B, .spr_hurt = SPR_DOGGO_HURT,
+ .idle_speed = 6, .check = "Easily excited by movement. Hobbies include: squirrels.", .acts = {"Pet"}, .nacts = 1,
+ .neutral = {"* Doggo is too suspicious of your movements."},
+ .act = act_doggo, .talk = talk_doggo, .attack = attack_doggo, .flavor = flavor_doggo, .on_item = stick_dog},
+ [MON_LESSERDOG - MON_RUINS_COUNT] = {
+ .name = "Lesser Dog", .spare_gold = 15, .hp = 60, .at = 6, .df = 0, .exp = 18, .gold = 15, .spr_idle = SPR_LESSERDOG_B,
+ .spr_hurt = SPR_LESSERDOG_HURT, .idle_speed = 6, .check = "Wields a stone dogger made of pomer-granite.",
+ .acts = {"Pet", "Pet", "Pet", "Pet", "Pet"}, .nacts = 5,
+ .neutral = {"* Lesser Dog cocks its head to one side.", "* Lesser Dog thinks your weapon is a dog treat.",
+ "* Lesser Dog is really not paying attention.", "* Smells like dog chow."},
+ .act = act_lesserdog, .talk = talk_lesserdog, .attack = attack_lesserdog, .draw = draw_lesserdog,
+ .on_item = stick_dog},
+ [MON_DOGAMY - MON_RUINS_COUNT] = {
+ .name = "Dogamy", .spare_gold = 20, .hp = 108, .at = 6, .df = 4, .exp = 30, .gold = 25, .spr_idle = SPR_DOGAMY_B, .spr_hurt = SPR_DOGAMY_B,
+ .check = "Husband of Dogaressa.\n* Knows only what he smells.", .acts = {"Pet", "Re-sniff", "Roll Around"}, .nacts = 3,
+ .neutral = {"* The Dogs keep shifting their axes to protect each other.", "* The Dogs are re-evaluating your smell.",
+ "* The Dogs are practicing for the next couples contest.",
+ "* The Dogs are saying sickly sweet things to each other."},
+ .act = act_dogi, .talk = talk_dogamy, .attack = attack_dogi, .on_item = stick_dog},
+ [MON_DOGARESSA - MON_RUINS_COUNT] = {
+ .name = "Dogaressa", .spare_gold = 20, .hp = 108, .at = 6, .df = 4, .exp = 30, .gold = 25, .spr_idle = SPR_DOGARESSA_B,
+ .spr_hurt = SPR_DOGARESSA_B, .check = "This dog's wife.\n* Only knows what she smells.", .acts = {"Pet", "Re-sniff", "Roll Around"},
+ .nacts = 3,
+ .neutral = {"* The Dogs keep shifting their axes to protect each other.", "* The Dogs are re-evaluating your smell."},
+ .act = act_dogi, .talk = talk_dogaressa, .attack = attack_dogi, .on_item = stick_dog},
+ [MON_GREATERDOG - MON_RUINS_COUNT] = {
+ .name = "Greater Dog", .spare_gold = 40, .hp = 105, .at = 6, .df = 4, .exp = 80, .gold = 60, .spr_idle = SPR_GREATERDOG_B,
+ .spr_hurt = SPR_GREATERDOG_HURT, .idle_speed = 10, .check = "It's so excited that it thinks fighting is just play.",
+ .acts = {"Pet", "Beckon", "Play", "Ignore"}, .nacts = 4,
+ .neutral = {"* Greater Dog is watching you intently.", "* Greater Dog is waiting for your command.",
+ "* It smells like freshly-squeezed puppy juice.", "* Greater Dog is seeking affection."},
+ .quotes = {"(Bark!)", "(Pant pant)", "(Wag wag)"},
+ .low_hp = "* Greater Dog is panting slowly.", .act = act_greaterdog, .attack = attack_greaterdog,
+ .flavor = flavor_greaterdog, .on_item = stick_dog},
+ [MON_JERRY - MON_RUINS_COUNT] = {
+ .name = "Jerry", .hp = 80, .at = 1, .df = 8, .exp = 1, .gold = 55, .spr_idle = SPR_JERRY_B, .spr_hurt = SPR_JERRY_HURT,
+ .idle_speed = 6, .dy = 10, .check = "Everyone knows Jerry.\n* Makes attacks 2 seconds longer.", .acts = {"Ditch"},
+ .nacts = 1,
+ .neutral = {"* Jerry eats powdery food and licks its hands loudly.", "* Jerry sneezes without covering its nose.",
+ "* Jerry tells everyone it has to go to the bathroom.", "* Jerry lets out a yawn.",
+ "* Smells like....... Jerry."},
+ .low_hp = "* Jerry is wounded.", .act = act_jerry, .talk = talk_jerry, .on_hit = hit_jerry},
+ [MON_CHILLDRAKE - MON_RUINS_COUNT] = {
+ .name = "Chilldrake", .spare_gold = 12, .hp = 74, .at = 6, .df = 2, .exp = 22, .gold = 18, .spr_idle = SPR_CHILLDRAKE_B,
+ .spr_hurt = SPR_CHILLDRAKE_B, .idle_speed = 8, .check = "Rebels against everything!!\n* Looking for its friend Snowy.",
+ .acts = {"Clash", "Agree", "Joke"}, .nacts = 3,
+ .neutral = {"* Chilldrake starts a one-monster riot.", "* Chilldrake is chanting an anarchist spell.",
+ "* Chilldrake is eating its own homework.", "* It smells like \"Ice\" scented body-spray.",
+ "* Chilldrake is wondering where Snowy went."},
+ .act = act_chilldrake, .talk = talk_chilldrake, .attack = attack_drake},
+ [MON_GLYDE - MON_RUINS_COUNT] = {
+ .name = "Glyde", .spare_gold = 120, .hp = 220, .at = 9, .df = -20, .exp = 100, .gold = 140, .spr_idle = SPR_GLYDE_B,
+ .spr_hurt = SPR_GLYDE_HURT, .idle_speed = 6, .dy = -6, .check = "Refuses to give more details about its statistics.",
+ .acts = {"Applaud", "Boo", "Nothing"}, .nacts = 3,
+ .neutral = {"* Glyde does fancy flips.", "* Glyde is giving itself a high five.\n* ... somehow.",
+ "* Glyde sees its reflection and gets jealous.", "* An arrogant-smelling wind blows through."},
+ .act = act_glyde, .talk = talk_glyde, .attack = attack_glyde},
+};
+const MonDef *snow_mon_def(int id) {
+ if (id == MON_PAPYRUS) return &papyrus_def;
+ return &snow_defs[id - MON_RUINS_COUNT];
+}
+
+static const Form snow_forms[FORM_COUNT - FORM_RUINS_COUNT] = {
+ [FORM_SNOWDRAKE - FORM_RUINS_COUNT] = {{MON_SNOWDRAKE}, 1, "* Snowdrake flutters forth!"},
+ [FORM_ICECAP - FORM_RUINS_COUNT] = {{MON_ICECAP}, 1, "* Icecap struts into view."},
+ [FORM_LESSERDOG - FORM_RUINS_COUNT] = {{MON_LESSERDOG}, 1, "* Lesser Dog appears."},
+ [FORM_CHILLDRAKE - FORM_RUINS_COUNT] = {{MON_CHILLDRAKE}, 1, "* Chilldrake saunters up!"},
+ [FORM_ICECAP_JERRY - FORM_RUINS_COUNT] = {{MON_ICECAP, MON_JERRY}, 2, "* Icecap appears.\n* Jerry came too."},
+ [FORM_ICECAP_JERRY_SNOWDRAKE - FORM_RUINS_COUNT] = {{MON_SNOWDRAKE, MON_ICECAP, MON_JERRY}, 3,
+ "* Icecap and Snowdrake confront you, sighing.\n* Jerry."},
+ [FORM_ICECAP_JERRY_CHILLDRAKE - FORM_RUINS_COUNT] = {{MON_CHILLDRAKE, MON_ICECAP, MON_JERRY}, 3,
+ "* Icecap and Chilldrake confront you, sighing.\n* Jerry."},
+ [FORM_GYFTROT - FORM_RUINS_COUNT] = {{MON_GYFTROT}, 1, "* Gyftrot confronts you!"},
+ [FORM_GLYDE - FORM_RUINS_COUNT] = {{MON_GLYDE}, 1, "* Glyde swooped in!"},
+ [FORM_DOGGO - FORM_RUINS_COUNT] = {{MON_DOGGO}, 1, "* Doggo blocks the way!"},
+ [FORM_DOGI - FORM_RUINS_COUNT] = {{MON_DOGAMY, MON_DOGARESSA}, 2, "* Dogi assault you!"},
+ [FORM_GREATERDOG - FORM_RUINS_COUNT] = {{MON_GREATERDOG}, 1, "* It's the Greater Dog."},
+ [FORM_PAPYRUS - FORM_RUINS_COUNT] = {{MON_PAPYRUS}, 1, "* Papyrus blocks the way!"},
+};
+const Form *snow_form(int form) { return &snow_forms[form - FORM_RUINS_COUNT]; }
+
+/* random encounters: the wiki's pools (no more of them once Papyrus is spared with no one killed here) */
+int snow_encounter(int room) {
+ if (flag(F_PAPYRUS) == 1 && !flag(F_KILLS_SNOWDIN)) return -1;
+ int drake = flag(F_SNOWDRAKE_DEAD) ? FORM_CHILLDRAKE : FORM_SNOWDRAKE;
+ bool lesser = !flag(F_LESSERDOG) && rnd_n(4) == 0;
+ switch (room) {
+ case ROOM_BOXROAD: case ROOM_PAPSENTRY: case ROOM_ICEFIELD:
+ if (lesser) return FORM_LESSERDOG;
+ return rnd_n(2) ? drake : FORM_ICECAP;
+ case ROOM_SNOWPUZZLE: case ROOM_DANGERBRIDGE:
+ if (lesser) return FORM_LESSERDOG;
+ if (rnd_n(2)) return FORM_ICECAP_JERRY;
+ return flag(F_SNOWDRAKE_DEAD) ? FORM_ICECAP_JERRY_CHILLDRAKE : FORM_ICECAP_JERRY_SNOWDRAKE;
+ case ROOM_SOUTHCLIFF: return FORM_GYFTROT;
+ case ROOM_DOORROOM: return FORM_GLYDE;
+ }
+ return -1;
+}
+
+/* ---------------------------------------------------------------- attacks */
+static int bx0(void) { return bt.x0 + 3; }
+static int bx1(void) { return bt.x1 - 3; }
+static int by0(void) { return bt.y0 + 3; }
+static int by1(void) { return bt.y1 - 3; }
+#define P(v) ((v) * FX)
+static Bullet *shot(uint16_t spr, int x, int y, int vx, int vy) {
+ Bullet *b = bullet_new(spr, P(x), P(y), vx, vy);
+ if (b) b->owner = (uint8_t)bt.atk_owner;
+ return b;
+}
+/* aimed at the SOUL, sp (1/16 px) a frame */
+static void aim(Bullet *b, int sp) {
+ int dx = bt.sx - b->x, dy = bt.sy - b->y;
+ int d = abs_i(dx) + abs_i(dy);
+ if (d) b->vx = dx * sp / d, b->vy = dy * sp / d;
+}
+
+/* Snowdrake: crescents falling in arcs from the top corners / in lines at the SOUL */
+static void atk_drake_arcs(int t) {
+ if (t < 120 && t % 14 == 0) {
+ bool left = (t / 14) % 2;
+ Bullet *b = shot(SPR_ICESHARD, left ? bx0() : bx1(), by0(), (left ? 1 : -1) * (P(1) + rnd_n(P(1))), -P(1));
+ if (b) b->kind = BK_GRAVITY, b->ay = 3, b->r = 3;
+ }
+}
+static void atk_drake_lines(int t) {
+ if (t < 120 && t % 20 == 0) {
+ int x = bx0() + 8 + rnd_n(bx1() - bx0() - 16);
+ for (int k = 0; k < 3; k++) {
+ Bullet *b = shot(SPR_ICESHARD, x + (k - 1) * 10, by0() - 10 - k * 6, 0, 0);
+ if (b) aim(b, P(2)), b->r = 3;
+ }
+ }
+}
+/* Ice Cap: ice shot up from hats at the bottom, falling back; zig-zag walls closing top and bottom */
+static void atk_icecap_hats(int t) {
+ if (t < 120 && t % 18 == 0) {
+ Bullet *b = shot(SPR_ICESHARD, bx0() + 8 + rnd_n(bx1() - bx0() - 16), by1(), rnd_n(P(1)) - P(1) / 2, -P(4));
+ if (b) b->kind = BK_GRAVITY, b->ay = 5, b->r = 3;
+ }
+}
+static void atk_icecap_waves(int t) {
+ /* columns of blocks scroll in from the right, their gaps zig-zagging */
+ if (t < 130 && t % 6 == 0) {
+ int h = by1() - by0();
+ int gap_mid = by0() + h / 2 + ((t / 6) % 8 < 4 ? (t / 6) % 4 : 4 - (t / 6) % 4) * h / 10 - h / 5;
+ for (int side = 0; side < 2; side++) {
+ int y0 = side ? gap_mid + 13 : by0(), y1 = side ? by1() : gap_mid - 13;
+ if (y1 <= y0) continue;
+ Bullet *b = shot(SPR_BONE, bx1() + 4, (y0 + y1) / 2, -P(2), 0);
+ if (b) b->flags |= BF_BOX, b->w = 5, b->h = (int16_t)(y1 - y0);
+ }
+ }
+}
+/* Gyftrot: three presents rise from the bottom (one blue: keep still), snowflakes fall in waves */
+static void atk_gyft_presents(int t) {
+ if (t % 50 == 0 && t < 130) {
+ int blue = rnd_n(3);
+ for (int k = 0; k < 3; k++) {
+ Bullet *b = shot(SPR_PRESENT, bx0() + (bx1() - bx0()) * (k + 1) / 4, by1() + 4, 0, -P(1) - P(1) / 2);
+ if (b) b->color = (uint8_t)(k == blue ? BC_BLUE : BC_WHITE), b->r = 4;
+ }
+ }
+}
+static void atk_gyft_snow(int t) {
+ if (t < 130 && t % 8 == 0) {
+ Bullet *b = shot(SPR_SNOWFLAKE, bx0() + 6 + rnd_n(bx1() - bx0() - 12), by0() - 4, 0, P(1) + P(1) / 4);
+ if (b) b->kind = BK_SCRIPT, b->a = (int16_t)(b->x / FX), b->r = 3;
+ }
+ for (int i = 0; i < MAX_BULLETS; i++) {
+ Bullet *b = &bullets[i];
+ if (b->kind != BK_SCRIPT || b->spr != SPR_SNOWFLAKE) continue;
+ b->t++;
+ b->y += b->vy;
+ b->x = P(b->a) + P(8) * gfx_sin(b->t * 4) / 1024;
+ if (b->y > P(by1() + 8)) b->kind = BK_NONE;
+ }
+}
+/* Doggo: a blue blade sweeps across the board (still, it can't see you) */
+static void atk_doggo_sword(int t) {
+ if (t == 10 || t == 80) {
+ bool right = t == 80;
+ Bullet *b = shot(SPR_BONE, right ? bx1() + 6 : bx0() - 6, (by0() + by1()) / 2, right ? -P(3) : P(3), 0);
+ if (b) b->flags |= BF_BOX, b->w = 4, b->h = (int16_t)(by1() - by0()), b->color = BC_BLUE;
+ }
+}
+/* Lesser Dog: a little dog runs on the spot, then leaps at the SOUL; or spears, blue then white */
+static void atk_ldog_jump(int t) {
+ if (t == 0) {
+ Bullet *b = shot(SPR_DOG_OW, bx1() - 10, by1() - 8, 0, 0);
+ if (b) b->kind = BK_SCRIPT, b->r = 6, b->anim = 4;
+ }
+ for (int i = 0; i < MAX_BULLETS; i++) {
+ Bullet *b = &bullets[i];
+ if (b->kind != BK_SCRIPT || b->spr != SPR_DOG_OW) continue;
+ b->t++;
+ if (b->t % 4 == 0) b->frame++;
+ if (b->t == 40 || b->t == 100) aim(b, P(3)), b->vy -= P(2), b->c = 1;
+ if (b->c) {
+ b->vy += 4;
+ b->x += b->vx, b->y += b->vy;
+ if (b->y > P(by1() - 8)) b->y = P(by1() - 8), b->vx = b->vy = 0, b->c = 0;
+ if (b->x < P(bx0() + 6)) b->x = P(bx0() + 6);
+ if (b->x > P(bx1() - 6)) b->x = P(bx1() - 6);
+ }
+ }
+}
+static void atk_ldog_spears(int t) {
+ if (t == 5) {
+ Bullet *b = shot(SPR_BONE, bx1() + 20, (by0() + by1()) / 2, -P(3), 0);
+ if (b) b->flags |= BF_BOX, b->w = 40, b->h = 4, b->color = BC_BLUE;
+ }
+ if (t == 70) {
+ bool left = rnd_n(2);
+ Bullet *b = shot(SPR_BONE, left ? bx0() - 20 : bx1() + 20, by0() + 10 + rnd_n(by1() - by0() - 20), left ? P(3) : -P(3), 0);
+ if (b) b->flags |= BF_BOX, b->w = 40, b->h = 4, b->kind = BK_SCRIPT, b->a = left;
+ }
+ for (int i = 0; i < MAX_BULLETS; i++) {
+ Bullet *b = &bullets[i];
+ if (b->kind != BK_SCRIPT || b->spr != SPR_BONE) continue;
+ b->t++;
+ if (b->t < 26) b->x += b->vx;
+ else if (b->t > 50) b->x -= b->vx;
+ }
+}
+/* the Dogi: two axes rise, then swing down crossing; a ring of hearts barked from one to the other (half blue) */
+static void atk_dogi_axes(int t) {
+ if (t == 0 || t == 70) {
+ for (int k = 0; k < 2; k++) {
+ Bullet *b = shot(SPR_KNIFE, k ? bx1() - 14 : bx0() + 14, by0() + 18, 0, -P(1) / 2);
+ if (b) b->kind = BK_SCRIPT, b->a = (int16_t)k, b->r = 5;
+ }
+ }
+ for (int i = 0; i < MAX_BULLETS; i++) {
+ Bullet *b = &bullets[i];
+ if (b->kind != BK_SCRIPT || b->spr != SPR_KNIFE) continue;
+ b->t++;
+ if (b->t < 16) b->y += b->vy;
+ else b->x += b->a ? -P(2) : P(2), b->y += P(1);
+ if (b->t > 70) b->kind = BK_NONE;
+ }
+}
+static void atk_dogi_hearts(int t) {
+ if (t % 50 == 5 && t < 120) {
+ int cy = by0() + 12 + rnd_n(by1() - by0() - 24);
+ for (int k = 0; k < 8; k++) {
+ Bullet *b = shot(SPR_HEARTBULLET, bx0() - 10, cy, P(2), 0);
+ if (b) b->kind = BK_ORBIT, b->a = (int16_t)(bx0() - 10), b->b = (int16_t)cy, b->c = P(13), b->d = (int16_t)(k * 32 * 16),
+ b->vx = 40, b->vy = 0, b->color = (uint8_t)(k % 2 ? BC_BLUE : BC_WHITE), b->r = 3, b->ax = P(2);
+ }
+ }
+ /* the ring's middle moves across */
+ for (int i = 0; i < MAX_BULLETS; i++) {
+ Bullet *b = &bullets[i];
+ if (b->kind == BK_ORBIT && b->spr == SPR_HEARTBULLET) b->a = (int16_t)(b->a + 2);
+ }
+}
+/* Greater Dog: its spear flies right to left flickering blue and white; a sleeping dog barks if you move */
+static void atk_gdog_spear(int t) {
+ if (t % 45 == 0 && t < 130) {
+ Bullet *b = shot(SPR_BONE, bx1() + 20, by0() + 8 + rnd_n(by1() - by0() - 16), -P(3), 0);
+ if (b) b->flags |= BF_BOX, b->w = 36, b->h = 4, b->kind = BK_SCRIPT;
+ }
+ for (int i = 0; i < MAX_BULLETS; i++) {
+ Bullet *b = &bullets[i];
+ if (b->kind != BK_SCRIPT || b->spr != SPR_BONE) continue;
+ b->t++;
+ b->x += b->vx;
+ b->color = (uint8_t)((b->t / 10) % 2 ? BC_BLUE : BC_WHITE);
+ if (b->x < P(bx0() - 30)) b->kind = BK_NONE;
+ }
+}
+static void atk_gdog_bark(int t) {
+ static int32_t lx, ly;
+ if (t == 0) {
+ lx = bt.sx, ly = bt.sy;
+ Bullet *d = shot(SPR_DOG_OW, (bx0() + bx1()) / 2, by1() - 6, 0, 0);
+ if (d) d->kind = BK_SCRIPT, d->flags |= BF_HARMLESS;
+ }
+ if (t > 10 && t % 16 == 0 && (bt.sx != lx || bt.sy != ly)) {
+ Bullet *b = shot(SPR_HEARTBULLET, (bx0() + bx1()) / 2, by1() - 14, 0, 0);
+ if (b) aim(b, P(2)), b->r = 3;
+ }
+ lx = bt.sx, ly = bt.sy;
+}
+/* Glyde: waves of stars */
+static void atk_glyde_stars(int t) {
+ if (t < 140 && t % 24 == 0) {
+ bool left = (t / 24) % 2;
+ for (int k = 0; k < 5; k++) {
+ Bullet *b = shot(SPR_SNOWFLAKE, left ? bx0() - 6 : bx1() + 6, by0() + 6 + k * (by1() - by0() - 12) / 4, left ? P(2) : -P(2),
+ (k - 2) * 6);
+ if (b) b->r = 3, b->angle = 1;
+ }
+ }
+}
+
+static const int16_t snow_lengths[ATK_COUNT - ATK_RUINS_COUNT] = {
+ [ATK_DRAKE_ARCS - ATK_RUINS_COUNT] = 150, [ATK_DRAKE_LINES - ATK_RUINS_COUNT] = 150,
+ [ATK_ICECAP_HATS - ATK_RUINS_COUNT] = 150, [ATK_ICECAP_WAVES - ATK_RUINS_COUNT] = 180,
+ [ATK_GYFT_PRESENTS - ATK_RUINS_COUNT] = 170, [ATK_GYFT_SNOW - ATK_RUINS_COUNT] = 160,
+ [ATK_DOGGO_SWORD - ATK_RUINS_COUNT] = 150, [ATK_LDOG_JUMP - ATK_RUINS_COUNT] = 150,
+ [ATK_LDOG_SPEARS - ATK_RUINS_COUNT] = 140, [ATK_DOGI_AXES - ATK_RUINS_COUNT] = 150,
+ [ATK_DOGI_HEARTS - ATK_RUINS_COUNT] = 170, [ATK_GDOG_SPEAR - ATK_RUINS_COUNT] = 160,
+ [ATK_GDOG_BARK - ATK_RUINS_COUNT] = 150, [ATK_GLYDE_STARS - ATK_RUINS_COUNT] = 170,
+};
+int papyrus_attack_length(int atk); /* papyrus.c */
+void papyrus_attack(int atk, int t);
+void papyrus_attack_draw(int atk, int t);
+
+int snow_attack_length(int atk) {
+ if (atk >= ATK_PAP_FIRST && atk <= ATK_PAP_LAST) return papyrus_attack_length(atk);
+ int n = snow_lengths[atk - ATK_RUINS_COUNT] ? snow_lengths[atk - ATK_RUINS_COUNT] : 150;
+ /* Jerry makes attacks 2 seconds longer */
+ for (int i = 0; i < bt.nmon; i++)
+ if (bt.mon[i].def == mon_def(MON_JERRY) && bt.mon[i].alive && !bt.mon[i].gone) n += 60;
+ return n;
+}
+
+void snow_attack_run(Battle *b, int atk, int t) {
+ (void)b;
+ if (t < 0) return;
+ switch (atk) {
+ case ATK_DRAKE_ARCS: atk_drake_arcs(t); break;
+ case ATK_DRAKE_LINES: atk_drake_lines(t); break;
+ case ATK_ICECAP_HATS: atk_icecap_hats(t); break;
+ case ATK_ICECAP_WAVES: atk_icecap_waves(t); break;
+ case ATK_GYFT_PRESENTS: atk_gyft_presents(t); break;
+ case ATK_GYFT_SNOW: atk_gyft_snow(t); break;
+ case ATK_DOGGO_SWORD: atk_doggo_sword(t); break;
+ case ATK_LDOG_JUMP: atk_ldog_jump(t); break;
+ case ATK_LDOG_SPEARS: atk_ldog_spears(t); break;
+ case ATK_DOGI_AXES: atk_dogi_axes(t); break;
+ case ATK_DOGI_HEARTS: atk_dogi_hearts(t); break;
+ case ATK_GDOG_SPEAR: atk_gdog_spear(t); break;
+ case ATK_GDOG_BARK: atk_gdog_bark(t); break;
+ case ATK_GLYDE_STARS: atk_glyde_stars(t); break;
+ default:
+ if (atk >= ATK_PAP_FIRST && atk <= ATK_PAP_LAST) papyrus_attack(atk, t);
+ break;
+ }
+}
+
+void snow_attack_draw(Battle *b, int atk, int t) {
+ (void)b;
+ if (atk >= ATK_PAP_FIRST && atk <= ATK_PAP_LAST) papyrus_attack_draw(atk, t);
+}
+
+/* after a battle in Snowdin: who was killed, who's been met */
+void snow_battle_done(int form) {
+ for (int i = 0; i < bt.nmon; i++) {
+ const Monster *m = &bt.mon[i];
+ if (m->def == mon_def(MON_SNOWDRAKE) && m->killed) set_flag(F_SNOWDRAKE_DEAD, 1);
+ }
+ if (form == FORM_LESSERDOG) set_flag(F_LESSERDOG, bt.mon[0].killed ? 2 : 1);
+}
diff --git a/games/undertale/src/snowtown.c b/games/undertale/src/snowtown.c
new file mode 100644
index 00000000..c2fcdb02
--- /dev/null
+++ b/games/undertale/src/snowtown.c
@@ -0,0 +1,313 @@
+/* Snowdin Town: the shop, the inn, Grillby's, the library, the townsfolk, the foggy path where Papyrus fights,
+ * his house and the time spent with him, and the way on to Waterfall. Signs and books are the game's; the
+ * townsfolk's talks are kept short. */
+#include <stdio.h>
+#include <string.h>
+#include "battle.h"
+#include "event.h"
+#include "events.h"
+#include "game.h"
+#include "items.h"
+#include "menu.h"
+#include "monsters.h"
+#include "save.h"
+#include "shop.h"
+#include "snowdin.h"
+#include "world.h"
+
+static void gone(Obj *o) { o->kind = OBJ_NONE; }
+
+/* someone of the town who's drawn on the map: a box to talk to, what they say */
+static void folk(int x, int y, const char *text) {
+ Obj *o = obj_sign(x - 12, y - 18, 24, 26, text);
+ (void)o;
+}
+
+void town_setup(int room, int from) {
+ (void)from;
+ switch (room) {
+ case ROOM_SNOWTOWN:
+ obj_save(518, 1076, "* (The sight of such a friendly town fills you with determination.)");
+ obj_sign(266, 1046, 30, 24, "* (Welcome to Snowdin Town!)");
+ obj_sign(776, 1048, 20, 20, "* (Don't want to walk to the other side of town?)\n* (Try the undersnow tunnels!)|* (They're simple, quick, and convenient!)");
+ {
+ Obj *b = obj_trigger(566, 1072, 26, 24, EV_BOX, ACTOR_ITEM);
+ if (b) b->flags = OF_TALK | OF_SOLID;
+ Obj *shop = obj_trigger(446, 1066, 28, 24, EV_SHOP, ACTOR_TRIGGER);
+ (void)shop;
+ Obj *house = obj_trigger(2238, 1086, 28, 26, EV_TOWN_DOOR, ACTOR_TRIGGER2);
+ if (house) house->arg = 0;
+ Obj *shed = obj_trigger(2398, 1084, 28, 16, EV_TOWN_DOOR, ACTOR_TRIGGER3);
+ if (shed) shed->arg = 1;
+ }
+ folk(850, 1029, "* My sister's walking our little brother on a leash again.\n* Is that weird? It's weird, right?");
+ folk(911, 1101, "* I'm taking little Cinnamon for a walk!");
+ folk(991, 1081, "* Teens kept decorating Gyftrot's horns as a prank...|* So now everyone decorates a tree and puts presents under it instead.");
+ folk(1202, 1043, "* Papyrus reports straight to the Royal Guard.\n* Around here, that's about all the government we've got.");
+ folk(1457, 1042, "* Everyone makes light of how things are down here.\n* I don't think it's funny.");
+ folk(1515, 1040, "* If we didn't laugh about it, we'd just be sad.\n* So we laugh.");
+ folk(1840, 1044, "* (The sign says \"Librarby.\")");
+ if (flag(F_PAPYRUS) == 1) {
+ Obj *p = obj_papyrus(2190, 1100, DIR_DOWN);
+ if (p) p->event = EV_PAP_HOUSE, p->flags |= OF_TALK;
+ if (!flag(F_GRILLBYS)) {
+ Obj *s = obj_sans(1290, 1104, DIR_DOWN);
+ if (s) s->event = EV_GRILLBYS, s->flags |= OF_TALK;
+ }
+ }
+ folk(1099, 1093, "* Yo! You're a kid too, right?\n* I can tell 'cause you're wearing a striped shirt.|* I'm going to see Undyne fight someday.\n* She's the coolest!");
+ break;
+ case ROOM_TOWNNORTH:
+ folk(1463, 851, "* The kids are playing \"monsters and humans.\"\n* Ah, to be young again...");
+ folk(1513, 880, "* I'm the human! You can't catch me!");
+ folk(1505, 807, "* (Knock knock.)\n* ... Who's there?\n* ...|* Oh, I just love it when someone knocks.");
+ folk(1910, 789, "* I throw ice into the water.\n* It floats all the way to the CORE.");
+ break;
+ case ROOM_TOWNDOCK:
+ folk(1611, 589, "* Tra la la.\n* The boat isn't going anywhere today.");
+ break;
+ case ROOM_INN1: {
+ Obj *k = obj_trigger(636, 770, 26, 26, EV_INN, ACTOR_ITEM);
+ if (k) k->flags = OF_TALK | OF_SOLID;
+ folk(698, 815, "* My mom runs this inn.\n* Sleep in a bed and you'll feel all better!");
+ break;
+ }
+ case ROOM_INN2:
+ obj_sign(680, 520, 80, 80, "* (Two people are snoring loudly.)");
+ break;
+ case ROOM_GRILLBYS:
+ folk(1246, 770, "* (Grillby is silently cleaning a glass.)");
+ folk(1214, 792, "* Cheep cheep!\n* (The dogs here are the Royal Guard's Snowdin squad.)");
+ folk(1194, 786, "* I'm fishing for a date.\n* Literally.");
+ folk(1156, 782, "* (Lesser Dog is playing poker against itself.)");
+ folk(1174, 834, "* (Bark!)");
+ folk(1134, 860, "* I'm thinking of getting a collar...\n* Then maybe someone would take me for a walk.");
+ folk(1316, 903, "* I want new drinks...\n* And hot guys!");
+ folk(1324, 833, "* Monster food turns into energy right away.\n* I want to try human food someday.");
+ folk(1329, 767, "* New Home's getting crowded.\n* I bet someday everyone moves out here.");
+ if (flag(F_DOGI) != 2) {
+ folk(1209, 871, "* Watch out for Greater Dog.\n* It'll love you to death.");
+ folk(1238, 853, "* Nobody respects the sentries...");
+ }
+ break;
+ case ROOM_LIBRARY:
+ obj_sign(1830, 506, 30, 40, "* Monster funerals, technically speaking, are cool as heck.|* When monsters get old and kick the bucket, they turn into dust.\n* At funerals, we take that dust and spread it on that person's favorite thing.|* Then their essence will live on in that thing...\n* Uhhh, am I at the page minimum yet? I'm kinda sick of writing this.");
+ obj_sign(1874, 506, 30, 40, "* While monsters are mostly made of magic, human beings are mostly made of water.|* Humans, with their physical forms, are far stronger than us.\n* But they will never know the joy of expressing themselves through magic.|* They will never get a bullet-pattern birthday card...");
+ obj_sign(1918, 506, 30, 40, "* (Here I am... Writing this book.)\n* (A person comes in and picks up the book...)\n* (They start reading it...!)");
+ obj_sign(1962, 506, 30, 40, "* Because they are made of magic, monsters' bodies are attuned to their SOUL.|* If a monster doesn't want to fight, its defenses will weaken.\n* And the crueller the intentions of our enemies, the more their attacks will hurt us.|* Therefore, if a being with a powerful SOUL struck with the desire to kill...\n* Um, let's end the chapter here...");
+ obj_sign(2006, 506, 30, 40, "* Fearing the humans no longer, we moved out of our old city, HOME.|* We braved harsh cold, damp swampland, and searing heat...\n* Until we reached what we now call our capital.|* \"NEW HOME.\"\n* Again, our King is really bad at names...?");
+ obj_sign(2050, 506, 30, 40, "* Love, hope, compassion...\n* This is what people say monster SOULs are made of.|* But the absolute nature of the \"SOUL\" is unknown.\n* After all, humans have proven their SOULs don't need these things to exist.");
+ folk(1896, 640, "* Yes, the sign outside says \"Librarby.\"\n* We made a typo when we were making it.");
+ folk(2031, 655, flag(F_WORDSEARCH) == 2 ? "* I can see it in your eyes...\n* You think Junior Jumble is harder." : "* I can see it in your eyes...\n* You think crosswords are harder.");
+ folk(2002, 589, "* There's no news around here, so the newspaper is mostly comics and puzzles.");
+ folk(2044, 590, "* I make the word searches.\n* Number one in the underground!");
+ break;
+ case ROOM_PSHOUSE:
+ {
+ Obj *couch = obj_trigger(2300, 892, 82, 40, EV_COUCH, ACTOR_ITEM);
+ if (couch) couch->flags = OF_TALK;
+ }
+ obj_sign(2316, 834, 52, 30, "* (A TV.)");
+ obj_sign(2398, 800, 64, 50, "* (The kitchen.)");
+ if (flag(F_PAP_DATE) == 1) {
+ Obj *p = obj_papyrus(2276, 940, DIR_RIGHT);
+ if (p) p->event = EV_PAP_DATE, p->flags |= OF_TALK;
+ }
+ break;
+ case ROOM_SANSROOM:
+ obj_sign(2560, 600, 40, 40, "* (It's dark... A trash tornado swirls in the corner.)");
+ break;
+ case ROOM_SHED:
+ obj_sign(2650, 770, 30, 20, flag(F_PAP_CAPTURED) <= 1 ? "* SORRY, I HAVE TO LOCK YOU IN THE GUEST ROOM UNTIL UNDYNE ARRIVES.\n* FEEL FREE TO MAKE YOURSELF AT HOME!!!|* REFRESHMENTS AND ACCOMODATIONS HAVE BEEN PROVIDED.\n* - NYEHFULLY YOURS, PAPYRUS"
+ : flag(F_PAP_CAPTURED) == 2 ? "* PLEASE ASK BEFORE YOU ESCAPE!!!\n* WHEN YOU WENT MISSING, I GOT WORRIED SICK!!!\n* - SLIGHTLY BONETROUSLED, PAPYRUS"
+ : "* IF YOU'RE JUST LOOKING FOR A PLACE TO STAY...\n* JUST ASK!!! YOU DON'T NEED TO FIGHT ME!!!\n* - YOUR HOST, PAPYRUS");
+ obj_sign(2680, 820, 40, 30, "* (A dog bed. It's warm.)");
+ break;
+ case ROOM_FOGROOM:
+ if (!flag(F_PAPYRUS)) obj_trigger(3290, 1030, 30, 150, EV_PAP_FIGHT, ACTOR_TRIGGER);
+ obj_trigger(3596, 1040, 24, 140, EV_SNOW_END, ACTOR_TRIGGER2);
+ break;
+ }
+}
+
+/* ---------------------------------------------------------------- the events */
+static int ev_shop(Ev *c) {
+ EV_BEGIN;
+ pl.y = (int16_t)(pl.y + 6); /* (a step back from the door, for after) */
+ shop_open(SHOP_SNOWDIN);
+ WAIT_UNTIL(g_mode == MODE_WORLD);
+ pl.dir = DIR_DOWN;
+ EV_END;
+}
+
+static int ev_inn(Ev *c) {
+ EV_BEGIN;
+ NARRATE("* Hello, traveller.\n* Welcome to Snowed Inn.|* A room is 80G for the night.\n* Would you like to stay?@Stay@Leave");
+ if (CHOICE() == 1) {
+ NARRATE("* Come back anytime!");
+ } else if (sv.gold < 80) {
+ NARRATE("* Oh... You don't have enough money...|* ... Um, you know what? Take the room anyway.");
+ c->v[0] = 1;
+ } else {
+ c->v[0] = 1;
+ }
+ if (c->v[0]) {
+ NARRATE("* Here's your key.\n* Sleep well!");
+ world_fade_hold(ROOM_INN2, 540, 620, DIR_DOWN, 90);
+ WAIT_UNTIL(!world_fading());
+ sv.hp = sv.maxhp;
+ set_flag(F_INN, flag(F_INN) + 1);
+ NARRATE("* (You slept soundly. Your HP was maxed out.)|* (The innkeeper gave you your money back.)");
+ }
+ EV_END;
+}
+
+static int ev_town_door(Ev *c) {
+ int k = c->self ? c->self->arg : 0;
+ EV_BEGIN;
+ if (k == 0 && flag(F_TOWN_HOUSE)) { /* Papyrus and Sans's house */
+ FADE_TO(ROOM_PSHOUSE, 2436, 914, DIR_UP);
+ return 1;
+ }
+ NARRATE("* (It's locked.)");
+ pl.y = (int16_t)(pl.y + 6); /* (a step back off the door) */
+ EV_END;
+}
+
+static int ev_pap_fight(Ev *c) {
+ Obj *p = obj_get(ACTOR_PAPYRUS);
+ EV_BEGIN;
+ /* through the fog, a tall silhouette */
+ p = obj_papyrus(3440, 1100, DIR_LEFT);
+ p = obj_get(ACTOR_PAPYRUS);
+ pl.dir = DIR_RIGHT;
+ WALK(p, 3400, 1100, 1);
+ if (flag(F_PAP_CAPTURED) >= 3) {
+ SAY(FACE_PAPYRUS, "`0* HUMAN! YOU KEEP COMING BACK...\n* WOULD YOU LIKE TO SKIP OUR BATTLE?@Yes@No");
+ if (CHOICE() == 0) {
+ SAY(FACE_PAPYRUS, "`2* WELL THEN! LET'S BE FRIENDS INSTEAD!!!");
+ set_flag(F_PAPYRUS, 1);
+ goto spared;
+ }
+ } else if (flag(F_PAP_CAPTURED)) {
+ SAY(FACE_PAPYRUS, "`0* HUMAN! YOU ESCAPED!\n* LET'S TRY THIS AGAIN!!!");
+ } else {
+ SAY(FACE_PAPYRUS, "`0* HUMAN. I HAVE BEEN THINKING.\n* YOU LIKE PASTA. YOU SOLVE PUZZLES. YOU SEEM... COOL.|`2* I COULD BE YOUR FRIEND!!!|`3* NO! A ROYAL GUARD CAN'T BEFRIEND A HUMAN!\n* I MUST CAPTURE YOU AND JOIN THE GUARD!!!");
+ }
+ sv.hp = sv.maxhp;
+ BATTLE(FORM_PAPYRUS);
+ set_flag(F_SNOWDIN_BOSSES, flag(F_SNOWDIN_BOSSES) + 1);
+ if (battle_result() == BR_SCRIPTED) {
+ /* captured: off to the shed */
+ set_flag(F_PAP_CAPTURED, flag(F_PAP_CAPTURED) + 1);
+ if (flag(F_PAP_CAPTURED) == 1)
+ SAY(FACE_PAPYRUS, "`2* NYEH HEH HEH! CAPTURED!!!\n* OFF TO THE CAPTURE ZONE WITH YOU! (OUR SHED.)");
+ else if (flag(F_PAP_CAPTURED) == 2)
+ SAY(FACE_PAPYRUS, "`2* CAPTURED AGAIN!!!\n* THE SHED HAS BEEN IMPROVED SINCE YOUR LAST VISIT.");
+ else
+ SAY(FACE_PAPYRUS, "`2* YOU ARE... PERSISTENT!\n* BUT I AM THE PERSISTENTEST!!!");
+ gone(p);
+ world_fade_hold(ROOM_SHED, 2640, 840, DIR_DOWN, 40);
+ WAIT_UNTIL(!world_fading());
+ return 1;
+ }
+ if (bt.mon[0].killed) {
+ set_flag(F_PAPYRUS, 2);
+ gone(p);
+ SAY(FACE_PAPYRUS, "`4* WELL... I DIDN'T SEE THAT COMING.|* STILL, I THINK YOU CAN BE BETTER THAN THIS.\n* I BELIEVE IN YOU!");
+ if (c->self) gone(c->self);
+ return 1;
+ }
+ set_flag(F_PAPYRUS, 1);
+spared:
+ SAY(FACE_PAPYRUS, "`4* NYOO HOO HOO... I COULDN'T EVEN CAPTURE YOU.\n* SO MUCH FOR THE ROYAL GUARD.|`0* WAIT... YOU WANT TO BE FRIENDS???|`2* WOWIE!!! COME HANG OUT AT MY HOUSE LATER!|`0* (THE CAPITAL IS FURTHER ON, PAST THE TOWN.)");
+ set_flag(F_PAP_DATE, 1);
+ set_flag(F_TOWN_HOUSE, 1);
+ WALK(p, 3240, 1100, 6);
+ gone(p);
+ if (c->self) gone(c->self);
+ EV_END;
+}
+
+static int ev_pap_house(Ev *c) {
+ EV_BEGIN;
+ if (flag(F_PAP_DATE) == 1) {
+ SAY(FACE_PAPYRUS, "`0* HUMAN! READY TO HANG OUT?\n* COME INSIDE!!!");
+ FADE_TO(ROOM_PSHOUSE, 2436, 914, DIR_UP);
+ } else {
+ SAY(FACE_PAPYRUS, "`2* HELLO, FRIEND!!!");
+ }
+ EV_END;
+}
+
+static int ev_pap_date(Ev *c) {
+ EV_BEGIN;
+ /* his room, his spaghetti, his number */
+ SAY(FACE_PAPYRUS, "`0* WELCOME TO MY HOUSE!\n* THIS IS WHERE I LIVE WITH MY BROTHER, SANS.|* LET'S GO TO MY ROOM!!!");
+ FADE_TO(ROOM_PAPROOM, 2290, 650, DIR_UP);
+ {
+ Obj *p = obj_papyrus(2330, 640, DIR_LEFT);
+ (void)p;
+ }
+ SAY(FACE_PAPYRUS, "`0* MY ROOM!!! IMPRESSIVE, ISN'T IT?|`4* NOW... HANGING OUT. I READ A GUIDE ABOUT THIS.|`0* STEP ONE: A PRESENT!\n* FOR YOU: SPAGHETTI!@Eat it@Keep it");
+ if (CHOICE() == 0) SAY(FACE_PAPYRUS, "`2* WOWIE!!! YOU LIKED IT?!?\n* I'LL HAVE TO MAKE MORE!!!");
+ else SAY(FACE_PAPYRUS, "`2* SAVING IT FOR LATER?\n* A TRUE CONNOISSEUR!");
+ SAY(FACE_PAPYRUS, "`4* HUMAN... I'VE THOUGHT ABOUT IT.\n* LET'S STAY FRIENDS! THE BEST OF FRIENDS!!!|`2* TAKE MY PHONE NUMBER! CALL ANY TIME!\n* NYEH HEH HEH!!!");
+ NARRATE("* (You got Papyrus's phone number.)");
+ set_flag(F_PAP_DATE, 2);
+ FADE_TO(ROOM_SNOWTOWN, 2240, 1096, DIR_DOWN);
+ EV_END;
+}
+
+static int ev_grillbys(Ev *c) {
+ EV_BEGIN;
+ SAY(FACE_SANS, "* hey.\n* thanks for keeping my brother entertained.|* want to grab some lunch?@Sure@Not now");
+ if (CHOICE() == 1) {
+ SAY(FACE_SANS, "* ok. maybe later.");
+ return 1;
+ }
+ SAY(FACE_SANS, "* well, i know a shortcut.");
+ FADE_TO(ROOM_GRILLBYS, 1230, 880, DIR_UP);
+ SAY(FACE_SANS, "* here's a good seat.|* so, what'll it be?\n`2* fries or burger?@Fries@Burger");
+ SAY(FACE_SANS, "* nice.|* say... papyrus says a #Yflower#X talks to him sometimes.\n* gives him advice. weird, right?|* if you see a talking flower, tell me, ok?|`1* oh, and thanks for paying.");
+ set_flag(F_GRILLBYS, 1);
+ FADE_TO(ROOM_SNOWTOWN, 1310, 1096, DIR_DOWN);
+ EV_END;
+}
+
+static int ev_snow_end(Ev *c) {
+ EV_BEGIN;
+ /* on to Waterfall: not made yet */
+ set_flag(F_SNOW_EXIT, 1);
+ sv.room = (int16_t)g_room, sv.x = (int16_t)(pl.x - 20), sv.y = pl.y;
+ save_write_auto();
+ menu_end_open();
+ EV_END;
+}
+
+static int ev_couch(Ev *c) {
+ EV_BEGIN;
+ if (!flag(F_COUCH_GOLD)) {
+ set_flag(F_COUCH_GOLD, 1);
+ sv.gold = (uint16_t)min_i(9999, sv.gold + 20);
+ NARRATE("* (There's 20G under the couch!)");
+ } else {
+ NARRATE("* (It's a couch.)");
+ }
+ EV_END;
+}
+
+int town_event(Ev *c) {
+ switch (c->id) {
+ case EV_SHOP: return ev_shop(c);
+ case EV_INN: return ev_inn(c);
+ case EV_TOWN_DOOR: return ev_town_door(c);
+ case EV_PAP_FIGHT: return ev_pap_fight(c);
+ case EV_PAP_HOUSE: return ev_pap_house(c);
+ case EV_PAP_DATE: return ev_pap_date(c);
+ case EV_GRILLBYS: return ev_grillbys(c);
+ case EV_SNOW_END: return ev_snow_end(c);
+ case EV_COUCH: return ev_couch(c);
+ }
+ return -1;
+}
diff --git a/games/undertale/src/text.c b/games/undertale/src/text.c
index d636eea4..a41ede6e 100644
--- a/games/undertale/src/text.c
+++ b/games/undertale/src/text.c
@@ -254,6 +254,7 @@ static int last_choice;
static char fmt_buf[512];
void text_set_top(int top) { box_top = top; }
+void text_wrap_width(int w) { wrap_width = w; }
void text_open(int face, const char *s) {
box_face = face;
diff --git a/games/undertale/src/text.h b/games/undertale/src/text.h
index a566b0d7..d4c17127 100644
--- a/games/undertale/src/text.h
+++ b/games/undertale/src/text.h
@@ -53,6 +53,7 @@ void text_draw(void);
int text_choice(void); /* 0 or 1: the last choice made (a list's: its index, -1 Back) */
void text_open_menu(const char *const *opts, int n); /* a list of options in the box */
void text_set_top(int top);
+void text_wrap_width(int w); /* where the next writer's lines wrap (pixels from its left) */
int text_menu_sel(void); /* (the tests) a list's selection, 100 + a page's choice, -1 neither open */ /* -1: by where Frisk is (the game's way), 0 bottom, 1 top */
extern char g_name[8]; /* the fallen human's name */
#endif
diff --git a/games/undertale/src/world.c b/games/undertale/src/world.c
index fa2a7d98..50073d31 100644
--- a/games/undertale/src/world.c
+++ b/games/undertale/src/world.c
@@ -245,10 +245,30 @@ static bool step(int sx, int sy, bool slide) {
return false;
}
+static int8_t slide_dx, slide_dy;
+bool pl_sliding(void) { return slide_dx || slide_dy; }
+
static void player_move(uint32_t keys, uint32_t pressed) {
int dx = ((keys & K_RIGHT) != 0) - ((keys & K_LEFT) != 0);
int dy = ((keys & K_DOWN) != 0) - ((keys & K_UP) != 0);
face_from_keys(keys, pressed);
+ /* on ice he slides the way he went on until he's off it, or something stops him */
+ if (room_ice(pl.x + PBX + PBW / 2, pl.y + PBY + PBH / 2)) {
+ if (!slide_dx && !slide_dy && (dx || dy)) {
+ static const int8_t ddx[4] = {0, 0, -1, 1}, ddy[4] = {1, -1, 0, 0};
+ slide_dx = ddx[pl.dir], slide_dy = ddy[pl.dir];
+ }
+ if (slide_dx || slide_dy) {
+ bool moved = false;
+ for (int i = 0; i < 4; i++) moved |= step(slide_dx, slide_dy, false);
+ if (!moved) slide_dx = slide_dy = 0;
+ pl.anim = 0, pl.frame = 0;
+ pl.moving = moved;
+ return;
+ }
+ } else {
+ slide_dx = slide_dy = 0;
+ }
bool moved = false;
for (int i = 0; i < SPEED; i++) {
if (dx) moved |= step(dx, 0, !dy);
@@ -343,7 +363,9 @@ void world_update(uint32_t keys, uint32_t pressed) {
/* a door */
for (int i = 0; i < ndoors; i++)
if (boxes_meet(pl.x + PBX, pl.y + PBY, PBW, PBH, doors[i].x, doors[i].y, doors[i].w, doors[i].h)) {
- world_fade_to(doors[i].room, doors[i].tx, doors[i].ty, doors[i].dir);
+ /* (a side door between rooms with a gap keeps Frisk's height: DOOR_KEEP) */
+ world_fade_to(doors[i].room, doors[i].tx == DOOR_KEEP ? pl.x : doors[i].tx,
+ doors[i].ty == DOOR_KEEP ? pl.y : doors[i].ty, doors[i].dir);
fade.walked = true;
return;
}
@@ -376,8 +398,9 @@ Obj *obj_npc(int name, const uint16_t spr[4], int x, int y, int dir, int event)
Frame f;
frame_get(spr[0], 0, &f);
o->name = (uint8_t)name, o->dir = (uint8_t)dir, o->event = (uint16_t)event;
- o->bx = (int16_t)(f.w / 5), o->bw = (int16_t)(f.w - 2 * (f.w / 5)), o->bh = (int16_t)(f.h / 4 < 8 ? 8 : f.h / 4);
- o->by = (int16_t)(f.h - o->bh);
+ /* its box: the bottom of its sprite, a little narrower (from the sprite's origin: its top-left or its feet) */
+ o->bx = (int16_t)(f.w / 5 - f.ox), o->bw = (int16_t)(f.w - 2 * (f.w / 5)), o->bh = (int16_t)(f.h / 4 < 8 ? 8 : f.h / 4);
+ o->by = (int16_t)(f.h - o->bh - f.oy);
o->flags = OF_SOLID | (event ? OF_TALK : 0) | OF_WALKANIM;
return o;
}
@@ -449,8 +472,22 @@ bool near_frisk(const Obj *o, int d) {
return abs_i(ox - px) <= d && abs_i(oy - py) <= d;
}
+bool cam_pan(int x, int y, int sp) {
+ cam_locked = true;
+ cam_x += clamp_i(x - cam_x, -sp, sp), cam_y += clamp_i(y - cam_y, -sp, sp);
+ return cam_x == x && cam_y == y;
+}
+void cam_free(void) { cam_locked = false; }
+
+void room_draw_floor(void); /* rooms.c */
+
+int g_shake; /* frames the view shakes */
+
void world_draw(void) {
+ int keep_x = cam_x, keep_y = cam_y;
+ if (g_shake > 0) cam_x += (rnd_n(3) - 1) * 2, cam_y += (rnd_n(3) - 1) * 2, g_shake--;
gfx_tiles(cam_x, cam_y);
+ room_draw_floor();
/* the room's objects and Frisk, the lower ones in front */
DrawRef order[MAX_OBJS + 1];
int n = 0;
@@ -480,7 +517,9 @@ void world_draw(void) {
for (int k = 0; k < o->arg; k++) gfx_sprite(o->spr[0], o->frame, o->x + k * 20 - cam_x, o->y + r * 20 - cam_y, 0, 255);
continue;
}
- gfx_sprite(obj_sprite(o), o->frame, o->x - cam_x, o->y - cam_y, 0, o->alpha);
+ if (o->flags & OF_DARK) gfx_sprite_color(obj_sprite(o), o->frame, o->x - cam_x, o->y - cam_y, 0, C_BLACK, o->alpha);
+ else gfx_sprite(obj_sprite(o), o->frame, o->x - cam_x, o->y - cam_y, (o->flags & OF_FLIP) ? GFX_FLIPX : 0, o->alpha);
}
}
+ cam_x = keep_x, cam_y = keep_y;
}
diff --git a/games/undertale/src/world.h b/games/undertale/src/world.h
index 150a7314..3df2f043 100644
--- a/games/undertale/src/world.h
+++ b/games/undertale/src/world.h
@@ -24,7 +24,9 @@ enum {
OF_ANIM = 16, /* its frames cycle (anim_speed) even standing */
OF_WALKANIM = 32, /* its frames cycle while it walks */
OF_FRONT = 64, /* drawn over everything else */
- OF_BACK = 128 /* drawn under everything else */
+ OF_BACK = 128, /* drawn under everything else */
+ OF_DARK = 256, /* a silhouette */
+ OF_FLIP = 512 /* drawn mirrored */
};
#define MAX_OBJS 48
typedef struct {
@@ -81,9 +83,12 @@ void obj_spikes_set(Obj *o, bool raised);
Obj *obj_rock(int x, int y, int name, int event); /* pushed by walking into it; with an event, it talks */
void obj_set_box(Obj *o, int bx, int by, int bw, int bh);
bool near_frisk(const Obj *o, int d); /* within d pixels (their feet) */
+bool room_ice(int x, int y); /* rooms.c: ice there (Frisk slides) */
+bool pl_sliding(void);
/* the room fades out, then in: room changes in the middle */
void world_fade_to(int room, int x, int y, int dir);
void world_fade_hold(int room, int x, int y, int dir, int hold); /* black for `hold` frames in the middle */
bool world_fading(void);
extern uint8_t g_fade; /* 0 clear, 255 black: drawn over the room */
+extern int g_shake; /* frames the view shakes */
#endif
diff --git a/games/undertale/tests/check.py b/games/undertale/tests/check.py
index 1c81bf1f..ee13235c 100644
--- a/games/undertale/tests/check.py
+++ b/games/undertale/tests/check.py
@@ -1,11 +1,11 @@
#!/usr/bin/env python3
"""Checks of Undertale on a computer (make test): the host build, with
-AddressSanitizer and UBSan, through the menus, every battle, the saves and
-the whole Ruins.
+AddressSanitizer and UBSan, through the menus, every battle, the saves, the
+whole Ruins and the whole of Snowdin.
python3 tests/check.py build/play [--quick]
---quick skips playing the whole Ruins (the longest part)."""
+--quick skips playing the whole Ruins and Snowdin (the longest parts)."""
import os
import re
import shutil
@@ -26,7 +26,11 @@ body = re.sub(r"/\*.*?\*/", "", src[src.index("enum {") + 6:src.rindex("FLAG_COU
for i, n in enumerate(n.strip() for n in body.split(",") if n.strip()):
FLAGS[n] = i
-MODE_WORLD, MODE_BATTLE, MODE_END = 2, 3, 8
+MODE_WORLD, MODE_BATTLE, MODE_END, MODE_SHOP = 2, 3, 8, 9
+# rooms and battles (src/data.h, src/monsters.h)
+ROOMS = {m.group(1): int(m.group(2)) for m in
+ re.finditer(r"#define ROOM_(\w+) (\d+)", open(os.path.join(HERE, "..", "src", "data.h")).read())}
+FORM_SNOWDRAKE, FORM_PAPYRUS = 19, 31
def run(args, frames, saves=None, what=""):
@@ -81,6 +85,28 @@ for form in (2, 3, 6, 10, 12):
s = run(["--god", "--battle", "16", "--path", "act:3"], 6000, what="Napstablook, cheered up")
check(s and s["mode"] == MODE_WORLD and s["kills"] == 0, f"Napstablook was not spared by cheering: {s}")
+# Snowdin's battles: fled from, fought (the Snowdrake, the Gyftrot, the Glyde, the Greater Dog...), and Papyrus,
+# who can't be fled: spared once he spares you, or (the SOUL hurt) he captures you
+for form in range(FORM_SNOWDRAKE, FORM_PAPYRUS):
+ s = run(["--god", "--battle", str(form), "--path", "flee"], 1500, what=f"battle {form}, fleeing")
+ check(s and s["mode"] == MODE_WORLD, f"battle {form}: fleeing did not end it: {s}")
+for form in (19, 20, 26, 27, 28, 30):
+ s = run(["--god", "--battle", str(form), "--path", "fight"], 4000, what=f"battle {form}, fighting")
+ check(s and s["mode"] == MODE_WORLD and s["kills"] >= 1, f"battle {form}: FIGHT did not win it: {s}")
+s = run(["--god", "--battle", str(FORM_PAPYRUS), "--path", "spare"], 15000, what="Papyrus, spared")
+check(s and s["mode"] == MODE_WORLD and s["kills"] == 0, f"Papyrus was not spared: {s}")
+s = run(["--battle", str(FORM_PAPYRUS), "--path", "spare"], 6000, what="Papyrus, captured")
+check(s and s["mode"] == MODE_WORLD and s["hp"] == 1, f"Papyrus did not capture Frisk: {s}")
+
+# the shop in Snowdin: a Cinnamon Bunny for 25G; Papyrus's date: his phone number
+s = run(["--name", "Frisk", "--noenc", "--room", str(ROOMS["SNOWTOWN"]), "--at", "446,1092", "--gold", "100", "--keys",
+ "2-24:up,60:z,90:down,100:down,110:down,120:z,140:z,170:x,190:down,200:down,210:down,220:z"], 400, what="the shop")
+check(s and s["gold"] == 75 and s["items"][0] == 16, f"the shop did not sell a Cinnamon Bunny: {s}")
+s = run(["--name", "Frisk", "--noenc", "--room", str(ROOMS["PSHOUSE"]), "--at", "2436,914", "--flag",
+ f"{FLAGS['F_PAPYRUS']}=1", "--flag", f"{FLAGS['F_PAP_DATE']}=1", "--path",
+ "go:2300,918;l;w5;l;w5;l;w5;z;pick:0;talk;w60"], 2500, what="Papyrus's date")
+check(s and flag(s, "PAP_DATE") == 2, f"the date did not end with Papyrus's number: {s}")
+
# the leaf pile's SAVE, then Continue from the title
d = tempfile.mkdtemp(prefix="undertale_check_")
s = run(["--name", "Frisk", "--noenc", "--room", "8", "--at", "5012,4498", "--path", "u;z;w20;z;w30;x"], 300, saves=d,
@@ -99,7 +125,7 @@ shutil.rmtree(d, ignore_errors=True)
if not QUICK:
s = run(["--name", "Frisk", "--noenc", "--god", "--path-file", os.path.join(HERE, "ruins.path")], 40000,
what="the Ruins")
- check(s and s["mode"] == MODE_END, f"the Ruins did not end at their door: {s}")
+ check(s and s["mode"] == MODE_WORLD and s["room"] == ROOMS["SNOWDIN1"], f"the Ruins' door did not lead to Snowdin: {s}")
if s:
for name, v in (("FLOWEY_MET", 1), ("DUMMY", 1), ("RUINS5_DONE", 1), ("RUINS6_DONE", 1), ("PHONE", 1),
("RUINS9_ROCK", 1), ("RUINS11_ROCK", 5), ("NAPSTA", 1), ("ONESWITCH", 1), ("ROTATE4", 1),
@@ -109,6 +135,20 @@ if not QUICK:
check(s["kills"] == 0, f"the Ruins: {s['kills']} killed on the friendly way")
check(s["items"].count(1) == 2, f"the Ruins: not the two pieces of Monster Candy: {s['items']}")
+# the whole of Snowdin, the friendly way: Sans, Papyrus's puzzles (the maze, the X/O ones, the ice, the tiles),
+# Doggo, Dogamy and Dogaressa, Greater Dog, the Gauntlet, the town, Papyrus spared, the way on
+if not QUICK:
+ s = run(["--name", "Frisk", "--noenc", "--god", "--room", str(ROOMS["SNOWDIN1"]), "--at", "34,392", "--path-file",
+ os.path.join(HERE, "snowdin.path")], 30000, what="Snowdin")
+ check(s and s["mode"] == MODE_END, f"Snowdin did not end on the way to Waterfall: {s}")
+ if s:
+ for name, v in (("BRANCH", 1), ("SANS_MET", 1), ("PAP_SENTRY", 1), ("DOGGO", 1), ("ELECMAZE", 2),
+ ("WORDSEARCH", 1), ("SNOWPUZZLE", 1), ("DOGI", 1), ("XOXO1", 1), ("XOXO2", 1), ("XOXO3", 1),
+ ("PAP_XOXO1", 2), ("TILES", 1), ("GREATERDOG", 1), ("GAUNTLET", 1), ("PAPYRUS", 1),
+ ("PAP_DATE", 1), ("TOWN_HOUSE", 1), ("SNOW_EXIT", 1)):
+ check(flag(s, name) == v, f"Snowdin: F_{name} is {flag(s, name)}, not {v}")
+ check(s["kills"] == 0, f"Snowdin: {s['kills']} killed on the friendly way")
+
if failures:
print("\n".join("FAIL " + f for f in failures))
sys.exit(1)
diff --git a/games/undertale/tests/play.c b/games/undertale/tests/play.c
index 1f369196..6277afa7 100644
--- a/games/undertale/tests/play.c
+++ b/games/undertale/tests/play.c
@@ -1,7 +1,7 @@
/* Plays Undertale on a computer, with scripted keys, and saves frames.
*
* play [--frames N] [--keys "10-40:right,50:z,..."] [--shots 30,60|all] [--out DIR] [--saves DIR]
- * [--room N --at X,Y] [--name NAME] [--flag F=V]... [--battle ID] [--trace]
+ * [--room N --at X,Y] [--name NAME] [--flag F=V]... [--gold N] [--battle ID] [--trace]
*
* --path "x,y;x,y;z;w30;..." steers Frisk to each point in turn (holding arrows), presses Z ("z"), X ("x"),
* waits ("wN": N frames) or mashes Z through talks ("talk": until no text or event is left), when the scripted
@@ -9,6 +9,7 @@
* Keys: left right up down z x c home. "a-b:key" holds the key from frame a to b, "a:key" for one frame.
* --room starts a new game in room N (its ROOM_* number) with Frisk's top-left at (X, Y), past the title.
* Screenshots are DIR/shot_<frame>.ppm. */
+#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -97,13 +98,21 @@ static uint32_t path_keys(int f) {
if (e) {
const char *n = e + 1;
bool nb = !strncmp(n, "fight", 5) || !strncmp(n, "spare", 5) || !strncmp(n, "bt", 2) || !strncmp(n, "act:", 4) ||
- !strncmp(n, "flee", 4);
+ !strncmp(n, "flee", 4) || !strncmp(n, "seq:", 4);
bool hb = !strncmp(path_at, "fight", 5) || !strncmp(path_at, "spare", 5) || !strncmp(path_at, "bt", 2) ||
- !strncmp(path_at, "act:", 4) || !strncmp(path_at, "flee", 4) || !strncmp(path_at, "pick:", 5);
+ !strncmp(path_at, "act:", 4) || !strncmp(path_at, "flee", 4) || !strncmp(path_at, "pick:", 5) ||
+ !strncmp(path_at, "seq:", 4);
if (!hb && ((g_mode == MODE_BATTLE && nb) || (g_mode == MODE_WORLD && text_menu_sel() >= 0 && !strncmp(n, "pick:", 5))))
path_at = e + 1;
}
}
+ /* a choice up while Frisk still walks: a "pick:" a few steps on (past "talk"s and points) is for it */
+ if (g_mode == MODE_WORLD && text_menu_sel() >= 0 && strncmp(path_at, "pick:", 5)) {
+ char *n = strchr(path_at, ';');
+ for (int k = 0; n && k < 3 && (!strncmp(n + 1, "talk", 4) || !strncmp(n + 1, "go:", 3) || isdigit((unsigned char)n[1])); k++)
+ n = strchr(n + 1, ';');
+ if (n && !strncmp(n + 1, "pick:", 5)) path_at = n + 1;
+ }
/* "pick:N": the option N of the next list or choice */
if (!strncmp(path_at, "pick:", 5) && g_mode == MODE_WORLD) {
int n = atoi(path_at + 5), sel = text_menu_sel();
@@ -123,7 +132,28 @@ static uint32_t path_keys(int f) {
* "bt" (a scripted battle) reads on; Z on whatever else comes (the bar, the texts). A battle the path didn't
* expect: Frisk flees it */
bool btok = !strncmp(path_at, "fight", 5) || !strncmp(path_at, "spare", 5) || !strncmp(path_at, "bt", 2) ||
- !strncmp(path_at, "act:", 4) || !strncmp(path_at, "flee", 4);
+ !strncmp(path_at, "act:", 4) || !strncmp(path_at, "flee", 4) || !strncmp(path_at, "seq:", 4);
+ /* "seq:a,b@2,...": an ACT a turn (b@2: on the second monster), MERCY once one can be spared or they're done */
+ static char *seq_for;
+ static int seq_i;
+ int seq_act = 0, seq_target = 0;
+ bool seq = !strncmp(path_at, "seq:", 4);
+ if (seq) {
+ if (seq_for != path_at) seq_for = path_at, seq_i = 0;
+ const char *q = path_at + 4;
+ for (int k = 0; k < seq_i && q && *q && *q != ';'; k++) {
+ q = strchr(q, ',');
+ if (q) q++;
+ }
+ if (q && *q && *q != ';') {
+ seq_act = atoi(q);
+ const char *at = strchr(q, '@'), *comma = strchr(q, ','), *semi = strchr(q, ';');
+ if (at && (!comma || at < comma) && (!semi || at < semi)) seq_target = atoi(at + 1) - 1;
+ }
+ bool can = false;
+ for (int i = 0; i < bt.nmon; i++) can |= bt.mon[i].alive && !bt.mon[i].gone && bt.mon[i].spare;
+ if (can) seq_act = 0;
+ }
static int idle;
if (g_mode == MODE_BATTLE) {
idle = 0;
@@ -131,11 +161,16 @@ static uint32_t path_keys(int f) {
if (f & 1) return 0;
if (bt.scripted) return K_Z; /* (Flowey's: read on) */
int want = !btok || !strncmp(path_at, "flee", 4) || !strncmp(path_at, "spare", 5) ? 3 : !strncmp(path_at, "act:", 4) ? 1 : 0;
+ if (seq) want = seq_act ? 1 : 3;
int mercy = (!btok || !strncmp(path_at, "flee", 4)) && !bt.no_flee ? 1 : 0;
switch (battle_ui()) {
case BUI_MENU: return bt.button < want ? K_RIGHT : bt.button > want ? K_LEFT : K_Z;
+ case BUI_TARGET:
+ if (seq && bt.button == 1) return bt.target < seq_target ? K_DOWN : bt.target > seq_target ? K_UP : K_Z;
+ return K_Z;
case BUI_ACTS: {
- int n = atoi(path_at + 4);
+ int n = seq ? seq_act : atoi(path_at + 4);
+ if (seq && bt.act == n) seq_i++;
return bt.act + 2 <= n ? K_DOWN : bt.act < n ? K_RIGHT : bt.act - 2 >= n ? K_UP : bt.act > n ? K_LEFT : K_Z;
}
case BUI_MERCY: return bt.mercy < mercy ? K_DOWN : bt.mercy > mercy ? K_UP : K_Z;
@@ -190,6 +225,15 @@ static uint32_t path_keys(int f) {
int gx, gy;
sscanf(tok + 3, "%d,%d", &gx, &gy);
static int planned_room;
+ if (planned == path_at && planned_room != g_room) {
+ /* a door to another area on the way: the point was there, so it is reached */
+ RoomInfo a, b;
+ room_info(planned_room, &a), room_info(g_room, &b);
+ if (a.area != b.area) {
+ path_at = next, planned = NULL;
+ return 0;
+ }
+ }
if (planned != path_at || planned_room != g_room) {
planned = path_at, planned_room = g_room;
if (!go_plan(gx, gy)) {
@@ -279,7 +323,7 @@ int main(int argc, char **argv) {
const char *out = "build/play", *saves = NULL, *shots = "";
int frames = 120, room = -1, ax = 0, ay = 0, battle = -1;
const char *name = NULL;
- int nflags = 0, fl[64][2];
+ int nflags = 0, fl[64][2], gold = -1;
bool trace = false, coll = false, god = false;
for (int i = 1; i < argc; i++) {
if (!strcmp(argv[i], "--frames") && i + 1 < argc) frames = atoi(argv[++i]);
@@ -316,6 +360,7 @@ int main(int argc, char **argv) {
} else if (!strcmp(argv[i], "--trace")) trace = true;
else if (!strcmp(argv[i], "--noenc")) g_no_encounters = true;
else if (!strcmp(argv[i], "--god")) god = true;
+ else if (!strcmp(argv[i], "--gold") && i + 1 < argc) gold = atoi(argv[++i]);
else if (!strcmp(argv[i], "--coll")) coll = true;
else fprintf(stderr, "unknown option %s\n", argv[i]), exit(2);
}
@@ -341,6 +386,7 @@ int main(int argc, char **argv) {
}
}
for (int i = 0; i < nflags; i++) set_flag(fl[i][0], fl[i][1]);
+ if (gold >= 0) sv.gold = (uint16_t)gold;
if (battle >= 0) battle_start(battle);
bool all = !strcmp(shots, "all");
for (int f = 0; f < frames && g_running; f++) {
diff --git a/games/undertale/tests/snowdin.path b/games/undertale/tests/snowdin.path
new file mode 100644
index 00000000..540c2c36
--- /dev/null
+++ b/games/undertale/tests/snowdin.path
@@ -0,0 +1,242 @@
+# Snowdin from the Ruins door (play it with --room 46 --at 34,392 --name Frisk --noenc --god), the friendly
+# way: one step a line, as in ruins.path; seq:a,b@2 picks an ACT a turn (b on the second monster) then MERCY.
+# The forest road: Sans at the gate, Papyrus at the lamp
+go:1060,404
+1100,404
+go:1760,404
+1800,404
+go:2200,404
+2240,404
+go:2530,404
+2580,404
+talk
+# Box Road, the sentry station
+go:3200,400
+go:3530,400
+3560,400
+talk
+# Doggo: pet it after its attack
+go:4110,404
+go:4290,404
+4330,404
+seq:1,1
+go:4570,404
+go:4660,404
+# the invisible electricity maze, along Papyrus's footprints
+go:5180,400
+5210,400
+talk
+5280,360
+talk
+5260,356
+5330,356
+5330,316
+5390,316
+5390,416
+5445,416
+talk
+go:5480,420
+# the ball game room (over the plank bridge), the word search, Junior Jumble
+go:5490,370
+5530,350
+go:5760,330
+go:6040,420
+go:6080,600
+go:6280,650
+6320,650
+talk
+go:6450,650
+pick:0
+talk
+# the spaghetti, then the snow puzzle's switch and Dogamy and Dogaressa
+go:6600,640
+6640,640
+go:6880,660
+6930,660
+go:7316,690
+u
+z
+talk
+go:7100,960
+go:7180,960
+go:7300,960
+seq:3,2,1@1,1@2
+# the first X/O puzzle, Papyrus and the spaghetti question; the second, with the switch in the tree
+go:7370,1100
+7370,1140
+go:7450,1222
+go:7530,1222
+go:7500,1196
+u
+z
+talk
+go:7590,1222
+7620,1222
+talk
+pick:0
+talk
+go:7690,1222
+7720,1222
+talk
+go:7960,1186
+u
+z
+talk
+go:8094,1232
+u
+z
+talk
+# the multicolor tile puzzle
+go:8480,1222
+8520,1222
+go:8580,1222
+pick:0
+talk
+go:8840,1236
+# the dog house; the ice X/O puzzle: slides (a key, then the wait while Frisk slides), the switch, the bridge
+go:9000,1240
+go:9300,1240
+go:9446,1230
+u
+u
+u
+u
+u
+r
+r
+r
+r
+r
+r
+r
+r
+r
+r
+r
+r
+r
+r
+r
+r
+r
+r
+r
+r
+r
+r
+r
+w18
+u
+r
+w11
+l
+u
+w20
+l
+w17
+d
+d
+d
+d
+r
+l
+w3
+r
+r
+w56
+d
+w8
+l
+w66
+u
+r
+r
+w8
+r
+r
+d
+d
+w30
+r
+r
+w41
+u
+u
+w36
+d
+w36
+u
+l
+w50
+r
+r
+w66
+u
+w17
+l
+w36
+d
+d
+l
+w3
+d
+d
+l
+w11
+r
+r
+w46
+u
+w5
+z
+talk
+l
+w36
+u
+u
+u
+u
+u
+u
+u
+u
+u
+l
+w3
+u
+u
+l
+w31
+u
+r
+r
+w67
+r
+r
+r
+r
+r
+r
+r
+9845,1196
+# the snow poffs, Greater Dog (beckon, pet, play, pet, pet), the Gauntlet bridge
+go:10500,1240
+go:10830,1240
+seq:2,1,3,1,1
+talk
+go:10950,1244
+go:11100,1236
+go:11300,1236
+talk
+go:11990,1236
+# Snowdin Town, the fog, Papyrus spared, the way on to Waterfall
+go:600,1090
+go:1500,1090
+go:2500,1090
+go:3240,1090
+go:3300,1090
+spare
+talk
+go:3560,1090
+3640,1090
+talk
diff --git a/games/undertale/tools/fetch.py b/games/undertale/tools/fetch.py
index 708a6fba..657aea85 100644
--- a/games/undertale/tools/fetch.py
+++ b/games/undertale/tools/fetch.py
@@ -25,6 +25,7 @@ UA = {"User-Agent": "NumPlay-Undertale/1.0 (fan port for the NumWorks calculator
CATEGORIES = {
"maps": ["Maps"],
"sprites": ["Overworld_sprites", "Battle_sprites", "Face_sprites", "Sprites", "Item_files", "Location_files"],
+ "screens": ["Screenshots", "Cut_content_files"],
}
PAGES = ["Ruins", "Ruins/Puzzles", "Toriel", "Toriel/In_battle", "Toriel's_Home", "Flowey", "Napstablook",
"Cell_Phone/Toriel", "SAVE_Point", "Froggit", "Whimsun", "Moldsmal", "Loox", "Vegetoid", "Migosp",
@@ -33,7 +34,25 @@ PAGES = ["Ruins", "Ruins/Puzzles", "Toriel", "Toriel/In_battle", "Toriel's_Home"
"HP", "AT", "DF", "Stats", "FIGHT", "ACT", "MERCY", "ITEM", "Flowey/In_battle", "Napstablook/In_battle",
"Encounter", "Home", "Annoying_Dog", "Rock", "Mouse", "Golden_flower", "Chara", "Frisk", "Name",
"Item", "Consumables", "Weapons", "Armor", "Cell_Phone", "Intro", "Game_Over", "Damage", "Monster_Candy",
- "Toriel's_Home", "Blue_SOUL", "Bullet_board", "Spare", "Flee", "Gold", "Save"]
+ "Toriel's_Home", "Blue_SOUL", "Bullet_board", "Spare", "Flee", "Gold", "Save",
+ # Snowdin
+ "Snowdin", "Snowdin/Puzzles", "Snowdin_Town", "Sans", "Papyrus", "Papyrus/In_battle", "Sans/In_battle",
+ "Snowdrake", "Ice_Cap", "Gyftrot", "Doggo", "Lesser_Dog", "Greater_Dog", "Dogamy_and_Dogaressa", "Jerry",
+ "Chilldrake", "Glyde", "Snowman", "Monster_Kid", "Multicolor_Tile_Puzzle", "Nice_Cream_guy", "Nice_Cream",
+ "Dimensional_Box", "Ball_Game", "Grillby's", "Grillby", "Papyrus_and_Sans's_House", "Papyrus's_room",
+ "Sans's_room", "Shop", "Snowdin_Shop", "Snowed_Inn", "Innkeeper", "Librarby", "Gift_Bear", "Ice_Wolf",
+ "Cell_Phone/Papyrus", "Papyrus_date", "Mysterious_door", "Snowdin_Forest", "Royal_Guard", "Blue_attack",
+ "Faun", "Big_Mouth", "Crazy_Bun", "Drunk_Bun", "Politics_Bear", "Punk_Hamster", "Rabbit_Kid",
+ "Rabbit_Lady_and_Cinnamon", "Red_Bird", "Red_Demon", "Scarf_Lady", "Slime_family", "Ugly_Fish",
+ "Library_Lizard", "Library_Loox", "Knock_lover", "Lady_Garf", "Wrap_Mouse", "Innkeeper's_child",
+ "Snoring_guests", "Mad_Mew_Mew", "Snowdrake's_mother", "Snowdrake's_father", "Bonetrousle",
+ "Tough_Glove", "Manly_Bandanna", "Old_Tutu", "Ballet_Shoes", "Cinnamon_Bunny", "Bisicle", "Unisicle",
+ "Nice_Cream_(item)", "Snowman_Piece", "Snowman_Piece", "Punch_Card", "Dog_Residue", "Abandoned_Quiche",
+ "Astronaut_Food", "Hot_Dog...?", "Hot_Cat", "Spaghetti", "Glamburger", "Sea_Tea", "Temmie_Flakes",
+ "Junk_Food", "Annoying_Dog/In_battle", "Lesser_Dog/In_battle", "Greater_Dog/In_battle", "Doggo/In_battle",
+ "Dogamy_and_Dogaressa/In_battle"]
+# files the categories leave out, as their wiki names
+FILES = ["QC sprite.png", "QC screenshot shop.png"]
DEMO = {
"MacUnderTale.zip": "https://thisisatestofthevideogamedeliverysystem.sfo2.digitaloceanspaces.com/game/MacUnderTale.zip",
}
@@ -97,6 +116,13 @@ def main():
if url:
print(kind, name)
save(path, get(url))
+ for name in FILES:
+ path = os.path.join(ref, "wiki", "sprites", name.replace(" ", "_"))
+ if not os.path.exists(path):
+ url = file_url("File:" + name)
+ if url:
+ print("file", name)
+ save(path, get(url))
for page in PAGES:
path = os.path.join(ref, "wiki", "pages", page.replace("/", "__") + ".txt")
if os.path.exists(path):
diff --git a/games/undertale/tools/pack.py b/games/undertale/tools/pack.py
index 3da1cbd7..5a96062d 100644
--- a/games/undertale/tools/pack.py
+++ b/games/undertale/tools/pack.py
@@ -10,7 +10,7 @@ data.bin: "UTD1", the number of sections, their offsets, then the sections (SEC_
lowest first, the run padded to a byte), until the row's width
- TILES: the areas' 20 x 20 tiles: bpp (0: one colour), colours, the colours (RGB565), 400 pixels of bpp bits
- ROOMS: 32 bytes each (res.c room_info): the room's rectangle on its area's map, its tile grid and
- collision map (4-pixel cells, 1 walkable), its area, flags and name
+ collision map (4-pixel cells, 1 walkable), its area, flags (1: ice, its bits after the collision's) and name
- GRID, COLL: the rooms' tile ids (u16, 0xFFFF none) and collision bits
- FONTS: height, first character, count, flags, then 8 bytes a glyph (advance, w, h, ox, oy, 0,
bitmap offset u16) and the bitmaps (rows of whole bytes, highest bit first)
@@ -183,6 +183,35 @@ def load_frames(ref, src):
return frames
if kind == "png":
return [Image.open(os.path.join(HERE, name)).convert("RGBA")]
+ if kind == "move":
+ # 'move:File.gif:x0,y0,x1,y1:i,j,...': the biggest thing that moves in a part of a screenshot GIF (against
+ # its median frame), in frames i, j...; halved
+ name, box, which = name.split(":")
+ x0, y0, x1, y1 = map(int, box.split(","))
+ im = Image.open(os.path.join(ref, "wiki", "screens", name))
+ st = np.stack([np.asarray(f.convert("RGB"))[y0:y1, x0:x1] for f in ImageSequence.Iterator(im)]).astype(int)
+ bg = np.median(st, axis=0)
+ out = []
+ for i in map(int, which.split(",")):
+ m = np.abs(st[i] - bg).sum(2) > 30
+ lab, n = ndimage.label(ndimage.binary_dilation(m, iterations=4))
+ k = int(np.argmax(ndimage.sum(m, lab, range(1, n + 1)))) + 1
+ sl = ndimage.find_objects(lab)[k - 1]
+ a = (m & (lab == k))[sl]
+ rgba = np.dstack([st[i][sl].astype(np.uint8), (a * 255).astype(np.uint8)])
+ # each frame on a canvas of the window's size, its feet at the bottom middle: frames line up
+ f = Image.fromarray(rgba, "RGBA")
+ canvas = Image.new("RGBA", (x1 - x0, y1 - y0), (0, 0, 0, 0))
+ canvas.paste(f, ((x1 - x0 - f.width) // 2, y1 - y0 - f.height), f)
+ out.append(halve(canvas))
+ return out
+ if kind == "map":
+ # 'map:Map.png:x,y,w,h': a piece of an area's map, as it is
+ name, box = name.split(":")
+ x, y, w, h = map(int, box.split(","))
+ return [Image.open(os.path.join(ref, "wiki", "maps", name)).convert("RGBA").crop((x, y, x + w, y + h))]
+ if kind == "gen": # drawn by tools/sprites.py
+ return S.GEN[name]()
if kind == "wiki2": # a wiki file of the 640 x 480 battle, at the game's size: halved
im = Image.open(os.path.join(ref, "wiki", "sprites", name))
return [shrink(fr.convert("RGBA")) for fr in ImageSequence.Iterator(im)]
@@ -241,13 +270,19 @@ class Area:
def __init__(self, ref, spec):
im = Image.open(os.path.join(ref, "wiki", "maps", spec["map"]))
- if im.mode != "P":
- im = im.convert("RGB").quantize(256, method=Image.Quantize.MAXCOVERAGE)
- self.idx = np.array(im)
- p = im.getpalette()
- self.rgb = [tuple(p[3 * i:3 * i + 3]) for i in range(len(p) // 3)]
- self.transparent = im.info.get("transparency", None)
- if isinstance(self.transparent, bytes):
+ if im.mode == "P":
+ self.idx = np.array(im)
+ p = im.getpalette()
+ self.rgb = [tuple(p[3 * i:3 * i + 3]) for i in range(len(p) // 3)]
+ self.transparent = im.info.get("transparency", None)
+ if not isinstance(self.transparent, int): # (bytes: none of the palette's)
+ self.transparent = None
+ else:
+ # every colour exactly (some maps have more than 256)
+ a = np.asarray(im.convert("RGB")).astype(np.int32)
+ cols, inv = np.unique((a[..., 0] << 16) | (a[..., 1] << 8) | a[..., 2], return_inverse=True)
+ self.idx = inv.reshape(a.shape[:2]).astype(np.int32)
+ self.rgb = [(int(c) >> 16, int(c) >> 8 & 255, int(c) & 255) for c in cols]
self.transparent = None
self.spec = spec
for patch in spec.get("patches", []):
@@ -272,11 +307,25 @@ class Area:
self.idx[dy:dy + h, dx:dx + w] = self.idx[sy:sy + h, sx:sx + w].copy()
elif p[0] == "erase":
# the nearest pixel of the colours, looking a little around the rectangle (only it changes)
- _, x, y, w, h, cols = p
+ _, x, y, w, h, cols, *drop = p
+ if cols == "ring": # a little more than the box: the outline's last pixels
+ x, y, w, h = x - 2, y - 2, w + 4, h + 4
m = 4
x0, y0 = max(0, x - m), max(0, y - m)
win = self.idx[y0:y + h + m, x0:x + w + m]
- keep = np.isin(win, [i for i, k in enumerate(self.rgb) if k in [tuple(c) for c in cols]])
+ if cols == "ring":
+ # the colours just around the rectangle (but those of drop): what's behind the monster
+ ring = np.ones(win.shape, bool)
+ ring[y - y0:y - y0 + h, x - x0:x - x0 + w] = False
+ # (black: the outlines of what's erased, unless the patch says otherwise)
+ dropped = drop[0] if drop else [(0, 0, 0)]
+ # (only colours common around it: a few pixels of a colour are the monster's own, sticking out)
+ u, n = np.unique(win[ring], return_counts=True)
+ ids = {int(i) for i, c in zip(u, n) if c >= 0.05 * ring.sum()} - \
+ {i for i, k in enumerate(self.rgb) if k in dropped}
+ keep = np.isin(win, list(ids))
+ else:
+ keep = np.isin(win, [i for i, k in enumerate(self.rgb) if k in [tuple(c) for c in cols]])
if not keep.any():
raise ValueError("erase %s: none of its colours there" % (p,))
_, (iy, ix) = ndimage.distance_transform_edt(~keep, return_indices=True)
@@ -302,7 +351,7 @@ def room_pixels(area, r):
out = np.zeros((h, w), np.int32)
xs0, ys0, xs1, ys1 = max(x, 0), max(y, 0), min(x + w, W), min(y + h, H)
sub = area.idx[ys0:ys1, xs0:xs1]
- lut = np.array([rgb565(*c) for c in area.rgb] + [0] * (256 - len(area.rgb)), np.int32)
+ lut = np.array([rgb565(*c) for c in area.rgb] + [0] * max(0, 256 - len(area.rgb)), np.int32)
if area.transparent is not None:
lut[area.transparent] = 0
out[ys0 - y:ys1 - y, xs0 - x:xs1 - x] = lut[sub]
@@ -316,6 +365,9 @@ def floor_mask(area, r, x0, y0, x1, y1):
return np.isin(area.idx[y0:y1, x0:x1], walk_idx)
+KEEP = -32768 # a door's landing: Frisk's own x or y, kept
+
+
def apply_links(area, rooms):
"""the links between rooms one above the other through a dark doorway, ("v", lower, upper, x, w, y): a door
each way between the lower room's floor under the doorway (x .. x + w, y in it) and the upper's above it, the
@@ -324,6 +376,17 @@ def apply_links(area, rooms):
lo = rooms.get(link[1])
if lo is None or lo["area"] != area.spec["name"]:
continue
+ if link[0] == "h":
+ # side by side: the left room's right edge and the right one's left edge, Frisk's height kept
+ ri = rooms[link[2]]
+ y, h = link[3:5]
+ lx, _, lw, _ = lo["rect"]
+ rx = ri["rect"][0]
+ lo.setdefault("fix", []).append(("walk", lx + lw - 8, y, 8, h))
+ ri.setdefault("fix", []).append(("walk", rx, y, 8, h))
+ lo.setdefault("doors", []).append(((lx + lw - 2, y, 2, h), link[2], (rx + 2, KEEP), "right"))
+ ri.setdefault("doors", []).append(((rx, y, 2, h), link[1], (lx + lw - 22, KEEP), "left"))
+ continue
x, w, yd = link[3:6] if link[0] == "v" else link[2:5]
cx = x + w // 2
lx, ly, lw, lh = lo["rect"]
@@ -368,6 +431,8 @@ def collision(area, r):
xs0, ys0, xs1, ys1 = max(X0, 0), max(Y0, 0), min(X1, W), min(Y1, H)
big[ys0 - Y0:ys1 - Y0, xs0 - X0:xs1 - X0] = np.isin(area.idx[ys0:ys1, xs0:xs1], list(walk_idx))
sub = big[margin:margin + ch * 4, margin:margin + cw * 4]
+ if r.get("open"): # floors of many colours (a carpet, planks): its floor_rects alone say
+ sub = np.ones_like(sub)
cells = sub.reshape(ch, 4, cw, 4).mean(axis=(1, 3)) >= 0.5
# piles of leaves are floor, outline and all
soft = area.spec.get("piles")
@@ -384,6 +449,12 @@ def collision(area, r):
# other colour within `margin` pixels of it (a pile's leaves don't count)
if margin:
other = ~big & ~pile_big
+ # lines drawn on the floor (a path's outline) aren't walls
+ lines = area.spec.get("lines", []) + r.get("lines", [])
+ if lines:
+ win = np.zeros(big.shape, area.idx.dtype)
+ win[ys0 - Y0:ys1 - Y0, xs0 - X0:xs1 - X0] = area.idx[ys0:ys1, xs0:xs1]
+ other &= ~np.isin(win, [i for i, k in enumerate(area.rgb) if k in [tuple(c) for c in lines]])
near = np.zeros_like(sub)
for dy in range(2 * margin + 1):
for dx in range(2 * margin + 1):
@@ -396,8 +467,12 @@ def collision(area, r):
for fx, fy, fw, fh in r["floor_rects"]:
keep[max(0, (fy - y) // 4):max(0, (fy + fh - y + 3) // 4), max(0, (fx - x) // 4):max(0, (fx + fw - x + 3) // 4)] = True
cells &= keep
- for kind, fx, fy, fw, fh in r.get("fix", []):
- cells[max(0, (fy - y) // 4):max(0, (fy + fh - y + 3) // 4), max(0, (fx - x) // 4):max(0, (fx + fw - x + 3) // 4)] = kind == "walk"
+ raw = sub.reshape(ch, 4, cw, 4).mean(axis=(1, 3)) >= 0.5
+ for kind, fx, fy, fw, fh, *how in r.get("fix", []):
+ sl = (slice(max(0, (fy - y) // 4), max(0, (fy + fh - y + 3) // 4)),
+ slice(max(0, (fx - x) // 4), max(0, (fx + fw - x + 3) // 4)))
+ # "floor": walkable only where the floor's colours are (the edge of a room, past the margin rule)
+ cells[sl] = raw[sl] if how == ["floor"] else kind == "walk"
out = bytearray()
for row in cells:
rb = bytearray((cw + 7) // 8)
@@ -448,8 +523,25 @@ def pack_room(area, r, tiles, strings):
block = big[ty * 20:ty * 20 + 20, tx * 20:tx * 20 + 20]
grid += struct.pack("<H", 0xFFFF if not block.any() else tiles.add(block.astype(np.uint16)))
coll, cw, ch = collision(area, r)
+ flags = r.get("flags", 0)
+ if r.get("ice"):
+ # the ice: cells mostly of the area's ice colours, after the collision bits (ROOM_ICE)
+ ice_idx = [i for i, k in enumerate(area.rgb) if k in [tuple(c) for c in area.spec.get("ice", [])]]
+ m = np.zeros((ch * 4, cw * 4), bool)
+ sub = np.isin(area.idx[y:y + h, x:x + w], ice_idx)
+ m[:sub.shape[0], :sub.shape[1]] = sub
+ cells = m.reshape(ch, 4, cw, 4).mean(axis=(1, 3)) >= 0.5
+ for fx, fy, fw, fh in r.get("no_ice", []):
+ cells[max(0, (fy - y) // 4):(fy + fh - y + 3) // 4, max(0, (fx - x) // 4):(fx + fw - x + 3) // 4] = False
+ for row in cells:
+ rb = bytearray((cw + 7) // 8)
+ for i, v in enumerate(row):
+ if v:
+ rb[i >> 3] |= 1 << (i & 7)
+ coll += rb
+ flags |= 1
return dict(rect=(x, y, w, h), g=(gx, gy, cols, rows), grid=bytes(grid), coll=bytes(coll), cw=cw, ch=ch,
- area=r["area_id"], flags=r.get("flags", 0), name=strings.add(r.get("title", "")))
+ area=r["area_id"], flags=flags, name=strings.add(r.get("title", "")))
# ------------------------------------------------------------------ main
@@ -482,10 +574,41 @@ def main():
if not out or im.tobytes() != out[-1].tobytes():
out.append(im)
imgs = out
+ if "box" in opts:
+ bx, by, bw, bh = opts["box"]
+ imgs = [im.crop((bx, by, bx + bw, by + bh)) for im in imgs]
if "every" in opts:
imgs = imgs[::opts["every"]]
if "frames" in opts:
imgs = [imgs[i] for i in opts["frames"]]
+ if opts.get("clear_bg"): # the black around a monster (the wiki's GIFs have no see-through) is clear
+ out = []
+ for im in imgs:
+ a = np.array(im)
+ dark = (a[:, :, 0] < 8) & (a[:, :, 1] < 8) & (a[:, :, 2] < 8) | (a[:, :, 3] < 128)
+ lab, _ = ndimage.label(dark)
+ edge = set(np.unique(np.concatenate([lab[0], lab[-1], lab[:, 0], lab[:, -1]]))) - {0}
+ a[np.isin(lab, list(edge))] = 0
+ out.append(Image.fromarray(a, "RGBA"))
+ imgs = out
+ if "clear" in opts: # these colours are see-through (a map's floor behind a thing cut from it)
+ out = []
+ for im in imgs:
+ a = np.array(im)
+ for c in opts["clear"]:
+ a[(a[:, :, 0] == c[0]) & (a[:, :, 1] == c[1]) & (a[:, :, 2] == c[2])] = 0
+ out.append(Image.fromarray(a, "RGBA"))
+ imgs = out
+ if opts.get("mirror"):
+ imgs = [im.transpose(Image.FLIP_LEFT_RIGHT) for im in imgs]
+ if "tints" in opts: # the first frame, then it again in each colour (the SOUL's modes)
+ a = np.array(imgs[0].convert("RGBA"))
+ lum = a[:, :, :3].max(axis=2).astype(np.float32) / 255
+ imgs = [imgs[0]]
+ for t in opts["tints"]:
+ b = a.copy()
+ b[:, :, :3] = (lum[:, :, None] * np.array(t, np.float32)).astype(np.uint8)
+ imgs.append(Image.fromarray(b, "RGBA"))
if "scale" in opts:
imgs = [im.resize((im.width * opts["scale"], im.height * opts["scale"]), Image.NEAREST) for im in imgs]
w0, h0 = imgs[0].size
diff --git a/games/undertale/tools/rooms.py b/games/undertale/tools/rooms.py
index 4ebfb97b..31a80b56 100644
--- a/games/undertale/tools/rooms.py
+++ b/games/undertale/tools/rooms.py
@@ -58,6 +58,51 @@ AREAS = [
]),
]
+SNOW = [(133, 163, 216), (114, 129, 177)]
+ICE = [(139, 163, 186), (180, 192, 201), (195, 207, 216)]
+WOOD = [(169, 124, 41), (91, 65, 0), (62, 35, 0)]
+# the paths' outlines
+SNOW_LINES = [(44, 46, 63)]
+INN_FLOOR = [(249, 210, 97)]
+PS_FLOOR = [(109, 85, 127), (74, 109, 127)]
+# the XOXO puzzles' tiles (drawn by the game, X or O), the spikes it raises and lowers
+XOXO1 = [(7460, 1240), (7540, 1240)]
+XOXO2 = [(8180, 1200), (8240, 1200), (8280, 1200), (8240, 1220), (8280, 1220), (8200, 1240), (8240, 1240),
+ (8260, 1240), (8280, 1240), (8180, 1260), (8240, 1260), (8180, 1280), (8200, 1280), (8220, 1280), (8240, 1280)]
+XOXO3 = [(9540, 1160), (9700, 1160), (9540, 1180), (9580, 1180), (9660, 1180), (9620, 1220), (9580, 1240),
+ (9620, 1240), (9580, 1260), (9660, 1260), (9540, 1300), (9700, 1300)]
+SNOW_SPIKES = [(7120, 940), (7120, 960), (7120, 980), (7680, 1220), (7680, 1240), (7680, 1260)] + \
+ [(8360, 1160 + 20 * i) for i in range(8)]
+BLUE = [(0, 0, 255)]
+SPIKE_COLOURS = [(128, 128, 128), (192, 192, 192), (255, 255, 255), (0, 0, 0)]
+AREAS.append(dict(name="snowdin", map="Snowdin_map.png", floor=SNOW + ICE + WOOD, margin=2, lines=SNOW_LINES, ice=ICE,
+ patches=[
+ # Sans, Papyrus and the monsters who come out after Papyrus' fight or at the very end; the SAVE stars
+ ("erase", 2881, 400, 26, 40, "ring"), ("erase", 3236, 374, 28, 34, "ring"), ("erase", 4668, 380, 37, 37, "ring"),
+ ("erase", 5440, 290, 42, 56, "ring"), ("erase", 6108, 280, 54, 58, "ring"), ("erase", 6508, 610, 54, 56, "ring"),
+ ("erase", 6743, 695, 24, 27, "ring"), ("erase", 7332, 944, 94, 52, "ring"), ("erase", 7858, 1170, 44, 60, "ring"),
+ ("erase", 8008, 1160, 44, 49, "ring"), ("erase", 8374, 1186, 32, 42, "ring"), ("erase", 8816, 1254, 34, 46, "ring"),
+ ("erase", 9258, 1300, 24, 27, "ring"), ("erase", 9692, 1488, 36, 44, "ring"), ("erase", 10630, 1270, 38, 50, "ring"),
+ ("erase", 11772, 1176, 38, 48, "ring"), ("erase", 10182, 2274, 38, 46, "ring"),
+ ("erase", 10328, 2255, 69, 58, "ring"), ("erase", 10532, 2274, 38, 46, "ring"),
+ ("erase", 7026, 576, 58, 50, "ring"), ("erase", 5948, 258, 54, 52, "ring"),
+ # Snowdrake and his parents by Papyrus' sentry station: the trees and the path there from beside (the trees
+ # repeat every 40 pixels)
+ ("copy", 3620, 316, 80, 72, 3700, 316), ("copy", 3620, 316, 80, 72, 3780, 316), ("copy", 3620, 316, 30, 72, 3860, 316),
+]))
+# (the puzzles' tiles and spikes first: what's beside them is erased after)
+AREAS[-1]["patches"][:0] = [("erase", x, y, 20, 20, "ring", BLUE) for x, y in XOXO1 + XOXO2 + XOXO3] + \
+ [("erase", x, y, 20, 20, "ring", SPIKE_COLOURS) for x, y in SNOW_SPIKES]
+AREAS.append(dict(name="snowtown", map="Snowdin_Town_map.png", floor=SNOW, margin=2, lines=SNOW_LINES, patches=[
+ # the SAVE star; Papyrus and Undyne by the house, the dogs at the library, Papyrus in the fog and at home
+ # (they come later)
+ ("erase", 518, 1076, 22, 22, "ring"),
+ ("erase", 1860, 1008, 34, 82, "ring"), ("erase", 1898, 1010, 56, 78, "ring"), ("erase", 1952, 1004, 44, 86, "ring"),
+ ("erase", 1998, 1012, 40, 78, "ring"), ("erase", 2038, 1018, 40, 72, "ring"),
+ ("erase", 2132, 1026, 32, 84, "ring"), ("erase", 2163, 1040, 32, 72, "ring"),
+ ("erase", 3376, 1036, 30, 66, "ring"), ("erase", 2212, 854, 32, 50, "ring"), ("erase", 2262, 580, 36, 52, "ring"),
+]))
+
ROOMS = [
# the landing: the bed of golden flowers, a hallway, the Delta Rune arch
dict(name="area1", area="ruins", rect=(0, 5900, 680, 260), title="Ruins", margin=0,
@@ -176,10 +221,104 @@ ROOMS = [
fix=[("walk", 10000, 1950, 40, 10)], doors=[((10000, 1956, 40, 4), "basement2", (10010, 2034), "down")]),
dict(name="ruinsexit", area="ruins", floor_colors=[(0, 0, 0), (97, 44, 97)], margin=0, rect=(9940, 0, 200, 300),
floor_rects=[(9980, 70, 80, 230)], title="Ruins - Exit"),
+
+ # ---- Snowdin: the forest, from the Ruins' door to the town
+ # the forest's walkway: the path is walked all along (trunks and a branch drawn over it are in front)
+ dict(name="snowdin1", area="snowdin", rect=(0, 240, 1070, 240), title="Snowdin Forest",
+ fix=[("walk", 40, 404, 1030, 52)]),
+ dict(name="snowdin2", area="snowdin", rect=(1100, 240, 670, 240), title="Snowdin Forest", fix=[("walk", 1100, 404, 670, 52)]),
+ dict(name="snowdin3", area="snowdin", rect=(1800, 240, 410, 240), title="Snowdin Forest", fix=[("walk", 1800, 404, 410, 52)]),
+ dict(name="snowdin4", area="snowdin", rect=(2240, 240, 300, 240), title="Snowdin Forest", fix=[("walk", 2240, 404, 300, 52)]),
+ # Papyrus' gate on the bridge: its bars are too wide to stop anyone
+ dict(name="snowdin5", area="snowdin", rect=(2570, 240, 590, 240), title="Snowdin Forest",
+ fix=[("walk", 2570, 412, 100, 44)]),
+ dict(name="boxroad", area="snowdin", rect=(3160, 240, 380, 240), title="Snowdin - Box Road"),
+ dict(name="river", area="snowdin", rect=(3220, 0, 320, 240), title="Snowdin Forest"),
+ dict(name="papsentry", area="snowdin", rect=(3540, 240, 580, 240), title="Snowdin Forest"),
+ dict(name="doggo", area="snowdin", rect=(4120, 240, 460, 240), title="Snowdin Forest"),
+ dict(name="icefield", area="snowdin", rect=(4580, 240, 620, 240), ice=True, title="Snowdin Forest"),
+ dict(name="snowman", area="snowdin", rect=(4720, 0, 380, 240), title="Snowdin Forest"),
+ dict(name="elecmaze", area="snowdin", rect=(5200, 240, 300, 240), title="Snowdin Forest"),
+ dict(name="ballgame", area="snowdin", rect=(5500, 240, 800, 580), ice=True, title="Snowdin Forest",
+ fix=[("walk", 5716, 318, 68, 22)]), # the plank bridge over the chasm
+ dict(name="dogi", area="snowdin", rect=(6300, 240, 300, 220), title="Snowdin Forest"),
+ dict(name="wordsearch", area="snowdin", rect=(6300, 520, 320, 300), title="Snowdin Forest"),
+ dict(name="spaghetti", area="snowdin", rect=(6620, 520, 300, 300), title="Snowdin - Spaghetti"),
+ dict(name="snowpuzzle", area="snowdin", rect=(6920, 540, 620, 580), title="Snowdin Forest",
+ fix=[("walk", 7254, 958, 50, 22)]), # the plank bridge
+ dict(name="xoxo1", area="snowdin", rect=(7260, 1120, 440, 240), title="Snowdin Forest"),
+ dict(name="xoxo2", area="snowdin", rect=(7700, 1120, 800, 240), title="Snowdin Forest"),
+ dict(name="tilepuzzle", area="snowdin", rect=(8500, 1120, 400, 240), title="Snowdin Forest",
+ floor_colors=[(255, 192, 192)], fix=[("walk", 8614, 1238, 52, 22)]), # the plank bridge
+ dict(name="doghouse", area="snowdin", rect=(8900, 1120, 540, 240), title="Snowdin - Dog House"),
+ # the ice puzzle: once solved, a bridge to the trees Frisk slides through (an object blocks it until then)
+ dict(name="xoxo3", area="snowdin", rect=(9440, 1120, 400, 220), ice=True, title="Snowdin Forest",
+ fix=[("walk", 9780, 1204, 60, 36), ("walk", 9520, 1320, 264, 20)], doors=[((9836, 1205, 4, 40), "poffzone", (10196, 1200), "right")]),
+ dict(name="xoxofail", area="snowdin", rect=(9440, 1340, 340, 260), title="Snowdin Forest"),
+ dict(name="poffzone", area="snowdin", rect=(10140, 1120, 820, 240), title="Snowdin Forest",
+ fix=[("walk", 10190, 1212, 40, 24), ("walk", 10840, 1260, 120, 14)],
+ doors=[((10190, 1195, 4, 30), "xoxo3", (9796, 1200), "left"),
+ ((10302, 1350, 36, 8), "southcliff", (10590, 2190), "down")]),
+ dict(name="dangerbridge", area="snowdin", rect=(10960, 1120, 1040, 240), title="Snowdin Forest",
+ fix=[("walk", 11110, 1226, 690, 26)], doors=[((11990, 1236, 10, 50), "snowtown", (4, 1088), "right")]),
+ # the mysterious door, up a long corridor from the cliff under the ice bridge
+ dict(name="doorroom", area="snowdin", rect=(9780, 1590, 320, 590), title="Snowdin Forest",
+ floor_colors=[(22, 67, 88), (27, 89, 109), (30, 106, 122), (6, 14, 22), (13, 37, 51), (19, 56, 75)]),
+ dict(name="southcliff", area="snowdin", rect=(9480, 2180, 1200, 240), title="Snowdin Forest",
+ fix=[("walk", 9922, 2180, 40, 60)], doors=[((10585, 2180, 30, 6), "poffzone", (10310, 1320), "up")]),
+
+ # ---- Snowdin Town
+ dict(name="snowtown", area="snowtown", rect=(0, 960, 3260, 240), title="Snowdin Town",
+ fix=[("walk", 0, 1080, 8, 50, "floor")],
+ doors=[((0, 1080, 4, 50), "dangerbridge", (11968, 1232), "left"),
+ ((624, 1066, 28, 24), "inn1", (628, 918), "up"), ((1312, 1070, 26, 20), "grillbys", (1236, 914), "up"),
+ ((1840, 1066, 26, 24), "library", (2026, 664), "up"),
+ # the undersnow tunnels: an igloo each end of the town
+ ((726, 1066, 24, 24), "snowtown", (2336, 1094), "down"), ((2336, 1084, 26, 16), "snowtown", (728, 1078), "down")]),
+ dict(name="townnorth", area="snowtown", rect=(1400, 700, 640, 260), title="Snowdin Town"),
+ dict(name="towndock", area="snowtown", rect=(1400, 480, 410, 220), title="Snowdin Town"),
+ dict(name="fogroom", area="snowtown", rect=(3260, 960, 360, 240), title="Snowdin Town",
+ fix=[("walk", 3440, 1084, 180, 48)]), # the way on: Waterfall's blue ground
+ # the interiors: their floors are many colours, so their floor and furniture are rectangles
+ dict(name="inn1", area="snowtown", rect=(500, 740, 260, 220), title="Snowed Inn", open=True, margin=0,
+ floor_rects=[(520, 800, 222, 100), (600, 900, 80, 60), (536, 756, 44, 48)],
+ fix=[("wall", 705, 850, 37, 50)],
+ doors=[((604, 952, 72, 8), "snowtown", (626, 1078), "down"), ((536, 756, 44, 6), "inn2", (512, 676), "right")]),
+ dict(name="inn2", area="snowtown", rect=(500, 480, 320, 230), title="Snowed Inn", open=True, margin=0,
+ floor_rects=[(522, 600, 116, 76), (662, 600, 136, 76), (504, 684, 312, 22), (566, 670, 32, 16), (706, 670, 32, 16)],
+ doors=[((504, 684, 4, 22), "inn1", (548, 790), "down")]),
+ dict(name="grillbys", area="snowtown", rect=(1080, 710, 320, 250), title="Grillby's", open=True, margin=0,
+ floor_rects=[(1090, 800, 300, 150)],
+ fix=[("wall", 1092, 826, 64, 44), ("wall", 1140, 884, 104, 48), ("wall", 1300, 820, 90, 130),
+ ("wall", 1098, 924, 44, 26)],
+ doors=[((1220, 944, 50, 6), "snowtown", (1314, 1080), "down")]),
+ dict(name="library", area="snowtown", rect=(1810, 480, 300, 225), title="Librarby", open=True, margin=0,
+ floor_rects=[(1822, 566, 276, 132)], fix=[("wall", 1822, 620, 88, 80), ("wall", 1976, 616, 88, 66)],
+ doors=[((2000, 694, 70, 6), "snowtown", (1842, 1078), "down")]),
+ dict(name="pshouse", area="snowtown", rect=(2210, 710, 300, 245), title="Snowdin Town", open=True, margin=0,
+ floor_rects=[(2220, 848, 280, 100), (2220, 768, 280, 34), (2222, 800, 56, 52)],
+ fix=[("wall", 2300, 892, 82, 40), ("wall", 2318, 836, 52, 30), ("wall", 2462, 868, 40, 64)],
+ doors=[((2420, 944, 50, 8), "snowtown", (2240, 1096), "down"), ((2228, 766, 34, 4), "paproom", (2296, 660), "up"), ((2440, 766, 30, 4), "sansroom", (2560, 660), "up")]),
+ dict(name="paproom", area="snowtown", rect=(2150, 500, 260, 200), title="Snowdin Town", open=True, margin=0,
+ floor_rects=[(2160, 574, 240, 120)],
+ fix=[("wall", 2160, 636, 92, 56), ("wall", 2338, 556, 64, 44), ("wall", 2160, 556, 40, 64),
+ ("wall", 2358, 648, 44, 44)],
+ doors=[((2286, 690, 40, 8), "pshouse", (2234, 774), "down")]),
+ dict(name="sansroom", area="snowtown", rect=(2470, 510, 180, 190), title="Snowdin Town", open=True, margin=0,
+ floor_rects=[(2480, 566, 160, 126)], fix=[("wall", 2480, 560, 52, 32), ("wall", 2598, 556, 42, 56)],
+ doors=[((2550, 690, 40, 8), "pshouse", (2444, 774), "down")]),
+ dict(name="shed", area="snowtown", rect=(2550, 710, 290, 245), title="Snowdin Town", open=True, margin=0,
+ floor_rects=[(2580, 770, 180, 120), (2560, 886, 80, 64)], fix=[("wall", 2580, 730, 56, 100)],
+ doors=[((2560, 945, 80, 8), "snowtown", (2400, 1096), "down")]),
]
-# rooms one above the other through a dark doorway (tools/pack.py: apply_links)
+# rooms one above the other through a dark doorway (tools/pack.py: apply_links); ("h", left, right, y, h): side
+# by side with a gap, a door each way along the rows y .. y + h
LINKS = [
+ ("h", "snowdin1", "snowdin2", 404, 52),
+ ("h", "snowdin2", "snowdin3", 404, 52),
+ ("h", "snowdin3", "snowdin4", 404, 52),
+ ("h", "snowdin4", "snowdin5", 404, 52),
("v", "ruins1", "ruins2", 506, 28, 5175),
("v", "ruins4", "ruins5", 1244, 32, 4640),
("v", "ruins7", "ruins7a", 4946, 28, 4400),
diff --git a/games/undertale/tools/sprites.py b/games/undertale/tools/sprites.py
index 56f5de8c..79597cdc 100644
--- a/games/undertale/tools/sprites.py
+++ b/games/undertale/tools/sprites.py
@@ -6,7 +6,112 @@ A sprite: (name, source or [sources], options). Sources (tools/pack.py load_fram
wiki:File.png a file of the Undertale Wiki, every frame of a GIF; the wiki shows sprites at twice the size,
halved here (wiki1: as it is)
Options: origin (x, y) in the source's pixels, center (its middle), feet (the middle of its bottom),
-frames (which of them), keep (no crop to the opaque pixels)."""
+frames (which of them), keep (no crop to the opaque pixels), every (one frame in n), clear (colours made
+see-through), mirror (flipped left to right), box (x, y, w, h: a part of the source, after halving).
+More sources: move:File.gif:x0,y0,x1,y1:frames (what moves in a wiki screenshot GIF), map:Map.png:x,y,w,h (a piece
+of an area's map), gen:name (drawn here, GEN)."""
+from PIL import Image, ImageDraw
+
+
+def _img(w, h):
+ return Image.new("RGBA", (w, h), (0, 0, 0, 0))
+
+
+def gen_otile():
+ # the XOXO puzzles' O (red), and once the puzzle's solved, the same in green
+ out = []
+ for c in ((255, 0, 0, 255), (0, 192, 0, 255)):
+ im = _img(20, 20)
+ d = ImageDraw.Draw(im)
+ d.ellipse([3, 3, 16, 16], outline=c, width=2)
+ out.append(im)
+ return out
+
+
+def gen_snowball():
+ # the Ball Game's snowball, from big to small (it melts as it rolls)
+ out = []
+ for r in (10, 9, 8, 7, 6, 5, 4, 3):
+ im = _img(22, 22)
+ d = ImageDraw.Draw(im)
+ d.ellipse([11 - r, 11 - r, 11 + r, 11 + r], fill=(255, 255, 255, 255), outline=(0, 0, 0, 255))
+ d.arc([11 - r + 2, 11 - r + 2, 11 + r - 2, 11 + r - 2], 200, 300, fill=(180, 192, 220, 255))
+ out.append(im)
+ return out
+
+
+def gen_bone():
+ # a bone 6 pixels wide, its ends' knobs (drawn stretched to any length: gfx_bone)
+ im = _img(6, 6)
+ d = ImageDraw.Draw(im)
+ d.rectangle([0, 0, 5, 5], fill=(255, 255, 255, 255))
+ return [im]
+
+
+def gen_orb():
+ im = _img(10, 10)
+ d = ImageDraw.Draw(im)
+ d.ellipse([0, 0, 9, 9], fill=(200, 220, 255, 255), outline=(255, 255, 255, 255))
+ return [im]
+
+
+def gen_snowflake():
+ im = _img(9, 9)
+ d = ImageDraw.Draw(im)
+ for a, b in (((4, 0), (4, 8)), ((0, 4), (8, 4)), ((1, 1), (7, 7)), ((1, 7), (7, 1))):
+ d.line([a, b], fill=(255, 255, 255, 255))
+ return [im]
+
+
+def gen_iceshard():
+ im = _img(7, 11)
+ d = ImageDraw.Draw(im)
+ d.polygon([(3, 0), (6, 4), (3, 10), (0, 4)], fill=(255, 255, 255, 255))
+ return [im]
+
+
+def gen_present():
+ im = _img(10, 10)
+ d = ImageDraw.Draw(im)
+ d.rectangle([0, 2, 9, 9], fill=(255, 255, 255, 255))
+ d.rectangle([4, 2, 5, 9], fill=(0, 0, 0, 255))
+ d.rectangle([0, 5, 9, 5], fill=(0, 0, 0, 255))
+ d.line([(2, 0), (4, 2)], fill=(255, 255, 255, 255))
+ d.line([(7, 0), (5, 2)], fill=(255, 255, 255, 255))
+ return [im]
+
+
+def gen_knife():
+ # Doggo's dog-knife: a blade, up
+ im = _img(5, 30)
+ d = ImageDraw.Draw(im)
+ d.polygon([(2, 0), (4, 6), (4, 24), (0, 24), (0, 6)], fill=(255, 255, 255, 255))
+ d.rectangle([0, 24, 4, 29], fill=(255, 255, 255, 255))
+ return [im]
+
+
+def gen_dogpaw():
+ im = _img(9, 9)
+ d = ImageDraw.Draw(im)
+ d.ellipse([2, 4, 7, 8], fill=(255, 255, 255, 255))
+ for x in (1, 4, 7):
+ d.ellipse([x - 1, 0, x + 1, 2], fill=(255, 255, 255, 255))
+ return [im]
+
+
+def gen_heartbullet():
+ im = _img(9, 8)
+ d = ImageDraw.Draw(im)
+ d.polygon([(0, 2), (2, 0), (4, 2), (6, 0), (8, 2), (4, 7)], fill=(255, 255, 255, 255))
+ return [im]
+
+
+GEN = {"otile": gen_otile, "snowball": gen_snowball, "bone": gen_bone, "orb": gen_orb, "snowflake": gen_snowflake,
+ "iceshard": gen_iceshard, "present": gen_present, "knife": gen_knife, "dogpaw": gen_dogpaw,
+ "heartbullet": gen_heartbullet}
+
+SNOW_CLEAR = [(133, 163, 216), (114, 129, 177), (139, 163, 186), (180, 192, 201), (195, 207, 216)]
+PAP_GIF = "move:Papyrus_screenshot_back_and_forth.gif:0,280,640,450:"
SPRITES = [
# Frisk walking: down and up 4 frames, left and right 2 (the game's own frames, from the demo)
@@ -21,7 +126,7 @@ SPRITES = [
("savepoint", "demo:spr_savepoint", {"origin": (0, 0), "keep": True}),
("flowey", "demo:spr_flowey", {"origin": (0, 0), "keep": True}),
# the SOUL, 8 x 8 as the game's 16 x 16 halved; frame 1: blue
- ("heart", "demo2:spr_heart", {"center": True, "keep": True}),
+ ("heart", "demo2:spr_heart", {"center": True, "keep": True, "tints": [(0, 60, 255)]}), # red, blue
] + [
# the battle: its buttons (orange, then yellow when chosen), the FIGHT target and its bar, the slash, the HP label
(n, "demo2:spr_" + n, {"keep": True}) for n in [
@@ -74,6 +179,67 @@ SPRITES = [
] + [
("frog_ow", "wiki:Froggit_overworld.png", {"keep": True}),
("napsta_ow", "wiki:Napstablook_overworld.png", {"keep": True}),
+] + [
+ # ---- Snowdin
+ # Papyrus walking (from a screenshot of him pacing at home: right; left is the same, mirrored), and facing you
+ ("papyrus_r", PAP_GIF + "19,21,23,25", {"feet": True}),
+ ("papyrus_l", PAP_GIF + "19,21,23,25", {"feet": True, "mirror": True}),
+ ("papyrus_d", "wiki:Papyrus_overworld.png", {"feet": True}),
+ ("sans_d", "wiki:Sans_overworld.png", {"feet": True}),
+ ("doggo_ow", "wiki:Doggo_overworld.png", {"feet": True}),
+ ("dogamy_ow", "wiki:Dogamy_overworld.png", {"feet": True}),
+ ("dogaressa_ow", "wiki:Dogaressa_overworld.png", {"feet": True}),
+ ("greaterdog_ow", "wiki:Greater_Dog_overworld.png", {"feet": True}),
+ ("poff", "wiki:Greater_Dog_overworld_snow_poff.png", {"feet": True}),
+ ("dog_ow", "wiki:Annoying_Dog_sprite.gif", {"feet": True}),
+ ("dog_bone", "wiki:Annoying_Dog_sprite_bone.gif", {"feet": True, "dedupe": True}),
+ # the puzzles' things: an X tile, its O, Snowdin's spikes (all cut from the map: its snow made see-through),
+ # the switches, the snowball, the electric orb
+ ("xtile", "map:Snowdin_map.png:7460,1240,20,20", {"keep": True, "clear": SNOW_CLEAR}),
+ ("otile", "gen:otile", {"keep": True}),
+ ("snowspikes", "map:Snowdin_map.png:7680,1220,20,20", {"keep": True, "clear": SNOW_CLEAR}),
+ ("snowswitch", "map:Snowdin_map.png:7498,1196,24,14", {"keep": True, "clear": SNOW_CLEAR}),
+ ("snowball", "gen:snowball", {"center": True, "keep": True}),
+ ("lamp", "map:Snowdin_map.png:2960,365,19,31", {"keep": True, "clear": SNOW_CLEAR + [(44, 46, 63)]}),
+ ("papyrus_zap", "wiki:Papyrus_overworld_electrocuted.gif", {"feet": True, "dedupe": True}),
+] + [
+ # the Ball Game's flags, by the time the ball took
+ ("flag_" + c, "wiki:%s_flag_overworld.png" % n, {"feet": True}) for c, n in [
+ ("lightblue", "Light_blue"), ("purple", "Purple"), ("green", "Green"), ("blue", "Blue"), ("yellow", "Yellow"),
+ ("orange", "Orange"), ("red", "Red")]
+] + [
+ ("orb", "gen:orb", {"center": True, "keep": True}),
+ # the shop's picture (QC behind her counter): the top of the wiki's screenshot
+ ("shop_qc", "wiki:QC_screenshot_shop.png", {"keep": True, "box": (0, 0, 320, 120)}),
+] + [
+ # Snowdin's bullets, their middle at their origin
+ (n, "gen:" + n, {"center": True}) for n in ["bone", "snowflake", "iceshard", "present", "knife", "dogpaw",
+ "heartbullet"]
+] + [
+ # Snowdin's monsters
+ ("snowdrake_b", "wiki:Snowdrake_battle.gif", {"feet": True, "clear_bg": True, "every": 6}),
+ ("snowdrake_hurt", "wiki:Snowdrake_battle_hurt.png", {"feet": True, "clear_bg": True}),
+ ("icecap_b", "wiki:Ice_Cap_battle_idle.gif", {"feet": True, "clear_bg": True}),
+ ("icecap_hurt", "wiki:Ice_Cap_battle_hurt.png", {"feet": True, "clear_bg": True}),
+ ("icecap_hatless", "wiki:Ice_Cap_battle_hatless.png", {"feet": True, "clear_bg": True}),
+ ("gyftrot_b", "wiki:Gyftrot_battle_idle.gif", {"feet": True, "clear_bg": True, "every": 14}),
+ ("gyftrot_hurt", "wiki:Gyftrot_battle_hurt.png", {"feet": True, "clear_bg": True}),
+ ("doggo_b", "wiki:Doggo_battle_idle.gif", {"feet": True, "clear_bg": True, "dedupe": True, "every": 8}),
+ ("doggo_hurt", "wiki:Doggo_battle_hurt.png", {"feet": True, "clear_bg": True}),
+ ("lesserdog_b", "wiki:Lesser_Dog_battle_idle.gif", {"feet": True, "clear_bg": True}),
+ ("lesserdog_hurt", "wiki:Lesser_Dog_battle_hurt.png", {"feet": True, "clear_bg": True}),
+ ("greaterdog_b", "wiki:Greater_Dog_battle.gif", {"feet": True, "clear_bg": True}),
+ ("greaterdog_hurt", "wiki:Greater_Dog_battle_hurt.png", {"feet": True, "clear_bg": True}),
+ ("dogamy_b", "wiki:Dogamy_battle.png", {"feet": True, "clear_bg": True}),
+ ("dogaressa_b", "wiki:Dogaressa_battle.png", {"feet": True, "clear_bg": True}),
+ ("jerry_b", "wiki:Jerry_battle.gif", {"feet": True, "clear_bg": True}),
+ ("jerry_hurt", "wiki:Jerry_battle_hurt.png", {"feet": True, "clear_bg": True}),
+ ("chilldrake_b", "wiki:Chilldrake_battle_idle.gif", {"feet": True, "clear_bg": True, "every": 6}),
+ ("glyde_b", "wiki:Glyde_battle_idle.gif", {"feet": True, "clear_bg": True, "dedupe": True, "every": 15}),
+ ("glyde_hurt", "wiki:Glyde_battle_hurt.png", {"feet": True, "clear_bg": True}),
+ ("papyrus_b", "wiki:Papyrus_battle.png", {"feet": True, "clear_bg": True}),
+ ("papyrus_hurt", "wiki:Papyrus_battle_hurt.png", {"feet": True, "clear_bg": True}),
+ ("papyrus_confused", "wiki:Papyrus_battle_confused.gif", {"feet": True, "clear_bg": True, "dedupe": True}),
] + [
# the intro's pictures, the title, GAME OVER
("introimage", "demo:spr_introimage", {"keep": True, "clear_black": True}),
diff --git a/tools/release.py b/tools/release.py
index 689c7c2b..b8b05e0b 100644
--- a/tools/release.py
+++ b/tools/release.py
@@ -27,9 +27,9 @@ ALONE = {
"on its own"),
"hollowknight": ("Hollow Knight", "from King's Pass to Hornet in Greenpath. Too big to share the calculator with "
"NumPlay: install it on its own"),
- "undertale": ("Undertale", "the Ruins, from the bed of golden flowers to the door out: Flowey, Toriel, Napstablook "
- "and every puzzle, the rest of the Underground to come. Too big to share the calculator with NumPlay: "
- "install it on its own"),
+ "undertale": ("Undertale", "the Ruins and Snowdin, from the bed of golden flowers to the edge of Waterfall: Flowey, "
+ "Toriel, Sans, Papyrus and every puzzle, the rest of the Underground to come. Too big to share the "
+ "calculator with NumPlay: install it on its own"),
"championisland": ("Champion Island", "the Doodle Champion Island Games. Too big to share the calculator with "
"NumPlay: install it on its own"),
"numpowder": ("NumPowder", "The Powder Toy on the calculator: sand, water, fire, acid, electricity and nearly 200 "