Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.67 KB | None | 0 0
  1. void game::draw() {
  2.     gameNetworkObj->jsonMutex.lock(); //will lock the gameData resource
  3.     //std::cout << "locked resource" << std::endl;
  4.  
  5.     if (!gameData.is_null()) {  //it now moves it
  6.         sf::CircleShape circleThing(60, 60);
  7.         circleThing.setOrigin(-60, 60);
  8.         sf::RectangleShape rectangle(sf::Vector2f(gameWindow->getSize().x, gameWindow->getSize().y / 2));
  9.         rectangle.setPosition(sf::Vector2f(-int(gameWindow->getSize().x) / 2, 0));
  10.         gameWindow->draw(circleThing);
  11.         gameWindow->draw(rectangle);
  12.         for (int j = 0; j < 8; j++) {
  13.             json chunkToDraw = json::parse(gameData["chunks"][j].get<std::string>());
  14.             //std::cout << chunkToDraw.dump() << std::endl;
  15.             if (chunkToDraw.dump() != "null") {
  16.                 //std::cout << chunkToDraw.dump() << std::endl;
  17.                 for (int i = 0; i < chunkToDraw["entityCount"]; i++) {
  18.                
  19.                     //std::cout << gameNetworkObj->unixMicrosecondsOfLastPacket << ": " << chunkToDraw["entities"][0]["location"]["x"].get<float>() << " -- " << chunkToDraw["entities"][0]["location"]["y"].get<float>() << std::endl;
  20.  
  21.                     if (networkObj->userID == chunkToDraw["entities"][i]["id"].get<int>()) {
  22.                         std::cout << "x: " << chunkToDraw["entities"][i]["location"]["x"].get<float>() * 10 << " -- y: " << chunkToDraw["entities"][i]["location"]["y"].get<float>() * 10 << std::endl;
  23.                         gameView->setCenter(chunkToDraw["entities"][i]["location"]["x"].get<float>() * 10, chunkToDraw["entities"][i]["location"]["y"].get<float>() * 10);
  24.                         sf::RectangleShape player(sf::Vector2f(40, 40));
  25.                         player.setOrigin(-20, 40);
  26.                         player.setFillColor(sf::Color::Blue);
  27.                         player.setPosition(chunkToDraw["entities"][i]["location"]["x"].get<float>() * 10, chunkToDraw["entities"][i]["location"]["y"].get<float>() * 10);
  28.  
  29.                         gameWindow->draw(player);
  30.                     }
  31.                     else {
  32.                         sf::RectangleShape opponent(sf::Vector2f(40, 40));
  33.                         opponent.setOrigin(-20, 40);
  34.                         opponent.setFillColor(sf::Color::Red);
  35.                         opponent.setPosition(chunkToDraw["entities"][i]["location"]["x"].get<float>() * 10, chunkToDraw["entities"][i]["location"]["y"].get<float>() * 10);
  36.  
  37.                         gameWindow->draw(opponent);
  38.                     }
  39.                 }
  40.             }
  41.         }
  42.     }
  43.  
  44.     gameNetworkObj->jsonMutex.unlock(); //will free the resource
  45. }
  46.  
  47. void game::live() {
  48.     if (changeInButtonState && !networkObj->msgBoxFocused) {
  49.         gameNetworkObj->sendData(keysObject); //sends the object to the server
  50.  
  51.         //we're resetting some of them here, as they just do a single action, rather than move or whatever
  52.         keysObject["interactNPC"] = false;
  53.         keysObject["switchTarget"] = false;
  54.  
  55.         changeInButtonState = false; //reset this so that we don't repeatedly send the same data to the server
  56.     }
  57.     draw(); //will draw the actual game
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement