feat: mob stop in front of castle
This commit is contained in:
@@ -194,6 +194,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
void moveMobs(std::uint64_t delta);
|
void moveMobs(std::uint64_t delta);
|
||||||
void moveMob(MobPtr mob, std::uint64_t delta);
|
void moveMob(MobPtr mob, std::uint64_t delta);
|
||||||
|
void moveBackMob(MobPtr mob, const TeamCastle& castle);
|
||||||
|
bool isMobTouchingCastle(MobPtr mob, const TeamCastle& castle) const;
|
||||||
void tickMobs(std::uint64_t delta);
|
void tickMobs(std::uint64_t delta);
|
||||||
void cleanDeadMobs();
|
void cleanDeadMobs();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ void World::tick(std::uint64_t delta) {
|
|||||||
|
|
||||||
void World::spawnMobAt(MobID id, MobType type, std::uint8_t level, PlayerID sender, float x, float y, Direction dir) {
|
void World::spawnMobAt(MobID id, MobType type, std::uint8_t level, PlayerID sender, float x, float y, Direction dir) {
|
||||||
MobPtr mob = MobFactory::createMob(id, type, level, sender);
|
MobPtr mob = MobFactory::createMob(id, type, level, sender);
|
||||||
mob->setCenter({x, y});
|
mob->setCenter({ x, y });
|
||||||
mob->setDirection(dir);
|
mob->setDirection(dir);
|
||||||
m_Mobs.push_back(mob);
|
m_Mobs.push_back(mob);
|
||||||
}
|
}
|
||||||
@@ -138,6 +138,20 @@ void World::moveMobs(std::uint64_t delta) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
moveMob(mob, delta);
|
moveMob(mob, delta);
|
||||||
|
|
||||||
|
TeamColor mobTeam = m_Game->getPlayerById(mob->getSender()).getTeamColor();
|
||||||
|
|
||||||
|
const TeamCastle* enemyCastle;
|
||||||
|
|
||||||
|
if (mobTeam == TeamColor::Red) {
|
||||||
|
enemyCastle = &getBlueTeam().getCastle();
|
||||||
|
} else if (mobTeam == TeamColor::Blue) {
|
||||||
|
enemyCastle = &getRedTeam().getCastle();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isMobTouchingCastle(mob, *enemyCastle)) {
|
||||||
|
moveBackMob(mob, *enemyCastle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,6 +183,31 @@ void World::moveMob(MobPtr mob, std::uint64_t delta) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool World::isMobTouchingCastle(MobPtr mob, const TeamCastle& enemyCastle) const {
|
||||||
|
return enemyCastle.collidesWith(*mob);
|
||||||
|
}
|
||||||
|
|
||||||
|
void World::moveBackMob(MobPtr mob, const TeamCastle& enemyCastle) {
|
||||||
|
switch (mob->getDirection()) {
|
||||||
|
case Direction::NegativeX: {
|
||||||
|
mob->setCenterX(enemyCastle.getBottomRight().getX() + mob->getWidth() / 2.0f);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Direction::PositiveX: {
|
||||||
|
mob->setCenterX(enemyCastle.getTopLeft().getX() - mob->getWidth() / 2.0f);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Direction::NegativeY: {
|
||||||
|
mob->setCenterY(enemyCastle.getBottomRight().getY() + mob->getHeight() / 2.0f);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Direction::PositiveY: {
|
||||||
|
mob->setCenterY(enemyCastle.getTopLeft().getY() - mob->getHeight() / 2.0f);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const Color* World::getTileColor(TilePtr tile) const {
|
const Color* World::getTileColor(TilePtr tile) const {
|
||||||
switch (tile->getType()) {
|
switch (tile->getType()) {
|
||||||
case TileType::Tower: {
|
case TileType::Tower: {
|
||||||
|
|||||||
Reference in New Issue
Block a user