]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
mem leak patches; world ground from image
authorClyne Sullivan <tullivan99@gmail.com>
Mon, 25 Feb 2019 23:47:55 +0000 (18:47 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Mon, 25 Feb 2019 23:47:55 +0000 (18:47 -0500)
assets/testground.png [new file with mode: 0644]
include/systems/light.hpp
include/systems/movement.hpp
include/texture.hpp
include/world.hpp
src/systems/light.cpp
src/systems/movement.cpp
src/texture.cpp
src/world.cpp
xml/!town.xml
xml/bobshouse.xml

diff --git a/assets/testground.png b/assets/testground.png
new file mode 100644 (file)
index 0000000..1d79cad
Binary files /dev/null and b/assets/testground.png differ
index ba91113ec4697c4b7c4af4eb3331ddc2dd5d5cb5..02c7eed611af161960131d553d928fe7b8ada73e 100644 (file)
@@ -21,6 +21,11 @@ class LightSystem : public entityx::System<LightSystem> {
 private:
        static std::vector<Light> lights;
 
+       static GLfloat *colorData;
+       static GLfloat *coordData;
+
+       static void resizeLights(void);
+
 public:
        void update(entityx::EntityManager& en, entityx::EventManager& ev, entityx::TimeDelta dt) override;
 
index fd37665a06a52a0cb21c2100faac31695298a0da..745fa9b7a6c8520a713584dbebf9e64132e7a712 100644 (file)
@@ -2,10 +2,32 @@
 #define SYSTEM_MOVEMENT_HPP_
 
 #include <entityx/entityx.h>
+#include <attack.hpp>
 
 class MovementSystem : public entityx::System<MovementSystem> {
+private:
+       constexpr static const char *hitPlayerScript = "\
+               effect = function()\n \
+                       flash(255, 0, 0)\n \
+                       damage(1)\n \
+               end\n \
+               hit = function()\n \
+                       xrange = 5\n \
+               end";
+       static LuaScript hitPlayer;
+       static Attack playerAttack;
+
 public:
+       MovementSystem(void) {
+               hitPlayer = LuaScript(hitPlayerScript);
+               AttackSystem::initLua(hitPlayer);
+               playerAttack = { vec2(), vec2(5, 5), vec2(), vec2(),
+                       hitPlayer, TextureIterator() };
+       }
+
        void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
+
+       static int doAttack(lua_State *);
 };
 
 #endif // SYSTEM_MOVEMENT_HPP_
index d4bcfa9a70d941f59807e484cd12244ba1e02b71..db1635760d6ca47d21e4622312ae9ee7ac715696 100644 (file)
@@ -174,4 +174,19 @@ public:
  */
 void unloadTextures(void);
 
+class ObjectTexture : public Texture {
+private:
+       std::vector<bool> solidMap;
+       bool valid;
+
+public:
+       ObjectTexture(const std::string filename = "");
+
+       int getHeight(int index);
+       bool isInsideObject(vec2 coord) const;
+       inline bool isValid(void) {
+               return valid;
+       }
+};
+
 #endif //TEXTURE_HPP_
index 0bfe078e766ed27ea0fee93c2f59647191c9c4b2..d53a40b378fe99fe7091796d66e7fd52d7bc155f 100644 (file)
@@ -69,7 +69,7 @@ constexpr const unsigned int INDOOR_FLOOR_HEIGHT = (INDOOR_FLOOR_HEIGHTT + INDOO
 struct WorldData2 {
 
        // Data variables
-       std::vector<WorldData> data; /**< The world's ground data. */
+       ObjectTexture ground;
        float startX;                /**< The furthest left coordinate of the world. */
 
        // Indoor variables
@@ -125,8 +125,6 @@ private:
 
        static std::vector<vec2> stars;
 
-       static int getLineIndex(float x);
-
 public:
        static std::thread thAmbient;
 
@@ -159,7 +157,8 @@ public:
        static void goWorldRight(Position& p, Solid &d);
        static void goWorldPortal(Position& p);
 
-       static void generate(LuaScript& script);
+       static void generate(const char *file);
+       static float getGroundHeight(float x);
 
        static bool save(void);
        static void load(const std::string& file);
index 51a6702049578391782f30a8e4871f2204e30598..b7c62aa37c6fd7c305921c8cbc8ef3cf891f3a1d 100644 (file)
@@ -6,6 +6,17 @@
 
 std::vector<Light> LightSystem::lights;
 
+GLfloat *LightSystem::colorData = nullptr;
+GLfloat *LightSystem::coordData = nullptr;
+
+void LightSystem::resizeLights(void)
+{
+       delete colorData;
+       delete coordData;
+       colorData = new GLfloat[lights.size() * 4];
+       coordData = new GLfloat[lights.size() * 4];
+}
+
 void LightSystem::update(entityx::EntityManager& en, entityx::EventManager& ev, entityx::TimeDelta dt) {
        (void)ev;
        (void)dt;
@@ -20,23 +31,20 @@ void LightSystem::update(entityx::EntityManager& en, entityx::EventManager& ev,
 }
 
 void LightSystem::render(void) {
-       auto coords = new GLfloat[lights.size() * 4];
-       auto colors = new GLfloat[lights.size() * 4];
-
        unsigned int offset = 0;
        for (const auto& l : lights) {
-               coords[offset] = l.pos.x, coords[offset + 1] = l.pos.y,
-                       coords[offset + 2] = -5, coords[offset + 3] = l.radius;
-               colors[offset] = l.color.red, colors[offset + 1] = l.color.green,
-                       colors[offset + 2] = l.color.blue, colors[offset + 3] = 1.0f;
+               coordData[offset] = l.pos.x, coordData[offset + 1] = l.pos.y,
+                       coordData[offset + 2] = -5, coordData[offset + 3] = l.radius;
+               colorData[offset] = l.color.red, colorData[offset + 1] = l.color.green,
+                       colorData[offset + 2] = l.color.blue, colorData[offset + 3] = 1.0f;
                offset += 4;
        }
 
        Render::worldShader.use();
        Render::worldShader.enable();
 
-       glUniform4fv(Render::worldShader.uniform[WU_light], lights.size(), coords);
-       glUniform4fv(Render::worldShader.uniform[WU_light_color], lights.size(), colors);
+       glUniform4fv(Render::worldShader.uniform[WU_light], lights.size(), coordData);
+       glUniform4fv(Render::worldShader.uniform[WU_light_color], lights.size(), colorData);
        glUniform1i(Render::worldShader.uniform[WU_light_size], lights.size());
 
        Render::worldShader.disable();
@@ -45,6 +53,7 @@ void LightSystem::render(void) {
 
 int LightSystem::addLight(vec2 pos, float radius, Color color) {
        lights.emplace_back(pos, radius, color);
+       resizeLights();
        return lights.size() - 1;
 }
 
@@ -56,5 +65,6 @@ void LightSystem::updateLight(int index, vec2 pos, float radius) {
 
 void LightSystem::removeLight(int index) {
        lights.erase(lights.begin() + index);
+       resizeLights();
 }
 
index 642fa6a611a461d4a76b816fef72fd2a87b771b9..b2c95c585a470165636563dc14dd24abc2e1aaf5 100644 (file)
 
 #include <thread>
 
-#include <attack.hpp>
 #include <events.hpp>
 #include <player.hpp>
 #include <ui.hpp>
 
+LuaScript MovementSystem::hitPlayer;
+Attack MovementSystem::playerAttack;
+
+int MovementSystem::doAttack(lua_State* s)
+{
+       vec2 pos (lua_tonumber(s, 1), lua_tonumber(s, 2));
+       game::events.emit<AttackEvent>(AttackEvent(pos,
+               playerAttack, false));
+       return 0;
+}
+
 void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
 {
        //bool fight = false;
@@ -72,18 +82,6 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e
                                }
                        }
 
-                       static auto doAttack = [](lua_State* s) -> int {
-                               vec2 pos (lua_tonumber(s, 1), lua_tonumber(s, 2));
-                               LuaScript script ("effect = function()\nflash(255,0,0)\ndamage(1)\nend\n\
-                                       hit = function()\nxrange = 5\nend");
-                               AttackSystem::initLua(script);
-                               Attack attack = {vec2(), vec2(5, 5), vec2(), vec2(),
-                                       script, TextureIterator()};
-                               game::events.emit<AttackEvent>(AttackEvent(pos,
-                                       attack, false));
-                               return 0;
-                       };
-
                        // make the entity wander
                        // TODO initialX and range?
                        if (entity.has_component<Wander>()) {
index 19aae3f7273f455ba6888607d77c44e6a47d92fa..422f0134ecacaaf9f23c72a34df7806386489a9d 100644 (file)
 #include <error.hpp>
 #include <gif_lib.h>
 
+ObjectTexture::ObjectTexture(const std::string filename)
+{
+       valid = !filename.empty();
+       if (!valid)
+               return;
+
+       auto image = IMG_Load(filename.c_str());
+
+       // format: RGBA8
+       solidMap.resize(image->w * image->h);
+       auto rgba = ((uint8_t *)image->pixels) + 3;
+       auto iter = solidMap.begin();
+       for (int i = 0; i < image->w * image->h; i++) {
+               *iter++ = *rgba > 0;
+               rgba += 4;
+       }
+
+       GLuint object;
+       glGenTextures(1, &object);                              // Turns "object" into a texture
+       glBindTexture(GL_TEXTURE_2D, object);   // Binds "object" to the top of the stack
+       glPixelStoref(GL_UNPACK_ALIGNMENT, 1);
+       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);      // Sets the "min" filter
+       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);      // The the "max" filter of the stack
+       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // Wrap the texture to the matrix
+       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); //
+       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->w, image->h, 0,
+                                GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);
+
+       name = filename;
+       tex = object;
+       dim = vec2 {(float)image->w, (float)image->h};
+
+       // free the SDL_Surface
+       SDL_FreeSurface(image);
+}
+
+int ObjectTexture::getHeight(int index)
+{
+       if (index < 0 || index > dim.x)
+               return 100;
+
+       unsigned int h;
+       for (h = 0; h < dim.y; h++) {
+               if (solidMap[h * dim.x + index])
+                       return dim.y - h;
+       }
+       return 0;
+}
+
+bool ObjectTexture::isInsideObject(vec2 coord) const {
+       coord /= 2;
+       return solidMap[(int)coord.y * (int)dim.x + (int)coord.x];
+}
+
 namespace Colors
 {
        ColorTex white;
index 0cfa7251ab589b3a846f23ff61f34010bd5d26e4..a6083848ed6474005ecebf1e152f89944f15caa3 100644 (file)
@@ -54,45 +54,30 @@ WorldSystem::~WorldSystem(void)
 {
 }
 
-int WorldSystem::getLineIndex(float x)
+void WorldSystem::generate(const char *file)
 {
-       return std::clamp(static_cast<int>((x - world.startX) / game::HLINE),
-               0, static_cast<int>(world.data.size()));
-}
-
-void WorldSystem::generate(LuaScript& script)
-{
-       int i = 0;
-       world.data.clear();
-       do {
-               float h, g[2];
-               script("ground", {LuaVariable("height", h)});
-               if (h == -1.0f)
-                       break;
-               if (h > 5000)
-                       h = 5000;
-               script("grass", {LuaVariable("height", g[0])});
-               script("grass", {LuaVariable("height", g[1])});
-               world.data.push_back(WorldData {true, {g[0], g[1]}, h,
-                       static_cast<unsigned char>(randGet() % 32 / 8)});
-       } while (++i);
-
-       // define x-coordinate of world's leftmost 'line'
-       world.startX = HLINES(i * -0.5);
+       world.ground = ObjectTexture(file);
+       auto width = world.ground.getDim().x;
+       world.startX = width / -2;
 
        // gen. star coordinates
        if (stars.empty()) {
                stars.resize(game::SCREEN_WIDTH / 30);
                for (auto& s : stars) {
-                       s.x = world.startX + (randGet() % (int)HLINES(i));
+                       s.x = world.startX + (randGet() % (int)width);
                        s.y = game::SCREEN_HEIGHT - (randGet() % (int)HLINES(game::SCREEN_HEIGHT / 1.3f));
                }
        }
 }
 
+float WorldSystem::getGroundHeight(float x)
+{
+       return world.ground.getHeight((int)(x - world.startX));
+}
+
 float WorldSystem::isAboveGround(const vec2& p) 
 {
-       const auto& gh = world.data[getLineIndex(p.x)].groundHeight;
+       auto gh = getGroundHeight(p.x);
        return p.y >= gh ? 0 : gh;
 }
 
@@ -255,8 +240,7 @@ void WorldSystem::loader(void)
 
                // world generation
                else if (tagName == "generation") {
-                       LuaScript script (wxml->GetText());
-                       generate(script);
+                       generate(wxml->GetText());
                }
 
                // indoor stuff
@@ -421,10 +405,8 @@ void WorldSystem::render(void)
        const vector2<int> backgroundOffset
                (static_cast<int>(SCREEN_WIDTH) / 2, static_cast<int>(SCREEN_HEIGHT) / 2);
 
-       int iStart, iEnd, pOffset;
-
     // world width in pixels
-       int width = HLINES(world.data.size());
+       int width = world.ground.getDim().x;
 
        static std::once_flag init;
        std::call_once(init, [&](void) {
@@ -557,176 +539,30 @@ void WorldSystem::render(void)
                delete[] bgItems;
        }
 
+       vec2 dim;
        if (world.indoor) {
                world.indoorTex.use();
-               auto dim = world.indoorTex.getDim() * game::HLINE;
-               GLfloat verts[] = {
-                       world.startX,         0,         z, 0, 0,
-                       world.startX + dim.x, 0,         z, 1, 0,
-                       world.startX + dim.x, dim.y, z, 1, 1,
-                       world.startX + dim.x, dim.y, z, 1, 1,
-                       world.startX,         dim.y, z, 0, 1,
-                       world.startX,         0,         z, 0, 0,
-               };
-
-               glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), verts);
-               glVertexAttribPointer(Render::worldShader.tex  , 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), verts + 3);
-               glDrawArrays(GL_TRIANGLES, 0, 6);
-       }
-
-       //glUniform1f(Render::worldShader.uniform[WU_light_impact], 0.075f + (0.2f * i));
-       //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
-       //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-
-       // get the line that the player is currently standing on
-       pOffset = (offset.x - world.startX) / game::HLINE;
-
-       // only draw world within player vision
-       iStart = std::clamp(static_cast<int>(pOffset - (SCREEN_WIDTH / 2 / game::HLINE)),
-                           0, static_cast<int>(world.data.size()));
-       iEnd = std::clamp(static_cast<int>(pOffset + (SCREEN_WIDTH / 2 / game::HLINE) + 2),
-                      0, static_cast<int>(world.data.size()));
-
-       // draw the dirt
-       waitToSwap = true;
-
-       bgTex++;
-       z = Render::ZRange::Ground;
-
-       static std::vector<GLfloat> dirt;
-       if (dirt.size() != world.data.size() * 30) {
-               dirt.clear();
-               dirt.resize(world.data.size() * 30);
-       }
-
-       GLfloat *dirtp = &dirt[0];
-       for (int i = iStart; i < iEnd; i++) {
-               int ty = world.data[i].groundHeight / 64 + world.data[i].groundColor;
-               GLfloat five[5] = {
-                       0, 0, world.startX + HLINES(i), world.data[i].groundHeight, z - 0.1f
-               };
-
-               push5(dirtp, five);
-               five[0]++, five[2] += game::HLINE;
-               push5(dirtp, five);
-               five[1] += ty, five[3] = 0;
-               push5(dirtp, five);
-               push5(dirtp, five);
-               five[0]--, five[2] -= game::HLINE;
-               push5(dirtp, five);
-               five[1] = 0, five[3] = world.data[i].groundHeight;
-               push5(dirtp, five);
-       }
-
-       glUniform1f(Render::worldShader.uniform[WU_light_impact], 0.45f);
-
-       glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &dirt[2]);
-       glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &dirt[0]);
-       glDrawArrays(GL_TRIANGLES, 0 , dirt.size() / 5);
-
-       Render::worldShader.disable();
-       Render::worldShader.unuse();
-
-       bgTex++;
-
-       static std::vector<GLfloat> grass;
-       if (grass.size() != world.data.size() * 60) {
-               grass.clear();
-               grass.resize(world.data.size() * 60);
-       }
-
-       GLfloat *grassp = &grass[0];
-       for (int i = iStart; i < iEnd; i++) {
-               auto wd = world.data[i];
-               auto gh = wd.grassHeight;
-
-               // flatten the grass if the player is standing on it.
-               if (!world.indoor && !wd.grassUnpressed) {
-                       gh[0] /= 4;
-                       gh[1] /= 4;
-               }
-
-               // actually draw the grass.
-               if (wd.groundHeight) {
-                       float five[5] = {
-                               0, 1, world.startX + HLINES(i), wd.groundHeight + gh[0], z - 0.2f
-                       };
-
-                       push5(grassp, five);
-                       five[0]++, five[1]--, five[2] += HLINES(0.5f);
-                       push5(grassp, five);
-                       five[1]++, five[3] = wd.groundHeight;
-                       push5(grassp, five);
-                       push5(grassp, five);
-                       five[0]--, five[2] -= HLINES(0.5f);
-                       push5(grassp, five);
-                       five[1]--, five[3] = wd.groundHeight + gh[0];
-                       push5(grassp, five);
-                       five[1]++;
-
-                       five[2] = world.startX + HLINES(i + 0.5), five[3] = wd.groundHeight + gh[1];
-
-                       push5(grassp, five);
-                       five[0]++, five[1]--, five[2] += HLINES(0.5f) + 1;
-                       push5(grassp, five);
-                       five[1]++, five[3] = wd.groundHeight;
-                       push5(grassp, five);
-                       push5(grassp, five);
-                       five[0]--, five[2] -= HLINES(0.5f) + 1;
-                       push5(grassp, five);
-                       five[1]--, five[3] = wd.groundHeight + gh[1];
-                       push5(grassp, five);
-               }
+               dim = world.indoorTex.getDim();
+       } else {
+               world.ground.use();
+               dim = world.ground.getDim();
        }
 
-       Render::worldShader.use();
-       glUniform1f(Render::worldShader.uniform[WU_light_impact], 1.0f);
-
-       Render::worldShader.enable();
-
-       glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &grass[2]);
-       glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &grass[0]);
-       glDrawArrays(GL_TRIANGLES, 0 , grass.size() / 5);
-
-       // the starting pixel of the world
-       static const float s = -(static_cast<float>(SCREEN_WIDTH) / 2.0f);
-       // the ending pixel of the world
-       static const float e = static_cast<float>(SCREEN_WIDTH) / 2.0f;
-       static const float sheight = static_cast<float>(SCREEN_HEIGHT);
-                       
-       auto yOffset = offset.y - static_cast<float>(SCREEN_HEIGHT) / 2.0f;
-       GLfloat blackBar[] = {
-               s,            yOffset,           z - 0.3f, 0.0f, 0.0f,
-               world.startX, yOffset,           z - 0.3f, 1.0f, 0.0f,
-               world.startX, yOffset + sheight, z - 0.3f, 1.0f, 1.0f,
-               world.startX, yOffset + sheight, z - 0.3f, 1.0f, 1.0f,
-               s,            yOffset + sheight, z - 0.3f, 0.0f, 1.0f,
-               s,            yOffset,           z - 0.3f, 0.0f, 0.0f
+       GLfloat verts[] = {
+               world.startX,         0,         z, 0, 0,
+               world.startX + dim.x, 0,         z, 1, 0,
+               world.startX + dim.x, dim.y, z, 1, 1,
+               world.startX + dim.x, dim.y, z, 1, 1,
+               world.startX,         dim.y, z, 0, 1,
+               world.startX,         0,         z, 0, 0,
        };
 
-       if (offset.x + world.startX > s) {
-               Colors::black.use();
-               glUniform1f(Render::worldShader.uniform[WU_light_impact], 0.0f);
-               glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 5, blackBar);
-               glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 5, blackBar + 3);
-               glDrawArrays(GL_TRIANGLES, 0, 6);
-       }
-
-       if (offset.x - world.startX < e) {
-               blackBar[0] = blackBar[20] = blackBar[25] = -world.startX;
-               blackBar[5] = blackBar[10] = blackBar[15] = e;
-
-               Colors::black.use();
-               glUniform1f(Render::worldShader.uniform[WU_light_impact], 0.0f);
-               glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 5, blackBar);
-               glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 5, blackBar + 3);
-               glDrawArrays(GL_TRIANGLES, 0, 6);
-       }
+       glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), verts);
+       glVertexAttribPointer(Render::worldShader.tex  , 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), verts + 3);
+       glDrawArrays(GL_TRIANGLES, 0, 6);
 
        Render::worldShader.disable();
        Render::worldShader.unuse();
