Advertisement
venik2405

course.coin

Dec 20th, 2021
784
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. #include "Coin.h"
  2.  
  3. void Coin::initTextures()
  4. {
  5.     switch (type)
  6.     {
  7.     case 1:
  8.         if (!this->texture.loadFromFile("Textures/coin_2.png"))
  9.             std::cout << "Failed to load coin`s texture\n";
  10.         this->coin.setScale(0.25, 0.25);
  11.         break;
  12.     case 2:
  13.         if (!this->texture.loadFromFile("Textures/fire.png"))
  14.             std::cout << "Failed to load coin`s texture\n";
  15.         this->coin.setScale(0.15, 0.15);
  16.         break;
  17.     case 3:
  18.         if (!this->texture.loadFromFile("Textures/luzha3.png"))
  19.             std::cout << "Failed to load luzha`s texture\n";
  20.         this->coin.setScale(0.3f, 0.2f);
  21.         break;
  22.     }
  23.     this->coin.setTexture(this->texture);
  24. }
  25.  
  26. void Coin::initVariables(int sp, int y, int type)
  27. {
  28.     this->type = type;
  29.     this->y = y;
  30.     this->speed = sp - rand() % 7;
  31.     this->line = (y - 450) / 110;
  32.     if (speed < 10) speed = 70;
  33. }
  34.  
  35. void Coin::updatePos(int posY)
  36. {
  37.     this->coin.setPosition(this->coin.getPosition().x, posY);
  38. }
  39.  
  40. const int Coin::getType() const
  41. {
  42.     return this->type;
  43. }
  44.  
  45. const sf::FloatRect Coin::getBounds() const
  46. {
  47.     return this->coin.getGlobalBounds();
  48. }
  49.  
  50. const sf::Sprite Coin::getShape() const
  51. {
  52.     return this->coin;;
  53. }
  54.  
  55. Coin::Coin(float x, float y, int sp, int type)
  56. {
  57.     this->initVariables(sp, y, type);
  58.     this->initTextures();
  59.     this->coin.setPosition(x, y);
  60. }
  61.  
  62. Coin::Coin()
  63. {
  64. }
  65.  
  66. void Coin::update(int sp, int posY)
  67. {
  68.     this->coin.move(-(sp * 0.1f), 0.f);
  69.     this->updatePos(posY + 300 + y);
  70. }
  71.  
  72. void Coin::render(sf::RenderTarget* target)
  73. {
  74.     target->draw(this->coin);
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement