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

2015/3/10

Object interaction

johansj johansj

2015/3/10

#
Hey guys, my Snakes are trying to eat my Wombat, that is intentional, unfortunately they are eating each other too - does anyone know how to stop this? Here is the code for my actor called Snake.... move(5); if (isAtEdge()) {turn(150);} if (Greenfoot.getRandomNumber(100)<10) {turn(15);} Actor wombat; wombat = getOneObjectAtOffset(0, 0, Wombat.class); if (wombat != null) { World world; world = getWorld(); world.removeObject(wombat); Greenfoot.playSound("Dead.wav");
Super_Hippo Super_Hippo

2015/3/10

#
Is "Snake" a subclass of "Wombat"? It should not, but if it is, 'getOneObjectAtOffset(0, 0, Wombat.class);' will also return Snake objects.
johansj johansj

2015/3/17

#
Hi there, yes Snake is a subclass of Wombat. I changed it and now it works, cheers Super Hippo
You need to login to post a reply.