Zmiana sposobu tworzenia gracza.
Użyto singleton pattern. Zmieniono konstruktor klasy Plansza
This commit is contained in:
@@ -11,12 +11,6 @@ class Actor {
|
||||
public:
|
||||
Actor(int x, int y, const sf::Texture& texture);
|
||||
|
||||
void loadTexture(std::string path);
|
||||
|
||||
sf::Sprite& getSprite();
|
||||
|
||||
Position getPosition();
|
||||
|
||||
virtual void move(float deltaX, float deltaY) = 0;
|
||||
virtual void moveLeft() = 0;
|
||||
virtual void moveRight() = 0;
|
||||
@@ -25,22 +19,24 @@ public:
|
||||
virtual void shoot() = 0;
|
||||
|
||||
std::vector<Bullet>& getBullets();
|
||||
|
||||
void updateBullets();
|
||||
sf::Sprite& getSprite();
|
||||
Position getPosition();
|
||||
|
||||
void setMovingSpeed(float speed);
|
||||
|
||||
void updateBullets();
|
||||
|
||||
protected:
|
||||
Position position;
|
||||
sf::Sprite actorSprite;
|
||||
sf::Texture actorTexture;
|
||||
sf::Texture bulletTextureLeft;
|
||||
sf::Texture bulletTextureRight;
|
||||
Position position;
|
||||
sf::Texture bulletTexture;
|
||||
sf::Texture rocketTexture;
|
||||
std::vector<Bullet> bullets;
|
||||
unsigned int hp;
|
||||
unsigned int damage;
|
||||
unsigned int firerate;
|
||||
float moving_speed;
|
||||
std::vector<Bullet> bullets;
|
||||
};
|
||||
|
||||
#endif //ACTOR_H
|
||||
|
||||
@@ -18,25 +18,30 @@
|
||||
|
||||
class Plansza {
|
||||
public:
|
||||
Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::RenderWindow *mainWindow,
|
||||
const sf::Texture& playerTexture, const sf::Texture& playerBulletTexture, const sf::Texture& playerRocketTexture);
|
||||
Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::RenderWindow *mainWindow);
|
||||
Size getSize();
|
||||
std::vector<Meteor> &getMeteors();
|
||||
void spawn_meteor();
|
||||
void update_meteors();
|
||||
void update();
|
||||
void update_score();
|
||||
void spawn_enemy();
|
||||
void setOutOfBounds(bool status);
|
||||
void spawn_player();
|
||||
void spawn_enemy();
|
||||
void spawn_advanced_enemy();
|
||||
void spawn_wiazkowiec();
|
||||
void spawn_bomber();
|
||||
void spawn_kamikadze();
|
||||
~Plansza() {
|
||||
delete ship; // usuwanie wskaźnika ship
|
||||
}
|
||||
private:
|
||||
Size size;
|
||||
Background background;
|
||||
Player ship;
|
||||
AudioManager audioManager;
|
||||
Player *ship;
|
||||
sf::RenderWindow *window;
|
||||
sf::Font font;
|
||||
sf::Texture meteorTexture1;
|
||||
sf::Texture meteorTexture2;
|
||||
sf::Texture enemyBulletTexture;
|
||||
@@ -53,20 +58,19 @@ private:
|
||||
sf::Clock spawnClock;
|
||||
sf::Clock scoreClock;
|
||||
sf::Clock shooterSpawnClock;
|
||||
std::vector<Enemy> enemies;
|
||||
std::vector<AdvancedEnemy> AEnemies;
|
||||
std::vector<Bomber> BEnemies;
|
||||
std::vector<Kamikadze> KEnemies;
|
||||
std::vector<Wiazkowiec> WEnemies;
|
||||
sf::Clock enemySpawnClock;
|
||||
sf::Clock AenemySpawnClock;
|
||||
sf::Clock BomberSpawnClock;
|
||||
sf::Clock KamikadzeSpawnClock;
|
||||
sf::Clock WiazkowiecSpawnClock;
|
||||
std::vector<Enemy> enemies;
|
||||
std::vector<AdvancedEnemy> AEnemies;
|
||||
std::vector<Bomber> BEnemies;
|
||||
std::vector<Kamikadze> KEnemies;
|
||||
std::vector<Wiazkowiec> WEnemies;
|
||||
std::vector<Meteor> meteors;
|
||||
sf::RenderWindow *window;
|
||||
sf::Font font;
|
||||
unsigned int score = 0;
|
||||
bool isPlayerSpawned = false;
|
||||
};
|
||||
|
||||
#endif //PLANSZA_H
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef LOTOSTATEK_PLAYER_H
|
||||
#define LOTOSTATEK_PLAYER_H
|
||||
|
||||
|
||||
#include <chrono>
|
||||
#include <SFML/System/Clock.hpp>
|
||||
|
||||
@@ -9,9 +8,17 @@
|
||||
#include "Rocket.h"
|
||||
|
||||
class Player : public Actor {
|
||||
// Zgodnie z refactoring.guru singleton pattern
|
||||
// https://refactoring.guru/design-patterns/singleton/cpp/example
|
||||
protected:
|
||||
Player(int x, int y, const sf::Texture &texture);
|
||||
static Player* player_;
|
||||
public:
|
||||
Player(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture, const sf::Texture& rocketTexture);
|
||||
void setTextures(const sf::Texture& shipTexture, const sf::Texture& bulletTexture, const sf::Texture& rocketTexture);
|
||||
Player(Player &other) = delete;
|
||||
void operator=(const Player &) = delete;
|
||||
static Player* getInstance(int x, int y, const sf::Texture &texture);
|
||||
// Tu się kończy definicja singletona
|
||||
|
||||
void shoot() override;
|
||||
void alternate_shoot();
|
||||
void setFirerate(unsigned int firerate);
|
||||
@@ -24,6 +31,9 @@ public:
|
||||
bool isAlive() const;
|
||||
void update();
|
||||
std::vector<Rocket>& getRockets();
|
||||
|
||||
void loadTexture();
|
||||
|
||||
private:
|
||||
std::chrono::steady_clock::time_point lastShotTime = std::chrono::steady_clock::now();
|
||||
std::vector<Rocket> rockets;
|
||||
|
||||
Reference in New Issue
Block a user