Guest User

Liloz damn character

a guest
Oct 26th, 2019
21
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. namespace Liloz
  2. {
  3. struct low
  4. {
  5.     sf::Sprite sprite; //End
  6.     PlayerEntity* liloz;
  7.  
  8.     void setPosition()
  9.     {
  10.         bool isLeft = RNG::getNumber(2);
  11.  
  12.         if(isLeft)
  13.         {
  14.             sprite.setPosition(-1 * RNG::getNumber(1250),-1 * RNG::getNumber(1000));
  15.             liloz->isNegativeLeft = true;
  16.             liloz->isNegativeRight = false;
  17.         }
  18.         else {
  19.             sprite.setPosition(RNG::getNumber(1250),RNG::getNumber(1000));
  20.             liloz->isNegativeLeft = false;
  21.             liloz->isNegativeRight = true;
  22.         }
  23.     }
  24.  
  25.     low(PlayerEntity* liloz)
  26.         :sprite(spriteSheet), liloz(liloz)
  27.     {
  28.         sprite.setTextureRect(sf::IntRect(100,431,80,69));
  29.         sprite.setScale(0.9f,0.9f);
  30.  
  31.         setPosition();
  32.         liloz->weapon->target = &sprite;
  33.     }
  34. };
  35.  
  36. struct CustomWeapon : public WeaponEntity
  37. {
  38.     bool forceJump = false;
  39.     bool slowdown = false;
  40.     bool forceLeft = false;
  41.     bool forceRight = false;
  42.  
  43.     PlayerEntity* player;
  44.  
  45.     unsigned short powerCounter = 1800;
  46.     unsigned short affectCounter = 350;
  47.  
  48.     void resetAffects()
  49.     {
  50.         forceJump = false; slowdown = false;
  51.         forceLeft = false; forceRight = false;
  52.     }
  53.  
  54.     void setAffect()
  55.     {
  56.         unsigned short affect = RNG::getNumber(4);
  57.  
  58.         if(affect == 3 && powerCounter > 1200)
  59.             forceLeft = true;
  60.         else if(affect == 2 && powerCounter > 1200)
  61.             forceRight = true;
  62.         else if(affect >= 1 && powerCounter > 600)
  63.             slowdown = true;
  64.         else forceJump = true;
  65.     }
  66.  
  67.     CustomWeapon(PlayerEntity* liloz)
  68.         :WeaponEntity(P90_UPGRADED,1,liloz), player(characterObjects.at(0))
  69.     {
  70.         setAffect();
  71.     }
  72.  
  73.     void PrimaryFire() override
  74.     {
  75.         if(--affectCounter == 0)
  76.         {
  77.             resetAffects();
  78.             setAffect();
  79.             affectCounter = 350;
  80.         }
  81.  
  82.         if(slowdown)
  83.             player->movespd = SLOW_X;
  84.         else
  85.             player->movespd = NORMAL_X;
  86.  
  87.         if(forceLeft)
  88.             player->x_movement -= 2;
  89.         else if(forceRight)
  90.             player->x_movement += 2;
  91.  
  92.         if(forceJump && player->fallCounter == 0 && player->jumpFrames == 0)
  93.             player->jumpFrames = 12;
  94.     }
  95. };
  96.  
  97. class top : public PlayerEntity
  98. {
  99.     sf::Sprite sprite;
  100.     CustomWeapon thisWeapon;
  101.     low* thisLow;
  102.  
  103. public:
  104.  
  105.     top()
  106.         :PlayerEntity(PlayerStatus(250),BOT,sprite,MODERATE_X,NORMAL_JUMP), sprite(spriteSheet), thisWeapon(this)
  107.     {
  108.         setTextureRect();
  109.         setAttackingRange();
  110.         weapon = new melee::Soft(this);
  111.         thisLow = new low(this);
  112.     }
  113.  
  114.     void forceProcess() override
  115.     {
  116.         if(thisWeapon.powerCounter == 0)
  117.         {
  118.             player.setHealthTo(0);
  119.             *enemyCounter -= 1;
  120.             delete thisLow;
  121.         }
  122.         thisWeapon.powerCounter--;
  123.     }
  124.  
  125.     void setTextureRect() override
  126.     {
  127.         sprite.setTextureRect(INT_RECT(7,2));
  128.     }
  129.  
  130.     void setAttackingRange() override
  131.     {
  132.         attackRange.setPosition(
  133.             sprite.getPosition().x - attackRange.getTextureRect().width / 2,
  134.             sprite.getPosition().y - attackRange.getTextureRect().height/ 2);
  135.  
  136.         attackRange.setTextureRect(sf::IntRect(
  137.             0,0,2 * thisWeapon.powerCounter, 2 * thisWeapon.powerCounter));
  138.     }
  139.  
  140.     bool checkAttacking() override
  141.     {
  142.         setAttackingRange();
  143.         if(attackRange.getGlobalBounds().contains(weapon->target->getPosition()))
  144.             thisWeapon.PrimaryFire();
  145.         if(attackRange.getGlobalBounds().intersects(weapon->target->getGlobalBounds()))
  146.             thisWeapon.PrimaryFire();
  147.  
  148.         return false;
  149.     }
  150.  
  151.     XyMove getInput() override
  152.     {
  153.         if(abs(thisLow->sprite.getPosition().x - sprite.getPosition().x) <= 10)
  154.         {
  155.             thisLow->sprite.move(0,
  156.                 thisLow->sprite.getPosition().y < sprite.getPosition().y ? 3 : -3);
  157.         }
  158.  
  159.         if(thisWeapon->powerCounter <= 600)
  160.         {
  161.             isNegativeLeft = isNegativeRight;
  162.             isNegativeRight = isNegativeRight ? false : true;
  163.         }
  164.  
  165.         if(thisLow->sprite.getGlobalBounds().intersects(sprite.getGlobalBounds()))
  166.         {
  167.             thisLow->setPosition();
  168.             thisWeapon.powerCounter = 1800;
  169.         }
  170.  
  171.         app.draw(thisLow->sprite);
  172.  
  173.         return moveScript;
  174.     }
  175.  
  176. };
  177. }
RAW Paste Data