Plansza to be continued (WIP)
This commit is contained in:
@@ -4,21 +4,34 @@
|
||||
#include "Meteor.h"
|
||||
#include "RandomNumberGenerator.h"
|
||||
#include "SFML/System/Clock.hpp"
|
||||
#include "SFML/Graphics/RenderWindow.hpp"
|
||||
#include "Size.h"
|
||||
|
||||
#include "Player.h"
|
||||
#include "Background.h"
|
||||
#include "AudioManager.h"
|
||||
#include "Meteor.h"
|
||||
#include "Plansza.h"
|
||||
|
||||
class Plansza {
|
||||
public:
|
||||
Plansza(unsigned int windowHeight, unsigned int windowWidth);
|
||||
Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::RenderWindow *mainWindow);
|
||||
Size getSize();
|
||||
std::vector<Meteor> &getMeteors();
|
||||
void spawn_meteor();
|
||||
void update_meteors();
|
||||
void update();
|
||||
private:
|
||||
Size size;
|
||||
Background background;
|
||||
Player ship;
|
||||
AudioManager audioManager;
|
||||
sf::Texture meteorTexture1;
|
||||
sf::Texture meteorTexture2;
|
||||
sf::Clock spawnClock;
|
||||
std::vector<Meteor> meteors;
|
||||
sf::RenderWindow *window;
|
||||
};
|
||||
|
||||
#endif //PLANSZA_H
|
||||
|
||||
10
main.cpp
10
main.cpp
@@ -2,7 +2,6 @@
|
||||
|
||||
#include "SFML/Graphics.hpp"
|
||||
#include "headers/Player.h"
|
||||
#include "headers/Bullet.h"
|
||||
#include "headers/Background.h"
|
||||
#include "headers/AudioManager.h"
|
||||
#include "headers/Meteor.h"
|
||||
@@ -17,17 +16,13 @@ int main()
|
||||
|
||||
sf::Image icon;
|
||||
icon.loadFromFile("../assets/img/icon/ikonka.png");
|
||||
|
||||
mainWindow.setIcon(128, 128, icon.getPixelsPtr());
|
||||
Plansza plansza(mainWindow.getSize().y, mainWindow.getSize().x);
|
||||
|
||||
Plansza plansza(mainWindow.getSize().y, mainWindow.getSize().x);
|
||||
Background background("../assets/img/background/background.png", 2.0f); //tutaj predkosc tla, mozna zwiekszyc jak za wolno
|
||||
|
||||
|
||||
AudioManager audioManager;
|
||||
if (!audioManager.loadBackgroundMusic("../assets/music/background.ogg")) {
|
||||
return -1;
|
||||
}
|
||||
audioManager.loadBackgroundMusic("../assets/music/background.ogg");
|
||||
audioManager.playBackgroundMusic();
|
||||
|
||||
audioManager.loadSoundEffect("shoot", "../assets/sounds/shoot.ogg");
|
||||
@@ -133,7 +128,6 @@ int main()
|
||||
audioManager.playSoundEffect("fail", 70.f);
|
||||
audioManager.stopBackgroundMusic();
|
||||
while (errorWindow.isOpen()) {
|
||||
sf::Event event;
|
||||
while (errorWindow.pollEvent(event)) {
|
||||
if (event.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
|
||||
errorWindow.close();
|
||||
|
||||
@@ -10,6 +10,22 @@ Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth) {
|
||||
spawnClock.restart();
|
||||
}
|
||||
|
||||
Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::RenderWindow *mainWindow) {
|
||||
size.height = windowHeight;
|
||||
size.width = windowWidth;
|
||||
window = mainWindow;
|
||||
meteorTexture1.loadFromFile("../assets/img/meteors/meteor-1.png");
|
||||
meteorTexture2.loadFromFile("../assets/img/meteors/meteor-2.png");
|
||||
spawnClock.restart();
|
||||
}
|
||||
|
||||
|
||||
void Plansza::update() {
|
||||
|
||||
}
|
||||
|
||||
// Meteor-related niżej
|
||||
|
||||
void Plansza::spawn_meteor() {
|
||||
if (spawnClock.getElapsedTime().asSeconds() > rand() % 10 + 1) { // randomowy spawn meteorytów od 10 do 1 sekundy
|
||||
if (meteors.size() < 5) { // jeśli jest mniej niż 5 meteorów na planszy
|
||||
@@ -23,14 +39,6 @@ void Plansza::spawn_meteor() {
|
||||
}
|
||||
}
|
||||
|
||||
Size Plansza::getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
std::vector<Meteor> &Plansza::getMeteors() {
|
||||
return meteors;
|
||||
}
|
||||
|
||||
void Plansza::update_meteors() {
|
||||
// usuwanie meteorów które wyleciały poza ekran
|
||||
for (auto& meteor : meteors) {
|
||||
@@ -39,3 +47,14 @@ void Plansza::update_meteors() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Size Plansza::getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
std::vector<Meteor> &Plansza::getMeteors() {
|
||||
return meteors;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user