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 - jakub

Pages: [1]
1
General / Re: Moving springs separately
« on: January 24, 2023, 04:10:19 pm »
It works  ;D

2
General / Re: Moving springs separately
« on: January 24, 2023, 02:47:38 pm »
With shapes it works good but not with sprites.
dinosaur::dinosaur()
{
        isTextureLoaded();
        isSpriteLoaded();
        up = false;
        down = false;
        left = false;
        right = false;
}

bool dinosaur::isTextureLoaded()
{
        if (!texture.loadFromFile("download.png"));
        return EXIT_FAILURE;
}


void dinosaur::isSpriteLoaded()
{
        sprite.setTexture(texture);

}

int main()
{
        dinosaur dino;
        godzilla god;//

        god.sprite.setScale(0.3, 0.3);


        sf::RenderWindow window(sf::VideoMode(800, 600), "SFML");
        while (window.isOpen())
        {
                sf::Event event;

                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                        {
                                window.close();
                        }
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
                                god.sprite.move(-2.f, 0.f);
                        }
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
                                god.sprite.move(2.f, 0.f);
                        }
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
                                god.sprite.move(0.f, -2.f);
                        }
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
                                god.sprite.move(0.f, +2.f);
                        }

                        //Moving Sprite 2
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
                                dino.sprite.move(-2.f, 0.f);
                        }
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
                                dino.sprite.move(2.f, 0.f);
                        }
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
                                dino.sprite.move(0.f, -2.f);
                        }
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
                                dino.sprite.move(0.f, +2.f);
                        }
                }
                window.clear(sf::Color::White);
                window.draw(dino.sprite);
                window.draw(god.sprite);
                window.display();

        }
        return 0;
}

3
General / Re: Moving springs separately
« on: January 24, 2023, 12:45:24 pm »
int main()
{
        App app;
        dinosaur dino;
        godzilla god;//Głodzilla
        god.sprite.setScale(0.3, 0.3);

        while (app.window->isOpen())
        {
                while (app.window->pollEvent(app.e))
                {
                        if (app.isClosedEvent())
                        {
                                app.window->close();
                                break;
                        }
                        if (app.isKeyPressedEvent())
                        {
                                dino.processEvents(app.e.key.code, true);
                        }
                        if (app.isKeyPressedEvent())
                        {
                                god.processEvent(app.e.key.code, true);
                        }
                        if (app.isKeyReleased())
                        {
                                dino.processEvents(app.e.key.code, false);
                        }
                        if (app.isKeyReleased())
                        {
                                god.processEvent(app.e.key.code, false);
                        }
                }
               
                app.update();
                dino.isTextureLoaded();
                dino.isSpriteLoaded();
                god.isTextureLoaded();
                god.isSpriteLoaded();
                god.model();
                dino.model();
                dino.update();
                god.update();
                god.colision(god.sprite);
                dino.colision(dino.sprite);
                app.window->draw(dino.sprite);
                app.window->draw(god.sprite);
                app.window->display();
        }
        return 0;
}
[code=cpp]

void dinosaur::processEvents(sf::Keyboard::Key key, bool checkPressed)
{

        if (checkPressed == true)
        {
                if (key == sf::Keyboard::W)
                        up = true;

                if (key == sf::Keyboard::S)
                        down = true;

                if (key == sf::Keyboard::A)
                        left = true;

                if (key == sf::Keyboard::D)
                        right = true;
        }

        if (checkPressed == false)
        {
                up = false;
                down = false;
                left = false;
                right = false;
        }

}
[code=cpp]
void dinosaur::update()
{
        sf::Vector2f movement;
        if (up)
                movement.y -= 2.0f;
        if (down)
                movement.y += 2.0f;
        if (left)
                movement.x -= 2.0f;
        if (right)
                movement.x += 2.0f;
        sprite.move(movement);
}
[code=cpp]
void godzilla::processEvent(sf::Keyboard::Key key, bool checkPressed)
{

        if (checkPressed == true)
        {
                if (key == sf::Keyboard::Up)
                        m_up = true;

                if (key == sf::Keyboard::Down)
                        m_down = true;

                if (key == sf::Keyboard::Left)
                        m_left = true;

                if (key == sf::Keyboard::Right)
                        m_right = true;
        }

        if (checkPressed == false)
        {
                m_up = false;
                m_down = false;
                m_left = false;
                m_right = false;
        }
}
The problem is when I hold e.g D and rigt arrow and when I release D both of them stops not only the one witch key was realessed.

4
General / Re: Moving springs separately
« on: January 24, 2023, 11:15:50 am »
void dinosaur::update()
{
        sf::Vector2f movement;
        if (up)
                movement.y -= 2.0f;
        if (down)
                movement.y += 2.0f;
        if (left)
                movement.x -= 2.0f;
        if (right)
                movement.x += 2.0f;
        sprite.move(movement);
}

5
General / Re: Moving springs separately
« on: January 24, 2023, 11:06:43 am »
Could you explain it in more details. My problem is that when I release either key or arrow both of sprites stops.

6
General / Re: Moving springs separately
« on: January 22, 2023, 12:07:45 pm »
void VirtualSpriteClass::ProcessEvents(sf::Keyboard::Key key, bool checkPressed)
{

        if (checkPressed == true)
        {
                if (key == sf::Keyboard::W)
                        m_up = true;

                if (key == sf::Keyboard::S)
                        m_down = true;

                if (key == sf::Keyboard::A)
                        m_left = true;

                if (key == sf::Keyboard::D)
                        m_right = true;
        }

        if (checkPressed == false)
        {
                m_up = false;
                m_down = false;
                m_left = false;
                m_right = false;
        }
}

That's the processEvents function and what I mean is that when I move sprites one of them by "AWSD" and another by "arrows" the move how I expected, but problem is when I relesse one of the key for example I move my dino object by using "D" and player object by using left arrow and the indeed move but when I relesse eaither of them they stops. What I try to achive is that to stop only this sprite which key was relased

7
General / Re: Moving springs separately
« on: January 19, 2023, 04:41:12 pm »
Sorry for unclear asked question. I am asking how can I make  both of control at the same tiem, It means "processEvents" for dino object is method which allow me to control him by "AWSD" for player allow me control him by arrows, but when I relessed one of the key both of them stops. I hope now it's more clear.

8
General / Moving springs separately
« on: January 19, 2023, 12:33:45 pm »
Hi, I want to have options to move them separately, how can I do this?

if (app.isKeyPressedEvent());
         {
            dino.processEvents(app.e.key.code, true);
            player.procesEvents(app.e.key.code, true);

         }
         if (app.isKeyReleased())
         {
            dino.processEvents(app.e.key.code, false);
            player.procesEvents(app.e.key.code, false);
         }
 

Pages: [1]
anything