222 lines
8.9 KiB
C
222 lines
8.9 KiB
C
#include "test_support.h"
|
|
|
|
void check_buffered_walking(void)
|
|
{
|
|
static u16 visible[WIDTH * HEIGHT], before[WIDTH * HEIGHT];
|
|
static const unsigned directions[] = {RIGHT, DOWN, LEFT, UP};
|
|
reset_dirty_rows();
|
|
mark_dirty(-2, -2, 4, 4);
|
|
assert(pending_pixels() == 4);
|
|
reset_dirty_rows();
|
|
mark_dirty(239, 159, 4, 4);
|
|
assert(pending_pixels() == 1);
|
|
reset_dirty_rows();
|
|
mark_dirty(-8, 0, 2, 2);
|
|
mark_dirty(240, 160, 4, 4);
|
|
assert(pending_pixels() == 0);
|
|
|
|
for (int room = OUTSIDE; room <= MELLON_HOUSE; ++room) {
|
|
current_room = (enum Room)room;
|
|
player_facing = FACING_DOWN;
|
|
int x, y;
|
|
reset_position(&x, &y);
|
|
if (current_room == ROUTE) y = 94;
|
|
render_scene(x, y);
|
|
assert(pending_pixels() == WIDTH * HEIGHT);
|
|
copy_pending_rows(visible);
|
|
for (int frame = 0; frame < 80; ++frame) {
|
|
memcpy(before, visible, sizeof(before));
|
|
unsigned keys = directions[(frame / 10) % 4];
|
|
int old_x = x, old_y = y;
|
|
player_facing = facing_for_keys(keys, player_facing);
|
|
int nx = x + !!(keys & RIGHT) - !!(keys & LEFT);
|
|
int ny = y + !!(keys & DOWN) - !!(keys & UP);
|
|
if (can_walk(nx, y)) x = nx;
|
|
if (can_walk(x, ny)) y = ny;
|
|
restore(old_x - 8, old_y - 20, 17, 24);
|
|
actors(x, y, (frame >> 3) & 1);
|
|
if (near_door(old_x, old_y) != near_door(x, y) ||
|
|
near_map_exit(old_x, old_y) != near_map_exit(x, y) ||
|
|
near_route_sign(old_x, old_y) != near_route_sign(x, y)) location_status(x, y);
|
|
assert(pending_pixels() < 16500);
|
|
/* Neither erasing nor drawing the head may touch the display. */
|
|
assert(memcmp(before, visible, sizeof(before)) == 0);
|
|
copy_pending_rows(visible);
|
|
assert(pending_pixels() == 0);
|
|
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
|
|
}
|
|
status("TALKING TO MILA");
|
|
dialogue_box(0);
|
|
assert(pending_pixels() < 16500);
|
|
copy_pending_rows(visible);
|
|
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
|
|
restore(DIALOGUE_X, DIALOGUE_Y, DIALOGUE_W, DIALOGUE_H);
|
|
actors(x, y, 0);
|
|
location_status(x, y);
|
|
assert(pending_pixels() < 16500);
|
|
copy_pending_rows(visible);
|
|
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
|
|
}
|
|
current_room = OUTSIDE;
|
|
player_facing = FACING_DOWN;
|
|
}
|
|
|
|
void check_route_travel(void)
|
|
{
|
|
static u16 visible[WIDTH * HEIGHT];
|
|
current_room = OUTSIDE;
|
|
assert(reachable(108, 103, 108, 131));
|
|
int x = 80, y = 131;
|
|
assert(!use_map_exit(&x, &y, DOWN)); /* No exit through the fence. */
|
|
x = 108;
|
|
assert(!use_map_exit(&x, &y, UP)); /* Must walk out, not back in. */
|
|
y = 130;
|
|
assert(!use_map_exit(&x, &y, DOWN)); /* Not across the edge yet. */
|
|
y = 131;
|
|
assert(!use_map_exit(&x, &y, A)); /* No button press needed. */
|
|
|
|
for (int trip = 0; trip < 5; ++trip) {
|
|
x = 108;
|
|
y = 131;
|
|
assert(use_map_exit(&x, &y, DOWN));
|
|
assert(current_room == ROUTE && x == 108 && y == 60);
|
|
assert(player_facing == FACING_DOWN && can_walk(x, y));
|
|
assert(!use_map_exit(&x, &y, DOWN)); /* Held direction cannot bounce. */
|
|
assert(!near_door(177, 83));
|
|
assert(!near_npc(NPC_X, NPC_Y));
|
|
assert(!use_door(&x, &y));
|
|
assert(!can_walk(175, 60)); /* Pond. */
|
|
assert(!can_walk(135, 65)); /* Sign. */
|
|
assert(!can_walk(49, 114)); /* Boulder. */
|
|
assert(!can_walk(20, 94)); /* Forest boundary. */
|
|
assert(!can_walk(108, 132)); /* No unfinished south exit. */
|
|
assert(can_walk(48, 70)); /* Grass patches are walkable. */
|
|
assert(can_walk(183, 121));
|
|
assert(near_route_sign(135, 80));
|
|
assert(!near_route_sign(108, 54));
|
|
assert(reachable(x, y, 135, 80));
|
|
assert(reachable(x, y, 183, 121));
|
|
assert(reachable(x, y, 108, 47));
|
|
render_scene(x, y);
|
|
assert(pending_pixels() == WIDTH * HEIGHT);
|
|
copy_pending_rows(visible);
|
|
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
|
|
assert(SCREEN[NPC_Y * WIDTH + NPC_X] == route_scenery(NPC_X, NPC_Y));
|
|
assert(SCREEN[95 * WIDTH + 181] == route_scenery(181, 95));
|
|
write_preview("build/route-preview.ppm");
|
|
|
|
x = 180;
|
|
y = 100;
|
|
reset_position(&x, &y);
|
|
assert(current_room == ROUTE && x == 108 && y == 60);
|
|
assert(player_facing == FACING_DOWN);
|
|
for (; y > 47; --y) assert(can_walk(x, y));
|
|
assert(!use_map_exit(&x, &y, DOWN));
|
|
assert(use_map_exit(&x, &y, UP));
|
|
assert(current_room == OUTSIDE && x == 108 && y == 125);
|
|
assert(player_facing == FACING_UP && can_walk(x, y));
|
|
assert(!use_map_exit(&x, &y, UP));
|
|
assert(reachable(x, y, 108, 103));
|
|
assert(reachable(x, y, 177, 83)); /* House still reachable on return. */
|
|
render_scene(x, y);
|
|
copy_pending_rows(visible);
|
|
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
|
|
}
|
|
current_room = COTTAGE;
|
|
x = 108;
|
|
y = 131;
|
|
assert(!use_map_exit(&x, &y, DOWN)); /* Cottage keeps its own exit. */
|
|
current_room = OUTSIDE;
|
|
player_facing = FACING_DOWN;
|
|
}
|
|
|
|
void check_mellon_visit(void)
|
|
{
|
|
static u16 expected[WIDTH * HEIGHT];
|
|
current_room = OUTSIDE;
|
|
assert(reachable(108, 103, 222, 113));
|
|
int x = 222, y = 100;
|
|
assert(!use_map_exit(&x, &y, RIGHT)); /* No passage through the fence. */
|
|
y = 113;
|
|
assert(!use_map_exit(&x, &y, LEFT));
|
|
for (int visit = 0; visit < 5; ++visit) {
|
|
x = 222;
|
|
y = 113;
|
|
assert(use_map_exit(&x, &y, RIGHT));
|
|
assert(current_room == MELLON_GARDEN && x == 31 && y == 113);
|
|
assert(player_facing == FACING_RIGHT && can_walk(x, y));
|
|
assert(!use_map_exit(&x, &y, RIGHT));
|
|
assert(!near_npc(NPC_X, NPC_Y));
|
|
assert(reachable(x, y, 177, 83));
|
|
assert(reachable(x, y, 17, 113));
|
|
assert(!can_walk(40, 65)); /* Melon beds. */
|
|
reset_position(&x, &y);
|
|
assert(x == 31 && y == 113);
|
|
render_scene(x, y);
|
|
write_preview("build/mellon-garden-preview.ppm");
|
|
assert(village_scenery(160, 41) != mellon_garden_scenery(160, 41));
|
|
|
|
x = 177;
|
|
y = 83;
|
|
assert(near_door(x, y));
|
|
assert(use_door(&x, &y));
|
|
assert(current_room == MELLON_HOUSE && x == 120 && y == 119);
|
|
assert(can_walk(x, y) && !near_door(x, y));
|
|
assert(!can_walk(PROF_X, PROF_Y));
|
|
assert(near_npc(PROF_X, PROF_Y + 22));
|
|
assert(!near_npc(PROF_X, PROF_Y + 23));
|
|
assert(reachable(x, y, PROF_X, PROF_Y + 22));
|
|
assert(reachable(x, y, 120, 125));
|
|
assert(!near_map_exit(222, 113));
|
|
reset_position(&x, &y);
|
|
assert(x == 120 && y == 119 && current_room == MELLON_HOUSE);
|
|
render_scene(x, y);
|
|
write_preview("build/mellon-house-preview.ppm");
|
|
|
|
/* Repainting near either side of the professor must not leave trails. */
|
|
const int positions[][2] = {{100, 92}, {126, 92}, {113, 101}, {113, 83}};
|
|
for (unsigned i = 0; i < sizeof(positions) / sizeof(positions[0]); ++i) {
|
|
int nx = positions[i][0], ny = positions[i][1];
|
|
assert(can_walk(nx, ny));
|
|
render_scene(nx, ny);
|
|
memcpy(expected, SCREEN, sizeof(expected));
|
|
render_scene(x, y);
|
|
restore(x - 8, y - 20, 17, 24);
|
|
actors(nx, ny, 0);
|
|
location_status(nx, ny);
|
|
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
|
dialogue_box(0);
|
|
restore(DIALOGUE_X, DIALOGUE_Y, DIALOGUE_W, DIALOGUE_H);
|
|
actors(nx, ny, 0);
|
|
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
|
}
|
|
render_scene(PROF_X, PROF_Y + 22);
|
|
dialogue_box(0);
|
|
write_preview("build/mellon-dialogue-preview.ppm");
|
|
for (int page = 0; page < DIALOGUE_PAGES; ++page)
|
|
for (int line = 0; line < 2; ++line) {
|
|
const char *message = professor_dialogue[page][line];
|
|
assert(strlen(message) <= 34);
|
|
for (; *message; ++message)
|
|
assert(*message == ' ' || (*message >= 'A' && *message <= 'Z'));
|
|
}
|
|
|
|
x = 120;
|
|
y = 125;
|
|
assert(use_door(&x, &y));
|
|
assert(current_room == MELLON_GARDEN && x == 177 && y == 83);
|
|
assert(can_walk(x, y) && reachable(x, y, 17, 113));
|
|
x = 17;
|
|
y = 113;
|
|
assert(!use_map_exit(&x, &y, RIGHT));
|
|
assert(use_map_exit(&x, &y, LEFT));
|
|
assert(current_room == OUTSIDE && x == 210 && y == 113);
|
|
assert(player_facing == FACING_LEFT && can_walk(x, y));
|
|
assert(!use_map_exit(&x, &y, LEFT));
|
|
assert(reachable(x, y, 108, 131)); /* South route still accessible. */
|
|
assert(reachable(x, y, 177, 83)); /* Original cottage still accessible. */
|
|
}
|
|
current_room = OUTSIDE;
|
|
player_facing = FACING_DOWN;
|
|
}
|