Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Projectile.cpp
- // Space Invaders
- //
- // Created by Marcuz on 25/02/13.
- // Copyright (c) 2013 Marcuz Stolte. All rights reserved.
- //
- #include <SFML/Graphics.hpp>
- #include <SFML/Audio.hpp>
- #include "ResourcePath.hpp"
- #include "Ship.h"
- #include "Projectile.h"
- using namespace sf;
- static Music shoot;
- Projectile::Projectile(){
- projectileTexture.loadFromFile(resourcePath() + "Projectile.png");
- shoot.openFromFile(resourcePath() + "Shoot.aif");
- projectile.setTexture(projectileTexture);
- pos.x = 0, pos.y = 0;
- projectile.setPosition(pos.x, pos.y);
- isFired = false;
- }
- void Projectile::fire(Ship &ship){
- pos.x = ship.pos.x + 28;
- pos.y = ship.pos.y - 7;
- isFired = true;
- shoot.play();
- }
- void Projectile::draw(RenderWindow &window){
- if(isFired && pos.y > 0){
- pos.y -= 7;
- projectile.setPosition(pos.x, pos.y);
- window.draw(projectile);
- }else{isFired = false;}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement