Skip to content

Commit

Permalink
add friction to movement for some enemies
Browse files Browse the repository at this point in the history
  • Loading branch information
evanbowman committed Sep 16, 2020
1 parent b8b535f commit 443cccb
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
37 changes: 33 additions & 4 deletions source/entity/enemies/dasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,16 @@ void Dasher::update(Platform& pf, Game& game, Microseconds dt)
state_ = State::dash_end;
sprite_.set_texture_index(TextureMap::dasher_crouch);
};
if (timer_ > milliseconds(200)) {
timer_ -= milliseconds(200);
if (timer_ > milliseconds(170)) {
speed_ =
interpolate(Vec2<Float>{0, 0},
speed_,
dt * 0.000016f);
// sprite_.set_mix({current_zone(game).energy_glow_color_, 255});
}
if (timer_ > milliseconds(350)) {
// sprite_.set_mix({current_zone(game).energy_glow_color_, 0});
timer_ -= milliseconds(350);
next_state();
}
const auto wc = check_wall_collisions(game.tiles(), *this);
Expand Down Expand Up @@ -248,8 +256,29 @@ void Dasher::update(Platform& pf, Game& game, Microseconds dt)
} break;

case State::dash_end:
if (timer_ > milliseconds(150)) {
timer_ -= milliseconds(150);
speed_ =
interpolate(Vec2<Float>{0, 0},
speed_,
dt * 0.000016f);


{
const auto wc = check_wall_collisions(game.tiles(), *this);
if (wc.any()) {
if ((wc.left and speed_.x < 0.f) or (wc.right and speed_.x > 0.f)) {
speed_.x = 0.f;
}
if ((wc.up and speed_.y < 0.f) or (wc.down and speed_.y > 0.f)) {
speed_.y = 0.f;
}
}

static const float movement_rate = 0.00005f;
position_.x += speed_.x * dt * movement_rate;
position_.y += speed_.y * dt * movement_rate;
}
if (timer_ > milliseconds(130)) {
timer_ -= milliseconds(130);
state_ = State::idle;
sprite_.set_texture_index(TextureMap::dasher_idle);

Expand Down
26 changes: 25 additions & 1 deletion source/entity/enemies/drone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ void Drone::update(Platform& pfrm, Game& game, Microseconds dt)
position_ = position_ + Float(dt) * step_vector_;
sprite_.set_position(position_);
shadow_.set_position(position_);
if (timer_ > milliseconds(900)) {
step_vector_ =
interpolate(Vec2<Float>{0, 0},
step_vector_,
dt * 0.000008f);
}
if (timer_ > seconds(1)) {
timer_ = 0;
state_ = State::idle2;
Expand All @@ -135,6 +141,12 @@ void Drone::update(Platform& pfrm, Game& game, Microseconds dt)
position_ = position_ + Float(dt) * step_vector_;
sprite_.set_position(position_);
shadow_.set_position(position_);
if (timer_ > milliseconds(900)) {
step_vector_ =
interpolate(Vec2<Float>{0, 0},
step_vector_,
dt * 0.000008f);
}
if (timer_ > seconds(1)) {
timer_ = 0;
state_ = State::idle3;
Expand All @@ -159,6 +171,12 @@ void Drone::update(Platform& pfrm, Game& game, Microseconds dt)
position_ = position_ + Float(dt) * step_vector_;
sprite_.set_position(position_);
shadow_.set_position(position_);
if (timer_ > milliseconds(900)) {
step_vector_ =
interpolate(Vec2<Float>{0, 0},
step_vector_,
dt * 0.000008f);
}
if (timer_ > seconds(1)) {
timer_ = 0;
state_ = State::idle4;
Expand All @@ -180,7 +198,13 @@ void Drone::update(Platform& pfrm, Game& game, Microseconds dt)
position_ = position_ + Float(dt) * step_vector_;
sprite_.set_position(position_);
shadow_.set_position(position_);
if (timer_ > seconds(1)) {
if (timer_ > milliseconds(900)) {
step_vector_ =
interpolate(Vec2<Float>{0, 0},
step_vector_,
dt * 0.0000060f);
}
if (timer_ > seconds(1) + milliseconds(350)) {
timer_ = 0;
state_ = State::idle1;

Expand Down

0 comments on commit 443cccb

Please sign in to comment.