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 }