예제 #1
0
        public virtual void Update(GameTime gameTime)
        {
            soundPan = (_position.X - Game.stateManager.shooterState.CurrentLevel.PlayerPosition.X)
                       / Game.stateManager.shooterState.CurrentLevel.LevelWidth;

            // Movement
            if (Enable)
            {
                Position += Direction * Speed * gameTime.ElapsedGameTime.Milliseconds;
            }

            // Rotation
            RotationAngle += Rotation * MathFunctions.FPSSyncFactor(gameTime);

            // Invicibility
            if (tempInvincibility > 0)
            {
                tempInvincibility -= gameTime.ElapsedGameTime.Milliseconds;
            }

            // Kill of object
            if (hp <= 0)
            {
                if (this is AllianceFighterAlly)
                {
                    ((AllianceFighterAlly)this).OnKilled();
                }

                IsKilled = true;
            }

            //Set degree
            if (DirectionY > 0)
            {
                Radians = Math.Acos(DirectionX);
            }
            else
            {
                Radians = 2 * Math.PI - (Math.Acos(DirectionX));
            }

            if (Radians >= 2 * Math.PI)
            {
                Radians -= 2 * Math.PI;
            }

            //Hantering av "Disable FollowObject"
            if (disableFollowObject > 0)
            {
                disableFollowObject -= gameTime.ElapsedGameTime.Milliseconds;
            }

            if (Follows)
            {
                FindFollowObject();

                if (FollowObject != null)
                {
                    UpdateFollowing(gameTime);
                }
            }

            //Bullet-duration
            if (this is Bullet)
            {
                if (duration > 0)
                {
                    duration -= gameTime.ElapsedGameTime.Milliseconds;
                }
                else
                {
                    IsKilled = true;
                }
            }

            if (shootObject != null)
            {
                if (shootObject.IsKilled || shootObject.IsOutside)
                {
                    shootObject = null;
                }
            }

            if (IsKilled)
            {
                OnKilled();
            }
        }
 private void UpdateFollowObject(GameTime gameTime)
 {
     Direction = MathFunctions.ChangeDirection(gameTime, Direction, Position, player.Position, turningSpeed);
     Direction = MathFunctions.ScaleDirection(Direction);
 }