This site requires JavaScript, please enable it in your browser!
Greenfoot back
Miki
Miki wrote ...

2012/12/22

Image based reaction

Miki Miki

2012/12/22

#
Hiii! Is there any way to create an image based reaction? In my game, I have lobsters and crabs, where clicking a button adds crabs and another button creates lobsters. Lobsters eat the crabs, and grow bigger as they do so. I was wondering if it was possible so that if a lobster meets another lobster, depending on which lobster is bigger, they eat each other? Thanks!
vonmeth vonmeth

2012/12/22

#
You can use the GreenfootImage class to get the width or height of the object. Just compare the two objects image sizes like that.
        Lobster lobster = (Lobster) getOneIntersectingObject(Lobster.class);
        if(lobster != null && lobster.getImage().getWidth() < getImage().getWidth())
            getWorld().removeObject(lobster);
tylers tylers

2012/12/22

#
and to make it bigger use:
getImage().scale(getImage().getWidth()+10, getImage().getHeight()+10 ) 
Miki Miki

2012/12/24

#
Thank you guys so much!!!!! :D
You need to login to post a reply.