I have an actor that moves along the x axis while its direction is on an angle is there a way to fix that
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
Here is my Tank and World code
/**
* 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"))
{
move(1);
}
if (Greenfoot.isKeyDown("s"))
{
move(-1);
}
if (Greenfoot.isKeyDown("a"))
{
turn(-1);
}
if (Greenfoot.isKeyDown("d"))
{
turn(1);
}
}
}
import greenfoot.*; // (Actor, World, Greenfoot, GreenfootImage)
public class TankWorld extends World
{
private GreenfootSound sound = new GreenfootSound("Background.wav");
/**
* Create the crab world (the beach). Our world has a size
* of 560x560 cells, where every cell is just 1 pixel.
*/
public TankWorld()
{
super(1000, 560, 1);
setUp();
}
public void act()
{
}
public void setUp()
{
Tank tank = new Tank();
addObject(tank, 280, 280);
TankTurret tankTurret = new TankTurret();
addObject(tankTurret, 280, 280);
Tracker track = new Tracker();
addObject(track, 280, 280);
}
}
