Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw bomb like icecube #1742

Merged
merged 9 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions src/badguy/bomb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,28 +131,35 @@ Bomb::grab(MovingObject& object, const Vector& pos, Direction dir_)
void
Bomb::ungrab(MovingObject& object, Direction dir_)
{
m_dir = dir_;
// This object is now thrown.
int toss_velocity_x = 0;
int toss_velocity_y = 0;
auto player = dynamic_cast<Player*> (&object);

// toss upwards
if (dir_ == Direction::UP)
toss_velocity_y += -500;

// toss to the side when moving sideways
if (player && player->get_physic().get_velocity_x()*(dir_ == Direction::LEFT ? -1 : 1) > 1) {
toss_velocity_x += (dir_ == Direction::LEFT) ? -200 : 200;
toss_velocity_y = (toss_velocity_y < -200) ? toss_velocity_y : -200;
// toss farther when running
if (player && player->get_physic().get_velocity_x()*(dir_ == Direction::LEFT ? -1 : 1) > 200)
toss_velocity_x += static_cast<int>(player->get_physic().get_velocity_x() - (190.0f * (dir_ == Direction::LEFT ? -1.0f : 1.0f)));
//handle swimming
if (player && (player->is_swimming() || player->is_water_jumping()))
{
float swimangle = player->get_swimming_angle();
m_physic.set_velocity(Vector(std::cos(swimangle) * 40.f, std::sin(swimangle) * 40.f) +
player->get_physic().get_velocity());
}
//handle non-swimming
else
{
if (player)
{
//handle x-movement
if (fabsf(player->get_physic().get_velocity_x()) < 1.0f)
m_physic.set_velocity_x(0.f);
else if ((player->m_dir == Direction::LEFT && player->get_physic().get_velocity_x() <= -1.0f)
|| (player->m_dir == Direction::RIGHT && player->get_physic().get_velocity_x() >= 1.0f))
m_physic.set_velocity_x(player->get_physic().get_velocity_x()
+ (player->m_dir == Direction::LEFT ? -10.f : 10.f));
else
m_physic.set_velocity_x(player->get_physic().get_velocity_x()
+ (player->m_dir == Direction::LEFT ? -330.f : 330.f));
//handle y-movement
m_physic.set_velocity_y(dir_ == Direction::UP ? -500.f :
dir_ == Direction::DOWN ? 500.f :
player->get_physic().get_velocity_x() != 0.f ? -200.f : 0.f);
}
}

m_physic.set_velocity(static_cast<float>(toss_velocity_x),
static_cast<float>(toss_velocity_y));

set_colgroup_active(COLGROUP_MOVING);
Portable::ungrab(object, dir_);
}
Expand Down
45 changes: 27 additions & 18 deletions src/badguy/goldbomb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,26 +204,35 @@ GoldBomb::grab(MovingObject& object, const Vector& pos, Direction dir_)
void
GoldBomb::ungrab(MovingObject& object, Direction dir_)
{
int toss_velocity_x = 0;
int toss_velocity_y = 0;
auto player = dynamic_cast<Player*> (&object);

// toss upwards
if (dir_ == Direction::UP)
toss_velocity_y += -500;

// toss to the side when moving sideways
if (player && player->get_physic().get_velocity_x()*(dir_ == Direction::LEFT ? -1 : 1) > 1) {
toss_velocity_x += (dir_ == Direction::LEFT) ? -200 : 200;
toss_velocity_y = (toss_velocity_y < -200) ? toss_velocity_y : -200;
// toss farther when running
if (player && player->get_physic().get_velocity_x()*(dir_ == Direction::LEFT ? -1 : 1) > 200)
toss_velocity_x += static_cast<int>(player->get_physic().get_velocity_x() - (190*(dir_ == Direction::LEFT ? -1 : 1)));
//handle swimming
if (player && (player->is_swimming() || player->is_water_jumping()))
{
float swimangle = player->get_swimming_angle();
m_physic.set_velocity(Vector(std::cos(swimangle) * 40.f, std::sin(swimangle) * 40.f) +
player->get_physic().get_velocity());
}
//handle non-swimming
else
{
if (player)
{
//handle x-movement
if (fabsf(player->get_physic().get_velocity_x()) < 1.0f)
m_physic.set_velocity_x(0.f);
else if ((player->m_dir == Direction::LEFT && player->get_physic().get_velocity_x() <= -1.0f)
|| (player->m_dir == Direction::RIGHT && player->get_physic().get_velocity_x() >= 1.0f))
m_physic.set_velocity_x(player->get_physic().get_velocity_x()
+ (player->m_dir == Direction::LEFT ? -10.f : 10.f));
else
m_physic.set_velocity_x(player->get_physic().get_velocity_x()
+ (player->m_dir == Direction::LEFT ? -330.f : 330.f));
//handle y-movement
m_physic.set_velocity_y(dir_ == Direction::UP ? -500.f :
dir_ == Direction::DOWN ? 500.f :
player->get_physic().get_velocity_x() != 0.f ? -200.f : 0.f);
}
}

//set_pos(object.get_pos() + Vector((dir_ == LEFT ? -33 : 33), get_bbox().get_height()*0.66666 - 32));
m_physic.set_velocity(static_cast<float>(toss_velocity_x),
static_cast<float>(toss_velocity_y));
set_colgroup_active(COLGROUP_MOVING);
Portable::ungrab(object, dir_);
}
Expand Down
46 changes: 37 additions & 9 deletions src/badguy/skydive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,10 @@ SkyDive::SkyDive(const ReaderMapping& reader) :
void
SkyDive::collision_solid(const CollisionHit& hit)
{
if (hit.bottom) {
explode ();
return;
}

if (hit.left || hit.right)
m_physic.set_velocity_x (0.0);
m_physic.set_velocity_x(0.0);
explode();
return;
}

HitResponse
Expand Down Expand Up @@ -70,9 +67,40 @@ void
SkyDive::ungrab(MovingObject& object, Direction dir_)
{
m_sprite->set_action("falling", 1);

m_physic.set_velocity_y(0);
m_physic.set_acceleration_y(0);
auto player = dynamic_cast<Player*> (&object);
//handle swimming
if (player)
{
if (player->is_swimming() || player->is_water_jumping())
{
float swimangle = player->get_swimming_angle();
m_physic.set_velocity(Vector(std::cos(swimangle) * 40.f, std::sin(swimangle) * 40.f) +
player->get_physic().get_velocity());
}
//handle non-swimming
else
{
//handle x-movement
if (fabsf(player->get_physic().get_velocity_x()) < 1.0f)
m_physic.set_velocity_x(0.f);
else if ((player->m_dir == Direction::LEFT && player->get_physic().get_velocity_x() <= -1.0f)
|| (player->m_dir == Direction::RIGHT && player->get_physic().get_velocity_x() >= 1.0f))
m_physic.set_velocity_x(player->get_physic().get_velocity_x()
+ (player->m_dir == Direction::LEFT ? -10.f : 10.f));
else
m_physic.set_velocity_x(player->get_physic().get_velocity_x()
+ (player->m_dir == Direction::LEFT ? -330.f : 330.f));
//handle y-movement
m_physic.set_velocity_y(dir_ == Direction::UP ? -500.f :
dir_ == Direction::DOWN ? 500.f :
player->get_physic().get_velocity_x() != 0.f ? -200.f : 0.f);
}
}
else
{
m_physic.set_velocity_y(0);
m_physic.set_acceleration_y(0);
}
m_physic.enable_gravity(true);
set_colgroup_active(COLGROUP_MOVING);
Portable::ungrab(object, dir_);
Expand Down