From 6034dbf3b2b1572b8f2e5960ebb48c63a161f06d Mon Sep 17 00:00:00 2001 From: Niklas Ulf Anders Cullberg Date: Sat, 20 Oct 2012 11:56:06 +0200 Subject: [PATCH 1/3] Inserted calculation if hover over enemy Though text is not displayed, only the calculation is done. --- DepthsBelow/DepthsBelow/MouseInput.cs | 452 +++++++++++++------------- 1 file changed, 233 insertions(+), 219 deletions(-) diff --git a/DepthsBelow/DepthsBelow/MouseInput.cs b/DepthsBelow/DepthsBelow/MouseInput.cs index 553eab5..e784028 100755 --- a/DepthsBelow/DepthsBelow/MouseInput.cs +++ b/DepthsBelow/DepthsBelow/MouseInput.cs @@ -1,219 +1,233 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -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 OnClick(MouseState ms, GameTime gameTime) - { - GUIManager.Click(new Point(ms.X, ms.Y), gameTime.TotalGameTime); - } - - public void Update(GameTime gameTime) - { - MouseState ms = Mouse.GetState(); - Vector2 mouseWorldPos = core.Camera.ScreenToWorld(new Vector2(ms.X, ms.Y)); - Rectangle mouseWorldRectangle = new Rectangle((int)mouseWorldPos.X, (int)mouseWorldPos.Y, 1, 1); - KeyboardState ks = Keyboard.GetState(); - - // OnClick event - if ( - (ms.LeftButton == ButtonState.Released && lastMouseState.LeftButton == ButtonState.Pressed) - || (ms.RightButton == ButtonState.Released && lastMouseState.RightButton == ButtonState.Pressed) - ) - OnClick(ms, gameTime); - - - // Tooltip stuff - var tooltip = core.Lua.GetObject("ToolTip"); - if (tooltip != null) - { - tooltip.Visible = false; - foreach(var entity in core.Squad) - { - if (mouseWorldRectangle.Intersects(entity.GetComponent().Rectangle)) - { - tooltip.Visible = true; - break; - } - } - - if (tooltip.Visible) - { - tooltip.X = ms.X + 10; - tooltip.Y = ms.Y + 15; - } - } - - if (core.TurnManager.CurrentTurn == core.TurnManager["Player"]) - { - // 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) - { - if (checkingDirection == false) - { - 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 - unit.Transform.World.Origin.Y, mouseWorldPos.X - unit.Transform.World.X - unit.Transform.World.Origin.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) - { - Utility.DrawLine(spriteBatch, Color.White, 2, directionStart, directionNow); - } - - } - - } -} +using System; +using System.Collections.Generic; +using System.Diagnostics; +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 OnClick(MouseState ms, GameTime gameTime) + { + GUIManager.Click(new Point(ms.X, ms.Y), gameTime.TotalGameTime); + } + + public void Update(GameTime gameTime) + { + MouseState ms = Mouse.GetState(); + Vector2 mouseWorldPos = core.Camera.ScreenToWorld(new Vector2(ms.X, ms.Y)); + Rectangle mouseWorldRectangle = new Rectangle((int)mouseWorldPos.X, (int)mouseWorldPos.Y, 1, 1); + KeyboardState ks = Keyboard.GetState(); + + // OnClick event + if ( + (ms.LeftButton == ButtonState.Released && lastMouseState.LeftButton == ButtonState.Pressed) + || (ms.RightButton == ButtonState.Released && lastMouseState.RightButton == ButtonState.Pressed) + ) + OnClick(ms, gameTime); + + + // Tooltip stuff + var tooltip = core.Lua.GetObject("ToolTip"); + if (tooltip != null) + { + tooltip.Visible = false; + foreach(var entity in core.Squad) + { + if (mouseWorldRectangle.Intersects(entity.GetComponent().Rectangle)) + { + tooltip.Visible = true; + break; + } + } + + if (tooltip.Visible) + { + tooltip.X = ms.X + 10; + tooltip.Y = ms.Y + 15; + } + } + + if (core.TurnManager.CurrentTurn == core.TurnManager["Player"]) + { + // 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; + } + } + //Calculating chance to hit if holding cursor over enemy + foreach (var unit in core.Squad) + { + if (unit.Selected == true && unit.Fired == false) + { + foreach (var enemy in core.Swarm) + { + if (gridRectangle.Intersects(enemy.GetComponent().Rectangle)) + { + Utility.CalculateHitChance(unit, enemy); + } + } + } + } + } + // 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) + { + if (checkingDirection == false) + { + 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 - unit.Transform.World.Origin.Y, mouseWorldPos.X - unit.Transform.World.X - unit.Transform.World.Origin.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) + { + Utility.DrawLine(spriteBatch, Color.White, 2, directionStart, directionNow); + } + + } + + } +} From 2fe63f51c05a84ca2b82925e9fa1ef584441c270 Mon Sep 17 00:00:00 2001 From: Niklas Ulf Anders Cullberg Date: Sat, 20 Oct 2012 13:01:57 +0200 Subject: [PATCH 2/3] Shooting calculation displayed, needs work --- DepthsBelow/DepthsBelow/Component/Stat.cs | 2 +- DepthsBelow/DepthsBelow/KeyboardInput.cs | 34 ++++++------ DepthsBelow/DepthsBelow/MouseInput.cs | 17 +++--- DepthsBelow/DepthsBelow/Shot.cs | 18 +++++-- DepthsBelow/DepthsBelow/Utility.cs | 64 ++++++++++++----------- 5 files changed, 74 insertions(+), 61 deletions(-) diff --git a/DepthsBelow/DepthsBelow/Component/Stat.cs b/DepthsBelow/DepthsBelow/Component/Stat.cs index dc1afa3..278cbc4 100644 --- a/DepthsBelow/DepthsBelow/Component/Stat.cs +++ b/DepthsBelow/DepthsBelow/Component/Stat.cs @@ -23,7 +23,7 @@ namespace DepthsBelow.Component public int GetAim { get { return soldierAim + weaponAccuracy; } - set { soldierAim = value; } + set { weaponAccuracy = value; } } public int GetDodge diff --git a/DepthsBelow/DepthsBelow/KeyboardInput.cs b/DepthsBelow/DepthsBelow/KeyboardInput.cs index 02818da..dc0cab3 100644 --- a/DepthsBelow/DepthsBelow/KeyboardInput.cs +++ b/DepthsBelow/DepthsBelow/KeyboardInput.cs @@ -12,7 +12,7 @@ namespace DepthsBelow { public class KeyboardInput { - Core core; + Core core; private KeyboardState lastKeyboardState; int checkerSpeed = 2; @@ -20,29 +20,29 @@ namespace DepthsBelow public KeyboardInput(Core core) { this.core = core; - } - + } + public void Update(GameTime gameTime) { KeyboardState ks = Keyboard.GetState(); - // Lua reload scripts - if (ks.IsKeyUp(Keys.R) && lastKeyboardState.IsKeyDown(Keys.R)) - { - core.Lua.Reload(); + // Lua reload scripts + if (ks.IsKeyUp(Keys.R) && lastKeyboardState.IsKeyDown(Keys.R)) + { + core.Lua.Reload(); } // Next turn if (ks.IsKeyDown(Keys.Enter) && lastKeyboardState.IsKeyUp(Keys.Enter)) - { + { if (core.TurnManager.CurrentTurn == core.TurnManager["Player"]) { foreach (var unit in core.Squad) { unit.step = 0; unit.Fired = false; - } - + } + core.TurnManager.EndTurn(); } @@ -65,8 +65,8 @@ namespace DepthsBelow } } core.TestMonster.GetComponent().Goal = target; - distance = 7000; - + distance = 7000; + core.TurnManager.EndTurn(); } } @@ -86,7 +86,7 @@ namespace DepthsBelow { if (soldier.Selected == true && soldier.Fired == false) { - core.Volley.Add(new Shot(core.EntityManager)); + core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent())); soldier.Fired = true; foreach (var shot in core.Volley) { @@ -143,7 +143,7 @@ namespace DepthsBelow current = 0; if (soldier.Selected == true && soldier.Fired == false && hit == true) { - core.Volley.Add(new Shot(core.EntityManager)); + core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent())); soldier.Fired = true; foreach (var shot in core.Volley) { @@ -165,9 +165,9 @@ namespace DepthsBelow hit = false; } } - } - - lastKeyboardState = ks; + } + + lastKeyboardState = ks; } } } \ No newline at end of file diff --git a/DepthsBelow/DepthsBelow/MouseInput.cs b/DepthsBelow/DepthsBelow/MouseInput.cs index e784028..6640ede 100755 --- a/DepthsBelow/DepthsBelow/MouseInput.cs +++ b/DepthsBelow/DepthsBelow/MouseInput.cs @@ -118,21 +118,22 @@ namespace DepthsBelow readjust = false; } } - //Calculating chance to hit if holding cursor over enemy - foreach (var unit in core.Squad) + } + //Calculating chance to hit if holding cursor over enemy + foreach (var unit in core.Squad) + { + if (unit.Selected == true && unit.Fired == false) { - if (unit.Selected == true && unit.Fired == false) + foreach (var enemy in core.Swarm) { - foreach (var enemy in core.Swarm) + if (gridRectangle.Intersects(enemy.GetComponent().Rectangle)) { - if (gridRectangle.Intersects(enemy.GetComponent().Rectangle)) - { - Utility.CalculateHitChance(unit, enemy); - } + Console.WriteLine(Utility.CalculateHitChance(unit, enemy)); } } } } + // When the mouse is released if (ms.LeftButton == ButtonState.Released && selectionRectangle != Rectangle.Empty) { diff --git a/DepthsBelow/DepthsBelow/Shot.cs b/DepthsBelow/DepthsBelow/Shot.cs index 8f2e229..f8ce89e 100644 --- a/DepthsBelow/DepthsBelow/Shot.cs +++ b/DepthsBelow/DepthsBelow/Shot.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; using DepthsBelow.Component; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; @@ -14,6 +14,14 @@ namespace DepthsBelow public Color Color; public static Point Origin; + Stat soldierStat; + + public Stat Stat + { + get { return soldierStat; } + set { soldierStat = value; } + } + private bool _selected = false; //I guess as in "currently doing something" public bool select @@ -29,7 +37,7 @@ namespace DepthsBelow public Vector2 direction = Vector2.Zero; - public Shot(EntityManager entityManager) + public Shot(EntityManager entityManager, Stat _soldierStat) : base(entityManager) { if (Texture == null) @@ -37,6 +45,8 @@ namespace DepthsBelow Transform.World.Origin = new Vector2(16, 16); + Stat = _soldierStat; + this.Color = Color.White; var rc = new SpriteRenderer(this) { Texture = Texture, Color = Color.White }; AddComponent(rc); @@ -46,7 +56,7 @@ namespace DepthsBelow } public static void LoadContent() - { + { Texture = GameServices.GetService().Load("images/Shot"); } public override void Update(GameTime gameTime) diff --git a/DepthsBelow/DepthsBelow/Utility.cs b/DepthsBelow/DepthsBelow/Utility.cs index 56cb736..3cce561 100644 --- a/DepthsBelow/DepthsBelow/Utility.cs +++ b/DepthsBelow/DepthsBelow/Utility.cs @@ -1,23 +1,23 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using DepthsBelow.Component; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - +using System.Text; +using DepthsBelow.Component; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + namespace DepthsBelow { - /// - /// Various global utility functions. + /// + /// Various global utility functions. /// static class Utility { - /// - /// Calculate the chance of an entity with a Stat component to hit another unit. - /// - /// The attacking unit. - /// The recieving unit. + /// + /// Calculate the chance of an entity with a Stat component to hit another unit. + /// + /// The attacking unit. + /// The recieving unit. /// Returns a hit chance percentage. public static int CalculateHitChance(Entity attacker, Entity defender) { @@ -29,7 +29,9 @@ namespace DepthsBelow } int baseHitChance = shooting.GetAim; int baseDodgeChance = dodging.GetDodge; - int basePenalty = shooting.Penalty((int)Vector2.Distance(attacker.GetComponent().World.Position, defender.GetComponent().World.Position) / Grid.TileSize); + int distance = (int)Vector2.Distance(attacker.GetComponent().World.Position, defender.GetComponent().World.Position); + int basePenalty = shooting.Penalty(distance / (Grid.TileSize / 2)); + Console.WriteLine("Penalty = " + basePenalty); int chanceToHit = baseHitChance - baseDodgeChance - basePenalty; //Console.WriteLine(chanceToHit); return chanceToHit; @@ -45,23 +47,23 @@ namespace DepthsBelow return true; } return false; - }*/ - private static Texture2D blank; - - public static void DrawLine(SpriteBatch batch, Color color, float width, Vector2 start, Vector2 end) - { - if (blank == null) - { - blank = new Texture2D(Core.GraphicsDeviceManager.GraphicsDevice, 1, 1, false, SurfaceFormat.Color); - blank.SetData(new[] { color }); - } - - float angle = (float)Math.Atan2(end.Y - start.Y, end.X - start.X); - float length = Vector2.Distance(start, end); - - batch.Draw(blank, start, null, color, - angle, Vector2.Zero, new Vector2(length, width), - SpriteEffects.None, 0); - } + }*/ + private static Texture2D blank; + + public static void DrawLine(SpriteBatch batch, Color color, float width, Vector2 start, Vector2 end) + { + if (blank == null) + { + blank = new Texture2D(Core.GraphicsDeviceManager.GraphicsDevice, 1, 1, false, SurfaceFormat.Color); + blank.SetData(new[] { color }); + } + + float angle = (float)Math.Atan2(end.Y - start.Y, end.X - start.X); + float length = Vector2.Distance(start, end); + + batch.Draw(blank, start, null, color, + angle, Vector2.Zero, new Vector2(length, width), + SpriteEffects.None, 0); + } } } From 6f6ee2d340213e7f1a731519206999964bfec2e3 Mon Sep 17 00:00:00 2001 From: Niklas Ulf Anders Cullberg Date: Sat, 20 Oct 2012 17:31:26 +0200 Subject: [PATCH 3/3] Steps taken and distance taken into account --- DepthsBelow/DepthsBelow/Component/Stat.cs | 9 +++++- DepthsBelow/DepthsBelow/Soldier.cs | 37 ++++++++++++----------- DepthsBelow/DepthsBelow/Utility.cs | 2 +- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/DepthsBelow/DepthsBelow/Component/Stat.cs b/DepthsBelow/DepthsBelow/Component/Stat.cs index 278cbc4..de40c82 100644 --- a/DepthsBelow/DepthsBelow/Component/Stat.cs +++ b/DepthsBelow/DepthsBelow/Component/Stat.cs @@ -26,6 +26,12 @@ namespace DepthsBelow.Component set { weaponAccuracy = value; } } + public int GetStep + { + get { return stepsTaken; } + set { stepsTaken = value; } + } + public int GetDodge { get { return enemyDodge; } @@ -80,7 +86,8 @@ namespace DepthsBelow.Component int penalty = 0; if (distance >= penaltyRange * 3) { - penalty = 100; + distance -= penaltyRange * 3; + penalty = penaltyRange + penaltyRange * 3 + penaltyRange * 5 + distance * 10; } else if (distance >= penaltyRange * 2) { diff --git a/DepthsBelow/DepthsBelow/Soldier.cs b/DepthsBelow/DepthsBelow/Soldier.cs index 21e9a96..81661b1 100644 --- a/DepthsBelow/DepthsBelow/Soldier.cs +++ b/DepthsBelow/DepthsBelow/Soldier.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; using DepthsBelow.Component; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; @@ -33,7 +33,7 @@ namespace DepthsBelow } public int numberOfSteps = 14; - public int currentStep = 0; + int currentStep = 0; public int step { @@ -41,10 +41,11 @@ namespace DepthsBelow set { currentStep = value; + GetComponent().GetStep = currentStep; } - } - - public Soldier(EntityManager entityManager, ref List squad) + } + + public Soldier(EntityManager entityManager, ref List squad) : base(entityManager) { if (Texture == null) @@ -62,16 +63,16 @@ namespace DepthsBelow AddComponent(cc); var pfc = new PathFinder(this); - AddComponent(pfc); - - var stat = new Component.Stat(this) - { - Life = 10, - Defence = 10, - Strength = 10, - GetAim = 10, - GetDodge = 20 - }; + AddComponent(pfc); + + var stat = new Component.Stat(this) + { + Life = 10, + Defence = 10, + Strength = 10, + GetAim = 40, + GetDodge = 20 + }; AddComponent(stat); } @@ -145,9 +146,9 @@ namespace DepthsBelow if (Transform.World == nodeWorldPos) { - if (currentStep < numberOfSteps) + if (step < numberOfSteps) { - currentStep++; + step++; lastLastNode = lastNode; lastNode = nextNode; nextNode = GetComponent().Next(); diff --git a/DepthsBelow/DepthsBelow/Utility.cs b/DepthsBelow/DepthsBelow/Utility.cs index 3cce561..4d7d54e 100644 --- a/DepthsBelow/DepthsBelow/Utility.cs +++ b/DepthsBelow/DepthsBelow/Utility.cs @@ -30,7 +30,7 @@ namespace DepthsBelow int baseHitChance = shooting.GetAim; int baseDodgeChance = dodging.GetDodge; int distance = (int)Vector2.Distance(attacker.GetComponent().World.Position, defender.GetComponent().World.Position); - int basePenalty = shooting.Penalty(distance / (Grid.TileSize / 2)); + int basePenalty = shooting.Penalty(distance / (Grid.TileSize)); Console.WriteLine("Penalty = " + basePenalty); int chanceToHit = baseHitChance - baseDodgeChance - basePenalty; //Console.WriteLine(chanceToHit);