blitz3d keydown speed

Started by
0 comments, last by SimonForsman 13 years, 4 months ago
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
Advertisement
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]
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

This topic is closed to new replies.

Advertisement