Advertisement
erzis

Untitled

Dec 29th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include "Character.h"
  3. #include <iostream>
  4.  
  5. //Loading & setting character attributes
  6. Character::Character()
  7. {
  8. chTexture.loadFromFile("tiles/char.png");
  9. chSprite = sf::Sprite(chTexture);
  10. chSprite.setTextureRect(sf::IntRect(0, 0, 32, 32));
  11. chSprite.setPosition(300.0, 300.0);
  12. chSprite.setScale(2, 2);
  13. }
  14.  
  15. //Movement
  16. void Character::Move(int Direction, int animation)
  17. {
  18. std::cout << animation;
  19. sf::Vector2f offset;
  20. switch (Direction)
  21. {
  22. case 0:
  23. offset.x = 0;
  24. offset.y = 10;
  25. break;
  26. case 1:
  27. offset.x = -10;
  28. offset.y = 0;
  29. break;
  30. case 2:
  31. offset.x = 10;
  32. offset.y = 0;
  33. break;
  34. case 3:
  35. offset.x = 0;
  36. offset.y = -10;
  37. break;
  38. }
  39. chSprite.move(offset);
  40. chSprite.setTextureRect(sf::IntRect(animation * 32, Direction * 32, 32, 32));
  41. animation++;
  42.  
  43. if (animation >= 3)
  44. {
  45. animation = 0;
  46. }
  47. }
  48.  
  49. //Drawing character
  50. void Character::Draw(sf::RenderWindow &window)
  51. {
  52. window.draw(chSprite);
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement