mirror of
https://forge.univ-lyon1.fr/tplifap4/dungeonanddeamon.git
synced 2024-02-27 13:31:50 +01:00
59 lines
1.5 KiB
C++
59 lines
1.5 KiB
C++
#include "GestionCollision.h"
|
|
|
|
#include <Texture.hpp>
|
|
#include <string>
|
|
|
|
GestionCollision::GestionCollision(GestionMobs* m, GestionPlayer* p, GestionTerrain* t) : gMobs(m), gPlayer(p), gTerrain(t)
|
|
{
|
|
}
|
|
|
|
std::vector<MobsIA*> GestionCollision::CheckCollisonSol()
|
|
{
|
|
std::vector<MobsIA*> mobs_collision;
|
|
/*for (MobsIA* m : gMobs->mobs)
|
|
{
|
|
Vector2 pos = m->get_transform().get_origin();
|
|
Vector2 size = m->get_transform().get_scale();
|
|
for (StaticBody2D* elem : gTerrain->elems_terrains)
|
|
{
|
|
if (elem->get_transform().get_origin().y > pos.x) {
|
|
Godot::print("Mob touche");
|
|
mobs_collision.push_back(m);
|
|
}
|
|
}
|
|
}*/
|
|
|
|
Vector2 posPlayer = gPlayer->get_transform().get_origin();
|
|
Vector2 taille_Player = ((Sprite*)gPlayer->get_children()[0])->get_texture().ptr()->get_size();
|
|
|
|
bool player_touch = false;
|
|
for (StaticBody2D* elem : gTerrain->elems_terrains)
|
|
{
|
|
Vector2 posTerrain = elem->get_transform().get_origin();
|
|
Vector2 taille_Sol = ((Sprite*)elem->get_children()[0])->get_texture().ptr()->get_size();
|
|
|
|
|
|
if (posTerrain.y - (taille_Sol.y) < posPlayer.y
|
|
&& posTerrain.y > posPlayer.y
|
|
&& posTerrain.x - (taille_Sol.x / 2) < posPlayer.x + taille_Player.x / 4
|
|
&& posTerrain.x + (taille_Sol.x / 2) > posPlayer.x - taille_Player.x / 4) {
|
|
|
|
player_touch = true;
|
|
break;
|
|
}
|
|
}
|
|
gPlayer->on_ground = player_touch;
|
|
|
|
return mobs_collision;
|
|
}
|
|
|
|
std::vector<MobsIA*> GestionCollision::CheckCollisonMur()
|
|
{
|
|
return std::vector<MobsIA*>();
|
|
}
|
|
|
|
std::vector<MobsIA*> GestionCollision::CheckCollisonToit()
|
|
{
|
|
return std::vector<MobsIA*>();
|
|
}
|