as of right now my firing is one after another and ive tried alot of different code to fix it and none works
Shooter(gun)
Bullet code
HELP!
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 | public class Shooter extends Actor { public void act() { if (Greenfoot.isKeyDown( "space" ) ) { getWorld().addObject( new bullet(getRotation()), getX(), getY()); } if (Greenfoot.isKeyDown ( "w" )) { move( 3 ); } if (Greenfoot.isKeyDown ( "s" )) { move(- 3 ); } if (Greenfoot.isKeyDown ( "d" )) { turn( 4 ); } if (Greenfoot.isKeyDown ( "a" )) { turn (- 4 ); } } } |
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 | public class bullet extends Shooter { private int direction, speed; public bullet( int dir) { direction = dir; } int time= 10 ; public boolean atWorldEdge() { if (getX() < 10 || getX() > getWorld().getWidth() - 10 ) return true ; if (getY() < 10 || getY() > getWorld().getHeight() - 10 ) return true ; else return false ; } /** * 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() { setRotation(direction); move(speed); destroyEnemies (); move( 17 ); kill(); if ( this .atWorldEdge()) { getWorld().removeObject( this ); } } public bullet() { GreenfootImage image=getImage(); image.scale( 40 , 6 ); setImage(image); } public void destroyEnemies() { //"Enemy" can be any class that you want the bullet to destroy. Actor enemy = getOneIntersectingObject(Enemy. class ); if (enemy != null ) { World myWorld = getWorld(); getWorld().removeObject(enemy); } } public void kill() { //"Enemy" can be any class that you want the bullet to destroy. Actor blueenemy = getOneIntersectingObject(Enemy. class ); if (blueenemy != null ) { getWorld().removeObject(blueenemy); } } } |