Compare commits

..

No commits in common. "36e70989af879a95c34dc7a0a9698150ed6df3c8" and "299ab41ec220530480e671c29d8f038c0a9004c8" have entirely different histories.

2 changed files with 15 additions and 17 deletions

View File

@ -94,7 +94,7 @@ namespace SemiColinGames {
if (box.Intersect(player) != null) { if (box.Intersect(player) != null) {
Debug.AddRect(box, Color.Cyan); Debug.AddRect(box, Color.Cyan);
reject = true; reject = true;
if (box.Tile?.IsHazard ?? false) { if (box.Tile?.IsHarmful ?? false) {
Debug.AddRect(box, Color.Red); Debug.AddRect(box, Color.Red);
harmedByCollision = true; harmedByCollision = true;
} }
@ -112,7 +112,7 @@ namespace SemiColinGames {
if (box.Intersect(player) != null) { if (box.Intersect(player) != null) {
Debug.AddRect(box, Color.Cyan); Debug.AddRect(box, Color.Cyan);
reject = true; reject = true;
if (box.Tile?.IsHazard ?? false) { if (box.Tile?.IsHarmful ?? false) {
Debug.AddRect(box, Color.Red); Debug.AddRect(box, Color.Red);
harmedByCollision = true; harmedByCollision = true;
} }
@ -130,7 +130,7 @@ namespace SemiColinGames {
if (groundIntersect.Intersect(box) != null) { if (groundIntersect.Intersect(box) != null) {
Debug.AddRect(box, Color.Cyan); Debug.AddRect(box, Color.Cyan);
standingOnGround = true; standingOnGround = true;
if (box.Tile?.IsHazard ?? false) { if (box.Tile?.IsHarmful ?? false) {
Debug.AddRect(box, Color.Red); Debug.AddRect(box, Color.Red);
harmedByCollision = true; harmedByCollision = true;
} }

View File

@ -15,11 +15,11 @@ namespace SemiColinGames {
Position = position; Position = position;
this.texture = texture; this.texture = texture;
this.textureSource = textureSource; this.textureSource = textureSource;
IsHazard = isHazard; IsHarmful = isHazard;
} }
public Rectangle Position { get; private set; } public Rectangle Position { get; private set; }
public bool IsHazard = false; public bool IsHarmful = false;
public void Draw(SpriteBatch spriteBatch) { public void Draw(SpriteBatch spriteBatch) {
spriteBatch.Draw( spriteBatch.Draw(
@ -35,7 +35,7 @@ namespace SemiColinGames {
// TODO: remove this. // TODO: remove this.
public const int TileSize = 16; public const int TileSize = 16;
readonly Tile[] obstacles; readonly Tile[] tiles;
readonly Tile[] decorations; readonly Tile[] decorations;
// Kept around for resetting the world's entities after player death or level restart. // Kept around for resetting the world's entities after player death or level restart.
readonly JToken entitiesLayer; readonly JToken entitiesLayer;
@ -134,8 +134,8 @@ namespace SemiColinGames {
} }
// Get all the obstacles into a single array, sorted by X. // Get all the obstacles into a single array, sorted by X.
obstacleTiles.AddRange(hazardTiles); obstacleTiles.AddRange(hazardTiles);
obstacles = obstacleTiles.ToArray(); tiles = obstacleTiles.ToArray();
Array.Sort(obstacles, CompareByX); Array.Sort(tiles, CompareByX);
// The background tiles are added before the rest of the decorations, so that they're drawn // The background tiles are added before the rest of the decorations, so that they're drawn
// in the back. // in the back.
backgroundTiles.AddRange(decorationTiles); backgroundTiles.AddRange(decorationTiles);
@ -144,21 +144,21 @@ namespace SemiColinGames {
// The obstacles are sorted by x-position. We maintain this invariant so that it's possible // The obstacles 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. // to efficiently find CollisionTargets that are nearby a given x-position.
CollisionTargets = new AABB[obstacles.Length + 2]; CollisionTargets = new AABB[tiles.Length + 2];
// Add a synthetic collisionTarget on the left side of the world. // Add a synthetic collisionTarget on the left side of the world.
CollisionTargets[0] = new AABB(new Vector2(-1, 0), new Vector2(1, float.MaxValue)); CollisionTargets[0] = new AABB(new Vector2(-1, 0), new Vector2(1, float.MaxValue));
// Now add all the normal collisionTargets for every obstacle. // Now add all the normal collisionTargets for every static terrain tile.
Vector2 halfSize = new Vector2(TileSize / 2, TileSize / 2); Vector2 halfSize = new Vector2(TileSize / 2, TileSize / 2);
for (int i = 0; i < obstacles.Length; i++) { for (int i = 0; i < tiles.Length; i++) {
Vector2 center = new Vector2( Vector2 center = new Vector2(
obstacles[i].Position.Left + halfSize.X, obstacles[i].Position.Top + halfSize.Y); tiles[i].Position.Left + halfSize.X, tiles[i].Position.Top + halfSize.Y);
CollisionTargets[i + 1] = new AABB(center, halfSize, obstacles[i]); CollisionTargets[i + 1] = new AABB(center, halfSize, tiles[i]);
} }
// Add a final synthetic collisionTarget on the right side of the world. // Add a final synthetic collisionTarget on the right side of the world.
CollisionTargets[obstacles.Length + 1] = new AABB( CollisionTargets[tiles.Length + 1] = new AABB(
new Vector2(Width + 1, 0), new Vector2(1, float.MaxValue)); new Vector2(Width + 1, 0), new Vector2(1, float.MaxValue));
} }
@ -176,7 +176,6 @@ namespace SemiColinGames {
(Player, npcs) = ParseEntities(entitiesLayer); (Player, npcs) = ParseEntities(entitiesLayer);
} }
// Draws everything that's behind the player, from back to front.
public void DrawBackground(SpriteBatch spriteBatch) { public void DrawBackground(SpriteBatch spriteBatch) {
foreach (Tile t in decorations) { foreach (Tile t in decorations) {
t.Draw(spriteBatch); t.Draw(spriteBatch);
@ -186,9 +185,8 @@ namespace SemiColinGames {
} }
} }
// Draws everything that's in front of the player, from back to front.
public void DrawForeground(SpriteBatch spriteBatch) { public void DrawForeground(SpriteBatch spriteBatch) {
foreach (Tile t in obstacles) { foreach (Tile t in tiles) {
t.Draw(spriteBatch); t.Draw(spriteBatch);
} }
} }