diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2016-06-28 21:32:04 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2016-06-28 21:32:04 -0400 |
commit | a466eb8fd6e5707aaa1bfafa28535b82c67d69d8 (patch) | |
tree | ce3a09b7b98584b3d42351eae7fd7e183e38b7f8 /src | |
parent | 00f633afb62ed6914205639b44dcdaf839a2c2f7 (diff) |
chests?, custom controls
Diffstat (limited to 'src')
-rw-r--r-- | src/entities.cpp | 3 | ||||
-rw-r--r-- | src/mob.cpp | 42 | ||||
-rw-r--r-- | src/ui.cpp | 101 | ||||
-rw-r--r-- | src/ui_menu.cpp | 50 | ||||
-rw-r--r-- | src/world.cpp | 99 |
5 files changed, 188 insertions, 107 deletions
diff --git a/src/entities.cpp b/src/entities.cpp index e156ee2..0c312e2 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -336,7 +336,8 @@ void Structures::createFromXML(XMLElement *e, World *w) // edge if (!inside.empty()) { - insideWorld = loadWorldFromXMLNoTakeover(inside); + insideWorld = dynamic_cast<IndoorWorld *>(loadWorldFromXMLNoTakeover(inside)); + insideWorld->outside = inWorld; } textureLoc = e->StrAttribute("texture"); diff --git a/src/mob.cpp b/src/mob.cpp index eba970e..20273d6 100644 --- a/src/mob.cpp +++ b/src/mob.cpp @@ -424,6 +424,48 @@ void Trigger::createFromXML(XMLElement *e, World *w=nullptr) void Trigger::saveToXML(void) {} +Chest::Chest(void) : Mob() +{ + ridable = false; + aggressive = false; + maxHealth = health = 100; + width = HLINES(10); + height = HLINES(5); + tex = TextureIterator({"assets/chest.png"}); +} + +void Chest::act(void) +{ + //die(); +} + +void Chest::onHit(unsigned int _health) +{ + (void)_health; + die(); +} + +bool Chest::bindTex(void) +{ + glActiveTexture(GL_TEXTURE0); + tex(0); + return true; +} + +void Chest::createFromXML(XMLElement *e, World *w) +{ + (void)w; + loc = vec2 { 0, 100 }; + xmle = e; +} + +void Chest::saveToXML(void) +{ + xmle->SetAttribute("alive", alive); +} + + + Mob::~Mob() { delete inv; @@ -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); diff --git a/src/ui_menu.cpp b/src/ui_menu.cpp index 5faf8a2..581e7fc 100644 --- a/src/ui_menu.cpp +++ b/src/ui_menu.cpp @@ -6,6 +6,7 @@ extern Menu *currentMenu; static Menu pauseMenu; static Menu optionsMenu; +static Menu controlsMenu; void Menu::gotoParent(void) { @@ -17,13 +18,27 @@ void Menu::gotoParent(void) } } -void Menu::gotoChild(void) +inline void segFault() { + (*((int *)NULL))++; +} + +void setControlF(unsigned int index) { - currentMenu = child; + SDL_Event e; + do SDL_WaitEvent(&e); + while (e.type != SDL_KEYDOWN); + setControl(index, e.key.keysym.sym); } -inline void segFault() { - (*((int *)NULL))++; +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); } namespace ui { @@ -37,11 +52,12 @@ namespace ui { temp.button.color = c; temp.button.text = t; temp.button.func = f; + temp.child = nullptr; return temp; } - menuItem createChildButton(vec2 l, dim2 d, Color c, const char* t) { + menuItem createChildButton(vec2 l, dim2 d, Color c, const char* t, Menu *_child) { menuItem temp; temp.member = -1; @@ -50,6 +66,7 @@ namespace ui { temp.button.color = c; temp.button.text = t; temp.button.func = NULL; + temp.child = _child; return temp; } @@ -63,6 +80,7 @@ namespace ui { temp.button.color = c; temp.button.text = t; temp.button.func = NULL; + temp.child = nullptr; return temp; } @@ -79,21 +97,29 @@ namespace ui { temp.slider.text = t; temp.slider.var = v; temp.slider.sliderLoc = *v; + temp.child = nullptr; return temp; } void init(void) { - pauseMenu.items.push_back(ui::menu::createParentButton({-256/2,0},{256,75},{0.0f,0.0f,0.0f}, "Resume")); - pauseMenu.items.push_back(ui::menu::createChildButton({-256/2,-100},{256,75},{0.0f,0.0f,0.0f}, "Options")); - pauseMenu.items.push_back(ui::menu::createButton({-256/2,-200},{256,75},{0.0f,0.0f,0.0f}, "Save and Quit", ui::quitGame)); - pauseMenu.items.push_back(ui::menu::createButton({-256/2,-300},{256,75},{0.0f,0.0f,0.0f}, "Segfault", segFault)); - pauseMenu.child = &optionsMenu; - + // Create the main pause menu + pauseMenu.items.push_back(ui::menu::createParentButton({-128,0},{256,75},{0.0f,0.0f,0.0f}, "Resume")); + pauseMenu.items.push_back(ui::menu::createChildButton({-128,-100},{256,75},{0.0f,0.0f,0.0f}, "Options", &optionsMenu)); + pauseMenu.items.push_back(ui::menu::createChildButton({-128,-200},{256,75},{0.0f,0.0f,0.0f}, "Controls", &controlsMenu)); + pauseMenu.items.push_back(ui::menu::createButton({-128,-300},{256,75},{0.0f,0.0f,0.0f}, "Save and Quit", ui::quitGame)); + pauseMenu.items.push_back(ui::menu::createButton({-128,-400},{256,75},{0.0f,0.0f,0.0f}, "Segfault", segFault)); + + // Create the options (sound) menu optionsMenu.items.push_back(ui::menu::createSlider({0-static_cast<float>(game::SCREEN_WIDTH)/4,0-(512/2)}, {50,512}, {0.0f, 0.0f, 0.0f}, 0, 100, "Master", &game::config::VOLUME_MASTER)); optionsMenu.items.push_back(ui::menu::createSlider({-200,100}, {512,50}, {0.0f, 0.0f, 0.0f}, 0, 100, "Music", &game::config::VOLUME_MUSIC)); optionsMenu.items.push_back(ui::menu::createSlider({-200,000}, {512,50}, {0.0f, 0.0f, 0.0f}, 0, 100, "SFX", &game::config::VOLUME_SFX)); 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.parent = &pauseMenu; } void toggle(void) { @@ -208,7 +234,7 @@ namespace ui { m.button.func(); break; case -1: - currentMenu->gotoChild(); + currentMenu = m.child; break; case -2: currentMenu->gotoParent(); diff --git a/src/world.cpp b/src/world.cpp index 8969fb9..7294fda 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -1314,7 +1314,7 @@ WorldSwitchInfo World::goInsideStructure(Player *p) // +size cuts folder prefix inside.push_back(¤tXML[xmlFolder.size()]); - tmp = loadWorldFromXML((*d)->inside); + tmp = (*d)->insideWorld; return std::make_pair(tmp, vec2 {0, 100}); } @@ -1322,7 +1322,7 @@ WorldSwitchInfo World::goInsideStructure(Player *p) // exit the building else { std::string current = ¤tXML[xmlFolder.size()]; - tmp = loadWorldFromXML(inside.back()); + tmp = dynamic_cast<IndoorWorld *>(currentWorld)->outside; //loadWorldFromXML(inside.back()); inside.clear(); Structures *b = nullptr; @@ -1646,56 +1646,59 @@ draw(Player *p) // TODO make floor texture static GLuint floorTex = Texture::genColor(Color(150, 100, 50)); - - glUseProgram(worldShader); glBindTexture(GL_TEXTURE_2D, floorTex); - std::vector<GLfloat>f; + std::vector<GLfloat> fc; + std::vector<GLfloat> ft; for (fl = 0; fl < floor.size(); fl++) { i = 0; for (const auto &h : floor[fl]) { - x = worldStart + fstart[fl] * HLINE + HLINES(i); - - f.emplace_back(x); - f.emplace_back(h); - f.emplace_back(-3); - f.emplace_back(0); - f.emplace_back(0); - - f.emplace_back(x + HLINE); - f.emplace_back(h); - f.emplace_back(-3); - f.emplace_back(1); - f.emplace_back(0); - - f.emplace_back(x + HLINE); - f.emplace_back(h - INDOOR_FLOOR_THICKNESS); - f.emplace_back(-3); - f.emplace_back(1); - f.emplace_back(1); - - f.emplace_back(x + HLINE); - f.emplace_back(h - INDOOR_FLOOR_THICKNESS); - f.emplace_back(-3); - f.emplace_back(1); - f.emplace_back(1); - - f.emplace_back(-3); - f.emplace_back(0); - f.emplace_back(1); - - f.emplace_back(x); - f.emplace_back(h); - f.emplace_back(-3); - f.emplace_back(0); - f.emplace_back(0); + x = worldStart + HLINES(fstart[fl] + i); + + fc.emplace_back(x); + fc.emplace_back(h); + fc.emplace_back(-3); + ft.emplace_back(0); + ft.emplace_back(0); + + fc.emplace_back(x + HLINE); + fc.emplace_back(h); + fc.emplace_back(-3); + ft.emplace_back(1); + ft.emplace_back(0); + + fc.emplace_back(x + HLINE); + fc.emplace_back(h - INDOOR_FLOOR_THICKNESS); + fc.emplace_back(-3); + ft.emplace_back(1); + ft.emplace_back(1); + + fc.emplace_back(x + HLINE); + fc.emplace_back(h - INDOOR_FLOOR_THICKNESS); + fc.emplace_back(-3); + ft.emplace_back(1); + ft.emplace_back(1); + + fc.emplace_back(x); + fc.emplace_back(h - INDOOR_FLOOR_THICKNESS); + fc.emplace_back(-3); + ft.emplace_back(0); + ft.emplace_back(1); + + fc.emplace_back(x); + fc.emplace_back(h); + fc.emplace_back(-3); + ft.emplace_back(0); + ft.emplace_back(0); i++; } } - makeWorldDrawingSimplerEvenThoughAndyDoesntThinkWeCanMakeItIntoFunctions_JustDrawThis(5 * sizeof(GLfloat), &f[0], &f[3], floor.size() * 6); + glUseProgram(worldShader); + + makeWorldDrawingSimplerEvenThoughAndyDoesntThinkWeCanMakeItIntoFunctions_JustDrawThis(0, &fc[0], &ft[0], floor.size() * 6); glUseProgram(0); @@ -1889,12 +1892,15 @@ loadWorldFromXMLNoSave(std::string path) { } // tells what world is outside, if in a structure - else if (Indoor && (ptr = wxml->Attribute("outside"))) - inside.push_back(ptr); + else if (Indoor && (ptr = wxml->Attribute("outside"))) { +// if (!loadedLeft && !loadedRight) +// inside.push_back(ptr); + } // error, invalid link tag - else + else { UserError("XML Error: Invalid <link> tag in " + _currentXML + "!"); + } } @@ -1949,7 +1955,9 @@ loadWorldFromXMLNoSave(std::string path) { newEntity = new Page(); } else if (name == "cat") { newEntity = new Cat(); - } + } else if (name == "chest") { + newEntity = new Chest(); + } // npc creation else if (name == "npc") { @@ -2001,7 +2009,6 @@ loadWorldFromXMLNoSave(std::string path) { newEntity->createFromXML(wxml, tmp); std::swap(currentXML, _currentXML); std::swap(currentXMLRaw, _currentXMLRaw); - std::cout << currentXML << '\n'; //} } |