public void CalculateCollisions() { List <Tuple <Tile, Side> > Effects = new List <Tuple <Tile, Side> >(); Tiles tiles = Program.World.Level.Tiles; collisions[Side.Left].Clear(); collisions[Side.Right].Clear(); collisions[Side.Up].Clear(); collisions[Side.Down].Clear(); int xbound = (int)Math.Floor(Position.X / Tile.Size.X / 2), ybound = (int)Math.Floor(Position.Y / Tile.Size.Y / 2); for (int y = ybound - 1; y <= ybound + 1; y++) { for (int x = xbound - 1; x <= xbound + 1; x++) { Tile t = tiles.GetTile(x, y); if (t != null && CollisionBox.Collide(Box, t.Box) && ((t.Position - Position).Length < (Tile.Size + Size).Length - 1)) { Side s = Box.Collide(t.Box); Effects.Add(new Tuple <Tile, Side>(t, s)); if (t.IsMark) { continue; } collisions[s].Add(t); } } } foreach (Tile t in tiles.GetMovingTiles()) { if (CollisionBox.Collide(Box, t.Box) && ((t.Position - Position).Length < (Tile.Size + Size).Length - 1)) { Side s = Box.Collide(t.Box); t.Effect(this, s); if (t.IsMark) { continue; } collisions[s].Add(t); } } foreach (var a in Effects) { a.Item1.Effect(this, a.Item2); } }