hello guys, ive got a problem with a random flying object. So, there's 2 actors(class) inside my scenario that'll fly. The first object flying from right to left and the second is the opposite. Then when the both of objects reachs the edge they'll turn and flying to the opposites direction.
The problem is, i want to make a shooting game. When the bullet hit the actor, the actor should've been gone and then respawn at a random place. but they're moving upside down continuously at the edge of screen. Can you help me?
this is inside Superclass called fly
this is actor1
and this is actor2
int q = 0;
private int Evil = 0;
/**
* Act - do whatever the Fly wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
}
public void flyy()
{
if(isAtEdge() ||getX()>750)
{
setLocation(getX(), 50+Greenfoot.getRandomNumber(320));
turn(180);
this.getImage().mirrorVertically();
q++;
}
}
public void right()
{
move(3/2);
}
public void left()
{
move(-3/2);
}
public void touch()
{
if(isTouching(Projectile.class))
{
MonkeyWorld MonkeyWorld = (MonkeyWorld) getWorld();
MonkeyWorld.poin = MonkeyWorld.poin + 10;
MonkeyWorld.changeScore(MonkeyWorld.poin);
removeTouching(Evil2.class);
setLocation(0, 50+Greenfoot.getRandomNumber(320));
}
}
public void touch2()
{
if(isTouching(Projectile.class))
{
MonkeyWorld MonkeyWorld = (MonkeyWorld) getWorld();
MonkeyWorld.poin = MonkeyWorld.poin + 10;
MonkeyWorld.changeScore(MonkeyWorld.poin);
removeTouching(Evil1.class);
setLocation(800, 50+Greenfoot.getRandomNumber(320));
}
}public void act()
{
left();
flyy();
touch2();
} public void act()
{
right();
flyy();
touch();
}
