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

2015/10/30

trouble with collisions and movement

pleasehelpme pleasehelpme

2015/10/30

#
so we have this project with the ff instructions: 1.Put one Ambulance object and one Person object into the world. Save the world. 2.If the ambulance touches the person, the ambulance should pick the person up. (the person will move to wherever the ambulance is) 3.While carrying the person, if the user presses the spacebar, the ambulance should drop the person at the point where it is currently located. The person should not be thrown at another location. i don't know how to do 2nd and 3rd pls help asap :(
danpost danpost

2015/10/30

#
To indicate a connection between the person and the ambulance, the person could have an Ambulance field to reference the ambulance. When its value is null, it is not connected and when its value has an object, it is currently "connected" to that ambulance. Now, this, in itself, is not enough information to control all aspects of their relationship. Something else is needed to determine whether the person is boarding or released from the ambulance. The ambulance can be given a reference field for the person it picks up. When it is an object, the person is boarding or has boarded; when it is null, the person has been released. With both fields in place, the person can determine what it is supposed to be doing at all times and the ambulance can determine when it can move.
pleasehelpme pleasehelpme

2015/10/30

#
i don't get the null part ... this is what i have so far..
public class Person extends Actor
{
    
    public void act() 
    {
        if(isTouching(Ambulance.class)){
            Ambulance m = (Ambulance) getOneIntersectingObject(Ambulance.class);
            setLocation(m.getX(),m.getY());
        }
    }    
}
danpost danpost

2015/10/30

#
pleasehelpme wrote...
i don't get the null part ... this is what i have so far.. < Code Omitted >
The code you have shown would be fine if the Person object was never going to be dropped off at some later time. However, more than just whether the person is touching an ambulance or not is needed for what you want (especially for the dropping off -- where the person would still be touching the ambulance after being dropped. From what I can tell from what you have given, the Person objects are just placed into the world and stay in one place until an ambulance arrives at its location (touches it). As such, I would place all codes in the Ambulance class. There would be four different states for an ambulance -- unoccupied, loading, occupied and unloading. You can use one int field to track the current state or two boolean fields, one for occupancy and the other for the transported state of the occupant (the four states would then be (1) no occupancy and transported -- unoccupied (2) no occupancy and not transported -- loading (3) occupancy and not transported -- occupied (4) occupancy and transported -- unloading). A Person reference should still be given to the Ambulance class so the ambulance can move the person easily. In other words, the Person class will not have an act method.
You need to login to post a reply.