예제 #1
0
        public override void Update(GameTime gameTime)
        {
            var keyboardState = Keyboard.GetState();
            var mouseState    = Mouse.GetState();

            VelocityGoal = Vector2.Zero;
            var vector = Camera.GetWorldPosition(new Vector2(mouseState.X, mouseState.Y));

            DirectionGoalVector.X = vector.X - BoundingBox.Center.X;
            DirectionGoalVector.Y = vector.Y - BoundingBox.Center.Y;
            DirectionGoalVector.Normalize();
            Rotation = (float)DirectionVector.GetRotationFromVector();

            if (mouseState.LeftButton == ButtonState.Pressed && gameTime.TotalGameTime.TotalMilliseconds > LastFire + 200)
            {
                LastFire = gameTime.TotalGameTime.TotalMilliseconds;
                Fire();
            }

            if (keyboardState.IsKeyDown(Keys.W))
            {
                CreateExhaustParticles();
                VelocityGoal = (DirectionVector) * Speed;
            }

            if (keyboardState.IsKeyDown(Keys.S))
            {
                CreateSideExhaustParticles(DirectionVector, new Vector2(position.X + texture.Width / 2f, position.Y));
                VelocityGoal += (DirectionVector) * (Speed * (-SideThrust));
            }
            if (keyboardState.IsKeyDown(Keys.D))
            {
                var right = new Vector2(-DirectionVector.Y, DirectionVector.X);
                CreateSideExhaustParticles(-right, new Vector2(position.X, position.Y + texture.Height / 2f));
                VelocityGoal += right * (Speed * (SideThrust));
            }
            else if (keyboardState.IsKeyDown(Keys.A))
            {
                var left = new Vector2(DirectionVector.Y, -DirectionVector.X);
                CreateSideExhaustParticles(-left, new Vector2(position.X + texture.Width, position.Y + texture.Height / 2f));
                VelocityGoal += left * (Speed * (SideThrust));
            }

            DirectionVector = Vector2.Lerp(DirectionGoalVector, DirectionVector, RotationSpeed);
            Velocity        = Vector2.Lerp(VelocityGoal, Velocity, 0.99f);
            //scale = Vector2.Lerp(scaleGoal,scale,0.995f);

            base.Update(gameTime);
        }
예제 #2
0
        public override void Update(GameTime gameTime)
        {
            //DEBUGGING HELP
            var keyboardState = Keyboard.GetState();
            var mouseState    = Mouse.GetState();

            if (keyboardState.IsKeyDown(Keys.Space))
            {
                var mouseWorldPosition = Camera.GetWorldPosition(new Vector2(mouseState.X, mouseState.Y));
                Seek(mouseWorldPosition);
            }
            if (keyboardState.IsKeyDown(Keys.G))
            {
                var mouseWorldPosition = Camera.GetWorldPosition(new Vector2(mouseState.X, mouseState.Y));
                Flee(mouseWorldPosition, 2000f);
            }
            //END DEBUGGING HELP

            Vector2 steering = Vector2.Zero;

            if (_shipBehaviour == ShipBehaviour.Seek)
            {
                steering += SeekBehaviour();
            }
            if (_shipBehaviour == ShipBehaviour.Wander)
            {
                steering += WanderBehaviour(gameTime);
            }
            if (_shipBehaviour == ShipBehaviour.Flee)
            {
                steering += FleeBehaviour();
            }

            steering            = Vector2.Normalize(steering);
            steering            = steering * maxForce;
            steering            = steering / Mass;
            DirectionGoalVector = Vector2.Normalize(steering);
            DirectionVector     = Vector2.Lerp(DirectionGoalVector, DirectionVector, 0.99f);
            Velocity            = DirectionVector * Speed;
            //Debug.WriteLine(DirectionVector);

            Rotation = (float)DirectionVector.GetRotationFromVector();
            _healthBar.Update(gameTime);

            CheckIfDestroyed();

            base.Update(gameTime);
        }