abstract class guy { PImage img; //the x and y coordinate in the world grid int xSquare,ySquare; int movebehaviour; //deltas are how much we move per frame, based on the calculated move float pixelDeltaX = 0.0, pixelDeltaY = 0.0; //offset is the sum of all the deltas this round, we just add it to the position float pixelOffsetX = 0.0, pixelOffsetY = 0.0; int destBoxX = -1; int destBoxY = -1; int lastDirMoved = 1; boolean isDoomed = false; guy(int startx,int starty){ xSquare = startx; ySquare = starty; if(random(2) < 1.0){ lastDirMoved = 1; } else { lastDirMoved = -1; } } void draw(){ image(img,LEFTOFWORLD+(xSquare*BOXSIZE)+pixelOffsetX,TOPOFWORLD+(ySquare*BOXSIZE)+pixelOffsetY); //line(0,0,destPixelX,destPixelY); } void shiftCW(){ int oldxsquare = xSquare; int oldysquare = ySquare; xSquare = (BOXCOUNT-1)-oldysquare; ySquare = oldxsquare; } void shiftCCW(){ int oldxsquare = xSquare; int oldysquare = ySquare; xSquare = oldysquare; ySquare = (BOXCOUNT-1)-oldxsquare; } abstract void animate(); abstract void calcMove(); void move(){ pixelOffsetX += pixelDeltaX; pixelOffsetY += pixelDeltaY; } void pickAndMove(){ lifepoints++; // println("MOVING"); boolean leftIsOK = true; boolean rightIsOK = true; if(getWorldContentsSafely(xSquare-1,ySquare) != EMPTY){ leftIsOK = false; } if(getWorldContentsSafely(xSquare+1,ySquare) != EMPTY){ rightIsOK = false; } //if we can't move either, return if(! (leftIsOK || rightIsOK)){ return; } if(leftIsOK && (! rightIsOK)){ doPickedMove(-1); return; } if((!leftIsOK) && rightIsOK){ doPickedMove(1); return; } //can go either way lets try to keep it moving the same direction doPickedMove(lastDirMoved); return; } void doPickedMove(int dir){ // println("MOVING TO "+dir); float currentPixelX = LEFTOFWORLD+(xSquare*BOXSIZE); float destPixelX = LEFTOFWORLD+((dir+xSquare)*BOXSIZE); float fractionPerFrame = (FRAMESPERROUND-TURNSTEP); pixelDeltaX = (destPixelX - currentPixelX) / fractionPerFrame; destBoxX = xSquare + dir; destBoxY = ySquare;// + dir; lastDirMoved = dir; checkIfDumb(); } abstract void checkIfDumb(); boolean dumb = false; //so here we have the guy 'know' where it is after the animation... //eventually this should return a boolean true if it's dead boolean registerMoveOrDie(){ /* if(destBoxX != -1){ } else { println("DOHH"); } if(destBoxY != -1){ } */ xSquare = destBoxX; ySquare = destBoxY; destBoxX = xSquare; destBoxY = ySquare; pixelOffsetX = 0.0; pixelOffsetY = 0.0; pixelDeltaX = 0.0; pixelDeltaY = 0.0; return isDoomed; } }