Jump to content
  • Advertisement
Sign in to follow this  
Shmuel

Side-scrollers

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

In most side scrollers, the player has a projectile weapon. How do most games implement this? With a class? I'm not sure how to implement it.

Share this post


Link to post
Share on other sites
Advertisement
I allocate an array of structs called "bullet."

Then I have a function that calculates the new position of each bullet, a function that calculates if it hits someone/something (and does something about it if it does), and a function that renders bullets, all depending on whether or not the bullet is 'active.'

Share this post


Link to post
Share on other sites
A common method is to employ a linked-list - basically a dynamic way to store objects where the number of instances will change at runtime. Google it or search on Gamedev.net. There is also the Standard Template Library (STL – C++ ) which provides a stable set of templated classes to handle dynamic containers (such as a list) – very easy to use and understand.

Good luck,
Jackson Allan

Share this post


Link to post
Share on other sites
Remember that bullets usually move very fast (unless you deliberately make some slowed down effect). On slow computers (slow = low FPS in this case), a standard point in box collision would not always manage to see a collision. This is because if a projectile moves 20 pixels in one single fram any object in between will be missed if it is small enough.

Rather, the collision detection you *ought* to do for projectiles would be to make a line interesection test, and treat the distance passed in that particular frame as the vector. This can be quite easy if the movement of the bullet's movement also is parallel to either the vertical or horizontal axes.

Share this post


Link to post
Share on other sites
I implement a class hierarchy as such:


CTarget
+CThing
+CWeapon
+CProjectile
+CCharacter


That's a very simplified version of the hierarchy but the point is a character would contain a pointer to a weapon that contains a pointer to a projectile. When the character fires, the weapon invokes a member function that informs the engine that a new projectile of a given type needs to be spawned.

And then everything just has it's own virtual functions for performing updates and whatnot. Projectiles of different types (hitscan vs slow moving, big vs point-sized, etc.) just need to be defined as a new class and some stuff implemented.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!