Changeset e1f78f5 in network-game
- Timestamp:
- May 26, 2013, 8:57:11 PM (12 years ago)
- Branches:
- master
- Children:
- 4b4b153
- Parents:
- 46fa35a
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/main.cpp
r46fa35a re1f78f5 254 254 for(it = mapPlayers.begin(); it != mapPlayers.end(); it++) 255 255 { 256 &it->second;257 256 if (it->second.id == curPlayerId) 258 257 p = &it->second; … … 279 278 else if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) { 280 279 if(wndCurrent == wndMain) { 281 msgTo.type = MSG_TYPE_PLAYER_MOVE; 282 283 POSITION pos; 284 pos.x = ev.mouse.x; 285 pos.y = ev.mouse.y; 286 pos = screenToMap(pos); 287 288 if (pos.x != -1) 289 { 290 memcpy(msgTo.buffer, &curPlayerId, 4); 291 memcpy(msgTo.buffer+4, &pos.x, 4); 292 memcpy(msgTo.buffer+8, &pos.y, 4); 293 294 sendMessage(&msgTo, sock, &server); 295 } 296 else 297 cout << "Invalid point: User did not click on the map" << endl; 280 if (ev.mouse.button == 1) { // left click 281 msgTo.type = MSG_TYPE_PLAYER_MOVE; 282 283 POSITION pos; 284 pos.x = ev.mouse.x; 285 pos.y = ev.mouse.y; 286 pos = screenToMap(pos); 287 288 if (pos.x != -1) 289 { 290 memcpy(msgTo.buffer, &curPlayerId, 4); 291 memcpy(msgTo.buffer+4, &pos.x, 4); 292 memcpy(msgTo.buffer+8, &pos.y, 4); 293 294 sendMessage(&msgTo, sock, &server); 295 } 296 else 297 cout << "Invalid point: User did not click on the map" << endl; 298 }else if (ev.mouse.button == 2) { // right click 299 map<unsigned int, Player>::iterator it; 300 301 Player* curPlayer; 302 for(it = mapPlayers.begin(); it != mapPlayers.end(); it++) 303 { 304 if (it->second.id == curPlayerId) 305 curPlayer = &it->second; 306 } 307 308 Player* target; 309 for(it = mapPlayers.begin(); it != mapPlayers.end(); it++) 310 { 311 target = &it->second; 312 if (target->id != curPlayerId && target->team != curPlayer->team) { 313 msgTo.type = MSG_TYPE_START_ATTACK; 314 memcpy(msgTo.buffer, &curPlayerId, 4); 315 memcpy(msgTo.buffer+4, &target->id, 4); 316 317 sendMessage(&msgTo, sock, &server); 318 } 319 } 320 } 298 321 } 299 322 } … … 710 733 al_draw_filled_rectangle(pos.x-12, pos.y-24, pos.x+12, pos.y-16, al_map_rgb(0, 0, 0)); 711 734 if (it->second.maxHealth != 0) 712 al_draw_filled_rectangle(pos.x-11, pos.y- 19, pos.x-11+(22*it->second.health)/it->second.maxHealth, pos.y-15, al_map_rgb(255, 0, 0));735 al_draw_filled_rectangle(pos.x-11, pos.y-23, pos.x-11+(22*it->second.health)/it->second.maxHealth, pos.y-17, al_map_rgb(255, 0, 0)); 713 736 714 737 if (p->hasBlueFlag) -
common/Message.h
r46fa35a re1f78f5 13 13 #define MSG_TYPE_DROP_FLAG 10 14 14 #define MSG_TYPE_SCORE 11 15 #define MSG_TYPE_START_ATTACK 12 16 #define MSG_TYPE_ATTACK 13 15 17 16 18 typedef struct
Note:
See TracChangeset
for help on using the changeset viewer.