move to github

This commit is contained in:
Magnus von Wachenfeldt
2015-12-04 10:23:49 +01:00
commit 2a9d8ce416
252 changed files with 45041 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
namespace SpacePew.Models.Projectiles
{
public sealed class BouncingBullet : Bullet
{
public BouncingBullet()
{
Health = 30;
}
public override CollisionType CollisionType
{
get
{
return CollisionType.Bounce;
}
}
}
}

View File

@@ -0,0 +1,70 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace SpacePew.Models.Projectiles
{
public class Bullet : ProjectileBase
{
#region Constructors
public Bullet()
{
this.Color = Color.White;
this.Velocity = new Vector2();
this.Angle = 0;
this.Health = 15;
}
public Bullet(Vector2 position)
: this()
{
this.Position = position;
}
#endregion
#region IEntity Members
public override sealed int Health
{
get;
set;
}
public override string TextureName
{
get { return "bullet"; }
}
#endregion
#region IProjectile Members
public override string FireSoundAssetName
{
get { return "Audio/Waves/bullet_sound"; }
}
public override string HitSoundAssetName
{
get { return "Audio/Waves/bullet_hit"; }
}
public override int Damage
{
get { return 5; }
}
public override float Speed
{
get { return 400f; }
}
public override CollisionType CollisionType
{
get { return CollisionType.Explode; }
}
#endregion
}
}

View File

@@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using SpacePew.Models.Weapons;
namespace SpacePew.Models.Projectiles
{
class ClusterBomb : Bullet, IKillable
{
private const int FuseTime = 7000; //time in milliseconds before it explodes
private double _elapsed = 0;
readonly DateTime _startTick;
public override int Damage
{
get { return 10; }
}
public override float Speed
{
get { return 100; }
}
public ClusterBomb()
{
_startTick = DateTime.Now;
}
public override Color Color
{
get
{
var r = (byte)((_elapsed / FuseTime) * 255f);
var g = (byte)(128 + Math.Sin(_elapsed / 150f) * 127f);
var b = (byte)(255 - g);
return new Color(r, g, b);
}
}
public override void Update(Microsoft.Xna.Framework.GameTime time)
{
_elapsed = (DateTime.Now - _startTick).TotalMilliseconds;
if (_elapsed >= FuseTime)
{
this.Health = 0;
}
base.Update(time);
}
private void CreateCluster(float angle, string owner)
{
var entity = EntityFactory.Instance.CreateEntity<ProjectileBase>(
typeof(Bullet),
owner,
Position,
Vector2.Zero,
angle);
Matrix m = Matrix.CreateRotationZ(angle + (float)(WeaponBase.Randomizer.NextDouble() * .2f - .1f));
Vector2 velocity = Vector2.Transform(-Vector2.UnitY, m);
entity.Position += velocity * 10;
entity.Velocity = velocity * entity.Speed * (float)(WeaponBase.Randomizer.NextDouble() + 0.5f);
//TODO.. fix
//FiredShots.Enqueue(entity);
}
public override void ApplyGravity(GameTime time)
{
float timeSeconds = time.ElapsedGameTime.Milliseconds * .001f;
Velocity = new Vector2(
Velocity.X,
Velocity.Y + (timeSeconds * GravityModifier * 0.5f));
}
#region IKillable Members
public void Kill()
{
//TODO: make sure the clusters are only created on the client that created the cluster, and then let the server send them to all klients
for (float i = 0; i < 45; i += .5f)
CreateCluster(i, this.Owner);
}
#endregion
}
}

View File

@@ -0,0 +1,8 @@
namespace SpacePew.Models.Projectiles
{
public enum CollisionType
{
Explode,
Bounce
}
}

View File

