didnt helped
heres the full code:
main.cpp
// Comp issues win any rez other tham 1920*1080
#include "smth.hpp"
using namespace sf;
void display_smth(Object &object, RenderWindow &window)
{
object.sprite.setPosition(object.position);
window.draw(object.sprite);
}
int main()
{
Object player = {{960, 540}, 0}, bg{{1000, 1000}, 0}, bullet{{0, 0}, 0};
if (!player.texture.loadFromFile("Images/big-floppa-player.png") || !bg.texture.loadFromFile("Images/bg.jpg"))
{
return -1;
}
// grass.texture.loadFromFile("Images/grass.png");
// grass.sprite.setTexture(grass.texture);
player.sprite.setOrigin(player.sprite.getTexture()->getSize().x * player.sprite.getScale().x / 2, player.sprite.getTexture()->getSize().y * player.sprite.getScale().y / 2);
bg.sprite.setTexture(bg.texture);
RenderWindow window(sf::VideoMode(500, 500), "Super Floppa", Style::Fullscreen);
while (window.isOpen())
{
Event event;
// bg.sprite.setScale(VideoMode::getDesktopMode()/bg.sprite.getTexture()->getSize().x);
bg.sprite.setScale(window.getSize().x / bg.sprite.getTexture()->getSize().x, window.getSize().y / bg.sprite.getTexture()->getSize().y);
while (window.pollEvent(event))
{
if (event.type == Event::Closed || Mouse::isButtonPressed(Mouse::Right))
window.close();
// moveObject(object, 10, 45); <-bullet
if (Keyboard::isKeyPressed(Keyboard::A))
player.position += {-10.f, 0.f};
if (Keyboard::isKeyPressed(Keyboard::D))
player.position += {10.f, 0.f};
if (Keyboard::isKeyPressed(Keyboard::W))
player.position += {0.f, -10.f};
if (Keyboard::isKeyPressed(Keyboard::S))
player.position += {0.f, 10.f};
window.draw(bg.sprite);
display_smth(player, window);
display_smth(bullet, window);
/* for (int i = 1; i <= window.getSize().y / 100; i++)
{
grass.position = {int(window.getSize().x) + 100 * i, 0};
display_smth(grass, window);
}
*/
window.display();
window.clear();
// if (!bullet.sprite.getGlobalBounds().intersects.bg.getGlobalBounds())
// update_pos(bullet, player);
}
}
// std::cout << window.getSize().x / bg.sprite.getTexture()->getSize().x;
return 0;
}
smth.hpp
#pragma once
#include <SFML/Graphics.hpp>
#include <SFML/Window/VideoMode.hpp>
#include <iostream>
#include <cmath>
const double PI = 3.14159265358979323846;
struct Object
{
sf::Vector2f position;
float angle;
sf::Sprite sprite;
sf::Texture texture;
} grass;
void update_pos(Object &object1, Object &object2)
{
object1.position = object2.position;
}
void moveObject_angle(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);
}
/*bool jump(int f)
{
int o = f;
f-= o/10;
player.position += player.position += {0.f, f};
if(player.getGlobalBounds.itersects.grass.sprite)
return 0;
}*/
plsssss