Changeset e5697b1 in network-game


Ignore:
Timestamp:
Jan 19, 2014, 8:02:22 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
1f6233e
Parents:
d05c484
Message:

Projectile drawing code moved to the GameRender class

Location:
client/Client
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • client/Client/GameRender.cpp

    rd05c484 re5697b1  
    22
    33#include <allegro5/allegro_primitives.h>
     4
     5#include "../../common/Common.h"
    46
    57void GameRender::drawMap(WorldMap* gameMap)
     
    113115   }
    114116}
     117
     118void 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   }
     139}
  • client/Client/GameRender.h

    rd05c484 re5697b1  
    1818
    1919#include "../../common/Player.h"
     20#include "../../common/Projectile.h"
    2021#include "../../common/WorldMap.h"
    2122
     
    2526   static void drawMap(WorldMap* gameMap);
    2627   static void drawPlayers(map<unsigned int, Player*>& mapPlayers, ALLEGRO_FONT* font, unsigned int curPlayerId);
     28   static void drawProjectiles(map<unsigned int, Projectile>& mapProjectiles, map<unsigned int, Player*>& mapPLayers);
    2729};
    2830
  • client/Client/main.cpp

    rd05c484 re5697b1  
    520520            GameRender::drawMap(game->getMap());
    521521            GameRender::drawPlayers(game->getPlayers(), font, curPlayerId);
    522 
    523             // draw projectiles
    524             for (it2 = game->getProjectiles().begin(); it2 != game->getProjectiles().end(); it2++)
    525             {
    526                Projectile proj = it2->second;
    527 
    528                FLOAT_POSITION target = game->getPlayers()[proj.target]->pos;
    529                float angle =  atan2(target.y-proj.pos.toFloat().y, target.x-proj.pos.toFloat().x);
    530 
    531                POSITION start, end;
    532                start.x = cos(angle)*15+proj.pos.x;
    533                start.y = sin(angle)*15+proj.pos.y;
    534                end.x = proj.pos.x;
    535                end.y = proj.pos.y;
    536 
    537                start = mapToScreen(start);
    538                end = mapToScreen(end);
    539 
    540                al_draw_line(start.x, start.y, end.x, end.y, al_map_rgb(0, 0, 0), 4);
    541             }
     522            GameRender::drawProjectiles(game->getProjectiles(), game->getPlayers());
    542523         }
    543524         else if (wndCurrent == wndGameSummary)
Note: See TracChangeset for help on using the changeset viewer.