Hosting courtesy of Sourceforge

SourceForge Logo
Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

Moveable.cpp

Go to the documentation of this file.
00001 //
00002 //      Copyright (C) 2002 Robert Renaud
00003 //
00004 //      This program is free software; you can redistribute it and/or
00005 //      modify it under the terms of the GNU General Public License
00006 //      as published by the Free Software Foundation; either version 2
00007 //      of the License, or (at your option) any later version.
00008 //
00009 //      This program is distributed in the hope that it will be useful,
00010 //      but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 //
00013 //      See the GNU General Public License for more details.
00014 //
00015 //      You should have received a copy of the GNU General Public License
00016 //      along with this program; if not, write to the Free Software
00017 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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), // had bug where i called PlaceableItem ctor with map instead of map_ :(
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 

Generated on Tue May 21 07:26:51 2002 for BomberLAN by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001