SFML и C++ Уроки \ Разработка игр › Форумы › SFML Network › Ошибка при компиляции строки socket.receive(); › Ответ в теме: Ошибка при компиляции строки socket.receive();
Вот весь класс:
C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
#include <SFML/Graphics.hpp> #include <SFML/Network.hpp> #include <iostream> //#include "ClientMultiplayer.cpp"; // Мультилпеерная часть клиента using namespace std; using namespace sf; class Player { public: // Multiplayer int x, y = 0; string stringIp; IpAddress myIp = IpAddress::getPublicAddress(); IpAddress serverip; UdpSocket socket; Packet packet; Packet packetip; // Текущие координаты персонажа int coordX; int coordY; //======== // Player double speed = 2.5; int side; Texture texture; Sprite sprite; Player(String File, int x, int y, int side) { // Дописать отправку на сервер координат и side(направление) this->side = side; texture.loadFromFile(File); if (!texture.loadFromFile(File)) { std::cout << "Error"; } sprite.setTexture(texture); switch (side) { //Блок side case 1: sprite.setTextureRect(IntRect(202, 0, 100, 100)); // поворот на лево break; case 2: sprite.setTextureRect(IntRect(101, 0, 100, 100)); // поворот на право break; case 3: sprite.setTextureRect(IntRect(0, 0, 100, 100)); // поворот вверх break; case 4: sprite.setTextureRect(IntRect(303, 0, 100, 100)); // поворот вниз break; } sprite.setPosition(x, y); } void controlling(float time) { // side тут нужен для отправки на сервер данных о том куда повернут персонаж(переделать его) coordX = sprite.getPosition().x; coordY = sprite.getPosition().y; if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { sprite.move(-speed*time, 0); sprite.setTextureRect(IntRect(202, 0, 100, 100)); side = 1; } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { sprite.move(speed*time, 0); sprite.setTextureRect(IntRect(101, 0, 100, 100)); side = 2; } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { sprite.move(0, -speed*time); sprite.setTextureRect(IntRect(0, 0, 100, 100)); side = 3; } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { sprite.move(0, speed*time); sprite.setTextureRect(IntRect(303, 0, 100, 100)); side = 4; } } void coordinate() { // Вывод координат cout << "coordinate xx: " << coordX << " y: " << coordY << "\n"; } // Multiplayer void receiveCoordinate() { // Получает данные координаты + сторону движения socket.receive(packet, serverip, 2000); packet >> x >> y >> side; drawingOtherSprite(); } void sendPacket() { // Отправка данных серверу } void connectionServer() { // Функция приконекта к серверу socket.bind(2000); stringIp = myIp.toString(); packetip << stringIp; socket.send(packetip, serverip, 2000); packetip.clear(); } void drawingOtherSprite() { // Для отрисовки Player otherplayer("image/people.png", x, y, side); // заменить на sprite.setPosition(x, y); + switch side } }; |