Esempio n. 1
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
 }
Esempio n. 2
0
        void BoatControls()
        {
            int RotationDirection = 0;

            if (!PlayerBoat.Anchored && !IsMainMenuOpened)
            {
                if (InputManager.Keyboard.KeyDown(Keys.Left))
                {
                    RotationDirection = 1;
                }

                else if (InputManager.Keyboard.KeyDown(Keys.Right))
                {
                    RotationDirection = -1;
                }

                if (InputManager.Keyboard.KeyPushed(Keys.Up))
                {
                    PlayerBoat.SpeedScale = Math.Min(PlayerBoat.SpeedScale + 1, 3);
                }

                else if (InputManager.Keyboard.KeyPushed(Keys.Down))
                {
                    PlayerBoat.SpeedScale = Math.Max(PlayerBoat.SpeedScale - 1, -1);
                }
            }

            PlayerBoat.Velocity = PlayerBoat.RotationMatrix.Up * PlayerBoat.MovementSpeed * PlayerBoat.SpeedScale;


            if (RotationDirection == 0)
            {
                //Si aucun bouton de direction n'est appuyé, on diminue la rotation du bateau en fonction du signe du nombre.
                //Si la vitesse de rotation est inférieure à la vitesse d'accélération, alors on stoppe tout simplement le bateau,
                //Pour éviter que ça ne fasse un effet yoyo : Avec une accel. de 0.1, si le bateau est à 0.05, on le mettra à -0.05,
                //Puis à nouveau à 0.05, etc.

                PlayerBoat.RotationZVelocity =
                    (Math.Abs(PlayerBoat.RotationZVelocity) > PlayerBoat.RotationAcceleration)
                    ? PlayerBoat.RotationZVelocity - PlayerBoat.RotationAcceleration * Math.Sign(PlayerBoat.RotationZVelocity) : 0;
            }

            //Sinon, si l'une des touches est appuyée on augmente la vitesse de rotation dans le sens correspondant
            else if (RotationDirection == 1)
            {
                PlayerBoat.RotationZVelocity = Math.Min(PlayerBoat.RotationZVelocity + PlayerBoat.RotationAcceleration, PlayerBoat.MaxRotationSpeed);
            }
            else if (RotationDirection == -1)
            {
                PlayerBoat.RotationZVelocity = Math.Max(PlayerBoat.RotationZVelocity - PlayerBoat.RotationAcceleration, -PlayerBoat.MaxRotationSpeed);
            }

            if (InputManager.Keyboard.KeyPushed(Keys.S))
            {
                PlayerBoat.SwitchSide();
            }

            if (InputManager.Keyboard.KeyPushed(Keys.Space))
            {
                PlayerBoat.FireCannonball();
            }

            else if (InputManager.Keyboard.KeyPushed(Keys.E))
            {
                if (NearToADock != null)
                {
                    ControlMethod = PlayerControls;

                    PlayerInstance.X       = NearToADock.X;
                    PlayerInstance.Y       = NearToADock.Y;
                    PlayerInstance.Visible = true;
                    EntityToFollowByCam    = PlayerInstance;
                    PlayerBoat.Anchor();

                    ZoomCamera();
                }
            }
            if (InputManager.Keyboard.KeyPushed(Keys.A))
            {
                if (PlayerBoat.Anchored)
                {
                    PlayerBoat.UnAnchor();
                }
                else
                {
                    PlayerBoat.Anchor();
                }
            }

            SpeedMeter.SetState(PlayerBoat.SpeedScale);
        }
Esempio n. 3
0
 void Awake()
 {
     if (instance == null){
         instance = this;
     }
 }