From a33b3d4ffc1defda5bdcd3348036ce48ef5b0085 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan <tullivan99@gmail.com> Date: Thu, 27 Apr 2017 17:40:12 -0400 Subject: modernized ui --- include/world.hpp | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) (limited to 'include/world.hpp') diff --git a/include/world.hpp b/include/world.hpp index e47f78f..7d7d016 100644 --- a/include/world.hpp +++ b/include/world.hpp @@ -108,36 +108,36 @@ private: /** * The world's data. */ - WorldData2 world; + static WorldData2 world; /** * SDL's object for handling the background music. */ - Mix_Music *bgmObj; - std::string bgmCurrent; + static Mix_Music *bgmObj; + static std::string bgmCurrent; /** * Paths of files to get stylized textures from. */ - std::vector<std::string> bgFiles; + static std::vector<std::string> bgFiles; /** * Allows for iteration between background textures, for rendering. */ - TextureIterator bgTex; + static TextureIterator bgTex; /** * An object to handle and parse world XML files. */ - XMLDocument xmlDoc; + static XMLDocument xmlDoc; /** * The file path to the currently loaded world. */ - std::string currentXMLFile; + static std::string currentXMLFile; public: - std::thread thAmbient; + static std::thread thAmbient; explicit WorldSystem(void); ~WorldSystem(void); @@ -146,37 +146,32 @@ public: ev.subscribe<BGMToggleEvent>(*this); } - inline XMLDocument* getXML(void) + static inline XMLDocument* getXML(void) { return &xmlDoc; } - inline float getWidth(void) const + static inline float getWidth(void) //const { return world.startX * -2.0f; } - float isAboveGround(const vec2& p) const; + static inline const std::string& getXMLFile(void) //const + { return currentXMLFile; } - void receive(const BGMToggleEvent &bte); + static float isAboveGround(const vec2& p); //const; + void receive(const BGMToggleEvent &bte); void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override; - void render(void); + static void render(void); - inline const std::string& getXMLFile(void) const - { return currentXMLFile; } void detect(entityx::TimeDelta dt); - void goWorldLeft(Position& p); - void goWorldRight(Position& p, Solid &d); - void goWorldPortal(Position& p); - - // worlddata2 stuff - WorldData2 worldData; + static void goWorldLeft(Position& p); + static void goWorldRight(Position& p, Solid &d); + static void goWorldPortal(Position& p); - void generate(int width = 0); - //void addHole(const unsigned int& start, const unsigned int& end); - //void addHill(const ivec2& peak, const unsigned int& width); + static void generate(int width = 0); - bool save(void); - void load(const std::string& file); + static bool save(void); + static void load(const std::string& file); void fight(entityx::Entity entity); }; -- cgit v1.2.3 From ef1ea79375ce865d78fb7da4244aee65d25c04b3 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan <tullivan99@gmail.com> Date: Thu, 27 Apr 2017 18:32:57 -0400 Subject: stars :O --- include/world.hpp | 2 ++ src/inventory.cpp | 2 +- src/world.cpp | 105 +++++++++++------------------------------------------- xml/!town.xml | 2 +- 4 files changed, 24 insertions(+), 87 deletions(-) (limited to 'include/world.hpp') diff --git a/include/world.hpp b/include/world.hpp index 7d7d016..163676d 100644 --- a/include/world.hpp +++ b/include/world.hpp @@ -136,6 +136,8 @@ private: */ static std::string currentXMLFile; + static std::vector<vec2> stars; + public: static std::thread thAmbient; diff --git a/src/inventory.cpp b/src/inventory.cpp index f307de2..761ca43 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -212,7 +212,7 @@ void InventorySystem::receive(const MouseReleaseEvent &mre) auto e = game::entities.create(); e.assign<Position>(mre.position.x, mre.position.y); - e.assign<Direction>(0, 0.4f); + e.assign<Direction>(0, 0.1f); e.assign<ItemDrop>(items[movingItem]); e.assign<Sprite>(); e.component<Sprite>()->addSpriteSegment( diff --git a/src/world.cpp b/src/world.cpp index 6351577..648507a 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -36,6 +36,7 @@ TextureIterator WorldSystem::bgTex; XMLDocument WorldSystem::xmlDoc; std::string WorldSystem::currentXMLFile; std::thread WorldSystem::thAmbient; +std::vector<vec2> WorldSystem::stars; extern std::string xmlFolder; @@ -123,6 +124,15 @@ void WorldSystem::generate(int width) // define x-coordinate of world's leftmost 'line' world.startX = HLINES(width * -0.5); + + // gen. star coordinates + if (stars.empty()) { + stars.resize(game::SCREEN_WIDTH / 30); + for (auto& s : stars) { + s.x = world.startX + (randGet() % (int)HLINES(width)); + s.y = game::SCREEN_HEIGHT - (randGet() % (int)HLINES(game::SCREEN_HEIGHT / 1.3f)); + } + } } float WorldSystem::isAboveGround(const vec2& p) @@ -445,76 +455,6 @@ loadWorldFromXMLNoSave(std::string path) { const char *ptr; std::string name, sptr; - // iterate through world tags - while (wxml) { - newEntity = nullptr; - name = wxml->Name(); - - // set spawn x for player - else if (name == "spawnx" && !(loadedLeft | loadedRight)) { - player->loc.x = std::stoi(wxml->GetText()); - } - - // mob creation - else if (name == "rabbit") { - newEntity = new Rabbit(); - } else if (name == "bird") { - newEntity = new Bird(); - } else if (name == "trigger") { - newEntity = new Trigger(); - } else if (name == "door") { - newEntity = new Door(); - } else if (name == "page") { - newEntity = new Page(); - } else if (name == "cat") { - newEntity = new Cat(); - } else if (name == "chest") { - newEntity = new Chest(); - } - - // npc creation - else if (name == "npc") { - newEntity = new NPC(); - } - - // structure creation - else if (name == "structure") { - newEntity = new Structures(); - } - - // hill creation - else if (name == "hill") { - tmp->addHill(ivec2 { wxml->IntAttribute("peakx"), wxml->IntAttribute("peaky") }, wxml->UnsignedAttribute("width")); - } - - if (newEntity != nullptr) { - //bool alive = true; - //if (wxml->QueryBoolAttribute("alive", &alive) != XML_NO_ERROR || alive) { - switch (newEntity->type) { - case NPCT: - tmp->addNPC(dynamic_cast<NPC *>(newEntity)); - break; - case MOBT: - tmp->addMob(dynamic_cast<Mob *>(newEntity), vec2 {0, 0}); - break; - case STRUCTURET: - tmp->addStructure(dynamic_cast<Structures *>(newEntity)); - break; - default: - break; - } - - std::swap(currentXML, _currentXML); - std::swap(currentXMLRaw, _currentXMLRaw); - newEntity->createFromXML(wxml, tmp); - std::swap(currentXML, _currentXML); - std::swap(currentXMLRaw, _currentXMLRaw); - //} - } - - wxml = wxml->NextSiblingElement(); - } - Village *vptr; Structures *s; @@ -610,13 +550,6 @@ loadWorldFromXMLNoSave(std::string path) { vil = vil->NextSiblingElement(); } - if (!loadedLeft && !loadedRight) { - currentXML = _currentXML; - currentXMLRaw = _currentXMLRaw; - } else { - delete _currentXMLDoc; - } - return tmp; }*/ @@ -735,16 +668,16 @@ void WorldSystem::render(void) //makeWorldDrawingSimplerEvenThoughAndyDoesntThinkWeCanMakeItIntoFunctions(0, fron_tex_coord, tex_coord, 6); // TODO make stars dynamic (make them particles??) - /*static GLuint starTex = Texture::loadTexture("assets/style/classic/bg/star.png"); + static const Texture starTex ("assets/style/classic/bg/star.png"); // TODO why in theme, not just std.? const static float stardim = 24; - GLfloat star_coord[star.size() * 5 * 6 + 1]; - GLfloat *si = &star_coord[0]; + GLfloat* star_coord = new GLfloat[stars.size() * 5 * 6 + 1]; + GLfloat* si = &star_coord[0]; if (worldShade > 0) { auto xcoord = offset.x * 0.9f; - for (auto &s : star) { + for (auto &s : stars) { float data[30] = { s.x + xcoord, s.y, 9.7, 0, 0, s.x + xcoord + stardim, s.y, 9.7, 1, 0, @@ -757,11 +690,13 @@ void WorldSystem::render(void) std::memcpy(si, data, sizeof(float) * 30); si += 30; } - glBindTexture(GL_TEXTURE_2D, starTex); - glUniform4f(Render::worldShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.3 - static_cast<float>(alpha)/255.0f); + starTex.use(); + glUniform4f(Render::worldShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.3); - makeWorldDrawingSimplerEvenThoughAndyDoesntThinkWeCanMakeItIntoFunctions(5 * sizeof(GLfloat), &star_coord[0], &star_coord[3], star.size() * 6); - }*/ + glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &star_coord[0]); + glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &star_coord[3]); + glDrawArrays(GL_TRIANGLES, 0, stars.size() * 6); + } Render::worldShader.disable(); diff --git a/xml/!town.xml b/xml/!town.xml index 72c11de..e3fb946 100644 --- a/xml/!town.xml +++ b/xml/!town.xml @@ -4,7 +4,7 @@ <World> <style background="0" bgm="assets/music/embark.wav" folder="assets/style/classic/"/> <generation width="320"/> - <weather>Snowy</weather> + <weather>Sunny</weather> <link right="!town2.xml"/> <spawnx>-300</spawnx> <time>8000</time> -- cgit v1.2.3