Exemplo n.º 1
0
        public void Update(GameTime gametime, List <ObjCollisionable> Obstacles, SoundEffect JumpEffect, SoundEffect ShootEffect, int NumShield)
        {
            Position += Speed;

            //Speed.X(MAX)
            if (Math.Abs(Speed.X) > 15)
            {
                if (Math.Sign(Speed.X) == -1)
                {
                    VitesseDepart = -15;
                }
                else
                {
                    VitesseDepart = 15;
                }
            }
            RecPerso.X   = Convert.ToInt32(Position.X) - RecPerso.Width / 2;
            RecPerso.Y   = Convert.ToInt32(Position.Y) - RecPerso.Height - (RecPerso.Height / 2);
            SurObject    = false;
            SousObject   = false;
            DroiteObject = false;
            GaucheObject = false;


            #region Obstacle

            if (Obstacles != null)
            {
                foreach (ObjCollisionable Objects in Obstacles)
                {
                    if (RecPerso.isOnTopOf(Objects.DimObj))
                    {
                        Speed.Y   = 0;
                        HasJump   = false;
                        Injure    = false;
                        Attack1   = false;
                        Gravity   = false;
                        SurObject = true;

                        if (Rebound)
                        {
                            Speed.Y -= 6;
                            HasJump  = true;
                            Rebound  = false;
                        }
                        break;
                    }
                    else
                    {
                        Gravity = true;
                    }

                    if (RecPerso.isOnBottomOf(Objects.DimObj))
                    {
                        SousObject = true;
                        Speed.Y    = 0;
                    }
                    else
                    if (RecPerso.isOnRightOf(Objects.DimObj))
                    {
                        DroiteObject = true;
                        SurObject    = true;
                        if (Objects.Loop)
                        {
                            Position.Y  -= 8;
                            DroiteObject = false;
                        }
                        else
                        {
                            Speed.X = 0;
                        }
                    }
                    if (RecPerso.isOnLeftOf(Objects.DimObj))
                    {
                        GaucheObject = true;
                        SurObject    = true;
                        if (Objects.Loop)
                        {
                            Position.Y  -= 8;
                            GaucheObject = false;
                        }
                        else
                        {
                            Speed.X = 0;
                        }
                    }
                    else
                    if (RecPerso.Intersects(Objects.DimObj))
                    {
                        Rotation = Objects.Rotation;

                        if (Objects.Loop)
                        {
                            Position.Y -= 6;
                        }
                    }
                }
            }
            #endregion

            if (!Enabled) //bloquer les bouton lors de la transformation
            {
                #region touche W,A,S,D
                if ((KeyboardHelper.KeyHold(Keys.W) || KeyboardHelper.KeyHold(Keys.Up)) && !HasJump)
                {
                    flip = SpriteEffects.None;

                    if (!OutofWindow(RecPerso, "W") && !SousObject)
                    {
                        if (!GravityActive)
                        {
                            Speed.Y = -2;
                            Speed.X = 0;
                            flip    = SpriteEffects.None;
                        }
                    }
                    else
                    {
                        Speed.Y = 0;
                    }
                }
                else if ((KeyboardHelper.KeyHold(Keys.A) || KeyboardHelper.KeyHold(Keys.Left)) && !EnBoule)
                {
                    if (!OutofWindow(RecPerso, "A") && !DroiteObject)
                    {
                        if (Speed.X > 0)
                        {
                            if (VitesseDepart > 2)
                            {
                                VitesseDepart -= 0.15f;
                            }
                            else
                            {
                                VitesseDepart = -2;
                            }
                        }

                        Speed.X        = VitesseDepart;
                        VitesseDepart -= (float)(gametime.ElapsedGameTime.TotalSeconds) * 4;
                        if (!HasJump && !Gravity)
                        {
                            Speed.Y = 0;
                        }

                        flip = SpriteEffects.FlipHorizontally;
                    }
                    else
                    {
                        Speed.X = 0;
                    }
                }
                else if ((KeyboardHelper.KeyHold(Keys.S) || KeyboardHelper.KeyHold(Keys.Down)) && !HasJump)
                {
                    if (!OutofWindow(RecPerso, "S") && !SurObject)
                    {
                        // Speed.Y = 2;
                        //Speed.X = 0;
                        //do nohting for now
                    }
                    else
                    {
                        Speed.Y = 0;
                        if (Speed.X > 0)
                        {
                            Speed.X -= (float)gametime.ElapsedGameTime.TotalSeconds * 3;
                        }
                        else if (Speed.X < 0)
                        {
                            Speed.X += (float)gametime.ElapsedGameTime.TotalSeconds * 3;
                        }
                    }
                }
                else if ((KeyboardHelper.KeyHold(Keys.D) || KeyboardHelper.KeyHold(Keys.Right)) && !EnBoule)
                {
                    if (!OutofWindow(RecPerso, "D") && !GaucheObject)
                    {
                        if (Speed.X < 0)
                        {
                            if (VitesseDepart < -2)
                            {
                                VitesseDepart += 0.15f;
                            }
                            else
                            {
                                VitesseDepart = 2;
                            }
                        }

                        Speed.X = VitesseDepart;

                        VitesseDepart += (float)gametime.ElapsedGameTime.TotalSeconds * 4;
                        if (!HasJump && !Gravity)
                        {
                            Speed.Y = 0;
                        }

                        flip = SpriteEffects.None;
                    }
                    else
                    {
                        Speed.X = 0;
                    }
                }
                else
                {
                    if (Speed.X > 0.5)
                    {
                        Speed.X       -= (float)gametime.ElapsedGameTime.TotalSeconds * 3;
                        VitesseDepart -= (float)gametime.ElapsedGameTime.TotalSeconds * 3;
                    }
                    else if (Speed.X < 0)
                    {
                        Speed.X       += (float)gametime.ElapsedGameTime.TotalSeconds * 3;
                        VitesseDepart += (float)gametime.ElapsedGameTime.TotalSeconds * 3;
                    }
                    else
                    {
                        Speed.X       = 0;
                        VitesseDepart = 2;
                    }
                    if (!GravityActive)
                    {
                        Speed.Y = 0;
                    }
                }

                #endregion
                #region Space
                if (GravityActive)
                {
                    if (KeyboardHelper.KeyPressed(Keys.Space) && HasJump)
                    {
                        if (NumShield == 0)
                        {
                            Attack1 = true;
                        }

                        else
                        {
                            Speed.Y = 7;
                            Rebound = true;
                        }
                    }
                    if (KeyboardHelper.KeyPressed(Keys.Space) && !HasJump && !bCrouch)
                    {
                        Position.Y -= 10;
                        Speed.Y     = -5;
                        RessourceSonic3.Jump.Play();
                        HasJump = true;
                        Gravity = true;
                        EnBoule = false;
                    }

                    if (Gravity)
                    {
                        float i = 1;
                        Speed.Y += 0.15f * i;
                    }

                    ///Pour aterrir au sol
                    if (GravityLimit)
                    {
                        if (Position.Y >= 500)
                        {
                            HasJump = false;
                            Gravity = false;
                            Attack1 = false;
                        }

                        else
                        {
                            Gravity = true;
                        }


                        if (!Gravity)
                        {
                            Speed.Y = 0f;
                        }
                    }
                }

                #endregion
                #region Boule et pente
                if (!SurObject && !DroiteObject && !GaucheObject && (EnBoule || bCrouch))
                {
                    if (Speed.X > -4 && Speed.X < 4)
                    {
                        if (flip == SpriteEffects.None)
                        {
                            Speed.X = 4;
                        }
                        else
                        {
                            Speed.X = -4;
                        }
                    }
                    EnBoule = true;
                }

                #endregion
                #region Animation Par rapport au touche
                bCrouch = false;
                #region Si Position X change
                if (Speed.X != 0)
                {
                    if (HasJump)
                    {
                        if (Attack1)
                        {
                            AnimationPlayer.PlayAnimation(Attack);
                            if (AnimationPlayer.FrameIndex == Attack.FrameCount - 1)
                            {
                                Attack1 = false;
                            }
                        }
                        else if (Injure)
                        {
                            AnimationPlayer.PlayAnimation(Hurt);
                        }

                        else
                        {
                            AnimationPlayer.PlayAnimation(JumpForwardNormal);
                        }
                    }

                    else if (KeyboardHelper.KeyPressed(Keys.S) || KeyboardHelper.KeyPressed(Keys.Down) || EnBoule)
                    {
                        AnimationPlayer.PlayAnimation(Rolling);
                        EnBoule = true;
                    }

                    else if (Math.Abs(Speed.X) > 9)
                    {
                        AnimationPlayer.PlayAnimation(Course);
                    }
                    else if (Math.Abs(Speed.X) > 6)
                    {
                        AnimationPlayer.PlayAnimation(MiCourse);
                    }
                    else
                    {
                        AnimationPlayer.PlayAnimation(WalkigNormal);
                    }

                    if (Math.Abs(Speed.X) < 2 && EnBoule)
                    {
                        VitesseDepart = 2;
                        EnBoule       = false;
                    }
                }
                #endregion
                #region Si Position X reste pareil
                else if (Speed.X == 0)
                {
                    if (HasJump)
                    {
                        if (Attack1)
                        {
                            AnimationPlayer.PlayAnimation(Attack);
                            if (AnimationPlayer.FrameIndex == Attack.FrameCount - 1)
                            {
                                Attack1 = false;
                            }
                        }
                        else if (Injure)
                        {
                            AnimationPlayer.PlayAnimation(Hurt);
                        }
                        else
                        {
                            AnimationPlayer.PlayAnimation(JumpNormal);
                        }
                    }

                    else if (KeyboardHelper.KeyHold(Keys.Down) || KeyboardHelper.KeyHold(Keys.S))
                    {
                        bCrouch = true;
                        if (KeyboardHelper.KeyPressed(Keys.Space))
                        {
                            ChargingTurbo = true;
                            NumberSpin++;
                            if (NumberSpin > 10)
                            {
                                NumberSpin = 10;
                            }

                            if (NumberSpin < 6)
                            {
                                RessourceSonic3.Spin.Play();
                            }
                            else
                            {
                                RessourceSonic3.Spin2.Play();
                            }

                            AnimationPlayer.PlayAnimation(SpiningCharge);
                            Ap2.PlayAnimation(DustSpin);
                        }
                        else if (!ChargingTurbo)
                        {
                            AnimationPlayer.PlayAnimation(Crouch);
                        }
                    }
                    else if (ChargingTurbo)
                    {
                        ChargingTurbo = false;
                        Ap2.PlayAnimation(null);
                        if (flip == SpriteEffects.None)
                        {
                            Speed.X = NumberSpin * 3;
                        }
                        else
                        {
                            Speed.X = -(NumberSpin * 3);
                        }
                        NumberSpin = 0;
                        EnBoule    = true;
                    }
                    else
                    {
                        AnimationPlayer.PlayAnimation(NothingNormal);
                        Ap2.PlayAnimation(null);
                    }
                }
                #endregion
                #endregion
            }

            else
            {
                Speed.X = 0; Speed.Y = 0; EnBoule = false;
            }

#warning si jamais bug avec les animation
            //les remettre ici-----------

            //------------------------------
        }
Exemplo n.º 2
0
        public void Update(List <ObjCollisionable> Obstacles, SoundEffect JumpEffect, SoundEffect ShootEffect)
        {
            Position += Speed;

            RecPerso.X   = Convert.ToInt32(Position.X) - 90 / 2;
            RecPerso.Y   = Convert.ToInt32(Position.Y) - 90 - (90 / 2);
            SurObject    = false;
            SousObject   = false;
            DroiteObject = false;
            GaucheObject = false;

            #region Obstacle

            if (Obstacles != null)
            {
                foreach (ObjCollisionable Objects in Obstacles)
                {
                    if (RecPerso.isOnTopOf(Objects.DimObj))
                    {
                        Speed.Y   = 0;
                        HasJump   = false;
                        Gravity   = false;
                        SurObject = true;
                        break;
                    }
                    else
                    {
                        Gravity = true;
                    }

                    if (RecPerso.isOnBottomOf(Objects.DimObj))
                    {
                        SousObject = true;
                        Speed.Y    = 0;
                    }
                    else
                    if (RecPerso.isOnRightOf(Objects.DimObj))
                    {
                        DroiteObject = true;
                        Speed.X      = 0;
                    }
                    if (RecPerso.isOnLeftOf(Objects.DimObj))
                    {
                        GaucheObject = true;
                        Speed.X      = 0;
                    }
                }
            }
            #endregion

            if (!Transformation) //bloquer les bouton lors de la transformation
            {
                #region touche W,A,S,D
                if (KeyboardHelper.KeyHold(Keys.W) || KeyboardHelper.KeyHold(Keys.Up) && !HasJump)
                {
                    flip = SpriteEffects.None;

                    if (KeyboardHelper.KeyPressed(Keys.C))
                    {
                        ShootUp = true;
                    }
                    if (!OutofWindow(RecPerso, "W") && !SousObject)
                    {
                        if (!GravityActive)
                        {
                            Speed.Y = -2;
                            Speed.X = 0;
                            flip    = SpriteEffects.None;
                        }
                    }
                    else
                    {
                        Speed.Y = 0;
                    }
                }
                else if (KeyboardHelper.KeyHold(Keys.A) || KeyboardHelper.KeyHold(Keys.Left))
                {
                    if (!OutofWindow(RecPerso, "A") && !DroiteObject)
                    {
                        Speed.X = -2;
                        if (!HasJump && !Gravity)
                        {
                            Speed.Y = 0;
                        }

                        if (KeyboardHelper.KeyHold(Keys.LeftShift))
                        {
                            Speed.X -= 2;
                            WalkigNormal.FrameTimer = CourseFrameTimer;
                        }
                        else
                        {
                            WalkigNormal.FrameTimer = WalkingFrameTimer;
                        }

                        flip = SpriteEffects.FlipHorizontally;
                    }
                    else
                    {
                        Speed.X = 0;
                    }
                }
                else if (KeyboardHelper.KeyHold(Keys.S) || KeyboardHelper.KeyHold(Keys.Down) && !HasJump)
                {
                    if (!OutofWindow(RecPerso, "S") && !SurObject)
                    {
                        Speed.Y = 2;
                        Speed.X = 0;
                        // flip = SpriteEffects.None;
                    }
                    else
                    {
                        Speed.Y = 0;
                    }
                }
                else if (KeyboardHelper.KeyHold(Keys.D) || KeyboardHelper.KeyHold(Keys.Right))
                {
                    if (!OutofWindow(RecPerso, "D") && !GaucheObject)
                    {
                        Speed.X = 2;
                        KeyboardHelper.InputRightPressed();
                        if (!HasJump && !Gravity)
                        {
                            Speed.Y = 0;
                        }

                        if (KeyboardHelper.KeyHold(Keys.LeftShift))
                        {
                            Speed.X += 2;
                            WalkigNormal.FrameTimer = CourseFrameTimer;
                        }
                        else
                        {
                            WalkigNormal.FrameTimer = WalkingFrameTimer;
                        }
                        flip = SpriteEffects.None;
                    }
                    else
                    {
                        Speed.X = 0;
                    }
                }
                else
                {
                    Speed.X = 0;
                    if (!GravityActive)
                    {
                        Speed.Y = 0;
                    }
                    Hula = false;
                }

                #endregion
                #region Space
                if (GravityActive)
                {
                    if (KeyboardHelper.KeyPressed(Keys.Space) && !HasJump && !bCrouch)
                    {
                        Position.Y -= 10;
                        Speed.Y     = -5;
                        if (JumpEffect != null)
                        {
                            JumpEffect.Play();
                        }
                        HasJump = true;
                        Gravity = true;
                    }

                    if (Gravity)
                    {
                        float i = 1;
                        Speed.Y += 0.15f * i;
                    }

                    ///Pour aterrir au sol
                    if (GravityLimit)
                    {
                        if (Position.Y >= 500)
                        {
                            HasJump = false;
                            Gravity = false;
                        }

                        else
                        {
                            Gravity = true;
                        }


                        if (!Gravity)
                        {
                            Speed.Y = 0f;
                        }
                    }
                }

                #endregion
                #region Transformation
                if (KeyboardHelper.KeyPressed(Keys.T))
                {
                    Transformation = true;
                }
                #endregion
                #region Hula
                if (KeyboardHelper.KeyHold(Keys.LeftAlt))
                {
                    Hula = true;
                }
                #endregion

                UpdateBullets();

                #region Shoot
                if (KeyboardHelper.KeyHold(Keys.C) && pastKey.IsKeyUp(Keys.C) && GravityActive)
                {
                    ShootAnim = true;
                    if (ShootEffect != null)
                    {
                        ShootEffect.Play();
                    }
                    Shoot();
                }
                pastKey = Keyboard.GetState();
                #endregion
            }

            else
            {
                Speed.X = 0; Speed.Y = 0;
            }


            #region Animation Par rapport au touche
            bCrouch = false;
            #region Si Position X change
            if (Speed.X != 0)
            {
                if (LoxiTransformation)
                {
                    if (HasJump)
                    {
                        AnimationPlayer.PlayAnimation(JumpForwardTransfo);
                    }
                    else if (Hula)
                    {
                        AnimationPlayer.PlayAnimation(Attack);
                    }
                    else
                    {
                        AnimationPlayer.PlayAnimation(WalkingTransfo);
                    }
                }
                else
                {
                    if (HasJump)
                    {
                        AnimationPlayer.PlayAnimation(JumpForwardNormal);
                    }
                    else if (ShootAnim)
                    {
                        if (ShootUp)
                        {
                            AnimationPlayer.PlayAnimation(ShootUpwardNormal);
                            if (AnimationPlayer.FrameIndex == 8)
                            {
                                ShootAnim = false;
                                ShootUp   = false;
                            }
                        }
                        else
                        {
                            AnimationPlayer.PlayAnimation(ShootNormal);
                            if (AnimationPlayer.FrameIndex == 10)
                            {
                                ShootAnim = false;
                            }
                        }
                    }
                    else
                    {
                        AnimationPlayer.PlayAnimation(WalkigNormal);
                    }
                }
            }
            #endregion
            #region Si Position X reste pareil
            else if (Speed.X == 0)
            {
                if (Transformation)
                {
                    AnimationPlayer.PlayAnimation(TransfoNormal);
                    if (AnimationPlayer.FrameIndex == 18)
                    {
                        Transformation = false;
                    }
                    LoxiTransformation = true;
                }
                else
                if (LoxiTransformation)
                {
                    if (HasJump)
                    {
                        AnimationPlayer.PlayAnimation(JumpTransfo);
                    }

                    else if (Hula)
                    {
                        AnimationPlayer.PlayAnimation(Attack);
                    }
                    else
                    {
                        AnimationPlayer.PlayAnimation(NothingTransfo);
                    }
                }
                else
                {
                    if (HasJump)
                    {
                        AnimationPlayer.PlayAnimation(JumpNormal);
                    }

                    else if (ShootAnim)
                    {
                        if (ShootUp)
                        {
                            AnimationPlayer.PlayAnimation(ShootUpwardNormal);
                            if (AnimationPlayer.FrameIndex == 8)
                            {
                                ShootAnim = false;
                                ShootUp   = false;
                            }
                        }
                        else
                        {
                            AnimationPlayer.PlayAnimation(ShootNormal);
                            if (AnimationPlayer.FrameIndex == 10)
                            {
                                ShootAnim = false;
                            }
                        }
                    }


                    else if (KeyboardHelper.KeyHold(Keys.Down) || KeyboardHelper.KeyHold(Keys.S))
                    {
                        bCrouch = true;
                        AnimationPlayer.PlayAnimation(Crouch);
                    }
                    else
                    {
                        AnimationPlayer.PlayAnimation(NothingNormal);
                    }
                }
            }
            #endregion
            #endregion
        }