Hi Im trying to make an object move like a boomerang. If the boomerange is a set distance away from other actor I want it to move back. The thrown boolean is used in the actor so only when "thrown" is false the player can press a button to throw the boomerang. This doesn't work, and the boomerang just appears in front of the actor and doesn't move. Can I have help with this?
public void act(){//this is the code in "throwkirby" that creates the boomerang
if(thrown==false&&Greenfoot.isKeyDown("space")){
thrown=true;
throwobject();
}
}
public void throwobject(){
setImage("throwing.png");
getWorld().addObject(new kirbyobject(), getX()+100,getY());
}
//this is a method in "kirbyobject" which is the boomerang that is supposed to add the boomerang effect
public void moveback(){
boolean distanceFromKirby=false;
if(getX()==throwkirby.xPos+800){//if 800 units away from kirby, return true
distanceFromKirby=true;
}
if (distanceFromKirby=false){//if not thrown
xSpeed++; // travels foward, with increasing speed
setLocation(getX()+xSpeed, getY());
}
else
{ if(distanceFromKirby==true){//if distance from throwkirby 800 ( i know this if statement isnt
//necessary, but i just put it to clarify)
xSpeed = -15; // add travel back speed
setLocation(getX()+xSpeed, getY());
}}
setLocation(getX()+xSpeed, getY());
if(getX() == throwkirby.xPos){//if boomerang at throwkirby Xpos, not thrown
throwkirby.thrown = false;}
}
