ObjectItem class added to accordance of diagram class
This commit is contained in:
@@ -1,40 +1,29 @@
|
||||
#include <iostream>
|
||||
#include "../headers/Meteor.h"
|
||||
|
||||
Meteor::Meteor(float x, float y, sf::Texture &texture) {
|
||||
Meteor::Meteor(float x, float y, sf::Texture &texture) : ObjectItem(x, y, 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);
|
||||
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);
|
||||
}
|
||||
|
||||
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) {
|
||||
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ą
|
||||
}
|
||||
// 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++;
|
||||
|
||||
Reference in New Issue
Block a user