I want to have it so the player can move freely and the enemy follows by getting the x position and y position. I know i need to use turnTowards however whenever i try and set the position of the player in the enemy class i get a null pointer
player code
enemy code
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()
{
if(Greenfoot.isKeyDown("up"))
{
move(5);
}
if(Greenfoot.isKeyDown("down"))
{
move(-2);
}
if(Greenfoot.isKeyDown("right"))
{
turn(3);
}
if(Greenfoot.isKeyDown("left"))
{
turn(-3);
}
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class enemy here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class enemy extends Actor
{
private Tank myTank;
/**
* Act - do whatever the enemy wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(2);
turnTowards(myTank.getX(), myTank.getY());
}
}
