class Player : Item { var left : Input var right : Input var up : Input var down : Input var mainView : StageView val pos = Vector2() override fun begin() { left = findInput("left") right = findInput("right") up = findInput("up") down = findInput("down") mainView = findStageView( "main" ) super.begin() } override fun isSolid() = false override fun isEmpty() = true override fun createAction() : Action { return this:>checkInputs.action() and flash() } fun checkInputs() : bool { if (left.isPressed()) tryToMove(-1,0) if (right.isPressed()) tryToMove(1,0) if (up.isPressed()) tryToMove(0,1) if (down.isPressed()) tryToMove(0,-1) return false } fun tryToMove( dx : int, dy : int ) { val there = look( dx, dy ) if (there.isSolid()) { if (there is Soil) { if (Play.instance.blasts > 0) { Play.instance.blasts -= 1 there.kill() replaceAction( Delay( 0.25 ) then createAction() ) } else { actor.event( "cantDig" ) } } else if (there is Ship) { if ( Play.instance.canLaunch() ) { actor.die() (there as Ship).launch() } } else if (there is Blasts || there is Fuel) { there.kill() } } else { if (there is Enemy) { kill() } else { there.kill() move( dx, dy ) replaceAction( Delay( 0.1 ) then createAction() ) } } } override fun move( dx : int, dy :int ) { super.move(dx, dy) adjustView() } fun adjustView() : bool { val worldRect = mainView.worldRect() val x = actor.position.x val y = actor.position.y val margin = 90 if ( x - worldRect.left < margin ) { mainView.worldFocal.x -= 36.0 return true } else if ( worldRect.right - x < margin ) { mainView.worldFocal.x += 36.0 return true } if ( y - worldRect.bottom < margin ) { mainView.worldFocal.y -= 36.0 return true } else if ( worldRect.top - y < margin ) { mainView.worldFocal.y += 36.0 return true } return false } }