paupav Master Cheater
Reputation: 13
Joined: 15 Apr 2011 Posts: 314 Location: P. Sherman 42, Wallaby Way, Sydney
|
Posted: Fri Mar 28, 2014 7:50 pm Post subject: I've made a game in SFML |
|
|
| Code: | #include <iostream>
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Paupav ball game");
sf::Clock clock;
sf::Clock clock2;
bool returning = false;
int positionx = 10;
double positiony = 16;
sf::CircleShape shape(30, 999);
sf::Texture texture, texture2;
if(!texture.loadFromFile("texture.jpg"))
{
std::cout << "Could not load ball texture" << std::endl;
}
shape.setTexture(&texture);
//floor
sf::RectangleShape floor(sf::Vector2f(800, 60));
if(!texture2.loadFromFile("brick.png"))
{
std::cout << "Could not load floor texture" << std::endl;
}
floor.setTexture(&texture2);
floor.setPosition(0, 540);
while(window.isOpen())
{
sf::Time time = clock.getElapsedTime();
sf::Time physic = clock2.getElapsedTime();
double restart = physic.asMilliseconds();
shape.setPosition(positionx, positiony);
if(!returning)
positiony = time.asMicroseconds() / 2319 + physic.asMilliseconds()/ 30;
if(positiony > 500)
{
returning = true;
}
if(returning )
{
positiony -=8;
clock.restart();
}
if(positiony < 15 + physic.asMilliseconds()/ 30)
{
returning = false;
}
std::cout << "Gravity:" << physic.asMilliseconds() << std::endl;
if(physic.asMilliseconds() > 17000.00)
{
clock.restart();
clock2.restart();
}
sf::Event event;
while(window.pollEvent(event))
{
switch(event.type)
{
case sf::Event::Closed:
window.close();
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
positionx += 10;
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
positionx -= 10;
}
}
window.clear(sf::Color::White);
window.draw(shape);
window.draw(floor);
window.display();
}
}
|
DOWNLOAD links:
linux: http://ubuntuone.com/3Tc8AbQCcJ2jd2xqN2OC3e
I don't have SFML on windows |
|