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...
![Twitter](/assets/twitter-4e19209ef84344ee0c433f4c7bad8d49.png)
![Twitter.hover](/assets/twitter.hover-1fb19a5bafc50deace8f88eaec867845.png)
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 }