Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

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.


Messages - floppa_dev

Pages: [1] 2
1
General / Re: strange behaviour caused by a simple variable change
« on: January 16, 2025, 08:16:20 pm »
rewriting?  :-\
also can you please tell some way to generate a fast collision system?
thank you so much for your time

3
General / strange behaviour caused by a simple variable change
« on: January 14, 2025, 02:23:01 pm »
Hello again! Last week I posted a question about compiling SFML, now I need some help in my code.
I inserted two clips that show the problem: objects glitch through eachother after about 10 objects inserted.
My assumtion is the following:
1.The vector in col when is cleared it remains with a zero? so that messes up the collision tehnique
2.the function build_col is wrong and needs to be redone
I am trying to implement square trees or what are they called to improve my naive collision system
Code:
main.cpp
#include "header.hpp"
#include <fstream>
int main()
{
    pushing(0, WINHEIGHT - 1, WINWIDTH, 100, 1);
    // std::cout<<pool[0].obj.getPosition().y<<&#39; &#39;<<pool[0].obj.getPosition().y;
    srand(time(NULL));
    sf::RenderWindow window(sf::VideoMode({WINWIDTH, WINHEIGHT}), "Physics");
    window.setFramerateLimit(60);
    Clock clock;
    clock.start();
    while (window.isOpen())
    {
        delete_col();
        build_col();
        for (int k = 0; k < pool.size(); k++)
        {

            pool[k].obj.setPosition(pool[k].obj.getPosition() + Vector2f(float(pool[k].momentumx), float(pool[k].momentumy)));
        }
        /*for (int i = 1; i <= part; i++)
        {

            for (int j = 1; j <= part; j++)
            {
                 std::cout<<"\n ."<<col[i][j].size();
            }
        }*/

        int s = 0;
        for (int i = 1; i <= part; i++)
        {

            for (int j = 1; j <= part; j++)
            {
                s += int(col[i][j].size());
                for (int k = 0; k < int(col[i][j].size()) - 1; k++)
                {
                   

                    for (int r = k + 1; r < int(col[i][j].size()); r++)
                    {

                        if (colision(pool[k], pool[r]) == 1)
                        {
                            if (r == col[i][j].size())
                                std::cout << 1;
                            pool[k].momentumy = pool[k].momentumx = pool[r].momentumx = pool[r].momentumy = 0;
                        }
                    }
                }
                std::cout<<&#39;\n&#39;;
            }
        }
        /*for (int i = 0; i < pool.size(); i++)
         {
         //naive
             pool[i].obj.setPosition(pool[i].obj.getPosition() + Vector2f(0, float(pool[i].momentumy)));
             for(int j = i + 1; j<pool.size(); j++)
             {

                 if(colision(pool[i], pool[j]) == 1)
                 {
                     pool[i].momentumx=pool[i].momentumy=0;
                     pool[j].momentumx=pool[j].momentumy=0;

                 }
             }


         }*/

        //
        if (clock.getElapsedTime() >= seconds(1))
        {
            for (int i = 0; i < pool.size(); i++)
            {
                if (pool[i].obj.getPosition().y > WINHEIGHT || pool[i].obj.getPosition().y + pool[i].obj.getSize().y < 0)
                    pool.erase(pool.begin() + i);
            }
            clock.restart();
        }
        while (const std::optional event = window.pollEvent())
        {
            if (event->is<sf::Event::Closed>())
                window.close();
            else if (event->is<Event::MouseButtonPressed>())
            {
                int Mousex, Mousey;
                Mousex = Mouse::getPosition(window).x;
                Mousey = Mouse::getPosition(window).y;
                pushing(Mousex, Mousey, 50, 50);
            }
        }
        window.clear(Color::Black);

        for (int i = 0; i < pool.size(); i++)
            window.draw(pool[i].obj);

        window.display();
    }

    return 0;
}
 
header.hpp
#include <SFML/Graphics.hpp>
#include <vector>
#include <iostream>
#include <random>
#define WINWIDTH 1000
#define WINHEIGHT 800
#define part 4 // this is the problem first recording the part was set to 2
using namespace sf;
const int gravity = 10;
class object
{
public:
    RectangleShape obj;
    Vector2f pos;
    float mass = 0.5;
    bool physics = true;
    float momentumx=0,momentumy = 0;
    int collisioncoef = 0;
    bool immutable = false;
    object() : obj(Vector2f(100.f, 100.f)) {}
    void create(int x, int y, Color color, bool imm, int Xsize, int Ysize);
};

void object::create(int x, int y, Color color, bool imm = true, int Xsize=100, int Ysize=100)
{
    pos = Vector2f(static_cast<float>(x), static_cast<float>(y));
    obj.setSize({static_cast<float>(Xsize), static_cast<float>(Ysize)});
   //std::cout<<pos.y;
    obj.setPosition(pos);
    obj.setFillColor(color);
    immutable = imm;
    momentumy = gravity * (!immutable);
}
std::vector<object> pool;
void pushing(int Xpos = -1, int Ypos = -1, int Xsize = 100, int Ysize = 100, bool imm = false)
{
    object r;

    int getsizex = WINWIDTH - Xsize;
    int getsizey = WINHEIGHT - Ysize;

    if (Xpos == -1 || Ypos == -1)
    {
        Xpos = rand() % getsizex;
        Ypos = rand() % getsizey;
    }

    Color randomcolor(rand() % 256, rand() % 256, rand() % 256);

    r.create(Xpos, Ypos, randomcolor, imm, Xsize, Ysize);


    pool.push_back(r);
}

bool colision(object &o1, object &o2)
{
    if(o1.obj.getGlobalBounds().findIntersection(o2.obj.getGlobalBounds()))
    {
        if(o1.obj.getPosition().y<o2.obj.getPosition().y)
        {
            o1.obj.setPosition(Vector2f(o1.obj.getPosition().x, o2.obj.getPosition().y) + Vector2f(0,float(-o1.obj.getSize().y)));
        }
        else
        {
            o2.obj.setPosition(Vector2f(o2.obj.getPosition().x, o1.obj.getPosition().y)+ Vector2f(0,float(-o2.obj.getSize().y)));
        }
        return 1;
    }
    return 0;
}
std::vector<int> col[part + 4][part + 4];
int px = WINWIDTH / part, py = WINHEIGHT / part;
void build_col()
{
   
    //lazy way
   /* object col2[part+1][part+1];
    //lazy init
    for(int i = 1; i<=part; i++)
    {
        for(int j = 1; j<=part; j++)
        {
            col2[i][j].create((i-1)*px, (j-1)*py, Color::Red,true,px,py);
        }
    }*/

    int sx,sy,fx,fy;//from where to start and to finish pushing back the value
    int posx,posy,sizex,sizey;
    //std::cout<<1;
    for(int i = 0; i<pool.size(); i++)
    {
        posx = pool[i].obj.getPosition().x;
        posy = pool[i].obj.getPosition().y;
        sizex = pool[i].obj.getSize().x;
        sizey = pool[i].obj.getSize().y;
        sx = posx/px + !bool(posx%px);
        sy = posy/py + !bool(posy%py);
        posx+=sizex;
        posy+=sizey;
        fx = posx/px + !bool(!posx%px);
        fy = posy/py + !bool(!posy%py);
      // std::cout<<&#39;\n&#39;<<fx-sx<<&#39; &#39;<<fy-fx;
        for(int j = sx; j<=fx; j++)
        {
            for(int k = sy; k<=fy; k++)
            {
               
                col[j][k].push_back(i);
            }
        }
    }
   // std::cout<<1;
}
void delete_col()
{
    for(int i = 0; i<=part; i++)
    {
        for(int j = 0; j<=part; j++)
        {
            col[i][j].clear();
        }
    }
}

4
General / Re: Linking SFML 2.6.1(I will upgrade but not now) to Makefile
« on: January 09, 2025, 04:21:01 pm »
yes it worked thank you

5
General / Re: Linking SFML 2.6.1(I will upgrade but not now) to Makefile
« on: January 09, 2025, 04:18:13 pm »
ok thanks I will reply later if this helped

6
General / Re: Linking SFML 2.6.1(I will upgrade but not now) to Makefile
« on: January 09, 2025, 03:56:50 pm »
when i try to run the exe i get this error
The procedure entry point _ZNSt15basic_streambuflcSt11char_traitslcEE7seekposESt4posliESt13_Ios_Openmode could not be located in the dynamic link library (path to system32)\sfml-system-2.dll

7
General / Linking SFML 2.6.1(I will upgrade but not now) to Makefile
« on: January 09, 2025, 03:10:59 pm »
Hello! I have this Makefile(VScode + mingw(msys2 on default settings))
I have 1 tab as space
all:run
CC=g++
CFLAGS=-O1 -Wall -std=c++17 -Wno-missing-braces -I./include/ -L ./lib/ -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio
TARGET=main.exe
SRC=src/main.cpp
$(TARGET): $(SRC) Makefile
        $(CC) $< -o $@ $(CFLAGS)
build: $(TARGET)
run: build
        ./$(TARGET)

 
but I get this error make: *** [Makefile:10: run] Error -1073741511
D:.
my file tree
-   .gitignore
-   main.exe
-   Makefile
-   README.md
-   sfml-audio-2.dll
-   sfml-audio-d-2.dll
-   sfml-graphics-2.dll
-   sfml-graphics-d-2.dll
-   sfml-network-2.dll
-   sfml-network-d-2.dll
-   sfml-system-2.dll
-   sfml-system-d-2.dll
-   sfml-window-2.dll
-   sfml-window-d-2.dll
-   tree.txt
-  
+¦¦¦.github
-   L¦¦¦workflows
-           jekyll-gh-pages.yml
-           static.yml
-          
+¦¦¦include
-   -   desktop.ini
-   -  
-   L¦¦¦SFML
-       -   Audio.hpp
-       -   Config.hpp
-       -   desktop.ini
-       -   GpuPreference.hpp
-       -   Graphics.hpp
-       -   Main.hpp
-       -   Network.hpp
-       -   OpenGL.hpp
-       -   System.hpp
-       -   Window.hpp
-       -  
-       +¦¦¦Audio
-       -       AlResource.hpp
-       -       desktop.ini
-       -       Export.hpp
-       -       InputSoundFile.hpp
-       -       Listener.hpp
-       -       Music.hpp
-       -       OutputSoundFile.hpp
-       -       Sound.hpp
-       -       SoundBuffer.hpp
-       -       SoundBufferRecorder.hpp
-       -       SoundFileFactory.hpp
-       -       SoundFileFactory.inl
-       -       SoundFileReader.hpp
-       -       SoundFileWriter.hpp
-       -       SoundRecorder.hpp
-       -       SoundSource.hpp
-       -       SoundStream.hpp
-       -      
-       +¦¦¦Graphics
-       -       BlendMode.hpp
-       -       CircleShape.hpp
-       -       Color.hpp
-       -       ConvexShape.hpp
-       -       desktop.ini
-       -       Drawable.hpp
-       -       Export.hpp
-       -       Font.hpp
-       -       Glsl.hpp
-       -       Glsl.inl
-       -       Glyph.hpp
-       -       Image.hpp
-       -       PrimitiveType.hpp
-       -       Rect.hpp
-       -       Rect.inl
-       -       RectangleShape.hpp
-       -       RenderStates.hpp
-       -       RenderTarget.hpp
-       -       RenderTexture.hpp
-       -       RenderWindow.hpp
-       -       Shader.hpp
-       -       Shape.hpp
-       -       Sprite.hpp
-       -       Text.hpp
-       -       Texture.hpp
-       -       Transform.hpp
-       -       Transformable.hpp
-       -       Vertex.hpp
-       -       VertexArray.hpp
-       -       VertexBuffer.hpp
-       -       View.hpp
-       -      
-       +¦¦¦Network
-       -       desktop.ini
-       -       Export.hpp
-       -       Ftp.hpp
-       -       Http.hpp
-       -       IpAddress.hpp
-       -       Packet.hpp
-       -       Socket.hpp
-       -       SocketHandle.hpp
-       -       SocketSelector.hpp
-       -       TcpListener.hpp
-       -       TcpSocket.hpp
-       -       UdpSocket.hpp
-       -      
-       +¦¦¦System
-       -       Clock.hpp
-       -       desktop.ini
-       -       Err.hpp
-       -       Export.hpp
-       -       FileInputStream.hpp
-       -       InputStream.hpp
-       -       Lock.hpp
-       -       MemoryInputStream.hpp
-       -       Mutex.hpp
-       -       NativeActivity.hpp
-       -       NonCopyable.hpp
-       -       Sleep.hpp
-       -       String.hpp
-       -       String.inl
-       -       Thread.hpp
-       -       Thread.inl
-       -       ThreadLocal.hpp
-       -       ThreadLocalPtr.hpp
-       -       ThreadLocalPtr.inl
-       -       Time.hpp
-       -       Utf.hpp
-       -       Utf.inl
-       -       Vector2.hpp
-       -       Vector2.inl
-       -       Vector3.hpp
-       -       Vector3.inl
-       -      
-       L¦¦¦Window
-               Clipboard.hpp
-               Context.hpp
-               ContextSettings.hpp
-               Cursor.hpp
-               desktop.ini
-               Event.hpp
-               Export.hpp
-               GlResource.hpp
-               Joystick.hpp
-               Keyboard.hpp
-               Mouse.hpp
-               Sensor.hpp
-               Touch.hpp
-               VideoMode.hpp
-               Window.hpp
-               WindowHandle.hpp
-               WindowStyle.hpp
-              
+¦¦¦lib
-   -   libFLAC.a
-   -   libfreetype.a
-   -   libogg.a
-   -   libopenal32.a
-   -   libsfml-audio-d.a
-   -   libsfml-audio-s-d.a
-   -   libsfml-audio-s.a
-   -   libsfml-audio.a
-   -   libsfml-graphics-d.a
-   -   libsfml-graphics-s-d.a
-   -   libsfml-graphics-s.a
-   -   libsfml-graphics.a
-   -   libsfml-main-d.a
-   -   libsfml-main.a
-   -   libsfml-network-d.a
-   -   libsfml-network-s-d.a
-   -   libsfml-network-s.a
-   -   libsfml-network.a
-   -   libsfml-system-d.a
-   -   libsfml-system-s-d.a
-   -   libsfml-system-s.a
-   -   libsfml-system.a
-   -   libsfml-window-d.a
-   -   libsfml-window-s-d.a
-   -   libsfml-window-s.a
-   -   libsfml-window.a
-   -   libvorbis.a
-   -   libvorbisenc.a
-   -   libvorbisfile.a
-   -  
-   L¦¦¦cmake
-       L¦¦¦SFML
-               SFMLConfig.cmake
-               SFMLConfigDependencies.cmake
-               SFMLConfigVersion.cmake
-               SFMLSharedTargets-debug.cmake
-               SFMLSharedTargets-release.cmake
-               SFMLSharedTargets.cmake
-               SFMLStaticTargets-debug.cmake
-               SFMLStaticTargets-release.cmake
-               SFMLStaticTargets.cmake
-              
L¦¦¦src
        main.cpp
main.cpp
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}
 

8
General / console disable c++
« on: March 31, 2023, 01:43:33 pm »
how can i hide console c++ from showing, like when i send my project to my friend his console to be hidden

9
General / Re: [Solved]Textures aren't showing
« on: January 23, 2023, 09:57:09 am »
tq

10
General / [Solved]Textures aren't showing
« on: January 21, 2023, 12:03:42 pm »
The textures arent showing
I will put my project below
In advance, thank you
main.cpp:
// Comp issues win any rez other tham 1920*1080
#include "smth.hpp"
#include "grass.cpp"
using namespace sf;
int main()
{
    init_grass();
    Object player, bg;
    player.position = {960, 100};
    bg.position = {0, 0};
    if (!player.texture.loadFromFile("Images/big-floppa-player.png") || !bg.texture.loadFromFile("Images/bg.jpg"))
    {
        return -1;
    }
    player.position = {0, 100};
    player.sprite.setTexture(player.texture);
    bg.sprite.setTexture(bg.texture);
    RenderWindow window(sf::VideoMode(1920, 1080), "Super Floppa", Style::Fullscreen);
    Clock clock;
    while (window.isOpen())
    {
        Event event;
        while (window.pollEvent(event))
        {
            sf::Time elapsed = clock.restart();
            float dt = elapsed.asSeconds();
            if (event.type == Event::Closed || Mouse::isButtonPressed(Mouse::Right))
                window.close();
            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.clear();
            window.draw(bg.sprite);
            window.draw(grass);
            display_smth(player, window);
            while (!touch_grass_lol(player, grass))
            {
                player.position += {0.f, 10.f};
            }
            std::cout << player.position.x << &#39;-&#39; << player.position.y << &#39;\n&#39;;
            window.display();
            if (dt < 1.f / 60.f)
            {
                sleep(sf::seconds(1.f / 60.f - dt));
            }
        }
    }
    return 0;
}
// no credits here
//------------------
grass.cpp
#include <SFML/Graphics.hpp>
#include "smth.hpp"
using namespace sf;
RectangleShape grass(Vector2f(1920.f, 100.f));
void init_grass()
{

    Texture grass_tex;
    if (!grass_tex.loadFromFile("Images/grass.png"))
    {
        std::cout << -1192919929;
    }
    grass.setTexture(&grass_tex);
    grass.setPosition(0, 980);
}
// my friend ... needs to (-insert someone name-)
bool touch_grass_lol(Object &object, RectangleShape grass)
{
    if (object.sprite.getGlobalBounds().intersects(grass.getGlobalBounds()))
        return 1;
    return 0;
}
 
