Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- int screen_hight = 1024, screen_width = 640;
- static int position_x = 10, position_y = 415;
- int backgroundPosition1_x = 0, backgroundPosition_y = 0;
- int backgroundPosition2_x = 1023;
- int main();
- void character();
- void character1();
- sf::RenderWindow window(sf::VideoMode(screen_hight, screen_width), "Rezaul", sf::Style::Close | sf::Style::Default | sf::Style::Resize | sf::Style::Titlebar);
- int level = 0;
- void jump(int *position_x, int *backgroundPosition1_x, int *backgroundPosition2_x, int level, char backState[]){
- sf::Clock clock;
- sf::Time time = sf::seconds(1.5);
- sf::Clock clock1;
- sf::Time time1 = sf::milliseconds(1);
- sf::Texture background;
- sf::Sprite backgroundSprite;
- background.loadFromFile(backState);
- backgroundSprite.setTexture(background);
- sf::Texture background1;
- sf::Sprite backgroundSprite1;
- background1.loadFromFile(backState);
- backgroundSprite1.setTexture(background1);
- while (window.isOpen()){
- sf::Event evnt;
- while (window.pollEvent(evnt)){
- if (evnt.type == evnt.Closed){
- window.close();
- }
- }
- if (clock.getElapsedTime() > time){
- if (level == 1)
- character();
- if (level == 2)
- character1();
- }
- if (clock1.getElapsedTime() > time1){
- sf::Vector2i mousePos;
- sf::Texture jerry;
- sf::Sprite jerrySprite;
- jerry.loadFromFile("1.png");
- jerrySprite.setTexture(jerry);
- backgroundSprite1.setPosition(*backgroundPosition2_x, 0);
- backgroundSprite.setPosition(*backgroundPosition1_x, 0);
- jerrySprite.setPosition(*position_x, position_y - 40);
- if (*position_x > 320){
- *backgroundPosition1_x -= 10;
- *backgroundPosition2_x -= 10;
- if (*backgroundPosition1_x < -1024)
- *backgroundPosition1_x = *backgroundPosition2_x + 1023;
- if (*backgroundPosition2_x < -1024)
- *backgroundPosition2_x = *backgroundPosition1_x + 1023;
- }
- else
- *position_x += 10;
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
- *position_x = 0, main();
- window.clear(sf::Color(255, 255, 255));
- window.draw(backgroundSprite);
- window.draw(backgroundSprite1);
- window.draw(jerrySprite);
- window.display();
- clock1.restart();
- }
- }
- }
- void character1(){
- char ara[][100] = { "1.png", "1.png", "2.png", "2.png", "3.png", "3.png", "4.png", "4.png", "3.png", "3.png" };
- int x = 0;
- sf::Clock clock;
- sf::Time time = sf::milliseconds(1);
- sf::Clock clock1;
- sf::Time time1 = sf::milliseconds(500);
- sf::Texture background;
- sf::Sprite backgroundSprite;
- background.loadFromFile("1b1.png");
- backgroundSprite.setTexture(background);
- sf::Texture background1;
- sf::Sprite backgroundSprite1;
- background1.loadFromFile("1b1.png");
- backgroundSprite1.setTexture(background1);
- char backState[] = { "1b1.png" };
- while (window.isOpen()){
- sf::Event evnt;
- while (window.pollEvent(evnt)){
- if (evnt.type == evnt.Closed){
- window.close();
- }
- }
- sf::Vector2i mousePos;
- if (sf::Mouse::isButtonPressed(sf::Mouse::Left)){
- mousePos = sf::Mouse::getPosition(window);
- }
- sf::Texture jerry;
- sf::Sprite jerrySprite;
- if (clock.getElapsedTime() > time){
- backgroundSprite1.setPosition(backgroundPosition2_x, 0);
- backgroundSprite.setPosition(backgroundPosition1_x, 0);
- if (x > 9)
- x = 0;
- if (clock1.getElapsedTime() > time1 && sf::Keyboard::isKeyPressed(sf::Keyboard::Up)){
- jump(&position_x, &backgroundPosition1_x, &backgroundPosition2_x, 2, backState);
- clock1.restart();
- }
- if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
- jerry.loadFromFile("2.png"), position_y - 10, jerrySprite.setPosition(position_x, position_y);
- else{
- jerry.loadFromFile(ara[x]);
- jerrySprite.setPosition(position_x, position_y);
- }
- x++;
- jerrySprite.setTexture(jerry);
- if (position_x > 320){
- backgroundPosition1_x -= 10;
- backgroundPosition2_x -= 10;
- if (backgroundPosition1_x < -1024)
- backgroundPosition1_x = backgroundPosition2_x + 1023;
- if (backgroundPosition2_x < -1024)
- backgroundPosition2_x = backgroundPosition1_x + 1023;
- }
- else
- position_x += 10;
- /*if (level >= 1)
- character1();*/
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
- position_x =0,main();
- window.clear(sf::Color(255, 255, 255));
- window.draw(backgroundSprite);
- window.draw(backgroundSprite1);
- window.draw(jerrySprite);
- window.display();
- clock.restart();
- }
- }
- }
- void character(){
- char ara[][100] = { "1.png", "1.png", "2.png", "2.png", "3.png", "3.png", "4.png", "4.png", "3.png", "3.png" };
- int x = 0;
- sf::Clock clock;
- sf::Time time = sf::microseconds(20);
- sf::Clock clock1;
- sf::Time time1 = sf::milliseconds(500);
- sf::Texture background;
- sf::Sprite backgroundSprite;
- background.loadFromFile("b1.png");
- backgroundSprite.setTexture(background);
- sf::Texture background1;
- sf::Sprite backgroundSprite1;
- background1.loadFromFile("b1.png");
- backgroundSprite1.setTexture(background1);
- char backState[] = { "b1.png" };
- while (window.isOpen()){
- sf::Event evnt;
- while (window.pollEvent(evnt)){
- if (evnt.type == evnt.Closed){
- window.close();
- }
- }
- sf::Vector2i mousePos;
- if (sf::Mouse::isButtonPressed(sf::Mouse::Left)){
- mousePos = sf::Mouse::getPosition(window);
- }
- if (clock.getElapsedTime() > time){
- sf::Texture jerry;
- sf::Sprite jerrySprite;
- backgroundSprite1.setPosition(backgroundPosition2_x, 0);
- backgroundSprite.setPosition(backgroundPosition1_x, 0);
- if (x > 9)
- x = 0;
- if (clock1.getElapsedTime() > time1 && sf::Keyboard::isKeyPressed(sf::Keyboard::Up)){
- jump(&position_x, &backgroundPosition1_x, &backgroundPosition2_x, 1, backState);
- clock1.restart();
- }
- else{
- jerry.loadFromFile(ara[x]);
- jerrySprite.setPosition(position_x, position_y);
- }
- x++;
- jerrySprite.setTexture(jerry);
- int state = 1;
- if (position_x > 320 && level<1){
- backgroundPosition1_x -= 10;
- backgroundPosition2_x -= 10;
- if (backgroundPosition1_x < -1024)
- backgroundPosition1_x = backgroundPosition2_x + 1023, level++;
- if (backgroundPosition2_x < -1024)
- backgroundPosition2_x = backgroundPosition1_x + 1023, level++;
- if (level >= 1){
- state = 1;
- }
- }
- else if(state==1)
- position_x += 10;
- if (position_x>1015){
- position_x = 2;
- position_y += 7;
- character1();
- }
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
- position_x = 0, main();
- window.clear(sf::Color(255, 255, 255));
- window.draw(backgroundSprite);
- window.draw(backgroundSprite1);
- window.draw(jerrySprite);
- window.display();
- clock.restart();
- }
- }
- }
- int main()
- {
- sf::Texture imgTexture;
- imgTexture.loadFromFile("welcome.jpg");
- sf::Sprite sprite;
- sprite.setTexture(imgTexture);
- sf::Texture newGame;
- newGame.loadFromFile("new.png");//hight of the photo=63 and width=251
- sf::Sprite newGameSprite;
- newGameSprite.setTexture(newGame);
- newGameSprite.setPosition(650, 227);
- sf::Texture highScore;
- highScore.loadFromFile("highscore.png");//hight of the photo=63 and width=251
- sf::Sprite highScoreSprite;
- highScoreSprite.setTexture(highScore);
- highScoreSprite.setPosition(650, 300);
- sf::Texture highScore1;
- highScore1.loadFromFile("highscore1.png");//hight of the photo=63 and width=251
- sf::Sprite highScore1Sprite;
- highScore1Sprite.setTexture(highScore1);
- highScore1Sprite.setPosition(650, 300);
- sf::Texture exit;
- exit.loadFromFile("exit.png");//hight of the photo=63 and width=251
- sf::Sprite exitSprite;
- exitSprite.setTexture(exit);
- exitSprite.setPosition(650, 446);
- sf::Texture exit1;
- exit1.loadFromFile("exit1.png");//hight of the photo=63 and width=251
- sf::Sprite exit1Sprite;
- exit1Sprite.setTexture(exit1);
- exit1Sprite.setPosition(650, 446);
- sf::Texture introduction;
- introduction.loadFromFile("intro.png");//hight of the photo=63 and width=251
- sf::Sprite introductionSprite;
- introductionSprite.setTexture(introduction);
- introductionSprite.setPosition(650, 373);
- sf::Texture introduction1;
- introduction1.loadFromFile("intro1.png");//hight of the photo=63 and width=251
- sf::Sprite introduction1Sprite;
- introduction1Sprite.setTexture(introduction1);
- introduction1Sprite.setPosition(650, 373);
- sf::Texture new1Game;
- new1Game.loadFromFile("new1.png");//hight of the photo=63 and width=251
- sf::Sprite new1GameSprite;
- new1GameSprite.setTexture(new1Game);
- new1GameSprite.setPosition(650, 227);
- while (window.isOpen()){
- sf::Event evnt;
- while (window.pollEvent(evnt)){
- if (evnt.type == evnt.Closed){
- window.close();
- }
- }
- sf::Vector2i mousePos;
- if (sf::Mouse::isButtonPressed(sf::Mouse::Left)){
- mousePos = sf::Mouse::getPosition(window);
- }
- window.clear();
- window.draw(sprite);
- window.draw(newGameSprite);
- window.draw(highScoreSprite);
- window.draw(exitSprite);
- window.draw(introductionSprite);
- if (mousePos.x >= 670 && mousePos.x <= 875 && mousePos.y >= 227 && mousePos.y <= 290){
- character();
- }
- if (mousePos.x >= 670 && mousePos.x <= 875 && mousePos.y >= 300 && mousePos.y <= 363){
- window.draw(highScore1Sprite);
- }
- if (mousePos.x >= 670 && mousePos.x <= 875 && mousePos.y >= 373 && mousePos.y <= 436){
- window.draw(introduction1Sprite);
- }
- if (mousePos.x >= 670 && mousePos.x <= 875 && mousePos.y >= 446 && mousePos.y <= 505){
- window.draw(exit1Sprite);
- window.close();
- }
- window.display();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement