|
|
@ -153,14 +153,26 @@ namespace SemiColinGames { |
|
|
|
} |
|
|
|
} |
|
|
|
tiles = tilesList.ToArray(); |
|
|
|
collisionTargets = new Aabb[tiles.Length]; |
|
|
|
|
|
|
|
// Because we added tiles from left to right, the collisionTargets are sorted by x-position.
|
|
|
|
// We maintain this invariant so that it's possible to efficiently find collisionTargets that
|
|
|
|
// are nearby a given x-position.
|
|
|
|
collisionTargets = new Aabb[tiles.Length + 2]; |
|
|
|
|
|
|
|
// Add a synthetic collisionTarget on the left side of the world.
|
|
|
|
collisionTargets[0] = new Aabb(new Vector2(-1, 0), new Vector2(1, float.MaxValue)); |
|
|
|
|
|
|
|
// Now add all the normal collisionTargets for every static terrain tile.
|
|
|
|
Vector2 halfSize = new Vector2(TileSize / 2, TileSize / 2); |
|
|
|
for (int i = 0; i < tiles.Length; i++) { |
|
|
|
Vector2 center = new Vector2( |
|
|
|
tiles[i].Position.Left + halfSize.X, tiles[i].Position.Top + halfSize.Y); |
|
|
|
collisionTargets[i] = new Aabb(center, halfSize); |
|
|
|
collisionTargets[i + 1] = new Aabb(center, halfSize); |
|
|
|
} |
|
|
|
|
|
|
|
// Add a final synthetic collisionTarget on the right side of the world.
|
|
|
|
collisionTargets[tiles.Length + 1] = new Aabb( |
|
|
|
new Vector2(Width * TileSize + 1, 0), new Vector2(1, float.MaxValue)); |
|
|
|
} |
|
|
|
|
|
|
|
public void Draw(SpriteBatch spriteBatch, Camera camera) { |
|
|
|