does getIntersectingObjects(java.lang.Class cls) return null if there are no objects of that type intersecting it? becuase i have a condition where it is always returning true, not sure if that is because of something else though. here's the code:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.lang.Class;
/**
* The player controled caracter.
*
* @author Michionlion
* @version 3/25/2012
*/
public class Jumper extends GameObject {
int xSpeed;
int ySpeed;
boolean touchingPad;
/**
* Act - do whatever the Jumper wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
getKeysAndMove();
touchingPad = TouchingPad();
}
public void getKeysAndMove() {
if (!touchingPad) {
if (Greenfoot.isKeyDown("a") || Greenfoot.isKeyDown("left")) xSpeed--;
if (Greenfoot.isKeyDown("d") || Greenfoot.isKeyDown("right")) xSpeed++;
if (Greenfoot.isKeyDown("w") || Greenfoot.isKeyDown("up") || Greenfoot.isKeyDown("space")) {
if (touchingPad) {
ySpeed -= 3;
}
}
setLocation(getX() + xSpeed, getY() + ySpeed);
if (ySpeed < 6) ySpeed++;
}
}
public boolean TouchingPad() {
if (getIntersectingObjects(Pad.class) != null) {
System.out.println("pads checked, returned true");
System.out.println(getIntersectingObjects(Pad.class));
return true;
}
else {
System.out.println("pads checked, returned false");
return false;
}
}
}