Skip to content

Commit

Permalink
fix: prevent frozen state when first starting game
Browse files Browse the repository at this point in the history
  • Loading branch information
literalpie committed Mar 5, 2022
1 parent 4ed913a commit c8a0d1d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Wonky Blocks/UI/GameViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class WonkyGameViewController: UIViewController, SKSceneDelegate {
self.rows.forEach { self.spriteKitView.scene?.addChild($0) }
view.ignoresSiblingOrder = true

// update row indicators (this block doesn't remove ant rows)
// update row indicators (this block doesn't remove any rows)
let timerCan = Timer.publish(every: 0.1, on: .main, in: .common).autoconnect().sink { (_) in
if !self.gameState.paused {
self.checkForMovedTetronimos()
Expand Down Expand Up @@ -143,6 +143,7 @@ class WonkyGameViewController: UIViewController, SKSceneDelegate {
}
allCans.append(contactCan)
let activeTetCan = self.gameState.$activeTet.sink { (newActive) in
print("new active")
let newPieceXPosition =
(CGFloat(WonkyGameBoard.width) / 2) + WonkyRowIndicator.indicatorWidth - newActive.center.x
newActive.position = CGPoint(x: newPieceXPosition, y: CGFloat(WonkyGameBoard.height))
Expand Down
5 changes: 5 additions & 0 deletions Wonky Blocks/UI/MainMenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ struct MainMenuView: View {
// for keyboard shortcut
if #available(macCatalyst 14.0, iOS 14.0, *) {
Button("Start Game") {
if (gameState.gameStarted) {
// sometimes if you hit enter when the game is first started,
// it will try to start the game twice.
return
}
gameState.resetGame()
gameState.gameStarted = true
}
Expand Down

0 comments on commit c8a0d1d

Please sign in to comment.