Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. //Player class
  2. Player::Player(float x, float y, sf::Texture* texture)
  3. {
  4. //ctor
  5. this->initVariables();
  6. this->initComponents();
  7. this->createSprite(texture);
  8. this->setPosition(x, y);
  9. }
  10.  
  11. Player::~Player()
  12. {
  13. //dtor
  14. }
  15. void Player::initComponents()
  16. {
  17.  
  18. }
  19. void Player::initVariables()
  20. {
  21.  
  22. }
  23.  
  24.  
  25. ======================================================
  26. //Entity class -- the sprite is created here and so the movement function.
  27. #include "Entity.h"
  28. Entity::Entity()
  29. {
  30. //ctor
  31. void initVariables();
  32. //void createSprite();
  33.  
  34. }
  35.  
  36. Entity::~Entity()
  37. {
  38. //dtor
  39. delete this->sprite;
  40.  
  41. }
  42.  
  43. void Entity::initVariables()
  44. {
  45. this->sprite = NULL;
  46. this->movementSpeed = 100.f;
  47. }
  48. void Entity::createSprite(sf::Texture* texture)
  49. {
  50. this->texture = texture;
  51. this->sprite = new sf::Sprite(*this->texture);
  52. }
  53.  
  54. void Entity::setPosition(const float x, const float y)
  55. {
  56. if(this->sprite)
  57. {
  58. this->sprite->setPosition(x, y);
  59. }
  60. }
  61. void Entity::update(const float& dt)
  62. {
  63.  
  64. }
  65. void Entity::render(sf::RenderTarget * target)
  66. {
  67. target->draw(*this->sprite);
  68. }
  69.  
  70. void Entity::movement(const float& dt, const float dir_x, const float dir_y)
  71. {
  72. this->sprite->move(dir_x * this->movementSpeed *dt, dir_y * this->movementSpeed*dt);
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement