From: Daniel Karbach Date: Wed, 20 Mar 2013 18:06:30 +0000 (+0100) Subject: better accessibility of map-related properties X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=abfa371d1d2c14052d4cbfc885b8383c6da7d499;p=l2e.git better accessibility of map-related properties also fixed a typo --- diff --git a/src/graphics/Camera.h b/src/graphics/Camera.h index ea4e6d5..7403d6f 100644 --- a/src/graphics/Camera.h +++ b/src/graphics/Camera.h @@ -15,6 +15,7 @@ public: public: void Resize(int w, int h) { halfWidth = w / 2; halfHeight = h / 2; } void SetTarget(const math::Vector > *t); + const math::Vector > *GetTarget() const { return target; } math::Vector CalculateOffset() const; diff --git a/src/map/Map.cpp b/src/map/Map.cpp index 85fbd22..ed6cc06 100644 --- a/src/map/Map.cpp +++ b/src/map/Map.cpp @@ -104,6 +104,10 @@ Vector Map::TileCoordinates(const Vector &position) const { return position / tileset->Size(); } +Vector Map::PixelCoordinates(const Vector &position) const { + return position * tileset->Size(); +} + void Map::Render( SDL_Surface *dest, diff --git a/src/map/Map.h b/src/map/Map.h index e0a95dd..6b2eea4 100644 --- a/src/map/Map.h +++ b/src/map/Map.h @@ -21,8 +21,8 @@ namespace map { /// 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. @@ -50,8 +50,10 @@ public: /// The battle background image for this map if neither the tile nor the /// area has one specified. SDL_Surface *BattleBackgroundAt(const math::Vector &); - /// Convert coordinates pixel to tile. + /// Convert coordinates from pixel to tile. math::Vector TileCoordinates(const math::Vector &) const; + /// Convert coordinates from tile to pixel. + math::Vector PixelCoordinates(const math::Vector &) const; Entity *EntitiesBegin() { return entities; } Entity *EntitiesEnd() { return entities + numEntities; } diff --git a/src/map/MapState.cpp b/src/map/MapState.cpp index b8b5eb6..0e0a3ee 100644 --- a/src/map/MapState.cpp +++ b/src/map/MapState.cpp @@ -43,7 +43,7 @@ MapState::MapState(GameConfig *g, Map *map) void MapState::OnEnterState(SDL_Surface *screen) { - camera.Resize(screen->w, screen->h); + OnResize(screen->w, screen->h); tileAnimation = GraphicsTimers().StartInterval(512); LoadMap(map); } @@ -53,7 +53,7 @@ void MapState::OnExitState(SDL_Surface *screen) { } void MapState::OnResumeState(SDL_Surface *screen) { - camera.Resize(screen->w, screen->h); + OnResize(screen->w, screen->h); } void MapState::OnPauseState(SDL_Surface *screen) { diff --git a/src/map/MapState.h b/src/map/MapState.h index 1901a67..b243c3b 100644 --- a/src/map/MapState.h +++ b/src/map/MapState.h @@ -38,7 +38,11 @@ public: 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 > *t) { camera.SetTarget(t); } + void TrackControlled() { if (controlled) Track(&controlled->Position()); } + + math::Vector > TrackPoint() const { return *camera.GetTarget(); } void SetWalkingSpeed(math::Fixed<8> s) { walkingSpeed = s; } @@ -46,6 +50,9 @@ public: 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);