The hell. Vi kan skjuta med S.

This commit is contained in:
Niklas Ulf Anders Cullberg
2012-10-29 00:51:14 +01:00
parent 4a60e4e2d5
commit 9a0ff658b4
10 changed files with 464 additions and 420 deletions
+11 -1
View File
@@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Microsoft.Xna.Framework;
namespace DepthsBelow.Component namespace DepthsBelow.Component
{ {
@@ -41,6 +42,14 @@ namespace DepthsBelow.Component
protected int penaltyRange = 5; protected int penaltyRange = 5;
Vector2 rememberedPosition = Vector2.Zero;
public Vector2 Remember
{
get { return rememberedPosition; }
set { rememberedPosition = value; }
}
public int GetAim public int GetAim
{ {
get { return soldierAim + weaponAccuracy; } get { return soldierAim + weaponAccuracy; }
@@ -84,6 +93,7 @@ namespace DepthsBelow.Component
public void Kill() public void Kill()
{ {
hp = 0; hp = 0;
Parent.Remove();
//Console.WriteLine("Blargh! I am dead!"); //Console.WriteLine("Blargh! I am dead!");
} }
@@ -95,7 +105,7 @@ namespace DepthsBelow.Component
public Stat(Entity parent) public Stat(Entity parent)
: base (parent) : base (parent)
{ {
rememberedPosition = Vector2.Zero;
} }
public bool targetInSight() public bool targetInSight()
+1 -1
View File
@@ -118,7 +118,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(); Soldier.LoadContent();
SmallEnemy.LoadContent(); SmallEnemy.LoadContent();
Shot.LoadContent(); //Shot.LoadContent();
MouseInput = new MouseInput(this); MouseInput = new MouseInput(this);
MouseInput.LoadContent(); MouseInput.LoadContent();
+6 -4
View File
@@ -211,7 +211,7 @@ namespace DepthsBelow
{ {
if (soldier.Selected == true && soldier.Fired == false) if (soldier.Selected == true && soldier.Fired == false)
{ {
core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>())); core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>(), "Bullet"));
soldier.Fired = true; soldier.Fired = true;
foreach (var shot in core.Volley) foreach (var shot in core.Volley)
{ {
@@ -225,10 +225,12 @@ namespace DepthsBelow
} }
if (shot.direction == Vector2.Zero) if (shot.direction == Vector2.Zero)
{ {
double directionX = Math.Cos(soldier.GetComponent<Component.Transform>().World.Rotation); double directionX = Math.Cos(soldier.Transform.World.Rotation);
double directionY = Math.Sin(soldier.GetComponent<Component.Transform>().World.Rotation); double directionY = Math.Sin(soldier.Transform.World.Rotation);
shot.direction = new Vector2((float)directionX, (float)directionY); shot.direction = new Vector2((float)directionX, (float)directionY);
shot.Transform.World.Rotation = soldier.Transform.World.Rotation; shot.Transform.World.Rotation = soldier.Transform.World.Rotation;
Vector2 yo = soldier.Transform.World.Position;
shot.Stat.Remember = yo;
} }
} }
} }
@@ -268,7 +270,7 @@ namespace DepthsBelow
current = 0; current = 0;
if (soldier.Selected == true && soldier.Fired == false && hit == true) if (soldier.Selected == true && soldier.Fired == false && hit == true)
{ {
core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>())); core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>(), "Bullet"));
soldier.Fired = true; soldier.Fired = true;
foreach (var shot in core.Volley) foreach (var shot in core.Volley)
{ {
+1 -1
View File
@@ -236,7 +236,7 @@ namespace DepthsBelow
{ {
if (gridRectangle.Intersects(enemy.GetComponent<Component.Collision>().Rectangle)) if (gridRectangle.Intersects(enemy.GetComponent<Component.Collision>().Rectangle))
{ {
Console.WriteLine(Utility.CalculateHitChance(unit, enemy)); Console.WriteLine(Utility.CalculateHitChance(unit.GetComponent<Component.Stat>(), unit.GetComponent<Component.Transform>().World.Position, enemy));
} }
} }
} }
+16 -3
View File
@@ -13,6 +13,7 @@ namespace DepthsBelow
public static Texture2D Texture; public static Texture2D Texture;
public Color Color; public Color Color;
public static Point Origin; public static Point Origin;
string type = "";
Stat soldierStat; Stat soldierStat;
@@ -37,7 +38,7 @@ namespace DepthsBelow
public Vector2 direction = Vector2.Zero; public Vector2 direction = Vector2.Zero;
public Shot(EntityManager entityManager, Stat _soldierStat) public Shot(EntityManager entityManager, Stat _soldierStat, string _type)
: base(entityManager) : base(entityManager)
{ {
if (Texture == null) if (Texture == null)
@@ -46,6 +47,7 @@ namespace DepthsBelow
Transform.World.Origin = new Vector2(16, 16); Transform.World.Origin = new Vector2(16, 16);
Stat = _soldierStat; Stat = _soldierStat;
type = _type;
this.Color = Color.White; this.Color = Color.White;
var rc = new SpriteRenderer(this) { Texture = Texture, Color = Color.White }; var rc = new SpriteRenderer(this) { Texture = Texture, Color = Color.White };
@@ -55,10 +57,17 @@ namespace DepthsBelow
AddComponent(cc); AddComponent(cc);
} }
public static void LoadContent() public void LoadContent()
{
if (type == "Rocket")
{ {
Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/Shot"); Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/Shot");
} }
else
{
Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/Shot3");
}
}
public override void Update(GameTime gameTime) public override void Update(GameTime gameTime)
{ {
base.Update(gameTime); base.Update(gameTime);
@@ -76,7 +85,11 @@ namespace DepthsBelow
{ {
if (this.GetComponent<Component.Collision>().Rectangle.Intersects(entity.GetComponent<Component.Collision>().Rectangle)) if (this.GetComponent<Component.Collision>().Rectangle.Intersects(entity.GetComponent<Component.Collision>().Rectangle))
{ {
if (Utility.HitTest(Stat, entity, Utility.CalculateHitChance(Stat, this.Stat.Remember, entity)))
{
this.Remove();
return;
}
} }
} }
} }
+13 -1
View File
@@ -54,7 +54,7 @@ namespace DepthsBelow
var stat = new Component.Stat(this) var stat = new Component.Stat(this)
{ {
Life = 2, Life = 2,
Defence = 0, Defence = 2,
Strength = 5000, Strength = 5000,
GetAim = 100, GetAim = 100,
GetDodge = 50 GetDodge = 50
@@ -141,6 +141,18 @@ namespace DepthsBelow
} }
else else
{ {
foreach (var entity in entityManager.Entities) {
if (entity is Soldier)
{
if (entity.GetComponent<Component.Collision>().Rectangle.Intersects(this.GetComponent<Component.Collision>().Rectangle))
{
if (Utility.HitTest(this.GetComponent<Component.Stat>(), entity, Utility.CalculateHitChance(this.GetComponent<Component.Stat>(), this.Transform.World.Position, entity)))
{
return;
}
}
}
}
GetComponent<PathFinder>().Stop(); GetComponent<PathFinder>().Stop();
} }
} }
+1 -1
View File
@@ -77,7 +77,7 @@ namespace DepthsBelow
MaxPanic = 100, MaxPanic = 100,
//Life = 10, //Life = 10,
Defence = 10, Defence = 10,
Strength = 10, Strength = 50,
GetAim = 40, GetAim = 40,
GetDodge = 20 GetDodge = 20
}; };
+5 -5
View File
@@ -19,9 +19,9 @@ namespace DepthsBelow
/// <param name="attacker">The attacking unit.</param> /// <param name="attacker">The attacking unit.</param>
/// <param name="defender">The recieving unit.</param> /// <param name="defender">The recieving unit.</param>
/// <returns>Returns a hit chance percentage.</returns> /// <returns>Returns a hit chance percentage.</returns>
public static int CalculateHitChance(Entity attacker, Entity defender) public static int CalculateHitChance(Stat attacker, Vector2 attackerPosition, Entity defender)
{ {
Stat shooting = attacker.GetComponent<Stat>(); Stat shooting = attacker;
Stat dodging = defender.GetComponent<Stat>(); Stat dodging = defender.GetComponent<Stat>();
if (shooting == null || dodging == null) if (shooting == null || dodging == null)
{ {
@@ -29,16 +29,16 @@ namespace DepthsBelow
} }
int baseHitChance = shooting.GetAim; int baseHitChance = shooting.GetAim;
int baseDodgeChance = dodging.GetDodge; int baseDodgeChance = dodging.GetDodge;
int distance = (int)Vector2.Distance(attacker.GetComponent<Transform>().World.Position, defender.GetComponent<Transform>().World.Position); int distance = (int)Vector2.Distance(attackerPosition, defender.Transform.World.Position);
int basePenalty = shooting.Penalty(distance / (Grid.TileSize)); int basePenalty = shooting.Penalty(distance / (Grid.TileSize));
Console.WriteLine("Penalty = " + basePenalty); Console.WriteLine("Penalty = " + basePenalty);
int chanceToHit = baseHitChance - baseDodgeChance - basePenalty; int chanceToHit = baseHitChance - baseDodgeChance - basePenalty;
//Console.WriteLine(chanceToHit); //Console.WriteLine(chanceToHit);
return chanceToHit; return chanceToHit;
} }
public static bool HitTest(Entity attacker, Entity defender, int chanceToHit) public static bool HitTest(Stat attacker, Entity defender, int chanceToHit)
{ {
Component.Stat shooting = attacker.GetComponent<Component.Stat>(); Component.Stat shooting = attacker;
Component.Stat dodging = defender.GetComponent<Component.Stat>(); Component.Stat dodging = defender.GetComponent<Component.Stat>();
Random rand = new Random(); Random rand = new Random();
if (rand.Next(0, 100) < chanceToHit) if (rand.Next(0, 100) < chanceToHit)
@@ -231,6 +231,13 @@
<Processor>TextureProcessor</Processor> <Processor>TextureProcessor</Processor>
</Compile> </Compile>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Compile Include="images\Shot3.bmp">
<Name>Shot3</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: 142 B