Ejemplo n.º 1
0
        public override void Update(double delta, SquashGame game)
        {
            game.ShowCursor();
            // if any key is pressed
            if (game.keyboardState.GetPressedKeys().Length > 0)
            {
                game.ShowMainMenu();
            }

            if (game.mouseState.LeftButton == ButtonState.Pressed)
            {
                mouseClick = true;
            }
            else if (mouseClick == true)
            {
                mouseClick = false;
                game.ShowMainMenu();
            }
        }
Ejemplo n.º 2
0
        public override void Update(double delta, SquashGame game)
        {
            if (!end_game)
            {
                game.HideCursor();
                // paddle x position is same as mouse x
                paddle.Move_to_x(game.mouseState.X);
                // TODO: clip mouse cursor to the middle of the screen

                ball.Update_position((float)delta);

                // moving opponent

                if (!player_turn)
                {
                    float enemy_velocity  = 0.35f;
                    int   reaction_height = 0;
                    switch (MainMenu.difficulty)
                    {
                    case Difficulty.EASY:
                        reaction_height = 300;
                        break;

                    case Difficulty.MEDIUM:
                        reaction_height = 200;
                        break;

                    case Difficulty.HARD:
                        reaction_height = 100;
                        break;
                    }

                    if (ball.position.Y > reaction_height)
                    {
                        int direction = 1;

                        if (paddle_opponent.position.Center.X < ball.position.Center.X)
                        {
                            direction = 1;
                        }
                        else
                        {
                            direction = -1;
                        }
                        paddle_opponent.Move_to_x((int)(paddle_opponent.position.X + enemy_velocity * delta * direction));
                    }
                }

                // if you score a goal
                if (ball.isGoal)
                {
                    if (!player_turn)
                    {
                        score++;
                    }
                    else
                    {
                        enemy_score++;
                    }

                    ball.isGoal = false;
                    game_coin.Play(volume, pitch, pan);
                }

                // if you failed

                if (ball.isFail)
                {
                    ball.isFail = false;

                    if (player_turn)
                    {
                        if (lifes >= 1)
                        {
                            lifes--;
                        }
                    }
                    else
                    {
                        if (enemy_lifes >= 1)
                        {
                            enemy_lifes--;
                        }
                    }

                    if (enemy_lifes < 1 || lifes < 1)
                    {
                        //gameover
                        game_over_arcade.Play(volume, pitch, pan);
                        end_game        = true;
                        ball.position.X = 10000;
                    }
                    else
                    {
                        fail.Play(volume - 0.5f, pitch, pan);
                    }

                    player_turn = true;
                    if (!Collision.ListOfObjectsWithCollision.Contains(paddle))
                    {
                        Collision.ListOfObjectsWithCollision.Add(paddle);
                    }

                    if (Collision.ListOfObjectsWithCollision.Contains(paddle_opponent))
                    {
                        Collision.ListOfObjectsWithCollision.Remove(paddle_opponent);
                    }
                }

                // when ball hits a paddle
                if (ball.isInPaddle)
                {
                    shot.Play(volume, pitch, pan);
                }
            }
            else
            {
                game.ShowCursor();
                // show scoreboard

                int mouse_x = game.mouseState.X;
                int mouse_y = game.mouseState.Y;

                if (retry_rect.Contains(mouse_x, mouse_y))
                {
                    hover = 1;
                }
                else if (quit_rect.Contains(mouse_x, mouse_y))
                {
                    hover = 2;
                }
                else
                {
                    hover = 0;
                }

                // mouse clicking

                if (game.mouseState.LeftButton == ButtonState.Pressed)
                {
                    mouseClick = true;
                }
                else if (mouseClick == true)
                {
                    mouseClick = false;

                    // Left mouse button click detected:

                    switch (hover)
                    {
                    case 1:
                        game.ShowGameMode();
                        break;

                    case 2:
                        game.ShowMainMenu();
                        break;

                    default:
                        // whoops
                        break;
                    }
                }
            }
        }