From 9f611094ee95d937654290704edab7aea2c7950c Mon Sep 17 00:00:00 2001 From: Ferdinand Saurenbach Date: Tue, 15 Apr 2025 21:39:14 +0200 Subject: [PATCH 1/6] fix bigL block --- src/commonMain/kotlin/Block.kt | 16 +++++++++------- src/commonMain/kotlin/main.kt | 10 ++-------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/commonMain/kotlin/Block.kt b/src/commonMain/kotlin/Block.kt index 74a3773..f8a2db2 100644 --- a/src/commonMain/kotlin/Block.kt +++ b/src/commonMain/kotlin/Block.kt @@ -189,7 +189,7 @@ class Block(private var color: RGBA, blockType: BlockType, startPosition: StartP } private fun twoByTwo(container: Container) { - val one = container.roundRect(Size(cs, cs), RectCorners(5f), fill = Colors.RED) + val one = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color) master = one container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignLeftToRightOf(one) val three = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignTopToBottomOf(one) @@ -199,8 +199,9 @@ class Block(private var color: RGBA, blockType: BlockType, startPosition: StartP private fun bigL(container: Container) { - val rotation = random.get(range = 0..3) + var rotation = random.get(range = 0..3) println("Rotation: $rotation") + rotation = 1 container.size = Size(cs * 3, cs * 3) @@ -219,10 +220,12 @@ class Block(private var color: RGBA, blockType: BlockType, startPosition: StartP // 90°: horizontal line + upward tail val one = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color) val two = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignLeftToRightOf(one) - container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignLeftToRightOf(two) - val four = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignTopToBottomOf(two) - container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignTopToBottomOf(four) - master = two + val three = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignLeftToRightOf(two) + val four = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignBottomToTopOf(three) + .alignLeftToLeftOf(three) + container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignBottomToTopOf(four) + .alignLeftToLeftOf(four) + master = one } 2 -> { @@ -243,7 +246,6 @@ class Block(private var color: RGBA, blockType: BlockType, startPosition: StartP val four = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignBottomToTopOf(two) val five = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignBottomToTopOf(four) master = one - master.color = Colors.CHOCOLATE } diff --git a/src/commonMain/kotlin/main.kt b/src/commonMain/kotlin/main.kt index aa881d9..72953e7 100644 --- a/src/commonMain/kotlin/main.kt +++ b/src/commonMain/kotlin/main.kt @@ -30,9 +30,6 @@ val allBlocks = mutableListOf() var placedBlocks = mutableListOf() val random: Random = SecureRandom var first: Field? = null -var leftStart:RoundRect by Delegates.notNull() -val middleStart:RoundRect by Delegates.notNull() -val rightStart: RoundRect by Delegates.notNull() suspend fun main() = Korge( //windowHeight = windowHeight, windowSize = Size(windowWidth, windowHeight), @@ -64,9 +61,6 @@ suspend fun main() = Korge( //backgroundField!!.y -= 70 populateField(this) - leftStart = roundRect(Size(cs*1.5, cs*1.5), RectCorners(5f), Colors.PURPLE) - .position(windowWidth*0.2, windowHeight*0.8) - //val testBlock = block(BlockColors.Red, BlockType.TWObyTWO, StartPosition.LEFT) createPieces(this) @@ -164,7 +158,7 @@ fun checkForBlast() { counter++ } } - println("Row: $rowY, counter: $counter") + //println("Row: $rowY, counter: $counter") if (counter == 8) { for (block in checkedBlocks) { val occupiedField = fields.find { it.pos == block.pos } @@ -188,7 +182,7 @@ fun checkForBlast() { counter++ } } - println("Row: $columnX, counter: $counter") + //println("Row: $columnX, counter: $counter") if (counter == 8) { for (block in checkedBlocks) { val occupiedField = fields.find { it.pos == block.pos } From cd910c8a9527215f9669322449f399043b3cdfaa Mon Sep 17 00:00:00 2001 From: Ferdinand Saurenbach Date: Tue, 15 Apr 2025 21:40:48 +0200 Subject: [PATCH 2/6] fix hardcoded rotation --- src/commonMain/kotlin/Block.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/commonMain/kotlin/Block.kt b/src/commonMain/kotlin/Block.kt index f8a2db2..80511d8 100644 --- a/src/commonMain/kotlin/Block.kt +++ b/src/commonMain/kotlin/Block.kt @@ -199,9 +199,8 @@ class Block(private var color: RGBA, blockType: BlockType, startPosition: StartP private fun bigL(container: Container) { - var rotation = random.get(range = 0..3) + val rotation = random.get(range = 0..3) println("Rotation: $rotation") - rotation = 1 container.size = Size(cs * 3, cs * 3) @@ -242,15 +241,14 @@ class Block(private var color: RGBA, blockType: BlockType, startPosition: StartP // 270°: horizontal line + downward tail val one = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color) val two = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignLeftToRightOf(one) - val three = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignLeftToRightOf(two) + container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignLeftToRightOf(two) val four = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignBottomToTopOf(two) - val five = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignBottomToTopOf(four) + container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignBottomToTopOf(four) master = one } } - //master!!.color = Colors.RED } From fca1d829a9fa5af84a19ad628944f2cded093b48 Mon Sep 17 00:00:00 2001 From: Ferdinand Saurenbach Date: Tue, 15 Apr 2025 22:22:32 +0200 Subject: [PATCH 3/6] prototype --- src/commonMain/kotlin/Block.kt | 114 ++++++++++++++++++++++----------- 1 file changed, 75 insertions(+), 39 deletions(-) diff --git a/src/commonMain/kotlin/Block.kt b/src/commonMain/kotlin/Block.kt index 80511d8..e66b646 100644 --- a/src/commonMain/kotlin/Block.kt +++ b/src/commonMain/kotlin/Block.kt @@ -3,64 +3,59 @@ import korlibs.korge.input.* import korlibs.korge.view.* import korlibs.korge.view.align.* import korlibs.math.geom.* -import korlibs.math.random.* +import korlibs.math.random.get +import kotlin.collections.count +import kotlin.collections.listOf import kotlin.collections.random +import kotlin.collections.toList import kotlin.math.* import kotlin.properties.* - +var cell11:RoundRect by Delegates.notNull() +var cell12 :RoundRect by Delegates.notNull() +var cell13 :RoundRect by Delegates.notNull() +var cell21 :RoundRect by Delegates.notNull() +var cell22 :RoundRect by Delegates.notNull() +var cell23:RoundRect by Delegates.notNull() +var cell31:RoundRect by Delegates.notNull() +var cell32:RoundRect by Delegates.notNull() +var cell33:RoundRect by Delegates.notNull() +//var template: Container by Delegates.notNull() +//var template:MutableList by Delegates.notNull() enum class BlockType { // Single block ONE_BY_ONE, // Straight blocks (all rotations are the same) - ONE_BY_TWO, - TWO_BY_ONE, - ONE_BY_THREE, - THREE_BY_ONE, - ONE_BY_FOUR, - FOUR_BY_ONE, - ONE_BY_FIVE, - FIVE_BY_ONE, + ONE_BY_TWO, TWO_BY_ONE, ONE_BY_THREE, THREE_BY_ONE, ONE_BY_FOUR, FOUR_BY_ONE, ONE_BY_FIVE, FIVE_BY_ONE, // Square blocks (all rotations are the same) - TWO_BY_TWO, - THREE_BY_THREE, + TWO_BY_TWO, THREE_BY_THREE, // L-Shaped blocks (all rotations) - L_2X2_0, - L_2X2_90, - L_2X2_180, - L_2X2_270, + L_2X2_0, L_2X2_90, L_2X2_180, L_2X2_270, - L_2X3_0, - L_2X3_90, - L_2X3_180, - L_2X3_270, + L_2X3_0, L_2X3_90, L_2X3_180, L_2X3_270, - L_3X3_0, - L_3X3_90, - L_3X3_180, - L_3X3_270, + L_3X3_0, L_3X3_90, L_3X3_180, L_3X3_270, // T-Shaped blocks (all rotations) - T_2X3_0, - T_2X3_90, - T_2X3_180, - T_2X3_270, + T_2X3_0, T_2X3_90, T_2X3_180, T_2X3_270, // Rectangle blocks (all rotations) - TWO_BY_THREE_0, - TWO_BY_THREE_90, - THREE_BY_TWO_0, - THREE_BY_TWO_90, + TWO_BY_THREE_0, TWO_BY_THREE_90, THREE_BY_TWO_0, THREE_BY_TWO_90, // S-Shaped blocks (all rotations) - S_2X3_0, - S_2X3_90, - S_2X3_180, - S_2X3_270 + S_2X3_0, S_2X3_90, S_2X3_180, S_2X3_270 } +val L_3X3_0 = arrayOf( + arrayOf(1, 0, 0), arrayOf(1, 0, 0), arrayOf(1, 1, 1) +) + +val L_3X3_90 = arrayOf( + arrayOf(1, 1, 1), arrayOf(0, 0, 1), arrayOf(0, 0, 1) +) + enum class StartPosition { LEFT, MIDDLE, RIGHT @@ -96,6 +91,22 @@ class Block(private var color: RGBA, blockType: BlockType, startPosition: StartP init { + val templateColor = Colors.PURPLE + cell11 = roundRect(Size(cs, cs), RectCorners(5f), fill = templateColor) + + cell12 = roundRect(Size(cs, cs), RectCorners(5f), fill = templateColor).alignLeftToRightOf(cell11) + cell13 = roundRect(Size(cs, cs), RectCorners(5f), fill = templateColor).alignLeftToRightOf(cell12) + cell21 = roundRect(Size(cs, cs), RectCorners(5f), fill = templateColor).alignTopToBottomOf(cell11) + cell22 = roundRect(Size(cs, cs), RectCorners(5f), fill = templateColor).alignLeftToRightOf(cell21) + .alignTopToBottomOf(cell12) + cell23 = roundRect(Size(cs, cs), RectCorners(5f), fill = templateColor).alignLeftToRightOf(cell22) + .alignTopToBottomOf(cell13) + cell31 = roundRect(Size(cs, cs), RectCorners(5f), fill = templateColor).alignTopToBottomOf(cell21) + cell32 = roundRect(Size(cs, cs), RectCorners(5f), fill = templateColor).alignLeftToRightOf(cell31) + .alignTopToBottomOf(cell22) + cell33 = roundRect(Size(cs, cs), RectCorners(5f), fill = templateColor).alignLeftToRightOf(cell32) + .alignTopToBottomOf(cell23) + when (startPosition) { StartPosition.LEFT -> this.position(windowWidth * 0.2, windowHeight * 0.8) StartPosition.MIDDLE -> this.position(windowWidth * 0.4, windowHeight * 0.8) @@ -105,13 +116,12 @@ class Block(private var color: RGBA, blockType: BlockType, startPosition: StartP BlockType.ONE_BY_ONE -> oneByOne(this) BlockType.TWO_BY_TWO -> twoByTwo(this) BlockType.L_3X3_0 -> bigL(this) - else -> bigL(this) + else -> arrayTest(this, L_3X3_0) } this.scale(0.5) var closeable: DraggableCloseable? = null closeable = this.draggableCloseable { it -> - //println("viewNextX: ${round(master!!.getPositionRelativeTo(first!!).x).toInt()}, viewNextY: ${round(master!!.getPositionRelativeTo(first!!).y).toInt()}") if (it.start) { println("master: $master") @@ -197,7 +207,6 @@ class Block(private var color: RGBA, blockType: BlockType, startPosition: StartP .alignTopToBottomOf(one) } - private fun bigL(container: Container) { val rotation = random.get(range = 0..3) println("Rotation: $rotation") @@ -251,7 +260,34 @@ class Block(private var color: RGBA, blockType: BlockType, startPosition: StartP } } + private fun arrayTest(container: Container, array: Array>) { + + if (array[0][0] == 1){ + container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell11) + } + if (L_3X3_0[0][1] == 1){ + container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell12) + } + if (L_3X3_0[0][2] == 1){ + container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell13) + } + if (L_3X3_0[1][0] == 1){ + container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell21) + } + if (L_3X3_0[1][1] == 1){ + container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell22) + } + if (L_3X3_0[1][2] == 1){ + container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell23) + } + + //template().removeFromParent() + println("Array test") + println(L_3X3_0[0][0]) + println(L_3X3_0[0][1]) + println(L_3X3_0[1][0]) + } } fun checkIfCorrectlyPlaced(wholeBlock: Block): Boolean { From 04d0352be8b3f6c92e1851e7239c714ce8d7b67f Mon Sep 17 00:00:00 2001 From: Ferdinand Saurenbach Date: Tue, 15 Apr 2025 22:24:38 +0200 Subject: [PATCH 4/6] prototype update --- src/commonMain/kotlin/Block.kt | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/commonMain/kotlin/Block.kt b/src/commonMain/kotlin/Block.kt index e66b646..20131dd 100644 --- a/src/commonMain/kotlin/Block.kt +++ b/src/commonMain/kotlin/Block.kt @@ -265,28 +265,33 @@ class Block(private var color: RGBA, blockType: BlockType, startPosition: StartP if (array[0][0] == 1){ container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell11) } - if (L_3X3_0[0][1] == 1){ + if (array[0][1] == 1){ container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell12) } - if (L_3X3_0[0][2] == 1){ + if (array[0][2] == 1){ container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell13) } - if (L_3X3_0[1][0] == 1){ + if (array[1][0] == 1){ container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell21) } - if (L_3X3_0[1][1] == 1){ + if (array[1][1] == 1){ container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell22) } - if (L_3X3_0[1][2] == 1){ + if (array[1][2] == 1){ container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell23) } + if (array[2][0] == 1){ + container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell31) + } + if (array[2][1] == 1){ + container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell32) + } + if (array[2][2] == 1){ + container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell33) + } - //template().removeFromParent() - println("Array test") - println(L_3X3_0[0][0]) - println(L_3X3_0[0][1]) - println(L_3X3_0[1][0]) + //template().removeFromParent() } } From 8c595d7175db02e00ffda6261eecb534d5a96fb3 Mon Sep 17 00:00:00 2001 From: Ferdinand Saurenbach Date: Tue, 15 Apr 2025 22:32:36 +0200 Subject: [PATCH 5/6] ich mach morgen weiter --- src/commonMain/kotlin/Block.kt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/Block.kt b/src/commonMain/kotlin/Block.kt index 20131dd..53d8e13 100644 --- a/src/commonMain/kotlin/Block.kt +++ b/src/commonMain/kotlin/Block.kt @@ -92,6 +92,7 @@ class Block(private var color: RGBA, blockType: BlockType, startPosition: StartP init { val templateColor = Colors.PURPLE + cell11 = roundRect(Size(cs, cs), RectCorners(5f), fill = templateColor) cell12 = roundRect(Size(cs, cs), RectCorners(5f), fill = templateColor).alignLeftToRightOf(cell11) @@ -289,9 +290,20 @@ class Block(private var color: RGBA, blockType: BlockType, startPosition: StartP if (array[2][2] == 1){ container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell33) } + master = container.getChildAt(0)as RoundRect + cell11.removeFromParent() + cell12.removeFromParent() + cell13.removeFromParent() + cell21.removeFromParent() + cell22.removeFromParent() + cell23.removeFromParent() + cell31.removeFromParent() + cell32.removeFromParent() + cell33.removeFromParent() + + - //template().removeFromParent() } } From b1cf785d6ea7fe3693227c7261f6fee837dc2aaf Mon Sep 17 00:00:00 2001 From: Ferdinand Saurenbach Date: Wed, 16 Apr 2025 09:24:48 +0200 Subject: [PATCH 6/6] huge update (all blocks implemented and everything works!) --- src/commonMain/kotlin/Block.kt | 143 ++++++------------------- src/commonMain/kotlin/allblocks.kt | 166 +++++++++++++++++++++++++++++ src/commonMain/kotlin/main.kt | 3 +- 3 files changed, 199 insertions(+), 113 deletions(-) create mode 100644 src/commonMain/kotlin/allblocks.kt diff --git a/src/commonMain/kotlin/Block.kt b/src/commonMain/kotlin/Block.kt index 53d8e13..b564e25 100644 --- a/src/commonMain/kotlin/Block.kt +++ b/src/commonMain/kotlin/Block.kt @@ -3,22 +3,19 @@ import korlibs.korge.input.* import korlibs.korge.view.* import korlibs.korge.view.align.* import korlibs.math.geom.* -import korlibs.math.random.get -import kotlin.collections.count -import kotlin.collections.listOf -import kotlin.collections.random -import kotlin.collections.toList import kotlin.math.* import kotlin.properties.* -var cell11:RoundRect by Delegates.notNull() -var cell12 :RoundRect by Delegates.notNull() -var cell13 :RoundRect by Delegates.notNull() -var cell21 :RoundRect by Delegates.notNull() -var cell22 :RoundRect by Delegates.notNull() -var cell23:RoundRect by Delegates.notNull() -var cell31:RoundRect by Delegates.notNull() -var cell32:RoundRect by Delegates.notNull() -var cell33:RoundRect by Delegates.notNull() + +var cell11: RoundRect by Delegates.notNull() +var cell12: RoundRect by Delegates.notNull() +var cell13: RoundRect by Delegates.notNull() +var cell21: RoundRect by Delegates.notNull() +var cell22: RoundRect by Delegates.notNull() +var cell23: RoundRect by Delegates.notNull() +var cell31: RoundRect by Delegates.notNull() +var cell32: RoundRect by Delegates.notNull() +var cell33: RoundRect by Delegates.notNull() + //var template: Container by Delegates.notNull() //var template:MutableList by Delegates.notNull() enum class BlockType { @@ -48,14 +45,6 @@ enum class BlockType { S_2X3_0, S_2X3_90, S_2X3_180, S_2X3_270 } -val L_3X3_0 = arrayOf( - arrayOf(1, 0, 0), arrayOf(1, 0, 0), arrayOf(1, 1, 1) -) - -val L_3X3_90 = arrayOf( - arrayOf(1, 1, 1), arrayOf(0, 0, 1), arrayOf(0, 0, 1) -) - enum class StartPosition { LEFT, MIDDLE, RIGHT @@ -82,10 +71,10 @@ object BlockColors { } } -fun Container.block(color: RGBA, blockType: BlockType, startPosition: StartPosition) = +fun Container.block(color: RGBA, blockType: Array>, startPosition: StartPosition) = Block(color, blockType, startPosition).addTo(this) -class Block(private var color: RGBA, blockType: BlockType, startPosition: StartPosition) : Container() { +class Block(private var color: RGBA, blockType: Array>, startPosition: StartPosition) : Container() { private var placed: Boolean = false private var master: RoundRect by Delegates.notNull() @@ -113,12 +102,8 @@ class Block(private var color: RGBA, blockType: BlockType, startPosition: StartP StartPosition.MIDDLE -> this.position(windowWidth * 0.4, windowHeight * 0.8) StartPosition.RIGHT -> this.position(windowWidth * 0.6, windowHeight * 0.8) } - when (blockType) { - BlockType.ONE_BY_ONE -> oneByOne(this) - BlockType.TWO_BY_TWO -> twoByTwo(this) - BlockType.L_3X3_0 -> bigL(this) - else -> arrayTest(this, L_3X3_0) - } + + arrayTest(this, blockType) this.scale(0.5) var closeable: DraggableCloseable? = null @@ -134,10 +119,10 @@ class Block(private var color: RGBA, blockType: BlockType, startPosition: StartP if (it.end) { this.zIndex(0) println("dragging ended: snapping!") - println("viewNextX: ${master.globalPos.x}, viewNextY: ${master.globalPos.y}") + println("viewNextX: ${this[0].globalPos.x}, viewNextY: ${this[0].globalPos.y}") val blockPosition1 = Point( - convertToCoordinateX(round(master.globalPos.x).toInt()), convertToCoordinateY( - round(master.globalPos.y).toInt() + convertToCoordinateX(round(this[0].globalPos.x).toInt()), convertToCoordinateY( + round(this[0].globalPos.y).toInt() ) ) for (field in fields) { @@ -152,7 +137,7 @@ class Block(private var color: RGBA, blockType: BlockType, startPosition: StartP if (blockPosition1 == fieldPosition && checkIfCorrectlyPlaced(this)) { println("Placed correctly snapping:") - master.globalPos = field.globalPos + this[0].globalPos = field.globalPos println("this global: ${this.globalPos}") this.forEachChild { sContainer.placedBlock( @@ -194,103 +179,39 @@ class Block(private var color: RGBA, blockType: BlockType, startPosition: StartP } } - private fun oneByOne(container: Container) { - val one = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color) - master = one - } - - private fun twoByTwo(container: Container) { - val one = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color) - master = one - container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignLeftToRightOf(one) - val three = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignTopToBottomOf(one) - container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignLeftToRightOf(three) - .alignTopToBottomOf(one) - } - - private fun bigL(container: Container) { - val rotation = random.get(range = 0..3) - println("Rotation: $rotation") - container.size = Size(cs * 3, cs * 3) - - - when (rotation) { - 0 -> { - // Original: vertical line + rightward tail - val one = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color) - val two = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignTopToBottomOf(one) - val three = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignTopToBottomOf(two) - val four = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignLeftToRightOf(three) - container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignLeftToRightOf(four) - master = three - } - - 1 -> { - // 90°: horizontal line + upward tail - val one = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color) - val two = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignLeftToRightOf(one) - val three = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignLeftToRightOf(two) - val four = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignBottomToTopOf(three) - .alignLeftToLeftOf(three) - container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignBottomToTopOf(four) - .alignLeftToLeftOf(four) - master = one - } - - 2 -> { - // 180°: vertical line + leftward tail - val one = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color) - val two = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignTopToBottomOf(one) - val three = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignTopToBottomOf(two) - val four = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignRightToLeftOf(one) - container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignRightToLeftOf(four) - master = three - } - - 3 -> { - // 270°: horizontal line + downward tail - val one = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color) - val two = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignLeftToRightOf(one) - container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignLeftToRightOf(two) - val four = container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignBottomToTopOf(two) - container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).alignBottomToTopOf(four) - master = one - } - - - } - } private fun arrayTest(container: Container, array: Array>) { - if (array[0][0] == 1){ + if (array[0][0] == 1) { container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell11) } - if (array[0][1] == 1){ + if (array[0][1] == 1) { container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell12) } - if (array[0][2] == 1){ + if (array[0][2] == 1) { container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell13) } - if (array[1][0] == 1){ + if (array[1][0] == 1) { container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell21) } - if (array[1][1] == 1){ + if (array[1][1] == 1) { container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell22) } - if (array[1][2] == 1){ + if (array[1][2] == 1) { container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell23) } - if (array[2][0] == 1){ + if (array[2][0] == 1) { container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell31) } - if (array[2][1] == 1){ + if (array[2][1] == 1) { container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell32) } - if (array[2][2] == 1){ + if (array[2][2] == 1) { container.roundRect(Size(cs, cs), RectCorners(5f), fill = color).centerOn(cell33) } - master = container.getChildAt(0)as RoundRect + println("c: ${container[0].globalPos}") + if (container[0] is RoundRect) master = container[0] as RoundRect + println(container[9]) cell11.removeFromParent() cell12.removeFromParent() cell13.removeFromParent() @@ -302,8 +223,6 @@ class Block(private var color: RGBA, blockType: BlockType, startPosition: StartP cell33.removeFromParent() - - } } diff --git a/src/commonMain/kotlin/allblocks.kt b/src/commonMain/kotlin/allblocks.kt new file mode 100644 index 0000000..c892647 --- /dev/null +++ b/src/commonMain/kotlin/allblocks.kt @@ -0,0 +1,166 @@ +import kotlin.properties.* + +var allBlockTypes: List>> by Delegates.notNull() + +// === SINGLE BLOCKS === +val ONE_BY_ONE = arrayOf( + arrayOf(1, 0, 0), arrayOf(0, 0, 0), arrayOf(0, 0, 0) +) + +val ONE_BY_TWO = arrayOf( + arrayOf(1, 0, 0), arrayOf(1, 0, 0), arrayOf(0, 0, 0) +) + +val TWO_BY_ONE = arrayOf( + arrayOf(1, 1, 0), arrayOf(0, 0, 0), arrayOf(0, 0, 0) +) + +val ONE_BY_THREE = arrayOf( + arrayOf(1, 0, 0), arrayOf(1, 0, 0), arrayOf(1, 0, 0) +) + +val THREE_BY_ONE = arrayOf( + arrayOf(1, 1, 1), arrayOf(0, 0, 0), arrayOf(0, 0, 0) +) + +val ONE_BY_FOUR = arrayOf( + arrayOf(1, 0, 0), arrayOf(1, 0, 0), arrayOf(1, 0, 0) // cut off after 3 (fits 3x3) +) + +val FOUR_BY_ONE = arrayOf( + arrayOf(1, 1, 1), arrayOf(0, 0, 0), arrayOf(0, 0, 0) // cut off after 3 +) + +val ONE_BY_FIVE = ONE_BY_THREE // same logic +val FIVE_BY_ONE = THREE_BY_ONE + +val TWO_BY_TWO = arrayOf( + arrayOf(1, 1, 0), arrayOf(1, 1, 0), arrayOf(0, 0, 0) +) + +val THREE_BY_THREE = arrayOf( + arrayOf(1, 1, 1), arrayOf(1, 1, 1), arrayOf(1, 1, 1) +) + +val L_2X2_0 = arrayOf( + arrayOf(1, 0, 0), arrayOf(1, 1, 0), arrayOf(0, 0, 0) +) + +val L_2X2_90 = arrayOf( + arrayOf(1, 1, 0), arrayOf(0, 1, 0), arrayOf(0, 0, 0) +) + +val L_2X2_180 = L_2X2_90 +val L_2X2_270 = L_2X2_0 + +val L_2X3_0 = arrayOf( + arrayOf(1, 0, 0), arrayOf(1, 0, 0), arrayOf(1, 1, 0) +) + +val L_2X3_90 = arrayOf( + arrayOf(0, 0, 1), arrayOf(1, 1, 1), arrayOf(0, 0, 0) +) + +val L_2X3_180 = arrayOf( + arrayOf(1, 1, 0), arrayOf(0, 1, 0), arrayOf(0, 1, 0) +) + +val L_2X3_270 = arrayOf( + arrayOf(1, 1, 1), arrayOf(1, 0, 0), arrayOf(0, 0, 0) +) + +val L_3X3_0 = arrayOf( + arrayOf(1, 0, 0), arrayOf(1, 0, 0), arrayOf(1, 1, 1) +) + +val L_3X3_90 = arrayOf( + arrayOf(1, 1, 1), arrayOf(0, 0, 1), arrayOf(0, 0, 1) +) + +val L_3X3_180 = arrayOf( + arrayOf(1, 1, 1), arrayOf(0, 0, 1), arrayOf(0, 0, 1) +) + +val L_3X3_270 = arrayOf( + arrayOf(1, 1, 1), arrayOf(1, 0, 0), arrayOf(1, 0, 0) +) + +val T_2X3_0 = arrayOf( + arrayOf(1, 1, 1), arrayOf(0, 1, 0), arrayOf(0, 0, 0) +) + +val T_2X3_90 = arrayOf( + arrayOf(0, 1, 0), arrayOf(1, 1, 0), arrayOf(0, 1, 0) +) + +val T_2X3_180 = arrayOf( + arrayOf(0, 1, 0), arrayOf(1, 1, 1), arrayOf(0, 0, 0) +) + +val T_2X3_270 = arrayOf( + arrayOf(1, 0, 0), arrayOf(1, 1, 0), arrayOf(1, 0, 0) +) + +val TWO_BY_THREE_0 = arrayOf( + arrayOf(1, 1, 1), arrayOf(1, 1, 1), arrayOf(0, 0, 0) +) + +val TWO_BY_THREE_90 = arrayOf( + arrayOf(1, 1, 0), arrayOf(1, 1, 0), arrayOf(1, 1, 0) +) + +val THREE_BY_TWO_0 = TWO_BY_THREE_90 +val THREE_BY_TWO_90 = TWO_BY_THREE_0 + +val S_2X3_0 = arrayOf( + arrayOf(0, 1, 1), arrayOf(1, 1, 0), arrayOf(0, 0, 0) +) + +val S_2X3_90 = arrayOf( + arrayOf(1, 0, 0), arrayOf(1, 1, 0), arrayOf(0, 1, 0) +) + +val S_2X3_180 = S_2X3_0 +val S_2X3_270 = S_2X3_90 + + +// === INIT FUNCTION === +fun initBlockTypes() { + allBlockTypes = listOf( + ONE_BY_ONE, + ONE_BY_TWO, + TWO_BY_ONE, + ONE_BY_THREE, + THREE_BY_ONE, + ONE_BY_FOUR, + FOUR_BY_ONE, + ONE_BY_FIVE, + FIVE_BY_ONE, + TWO_BY_TWO, + THREE_BY_THREE, + L_2X2_0, + L_2X2_90, + L_2X2_180, + L_2X2_270, + L_2X3_0, + L_2X3_90, + L_2X3_180, + L_2X3_270, + L_3X3_0, + L_3X3_90, + L_3X3_180, + L_3X3_270, + T_2X3_0, + T_2X3_90, + T_2X3_180, + T_2X3_270, + TWO_BY_THREE_0, + TWO_BY_THREE_90, + THREE_BY_TWO_0, + THREE_BY_TWO_90, + S_2X3_0, + S_2X3_90, + S_2X3_180, + S_2X3_270 + ) +} diff --git a/src/commonMain/kotlin/main.kt b/src/commonMain/kotlin/main.kt index 72953e7..00ba6ce 100644 --- a/src/commonMain/kotlin/main.kt +++ b/src/commonMain/kotlin/main.kt @@ -61,6 +61,7 @@ suspend fun main() = Korge( //backgroundField!!.y -= 70 populateField(this) + initBlockTypes() //val testBlock = block(BlockColors.Red, BlockType.TWObyTWO, StartPosition.LEFT) createPieces(this) @@ -137,7 +138,7 @@ fun createPieces(container: Container) { } } val color = BlockColors.getRandomColor() - val c = container.block(color, BlockTypeHelper.getRandomBlockType(), location!!) + val c = container.block(color, allBlockTypes.random(), location!!) allBlocks.add(c) }