Sign in to follow this  
fuerchter

Shooting multiple projectiles (sloppy code? :S)

Recommended Posts

Hey there
I have my project's solution attached. I'm still kind of a newbie with XNA and I thought just to test what I can do I'd try programming something like e.g. a dual stick shooter. What I've done until now is write it so you can move the ship (circle) with the left stick and the crosshair with the right stick and shoot a projectile with the right shoulder button.

My problem at this stage is that the projectile class i have owns a crosshair object which in turn owns a ship object and I execute all my major stuff (like moving the ship, the crosshair or shooting) from this projectile class. This way of organizing my project seems to have made it impossible for me to create a second projectile which can be triggered (instead of the one I have now which just resets as soon as I hit the left shoulder button again).

Is there any way to solve this problem or can anyone help me structure my project a bit better (making it more readable/maintainable). I don't know what I did wrong, should I have made some kind of design (like UML diagram or something) before I have gone to work on writing the program?
greetings

Share this post


Link to post
Share on other sites
Your projectile class should not own a crosshair object, which in turn should not own a ship object. Your projectile class is steering your ship at the moment, that is a big red flag. Think of your classes as actual objects, what does a ship do? It steers, fires of projectiles etc. If you think of your classes this way, deciding what goes where becomes easier.

Setting aside how you would retrieve and pass on data, how would you structure your objects now?

Share this post


Link to post
Share on other sites
So basically according to that logic the ship should own both the crosshair and the projectile?

//EDIT:
I've tried restructure it with this idea in mind. The new version is in the attachments

Share this post


Link to post
Share on other sites
Not necessarily, but that would already be a better design. If the crosshair is used for more than shooting projectiles in that direction(e.g. hover over for details), I'd consider passing it as an argument when calling ship.shoot() or store a reference to it. If ships don't actually carry ammunition(i.e. unlimited ammo), you might consider using a pool of projectiles that is shared between ships. Edited by Mussi

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