Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void game::draw() {
- gameNetworkObj->jsonMutex.lock(); //will lock the gameData resource
- //std::cout << "locked resource" << std::endl;
- if (!gameData.is_null()) { //it now moves it
- sf::CircleShape circleThing(60, 60);
- circleThing.setOrigin(-60, 60);
- sf::RectangleShape rectangle(sf::Vector2f(gameWindow->getSize().x, gameWindow->getSize().y / 2));
- rectangle.setPosition(sf::Vector2f(-int(gameWindow->getSize().x) / 2, 0));
- gameWindow->draw(circleThing);
- gameWindow->draw(rectangle);
- for (int j = 0; j < 8; j++) {
- json chunkToDraw = json::parse(gameData["chunks"][j].get<std::string>());
- //std::cout << chunkToDraw.dump() << std::endl;
- if (chunkToDraw.dump() != "null") {
- //std::cout << chunkToDraw.dump() << std::endl;
- for (int i = 0; i < chunkToDraw["entityCount"]; i++) {
- //std::cout << gameNetworkObj->unixMicrosecondsOfLastPacket << ": " << chunkToDraw["entities"][0]["location"]["x"].get<float>() << " -- " << chunkToDraw["entities"][0]["location"]["y"].get<float>() << std::endl;
- if (networkObj->userID == chunkToDraw["entities"][i]["id"].get<int>()) {
- std::cout << "x: " << chunkToDraw["entities"][i]["location"]["x"].get<float>() * 10 << " -- y: " << chunkToDraw["entities"][i]["location"]["y"].get<float>() * 10 << std::endl;
- gameView->setCenter(chunkToDraw["entities"][i]["location"]["x"].get<float>() * 10, chunkToDraw["entities"][i]["location"]["y"].get<float>() * 10);
- sf::RectangleShape player(sf::Vector2f(40, 40));
- player.setOrigin(-20, 40);
- player.setFillColor(sf::Color::Blue);
- player.setPosition(chunkToDraw["entities"][i]["location"]["x"].get<float>() * 10, chunkToDraw["entities"][i]["location"]["y"].get<float>() * 10);
- gameWindow->draw(player);
- }
- else {
- sf::RectangleShape opponent(sf::Vector2f(40, 40));
- opponent.setOrigin(-20, 40);
- opponent.setFillColor(sf::Color::Red);
- opponent.setPosition(chunkToDraw["entities"][i]["location"]["x"].get<float>() * 10, chunkToDraw["entities"][i]["location"]["y"].get<float>() * 10);
- gameWindow->draw(opponent);
- }
- }
- }
- }
- }
- gameNetworkObj->jsonMutex.unlock(); //will free the resource
- }
- void game::live() {
- if (changeInButtonState && !networkObj->msgBoxFocused) {
- gameNetworkObj->sendData(keysObject); //sends the object to the server
- //we're resetting some of them here, as they just do a single action, rather than move or whatever
- keysObject["interactNPC"] = false;
- keysObject["switchTarget"] = false;
- changeInButtonState = false; //reset this so that we don't repeatedly send the same data to the server
- }
- draw(); //will draw the actual game
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement