From 16f2d57aec74878ab97a2c9b508c83e3871ed640 Mon Sep 17 00:00:00 2001 From: Niklas Ulf Anders Cullberg Date: Tue, 16 Oct 2012 16:18:21 +0200 Subject: [PATCH] You can now fire selected units with S --- DepthsBelow/DepthsBelow/Core.cs | 3 + DepthsBelow/DepthsBelow/KeyboardInput.cs | 27 +- DepthsBelow/DepthsBelow/Shot.cs | 11 +- DepthsBelow/DepthsBelow/Soldier.cs | 293 +++++++++--------- .../DepthsBelowContent.contentproj | 9 +- .../DepthsBelowContent/images/FireBall.PNG | Bin 0 -> 1547 bytes .../images/{Shot.bmp => Shot2.bmp} | Bin 7 files changed, 193 insertions(+), 150 deletions(-) create mode 100644 DepthsBelow/DepthsBelowContent/images/FireBall.PNG rename DepthsBelow/DepthsBelowContent/images/{Shot.bmp => Shot2.bmp} (100%) diff --git a/DepthsBelow/DepthsBelow/Core.cs b/DepthsBelow/DepthsBelow/Core.cs index 72f58cf..8528748 100755 --- a/DepthsBelow/DepthsBelow/Core.cs +++ b/DepthsBelow/DepthsBelow/Core.cs @@ -127,6 +127,9 @@ namespace DepthsBelow foreach (var body in Swarm) body.Update(gameTime); + foreach (var bullet in Volley) + bullet.Update(gameTime); + TestMonster.Update(gameTime); GUIManager.Update(gameTime); diff --git a/DepthsBelow/DepthsBelow/KeyboardInput.cs b/DepthsBelow/DepthsBelow/KeyboardInput.cs index 6d2e15d..2d63887 100644 --- a/DepthsBelow/DepthsBelow/KeyboardInput.cs +++ b/DepthsBelow/DepthsBelow/KeyboardInput.cs @@ -39,6 +39,7 @@ namespace DepthsBelow foreach (var unit in core.Squad) { unit.step = 0; + unit.Fired = false; } } else @@ -77,15 +78,27 @@ namespace DepthsBelow { foreach (var soldier in core.Squad) { - core.Volley.Add(new Shot(core)); - foreach (var shot in core.Volley) + if (soldier.Selected == true && soldier.Fired == false) { - if (shot.direction == Vector2.Zero) + core.Volley.Add(new Shot(core)); + soldier.Fired = true; + foreach (var shot in core.Volley) { - double directionX = Math.Cos(soldier.GetComponent().World.Rotation); - double directionY = Math.Sin(soldier.GetComponent().World.Rotation); - shot.direction = new Vector2((float)directionX, (float)directionY); - + if (shot.select == false) + { + shot.select = true; + shot.X = soldier.X; + shot.Y = soldier.Y; + //shot.Transform.World.X += Grid.TileSize / 2; + //shot.Transform.World.Y += Grid.TileSize / 2; + } + if (shot.direction == Vector2.Zero) + { + double directionX = Math.Cos(soldier.GetComponent().World.Rotation); + double directionY = Math.Sin(soldier.GetComponent().World.Rotation); + shot.direction = new Vector2((float)directionX, (float)directionY); + shot.Transform.World.Rotation = soldier.Transform.World.Rotation; + } } } } diff --git a/DepthsBelow/DepthsBelow/Shot.cs b/DepthsBelow/DepthsBelow/Shot.cs index edd0908..c9878b4 100644 --- a/DepthsBelow/DepthsBelow/Shot.cs +++ b/DepthsBelow/DepthsBelow/Shot.cs @@ -13,7 +13,16 @@ namespace DepthsBelow public Color Color; public static Point Origin; - private bool _selected; //I guess as in "currently doing something" + private bool _selected = false; //I guess as in "currently doing something" + + public bool select + { + get { return _selected; } + set + { + _selected = value; + } + } public List Volley; diff --git a/DepthsBelow/DepthsBelow/Soldier.cs b/DepthsBelow/DepthsBelow/Soldier.cs index 3c5a4c4..074e002 100644 --- a/DepthsBelow/DepthsBelow/Soldier.cs +++ b/DepthsBelow/DepthsBelow/Soldier.cs @@ -1,142 +1,153 @@ -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 Soldier : Entity - { - public static Texture2D Texture; - public Color Color; - public static Point Origin; - private bool _selected; - - public List Squad; - - private PathFinder.Node nextNode; - private PathFinder.Node lastNode; - private PathFinder.Node lastLastNode; - - public int numberOfSteps = 14; - public int currentStep = 0; - - public int step - { - get { return currentStep; } - set - { - currentStep = value; - } - } - - public Soldier(Core core, ref List squad) : base(core) - { - if (Texture == null) - LoadContent(core); - - this.Squad = squad; - - 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/soldier2"); - } - - 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 soldier in Squad) - { - if (soldier != this && !soldier.GetComponent().IsMoving) - { - soldierCollisions.Add(soldier.Transform.Grid); - } - } - - foreach (var soldier in Squad) - { - if (soldier != this) - { - var pathFinder = soldier.GetComponent(); - var position = nextNode.Position; - if (soldier.Transform.Grid == position) - { - soldierCollisions.Add(soldier.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) - { - if (currentStep < numberOfSteps) - { - currentStep++; - lastLastNode = lastNode; - lastNode = nextNode; - nextNode = GetComponent().Next(); - } - else - { - GetComponent().Stop(); - } - } - } - - } - - /**/ - } - } +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 Soldier : Entity + { + public static Texture2D Texture; + public Color Color; + public static Point Origin; + private bool _selected; + + public List Squad; + + private PathFinder.Node nextNode; + private PathFinder.Node lastNode; + private PathFinder.Node lastLastNode; + + private bool hasFiredAlready = false; + + public bool Fired + { + get { return hasFiredAlready; } + set + { + hasFiredAlready = value; + } + } + + public int numberOfSteps = 14; + public int currentStep = 0; + + public int step + { + get { return currentStep; } + set + { + currentStep = value; + } + } + + public Soldier(Core core, ref List squad) : base(core) + { + if (Texture == null) + LoadContent(core); + + this.Squad = squad; + + 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/soldier2"); + } + + 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 soldier in Squad) + { + if (soldier != this && !soldier.GetComponent().IsMoving) + { + soldierCollisions.Add(soldier.Transform.Grid); + } + } + + foreach (var soldier in Squad) + { + if (soldier != this) + { + var pathFinder = soldier.GetComponent(); + var position = nextNode.Position; + if (soldier.Transform.Grid == position) + { + soldierCollisions.Add(soldier.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) + { + if (currentStep < numberOfSteps) + { + currentStep++; + lastLastNode = lastNode; + lastNode = nextNode; + nextNode = GetComponent().Next(); + } + else + { + GetComponent().Stop(); + } + } + } + + } + + /**/ + } + } } \ No newline at end of file diff --git a/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj b/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj index d879969..c678761 100644 --- a/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj +++ b/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj @@ -121,7 +121,14 @@ - + + Shot2 + TextureImporter + TextureProcessor + + + + Shot TextureImporter TextureProcessor diff --git a/DepthsBelow/DepthsBelowContent/images/FireBall.PNG b/DepthsBelow/DepthsBelowContent/images/FireBall.PNG new file mode 100644 index 0000000000000000000000000000000000000000..373ec4e5114ff117e40c8752ee3ad1c1d7a6b244 GIT binary patch literal 1547 zcmV+m2K4!fP)6$+-jKB#3CW5z&U60dWHK zAp~ugU9K+M@4Z=eutt6!|5SBXw}1HK=iSe{v!Cy8{w!TyrhcE^mCp~~%I~+If9&S? z{?Nz%-MW1GFa}2L)sr#wuYb4mY%vCbWqEjZ|IhPMZg1{y?@K{T`K%@C(PG7>x;@zN^q0PT(T@(JiH-M!a23<9bdTB{k`mJw^w-W-C;v!_EC1?$I-ShUncr2>nYqeImv zW{&zXnMNRK2Kca2g|6VJpQtRw&?2WwKRUD+sFRf0Ff9Uu&{6+Ve|HWs|JN6#9LL5T zrBdjsdAiljv;|X-;30#~cDSx$g6#_?A_Mxs8pXT;8Ze&}(AfFmgunn)7t@e!magE8 zEwsG8sMnuqB{sn>|3pmInuVfif_`z+E8`4>5dXg>DP?KzF062(Ew= zmab?qPz)1YI~u58)vQrC&{w^t2m$m=;PulI(;#4pzey#QtE-Q|Gj(;h%p4j41baYf z(OhS23WhYhIW-lIJgB&dUN8lR7BEbpgotkOTb!0MtdbFjKvb6rh)8P*B0C-sK1w>QzMZUa3F ztYaU1iDG=p@e7DaAS!?&DJU#Kpy_NU z!JW20>gTZpVj!6ucmQPD!47c20fX5BEs;!xyC4vKNIN=TSHJ3tXT&Q6_`WbW=!uPD z5GUYVZChA6EpwC+I8{G7>4S;l?XLjIF@P zj5wYH%g#bT4@dou2WA3Qx93?1wzTtUJJ>M*G$gPRozSl@Z3ue)2MJvvz^Aq4k#2D` zpngc89!@k%q^mkTpd1id$3KQ15~^Np9^g5Y@t`L6>p{2iGAYGWEu~hCwt~8b!R!Z4 zyWECjtoRLgYh238Khp_Z!AGT7I9(5xy4NHNY3Y)c38d)vESOW~Y~6H~7_O?rdzleX zluH6vIRtJi9X-wDNhvFeWLi?*qfZ_{*x?;dg8?ll&;~yjd%Hrf;$A0WItNif>+&51EbNNSh6b8vkjPln=!1)aRLZ~BHS3z z#may#hUbj5O@H>{?rVn#y9_Nh#40T=I_dyT^ict@j=|nZY!A6UsSDiu9syeAOgx=F}^>K`09FUVkF9#_fmdZnwv6O83fp^ltCOYOvj#7ckLLn!Dyz=OgWLFq~f2k33)xM9YKf xG2DaYT|d_>y_@j-Rl*FsoM_4Lq6vSq+b`9ik+vT{;fw$P002ovPDHLkV1j(T%dr3e literal 0 HcmV?d00001 diff --git a/DepthsBelow/DepthsBelowContent/images/Shot.bmp b/DepthsBelow/DepthsBelowContent/images/Shot2.bmp similarity index 100% rename from DepthsBelow/DepthsBelowContent/images/Shot.bmp rename to DepthsBelow/DepthsBelowContent/images/Shot2.bmp