Change tetromino appearance

This commit is contained in:
Shadowfacts 2019-10-20 19:21:04 -04:00
parent f1f0a49023
commit 18c2938470
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
15 changed files with 194 additions and 35 deletions

View File

@ -17,19 +17,20 @@ struct CurrentPieceView: View {
var body: some View {
GridView(rows: self.boardHeight, columns: self.boardWidth) { (col, row, size) in
Rectangle()
.foregroundColor(self.colorAt(col, row))
.frame(width: size, height: size)
}
}
func colorAt(_ col: Int, _ row: Int) -> Color {
if currentPieceAt(col, row) {
return self.currentPiece!.tetromino.color
} else if droppedPieceAt(col, row) {
return .gray
} else {
return .clear
if self.currentPieceAt(col, row) {
Rectangle()
.foregroundColor(self.currentPiece!.tetromino.color)
.frame(width: size, height: size)
.border(self.currentPiece!.tetromino.borderColor, width: 6)
} else if self.droppedPieceAt(col, row) {
Rectangle()
.foregroundColor(.gray)
.frame(width: size, height: size)
} else {
Rectangle()
.foregroundColor(.clear)
.frame(width: size, height: size)
}
}
}

View File

@ -11,8 +11,8 @@
"components" : {
"red" : "0",
"alpha" : "1.000",
"blue" : "211",
"green" : "214"
"blue" : "202",
"green" : "205"
}
}
}

View File

@ -0,0 +1,20 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "0.320",
"alpha" : "1.000",
"blue" : "0.908",
"green" : "0.916"
}
}
}
]
}

View File

@ -0,0 +1,20 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "0.294",
"alpha" : "1.000",
"blue" : "0.839",
"green" : "0.495"
}
}
}
]
}

View File

@ -11,8 +11,8 @@
"components" : {
"red" : "0",
"alpha" : "1.000",
"blue" : "71",
"green" : "214"
"blue" : "68",
"green" : "204"
}
}
}

View File

@ -0,0 +1,20 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "0.364",
"alpha" : "1.000",
"blue" : "0.542",
"green" : "0.899"
}
}
}
]
}

View File

@ -9,10 +9,10 @@
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "255",
"red" : "1.000",
"alpha" : "1.000",
"blue" : "0",
"green" : "128"
"blue" : "0.000",
"green" : "0.502"
}
}
}

View File

@ -0,0 +1,20 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "255",
"alpha" : "1.000",
"blue" : "89",
"green" : "172"
}
}
}
]
}

View File

@ -0,0 +1,20 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "0.722",
"alpha" : "1.000",
"blue" : "0.839",
"green" : "0.294"
}
}
}
]
}

View File

@ -0,0 +1,20 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "0.839",
"alpha" : "1.000",
"blue" : "0.449",
"green" : "0.294"
}
}
}
]
}

View File

@ -11,8 +11,8 @@
"components" : {
"red" : "255",
"alpha" : "1.000",
"blue" : "71",
"green" : "229"
"blue" : "0",
"green" : "206"
}
}
}

View File

@ -0,0 +1,20 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "1.000",
"alpha" : "1.000",
"blue" : "0.431",
"green" : "0.920"
}
}
}
]
}

View File

@ -28,4 +28,22 @@ extension Tetromino {
return Color("TetrominoGreen", bundle: .tetrisUI)
}
}
var borderColor: Color {
switch self {
case .i:
return Color("TetrominoAquaLight", bundle: .tetrisUI)
case .o:
return Color("TetrominoYellowLight", bundle: .tetrisUI)
case .t:
return Color("TetrominoPurpleLight", bundle: .tetrisUI)
case .j:
return Color("TetrominoOrangeLight", bundle: .tetrisUI)
case .l:
return Color("TetrominoBlueLight", bundle: .tetrisUI)
case .s:
return Color("TetrominoRedLight", bundle: .tetrisUI)
case .z:
return Color("TetrominoGreenLight", bundle: .tetrisUI)
}
}
}

View File

@ -18,9 +18,16 @@ public struct TetrominoView: View {
public var body: some View {
GridView(rows: self.rows, columns: self.columns) { (col, row, size) in
Rectangle()
.foregroundColor(self.colorAt(col, row))
.frame(width: size, height: size)
if row < self.tetromino.shape.count && col < self.tetromino.shape[row].count && self.tetromino.shape[row][col] {
Rectangle()
.foregroundColor(self.tetromino.color)
.frame(width: size, height: size)
.border(self.tetromino.borderColor, width: 6)
} else {
Rectangle()
.foregroundColor(.clear)
.frame(width: size, height: size)
}
}
}
@ -39,14 +46,6 @@ public struct TetrominoView: View {
}) ?? row.count - 1) + 1
}.max() ?? self.tetromino.shape.first!.count
}
func colorAt(_ col: Int, _ row: Int) -> Color {
if row < tetromino.shape.count && col < tetromino.shape[row].count && tetromino.shape[row][col] {
return tetromino.color
} else {
return .clear
}
}
}
struct TetrominoView_Previews: PreviewProvider {

View File

@ -17,12 +17,13 @@ struct TilesView: View {
if self.board[col, row] {
Rectangle()
.frame(width: size, height: size)
.foregroundColor(self.board[col, row]?.color ?? Color("Background", bundle: .tetrisUI))
.foregroundColor(self.board[col, row]!.color)
.border(self.board[col, row]!.borderColor, width: 6)
} else {
Rectangle()
.frame(width: size, height: size)
.foregroundColor(Color("Background", bundle: .tetrisUI))
.border(Color("TileBorder"), width: 1)
.border(Color("TileBorder", bundle: .tetrisUI), width: 2)
}
}
}