You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PacMan/iaghost2.cpp

105 lines
2.6 KiB

#include "..\C-Engine\CHeader.hpp"
#include "GUI.hpp"
#include "iaghost2.hpp"
void IA2::Start()
{
direction=1;
directionuser=1;
}
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();
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)));
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 --;
}
}
//***********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;
}
}