/// <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); //Create a new list of players playerList = new List<Paddle>(); gameFont = Content.Load<SpriteFont>("Fonts/ScoreFont"); player1ScoreBoard = new Scoreboard(this, spriteBatch, gameFont, new Vector2(0, 0), "Doug", true); this.Components.Add(player1ScoreBoard); player2ScoreBoard = new Scoreboard(this, spriteBatch, gameFont, new Vector2(stage.X - (LARGE_PADDING), 0), "Kendall", false); this.Components.Add(player2ScoreBoard); //Load the paddle texture Texture2D paddleTexture = Content.Load<Texture2D>("Images/Paddle"); //Create player 1 Vector2 paddle1Position = new Vector2(PADDING, stage.Y / 2 - paddleTexture.Height / 2); player1 = new Paddle(this, spriteBatch, paddleTexture, paddle1Position, Keys.A, Keys.Z); playerList.Add(player1); //Create player 2 Vector2 paddle2Position = new Vector2(stage.X - paddleTexture.Width - PADDING, stage.Y / 2 - paddleTexture.Height / 2); player2 = new Paddle(this, spriteBatch, paddleTexture, paddle2Position, Keys.Up, Keys.Down); playerList.Add(player2); //Create the ball Texture2D ballTexture = Content.Load<Texture2D>("Images/Ball"); ball = new Ball(this, spriteBatch, ballTexture); this.Components.Add(ball); //Add each player to the GameComponents list foreach (Paddle paddle in playerList) { this.Components.Add(paddle); } //Create a new collision manager collisionManager = new CollisionManager(this, playerList, ball); this.Components.Add(collisionManager); //Create a new sound manager soundManager = new SoundManager(this); this.Components.Add(soundManager); }
/// <summary> /// Create a new CollisionManager object /// </summary> /// <param name="game">Game reference for the component</param> /// <param name="playerList">List of players (paddles)</param> /// <param name="ball">Ball reference</param> public CollisionManager(Game game, List<Paddle> playerList, Ball ball) : base(game) { this.playerList = playerList; this.ball = ball; }