Merge branch 'master' of github.com:sippeangelo/DepthsBelow

This commit is contained in:
2012-10-05 11:06:17 +02:00
6 changed files with 763 additions and 613 deletions
+12
View File
@@ -23,6 +23,7 @@ namespace DepthsBelow
public static MouseInput MouseInput;
public List<Soldier> Squad;
public List<SmallEnemy> Swarm;
public static Map Map;
public Core()
@@ -52,6 +53,7 @@ namespace DepthsBelow
// TODO: Add your initialization logic here
Camera = new Camera(this);
Squad = new List<Soldier>();
Swarm = new List<SmallEnemy>();
base.Initialize();
}
@@ -71,6 +73,7 @@ namespace DepthsBelow
// TODO: use this.Content to load your game content here
Soldier.LoadContent(this);
SmallEnemy.LoadContent(this);
MouseInput = new MouseInput(this);
MouseInput.LoadContent();
@@ -103,6 +106,9 @@ namespace DepthsBelow
foreach (var soldier in Squad)
soldier.Update(gameTime);
foreach (var body in Swarm)
body.Update(gameTime);
base.Update(gameTime);
}
@@ -128,6 +134,12 @@ namespace DepthsBelow
if (sr != null)
sr.Draw(spriteBatch);
}
foreach (var body in Swarm)
{
var sr = body.GetComponent<Component.SpriteRenderer>();
if (sr != null)
sr.Draw(spriteBatch);
}
// Draw mouse input visuals
MouseInput.Draw(spriteBatch);
@@ -135,6 +135,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Program.cs" />
<Compile Include="Component\SpriteRenderer.cs" />
<Compile Include="SmallEnemy.cs" />
<Compile Include="Soldier.cs" />
<Compile Include="Component\PixelTransform.cs" />
</ItemGroup>
+21
View File
@@ -23,6 +23,7 @@ namespace DepthsBelow
Vector2 directionNow;
bool checkingDirection = false;
bool readjust = false;
public MouseInput(Core core)
@@ -52,14 +53,34 @@ namespace DepthsBelow
// Selection rectangle
if (ms.LeftButton == ButtonState.Pressed)
{
if (selectionRectangle == Rectangle.Empty)
{
directionStart = mouseWorldPos;
selectionRectangle = new Rectangle((int)mouseWorldPos.X, (int)mouseWorldPos.Y, 0, 0);
readjust = false;
}
else
{
if (mouseWorldPos.X > directionStart.X && mouseWorldPos.Y < directionStart.Y || mouseWorldPos.X < directionStart.X && mouseWorldPos.Y > directionStart.Y)
{
int rectangleX = (int)mouseWorldPos.X - ((int)mouseWorldPos.X - (int)directionStart.X);
int rectangleY = (int)mouseWorldPos.Y;
int rectangleWidth = (int)mouseWorldPos.X - (int)directionStart.X;
int rectangleHeight = (int)directionStart.Y - (int)mouseWorldPos.Y;
selectionRectangle = new Rectangle(rectangleX, rectangleY, rectangleWidth, rectangleHeight);
readjust = true;
}
else
{
if (readjust == true)
{
selectionRectangle = new Rectangle((int)directionStart.X, (int)directionStart.Y, 0, 0);
}
selectionRectangle.Width = (int)mouseWorldPos.X - selectionRectangle.X;
selectionRectangle.Height = (int)mouseWorldPos.Y - selectionRectangle.Y;
readjust = false;
}
}
}
// When the mouse is released
+109
View File
@@ -0,0 +1,109 @@
using System;
using System.Collections.Generic;
using DepthsBelow.Component;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace DepthsBelow
{
public class SmallEnemy : Entity
{
public static Texture2D Texture;
public Color Color;
public static Point Origin;
private bool _selected; //I guess as in "currently doing something"
public List<SmallEnemy> Swarm;
private PathFinder.Node nextNode;
public SmallEnemy(Core core, ref List<SmallEnemy> swarm)
: base(core)
{
if (Texture == null)
LoadContent(core);
this.Swarm = swarm;
Transform.World.Origin = new Vector2(16, 16);
this.Color = Color.White;
var rc = new SpriteRenderer(this) { Texture = Texture, Color = Color.White };
AddComponent(rc);
var cc = new Collision(this, 32, 32);
AddComponent(cc);
var pfc = new PathFinder(this);
AddComponent(pfc);
}
public bool Selected
{
get { return _selected; }
set
{
_selected = value;
GetComponent<SpriteRenderer>().Color = (value) ? Color.Blue : this.Color;
}
}
public static void LoadContent(Core core)
{
Texture = core.Content.Load<Texture2D>("images/Monster");
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
if (nextNode == null)
nextNode = GetComponent<PathFinder>().Next();
if (nextNode != null)
{
List<Point> soldierCollisions = new List<Point>();
foreach (var body in Swarm)
{
if (body != this)
{
if (body.Transform.Grid == nextNode.Position)
{
soldierCollisions.Add(body.Transform.Grid);
GetComponent<PathFinder>().RecreatePath(soldierCollisions);
nextNode = GetComponent<PathFinder>().Next();
break;
}
}
}
if (nextNode != null)
{
var nodeWorldPos = Grid.GridToWorld(nextNode.Position);
// HACK: Make this work properly with other speeds...
float speed = 4f;
if (Transform.World.X < nodeWorldPos.X)
Transform.World.X += speed;
if (Transform.World.X > nodeWorldPos.X)
Transform.World.X -= speed;
if (Transform.World.Y < nodeWorldPos.Y)
Transform.World.Y += speed;
if (Transform.World.Y > nodeWorldPos.Y)
Transform.World.Y -= speed;
if (Transform.World == nodeWorldPos)
nextNode = GetComponent<PathFinder>().Next();
}
}
/**/
}
}
}
@@ -99,6 +99,13 @@
<Processor>TextureProcessor</Processor>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="images\Monster.png">
<Name>Monster</Name>
<Importer>TextureImporter</Importer>
<Processor>TextureProcessor</Processor>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB