示例#1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            EstadoDeJogo.ZeraJogo();

            Sujeira.Limpa();

            base.Initialize();
        }
示例#2
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)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            MouseState mouse = Mouse.GetState();

            switch (EstadoDeJogo.FaseDeExecucao)
            {
            case Fase.Inicial:
                if (btnPlay.isClicked == true)
                {
                    EstadoDeJogo.FaseDeExecucao = Fase.Partida;
                    Sujeira.CriaLixo();
                }
                btnPlay.Update(mouse);
                break;

            case Fase.Partida:
                // TODO: Atualizar a posição dos lixos de acordo com o toque

                Sujeira.Update();

                Sujeira.CriaLixo(gameTime);

                VerificaPontuacao();

                background.Update(gameTime);

                if (EstadoDeJogo.Vidas == 0)
                {
                    EstadoDeJogo.FaseDeExecucao = Fase.Final;
                    flag_acabou = true;
                }
                break;

            case Fase.Final:
                btnPlay.isClicked = false;
                if (mouse.LeftButton == ButtonState.Pressed && flag_acabou == false)
                {
                    EstadoDeJogo.ZeraJogo();
                }
                if (mouse.LeftButton == ButtonState.Released)
                {
                    flag_acabou = false;
                }
                break;

            default:
                break;
            }

            base.Update(gameTime);
        }
示例#3
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin();
            switch (EstadoDeJogo.FaseDeExecucao)
            {
            case Fase.Inicial:
                spriteBatch.Draw(Content.Load <Texture2D>("MainMenu"), new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
                btnPlay.Draw(spriteBatch);
                break;

            case Fase.Partida:
                background.Draw(spriteBatch);

                // TODO: Desenhar Lixeiros
                // Lixeiros.Draw(spriteBatch);

                foreach (var item in lixeiros)
                {
                    item.Draw(spriteBatch);
                }

                Sujeira.DrawLixoNoChao(spriteBatch);

                // TODO: Desenhar Lixos
                // VetorDeLixo.Draw(spriteBatch);

                EstadoDeJogo.DrawScoreAndLife(spriteBatch, scoreFont, heart);
                break;

            case Fase.Final:
                // TelaPontuacao.Draw();
                Sujeira.Limpa();
                spriteBatch.DrawString(GameOverFont, "GAME OVER", new Vector2(302, 252), Color.Black);
                spriteBatch.DrawString(GameOverFont, "GAME OVER", new Vector2(300, 250), Color.White);

                spriteBatch.DrawString(GameOverFont, EstadoDeJogo.Pontuacao.ToString(), new Vector2(302, 302), Color.Black);
                spriteBatch.DrawString(GameOverFont, EstadoDeJogo.Pontuacao.ToString(), new Vector2(300, 300), Color.White);
                break;

            default:
                break;
            }
            spriteBatch.End();

            base.Draw(gameTime);
        }
示例#4
0
        /// <summary>
        /// Testa se houve colisão e atualiza pontuação de acordo.
        /// </summary>
        protected void VerificaPontuacao()
        {
            if (Sujeira.ativo != null)
            {
                bool lixeiraCorreta;

                // Se colidiu com uma lixeira
                if (Sujeira.VerificaColisoes(lixeiros, out lixeiraCorreta))
                {
                    if (lixeiraCorreta)
                    {
                        EstadoDeJogo.Pontua();
                    }
                    else
                    {
                        EstadoDeJogo.Vidas--;
                    }

                    Sujeira.lixosNoChao.Remove(Sujeira.ativo);
                    Sujeira.ativo = null;
                    return;
                }

                bool bonus;
                Lixo outro;

                // Se colidiu com outro lixo
                if (Sujeira.VerificaColisoes(out outro, out bonus))
                {
                    if (bonus)
                    {
                        EstadoDeJogo.GanhaBonus();
                    }
                    else
                    {
                        Sujeira.lixosNoChao.Remove(Sujeira.ativo);
                        Sujeira.ativo = null;
                    }
                    Sujeira.lixosNoChao.Remove(outro);
                }
            }
        }