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.
C calculatorcalculator-gamescasiochesscrossy-roaddrive-madfx-cg50gamesgeometry-dashgraphing-calculatorndlessnumworksnumworks-appsnumworks-calculatornumworks-gamenumworks-gamestetristi-84-plus-ceti-nspire
Undertale: walk on while they walk off after a talk, as in the game; Frisk in Toriel's mirror
Mason3631734a1d73ac0
diff --git a/games/undertale/src/core.c b/games/undertale/src/core.cindex fda6263c..4ce54ab3 100644--- a/games/undertale/src/core.c+++ b/games/undertale/src/core.c@@ -526,8 +526,7 @@ static int ev_hall(Ev *c) {SAY(FACE_ALPHYS, "* ...one of you won't come\n back.|* I'm sorry. I made it all up,\n so I'd seem like a hero.|* Good luck. You deserve a\n better friend than me.");set_flag(F_CORE_HALL, 1);a = obj_get(ACTOR_ALPHYS);- WALK(a, 3360, a->y, 3);- gone(obj_get(ACTOR_ALPHYS));+ LEAVE(a, 3, 3360, a->y);EV_END;}diff --git a/games/undertale/src/event.h b/games/undertale/src/event.hindex b408f2f4..98c33cf9 100644--- a/games/undertale/src/event.h+++ b/games/undertale/src/event.h@@ -38,7 +38,11 @@ typedef struct Ev {#define CHOOSE(opts, n) do { text_open_menu(opts, n); WAIT_UNTIL(!text_active()); } while (0)#define CHOSEN() text_choice()/* an object walks to (x, y) at sp pixels a frame; WALK waits for it */-#define WALK_TO(o, X, Y, SP) do { (o)->tx = (int16_t)(X), (o)->ty = (int16_t)(Y), (o)->speed = (uint8_t)(SP), (o)->walking = 1; } while (0)+#define WALK_TO(o, X, Y, SP) do { obj_walk_cancel(o); (o)->tx = (int16_t)(X), (o)->ty = (int16_t)(Y), (o)->speed = (uint8_t)(SP), (o)->walking = 1; } while (0)+/* it walks off through (x, y) points on its own and is gone at the last: the cutscene doesn't wait (Frisk walks) */+#define LEAVE(o, SP, ...) obj_walk_off(o, SP, -1, (int)(sizeof((int[]){__VA_ARGS__}) / sizeof(int) / 2), __VA_ARGS__)+/* the same, staying at the last point, facing DIR */+#define WALK_ON(o, SP, DIR, ...) obj_walk_off(o, SP, DIR, (int)(sizeof((int[]){__VA_ARGS__}) / sizeof(int) / 2), __VA_ARGS__)#define WALK(o, X, Y, SP) do { WALK_TO(o, X, Y, SP); WAIT_UNTIL(!(o)->walking); } while (0)/* Frisk walks to (x, y), as a cutscene moves him */#define PL_WALK(X, Y, SP) do { pl_walk_to(X, Y, SP); WAIT_UNTIL(!pl_walking()); } while (0)diff --git a/games/undertale/src/ht1.c b/games/undertale/src/ht1.cindex 559e0f68..d5ad89f1 100644--- a/games/undertale/src/ht1.c+++ b/games/undertale/src/ht1.c@@ -334,8 +334,7 @@ static int ev_lab(Ev *c) {set_flag(F_HT_LAB, 2);SAY(FACE_ALPHYS, "* There! It has a few new...\n features.|* I'll, um, call you if I can help.|* Now I have to go to the...\n bathroom. Good luck!");a = obj_get(ACTOR_ALPHYS);- WALK(a, 2342, 6225, 3);- gone(obj_get(ACTOR_ALPHYS));+ LEAVE(a, 3, 2342, 6225);EV_END;}diff --git a/games/undertale/src/ht2.c b/games/undertale/src/ht2.cindex 06186543..b65612f9 100644--- a/games/undertale/src/ht2.c+++ b/games/undertale/src/ht2.c@@ -393,10 +393,8 @@ static int ev_guards(Ev *c) {}set_flag(F_HT_GUARDS, 1);NARRATE("* So, uh... we're gonna go get\n some ice cream now.|* Later, dude!");- WALK_TO(b, 3230, b->y, 3);- WALK(a, 3230, a->y, 3);- gone(obj_get(ACTOR_RG01));- gone(obj_get(ACTOR_RG02));+ LEAVE(b, 3, 3230, b->y);+ LEAVE(a, 3, 3230, a->y);EV_END;}@@ -425,8 +423,7 @@ static int ev_news(Ev *c) {}NARRATE("* ALPHYS HACKED MY BOMB?!|* UGH! THAT'S ALL FOR TONIGHT,\n FOLKS!");m = obj_get(ACTOR_METTATON);- WALK(m, m->x, m->y - 200, 6);- gone(obj_get(ACTOR_METTATON));+ LEAVE(m, 6, m->x, m->y - 200);fields_down();news = NEWS_OVER;set_flag(F_HT_NEWS, c->v[0]);diff --git a/games/undertale/src/ht3.c b/games/undertale/src/ht3.cindex 1a5fcfe0..b271350a 100644--- a/games/undertale/src/ht3.c+++ b/games/undertale/src/ht3.c@@ -296,8 +296,7 @@ static int ev_muffet(Ev *c) {set_flag(F_HT_MUFFET, 1);NARRATE("* Ahuhu... no hard feelings,\n deary~|* Do come back to our bake sale!");m = obj_get(ACTOR_MUFFET);- WALK(m, m->x + 200, m->y, 3);- gone(obj_get(ACTOR_MUFFET));+ LEAVE(m, 3, m->x + 200, m->y);EV_END;}@@ -365,8 +364,7 @@ static int ev_tiles_end(Ev *c) {set_flag(F_HT_TILES3, c->v[0]);NARRATE("* OHHH... I'M ALL OUT OF POWER.|* UNTIL NEXT TIME, DARLING!\n* STAY TUNED!");m = obj_get(ACTOR_METTATON);- WALK(m, m->x, m->y - 220, 6);- gone(obj_get(ACTOR_METTATON));+ LEAVE(m, 6, m->x, m->y - 220);EV_END;}diff --git a/games/undertale/src/newhome.c b/games/undertale/src/newhome.cindex e8b34260..16f80a0c 100644--- a/games/undertale/src/newhome.c+++ b/games/undertale/src/newhome.c@@ -224,10 +224,7 @@ static int ev_throne(Ev *c) {a->dir = DIR_DOWN;SAY(FACE_ASGORE, "* ...oh.|* I so wish we could have tea,\n like any other afternoon.|* But... you know how this must\n be.|* When you are ready, come to\n the next room.");a = obj_get(ACTOR_ITEM);- WALK(a, 5968, a->y, 2);- a = obj_get(ACTOR_ITEM);- WALK(a, 5968, 1110, 2);- gone(obj_get(ACTOR_ITEM));+ LEAVE(a, 2, 5968, a->y, 5968, 1110);set_flag(F_NH_THRONE, 1);EV_END;}diff --git a/games/undertale/src/resort.c b/games/undertale/src/resort.cindex d96c13bd..a3c7c5f4 100644--- a/games/undertale/src/resort.c+++ b/games/undertale/src/resort.c@@ -13,7 +13,6 @@#include "snowdin.h"#include "world.h"-static void gone(Obj *o) { o->kind = OBJ_NONE; }static Obj *thing(int x, int y, int w, int h, int event, int name, int arg) {Obj *o = obj_trigger(x, y, w, h, event, name);if (o) o->flags = OF_TALK | OF_SOLID, o->arg = (int16_t)arg;@@ -88,10 +87,7 @@ static int ev_sans(Ev *c) {SAY(FACE_SANS, "* ...heh. lighten up.\n* thanks for dinner.|* wait. i said i'd pay, huh.\n* ...catch you later.");set_flag(F_RES_SANS, 1);s = obj_get(ACTOR_SANS);- WALK(s, s->x, 362, 2); /* up past the tables, out east */- s = obj_get(ACTOR_SANS);- WALK(s, 780, 362, 3);- gone(obj_get(ACTOR_SANS));+ LEAVE(s, 3, s->x, 362, 780, 362); /* up past the tables, out east */EV_END;}diff --git a/games/undertale/src/rooms.c b/games/undertale/src/rooms.cindex c533bd16..c317f6ce 100644--- a/games/undertale/src/rooms.c+++ b/games/undertale/src/rooms.c@@ -45,6 +45,7 @@ void room_update(void) {/* what a room draws on its floor, under everything (world.c) */void room_draw_floor(void) {+ ruins3_draw();snow1_draw();snow2_draw();ht1_draw();diff --git a/games/undertale/src/ruins.h b/games/undertale/src/ruins.hindex ed5d85f3..346412ca 100644--- a/games/undertale/src/ruins.h+++ b/games/undertale/src/ruins.h@@ -9,4 +9,5 @@ int ruins2_event(Ev *c);void ruins2_update(void);void ruins3_setup(int room, int from);int ruins3_event(Ev *c);+void ruins3_draw(void); /* the mirror */#endifdiff --git a/games/undertale/src/ruins1.c b/games/undertale/src/ruins1.cindex 63bc826c..27b70b64 100644--- a/games/undertale/src/ruins1.c+++ b/games/undertale/src/ruins1.c@@ -115,7 +115,7 @@ static const char flowey_hi[] ="`7* Ready?^2 Here we go!";static int ev_flowey_meet(Ev *c) {- Obj *f, *t;+ Obj *f;EV_BEGIN;if (c->self) c->self->kind = OBJ_NONE;SAY(FACE_FLOWEY, flowey_hi);@@ -128,28 +128,16 @@ static int ev_flowey_meet(Ev *c) {set_flag(F_TORIEL_MET, 1);WAIT(10);SAY(FACE_TORIEL, "`0* This way.");- t = obj_find(ACTOR_TORIEL);- if (t) WALK_TO(t, 504, 5580, 2);- WAIT_UNTIL(!(t = obj_find(ACTOR_TORIEL)) || !t->walking);- if ((t = obj_find(ACTOR_TORIEL))) t->kind = OBJ_NONE;+ LEAVE(obj_find(ACTOR_TORIEL), 2, 504, 5580);EV_END;}static int ev_ruins1_toriel(Ev *c) {- Obj *t = obj_find(ACTOR_TORIEL);- EV_BEGIN;if (c->self) c->self->kind = OBJ_NONE;- c->v[0] = 0;/* she goes up the stairs, then through the door */- if (!t) return 1;- WALK(t, 580, 5300, 2);- WALK(t, 606, 5250, 2);- WALK(t, 606, 5160, 2);- WALK(t, 504, 5150, 2);- WALK(t, 504, 5100, 2);- t->kind = OBJ_NONE;+ LEAVE(obj_find(ACTOR_TORIEL), 2, 580, 5300, 606, 5250, 606, 5160, 504, 5150, 504, 5100);set_flag(F_RUINS1_DONE, 1);- EV_END;+ return 1;}static int ev_ruins2_toriel(Ev *c) {@@ -186,9 +174,7 @@ static int ev_ruins2_toriel(Ev *c) {t->dir = DIR_DOWN;SAY(FACE_TORIEL, "`0* The RUINS are full of\n puzzles that open the way.|* Solve each one to reach\n the next room.");set_flag(F_RUINS2_DONE, 1);- WALK(t, 484, 4900, 2);- WALK(t, 484, 4840, 2);- t->kind = OBJ_NONE;+ LEAVE(t, 2, 484, 4900, 484, 4840);EV_END;}@@ -198,9 +184,7 @@ static int ev_ruins3_toriel(Ev *c) {if (c->self) c->self->kind = OBJ_NONE;if (!t) return 1;SAY(FACE_TORIEL, "`0* Here you must flip some\n switches.|* I marked the right ones\n for you.");- WALK(t, 560, 4716, 3);- WALK(t, 990, 4716, 3);- t->dir = DIR_LEFT;+ WALK_ON(t, 3, DIR_LEFT, 560, 4716, 990, 4716);EV_END;}@@ -227,9 +211,7 @@ static int ev_ruins3_switch(Ev *c) {WAIT(10);if (obj_find(ACTOR_TORIEL)) {SAY(FACE_TORIEL, "`2* Splendid!\n* I am proud of you, little\n one.|`0* Let us move to the next\n room.");- WALK(obj_get(ACTOR_TORIEL), 1040, 4730, 3);- WALK(obj_get(ACTOR_TORIEL), 1100, 4730, 3);- obj_get(ACTOR_TORIEL)->kind = OBJ_NONE;+ LEAVE(obj_get(ACTOR_TORIEL), 3, 1040, 4730, 1100, 4730);}}EV_END;@@ -263,11 +245,7 @@ static int ev_ruins4_dummy(Ev *c) {set_flag(F_DUMMY, 1);SAY(FACE_TORIEL, "`2* Ah, very good!\n* You are very good.");}- if (obj_find(ACTOR_TORIEL)) {- WALK(obj_get(ACTOR_TORIEL), 1244, 4640, 2);- WALK(obj_get(ACTOR_TORIEL), 1244, 4560, 2);- obj_get(ACTOR_TORIEL)->kind = OBJ_NONE;- }+ LEAVE(obj_find(ACTOR_TORIEL), 2, 1244, 4640, 1244, 4560);EV_END;}@@ -306,8 +284,7 @@ static int ev_ruins5_toriel(Ev *c) {obj_get(ACTOR_TORIEL)->dir = DIR_LEFT;SAY(FACE_TORIEL, "`0* Puzzles seem too dangerous\n for now.");set_flag(F_RUINS5_DONE, 1);- WALK(obj_get(ACTOR_TORIEL), 2320, 4440, 3);- obj_get(ACTOR_TORIEL)->kind = OBJ_NONE;+ LEAVE(obj_find(ACTOR_TORIEL), 3, 2320, 4440);EV_END;}@@ -348,9 +325,7 @@ static int ev_ruins6_reveal(Ev *c) {t->dir = DIR_LEFT;SAY(FACE_TORIEL, "`0* There you are!|* I was just behind the\n pillar.|`2* Thank you for trusting\n me.|`0* That was a test of your\n independence.|`1* I have errands to run.\n* Please wait here for me.|`2* Take this CELL PHONE.|`0* Call me if you need\n anything. Be good!");set_flag(F_PHONE, 1);- WALK(obj_get(ACTOR_TORIEL), 4700, 4470, 3);- WALK(obj_get(ACTOR_TORIEL), 4860, 4470, 3);- obj_get(ACTOR_TORIEL)->kind = OBJ_NONE;+ LEAVE(obj_find(ACTOR_TORIEL), 3, 4700, 4470, 4860, 4470);set_flag(F_RUINS6_DONE, 1);/* (the game saves here when she leaves) */sv.room = (int16_t)g_room, sv.x = pl.x, sv.y = pl.y;diff --git a/games/undertale/src/ruins2.c b/games/undertale/src/ruins2.cindex 178643b3..8bf3ad9c 100644--- a/games/undertale/src/ruins2.c+++ b/games/undertale/src/ruins2.c@@ -548,8 +548,7 @@ static int ev_toriel_tree(Ev *c) {sv.hp = sv.maxhp;SAY(FACE_TORIEL, "`1* I left you alone too long.\n* I am sorry.|`0* Oh, the surprise is\n spoiled now...|`2* Come along, little one!");set_flag(F_TORIEL_HOME, 1);- WALK(obj_get(ACTOR_TORIEL), 9006, 3070, 3);- obj_get(ACTOR_TORIEL)->kind = OBJ_NONE;+ LEAVE(obj_find(ACTOR_TORIEL), 3, 9006, 3070);EV_END;}diff --git a/games/undertale/src/ruins3.c b/games/undertale/src/ruins3.cindex d909026e..ed01d3b8 100644--- a/games/undertale/src/ruins3.c+++ b/games/undertale/src/ruins3.c@@ -6,6 +6,7 @@#include "event.h"#include "events.h"#include "game.h"+#include "gfx.h"#include "items.h"#include "menu.h"#include "monsters.h"@@ -49,7 +50,10 @@ void ruins3_setup(int room, int from) {obj_sign(9492, 2750, 24, 54, "* (You have seen this type of\n plant before but do not know\n its name.)");obj_sign(9746, 2775, 30, 47, "* (Room under renovations.)");obj_sign(9810, 2770, 60, 52, "* (It's you!)");- if (flag(F_TORIEL_HOME) && !flag(F_HOME_TOUR)) obj_toriel(9370, 2780, DIR_DOWN);+ if (flag(F_TORIEL_HOME) && !flag(F_HOME_TOUR)) {+ obj_toriel(9370, 2780, DIR_DOWN);+ obj_trigger(9280, 2810, 24, 80, EV_HOME_TOUR, ACTOR_TRIGGER);+ }break;case ROOM_ASRIELROOM:{@@ -103,25 +107,41 @@ void ruins3_setup(int room, int from) {}}+/* the hallway's mirror: Frisk in its glass, as far behind the wall as he stands in front of it (his face when he+ * faces it) */+#define MIRROR_X 9819+#define MIRROR_Y 2786+#define MIRROR_W 45+#define MIRROR_H 18+#define MIRROR_WALL 2820 /* (where the wall meets the floor) */+void ruins3_draw(void) {+ if (g_room != ROOM_TORHOUSE3 || pl.hidden) return;+ static const uint16_t facing[4] = {SPR_FRISK_U, SPR_FRISK_D, SPR_FRISK_L, SPR_FRISK_R};+ int feet = pl.y + 29, y = 2 * MIRROR_WALL - feet - 29;+ if (pl.x + 20 <= MIRROR_X || pl.x >= MIRROR_X + MIRROR_W || y >= MIRROR_Y + MIRROR_H) return;+ gfx_clip(MIRROR_X - cam_x, MIRROR_Y - cam_y, MIRROR_W, MIRROR_H);+ gfx_sprite(facing[pl.dir], pl.frame, pl.x - cam_x, y - cam_y, 0, 255);+ gfx_clip_all();+}+/* ---------------------------------------------------------------- the events */static int ev_home_tour(Ev *c) {EV_BEGIN;WAIT_UNTIL(!world_fading());- SAY(FACE_TORIEL, "`0* Smell that?|`2* Surprise! A butterscotch-\n cinnamon pie, for you!|`0* No snail pie tonight.|`2* And one more surprise...");- WALK(obj_get(ACTOR_TORIEL), 8996, 2840, 3);- WALK(obj_get(ACTOR_TORIEL), 9200, 2840, 3);- obj_get(ACTOR_TORIEL)->kind = OBJ_NONE;- PL_WALK(pl.x + 40, pl.y, 3);- FADE_TO(ROOM_TORHOUSE3, 9196, 2836, DIR_RIGHT);- PL_WALK(9330, 2836, 3);- pl.dir = DIR_UP;+ if (g_room != ROOM_TORHOUSE3) {+ /* she goes on into the hallway, and waits by your room */+ SAY(FACE_TORIEL, "`0* Smell that?|`2* Surprise! A butterscotch-\n cinnamon pie, for you!|`0* No snail pie tonight.|`2* And one more surprise...");+ LEAVE(obj_find(ACTOR_TORIEL), 3, 8996, 2840, 9200, 2840);+ return 1;+ }+ if (c->self) c->self->kind = OBJ_NONE;+ obj_get(ACTOR_TORIEL)->dir = DIR_LEFT;SAY(FACE_TORIEL, "`2* A room of your own.|* I hope you like it!");WAIT(20);SAY(FACE_TORIEL, "`7* ...!|`3* Is something burning...?|`0* Um, make yourself at home!");- WALK(obj_get(ACTOR_TORIEL), 9370, 2840, 4);- WALK(obj_get(ACTOR_TORIEL), 9180, 2840, 5);- obj_get(ACTOR_TORIEL)->kind = OBJ_NONE;set_flag(F_HOME_TOUR, 1);+ obj_get(ACTOR_TORIEL)->flags &= (uint16_t)~OF_SOLID;+ LEAVE(obj_find(ACTOR_TORIEL), 5, 9370, 2840, 9180, 2840);EV_END;}@@ -155,9 +175,7 @@ static int ev_toriel_chair(Ev *c) {Obj *t = obj_toriel(8660, 2760, DIR_RIGHT);if (t) t->flags &= (uint16_t)~OF_SOLID;}- WALK(obj_get(ACTOR_TORIEL), 8800, 2780, 4);- WALK(obj_get(ACTOR_TORIEL), 8860, 2780, 4);- obj_get(ACTOR_TORIEL)->kind = OBJ_NONE;+ LEAVE(obj_find(ACTOR_TORIEL), 4, 8800, 2780, 8860, 2780);EV_END;}@@ -186,6 +204,7 @@ static int ev_bed(Ev *c) {static int ev_basement_talk(Ev *c) {EV_BEGIN;if (c->self) c->self->kind = OBJ_NONE;+ WAIT_UNTIL(!obj_get(ACTOR_TORIEL)->walking); /* (Frisk caught up with her) */obj_get(ACTOR_TORIEL)->dir = DIR_LEFT;switch (flag(F_BASEMENT_TALK)) {case 0:@@ -202,27 +221,23 @@ static int ev_basement_talk(Ev *c) {set_flag(F_BASEMENT_TALK, flag(F_BASEMENT_TALK) + 1);if (g_room == ROOM_BASEMENT1 && flag(F_BASEMENT_TALK) == 1) {/* on ahead, to wait further down */- obj_get(ACTOR_TORIEL)->dir = DIR_RIGHT;- WALK(obj_get(ACTOR_TORIEL), 9560, 2300, 4);- obj_get(ACTOR_TORIEL)->dir = DIR_RIGHT;+ WALK_ON(obj_find(ACTOR_TORIEL), 4, DIR_RIGHT, 9560, 2300);obj_trigger(9490, 2300, 16, 80, EV_BASEMENT_TALK, ACTOR_TRIGGER);return 1;}if (g_room == ROOM_BASEMENT1) {- WALK(obj_get(ACTOR_TORIEL), 10120, 2300, 5);+ LEAVE(obj_find(ACTOR_TORIEL), 5, 10120, 2300);} else {- WALK(obj_get(ACTOR_TORIEL), 10004, 1984, 4);- obj_get(ACTOR_TORIEL)->dir = DIR_DOWN;+ WALK_ON(obj_find(ACTOR_TORIEL), 4, DIR_DOWN, 10004, 1984);obj_trigger(9960, 2060, 140, 14, EV_TORIEL_DOOR, ACTOR_TRIGGER2);- return 1;}- obj_get(ACTOR_TORIEL)->kind = OBJ_NONE;EV_END;}static int ev_toriel_door(Ev *c) {EV_BEGIN;if (c->self) c->self->kind = OBJ_NONE;+ WAIT_UNTIL(!obj_get(ACTOR_TORIEL)->walking);SAY(FACE_TORIEL, "`6* So you insist on leaving.|* Like all the others.|* Then show me you are\n strong enough to survive.");BATTLE(FORM_TORIEL);if (flag(F_TORIEL_FIGHT) != 1) {@@ -243,9 +258,7 @@ static int ev_toriel_door(Ev *c) {WAIT(20);SAY(FACE_TORIEL, "`0* Goodbye, my child.");obj_get(ACTOR_TORIEL)->flags &= (uint16_t)~OF_SOLID;- WALK(obj_get(ACTOR_TORIEL), 10040, 2050, 2);- WALK(obj_get(ACTOR_TORIEL), 10040, 2240, 2);- obj_get(ACTOR_TORIEL)->kind = OBJ_NONE;+ LEAVE(obj_find(ACTOR_TORIEL), 2, 10040, 2050, 10040, 2240);EV_END;}diff --git a/games/undertale/src/snowdin1.c b/games/undertale/src/snowdin1.cindex eeced798..d0adc4ab 100644--- a/games/undertale/src/snowdin1.c+++ b/games/undertale/src/snowdin1.c@@ -314,8 +314,7 @@ static int ev_sans_intro(Ev *c) {set_flag(F_SANS_MET, 1);set_flag(F_SANS_FAVOR, 1);/* (the wrong way) */- WALK(s, 2556, 432, 2);- gone(s);+ LEAVE(s, 2, 2556, 432);if (c->self) gone(c->self);EV_END;}@@ -380,8 +379,7 @@ static int ev_pap_sentry(Ev *c) {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);+ LEAVE(s, 2, 4140, 414);set_flag(F_PAP_SENTRY, 1);if (c->self) gone(c->self);EV_END;@@ -472,8 +470,7 @@ static int ev_elecmaze(Ev *c) {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);+ LEAVE(p, 5, 5520, 446);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;@@ -573,8 +570,7 @@ static int ev_wordsearch(Ev *c) {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);+ LEAVE(p, 6, 6640, 652);if (c->self) gone(c->self);EV_END;}diff --git a/games/undertale/src/snowdin2.c b/games/undertale/src/snowdin2.cindex 3cef0f8a..6f6ee074 100644--- a/games/undertale/src/snowdin2.c+++ b/games/undertale/src/snowdin2.c@@ -306,8 +306,7 @@ static int ev_pap_xoxo(Ev *c) {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);+ LEAVE(p, 6, 7740, 1252);if (c->self) gone(c->self);return 1;}@@ -342,8 +341,7 @@ static int ev_tiles(Ev *c) {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);+ LEAVE(p, 8, 8920, 1252);if (c->self) gone(c->self);EV_END;}@@ -398,8 +396,7 @@ static int ev_gauntlet(Ev *c) {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);+ LEAVE(s, 2, 12000, 1200);set_flag(F_GAUNTLET, 1);if (c->self) gone(c->self);EV_END;diff --git a/games/undertale/src/snowtown.c b/games/undertale/src/snowtown.cindex fd81a096..72a32c72 100644--- a/games/undertale/src/snowtown.c+++ b/games/undertale/src/snowtown.c@@ -218,8 +218,7 @@ spared:SAY(FACE_PAPYRUS, "`4* NYOO HOO HOO...|* I COULDN'T EVEN CAPTURE\n YOU.\n* SO MUCH FOR THE 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);+ LEAVE(p, 6, 3240, 1100);if (c->self) gone(c->self);EV_END;}diff --git a/games/undertale/src/wf1.c b/games/undertale/src/wf1.cindex 2f6b0049..1e7bda86 100644--- a/games/undertale/src/wf1.c+++ b/games/undertale/src/wf1.c@@ -460,8 +460,7 @@ static int ev_wf_mk(Ev *c) {pl.dir = DIR_RIGHT;NARRATE("* Yo! Are you going to see Undyne too?|* She's the head of the Royal Guard!\n* She's SO cool!|* Come on, let's go!");set_flag(F_WF_MK, 1);- WALK(mk, 1180, 1496, 4);- gone(mk);+ LEAVE(mk, 4, 1180, 1496);if (c->self) gone(c->self);EV_END;}@@ -513,8 +512,7 @@ static int ev_wf_undyne1(Ev *c) {obj_mk(1840, 1530, DIR_LEFT);NARRATE("* Yo! Did you see that?!\n* She was looking right at you!|* That's so awesome!!");mk = obj_get(ACTOR_MK);- WALK(mk, 2120, 1520, 4);- gone(mk);+ LEAVE(mk, 4, 2120, 1520);}set_flag(F_WF_UNDYNE1, 1);if (c->self) gone(c->self);@@ -556,8 +554,7 @@ static int ev_wf_grass(Ev *c) {if (flag(F_WF_MK)) {NARRATE("* Yo! She almost got you!\n* ...wait, why WAS she after you?|* Never mind! Let's keep going!");mk = obj_get(ACTOR_MK);- WALK(mk, 6900, 580, 4);- gone(mk);+ LEAVE(mk, 4, 6900, 580);}set_flag(F_CHASE1, 1);if (c->self) gone(c->self);diff --git a/games/undertale/src/wf3.c b/games/undertale/src/wf3.cindex e8a4670b..29b90bf4 100644--- a/games/undertale/src/wf3.c+++ b/games/undertale/src/wf3.c@@ -209,8 +209,7 @@ static int ev_mk_chasm(Ev *c) {mk->dir = DIR_LEFT;NARRATE("* Yo... thanks for saving me.|* We're still friends, right? Cool.|* I'd better get home before my parents worry. Later!");mk = obj_get(ACTOR_MK);- WALK(mk, 22920, mk->y, 4);- gone(mk);+ LEAVE(mk, 4, 22920, mk->y);set_flag(F_MK_CHASM, 2);return 1;}@@ -229,9 +228,8 @@ static int ev_mk_chasm(Ev *c) {NARRATE("* (Undyne climbs back up, Monster Kid with her.)\n* (She's badly hurt.)");NARRATE("* Undyne... you were right about them.|* They just stood there and watched me fall.");u = obj_get(ACTOR_UNDYNE), mk = obj_get(ACTOR_MK);- WALK_TO(mk, 22940, mk->y, 2);- WALK(u, 22920, u->y, 2);- gone(obj_get(ACTOR_UNDYNE)), gone(obj_get(ACTOR_MK));+ LEAVE(mk, 2, 22940, mk->y);+ LEAVE(u, 2, 22920, u->y);set_flag(F_MK_CHASM, 3);return 1;}@@ -335,8 +333,7 @@ static int ev_hot_undyne(Ev *c) {WAIT(20);NARRATE("* (Undyne gets up... and stares at you for a long time.)");u = obj_get(ACTOR_UNDYNE);- WALK(u, -20, u->y, 2);- gone(u);+ LEAVE(u, 2, -20, u->y);set_flag(F_UNDYNE, 4);EV_END;}diff --git a/games/undertale/src/world.c b/games/undertale/src/world.cindex f964d542..b1d596aa 100644--- a/games/undertale/src/world.c+++ b/games/undertale/src/world.c@@ -1,4 +1,5 @@/* The overworld: rooms, the camera, Frisk and the room's objects (world.h). */+#include <stdarg.h>#include <string.h>#include "event.h"#include "game.h"@@ -115,7 +116,73 @@ Obj *obj_get(int name) {memset(&spare, 0, sizeof spare);return &spare;}-void obj_clear_all(void) { memset(objs, 0, sizeof objs); }+/* objects walking off on their own through a few points (a cutscene's last steps: the cutscene is over, Frisk+ * walks meanwhile, as in the game), gone at the last one if they leave */+#define MAX_LEAVERS 4+static struct {+ uint8_t obj, name, n, i, sp, solid;+ int8_t end; /* -1 gone, or the way it faces */+ int16_t pts[6][2];+} leavers[MAX_LEAVERS];++void obj_clear_all(void) {+ memset(objs, 0, sizeof objs);+ memset(leavers, 0, sizeof leavers);+}++void obj_walk_off(Obj *o, int sp, int end, int n, ...) {+ if (!o || o < objs || o >= objs + MAX_OBJS || o->kind == OBJ_NONE || n < 1) return;+ obj_walk_cancel(o);+ int k = 0;+ while (k < MAX_LEAVERS && leavers[k].n) k++;+ if (k == MAX_LEAVERS) k = 0;+ va_list ap;+ va_start(ap, n);+ if (n > 6) n = 6;+ for (int i = 0; i < n; i++) {+ leavers[k].pts[i][0] = (int16_t)va_arg(ap, int);+ leavers[k].pts[i][1] = (int16_t)va_arg(ap, int);+ }+ va_end(ap);+ leavers[k].obj = (uint8_t)(o - objs), leavers[k].name = o->name, leavers[k].n = (uint8_t)n, leavers[k].i = 0;+ leavers[k].sp = (uint8_t)sp, leavers[k].end = (int8_t)end;+ /* (it walks through Frisk: solid again once it stays, and Frisk isn't in its way) */+ leavers[k].solid = (o->flags & OF_SOLID) != 0;+ o->flags &= (uint16_t)~OF_SOLID;+ o->tx = leavers[k].pts[0][0], o->ty = leavers[k].pts[0][1], o->speed = (uint8_t)sp, o->walking = 1;+}++void obj_walk_cancel(Obj *o) {+ for (int k = 0; k < MAX_LEAVERS; k++)+ if (leavers[k].n && &objs[leavers[k].obj] == o) {+ if (leavers[k].solid) o->flags |= OF_SOLID;+ leavers[k].n = 0;+ }+}++static void leavers_update(void) {+ for (int k = 0; k < MAX_LEAVERS; k++) {+ if (!leavers[k].n) continue;+ Obj *o = &objs[leavers[k].obj];+ if (o->kind == OBJ_NONE || o->name != leavers[k].name) {+ leavers[k].n = 0;+ continue;+ }+ if (o->walking) continue;+ if (leavers[k].i + 1 < leavers[k].n) {+ leavers[k].i++;+ o->tx = leavers[k].pts[leavers[k].i][0], o->ty = leavers[k].pts[leavers[k].i][1];+ o->speed = leavers[k].sp, o->walking = 1;+ } else if (leavers[k].end < 0) {+ o->kind = OBJ_NONE, leavers[k].n = 0;+ } else {+ o->dir = (uint8_t)leavers[k].end;+ if (leavers[k].solid && boxes_meet(pl.x + PBX, pl.y + PBY, PBW, PBH, o->x + o->bx, o->y + o->by, o->bw, o->bh)) continue;+ if (leavers[k].solid) o->flags |= OF_SOLID;+ leavers[k].n = 0;+ }+ }+}void world_camera(void) {if (cam_locked) return;@@ -341,6 +408,7 @@ static void touches(void) {/* ---------------------------------------------------------------- objects walking */static void objs_update(void) {+ leavers_update();for (int i = 0; i < MAX_OBJS; i++) {Obj *o = &objs[i];if (o->kind == OBJ_NONE) continue;diff --git a/games/undertale/src/world.h b/games/undertale/src/world.hindex 84eb9595..e077a689 100644--- a/games/undertale/src/world.h+++ b/games/undertale/src/world.h@@ -73,6 +73,10 @@ Obj *obj_new(int kind, int x, int y);Obj *obj_find(int name);Obj *obj_get(int name); /* obj_find, or a spare object when there is none (events can't crash on it) */void obj_clear_all(void);+/* the object walks through n points (x, y, ...) at sp pixels a frame, on its own: whoever started it goes on (Frisk+ * walks); at the last point it's gone (end -1) or faces that way (DIR_*) */+void obj_walk_off(Obj *o, int sp, int end, int n, ...);+void obj_walk_cancel(Obj *o); /* (a cutscene walks it itself) *//* the room's things, made by rooms.c */Obj *obj_npc(int name, const uint16_t spr[4], int x, int y, int dir, int event);Obj *obj_toriel(int x, int y, int dir);diff --git a/games/undertale/tests/ruins.path b/games/undertale/tests/ruins.pathindex e23a6e78..25b4dbf4 100644--- a/games/undertale/tests/ruins.path+++ b/games/undertale/tests/ruins.path@@ -207,6 +207,10 @@ talkw60talkw30+# she waits by your room down the hallway+go:9300,2840+talk+w30# the living room: ask her how to leavego:9190,2840go:8840,2860