ObjectItem class added to accordance of diagram class
This commit is contained in:
@@ -25,7 +25,9 @@ add_executable(LotoStatek main.cpp
|
|||||||
headers/Rocket.h
|
headers/Rocket.h
|
||||||
sources/Rocket.cpp
|
sources/Rocket.cpp
|
||||||
headers/Size.h
|
headers/Size.h
|
||||||
headers/Position.h)
|
headers/Position.h
|
||||||
|
headers/ObjectItem.hpp
|
||||||
|
sources/ObjectItem.cpp)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
set(SFML_ROOT "${CMAKE_SOURCE_DIR}/lib/SFML")
|
set(SFML_ROOT "${CMAKE_SOURCE_DIR}/lib/SFML")
|
||||||
|
|||||||
BIN
assets/img/hearts/heart.png
Normal file
BIN
assets/img/hearts/heart.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 782 B |
@@ -4,22 +4,12 @@
|
|||||||
#include "SFML/Graphics/Texture.hpp"
|
#include "SFML/Graphics/Texture.hpp"
|
||||||
#include "SFML/Graphics/Sprite.hpp"
|
#include "SFML/Graphics/Sprite.hpp"
|
||||||
#include "Position.h"
|
#include "Position.h"
|
||||||
|
#include "ObjectItem.hpp"
|
||||||
|
|
||||||
class Meteor {
|
class Meteor : public ObjectItem {
|
||||||
public:
|
public:
|
||||||
Meteor(float x, float y, sf::Texture &texture);
|
Meteor(float x, float y, sf::Texture &texture);
|
||||||
sf::Sprite &getSprite();
|
|
||||||
bool getStatus();
|
|
||||||
void update();
|
void update();
|
||||||
// ~Meteor();
|
|
||||||
private:
|
|
||||||
sf::Texture meteorTexture;
|
|
||||||
sf::Sprite meteorSprite;
|
|
||||||
Position meteorPosition;
|
|
||||||
float meteorRotationSpeed;
|
|
||||||
float meteorSpeed;
|
|
||||||
bool outOfBounds;
|
|
||||||
static unsigned int counter;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
24
headers/ObjectItem.hpp
Normal file
24
headers/ObjectItem.hpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#ifndef LOTOSTATEK_OBJECTITEM_HPP
|
||||||
|
#define LOTOSTATEK_OBJECTITEM_HPP
|
||||||
|
|
||||||
|
#include "SFML/Graphics/Sprite.hpp"
|
||||||
|
#include "Position.h"
|
||||||
|
#include "SFML/Graphics/Texture.hpp"
|
||||||
|
|
||||||
|
class ObjectItem {
|
||||||
|
public:
|
||||||
|
ObjectItem(float x, float y, sf::Texture &texture);
|
||||||
|
sf::Sprite &getSprite();
|
||||||
|
bool getStatus();
|
||||||
|
virtual void update() = 0;
|
||||||
|
protected:
|
||||||
|
sf::Texture texture;
|
||||||
|
sf::Sprite sprite;
|
||||||
|
Position position;
|
||||||
|
float rotationSpeed;
|
||||||
|
float movingSpeed;
|
||||||
|
bool outOfBounds;
|
||||||
|
static unsigned int counter;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //LOTOSTATEK_OBJECTITEM_HPP
|
||||||
@@ -1,40 +1,29 @@
|
|||||||
#include <iostream>
|
|
||||||
#include "../headers/Meteor.h"
|
#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;
|
outOfBounds = false;
|
||||||
meteorTexture = texture;
|
texture = texture;
|
||||||
meteorSprite.setTexture(texture);
|
sprite.setTexture(texture);
|
||||||
meteorSprite.setOrigin(meteorSprite.getLocalBounds().width / 2, meteorSprite.getLocalBounds().height / 2); // wycentrowanie sprite
|
sprite.setOrigin(sprite.getLocalBounds().width / 2, sprite.getLocalBounds().height / 2); // wycentrowanie sprite
|
||||||
meteorSprite.setPosition(x, y);
|
sprite.setPosition(x, y);
|
||||||
meteorSpeed = 5.0f;
|
movingSpeed = 5.0f;
|
||||||
meteorSprite.scale(0.05f, 0.05f);
|
sprite.scale(0.05f, 0.05f);
|
||||||
meteorPosition.x = x;
|
position.x = x;
|
||||||
meteorPosition.y = y;
|
position.y = y;
|
||||||
meteorRotationSpeed = static_cast<float>(rand() % 2 + 1) * (rand() % 2 == 0 ? 1 : -1);
|
rotationSpeed = static_cast<float>(rand() % 2 + 1) * (rand() % 2 == 0 ? 1 : -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
sf::Sprite &Meteor::getSprite() {
|
|
||||||
return meteorSprite;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Meteor::update() {
|
void Meteor::update() {
|
||||||
meteorSprite.move(0.0f, meteorSpeed); // przesunięcie sprajta
|
sprite.move(0.0f, movingSpeed); // przesunięcie sprajta
|
||||||
meteorPosition.y += int(meteorSpeed); // przesunięcie pozycji
|
position.y += int(movingSpeed); // przesunięcie pozycji
|
||||||
meteorSprite.rotate(meteorRotationSpeed); // obracanie tym meteorkiem pięknym
|
sprite.rotate(rotationSpeed); // obracanie tym meteorkiem pięknym
|
||||||
if(meteorPosition.y > 900) {
|
if(position.y > 900) {
|
||||||
outOfBounds = true; // jeżeli wyszedł poza granice ekranu ustaw tą zmienną
|
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
|
// było użyte do testowania czy meteoryt jest kasowany
|
||||||
//Meteor::~Meteor() {
|
//Meteor::~Meteor() {
|
||||||
// Meteor::counter++;
|
// Meteor::counter++;
|
||||||
|
|||||||
17
sources/ObjectItem.cpp
Normal file
17
sources/ObjectItem.cpp
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#include "../headers/ObjectItem.hpp"
|
||||||
|
|
||||||
|
ObjectItem::ObjectItem(float x, float y, sf::Texture &texture) {
|
||||||
|
Position position_;
|
||||||
|
position_.x = x;
|
||||||
|
position_.y = y;
|
||||||
|
position = position_;
|
||||||
|
this->texture = texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ObjectItem::getStatus() {
|
||||||
|
return outOfBounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
sf::Sprite &ObjectItem::getSprite() {
|
||||||
|
return sprite;
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <random>
|
#include <random>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "../headers/Plansza.h"
|
#include "../headers/Plansza.h"
|
||||||
|
#include "../headers/ObjectItem.hpp"
|
||||||
|
|
||||||
Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::RenderWindow *mainWindow)
|
Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::RenderWindow *mainWindow)
|
||||||
: background("../assets/img/background/background.png", 2.0f),
|
: background("../assets/img/background/background.png", 2.0f),
|
||||||
|
|||||||
Reference in New Issue
Block a user