Changeset 58ca135 in network-game for client/Client/main.cpp


Ignore:
Timestamp:
Dec 22, 2013, 10:56:37 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
5ae8dca
Parents:
45734ff
Message:

Client handles PROJECTILE and REMOVE_PROJECTILE messages in individual games and updates projectile targets and move projectils in individual games as well

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    r45734ff r58ca135  
    516516            }
    517517
     518             // update projectile positions
     519            map<unsigned int, Projectile>::iterator it2;
     520            for (it2 = game->getProjectiles().begin(); it2 != game->getProjectiles().end(); it2++)
     521            {
     522               it2->second.move(game->getPlayers());
     523            }
     524
    518525            GameRender::drawMap(game->getMap());
    519526            GameRender::drawPlayers(game->getPlayers(), font, curPlayerId);
     527
     528            // draw projectiles
     529            for (it2 = game->getProjectiles().begin(); it2 != game->getProjectiles().end(); it2++)
     530            {
     531               Projectile proj = it2->second;
     532
     533               FLOAT_POSITION target = game->getPlayers()[proj.target]->pos;
     534               float angle =  atan2(target.y-proj.pos.toFloat().y, target.x-proj.pos.toFloat().x);
     535
     536               POSITION start, end;
     537               start.x = cos(angle)*15+proj.pos.x;
     538               start.y = sin(angle)*15+proj.pos.y;
     539               end.x = proj.pos.x;
     540               end.y = proj.pos.y;
     541
     542               start = mapToScreen(start);
     543               end = mapToScreen(end);
     544
     545               al_draw_line(start.x, start.y, end.x, end.y, al_map_rgb(0, 0, 0), 4);
     546            }
    520547         }
    521548         else if (wndCurrent == wndGame)
     
    10831110               source->targetPlayer = targetId;
    10841111               source->isChasing = true;
     1112
     1113               break;
     1114            }
     1115            case MSG_TYPE_PROJECTILE:
     1116            {
     1117               cout << "Received a PROJECTILE message" << endl;
     1118
     1119               unsigned int projId, x, y, targetId;
     1120
     1121               memcpy(&projId, msg.buffer, 4);
     1122               memcpy(&x, msg.buffer+4, 4);
     1123               memcpy(&y, msg.buffer+8, 4);
     1124               memcpy(&targetId, msg.buffer+12, 4);
     1125
     1126               cout << "projId: " << projId << endl;
     1127               cout << "x: " << x << endl;
     1128               cout << "y: " << y << endl;
     1129               cout << "Target: " << targetId << endl;
     1130
     1131               Projectile proj(x, y, targetId, 0);
     1132               proj.setId(projId);
     1133
     1134               game->addProjectile(proj);
     1135
     1136               break;
     1137            }
     1138            case MSG_TYPE_REMOVE_PROJECTILE:
     1139            {
     1140                cout << "Received a REMOVE_PROJECTILE message" << endl;
     1141
     1142               unsigned int id;
     1143               memcpy(&id, msg.buffer, 4);
     1144               
     1145               game->removeProjectile(id);
    10851146
    10861147               break;
Note: See TracChangeset for help on using the changeset viewer.