50 Commits

Author SHA1 Message Date
bafab8d75a counter fixed at 200 2025-01-16 21:31:34 +01:00
92d5f66a91 ultimate implemented 2025-01-16 21:27:14 +01:00
622e814d1c WIP - ultimate 2025-01-16 20:16:08 +01:00
0834460e82 Merge branch 'BossV1'
# Conflicts:
#	CMakeLists.txt
#	headers/Plansza.h
#	sources/Plansza.cpp
2025-01-16 08:01:02 +01:00
ff562d4d92 usunięcie zduplikowanego wpisu 2025-01-15 23:21:54 +01:00
c332b7e729 adjust timings 2025-01-15 23:13:56 +01:00
44f56e2035 Merge remote-tracking branch 'origin/debuff' 2025-01-15 23:12:58 +01:00
898671a72a Poprawiono kolizje bomb z pociskami gracza 2025-01-15 21:58:20 +01:00
0ea80559e5 Boss poprawnie reaguje z rakietami 2025-01-15 19:40:08 +01:00
6a833f5698 Merge remote-tracking branch 'origin/BossV1' into BossV1 2025-01-14 15:38:14 +01:00
2539892b71 Boss nie wylazi 2025-01-14 15:38:02 +01:00
17a1d3689b todo added 2025-01-14 14:45:13 +01:00
8b8bfc9aed Merge remote-tracking branch 'origin/BossV1' into BossV1 2025-01-14 14:11:42 +01:00
b833a21dbb Tekstura bossa 2025-01-14 14:09:28 +01:00
2e02b17cc7 dodano laser 2025-01-14 14:09:18 +01:00
f2426f5930 dodano sprite 2025-01-14 14:05:38 +01:00
7d2b8bd9a2 Kolizja wiazki dodana 2025-01-14 13:52:58 +01:00
baced5f971 Kolizja wiazki dodana 2025-01-14 13:52:05 +01:00
629b1279a9 Boss utworzony, strzela, bombuje, wiazkuje(#KolizjaToDo) 2025-01-13 23:59:18 +01:00
7a808d46a6 Debuffs fully implemented 2025-01-13 23:24:43 +01:00
67f396ae84 Zaimplementowano debuff.
Do dokończenia resetowanie debuff
2025-01-13 15:55:45 +01:00
62808a9fbf Zaimplementowano pauze 2025-01-09 12:11:56 +01:00
5ad7cc9d1e Merge branch 'powerup' 2025-01-07 10:32:50 +01:00
4d2283d15e powerups fully implemented 2025-01-06 16:17:38 +01:00
236ddd828d Merge branch 'refactor' 2025-01-06 11:51:33 +01:00
b1b5858fb6 Dziala powerup na prędkość poruszania się 2025-01-06 01:31:59 +01:00
3d83a3a767 powerup init commit 2025-01-05 18:35:39 +01:00
6b45443c75 Laser naprawiono 2025-01-05 18:20:19 +01:00
3e2d37cf72 Update README.md 2025-01-03 17:28:54 +01:00
c4c83382c3 Do poprawy centrowanie lasera i strzelanie w lewo i w prawo 2024-12-20 23:38:37 +01:00
0a5a26208a wip 2024-12-20 19:39:18 +01:00
76203a8b29 refactor 2024-12-19 16:01:21 +01:00
36984b859f Naprawiono laser, przerobiono na wskaźniki. Do refactoringu i poprawy sprite'a 2024-12-19 15:14:14 +01:00
15a8d82176 fix serduszek 2024-12-14 20:47:02 +01:00
5459b97e74 poprawniony spawn serduszek 2024-12-14 20:38:50 +01:00
94eddb457f Implementacja naliczania punktów za zabicie wrogów 2024-12-14 20:32:08 +01:00
9432cd94fe Zaimplementowane menu i wybieranie skinów statku 2024-12-14 20:21:46 +01:00
34424da9d6 refactor ciąg dalszy 2024-12-13 20:13:52 +01:00
80a4b1b397 Złączono i wszystko działa, ale trzeba zrobić mocny refactor Planszy bo za dużo niewiadomo skąd biorących się pętli 2024-12-13 20:05:11 +01:00
fdf67f4bc2 Merge remote-tracking branch 'origin/serduszka'
# Conflicts:
#	CMakeLists.txt
#	headers/Actor.h
#	headers/Plansza.h
#	headers/Player.h
#	sources/Plansza.cpp
#	sources/Player.cpp
2024-12-13 19:48:39 +01:00
8b4b25747e Zmiana sposobu tworzenia gracza.
Użyto singleton pattern.
Zmieniono konstruktor klasy Plansza
2024-12-13 13:36:41 +01:00
3f4a937257 Zamiana tekstur 2024-12-13 09:34:40 +01:00
d87143d98b Drobne poprawki 2024-12-13 09:16:03 +01:00
1298bab79a Usunięcie zbędnych rzeczy 2024-12-12 22:51:25 +01:00
9929a5dd40 Merge remote-tracking branch 'origin/5PrzeciwnikowWmiareDziala'
# Conflicts:
#	headers/Plansza.h
#	sources/Plansza.cpp
2024-12-12 22:28:09 +01:00
da33fcc718 Adjustin hearts to be in right upper corner due to score counter in left upper corner 2024-12-10 20:37:10 +01:00
74c739a09e Dodano podstawowy licznik 2024-12-10 20:30:31 +01:00
71f8ebe285 Statek miga
przy uderzeniu w meteoryt
2024-12-06 15:16:57 +01:00
2f9e0ba236 Serduszka działają
do zrobienia jeszcze animacja uderzenia się w meteoryt (miganie) i wybuch statku przy uderzeniu się w meteoryt po raz trzeci
2024-12-06 12:24:39 +01:00
3b637508e1 Added heart and spawn of them 2024-12-05 14:52:00 +01:00
62 changed files with 1671 additions and 534 deletions

View File

@@ -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)

