Changeset 6319311 in network-game for client/Client/main.cpp


Ignore:
Timestamp:
Oct 1, 2013, 3:56:03 PM (11 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
master
Children:
373089e
Parents:
0693e25
Message:

Some redfinition issues related to winsock2 are fixed and a few allegro rendering functions are now in GameRender

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    r0693e25 r6319311  
    33#if defined WINDOWS
    44   #include <winsock2.h>
    5    #include <WS2tcpip.h>
     5   #include <ws2tcpip.h>
    66#elif defined LINUX
    77   #include <sys/types.h>
     
    3737
    3838#include "Window.h"
     39#include "TextLabel.h"
     40#include "Button.h"
    3941#include "Textbox.h"
    40 #include "Button.h"
    4142#include "RadioButtonList.h"
    42 #include "TextLabel.h"
     43
     44#include "GameRender.h"
     45
    4346#include "chat.h"
    4447
     
    5255void shutdownWinSock();
    5356void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, WorldMap *gameMap, map<unsigned int, Player>& mapPlayers, map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId, int &scoreBlue, int &scoreRed);
    54 void drawMap(WorldMap* gameMap);
    55 void drawPlayers(map<unsigned int, Player>& mapPlayers, ALLEGRO_FONT* font, unsigned int curPlayerId);
    5657int getRefreshRate(int width, int height);
    5758void drawMessageStatus(ALLEGRO_FONT* font);
     
    482483            al_draw_text(font, al_map_rgb(0, 255, 0), 515, 80, ALLEGRO_ALIGN_LEFT, ossScoreRed.str().c_str());
    483484
    484             drawMap(game->getMap());
    485             game->drawPlayers(font, curPlayerId);
     485            GameRender::drawMap(game->getMap());
     486            GameRender::drawPlayers(game->getPlayers(), font, curPlayerId);
    486487         }
    487488         else if (wndCurrent == wndGame)
     
    519520            }
    520521
    521             drawMap(gameMap);
    522             drawPlayers(mapPlayers, font, curPlayerId);
     522            GameRender::drawMap(gameMap);
     523            GameRender::drawPlayers(mapPlayers, font, curPlayerId);
    523524
    524525            // draw projectiles
     
    948949         break;
    949950      }
    950    }
    951 }
    952 
    953 // this should probably be in the WorldMap class
    954 void drawMap(WorldMap* gameMap)
    955 {
    956    POSITION mapPos;
    957    mapPos.x = 0;
    958    mapPos.y = 0;
    959    mapPos = mapToScreen(mapPos);
    960 
    961    for (int x=0; x<gameMap->width; x++)
    962    {
    963       for (int y=0; y<gameMap->height; y++)
    964       {
    965          WorldMap::TerrainType el = gameMap->getElement(x, y);
    966          WorldMap::StructureType structure = gameMap->getStructure(x, y);
    967 
    968          if (el == WorldMap::TERRAIN_GRASS)
    969             al_draw_filled_rectangle(x*25+mapPos.x, y*25+mapPos.y, x*25+25+mapPos.x, y*25+25+mapPos.y, al_map_rgb(0, 255, 0));
    970          else if (el == WorldMap::TERRAIN_OCEAN)
    971             al_draw_filled_rectangle(x*25+mapPos.x, y*25+mapPos.y, x*25+25+mapPos.x, y*25+25+mapPos.y, al_map_rgb(0, 0, 255));
    972          else if (el == WorldMap::TERRAIN_ROCK)
    973             al_draw_filled_rectangle(x*25+mapPos.x, y*25+mapPos.y, x*25+25+mapPos.x, y*25+25+mapPos.y, al_map_rgb(100, 100, 0));
    974 
    975          if (structure == WorldMap::STRUCTURE_BLUE_FLAG) {
    976             al_draw_circle(x*25+12+mapPos.x, y*25+12+mapPos.y, 12, al_map_rgb(0, 0, 0), 3);
    977             //al_draw_filled_rectangle(x*25+5+mapPos.x, y*25+5+mapPos.y, x*25+20+mapPos.x, y*25+20+mapPos.y, al_map_rgb(0, 0, 255));
    978          }else if (structure == WorldMap::STRUCTURE_RED_FLAG) {
    979             al_draw_circle(x*25+12+mapPos.x, y*25+12+mapPos.y, 12, al_map_rgb(0, 0, 0), 3);
    980             //al_draw_filled_rectangle(x*25+5+mapPos.x, y*25+5+mapPos.y, x*25+20+mapPos.x, y*25+20+mapPos.y, al_map_rgb(255, 0, 0));
    981          }
    982       }
    983    }
    984 
    985    for (int x=0; x<gameMap->width; x++)
    986    {
    987       for (int y=0; y<gameMap->height; y++)
    988       {
    989          vector<WorldMap::Object> vctObjects = gameMap->getObjects(x, y);
    990 
    991          vector<WorldMap::Object>::iterator it;
    992          for(it = vctObjects.begin(); it != vctObjects.end(); it++) {
    993             switch(it->type) {
    994                case WorldMap::OBJECT_BLUE_FLAG:
    995                   al_draw_filled_rectangle(it->pos.x-8+mapPos.x, it->pos.y-8+mapPos.y, it->pos.x+8+mapPos.x, it->pos.y+8+mapPos.y, al_map_rgb(0, 0, 255));
    996                   break;
    997                case WorldMap::OBJECT_RED_FLAG:
    998                   al_draw_filled_rectangle(it->pos.x-8+mapPos.x, it->pos.y-8+mapPos.y, it->pos.x+8+mapPos.x, it->pos.y+8+mapPos.y, al_map_rgb(255, 0, 0));
    999                   break;
    1000             }
    1001          }
    1002       }
    1003    }
    1004 }
    1005 
    1006 void drawPlayers(map<unsigned int, Player>& mapPlayers, ALLEGRO_FONT* font, unsigned int curPlayerId)
    1007 {
    1008    map<unsigned int, Player>::iterator it;
    1009 
    1010    Player* p;
    1011    POSITION pos;
    1012    ALLEGRO_COLOR color;
    1013 
    1014    for(it = mapPlayers.begin(); it != mapPlayers.end(); it++)
    1015    {
    1016       p = &it->second;
    1017 
    1018       if (p->isDead)
    1019          continue;
    1020 
    1021       pos = mapToScreen(p->pos.toInt());
    1022 
    1023       if (p->id == curPlayerId)
    1024          al_draw_filled_circle(pos.x, pos.y, 14, al_map_rgb(0, 0, 0));
    1025      
    1026       if (p->team == 0)
    1027          color = al_map_rgb(0, 0, 255);
    1028       else if (p->team == 1)
    1029          color = al_map_rgb(255, 0, 0);
    1030      
    1031       al_draw_filled_circle(pos.x, pos.y, 12, color);
    1032 
    1033       // draw player class
    1034       int fontHeight = al_get_font_line_height(font);
    1035 
    1036       string strClass;
    1037       switch (p->playerClass) {
    1038       case Player::CLASS_WARRIOR:
    1039          strClass = "W";
    1040          break;
    1041       case Player::CLASS_RANGER:
    1042          strClass = "R";
    1043          break;
    1044       case Player::CLASS_NONE:
    1045          strClass = "";
    1046          break;
    1047       default:
    1048          strClass = "";
    1049          break;
    1050       }
    1051       al_draw_text(font, al_map_rgb(0, 0, 0), pos.x, pos.y-fontHeight/2, ALLEGRO_ALIGN_CENTRE, strClass.c_str());
    1052 
    1053       // draw player health
    1054       al_draw_filled_rectangle(pos.x-12, pos.y-24, pos.x+12, pos.y-16, al_map_rgb(0, 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));
    1057 
    1058       if (p->hasBlueFlag)
    1059          al_draw_filled_rectangle(pos.x+4, pos.y-18, pos.x+18, pos.y-4, al_map_rgb(0, 0, 255));
    1060       else if (p->hasRedFlag)
    1061          al_draw_filled_rectangle(pos.x+4, pos.y-18, pos.x+18, pos.y-4, al_map_rgb(255, 0, 0));
    1062951   }
    1063952}
Note: See TracChangeset for help on using the changeset viewer.