54 lines
1.2 KiB
C++
54 lines
1.2 KiB
C++
#include <catch2/catch_test_macros.hpp>
|
|
#include <fmt/core.h>
|
|
#include <nlohmann/json.hpp>
|
|
#include <fstream>
|
|
#include "game/map.hpp"
|
|
#include "game/level.hpp"
|
|
#include "game/systems.hpp"
|
|
#include <cmath>
|
|
#include "graphics/textures.hpp"
|
|
#include "algos/rand.hpp"
|
|
|
|
using namespace fmt;
|
|
using namespace nlohmann;
|
|
using std::string;
|
|
|
|
json load_test_data(const string &fname) {
|
|
std::ifstream infile(fname);
|
|
return json::parse(infile);
|
|
}
|
|
|
|
TEST_CASE("camera control", "[map]") {
|
|
GameDB::init();
|
|
|
|
auto& level = GameDB::current_level();
|
|
auto& map = *level.map;
|
|
|
|
Point center = map.center_camera({10,10}, 5, 5);
|
|
|
|
// map.dump(center.x, center.y);
|
|
REQUIRE(center.x == 8);
|
|
REQUIRE(center.y == 8);
|
|
|
|
Point translation = map.map_to_camera({10,10}, center);
|
|
|
|
REQUIRE(translation.x == 2);
|
|
REQUIRE(translation.y == 2);
|
|
}
|
|
|
|
TEST_CASE("map placement test", "[map-fail]") {
|
|
GameDB::init();
|
|
|
|
for(int i = 0; i < 10; i++) {
|
|
auto& level = GameDB::create_level();
|
|
|
|
for(size_t rnum = 0; rnum < level.map->room_count(); rnum++) {
|
|
Point pos;
|
|
|
|
REQUIRE(level.map->place_entity(rnum, pos));
|
|
|
|
REQUIRE(!level.map->iswall(pos.x, pos.y));
|
|
REQUIRE(level.map->inmap(pos.x, pos.y));
|
|
}
|
|
}
|
|
}
|