1 Replies - 1213 Views - Last Post: 20 December 2016 - 05:26 AM

#1 Braber01   User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 332
  • Joined: 29-November 08

Need General Help organizing Code for Breakout Powerups

Posted 03 November 2016 - 12:18 PM

I just want help with how to better orgnize my code, and help with filling a Rectangle with a color.

here is my code for the powerups:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

public abstract class BasePowerUp {
    protected string name;
    protected Texture2D image; //used for drawing the small powerup Filled Rectangle
    Rectangle powerUpRectangle; //I'm not sure if this is needed;
    Color rectColor;
    protected int width = 32;
    protected int height = 16;
    protected Game1 GameRef;
    protected Random rand;

    //Not sure what a valid constructor would be here
    public BasePowerUp(Rectangle rect, Color color) {
        this.powerUpRect = rect;
        this.rectColor = color;
        //GameRef = new Game1(); //not sure how to add a refrence to the game 

    public abstract void Update();

    public abstract void Draw(SpriteBatch spriteBatch);
//only one of the powerup classes follow

public class MultiBall(Rectangle rect,Color color) : base(rect,color) {
    public override void Update(){

    public override void Draw(SpriteBatch spriteBatch) {


I want to be able to draw an image, which is a filled Rectangle with a solid color,

I've been kind of stuck on this a while, and I'm not sure where to go.

Is This A Good Question/Topic? 0
  • +

Replies To: Need General Help organizing Code for Breakout Powerups

#2 SixOfEleven   User is offline

  • Planeswalker
  • member icon

Reputation: 1055
  • View blog
  • Posts: 6,643
  • Joined: 18-October 08

Re: Need General Help organizing Code for Breakout Powerups

Posted 20 December 2016 - 05:26 AM

What I would do is have a base class that has a Texture2D and Color property for the image of the power up and the color of the power up. To reuse the same image I create a grey scale image for that object. I then load that object into my game. When it comes to drawing it I tint it with the color I want it to appear in, such as Color.Red, Color.Blue or Color.Green instead of Color.White. Because of this the white parts are drawn in that tint color. The grey parts are drawn slightly darker and black is drawn as black because it cannot be tinted at all. In my break out tutorials I used this approach when it came to bricks. Check it out on my site.

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1