Sign in to follow this  
LMRFUD

Shooting and the Shot Class Help

Recommended Posts

Hi I’m trying to wrap my head around a shooting routine for something like a 2d space shooter. What I basically want is a massive shooting routine with many shots and power ups. What I was going to start with was what I know and that’s C, have it control storing of the X and Y with velocity from a structure. Have the shots move from an array and have a Boolean operator if the shot was alive or dead (if it hot something or went off screen). Then with the help of some C++ programmers was told that a use of a shot or weapon class would be better and easier in the long run. What my question is: If I have power ups with change of weapons and unlimited shooting how do I change the shot. The shot class will still be the same, shooting and rate and speed will not change but the pointer to the data will. How do I do that within a class, I don’t need the code just the technique or the thought process. Please and thanks Fud

Share this post


Link to post
Share on other sites
There's probably a fairly straightforward answer to your question. But first, what exactly do you mean by 'change the shot'? You said the shot class will stay the same but the pointer to the data will change - I didn't quite follow that.

Share this post


Link to post
Share on other sites
Well the data will change, each shot looks different and only the pointer to the data will change.

So for instance if you get a power up your shot will change to a laser from a regular shot. I know I'm not making too much sense but is there a way to put that in a class.

I've just finished it in C but it needs work, I would really like to OO.

Fud

Share this post


Link to post
Share on other sites
Well, I'm not sure what to tell you, without understanding your situation any better. But I think if you can develop a basic understanding of classes and object-oriented design, it'll become clear to you what you need to to.

In short, a class generally encapsulates data (member variables) and behavior (member functions). The ideal is that the interface is as small as possible (i.e. no public data and few public functions). With a projectile class, you'll probably need public interface functions to set the initial position and velocity at least, and then perhaps Update() and Render() functions.

For the different projectile types, you could make it data-driven, or use inheritance.

In the data-driven model, different projectiles are only differentiated by their member data. So a bullet would be the same class as a missile, but would have different model, damage, and speed characteristics.

Using inheritance, you would have a base projectile class, and derive other classes from that class, each with different properties.

The approach I think is best is to be data-driven until you have to use inheritance (i.e. to implement special behavior that doesn't fit in the base class). This way you can keep your definitions (damage, speed, etc.) in text files for easy tweaking and editing. It may not be so important in a small game, but in a more complicated game with lots of projectiles and weapons, you want to be able to tweak easily, and you don't want to be hard-coding stuff.

Hope that was of some help to you.

Share this post


Link to post
Share on other sites
Quote:
Original post by LMRFUD
Then with the help of some C++ programmers was told that a use of a shot or weapon class would be better and easier in the long run.


dont listen too 'em - just because lots of people use something, doesnt mean its right (OO progin')

Share this post


Link to post
Share on other sites
Actually I've made it shoot well using a FSM model, it still needs work but I'm happy with it. It's all abount timing now and I need to really see the big picture.

The truth is I am still understanding CLASSES and even though I want to use them at some point right now I'm just having fun making a space shooter.

The information you provided was excellent!

Thanks
Fud

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this