Changeset 8c74150 in network-game for client/Client


Ignore:
Timestamp:
Jun 9, 2013, 7:29:59 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
11d21ee
Parents:
8795a38
Message:

The client processes PROJECTILE and REMOVE_PROJECTILE messages and draws moving projectiles on the screen

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    r8795a38 r8c74150  
    1313#endif
    1414
    15 #include <sys/types.h>
    1615#include <cstdio>
    1716#include <cstdlib>
     17#include <cmath>
     18#include <sys/types.h>
    1819#include <string>
    1920#include <iostream>
    2021#include <sstream>
    21 
    22 #include <map>
    23 
    2422#include <map>
    2523
     
    360358            }
    361359
     360            // update projectile positions
     361            map<unsigned int, Projectile>::iterator it2;
     362            for (it2 = mapProjectiles.begin(); it2 != mapProjectiles.end(); it2++)
     363            {
     364               cout << "Update projectile position" << endl;
     365               it2->second.move(mapPlayers);
     366            }
     367
    362368            drawMap(gameMap);
    363369            drawPlayers(mapPlayers, font, curPlayerId);
     370
     371            // draw projectiles
     372            for (it2 = mapProjectiles.begin(); it2 != mapProjectiles.end(); it2++)
     373            {
     374               cout << "Draw projectile" << endl;
     375
     376               Projectile proj = it2->second;
     377
     378               FLOAT_POSITION target = mapPlayers[proj.target].pos;
     379               float angle =  atan2(target.y-proj.pos.toFloat().y, target.x-proj.pos.toFloat().x);
     380
     381               POSITION start, end;
     382               start.x = cos(angle)*15+proj.pos.x;
     383               start.y = sin(angle)*15+proj.pos.y;
     384               end.x = proj.pos.x;
     385               end.y = proj.pos.y;
     386
     387               start = mapToScreen(start);
     388               end = mapToScreen(end);
     389
     390               al_draw_line(start.x, start.y, end.x, end.y, al_map_rgb(0, 0, 0), 4);
     391            }
    364392         }
    365393
     
    628656            case MSG_TYPE_PROJECTILE:
    629657            {
    630                cout << "Received a prjectile message" << endl;
     658               cout << "Received a PROJECTILE message" << endl;
    631659
    632660               int id, x, y, targetId;
     
    637665               memcpy(&targetId, msg.buffer+12, 4);
    638666
    639                cout << "id" << id << endl;
    640                cout << "x" << x << endl;
    641                cout << "y" << y << endl;
    642                cout << "Target" << targetId << endl;
     667               cout << "id: " << id << endl;
     668               cout << "x: " << x << endl;
     669               cout << "y: " << y << endl;
     670               cout << "Target: " << targetId << endl;
     671
     672               Projectile proj(x, y, targetId, 0);
     673               proj.setId(id);
     674
     675               mapProjectiles[id] = proj;
    643676
    644677               break;
     
    646679            case MSG_TYPE_REMOVE_PROJECTILE:
    647680            {
     681                cout << "Received a REMOVE_PROJECTILE message" << endl;
     682
     683               int id;
     684
     685               memcpy(&id, msg.buffer, 4);
     686               
     687               mapProjectiles.erase(id);
     688
    648689               break;
    649690            }
Note: See TracChangeset for help on using the changeset viewer.