Преглед изворни кода

some kind of X collision

opengl-renderer-broken
Martin Dørum пре 4 година
родитељ
комит
2862f823da
1 измењених фајлова са 20 додато и 6 уклоњено
  1. 20
    6
      libswan/src/Body.cc

+ 20
- 6
libswan/src/Body.cc Прегледај датотеку

@@ -11,18 +11,32 @@ void Body::gravity(Vec2 g) {
}

void Body::collide(WorldPlane &plane) {
int startx = (int)pos_.x_;
int endx = (int)(pos_.x_ + size_.x_);
int px = (int)pos_.x_;
if (pos_.x_ < 0) px -= 1;
int startx = px;
int endx = (int)(px + size_.x_);

int y = (int)(pos_.y_ + size_.y_);
on_ground_ = false;
int y = (int)pos_.y_ + size_.y_;
for (int x = startx; x <= endx; ++x) {
Tile &tile = plane.getTile(TilePos(x, y));
if (tile.is_solid_) {
Tile &ground = plane.getTile(TilePos(x, y));
if (ground.is_solid_ && vel_.y_ > 0) {
pos_.y_ = y - size_.y_;
vel_.y_ = 0;
on_ground_ = true;
break;
}

Tile &wall = plane.getTile(TilePos(x, y - 1));
if (x == startx && vel_.x_ < 0) {
if (wall.is_solid_) {
vel_.x_ = 0;
pos_.x_ = startx + 1;
}
} else if (x == endx && vel_.x_ > 0) {
if (wall.is_solid_) {
vel_.x_ = 0;
pos_.x_ = endx - 1;
}
}
}
}

Loading…
Откажи
Сачувај