smth.hpp
#pragma once
#include <SFML/Graphics.hpp>
#include <SFML/Window/VideoMode.hpp>
#include <SFML/System.hpp>
#include <iostream>
#include <cmath>
const double PI = 3.14159265358979323846;
struct Object
{
    sf::Vector2f position;
    float angle;
    sf::Sprite sprite;
    sf::Texture texture;
};

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&#39;s position
    object.position.x += dx;
    object.position.y += dy;

    // Update the object&#39;s sprite position
    object.sprite.setPosition(object.position);
}
void display_smth(Object &object, RenderWindow &window)
{
    object.sprite.setPosition(object.position);
    window.draw(object.sprite);
}
/*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;
}*/

11
General / Re: Error
« on: January 17, 2023, 03:41:36 pm »
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&#39;s position
    object.position.x += dx;
    object.position.y += dy;

    // Update the object&#39;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

12
General / Re: Error
« on: January 16, 2023, 03:51:06 pm »
.

13
General / Re: Error
« on: January 16, 2023, 02:34:30 pm »
in the same folder or at src/dll? (src is the source folder)

14
General / [Please help]Error
« on: January 15, 2023, 09:07:09 am »
mingw32-make: *** [Makefile:11: run] Error -1073741819
code:
all:run
CC=g++
CFLAGS=-O1 -Wall -std=c++17 -Wno-missing-braces -I ./include/ -L ./lib/ -lsfml-graphics -lsfml-window -lsfml-system
TARGET=floppa.exe
SRC=src/main.cpp
DEPS=src/smth.hpp
$(TARGET): $(SRC) $(DEPS) Makefile
   $(CC) $< -o $@ $(CFLAGS)
build: $(TARGET)
run: build
   ./$(TARGET)

15
General / Re: Error
« on: January 12, 2023, 03:13:23 pm »
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;
    }
}
 

Pages: [1] 2