OMGOSH it actually works thanks soo much. now I actually used a while statement instead of switch cause I actually don't have any switch statements in my game. I hope this isn't a bad thing?? Here is my code if u want to check it out.
#include <iostream>
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <string>
#include <sstream>
using namespace sf;
using namespace std;
int main(){
Clock clock;
clock.restart();
RenderWindow window(sf::VideoMode(1000, 1000), "My window");
window.setTitle("SFML window");
window.setFramerateLimit(60);
FloatRect SwindowBounds({49.f, 0.f},{955.f, 970.f} );
FloatRect AwindowBounds({0.f, 0.f},{1000.f, 1000.f} );
Text text;
Font font;
if (!font.loadFromFile("sansation.ttf")){
return EXIT_FAILURE;
}
text.setCharacterSize(100);
text.setFillColor(sf::Color::Black);
text.setString("five");
text.setFont(font);
text.setStyle(sf::Text::Bold | sf::Text::Underlined);
Texture backGround;
if(!backGround.loadFromFile("2616074.jpg")){
return EXIT_FAILURE;
}
Sprite BG(backGround);
CircleShape triangle(80.f, 3);
Texture Astroid;
if(!Astroid.loadFromFile("Astroid.png")){
return EXIT_FAILURE;
}
Sprite sprite1(Astroid);
Sprite sprite2(Astroid);
Sprite sprite3(Astroid);
Sprite sprite4(Astroid);
Sprite sprite5(Astroid);
BG.setScale(.7, .7);
triangle.setPosition(425, 625);
triangle.setScale(.4, .4);
sprite1.setPosition(700, -50);
sprite1.setScale(.15, .15);
sprite2.setPosition(500, -50);
sprite2.setScale(.17, .17);
sprite3.setPosition(300, -50);
sprite3.setScale(.12, .12);
sprite4.setPosition(600, -50);
sprite4.setScale(.18, .18);
sprite5.setPosition(400, -50);
sprite5.setScale(.15, .15);
while (window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed){
window.close();
}
}
//here is how I paused it
bool isPaused = false;
while(sf::Event::KeyReleased){
if(event.key.code == sf::Keyboard::Escape)
isPaused = true;
break;
}
if (!isPaused) {
window.clear(Color::White);
window.draw(BG);
Time elapsed = clock.getElapsedTime();
int sec = elapsed.asSeconds();
cout << sec << endl;
if(sec >= 2){
window.draw(sprite1);
sprite1.move(0.0f,8.0f);
}
if(sec >= 5){
window.draw(sprite2);
sprite2.move(0.0f,7.0f);
}
if(sec >= 10){
window.draw(sprite3);
sprite3.move(0.0f,8.0f);
}
if(sec >= 15){
window.draw(sprite4);
sprite4.move(0.0f,9.0f);
}
if(sec >= 20){
window.draw(sprite5);
sprite5.move(0.0f,6.0f);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)){
triangle.move(Vector2f(-15.f, 0.f));
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)){
triangle.move(Vector2f(15.f, 0.f));
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)){
triangle.move(Vector2f(0.f, -15.f));
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)){
triangle.move(Vector2f(0.f, 15.f));
}
FloatRect shipBox = triangle.getGlobalBounds();
FloatRect astroidBox1 = sprite1.getGlobalBounds();
FloatRect astroidBox2 = sprite2.getGlobalBounds();
FloatRect astroidBox3 = sprite3.getGlobalBounds();
FloatRect astroidBox4 = sprite4.getGlobalBounds();
FloatRect astroidBox5 = sprite5.getGlobalBounds();
if (!shipBox.intersects(SwindowBounds))
{
window.close();
}
if (shipBox.intersects(astroidBox1))
{
window.close();
}
if (shipBox.intersects(astroidBox2))
{
window.close();
}
if (shipBox.intersects(astroidBox3))
{
window.close();
}
if (shipBox.intersects(astroidBox4))
{
window.close();
}
if (shipBox.intersects(astroidBox5))
{
window.close();
}
if (!astroidBox1.intersects(AwindowBounds))
{
sprite1.setPosition(rand()%1000-1,-50);
}
if (!astroidBox2.intersects(AwindowBounds))
{
sprite2.setPosition(rand()%1000-1,-50);
}
if (!astroidBox3.intersects(AwindowBounds))
{
sprite3.setPosition(rand()%1000-1,-50);
}
if (!astroidBox4.intersects(AwindowBounds))
{
sprite4.setPosition(rand()%1000-1,-50);
}
if (!astroidBox5.intersects(AwindowBounds))
{
sprite5.setPosition(rand()%1000-1,-50);
}
window.draw(triangle);
window.display();}
}
}