I am making a game with a car and that car has to drive on a field and u can control the car.
when you press the left arrow it turns left with turn(-1); and right turn(1);
But my car keeps going to the right horizontaly the picture does change but the direction not untill it reaches a rotation of 30.
anybody can help me how i can let the car drive more precisely?
EDIT: Humvee now is called Tank
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 Actor
{
/**
* 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()
{
// Add your action code here.
move(1);
int x = getX();
int y = getY();
int ww = getWorld().getWidth();
int wh = getWorld().getHeight();
if (x%(ww-1) == 0)
{
setLocation((1-x/(ww-1))*(ww-3)+1, y);
}
if (y%(wh-1) == 0)
{
setLocation(x, (1-y/(wh-1))*(wh-3)+1);
}
if (Greenfoot.isKeyDown("left"))
{
turn(-1);
}
if (Greenfoot.isKeyDown("right"))
{
turn(1);
}
if (Greenfoot.isKeyDown("up"))
{
move(5);
}
//checkSide();
}
public void checkSide()
{
if(atWorldEdge()){
World world;
world = getWorld();
world.removeObject(this);
}
}
public boolean atWorldEdge()
{
if(getX() < 10 || getX() > getWorld().getWidth() - 10)
return true;
if(getY() < 10 || getY() > getWorld().getHeight() - 10)
return true;
else
return false;
}
}

