I am making a new version of a previous game I made, long story short, I am using two actors instead of one to work as one actor. One actor being the body, responsible for taking damage and movement. The other actor is the arm, responsible for shooting and aiming towards the mouse. The problem I am having is that I cannot find a way to make the arm follow the body, I've tried numerous ways but the arm will either move towards the mouse or just move towards the body. Help?
public class Body extends Actor
{
private int speed = 10;
private int health = 100;
private boolean hurt = true;
private static final GreenfootImage norm = new GreenfootImage("Hum.png");
private static final GreenfootImage high = new GreenfootImage("Hum.png");
private static final GreenfootImage med = new GreenfootImage("Hum.png");
private static final GreenfootImage low = new GreenfootImage("Hum.png");
public Body()
{
setImage(norm);
}
public void addedToWorld(greenfoot.World wrld)
{
move();
}
public void act()
{
move();
Actor a = getOneIntersectingObject(Zombie.class);
Actor b = getOneIntersectingObject(Tanker.class);
Actor c = getOneIntersectingObject(Crawler.class);
if (a != null)
{
hurt(2);
a.move(-30);
hurt = true;
}
if (b != null)
{
hurt(4);
b.move(-20);
hurt = true;
}
if (c != null)
{
hurt(1);
c.move(-40);
hurt = true;
}
if (health <= 95)
{
setImage(high);
}
if (health <= 65)
{
setImage(med);
}
if (health <= 20)
{
setImage(low);
}
if (health <= 0)
((zworld)getWorld()).gameOver();
}
public void move()
{
if(Greenfoot.isKeyDown("d"))
move(3);
turn(90);
if(Greenfoot.isKeyDown("s"))
move(3);
turn(90);
if(Greenfoot.isKeyDown("a"))
move(3);
turn(90);
if(Greenfoot.isKeyDown("w"))
move(3);
turn(90);
}
public void move(int dist)
{
int x = getX();
int y = getY();
super.move(dist);
if (getX() > getWorld().getWidth() || getX() < 0)
setLocation(x, getY());
if (getY() > getWorld().getHeight() || getY() < 200)
setLocation(getX(), y);
}
public void hurt(int amount)
{
health -= amount;
int size = Greenfoot.getRandomNumber(5)+1;
for (int i = 0; i < size; i++)
{
int rot = Greenfoot.getRandomNumber(360);
int spd = 2;
}
}
}
public class Arm extends Actor
{
private int counter = 5;
public Arm()
{
setImage("Arm.png");
}
public void act()
{
shoot();
if (Greenfoot.getMouseInfo() == null)
return;
int x = Greenfoot.getMouseInfo().getX();
int y = Greenfoot.getMouseInfo().getY();
turnTowards(x, y);
}
private void shoot()
{
if (counter < 40)
counter++;
if (counter < 10)
return;
if (Greenfoot.isKeyDown("space"))
{
shootAssault();
Greenfoot.playSound("bullet.wav");
}
if (counter < 40)
return;
}
public void shootAssault()
{
counter = 0;
Bullet b = new Bullet(false,20);
getWorld().addObject(b,getX(),getY());
b.setRotation(getRotation());
b.move(10);
b.turn(90);
b.move(2);
b.turn(-90);
b.turn(Greenfoot.getRandomNumber(3)-1);
}
}


