//public Fantome(Texture2D fantome) //{ // this.fantome = fantome; //} public virtual void Initialize(string namemap, int jet, int level) { this.j = jet; if (level == 1) fantome_position = new Vector2(12 * size, 10 * size); else fantome_position = new Vector2(12 * size, 13 * size); direction_fantome = Direction_fantome.left; old_direction_fantome = Old_direction_fantome.left; map = new Bitmap(".../.../.../" + namemap); is_manger = false; nb_tour_manger = 0; retard = 0; }
public virtual void Update(ref int[,] tab, string namemap, int level, Pacman pacman) { test_u = false; test_r = false; test_l = false; test_d = false; bool test = false; if (!is_manger) { // position pacman en x et y en entier int pos_x = Convert.ToInt32(fantome_position.X); int pos_y = Convert.ToInt32(fantome_position.Y); if (direction_fantome != Direction_fantome.up && Check_pixel(pos_x, pos_y - 5, map) && Check_pixel(pos_x + fantome.Width, pos_y - 5, map)) test_u = true; if (direction_fantome != Direction_fantome.down && Check_pixel(pos_x, pos_y + fantome.Height + 5, map) && Check_pixel(pos_x + fantome.Width, pos_y + fantome.Height + 5, map)) test_d = true; if (direction_fantome != Direction_fantome.right && Check_pixel(pos_x + fantome.Width + 5, pos_y, map) && Check_pixel(pos_x + fantome.Width + 5, pos_y + fantome.Height, map)) test_r = true; if (direction_fantome != Direction_fantome.left && Check_pixel(pos_x - 5, pos_y, map) && Check_pixel(pos_x - 5, pos_y + fantome.Height, map)) test_l = true; // si pacman plsu haut que fantomes if (test_u && pacman.Pacman_position.Y < fantome_position.Y) { direction_fantome = Direction_fantome.up; } // si pacman plus bas que fantome if (test_r && pacman.Pacman_position.Y > fantome_position.Y) { direction_fantome = Direction_fantome.down; } // si pacman plus à droite que fantome if (test_r && pacman.Pacman_position.X > fantome_position.X) { direction_fantome = Direction_fantome.right; } // si pacman plus à gauche que fantome if (test_l && pacman.Pacman_position.X < fantome_position.X) { direction_fantome = Direction_fantome.left; } // gestion des directions if (direction_fantome == Direction_fantome.up && Check_pixel(pos_x, pos_y - 2, map) && Check_pixel(pos_x + fantome.Width, pos_y - 2, map)) { fantome_position.Y = fantome_position.Y - speed; test = true; } else if (direction_fantome == Direction_fantome.down && Check_pixel(pos_x, pos_y + fantome.Height + 2, map) && Check_pixel(pos_x + fantome.Width, pos_y + fantome.Height + 2, map)) { fantome_position.Y = fantome_position.Y + speed; test = true; } else if (direction_fantome == Direction_fantome.right && Check_pixel(pos_x + fantome.Width + 2, pos_y, map) && Check_pixel(pos_x + fantome.Width + 2, pos_y + fantome.Height, map)) { fantome_position.X = fantome_position.X + speed; test = true; } else if (direction_fantome == Direction_fantome.left && Check_pixel(pos_x - 2, pos_y, map) && Check_pixel(pos_x - 2, pos_y + fantome.Height, map)) { fantome_position.X = fantome_position.X - speed; test = true; } while (!test) { int jet = rand.Next(1, 100); if (jet < 25 && test_u) { direction_fantome = Direction_fantome.up; test = true; } else if (jet < 50 && test_d) { direction_fantome = Direction_fantome.down; test = true; } else if (jet < 75 && test_r) { direction_fantome = Direction_fantome.right; test = true; } else if (test_l) { direction_fantome = Direction_fantome.left; test = true; } } } else { nb_tour_manger++; if (nb_tour_manger > 500) { this.Initialize(namemap, this.j, level); } } if (direction_fantome == Direction_fantome.up) old_direction_fantome = Old_direction_fantome.up; else if (direction_fantome == Direction_fantome.down) old_direction_fantome = Old_direction_fantome.down; else if (direction_fantome == Direction_fantome.left) old_direction_fantome = Old_direction_fantome.left; else if (direction_fantome == Direction_fantome.right) old_direction_fantome = Old_direction_fantome.right; }
public virtual void Update(ref int[,] tab, string namemap, int level) { test_u = false; test_r = false; test_l = false; test_d = false; bool test = false; if (!is_manger) { // position pacman en x et y en entier int pos_x = Convert.ToInt32(fantome_position.X); int pos_y = Convert.ToInt32(fantome_position.Y); // gestion des directions if (direction_fantome == Direction_fantome.up && Check_pixel(pos_x, pos_y - 2, map) && Check_pixel(pos_x + fantome.Width, pos_y - 2, map)) { fantome_position.Y = fantome_position.Y - speed; test = true; } else if (direction_fantome == Direction_fantome.down && Check_pixel(pos_x, pos_y + fantome.Height + 2, map) && Check_pixel(pos_x + fantome.Width, pos_y + fantome.Height + 2, map)) { fantome_position.Y = fantome_position.Y + speed; test = true; } else if (direction_fantome == Direction_fantome.right && Check_pixel(pos_x + fantome.Width + 2, pos_y, map) && Check_pixel(pos_x + fantome.Width + 2, pos_y + fantome.Height, map)) { fantome_position.X = fantome_position.X + speed; test = true; } else if (direction_fantome == Direction_fantome.left && Check_pixel(pos_x - 2, pos_y, map) && Check_pixel(pos_x - 2, pos_y + fantome.Height, map)) { fantome_position.X = fantome_position.X - speed; test = true; } if (direction_fantome != Direction_fantome.up && Check_pixel(pos_x, pos_y - 5, map) && Check_pixel(pos_x + fantome.Width, pos_y - 5, map)) test_u = true; if (direction_fantome != Direction_fantome.down && Check_pixel(pos_x, pos_y + fantome.Height + 5, map) && Check_pixel(pos_x + fantome.Width, pos_y + fantome.Height + 5, map)) test_d = true; if (direction_fantome != Direction_fantome.right && Check_pixel(pos_x + fantome.Width + 5, pos_y, map) && Check_pixel(pos_x + fantome.Width + 5, pos_y + fantome.Height, map)) test_r = true; if (direction_fantome != Direction_fantome.left && Check_pixel(pos_x - 5, pos_y, map) && Check_pixel(pos_x - 5, pos_y + fantome.Height, map)) test_l = true; // si pacman bloqué while (test == false) { int jet = rand.Next(1, 41); if (jet < 10 && test_u && (int)direction_fantome % 2 == 1) { direction_fantome = Direction_fantome.up; test = true; } else if (jet < 20 && test_d && (int)direction_fantome % 2 == 1) { direction_fantome = Direction_fantome.down; test = true; } else if (jet < 30 && test_r && (int)direction_fantome % 2 == 0) { direction_fantome = Direction_fantome.right; test = true; } else if (jet < 40 && test_l && (int)direction_fantome % 2 == 0) { direction_fantome = Direction_fantome.left; test = true; } } if ((int)old_direction_fantome == (int)direction_fantome) retard++; else retard = 0; // random pour changement de direction if ((int)direction_fantome % 2 == 1 && (test_u || test_d) && retard > 200) { test = false; while (!test) { int jet = rand.Next(1, 800); if (jet < 360 && test_u) { direction_fantome = Direction_fantome.up; test = true; } else if (jet < 770 && test_d) { direction_fantome = Direction_fantome.down; test = true; } else { test = true; } } } else if ((int)direction_fantome % 2 == 0 && (test_r || test_l) && retard > 200) { test = false; while (!test) { int jet = rand.Next(1, 800); if (jet < 360 && test_r) { direction_fantome = Direction_fantome.right; test = true; } else if (jet < 700 && test_l) { direction_fantome = Direction_fantome.left; test = true; } else { test = true; } } } } else { nb_tour_manger++; if (nb_tour_manger > 500) { this.Initialize(namemap, this.j, level); } } if (direction_fantome == Direction_fantome.up) old_direction_fantome = Old_direction_fantome.up; if (direction_fantome == Direction_fantome.down) old_direction_fantome = Old_direction_fantome.down; if (direction_fantome == Direction_fantome.left) old_direction_fantome = Old_direction_fantome.left; if (direction_fantome == Direction_fantome.right) old_direction_fantome = Old_direction_fantome.right; }