public void Update() { if (!this.IsAlive) { return; } this.current = Keyboard.GetState(); if (Serve.CheckKeyBoard(this.current, this.previous, Keys.Space) && !this.IsSpacePressed) { PacmanGame.GameState = GameState.Game; this.IsSpacePressed = true; this.Ready.IsAlive = true; } if (this.IsSpacePressed) { this.Ready.Update(); if (this.Ready.Timer.IsFinished) { Items.Pacman.IsReady = true; this.Ready.Timer.Reset(); this.IsAlive = false; } } this.previous = this.current; }
private void CheckBonusContact(Point point) { this.BonusMapPosition = Serve.WorldToMap(new Vector2(Items.Bonus.Position.X, Items.Bonus.Position.Y)); if (!(point == this.BonusMapPosition & Items.Bonus.IsAlive)) { return; } Items.Bonus.Timer.Reset(); Items.Bonus.Timer.Value = Items.Bonus.GetNewTimeValue(); Items.Bonus.IsAlive = false; Items.Player.Score += Items.Levels[Level.Count].BonusPoints; Items.Bonus.Score.Value = Items.Levels[Level.Count].BonusPoints; Items.Bonus.Score.Position = new Vector2(Items.Bonus.Position.X - 8f, Items.Bonus.Position.Y - 8f); Items.Bonus.Score.IsAlive = true; }
public void Contact(Point point) { if (!this.IsAlive) { return; } this.maploc = Serve.WorldToMap(new Vector2(this.Position.X, this.Position.Y)); if (!(point == this.maploc & this.IsAlive)) { return; } if (Items.Pacman.IsSpeedUp) { this.IsMoving = false; ++Items.Pacman.GhostDestroyedCounter; this.result = 0; switch (Items.Pacman.GhostDestroyedCounter) { case 1: this.result = 200; break; case 2: this.result = 400; break; case 3: this.result = 800; break; case 4: this.result = 1600; break; } Items.Player.Score += this.result; this.Score.Value = this.result; this.Score.Position = new Vector2(this.Position.X - 16f, this.Position.Y - 16f); this.Score.IsAlive = true; this.Reset(); } else { Items.Pacman.Expire(); } }
public override void Update(GameTime gameTime) { if (this.IsAlive) { if (this.homeTimer.IsFinished) { this.Position = this.StartPosition; this.IsMoving = true; this.homeTimer.IsFinished = false; } this.GhostMove(); switch ((int)this.Position.X) { case -1: this.Position.X = 445f; break; case 445: this.Position.X = -1f; break; } if (this.mode == GhostMode.Reset && !Items.Pacman.IsSpeedUp) { if (this.ident == GhostIdent.Red) { this.Reset(); } else { this.Reset(); } } if (this.Score.IsAlive) { this.Score.Update(); } } this.Contact(Serve.WorldToMap(Items.Pacman.Position)); this.homeTimer.Update(); base.Update(gameTime); }
public override void Update(GameTime gameTime) { if (!this.IsAlive) { return; } this.timer.Update(); if (this.timer.Count <= this.timer.Value) { Items.Pacman.DisableGhosts(); } if (this.timer.Count == 100) { this.draw = true; } if (!this.timer.IsFinished) { return; } PacmanGame.GameState = GameState.End; this.current = Keyboard.GetState(); if (Serve.CheckKeyBoard(this.current, this.previous, Keys.Space)) { PacmanGame.GameState = GameState.Game; Items.Player.Score = 0; Items.Player.Lives = 3; Items.Pacman.IsGameOver = false; Level.Count = 0; Items.Pacman.GhostModeTimer.Reset(); Items.Pacman.ResetLevel(); this.draw = false; this.timer.Reset(); this.IsAlive = false; } this.previous = this.current; }
private void GhostMove() { if (!this.IsMoving) { return; } switch (this.ident) { case GhostIdent.Red: this.aimPoint = Items.Pacman.mode == GhostMode.Scatter ? new Vector2(400f, 0.0f) : Items.Pacman.Position; break; case GhostIdent.Pink: if (Items.Pacman.mode == GhostMode.Chase) { switch (Items.Pacman.Direction) { case 0: this.aimPoint = new Vector2(Items.Pacman.Position.X + 64f, Items.Pacman.Position.Y); break; case 90: this.aimPoint = new Vector2(Items.Pacman.Position.X, Items.Pacman.Position.Y + 64f); break; case 180: this.aimPoint = new Vector2(Items.Pacman.Position.X - 64f, Items.Pacman.Position.Y); break; case 270: this.aimPoint = new Vector2(Items.Pacman.Position.X, Items.Pacman.Position.Y - 64f); break; } } else { this.aimPoint = new Vector2(0.0f, 48f); break; } break; case GhostIdent.Blue: this.aimPoint = Items.Pacman.mode != GhostMode.Chase ? new Vector2(448f, 576f) : new Vector2(2f * Items.Pacman.Position.X - Items.Red.Position.X, 2f * Items.Pacman.Position.Y - Items.Red.Position.Y); break; case GhostIdent.Orange: this.aimPoint = Items.Pacman.mode != GhostMode.Chase ? new Vector2(0.0f, 576f) : ((double)Vector2.Distance(this.Position, Items.Pacman.Position) <= 128.0 ? new Vector2(0.0f, 576f) : Items.Pacman.Position); break; } Vector2 vector2_1 = new Vector2(this.Position.X - 16f, this.Position.Y); Vector2 vector2_2 = new Vector2(this.Position.X + 16f, this.Position.Y); Vector2 vector2_3 = new Vector2(this.Position.X, this.Position.Y - 16f); Vector2 vector2_4 = new Vector2(this.Position.X, this.Position.Y + 16f); this.maploc = Serve.WorldToMap(new Vector2(this.Position.X, this.Position.Y)); if (this.direction == DirectionEnum.Right) { if (!PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y - 1) & !PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y + 1)) { this.direction = DirectionEnum.Right; this.Position.X += this.Speed; this.Position.Y = this.SnapToY(this.Position); return; } if (!PacmanGame.Map.IsOpenLocation(this.maploc.X + 1, this.maploc.Y) && !PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y + 1)) { this.direction = DirectionEnum.Up; this.Position.Y -= 9f; this.Position.X = this.SnapToX(this.Position); return; } if (!PacmanGame.Map.IsOpenLocation(this.maploc.X + 1, this.maploc.Y) && !PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y - 1)) { this.direction = DirectionEnum.Down; this.Position.Y += 9f; this.Position.X = this.SnapToX(this.Position); return; } if (PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y + 1) & PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y - 1)) { if (PacmanGame.Map.IsOpenLocation(this.maploc.X + 1, this.maploc.Y)) { if (Items.Pacman.mode == GhostMode.Frightened) { switch (new Random().Next(1, 3)) { case 1: this.Position.Y -= 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Up; return; case 2: this.Position.Y += 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Down; return; case 3: this.Position.X += 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Right; return; default: return; } } else { if ((double)Vector2.Distance(vector2_3, this.aimPoint) <= (double)Vector2.Distance(vector2_4, this.aimPoint) && (double)Vector2.Distance(vector2_3, this.aimPoint) <= (double)Vector2.Distance(vector2_2, this.aimPoint)) { this.Position.Y -= 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Up; return; } if ((double)Vector2.Distance(vector2_4, this.aimPoint) <= (double)Vector2.Distance(vector2_3, this.aimPoint) && (double)Vector2.Distance(vector2_4, this.aimPoint) <= (double)Vector2.Distance(vector2_2, this.aimPoint)) { this.Position.Y += 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Down; return; } this.Position.X += 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Right; return; } } else if (Items.Pacman.mode == GhostMode.Frightened) { switch (new Random().Next(1, 2)) { case 1: this.Position.Y -= 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Up; return; case 2: this.Position.Y += 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Down; return; default: return; } } else { if ((double)Vector2.Distance(vector2_3, this.aimPoint) <= (double)Vector2.Distance(vector2_4, this.aimPoint)) { this.Position.Y -= 9f; this.direction = DirectionEnum.Up; this.Position.X = this.SnapToX(this.Position); return; } this.Position.Y += 9f; this.direction = DirectionEnum.Down; this.Position.X = this.SnapToX(this.Position); return; } } else if (PacmanGame.Map.IsOpenLocation(this.maploc.X + 1, this.maploc.Y) & PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y - 1)) { if (Items.Pacman.mode == GhostMode.Frightened) { switch (new Random().Next(1, 2)) { case 1: this.Position.Y -= 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Up; return; case 2: this.Position.X += 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Right; return; default: return; } } else { if ((double)Vector2.Distance(vector2_3, this.aimPoint) <= (double)Vector2.Distance(vector2_2, this.aimPoint)) { this.Position.Y -= 9f; this.direction = DirectionEnum.Up; this.Position.X = this.SnapToX(this.Position); return; } this.Position.X += 9f; this.direction = DirectionEnum.Right; this.Position.Y = this.SnapToY(this.Position); return; } } else if (PacmanGame.Map.IsOpenLocation(this.maploc.X + 1, this.maploc.Y) & PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y + 1)) { if (Items.Pacman.mode == GhostMode.Frightened) { switch (new Random().Next(1, 2)) { case 1: this.Position.Y += 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Up; return; case 2: this.Position.X += 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Right; return; default: return; } } else { if ((double)Vector2.Distance(vector2_4, this.aimPoint) <= (double)Vector2.Distance(vector2_2, this.aimPoint)) { this.Position.Y += 9f; this.direction = DirectionEnum.Down; this.Position.X = this.SnapToX(this.Position); return; } this.Position.X += 9f; this.direction = DirectionEnum.Right; this.Position.Y = this.SnapToY(this.Position); return; } } } if (this.direction == DirectionEnum.Left) { if (!PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y - 1) & !PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y + 1)) { this.Position.X -= this.Speed; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Left; return; } if (!PacmanGame.Map.IsOpenLocation(this.maploc.X - 1, this.maploc.Y) & !PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y + 1)) { this.Position.Y -= 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Up; return; } if (!PacmanGame.Map.IsOpenLocation(this.maploc.X - 1, this.maploc.Y) && !PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y - 1)) { this.Position.Y += 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Down; return; } if (PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y + 1) & PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y - 1)) { if (PacmanGame.Map.IsOpenLocation(this.maploc.X - 1, this.maploc.Y)) { if (Items.Pacman.mode == GhostMode.Frightened) { switch (new Random().Next(1, 3)) { case 1: this.Position.Y -= 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Up; return; case 2: this.Position.X -= 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Left; return; case 3: this.Position.Y += 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Down; return; default: return; } } else { if ((double)Vector2.Distance(vector2_3, this.aimPoint) <= (double)Vector2.Distance(vector2_4, this.aimPoint) && (double)Vector2.Distance(vector2_3, this.aimPoint) <= (double)Vector2.Distance(vector2_1, this.aimPoint)) { this.Position.Y -= 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Up; return; } if ((double)Vector2.Distance(vector2_1, this.aimPoint) <= (double)Vector2.Distance(vector2_3, this.aimPoint) && (double)Vector2.Distance(vector2_1, this.aimPoint) <= (double)Vector2.Distance(vector2_4, this.aimPoint)) { this.Position.X -= 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Left; return; } this.Position.Y += 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Down; return; } } else if (Items.Pacman.mode == GhostMode.Frightened) { switch (new Random().Next(1, 2)) { case 1: this.Position.Y -= 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Up; return; case 2: this.Position.Y += 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Down; return; default: return; } } else { if ((double)Vector2.Distance(vector2_3, this.aimPoint) <= (double)Vector2.Distance(vector2_4, this.aimPoint)) { this.Position.Y -= 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Up; return; } this.Position.Y += 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Down; return; } } else if (PacmanGame.Map.IsOpenLocation(this.maploc.X - 1, this.maploc.Y) & PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y - 1)) { if (Items.Pacman.mode == GhostMode.Frightened) { switch (new Random().Next(1, 2)) { case 1: this.Position.Y -= 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Up; return; case 2: this.Position.X -= 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Left; return; default: return; } } else { if ((double)Vector2.Distance(vector2_3, this.aimPoint) <= (double)Vector2.Distance(vector2_1, this.aimPoint)) { this.Position.Y -= 9f; this.direction = DirectionEnum.Up; this.Position.X = this.SnapToX(this.Position); return; } this.Position.X -= 9f; this.direction = DirectionEnum.Left; this.Position.Y = this.SnapToY(this.Position); return; } } else if (PacmanGame.Map.IsOpenLocation(this.maploc.X - 1, this.maploc.Y) & PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y + 1)) { if (Items.Pacman.mode == GhostMode.Frightened) { switch (new Random().Next(1, 2)) { case 1: this.Position.Y += 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Up; return; case 2: this.Position.X -= 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Left; return; default: return; } } else { if ((double)Vector2.Distance(vector2_4, this.aimPoint) <= (double)Vector2.Distance(vector2_1, this.aimPoint)) { this.Position.Y += 9f; this.direction = DirectionEnum.Down; this.Position.X = this.SnapToX(this.Position); return; } this.Position.X -= 9f; this.direction = DirectionEnum.Left; this.Position.Y = this.SnapToY(this.Position); return; } } } if (this.direction == DirectionEnum.Up) { if (!PacmanGame.Map.IsOpenLocation(this.maploc.X + 1, this.maploc.Y) & !PacmanGame.Map.IsOpenLocation(this.maploc.X - 1, this.maploc.Y)) { this.Position.Y -= this.Speed; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Up; return; } if (!PacmanGame.Map.IsOpenLocation(this.maploc.X - 1, this.maploc.Y) && !PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y - 1)) { this.Position.X += 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Right; return; } if (!PacmanGame.Map.IsOpenLocation(this.maploc.X + 1, this.maploc.Y) && !PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y - 1)) { this.Position.X -= 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Left; return; } if (PacmanGame.Map.IsOpenLocation(this.maploc.X + 1, this.maploc.Y) & PacmanGame.Map.IsOpenLocation(this.maploc.X - 1, this.maploc.Y)) { if (PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y - 1)) { if (Items.Pacman.mode == GhostMode.Frightened) { switch (new Random().Next(1, 3)) { case 1: this.Position.Y -= 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Up; return; case 2: this.Position.X -= 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Left; return; case 3: this.Position.X += 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Right; return; default: return; } } else { if ((double)Vector2.Distance(vector2_3, this.aimPoint) <= (double)Vector2.Distance(vector2_2, this.aimPoint) & (double)Vector2.Distance(vector2_3, this.aimPoint) <= (double)Vector2.Distance(vector2_1, this.aimPoint)) { this.Position.Y -= 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Up; return; } if ((double)Vector2.Distance(vector2_1, this.aimPoint) <= (double)Vector2.Distance(vector2_3, this.aimPoint) && (double)Vector2.Distance(vector2_1, this.aimPoint) <= (double)Vector2.Distance(vector2_2, this.aimPoint)) { this.Position.X -= 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Left; return; } this.Position.X += 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Right; return; } } else if (Items.Pacman.mode == GhostMode.Frightened) { switch (new Random().Next(1, 2)) { case 1: this.Position.X -= 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Left; return; case 2: this.Position.X += 9f; this.Position.Y = this.SnapToX(this.Position); this.direction = DirectionEnum.Right; return; default: return; } } else { if ((double)Vector2.Distance(vector2_1, this.aimPoint) <= (double)Vector2.Distance(vector2_2, this.aimPoint)) { this.Position.X -= 9f; this.direction = DirectionEnum.Left; this.Position.Y = this.SnapToY(this.Position); return; } this.Position.X += 9f; this.direction = DirectionEnum.Right; this.Position.Y = this.SnapToY(this.Position); return; } } else if (PacmanGame.Map.IsOpenLocation(this.maploc.X + 1, this.maploc.Y) & PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y - 1)) { if (Items.Pacman.mode == GhostMode.Frightened) { switch (new Random().Next(1, 2)) { case 1: this.Position.Y -= 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Up; return; case 2: this.Position.X += 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Right; return; default: return; } } else { if ((double)Vector2.Distance(vector2_3, this.aimPoint) <= (double)Vector2.Distance(vector2_2, this.aimPoint)) { this.Position.Y -= 9f; this.direction = DirectionEnum.Up; this.Position.X = this.SnapToX(this.Position); return; } this.Position.X += 9f; this.direction = DirectionEnum.Right; this.Position.Y = this.SnapToY(this.Position); return; } } else if (PacmanGame.Map.IsOpenLocation(this.maploc.X - 1, this.maploc.Y) & PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y - 1)) { if (Items.Pacman.mode == GhostMode.Frightened) { switch (new Random().Next(1, 2)) { case 1: this.Position.Y -= 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Up; return; case 2: this.Position.X -= 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Left; return; default: return; } } else { if ((double)Vector2.Distance(vector2_3, this.aimPoint) <= (double)Vector2.Distance(vector2_2, this.aimPoint)) { this.Position.Y -= 9f; this.direction = DirectionEnum.Up; this.Position.X = this.SnapToX(this.Position); return; } this.Position.X -= 9f; this.direction = DirectionEnum.Left; this.Position.Y = this.SnapToY(this.Position); return; } } } if (this.direction != DirectionEnum.Down) { return; } if (!PacmanGame.Map.IsOpenLocation(this.maploc.X + 1, this.maploc.Y) && !PacmanGame.Map.IsOpenLocation(this.maploc.X - 1, this.maploc.Y)) { this.direction = DirectionEnum.Down; this.Position.Y += this.Speed; this.Position.X = this.SnapToX(this.Position); } else if (!PacmanGame.Map.IsOpenLocation(this.maploc.X - 1, this.maploc.Y) && !PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y + 1)) { this.Position.X += 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Right; } else if (!PacmanGame.Map.IsOpenLocation(this.maploc.X + 1, this.maploc.Y) && !PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y + 1)) { this.Position.X -= 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Left; } else if (PacmanGame.Map.IsOpenLocation(this.maploc.X + 1, this.maploc.Y) && PacmanGame.Map.IsOpenLocation(this.maploc.X - 1, this.maploc.Y)) { if (PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y + 1)) { if (Items.Pacman.mode == GhostMode.Frightened) { switch (new Random().Next(1, 3)) { case 1: this.Position.X -= 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Left; break; case 2: this.Position.Y += 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Down; break; case 3: this.Position.X += 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Right; break; } } else if ((double)Vector2.Distance(vector2_1, this.aimPoint) <= (double)Vector2.Distance(vector2_3, this.aimPoint) && (double)Vector2.Distance(vector2_1, this.aimPoint) <= (double)Vector2.Distance(vector2_2, this.aimPoint)) { this.Position.X -= 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Left; } else if ((double)Vector2.Distance(vector2_4, this.aimPoint) <= (double)Vector2.Distance(vector2_2, this.aimPoint) && (double)Vector2.Distance(vector2_4, this.aimPoint) <= (double)Vector2.Distance(vector2_1, this.aimPoint)) { this.Position.Y += 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Down; } else { this.Position.X += 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Right; } } else if (Items.Pacman.mode == GhostMode.Frightened) { switch (new Random().Next(1, 2)) { case 1: this.Position.X -= 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Left; break; case 2: this.Position.X += 9f; this.Position.Y = this.SnapToX(this.Position); this.direction = DirectionEnum.Right; break; } } else if ((double)Vector2.Distance(vector2_1, this.aimPoint) <= (double)Vector2.Distance(vector2_2, this.aimPoint)) { this.Position.X -= 9f; this.direction = DirectionEnum.Left; this.Position.Y = this.SnapToY(this.Position); } else { this.Position.X += 9f; this.direction = DirectionEnum.Right; this.Position.Y = this.SnapToY(this.Position); } } else if (PacmanGame.Map.IsOpenLocation(this.maploc.X + 1, this.maploc.Y) & PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y + 1)) { if (Items.Pacman.mode == GhostMode.Frightened) { switch (new Random().Next(1, 2)) { case 1: this.Position.Y += 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Down; break; case 2: this.Position.X += 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Right; break; } } else if ((double)Vector2.Distance(vector2_4, this.aimPoint) <= (double)Vector2.Distance(vector2_2, this.aimPoint)) { this.Position.Y += 9f; this.direction = DirectionEnum.Down; this.Position.X = this.SnapToX(this.Position); } else { this.Position.X += 9f; this.direction = DirectionEnum.Right; this.Position.Y = this.SnapToY(this.Position); } } else { if (!(PacmanGame.Map.IsOpenLocation(this.maploc.X - 1, this.maploc.Y) & PacmanGame.Map.IsOpenLocation(this.maploc.X, this.maploc.Y + 1))) { return; } if (Items.Pacman.mode == GhostMode.Frightened) { switch (new Random().Next(1, 2)) { case 1: this.Position.Y += 9f; this.Position.X = this.SnapToX(this.Position); this.direction = DirectionEnum.Down; break; case 2: this.Position.X -= 9f; this.Position.Y = this.SnapToY(this.Position); this.direction = DirectionEnum.Left; break; } } else if ((double)Vector2.Distance(vector2_4, this.aimPoint) <= (double)Vector2.Distance(vector2_2, this.aimPoint)) { this.Position.Y += 9f; this.direction = DirectionEnum.Down; this.Position.X = this.SnapToX(this.Position); } else { this.Position.X -= 9f; this.direction = DirectionEnum.Left; this.Position.Y = this.SnapToY(this.Position); } } }
public override void Update(GameTime gameTime) { this.current = Keyboard.GetState(); if (PacmanGame.GameState == GameState.Game) { if (this.IsReload & !this.IsGameOver) { this.DisableGhosts(); this.ready.IsAlive = true; if (this.ready.IsAlive) { this.ready.Update(); } if (!this.IsAlive & this.ready.IsAlive) { this.Reset(); this.IsAlive = true; this.IsReset = true; --Items.Player.Lives; } if (this.ready.Timer.IsFinished) { this.IsReady = true; this.IsReload = false; this.ready.Timer.Reset(); this.ready.IsAlive = false; } } if (!this.IsAlive) { return; } if (this.IsReady && !this.GhostModeTimer.IsFinished) { switch (this.GhostModeTimer.Count) { case 0: case 1620: case 3240: case 4740: this.mode = GhostMode.Scatter; break; case 420: case 2040: case 3540: this.mode = GhostMode.Chase; break; case 5040: this.mode = GhostMode.Chase; this.GhostModeTimer.IsFinished = true; break; } this.GhostModeTimer.Update(); } if (this.current.IsKeyDown(Keys.Up) & this.IsReady) { Point map = Serve.WorldToMap(new Vector2(this.Position.X, this.Position.Y + 7f)); if (PacmanGame.Map.IsOpenLocation(map.X, map.Y - 1)) { this.Direction = 270; this.Position.Y -= this.Speed; this.Position.X = this.SnaptoX(this.Position); this.CheckDotContact(map); this.CheckBonusContact(map); this.CheckGhostContact(map); } } if (this.current.IsKeyDown(Keys.Down) & this.IsReady) { Point map = Serve.WorldToMap(new Vector2(this.Position.X, this.Position.Y - 7f)); if (PacmanGame.Map.IsOpenLocation(map.X, map.Y + 1)) { this.Direction = 90; this.Position.Y += this.Speed; this.Position.X = this.SnaptoX(this.Position); this.CheckDotContact(map); this.CheckBonusContact(map); this.CheckGhostContact(map); } } if (this.current.IsKeyDown(Keys.Left) & this.IsReady) { Point map = Serve.WorldToMap(new Vector2(this.Position.X + 7f, this.Position.Y)); if (PacmanGame.Map.IsOpenLocation(map.X - 1, map.Y)) { this.Direction = 180; this.Position.X -= this.Speed; this.Position.Y = this.SnaptoY(this.Position); this.CheckDotContact(map); this.CheckBonusContact(map); this.CheckGhostContact(map); if (PacmanGame.Map.IsInTunnel & map.X == -1) { this.Position.X = 445f; } } } if (this.current.IsKeyDown(Keys.Right) & this.IsReady) { Point map = Serve.WorldToMap(new Vector2(this.Position.X - 7f, this.Position.Y)); if (PacmanGame.Map.IsOpenLocation(map.X + 1, map.Y)) { this.Direction = 0; this.Position.X += this.Speed; this.Position.Y = this.SnaptoY(this.Position); this.CheckDotContact(map); this.CheckBonusContact(map); this.CheckGhostContact(map); if (PacmanGame.Map.IsInTunnel & map.X == 29) { this.Position.X = -1f; } } } if (this.IsSpeedUp) { if (this.speedUpTime > 0) { --this.speedUpTime; } else { this.IsSpeedUp = false; this.mode = this.previousMode; } } if (this.DotsCounter == 50 & !this.Dots50Eat) { Items.Bonus.Timer.Reset(); Items.Bonus.IsAlive = true; this.Dots50Eat = true; } if (this.DotsCounter == 150 & !this.Dots150Eat) { Items.Bonus.Timer.Reset(); Items.Bonus.IsAlive = true; this.Dots150Eat = true; } if (this.DotsCounter == 244) { this.IsReady = false; Items.InterMission.IsAlive = true; } this.pacmanAnimation.Position = this.Position; this.pacmanAnimation.Direction = (float)this.Direction; this.pacmanAnimation.Update(gameTime); } this.previous = this.current; base.Update(gameTime); }