Skip to content

Commit

Permalink
Merge pull request #318 from lethal-guitar/fix-watchbot
Browse files Browse the repository at this point in the history
Fix: Prevent watch bot from getting stuck
  • Loading branch information
lethal-guitar committed Jan 12, 2019
2 parents c315978 + 76d4ab6 commit 7091496
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 13 deletions.
12 changes: 12 additions & 0 deletions src/game_logic/ai/bomber_plane.cpp
Expand Up @@ -148,6 +148,18 @@ void BomberPlane::update(
}


void BomberPlane::onKilled(
GlobalDependencies&,
GlobalState&,
const base::Point<float>&,
entityx::Entity
) {
if (mBombSprite) {
mBombSprite.destroy();
}
}


void BigBomb::update(
GlobalDependencies& d,
GlobalState& s,
Expand Down
6 changes: 6 additions & 0 deletions src/game_logic/ai/bomber_plane.hpp
Expand Up @@ -46,6 +46,12 @@ struct BomberPlane {
bool isOnScreen,
entityx::Entity entity);

void onKilled(
GlobalDependencies& dependencies,
GlobalState& state,
const base::Point<float>& inflictorVelocity,
entityx::Entity entity);

State mState;
entityx::Entity mBombSprite;
};
Expand Down
41 changes: 28 additions & 13 deletions src/game_logic/ai/watch_bot.cpp
Expand Up @@ -18,6 +18,7 @@

#include "base/match.hpp"
#include "data/sound_ids.hpp"
#include "engine/collision_checker.hpp"
#include "engine/entity_tools.hpp"
#include "engine/movement.hpp"
#include "engine/random_number_generator.hpp"
Expand Down Expand Up @@ -66,6 +67,7 @@ void WatchBot::update(
using namespace watch_bot;

const auto& position = *entity.component<WorldPosition>();
const auto& bbox = *entity.component<BoundingBox>();
const auto& playerPos = s.mpPlayer->orientedPosition();

auto& animationFrame = entity.component<Sprite>()->mFramesToRender[0];
Expand Down Expand Up @@ -109,6 +111,10 @@ void WatchBot::update(
*d.mpCollisionChecker,
entity,
orientation::toMovement(state.mOrientation));

if (d.mpCollisionChecker->isOnSolidGround(position, bbox)) {
land(entity, d);
}
},

[&, this](OnGround& state) {
Expand Down Expand Up @@ -164,27 +170,36 @@ void WatchBot::onCollision(
const engine::events::CollidedWithWorld&,
entityx::Entity entity
) {
using namespace engine::components;
using namespace watch_bot;

const auto isOnScreen = entity.component<Active>()->mIsOnScreen;

base::match(mState,
[&, this](const Falling& state) {
if (isOnScreen) {
d.mpServiceProvider->playSound(data::SoundId::DukeJumping);
}

engine::startAnimationSequence(entity, LAND_ON_GROUND_ANIM);
entity.component<MovingBody>()->mGravityAffected = false;
mState = OnGround{};
advanceRandomNumberGenerator(d);

engine::synchronizeBoundingBoxToSprite(entity);
land(entity, d);
},

[](const auto&) {}
);
}


void WatchBot::land(
entityx::Entity entity,
GlobalDependencies& d
) {
using namespace engine::components;
using namespace watch_bot;

const auto isOnScreen = entity.component<Active>()->mIsOnScreen;
if (isOnScreen) {
d.mpServiceProvider->playSound(data::SoundId::DukeJumping);
}

engine::startAnimationSequence(entity, LAND_ON_GROUND_ANIM);
entity.component<MovingBody>()->mGravityAffected = false;
mState = OnGround{};
advanceRandomNumberGenerator(d);

engine::synchronizeBoundingBoxToSprite(entity);
}

}}}
2 changes: 2 additions & 0 deletions src/game_logic/ai/watch_bot.hpp
Expand Up @@ -79,6 +79,8 @@ struct WatchBot {
const engine::events::CollidedWithWorld& event,
entityx::Entity entity);

void land(entityx::Entity entity, GlobalDependencies& dependencies);

watch_bot::State mState;
};

Expand Down

0 comments on commit 7091496

Please sign in to comment.