include/World2D.h

00001 
00026 #ifndef _WORLD2D_
00027 #define _WORLD2D_
00028 
00029 #include <Vector2D.h>
00030 #include <Body2D.h>
00031 #include <disableWarnings.h>
00032 
00033 namespace sonus
00034 {
00048         template <class T>
00049         class World2D
00050         {
00051                 public:
00052 
00056                         World2D();
00057 
00063                         World2D( int length );
00064 
00068                         ~World2D();
00069 
00075                         bool setBorder( Body2D<T>* b );
00076 
00082                         Body2D<T>* getBorder();
00083 
00090                         int     pushObstacle( Body2D<T>* b );
00091 
00097                         Body2D<T>*      popObstacle();
00098 
00105                         Body2D<T>* getObstacleAt( int index );
00106 
00110                         void clear();
00111 
00118                         int     getIndexOf( Body2D<T>* b );
00119 
00125                         int     getLength();
00126 
00132                         int     getSize();
00133                         
00134                 private:
00135 
00136                         int                     count;
00137                         int                     length;
00138                         Body2D<T>**     obstacles;
00139                         Body2D<T>*      border;
00140 
00141         };
00142 
00143         template<class T>
00144         World2D<T>::World2D()
00145         {
00146                 this->count = 0;
00147                 this->length = 10;
00148                 this->obstacles = new Body2D<T>*[ length ];
00149         }
00150 
00151         template<class T>
00152         World2D<T>::World2D( int length )
00153         {
00154                 this->count = 0;
00155                 this->length = length;
00156                 this->obstacles = new Body2D<T>*[ length ];
00157         }
00158 
00159         template<class T>
00160         World2D<T>::~World2D()
00161         {
00162                 delete this->obstacles;
00163         }
00164 
00165         template<class T>
00166         bool World2D<T>::setBorder( Body2D<T>* b )
00167         {
00168                 border = b;
00169                 return true;
00170         }
00171 
00172         template<class T>
00173         Body2D<T>* World2D<T>::getBorder()
00174         {
00175                 return border;
00176         }
00177 
00178         template<class T>
00179         int World2D<T>::pushObstacle( Body2D<T>* b )
00180         {
00181                 if ( count < length )
00182                 {
00183                         obstacles[ count++ ] = b;
00184                         return count;
00185                 }
00186                 else
00187                 {
00188                         return -1;
00189                 }
00190         }
00191 
00192         template<class T>
00193         Body2D<T>* World2D<T>::popObstacle()
00194         {
00195                 Body2D<T>* b = obstacles[ --count ];
00196                 obstacles[ count ] = ( Body2D<T>* )0;
00197                 return b;
00198         }
00199 
00200         template<class T>
00201         Body2D<T>* World2D<T>::getObstacleAt( int index )
00202         {
00203                 if ( index <= count )
00204                 {
00205                         return obstacles[ index ];
00206                 }
00207                 else
00208                 {
00209                         return ( Body2D<T>* )0;
00210                 }
00211         }
00212 
00213         template<class T>
00214         void World2D<T>::clear()
00215         {
00216                 for ( int i = 0; i < count; i++ )
00217                 {
00218                         obstacles[ i ] = ( Body2D<T>* )0;
00219                 }
00220                 count = 0;
00221         }
00222 
00223         template<class T>
00224         int World2D<T>::getIndexOf( Body2D<T>* b )
00225         {
00226                 for ( int i = 0; i < count; i++ )
00227                 {
00228                         if ( obstacles[ i ] == b )
00229                         {
00230                                 return i;
00231                         }
00232                 }
00233                 return -1;
00234         }
00235 
00236         template<class T>
00237         int World2D<T>::getLength()
00238         {
00239                 return length;
00240         }
00241 
00242         template<class T>
00243         int World2D<T>::getSize()
00244         {
00245                 return count;
00246         }
00247 
00248 }
00249 
00250 #endif

Generated on Tue Aug 26 12:26:54 2008 for sonus by  doxygen 1.5.4