Advertisement
TermSpar

Main.cpp of Game

Aug 11th, 2016
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 17.48 KB | None | 0 0
  1. //Library Includes:
  2. #include <iostream>
  3. #include <SFML/Graphics.hpp>
  4. #include <sstream>
  5.  
  6. //Object Classes:
  7. #include "Arrow.h"
  8. #include "InsectImage.h"
  9. #include "Button.h"
  10. #include "Waypoint.h"
  11.  
  12. //Player Classes:
  13. #include "Caterpillar.h"
  14. #include "Ant.h"
  15. #include "Grasshopper.h"
  16. #include "Scorpion.h"
  17.  
  18. //Window States:
  19. #define MAIN_MENU 1
  20. #define MAIN_GAME 2
  21. #define CHOOSE_INSECT 10
  22.  
  23. int main() {
  24.     sf::RenderWindow window;
  25.  
  26.     sf::Vector2i centerWindow((sf::VideoMode::getDesktopMode().width / 2) - 445, (sf::VideoMode::getDesktopMode().height / 2) - 480);
  27.  
  28.     window.create(sf::VideoMode(900, 900), "Insect World", sf::Style::Titlebar | sf::Style::Close);
  29.     window.setPosition(centerWindow);
  30.  
  31.     window.setKeyRepeatEnabled(true);
  32.  
  33.     int windowState = MAIN_MENU;
  34.  
  35.     //Insect Species:
  36.     enum InsectSpecies {
  37.         none,
  38.         caterpillar,
  39.         grasshopper,
  40.         ant
  41.     };
  42.     InsectSpecies insectID = none;
  43.  
  44.     //Load In Fonts:
  45.     sf::Font arial;
  46.     if (!arial.loadFromFile("arial.ttf")) {
  47.         std::cerr << "Error Loading Font\n";
  48.     }
  49.     sf::Font impact;
  50.     if (!impact.loadFromFile("impact.ttf")) {
  51.         std::cerr << "Error Loading Impact\n";
  52.     }
  53.  
  54.     //Default View:
  55.     sf::View noView;
  56.     noView.setCenter(window.getDefaultView().getCenter().x, window.getDefaultView().getCenter().y);
  57.  
  58.     /* WINDOW STATE 1: MAIN MENU */
  59.  
  60. main_menu:
  61.     //Welcome Label:
  62.     sf::Text lblWelcome;
  63.     lblWelcome.setCharacterSize(150);
  64.     lblWelcome.setFont(impact);
  65.     lblWelcome.setColor(sf::Color::Cyan);
  66.     lblWelcome.setString("Insect World");
  67.     lblWelcome.setPosition({ 60, 10 });
  68.  
  69.     //Label For btnPlay:
  70.     sf::Text lblBtnPlay;
  71.     lblBtnPlay.setCharacterSize(60);
  72.     lblBtnPlay.setString("Play");
  73.     lblBtnPlay.setFont(impact);
  74.  
  75.     lblBtnPlay.setPosition({ 400, 462 });
  76.     lblBtnPlay.setColor(sf::Color::Black);
  77.  
  78.     //btnPlay:
  79.     Button btnPlay({ 400, 100 });
  80.     btnPlay.setColor(sf::Color::Green);
  81.     btnPlay.setPos({ 250, 450 });
  82.  
  83.     //Label For btnChoose:
  84.     sf::Text lblBtnChoose;
  85.     lblBtnChoose.setCharacterSize(50);
  86.     lblBtnChoose.setString("Choose Insect");
  87.     lblBtnChoose.setFont(impact);
  88.  
  89.     lblBtnChoose.setPosition({ 300, 290 });
  90.     lblBtnChoose.setColor(sf::Color::Black);
  91.  
  92.     //btnChoose:
  93.     Button btnChoose({ 400, 100 });
  94.     btnChoose.setColor(sf::Color::Magenta);
  95.     btnChoose.setPos({ 250, 270 });
  96.  
  97.     //Main Menu Loop:
  98.     while (window.isOpen() && windowState == MAIN_MENU) {
  99.  
  100.         sf::Event Event;
  101.  
  102.         int mousePosX = sf::Mouse::getPosition().x - 520;
  103.         int mousePosY = sf::Mouse::getPosition().y - 89;
  104.  
  105.         //Event Loop:
  106.         while (window.pollEvent(Event)) {
  107.  
  108.             switch (Event.type) {
  109.  
  110.             case sf::Event::Closed:
  111.                 window.close();
  112.  
  113.             case sf::Event::MouseButtonPressed:
  114.                 if (btnPlay.isMouseOver(mousePosX, mousePosY)) {
  115.                     //Change WindowState To Game Window:
  116.                     windowState = MAIN_GAME;
  117.                 }
  118.                 if (btnChoose.isMouseOver(mousePosX, mousePosY)) {
  119.                     //Change WindowState To Choose Insect Window
  120.                     windowState = CHOOSE_INSECT;
  121.                 }
  122.  
  123.             case sf::Event::MouseMoved:
  124.                 if (btnPlay.isMouseOver(mousePosX, mousePosY)) {
  125.                     btnPlay.setColor(sf::Color(16, 133, 52));
  126.                 }
  127.                 else {
  128.                     btnPlay.setColor(sf::Color::Green);
  129.                 }
  130.  
  131.                 if (btnChoose.isMouseOver(mousePosX, mousePosY)) {
  132.                     btnChoose.setColor(sf::Color(148, 29, 124));
  133.                 }
  134.                 else {
  135.                     btnChoose.setColor(sf::Color::Magenta);
  136.                 }
  137.             }
  138.  
  139.         }
  140.         window.clear();
  141.         window.draw(lblWelcome);
  142.         btnPlay.drawTo(&window);
  143.         window.draw(lblBtnPlay);
  144.         btnChoose.drawTo(&window);
  145.         window.draw(lblBtnChoose);
  146.         window.setView(noView);
  147.         window.display();
  148.     }
  149.  
  150.  
  151.     /* WINDOW STATE 2: MAIN GAME */
  152.  
  153.     //Waypoints:
  154.     Waypoint point1({ 100, 900 }, sf::Color::Transparent);
  155.     point1.setPos({ 300, 0 });
  156.  
  157.     //Characters:
  158.     Caterpillar cater1(1);
  159.     if (insectID == caterpillar || insectID == none) {
  160.         cater1.setPos({ 100, 100 });
  161.     }
  162.     else {
  163.         cater1.setPos({ 43242, 423432 });
  164.     }
  165.  
  166.     Ant ant1;
  167.     if (insectID == ant) {
  168.         ant1.setPos({ 100, 100 });
  169.     }
  170.     else {
  171.         ant1.setPos({ 43242, 423432 });
  172.     }
  173.  
  174.     Grasshopper grass1;
  175.     if (insectID == grasshopper) {
  176.         grass1.setPos({ 100, 100 });
  177.     }
  178.     else {
  179.         grass1.setPos({ 43242, 423432 });
  180.     }
  181.  
  182.     //Gravity Vars:
  183.     const int groundHeight = 780;
  184.     bool isJumping = false;
  185.     const float fallSpeed = 0.6;
  186.  
  187.     //Movment Vars:
  188.     const float moveSpeed = 0.99;
  189.     const float jumpSpeed = 0.5;
  190.  
  191.     bool goingRight = false;
  192.     bool goingLeft = false;
  193.  
  194.     float x = cater1.getX();
  195.     float y = cater1.getY();
  196.  
  197.     //Player Coords:
  198.     sf::Text xCoord;
  199.     xCoord.setCharacterSize(30);
  200.     xCoord.setFont(arial);
  201.     xCoord.setPosition({ 453434, 53455 });
  202.     xCoord.setString("X Position: 0");
  203.  
  204.     sf::Text yCoord;
  205.     yCoord.setCharacterSize(30);
  206.     yCoord.setFont(arial);
  207.     yCoord.setPosition({ -54543, 54355 });
  208.     yCoord.setString("Y Position: 0");
  209.  
  210.     std::ostringstream ssX;
  211.     std::ostringstream ssY;
  212.  
  213.     bool coordsShowing = false;
  214.  
  215.     //Decoration:
  216.     sf::Texture grassTexture;
  217.     sf::Sprite grassWallpaper;
  218.     if (!grassTexture.loadFromFile("grassImage.png"))
  219.         std::cerr << "Error\n";
  220.     grassWallpaper.setTexture(grassTexture);
  221.     grassWallpaper.setPosition({ -10, 350 });
  222.  
  223.     sf::Texture grassTexture2;
  224.     sf::Sprite grassWallpaper2;
  225.     if (!grassTexture2.loadFromFile("grassImage.png"))
  226.         std::cerr << "Error\n";
  227.     grassWallpaper2.setTexture(grassTexture2);
  228.     grassWallpaper2.setPosition({ 3500, 350 });
  229.  
  230.     sf::Texture sunTexture;
  231.     sf::Sprite sunWallpaper;
  232.     if (!sunTexture.loadFromFile("sun.png"))
  233.         std::cerr << "Error\n";
  234.     sunWallpaper.setTexture(sunTexture);
  235.     sunWallpaper.setPosition({ -50, -50 });
  236.  
  237.     //Scorpion Vars:
  238.     std::vector<Scorpion*> scorpVec;
  239.  
  240.     Scorpion scorp1;
  241.     scorpVec.push_back(&scorp1);
  242.  
  243.     Scorpion scorp2;
  244.     scorpVec.push_back(&scorp2);
  245.  
  246.     Scorpion scorp3;
  247.     scorpVec.push_back(&scorp3);
  248.  
  249.     Scorpion scorp4;
  250.     scorpVec.push_back(&scorp4);
  251.    
  252.     for (int i = 0; i < scorpVec.size(); i++) {
  253.         scorpVec[i]->hide();
  254.     }
  255.  
  256.     bool scorpShown = false;
  257.     float scorpSpeed = 0.05f;
  258.  
  259.     //View Objects:
  260.     sf::View followPlayer;
  261.     followPlayer.reset(sf::FloatRect(0, 0, window.getSize().x, window.getSize().y));
  262.     sf::Vector2f position(window.getSize().x / 2, window.getSize().y / 2);
  263.  
  264.     //Game Loop:
  265.     while (window.isOpen() && windowState == MAIN_GAME) {
  266.  
  267.         sf::Event Event;
  268.  
  269.         //Caterpillar Movement:
  270.         if (insectID == caterpillar || insectID == none) {
  271.  
  272.             ssX.str("");
  273.             ssX << "X Position: " << cater1.getX();
  274.             xCoord.setString(ssX.str());
  275.  
  276.             ssY.str("");
  277.             ssY << "Y Position: " << cater1.getY();
  278.             yCoord.setString(ssY.str());
  279.  
  280.             if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
  281.                 if (goingLeft == true) {
  282.                     cater1.move({ -jumpSpeed, -jumpSpeed });
  283.                 }
  284.                 else if (goingRight == true) {
  285.                     cater1.move({ jumpSpeed, -jumpSpeed });
  286.                 }
  287.                 else {
  288.                     cater1.move({ 0, -jumpSpeed });
  289.                 }
  290.                 isJumping = true;
  291.             }
  292.             else if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
  293.                 cater1.move({ -moveSpeed, 0 });
  294.                 cater1.setImage('l');
  295.                 goingLeft = true;
  296.             }
  297.             else if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
  298.                 cater1.move({ moveSpeed, 0 });
  299.                 cater1.setImage('r');
  300.                 goingRight = true;
  301.             }
  302.             else if (sf::Keyboard::isKeyPressed(sf::Keyboard::F3)) {
  303.                 coordsShowing = true;
  304.             }
  305.             else if (sf::Keyboard::isKeyPressed(sf::Keyboard::F4)) {
  306.                 coordsShowing = false;
  307.             }
  308.         }
  309.        
  310.         //Ant Movement:
  311.         if (insectID == ant) {
  312.             ssX.str("");
  313.             ssX << "X Position: " << ant1.getX();
  314.             xCoord.setString(ssX.str());
  315.  
  316.             ssY.str("");
  317.             ssY << "Y Position: " << ant1.getY();
  318.             yCoord.setString(ssY.str());
  319.  
  320.             if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
  321.                 if (goingLeft == true) {
  322.                     ant1.move({ -jumpSpeed, -jumpSpeed });
  323.                 }
  324.                 else if (goingRight == true) {
  325.                     ant1.move({ jumpSpeed, -jumpSpeed });
  326.                 }
  327.                 else {
  328.                     ant1.move({ 0, -jumpSpeed });
  329.                 }
  330.                 isJumping = true;
  331.             }
  332.             else if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
  333.                 ant1.setImage('l');
  334.                 ant1.move({ -moveSpeed, 0 });
  335.                 goingLeft = true;
  336.             }
  337.             else if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
  338.                 ant1.setImage('r');
  339.                 ant1.move({ moveSpeed, 0 });
  340.                 goingRight = true;
  341.             }
  342.             else if (sf::Keyboard::isKeyPressed(sf::Keyboard::F3)) {
  343.                 coordsShowing = true;
  344.             }
  345.             else if (sf::Keyboard::isKeyPressed(sf::Keyboard::F4)) {
  346.                 coordsShowing = false;
  347.             }
  348.         }
  349.  
  350.         //Grasshopper Movement:
  351.         if (insectID == grasshopper) {
  352.             ssX.str("");
  353.             ssX << "X Position: " << grass1.getX();
  354.             xCoord.setString(ssX.str());
  355.  
  356.             ssY.str("");
  357.             ssY << "Y Position: " << grass1.getY();
  358.             yCoord.setString(ssY.str());
  359.  
  360.             if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
  361.                 if (goingLeft == true) {
  362.                     grass1.move({ -jumpSpeed, -jumpSpeed });
  363.                 }
  364.                 else if (goingRight == true) {
  365.                     grass1.move({ jumpSpeed, -jumpSpeed });
  366.                 }
  367.                 else {
  368.                     grass1.move({ 0, -jumpSpeed });
  369.                 }
  370.                 isJumping = true;
  371.             }
  372.             else if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
  373.                 grass1.setImage('l');
  374.                 grass1.move({ -moveSpeed, 0 });
  375.                 goingLeft = true;
  376.             }
  377.             else if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
  378.                 grass1.setImage('r');
  379.                 grass1.move({ moveSpeed, 0 });
  380.                 goingRight = true;
  381.             }
  382.             else if (sf::Keyboard::isKeyPressed(sf::Keyboard::F3)) {
  383.                 coordsShowing = true;
  384.             }
  385.             else if (sf::Keyboard::isKeyPressed(sf::Keyboard::F4)) {
  386.                 coordsShowing = false;
  387.             }
  388.         }
  389.  
  390.         //Event Loop:
  391.         while (window.pollEvent(Event)) {
  392.             switch (Event.type) {
  393.  
  394.             case sf::Event::Closed:
  395.                 window.close();
  396.  
  397.             case sf::Event::KeyPressed:
  398.                 if (Event.key.code == sf::Keyboard::Escape) {
  399.                     windowState = MAIN_MENU;
  400.                     window.setView(noView);
  401.                     goto main_menu;
  402.                 }
  403.  
  404.             case sf::Event::KeyReleased:
  405.                 if (Event.key.code == sf::Keyboard::W) {
  406.                     isJumping = false;
  407.                 }
  408.                 else if (Event.key.code == sf::Keyboard::A) {
  409.                     goingLeft = false;
  410.                 }
  411.                 else if (Event.key.code == sf::Keyboard::D) {
  412.                     goingRight = false;
  413.                 }
  414.             }
  415.         }
  416.  
  417.         //Gravity Logic:
  418.         if (insectID == caterpillar || insectID == none) {
  419.             if (cater1.getY() < groundHeight && isJumping == false) {
  420.                 cater1.fall(fallSpeed);
  421.             }
  422.  
  423.             if (cater1.getX() + 10 > window.getSize().x / 2) {
  424.                 position.x = cater1.getX() + 10;
  425.             }
  426.             else {
  427.                 position.x = window.getSize().x / 2;
  428.             }
  429.         }
  430.         if (insectID == ant) {
  431.             if (ant1.getY() < groundHeight && isJumping == false) {
  432.                 ant1.fall(fallSpeed);
  433.             }
  434.  
  435.             if (ant1.getX() > window.getSize().x / 2) {
  436.                 position.x = ant1.getX();
  437.             }
  438.             else {
  439.                 position.x = window.getSize().x / 2;
  440.             }
  441.         }
  442.         if (insectID == grasshopper) {
  443.             if (grass1.getY() < groundHeight && isJumping == false) {
  444.                 grass1.fall(fallSpeed);
  445.             }
  446.  
  447.             if (grass1.getX() > window.getSize().x / 2) {
  448.                 position.x = grass1.getX();
  449.             }
  450.             else {
  451.                 position.x = window.getSize().x / 2;
  452.             }
  453.         }
  454.  
  455.         //Cater Coords Logic:
  456.         if (coordsShowing == true && insectID == caterpillar) {
  457.             xCoord.setPosition({ cater1.getX() + 100, cater1.getY() - 700 });
  458.             yCoord.setPosition({ cater1.getX() + 100, cater1.getY() - 750 });
  459.         }
  460.         else if(coordsShowing == false && insectID == caterpillar){
  461.             xCoord.setPosition({ 543545, 543543 });
  462.             yCoord.setPosition({ 345435, 54453 });
  463.         }
  464.  
  465.         if (coordsShowing == true && insectID == none) {
  466.             xCoord.setPosition({ cater1.getX() + 100, cater1.getY() - 700 });
  467.             yCoord.setPosition({ cater1.getX() + 100, cater1.getY() - 750 });
  468.         }
  469.         else if (coordsShowing == false && insectID == none) {
  470.             xCoord.setPosition({ 543545, 543543 });
  471.             yCoord.setPosition({ 345435, 54453 });
  472.         }
  473.  
  474.         //Ant Coords Logic:
  475.         if (coordsShowing == true && insectID == ant) {
  476.             xCoord.setPosition({ ant1.getX() + 100, ant1.getY() - 700 });
  477.             yCoord.setPosition({ ant1.getX() + 100, ant1.getY() - 750 });
  478.         }
  479.         else if (coordsShowing == false && insectID == ant) {
  480.             xCoord.setPosition({ 543545, 543543 });
  481.             yCoord.setPosition({ 345435, 54453 });
  482.         }
  483.  
  484.         //Grasshopper Coords Logic:
  485.         if (coordsShowing == true && insectID == grasshopper) {
  486.             xCoord.setPosition({ grass1.getX() + 100, grass1.getY() - 700 });
  487.             yCoord.setPosition({ grass1.getX() + 100, grass1.getY() - 750 });
  488.         }
  489.         else if (coordsShowing == false && insectID == grasshopper) {
  490.             xCoord.setPosition({ 543545, 543543 });
  491.             yCoord.setPosition({ 345435, 54453 });
  492.         }
  493.  
  494.         //Caterpillar Waypoint Logic:
  495.         if (insectID == caterpillar || insectID == none) {
  496.             if (point1.isCollidingWith(&cater1)) {
  497.                 if (scorpShown == false) {
  498.                     for (int i = 0; i < scorpVec.size(); i++) {
  499.                         scorpVec[i]->setPos({ cater1.getX() + 600 + (i * 38), cater1.getY() - 15 - (i * 38) });
  500.                     }
  501.                     scorpShown = true;
  502.                 }
  503.             }
  504.             if (scorpShown == true) {
  505.                 for (int i = 0; i < scorpVec.size(); i++) {
  506.                     scorpVec[i]->move({ -scorpSpeed, 0 });
  507.                 }
  508.             }
  509.         }
  510.  
  511.         //Ant Waypoint Logic:
  512.         if (insectID == ant) {
  513.             if (point1.isCollidingWith(&ant1)) {
  514.                 if (scorpShown == false) {
  515.                     for (int i = 0; i < scorpVec.size(); i++) {
  516.                         scorpVec[i]->setPos({ ant1.getX() + 600 + (i * 38), ant1.getY() - 15 - (i * 35) });
  517.                     }
  518.                     scorpShown = true;
  519.                 }
  520.             }
  521.             if (scorpShown == true) {
  522.                 for (int i = 0; i < scorpVec.size(); i++) {
  523.                     scorpVec[i]->move({ -scorpSpeed, 0 });
  524.                 }
  525.             }
  526.         }
  527.  
  528.         //Grasshopper Waypoint Logic:
  529.         if (insectID == grasshopper) {
  530.             if (point1.isCollidingWith(&grass1)) {
  531.                 if (scorpShown == false) {
  532.                     for (int i = 0; i < scorpVec.size(); i++) {
  533.                         scorpVec[i]->setPos({ grass1.getX() + 600 + (i * 38), grass1.getY() - 15 - (i * 35) });
  534.                     }
  535.                     scorpShown = true;
  536.                 }
  537.             }
  538.             if (scorpShown == true) {
  539.                 for (int i = 0; i < scorpVec.size(); i++) {
  540.                     scorpVec[i]->move({ -scorpSpeed, 0 });
  541.                 }
  542.             }
  543.         }
  544.  
  545.         followPlayer.setCenter(position);
  546.         window.clear(sf::Color(0, 128, 255));
  547.  
  548.         //Draw Coords:
  549.         window.draw(xCoord);
  550.         window.draw(yCoord);
  551.  
  552.         //Draw Decors:
  553.         window.draw(grassWallpaper);
  554.         window.draw(grassWallpaper2);
  555.         window.draw(sunWallpaper);
  556.  
  557.         //Draw Waypoints:
  558.         point1.drawTo(&window);
  559.  
  560.         //Draw Player Models:
  561.         cater1.drawTo(&window);
  562.         ant1.drawTo(&window);
  563.         grass1.drawTo(&window);
  564.  
  565.         //Scorpions:
  566.         scorp1.drawTo(&window);
  567.         scorp2.drawTo(&window);
  568.         scorp3.drawTo(&window);
  569.         scorp4.drawTo(&window);
  570.        
  571.         //Window Stuff:
  572.         window.setView(followPlayer);
  573.         window.display();
  574.     }
  575.  
  576.  
  577.     /* WINDOW STATE 10: CHOOSE INSECT" */
  578.  
  579.     //lblChoose Attributes:
  580.     sf::Text lblChoose;
  581.     lblChoose.setCharacterSize(90);
  582.     lblChoose.setColor(sf::Color::Black);
  583.     lblChoose.setString("Choose Insect:");
  584.     lblChoose.setFont(impact);
  585.     lblChoose.setPosition({ 170, 10 });
  586.  
  587.     //Arrows:
  588.     Arrow arrowRight('r');
  589.     arrowRight.setPos({ 650, 350 });
  590.  
  591.     //Images:
  592.     int currentInsect = 1;
  593.  
  594.     InsectImage caterpillarImage("caterpillar.png");
  595.     InsectImage antImage("ant.png");
  596.     InsectImage grasshopperImage("grasshopperImage.png");
  597.     caterpillarImage.setPos({ 310, 400 });
  598.     antImage.erase();
  599.     grasshopperImage.erase();
  600.  
  601.     //Buttons and Labels:
  602.     sf::Text lblInsect;
  603.     lblInsect.setCharacterSize(60);
  604.     lblInsect.setFont(impact);
  605.     lblInsect.setColor(sf::Color::Black);
  606.     lblInsect.setString("Caterpillar:");
  607.     lblInsect.setPosition({ -10, 440 });
  608.  
  609.     sf::Text lblSelect;
  610.     lblSelect.setCharacterSize(50);
  611.     lblSelect.setFont(impact);
  612.     lblSelect.setColor(sf::Color::Black);
  613.     lblSelect.setString("Select");
  614.     lblSelect.setPosition({ 385, 720 });
  615.  
  616.     Button btnSelect({ 280, 100 });
  617.     btnSelect.setColor(sf::Color::Green);
  618.     btnSelect.setPos({ 310, 700 });
  619.  
  620.     //Main Loop:
  621.     while (window.isOpen() && windowState == CHOOSE_INSECT) {
  622.  
  623.         sf::Event Event;
  624.  
  625.         int mousePosX = sf::Mouse::getPosition().x - 520;
  626.         int mousePosY = sf::Mouse::getPosition().y - 89;
  627.  
  628.         //Event Loop:
  629.         while (window.pollEvent(Event)) {
  630.             switch (Event.type) {
  631.  
  632.             case sf::Event::Closed:
  633.                 window.close();
  634.  
  635.             case sf::Event::MouseButtonPressed:
  636.                 if (arrowRight.isMouseOver(mousePosX, mousePosY)) {
  637.                     if (currentInsect == 0) {
  638.                         caterpillarImage.setPos({ 310, 400 });
  639.                         antImage.erase();
  640.                         grasshopperImage.erase();
  641.                         lblInsect.setString("Caterpillar:");
  642.                         currentInsect++;
  643.                     }
  644.                     else if (currentInsect == 1) {
  645.                         antImage.setPos({ 320, 390 });
  646.                         caterpillarImage.erase();
  647.                         grasshopperImage.erase();
  648.                         lblInsect.setString("Ant:");
  649.                         currentInsect++;
  650.                     }
  651.                     else if (currentInsect == 2) {
  652.                         grasshopperImage.setPos({ 320, 390 });
  653.                         caterpillarImage.erase();
  654.                         antImage.erase();
  655.                         lblInsect.setString("Grasshopper:");
  656.                         currentInsect = 0;
  657.                     }
  658.                 }
  659.  
  660.                 if (btnSelect.isMouseOver(mousePosX, mousePosY)) {
  661.                     if (currentInsect == 1) {
  662.                         insectID = caterpillar;
  663.                         std::cout << currentInsect;
  664.                         std::cout << "Cater\n";
  665.                     }
  666.                     else if (currentInsect == 2) {
  667.                         insectID = ant;
  668.                         std::cout << "Ant\n";
  669.                     }
  670.                     else if (currentInsect == 0) {
  671.                         insectID = grasshopper;
  672.                         std::cout << "Grasshopper\n";
  673.                     }
  674.                     windowState = MAIN_MENU;
  675.                     goto main_menu;
  676.                 }
  677.  
  678.             case sf::Event::MouseMoved:
  679.                 if (arrowRight.isMouseOver(mousePosX, mousePosY)) {
  680.                     arrowRight.darken();
  681.                 }
  682.                 else {
  683.                     arrowRight.lighten();
  684.                 }
  685.  
  686.                 if (btnSelect.isMouseOver(mousePosX, mousePosY)) {
  687.                     btnSelect.setColor(sf::Color(16, 133, 52));
  688.                 }
  689.                 else {
  690.                     btnSelect.setColor(sf::Color::Green);
  691.                 }
  692.             }
  693.         }
  694.  
  695.         window.clear(sf::Color::Magenta);
  696.  
  697.         window.draw(lblChoose);
  698.  
  699.         caterpillarImage.drawTo(&window);
  700.         antImage.drawTo(&window);
  701.         grasshopperImage.drawTo(&window);
  702.  
  703.         arrowRight.drawTo(&window);
  704.         btnSelect.drawTo(&window);
  705.         window.draw(lblInsect);
  706.         window.draw(lblSelect);
  707.  
  708.         window.setView(noView);
  709.         window.display();
  710.     }
  711. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement