This repository has been archived on 2025-06-06. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
LotoStatek/sources/Meteor.cpp
2024-12-19 16:01:21 +01:00

33 lines
1.0 KiB
C++

#include "../headers/Meteor.h"
Meteor::Meteor(float x, float y, sf::Texture &texture) : ObjectItem(x, y, texture) {
outOfBounds = false;
texture_ = texture;
sprite.setTexture(texture);
sprite.setOrigin(sprite.getLocalBounds().width / 2, sprite.getLocalBounds().height / 2); // wycentrowanie sprite
sprite.setPosition(x, y);
movingSpeed = 5.0f;
sprite.scale(0.05f, 0.05f);
position.x = x;
position.y = y;
rotationSpeed = static_cast<float>(rand() % 2 + 1) * (rand() % 2 == 0 ? 1 : -1);
}
void Meteor::update() {
sprite.move(0.0f, movingSpeed); // przesunięcie sprajta
position.y += int(movingSpeed); // przesunięcie pozycji
sprite.rotate(rotationSpeed); // obracanie tym meteorkiem pięknym
if(position.y > 900) {
outOfBounds = true; // jeżeli wyszedł poza granice ekranu ustaw tą zmienną
}
}
// było użyte do testowania czy meteoryt jest kasowany
//Meteor::~Meteor() {
// Meteor::counter++;
// std::clog << Meteor::counter << " Meteor destroyed\n";
//}