public void GetVectorInDirectionTest() { Assert.AreEqual(new Vector2(1, 0), VectorHelpers.GetVectorInDirection(0)); Assert.AreEqual(new Vector2(1, 1), VectorHelpers.GetVectorInDirection(MathHelper.PiOver4)); Assert.AreEqual(new Vector2(0, 1), VectorHelpers.GetVectorInDirection(MathHelper.PiOver2)); Assert.AreEqual(new Vector2(-1, 1), VectorHelpers.GetVectorInDirection(3 * MathHelper.PiOver4)); Assert.AreEqual(new Vector2(-1, 0), VectorHelpers.GetVectorInDirection(MathHelper.Pi)); Assert.AreEqual(new Vector2(-1, -1), VectorHelpers.GetVectorInDirection(-3 * MathHelper.PiOver4)); Assert.AreEqual(new Vector2(0, -1), VectorHelpers.GetVectorInDirection(-1 * MathHelper.PiOver2)); Assert.AreEqual(new Vector2(1, -1), VectorHelpers.GetVectorInDirection(-1 * MathHelper.PiOver4)); }
public void Shoot() { if (LastFiringTicks != null && World.Ticks - LastFiringTicks < FiringTimeTicks) { return; } LastFiringTicks = World.Ticks; Vector2 bulletDirection = VectorHelpers.GetVectorInDirection(Rotation); bulletDirection.Normalize(); Vector2 bulletImpactVector = GunRange * bulletDirection; Point bulletImpact = Position + new Point((int)bulletImpactVector.X, (int)bulletImpactVector.Y); bulletImpact.Y += FlyingHeight; Bullet bullet = new Bullet(World, Player.One, Position, bulletImpact); World.AddProjectile(bullet); Sounds.HeavyMachineGun.Play(0.5f, 0, 0); World.AddExplosion(new GunfireMuzzle(World, this, Rotation)); }
public void Rocket() { if (LastBombingTicks != null && World.Ticks - LastBombingTicks < BombingTimeTicks) { return; } LastBombingTicks = World.Ticks; Vector2 rocketDirection = VectorHelpers.GetVectorInDirection(Rotation); rocketDirection = GunRange * 2 * rocketDirection; Point rocketTarget = Position + new Point((int)rocketDirection.X, (int)rocketDirection.Y); rocketTarget.Y += FlyingHeight; rocketTarget.X += (new Random().Next(30) - 15); rocketTarget.Y += (new Random().Next(30) - 15); Sounds.Rocket2.Play(); World.AddProjectile(new AirToGroundRocket(World, Player, Position, rocketTarget)); }