Changeset 054b50b in network-game for client/Client


Ignore:
Timestamp:
Feb 25, 2013, 12:43:54 PM (12 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
a1a3bd5
Parents:
67d032c
Message:

Removed some unused client code and made the client update player positions as well as recieve them from the server.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    r67d032c r054b50b  
    6565const int SCREEN_W = 640;
    6666const int SCREEN_H = 480;
    67 const int BOUNCER_SIZE = 32;
    68 enum MYKEYS {
    69    KEY_UP,
    70    KEY_DOWN,
    71    KEY_LEFT,
    72    KEY_RIGHT
    73 };
    7467
    7568enum STATE {
     
    10497   ALLEGRO_EVENT_QUEUE *event_queue = NULL;
    10598   ALLEGRO_TIMER *timer = NULL;
    106    ALLEGRO_BITMAP *bouncer = NULL;
    10799   bool key[4] = { false, false, false, false };
    108100   bool redraw = true;
     
    110102   map<unsigned int, Player> mapPlayers;
    111103   unsigned int curPlayerId = -1;
    112 
    113    float bouncer_x = SCREEN_W / 2.0 - BOUNCER_SIZE / 2.0;
    114    float bouncer_y = SCREEN_H / 2.0 - BOUNCER_SIZE / 2.0;
    115104
    116105   state = STATE_START;
     
    184173
    185174   wndCurrent = wndLogin;
    186 
    187    bouncer = al_create_bitmap(BOUNCER_SIZE, BOUNCER_SIZE);
    188    if(!bouncer) {
    189       fprintf(stderr, "failed to create bouncer bitmap!\n");
     175 
     176   event_queue = al_create_event_queue();
     177   if(!event_queue) {
     178      fprintf(stderr, "failed to create event_queue!\n");
    190179      al_destroy_display(display);
    191180      al_destroy_timer(timer);
    192181      return -1;
    193182   }
    194  
    195    event_queue = al_create_event_queue();
    196    if(!event_queue) {
    197       fprintf(stderr, "failed to create event_queue!\n");
    198       al_destroy_bitmap(bouncer);
    199       al_destroy_display(display);
    200       al_destroy_timer(timer);
    201       return -1;
    202    }
    203 
    204    al_set_target_bitmap(bouncer);
    205  
    206    al_clear_to_color(al_map_rgb(255, 0, 255));
    207183 
    208184   al_set_target_bitmap(al_get_backbuffer(display));
     
    250226      }
    251227      else if(ev.type == ALLEGRO_EVENT_TIMER) {
    252          if(key[KEY_UP] && bouncer_y >= 4.0) {
    253             bouncer_y -= 4.0;
    254          }
    255  
    256          if(key[KEY_DOWN] && bouncer_y <= SCREEN_H - BOUNCER_SIZE - 4.0) {
    257             bouncer_y += 4.0;
    258          }
    259  
    260          if(key[KEY_LEFT] && bouncer_x >= 4.0) {
    261             bouncer_x -= 4.0;
    262          }
    263  
    264          if(key[KEY_RIGHT] && bouncer_x <= SCREEN_W - BOUNCER_SIZE - 4.0) {
    265             bouncer_x += 4.0;
    266          }
    267  
    268228         redraw = true;
    269229      }
     
    272232      }
    273233      else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) {
    274          switch(ev.keyboard.keycode) {
    275             case ALLEGRO_KEY_UP:
    276                key[KEY_UP] = true;
    277                break;
    278  
    279             case ALLEGRO_KEY_DOWN:
    280                key[KEY_DOWN] = true;
    281                break;
    282  
    283             case ALLEGRO_KEY_LEFT:
    284                key[KEY_LEFT] = true;
    285                break;
    286  
    287             case ALLEGRO_KEY_RIGHT:
    288                key[KEY_RIGHT] = true;
    289                break;
    290          }
    291234      }
    292235      else if(ev.type == ALLEGRO_EVENT_KEY_UP) {
    293236         switch(ev.keyboard.keycode) {
    294             case ALLEGRO_KEY_UP:
    295                key[KEY_UP] = false;
    296                break;
    297  
    298             case ALLEGRO_KEY_DOWN:
    299                key[KEY_DOWN] = false;
    300                break;
    301  
    302             case ALLEGRO_KEY_LEFT:
    303                key[KEY_LEFT] = false;
    304                break;
    305  
    306             case ALLEGRO_KEY_RIGHT:
    307                key[KEY_RIGHT] = false;
    308                break;
    309  
    310237            case ALLEGRO_KEY_ESCAPE:
    311238               doexit = true;
     
    338265         processMessage(msgFrom, state, chatConsole, mapPlayers, curPlayerId);
    339266 
     267      // update player positions
     268      map<unsigned int, Player>::iterator it;
     269      for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)
     270      {
     271         it->second.move();
     272      }
     273
    340274      if (redraw && al_is_event_queue_empty(event_queue))
    341275      {
     
    375309
    376310   al_destroy_event_queue(event_queue);
    377    al_destroy_bitmap(bouncer);
    378311   al_destroy_display(display);
    379312   al_destroy_timer(timer);
     
    506439               chatConsole.addLine(response);
    507440
     441               cout << "Got a logout message" << endl;
    508442               if (response.compare("You have successfully logged out.") == 0)
    509443               {
     
    519453               break;
    520454            }
     455            case MSG_TYPE_LOGOUT:
     456            {
     457               cout << "Got a logout message, but we don't process it" << endl;
     458
     459               break;
     460            }
    521461            case MSG_TYPE_PLAYER:
    522462            {
    523463               Player p("", "");
    524464               p.deserialize(msg.buffer);
     465               p.timeLastUpdated = getCurrentMillis();
    525466               mapPlayers[p.id] = p;
    526467
Note: See TracChangeset for help on using the changeset viewer.