Advertisement
Guest User

Projectile.cpp

a guest
Mar 4th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. //
  2. //  Projectile.cpp
  3. //  Space Invaders
  4. //
  5. //  Created by Marcuz on 25/02/13.
  6. //  Copyright (c) 2013 Marcuz Stolte. All rights reserved.
  7. //
  8.  
  9. #include <SFML/Graphics.hpp>
  10. #include <SFML/Audio.hpp>
  11. #include "ResourcePath.hpp"
  12. #include "Ship.h"
  13. #include "Projectile.h"
  14.  
  15. using namespace sf;
  16.  
  17. static Music shoot;
  18.  
  19. Projectile::Projectile(){
  20.     projectileTexture.loadFromFile(resourcePath() + "Projectile.png");
  21.     shoot.openFromFile(resourcePath() + "Shoot.aif");
  22.     projectile.setTexture(projectileTexture);
  23.     pos.x = 0, pos.y = 0;
  24.     projectile.setPosition(pos.x, pos.y);
  25.     isFired = false;
  26. }
  27.  
  28. void Projectile::fire(Ship &ship){
  29.     pos.x = ship.pos.x + 28;
  30.     pos.y = ship.pos.y - 7;
  31.     isFired = true;
  32.     shoot.play();
  33. }
  34.  
  35. void Projectile::draw(RenderWindow &window){
  36.     if(isFired && pos.y > 0){
  37.         pos.y -= 7;
  38.         projectile.setPosition(pos.x, pos.y);
  39.         window.draw(projectile);
  40.     }else{isFired = false;}
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement