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 00021 #ifndef TILE_H_ 00022 #define TILE_H_ 00023 00024 #include "../Config.h" 00025 #include "GameDebug.h" 00026 #include "Moveable.h" 00027 #include "../Graphics/draw.h" 00028 #include "../Parse/ListParser.h" 00029 00030 #include <vector> 00031 #include <fstream> 00032 00033 namespace Game { 00034 00036 class MovementEffect { 00037 public: 00038 MovementEffect(Sint16 x, Sint16 y, bool relative=true); 00039 00041 Sint16 getXchange() const; 00043 Sint16 getYchange() const; 00044 00048 bool isRelative() const; 00049 private: 00050 Sint16 x; 00051 Sint16 y; 00052 bool motionIsRelative; 00053 }; 00054 00056 class AbstractTile : public Graphics::DrawableAt, public Parse::Parseable { 00057 public: 00058 AbstractTile(); 00062 virtual bool isPassable() const=0; 00063 00065 virtual void hitWithExplosion() { } 00066 00075 virtual MovementEffect AbstractTile::effect(MoveableItem& item); 00076 00077 void occupy(); 00078 void deOccupy(); 00079 00080 bool isOccupied() const; 00081 00082 virtual ~AbstractTile(); 00083 00085 virtual AbstractTile* dynCopy() const=0; 00086 private: 00087 bool currentlyOccupied; 00088 }; 00089 00094 class SingleImageTile : public AbstractTile { 00095 public: 00096 SingleImageTile(); 00097 00099 SingleImageTile(Graphics::AbstractImage* image); 00100 virtual ~SingleImageTile(); 00101 00105 Parse::Parser* makeParserToParseMe(istream &inputFile); 00106 void drawAt(SDL_Surface *screen, SDL_Rect *loc); 00107 00108 void setImage(Graphics::AbstractImage* image); 00109 protected: 00110 Graphics::AbstractImage* img; 00111 }; 00112 00114 class IndestructibleTile : public SingleImageTile { 00115 public: 00116 virtual ~IndestructibleTile() { } 00117 00118 bool isPassable() const; 00119 AbstractTile* dynCopy() const; 00120 }; 00121 00123 class PassableTile: public SingleImageTile { 00124 public: 00125 virtual ~PassableTile() { } 00126 00127 AbstractTile* dynCopy() const; 00128 bool isPassable() const; 00129 }; 00130 00135 class ExplodableTile: public AbstractTile { 00136 public: 00137 ExplodableTile(); 00138 ~ExplodableTile(); 00139 00140 bool isPassable() const; 00141 void hitWithExplosion(); 00142 00147 Parse::Parser* makeParserToParseMe(std::istream &input); 00148 00149 void drawAt(SDL_Surface * screen, SDL_Rect * loc); 00150 00151 AbstractTile* dynCopy() const; 00152 private: 00153 bool hasExploded; 00154 Graphics::AbstractImage* bombedImage; 00155 Graphics::AbstractImage* unbombedImage; 00156 }; 00157 00159 class ConveyorTile: public AbstractTile { 00160 public: 00161 ConveyorTile(); 00162 ~ConveyorTile(); 00163 00164 bool isPassable() const; 00165 00174 Parse::Parser* makeParserToParseMe(std::istream& input); 00175 00177 virtual MovementEffect effect(MoveableItem& m); 00178 00179 void drawAt(SDL_Surface* surf, SDL_Rect* loc); 00180 00181 AbstractTile* dynCopy() const; 00182 private: 00183 Graphics::AbstractImage* img; 00184 Sint16 xSpeed; 00185 Sint16 ySpeed; 00186 }; 00187 00191 class SlipperyTile: public AbstractTile { 00192 public: 00193 SlipperyTile(); 00194 ~SlipperyTile(); 00195 00199 MovementEffect effect(MoveableItem& p); 00200 00202 bool isPassable() const; 00203 00204 AbstractTile* dynCopy() const; 00205 void drawAt(SDL_Surface* surf, SDL_Rect* loc); 00206 00213 Parse::Parser* makeParserToParseMe(std::istream& in); 00214 private: 00215 Graphics::AbstractImage* front; 00216 Graphics::AbstractImage* back; 00217 }; 00218 00222 class TileSetReader : public Parse::Parseable { 00223 public: 00224 TileSetReader(); 00225 ~TileSetReader(); 00226 Game::AbstractTile* copyTile(int index) const; 00227 Game::AbstractTile* getTile(int index); 00228 // friend std::ostream& operator << (std::ostream& o, const TileSet& ts); 00229 int numTiles() const; 00230 Parse::Parser* makeParserToParseMe(std::istream&); 00231 private: 00232 // throws if index is invalid 00233 void validateIndex(int index) const; 00234 std::vector<AbstractTile*> tileVec; 00235 }; 00236 00237 }; // namespace Game 00238 00239 //std::ostream& operator << (std::ostream& o, const TileSet &ts); 00240 00241 #endif // ifndef TILE_H_ 00242
1.2.12 written by Dimitri van Heesch,
© 1997-2001