public virtual void Update(GameTime gameTime, KeyboardState keyboard_state, ref int[,] tab_boulette, ref int score, ref int nb_boulette) { // logique de jeu pour deplacement if (keyboard_state.IsKeyDown(Keys.Down)) direction_pacman = Direction_pacman.down; if (keyboard_state.IsKeyDown(Keys.Up)) direction_pacman = Direction_pacman.up; if (keyboard_state.IsKeyDown(Keys.Right)) direction_pacman = Direction_pacman.right; if (keyboard_state.IsKeyDown(Keys.Left)) direction_pacman = Direction_pacman.left; // position pacman en x et y en entier int pos_x = Convert.ToInt32(pacman_position.X); int pos_y = Convert.ToInt32(pacman_position.Y); // ajustement x et y pour le mangeage de boulette float ajustement_x = 0; float ajustement_y = 0; // gestion des directions if (direction_pacman == Direction_pacman.up && Check_pixel(pos_x, pos_y - 2, map) && Check_pixel(pos_x + pacman.Width, pos_y - 2, map)) { pacman_position.Y = pacman_position.Y - speed; ajustement_x = 0; ajustement_y = 10; } else if (direction_pacman == Direction_pacman.down && Check_pixel(pos_x, pos_y + pacman.Height + 2, map) && Check_pixel(pos_x + pacman.Width, pos_y + pacman.Height + 2, map)) { pacman_position.Y = pacman_position.Y + speed; ajustement_x = 0; ajustement_y = -10; } else if (direction_pacman == Direction_pacman.right && Check_pixel(pos_x + pacman.Width + 2, pos_y, map) && Check_pixel(pos_x + pacman.Width + 2, pos_y + pacman.Height, map)) { pacman_position.X = pacman_position.X + speed; ajustement_x = -10; ajustement_y = 0; } else if (direction_pacman == Direction_pacman.left && Check_pixel(pos_x - 2, pos_y, map) && Check_pixel(pos_x - 2, pos_y + pacman.Height, map)) { pacman_position.X = pacman_position.X - speed; ajustement_x = +10; ajustement_y = 0; } // logique de jeu pour mangeage de boulette // position du pacman par rapport au tableau int positionX_tab = Convert.ToInt32((pacman_position.X + ajustement_x) / 28); int positionY_tab = Convert.ToInt32((pacman_position.Y + ajustement_y) / 28); // si pacman passe et que ca fait 0 alors on met 2 et plus de boulette if (tab_boulette[positionX_tab, positionY_tab] == '0') { tab_boulette[positionX_tab, positionY_tab] = 2; score = score + 10; nb_boulette--; } else if (tab_boulette[positionX_tab, positionY_tab] == '3') { tab_boulette[positionX_tab, positionY_tab] = 2; score = score + 10; is_invincible = true; nb_tours_invincilble = 1; nb_boulette--; } if (nb_tours_invincilble > 0 && nb_tours_invincilble < 850) { nb_tours_invincilble++; } else { nb_tours_invincilble = 0; is_invincible = false; } }
public virtual void Initialize(string mapbmp) { direction_pacman = Direction_pacman.right; pacman_position = new Vector2(28, 28); is_invincible = false; nb_tours_invincilble = 0; map = new Bitmap(".../.../.../"+mapbmp); }