From 18e1890590633c2b8b39fb50005f17d1cae7c8dd Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sat, 4 Aug 2012 14:34:43 +0100 Subject: [PATCH] Stickman keys working, fixes first half of issue #50 --- src/game/GameController.cpp | 74 ++++++++++++++++++++++++++++++++++++- src/interface/Keys.h | 5 +++ 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index e39b47b2b..350bc25c9 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() diff --git a/src/interface/Keys.h b/src/interface/Keys.h index a06b4d791..685f24059 100644 --- a/src/interface/Keys.h +++ b/src/interface/Keys.h @@ -22,6 +22,11 @@ #define KEY_MOD_ALT KMOD_ALT #define KEY_MOD_SHIFT KMOD_SHIFT +#define KEY_a SDLK_a +#define KEY_d SDLK_d +#define KEY_s SDLK_s +#define KEY_w SDLK_w + #define BUTTON_LEFT SDL_BUTTON_LEFT #define BUTTON_MIDDLE SDL_BUTTON_MIDDLE #define BUTTON_RIGHT SDL_BUTTON_RIGHT