// // GamePieceView.swift // Tetris // // Created by Shadowfacts on 10/20/19. // Copyright © 2019 Shadowfacts. All rights reserved. // import SwiftUI import TetrisKit struct GamePieceView: View { let size: CGFloat let piece: GamePiece let color: Color let border: Bool init(size: CGFloat, piece: GamePiece, color: Color? = nil, border: Bool = true) { self.size = size self.piece = piece self.color = color ?? piece.tetromino.color self.border = border } var body: some View { return TetrominoView(size: size, tetromino: piece.tetromino, color: color, border: border) .rotationEffect(.degrees(piece.rotation)) .offset(x: CGFloat(piece.topLeft.0) * size, y: CGFloat(piece.topLeft.1) * size) .frame(width: size * CGFloat(piece.tiles.count), height: size * CGFloat(piece.tiles.count)) } } struct GamePieceView_Previews: PreviewProvider { static var previews: some View { GamePieceView(size: 100, piece: GamePiece(tetromino: .t)) } }