Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed input when swapping scenery #38

Merged
merged 1 commit into from

2 participants

Marcus Møller Cheese
Marcus Møller

Without this fix, the swapScenery() event would be called for each key repeat. This would make the game swap scenery every millisecond or so as long as you held the KEY_SWAP_SCENERY down.

This new method makes sure that it's only called, when the key KEY_SWAP_SCENERY has been released as well.

Cheese Cheeseness merged commit 3eaa886 into from
Cheese
Owner

And so dies epilepsy mode :(

I'm going to merge this, but I think we should keep an eye out for behaviour when multiple keys are pressed.

Marcus Møller

That shouldn't be a concern AFAIK. It basically calls the same function, al_key_down(), so it's nothing new compared to the old method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 31, 2013
  1. Marcus Møller
This page is out of date. Refresh to see the latest.
Showing with 31 additions and 1 deletion.
  1. +30 −1 src/Game.cpp
  2. +1 −0  src/Game.h
31 src/Game.cpp
View
@@ -286,6 +286,35 @@ int Game::initialize() {
return 1;
}
+bool Game::keyrel(int k)
+{
+ /*
+ Checks if a key has been pressed AND released. This means key repeats doesn't affect the input
+ */
+
+ static bool initialized = false;
+ static bool keyp[ALLEGRO_KEY_MAX];
+
+ if (!initialized)
+ {
+ for (int i=0; i<ALLEGRO_KEY_MAX; i++) keyp[i] = false;
+ initialized = 1;
+ }
+
+ if (al_key_down(keyboard_state, key[k]) && !keyp[k])
+ {
+ keyp[k] = 1;
+ return 0;
+ }
+ else if (!al_key_down(keyboard_state, key[k]) && keyp[k])
+ {
+ keyp[k] = 0;
+ return 1;
+ }
+
+ return 0;
+}
+
void Game::update() {
if (!splash && end)
@@ -363,7 +392,7 @@ void Game::update() {
if(al_key_down(keyboard_state, key[KEY_WEAPON3])) {
player->switchWeapon(2);
}
- if(al_key_down(keyboard_state, key[KEY_SWAP_SCENERY])) {
+ if (keyrel(KEY_SWAP_SCENERY)){
floor->swapScenery();
}
1  src/Game.h
View
@@ -155,6 +155,7 @@ class Game
float digitalDrag;
int key[16];
+ bool keyrel(int k);
void update();
void draw();
Something went wrong with that request. Please try again.