Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Bullet.hpp"
- #include "TextureManager.hpp"
- Bullet::Bullet(const char* texturesheet, int x, int y, int h, int w) {
- objTexture = TextureManager::LoadTexture(texturesheet);
- xpos = x;
- ypos = y;
- textureHeight = h;
- textureWidth = w;
- frameHeight = 0;
- frameWidth = 0;
- velocity = 0;
- SDL_QueryTexture(objTexture, NULL, NULL, &textureWidth, &textureHeight);
- }
- void Bullet::Update() {
- frameWidth = textureWidth / 2;
- frameHeight = textureHeight / 3;
- playerRect.h = frameHeight;
- playerRect.w = frameWidth;
- playerRect.x = 0; // controlar a animaçao
- playerRect.y = 0;
- destRect.h = playerRect.h;
- destRect.w = playerRect.w;
- destRect.x = xpos;
- destRect.y = ypos;
- setVelocity(1);
- moveBullet();
- if (ypos <= 0) {
- destroy();
- }
- }
- void Bullet::Render() {
- SDL_RenderCopy(Game::renderer, objTexture, &playerRect, &destRect);
- }
- void Bullet::setVelocity(int v) {
- velocity = v;
- }
- int Bullet::getVelocity() {
- return velocity;
- }
- void Bullet::moveBullet() {
- ypos -= velocity;
- }
- void Bullet::destroy() {
- SDL_DestroyTexture(objTexture);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement