Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.62 KB | None | 0 0
  1. //********************************************* Klasa Mapy ********************************************************
  2. //------------------------------------- Draw Entity ------------------------------------------
  3. void GameplayScreen::DrawEntity(SDL_Renderer * renderer)
  4. {
  5.     for (int i = 0; i < vEntity.size(); i++)
  6.     {
  7.         for (int j = 0; j < vEntity[i].size(); j++)
  8.         {
  9.             vEntity[i][j]->Draw(renderer, vBlock[vEntity[i][j]->getBlockID()]->GetSprite()->getTexture());
  10.         }
  11.     }
  12. }
  13. //------------------------------------- Update Entity --------------------------------------------
  14. void GameplayScreen::UpdateEntity()
  15. {
  16.     for (int i = 0; i < vEntity.size(); i++)
  17.     {
  18.         for (int j = 0; j < vEntity[i].size(); j++)
  19.         {
  20.             vEntity[i][j]->Upadate();
  21.         }
  22.     }
  23.  
  24.     for (int i = 0; i < vEntity.size(); i++)
  25.     {
  26.         for (int j = 0; j < vEntity[i].size(); j++)
  27.         {
  28.             if (vEntity[i][j]->entityState == -1)
  29.             {
  30.                 delete vEntity[i][j];
  31.                 vEntity[i].erase(vEntity[i].begin() + j);
  32.                 continue;
  33.             }
  34.         }
  35.     }
  36. }
  37. //----------------------------------- Dodaje broΕ„ ---------------------------------------------------
  38. void GameplayScreen::addPlayerGun(int x, int y, int moveDirection)
  39. {
  40.     vEntity[4].push_back(new PlayerGun(x, y, moveDirection));
  41. }
  42.  
  43. //*************************************** Klasa broni ************************************************
  44.  
  45. PlayerGun::PlayerGun(int posX, int posY, int moveDirection)
  46. {
  47.     this->posX = posY;
  48.     this->posY = posY;
  49.     this->moveDirection = moveDirection;
  50.    
  51.     this->moveSpeed = 6;
  52.  
  53.     this->hitBoxX = 16;
  54.     this->hitBoxY = 16;
  55.  
  56.     this->blockID = 4;
  57. }
  58. void PlayerGun::Draw(SDL_Renderer * renderer, Texture* bulletTxt)
  59. {
  60.     SDL_Rect srcRect;
  61.  
  62.     srcRect.x = (int)posX + (int)System::getManager()->GetGame()->getPosX();
  63.     srcRect.y = (int)posY;
  64.     srcRect.w = hitBoxX;
  65.     srcRect.h = hitBoxY;
  66.  
  67.     bulletTxt->Draw(srcRect, renderer, !moveDirection);
  68. }
  69.  
  70. void PlayerGun::Upadate()
  71. {
  72.     UpdatePosX();
  73. }
  74.  
  75. void PlayerGun::UpdatePosX()
  76. {
  77.     if (moveDirection)
  78.     {
  79.         posX -= moveSpeed;
  80.     }
  81.     else
  82.     {
  83.         posX += moveSpeed;
  84.     }
  85. }
  86. //************************************************ Dodawanie Broni do Postaci ***************************************
  87. void Player::CreateBullet()
  88. {
  89.     if (playerGunState == 1)
  90.     {
  91.             System::getManager->GetGame()->addPlayerGun(posX - System::getManager->GetGame()->getPosX() + 32, posY + getHitBoxY() / 2, !moveDirection);
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement