Compare commits
1 Commits
8b4b25747e
...
Strzaly-w-
| Author | SHA1 | Date | |
|---|---|---|---|
| 8db6b8572d |
@@ -25,22 +25,7 @@ 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
|
|
||||||
sources/Enemy.cpp
|
|
||||||
headers/Enemy.h
|
|
||||||
headers/AdvancedEnemy.h
|
|
||||||
sources/AdvancedEnemy.cpp
|
|
||||||
headers/Bomber.h
|
|
||||||
sources/Bomber.cpp
|
|
||||||
headers/Kamikadze.h
|
|
||||||
sources/Kamikadze.cpp
|
|
||||||
headers/wiazkowiec.h
|
|
||||||
sources/Wiazkowiec.cpp
|
|
||||||
headers/Beam.h
|
|
||||||
sources/Beam.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
set(SFML_ROOT "${CMAKE_SOURCE_DIR}/lib/SFML")
|
set(SFML_ROOT "${CMAKE_SOURCE_DIR}/lib/SFML")
|
||||||
@@ -55,9 +40,9 @@ if(WIN32)
|
|||||||
target_link_libraries(LotoStatek ${SFML_LIBRARIES})
|
target_link_libraries(LotoStatek ${SFML_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
elseif(APPLE)
|
elseif(APPLE)
|
||||||
find_package(SFML 2.6.2 COMPONENTS graphics window system REQUIRED)
|
find_package(lib/SFML 2.6.2 COMPONENTS graphics window system REQUIRED)
|
||||||
target_link_libraries(LotoStatek sfml-graphics sfml-window sfml-audio sfml-system)
|
target_link_libraries(LotoStatek sfml-graphics sfml-window sfml-audio sfml-system)
|
||||||
elseif(LINUX)
|
elseif(LINUX)
|
||||||
find_package(SFML 2.6.2 COMPONENTS graphics window system REQUIRED)
|
find_package(lib/SFML 2.6.2 COMPONENTS graphics window system REQUIRED)
|
||||||
target_link_libraries(LotoStatek sfml-graphics sfml-window sfml-audio sfml-system)
|
target_link_libraries(LotoStatek sfml-graphics sfml-window sfml-audio sfml-system)
|
||||||
endif()
|
endif()
|
||||||
|
Before Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 8.3 KiB |
|
Before Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 6.1 KiB |
|
Before Width: | Height: | Size: 7.9 KiB |
|
Before Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 782 B |
|
Before Width: | Height: | Size: 39 KiB |
@@ -9,7 +9,13 @@
|
|||||||
|
|
||||||
class Actor {
|
class Actor {
|
||||||
public:
|
public:
|
||||||
Actor(int x, int y, const sf::Texture& texture);
|
Actor(int x, int y, std::string path);
|
||||||
|
|
||||||
|
void loadTexture(std::string path);
|
||||||
|
|
||||||
|
sf::Sprite& getSprite();
|
||||||
|
|
||||||
|
Position getPosition();
|
||||||
|
|
||||||
virtual void move(float deltaX, float deltaY) = 0;
|
virtual void move(float deltaX, float deltaY) = 0;
|
||||||
virtual void moveLeft() = 0;
|
virtual void moveLeft() = 0;
|
||||||
@@ -19,24 +25,22 @@ public:
|
|||||||
virtual void shoot() = 0;
|
virtual void shoot() = 0;
|
||||||
|
|
||||||
std::vector<Bullet>& getBullets();
|
std::vector<Bullet>& getBullets();
|
||||||
sf::Sprite& getSprite();
|
|
||||||
Position getPosition();
|
|
||||||
|
|
||||||
void setMovingSpeed(float speed);
|
|
||||||
|
|
||||||
void updateBullets();
|
void updateBullets();
|
||||||
|
|
||||||
|
void setMovingSpeed(float speed);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Position position;
|
|
||||||
sf::Sprite actorSprite;
|
sf::Sprite actorSprite;
|
||||||
sf::Texture actorTexture;
|
sf::Texture actorTexture;
|
||||||
sf::Texture bulletTexture;
|
sf::Texture bulletTextureLeft;
|
||||||
sf::Texture rocketTexture;
|
sf::Texture bulletTextureRight;
|
||||||
std::vector<Bullet> bullets;
|
Position position;
|
||||||
unsigned int hp;
|
unsigned int hp;
|
||||||
unsigned int damage;
|
unsigned int damage;
|
||||||
unsigned int firerate;
|
unsigned int firerate;
|
||||||
float moving_speed;
|
float moving_speed;
|
||||||
|
std::vector<Bullet> bullets;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //ACTOR_H
|
#endif //ACTOR_H
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
#ifndef ADVANCED_ENEMY_H
|
|
||||||
#define ADVANCED_ENEMY_H
|
|
||||||
|
|
||||||
#include "Enemy.h"
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
enum class DirectionA {
|
|
||||||
Up,
|
|
||||||
Down,
|
|
||||||
Left,
|
|
||||||
Right
|
|
||||||
};
|
|
||||||
|
|
||||||
class AdvancedEnemy : public Actor {
|
|
||||||
public:
|
|
||||||
AdvancedEnemy(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture);
|
|
||||||
|
|
||||||
void shoot() override;
|
|
||||||
void move(float deltaX, float deltaY) override;
|
|
||||||
void moveLeft() override;
|
|
||||||
void moveRight() override;
|
|
||||||
void moveUp() override;
|
|
||||||
void moveDown() override;
|
|
||||||
|
|
||||||
void update();
|
|
||||||
|
|
||||||
bool isAlive() const;
|
|
||||||
void takeDamage();
|
|
||||||
void updateDirection();
|
|
||||||
|
|
||||||
private:
|
|
||||||
sf::Clock shootClock;
|
|
||||||
sf::Texture enemyBulletTexture;
|
|
||||||
float movementSpeed = 2.0f;
|
|
||||||
bool alive = true;
|
|
||||||
DirectionA direction = DirectionA::Down;
|
|
||||||
};
|
|
||||||
#endif // ADVANCED_ENEMY_H
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
#ifndef LOTOSTATEK_BEAM_H
|
|
||||||
#define LOTOSTATEK_BEAM_H
|
|
||||||
|
|
||||||
#include <SFML/Graphics.hpp>
|
|
||||||
#include "Position.h"
|
|
||||||
|
|
||||||
class Beam {
|
|
||||||
public:
|
|
||||||
Beam(float x, float y, float width, float height, const sf::Color& color);
|
|
||||||
|
|
||||||
void draw(sf::RenderWindow &window);
|
|
||||||
|
|
||||||
void update();
|
|
||||||
void render(sf::RenderWindow& window);
|
|
||||||
|
|
||||||
sf::FloatRect getBounds() const;
|
|
||||||
|
|
||||||
bool isVisible() const;
|
|
||||||
void setVisible(bool visible);
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
sf::RectangleShape beamShape;
|
|
||||||
bool visible;
|
|
||||||
sf::Texture beamTexture;
|
|
||||||
sf::Sprite beamSprite;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // LOTOSTATEK_BEAM_H
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by k on 11.12.2024.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef BOMBER_H
|
|
||||||
#define BOMBER_H
|
|
||||||
|
|
||||||
#include "Enemy.h"
|
|
||||||
#include "Actor.h"
|
|
||||||
enum class DirectionB {
|
|
||||||
Up,
|
|
||||||
Down,
|
|
||||||
Left,
|
|
||||||
Right
|
|
||||||
};
|
|
||||||
|
|
||||||
class Bomber : public Actor {
|
|
||||||
public:
|
|
||||||
Bomber(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture);
|
|
||||||
|
|
||||||
void shoot() override;
|
|
||||||
void move(float deltaX, float deltaY) override;
|
|
||||||
void moveLeft() override;
|
|
||||||
void moveRight() override;
|
|
||||||
void moveUp() override;
|
|
||||||
void moveDown() override;
|
|
||||||
void setRandomDirection();
|
|
||||||
|
|
||||||
void update();
|
|
||||||
|
|
||||||
bool isAlive() const;
|
|
||||||
void takeDamage();
|
|
||||||
void updateDirection();
|
|
||||||
void setPlanszaHeight(float height, float width);
|
|
||||||
|
|
||||||
private:
|
|
||||||
float planszaHeight = 800.f;
|
|
||||||
float planszaWidth = 600.f;
|
|
||||||
sf::Clock shootClock;
|
|
||||||
sf::Texture BombaTexture;
|
|
||||||
float movementSpeed = 2.0f;
|
|
||||||
bool alive = true;
|
|
||||||
DirectionB direction = DirectionB::Down;
|
|
||||||
};
|
|
||||||
#endif //BOMBER_H
|
|
||||||
@@ -1,16 +1,23 @@
|
|||||||
|
|
||||||
#ifndef LOTOSTATEK_BULLET_H
|
#ifndef LOTOSTATEK_BULLET_H
|
||||||
#define LOTOSTATEK_BULLET_H
|
#define LOTOSTATEK_BULLET_H
|
||||||
|
|
||||||
#include "Projectile.h"
|
#include "Projectile.h"
|
||||||
#include "SFML/Graphics/Texture.hpp"
|
#include "SFML/Graphics/Texture.hpp"
|
||||||
|
#include "SFML/Audio/Sound.hpp"
|
||||||
|
#include "SFML/Audio/SoundBuffer.hpp"
|
||||||
|
|
||||||
class Bullet : public Projectile {
|
class Bullet : public Projectile {
|
||||||
public:
|
public:
|
||||||
Bullet(float x, float y, sf::Texture &texture) : Projectile(x,y, texture) {};
|
Bullet(float x, float y, sf::Texture &texture);
|
||||||
void update() override;
|
void update() override;
|
||||||
|
|
||||||
|
// Dodanie metody do odtwarzania dźwięku
|
||||||
|
void playShootSound();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float directionY;
|
sf::Sound shootSound;
|
||||||
|
sf::SoundBuffer shootBuffer; // Dodanie bufora dźwięku
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif //LOTOSTATEK_BULLET_H
|
#endif //LOTOSTATEK_BULLET_H
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
#ifndef ENEMY_H
|
|
||||||
#define ENEMY_H
|
|
||||||
|
|
||||||
#include "Actor.h"
|
|
||||||
#include "SFML/System/Clock.hpp"
|
|
||||||
|
|
||||||
enum class Direction {
|
|
||||||
Up,
|
|
||||||
Down,
|
|
||||||
Left,
|
|
||||||
Right
|
|
||||||
};
|
|
||||||
|
|
||||||
class Enemy : public Actor {
|
|
||||||
public:
|
|
||||||
Enemy(int x, int y, const sf::Texture& texture) ;
|
|
||||||
|
|
||||||
void shoot() override;
|
|
||||||
void move(float deltaX, float deltaY) override;
|
|
||||||
void moveLeft() override;
|
|
||||||
void moveRight() override;
|
|
||||||
void moveUp() override;
|
|
||||||
void moveDown() override;
|
|
||||||
|
|
||||||
void update();
|
|
||||||
|
|
||||||
bool isAlive() const;
|
|
||||||
void takeDamage();
|
|
||||||
void updateDirection();
|
|
||||||
|
|
||||||
private:
|
|
||||||
sf::Clock shootClock;
|
|
||||||
sf::Texture enemyBulletTexture;
|
|
||||||
float movementSpeed = 2.0f;
|
|
||||||
bool alive = true;
|
|
||||||
Direction direction = Direction::Down;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // ENEMY_H
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
#ifndef KAMIKADZE_H
|
|
||||||
#define KAMIKADZE_H
|
|
||||||
|
|
||||||
#include "Enemy.h"
|
|
||||||
#include "Actor.h"
|
|
||||||
#include "Player.h"
|
|
||||||
enum class DirectionK {
|
|
||||||
Up,
|
|
||||||
Down,
|
|
||||||
Left,
|
|
||||||
Right
|
|
||||||
};
|
|
||||||
|
|
||||||
class Kamikadze : public Actor {
|
|
||||||
public:
|
|
||||||
Kamikadze(int x, int y, const sf::Texture& texture);
|
|
||||||
|
|
||||||
void move(float deltaX, float deltaY) override;
|
|
||||||
void moveLeft() override;
|
|
||||||
void moveRight() override;
|
|
||||||
void moveUp() override;
|
|
||||||
void moveDown() override;
|
|
||||||
void setRandomDirection();
|
|
||||||
void shoot() override;
|
|
||||||
|
|
||||||
void update(const sf::Vector2f& playerPosition);
|
|
||||||
|
|
||||||
bool isAlive() const;
|
|
||||||
bool isExploding() const;
|
|
||||||
void takeDamage();
|
|
||||||
void updateDirection();
|
|
||||||
|
|
||||||
void followPlayer(const sf::Vector2f &playerPosition);
|
|
||||||
|
|
||||||
void explode(const sf::Vector2f &playerPosition, bool &playerHit);
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool exploding = false;
|
|
||||||
sf::Clock explosionClock;
|
|
||||||
sf::Clock shootClock;
|
|
||||||
float movementSpeed = 2.0f;
|
|
||||||
bool alive = true;
|
|
||||||
DirectionK direction = DirectionK::Down;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif //KAMIKADZE_H
|
|
||||||
@@ -4,12 +4,22 @@
|
|||||||
#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 : public ObjectItem {
|
class Meteor {
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
#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,76 +1,36 @@
|
|||||||
#ifndef PLANSZA_H
|
#ifndef PLANSZA_H
|
||||||
#define PLANSZA_H
|
#define PLANSZA_H
|
||||||
|
|
||||||
|
#include "Meteor.h"
|
||||||
|
#include "RandomNumberGenerator.h"
|
||||||
#include "SFML/System/Clock.hpp"
|
#include "SFML/System/Clock.hpp"
|
||||||
#include "SFML/Graphics/RenderWindow.hpp"
|
#include "SFML/Graphics/RenderWindow.hpp"
|
||||||
|
#include "Size.h"
|
||||||
|
|
||||||
#include "Meteor.h"
|
|
||||||
#include "Enemy.h"
|
|
||||||
#include "AdvancedEnemy.h"
|
|
||||||
#include "Bomber.h"
|
|
||||||
#include "Kamikadze.h"
|
|
||||||
#include "Wiazkowiec.h"
|
|
||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "Background.h"
|
#include "Background.h"
|
||||||
#include "AudioManager.h"
|
#include "AudioManager.h"
|
||||||
|
#include "Meteor.h"
|
||||||
#include "Plansza.h"
|
#include "Plansza.h"
|
||||||
#include "Size.h"
|
|
||||||
|
|
||||||
class Plansza {
|
class Plansza {
|
||||||
public:
|
public:
|
||||||
Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::RenderWindow *mainWindow);
|
Plansza(unsigned int windowHeight,unsigned int windowWidth, sf::RenderWindow *mainWindow);
|
||||||
Size getSize();
|
Size getSize();
|
||||||
std::vector<Meteor> &getMeteors();
|
std::vector<Meteor> &getMeteors();
|
||||||
void spawn_meteor();
|
void spawn_meteor();
|
||||||
void update_meteors();
|
void update_meteors();
|
||||||
void update();
|
void update();
|
||||||
void update_score();
|
|
||||||
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:
|
private:
|
||||||
Size size;
|
Size size;
|
||||||
Background background;
|
Background background;
|
||||||
|
Player ship;
|
||||||
AudioManager audioManager;
|
AudioManager audioManager;
|
||||||
Player *ship;
|
|
||||||
sf::RenderWindow *window;
|
|
||||||
sf::Font font;
|
|
||||||
sf::Texture meteorTexture1;
|
sf::Texture meteorTexture1;
|
||||||
sf::Texture meteorTexture2;
|
sf::Texture meteorTexture2;
|
||||||
sf::Texture enemyBulletTexture;
|
|
||||||
sf::Texture WiazkaTexture;
|
|
||||||
sf::Texture BombaTexture;
|
|
||||||
sf::Texture playerTexture;
|
|
||||||
sf::Texture playerBulletTexture;
|
|
||||||
sf::Texture playerRocketTexture;
|
|
||||||
sf::Texture enemyTexture;
|
|
||||||
sf::Texture advancedEnemyTexture;
|
|
||||||
sf::Texture BomberEnemyTexture;
|
|
||||||
sf::Texture KamikadzeTexture;
|
|
||||||
sf::Texture WiazkowiecTexture;
|
|
||||||
sf::Clock spawnClock;
|
sf::Clock spawnClock;
|
||||||
sf::Clock scoreClock;
|
|
||||||
sf::Clock shooterSpawnClock;
|
|
||||||
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;
|
std::vector<Meteor> meteors;
|
||||||
unsigned int score = 0;
|
sf::RenderWindow *window;
|
||||||
bool isPlayerSpawned = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //PLANSZA_H
|
#endif //PLANSZA_H
|
||||||
|
|||||||
@@ -1,24 +1,14 @@
|
|||||||
#ifndef LOTOSTATEK_PLAYER_H
|
#ifndef LOTOSTATEK_PLAYER_H
|
||||||
#define LOTOSTATEK_PLAYER_H
|
#define LOTOSTATEK_PLAYER_H
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
#include <SFML/System/Clock.hpp>
|
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
#include "Actor.h"
|
#include "Actor.h"
|
||||||
#include "Rocket.h"
|
#include "Rocket.h"
|
||||||
|
|
||||||
class Player : public Actor {
|
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:
|
public:
|
||||||
Player(Player &other) = delete;
|
Player(int x, int y, std::string path);
|
||||||
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 shoot() override;
|
||||||
void alternate_shoot();
|
void alternate_shoot();
|
||||||
void setFirerate(unsigned int firerate);
|
void setFirerate(unsigned int firerate);
|
||||||
@@ -27,22 +17,12 @@ public:
|
|||||||
void moveRight() override;
|
void moveRight() override;
|
||||||
void moveUp() override;
|
void moveUp() override;
|
||||||
void moveDown() override;
|
void moveDown() override;
|
||||||
void takeDamage();
|
|
||||||
bool isAlive() const;
|
|
||||||
void update();
|
|
||||||
std::vector<Rocket>& getRockets();
|
std::vector<Rocket>& getRockets();
|
||||||
|
|
||||||
void loadTexture();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::chrono::steady_clock::time_point lastShotTime = std::chrono::steady_clock::now();
|
std::chrono::steady_clock::time_point lastShotTime = std::chrono::steady_clock::now();
|
||||||
std::vector<Rocket> rockets;
|
std::vector<Rocket> rockets;
|
||||||
sf::Texture rocketTexture;
|
sf::Texture rocketTexture;
|
||||||
sf::Texture bulletTexture;
|
sf::Texture bulletTexture;
|
||||||
sf::Clock immortalityClock; // Zegar kontrolujący czas nieśmiertelności
|
|
||||||
int health = 3; // Liczba punktów życia gracza
|
|
||||||
float immortalityDuration = 1.5f; // Czas trwania nieśmiertelności w sec
|
|
||||||
bool isImmortal = false; // flaga na immortal
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ class Rocket : public Projectile{
|
|||||||
public:
|
public:
|
||||||
Rocket(float x, float y, sf::Texture &texture) : Projectile(x,y, texture) {};
|
Rocket(float x, float y, sf::Texture &texture) : Projectile(x,y, texture) {};
|
||||||
void update() override;
|
void update() override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
#ifndef WIAZKOWIEC_H
|
|
||||||
#define WIAZKOWIEC_H
|
|
||||||
|
|
||||||
#include "Enemy.h"
|
|
||||||
#include "Actor.h"
|
|
||||||
#include "Beam.h"
|
|
||||||
enum class DirectionW {
|
|
||||||
Up,
|
|
||||||
Down,
|
|
||||||
Left,
|
|
||||||
Right
|
|
||||||
};
|
|
||||||
|
|
||||||
class Wiazkowiec : public Actor {
|
|
||||||
public:
|
|
||||||
Wiazkowiec(int x, int y, const sf::Texture& texture);
|
|
||||||
|
|
||||||
void shoot() override;
|
|
||||||
void move(float deltaX, float deltaY) override;
|
|
||||||
void moveLeft() override;
|
|
||||||
void moveRight() override;
|
|
||||||
void moveUp() override;
|
|
||||||
void moveDown() override;
|
|
||||||
void setRandomDirection();
|
|
||||||
|
|
||||||
void update();
|
|
||||||
|
|
||||||
void render(sf::RenderWindow &window);
|
|
||||||
|
|
||||||
bool isAlive() const;
|
|
||||||
void takeDamage();
|
|
||||||
void updateDirection();
|
|
||||||
bool isShooting() const;
|
|
||||||
const Beam& getBeam() const;
|
|
||||||
void setPlanszaHeight(float height, float width);
|
|
||||||
void setMapBounds(float width, float height);
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
float planszaHeight = 800.f;
|
|
||||||
float planszaWidth = 600.f;
|
|
||||||
sf::Clock shootClock;
|
|
||||||
sf::Texture WiazkaTexture;
|
|
||||||
float movementSpeed = 2.0f;
|
|
||||||
bool alive = true;
|
|
||||||
DirectionW direction = DirectionW::Down;
|
|
||||||
Beam beam; // Wiązka
|
|
||||||
bool shooting = false;
|
|
||||||
sf::Clock shootingClock;
|
|
||||||
float beamDuration = 1.0f;
|
|
||||||
void spawnBeam(); // Tworzy wiązkę
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif //WIAZKOWIEC_H
|
|
||||||
6
main.cpp
@@ -3,7 +3,8 @@
|
|||||||
|
|
||||||
#include "headers/Plansza.h"
|
#include "headers/Plansza.h"
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
std::clog << "Game started\n";
|
std::clog << "Game started\n";
|
||||||
sf::RenderWindow mainWindow(sf::VideoMode(600, 800), "LotoStatek");
|
sf::RenderWindow mainWindow(sf::VideoMode(600, 800), "LotoStatek");
|
||||||
mainWindow.setVerticalSyncEnabled(true);
|
mainWindow.setVerticalSyncEnabled(true);
|
||||||
@@ -13,7 +14,6 @@ int main() {
|
|||||||
icon.loadFromFile("../assets/img/icon/ikonka.png");
|
icon.loadFromFile("../assets/img/icon/ikonka.png");
|
||||||
mainWindow.setIcon(128, 128, icon.getPixelsPtr());
|
mainWindow.setIcon(128, 128, icon.getPixelsPtr());
|
||||||
|
|
||||||
|
|
||||||
Plansza plansza(mainWindow.getSize().y, mainWindow.getSize().x, &mainWindow);
|
Plansza plansza(mainWindow.getSize().y, mainWindow.getSize().x, &mainWindow);
|
||||||
|
|
||||||
while (mainWindow.isOpen()) {
|
while (mainWindow.isOpen()) {
|
||||||
@@ -22,7 +22,7 @@ int main() {
|
|||||||
// Tu są handlowane eventy
|
// Tu są handlowane eventy
|
||||||
sf::Event event{};
|
sf::Event event{};
|
||||||
while (mainWindow.pollEvent(event)) {
|
while (mainWindow.pollEvent(event)) {
|
||||||
if (event.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
|
if(event.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
|
||||||
mainWindow.close();
|
mainWindow.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,22 @@
|
|||||||
#include "../headers/Actor.h"
|
#include "../headers/Actor.h"
|
||||||
|
|
||||||
#include <iostream>
|
Actor::Actor(int x, int y, std::string path) {
|
||||||
|
loadTexture(path);
|
||||||
Actor::Actor(int x, int y, const sf::Texture& texture) {
|
|
||||||
actorSprite.setTexture(texture);
|
|
||||||
position.x = x;
|
position.x = x;
|
||||||
position.y = y;
|
position.y = y;
|
||||||
actorSprite.setOrigin(actorSprite.getLocalBounds().width / 2, actorSprite.getLocalBounds().height / 2); // wycentrowanie sprite
|
actorSprite.setOrigin(actorSprite.getLocalBounds().width / 2, actorSprite.getLocalBounds().height / 2); // wycentrowanie sprite
|
||||||
actorSprite.setPosition(float(x), float(y));
|
actorSprite.setPosition(float(x), float(y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Actor::loadTexture(std::string path) {
|
||||||
|
actorTexture.loadFromFile(path);
|
||||||
|
actorSprite.setTexture(actorTexture);
|
||||||
|
|
||||||
|
bulletTextureLeft.loadFromFile("../assets/img/bullets/bullet_pink.png");
|
||||||
|
bulletTextureRight.loadFromFile("../assets/img/rockets/Rocket_111.png");
|
||||||
|
}
|
||||||
|
|
||||||
sf::Sprite &Actor::getSprite() {
|
sf::Sprite &Actor::getSprite() {
|
||||||
if (!actorSprite.getTexture()) {
|
|
||||||
std::cerr << "actorSprite has no texture set!" << std::endl;
|
|
||||||
}
|
|
||||||
return actorSprite;
|
return actorSprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,17 +29,13 @@ std::vector<Bullet> &Actor::getBullets() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Actor::updateBullets() {
|
void Actor::updateBullets() {
|
||||||
for (auto it = bullets.begin(); it != bullets.end(); ) {
|
for (auto& bullet : bullets) {
|
||||||
if (it->isOutOfBounds()) {
|
if(bullet.isOutOfBounds()) {
|
||||||
it = bullets.erase(it); // Usuwa element i zwraca iterator na następny element
|
bullets.erase(bullets.begin());
|
||||||
} else {
|
|
||||||
++it; // Przechodzi do następnego elementu
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//std::cout << "Liczba pociskow: " << bullets.size() << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Actor::setMovingSpeed(float speed) {
|
void Actor::setMovingSpeed(float speed) {
|
||||||
moving_speed = speed;
|
moving_speed = speed;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,89 +0,0 @@
|
|||||||
#include "../headers/AdvancedEnemy.h"
|
|
||||||
#include "../headers/Bullet.h"
|
|
||||||
|
|
||||||
AdvancedEnemy::AdvancedEnemy(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture) : Actor(x, y, texture) {
|
|
||||||
actorSprite.setTexture(texture);
|
|
||||||
enemyBulletTexture = bulletTexture;
|
|
||||||
hp = 2; // 2 punkty życia
|
|
||||||
firerate = 2000; // Strzela co 2
|
|
||||||
moving_speed = 2.0f; // Prędkość
|
|
||||||
enemyBulletTexture.loadFromFile("../assets/img/bullets/enemy_bullet.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
void AdvancedEnemy::shoot() {
|
|
||||||
if (shootClock.getElapsedTime().asMilliseconds() >= firerate) {
|
|
||||||
Bullet Cbullet(position.x, position.y + actorSprite.getGlobalBounds().height / 2, enemyBulletTexture);
|
|
||||||
Cbullet.setSpeed(10.0f); // Prędkość w dół
|
|
||||||
bullets.emplace_back(std::move(Cbullet));
|
|
||||||
|
|
||||||
Bullet Lbullet(position.x - 20, position.y + actorSprite.getGlobalBounds().height / 2, enemyBulletTexture);
|
|
||||||
Lbullet.setSpeed(10.0f); // Prędkość w dół
|
|
||||||
bullets.emplace_back(std::move(Lbullet));
|
|
||||||
|
|
||||||
Bullet Rbullet(position.x + 20, position.y + actorSprite.getGlobalBounds().height / 2, enemyBulletTexture);
|
|
||||||
Rbullet.setSpeed(10.0f); // Prędkość w dół
|
|
||||||
bullets.emplace_back(std::move(Rbullet));
|
|
||||||
|
|
||||||
shootClock.restart();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AdvancedEnemy::updateDirection() {
|
|
||||||
// Zmieniamy kierunek przeciwnika, gdy dotrze do krawędzi
|
|
||||||
if (position.y <= 0) {
|
|
||||||
direction = DirectionA::Down;
|
|
||||||
} else if (position.y >= 800) {
|
|
||||||
direction = DirectionA::Up;
|
|
||||||
}
|
|
||||||
|
|
||||||
// logika dla kierunku lewo/prawo
|
|
||||||
if (position.x <= 0) {
|
|
||||||
direction = DirectionA::Right;
|
|
||||||
} else if (position.x >= 1200) {
|
|
||||||
direction = DirectionA::Left;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AdvancedEnemy::move(float deltaX, float deltaY) {
|
|
||||||
actorSprite.move(deltaX, deltaY);
|
|
||||||
position.x += static_cast<int>(deltaX);
|
|
||||||
position.y += static_cast<int>(deltaY);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void AdvancedEnemy::moveLeft() { move(-moving_speed, 0.0f); }
|
|
||||||
void AdvancedEnemy::moveRight() { move(moving_speed, 0.0f); }
|
|
||||||
void AdvancedEnemy::moveUp() { move(0.0f, -moving_speed); }
|
|
||||||
void AdvancedEnemy::moveDown() { move(0.0f, moving_speed); }
|
|
||||||
|
|
||||||
void AdvancedEnemy::update() {
|
|
||||||
// Sprawdzamy, czy przeciwnik dotarł do krawędzi i zmieniamy kierunek
|
|
||||||
updateDirection();
|
|
||||||
|
|
||||||
switch (direction) {
|
|
||||||
case DirectionA::Up:
|
|
||||||
moveUp();
|
|
||||||
break;
|
|
||||||
case DirectionA::Down:
|
|
||||||
moveDown();
|
|
||||||
break;
|
|
||||||
case DirectionA::Left:
|
|
||||||
moveLeft();
|
|
||||||
break;
|
|
||||||
case DirectionA::Right:
|
|
||||||
moveRight();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool AdvancedEnemy::isAlive() const {
|
|
||||||
return alive;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AdvancedEnemy::takeDamage() {
|
|
||||||
if (--hp <= 0) {
|
|
||||||
alive = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
#include "../headers/Beam.h"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
Beam::Beam(float x, float y, float width, float height, const sf::Color& color)
|
|
||||||
: visible(false) {
|
|
||||||
beamShape.setPosition(x, y);
|
|
||||||
beamShape.setSize({width, height});
|
|
||||||
beamShape.setFillColor(color);
|
|
||||||
|
|
||||||
if (!beamTexture.loadFromFile("../assets/img/wiazka/wiazka.png")) {
|
|
||||||
std::cerr << "Błąd! Nie można załadować tekstury wiazka.png" << std::endl;
|
|
||||||
}
|
|
||||||
beamSprite.setTexture(beamTexture);
|
|
||||||
|
|
||||||
if (beamTexture.getSize().x > 0 && beamTexture.getSize().y > 0) {
|
|
||||||
float scaleX = width / beamTexture.getSize().x;
|
|
||||||
float scaleY = height / beamTexture.getSize().y;
|
|
||||||
beamSprite.setScale(scaleX, scaleY);
|
|
||||||
beamSprite.setPosition(x, y);
|
|
||||||
} else {
|
|
||||||
std::cerr << "Błąd: Tekstura wiązki nie została poprawnie załadowana." << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Beam::draw(sf::RenderWindow& window) {
|
|
||||||
|
|
||||||
window.draw(beamSprite);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Beam::update() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void Beam::render(sf::RenderWindow& window) {
|
|
||||||
window.draw(beamSprite);
|
|
||||||
}
|
|
||||||
|
|
||||||
sf::FloatRect Beam::getBounds() const {
|
|
||||||
return beamShape.getGlobalBounds();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Beam::isVisible() const {
|
|
||||||
return visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Beam::setVisible(bool visible) {
|
|
||||||
this->visible = visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,125 +0,0 @@
|
|||||||
#include "../headers/Bomber.h"
|
|
||||||
#include "../headers/Bullet.h"
|
|
||||||
#include <random>
|
|
||||||
|
|
||||||
Bomber::Bomber(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture) : Actor(x, y, texture) {
|
|
||||||
actorSprite.setTexture(texture);
|
|
||||||
BombaTexture = bulletTexture;
|
|
||||||
hp = 2; // 2 punkty życia
|
|
||||||
firerate = 10000; // Strzela co 10
|
|
||||||
moving_speed = 10.0f; // Prędkość
|
|
||||||
}
|
|
||||||
|
|
||||||
void Bomber::setPlanszaHeight(float height, float width) {
|
|
||||||
planszaHeight = height;
|
|
||||||
planszaWidth = width;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Bomber::setRandomDirection() {
|
|
||||||
std::random_device rd;
|
|
||||||
std::mt19937 gen(rd());
|
|
||||||
std::uniform_int_distribution<int> dist(0, 3);
|
|
||||||
|
|
||||||
int randomDirection = dist(gen);
|
|
||||||
|
|
||||||
// Zapobieganie wyjscia poza ekran
|
|
||||||
switch (randomDirection) {
|
|
||||||
case 0:
|
|
||||||
if (position.y > 0) direction = DirectionB::Up;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
if (position.y < 600) direction = DirectionB::Down;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
if (position.x > 0) direction = DirectionB::Left;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
if (position.x < 800) direction = DirectionB::Right;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Bomber::shoot() {
|
|
||||||
if (shootClock.getElapsedTime().asMilliseconds() >= firerate) {
|
|
||||||
Bullet Bbullet(position.x, position.y + actorSprite.getGlobalBounds().height / 2, BombaTexture);
|
|
||||||
Bbullet.setSpeed(0.1f); // Prędkość w dół
|
|
||||||
bullets.emplace_back(std::move(Bbullet));
|
|
||||||
shootClock.restart();
|
|
||||||
setRandomDirection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Bomber::updateDirection() {
|
|
||||||
auto spriteBounds = actorSprite.getGlobalBounds(); // Pobierz rozmiar i pozycję sprite'a
|
|
||||||
|
|
||||||
// Kontrola górnej i dolnej krawędzi (wysokości planszy)
|
|
||||||
if (position.y <= 0) {
|
|
||||||
direction = DirectionB::Down;
|
|
||||||
} else if (position.y + spriteBounds.height >= planszaHeight) {
|
|
||||||
direction = DirectionB::Up;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Kontrola lewej i prawej krawędzi (szerokości planszy)
|
|
||||||
if (position.x <= 0) {
|
|
||||||
direction = DirectionB::Right;
|
|
||||||
} else if (position.x + spriteBounds.width >= planszaWidth) {
|
|
||||||
direction = DirectionB::Left;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Bomber::move(float deltaX, float deltaY) {
|
|
||||||
auto spriteBounds = actorSprite.getGlobalBounds(); // Rozmiar i pozycja sprite'a
|
|
||||||
|
|
||||||
// Zapobiegaj wyjściu poza poziome granice
|
|
||||||
if (position.x + deltaX < 0) {
|
|
||||||
deltaX = -position.x;
|
|
||||||
} else if (position.x + spriteBounds.width + deltaX > planszaWidth) {
|
|
||||||
deltaX = planszaWidth - (position.x + spriteBounds.width);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Zapobiegaj wyjściu poza pionowe granice
|
|
||||||
if (position.y + deltaY < 0) {
|
|
||||||
deltaY = -position.y;
|
|
||||||
} else if (position.y + spriteBounds.height + deltaY > planszaHeight) {
|
|
||||||
deltaY = planszaHeight - (position.y + spriteBounds.height);
|
|
||||||
}
|
|
||||||
actorSprite.move(deltaX, deltaY);
|
|
||||||
position.x += static_cast<int>(deltaX);
|
|
||||||
position.y += static_cast<int>(deltaY);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Bomber::moveLeft() { move(-moving_speed, 0.0f); }
|
|
||||||
void Bomber::moveRight() { move(moving_speed, 0.0f); }
|
|
||||||
void Bomber::moveUp() { move(0.0f, -moving_speed); }
|
|
||||||
void Bomber::moveDown() { move(0.0f, moving_speed); }
|
|
||||||
|
|
||||||
void Bomber::update() {
|
|
||||||
// Sprawdzamy, czy przeciwnik dotarł do krawędzi i zmieniamy kierunek
|
|
||||||
updateDirection();
|
|
||||||
|
|
||||||
switch (direction) {
|
|
||||||
case DirectionB::Up:
|
|
||||||
moveUp();
|
|
||||||
break;
|
|
||||||
case DirectionB::Down:
|
|
||||||
moveDown();
|
|
||||||
break;
|
|
||||||
case DirectionB::Left:
|
|
||||||
moveLeft();
|
|
||||||
break;
|
|
||||||
case DirectionB::Right:
|
|
||||||
moveRight();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Bomber::isAlive() const {
|
|
||||||
return alive;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Bomber::takeDamage() {
|
|
||||||
if (--hp <= 0) {
|
|
||||||
alive = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,22 @@
|
|||||||
#include "../headers/Bullet.h"
|
#include "../headers/Bullet.h"
|
||||||
|
|
||||||
#include <iostream>
|
Bullet::Bullet(float x, float y, sf::Texture &texture) : Projectile(x, y, texture) {
|
||||||
#include <ostream>
|
// Ładowanie dźwięku wystrzału
|
||||||
|
if (!shootBuffer.loadFromFile("../assets/sounds/shoot.ogg")) {
|
||||||
|
// Obsługa błędu
|
||||||
|
}
|
||||||
|
shootSound.setBuffer(shootBuffer);
|
||||||
|
playShootSound(); // Odtwarzanie dźwięku wystrzału przy utworzeniu pocisku
|
||||||
|
}
|
||||||
|
|
||||||
void Bullet::update() {
|
void Bullet::update() {
|
||||||
//std::cout << "Start update: speed = " << speed << ", position.y = " << position.y << std::endl;
|
|
||||||
sprite.move(0.0f, speed);
|
sprite.move(0.0f, speed);
|
||||||
position.y += int(speed);
|
position.y += int(speed);
|
||||||
if(position.y < -100) {
|
if (position.y < -100) {
|
||||||
outOfBounds = true;
|
outOfBounds = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Bullet::playShootSound() {
|
||||||
|
shootSound.play();
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,79 +0,0 @@
|
|||||||
#include "../headers/Enemy.h"
|
|
||||||
#include "../headers/Bullet.h"
|
|
||||||
|
|
||||||
Enemy::Enemy(int x, int y, const sf::Texture& texture) : Actor(x, y, texture) {
|
|
||||||
actorSprite.setTexture(texture);
|
|
||||||
hp = 1; // Przeciwnik ma 1 punkt życia
|
|
||||||
firerate = 2000; // Strzela co 2
|
|
||||||
moving_speed = 2.0f; // Prędkość
|
|
||||||
enemyBulletTexture.loadFromFile("../assets/img/bullets/enemy_bullet.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
void Enemy::shoot() {
|
|
||||||
if (shootClock.getElapsedTime().asMilliseconds() >= firerate) {
|
|
||||||
Bullet bullet(position.x, position.y + actorSprite.getGlobalBounds().height / 2, enemyBulletTexture);
|
|
||||||
bullet.setSpeed(10.0f); // Prędkość w dół
|
|
||||||
bullets.emplace_back(std::move(bullet));
|
|
||||||
shootClock.restart();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Enemy::updateDirection() {
|
|
||||||
// Zmieniamy kierunek przeciwnika, gdy dotrze do krawędzi
|
|
||||||
if (position.y <= 0) {
|
|
||||||
direction = Direction::Down;
|
|
||||||
} else if (position.y >= 800) {
|
|
||||||
direction = Direction::Up;
|
|
||||||
}
|
|
||||||
|
|
||||||
// logika dla kierunku lewo/prawo
|
|
||||||
if (position.x <= 0) {
|
|
||||||
direction = Direction::Right;
|
|
||||||
} else if (position.x >= 1200) {
|
|
||||||
direction = Direction::Left;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Enemy::move(float deltaX, float deltaY) {
|
|
||||||
actorSprite.move(deltaX, deltaY);
|
|
||||||
position.x += static_cast<int>(deltaX);
|
|
||||||
position.y += static_cast<int>(deltaY);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Enemy::moveLeft() { move(-moving_speed, 0.0f); }
|
|
||||||
void Enemy::moveRight() { move(moving_speed, 0.0f); }
|
|
||||||
void Enemy::moveUp() { move(0.0f, -moving_speed); }
|
|
||||||
void Enemy::moveDown() { move(0.0f, moving_speed); }
|
|
||||||
|
|
||||||
void Enemy::update() {
|
|
||||||
// Sprawdzamy, czy przeciwnik dotarł do krawędzi i zmieniamy kierunek
|
|
||||||
updateDirection();
|
|
||||||
|
|
||||||
switch (direction) {
|
|
||||||
case Direction::Up:
|
|
||||||
moveUp();
|
|
||||||
break;
|
|
||||||
case Direction::Down:
|
|
||||||
moveDown();
|
|
||||||
break;
|
|
||||||
case Direction::Left:
|
|
||||||
moveLeft();
|
|
||||||
break;
|
|
||||||
case Direction::Right:
|
|
||||||
moveRight();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Enemy::isAlive() const {
|
|
||||||
return alive;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Enemy::takeDamage() {
|
|
||||||
if (--hp <= 0) {
|
|
||||||
alive = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,134 +0,0 @@
|
|||||||
#include "../headers/Kamikadze.h"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <random>
|
|
||||||
|
|
||||||
#include "../headers/RandomNumberGenerator.h"
|
|
||||||
|
|
||||||
Kamikadze::Kamikadze(int x, int y, const sf::Texture& texture) : Actor(x, y, texture) {
|
|
||||||
actorSprite.setTexture(texture);
|
|
||||||
hp = 3; // 3 punkty życia
|
|
||||||
moving_speed = 2.0f; // Prędkość
|
|
||||||
}
|
|
||||||
|
|
||||||
void Kamikadze::shoot(){}
|
|
||||||
|
|
||||||
void Kamikadze::setRandomDirection() {
|
|
||||||
int randomDirection = RandomNumberGenerator::getRandomNumber(0,3);
|
|
||||||
|
|
||||||
// Zapobieganie wyjscia poza ekran
|
|
||||||
switch (randomDirection) {
|
|
||||||
case 0:
|
|
||||||
if (position.y > 0) direction = DirectionK::Up;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
if (position.y < 800) direction = DirectionK::Down;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
if (position.x > 0) direction = DirectionK::Left;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
if (position.x < 1200) direction = DirectionK::Right;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Kamikadze::updateDirection() {
|
|
||||||
// Zmieniamy kierunek przeciwnika, gdy dotrze do krawędzi
|
|
||||||
if (position.y <= 0) {
|
|
||||||
direction = DirectionK::Down;
|
|
||||||
} else if (position.y >= 800) {
|
|
||||||
direction = DirectionK::Up;
|
|
||||||
}
|
|
||||||
|
|
||||||
// logika dla kierunku lewo/prawo
|
|
||||||
if (position.x <= 0) {
|
|
||||||
direction = DirectionK::Right;
|
|
||||||
} else if (position.x >= 1200) {
|
|
||||||
direction = DirectionK::Left;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Kamikadze::followPlayer(const sf::Vector2f& playerPosition) {
|
|
||||||
float diffX = playerPosition.x - position.x;
|
|
||||||
float diffY = playerPosition.y - position.y;
|
|
||||||
|
|
||||||
float magnitude = std::sqrt(diffX * diffX + diffY * diffY);
|
|
||||||
if (magnitude != 0) {
|
|
||||||
diffX /= magnitude;
|
|
||||||
diffY /= magnitude;
|
|
||||||
|
|
||||||
// Aktualizacja pozycji Kamikadze w kierunku gracza
|
|
||||||
position.x += diffX * movementSpeed;
|
|
||||||
position.y += diffY * movementSpeed;
|
|
||||||
} else { //zatrzymanie kamikadze
|
|
||||||
movementSpeed = 0.0f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Kamikadze::explode(const sf::Vector2f& playerPosition, bool& playerHit) {
|
|
||||||
if (!exploding) {
|
|
||||||
// Rozpocznij kamikadze
|
|
||||||
exploding = true;
|
|
||||||
explosionClock.restart();
|
|
||||||
movementSpeed = 0.0f;
|
|
||||||
|
|
||||||
std::cout << "Kamikadze exploding!" << std::endl;
|
|
||||||
std::cout << "Kamikadze position: (" << position.x << ", " << position.y << ")" << std::endl;
|
|
||||||
std::cout << "Player position: (" << playerPosition.x << ", " << playerPosition.y << ")" << std::endl;
|
|
||||||
|
|
||||||
// Zakres, w jakim gracz może zostać trafiony
|
|
||||||
|
|
||||||
sf::Vector2f diff = playerPosition - sf::Vector2f(static_cast<float>(position.x), static_cast<float>(position.y));
|
|
||||||
float distance = std::sqrt(diff.x * diff.x + diff.y * diff.y);
|
|
||||||
|
|
||||||
std::cout << "Distance to player: " << distance << std::endl;
|
|
||||||
|
|
||||||
// Trafienie gracza, jeśli jest w obszarze eksplozji
|
|
||||||
const float explosionRange = 100.0f;
|
|
||||||
if (distance <= explosionRange) {
|
|
||||||
playerHit = true;
|
|
||||||
std::cout << "Player is within explosion range! Player hit!" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sprawdzanie czasu wybuchu
|
|
||||||
if (exploding && explosionClock.getElapsedTime().asSeconds() >= 0.5f) {
|
|
||||||
alive = false; // Kamikadze ulega zniszczeniu po eksplozji
|
|
||||||
std::cout << "Kamikadze destroyed after explosion!" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Kamikadze::move(float deltaX, float deltaY) {
|
|
||||||
actorSprite.move(deltaX, deltaY);
|
|
||||||
position.x += static_cast<int>(deltaX);
|
|
||||||
position.y += static_cast<int>(deltaY);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Kamikadze::moveLeft() { move(-moving_speed, 0.0f); }
|
|
||||||
void Kamikadze::moveRight() { move(moving_speed, 0.0f); }
|
|
||||||
void Kamikadze::moveUp() { move(0.0f, -moving_speed); }
|
|
||||||
void Kamikadze::moveDown() { move(0.0f, moving_speed); }
|
|
||||||
|
|
||||||
void Kamikadze::update(const sf::Vector2f& playerPosition) {
|
|
||||||
if (alive && !exploding) {
|
|
||||||
// Podążanie za graczem, dopóki Kamikadze jest żywy
|
|
||||||
followPlayer(playerPosition);
|
|
||||||
actorSprite.setPosition(position.x, position.y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Kamikadze::isExploding() const {
|
|
||||||
return exploding;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Kamikadze::isAlive() const {
|
|
||||||
return alive;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Kamikadze::takeDamage() {
|
|
||||||
if (--hp <= 0) {
|
|
||||||
alive = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +1,40 @@
|
|||||||
|
#include <iostream>
|
||||||
#include "../headers/Meteor.h"
|
#include "../headers/Meteor.h"
|
||||||
|
|
||||||
Meteor::Meteor(float x, float y, sf::Texture &texture) : ObjectItem(x, y, texture) {
|
Meteor::Meteor(float x, float y, sf::Texture &texture) {
|
||||||
outOfBounds = false;
|
outOfBounds = false;
|
||||||
texture = texture;
|
meteorTexture = texture;
|
||||||
sprite.setTexture(texture);
|
meteorSprite.setTexture(texture);
|
||||||
sprite.setOrigin(sprite.getLocalBounds().width / 2, sprite.getLocalBounds().height / 2); // wycentrowanie sprite
|
meteorSprite.setOrigin(meteorSprite.getLocalBounds().width / 2, meteorSprite.getLocalBounds().height / 2); // wycentrowanie sprite
|
||||||
sprite.setPosition(x, y);
|
meteorSprite.setPosition(x, y);
|
||||||
movingSpeed = 5.0f;
|
meteorSpeed = 5.0f;
|
||||||
sprite.scale(0.05f, 0.05f);
|
meteorSprite.scale(0.05f, 0.05f);
|
||||||
position.x = x;
|
meteorPosition.x = x;
|
||||||
position.y = y;
|
meteorPosition.y = y;
|
||||||
rotationSpeed = static_cast<float>(rand() % 2 + 1) * (rand() % 2 == 0 ? 1 : -1);
|
meteorRotationSpeed = static_cast<float>(rand() % 2 + 1) * (rand() % 2 == 0 ? 1 : -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sf::Sprite &Meteor::getSprite() {
|
||||||
|
return meteorSprite;
|
||||||
|
}
|
||||||
|
|
||||||
void Meteor::update() {
|
void Meteor::update() {
|
||||||
sprite.move(0.0f, movingSpeed); // przesunięcie sprajta
|
meteorSprite.move(0.0f, meteorSpeed); // przesunięcie sprajta
|
||||||
position.y += int(movingSpeed); // przesunięcie pozycji
|
meteorPosition.y += int(meteorSpeed); // przesunięcie pozycji
|
||||||
sprite.rotate(rotationSpeed); // obracanie tym meteorkiem pięknym
|
meteorSprite.rotate(meteorRotationSpeed); // obracanie tym meteorkiem pięknym
|
||||||
if(position.y > 900) {
|
if(meteorPosition.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++;
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
#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,37 +1,18 @@
|
|||||||
#include <random>
|
#include <random>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "../headers/Plansza.h"
|
#include "../headers/Plansza.h"
|
||||||
#include "../headers/RandomNumberGenerator.h"
|
|
||||||
|
|
||||||
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),
|
||||||
|
ship(static_cast<int>(mainWindow->getSize().x) / 2, static_cast<int>(mainWindow->getSize().y) - 100, "../assets/ship/Dreadnought-Base.png")
|
||||||
|
{
|
||||||
|
|
||||||
window = mainWindow;
|
window = mainWindow;
|
||||||
size.height = static_cast<int>(windowHeight);
|
size.height = static_cast<int>(windowHeight);
|
||||||
size.width = static_cast<int>(windowWidth);
|
size.width = static_cast<int>(windowWidth);
|
||||||
|
|
||||||
try {
|
ship.setMovingSpeed(8);
|
||||||
playerTexture.loadFromFile("../assets/ship/Dreadnought-Base.png");
|
ship.setFirerate(200);
|
||||||
meteorTexture1.loadFromFile("../assets/img/meteors/meteor-1.png");
|
|
||||||
meteorTexture2.loadFromFile("../assets/img/meteors/meteor-2.png");
|
|
||||||
// Ładowanie tekstur wrogów
|
|
||||||
enemyTexture.loadFromFile("../assets/img/enemy/enemy.png");
|
|
||||||
advancedEnemyTexture.loadFromFile("../assets/img/enemy/advanced_enemy.png");
|
|
||||||
BomberEnemyTexture.loadFromFile("../assets/img/enemy/bomber.png");
|
|
||||||
KamikadzeTexture.loadFromFile("../assets/img/enemy/kamikadze.png");
|
|
||||||
BombaTexture.loadFromFile("../assets/img/bullets/bomba.png");
|
|
||||||
WiazkowiecTexture.loadFromFile("../assets/img/enemy/wiazkowiec.png");
|
|
||||||
} catch (std::exception &e) {
|
|
||||||
std::cerr << "Failed to load textures: " << e.what() << std::endl;
|
|
||||||
exit(-500);
|
|
||||||
}
|
|
||||||
|
|
||||||
score = 0;
|
|
||||||
|
|
||||||
// Wczytywanie czcionki dla licznika punktów
|
|
||||||
if (!font.loadFromFile("../assets/fonts/arial.ttf")) {
|
|
||||||
std::cerr << "Error loading font\n";
|
|
||||||
exit(-500);
|
|
||||||
}
|
|
||||||
|
|
||||||
audioManager.loadBackgroundMusic("../assets/music/background.ogg");
|
audioManager.loadBackgroundMusic("../assets/music/background.ogg");
|
||||||
audioManager.playBackgroundMusic();
|
audioManager.playBackgroundMusic();
|
||||||
@@ -40,639 +21,167 @@ Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::Render
|
|||||||
audioManager.loadSoundEffect("shoot_alt", "../assets/sounds/shoot_alt.ogg");
|
audioManager.loadSoundEffect("shoot_alt", "../assets/sounds/shoot_alt.ogg");
|
||||||
audioManager.loadSoundEffect("fail", "../assets/sounds/fail.mp3");
|
audioManager.loadSoundEffect("fail", "../assets/sounds/fail.mp3");
|
||||||
|
|
||||||
spawn_player();
|
meteorTexture1.loadFromFile("../assets/img/meteors/meteor-1.png");
|
||||||
|
meteorTexture2.loadFromFile("../assets/img/meteors/meteor-2.png");
|
||||||
spawnClock.restart();
|
spawnClock.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Plansza::update() {
|
void Plansza::update() {
|
||||||
// tło
|
// tło
|
||||||
background.update();
|
background.update();
|
||||||
background.draw(*window);
|
background.draw(*window);
|
||||||
|
|
||||||
// poruszanie się statkiem
|
// poruszanie się statkiem
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
|
||||||
if (ship->getPosition().x > 50) {
|
if(ship.getPosition().x > 50) {
|
||||||
ship->moveLeft();
|
ship.moveLeft();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
|
if(ship.getPosition().y > 80) {
|
||||||
if (ship->getPosition().y > 80) {
|
ship.moveUp();
|
||||||
ship->moveUp();
|
}
|
||||||
}
|
}
|
||||||
}
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
|
if(ship.getPosition().y < 720) {
|
||||||
if (ship->getPosition().y < 720) {
|
ship.moveDown();
|
||||||
ship->moveDown();
|
}
|
||||||
}
|
}
|
||||||
}
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
|
if(ship.getPosition().x < 550) {
|
||||||
if (ship->getPosition().x < 550) {
|
ship.moveRight();
|
||||||
ship->moveRight();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Przenieść obiekt dźwięku wewnątrz klasy Bullet
|
// TODO: Przenieść obiekt dźwięku wewnątrz klasy Bullet
|
||||||
if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
|
if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
|
||||||
ship->shoot();
|
ship.shoot();
|
||||||
audioManager.playSoundEffect("shoot", 70.f); // Odtworzenie dźwięku wystrzału
|
// audioManager.playSoundEffect("shoot", 70.f); // Odtworzenie dźwięku wystrzału
|
||||||
}
|
|
||||||
if (sf::Mouse::isButtonPressed(sf::Mouse::Right)) {
|
|
||||||
ship->alternate_shoot();
|
|
||||||
audioManager.playSoundEffect("shoot_alt", 70.f); // Odtworzenie dźwięku dla alternatywnego strzału
|
|
||||||
}
|
|
||||||
|
|
||||||
// generowanie nowego meteoru
|
|
||||||
ship->update(); // migotanie statku
|
|
||||||
update_score(); // naliczanie punktów
|
|
||||||
// Sprawnowanie wszystkich rodzajów wrogów
|
|
||||||
spawn_meteor();
|
|
||||||
spawn_enemy();
|
|
||||||
spawn_advanced_enemy();
|
|
||||||
spawn_wiazkowiec();
|
|
||||||
spawn_bomber();
|
|
||||||
spawn_kamikadze();
|
|
||||||
|
|
||||||
// utrzymanie meteorów i pocisków w ruchu
|
|
||||||
for (auto &meteor: getMeteors()) {
|
|
||||||
meteor.update();
|
|
||||||
window->draw(meteor.getSprite());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto &bullet: ship->getBullets()) {
|
|
||||||
bullet.update();
|
|
||||||
window->draw(bullet.getSprite());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto &rocket: ship->getRockets()) {
|
|
||||||
rocket.update();
|
|
||||||
window->draw(rocket.getSprite());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sprawdzenie czy meteory i pociski są poza granicami ekranu
|
|
||||||
update_meteors();
|
|
||||||
ship->updateBullets();
|
|
||||||
|
|
||||||
window->draw(ship->getSprite());
|
|
||||||
|
|
||||||
for (auto &meteor: getMeteors()) {
|
|
||||||
if (ship->getSprite().getGlobalBounds().intersects(meteor.getSprite().getGlobalBounds())) {
|
|
||||||
ship->takeDamage();
|
|
||||||
}
|
}
|
||||||
}
|
if (sf::Mouse::isButtonPressed(sf::Mouse::Right)) {
|
||||||
|
ship.alternate_shoot();
|
||||||
if (!ship->isAlive()) {
|
audioManager.playSoundEffect("shoot_alt", 70.f); // Odtworzenie dźwięku dla alternatywnego strzału
|
||||||
sf::RenderWindow errorWindow(sf::VideoMode(350, 200), "The end");
|
|
||||||
sf::Font font;
|
|
||||||
if (!font.loadFromFile("../assets/fonts/arial.ttf")) {
|
|
||||||
std::cerr << "Error loading font\n";
|
|
||||||
exit(-500);
|
|
||||||
}
|
}
|
||||||
sf::Text text("Your ship is destroyed!", font, 24);
|
|
||||||
text.setFillColor(sf::Color::Red);
|
|
||||||
text.setPosition(50, 80);
|
|
||||||
|
|
||||||
// zatrzymanie muzyki i odtworzenie dźwięku przegranej
|
// generowanie nowego meteoru
|
||||||
audioManager.playSoundEffect("fail", 70.f);
|
spawn_meteor();
|
||||||
audioManager.stopBackgroundMusic();
|
|
||||||
sf::Event event{};
|
|
||||||
while (errorWindow.isOpen()) {
|
// utrzymanie meteorów i pocisków w ruchu
|
||||||
while (errorWindow.pollEvent(event)) {
|
for (auto& meteor : getMeteors()) {
|
||||||
if (event.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
|
meteor.update();
|
||||||
errorWindow.close();
|
window->draw(meteor.getSprite());
|
||||||
window->close();
|
}
|
||||||
exit(-2);
|
|
||||||
|
for (auto& bullet : ship.getBullets()) {
|
||||||
|
bullet.update();
|
||||||
|
window->draw(bullet.getSprite());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& rocket : ship.getRockets()) {
|
||||||
|
rocket.update();
|
||||||
|
window->draw(rocket.getSprite());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sprawdzenie czy meteory i pociski są poza granicami ekranu
|
||||||
|
update_meteors();
|
||||||
|
ship.updateBullets();
|
||||||
|
|
||||||
|
window->draw(ship.getSprite());
|
||||||
|
|
||||||
|
// trochę dziwny sposób ale jednak działa
|
||||||
|
for (auto& meteor : getMeteors()) {
|
||||||
|
if(ship.getSprite().getGlobalBounds().intersects(meteor.getSprite().getGlobalBounds())) {
|
||||||
|
std::cout << "You lost the game!\n";
|
||||||
|
sf::RenderWindow errorWindow(sf::VideoMode(350, 200), "The end");
|
||||||
|
sf::Font font;
|
||||||
|
if (!font.loadFromFile("../assets/fonts/arial.ttf")) {
|
||||||
|
std::cerr << "Error loading font\n";
|
||||||
|
exit(-500);
|
||||||
|
}
|
||||||
|
sf::Text text("Your ship is destroyed!", font, 24);
|
||||||
|
text.setFillColor(sf::Color::Red);
|
||||||
|
text.setPosition(50, 80);
|
||||||
|
|
||||||
|
// zatrzymanie muzyki i odtworzenie dźwięku przegranej
|
||||||
|
audioManager.playSoundEffect("fail", 70.f);
|
||||||
|
audioManager.stopBackgroundMusic();
|
||||||
|
sf::Event event{};
|
||||||
|
while (errorWindow.isOpen()) {
|
||||||
|
while (errorWindow.pollEvent(event)) {
|
||||||
|
if (event.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
|
||||||
|
errorWindow.close();
|
||||||
|
window->close();
|
||||||
|
exit(-2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
errorWindow.clear();
|
||||||
|
errorWindow.draw(text);
|
||||||
|
errorWindow.display();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
errorWindow.clear();
|
|
||||||
errorWindow.draw(text);
|
|
||||||
errorWindow.display();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto meteorIt = getMeteors().begin(); meteorIt != getMeteors().end();) {
|
|
||||||
bool meteorHit = false;
|
|
||||||
for (auto bulletIt = ship->getBullets().begin(); bulletIt != ship->getBullets().end();) {
|
|
||||||
if (meteorIt->getSprite().getGlobalBounds().intersects(bulletIt->getSprite().getGlobalBounds())) {
|
|
||||||
ship->getBullets().erase(bulletIt);
|
|
||||||
meteorIt = getMeteors().erase(meteorIt);
|
|
||||||
meteorHit = true;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
++bulletIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!meteorHit) {
|
|
||||||
++meteorIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto meteorIt = getMeteors().begin(); meteorIt != getMeteors().end();) {
|
|
||||||
bool meteorHit = false;
|
|
||||||
for (auto rocketIt = ship->getRockets().begin(); rocketIt != ship->getRockets().end();) {
|
|
||||||
if (meteorIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
|
||||||
ship->getRockets().erase(rocketIt);
|
|
||||||
meteorIt = getMeteors().erase(meteorIt);
|
|
||||||
meteorHit = true;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
++rocketIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!meteorHit) {
|
|
||||||
++meteorIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ruch i render przeciwnika
|
|
||||||
for (auto it = enemies.begin(); it != enemies.end();) {
|
|
||||||
it->update(); // Aktualizacja kierunku i ruchu
|
|
||||||
it->shoot();
|
|
||||||
|
|
||||||
window->draw(it->getSprite());
|
|
||||||
|
|
||||||
// Usunięcie martwych przeciwników
|
|
||||||
if (!it->isAlive()) {
|
|
||||||
std::cout << "Basic Enemy has been eliminated." << std::endl;
|
|
||||||
it = enemies.erase(it);
|
|
||||||
} else {
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (auto it = AEnemies.begin(); it != AEnemies.end();) {
|
|
||||||
it->update(); // Ruch zaawansowanego przeciwnika
|
|
||||||
it->shoot(); // Strzał przeciwnika
|
|
||||||
|
|
||||||
window->draw(it->getSprite()); // Rysowanie na ekranie
|
|
||||||
|
|
||||||
if (!it->isAlive()) {
|
|
||||||
std::cout << "Advanced Enemy has been eliminated." << std::endl;
|
|
||||||
it = AEnemies.erase(it); // Usunięcie martwych przeciwników
|
|
||||||
} else {
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (auto it = BEnemies.begin(); it != BEnemies.end();) {
|
|
||||||
it->update(); // Ruch bombera
|
|
||||||
it->shoot(); // Strzał przeciwnika
|
|
||||||
|
|
||||||
window->draw(it->getSprite()); // Rysowanie na ekranie
|
|
||||||
|
|
||||||
if (!it->isAlive()) {
|
|
||||||
std::cout << "Bomber has been eliminated." << std::endl;
|
|
||||||
it = BEnemies.erase(it); // Usunięcie martwych przeciwników
|
|
||||||
} else {
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
for (auto it = KEnemies.begin(); it != KEnemies.end();) {
|
|
||||||
sf::Vector2f playerPosition = ship->getSprite().getPosition(); // Aktualna pozycja gracza
|
|
||||||
bool playerHit = false;
|
|
||||||
|
|
||||||
it->update(playerPosition);
|
|
||||||
|
|
||||||
// Wybuch, gdy Kamikadze dotknie gracza
|
|
||||||
if (ship->getSprite().getGlobalBounds().intersects(it->getSprite().getGlobalBounds())) {
|
|
||||||
it->explode(playerPosition, playerHit);
|
|
||||||
if (playerHit) {
|
|
||||||
ship->takeDamage(); // Gracz otrzymuje obrażenia
|
|
||||||
std::cout << "Gracz został trafiony przez eksplozję Kamikadze!" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kamikadze eksploduje po aktywacji niezależnie od obecności gracza
|
for (auto meteorIt = getMeteors().begin(); meteorIt != getMeteors().end(); ) {
|
||||||
if (it->isExploding()) {
|
bool meteorHit = false;
|
||||||
it->explode(playerPosition, playerHit); // Eksplozja trwa
|
for (auto rocketIt = ship.getBullets().begin(); rocketIt != ship.getBullets().end(); ) {
|
||||||
}
|
if (meteorIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
||||||
|
ship.getBullets().erase(rocketIt);
|
||||||
// Usunięcie martwego Kamikadze
|
meteorIt = getMeteors().erase(meteorIt);
|
||||||
if (it->isAlive()) {
|
meteorHit = true;
|
||||||
window->draw(it->getSprite());
|
|
||||||
++it;
|
|
||||||
} else {
|
|
||||||
std::cout << "Kamikadze exploded!" << std::endl;
|
|
||||||
it = KEnemies.erase(it);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Obsługa pocisków zaawansowanych przeciwników
|
|
||||||
for (auto &aEnemy: AEnemies) {
|
|
||||||
for (auto it = aEnemy.getBullets().begin(); it != aEnemy.getBullets().end();) {
|
|
||||||
if (ship->getSprite().getGlobalBounds().intersects(it->getSprite().getGlobalBounds())) {
|
|
||||||
ship->takeDamage(); // Zadanie obrażeń graczowi
|
|
||||||
it = aEnemy.getBullets().erase(it); // Usuwanie pocisku po trafieniu
|
|
||||||
} else {
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obsługa bomb
|
|
||||||
for (auto &aEnemy: BEnemies) {
|
|
||||||
for (auto it = aEnemy.getBullets().begin(); it != aEnemy.getBullets().end();) {
|
|
||||||
if (ship->getSprite().getGlobalBounds().intersects(it->getSprite().getGlobalBounds())) {
|
|
||||||
ship->takeDamage(); // Zadanie obrażeń graczowi
|
|
||||||
it = aEnemy.getBullets().erase(it); // Usuwanie pocisku po trafieniu
|
|
||||||
} else {
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
for (auto &enemy: enemies) {
|
|
||||||
enemy.shoot();
|
|
||||||
enemy.updateBullets();
|
|
||||||
for (auto &bullet: enemy.getBullets()) {
|
|
||||||
bullet.update();
|
|
||||||
window->draw(bullet.getSprite());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto &advancedEnemy: AEnemies) {
|
|
||||||
advancedEnemy.updateBullets(); // Obsługuje pociski zaawansowanych przeciwników
|
|
||||||
for (auto &bullet: advancedEnemy.getBullets()) {
|
|
||||||
bullet.update();
|
|
||||||
window->draw(bullet.getSprite());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto &bomberEnemy: BEnemies) {
|
|
||||||
bomberEnemy.updateBullets(); // Obsługuje bomby
|
|
||||||
for (auto &bullet: bomberEnemy.getBullets()) {
|
|
||||||
bullet.update();
|
|
||||||
window->draw(bullet.getSprite());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto &enemy: enemies) {
|
|
||||||
for (auto it = enemy.getBullets().begin(); it != enemy.getBullets().end();) {
|
|
||||||
if (ship->getSprite().getGlobalBounds().intersects(it->getSprite().getGlobalBounds())) {
|
|
||||||
// Kolizja wykryta
|
|
||||||
ship->takeDamage();
|
|
||||||
// Usuwanie pocisku
|
|
||||||
it = enemy.getBullets().erase(it);
|
|
||||||
} else {
|
|
||||||
++it; // Brak kolizji, przechodzimy do kolejnego pocisku
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto &bomberEnemy: BEnemies) {
|
|
||||||
for (auto it = bomberEnemy.getBullets().begin(); it != bomberEnemy.getBullets().end();) {
|
|
||||||
bool bulletDestroyed = false;
|
|
||||||
|
|
||||||
// Kolizja pocisku gracza z pociskiem Bombera
|
|
||||||
for (auto playerBulletIt = ship->getBullets().begin(); playerBulletIt != ship->getBullets().end();) {
|
|
||||||
if (playerBulletIt->getSprite().getGlobalBounds().intersects(it->getSprite().getGlobalBounds())) {
|
|
||||||
// Usuń pocisk Bombera i pocisk gracza
|
|
||||||
it = bomberEnemy.getBullets().erase(it);
|
|
||||||
playerBulletIt = ship->getBullets().erase(playerBulletIt);
|
|
||||||
bulletDestroyed = true;
|
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
++playerBulletIt;
|
++rocketIt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!meteorHit) {
|
||||||
// Kolizja rakiety gracza z pociskiem Bombera
|
++meteorIt;
|
||||||
if (!bulletDestroyed) {
|
|
||||||
for (auto rocketIt = ship->getRockets().begin(); rocketIt != ship->getRockets().end();) {
|
|
||||||
if (rocketIt->getSprite().getGlobalBounds().intersects(it->getSprite().getGlobalBounds())) {
|
|
||||||
// Usuń pocisk Bombera i rakietę gracza
|
|
||||||
it = bomberEnemy.getBullets().erase(it);
|
|
||||||
rocketIt = ship->getRockets().erase(rocketIt);
|
|
||||||
bulletDestroyed = true;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
++rocketIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Jeśli pocisk Bombera przetrwał dotychczasowe sprawdzenia, wykonaj inne działania
|
for (auto meteorIt = getMeteors().begin(); meteorIt != getMeteors().end(); ) {
|
||||||
if (!bulletDestroyed) {
|
bool meteorHit = false;
|
||||||
if (ship->getSprite().getGlobalBounds().intersects(it->getSprite().getGlobalBounds())) {
|
for (auto rocketIt = ship.getRockets().begin(); rocketIt != ship.getRockets().end(); ) {
|
||||||
// Kolizja pocisku Bombera z graczem
|
if (meteorIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
||||||
ship->takeDamage();
|
ship.getRockets().erase(rocketIt);
|
||||||
it = bomberEnemy.getBullets().erase(it);
|
meteorIt = getMeteors().erase(meteorIt);
|
||||||
|
meteorHit = true;
|
||||||
|
break;
|
||||||
} else {
|
} else {
|
||||||
++it;
|
++rocketIt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (!meteorHit) {
|
||||||
}
|
++meteorIt;
|
||||||
|
|
||||||
for (auto &wiazkowiec: WEnemies) {
|
|
||||||
wiazkowiec.update();
|
|
||||||
|
|
||||||
if (wiazkowiec.isShooting() && wiazkowiec.getBeam().isVisible()) {
|
|
||||||
if (ship->getSprite().getGlobalBounds().intersects(wiazkowiec.getBeam().getBounds())) {
|
|
||||||
ship->takeDamage(); // Gracz otrzymuje obrażenia
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window->draw(wiazkowiec.getSprite());
|
|
||||||
wiazkowiec.render(*window);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Usuwanie pocisków, które są poza ekranem srednio to dziala
|
|
||||||
for (auto enemyIt = enemies.begin(); enemyIt != enemies.end();) {
|
|
||||||
for (auto bulletIt = enemyIt->getBullets().begin(); bulletIt != enemyIt->getBullets().end();) {
|
|
||||||
if (bulletIt->isOutOfBounds()) {
|
|
||||||
bulletIt = enemyIt->getBullets().erase(bulletIt); // Usuwamy pocisk, który wyszedł poza ekran
|
|
||||||
} else {
|
|
||||||
++bulletIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
++enemyIt;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Kolizje między pociskami gracza a przeciwnikami
|
|
||||||
for (auto enemyIt = enemies.begin(); enemyIt != enemies.end();) {
|
|
||||||
bool hit = false;
|
|
||||||
for (auto bulletIt = ship->getBullets().begin(); bulletIt != ship->getBullets().end();) {
|
|
||||||
if (enemyIt->getSprite().getGlobalBounds().intersects(bulletIt->getSprite().getGlobalBounds())) {
|
|
||||||
bulletIt = ship->getBullets().erase(bulletIt);
|
|
||||||
enemyIt->takeDamage();
|
|
||||||
hit = true;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
++bulletIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hit && !enemyIt->isAlive()) {
|
|
||||||
enemyIt = enemies.erase(enemyIt);
|
|
||||||
} else {
|
|
||||||
++enemyIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto advancedIt = AEnemies.begin(); advancedIt != AEnemies.end();) {
|
|
||||||
bool hit = false;
|
|
||||||
for (auto bulletIt = ship->getBullets().begin(); bulletIt != ship->getBullets().end();) {
|
|
||||||
if (advancedIt->getSprite().getGlobalBounds().intersects(bulletIt->getSprite().getGlobalBounds())) {
|
|
||||||
bulletIt = ship->getBullets().erase(bulletIt);
|
|
||||||
advancedIt->takeDamage();
|
|
||||||
hit = true;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
++bulletIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hit && !advancedIt->isAlive()) {
|
|
||||||
advancedIt = AEnemies.erase(advancedIt); // Usunięcie przeciwnika AdvancedEnemy
|
|
||||||
} else {
|
|
||||||
++advancedIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto bomberIt = BEnemies.begin(); bomberIt != BEnemies.end();) {
|
|
||||||
bool hit = false;
|
|
||||||
for (auto bulletIt = ship->getBullets().begin(); bulletIt != ship->getBullets().end();) {
|
|
||||||
if (bomberIt->getSprite().getGlobalBounds().intersects(bulletIt->getSprite().getGlobalBounds())) {
|
|
||||||
bulletIt = ship->getBullets().erase(bulletIt);
|
|
||||||
bomberIt->takeDamage();
|
|
||||||
hit = true;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
++bulletIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hit && !bomberIt->isAlive()) {
|
|
||||||
bomberIt = BEnemies.erase(bomberIt); // Usunięcie przeciwnika Bomber
|
|
||||||
} else {
|
|
||||||
++bomberIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto kamikadzeIt = KEnemies.begin(); kamikadzeIt != KEnemies.end();) {
|
|
||||||
bool hit = false;
|
|
||||||
for (auto bulletIt = ship->getBullets().begin(); bulletIt != ship->getBullets().end();) {
|
|
||||||
if (kamikadzeIt->getSprite().getGlobalBounds().intersects(bulletIt->getSprite().getGlobalBounds())) {
|
|
||||||
bulletIt = ship->getBullets().erase(bulletIt);
|
|
||||||
kamikadzeIt->takeDamage();
|
|
||||||
hit = true;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
++bulletIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hit && !kamikadzeIt->isAlive()) {
|
|
||||||
kamikadzeIt = KEnemies.erase(kamikadzeIt); // Usunięcie przeciwnika Kamikadze
|
|
||||||
} else {
|
|
||||||
++kamikadzeIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto wiazkowiecIt = WEnemies.begin(); wiazkowiecIt != WEnemies.end();) {
|
|
||||||
bool hit = false;
|
|
||||||
for (auto bulletIt = ship->getBullets().begin(); bulletIt != ship->getBullets().end();) {
|
|
||||||
if (wiazkowiecIt->getSprite().getGlobalBounds().intersects(bulletIt->getSprite().getGlobalBounds())) {
|
|
||||||
bulletIt = ship->getBullets().erase(bulletIt);
|
|
||||||
wiazkowiecIt->takeDamage();
|
|
||||||
hit = true;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
++bulletIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hit && !wiazkowiecIt->isAlive()) {
|
|
||||||
wiazkowiecIt = WEnemies.erase(wiazkowiecIt); // Usunięcie przeciwnika Wiazkowiec
|
|
||||||
} else {
|
|
||||||
++wiazkowiecIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//oblsuga dla rakiety
|
|
||||||
for (auto enemyIt = enemies.begin(); enemyIt != enemies.end();) {
|
|
||||||
bool hit = false;
|
|
||||||
for (auto rocketIt = ship->getRockets().begin(); rocketIt != ship->getRockets().end();) {
|
|
||||||
if (enemyIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
|
||||||
rocketIt = ship->getRockets().erase(rocketIt);
|
|
||||||
enemyIt->takeDamage();
|
|
||||||
hit = true;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
++rocketIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hit && !enemyIt->isAlive()) {
|
|
||||||
enemyIt = enemies.erase(enemyIt);
|
|
||||||
} else {
|
|
||||||
++enemyIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto advancedIt = AEnemies.begin(); advancedIt != AEnemies.end();) {
|
|
||||||
bool hit = false;
|
|
||||||
for (auto rocketIt = ship->getRockets().begin(); rocketIt != ship->getRockets().end();) {
|
|
||||||
if (advancedIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
|
||||||
rocketIt = ship->getRockets().erase(rocketIt);
|
|
||||||
advancedIt->takeDamage();
|
|
||||||
hit = true;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
++rocketIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hit && !advancedIt->isAlive()) {
|
|
||||||
advancedIt = AEnemies.erase(advancedIt);
|
|
||||||
} else {
|
|
||||||
++advancedIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto bomberIt = BEnemies.begin(); bomberIt != BEnemies.end();) {
|
|
||||||
bool hit = false;
|
|
||||||
for (auto rocketIt = ship->getRockets().begin(); rocketIt != ship->getRockets().end();) {
|
|
||||||
if (bomberIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
|
||||||
rocketIt = ship->getRockets().erase(rocketIt);
|
|
||||||
bomberIt->takeDamage();
|
|
||||||
hit = true;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
++rocketIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hit && !bomberIt->isAlive()) {
|
|
||||||
bomberIt = BEnemies.erase(bomberIt);
|
|
||||||
} else {
|
|
||||||
++bomberIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto kamikadzeIt = KEnemies.begin(); kamikadzeIt != KEnemies.end();) {
|
|
||||||
bool hit = false;
|
|
||||||
for (auto rocketIt = ship->getRockets().begin(); rocketIt != ship->getRockets().end();) {
|
|
||||||
if (kamikadzeIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
|
||||||
rocketIt = ship->getRockets().erase(rocketIt);
|
|
||||||
kamikadzeIt->takeDamage();
|
|
||||||
hit = true;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
++rocketIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hit && !kamikadzeIt->isAlive()) {
|
|
||||||
kamikadzeIt = KEnemies.erase(kamikadzeIt);
|
|
||||||
} else {
|
|
||||||
++kamikadzeIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto wiazkowiecIt = WEnemies.begin(); wiazkowiecIt != WEnemies.end();) {
|
|
||||||
bool hit = false;
|
|
||||||
for (auto rocketIt = ship->getRockets().begin(); rocketIt != ship->getRockets().end();) {
|
|
||||||
if (wiazkowiecIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
|
||||||
rocketIt = ship->getRockets().erase(rocketIt);
|
|
||||||
wiazkowiecIt->takeDamage();
|
|
||||||
hit = true;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
++rocketIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hit && !wiazkowiecIt->isAlive()) {
|
|
||||||
wiazkowiecIt = WEnemies.erase(wiazkowiecIt);
|
|
||||||
} else {
|
|
||||||
++wiazkowiecIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Meteor-related niżej
|
// Meteor-related niżej
|
||||||
|
|
||||||
|
|
||||||
void Plansza::update_meteors() {
|
|
||||||
// usuwanie meteorów które wyleciały poza ekran
|
|
||||||
for (auto &meteor: meteors) {
|
|
||||||
if (meteor.getStatus()) {
|
|
||||||
meteors.erase(meteors.begin());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Plansza::spawn_meteor() {
|
void Plansza::spawn_meteor() {
|
||||||
if (spawnClock.getElapsedTime().asSeconds() > rand() % 10 + 1) { // randomowy spawn meteorytów od 10 do 1 sekundy
|
if (spawnClock.getElapsedTime().asSeconds() > rand() % 10 + 1) { // randomowy spawn meteorytów od 10 do 1 sekundy
|
||||||
if (meteors.size() < 5) { // jeśli jest mniej niż 5 meteorów na planszy
|
if (meteors.size() < 5) { // jeśli jest mniej niż 5 meteorów na planszy
|
||||||
if (rand() % 2 == 1) {
|
if(rand() % 2 == 1) {
|
||||||
meteors.emplace_back(RandomNumberGenerator::getRandomNumber(50, 499), -100, meteorTexture2);
|
meteors.emplace_back(RandomNumberGenerator::getRandomNumber(50,499), -100, meteorTexture2);
|
||||||
} else {
|
} else {
|
||||||
meteors.emplace_back(RandomNumberGenerator::getRandomNumber(50, 499), -100, meteorTexture1);
|
meteors.emplace_back(RandomNumberGenerator::getRandomNumber(50,499), -100, meteorTexture1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
spawnClock.restart();
|
spawnClock.restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plansza::spawn_player() {
|
void Plansza::update_meteors() {
|
||||||
ship = Player::getInstance(static_cast<int>(window->getSize().x) / 2, static_cast<int>(window->getSize().y) - 100, this->playerTexture);
|
// usuwanie meteorów które wyleciały poza ekran
|
||||||
ship->loadTexture();
|
for (auto& meteor : meteors) {
|
||||||
ship->setMovingSpeed(8);
|
if(meteor.getStatus()) {
|
||||||
ship->setFirerate(200);
|
meteors.erase(meteors.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plansza::spawn_enemy() {
|
|
||||||
if (enemySpawnClock.getElapsedTime().asSeconds() >= 10) { // Spawn co 10 sekund
|
|
||||||
int spawnX = RandomNumberGenerator::getRandomNumber(50, size.width - 50);
|
|
||||||
enemies.emplace_back(spawnX, -50, enemyTexture);
|
|
||||||
std::cout << "Spawned Basic Enemy at X: " << spawnX << std::endl;
|
|
||||||
enemySpawnClock.restart();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plansza::spawn_advanced_enemy() {
|
|
||||||
if (AenemySpawnClock.getElapsedTime().asSeconds() >= 20) { // Spawn co 10 sekund
|
|
||||||
int spawnX = RandomNumberGenerator::getRandomNumber(50, size.width - 50);
|
|
||||||
AEnemies.emplace_back(spawnX, -50, advancedEnemyTexture, enemyBulletTexture);
|
|
||||||
std::cout << "Spawned Advanced Enemy at X: " << spawnX << std::endl;
|
|
||||||
AenemySpawnClock.restart();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Plansza::spawn_bomber() {
|
|
||||||
if (BomberSpawnClock.getElapsedTime().asSeconds() >= 30) { // Spawn co 10 sekund
|
|
||||||
int spawnX = RandomNumberGenerator::getRandomNumber(50, size.width - 50);
|
|
||||||
Bomber bomber(spawnX, -50, BomberEnemyTexture, BombaTexture);
|
|
||||||
bomber.setPlanszaHeight(size.height, size.width); // Przekazanie wysokości i szerokości okna
|
|
||||||
BEnemies.push_back(bomber);
|
|
||||||
std::cout << "Spawned Bomber Enemy at X: " << spawnX << std::endl;
|
|
||||||
BomberSpawnClock.restart();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Plansza::spawn_kamikadze() {
|
|
||||||
if (KamikadzeSpawnClock.getElapsedTime().asSeconds() >= 40) { // Spawn co 10 sekund
|
|
||||||
int spawnX = RandomNumberGenerator::getRandomNumber(50, size.width - 50);
|
|
||||||
KEnemies.emplace_back(spawnX, -50, KamikadzeTexture);
|
|
||||||
std::cout << "Spawned Kamikadze Enemy at X: " << spawnX << std::endl;
|
|
||||||
KamikadzeSpawnClock.restart();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Plansza::spawn_wiazkowiec() {
|
|
||||||
if (WiazkowiecSpawnClock.getElapsedTime().asSeconds() >= 50) { // Spawn co 10 sekund
|
|
||||||
int spawnX = RandomNumberGenerator::getRandomNumber(50, size.width - 50);
|
|
||||||
Wiazkowiec wiazkowiec(spawnX, -50, WiazkowiecTexture);
|
|
||||||
wiazkowiec.setPlanszaHeight(size.height, size.width); // Przekazanie wysokości i szerokosci okna
|
|
||||||
WEnemies.push_back(wiazkowiec);
|
|
||||||
std::cout << "Spawned Wiazkowiec Enemy at X: " << spawnX << std::endl;
|
|
||||||
WiazkowiecSpawnClock.restart();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Size Plansza::getSize() {
|
Size Plansza::getSize() {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
@@ -681,15 +190,5 @@ std::vector<Meteor> &Plansza::getMeteors() {
|
|||||||
return meteors;
|
return meteors;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: naliczanie punktów za zabicie wrogów
|
|
||||||
void Plansza::update_score() {
|
|
||||||
if (scoreClock.getElapsedTime().asMilliseconds() > 500) {
|
|
||||||
score++;
|
|
||||||
scoreClock.restart();
|
|
||||||
}
|
|
||||||
|
|
||||||
sf::Text text(std::to_string(score), font, 24);
|
|
||||||
text.setFillColor(sf::Color::White);
|
|
||||||
text.setPosition(25, 25);
|
|
||||||
window->draw(text);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,25 +1,10 @@
|
|||||||
#include "../headers/Player.h"
|
#include "../headers/Player.h"
|
||||||
|
#include "../headers/Bullet.h"
|
||||||
|
|
||||||
#include <iostream>
|
Player::Player(int x, int y, std::string path) : Actor(x, y, path) {
|
||||||
#include <SFML/Graphics/Font.hpp>
|
|
||||||
#include <SFML/Graphics/RenderWindow.hpp>
|
|
||||||
#include <SFML/Graphics/Text.hpp>
|
|
||||||
|
|
||||||
Player::Player(int x, int y, const sf::Texture& texture) : Actor(x, y, texture) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Player* Player::getInstance(int x, int y, const sf::Texture& texture) {
|
|
||||||
if (player_ == nullptr) {
|
|
||||||
player_ = new Player(x, y, texture);
|
|
||||||
}
|
|
||||||
return player_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Player::loadTexture() {
|
|
||||||
bulletTexture.loadFromFile("../assets/img/bullets/bullet_pink.png");
|
bulletTexture.loadFromFile("../assets/img/bullets/bullet_pink.png");
|
||||||
rocketTexture.loadFromFile("../assets/img/rockets/Rocket_111.png");
|
rocketTexture.loadFromFile("../assets/img/rockets/Rocket_111.png");
|
||||||
}
|
};
|
||||||
|
|
||||||
void Player::shoot() {
|
void Player::shoot() {
|
||||||
auto now = std::chrono::steady_clock::now();
|
auto now = std::chrono::steady_clock::now();
|
||||||
@@ -29,7 +14,6 @@ void Player::shoot() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Player::alternate_shoot() {
|
void Player::alternate_shoot() {
|
||||||
auto now = std::chrono::steady_clock::now();
|
auto now = std::chrono::steady_clock::now();
|
||||||
if (std::chrono::duration_cast<std::chrono::milliseconds>(now - lastShotTime).count() >= firerate) {
|
if (std::chrono::duration_cast<std::chrono::milliseconds>(now - lastShotTime).count() >= firerate) {
|
||||||
@@ -38,47 +22,6 @@ void Player::alternate_shoot() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::update() {
|
|
||||||
// Wyłącz nieśmiertelność po określonym czasie
|
|
||||||
if (isImmortal && immortalityClock.getElapsedTime().asSeconds() >= immortalityDuration) {
|
|
||||||
isImmortal = false;
|
|
||||||
std::cout << "Immortality ended.\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Efekt migania podczas nieśmiertelności
|
|
||||||
if (isImmortal) {
|
|
||||||
if (static_cast<int>(immortalityClock.getElapsedTime().asMilliseconds() / 200) % 2 == 0) {
|
|
||||||
actorSprite.setColor(sf::Color(255, 255, 255, 128)); // Półprzezroczysty
|
|
||||||
} else {
|
|
||||||
actorSprite.setColor(sf::Color(255, 255, 255, 255)); // Normalny
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
actorSprite.setColor(sf::Color(255, 255, 255, 255)); // Normalny
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Player::takeDamage() {
|
|
||||||
if (!isImmortal) {
|
|
||||||
if (health > 0) {
|
|
||||||
health--;
|
|
||||||
std::cout << "Player hit! Remaining health: " << health << "\n";
|
|
||||||
isImmortal = true; // Aktywuj chwilową nieśmiertelność
|
|
||||||
immortalityClock.restart();
|
|
||||||
|
|
||||||
|
|
||||||
if (health <= 0) {
|
|
||||||
std::cout << "Player has been destroyed!\n";
|
|
||||||
std::cout << "You lost the game!\n";
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Player::isAlive() const {
|
|
||||||
return health > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Player::setFirerate(unsigned int firerate) {
|
void Player::setFirerate(unsigned int firerate) {
|
||||||
this->firerate = firerate;
|
this->firerate = firerate;
|
||||||
}
|
}
|
||||||
@@ -110,5 +53,3 @@ void Player::moveDown() {
|
|||||||
std::vector<Rocket> &Player::getRockets() {
|
std::vector<Rocket> &Player::getRockets() {
|
||||||
return rockets;
|
return rockets;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player* Player::player_ = nullptr;
|
|
||||||
|
|||||||
@@ -6,5 +6,4 @@ void Rocket::update() {
|
|||||||
if(position.y < -100) {
|
if(position.y < -100) {
|
||||||
outOfBounds = true;
|
outOfBounds = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,188 +0,0 @@
|
|||||||
#include "../headers/Wiazkowiec.h"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "../headers/Bullet.h"
|
|
||||||
#include <random>
|
|
||||||
|
|
||||||
Wiazkowiec::Wiazkowiec(int x, int y, const sf::Texture& texture) : Actor(x, y, texture), beam(0, 0, 50.f, 50.f, sf::Color::Red) {
|
|
||||||
actorSprite.setTexture(texture);
|
|
||||||
hp = 2; // 2 punkty życia
|
|
||||||
firerate = 5000; // Strzela co 10
|
|
||||||
moving_speed = 5.0f; // Prędkość
|
|
||||||
}
|
|
||||||
|
|
||||||
void Wiazkowiec::setPlanszaHeight(float height, float width) {
|
|
||||||
planszaHeight = height;
|
|
||||||
planszaWidth = width;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Wiazkowiec::spawnBeam() {
|
|
||||||
float beamX = position.x;
|
|
||||||
float beamY = position.y;
|
|
||||||
float beamWidth = 50.f;
|
|
||||||
float beamHeight = 0.f;
|
|
||||||
|
|
||||||
switch (direction) {
|
|
||||||
case DirectionW::Up:
|
|
||||||
beamHeight = position.y;
|
|
||||||
beamY -= beamHeight;
|
|
||||||
beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
|
||||||
break;
|
|
||||||
case DirectionW::Down:
|
|
||||||
beamHeight = planszaHeight - position.y;
|
|
||||||
beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
|
||||||
break;
|
|
||||||
case DirectionW::Left:
|
|
||||||
beamHeight = 50.f;
|
|
||||||
beamWidth = position.x;
|
|
||||||
beamX -= beamWidth;
|
|
||||||
beamY = position.y + (actorSprite.getGlobalBounds().height / 2) - 25.f;
|
|
||||||
beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
|
||||||
break;
|
|
||||||
case DirectionW::Right:
|
|
||||||
beamHeight = 50.f;
|
|
||||||
beamWidth = 800 - position.x;
|
|
||||||
beamY = position.y + (actorSprite.getGlobalBounds().height / 2) - 25.f;
|
|
||||||
beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
|
||||||
beam.setVisible(true);
|
|
||||||
|
|
||||||
shooting = true;
|
|
||||||
shootingClock.restart();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strzał wiązki
|
|
||||||
void Wiazkowiec::shoot() {
|
|
||||||
if (!shooting) {
|
|
||||||
spawnBeam();
|
|
||||||
std::cout << "Wiazkowiec shot a beam!" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Wiazkowiec::setRandomDirection() {
|
|
||||||
// Losowanie kierunku: 0 = Up, 1 = Down, 2 = Left, 3 = Right
|
|
||||||
int directionIndex = std::rand() % 4;
|
|
||||||
|
|
||||||
switch (directionIndex) {
|
|
||||||
case 0:
|
|
||||||
direction = DirectionW::Up;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
direction = DirectionW::Down;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
direction = DirectionW::Left;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
direction = DirectionW::Right;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Wiazkowiec::updateDirection() {
|
|
||||||
auto spriteBounds = actorSprite.getGlobalBounds(); // Pobierz rozmiar i pozycję sprite'a
|
|
||||||
|
|
||||||
// Kontrola górnej i dolnej krawędzi
|
|
||||||
if (position.y <= 0) {
|
|
||||||
direction = DirectionW::Down;
|
|
||||||
} else if (position.y + spriteBounds.height >= planszaHeight) {
|
|
||||||
direction = DirectionW::Up;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Kontrola lewej i prawej krawędzi
|
|
||||||
if (position.x <= 0) {
|
|
||||||
direction = DirectionW::Right;
|
|
||||||
} else if (position.x + spriteBounds.width >= planszaWidth) {
|
|
||||||
direction = DirectionW::Left;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Wiazkowiec::move(float deltaX, float deltaY) {
|
|
||||||
auto spriteBounds = actorSprite.getGlobalBounds(); // Rozmiar i pozycja sprite'a
|
|
||||||
|
|
||||||
// Zapobiegaj wyjściu poza poziome granice
|
|
||||||
if (position.x + deltaX < 0) {
|
|
||||||
deltaX = -position.x;
|
|
||||||
} else if (position.x + spriteBounds.width + deltaX > planszaWidth) {
|
|
||||||
deltaX = planszaWidth - (position.x + spriteBounds.width);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Zapobiegaj wyjściu poza pionowe granice
|
|
||||||
if (position.y + deltaY < 0) {
|
|
||||||
deltaY = -position.y;
|
|
||||||
} else if (position.y + spriteBounds.height + deltaY > planszaHeight) {
|
|
||||||
deltaY = planszaHeight - (position.y + spriteBounds.height);
|
|
||||||
}
|
|
||||||
|
|
||||||
actorSprite.move(deltaX, deltaY);
|
|
||||||
position.x += static_cast<int>(deltaX);
|
|
||||||
position.y += static_cast<int>(deltaY);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Wiazkowiec::moveLeft() { move(-moving_speed, 0.0f); }
|
|
||||||
void Wiazkowiec::moveRight() { move(moving_speed, 0.0f); }
|
|
||||||
void Wiazkowiec::moveUp() { move(0.0f, -moving_speed); }
|
|
||||||
void Wiazkowiec::moveDown() { move(0.0f, moving_speed); }
|
|
||||||
|
|
||||||
void Wiazkowiec::update() {
|
|
||||||
if (shooting) {
|
|
||||||
// Kontrola zakończenia strzału
|
|
||||||
if (shootingClock.getElapsedTime().asSeconds() >= beamDuration) {
|
|
||||||
beam.setVisible(false);
|
|
||||||
shooting = false;
|
|
||||||
setRandomDirection(); // Zmień kierunek po strzale
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
updateDirection();
|
|
||||||
|
|
||||||
switch (direction) {
|
|
||||||
case DirectionW::Up:
|
|
||||||
moveUp();
|
|
||||||
break;
|
|
||||||
case DirectionW::Down:
|
|
||||||
moveDown();
|
|
||||||
break;
|
|
||||||
case DirectionW::Left:
|
|
||||||
moveLeft();
|
|
||||||
break;
|
|
||||||
case DirectionW::Right:
|
|
||||||
moveRight();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shootClock.getElapsedTime().asSeconds() >= 3.0f) { // Co 3 sekundy
|
|
||||||
shoot();
|
|
||||||
shootClock.restart();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ustawianie widoczności wiązki podczas renderowania
|
|
||||||
void Wiazkowiec::render(sf::RenderWindow& window) {
|
|
||||||
if (beam.isVisible()) {
|
|
||||||
beam.render(window);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Wiazkowiec::isAlive() const {
|
|
||||||
return alive;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Wiazkowiec::takeDamage() {
|
|
||||||
if (--hp <= 0) {
|
|
||||||
alive = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Wiazkowiec::isShooting() const {
|
|
||||||
return shooting;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Beam& Wiazkowiec::getBeam() const {
|
|
||||||
return beam;
|
|
||||||
}
|
|
||||||