I wanted to have a Sponge for Game which inflates (changes Images) when hit.
Also I wanted the player to be able to climb up only the inflated sponge.
For the 2. thing i have no idea how to do it...


Actor sponge = getOneIntersectingObject(Sponge.class); if (sponge != null && sponge.getImage().getWidth() >= 50 && Greenfoot.isKeyDown("up")) { climb(); }
import greenfoot.*; public class sponge extends object { public GreenfootImage small, big; public sponge() { small = new GreenfootImage("spongesmol.png"); big = new GreenfootImage("spongeBEEG.png"); } public void act() { if (isTouching(inklingshot.class)) { setImage(big); removeTouching(inklingshot.class); } } }
setImage(small);
sponge hitSponge = (Sponge)getOneIntersectingObject(sponge.class); if (hitSponge != null && hitSponge.getImage() == hitSponge.big) { // climbing code here }