Hello,
I'm trying to make an Agario clone. I have the player who follows the mouse. But I am stuck on how to make the food 'scroll' in the screen as the player moves. Can someone please help? Thank you.
My code for Player class:
My code for Food class:
public class Player extends Actor
{
/**
* Act - do whatever the Player wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (Greenfoot.mouseMoved(null)){
MouseInfo e = Greenfoot.getMouseInfo();
if (e != null){
turnTowards(e.getX(), e.getY());
move(3);
}
}
// Add your action code here.
}
}public class Food extends Actor
{
public Food(){
getImage().scale(30, 30);
}
/**
* Act - do whatever the Food 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.
if (Greenfoot.mouseMoved(null)){
MouseInfo e = Greenfoot.getMouseInfo();
if (e != null){
//turnTowards(e.getX(), e.getY());
move(-3);
}
}
}
}