if(Greenfoot.isKeyDown("left"))
{
setLocation(getX()-1,getY());
}
if(Greenfoot.isKeyDown("right"))
{
setLocation(getX()+1,getY());
}
if(isTouching(house.class))
{
getWorld().removeObject(this);
}
this is the code for the car i made it go to the house and than vanish now i want to know how to make the the house move back when the car hits it.
In the if isTouching block, you will need to create a reference (Object variable) for the hit house:
house hse = (house)getOneIntersectingObject(house.class);
Then you can "tell" (call a method in) the house it was hit. The method may need to be supplied a direction to move and should probably set a counter to some nominal positive value to count move steps down from. The act method in house should check for non-zero counter value. If so, move house in set direction and decrease the counter.