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

Pages: [1] 2 3
1
Graphics / Re: left and top of FloatRect, some explanation needed
« on: August 25, 2013, 11:26:33 pm »
By the way, the coordinate system point (0,0) is located at the LEFT TOP CORNER of the screen right ? if by example I try to set the position of a rectangle at (10,10) it will be 10 pixel lower in x and in y than the left top corner, right ?
And if I try to see if the rectangle has gone out of the screen, his coordinates will be NEGATIVE right ?
Thanks for your help.

2
Graphics / Re: left and top of FloatRect, some explanation needed
« on: August 25, 2013, 10:28:31 pm »
Its ok I understood now. Thanks a lot. :)

3
Graphics / left and top of FloatRect, some explanation needed
« on: August 25, 2013, 09:59:40 pm »
Hello
I try to understand for ages what is the left and top coordinates of the floatrect, it is not explained very well in the API documentation what is it really.
If somebody could put the left and top coordinates of a rectangle it would help me (because I don't see on which corner the left coordinate is, is it on left high or left bottom? and what is EXACTLY top coordinate? Also if its a coordinate, can I access his X and Y components somehow? If yes, how ?)
Thanks a lot in advance. I'd like a picture. :)

4
SFML projects / Re: Serpent - A simple snake clone
« on: August 21, 2013, 01:56:38 am »
Dunno why but there is no more snake appearing on my screen with the last build.

5
SFML projects / Re: Serpent - A simple snake clone
« on: August 20, 2013, 10:41:16 pm »
When I launch your .exe I cannot see any snake, maybe a render problem ? But I see the main screen and the background

6
SFML projects / Re: Serpent - A simple snake clone
« on: August 20, 2013, 08:49:26 pm »
Haha, I was joking about the features of my game, at least yours prevent the snake from moving in the menu screen and you can restart it without launching the .exe again. :)

I enjoyed your snake through I noticed one minor problem :

- You can go left when your current direction is right, or up if your current direction is down, etc etc but ONLY if the size of the snake is equal to 2. Maybe you need to find some way to prevent the snake from going left if your current direction is right, or move the snake in the left direction nonetheless.

"Also, please bear with the 33/16 time signature music.  I can't seem to fix the music."
I don't see what you are talking about, but just know if you want to add more music it is very easy to do so and manage them with SFML. :)

By the way, even if you say your code is unpolished, your organization looks very nice and is separate in multiple files which is easy to read, which is good for a beginner (you don't want to read my snake made in one file). :)

7
SFML projects / Re: epic Snake with SFML
« on: August 19, 2013, 03:29:39 pm »
Oh yes, you mean you press space while being in the menu, well I fixed that (it was easy) :)
and thanks for the background image : P
I'll release a new version soon with fixes, keep in mind tho its only my first game so there are some things I can not fix (like losing after being in the menu for a little time) because of the bad architecture of the code. :)
Thanks for taking the time of uploading image/and video to provide feedback, I really appreciate it :)

8
SFML projects / Re: epic Snake with SFML
« on: August 19, 2013, 02:13:03 pm »
First, thanks for your feedback and taking the time to try my game (even if its a classic and simple one). :)

For the issues:

You need to press S to Start : I know it can be kinda confusing but its because I'm using a start screen (find it to be cooler) :P

Music problem: You sure it mix songs ? Everytime I press space it makes a new song play (I know they are all 8 bits but they are all different). Maybe you mean that if you stop one music then press space a few times  the song will be where you paused it but that's not the case either.

I know for the restart thing and for the problem of locating, through the framerate limit of the game is set low so the game is kinda easy. (there's another variant of the game where I double the framerate limit and make the snake grow 3 times bigger everytime you eat a key :p ).

The problem is that due of the architecture of the code right now, it is kinda impossible to make the game restart. I did not make a screenstate system (like putting all the game in a function and call this function if you press a button in the menu). Instead I just draw sprite (the fail screen if your snake hit something, the menu while you still didn't press S)... I know it's a very very very bad choice but it's only my first game and I plan to implement a screenstate system in the next game :)

Most of the time on my side the snake picks the key up. For the collision I use the contains() method which detect if a point (x,y) is contained in the sprite of the key. So yeah it's kinda based on luck... :)
For the top wall I would just need to change the background image (located in data/), as well as all the epic songs if you wish to hear them again, outside of the game :D

Thanks a lot for your feedback. :)

9
SFML projects / epic Snake with SFML
« on: August 19, 2013, 01:47:23 am »
Hello all !
I finally succesfully made a snake using SFML and wanted to share it here  :)
Unique features:

