- Timestamp:
- May 21, 2013, 10:00:54 PM (12 years ago)
- Branches:
- master
- Children:
- 5f868c0
- Parents:
- cc1c6c1
- Location:
- common
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
common/WorldMap.cpp
rcc1c6c1 r6e66ffd 67 67 vector<WorldMap::Object> vctObjectsInRegion; 68 68 69 vector<WorldMap::Object>::iterator it; 70 for(it = vctObjects->begin(); it != vctObjects->end(); it++) { 71 if (it->pos.x/25 == x && it->pos.y/25 == y) 72 vctObjectsInRegion.push_back(*it); 73 } 74 69 75 return vctObjectsInRegion; 70 76 } 71 77 72 void WorldMap::addObject(int x, int y, WorldMap::ObjectType t) { 73 WorldMap::Object o(t, x, y); 74 78 // used by the server to create new objects 79 void WorldMap::addObject(WorldMap::ObjectType t, int x, int y) { 80 WorldMap::Object o(t, vctObjects->size(), x, y); 75 81 vctObjects->push_back(o); 82 } 83 84 // used by the client to update object positions or create objects it has not seen before 85 void WorldMap::updateObject(int id, WorldMap::ObjectType t, int x, int y) { 86 vector<WorldMap::Object>::iterator it; 87 bool foundObject = false; 88 89 for (it = vctObjects->begin(); it != vctObjects->end(); it++) { 90 if (it->id == id) { 91 foundObject = true; 92 it->pos.x = x; 93 it->pos.y = y; 94 } 95 } 96 97 if (!foundObject) { 98 WorldMap::Object o(t, id, x, y); 99 vctObjects->push_back(o); 100 } 76 101 } 77 102 … … 190 215 case 1: 191 216 structure = STRUCTURE_BLUE_FLAG; 217 cout << "Should have added blue flag object" << endl; 192 218 break; 193 219 case 2: 194 220 structure = STRUCTURE_RED_FLAG; 221 cout << "Should have added red flag object" << endl; 195 222 break; 196 223 } … … 213 240 /*** Functions for Object ***/ 214 241 215 WorldMap::Object::Object(ObjectType type, POSITION pos) {242 WorldMap::Object::Object(ObjectType type, int id, int x, int y) { 216 243 this->type = type; 217 this->pos = pos; 218 } 219 220 WorldMap::Object::Object(ObjectType type, int x, int y) { 221 this->type = type; 244 this->id = id; 222 245 this->pos.x = x; 223 246 this->pos.y = y; 224 247 } 225 248 249 WorldMap::Object::Object(ObjectType type, int id, POSITION pos) { 250 this->type = type; 251 this->id = id; 252 this->pos = pos; 253 } 254 226 255 WorldMap::Object::~Object() { 227 256 } -
common/WorldMap.h
rcc1c6c1 r6e66ffd 33 33 class Object { 34 34 public: 35 int id; 35 36 ObjectType type; 36 37 POSITION pos; 37 38 38 Object(ObjectType type, int x, int y);39 Object(ObjectType type, POSITION pos);39 Object(ObjectType type, int id, int x, int y); 40 Object(ObjectType type, int id, POSITION pos); 40 41 41 42 ~Object(); … … 58 59 59 60 vector<Object> getObjects(int x, int y); 60 void addObject(int x, int y, ObjectType type); 61 void addObject(ObjectType type, int x, int y); 62 void updateObject(int id, WorldMap::ObjectType t, int x, int y); 61 63 62 64 static WorldMap* createDefaultMap();
Note:
See TracChangeset
for help on using the changeset viewer.