Ejemplo n.º 1
0
 public Menu(List<Text> listoptions,Texture2D Menuimg)
 {
     ListofOptions = listoptions;
     maxitems = listoptions.Count - 1;
     currentitem = 0;
     G = GameScreens.GameState.Menu;
     ListofOptions[currentitem].isselected = true;
     img = Menuimg;
 }
Ejemplo n.º 2
0
 protected void difficulty()
 {
     gamescreen = GameScreens.GameState.DifficultySelect;
     List<Text> Menutextdiff = new List<Text>();
     Menutextdiff.Add(new Text(new Vector2(360,150),"Easy",font,easy));
     Menutextdiff.Add(new Text(new Vector2(360, 200), "Medium", font, easy));
     Menutextdiff.Add(new Text(new Vector2(360, 250), "Hard", font, easy));
     difmenu = new Menu(Menutextdiff, difficultymenu);
 }
Ejemplo n.º 3
0
 protected override void LoadContent()
 {
     gamescreen  = GameScreens.GameState.Menu;
     font = Content.Load<SpriteFont>("GameFont");
     ListMenu = new List<Text>();
     mainmenuimg = Content.Load<Texture2D>("MainMenu");
     ListMenu.Add(new Text(new Vector2(50, 50), "Human vs Human", font, gamestart));
     ListMenu.Add(new Text(new Vector2(50, 100), "Human vs Computer", font, difficulty));
     ListMenu.Add(new Text(new Vector2(50, 150), "Exit", font,End));
     mainmenu = new Menu(ListMenu,mainmenuimg);
     spriteBatch = new SpriteBatch(GraphicsDevice);
     ball = Content.Load<Texture2D>("Ball");
     paddle = Content.Load<Texture2D>("Paddle");
     board = Content.Load<Texture2D>("Board");
     gametimer = new Stopwatch();
     keyboardstate = new KeyboardState();
     oldkeyboardstate = new KeyboardState();
     difficultymenu = Content.Load<Texture2D>("Difficulty Screen");
     timerstarted = false;
     timestart = new Stopwatch();
     gameend = false;
 }
Ejemplo n.º 4
0
        protected override void Update(GameTime gameTime)
        {
            oldkeyboardstate = keyboardstate;
            keyboardstate = Keyboard.GetState();

            if (gameend)
            {
                if (keyboardstate.IsKeyDown(Keys.Escape))
                {

                    gamescreen = GameScreens.GameState.Menu;
                    ListMenu = new List<Text>();

                    ListMenu.Add(new Text(new Vector2(50, 50), "Human vs Human", font, gamestart));
                    ListMenu.Add(new Text(new Vector2(50, 100), "Human vs Computer", font, difficulty));
                    ListMenu.Add(new Text(new Vector2(50, 150), "Exit", font, End));
                    mainmenu = new Menu(ListMenu,mainmenuimg);
                    gameend = false;

                }
            }

            if (gamescreen == GameScreens.GameState.Play)
            {
                if (timerstarted)
                {
                    if (timestart.ElapsedMilliseconds > 3000)
                    {

                        timestart.Stop();
                        timestart.Reset();
                        timerstarted = false;
                        gameball.start_ball();
                    }
                }

                Left.TakeInput(keyboardstate);
                Right.TakeInput(keyboardstate);
                gameball.updatepaddleboundary(Left.boundary, Right.boundary);
                gameball.update();
                if (gameball.Location.X < -25)
                {
                    playerright.scored();
                    gameball.stop();
                    gameball.keepinposition();
                    timestart.Start();
                    timerstarted = true;

                }
                else if (gameball.Location.X > 750)
                {
                    playerleft.scored();
                    gameball.stop();
                    gameball.keepinposition();
                    timestart.Start();
                    timerstarted = true;

                }
                if (playerleft.Score == 10)
                {
                    gameover(playerleft);
                    timestart.Stop();
                }
                if (playerright.Score == 10)
                {
                    gameover(playerright);
                    timestart.Stop();
                }
            }
            else if (gamescreen == GameScreens.GameState.Menu)
            { mainmenu.input(keyboardstate,oldkeyboardstate); }
            else if (gamescreen == GameScreens.GameState.PlayComp)
            {
                if (timerstarted)
                {
                    if (timestart.ElapsedMilliseconds > 3000)
                    {

                        timestart.Stop();
                        timestart.Reset();
                        timerstarted = false;
                        gameball.start_ball();
                    }
                }

                computer.updatepaddle(gameball,Left);
                gameball.updatepaddleboundary(Left.boundary, Right.boundary);
                Right.TakeInput(keyboardstate);
                gameball.update();
                if (gameball.Location.X < -25)
                {
                    playerright.scored();
                    gameball.stop();
                    gameball.keepinposition();
                    timestart.Start();
                    timerstarted = true;

                }
                else if (gameball.Location.X > 750)
                {
                    playerleft.scored();
                    gameball.stop();
                    gameball.keepinposition();
                    timestart.Start();
                    timerstarted = true;

                }
                if (playerleft.Score == 10)
                {
                    gameover(playerleft);
                    timestart.Stop();
                }
                if (playerright.Score == 10)
                {
                    gameover(playerright);
                    timestart.Stop();
                }
            }
            else if (gamescreen == GameScreens.GameState.DifficultySelect)
            {
                difmenu.input(keyboardstate, oldkeyboardstate);
            }

            base.Update(gameTime);
        }
Ejemplo n.º 5
0
 protected void gamestart()
 {
     playerleft = new Player(new Vector2(50, 480), font,"Player Left");
     playerright = new Player(new Vector2(600, 480), font,"Player Right");
     Left = new Paddle(0, 213, paddle, Keys.W, Keys.S);
     Right = new Paddle(740, 213, paddle, Keys.Up, Keys.Down);
     upb = new Boundary(0, 0, 750, 20);
     downb = new Boundary(0, 480, 750, 20);
     gameball = new Ball(ball, upb.boundary, downb.boundary, Left.boundary, Right.boundary, font);
     timestart.Start();
     timerstarted = true;
     gameball.keepinposition();
     gamescreen = GameScreens.GameState.Play;
     gametimer.Start();
 }