SHARE
TWEET

Untitled

a guest Nov 14th, 2017 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "Bullet.hpp"
  2. #include "TextureManager.hpp"
  3.  
  4.  
  5.  
  6. Bullet::Bullet(const char* texturesheet, int x, int y, int h, int w) {
  7.  
  8.     objTexture = TextureManager::LoadTexture(texturesheet);
  9.  
  10.     xpos = x;
  11.     ypos = y;
  12.     textureHeight = h;
  13.     textureWidth = w;
  14.     frameHeight = 0;
  15.     frameWidth = 0;
  16.     velocity = 0;
  17.  
  18.     SDL_QueryTexture(objTexture, NULL, NULL, &textureWidth, &textureHeight);
  19. }
  20.  
  21. void Bullet::Update() {
  22.  
  23.     frameWidth = textureWidth / 2;
  24.     frameHeight = textureHeight / 3;
  25.  
  26.     playerRect.h = frameHeight;
  27.     playerRect.w = frameWidth;
  28.     playerRect.x = 0; // controlar a animaƧao
  29.     playerRect.y = 0;
  30.  
  31.  
  32.     destRect.h = playerRect.h;
  33.     destRect.w = playerRect.w;
  34.     destRect.x = xpos;
  35.     destRect.y = ypos;
  36.  
  37.     setVelocity(1);
  38.     moveBullet();
  39.     if (ypos <= 0) {
  40.         destroy();
  41.     }
  42. }
  43.  
  44. void Bullet::Render() {
  45.  
  46.     SDL_RenderCopy(Game::renderer, objTexture, &playerRect, &destRect);
  47. }
  48.  
  49. void Bullet::setVelocity(int v) {
  50.     velocity = v;
  51. }
  52. int Bullet::getVelocity() {
  53.     return velocity;
  54. }
  55. void Bullet::moveBullet() {
  56.     ypos -= velocity;
  57.  
  58. }
  59. void Bullet::destroy() {
  60.     SDL_DestroyTexture(objTexture);
  61. }
RAW Paste Data
Top