package graphics; import scheme.lib.htdch.graphics.rename; import scheme.lib.mred.mred; public abstract class GameWorld extends World { dynamic timer; public GameWorld() { super(new View()); } public World endOfWorld() { timer.stop(); return this; } World nextWorld = this; void oneStepPrivate(World oldWorld, World newWorld) { ((GameWorld) newWorld).timer = ((GameWorld) oldWorld).timer; newWorld.display = oldWorld.display; display.allowImage(false); oldWorld.erase(); newWorld.draw(); display.allowImage(true); } //Produces a World that will animate with a clock tick of rate public final boolean animate( int width, int height, int rate ) { class TimerCallBack { public void callBack() { World old = GameWorld.this.nextWorld; GameWorld.this.nextWorld = GameWorld.this.nextWorld.onTick(); GameWorld.this.oneStepPrivate(old, GameWorld.this.nextWorld); } } class KeyCallBack { public void callBack(String key) { World old = GameWorld.this.nextWorld; GameWorld.this.nextWorld = GameWorld.this.nextWorld.onKey(key); GameWorld.this.oneStepPrivate(old,GameWorld.this.nextWorld); } } display.display(width, height); dynamic tCB = new TimerCallBack(); display.keyCallBack(rename.innerToFunction(1, new KeyCallBack())); timer = rename.newObject(mred.timerObj, rename.innerToFunction(0,tCB)); timer.start(rate, false); return true; } } /* class TimerCallBack { private World nextWorld; TimerCallBack( World w) { nextWorld = w; } public void callBack() { rename.printer(nextWorld.toString()); nextWorld.erase(); nextWorld = nextWorld.onTick(); rename.printer(nextWorld.toString()); nextWorld.draw(); } void updateNextWorld(World w) { rename.printer("Calling update "+this.toString()); nextWorld = w; } } class KeyCallBack { private World nextWorld; private TimerCallBack t; KeyCallBack( World w, TimerCallBack t) { nextWorld = w; this.t = t; } public void callBack(dynamic key) { rename.printer(key); nextWorld = nextWorld.onKey(key); rename.printer("Should call updateNextWorld next"+nextWorld.toString()); t.updateNextWorld(this.nextWorld); } } */