danpost wrote...
Roshan123 wrote...
Finally made!!!!!!
@Danpost please go through this Link and give some feedbacks
Plz try this......int dx = 0; // direction along x-axis
if (Greenfoot.isKeyDown("left")) dx--;
if (Greenfoot.isKeyDown("right")) dx++;int dy = 0; // direction along y-axis
if (Greenfoot.isKeyDown("up")) dy--;
if (Greenfoot.isKeyDown("down")) dy++;if (dx*dy == 0 && dx+dy != 0)
{
// next steps
}int rotation = 90*(dx == 0 ? 2-dy : 1-dx);
setRotation(rotation); move(2); if (isTouching(Actor.class)) move(-2);
int rotation = 90*(dx == 0 ? 2-dy : 1-dx);
public void moveANDturn()
{
int dr = 0;
if (Greenfoot.isKeyDown("left")) dr--;
if (Greenfoot.isKeyDown("right")) dr++;
if (dr != 0)
{
turn(dr*2);
if (isTouching(Actor.class)) turn(-dr*2);
}
int ds = 0;
if (Greenfoot.isKeyDown("up")) ds++;
if (Greenfoot.isKeyDown("down")) ds--;
if (ds != 0)
{
move(ds*3);
if (isTouching(Actor.class)) move(-ds*3);
}
}