Now also combat works no matter what's on the ground. Closes #81.
This commit is contained in:
parent
f84b63f0e6
commit
05d54ff661
5 changed files with 19 additions and 23 deletions
2
Makefile
2
Makefile
|
@ -37,7 +37,7 @@ tracy_build:
|
||||||
meson compile -j 10 -C builddir
|
meson compile -j 10 -C builddir
|
||||||
|
|
||||||
test: asset_build build
|
test: asset_build build
|
||||||
./builddir/runtests
|
./builddir/runtests "[spatialmap-neighbors]"
|
||||||
|
|
||||||
run: build test
|
run: build test
|
||||||
ifeq '$(OS)' 'Windows_NT'
|
ifeq '$(OS)' 'Windows_NT'
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace gui {
|
||||||
$gui.position(COMBAT_UI_X, COMBAT_UI_Y, COMBAT_UI_WIDTH, COMBAT_UI_HEIGHT);
|
$gui.position(COMBAT_UI_X, COMBAT_UI_Y, COMBAT_UI_WIDTH, COMBAT_UI_HEIGHT);
|
||||||
$gui.layout(
|
$gui.layout(
|
||||||
"[button_0 | button_1 | button_2 | button_3"
|
"[button_0 | button_1 | button_2 | button_3"
|
||||||
"|button_4 | button_5 | button_6 | healing_button | hp_gauge ]"
|
"|button_4 | button_5 | button_6 | =healing_button | =hp_gauge ]"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,12 +53,7 @@ Entity SpatialMap::get(Point at) const {
|
||||||
return begin->second.entity;
|
return begin->second.entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
void SpatialMap::find_neighbor(EntityList &result, Point at, int dy, int dx) const {
|
||||||
* Avoid doing work by using the dy,dx and confirming that
|
|
||||||
* at.x or at.y is > 0. If either is 0 then there can't be
|
|
||||||
* a neighbor since that's out of bounds.
|
|
||||||
*/
|
|
||||||
inline void find_neighbor(const PointEntityMap &table, EntityList &result, Point at, int dy, int dx) {
|
|
||||||
// don't bother checking for cells out of bounds
|
// don't bother checking for cells out of bounds
|
||||||
if((dx < 0 && at.x <= 0) || (dy < 0 && at.y <= 0)) {
|
if((dx < 0 && at.x <= 0) || (dy < 0 && at.y <= 0)) {
|
||||||
return;
|
return;
|
||||||
|
@ -66,11 +61,11 @@ inline void find_neighbor(const PointEntityMap &table, EntityList &result, Point
|
||||||
|
|
||||||
Point cell = {at.x + dx, at.y + dy};
|
Point cell = {at.x + dx, at.y + dy};
|
||||||
|
|
||||||
// Bug #81, should actually for-loop through these and only add ones with collision
|
auto entity = find(cell, [&](auto data) {
|
||||||
auto it = table.find(cell);
|
return data.collision;
|
||||||
if (it != table.end()) {
|
});
|
||||||
result.insert(result.end(), it->second.entity);
|
|
||||||
}
|
if(entity != DinkyECS::NONE) result.push_back(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
FoundEntities SpatialMap::neighbors(Point cell, bool diag) const {
|
FoundEntities SpatialMap::neighbors(Point cell, bool diag) const {
|
||||||
|
@ -78,16 +73,16 @@ FoundEntities SpatialMap::neighbors(Point cell, bool diag) const {
|
||||||
|
|
||||||
// just unroll the loop since we only check four directions
|
// just unroll the loop since we only check four directions
|
||||||
// this also solves the problem that it was detecting that the cell was automatically included as a "neighbor" but it's not
|
// this also solves the problem that it was detecting that the cell was automatically included as a "neighbor" but it's not
|
||||||
find_neighbor($collision, result, cell, 0, 1); // north
|
find_neighbor(result, cell, 0, 1); // north
|
||||||
find_neighbor($collision, result, cell, 0, -1); // south
|
find_neighbor(result, cell, 0, -1); // south
|
||||||
find_neighbor($collision, result, cell, 1, 0); // east
|
find_neighbor(result, cell, 1, 0); // east
|
||||||
find_neighbor($collision, result, cell, -1, 0); // west
|
find_neighbor(result, cell, -1, 0); // west
|
||||||
|
|
||||||
if(diag) {
|
if(diag) {
|
||||||
find_neighbor($collision, result, cell, 1, -1); // south east
|
find_neighbor(result, cell, 1, -1); // south east
|
||||||
find_neighbor($collision, result, cell, -1, -1); // south west
|
find_neighbor(result, cell, -1, -1); // south west
|
||||||
find_neighbor($collision, result, cell, 1, 1); // north east
|
find_neighbor(result, cell, 1, 1); // north east
|
||||||
find_neighbor($collision, result, cell, -1, 1); // north west
|
find_neighbor(result, cell, -1, 1); // north west
|
||||||
}
|
}
|
||||||
|
|
||||||
return {!result.empty(), result};
|
return {!result.empty(), result};
|
||||||
|
|
|
@ -39,6 +39,7 @@ class SpatialMap {
|
||||||
bool something_there(Point at) const;
|
bool something_there(Point at) const;
|
||||||
DinkyECS::Entity get(Point at) const;
|
DinkyECS::Entity get(Point at) const;
|
||||||
DinkyECS::Entity find(Point at, std::function<bool(CollisionData)> cb) const;
|
DinkyECS::Entity find(Point at, std::function<bool(CollisionData)> cb) const;
|
||||||
|
void find_neighbor(EntityList &result, Point at, int dy, int dx) const;
|
||||||
|
|
||||||
FoundEntities neighbors(Point position, bool diag=false) const;
|
FoundEntities neighbors(Point position, bool diag=false) const;
|
||||||
|
|
||||||
|
|
|
@ -186,7 +186,7 @@ TEST_CASE("SpatialMap::find", "[spatialmap-find]") {
|
||||||
REQUIRE(no_collide != should_collide);
|
REQUIRE(no_collide != should_collide);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("SpatialMap::neighbors", "[spatialmap]") {
|
TEST_CASE("SpatialMap::neighbors", "[spatialmap-neighbors]") {
|
||||||
DinkyECS::World world;
|
DinkyECS::World world;
|
||||||
SpatialMap map;
|
SpatialMap map;
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ TEST_CASE("SpatialMap::neighbors", "[spatialmap]") {
|
||||||
|
|
||||||
auto result = map.neighbors(at, true);
|
auto result = map.neighbors(at, true);
|
||||||
REQUIRE(result.found);
|
REQUIRE(result.found);
|
||||||
REQUIRE(result.nearby.size() > 0);
|
REQUIRE(result.nearby.size() == 2);
|
||||||
|
|
||||||
bool maybe = result.nearby[0] == enemy1 || result.nearby[1] == enemy1;
|
bool maybe = result.nearby[0] == enemy1 || result.nearby[1] == enemy1;
|
||||||
REQUIRE(maybe);
|
REQUIRE(maybe);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue