Changeset e6c26b8 in network-game for client/Client/GameRender.cpp


Ignore:
Timestamp:
Oct 1, 2013, 8:08:24 PM (12 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
master
Children:
95ffe57
Parents:
373089e
Message:

The client dynamically allocates memory for players and passes around a map with player pointers and some includes are now in individual files instead of in Common.h

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client/Client/GameRender.cpp

    r373089e re6c26b8  
    5252         }
    5353      }
    54    }
    55 }
    56 
    57 void GameRender::drawPlayers(map<unsigned int, Player>& mapPlayers, ALLEGRO_FONT* font, unsigned int curPlayerId)
    58 {
    59    map<unsigned int, Player>::iterator it;
    60 
    61    Player* p;
    62    POSITION pos;
    63    ALLEGRO_COLOR color;
    64 
    65    for(it = mapPlayers.begin(); it != mapPlayers.end(); it++)
    66    {
    67       p = &it->second;
    68 
    69       if (p->isDead)
    70          continue;
    71 
    72       pos = mapToScreen(p->pos.toInt());
    73 
    74       if (p->id == curPlayerId)
    75          al_draw_filled_circle(pos.x, pos.y, 14, al_map_rgb(0, 0, 0));
    76      
    77       if (p->team == 0)
    78          color = al_map_rgb(0, 0, 255);
    79       else if (p->team == 1)
    80          color = al_map_rgb(255, 0, 0);
    81      
    82       al_draw_filled_circle(pos.x, pos.y, 12, color);
    83 
    84       // draw player class
    85       int fontHeight = al_get_font_line_height(font);
    86 
    87       string strClass;
    88       switch (p->playerClass) {
    89       case Player::CLASS_WARRIOR:
    90          strClass = "W";
    91          break;
    92       case Player::CLASS_RANGER:
    93          strClass = "R";
    94          break;
    95       case Player::CLASS_NONE:
    96          strClass = "";
    97          break;
    98       default:
    99          strClass = "";
    100          break;
    101       }
    102       al_draw_text(font, al_map_rgb(0, 0, 0), pos.x, pos.y-fontHeight/2, ALLEGRO_ALIGN_CENTRE, strClass.c_str());
    103 
    104       // draw player health
    105       al_draw_filled_rectangle(pos.x-12, pos.y-24, pos.x+12, pos.y-16, al_map_rgb(0, 0, 0));
    106       if (p->maxHealth != 0)
    107          al_draw_filled_rectangle(pos.x-11, pos.y-23, pos.x-11+(22*p->health)/p->maxHealth, pos.y-17, al_map_rgb(255, 0, 0));
    108 
    109       if (p->hasBlueFlag)
    110          al_draw_filled_rectangle(pos.x+4, pos.y-18, pos.x+18, pos.y-4, al_map_rgb(0, 0, 255));
    111       else if (p->hasRedFlag)
    112          al_draw_filled_rectangle(pos.x+4, pos.y-18, pos.x+18, pos.y-4, al_map_rgb(255, 0, 0));
    11354   }
    11455}
Note: See TracChangeset for help on using the changeset viewer.