Jump to content
  • Advertisement
Sign in to follow this  
phil67rpg

2-d arrays and breakout

This topic is 3880 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am working on a breakout game and want to use a 2-d array for the building of the wall and am unsure of how to proceed.

Share this post


Link to post
Share on other sites
Advertisement
Well a good first step would to be to choose a programming language or other game making package to do your game in.

Share this post


Link to post
Share on other sites
What is the issue you're having with using a 2D array for representing the play area? Are you stumped somewhere, or are you just looking for tips in general?

Share this post


Link to post
Share on other sites
well I have developed the 2-d array that I am using to draw the bricks, any tips on how to proceeed would be very helpful, below is some code

for (m=0;m<3;m++)
{
for (n=0;n<7;n++)
{
array[m][n]=1;
}
}
any tips would be helpful

Share this post


Link to post
Share on other sites
So you have a 2x6 array that you're filling with ones? Not sure what you're doing here...

Ok... Here's what I recommend:

1. Create your block graphics. These should probably be rectangular (16x8 pixels per block for instance)

2. Create an array of "block type" structs. This struct should define the characteristics of each block type. For instance, if one of your types of block is a red block that needs 3 hits to be destroyed, you'll have a variable in it that says which graphic to use to represent it, and a variable that says how much health it has (3). You can also have variables such as "is indestructible" or "gives a 'longer paddle' bonus."

3. Create a "map" array that is the size of your play field in blocks. For instance, 20 by 80. The array should be an array of bytes (chars). You'll most likely want to have 0 for empty areas. In places where there are blocks, put a "block type" id number there. (if your basic red block is type 1, put a 1, etc)

4. Create a "play area" array that is 20 by 80 (if that's your play field size) and contains information about the current play field. Each entry should be a "block" struct -- different from the block type struct -- which carries information such as "there is a block there (or not)", "number of hits left before this is destroyed", "this is a breakable block (or not)", etc.


When you have all that, you're ready to read your level into the game:

1. Start at the beginning of your map array, with a for loop.
2. Retrieve the id number for the current block.
3. Get information from your list of block types that corresponds to this id number (basically, should be something like list_of_block_types[current_block_id_number])
4. Fill up the corresponding block in your "play area" array with data retrieved from the "block type" you identified.

And each game loop, simply read your "play area" array each time, and use the data in there to draw your blocks, skipping over those that have an id of "0" since those are empty...

While the game is in progress, you can simply check for collisions and modify data in your "play area" array, by reducing blocks' HP when they get hit for instance.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!