i fixed it somehow, but now the window crashes instantly
heres the code:
#include <SFML/Graphics.hpp>
#include <cmath>
using namespace sf;
const float PI = 3.14159265358979323846;
// Struct to represent an object with a position, angle, sprite, and texture
struct Object
{
sf::Vector2f position;
float angle;
sf::Sprite sprite;
sf::Texture texture;
};
// Function to move the object by a specified distance at the specified angle
void moveObject(Object &object, float distance, float angle)
{
// Calculate the displacement in the x and y directions
float dx = distance * cos(angle * PI / 180.0f);
float dy = distance * sin(angle * PI / 180.0f);
// Update the object's position
object.position.x += dx;
object.position.y += dy;
// Update the object's sprite position
object.sprite.setPosition(object.position);
}
int main()
{
// Create an object at position (0, 0) with an angle of 0 degrees
Object player = {{0, 0}, 0}, bg{{0, 0}, 0};
// Load an image for the object's texture
if (!player.texture.loadFromFile("Images/big-floppa-player.png") || !bg.texture.loadFromFile("Images/bg.jpg"))
{
return -1;
}
// Set the object's texture for the sprite
player.sprite.setTexture(player.texture);
bg.sprite.setTexture(bg.texture);
RenderWindow window(sf::VideoMode(500, 500), "Super Floppa", Style::Fullscreen);
while (window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
if (event.type == Event::Closed || Mouse::isButtonPressed(Mouse::Right))
window.close();
// moveObject(object, 10, 45);
window.draw(bg.sprite);
window.draw(player.sprite);
if (Keyboard::isKeyPressed(Keyboard::A))
player.position += {-1.f, 0.f};
if (Keyboard::isKeyPressed(Keyboard::D))
player.position += {1.f, 0.f};
if (Keyboard::isKeyPressed(Keyboard::W))
player.position += {0.f, -1.f};
if (Keyboard::isKeyPressed(Keyboard::S))
player.position += {0.f, 1.f};
window.draw(player.sprite);
window.display();
}
return 0;
}
}