Esempio n. 1
0
        static void Main()
        {
            //if (dist_x > 40)
            //    rad = 0.5235987756;
            //else
            //    rad = 0.7853981634;

            //double x2 = -(Math.Cos(rad) * speed.x_direction - Math.Sin(rad) * speed.y_direction);
            //double y2 = -(Math.Sin(rad) * speed.x_direction + Math.Cos(rad) * speed.y_direction);
            Console.WriteLine(Math.Cos(0.3490658504) * 0.3 - Math.Sin(0.3490658504) * 0.3);
            Console.WriteLine(Math.Sin(0.3490658504) * 0.3 + Math.Cos(0.3490658504) * 0.3);

            using (var game = new SquashGame())
                game.Run();
        }
Esempio n. 2
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();
            }
        }
Esempio n. 3
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;
                    }
                }
            }
        }
Esempio n. 4
0
        public override void Update(double delta, SquashGame game)
        {
            // TODO: use this only once, when entering main menu
            game.ShowCursor();

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

            if (start_rect.Contains(mouse_x, mouse_y))
            {
                hover = 1;
            }
            else if (diff_rect.Contains(mouse_x, mouse_y))
            {
                hover = 2;
            }
            else if (quit_rect.Contains(mouse_x, mouse_y))
            {
                hover = 3;
            }
            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:
                    // it is possible to cast enum into int!
                    int current_diff = (int)difficulty;
                    if (mouse_x < diff_rect.Center.X && current_diff > 0)
                    {
                        difficulty = (Difficulty)(current_diff - 1);
                    }
                    else if (mouse_x > diff_rect.Center.X && current_diff < 2)
                    {
                        difficulty = (Difficulty)(current_diff + 1);
                    }


                    break;

                case 3:
                    game.Exit();
                    break;

                default:
                    // whoops
                    break;
                }
            }
        }
Esempio n. 5
0
 public abstract void Update(double delta, SquashGame game);