better collision

main
Benjamin Kraft 2 years ago
parent 1dd514e905
commit 44fa51d0ad
  1. 5
      src/Player.cpp
  2. 2
      src/Wall.cpp

@ -27,9 +27,10 @@ void Player::update(float dTime, std::vector<Wall> &walls, std::vector<Coin>& co
} }
for (auto &wall : walls){ for (auto &wall : walls){
int wWidth = wall.size.width();
if (!wall.jumped && !wall.failed){ if (!wall.jumped && !wall.failed){
if (pos.x() > wall.pos.x() - wall.size.width() / 2 if (pos.x() > wall.pos.x() - wWidth / 2
&& pos.x() < wall.pos.x() + wall.size.width() / 2){ && pos.x() < wall.pos.x() + wWidth / 2){
if (pos.y() < wall.pos.y() - wall.size.height()){ if (pos.y() < wall.pos.y() - wall.size.height()){
wall.jumped = true; wall.jumped = true;
auto e = new WallJumpEvent; auto e = new WallJumpEvent;

@ -7,7 +7,7 @@ void Wall::draw(QPainter &painter) const {
int w = size.width(); int w = size.width();
int h = size.height(); int h = size.height();
painter.translate(pos.toPoint()); painter.translate(pos.toPoint());
painter.fillRect(w / 2, -h, w, h, Qt::red); painter.fillRect(-w / 2, -h, w, h, Qt::red);
painter.restore(); painter.restore();
} }

Loading…
Cancel
Save