IOnitial attempt to shoot player
This commit is contained in:
@@ -13,11 +13,13 @@ namespace EvilSatellites.Objects
|
||||
{
|
||||
private ISoundEffect3D Sound;
|
||||
private Random rnd = new Random();
|
||||
private Vector3 Direction;
|
||||
public Vector3 Direction;
|
||||
private Vector3 StartPos;
|
||||
private float Range;
|
||||
public Projectile(IScreen screen, Vector3 pos, Matrix rotation) : base(screen)
|
||||
public IGameObject Owner;
|
||||
public Projectile(IScreen screen, Vector3 pos, Matrix rotation, IGameObject owner) : base(screen)
|
||||
{
|
||||
Owner = owner;
|
||||
StartPos = pos;
|
||||
Position = pos;
|
||||
Dimensions = new Vector3(5, 5, 5);
|
||||
@@ -58,7 +60,8 @@ namespace EvilSatellites.Objects
|
||||
|
||||
public override void OnCollision(IGameObject obj)
|
||||
{
|
||||
if (obj.Type == ObjectType.Projectile || obj.Type == ObjectType.Player || obj.Type == ObjectType.Debris) return;
|
||||
if (obj.Type == ObjectType.Projectile || obj.Type == ObjectType.Debris) return;
|
||||
if (obj == Owner) return;
|
||||
Screen.Manager.Sound.PlayOneshot(@"sfx/physics/impacts/bullet/"+(rnd.Next(5)+1)+".wav", new System.Numerics.Vector3(Position.X+Dimensions.X/2, Position.Y+Dimensions.Y/2, Position.Z+Dimensions.Z/2), Screen.Manager.EnvironmentEffect);
|
||||
Destroy();
|
||||
}
|
||||
|
||||
@@ -50,10 +50,28 @@ namespace EvilSatellites.Objects
|
||||
{
|
||||
Move(new Vector3(0, 0, -0.05f));
|
||||
Sound.Position = new System.Numerics.Vector3(Position.X+Dimensions.X/2, Position.Y+Dimensions.Y/2, Position.Z+Dimensions.Z/2);
|
||||
if (rnd.Next(500) == 250)
|
||||
{
|
||||
var scr = (GameScreen)Screen;
|
||||
var player = scr.GetPlayer();
|
||||
var view = player.Position - Position;
|
||||
var rotationAxis = Vector3.Cross(Rotation.Forward, view);
|
||||
var rotationAngle = (float)Math.Acos(Vector3.Dot(Rotation.Forward, view) / Rotation.Forward.Length() / view.Length());
|
||||
var rotationMatrix = Matrix.CreateFromAxisAngle(rotationAxis, rotationAngle);
|
||||
var proj = new Projectile(Screen, Position, rotationMatrix, this);
|
||||
proj.Direction = new Vector3(0, 0, 1);
|
||||
scr.AddObject(proj);
|
||||
DavyKager.Tolk.Output("Shoot!");
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnCollision(IGameObject obj)
|
||||
{
|
||||
if (obj.Type == ObjectType.Projectile)
|
||||
{
|
||||
var proj = (Projectile)obj;
|
||||
if (proj.Owner == this) return;
|
||||
}
|
||||
Health -= 10;
|
||||
if (obj.Type == ObjectType.Player)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user