Skip to content

Commit

Permalink
Merge pull request cs3217-2324#115 from zheng-ze/main
Browse files Browse the repository at this point in the history
Update GameScene to scale with iPad sizes
  • Loading branch information
Vanessamae23 authored Apr 16, 2024
2 parents 082fa1f + b432f0c commit 1b0d8f9
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions TowerForge/TowerForge/GameModule/GameWorld.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import QuartzCore
import UIKit

class GameWorld {
// Need to ensure that width is a multiple of 1024 - unit selection node height
static let worldSize = CGSize(width: 2_472, height: 1_024)
// Must subtract one else there will be an extra unintended tile for each row.
static let worldSize = CGSize(width: (1_024 * 0.8) * 3 - 1, height: 1_024)

private var gameEngine: AbstractGameEngine
private var gameMode: GameMode
Expand Down
2 changes: 1 addition & 1 deletion TowerForge/TowerForge/LevelModule/Grid/Grid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SpriteKit

class Grid: GridDelegate {
static let DEFAULT_NUM_ROWS = 5
let UNIT_SELECTION_NODE_HEIGHT = CGFloat(200)
var UNIT_SELECTION_NODE_HEIGHT: CGFloat { GameWorld.worldSize.height / 5 }
let playableBounds: CGRect

private let numRows: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class GameRoom {
}

deinit {
print("deinit")
removeAllListeners()
}

Expand Down
2 changes: 1 addition & 1 deletion TowerForge/TowerForge/Nodes/PowerUpNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protocol PowerUpNodeDelegate: AnyObject {
}

class PowerUpNode: TFEntity {
static let size = CGSize(width: 140, height: 200)
static let size = UnitNode.size
let type: PowerUp
var delegate: PowerUpNodeDelegate

Expand Down
6 changes: 5 additions & 1 deletion TowerForge/TowerForge/Nodes/UnitNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ protocol UnitNodeDelegate: AnyObject {
}

class UnitNode: TFEntity {
static let size = CGSize(width: 140, height: 200)
static var size: CGSize {
let height = UIScreen.main.bounds.height / 5
let width = height * 0.7
return CGSize(width: width, height: height)
}

let type: (TFEntity & PlayerSpawnable).Type
weak var delegate: UnitNodeDelegate?
Expand Down
4 changes: 4 additions & 0 deletions TowerForge/TowerForge/Scenes/GameScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ class GameScene: SKScene {

private func setupCamera() {
let cameraNode = TFCameraNode()
let scaleRatio = size.height / UIScreen.main.bounds.height
self.cameraNode = cameraNode
cameraNode.position = CGPoint(x: size.width / 2, y: size.height / 2)
cameraNode.zPosition = 1_000
cameraNode.xScale = scaleRatio
cameraNode.yScale = scaleRatio

addChild(cameraNode.node)
camera = cameraNode.cameraNode
}
Expand Down
9 changes: 5 additions & 4 deletions TowerForge/TowerForge/TFCore/TFCameraNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ class TFCameraNode: TFNode {
func setBounds(_ bounds: CGRect) {
let size = UIScreen.main.bounds.size

self.minX = bounds.minX + size.width / 2
self.maxX = bounds.maxX - size.width / 2
self.minY = bounds.minY + size.height / 2
self.maxY = bounds.maxY - size.height / 2
self.minX = (bounds.minX + size.width / 2) * self.xScale
self.maxX = (bounds.maxX - size.width / 2) - minX * (self.xScale - 1) / self.xScale
self.minY = (bounds.minY + size.height / 2) * self.yScale
self.maxY = (bounds.maxY - size.height / 2) - minY * (self.yScale - 1) / self.yScale
self.move(by: .zero)
}

override func move(by displacement: CGVector) {
Expand Down
3 changes: 1 addition & 2 deletions TowerForge/TowerForge/TFCore/TFNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SpriteKit
class TFNode {
var staticOnScreen = false
var node: SKNode
private var children: [String: TFNode] = [:]
var children: [String: TFNode] = [:]

var name: String? {
get { node.name }
Expand Down Expand Up @@ -61,7 +61,6 @@ 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 @@ -17,7 +17,6 @@ class GameWaitingRoomViewController: UIViewController {
gameRoom?.deleteRoom()
gameRoom = nil
currentPlayer = nil
print("deinit")
}

override func viewDidLoad() {
Expand Down

0 comments on commit 1b0d8f9

Please sign in to comment.