I converted the normal polar coordinates used in moving a actor to Cartesian coordinates now the tank will work until it hits a certain angle then the direction will completely change here is my code
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Executer here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Executer extends Animal
{
public Executer()
{
getImage().setTransparency(0);
}
double ex = 280;
double ey = 280;
double rx;
double ry;
public void move(int r) //takes in rotation
{
rx = Math.cos(r);
ry = Math.sin(r);
ex += rx;
ey += ry;
Tank tank = (Tank)getWorld().getObjects(Tank.class).get(0);
tank.setLocation((int) ex, (int) ey);
}
public void back(int r) //takes in rotation
{
rx = Math.cos(r);
ry = Math.sin(r);
ex -= rx;
ey -= ry;
Tank tank = (Tank)getWorld().getObjects(Tank.class).get(0);
tank.setLocation((int) ex, (int) ey);
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Tank here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Tank extends Animal
{
/**
* Act - do whatever the Tank wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
navigate();
}
public void navigate()
{
if (Greenfoot.isKeyDown("w"))
{
Executer execute = (Executer)getWorld().getObjects(Executer.class).get(0);
execute.move(getRotation());
}
//if (Greenfoot.isKeyDown("s"))
//{
// Executer execute = (Executer)getWorld().getObjects(Executer.class).get(0);
// execute.back(getRotation());
//}
if (Greenfoot.isKeyDown("a"))
{
turn(-1);
}
if (Greenfoot.isKeyDown("d"))
{
turn(1);
}
}
}

