Question Breakout Game

Rayray

New member
Joined
Apr 30, 2012
Messages
2
Programming Experience
Beginner
I am Making a simple breakout game and I am having trouble making an array of bricks and having them display on the board that I created. Also when the ball hits brick and the bumper the ball gets stuck inside of either the bumper or the brick. Any help would be appreciated thanks.

<Attachment removed by moderator>
 
Last edited by a moderator:

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,137
Location
Sydney, Australia
Programming Experience
10+
I have removed your attachment because attachments containing binary files are not allowed. If you want to upload a project or solution then make sure all binaries are removed first, which means at least deleting all 'bin' and 'obj' folders.

That said, I would suggest that uploading the whole project should be a last resort only. You're expecting us to download your ZIP file, extract it, open the solution and then start looking through code to first find the problem before we can even think about fixing it. Noone in their right mind is going to actually run your code without examining it to make sure there's nothing malicious in there, which is more effort on our part. How about you help us to help you by:

1. Identify one issue at a time.
2. Provide a clear explanation of what you're trying to achieve.
3. Provide a clear explanation of how you're trying to achieve it, which would include posting all and only the relevant code directly, using
 tags to make your snippet(s) readable.
4. Provide a clear explanation of exactly what happens, including any and all error messages and where they occur, and how that differs from your expectations.
5. Zip and upload the whole solution (without binaries) if the problem can't be solved otherwise.
 

Rayray

New member
Joined
Apr 30, 2012
Messages
2
Programming Experience
Beginner
I apologize for posting the whole zip file to the website. This is my code so far that I have worked on. I thought it would have worked because I am making an array of bricks then looping through that array to find a specific index and drawing that to the board.
C#:
   private Brick brick = new Brick();


Making a brick array of size 20 now I need to draw these to the board class.
        Brick[] numberOfBricks = new Brick[20];

        public Board()
        {
            ball = new Ball(new Point(10, 10));


            this.Location = new System.Drawing.Point(0, 0);
            this.Size = new System.Drawing.Size(500, 462);

            this.Visible = true;

            movement.Interval = 1;
            movement.Tick += new EventHandler(movement_Tick);

            this.KeyDown += new KeyEventHandler(Board_KeyDown);
            this.Paint += new PaintEventHandler(Form1_Paint);

            delta =2;
        }


        private void Render()
        {
            BufferedGraphicsContext currentContext;
            BufferedGraphics buffer;
            currentContext = BufferedGraphicsManager.Current;

            //create the bufer to draw onto
            buffer = currentContext.Allocate(this.CreateGraphics(), this.DisplayRectangle);

            buffer.Graphics.DrawImage(newImage, corners);

            ball.DrawMe(buffer.Graphics);
            bumper.Draw(buffer.Graphics);

            [COLOR=#ff0000] for (int index = 0; index < numberOfBricks.Length; index++)[/COLOR][COLOR=#ff0000]            {[/COLOR]
[COLOR=#ff0000]                numberOfBricks[index].Draw(buffer.Graphics);[/COLOR]
[COLOR=#ff0000]            }   [/COLOR]


            //draw the buffer to the visible scfrren
            buffer.Render();
            //always destroy a buffer after you are done with it!!!
            buffer.Dispose();
        }
I do not understand the error in read it says "Object reference not set to an instance of an object."



This is my brick class where I need to create the bricks

C#:
public class Brick : Images
    {
        private Rectangle brick;
        private const int WIDTH = 500;
        private const int NBRICKS_PER_ROW = 10;
        private const int NBRICK_ROWS = 10;
        private const int BRICK_SEP = 2;
        private const int BRICK_WIDTH = (WIDTH - (NBRICKS_PER_ROW - 1) * BRICK_SEP) / NBRICKS_PER_ROW;
        private const int BRICK_HEIGHT = 8;


        //List<Rectangle> brick = new List<Rectangle>();

        public Brick()
            : base("brick.gif")
        {
            brick.X = 150;
            brick.Y = 150;
            this.UpdateBounds(brick.Location);
        }
        public Rectangle Bounds
        {
            get
            {
                return brick;
            }
        }
        public void Hits()
        {
            brick = Rectangle.Empty;
        }
 
Top Bottom