Renommage Engine -> Game

This commit is contained in:
Mattéo Delabre 2016-03-28 15:05:18 +02:00
parent 14f9587fd8
commit c505437e01
3 changed files with 41 additions and 44 deletions

View File

@ -1,5 +1,5 @@
#ifndef __PTF_ENGINE_HPP__ #ifndef __PTF_GAME_HPP__
#define __PTF_ENGINE_HPP__ #define __PTF_GAME_HPP__
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp> #include <SFML/Audio.hpp>
@ -7,12 +7,11 @@
#include "engine_state.hpp" #include "engine_state.hpp"
#include "resource_manager.hpp" #include "resource_manager.hpp"
/** /**
* La classe principale Engine coordonne les éléments * La classe Game gère l'affichage et les objets
* du jeu et organise le dessin des frames * d'une partie de jeu
*/ */
class Engine { class Game {
private: private:
sf::Clock clock; sf::Clock clock;
sf::RenderWindow window; sf::RenderWindow window;
@ -24,7 +23,7 @@ private:
/** /**
* Met à jour les objets du jeu pour * Met à jour les objets du jeu pour
* qu'ils s'adaptent au nouvel état du moteur * qu'ils s'adaptent au nouvel état
*/ */
void update(); void update();
@ -34,7 +33,7 @@ private:
void draw(); void draw();
public: public:
Engine(); Game();
/** /**
* Démarre la boucle principale du jeu * Démarre la boucle principale du jeu
@ -48,4 +47,3 @@ public:
}; };
#endif #endif

View File

@ -1,9 +1,9 @@
#include "engine.hpp" #include "game.hpp"
#include "constants.hpp" #include "constants.hpp"
#include <cmath> #include <cmath>
#include <queue> #include <queue>
Engine::Engine() : window( Game::Game() : window(
sf::VideoMode(704, 480), "Projet CMI", sf::Style::Default, sf::VideoMode(704, 480), "Projet CMI", sf::Style::Default,
sf::ContextSettings(0, 0, 2) sf::ContextSettings(0, 0, 2)
), view(sf::FloatRect(0, 0, 704, 480)) { ), view(sf::FloatRect(0, 0, 704, 480)) {
@ -14,7 +14,7 @@ Engine::Engine() : window(
window.setView(view); window.setView(view);
} }
void Engine::start() { void Game::start() {
float accumulator = 0; float accumulator = 0;
if (!music.openFromFile("./res/music_lvl1.wav")) if (!music.openFromFile("./res/music_lvl1.wav"))
{ {
@ -66,11 +66,11 @@ void Engine::start() {
} }
} }
void Engine::addObject(Object& object) { void Game::addObject(Object& object) {
state.objects.push_back(&object); state.objects.push_back(&object);
} }
void Engine::update() { void Game::update() {
std::vector<CollisionData> colliding; std::vector<CollisionData> colliding;
// détection des objets en collision // détection des objets en collision
@ -117,7 +117,7 @@ void Engine::update() {
} }
} }
void Engine::draw() { void Game::draw() {
// efface la scène précédente et dessine la couche de fond // efface la scène précédente et dessine la couche de fond
window.clear(sf::Color(66, 165, 245)); window.clear(sf::Color(66, 165, 245));

View File

@ -1,12 +1,12 @@
#include "player.hpp" #include "player.hpp"
#include "block.hpp" #include "block.hpp"
#include "engine.hpp" #include "game.hpp"
#include "constants.hpp" #include "constants.hpp"
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
int main() { int main() {
Engine engine; Game game;
Player player1(3.5f * Constants::GRID, 10 * Constants::GRID); Player player1(3.5f * Constants::GRID, 10 * Constants::GRID);
player1.setPlayerNumber(1); player1.setPlayerNumber(1);
@ -40,33 +40,33 @@ int main() {
block22.setCharge(1.f); block22.setCharge(1.f);
block22.setMass(2); block22.setMass(2);
engine.addObject(player1); game.addObject(player1);
engine.addObject(player2); game.addObject(player2);
engine.addObject(block01); game.addObject(block01);
engine.addObject(block02); game.addObject(block02);
engine.addObject(block03); game.addObject(block03);
engine.addObject(block04); game.addObject(block04);
engine.addObject(block05); game.addObject(block05);
engine.addObject(block06); game.addObject(block06);
engine.addObject(block07); game.addObject(block07);
engine.addObject(block08); game.addObject(block08);
engine.addObject(block09); game.addObject(block09);
engine.addObject(block10); game.addObject(block10);
engine.addObject(block11); game.addObject(block11);
engine.addObject(block12); game.addObject(block12);
engine.addObject(block13); game.addObject(block13);
engine.addObject(block14); game.addObject(block14);
engine.addObject(block15); game.addObject(block15);
engine.addObject(block16); game.addObject(block16);
engine.addObject(block17); game.addObject(block17);
engine.addObject(block18); game.addObject(block18);
engine.addObject(block19); game.addObject(block19);
engine.addObject(block20); game.addObject(block20);
engine.addObject(block21); game.addObject(block21);
engine.addObject(block22); game.addObject(block22);
try { try {
engine.start(); game.start();
} catch (const std::exception& exception) { } catch (const std::exception& exception) {
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "Le programme a quitté après une erreur d'exécution." << std::endl; std::cerr << "Le programme a quitté après une erreur d'exécution." << std::endl;
@ -76,4 +76,3 @@ int main() {
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }