I recently uploaded a scenario called UFO hunt .
The problem is, the tank and the tank's cannon move very strangely with the keys, even though on the computer it was fine.
Tank's movement:
Cannon's movement and turning:
Notice: gspeed is the speed that the gun moves left or right, it is equal to the speed the tank moves (pspeed).
the turn() method activates from the move() method.
the gunAngle thing is so that there is a limit on how much you can turn the cannon.
Thanks!
public int pspeed = 3;
public void act()
{
pmove();
pmakeSmoke();
}
public void pmove()
{
if (Greenfoot.isKeyDown("d"))
{
move(pspeed);
}
if (Greenfoot.isKeyDown("a"))
{
move(-pspeed);
}
} public int gspeed = pspeed;
public int gTurnspeed = 2;
public Gun()
{
setRotation(270);
}
public void act()
{
move();
shoot();
}
public void move()
{
if (Greenfoot.isKeyDown("a"))
{
setLocation(getX()-gspeed,getY());
}
if (Greenfoot.isKeyDown("d"))
{
setLocation(getX()+gspeed,getY());
}
turn();
}
public void turn()
{
int gunAngle = getRotation();
if (gunAngle < 358)
{
if (Greenfoot.isKeyDown("right"))
{
turn(gTurnspeed);
}
}
if (gunAngle > 210)
{
if (Greenfoot.isKeyDown("left"))
{
turn(-gTurnspeed);
}
}
}
