Changeset d436ac4 in network-game for common/Player.cpp
- Timestamp:
- May 18, 2013, 6:36:54 PM (12 years ago)
- Branches:
- master
- Children:
- 7efed11
- Parents:
- 7f2cef0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
common/Player.cpp
r7f2cef0 rd436ac4 5 5 #include <cstring> 6 6 #include <cmath> 7 8 #include <allegro5/allegro.h> 9 #include <allegro5/allegro_primitives.h> 7 10 8 11 using namespace std; … … 16 19 this->pos.y = this->target.y = 0; 17 20 this->timeLastUpdated = 0; 21 this->team = 0; // blue team by default 22 this->hasBlueFlag = false; 23 this->hasRedFlag = false; 18 24 } 19 25 … … 28 34 this->target.y = p.target.y; 29 35 this->addr = p.addr; 36 this->team = 0; // blue team by default 37 this->hasBlueFlag = false; 38 this->hasRedFlag = false; 30 39 } 31 40 … … 37 46 this->pos.x = this->target.x = 200; 38 47 this->pos.y = this->target.y = 200; 39 } 40 41 Player::Player(string name, sockaddr_in addr) 42 { 43 this->id = 0; 44 this->name = name; 45 this->password = ""; 46 this->pos.x = this->target.x = 200; 47 this->pos.y = this->target.y = 200; 48 this->addr = addr; 48 this->team = 0; // blue team by default 49 this->hasBlueFlag = true; 50 this->hasRedFlag = true; 49 51 } 50 52 … … 60 62 memcpy(buffer+12, &this->target.x, 4); 61 63 memcpy(buffer+16, &this->target.y, 4); 62 strcpy(buffer+20, this->name.c_str()); 64 memcpy(buffer+20, &this->team, 4); 65 memcpy(buffer+24, &this->hasBlueFlag, 1); 66 memcpy(buffer+25, &this->hasRedFlag, 1); 67 strcpy(buffer+26, this->name.c_str()); 63 68 } 64 69 … … 70 75 memcpy(&this->target.x, buffer+12, 4); 71 76 memcpy(&this->target.y, buffer+16, 4); 72 this->name.assign(buffer+20); 77 memcpy(&this->team, buffer+20, 4); 78 memcpy(&this->hasBlueFlag, buffer+24, 1); 79 memcpy(&this->hasRedFlag, buffer+25, 1); 80 this->name.assign(buffer+26); 73 81 } 74 82 … … 81 89 { 82 90 this->addr = addr; 91 } 92 93 void Player::draw(POSITION pos, bool curPlayer) { 94 if (curPlayer) 95 al_draw_filled_circle(pos.x, pos.y, 12, al_map_rgb(255, 0, 0)); 96 else 97 al_draw_filled_circle(pos.x, pos.y, 12, al_map_rgb(191, 0, 0)); 98 99 if (this->hasBlueFlag) 100 al_draw_filled_rectangle(pos.x+4, pos.y-18, pos.x+18, pos.y-4, al_map_rgb(0, 0, 255)); 101 else if(this->hasRedFlag) 102 al_draw_filled_rectangle(pos.x+4, pos.y-18, pos.x+18, pos.y-4, al_map_rgb(255, 0, 0)); 83 103 } 84 104
Note:
See TracChangeset
for help on using the changeset viewer.