]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
stars :O
authorClyne Sullivan <tullivan99@gmail.com>
Thu, 27 Apr 2017 22:32:57 +0000 (18:32 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Thu, 27 Apr 2017 22:32:57 +0000 (18:32 -0400)
include/world.hpp
src/inventory.cpp
src/world.cpp
xml/!town.xml

index 7d7d016adfa91a18b0d06874cbe1019309a15c36..163676dca68b6a97828b80707d01e03be9ceb778 100644 (file)
@@ -136,6 +136,8 @@ private:
         */
        static std::string currentXMLFile;
 
+       static std::vector<vec2> stars;
+
 public:
        static std::thread thAmbient;
 
index f307de27d7d4213cf2f78c1a67bdf6940f041316..761ca4300911c9405541f48de252f30402eddb9e 100644 (file)
@@ -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(
index 6351577e4ec7c5d9bed7dc6b1c75b09d1892f5f0..648507a03ad382274e7c1a49a8e32999d48fb1a7 100644 (file)
@@ -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];
+    GLfloatsi = &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();
 
index 72c11de0dd10ccb1796f95daccb9897f75fc28ad..e3fb946119bef2d65518d204d690f676329e966d 100644 (file)
@@ -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>