AsteroidsSFML/Menu.h
2025-09-26 09:18:22 -06:00

832 lines
48 KiB
C++

//
// Created by benmo on 2/20/2020.
//
#ifndef SFML_TEMPLATE_MENU_H
#define SFML_TEMPLATE_MENU_H
#include <windows.h>
#include <shellapi.h>
#include <winuser.h>
class Menu {
public:
int result, musicPicked = 0;
bool soundOn = true, musicOn = true;
Time mTime;
Menu(int loop, Time time) {
musicPicked = loop;
result = init(time);
}
private:
sf::SoundBuffer bip;
sf::Sound bipSound;
bool playedBip = false;
int init(Time time) {
const int MENU = 0, CREDITS = 1;
int screen = 0;
std::vector<MySprite*> buttons;
std::vector<sf::Text*> text;
std::vector<sf::Text*> credits;
std::vector<sf::Sprite*> creditsGUI;
sf::RenderWindow window( sf::VideoMode(1240, 640), "Asteroids" );
sf::View mainView;
mainView.setCenter(window.getSize().x/(float)2.0, window.getSize().y/(float)2.0);
mainView.setSize(window.getSize().x, window.getSize().y);
window.setView(mainView);
window.setPosition(sf::Vector2i(window.getPosition().x, window.getPosition().y - 50));
/*************************************************
* File Input && Processing
*************************************************/
sf::Font sk;
sk.loadFromFile("data/Fonts/Sk.ttf");
sf::Font skME;
skME.loadFromFile("data/Fonts/SKoME.ttf");
sf::Font xolo;
xolo.loadFromFile("data/Fonts/Xolonium-Bold.ttf");
sf::Font monkirta;
monkirta.loadFromFile("data/Fonts/Monkirta Pursuit NC.ttf");
sf::Font oxan;
oxan.loadFromFile("data/Fonts/Oxanium-Light.ttf");
sf::Texture back;
back.loadFromFile("data/Gui/space.png");
back.setRepeated(true);
sf::Texture button;
button.loadFromFile("data/Gui/button.png");
sf::Texture box;
box.loadFromFile("data/Gui/window.png");
sf::Texture boxSm;
boxSm.loadFromFile("data/Gui/windowSm.png");
sf::Texture cloud;
cloud.loadFromFile("data/Gui/cloud.png");
sf::Texture leftArrow;
leftArrow.loadFromFile("data/Gui/Backward_BTN.png");
sf::Texture soundBTN;
soundBTN.loadFromFile("data/Gui/Sound.png");
sf::Texture musicBTN;
musicBTN.loadFromFile("data/Gui/Music.png");
sf::Texture initials;
initials.loadFromFile("data/Morgan Ben initials.png");
if (musicPicked == 0) {
default_random_engine gen(std::chrono::system_clock::now().time_since_epoch().count());
uniform_int_distribution<int> loopPicker(1, 2);
musicPicked = loopPicker(gen);
}
sf::Music menuLoop1;
menuLoop1.openFromFile("data/Sounds/Unknown Theme.wav");
menuLoop1.setVolume(60);
sf::Music menuLoop2;
menuLoop2.openFromFile("data/Sounds/loop.wav");
if (musicPicked == 1) {
menuLoop1.setPlayingOffset(time);
menuLoop1.play();
} else {
menuLoop2.setPlayingOffset(time);
menuLoop2.play();
}
bip.loadFromFile("data/Sounds/rollover.wav");
/*************************************************
* Object Initialization
*************************************************/
//Background pan sprite
sf::Sprite background(back);
sf::FloatRect fBounds(mainView.getCenter().x, mainView.getCenter().y, background.getTexture()->getSize().x * 3, background.getTexture()->getSize().y * 3);
sf::IntRect iBounds(fBounds);
background.setTextureRect(iBounds);
background.setPosition(mainView.getCenter());
background.setOrigin(iBounds.width/(float)2.0,iBounds.height/(float)2.0);
//Sound settings
MySprite soundButton(soundBTN, 25, 35, 37, 0, 0);
MySprite musicButton(musicBTN, 25, soundButton.getXPos() + soundButton.getGlobalBounds().width, soundButton.getYPos(), 0, 0);
//Title text
sf::Text title("Asteroids", skME, 90);
title.setPosition(mainView.getCenter().x, mainView.getCenter().y - window.getSize().y / (float)3.0);
title.setFillColor(sf::Color::White);
title.setLetterSpacing(title.getLetterSpacing() + (float)0.5);
title.setOrigin(title.getGlobalBounds().width/(float)2.0, title.getGlobalBounds().height/(float)2.0);
MySprite inits(initials, 15);
inits.setPosition(window.getSize().x - inits.getGlobalBounds().width + 10, window.getSize().y - inits.getGlobalBounds().height);
//Start button & text
MySprite startButton(button, 55);
startButton.setPosition(mainView.getCenter().x, mainView.getCenter().y - window.getSize().y / (float)12.0);
//default button color
sf::Color defButtonColor = startButton.getColor();
sf::Text startText("Start", sk, 28);
startText.setPosition(startButton.getPosition().x, startButton.getPosition().y - 7);
startText.setFillColor(sf::Color(0,0,0,0));
startText.setOutlineColor(sf::Color::White);
startText.setOutlineThickness(1);
startText.setLetterSpacing(startText.getLetterSpacing() + 1);
startText.setOrigin(startText.getLocalBounds().width/2, startText.getLocalBounds().height/2);
//Credits button & text
MySprite creditsButton(button, 55);
creditsButton.setPosition(mainView.getCenter().x, mainView.getCenter().y);
sf::Text creditsText("Credits", sk, 28);
creditsText.setPosition(creditsButton.getPosition().x, creditsButton.getPosition().y - 6);
creditsText.setFillColor(sf::Color(0,0,0,0));
creditsText.setOutlineColor(sf::Color::White);
creditsText.setOutlineThickness(1);
creditsText.setLetterSpacing(creditsText.getLetterSpacing() + 1);
creditsText.setOrigin(creditsText.getLocalBounds().width/2, creditsText.getLocalBounds().height/2);
//Exit button & text
MySprite exitButton(button, 55);
exitButton.setPosition(mainView.getCenter().x, mainView.getCenter().y + window.getSize().y / (float)12.0);
sf::Text exitText("Exit", sk, 28);
exitText.setPosition(mainView.getCenter().x, exitButton.getPosition().y - 6);
exitText.setFillColor(sf::Color(0,0,0,0));
exitText.setOutlineColor(sf::Color::White);
exitText.setOutlineThickness(1);
exitText.setLetterSpacing(exitText.getLetterSpacing() + 1);
exitText.setOrigin(exitText.getLocalBounds().width/2, exitText.getLocalBounds().height/2);
buttons.push_back(&startButton);
buttons.push_back(&creditsButton);
buttons.push_back(&exitButton);
text.push_back(&startText);
text.push_back(&creditsText);
text.push_back(&exitText);
//Credits
sf::Text creditsTitle("Credits + Resources", sk, 70);
creditsTitle.setPosition(mainView.getCenter().x, window.getSize().y / (float)14.0);
creditsTitle.setFillColor(sf::Color::White);
creditsTitle.setOrigin(creditsTitle.getGlobalBounds().width/2, creditsTitle.getGlobalBounds().height/2);
//Credits box
sf::Text credsTitle("Credits", xolo, 28);
credsTitle.setOrigin(credsTitle.getGlobalBounds().width/2, credsTitle.getGlobalBounds().height/2);
credsTitle.setPosition(mainView.getSize().x/(float)5.1, mainView.getSize().y/2 + mainView.getSize().y/22);
credsTitle.setFillColor(sf::Color::White);
sf::Text music("River Schreckengost - ", monkirta, 20);
music.setOrigin(music.getGlobalBounds().width/2, music.getGlobalBounds().height/2);
music.setPosition(mainView.getSize().x/(float)5.8, mainView.getSize().y/(float)2 + mainView.getSize().y/(float)8.5);
music.setFillColor(sf::Color::White);
sf::Text musicText("Music", oxan, 15);
musicText.setPosition(mainView.getSize().x/(float)5.8 + music.getGlobalBounds().width/2, mainView.getSize().y/(float)2 + mainView.getSize().y/(float)8.925);
musicText.setFillColor(sf::Color::White);
sf::Text musicLabel("Instagram - ", monkirta, 15);
musicLabel.setPosition(mainView.getSize().x/(float)11.5, mainView.getSize().y/(float)2 + mainView.getSize().y/(float)7.3);
musicLabel.setFillColor(sf::Color::White);
sf::Text musicText0("@river.schreck", oxan, 12);
musicText0.setPosition(mainView.getSize().x/(float)11.5 + musicLabel.getGlobalBounds().width, mainView.getSize().y/(float)2 + mainView.getSize().y/(float)7.15);
musicText0.setFillColor(sf::Color::White);
musicText0.setStyle(sf::Text::Style::Underlined);
sf::Text musicLabel0("SoundCloud - ", monkirta, 15);
musicLabel0.setPosition(mainView.getSize().x/(float)11.5, mainView.getSize().y/(float)2 + mainView.getSize().y/(float)6.1);
musicLabel0.setFillColor(sf::Color::White);
sf::Text musicText1("River Ethans", oxan, 12);
musicText1.setPosition(mainView.getSize().x/(float)11.5 + musicLabel0.getGlobalBounds().width, mainView.getSize().y/(float)2 + mainView.getSize().y/(float)5.95);
musicText1.setFillColor(sf::Color::White);
musicText1.setStyle(sf::Text::Style::Underlined);
sf::Text images("MillionthVector - ", monkirta, 20);
images.setOrigin(images.getGlobalBounds().width/2, images.getGlobalBounds().height/2);
images.setPosition(mainView.getSize().x/(float)6.75, mainView.getSize().y/(float)2 + mainView.getSize().y/(float)4.9);
images.setFillColor(sf::Color::White);
sf::Text imagesText("Images", oxan, 15);
imagesText.setPosition(mainView.getSize().x/(float)6.75 + images.getGlobalBounds().width/2, mainView.getSize().y/(float)2 + mainView.getSize().y/(float)4.975);
imagesText.setFillColor(sf::Color::White);
sf::Text imagesLabel("Website - ", monkirta, 15);
imagesLabel.setPosition(mainView.getSize().x/(float)11.5, mainView.getSize().y/(float)2 + mainView.getSize().y/(float)4.4);
imagesLabel.setFillColor(sf::Color::White);
sf::Text imagesText0("http://millionthvector.blogspot.com/", oxan, 12);
imagesText0.setPosition(mainView.getSize().x/(float)11.5 + imagesLabel.getGlobalBounds().width, mainView.getSize().y/(float)2 + mainView.getSize().y/(float)4.3);
imagesText0.setFillColor(sf::Color::White);
imagesText0.setStyle(sf::Text::Style::Underlined);
sf::Text gui("CraftPix.net - ", monkirta, 20);
gui.setOrigin(gui.getGlobalBounds().width/2, gui.getGlobalBounds().height/2);
gui.setPosition(mainView.getSize().x/(float)7.25, mainView.getSize().y/(float)2 + mainView.getSize().y/(float)4.9 + 42);
gui.setFillColor(sf::Color::White);
sf::Text guiText("Gui Elements", oxan, 15);
guiText.setPosition(mainView.getSize().x/(float)7.25 + gui.getGlobalBounds().width/2, mainView.getSize().y/(float)2 + mainView.getSize().y/(float)4.975 + 42);
guiText.setFillColor(sf::Color::White);
sf::Text guiLabel("Website - ", monkirta, 15);
guiLabel.setPosition(mainView.getSize().x/(float)11.5, mainView.getSize().y/(float)2 + mainView.getSize().y/(float)4.4 + 42);
guiLabel.setFillColor(sf::Color::White);
sf::Text guiText0("https://craftpix.net/", oxan, 12);
guiText0.setPosition(mainView.getSize().x/(float)11.5 + guiLabel.getGlobalBounds().width, mainView.getSize().y/(float)2 + mainView.getSize().y/(float)4.3 + 42);
guiText0.setFillColor(sf::Color::White);
guiText0.setStyle(sf::Text::Style::Underlined);
//Resources Box
sf::Text resourcesTitle("Resources", xolo, 28);
resourcesTitle.setOrigin(resourcesTitle.getGlobalBounds().width/2, resourcesTitle.getGlobalBounds().height/2);
resourcesTitle.setPosition(mainView.getSize().x - mainView.getSize().x/(float)4.95, mainView.getSize().y/(float)4.8);
resourcesTitle.setFillColor(sf::Color::White);
sf::Text bt("Button Tick", monkirta, 20);
bt.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.1275, mainView.getSize().y/(float)3.75);
bt.setFillColor(sf::Color::White);
sf::Text btLabel("Creator - ", monkirta, 15);
btLabel.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195, mainView.getSize().y/(float)3.325);
btLabel.setFillColor(sf::Color::White);
sf::Text btText("NenadSimic", oxan, 12);
btText.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195 + btLabel.getGlobalBounds().width, mainView.getSize().y/(float)3.3);
btText.setFillColor(sf::Color::White);
btText.setStyle(sf::Text::Style::Underlined);
sf::Text btLabel0("Source - ", monkirta, 15);
btLabel0.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195, mainView.getSize().y/(float)3.05);
btLabel0.setFillColor(sf::Color::White);
sf::Text btText0("https://freesound.org/s/268108/", oxan, 12);
btText0.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195 + btLabel0.getGlobalBounds().width, mainView.getSize().y/(float)3.025);
btText0.setFillColor(sf::Color::White);
btText0.setStyle(sf::Text::Style::Underlined);
sf::Text pew("Laser 'Pews'", monkirta, 20);
pew.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.1275, mainView.getSize().y/(float)3.75 + 58);
pew.setFillColor(sf::Color::White);
sf::Text pewLabel("Creator - ", monkirta, 15);
pewLabel.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195, mainView.getSize().y/(float)3.325 + 58);
pewLabel.setFillColor(sf::Color::White);
sf::Text pewText("SeanSecret", oxan, 12);
pewText.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195 + pewLabel.getGlobalBounds().width, mainView.getSize().y/(float)3.3 + 58);
pewText.setFillColor(sf::Color::White);
pewText.setStyle(sf::Text::Style::Underlined);
sf::Text pewLabel0("Source - ", monkirta, 15);
pewLabel0.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195, mainView.getSize().y/(float)3.05 + 58);
pewLabel0.setFillColor(sf::Color::White);
sf::Text pewText0("https://freesound.org/s/440661/", oxan, 12);
pewText0.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195 + pewLabel0.getGlobalBounds().width, mainView.getSize().y/(float)3.025 + 58);
pewText0.setFillColor(sf::Color::White);
pewText0.setStyle(sf::Text::Style::Underlined);
sf::Text life("New Life", monkirta, 20);
life.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.1275, mainView.getSize().y/(float)3.75 + 2*58);
life.setFillColor(sf::Color::White);
sf::Text lifeLabel("Creator - ", monkirta, 15);
lifeLabel.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195, mainView.getSize().y/(float)3.325 + 2*58);
lifeLabel.setFillColor(sf::Color::White);
sf::Text lifeText("SimonBay", oxan, 12);
lifeText.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195 + lifeLabel.getGlobalBounds().width, mainView.getSize().y/(float)3.3 + 2*58);
lifeText.setFillColor(sf::Color::White);
lifeText.setStyle(sf::Text::Style::Underlined);
sf::Text lifeLabel0("Source - ", monkirta, 15);
lifeLabel0.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195, mainView.getSize().y/(float)3.05 + 2*58);
lifeLabel0.setFillColor(sf::Color::White);
sf::Text lifeText0("https://freesound.org/s/439889/", oxan, 12);
lifeText0.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195 + lifeLabel0.getGlobalBounds().width, mainView.getSize().y/(float)3.025 + 2*58);
lifeText0.setFillColor(sf::Color::White);
lifeText0.setStyle(sf::Text::Style::Underlined);
sf::Text powerUp("Power Up", monkirta, 20);
powerUp.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.1275, mainView.getSize().y/(float)3.75 + 3*58);
powerUp.setFillColor(sf::Color::White);
sf::Text powerUpLabel("Creator - ", monkirta, 15);
powerUpLabel.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195, mainView.getSize().y/(float)3.325 + 3*58);
powerUpLabel.setFillColor(sf::Color::White);
sf::Text powerUpText("Joao_Janz", oxan, 12);
powerUpText.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195 + powerUpLabel.getGlobalBounds().width, mainView.getSize().y/(float)3.3 + 3*58);
powerUpText.setFillColor(sf::Color::White);
powerUpText.setStyle(sf::Text::Style::Underlined);
sf::Text powerUpLabel0("Source - ", monkirta, 15);
powerUpLabel0.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195, mainView.getSize().y/(float)3.05 + 3*58);
powerUpLabel0.setFillColor(sf::Color::White);
sf::Text powerUpText0("https://freesound.org/s/478338/", oxan, 12);
powerUpText0.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195 + powerUpLabel0.getGlobalBounds().width, mainView.getSize().y/(float)3.025 + 3*58);
powerUpText0.setFillColor(sf::Color::White);
powerUpText0.setStyle(sf::Text::Style::Underlined);
sf::Text playerExp("Player Explosion", monkirta, 20);
playerExp.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.1275, mainView.getSize().y/(float)3.75 + 4*58);
playerExp.setFillColor(sf::Color::White);
sf::Text playerExpLabel("Creator - ", monkirta, 15);
playerExpLabel.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195, mainView.getSize().y/(float)3.325 + 4*58);
playerExpLabel.setFillColor(sf::Color::White);
sf::Text playerExpText("ggctuk", oxan, 12);
playerExpText.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195 + playerExpLabel.getGlobalBounds().width, mainView.getSize().y/(float)3.3 + 4*58);
playerExpText.setFillColor(sf::Color::White);
playerExpText.setStyle(sf::Text::Style::Underlined);
sf::Text playerExpLabel0("Source - ", monkirta, 15);
playerExpLabel0.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195, mainView.getSize().y/(float)3.05 + 4*58);
playerExpLabel0.setFillColor(sf::Color::White);
sf::Text playerExpText0("https://freesound.org/s/80500/", oxan, 12);
playerExpText0.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195 + playerExpLabel0.getGlobalBounds().width, mainView.getSize().y/(float)3.025 + 4*58);
playerExpText0.setFillColor(sf::Color::White);
playerExpText0.setStyle(sf::Text::Style::Underlined);
sf::Text enemyExp("Enemy Explosion", monkirta, 20);
enemyExp.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.1275, mainView.getSize().y/(float)3.75 + 5*58);
enemyExp.setFillColor(sf::Color::White);
sf::Text enemyExpLabel("Creator - ", monkirta, 15);
enemyExpLabel.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195, mainView.getSize().y/(float)3.325 + 5*58);
enemyExpLabel.setFillColor(sf::Color::White);
sf::Text enemyExpText("Werra", oxan, 12);
enemyExpText.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195 + enemyExpLabel.getGlobalBounds().width, mainView.getSize().y/(float)3.3 + 5*58);
enemyExpText.setFillColor(sf::Color::White);
enemyExpText.setStyle(sf::Text::Style::Underlined);
sf::Text enemyExpLabel0("Source - ", monkirta, 15);
enemyExpLabel0.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195, mainView.getSize().y/(float)3.05 + 5*58);
enemyExpLabel0.setFillColor(sf::Color::White);
sf::Text enemyExpText0("https://freesound.org/s/244394/", oxan, 12);
enemyExpText0.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195 + enemyExpLabel0.getGlobalBounds().width, mainView.getSize().y/(float)3.025 + 5*58);
enemyExpText0.setFillColor(sf::Color::White);
enemyExpText0.setStyle(sf::Text::Style::Underlined);
sf::Text playerLost("Player Lost", monkirta, 20);
playerLost.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.1275, mainView.getSize().y/(float)3.75 + 6*58);
playerLost.setFillColor(sf::Color::White);
sf::Text playerLostLabel("Creator - ", monkirta, 15);
playerLostLabel.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195, mainView.getSize().y/(float)3.325 + 6*58);
playerLostLabel.setFillColor(sf::Color::White);
sf::Text playerLostText("zimbot", oxan, 12);
playerLostText.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195 + playerLostLabel.getGlobalBounds().width, mainView.getSize().y/(float)3.3 + 6*58);
playerLostText.setFillColor(sf::Color::White);
playerLostText.setStyle(sf::Text::Style::Underlined);
sf::Text playerLostLabel0("Source - ", monkirta, 15);
playerLostLabel0.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195, mainView.getSize().y/(float)3.05 + 6*58);
playerLostLabel0.setFillColor(sf::Color::White);
sf::Text playerLostText0("https://freesound.org/s/117323/", oxan, 12);
playerLostText0.setPosition(mainView.getSize().x - mainView.getSize().x/(float)3.195 + playerLostLabel0.getGlobalBounds().width, mainView.getSize().y/(float)3.025 + 6*58);
playerLostText0.setFillColor(sf::Color::White);
playerLostText0.setStyle(sf::Text::Style::Underlined);
//Dev box
sf::Text developerTitle("Developer: ", xolo, 25);
developerTitle.setPosition(mainView.getSize().x/13, mainView.getSize().y/(float)5.2);
developerTitle.setFillColor(sf::Color(0,0,0,0));
developerTitle.setOutlineThickness(.8);
developerTitle.setOutlineColor(sf::Color::White);
sf::Text developer("Benjamin Morgan", monkirta, 20);
developer.setOrigin(developer.getGlobalBounds().width/2, developer.getGlobalBounds().height/2);
developer.setPosition(mainView.getSize().x/(float)6.725, mainView.getSize().y/(float)3.95);
developer.setFillColor(sf::Color::White);
sf::Text devLabel("Site - ", monkirta, 15);
devLabel.setPosition(mainView.getSize().x/(float)11.5, mainView.getSize().y/(float)3.65);
devLabel.setFillColor(sf::Color::White);
sf::Text devText("https://www.benrmorgan.com/", oxan, 12);
devText.setPosition(mainView.getSize().x/(float)11.5 + devLabel.getGlobalBounds().width, mainView.getSize().y/(float)3.6);
devText.setFillColor(sf::Color::White);
devText.setStyle(sf::Text::Style::Underlined);
sf::Text devLabel0("Github - ", monkirta, 15);
devLabel0.setPosition(mainView.getSize().x/(float)11.5, mainView.getSize().y/(float)3.35);
devLabel0.setFillColor(sf::Color::White);
sf::Text devText0("bMorgan01", oxan, 12);
devText0.setPosition(mainView.getSize().x/(float)11.5 + devLabel0.getGlobalBounds().width, mainView.getSize().y/(float)3.3);
devText0.setFillColor(sf::Color::White);
devText0.setStyle(sf::Text::Style::Underlined);
sf::Text devLabel1("Email - ", monkirta, 15);
devLabel1.setPosition(mainView.getSize().x/(float)11.5, mainView.getSize().y/(float)3.1);
devLabel1.setFillColor(sf::Color::White);
sf::Text devText1("ben@benrmorgan.com", oxan, 12);
devText1.setPosition(mainView.getSize().x/(float)11.5 + devLabel1.getGlobalBounds().width, mainView.getSize().y/(float)3.05);
devText1.setFillColor(sf::Color::White);
devText1.setStyle(sf::Text::Style::Underlined);
sf::Text devLabel2("Repo - ", monkirta, 15);
devLabel2.setPosition(mainView.getSize().x/(float)11.5, mainView.getSize().y/(float)2.87);
devLabel2.setFillColor(sf::Color::White);
sf::Text devText2("https://github.com/bMorgan01/StarCap", oxan, 12);
devText2.setPosition(mainView.getSize().x/(float)11.5 + devLabel2.getGlobalBounds().width, mainView.getSize().y/(float)2.83);
devText2.setFillColor(sf::Color::White);
devText2.setStyle(sf::Text::Style::Underlined);
//Credits GUI
sf::Sprite backButton(leftArrow);
backButton.setScale(.3, .3);
backButton.setPosition(33, 100);
sf::Sprite textBox(box);
textBox.setScale(.35, .35);
textBox.setPosition(mainView.getSize().x - mainView.getSize().x/3, mainView.getSize().y/(float)5.5);
sf::Sprite textBoxSm(boxSm);
textBoxSm.setScale(.35, .35);
textBoxSm.setPosition(mainView.getSize().x/15, mainView.getSize().y/2 + mainView.getSize().y/50);
sf::Sprite devBox(cloud);
devBox.setScale(.442, .442);
devBox.setPosition(mainView.getSize().x/15 - 2, mainView.getSize().y/(float)5.5);
sf::Sprite issueButton(button);
issueButton.setColor(sf::Color::Red);
issueButton.setScale(40.0/100.0, 40.0/100.0);
issueButton.setOrigin(issueButton.getGlobalBounds().width/2, issueButton.getGlobalBounds().height/2);
issueButton.setPosition(mainView.getSize().x/(float)6.2, mainView.getSize().y/(float)2.52);
sf::Text issueText("Report Bug", sk, 16);
issueText.setPosition(issueButton.getPosition().x - 21, issueButton.getPosition().y);
issueText.setFillColor(sf::Color(0,0,0,0));
issueText.setFillColor(sf::Color::White);
credits.push_back(&creditsTitle);
credits.push_back(&developerTitle);
credits.push_back(&credsTitle);
credits.push_back(&music);
credits.push_back(&musicText);
credits.push_back(&musicLabel);
credits.push_back(&musicText0);
credits.push_back(&musicLabel0);
credits.push_back(&musicText1);
credits.push_back(&images);
credits.push_back(&imagesText);
credits.push_back(&imagesLabel);
credits.push_back(&imagesText0);
credits.push_back(&gui);
credits.push_back(&guiText);
credits.push_back(&guiLabel);
credits.push_back(&guiText0);
credits.push_back(&resourcesTitle);
credits.push_back(&bt);
credits.push_back(&btLabel);
credits.push_back(&btText);
credits.push_back(&btLabel0);
credits.push_back(&btText0);
credits.push_back(&pew);
credits.push_back(&pewLabel);
credits.push_back(&pewText);
credits.push_back(&pewLabel0);
credits.push_back(&pewText0);
credits.push_back(&life);
credits.push_back(&lifeLabel);
credits.push_back(&lifeText);
credits.push_back(&lifeLabel0);
credits.push_back(&lifeText0);
credits.push_back(&powerUp);
credits.push_back(&powerUpLabel);
credits.push_back(&powerUpText);
credits.push_back(&powerUpLabel0);
credits.push_back(&powerUpText0);
credits.push_back(&playerExp);
credits.push_back(&playerExpLabel);
credits.push_back(&playerExpText);
credits.push_back(&playerExpLabel0);
credits.push_back(&playerExpText0);
credits.push_back(&enemyExp);
credits.push_back(&enemyExpLabel);
credits.push_back(&enemyExpText);
credits.push_back(&enemyExpLabel0);
credits.push_back(&enemyExpText0);
credits.push_back(&playerLost);
credits.push_back(&playerLostLabel);
credits.push_back(&playerLostText);
credits.push_back(&playerLostLabel0);
credits.push_back(&playerLostText0);
credits.push_back(&developer);
credits.push_back(&devLabel);
credits.push_back(&devText);
credits.push_back(&devLabel0);
credits.push_back(&devText0);
credits.push_back(&devLabel1);
credits.push_back(&devText1);
credits.push_back(&devLabel2);
credits.push_back(&devText2);
credits.push_back(&issueText);
creditsGUI.push_back(&backButton);
creditsGUI.push_back(&textBox);
creditsGUI.push_back(&textBoxSm);
creditsGUI.push_back(&devBox);
creditsGUI.push_back(&issueButton);
while( window.isOpen() ) {
/*********************************************
* Pre-draw ops here.
*********************************************/
/*********************************************
* Drawing goes here.
*********************************************/
window.clear( sf::Color::Black ); // clear the contents of the old frame
window.draw(background);
switch(screen) {
case MENU:
/**************
* Draw Menu
**************/
backButton.setPosition(33, 100);
//Sound buttons
window.draw(soundButton);
window.draw(musicButton);
//Title text
window.draw(title);
for (int i = 0; i < buttons.size(); i++) {
window.draw(*buttons[i]);
window.draw(*text[i]);
}
window.draw(inits);
break;
case CREDITS:
/**************
* Draw Credits
**************/
backButton.setPosition(33, 27);
for (sf::Sprite *s : creditsGUI) {
window.draw(*s);
}
for (sf::Text *t : credits) {
window.draw(*t);
}
break;
}
window.display(); // display the window
if (musicPicked == 1 && menuLoop1.getStatus() == Music::Stopped) {
menuLoop2.setPlayingOffset(Time::Zero);
menuLoop2.play();
musicPicked = 2;
} else if (musicPicked == 2 && menuLoop2.getStatus() == Music::Stopped) {
menuLoop1.setPlayingOffset(Time::Zero);
menuLoop1.play();
musicPicked = 1;
}
sf::Event event{};
while( window.pollEvent(event) ) { // ask the window if any events occurred
/*********************************************
* Event handling here.
*********************************************/
sf::Vector2i mousePos = sf::Mouse::getPosition( window );
sf::Vector2f mousePosF( static_cast<float>( mousePos.x ), static_cast<float>( mousePos.y ) );
switch (event.type) {
case sf::Event::Closed: //user clicked X button
window.close();
break;
case sf::Event::MouseButtonPressed: //User clicked mouse
if (exitButton.getGlobalBounds().contains(mousePosF) && screen == MENU) {
playBip();
return EXIT_FAILURE;
} else if (startButton.getGlobalBounds().contains(mousePosF) && screen == MENU) {
playBip();
if (musicPicked == 1) mTime = menuLoop1.getPlayingOffset();
else mTime = menuLoop2.getPlayingOffset();
menuLoop1.stop();
menuLoop2.stop();
return EXIT_SUCCESS;
} else if (creditsButton.getGlobalBounds().contains(mousePosF) && screen == MENU) {
playBip();
screen = CREDITS;
} else if (issueButton.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
ShellExecute(nullptr, "open", "https://github.com/bMorgan01/Asteroids/issues", nullptr, nullptr, SW_SHOWNORMAL);
} else if (devText.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
ShellExecute(nullptr, "open", "https://www.benrmorgan.com", nullptr, nullptr, SW_SHOWNORMAL);
} else if (devText0.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
ShellExecute(nullptr, "open", "https://github.com/bMorgan01", nullptr, nullptr, SW_SHOWNORMAL);
} else if (devText1.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
ShellExecute(nullptr, "open", "mailto:ben@benrmorgan.com", nullptr, nullptr, SW_SHOWNORMAL);
} else if (devText2.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
ShellExecute(nullptr, "open", "https://github.com/bMorgan01/Asteroids", nullptr, nullptr, SW_SHOWNORMAL);
} else if (musicText0.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
ShellExecute(nullptr, "open", "https://www.instagram.com/river.schreck/", nullptr, nullptr, SW_SHOWNORMAL);
} else if (musicText1.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
ShellExecute(nullptr, "open", "https://soundcloud.com/riverethans", nullptr, nullptr, SW_SHOWNORMAL);
} else if (imagesText0.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
ShellExecute(nullptr, "open", "http://millionthvector.blogspot.com/", nullptr, nullptr, SW_SHOWNORMAL);
} else if (guiText0.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
ShellExecute(nullptr, "open", "https://craftpix.net/", nullptr, nullptr, SW_SHOWNORMAL);
} else if (btText.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
ShellExecute(nullptr, "open", "https://freesound.org/people/NenadSimic/", nullptr, nullptr, SW_SHOWNORMAL);
} else if (btText0.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
ShellExecute(nullptr, "open", "https://freesound.org/s/268108/", nullptr, nullptr, SW_SHOWNORMAL);
} else if (pewText.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
ShellExecute(nullptr, "open", "https://freesound.org/people/SeanSecret/", nullptr, nullptr, SW_SHOWNORMAL);
} else if (pewText0.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
ShellExecute(nullptr, "open", "https://freesound.org/s/440661/", nullptr, nullptr, SW_SHOWNORMAL);
} else if (lifeText.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
ShellExecute(nullptr, "open", "https://freesound.org/people/SimonBay/", nullptr, nullptr, SW_SHOWNORMAL);
} else if (lifeText0.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
ShellExecute(nullptr, "open", "https://freesound.org/s/439889/", nullptr, nullptr, SW_SHOWNORMAL);
} else if (powerUpText.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
ShellExecute(nullptr, "open", "https://freesound.org/people/Joao_Janz/", nullptr, nullptr, SW_SHOWNORMAL);
} else if (powerUpText0.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
ShellExecute(nullptr, "open", "https://freesound.org/s/478338/", nullptr, nullptr, SW_SHOWNORMAL);
} else if (playerExpText.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
ShellExecute(nullptr, "open", "https://freesound.org/people/ggctuk/", nullptr, nullptr, SW_SHOWNORMAL);
} else if (playerExpText0.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
ShellExecute(nullptr, "open", "https://freesound.org/s/80500/", nullptr, nullptr, SW_SHOWNORMAL);
} else if (enemyExpText.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
ShellExecute(nullptr, "open", "https://freesound.org/people/Werra/", nullptr, nullptr, SW_SHOWNORMAL);
} else if (enemyExpText0.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
ShellExecute(nullptr, "open", "https://freesound.org/s/244394/", nullptr, nullptr, SW_SHOWNORMAL);
} else if (playerLostText.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
ShellExecute(nullptr, "open", "https://freesound.org/people/zimbot/", nullptr, nullptr, SW_SHOWNORMAL);
} else if (playerLostText0.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
ShellExecute(nullptr, "open", "https://freesound.org/s/117323/", nullptr, nullptr, SW_SHOWNORMAL);
} else if (backButton.getGlobalBounds().contains(mousePosF) && screen == CREDITS) {
playBip();
screen = MENU;
} else if (soundButton.getGlobalBounds().contains(mousePosF) && screen == MENU) {
soundOn = !soundOn;
playBip();
} else if (musicButton.getGlobalBounds().contains(mousePosF) && screen == MENU) {
playBip();
musicOn = !musicOn;
if (!musicOn) {
menuLoop1.setVolume(0);
menuLoop2.setVolume(0);
} else {
menuLoop1.setVolume(60);
menuLoop2.setVolume(100);
}
}
break;
case sf::Event::MouseMoved:
if (exitButton.getGlobalBounds().contains(mousePosF) && screen == MENU) exitButton.setColor(sf::Color::Red);
else if (startButton.getGlobalBounds().contains(mousePosF) && screen == MENU) startButton.setColor(sf::Color::Red);
else if (creditsButton.getGlobalBounds().contains(mousePosF) && screen == MENU) creditsButton.setColor(sf::Color::Red);
else if (issueButton.getGlobalBounds().contains(mousePosF) && screen == CREDITS) issueButton.setColor(sf::Color::Green);
else if (devText.getGlobalBounds().contains(mousePosF) && screen == CREDITS) devText.setFillColor(sf::Color::Red);
else if (devText0.getGlobalBounds().contains(mousePosF) && screen == CREDITS) devText0.setFillColor(sf::Color::Red);
else if (devText1.getGlobalBounds().contains(mousePosF) && screen == CREDITS) devText1.setFillColor(sf::Color::Red);
else if (devText2.getGlobalBounds().contains(mousePosF) && screen == CREDITS) devText2.setFillColor(sf::Color::Red);
else if (musicText0.getGlobalBounds().contains(mousePosF) && screen == CREDITS) musicText0.setFillColor(sf::Color::Red);
else if (musicText1.getGlobalBounds().contains(mousePosF) && screen == CREDITS) musicText1.setFillColor(sf::Color::Red);
else if (imagesText0.getGlobalBounds().contains(mousePosF) && screen == CREDITS) imagesText0.setFillColor(sf::Color::Red);
else if (guiText0.getGlobalBounds().contains(mousePosF) && screen == CREDITS) guiText0.setFillColor(sf::Color::Red);
else if (btText.getGlobalBounds().contains(mousePosF) && screen == CREDITS) btText.setFillColor(sf::Color::Red);
else if (btText0.getGlobalBounds().contains(mousePosF) && screen == CREDITS) btText0.setFillColor(sf::Color::Red);
else if (pewText.getGlobalBounds().contains(mousePosF) && screen == CREDITS) pewText.setFillColor(sf::Color::Red);
else if (pewText0.getGlobalBounds().contains(mousePosF) && screen == CREDITS) pewText0.setFillColor(sf::Color::Red);
else if (lifeText.getGlobalBounds().contains(mousePosF) && screen == CREDITS) lifeText.setFillColor(sf::Color::Red);
else if (lifeText0.getGlobalBounds().contains(mousePosF) && screen == CREDITS) lifeText0.setFillColor(sf::Color::Red);
else if (powerUpText.getGlobalBounds().contains(mousePosF) && screen == CREDITS) powerUpText.setFillColor(sf::Color::Red);
else if (powerUpText0.getGlobalBounds().contains(mousePosF) && screen == CREDITS) powerUpText0.setFillColor(sf::Color::Red);
else if (playerExpText.getGlobalBounds().contains(mousePosF) && screen == CREDITS) playerExpText.setFillColor(sf::Color::Red);
else if (playerExpText0.getGlobalBounds().contains(mousePosF) && screen == CREDITS) playerExpText0.setFillColor(sf::Color::Red);
else if (enemyExpText.getGlobalBounds().contains(mousePosF) && screen == CREDITS) enemyExpText.setFillColor(sf::Color::Red);
else if (enemyExpText0.getGlobalBounds().contains(mousePosF) && screen == CREDITS) enemyExpText0.setFillColor(sf::Color::Red);
else if (playerLostText.getGlobalBounds().contains(mousePosF) && screen == CREDITS) playerLostText.setFillColor(sf::Color::Red);
else if (playerLostText0.getGlobalBounds().contains(mousePosF) && screen == CREDITS) playerLostText0.setFillColor(sf::Color::Red);
else if (backButton.getGlobalBounds().contains(mousePosF) && screen == CREDITS) backButton.setColor(sf::Color::Red);
else if (soundButton.getGlobalBounds().contains(mousePosF) && soundOn && screen == MENU) soundButton.setColor(sf::Color::Red);
else if (musicButton.getGlobalBounds().contains(mousePosF) && musicOn && screen == MENU) musicButton.setColor(sf::Color::Red);
else if (soundButton.getGlobalBounds().contains(mousePosF) && !soundOn && screen == MENU) soundButton.setColor(sf::Color::White);
else if (musicButton.getGlobalBounds().contains(mousePosF) && !musicOn && screen == MENU) musicButton.setColor(sf::Color::White);
break;
}
if (!exitButton.getGlobalBounds().contains(mousePosF)) exitButton.setColor(defButtonColor);
if (!startButton.getGlobalBounds().contains(mousePosF)) startButton.setColor(defButtonColor);
if (!creditsButton.getGlobalBounds().contains(mousePosF)) creditsButton.setColor(defButtonColor);
if (!issueButton.getGlobalBounds().contains(mousePosF)) issueButton.setColor(sf::Color::Red);
if (!devText.getGlobalBounds().contains(mousePosF)) devText.setFillColor(sf::Color::White);
if (!devText0.getGlobalBounds().contains(mousePosF)) devText0.setFillColor(sf::Color::White);
if (!devText1.getGlobalBounds().contains(mousePosF)) devText1.setFillColor(sf::Color::White);
if (!devText2.getGlobalBounds().contains(mousePosF)) devText2.setFillColor(sf::Color::White);
if (!musicText0.getGlobalBounds().contains(mousePosF)) musicText0.setFillColor(sf::Color::White);
if (!musicText1.getGlobalBounds().contains(mousePosF)) musicText1.setFillColor(sf::Color::White);
if (!imagesText0.getGlobalBounds().contains(mousePosF)) imagesText0.setFillColor(sf::Color::White);
if (!guiText0.getGlobalBounds().contains(mousePosF)) guiText0.setFillColor(sf::Color::White);
if (!btText.getGlobalBounds().contains(mousePosF)) btText.setFillColor(sf::Color::White);
if (!btText0.getGlobalBounds().contains(mousePosF)) btText0.setFillColor(sf::Color::White);
if (!pewText.getGlobalBounds().contains(mousePosF)) pewText.setFillColor(sf::Color::White);
if (!pewText0.getGlobalBounds().contains(mousePosF)) pewText0.setFillColor(sf::Color::White);
if (!lifeText.getGlobalBounds().contains(mousePosF)) lifeText.setFillColor(sf::Color::White);
if (!lifeText0.getGlobalBounds().contains(mousePosF)) lifeText0.setFillColor(sf::Color::White);
if (!powerUpText.getGlobalBounds().contains(mousePosF)) powerUpText.setFillColor(sf::Color::White);
if (!powerUpText0.getGlobalBounds().contains(mousePosF)) powerUpText0.setFillColor(sf::Color::White);
if (!playerExpText.getGlobalBounds().contains(mousePosF)) playerExpText.setFillColor(sf::Color::White);
if (!playerExpText0.getGlobalBounds().contains(mousePosF)) playerExpText0.setFillColor(sf::Color::White);
if (!enemyExpText.getGlobalBounds().contains(mousePosF)) enemyExpText.setFillColor(sf::Color::White);
if (!enemyExpText0.getGlobalBounds().contains(mousePosF)) enemyExpText0.setFillColor(sf::Color::White);
if (!playerLostText.getGlobalBounds().contains(mousePosF)) playerLostText.setFillColor(sf::Color::White);
if (!playerLostText0.getGlobalBounds().contains(mousePosF)) playerLostText0.setFillColor(sf::Color::White);
if (!backButton.getGlobalBounds().contains(mousePosF)) backButton.setColor(defButtonColor);
if (!soundButton.getGlobalBounds().contains(mousePosF) && soundOn) soundButton.setColor(sf::Color::White);
if (!musicButton.getGlobalBounds().contains(mousePosF) && musicOn) musicButton.setColor(sf::Color::White);
if (!soundButton.getGlobalBounds().contains(mousePosF) && !soundOn) soundButton.setColor(sf::Color::Red);
if (!musicButton.getGlobalBounds().contains(mousePosF) && !musicOn) musicButton.setColor(sf::Color::Red);
}
}
return EXIT_FAILURE;
}
void playBip() {
if (soundOn) {
bipSound.setBuffer(bip);
bipSound.setVolume(100);
bipSound.play();
}
}
};
#endif //SFML_TEMPLATE_MENU_H