diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2016-04-29 08:47:21 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2016-04-29 08:47:21 -0400 |
commit | bf3a781ab8ea7c00bf18c960bcb23e72da99bc7b (patch) | |
tree | 0adb4cff5da5a4a05356278eb0d5ae4d9b9c6858 /src | |
parent | 62df9319f06bb52da8878522117ebe85fc5226b5 (diff) |
re-added arenas
Diffstat (limited to 'src')
-rw-r--r-- | src/mob.cpp | 36 | ||||
-rw-r--r-- | src/ui.cpp | 63 | ||||
-rw-r--r-- | src/world.cpp | 86 |
3 files changed, 78 insertions, 107 deletions
diff --git a/src/mob.cpp b/src/mob.cpp index 1608234..220e948 100644 --- a/src/mob.cpp +++ b/src/mob.cpp @@ -1,5 +1,6 @@ #include <mob.hpp> #include <ui.hpp> +#include <world.hpp> Mob::Mob(void) { @@ -138,6 +139,7 @@ Rabbit::Rabbit(void) : Mob() actCounter = 1; } +extern bool inBattle; void Rabbit::act(void) { static int direction = 0; @@ -149,6 +151,9 @@ void Rabbit::act(void) vel.x *= direction; } + if (inBattle) + die(); + if (ground && direction) { ground = false; vel.y = .15; @@ -293,28 +298,31 @@ Mob::~Mob() delete[] name; } +extern World *currentWorld; void Mob::wander(void) { - //static bool YAYA = false; + static bool YAYA = false; if (forcedMove) return; - /*if (aggressive && !YAYA && isInside(vec2 {player->loc.x + width / 2, player->loc.y + height / 4})) { + if (aggressive && !YAYA && isInside(vec2 {player->loc.x + width / 2, player->loc.y + height / 4})) { if (!ui::dialogBoxExists) { - Arena *a = new Arena(currentWorld, player, this); - a->setStyle(""); - a->setBackground(WorldBGType::Forest); - a->setBGM("assets/music/embark.wav"); - - ui::toggleWhiteFast(); - YAYA = true; - ui::waitForCover(); - YAYA = false; - currentWorld = a; - ui::toggleWhiteFast(); + std::thread([&](void){ + auto *a = new Arena(currentWorld, player, this); + a->setStyle(""); + a->setBackground(WorldBGType::Forest); + a->setBGM("assets/music/embark.wav"); + + ui::toggleWhiteFast(); + YAYA = true; + ui::waitForCover(); + YAYA = false; + currentWorld = a; + ui::toggleWhiteFast(); + }).detach(); } - }*/ + } act(); } @@ -916,8 +916,9 @@ EXIT: auto SCREEN_WIDTH = game::SCREEN_WIDTH; auto SCREEN_HEIGHT = game::SCREEN_HEIGHT; - World *tmp; + auto indoor = dynamic_cast<IndoorWorld *>(currentWorld); Mob *m; // ;lkjfdsa + SDL_Event e; // update mouse coords @@ -1012,7 +1013,6 @@ EXIT: // only let other keys be handled if dialog allows it } else if (!dialogBoxExists || dialogPassive) { - tmp = currentWorld; switch(SDL_KEY) { case SDLK_t: game::time::tick(50); @@ -1061,23 +1061,33 @@ EXIT: break; case SDLK_w: if (inBattle) { - tmp = currentWorld; - currentWorld = ((Arena *)currentWorld)->exitArena(player); - if (tmp != currentWorld) - toggleBlackFast(); + std::thread([&](void){ + auto thing = dynamic_cast<Arena *>(currentWorld)->exitArena(player); + if (thing.first != currentWorld) { + player->canMove = false; + toggleBlackFast(); + waitForCover(); + //delete dynamic_cast<Arena *>(currentWorld); + currentWorld = thing.first; + player->loc = thing.second; + toggleBlackFast(); + player->canMove = true; + } + }).detach(); } else { - auto tmpp = currentWorld->goInsideStructure(player); - - if (tmpp.first != currentWorld) { - ui::toggleBlackFast(); - ui::waitForCover(); - - currentWorld = tmpp.first; - if (tmpp.second) - player->loc.x = tmpp.second; - - ui::toggleBlackFast(); - } + std::thread([&](void){ + auto thing = currentWorld->goInsideStructure(player); + if (thing.first != currentWorld) { + player->canMove = false; + toggleBlackFast(); + waitForCover(); + currentWorld = thing.first; + if (thing.second.x) + player->loc.x = thing.second.x; + toggleBlackFast(); + player->canMove = true; + } + }).detach(); } break; case SDLK_LSHIFT: @@ -1111,15 +1121,6 @@ EXIT: default: break; } - - // handle world switches? - if (tmp != currentWorld) { - std::swap(tmp, currentWorld); - toggleBlackFast(); - waitForCover(); - std::swap(tmp, currentWorld); - toggleBlackFast(); - } } break; /* @@ -1145,14 +1146,14 @@ EXIT: m->ride(player); break; case SDLK_i: - if (isCurrentWorldIndoors() && Indoorp(currentWorld)->isFloorAbove(player)) { - player->loc.y += getIndoorWorldFloorHeight(); + if (indoor && indoor->isFloorAbove(player)) { + player->loc.y += INDOOR_FLOOR_HEIGHT; player->ground = false; } break; case SDLK_k: - if (isCurrentWorldIndoors() && Indoorp(currentWorld)->isFloorBelow(player)) { - player->loc.y -= getIndoorWorldFloorHeight(); + if (indoor && indoor->isFloorBelow(player)) { + player->loc.y -= INDOOR_FLOOR_HEIGHT; player->ground = false; } break; diff --git a/src/world.cpp b/src/world.cpp index cd57087..5d6e7c1 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -48,6 +48,7 @@ static const unsigned int GRASS_HEIGHT = 4; // indoor world constants static const unsigned int INDOOR_FLOOR_THICKNESS = 50; static const unsigned int INDOOR_FLOOR_HEIGHTT = 400; +const unsigned int INDOOR_FLOOR_HEIGHT = INDOOR_FLOOR_HEIGHTT + INDOOR_FLOOR_THICKNESS; // the path of the currently loaded XML file, externally referenced in places std::string currentXML; @@ -59,8 +60,7 @@ WorldWeather weather = WorldWeather::Sunny; static std::vector<std::string> inside; // keeps track of information of worlds the player has left to enter arenas -static std::vector<World *> battleNest; -static std::vector<vec2> battleNestLoc; +static std::vector<WorldSwitchInfo> arenaNest; // pathnames of images for world themes static const unsigned int BG_PATHS_ENTRY_SIZE = 9; @@ -1053,7 +1053,7 @@ getToRight(void) const /** * Attempts to go to the left world, returning either that world or itself. */ -std::pair<World *, vec2> World:: +WorldSwitchInfo World:: goWorldLeft(Player *p) { World *tmp; @@ -1074,7 +1074,7 @@ goWorldLeft(Player *p) /** * Attempts to go to the right world, returning either that world or itself. */ -std::pair<World *, vec2> World:: +WorldSwitchInfo World:: goWorldRight(Player *p) { World *tmp; @@ -1110,7 +1110,7 @@ goWorldLeft(NPC *e) /** * Attempts to enter a building that the player is standing in front of. */ -std::pair<World *, float> World:: +WorldSwitchInfo World:: goInsideStructure(Player *p) { World *tmp; @@ -1122,13 +1122,13 @@ goInsideStructure(Player *p) auto b = *d; if ((d == std::end(build)) || b->inside.empty()) - return std::make_pair(this, 0); + return std::make_pair(this, vec2 {0, 0}); // +size cuts folder prefix inside.push_back(¤tXML[xmlFolder.size()]); tmp = loadWorldFromXML(b->inside); - return std::make_pair(tmp, 0); + return std::make_pair(tmp, vec2 {0, 0}); } else { std::string current = ¤tXML[xmlFolder.size()]; tmp = loadWorldFromXML(inside.back()); @@ -1143,12 +1143,12 @@ goInsideStructure(Player *p) } if (b == nullptr) - return std::make_pair(this, 0); + return std::make_pair(this, vec2 {0, 0}); - return std::make_pair(tmp, b->loc.x + (b->width / 2)); + return std::make_pair(tmp, vec2 {b->loc.x + (b->width / 2), 0}); } - return std::make_pair(this, 0); + return std::make_pair(this, vec2 {0, 0}); } void World:: @@ -1169,15 +1169,6 @@ addVillage(std::string name, World *world) return &village.back(); } -/*void World:: -addMob(int t, float x, float y) -{ - mob.push_back(new new(auto *&t)); - mob.back()->spawn(x, y); - - entity.push_back(mob.back()); -}*/ - void World::addMob(Mob *m, vec2 coord) { mob.push_back(m); @@ -1186,16 +1177,6 @@ void World::addMob(Mob *m, vec2 coord) entity.push_back(mob.back()); } -/*void World:: -addMob(int t, float x, float y, void (*hey)(Mob *)) -{ - mob.push_back(new Mob(t)); - mob.back()->spawn(x, y); - mob.back()->hey = hey; - - entity.push_back(mob.back()); -}*/ - void World:: addNPC(float x, float y) { @@ -1284,15 +1265,6 @@ addHill(const ivec2 peak, const unsigned int width) } } -float getIndoorWorldFloorHeight(void) -{ - return INDOOR_FLOOR_HEIGHTT + INDOOR_FLOOR_THICKNESS; -} - -bool isCurrentWorldIndoors(void) { - return !inside.empty(); -} - IndoorWorld::IndoorWorld(void) { } @@ -1507,47 +1479,37 @@ draw(Player *p) p->draw(); } -Arena::Arena(World *leave,Player *p,Mob *m) { +Arena::Arena(World *leave, Player *p, Mob *m) +{ generate(800); addMob(new Door(), vec2 {100, 100}); inBattle = true; - mmob = m; - mmob->aggressive = false; - mob.push_back(m); - entity.push_back(mob.back()); + mob.push_back((mmob = m)); + entity.push_back(mmob); + mmob->aggressive = false; - battleNest.push_back(leave); - battleNestLoc.push_back(p->loc); + arenaNest.emplace_back(leave, p->loc); } Arena::~Arena(void) { + mmob->die(); deleteEntities(); } -World *Arena::exitArena(Player *p) { - World *tmp; +WorldSwitchInfo Arena::exitArena(Player *p) { if (!mmob->isAlive() && p->loc.x + p->width / 2 > mob[0]->loc.x && p->loc.x + p->width / 2 < mob[0]->loc.x + HLINES(12)) { - tmp = battleNest.front(); - battleNest.erase(battleNest.begin()); - - inBattle = !battleNest.empty(); - ui::toggleBlackFast(); - ui::waitForCover(); - - p->loc = battleNestLoc.back(); - battleNestLoc.pop_back(); + auto ret = arenaNest.back(); + arenaNest.pop_back(); + inBattle = !(arenaNest.empty()); - mob.clear(); - mmob->die(); - - return tmp; - } + return ret; + } - return this; + return std::make_pair(this, vec2 {0, 0}); } std::string getWorldWeatherStr(WorldWeather ww) |