Compare commits
48 Commits
8b4b25747e
...
ultimateIm
| Author | SHA1 | Date | |
|---|---|---|---|
| bad49c78a5 | |||
| f5d9bae6e9 | |||
| 696714cf9a | |||
| 3c0cd4b950 | |||
| 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 | |||
| da33fcc718 | |||
| 71f8ebe285 | |||
| 2f9e0ba236 | |||
| 3b637508e1 |
@@ -40,6 +40,14 @@ add_executable(LotoStatek main.cpp
|
||||
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)
|
||||
|
||||
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/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/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/ultimate/ultimate_0.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
assets/img/ultimate/ultimate_10.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
assets/img/ultimate/ultimate_100.png
Normal file
|
After Width: | Height: | Size: 6.1 KiB |
BIN
assets/img/ultimate/ultimate_20.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
assets/img/ultimate/ultimate_30.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
assets/img/ultimate/ultimate_40.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
assets/img/ultimate/ultimate_50.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
assets/img/ultimate/ultimate_60.png
Normal file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
assets/img/ultimate/ultimate_70.png
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
assets/img/ultimate/ultimate_80.png
Normal file
|
After Width: | Height: | Size: 4.5 KiB |
BIN
assets/img/ultimate/ultimate_90.png
Normal file
|
After Width: | Height: | Size: 5.0 KiB |
BIN
assets/img/wiazka/laser.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 39 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/destroyed.ogg
Normal file
@@ -5,11 +5,18 @@
|
||||
#include "SFML/Graphics/Texture.hpp"
|
||||
#include "Bullet.h"
|
||||
#include "Position.h"
|
||||
#include "SFML/System/Clock.hpp"
|
||||
|
||||
|
||||
class Actor {
|
||||
public:
|
||||
Actor(int x, int y, const sf::Texture& texture);
|
||||
virtual ~Actor() = default;
|
||||
|
||||
sf::Sprite& getSprite();
|
||||
unsigned int getHP();
|
||||
Position getPosition();
|
||||
std::vector<Bullet>& getBullets();
|
||||
|
||||
virtual void move(float deltaX, float deltaY) = 0;
|
||||
virtual void moveLeft() = 0;
|
||||
@@ -18,13 +25,10 @@ public:
|
||||
virtual void moveDown() = 0;
|
||||
virtual void shoot() = 0;
|
||||
|
||||
std::vector<Bullet>& getBullets();
|
||||
sf::Sprite& getSprite();
|
||||
Position getPosition();
|
||||
|
||||
void setMovingSpeed(float speed);
|
||||
|
||||
void updateBullets();
|
||||
void setMovingSpeed(float speed);
|
||||
void dealDamage();
|
||||
void healUP();
|
||||
|
||||
protected:
|
||||
Position position;
|
||||
@@ -33,7 +37,8 @@ protected:
|
||||
sf::Texture bulletTexture;
|
||||
sf::Texture rocketTexture;
|
||||
std::vector<Bullet> bullets;
|
||||
unsigned int hp;
|
||||
sf::Clock damageDealClock;
|
||||
int hp;
|
||||
unsigned int damage;
|
||||
unsigned int firerate;
|
||||
float moving_speed;
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
|
||||
#include "Enemy.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
enum class DirectionA {
|
||||
Up,
|
||||
Down,
|
||||
|
||||
@@ -2,27 +2,16 @@
|
||||
#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);
|
||||
Beam() = default;
|
||||
Beam(int x, int y, const sf::Texture &texture);
|
||||
|
||||
sf::Sprite getSprite();
|
||||
|
||||
void setRotation(float angle);
|
||||
private:
|
||||
sf::RectangleShape beamShape;
|
||||
bool visible;
|
||||
sf::Texture beamTexture;
|
||||
sf::Sprite beamSprite;
|
||||
};
|
||||
|
||||
|
||||
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,14 +2,14 @@
|
||||
#define LOTOSTATEK_BULLET_H
|
||||
|
||||
#include "Projectile.h"
|
||||
#include "SFML/Graphics/Texture.hpp"
|
||||
|
||||
class Bullet : public Projectile {
|
||||
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;
|
||||
private:
|
||||
float directionY;
|
||||
};
|
||||
|
||||
|
||||
|
||||
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
|
||||
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
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
class Meteor : public ObjectItem {
|
||||
public:
|
||||
Meteor(float x, float y, sf::Texture &texture);
|
||||
Meteor(float x, float y, sf::Texture &texture_);
|
||||
void update();
|
||||
};
|
||||
|
||||
|
||||
@@ -7,12 +7,13 @@
|
||||
|
||||
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::Texture texture_;
|
||||
sf::Sprite sprite;
|
||||
Position position;
|
||||
float rotationSpeed;
|
||||
|
||||
@@ -14,48 +14,81 @@
|
||||
#include "Background.h"
|
||||
#include "AudioManager.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 {
|
||||
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();
|
||||
std::vector<Meteor> &getMeteors();
|
||||
void spawn_meteor();
|
||||
void spawn_hearts();
|
||||
void spawn_power_up();
|
||||
void spawn_debuff();
|
||||
void update_meteors();
|
||||
void update_hearts();
|
||||
void update_power_ups();
|
||||
void update_debuffs();
|
||||
|
||||
|
||||
void update();
|
||||
void update_score();
|
||||
void setOutOfBounds(bool status);
|
||||
|
||||
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; // usuwanie wskaźnika ship
|
||||
delete ship;
|
||||
delete boss;
|
||||
}
|
||||
|
||||
static ships selectedShip;
|
||||
static unsigned int score;
|
||||
static unsigned int ultimateCounter;
|
||||
sf::Font font;
|
||||
|
||||
private:
|
||||
Size size;
|
||||
Background background;
|
||||
AudioManager audioManager;
|
||||
Player *ship;
|
||||
Size size;
|
||||
sf::RenderWindow *window;
|
||||
sf::Font font;
|
||||
sf::Texture meteorTexture1;
|
||||
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;
|
||||
// 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;
|
||||
@@ -63,14 +96,65 @@ private:
|
||||
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 meteorTexture2;
|
||||
sf::Texture heartTexture;
|
||||
sf::Texture heartTextureGray;
|
||||
sf::Texture movingSpeedPowerUpTexture;
|
||||
sf::Texture fireratePowerUpTexture;
|
||||
sf::Texture tripleShotPowerUpTexture;
|
||||
sf::Texture movingSpeedDebuffTexture;
|
||||
sf::Texture firerateDebuffTexture;
|
||||
sf::Texture bulletSpeedDebuffTexture;
|
||||
sf::Texture ultimateIndicatorTextures[11];
|
||||
|
||||
// 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;
|
||||
unsigned int score = 0;
|
||||
bool isPlayerSpawned = false;
|
||||
std::vector<Heart> hearts;
|
||||
std::vector<sf::Sprite> heartStats;
|
||||
std::vector<PowerUp> powerUps;
|
||||
std::vector<Debuff> debuffs;
|
||||
std::vector<sf::Sprite> ultimateIndicators;
|
||||
|
||||
void loadUltimateIndicators();
|
||||
|
||||
// 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
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef LOTOSTATEK_PLAYER_H
|
||||
#define LOTOSTATEK_PLAYER_H
|
||||
|
||||
|
||||
#include <chrono>
|
||||
#include <SFML/System/Clock.hpp>
|
||||
|
||||
@@ -21,6 +22,7 @@ public:
|
||||
|
||||
void shoot() override;
|
||||
void alternate_shoot();
|
||||
void ultimate_shoot();
|
||||
void setFirerate(unsigned int firerate);
|
||||
void move(float deltaX, float deltaY) override;
|
||||
void moveLeft() override;
|
||||
@@ -28,21 +30,30 @@ public:
|
||||
void moveUp() override;
|
||||
void moveDown() override;
|
||||
void takeDamage();
|
||||
bool isAlive() const;
|
||||
void setTripleShot(bool toogle);
|
||||
|
||||
void setBulletSpeed(float speed);
|
||||
bool getUltimateStatus();
|
||||
void update();
|
||||
|
||||
std::vector<Rocket>& getRockets();
|
||||
|
||||
void loadTexture();
|
||||
|
||||
void setUltimateStatus(bool status);
|
||||
|
||||
private:
|
||||
std::chrono::steady_clock::time_point lastShotTime = std::chrono::steady_clock::now();
|
||||
std::vector<Rocket> rockets;
|
||||
sf::Texture rocketTexture;
|
||||
sf::Texture bulletTexture;
|
||||
sf::Color originalColor;
|
||||
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
|
||||
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;
|
||||
};
|
||||
|
||||
struct PositionU {
|
||||
unsigned int x;
|
||||
unsigned int y;
|
||||
};
|
||||
|
||||
struct PositionF {
|
||||
float x;
|
||||
float y;
|
||||
};
|
||||
|
||||
#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
|
||||
@@ -13,42 +13,47 @@ enum class DirectionW {
|
||||
|
||||
class Wiazkowiec : public Actor {
|
||||
public:
|
||||
Wiazkowiec(int x, int y, const sf::Texture& texture);
|
||||
Wiazkowiec(int x, int y, const sf::Texture& texture, sf::RenderWindow *window);
|
||||
|
||||
void shoot() override;
|
||||
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;
|
||||
void takeDamage();
|
||||
void updateDirection();
|
||||
bool isShooting() const;
|
||||
const Beam& getBeam() const;
|
||||
void setPlanszaHeight(float height, float width);
|
||||
void setMapBounds(float width, float height);
|
||||
|
||||
void setPlanszaHeight(int height, int width);
|
||||
Beam* getBeam() const;
|
||||
|
||||
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::Texture beamTexture;
|
||||
sf::Clock shootClock;
|
||||
sf::Clock shootingClock;
|
||||
float beamDuration = 1.0f;
|
||||
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
|
||||
|
||||
180
main.cpp
@@ -3,7 +3,13 @@
|
||||
|
||||
#include "headers/Plansza.h"
|
||||
|
||||
ships selectedShip = none;
|
||||
|
||||
void menu();
|
||||
|
||||
int main() {
|
||||
menu();
|
||||
|
||||
std::clog << "Game started\n";
|
||||
sf::RenderWindow mainWindow(sf::VideoMode(600, 800), "LotoStatek");
|
||||
mainWindow.setVerticalSyncEnabled(true);
|
||||
@@ -13,8 +19,9 @@ int main() {
|
||||
icon.loadFromFile("../assets/img/icon/ikonka.png");
|
||||
mainWindow.setIcon(128, 128, icon.getPixelsPtr());
|
||||
|
||||
bool isPaused = false;
|
||||
|
||||
Plansza plansza(mainWindow.getSize().y, mainWindow.getSize().x, &mainWindow);
|
||||
Plansza plansza(mainWindow.getSize().y, mainWindow.getSize().x, &mainWindow, selectedShip);
|
||||
|
||||
while (mainWindow.isOpen()) {
|
||||
mainWindow.clear();
|
||||
@@ -26,10 +33,175 @@ int main() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,25 @@ Position Actor::getPosition() {
|
||||
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() {
|
||||
return bullets;
|
||||
}
|
||||
@@ -39,4 +58,4 @@ void Actor::updateBullets() {
|
||||
|
||||
void Actor::setMovingSpeed(float speed) {
|
||||
moving_speed = speed;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
#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) {
|
||||
actorSprite.setTexture(texture);
|
||||
enemyBulletTexture = bulletTexture;
|
||||
hp = 2; // 2 punkty życia
|
||||
firerate = 2000; // Strzela co 2
|
||||
moving_speed = 2.0f; // Prędkość
|
||||
moving_speed = 4.0f; // Prędkość
|
||||
enemyBulletTexture.loadFromFile("../assets/img/bullets/enemy_bullet.png");
|
||||
}
|
||||
|
||||
@@ -85,5 +85,7 @@ bool AdvancedEnemy::isAlive() const {
|
||||
void AdvancedEnemy::takeDamage() {
|
||||
if (--hp <= 0) {
|
||||
alive = false;
|
||||
Plansza::score += 10;
|
||||
Plansza::ultimateCounter += 10;
|
||||
}
|
||||
}
|
||||
@@ -2,50 +2,21 @@
|
||||
|
||||
#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);
|
||||
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);
|
||||
}
|
||||
|
||||
void Beam::draw(sf::RenderWindow& window) {
|
||||
|
||||
window.draw(beamSprite);
|
||||
|
||||
sf::Sprite Beam::getSprite() {
|
||||
return 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;
|
||||
void Beam::setRotation(float angle) {
|
||||
beamSprite.setRotation(angle);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#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) {
|
||||
actorSprite.setTexture(texture);
|
||||
BombaTexture = bulletTexture;
|
||||
hp = 2; // 2 punkty życia
|
||||
firerate = 10000; // Strzela co 10
|
||||
moving_speed = 10.0f; // Prędkość
|
||||
firerate = 6000; // Strzela co 6
|
||||
moving_speed = 8.0f; // Prędkość
|
||||
}
|
||||
|
||||
void Bomber::setPlanszaHeight(float height, float width) {
|
||||
@@ -121,5 +121,7 @@ bool Bomber::isAlive() const {
|
||||
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 = 3.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,7 +1,10 @@
|
||||
#include "../headers/Bullet.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
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() {
|
||||
//std::cout << "Start update: speed = " << speed << ", position.y = " << position.y << std::endl;
|
||||
|
||||
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ą
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
#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) {
|
||||
actorSprite.setTexture(texture);
|
||||
hp = 1; // Przeciwnik ma 1 punkt życia
|
||||
firerate = 2000; // Strzela co 2
|
||||
moving_speed = 2.0f; // Prędkość
|
||||
moving_speed = 2.5f; // Prędkość
|
||||
enemyBulletTexture.loadFromFile("../assets/img/bullets/enemy_bullet.png");
|
||||
}
|
||||
|
||||
@@ -75,5 +75,7 @@ bool Enemy::isAlive() const {
|
||||
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ą
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
#include "../headers/Kamikadze.h"
|
||||
|
||||
#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) {
|
||||
actorSprite.setTexture(texture);
|
||||
hp = 3; // 3 punkty życia
|
||||
moving_speed = 2.0f; // Prędkość
|
||||
moving_speed = 5.0f; // Prędkość
|
||||
}
|
||||
|
||||
void Kamikadze::shoot(){}
|
||||
@@ -130,5 +130,7 @@ bool Kamikadze::isAlive() const {
|
||||
void Kamikadze::takeDamage() {
|
||||
if (--hp <= 0) {
|
||||
alive = false;
|
||||
Plansza::score += 20;
|
||||
Plansza::ultimateCounter += 20;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
#include "../headers/Meteor.h"
|
||||
|
||||
Meteor::Meteor(float x, float y, sf::Texture &texture) : ObjectItem(x, y, texture) {
|
||||
outOfBounds = false;
|
||||
texture = texture;
|
||||
texture_ = texture;
|
||||
sprite.setTexture(texture);
|
||||
sprite.setOrigin(sprite.getLocalBounds().width / 2, sprite.getLocalBounds().height / 2); // wycentrowanie sprite
|
||||
sprite.setPosition(x, y);
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include "../headers/ObjectItem.hpp"
|
||||
|
||||
ObjectItem::ObjectItem(float x, float y, sf::Texture &texture) {
|
||||
Position position_;
|
||||
position_.x = x;
|
||||
position_.y = y;
|
||||
outOfBounds = false;
|
||||
Position position_ = {0,0};
|
||||
position_.x = static_cast<int>(x);
|
||||
position_.y = static_cast<int>(y);
|
||||
position = position_;
|
||||
this->texture = texture;
|
||||
this->texture_ = texture;
|
||||
}
|
||||
|
||||
bool ObjectItem::getStatus() {
|
||||
|
||||
@@ -2,17 +2,37 @@
|
||||
#include <iostream>
|
||||
#include "../headers/Plansza.h"
|
||||
#include "../headers/RandomNumberGenerator.h"
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::RenderWindow *mainWindow)
|
||||
Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::RenderWindow *mainWindow, ships selectedShip)
|
||||
: background("../assets/img/background/background.png", 2.0f) {
|
||||
window = mainWindow;
|
||||
size.height = static_cast<int>(windowHeight);
|
||||
size.width = static_cast<int>(windowWidth);
|
||||
|
||||
Plansza::selectedShip = selectedShip;
|
||||
|
||||
try {
|
||||
playerTexture.loadFromFile("../assets/ship/Dreadnought-Base.png");
|
||||
if(selectedShip == nova) {
|
||||
playerTexture.loadFromFile("../assets/ship/nova.png");
|
||||
} else if(selectedShip == pulsar) {
|
||||
playerTexture.loadFromFile("../assets/ship/pulsar.png");
|
||||
} else if(selectedShip == zenith) {
|
||||
playerTexture.loadFromFile("../assets/ship/zenith.png");
|
||||
} else {
|
||||
playerTexture.loadFromFile("../assets/ship/Dreadnought-Base.png");
|
||||
}
|
||||
// Ładowanie tekstur itemów
|
||||
meteorTexture1.loadFromFile("../assets/img/meteors/meteor-1.png");
|
||||
meteorTexture2.loadFromFile("../assets/img/meteors/meteor-2.png");
|
||||
heartTexture.loadFromFile("../assets/img/hearts/heart.png");
|
||||
heartTextureGray.loadFromFile("../assets/img/hearts/heart_gray.png");
|
||||
movingSpeedPowerUpTexture.loadFromFile("../assets/img/powerups/movingSpeedPU.png");
|
||||
fireratePowerUpTexture.loadFromFile("../assets/img/powerups/fireratePU.png");
|
||||
tripleShotPowerUpTexture.loadFromFile("../assets/img/powerups/TripleShotPU.png");
|
||||
movingSpeedDebuffTexture.loadFromFile("../assets/img/debuffs/movingSpeedDBF.png");
|
||||
firerateDebuffTexture.loadFromFile("../assets/img/debuffs/firerateDBF.png");
|
||||
bulletSpeedDebuffTexture.loadFromFile("../assets/img/debuffs/BulletSpeedDBF.png");
|
||||
// Ładowanie tekstur wrogów
|
||||
enemyTexture.loadFromFile("../assets/img/enemy/enemy.png");
|
||||
advancedEnemyTexture.loadFromFile("../assets/img/enemy/advanced_enemy.png");
|
||||
@@ -20,11 +40,15 @@ Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::Render
|
||||
KamikadzeTexture.loadFromFile("../assets/img/enemy/kamikadze.png");
|
||||
BombaTexture.loadFromFile("../assets/img/bullets/bomba.png");
|
||||
WiazkowiecTexture.loadFromFile("../assets/img/enemy/wiazkowiec.png");
|
||||
enemyBulletTexture.loadFromFile("../assets/img/bullets/enemy_bullet.png");
|
||||
BossTexture.loadFromFile("../assets/img/boss/boss.png");
|
||||
} catch (std::exception &e) {
|
||||
std::cerr << "Failed to load textures: " << e.what() << std::endl;
|
||||
exit(-500);
|
||||
}
|
||||
|
||||
loadUltimateIndicators();
|
||||
|
||||
score = 0;
|
||||
|
||||
// Wczytywanie czcionki dla licznika punktów
|
||||
@@ -39,15 +63,56 @@ Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::Render
|
||||
audioManager.loadSoundEffect("shoot", "../assets/sounds/shoot.ogg");
|
||||
audioManager.loadSoundEffect("shoot_alt", "../assets/sounds/shoot_alt.ogg");
|
||||
audioManager.loadSoundEffect("fail", "../assets/sounds/fail.mp3");
|
||||
audioManager.loadSoundEffect("destroyed", "../assets/sounds/destroyed.ogg");
|
||||
|
||||
heartStats.emplace_back(heartTexture);
|
||||
heartStats.emplace_back(heartTexture);
|
||||
heartStats.emplace_back(heartTexture);
|
||||
heartStats[0].setPosition(565, 10);
|
||||
heartStats[1].setPosition(530, 10);
|
||||
heartStats[2].setPosition(495, 10);
|
||||
|
||||
meteorSpawnClock.restart();
|
||||
powerUpSpawnClock.restart();
|
||||
debuffSpawnClock.restart();
|
||||
spawn_player();
|
||||
|
||||
spawnClock.restart();
|
||||
// spawnClock.restart();
|
||||
}
|
||||
|
||||
void Plansza::loadUltimateIndicators() {
|
||||
const std::string texturePaths[11] = {
|
||||
"../assets/img/ultimate/ultimate_0.png",
|
||||
"../assets/img/ultimate/ultimate_10.png",
|
||||
"../assets/img/ultimate/ultimate_20.png",
|
||||
"../assets/img/ultimate/ultimate_30.png",
|
||||
"../assets/img/ultimate/ultimate_40.png",
|
||||
"../assets/img/ultimate/ultimate_50.png",
|
||||
"../assets/img/ultimate/ultimate_60.png",
|
||||
"../assets/img/ultimate/ultimate_70.png",
|
||||
"../assets/img/ultimate/ultimate_80.png",
|
||||
"../assets/img/ultimate/ultimate_90.png",
|
||||
"../assets/img/ultimate/ultimate_100.png"
|
||||
};
|
||||
|
||||
for (int i = 0; i < 11; ++i) {
|
||||
if (!ultimateIndicatorTextures[i].loadFromFile(texturePaths[i])) {
|
||||
std::cerr << "Failed to load ultimate indicator texture: " << texturePaths[i] << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
sf::Sprite sprite;
|
||||
sprite.setTexture(ultimateIndicatorTextures[i]);
|
||||
sprite.setPosition(10, window->getSize().y - 60);
|
||||
sprite.setScale(0.7f, 0.7f);
|
||||
ultimateIndicators.push_back(sprite);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TODO: Refactor tej metody bo rozrosła się za bardzo już
|
||||
void Plansza::update() {
|
||||
// tło
|
||||
srand(time(0)); // generacja innego ziarna na podstawie zegara systemowego
|
||||
// tło
|
||||
background.update();
|
||||
background.draw(*window);
|
||||
|
||||
@@ -73,33 +138,60 @@ void Plansza::update() {
|
||||
}
|
||||
}
|
||||
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space) && !ship->getUltimateStatus() && ultimateCounter >= 200) {
|
||||
ultimateClock.restart();
|
||||
ship->ultimate_shoot();
|
||||
}
|
||||
|
||||
int indicatorIndex = ultimateCounter / 20;
|
||||
indicatorIndex = std::min(indicatorIndex, 10); // Zapobiegaj przekroczeniu zakresu
|
||||
window->draw(ultimateIndicators[indicatorIndex]);
|
||||
|
||||
// TODO: Przenieść obiekt dźwięku wewnątrz klasy Bullet
|
||||
if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
|
||||
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
|
||||
// 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_hearts();
|
||||
spawn_power_up();
|
||||
spawn_debuff();
|
||||
spawn_enemy();
|
||||
spawn_advanced_enemy();
|
||||
spawn_wiazkowiec();
|
||||
spawn_bomber();
|
||||
spawn_kamikadze();
|
||||
spawn_boss();
|
||||
|
||||
// utrzymanie meteorów i pocisków w ruchu
|
||||
for (auto &meteor: getMeteors()) {
|
||||
for (auto &meteor: meteors) {
|
||||
meteor.update();
|
||||
window->draw(meteor.getSprite());
|
||||
}
|
||||
|
||||
for (auto &heart: hearts) {
|
||||
heart.update();
|
||||
window->draw(heart.getSprite());
|
||||
}
|
||||
|
||||
for (auto &powerUp: powerUps) {
|
||||
powerUp.update();
|
||||
window->draw(powerUp.getSprite());
|
||||
}
|
||||
|
||||
for (auto &debuff: debuffs) {
|
||||
debuff.update();
|
||||
window->draw(debuff.getSprite());
|
||||
}
|
||||
|
||||
for (auto &bullet: ship->getBullets()) {
|
||||
bullet.update();
|
||||
window->draw(bullet.getSprite());
|
||||
@@ -110,19 +202,50 @@ void Plansza::update() {
|
||||
window->draw(rocket.getSprite());
|
||||
}
|
||||
|
||||
// Sprawdzenie czy meteory i pociski są poza granicami ekranu
|
||||
// Sprawdzenie, czy meteory i pociski są poza granicami ekranu
|
||||
update_meteors();
|
||||
update_hearts();
|
||||
update_power_ups();
|
||||
update_debuffs();
|
||||
ship->updateBullets();
|
||||
|
||||
window->draw(ship->getSprite());
|
||||
|
||||
for (auto &meteor: getMeteors()) {
|
||||
if (ship->getSprite().getGlobalBounds().intersects(meteor.getSprite().getGlobalBounds())) {
|
||||
ship->takeDamage();
|
||||
}
|
||||
check_Meteor_collisions();
|
||||
check_Heart_collisions();
|
||||
check_PowerUp_collisions();
|
||||
check_Debuff_collisions();
|
||||
|
||||
|
||||
// TODO: Dodać flagę aby warunek był sprawdzany nie tylko pod kątem Timeru ale również pod kątem ustawionej flagi
|
||||
if (movingSpeedPUTimer.getElapsedTime().asSeconds() >= 5.0f && powerUpCollected.movingSpeed) {
|
||||
powerUpCollected.movingSpeed = false;
|
||||
ship->setMovingSpeed(8.0f);
|
||||
}
|
||||
if (fireratePUTimer.getElapsedTime().asSeconds() >= 10.0f && powerUpCollected.firerate) {
|
||||
powerUpCollected.firerate = false;
|
||||
ship->setFirerate(200);
|
||||
}
|
||||
if (tripleShotPUTimer.getElapsedTime().asSeconds() >= 5.0f && powerUpCollected.tripleShot) {
|
||||
powerUpCollected.tripleShot = false;
|
||||
ship->setTripleShot(false);
|
||||
}
|
||||
if (movingSpeedDebuffTimer.getElapsedTime().asSeconds() >= 5.0f && debuffCollected.movingSpeed) {
|
||||
debuffCollected.movingSpeed = false;
|
||||
ship->setMovingSpeed(8.0f);
|
||||
}
|
||||
if (firerateDebuffTimer.getElapsedTime().asSeconds() >= 5.0f && debuffCollected.firerate) {
|
||||
debuffCollected.firerate = false;
|
||||
ship->setFirerate(200);
|
||||
}
|
||||
if (bulletSpeedDebuffTimer.getElapsedTime().asSeconds() >= 5.0f && debuffCollected.bulletSpeed) {
|
||||
debuffCollected.bulletSpeed = false;
|
||||
ship->setBulletSpeed(10.0f);
|
||||
}
|
||||
|
||||
if (!ship->isAlive()) {
|
||||
handleUltimate();
|
||||
|
||||
if (gameOver) {
|
||||
sf::RenderWindow errorWindow(sf::VideoMode(350, 200), "The end");
|
||||
sf::Font font;
|
||||
if (!font.loadFromFile("../assets/fonts/arial.ttf")) {
|
||||
@@ -185,6 +308,40 @@ void Plansza::update() {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
@@ -283,6 +440,107 @@ void Plansza::update() {
|
||||
}
|
||||
}
|
||||
|
||||
// Aktualizacja bossa
|
||||
if (boss && boss->isAlive()) {
|
||||
boss->update();
|
||||
window->draw(boss->getSprite());
|
||||
|
||||
// Kolizje bossa z pociskami
|
||||
for (auto bulletIt = ship->getBullets().begin(); bulletIt != ship->getBullets().end();) {
|
||||
if (boss->getSprite().getGlobalBounds().intersects(bulletIt->getSprite().getGlobalBounds())) {
|
||||
boss->takeDamage();
|
||||
bulletIt = ship->getBullets().erase(bulletIt);
|
||||
} else {
|
||||
++bulletIt;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto rocketIt = ship->getRockets().begin(); rocketIt != ship->getRockets().end();) {
|
||||
if (boss->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
||||
boss->takeDamage();
|
||||
rocketIt = ship->getRockets().erase(rocketIt);
|
||||
std::cout << "Rocket hit boss! Boss HP: " << boss->getHP() << std::endl;
|
||||
} else {
|
||||
++rocketIt;
|
||||
}
|
||||
}
|
||||
|
||||
// Kolizja bossa z graczem
|
||||
// if (ship->getSprite().getGlobalBounds().intersects(boss->getSprite().getGlobalBounds())) {
|
||||
// ship->takeDamage();
|
||||
// }
|
||||
} else if (bossSpawned && (!boss || !boss->isAlive())) {
|
||||
std::cout << "Boss defeated!" << std::endl;
|
||||
delete boss;
|
||||
boss = nullptr;
|
||||
bossSpawned = false; // Resetowanie flagi, jeśli boss został pokonany
|
||||
}
|
||||
|
||||
// Obsługa pocisków bossa
|
||||
if (boss && boss->isAlive()) {
|
||||
for (auto it = boss->getBullets().begin(); it != boss->getBullets().end();) {
|
||||
if (ship->getSprite().getGlobalBounds().intersects(it->getSprite().getGlobalBounds())) {
|
||||
ship->takeDamage();
|
||||
it = boss->getBullets().erase(it); // Usuwanie pocisku po trafieniu
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
// Obsługa bomb bossa
|
||||
for (auto it = boss->getBombs().begin(); it != boss->getBombs().end();) {
|
||||
if (ship->getSprite().getGlobalBounds().intersects(it->getSprite().getGlobalBounds())) {
|
||||
ship->takeDamage();
|
||||
it = boss->getBombs().erase(it); // Usuwanie bomby po trafieniu
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (boss->isShooting() && boss->getBeam() != nullptr) {
|
||||
if (ship->getSprite().getGlobalBounds().intersects(boss->getBeam()->getSprite().getGlobalBounds())) {
|
||||
ship->takeDamage(); // Gracz otrzymuje obrażenia
|
||||
}
|
||||
}
|
||||
|
||||
// Sprawdzenie kolizji pocisków gracza z bombami Bossa
|
||||
for (auto bombIt = boss->getBombs().begin(); bombIt != boss->getBombs().end();) {
|
||||
bool bombHit = false;
|
||||
for (auto bulletIt = ship->getBullets().begin(); bulletIt != ship->getBullets().end();) {
|
||||
if (bombIt->getSprite().getGlobalBounds().intersects(bulletIt->getSprite().getGlobalBounds())) {
|
||||
ship->getBullets().erase(bulletIt);
|
||||
bombIt = boss->getBombs().erase(bombIt);
|
||||
bombHit = true;
|
||||
break;
|
||||
} else {
|
||||
++bulletIt;
|
||||
}
|
||||
}
|
||||
if (!bombHit) {
|
||||
++bombIt;
|
||||
}
|
||||
}
|
||||
|
||||
// Sprawdzenie kolizji rakiet gracza z bombami Bossa
|
||||
for (auto bombIt = boss->getBombs().begin(); bombIt != boss->getBombs().end();) {
|
||||
bool bombHit = false;
|
||||
for (auto rocketIt = ship->getRockets().begin(); rocketIt != ship->getRockets().end();) {
|
||||
if (bombIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
||||
ship->getRockets().erase(rocketIt);
|
||||
bombIt = boss->getBombs().erase(bombIt);
|
||||
bombHit = true;
|
||||
break;
|
||||
} else {
|
||||
++rocketIt;
|
||||
}
|
||||
}
|
||||
if (!bombHit) {
|
||||
++bombIt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (auto &enemy: enemies) {
|
||||
enemy.shoot();
|
||||
@@ -331,7 +589,7 @@ void Plansza::update() {
|
||||
if (playerBulletIt->getSprite().getGlobalBounds().intersects(it->getSprite().getGlobalBounds())) {
|
||||
// Usuń pocisk Bombera i pocisk gracza
|
||||
it = bomberEnemy.getBullets().erase(it);
|
||||
playerBulletIt = ship->getBullets().erase(playerBulletIt);
|
||||
ship->getBullets().erase(playerBulletIt);
|
||||
bulletDestroyed = true;
|
||||
break;
|
||||
} else {
|
||||
@@ -345,7 +603,7 @@ void Plansza::update() {
|
||||
if (rocketIt->getSprite().getGlobalBounds().intersects(it->getSprite().getGlobalBounds())) {
|
||||
// Usuń pocisk Bombera i rakietę gracza
|
||||
it = bomberEnemy.getBullets().erase(it);
|
||||
rocketIt = ship->getRockets().erase(rocketIt);
|
||||
ship->getRockets().erase(rocketIt);
|
||||
bulletDestroyed = true;
|
||||
break;
|
||||
} else {
|
||||
@@ -370,16 +628,16 @@ void Plansza::update() {
|
||||
for (auto &wiazkowiec: WEnemies) {
|
||||
wiazkowiec.update();
|
||||
|
||||
if (wiazkowiec.isShooting() && wiazkowiec.getBeam().isVisible()) {
|
||||
if (ship->getSprite().getGlobalBounds().intersects(wiazkowiec.getBeam().getBounds())) {
|
||||
if (wiazkowiec.isShooting()) {
|
||||
if (ship->getSprite().getGlobalBounds().intersects(wiazkowiec.getBeam()->getSprite().getGlobalBounds())) {
|
||||
ship->takeDamage(); // Gracz otrzymuje obrażenia
|
||||
}
|
||||
}
|
||||
|
||||
window->draw(wiazkowiec.getSprite());
|
||||
wiazkowiec.render(*window);
|
||||
}
|
||||
|
||||
// TODO: naprawić to co średnio działa
|
||||
// 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();) {
|
||||
@@ -398,7 +656,7 @@ void Plansza::update() {
|
||||
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);
|
||||
ship->getBullets().erase(bulletIt);
|
||||
enemyIt->takeDamage();
|
||||
hit = true;
|
||||
break;
|
||||
@@ -417,7 +675,7 @@ void Plansza::update() {
|
||||
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);
|
||||
ship->getBullets().erase(bulletIt);
|
||||
advancedIt->takeDamage();
|
||||
hit = true;
|
||||
break;
|
||||
@@ -436,7 +694,7 @@ void Plansza::update() {
|
||||
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);
|
||||
ship->getBullets().erase(bulletIt);
|
||||
bomberIt->takeDamage();
|
||||
hit = true;
|
||||
break;
|
||||
@@ -455,7 +713,7 @@ void Plansza::update() {
|
||||
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);
|
||||
ship->getBullets().erase(bulletIt);
|
||||
kamikadzeIt->takeDamage();
|
||||
hit = true;
|
||||
break;
|
||||
@@ -474,7 +732,7 @@ void Plansza::update() {
|
||||
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);
|
||||
ship->getBullets().erase(bulletIt);
|
||||
wiazkowiecIt->takeDamage();
|
||||
hit = true;
|
||||
break;
|
||||
@@ -496,7 +754,7 @@ void Plansza::update() {
|
||||
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);
|
||||
ship->getRockets().erase(rocketIt);
|
||||
enemyIt->takeDamage();
|
||||
hit = true;
|
||||
break;
|
||||
@@ -515,7 +773,7 @@ void Plansza::update() {
|
||||
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);
|
||||
ship->getRockets().erase(rocketIt);
|
||||
advancedIt->takeDamage();
|
||||
hit = true;
|
||||
break;
|
||||
@@ -534,7 +792,7 @@ void Plansza::update() {
|
||||
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);
|
||||
ship->getRockets().erase(rocketIt);
|
||||
bomberIt->takeDamage();
|
||||
hit = true;
|
||||
break;
|
||||
@@ -553,7 +811,7 @@ void Plansza::update() {
|
||||
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);
|
||||
ship->getRockets().erase(rocketIt);
|
||||
kamikadzeIt->takeDamage();
|
||||
hit = true;
|
||||
break;
|
||||
@@ -572,7 +830,7 @@ void Plansza::update() {
|
||||
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);
|
||||
ship->getRockets().erase(rocketIt);
|
||||
wiazkowiecIt->takeDamage();
|
||||
hit = true;
|
||||
break;
|
||||
@@ -588,13 +846,42 @@ void Plansza::update() {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// Statystyka życia gracza (wyświetlanie)
|
||||
switch (ship->getHP()) {
|
||||
case 0:
|
||||
heartStats[0].setTexture(heartTextureGray);
|
||||
heartStats[1].setTexture(heartTextureGray);
|
||||
heartStats[2].setTexture(heartTextureGray);
|
||||
gameOver = true;
|
||||
break;
|
||||
case 1:
|
||||
heartStats[0].setTexture(heartTexture);
|
||||
heartStats[1].setTexture(heartTextureGray);
|
||||
heartStats[2].setTexture(heartTextureGray);
|
||||
break;
|
||||
case 2:
|
||||
heartStats[0].setTexture(heartTexture);
|
||||
heartStats[1].setTexture(heartTexture);
|
||||
heartStats[2].setTexture(heartTextureGray);
|
||||
break;
|
||||
case 3:
|
||||
heartStats[0].setTexture(heartTexture);
|
||||
heartStats[1].setTexture(heartTexture);
|
||||
heartStats[2].setTexture(heartTexture);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
for (const auto& heart: heartStats) {
|
||||
window->draw(heart);
|
||||
}
|
||||
}
|
||||
// Meteor-related niżej
|
||||
|
||||
|
||||
void Plansza::update_meteors() {
|
||||
// usuwanie meteorów które wyleciały poza ekran
|
||||
// usuwanie meteorów, które wyleciały poza ekran
|
||||
for (auto &meteor: meteors) {
|
||||
if (meteor.getStatus()) {
|
||||
meteors.erase(meteors.begin());
|
||||
@@ -602,16 +889,91 @@ void Plansza::update_meteors() {
|
||||
}
|
||||
}
|
||||
|
||||
void Plansza::update_hearts() {
|
||||
// usuwanie serduszek, które wyleciały poza ekran
|
||||
for (auto& heart : hearts) {
|
||||
if(heart.getStatus()) {
|
||||
hearts.erase(hearts.begin());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Plansza::update_power_ups() {
|
||||
for (auto& power : powerUps) {
|
||||
if(power.getStatus()) {
|
||||
powerUps.erase(powerUps.begin());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Plansza::update_debuffs() {
|
||||
for (auto& debuff : debuffs) {
|
||||
if(debuff.getStatus()) {
|
||||
debuffs.erase(debuffs.begin());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Plansza::spawn_meteor() {
|
||||
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 (meteorSpawnClock.getElapsedTime().asSeconds() > rand() % 30 + 5) { // randomowy spawn meteorytów od 10 do 1 sekundy
|
||||
if (meteors.size() < 3) { // jeśli jest mniej niż 5 meteorów na planszy
|
||||
if (rand() % 2 == 1) {
|
||||
meteors.emplace_back(RandomNumberGenerator::getRandomNumber(50, 499), -100, meteorTexture2);
|
||||
} else {
|
||||
meteors.emplace_back(RandomNumberGenerator::getRandomNumber(50, 499), -100, meteorTexture1);
|
||||
}
|
||||
}
|
||||
spawnClock.restart();
|
||||
meteorSpawnClock.restart();
|
||||
}
|
||||
}
|
||||
|
||||
void Plansza::spawn_hearts() {
|
||||
if (heartSpawnClock.getElapsedTime().asSeconds() > rand() % 26 + 5) { // randomowy spawn serduszek od 5 do 30 sekundy
|
||||
if (hearts.size() < 5) { // jeśli jest mniej niż 5 serduszek na planszy
|
||||
hearts.emplace_back(RandomNumberGenerator::getRandomNumber(50, 499), -100, heartTexture);
|
||||
}
|
||||
heartSpawnClock.restart();
|
||||
}
|
||||
}
|
||||
|
||||
void Plansza::spawn_power_up() {
|
||||
if (powerUpSpawnClock.getElapsedTime().asSeconds() > 15) {
|
||||
if (powerUps.size() < 2) {
|
||||
auto powerUpRand = rand() % 3;
|
||||
switch (powerUpRand) {
|
||||
case 0:
|
||||
powerUps.emplace_back(RandomNumberGenerator::getRandomNumber(50, 499), -100, movingSpeedPowerUpTexture, PowerUp::movingSpeedUp);
|
||||
break;
|
||||
case 1:
|
||||
powerUps.emplace_back(RandomNumberGenerator::getRandomNumber(50, 499), -100, fireratePowerUpTexture, PowerUp::firerateUp);
|
||||
break;
|
||||
case 2:
|
||||
powerUps.emplace_back(RandomNumberGenerator::getRandomNumber(50,499), -100, tripleShotPowerUpTexture, PowerUp::tripleShotUp);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
powerUpSpawnClock.restart();
|
||||
}
|
||||
}
|
||||
|
||||
void Plansza::spawn_debuff() {
|
||||
if (debuffSpawnClock.getElapsedTime().asSeconds() > 30) {
|
||||
if (debuffs.size() < 1) {
|
||||
switch (rand() % 3) {
|
||||
case 0:
|
||||
debuffs.emplace_back(RandomNumberGenerator::getRandomNumber(50, 499), -100, movingSpeedDebuffTexture, Debuff::movingSpeedDbf);
|
||||
break;
|
||||
case 1:
|
||||
debuffs.emplace_back(RandomNumberGenerator::getRandomNumber(50, 499), -100, firerateDebuffTexture, Debuff::firerateDbf);
|
||||
break;
|
||||
case 2:
|
||||
debuffs.emplace_back(RandomNumberGenerator::getRandomNumber(50,499), -100, bulletSpeedDebuffTexture, Debuff::bulletSpeedDbf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
debuffSpawnClock.restart();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -623,7 +985,7 @@ void Plansza::spawn_player() {
|
||||
}
|
||||
|
||||
void Plansza::spawn_enemy() {
|
||||
if (enemySpawnClock.getElapsedTime().asSeconds() >= 10) { // Spawn co 10 sekund
|
||||
if (enemySpawnClock.getElapsedTime().asSeconds() >= 3) { // Spawn co 3 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;
|
||||
@@ -633,7 +995,7 @@ void Plansza::spawn_enemy() {
|
||||
}
|
||||
|
||||
void Plansza::spawn_advanced_enemy() {
|
||||
if (AenemySpawnClock.getElapsedTime().asSeconds() >= 20) { // Spawn co 10 sekund
|
||||
if (AenemySpawnClock.getElapsedTime().asSeconds() >= 5) { // Spawn co 5 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;
|
||||
@@ -642,7 +1004,7 @@ void Plansza::spawn_advanced_enemy() {
|
||||
}
|
||||
|
||||
void Plansza::spawn_bomber() {
|
||||
if (BomberSpawnClock.getElapsedTime().asSeconds() >= 30) { // Spawn co 10 sekund
|
||||
if (BomberSpawnClock.getElapsedTime().asSeconds() >= 7) { // Spawn co 7 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
|
||||
@@ -653,7 +1015,7 @@ void Plansza::spawn_bomber() {
|
||||
}
|
||||
|
||||
void Plansza::spawn_kamikadze() {
|
||||
if (KamikadzeSpawnClock.getElapsedTime().asSeconds() >= 40) { // Spawn co 10 sekund
|
||||
if (KamikadzeSpawnClock.getElapsedTime().asSeconds() >= 9) { // Spawn co 9 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;
|
||||
@@ -662,13 +1024,25 @@ void Plansza::spawn_kamikadze() {
|
||||
}
|
||||
|
||||
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();
|
||||
if (WiazkowiecSpawnClock.getElapsedTime().asSeconds() >= 6) { // Spawn co 6 sekund
|
||||
if (WEnemies.size() < 1) {
|
||||
int spawnX = RandomNumberGenerator::getRandomNumber(50, size.width - 50);
|
||||
Wiazkowiec wiazkowiec(spawnX, -50, WiazkowiecTexture, window);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Plansza::spawn_boss() {
|
||||
if (!bossSpawned && score >= nextBossScoreThreshold) { // Spawn po BossThreshold i jesli go nie ma
|
||||
boss = new Boss(size.width / 2, -100, BossTexture, enemyBulletTexture, BombaTexture, window);
|
||||
boss->setPlanszaHeight(size.width, size.height);
|
||||
bossSpawned = true;
|
||||
nextBossScoreThreshold += 1000;
|
||||
std::cout << "Boss spawned at score: " << score << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -681,10 +1055,13 @@ std::vector<Meteor> &Plansza::getMeteors() {
|
||||
return meteors;
|
||||
}
|
||||
|
||||
// TODO: naliczanie punktów za zabicie wrogów
|
||||
void Plansza::update_score() {
|
||||
if (scoreClock.getElapsedTime().asMilliseconds() > 500) {
|
||||
score++;
|
||||
ultimateCounter++;
|
||||
if (ultimateCounter >= 200) {
|
||||
ultimateCounter = 200;
|
||||
}
|
||||
scoreClock.restart();
|
||||
}
|
||||
|
||||
@@ -692,4 +1069,103 @@ void Plansza::update_score() {
|
||||
text.setFillColor(sf::Color::White);
|
||||
text.setPosition(25, 25);
|
||||
window->draw(text);
|
||||
}
|
||||
}
|
||||
|
||||
void Plansza::check_PowerUp_collisions() {
|
||||
for (auto powerUpIt = powerUps.begin(); powerUpIt != powerUps.end();) {
|
||||
if (ship->getSprite().getGlobalBounds().intersects(powerUpIt->getSprite().getGlobalBounds())) {
|
||||
if (powerUpIt->getType() == PowerUp::movingSpeedUp) {
|
||||
ship->setMovingSpeed(15.0f);
|
||||
powerUpCollected.movingSpeed = true;
|
||||
movingSpeedPUTimer.restart();
|
||||
}
|
||||
if (powerUpIt->getType() == PowerUp::firerateUp) {
|
||||
ship->setFirerate(100);
|
||||
powerUpCollected.firerate = true;
|
||||
fireratePUTimer.restart();
|
||||
}
|
||||
if (powerUpIt->getType() == PowerUp::tripleShotUp) {
|
||||
ship->setTripleShot(true);
|
||||
powerUpCollected.tripleShot = true;
|
||||
tripleShotPUTimer.restart();
|
||||
}
|
||||
powerUpIt = powerUps.erase(powerUpIt);
|
||||
} else {
|
||||
++powerUpIt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Plansza::check_Debuff_collisions() {
|
||||
for (auto debuffIt = debuffs.begin(); debuffIt != debuffs.end();) {
|
||||
if (ship->getSprite().getGlobalBounds().intersects(debuffIt->getSprite().getGlobalBounds())) {
|
||||
if (debuffIt->getType() == Debuff::movingSpeedDbf) {
|
||||
ship->setMovingSpeed(4.0f);
|
||||
debuffCollected.movingSpeed = true;
|
||||
movingSpeedDebuffTimer.restart();
|
||||
}
|
||||
if (debuffIt->getType() == Debuff::firerateDbf) {
|
||||
ship->setFirerate(500);
|
||||
debuffCollected.firerate = true;
|
||||
firerateDebuffTimer.restart();
|
||||
}
|
||||
if (debuffIt->getType() == Debuff::bulletSpeedDbf) {
|
||||
ship->setBulletSpeed(5.0f);
|
||||
debuffCollected.bulletSpeed = true;
|
||||
bulletSpeedDebuffTimer.restart();
|
||||
}
|
||||
debuffIt = debuffs.erase(debuffIt);
|
||||
} else {
|
||||
++debuffIt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Plansza::check_Heart_collisions() {
|
||||
for (auto heartIt = hearts.begin(); heartIt != hearts.end();) {
|
||||
if (ship->getSprite().getGlobalBounds().intersects(heartIt->getSprite().getGlobalBounds())) {
|
||||
ship->healUP();
|
||||
heartIt = hearts.erase(heartIt);
|
||||
} else {
|
||||
++heartIt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Plansza::check_Meteor_collisions() {
|
||||
for (auto &meteor: meteors) {
|
||||
if (ship->getSprite().getGlobalBounds().intersects(meteor.getSprite().getGlobalBounds())) {
|
||||
ship->takeDamage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ships Plansza::selectedShip = none;
|
||||
unsigned int Plansza::score = 0;
|
||||
unsigned int Plansza::ultimateCounter = 0;
|
||||
|
||||
void Plansza::handleUltimate() {
|
||||
if (ship->getUltimateStatus() && ultimateCounter >= 200) {
|
||||
float elapsedTime = ultimateClock.getElapsedTime().asSeconds();
|
||||
if (ship->getUltimateStatus() && ultimateClock.getElapsedTime().asSeconds() >= 1) {
|
||||
ultimateCounter = 0;
|
||||
}
|
||||
if (elapsedTime < 1) {
|
||||
sf::RectangleShape ultimateShape(sf::Vector2f(600, 800));
|
||||
int alpha = static_cast<int>(255 * (1 - elapsedTime));
|
||||
ultimateShape.setFillColor(sf::Color(255, 255, 255, alpha));
|
||||
|
||||
meteors.clear();
|
||||
debuffs.clear();
|
||||
enemies.clear();
|
||||
AEnemies.clear();
|
||||
BEnemies.clear();
|
||||
KEnemies.clear();
|
||||
WEnemies.clear();
|
||||
|
||||
window->draw(ultimateShape);
|
||||
} else {
|
||||
ship->setUltimateStatus(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
#include "../headers/Player.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <SFML/Graphics/Font.hpp>
|
||||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
#include <SFML/Graphics/Text.hpp>
|
||||
|
||||
#include "../headers/Player.h"
|
||||
#include "../headers/Plansza.h"
|
||||
|
||||
|
||||
|
||||
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) {
|
||||
@@ -17,15 +21,31 @@ Player* Player::getInstance(int x, int y, const sf::Texture& texture) {
|
||||
}
|
||||
|
||||
void Player::loadTexture() {
|
||||
bulletTexture.loadFromFile("../assets/img/bullets/bullet_pink.png");
|
||||
rocketTexture.loadFromFile("../assets/img/rockets/Rocket_111.png");
|
||||
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() {
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
if (std::chrono::duration_cast<std::chrono::milliseconds>(now - lastShotTime).count() >= firerate) {
|
||||
bullets.emplace_back(position.x, position.y, bulletTexture);
|
||||
lastShotTime = now;
|
||||
if (tripleShot == true) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +58,10 @@ 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) {
|
||||
@@ -59,24 +83,16 @@ void Player::update() {
|
||||
|
||||
void Player::takeDamage() {
|
||||
if (!isImmortal) {
|
||||
if (health > 0) {
|
||||
health--;
|
||||
std::cout << "Player hit! Remaining health: " << health << "\n";
|
||||
if (hp > 0) {
|
||||
hp--;
|
||||
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::setTripleShot(bool toogle) {
|
||||
tripleShot = toogle;
|
||||
}
|
||||
|
||||
void Player::setFirerate(unsigned int firerate) {
|
||||
@@ -111,4 +127,17 @@ std::vector<Rocket> &Player::getRockets() {
|
||||
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,7 +2,7 @@
|
||||
|
||||
void Rocket::update() {
|
||||
sprite.move(0.0f, speed);
|
||||
position.y += int(speed);
|
||||
position.y += static_cast<int>(speed);
|
||||
if(position.y < -100) {
|
||||
outOfBounds = true;
|
||||
}
|
||||
|
||||
@@ -1,56 +1,60 @@
|
||||
#include "../headers/Wiazkowiec.h"
|
||||
#include "../headers/Plansza.h"
|
||||
#include "../headers/RandomNumberGenerator.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);
|
||||
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(float height, float width) {
|
||||
void Wiazkowiec::setPlanszaHeight(int height, int width) {
|
||||
planszaHeight = height;
|
||||
planszaWidth = width;
|
||||
}
|
||||
|
||||
void Wiazkowiec::spawnBeam() {
|
||||
float beamX = position.x;
|
||||
float beamY = position.y;
|
||||
float beamWidth = 50.f;
|
||||
float beamHeight = 0.f;
|
||||
int beamX = actorSprite.getPosition().x;
|
||||
int beamY = actorSprite.getPosition().y;
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
||||
beam.setVisible(true);
|
||||
|
||||
shooting = true;
|
||||
shootingClock.restart();
|
||||
}
|
||||
@@ -59,31 +63,53 @@ void Wiazkowiec::spawnBeam() {
|
||||
void Wiazkowiec::shoot() {
|
||||
if (!shooting) {
|
||||
spawnBeam();
|
||||
std::cout << "Wiazkowiec shot a beam!" << std::endl;
|
||||
}
|
||||
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 directionIndex = std::rand() % 4;
|
||||
|
||||
switch (directionIndex) {
|
||||
int whatNumber = rand() % 4;
|
||||
|
||||
switch (whatNumber) {
|
||||
case 0:
|
||||
direction = DirectionW::Up;
|
||||
break;
|
||||
break;
|
||||
case 1:
|
||||
direction = DirectionW::Down;
|
||||
break;
|
||||
break;
|
||||
case 2:
|
||||
direction = DirectionW::Left;
|
||||
break;
|
||||
break;
|
||||
case 3:
|
||||
direction = DirectionW::Right;
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Wiazkowiec::updateDirection() {
|
||||
void Wiazkowiec::checkIfBeamShootOutOfBounds() {
|
||||
auto spriteBounds = actorSprite.getGlobalBounds(); // Pobierz rozmiar i pozycję sprite'a
|
||||
|
||||
// Kontrola górnej i dolnej krawędzi
|
||||
@@ -106,17 +132,17 @@ 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);
|
||||
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 (position.y + deltaY < 0) {
|
||||
deltaY = -position.y;
|
||||
} else if (position.y + spriteBounds.height + deltaY > planszaHeight) {
|
||||
deltaY = planszaHeight - (position.y + spriteBounds.height);
|
||||
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);
|
||||
@@ -133,42 +159,39 @@ void Wiazkowiec::update() {
|
||||
if (shooting) {
|
||||
// Kontrola zakończenia strzału
|
||||
if (shootingClock.getElapsedTime().asSeconds() >= beamDuration) {
|
||||
beam.setVisible(false);
|
||||
shooting = false;
|
||||
delete beam;
|
||||
beam = nullptr;
|
||||
setRandomDirection(); // Zmień kierunek po strzale
|
||||
} else {
|
||||
window_ptr->draw(beam->getSprite());
|
||||
}
|
||||
} else {
|
||||
updateDirection();
|
||||
checkIfBeamShootOutOfBounds();
|
||||
|
||||
switch (direction) {
|
||||
case DirectionW::Up:
|
||||
moveUp();
|
||||
break;
|
||||
break;
|
||||
case DirectionW::Down:
|
||||
moveDown();
|
||||
break;
|
||||
break;
|
||||
case DirectionW::Left:
|
||||
moveLeft();
|
||||
break;
|
||||
break;
|
||||
case DirectionW::Right:
|
||||
moveRight();
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
if (shootClock.getElapsedTime().asSeconds() >= 3.0f) { // Co 3 sekundy
|
||||
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;
|
||||
}
|
||||
@@ -176,6 +199,8 @@ bool Wiazkowiec::isAlive() const {
|
||||
void Wiazkowiec::takeDamage() {
|
||||
if (--hp <= 0) {
|
||||
alive = false;
|
||||
Plansza::score += 10;
|
||||
Plansza::ultimateCounter += 10;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,6 +208,6 @@ bool Wiazkowiec::isShooting() const {
|
||||
return shooting;
|
||||
}
|
||||
|
||||
const Beam& Wiazkowiec::getBeam() const {
|
||||
Beam* Wiazkowiec::getBeam() const {
|
||||
return beam;
|
||||
}
|
||||
}
|
||||
|
||||