|
|
Greenfoot LabMaking objects Move and Interact
How to tell if you are next to an object
Actor Rock = getOneObjectAtOffset(1, 0, Rock.class);
if(Rock != null)
System.out.println("rock is to the right ");
Actor Rock2 = getOneObjectAtOffset(0, 1, Rock.class);
if(Rock2 != null)
System.out.println("rock is below");
The picture below illustartes how a Class named Car() could find out that there is a Rock() to its right.
|