by savvy » Mon Oct 11, 2010 4:22 pm
maybe this...
//slow down
if(xvelocity>0&&xvelocity>0.01)xvelocity-=0.05;
if(xvelocity<0&&xvelocity<-0.01)xvelocity+=0.05;
//setup names etc
d_1=distance(x, y, cpu1.x, cpu1.y);
d_2=distance(x, y, cpu2.x, cpu2.y);
d_3=distance(x, y, cpu3.x, cpu3.y);
d_4=distance(x, y, cpu4.x, cpu4.y);
d_p=distance(x, y, player.x, player.y);
//gravity
yvelocity+=0.1;
//movement towards cpu1
if(d_1<d_2&&d_1<d_3&&d_1<d_4&&d_1<d_p&&definecpu!=1)
{
if(x<cpu1.x+50)xvelocity-=0.1;
if(x>cpu1.x-50)xvelocity+=0.1;
if(xvelocity>5)xvelocity=5;
if(xvelocity<-5)xvelocity=-5;
if(x<cpu1.x+50&&x>cpu1.x-50&&y>cpu1.y-50&&y<cpu1.y+50&&jump==1)
{
if(xvelocity<-1)xvelocity=-3;yvelocity=-4;
if(xvelocity>1)xvelocity=3;yvelocity=-4;
if(xvelocity<1&&xvelocity>-1)yvelocity=-8;
jump=0;
}
if(xvelocity>1||xvelocity<-1)
{
if(cpu1.x<x){ChangeAnimation("Event Actor", "moveL", FORWARD);}
if(cpu1.x>x){ChangeAnimation("Event Actor", "moveR", FORWARD);}
}
else
{
if(cpu1.x<x){ChangeAnimation("Event Actor", "idleL", FORWARD);}
if(cpu1.x>x){ChangeAnimation("Event Actor", "idleR", FORWARD);}
}
}
//movement towards cpu2
if(d_2<d_1&&d_2<d_3&&d_2<d_4&&d_2<d_p&&definecpu!=2)
{
if(x<cpu2.x+50)xvelocity-=0.1;
if(x>cpu2.x-50)xvelocity+=0.1;
if(xvelocity>5)xvelocity=5;
if(xvelocity<-5)xvelocity=-5;
if(x<cpu2.x+50&&x>cpu2.x-50&&y>cpu2.y-50&&y<cpu2.y+50&&jump==1)
{
if(xvelocity<-1)xvelocity=-3;yvelocity=-4;
if(xvelocity>1)xvelocity=3;yvelocity=-4;
if(xvelocity<1&&xvelocity>-1)yvelocity=-8;
jump=0;
}
if(xvelocity>1||xvelocity<-1)
{
if(cpu2.x<x){ChangeAnimation("Event Actor", "moveL", FORWARD);}
if(cpu2.x>x){ChangeAnimation("Event Actor", "moveR", FORWARD);}
}
else
{
if(cpu2.x<x){ChangeAnimation("Event Actor", "idleL", FORWARD);}
if(cpu2.x>x){ChangeAnimation("Event Actor", "idleR", FORWARD);}
}
}
//movement towards cpu3
if(d_3<d_2&&d_3<d_1&&d_3<d_4&&d_3<d_p&&definecpu!=3)
{
if(x<cpu3.x+50)xvelocity-=0.1;
if(x>cpu3.x-50)xvelocity+=0.1;
if(xvelocity>5)xvelocity=5;
if(xvelocity<-5)xvelocity=-5;
if(x<cpu3.x+50&&x>cpu3.x-50&&y>cpu3.y-50&&y<cpu3.y+50&&jump==1)
{
if(xvelocity<-1)xvelocity=-3;yvelocity=-4;
if(xvelocity>1)xvelocity=3;yvelocity=-4;
if(xvelocity<1&&xvelocity>-1)yvelocity=-8;
jump=0;
}
if(xvelocity>1||xvelocity<-1)
{
if(cpu3.x<x){ChangeAnimation("Event Actor", "moveL", FORWARD);}
if(cpu3.x>x){ChangeAnimation("Event Actor", "moveR", FORWARD);}
}
else
{
if(cpu3.x<x){ChangeAnimation("Event Actor", "idleL", FORWARD);}
if(cpu3.x>x){ChangeAnimation("Event Actor", "idleR", FORWARD);}
}
}
//movement towards cpu4
if(d_4<d_2&&d_4<d_3&&d_4<d_1&&d_4<d_p&&definecpu!=4)
{
if(x<cpu4.x+50)xvelocity-=0.1;
if(x>cpu4.x-50)xvelocity+=0.1;
if(xvelocity>5)xvelocity=5;
if(xvelocity<-5)xvelocity=-5;
if(x<cpu4.x+50&&x>cpu4.x-50&&y>cpu4.y-50&&y<cpu4.y+50&&jump==1)
{
if(xvelocity<-1)xvelocity=-3;yvelocity=-4;
if(xvelocity>1)xvelocity=3;yvelocity=-4;
if(xvelocity<1&&xvelocity>-1)yvelocity=-8;
jump=0;
}
if(xvelocity>1||xvelocity<-1)
{
if(cpu4.x<x){ChangeAnimation("Event Actor", "moveL", FORWARD);}
if(cpu4.x>x){ChangeAnimation("Event Actor", "moveR", FORWARD);}
}
else
{
if(cpu4.x<x){ChangeAnimation("Event Actor", "idleL", FORWARD);}
if(cpu4.x>x){ChangeAnimation("Event Actor", "idleR", FORWARD);}
}
}
//movement towards player
if(d_p<d_2&&d_p<d_3&&d_p<d_4&&d_p<d_1&&definecpu!=0)
{
if(x<player.x+50)xvelocity-=0.1;
if(x>player.x-50)xvelocity+=0.1;
if(xvelocity>5)xvelocity=5;
if(xvelocity<-5)xvelocity=-5;
if(x<player.x+50&&x>player.x-50&&y>player.y-50&&y<player.y+50&&jump==1)
{
if(xvelocity<-1)xvelocity=-3;yvelocity=-4;
if(xvelocity>1)xvelocity=3;yvelocity=-4;
if(xvelocity<1&&xvelocity>-1)yvelocity=-8;
jump=0;
}
if(xvelocity>1||xvelocity<-1)
{
if(player.x<x){ChangeAnimation("Event Actor", "moveL", FORWARD);}
if(player.x>x){ChangeAnimation("Event Actor", "moveR", FORWARD);}
}
else
{
if(player.x<x){ChangeAnimation("Event Actor", "idleL", FORWARD);}
if(player.x>x){ChangeAnimation("Event Actor", "idleR", FORWARD);}
}
}
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".