Please help me to create an explosion when i shooting an enemy.


1 2 3 4 5 6 7 8 | public void shoot() { if ( "space" .equals(Greenfoot.getKey())) { bullet shot= new bullet(); getWorld().addObject(shot,getX(),getY()); shot.setRotation(getRotation()); } } |
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 | public void act() { move( 5 ); kill(); remove(); } public void kill() { Actor rocket=getOneIntersectingObject(rocket. class ); if (rocket != null ) { World myWorld = getWorld(); getWorld().removeObject(rocket); } } public void remove() { Actor rocket = getOneObjectAtOffset( 0 , 0 , rocket. class ); if (rocket != null ) { World world; World myWorld = getWorld(); getWorld().removeObject( this ); } else { if (getX()== 599 ||getX()== 0 ||getY()== 0 ||getY()== 399 ) { getWorld().removeObject( this ); } } } |
1 | getWorld().addObject( new explosion(), getX(), getY()); |
1 2 3 4 5 6 7 8 | public void shoot() { if ( "space" .equals(Greenfoot.getKey())) { bullet shot= new bullet(); getWorld().addObject(shot,getX(),getY()); shot.setRotation(getRotation()); } } |
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 | { /** * Act - do whatever the bullet wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move( 5 ); remove(); } public void remove() { Actor rocket=getOneIntersectingObject(rocket. class ); if (rocket != null ) { getWorld().addObject( new explosion(), getX(), getY()); getWorld().removeObject( this ); getWorld().removeObject(rocket); } else { if (getX()== 599 ||getX()== 0 ||getY()== 0 ||getY()== 399 ) { getWorld().removeObject( this ); } } } } |