Ejemplo 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)
        {
            controls.Update();
            if (Ball.Launched)
            {
                Ball.Move();
            }

            base.Update(gameTime);

            //These checks are ordered like this to guarantee
            // That update is called once before the endgame dialog
            // window is shown, so that the updated lives and score can be seen
            if (curState == GameState.Lost)
            {
                GameOver();
            }
            if (curState == GameState.Won)
            {
                Victory();
            }

            if (Cells.CellsAlive <= 0)
            {
                curState = GameState.Won;
            }
            if (Player.Lives <= 0)
            {
                curState = GameState.Lost;
            }
        }
Ejemplo n.º 2
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     label1.Text = k.ToString();
     ball.Move();
     Refresh();
     k++;
 }
Ejemplo n.º 3
0
 private void GameLoop(object sender, EventArgs e)
 {
     paddle.Move();
     ball.Move();
     ball.Draw();
     paddle.Draw();
     DrawAndMoveBonuses();
 }
Ejemplo n.º 4
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.Black);

            // TODO: Add your drawing code here
            spriteBatch.Begin();
            paddle.Draw();
            wall.Draw();
            gameBorder.Draw();
            if (ball.Visible)
            {
                bool inPlay = ball.Move(wall, paddle);
                if (inPlay)
                {
                    ball.Draw();
                }
                else
                {
                    ballsRemaining--;
                    readyToServeBall = true;
                }
            }

            staticBall.Draw();

            string  scoreMsg = "Score: " + ball.Score.ToString("00000");
            Vector2 space    = gameContent.labelFont.MeasureString(scoreMsg);

            spriteBatch.DrawString(gameContent.labelFont, scoreMsg, new Vector2((screenWidth - space.X) / 2, screenHeight - 40), Color.White);
            if (ball.bricksCleared >= 70)
            {
                ball.Visible       = false;
                ball.bricksCleared = 0;
                wall             = new Wall(1, 50, spriteBatch, gameContent);
                readyToServeBall = true;
            }
            if (readyToServeBall)
            {
                if (ballsRemaining > 0)
                {
                    string  startMsg   = "Press <Space> or Click Mouse to Start";
                    Vector2 startSpace = gameContent.labelFont.MeasureString(startMsg);
                    spriteBatch.DrawString(gameContent.labelFont, startMsg, new Vector2((screenWidth - startSpace.X) / 2, screenHeight / 2), Color.White);
                }
                else
                {
                    string  endMsg   = "Game Over";
                    Vector2 endSpace = gameContent.labelFont.MeasureString(endMsg);
                    spriteBatch.DrawString(gameContent.labelFont, endMsg, new Vector2((screenWidth - endSpace.X) / 2, screenHeight / 2), Color.White);
                }
            }
            spriteBatch.DrawString(gameContent.labelFont, ballsRemaining.ToString(), new Vector2(40, 10), Color.White);
            spriteBatch.End();
            base.Draw(gameTime);
        }
Ejemplo n.º 5
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            _infoPanel.OnTick(sender, e);
            if (Game.IsOver)
            {
                Timer.Stop();
                return;
            }
            //_infoPanel.OnTick(sender, e);
            //if (Game.IsOver)
            //{
            //    Timer.Stop();
            //    return;
            //}
            Paddle.Collide();
            Ball.Move(null, Game.FPS);

            //DrawGame();
            Invalidate();
        }