From: Daniel Karbach Date: Wed, 30 Jan 2013 11:24:27 +0000 (+0100) Subject: implemented map tile anmation X-Git-Url: http://git.localhorst.tv/?p=l2e.git;a=commitdiff_plain;h=d97b7038c28058a76e7214e0dce0394fd8b67cff implemented map tile anmation 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 --- diff --git a/src/map/Area.cpp b/src/map/Area.cpp index a2554c3..91018e5 100644 --- a/src/map/Area.cpp +++ b/src/map/Area.cpp @@ -44,13 +44,19 @@ const Tile *Area::TileAt(const math::Vector &offset) const { } -void Area::Render(SDL_Surface *dest, const graphics::Sprite *tileset, const Vector &inOffset) const { +void Area::Render( + SDL_Surface *dest, + const graphics::Sprite *tileset, + const Vector &inOffset, + unsigned int frame) const { for (int i(0); i < numTiles; ++i) { Vector 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())); } } diff --git a/src/map/Area.h b/src/map/Area.h index 68f376b..5bdcf01 100644 --- a/src/map/Area.h +++ b/src/map/Area.h @@ -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 &offset) const; + void Render( + SDL_Surface *dest, + const graphics::Sprite *tileset, + const math::Vector &offset, + unsigned int frame) const; void RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const math::Vector &offset) const; static void CreateTypeDescription(); diff --git a/src/map/Map.cpp b/src/map/Map.cpp index 682f4f2..60c319d 100644 --- a/src/map/Map.cpp +++ b/src/map/Map.cpp @@ -105,12 +105,15 @@ Vector Map::TileCoordinates(const Vector &position) const { } -void Map::Render(SDL_Surface *dest, const Vector &inOffset) const { +void Map::Render( + SDL_Surface *dest, + const Vector &inOffset, + unsigned int frame) const { // TODO: skip invisible areas for (int i(0); i < numAreas; ++i) { const Area &area(areas[i]); Vector offset(inOffset + Vector::FromIndex(i, width) * area.Size() * tileset->Size()); - area.Render(dest, tileset, offset); + area.Render(dest, tileset, offset, frame); } } diff --git a/src/map/Map.h b/src/map/Map.h index c86b0ac..e0a95dd 100644 --- a/src/map/Map.h +++ b/src/map/Map.h @@ -58,7 +58,10 @@ public: /// Render the map. /// Entities are not rendered by this function. - void Render(SDL_Surface *dest, const math::Vector &offset) const; + void Render( + SDL_Surface *dest, + const math::Vector &offset, + unsigned int frame) const; /// Render a debugging overlay that includes collision and trigger /// information. void RenderDebug(SDL_Surface *dest, const math::Vector &offset) const; diff --git a/src/map/MapState.cpp b/src/map/MapState.cpp index 9bae990..b8b5eb6 100644 --- a/src/map/MapState.cpp +++ b/src/map/MapState.cpp @@ -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 offset(camera.CalculateOffset()); - map->Render(screen, offset); + map->Render(screen, offset, tileAnimation.Iteration()); if (debug) { map->RenderDebug(screen, offset); diff --git a/src/map/MapState.h b/src/map/MapState.h index 2465ddf..1901a67 100644 --- a/src/map/MapState.h +++ b/src/map/MapState.h @@ -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 entities; math::Fixed<8> walkingSpeed; + app::Timer tileAnimation; int nextDirection; bool afterLock; bool skipLock; diff --git a/src/map/Tile.cpp b/src/map/Tile.cpp index d621747..2b7e0f2 100644 --- a/src/map/Tile.cpp +++ b/src/map/Tile.cpp @@ -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)); } diff --git a/src/map/Tile.h b/src/map/Tile.h index 137da43..34481f3 100644 --- a/src/map/Tile.h +++ b/src/map/Tile.h @@ -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 offset; int flags; + int frames; };