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.Linq;
using System.Text;
using Microsoft.Xna.Framework;
namespace DepthsBelow.Component
{
@@ -41,6 +42,14 @@ namespace DepthsBelow.Component
protected int penaltyRange = 5;
Vector2 rememberedPosition = Vector2.Zero;
public Vector2 Remember
{
get { return rememberedPosition; }
set { rememberedPosition = value; }
}
public int GetAim
{
get { return soldierAim + weaponAccuracy; }
@@ -84,6 +93,7 @@ namespace DepthsBelow.Component
public void Kill()
{
hp = 0;
Parent.Remove();
//Console.WriteLine("Blargh! I am dead!");
}
@@ -95,7 +105,7 @@ namespace DepthsBelow.Component
public Stat(Entity parent)
: base (parent)
{
rememberedPosition = Vector2.Zero;
}
public bool targetInSight()
+1 -1
View File
@@ -118,7 +118,7 @@ namespace DepthsBelow
// TODO: use this.Content to load your game content here
Soldier.LoadContent();
SmallEnemy.LoadContent();
Shot.LoadContent();
//Shot.LoadContent();
MouseInput = new MouseInput(this);
MouseInput.LoadContent();
+6 -4
View File
@@ -211,7 +211,7 @@ namespace DepthsBelow
{
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;
foreach (var shot in core.Volley)
{
@@ -225,10 +225,12 @@ namespace DepthsBelow
}
if (shot.direction == Vector2.Zero)
{
double directionX = Math.Cos(soldier.GetComponent<Component.Transform>().World.Rotation);
double directionY = Math.Sin(soldier.GetComponent<Component.Transform>().World.Rotation);
double directionX = Math.Cos(soldier.Transform.World.Rotation);
double directionY = Math.Sin(soldier.Transform.World.Rotation);
shot.direction = new Vector2((float)directionX, (float)directionY);
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;
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;
foreach (var shot in core.Volley)
{
+1 -1
View File
@@ -236,7 +236,7 @@ namespace DepthsBelow
{
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 Color Color;
public static Point Origin;
string type = "";
Stat soldierStat;
@@ -37,7 +38,7 @@ namespace DepthsBelow
public Vector2 direction = Vector2.Zero;
public Shot(EntityManager entityManager, Stat _soldierStat)
public Shot(EntityManager entityManager, Stat _soldierStat, string _type)
: base(entityManager)
{
if (Texture == null)
@@ -46,6 +47,7 @@ namespace DepthsBelow
Transform.World.Origin = new Vector2(16, 16);
Stat = _soldierStat;
type = _type;
this.Color = Color.White;
var rc = new SpriteRenderer(this) { Texture = Texture, Color = Color.White };
@@ -55,10 +57,17 @@ namespace DepthsBelow
AddComponent(cc);
}
public static void LoadContent()
public void LoadContent()
{
if (type == "Rocket")
{
Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/Shot");
}
else
{
Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/Shot3");
}
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
@@ -76,7 +85,11 @@ namespace DepthsBelow
{
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)
{
Life = 2,
Defence = 0,
Defence = 2,
Strength = 5000,
GetAim = 100,
GetDodge = 50
@@ -141,6 +141,18 @@ namespace DepthsBelow
}
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();
}
}
+1 -1
View File
@@ -77,7 +77,7 @@ namespace DepthsBelow
MaxPanic = 100,
//Life = 10,
Defence = 10,
Strength = 10,
Strength = 50,
GetAim = 40,
GetDodge = 20
};
+5 -5
View File
@@ -19,9 +19,9 @@ namespace DepthsBelow
/// <param name="attacker">The attacking unit.</param>
/// <param name="defender">The recieving unit.</param>
/// <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>();
if (shooting == null || dodging == null)
{
@@ -29,16 +29,16 @@ namespace DepthsBelow
}
int baseHitChance = shooting.GetAim;
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));
Console.WriteLine("Penalty = " + basePenalty);
int chanceToHit = baseHitChance - baseDodgeChance - basePenalty;
//Console.WriteLine(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>();
Random rand = new Random();
if (rand.Next(0, 100) < chanceToHit)
@@ -231,6 +231,13 @@
<Processor>TextureProcessor</Processor>
</Compile>
</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" />
<!-- 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.
Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B