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

Pages: [1]
1
General / Re: Vertical falling ball. need help.
« on: January 03, 2013, 02:30:31 pm »
I've written a shorter code then the previouse one and now it's works. Here it is, if someone is interested.
#include <SFML/Graphics.hpp>
#include <iostream>
using namespace std;



int main()
{


    sf::RenderWindow Game(sf::VideoMode(800, 600, 32), "Ball ... ");
    sf::Clock Clock;
        sf::Image bg;
        bg.LoadFromFile("ball.png");
        sf::Sprite ball;
        ball.SetCenter(60,120);
        ball.SetImage(bg);
        ball.SetPosition(300,120);
        bool running = true;
        float g = 0.6;
        float tempV;
        int y;
        int i=2;
        bool Collission = false;       
        float v;
        float t;
        sf::Event Event;
        while(running == true)
        {
                t = Clock.GetElapsedTime();
                if( Collission == false) {v=g*t;}
                ball.Move(0,v);
            y = ball.GetPosition().y;
                if(y >= 600)
                {
                        Collission = true;
                        tempV = v;
                        Clock.Reset();
                        ball.SetPosition(ball.GetPosition().x,599.9999);
                        i++;
                }
                t = Clock.GetElapsedTime();
                if(Collission == true)
                {
                        v = -((1*tempV)/2-g*t);
                        if(-v <= 0){Collission == false;}
                }
               
               
                Game.Clear();
                Game.Draw(ball);
                Game.Display();
               
        }


    return 0;
}
 

2
General / Re: Vertical falling ball. need help.
« on: January 02, 2013, 05:52:32 pm »
I think it is better for me to install SFML 2.0 and write the same code for it.

3
General / Re: Vertical falling ball. need help.
« on: January 02, 2013, 05:48:04 pm »
It's falling down, and then at the collission with the window it's stoping and after some time it's moving up. You can try the code to see.

4
General / Re: Vertical falling ball. need help.
« on: January 02, 2013, 05:32:28 pm »
Ok. The first if(y == s) collision with the window, if(move == true && i>1) to change the direction of the moving and other parameters, if(i>1 && move == false) the end of the  up move and again falling down.

5
General / Vertical falling ball. need help.
« on: January 02, 2013, 05:15:50 pm »
I'm trying to create a Vertical falling ball, without any move controls or something else. I have written a code that i think shall work, but it doesn't work : :o Please look at the source code. Or if someone an oter code, pleas share it with me :D.
Sorry for my bad english.
#include <SFML/Graphics.hpp>
#include <iostream>
using namespace std;



int main()
{


    sf::RenderWindow Game(sf::VideoMode(800, 600, 32), "Ball ... ");
    sf::Clock Clock;
        sf::Image bg;
        bg.LoadFromFile("ball.png");
        sf::Sprite ball;
        ball.SetCenter(60,120);
        ball.SetImage(bg);
        ball.SetPosition(300,120);
        bool running = true;
        float g = 0.6;
        int s = 595;
        int y;
        int i=1;
        bool move = false;     
        int vy;
        int v = 1;
        float t = 1;
        sf::Event Event;
        while(running == true)
        {
               
               
                if(i == 1)
                {
                ball.Move(0,g*Clock.GetElapsedTime());
                }
                y = ball.GetPosition().y;
                std::cout<<"y= "<<y<<"\n";
                std::cout<<"s= "<<s<<"\n";
                if(y == s)
                {
                        v=g*Clock.GetElapsedTime();
                        move = true;
                        i++;
                        Clock.Reset();
                }
                if(move == true && i>1)
                {
                        vy=-(v-g*Clock.GetElapsedTime());
                        if(vy == 0)
                        {
                                Clock.Reset();
                                move = false;
                        }
                        ball.Move(0,vy);
                }
                if(i>1 && move == false)
                {
                        ball.Move(0,g*(Clock.GetElapsedTime()));
                }      
                while(Game.GetEvent(Event))
                        {
                        }
                Game.Clear();
                Game.Draw(ball);
                Game.Display();
               
        }


    return 0;
}
 

6
General / Re: How can i get in sfml the previous position of a sprite?
« on: December 28, 2012, 12:54:13 pm »
Good idea. Thanks.

7
General / How can i get in sfml the previous position of a sprite?
« on: December 28, 2012, 12:35:36 pm »
I'm trying to write a Classical Snake game, and i need to get the previous position of the head from my snake to create the first part of the snake body, and then the next part with the previous position of the first body part and so on.
Any Ideas ?
Sorry for my bad English.

Pages: [1]