//la fonction update pour les monstres public void Update(Ennemi ennemi, Joueur joueur) { lancerSort(ennemi, joueur); for (int i = 0; i < listeSorts.Count; i++) { listeSorts[i].Update(ennemi); if (!listeSorts[i].sortLance) this.listeSorts.RemoveAt(i); } }
public static void CollisionEnnemiDeplacement(Carte mapManager, Ennemi ennemi) { ennemi.blocage_haut = false; ennemi.blocage_bas = false; ennemi.blocage_gauche = false; ennemi.blocage_droit = false; foreach (List<Rectangle> rectangleligne in mapManager.collision) { foreach (Rectangle rectangle in rectangleligne) { if (new Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height).Intersects(ennemi.collisionhaut)) { ennemi.blocage_haut = true; } if (new Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height).Intersects(ennemi.collisionbas)) { ennemi.blocage_bas = true; } if (new Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height).Intersects(ennemi.collisiongauche)) { ennemi.blocage_gauche = true; } if (new Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height).Intersects(ennemi.collisiondroite)) { ennemi.blocage_droit = true; } } } foreach (List<Rectangle> rectangleligne in mapManager.murs.collision) { foreach (Rectangle rectangle in rectangleligne) { if (new Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height).Intersects(ennemi.collisionhaut)) { ennemi.blocage_haut = true; } if (new Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height).Intersects(ennemi.collisionbas)) { ennemi.blocage_bas = true; } if (new Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height).Intersects(ennemi.collisiongauche)) { ennemi.blocage_gauche = true; } if (new Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height).Intersects(ennemi.collisiondroite)) { ennemi.blocage_droit = true; } } } }
private void lancerSort(Ennemi ennemi, Joueur joueur) { Random rand = new Random(); if (rand.Next(0, 100) == 25) { switch (ennemi.sortMonstre) { case "lumiere": this.listeSorts.Add(new Sort("lumiere")); this.listeSorts[this.listeSorts.Count - 1].texture = this.lumiere.texture; this.listeSorts[this.listeSorts.Count - 1].textureActuelle = this.lumiere.textureActuelle; break; case "feu": this.listeSorts.Add(new Sort("feu")); this.listeSorts[this.listeSorts.Count - 1].texture = this.feu.texture; this.listeSorts[this.listeSorts.Count - 1].textureActuelle = this.feu.textureActuelle; break; default: break; } if (ennemi.mana - this.listeSorts[listeSorts.Count - 1].consoMana >= 0) { this.listeSorts[listeSorts.Count - 1].position.X = ennemi.rect[0, 0].X; this.listeSorts[listeSorts.Count - 1].position.Y = ennemi.rect[0, 0].Y; this.listeSorts[listeSorts.Count - 1].direction.X = joueur.rectangle.X - ennemi.rect[0, 0].X; this.listeSorts[listeSorts.Count - 1].direction.Y = joueur.rectangle.Y - ennemi.rect[0, 0].Y; if (Math.Abs(this.listeSorts[listeSorts.Count - 1].direction.X) > Math.Abs(this.listeSorts[listeSorts.Count - 1].direction.Y)) { this.listeSorts[listeSorts.Count - 1].direction.X /= Math.Abs(this.listeSorts[listeSorts.Count - 1].direction.Y); this.listeSorts[listeSorts.Count - 1].direction.Y /= Math.Abs(this.listeSorts[listeSorts.Count - 1].direction.Y); this.listeSorts[listeSorts.Count - 1].direction.X *= 2; this.listeSorts[listeSorts.Count - 1].direction.Y *= 2; } else { this.listeSorts[listeSorts.Count - 1].direction.Y /= Math.Abs(this.listeSorts[listeSorts.Count - 1].direction.X); this.listeSorts[listeSorts.Count - 1].direction.X /= Math.Abs(this.listeSorts[listeSorts.Count - 1].direction.X); this.listeSorts[listeSorts.Count - 1].direction.X *= 2; this.listeSorts[listeSorts.Count - 1].direction.Y *= 2; } ennemi.mana -= this.listeSorts[listeSorts.Count - 1].consoMana; this.listeSorts[listeSorts.Count - 1].portee = this.listeSorts[listeSorts.Count - 1].porteeInitiale; this.listeSorts[listeSorts.Count - 1].sortLance = true; } else { listeSorts.RemoveAt(listeSorts.Count - 1); } } }
public void Update(Ennemi ennemi) { if (this.sortLance && this.portee > 0) { this.compteur = (this.compteur + 1) % this.texture.Length; this.textureActuelle = this.texture[this.compteur]; this.position.X += this.direction.X; this.position.Y += this.direction.Y; this.portee--; this.collision.X = (int)this.position.X; this.collision.Y = (int)this.position.Y; this.collision.Width = this.textureActuelle.Width; this.collision.Height = this.textureActuelle.Height; } else { this.sortLance = false; this.position.X = ennemi.rect[0,0].X; this.position.Y = ennemi.rect[0, 0].Y; } }