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.


Topics - TheBaldPanda

Pages: [1]
1
General / Pong- How would I make the ball bounce of at different angles?
« on: October 03, 2013, 04:01:28 am »
Hey. I am making my first game, and so far handled everything else but this. The two paddles just bounce the ball in a straight line, and that isn't fun at all. I am wondering, how would I make it bounce off at an angle? PLEASE provided example code if possible   :D

2
Graphics / [SOLVED] How would I cause collision to the window?
« on: October 02, 2013, 01:51:59 pm »
Me again. I am still attempting my pong clone. I have movement and everything down. It's just that when I move the paddle up, it continues forever, is there a way to, erm, stop that?

#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;

float ballSpeed = 400.0f;
float paddleSpeed = 10000.0f;
float ballVelX = 10;
float ballVelY = 10;


sf::Clock cloc;
sf::Time tim;


bool isPlaying = true;

sf::Vector2i screenSize(800,600);

int main()
{

    sf::CircleShape pongBall;
    //sf::CircleShape::
    pongBall.setFillColor(sf::Color::Red);
    pongBall.setRadius(25.0f);
    pongBall.setPosition(400, 300);

    sf::RectangleShape paddle1;
    // sf::RectangleShape::
    paddle1.setFillColor(sf::Color::Yellow);
    paddle1.setSize(sf::Vector2f(50, 150));
    paddle1.setPosition(0, 175);

    sf::RectangleShape paddle2;
    // sf::RectangleShape::
    paddle2.setFillColor(sf::Color::Yellow);
    paddle2.setSize(sf::Vector2f(50, 150));
    paddle2.setPosition(750, 175);

    pongBall.setPosition(400, 300);
    paddle1.setPosition(1, 250);
    paddle2.setPosition(784, 250);

    sf::FloatRect boundingBox = paddle1.getGlobalBounds();

    sf::FloatRect boundbox2 = paddle2.getGlobalBounds();
    if(boundingBox.intersects(boundbox2)){

    }

    float t = rand() % 1;
    float w = rand() % 1;



    sf::RenderWindow window(sf::VideoMode(screenSize.x, screenSize.y), "Pro");


    cloc.restart();

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

    window.pollEvent(event);
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
{
    // left key is pressed: move our character
    paddle1.move(0, -1);
}
    if (sf::Event::Closed){
        window.close();
    }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
    {
        paddle1.move(0, 1);
    }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
    {
        paddle2.move(0, -1);
        if (paddle2.getPosition().x >= window.getPosition().x){



        }
    }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)){
        paddle2.move(0, 1);
    }
    window.clear(sf::Color::Red);
    window.draw(paddle1);
    window.draw(paddle2);
    window.display();


}







}

 

3
Graphics / [SOLVED]Can't get a smooth motion (First Time)
« on: October 02, 2013, 05:38:23 am »
I am making a pong clone for a first project, but so far the paddle's movement choppy, not laggy, but just skips from one place to another. Try this out and please tell me how to fix this.

#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;

float ballSpeed = 400.0f;
float paddleSpeed = 10000.0f;
float ballVelX = 10;
float ballVelY = 10;


sf::Clock cloc;
sf::Time tim;


bool isPlaying = true;

sf::Vector2i screenSize(800,600);

int main()
{

    sf::CircleShape pongBall;
    //sf::CircleShape::
    pongBall.setFillColor(sf::Color::Red);
    pongBall.setRadius(25.0f);
    pongBall.setPosition(400, 300);

    sf::RectangleShape paddle1;
    // sf::RectangleShape::
    paddle1.setFillColor(sf::Color::Yellow);
    paddle1.setSize(sf::Vector2f(50, 250));
    paddle1.setPosition(0, 175);

    sf::RectangleShape paddle2;
    // sf::RectangleShape::
    paddle2.setFillColor(sf::Color::Yellow);
    paddle2.setSize(sf::Vector2f(50, 250));
    paddle2.setPosition(750, 175);

    pongBall.setPosition(400, 300);
    paddle1.setPosition(1, 250);
    paddle2.setPosition(784, 250);

    float t = rand() % 1;
    float w = rand() % 1;



    sf::RenderWindow window(sf::VideoMode(screenSize.x, screenSize.y), "Pro");

    float deltaTime = cloc.restart().asSeconds();

    cloc.restart();

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

        while(window.pollEvent(event)){
            if(event.type == sf::Event::Closed){
                window.close();
            }
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::W)){
                paddle1.move(0, paddleSpeed * cloc.getElapsedTime().asSeconds());
                if(paddle1.getPosition().y < 0){



                paddle1.setPosition(15, 0);
                }
                if(paddle1.getPosition().y > window.getSize().y){
                    paddle1.setPosition(10, 10);
                }
            }
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)){
                paddle1.move(0,  paddleSpeed * cloc.getElapsedTime().asSeconds());
                if(paddle1.getPosition().y > 491)
                paddle1.setPosition(1, 490);

                cout << paddle1.getPosition().y << endl;
                     if(paddle1.getPosition().y > window.getSize().y){
                    paddle1.setPosition(10, 10);
                }
        }

            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)){


            }

        }
    window.clear();
    window.draw(pongBall);
    window.draw(paddle1);
    window.draw(paddle2);
    window.display();

}




}

 

Pages: [1]
anything