Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
keith-gan committed Apr 5, 2024
2 parents 3e7cede + 6958d1b commit 19a3881
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 2 deletions.
4 changes: 4 additions & 0 deletions TowerForge/TowerForge.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
527A07842BB3FD9A00CD9D08 /* TimerSystem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 527A07832BB3FD9A00CD9D08 /* TimerSystem.swift */; };
527A07862BB411FB00CD9D08 /* GameOverScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 527A07852BB411FB00CD9D08 /* GameOverScene.swift */; };
527E3A242BA613F000FE1628 /* PlayerComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 527E3A232BA613EF00FE1628 /* PlayerComponent.swift */; };
529190E32BBFB59B001D8821 /* StatePopupNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 529190E22BBFB59B001D8821 /* StatePopupNode.swift */; };
5295A2022BA9FBD9005018A8 /* SceneManagerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5295A2012BA9FBD9005018A8 /* SceneManagerDelegate.swift */; };
5295A2042BA9FED4005018A8 /* MenuScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5295A2032BA9FED4005018A8 /* MenuScene.swift */; };
5295A2072BAA02FD005018A8 /* TFButtonNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5295A2062BAA02FD005018A8 /* TFButtonNode.swift */; };
Expand Down Expand Up @@ -294,6 +295,7 @@
527A07832BB3FD9A00CD9D08 /* TimerSystem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimerSystem.swift; sourceTree = "<group>"; };
527A07852BB411FB00CD9D08 /* GameOverScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameOverScene.swift; sourceTree = "<group>"; };
527E3A232BA613EF00FE1628 /* PlayerComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerComponent.swift; sourceTree = "<group>"; };
529190E22BBFB59B001D8821 /* StatePopupNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatePopupNode.swift; sourceTree = "<group>"; };
5295A2012BA9FBD9005018A8 /* SceneManagerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneManagerDelegate.swift; sourceTree = "<group>"; };
5295A2032BA9FED4005018A8 /* MenuScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuScene.swift; sourceTree = "<group>"; };
5295A2062BAA02FD005018A8 /* TFButtonNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TFButtonNode.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -590,6 +592,7 @@
5295A2142BAAF335005018A8 /* UnitSelectionNode.swift */,
9B0406112BB889940026E903 /* PowerUpNode.swift */,
9B0406132BB89BE00026E903 /* PowerUpSelectionNode.swift */,
529190E22BBFB59B001D8821 /* StatePopupNode.swift */,
);
path = Nodes;
sourceTree = "<group>";
Expand Down Expand Up @@ -1380,6 +1383,7 @@
3CAC4A6B2BB6992F00A5D22E /* TFNode.swift in Sources */,
3CAC4A6D2BB6A13B00A5D22E /* PositionRenderStage.swift in Sources */,
3CE951672BAEAB0E008B2785 /* ContactSystem.swift in Sources */,
529190E32BBFB59B001D8821 /* StatePopupNode.swift in Sources */,
3CE951692BAEB719008B2785 /* RequestSpawnEvent.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,27 @@
<view key="view" multipleTouchEnabled="YES" contentMode="scaleToFill" id="3se-qz-xqx" customClass="SKView">
<rect key="frame" x="0.0" y="0.0" width="1366" height="1024"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="FRf-Sx-cuP">
<rect key="frame" x="20" y="20" width="114" height="77"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain">
<backgroundConfiguration key="background" image="resume-button"/>
</buttonConfiguration>
<connections>
<action selector="onStatePressed:" destination="BV1-FR-VrT" eventType="touchUpInside" id="jae-ri-mPS"/>
</connections>
</button>
</subviews>
<viewLayoutGuide key="safeArea" id="4qk-I5-YsI"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
<navigationItem key="navigationItem" id="9Rh-a0-sTy"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="SZV-WD-TEh" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="140" y="-2"/>
<point key="canvasLocation" x="139.67789165446558" y="-2.34375"/>
</scene>
<!--MainMenuViewController-->
<scene sceneID="vFw-SO-Nq3">
Expand Down Expand Up @@ -387,6 +400,7 @@ Match</string>
</scene>
</scenes>
<inferredMetricsTieBreakers>
<segue reference="gCm-LW-wHo"/>
<segue reference="5Mz-7I-nNc"/>
</inferredMetricsTieBreakers>
<resources>
Expand All @@ -395,6 +409,7 @@ Match</string>
<image name="background" width="1000" height="500"/>
<image name="background1" width="1600" height="1000"/>
<image name="logo" width="1000" height="500"/>
<image name="resume-button" width="1600" height="1000"/>
<image name="square-button" width="1600" height="1000"/>
<image name="start-button" width="1000" height="500"/>
<namedColor name="AccentColor">
Expand Down
23 changes: 23 additions & 0 deletions TowerForge/TowerForge/GameModule/GameWorld.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import QuartzCore
import UIKit

class GameWorld {
// Need to ensure that width is a multiple of 1024 - unit selection node height
Expand Down Expand Up @@ -90,6 +91,16 @@ class GameWorld {
gameEngine.addEntity(node)
}
}

func presentStatePopup() {
let popup = StatePopupNode()
popup.delegate = self
// TODO: Refactor this
popup.zPosition = 10_000
popup.position = CGPoint(x: UIScreen.main.bounds.width / 2,
y: UIScreen.main.bounds.height / 2)
scene?.add(node: popup, staticOnScreen: false)
}
}

extension GameWorld: Renderable {
Expand All @@ -104,3 +115,15 @@ extension GameWorld: UnitSelectionNodeDelegate {
position: position, player: .ownPlayer))
}
}

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

func onResume() {
//
}

}
3 changes: 3 additions & 0 deletions TowerForge/TowerForge/GameViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class GameViewController: UIViewController {
private var gameWorld: GameWorld?
var gameMode: Mode?

@IBAction private func onStatePressed(_ sender: Any) {
gameWorld?.presentStatePopup()
}
override func viewDidLoad() {
super.viewDidLoad()
AchievementManager.incrementTotalGamesStarted()
Expand Down
60 changes: 60 additions & 0 deletions TowerForge/TowerForge/Nodes/StatePopupNode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// StatePopupNode.swift
// TowerForge
//
// Created by Vanessa Mae on 05/04/24.
//

import Foundation
import UIKit

protocol StatePopupDelegate {
func onMenu()
func onResume()
}

class StatePopupNode: TFSpriteNode {

var delegate: StatePopupDelegate?

init() {
super.init(color: .clear, size: CGSize(width: 300, height: 300))
setupNode()
}

func setupNode() {
let background = TFSpriteNode(imageName: "square-button", size: self.size)

// TODO: Refactor into a constant
background.position = CGPoint(x: 0, y: 0)
background.name = "statePopupNode"

let resumeButton = TFButtonNode(action: TFButtonDelegate(onTouchBegan: { [weak self] in
self?.delegate?.onResume()
},
onTouchEnded: {}),
size: CGSize(width: 50,
height: 50),
imageNamed: "circle-button")
resumeButton.name = "resumeButton"

let menuButton = TFButtonNode(action: TFButtonDelegate(onTouchBegan: { [weak self] in
self?.delegate?.onMenu()
}, onTouchEnded: {}), size: CGSize(width: 50, height: 50), imageNamed: "circle-button")
menuButton.name = "menuButton"

// TODO: Refactor the position into a constants
resumeButton.position = CGPoint(x: background.position.x + 150, y: background.position.y)
menuButton.position = CGPoint(x: background.position.x - 150, y: background.position.y)

background.zPosition = self.zPosition + 10
resumeButton.zPosition = self.zPosition + 20
menuButton.zPosition = self.zPosition + 20

self.add(child: background)
self.add(child: menuButton)
self.add(child: resumeButton)

}

}
1 change: 1 addition & 0 deletions TowerForge/TowerForge/Scenes/GameScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class GameScene: SKScene {
let cameraNode = TFCameraNode()
self.cameraNode = cameraNode
cameraNode.position = CGPoint(x: size.width / 2, y: size.height / 2)
cameraNode.zPosition = 1_000
addChild(cameraNode.node)
camera = cameraNode.cameraNode
}
Expand Down
13 changes: 13 additions & 0 deletions TowerForge/TowerForge/TFCore/TFButtonNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ struct TFButtonDelegate {

private class TFButton: SKSpriteNode {
private var action: TFButtonDelegate?

init(buttonAction: TFButtonDelegate?, size: CGSize) {
self.action = buttonAction
super.init(texture: nil, color: .clear, size: size)
}

init(buttonAction: TFButtonDelegate?, size: CGSize, imageNamed: String) {
let texture = SKTexture(imageNamed: imageNamed)
self.action = buttonAction
super.init(texture: texture, color: .clear, size: size)
}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
action?.onTouchBegan()
}
Expand All @@ -38,4 +45,10 @@ class TFButtonNode: TFNode {
super.init()
node = TFButton(buttonAction: action, size: size)
}
init(action: TFButtonDelegate?, size: CGSize, imageNamed: String) {
super.init()
node = TFButton(buttonAction: action,
size: size,
imageNamed: imageNamed)
}
}
1 change: 1 addition & 0 deletions TowerForge/TowerForge/TFCore/TFNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class TFNode {
}

func add(child: TFNode) {
// TODO: This enforces child to have name
guard let name = child.name, children[name] == nil else {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class GameWaitingRoomViewController: UIViewController {
var currentPlayer: GamePlayer?
override func viewDidLoad() {
super.viewDidLoad()
print(gameRoom)
gameRoom?.gameRoomDelegate = self
updatePlayerList()
}
Expand Down

0 comments on commit 19a3881

Please sign in to comment.