}
-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()));
}
}
/// 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();
}
-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);
}
}
/// 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;
void MapState::OnEnterState(SDL_Surface *screen) {
camera.Resize(screen->w, screen->h);
+ tileAnimation = GraphicsTimers().StartInterval(512);
LoadMap(map);
}
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);
#include "Entity.h"
#include "../app/State.h"
+#include "../app/Timer.h"
#include "../common/ScriptHost.h"
#include "../common/ScriptRunner.h"
#include "../math/Fixed.h"
graphics::Camera camera;
std::vector<Entity *> entities;
math::Fixed<8> walkingSpeed;
+ app::Timer<Uint32> tileAnimation;
int nextDirection;
bool afterLock;
bool skipLock;
Tile::Tile()
: battlebg(0)
-, flags(0) {
+, flags(0)
+, frames(1) {
}
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));
}
bool IsLadder() const { return flags & LADDER; }
+ int NumFrames() const { return frames; }
+
static void CreateTypeDescription();
static void Construct(void *);
SDL_Surface *battlebg;
math::Vector<int> offset;
int flags;
+ int frames;
};