Changeset 0693e25 in network-game


Ignore:
Timestamp:
Sep 28, 2013, 2:11:19 AM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
6319311
Parents:
3ef8cf4
Message:

The client draws the map and players in individual games

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    r3ef8cf4 r0693e25  
    5454void drawMap(WorldMap* gameMap);
    5555void drawPlayers(map<unsigned int, Player>& mapPlayers, ALLEGRO_FONT* font, unsigned int curPlayerId);
    56 POSITION screenToMap(POSITION pos);
    57 POSITION mapToScreen(POSITION pos);
    5856int getRefreshRate(int width, int height);
    5957void drawMessageStatus(ALLEGRO_FONT* font);
     
    483481            al_draw_text(font, al_map_rgb(0, 255, 0), 330, 80, ALLEGRO_ALIGN_LEFT, ossScoreBlue.str().c_str());
    484482            al_draw_text(font, al_map_rgb(0, 255, 0), 515, 80, ALLEGRO_ALIGN_LEFT, ossScoreRed.str().c_str());
     483
     484            drawMap(game->getMap());
     485            game->drawPlayers(font, curPlayerId);
    485486         }
    486487         else if (wndCurrent == wndGame)
     
    613614   WSACleanup();
    614615#endif
    615 }
    616 
    617 POSITION screenToMap(POSITION pos)
    618 {
    619    pos.x = pos.x-300;
    620    pos.y = pos.y-100;
    621 
    622    if (pos.x < 0 || pos.y < 0)
    623    {
    624       pos.x = -1;
    625       pos.y = -1;
    626    }
    627 
    628    return pos;
    629 }
    630 
    631 POSITION mapToScreen(POSITION pos)
    632 {
    633    pos.x = pos.x+300;
    634    pos.y = pos.y+100;
    635 
    636    return pos;
    637 }
    638 
    639 POSITION mapToScreen(FLOAT_POSITION pos)
    640 {
    641    POSITION p;
    642    p.x = pos.x+300;
    643    p.y = pos.y+100;
    644 
    645    return p;
    646616}
    647617
     
    10491019         continue;
    10501020
    1051       pos = mapToScreen(p->pos);
     1021      pos = mapToScreen(p->pos.toInt());
    10521022
    10531023      if (p->id == curPlayerId)
     
    10831053      // draw player health
    10841054      al_draw_filled_rectangle(pos.x-12, pos.y-24, pos.x+12, pos.y-16, al_map_rgb(0, 0, 0));
    1085       if (it->second.maxHealth != 0)
    1086          al_draw_filled_rectangle(pos.x-11, pos.y-23, pos.x-11+(22*it->second.health)/it->second.maxHealth, pos.y-17, al_map_rgb(255, 0, 0));
     1055      if (p->maxHealth != 0)
     1056         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));
    10871057
    10881058      if (p->hasBlueFlag)
  • common/Common.cpp

    r3ef8cf4 r0693e25  
    1111
    1212using namespace std;
     13
     14FLOAT_POSITION POSITION::toFloat() {
     15   FLOAT_POSITION floatPosition;
     16   floatPosition.x = x;
     17   floatPosition.y = y;
     18
     19   return floatPosition;
     20}
     21
     22POSITION FLOAT_POSITION::toInt() {
     23   POSITION position;
     24   position.x = x;
     25   position.y = y;
     26
     27   return position;
     28}
    1329
    1430void set_nonblock(int sock)
     
    5874   return sqrt( pow(xDiff,2) + pow(yDiff,2) );   
    5975}
     76
     77POSITION screenToMap(POSITION pos)
     78{
     79   pos.x = pos.x-300;
     80   pos.y = pos.y-100;
     81
     82   if (pos.x < 0 || pos.y < 0)
     83   {
     84      pos.x = -1;
     85      pos.y = -1;
     86   }
     87
     88   return pos;
     89}
     90
     91POSITION mapToScreen(POSITION pos)
     92{
     93   pos.x = pos.x+300;
     94   pos.y = pos.y+100;
     95
     96   return pos;
     97}
  • common/Common.h

    r3ef8cf4 r0693e25  
    1616using namespace std;
    1717
    18 typedef struct
    19 {
     18struct FLOAT_POSITION;
     19
     20struct POSITION {
     21   int x;
     22   int y;
     23   FLOAT_POSITION toFloat();
     24};
     25
     26struct FLOAT_POSITION {
    2027   float x;
    2128   float y;
    22 } FLOAT_POSITION;
    23 
    24 typedef struct
    25 {
    26    int x;
    27    int y;
    28    FLOAT_POSITION toFloat() {
    29       FLOAT_POSITION floatPosition;
    30       floatPosition.x = x;
    31       floatPosition.y = y;
    32 
    33       return floatPosition;
    34    }
    35 } POSITION;
     29   POSITION toInt();
     30};
    3631
    3732void set_nonblock(int sock);
    3833unsigned long long getCurrentMillis();
    3934string getCurrentDateTimeString();
     35
     36POSITION screenToMap(POSITION pos);
     37POSITION mapToScreen(POSITION pos);
    4038float posDistance(FLOAT_POSITION pos1, FLOAT_POSITION pos2);
    4139
  • common/Game.cpp

    r3ef8cf4 r0693e25  
    11#include "Game.h"
     2
     3#include <allegro5/allegro_primitives.h>
     4
     5#include "Common.h"
    26
    37using namespace std;
     
    7478   this->blueScore = score;
    7579}
     80
     81void Game::drawPlayers(ALLEGRO_FONT* font, unsigned int curPlayerId) {
     82   map<unsigned int, Player*>::iterator it;
     83
     84   Player* p;
     85   POSITION pos;
     86   ALLEGRO_COLOR color;
     87
     88   for(it = players.begin(); it != players.end(); it++)
     89   {
     90      p = it->second;
     91
     92      if (p->isDead)
     93         continue;
     94
     95      pos = mapToScreen(p->pos.toInt());
     96
     97      if (p->id == curPlayerId)
     98         al_draw_filled_circle(pos.x, pos.y, 14, al_map_rgb(0, 0, 0));
     99     
     100      if (p->team == 0)
     101         color = al_map_rgb(0, 0, 255);
     102      else if (p->team == 1)
     103         color = al_map_rgb(255, 0, 0);
     104     
     105      al_draw_filled_circle(pos.x, pos.y, 12, color);
     106
     107      // draw player class
     108      int fontHeight = al_get_font_line_height(font);
     109
     110      string strClass;
     111      switch (p->playerClass) {
     112      case Player::CLASS_WARRIOR:
     113         strClass = "W";
     114         break;
     115      case Player::CLASS_RANGER:
     116         strClass = "R";
     117         break;
     118      case Player::CLASS_NONE:
     119         strClass = "";
     120         break;
     121      default:
     122         strClass = "";
     123         break;
     124      }
     125      al_draw_text(font, al_map_rgb(0, 0, 0), pos.x, pos.y-fontHeight/2, ALLEGRO_ALIGN_CENTRE, strClass.c_str());
     126
     127      // draw player health
     128      al_draw_filled_rectangle(pos.x-12, pos.y-24, pos.x+12, pos.y-16, al_map_rgb(0, 0, 0));
     129      if (p->maxHealth != 0)
     130         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));
     131
     132      if (p->hasBlueFlag)
     133         al_draw_filled_rectangle(pos.x+4, pos.y-18, pos.x+18, pos.y-4, al_map_rgb(0, 0, 255));
     134      else if (p->hasRedFlag)
     135         al_draw_filled_rectangle(pos.x+4, pos.y-18, pos.x+18, pos.y-4, al_map_rgb(255, 0, 0));
     136   }
     137}
  • common/Game.h

    r3ef8cf4 r0693e25  
    1313#include <string>
    1414#include <map>
     15
     16#include <allegro5/allegro_font.h>
    1517
    1618#include "Player.h"
     
    4648   void setBlueScore(int score);
    4749   void setRedScore(int score);
     50
     51   void drawPlayers(ALLEGRO_FONT* font, unsigned int curPlayerId);
    4852};
    4953
Note: See TracChangeset for help on using the changeset viewer.