Jump to content
  • Advertisement
Sign in to follow this  
Rahl

Need help with my basic breakout clone please(XNA)

This topic is 3981 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

Here's the code: http://rafb.net/p/oQsz9d62.html http://rafb.net/p/ec0PXO17.html I use that partial class just to make things a little cleaner and not have everything in the main file. It's probably a bad way to go about it, but I am a beginner! lol. Anyways, I'm trying to make it to where each block is set to a random color, but I can't figure out how to do it. The way I have it now makes it to where the colors change every frame, and I know it's doing that because the random is set every time draw is called, but I can't figure out another way to do it :( Any help would be really appreciated...it's probably really simple and I'm gonna kick myself for not being able to figure it out...

Share this post


Link to post
Share on other sites
Advertisement
You need to set the colors out side the draw function and then have them passed to the function. Setup or use an existing class to store the colors in.

Now if C# allows much the same practice as C++ this may be of some help.
1. create a class that will hold what color has been assigned to which block you may want to add this to the class that holds the information about what blocks are left and where they are positioned.
2. make sure you create the class in main so it doesn't go out of scope.
3. add a set color function to randomly assign the colors. you'll need to pass the class that will hold these by reference.
4. now you should have a variable holding all the colors of each block now all you need to do is access this class when in the draw function all the colors should remain constant until you call set color function again.

Share this post


Link to post
Share on other sites
wherever you are storing your block locations (i assume it's your block class after looking at your code for only about 2 seconds) when you initialize all your data set a colour value for each block then. each time you go to draw the array of blocks you just set the colour to whatever the block has stored for it's particular colour.

does that help?

Share this post


Link to post
Share on other sites
Hello,

I would actually try to design it in a different way. I would actually make a class called blocks that would contain all the update logic and stuff in there. Then I would actually make a enum of colors, and then in the constructor of the class blocks I would make it seed a random number that will fit the length of the enum of colors. For example, if there was 7 colors in the enum I would seed a random number between the choices of 1-7. Then in the constructor it will set the color based on the random number choice. Then in your main part you could just create an array of the blocks object. I hope this helps. If you need me to go more into detail about this then just pm me and I will write up a more detailed description.

~Carl J. Loucius

P.S. Object Orientated Programming can be your best friend if you start thinking of things as objects.

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!