View File

@@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.3 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 958 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

BIN
assets/img/wiazka/laser.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 773 B

BIN
assets/ship/nova.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB

BIN
assets/ship/pulsar.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 KiB

BIN
assets/ship/zenith.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 221 KiB

View File

@@ -5,17 +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);
void loadTexture(std::string path);
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;
@@ -24,23 +25,23 @@ public:
virtual void moveDown() = 0;
virtual void shoot() = 0;
std::vector<Bullet>& getBullets();
void updateBullets();
void setMovingSpeed(float speed);
void dealDamage();
void healUP();
protected:
Position position;
sf::Sprite actorSprite;
sf::Texture actorTexture;
sf::Texture bulletTextureLeft;
sf::Texture bulletTextureRight;
Position position;
unsigned int hp;
sf::Texture bulletTexture;
sf::Texture rocketTexture;
std::vector<Bullet> bullets;
sf::Clock damageDealClock;
int hp;
unsigned int damage;
unsigned int firerate;
float moving_speed;
std::vector<Bullet> bullets;
};
#endif //ACTOR_H

View File

@@ -3,8 +3,6 @@
#include "Enemy.h"
#include <cmath>
enum class DirectionA {
Up,
Down,

View File

@@ -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
View 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

View File

@@ -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
View 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
View 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

View File

@@ -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();
};

View File

@@ -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;

View File

@@ -1,75 +1,156 @@
#ifndef PLANSZA_H
#define PLANSZA_H
#include "SFML/System/Clock.hpp"
#include "SFML/Graphics/RenderWindow.hpp"
#include "Meteor.h"
#include "Enemy.h"
#include "AdvancedEnemy.h"
#include "Bomber.h"
#include "Kamikadze.h"
#include "Wiazkowiec.h"
#include "Beam.h"
#include "RandomNumberGenerator.h"
#include "SFML/System/Clock.hpp"
#include "SFML/Graphics/RenderWindow.hpp"
#include "Size.h"
#include <memory>
#include "Player.h"
#include "Background.h"
#include "AudioManager.h"
#include "Meteor.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,
const sf::Texture& playerTexture, const sf::Texture& playerBulletTexture, const sf::Texture& playerRocketTexture);
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 check_PowerUp_collisions();
void check_Heart_collisions();
void check_Meteor_collisions();
void check_Debuff_collisions();
void handleUltimate();
void spawn_player();
void spawn_enemy();
void setOutOfBounds(bool status);
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:
Size size;
Background background;
Player ship;
AudioManager audioManager;
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;
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;
std::vector<Enemy> enemies;
std::vector<AdvancedEnemy> AEnemies;
std::vector<Bomber> BEnemies;
std::vector<Kamikadze> KEnemies;
std::vector<Wiazkowiec> WEnemies;
sf::Clock enemySpawnClock;
sf::Clock AenemySpawnClock;
sf::Clock BomberSpawnClock;
sf::Clock KamikadzeSpawnClock;
sf::Clock WiazkowiecSpawnClock;
//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;
// 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;
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

View File

@@ -9,11 +9,20 @@
#include "Rocket.h"
class Player : public Actor {
// Zgodnie z refactoring.guru singleton pattern
// https://refactoring.guru/design-patterns/singleton/cpp/example
protected:
Player(int x, int y, const sf::Texture &texture);
static Player* player_;
public:
Player(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture, const sf::Texture& rocketTexture);
void setTextures(const sf::Texture& shipTexture, const sf::Texture& bulletTexture, const sf::Texture& rocketTexture);
Player(Player &other) = delete;
void operator=(const Player &) = delete;
static Player* getInstance(int x, int y, const sf::Texture &texture);
// Tu się kończy definicja singletona
void shoot() override;
void alternate_shoot();
void ultimate_shoot();
void setFirerate(unsigned int firerate);
void move(float deltaX, float deltaY) override;
void moveLeft() override;
@@ -21,18 +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;
int health = 3; // Liczba punktów życia gracza
sf::Texture bulletTexture;
bool isImmortal = false; // flaga na immortal
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;
};

View File

@@ -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
View 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

View File

@@ -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

193
main.cpp
View File

@@ -3,16 +3,14 @@
#include "headers/Plansza.h"
int main()
{
ships selectedShip = none;
void menu();
int main() {
menu();
std::clog << "Game started\n";
sf::Texture playerTexture, playerBulletTexture, playerRocketTexture;
if (!playerTexture.loadFromFile("../assets/ship/Dreadnought-Base.png") ||
!playerBulletTexture.loadFromFile("../assets/img/bullets/bullet_pink.png") ||
!playerRocketTexture.loadFromFile("../assets/img/rockets/Rocket_111.png")) {
std::cerr << "Failed to load player textures!" << std::endl;
return -1;
}
sf::RenderWindow mainWindow(sf::VideoMode(600, 800), "LotoStatek");
mainWindow.setVerticalSyncEnabled(true);
mainWindow.setFramerateLimit(60);
@@ -21,9 +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,playerTexture, playerBulletTexture, playerRocketTexture);
Plansza plansza(mainWindow.getSize().y, mainWindow.getSize().x, &mainWindow, selectedShip);
while (mainWindow.isOpen()) {
mainWindow.clear();
@@ -31,14 +29,179 @@ int main()
// Tu są handlowane eventy
sf::Event 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();
}
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();
}
}

View File

@@ -10,14 +10,6 @@ Actor::Actor(int x, int y, const sf::Texture& texture) {
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() {
if (!actorSprite.getTexture()) {
std::cerr << "actorSprite has no texture set!" << std::endl;
@@ -29,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;
}
@@ -47,4 +58,4 @@ void Actor::updateBullets() {
void Actor::setMovingSpeed(float speed) {
moving_speed = speed;
}
}

View File

@@ -1,8 +1,8 @@
#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
@@ -85,5 +85,7 @@ bool AdvancedEnemy::isAlive() const {
void AdvancedEnemy::takeDamage() {
if (--hp <= 0) {
alive = false;
Plansza::score += 10;
Plansza::ultimateCounter += 10;
}
}

View File

@@ -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);
}

View File

@@ -1,9 +1,9 @@
#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
@@ -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
View 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;
}
}

View File

@@ -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
View 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ą
}
}

View File

@@ -1,8 +1,8 @@
#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ść
@@ -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
View 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ą
}
}

View File

@@ -1,12 +1,12 @@
#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ść
}
@@ -130,5 +130,7 @@ bool Kamikadze::isAlive() const {
void Kamikadze::takeDamage() {
if (--hp <= 0) {
alive = false;
Plansza::score += 20;
Plansza::ultimateCounter += 20;
}
}

View File

@@ -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);

View File

@@ -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() {

File diff suppressed because it is too large Load Diff

View File

@@ -1,27 +1,51 @@
#include "../headers/Player.h"
#include <iostream>
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/Text.hpp>
#include "../headers/Bullet.h"
#include "../headers/Player.h"
#include "../headers/Plansza.h"
Player::Player(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture, const sf::Texture& rocketTexture) : Actor(x, y, texture), bulletTexture(bulletTexture), rocketTexture(rocketTexture) {
};
void Player::setTextures(const sf::Texture& shipTexture, const sf::Texture& bulletTexture, const sf::Texture& rocketTexture) {
this->actorSprite.setTexture(shipTexture); // Poprawiona nazwa - actorSprite zamiast shipSprite
this->bulletTexture = bulletTexture;
this->rocketTexture = rocketTexture;
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() {
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;
}
}
}
@@ -34,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) {
@@ -55,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) {
@@ -106,3 +126,18 @@ void Player::moveDown() {
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
View 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ą
}
}

View File

@@ -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;
}

View File

@@ -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;
}
}