public:
void Resize(int w, int h) { halfWidth = w / 2; halfHeight = h / 2; }
void SetTarget(const math::Vector<math::Fixed<8> > *t);
+ const math::Vector<math::Fixed<8> > *GetTarget() const { return target; }
math::Vector<int> CalculateOffset() const;
return position / tileset->Size();
}
+Vector<int> Map::PixelCoordinates(const Vector<int> &position) const {
+ return position * tileset->Size();
+}
+
void Map::Render(
SDL_Surface *dest,
/// Maps are made up of uniform areas of tiles.
/// The looks of a tile is defined by the Tileset() sprite with Tile::Offset()
/// as the column and row in the sprite.
-/// Maps can be propulated with triggers and entities. Those are or use with
-/// MapState and are not handled by the map itself.
+/// Maps can be propulated with triggers and entities. Those are for use with
+/// a MapState and are not handled by the map itself.
/// Positions are expressed either as pixel or tile coordinates depending on
/// function purpose with (0|0) being the top left corner and positive values
/// extending to the right and down respectively.
/// The battle background image for this map if neither the tile nor the
/// area has one specified.
SDL_Surface *BattleBackgroundAt(const math::Vector<int> &);
- /// Convert coordinates pixel to tile.
+ /// Convert coordinates from pixel to tile.
math::Vector<int> TileCoordinates(const math::Vector<int> &) const;
+ /// Convert coordinates from tile to pixel.
+ math::Vector<int> PixelCoordinates(const math::Vector<int> &) const;
Entity *EntitiesBegin() { return entities; }
Entity *EntitiesEnd() { return entities + numEntities; }
void MapState::OnEnterState(SDL_Surface *screen) {
- camera.Resize(screen->w, screen->h);
+ OnResize(screen->w, screen->h);
tileAnimation = GraphicsTimers().StartInterval(512);
LoadMap(map);
}
}
void MapState::OnResumeState(SDL_Surface *screen) {
- camera.Resize(screen->w, screen->h);
+ OnResize(screen->w, screen->h);
}
void MapState::OnPauseState(SDL_Surface *screen) {
public:
void AddEntity(Entity *e) { entities.push_back(e); }
- void ControlEntity(Entity *e) { controlled = e; camera.SetTarget(&e->Position()); }
+ void ControlEntity(Entity *e) { controlled = e; TrackControlled(); }
+ void Track(math::Vector<math::Fixed<8> > *t) { camera.SetTarget(t); }
+ void TrackControlled() { if (controlled) Track(&controlled->Position()); }
+
+ math::Vector<math::Fixed<8> > TrackPoint() const { return *camera.GetTarget(); }
void SetWalkingSpeed(math::Fixed<8> s) { walkingSpeed = s; }
virtual void HandleSyscall(common::ScriptRunner &);
+ const graphics::Camera &GetCamera() const { return camera; }
+ Map *GetMap() { return map; }
+
private:
virtual void OnEnterState(SDL_Surface *screen);
virtual void OnExitState(SDL_Surface *screen);