Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 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.  
  23. vector<Shuriken> shuriken;
  24.  
  25. sf::RenderWindow window(VideoMode(ui.qualityX, ui.qualityY), "Game");
  26.  
  27. sf::Texture cursorTexture;
  28.  
  29. cursorTexture.loadFromFile("cursor.png");
  30.  
  31. sf::Sprite cursor(cursorTexture);
  32.  
  33. cursor.setScale(0.15, 0.15); cursor.setOrigin(cursorTexture.getSize().x / 2, cursorTexture.getSize().y / 2);
  34.  
  35. window.setMouseCursorVisible(false);
  36.  
  37. while (window.isOpen())
  38. {
  39. while (window.pollEvent(event))
  40. {
  41. if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
  42. window.close();
  43. }
  44. double dx = window.mapPixelToCoords(sf::Mouse::getPosition(window)).x - character.spriteCharacter.getPosition().x;
  45.  
  46. double dy = window.mapPixelToCoords(sf::Mouse::getPosition(window)).y - character.spriteCharacter.getPosition().y;
  47.  
  48. double angle = atan2(dx, dy) * 180 / M_PI;
  49.  
  50. character.move(); character.cameraLookPose(window); character.look(angle); character.attack();
  51.  
  52. cursor.setPosition(window.mapPixelToCoords(sf::Mouse::getPosition(window)));
  53.  
  54. shuriken.resize(character.shurikenIndex+1);
  55.  
  56. for (Shuriken& shuriken_VALUE : shuriken)
  57. {
  58. shuriken_VALUE.forward();
  59. window.draw(shuriken_VALUE.shurikenSprite);
  60. }
  61.  
  62. window.draw(character.spriteCharacter);
  63.  
  64. window.draw(cursor);
  65.  
  66. window.setView(character.view);
  67.  
  68. window.display();
  69.  
  70. window.clear();
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement