NO he will, because the boxes move to him.
public void blocade() { Actor box = getOneIntersectingObject(Boxes.class); if (box != null) { int yDir = (int)Math.signum(ySpeed); setLocation(getX(), box.getY()-yDir*((box.getImage().getHeight()+this.getImage().getHeight())/2+1)); ySpeed = 0; }
import greenfoot.*; public class Mans extends Actor { public int ySpeed; public int groundLevel=489; private boolean pressed; public void act() { boolean onGround = false; ySpeed++; setLocation(getX(), getY()+ySpeed); // at ground level if (getY() == groundLevel) { setLocation(getX(), groundLevel); onGround = true; } // hitting box Actor box = getOneIntersectingObject(Boxes.class); if (box != null) { int yDir = (int)Math.signum(ySpeed); setLocation(getX(), box.getY()-yDir*((box.getImage().getHeight()+getImage().getHeight())/2+1)); ySpeed = 0; if (yDir > 0) onGround = true; } // jumping if (onGround && Greenfoot.isKeyDown("up")) ySpeed = -15; // firing weapon if (pressed == Greenfoot.isKeyDown("space")) { pressed = !pressed; if (pressed) getWorld().addObject(new Weapons(), getX()+80, getY()-25); } } }
import greenfoot.*; public class Mans extends Actor { public int ySpeed; public int groundLevel=489; private boolean pressed; public void act() { boolean onGround = false; ySpeed++; setLocation(getX(), getY()+ySpeed); // at ground level if (getY() > groundLevel) { setLocation(getX(), groundLevel); onGround = true; } // hitting box Actor box = getOneIntersectingObject(Boxes.class); if (box != null) { int yDir = (int)Math.signum(ySpeed); setLocation(getX(), box.getY()-yDir*((box.getImage().getHeight()+getImage().getHeight())/2+1)); ySpeed = 0; if (yDir > 0) onGround = true; } // jumping if (onGround && Greenfoot.isKeyDown("up")) ySpeed = -15; // firing weapon if (pressed == Greenfoot.isKeyDown("space")) { pressed = !pressed; if (pressed) getWorld().addObject(new Weapons(), getX()+80, getY()-25); } } }
ySpeed = 0;