Shot and Shooting Classes added (not working yet)
This commit is contained in:
@@ -0,0 +1,57 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace DepthsBelow.Component
|
||||||
|
{
|
||||||
|
class Shooting : Component
|
||||||
|
{
|
||||||
|
protected int stepsTaken = 0;
|
||||||
|
protected int distanceToTarget = 0;
|
||||||
|
protected int panic = 0;
|
||||||
|
protected int soldierAim = 0;
|
||||||
|
protected int weaponAccuracy = 0;
|
||||||
|
protected int enemyDodge = 0;
|
||||||
|
|
||||||
|
protected int penaltyRange = 5;
|
||||||
|
|
||||||
|
public Shooting(Entity parent) : base (parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int CalculateChance()
|
||||||
|
{
|
||||||
|
int baseHitChance = soldierAim + weaponAccuracy;
|
||||||
|
int baseDodgeChance = panic + enemyDodge;
|
||||||
|
int basePenalty = ReturnPenalty(stepsTaken) + (int)(ReturnPenalty(distanceToTarget) / 2);
|
||||||
|
int chanceToHit = baseHitChance - baseDodgeChance - basePenalty;
|
||||||
|
return chanceToHit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ReturnPenalty(int distance)
|
||||||
|
{
|
||||||
|
int penalty = 0;
|
||||||
|
if (distance >= penaltyRange * 3)
|
||||||
|
{
|
||||||
|
penalty = 100;
|
||||||
|
}
|
||||||
|
else if (distance >= penaltyRange * 2)
|
||||||
|
{
|
||||||
|
distance -= penaltyRange * 2;
|
||||||
|
penalty = penaltyRange + penaltyRange * 3 + distance * 5;
|
||||||
|
}
|
||||||
|
else if (distance >= penaltyRange)
|
||||||
|
{
|
||||||
|
distance -= penaltyRange;
|
||||||
|
penalty = penaltyRange + distance * 3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
penalty = distance;
|
||||||
|
}
|
||||||
|
return penalty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,6 +28,7 @@ namespace DepthsBelow
|
|||||||
public static KeyboardInput KeyboardInput;
|
public static KeyboardInput KeyboardInput;
|
||||||
public List<Soldier> Squad;
|
public List<Soldier> Squad;
|
||||||
public List<SmallEnemy> Swarm;
|
public List<SmallEnemy> Swarm;
|
||||||
|
public List<Shot> Volley;
|
||||||
public static Map Map;
|
public static Map Map;
|
||||||
|
|
||||||
public SmallEnemy TestMonster;
|
public SmallEnemy TestMonster;
|
||||||
@@ -60,6 +61,7 @@ namespace DepthsBelow
|
|||||||
Camera = new Camera(this);
|
Camera = new Camera(this);
|
||||||
Squad = new List<Soldier>();
|
Squad = new List<Soldier>();
|
||||||
Swarm = new List<SmallEnemy>();
|
Swarm = new List<SmallEnemy>();
|
||||||
|
Volley = new List<Shot>();
|
||||||
|
|
||||||
TestMonster = new SmallEnemy(this, ref Swarm);
|
TestMonster = new SmallEnemy(this, ref Swarm);
|
||||||
|
|
||||||
@@ -82,6 +84,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(this);
|
Soldier.LoadContent(this);
|
||||||
SmallEnemy.LoadContent(this);
|
SmallEnemy.LoadContent(this);
|
||||||
|
Shot.LoadContent(this);
|
||||||
|
|
||||||
MouseInput = new MouseInput(this);
|
MouseInput = new MouseInput(this);
|
||||||
MouseInput.LoadContent();
|
MouseInput.LoadContent();
|
||||||
@@ -183,6 +186,12 @@ namespace DepthsBelow
|
|||||||
if (sr != null)
|
if (sr != null)
|
||||||
sr.Draw(spriteBatch);
|
sr.Draw(spriteBatch);
|
||||||
}
|
}
|
||||||
|
foreach (var bullet in Volley)
|
||||||
|
{
|
||||||
|
var sr = bullet.GetComponent<Component.SpriteRenderer>();
|
||||||
|
if (sr != null)
|
||||||
|
sr.Draw(spriteBatch);
|
||||||
|
}
|
||||||
|
|
||||||
// Draw mouse input visuals
|
// Draw mouse input visuals
|
||||||
MouseInput.Draw(spriteBatch);
|
MouseInput.Draw(spriteBatch);
|
||||||
|
|||||||
@@ -122,6 +122,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Camera.cs" />
|
<Compile Include="Camera.cs" />
|
||||||
|
<Compile Include="Shot.cs" />
|
||||||
|
<Compile Include="Component\Shooting.cs" />
|
||||||
<Compile Include="GUIManager.cs" />
|
<Compile Include="GUIManager.cs" />
|
||||||
<Compile Include="GUI\Button.cs" />
|
<Compile Include="GUI\Button.cs" />
|
||||||
<Compile Include="GUI\Frame.cs" />
|
<Compile Include="GUI\Frame.cs" />
|
||||||
|
|||||||
@@ -73,6 +73,10 @@ namespace DepthsBelow
|
|||||||
core.TestMonster.X = 12;
|
core.TestMonster.X = 12;
|
||||||
core.TestMonster.Y = 4;
|
core.TestMonster.Y = 4;
|
||||||
}
|
}
|
||||||
|
if (ks.IsKeyDown(Keys.S))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
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 Shot : Entity
|
||||||
|
{
|
||||||
|
public static Texture2D Texture;
|
||||||
|
public Color Color;
|
||||||
|
public static Point Origin;
|
||||||
|
|
||||||
|
private bool _selected; //I guess as in "currently doing something"
|
||||||
|
|
||||||
|
public List<Shot> Volley;
|
||||||
|
|
||||||
|
private PathFinder.Node nextNode;
|
||||||
|
public Vector2 direction = Vector2.Zero;
|
||||||
|
|
||||||
|
public Shot(Core core)
|
||||||
|
: base(core)
|
||||||
|
{
|
||||||
|
if (Texture == null)
|
||||||
|
LoadContent(core);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
public static void LoadContent(Core core)
|
||||||
|
{
|
||||||
|
Texture = core.Content.Load<Texture2D>("images/Shot");
|
||||||
|
}
|
||||||
|
public override void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
base.Update(gameTime);
|
||||||
|
|
||||||
|
float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
|
||||||
|
List<Point> soldierCollisions = new List<Point>();
|
||||||
|
|
||||||
|
foreach (var body in core.Swarm)
|
||||||
|
{
|
||||||
|
if (this.GetComponent<Collision>().Rectangle.Intersects(body.GetComponent<Collision>().Rectangle))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var soldier in core.Squad)
|
||||||
|
{
|
||||||
|
if (this.GetComponent<Collision>().Rectangle.Intersects(soldier.GetComponent<Collision>().Rectangle))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// HACK: Make this work properly with other speeds...
|
||||||
|
float speed = 4f;
|
||||||
|
Transform.World.Position += speed * direction;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -120,6 +120,13 @@
|
|||||||
<Processor>FontDescriptionProcessor</Processor>
|
<Processor>FontDescriptionProcessor</Processor>
|
||||||
</Compile>
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="images\Shot.bmp">
|
||||||
|
<Name>Shot</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: 222 B |
Reference in New Issue
Block a user