Changeset 6319311 in network-game
- Timestamp:
- Oct 1, 2013, 3:56:03 PM (11 years ago)
- Branches:
- master
- Children:
- 373089e
- Parents:
- 0693e25
- Files:
-
- 2 added
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/Button.cpp
r0693e25 r6319311 1 1 #include "Button.h" 2 3 #include "../../common/Compiler.h" 2 4 3 5 Button::Button(int x, int y, int width, int height, ALLEGRO_FONT *font, string str, void (*callback)()) : -
client/Client/Client.vcxproj
r0693e25 r6319311 76 76 <ClCompile Include="chat.cpp" /> 77 77 <ClCompile Include="Button.cpp" /> 78 <ClCompile Include="GameRender.cpp" /> 78 79 <ClCompile Include="GuiComponent.cpp" /> 79 80 <ClCompile Include="main.cpp" /> … … 94 95 <ClInclude Include="chat.h" /> 95 96 <ClInclude Include="Button.h" /> 97 <ClInclude Include="GameRender.h" /> 96 98 <ClInclude Include="GuiComponent.h" /> 97 99 <ClInclude Include="RadioButtonList.h" /> -
client/Client/Client.vcxproj.filters
r0693e25 r6319311 73 73 <Filter>Source Files\common</Filter> 74 74 </ClCompile> 75 <ClCompile Include="GameRender.cpp"> 76 <Filter>Source Files</Filter> 77 </ClCompile> 75 78 </ItemGroup> 76 79 <ItemGroup> … … 120 123 <Filter>Header Files\common</Filter> 121 124 </ClInclude> 125 <ClInclude Include="GameRender.h"> 126 <Filter>Header Files</Filter> 127 </ClInclude> 122 128 </ItemGroup> 123 129 <ItemGroup> -
client/Client/GuiComponent.h
r0693e25 r6319311 5 5 #include <allegro5/allegro_primitives.h> 6 6 #include <allegro5/allegro_font.h> 7 8 #include "../../common/Compiler.h"9 7 10 8 class GuiComponent -
client/Client/Textbox.cpp
r0693e25 r6319311 2 2 3 3 #include <iostream> 4 5 #include "../../common/Compiler.h" 4 6 5 7 using namespace std; -
client/Client/chat.h
r0693e25 r6319311 1 #pragma once 1 #ifndef _CHAT_H 2 #define _CHAT_H 2 3 3 4 #include <string> … … 28 29 }; 29 30 31 #endif 32 -
client/Client/main.cpp
r0693e25 r6319311 3 3 #if defined WINDOWS 4 4 #include <winsock2.h> 5 #include < WS2tcpip.h>5 #include <ws2tcpip.h> 6 6 #elif defined LINUX 7 7 #include <sys/types.h> … … 37 37 38 38 #include "Window.h" 39 #include "TextLabel.h" 40 #include "Button.h" 39 41 #include "Textbox.h" 40 #include "Button.h"41 42 #include "RadioButtonList.h" 42 #include "TextLabel.h" 43 44 #include "GameRender.h" 45 43 46 #include "chat.h" 44 47 … … 52 55 void shutdownWinSock(); 53 56 void 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);56 57 int getRefreshRate(int width, int height); 57 58 void drawMessageStatus(ALLEGRO_FONT* font); … … 482 483 al_draw_text(font, al_map_rgb(0, 255, 0), 515, 80, ALLEGRO_ALIGN_LEFT, ossScoreRed.str().c_str()); 483 484 484 drawMap(game->getMap());485 game->drawPlayers(font, curPlayerId);485 GameRender::drawMap(game->getMap()); 486 GameRender::drawPlayers(game->getPlayers(), font, curPlayerId); 486 487 } 487 488 else if (wndCurrent == wndGame) … … 519 520 } 520 521 521 drawMap(gameMap);522 drawPlayers(mapPlayers, font, curPlayerId);522 GameRender::drawMap(gameMap); 523 GameRender::drawPlayers(mapPlayers, font, curPlayerId); 523 524 524 525 // draw projectiles … … 948 949 break; 949 950 } 950 }951 }952 953 // this should probably be in the WorldMap class954 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 class1034 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 health1054 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));1062 951 } 1063 952 } -
common/Common.cpp
r0693e25 r6319311 3 3 #include <sstream> 4 4 #include <cmath> 5 6 #if defined WINDOWS7 #include <Windows.h>8 #endif9 10 5 #include <ctime> 11 6 -
common/Common.h
r0693e25 r6319311 6 6 #if defined WINDOWS 7 7 #include <winsock2.h> 8 #include < WS2tcpip.h>8 #include <ws2tcpip.h> 9 9 #elif defined LINUX 10 10 #include <fcntl.h> -
common/Game.cpp
r0693e25 r6319311 2 2 3 3 #include <allegro5/allegro_primitives.h> 4 5 #include "Common.h"6 4 7 5 using namespace std; … … 78 76 this->blueScore = score; 79 77 } 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 class108 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 health128 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 4 4 #include "Compiler.h" 5 5 6 #if defined WINDOWS7 #include <winsock2.h>8 #include <WS2tcpip.h>9 #elif defined LINUX10 #include <netinet/in.h>11 #endif12 13 6 #include <string> 14 7 #include <map> 8 9 #ifdef WINDOWS 10 #define WIN32_LEAN_AND_MEAN 11 #endif 15 12 16 13 #include <allegro5/allegro_font.h> … … 48 45 void setBlueScore(int score); 49 46 void setRedScore(int score); 50 51 void drawPlayers(ALLEGRO_FONT* font, unsigned int curPlayerId);52 47 }; 53 48 -
common/MessageContainer.cpp
r0693e25 r6319311 2 2 3 3 #include <iostream> 4 5 #include "Compiler.h"6 4 7 5 using namespace std; -
common/MessageContainer.h
r0693e25 r6319311 2 2 #define _MESSAGE_CONTAINER_H 3 3 4 #include "Compiler.h"5 6 4 #include <string> 7 5 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" 14 7 15 8 using namespace std; -
common/MessageProcessor.cpp
r0693e25 r6319311 3 3 #include <iostream> 4 4 #include <fstream> 5 6 #include "Common.h"7 5 8 6 MessageProcessor::MessageProcessor() { -
common/Player.h
r0693e25 r6319311 1 1 #ifndef _PLAYER_H 2 2 #define _PLAYER_H 3 4 #include "Compiler.h"5 6 #if defined WINDOWS7 #include <winsock2.h>8 #include <WS2tcpip.h>9 #elif defined LINUX10 #include <netinet/in.h>11 #endif12 3 13 4 #include <string> -
common/Projectile.h
r0693e25 r6319311 1 1 #ifndef _PROJECTILE_H 2 2 #define _PROJECTILE_H 3 4 #include "Compiler.h"5 3 6 4 #include <string> -
common/WorldMap.h
r0693e25 r6319311 3 3 4 4 #include <string> 5 6 5 #include <vector> 7 6
Note:
See TracChangeset
for help on using the changeset viewer.