I tried everything to make this more bouncy... but imposs :(
Please, help, and sorry for spam :(
// Football Head Champions.cpp : main project file.
#include "stdafx.h"
#include "SFML/Window.hpp"
#include "SFML/Graphics.hpp"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <algorithm>
#include <cmath>
using namespace System;
int main(array<System::String ^> ^args)
{
bool isPlaying;
sf::RenderWindow window;
window.create(sf::VideoMode(800, 600), L"Building Blocks");
float gravity = 0.6;
float tempV;
int ypos;
int i = 2;
bool collision = false;
float v;
float time;
sf::Clock clock;
sf::Texture ballTXT;
ballTXT.loadFromFile("data/ball.png");
sf::Sprite ball;
ball.setTexture(ballTXT);
ball.setOrigin(ball.getGlobalBounds().width / 2, ball.getGlobalBounds().height / 2);
ball.setPosition(400, 400);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
ball.move(0, 1.0f);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
ball.move(0, -1.0f);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
ball.move(1.0f, 0);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
ball.move(-1.0f, 0);
}
time = clock.getElapsedTime().asSeconds();
if(collision == false)
{
v = gravity * time;
}
ball.move(0,v);
ypos = ball.getPosition().y;
if(ball.getPosition().y + ball.getGlobalBounds().height >= 580)
{
collision = true;
tempV = v;
clock.restart();
ball.setPosition(ball.getPosition().x, 579.9999 - ball.getGlobalBounds().height);
i++;
}
time = clock.getElapsedTime().asSeconds();
if(collision == true)
{
v = -((1 * tempV) / 2 - gravity * time);
if(-v <= 0)
{
collision = false;
}
}
window.clear(sf::Color(0, 50, 180));
window.draw(ball);
window.display();
}
return 0;
}