Browse Source

enumerate and show collision targets

GitOrigin-RevId: d8cb888e4e
master
Colin McMillen 4 years ago
parent
commit
9c8f8b70df
  1. 7
      Jumpy.Shared/JumpyGame.cs
  2. 18
      Jumpy.Shared/World.cs

7
Jumpy.Shared/JumpyGame.cs

@ -54,6 +54,7 @@ namespace Jumpy {
// Called once per game. Loads all game content.
protected override void LoadContent() {
Console.WriteLine("LoadContent()");
spriteBatch = new SpriteBatch(GraphicsDevice);
font = Content.Load<SpriteFont>("font");
// TODO: decouple things like Player and World from their textures.
@ -86,6 +87,7 @@ namespace Jumpy {
display.SetFullScreen(fullScreen);
}
List<Rectangle> collisionTargets = world.CollisionTargets();
player.Update(gameTime, gamePad);
base.Update(gameTime);
@ -132,6 +134,11 @@ namespace Jumpy {
// Draw foreground tiles.
world.Draw(spriteBatch);
// Draw debug rects.
foreach (var rect in world.CollisionTargets()) {
DrawRect(spriteBatch, rect, Color.Yellow);
}
// Aaaaand we're done.
spriteBatch.End();

18
Jumpy.Shared/World.cs

@ -1,5 +1,6 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
namespace Jumpy {
@ -20,8 +21,8 @@ namespace Jumpy {
this.position = position;
}
public Rectangle Position { get; }
public Terrain Terrain { get; }
public Rectangle Position { get { return position; } }
public Terrain Terrain { get { return terrain; } }
public void Draw(SpriteBatch spriteBatch) {
int size = World.TileSize;
@ -84,5 +85,18 @@ namespace Jumpy {
}
}
}
public List<Rectangle> CollisionTargets() {
var result = new List<Rectangle>();
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
var t = tiles[i, j];
if (t.Terrain != Terrain.Empty) {
result.Add(t.Position);
}
}
}
return result;
}
}
}
Loading…
Cancel
Save