00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "Moveable.h"
00021
00022 using namespace Game;
00023
00024 std::istream& operator >> (std::istream& in, Game::Direction& d) {
00025 std::string name;
00026 in >> name;
00027 Util::makeLowercase(name);
00028
00029 if (name == "right") d = RIGHT;
00030 else if (name == "left") d = LEFT;
00031 else if (name == "up") d = UP;
00032 else if (name == "down") d = DOWN;
00033
00034 else d = NO_DIRECTION;
00035 return in;
00036 }
00037
00038 PlaceableItem::PlaceableItem(Sint16 startX, Sint16 startY)
00039 {
00040 picPosition.x = startX;
00041 picPosition.y = startY;
00042 picPosition.w = Constants::TILE_WIDTH;
00043 picPosition.h = Constants::TILE_HEIGHT;
00044 }
00045
00046
00047 Sint16 PlaceableItem::getXpixel() const {
00048 return picPosition.x;
00049 }
00050
00051 Sint16 PlaceableItem::getYpixel() const {
00052 return picPosition.y;
00053 }
00054
00055 MoveableItem::MoveableItem(Sint16 startX, Sint16 startY, int speed_) :
00056 PlaceableItem(startX, startY),
00057 speed(speed_),
00058 dir(NO_DIRECTION),
00059 dirIsLocked(false)
00060 {
00061 }
00062
00063 int MoveableItem::getSpeed() {
00064 return speed;
00065 }
00066
00067 void MoveableItem::setSpeed(int newSpeed) {
00068 speed = newSpeed;
00069 }
00070
00071 Direction MoveableItem::getDirection() {
00072 return dir;
00073 }
00074
00075 void MoveableItem::setDirection(Direction d) {
00076 dir = d;
00077 }
00078
00079 void MoveableItem::setXpixel(Sint16 x) {
00080 picPosition.x = x;
00081 }
00082
00083 void MoveableItem::setYpixel(Sint16 y) {
00084 picPosition.y = y;
00085 }
00086
00087 void MoveableItem::move() {
00088 move(getSpeed());
00089 }
00090
00091 void MoveableItem::move(int amount) {
00092 inch(amount, dir);
00093 }
00094
00095 void MoveableItem::inch(int amount, Direction d) {
00096 switch (d) {
00097 case LEFT: picPosition.x -= amount; break;
00098 case RIGHT: picPosition.x += amount; break;
00099 case UP: picPosition.y -= amount; break;
00100 case DOWN: picPosition.y += amount; break;
00101 }
00102 }
00103
00104 void MoveableItem::lockMovement() {
00105 dirIsLocked=true;
00106 }
00107
00108 void MoveableItem::unlockMovement() {
00109 dirIsLocked=false;
00110 }
00111