* Awesome In-Game Epic Audio Player ! Unleash the 8 bit epic songs while playing Snake !
* A snake that is very unique... You don't eat fruits, you eat keys (don't ask me why).
* Excellent fail screen !

You start with S, and change music with Space.
You control the snake with the arrows of your keyboard.

I want to thank you all the people who helped me into making the game a reality, and a special Thanks to Geheim for his BIG support.  :D


The link:
http://www.megafileupload.com/en/file/442446/snakeSFML-zip.html

Tell me your opinion about it. :)

10
Graphics / Re: how to remove a sf::Sprite and use a timer
« on: August 18, 2013, 02:29:50 pm »
Damn dude you are an angel, I never thought about that.
But I set up the positions at 300 and 255 after that and it still doesn't work.
So I don't know. :(
in fact, I'd like to put rand() in the set position of my function spawnkey but it always spawn at the same place X_X

11
Graphics / Re: how to remove a sf::Sprite and use a timer
« on: August 18, 2013, 01:32:17 pm »
Okay thanks a lot for your advice already. Right now my snake grows when he eats one pickup. :)
But only the first one, I do not know why. :(
Here are my modified piece of code (only work once, after that the snake don't grow if he eats one pick up :


Alright, I had only given a piece of the code because my program is all made in one file. :/

No, there is only one key object because I only want them to respawn one at a time, so I didn't made a list/vector/deque for the pick up.

I will give you the functions of snake so you can understand:
Block::Block(int x, int y)
{
    ax = x;
    ay = y;
}

float Block::getX()
{
    return ax;
}

float Block::getY()
{
    return ay;
}

void Block::setX(float ZX)
{
    ax = ZX;
}

void Block::setY(float ZY)
{
    ay = ZY;
}

void Snake::Move(int NewDirection)
{
    shrink();
    if(NewDirection == Up)
    {

        if(adirection != Down)
        {
            asnake.push_front(Block(asnake.front().getX(), asnake.front().getY() - 15));
            adirection = Up;
        }
        else
        {
            asnake.push_front(Block(asnake.front().getX(), asnake.front().getY() + 15));
        }
    }
    else if(NewDirection == Right)
    {
        if(adirection != Left)
        {
            asnake.push_front(Block(asnake.front().getX() + 15, asnake.front().getY()));
            adirection = Right;
        }
        else
        {
            asnake.push_front(Block(asnake.front().getX() - 15, asnake.front().getY()));
        }
    }
    else if(NewDirection == Down)
    {
            if(adirection != Up)
            {
                asnake.push_front(Block(asnake.front().getX(), asnake.front().getY() + 15));
                adirection = Down;
            }
            else
            {
                asnake.push_front(Block(asnake.front().getX(), asnake.front().getY() - 15));
            }

    }
    else if(NewDirection == Left)
    {
        if(adirection != Right)
        {
            asnake.push_front(Block(asnake.front().getX() - 15, asnake.front().getY()));
            adirection = Left;
        }
        else
        {
            asnake.push_front(Block(asnake.front().getX() + 15, asnake.front().getY()));
        }
    }

}

void Snake::grow()
{
    asnake.push_back(Block(asnake.back().getX(), asnake.back().getY()));
}
void Snake::shrink()
{
    asnake.pop_back();
}

std::deque<Block> Snake::getBlocks()
{
    return asnake;
}
int Snake::getX()
{
    return asnake.front().getX();
}

int Snake::getY()
{
    return asnake.front().getY();
}

Snake::Snake()
{
    asnake.push_front(Block(BORDERX/2,BORDERY/2));
    asnake.push_front(Block(BORDERX/2+15,BORDERY/2+15));
    asnake.push_front(Block(BORDERX/2+15,BORDERY/2+15));
}

void Snake::setdirection()
{
    adirection = Left;
}

bool Snake::checkForCollisionBorder()
{
    for(unsigned int i = 0; i < getBlocks().size(); i++)
    {
        int cx = (getBlocks())[i].getX();
        int cy = (getBlocks())[i].getY();
        if((cx > BORDERX - 50) || (cx < 50) || (cy > BORDERY - 50) || (cy < 50))
        {
            return true;
        }
    }
    return false;
}

bool Snake::checkForBite()
{
    for(unsigned int s = 1; s < getBlocks().size(); s++)
    {
        if((getBlocks())[s].getX() == snake.getX() && (getBlocks())[s].getY() == snake.getY())
        {
            return true;
        }
    }
    return false;
}

void Key::SpawnKey() // spawn a key every 5 seconds
{
    if(clockKey.getElapsedTime().asSeconds() > 3)
    {
        spawn = true;
        keysprite.setPosition(350, 200);
        clockKey.restart();
    }
}
bool Key::isKeyPickedUp()
{
    if((keysprite.getPosition().x == snake.getX() && keysprite.getPosition().y == snake.getY()) && spawn)
    {
        spawn = false;
        return true;
    }
    return false;
}

sf::Sprite Key::getKeySprite()
{
    return keysprite;
}

void Key::growOrDespawn()
{
    if(isKeyPickedUp())
    {
        maximalSize++;
        snake.grow();// if key has been picked up, move the key out of the map (I do not know how to destroy it :p
        SpawnKey();                       // and spawn a new key after 5 seconds.
    }
}
 

My snake is made of a deque of Blocks (which contains 2 coordinates), and in my main function in the window.isOpen() loop, I put this to draw each segment of the snake based on the deque of Blocks:

                window.draw(backgroundsprite);
                for(unsigned int i = 1; i < (snake.getBlocks()).size(); i++)
                {
                    float xb = (snake.getBlocks())[i].getX();
                    float yb = (snake.getBlocks())[i].getY();

                    sf::RectangleShape block(sf::Vector2f(15,15));
                    block.setFillColor(sf::Color::Green);
                    block.setOutlineThickness(2);
                    block.setOutlineColor(sf::Color::Yellow);
                    block.setPosition(xb, yb);

                    window.draw(block);
                }

So you can understand now how my code works. :)
Right now the only issue is that it only work once (once the snake takes the pick up, he will grow once, but if he takes again the pick up (which is put elsewhere on the screen), he doesn't grow. :(
Thanks for your help.

12
Graphics / how to remove a sf::Sprite and use a timer
« on: August 18, 2013, 02:52:33 am »
Hello,
in my snake game I try to make pick ups which grant abilities to the player controlling the snake.
However I experience some problems : the pick up spawns all the time even if I programmed it to spawn every 3 seconds :/
Also I do not know how to remove a sprite from the screen. Thought about not drawing it but then if the player still go on it the snake would still grow :/
And last problem, my function isKeyPickedUp() always return true, even if I programmed it to return true ONLY if the key sprite coordinate match with the snake coordinate, and if it does, spawn the key elsewhere directly. So I end up with a snake that grows bigger and bigger... :(
I will also explain other problems of my snake after those have been resolved (those are minor other problems).
Thanks for your help, here is the code of my pick up for the snake
/*void Key::SpawnKey() // spawn a key every 5 seconds
{
    timeKey = clockKey.getElapsedTime();
    if(timeKey.asSeconds() > 5)
    {
        keysprite.setPosition(rand() % BORDERX - 70, rand() % BORDERY - 70);
        clockKey.restart();
        timeKey = clockKey.getElapsedTime();
    }
    timeKey = clockKey.getElapsedTime();
}
bool Key::isKeyPickedUp()
{
    if(keysprite.getGlobalBounds().contains(snake.getX(),snake.getY()));
    {
        return true;
    }
    return false;
}

sf::Sprite Key::getKeySprite()
{
    return keysprite;
}

void Key::growOrDespawn()
{
    if(isKeyPickedUp())
    {
        keysprite.setPosition(1000,1000);
        snake.grow();// if key has been picked up, move the key out of the map (I do not know how to destroy it :p
        SpawnKey();                       // and spawn a new key after 5 seconds.
    }
}*/

 

and the code in my main, in the window.isOpen() loop :

//key.growOrDespawn();
//window.draw(key.keysprite);
 
and the code in the main BEFORE the window.isOpen() loop :

    /*Key key;
    sf::Texture keyTexture;
    keyTexture.loadFromFile("key.png");
    key.keysprite.setTexture(keyTexture);*/

I think the problem comes that I put spawnKey() inside the loop, so it spawns keys all the time, but it's strange because I put a timer of 10 seconds before it actually set the position of the sprite :(
Some help?
Thanks a lot in advance. :)

Oh, and of course, I declared sf::Clock clockKey at debut of file, as well as timeKey. :)

13
Graphics / Re: beginning of snake
« on: August 17, 2013, 03:11:58 am »
Made it work. So. Fucking. Happy. :)

