]> git.localhorst.tv Git - l2e.git/commitdiff
implemented map tile anmation
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 30 Jan 2013 11:24:27 +0000 (12:24 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 30 Jan 2013 11:24:27 +0000 (12:24 +0100)
The number of frames can be set per tile via the 'frames' property (which
defaults to 1).
Frame time is currently 512ms, could still need a little tuning.

fixes #27

src/map/Area.cpp
src/map/Area.h
src/map/Map.cpp
src/map/Map.h
src/map/MapState.cpp
src/map/MapState.h
src/map/Tile.cpp
src/map/Tile.h

index a2554c31b2bd01b833171909556d4ee7dd6f3441..91018e5b4a82cf410f328a43d93376c532b7a0d2 100644 (file)
@@ -44,13 +44,19 @@ const Tile *Area::TileAt(const math::Vector<int> &offset) const {
 }
 
 
-void Area::Render(SDL_Surface *dest, const graphics::Sprite *tileset, const Vector<int> &inOffset) const {
+void Area::Render(
+               SDL_Surface *dest,
+               const graphics::Sprite *tileset,
+               const Vector<int> &inOffset,
+               unsigned int frame) const {
        for (int i(0); i < numTiles; ++i) {
                Vector<int> offset(
                                inOffset.X() + (i % width) * tileset->Width(),
                                inOffset.Y() + (i / width) * tileset->Height());
                const Tile &tile(tiles[i]);
-               tileset->Draw(dest, offset, tile.Offset().X(), tile.Offset().Y());
+               tileset->Draw(dest, offset,
+                               tile.Offset().X(),
+                               tile.Offset().Y() + (frame % tile.NumFrames()));
        }
 }
 
index 68f376b42ee120689e83e895a5e22db36b59ebd5..5bdcf0121fdffeeedcc8d1a47b36081d6f493b29 100644 (file)
@@ -40,7 +40,11 @@ public:
        /// Get the default battle background for this area.
        SDL_Surface *BattleBackground() { return battlebg; }
 
-       void Render(SDL_Surface *dest, const graphics::Sprite *tileset, const math::Vector<int> &offset) const;
+       void Render(
+                       SDL_Surface *dest,
+                       const graphics::Sprite *tileset,
+                       const math::Vector<int> &offset,
+                       unsigned int frame) const;
        void RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const math::Vector<int> &offset) const;
 
        static void CreateTypeDescription();
index 682f4f2a8a7f6a43a68cb300db0e7abf36cb2edd..60c319d4a8d8c8fc6a4c0a974c3129ac3a4d176f 100644 (file)
@@ -105,12 +105,15 @@ Vector<int> Map::TileCoordinates(const Vector<int> &position) const {
 }
 
 
-void Map::Render(SDL_Surface *dest, const Vector<int> &inOffset) const {
+void Map::Render(
+               SDL_Surface *dest,
+               const Vector<int> &inOffset,
+               unsigned int frame) const {
        // TODO: skip invisible areas
        for (int i(0); i < numAreas; ++i) {
                const Area &area(areas[i]);
                Vector<int> offset(inOffset + Vector<int>::FromIndex(i, width) * area.Size() * tileset->Size());
-               area.Render(dest, tileset, offset);
+               area.Render(dest, tileset, offset, frame);
        }
 }
 
index c86b0ace9dc5bfd25dec749e57765ee2b3fb54bf..e0a95dd9bca2d062447249a1b9a88b02ae3dfd5f 100644 (file)
@@ -58,7 +58,10 @@ public:
 
        /// Render the map.
        /// Entities are not rendered by this function.
-       void Render(SDL_Surface *dest, const math::Vector<int> &offset) const;
+       void Render(
+                       SDL_Surface *dest,
+                       const math::Vector<int> &offset,
+                       unsigned int frame) const;
        /// Render a debugging overlay that includes collision and trigger
        /// information.
        void RenderDebug(SDL_Surface *dest, const math::Vector<int> &offset) const;
index 9bae990ce6d72c053ce1b252a48a121cf49d0f67..b8b5eb629d8601a2de2ce2a4a03044df9b28fcad 100644 (file)
@@ -44,6 +44,7 @@ MapState::MapState(GameConfig *g, Map *map)
 
 void MapState::OnEnterState(SDL_Surface *screen) {
        camera.Resize(screen->w, screen->h);
+       tileAnimation = GraphicsTimers().StartInterval(512);
        LoadMap(map);
 }
 
@@ -463,7 +464,7 @@ void MapState::Render(SDL_Surface *screen) {
        SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
 
        Vector<int> offset(camera.CalculateOffset());
-       map->Render(screen, offset);
+       map->Render(screen, offset, tileAnimation.Iteration());
 
        if (debug) {
                map->RenderDebug(screen, offset);
index 2465ddf3526ea80e72ca7683388d02d49c2a3ed3..1901a67afc4b27f0f18943c4ceab2db4aa8a8eaf 100644 (file)
@@ -11,6 +11,7 @@ namespace map {
 
 #include "Entity.h"
 #include "../app/State.h"
+#include "../app/Timer.h"
 #include "../common/ScriptHost.h"
 #include "../common/ScriptRunner.h"
 #include "../math/Fixed.h"
@@ -93,6 +94,7 @@ private:
        graphics::Camera camera;
        std::vector<Entity *> entities;
        math::Fixed<8> walkingSpeed;
+       app::Timer<Uint32> tileAnimation;
        int nextDirection;
        bool afterLock;
        bool skipLock;
index d621747996a0a70c7261ce215ed28139f0c9f3a4..2b7e0f23bb2a56117b63166fe572605581dca548 100644 (file)
@@ -11,7 +11,8 @@ namespace map {
 
 Tile::Tile()
 : battlebg(0)
-, flags(0) {
+, flags(0)
+, frames(1) {
 
 }
 
@@ -26,6 +27,7 @@ void Tile::CreateTypeDescription() {
        td.AddField("battlebg", FieldDescription(((char *)&t.battlebg) - ((char *)&t), Interpreter::IMAGE_ID).SetReferenced());
        td.AddField("t", FieldDescription(((char *)&t.offset) - ((char *)&t), Interpreter::VECTOR_ID));
        td.AddField("flags", FieldDescription(((char *)&t.flags) - ((char *)&t), Interpreter::NUMBER_ID));
+       td.AddField("frames", FieldDescription(((char *)&t.frames) - ((char *)&t), Interpreter::NUMBER_ID));
 
 }
 
index 137da43c02b30faff6ec6b92b70b98e2ef072469..34481f315e01119af4ff50fbc2c9ee670a6f274d 100644 (file)
@@ -36,6 +36,8 @@ public:
 
        bool IsLadder() const { return flags & LADDER; }
 
+       int NumFrames() const { return frames; }
+
        static void CreateTypeDescription();
        static void Construct(void *);
 
@@ -48,6 +50,7 @@ private:
        SDL_Surface *battlebg;
        math::Vector<int> offset;
        int flags;
+       int frames;
 
 };