Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Ship.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 "AlienProjectile.h"
- using namespace sf;
- static Music shipDead;
- Ship::Ship(){
- shipDead.openFromFile(resourcePath() + "explosion.ogg");
- shipTexture.loadFromFile(resourcePath() + "Ship.png");
- ship.setTexture(shipTexture);
- pos.x = 365;
- pos.y = 550;
- ship.setPosition(pos.x, pos.y);
- }
- void Ship::draw(RenderWindow &window){
- window.draw(ship);
- ship.setPosition(pos.x, pos.y);
- }
- void Ship::moveLeft(){
- if(pos.x > 4){
- pos.x -= 7.5f;
- }
- }
- void Ship::moveRight(){
- if(pos.x < 740){
- pos.x += 7.5f;
- }
- }
- void Ship::checkCollision(AlienProjectile &alienProj, int &lives){
- if(alienProj.pos.y < pos.y + 32 && alienProj.pos.y > 0 && alienProj.pos.x > pos.x && alienProj.pos.x < pos.x + 60){
- shipDead.play();
- lives--;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement