Hosting courtesy of Sourceforge

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

MapLocation.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 "MapLocation.h"
00021 
00022 using namespace Game;
00023 
00024 int Game::getRightSlack(const SDL_Rect& picPosition)  {
00025         return  (Constants::TILE_WIDTH - getLeftSlack(picPosition)) % Constants::TILE_WIDTH ;
00026 }
00027 
00028 int Game::getLeftSlack(const SDL_Rect& picPosition) {
00029         return picPosition.x % Constants::TILE_WIDTH;
00030 }
00031 
00032 int Game::getUpSlack(const SDL_Rect& picPosition) {
00033         return picPosition.y % Constants::TILE_HEIGHT;
00034 }
00035 
00036 int Game::getDownSlack(const SDL_Rect& picPosition) {
00037         return (Constants::TILE_HEIGHT - getUpSlack(picPosition) ) % Constants::TILE_HEIGHT;
00038 }
00039 
00040 int Game::getDownSlack(Sint16 y) {
00041         return (Constants::TILE_HEIGHT - getUpSlack(y)) % Constants::TILE_HEIGHT;
00042 }
00043 
00044 int Game::getUpSlack(Sint16 y) {
00045         return y % Constants::TILE_HEIGHT;
00046 }
00047 
00048 int Game::getLeftSlack(Sint16 x) {
00049         return x % Constants::TILE_WIDTH;
00050 }
00051 
00052 int Game::getRightSlack(Sint16 x) {
00053         return (Constants::TILE_WIDTH - getLeftSlack(x)) % Constants::TILE_WIDTH;
00054 }
00055 
00056 int Game::getRightTile(Sint16 x, int offset) {
00057         return ((x + Constants::TILE_WIDTH - 1 + offset)/ Constants::TILE_WIDTH);
00058 }
00059 
00060 int Game::getLeftTile(Sint16 x, int offset) {
00061         return (x + offset) / Constants::TILE_WIDTH;
00062 }
00063 
00064 int Game::getUpTile(Sint16 y, int offset) {
00065         return (y + offset) / Constants::TILE_HEIGHT;
00066 }
00067 
00068 int Game::getDownTile(Sint16 y, int offset) {
00069         return (y + Constants::TILE_HEIGHT - 1 + offset) / Constants::TILE_HEIGHT;
00070 }
00071 
00072 Parse::Parser* MapLocation::makeParserToParseMe(std::istream &input) {
00073         Parse::Parser* parser= new Parse::SimpleParser(input);
00074         
00075         parser->addAction("x", new Parse::StdRead<int>(x));
00076         parser->addAction("y", new Parse::StdRead<int>(y));
00077         
00078         return parser;
00079 }
00080 
00081 int Game::getNearestHorizTile(Sint16 xPixel) {
00082         int xLoc = xPixel / Constants::TILE_WIDTH;
00083         if (getLeftSlack(xPixel) > getRightSlack(xPixel)) xLoc++;
00084         return xLoc;
00085 }
00086 
00087 int Game::getNearestVertTile(Sint16 yPixel) {
00088         int yLoc = yPixel / Constants::TILE_HEIGHT;
00089         if (getUpSlack(yPixel) > getDownSlack(yPixel)) yLoc++;
00090         return yLoc;
00091 }
00092 
00093 MapLocation Game::getLocation(const SDL_Rect& rect) {
00094         return MapLocation(getNearestHorizTile(rect.x), getNearestVertTile(rect.y));
00095 }
00096 
00097 MapLocation::MapLocation(const MapLocation &other) :
00098 x(other.x),
00099 y(other.y)
00100 { }
00101 
00102 MapLocation::MapLocation() :
00103 x(-1),
00104 y(-1)
00105 { }
00106 
00107 MapLocation::MapLocation(int x_, int y_) :
00108 x(x_),
00109 y(y_)
00110 { }
00111 
00112 bool MapLocation::operator < (const MapLocation& other) const {
00113         if (x < other.x) return true;
00114         if (y < other.y) return true;
00115         
00116         return false;
00117 }
00118 
00119 bool MapLocation::operator ==(const MapLocation& other) const {
00120         return (x == other.x && y == other.y);
00121 }
00122 
00123 int MapLocation::getMapX() const {
00124         return x;
00125 }
00126 
00127 int MapLocation::getMapY() const {
00128         return y;
00129 }
00130 
00131 MapLocAt::MapLocAt(int xx, int yy) :
00132 x(xx),
00133 y(yy)
00134 { }
00135 
00136 bool MapLocAt::operator()(MapLocation* m) {
00137         return x == m->getMapX() && y == m->getMapY();
00138 }
00139 

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