From c03b01f2a152927227a674d462794604aa08e5dd Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Sun, 30 Sep 2012 16:25:20 +0200 Subject: [PATCH] added Entity class --- Debug/src/map/subdir.mk | 3 +++ Release/src/map/subdir.mk | 3 +++ src/map/Entity.cpp | 31 ++++++++++++++++++++++++ src/map/Entity.h | 51 +++++++++++++++++++++++++++++++++++++++ src/map/fwd.h | 1 + 5 files changed, 89 insertions(+) create mode 100644 src/map/Entity.cpp create mode 100644 src/map/Entity.h diff --git a/Debug/src/map/subdir.mk b/Debug/src/map/subdir.mk index b90f2b1..fa93078 100644 --- a/Debug/src/map/subdir.mk +++ b/Debug/src/map/subdir.mk @@ -5,18 +5,21 @@ # Add inputs and outputs from these tool invocations to the build variables CPP_SRCS += \ ../src/map/Area.cpp \ +../src/map/Entity.cpp \ ../src/map/Map.cpp \ ../src/map/MapState.cpp \ ../src/map/Tile.cpp OBJS += \ ./src/map/Area.o \ +./src/map/Entity.o \ ./src/map/Map.o \ ./src/map/MapState.o \ ./src/map/Tile.o CPP_DEPS += \ ./src/map/Area.d \ +./src/map/Entity.d \ ./src/map/Map.d \ ./src/map/MapState.d \ ./src/map/Tile.d diff --git a/Release/src/map/subdir.mk b/Release/src/map/subdir.mk index 7fa8f6a..25e2b82 100644 --- a/Release/src/map/subdir.mk +++ b/Release/src/map/subdir.mk @@ -5,18 +5,21 @@ # Add inputs and outputs from these tool invocations to the build variables CPP_SRCS += \ ../src/map/Area.cpp \ +../src/map/Entity.cpp \ ../src/map/Map.cpp \ ../src/map/MapState.cpp \ ../src/map/Tile.cpp OBJS += \ ./src/map/Area.o \ +./src/map/Entity.o \ ./src/map/Map.o \ ./src/map/MapState.o \ ./src/map/Tile.o CPP_DEPS += \ ./src/map/Area.d \ +./src/map/Entity.d \ ./src/map/Map.d \ ./src/map/MapState.d \ ./src/map/Tile.d diff --git a/src/map/Entity.cpp b/src/map/Entity.cpp new file mode 100644 index 0000000..01cbe7f --- /dev/null +++ b/src/map/Entity.cpp @@ -0,0 +1,31 @@ +/* + * Entity.cpp + * + * Created on: Sep 29, 2012 + * Author: holy + */ + +#include "Entity.h" + +namespace map { + +Entity::Entity() +: sprite(0) { + +} + + +void Entity::Update(float deltaT) { + position += velocity * deltaT; +} + + +void Entity::Render(SDL_Surface *dest, const geometry::Vector &offset) const { + if (animation.Running()) { + animation.DrawCenterBottom(dest, offset + position); + } else { + sprite->DrawCenterBottom(dest, offset + position); + } +} + +} diff --git a/src/map/Entity.h b/src/map/Entity.h new file mode 100644 index 0000000..fd91f3e --- /dev/null +++ b/src/map/Entity.h @@ -0,0 +1,51 @@ +/* + * Entity.h + * + * Created on: Sep 29, 2012 + * Author: holy + */ + +#ifndef MAP_ENTITY_H_ +#define MAP_ENTITY_H_ + +#include "../geometry/Vector.h" +#include "../graphics/fwd.h" +#include "../graphics/Animation.h" + +#include +#include + +namespace map { + +class Entity { + +public: + Entity(); + ~Entity() { } + +public: + geometry::Vector &Position() { return position; } + const geometry::Vector &Position() const { return position; } + + geometry::Vector &Velocity() { return velocity; } + const geometry::Vector &Velocity() const { return velocity; } + + void SetSprite(const graphics::Sprite *s) { sprite = s; } + graphics::AnimationRunner &Animation() { return animation; } + const graphics::AnimationRunner &Animation() const { return animation; } + + void Update(float deltaT); + + void Render(SDL_Surface *, const geometry::Vector &offset) const; + +private: + const graphics::Sprite *sprite; + graphics::AnimationRunner animation; + geometry::Vector position; + geometry::Vector velocity; + +}; + +} + +#endif /* MAP_ENTITY_H_ */ diff --git a/src/map/fwd.h b/src/map/fwd.h index 5ff828b..a9d1e2e 100644 --- a/src/map/fwd.h +++ b/src/map/fwd.h @@ -11,6 +11,7 @@ namespace map { class Area; +class Entity; class Map; class MapState; class Tile; -- 2.39.2