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