Esempio n. 1
0
 public void Update()
 {
     Blinky.Update();
     Pinky.Update();
     Inky.Update();
     Clyde.Update();
     Pack.Update();
 }
Esempio n. 2
0
        public void Update(GameTime gameTime)
        {
            hud.Update(gameTime);

            if (pacman != null)
            {
                pacman.Update(gameTime);
            }

            foreach (Ghost ghost in ghosts)
            {
                ghost.Update(gameTime);
            }

            Collision();
        }
Esempio n. 3
0
        public override void Update(GameTime gameTime)
        {
            bool cantUpdate = false;

            for (int i = 0; i < Hearts.Count; i++)
            {
                Hearts[i].Update(gameTime);
                cantUpdate |= Hearts[i].ShouldFlash;
                if (Hearts[i].ShouldBeRemoved)
                {
                    Hearts.Remove(Hearts[i]);
                    i--;
                }
            }

            #region LoseStatement
            if (Hearts.Count == 0)
            {
                Game1.CurrentUserData.Money += (int)(((float)food.Count / originalFoodCount) * 100);
                Game1.CurrentState           = ScreenStates.End;
                Game1.DidWin = false;
                Game1.Screens.Add(ScreenStates.End, new EndScreen(Graphics, Content));
            }
            #endregion

            for (int i = 0; i < food.Count; i++)
            {
                if (food[i].HitBox.Contains(pac.Position))
                {
                    food.RemoveAt(i);
                    i--;
                }
            }

            if (food.Count == 0)
            {
                Game1.CurrentUserData.Money += 100 * Hearts.Count;
                Game1.CurrentState           = ScreenStates.End;
                Game1.DidWin = true;
                Game1.Screens.Add(ScreenStates.End, new EndScreen(Graphics, Content));
            }

            var keyboard = Keyboard.GetState();
            foreach (var key in StartKeys)
            {
                if (keyboard.IsKeyDown(key))
                {
                    shouldStart = true;
                }
            }

            if (shouldStart)
            {
                for (int i = 0; i < food.Count; i++)
                {
                    if (food[i].HitBox.Intersects(pac.HitBox))
                    {
                        food.RemoveAt(i);
                        i--;
                    }
                }

                if (cantUpdate == false)
                {
                    pac.Update(gameTime, Walls, Graphics);
                    blinky.Update(gameTime);
                    pinky.Update(gameTime);
                    Clyde.Update(gameTime);
                    Inky.Update(gameTime);
                }

                foreach (var ghost in Ghosts)
                {
                    if (pac.HitBox.Contains(ghost.HitBox) && !pac.IsPowerActivated)
                    {
                        Hearts[Hearts.Count - 1].ShouldFlash = true;

                        shouldStart = false;

                        pac.Position    = new Vector2(120, 40);
                        pac.Direction   = Directions.None;
                        pinky.Position  = new Vector2(400, 360);
                        Clyde.Position  = new Vector2(440, 360);
                        blinky.Position = new Vector2(480, 360);
                        Inky.Position   = new Vector2(520, 360);
                    }
                    else if (pac.HitBox.Contains(ghost.HitBox))
                    {
                        ghost.Position = ghost.StartingPosition;
                    }
                }
            }

            for (int i = 0; i < PowerUps.Count; i++)
            {
                if (PowerUps[i].HitBox.Contains(pac.HitBox))
                {
                    //able to kill
                    pac.elapsedPowerTime = TimeSpan.Zero;
                    pac.IsPowerActivated = true;
                    PowerUps.RemoveAt(i);
                    i--;
                }
            }
            base.Update(gameTime);
        }