I'm trying to make a simple shooting game. The basic idea is that I have a paddle on the left side of the screen that can shoot when I press space, and there are balloons starting on the right side that move across the screen slowly. The balloons get removed when they touch the bullet, and the bullet does too. What I'm trying to do is make it so that if the bullet does not hit a balloon and touches the edge, it goes away. I've looked all over the place and actually did find something but when I plugged it in, Greenfoot is saying the method does not exist. My code for the bullet is attached. Ask if you need code for other parts.
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 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Bullet here. * * @author (your name) * @version (a version number or a date) */ public class Bullet extends Actor { /** * 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 ); destroy(); } public void destroy() { Actor ballon; ballon = getOneObjectAtOffset( 0 , 0 , Ballon. class ); if (ballon != null ) { World world; world = getWorld(); world.removeObject(ballon); world.removeObject( this ); } //Everything works but this. GreenFoot is saying that "(this.atWorldEdge()))" is not a method if ( this .atWorldEdge()) World world; world = getWorld(); world.removeObject( this ); } } } |