aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2016-06-28 21:32:04 -0400
committerClyne Sullivan <tullivan99@gmail.com>2016-06-28 21:32:04 -0400
commita466eb8fd6e5707aaa1bfafa28535b82c67d69d8 (patch)
treece3a09b7b98584b3d42351eae7fd7e183e38b7f8 /src/ui.cpp
parent00f633afb62ed6914205639b44dcdaf839a2c2f7 (diff)
chests?, custom controls
Diffstat (limited to 'src/ui.cpp')
-rw-r--r--src/ui.cpp101
1 files changed, 53 insertions, 48 deletions
diff --git a/src/ui.cpp b/src/ui.cpp
index 037ba89..d7f6e19 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -28,6 +28,16 @@ extern std::vector<NPC *> aipreload;
*/
extern bool gameRunning;
+
+static SDL_Keycode controlMap[] = {
+ SDLK_w, SDLK_s, SDLK_a, SDLK_d
+};
+
+void setControl(unsigned int index, SDL_Keycode key)
+{
+ controlMap[index] = key;
+}
+
/**
* Freetype variables
*/
@@ -1402,46 +1412,7 @@ EXIT:
// only let other keys be handled if dialog allows it
} else if (!dialogBoxExists || dialogPassive) {
- switch(SDL_KEY) {
- case SDLK_DELETE:
- gameRunning = false;
- break;
- case SDLK_t:
- game::time::tick(50);
- break;
- case SDLK_a:
- if (fadeEnable)
- break;
- player->vel.x = -PLAYER_SPEED_CONSTANT;
- if (std::stoi(game::getValue("Slow")) == 1)
- player->vel.x /= 2.0f;
- player->left = left = true;
- player->right = right = false;
- if (currentWorldToLeft) {
- std::thread([&](void){
- auto thing = currentWorld->goWorldLeft(player);
- if (thing.first != currentWorld)
- worldSwitch(thing);
- }).detach();
- }
- break;
- case SDLK_d:
- if (fadeEnable)
- break;
- player->vel.x = PLAYER_SPEED_CONSTANT;
- if (std::stoi(game::getValue("Slow")) == 1)
- player->vel.x /= 2.0f;
- player->right = right = true;
- player->left = left = false;
- if (currentWorldToRight) {
- std::thread([&](void){
- auto thing = currentWorld->goWorldRight(player);
- if (thing.first != currentWorld)
- worldSwitch(thing);
- }).detach();
- }
- break;
- case SDLK_w:
+ if (SDL_KEY == controlMap[0]) {
if (inBattle) {
std::thread([&](void){
auto thing = dynamic_cast<Arena *>(currentWorld)->exitArena(player);
@@ -1455,6 +1426,43 @@ EXIT:
worldSwitch(thing);
}).detach();
}
+ } else if (SDL_KEY == controlMap[1]) {
+ } else if (SDL_KEY == controlMap[2]) {
+ if (!fadeEnable) {
+ player->vel.x = -PLAYER_SPEED_CONSTANT;
+ if (std::stoi(game::getValue("Slow")) == 1)
+ player->vel.x /= 2.0f;
+ player->left = left = true;
+ player->right = right = false;
+ if (currentWorldToLeft) {
+ std::thread([&](void){
+ auto thing = currentWorld->goWorldLeft(player);
+ if (thing.first != currentWorld)
+ worldSwitch(thing);
+ }).detach();
+ }
+ }
+ } else if (SDL_KEY == controlMap[3]) {
+ if (!fadeEnable) {
+ player->vel.x = PLAYER_SPEED_CONSTANT;
+ if (std::stoi(game::getValue("Slow")) == 1)
+ player->vel.x /= 2.0f;
+ player->right = right = true;
+ player->left = left = false;
+ if (currentWorldToRight) {
+ std::thread([&](void){
+ auto thing = currentWorld->goWorldRight(player);
+ if (thing.first != currentWorld)
+ worldSwitch(thing);
+ }).detach();
+ }
+ }
+ } else switch(SDL_KEY) {
+ case SDLK_DELETE:
+ gameRunning = false;
+ break;
+ case SDLK_t:
+ game::time::tick(50);
break;
case SDLK_LSHIFT:
if (game::canSprint) {
@@ -1501,8 +1509,11 @@ EXIT:
ui::menu::toggle();
player->save();
return;
- }
- switch (SDL_KEY) {
+ } else if (SDL_KEY == controlMap[2]) {
+ left = false;
+ } else if (SDL_KEY == controlMap[3]) {
+ right = false;
+ } else switch (SDL_KEY) {
case SDLK_F3:
debug ^= true;
break;
@@ -1526,12 +1537,6 @@ EXIT:
player->ground = false;
}
break;
- case SDLK_a:
- left = false;
- break;
- case SDLK_d:
- right = false;
- break;
case SDLK_LSHIFT:
if (player->speed == 4)
Mix_FadeOutChannel(1,2000);