Jump to content
  • Advertisement
Sign in to follow this  
zergdeath1

Break Out, Instances?

This topic is 5043 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 want to make breakout as my next project. But of course I have a few snags: 1. I do not know how I would create multiple blocks? I could create "personal" instances of the object with their own unique name, That the program call specifically, but that would be long, dirty, and basically useless. So I know I need to create an array like thing to store each instance of the class, But I dont know how. 2. If I want to have this game actually play, Im going to need more than one level. Aside from having a randomly generated level each time(interesting but not what i want). I would need to make both a level editor and have a way to save them. So I could probably make a level editor even though it would take me a while. But I still dont know how to save it. My only Idea is to just save the blocks as text. With the level # in (). So I would have my code loop through the corditnates and then stop when it hit a (. And start again if there are no blocks on screen. But that would be hard to make and implement, so I was wondering if there was a better way?

Share this post


Link to post
Share on other sites
Advertisement
I made breakout long ago. I didn't make any instances. I had a file format for it. What the file format contained was a line for each block. The first number on each line was the lower-left corner coordinate. The second number was the upper right-corner coordinate. I did this so that I could have variable size blocks.

At the beginning of the file I had the textures to load. Each sucessive texture was assigned a number. So the first texture listed would get a 0, the second would get a 1 and so on. So, on my line with the block coordinates for a given block the third entry was the texture number.

The next number was how many hits it takes to break a block. Some blocks would take more hits than others.

Then the last number was a powerup. I had 8 powerups, so the number would be from 0-8, 0 meaning no powerup, and any other number meaning that if this block is hit to drop whatever powerup. So a single line might look like this:

0.15 0.15 5.3 5.3 0 3 2
which would mean the lower-left corner is at the coordinate (0.15, 0.15) the upper-right corner is at (5.3, 5.3), it uses the first texture in the list, it takes 3 hits to destroy and holds the second powerup.

From this, I created a block editor. I could just place blocks on there, drag textures and powerups to whatever block, and then save the file. That's how I made the different levels. Hope this helps.

Share this post


Link to post
Share on other sites
Thx, How did you create the editor? I could create a simple one but, not onw like that. And dont you still need instances in the program when you load in the blocks?

Share this post


Link to post
Share on other sites
Quote:
Original post by zergdeath1
Thx, How did you create the editor? I could create a simple one but, not onw like that. And dont you still need instances in the program when you load in the blocks?


I used a programming language called tcl/tk for the editor. It was just a personal thing so it didn't have to be really professional. Windows programming with tcl/tk is simple and fast and the editor was no problem.

I didn't use instances. The file just loaded the geometry and texture information and I just saved it in an stl::vector and then removed blocks from the vector that were hit as I went (or decremented the number of times you needed to hit them to break them).

Anyways, here is what I did with the editor. I had two basic areas of the window at the beginning. One displayed the board as a grid, and the other had the texutres I wanted loaded. I would click on a block on the grid and add a block. I would then drag a texture of my choosing to the block. When you clicked on the block after this a drop down list and a text box would appear. The drop down list had values of 0-8 for the powerups (0 was default so if you didn't change it you got no powerup) nad the textbox was for how many hits the block takes to break. 1 was default so if you didn't do this for the block it would be 1. As I did this I added the data to an array. When I was done and clicked save it would write this arraylist into a file in the manner I wanted.

Share this post


Link to post
Share on other sites
Quote:
Original post by zergdeath1
I want to make breakout as my next project. But of course I have a few snags:

1. I do not know how I would create multiple blocks? I could create "personal" instances of the object with their own unique name, That the program call specifically, but that would be long, dirty, and basically useless. So I know I need to create an array like thing to store each instance of the class, But I dont know how.



class Block
{
// Stuff
};

// main.cpp
Block blocks[50];

// then do stuff like...
for (int i=0, i <= 49, ++i)
{
blocks.Draw();
}

Share this post


Link to post
Share on other sites
Quote:
Original post by zergdeath1
Thx both of you. I feel stupid not knowing I could create multiple blocks that way.


It's something that comes with practice. Just remember, when you define a class you are essentially creating your own type. Just like the built in types (int, char, float,...) you can create an array of them :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Rhaal
Quote:
Original post by zergdeath1
I want to make breakout as my next project. But of course I have a few snags:

1. I do not know how I would create multiple blocks? I could create "personal" instances of the object with their own unique name, That the program call specifically, but that would be long, dirty, and basically useless. So I know I need to create an array like thing to store each instance of the class, But I dont know how.



class Block
{
// Stuff
};

// main.cpp
Block blocks[50];

// then do stuff like...
for (int i=0, i <= 49, ++i)
{
blocks.Draw();
}


I did close to the same thing. I used a vector<Block> Blocks; It just seemed alot simpler to handle with a vector than an array.

Share this post


Link to post
Share on other sites
I made a breakout clone as well. I used something similar to what Rhaal suggested and I think its probably the best way to go. Like others have said, don't worry about the fact that you couldn't express what you wanted to do in the language yet as it is something I think everyone goes through. Maybe you need to spend a bit more time studying and writing programs in the language you are using.

I think it would be best if you tackled the your first problem before even thinking about a level editor and how to save each level.

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!