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