Merge branch 'master' into astar
Conflicts: DepthsBelow/DepthsBelow/Core.cs DepthsBelow/DepthsBelow/MouseInput.cs DepthsBelow/DepthsBelowContent/maps/Cave.Level1.tmx
This commit is contained in:
Regular → Executable
+25
-12
@@ -20,10 +20,11 @@ namespace DepthsBelow
|
||||
SpriteBatch spriteBatch;
|
||||
|
||||
public static AStar.PathFinderFast PathFinder;
|
||||
public Camera Camera;
|
||||
|
||||
public Camera camera;
|
||||
MouseInput mouseInput;
|
||||
public Soldier soldier;
|
||||
//public Soldier soldier;
|
||||
public List<Soldier> Squad;
|
||||
private Map map;
|
||||
|
||||
public Core()
|
||||
@@ -51,7 +52,9 @@ namespace DepthsBelow
|
||||
protected override void Initialize()
|
||||
{
|
||||
// TODO: Add your initialization logic here
|
||||
camera = new Camera(this);
|
||||
Camera = new Camera(this);
|
||||
Squad = new List<Soldier>();
|
||||
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
@@ -65,6 +68,8 @@ namespace DepthsBelow
|
||||
spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||
|
||||
map = Content.Load<Map>("maps/Cave.Level1");
|
||||
map.ParseObjects(this);
|
||||
|
||||
PathFinder = new AStar.PathFinderFast(map.GetCollisionMap());
|
||||
PathFinder.Formula = AStar.HeuristicFormula.Manhattan;
|
||||
PathFinder.Diagonals = false;
|
||||
@@ -78,7 +83,7 @@ namespace DepthsBelow
|
||||
|
||||
// TODO: use this.Content to load your game content here
|
||||
Soldier.LoadContent(this);
|
||||
soldier = new Soldier(this);
|
||||
//soldier = new Soldier(this);
|
||||
|
||||
mouseInput = new MouseInput(this);
|
||||
mouseInput.LoadContent();
|
||||
@@ -104,11 +109,13 @@ namespace DepthsBelow
|
||||
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
|
||||
this.Exit();
|
||||
|
||||
camera.Update(gameTime);
|
||||
Camera.Update(gameTime);
|
||||
mouseInput.Update(gameTime);
|
||||
|
||||
// TODO: Add your update logic here
|
||||
soldier.Update(gameTime);
|
||||
//soldier.Update(gameTime);
|
||||
foreach (var soldier in Squad)
|
||||
soldier.Update(gameTime);
|
||||
|
||||
base.Update(gameTime);
|
||||
}
|
||||
@@ -121,17 +128,23 @@ namespace DepthsBelow
|
||||
{
|
||||
GraphicsDevice.Clear(Color.Black);
|
||||
|
||||
// Start drawing using the camera transform
|
||||
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, camera.Transform);
|
||||
// Start drawing using the Camera transform
|
||||
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null,
|
||||
Camera.Transform);
|
||||
|
||||
// Draw the level
|
||||
map.Draw(spriteBatch);
|
||||
// Draw units
|
||||
// TODO: Foreach etc...
|
||||
Component.SpriteRenderer rc = soldier.GetComponent<Component.SpriteRenderer>();
|
||||
if (rc != null)
|
||||
rc.Draw(spriteBatch);
|
||||
// Draw mouse input visuals
|
||||
foreach (var soldier in Squad)
|
||||
{
|
||||
var sr = soldier.GetComponent<Component.SpriteRenderer>();
|
||||
Console.WriteLine("Drawing soldier at: " + soldier.pixelTransform.X + "," + soldier.pixelTransform.Y);
|
||||
if (sr != null)
|
||||
sr.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
// Draw mouse input visuals
|
||||
mouseInput.Draw(spriteBatch);
|
||||
|
||||
spriteBatch.End();
|
||||
|
||||
@@ -11,6 +11,25 @@ namespace DepthsBelow
|
||||
List<Component.Component> Components;
|
||||
public Component.PixelTransform pixelTransform;
|
||||
public Component.GridTransform gridTransform;
|
||||
public int X
|
||||
{
|
||||
get { return this.gridTransform.X; }
|
||||
set
|
||||
{
|
||||
this.gridTransform.X = value;
|
||||
this.pixelTransform.X = this.gridTransform.ToWorld().X;
|
||||
}
|
||||
}
|
||||
public int Y
|
||||
{
|
||||
get { return this.gridTransform.Y; }
|
||||
set
|
||||
{
|
||||
this.gridTransform.Y = value;
|
||||
this.pixelTransform.Y = this.gridTransform.ToWorld().Y;
|
||||
}
|
||||
}
|
||||
|
||||
private Core core;
|
||||
|
||||
public Entity(Core core)
|
||||
|
||||
@@ -5,7 +5,7 @@ using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace DepthsBelow
|
||||
{
|
||||
public class Tile
|
||||
public class MapTile
|
||||
{
|
||||
public int LocalId;
|
||||
public Texture2D Texture;
|
||||
@@ -13,42 +13,107 @@ namespace DepthsBelow
|
||||
public SpriteEffects SpriteEffects;
|
||||
}
|
||||
|
||||
public class Layer
|
||||
public enum MapObjectType : byte
|
||||
{
|
||||
Plain,
|
||||
Tile,
|
||||
Polygon,
|
||||
Polyline
|
||||
}
|
||||
|
||||
public class MapObject
|
||||
{
|
||||
//public MapObjectType ObjectType;
|
||||
public string Name;
|
||||
public string Type;
|
||||
public Rectangle Bounds;
|
||||
public List<Vector2> Points;
|
||||
}
|
||||
|
||||
public class MapLayer
|
||||
{
|
||||
public int Width;
|
||||
public int Height;
|
||||
public string Name;
|
||||
public Tile[] Tiles;
|
||||
}
|
||||
|
||||
public class MapTileLayer : MapLayer
|
||||
{
|
||||
public MapTile[] Tiles;
|
||||
}
|
||||
|
||||
public class MapObjectLayer : MapLayer
|
||||
{
|
||||
public MapObject[] Objects;
|
||||
}
|
||||
|
||||
public class Map
|
||||
{
|
||||
public int TileWidth;
|
||||
public int TileHeight;
|
||||
public List<Layer> Layers = new List<Layer>();
|
||||
public List<MapLayer> Layers = new List<MapLayer>();
|
||||
|
||||
public Map()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void ParseObjects(Core core)
|
||||
{
|
||||
foreach (var layer in Layers)
|
||||
{
|
||||
var objectLayer = layer as MapObjectLayer;
|
||||
|
||||
if (objectLayer == null)
|
||||
continue;
|
||||
|
||||
foreach (var mapObject in objectLayer.Objects)
|
||||
{
|
||||
Console.WriteLine(mapObject.Type);
|
||||
Console.WriteLine(mapObject.Bounds.Left + "," + mapObject.Bounds.Top);
|
||||
|
||||
if (mapObject.Type == "SquadStart")
|
||||
{
|
||||
var soldier = new Soldier(core);
|
||||
var mapObjectPos = new Vector2(mapObject.Bounds.Left, mapObject.Bounds.Top);
|
||||
var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos);
|
||||
soldier.X = mapObjectGridPos.X;
|
||||
soldier.Y = mapObjectGridPos.Y;
|
||||
|
||||
core.Squad.Add(soldier);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
foreach (var layer in Layers)
|
||||
{
|
||||
if (layer.Name == "Collision")
|
||||
var tileLayer = layer as MapTileLayer;
|
||||
|
||||
if (tileLayer == null)
|
||||
continue;
|
||||
|
||||
for (int y = 0; y < layer.Height; y++)
|
||||
// Don't draw the collision layer
|
||||
if (tileLayer.Name == "Collision")
|
||||
continue;
|
||||
|
||||
for (int y = 0; y < tileLayer.Height; y++)
|
||||
{
|
||||
for (int x = 0; x < layer.Width; x++)
|
||||
for (int x = 0; x < tileLayer.Width; x++)
|
||||
{
|
||||
Tile tile = layer.Tiles[y*layer.Width + x];
|
||||
if (tile != null)
|
||||
MapTile mapTile = tileLayer.Tiles[y * layer.Width + x];
|
||||
if (mapTile != null)
|
||||
{
|
||||
spriteBatch.Draw(
|
||||
tile.Texture,
|
||||
mapTile.Texture,
|
||||
new Rectangle(x * TileWidth, y * TileHeight, TileWidth, TileHeight),
|
||||
tile.SourceRectangle,
|
||||
mapTile.SourceRectangle,
|
||||
Color.White,
|
||||
0,
|
||||
Vector2.Zero,
|
||||
tile.SpriteEffects,
|
||||
mapTile.SpriteEffects,
|
||||
0);
|
||||
}
|
||||
}
|
||||
|
||||
Regular → Executable
+11
-5
@@ -39,7 +39,7 @@ namespace DepthsBelow
|
||||
public void Update(GameTime gameTime)
|
||||
{
|
||||
MouseState ms = Mouse.GetState();
|
||||
Vector2 mouseWorldPos = core.camera.ScreenToWorld(new Vector2(ms.X, ms.Y));
|
||||
Vector2 mouseWorldPos = core.Camera.ScreenToWorld(new Vector2(ms.X, ms.Y));
|
||||
KeyboardState ks = Keyboard.GetState();
|
||||
|
||||
// Selection rectangle
|
||||
@@ -55,18 +55,24 @@ namespace DepthsBelow
|
||||
selectionRectangle.Height = (int)mouseWorldPos.Y - selectionRectangle.Y;
|
||||
}
|
||||
}
|
||||
// When the mouse is released
|
||||
if (ms.LeftButton == ButtonState.Released && selectionRectangle != Rectangle.Empty)
|
||||
{
|
||||
// Deselect all units
|
||||
if (!ks.IsKeyDown(Keys.LeftControl))
|
||||
{
|
||||
core.soldier.Selected = false;
|
||||
foreach (var unit in core.Squad)
|
||||
unit.Selected = false;
|
||||
}
|
||||
|
||||
if (selectionRectangle.Intersects(core.soldier.GetComponent<Component.Collision>().Rectangle))
|
||||
// Select all units in the rectangle
|
||||
foreach (var unit in core.Squad)
|
||||
{
|
||||
core.soldier.Selected = true;
|
||||
if (selectionRectangle.Intersects(unit.GetComponent<Component.Collision>().Rectangle))
|
||||
unit.Selected = true;
|
||||
}
|
||||
|
||||
|
||||
// Hide the selection rectangle
|
||||
selectionRectangle = Rectangle.Empty;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace DepthsBelow
|
||||
public class Soldier : Entity
|
||||
{
|
||||
public static Texture2D Texture;
|
||||
public Color Color;
|
||||
public static Point Origin;
|
||||
private bool _selected;
|
||||
|
||||
@@ -23,6 +24,7 @@ namespace DepthsBelow
|
||||
gridTransform.Position = new Point(7, 3);
|
||||
pixelTransform.Position = gridTransform.ToWorld();
|
||||
|
||||
this.Color = Color.White;
|
||||
var rc = new SpriteRenderer(this) {Texture = Texture, Color = Color.White};
|
||||
AddComponent(rc);
|
||||
|
||||
@@ -40,7 +42,7 @@ namespace DepthsBelow
|
||||
set
|
||||
{
|
||||
_selected = value;
|
||||
GetComponent<SpriteRenderer>().Color = (value) ? Color.Blue : Color.HotPink;
|
||||
GetComponent<SpriteRenderer>().Color = (value) ? Color.Blue : this.Color;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -89,6 +89,7 @@
|
||||
<Name>Cave.Level1</Name>
|
||||
<Processor>MapProcessor</Processor>
|
||||
<Importer>TmxImporter</Importer>
|
||||
<SubType>Designer</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -214,4 +214,11 @@
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||
</data>
|
||||
</layer>
|
||||
<objectgroup name="Object Layer 1" width="100" height="100">
|
||||
<object name="Spawn1" type="SquadStart" gid="143" x="288" y="256"/>
|
||||
<object name="Spawn2" type="SquadStart" gid="143" x="288" y="192"/>
|
||||
<object name="Spawn4" type="SquadStart" gid="143" x="224" y="160"/>
|
||||
<object name="Spawn3" type="SquadStart" gid="143" x="224" y="224"/>
|
||||
<object name="Spawn5" type="SquadStart" gid="143" x="160" y="192"/>
|
||||
</objectgroup>
|
||||
</map>
|
||||
|
||||
@@ -12,7 +12,7 @@ using TiledLib;
|
||||
namespace DepthsBelowContentPipeline
|
||||
{
|
||||
// Each tile has a texture, source rect, and sprite effects.
|
||||
[ContentSerializerRuntimeType("DepthsBelow.Tile, DepthsBelow")]
|
||||
[ContentSerializerRuntimeType("DepthsBelow.MapTile, DepthsBelow")]
|
||||
public class MapTileContent
|
||||
{
|
||||
public int LocalId;
|
||||
@@ -21,15 +21,34 @@ namespace DepthsBelowContentPipeline
|
||||
public SpriteEffects SpriteEffects;
|
||||
}
|
||||
|
||||
[ContentSerializerRuntimeType("DepthsBelow.MapObject, DepthsBelow")]
|
||||
public class MapObjectContent
|
||||
{
|
||||
//public MapObjectType ObjectType;
|
||||
public string Name;
|
||||
public string Type;
|
||||
public Rectangle Bounds;
|
||||
public List<Vector2> Points;
|
||||
}
|
||||
|
||||
// For each layer, we store the size of the layer and the tiles.
|
||||
[ContentSerializerRuntimeType("DepthsBelow.Layer, DepthsBelow")]
|
||||
[ContentSerializerRuntimeType("DepthsBelow.MapLayer, DepthsBelow")]
|
||||
public class MapLayerContent
|
||||
{
|
||||
public int Width;
|
||||
public int Height;
|
||||
public string Name;
|
||||
}
|
||||
[ContentSerializerRuntimeType("DepthsBelow.MapTileLayer, DepthsBelow")]
|
||||
public class MapTileLayerContent : MapLayerContent
|
||||
{
|
||||
public MapTileContent[] Tiles;
|
||||
}
|
||||
[ContentSerializerRuntimeType("DepthsBelow.MapObjectLayer, DepthsBelow")]
|
||||
public class MapObjectLayerContent : MapLayerContent
|
||||
{
|
||||
public MapObjectContent[] Objects;
|
||||
}
|
||||
|
||||
// For the map itself, we just store the size, tile size, and a list of layers.
|
||||
[ContentSerializerRuntimeType("DepthsBelow.Map, DepthsBelow")]
|
||||
@@ -45,8 +64,6 @@ namespace DepthsBelowContentPipeline
|
||||
{
|
||||
public override MapContent Process(TiledLib.MapContent input, ContentProcessorContext context)
|
||||
{
|
||||
//System.Diagnostics.Debugger.Launch();
|
||||
|
||||
// build the textures
|
||||
TiledHelpers.BuildTileSetTextures(input, context, "maps");
|
||||
|
||||
@@ -57,18 +74,49 @@ namespace DepthsBelowContentPipeline
|
||||
MapContent output = new MapContent
|
||||
{
|
||||
TileWidth = input.TileWidth,
|
||||
TileHeight = input.TileHeight
|
||||
TileHeight = input.TileHeight,
|
||||
};
|
||||
|
||||
// iterate all the layers of the input
|
||||
foreach (LayerContent layer in input.Layers)
|
||||
{
|
||||
// Get layer objects
|
||||
var molc = layer as TiledLib.MapObjectLayerContent;
|
||||
if (molc != null)
|
||||
{
|
||||
//System.Diagnostics.Debugger.Launch();
|
||||
// create the new layer
|
||||
MapObjectLayerContent outLayer = new MapObjectLayerContent
|
||||
{
|
||||
Width = molc.Width,
|
||||
Height = molc.Height,
|
||||
Name = molc.Name
|
||||
};
|
||||
|
||||
outLayer.Objects = new MapObjectContent[molc.Objects.Count];
|
||||
for (int i = 0; i < molc.Objects.Count; i++)
|
||||
{
|
||||
var layerObject = molc.Objects[i];
|
||||
outLayer.Objects[i] = new MapObjectContent
|
||||
{
|
||||
//ObjectType = layerObject.ObjectType,
|
||||
Name = layerObject.Name,
|
||||
Type = layerObject.Type,
|
||||
Bounds = layerObject.Bounds,
|
||||
Points = layerObject.Points
|
||||
};
|
||||
}
|
||||
|
||||
output.Layers.Add(outLayer);
|
||||
}
|
||||
|
||||
// we only care about tile layers in our demo
|
||||
TileLayerContent tlc = layer as TileLayerContent;
|
||||
|
||||
if (tlc != null)
|
||||
{
|
||||
// create the new layer
|
||||
MapLayerContent outLayer = new MapLayerContent
|
||||
MapTileLayerContent outLayer = new MapTileLayerContent
|
||||
{
|
||||
Width = tlc.Width,
|
||||
Height = tlc.Height,
|
||||
|
||||
Reference in New Issue
Block a user