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


Ignore:
Timestamp:
Dec 19, 2013, 3:34:50 AM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
402cf86
Parents:
0129700
Message:

The client sends and processes PLAYER_MOVE messages when in a game and updates player movement accordingly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    r0129700 rfef7c69  
    399399               wndCurrent = wndGame;
    400400            }
    401          }else if(wndCurrent == wndGame) {
     401         }else if(wndCurrent == wndGame || wndCurrent == wndNewGame) {
    402402            if (ev.mouse.button == 1) {   // left click
    403403               msgTo.type = MSG_TYPE_PLAYER_MOVE;
     
    500500            al_draw_text(font, al_map_rgb(0, 255, 0), 515, 80, ALLEGRO_ALIGN_LEFT, ossScoreRed.str().c_str());
    501501
     502            // update players
     503            for (it = game->getPlayers().begin(); it != game->getPlayers().end(); it++)
     504            {
     505               it->second->updateTarget(game->getPlayers());
     506            }
     507
     508            for (it = game->getPlayers().begin(); it != game->getPlayers().end(); it++)
     509            {
     510               it->second->move(game->getMap());    // ignore return value
     511            }
     512
    502513            GameRender::drawMap(game->getMap());
    503514            GameRender::drawPlayers(game->getPlayers(), font, curPlayerId);
     
    982993
    983994               game->addPlayer(mapPlayers[p.id]);
     995
     996               break;
     997            }
     998            case MSG_TYPE_PLAYER_MOVE:
     999            {
     1000               cout << "Received PLAYER_MOVE message" << endl;
     1001
     1002               unsigned int id;
     1003               int x, y;
     1004
     1005               memcpy(&id, msg.buffer, 4);
     1006               memcpy(&x, msg.buffer+4, 4);
     1007               memcpy(&y, msg.buffer+8, 4);
     1008
     1009               cout << "id: " << id << endl;
     1010
     1011               mapPlayers[id]->target.x = x;
     1012               mapPlayers[id]->target.y = y;
    9841013
    9851014               break;
Note: See TracChangeset for help on using the changeset viewer.