Пример #1
0
 /// <summary>
 /// TO BE COMPLETED
 /// </summary>
 /// <param name="deltaT"></param>
 /// <param name="game"></param>
 /// <returns></returns>
 public override bool Update(Single deltaT, Game game)
 {
     if (IsSpawning)
     {
         if (timeSinceSpawnStart < spawningDelay)
         {
             timeSinceSpawnStart++;
             float spawningPercentage = (float)timeSinceSpawnStart / spawningDelay;
             int   size = (int)(enemyMaxSize * spawningPercentage);
             RandomColor(colorInt, spawningPercentage);
             enemyCurrentSize = size;
             setEnemyPoints();
             Speed = speed * spawningPercentage / 2;
         }
         else
         {
             IsSpawning = false;
             RandomColor(colorInt, 1);
             enemyCurrentSize = enemyMaxSize;
             setEnemyPoints();
             Speed = speed;
         }
     }
     Bounce();
     Advance(Speed);
     if (Game.Stopwatch.ElapsedMilliseconds > smokeParticleLastCreated.TotalMilliseconds + 20)
     {
         smokeParticleLastCreated = Game.Stopwatch.Elapsed;
         SmokeParticle smokeParticle = new SmokeParticle(Type, Position.X, Position.Y, 4, 1, false, 30, enemyMaxSize / 5, 0.2f, colorInt, 1);
         smokeParticle.Angle = rnd.Next(-180, 181);
         game.smokeParticles.Add(smokeParticle);
     }
     return(base.Update(deltaT, game));
 }
Пример #2
0
        /// <summary>
        /// TO BE COMPLETED
        /// </summary>
        /// <param name="deltaT"></param>
        /// <param name="game"></param>
        /// <returns></returns>
        public override bool Update(Single deltaT, Game game)
        {
            if (IsSpawning)
            {
                if (timeSinceSpawnStart < spawningDelay)
                {
                    timeSinceSpawnStart++;
                    float spawningPercentage = (float)timeSinceSpawnStart / spawningDelay;
                    int   size = (int)(enemyMaxSize * spawningPercentage);
                    RandomColor(colorInt, spawningPercentage);
                    enemyCurrentSize = size;
                    setEnemyPoints();
                    Speed = speed * spawningPercentage / 2;
                }
                else
                {
                    RandomColor(colorInt, 1);
                    IsSpawning       = false;
                    enemyCurrentSize = enemyMaxSize;
                    setEnemyPoints();
                    Speed = speed;
                }
            }
            float AngleToHero =
                (float)(Math.Atan2(game.hero.Position.Y - Position.Y, game.hero.Position.X - Position.X) * 180 / Math.PI);

            if (RightAngle)
            {
                if (AngleModifier < 60)
                {
                    AngleModifier += 3;
                }
                else
                {
                    RightAngle = false;
                }
            }
            else
            {
                if (AngleModifier > -60)
                {
                    AngleModifier -= 3;
                }
                else
                {
                    RightAngle = true;
                }
            }
            Angle = AngleToHero + AngleModifier;
            if (Game.Stopwatch.ElapsedMilliseconds > smokeParticleLastCreated.TotalMilliseconds + 15)
            {
                smokeParticleLastCreated = Game.Stopwatch.Elapsed;
                SmokeParticle smokeParticle = new SmokeParticle(Type, Position.X, Position.Y, 4, Speed / 2, false, 25,
                                                                enemyMaxSize / 2, 0.2f, colorInt, 1);
                smokeParticle.Angle = Angle - 180;
                game.smokeParticles.Add(smokeParticle);
            }
            Advance(Speed);
            Fire(deltaT, game);
            return(base.Update(deltaT, game));
        }
