public void UpdateSong(ContentManager content, Character hero, Ennemy ennemy) { if (ennemy.is_in_bound(hero.Hitbox.X, hero.Hitbox.Y) && compteur < 1) //attente de réglage <-- LOL { if (numberOfSong == 2) numberOfSong = 0; else numberOfSong++; MediaPlayer.Play(songs[numberOfSong]); compteur++; } /* if (!hero.is_in_bound(hero.Hitbox.X, hero.Hitbox.Y) && compteur > 0) { if (numberOfSong == 2) numberOfSong = 0; else numberOfSong++; MediaPlayer.Play(songs[numberOfSong]); compteur++; } */ }
/* GraphicsDeviceManager graphics; enum IAState { Chasing, Caught, Wander } const float MaxIASpeed = 5.0f; const float IATurnSpeed = 0.10f; const float IAChaseDistance = 250.0f; const float IACaughtDistance = 60.0f; const float IAHysteresis = 15.0f; Texture2D IATexture; Vector2 IATextureCenter; Vector2 IAPosition; IAState IaState = IAState.Wander; float IAOrientation; Vector2 IAWanderDirection; Texture2D heroTexture; Vector2 heroTextureCenter; Vector2 heroPosition; Random random = new Random(); public void updateIA(Character hero, Ennemy ennemy) { heroPosition = new Vector2(hero.Hitbox.X, hero.Hitbox.Y); IAPosition = new Vector2(ennemy.IAHitbox.X, ennemy.IAHitbox.Y); float IAChaseThreshold = IAChaseDistance; float IACaughtThreshold = IACaughtDistance; if (IaState == IAState.Wander) { IAChaseThreshold -= IAHysteresis / 2; } else if (IaState == IAState.Chasing) { IACaughtThreshold += IAHysteresis / 2; } float distanceFromHero = Vector2.Distance(IAPosition, heroPosition); if (distanceFromHero > IACaughtThreshold) { IaState = IAState.Wander; } else if (distanceFromHero > IACaughtThreshold) { IaState = IAState.Chasing; } else { IaState = IAState.Caught; } float currentIASpeed; if (IaState == IAState.Chasing) { IAOrientation = TurnToFace(IAPosition, heroPosition, IAOrientation, IATurnSpeed); currentIASpeed = MaxIASpeed; } else if (IaState == IAState.Wander) { Wander(IAPosition, ref IAWanderDirection, ref IAOrientation, IATurnSpeed); currentIASpeed = .25f * MaxIASpeed; } else { currentIASpeed = 0.0f; } Vector2 heading = new Vector2((float)Math.Cos(IAOrientation), (float)Math.Sign(IAOrientation)); IAPosition += heading * currentIASpeed; } private void Wander(Vector2 position, ref Vector2 wanderDirection, ref float orientation, float turnSpeed) { wanderDirection.X += MathHelper.Lerp(-.25f, .25f, (float)random.NextDouble()); wanderDirection.Y += MathHelper.Lerp(-.25f, .25f, (float)random.NextDouble()); if (wanderDirection != Vector2.Zero) { wanderDirection.Normalize(); } orientation = TurnToFace(position, position + wanderDirection, orientation, .15f * turnSpeed); Vector2 screenCenter = Vector2.Zero; screenCenter.X = 624 / 2; screenCenter.Y = 480 / 2; float distanceFromScreenCenter = Vector2.Distance(screenCenter, position); float MaxDistanceFromScreenCenter = Math.Min(screenCenter.Y, screenCenter.X); float normalizedDistance = distanceFromScreenCenter / MaxDistanceFromScreenCenter; float turnToCenterSpeed = .3f * normalizedDistance * normalizedDistance * turnSpeed; orientation = TurnToFace(position, screenCenter, orientation, turnToCenterSpeed); } private static float TurnToFace(Vector2 position, Vector2 faceThis, float currentAngle, float turnSpeed) { float x = faceThis.X - position.X; float y = faceThis.Y - position.Y; float desiredAngle = (float)Math.Atan2(y, x); float difference = WrapAngle(desiredAngle - currentAngle); difference = MathHelper.Clamp(difference, -turnSpeed, turnSpeed); return WrapAngle(currentAngle + difference); } private static float WrapAngle(float radians) { while (radians < -MathHelper.Pi) { radians += MathHelper.TwoPi; } while (radians > MathHelper.Pi) { radians -= MathHelper.TwoPi; } return radians; } */ //IA Soutenance 3. /* public void UpdatePosIA(Character hero, Ennemy ennemy, Vector2[] posTreeTab, Vector2[] posWaterTab, Vector2[] posStoneTab, Vector2[] posGateTab, Texture2D heroExample, Texture2D[] listOfTextures, int MaxWidth, int MaxHeight) { if (ennemy.is_in_bound(hero.Hitbox.X, hero.Hitbox.Y)) { // ennemy.PlayerSpeed = 2; // Game1.IAState.Chasing; if (ennemy.IAHitbox.X > hero.Hitbox.X + hero.Hitbox.Width && ennemy.IAHitbox.Y > hero.Hitbox.Y && Collisions.libreHeroLeft(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, heroExample, listOfTextures, MaxWidth, MaxHeight) && Collisions.libreHeroUp(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, heroExample, listOfTextures, MaxWidth, MaxHeight)) { ennemy.IAHitbox.X -= ennemy.PlayerSpeed; ennemy.IAHitbox.Y -= ennemy.PlayerSpeed; ennemy.Direction = Direction.UpLeft; ennemy.Animate(); } else if (ennemy.IAHitbox.X < hero.Hitbox.X - hero.Hitbox.Width && ennemy.IAHitbox.Y > hero.Hitbox.Y && Collisions.libreHeroUp(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, heroExample, listOfTextures, MaxWidth, MaxHeight) && Collisions.libreHeroRight(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, heroExample, listOfTextures, MaxWidth, MaxHeight)) { ennemy.IAHitbox.X += ennemy.PlayerSpeed; ennemy.IAHitbox.Y -= ennemy.PlayerSpeed; ennemy.Direction = Direction.UpRight; ennemy.Animate(); } else if (ennemy.IAHitbox.X > hero.Hitbox.X && ennemy.IAHitbox.Y < hero.Hitbox.Y - hero.Hitbox.Height && Collisions.libreHeroDown(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, heroExample, listOfTextures, MaxWidth, MaxHeight) && Collisions.libreHeroLeft(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, heroExample, listOfTextures, MaxWidth, MaxHeight)) { ennemy.IAHitbox.X -= ennemy.PlayerSpeed; ennemy.IAHitbox.Y += ennemy.PlayerSpeed; ennemy.Direction = Direction.DownLeft; ennemy.Animate(); } else if (ennemy.IAHitbox.X < hero.Hitbox.X && ennemy.IAHitbox.Y < hero.Hitbox.Y - hero.Hitbox.Height && Collisions.libreHeroDown(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, heroExample, listOfTextures, MaxWidth, MaxHeight) && Collisions.libreHeroRight(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, heroExample, listOfTextures, MaxWidth, MaxHeight)) { ennemy.IAHitbox.X += ennemy.PlayerSpeed; ennemy.IAHitbox.Y += ennemy.PlayerSpeed; ennemy.Direction = Direction.DownRight; ennemy.Animate(); } else if (ennemy.IAHitbox.X > hero.Hitbox.X + hero.Hitbox.Width && Collisions.libreHeroLeft(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, heroExample, listOfTextures, MaxWidth, MaxHeight)) { ennemy.IAHitbox.X -= ennemy.PlayerSpeed; ennemy.Direction = Direction.Left; ennemy.Animate(); } else if (ennemy.IAHitbox.X < hero.Hitbox.X - hero.Hitbox.Width && Collisions.libreHeroRight(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, heroExample, listOfTextures, MaxWidth, MaxHeight)) { ennemy.IAHitbox.X += ennemy.PlayerSpeed; ennemy.Direction = Direction.Right; ennemy.Animate(); } else if (ennemy.IAHitbox.Y > hero.Hitbox.Y + hero.Hitbox.Height && Collisions.libreHeroUp(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, heroExample, listOfTextures, MaxWidth, MaxHeight)) { ennemy.IAHitbox.Y -= ennemy.PlayerSpeed; ennemy.Direction = Direction.Up; ennemy.Animate(); } else if (ennemy.IAHitbox.Y < hero.Hitbox.Y - hero.Hitbox.Height && Collisions.libreHeroDown(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, heroExample, listOfTextures, MaxWidth, MaxHeight)) { ennemy.IAHitbox.Y += ennemy.PlayerSpeed; ennemy.Direction = Direction.Down; ennemy.Animate(); } } } */ public void RandomMovements(Character hero, Ennemy ennemy, Vector2[] posTreeTab, Vector2[] posWaterTab, Vector2[] posStoneTab, Vector2[] posGateTab, Texture2D heroExample, Texture2D[] listOfTextures, int MaxWidth, int MaxHeight) { }
public void updatePosition(PlayerType type, KeyboardState kbState, ref Background backG, Vector2[] posTreeTab, Vector2[] posWaterTab, Vector2[] posStoneTab, Vector2[] posGateTab, Texture2D spriteExample, Texture2D[] listOfTextures, int MaxWidth, int MaxHeight, int initPosX, int initPosY, int direc, Character hero, Ennemy ennemy) { if (type == PlayerType.Hero) { if (kbState.IsKeyDown(Keys.Up) && kbState.IsKeyDown(Keys.Left) // flèches haut et gauche appuyées && Collisions.libreHeroUp(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight) && Collisions.libreHeroLeft(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)) { this.Direction = TLN_The_Last_Ninja.Direction.UpLeft; this.Hitbox.X -= this.Speed; this.Hitbox.Y -= this.Speed; this.Animate(); } else if (kbState.IsKeyDown(Keys.Up) && kbState.IsKeyDown(Keys.Right) // flèches haut et droite appuyées && Collisions.libreHeroUp(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight) && Collisions.libreHeroRight(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)) { this.Direction = TLN_The_Last_Ninja.Direction.UpRight; this.Hitbox.X += this.Speed; this.Hitbox.Y -= this.Speed; this.Animate(); } else if (kbState.IsKeyDown(Keys.Down) && kbState.IsKeyDown(Keys.Left) // flèches bas et gauche appuyées && Collisions.libreHeroDown(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight) && Collisions.libreHeroLeft(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)) { this.Direction = TLN_The_Last_Ninja.Direction.DownLeft; this.Hitbox.X -= this.Speed; this.Hitbox.Y += this.Speed; this.Animate(); } else if (kbState.IsKeyDown(Keys.Down) && kbState.IsKeyDown(Keys.Right) // flèches bas et droite appuyées && Collisions.libreHeroDown(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight) && Collisions.libreHeroRight(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)) { this.Direction = TLN_The_Last_Ninja.Direction.DownRight; this.Hitbox.X += this.Speed; this.Hitbox.Y += this.Speed; this.Animate(); } else if (kbState.IsKeyDown(Keys.Up) // flèche haut appuyée && Collisions.libreHeroUp(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)) //test collisions avec dessus du héros { this.Direction = TLN_The_Last_Ninja.Direction.Up; this.Hitbox.Y -= this.Speed; this.Animate(); } else if (kbState.IsKeyDown(Keys.Down) // flèche bas appuyée && Collisions.libreHeroDown(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)) //test collisions avec dessous du héros { this.Direction = TLN_The_Last_Ninja.Direction.Down; this.Hitbox.Y += this.Speed; this.Animate(); } else if (kbState.IsKeyDown(Keys.Left) // flèche gauche appuyée && Collisions.libreHeroLeft(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)) //test collisions avec gauche du héros { this.Direction = TLN_The_Last_Ninja.Direction.Left; this.Hitbox.X -= this.Speed; this.Animate(); } else if (kbState.IsKeyDown(Keys.Right) // flèche droite appuyée && Collisions.libreHeroRight(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)) //test collisions avec droite du héros { this.Direction = TLN_The_Last_Ninja.Direction.Right; this.Hitbox.X += this.Speed; this.Animate(); } else if (kbState.IsKeyUp(Keys.Up) && (kbState.IsKeyUp(Keys.Down) && (kbState.IsKeyUp(Keys.Left) && (kbState.IsKeyUp(Keys.Right))))) // ici on empeche le sprite de moonwalk quand on n'appuie sur aucune touche ! { this.FrameColumn = 1; // faut remplacer par la colonne de notre sprite! this.Timer = 0; } switch (this.Direction) // switch = plusieurs if ici on donne l'effet inverse au sprite. { case Direction.Up: this.FrameLine = 3; // remplacer par les bons chiffres ! this.Effects = SpriteEffects.None; break; case Direction.Down: this.FrameLine = 1; this.Effects = SpriteEffects.None; break; case Direction.Left: this.FrameLine = 2; this.Effects = SpriteEffects.None; break; case Direction.Right: this.FrameLine = 2; this.Effects = SpriteEffects.FlipHorizontally; break; case Direction.DownLeft: this.FrameLine = 4; this.Effects = SpriteEffects.None; break; case Direction.UpRight: this.FrameLine = 5; this.Effects = SpriteEffects.None; break; case Direction.UpLeft: this.FrameLine = 7; this.Effects = SpriteEffects.None; break; case Direction.DownRight: this.FrameLine = 6; this.Effects = SpriteEffects.None; break; } } if (type == PlayerType.Ennemy) { if (ennemy.is_in_bound(hero.Hitbox.X, hero.Hitbox.Y)) { if (ennemy.IAHitbox.X > hero.Hitbox.X + hero.Hitbox.Width && ennemy.IAHitbox.Y > hero.Hitbox.Y && Collisions.libreHeroLeft(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight) && Collisions.libreHeroUp(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)) { ennemy.IAHitbox.X -= ennemy.PlayerSpeed; ennemy.IAHitbox.Y -= ennemy.PlayerSpeed; ennemy.Direction = Direction.UpLeft; ennemy.Animate(); } else if (ennemy.IAHitbox.X < hero.Hitbox.X - hero.Hitbox.Width && ennemy.IAHitbox.Y > hero.Hitbox.Y && Collisions.libreHeroUp(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight) && Collisions.libreHeroRight(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)) { ennemy.IAHitbox.X += ennemy.PlayerSpeed; ennemy.IAHitbox.Y -= ennemy.PlayerSpeed; ennemy.Direction = Direction.UpRight; ennemy.Animate(); } else if (ennemy.IAHitbox.X > hero.Hitbox.X && ennemy.IAHitbox.Y < hero.Hitbox.Y - hero.Hitbox.Height && Collisions.libreHeroDown(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight) && Collisions.libreHeroLeft(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)) { ennemy.IAHitbox.X -= ennemy.PlayerSpeed; ennemy.IAHitbox.Y += ennemy.PlayerSpeed; ennemy.Direction = Direction.DownLeft; ennemy.Animate(); } else if (ennemy.IAHitbox.X < hero.Hitbox.X && ennemy.IAHitbox.Y < hero.Hitbox.Y - hero.Hitbox.Height && Collisions.libreHeroDown(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight) && Collisions.libreHeroRight(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)) { ennemy.IAHitbox.X += ennemy.PlayerSpeed; ennemy.IAHitbox.Y += ennemy.PlayerSpeed; ennemy.Direction = Direction.DownRight; ennemy.Animate(); } else if (ennemy.IAHitbox.X > hero.Hitbox.X + hero.Hitbox.Width && Collisions.libreHeroLeft(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)) { ennemy.IAHitbox.X -= ennemy.PlayerSpeed; ennemy.Direction = Direction.Left; ennemy.Animate(); } else if (ennemy.IAHitbox.X < hero.Hitbox.X - hero.Hitbox.Width && Collisions.libreHeroRight(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)) { ennemy.IAHitbox.X += ennemy.PlayerSpeed; ennemy.Direction = Direction.Right; ennemy.Animate(); } else if (ennemy.IAHitbox.Y > hero.Hitbox.Y /*+ hero.Hitbox.Height*/ && Collisions.libreHeroUp(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)) { ennemy.IAHitbox.Y -= ennemy.PlayerSpeed; ennemy.Direction = Direction.Up; ennemy.Animate(); } else if (ennemy.IAHitbox.Y < hero.Hitbox.Y /*- hero.Hitbox.Height*/ && Collisions.libreHeroDown(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)) { ennemy.IAHitbox.Y += ennemy.PlayerSpeed; ennemy.Direction = Direction.Down; ennemy.Animate(); } } else { if (direc == 0 && Collisions.libreHeroRight(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)) { this.IAHitbox.X += this.Speed; this.Direction = TLN_The_Last_Ninja.Direction.Right; this.Animate(); } if (direc == 1 && Collisions.libreHeroDown(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)) { this.IAHitbox.Y += this.Speed; this.Direction = TLN_The_Last_Ninja.Direction.Down; this.Animate(); } if (direc == 2 && Collisions.libreHeroLeft(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)) { this.IAHitbox.X -= this.Speed; this.Direction = TLN_The_Last_Ninja.Direction.Left; this.Animate(); } else if (direc == 3 && Collisions.libreHeroUp(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)) { this.IAHitbox.Y -= this.Speed; this.Direction = TLN_The_Last_Ninja.Direction.Up; this.Animate(); } } } switch (this.Direction) // switch = plusieurs if ici on donne l'effet inverse au sprite. { case Direction.Up: this.FrameLine = 3; // remplacer par les bons chiffres ! this.Effects = SpriteEffects.None; break; case Direction.Down: this.FrameLine = 1; this.Effects = SpriteEffects.None; break; case Direction.Left: this.FrameLine = 2; this.Effects = SpriteEffects.None; break; case Direction.Right: this.FrameLine = 2; this.Effects = SpriteEffects.FlipHorizontally; break; } if (type == PlayerType.Munition) { } }