2016-06-09 17:07:38 +02:00
|
|
|
/* ************************************************************************** */
|
2016-06-10 15:28:40 +02:00
|
|
|
/* _____ _ __ ___ __ */
|
|
|
|
/* Object.cpp | ___(_)/ _| ___ ( _ ) / /_ */
|
|
|
|
/* Project: C-Engine | |_ | | |_ / _ \/ _ \| '_ \ */
|
|
|
|
/* | _| | | _| __/ (_) | (_) | */
|
|
|
|
/* Author: Fife <wasabifife@gmail.com> |_| |_|_| \___|\___/ \___/ */
|
2016-06-09 17:07:38 +02:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
2016-06-11 15:31:10 +02:00
|
|
|
#include "..\C-Engine\include\Object.hpp"
|
2016-06-09 17:07:38 +02:00
|
|
|
|
|
|
|
|
2016-06-10 15:28:40 +02:00
|
|
|
Object::Object()
|
|
|
|
{
|
|
|
|
OTransform = new Transform(this);
|
|
|
|
ORender = new Render(this);
|
|
|
|
tag = new char[20];
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
ORigidBody = NULL;
|
|
|
|
OScript = NULL;
|
|
|
|
Conteneur = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Object::~Object()
|
|
|
|
{
|
|
|
|
delete OTransform;
|
|
|
|
delete ORender;
|
|
|
|
delete ORigidBody;
|
|
|
|
delete OScript;
|
|
|
|
delete []tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Object::AffectEngine(Engine * EV)
|
|
|
|
{
|
|
|
|
Conteneur = EV;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Object::AffectScript(Script * SV)
|
|
|
|
{
|
|
|
|
OScript = SV;
|
|
|
|
OScript->AffectObject(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Object::AffectTag(char * v)
|
|
|
|
{
|
|
|
|
strcpy( tag , v );//Copie v dans tag.
|
|
|
|
}
|
|
|
|
|
|
|
|
void Object::Enable()
|
|
|
|
{
|
|
|
|
enable = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Object::Disable()
|
|
|
|
{
|
|
|
|
enable = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Object::AddRigidBody()
|
|
|
|
{
|
|
|
|
ORigidBody = new RigidBody(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Engine * Object::GetEngine()
|
|
|
|
{
|
|
|
|
return Conteneur;
|
|
|
|
}
|
|
|
|
|
|
|
|
Transform * Object::GetTransform()
|
|
|
|
{
|
|
|
|
return OTransform;
|
|
|
|
}
|
|
|
|
|
|
|
|
RigidBody * Object::GetRigidBody()
|
|
|
|
{
|
|
|
|
return ORigidBody;
|
|
|
|
}
|
|
|
|
|
|
|
|
Render * Object::GetRender()
|
|
|
|
{
|
|
|
|
return ORender;
|
|
|
|
}
|
|
|
|
|
|
|
|
Script * Object::GetScript()
|
|
|
|
{
|
|
|
|
return OScript;
|
|
|
|
}
|
|
|
|
|
|
|
|
char * Object::GetTag()
|
|
|
|
{
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Object::GetEnable()
|
|
|
|
{
|
|
|
|
return enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Object::IsOnScreen()
|
|
|
|
{
|
2016-06-14 15:39:24 +02:00
|
|
|
if(OTransform->GetX() < Conteneur->GetScreen()->max.x && OTransform->GetX() + ORender->GetSizeX() > Conteneur->GetScreen()->min.x && OTransform->GetY() < Conteneur->GetScreen()->max.y && OTransform->GetY() + ORender->GetSizeY() > Conteneur->GetScreen()->min.y ) return true;
|
|
|
|
else return false;
|
2016-06-09 17:07:38 +02:00
|
|
|
|
2016-06-10 15:28:40 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-06-09 17:07:38 +02:00
|
|
|
|
2016-06-10 15:28:40 +02:00
|
|
|
Object * Object::GetObjectCollisionTag( char* v, int x , int y)
|
|
|
|
{
|
2016-06-11 15:31:10 +02:00
|
|
|
if(Conteneur->GetCurrentLevel())
|
2016-06-09 17:07:38 +02:00
|
|
|
{
|
2016-06-11 15:31:10 +02:00
|
|
|
for( int i = 0; i < Conteneur->GetCurrentLevel()->GetNbObject(); i++ )
|
2016-06-09 17:07:38 +02:00
|
|
|
{
|
2016-06-11 15:31:10 +02:00
|
|
|
if(Conteneur->GetCurrentLevel()->GetListeObject()[i] != this)
|
2016-06-09 17:07:38 +02:00
|
|
|
{
|
2016-06-14 15:39:24 +02:00
|
|
|
if( Conteneur->GetCurrentLevel()->GetListeObject()[i]->TestTag(v) && Conteneur->GetCurrentLevel()->GetListeObject()[i]->enable)
|
2016-06-11 15:31:10 +02:00
|
|
|
{
|
|
|
|
if(Collision(i , Conteneur->GetCurrentLevel()))return Conteneur->GetCurrentLevel()->GetListeObject()[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( int i = 0; i < Conteneur->GetNbObject(); i++ )
|
|
|
|
{
|
|
|
|
if(Conteneur->GetListeObject()[i] != this)
|
|
|
|
{
|
2016-06-14 15:39:24 +02:00
|
|
|
if( Conteneur->GetCurrentLevel()->GetListeObject()[i]->TestTag(v) && Conteneur->GetListeObject()[i]->enable)
|
2016-06-11 15:31:10 +02:00
|
|
|
{
|
|
|
|
if(Collision(i))return Conteneur->GetListeObject()[i];
|
|
|
|
}
|
2016-06-09 17:07:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-10 15:28:40 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2016-06-09 17:07:38 +02:00
|
|
|
|
|
|
|
|
2016-06-10 15:28:40 +02:00
|
|
|
bool Object::GetCollisionTag(char* v , int x , int y)
|
|
|
|
{
|
|
|
|
if(GetObjectCollisionTag(v,x,y))return true;
|
2016-06-09 17:07:38 +02:00
|
|
|
|
2016-06-10 15:28:40 +02:00
|
|
|
return false;
|
|
|
|
}
|
2016-06-09 17:07:38 +02:00
|
|
|
|
2016-06-11 15:31:10 +02:00
|
|
|
bool Object::Collision(int id , Level * l)
|
2016-06-10 15:28:40 +02:00
|
|
|
{
|
2016-06-11 15:31:10 +02:00
|
|
|
Object * buffer;
|
|
|
|
|
|
|
|
if(l)buffer = Conteneur->GetCurrentLevel()->GetListeObject()[id];
|
|
|
|
else buffer = Conteneur->GetListeObject()[id];
|
|
|
|
|
2016-06-10 15:28:40 +02:00
|
|
|
int widht1 = ORender->GetSizeX();
|
|
|
|
int height1 = ORender->GetSizeY();
|
2016-06-11 15:31:10 +02:00
|
|
|
int widht2 = buffer->ORender->GetSizeX();
|
|
|
|
int height2 = buffer->ORender->GetSizeY();
|
2016-06-10 15:28:40 +02:00
|
|
|
|
|
|
|
if(ORigidBody)
|
|
|
|
{
|
|
|
|
if(ORigidBody->GetStat())
|
2016-06-09 17:07:38 +02:00
|
|
|
{
|
2016-06-10 15:28:40 +02:00
|
|
|
widht1 = ORigidBody->GetWidht();
|
|
|
|
height1 = ORigidBody->GetHeight();
|
2016-06-09 17:07:38 +02:00
|
|
|
}
|
2016-06-10 15:28:40 +02:00
|
|
|
}
|
2016-06-09 17:07:38 +02:00
|
|
|
|
2016-06-11 15:31:10 +02:00
|
|
|
if(buffer->ORigidBody)
|
2016-06-10 15:28:40 +02:00
|
|
|
{
|
2016-06-11 15:31:10 +02:00
|
|
|
if(buffer->ORigidBody->GetStat())
|
2016-06-09 17:07:38 +02:00
|
|
|
{
|
2016-06-11 15:31:10 +02:00
|
|
|
widht2 = buffer->ORigidBody->GetWidht();
|
|
|
|
height2 = buffer->ORigidBody->GetHeight();
|
2016-06-09 17:07:38 +02:00
|
|
|
}
|
2016-06-10 15:28:40 +02:00
|
|
|
}
|
2016-06-09 17:07:38 +02:00
|
|
|
|
2016-06-11 15:31:10 +02:00
|
|
|
if( (( buffer->OTransform->GetX() + buffer->ORender->GetBlitX() >= OTransform->GetX() + ORender->GetBlitX() + widht1)
|
|
|
|
|| (buffer->OTransform->GetX() + buffer->ORender->GetBlitX() + widht2 <= OTransform->GetX() + ORender->GetBlitX())
|
|
|
|
|| (buffer->OTransform->GetY() + buffer->ORender->GetBlitY()>= OTransform->GetY() + ORender->GetBlitY() + height1)
|
|
|
|
|| (buffer->OTransform->GetY() + buffer->ORender->GetBlitY() + height2 <= OTransform->GetY() + ORender->GetBlitY())
|
2016-06-10 15:28:40 +02:00
|
|
|
) == false )return true;
|
2016-06-09 17:07:38 +02:00
|
|
|
|
2016-06-10 15:28:40 +02:00
|
|
|
return false;
|
|
|
|
}
|
2016-06-09 17:07:38 +02:00
|
|
|
|
2016-06-14 15:39:24 +02:00
|
|
|
bool Object::TestTag(char * v)
|
|
|
|
{
|
|
|
|
if(!strcmp(tag , v))
|
|
|
|
return true;
|
2016-06-09 17:07:38 +02:00
|
|
|
|
2016-06-14 15:39:24 +02:00
|
|
|
return false;
|
|
|
|
}
|
2016-06-09 17:07:38 +02:00
|
|
|
|