]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
control setting
authorClyne Sullivan <tullivan99@gmail.com>
Wed, 29 Jun 2016 14:18:56 +0000 (10:18 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Wed, 29 Jun 2016 14:18:56 +0000 (10:18 -0400)
include/ui_menu.hpp
src/ui.cpp
src/ui_menu.cpp
xml/town.xml

index 3ed9fa574aea8020cd87b518853519f276296cf8..8ca9368785f3f6d3fa9cf3aa1dcb9dd887c4ffc2 100644 (file)
@@ -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;
index d7f6e19053fcd179ede5aa9a2b34222b30b5ac21..f3523f645af0e7aec10c7686517079b59381535a 100644 (file)
@@ -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:
index 581e7fc9b87eafe499697fb805631ec9166ba276..35a6d0149ff9a44daea25680a081b39cc42fc480 100644 (file)
@@ -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;
 
index 4e535d9e397214fb857a80dd99a532649311006b..5ee83976d48dd333e6434fc3e62e4357dc6138ba 100644 (file)
@@ -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"/>