Now using a simple collision map to track entities and then determine if they're near the player for attacking.
This commit is contained in:
parent
743f906bc7
commit
ec1ed23c52
6 changed files with 72 additions and 48 deletions
|
@ -23,7 +23,7 @@ TEST_CASE("confirm basic collision operations", "[collision]") {
|
|||
}
|
||||
|
||||
{ // found
|
||||
auto [found, nearby] = coltable.neighbors({10,10});
|
||||
auto [found, nearby] = coltable.neighbors({10,10}, true);
|
||||
|
||||
REQUIRE(found);
|
||||
REQUIRE(nearby[0] == player);
|
||||
|
@ -31,7 +31,7 @@ TEST_CASE("confirm basic collision operations", "[collision]") {
|
|||
|
||||
{ // removed
|
||||
coltable.remove({11,11});
|
||||
auto [found, nearby] = coltable.neighbors({10,10});
|
||||
auto [found, nearby] = coltable.neighbors({10,10}, true);
|
||||
REQUIRE(!found);
|
||||
REQUIRE(nearby.empty());
|
||||
}
|
||||
|
@ -40,13 +40,13 @@ TEST_CASE("confirm basic collision operations", "[collision]") {
|
|||
|
||||
{ // moving
|
||||
coltable.move({11,11}, {12, 12}, player);
|
||||
auto [found, nearby] = coltable.neighbors({10,10});
|
||||
auto [found, nearby] = coltable.neighbors({10,10}, true);
|
||||
REQUIRE(!found);
|
||||
REQUIRE(nearby.empty());
|
||||
}
|
||||
|
||||
{ // find it after move
|
||||
auto [found, nearby] = coltable.neighbors({11,11});
|
||||
auto [found, nearby] = coltable.neighbors({11,11}, true);
|
||||
REQUIRE(found);
|
||||
REQUIRE(nearby[0] == player);
|
||||
}
|
||||
|
@ -59,7 +59,6 @@ TEST_CASE("confirm basic collision operations", "[collision]") {
|
|||
}
|
||||
|
||||
|
||||
|
||||
TEST_CASE("confirm multiple entities moving", "[collision]") {
|
||||
DinkyECS::World world;
|
||||
Entity player = world.entity();
|
||||
|
@ -74,22 +73,20 @@ TEST_CASE("confirm multiple entities moving", "[collision]") {
|
|||
coltable.insert({21,21}, e1);
|
||||
|
||||
{ // find e3 and e2
|
||||
auto [found, nearby] = coltable.neighbors({11, 11});
|
||||
auto [found, nearby] = coltable.neighbors({11, 11}, true);
|
||||
REQUIRE(found);
|
||||
REQUIRE(nearby.size() == 3);
|
||||
REQUIRE(nearby.size() == 2);
|
||||
// BUG: replace this with std::find/std::search
|
||||
REQUIRE(nearby[0] == e2);
|
||||
REQUIRE(nearby[1] == e3);
|
||||
REQUIRE(nearby[2] == player);
|
||||
REQUIRE(nearby[0] == e3);
|
||||
REQUIRE(nearby[1] == e2);
|
||||
}
|
||||
|
||||
coltable.move({11,11}, {20,20}, player);
|
||||
{ // should only find the e1
|
||||
auto [found, nearby] = coltable.neighbors({20,20});
|
||||
auto [found, nearby] = coltable.neighbors({20,20}, true);
|
||||
REQUIRE(found);
|
||||
REQUIRE(nearby.size() == 2);
|
||||
REQUIRE(nearby.size() == 1);
|
||||
// BUG: replace this with std::find/std::search
|
||||
REQUIRE(nearby[0] == player);
|
||||
REQUIRE(nearby[1] == e1);
|
||||
REQUIRE(nearby[0] == e1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue