Changeset 6e66ffd in network-game
- Timestamp:
- May 21, 2013, 10:00:54 PM (12 years ago)
- Branches:
- master
- Children:
- 5f868c0
- Parents:
- cc1c6c1
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/main.cpp
rcc1c6c1 r6e66ffd 530 530 mapPos.y = 0; 531 531 mapPos = mapToScreen(mapPos); 532 532 533 for (int x=0; x<12; x++) 533 534 { … … 544 545 al_draw_filled_rectangle(x*25+mapPos.x, y*25+mapPos.y, x*25+25+mapPos.x, y*25+25+mapPos.y, al_map_rgb(100, 100, 0)); 545 546 546 if (structure == WorldMap::STRUCTURE_BLUE_FLAG) 547 al_draw_filled_rectangle(x*25+5+mapPos.x, y*25+5+mapPos.y, x*25+20+mapPos.x, y*25+20+mapPos.y, al_map_rgb(0, 0, 255)); 548 else if (structure == WorldMap::STRUCTURE_RED_FLAG) 549 al_draw_filled_rectangle(x*25+5+mapPos.x, y*25+5+mapPos.y, x*25+20+mapPos.x, y*25+20+mapPos.y, al_map_rgb(255, 0, 0)); 547 if (structure == WorldMap::STRUCTURE_BLUE_FLAG) { 548 al_draw_circle(x*25+12+mapPos.x, y*25+12+mapPos.y, 12, al_map_rgb(0, 0, 0), 3); 549 //al_draw_filled_rectangle(x*25+5+mapPos.x, y*25+5+mapPos.y, x*25+20+mapPos.x, y*25+20+mapPos.y, al_map_rgb(0, 0, 255)); 550 }else if (structure == WorldMap::STRUCTURE_RED_FLAG) { 551 al_draw_circle(x*25+12+mapPos.x, y*25+12+mapPos.y, 12, al_map_rgb(0, 0, 0), 3); 552 //al_draw_filled_rectangle(x*25+5+mapPos.x, y*25+5+mapPos.y, x*25+20+mapPos.x, y*25+20+mapPos.y, al_map_rgb(255, 0, 0)); 553 } 554 } 555 } 556 557 for (int x=0; x<12; x++) 558 { 559 for (int y=0; y<12; y++) 560 { 561 vector<WorldMap::Object> vctObjects = gameMap->getObjects(x, y); 562 563 vector<WorldMap::Object>::iterator it; 564 for(it = vctObjects.begin(); it != vctObjects.end(); it++) { 565 switch(it->type) { 566 case WorldMap::OBJECT_BLUE_FLAG: 567 al_draw_filled_rectangle(it->pos.x-8+mapPos.x, it->pos.y-8+mapPos.y, it->pos.x+8+mapPos.x, it->pos.y+8+mapPos.y, al_map_rgb(0, 0, 255)); 568 break; 569 case WorldMap::OBJECT_RED_FLAG: 570 al_draw_filled_rectangle(it->pos.x-8+mapPos.x, it->pos.y-8+mapPos.y, it->pos.x+8+mapPos.x, it->pos.y+8+mapPos.y, al_map_rgb(255, 0, 0)); 571 break; 572 } 573 } 550 574 } 551 575 } -
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(); -
server/server.cpp
rcc1c6c1 r6e66ffd 95 95 96 96 WorldMap* gameMap = WorldMap::loadMapFromFile("../data/map.txt"); 97 97 98 // add some items to the map. They will be sent out 99 // to players when they login 100 // m->addObject(x*25+12, y*25+12, OBJECT_BLUE_FLAG); 101 // m->addObject(x*25+12, y*25+12, OBJECT_RED_FLAG); 102 98 103 sock = socket(AF_INET, SOCK_DGRAM, 0); 99 104 if (sock < 0) error("Opening socket");
Note:
See TracChangeset
for help on using the changeset viewer.