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

Pages: [1]
1
Window / Re: SFML errors
« on: May 19, 2014, 10:03:55 pm »
I'm using Windows 7 Home Premium, compiling wirh MinGW 4.8.1, SFML 2.1, static linking.
It's the first time I'm having this kind of problems though I've been using SFML for about 2 months.

2
Window / SFML errors
« on: May 19, 2014, 07:13:33 pm »
Hello!
I'm having some problems with some SFML code. I'm getting the following errors:
"Failed to activate the window's context" x2
"Failed to initialize GLEW. Missing GL version" x8

Here is the code:
(click to show/hide)

3
Graphics / Re: Using sf::Clock on a moving ball.
« on: April 30, 2014, 08:00:45 pm »
#include <SFML/Graphics.hpp>
#include <vector>
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>
#include <sstream>

std::string convertInt(int number)
{
   std::stringstream ss;
   ss << number;
   return ss.str();
}

int main(int argc, char** argv)
{
    sf::RenderWindow window(sf::VideoMode(800, 800), "Bounce!");

    int nr = 0;
    int times = 10;

    sf::Font font;
    if(!font.loadFromFile("arial.ttf"))
        return -1;

    sf::Texture texture1;
    if(!texture1.loadFromFile("D:\\texture1.jpg"))
        return -1;

    sf::Texture texture2;
    if(!texture2.loadFromFile("D:\\texture2.png"))
        return -1;

    sf::Texture texture3;
    if(!texture3.loadFromFile("D:\\texture3.jpg"));

    sf::Sprite sprite;
    sprite.setTexture(texture1);

    sf::Clock clock;

    std::vector<float> random_neg;
    std::vector<float> random_pos;

    random_neg.push_back(-0.3);
    random_neg.push_back(-0.2);
    random_pos.push_back(0.2);
    random_pos.push_back(0.3);

    float x1 = -0.2, y1 = -0.3;

    srand(time(0));

    int random1 = rand() % 2;
    int random2 = rand() % 2;

    sf::Texture* text2 = &texture2;
    sf::Texture* text3 = &texture3;

    sf::RectangleShape paddle;

    paddle.setPosition(350, 650);
    paddle.setSize(sf::Vector2f(100, 10));
    paddle.setTexture(text2);

    sf::CircleShape ball;

    ball.setRadius(10);
    ball.setPosition(335, 335);
    ball.setTexture(text3);

    window.setMouseCursorVisible(false);

    while(window.isOpen())
    {
        sf::Event event;
        clock.restart();

        float delta = clock.restart().asSeconds();

        random_neg[0] *= delta;
        random_neg[1] *= delta;
        random_pos[0] *= delta;
        random_pos[1] *= delta;

        while(window.pollEvent(event))
        {
            switch(event.type)
            {
            case sf::Event::Closed:
                window.close();
                break;
            case sf::Event::KeyPressed:
                if(event.key.code == sf::Keyboard::Escape)
                    window.close();
                break;
            }
        }

        paddle.setPosition(sf::Mouse::getPosition(window).x, 650);

        if(paddle.getPosition().x <= 0)
            paddle.setPosition(0, 650);
        if(paddle.getPosition().x >= 700)
            paddle.setPosition(700, 650);

        if(ball.getPosition().y <= 0)
        {
            random1 = rand() % 2;
            y1 = random_pos[random1];
        }

        if(ball.getPosition().y >= 785)
        {
            random1 = rand() % 2;
            y1 = random_neg[random1];
        }

        if(ball.getPosition().x <= 0)
        {
            random1 = rand() % 2;
            x1 = random_pos[random2];
        }

        if(ball.getPosition().x >= 800)
        {
            random1 = rand() % 2;
            x1 = random_neg[random2];
        }

        if( ball.getPosition().x <= paddle.getPosition().x + 100 &&
           ball.getPosition().x >= paddle.getPosition().x &&
           ball.getPosition().y <= paddle.getPosition().y &&
           ball.getPosition().y >= paddle.getPosition().y - 10 )
        {
            ++times;

            if(times >= 1)
            {
                nr += 1;
                times = 0;
            }

            y1 = random_neg[random1];

            if(x1 < 0)
                x1 = random_neg[random2];
            else
                x1 = random_pos[random2];
            ball.move(x1, y1);
        }
        else
            ball.move(x1, y1);
    }
}

