- Timestamp:
- Sep 28, 2013, 2:11:19 AM (11 years ago)
- Branches:
- master
- Children:
- 6319311
- Parents:
- 3ef8cf4
- Location:
- common
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
common/Common.cpp
r3ef8cf4 r0693e25 11 11 12 12 using namespace std; 13 14 FLOAT_POSITION POSITION::toFloat() { 15 FLOAT_POSITION floatPosition; 16 floatPosition.x = x; 17 floatPosition.y = y; 18 19 return floatPosition; 20 } 21 22 POSITION FLOAT_POSITION::toInt() { 23 POSITION position; 24 position.x = x; 25 position.y = y; 26 27 return position; 28 } 13 29 14 30 void set_nonblock(int sock) … … 58 74 return sqrt( pow(xDiff,2) + pow(yDiff,2) ); 59 75 } 76 77 POSITION 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 91 POSITION 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 16 16 using namespace std; 17 17 18 typedef struct 19 { 18 struct FLOAT_POSITION; 19 20 struct POSITION { 21 int x; 22 int y; 23 FLOAT_POSITION toFloat(); 24 }; 25 26 struct FLOAT_POSITION { 20 27 float x; 21 28 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 }; 36 31 37 32 void set_nonblock(int sock); 38 33 unsigned long long getCurrentMillis(); 39 34 string getCurrentDateTimeString(); 35 36 POSITION screenToMap(POSITION pos); 37 POSITION mapToScreen(POSITION pos); 40 38 float posDistance(FLOAT_POSITION pos1, FLOAT_POSITION pos2); 41 39 -
common/Game.cpp
r3ef8cf4 r0693e25 1 1 #include "Game.h" 2 3 #include <allegro5/allegro_primitives.h> 4 5 #include "Common.h" 2 6 3 7 using namespace std; … … 74 78 this->blueScore = score; 75 79 } 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
r3ef8cf4 r0693e25 13 13 #include <string> 14 14 #include <map> 15 16 #include <allegro5/allegro_font.h> 15 17 16 18 #include "Player.h" … … 46 48 void setBlueScore(int score); 47 49 void setRedScore(int score); 50 51 void drawPlayers(ALLEGRO_FONT* font, unsigned int curPlayerId); 48 52 }; 49 53
Note:
See TracChangeset
for help on using the changeset viewer.