Changeset 054b50b in network-game for client/Client/main.cpp
- Timestamp:
- Feb 25, 2013, 12:43:54 PM (12 years ago)
- Branches:
- master
- Children:
- a1a3bd5
- Parents:
- 67d032c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/main.cpp
r67d032c r054b50b 65 65 const int SCREEN_W = 640; 66 66 const int SCREEN_H = 480; 67 const int BOUNCER_SIZE = 32;68 enum MYKEYS {69 KEY_UP,70 KEY_DOWN,71 KEY_LEFT,72 KEY_RIGHT73 };74 67 75 68 enum STATE { … … 104 97 ALLEGRO_EVENT_QUEUE *event_queue = NULL; 105 98 ALLEGRO_TIMER *timer = NULL; 106 ALLEGRO_BITMAP *bouncer = NULL;107 99 bool key[4] = { false, false, false, false }; 108 100 bool redraw = true; … … 110 102 map<unsigned int, Player> mapPlayers; 111 103 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;115 104 116 105 state = STATE_START; … … 184 173 185 174 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"); 190 179 al_destroy_display(display); 191 180 al_destroy_timer(timer); 192 181 return -1; 193 182 } 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));207 183 208 184 al_set_target_bitmap(al_get_backbuffer(display)); … … 250 226 } 251 227 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 268 228 redraw = true; 269 229 } … … 272 232 } 273 233 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 }291 234 } 292 235 else if(ev.type == ALLEGRO_EVENT_KEY_UP) { 293 236 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 310 237 case ALLEGRO_KEY_ESCAPE: 311 238 doexit = true; … … 338 265 processMessage(msgFrom, state, chatConsole, mapPlayers, curPlayerId); 339 266 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 340 274 if (redraw && al_is_event_queue_empty(event_queue)) 341 275 { … … 375 309 376 310 al_destroy_event_queue(event_queue); 377 al_destroy_bitmap(bouncer);378 311 al_destroy_display(display); 379 312 al_destroy_timer(timer); … … 506 439 chatConsole.addLine(response); 507 440 441 cout << "Got a logout message" << endl; 508 442 if (response.compare("You have successfully logged out.") == 0) 509 443 { … … 519 453 break; 520 454 } 455 case MSG_TYPE_LOGOUT: 456 { 457 cout << "Got a logout message, but we don't process it" << endl; 458 459 break; 460 } 521 461 case MSG_TYPE_PLAYER: 522 462 { 523 463 Player p("", ""); 524 464 p.deserialize(msg.buffer); 465 p.timeLastUpdated = getCurrentMillis(); 525 466 mapPlayers[p.id] = p; 526 467
Note:
See TracChangeset
for help on using the changeset viewer.