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.
 

128 lines
3.9 KiB

#include "Perso.hpp"
void Control ::Start()
{
couldown = 0;
Vie=40;
BarreVie=0;
VieMax=40;
p_epee->Disable();
p_epee->AffectTag("Epee");
}
void Control::Teleport( int x , int y , int level )
{
GetEngine()->GetCurrentLevel()->DrawLevel();
for(int i = 0 ; i < 190 ; i ++)
{
ML_line(0,i,i,0,ML_BLACK);
ML_display_vram();
Sleep(3);
}
GetEngine()->MoveObject(GetObject(),level);
GetEngine()->MoveObject(p_epee,level);
GetEngine()->SetCurrentLevel(level);
GetObject()->GetTransform()->SetXY(x,y);
}
void Control::Update()
{
BarreVie=Vie*40/VieMax;
ML_line (126,40,126,40-BarreVie,ML_BLACK);
ML_rectangle(125,1,127,42,1,ML_BLACK,ML_BLACK);
Object * Buffer = GetObject()->GetObjectCollisionTag("Slime");
if(Buffer != NULL)
{
Vie--;
int difx = GetObject()->GetTransform()->GetX() - Buffer->GetTransform()->GetX();
int dify = GetObject()->GetTransform()->GetY() - Buffer->GetTransform()->GetY();
GetObject()->GetRigidBody()->Move(difx * 2 ,dify * 2);
}
if (input_trigger(K_SHIFT) || couldown > 0)
{
couldown --;
if(couldown < 0) couldown = 10;
switch (Direction_p)
{
case 1:
GetObject()->GetRender()->SetIt(7);
p_epee->GetTransform()->SetXY(GetObject()->GetTransform()->GetX() + 1,GetObject()->GetTransform()->GetY() + 12);
p_epee->GetRender()->SetDirection(0);
break;
case 2:
GetObject()->GetRender()->SetIt(8);
GetObject()->GetRender()->ReverseRender(true);
p_epee->GetTransform()->SetXY(GetObject()->GetTransform()->GetX()+14,GetObject()->GetTransform()->GetY()-2);
p_epee->GetRender()->SetDirection(270);
break;
case 3:
GetObject()->GetRender()->SetIt(6);
p_epee->GetTransform()->SetXY(GetObject()->GetTransform()->GetX() + 6,GetObject()->GetTransform()->GetY() - 12);
p_epee->GetRender()->SetDirection(180);
break;
case 4:
GetObject()->GetRender()->SetIt(8);
GetObject()->GetRender()->ReverseRender(false);
p_epee->GetTransform()->SetXY(GetObject()->GetTransform()->GetX() - 8,GetObject()->GetTransform()->GetY() - 3);
p_epee->GetRender()->SetDirection(90);
break;
}
p_epee->Enable();
}
else
{
p_epee->Disable();
if(input_press(K_RIGHT))
{
GetObject()->GetRigidBody()->Move(1,0);
GetObject()->GetRender()->SetIt(5);
GetObject()->GetRender()->ReverseRender(true);
Direction_p=2;
}
else if(input_press(K_LEFT))
{
GetObject()->GetRigidBody()->Move(-1,0);
GetObject()->GetRender()->SetIt(5);
GetObject()->GetRender()->ReverseRender(false);
Direction_p=4;
}
else if(input_press(K_UP))
{
GetObject()->GetRigidBody()->Move (0,1);
GetObject()->GetRender()->SetIt(3);
Direction_p=1;
}
else if(input_press(K_DOWN))
{
GetObject()->GetRigidBody()->Move (0,-1);
GetObject()->GetRender()->SetIt(1);
Direction_p=3;
}
else
{
switch (Direction_p)
{
case 1:GetObject()->GetRender()->SetIt(2);break;
case 2:GetObject()->GetRender()->SetIt(4);break;
case 3:GetObject()->GetRender()->SetIt(0);break;
case 4:GetObject()->GetRender()->SetIt(4);break;
}
}
}
if (input_press(K_EXIT))GetEngine()->StopGame();
GetEngine()->MiddleScreen(GetObject()->GetTransform()->GetX() + 6 , GetObject()->GetTransform()->GetY() + 6);
}