mirror of
https://forge.univ-lyon1.fr/tplifap4/dungeonanddeamon.git
synced 2024-02-27 13:31:50 +01:00
111 lines
2.1 KiB
C++
111 lines
2.1 KiB
C++
#include "GestionJeu.h"
|
|
|
|
#include <Sprite.hpp>
|
|
#include <CollisionShape2D.hpp>
|
|
#include <ResourceLoader.hpp>
|
|
#include <CircleShape2D.hpp>
|
|
#include <GodotGlobal.hpp>
|
|
#include <Texture.hpp>
|
|
#include <AnimatedSprite.hpp>
|
|
|
|
#include "MobsCorpACorpIA.h"
|
|
|
|
using namespace godot;
|
|
|
|
GestionJeu::GestionJeu()
|
|
{
|
|
//Instanciation des principales classes des gestion des elmts du jeu
|
|
gPlayer = GestionPlayer::_new();
|
|
gTerrain = GestionTerrain::_new();
|
|
|
|
gMobs = new GestionMobs();
|
|
gCollision = new GestionCollision(gMobs, gPlayer, gTerrain);
|
|
}
|
|
|
|
GestionJeu::~GestionJeu()
|
|
{
|
|
//delete gTerrain;
|
|
//delete gPlayer;
|
|
delete gMobs;
|
|
delete gCollision;
|
|
}
|
|
|
|
/**
|
|
* <summary>Associe les méthodes GODOT aux méthodes de la classe</summary>
|
|
*/
|
|
void GestionJeu::_register_methods()
|
|
{
|
|
register_method((char*)"_init", &GestionJeu::_init);
|
|
register_method((char*)"_ready", &GestionJeu::_ready);
|
|
register_method((char*)"_process", &GestionJeu::_process);
|
|
}
|
|
|
|
/**
|
|
* <summary>Methode éxécutée lors de l'initialison de la classe (par godot)</summary>
|
|
*/
|
|
void GestionJeu::_init()
|
|
{
|
|
//Godot::print("Initialisation...");
|
|
create_scene();
|
|
//Godot::print("Initialisation OK !");
|
|
}
|
|
|
|
/**
|
|
* <summary>Methode éxécutée suivant l'initialison de la classe</summary>
|
|
*/
|
|
void GestionJeu::_ready()
|
|
{
|
|
//Godot::print("Ready...");
|
|
setup_scene();
|
|
//Godot::print("Ready OK !");
|
|
|
|
}
|
|
|
|
/**
|
|
* <summary>Methode éxécutée en boucle par Godot</summary>
|
|
*/
|
|
void GestionJeu::_process()
|
|
{
|
|
// Check des collisions
|
|
gCollision->CheckCollisonSol();
|
|
|
|
|
|
Vector2 posPlayer = gPlayer->get_position();
|
|
for (MobsCorpACorpIA* m : gMobs->mobs)
|
|
{
|
|
m->UpdateTargetPosition(posPlayer);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* <summary>Méthdode appelé lors de l'initilisation</summary>
|
|
*/
|
|
void GestionJeu::create_scene()
|
|
{
|
|
add_child(gPlayer);
|
|
add_child(gTerrain);
|
|
gMobs->AjoutMobC2C(10, 20, 5, 0, 1, 25);
|
|
|
|
for (MobsCorpACorpIA* m : gMobs->mobs)
|
|
{
|
|
auto mob = (MobsCorpACorpIA*) m;
|
|
Godot::print("Add child mob");
|
|
add_child(m);
|
|
m->setPosition(15.0f, 150.0f);
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* <summary></summary>
|
|
*/
|
|
void GestionJeu::setup_scene()
|
|
{
|
|
gPlayer->setPosition(15.0f, 150.0f);
|
|
|
|
gTerrain->GenerationCarte();
|
|
|
|
}
|
|
|
|
|