Re: just about had it with joystick implementation errors

There are many ways to prevent the rapid-fire problem. One way is to keep track of two things in every frame: what keys were pressed in that frame, and what keys weren't pressed in that frame.

Specific keys would be mapped to generic actions (GameActions.fireWeapon.) Also keep track of how much time should elapse between "fires" of this weapon (preferrably by measuring it as a function of your frame rate.) Then, when the code to execute actions is executed, depending on what weapon is selected, you can calculate delta(t1, t2) where t1 and t2 note the current time and the last execution time of the action, respectively. If this delta exceeds your fire rate, fire the weapon.

I've written some pseudo code here.

For every frame {
  Note down which keys are pressed
  Note down which keys are not pressed
  Based on what keys are pressed, queue some actions.
  for every action {
    if the action is a fire action, then {
      let delta = currentTime - lastTimeWeExecutedThisAction
      if delta is greater than or equal to the fire rate, fire the weapon and let lastTimeWeExecutedThisAction = currentTime, otherwise do nothing
    }
  }
}

One other thing you will have to do is if the fire action is not executed in a frame, execute it in the next frame if the fire action registers in that frame. This way, if they're holding down the fire button, then let go, then press it again, the weapon will fire.

if the fire action is not registered in this frame {
  let lastTimeWeExecutedThisAction = 0
}

This way, the next time you end up calculating delta, you'll get currentTime - 0 which will execute your fire action.

One other tip I have for you is to separate out your input loop from your frame code. Otherwise, if your frame rate is something like 100 milliseconds, you'll get a problem when sometimes the buttons you press won't register. To get around this in TDV, I had my input loop running on a separate thread, and I queued actions to be consumed by the next frame. The input loop was running sufficiently fast, maybe double the speed of the frame rate, so the user input became smooth. I'm not sure if you can multithread in BGT, but it's worth a look.

jack wrote:

**update:** After some hard deliberation we are not revamping the enemy system. What we were trying to do turned out to be a much larger endeavor than Garrett had thought, I"m the one who came to that conclusion anyway. So, the enemy system is staying as is. IN other news, we have full joystick support, and the only bug we have is that now the spacebar repeat fires the sword and gun, like every weapon is a machinegun. Lol.

-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : jack via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Munawar via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : kianoosh via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : jack via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : jack via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : jack via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : shotgunshell via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : jack via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : jack via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Munawar via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : kianoosh via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : ironcross32 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : shotgunshell via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Munawar via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : jack via Audiogames-reflector

Reply via email to