Meteoryty lecą w trybie testowym.
This commit is contained in:
66
main.cpp
66
main.cpp
@@ -1,9 +1,9 @@
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <random>
|
||||
|
||||
#include "SFML/Graphics.hpp"
|
||||
#include "headers/Player.h"
|
||||
#include "headers/Bullet.h"
|
||||
#include "headers/Meteor.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
@@ -12,6 +12,15 @@ int main()
|
||||
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");
|
||||
|
||||
sf::Texture backgroundTexture;
|
||||
backgroundTexture.loadFromFile("../assets/img/space.jpg"); // wczytywanie tła
|
||||
sf::Sprite backgroundSprite(backgroundTexture); // tworzenie tła
|
||||
@@ -20,6 +29,9 @@ 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();
|
||||
|
||||
@@ -33,16 +45,6 @@ int main()
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
|
||||
window.close();
|
||||
}
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) {
|
||||
ship.shoot();
|
||||
}
|
||||
}
|
||||
|
||||
if(event.type == sf::Event::MouseButtonPressed) {
|
||||
if(event.mouseButton.button == sf::Mouse::Left)
|
||||
ship.shoot();
|
||||
else
|
||||
ship.alternate_shoot();
|
||||
}
|
||||
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
|
||||
@@ -50,11 +52,6 @@ int main()
|
||||
ship.moveLeft();
|
||||
}
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
|
||||
if(ship.getPosition().x < 480) {
|
||||
ship.moveRight();
|
||||
}
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
|
||||
if(ship.getPosition().y > 0) {
|
||||
ship.moveUp();
|
||||
@@ -65,6 +62,40 @@ int main()
|
||||
ship.moveDown();
|
||||
}
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
|
||||
if(ship.getPosition().x < 480) {
|
||||
ship.moveRight();
|
||||
}
|
||||
}
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) {
|
||||
ship.shoot();
|
||||
}
|
||||
|
||||
|
||||
if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) ship.shoot();
|
||||
if(sf::Mouse::isButtonPressed(sf::Mouse::Right)) ship.alternate_shoot();
|
||||
|
||||
|
||||
// TODO: Meteory na jednym poziomie ze statkiem
|
||||
// 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);
|
||||
}
|
||||
|
||||
// Update and draw meteors
|
||||
for (auto& meteor : meteors) {
|
||||
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();
|
||||
@@ -73,6 +104,7 @@ int main()
|
||||
|
||||
ship.updateBullets();
|
||||
window.draw(ship.getSprite());
|
||||
|
||||
window.display();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user