#include "test_support.h" int main(void) { int x = 108, y = 103; reset_dirty_rows(); assert(can_walk(108, 103)); assert(!can_walk(30, 60)); /* Pond. */ assert(!can_walk(175, 60)); /* House. */ assert(!can_walk(0, 100)); /* Map edge. */ assert(!can_walk(NPC_X, NPC_Y)); assert(!can_walk(NPC_X - 12, NPC_Y)); assert(!can_walk(NPC_X, NPC_Y + 8)); assert(can_walk(NPC_X - 13, NPC_Y)); assert(can_walk(NPC_X + 13, NPC_Y)); assert(can_walk(NPC_X, NPC_Y + 9)); assert(can_walk(NPC_X, NPC_Y - 9)); assert(!near_npc(108, 103)); assert(near_npc(NPC_X - 13, NPC_Y)); assert(near_npc(NPC_X + 13, NPC_Y)); assert(near_npc(NPC_X, NPC_Y + 9)); assert(near_npc(NPC_X, NPC_Y - 9)); assert(near_npc(NPC_X - 24, NPC_Y - 20)); assert(!near_npc(NPC_X - 25, NPC_Y)); assert(!near_npc(NPC_X, NPC_Y + 21)); assert(!near_npc(182, 103)); /* The creature does not trigger Mila. */ assert(DIALOGUE_PAGES == 2); assert(next_dialogue_page(0) == 1); assert(next_dialogue_page(1) == -1); for (int page = 0; page < DIALOGUE_PAGES; ++page) { for (int line = 0; line < 2; ++line) { int length = 0; for (const char *p = dialogue[page][line]; *p; ++p) { assert(*p == ' ' || (*p >= 'A' && *p <= 'Z')); ++length; } assert(length <= 34); /* Larger letters stay inside the box. */ } } check_art(person_art, 20, 11); check_art(person_back_art, 20, 13); check_art(person_side_art, 20, 13); check_art(creature_art, 16, 8); assert(facing_for_keys(UP, FACING_DOWN) == FACING_UP); assert(facing_for_keys(DOWN, FACING_UP) == FACING_DOWN); assert(facing_for_keys(LEFT, FACING_DOWN) == FACING_LEFT); assert(facing_for_keys(RIGHT, FACING_DOWN) == FACING_RIGHT); assert(facing_for_keys(0, FACING_LEFT) == FACING_LEFT); assert(facing_for_keys(A, FACING_RIGHT) == FACING_RIGHT); for (unsigned letter = 0; letter < 26; ++letter) for (unsigned row = 0; row < 7; ++row) assert(large_alphabet[letter][row] < 32); /* A partial redraw must look exactly like drawing the whole map again. */ static u16 expected[WIDTH * HEIGHT]; const int positions[][2] = { {108, 103}, {130, 103}, {146, 95}, {146, 115}, {182, 104}, {222, 131}, {174, 79}, {174, 130} }; test_pixels[0] = test_pixels[WIDTH * HEIGHT + 1] = 0xbeef; for (unsigned i = 0; i < sizeof(positions) / sizeof(positions[0]); ++i) { int x = positions[i][0], y = positions[i][1]; assert(can_walk(x, y)); render_scene(x, y); memcpy(expected, SCREEN, sizeof(expected)); render_scene(108, 103); restore(108 - 8, 103 - 20, 17, 24); actors(x, y, 0); location_status(x, y); assert(memcmp(expected, SCREEN, sizeof(expected)) == 0); dialogue_box(0); restore(DIALOGUE_X, DIALOGUE_Y, DIALOGUE_W, DIALOGUE_H); actors(x, y, 0); assert(memcmp(expected, SCREEN, sizeof(expected)) == 0); } for (int room = OUTSIDE; room <= MELLON_HOUSE; ++room) { current_room = (enum Room)room; reset_position(&x, &y); if (current_room == OUTSIDE) x = 130; if (current_room == ROUTE) y = 94; for (int facing = FACING_DOWN; facing <= FACING_RIGHT; ++facing) { for (int step = 0; step < 2; ++step) { player_facing = FACING_DOWN; render_scene(x, y); player_facing = (enum Facing)facing; restore(x - 8, y - 20, 17, 24); actors(x, y, step); memcpy(expected, SCREEN, sizeof(expected)); render_scene(x, y); restore(x - 8, y - 20, 17, 24); actors(x, y, step); assert(memcmp(expected, SCREEN, sizeof(expected)) == 0); } } } current_room = OUTSIDE; player_facing = FACING_DOWN; render_scene(108, 103); person(60, 116, 0, shirt, RGB(28, 8, 9), FACING_UP); person(85, 116, 1, shirt, RGB(28, 8, 9), FACING_LEFT); person(130, 126, 0, shirt, RGB(28, 8, 9), FACING_RIGHT); write_preview("build/directions-preview.ppm"); assert(test_pixels[0] == 0xbeef); assert(test_pixels[WIDTH * HEIGHT + 1] == 0xbeef); render_scene(108, 103); write_preview("build/preview.ppm"); dialogue_box(0); write_preview("build/dialogue-preview.ppm"); assert(near_door(177, 78)); assert(near_door(169, 89)); assert(!near_door(168, 83)); assert(!near_door(177, 90)); assert(!near_door(177, 63)); /* The house wall stays solid. */ assert(reachable(108, 103, 177, 83)); u16 closed_door = scenery(177, 63); door_open = 1; assert(scenery(177, 63) != closed_door); render_scene(177, 83); write_preview("build/open-door-preview.ppm"); door_open = 0; assert(scenery(177, 63) == closed_door); x = 108; y = 103; assert(!use_door(&x, &y)); assert(current_room == OUTSIDE && x == 108 && y == 103); for (int trip = 0; trip < 5; ++trip) { x = 177; y = 83; door_open = 1; assert(use_door(&x, &y)); assert(current_room == COTTAGE && x == 120 && y == 119); assert(!door_open && can_walk(x, y) && !near_door(x, y)); assert(!near_npc(NPC_X, NPC_Y)); assert(!use_door(&x, &y)); /* No immediate bounce back outside. */ assert(!can_walk(50, 90)); /* Bed. */ assert(!can_walk(170, 90)); /* Table. */ assert(!can_walk(201, 80)); /* Plant. */ assert(!can_walk(25, 120)); /* Wall. */ assert(!can_walk(120, 132)); /* Bottom boundary. */ assert(can_walk(100, 90)); /* Rug. */ assert(reachable(x, y, 120, 125)); assert(reachable(x, y, 80, 75)); reset_position(&x, &y); assert(x == 120 && y == 119 && current_room == COTTAGE); const int inside_positions[][2] = {{120, 125}, {80, 75}, {100, 90}, {205, 119}}; for (unsigned i = 0; i < sizeof(inside_positions) / sizeof(inside_positions[0]); ++i) { int nx = inside_positions[i][0], ny = inside_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); } render_scene(x, y); assert(SCREEN[95 * WIDTH + 181] == cottage_scenery(181, 95)); assert(SCREEN[90 * WIDTH + NPC_X] == cottage_scenery(NPC_X, 90)); write_preview("build/inside-preview.ppm"); y = 125; assert(near_door(x, y)); assert(use_door(&x, &y)); assert(current_room == OUTSIDE && x == 177 && y == 83); assert(can_walk(x, y) && !door_open); reset_position(&x, &y); assert(x == 108 && y == 103 && current_room == OUTSIDE); } assert(test_pixels[0] == 0xbeef); assert(test_pixels[WIDTH * HEIGHT + 1] == 0xbeef); check_buffered_walking(); check_route_travel(); check_mellon_visit(); check_starter_gift(); check_following_and_battle(); check_wild_encounters(); check_ball_gift(); check_background_cache(); check_sprite_rows(); check_movement_clock_and_speed(); assert(test_pixels[0] == 0xbeef); assert(test_pixels[WIDTH * HEIGHT + 1] == 0xbeef); puts("Ball gift/inventory/save migration, wild encounters, battles, following, and map checks passed"); return 0; }