aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2016-06-29 10:18:56 -0400
committerClyne Sullivan <tullivan99@gmail.com>2016-06-29 10:18:56 -0400
commitdf12451f837854c816bed32ae0d962fba9601959 (patch)
tree8f10b1ff814c83f2bc92c19e628e7dcef37ae63b
parenta466eb8fd6e5707aaa1bfafa28535b82c67d69d8 (diff)
control setting
-rw-r--r--include/ui_menu.hpp8
-rw-r--r--src/ui.cpp81
-rw-r--r--src/ui_menu.cpp31
-rw-r--r--xml/town.xml4
4 files changed, 60 insertions, 64 deletions
diff --git a/include/ui_menu.hpp b/include/ui_menu.hpp
index 3ed9fa5..8ca9368 100644
--- a/include/ui_menu.hpp
+++ b/include/ui_menu.hpp
@@ -13,13 +13,13 @@ class menuItem {
public:
int member;
Menu *child;
- union {
+ //union {
struct {
vec2 loc;
dim2 dim;
Color color;
- const char *text;
+ std::string text;
menuFunc func;
} button;
struct {
@@ -31,10 +31,10 @@ public:
float maxValue;
float sliderLoc;
- const char *text;
+ std::string text;
float *var;
} slider;
- };
+ //};
menuItem(){}
~menuItem(){
//button.text = NULL;
diff --git a/src/ui.cpp b/src/ui.cpp
index d7f6e19..f3523f6 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -30,7 +30,7 @@ extern bool gameRunning;
static SDL_Keycode controlMap[] = {
- SDLK_w, SDLK_s, SDLK_a, SDLK_d
+ SDLK_w, SDLK_s, SDLK_a, SDLK_d, SDLK_LSHIFT, SDLK_LCTRL, SDLK_e
};
void setControl(unsigned int index, SDL_Keycode key)
@@ -1426,7 +1426,6 @@ EXIT:
worldSwitch(thing);
}).detach();
}
- } else if (SDL_KEY == controlMap[1]) {
} else if (SDL_KEY == controlMap[2]) {
if (!fadeEnable) {
player->vel.x = -PLAYER_SPEED_CONSTANT;
@@ -1457,14 +1456,7 @@ EXIT:
}).detach();
}
}
- } else switch(SDL_KEY) {
- case SDLK_DELETE:
- gameRunning = false;
- break;
- case SDLK_t:
- game::time::tick(50);
- break;
- case SDLK_LSHIFT:
+ } else if (SDL_KEY == controlMap[4]) {
if (game::canSprint) {
if (debug) {
Mix_PlayChannel(1, sanic, -1);
@@ -1473,11 +1465,9 @@ EXIT:
player->speed = 2.0f;
}
}
- break;
- case SDLK_LCTRL:
+ } else if (SDL_KEY == controlMap[5]) {
player->speed = .5;
- break;
- case SDLK_e:
+ } else if (SDL_KEY == controlMap[6]) {
edown = true;
// start hover counter?
@@ -1493,7 +1483,12 @@ EXIT:
// enable action ui
action::enable();
}
-
+ } else switch(SDL_KEY) {
+ case SDLK_DELETE:
+ gameRunning = false;
+ break;
+ case SDLK_t:
+ game::time::tick(50);
break;
default:
break;
@@ -1513,6 +1508,31 @@ EXIT:
left = false;
} else if (SDL_KEY == controlMap[3]) {
right = false;
+ } else if (SDL_KEY == controlMap[4]) {
+ if (player->speed == 4)
+ Mix_FadeOutChannel(1, 2000);
+
+ player->speed = 1;
+ } else if (SDL_KEY == controlMap[5]) {
+ player->speed = 1;
+ } else if (SDL_KEY == controlMap[6]) {
+ edown = false;
+
+ if (player->inv->invHover) {
+ player->inv->invHover = false;
+ } else {
+ if (!player->inv->selected)
+ player->inv->invOpening ^= true;
+ else
+ player->inv->selected = false;
+
+ player->inv->mouseSel = false;
+ }
+
+ // disable action ui
+ action::disable();
+
+ heyOhLetsGo = 0;
} else switch (SDL_KEY) {
case SDLK_F3:
debug ^= true;
@@ -1537,31 +1557,6 @@ EXIT:
player->ground = false;
}
break;
- case SDLK_LSHIFT:
- if (player->speed == 4)
- Mix_FadeOutChannel(1,2000);
-
- // fall through
- case SDLK_LCTRL:
- player->speed = 1;
- break;
- case SDLK_e:
- edown=false;
- if (player->inv->invHover) {
- player->inv->invHover = false;
- } else {
- if (!player->inv->selected)
- player->inv->invOpening ^= true;
- else
- player->inv->selected = false;
- player->inv->mouseSel = false;
- }
-
- // disable action ui
- action::disable();
-
- heyOhLetsGo = 0;
- break;
case SDLK_l:
currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y}, 300.0f, {1.0f,1.0f,1.0f});
currentWorld->getLastLight()->follow(player);
@@ -1576,10 +1571,10 @@ EXIT:
else {
auto s = new Structures();
s->spawn(FIRE_PIT, player->loc.x, player->loc.y);
- currentWorld->addStructure(s);
- currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y}, 400.0f, {1.0f,1.0f,1.0f});
+ //currentWorld->addStructure(s);
+ //currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y}, 400.0f, {1.0f,1.0f,1.0f});
//currentWorld->getLastLight()->follow(currentWorld->build.back());
- currentWorld->getLastLight()->makeFlame();
+ //currentWorld->getLastLight()->makeFlame();
}
break;
case SDLK_F12:
diff --git a/src/ui_menu.cpp b/src/ui_menu.cpp
index 581e7fc..35a6d01 100644
--- a/src/ui_menu.cpp
+++ b/src/ui_menu.cpp
@@ -22,23 +22,14 @@ inline void segFault() {
(*((int *)NULL))++;
}
-void setControlF(unsigned int index)
+void setControlF(unsigned int index, menuItem &m)
{
SDL_Event e;
do SDL_WaitEvent(&e);
while (e.type != SDL_KEYDOWN);
setControl(index, e.key.keysym.sym);
-}
-
-void setLeftKey(void) {
- SDL_Event e;
-
- std::cout << "Waiting...\n";
- do SDL_WaitEvent(&e);
- while (e.type != SDL_KEYDOWN);
- std::cout << "Good.\n";
-
- setControl(2, e.key.keysym.sym);
+ m.button.text.pop_back();
+ m.button.text.push_back(e.key.keysym.sym);
}
namespace ui {
@@ -117,8 +108,18 @@ namespace ui {
optionsMenu.parent = &pauseMenu;
// Create the controls menu
- controlsMenu.items.push_back(ui::menu::createButton({-300,200}, {-200, 100}, {0.0f, 0.0f, 0.0f}, "Left", [](){ setControlF(2);}));
- controlsMenu.items.push_back(ui::menu::createButton({-300,50}, {-200, 100}, {0.0f, 0.0f, 0.0f}, "Right", [](){ setControlF(3);}));
+ controlsMenu.items.push_back(ui::menu::createButton({-450,300}, {400, 75}, {0.0f, 0.0f, 0.0f}, "Left: ", nullptr));
+ controlsMenu.items.back().button.func = [](){ setControlF(2, controlsMenu.items[0]); };
+ controlsMenu.items.push_back(ui::menu::createButton({-450,200}, {400, 75}, {0.0f, 0.0f, 0.0f}, "Right: ", nullptr));
+ controlsMenu.items.back().button.func = [](){ setControlF(3, controlsMenu.items[1]); };
+ controlsMenu.items.push_back(ui::menu::createButton({-450,100}, {400, 75}, {0.0f, 0.0f, 0.0f}, "Up: ", nullptr));
+ controlsMenu.items.back().button.func = [](){ setControlF(0, controlsMenu.items[2]); };
+ controlsMenu.items.push_back(ui::menu::createButton({-450,0}, {400, 75}, {0.0f, 0.0f, 0.0f}, "Sprint: ", nullptr));
+ controlsMenu.items.back().button.func = [](){ setControlF(4, controlsMenu.items[3]); };
+ controlsMenu.items.push_back(ui::menu::createButton({-450,-100}, {400, 75}, {0.0f, 0.0f, 0.0f}, "Creep: ", nullptr));
+ controlsMenu.items.back().button.func = [](){ setControlF(5, controlsMenu.items[4]); };
+ controlsMenu.items.push_back(ui::menu::createButton({-450,-200}, {400, 75}, {0.0f, 0.0f, 0.0f}, "Inventory: ", nullptr));
+ controlsMenu.items.back().button.func = [](){ setControlF(6, controlsMenu.items[5]); };
controlsMenu.parent = &pauseMenu;
}
@@ -248,7 +249,7 @@ namespace ui {
}else if (m.member == 1) {
//combining slider text with variable amount
char outSV[32];
- sprintf(outSV, "%s: %.1f",m.slider.text, *m.slider.var);
+ sprintf(outSV, "%s: %.1f",m.slider.text.c_str(), *m.slider.var);
float sliderW, sliderH;
diff --git a/xml/town.xml b/xml/town.xml
index 4e535d9..5ee8397 100644
--- a/xml/town.xml
+++ b/xml/town.xml
@@ -4,8 +4,8 @@
<generation type="Random" width="1600"/>
<time>6000</time>
<spawnx>-300</spawnx>
- <npc name="Sanc" hasDialog="true" health="1" x="122.07431" y="66.698975" dindex="0"/>
- <npc name="Bob" hasDialog="true" spawnx="30" health="1" x="637.40271" y="63.396015" dindex="0"/>
+ <npc name="Sanc" hasDialog="true" health="1" x="414.76144" y="62.599087" dindex="9999"/>
+ <npc name="Bob" hasDialog="true" spawnx="30" health="1" x="356.11185" y="60.999081" dindex="0"/>
<structure type="1" spawnx="300" alive="1"/>
<structure inside="bobshouse.xml" type="1" spawnx="10" alive="1"/>
<chest alive="1"/>