1
Network / Re: UDP receive method not compiling
« on: May 06, 2025, 11:08:27 pm »
That solved it, also the PORT was assumed int because I used #define, it should be an unsigned short so I created a variable, thanks!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
#define IP 191, 168, 1, 50
#define PORT 54000
...
sf::UdpSocket socket;
sf::IpAddress sender(IP); // I had to add the IP here because it gave me an error if I left it like in the tutorial
std::uint16_t x;
std::string s;
double d;
sf::Packet packet;
packet >> x >> s >> d;
...
if (socket.receive(packet, sender, PORT) != sf::Socket::Status::Done)
{
// error
}
if (_currentEvent.type == sf::Event::EventType::JoystickButtonReleased && _currentEvent.joystickButton.joystickId == 0 && _currentEvent.joystickButton.button == _gamepadOne->getButtonNumber(Gamepad::GAMEPAD_BUTTON::btn_start))
/// do something
void FieldPlayer::draw()
{
sf::Vector2f spritePos = sf::Vector2f(Game::SCALE * m_body->GetPosition().x, Game::SCALE * m_body->GetPosition().y);
float degreesOfRotation = Game::RadiansToDegrees(m_body->GetAngle());
m_sprite.setPosition(spritePos);
m_sprite.setRotation(degreesOfRotation);
Game::GetWindow()->draw(m_sprite);
if (PlayerState.sliding) {
// 80cm to the back of the player (local y axis)
b2Vec2 headPosSliding = m_body->GetPosition() - (0.8 * getHeading());
// 24cm to the left of the player (local x axis)
headPosSliding -= 0.24f * getSide(false);
spritePos = Game::BoxVecToSfVec(headPosSliding);
// slightly to the right of the body
degreesOfRotation += 30.f;
}
head_sprite.setPosition(spritePos);
head_sprite.setRotation(degreesOfRotation);
Game::GetWindow()->draw(head_sprite);
}
void FieldPlayer::draw()
{
m_sprite.setPosition(Game::SCALE * m_body->GetPosition().x, Game::SCALE * m_body->GetPosition().y);
m_sprite.setRotation(Game::RadiansToDegrees(m_body->GetAngle()));
Game::GetWindow()->draw(m_sprite);
sf::Vector2f offset(0.f, 0.f);
if (PlayerState.sliding) offset = sf::Vector2f(-1.4f, -0.8f);
head_sprite.setPosition(Game::SCALE * (m_body->GetPosition().x + offset.x), Game::SCALE * (m_body->GetPosition().y + offset.y));
head_sprite.setRotation(Game::RadiansToDegrees(m_body->GetAngle()));
Game::GetWindow()->draw(head_sprite);
}
m_sprite.setPosition(Game::SCALE * m_body->GetPosition());
void FieldPlayer::draw()
{
m_sprite.setPosition(Game::SCALE * m_body->GetPosition().x, Game::SCALE * m_body->GetPosition().y);
m_sprite.setRotation(Game::RadiansToDegrees(m_body->GetAngle()));
Game::GetWindow()->draw(m_sprite);
head_sprite.setPosition(Game::SCALE * m_body->GetPosition().x, Game::SCALE * m_body->GetPosition().y);
head_sprite.setRotation(Game::RadiansToDegrees(m_body->GetAngle()));
// move the head back if sliding
if (PlayerState.sliding) {
sf::Transform t = head_sprite.getTransform();
t.translate(-52.f, -10.f); ???
Game::GetWindow()->draw(head_sprite, t);
}
else {
Game::GetWindow()->draw(head_sprite);
}
}