public void HandleCollisions() { int xOrigin = (int)(Position.X) / Tile.Width; int yOrigin = (int)(Position.Y) / Tile.Height; int xStart = xOrigin - 15; int yStart = yOrigin - 15; int xEnd = xOrigin + 15; int yEnd = yOrigin + 15; enemyToChar = new LiangBarsky(Position, new Vector2(level.Player.Position.X, level.Player.Position.Y - 32.0f)); wallInWay = false; for (int y = yStart; y < yEnd; ++y) { for (int x = xStart; x < xEnd; ++x) { TileCollision collision = level.GetCollision(x, y); if (collision != TileCollision.Passable) { Rectangle tileBounds = level.GetBounds(x, y); if (enemyToChar.Intersect(tileBounds) == true) { wallInWay = true; } } } } }
public override void HandleCollisions(GameTime gameTime) { int xOrigin = (int)(Position.X) / Tile.Width; int yOrigin = (int)(Position.Y) / Tile.Height; int xStart = xOrigin - 15; int yStart = yOrigin - 15; int xEnd = xOrigin + 15; int yEnd = yOrigin + 15; enemyToChar = new LiangBarsky(Position, new Vector2(level.Player.Position.X, level.Player.Position.Y - 32.0f)); wallInWay = false; for (int y = yStart; y < yEnd; ++y) { for (int x = xStart; x < xEnd; ++x) { TileCollision collision = level.GetCollision(x, y); if (collision != TileCollision.Passable && collision != TileCollision.Patrol) { Rectangle tileBounds = level.GetBounds(x, y); if (enemyToChar.Intersect(tileBounds) == true) { wallInWay = true; } } } } Rectangle bounds = BoundingRectangle; Vector2 depth = RectangleExtensions.GetIntersectionDepth(bounds, level.Player.BoundingRectangle); if (depth.X < -2.0f || depth.X > 2.0f) { velocity = Vector2.Zero; if (level.Player.StopPlayerCollision == false) { level.Rumble.RumbleSetup(500.0f, 0.5f); level.Player.Strikes -= 1; level.Player.IsHit = true; } } }