Changeset f63aa57 in network-game
- Timestamp:
- Dec 27, 2013, 5:57:25 PM (11 years ago)
- Branches:
- master
- Children:
- 9bfc1cb
- Parents:
- cbc70eb
- Location:
- client/Client
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/Window.cpp
rcbc70eb rf63aa57 8 8 Window::~Window(void) 9 9 { 10 for(unsigned int x=0; x<this->vctGui.size(); x++)11 delete this->vctGui[x];12 10 } 13 11 14 void Window::addComponent(GuiComponent *comp)12 GuiComponent* Window::addComponent(GuiComponent* comp) 15 13 { 16 14 this->vctGui.push_back(comp); 15 return comp; 17 16 } 18 17 -
client/Client/Window.h
rcbc70eb rf63aa57 18 18 ~Window(void); 19 19 20 void addComponent(GuiComponent *comp);20 GuiComponent* addComponent(GuiComponent* comp); 21 21 GuiComponent* getComponent(int x); 22 22 void draw(ALLEGRO_DISPLAY *display); -
client/Client/main.cpp
rcbc70eb rf63aa57 22 22 #include <fstream> 23 23 #include <map> 24 #include <vector> 24 25 25 26 #include <allegro5/allegro.h> … … 88 89 bool doexit; 89 90 91 vector<GuiComponent*> vctComponents; 92 90 93 Window* wndLogin; 91 94 Window* wndRegister; 92 95 Window* wndLobby; 93 Window* wnd Game;96 Window* wndLobbyDebug; 94 97 Window* wndNewGame; 95 Window* wndGameDebug;96 98 Window* wndGameSummary; 97 99 Window* wndCurrent; … … 111 113 Textbox* txtJoinGame; 112 114 Textbox* txtCreateGame; 113 114 // wndGame115 115 Textbox* txtChat; 116 116 … … 213 213 214 214 wndLogin = new Window(0, 0, SCREEN_W, SCREEN_H); 215 wndLogin->addComponent(new Textbox(516, 40, 100, 20, font));216 wndLogin->addComponent(new Textbox(516, 70, 100, 20, font));217 wndLogin->addComponent(new TextLabel(410, 40, 100, 20, font, "Username:", ALLEGRO_ALIGN_RIGHT));218 wndLogin->addComponent(new TextLabel(410, 70, 100, 20, font, "Password:", ALLEGRO_ALIGN_RIGHT));219 wndLogin->addComponent(new TextLabel((SCREEN_W-600)/2, 100, 600, 20, font, "", ALLEGRO_ALIGN_CENTRE));220 wndLogin->addComponent(new Button(SCREEN_W/2-100, 130, 90, 20, font, "Register", goToRegisterScreen));221 wndLogin->addComponent(new Button(SCREEN_W/2+10, 130, 90, 20, font, "Login", login));222 wndLogin->addComponent(new Button(920, 10, 80, 20, font, "Quit", quit));223 wndLogin->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging));215 vctComponents.push_back(wndLogin->addComponent(new Textbox(516, 40, 100, 20, font))); 216 vctComponents.push_back(wndLogin->addComponent(new Textbox(516, 70, 100, 20, font))); 217 vctComponents.push_back(wndLogin->addComponent(new TextLabel(410, 40, 100, 20, font, "Username:", ALLEGRO_ALIGN_RIGHT))); 218 vctComponents.push_back(wndLogin->addComponent(new TextLabel(410, 70, 100, 20, font, "Password:", ALLEGRO_ALIGN_RIGHT))); 219 vctComponents.push_back(wndLogin->addComponent(new TextLabel((SCREEN_W-600)/2, 100, 600, 20, font, "", ALLEGRO_ALIGN_CENTRE))); 220 vctComponents.push_back(wndLogin->addComponent(new Button(SCREEN_W/2-100, 130, 90, 20, font, "Register", goToRegisterScreen))); 221 vctComponents.push_back(wndLogin->addComponent(new Button(SCREEN_W/2+10, 130, 90, 20, font, "Login", login))); 222 vctComponents.push_back(wndLogin->addComponent(new Button(920, 10, 80, 20, font, "Quit", quit))); 223 vctComponents.push_back(wndLogin->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging))); 224 224 225 225 txtUsername = (Textbox*)wndLogin->getComponent(0); … … 230 230 231 231 wndRegister = new Window(0, 0, SCREEN_W, SCREEN_H); 232 wndRegister->addComponent(new Textbox(516, 40, 100, 20, font));233 wndRegister->addComponent(new Textbox(516, 70, 100, 20, font));234 wndRegister->addComponent(new TextLabel(410, 40, 100, 20, font, "Username:", ALLEGRO_ALIGN_RIGHT));235 wndRegister->addComponent(new TextLabel(410, 70, 100, 20, font, "Password:", ALLEGRO_ALIGN_RIGHT));236 wndRegister->addComponent(new RadioButtonList(432, 100, "Pick a class", font));237 wndRegister->addComponent(new TextLabel((SCREEN_W-600)/2, 190, 600, 20, font, "", ALLEGRO_ALIGN_CENTRE));238 wndRegister->addComponent(new Button(SCREEN_W/2-100, 220, 90, 20, font, "Back", goToLoginScreen));239 wndRegister->addComponent(new Button(SCREEN_W/2+10, 220, 90, 20, font, "Submit", registerAccount));240 wndRegister->addComponent(new Button(920, 10, 80, 20, font, "Quit", quit));241 wndRegister->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging));232 vctComponents.push_back(wndRegister->addComponent(new Textbox(516, 40, 100, 20, font))); 233 vctComponents.push_back(wndRegister->addComponent(new Textbox(516, 70, 100, 20, font))); 234 vctComponents.push_back(wndRegister->addComponent(new TextLabel(410, 40, 100, 20, font, "Username:", ALLEGRO_ALIGN_RIGHT))); 235 vctComponents.push_back(wndRegister->addComponent(new TextLabel(410, 70, 100, 20, font, "Password:", ALLEGRO_ALIGN_RIGHT))); 236 vctComponents.push_back(wndRegister->addComponent(new RadioButtonList(432, 100, "Pick a class", font))); 237 vctComponents.push_back(wndRegister->addComponent(new TextLabel((SCREEN_W-600)/2, 190, 600, 20, font, "", ALLEGRO_ALIGN_CENTRE))); 238 vctComponents.push_back(wndRegister->addComponent(new Button(SCREEN_W/2-100, 220, 90, 20, font, "Back", goToLoginScreen))); 239 vctComponents.push_back(wndRegister->addComponent(new Button(SCREEN_W/2+10, 220, 90, 20, font, "Submit", registerAccount))); 240 vctComponents.push_back(wndRegister->addComponent(new Button(920, 10, 80, 20, font, "Quit", quit))); 241 vctComponents.push_back(wndRegister->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging))); 242 242 243 243 txtUsernameRegister = (Textbox*)wndRegister->getComponent(0); … … 252 252 cout << "Created register screen" << endl; 253 253 254 txtJoinGame = new Textbox(SCREEN_W*1/2+15+4, 40, 100, 20, font); 255 txtCreateGame = new Textbox(SCREEN_W*3/4+4, 40, 100, 20, font); 256 257 vctComponents.push_back(txtJoinGame); 258 vctComponents.push_back(txtCreateGame); 259 254 260 wndLobby = new Window(0, 0, SCREEN_W, SCREEN_H); 255 wndLobby->addComponent(new Button(920, 10, 80, 20, font, "Logout", logout));256 wndLobby->addComponent(new TextLabel(SCREEN_W*1/2+15-112, 40, 110, 20, font, "Game Name:", ALLEGRO_ALIGN_RIGHT));257 wndLobby->addComponent( new Textbox(SCREEN_W*1/2+15+4, 40, 100, 20, font));258 wndLobby->addComponent(new Button(SCREEN_W*1/2+15-100, 80, 200, 20, font, "Join Existing Game", joinGame));259 wndLobby->addComponent(new TextLabel(SCREEN_W*3/4-112, 40, 110, 20, font, "Game Name:", ALLEGRO_ALIGN_RIGHT));260 wndLobby->addComponent( new Textbox(SCREEN_W*3/4+4, 40, 100, 20, font));261 wndLobby->addComponent(new Button(SCREEN_W*3/4-100, 80, 200, 20, font, "Create New Game", createGame));262 wndLobby->addComponent(new Textbox(95, 40, 300, 20, font));263 wndLobby->addComponent(new Button(95, 70, 60, 20, font, "Send", sendChatMessage));264 265 txtJoinGame = (Textbox*)wndLobby->getComponent(2); 266 txtCreateGame = (Textbox*)wndLobby->getComponent(5); 261 vctComponents.push_back(wndLobby->addComponent(new Button(920, 10, 80, 20, font, "Logout", logout))); 262 vctComponents.push_back(wndLobby->addComponent(new TextLabel(SCREEN_W*1/2+15-112, 40, 110, 20, font, "Game Name:", ALLEGRO_ALIGN_RIGHT))); 263 wndLobby->addComponent(txtJoinGame); 264 vctComponents.push_back(wndLobby->addComponent(new Button(SCREEN_W*1/2+15-100, 80, 200, 20, font, "Join Existing Game", joinGame))); 265 vctComponents.push_back(wndLobby->addComponent(new TextLabel(SCREEN_W*3/4-112, 40, 110, 20, font, "Game Name:", ALLEGRO_ALIGN_RIGHT))); 266 wndLobby->addComponent(txtCreateGame); 267 vctComponents.push_back(wndLobby->addComponent(new Button(SCREEN_W*3/4-100, 80, 200, 20, font, "Create New Game", createGame))); 268 vctComponents.push_back(wndLobby->addComponent(new Textbox(95, 40, 300, 20, font))); 269 vctComponents.push_back(wndLobby->addComponent(new Button(95, 70, 60, 20, font, "Send", sendChatMessage))); 270 vctComponents.push_back(wndLobby->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging))); 271 272 267 273 txtChat = (Textbox*)wndLobby->getComponent(7); 268 274 269 275 cout << "Created lobby screen" << endl; 270 276 271 // this is the old game screen 272 wndGame = new Window(0, 0, SCREEN_W, SCREEN_H); 273 wndGame->addComponent(new Textbox(95, 40, 300, 20, font)); 274 wndGame->addComponent(new Button(95, 70, 60, 20, font, "Send", sendChatMessage)); 275 wndGame->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging)); 276 wndGame->addComponent(new Button(920, 10, 80, 20, font, "Logout", logout)); 277 278 wndGameDebug = new Window(0, 0, SCREEN_W, SCREEN_H); 279 wndGameDebug->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging)); 280 wndGameDebug->addComponent(new Button(920, 10, 80, 20, font, "Logout", logout)); 281 282 cout << "Created game screen" << endl; 283 284 // this is the new game screen, without a debug console 277 wndLobbyDebug = new Window(0, 0, SCREEN_W, SCREEN_H); 278 vctComponents.push_back(wndLobbyDebug->addComponent(new Button(920, 10, 80, 20, font, "Logout", logout))); 279 vctComponents.push_back(wndLobbyDebug->addComponent(new TextLabel(SCREEN_W*1/2+15-112, 40, 110, 20, font, "Game Name:", ALLEGRO_ALIGN_RIGHT))); 280 wndLobbyDebug->addComponent(txtJoinGame); 281 vctComponents.push_back(wndLobbyDebug->addComponent(new Button(SCREEN_W*1/2+15-100, 80, 200, 20, font, "Join Existing Game", joinGame))); 282 vctComponents.push_back(wndLobbyDebug->addComponent(new TextLabel(SCREEN_W*3/4-112, 40, 110, 20, font, "Game Name:", ALLEGRO_ALIGN_RIGHT))); 283 wndLobbyDebug->addComponent(txtCreateGame); 284 vctComponents.push_back(wndLobbyDebug->addComponent(new Button(SCREEN_W*3/4-100, 80, 200, 20, font, "Create New Game", createGame))); 285 vctComponents.push_back(wndLobbyDebug->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging))); 286 287 cout << "Created debug lobby screen" << endl; 288 285 289 wndNewGame = new Window(0, 0, SCREEN_W, SCREEN_H); 286 wndNewGame->addComponent(new Button(880, 10, 120, 20, font, "Leave Game", leaveGame));290 vctComponents.push_back(wndNewGame->addComponent(new Button(880, 10, 120, 20, font, "Leave Game", leaveGame))); 287 291 288 292 cout << "Created new game screen" << endl; 289 293 290 294 wndGameSummary = new Window(0, 0, SCREEN_W, SCREEN_H); 291 wndGameSummary->addComponent(new Button(840, 730, 160, 20, font, "Back to Lobby", closeGameSummary));295 vctComponents.push_back(wndGameSummary->addComponent(new Button(840, 730, 160, 20, font, "Back to Lobby", closeGameSummary))); 292 296 293 297 cout << "Created game summary screen" << endl; … … 394 398 } 395 399 else if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) { 396 if(wndCurrent == wnd Game || wndCurrent == wndNewGame) {400 if(wndCurrent == wndNewGame) { 397 401 if (ev.mouse.button == 1) { // left click 398 402 msgTo.type = MSG_TYPE_PLAYER_MOVE; … … 455 459 msgProcessor.resendUnackedMessages(); 456 460 457 if (debugging && wndCurrent == wnd Game)458 wnd GameDebug->draw(display);461 if (debugging && wndCurrent == wndLobby) 462 wndLobbyDebug->draw(display); 459 463 else 460 464 wndCurrent->draw(display); 461 465 462 466 if (wndCurrent == wndLobby) { 463 chatConsole.draw(font, al_map_rgb(255,255,255)); 467 if (!debugging) 468 chatConsole.draw(font, al_map_rgb(255,255,255)); 464 469 465 470 map<string, int>::iterator it; … … 537 542 } 538 543 } 539 else if (wndCurrent == wndGame )544 else if (wndCurrent == wndGameSummary) 540 545 { 541 if (!debugging)542 chatConsole.draw(font, al_map_rgb(255,255,255));543 544 al_draw_text(font, al_map_rgb(0, 255, 0), 4, 43, ALLEGRO_ALIGN_LEFT, "Message:");545 546 ostringstream ossScoreBlue, ossScoreRed;547 548 ossScoreBlue << "Blue: " << game->getBlueScore() << endl;549 ossScoreRed << "Red: " << game->getRedScore() << endl;550 551 al_draw_text(font, al_map_rgb(0, 255, 0), 330, 80, ALLEGRO_ALIGN_LEFT, ossScoreBlue.str().c_str());552 al_draw_text(font, al_map_rgb(0, 255, 0), 515, 80, ALLEGRO_ALIGN_LEFT, ossScoreRed.str().c_str());553 554 // update players555 map<unsigned int, Player*>::iterator it;556 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)557 {558 it->second->updateTarget(mapPlayers);559 }560 561 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)562 {563 it->second->move(gameMap); // ignore return value564 }565 566 // update projectile positions567 map<unsigned int, Projectile>::iterator it2;568 for (it2 = mapProjectiles.begin(); it2 != mapProjectiles.end(); it2++)569 {570 it2->second.move(mapPlayers);571 }572 573 GameRender::drawMap(gameMap);574 GameRender::drawPlayers(mapPlayers, font, curPlayerId);575 576 // draw projectiles577 for (it2 = mapProjectiles.begin(); it2 != mapProjectiles.end(); it2++)578 {579 Projectile proj = it2->second;580 581 FLOAT_POSITION target = mapPlayers[proj.target]->pos;582 float angle = atan2(target.y-proj.pos.toFloat().y, target.x-proj.pos.toFloat().x);583 584 POSITION start, end;585 start.x = cos(angle)*15+proj.pos.x;586 start.y = sin(angle)*15+proj.pos.y;587 end.x = proj.pos.x;588 end.y = proj.pos.y;589 590 start = mapToScreen(start);591 end = mapToScreen(end);592 593 al_draw_line(start.x, start.y, end.x, end.y, al_map_rgb(0, 0, 0), 4);594 }595 }else if (wndCurrent == wndGameSummary) {596 546 ostringstream ossBlueScore, ossRedScore; 597 547 … … 631 581 shutdownWinSock(); 632 582 583 // delete all components 584 for (unsigned int x=0; x<vctComponents.size(); x++) 585 delete vctComponents[x]; 586 633 587 delete wndLogin; 634 588 delete wndRegister; 635 589 delete wndLobby; 636 delete wndGame; 637 delete wndGameDebug; 590 delete wndLobbyDebug; 591 delete wndNewGame; 592 delete wndGameSummary; 638 593 639 594 delete gameMap;
Note:
See TracChangeset
for help on using the changeset viewer.