14
Graphics / Re: beginning of snake
« on: August 17, 2013, 01:21:09 am »
Okay so I made a big step in the code, after asking stackoverflow I did another approach which is similar but don't use sprites and better organization etc.
Here is a code of a snake that can wiggle. sadly ! it only move when you press a key. Why so ? putting the move outside of the if(key pressed) change nothing.
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>

#include <deque>

enum Direction { Up, Down, Right, Left};
int direction = Down;

class Block
{
    private:
    int ax, ay;

    public:
    Block(int, int);
    int getX();
    int getY();

};


class Snake
{
    private:
    std::deque<Block> asnake;
    int adirection;

    public:
    void Move(int);
    void grow();
    void shrink();
    std::deque<Block> getBlocks();
    int getX();
    int getY();
    Snake();
    void setdirection();
};

int main()
{
    sf::Music epicMusic;
    epicMusic.openFromFile("epicmusic.wav");
    epicMusic.play();
    sf::Event event;
    Snake snake;
    snake.setdirection();
    snake.grow();
    snake.grow();

    sf::RenderWindow window(sf::VideoMode(500,500), "SFML Snake");
    window.setFramerateLimit(30);
    while(window.isOpen())
    {
        while(window.pollEvent(event))
        {
            switch(event.type)
            {
                case sf::Event::Closed:

                epicMusic.stop();
                window.close();
                break;

                default:

                break;
            }

        }

        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
        {
                direction = Left;
                snake.Move(direction);
        }
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
        {
                direction = Right;
                snake.Move(direction);
        }
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
        {
                direction = Down;
                snake.Move(direction);
        }
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
        {
                direction = Up;
                snake.Move(direction);
        }

        window.clear(sf::Color::Red);


        for(unsigned int i = 1; i < (snake.getBlocks()).size(); i++)
        {
            float x = (snake.getBlocks())[i].getX();
            float y = (snake.getBlocks())[i].getY();

            sf::RectangleShape block(sf::Vector2f(20,20));
            block.setFillColor(sf::Color::Green);
            block.setPosition(x, y);

            window.draw(block);
        }
        window.display();
    }
    return 0;
}

