Update() private method

private Update ( ) : void
return void
Esempio n. 1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            MouseState mouse = Mouse.GetState();
            //Mouse.WindowHandle = Window.Handle;
            Vector2 clickCoord  = new Vector2(mouse.X, mouse.Y) + new Vector2((Ecir.cameraMove.X) + 180, (Ecir.cameraMove.Y) + 451);
            Matrix  screenScale = camera.GetTransform();
            Point   mousePoint  = new Point((int)clickCoord.X, (int)clickCoord.Y);

            //Vector2 mousePos = new Vector2(mouse.X, mouse.Y);
            // Vector2 worldPosition = Vector2.Transform(mousePos, Matrix.Invert(screenScale));
            // Console.WriteLine("mouseX=" + worldPosition.X + "mouseY=" + worldPosition.Y);

            MenuPause.Mouse1(mousePoint);
            // Console.WriteLine("mouseX=" + clickCoord.X + "mouseY=" + clickCoord.Y);


            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }
            if (exit)
            {
                Exit();
            }
            if (pause)
            {
                this.IsMouseVisible = true;
            }
            else
            {
                this.IsMouseVisible = false;
            }

            MenuPause.Update();


            keyState = Keyboard.GetState();
            if (pause == false)
            {
                if (!ecir.EcirDestroy())
                {
                    ecir.EcirMove(2, 2);
                    ecir.TerrainColisions();
                    ecir.EcirLife();
                }
                hollowKnight.Update();
                ecir.UpdateTime(gameTime.ElapsedGameTime.TotalSeconds);
                stairs.Update();
                ogre.Update();
                ogre.UpdateTime(gameTime.ElapsedGameTime.TotalSeconds);
                terrain1.Update();
                skeleton.Update();
                skeleton.UpdateTime(gameTime.ElapsedGameTime.TotalSeconds, gameTime.ElapsedGameTime.Milliseconds);
                fireBall.Update();
                fireBall.CreateFireBall(graphics);
                fireBall.UpdateTime(gameTime.ElapsedGameTime.TotalSeconds);

                if (zombie != null)
                {
                    zombie.UpdateTimer(gameTime.ElapsedGameTime.TotalSeconds);
                    zombie.ZombieChageDirection();
                    zombie.ZombieMove();
                    zombie.ZombieLife();
                    zombie.ZombieColor();
                }
                hollowKnight.UpdateTime(gameTime.ElapsedGameTime.TotalSeconds);
                Console.WriteLine("Pause==" + pause);
                base.Update(gameTime);
            }

            if (keyState.IsKeyDown(Keys.P) && !keyStateOld.IsKeyDown(Keys.P))
            {
                pause = !pause;  //->pausar o jogo
            }
            keyStateOld = keyState;
            if (restart == true)
            {
                this.Initialize();//->reiniciar o jogo
                this.LoadContent();
                Zombie.zombieLife = 100;
                Ecir.life         = 100;
                Ecir.color        = Color.White;
                this.Draw(gameTime);
            }
            restart = false;
        }
Esempio n. 2
0
        private void UpdateLevelState(GameTime gameTime)
        {
            if (darwin.isZombie() && darwin.isDarwinAlive())
            {
                if (zTime.isTimedOut())
                {
                    gameOver = true;
                }
                else
                {
                    zTime.Update(gameTime);
                }
            }

            KeyboardState ks = Keyboard.GetState();

            checkForExitGame(ks);
            updateKeyHeldDown(ks);

            if (darwin.isDarwinAlive())
            {
                foreach (Flame flame in flames)
                {
                    this.checkForFlameDeath(flame, darwin);
                }

                darwin.Update(gameTime, ks, board, darwin.X, darwin.Y);
            }

            stairs.Update(gameTime, darwin);
            potion.Update(gameTime, ks, darwin, zTime);

            foreach (Box b in boxes)
            {
                b.Update(gameTime, ks, darwin);
            }

            foreach (Vortex v in vortexes)
            {
                v.Update(gameTime, ks);
                // maybe update this so that boxes can't go in holes
                foreach (Box b in boxes)
                {
                    v.CollisionWithBO(b, board);
                }
            }

            northZombie.Update(darwin);
            southZombie.Update(darwin);
            eastZombie.Update(darwin);
            westZombie.Update(darwin);

            if (!darwin.isZombie())
            {
                if (!northZombie.isPatrolling())
                {
                    if (darwin.X == northZombie.X)
                    {
                        flames.AddLast(new Flame(board, northZombie.X, northZombie.Y + 1));
                        flames.AddLast(new Flame(board, northZombie.X, northZombie.Y + 2));
                        flames.AddLast(new Flame(board, northZombie.X, northZombie.Y + 3));
                        northZombie.doFlameSound();
                    }
                }
                else if (!southZombie.isPatrolling())
                {
                    if (darwin.X == southZombie.X)
                    {
                        flames.AddLast(new Flame(board, southZombie.X, southZombie.Y - 1));
                        flames.AddLast(new Flame(board, southZombie.X, southZombie.Y - 2));
                        flames.AddLast(new Flame(board, southZombie.X, southZombie.Y - 3));
                        southZombie.doFlameSound();
                    }
                }
                else if (!eastZombie.isPatrolling())
                {
                    if (darwin.Y == eastZombie.Y)
                    {
                        flames.AddLast(new Flame(board, eastZombie.X - 1, eastZombie.Y));
                        flames.AddLast(new Flame(board, eastZombie.X - 2, eastZombie.Y));
                        flames.AddLast(new Flame(board, eastZombie.X - 3, eastZombie.Y));
                        eastZombie.doFlameSound();
                    }
                }
                else if (!westZombie.isPatrolling())
                {
                    if (darwin.Y == westZombie.Y)
                    {
                        flames.AddLast(new Flame(board, westZombie.X + 1, westZombie.Y));
                        flames.AddLast(new Flame(board, westZombie.X + 2, westZombie.Y));
                        flames.AddLast(new Flame(board, westZombie.X + 3, westZombie.Y));
                        westZombie.doFlameSound();
                    }
                }
            }


            foreach (Flame flame in flames)
            {
                flame.Update();

                if (!flame.isAlive())
                {
                    //flames.Remove(flame);
                }
            }

            if (darwin.isDarwinAlive())
            {
                if (snake.isZombieAlive())
                {
                    updateSnakeCollision(snake, darwin, gameTime);
                }
                if (snake2.isZombieAlive())
                {
                    updateSnakeCollision(snake2, darwin, gameTime);
                }
                if (snake3.isZombieAlive())
                {
                    updateSnakeCollision(snake3, darwin, gameTime);
                }
                if (snake4.isZombieAlive())
                {
                    updateSnakeCollision(snake4, darwin, gameTime);
                }
            }

            foreach (Vortex v in vortexes)
            {
                if (darwin.isOnTop(v))
                {
                    fellDownPit = true;
                    gameOver    = true;
                }
            }

            checkForGameWin();
            checkForSwitchToLevelSix();

            if (ks.IsKeyDown(Keys.H) && messageModeCounter > 10)
            {
                messageMode        = true;
                messageModeCounter = 0;
            }
            messageModeCounter++;
        }