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.

401 lines
12 KiB

#include "..\C-Engine\CHeader.hpp"
#include "GUI.hpp"
#include "IaGhost.hpp"
void IAG::Start()
{
direction=0;
directionuser=0;
couldown = 0;
}
void IAG::Initialisation(Script_GUI * v)
{
SGUI = v ;
}
void IAG::SetGhost(int v)
{
ghost = v;
}
void IAG::Update()
{
if(SGUI->GetVulnerability() > 0)
{
SetIt(1);
couldown = 0;
}
else SetIt(0);
if(GetObject()->CollisionTag("Jail"))
{
ScriptJail();
}
else
{
switch(ghost)
{
case 1: ScriptRed();break;
case 2: ScriptYellow();break;
case 3: ScriptBlue();break;
case 4: ScriptPink();break;
}
}
UpdateDirection();
}
void IAG::InvDirection()
{
switch(direction)
{
case 1: direction = 3; directionuser = 3; break;
case 2: direction = 4; directionuser = 4; break;
case 3: direction = 1; directionuser = 1; break;
case 4: direction = 2; directionuser = 2; break;
}
if(recur < 2)UpdateDirection();
}
void IAG::UpdateDirection()
{
if(!GetObject()->GetRigibody()->CollisionDecor( GetX() + (directionuser == 2) - (directionuser == 4) , GetY() + (directionuser == 1) - (directionuser == 3) ))direction = directionuser;
if(couldown <= 1)
{
recur ++;
switch(direction)
{
case 1: if(!GetObject()->CollisionTag("Ghost",0,1))Move(0,1);else InvDirection(); break;
case 2: if(!GetObject()->CollisionTag("Ghost",1,0))Move(1,0);else InvDirection(); break;
case 3: if(!GetObject()->CollisionTag("Ghost",0,-1))Move(0,-1);else InvDirection(); break;
case 4: if(!GetObject()->CollisionTag("Ghost",-1,0))Move(-1,0);else InvDirection(); break;
}
recur = 0;
}
//************Teleportation*************//
if(GetObject()->CollisionTag("TP1"))
{
GetObject()->GetTransforms()->SetXY(229,138);
direction = 4;
}
if(GetObject()->CollisionTag("TP2"))
{
GetObject()->GetTransforms()->SetXY(2,138);
direction = 2;
}
}
void IAG::ScriptJail()
{
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;
}
void IAG::ScriptRed()
{
int difx = GetEngine()->GetListeObject()[0]->GetTransforms()->GetX() - GetX();
int dify = GetEngine()->GetListeObject()[0]->GetTransforms()->GetY() - GetY();
if(couldown <= 0)
{
if(!GetObject()->GetRigibody()->CollisionDecor(GetX() + (direction%2), GetY() + (!(direction%2))) || !GetObject()->GetRigibody()->CollisionDecor(GetX() - (direction%2), GetY() - (!(direction%2))))
{
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;
}
if(SGUI->GetVulnerability() > 0)
{
bool buffer[4];
for(int i = 0; i < 4 ; i++)buffer[i] = betterdirection[i];
for(int i = 0; i < 4 ; i++)betterdirection[i] = buffer[3 - i];
}
int end = 4;
while(end > 0)
{
if(possibledirection[betterdirection[4 - end] - 1])
{
directionuser = betterdirection[4 - end];
end = 0;
}
else end --;
}
couldown = rand_int(10);
}
}
else couldown --;
}
void IAG::ScriptYellow()
{
int hasard;
if(!(!GetObject()->GetRigibody()->CollisionDecor(GetX(), GetY() + 1) && !GetObject()->GetRigibody()->CollisionDecor(GetX() , GetY() - 1) &&!GetObject()->GetRigibody()->CollisionDecor(GetX() + 1 , GetY()) && !GetObject()->GetRigibody()->CollisionDecor(GetX() - 1 , GetY())))
{
switch(direction)
{
case 1:
if(!GetObject()->GetRigibody()->CollisionDecor(GetX(), GetY() + 1) || !GetObject()->GetRigibody()->CollisionDecor(GetX() , GetY() - 1))
{
hasard = rand_int(3) + 1;
switch(hasard)
{
case 1: directionuser = 1;break;
case 2: directionuser = 2;break;
case 3: directionuser = 4;break;
}
}
break;
case 2:
if(!GetObject()->GetRigibody()->CollisionDecor(GetX() + 1 , GetY()) || !GetObject()->GetRigibody()->CollisionDecor(GetX() - 1 , GetY()))
{
hasard = rand_int(3) + 1;
switch(hasard)
{
case 1: directionuser = 2;break;
case 2: directionuser = 1;break;
case 3: directionuser = 3;break;
}
}
break;
case 3:
if(!GetObject()->GetRigibody()->CollisionDecor(GetX(), GetY() + 1) || !GetObject()->GetRigibody()->CollisionDecor(GetX(), GetY() - 1))
{
hasard = rand_int(3) + 1;
switch(hasard)
{
case 1: directionuser = 3;break;
case 2: directionuser = 2;break;
case 3: directionuser = 4;break;
}
}
break;
case 4:
if(!GetObject()->GetRigibody()->CollisionDecor(GetX() + 1 , GetY()) || !GetObject()->GetRigibody()->CollisionDecor(GetX() - 1 , GetY()))
{
hasard = rand_int(3) + 1;
switch(hasard)
{
case 1: directionuser = 4;break;
case 2: directionuser = 1;break;
case 3: directionuser = 3;break;
}
}
break;
}
}
}
void IAG::ScriptBlue()
{
int difx = GetEngine()->GetListeObject()[0]->GetTransforms()->GetX() - GetX();
int dify = GetEngine()->GetListeObject()[0]->GetTransforms()->GetY() - GetY();
if(couldown <= 0)
{
if(!GetObject()->GetRigibody()->CollisionDecor(GetX() + (direction%2), GetY() + (!(direction%2))) || !GetObject()->GetRigibody()->CollisionDecor(GetX() - (direction%2), GetY() - (!(direction%2))))
{
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)] = 4;
betterdirection[ 3 -(best == 2)] = 2;
}
else
{
betterdirection[ (best == 2)] = 2;
betterdirection[ 3 -(best == 2)] = 4;
}
if(dify > 0)
{
betterdirection[ (best == 1)] = 3;
betterdirection[ 3 -(best == 1)] = 1;
}
else
{
betterdirection[ (best == 1)] = 1;
betterdirection[ 3 -(best == 1)] = 3;
}
if(SGUI->GetVulnerability() > 0)
{
bool buffer[4];
for(int i = 0; i < 4 ; i++)buffer[i] = betterdirection[i];
for(int i = 0; i < 4 ; i++)betterdirection[i] = buffer[3 - i];
}
int end = 4;
while(end > 0)
{
if(possibledirection[betterdirection[4 - end] - 1])
{
directionuser = betterdirection[4 - end];
end = 0;
}
else end --;
}
couldown = rand_int(10);
}
}
else couldown --;
}
void IAG::ScriptPink()
{
int px , py , bx , by;
px = GetEngine()->GetListeObject()[0]->GetTransforms()->GetX();
py = GetEngine()->GetListeObject()[0]->GetTransforms()->GetY();
bx = px;
by = py;
bool end = false;
while(end)
{
switch(*pacmandirection)
{
case 1: by ++; break;
case 2: bx ++; break;
case 3: by --; break;
case 4: bx --; break;
}
if(GetEngine()->GetListeObject()[0]->GetRigibody()->CollisionDecor(bx , by))end = true;
}
int difx = bx - GetX();
int dify = by - GetY();
if(couldown <= 0)
{
if(!GetObject()->GetRigibody()->CollisionDecor(GetX() + (direction%2), GetY() + (!(direction%2))) || !GetObject()->GetRigibody()->CollisionDecor(GetX() - (direction%2), GetY() - (!(direction%2))))
{
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;
}
if(SGUI->GetVulnerability() > 0)
{
bool buffer[4];
for(int i = 0; i < 4 ; i++)buffer[i] = betterdirection[i];
for(int i = 0; i < 4 ; i++)betterdirection[i] = buffer[3 - i];
}
int end = 4;
while(end > 0)
{
if(possibledirection[betterdirection[4 - end] - 1])
{
directionuser = betterdirection[4 - end];
end = 0;
}
else end --;
}
couldown = rand_int(10);
}
}
else couldown --;
}