|
|
@ -6,7 +6,7 @@ using System.Collections.Generic; |
|
|
|
|
|
|
|
namespace SemiColinGames { |
|
|
|
|
|
|
|
public class World { |
|
|
|
public sealed class World : IDisposable { |
|
|
|
|
|
|
|
public const int TileSize = 16; |
|
|
|
|
|
|
@ -21,6 +21,7 @@ namespace SemiColinGames { |
|
|
|
|
|
|
|
public Player Player { get; private set; } |
|
|
|
public AABB[] CollisionTargets { get; } |
|
|
|
public LinesOfSight LinesOfSight { get; private set; } |
|
|
|
|
|
|
|
// Size of World in pixels.
|
|
|
|
public int Width { |
|
|
@ -31,7 +32,9 @@ namespace SemiColinGames { |
|
|
|
get { return gridHeight * TileSize; } |
|
|
|
} |
|
|
|
|
|
|
|
public World(string json) { |
|
|
|
public World(GraphicsDevice graphics, string json) { |
|
|
|
LinesOfSight = new LinesOfSight(graphics); |
|
|
|
|
|
|
|
JObject root = JObject.Parse(json); |
|
|
|
|
|
|
|
List<Tile> hazardTiles = new List<Tile>(); |
|
|
@ -86,6 +89,15 @@ namespace SemiColinGames { |
|
|
|
new Vector2(Width + 1, 0), new Vector2(1, float.MaxValue)); |
|
|
|
} |
|
|
|
|
|
|
|
~World() { |
|
|
|
Dispose(); |
|
|
|
} |
|
|
|
|
|
|
|
public void Dispose() { |
|
|
|
LinesOfSight.Dispose(); |
|
|
|
GC.SuppressFinalize(this); |
|
|
|
} |
|
|
|
|
|
|
|
private List<Tile> ParseLayer(JToken layer) { |
|
|
|
string layerName = layer.SelectToken("name").Value<string>(); |
|
|
|
|
|
|
@ -149,6 +161,7 @@ namespace SemiColinGames { |
|
|
|
if (Player.Health <= 0) { |
|
|
|
Reset(); |
|
|
|
} |
|
|
|
LinesOfSight.Update(Player, CollisionTargets); |
|
|
|
} |
|
|
|
|
|
|
|
// Draws everything that's behind the player, from back to front.
|
|
|
@ -174,8 +187,8 @@ namespace SemiColinGames { |
|
|
|
return t1.Position.X.CompareTo(t2.Position.X); |
|
|
|
} |
|
|
|
|
|
|
|
private TextureRef texture; |
|
|
|
private Rectangle textureSource; |
|
|
|
private readonly TextureRef texture; |
|
|
|
private readonly Rectangle textureSource; |
|
|
|
|
|
|
|
public Tile(TextureRef texture, Rectangle textureSource, Rectangle position, bool isHazard) { |
|
|
|
Position = position; |
|
|
|