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...


1 2 3 4 5 6 7 | Actor sponge = getOneIntersectingObject(Sponge. class ); if (sponge != null && sponge.getImage().getWidth() >= 50 && Greenfoot.isKeyDown( "up" )) { climb(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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 ); } } } |
1 | setImage(small); |
1 2 3 4 5 | sponge hitSponge = (Sponge)getOneIntersectingObject(sponge. class ); if (hitSponge != null && hitSponge.getImage() == hitSponge.big) { // climbing code here } |