class downer extends guy{ PImage imgWalkingLeft[] = new PImage[4] ; PImage imgWalkingRight[] = new PImage[4] ; PImage imgFallLeft ; PImage imgFallRight ; downer(int startx,int starty){ super(startx,starty); imgWalkingLeft[0] = loadImage("l_walker1.png"); imgWalkingLeft[1] = loadImage("l_walker2.png"); imgWalkingLeft[2] = loadImage("l_walker3.png"); imgWalkingLeft[3] = loadImage("l_walker4.png"); imgWalkingRight[0] = loadImage("r_walker1.png"); imgWalkingRight[1] = loadImage("r_walker2.png"); imgWalkingRight[2] = loadImage("r_walker3.png"); imgWalkingRight[3] = loadImage("r_walker4.png"); imgFallLeft = loadImage("l_walkprefall2.png"); imgFallRight = loadImage("walkprefall2.png"); } void calcMove(){ pixelDeltaX = 0.0; pixelDeltaY = 0.0; //anything beneath feet? if(!hasBoxUnder(xSquare,ySquare)){ calcFall(); } else{ pickAndMove(); } } int FRAMESOFHOVER = 4; int FRAMESTOHOLD = 5; int currentFrame = (int)random(FRAMESOFHOVER); int timeTilChange = (int)random(FRAMESTOHOLD); void animate(){ if(dumb){ if(lastDirMoved == 1){ img = imgFallRight; }else { img = imgFallLeft; } return; } if(lastDirMoved == 1){ img = imgWalkingRight[currentFrame]; } else { img = imgWalkingLeft[currentFrame]; } timeTilChange --; if(timeTilChange <= 0){ timeTilChange = FRAMESTOHOLD; currentFrame++; if(currentFrame >= FRAMESOFHOVER){ currentFrame = 0; } } } void checkIfDumb(){ //println("checking for "+destBoxX+" "+destBoxY ); int testy = destBoxY; while(testy < BOXCOUNT && !hasBoxUnder(destBoxX,testy)){ testy++; } if(testy == BOXCOUNT){ dumb =true; } } boolean hasBoxUnder(int x, int y){ int checky = y + 1; if(getWorldContentsSafely(x,checky) == WALL){ return true; } return false; } void calcFall(){ destBoxX = xSquare; destBoxY = ySquare; float currentPixelX, currentPixelY; float destPixelX, destPixelY; while(destBoxY < BOXCOUNT && !hasBoxUnder(destBoxX,destBoxY)){ destBoxY++; } currentPixelX = LEFTOFWORLD+(xSquare*BOXSIZE); currentPixelY = TOPOFWORLD+(ySquare*BOXSIZE); if(destBoxY == BOXCOUNT){ //FALLEN OUT OF BOTTOM screamdown(); isDoomed = true; destPixelX = LEFTOFWORLD+(destBoxX*BOXSIZE); destPixelY = SCREENSIZE; } else { destPixelX = LEFTOFWORLD+(destBoxX*BOXSIZE); destPixelY = TOPOFWORLD+(destBoxY*BOXSIZE); } float fractionPerFrame = (FRAMESPERROUND-TURNSTEP); pixelDeltaX = (destPixelX - currentPixelX) / fractionPerFrame; pixelDeltaY = (destPixelY - currentPixelY)/ fractionPerFrame; } }