enumerate and show collision targets
GitOrigin-RevId: d8cb888e4e13e4f492df90a210c8f24884d73b94
This commit is contained in:
parent
fb2d0e8a6d
commit
9c8f8b70df
@ -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();
|
||||
|
||||
|
@ -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…
Reference in New Issue
Block a user