2016-04-30 13:47:44 +02:00
|
|
|
#include "..\C-Engine\CHeader.hpp"
|
|
|
|
#include "GUI.hpp"
|
|
|
|
#include "iaghost2.hpp"
|
|
|
|
|
|
|
|
void IA2::Start()
|
|
|
|
{
|
2016-05-02 20:10:33 +02:00
|
|
|
direction=0;
|
|
|
|
directionuser=0;
|
|
|
|
couldown = 0;
|
2016-04-30 13:47:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void IA2::Initialisation(Script_GUI * v)
|
|
|
|
{
|
|
|
|
SGUI = v ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IA2::Update()
|
|
|
|
{
|
|
|
|
|
|
|
|
if(SGUI->GetVulnerability() > 0)SetIt(1);
|
|
|
|
else SetIt(0);
|
|
|
|
|
|
|
|
//Intersection//
|
|
|
|
|
|
|
|
int difx = GetEngine()->GetListeObject()[0]->GetTransforms()->GetX() - GetX();
|
|
|
|
int dify = GetEngine()->GetListeObject()[0]->GetTransforms()->GetY() - GetY();
|
|
|
|
|
2016-05-02 20:10:33 +02:00
|
|
|
if(couldown <= 0)
|
2016-04-30 13:47:44 +02:00
|
|
|
{
|
|
|
|
|
2016-05-02 20:10:33 +02:00
|
|
|
if(!GetObject()->CollisionTag("Jail"))
|
2016-04-30 13:47:44 +02:00
|
|
|
{
|
|
|
|
|
2016-05-02 20:10:33 +02:00
|
|
|
if(!GetObject()->GetRigibody()->CollisionDecor(GetX() + (direction%2), GetY() + (!(direction%2))) || !GetObject()->GetRigibody()->CollisionDecor(GetX() - (direction%2), GetY() - (!(direction%2))))
|
|
|
|
{
|
|
|
|
PrintMini(10,10,"Test",0);
|
|
|
|
|
|
|
|
bool possibledirection[4];
|
|
|
|
for(int i = 0; i < 4 ; i++)possibledirection[i] = !(GetObject()->GetRigibody()->CollisionDecor(GetX() + (i == 1) - (i == 3), GetY() + (i == 0) - (i == 2)));
|
|
|
|
|
|
|
|
if(GetObject()->CollisionTag("Jail",0,-1))possibledirection[2] = false;
|
|
|
|
|
|
|
|
int betterdirection[4]; int best;
|
|
|
|
if(ABS(difx) > ABS(dify))best = 1;
|
|
|
|
else best = 2;
|
|
|
|
|
|
|
|
if(difx == 0)best = 2;
|
|
|
|
if(dify == 0)best = 1;
|
|
|
|
|
|
|
|
if(difx > 0)
|
|
|
|
{
|
|
|
|
betterdirection[ (best == 2)] = 2;
|
|
|
|
betterdirection[ 3 -(best == 2)] = 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
betterdirection[ (best == 2)] = 4;
|
|
|
|
betterdirection[ 3 -(best == 2)] = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dify > 0)
|
|
|
|
{
|
|
|
|
betterdirection[ (best == 1)] = 1;
|
|
|
|
betterdirection[ 3 -(best == 1)] = 3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
betterdirection[ (best == 1)] = 3;
|
|
|
|
betterdirection[ 3 -(best == 1)] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int end = 4;
|
|
|
|
while(end > 0)
|
|
|
|
{
|
|
|
|
if(possibledirection[betterdirection[4 - end] - 1])
|
|
|
|
{
|
|
|
|
directionuser = betterdirection[4 - end];
|
|
|
|
end = 0;
|
|
|
|
}
|
|
|
|
else end --;
|
|
|
|
}
|
|
|
|
}
|
2016-04-30 13:47:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-02 20:10:33 +02:00
|
|
|
if(GetObject()->GetRigibody()->CollisionDecor(GetX() , GetY()+1))
|
|
|
|
{
|
|
|
|
Object * Jail = GetObject()->CollisionTagO("Jail");
|
|
|
|
if(Jail != NULL)
|
|
|
|
{
|
|
|
|
if(Jail->GetTransforms()->GetX() + 20 < GetX())directionuser = 4;
|
|
|
|
else directionuser = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else directionuser = 1;
|
2016-04-30 13:47:44 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-02 20:10:33 +02:00
|
|
|
else couldown --;
|
2016-04-30 13:47:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
//***********Deplacement***********//
|
|
|
|
|
|
|
|
if(!GetObject()->GetRigibody()->CollisionDecor( GetX() + (directionuser == 2) - (directionuser == 4) , GetY() + (directionuser == 1) - (directionuser == 3) ))direction = directionuser;
|
|
|
|
|
|
|
|
|
|
|
|
switch(direction)
|
|
|
|
{
|
|
|
|
case 1: Move(0,1); break;
|
|
|
|
case 2: Move(1,0); break;
|
|
|
|
case 3: Move(0,-1); break;
|
|
|
|
case 4: Move(-1,0); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//************//
|
|
|
|
|
|
|
|
if(GetObject()->CollisionTag("TP1"))
|
|
|
|
{
|
|
|
|
GetObject()->GetTransforms()->SetXY(229,138);
|
|
|
|
direction = 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(GetObject()->CollisionTag("TP2"))
|
|
|
|
{
|
|
|
|
GetObject()->GetTransforms()->SetXY(2,138);
|
|
|
|
direction = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|