Modification plus propre de la vue
This commit is contained in:
parent
552adfb670
commit
6f0ff5131e
|
@ -32,6 +32,22 @@ private:
|
|||
|
||||
public:
|
||||
Game();
|
||||
virtual ~Game();
|
||||
|
||||
/**
|
||||
* Charge un niveau de jeu depuis le fichier donné
|
||||
*/
|
||||
void load();
|
||||
|
||||
/**
|
||||
* Sauvegarde la configuration actuelle comme un niveau
|
||||
*/
|
||||
void save();
|
||||
|
||||
/**
|
||||
* Libère les ressources du niveau
|
||||
*/
|
||||
void clear();
|
||||
|
||||
/**
|
||||
* Demande le passage à la frame suivante sur
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "resource_manager.hpp"
|
||||
#include "view.hpp"
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* Gestionnaire principal de toutes les vues et
|
||||
|
@ -17,10 +18,9 @@ private:
|
|||
ResourceManager resource_manager;
|
||||
std::array<bool, sf::Keyboard::KeyCount> keys;
|
||||
|
||||
public:
|
||||
// FIXME: devrait être privé
|
||||
View* view;
|
||||
std::shared_ptr<View> view;
|
||||
|
||||
public:
|
||||
Manager();
|
||||
|
||||
/**
|
||||
|
@ -28,6 +28,11 @@ public:
|
|||
*/
|
||||
void start();
|
||||
|
||||
/**
|
||||
* Charge la vue donnée dans le jeu
|
||||
*/
|
||||
void setView(std::shared_ptr<View> set_view);
|
||||
|
||||
/**
|
||||
* Renvoie la fenêtre actuellement utilisée pour le dessin
|
||||
*/
|
||||
|
|
|
@ -11,13 +11,13 @@ class Object;
|
|||
*/
|
||||
class View {
|
||||
public:
|
||||
virtual ~View() {}
|
||||
|
||||
/**
|
||||
* Demande le passage à la frame suivante sur
|
||||
* cette vue
|
||||
*/
|
||||
virtual void frame(Manager& manager) = 0;
|
||||
|
||||
virtual void addObject(Object& object) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
32
src/game.cpp
32
src/game.cpp
|
@ -3,6 +3,8 @@
|
|||
#include <cmath>
|
||||
#include <queue>
|
||||
|
||||
#include "player.hpp"
|
||||
|
||||
Game::Game() : accumulator(0.f) {
|
||||
if (!music.openFromFile("./res/music_lvl1.wav")) {
|
||||
// erreur
|
||||
|
@ -11,10 +13,36 @@ Game::Game() : accumulator(0.f) {
|
|||
music.play();
|
||||
music.setVolume(15);
|
||||
music.setLoop(true);
|
||||
|
||||
load();
|
||||
}
|
||||
|
||||
void Game::addObject(Object& object) {
|
||||
objects.push_back(&object);
|
||||
Game::~Game() {
|
||||
clear();
|
||||
}
|
||||
|
||||
void Game::load() {
|
||||
// vide le niveau précédent s'il y a lieu
|
||||
if (objects.size()) {
|
||||
clear();
|
||||
}
|
||||
|
||||
// TODO: faire une vraie fonction de chargement
|
||||
Player* player1 = new Player(3.5f * Constants::GRID, 10 * Constants::GRID);
|
||||
objects.push_back(player1);
|
||||
}
|
||||
|
||||
void Game::save() {
|
||||
// TODO: faire une fonction d'enregistrement
|
||||
// TODO: migrer sur une classe commune Game <-> Editor
|
||||
}
|
||||
|
||||
void Game::clear() {
|
||||
for (unsigned int i = 0; i < objects.size(); i++) {
|
||||
delete objects[i];
|
||||
}
|
||||
|
||||
objects.clear();
|
||||
}
|
||||
|
||||
void Game::frame(Manager& manager) {
|
||||
|
|
62
src/main.cpp
62
src/main.cpp
|
@ -5,69 +5,13 @@
|
|||
#include "constants.hpp"
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
int main() {
|
||||
Manager manager;
|
||||
std::shared_ptr<Game> game = std::shared_ptr<Game>(new Game);
|
||||
|
||||
Player player1(3.5f * Constants::GRID, 10 * Constants::GRID);
|
||||
player1.setPlayerNumber(1);
|
||||
Player player2(18.5f * Constants::GRID, 10 * Constants::GRID);
|
||||
player2.setPlayerNumber(2);
|
||||
Block block01(2 * Constants::GRID, 10 * Constants::GRID);
|
||||
Block block02(2 * Constants::GRID, 11 * Constants::GRID);
|
||||
Block block03(3 * Constants::GRID, 11 * Constants::GRID);
|
||||
Block block04(4 * Constants::GRID, 11 * Constants::GRID);
|
||||
Block block05(5 * Constants::GRID, 11 * Constants::GRID);
|
||||
Block block06(6 * Constants::GRID, 11 * Constants::GRID);
|
||||
Block block07(7 * Constants::GRID, 11 * Constants::GRID);
|
||||
Block block08(8 * Constants::GRID, 11 * Constants::GRID);
|
||||
Block block09(9 * Constants::GRID, 11 * Constants::GRID);
|
||||
Block block10(10 * Constants::GRID, 11 * Constants::GRID);
|
||||
Block block11(11 * Constants::GRID, 11 * Constants::GRID);
|
||||
Block block12(12 * Constants::GRID, 11 * Constants::GRID);
|
||||
Block block13(13 * Constants::GRID, 11 * Constants::GRID);
|
||||
Block block14(14 * Constants::GRID, 11 * Constants::GRID);
|
||||
Block block15(15 * Constants::GRID, 11 * Constants::GRID);
|
||||
Block block16(16 * Constants::GRID, 11 * Constants::GRID);
|
||||
Block block17(17 * Constants::GRID, 11 * Constants::GRID);
|
||||
Block block18(18 * Constants::GRID, 11 * Constants::GRID);
|
||||
Block block19(19 * Constants::GRID, 11 * Constants::GRID);
|
||||
Block block20(20 * Constants::GRID, 10 * Constants::GRID);
|
||||
Block block21(20 * Constants::GRID, 11 * Constants::GRID);
|
||||
Block block22(11 * Constants::GRID, 10 * Constants::GRID);
|
||||
|
||||
player1.setCharge(-.01f);
|
||||
player2.setCharge(-.01f);
|
||||
block22.setCharge(1.f);
|
||||
block22.setMass(2);
|
||||
|
||||
Game game_view;
|
||||
manager.view = &game_view;
|
||||
|
||||
manager.view->addObject(player1);
|
||||
manager.view->addObject(player2);
|
||||
manager.view->addObject(block01);
|
||||
manager.view->addObject(block02);
|
||||
manager.view->addObject(block03);
|
||||
manager.view->addObject(block04);
|
||||
manager.view->addObject(block05);
|
||||
manager.view->addObject(block06);
|
||||
manager.view->addObject(block07);
|
||||
manager.view->addObject(block08);
|
||||
manager.view->addObject(block09);
|
||||
manager.view->addObject(block10);
|
||||
manager.view->addObject(block11);
|
||||
manager.view->addObject(block12);
|
||||
manager.view->addObject(block13);
|
||||
manager.view->addObject(block14);
|
||||
manager.view->addObject(block15);
|
||||
manager.view->addObject(block16);
|
||||
manager.view->addObject(block17);
|
||||
manager.view->addObject(block18);
|
||||
manager.view->addObject(block19);
|
||||
manager.view->addObject(block20);
|
||||
manager.view->addObject(block21);
|
||||
manager.view->addObject(block22);
|
||||
manager.setView(game);
|
||||
|
||||
try {
|
||||
manager.start();
|
||||
|
|
|
@ -40,6 +40,10 @@ void Manager::start() {
|
|||
}
|
||||
}
|
||||
|
||||
void Manager::setView(std::shared_ptr<View> set_view) {
|
||||
view = set_view;
|
||||
}
|
||||
|
||||
sf::RenderWindow& Manager::getWindow() {
|
||||
return window;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue