Fix up the spatialmap to have an occupied_by method which checks if a square is occupied and returns what is there.
This commit is contained in:
parent
759f93cae0
commit
a11e7de14e
7 changed files with 24 additions and 43 deletions
|
@ -38,9 +38,5 @@ TEST_CASE("lighting a map works", "[lighting]") {
|
|||
lr.clear_light_target(light2);
|
||||
|
||||
Matrix &lighting = lr.lighting();
|
||||
|
||||
matrix::dump("WALLS=====", map.walls(), light1.x, light1.y);
|
||||
matrix::dump("PATHS=====", lr.paths(), light1.x, light1.y);
|
||||
matrix::dump("LIGHTING 1", lighting, light1.x, light1.y);
|
||||
matrix::dump("LIGHTING 2", lighting, light2.x, light2.y);
|
||||
(void)lighting;
|
||||
}
|
||||
|
|
|
@ -27,11 +27,12 @@ TEST_CASE("SpatialMap::insert", "[spatialmap]") {
|
|||
REQUIRE(!map.occupied(at));
|
||||
|
||||
map.insert(at, player, true);
|
||||
REQUIRE(map.occupied(at));
|
||||
REQUIRE(map.occupied_by(at) == player);
|
||||
|
||||
REQUIRE_THROWS(map.insert(at, enemy, true));
|
||||
|
||||
map.insert(enemy_at, enemy, true);
|
||||
REQUIRE(map.occupied_by(enemy_at) == player);
|
||||
REQUIRE(map.occupied(enemy_at));
|
||||
}
|
||||
|
||||
|
@ -47,6 +48,7 @@ TEST_CASE("SpatialMap::remove", "[spatialmap]") {
|
|||
map.insert(at, player, true);
|
||||
map.insert(at, item, false);
|
||||
REQUIRE(map.occupied(at));
|
||||
REQUIRE(map.occupied_by(at) == player);
|
||||
|
||||
auto data = map.remove(at, player);
|
||||
REQUIRE(!map.occupied(at));
|
||||
|
@ -74,6 +76,7 @@ TEST_CASE("SpatialMap::move", "[spatialmap]") {
|
|||
map.insert(enemy_at, enemy, true);
|
||||
map.insert(enemy_at, potion, false);
|
||||
REQUIRE(map.occupied(enemy_at));
|
||||
REQUIRE(map.occupied_by(enemy_at) == enemy);
|
||||
|
||||
Point target{at.x + 1, at.y};
|
||||
|
||||
|
@ -89,6 +92,7 @@ TEST_CASE("SpatialMap::move", "[spatialmap]") {
|
|||
map.move(at, target, player);
|
||||
|
||||
REQUIRE(map.occupied(target));
|
||||
REQUIRE(map.occupied_by(target) == player);
|
||||
auto data = map.remove(target, player);
|
||||
REQUIRE(data.entity == player);
|
||||
REQUIRE(data.collision == true);
|
||||
|
@ -116,12 +120,14 @@ TEST_CASE("SpatialMap::occupied/something_there", "[spatialmap]") {
|
|||
map.insert(at, player, true);
|
||||
REQUIRE(map.something_there(at));
|
||||
REQUIRE(map.occupied(at));
|
||||
REQUIRE(map.occupied_by(at) == player);
|
||||
|
||||
// then remove the item and still have collision
|
||||
|
||||
map.remove(at, item);
|
||||
REQUIRE(map.something_there(at));
|
||||
REQUIRE(map.occupied(at));
|
||||
REQUIRE(map.occupied_by(at) == player);
|
||||
|
||||
// remove player and back to no collision
|
||||
map.remove(at, player);
|
||||
|
@ -133,6 +139,7 @@ TEST_CASE("SpatialMap::occupied/something_there", "[spatialmap]") {
|
|||
map.insert(target, player, true);
|
||||
REQUIRE(map.something_there(target));
|
||||
REQUIRE(map.occupied(target));
|
||||
REQUIRE(map.occupied_by(target) == player);
|
||||
}
|
||||
|
||||
|
||||
|
@ -147,6 +154,7 @@ TEST_CASE("SpatialMap::get", "[spatialmap]") {
|
|||
// finally with collision and an item there
|
||||
map.insert(at, player, true);
|
||||
REQUIRE(map.occupied(at));
|
||||
REQUIRE(map.occupied_by(at) == player);
|
||||
|
||||
auto entity = map.get(at);
|
||||
REQUIRE(player == entity);
|
||||
|
|
|
@ -4,19 +4,6 @@
|
|||
#include <cmath>
|
||||
#include <numbers>
|
||||
|
||||
/*
|
||||
face_x := rand.Float64() * 100
|
||||
face_y := rand.Float64() * 100
|
||||
target_x := rand.Float64() * 100
|
||||
target_y := rand.Float64() * 100
|
||||
rad_angle1 := atan2(target_y, target_x)
|
||||
rad_angle2 := atan2(face_y, face_x)
|
||||
diff := rad_angle1 - rad_angle2
|
||||
|
||||
if diff < 0 { fmt.Printf("\nTurn Right") }
|
||||
else { fmt.Printf("\nTurn Left") }
|
||||
*/
|
||||
|
||||
|
||||
TEST_CASE("figure out best rotation direction", "[systems-rotate]") {
|
||||
Matrix map = matrix::make(3, 3);
|
||||
|
@ -34,26 +21,14 @@ TEST_CASE("figure out best rotation direction", "[systems-rotate]") {
|
|||
float aiming_dx = float(player_at.x) - float(aiming_at.x);
|
||||
float aiming_dy = float(player_at.y) - float(aiming_at.y);
|
||||
|
||||
fmt::println("target_d={},{}; aiming_d={},{}",
|
||||
target_dx, target_dy, aiming_dx, aiming_dy);
|
||||
|
||||
float target_angle = atan2(-target_dy, target_dx) * (180.0 / std::numbers::pi);
|
||||
float aiming_angle = atan2(-aiming_dy, aiming_dx) * (180.0 / std::numbers::pi);
|
||||
|
||||
float diff = target_angle - aiming_angle;
|
||||
double normalized = fmod(diff + 360.0, 360.0);
|
||||
|
||||
fmt::println("\n\n>>>>>>>>> BEGIN");
|
||||
|
||||
if(normalized != diff) fmt::println("YOU NEED NORMALIZED");
|
||||
|
||||
fmt::println("aming_angle={}, target_angle={}, delta={}, norm={}",
|
||||
aiming_angle, target_angle, diff, normalized);
|
||||
|
||||
fmt::println("TURN {}", normalized < 180.0 ? "LEFT" : "RIGHT");
|
||||
|
||||
matrix::dump("< is target, a is aim", map, target.x, target.y);
|
||||
fmt::println("-----------------END");
|
||||
REQUIRE(normalized >= 0);
|
||||
REQUIRE(normalized <= 360);
|
||||
|
||||
map[aiming_at.y][aiming_at.x] = 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue