예제 #1
0
        public override IEnumerable <Object3D> Update(DefaultEnvironment Environment, TimeSpan ElapsedTime)
        {
            UpdateCanon(ElapsedTime);

            if (ReadyToShoot && Shooting)
            {
                var dst = (Position - Environment.ActiveCamera.Position).Length();
                Environment.Sounds[Data.LaserSound].Play(1 / (1 + dst / 5000), 0, 0);
                var bulletDirection = Vector3.Normalize(Vector3.Transform(Vector3.Forward, Orientation));
                var bullet          = new Bullet(Position, bulletDirection, Speed * 50 + 1000);
                bullet.Position += (bullet.Boundary.Radius + Boundary.Radius) * 75 * bulletDirection;
                yield return(bullet);

                ReadyToShoot = false;
            }
            Shooting = false;

            foreach (var thrustParticle in GenerateThrust(Environment, ElapsedTime))
            {
                yield return(thrustParticle);
            }

            Speed += forwardAcceleration * (float)ElapsedTime.TotalSeconds;
            if (targetRotation > rotation)
            {
                rotation += rotationSpeed * (float)ElapsedTime.TotalSeconds;
                if (rotation >= targetRotation)
                {
                    rotation = targetRotation;
                }
            }
            else if (targetRotation < rotation)
            {
                rotation -= rotationSpeed * (float)ElapsedTime.TotalSeconds;
                if (rotation <= targetRotation)
                {
                    rotation = targetRotation;
                }
            }
            if (rotation > maxRotation)
            {
                rotation = maxRotation;
            }
            if (rotation < -maxRotation)
            {
                rotation = -maxRotation;
            }

            Orientation *= Rotation;
            var Direction = Vector3.Transform(Vector3.Forward * Speed, Orientation);
            var Up        = Vector3.Transform(Vector3.Up, Orientation);

            Position += Direction * (ElapsedTime == TimeSpan.Zero ? 0 : 1);

            if (Speed > 0)
            {
                ThrustFlame.UpdateThrust(Position, Direction, Up, ElapsedTime, Environment);
            }
            else
            {
                if (ThrustFlame != null)
                {
                    ThrustFlame.DontThrust();
                }
            }
            yield break;
        }
예제 #2
0
 public Spaceship()
 {
     ThrustFlame = new ThrustFlame();
     Id          = Data.Spaceship;
     lastShot    = -shotTrigger;
 }