Changeset d09fe76 in network-game


Ignore:
Timestamp:
May 26, 2013, 8:20:49 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
46fa35a
Parents:
07c73fa
Message:

The client displays a player's health and class

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    r07c73fa rd09fe76  
    4949void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, WorldMap *gameMap, map<unsigned int, Player>& mapPlayers, unsigned int& curPlayerId, int &scoreBlue, int &scoreRed);
    5050void drawMap(WorldMap* gameMap);
    51 void drawPlayers(map<unsigned int, Player>& mapPlayers, unsigned int curPlayerId);
     51void drawPlayers(map<unsigned int, Player>& mapPlayers, ALLEGRO_FONT* font, unsigned int curPlayerId);
    5252POSITION screenToMap(POSITION pos);
    5353POSITION mapToScreen(POSITION pos);
     
    333333
    334334            drawMap(gameMap);
    335             drawPlayers(mapPlayers, curPlayerId);
     335            drawPlayers(mapPlayers, font, curPlayerId);
    336336         }
    337337
     
    664664}
    665665
    666 void drawPlayers(map<unsigned int, Player>& mapPlayers, unsigned int curPlayerId)
     666void drawPlayers(map<unsigned int, Player>& mapPlayers, ALLEGRO_FONT* font, unsigned int curPlayerId)
    667667{
    668668   map<unsigned int, Player>::iterator it;
     
    670670   Player* p;
    671671   POSITION pos;
     672   ALLEGRO_COLOR color;
    672673
    673674   for(it = mapPlayers.begin(); it != mapPlayers.end(); it++)
     
    680681     
    681682      if (p->team == 0)
    682          al_draw_filled_circle(pos.x, pos.y, 12, al_map_rgb(0, 0, 255));
     683         color = al_map_rgb(0, 0, 255);
    683684      else if (p->team == 1)
    684          al_draw_filled_circle(pos.x, pos.y, 12, al_map_rgb(255, 0, 0));
     685         color = al_map_rgb(255, 0, 0);
     686     
     687      al_draw_filled_circle(pos.x, pos.y, 12, color);
     688
     689      // draw player class
     690      int fontHeight = al_get_font_line_height(font);
     691
     692      string strClass;
     693      switch (p->playerClass) {
     694      case Player::CLASS_WARRIOR:
     695         strClass = "W";
     696         break;
     697      case Player::CLASS_RANGER:
     698         strClass = "R";
     699         break;
     700      case Player::CLASS_NONE:
     701         strClass = "";
     702         break;
     703      default:
     704         strClass = "";
     705         break;
     706      }
     707      al_draw_text(font, al_map_rgb(0, 0, 0), pos.x, pos.y-fontHeight/2, ALLEGRO_ALIGN_CENTRE, strClass.c_str());
     708
     709      // draw player health
     710      al_draw_filled_rectangle(pos.x-12, pos.y-24, pos.x+12, pos.y-16, al_map_rgb(0, 0, 0));
     711      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));
    685713
    686714      if (p->hasBlueFlag)
Note: See TracChangeset for help on using the changeset viewer.