Hi there,
I have a small problem with a box in my game.
I'm trying to push and drag a box.
Well pushing the box wasn't very difficult, I wrote it like that.
But with getOneIntersectingObject I wasn't properly able to drag the box to the left/right.
I tried it with getObjectsInRange but it didn't work either.
Any suggestions?
// box class
public int speed = 3;
public void act(){
moveRight();
}
public void moveRight(){
if (getOneIntersectingObject(Boy.class) != null && Boy.facingRight == true){
setLocation(getX() +speed, getY());
}
else if (getOneIntersectingObject(Boy.class != null && Boy.facingRight == false){
setLocation(getX() -speed, getY());
}
}// player class
public static facingRight = true;
private Box boxmoving;
public player(Box moving){
boxmoving = moving;
}
public void act(){
checkKeys();
}
public void checkKeys(){
if (Greenfoot.siKeyDown("control") && Greenfoot.isKeyDown("right") && getOneIntersectingObject(Box.class) != null && facingRight == true){
dx = boxmoving.speed;
pushBoxRight(); // referes to the animation methode
}
else if (Greenfoot.isKeyDown("control") && Greenfoot.isKeyDown("left") && getOneIntersectingObject(Box.class) != null && facingRight == false){
dx = -boxmoving.speed;
pushBoxLeft(); // referes to the animation methode
}
}
