class Movable : Item { var speed = 8 var movement : Movement = null fun movement() : Movement = movement override fun end() { if (movement != null && movement.toSquare.entrant == this) { movement.toSquare.entrant = null movement = null } super.end() } override fun isAlternate() : boolean = false override fun isMoving() : boolean = movement != null fun move( direction : int ) { moveDelta( Item.getDeltaX( direction ), Item.getDeltaY( direction ), speed ) } fun move( direction : int, speed : int ) { moveDelta( Item.getDeltaX( direction ), Item.getDeltaY( direction ), speed ) } fun moveEast() { moveDelta( 1, 0, speed ) } fun moveNorth() { moveDelta( 0, 1, speed ) } fun moveWest() { moveDelta( -1, 0, speed ) } fun moveSouth() { moveDelta( 0, -1, speed ) } fun moveDelta( dx : int, dy : int ) { moveDelta( dx, dy, speed ) } // Items can optionally have an animation while moving. // If so, the animation acts in parallel with the Movement fun createAnimation( direction : int ) : Action = null fun moveDelta( dx : int , dy : int , speed : int ) { val movement = Movement( this, dx, dy, speed ) val animation = createAnimation( Item.getDirection( dx, dy ) ) if (animation == null) { replaceAction( movement ) } else { replaceAction( animation.whilst( movement ) ) } act() } override fun lookEast() : LookedAt = lookDelta( 1, 0, speed) override fun lookWest() : LookedAt = lookDelta( -1, 0, speed ) override fun lookNorth() : LookedAt = lookDelta( 0, 1, speed ) override fun lookSouth() : LookedAt = lookDelta( 0, -1, speed ) override fun look( direction : int ) : LookedAt = look( direction, speed ) override fun lookDelta( dx : int, dy : int ) : LookedAt = lookDelta( dx, dy, speed ) fun moved( movement : Movement ) { replaceAction( createAction() ) } }