class Rock : Movable { static val sideSpeed = 20 var falling = false override fun myTurn() { var south = lookSouth() if (south.squashable( SOUTH )) { moveSouth() falling = true } else { if (falling) { falling = false south = lookSouth( IMMEDIATELY ).item() if (south.isPlayer()) { south.item().actor.die() } } // If we CAN roll around the balloon do NOTHING, and let the balloon roll around the rock. val isBalloon = south.item() is Balloon if ( south.rounded( NORTH_WEST ) && canRoll(-1) ) { if (! isBalloon ) { moveDelta(-1, 0, sideSpeed ) } } else if ( south.rounded( NORTH_EAST ) && canRoll(1) ) { if (! isBalloon ) { moveDelta(1, 0, sideSpeed ) } } } } fun canRoll( dx : int ) : boolean { val side = lookDelta( dx, 0, sideSpeed ) if (! ( side.squashable( if (dx == 1) EAST else WEST ) ) ) { return false } val below = square.neighbour( dx, -1 ).look( speed, SOUTH ) return below.squashable( SOUTH ) } override fun canPush( direction : int, speed : int, strength : int ) : boolean { if (strength < 2) return false if (isMoving()) return false if ( direction == SOUTH ) return false val next = look( direction ) if ( next.squashable( direction ) ) { return true } return next.canPush( direction, speed, strength - 4 ) } override fun moved( movement : Movement ) { val south = lookSouth().item() if (movement.dy == -1 && south.isPlayer()) { south.item().kill() } else if (south is Explodes && !south.isMoving()) { (south as Explodes).explode() actor.die() } super.moved( movement ) } override fun rounded( direction : int ) = true override fun copyable() = true }