Obracające się meteoryty, koniec gry przy natrafieniu na meteoryt. Poprawione sprajty statku, meteorytu i pocisku
44 lines
1.4 KiB
C++
44 lines
1.4 KiB
C++
#include <iostream>
|
|
#include "../headers/Meteor.h"
|
|
|
|
Meteor::Meteor(float x, float y, sf::Texture &texture) {
|
|
outOfBounds = false;
|
|
meteorTexture = texture;
|
|
meteorSprite.setTexture(texture);
|
|
meteorSprite.setOrigin(meteorSprite.getLocalBounds().width / 2, meteorSprite.getLocalBounds().height / 2); // wycentrowanie sprite
|
|
meteorSprite.setPosition(x, y);
|
|
meteorSpeed = 5.0f;
|
|
meteorSprite.scale(0.05f, 0.05f);
|
|
meteorPosition.x = x;
|
|
meteorPosition.y = y;
|
|
meteorRotationSpeed = static_cast<float>(rand() % 2 + 1) * (rand() % 2 == 0 ? 1 : -1);
|
|
}
|
|
|
|
sf::Sprite &Meteor::getSprite() {
|
|
return meteorSprite;
|
|
}
|
|
|
|
void Meteor::update() {
|
|
meteorSprite.move(0.0f, meteorSpeed); // przesunięcie sprajta
|
|
meteorPosition.y += int(meteorSpeed); // przesunięcie pozycji
|
|
meteorSprite.rotate(meteorRotationSpeed); // obracanie tym meteorkiem pięknym
|
|
if(meteorPosition.y > 900) {
|
|
outOfBounds = true; // jeżeli wyszedł poza granice ekranu ustaw tą zmienną
|
|
}
|
|
// std::cout << "x: " << meteorSprite.getPosition().x << std::endl;
|
|
// std::cout << "y: " << meteorSprite.getPosition().y << std::endl;
|
|
}
|
|
|
|
bool Meteor::getStatus() {
|
|
return outOfBounds;
|
|
}
|
|
|
|
unsigned int Meteor::counter = 0;
|
|
|
|
// było użyte do testowania czy meteoryt jest kasowany
|
|
//Meteor::~Meteor() {
|
|
// Meteor::counter++;
|
|
// std::clog << Meteor::counter << " Meteor destroyed\n";
|
|
//}
|
|
|