Skip to content
Browse files

Merge pull request #38 from marcusmoller/master

Fixed input when swapping scenery
  • Loading branch information...
2 parents e8ad0e2 + 9c7930a commit 3eaa886b1d921c2c18ee6602faf6d416a1852ca4 @Cheeseness committed Jan 31, 2013
Showing with 31 additions and 1 deletion.
  1. +30 −1 src/Game.cpp
  2. +1 −0 src/Game.h
View
31 src/Game.cpp
@@ -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();
}
View
1 src/Game.h
@@ -155,6 +155,7 @@ class Game
float digitalDrag;
int key[16];
+ bool keyrel(int k);
void update();
void draw();

0 comments on commit 3eaa886

Please sign in to comment.
Something went wrong with that request. Please try again.