Meteory są w tym samym stanie co w poprzednim commit, tylko, że teraz są zdefiniowane w osobnej klasie "Plansza"

This commit is contained in:
2024-11-20 14:01:43 +01:00
parent cf10a042c0
commit 1cd9f9b950
8 changed files with 84 additions and 39 deletions
+3 -3
View File
@@ -12,15 +12,15 @@ class Bullet {
public:
Bullet(float x, float y, sf::Texture &texture);
void update();
sf::Sprite& getSprite();
sf::Sprite &getSprite();
void setSpeed(float speed);
bool getStatus() const;
void update();
private:
sf::Sprite bulletSprite;
sf::Texture bulletTexture;
float bulletSpeed;
Position bulletPosition;
float bulletSpeed;
bool outOfBounds;
};
+4 -3
View File
@@ -9,15 +9,16 @@ class Meteor {
int x;
int y;
};
public:
Meteor(int x, int y, sf::Texture &texture);
sf::Sprite & getSprite();
Meteor(float x, float y, sf::Texture &texture);
sf::Sprite &getSprite();
bool getStatus();
void update();
private:
sf::Texture meteorTexture;
sf::Sprite meteorSprite;
Position position;
Position meteorPosition;
float meteorSpeed;
bool outOfBounds;
};
+17 -3
View File
@@ -2,11 +2,25 @@
#define PLANSZA_H
#include "Meteor.h"
#include "RandomNumberGenerator.h"
class Plansza {
struct Size {
int height;
int width;
};
public:
Plansza(int windowHeight, int windowWidth);
void spawn_meteor();
Size getSize();
std::vector<Meteor> &getMeteors();
void update_meteors();
private:
std::vector<Meteor> meteors;
Size size;
sf::Texture meteorTexture;
RandomNumberGenerator random;
};
#endif //PLANSZA_H
+20
View File
@@ -0,0 +1,20 @@
#ifndef LOTOSTATEK_RANDOMNUMBERGENERATOR_H
#define LOTOSTATEK_RANDOMNUMBERGENERATOR_H
#include <random>
class RandomNumberGenerator {
private:
std::random_device rd;
std::mt19937 gen;
std::uniform_int_distribution<> dis;
public:
RandomNumberGenerator() : gen(rd()), dis(0, 599) {}
int getRandomNumber() {
return dis(gen);
}
};
#endif //LOTOSTATEK_RANDOMNUMBERGENERATOR_H