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/iaghost1.cpp

123 lines
3.4 KiB

#include "..\C-Engine\CHeader.hpp"
#include "GUI.hpp"
#include "iaghost1.hpp"
void IA1::Start()
{
couldown=0;
direction=1;
directionuser=1;
}
void IA1::UpdateEverySecond()
{
if (couldown==5)
{
directionuser = rand_int(4) + 1;
couldown=0;
}
couldown++;
}
void IA1::Initialisation(Script_GUI * v)
{
SGUI = v ;
}
void IA1::Update()
{
int hasard;
if(SGUI->GetVulnerability() > 0)SetIt(1);
else SetIt(0);
//Intersection//
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;
}
}
//***********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;
}
}