diff --git a/Shared/Player.cs b/Shared/Player.cs index 95baa00..8433626 100644 --- a/Shared/Player.cs +++ b/Shared/Player.cs @@ -33,7 +33,7 @@ namespace SemiColinGames { return new Rectangle(position.X - spriteWidth, position.Y - 7, spriteWidth * 2, 26); } - public void Update(float modelTime, History input, List collisionTargets) { + public void Update(float modelTime, History input, Rectangle[] collisionTargets) { Point oldPosition = position; Vector2 movement = HandleInput(modelTime, input); position = new Point((int) (oldPosition.X + movement.X), (int) (oldPosition.Y + movement.Y)); diff --git a/Shared/SneakGame.cs b/Shared/SneakGame.cs index c5f2793..4b61005 100644 --- a/Shared/SneakGame.cs +++ b/Shared/SneakGame.cs @@ -93,7 +93,7 @@ namespace SemiColinGames { if (!paused) { float modelTime = (float) gameTime.ElapsedGameTime.TotalSeconds; Clock.AddModelTime(modelTime); - List collisionTargets = world.CollisionTargets(); + Rectangle[] collisionTargets = world.CollisionTargets; player.Update(modelTime, input, collisionTargets); camera.Update(player.Position); } diff --git a/Shared/World.cs b/Shared/World.cs index 54e65ea..e46c6ad 100644 --- a/Shared/World.cs +++ b/Shared/World.cs @@ -82,7 +82,8 @@ namespace SemiColinGames { class World { public const int TileSize = 16; - readonly List tiles = new List(); + readonly Tile[] tiles; + readonly Rectangle[] collisionTargets; public int Width { get; private set; } public int Height { get; private set; } @@ -106,6 +107,7 @@ namespace SemiColinGames { ....................] [............................................] [.............] [..............................................................] [......................................................."; public World(Texture2D texture) { + var tilesList = new List(); string[] worldDesc = worldString.Split('\n'); Width = worldDesc.AsQueryable().Max(a => a.Length); Height = worldDesc.Length; @@ -146,10 +148,15 @@ namespace SemiColinGames { } if (terrain != Terrain.Empty) { var position = new Rectangle(i * TileSize, j * TileSize, TileSize, TileSize); - tiles.Add(new Tile(texture, terrain, position)); + tilesList.Add(new Tile(texture, terrain, position)); } } } + tiles = tilesList.ToArray(); + collisionTargets = new Rectangle[tiles.Length]; + for (int i = 0; i < tiles.Length; i++) { + collisionTargets[i] = tiles[i].Position; + } } public void Draw(SpriteBatch spriteBatch, Camera camera) { @@ -158,12 +165,8 @@ namespace SemiColinGames { } } - public List CollisionTargets() { - var result = new List(); - foreach (Tile t in tiles) { - result.Add(t.Position); - } - return result; + public Rectangle[] CollisionTargets { + get { return collisionTargets; } } } }