source: network-game/client/Client/GameRender.cpp@ 45734ff

Last change on this file since 45734ff was b4c5b6a, checked in by dportnoy <dmp1488@…>, 11 years ago

PLAYER messages are handled in the NEW_GAME state and players are added to the client's Game instance

  • Property mode set to 100644
File size: 4.2 KB
Line 
1#include "GameRender.h"
2
3#include <allegro5/allegro_primitives.h>
4
5void GameRender::drawMap(WorldMap* gameMap)
6{
7 POSITION mapPos;
8 mapPos.x = 0;
9 mapPos.y = 0;
10 mapPos = mapToScreen(mapPos);
11
12 for (int x=0; x<gameMap->width; x++)
13 {
14 for (int y=0; y<gameMap->height; y++)
15 {
16 WorldMap::TerrainType el = gameMap->getElement(x, y);
17 WorldMap::StructureType structure = gameMap->getStructure(x, y);
18
19 if (el == WorldMap::TERRAIN_GRASS)
20 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));
21 else if (el == WorldMap::TERRAIN_OCEAN)
22 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));
23 else if (el == WorldMap::TERRAIN_ROCK)
24 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));
25
26 if (structure == WorldMap::STRUCTURE_BLUE_FLAG) {
27 al_draw_circle(x*25+12+mapPos.x, y*25+12+mapPos.y, 12, al_map_rgb(0, 0, 0), 3);
28 //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));
29 }else if (structure == WorldMap::STRUCTURE_RED_FLAG) {
30 al_draw_circle(x*25+12+mapPos.x, y*25+12+mapPos.y, 12, al_map_rgb(0, 0, 0), 3);
31 //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));
32 }
33 }
34 }
35
36 for (int x=0; x<gameMap->width; x++)
37 {
38 for (int y=0; y<gameMap->height; y++)
39 {
40 vector<WorldMap::Object> vctObjects = gameMap->getObjects(x, y);
41
42 vector<WorldMap::Object>::iterator it;
43 for(it = vctObjects.begin(); it != vctObjects.end(); it++) {
44 switch(it->type) {
45 case WorldMap::OBJECT_BLUE_FLAG:
46 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));
47 break;
48 case WorldMap::OBJECT_RED_FLAG:
49 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));
50 break;
51 }
52 }
53 }
54 }
55}
56
57void GameRender::drawPlayers(map<unsigned int, Player*>& mapPlayers, ALLEGRO_FONT* font, unsigned int curPlayerId)
58{
59 map<unsigned int, Player*>::iterator it;
60
61 Player* p;
62 POSITION pos;
63 ALLEGRO_COLOR color;
64
65 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)
66 {
67 p = it->second;
68
69 if (p->isDead)
70 continue;
71
72 pos = mapToScreen(p->pos.toInt());
73
74 if (p->id == curPlayerId)
75 al_draw_filled_circle(pos.x, pos.y, 14, al_map_rgb(0, 0, 0));
76
77 if (p->team == 0)
78 color = al_map_rgb(0, 0, 255);
79 else if (p->team == 1)
80 color = al_map_rgb(255, 0, 0);
81
82 al_draw_filled_circle(pos.x, pos.y, 12, color);
83
84 // draw player class
85 int fontHeight = al_get_font_line_height(font);
86
87 string strClass;
88 switch (p->playerClass) {
89 case Player::CLASS_WARRIOR:
90 strClass = "W";
91 break;
92 case Player::CLASS_RANGER:
93 strClass = "R";
94 break;
95 case Player::CLASS_NONE:
96 strClass = "";
97 break;
98 default:
99 strClass = "";
100 break;
101 }
102 al_draw_text(font, al_map_rgb(0, 0, 0), pos.x, pos.y-fontHeight/2, ALLEGRO_ALIGN_CENTRE, strClass.c_str());
103
104 // draw player health
105 al_draw_filled_rectangle(pos.x-12, pos.y-24, pos.x+12, pos.y-16, al_map_rgb(0, 0, 0));
106 if (p->maxHealth != 0)
107 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));
108
109 if (p->hasBlueFlag)
110 al_draw_filled_rectangle(pos.x+4, pos.y-18, pos.x+18, pos.y-4, al_map_rgb(0, 0, 255));
111 else if (p->hasRedFlag)
112 al_draw_filled_rectangle(pos.x+4, pos.y-18, pos.x+18, pos.y-4, al_map_rgb(255, 0, 0));
113 }
114}
Note: See TracBrowser for help on using the repository browser.