bullets, lasers, rockets

Started by
12 comments, last by GameDev.net 24 years, 7 months ago
OK thanks for the help then. I believe that I shall stay with the array, simply because it is working great at this time and I also do not expect to ever exceed 100 weapons on screen at the time. Oh, and sorry about the double posts. They were made from my school, which is running crappy hardware, and I kinda clicked "post" twice
Advertisement
Hi

Email me and I'll give you my routine for bullets and other on-screen items(minus the main game sprites)

Indy

Hello there...

I am currently writing a top down-ish shooter in C++. I've got most of the graphics routines done, but I am wondering how to implement a shooting routine.

Some thoughts were:

1. When the user presses [shoot], a new bullet structure is created and inserted into an array, bullets[number of bullets]. Then during the rest of the loop, this array is calculated and bullets are moved, etc.

The problem is that when bullets "die" (hit a wall, go off the screen), how do I remove them from the array, and create a "free space" to put the next bullet in?

And how would you cope with Unlimited Bullets - i.e. being able to shoot as quickly and as much as you want - NOT just having 8 shots on the screen, and you have to wait for these shots to "die" before you can shoot again.

This is the only practical method I can think of, if you have any suggestions, please help me out here!

Another solution is a combination of the linked list and arrays...a linked list of arrays.

Have the array structure so that it contains the "normal" number of bullets you expect to exist at one time. If you exceed that number, you create a new array of bullets and link it to the existing one.

You could then add a "count" to the array so that you know if the array is full or empty. Empty arrays could be deallocated or just left so that you don't have to worry about allocating them again.

Say you estimate that you will need 25 bullets on average. Then you create a structure that includes a counter and space for 25 bullets as well as a "next" pointer. Scanning 25 slots is seldom going to be slow, so hunting an empty or "dead" slot isn't really a problem. You know if the structure is full, if it is you skip to the next batch of bullets, allocating it if necessary.

My take on the setup.

------------------
DavidRM
Samu Games

This topic is closed to new replies.

Advertisement