internal override void Destroy() { GhostTimer.Stop(); if (BulletDodgeReactionTimer != null) { BulletDodgeReactionTimer.Stop(); } base.Destroy(); }
private void DrawingTimer_Tick(object sender, EventArgs e) { ShowScene(); if (Dead || ((((!RGhost.CaughtPacman(Pman)) && (!YGhost.CaughtPacman(Pman))) && (!BGhost.CaughtPacman(Pman))) && (!PGhost.CaughtPacman(Pman)))) { return; } Dead = true; Pman.ReduceTries(); GhostTimer.Stop(); PinkGhostAppearTimer = 25; }
private void Timer_Tick(object sender, EventArgs e) { GhostTimer.Interval = new TimeSpan(0, 0, 0, 0, new Random().Next(0, 2000)); if (TickCount >= 3) { TickCount = 0; if (Direction == Direction.Left) { Bullet <Player, Ghost> ghostBullet = new Bullet <Player, Ghost>(this, (int)(this.Coordinates.X - 1), (int)(this.Coordinates.Y), GameTable, this.Direction); } else if (Direction == Direction.Right) { Bullet <Player, Ghost> ghostBullet = new Bullet <Player, Ghost>(this, (int)(this.Coordinates.X + 1), (int)(this.Coordinates.Y), GameTable, this.Direction); } else if (Direction == Direction.Up) { Bullet <Player, Ghost> ghostBullet = new Bullet <Player, Ghost>(this, (int)(this.Coordinates.X), (int)(this.Coordinates.Y - 1), GameTable, this.Direction); } else if (Direction == Direction.Down) { Bullet <Player, Ghost> ghostBullet = new Bullet <Player, Ghost>(this, (int)(this.Coordinates.X), (int)(this.Coordinates.Y + 1), GameTable, this.Direction); } } Bullet <Ghost, Player> BulletToDodge = null; //only if the ghost is not trying to dodge the bullet if (IsBulletCollisionTrajectory(this.Coordinates, out BulletToDodge) == false) { //Find the player and follow him if (Player.Coordinates.X > this.Coordinates.X) { var newCoord = new Point(this.Coordinates.X + 1, this.Coordinates.Y); if (!IsBulletCollisionTrajectory(newCoord)) { this.Direction = Direction.Right; UiContainer.RenderTransform = new RotateTransform(90); this.Coordinates = newCoord; } } else if (Player.Coordinates.X < this.Coordinates.X) { var newCoord = new Point(this.Coordinates.X - 1, this.Coordinates.Y); if (!IsBulletCollisionTrajectory(newCoord)) { this.Direction = Direction.Left; UiContainer.RenderTransform = new RotateTransform(-90); this.Coordinates = newCoord; } } if (Player.Coordinates.Y > this.Coordinates.Y) { var newCoord = new Point(this.Coordinates.X, this.Coordinates.Y + 1); if (!IsBulletCollisionTrajectory(newCoord)) { this.Direction = Direction.Down; UiContainer.RenderTransform = new RotateTransform(180); this.Coordinates = newCoord; } } else if (Player.Coordinates.Y < this.Coordinates.Y) { var newCoord = new Point(this.Coordinates.X, this.Coordinates.Y - 1); if (!IsBulletCollisionTrajectory(newCoord)) { this.Direction = Direction.Up; UiContainer.RenderTransform = new RotateTransform(0); this.Coordinates = newCoord; } } if (this.Coordinates.X == Player.Coordinates.X && this.Coordinates.Y == Player.Coordinates.Y) { GhostTimer.Stop(); GameTable.OnGameOver(); } } else { TryDodgeBullet(BulletToDodge); } AdjustCoordinatesToFitIntoTable(); TickCount++; }
private void PacmanTimer_Tick(object sender, EventArgs e) { HighScore hs; DialogResult dr; if (!Dead) { if (PacmanPicState == 1) { Pman.SetImage(Properties.Resources.Pacman2); PacmanPicState = 2; } else { Pman.SetImage(Properties.Resources.Pacman1); PacmanPicState = 1; } Pman.RotatePacman(); Pman.MovePacman(maze.GetMaze()); if (maze.GameWin()) { Pman.SetScore(Pman.GetTries() * 200); PacmanTimer.Stop(); GhostTimer.Stop(); hs = new HighScore(Pman); hs.ShowDialog(); hs.Close(); dr = MessageBox.Show("Do you want to play again?", "Game Over", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { StartGame(); } else { DrawingTimer.Stop(); Close(); } } } else { if (i < 10) { Pman.ResetDeathAnimationFrames(); Pman.SetImage(Pman.GetAnimation()[i]); Pman.RotatePacman(); i++; } else { i = 0; Pman.SetImage(Properties.Resources.Pacman1); ResetLocations(); PacmanTimer.Stop(); Dead = false; } } if (Pman.GetTries() != 0 || Dead) { return; } hs = new HighScore(Pman); hs.ShowDialog(); hs.Close(); dr = MessageBox.Show("Do you want to play again?", "Game Over", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { StartGame(); } else { DrawingTimer.Stop(); Close(); } }
private void GameForm_KeyDown(object sender, KeyEventArgs e) { int i = Pman.GetY() / 20; int j = Pman.GetX() / 20; if (Dead) { return; } if ((e.KeyCode == Keys.Up) || (e.KeyCode == Keys.W)) { if (maze.GetMaze()[i - 1, j] != 1) { Pman.SetDirection((int)Directions.Up); } PacmanTimer.Start(); GhostTimer.Start(); } if ((e.KeyCode == Keys.Down) || (e.KeyCode == Keys.S)) { if (maze.GetMaze()[i + 1, j] != 1) { Pman.SetDirection((int)Directions.Down); } PacmanTimer.Start(); GhostTimer.Start(); } if ((e.KeyCode == Keys.Left) || (e.KeyCode == Keys.A)) { if (maze.GetMaze()[i, j - 1] != 1) { Pman.SetDirection((int)Directions.Left); } PacmanTimer.Start(); GhostTimer.Start(); } if ((e.KeyCode == Keys.Right) || (e.KeyCode == Keys.D)) { if (maze.GetMaze()[i, j + 1] != 1) { Pman.SetDirection((int)Directions.Right); } PacmanTimer.Start(); GhostTimer.Start(); } if (e.KeyCode != Keys.Space || Pman.GetAmmo() <= 0 || ShootOnce) { return; } bullet.SetImage(Properties.Resources.Bullet); Pman.ReduceAmmo(); bullet.SetX(Pman.GetX() + 5); bullet.SetY(Pman.GetY() + 5); ShootOnce = true; bullet.SetDirection(Pman.GetDirection()); bullet.RotateBullet(); BulletTimer.Start(); }