[6319311] | 1 | #include "GameRender.h"
|
---|
| 2 |
|
---|
| 3 | #include <allegro5/allegro_primitives.h>
|
---|
| 4 |
|
---|
[e5697b1] | 5 | #include "../../common/Common.h"
|
---|
| 6 |
|
---|
[6319311] | 7 | void GameRender::drawMap(WorldMap* gameMap)
|
---|
| 8 | {
|
---|
[e6c26b8] | 9 | POSITION mapPos;
|
---|
| 10 | mapPos.x = 0;
|
---|
| 11 | mapPos.y = 0;
|
---|
| 12 | mapPos = mapToScreen(mapPos);
|
---|
| 13 |
|
---|
| 14 | for (int x=0; x<gameMap->width; x++)
|
---|
| 15 | {
|
---|
| 16 | for (int y=0; y<gameMap->height; y++)
|
---|
| 17 | {
|
---|
[f66d04f] | 18 | TerrainType el = gameMap->getElement(x, y);
|
---|
| 19 | StructureType structure = gameMap->getStructure(x, y);
|
---|
[e6c26b8] | 20 |
|
---|
[f66d04f] | 21 | if (el == TERRAIN_GRASS)
|
---|
[e6c26b8] | 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, 255, 0));
|
---|
[f66d04f] | 23 | else if (el == TERRAIN_OCEAN)
|
---|
[e6c26b8] | 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(0, 0, 255));
|
---|
[f66d04f] | 25 | else if (el == TERRAIN_ROCK)
|
---|
[e6c26b8] | 26 | 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));
|
---|
| 27 |
|
---|
[f66d04f] | 28 | if (structure == STRUCTURE_BLUE_FLAG) {
|
---|
[e6c26b8] | 29 | al_draw_circle(x*25+12+mapPos.x, y*25+12+mapPos.y, 12, al_map_rgb(0, 0, 0), 3);
|
---|
| 30 | //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));
|
---|
[f66d04f] | 31 | }else if (structure == STRUCTURE_RED_FLAG) {
|
---|
[e6c26b8] | 32 | al_draw_circle(x*25+12+mapPos.x, y*25+12+mapPos.y, 12, al_map_rgb(0, 0, 0), 3);
|
---|
| 33 | //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));
|
---|
| 34 | }
|
---|
| 35 | }
|
---|
[6319311] | 36 | }
|
---|
| 37 |
|
---|
[e6c26b8] | 38 | for (int x=0; x<gameMap->width; x++)
|
---|
| 39 | {
|
---|
| 40 | for (int y=0; y<gameMap->height; y++)
|
---|
| 41 | {
|
---|
| 42 | vector<WorldMap::Object> vctObjects = gameMap->getObjects(x, y);
|
---|
| 43 |
|
---|
| 44 | vector<WorldMap::Object>::iterator it;
|
---|
| 45 | for(it = vctObjects.begin(); it != vctObjects.end(); it++) {
|
---|
| 46 | switch(it->type) {
|
---|
[f66d04f] | 47 | case OBJECT_BLUE_FLAG:
|
---|
[e6c26b8] | 48 | 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));
|
---|
| 49 | break;
|
---|
[f66d04f] | 50 | case OBJECT_RED_FLAG:
|
---|
[e6c26b8] | 51 | 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));
|
---|
| 52 | break;
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
[6319311] | 56 | }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | void GameRender::drawPlayers(map<unsigned int, Player*>& mapPlayers, ALLEGRO_FONT* font, unsigned int curPlayerId)
|
---|
| 60 | {
|
---|
[e6c26b8] | 61 | map<unsigned int, Player*>::iterator it;
|
---|
| 62 |
|
---|
| 63 | Player* p;
|
---|
| 64 | POSITION pos;
|
---|
| 65 | ALLEGRO_COLOR color;
|
---|
| 66 |
|
---|
[b4c5b6a] | 67 | for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)
|
---|
[e6c26b8] | 68 | {
|
---|
| 69 | p = it->second;
|
---|
| 70 |
|
---|
| 71 | if (p->isDead)
|
---|
| 72 | continue;
|
---|
| 73 |
|
---|
| 74 | pos = mapToScreen(p->pos.toInt());
|
---|
| 75 |
|
---|
[5b92307] | 76 | if (p->getId() == curPlayerId)
|
---|
[e6c26b8] | 77 | al_draw_filled_circle(pos.x, pos.y, 14, al_map_rgb(0, 0, 0));
|
---|
| 78 |
|
---|
| 79 | if (p->team == 0)
|
---|
| 80 | color = al_map_rgb(0, 0, 255);
|
---|
| 81 | else if (p->team == 1)
|
---|
| 82 | color = al_map_rgb(255, 0, 0);
|
---|
| 83 |
|
---|
| 84 | al_draw_filled_circle(pos.x, pos.y, 12, color);
|
---|
| 85 |
|
---|
| 86 | // draw player class
|
---|
| 87 | int fontHeight = al_get_font_line_height(font);
|
---|
| 88 |
|
---|
| 89 | string strClass;
|
---|
| 90 | switch (p->playerClass) {
|
---|
| 91 | case Player::CLASS_WARRIOR:
|
---|
| 92 | strClass = "W";
|
---|
| 93 | break;
|
---|
| 94 | case Player::CLASS_RANGER:
|
---|
| 95 | strClass = "R";
|
---|
| 96 | break;
|
---|
| 97 | case Player::CLASS_NONE:
|
---|
| 98 | strClass = "";
|
---|
| 99 | break;
|
---|
| 100 | default:
|
---|
| 101 | strClass = "";
|
---|
| 102 | break;
|
---|
| 103 | }
|
---|
| 104 | al_draw_text(font, al_map_rgb(0, 0, 0), pos.x, pos.y-fontHeight/2, ALLEGRO_ALIGN_CENTRE, strClass.c_str());
|
---|
| 105 |
|
---|
| 106 | // draw player health
|
---|
| 107 | al_draw_filled_rectangle(pos.x-12, pos.y-24, pos.x+12, pos.y-16, al_map_rgb(0, 0, 0));
|
---|
| 108 | if (p->maxHealth != 0)
|
---|
| 109 | 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));
|
---|
| 110 |
|
---|
| 111 | if (p->hasBlueFlag)
|
---|
| 112 | al_draw_filled_rectangle(pos.x+4, pos.y-18, pos.x+18, pos.y-4, al_map_rgb(0, 0, 255));
|
---|
| 113 | else if (p->hasRedFlag)
|
---|
| 114 | al_draw_filled_rectangle(pos.x+4, pos.y-18, pos.x+18, pos.y-4, al_map_rgb(255, 0, 0));
|
---|
[6319311] | 115 | }
|
---|
[e5697b1] | 116 | }
|
---|
| 117 |
|
---|
| 118 | void GameRender::drawProjectiles(map<unsigned int, Projectile>& mapProjectiles, map<unsigned int, Player*>& mapPlayers)
|
---|
| 119 | {
|
---|
| 120 | map<unsigned int, Projectile>::iterator it;
|
---|
| 121 | for (it = mapProjectiles.begin(); it != mapProjectiles.end(); it++)
|
---|
| 122 | {
|
---|
| 123 | Projectile proj = it->second;
|
---|
| 124 |
|
---|
| 125 | FLOAT_POSITION target = mapPlayers[proj.target]->pos;
|
---|
| 126 | float angle = atan2(target.y-proj.pos.toFloat().y, target.x-proj.pos.toFloat().x);
|
---|
| 127 |
|
---|
| 128 | POSITION start, end;
|
---|
| 129 | start.x = cos(angle)*15+proj.pos.x;
|
---|
| 130 | start.y = sin(angle)*15+proj.pos.y;
|
---|
| 131 | end.x = proj.pos.x;
|
---|
| 132 | end.y = proj.pos.y;
|
---|
| 133 |
|
---|
| 134 | start = mapToScreen(start);
|
---|
| 135 | end = mapToScreen(end);
|
---|
| 136 |
|
---|
| 137 | al_draw_line(start.x, start.y, end.x, end.y, al_map_rgb(0, 0, 0), 4);
|
---|
| 138 | }
|
---|
[6319311] | 139 | }
|
---|