From: Daniel Karbach Date: Sun, 30 Sep 2012 14:50:17 +0000 (+0200) Subject: check tile lock in Entity X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=657eed00ae73b8d06470cec0d955aeada537a90d;p=l2e.git check tile lock in Entity --- diff --git a/src/map/Entity.cpp b/src/map/Entity.cpp index 01cbe7f..c14c9a0 100644 --- a/src/map/Entity.cpp +++ b/src/map/Entity.cpp @@ -7,6 +7,8 @@ #include "Entity.h" +using geometry::Vector; + namespace map { Entity::Entity() @@ -15,12 +17,20 @@ Entity::Entity() } +bool Entity::TileLock(int width, int height) const { + Vector tilePosition( + position.X() - (width / 2), + position.Y() - height); + return (tilePosition.X() % width == 0) && (tilePosition.Y() % height == 0); +} + + void Entity::Update(float deltaT) { position += velocity * deltaT; } -void Entity::Render(SDL_Surface *dest, const geometry::Vector &offset) const { +void Entity::Render(SDL_Surface *dest, const Vector &offset) const { if (animation.Running()) { animation.DrawCenterBottom(dest, offset + position); } else { diff --git a/src/map/Entity.h b/src/map/Entity.h index fd91f3e..d6ba5f3 100644 --- a/src/map/Entity.h +++ b/src/map/Entity.h @@ -34,6 +34,8 @@ public: graphics::AnimationRunner &Animation() { return animation; } const graphics::AnimationRunner &Animation() const { return animation; } + bool TileLock(int width, int height) const; + void Update(float deltaT); void Render(SDL_Surface *, const geometry::Vector &offset) const; diff --git a/src/map/Map.h b/src/map/Map.h index 5733760..92c866b 100644 --- a/src/map/Map.h +++ b/src/map/Map.h @@ -23,6 +23,8 @@ public: ~Map() { } public: + const graphics::Sprite *Tileset() const { return tileset; } + void Render(SDL_Surface *dest, const geometry::Vector &offset) const; // temporary setters diff --git a/src/map/MapState.cpp b/src/map/MapState.cpp index 7f602a7..5477999 100644 --- a/src/map/MapState.cpp +++ b/src/map/MapState.cpp @@ -51,6 +51,7 @@ void MapState::Resize(int width, int height) { void MapState::HandleEvents(const Input &input) { if (!controlled) return; + if (!controlled->TileLock(map->Tileset()->Width(), map->Tileset()->Height())) return; } void MapState::UpdateWorld(float deltaT) {