Compare commits
72 Commits
Strzaly-w-
...
ultimate
| Author | SHA1 | Date | |
|---|---|---|---|
| bafab8d75a | |||
| 92d5f66a91 | |||
| 622e814d1c | |||
| 0834460e82 | |||
| ff562d4d92 | |||
| c332b7e729 | |||
| 44f56e2035 | |||
| 898671a72a | |||
| 0ea80559e5 | |||
| 6a833f5698 | |||
| 2539892b71 | |||
| 17a1d3689b | |||
| 8b8bfc9aed | |||
| b833a21dbb | |||
| 2e02b17cc7 | |||
| f2426f5930 | |||
| 7d2b8bd9a2 | |||
| baced5f971 | |||
| 629b1279a9 | |||
| 7a808d46a6 | |||
| 67f396ae84 | |||
| 62808a9fbf | |||
| 5ad7cc9d1e | |||
| 4d2283d15e | |||
| 236ddd828d | |||
| b1b5858fb6 | |||
| 3d83a3a767 | |||
| 6b45443c75 | |||
| 3e2d37cf72 | |||
| c4c83382c3 | |||
| 0a5a26208a | |||
| 76203a8b29 | |||
| 36984b859f | |||
| 15a8d82176 | |||
| 5459b97e74 | |||
| 94eddb457f | |||
| 9432cd94fe | |||
| 34424da9d6 | |||
| 80a4b1b397 | |||
| fdf67f4bc2 | |||
| 8b4b25747e | |||
| 3f4a937257 | |||
| d87143d98b | |||
| 1298bab79a | |||
| 9929a5dd40 | |||
| 87399213b3 | |||
| f1dc19e795 | |||
| 168ba2e477 | |||
| 38fd71b8e6 | |||
| 1c0e5d0293 | |||
| c898aa0d81 | |||
| b257837d18 | |||
| 17c372fad9 | |||
| 0c706625d2 | |||
| c1a24a701b | |||
| 41945b3d88 | |||
| 2234e4d973 | |||
| da33fcc718 | |||
| 74c739a09e | |||
| 81b04bae0f | |||
| 77eb83c2c3 | |||
| a81cf284d0 | |||
| 13066709a7 | |||
| 44f4556fda | |||
| c655409596 | |||
| e2e44ff1ba | |||
| 71f8ebe285 | |||
| 2f9e0ba236 | |||
| 3b637508e1 | |||
| b6830c305b | |||
| 087a8d7672 | |||
| 0e1b53fc9b |
@@ -25,7 +25,30 @@ 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
|
||||||
|
headers/Heart.hpp
|
||||||
|
sources/Heart.cpp
|
||||||
|
headers/PowerUp.h
|
||||||
|
sources/PowerUp.cpp
|
||||||
|
headers/Debuff.h
|
||||||
|
sources/Debuff.cpp
|
||||||
|
sources/Boss.cpp
|
||||||
|
headers/Boss.h
|
||||||
|
)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
set(SFML_ROOT "${CMAKE_SOURCE_DIR}/lib/SFML")
|
set(SFML_ROOT "${CMAKE_SOURCE_DIR}/lib/SFML")
|
||||||
@@ -40,9 +63,9 @@ if(WIN32)
|
|||||||
target_link_libraries(LotoStatek ${SFML_LIBRARIES})
|
target_link_libraries(LotoStatek ${SFML_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
elseif(APPLE)
|
elseif(APPLE)
|
||||||
find_package(lib/SFML 2.6.2 COMPONENTS graphics window system REQUIRED)
|
find_package(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(lib/SFML 2.6.2 COMPONENTS graphics window system REQUIRED)
|
find_package(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()
|
||||||
12
README.md
@@ -1 +1,11 @@
|
|||||||
Tu będzie lotoł statek
|
The space-invaders type game created for university project.
|
||||||
|
The main character is a "Ship", with which you are fighting enemies that have different abilities, for example laser beams or "Kamikaze" that will try to explode at you.
|
||||||
|
Your character has only 3 HP that are showed in right upper corner.
|
||||||
|
|
||||||
|
|
||||||
|
There are 5 different types of enemies:
|
||||||
|
1. The simpliest one - just shoots you with one bullet
|
||||||
|
2. The advanced enemy - shoots you with the same bullet, but shooted 3 at the one piece of time
|
||||||
|
3. The "Kamikaze" will explode at you once reaches you, dealing 2 hp damage.
|
||||||
|
4. The Laser enemy will shoot you with laser beam both sideways and up and down direction, dealing 1 hp damage.
|
||||||
|
5. The bomber - will leave bombs all around map which will deal 1 hp damage once exploded.
|
||||||
BIN
assets/img/boss/Boss.png
Normal file
|
After Width: | Height: | Size: 58 KiB |
BIN
assets/img/bullets/bomba.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
assets/img/bullets/enemy_bullet.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
assets/img/bullets/old/bomba.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
assets/img/bullets/old/enemy_bullet.png
Normal file
|
After Width: | Height: | Size: 8.3 KiB |
BIN
assets/img/debuffs/BulletSpeedDBF.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
assets/img/debuffs/firerateDBF.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
assets/img/debuffs/movingSpeedDBF.png
Normal file
|
After Width: | Height: | Size: 6.4 KiB |
BIN
assets/img/enemy/advanced_enemy.png
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
assets/img/enemy/bomber.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
assets/img/enemy/enemy.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
assets/img/enemy/kamikadze.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
assets/img/enemy/old/advanced_enemy.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
assets/img/enemy/old/bomber.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
assets/img/enemy/old/enemy.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
assets/img/enemy/old/kamikadze.png
Normal file
|
After Width: | Height: | Size: 6.1 KiB |
BIN
assets/img/enemy/old/wiazkowiec.png
Normal file
|
After Width: | Height: | Size: 7.9 KiB |
BIN
assets/img/enemy/wiazkowiec.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
assets/img/hearts/heart.png
Normal file
|
After Width: | Height: | Size: 782 B |
BIN
assets/img/hearts/heart_gray.png
Normal file
|
After Width: | Height: | Size: 958 B |
BIN
assets/img/powerups/TripleShotPU.png
Normal file
|
After Width: | Height: | Size: 9.3 KiB |
BIN
assets/img/powerups/fireratePU.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
assets/img/powerups/movingSpeedPU.png
Normal file
|
After Width: | Height: | Size: 7.0 KiB |
BIN
assets/img/wiazka/laser.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 773 B |
BIN
assets/ship/nova.png
Normal file
|
After Width: | Height: | Size: 154 KiB |
BIN
assets/ship/pulsar.png
Normal file
|
After Width: | Height: | Size: 188 KiB |
BIN
assets/ship/zenith.png
Normal file
|
After Width: | Height: | Size: 221 KiB |
BIN
assets/sounds/explosion.mp3
Normal file
@@ -5,17 +5,18 @@
|
|||||||
#include "SFML/Graphics/Texture.hpp"
|
#include "SFML/Graphics/Texture.hpp"
|
||||||
#include "Bullet.h"
|
#include "Bullet.h"
|
||||||
#include "Position.h"
|
#include "Position.h"
|
||||||
|
#include "SFML/System/Clock.hpp"
|
||||||
|
|
||||||
|
|
||||||
class Actor {
|
class Actor {
|
||||||
public:
|
public:
|
||||||
Actor(int x, int y, std::string path);
|
Actor(int x, int y, const sf::Texture& texture);
|
||||||
|
virtual ~Actor() = default;
|
||||||
void loadTexture(std::string path);
|
|
||||||
|
|
||||||
sf::Sprite& getSprite();
|
sf::Sprite& getSprite();
|
||||||
|
unsigned int getHP();
|
||||||
Position getPosition();
|
Position getPosition();
|
||||||
|
std::vector<Bullet>& getBullets();
|
||||||
|
|
||||||
virtual void move(float deltaX, float deltaY) = 0;
|
virtual void move(float deltaX, float deltaY) = 0;
|
||||||
virtual void moveLeft() = 0;
|
virtual void moveLeft() = 0;
|
||||||
@@ -24,23 +25,23 @@ public:
|
|||||||
virtual void moveDown() = 0;
|
virtual void moveDown() = 0;
|
||||||
virtual void shoot() = 0;
|
virtual void shoot() = 0;
|
||||||
|
|
||||||
std::vector<Bullet>& getBullets();
|
|
||||||
|
|
||||||
void updateBullets();
|
void updateBullets();
|
||||||
|
|
||||||
void setMovingSpeed(float speed);
|
void setMovingSpeed(float speed);
|
||||||
|
void dealDamage();
|
||||||
|
void healUP();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Position position;
|
||||||
sf::Sprite actorSprite;
|
sf::Sprite actorSprite;
|
||||||
sf::Texture actorTexture;
|
sf::Texture actorTexture;
|
||||||
sf::Texture bulletTextureLeft;
|
sf::Texture bulletTexture;
|
||||||
sf::Texture bulletTextureRight;
|
sf::Texture rocketTexture;
|
||||||
Position position;
|
std::vector<Bullet> bullets;
|
||||||
unsigned int hp;
|
sf::Clock damageDealClock;
|
||||||
|
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
|
||||||
|
|||||||
37
headers/AdvancedEnemy.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#ifndef ADVANCED_ENEMY_H
|
||||||
|
#define ADVANCED_ENEMY_H
|
||||||
|
|
||||||
|
#include "Enemy.h"
|
||||||
|
|
||||||
|
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
|
||||||
18
headers/Beam.h
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef LOTOSTATEK_BEAM_H
|
||||||
|
#define LOTOSTATEK_BEAM_H
|
||||||
|
|
||||||
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
|
class Beam {
|
||||||
|
public:
|
||||||
|
Beam() = default;
|
||||||
|
Beam(int x, int y, const sf::Texture &texture);
|
||||||
|
|
||||||
|
sf::Sprite getSprite();
|
||||||
|
|
||||||
|
void setRotation(float angle);
|
||||||
|
private:
|
||||||
|
sf::Sprite beamSprite;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LOTOSTATEK_BEAM_H
|
||||||
45
headers/Bomber.h
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
//
|
||||||
|
// 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
|
||||||
72
headers/Boss.h
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
#ifndef BOSS_H
|
||||||
|
#define BOSS_H
|
||||||
|
|
||||||
|
#include "Actor.h"
|
||||||
|
#include "Bullet.h"
|
||||||
|
#include "Beam.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
|
enum class BossDirection {
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
Left,
|
||||||
|
Right
|
||||||
|
};
|
||||||
|
|
||||||
|
class Boss : public Actor {
|
||||||
|
public:
|
||||||
|
Boss(int x, int y, const sf::Texture &bossTexture, const sf::Texture &bulletTexture, sf::Texture BombaTexture,
|
||||||
|
sf::RenderWindow *window);
|
||||||
|
|
||||||
|
void setPlanszaHeight(int height, int width);
|
||||||
|
|
||||||
|
void moveLeft() override;
|
||||||
|
void moveRight() override;
|
||||||
|
void moveUp() override;
|
||||||
|
void moveDown() override;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void shoot() override;
|
||||||
|
void dropBomb();
|
||||||
|
void shootLaser();
|
||||||
|
void move(float deltaX, float deltaY) override;
|
||||||
|
void update();
|
||||||
|
void takeDamage();
|
||||||
|
bool isAlive() const;
|
||||||
|
std::vector<Bullet>& getBullets() { return bullets; }
|
||||||
|
std::vector<Bullet>& getBombs() { return bombs; }
|
||||||
|
bool isShooting() const { return laserBeam != nullptr; }
|
||||||
|
Beam* getBeam() const { return laserBeam; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
float movementSpeed = 5.5f;
|
||||||
|
BossDirection direction = BossDirection::Down;
|
||||||
|
|
||||||
|
sf::Clock shootClock;
|
||||||
|
sf::Clock bombClock;
|
||||||
|
sf::Clock laserClock;
|
||||||
|
sf::Clock directionClock;
|
||||||
|
sf::Clock beamDurationClock;
|
||||||
|
float beamDuration = 1.0f;
|
||||||
|
|
||||||
|
sf::Texture bulletTexture;
|
||||||
|
sf::Texture BombaTexture;
|
||||||
|
sf::Texture beamTexture;
|
||||||
|
sf::RenderWindow* window;
|
||||||
|
Beam* laserBeam = nullptr;
|
||||||
|
|
||||||
|
std::vector<Bullet> bullets;
|
||||||
|
std::vector<Bullet> bombs;
|
||||||
|
|
||||||
|
int planszaHeight = 800;
|
||||||
|
int planszaWidth = 600;
|
||||||
|
|
||||||
|
bool isStationary = false;
|
||||||
|
|
||||||
|
void setRandomDirection();
|
||||||
|
void handleBounds();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BOSS_H
|
||||||
@@ -2,11 +2,13 @@
|
|||||||
#define LOTOSTATEK_BULLET_H
|
#define LOTOSTATEK_BULLET_H
|
||||||
|
|
||||||
#include "Projectile.h"
|
#include "Projectile.h"
|
||||||
#include "SFML/Graphics/Texture.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);
|
||||||
|
|
||||||
|
Bullet(float x, float y, sf::Texture &texture, float speed);
|
||||||
|
|
||||||
void update() override;
|
void update() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
24
headers/Debuff.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#ifndef DEBUFF_H
|
||||||
|
#define DEBUFF_H
|
||||||
|
#include "ObjectItem.hpp"
|
||||||
|
|
||||||
|
class Debuff : public ObjectItem {
|
||||||
|
public:
|
||||||
|
enum Type {
|
||||||
|
movingSpeedDbf,
|
||||||
|
firerateDbf,
|
||||||
|
bulletSpeedDbf
|
||||||
|
};
|
||||||
|
Debuff(float x, float y, sf::Texture &texture, Type type);
|
||||||
|
|
||||||
|
void update() override;
|
||||||
|
|
||||||
|
Type getType() const {
|
||||||
|
return type_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Type type_;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //DEBUFF_H
|
||||||
39
headers/Enemy.h
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#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
|
||||||
13
headers/Heart.hpp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#ifndef LOTOSTATEK_HEART_HPP
|
||||||
|
#define LOTOSTATEK_HEART_HPP
|
||||||
|
|
||||||
|
#include "SFML/Graphics/Texture.hpp"
|
||||||
|
#include "ObjectItem.hpp"
|
||||||
|
|
||||||
|
class Heart : public ObjectItem {
|
||||||
|
public:
|
||||||
|
Heart(float x, float y, sf::Texture &texture_);
|
||||||
|
void update() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //LOTOSTATEK_HEART_HPP
|
||||||
46
headers/Kamikadze.h
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
#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,22 +4,12 @@
|
|||||||
#include "SFML/Graphics/Texture.hpp"
|
#include "SFML/Graphics/Texture.hpp"
|
||||||
#include "SFML/Graphics/Sprite.hpp"
|
#include "SFML/Graphics/Sprite.hpp"
|
||||||
#include "Position.h"
|
#include "Position.h"
|
||||||
|
#include "ObjectItem.hpp"
|
||||||
|
|
||||||
class Meteor {
|
class Meteor : public ObjectItem {
|
||||||
public:
|
public:
|
||||||
Meteor(float x, float y, sf::Texture &texture);
|
Meteor(float x, float y, sf::Texture &texture_);
|
||||||
sf::Sprite &getSprite();
|
|
||||||
bool getStatus();
|
|
||||||
void update();
|
void update();
|
||||||
// ~Meteor();
|
|
||||||
private:
|
|
||||||
sf::Texture meteorTexture;
|
|
||||||
sf::Sprite meteorSprite;
|
|
||||||
Position meteorPosition;
|
|
||||||
float meteorRotationSpeed;
|
|
||||||
float meteorSpeed;
|
|
||||||
bool outOfBounds;
|
|
||||||
static unsigned int counter;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
25
headers/ObjectItem.hpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef LOTOSTATEK_OBJECTITEM_HPP
|
||||||
|
#define LOTOSTATEK_OBJECTITEM_HPP
|
||||||
|
|
||||||
|
#include "SFML/Graphics/Sprite.hpp"
|
||||||
|
#include "Position.h"
|
||||||
|
#include "SFML/Graphics/Texture.hpp"
|
||||||
|
|
||||||
|
class ObjectItem {
|
||||||
|
public:
|
||||||
|
virtual ~ObjectItem() = default;
|
||||||
|
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,36 +1,156 @@
|
|||||||
#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 "Heart.hpp"
|
||||||
|
#include "PowerUp.h"
|
||||||
|
#include "Debuff.h"
|
||||||
|
#include "Size.h"
|
||||||
|
#include "Boss.h"
|
||||||
|
|
||||||
|
enum ships{
|
||||||
|
nova,
|
||||||
|
pulsar,
|
||||||
|
zenith,
|
||||||
|
none
|
||||||
|
};
|
||||||
|
|
||||||
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, ships selectedShip);
|
||||||
Size getSize();
|
Size getSize();
|
||||||
std::vector<Meteor> &getMeteors();
|
std::vector<Meteor> &getMeteors();
|
||||||
void spawn_meteor();
|
void spawn_meteor();
|
||||||
|
void spawn_hearts();
|
||||||
|
void spawn_power_up();
|
||||||
|
void spawn_debuff();
|
||||||
void update_meteors();
|
void update_meteors();
|
||||||
|
void update_hearts();
|
||||||
|
void update_power_ups();
|
||||||
|
void update_debuffs();
|
||||||
|
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
|
void update_score();
|
||||||
|
|
||||||
|
void check_PowerUp_collisions();
|
||||||
|
void check_Heart_collisions();
|
||||||
|
void check_Meteor_collisions();
|
||||||
|
void check_Debuff_collisions();
|
||||||
|
|
||||||
|
void handleUltimate();
|
||||||
|
|
||||||
|
void spawn_player();
|
||||||
|
void spawn_enemy();
|
||||||
|
void spawn_advanced_enemy();
|
||||||
|
void spawn_wiazkowiec();
|
||||||
|
void spawn_boss();
|
||||||
|
void spawn_bomber();
|
||||||
|
void spawn_kamikadze();
|
||||||
|
~Plansza() {
|
||||||
|
delete ship;
|
||||||
|
delete boss;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ships selectedShip;
|
||||||
|
static unsigned int score;
|
||||||
|
static unsigned int ultimateCounter;
|
||||||
|
sf::Font font;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Size size;
|
|
||||||
Background background;
|
Background background;
|
||||||
Player ship;
|
|
||||||
AudioManager audioManager;
|
AudioManager audioManager;
|
||||||
|
Player *ship;
|
||||||
|
Size size;
|
||||||
|
sf::RenderWindow *window;
|
||||||
|
// Timers
|
||||||
|
sf::Clock movingSpeedPUTimer;
|
||||||
|
sf::Clock fireratePUTimer;
|
||||||
|
sf::Clock tripleShotPUTimer;
|
||||||
|
sf::Clock movingSpeedDebuffTimer;
|
||||||
|
sf::Clock firerateDebuffTimer;
|
||||||
|
sf::Clock bulletSpeedDebuffTimer;
|
||||||
|
|
||||||
|
// Zegary
|
||||||
|
sf::Clock meteorSpawnClock;
|
||||||
|
sf::Clock heartSpawnClock;
|
||||||
|
sf::Clock powerUpSpawnClock;
|
||||||
|
sf::Clock debuffSpawnClock;
|
||||||
|
sf::Clock ultimateClock;
|
||||||
|
sf::Clock scoreClock;
|
||||||
|
sf::Clock shooterSpawnClock;
|
||||||
|
sf::Clock enemySpawnClock;
|
||||||
|
sf::Clock AenemySpawnClock;
|
||||||
|
sf::Clock BomberSpawnClock;
|
||||||
|
sf::Clock KamikadzeSpawnClock;
|
||||||
|
sf::Clock WiazkowiecSpawnClock;
|
||||||
|
|
||||||
|
//Textury
|
||||||
|
sf::Texture playerTexture;
|
||||||
|
sf::Texture playerBulletTexture;
|
||||||
|
sf::Texture playerRocketTexture;
|
||||||
|
sf::Texture enemyTexture;
|
||||||
|
sf::Texture enemyBulletTexture;
|
||||||
|
sf::Texture advancedEnemyTexture;
|
||||||
|
sf::Texture BomberEnemyTexture;
|
||||||
|
sf::Texture BombaTexture;
|
||||||
|
sf::Texture BossTexture;
|
||||||
|
sf::Texture KamikadzeTexture;
|
||||||
|
sf::Texture WiazkowiecTexture;
|
||||||
|
sf::Texture WiazkaTexture;
|
||||||
sf::Texture meteorTexture1;
|
sf::Texture meteorTexture1;
|
||||||
sf::Texture meteorTexture2;
|
sf::Texture meteorTexture2;
|
||||||
sf::Clock spawnClock;
|
sf::Texture heartTexture;
|
||||||
|
sf::Texture heartTextureGray;
|
||||||
|
sf::Texture movingSpeedPowerUpTexture;
|
||||||
|
sf::Texture fireratePowerUpTexture;
|
||||||
|
sf::Texture tripleShotPowerUpTexture;
|
||||||
|
sf::Texture movingSpeedDebuffTexture;
|
||||||
|
sf::Texture firerateDebuffTexture;
|
||||||
|
sf::Texture bulletSpeedDebuffTexture;
|
||||||
|
|
||||||
|
// Tablice
|
||||||
|
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;
|
||||||
sf::RenderWindow *window;
|
std::vector<Heart> hearts;
|
||||||
|
std::vector<sf::Sprite> heartStats;
|
||||||
|
std::vector<PowerUp> powerUps;
|
||||||
|
std::vector<Debuff> debuffs;
|
||||||
|
|
||||||
|
// Zmienne prymitywne
|
||||||
|
Boss* boss = nullptr; // Wskaźnik na bossa
|
||||||
|
sf::Clock bossSpawnClock; // Zegar do spawnowania bossa
|
||||||
|
unsigned int nextBossScoreThreshold = 1000; // Próg punktowy dla spawnu bossa
|
||||||
|
bool bossSpawned = false; // Flaga informująca, czy boss został już zespawnowany
|
||||||
|
bool gameOver = false;
|
||||||
|
|
||||||
|
// Używane do powerup i debuff flagi
|
||||||
|
struct {
|
||||||
|
bool movingSpeed = false;
|
||||||
|
bool firerate = false;
|
||||||
|
bool tripleShot = false;
|
||||||
|
} powerUpCollected;
|
||||||
|
struct {
|
||||||
|
bool movingSpeed = false;
|
||||||
|
bool firerate = false;
|
||||||
|
bool bulletSpeed = false;
|
||||||
|
} debuffCollected;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //PLANSZA_H
|
#endif //PLANSZA_H
|
||||||
|
|||||||
@@ -3,26 +3,57 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <SFML/System/Clock.hpp>
|
||||||
|
|
||||||
#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(int x, int y, std::string path);
|
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 shoot() override;
|
||||||
void alternate_shoot();
|
void alternate_shoot();
|
||||||
|
void ultimate_shoot();
|
||||||
void setFirerate(unsigned int firerate);
|
void setFirerate(unsigned int firerate);
|
||||||
void move(float deltaX, float deltaY) override;
|
void move(float deltaX, float deltaY) override;
|
||||||
void moveLeft() override;
|
void moveLeft() override;
|
||||||
void moveRight() override;
|
void moveRight() override;
|
||||||
void moveUp() override;
|
void moveUp() override;
|
||||||
void moveDown() override;
|
void moveDown() override;
|
||||||
|
void takeDamage();
|
||||||
|
void setTripleShot(bool toogle);
|
||||||
|
|
||||||
|
void setBulletSpeed(float speed);
|
||||||
|
bool getUltimateStatus();
|
||||||
|
void update();
|
||||||
|
|
||||||
std::vector<Rocket>& getRockets();
|
std::vector<Rocket>& getRockets();
|
||||||
|
|
||||||
|
void loadTexture();
|
||||||
|
|
||||||
|
void setUltimateStatus(bool status);
|
||||||
|
|
||||||
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::Color originalColor;
|
||||||
|
sf::Clock immortalityClock; // Zegar kontrolujący czas nieśmiertelności
|
||||||
|
float immortalityDuration = 1.5f; // Czas trwania nieśmiertelności w sec
|
||||||
|
float bulletSpeed = 10.0f; // prędkość pocisku
|
||||||
|
bool isImmortal = false; // flaga na immortal
|
||||||
|
bool tripleShot = false; // flaga na potrójny strzał
|
||||||
|
bool ultimateShootActive = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,4 +6,14 @@ struct Position {
|
|||||||
int y;
|
int y;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct PositionU {
|
||||||
|
unsigned int x;
|
||||||
|
unsigned int y;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PositionF {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
};
|
||||||
|
|
||||||
#endif //LOTOSTATEK_POSITION_H
|
#endif //LOTOSTATEK_POSITION_H
|
||||||
|
|||||||
25
headers/PowerUp.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef POWERUP_H
|
||||||
|
#define POWERUP_H
|
||||||
|
#include "ObjectItem.hpp"
|
||||||
|
|
||||||
|
class PowerUp : public ObjectItem {
|
||||||
|
public:
|
||||||
|
enum Type {
|
||||||
|
movingSpeedUp,
|
||||||
|
firerateUp,
|
||||||
|
tripleShotUp
|
||||||
|
};
|
||||||
|
|
||||||
|
PowerUp(float x, float y, sf::Texture &texture, Type type);
|
||||||
|
|
||||||
|
void update() override;
|
||||||
|
|
||||||
|
Type getType() const {
|
||||||
|
return type_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Type type_;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //POWERUP_H
|
||||||
@@ -7,6 +7,7 @@ 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;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
59
headers/Wiazkowiec.h
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
#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, sf::RenderWindow *window);
|
||||||
|
|
||||||
|
void move(float deltaX, float deltaY) override;
|
||||||
|
void moveLeft() override;
|
||||||
|
void moveRight() override;
|
||||||
|
void moveUp() override;
|
||||||
|
void moveDown() override;
|
||||||
|
|
||||||
|
void takeDamage();
|
||||||
|
|
||||||
|
void setRandomDirection();
|
||||||
|
void checkIfBeamShootOutOfBounds();
|
||||||
|
|
||||||
|
void update();
|
||||||
|
void shoot() override;
|
||||||
|
void render(sf::RenderWindow &window);
|
||||||
|
|
||||||
|
bool isAlive() const;
|
||||||
|
bool isShooting() const;
|
||||||
|
|
||||||
|
void setPlanszaHeight(int height, int width);
|
||||||
|
Beam* getBeam() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
sf::Texture WiazkaTexture;
|
||||||
|
sf::Texture beamTexture;
|
||||||
|
sf::Clock shootClock;
|
||||||
|
sf::Clock shootingClock;
|
||||||
|
DirectionW direction = DirectionW::Down;
|
||||||
|
|
||||||
|
Beam *beam; // wskaźnik na wiązkę
|
||||||
|
sf::RenderWindow *window_ptr;
|
||||||
|
|
||||||
|
void spawnBeam(); // Tworzy wiązkę
|
||||||
|
|
||||||
|
int planszaHeight = 800;
|
||||||
|
int planszaWidth = 600;
|
||||||
|
float beamDuration = 1.0f;
|
||||||
|
float movementSpeed = 2.0f;
|
||||||
|
bool shooting = false;
|
||||||
|
bool alive = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //WIAZKOWIEC_H
|
||||||
186
main.cpp
@@ -3,8 +3,13 @@
|
|||||||
|
|
||||||
#include "headers/Plansza.h"
|
#include "headers/Plansza.h"
|
||||||
|
|
||||||
int main()
|
ships selectedShip = none;
|
||||||
{
|
|
||||||
|
void menu();
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
menu();
|
||||||
|
|
||||||
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);
|
||||||
@@ -14,7 +19,9 @@ 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);
|
bool isPaused = false;
|
||||||
|
|
||||||
|
Plansza plansza(mainWindow.getSize().y, mainWindow.getSize().x, &mainWindow, selectedShip);
|
||||||
|
|
||||||
while (mainWindow.isOpen()) {
|
while (mainWindow.isOpen()) {
|
||||||
mainWindow.clear();
|
mainWindow.clear();
|
||||||
@@ -22,14 +29,179 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
plansza.update();
|
|
||||||
|
|
||||||
mainWindow.display();
|
// Obsługa pauzy
|
||||||
|
if (event.key.code == sf::Keyboard::P) {
|
||||||
|
isPaused = !isPaused;
|
||||||
|
|
||||||
|
sf::RectangleShape bg(sf::Vector2f(mainWindow.getSize().x, mainWindow.getSize().y));
|
||||||
|
bg.setFillColor(sf::Color(0,0,0,100));
|
||||||
|
sf::Text text("PAUZA", plansza.font, 50);
|
||||||
|
text.setOrigin(text.getLocalBounds().getSize().x/2, text.getLocalBounds().getSize().y/2);
|
||||||
|
text.setFillColor(sf::Color::White);
|
||||||
|
text.setPosition(mainWindow.getSize().x/2, mainWindow.getSize().y/2);
|
||||||
|
plansza.update();
|
||||||
|
mainWindow.draw(bg);
|
||||||
|
mainWindow.draw(text);
|
||||||
|
mainWindow.display();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isPaused) { // jesli nie spauzowane to graj
|
||||||
|
plansza.update();
|
||||||
|
mainWindow.display();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void menu() {
|
||||||
|
sf::RenderWindow menuWindow(sf::VideoMode(800, 400), "LotoStatek->Menu");
|
||||||
|
// Ustawienia ikonki okna
|
||||||
|
sf::Image icon;
|
||||||
|
icon.loadFromFile("../assets/img/icon/ikonka.png");
|
||||||
|
menuWindow.setIcon(128, 128, icon.getPixelsPtr());
|
||||||
|
|
||||||
|
// start button
|
||||||
|
sf::RectangleShape startButton(sf::Vector2f(140, 50));
|
||||||
|
startButton.setPosition(50, 20);
|
||||||
|
startButton.setFillColor(sf::Color::White);
|
||||||
|
|
||||||
|
|
||||||
|
sf::Font font;
|
||||||
|
if (!font.loadFromFile("../assets/fonts/arial.ttf")) {
|
||||||
|
std::cerr << "Nie można załadować czcionki\n";
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
// tekst dla start button
|
||||||
|
sf::Text startText("Start", font, 24);
|
||||||
|
startText.setFillColor(sf::Color::Black);
|
||||||
|
startText.setPosition(startButton.getSize().x / 2 + 20, startButton.getSize().y / 2 + 5);
|
||||||
|
|
||||||
|
|
||||||
|
// exit button
|
||||||
|
sf::RectangleShape exitButton(sf::Vector2f(140, 50));
|
||||||
|
exitButton.setPosition(600, 20);
|
||||||
|
exitButton.setFillColor(sf::Color::White);
|
||||||
|
|
||||||
|
sf::Text exitText("Exit", font, 24);
|
||||||
|
exitText.setFillColor(sf::Color::Black);
|
||||||
|
exitText.setPosition(exitButton.getPosition().x + 45, exitButton.getPosition().y + 10);
|
||||||
|
|
||||||
|
|
||||||
|
sf::Texture pulsarTexture;
|
||||||
|
pulsarTexture.loadFromFile("../assets/ship/pulsar.png");
|
||||||
|
sf::Sprite pulsarSprite(pulsarTexture);
|
||||||
|
pulsarSprite.setPosition(50, 200);
|
||||||
|
pulsarSprite.setScale(0.25f, 0.25f);
|
||||||
|
|
||||||
|
sf::Texture novaTexture;
|
||||||
|
novaTexture.loadFromFile("../assets/ship/nova.png");
|
||||||
|
sf::Sprite novaSprite(novaTexture);
|
||||||
|
novaSprite.setPosition(330, 200);
|
||||||
|
novaSprite.setScale(0.25f, 0.25f);
|
||||||
|
|
||||||
|
sf::Texture zenithTexture;
|
||||||
|
zenithTexture.loadFromFile("../assets/ship/zenith.png");
|
||||||
|
sf::Sprite zenithSprite(zenithTexture);
|
||||||
|
zenithSprite.setPosition(600, 200);
|
||||||
|
zenithSprite.setScale(0.25f, 0.25f);
|
||||||
|
|
||||||
|
sf::RectangleShape pulsarBorder(sf::Vector2f(pulsarSprite.getGlobalBounds().width + 4,
|
||||||
|
pulsarSprite.getGlobalBounds().height + 4));
|
||||||
|
pulsarBorder.setPosition(pulsarSprite.getPosition().x - 2, pulsarSprite.getPosition().y - 2);
|
||||||
|
pulsarBorder.setFillColor(sf::Color::Transparent);
|
||||||
|
pulsarBorder.setOutlineThickness(2);
|
||||||
|
pulsarBorder.setOutlineColor(sf::Color::Transparent);
|
||||||
|
|
||||||
|
sf::RectangleShape novaBorder(sf::Vector2f(novaSprite.getGlobalBounds().width + 4,
|
||||||
|
novaSprite.getGlobalBounds().height + 4));
|
||||||
|
novaBorder.setPosition(novaSprite.getPosition().x - 2, novaSprite.getPosition().y - 2);
|
||||||
|
novaBorder.setFillColor(sf::Color::Transparent);
|
||||||
|
novaBorder.setOutlineThickness(2);
|
||||||
|
novaBorder.setOutlineColor(sf::Color::Transparent);
|
||||||
|
|
||||||
|
sf::RectangleShape zenithBorder(sf::Vector2f(zenithSprite.getGlobalBounds().width + 4,
|
||||||
|
zenithSprite.getGlobalBounds().height + 4));
|
||||||
|
zenithBorder.setPosition(zenithSprite.getPosition().x - 2, zenithSprite.getPosition().y - 2);
|
||||||
|
zenithBorder.setFillColor(sf::Color::Transparent);
|
||||||
|
zenithBorder.setOutlineThickness(2);
|
||||||
|
zenithBorder.setOutlineColor(sf::Color::Transparent);
|
||||||
|
|
||||||
|
while (menuWindow.isOpen()) {
|
||||||
|
sf::Event event{};
|
||||||
|
while (menuWindow.pollEvent(event)) {
|
||||||
|
if (event.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
|
||||||
|
menuWindow.close();
|
||||||
|
exit(-2);
|
||||||
|
}
|
||||||
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Enter)) {
|
||||||
|
menuWindow.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.type == sf::Event::MouseButtonPressed) {
|
||||||
|
if (event.mouseButton.button == sf::Mouse::Left) {
|
||||||
|
sf::Vector2i mousePos = sf::Mouse::getPosition(menuWindow);
|
||||||
|
if (startButton.getGlobalBounds().contains(static_cast<sf::Vector2f>(mousePos))) {
|
||||||
|
std::cout << "Przycisk Start zostal kliknięty\n";
|
||||||
|
menuWindow.close();
|
||||||
|
}
|
||||||
|
if (exitButton.getGlobalBounds().contains(static_cast<sf::Vector2f>(mousePos))) {
|
||||||
|
std::cout << "Przycisk Exit zostal kliknięty\n";
|
||||||
|
menuWindow.close();
|
||||||
|
exit(-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pulsarSprite.getGlobalBounds().contains(static_cast<sf::Vector2f>(mousePos))) {
|
||||||
|
pulsarBorder.setOutlineColor(sf::Color::White);
|
||||||
|
selectedShip = pulsar;
|
||||||
|
} else {
|
||||||
|
pulsarBorder.setOutlineColor(sf::Color::Transparent);
|
||||||
|
}
|
||||||
|
if (novaSprite.getGlobalBounds().contains(static_cast<sf::Vector2f>(mousePos))) {
|
||||||
|
novaBorder.setOutlineColor(sf::Color::White);
|
||||||
|
selectedShip = nova;
|
||||||
|
} else {
|
||||||
|
novaBorder.setOutlineColor(sf::Color::Transparent);
|
||||||
|
}
|
||||||
|
if (zenithSprite.getGlobalBounds().contains(static_cast<sf::Vector2f>(mousePos))) {
|
||||||
|
zenithBorder.setOutlineColor(sf::Color::White);
|
||||||
|
selectedShip = zenith;
|
||||||
|
} else {
|
||||||
|
zenithBorder.setOutlineColor(sf::Color::Transparent);
|
||||||
|
}
|
||||||
|
if (!pulsarSprite.getGlobalBounds().contains(static_cast<sf::Vector2f>(mousePos)) &&
|
||||||
|
!novaSprite.getGlobalBounds().contains(static_cast<sf::Vector2f>(mousePos)) &&
|
||||||
|
!zenithSprite.getGlobalBounds().contains(static_cast<sf::Vector2f>(mousePos)) &&
|
||||||
|
!startButton.getGlobalBounds().contains(static_cast<sf::Vector2f>(mousePos)) &&
|
||||||
|
!exitButton.getGlobalBounds().contains(static_cast<sf::Vector2f>(mousePos))) {
|
||||||
|
selectedShip = none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
menuWindow.clear();
|
||||||
|
|
||||||
|
menuWindow.draw(startButton);
|
||||||
|
menuWindow.draw(startText);
|
||||||
|
|
||||||
|
menuWindow.draw(exitButton);
|
||||||
|
menuWindow.draw(exitText);
|
||||||
|
|
||||||
|
menuWindow.draw(pulsarSprite);
|
||||||
|
menuWindow.draw(novaSprite);
|
||||||
|
menuWindow.draw(zenithSprite);
|
||||||
|
|
||||||
|
menuWindow.draw(pulsarBorder);
|
||||||
|
menuWindow.draw(novaBorder);
|
||||||
|
menuWindow.draw(zenithBorder);
|
||||||
|
|
||||||
|
menuWindow.display();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,22 +1,19 @@
|
|||||||
#include "../headers/Actor.h"
|
#include "../headers/Actor.h"
|
||||||
|
|
||||||
Actor::Actor(int x, int y, std::string path) {
|
#include <iostream>
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,18 +21,41 @@ Position Actor::getPosition() {
|
|||||||
return {position.x, position.y};
|
return {position.x, position.y};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int Actor::getHP() {
|
||||||
|
return hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Actor::dealDamage() {
|
||||||
|
if(damageDealClock.getElapsedTime().asSeconds() > 1.5) {
|
||||||
|
if(hp > 0) {
|
||||||
|
hp--;
|
||||||
|
}
|
||||||
|
damageDealClock.restart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Actor::healUP() {
|
||||||
|
if(hp < 3){
|
||||||
|
hp++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Bullet> &Actor::getBullets() {
|
std::vector<Bullet> &Actor::getBullets() {
|
||||||
return bullets;
|
return bullets;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Actor::updateBullets() {
|
void Actor::updateBullets() {
|
||||||
for (auto& bullet : bullets) {
|
for (auto it = bullets.begin(); it != bullets.end(); ) {
|
||||||
if(bullet.isOutOfBounds()) {
|
if (it->isOutOfBounds()) {
|
||||||
bullets.erase(bullets.begin());
|
it = bullets.erase(it); // Usuwa element i zwraca iterator na następny element
|
||||||
|
} 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;
|
||||||
}
|
}
|
||||||
91
sources/AdvancedEnemy.cpp
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
#include "../headers/AdvancedEnemy.h"
|
||||||
|
#include "../headers/Bullet.h"
|
||||||
|
#include "../headers/Plansza.h"
|
||||||
|
|
||||||
|
AdvancedEnemy::AdvancedEnemy(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture) : Actor(x, y, 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;
|
||||||
|
Plansza::score += 10;
|
||||||
|
Plansza::ultimateCounter += 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
sources/Beam.cpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include "../headers/Beam.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
Beam::Beam(int x, int y, const sf::Texture& texture) {
|
||||||
|
beamSprite.setOrigin(beamSprite.getLocalBounds().width/2, beamSprite.getLocalBounds().height/2);
|
||||||
|
if (texture.getSize().x > 0 && texture.getSize().y > 0) {
|
||||||
|
beamSprite.setPosition(x, y);
|
||||||
|
} else {
|
||||||
|
std::cerr << "Błąd: Tekstura wiązki nie została poprawnie załadowana." << std::endl;
|
||||||
|
}
|
||||||
|
beamSprite.setTexture(texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
sf::Sprite Beam::getSprite() {
|
||||||
|
return beamSprite;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Beam::setRotation(float angle) {
|
||||||
|
beamSprite.setRotation(angle);
|
||||||
|
}
|
||||||
|
|
||||||
127
sources/Bomber.cpp
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
#include "../headers/Bomber.h"
|
||||||
|
#include "../headers/Bullet.h"
|
||||||
|
#include "../headers/Plansza.h"
|
||||||
|
#include <random>
|
||||||
|
|
||||||
|
Bomber::Bomber(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture) : Actor(x, y, 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;
|
||||||
|
Plansza::score += 15;
|
||||||
|
Plansza::ultimateCounter += 15;
|
||||||
|
}
|
||||||
|
}
|
||||||
188
sources/Boss.cpp
Normal file
@@ -0,0 +1,188 @@
|
|||||||
|
#include "../headers/Boss.h"
|
||||||
|
#include <random>
|
||||||
|
#include <iostream>
|
||||||
|
#include "../headers/RandomNumberGenerator.h"
|
||||||
|
|
||||||
|
Boss::Boss(int x, int y, const sf::Texture& bossTexture, const sf::Texture& bulletTexture, const sf::Texture BombaTexture, sf::RenderWindow* window)
|
||||||
|
: Actor(x, y, bossTexture), bulletTexture(bulletTexture), BombaTexture(BombaTexture), window(window) {
|
||||||
|
try {
|
||||||
|
beamTexture.loadFromFile("../assets/img/wiazka/laser.png");
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "Failed to load textures: " << e.what() << std::endl;
|
||||||
|
exit(-500);
|
||||||
|
}
|
||||||
|
hp = 100;
|
||||||
|
firerate = 2000;
|
||||||
|
movementSpeed = 2.0f;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Boss::setPlanszaHeight(int height, int width) {
|
||||||
|
planszaHeight = height;
|
||||||
|
planszaWidth = width;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Po mergowaniu dodać obsługę pocisku, przy pomocy nowego konstruktora Bullet
|
||||||
|
void Boss::shoot() {
|
||||||
|
if (shootClock.getElapsedTime().asMilliseconds() >= firerate) {
|
||||||
|
Bullet leftBullet(position.x - 20, position.y, bulletTexture);
|
||||||
|
leftBullet.setSpeed(5.0f);
|
||||||
|
Bullet centerBullet(position.x, position.y, bulletTexture);
|
||||||
|
centerBullet.setSpeed(5.0f);
|
||||||
|
Bullet rightBullet(position.x + 20, position.y, bulletTexture);
|
||||||
|
rightBullet.setSpeed(5.0f);
|
||||||
|
bullets.push_back(std::move(leftBullet));
|
||||||
|
bullets.push_back(std::move(centerBullet));
|
||||||
|
bullets.push_back(std::move(rightBullet));
|
||||||
|
std::cout << "Strzal lezy" << std::endl;
|
||||||
|
shootClock.restart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Boss::dropBomb() {
|
||||||
|
if (bombClock.getElapsedTime().asMilliseconds() >= 5000) {
|
||||||
|
Bullet Bomb(position.x, position.y, BombaTexture);
|
||||||
|
Bomb.setSpeed(0.5f);
|
||||||
|
bombs.emplace_back(std::move(Bomb)); // Można zmienić na bombę
|
||||||
|
std::cout << "Bombka lezy" << std::endl;
|
||||||
|
bombClock.restart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Boss::shootLaser() {
|
||||||
|
if (!laserBeam && laserClock.getElapsedTime().asSeconds() >= 5.0f) {
|
||||||
|
laserBeam = new Beam(position.x, position.y, beamTexture);
|
||||||
|
beamDurationClock.restart();
|
||||||
|
laserClock.restart();
|
||||||
|
isStationary = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (laserBeam) {
|
||||||
|
window->draw(laserBeam->getSprite());
|
||||||
|
std::cout << "Laser beam shooted" << std::endl;
|
||||||
|
|
||||||
|
if (beamDurationClock.getElapsedTime().asSeconds() >= beamDuration) {
|
||||||
|
delete laserBeam;
|
||||||
|
laserBeam = nullptr;
|
||||||
|
isStationary = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Boss::move(float deltaX, float deltaY) {
|
||||||
|
if (deltaX == 0 && deltaY == 0) {
|
||||||
|
std::cerr << "Boss stopped: deltaX and deltaY are both 0" << std::endl;
|
||||||
|
}
|
||||||
|
actorSprite.move(deltaX, deltaY);
|
||||||
|
position.x += static_cast<int>(deltaX);
|
||||||
|
position.y += static_cast<int>(deltaY);
|
||||||
|
handleBounds();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Boss::update() {
|
||||||
|
std::cout << "Current movementSpeed: " << movementSpeed << std::endl;
|
||||||
|
std::cout << "Boss position: (" << position.x << ", " << position.y << "), Direction: " << static_cast<int>(direction) << std::endl;
|
||||||
|
|
||||||
|
if (!isStationary) {
|
||||||
|
if (directionClock.getElapsedTime().asSeconds() >= 3.0f) {
|
||||||
|
setRandomDirection();
|
||||||
|
directionClock.restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (direction) {
|
||||||
|
case BossDirection::Up: moveUp(); break;
|
||||||
|
case BossDirection::Down: moveDown(); break;
|
||||||
|
case BossDirection::Left: moveLeft(); break;
|
||||||
|
case BossDirection::Right: moveRight(); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shoot();
|
||||||
|
dropBomb();
|
||||||
|
shootLaser();
|
||||||
|
|
||||||
|
// Aktualizacja pocisków
|
||||||
|
for (auto it = bullets.begin(); it != bullets.end();) {
|
||||||
|
it->update();
|
||||||
|
window->draw(it->getSprite());
|
||||||
|
if (it->isOutOfBounds()) {
|
||||||
|
it = bullets.erase(it);
|
||||||
|
} else {
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aktualizacja bomb
|
||||||
|
for (auto it = bombs.begin(); it != bombs.end();) {
|
||||||
|
it->update();
|
||||||
|
window->draw(it->getSprite());
|
||||||
|
if (it->isOutOfBounds()) {
|
||||||
|
it = bombs.erase(it);
|
||||||
|
} else {
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Boss::moveLeft() {
|
||||||
|
move(-movementSpeed, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Boss::moveRight() {
|
||||||
|
move(movementSpeed, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Boss::moveUp() {
|
||||||
|
move(0.0f, -movementSpeed);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Boss::moveDown() {
|
||||||
|
move(0.0f, movementSpeed);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Boss::takeDamage() {
|
||||||
|
if (--hp <= 0) {
|
||||||
|
hp = 0;
|
||||||
|
std::cout << "HP bossa" << hp << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Boss::isAlive() const {
|
||||||
|
return hp > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Boss::setRandomDirection() {
|
||||||
|
BossDirection previousDirection = direction;
|
||||||
|
do {
|
||||||
|
int randomValue = RandomNumberGenerator::getRandomNumber(0, 3);
|
||||||
|
direction = static_cast<BossDirection>(randomValue);
|
||||||
|
} while (
|
||||||
|
(direction == BossDirection::Left && position.x <= 0) ||
|
||||||
|
(direction == BossDirection::Right && position.x >= 600) ||
|
||||||
|
(direction == BossDirection::Up && position.y <= 0) ||
|
||||||
|
(direction == BossDirection::Down && position.y >= 800)
|
||||||
|
);
|
||||||
|
if (previousDirection == direction) {
|
||||||
|
std::cerr << "Boss kept the same direction: " << static_cast<int>(direction) << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Boss::handleBounds() {
|
||||||
|
if (position.x < 0) {
|
||||||
|
direction = BossDirection::Right;
|
||||||
|
} else if (position.x > 600 - actorSprite.getGlobalBounds().width) {
|
||||||
|
direction = BossDirection::Left;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (position.y < 0) {
|
||||||
|
direction = BossDirection::Down;
|
||||||
|
} else if (position.y > 800 - actorSprite.getGlobalBounds().height) {
|
||||||
|
direction = BossDirection::Up;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,9 +1,16 @@
|
|||||||
#include "../headers/Bullet.h"
|
#include "../headers/Bullet.h"
|
||||||
|
|
||||||
|
Bullet::Bullet(float x, float y, sf::Texture &texture): Projectile(x,y, texture) {}
|
||||||
|
|
||||||
|
Bullet::Bullet(float x, float y, sf::Texture &texture, float speed): Projectile(x,y, texture) {
|
||||||
|
this->speed = -speed;
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
21
sources/Debuff.cpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#include "../headers/Debuff.h"
|
||||||
|
|
||||||
|
Debuff::Debuff(float x, float y, sf::Texture &texture, Type type) : ObjectItem(x, y, texture) {
|
||||||
|
position.x = x;
|
||||||
|
position.y = y;
|
||||||
|
texture_ = texture;
|
||||||
|
sprite.setTexture(texture);
|
||||||
|
sprite.setOrigin(sprite.getLocalBounds().width / 2, sprite.getLocalBounds().height / 2); // wycentrowanie sprite
|
||||||
|
sprite.setScale(0.5f, 0.5f);
|
||||||
|
sprite.setPosition(x, y);
|
||||||
|
movingSpeed = 3.0f;
|
||||||
|
this->type_ = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Debuff::update() {
|
||||||
|
sprite.move(0.0f, movingSpeed); // przesunięcie sprajta
|
||||||
|
position.y += int(movingSpeed); // przesunięcie pozycji
|
||||||
|
if(position.y > 900) {
|
||||||
|
outOfBounds = true; // jeżeli wyszedł poza granice ekranu ustaw tą zmienną
|
||||||
|
}
|
||||||
|
}
|
||||||
81
sources/Enemy.cpp
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
#include "../headers/Enemy.h"
|
||||||
|
#include "../headers/Bullet.h"
|
||||||
|
#include "../headers/Plansza.h"
|
||||||
|
|
||||||
|
Enemy::Enemy(int x, int y, const sf::Texture& texture) : Actor(x, y, 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;
|
||||||
|
Plansza::score += 5;
|
||||||
|
Plansza::ultimateCounter += 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
20
sources/Heart.cpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#include "../headers/Heart.hpp"
|
||||||
|
|
||||||
|
Heart::Heart(float x, float y, sf::Texture &texture) : ObjectItem(x,y,texture) {
|
||||||
|
texture_ = texture;
|
||||||
|
sprite.setTexture(texture_);
|
||||||
|
sprite.setOrigin(sprite.getLocalBounds().width / 2, sprite.getLocalBounds().height / 2); // wycentrowanie sprite
|
||||||
|
sprite.setPosition(x, y);
|
||||||
|
movingSpeed = 3.0f;
|
||||||
|
position.x = x;
|
||||||
|
position.y = y;
|
||||||
|
rotationSpeed = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Heart::update() {
|
||||||
|
sprite.move(0.0f, movingSpeed); // przesunięcie sprajta
|
||||||
|
position.y += int(movingSpeed); // przesunięcie pozycji
|
||||||
|
if(position.y > 900) {
|
||||||
|
outOfBounds = true; // jeżeli wyszedł poza granice ekranu ustaw tą zmienną
|
||||||
|
}
|
||||||
|
}
|
||||||
136
sources/Kamikadze.cpp
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <random>
|
||||||
|
#include "../headers/Kamikadze.h"
|
||||||
|
#include "../headers/RandomNumberGenerator.h"
|
||||||
|
#include "../headers/Plansza.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Kamikadze::Kamikadze(int x, int y, const sf::Texture& texture) : Actor(x, y, 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;
|
||||||
|
Plansza::score += 20;
|
||||||
|
Plansza::ultimateCounter += 20;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,40 +1,28 @@
|
|||||||
#include <iostream>
|
|
||||||
#include "../headers/Meteor.h"
|
#include "../headers/Meteor.h"
|
||||||
|
|
||||||
Meteor::Meteor(float x, float y, sf::Texture &texture) {
|
Meteor::Meteor(float x, float y, sf::Texture &texture) : ObjectItem(x, y, texture) {
|
||||||
outOfBounds = false;
|
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() {
|
||||||
meteorSprite.move(0.0f, meteorSpeed); // przesunięcie sprajta
|
sprite.move(0.0f, movingSpeed); // przesunięcie sprajta
|
||||||
meteorPosition.y += int(meteorSpeed); // przesunięcie pozycji
|
position.y += int(movingSpeed); // przesunięcie pozycji
|
||||||
meteorSprite.rotate(meteorRotationSpeed); // obracanie tym meteorkiem pięknym
|
sprite.rotate(rotationSpeed); // obracanie tym meteorkiem pięknym
|
||||||
if(meteorPosition.y > 900) {
|
if(position.y > 900) {
|
||||||
outOfBounds = true; // jeżeli wyszedł poza granice ekranu ustaw tą zmienną
|
outOfBounds = true; // jeżeli wyszedł poza granice ekranu ustaw tą zmienną
|
||||||
}
|
}
|
||||||
// std::cout << "x: " << meteorSprite.getPosition().x << std::endl;
|
|
||||||
// std::cout << "y: " << meteorSprite.getPosition().y << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Meteor::getStatus() {
|
|
||||||
return outOfBounds;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int Meteor::counter = 0;
|
|
||||||
|
|
||||||
// było użyte do testowania czy meteoryt jest kasowany
|
// było użyte do testowania czy meteoryt jest kasowany
|
||||||
//Meteor::~Meteor() {
|
//Meteor::~Meteor() {
|
||||||
// Meteor::counter++;
|
// Meteor::counter++;
|
||||||
|
|||||||
18
sources/ObjectItem.cpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#include "../headers/ObjectItem.hpp"
|
||||||
|
|
||||||
|
ObjectItem::ObjectItem(float x, float y, sf::Texture &texture) {
|
||||||
|
outOfBounds = false;
|
||||||
|
Position position_ = {0,0};
|
||||||
|
position_.x = static_cast<int>(x);
|
||||||
|
position_.y = static_cast<int>(y);
|
||||||
|
position = position_;
|
||||||
|
this->texture_ = texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ObjectItem::getStatus() {
|
||||||
|
return outOfBounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
sf::Sprite &ObjectItem::getSprite() {
|
||||||
|
return sprite;
|
||||||
|
}
|
||||||
1199
sources/Plansza.cpp
@@ -1,19 +1,55 @@
|
|||||||
#include "../headers/Player.h"
|
#include <iostream>
|
||||||
#include "../headers/Bullet.h"
|
#include <SFML/Graphics/Font.hpp>
|
||||||
|
|
||||||
Player::Player(int x, int y, std::string path) : Actor(x, y, path) {
|
#include "../headers/Player.h"
|
||||||
bulletTexture.loadFromFile("../assets/img/bullets/bullet_pink.png");
|
#include "../headers/Plansza.h"
|
||||||
rocketTexture.loadFromFile("../assets/img/rockets/Rocket_111.png");
|
|
||||||
};
|
|
||||||
|
|
||||||
|
Player::Player(int x, int y, const sf::Texture& texture) : Actor(x, y, texture) {
|
||||||
|
hp = 3;
|
||||||
|
if(Plansza::selectedShip != none) {
|
||||||
|
actorSprite.setScale(0.20f, 0.20f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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() {
|
||||||
|
try {
|
||||||
|
bulletTexture.loadFromFile("../assets/img/bullets/bullet_pink.png");
|
||||||
|
rocketTexture.loadFromFile("../assets/img/rockets/Rocket_111.png");
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
std::cerr << "Failed to load textures: " << e.what() << std::endl;
|
||||||
|
exit(-500);
|
||||||
|
}
|
||||||
|
|
||||||
|
damageDealClock.restart();
|
||||||
|
originalColor = actorSprite.getColor();
|
||||||
|
}
|
||||||
|
|
||||||
void Player::shoot() {
|
void Player::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) {
|
||||||
bullets.emplace_back(position.x, position.y, bulletTexture);
|
if (tripleShot == true) {
|
||||||
lastShotTime = now;
|
bullets.emplace_back(position.x - 40, position.y, bulletTexture, bulletSpeed);
|
||||||
|
bullets.emplace_back(position.x, position.y, bulletTexture, bulletSpeed);
|
||||||
|
bullets.emplace_back(position.x + 40, position.y, bulletTexture, bulletSpeed);
|
||||||
|
lastShotTime = now;
|
||||||
|
}
|
||||||
|
if (tripleShot == false) {
|
||||||
|
bullets.emplace_back(position.x, position.y, bulletTexture, bulletSpeed);
|
||||||
|
lastShotTime = now;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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) {
|
||||||
@@ -22,6 +58,43 @@ void Player::alternate_shoot() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::ultimate_shoot() {
|
||||||
|
ultimateShootActive = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (hp > 0) {
|
||||||
|
hp--;
|
||||||
|
isImmortal = true; // Aktywuj chwilową nieśmiertelność
|
||||||
|
immortalityClock.restart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::setTripleShot(bool toogle) {
|
||||||
|
tripleShot = toogle;
|
||||||
|
}
|
||||||
|
|
||||||
void Player::setFirerate(unsigned int firerate) {
|
void Player::setFirerate(unsigned int firerate) {
|
||||||
this->firerate = firerate;
|
this->firerate = firerate;
|
||||||
}
|
}
|
||||||
@@ -53,3 +126,18 @@ void Player::moveDown() {
|
|||||||
std::vector<Rocket> &Player::getRockets() {
|
std::vector<Rocket> &Player::getRockets() {
|
||||||
return rockets;
|
return rockets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::setBulletSpeed(float speed) {
|
||||||
|
this->bulletSpeed = speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Player* Player::player_ = nullptr;
|
||||||
|
|
||||||
|
bool Player::getUltimateStatus() {
|
||||||
|
return ultimateShootActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::setUltimateStatus(bool status) {
|
||||||
|
ultimateShootActive = status;
|
||||||
|
}
|
||||||
|
|||||||
21
sources/PowerUp.cpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#include "../headers/PowerUp.h"
|
||||||
|
|
||||||
|
PowerUp::PowerUp(float x, float y, sf::Texture &texture, PowerUp::Type type): ObjectItem(x, y, texture) {
|
||||||
|
position.x = x;
|
||||||
|
position.y = y;
|
||||||
|
texture_ = texture;
|
||||||
|
sprite.setTexture(texture);
|
||||||
|
sprite.setOrigin(sprite.getLocalBounds().width / 2, sprite.getLocalBounds().height / 2); // wycentrowanie sprite
|
||||||
|
sprite.setScale(0.5f, 0.5f);
|
||||||
|
sprite.setPosition(x, y);
|
||||||
|
movingSpeed = 3.0f;
|
||||||
|
this->type_ = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PowerUp::update() {
|
||||||
|
sprite.move(0.0f, movingSpeed); // przesunięcie sprajta
|
||||||
|
position.y += int(movingSpeed); // przesunięcie pozycji
|
||||||
|
if(position.y > 900) {
|
||||||
|
outOfBounds = true; // jeżeli wyszedł poza granice ekranu ustaw tą zmienną
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
void Rocket::update() {
|
void Rocket::update() {
|
||||||
sprite.move(0.0f, speed);
|
sprite.move(0.0f, speed);
|
||||||
position.y += int(speed);
|
position.y += static_cast<int>(speed);
|
||||||
if(position.y < -100) {
|
if(position.y < -100) {
|
||||||
outOfBounds = true;
|
outOfBounds = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
213
sources/Wiazkowiec.cpp
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
#include "../headers/Wiazkowiec.h"
|
||||||
|
#include "../headers/Plansza.h"
|
||||||
|
#include "../headers/RandomNumberGenerator.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
|
Wiazkowiec::Wiazkowiec(int x, int y, const sf::Texture &texture, sf::RenderWindow *window) : Actor(x, y, texture),
|
||||||
|
beam(nullptr)
|
||||||
|
{
|
||||||
|
window_ptr = window;
|
||||||
|
|
||||||
|
try {
|
||||||
|
beamTexture.loadFromFile("../assets/img/wiazka/laser.png");
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
std::cerr << "Failed to load textures: " << e.what() << std::endl;
|
||||||
|
exit(-500);
|
||||||
|
}
|
||||||
|
|
||||||
|
hp = 2; // 2 punkty życia
|
||||||
|
firerate = 5000; // Strzela co 10
|
||||||
|
moving_speed = 5.0f; // Prędkość
|
||||||
|
}
|
||||||
|
|
||||||
|
void Wiazkowiec::setPlanszaHeight(int height, int width) {
|
||||||
|
planszaHeight = height;
|
||||||
|
planszaWidth = width;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Wiazkowiec::spawnBeam() {
|
||||||
|
int beamX = actorSprite.getPosition().x;
|
||||||
|
int beamY = actorSprite.getPosition().y;
|
||||||
|
|
||||||
|
switch (direction) {
|
||||||
|
case DirectionW::Up: {
|
||||||
|
beam = new Beam(beamX, beamY, beamTexture);
|
||||||
|
beam->setRotation(180);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DirectionW::Down: {
|
||||||
|
beam = new Beam(beamX, beamY, beamTexture);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DirectionW::Left: {
|
||||||
|
beam = new Beam(beamX, beamY, beamTexture);
|
||||||
|
beam->setRotation(90);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DirectionW::Right: {
|
||||||
|
beam = new Beam(beamX, beamY, beamTexture);
|
||||||
|
beam->setRotation(270);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
shooting = true;
|
||||||
|
shootingClock.restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strzał wiązki
|
||||||
|
void Wiazkowiec::shoot() {
|
||||||
|
if (!shooting) {
|
||||||
|
spawnBeam();
|
||||||
|
}
|
||||||
|
switch (direction) {
|
||||||
|
case DirectionW::Up: {
|
||||||
|
std::cout << "Direction is up" << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DirectionW::Down: {
|
||||||
|
std::cout << "Direction is down" << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DirectionW::Left: {
|
||||||
|
std::cout << "Direction is left" << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DirectionW::Right: {
|
||||||
|
std::cout << "Direction is right" << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Wiazkowiec::setRandomDirection() {
|
||||||
|
// Losowanie kierunku: 0 = Up, 1 = Down, 2 = Left, 3 = Right
|
||||||
|
|
||||||
|
int whatNumber = rand() % 4;
|
||||||
|
|
||||||
|
switch (whatNumber) {
|
||||||
|
case 0:
|
||||||
|
direction = DirectionW::Up;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
direction = DirectionW::Down;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
direction = DirectionW::Left;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
direction = DirectionW::Right;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Wiazkowiec::checkIfBeamShootOutOfBounds() {
|
||||||
|
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 (static_cast<float>(position.x) + deltaX < 0) {
|
||||||
|
deltaX = static_cast<float>(-position.x);
|
||||||
|
} else if (static_cast<float>(position.x) + spriteBounds.width + deltaX > static_cast<float>(planszaWidth)) {
|
||||||
|
deltaX = static_cast<float>(planszaWidth) - (static_cast<float>(position.x) + spriteBounds.width);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Zapobiegaj wyjściu poza pionowe granice
|
||||||
|
if (static_cast<float>(position.y) + deltaY < 0) {
|
||||||
|
deltaY = static_cast<float>(-position.y);
|
||||||
|
} else if (static_cast<float>(position.y) + spriteBounds.height + deltaY > static_cast<float>(planszaHeight)) {
|
||||||
|
deltaY = static_cast<float>(planszaHeight) - (static_cast<float>(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) {
|
||||||
|
shooting = false;
|
||||||
|
delete beam;
|
||||||
|
beam = nullptr;
|
||||||
|
setRandomDirection(); // Zmień kierunek po strzale
|
||||||
|
} else {
|
||||||
|
window_ptr->draw(beam->getSprite());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
checkIfBeamShootOutOfBounds();
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Wiazkowiec::isAlive() const {
|
||||||
|
return alive;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Wiazkowiec::takeDamage() {
|
||||||
|
if (--hp <= 0) {
|
||||||
|
alive = false;
|
||||||
|
Plansza::score += 10;
|
||||||
|
Plansza::ultimateCounter += 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Wiazkowiec::isShooting() const {
|
||||||
|
return shooting;
|
||||||
|
}
|
||||||
|
|
||||||
|
Beam* Wiazkowiec::getBeam() const {
|
||||||
|
return beam;
|
||||||
|
}
|
||||||