Hi guys,
This is my first post here.
Im trying to make a game in greenfoot, the game is about loading trucks with containers picked from a ship with a crane.
The problem is; the truck is moving but i want it to be dissapeared when it reaches the right edge of the World, and when it dissapears i want it to spawn at the same place it was departing.
I have one class with two subclasses
Truck
- beladenTruck (english loadedTruck)
- Truck1
This is the Truck class script:
public class Truck extends Actor
{
/**
* Act - do whatever the Truck wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public beladenTruck beladenTruck;
public void act()
{
if(isTouching(beladenTruck.class))
{
move(1);
}
int x = getX();
if(x == 0){
getWorld().removeObject(this);
}
}
}
This is the subclass beladenTruck(loadedTruck)
public class beladenTruck extends Truck
{
/**
* Act - do whatever the beladenTruck wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private int counter=0;
private int count=0;
public Truck1 Truck1 = new Truck1();
public void act()
{
List objectslookingfor = getWorld().getObjects(ContainerGoederen.class);
List objectslookingfor1 = getWorld().getObjects(ContainerIlliMensen.class);
if (objectslookingfor.size() == 0 && objectslookingfor1.size() == 0) {
move(1);
}
if (isTouching(Truck1.class))
{
if (counter<15){
move(3);
}
}
if (isTouching(beladenTruck.class))
{
if (count<1){
move(3);
}
}
}
}
and the the second subclass Truck1 script:
public class Truck1 extends Truck
{
/**
* Act - do whatever the Truck1 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
List objectslookingfor = getWorld().getObjects(ContainerGoederen.class);
List objectslookingfor1 = getWorld().getObjects(ContainerIlliMensen.class);
if (objectslookingfor.size() == 0 && objectslookingfor1.size() == 0) {
getWorld().removeObjects(getWorld().getObjects(Truck1.class));
}
}
}