From c8a0d1d0add78f4ecae24c97e3403ca022e4ed36 Mon Sep 17 00:00:00 2001 From: Benjamin Kindle Date: Sat, 5 Mar 2022 11:24:48 -0500 Subject: [PATCH] fix: prevent frozen state when first starting game --- Wonky Blocks/UI/GameViewController.swift | 3 ++- Wonky Blocks/UI/MainMenuView.swift | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Wonky Blocks/UI/GameViewController.swift b/Wonky Blocks/UI/GameViewController.swift index b03d18e..9dcc5b5 100644 --- a/Wonky Blocks/UI/GameViewController.swift +++ b/Wonky Blocks/UI/GameViewController.swift @@ -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() @@ -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)) diff --git a/Wonky Blocks/UI/MainMenuView.swift b/Wonky Blocks/UI/MainMenuView.swift index 5adef40..3172e68 100644 --- a/Wonky Blocks/UI/MainMenuView.swift +++ b/Wonky Blocks/UI/MainMenuView.swift @@ -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 }