What must I write that an actor can not go through an other actor? I have no Idee what I must write that an actor can not go through an other actor.
if(!isTouching(Actor.class/*name of actor to not go thru*/)) { //put your movement code here }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) public class Mans extends Actor { /** * Act - do whatever the Mans wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { this.jump(); this.blocade(); } public int ySpeed; public int groundLevel=489; private boolean pressed = false; public void jump() { boolean onGround = (getY() == groundLevel); if (!onGround) { ySpeed++; setLocation(getX(), getY()+ySpeed); if (getY()==groundLevel) { setLocation(getX(), groundLevel); } } else { if (Greenfoot.isKeyDown("up")) { ySpeed = -15; setLocation(getX(), getY()+ySpeed); } } if(this.pressed == Greenfoot.isKeyDown("space")) { this.pressed =! this.pressed; if(this.pressed == true) { this.getWorld().addObject(new Weapons(), this.getX() + 80, this.getY()-25 ); } } } public void blocade() { if(!isTouching(Boxes.class)) { move(0); } } }
public void blocade() { Actor box = getOneIntersectingObject(Boxes.class); if (box != null) { setLocation(getX(), box.getY()+(box.getImage().getHeight()+this.getImage().getHeight())/2+1); ySpeed = 0; }