Sign in to follow this  

blitz3d keydown speed

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

hello i'm new to this forum and i am wondering if anyone could help me with a game me and my friend are working on. it's a frist person shooter. we've gotten really far but there is one problem i just can't seem to solve. i want to use automatic weapons and to do that i need to use the MouseDown function but then if i hold down the mouse it just shoots sooooooo fast it's unrealistic. plus i wanna control firerate for guns. can any pliz tell me how to control mousedown speed it would be sooooo awsome if you could

Share this post


Link to post
Share on other sites
Quote:
Original post by VZdemon
hello i'm new to this forum and i am wondering if anyone could help me with a game me and my friend are working on. it's a frist person shooter. we've gotten really far but there is one problem i just can't seem to solve. i want to use automatic weapons and to do that i need to use the MouseDown function but then if i hold down the mouse it just shoots sooooooo fast it's unrealistic. plus i wanna control firerate for guns. can any pliz tell me how to control mousedown speed it would be sooooo awsome if you could


don't use the MouseDown function to fire, use the MouseDown function to set a flag instead (and MouseUp to remove/unset it), the actual firing can then easily be handled in the main gameloop or your players update function, use a timer to control the firerate.

I'm not familiar with blitz3d though so i can't provide any exact code, but something like:

(pseudocode)


bool mousebuttonstatus[3] = {false,false,false};

handleEvents() {
Event e = getEvent();
if (e.type == Event.MOUSEBUTTONDOWN) {
mousebuttonstatus[e.buttonid] = true;
} elseif (e.type == Event.MOUSEBUTTONUP)
mousebuttonstatus[e.buttonid] = false;
}
}

Player::Update(float dt) {
if (mousebuttonstatus[0]==false) { //This shouldn't really be hardcoded
fireRateAccumulator=0;
}
else {
fireRateAccumulator+=dt;
if (fireRateAccumulator>=currentWeapon.fireRate) {
currentWeapon.Fire();
fireRateAccumulator-=currentWeapon.fireRate;
}
}
}

main() {
...
dt=getTimeSinceLastFrame();
handleEvents();

for each a in actors do {
a.Update(dt);
}
}




In a real game you'd want a structure to map keys and events together, so that rather than checking if a specific mousebutton is pressed you check if the firebutton is pressed (which could then be anything)

[Edited by - SimonForsman on December 3, 2010 5:28:18 AM]

Share this post


Link to post
Share on other sites

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