Guest User

Untitled

a guest
Aug 13th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.81 KB | None | 0 0
  1. #include "SFML/Graphics.hpp"
  2. #include "SFML/Audio.hpp"
  3. #include "SFML/Window.hpp"
  4. #include "SFML/System.hpp"
  5.  
  6. #include <iostream>
  7. #define _USE_MATH_DEFINES
  8. #include <math.h>
  9.  
  10. #include "Character.h"
  11. #include "UI.h"
  12.  
  13. using namespace std;
  14. using namespace sf;
  15.  
  16. void main()
  17. {
  18. //references
  19.     Event event;
  20.     UI ui;
  21.     Character character;
  22. //vector of shurikens
  23.     vector<Shuriken> shuriken;
  24.  
  25.     Shuriken shurik;
  26.    
  27.  
  28.     sf::RenderWindow window(VideoMode(ui.qualityX, ui.qualityY), "Game");
  29.  
  30.     sf::Texture cursorTexture;
  31.  
  32.     cursorTexture.loadFromFile("cursor.png");
  33.  
  34.     sf::Sprite cursor(cursorTexture);
  35.  
  36.     cursor.setScale(0.15, 0.15); cursor.setOrigin(cursorTexture.getSize().x / 2, cursorTexture.getSize().y / 2);
  37.  
  38.     window.setMouseCursorVisible(false);
  39.  
  40.     while (window.isOpen())
  41.     {
  42.         while (window.pollEvent(event))
  43.         {
  44.             if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
  45.                 window.close();
  46.         }
  47.         double dx = window.mapPixelToCoords(sf::Mouse::getPosition(window)).x - character.spriteCharacter.getPosition().x;
  48.        
  49.         double dy = window.mapPixelToCoords(sf::Mouse::getPosition(window)).y - character.spriteCharacter.getPosition().y;
  50.  
  51.         double angle = atan2(dx, dy) * 180 / M_PI;
  52.  
  53.         character.move(); character.cameraLookPose(window); character.look(angle);
  54.  
  55.         cursor.setPosition(window.mapPixelToCoords(sf::Mouse::getPosition(window)));
  56.  
  57.         shuriken.resize(character.shurikenIndex + 1);
  58.  
  59.         if (Mouse::isButtonPressed(Mouse::Left))
  60.         {
  61.             shuriken.push_back(Shuriken(shurik));
  62.             character.shurikenIndex++;
  63.         }
  64.  
  65.         window.clear();
  66.  
  67.         if (character.shurikenIndex < shuriken.size())
  68.         {
  69.             window.draw(shuriken[character.shurikenIndex].shurikenSprite);
  70.         }
  71.        
  72.         window.draw(character.spriteCharacter);
  73.  
  74.         window.draw(cursor);
  75.  
  76.         window.setView(character.view);
  77.          
  78.         window.display();
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment