I have a game where a crab shoots ants. Managed to get the crab to shoot the ant but the ant only moves upwards. How do I get the ant to move in the direction the crab is facing, as my crab rotates. Here's the code
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Ant here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Ant extends Animal
{
private Crab myCrab;
/**
* Act - do whatever the Ant wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public Ant(Crab myCrab)
{
this.myCrab = myCrab;
}
public void act()
{
int ypos = getY();
if (ypos > 0) {
ypos = ypos - 40;
setLocation(getX(), ypos);
Actor lobster = getOneIntersectingObject(Lobster.class);
if (lobster != null) {
// We've hit an asteroid!
getWorld().removeObject(lobster);
getWorld().removeObject(this);
}
}
else {
// I reached the top of the screen
getWorld().removeObject(this);
}
}
}
