Tried making Enemy by copying Soldier. +Monster

... I think I failed, though...

Oh, that monster was made by Christian
This commit is contained in:
Niklas Ulf Anders Cullberg
2012-10-03 12:33:22 +02:00
parent 4658decf32
commit b4dc13e420
5 changed files with 573 additions and 444 deletions
+12
View File
@@ -23,6 +23,7 @@ namespace DepthsBelow
public static MouseInput MouseInput; public static MouseInput MouseInput;
public List<Soldier> Squad; public List<Soldier> Squad;
public List<SmallEnemy> Swarm;
public static Map Map; public static Map Map;
public Core() public Core()
@@ -52,6 +53,7 @@ namespace DepthsBelow
// TODO: Add your initialization logic here // TODO: Add your initialization logic here
Camera = new Camera(this); Camera = new Camera(this);
Squad = new List<Soldier>(); Squad = new List<Soldier>();
Swarm = new List<SmallEnemy>();
base.Initialize(); base.Initialize();
} }
@@ -71,6 +73,7 @@ namespace DepthsBelow
// TODO: use this.Content to load your game content here // TODO: use this.Content to load your game content here
Soldier.LoadContent(this); Soldier.LoadContent(this);
SmallEnemy.LoadContent(this);
MouseInput = new MouseInput(this); MouseInput = new MouseInput(this);
MouseInput.LoadContent(); MouseInput.LoadContent();
@@ -103,6 +106,9 @@ namespace DepthsBelow
foreach (var soldier in Squad) foreach (var soldier in Squad)
soldier.Update(gameTime); soldier.Update(gameTime);
foreach (var body in Swarm)
body.Update(gameTime);
base.Update(gameTime); base.Update(gameTime);
} }
@@ -128,6 +134,12 @@ namespace DepthsBelow
if (sr != null) if (sr != null)
sr.Draw(spriteBatch); sr.Draw(spriteBatch);
} }
foreach (var body in Swarm)
{
var sr = body.GetComponent<Component.SpriteRenderer>();
if (sr != null)
sr.Draw(spriteBatch);
}
// Draw mouse input visuals // Draw mouse input visuals
MouseInput.Draw(spriteBatch); MouseInput.Draw(spriteBatch);
@@ -135,6 +135,7 @@
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Component\SpriteRenderer.cs" /> <Compile Include="Component\SpriteRenderer.cs" />
<Compile Include="SmallEnemy.cs" />
<Compile Include="Soldier.cs" /> <Compile Include="Soldier.cs" />
<Compile Include="Component\PixelTransform.cs" /> <Compile Include="Component\PixelTransform.cs" />
</ItemGroup> </ItemGroup>
+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> <Processor>TextureProcessor</Processor>
</Compile> </Compile>
</ItemGroup> </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" /> <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. <!-- 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. Other similar extension points exist, see Microsoft.Common.targets.
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB