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

Pages: [1]
1
Graphics / Re: Projectile
« on: October 10, 2017, 06:12:08 pm »
It's inside of the second while loop,

        while (window.isOpen())
        {
                clock2.restart();
                sf::Event evnt;
                while (window.pollEvent(evnt))
                {
                        switch (evnt.type)
                        {
                        case sf::Event::Closed:
                                window.close();
                                break;
                        case sf::Event::KeyPressed:
                                if (evnt.key.code == sf::Keyboard::Space)
                                {
                                        isJump = true;
                                        CreateSoundJump();
                                }
                                if (evnt.key.code == sf::Keyboard::Return)
                                {
                                        dIsVisible = false;
                                }
                                if (evnt.key.code == sf::Keyboard::F)
                                {
                                        CreateAbilitySound();
                                        orbMovement = true;
                                        break;
                                }
                        }
                }

I tried moving the break from outside of the third switch to inside of the curly braces, but it still does the same thing.

2
Graphics / Projectile
« on: October 10, 2017, 01:17:10 am »
I have another question. So I'm creating a projectile in the form of an orb. I currently am able to have it move to a certain point and despawn, but I am unable to get it to reset the orb's location so it can do it again.
        //Code for Player Ability
        if (orbMovement == true)
        {
                float move = velocity.x += 4;
                pOrb.setPosition(pImage.getPosition().x + 40, pImage.getPosition().y + 20);
                pOrb.move(move, 0);
                window.draw(pOrb);
                if (pOrb.getPosition().x >= pImage.getPosition().x + 300)
                        orbMovement = false;
        }
        if (orbMovement == false)
        {
                pOrb.setPosition(pImage.getPosition().x, pImage.getPosition().y);
        }

and in the main function I'm using a switch statement that when 'F' is pressed it sets orbMovement to True as shown here,

                                if (evnt.key.code == sf::Keyboard::F)
                                {
                                        CreateAbilitySound();
                                        orbMovement = true;
                                }

I want it to once it moves to the maximum distance, the orb resets position and can do it again.

3
General / Re: Jump Code
« on: October 09, 2017, 07:46:54 pm »
Thanks. I'll give that a shot

4
General / Jump Code
« on: October 08, 2017, 06:13:07 pm »
I've been a bit stuck for the past few days. Basically what I want to happen is when pImage(player Sprite) hits a certain height gravity activates and brings the player down. That way when you press the space key you don't continue going up and when released you go down. I Want it similar to that of a mario or traditional platformer. I currently have collision done, it's just this one part that has been driving me mad. I'm a bit new to this so I'm sure there is an easy solution to this problem.
 
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Space))
                {
                        source.y = Up;
                        pImage.move(0, -moveSpeed* clock.getElapsedTime().asSeconds());
                        //Debugging: Getting Player Position
                        std::cout << "Position X: " << pImage.getPosition().x
                                << "||Position Y: " << pImage.getPosition().y << std::endl;
                }
                else if (pImage.getPosition().y >= 341)
                {
                        pImage.move(0, moveSpeed* clock.getElapsedTime().asSeconds());
                }

Pages: [1]
anything