I have a game that's supposed to remove an actor whenever it eats it, and it does, but it also gives an error message and pauses the program. How can I stop this?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class nonPlayerCharacters here. * * @author (your name) * @version (a version number or a date) */ public class nonPlayerCharacters extends insects { int x; int y; boolean food; /** * Act - do whatever the nonPlayerCharacters wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public boolean atWorldEdge() { if (getX() <= 5 || getX() >= getWorld() . getWidth() - 5 || getY() <= 5 || getY() >= getWorld() . getHeight() - 5 ) { return true ; } else { return false ; } } public int movement( int x) { int q = 0 ; while (q< 30 ) { move(x); delay( 1 ); q++; kill (); } return (x); } public int delay ( int z) { Greenfoot.delay(z); return (z); } public void borderTurn () { if (atWorldEdge()) { turnTowards( 500 , 300 ); atWorldEdge(); movement( 1 ); delay( 1 ); } } public int playerDetection( int a) { Actor playerCharacter; playerCharacter = getWorld().getObjects(playerCharacter. class ).get( 0 ); turnTowards(playerCharacter.getX()*a, playerCharacter.getY()*a); return (a); } public void kill () { if (isTouching(playerCharacter. class )&&food) { World world; world = getWorld(); Actor superfood; superfood = this .getOneObjectAtOffset( 0 , 0 , superfood. class ); if (getWorld() != null ){getWorld().removeObject( this );} counter.addScore(); counter.addScore(); } if (isTouching(playerCharacter. class )&&!food) { World world; world = getWorld(); Actor food; food = this .getOneObjectAtOffset( 0 , 0 , food. class ); getWorld().getObjects(food. class ); if (getWorld() != null ){getWorld().removeObject( this );} counter.addScore(); } } public void act() { } } |