/// <summary> /// Initializes a new instance of the <see cref="SeekMotion"/> class. /// </summary> /// <param name="target">The target object.</param> /// <param name="speed">The speed (under 0.1f is better).</param> /// <param name="defaultVector">The default vector used when no target is set yet.</param> /// <param name="rotationSpeed">The rotation speed.</param> public SeekMotion(GameObject target, float speed, Vector2D defaultVector, float rotationSpeed) { Target = target; _lastDirection = defaultVector; _speed = speed; _rotationSpeed = rotationSpeed; }
public void Update(GameObject gameObject, float deltaTime) { if (!Script.IsNullOrUndefined(Target)) { float lastAngle = _lastDirection.GetAbsoluteAngle(); Vector2D targetVector = new Vector2D(Target.Location.X - gameObject.Location.X, Target.Location.Y - gameObject.Location.Y); double relativeAngle = targetVector.GetAbsoluteAngle() - lastAngle; if (Math.Abs(relativeAngle) > Math.PI) { if (relativeAngle < 0) relativeAngle += Math.PI * 2; else relativeAngle -= Math.PI * 2; } if (relativeAngle != 0) { Angle = lastAngle + (Math.Min(_rotationSpeed, Math.Abs(relativeAngle)) * (relativeAngle / Math.Abs(relativeAngle))); _lastDirection.X = _speed * Math.Cos(Angle); _lastDirection.Y = _speed * Math.Sin(Angle); } } gameObject.Location.TranslateByVector(_lastDirection); }
public override void Load() { ImageElement ship = _level.LoadImage("Images/shooter/meteor/1.png", false); _gunPosition = new Vector2D(ship.NaturalWidth * .8f, ship.NaturalHeight / 2); _missileBayPosition = new Vector2D(ship.NaturalWidth * .5f, ship.NaturalHeight * .8f); }
public PlasmaBall(Vector2D location, IMotion motion) : base() { Location = new Vector3D(location.X, location.Y, ShooterLevel.WeaponsZ); Motion = motion; ShooterLevel.Current.Plasma.AddPlasmaBall(this); }
public Bullet(Vector2D location, int strength, IMotion motion) : base(location, motion) { AnimationSequence sequence = new AnimationSequence(); sequence.AddSprite(ShooterLevel.Current.LoadImage((strength == 1)? "images/shooter/meteor/sb.png" : "images/shooter/meteor/b.png", false), 0, 0); AnimationSequences["Default"] = sequence; StartAnimation("Default"); _strength = strength; }
public BasicPlasmaBall(Vector2D location, IMotion motion) : base(location, motion) { ShooterLevel level = ShooterLevel.Current; AnimationSequence sequence = new AnimationSequence(); sequence.AddSprites(new ImageElement[]{ level.LoadImage("images/shooter/plasma/1.png", false), level.LoadImage("images/shooter/plasma/2.png", false), level.LoadImage("images/shooter/plasma/3.png", false), level.LoadImage("images/shooter/plasma/2.png", false) }, 6, 6); sequence.Loop = true; sequence.Delay = 200; AnimationSequences["Default"] = sequence; StartAnimation("Default"); }
public Missile(Vector2D location) : base(location, new SeekMotion(null, 12, new Vector2D(12, 0), 0.25f)) { WeaponsSystem.TotalMissiles++; LoadAnimation("00", "8"); LoadAnimation("01", "9"); LoadAnimation("02", "10"); LoadAnimation("03", "11"); LoadAnimation("04", "12"); LoadAnimation("05", "13"); LoadAnimation("06", "14"); LoadAnimation("07", "15"); LoadAnimation("08", "0"); LoadAnimation("09", "1"); LoadAnimation("10", "2"); LoadAnimation("11", "3"); LoadAnimation("12", "4"); LoadAnimation("13", "5"); LoadAnimation("14", "6"); LoadAnimation("15", "7"); StartAnimation("0"); ShooterLevel level = ShooterLevel.Current; AnimationSequence sequence = new AnimationSequence(); sequence.AddSprites(new ImageElement[]{ level.LoadImage("images/shooter/explosion/0002.png", false), level.LoadImage("images/shooter/explosion/0003.png", false), level.LoadImage("images/shooter/explosion/0004.png", false), level.LoadImage("images/shooter/explosion/0005.png", false), level.LoadImage("images/shooter/explosion/0006.png", false), level.LoadImage("images/shooter/explosion/0007.png", false), level.LoadImage("images/shooter/explosion/0008.png", false), level.LoadImage("images/shooter/explosion/0009.png", false) }, 25, 25); sequence.Delay = 50; sequence.Loop = false; AnimationSequences["Explosion"] = sequence; Dino dino = AcquireTarget(); if (dino != null) dino.Locked = true; ((SeekMotion)Motion).Target = AcquireTarget(); }
public void Shoot(Vector2D gunLocation, Vector2D missileBayLocation) { switch (ShotCount) { case 3: if (_level.Ticks >= Bullet.LastFired + Bullet.FireRate) { Bullet.LastFired = _level.Ticks; _projectiles.Add(new Bullet(gunLocation, ShotPower, new StraightMotion(new Vector2D(0.41f, 0.25f)))); _projectiles.Add(new Bullet(gunLocation, ShotPower, new StraightMotion(new Vector2D(0.5f, 0)))); _projectiles.Add(new Bullet(gunLocation, ShotPower, new StraightMotion(new Vector2D(0.41f, -0.25f)))); } break; case 2: if (_level.Ticks >= Bullet.LastFired + Bullet.FireRate / 2) { _lastShotIndex = (_lastShotIndex + 1) % 2; Bullet.LastFired = _level.Ticks; _projectiles.Add(new Bullet(gunLocation.Clone().TranslateByCoordinates(0, _lastShotIndex * -5), ShotPower, new StraightMotion(new Vector2D(0.5f, 0)))); } break; default: if (_level.Ticks >= Bullet.LastFired + Bullet.FireRate) { Bullet.LastFired = _level.Ticks; _projectiles.Add(new Bullet(gunLocation, ShotPower, new StraightMotion(new Vector2D(0.5f, 0)))); } break; } if (TotalMissiles < MissileCount && _level.Ticks >= Missile.LastFired + Missile.FireRate) { Missile.LastFired = _level.Ticks; _projectiles.Add(new Missile(missileBayLocation)); } }
public Projectile(Vector2D location, IMotion motion) : base() { Location = new Vector3D(location.X, location.Y, ShooterLevel.WeaponsZ); Motion = motion; }
public Vector2D TranslateByVector(Vector2D vector) { X += vector.X; Y += vector.Y; return this; }
public Vector2D SetOrigin(Vector2D origin) { X -= origin.X; Y -= origin.Y; return this; }
public StraightMotion(Vector2D motionVector) { _motionVector = motionVector.Clone(); }