Removed collision checks for non-moving sprites.
This commit is contained in:
parent
525e33fbc2
commit
83b523ca70
4 changed files with 17 additions and 5 deletions
|
@ -27,7 +27,7 @@ Game::Game(sf::RenderWindow& window) :
|
|||
mWindow.setKeyRepeatEnabled(true);
|
||||
|
||||
Generator generator;
|
||||
generator.generateTiles(mTileManager, sf::IntRect(-10, -10, 20, 20));
|
||||
generator.generateTiles(mTileManager, sf::IntRect(-20, -20, 40, 40));
|
||||
mPlayer = std::shared_ptr<Player>(new Player(mWorld, mTileManager,
|
||||
sf::Vector2f(0.0f, 0.0f), Yaml("player.yaml")));
|
||||
mWorld.insertCharacter(mPlayer);
|
||||
|
|
|
@ -262,11 +262,14 @@ World::heuristic_cost_estimate(Area* start, Area* end) const {
|
|||
void
|
||||
World::step(int elapsed) {
|
||||
for (auto v = mDrawables.begin(); v != mDrawables.end(); v++) {
|
||||
for (auto it = v->second.begin(); it != v->second.end(); ) {
|
||||
for (auto it = v->second.begin(); it != v->second.end(); it++) {
|
||||
auto spriteA = *it;
|
||||
if (spriteA->getDelete())
|
||||
if (spriteA->getDelete()) {
|
||||
remove(spriteA);
|
||||
else {
|
||||
it--;
|
||||
}
|
||||
// Apply movement for movable sprites.
|
||||
else if ((*it)->isMovable()) {
|
||||
sf::Vector2f speed = spriteA->getSpeed();
|
||||
speed *= elapsed / 1000.0f;
|
||||
bool overlap = false;
|
||||
|
@ -286,7 +289,6 @@ World::step(int elapsed) {
|
|||
}
|
||||
if (!overlap)
|
||||
spriteA->setPosition(spriteA->getPosition() + speed);
|
||||
it++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -153,6 +153,15 @@ Sprite::collisionEnabled(Category category) const {
|
|||
return (category & mMask) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this sprite is able to move, currently decided by shape
|
||||
* (circle can move, rectangle can not).
|
||||
*/
|
||||
bool
|
||||
Sprite::isMovable() const {
|
||||
return mShape.type == Shape::Type::CIRCLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a collision with another Sprite occured. Override this method
|
||||
* to manage collision events.
|
||||
|
|
|
@ -67,6 +67,7 @@ public:
|
|||
sf::Vector2f getSize() const;
|
||||
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
|
||||
bool collisionEnabled(Category category) const;
|
||||
bool isMovable() const;
|
||||
|
||||
virtual void onCollide(std::shared_ptr<Sprite> other);
|
||||
|
||||
|
|
Reference in a new issue