#include <Map.h>
| Public Member Functions | |
| Map () | |
| ~Map () | |
| void | SetMax (int, int) | 
| int | GetMaxX () | 
| int | GetMaxY () | 
| double | GetNearest (double x, double y) | 
| void | SetWraps (bool x=true) | 
| bool | GetWraps () | 
| void | AddObject (MapObject *p, bool delete_by_map=true) | 
| void | IncreaseTime (long usec) | 
| void | SpawnRandom () | 
| size_t | objects_in_map () | 
| Private Attributes | |
| int | m_max_x | 
| int | m_max_y | 
| bool | m_wraps | 
| mapobject_v | m_objects | 
Definition at line 7 of file Map.h.
| Map::Map | ( | ) | 
| Map::~Map | ( | ) | 
| void Map::SetMax | ( | int | , | |
| int | ||||
| ) | 
| int Map::GetMaxX | ( | ) |  [inline] | 
| int Map::GetMaxY | ( | ) |  [inline] | 
| double Map::GetNearest | ( | double | x, | |
| double | y | |||
| ) | 
Definition at line 85 of file Map.cpp.
References m_max_x, m_max_y, and m_objects.
Referenced by SpawnRandom().
00086 { 00087 double dist = m_max_x * m_max_y; 00088 for (mapobject_v::iterator it = m_objects.begin(); it != m_objects.end(); it++) 00089 { 00090 MapObject *p = *it; 00091 double x1 = p -> GetX() - x; 00092 double x2 = x - p -> GetX(); 00093 if (x1 < m_max_x) 00094 x1 += m_max_x; 00095 if (x2 < m_max_x) 00096 x2 += m_max_x; 00097 double y1 = p -> GetY() - y; 00098 double y2 = y - p -> GetY(); 00099 if (y1 < m_max_y) 00100 y1 += m_max_y; 00101 if (y2 < m_max_y) 00102 y2 += m_max_y; 00103 double xx = (x1 < x2) ? x1 : x2; 00104 double yy = (y1 < y2) ? y1 : y2; 00105 double d = sqrt(xx * xx + yy * yy); 00106 if (d < dist) 00107 dist = d; 00108 } 00109 return dist; 00110 }
| void Map::SetWraps | ( | bool | x = true | ) |  [inline] | 
| bool Map::GetWraps | ( | ) |  [inline] | 
| void Map::AddObject | ( | MapObject * | p, | |
| bool | delete_by_map = true | |||
| ) | 
Definition at line 37 of file Map.cpp.
References m_objects.
Referenced by RowoHandler::InjectRobot(), and main().
00038 { 00039 m_objects.push_back(p); 00040 p -> SetDeleteByMap(delete_by_map); 00041 printf("New object added - new map size is %d object%s\n",m_objects.size(),(m_objects.size() == 1) ? "" : "s"); 00042 }
| void Map::IncreaseTime | ( | long | usec | ) | 
Definition at line 45 of file Map.cpp.
References m_objects.
Referenced by main().
00046 { 00047 for (mapobject_v::iterator it = m_objects.begin(); it != m_objects.end(); it++) 00048 { 00049 MapObject *p0 = *it; 00050 Robot *p = dynamic_cast<Robot *>(p0); 00051 if (p) 00052 { 00053 p -> Tick( usec ); 00054 p -> Call("Main"); 00055 } 00056 } 00057 }
| void Map::SpawnRandom | ( | ) | 
Definition at line 60 of file Map.cpp.
References GetNearest(), m_max_x, m_max_y, and m_objects.
Referenced by main().
00061 { 00062 MapObject *p = NULL; 00063 switch (random() % 2) 00064 { 00065 case 0: // powerup 00066 p = new Powerup( *this ); 00067 break; 00068 case 1: // item 00069 p = new Item( *this ); 00070 break; 00071 } 00072 p -> SetPos(random() % m_max_x,random() % m_max_y); 00073 double dist = GetNearest(p -> GetX(),p -> GetY()); 00074 if (dist > 20) 00075 { 00076 m_objects.push_back( p ); 00077 } 00078 else 00079 { 00080 delete p; 00081 } 00082 }
| size_t Map::objects_in_map | ( | ) |  [inline] | 
| int Map::m_max_x  [private] | 
Definition at line 27 of file Map.h.
Referenced by GetMaxX(), GetNearest(), SetMax(), and SpawnRandom().
| int Map::m_max_y  [private] | 
Definition at line 28 of file Map.h.
Referenced by GetMaxY(), GetNearest(), SetMax(), and SpawnRandom().
| bool Map::m_wraps  [private] | 
| mapobject_v Map::m_objects  [private] | 
Definition at line 30 of file Map.h.
Referenced by AddObject(), GetNearest(), IncreaseTime(), objects_in_map(), SpawnRandom(), and ~Map().
 1.3.6
 
1.3.6