This site requires JavaScript, please enable it in your browser!
Greenfoot back
roidrage
roidrage wrote ...

2014/1/21

Stuck! Move object problems , help!

roidrage roidrage

2014/1/21

#
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)); } } }
danpost danpost

2014/1/21

#
You are moving the truck to the right, but checking for the left edge of the world.
roidrage roidrage

2014/1/21

#
danpost wrote...
You are moving the truck to the right, but checking for the left edge of the world.
hey, tnx for the reply, but where is the left edge in the script? cant find it, also made this script with a friend of mine
danpost danpost

2014/1/22

#
IIn the act method of the Truck class, you have this:
 int x = getX();
if (x == 0){
    getWorld().removeObject(this);
}
'x' (or 'getX()') is zero when the Truck object is at the left edge of the world.
You need to login to post a reply.