Début du menu
This commit is contained in:
parent
83e644a0e8
commit
3c66542bca
|
@ -0,0 +1,46 @@
|
|||
#ifndef __PTF_MENU_HPP__
|
||||
#define __PTF_MENU_HPP__
|
||||
|
||||
#include <SFML/Audio.hpp>
|
||||
#include "manager.hpp"
|
||||
#include "view.hpp"
|
||||
#include "resource_manager.hpp"
|
||||
#include <vector>
|
||||
|
||||
#define NB_CHOICES 4
|
||||
|
||||
/**
|
||||
* La classe Menu charge le menu du jeu
|
||||
* et permet de choisir entre jouer, lire les règles
|
||||
* et quitter.
|
||||
*/
|
||||
class Menu : public View {
|
||||
|
||||
public:
|
||||
Menu(Manager& manager);
|
||||
virtual ~Menu();
|
||||
|
||||
/**
|
||||
* Dessine le menu
|
||||
*/
|
||||
void frame();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void MoveUp();
|
||||
void MoveDown();
|
||||
|
||||
private:
|
||||
//repère le choix sélectionné
|
||||
int selection;
|
||||
|
||||
sf::Font font;
|
||||
|
||||
//tableau de textes modélisant les différents
|
||||
//choix dans le menu
|
||||
sf::Text choice[NB_CHOICES];
|
||||
};
|
||||
|
||||
|
||||
#endif
|
Binary file not shown.
|
@ -1,11 +1,14 @@
|
|||
#include "manager.hpp"
|
||||
#include "editor.hpp"
|
||||
#include "menu.hpp"
|
||||
#include "game.hpp"
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <fstream>
|
||||
|
||||
int main() {
|
||||
Manager manager;
|
||||
std::shared_ptr<Menu> menu = std::shared_ptr<Menu>(new Menu(manager));
|
||||
std::shared_ptr<Editor> editor = std::shared_ptr<Editor>(new Editor(manager));
|
||||
|
||||
try {
|
||||
|
@ -15,7 +18,7 @@ int main() {
|
|||
editor->load(file);
|
||||
file.close();
|
||||
|
||||
manager.setView(editor);
|
||||
manager.setView(menu);
|
||||
manager.start();
|
||||
} catch (const std::exception& exception) {
|
||||
std::cerr << "Le programme a quitté après une erreur d'exécution." << std::endl;
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
#include "menu.hpp"
|
||||
|
||||
Menu::Menu(Manager& manager) : View(manager){
|
||||
|
||||
//mise en place des propriétés des textes affichés dans le menu
|
||||
choice[0].setFont(manager.getResourceManager().getFont("Raleway-Regular.ttf"));
|
||||
choice[0].setColor(sf::Color::Red);
|
||||
choice[0].setPosition(sf::Vector2f(460, 400/(NB_CHOICES + 1)));
|
||||
|
||||
for(int i=1; i < NB_CHOICES; i++)
|
||||
{
|
||||
choice[i].setFont(manager.getResourceManager().getFont("Raleway-Regular.ttf"));
|
||||
choice[i].setColor(sf::Color::White);
|
||||
choice[i].setPosition(sf::Vector2f(460, 400/((NB_CHOICES + 1))*(i+1)));
|
||||
}
|
||||
choice[0].setString("Jouer");
|
||||
choice[1].setString("Regles du jeu");
|
||||
choice[2].setString("Creer un niveau");
|
||||
choice[3].setString("Quitter");
|
||||
|
||||
//choix sélectionné à l'ouverture du menu
|
||||
selection = 0;
|
||||
|
||||
if (manager.isKeyPressed(sf::Keyboard::Up)) {
|
||||
MoveUp();
|
||||
}
|
||||
if (manager.isKeyPressed(sf::Keyboard::Down)) {
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
|
||||
Menu::~Menu(){
|
||||
}
|
||||
|
||||
void Menu::frame(){
|
||||
sf::RenderWindow& window = manager.getWindow();
|
||||
window.clear(sf::Color(66, 165, 245));
|
||||
|
||||
//dessin des textes du menu
|
||||
for(int i=0; i<NB_CHOICES; i++)
|
||||
{
|
||||
window.draw(choice[i]);
|
||||
}
|
||||
window.display();
|
||||
}
|
||||
|
||||
void Menu::MoveUp()
|
||||
{
|
||||
if(selection-1 >= 0)
|
||||
{
|
||||
choice[selection].setColor(sf::Color::White);
|
||||
selection--;
|
||||
choice[selection].setColor(sf::Color::Red);
|
||||
}
|
||||
}
|
||||
|
||||
void Menu::MoveDown()
|
||||
{
|
||||
if(selection+1 >= NB_CHOICES)
|
||||
{
|
||||
choice[selection].setColor(sf::Color::White);
|
||||
selection++;
|
||||
choice[selection].setColor(sf::Color::Red);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue