Skip to content

Commit

Permalink
Merge pull request cs3217-2324#83 from keith-gan/kgan/pause
Browse files Browse the repository at this point in the history
Kgan/pause
  • Loading branch information
zheng-ze authored Apr 6, 2024
2 parents 9907dcc + a6c9e3f commit 8c286b8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
15 changes: 2 additions & 13 deletions TowerForge/TowerForge/GameModule/GameWorld.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class GameWorld {
private let worldBounds: CGRect

unowned var delegate: SceneManagerDelegate?
unowned var statePopupDelegate: StatePopupDelegate?

init(scene: GameScene?, screenSize: CGRect, mode: Mode,
gameRoom: GameRoom? = nil, currentPlayer: GamePlayer? = nil) {
Expand Down Expand Up @@ -94,7 +95,7 @@ class GameWorld {

func presentStatePopup() {
let popup = StatePopupNode()
popup.delegate = self
popup.delegate = statePopupDelegate
// TODO: Refactor this
popup.zPosition = 10_000
popup.name = "popup"
Expand All @@ -115,15 +116,3 @@ extension GameWorld: UnitSelectionNodeDelegate {
position: position, player: .ownPlayer))
}
}

// TODO: Fill the function
extension GameWorld: StatePopupDelegate {
func onMenu() {
//
}

func onResume() {
//
}

}
13 changes: 13 additions & 0 deletions TowerForge/TowerForge/GameViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import SpriteKit
class GameViewController: UIViewController {
private var gameWorld: GameWorld?
var gameMode: Mode?
var isPaused = false
var gameRoom: GameRoom?
var currentPlayer: GamePlayer?

@IBAction private func onStatePressed(_ sender: Any) {
isPaused = true
gameWorld?.presentStatePopup()
}

Expand Down Expand Up @@ -47,6 +49,7 @@ class GameViewController: UIViewController {
mode: self.gameMode ?? .captureTheFlag,
gameRoom: gameRoom, currentPlayer: currentPlayer)
self.gameWorld?.delegate = self
self.gameWorld?.statePopupDelegate = self
}
}

Expand Down Expand Up @@ -81,6 +84,7 @@ extension GameViewController: SceneManagerDelegate {
// Present the scene
gameScene.sceneManagerDelegate = self
gameScene.updateDelegate = self
gameScene.statePopupDelegate = self
showScene(scene: gameScene)
setUpGameWorld(scene: gameScene)
}
Expand All @@ -95,3 +99,12 @@ extension GameViewController: SceneManagerDelegate {
}
}
}

extension GameViewController: StatePopupDelegate {
func onMenu() {
}

func onResume() {
isPaused = false
}
}
1 change: 1 addition & 0 deletions TowerForge/TowerForge/Nodes/StatePopupNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Foundation
import UIKit

protocol StatePopupDelegate: AnyObject {
var isPaused: Bool { get }
func onMenu()
func onResume()
}
Expand Down
13 changes: 13 additions & 0 deletions TowerForge/TowerForge/Scenes/GameScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import GameplayKit
class GameScene: SKScene {
unowned var updateDelegate: SceneUpdateDelegate?
unowned var sceneManagerDelegate: SceneManagerDelegate?
unowned var statePopupDelegate: StatePopupDelegate?
private var lastUpdatedTimeInterval = TimeInterval(0)
private var cameraNode: TFCameraNode?
private var isPan = false
Expand All @@ -21,11 +22,17 @@ class GameScene: SKScene {
}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if statePopupDelegate?.isPaused ?? false {
return
}
super.touchesBegan(touches, with: event)
isPan = false
}

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
if statePopupDelegate?.isPaused ?? false {
return
}
super.touchesEnded(touches, with: event)
guard let touch = touches.first else {
return
Expand All @@ -39,6 +46,9 @@ class GameScene: SKScene {
}

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
if statePopupDelegate?.isPaused ?? false {
return
}
super.touchesMoved(touches, with: event)
guard let touch = touches.first else {
return
Expand All @@ -55,6 +65,9 @@ class GameScene: SKScene {
}

override func update(_ currentTime: TimeInterval) {
if statePopupDelegate?.isPaused ?? false {
return
}
if lastUpdatedTimeInterval == TimeInterval(0) {
lastUpdatedTimeInterval = currentTime
}
Expand Down

0 comments on commit 8c286b8

Please sign in to comment.