Advertisement
Guest User

efaefefaefaefaef

a guest
Apr 27th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. // GameDevLab1.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <SFML/Graphics.hpp>
  6.  
  7. int main()
  8. {
  9. sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
  10. sf::CircleShape shape(100.f);
  11. shape.setFillColor(sf::Color::Green);
  12.  
  13. /*//make rectangle
  14. sf::RectangleShape rectangle(sf::Vector2f(128.0f, 128.0f));
  15. rectangle.setFillColor(sf::Color::Red);
  16. rectangle.setPosition(320, 240);*/
  17.  
  18. sf::Texture mushroomTexture;
  19. mushroomTexture.loadFromFile("Mushroom.png");
  20. sf::Sprite mushroom(mushroomTexture);
  21. sf::Vector2u size = mushroomTexture.getSize();
  22. mushroom.setOrigin(size.x / 2.0f, size.y / 2.0f);
  23. sf::Vector2f increment(0.4f, 0.4f);
  24.  
  25.  
  26. /*
  27. //error checking for texture, returns boolean
  28. sf::Texture texture;
  29. if (!texture.loadFromFile("filename.png")) {
  30.  
  31. }*/
  32.  
  33. while (window.isOpen())
  34. {
  35. //load textures
  36. sf::Texture texture;
  37. texture.loadFromFile("Mushroom.png");
  38.  
  39. sf::Sprite sprite(texture); //give the sprite the apperance of the texture
  40.  
  41.  
  42.  
  43. sf::Event event;
  44. while (window.pollEvent(event))
  45. {
  46. if (event.type == sf::Event::Closed)
  47. window.close();
  48. }
  49.  
  50. if((mushroom.getPosition().x + (size.x /2) > window.getSize().x && increment.x > 0)
  51. || (mushroom.getPosition().x - (size.x / 2) < 0 && increment.x < 0)) {
  52. increment.x = increment.x; //reverse direction on x axis
  53. }
  54. if ((mushroom.getPosition().y + (size.y / 2) > window.getSize().y && increment.y > 0)
  55. || (mushroom.getPosition().y - (size.x / 2) < 0 && increment.y < 0)) {
  56. increment.y = increment.y; //reverse direction on y axis
  57. }
  58. mushroom.setPosition(mushroom.getPosition() + increment);
  59. window.clear(sf::Color(16, 16, 16, 255));
  60.  
  61. window.draw(mushroom);
  62.  
  63.  
  64.  
  65.  
  66. //set position of rectangle
  67. //rectangle.setOrigin(rectangle.getSize().x / 2, rectangle.getSize().y / 2);
  68.  
  69. //clear screen
  70. window.clear();
  71.  
  72. //draw objects
  73. window.draw(shape); //drawing order, shape first, sprite last
  74. //window.draw(rectangle);
  75. window.draw(sprite);
  76.  
  77. window.display();
  78. }
  79.  
  80. return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement