Update() public method

public Update ( ) : bool
return bool
Exemplo n.º 1
0
        public void Update(GameTime gameTime)
        {
            //сначала с чем сталкиваемся потом что сталкиваем
            if (TennisBall.IntersectsPixel(TennisBall.BallRectangle, TennisBall.BallTextureData, Panel.PanelRectangle, Panel.PanelTextureData))
            {
                TennisBall.Update(gameTime);
            }
            else if (TennisBall.IntersectsPixel(TennisBall.BallRectangle, TennisBall.BallTextureData, JumpButton.PanelRectangle, JumpButton.PanelTextureData))
            {
                TennisBall.BallVelocity *= 2f;
                TennisBall.Update(gameTime);
            }
            else if (EndBlock.IntersectsPixel(TennisBall.BallRectangle, TennisBall.BallTextureData, EndBlock.PanelRectangle, EndBlock.PanelTextureData))
            {
                TennisBall.Update(gameTime);
                finished = true;
            }
            else
            {
                TennisBall.Update(gameTime);
            }

            if (JumpButton.IntersectsPixel(cursorRectangle, cursorTextureData, JumpButton.PanelRectangle, JumpButton.PanelTextureData) &&
                Mouse.GetState().LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed && !TennisBall.started)
            {
                float x, y;
                x = JumpButton.PanelPosition.X - mouse.X;
                y = JumpButton.PanelPosition.Y - mouse.Y;
                JumpButton.PanelPosition.X = Mouse.GetState().X + x;
                JumpButton.PanelPosition.Y = Mouse.GetState().Y + y;
            }
            if (gui.Start.IntersectsPixel(cursorRectangle, cursorTextureData, gui.Start.ButtonRectangle, gui.Start.ButtonTextureData) &&
                mouse.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
            {
                TennisBall.started = true;
            }
            if (gui.Stop.IntersectsPixel(cursorRectangle, cursorTextureData, gui.Stop.ButtonRectangle, gui.Stop.ButtonTextureData) &&
                mouse.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
            {
                TennisBall.started = false;
            }
            if (gui.Hint.IntersectsPixel(cursorRectangle, cursorTextureData, gui.Hint.HRectangle, gui.Hint.HTextureData) &&
                Mouse.GetState().LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed && TennisBall.started == false)
            {
                MessageBox.Show("Фиолетовый ускоритель поможет мячику забраться\n" +
                                "выше если его правильно использовать.\n", "Подсказка #4", MessageBoxButtons.OK);
            }
            Panel.Update(gameTime);
            JumpButton.Update(gameTime);

            EndBlock.Update(gameTime);

            gui.Update(gameTime);
            mouse           = Mouse.GetState();
            cursorRectangle = new Rectangle(mouse.X - (cursorTexture.Width / 2),
                                            mouse.Y - (cursorTexture.Height / 2), cursorTexture.Width, cursorTexture.Height);
        }
Exemplo n.º 2
0
        public override void Update(GameTime gameTime)
        {
            CheckCollision();

            if (mainBall.launched == false)
            {
                mainBall.position.X = paddleManager[paddleManager.activePaddle].position.X + 16;
            }

            if (InputHandler.KeyDown(Keys.Space))
            {
                if (mainBall.launched == false)
                {
                    mainBall.motion   = new Vector2(ballSpeed, -ballSpeed);
                    mainBall.launched = true;
                }
            }

            paddleManager.Update(gameTime, GameRef, walls);
            mainBall.Update(gameTime);
            brickManager.Update(gameTime);

            scoreLabel.Text = score.ToString();

            base.Update(gameTime);
        }
Exemplo n.º 3
0
 void Update()
 {
     if (_ball != null)
     {
         _ball.Update();
     }
 }
Exemplo n.º 4
0
 public override void Update(GameTime gameTime)
 {
     _player.Update(gameTime);
     _enemy.Update(gameTime);
     _ball.Update(gameTime, _player, _enemy);
     CheckState();
 }
Exemplo n.º 5
0
        protected virtual void Update()
        {
            Board.Update();
            Ball.Update();
            Paddle.Update();

            foreach (Actor block in Blocks)
            {
                block.Update();
            }

            if (!Ball.GetComponent <BallActorComponent>().IsAlive)
            {
                Reset();
            }

            bool blocksLeft = false;

            foreach (Actor block in Blocks)
            {
                if (block.GetComponent <BlockActorComponent>().IsAlive)
                {
                    blocksLeft = true;

                    break;
                }
            }

            if (!blocksLeft)
            {
                Reset();
            }
        }
Exemplo n.º 6
0
 public override void Update(GameTime gameTime)
 {
     _debug.Update(gameTime);
     _paddles.Update(_ball);
     _score.Update();
     _ball.Update(_paddles);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Update the objects participating in the game
        /// </summary>
        /// <param name="gameTime">Snapshot of the gameTiming.</param>
        public void Update(GameTime gameTime)
        {
            _ball.Update(gameTime);
            _blockLeft.Update(gameTime);
            _blockRight.Update(gameTime);

            if (Sound.BGMInstance.State == SoundState.Stopped)
            {
                Sound.BGMInstance.Play();
            }

            // Ball - Bat collisons
            if (_ball._ballRectangle.Intersects(_blockLeft.lPaddleRectangle))
            {
                _ball.ballXSpeed = -_ball.ballXSpeed;
                _ball.ballYSpeed = -_ball.ballYSpeed;
                Sound.PlayDing();
                _leftScore++;
                // _Score =_leftScore.ToString() + ":" + _rightScore.ToString();
            }
            if (_ball._ballRectangle.Intersects(_blockRight.rPaddleRectangle))
            {
                _ball.ballXSpeed = -_ball.ballXSpeed;
                _ball.ballYSpeed = -_ball.ballYSpeed;
                Sound.PlayDing();
                _rightScore++;
                // _Score = _leftScore.ToString() + ":" + _rightScore.ToString();
            }
        }
Exemplo n.º 8
0
 public void Update(GameTime gameTime)
 {
     ball.Update(gameTime);
     can1.Update(gameTime);
     can2.Update(gameTime);
     can3.Update(gameTime);
 }
Exemplo n.º 9
0
	void MatchNearestBall(ref Vector2 position) {
		int i=0, len=balls.Length;
		int nearest = -1;
		float distance = float.MaxValue;
		float sqrmag;
		
		for(i=0; i<len; ++i) {
			if(balls[i].isUpdatedInThisFrame) {
				continue;
			}
			sqrmag = (balls[i].position - position).sqrMagnitude;
			if(sqrmag < distance) {
				distance = sqrmag;
				nearest = i;
			}
		}
		
		if(nearest < 0) {
			return;
		}
		
		Ball ball = balls[nearest];
		ball.Update(position);
		balls[nearest] = ball;
	}
Exemplo n.º 10
0
        public void Update(float delta)
        {
            if (c1 != null)
            {
                c1.Update(p1);
            }
            if (c2 != null)
            {
                c2.Update(p2);
            }
            if (playerAI != null)
            {
                playerAI.Update(p2, ball);
            }
            if (AI2 != null)
            {
                AI2.Update(p1, ball);
            }
            p1.Update(delta);
            p2.Update(delta);

            ball.Update(delta);

            HorizontalCollision(delta);
            VerticalCollision();
        }
Exemplo n.º 11
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            settings.Graphics = e.Graphics;

            //Work out how long since we were last here in seconds
            double gameTime    = _timer.ElapsedMilliseconds / 1000.0;
            double elapsedTime = gameTime - _lastTime;

            _lastTime = gameTime;
            _frameCounter++;

            //Perform any animation
            _player1.Update(gameTime, elapsedTime);
            _player2.Update(gameTime, elapsedTime);
            _ball_1.Update(gameTime, elapsedTime);


            DrawScoresAndBonus();

            //and the game objects
            _player1.Draw();
            _player2.Draw();
            _ball_1.Draw();

            //Force the next Paint()
            this.Invalidate();
        }
 private void UpdateGameObjects()
 {
     _paddle.Update(_gameState);
     _ball.Update(_gameState);
     foreach (var brick in _gameState.Bricks)
     {
         brick.Update();
     }
 }
Exemplo n.º 13
0
        public override void Update(GameTime theTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.P) || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                ScreenEvent.Invoke(this, new EventArgs());
                return;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Space))
            {
                if (isGameOver == true)
                {
                    StartGame(level);
                }
            }

            paddle.Update();
            aiPaddle.aiUpdate(level, ball);

            ball.Update();

            foreach (Wall wall in walls)
            {
                if (wall.CheckCollision(ball) == 1)
                {
                    score++;
                }
            }

            if (isPlayerTurn == true)
            {
                aiPaddle.Tint = new Color(255, 0, 0, 50);
                paddle.Tint   = new Color(0, 0, 255, 50);
                if (ball.PaddleCollision(paddle.GetBounds()) == 1)
                {
                    isPlayerTurn = !isPlayerTurn;
                }
            }
            else
            {
                aiPaddle.Tint = new Color(255, 0, 0, 50);
                paddle.Tint   = new Color(0, 0, 255, 50);
                if (ball.PaddleCollision(aiPaddle.GetBounds()) == 1)
                {
                    isPlayerTurn = !isPlayerTurn;
                }
            }

            if (ball.IsGameOver())
            {
                isGameOver = true;
            }

            base.Update(theTime);
        }
Exemplo n.º 14
0
 void OnTriggerEnter2D(Collider2D collider)
 {
     life--;
     ChangeNumber();
     ball.hasStarted = false;
     ball.Update();
     if (life == 0)
     {
         levelManager.LoadLevel("Lose");
     }
 }
Exemplo n.º 15
0
 public void Update()
 {
     if (ball.IsDead())
     {
         Dispose();
         SceneManager.GetInstance.ChangeScene(new GameOver());
         return;
     }
     ball.Update();
     player.Move(DirectionKey);
     BlockManager.GetInstance.Update();
 }
Exemplo n.º 16
0
    public void Update(GameTime gameTime)
    {
        if (IsGameOver)
        {
            return;
        }

        ball.Update(gameTime);
        can1.Update(gameTime);
        can2.Update(gameTime);
        can3.Update(gameTime);
    }
Exemplo n.º 17
0
    /// <summary>
    /// Update the models
    /// </summary>
    /// <param name="deltaTime"></param>
    public void Update(float deltaTime)
    {
        // Update the paddles
        leftPaddle.Update(deltaTime);
        rightPaddle.Update(deltaTime);

        // Check if the ball is colliding with any of the paddles
        CheckBallCollisionLeftPaddle();
        CheckBallCollisionRightPaddle();

        // Update the ball
        ball.Update(deltaTime);
    }
Exemplo n.º 18
0
    /// <summary>
    /// Updates all game objects for one frame of the game loop.
    /// </summary>
    /// <param name="gameTime">An object that contains information about the game time that has passed.</param>
    public void Update(GameTime gameTime)
    {
        // in the "game over" state, don't update any objects
        if (IsGameOver)
        {
            return;
        }

        ball.Update(gameTime);
        can1.Update(gameTime);
        can2.Update(gameTime);
        can3.Update(gameTime);
    }
Exemplo n.º 19
0
        public void Update(Graphics g, Rectangle window)
        {
            _graphics = g;
            _window   = window;

            if (_level == null)
            {
                LoadLevel();
            }

            if (_gameIsOver)
            {
                ShowGameOverMessage();
                return;
            }

            if (IsPaused)
            {
                ShowPauseMessage();
                return;
            }

            _ball.Update(g, window);
            _platform.Update(g, window);
            _bricks.ForEach(b =>
            {
                if (!b.IsSmashed)
                {
                    b.Update(g, window);
                }
            });

            _ball.ResolvePlatformCollisions(_platform);
            _ball.ResolveBricksCollisions(_bricks);

            _bricks.RemoveAll(b =>
            {
                _score += b.IsSmashed ? 100 : 0;
                return(b.IsSmashed);
            });

            if (!_bricks.Any())
            {
                LoadLevel();
            }

            ShowInfo();
        }
        public void Update(FrameEventArgs e)
        {
            // Set the title of the window
            sceneManager.Title = "Pong - Player Score: " + scorePlayer + " - AI Score: " + scoreAI;

            paddleAI.Move(ball.Position);

            ball.Update((float)e.Time);
            paddleAI.Update((float)e.Time);

            CollisionDetection();
            if (GoalDetection())
            {
                ResetGame();
            }
        }
Exemplo n.º 21
0
        public void Update(GameTime gameTime)
        {
            player.Update(gameTime);
            enemy.Update(gameTime);
            ball.Update(gameTime);

            if (ball.Hitbox.X < 0)
            {
                EnemyScores++;
                StartGame();
            }
            else if (ball.Hitbox.X > graphics.PreferredBackBufferWidth)
            {
                PlayerScores++;
                StartGame();
            }
        }
Exemplo n.º 22
0
 public void Update(GameTime gTime)
 {
     if (state == State.Playing)
     {
         player.Update(gTime, ball);
         enemy.Update(gTime, ball);
         ball.Update(gTime, player, enemy);
     }
     if (scorePlayer > scoreFinal)
     {
         state   = State.Victory;
         victory = "Congratulations! You beat the computer. Your Score: " + scorePlayer + "     Computer Score: " + scoreComputer;
     }
     else if (scoreComputer > scoreFinal)
     {
         state   = State.Victory;
         victory = "Better luck next time! Your Score: " + scorePlayer + "     Computer Score: " + scoreComputer;
     }
 }
Exemplo n.º 23
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 (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // TODO: Add your update logic here
            if (playerBall.ballState == BallState.STATIC)
            {
                mouseArrow.Update();
            }

            windArrow.Update(gameTime);
            playerBall.Update();
            enemyBall.Update();
            targetBall.Update();



            base.Update(gameTime);
        }
Exemplo n.º 24
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)
        {
            kBoard = Keyboard.GetState();

            //Player & Ball Movement
            if (canMove)
            {
                player1.Update(gameTime);
                player2.Update(gameTime);
                ball.Update(ref windowSize, gameTime);

                if (ball.Transform.Intersects(player1.Transform))
                {
                    ball.CollidedWith(ref player1);
                }
                if (ball.Transform.Intersects(player2.Transform))
                {
                    ball.CollidedWith(ref player2);
                }
            }
            base.Update(gameTime);
        }
Exemplo n.º 25
0
        public override void Update(GameTime theTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.P) || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                ScreenEvent.Invoke(this, new EventArgs());
                return;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Space))
            {
                if (isGameOver == true)
                {
                    StartGame();
                }
            }

            paddle.Update();
            ball.Update();

            foreach (Brick brick in textureAtlases.Bricks)
            {
                brick.CheckCollision(ball);
            }

            ball.PaddleCollision(paddle.GetBounds());

            if (ball.IsGameOver())
            {
                isGameOver = true;
            }

            if (textureAtlases.NoMoreBricks())
            {
                isGameOver = true;
            }

            base.Update(theTime);
        }
Exemplo n.º 26
0
        public void Update(float deltaTime)
        {
            if (GameWindow.GetGameWindow().Paused)
            {
                return;
            }

            if (PlayerOneServing)
            {
                _ball.PrepareToServe(_playerOne);
            }
            else if (PlayerTwoServing)
            {
                _ball.PrepareToServe(_playerTwo);
            }

            _ball.Update(_playerOne, _playerTwo, deltaTime);
            _playerOne.Update(PlayerOneTargetHeight, deltaTime);
            _playerTwo.Update(PlayerTwoTargetHeight, deltaTime);
            _aiController.Update(_ball, _playerOne, _playerTwo);

            Score();
        }
Exemplo n.º 27
0
        /// <summary>
        /// Steps the physics forward, checking for conditions.
        /// </summary>
        public async Task Update()
        {
            await Task.Run(() =>
            {
                if (LobbyState == LobbyStates.WonByLeft || LobbyState == LobbyStates.WonByRight)//check for win
                {
                    Reset();
                    return;
                }

                if (IsLobbyFull())
                {
                    LobbyState = LobbyStates.InGame;
                }
                if (LobbyState == LobbyStates.WaitingForPlayers)
                {
                    return;                                              //do nothing if the lobby is still waiting
                }
                Ball.Update();

                //Collision handle
                foreach (var player in Players)
                {
                    if (player.IsCollidingWith(in Ball.Hitbox))
                    {
                        CollidePaddleWithBall(player, ref Ball);
                    }
                }

                if (CurrentMap.Blocks.Length > 0)
                {
                    //needs to be for loop for ref block
                    for (var i = 0; i < (CurrentMap?.Blocks).Length; i++)
                    {
                        ref var block = ref (CurrentMap?.Blocks)[i];
                        if (block.IsCollidingWith(in Ball.Hitbox))
                        {
                            CollideBlockWithBall(ref block, ref Ball);
                        }
                    }

                    //If blocks have changed sense last iteration, mark diff bit
                    BlocksHaveChanged = CurrentMap.Blocks.Except(OldBlocks).Any();

                    //update blocks for diffing
                    OldBlocks = CurrentMap.Blocks.Copy();
                }

                //Goal scoring
                var actionIfScored = CurrentMap.CheckForGoal(in Ball.Hitbox) switch
                {
                    var(leftScored, _) when leftScored => () =>
                    {
                        ScoreBoard.ScoreLeft();
                        Ball.Reset();
                    },

                    var(_, rightScored) when rightScored => () =>
                    {
                        ScoreBoard.ScoreRight();
                        Ball.Reset();
                    },

                    _ => (Action)(() => {})
                };

                actionIfScored.Invoke();

                //WrapAround!
                Ball.KeepInBounds(CurrentMap.CanvasSize);

                //check for wins
                var actionIfWon = ScoreBoard.IsWon() switch
                {
                    var(leftWon, _) when leftWon => () => { LobbyState = LobbyStates.WonByLeft; }
                    ,
                    var(_, rightWon) when rightWon => () => { LobbyState = LobbyStates.WonByRight; }
                    ,
                    _ => (Action)(() => { })
                };
                actionIfWon.Invoke();
            });
Exemplo n.º 28
0
 private void Timer_Tick(object sender, EventArgs e)
 {
     ball1.Update();
     ball2.Update();
     ball3.Update();
 }
Exemplo n.º 29
0
 public void Update()
 {
     player1Ball.Update();
     player2Ball.Update();
     KeepTheBallOnGround();
 }
Exemplo n.º 30
0
 public void Update(GameTime gameTime)
 {
     ball.Update(gameTime);
 }