Advertisement
Guest User

Ship.cpp

a guest
Mar 4th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. //
  2. //  Ship.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 "AlienProjectile.h"
  14.  
  15. using namespace sf;
  16.  
  17. static Music shipDead;
  18.  
  19. Ship::Ship(){
  20.     shipDead.openFromFile(resourcePath() + "explosion.ogg");
  21.     shipTexture.loadFromFile(resourcePath() + "Ship.png");
  22.     ship.setTexture(shipTexture);
  23.     pos.x = 365;
  24.     pos.y = 550;
  25.     ship.setPosition(pos.x, pos.y);
  26. }
  27.  
  28. void Ship::draw(RenderWindow &window){
  29.     window.draw(ship);
  30.     ship.setPosition(pos.x, pos.y);
  31. }
  32.  
  33. void Ship::moveLeft(){
  34.     if(pos.x > 4){
  35.         pos.x -= 7.5f;
  36.     }
  37. }
  38.  
  39. void Ship::moveRight(){
  40.     if(pos.x < 740){
  41.         pos.x += 7.5f;
  42.     }
  43. }
  44.  
  45. void Ship::checkCollision(AlienProjectile &alienProj, int &lives){
  46.     if(alienProj.pos.y < pos.y + 32 && alienProj.pos.y > 0 && alienProj.pos.x > pos.x && alienProj.pos.x < pos.x + 60){
  47.         shipDead.play();
  48.         lives--;
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement