Allow player movement

This commit is contained in:
Matthias Schiffer 2014-09-23 00:13:05 +02:00
parent c9b41bc102
commit 11e77a9d65
8 changed files with 165 additions and 8 deletions

View file

@ -27,9 +27,17 @@
#pragma once
namespace RPGEdit {
namespace Model {
enum Direction {
NORTH,
EAST,
SOUTH,
WEST,
};
}
}

View file

@ -63,10 +63,31 @@ public:
return dir;
}
void move(float newX, float newY) {
void moveTo(float newX, float newY) {
x = newX;
y = newY;
}
void move(Direction direction, float amount = 1) {
dir = direction;
switch (direction) {
case NORTH:
y -= amount;
break;
case EAST:
x += amount;
break;
case SOUTH:
y += amount;
break;
case WEST:
x -= amount;
}
}
};
}

View file

@ -45,10 +45,10 @@ std::shared_ptr<Map> Map::load(__attribute__((unused)) const std::string &name)
}
}
std::shared_ptr<Entity> square(new Entity("square"));
square->move(6, 6);
map->playerEntity.reset(new Entity("square"));
map->playerEntity->moveTo(6, 6);
map->entities.push_back(square);
map->entities.push_back(map->playerEntity);
return map;
}

View file

@ -46,6 +46,7 @@ private:
size_t width, height;
std::unique_ptr<uint32_t[]> tiles;
std::shared_ptr<Entity> playerEntity;
mutable std::deque<std::shared_ptr<Entity>> entities;
@ -66,6 +67,10 @@ public:
return entities;
}
Entity & getPlayerEntity() const {
return *playerEntity;
}
size_t getWidth() const {
return width;
}