Arranging Breakout Blocks

This is a discussion on Arranging Breakout Blocks within the Game Programming forums, part of the General Programming Boards category; I've been trying to figure out how to arrange my blocks, for a breakout type game. I was thinking of ...

  1. #1
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719

    Arranging Breakout Blocks

    I've been trying to figure out how to arrange my blocks, for a breakout type game. I was thinking of declaring variables of type int (columns and rows) and then use a for loop to draw the amount of blocks that I need. Would this work? Or can I use an array to better display these? Such as char red_block[10][10]. I know the best thing would be to create a tool that would aid me in displaying these blocks, but I'm not planning on doing that much work for something I will never use again. So any help would be nice! Thanks!

  2. #2
    glo
    glo is offline
    Registered User
    Join Date
    May 2006
    Posts
    169
    Wont parsing a simple text file that has a map of a specific level work well enough?
    Something like:
    1,1,2,2,1,1
    1,1,1,1,1,1
    0,0,0,0,0,0
    0,0,0,0,0,0
    etc.

  3. #3
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    I could just do this in a 2D-Array, no? I am going to have different colored blocks (red, green, blue, etc.) So I would have to define which number equals what color?

  4. #4
    glo
    glo is offline
    Registered User
    Join Date
    May 2006
    Posts
    169
    Yes, a 2D array should do the trick nicely.
    After you parse the text file make sure to place the data into an array.
    Then have your engine use that array for building and drawing your in-game level.

  5. #5
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Alright! So, for the defining the color constants which would be the best to use, from the following:
    Code:
    const int red=0
    or
    Code:
    enum COLOR={GREEN,RED,BLUE}
    I think the enumeration is the best way to go, but what do I know

  6. #6
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,516
    0 could be an empty space and you would be left with 9 colors. Alpha characters could be used for special blocks:

    Code:
    2,w,0,0,2   w = wall block
    2,2,w,0,3   x = bomb block
    4,x,0,3,3   2 = green, 3 = blue, 4 = grey, 0 = empty space
    If you had different size blocks, you could build a matrix like so:

    Code:
    333,220,22,3,www     1, 2 and 3 size blocks
    w,444,2,000,22,22   
    x,22,0,3,0,44,332,2     note that all lines have 12 positions
    if the size of blocks extended vertically also. The matrix could look like,

    Code:
    333,222,22,3,www     empty spaces extend the block on the top.
       ,   ,33,33,22     note that they have to have the same size
    w,444,2,333,22,22    as the block on top of them.
    x,22,3,3,3,44,332,2
    Then juts build a nice parser for this. An implementation as easy as this also makes building a level editor a breeze.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  7. #7
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Are these blocks sprites or are you rendering them as quads? If you're rendering them you're going to want to make a struct of block information because there is going to be alot of information.
    Code:
    struct blocks {
       GLfloat corners[4][2];  // X and Y values for the 4 corners
       GLfloat color[3];  // Red, Green, Blue;
    };
    All of this information should be contained in your text file.

    1.0, 1.0
    0.0, 1.0
    0.0, 0.0
    0.0, 1.0
    1.0, 0.0, 0.0

    etc...
    Sent from my iPad®

  8. #8
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    I am using SDL and C++ to make this. So the blocks are sprites, with a .bmp extension.

    For blank space I could assign NULL to a value?

  9. #9
    glo
    glo is offline
    Registered User
    Join Date
    May 2006
    Posts
    169
    In case you read a '0' character for example from the array you just parsed, the engine should not create a block in its place.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pthread recv Blocks
    By scioner in forum C Programming
    Replies: 6
    Last Post: 03-13-2008, 08:45 PM
  2. Identifying 3x3 blocks (2d-array)
    By Shapper in forum C++ Programming
    Replies: 4
    Last Post: 04-29-2007, 01:12 PM
  3. Breakout althorigm help!!!
    By hdragon in forum Game Programming
    Replies: 1
    Last Post: 02-20-2006, 11:03 PM
  4. My Breakout Clone is Insane
    By Grantyt3 in forum C++ Programming
    Replies: 10
    Last Post: 12-18-2005, 12:45 PM
  5. get nxn size blocks from 2d array?
    By acfror in forum C Programming
    Replies: 4
    Last Post: 10-28-2005, 03:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21