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 transition( World last ){ if (!(last instanceof GameWorld)) throw new RuntimeException("Cannot transition from a non-GameWorld to a GameWorld"); this.display = last.display; this.timer = ((GameWorld) last).timer; return this; } public World endOfWorld() { timer.stop(); return this; } World nextWorld = this; //Produces a World that will animate with a clock tick of rate public final boolean animate( int width, int height, int rate ) { class TimerCallBack { TimerCallBack() { } public void callBack() { World old = GameWorld.this.nextWorld; GameWorld.this.nextWorld = GameWorld.this.nextWorld.onTick(); GameWorld.this.display.allowImage(false); old.erase(); GameWorld.this.nextWorld.draw(); GameWorld.this.display.allowImage(true); } } class KeyCallBack { public void callBack(dynamic key) { World old = GameWorld.this.nextWorld; GameWorld.this.nextWorld = GameWorld.this.nextWorld.onKey(key); GameWorld.this.display.allowImage(false); old.erase(); GameWorld.this.nextWorld.draw(); GameWorld.this.display.allowImage(true); } } 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); } } */