diff options
Diffstat (limited to 'src/mob.cpp')
-rw-r--r-- | src/mob.cpp | 63 |
1 files changed, 35 insertions, 28 deletions
diff --git a/src/mob.cpp b/src/mob.cpp index 1608234..e98a648 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) { @@ -16,7 +17,7 @@ Page::Page(void) : Mob() maxHealth = health = 50; width = HLINES(6); height = HLINES(4); - tex = new Texturec({"assets/items/ITEM_PAGE.png"}); + tex = TextureIterator({"assets/items/ITEM_PAGE.png"}); } void Page::act(void) @@ -34,7 +35,7 @@ void Page::act(void) bool Page::bindTex(void) { glActiveTexture(GL_TEXTURE0); - tex->bind(0); + tex(0); return true; } @@ -53,7 +54,7 @@ Door::Door(void) : Mob() maxHealth = health = 50; width = HLINES(12); height = HLINES(20); - tex = new Texturec({"assets/door.png"}); + tex = TextureIterator({"assets/door.png"}); } void Door::act(void) @@ -63,7 +64,7 @@ void Door::act(void) bool Door::bindTex(void) { glActiveTexture(GL_TEXTURE0); - tex->bind(0); + tex(0); return true; } @@ -81,7 +82,7 @@ Cat::Cat(void) : Mob() maxHealth = health = 1000; width = HLINES(19); height = HLINES(15); - tex = new Texturec({"assets/cat.png"}); + tex = TextureIterator({"assets/cat.png"}); actCounterInitial = 0; actCounter = 1; } @@ -115,7 +116,7 @@ void Cat::act(void) bool Cat::bindTex(void) { glActiveTexture(GL_TEXTURE0); - tex->bind(0); + tex(0); return true; } @@ -133,22 +134,26 @@ Rabbit::Rabbit(void) : Mob() maxHealth = health = 50; width = HLINES(10); height = HLINES(8); - tex = new Texturec({"assets/rabbit.png", "assets/rabbit1.png"}); - actCounterInitial = getRand() % 240 + 15; + tex = TextureIterator({"assets/rabbit.png", "assets/rabbit1.png"}); + actCounterInitial = randGet() % 240 + 15; actCounter = 1; } +extern bool inBattle; void Rabbit::act(void) { static int direction = 0; if (!--actCounter) { actCounter = actCounterInitial; - direction = (getRand() % 3 - 1); //sets the direction to either -1, 0, 1 + direction = (randGet() % 3 - 1); //sets the direction to either -1, 0, 1 if (direction == 0) ticksToUse /= 2; vel.x *= direction; } + if (inBattle) + die(); + if (ground && direction) { ground = false; vel.y = .15; @@ -160,7 +165,7 @@ void Rabbit::act(void) bool Rabbit::bindTex(void) { glActiveTexture(GL_TEXTURE0); - tex->bind(!ground); + tex(!ground); return true; } @@ -182,7 +187,7 @@ Bird::Bird(void) : Mob() maxHealth = health = 50; width = HLINES(8); height = HLINES(8); - tex = new Texturec({"assets/robin.png"}); + tex = TextureIterator({"assets/robin.png"}); actCounterInitial = actCounter = 200; } @@ -203,7 +208,7 @@ void Bird::act(void) bool Bird::bindTex(void) { glActiveTexture(GL_TEXTURE0); - tex->bind(0); + tex(0); return true; } @@ -227,7 +232,7 @@ Trigger::Trigger(void) : Mob() maxHealth = health = 50; width = HLINES(20); height = 2000; - tex = new Texturec(0); + //tex = TextureIterator(); triggered = false; } @@ -289,32 +294,34 @@ void Trigger::createFromXML(const XMLElement *e) Mob::~Mob() { delete inv; - delete tex; 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(); } |