private SpriteBatch spriteBatch; // Allows us to write on backbuffer when we need to draw self public Paddle(float x, float y, float screenWidth, SpriteBatch spriteBatch, GameContent gameContent) { X = x; Y = y; imgPaddle = gameContent.imgPaddle; Width = imgPaddle.Width; Height = imgPaddle.Height; this.spriteBatch = spriteBatch; ScreenWidth = screenWidth; }
private SpriteBatch spriteBatch; // Allows us to write on backbuffer when we need to draw self public Brick(float x, float y, Color color, SpriteBatch spriteBatch, GameContent gameContent) { X = x; Y = y; imgBrick = gameContent.imgBrick; lParticle = gameContent.lParticle; Width = imgBrick.Width; Height = imgBrick.Height; this.spriteBatch = spriteBatch; Visible = true; this.color = color; }
public Wall(float x, float y, SpriteBatch spriteBatch, GameContent gameContent) { BrickWall = new Brick[7, 10]; float brickX = x; float brickY = y; Color color = Color.White; for (int i = 0; i < 7; i++) { switch (i) { case 0: color = Color.Red; break; case 1: color = Color.Orange; break; case 2: color = Color.Yellow; break; case 3: color = Color.Green; break; case 4: color = Color.Blue; break; case 5: color = Color.Indigo; break; case 6: color = Color.Violet; break; } brickY = y + i * (gameContent.imgBrick.Height + 1); for (int j = 0; j < 10; j++) { brickX = x + j * (gameContent.imgBrick.Width); Brick brick = new Brick(brickX, brickY, color, spriteBatch, gameContent); BrickWall[i, j] = brick; } } }
/// <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); gameContent = new GameContent(Content); // Create game objects int paddleX = (screenWidth - gameContent.imgPaddle.Width) / 2; // Center the paddle on the screen to start int paddleY = screenHeight - 100; // Set paddle to be 100 pixels from the bottom of the screen paddle = new Paddle(paddleX, paddleY, screenWidth, spriteBatch, gameContent); // Create the game paddle wall = new Wall(1, 50, spriteBatch, gameContent); // Create walls of bricks gameBorder = new GameBorder(screenWidth, screenHeight, spriteBatch, gameContent); // Game play field borders ball = new Ball(screenWidth, screenHeight, spriteBatch, gameContent); // Game ball staticBallIcon = new Ball(screenWidth, screenHeight, spriteBatch, gameContent) { X = 25, Y = 25, Visible = true, UseRotation = false }; // Static display ball for UI }
public Ball(float screenWidth, float screenHeight, SpriteBatch spriteBatch, GameContent gameContent) { X = 0; Y = 0; XVelocity = 0; YVelocity = 0; Rotation = 0; imgBall = gameContent.imgBall; Width = imgBall.Width; Height = imgBall.Height; this.spriteBatch = spriteBatch; this.gameContent = gameContent; ScreenWidth = screenWidth; ScreenHeight = screenHeight; Visible = false; Score = 0; bricksCleared = 0; UseRotation = true; }
private SpriteBatch spriteBatch; // Allows us to write on backbuffer when we need to draw self public GameBorder(float screenWidth, float screenHeight, SpriteBatch spriteBatch, GameContent gameContent) { Width = screenWidth; Height = screenHeight; ImgPixel = gameContent.imgPixel; this.spriteBatch = spriteBatch; }