Fixed bug in calculating sprite offset for collectables
This commit is contained in:
parent
23fb9d4fd5
commit
24963b2d0a
10 changed files with 23 additions and 16 deletions
2
TODO.md
2
TODO.md
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
## Next
|
## Next
|
||||||
|
|
||||||
|
- Physics
|
||||||
- Damage other players on contact
|
- Damage other players on contact
|
||||||
|
|
||||||
## Bugs
|
## Bugs
|
||||||
|
@ -10,7 +11,6 @@
|
||||||
|
|
||||||
## High priority
|
## High priority
|
||||||
|
|
||||||
- Physics
|
|
||||||
- Players-join-screen before the game starts
|
- Players-join-screen before the game starts
|
||||||
|
|
||||||
- Short input delay when a new identity connects, to avoid accidental inputs at beginning
|
- Short input delay when a new identity connects, to avoid accidental inputs at beginning
|
||||||
|
|
|
@ -46,6 +46,11 @@ void TranslatedCoordinates::move(WorldCoordinates deltaWorldCoordinates)
|
||||||
this->worldCoordinates = this->worldCoordinates + deltaWorldCoordinates;
|
this->worldCoordinates = this->worldCoordinates + deltaWorldCoordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TranslatedCoordinates::move(IsometricCoordinates deltaIsometricCoordinates)
|
||||||
|
{
|
||||||
|
move(CoordinateTransformer::isometricToWorld(deltaIsometricCoordinates));
|
||||||
|
}
|
||||||
|
|
||||||
TranslatedCoordinates::TranslatedCoordinates(WorldCoordinates worldCoordinates)
|
TranslatedCoordinates::TranslatedCoordinates(WorldCoordinates worldCoordinates)
|
||||||
: worldCoordinates(worldCoordinates)
|
: worldCoordinates(worldCoordinates)
|
||||||
{
|
{
|
||||||
|
@ -53,7 +58,7 @@ TranslatedCoordinates::TranslatedCoordinates(WorldCoordinates worldCoordinates)
|
||||||
|
|
||||||
void TranslatedCoordinates::move(sf::Vector2f deltaWorldCoordinates)
|
void TranslatedCoordinates::move(sf::Vector2f deltaWorldCoordinates)
|
||||||
{
|
{
|
||||||
move({deltaWorldCoordinates.x, deltaWorldCoordinates.y, 0});
|
move(WorldCoordinates {deltaWorldCoordinates.x, deltaWorldCoordinates.y, 0});
|
||||||
}
|
}
|
||||||
|
|
||||||
void TranslatedCoordinates::setParent(std::shared_ptr<TranslatedCoordinates> parent, WorldCoordinates offset)
|
void TranslatedCoordinates::setParent(std::shared_ptr<TranslatedCoordinates> parent, WorldCoordinates offset)
|
||||||
|
|
|
@ -40,10 +40,13 @@ public:
|
||||||
|
|
||||||
void setScreenOffset(IsometricCoordinates offset);
|
void setScreenOffset(IsometricCoordinates offset);
|
||||||
|
|
||||||
|
void move(IsometricCoordinates deltaIsometricCoordinates);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WorldCoordinates worldCoordinates{};
|
WorldCoordinates worldCoordinates{};
|
||||||
|
|
||||||
std::shared_ptr<TranslatedCoordinates> parent = nullptr;
|
std::shared_ptr<TranslatedCoordinates> parent = nullptr;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,5 +27,5 @@ void Collectable::setSprite(const std::string &spriteName)
|
||||||
addChildScreenOffset(sprite, IsometricCoordinates(-size / 2.f));
|
addChildScreenOffset(sprite, IsometricCoordinates(-size / 2.f));
|
||||||
|
|
||||||
// Set half size offset of coordinates
|
// Set half size offset of coordinates
|
||||||
coordinates->move(WorldCoordinates(0, 0, sizeWidth / 2.f));
|
coordinates->move(IsometricCoordinates(0, -sizeWidth / 2.f, 0));
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,8 +57,15 @@ void CollectablesCollection::update()
|
||||||
for (auto &collectable: collectables)
|
for (auto &collectable: collectables)
|
||||||
{
|
{
|
||||||
int newDepth = std::floor(collectable->getDepth());
|
int newDepth = std::floor(collectable->getDepth());
|
||||||
if (newDepth != depth && newDepth < depthCollections.size())
|
if (newDepth != depth)
|
||||||
{
|
{
|
||||||
|
if (newDepth < 0 || newDepth >= (int) depthCollections.size())
|
||||||
|
{
|
||||||
|
LOG(ERROR) << "Collectable " << collectable->getId() << " has invalid depth " << newDepth
|
||||||
|
<< "! Keeping it at previous depth " << depth << " ...";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
depthCollection->remove(collectable);
|
depthCollection->remove(collectable);
|
||||||
depthCollections[newDepth]->add(collectable);
|
depthCollections[newDepth]->add(collectable);
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,14 +61,6 @@ void LevelLoader::loadLevel(const LevelConfig &levelConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i <= 25; i++)
|
|
||||||
{
|
|
||||||
auto debugImage = SpriteFactory::createSingleSprite("edge");
|
|
||||||
debugImage->coordinates->setWorld({0, 0, (float) i});
|
|
||||||
levelRenderer->addDetachedChild(debugImage);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
LOG(INFO) << "Finished loading level '" << levelConfig.name << "'.";
|
LOG(INFO) << "Finished loading level '" << levelConfig.name << "'.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ void CollectableSimulation::physicsUpdate()
|
||||||
{
|
{
|
||||||
updateGroundHole();
|
updateGroundHole();
|
||||||
|
|
||||||
world->Step(FRAME_TIME.asSeconds(), COLLECTABLES_SIM_VELOCITY_ITERATIONS, COLLECTABLES_SIM_POSITION_ITERATIONS);
|
// world->Step(FRAME_TIME.asSeconds(), COLLECTABLES_SIM_VELOCITY_ITERATIONS, COLLECTABLES_SIM_POSITION_ITERATIONS);
|
||||||
|
|
||||||
updateCollectable();
|
updateCollectable();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ public:
|
||||||
|
|
||||||
void physicsUpdate() override;
|
void physicsUpdate() override;
|
||||||
|
|
||||||
std::shared_ptr<Collectable> getCollectable() const;
|
[[nodiscard]] std::shared_ptr<Collectable> getCollectable() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<b2World> world;
|
std::shared_ptr<b2World> world;
|
||||||
|
|
|
@ -29,7 +29,7 @@ void HolesSimulation::addCollectable(const std::shared_ptr<Collectable> &collect
|
||||||
{
|
{
|
||||||
// Create new collectable simulation
|
// Create new collectable simulation
|
||||||
auto collectableSim = std::make_shared<CollectableSimulation>(collectable);
|
auto collectableSim = std::make_shared<CollectableSimulation>(collectable);
|
||||||
addChild(collectableSim);
|
addDetachedChild(collectableSim);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HolesSimulation::lateUpdate()
|
void HolesSimulation::lateUpdate()
|
||||||
|
|
|
@ -12,7 +12,7 @@ std::map<std::string, LevelConfig> const all_levels = {
|
||||||
{18, 18},
|
{18, 18},
|
||||||
{0, 18},
|
{0, 18},
|
||||||
{18, 0}}, {
|
{18, 0}}, {
|
||||||
CollectableInLevel("box", {5, 5})
|
CollectableInLevel("box", {0, 0})
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Blues
|
// Blues
|
||||||
|
|
Loading…
Reference in a new issue