From 4658decf327f5904716579c26b88e74a1492089b Mon Sep 17 00:00:00 2001 From: Niklas Ulf Anders Cullberg Date: Wed, 3 Oct 2012 11:01:41 +0200 Subject: [PATCH 1/2] SelectionRectangle forms in all directions --- DepthsBelow/DepthsBelow/MouseInput.cs | 359 ++++++++++++++------------ 1 file changed, 190 insertions(+), 169 deletions(-) diff --git a/DepthsBelow/DepthsBelow/MouseInput.cs b/DepthsBelow/DepthsBelow/MouseInput.cs index 18af796..29fb119 100755 --- a/DepthsBelow/DepthsBelow/MouseInput.cs +++ b/DepthsBelow/DepthsBelow/MouseInput.cs @@ -1,169 +1,190 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Content; -using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; -using Microsoft.Xna.Framework.Media; - -namespace DepthsBelow -{ - public class MouseInput - { - Core core; - MouseState lastMouseState; - Rectangle selectionRectangle; - Texture2D selectionTexture; - Rectangle gridRectangle; - Texture2D gridTexture; - - Vector2 directionStart; - Vector2 directionNow; - - bool checkingDirection = false; - - - public MouseInput(Core core) - { - this.core = core; - - selectionRectangle = Rectangle.Empty; - gridRectangle = Rectangle.Empty; - } - - - public void LoadContent() - { - selectionTexture = new Texture2D(core.GraphicsDevice, 1, 1); - selectionTexture.SetData(new Color[] { Color.White }); - - gridTexture = new Texture2D(core.GraphicsDevice, 1, 1); - gridTexture.SetData(new Color[] { Color.White }); - } - - public void Update(GameTime gameTime) - { - MouseState ms = Mouse.GetState(); - Vector2 mouseWorldPos = core.Camera.ScreenToWorld(new Vector2(ms.X, ms.Y)); - KeyboardState ks = Keyboard.GetState(); - - // Selection rectangle - if (ms.LeftButton == ButtonState.Pressed) - { - if (selectionRectangle == Rectangle.Empty) - { - selectionRectangle = new Rectangle((int)mouseWorldPos.X, (int)mouseWorldPos.Y, 0, 0); - } - else - { - selectionRectangle.Width = (int)mouseWorldPos.X - selectionRectangle.X; - 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)) - { - foreach (var unit in core.Squad) - unit.Selected = false; - } - - // Select all units in the rectangle - foreach (var unit in core.Squad) - { - if (selectionRectangle.Intersects(unit.GetComponent().Rectangle)) - unit.Selected = true; - } - - // Hide the selection rectangle - selectionRectangle = Rectangle.Empty; - } - - // Send orders with right click - if (ms.RightButton == ButtonState.Released && lastMouseState.RightButton == ButtonState.Pressed) - { - foreach (var unit in core.Squad) - if (unit.Selected) - { - unit.GetComponent().Goal = Grid.WorldToGrid(mouseWorldPos); - } - - } - if (ms.RightButton == ButtonState.Pressed) - { - foreach (var unit in core.Squad) - { - if (unit.Selected && gridRectangle.Intersects(unit.GetComponent().Rectangle)) - { - checkingDirection = true; - directionStart = unit.Transform.World + unit.Transform.World.Origin; - } - } - } - if (checkingDirection == true && ms.RightButton == ButtonState.Pressed) - { - foreach (var unit in core.Squad) - if (unit.Selected) - { - directionNow.X = mouseWorldPos.X; - directionNow.Y = mouseWorldPos.Y; - float directionX = mouseWorldPos.X - unit.Transform.World.X; - float directionY = mouseWorldPos.Y - unit.Transform.World.Y; - var mouseDirection = mouseWorldPos; - mouseDirection.Normalize(); - //float angle = (float)Math.Acos(Vector2.Dot(new Vector2(0, 1), mouseDirection)) * MathHelper.TwoPi; - /*if (directionX < 0) - { - directionX *= -1; - unit.GetComponent().World.Rotation = (float)Math.Atan(directionY / directionX); - } - else - { - */unit.GetComponent().World.Rotation = (float)Math.Atan2(mouseWorldPos.Y - unit.Transform.World.Y, mouseWorldPos.X - unit.Transform.World.X);/* - }*/ - //Console.WriteLine(angle); - //unit.GetComponent().World.Rotation = angle; - } - } - else - { - checkingDirection = false; - } - - // Grid highlighting - Point mouseGridPos = Grid.WorldToGrid(mouseWorldPos); - Vector2 rectWorldPos = Grid.GridToWorld(mouseGridPos); - gridRectangle = new Rectangle((int)rectWorldPos.X, (int)rectWorldPos.Y, Grid.TileSize, Grid.TileSize); - - lastMouseState = ms; - } - - public void Draw(SpriteBatch spriteBatch) - { - spriteBatch.Draw(selectionTexture, selectionRectangle, Color.Red * 0.5f); - spriteBatch.Draw(gridTexture, gridRectangle, Color.Yellow * 0.3f); - - if (checkingDirection == true) - { - Texture2D blank = new Texture2D(core.GraphicsDevice, 1, 1, false, SurfaceFormat.Color); - blank.SetData(new[] { Color.White }); - DrawLine(spriteBatch, blank, 2, Color.White, directionStart, directionNow); - } - - } - - void DrawLine(SpriteBatch batch, Texture2D blank, float width, Color color, Vector2 point1, Vector2 point2) - { - float angle = (float)Math.Atan2(point2.Y - point1.Y, point2.X - point1.X); - float length = Vector2.Distance(point1, point2); - - batch.Draw(blank, point1, null, color, - angle, Vector2.Zero, new Vector2(length, width), - SpriteEffects.None, 0); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; +using Microsoft.Xna.Framework.Media; + +namespace DepthsBelow +{ + public class MouseInput + { + Core core; + MouseState lastMouseState; + Rectangle selectionRectangle; + Texture2D selectionTexture; + Rectangle gridRectangle; + Texture2D gridTexture; + + Vector2 directionStart; + Vector2 directionNow; + + bool checkingDirection = false; + bool readjust = false; + + + public MouseInput(Core core) + { + this.core = core; + + selectionRectangle = Rectangle.Empty; + gridRectangle = Rectangle.Empty; + } + + + public void LoadContent() + { + selectionTexture = new Texture2D(core.GraphicsDevice, 1, 1); + selectionTexture.SetData(new Color[] { Color.White }); + + gridTexture = new Texture2D(core.GraphicsDevice, 1, 1); + gridTexture.SetData(new Color[] { Color.White }); + } + + public void Update(GameTime gameTime) + { + MouseState ms = Mouse.GetState(); + Vector2 mouseWorldPos = core.Camera.ScreenToWorld(new Vector2(ms.X, ms.Y)); + KeyboardState ks = Keyboard.GetState(); + + // 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 + if (ms.LeftButton == ButtonState.Released && selectionRectangle != Rectangle.Empty) + { + // Deselect all units + if (!ks.IsKeyDown(Keys.LeftControl)) + { + foreach (var unit in core.Squad) + unit.Selected = false; + } + + // Select all units in the rectangle + foreach (var unit in core.Squad) + { + if (selectionRectangle.Intersects(unit.GetComponent().Rectangle)) + unit.Selected = true; + } + + // Hide the selection rectangle + selectionRectangle = Rectangle.Empty; + } + + // Send orders with right click + if (ms.RightButton == ButtonState.Released && lastMouseState.RightButton == ButtonState.Pressed) + { + foreach (var unit in core.Squad) + if (unit.Selected) + { + unit.GetComponent().Goal = Grid.WorldToGrid(mouseWorldPos); + } + + } + if (ms.RightButton == ButtonState.Pressed) + { + foreach (var unit in core.Squad) + { + if (unit.Selected && gridRectangle.Intersects(unit.GetComponent().Rectangle)) + { + checkingDirection = true; + directionStart = unit.Transform.World + unit.Transform.World.Origin; + } + } + } + if (checkingDirection == true && ms.RightButton == ButtonState.Pressed) + { + foreach (var unit in core.Squad) + if (unit.Selected) + { + directionNow.X = mouseWorldPos.X; + directionNow.Y = mouseWorldPos.Y; + float directionX = mouseWorldPos.X - unit.Transform.World.X; + float directionY = mouseWorldPos.Y - unit.Transform.World.Y; + var mouseDirection = mouseWorldPos; + mouseDirection.Normalize(); + //float angle = (float)Math.Acos(Vector2.Dot(new Vector2(0, 1), mouseDirection)) * MathHelper.TwoPi; + /*if (directionX < 0) + { + directionX *= -1; + unit.GetComponent().World.Rotation = (float)Math.Atan(directionY / directionX); + } + else + { + */unit.GetComponent().World.Rotation = (float)Math.Atan2(mouseWorldPos.Y - unit.Transform.World.Y, mouseWorldPos.X - unit.Transform.World.X);/* + }*/ + //Console.WriteLine(angle); + //unit.GetComponent().World.Rotation = angle; + } + } + else + { + checkingDirection = false; + } + + // Grid highlighting + Point mouseGridPos = Grid.WorldToGrid(mouseWorldPos); + Vector2 rectWorldPos = Grid.GridToWorld(mouseGridPos); + gridRectangle = new Rectangle((int)rectWorldPos.X, (int)rectWorldPos.Y, Grid.TileSize, Grid.TileSize); + + lastMouseState = ms; + } + + public void Draw(SpriteBatch spriteBatch) + { + spriteBatch.Draw(selectionTexture, selectionRectangle, Color.Red * 0.5f); + spriteBatch.Draw(gridTexture, gridRectangle, Color.Yellow * 0.3f); + + if (checkingDirection == true) + { + Texture2D blank = new Texture2D(core.GraphicsDevice, 1, 1, false, SurfaceFormat.Color); + blank.SetData(new[] { Color.White }); + DrawLine(spriteBatch, blank, 2, Color.White, directionStart, directionNow); + } + + } + + void DrawLine(SpriteBatch batch, Texture2D blank, float width, Color color, Vector2 point1, Vector2 point2) + { + float angle = (float)Math.Atan2(point2.Y - point1.Y, point2.X - point1.X); + float length = Vector2.Distance(point1, point2); + + batch.Draw(blank, point1, null, color, + angle, Vector2.Zero, new Vector2(length, width), + SpriteEffects.None, 0); + } + } +} From b4dc13e42041f70a6ad5c96654c1f74dbbd502d5 Mon Sep 17 00:00:00 2001 From: Niklas Ulf Anders Cullberg Date: Wed, 3 Oct 2012 12:33:22 +0200 Subject: [PATCH 2/2] Tried making Enemy by copying Soldier. +Monster ... I think I failed, though... Oh, that monster was made by Christian --- DepthsBelow/DepthsBelow/Core.cs | 292 ++++++------- DepthsBelow/DepthsBelow/DepthsBelow.csproj | 391 +++++++++--------- DepthsBelow/DepthsBelow/SmallEnemy.cs | 109 +++++ .../DepthsBelowContent.contentproj | 225 +++++----- .../DepthsBelowContent/images/Monster.png | Bin 0 -> 4080 bytes 5 files changed, 573 insertions(+), 444 deletions(-) create mode 100644 DepthsBelow/DepthsBelow/SmallEnemy.cs create mode 100644 DepthsBelow/DepthsBelowContent/images/Monster.png diff --git a/DepthsBelow/DepthsBelow/Core.cs b/DepthsBelow/DepthsBelow/Core.cs index 415469c..42a3330 100755 --- a/DepthsBelow/DepthsBelow/Core.cs +++ b/DepthsBelow/DepthsBelow/Core.cs @@ -1,140 +1,152 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Audio; -using Microsoft.Xna.Framework.Content; -using Microsoft.Xna.Framework.GamerServices; -using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; -using Microsoft.Xna.Framework.Media; - -namespace DepthsBelow -{ - /// - /// This is the main type for your game - /// - public class Core : Microsoft.Xna.Framework.Game - { - GraphicsDeviceManager graphics; - SpriteBatch spriteBatch; - - public Camera Camera; - - public static MouseInput MouseInput; - public List Squad; - public static Map Map; - - public Core() - { - graphics = new GraphicsDeviceManager(this); - Content.RootDirectory = "Content"; - - graphics.PreferredBackBufferWidth = 1280; - graphics.PreferredBackBufferHeight = 720; - graphics.IsFullScreen = false; - - //graphics.SynchronizeWithVerticalRetrace = false; - this.IsFixedTimeStep = false; - graphics.ApplyChanges(); - - this.IsMouseVisible = true; - } - - /// - /// Allows the game to perform any initialization it needs to before starting to run. - /// This is where it can query for any required services and load any non-graphic - /// related content. Calling base.Initialize will enumerate through any components - /// and initialize them as well. - /// - protected override void Initialize() - { - // TODO: Add your initialization logic here - Camera = new Camera(this); - Squad = new List(); - - base.Initialize(); - } - - /// - /// LoadContent will be called once per game and is the place to load - /// all of your content. - /// - protected override void LoadContent() - { - // Create a new SpriteBatch, which can be used to draw textures. - spriteBatch = new SpriteBatch(GraphicsDevice); - - Map = Content.Load("maps/Cave.Level1"); - // Load map objects - Map.ParseObjects(this); - - // TODO: use this.Content to load your game content here - Soldier.LoadContent(this); - - MouseInput = new MouseInput(this); - MouseInput.LoadContent(); - } - - /// - /// UnloadContent will be called once per game and is the place to unload - /// all content. - /// - protected override void UnloadContent() - { - // TODO: Unload any non ContentManager content here - } - - /// - /// Allows the game to run logic such as updating the world, - /// checking for collisions, gathering input, and playing audio. - /// - /// Provides a snapshot of timing values. - protected override void Update(GameTime gameTime) - { - // Allows the game to exit - if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) - this.Exit(); - - Camera.Update(gameTime); - MouseInput.Update(gameTime); - - // Update soldiers in squad - foreach (var soldier in Squad) - soldier.Update(gameTime); - - base.Update(gameTime); - } - - /// - /// This is called when the game should draw itself. - /// - /// Provides a snapshot of timing values. - protected override void Draw(GameTime gameTime) - { - GraphicsDevice.Clear(Color.Black); - - // 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 - foreach (var soldier in Squad) - { - var sr = soldier.GetComponent(); - if (sr != null) - sr.Draw(spriteBatch); - } - - // Draw mouse input visuals - MouseInput.Draw(spriteBatch); - - spriteBatch.End(); - - base.Draw(gameTime); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Audio; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.GamerServices; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; +using Microsoft.Xna.Framework.Media; + +namespace DepthsBelow +{ + /// + /// This is the main type for your game + /// + public class Core : Microsoft.Xna.Framework.Game + { + GraphicsDeviceManager graphics; + SpriteBatch spriteBatch; + + public Camera Camera; + + public static MouseInput MouseInput; + public List Squad; + public List Swarm; + public static Map Map; + + public Core() + { + graphics = new GraphicsDeviceManager(this); + Content.RootDirectory = "Content"; + + graphics.PreferredBackBufferWidth = 1280; + graphics.PreferredBackBufferHeight = 720; + graphics.IsFullScreen = false; + + //graphics.SynchronizeWithVerticalRetrace = false; + this.IsFixedTimeStep = false; + graphics.ApplyChanges(); + + this.IsMouseVisible = true; + } + + /// + /// Allows the game to perform any initialization it needs to before starting to run. + /// This is where it can query for any required services and load any non-graphic + /// related content. Calling base.Initialize will enumerate through any components + /// and initialize them as well. + /// + protected override void Initialize() + { + // TODO: Add your initialization logic here + Camera = new Camera(this); + Squad = new List(); + Swarm = new List(); + + base.Initialize(); + } + + /// + /// LoadContent will be called once per game and is the place to load + /// all of your content. + /// + protected override void LoadContent() + { + // Create a new SpriteBatch, which can be used to draw textures. + spriteBatch = new SpriteBatch(GraphicsDevice); + + Map = Content.Load("maps/Cave.Level1"); + // Load map objects + Map.ParseObjects(this); + + // TODO: use this.Content to load your game content here + Soldier.LoadContent(this); + SmallEnemy.LoadContent(this); + + MouseInput = new MouseInput(this); + MouseInput.LoadContent(); + } + + /// + /// UnloadContent will be called once per game and is the place to unload + /// all content. + /// + protected override void UnloadContent() + { + // TODO: Unload any non ContentManager content here + } + + /// + /// Allows the game to run logic such as updating the world, + /// checking for collisions, gathering input, and playing audio. + /// + /// Provides a snapshot of timing values. + protected override void Update(GameTime gameTime) + { + // Allows the game to exit + if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) + this.Exit(); + + Camera.Update(gameTime); + MouseInput.Update(gameTime); + + // Update soldiers in squad + foreach (var soldier in Squad) + soldier.Update(gameTime); + + foreach (var body in Swarm) + body.Update(gameTime); + + base.Update(gameTime); + } + + /// + /// This is called when the game should draw itself. + /// + /// Provides a snapshot of timing values. + protected override void Draw(GameTime gameTime) + { + GraphicsDevice.Clear(Color.Black); + + // 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 + foreach (var soldier in Squad) + { + var sr = soldier.GetComponent(); + if (sr != null) + sr.Draw(spriteBatch); + } + foreach (var body in Swarm) + { + var sr = body.GetComponent(); + if (sr != null) + sr.Draw(spriteBatch); + } + + // Draw mouse input visuals + MouseInput.Draw(spriteBatch); + + spriteBatch.End(); + + base.Draw(gameTime); + } + } +} diff --git a/DepthsBelow/DepthsBelow/DepthsBelow.csproj b/DepthsBelow/DepthsBelow/DepthsBelow.csproj index fe80598..492a487 100644 --- a/DepthsBelow/DepthsBelow/DepthsBelow.csproj +++ b/DepthsBelow/DepthsBelow/DepthsBelow.csproj @@ -1,196 +1,197 @@ - - - - {94683C5B-052D-4143-96D8-35C67E831000} - {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Debug - x86 - WinExe - Properties - DepthsBelow - DepthsBelow - v4.0 - Client - v4.0 - Windows - HiDef - faa0577e-a03e-43cf-89c7-0a03f4c22717 - Game - Game.ico - GameThumbnail.png - false - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 1 - 1.0.0.%2a - false - true - true - - - true - full - false - bin\x86\Debug - DEBUG;TRACE;WINDOWS - prompt - 4 - true - false - x86 - false - - - pdbonly - true - bin\x86\Release - TRACE;WINDOWS - prompt - 4 - true - false - x86 - true - - - ECE66DEF071576E8D2F7D57232C0569623E3E2DF - - - DepthsBelow_TemporaryKey.pfx - - - true - - - true - - - - False - - - False - - - False - - - False - - - False - - - False - - - False - - - False - - - False - - - False - - - False - - - - False - - - False - - - False - - - False - - - - - - - - - - - - - - - - - - - - - - - - - - - {CD3F949D-54AA-4D38-99DB-92905A375D84} - AStar - - - DepthsBelowContent %28Content%29 - Content - {433A77A2-DE52-4875-A4EF-232CF59C2DD3} - - - - - False - Microsoft .NET Framework 4 Client Profile %28x86 and x64%29 - true - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - false - - - False - Windows Installer 3.1 - true - - - False - Microsoft XNA Framework Redistributable 4.0 - true - - - - - - - - + + + + {94683C5B-052D-4143-96D8-35C67E831000} + {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Debug + x86 + WinExe + Properties + DepthsBelow + DepthsBelow + v4.0 + Client + v4.0 + Windows + HiDef + faa0577e-a03e-43cf-89c7-0a03f4c22717 + Game + Game.ico + GameThumbnail.png + false + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 1 + 1.0.0.%2a + false + true + true + + + true + full + false + bin\x86\Debug + DEBUG;TRACE;WINDOWS + prompt + 4 + true + false + x86 + false + + + pdbonly + true + bin\x86\Release + TRACE;WINDOWS + prompt + 4 + true + false + x86 + true + + + ECE66DEF071576E8D2F7D57232C0569623E3E2DF + + + DepthsBelow_TemporaryKey.pfx + + + true + + + true + + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + + False + + + False + + + False + + + False + + + + + + + + + + + + + + + + + + + + + + + + + + + + {CD3F949D-54AA-4D38-99DB-92905A375D84} + AStar + + + DepthsBelowContent %28Content%29 + Content + {433A77A2-DE52-4875-A4EF-232CF59C2DD3} + + + + + False + Microsoft .NET Framework 4 Client Profile %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + False + Windows Installer 3.1 + true + + + False + Microsoft XNA Framework Redistributable 4.0 + true + + + + + + + + \ No newline at end of file diff --git a/DepthsBelow/DepthsBelow/SmallEnemy.cs b/DepthsBelow/DepthsBelow/SmallEnemy.cs new file mode 100644 index 0000000..03b5313 --- /dev/null +++ b/DepthsBelow/DepthsBelow/SmallEnemy.cs @@ -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 Swarm; + + private PathFinder.Node nextNode; + + public SmallEnemy(Core core, ref List 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().Color = (value) ? Color.Blue : this.Color; + } + } + + public static void LoadContent(Core core) + { + Texture = core.Content.Load("images/Monster"); + } + + public override void Update(GameTime gameTime) + { + base.Update(gameTime); + + float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f; + + if (nextNode == null) + nextNode = GetComponent().Next(); + + if (nextNode != null) + { + List soldierCollisions = new List(); + + foreach (var body in Swarm) + { + if (body != this) + { + if (body.Transform.Grid == nextNode.Position) + { + soldierCollisions.Add(body.Transform.Grid); + GetComponent().RecreatePath(soldierCollisions); + nextNode = GetComponent().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().Next(); + } + + } + + /**/ + } + } +} \ No newline at end of file diff --git a/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj b/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj index 3a6f708..a009837 100644 --- a/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj +++ b/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj @@ -1,110 +1,117 @@ - - - - {433A77A2-DE52-4875-A4EF-232CF59C2DD3} - {96E2B04D-8817-42c6-938A-82C39BA4D311};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Debug - x86 - Library - Properties - v4.0 - v4.0 - bin\$(Platform)\$(Configuration) - Content - - - x86 - - - x86 - - - DepthsBelowContent - - - - False - - - False - - - False - - - False - - - False - - - False - - - - - soldier - TextureImporter - TextureProcessor - - - test - TmxImporter - MapProcessor - - - - - {EC3F6988-459C-4783-89E9-F34C0CC731C7} - TiledLib - - - {D054E3A6-7E05-4255-984F-69FE40D9137F} - DepthsBelowContentPipeline - - - - - aztek - TextureImporter - TextureProcessor - - - - - soldier2 - TextureImporter - TextureProcessor - - - - - collision - TextureImporter - TextureProcessor - - - - - Cave.Level1 - MapProcessor - TmxImporter - Designer - - - - - cave - TextureImporter - TextureProcessor - - - - + + + + {433A77A2-DE52-4875-A4EF-232CF59C2DD3} + {96E2B04D-8817-42c6-938A-82C39BA4D311};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Debug + x86 + Library + Properties + v4.0 + v4.0 + bin\$(Platform)\$(Configuration) + Content + + + x86 + + + x86 + + + DepthsBelowContent + + + + False + + + False + + + False + + + False + + + False + + + False + + + + + soldier + TextureImporter + TextureProcessor + + + test + TmxImporter + MapProcessor + + + + + {EC3F6988-459C-4783-89E9-F34C0CC731C7} + TiledLib + + + {D054E3A6-7E05-4255-984F-69FE40D9137F} + DepthsBelowContentPipeline + + + + + aztek + TextureImporter + TextureProcessor + + + + + soldier2 + TextureImporter + TextureProcessor + + + + + collision + TextureImporter + TextureProcessor + + + + + Cave.Level1 + MapProcessor + TmxImporter + Designer + + + + + cave + TextureImporter + TextureProcessor + + + + + Monster + TextureImporter + TextureProcessor + + + + \ No newline at end of file diff --git a/DepthsBelow/DepthsBelowContent/images/Monster.png b/DepthsBelow/DepthsBelowContent/images/Monster.png new file mode 100644 index 0000000000000000000000000000000000000000..371c75ffcc752c698d5d47eb10f7c4b36529b7bc GIT binary patch literal 4080 zcmVKLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpwUVxrVZ>QdQz32KIeJ}k~{cZZE^+ya? z2D1z#2HOnI7(B%_ac?{wFUQ;QQA1tBKtrWrm0_3Rgps+?Jfqb{jYbcQX~taRB;#$y zZN{S}1|}gUOHJxc?wV3fxuz+mJ4`!F$IZ;mqRrNsHJd##*D~ju=bP7?-?v~|cv>vB zsJ6IeNwVZxrdjT`yl#bBIa#GxRa#xMMy;K#CDyyGyQdMSxlWT#t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