diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-08-04 13:34:43 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-08-04 13:34:43 (GMT) |
| commit | 18e1890590633c2b8b39fb50005f17d1cae7c8dd (patch) | |
| tree | 665a098053a90c2f66634e3ad98be06a60e34c9f /src/game/GameController.cpp | |
| parent | ae5d099b8175e9618bf5773d04e7876b90606b1b (diff) | |
| download | powder-18e1890590633c2b8b39fb50005f17d1cae7c8dd.zip powder-18e1890590633c2b8b39fb50005f17d1cae7c8dd.tar.gz | |
Stickman keys working, fixes first half of issue #50
Diffstat (limited to 'src/game/GameController.cpp')
| -rw-r--r-- | src/game/GameController.cpp | 74 |
1 files changed, 72 insertions, 2 deletions
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index e39b47b..350bc25 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -386,12 +386,82 @@ bool GameController::MouseWheel(int x, int y, int d) bool GameController::KeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) { - return commandInterface->OnKeyPress(key, character, shift, ctrl, alt); + bool ret = commandInterface->OnKeyPress(key, character, shift, ctrl, alt); + if(ret) + { + Simulation * sim = gameModel->GetSimulation(); + if (key == KEY_RIGHT) + { + sim->player.comm = (int)(sim->player.comm)|0x02; //Go right command + } + if (key == KEY_LEFT) + { + sim->player.comm = (int)(sim->player.comm)|0x01; //Go left command + } + if (key == KEY_DOWN && ((int)(sim->player.comm)&0x08)!=0x08) + { + sim->player.comm = (int)(sim->player.comm)|0x08; //Use element command + } + if (key == KEY_UP && ((int)(sim->player.comm)&0x04)!=0x04) + { + sim->player.comm = (int)(sim->player.comm)|0x04; //Jump command + } + + if (key == KEY_d) + { + sim->player2.comm = (int)(sim->player2.comm)|0x02; //Go right command + } + if (key == KEY_a) + { + sim->player2.comm = (int)(sim->player2.comm)|0x01; //Go left command + } + if (key == KEY_s && ((int)(sim->player2.comm)&0x08)!=0x08) + { + sim->player2.comm = (int)(sim->player2.comm)|0x08; //Use element command + } + if (key == KEY_w && ((int)(sim->player2.comm)&0x04)!=0x04) + { + sim->player2.comm = (int)(sim->player2.comm)|0x04; //Jump command + } + } + return ret; } bool GameController::KeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) { - return commandInterface->OnKeyRelease(key, character, shift, ctrl, alt); + bool ret = commandInterface->OnKeyRelease(key, character, shift, ctrl, alt); + if(ret) + { + Simulation * sim = gameModel->GetSimulation(); + if (key == SDLK_RIGHT || key == SDLK_LEFT) + { + sim->player.pcomm = sim->player.comm; //Saving last movement + sim->player.comm = (int)(sim->player.comm)&12; //Stop command + } + if (key == SDLK_UP) + { + sim->player.comm = (int)(sim->player.comm)&11; + } + if (key == SDLK_DOWN) + { + sim->player.comm = (int)(sim->player.comm)&7; + } + + if (key == SDLK_d || key == SDLK_a) + { + sim->player2.pcomm = sim->player2.comm; //Saving last movement + sim->player2.comm = (int)(sim->player2.comm)&12; //Stop command + } + if (key == SDLK_w) + { + sim->player2.comm = (int)(sim->player2.comm)&11; + } + if (key == SDLK_s) + { + sim->player2.comm = (int)(sim->player2.comm)&7; + } + } + return ret; } void GameController::Tick() |
