public class WalkingDoll { /** * Which character node position are we at? **/ public CharNode current; /** * Starting position for new walking. **/ public CharNode start; /** * Position for the character **/ public int x, y; public int getX() {return x;} public int getY() {return y;} public void setLoc(int nux, int nuy){x=nux; y=nuy;} /** * FrameSequence for the display **/ FrameSequence frames; /** * We'll do the list setup in the constructor **/ public WalkingDoll(){ FileChooser.setMediaPath("D:/cs1316/mediasources/"); Picture p = null; // For loading up images p = new Picture(FileChooser.getMediaPath("gal1-rightface.jpg")); start = new CharNode(p); p = new Picture(FileChooser.getMediaPath("gal1-right2.jpg")); CharNode rightfoot = new CharNode(p); p = new Picture(FileChooser.getMediaPath("gal1-rightface.jpg")); CharNode center = new CharNode(p); p = new Picture(FileChooser.getMediaPath("gal1-right1.jpg")); CharNode leftfoot = new CharNode(p); start.setNext(rightfoot); rightfoot.setNext(center); center.setNext(leftfoot); // Now the scary one leftfoot.setNext(start); frames = new FrameSequence("D:/Temp/"); } /** * Setup to display walking left to right **/ public void setUp(){ x = 0; // Left side y = 300; // 300 pixels down frames.show(); this.start(); } /** * Start a walking sequence **/ public void start() { current = start; this.draw(); } /** * Draw the current character **/ public void draw() { Picture bg = new Picture(400,400); Turtle pen = new Turtle(bg); pen.setPenDown(false); pen.moveTo(x,y); current.drawWith(pen); frames.addFrame(bg); } /** * Draw the next step **/ public void step(){ current = (CharNode) current.getNext(); x=x+10; // We'll try this this.draw(); } /** * Draw a few steps **/ public void steps(int num){ for (int i=0; i < num; i++) {this.step();}} /** * Delegate replay **/ public void replay(int delay){ frames.replay(delay); } }