diff --git a/source/Game.cpp b/source/Game.cpp index 6473e57..2201403 100644 --- a/source/Game.cpp +++ b/source/Game.cpp @@ -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(new Player(mWorld, mTileManager, sf::Vector2f(0.0f, 0.0f), Yaml("player.yaml"))); mWorld.insertCharacter(mPlayer); diff --git a/source/World.cpp b/source/World.cpp index 0da96ab..50c35da 100755 --- a/source/World.cpp +++ b/source/World.cpp @@ -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++; } } } diff --git a/source/abstract/Sprite.cpp b/source/abstract/Sprite.cpp index 4f0d819..b29003f 100755 --- a/source/abstract/Sprite.cpp +++ b/source/abstract/Sprite.cpp @@ -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. diff --git a/source/abstract/Sprite.h b/source/abstract/Sprite.h index cb7f087..5f98b64 100755 --- a/source/abstract/Sprite.h +++ b/source/abstract/Sprite.h @@ -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 other);