Have i said something wrong?


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 | public class Vile extends Enemy { private int vSpeed = 0 ; private int acceleration = 1 ; private int shootingCounter = 10 ; private int spriteHeight = getImage().getHeight(); private int spriteWidth = getImage().getWidth(); private int lookForGroundDistance = ( int )spriteHeight/ 2 ; private int lookForEdge = ( int )spriteWidth/ 2 ; private int speed = 15 ; private int animCount; // counter for animations private int animDelay = 6 ; // initially set for standing animation (frame rate field) private static GreenfootImage[] VileStandAnim = new GreenfootImage[ 1 ]; private static GreenfootImage[] VileStandLeftAnim = new GreenfootImage[ 1 ]; private static GreenfootImage[] rightAnim = new GreenfootImage[ 2 ]; private static GreenfootImage[] leftAnim = new GreenfootImage[ 2 ]; private static GreenfootImage[] shootAnim = new GreenfootImage[ 1 ]; private static GreenfootImage[] shootLeftAnim = new GreenfootImage[ 1 ]; static { for ( int i= 0 ; i<VileStandAnim.length; i++) VileStandAnim[i] = new GreenfootImage( "VileStand_0" +(i+ 1 )+ ".png" ); for ( int i= 0 ; i<VileStandLeftAnim.length; i++) VileStandLeftAnim[i] = new GreenfootImage( "VileStandLeft_0" +(i+ 1 )+ ".png" ); for ( int i= 0 ; i<rightAnim.length; i++) rightAnim[i] = new GreenfootImage( "VileDash_0" +(i+ 1 )+ ".png" ); for ( int i= 0 ; i<leftAnim.length; i++) leftAnim[i] = new GreenfootImage( "VileDashLeft_0" +(i+ 1 )+ ".png" ); for ( int i= 0 ; i<shootAnim.length; i++) shootAnim[i] = new GreenfootImage( "VileShoot_0" +(i+ 1 )+ ".png" ); for ( int i= 0 ; i<shootLeftAnim.length; i++) shootLeftAnim[i] = new GreenfootImage( "VileShootLeft_0" +(i+ 1 )+ ".png" ); } private void setAnim(GreenfootImage[] anim, int frameRate) { animSet = anim; animCount = - 1 ; // prepares to set first image when incremented animDelay = frameRate; animate(); // calls a method to set a frame of this newly set animation } private GreenfootImage[] animSet = VileStandLeftAnim; /** * Act - do whatever the Vile wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { animate(); checkAnim(); move(); } public void move() { Actor ground = getOneObjectAtOffset(lookForEdge, lookForGroundDistance, Collider. class ); if (ground == null ) { speed *= - 1 ; lookForEdge *= - 1 ; } else { move(speed); } } public void checkAnim() { if (speed == 15 && animSet != rightAnim )setAnim(rightAnim, 2 ); else if (speed == - 15 && animSet != leftAnim) setAnim(leftAnim, 2 ); } |