@@ -0,0 +1,91 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
namespace SpacePew.Models.Projectiles
{
public class HomingBullet : Bullet
{
public HomingBullet()
{
this.Color = Color.PowderBlue;
}
public override float Speed
{
get
{
return 200f;
}
}
public override int Damage
{
get
{
return 3;
}
}
private Player _target;
const float TimeIncrementSpeed = 5;
public override void Update(GameTime time)
{
base.Update(time);
if (_target == null)
{
GetTarget();
}
if (_target != null)
{
var delta = new Vector2(_target.Position.X - this.Position.X, _target.Position.Y - this.Position.Y);
if (delta.Length() > TimeIncrementSpeed)
{
delta.Normalize();
delta.X *= TimeIncrementSpeed;
delta.Y *= TimeIncrementSpeed;
}
this.Position = new Vector2(Position.X + (int)delta.X, Position.Y + (int)delta.Y);
}
}
private void GetTarget()
{
var players = EntityFactory.Instance.Entities.OfType<Player>().Where(player => player.Owner != this.Owner).ToList();
if (players.Count > 0)
{
_target = FindClosestPlayer(players, this.Position);
}
}
private static Player FindClosestPlayer(IEnumerable<Player> list, Vector2 pointToCompare)
{
Player closestPlayer = list.ToList()[0];
float distance = float.PositiveInfinity;
foreach (var player in list)
{
float dx = pointToCompare.X - player.Position.X;
float dy = pointToCompare.Y - player.Position.Y;
float d = dx * dx - dy * dy;
if (d < distance)
{
distance = d;
closestPlayer = player;
}
}
return closestPlayer;
}
}
}

View File

@@ -0,0 +1,12 @@
namespace SpacePew.Models.Projectiles
{
public interface IProjectile : IEntity
{
string HitSoundAssetName { get; }
string FireSoundAssetName { get; }
int Damage { get; }
float Speed { get; }
CollisionType CollisionType { get; }
}
}

View File

@@ -0,0 +1,29 @@
using System;
using Microsoft.Xna.Framework;
namespace SpacePew.Models.Projectiles
{
public class LongShot : Bullet
{
public override Vector2 Origin
{
get { return new Vector2(5, 12); }
}
public override string TextureName
{
get { return "longshot"; }
}
public override void ApplyGravity(GameTime time)
{
base.ApplyGravity(time);
//Sätt rotationen till lika som riktningen som pilen åker
Vector2 vNormal = Velocity;
vNormal.Normalize();
Angle = (vNormal.X > 0 ? 1f : -1f) * (float)(Math.Acos(Vector2.Dot(-Vector2.UnitY, vNormal)));
}
}
}

View File

@@ -0,0 +1,75 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace SpacePew.Models.Projectiles
{
public sealed class Missile : ProjectileBase
{
#region Constructors
public Missile()
{
this.Color = Color.Red;
this.Velocity = new Vector2();
this.Angle = 0;
this.Health = 10;
}
public Missile(Vector2 position)
: this()
{
this.Position = position;
}
#endregion
#region IEntity Members
public override void CollideWithLevel(Level level)
{
// blow stuff
}
public override int Health
{
get;
set;
}
public override string TextureName
{
get { return "bullet"; }
}
#endregion
#region IProjectile Members
public override string FireSoundAssetName
{
get { return "Audio/Waves/bullet_sound"; }
}
public override string HitSoundAssetName
{
get { return "Audio/Waves/bullet_hit"; }
}
public override int Damage
{
get { return 50; }
}
public override float Speed
{
get { return 600f; }
}
public override CollisionType CollisionType
{
get { return CollisionType.Explode; }
}
#endregion
}
}

View File

@@ -0,0 +1,48 @@
namespace SpacePew.Models.Projectiles
{
public abstract class ProjectileBase : EntityBase, IProjectile
{
#region IEntity Members
public override bool Collide(IEntity entity)
{
bool collided = base.Collide(entity);
if (collided)
{
SoundManager.Play(HitSoundAssetName, this.Position);
}
return collided;
}
public override void CollideWithLevel(Level level)
{
if (this.CollisionType == CollisionType.Explode)
{
// blow up somehow (particle system is there, but needs to trash the level a little more too)
}
else if (this.CollisionType == CollisionType.Bounce)
{
this.Velocity -= (this.Velocity * 1.9f);
}
}
public override void Created()
{
SoundManager.Play(FireSoundAssetName, this.Position);
}
#endregion
#region IProjectile Members
public abstract string HitSoundAssetName { get; }
public abstract string FireSoundAssetName { get; }
public abstract int Damage { get; }
public abstract float Speed { get; }
public abstract CollisionType CollisionType { get; }
#endregion
}
}