Changeset d436ac4 in network-game for common/Player.cpp


Ignore:
Timestamp:
May 18, 2013, 6:36:54 PM (12 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
7efed11
Parents:
7f2cef0
Message:

Modified the player class to include the team and whether the player has either of the flags

File:
1 edited

Legend:

Unmodified
Added
Removed
  • common/Player.cpp

    r7f2cef0 rd436ac4  
    55#include <cstring>
    66#include <cmath>
     7
     8#include <allegro5/allegro.h>
     9#include <allegro5/allegro_primitives.h>
    710
    811using namespace std;
     
    1619   this->pos.y = this->target.y = 0;
    1720   this->timeLastUpdated = 0;
     21   this->team = 0;   // blue team by default
     22   this->hasBlueFlag = false;
     23   this->hasRedFlag = false;
    1824}
    1925
     
    2834   this->target.y = p.target.y;
    2935   this->addr = p.addr;
     36      this->team = 0;   // blue team by default
     37   this->hasBlueFlag = false;
     38   this->hasRedFlag = false;
    3039}
    3140
     
    3746   this->pos.x = this->target.x = 200;
    3847   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;
    4951}
    5052
     
    6062   memcpy(buffer+12, &this->target.x, 4);
    6163   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());
    6368}
    6469
     
    7075   memcpy(&this->target.x, buffer+12, 4);
    7176   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);
    7381}
    7482
     
    8189{
    8290   this->addr = addr;
     91}
     92
     93void 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));
    83103}
    84104
Note: See TracChangeset for help on using the changeset viewer.