Block::Block(int x, int y)
{
    ax = x;
    ay = y;
}

int Block::getX()
{
    return ax;
}

int Block::getY()
{
    return ay;
}

void Snake::Move(int NewDirection)
{
    shrink();
    if(NewDirection == Up)
    {

        if(adirection != Down)
        {
            asnake.push_front(Block(asnake.front().getX(), asnake.front().getY() - 22));
            adirection = Up;
        }
        else
        {
            asnake.push_front(Block(asnake.front().getX(), asnake.front().getY() + 22));
        }
    }
    else if(NewDirection == Right)
    {
        if(adirection != Left)
        {
            asnake.push_front(Block(asnake.front().getX() + 25, asnake.front().getY()));
            adirection = Right;
        }
        else
        {
            asnake.push_front(Block(asnake.front().getX() - 25, asnake.front().getY()));
        }
    }
    else if(NewDirection == Down)
    {
            if(adirection != Up)
            {
                asnake.push_front(Block(asnake.front().getX(), asnake.front().getY() + 22));
                adirection = Down;
            }
            else
            {
                asnake.push_front(Block(asnake.front().getX(), asnake.front().getY() - 22));
            }

    }
    else if(NewDirection == Left)
    {
        if(adirection != Right)
        {
            asnake.push_front(Block(asnake.front().getX() - 25, asnake.front().getY()));
            adirection = Left;
        }
        else
        {
            asnake.push_front(Block(asnake.front().getX() + 25, asnake.front().getY()));
        }
    }

}

void Snake::grow()
{
    asnake.push_back(Block(asnake.back().getX(), asnake.back().getY()));
}
void Snake::shrink()
{
    asnake.pop_back();
}

std::deque<Block> Snake::getBlocks()
{
    return asnake;
}
int Snake::getX()
{
    return asnake.front().getX();
}

int Snake::getY()
{
    return asnake.front().getY();
}

Snake::Snake()
{
    asnake.push_front(Block(25,0));
    asnake.push_front(Block(50,0));
    asnake.push_front(Block(75,0));
}

void Snake::setdirection()
{
    adirection = Up;
}
 
Thanks.

15
Graphics / Re: [Solved]How to stop a color from displaying?
« on: August 17, 2013, 01:19:43 am »
Just don't get through ALL this fuss, just get paint.net, magic wand and CTRL+X the white background. SFML handles pretty well the alpha channel (= transparency).

Pages: [1] 2 3