Meteory są w tym samym stanie co w poprzednim commit, tylko, że teraz są zdefiniowane w osobnej klasie "Plansza"
This commit is contained in:
26
main.cpp
26
main.cpp
@@ -4,6 +4,7 @@
|
||||
#include "SFML/Graphics.hpp"
|
||||
#include "headers/Player.h"
|
||||
#include "headers/Meteor.h"
|
||||
#include "headers/Plansza.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
@@ -11,15 +12,7 @@ int main()
|
||||
sf::RenderWindow window(sf::VideoMode(600, 800), "My window");
|
||||
window.setVerticalSyncEnabled(true);
|
||||
window.setFramerateLimit(60);
|
||||
|
||||
// Ustawienia randomizera
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::uniform_int_distribution<> dis(0, 599);
|
||||
// Koniec ustawień randomizera
|
||||
|
||||
sf::Texture meteorTexture;
|
||||
meteorTexture.loadFromFile("../assets/img/meteor.png");
|
||||
Plansza plansza(window.getSize().y, window.getSize().x);
|
||||
|
||||
sf::Texture backgroundTexture;
|
||||
backgroundTexture.loadFromFile("../assets/img/space.jpg"); // wczytywanie tła
|
||||
@@ -29,9 +22,6 @@ int main()
|
||||
ship.setMovingSpeed(8);
|
||||
ship.setFirerate(200);
|
||||
|
||||
std::vector<Meteor> meteors;
|
||||
std::srand(static_cast<unsigned int>(std::time(nullptr)));
|
||||
|
||||
while (window.isOpen()) {
|
||||
window.clear();
|
||||
|
||||
@@ -80,23 +70,15 @@ int main()
|
||||
// TODO: Kolizje
|
||||
// Generate a new meteor at a random position at the top of the screen
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::M)) {
|
||||
int randomX = dis(gen);
|
||||
meteors.emplace_back(randomX, -100, meteorTexture);
|
||||
plansza.spawn_meteor();
|
||||
}
|
||||
|
||||
// Update and draw meteors
|
||||
for (auto& meteor : meteors) {
|
||||
for (auto& meteor : plansza.getMeteors()) {
|
||||
meteor.update();
|
||||
window.draw(meteor.getSprite());
|
||||
}
|
||||
|
||||
// Remove meteors that are out of bounds
|
||||
for (auto& meteor : meteors) {
|
||||
if(meteor.getStatus()) {
|
||||
meteors.erase(meteors.begin());
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& bullet : ship.getBullets()) {
|
||||
bullet.update();
|
||||
window.draw(bullet.getSprite());
|
||||
|
||||
Reference in New Issue
Block a user