Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.53 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2.  
  3. int screen_hight = 1024, screen_width = 640;
  4. static int position_x = 10, position_y = 415;
  5. int backgroundPosition1_x = 0, backgroundPosition_y = 0;
  6. int backgroundPosition2_x = 1023;
  7. int main();
  8. void character();
  9. void character1();
  10. sf::RenderWindow window(sf::VideoMode(screen_hight, screen_width), "Rezaul", sf::Style::Close | sf::Style::Default | sf::Style::Resize | sf::Style::Titlebar);
  11. int level = 0;
  12.  
  13.  
  14. void jump(int *position_x, int *backgroundPosition1_x, int *backgroundPosition2_x, int level, char backState[]){
  15. sf::Clock clock;
  16. sf::Time time = sf::seconds(1.5);
  17.  
  18. sf::Clock clock1;
  19. sf::Time time1 = sf::milliseconds(1);
  20.  
  21. sf::Texture background;
  22. sf::Sprite backgroundSprite;
  23. background.loadFromFile(backState);
  24. backgroundSprite.setTexture(background);
  25.  
  26. sf::Texture background1;
  27. sf::Sprite backgroundSprite1;
  28. background1.loadFromFile(backState);
  29. backgroundSprite1.setTexture(background1);
  30.  
  31. while (window.isOpen()){
  32.  
  33. sf::Event evnt;
  34. while (window.pollEvent(evnt)){
  35. if (evnt.type == evnt.Closed){
  36. window.close();
  37. }
  38.  
  39. }
  40. if (clock.getElapsedTime() > time){
  41. if (level == 1)
  42. character();
  43. if (level == 2)
  44. character1();
  45. }
  46. if (clock1.getElapsedTime() > time1){
  47. sf::Vector2i mousePos;
  48. sf::Texture jerry;
  49. sf::Sprite jerrySprite;
  50. jerry.loadFromFile("1.png");
  51. jerrySprite.setTexture(jerry);
  52. backgroundSprite1.setPosition(*backgroundPosition2_x, 0);
  53. backgroundSprite.setPosition(*backgroundPosition1_x, 0);
  54. jerrySprite.setPosition(*position_x, position_y - 40);
  55.  
  56.  
  57.  
  58. if (*position_x > 320){
  59. *backgroundPosition1_x -= 10;
  60. *backgroundPosition2_x -= 10;
  61. if (*backgroundPosition1_x < -1024)
  62. *backgroundPosition1_x = *backgroundPosition2_x + 1023;
  63. if (*backgroundPosition2_x < -1024)
  64. *backgroundPosition2_x = *backgroundPosition1_x + 1023;
  65. }
  66. else
  67. *position_x += 10;
  68.  
  69. if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
  70. *position_x = 0, main();
  71.  
  72. window.clear(sf::Color(255, 255, 255));
  73.  
  74. window.draw(backgroundSprite);
  75.  
  76. window.draw(backgroundSprite1);
  77.  
  78. window.draw(jerrySprite);
  79.  
  80. window.display();
  81.  
  82. clock1.restart();
  83. }
  84. }
  85. }
  86.  
  87.  
  88. void character1(){
  89. char ara[][100] = { "1.png", "1.png", "2.png", "2.png", "3.png", "3.png", "4.png", "4.png", "3.png", "3.png" };
  90. int x = 0;
  91.  
  92.  
  93. sf::Clock clock;
  94. sf::Time time = sf::milliseconds(1);
  95.  
  96. sf::Clock clock1;
  97. sf::Time time1 = sf::milliseconds(500);
  98.  
  99. sf::Texture background;
  100. sf::Sprite backgroundSprite;
  101.  
  102. background.loadFromFile("1b1.png");
  103. backgroundSprite.setTexture(background);
  104.  
  105. sf::Texture background1;
  106. sf::Sprite backgroundSprite1;
  107. background1.loadFromFile("1b1.png");
  108. backgroundSprite1.setTexture(background1);
  109. char backState[] = { "1b1.png" };
  110. while (window.isOpen()){
  111. sf::Event evnt;
  112. while (window.pollEvent(evnt)){
  113. if (evnt.type == evnt.Closed){
  114. window.close();
  115. }
  116.  
  117. }
  118. sf::Vector2i mousePos;
  119. if (sf::Mouse::isButtonPressed(sf::Mouse::Left)){
  120. mousePos = sf::Mouse::getPosition(window);
  121. }
  122. sf::Texture jerry;
  123. sf::Sprite jerrySprite;
  124. if (clock.getElapsedTime() > time){
  125. backgroundSprite1.setPosition(backgroundPosition2_x, 0);
  126. backgroundSprite.setPosition(backgroundPosition1_x, 0);
  127. if (x > 9)
  128. x = 0;
  129.  
  130. if (clock1.getElapsedTime() > time1 && sf::Keyboard::isKeyPressed(sf::Keyboard::Up)){
  131. jump(&position_x, &backgroundPosition1_x, &backgroundPosition2_x, 2, backState);
  132. clock1.restart();
  133. }
  134.  
  135. if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
  136. jerry.loadFromFile("2.png"), position_y - 10, jerrySprite.setPosition(position_x, position_y);
  137. else{
  138. jerry.loadFromFile(ara[x]);
  139. jerrySprite.setPosition(position_x, position_y);
  140. }
  141. x++;
  142. jerrySprite.setTexture(jerry);
  143.  
  144.  
  145. if (position_x > 320){
  146. backgroundPosition1_x -= 10;
  147. backgroundPosition2_x -= 10;
  148. if (backgroundPosition1_x < -1024)
  149. backgroundPosition1_x = backgroundPosition2_x + 1023;
  150. if (backgroundPosition2_x < -1024)
  151. backgroundPosition2_x = backgroundPosition1_x + 1023;
  152. }
  153. else
  154. position_x += 10;
  155. /*if (level >= 1)
  156. character1();*/
  157. if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
  158. position_x =0,main();
  159. window.clear(sf::Color(255, 255, 255));
  160. window.draw(backgroundSprite);
  161. window.draw(backgroundSprite1);
  162. window.draw(jerrySprite);
  163. window.display();
  164. clock.restart();
  165. }
  166. }
  167.  
  168. }
  169.  
  170.  
  171. void character(){
  172. char ara[][100] = { "1.png", "1.png", "2.png", "2.png", "3.png", "3.png", "4.png", "4.png", "3.png", "3.png" };
  173. int x = 0;
  174.  
  175. sf::Clock clock;
  176. sf::Time time = sf::microseconds(20);
  177.  
  178. sf::Clock clock1;
  179. sf::Time time1 = sf::milliseconds(500);
  180.  
  181. sf::Texture background;
  182. sf::Sprite backgroundSprite;
  183.  
  184. background.loadFromFile("b1.png");
  185. backgroundSprite.setTexture(background);
  186.  
  187. sf::Texture background1;
  188. sf::Sprite backgroundSprite1;
  189. background1.loadFromFile("b1.png");
  190. backgroundSprite1.setTexture(background1);
  191.  
  192. char backState[] = { "b1.png" };
  193. while (window.isOpen()){
  194. sf::Event evnt;
  195. while (window.pollEvent(evnt)){
  196. if (evnt.type == evnt.Closed){
  197. window.close();
  198. }
  199.  
  200. }
  201. sf::Vector2i mousePos;
  202. if (sf::Mouse::isButtonPressed(sf::Mouse::Left)){
  203. mousePos = sf::Mouse::getPosition(window);
  204. }
  205.  
  206. if (clock.getElapsedTime() > time){
  207. sf::Texture jerry;
  208. sf::Sprite jerrySprite;
  209. backgroundSprite1.setPosition(backgroundPosition2_x, 0);
  210. backgroundSprite.setPosition(backgroundPosition1_x, 0);
  211. if (x > 9)
  212. x = 0;
  213. if (clock1.getElapsedTime() > time1 && sf::Keyboard::isKeyPressed(sf::Keyboard::Up)){
  214. jump(&position_x, &backgroundPosition1_x, &backgroundPosition2_x, 1, backState);
  215. clock1.restart();
  216. }
  217. else{
  218. jerry.loadFromFile(ara[x]);
  219. jerrySprite.setPosition(position_x, position_y);
  220. }
  221. x++;
  222. jerrySprite.setTexture(jerry);
  223. int state = 1;
  224.  
  225. if (position_x > 320 && level<1){
  226. backgroundPosition1_x -= 10;
  227. backgroundPosition2_x -= 10;
  228. if (backgroundPosition1_x < -1024)
  229. backgroundPosition1_x = backgroundPosition2_x + 1023, level++;
  230. if (backgroundPosition2_x < -1024)
  231. backgroundPosition2_x = backgroundPosition1_x + 1023, level++;
  232. if (level >= 1){
  233. state = 1;
  234. }
  235. }
  236. else if(state==1)
  237. position_x += 10;
  238. if (position_x>1015){
  239. position_x = 2;
  240. position_y += 7;
  241. character1();
  242. }
  243. if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
  244. position_x = 0, main();
  245. window.clear(sf::Color(255, 255, 255));
  246. window.draw(backgroundSprite);
  247. window.draw(backgroundSprite1);
  248. window.draw(jerrySprite);
  249. window.display();
  250. clock.restart();
  251. }
  252. }
  253.  
  254. }
  255.  
  256. int main()
  257. {
  258.  
  259.  
  260. sf::Texture imgTexture;
  261. imgTexture.loadFromFile("welcome.jpg");
  262. sf::Sprite sprite;
  263. sprite.setTexture(imgTexture);
  264.  
  265. sf::Texture newGame;
  266. newGame.loadFromFile("new.png");//hight of the photo=63 and width=251
  267. sf::Sprite newGameSprite;
  268. newGameSprite.setTexture(newGame);
  269. newGameSprite.setPosition(650, 227);
  270.  
  271. sf::Texture highScore;
  272. highScore.loadFromFile("highscore.png");//hight of the photo=63 and width=251
  273. sf::Sprite highScoreSprite;
  274. highScoreSprite.setTexture(highScore);
  275. highScoreSprite.setPosition(650, 300);
  276.  
  277. sf::Texture highScore1;
  278. highScore1.loadFromFile("highscore1.png");//hight of the photo=63 and width=251
  279. sf::Sprite highScore1Sprite;
  280. highScore1Sprite.setTexture(highScore1);
  281. highScore1Sprite.setPosition(650, 300);
  282.  
  283. sf::Texture exit;
  284. exit.loadFromFile("exit.png");//hight of the photo=63 and width=251
  285. sf::Sprite exitSprite;
  286. exitSprite.setTexture(exit);
  287. exitSprite.setPosition(650, 446);
  288.  
  289. sf::Texture exit1;
  290. exit1.loadFromFile("exit1.png");//hight of the photo=63 and width=251
  291. sf::Sprite exit1Sprite;
  292. exit1Sprite.setTexture(exit1);
  293. exit1Sprite.setPosition(650, 446);
  294.  
  295. sf::Texture introduction;
  296. introduction.loadFromFile("intro.png");//hight of the photo=63 and width=251
  297. sf::Sprite introductionSprite;
  298. introductionSprite.setTexture(introduction);
  299. introductionSprite.setPosition(650, 373);
  300.  
  301. sf::Texture introduction1;
  302. introduction1.loadFromFile("intro1.png");//hight of the photo=63 and width=251
  303. sf::Sprite introduction1Sprite;
  304. introduction1Sprite.setTexture(introduction1);
  305. introduction1Sprite.setPosition(650, 373);
  306.  
  307. sf::Texture new1Game;
  308. new1Game.loadFromFile("new1.png");//hight of the photo=63 and width=251
  309. sf::Sprite new1GameSprite;
  310. new1GameSprite.setTexture(new1Game);
  311. new1GameSprite.setPosition(650, 227);
  312.  
  313.  
  314. while (window.isOpen()){
  315. sf::Event evnt;
  316. while (window.pollEvent(evnt)){
  317. if (evnt.type == evnt.Closed){
  318. window.close();
  319. }
  320.  
  321. }
  322. sf::Vector2i mousePos;
  323. if (sf::Mouse::isButtonPressed(sf::Mouse::Left)){
  324. mousePos = sf::Mouse::getPosition(window);
  325. }
  326.  
  327.  
  328.  
  329. window.clear();
  330. window.draw(sprite);
  331. window.draw(newGameSprite);
  332. window.draw(highScoreSprite);
  333. window.draw(exitSprite);
  334. window.draw(introductionSprite);
  335. if (mousePos.x >= 670 && mousePos.x <= 875 && mousePos.y >= 227 && mousePos.y <= 290){
  336.  
  337. character();
  338. }
  339. if (mousePos.x >= 670 && mousePos.x <= 875 && mousePos.y >= 300 && mousePos.y <= 363){
  340. window.draw(highScore1Sprite);
  341. }
  342. if (mousePos.x >= 670 && mousePos.x <= 875 && mousePos.y >= 373 && mousePos.y <= 436){
  343. window.draw(introduction1Sprite);
  344. }
  345. if (mousePos.x >= 670 && mousePos.x <= 875 && mousePos.y >= 446 && mousePos.y <= 505){
  346. window.draw(exit1Sprite);
  347. window.close();
  348. }
  349.  
  350. window.display();
  351. }
  352.  
  353. return 0;
  354. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement