1 Commits

Author SHA1 Message Date
8db6b8572d emmmm, strzal niby jest w bullecie, ale chujowo to dziala 2024-12-04 23:33:21 +01:00
79 changed files with 252 additions and 3018 deletions

View File

@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.25)
project(LotoStatek)
include(FetchContent)
set(CMAKE_CXX_STANDARD 17)
add_executable(LotoStatek main.cpp
@@ -25,30 +25,7 @@ add_executable(LotoStatek main.cpp
headers/Rocket.h
sources/Rocket.cpp
headers/Size.h
headers/Position.h
headers/ObjectItem.hpp
sources/ObjectItem.cpp
sources/Enemy.cpp
headers/Enemy.h
headers/AdvancedEnemy.h
sources/AdvancedEnemy.cpp
headers/Bomber.h
sources/Bomber.cpp
headers/Kamikadze.h
sources/Kamikadze.cpp
headers/wiazkowiec.h
sources/Wiazkowiec.cpp
headers/Beam.h
sources/Beam.cpp
headers/Heart.hpp
sources/Heart.cpp
headers/PowerUp.h
sources/PowerUp.cpp
headers/Debuff.h
sources/Debuff.cpp
sources/Boss.cpp
headers/Boss.h
)
headers/Position.h)
if(WIN32)
set(SFML_ROOT "${CMAKE_SOURCE_DIR}/lib/SFML")
@@ -63,12 +40,9 @@ if(WIN32)
target_link_libraries(LotoStatek ${SFML_LIBRARIES})
endif()
elseif(APPLE)
set(BUILD_SHARED_LIBS OFF)
FetchContent_Declare(
SFML
GIT_REPOSITORY https://github.com/SFML/SFML.git
GIT_TAG 2.6.2
)
FetchContent_MakeAvailable(SFML)
find_package(lib/SFML 2.6.2 COMPONENTS graphics window system REQUIRED)
target_link_libraries(LotoStatek sfml-graphics sfml-window sfml-audio sfml-system)
elseif(LINUX)
find_package(lib/SFML 2.6.2 COMPONENTS graphics window system REQUIRED)
target_link_libraries(LotoStatek sfml-graphics sfml-window sfml-audio sfml-system)
endif()

View File

@@ -1,11 +1 @@
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.
Tu będzie lotoł statek

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 782 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 958 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 773 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 154 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 188 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 221 KiB

Binary file not shown.

Binary file not shown.

View File

@@ -5,18 +5,17 @@
#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;
Actor(int x, int y, std::string path);
void loadTexture(std::string path);
sf::Sprite& getSprite();
unsigned int getHP();
Position getPosition();
std::vector<Bullet>& getBullets();
virtual void move(float deltaX, float deltaY) = 0;
virtual void moveLeft() = 0;
@@ -25,23 +24,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 bulletTexture;
sf::Texture rocketTexture;
std::vector<Bullet> bullets;
sf::Clock damageDealClock;
int hp;
sf::Texture bulletTextureLeft;
sf::Texture bulletTextureRight;
Position position;
unsigned int hp;
unsigned int damage;
unsigned int firerate;
float moving_speed;
std::vector<Bullet> bullets;
};
#endif //ACTOR_H

View File

@@ -1,37 +0,0 @@
#ifndef ADVANCED_ENEMY_H
#define ADVANCED_ENEMY_H
#include "Enemy.h"
enum class DirectionA {
Up,
Down,
Left,
Right
};
class AdvancedEnemy : public Actor {
public:
AdvancedEnemy(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture);
void shoot() override;
void move(float deltaX, float deltaY) override;
void moveLeft() override;
void moveRight() override;
void moveUp() override;
void moveDown() override;
void update();
bool isAlive() const;
void takeDamage();
void updateDirection();
private:
sf::Clock shootClock;
sf::Texture enemyBulletTexture;
float movementSpeed = 2.0f;
bool alive = true;
DirectionA direction = DirectionA::Down;
};
#endif // ADVANCED_ENEMY_H

View File

@@ -1,18 +0,0 @@
#ifndef LOTOSTATEK_BEAM_H
#define LOTOSTATEK_BEAM_H
#include <SFML/Graphics.hpp>
class Beam {
public:
Beam() = default;
Beam(int x, int y, const sf::Texture &texture);
sf::Sprite getSprite();
void setRotation(float angle);
private:
sf::Sprite beamSprite;
};
#endif // LOTOSTATEK_BEAM_H

View File

@@ -1,45 +0,0 @@
//
// Created by k on 11.12.2024.
//
#ifndef BOMBER_H
#define BOMBER_H
#include "Enemy.h"
#include "Actor.h"
enum class DirectionB {
Up,
Down,
Left,
Right
};
class Bomber : public Actor {
public:
Bomber(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture);
void shoot() override;
void move(float deltaX, float deltaY) override;
void moveLeft() override;
void moveRight() override;
void moveUp() override;
void moveDown() override;
void setRandomDirection();
void update();
bool isAlive() const;
void takeDamage();
void updateDirection();
void setPlanszaHeight(float height, float width);
private:
float planszaHeight = 800.f;
float planszaWidth = 600.f;
sf::Clock shootClock;
sf::Texture BombaTexture;
float movementSpeed = 2.0f;
bool alive = true;
DirectionB direction = DirectionB::Down;
};
#endif //BOMBER_H

View File

@@ -1,72 +0,0 @@
#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

@@ -1,16 +1,23 @@
#ifndef LOTOSTATEK_BULLET_H
#define LOTOSTATEK_BULLET_H
#include "Projectile.h"
#include "SFML/Graphics/Texture.hpp"
#include "SFML/Audio/Sound.hpp"
#include "SFML/Audio/SoundBuffer.hpp"
class Bullet : public Projectile {
public:
Bullet(float x, float y, sf::Texture &texture);
Bullet(float x, float y, sf::Texture &texture, float speed);
void update() override;
// Dodanie metody do odtwarzania dźwięku
void playShootSound();
private:
sf::Sound shootSound;
sf::SoundBuffer shootBuffer; // Dodanie bufora dźwięku
};
#endif //LOTOSTATEK_BULLET_H

View File

@@ -1,24 +0,0 @@
#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

View File

@@ -1,39 +0,0 @@
#ifndef ENEMY_H
#define ENEMY_H
#include "Actor.h"
#include "SFML/System/Clock.hpp"
enum class Direction {
Up,
Down,
Left,
Right
};
class Enemy : public Actor {
public:
Enemy(int x, int y, const sf::Texture& texture) ;
void shoot() override;
void move(float deltaX, float deltaY) override;
void moveLeft() override;
void moveRight() override;
void moveUp() override;
void moveDown() override;
void update();
bool isAlive() const;
void takeDamage();
void updateDirection();
private:
sf::Clock shootClock;
sf::Texture enemyBulletTexture;
float movementSpeed = 2.0f;
bool alive = true;
Direction direction = Direction::Down;
};
#endif // ENEMY_H

View File

@@ -1,13 +0,0 @@
#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

@@ -1,46 +0,0 @@
#ifndef KAMIKADZE_H
#define KAMIKADZE_H
#include "Enemy.h"
#include "Actor.h"
#include "Player.h"
enum class DirectionK {
Up,
Down,
Left,
Right
};
class Kamikadze : public Actor {
public:
Kamikadze(int x, int y, const sf::Texture& texture);
void move(float deltaX, float deltaY) override;
void moveLeft() override;
void moveRight() override;
void moveUp() override;
void moveDown() override;
void setRandomDirection();
void shoot() override;
void update(const sf::Vector2f& playerPosition);
bool isAlive() const;
bool isExploding() const;
void takeDamage();
void updateDirection();
void followPlayer(const sf::Vector2f &playerPosition);
void explode(const sf::Vector2f &playerPosition, bool &playerHit);
private:
bool exploding = false;
sf::Clock explosionClock;
sf::Clock shootClock;
float movementSpeed = 2.0f;
bool alive = true;
DirectionK direction = DirectionK::Down;
};
#endif //KAMIKADZE_H

View File

@@ -4,12 +4,22 @@
#include "SFML/Graphics/Texture.hpp"
#include "SFML/Graphics/Sprite.hpp"
#include "Position.h"
#include "ObjectItem.hpp"
class Meteor : public ObjectItem {
class Meteor {
public:
Meteor(float x, float y, sf::Texture &texture_);
Meteor(float x, float y, sf::Texture &texture);
sf::Sprite &getSprite();
bool getStatus();
void update();
// ~Meteor();
private:
sf::Texture meteorTexture;
sf::Sprite meteorSprite;
Position meteorPosition;
float meteorRotationSpeed;
float meteorSpeed;
bool outOfBounds;
static unsigned int counter;
};

View File

@@ -1,25 +0,0 @@
#ifndef LOTOSTATEK_OBJECTITEM_HPP
#define LOTOSTATEK_OBJECTITEM_HPP
#include "SFML/Graphics/Sprite.hpp"
#include "Position.h"
#include "SFML/Graphics/Texture.hpp"
class ObjectItem {
public:
virtual ~ObjectItem() = default;
ObjectItem(float x, float y, sf::Texture &texture);
sf::Sprite &getSprite();
bool getStatus();
virtual void update() = 0;
protected:
sf::Texture texture_;
sf::Sprite sprite;
Position position;
float rotationSpeed;
float movingSpeed;
bool outOfBounds;
static unsigned int counter;
};
#endif //LOTOSTATEK_OBJECTITEM_HPP

View File

@@ -1,160 +1,36 @@
#ifndef PLANSZA_H
#define PLANSZA_H
#include "Meteor.h"
#include "RandomNumberGenerator.h"
#include "SFML/System/Clock.hpp"
#include "SFML/Graphics/RenderWindow.hpp"
#include "Size.h"
#include "Meteor.h"
#include "Enemy.h"
#include "AdvancedEnemy.h"
#include "Bomber.h"
#include "Kamikadze.h"
#include "Wiazkowiec.h"
#include "Player.h"
#include "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, ships selectedShip);
Plansza(unsigned int windowHeight,unsigned int windowWidth, sf::RenderWindow *mainWindow);
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 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:
Background background;
AudioManager audioManager;
Player *ship;
Size size;
sf::RenderWindow *window;
// Timers
sf::Clock movingSpeedPUTimer;
sf::Clock fireratePUTimer;
sf::Clock tripleShotPUTimer;
sf::Clock movingSpeedDebuffTimer;
sf::Clock firerateDebuffTimer;
sf::Clock bulletSpeedDebuffTimer;
// Zegary
sf::Clock meteorSpawnClock;
sf::Clock heartSpawnClock;
sf::Clock powerUpSpawnClock;
sf::Clock debuffSpawnClock;
sf::Clock ultimateClock;
sf::Clock scoreClock;
sf::Clock shooterSpawnClock;
sf::Clock enemySpawnClock;
sf::Clock AenemySpawnClock;
sf::Clock BomberSpawnClock;
sf::Clock KamikadzeSpawnClock;
sf::Clock WiazkowiecSpawnClock;
//Textury
sf::Texture playerTexture;
sf::Texture playerBulletTexture;
sf::Texture playerRocketTexture;
sf::Texture enemyTexture;
sf::Texture enemyBulletTexture;
sf::Texture advancedEnemyTexture;
sf::Texture BomberEnemyTexture;
sf::Texture BombaTexture;
sf::Texture BossTexture;
sf::Texture KamikadzeTexture;
sf::Texture WiazkowiecTexture;
sf::Texture WiazkaTexture;
Background background;
Player ship;
AudioManager audioManager;
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;
sf::Clock spawnClock;
std::vector<Meteor> meteors;
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;
sf::RenderWindow *window;
};
#endif //PLANSZA_H

View File

@@ -3,57 +3,26 @@
#include <chrono>
#include <SFML/System/Clock.hpp>
#include "Actor.h"
#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(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
Player(int x, int y, std::string path);
void shoot() override;
void alternate_shoot();
void ultimate_shoot();
void setFirerate(unsigned int firerate);
void move(float deltaX, float deltaY) override;
void moveLeft() override;
void moveRight() override;
void moveUp() override;
void moveDown() override;
void takeDamage();
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
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,14 +6,4 @@ struct Position {
int y;
};
struct PositionU {
unsigned int x;
unsigned int y;
};
struct PositionF {
float x;
float y;
};
#endif //LOTOSTATEK_POSITION_H

View File

@@ -1,25 +0,0 @@
#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

@@ -7,7 +7,6 @@ class Rocket : public Projectile{
public:
Rocket(float x, float y, sf::Texture &texture) : Projectile(x,y, texture) {};
void update() override;
};

View File

@@ -1,59 +0,0 @@
#ifndef WIAZKOWIEC_H
#define WIAZKOWIEC_H
#include "Enemy.h"
#include "Actor.h"
#include "Beam.h"
enum class DirectionW {
Up,
Down,
Left,
Right
};
class Wiazkowiec : public Actor {
public:
Wiazkowiec(int x, int y, const sf::Texture& texture, sf::RenderWindow *window);
void move(float deltaX, float deltaY) override;
void moveLeft() override;
void moveRight() override;
void moveUp() override;
void moveDown() override;
void takeDamage();
void setRandomDirection();
void checkIfBeamShootOutOfBounds();
void update();
void shoot() override;
void render(sf::RenderWindow &window);
bool isAlive() const;
bool isShooting() const;
void setPlanszaHeight(int height, int width);
Beam* getBeam() const;
private:
sf::Texture WiazkaTexture;
sf::Texture beamTexture;
sf::Clock shootClock;
sf::Clock shootingClock;
DirectionW direction = DirectionW::Down;
Beam *beam; // wskaźnik na wiązkę
sf::RenderWindow *window_ptr;
void spawnBeam(); // Tworzy wiązkę
int planszaHeight = 800;
int planszaWidth = 600;
float beamDuration = 1.0f;
float movementSpeed = 2.0f;
bool shooting = false;
bool alive = true;
};
#endif //WIAZKOWIEC_H

186
main.cpp
View File

@@ -3,13 +3,8 @@
#include "headers/Plansza.h"
ships selectedShip = none;
void menu();
int main() {
menu();
int main()
{
std::clog << "Game started\n";
sf::RenderWindow mainWindow(sf::VideoMode(600, 800), "LotoStatek");
mainWindow.setVerticalSyncEnabled(true);
@@ -19,9 +14,7 @@ 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, selectedShip);
Plansza plansza(mainWindow.getSize().y, mainWindow.getSize().x, &mainWindow);
while (mainWindow.isOpen()) {
mainWindow.clear();
@@ -29,179 +22,14 @@ 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();
// 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();
}
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

@@ -1,19 +1,22 @@
#include "../headers/Actor.h"
#include <iostream>
Actor::Actor(int x, int y, const sf::Texture& texture) {
actorSprite.setTexture(texture);
Actor::Actor(int x, int y, std::string path) {
loadTexture(path);
position.x = x;
position.y = y;
actorSprite.setOrigin(actorSprite.getLocalBounds().width / 2, actorSprite.getLocalBounds().height / 2); // wycentrowanie sprite
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;
}
return actorSprite;
}
@@ -21,41 +24,18 @@ 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;
}
void Actor::updateBullets() {
for (auto it = bullets.begin(); it != bullets.end(); ) {
if (it->isOutOfBounds()) {
it = bullets.erase(it); // Usuwa element i zwraca iterator na następny element
} else {
++it; // Przechodzi do następnego elementu
for (auto& bullet : bullets) {
if(bullet.isOutOfBounds()) {
bullets.erase(bullets.begin());
}
}
//std::cout << "Liczba pociskow: " << bullets.size() << std::endl;
}
void Actor::setMovingSpeed(float speed) {
moving_speed = speed;
}
}

View File

@@ -1,91 +0,0 @@
#include "../headers/AdvancedEnemy.h"
#include "../headers/Bullet.h"
#include "../headers/Plansza.h"
AdvancedEnemy::AdvancedEnemy(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture) : Actor(x, y, texture) {
enemyBulletTexture = bulletTexture;
hp = 2; // 2 punkty życia
firerate = 2000; // Strzela co 2
moving_speed = 4.0f; // Prędkość
enemyBulletTexture.loadFromFile("../assets/img/bullets/enemy_bullet.png");
}
void AdvancedEnemy::shoot() {
if (shootClock.getElapsedTime().asMilliseconds() >= firerate) {
Bullet Cbullet(position.x, position.y + actorSprite.getGlobalBounds().height / 2, enemyBulletTexture);
Cbullet.setSpeed(10.0f); // Prędkość w dół
bullets.emplace_back(std::move(Cbullet));
Bullet Lbullet(position.x - 20, position.y + actorSprite.getGlobalBounds().height / 2, enemyBulletTexture);
Lbullet.setSpeed(10.0f); // Prędkość w dół
bullets.emplace_back(std::move(Lbullet));
Bullet Rbullet(position.x + 20, position.y + actorSprite.getGlobalBounds().height / 2, enemyBulletTexture);
Rbullet.setSpeed(10.0f); // Prędkość w dół
bullets.emplace_back(std::move(Rbullet));
shootClock.restart();
}
}
void AdvancedEnemy::updateDirection() {
// Zmieniamy kierunek przeciwnika, gdy dotrze do krawędzi
if (position.y <= 0) {
direction = DirectionA::Down;
} else if (position.y >= 800) {
direction = DirectionA::Up;
}
// logika dla kierunku lewo/prawo
if (position.x <= 0) {
direction = DirectionA::Right;
} else if (position.x >= 1200) {
direction = DirectionA::Left;
}
}
void AdvancedEnemy::move(float deltaX, float deltaY) {
actorSprite.move(deltaX, deltaY);
position.x += static_cast<int>(deltaX);
position.y += static_cast<int>(deltaY);
}
void AdvancedEnemy::moveLeft() { move(-moving_speed, 0.0f); }
void AdvancedEnemy::moveRight() { move(moving_speed, 0.0f); }
void AdvancedEnemy::moveUp() { move(0.0f, -moving_speed); }
void AdvancedEnemy::moveDown() { move(0.0f, moving_speed); }
void AdvancedEnemy::update() {
// Sprawdzamy, czy przeciwnik dotarł do krawędzi i zmieniamy kierunek
updateDirection();
switch (direction) {
case DirectionA::Up:
moveUp();
break;
case DirectionA::Down:
moveDown();
break;
case DirectionA::Left:
moveLeft();
break;
case DirectionA::Right:
moveRight();
break;
}
}
bool AdvancedEnemy::isAlive() const {
return alive;
}
void AdvancedEnemy::takeDamage() {
if (--hp <= 0) {
alive = false;
Plansza::score += 10;
Plansza::ultimateCounter += 10;
}
}

View File

@@ -1,22 +0,0 @@
#include "../headers/Beam.h"
#include <iostream>
Beam::Beam(int x, int y, const sf::Texture& texture) {
beamSprite.setOrigin(beamSprite.getLocalBounds().width/2, beamSprite.getLocalBounds().height/2);
if (texture.getSize().x > 0 && texture.getSize().y > 0) {
beamSprite.setPosition(x, y);
} else {
std::cerr << "Błąd: Tekstura wiązki nie została poprawnie załadowana." << std::endl;
}
beamSprite.setTexture(texture);
}
sf::Sprite Beam::getSprite() {
return beamSprite;
}
void Beam::setRotation(float angle) {
beamSprite.setRotation(angle);
}

View File

@@ -1,127 +0,0 @@
#include "../headers/Bomber.h"
#include "../headers/Bullet.h"
#include "../headers/Plansza.h"
#include <random>
Bomber::Bomber(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture) : Actor(x, y, texture) {
BombaTexture = bulletTexture;
hp = 2; // 2 punkty życia
firerate = 6000; // Strzela co 6
moving_speed = 8.0f; // Prędkość
}
void Bomber::setPlanszaHeight(float height, float width) {
planszaHeight = height;
planszaWidth = width;
}
void Bomber::setRandomDirection() {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<int> dist(0, 3);
int randomDirection = dist(gen);
// Zapobieganie wyjscia poza ekran
switch (randomDirection) {
case 0:
if (position.y > 0) direction = DirectionB::Up;
break;
case 1:
if (position.y < 600) direction = DirectionB::Down;
break;
case 2:
if (position.x > 0) direction = DirectionB::Left;
break;
case 3:
if (position.x < 800) direction = DirectionB::Right;
break;
}
}
void Bomber::shoot() {
if (shootClock.getElapsedTime().asMilliseconds() >= firerate) {
Bullet Bbullet(position.x, position.y + actorSprite.getGlobalBounds().height / 2, BombaTexture);
Bbullet.setSpeed(0.1f); // Prędkość w dół
bullets.emplace_back(std::move(Bbullet));
shootClock.restart();
setRandomDirection();
}
}
void Bomber::updateDirection() {
auto spriteBounds = actorSprite.getGlobalBounds(); // Pobierz rozmiar i pozycję sprite'a
// Kontrola górnej i dolnej krawędzi (wysokości planszy)
if (position.y <= 0) {
direction = DirectionB::Down;
} else if (position.y + spriteBounds.height >= planszaHeight) {
direction = DirectionB::Up;
}
// Kontrola lewej i prawej krawędzi (szerokości planszy)
if (position.x <= 0) {
direction = DirectionB::Right;
} else if (position.x + spriteBounds.width >= planszaWidth) {
direction = DirectionB::Left;
}
}
void Bomber::move(float deltaX, float deltaY) {
auto spriteBounds = actorSprite.getGlobalBounds(); // Rozmiar i pozycja sprite'a
// Zapobiegaj wyjściu poza poziome granice
if (position.x + deltaX < 0) {
deltaX = -position.x;
} else if (position.x + spriteBounds.width + deltaX > planszaWidth) {
deltaX = planszaWidth - (position.x + spriteBounds.width);
}
// Zapobiegaj wyjściu poza pionowe granice
if (position.y + deltaY < 0) {
deltaY = -position.y;
} else if (position.y + spriteBounds.height + deltaY > planszaHeight) {
deltaY = planszaHeight - (position.y + spriteBounds.height);
}
actorSprite.move(deltaX, deltaY);
position.x += static_cast<int>(deltaX);
position.y += static_cast<int>(deltaY);
}
void Bomber::moveLeft() { move(-moving_speed, 0.0f); }
void Bomber::moveRight() { move(moving_speed, 0.0f); }
void Bomber::moveUp() { move(0.0f, -moving_speed); }
void Bomber::moveDown() { move(0.0f, moving_speed); }
void Bomber::update() {
// Sprawdzamy, czy przeciwnik dotarł do krawędzi i zmieniamy kierunek
updateDirection();
switch (direction) {
case DirectionB::Up:
moveUp();
break;
case DirectionB::Down:
moveDown();
break;
case DirectionB::Left:
moveLeft();
break;
case DirectionB::Right:
moveRight();
break;
}
}
bool Bomber::isAlive() const {
return alive;
}
void Bomber::takeDamage() {
if (--hp <= 0) {
alive = false;
Plansza::score += 15;
Plansza::ultimateCounter += 15;
}
}

View File

@@ -1,188 +0,0 @@
#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;
}
}

View File

@@ -1,16 +1,22 @@
#include "../headers/Bullet.h"
Bullet::Bullet(float x, float y, sf::Texture &texture): Projectile(x,y, texture) {}
Bullet::Bullet(float x, float y, sf::Texture &texture, float speed): Projectile(x,y, texture) {
this->speed = -speed;
Bullet::Bullet(float x, float y, sf::Texture &texture) : Projectile(x, y, texture) {
// Ładowanie dźwięku wystrzału
if (!shootBuffer.loadFromFile("../assets/sounds/shoot.ogg")) {
// Obsługa błędu
}
shootSound.setBuffer(shootBuffer);
playShootSound(); // Odtwarzanie dźwięku wystrzału przy utworzeniu pocisku
}
void Bullet::update() {
//std::cout << "Start update: speed = " << speed << ", position.y = " << position.y << std::endl;
sprite.move(0.0f, speed);
position.y += int(speed);
if(position.y < -100) {
if (position.y < -100) {
outOfBounds = true;
}
}
void Bullet::playShootSound() {
shootSound.play();
}

View File

@@ -1,21 +0,0 @@
#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,81 +0,0 @@
#include "../headers/Enemy.h"
#include "../headers/Bullet.h"
#include "../headers/Plansza.h"
Enemy::Enemy(int x, int y, const sf::Texture& texture) : Actor(x, y, texture) {
hp = 1; // Przeciwnik ma 1 punkt życia
firerate = 2000; // Strzela co 2
moving_speed = 2.5f; // Prędkość
enemyBulletTexture.loadFromFile("../assets/img/bullets/enemy_bullet.png");
}
void Enemy::shoot() {
if (shootClock.getElapsedTime().asMilliseconds() >= firerate) {
Bullet bullet(position.x, position.y + actorSprite.getGlobalBounds().height / 2, enemyBulletTexture);
bullet.setSpeed(10.0f); // Prędkość w dół
bullets.emplace_back(std::move(bullet));
shootClock.restart();
}
}
void Enemy::updateDirection() {
// Zmieniamy kierunek przeciwnika, gdy dotrze do krawędzi
if (position.y <= 0) {
direction = Direction::Down;
} else if (position.y >= 800) {
direction = Direction::Up;
}
// logika dla kierunku lewo/prawo
if (position.x <= 0) {
direction = Direction::Right;
} else if (position.x >= 1200) {
direction = Direction::Left;
}
}
void Enemy::move(float deltaX, float deltaY) {
actorSprite.move(deltaX, deltaY);
position.x += static_cast<int>(deltaX);
position.y += static_cast<int>(deltaY);
}
void Enemy::moveLeft() { move(-moving_speed, 0.0f); }
void Enemy::moveRight() { move(moving_speed, 0.0f); }
void Enemy::moveUp() { move(0.0f, -moving_speed); }
void Enemy::moveDown() { move(0.0f, moving_speed); }
void Enemy::update() {
// Sprawdzamy, czy przeciwnik dotarł do krawędzi i zmieniamy kierunek
updateDirection();
switch (direction) {
case Direction::Up:
moveUp();
break;
case Direction::Down:
moveDown();
break;
case Direction::Left:
moveLeft();
break;
case Direction::Right:
moveRight();
break;
}
}
bool Enemy::isAlive() const {
return alive;
}
void Enemy::takeDamage() {
if (--hp <= 0) {
alive = false;
Plansza::score += 5;
Plansza::ultimateCounter += 5;
}
}

View File

@@ -1,20 +0,0 @@
#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,136 +0,0 @@
#include <iostream>
#include <random>
#include "../headers/Kamikadze.h"
#include "../headers/RandomNumberGenerator.h"
#include "../headers/Plansza.h"
Kamikadze::Kamikadze(int x, int y, const sf::Texture& texture) : Actor(x, y, texture) {
hp = 3; // 3 punkty życia
moving_speed = 5.0f; // Prędkość
}
void Kamikadze::shoot(){}
void Kamikadze::setRandomDirection() {
int randomDirection = RandomNumberGenerator::getRandomNumber(0,3);
// Zapobieganie wyjscia poza ekran
switch (randomDirection) {
case 0:
if (position.y > 0) direction = DirectionK::Up;
break;
case 1:
if (position.y < 800) direction = DirectionK::Down;
break;
case 2:
if (position.x > 0) direction = DirectionK::Left;
break;
case 3:
if (position.x < 1200) direction = DirectionK::Right;
break;
}
}
void Kamikadze::updateDirection() {
// Zmieniamy kierunek przeciwnika, gdy dotrze do krawędzi
if (position.y <= 0) {
direction = DirectionK::Down;
} else if (position.y >= 800) {
direction = DirectionK::Up;
}
// logika dla kierunku lewo/prawo
if (position.x <= 0) {
direction = DirectionK::Right;
} else if (position.x >= 1200) {
direction = DirectionK::Left;
}
}
void Kamikadze::followPlayer(const sf::Vector2f& playerPosition) {
float diffX = playerPosition.x - position.x;
float diffY = playerPosition.y - position.y;
float magnitude = std::sqrt(diffX * diffX + diffY * diffY);
if (magnitude != 0) {
diffX /= magnitude;
diffY /= magnitude;
// Aktualizacja pozycji Kamikadze w kierunku gracza
position.x += diffX * movementSpeed;
position.y += diffY * movementSpeed;
} else { //zatrzymanie kamikadze
movementSpeed = 0.0f;
}
}
void Kamikadze::explode(const sf::Vector2f& playerPosition, bool& playerHit) {
if (!exploding) {
// Rozpocznij kamikadze
exploding = true;
explosionClock.restart();
movementSpeed = 0.0f;
std::cout << "Kamikadze exploding!" << std::endl;
std::cout << "Kamikadze position: (" << position.x << ", " << position.y << ")" << std::endl;
std::cout << "Player position: (" << playerPosition.x << ", " << playerPosition.y << ")" << std::endl;
// Zakres, w jakim gracz może zostać trafiony
sf::Vector2f diff = playerPosition - sf::Vector2f(static_cast<float>(position.x), static_cast<float>(position.y));
float distance = std::sqrt(diff.x * diff.x + diff.y * diff.y);
std::cout << "Distance to player: " << distance << std::endl;
// Trafienie gracza, jeśli jest w obszarze eksplozji
const float explosionRange = 100.0f;
if (distance <= explosionRange) {
playerHit = true;
std::cout << "Player is within explosion range! Player hit!" << std::endl;
}
}
// Sprawdzanie czasu wybuchu
if (exploding && explosionClock.getElapsedTime().asSeconds() >= 0.5f) {
alive = false; // Kamikadze ulega zniszczeniu po eksplozji
std::cout << "Kamikadze destroyed after explosion!" << std::endl;
}
}
void Kamikadze::move(float deltaX, float deltaY) {
actorSprite.move(deltaX, deltaY);
position.x += static_cast<int>(deltaX);
position.y += static_cast<int>(deltaY);
}
void Kamikadze::moveLeft() { move(-moving_speed, 0.0f); }
void Kamikadze::moveRight() { move(moving_speed, 0.0f); }
void Kamikadze::moveUp() { move(0.0f, -moving_speed); }
void Kamikadze::moveDown() { move(0.0f, moving_speed); }
void Kamikadze::update(const sf::Vector2f& playerPosition) {
if (alive && !exploding) {
// Podążanie za graczem, dopóki Kamikadze jest żywy
followPlayer(playerPosition);
actorSprite.setPosition(position.x, position.y);
}
}
bool Kamikadze::isExploding() const {
return exploding;
}
bool Kamikadze::isAlive() const {
return alive;
}
void Kamikadze::takeDamage() {
if (--hp <= 0) {
alive = false;
Plansza::score += 20;
Plansza::ultimateCounter += 20;
}
}

View File

@@ -1,28 +1,40 @@
#include <iostream>
#include "../headers/Meteor.h"
Meteor::Meteor(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 = 5.0f;
sprite.scale(0.05f, 0.05f);
position.x = x;
position.y = y;
rotationSpeed = static_cast<float>(rand() % 2 + 1) * (rand() % 2 == 0 ? 1 : -1);
Meteor::Meteor(float x, float y, sf::Texture &texture) {
outOfBounds = false;
meteorTexture = texture;
meteorSprite.setTexture(texture);
meteorSprite.setOrigin(meteorSprite.getLocalBounds().width / 2, meteorSprite.getLocalBounds().height / 2); // wycentrowanie sprite
meteorSprite.setPosition(x, y);
meteorSpeed = 5.0f;
meteorSprite.scale(0.05f, 0.05f);
meteorPosition.x = x;
meteorPosition.y = y;
meteorRotationSpeed = static_cast<float>(rand() % 2 + 1) * (rand() % 2 == 0 ? 1 : -1);
}
sf::Sprite &Meteor::getSprite() {
return meteorSprite;
}
void Meteor::update() {
sprite.move(0.0f, movingSpeed); // przesunięcie sprajta
position.y += int(movingSpeed); // przesunięcie pozycji
sprite.rotate(rotationSpeed); // obracanie tym meteorkiem pięknym
if(position.y > 900) {
meteorSprite.move(0.0f, meteorSpeed); // przesunięcie sprajta
meteorPosition.y += int(meteorSpeed); // przesunięcie pozycji
meteorSprite.rotate(meteorRotationSpeed); // obracanie tym meteorkiem pięknym
if(meteorPosition.y > 900) {
outOfBounds = true; // jeżeli wyszedł poza granice ekranu ustaw tą zmienną
}
// std::cout << "x: " << meteorSprite.getPosition().x << std::endl;
// std::cout << "y: " << meteorSprite.getPosition().y << std::endl;
}
bool Meteor::getStatus() {
return outOfBounds;
}
unsigned int Meteor::counter = 0;
// było użyte do testowania czy meteoryt jest kasowany
//Meteor::~Meteor() {
// Meteor::counter++;

View File

@@ -1,18 +0,0 @@
#include "../headers/ObjectItem.hpp"
ObjectItem::ObjectItem(float x, float y, sf::Texture &texture) {
outOfBounds = false;
Position position_ = {0,0};
position_.x = static_cast<int>(x);
position_.y = static_cast<int>(y);
position = position_;
this->texture_ = texture;
}
bool ObjectItem::getStatus() {
return outOfBounds;
}
sf::Sprite &ObjectItem::getSprite() {
return sprite;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,55 +1,19 @@
#include <iostream>
#include <SFML/Graphics/Font.hpp>
#include "../headers/Player.h"
#include "../headers/Plansza.h"
#include "../headers/Bullet.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) {
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();
}
Player::Player(int x, int y, std::string path) : Actor(x, y, path) {
bulletTexture.loadFromFile("../assets/img/bullets/bullet_pink.png");
rocketTexture.loadFromFile("../assets/img/rockets/Rocket_111.png");
};
void Player::shoot() {
auto now = std::chrono::steady_clock::now();
if (std::chrono::duration_cast<std::chrono::milliseconds>(now - lastShotTime).count() >= firerate) {
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;
}
bullets.emplace_back(position.x, position.y, bulletTexture);
lastShotTime = now;
}
}
void Player::alternate_shoot() {
auto now = std::chrono::steady_clock::now();
if (std::chrono::duration_cast<std::chrono::milliseconds>(now - lastShotTime).count() >= firerate) {
@@ -58,43 +22,6 @@ void Player::alternate_shoot() {
}
}
void Player::ultimate_shoot() {
ultimateShootActive = true;
}
void Player::update() {
// Wyłącz nieśmiertelność po określonym czasie
if (isImmortal && immortalityClock.getElapsedTime().asSeconds() >= immortalityDuration) {
isImmortal = false;
std::cout << "Immortality ended.\n";
}
// Efekt migania podczas nieśmiertelności
if (isImmortal) {
if (static_cast<int>(immortalityClock.getElapsedTime().asMilliseconds() / 200) % 2 == 0) {
actorSprite.setColor(sf::Color(255, 255, 255, 128)); // Półprzezroczysty
} else {
actorSprite.setColor(sf::Color(255, 255, 255, 255)); // Normalny
}
} else {
actorSprite.setColor(sf::Color(255, 255, 255, 255)); // Normalny
}
}
void Player::takeDamage() {
if (!isImmortal) {
if (hp > 0) {
hp--;
isImmortal = true; // Aktywuj chwilową nieśmiertelność
immortalityClock.restart();
}
}
}
void Player::setTripleShot(bool toogle) {
tripleShot = toogle;
}
void Player::setFirerate(unsigned int firerate) {
this->firerate = firerate;
}
@@ -126,18 +53,3 @@ 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;
}

View File

@@ -1,21 +0,0 @@
#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,9 +2,8 @@
void Rocket::update() {
sprite.move(0.0f, speed);
position.y += static_cast<int>(speed);
position.y += int(speed);
if(position.y < -100) {
outOfBounds = true;
}
}
}

View File

@@ -1,213 +0,0 @@
#include "../headers/Wiazkowiec.h"
#include "../headers/Plansza.h"
#include "../headers/RandomNumberGenerator.h"
#include <iostream>
Wiazkowiec::Wiazkowiec(int x, int y, const sf::Texture &texture, sf::RenderWindow *window) : Actor(x, y, texture),
beam(nullptr)
{
window_ptr = window;
try {
beamTexture.loadFromFile("../assets/img/wiazka/laser.png");
} catch (std::exception &e) {
std::cerr << "Failed to load textures: " << e.what() << std::endl;
exit(-500);
}
hp = 2; // 2 punkty życia
firerate = 5000; // Strzela co 10
moving_speed = 5.0f; // Prędkość
}
void Wiazkowiec::setPlanszaHeight(int height, int width) {
planszaHeight = height;
planszaWidth = width;
}
void Wiazkowiec::spawnBeam() {
int beamX = actorSprite.getPosition().x;
int beamY = actorSprite.getPosition().y;
switch (direction) {
case DirectionW::Up: {
beam = new Beam(beamX, beamY, beamTexture);
beam->setRotation(180);
break;
}
case DirectionW::Down: {
beam = new Beam(beamX, beamY, beamTexture);
break;
}
case DirectionW::Left: {
beam = new Beam(beamX, beamY, beamTexture);
beam->setRotation(90);
break;
}
case DirectionW::Right: {
beam = new Beam(beamX, beamY, beamTexture);
beam->setRotation(270);
break;
}
default:
break;
}
shooting = true;
shootingClock.restart();
}
// Strzał wiązki
void Wiazkowiec::shoot() {
if (!shooting) {
spawnBeam();
}
switch (direction) {
case DirectionW::Up: {
std::cout << "Direction is up" << std::endl;
break;
}
case DirectionW::Down: {
std::cout << "Direction is down" << std::endl;
break;
}
case DirectionW::Left: {
std::cout << "Direction is left" << std::endl;
break;
}
case DirectionW::Right: {
std::cout << "Direction is right" << std::endl;
break;
}
default:
break;
}
}
void Wiazkowiec::setRandomDirection() {
// Losowanie kierunku: 0 = Up, 1 = Down, 2 = Left, 3 = Right
int whatNumber = rand() % 4;
switch (whatNumber) {
case 0:
direction = DirectionW::Up;
break;
case 1:
direction = DirectionW::Down;
break;
case 2:
direction = DirectionW::Left;
break;
case 3:
direction = DirectionW::Right;
break;
default:
break;
}
}
void Wiazkowiec::checkIfBeamShootOutOfBounds() {
auto spriteBounds = actorSprite.getGlobalBounds(); // Pobierz rozmiar i pozycję sprite'a
// Kontrola górnej i dolnej krawędzi
if (position.y <= 0) {
direction = DirectionW::Down;
} else if (position.y + spriteBounds.height >= planszaHeight) {
direction = DirectionW::Up;
}
// Kontrola lewej i prawej krawędzi
if (position.x <= 0) {
direction = DirectionW::Right;
} else if (position.x + spriteBounds.width >= planszaWidth) {
direction = DirectionW::Left;
}
}
void Wiazkowiec::move(float deltaX, float deltaY) {
auto spriteBounds = actorSprite.getGlobalBounds(); // Rozmiar i pozycja sprite'a
// Zapobiegaj wyjściu poza poziome granice
if (static_cast<float>(position.x) + deltaX < 0) {
deltaX = static_cast<float>(-position.x);
} else if (static_cast<float>(position.x) + spriteBounds.width + deltaX > static_cast<float>(planszaWidth)) {
deltaX = static_cast<float>(planszaWidth) - (static_cast<float>(position.x) + spriteBounds.width);
}
// Zapobiegaj wyjściu poza pionowe granice
if (static_cast<float>(position.y) + deltaY < 0) {
deltaY = static_cast<float>(-position.y);
} else if (static_cast<float>(position.y) + spriteBounds.height + deltaY > static_cast<float>(planszaHeight)) {
deltaY = static_cast<float>(planszaHeight) - (static_cast<float>(position.y) + spriteBounds.height);
}
actorSprite.move(deltaX, deltaY);
position.x += static_cast<int>(deltaX);
position.y += static_cast<int>(deltaY);
}
void Wiazkowiec::moveLeft() { move(-moving_speed, 0.0f); }
void Wiazkowiec::moveRight() { move(moving_speed, 0.0f); }
void Wiazkowiec::moveUp() { move(0.0f, -moving_speed); }
void Wiazkowiec::moveDown() { move(0.0f, moving_speed); }
void Wiazkowiec::update() {
if (shooting) {
// Kontrola zakończenia strzału
if (shootingClock.getElapsedTime().asSeconds() >= beamDuration) {
shooting = false;
delete beam;
beam = nullptr;
setRandomDirection(); // Zmień kierunek po strzale
} else {
window_ptr->draw(beam->getSprite());
}
} else {
checkIfBeamShootOutOfBounds();
switch (direction) {
case DirectionW::Up:
moveUp();
break;
case DirectionW::Down:
moveDown();
break;
case DirectionW::Left:
moveLeft();
break;
case DirectionW::Right:
moveRight();
break;
}
if (shootClock.getElapsedTime().asSeconds() >= 3.0f) {
// Co 3 sekundy
shoot();
shootClock.restart();
}
}
}
bool Wiazkowiec::isAlive() const {
return alive;
}
void Wiazkowiec::takeDamage() {
if (--hp <= 0) {
alive = false;
Plansza::score += 10;
Plansza::ultimateCounter += 10;
}
}
bool Wiazkowiec::isShooting() const {
return shooting;
}
Beam* Wiazkowiec::getBeam() const {
return beam;
}