Esempio n. 1
0
 public CollisionManger(Game game, Ball ball, Bat playerOne, Bat playerTwo)
     : base(game)
 {
     this.ball      = ball;
     this.playerOne = playerOne;
     this.playerTwo = playerTwo;
 }
Esempio n. 2
0
        public void AddNormalPlayer()
        {
            Bat player = new Bat(
                game: this,
                controller: new PlayerController(Keyboard.Key.Up, Keyboard.Key.Down),
                position: new PVector2F(width - 20, height / 2 - BarHeight / 2),
                size: new PVector2F(BarWidth, BarHeight),
                speed: BatSpeed);

            _entities.Add(player);
        }
Esempio n. 3
0
        public void AddAiPlayer()
        {
            Bat player = new Bat(
                game: this,
                controller: new AiController(this),
                position: new PVector2F(width - 10, height / 2 - BarHeight / 2),
                size: new PVector2F(BarWidth, BarHeight),
                speed: BatSpeed);

            _entities.Add(player);
        }
Esempio n. 4
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            textFont    = Content.Load <SpriteFont>("font/textFont");

            backTexture = Content.Load <Texture2D>("backround/pongTable");
            nameFont    = Content.Load <SpriteFont>("font/nameFont");



            stage = new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);

            playerText        = Content.Load <Texture2D>("images/Bat");
            playerOnePosition = new Vector2(0, (stage.Y / 2) - (playerText.Height / 2));
            playerTwoPosition = new Vector2(stage.X - playerText.Width, (stage.Y / 2) - (playerText.Height / 2));

            gameBallText = Content.Load <Texture2D>("images/ball");
            ballPosition = new Vector2((stage.X / 2) - (gameBallText.Width / 2), (stage.Y / 2) - (gameBallText.Height / 2));
            ballSpeed    = randomSpeed();
            //Loading Game Objects
            playerOne = new Bat(this,
                                spriteBatch,
                                playerText,
                                playerOnePosition,
                                stage);
            playerTwo = new Bat(this,
                                spriteBatch,
                                playerText,
                                playerTwoPosition,
                                stage);
            ball = new Ball(this,
                            spriteBatch,
                            gameBallText,
                            ballPosition,
                            stage);
            collisionManager = new CollisionManger(this, ball, playerOne, playerTwo);
            playerOneString  = new DrawString(this, spriteBatch, textFont, new Vector2(170, 50));
            playerTwoString  = new DrawString(this, spriteBatch, textFont, new Vector2(575, 50));
            winnerString     = new DrawString(this, spriteBatch, textFont, new Vector2(stage.X / 3, stage.Y / 2));


            // TODO: use this.Content to load your game content here
            Components.Add(playerOne);
            Components.Add(playerTwo);
            Components.Add(ball);
            Components.Add(collisionManager);
            Components.Add(playerOneString);
            Components.Add(playerTwoString);
            Components.Add(winnerString);
        }
Esempio n. 5
0
 public void Update(Bat bat)
 {
     if (Keyboard.IsKeyPressed(_up))
     {
         bat.Velocity = new PVector2F(0, -1);
     }
     else if (Keyboard.IsKeyPressed(_down))
     {
         bat.Velocity = new PVector2F(0, 1);
     }
     else
     {
         bat.Velocity = new PVector2F(0, 0);
     }
 }
Esempio n. 6
0
 public bool Move(int ch, int cw, Bat u)
 {
     Shape = new Rect(Shape.X + dx, Shape.Y + dy, Shape.Height, Shape.Width);
     if (Shape.Top <= 0 || Shape.IntersectsWith(u.Shape))
     {
         dy = -dy;
     }
     if (Shape.Left <= 0 || Shape.Right >= cw)
     {
         dx = -dx;
     }
     if (Shape.Top >= ch)
     {
         return(true);
     }
     return(false);
 }
Esempio n. 7
0
        public void Update(Bat bat)
        {
            var playerOne = _game.GetEntities <Bat>()[0];
            var playerTwo = _game.GetEntities <Bat>()[1];
            var ball      = _game.GetEntities <Ball>()[0];

            _clientWriter.Write("{0} {1} {2} {3} {4} {5} {6},",
                                ball.Position.X,
                                ball.Position.Y,
                                ball.Velocity.X,
                                ball.Velocity.Y,
                                ball.EffectiveSpeed,
                                playerOne.Position.Y,
                                playerTwo.Position.Y);
            _clientWriter.Flush();

            bat.Velocity = _velocity;
        }
Esempio n. 8
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            ContentLoader.Content = Content;
            player1 = new Bat(new Vector2(0, 176));
            player2 = new Bat(new Vector2(768, 176));
            balls   = new List <Ball>();
            for (int i = 0; i < 10; i++)
            {
                balls.Add(new Ball(new Vector2(392, 232)));
            }
            font = Content.Load <SpriteFont>("font");
            foreach (Ball ball in balls)
            {
                BallReset(ball);
            }
        }
Esempio n. 9
0
 private void SetUpSingle()
 {
     rightBat = new AIBat(Content, new Vector2(screenWidth, screenHeight), false);
     leftBat = new Bat(Content, new Vector2(screenWidth, screenHeight), true);
 }
Esempio n. 10
0
 private int CheckHitLocation(Bat bat)
 {
     int block = 0;
     if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 20) block = 1;
     else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 10 * 2) block = 2;
     else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 10 * 3) block = 3;
     else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 10 * 4) block = 4;
     else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 10 * 5) block = 5;
     else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 10 * 6) block = 6;
     else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 10 * 7) block = 7;
     else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 10 * 8) block = 8;
     else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 20 * 19) block = 9;
     else block = 10;
     return block;
 }
Esempio n. 11
0
 public ViewModel()
 {
     Balls  = new List <Sphere>();
     Slider = new Bat();
     Lifes  = 5;
 }