-
-       waitToSwap = false;
 }
 
 bool WorldSystem::receive(const BGMToggleEvent &bte)
@@ -781,7 +617,7 @@ void WorldSystem::detect(entityx::TimeDelta dt)
                (void)e;
                if (!g.grounded) {
                        // make sure entity is above ground
-                       auto height = world.data[getLineIndex(loc.x + dim.width / 2)].groundHeight;
+                       auto height = getGroundHeight(loc.x + dim.width / 2);
                        if (loc.y != height) {
                                loc.y = height;
                                e.remove<Grounded>();
@@ -800,25 +636,24 @@ void WorldSystem::detect(entityx::TimeDelta dt)
        game::entities.each<Position, Direction, Solid>(
            [&](entityx::Entity e, Position &loc, Direction &vel, Solid &dim) {
                (void)e;
-               // get the line the entity is on
-               auto line = getLineIndex(loc.x + dim.width / 2);
 
                // make sure entity is above ground
-               if (loc.y < world.data[line].groundHeight) {
-                       int dir = vel.x < 0 ? -1 : 1;
+               auto height = getGroundHeight(loc.x + dim.width / 2);
+               if (loc.y < height) {
+                       /*int dir = vel.x < 0 ? -1 : 1;
                        auto near = std::clamp(line + dir * 2, 0, static_cast<int>(world.data.size()));
                        if (world.data[near].groundHeight - 30 > world.data[line + dir].groundHeight) {
                                loc.x -= (PLAYER_SPEED_CONSTANT + 2.7f) * dir * 2;
                                vel.x = 0;
-                       } else {
-                               loc.y = world.data[line].groundHeight - 0.001f * dt;
+                       } else {*/
+                               loc.y = height - 0.001f * dt;
                                vel.y = 0;
                                if (!vel.grounded) {
                                        vel.grounded = true;
                                        ParticleSystem::addMultiple(20, ParticleType::SmallPoof,
                                                [&](){ return vec2(loc.x + randGet() % static_cast<int>(dim.width), loc.y); }, 500, 30);
                                }
-                       }
+                       //}
                }
 
 
index b2d96a54c92878bf346cf99d24c2afa533509b2d..1b1d52785572ace3af59ae08e0c17aaf14471193 100644 (file)
                <layer path="bg/dirt.png"/>
                <layer path="bg/grass.png"/>
        </style>
-       <generation>
-               x = 0
-
-               ground = function()
-                       if (x == 320) then
-                               height = -1
-                       else
-                               height = 1 / math.pow(2, (x - 50) / 2) + 60 
-                       end
-                       x = x + 1
-               end
-
-               grass = function()
-                       height = math.random(2, 7)
-               end
-       </generation>
+       <generation>assets/testground.png</generation>
        <weather>Sunny</weather>
        <link right="!town2.xml"/>
        <spawnx>-300</spawnx>
@@ -37,7 +22,6 @@
        <structure type="1" position="300.0,100.0"/>
        <structure inside="bobshouse.xml" type="1" position="10.0,100.0"/>
        <skirl />
-       <birb position="-300.0,100.0" />
        <firefly />
 </World>
 
index 9160ef06d46a3699cd5fe6776c772402a83efac2..384af4facfe85cc3a79584aa4e31bff21311751a 100644 (file)
                <layer path="bg/carpet.png"/>
        </style>
        <house width="800" texture="assets/style/classic/bg/insideWoodHouse.png"/>
-       <generation>
-               x = 0
-
-               ground = function()
-                       if (x == 320) then
-                               height = -1
-                       else
-                               height = 60
-                       end
-
-                       x = x + 1
-               end
-
-               grass = function()
-                       height = 2
-               end
-       </generation>
+       <generation>testground.png</generation>
        <time>6000</time>
        <!--<link outside="town.xml"/>-->
        <npc name="Bob" hasDialog="true" spawnx="30"/>