class CompoundPlayer : Player, Compound { // All of the extra Parts, which are "fake" items, not on a Stage. var parts : Array // For each direction E,N,W,S a list of either this or a Part which make the // leading edge when the compond object moves in the direction. val edges = Array>(4) // The opposite of [edges], i.e. all Parts and this which are NOT leading edges // when the compound object moves in the direction. val followers = Array>(4) @CostumeAttribute var width = 1 @CostumeAttribute var height = 2 override fun parts() : Array = parts override fun edges( direction : int ) = edges[direction] override fun activated() { super.activated() if ( height == 2 ) { actor.scale.y = 2 actor.y += gridSize()/2 } if ( width == 2 ) { // Note. Burton is narrower than 1 square, which makes Hilton // too narrow if using a scale of 2 actor.scale.x = 3 actor.x += gridSize()/2 } parts = Array(width * height - 1) for ( y in 0 until height ) { for ( x in 0 until width) { if ( x != 0 || y != 0 ) { val part = Part(this, x, y) parts[x + y * width - 1] = part part.reoccupy() } } } for ( i in 0..3 ) { edges[i] = listOf() // Feather BUG! Adds this!!! edges[i].clear() followers[i] = listOf() // Feather BUG! Adds this!!! followers[i].clear() } for ( x in 0 until width) { println( "x = $x" ) edges[SOUTH].add( partOrThis( x, 0 ) ) edges[NORTH].add( partOrThis( x, height-1 ) ) } for ( y in 0 until height ) { edges[WEST].add( partOrThis( 0, y ) ) edges[EAST].add( partOrThis( width -1, y ) ) } for ( dir in 0..3 ) { for ( part in parts ) { if ( ! edges[dir].contains( part ) ) { followers[dir].add(part) } } if ( ! edges[dir].contains( this ) ) { followers[dir].add(this) } } println( "all parts : $parts" ) println( "Edges[0] ${edges[0]}" ) println( "Edges[1] ${edges[1]}" ) println( "Edges[2] ${edges[2]}" ) println( "Edges[3] ${edges[3]}" ) } fun partOrThis( dx : int, dy : int ) : Movable { if ( dx == 0 && dy == 0 ) return this return parts[dx + dy * width - 1] } override fun canMove( direction : int ) : boolean { for ( edge in edges[ direction ] ) { if ( !canMove( edge, direction ) ) return false } return true } fun canMove( part : Movable, direction : int ) : boolean { val other = part.look( direction ) return other.squashable( direction ) || other.collectable() || other.canPush( direction, speed, strength ) } override fun makeMove( direction : int ) { for ( edge in edges[ direction ] ) { val next = edge.look( direction ) if (next.canPush( direction, speed, strength ) ) { next.push( direction, speed ) } } move( direction ) } override fun moved( movement : Movement) { super.moved( movement ) for ( part in parts ) { part.reoccupy() } } }