Sign in to follow this  
timmyk

how to shoot??

Recommended Posts

timmyk    158
hi,i am new to this site and i recently posted this same topic in the game design forum but one of the guys said it would be more useful if i posted it here as people from this post could help!!! i am currently creating a capture the flag style game on eclipse. its a 4 player game. everthing is going good except for the shooting. i want to be able to have the players on my game just shooting bullets if say, Ctrl is pressed. can someone please post something in how to shoot, create bullets, the keylistener and how to get the bullets to come out of the player. thanks in advance!!!!! p.s some basic stuff could really help

Share this post


Link to post
Share on other sites
Rob Loach    1504
You're going to have to implement a timer to control the reload rate, or else your player is going to be able to shoot at any rate they want. Have a variable check the current time to the reload time and the last shot time, then you'll be good to go.

Share this post


Link to post
Share on other sites
sirGustav    588
Since you are talking about eclipse and keylisteners I assume you are coding in Java, right? Responding to key presses are a simple key-listener and there are great examples on them in "The Java tutorial" at suns page.
Rendering stuff(bullets) is also covered in the tutorials.

About the shooting part, I wouldprobably do it something like this:

A bullet class that contains the position, direction and possible damage and velocity too.

A bullet manager class that manages all the bullets, updates and draws them etc.

The key listener would call specific functions in the player to make it use the selected weapons.

From there on it is up to the player/weapon to decide when to shoot. A shotgun would spawn 3 bullets in a widespread manner and only react to keydown messages. A smg would spawn 1 bullet each 0.20 seconds while the key is down.

edit: beaten

Share this post


Link to post
Share on other sites
timmyk    158
thats right, i am doing it on eclipse, but the thing is that i am a newbie to game programming and so it is hard for me to understand what your trying to say, sorry, so would it be possible if i posted what i have of my coding and then you would be able to point/show me where what goes and help me figure it out???
Sorry!!! i am still in yr 12 at momement and been doing it for 1 year so everthing is kinda fuzzy, like i got most of the basics but this shooting part is killing me!!!!
thanks in advance

Share this post


Link to post
Share on other sites
Ravuya    135
First question: Do you know how to implement a timer in your game code?
Second question: Do you know how to create additional classes (or objects) and have them work?

Share this post


Link to post
Share on other sites
timmyk    158
i got no idea about the timers, but hav a pretty good idea about the classes. i have a gamescreen with images on them and i want to be able to get those images to be able to shoot once ctrl(or any key is pressed).

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