/// <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() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // Publish the service, allowing everything to use the spriteBatch Services.AddService(typeof(SpriteBatch), spriteBatch); // Player classes. player1 = new Player(this, Pallet.PlayerNumber.PlayerOne); player1.Name = "Player 1"; player2 = new Player(this, Pallet.PlayerNumber.PlayerTwo); player2.Name = "Player 2"; // Ball classes. ball = new Ball(this); // Collision groups collisionGroup = new Group("Collisions"); playerGroup = new Group("Players"); playerGroup.Add(player1.Pallet); playerGroup.Add(player2.Pallet); // Groups GroupList GameGroups = new GroupList(); GameGroups.Add(collisionGroup); GameGroups.Add(playerGroup); //Add the list of groups into the services so objects can retrieve info about items in specific groups Services.AddService(typeof(GroupList), GameGroups); // Blocks BlockList = new BlockManager(this); // Will initialize the basic graphical objects. base.Initialize(); // Goes to LoadContent() // Placed after general initialisation so the texture is already loaded and its size initialized player1.Pallet.placeInDefaultPosition(); player2.Pallet.placeInDefaultPosition(); /* Define the block safe zone, it's meant to restrict where the blocks can appear so they don't get on top of the pallet * or behind it. */ BlockList.BlocksSafeZone = new Rectangle((int)player1.Pallet.Position.X + 1, 0, (int)player2.Pallet.Position.X + (int)player2.Pallet.ObjectRectangle.Width - (int)player1.Pallet.ObjectRectangle.X - BlockList.MaxBlockSize, Window.ClientBounds.Height - BlockList.MaxBlockSize); // Places the ball in the center position and give it a random angle. ball.placeInDefaultPosition(); }