Пример #3
0
        /// <summary>
        /// Mise à jour de la classe « Hero ». Fais la validation et le traitement d'entrée de donnée de la manette.
        /// </summary>
        /// <param name="deltaT"> Le temps en seconde écoulé depuis la dernière mise à jour. </param>
        /// <param name="game"> L'instance de la classe du Jeu. Utilisé pour la mise à jour de certaines variables de la classe de Jeu. </param>
        /// <returns> Retourne vrai si l’« Hero » est encore en vie. Retourne faux si l’« Hero » n'a plus de vie. </returns>
        public override bool Update(float deltaT, Game game)
        {
            float speed = 0;
            // Retrieves the Singleton instance of the controller.
            Controller controller = Controller.ControllerInstance;

            if (controller.ControllerIsPluggedIn())
            {
                speed = controller.LeftJoystickSpeed();
            }
            else
            {
                bool W = controller.KeyboardIsKeyPressed(Keyboard.Key.W);
                bool A = controller.KeyboardIsKeyPressed(Keyboard.Key.A);
                bool S = controller.KeyboardIsKeyPressed(Keyboard.Key.S);
                bool D = controller.KeyboardIsKeyPressed(Keyboard.Key.D);
                if (W || A || S || D)
                {
                    speed = 100;
                    if (S && A)
                    {
                        Angle = 135;
                    }
                    else if (S && D)
                    {
                        Angle = 45;
                    }
                    else if (W && A)
                    {
                        Angle = 225;
                    }
                    else if (W && D)
                    {
                        Angle = 315;
                    }
                    else if (W)
                    {
                        Angle = 270;
                    }
                    else if (A)
                    {
                        Angle = 180;
                    }
                    else if (S)
                    {
                        Angle = 90;
                    }
                    else if (D)
                    {
                        Angle = 0;
                    }
                }
                else
                {
                    speed = 0;
                }
            }

            // Checks to see if the left joystick is tilted at least 30% from it's neutral position.
            // This prevents involuntary movement in case the joystick is slightly slack.
            if (speed > 30)
            {
                isMoving = true;
                // The joystick's speed is about 100 when fully tilted in a direction.
                // Here we divide that amount by 18 so the hero's speed is never more than 5.55f
                Speed = speed / 18;
                if (controller.ControllerIsPluggedIn())
                {
                    Angle = controller.LeftJoystickAngle();
                }
                // Temporary variable to validate whether or not the ship is outside the bounds of the game.
                Vector2f temp = Position + Direction * Speed;

                // Keeps the Hero's ship inside the game area.
                if (temp.X <= 20)
                {
                    if (Angle > 0)
                    {
                        Angle = 90;
                    }
                    else
                    {
                        Angle = -90;
                    }
                }
                else if (temp.X >= Game.GAME_WIDTH - 20)
                {
                    if (Angle > 0)
                    {
                        Angle = 90;
                    }
                    else
                    {
                        Angle = -90;
                    }
                }
                else if (temp.Y <= 20)
                {
                    if (Angle < -90)
                    {
                        Angle = 180;
                    }
                    else
                    {
                        Angle = 0;
                    }
                }
                else if (temp.Y >= Game.GAME_HEIGHT - 20)
                {
                    if (Angle < 90)
                    {
                        Angle = 0;
                    }
                    else
                    {
                        Angle = -180;
                    }
                }

                // After potential angle adjustments above, the temporary var is updated to re-validate the new path.
                temp = Position + Direction * Speed;
                if (!(temp.X <= 20) && !(temp.X >= Game.GAME_WIDTH - 20) && !(temp.Y <= 20) && !(temp.Y >= Game.GAME_HEIGHT - 20))
                {
                    SmokeParticle smokeParticle = new SmokeParticle(Type, Position.X, Position.Y, 4, Speed / 2, false, 100, 15, 0.0f, 5, 1)
                    {
                        Angle = Angle - 180
                    };
                    game.smokeParticles.Add(smokeParticle);
                    Advance(Speed);
                }
            }
            else
            {
                isMoving = false;
            }

            // Checks to see if the right joystick is tilted at least 30% from it's neutral position.
            // This prevents involuntary shooting in case the joystick is slightly slack.
            if (controller.RightJoystickSpeed() > 30 || controller.MouseButtonIsPressed(Mouse.Button.Left) && !controller.ControllerIsPluggedIn())
            {
                Fire(game);
            }

            // Checks to see if the right bumper on the controller has been pressed.
            // This if/else statement ensures that the player must release the right bumper and press it again to shoot a second bomb.
            if (controller.ControllerIsButtonPressed(5) || controller.KeyboardIsKeyPressed(Keyboard.Key.Space) && !controller.ControllerIsPluggedIn())
            {
                if (!bombButtonStillHeld)
                {
                    bombButtonStillHeld = true;
                    FireBomb(game);
                }
            }
            else
            {
                bombButtonStillHeld = false;
            }

            // If the hero's life falls to 0 or less, the game is lost.
            if (life <= 0)
            {
                IsAlive = false;
                return(false);
            }
            return(true);
        }