From 275727f8610c648da89297f64dfba54507ffaf18 Mon Sep 17 00:00:00 2001 From: Niklas Ulf Anders Cullberg Date: Tue, 16 Oct 2012 17:27:35 +0200 Subject: [PATCH] Working on calculation of chance to hit --- DepthsBelow/DepthsBelow/Component/Shooting.cs | 5 ++ DepthsBelow/DepthsBelow/KeyboardInput.cs | 58 +++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/DepthsBelow/DepthsBelow/Component/Shooting.cs b/DepthsBelow/DepthsBelow/Component/Shooting.cs index 6ff6431..382d5ac 100644 --- a/DepthsBelow/DepthsBelow/Component/Shooting.cs +++ b/DepthsBelow/DepthsBelow/Component/Shooting.cs @@ -21,6 +21,11 @@ namespace DepthsBelow.Component } + public bool targetInSight() + { + return false; + } + public int CalculateChance() { int baseHitChance = soldierAim + weaponAccuracy; diff --git a/DepthsBelow/DepthsBelow/KeyboardInput.cs b/DepthsBelow/DepthsBelow/KeyboardInput.cs index 2d63887..c9dd67e 100644 --- a/DepthsBelow/DepthsBelow/KeyboardInput.cs +++ b/DepthsBelow/DepthsBelow/KeyboardInput.cs @@ -15,6 +15,7 @@ namespace DepthsBelow Core core; bool Enter = false; bool turn; + int checkerSpeed = 1; public KeyboardInput(Core core) { @@ -103,6 +104,63 @@ namespace DepthsBelow } } } + if (ks.IsKeyDown(Keys.C)) + { + foreach (var soldier in core.Squad) + { + if (soldier.Selected == true && soldier.Fired == false) + { + Point checker = Point.Zero; + double directionX = Math.Cos(soldier.GetComponent().World.Rotation); + double directionY = Math.Sin(soldier.GetComponent().World.Rotation); + Vector2 direction = new Vector2((int)directionX, (int)directionY); + int range = 120; + int current = 0; + bool hit = false; + checker = new Point((int)soldier.Transform.World.Origin.X, (int)soldier.Transform.World.Origin.Y); + do + { + checker.X += (int)direction.X * checkerSpeed; + checker.Y += (int)direction.Y * checkerSpeed; + foreach (var creature in core.Swarm) + { + if (creature.GetComponent().Rectangle.Contains(checker)) + { + hit = true; + } + } + if (core.TestMonster.GetComponent().Rectangle.Contains(checker)) + { + + } + current++; + } while (hit == false && current < range); + current = 0; + if (soldier.Selected == true && soldier.Fired == false && hit == true) + { + core.Volley.Add(new Shot(core)); + soldier.Fired = true; + foreach (var shot in core.Volley) + { + 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) + { + shot.direction = new Vector2((float)directionX, (float)directionY); + shot.Transform.World.Rotation = soldier.Transform.World.Rotation; + } + } + } + hit = false; + } + } + } } } } \ No newline at end of file