Sign in to follow this  

2D Shooter: Firing Control

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

So lately I've been working on a 2D tank shooter game. I've gotten a tile map fully implemented, including restricting collision detection to only a tank's current tile and its eight neighboring tiles. Additionally, each tank has a pointer to a "control function", which allows it to be controlled either from human input or "AI" algorithms. Right now I'm somewhat concerned about firing control. This is more of a code-organizational problem than anything else. What I mean is, in the even that a tank is ready to fire (however that's defined in the code), the firing should not happen until after its position has been updated and passed through collision detection. That way, the position of the projectile will be "correct" with respect to the tank's position. However, if I want to keep a single control-function pointer for each tank, that would mean putting the collision detection inside the functions that can be used as control functions. I suppose this wouldn't be so bad if I put the collision detection inside its own function, which is called from each control function. But I don't expect the collision detection to change between human- and computer-controlled tanks. "Semantically speaking", then, it would seem that the collision-detection function doesn't belong in the control code. The alternative, though, would seem to be having two separate control functions, one for movement and the other for firing. What are your thoughts on this, fellow game developers? Is there anything that I'm missing with the above? Am I making a mountain out of a molehill? Thanks in advance for your input! [Edited by - RobAU78 on March 9, 2010 2:30:12 PM]

Share this post


Link to post
Share on other sites
Could you give the control functions access to a move function that does the work of moving, and doesn't return until collision detection for that move has been processed? Then the controller could fire without worrying about position, because it's already taken care of. You could also have the controller explicitly update_collisions, which, while ugly, is not too bad. Just a single function call.

Unless you mean game-wide collision detection, in which case you might just have to have a two-phase update, or two controller functions.

Alternatively, if controllers can have state outside the function, they could signal passively that they want to fire. The game would call their movement function, update collisions, then fire the tank on its own if the controller wants to.

Share this post


Link to post
Share on other sites

This topic is 2840 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.

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