I want to shoot bubbles out of my Bubblegun, but i don't know how I need to program that


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 | import greenfoot.*; public class BubbleGun extends Actor { protected GreenfootImage bubbleImage = new GreenfootImage( "bubble.png" ); private boolean spaceDown = false ; public void act() { // shooting if (spaceDown != Greenfoot.isKeyDown( "space" )) { spaceDown = !spaceDown; if (spaceDown) { Bubble bubble = new Bubble(); getWorld().addObject(bubble, getX()+ 0 , getY()+ 0 ); // adjust offsets ass needed } } /** other gun actions here */ } private class Bubble extends Actor { protected void addedToWorld(World world) { setRotation(BubbleGun. this .getRotation()); setImage(bubbleImage); } public void act() { move( 5 ); } } } |