Changeset d436ac4 in network-game


Ignore:
Timestamp:
May 18, 2013, 6:36:54 PM (11 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

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    r7f2cef0 rd436ac4  
    523523}
    524524
     525// this should probably be in the WorldMap class
    525526void drawMap(WorldMap* gameMap)
    526527{
     
    563564      pos = mapToScreen(p->pos);
    564565
    565       if (p->id == curPlayerId)
    566          al_draw_filled_circle(pos.x, pos.y, 12, al_map_rgb(255, 0, 0));
    567       else
    568          al_draw_filled_circle(pos.x, pos.y, 12, al_map_rgb(191, 0, 0));
     566      p->draw(pos, p->id == curPlayerId);
    569567   }
    570568}
  • 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
  • common/Player.h

    r7f2cef0 rd436ac4  
    2323   Player(const Player& p);
    2424   Player(string name, string password);
    25    Player(string name, sockaddr_in addr); // this will be deleted
    2625
    2726   ~Player();
     
    3332   void setAddr(sockaddr_in addr);
    3433
     34   void draw(POSITION pos, bool curPlayer);
    3535   bool move(WorldMap *map);
     36
     37   void takeFlag(int flag, WorldMap *map);
     38   void dropFlag(int flag, WorldMap *map);
    3639
    3740   int id;
     
    4245   POSITION target;
    4346   unsigned long long timeLastUpdated;
     47
     48   int team; // 0 is blue, 1 is red
     49      bool hasBlueFlag;
     50   bool hasRedFlag;
    4451};
    4552
Note: See TracChangeset for help on using the changeset viewer.