Changeset 6319311 in network-game


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

Files:
2 added
17 edited

Legend:

Unmodified
Added
Removed
  • client/Client/Button.cpp

    r0693e25 r6319311  
    11#include "Button.h"
     2
     3#include "../../common/Compiler.h"
    24
    35Button::Button(int x, int y, int width, int height, ALLEGRO_FONT *font, string str, void (*callback)()) :
  • client/Client/Client.vcxproj

    r0693e25 r6319311  
    7676    <ClCompile Include="chat.cpp" />
    7777    <ClCompile Include="Button.cpp" />
     78    <ClCompile Include="GameRender.cpp" />
    7879    <ClCompile Include="GuiComponent.cpp" />
    7980    <ClCompile Include="main.cpp" />
     
    9495    <ClInclude Include="chat.h" />
    9596    <ClInclude Include="Button.h" />
     97    <ClInclude Include="GameRender.h" />
    9698    <ClInclude Include="GuiComponent.h" />
    9799    <ClInclude Include="RadioButtonList.h" />
  • client/Client/Client.vcxproj.filters

    r0693e25 r6319311  
    7373      <Filter>Source Files\common</Filter>
    7474    </ClCompile>
     75    <ClCompile Include="GameRender.cpp">
     76      <Filter>Source Files</Filter>
     77    </ClCompile>
    7578  </ItemGroup>
    7679  <ItemGroup>
     
    120123      <Filter>Header Files\common</Filter>
    121124    </ClInclude>
     125    <ClInclude Include="GameRender.h">
     126      <Filter>Header Files</Filter>
     127    </ClInclude>
    122128  </ItemGroup>
    123129  <ItemGroup>
  • client/Client/GuiComponent.h

    r0693e25 r6319311  
    55#include <allegro5/allegro_primitives.h>
    66#include <allegro5/allegro_font.h>
    7 
    8 #include "../../common/Compiler.h"
    97
    108class GuiComponent
  • client/Client/Textbox.cpp

    r0693e25 r6319311  
    22
    33#include <iostream>
     4
     5#include "../../common/Compiler.h"
    46
    57using namespace std;
  • client/Client/chat.h

    r0693e25 r6319311  
    1 #pragma once
     1#ifndef _CHAT_H
     2#define _CHAT_H
    23
    34#include <string>
     
    2829};
    2930
     31#endif
     32
  • 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}
  • common/Common.cpp

    r0693e25 r6319311  
    33#include <sstream>
    44#include <cmath>
    5 
    6 #if defined WINDOWS
    7    #include <Windows.h>
    8 #endif
    9 
    105#include <ctime>
    116
  • common/Common.h

    r0693e25 r6319311  
    66#if defined WINDOWS
    77   #include <winsock2.h>
    8    #include <WS2tcpip.h>
     8   #include <ws2tcpip.h>
    99#elif defined LINUX
    1010   #include <fcntl.h>
  • common/Game.cpp

    r0693e25 r6319311  
    22
    33#include <allegro5/allegro_primitives.h>
    4 
    5 #include "Common.h"
    64
    75using namespace std;
     
    7876   this->blueScore = score;
    7977}
    80 
    81 void 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

    r0693e25 r6319311  
    44#include "Compiler.h"
    55
    6 #if defined WINDOWS
    7    #include <winsock2.h>
    8    #include <WS2tcpip.h>
    9 #elif defined LINUX
    10    #include <netinet/in.h>
    11 #endif
    12 
    136#include <string>
    147#include <map>
     8
     9#ifdef WINDOWS
     10   #define WIN32_LEAN_AND_MEAN
     11#endif
    1512
    1613#include <allegro5/allegro_font.h>
     
    4845   void setBlueScore(int score);
    4946   void setRedScore(int score);
    50 
    51    void drawPlayers(ALLEGRO_FONT* font, unsigned int curPlayerId);
    5247};
    5348
  • common/MessageContainer.cpp

    r0693e25 r6319311  
    22
    33#include <iostream>
    4 
    5 #include "Compiler.h"
    64
    75using namespace std;
  • common/MessageContainer.h

    r0693e25 r6319311  
    22#define _MESSAGE_CONTAINER_H
    33
    4 #include "Compiler.h"
    5 
    64#include <string>
    75
    8 #if defined WINDOWS
    9    #include <winsock2.h>
    10    #include <WS2tcpip.h>
    11 #elif defined LINUX
    12    #include <netinet/in.h>
    13 #endif
     6#include "Common.h"
    147
    158using namespace std;
  • common/MessageProcessor.cpp

    r0693e25 r6319311  
    33#include <iostream>
    44#include <fstream>
    5 
    6 #include "Common.h"
    75
    86MessageProcessor::MessageProcessor() {
  • common/Player.h

    r0693e25 r6319311  
    11#ifndef _PLAYER_H
    22#define _PLAYER_H
    3 
    4 #include "Compiler.h"
    5 
    6 #if defined WINDOWS
    7    #include <winsock2.h>
    8    #include <WS2tcpip.h>
    9 #elif defined LINUX
    10    #include <netinet/in.h>
    11 #endif
    123
    134#include <string>
  • common/Projectile.h

    r0693e25 r6319311  
    11#ifndef _PROJECTILE_H
    22#define _PROJECTILE_H
    3 
    4 #include "Compiler.h"
    53
    64#include <string>
  • common/WorldMap.h

    r0693e25 r6319311  
    33
    44#include <string>
    5 
    65#include <vector>
    76
Note: See TracChangeset for help on using the changeset viewer.