SimpleAnimation mapSelanAnimation(&mapSelanSprite, (tileSize/walkSpeed) / 2 * 1000, 2, 0, 0, true);
Entity mapSelan;
mapSelan.SetAnimation(&mapSelanAnimation);
+ mapSelan.Position() = Vector<float>(80, 128);
+ mapMaxim.AddFollower(&mapSelan);
SDL_Surface *mapGuyImg(IMG_Load("test-data/guy-map.png"));
Sprite mapGuySprite(mapGuyImg, 32, 64);
SimpleAnimation mapGuyAnimation(&mapGuySprite, (tileSize/walkSpeed) / 2 * 1000, 2, 0, 0, true);
Entity mapGuy;
mapGuy.SetAnimation(&mapGuyAnimation);
+ mapGuy.Position() = Vector<float>(80, 128);
+ mapSelan.AddFollower(&mapGuy);
SDL_Surface *mapDekarImg(IMG_Load("test-data/dekar-map.png"));
Sprite mapDekarSprite(mapDekarImg, 32, 64);
SimpleAnimation mapDekarAnimation(&mapDekarSprite, (tileSize/walkSpeed) / 2 * 1000, 2, 0, 0, true);
Entity mapDekar;
mapDekar.SetAnimation(&mapDekarAnimation);
+ mapDekar.Position() = Vector<float>(80, 128);
+ mapGuy.AddFollower(&mapDekar);
InitScreen screen(width, height);
} else {
MapState *mapState(new MapState(&map));
mapState->AddEntity(&mapMaxim);
+// mapState->AddEntity(&mapSelan);
+// mapState->AddEntity(&mapGuy);
+// mapState->AddEntity(&mapDekar);
mapState->ControlEntity(&mapMaxim);
mapState->SetWalkingSpeed(walkSpeed);
state = mapState;
namespace map {
Entity::Entity()
-: animation(0)
+: follower(0)
+, animation(0)
, orientation(ORIENTATION_NORTH)
, speed(0) {
runner.SetFrameShift(1);
UpdateVelocity();
}
+void Entity::StartAnimation(app::Application &ctrl) {
+ runner.Start(ctrl);
+}
+
+void Entity::StartAnimation(app::State &ctrl) {
+ runner.Start(ctrl);
+}
+
+void Entity::StopAnimation() {
+ runner.Stop();
+}
+
+void Entity::AddFollower(Entity *f) {
+ if (follower) {
+ follower->AddFollower(f);
+ } else {
+ follower = f;
+ }
+}
+
+void Entity::RemoveFollower(Entity *f) {
+ if (follower == f) {
+ follower = follower->follower;
+ } else if (follower) {
+ follower->RemoveFollower(f);
+ }
+}
+
void Entity::SetAnimation(const graphics::Animation *a) {
animation = a;
runner.ChangeAnimation(animation);
const geometry::Vector<float> &Velocity() const { return velocity; }
void SetAnimation(const graphics::Animation *a);
- void StartAnimation(app::Application &ctrl) { runner.Start(ctrl); }
- void StartAnimation(app::State &ctrl) { runner.Start(ctrl); }
- void StopAnimation() { runner.Stop(); }
+ void StartAnimation(app::Application &ctrl);
+ void StartAnimation(app::State &ctrl);
+ void StopAnimation();
bool AnimationRunning() const { return runner.Running(); }
void SetOrientation(Orientation);
Orientation GetOrientation() const { return orientation; }
void SetSpeed(float);
+ Entity *Follower() { return follower; }
+ const Entity *Follower() const { return follower; }
+ void AddFollower(Entity *);
+ void RemoveFollower(Entity *);
+
bool TileLock(int width, int height) const;
void Update(float deltaT);
void Render(SDL_Surface *, const geometry::Vector<int> &offset) const;
private:
- void UpdateVelocity();
+ void UpdateVelocity();;
private:
+ Entity *follower;
const graphics::Animation *animation;
graphics::AnimationRunner runner;
geometry::Vector<float> position;
}
if (nextDirection >= 0) {
if (afterLock) {
+ // FIXME: this check is unreliable, see #21
OnMove();
afterLock = false;
}
void MapState::OnMove() {
// TODO: evaluate monster movements
+ UpdateFollower(controlled);
+}
+
+void MapState::UpdateFollower(Entity *e) {
+ if (!e->Follower()) return;
+ UpdateFollower(e->Follower());
+
+ e->Follower()->SetOrientation(e->GetOrientation());
+ // TODO: set follower speed
}
void OnGridLock();
void OnMove();
+ void UpdateFollower(Entity *);
+
private:
Map *map;
Entity *controlled;