예제 #1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            base.Initialize();
            IsMouseVisible = true;
            masterServerIP = File.ReadAllText(@"Content\MasterServerIP.txt");

            if (!hasStarted)
            {
                state = State.Connect;
                focus = FieldFocus.Name;
                serverNameTextHost = new InputBox(new Vector2(100, 100));
                passwordTextHost = new InputBox(new Vector2(100, 130));
                serverNameTextJoin = new InputBox(new Vector2(100, 400));
                passwordTextJoin = new InputBox(new Vector2(100, 430));
            }

            ballCount = 1;
            powerCount = 1;
            powerTimer = 0;
            allGameObjects = new List<GameObject>();
            allGameObjects.Clear();
            suicidalObjects = new List<GameObject>();
            addThese = new List<GameObject>();
            windowHeight = Window.ClientBounds.Height;
            windowWidth = Window.ClientBounds.Width;

            if (hasStarted)
            {
                #region
                Sprite pongSprite = new Sprite(new Vector2(200, 200), 0.5f, new Vector2(1, 1), Color.White, SpriteEffects.None);
                Sprite ballSprite = new Sprite(new Vector2(200, 200), 0.5f, new Vector2(1, 1), Color.White, SpriteEffects.None);
                Sprite wallSprite = new Sprite(new Vector2(200, 200), 1, new Vector2(80, 2), Color.White, SpriteEffects.None);
                Sprite netSprite = new Sprite(new Vector2(200, 200), 0.5f, new Vector2(0.5f, 1), Color.White, SpriteEffects.None, @"PongMiddle");

                Rectangle pongCollision = new Rectangle(0, 0, 10, 82);
                Rectangle ballColl = new Rectangle(0, 0, 15, 15);
                Rectangle pwrColl = new Rectangle(0, 0, 40, 40);
                Rectangle wallCollision = new Rectangle(0, 0, Window.ClientBounds.Width, 15);

                SpriteA animatedSprite = new SpriteA(new Vector2(200, 200), 0.5f, new Vector2(1, 1), Color.White, SpriteEffects.None, @"powerpad");
                animatedSprite.CreateAnimation("Orb", 8, 0, 1, (648 / 8), (486 / 6), Vector2.Zero, 15f);
                animatedSprite.PlayAnimation("Orb");
                PowerUp powerup = new PowerUp(animatedSprite, new Vector2(rnd.Next(50, 600), rnd.Next(100, 350)), new Vector2(40, 0), 0, Content, pwrColl);

                SoundEffect wallBounce = Content.Load<SoundEffect>(@"SoundFX\wall_effect");
                SoundEffect pad1Bounce = Content.Load<SoundEffect>(@"SoundFX\pad1_effect");
                SoundEffect pad2Bounce = Content.Load<SoundEffect>(@"SoundFX\pad2_effect");

                GameObject net = new GameObject(netSprite, new Vector2(windowWidth / 2, windowHeight / 2), new Vector2(1, 0), 0, Content, new Rectangle(0, 0, 0, 0));

                if (isHost)
                {
                    p1Pad = new PongPaddle(PlayerNumber.player1, pongSprite, new Vector2(50, 250), new Vector2(0, 0), 100, Content, pongCollision, pad1Bounce);
                    p2PadGobject = new Dummyclass(pongSprite, new Vector2(740, 250), new Vector2(0, 0), 100, Content, pongCollision, 'p', ClientPort, pad2Bounce);
                    myBallDummy = null;
                }
                else
                {
                    p1Pad = new PongPaddle(PlayerNumber.player1, pongSprite, new Vector2(740, 250), new Vector2(0, 0), 100, Content, pongCollision, pad1Bounce);
                    p2PadGobject = new Dummyclass(pongSprite, new Vector2(50, 250), new Vector2(0, 0), 100, Content, pongCollision, 'p', ClientPort, pad1Bounce);
                    myBallDummy = new Dummyclass(ballSprite, new Vector2(400, 200), new Vector2(0, 0), 0, Content, ballColl, 'b', ClientPort + 1, null);
                }
                p1Pad.Sprite.Scale = new Vector2(1, 8);
                //P2 is basicly useless though
                p2Pad = new PongPaddle(PlayerNumber.player2, pongSprite, new Vector2(740, 250), new Vector2(0, 0), 100, Content, pongCollision, pad2Bounce);
                myBall = new Ball(ballSprite, new Vector2(400, 200), new Vector2(40f, 20), 100, Content, ballColl, rnd);

                Wall topWall = new Wall(wallSprite, new Vector2(Window.ClientBounds.Width * 0.5f, 0), new Vector2(0, 1), 0, Content, wallCollision, wallBounce);
                Wall bottomWall = new Wall(wallSprite, new Vector2(Window.ClientBounds.Width * 0.5f, Window.ClientBounds.Bottom), new Vector2(0, -1), 0, Content, wallCollision, wallBounce);

                allGameObjects.Add(p1Pad);
                allGameObjects.Add(p2Pad);
                allGameObjects.Add(myBall);
                allGameObjects.Add(topWall);
                //allGameObjects.Add(powerup);
                allGameObjects.Add(myBallDummy);
                allGameObjects.Add(bottomWall);
                allGameObjects.Add(p2PadGobject);
                allGameObjects.Add(net);
                hasJustScored = false;
                #endregion
            }
        }
예제 #2
0
 public PongPlayer(PlayerIndex playerIndex, int player, Texture2D paddleTexture)
     : base(playerIndex)
 {
     paddle = new PongPaddle(player, paddleTexture, null, Vector2.Zero, 1.0f);
     /* we now have access to which player this class represents at run time */
 }