Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Writing an Asteroid Clone

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

ok i finally got the basics down and can get ddraw running smoothly in just a short time, and can do al sorts of wonderful things with bitmaps (load them, display em, and scale . NOW im going to write an asteroids clone as my first project, and im having a few troubles. My questions are as followed: 1) How do i keep track of the asteroids? i thought of using an array, but if the player moves up a level, there should be 1 more asteroid...not sure how i could put that in the array...or should i make a finite number of levels, and declare a big array at the start? 2) Collision Detecton. In a small game like this, should i use bounding boxes, pixel-per-pixel collison, etc. im not too sure... 3) How would i handle it when a player shoots an asteroid and breaks it? I know im supposed to wipe it off the screen and put 3 smaller ones which are faster, but im a little stumped on this. Im using c/c++ and direct draw, and the graphics are all bitmaps. (all 3 of em( asteroid bullet ship)) If ANYONE can provide advice on how to proceed, answer my questions, etc. i would really appreciate it. Im trying to write it to compare it to something thats in LaMothe''s book Tricks of the Windows Game Programming Gurus, which im going to buy early January. Thanks!

Share this post

Link to post
Share on other sites
I can help u out here.

1.)Linked lists is what i used. I know there''s a tut out there. I wish i could show you some code but i lost the source. :-( They allow you to add info right in the middle and everything. Arrays could be fine but they are a little xtra work when it comes to adding a new but of info

2.)If you don''t already, buy lamothe''s book tricks of the windows. It covers much more than the howtos. There''s many algorithms inside. I wish I new more stuff offhand but there''s a function to tell whether two lines connect. What i did is calculate the distance from the center of the asteroid to the center of the ship for each asteroid and if its within a certain distance, check each line of the poly if they intersect. If you are using bitmaps, do the same thing and pretend that there are lines instead of bitmaps. What i mean is do the calculations using the lines but draw them with bitmaps.

3.)Okay, i didn''t break them up. I just killed the asteroid. Everytime the player shoots, create a new bullet using the new keyword and then just test every frame if the point of the bullet crosses the lines of the asteroids. then you delete that asteroid from the linked list and walah, it never gets drawn again.

Just store all the the values of the asteroids in lines as if you were to draw them with only lines. This creates relistic effects and not just bounding box testing because that is unaccurate.

Share this post

Link to post
Share on other sites
For number 1, if you want to get technical:

Create two pointers:

[datatype] *MainAsteroidArray;
[datatype] *TempAsteroidArray;

Then, a variable that holds the number of asteroids you have:

datatype NumberOfAsteroids;

Now, when you start your game loop, on the first level, let''s say there are three asteroids:

NumberOfAsteroids = 3;

MainAsteroidArray = ([datatype])calloc(NumberOfAsteroids, sizeof([datatype])

Using calloc is very useful. Like malloc, it allocates memory, but calloc ill allocate you an array, with NumberOfAsteroids elements.

When you want to move to the next level, add one onto the number of asteroids, then move everything from the MainAsteroidArray to the TempAsteroidArray, to prevent it being deleted, make Main bigger with calloc, and move everything back...slightly complex, but extremely reliable, and infinitely expandable. You can have as many asteroids as you want. Look up calloc in a C book, or on the net.

Oh, and by the way, LaMothe''s book Secrets Of Windows Game Programming Gurus is brilliant, I have it, and I highly recommend it...

Share this post

Link to post
Share on other sites
linked list''s are pretty simple .. and would probably be better than arrays in this case.

Like kmsixpence suggested, when an asteroid is destroyed you just delete it from the linked list. If you shoot a large asteroid and it needs to turn into 3 smaller asteroids, then you delete the large one from the list, and add 3 small ones to the list with appropriate positions/headings/speed/etc. Then in your main rendering/rasterizing loop you just loop through the list drawing each item.

If you want some more info on linked lists, let me know.


Share this post

Link to post
Share on other sites

  • 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!