Skip to content

Commit

Permalink
it works??
Browse files Browse the repository at this point in the history
  • Loading branch information
MatusGuy committed Jul 17, 2024
1 parent e0a6ede commit 9d74250
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 24 deletions.
43 changes: 23 additions & 20 deletions src/badguy/badguy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ BadGuy::BadGuy(const Vector& pos, Direction direction, const std::string& sprite
m_glowing(false),
m_water_affected(true),
m_unfreeze_timer(),
m_floor_normal(0.0f, 0.0f),
m_state(STATE_INIT),
m_is_active_flag(),
m_state_timer(),
m_on_ground_flag(false),
m_floor_normal(0.0f, 0.0f),
m_colgroup_active(COLGROUP_MOVING)
{
SoundManager::current()->preload("sounds/squish.wav");
Expand Down Expand Up @@ -113,11 +113,11 @@ BadGuy::BadGuy(const ReaderMapping& reader, const std::string& sprite_name,
m_glowing(false),
m_water_affected(true),
m_unfreeze_timer(),
m_floor_normal(0.0f, 0.0f),
m_state(STATE_INIT),
m_is_active_flag(),
m_state_timer(),
m_on_ground_flag(false),
m_floor_normal(0.0f, 0.0f),
m_colgroup_active(COLGROUP_MOVING)
{
std::string dir_str;
Expand All @@ -143,11 +143,11 @@ BadGuy::draw(DrawingContext& context)
Vector eye(0, get_bbox().get_bottom() + 1.f);
eye.x = (m_dir == Direction::LEFT ? get_bbox().get_left() : get_bbox().get_right());

Vector end(eye.x, eye.y + 16.f);
Vector end(eye.x, eye.y + 256.f);
context.color().draw_line(eye, end, Color::GREEN, LAYER_GUI);

Vector seye(get_bbox().get_left() + get_bbox().get_width() / 2.f, eye.y);
Vector send(seye.x + 5.f * (m_dir == Direction::LEFT ? 1.f : -1.f), seye.y + 64.f);
Vector send(seye.x + 6.5f * (m_dir == Direction::LEFT ? 1.f : -1.f), seye.y + 80.f);
context.color().draw_line(seye, send, Color::GREEN, LAYER_GUI);

if (!m_sprite.get()) return;
Expand Down Expand Up @@ -853,31 +853,34 @@ BadGuy::might_fall(int height) const
Vector eye(0, get_bbox().get_bottom() + 1.f);
eye.x = (m_dir == Direction::LEFT ? get_bbox().get_left() : get_bbox().get_right());

Vector end(eye.x, eye.y + 64.f);
// TODO: change to max possible drop height
Vector end(eye.x, eye.y + 256.f);
std::cout << eye << " " << end << std::endl;

RaycastResult result = Sector::get().get_first_line_intersection(eye, end, false, nullptr);
bool slope = false;
//bool slope = false;

auto tile_p = std::get_if<const Tile*>(&result.hit);
if (tile_p && (*tile_p) && (*tile_p)->is_slope())
if (result.is_valid && result.box.p1().y - eye.y < static_cast<float>(height)) {
return false;
}
else if (tile_p && (*tile_p) && (*tile_p)->is_slope())
{
AATriangle tri((*tile_p)->get_data());
std::cout << "SLOPE" << std::endl;
if (tri.is_south() && (m_dir == Direction::LEFT ? tri.is_east() : !tri.is_east()))
slope = true;
}

if (slope)
{
Vector seye(get_bbox().get_left() + get_bbox().get_width() / 2.f, eye.y);
Vector send(seye.x + 5.f * (m_dir == Direction::LEFT ? 1.f : -1.f), seye.y + 64.f);
RaycastResult sresult = Sector::get().get_first_line_intersection(seye, send, false, nullptr);
{
//slope = true;
Vector seye(get_bbox().get_left() + get_bbox().get_width() / 2.f, eye.y);
Vector send(seye.x + 6.5f * (m_dir == Direction::LEFT ? 1.f : -1.f), seye.y + 80.f);
RaycastResult sresult = Sector::get().get_first_line_intersection(seye, send, false, nullptr);

return !sresult.is_valid;
}
else
{
return !result.is_valid && result.box.p1().y - get_pos().y < static_cast<float>(height);
std::cout << sresult.is_valid << std::endl;
return !sresult.is_valid;
}
}

return true;
}

Player*
Expand Down
7 changes: 4 additions & 3 deletions src/badguy/badguy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ class BadGuy : public MovingSprite,

Timer m_unfreeze_timer;

/** floor normal stored the last time when update_on_ground_flag was
called and we touched something solid from above */
Vector m_floor_normal;

private:
State m_state;

Expand All @@ -306,9 +310,6 @@ class BadGuy : public MovingSprite,
update_on_ground_flag was called last frame */
bool m_on_ground_flag;

/** floor normal stored the last time when update_on_ground_flag was
called and we touched something solid from above */
Vector m_floor_normal;

/** CollisionGroup the badguy should be in while active */
CollisionGroup m_colgroup_active;
Expand Down
5 changes: 5 additions & 0 deletions src/badguy/walking_badguy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ WalkingBadguy::active_update(float dt_sec, float dest_x_velocity, float modifier
{
BadGuy::active_update(dt_sec);

// Walk down slopes smoothly.
if (on_ground() && m_floor_normal.y != 0 && (m_floor_normal.x * m_physic.get_velocity_x()) >= 0) {
m_physic.set_velocity_y((std::abs(m_physic.get_velocity_x()) * std::abs(m_floor_normal.x)) + 100.f);
}

float current_x_velocity = m_physic.get_velocity_x ();

if (m_frozen)
Expand Down
9 changes: 8 additions & 1 deletion src/supertux/sector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#include "object/tilemap.hpp"
#include "object/vertical_stripes.hpp"
#include "physfs/ifile_stream.hpp"
#include "scripting/sector.hpp"
#include "squirrel/squirrel_environment.hpp"
#include "supertux/colorscheme.hpp"
#include "supertux/constants.hpp"
Expand Down Expand Up @@ -559,6 +558,14 @@ Sector::is_free_of_statics(const Rectf& rect, const MovingObject* ignore_object,
tiletype);
}

bool
Sector::is_free_of_statics(float left, float top, float right, float bottom,
bool ignore_unisolid) const
{
return m_collision_system->is_free_of_statics(Rectf(Vector(left, top), Vector(right, bottom)),
nullptr, ignore_unisolid);
}

bool
Sector::is_free_of_movingstatics(const Rectf& rect, const MovingObject* ignore_object) const
{
Expand Down

0 comments on commit 9d74250

Please sign in to comment.