Skip to content

Commit

Permalink
WIP!!!!!!!!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
MatusGuy committed Sep 1, 2024
1 parent 9d7b452 commit 5d9ea51
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
18 changes: 15 additions & 3 deletions src/badguy/granito.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,24 +221,25 @@ Granito::collision(GameObject& other, const CollisionHit& hit)
if (hit.top)
m_col.propagate_movement(m_col.get_movement());


if (hit.bottom)
{
if (m_state == STATE_SIT)
return WalkingBadguy::collision(other, hit);
goto granito_collision_end;

// Yo big granito can i sit on top of your head?
GranitoBig* granito = dynamic_cast<GranitoBig*>(&other);

if (!granito)
{
// I'm not a big granito.
return WalkingBadguy::collision(other, hit);
goto granito_collision_end;
}

if (granito->get_carrying() != nullptr)
{
// Sorry, im already carrying this guy.
return WalkingBadguy::collision(other, hit);
goto granito_collision_end;
}

// Sure dude.
Expand All @@ -249,6 +250,17 @@ Granito::collision(GameObject& other, const CollisionHit& hit)
Sector::get().run_script(m_carried_script, "carried-script");
}

{
auto* movingobject = dynamic_cast<MovingObject*>(&other);
if (movingobject != nullptr && movingobject->get_group() == COLGROUP_MOVING_STATIC &&
m_dir == Direction::LEFT ? hit.left : hit.right) {
turn(invert_dir(m_dir));
return ABORT_MOVE;
}
}

granito_collision_end:

// Call other collision functions (collision_player, collision_badguy, ...)
WalkingBadguy::collision(other, hit);

Expand Down
1 change: 1 addition & 0 deletions src/badguy/granito_big.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ GranitoBig::active_update(float dt_sec)

Vector pos(get_bbox().get_middle().x - m_carrying->get_bbox().get_width() / 2,
get_bbox().get_top() - m_carrying->get_bbox().get_height());
m_carrying->set_velocity_y(0);
m_carrying->set_pos(pos);
m_carrying->turn(m_dir);
}
Expand Down
15 changes: 13 additions & 2 deletions src/collision/collision_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ collision::Constraints check_collisions(const Vector& obj_movement, const Rectf&

if (!shiftout)
{
if (other_object && other_object->is_unisolid())
if (other_object && other_object->is_unisolid() &&
moving_object->get_group() != COLGROUP_MOVING_STATIC)
{
// Constrain only on fall on top of the unisolid object.
// Here we are checking the movements of the objects to prevent
Expand Down Expand Up @@ -398,6 +399,9 @@ CollisionSystem::collision_object(CollisionObject* object1, CollisionObject* obj
std::swap(hit.left, hit.right);
std::swap(hit.top, hit.bottom);
HitResponse response2 = object2->collision(*object1, hit);

//std::cout << response1 << response2 << std::endl;

if (response1 == CONTINUE && response2 == CONTINUE) {
normal *= (0.5f + EPSILON);
object1->m_dest.move(-normal);
Expand Down Expand Up @@ -425,10 +429,17 @@ CollisionSystem::collision_static(collision::Constraints* constraints,
const float static_size = static_object->get_bbox().get_width() * static_object->get_bbox().get_height();
const float object_size = object.get_bbox().get_width() * object.get_bbox().get_height();
// let's skip this if two colgroup_moving_static's connect and our object is somewhat larger than the static object.

//if (object.get_group() == COLGROUP_MOVING_STATIC && static_object->get_group() == COLGROUP_MOVING_STATIC)
// std::cout << object_size << " " << static_size + FORGIVENESS << std::endl;

if ((object.get_group() == COLGROUP_MOVING_STATIC && static_object->get_group() == COLGROUP_MOVING_STATIC) &&
(object_size > static_size + FORGIVENESS)) {
((object_size >= static_size + FORGIVENESS))
)
{
continue;
}

if ((
static_object->get_group() == COLGROUP_STATIC ||
static_object->get_group() == COLGROUP_MOVING_STATIC
Expand Down
2 changes: 2 additions & 0 deletions src/object/rock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,12 @@ Rock::collision(GameObject& other, const CollisionHit& hit)
return ABORT_MOVE;
}

/*
auto crusher = dynamic_cast<Crusher*> (&other);
if (crusher) {
return FORCE_MOVE;
}
*/

if (hit.bottom) {
auto player = dynamic_cast<Player*> (&other);
Expand Down

0 comments on commit 5d9ea51

Please sign in to comment.