Zaimplementowane menu i wybieranie skinów statku
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 773 B |
BIN
assets/ship/nova.png
Normal file
BIN
assets/ship/nova.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 154 KiB |
BIN
assets/ship/pulsar.png
Normal file
BIN
assets/ship/pulsar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 188 KiB |
BIN
assets/ship/zenith.png
Normal file
BIN
assets/ship/zenith.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 221 KiB |
@@ -17,9 +17,16 @@
|
||||
#include "Heart.hpp"
|
||||
#include "Size.h"
|
||||
|
||||
enum ships{
|
||||
nova,
|
||||
pulsar,
|
||||
zenith,
|
||||
none
|
||||
};
|
||||
|
||||
class Plansza {
|
||||
public:
|
||||
Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::RenderWindow *mainWindow);
|
||||
Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::RenderWindow *mainWindow, ships selectedShip);
|
||||
Size getSize();
|
||||
std::vector<Meteor> &getMeteors();
|
||||
void spawn_meteor();
|
||||
@@ -37,6 +44,8 @@ public:
|
||||
~Plansza() {
|
||||
delete ship; // usuwanie wskaźnika ship
|
||||
}
|
||||
|
||||
static ships selectedShip;
|
||||
private:
|
||||
Background background;
|
||||
AudioManager audioManager;
|
||||
|
||||
154
main.cpp
154
main.cpp
@@ -3,7 +3,13 @@
|
||||
|
||||
#include "headers/Plansza.h"
|
||||
|
||||
ships selectedShip = none;
|
||||
|
||||
void menu();
|
||||
|
||||
int main() {
|
||||
menu();
|
||||
|
||||
std::clog << "Game started\n";
|
||||
sf::RenderWindow mainWindow(sf::VideoMode(600, 800), "LotoStatek");
|
||||
mainWindow.setVerticalSyncEnabled(true);
|
||||
@@ -14,7 +20,7 @@ int main() {
|
||||
mainWindow.setIcon(128, 128, icon.getPixelsPtr());
|
||||
|
||||
|
||||
Plansza plansza(mainWindow.getSize().y, mainWindow.getSize().x, &mainWindow);
|
||||
Plansza plansza(mainWindow.getSize().y, mainWindow.getSize().x, &mainWindow, selectedShip);
|
||||
|
||||
while (mainWindow.isOpen()) {
|
||||
mainWindow.clear();
|
||||
@@ -32,4 +38,148 @@ int main() {
|
||||
}
|
||||
|
||||
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 (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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,24 @@
|
||||
#include "../headers/Plansza.h"
|
||||
#include "../headers/RandomNumberGenerator.h"
|
||||
|
||||
Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::RenderWindow *mainWindow)
|
||||
Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::RenderWindow *mainWindow, ships selectedShip)
|
||||
: background("../assets/img/background/background.png", 2.0f) {
|
||||
window = mainWindow;
|
||||
size.height = static_cast<int>(windowHeight);
|
||||
size.width = static_cast<int>(windowWidth);
|
||||
|
||||
Plansza::selectedShip = selectedShip;
|
||||
|
||||
try {
|
||||
playerTexture.loadFromFile("../assets/ship/Dreadnought-Base.png");
|
||||
if(selectedShip == nova) {
|
||||
playerTexture.loadFromFile("../assets/ship/nova.png");
|
||||
} else if(selectedShip == pulsar) {
|
||||
playerTexture.loadFromFile("../assets/ship/pulsar.png");
|
||||
} else if(selectedShip == zenith) {
|
||||
playerTexture.loadFromFile("../assets/ship/zenith.png");
|
||||
} else {
|
||||
playerTexture.loadFromFile("../assets/ship/Dreadnought-Base.png");
|
||||
}
|
||||
meteorTexture1.loadFromFile("../assets/img/meteors/meteor-1.png");
|
||||
meteorTexture2.loadFromFile("../assets/img/meteors/meteor-2.png");
|
||||
// Ładowanie tekstur wrogów
|
||||
@@ -803,4 +813,6 @@ void Plansza::update_score() {
|
||||
text.setFillColor(sf::Color::White);
|
||||
text.setPosition(25, 25);
|
||||
window->draw(text);
|
||||
}
|
||||
}
|
||||
|
||||
ships Plansza::selectedShip = none;
|
||||
@@ -7,8 +7,13 @@
|
||||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
#include <SFML/Graphics/Text.hpp>
|
||||
|
||||
#include "../headers/Plansza.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) {
|
||||
|
||||
Reference in New Issue
Block a user