Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
literalpie committed Dec 20, 2020
1 parent 622ef7b commit b68916b
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 37 deletions.
3 changes: 2 additions & 1 deletion Wonky Blocks/UI/GameViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ class WonkyGameViewController: UIViewController {
}
allCans.append(contactCan)
let activeTetCan = self.gameState.$activeTet.sink { (newActive) in
let newPieceXPosition = (CGFloat(WonkyGameBoard.width) / 2) + WonkyRowIndicator.indicatorWidth - newActive.center.x
let newPieceXPosition =
(CGFloat(WonkyGameBoard.width) / 2) + WonkyRowIndicator.indicatorWidth - newActive.center.x
newActive.position = CGPoint(x: newPieceXPosition, y: CGFloat(WonkyGameBoard.height))
newActive.removeFromParent() // removes from preview scene
self.spriteKitView.scene?.addChild(newActive)
Expand Down
11 changes: 6 additions & 5 deletions Wonky Blocks/UI/MainMenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,18 @@ struct MainMenuView: View {
.padding()
}
Text("High Score: \(gameState.highScore)")
Button("Reset High Score") {
gameState.resetHighScore()
}
.wonkyButton()
Button("Reset High Score") {
gameState.resetHighScore()
}
.wonkyButton()
}
}
}

struct WonkyButton: ViewModifier {
func body(content: Content) -> some View {
return content
return
content
.foregroundColor(.primary)
.font(.headline)
.padding(5)
Expand Down
5 changes: 4 additions & 1 deletion Wonky Blocks/UI/PiecePreviewView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ struct PiecePreviewView: UIViewRepresentable {
scene.isPaused = false
piece.removeFromParent()
scene.addChild(piece)
piece.position = CGPoint(x: Self.previewSize / 2 - piece.center.x, y: Self.previewSize / 2 - piece.center.y)
piece.position = CGPoint(
x: Self.previewSize / 2 - piece.center.x,
y: Self.previewSize / 2 - piece.center.y
)
scene.isPaused = true
}
}
Expand Down
26 changes: 13 additions & 13 deletions Wonky Blocks/UI/RootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ struct RootView: View {
if gameState.gameStarted && size.size.width <= size.size.height && !gameState.gameOver {
HStack {
#if targetEnvironment(macCatalyst)
if gameState.gameStarted && showInstructions {
InstructionsView(layoutDirection: .horizontal)
}
if gameState.gameStarted && showInstructions {
InstructionsView(layoutDirection: .horizontal)
}
#endif
Spacer()
ScoreBoardView()
Expand All @@ -51,9 +51,9 @@ struct RootView: View {
Spacer()
Group {
#if targetEnvironment(macCatalyst)
if showInstructions {
InstructionsView(layoutDirection: .vertical)
}
if showInstructions {
InstructionsView(layoutDirection: .vertical)
}
#endif
}
}
Expand All @@ -62,15 +62,15 @@ struct RootView: View {
}
// we don't want this to get in the way of button presses
#if !targetEnvironment(macCatalyst)
if gameState.gameStarted, !gameState.gameOver {
VStack {
Spacer(minLength: size.size.height / 2) // cause joysticks to only be on bottom half so buttons can be pressed
HStack(spacing: 0) {
Joystick(state: self.$joyState, radius: 50)
Joystick(state: self.$rotateState, radius: 50)
if gameState.gameStarted, !gameState.gameOver {
VStack {
Spacer(minLength: size.size.height / 2) // cause joysticks to only be on bottom half so buttons can be pressed
HStack(spacing: 0) {
Joystick(state: self.$joyState, radius: 50)
Joystick(state: self.$rotateState, radius: 50)
}
}
}
}
#endif
}
.onAppear {
Expand Down
5 changes: 4 additions & 1 deletion Wonky Blocks/UI/SKNodes/WonkyGameBoard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ class WonkyGameBoard: SKNode {

let ground = SKShapeNode(rect: CGRect(x: 0, y: 0, width: Self.width, height: 0))
ground.name = "ground"
ground.physicsBody = SKPhysicsBody(edgeFrom: CGPoint(x: 0, y: -2), to: CGPoint(x: Self.width, y: -2))
ground.physicsBody = SKPhysicsBody(
edgeFrom: CGPoint(x: 0, y: -2),
to: CGPoint(x: Self.width, y: -2)
)
ground.physicsBody?.categoryBitMask = groundCategory

self.addChild(leftWall)
Expand Down
10 changes: 7 additions & 3 deletions Wonky Blocks/UI/SKNodes/WonkyRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ class WonkyRow: SKShapeNode {
init(rowNumber: Int = 0) {
super.init()
let rowSize = CGSize(width: Self.rowWidth, height: Self.rowHeight)
let rowCenter = CGPoint(x: rowSize.width / 2, y: rowSize.height / 2 + (CGFloat(Self.rowHeight * rowNumber)))
let rowCenter = CGPoint(
x: rowSize.width / 2, y: rowSize.height / 2 + (CGFloat(Self.rowHeight * rowNumber)))
self.path = CGPath(
rect: CGRect(x: 0, y: Self.rowHeight * rowNumber, width: Self.rowWidth, height: Self.rowHeight),
transform: nil)
rect: CGRect(
x: 0, y: Self.rowHeight * rowNumber, width: Self.rowWidth, height: Self.rowHeight
),
transform: nil
)
physicsBody = SKPhysicsBody(
rectangleOf: rowSize, center: CGPoint(x: rowCenter.x, y: rowCenter.y))
physicsBody?.affectedByGravity = true
Expand Down
5 changes: 3 additions & 2 deletions Wonky Blocks/UI/SKNodes/WonkyRowIndicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SpriteKit

/// The bars on the left side of the board that indicate how full the row is.
class WonkyRowIndicator: SKShapeNode {
static let indicatorWidth = CGFloat(WonkyRow.rowHeight) // square, based on the row height
static let indicatorWidth = CGFloat(WonkyRow.rowHeight) // square, based on the row height
static let indicatorHeight = CGFloat(WonkyRow.rowHeight)

override init() {
Expand All @@ -23,8 +23,9 @@ class WonkyRowIndicator: SKShapeNode {
}

func updateRowStatus(fillPercentage: CGFloat) {
let rowStatusWidth = Self.indicatorWidth * fillPercentage
self.path = CGPath(
rect: CGRect(x: 0, y: 0, width: Self.indicatorWidth * fillPercentage, height: Self.indicatorHeight),
rect: CGRect(x: 0, y: 0, width: rowStatusWidth, height: Self.indicatorHeight),
transform: nil
)
if fillPercentage > 1 {
Expand Down
2 changes: 1 addition & 1 deletion Wonky Blocks/UI/SKNodes/WonkyTetronimo+movements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2020 Benjamin Kindle. All rights reserved.
//

import Foundation
import CoreGraphics
import Foundation

extension WonkyTetronimo {
func moveLeft() {
Expand Down
20 changes: 10 additions & 10 deletions Wonky Blocks/UI/ScoreboardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ struct ScoreBoardView: View {
Text("High Score: \(highScore)")
}
if gameState.gameStarted && !gameState.gameOver {
VStack(alignment: .center) {
Button("Main Menu") {
gameState.gameStarted = false
}
.wonkyButton()

Button(gameState.paused ? "Resume" : "Pause") {
gameState.paused.toggle()
}
.wonkyButton()
VStack(alignment: .center) {
Button("Main Menu") {
gameState.gameStarted = false
}
.wonkyButton()

Button(gameState.paused ? "Resume" : "Pause") {
gameState.paused.toggle()
}
.wonkyButton()
}
}
}
}
Expand Down

0 comments on commit b68916b

Please sign in to comment.