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

Pages: [1]
1
General / Re: laser event not working
« on: November 03, 2014, 01:59:16 pm »
That's what I was assuming, but I wasn't 100% sure. I can try making it reset and see if that helps.

2
General / laser event not working
« on: November 03, 2014, 01:53:44 am »
I am trying to make a Space Invaders game. When you press the Space key, it is supposed to make a laser spawn in front of the ship and go up, but it only works the first time, then not again. It is not finished yet. If someone could please tell me what is wrong, I will appreciate it.

#include <SFML/Graphics.hpp>

int main()
{
        using namespace sf;

    Sprite enemyShips [12];
    int isEnemyLiving [12];
    Sprite enemyLasers [12];
    int isEnemyLaserActive [12];
    Sprite playerLasers [12];
    int isPlayerLaserActive [12];
    int playerPosition = 370;
    int laserInactive = 0;

    for (int firstSet=0; firstSet<12; firstSet++)
        {
                isEnemyLaserActive [firstSet] = 0;
                isEnemyLiving [firstSet] = 0;
                isPlayerLaserActive [firstSet] = 0;
        }

    // Create the main window
    RenderWindow spaceInvaders(VideoMode(800, 660), "Space Invaders");

    Texture removeEntity;
    if (!removeEntity.loadFromFile("empty.png"))
    {
        return EXIT_FAILURE;
    }

    Texture enemyShip;
    if (!enemyShip.loadFromFile("enemyShip.png"))
        {
                return EXIT_FAILURE;
        }

        Texture boom;
        if (!boom.loadFromFile("boom.png"))
        {
                return EXIT_FAILURE;
        }

        Texture laser;
        if (!laser.loadFromFile("laser.png"))
        {
                return EXIT_FAILURE;
        }

        Texture spaceShip;
        if (!spaceShip.loadFromFile("spaceShip.png"))
        {
                return EXIT_FAILURE;
        }

    Sprite player;
    player.setTexture(spaceShip);
    player.setPosition(370, 600);

        // Start the game loop
    while (spaceInvaders.isOpen())
        {
                // Process events
        Event isWindowClosed;
        while (spaceInvaders.pollEvent(isWindowClosed))
                {
                        // Close window : exit
            if (isWindowClosed.type == Event::Closed)
                spaceInvaders.close();
        }

        if (playerPosition>=0)
                {
                                if (Keyboard::isKeyPressed(Keyboard::Left))
                                {
                                        player.move(-1,0);
                                        playerPosition--;
                                }
                }

                if (playerPosition<=760)
                {
                        if (Keyboard::isKeyPressed(Keyboard::Right))
                        {
                                player.move(1,0);
                                playerPosition++;
                        }
                }

                if (Keyboard::isKeyPressed(Keyboard::Space))
                {
            for (int playerLaserChecker=0; playerLaserChecker<12; playerLaserChecker++)
                        {
                                if (laserInactive==0)
                                {
                                        if (isPlayerLaserActive [playerLaserChecker]==0)
                                        {
                                                playerLasers [playerLaserChecker].setTexture(laser);
                                                isPlayerLaserActive [playerLaserChecker] = 1;
                                                playerLasers [playerLaserChecker].setPosition(playerPosition+20, 540);
                                                laserInactive = 1;
                                        }
                                }
                        }
                }

                laserInactive = 0;

                for (int laserMover=0; laserMover<12; laserMover++)
                {
                        if (isPlayerLaserActive [laserMover]==true)
                        {
                                playerLasers [laserMover].move(0,-1);
                        }
                }

        // Clear screen
        spaceInvaders.clear();

                // Draw the sprite
        spaceInvaders.draw(player);

        for (int laserDraw=0; laserDraw<12; laserDraw++)
        {
                spaceInvaders.draw(playerLasers[laserDraw]);
        }

                // Update the window
        spaceInvaders.display();
    }

    return EXIT_SUCCESS;
}
 

3
Graphics / Re: Can you make an array of sprites
« on: October 30, 2014, 04:12:18 pm »
Would std::vector be a more efficient choice over an array, or does it matter?

4
Graphics / Can you make an array of sprites
« on: October 30, 2014, 03:49:41 pm »
I am new to sfml, and I want to know if it is possible to make an array of sprites?

Pages: [1]
anything