Compare commits
1 Commits
74c739a09e
...
Strzaly-w-
| Author | SHA1 | Date | |
|---|---|---|---|
| 8db6b8572d |
@@ -25,9 +25,7 @@ add_executable(LotoStatek main.cpp
|
|||||||
headers/Rocket.h
|
headers/Rocket.h
|
||||||
sources/Rocket.cpp
|
sources/Rocket.cpp
|
||||||
headers/Size.h
|
headers/Size.h
|
||||||
headers/Position.h
|
headers/Position.h)
|
||||||
headers/ObjectItem.hpp
|
|
||||||
sources/ObjectItem.cpp)
|
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
set(SFML_ROOT "${CMAKE_SOURCE_DIR}/lib/SFML")
|
set(SFML_ROOT "${CMAKE_SOURCE_DIR}/lib/SFML")
|
||||||
@@ -42,9 +40,9 @@ if(WIN32)
|
|||||||
target_link_libraries(LotoStatek ${SFML_LIBRARIES})
|
target_link_libraries(LotoStatek ${SFML_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
elseif(APPLE)
|
elseif(APPLE)
|
||||||
find_package(SFML 2.6.2 COMPONENTS graphics window system REQUIRED)
|
find_package(lib/SFML 2.6.2 COMPONENTS graphics window system REQUIRED)
|
||||||
target_link_libraries(LotoStatek sfml-graphics sfml-window sfml-audio sfml-system)
|
target_link_libraries(LotoStatek sfml-graphics sfml-window sfml-audio sfml-system)
|
||||||
elseif(LINUX)
|
elseif(LINUX)
|
||||||
find_package(SFML 2.6.2 COMPONENTS graphics window system REQUIRED)
|
find_package(lib/SFML 2.6.2 COMPONENTS graphics window system REQUIRED)
|
||||||
target_link_libraries(LotoStatek sfml-graphics sfml-window sfml-audio sfml-system)
|
target_link_libraries(LotoStatek sfml-graphics sfml-window sfml-audio sfml-system)
|
||||||
endif()
|
endif()
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 782 B |
Binary file not shown.
@@ -1,14 +1,23 @@
|
|||||||
|
|
||||||
#ifndef LOTOSTATEK_BULLET_H
|
#ifndef LOTOSTATEK_BULLET_H
|
||||||
#define LOTOSTATEK_BULLET_H
|
#define LOTOSTATEK_BULLET_H
|
||||||
|
|
||||||
#include "Projectile.h"
|
#include "Projectile.h"
|
||||||
#include "SFML/Graphics/Texture.hpp"
|
#include "SFML/Graphics/Texture.hpp"
|
||||||
|
#include "SFML/Audio/Sound.hpp"
|
||||||
|
#include "SFML/Audio/SoundBuffer.hpp"
|
||||||
|
|
||||||
class Bullet : public Projectile {
|
class Bullet : public Projectile {
|
||||||
public:
|
public:
|
||||||
Bullet(float x, float y, sf::Texture &texture) : Projectile(x,y, texture) {};
|
Bullet(float x, float y, sf::Texture &texture);
|
||||||
void update() override;
|
void update() override;
|
||||||
|
|
||||||
|
// Dodanie metody do odtwarzania dźwięku
|
||||||
|
void playShootSound();
|
||||||
|
|
||||||
|
private:
|
||||||
|
sf::Sound shootSound;
|
||||||
|
sf::SoundBuffer shootBuffer; // Dodanie bufora dźwięku
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif //LOTOSTATEK_BULLET_H
|
#endif //LOTOSTATEK_BULLET_H
|
||||||
|
|||||||
@@ -4,12 +4,22 @@
|
|||||||
#include "SFML/Graphics/Texture.hpp"
|
#include "SFML/Graphics/Texture.hpp"
|
||||||
#include "SFML/Graphics/Sprite.hpp"
|
#include "SFML/Graphics/Sprite.hpp"
|
||||||
#include "Position.h"
|
#include "Position.h"
|
||||||
#include "ObjectItem.hpp"
|
|
||||||
|
|
||||||
class Meteor : public ObjectItem {
|
class Meteor {
|
||||||
public:
|
public:
|
||||||
Meteor(float x, float y, sf::Texture &texture);
|
Meteor(float x, float y, sf::Texture &texture);
|
||||||
|
sf::Sprite &getSprite();
|
||||||
|
bool getStatus();
|
||||||
void update();
|
void update();
|
||||||
|
// ~Meteor();
|
||||||
|
private:
|
||||||
|
sf::Texture meteorTexture;
|
||||||
|
sf::Sprite meteorSprite;
|
||||||
|
Position meteorPosition;
|
||||||
|
float meteorRotationSpeed;
|
||||||
|
float meteorSpeed;
|
||||||
|
bool outOfBounds;
|
||||||
|
static unsigned int counter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
#ifndef LOTOSTATEK_OBJECTITEM_HPP
|
|
||||||
#define LOTOSTATEK_OBJECTITEM_HPP
|
|
||||||
|
|
||||||
#include "SFML/Graphics/Sprite.hpp"
|
|
||||||
#include "Position.h"
|
|
||||||
#include "SFML/Graphics/Texture.hpp"
|
|
||||||
|
|
||||||
class ObjectItem {
|
|
||||||
public:
|
|
||||||
ObjectItem(float x, float y, sf::Texture &texture);
|
|
||||||
sf::Sprite &getSprite();
|
|
||||||
bool getStatus();
|
|
||||||
virtual void update() = 0;
|
|
||||||
protected:
|
|
||||||
sf::Texture texture;
|
|
||||||
sf::Sprite sprite;
|
|
||||||
Position position;
|
|
||||||
float rotationSpeed;
|
|
||||||
float movingSpeed;
|
|
||||||
bool outOfBounds;
|
|
||||||
static unsigned int counter;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif //LOTOSTATEK_OBJECTITEM_HPP
|
|
||||||
@@ -21,7 +21,6 @@ public:
|
|||||||
void spawn_meteor();
|
void spawn_meteor();
|
||||||
void update_meteors();
|
void update_meteors();
|
||||||
void update();
|
void update();
|
||||||
void update_score();
|
|
||||||
private:
|
private:
|
||||||
Size size;
|
Size size;
|
||||||
Background background;
|
Background background;
|
||||||
@@ -30,11 +29,8 @@ private:
|
|||||||
sf::Texture meteorTexture1;
|
sf::Texture meteorTexture1;
|
||||||
sf::Texture meteorTexture2;
|
sf::Texture meteorTexture2;
|
||||||
sf::Clock spawnClock;
|
sf::Clock spawnClock;
|
||||||
sf::Clock scoreClock;
|
|
||||||
std::vector<Meteor> meteors;
|
std::vector<Meteor> meteors;
|
||||||
sf::RenderWindow *window;
|
sf::RenderWindow *window;
|
||||||
sf::Font font;
|
|
||||||
unsigned int score = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //PLANSZA_H
|
#endif //PLANSZA_H
|
||||||
|
|||||||
@@ -1,9 +1,22 @@
|
|||||||
#include "../headers/Bullet.h"
|
#include "../headers/Bullet.h"
|
||||||
|
|
||||||
|
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() {
|
void Bullet::update() {
|
||||||
sprite.move(0.0f, speed);
|
sprite.move(0.0f, speed);
|
||||||
position.y += int(speed);
|
position.y += int(speed);
|
||||||
if(position.y < -100) {
|
if (position.y < -100) {
|
||||||
outOfBounds = true;
|
outOfBounds = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Bullet::playShootSound() {
|
||||||
|
shootSound.play();
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,29 +1,40 @@
|
|||||||
|
#include <iostream>
|
||||||
#include "../headers/Meteor.h"
|
#include "../headers/Meteor.h"
|
||||||
|
|
||||||
Meteor::Meteor(float x, float y, sf::Texture &texture) : ObjectItem(x, y, texture) {
|
Meteor::Meteor(float x, float y, sf::Texture &texture) {
|
||||||
outOfBounds = false;
|
outOfBounds = false;
|
||||||
texture = texture;
|
meteorTexture = texture;
|
||||||
sprite.setTexture(texture);
|
meteorSprite.setTexture(texture);
|
||||||
sprite.setOrigin(sprite.getLocalBounds().width / 2, sprite.getLocalBounds().height / 2); // wycentrowanie sprite
|
meteorSprite.setOrigin(meteorSprite.getLocalBounds().width / 2, meteorSprite.getLocalBounds().height / 2); // wycentrowanie sprite
|
||||||
sprite.setPosition(x, y);
|
meteorSprite.setPosition(x, y);
|
||||||
movingSpeed = 5.0f;
|
meteorSpeed = 5.0f;
|
||||||
sprite.scale(0.05f, 0.05f);
|
meteorSprite.scale(0.05f, 0.05f);
|
||||||
position.x = x;
|
meteorPosition.x = x;
|
||||||
position.y = y;
|
meteorPosition.y = y;
|
||||||
rotationSpeed = static_cast<float>(rand() % 2 + 1) * (rand() % 2 == 0 ? 1 : -1);
|
meteorRotationSpeed = static_cast<float>(rand() % 2 + 1) * (rand() % 2 == 0 ? 1 : -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sf::Sprite &Meteor::getSprite() {
|
||||||
|
return meteorSprite;
|
||||||
|
}
|
||||||
|
|
||||||
void Meteor::update() {
|
void Meteor::update() {
|
||||||
sprite.move(0.0f, movingSpeed); // przesunięcie sprajta
|
meteorSprite.move(0.0f, meteorSpeed); // przesunięcie sprajta
|
||||||
position.y += int(movingSpeed); // przesunięcie pozycji
|
meteorPosition.y += int(meteorSpeed); // przesunięcie pozycji
|
||||||
sprite.rotate(rotationSpeed); // obracanie tym meteorkiem pięknym
|
meteorSprite.rotate(meteorRotationSpeed); // obracanie tym meteorkiem pięknym
|
||||||
if(position.y > 900) {
|
if(meteorPosition.y > 900) {
|
||||||
outOfBounds = true; // jeżeli wyszedł poza granice ekranu ustaw tą zmienną
|
outOfBounds = true; // jeżeli wyszedł poza granice ekranu ustaw tą zmienną
|
||||||
}
|
}
|
||||||
|
// std::cout << "x: " << meteorSprite.getPosition().x << std::endl;
|
||||||
|
// std::cout << "y: " << meteorSprite.getPosition().y << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Meteor::getStatus() {
|
||||||
|
return outOfBounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int Meteor::counter = 0;
|
||||||
|
|
||||||
// było użyte do testowania czy meteoryt jest kasowany
|
// było użyte do testowania czy meteoryt jest kasowany
|
||||||
//Meteor::~Meteor() {
|
//Meteor::~Meteor() {
|
||||||
// Meteor::counter++;
|
// Meteor::counter++;
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
#include "../headers/ObjectItem.hpp"
|
|
||||||
|
|
||||||
ObjectItem::ObjectItem(float x, float y, sf::Texture &texture) {
|
|
||||||
Position position_;
|
|
||||||
position_.x = x;
|
|
||||||
position_.y = y;
|
|
||||||
position = position_;
|
|
||||||
this->texture = texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ObjectItem::getStatus() {
|
|
||||||
return outOfBounds;
|
|
||||||
}
|
|
||||||
|
|
||||||
sf::Sprite &ObjectItem::getSprite() {
|
|
||||||
return sprite;
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
#include <random>
|
#include <random>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "../headers/Plansza.h"
|
#include "../headers/Plansza.h"
|
||||||
#include "../headers/ObjectItem.hpp"
|
|
||||||
|
|
||||||
Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::RenderWindow *mainWindow)
|
Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::RenderWindow *mainWindow)
|
||||||
: background("../assets/img/background/background.png", 2.0f),
|
: background("../assets/img/background/background.png", 2.0f),
|
||||||
@@ -12,13 +11,6 @@ ship(static_cast<int>(mainWindow->getSize().x) / 2, static_cast<int>(mainWindow-
|
|||||||
size.height = static_cast<int>(windowHeight);
|
size.height = static_cast<int>(windowHeight);
|
||||||
size.width = static_cast<int>(windowWidth);
|
size.width = static_cast<int>(windowWidth);
|
||||||
|
|
||||||
score = 0;
|
|
||||||
|
|
||||||
if (!font.loadFromFile("../assets/fonts/arial.ttf")) {
|
|
||||||
std::cerr << "Error loading font\n";
|
|
||||||
exit(-500);
|
|
||||||
}
|
|
||||||
|
|
||||||
ship.setMovingSpeed(8);
|
ship.setMovingSpeed(8);
|
||||||
ship.setFirerate(200);
|
ship.setFirerate(200);
|
||||||
|
|
||||||
@@ -65,7 +57,7 @@ void Plansza::update() {
|
|||||||
// TODO: Przenieść obiekt dźwięku wewnątrz klasy Bullet
|
// TODO: Przenieść obiekt dźwięku wewnątrz klasy Bullet
|
||||||
if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
|
if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
|
||||||
ship.shoot();
|
ship.shoot();
|
||||||
audioManager.playSoundEffect("shoot", 70.f); // Odtworzenie dźwięku wystrzału
|
// audioManager.playSoundEffect("shoot", 70.f); // Odtworzenie dźwięku wystrzału
|
||||||
}
|
}
|
||||||
if (sf::Mouse::isButtonPressed(sf::Mouse::Right)) {
|
if (sf::Mouse::isButtonPressed(sf::Mouse::Right)) {
|
||||||
ship.alternate_shoot();
|
ship.alternate_shoot();
|
||||||
@@ -164,7 +156,6 @@ void Plansza::update() {
|
|||||||
++meteorIt;
|
++meteorIt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update_score();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Meteor-related niżej
|
// Meteor-related niżej
|
||||||
@@ -199,18 +190,5 @@ std::vector<Meteor> &Plansza::getMeteors() {
|
|||||||
return meteors;
|
return meteors;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: naliczanie punktów za zabicie wrogów
|
|
||||||
void Plansza::update_score() {
|
|
||||||
if (scoreClock.getElapsedTime().asMilliseconds() > 500) {
|
|
||||||
score++;
|
|
||||||
scoreClock.restart();
|
|
||||||
}
|
|
||||||
|
|
||||||
sf::Text text(std::to_string(score), font, 24);
|
|
||||||
text.setFillColor(sf::Color::White);
|
|
||||||
text.setPosition(25, 25);
|
|
||||||
window->draw(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user