4
Graphics / Re: Using sf::Clock on a moving ball.
« on: April 30, 2014, 02:58:29 pm »
I tried to implement it but now the ball is moving only a few seconds and then stops on the left corner.

    while(window.isOpen())
    {
        sf::Event event;

        float delta = clock.restart().asSeconds();

        random_neg[0] *= delta;
        random_neg[1] *= delta;
        random_pos[0] *= delta;
        random_pos[1] *= delta;
.........

5
Graphics / Using sf::Clock on a moving ball.
« on: April 29, 2014, 07:20:51 pm »
Hi! I'm trying to make a game, but on different computers the speed of the ball is different. I know I have to use the sf::Clock but I don't know how?
Can you help me?

#include <SFML/Graphics.hpp>
#include <vector>
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>
#include <sstream>

std::string convertInt(int number)
{
   std::stringstream ss;
   ss << number;
   return ss.str();
}

const float speed = 0.3;

int main(int argc, char** argv)
{
    sf::RenderWindow window(sf::VideoMode(800, 800), "Bounce!!!");

    int nr = 0;

    sf::Font font;

    if(!font.loadFromFile("arial.ttf"))
        return -1;

    std::vector<float> random_neg;
    std::vector<float> random_pos;

    random_neg.push_back(-0.3);
    random_neg.push_back(-0.2);
    random_pos.push_back(0.2);
    random_pos.push_back(0.3);

    float x1 = -0.2, y1 = -0.3;

    srand(time(0));

    int random1 = rand() % 2;
    int random2 = rand() % 2;

    sf::RectangleShape paddle;

    paddle.setFillColor(sf::Color::Blue);
    paddle.setPosition(350, 650);
    paddle.setSize(sf::Vector2f(100, 10));

    sf::CircleShape ball;

    ball.setRadius(10);
    ball.setPosition(335, 335);
    ball.setFillColor(sf::Color::Red);

    window.setMouseCursorVisible(false);

    while(window.isOpen())
    {
        sf::Event event;

        while(window.pollEvent(event))
        {
            switch(event.type)
            {
            case sf::Event::Closed:
                window.close();
                break;
            case sf::Event::KeyPressed:
                if(event.key.code == sf::Keyboard::Escape)
                    window.close();
                break;
            }
        }

        paddle.setPosition(sf::Mouse::getPosition(window).x, 650);

        if(paddle.getPosition().x <= 0)
            paddle.setPosition(0, 650);
        if(paddle.getPosition().x >= 700)
            paddle.setPosition(700, 650);

        if(ball.getPosition().y <= 0)
        {
            random1 = rand() % 2;
            y1 = random_pos[random1];
        }

        if(ball.getPosition().y >= 785)
        {
            random1 = rand() % 2;
            y1 = random_neg[random1];
        }

        if(ball.getPosition().x <= 0)
        {
            random1 = rand() % 2;
            x1 = random_pos[random2];
        }

        if(ball.getPosition().x >= 800)
        {
            random1 = rand() % 2;
            x1 = random_neg[random2];
        }

        if( ball.getPosition().x <= paddle.getPosition().x + 100 &&
           ball.getPosition().x >= paddle.getPosition().x - 40 &&
           ball.getPosition().y <= paddle.getPosition().y + 10 &&
           ball.getPosition().y >= paddle.getPosition().y - 10 )
        {
            ++nr;
            y1 = random_neg[random1];

            if(x1 < 0)
                x1 = random_neg[random2];
            else
                x1 = random_pos[random2];
            ball.move(x1, y1);
        }
        else
            ball.move(x1, y1);

        if(ball.getPosition().y >= 650)
        {
            ball.setPosition(300, 300);
            break;
        }

        std::string score0 = "Score: " + convertInt(nr);

        sf::Text score;
        score.setString(score0);
        score.setFont(font);
        score.setCharacterSize(15);
        score.setPosition(700, 750);
        score.setColor(sf::Color::Black);

        window.clear(sf::Color::Yellow);
        window.draw(paddle);
        window.draw(ball);
        window.draw(score);
        window.display();
    }
}

6
Graphics / Re: sfml-graphics-2.dll missing
« on: April 28, 2014, 06:18:33 pm »
Hey! Now it's working. It seems I didn't put all DLL's in the file where the .exe is.
Thanks for help!

7
Graphics / Re: sfml-graphics-2.dll missing
« on: April 28, 2014, 06:08:01 pm »
Yes, I'm getting the same error message.

8
Graphics / Re: sfml-graphics-2.dll missing
« on: April 28, 2014, 05:36:26 pm »
It's not working.

9
Graphics / sfml-graphics-2.dll missing
« on: April 28, 2014, 05:27:27 pm »
Hi! I'm trying to build a first game in SFML. I have the code, I can compile it and I can play the game. But when I open the .exe project file, I'm getting an error message: "The program can't start because sfml-graphics-2.dll is missing from your computer.". This is kinda weird because when I compile and run the code in Code::Blocks everything is ok.
How can I fix this problem?
P.S : Sorry for my english.

Pages: [1]