Merge branch '24-map-generation-fur-zwei-spieler-twoplayermap' into 'development'
Resolve "Map Generation für zwei Spieler - TwoPlayerMap" Closes #24 See merge request marcel.schwarz/software-projekt-2!64
This commit is contained in:
commit
53705849f2
@ -46,9 +46,10 @@
|
|||||||
9EC86BA6245C8AD000796EF3 /* ModalType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86BA5245C8AD000796EF3 /* ModalType.swift */; };
|
9EC86BA6245C8AD000796EF3 /* ModalType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86BA5245C8AD000796EF3 /* ModalType.swift */; };
|
||||||
9EEDE02D246FCD770096C735 /* SpinningLogoEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EEDE02C246FCD770096C735 /* SpinningLogoEntity.swift */; };
|
9EEDE02D246FCD770096C735 /* SpinningLogoEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EEDE02C246FCD770096C735 /* SpinningLogoEntity.swift */; };
|
||||||
9EEDE02F246FCD800096C735 /* SpinningLogoComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EEDE02E246FCD800096C735 /* SpinningLogoComponent.swift */; };
|
9EEDE02F246FCD800096C735 /* SpinningLogoComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EEDE02E246FCD800096C735 /* SpinningLogoComponent.swift */; };
|
||||||
AB1D759C245DD18100671525 /* MapProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759A245DD18100671525 /* MapProtocol.swift */; };
|
|
||||||
AB1D759D245DD18100671525 /* TwoPlayerDefaultTestMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */; };
|
AB1D759D245DD18100671525 /* TwoPlayerDefaultTestMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */; };
|
||||||
AB1D75A0245DEC0500671525 /* MapFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759F245DEC0500671525 /* MapFactory.swift */; };
|
AB1D75A0245DEC0500671525 /* MapFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759F245DEC0500671525 /* MapFactory.swift */; };
|
||||||
|
AB21D7D5246C748A00B09CBA /* TwoPlayerMapGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB21D7D4246C748A00B09CBA /* TwoPlayerMapGenerator.swift */; };
|
||||||
|
AB94038A2471528D004FCD07 /* SampleCElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB9403892471528D004FCD07 /* SampleCElement.swift */; };
|
||||||
ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; };
|
ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; };
|
||||||
AE151589245F18EF001D363E /* MatchmakingHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE151588245F18EF001D363E /* MatchmakingHelper.swift */; };
|
AE151589245F18EF001D363E /* MatchmakingHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE151588245F18EF001D363E /* MatchmakingHelper.swift */; };
|
||||||
AEBF3AFF246EB146004F7CD5 /* CancelBtnNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEBF3AFE246EB146004F7CD5 /* CancelBtnNode.swift */; };
|
AEBF3AFF246EB146004F7CD5 /* CancelBtnNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEBF3AFE246EB146004F7CD5 /* CancelBtnNode.swift */; };
|
||||||
@ -117,9 +118,10 @@
|
|||||||
9ECD3699245C91F7008DEEBD /* GoldWars.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GoldWars.entitlements; sourceTree = "<group>"; };
|
9ECD3699245C91F7008DEEBD /* GoldWars.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GoldWars.entitlements; sourceTree = "<group>"; };
|
||||||
9EEDE02C246FCD770096C735 /* SpinningLogoEntity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpinningLogoEntity.swift; sourceTree = "<group>"; };
|
9EEDE02C246FCD770096C735 /* SpinningLogoEntity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpinningLogoEntity.swift; sourceTree = "<group>"; };
|
||||||
9EEDE02E246FCD800096C735 /* SpinningLogoComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpinningLogoComponent.swift; sourceTree = "<group>"; };
|
9EEDE02E246FCD800096C735 /* SpinningLogoComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpinningLogoComponent.swift; sourceTree = "<group>"; };
|
||||||
AB1D759A245DD18100671525 /* MapProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapProtocol.swift; sourceTree = "<group>"; };
|
|
||||||
AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TwoPlayerDefaultTestMap.swift; sourceTree = "<group>"; };
|
AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TwoPlayerDefaultTestMap.swift; sourceTree = "<group>"; };
|
||||||
AB1D759F245DEC0500671525 /* MapFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapFactory.swift; sourceTree = "<group>"; };
|
AB1D759F245DEC0500671525 /* MapFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapFactory.swift; sourceTree = "<group>"; };
|
||||||
|
AB21D7D4246C748A00B09CBA /* TwoPlayerMapGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoPlayerMapGenerator.swift; sourceTree = "<group>"; };
|
||||||
|
AB9403892471528D004FCD07 /* SampleCElement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleCElement.swift; sourceTree = "<group>"; };
|
||||||
ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = "<group>"; };
|
ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = "<group>"; };
|
||||||
AE151588245F18EF001D363E /* MatchmakingHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatchmakingHelper.swift; sourceTree = "<group>"; };
|
AE151588245F18EF001D363E /* MatchmakingHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatchmakingHelper.swift; sourceTree = "<group>"; };
|
||||||
AEBF3AFE246EB146004F7CD5 /* CancelBtnNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CancelBtnNode.swift; sourceTree = "<group>"; };
|
AEBF3AFE246EB146004F7CD5 /* CancelBtnNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CancelBtnNode.swift; sourceTree = "<group>"; };
|
||||||
@ -297,9 +299,10 @@
|
|||||||
AB1D759E245DD2EA00671525 /* Map */ = {
|
AB1D759E245DD2EA00671525 /* Map */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
AB1D759A245DD18100671525 /* MapProtocol.swift */,
|
|
||||||
AB1D759F245DEC0500671525 /* MapFactory.swift */,
|
AB1D759F245DEC0500671525 /* MapFactory.swift */,
|
||||||
AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */,
|
AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */,
|
||||||
|
AB21D7D4246C748A00B09CBA /* TwoPlayerMapGenerator.swift */,
|
||||||
|
AB9403892471528D004FCD07 /* SampleCElement.swift */,
|
||||||
);
|
);
|
||||||
path = Map;
|
path = Map;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -429,6 +432,7 @@
|
|||||||
AE151589245F18EF001D363E /* MatchmakingHelper.swift in Sources */,
|
AE151589245F18EF001D363E /* MatchmakingHelper.swift in Sources */,
|
||||||
11036113244B3E30008610AF /* MenuScene.swift in Sources */,
|
11036113244B3E30008610AF /* MenuScene.swift in Sources */,
|
||||||
C099579C246C5E5C0016AA22 /* DataService.swift in Sources */,
|
C099579C246C5E5C0016AA22 /* DataService.swift in Sources */,
|
||||||
|
AB21D7D5246C748A00B09CBA /* TwoPlayerMapGenerator.swift in Sources */,
|
||||||
9EA3ABE9245C6DAA006BC61D /* DefaultBaseComponent.swift in Sources */,
|
9EA3ABE9245C6DAA006BC61D /* DefaultBaseComponent.swift in Sources */,
|
||||||
9E174C8A245E1A0A00209FF0 /* Background.swift in Sources */,
|
9E174C8A245E1A0A00209FF0 /* Background.swift in Sources */,
|
||||||
9EA3ABED245C8143006BC61D /* ModalBackgroundComponent.swift in Sources */,
|
9EA3ABED245C8143006BC61D /* ModalBackgroundComponent.swift in Sources */,
|
||||||
@ -453,6 +457,7 @@
|
|||||||
9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */,
|
9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */,
|
||||||
9E78ACC2245CC9EE00526FF7 /* DefBoostSkillComponent.swift in Sources */,
|
9E78ACC2245CC9EE00526FF7 /* DefBoostSkillComponent.swift in Sources */,
|
||||||
C05FAED62468559D0006AF2E /* SoundManager.swift in Sources */,
|
C05FAED62468559D0006AF2E /* SoundManager.swift in Sources */,
|
||||||
|
AB94038A2471528D004FCD07 /* SampleCElement.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
@ -8,8 +8,30 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import SpriteKit
|
import SpriteKit
|
||||||
|
import os
|
||||||
|
|
||||||
|
protocol MapProtocol {
|
||||||
|
var size: CGSize! {get set}
|
||||||
|
var entityManager: EntityManager! {get set}
|
||||||
|
|
||||||
|
init(scene: SKScene, entityManager: EntityManager)
|
||||||
|
|
||||||
|
func load()
|
||||||
|
}
|
||||||
|
|
||||||
|
protocol CenterElementProtocol {
|
||||||
|
|
||||||
|
init(frame: CGRect)
|
||||||
|
|
||||||
|
func getAllBases() -> [Base]
|
||||||
|
func getTopConnection() -> Base?
|
||||||
|
func getRightConnection() -> Base?
|
||||||
|
func getBottomConnection() -> Base?
|
||||||
|
func getLeftConnection() -> Base?
|
||||||
|
}
|
||||||
|
|
||||||
class MapFactory {
|
class MapFactory {
|
||||||
|
let LOG = OSLog.init(subsystem: "MapGenerator", category: "MapFactory")
|
||||||
|
|
||||||
var twoPlayerMaps: [MapProtocol]!
|
var twoPlayerMaps: [MapProtocol]!
|
||||||
var threePlayerMaps: [MapProtocol]!
|
var threePlayerMaps: [MapProtocol]!
|
||||||
@ -17,7 +39,7 @@ class MapFactory {
|
|||||||
|
|
||||||
init(scene: SKScene, entityManager: EntityManager) {
|
init(scene: SKScene, entityManager: EntityManager) {
|
||||||
self.twoPlayerMaps = [
|
self.twoPlayerMaps = [
|
||||||
TwoPlayerDefaultTestMap(scene: scene, entityManager: entityManager)
|
TwoPlayerMapGenerator(scene: scene, entityManager: entityManager)
|
||||||
]
|
]
|
||||||
|
|
||||||
self.threePlayerMaps = [MapProtocol]()
|
self.threePlayerMaps = [MapProtocol]()
|
||||||
@ -26,11 +48,30 @@ class MapFactory {
|
|||||||
|
|
||||||
func loadMap(playerCount: Int) {
|
func loadMap(playerCount: Int) {
|
||||||
if playerCount == 2 {
|
if playerCount == 2 {
|
||||||
|
os_log("Loading two player map", log: LOG, type: .info)
|
||||||
twoPlayerMaps.randomElement()?.load()
|
twoPlayerMaps.randomElement()?.load()
|
||||||
} else if playerCount == 3 {
|
} else if playerCount == 3 {
|
||||||
|
os_log("Loading three player map", log: LOG, type: .info)
|
||||||
threePlayerMaps.randomElement()?.load()
|
threePlayerMaps.randomElement()?.load()
|
||||||
} else {
|
} else {
|
||||||
|
os_log("Loading four player map", log: LOG, type: .info)
|
||||||
fourPlayerMaps.randomElement()?.load()
|
fourPlayerMaps.randomElement()?.load()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CenterElementProvider {
|
||||||
|
static let LOG = OSLog.init(subsystem: "MapGenerator", category: "CenterElementProvider")
|
||||||
|
|
||||||
|
static func get(frame: CGRect) -> CenterElementProtocol {
|
||||||
|
// TODO: Implemented by Jakob
|
||||||
|
os_log("Getting new center element from provider", log: LOG, type: .info)
|
||||||
|
|
||||||
|
let centerElements: [CenterElementProtocol.Type] = [
|
||||||
|
SampleCElement.self,
|
||||||
|
CElement7.self
|
||||||
|
]
|
||||||
|
|
||||||
|
return centerElements.randomElement()!.init(frame: frame)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
//
|
|
||||||
// MapProtocoll.swift
|
|
||||||
// GoldWars
|
|
||||||
//
|
|
||||||
// Created by Marcel Schwarz on 02.05.20.
|
|
||||||
// Copyright © 2020 SP2. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
import Foundation
|
|
||||||
import SpriteKit
|
|
||||||
|
|
||||||
protocol MapProtocol {
|
|
||||||
|
|
||||||
var size: CGSize! {get set}
|
|
||||||
var entityManager: EntityManager! {get set}
|
|
||||||
|
|
||||||
init(scene: SKScene, entityManager: EntityManager)
|
|
||||||
|
|
||||||
func load()
|
|
||||||
}
|
|
123
GoldWars/GoldWars/Map/SampleCElement.swift
Normal file
123
GoldWars/GoldWars/Map/SampleCElement.swift
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
//
|
||||||
|
// CElemente.swift
|
||||||
|
// GoldWars
|
||||||
|
//
|
||||||
|
// Created by Jakob Haag on 14.05.20.
|
||||||
|
// Copyright © 2020 SP2. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import SpriteKit
|
||||||
|
|
||||||
|
class SampleCElement : CenterElementProtocol {
|
||||||
|
var frame: CGRect
|
||||||
|
var bases: [Base] = []
|
||||||
|
var centerBase: Base
|
||||||
|
|
||||||
|
required init(frame: CGRect) {
|
||||||
|
self.frame = frame
|
||||||
|
self.centerBase = Base(
|
||||||
|
position: CGPoint(
|
||||||
|
x: frame.midX,
|
||||||
|
y: frame.midY
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.bases.append(centerBase)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAllBases() -> [Base] {
|
||||||
|
return self.bases
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTopConnection() -> Base? {
|
||||||
|
return self.centerBase
|
||||||
|
}
|
||||||
|
|
||||||
|
func getRightConnection() -> Base? {
|
||||||
|
return self.centerBase
|
||||||
|
}
|
||||||
|
|
||||||
|
func getBottomConnection() -> Base? {
|
||||||
|
return self.centerBase
|
||||||
|
}
|
||||||
|
|
||||||
|
func getLeftConnection() -> Base? {
|
||||||
|
return self.centerBase
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// CElement7.swift
|
||||||
|
// GoldWars
|
||||||
|
//
|
||||||
|
// Created by Jakob Haag on 14.05.20.
|
||||||
|
// Copyright © 2020 SP2. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import SpriteKit
|
||||||
|
|
||||||
|
class CElement7 : CenterElementProtocol {
|
||||||
|
var frame: CGRect
|
||||||
|
var bases: [Base] = []
|
||||||
|
var topBase: Base
|
||||||
|
var bottomBase: Base
|
||||||
|
var leftBase: Base
|
||||||
|
var rightBase: Base
|
||||||
|
|
||||||
|
required init(frame: CGRect) {
|
||||||
|
self.frame = frame
|
||||||
|
self.topBase = Base(
|
||||||
|
position: CGPoint(
|
||||||
|
x: frame.midX,
|
||||||
|
y: frame.minY
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.bottomBase = Base(
|
||||||
|
position: CGPoint(
|
||||||
|
x: frame.midX,
|
||||||
|
y: frame.maxY
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.leftBase = Base(
|
||||||
|
position: CGPoint(
|
||||||
|
x: frame.minX,
|
||||||
|
y: frame.midY
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.rightBase = Base(
|
||||||
|
position: CGPoint(
|
||||||
|
x: frame.maxX,
|
||||||
|
y: frame.midY
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.bases.append(topBase)
|
||||||
|
self.bases.append(bottomBase)
|
||||||
|
self.bases.append(leftBase)
|
||||||
|
self.bases.append(rightBase)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAllBases() -> [Base] {
|
||||||
|
return self.bases
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTopConnection() -> Base? {
|
||||||
|
return self.topBase
|
||||||
|
}
|
||||||
|
|
||||||
|
func getRightConnection() -> Base? {
|
||||||
|
return self.rightBase
|
||||||
|
}
|
||||||
|
|
||||||
|
func getBottomConnection() -> Base? {
|
||||||
|
return self.bottomBase
|
||||||
|
}
|
||||||
|
|
||||||
|
func getLeftConnection() -> Base? {
|
||||||
|
return self.leftBase
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
213
GoldWars/GoldWars/Map/TwoPlayerMapGenerator.swift
Normal file
213
GoldWars/GoldWars/Map/TwoPlayerMapGenerator.swift
Normal file
@ -0,0 +1,213 @@
|
|||||||
|
//
|
||||||
|
// TwoPlayerMapGenerator.swift
|
||||||
|
// GoldWars
|
||||||
|
//
|
||||||
|
// Created by Marcel Schwarz on 13.05.20.
|
||||||
|
// Copyright © 2020 SP2. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import SpriteKit
|
||||||
|
import GameKit
|
||||||
|
import os
|
||||||
|
|
||||||
|
class TwoPlayerMapGenerator: MapProtocol {
|
||||||
|
let LOG = OSLog.init(subsystem: "MapGenerator", category: "TwoPlayerMapGenerator")
|
||||||
|
|
||||||
|
var size: CGSize!
|
||||||
|
var entityManager: EntityManager!
|
||||||
|
|
||||||
|
required init(scene: SKScene, entityManager: EntityManager) {
|
||||||
|
self.size = scene.size
|
||||||
|
self.entityManager = entityManager
|
||||||
|
}
|
||||||
|
|
||||||
|
func load() {
|
||||||
|
os_log("Loading from TwoPlayerMapFactory", log: LOG, type: .info)
|
||||||
|
|
||||||
|
// Generate bases structure
|
||||||
|
os_log("Get player one base", log: LOG, type: .info)
|
||||||
|
let basePlayerOne = Base(
|
||||||
|
position: CGPoint(x: self.size.width * 0.07, y: self.size.height / 2),
|
||||||
|
player: (MatchmakingHelper.sharedInstance.isServer) ? GKLocalPlayer.local : MatchmakingHelper.sharedInstance.mpMatch?.players[0],
|
||||||
|
team: .team1
|
||||||
|
)
|
||||||
|
|
||||||
|
os_log("Get player one's startbases", log: LOG, type: .info)
|
||||||
|
|
||||||
|
let p1StartBaseCount = Int.random(in: 1...3)
|
||||||
|
var p1StartBases = [String: Base]()
|
||||||
|
|
||||||
|
if (p1StartBaseCount == 1) {
|
||||||
|
p1StartBases["mid"] = Base(position: CGPoint(x: self.size.width * 0.2, y: self.size.height * 0.5))
|
||||||
|
} else if (p1StartBaseCount == 2) {
|
||||||
|
p1StartBases["top"] = Base(position: CGPoint(x: self.size.width * 0.2, y: self.size.height * 0.333))
|
||||||
|
p1StartBases["bot"] = Base(position: CGPoint(x: self.size.width * 0.2, y: self.size.height * 0.666))
|
||||||
|
} else {
|
||||||
|
p1StartBases["top"] = Base(position: CGPoint(x: self.size.width * 0.2, y: self.size.height * 0.25))
|
||||||
|
p1StartBases["mid"] = Base(position: CGPoint(x: self.size.width * 0.2, y: self.size.height * 0.5))
|
||||||
|
p1StartBases["bot"] = Base(position: CGPoint(x: self.size.width * 0.2, y: self.size.height * 0.75))
|
||||||
|
}
|
||||||
|
|
||||||
|
os_log("Generate Map center", log: LOG, type: .info)
|
||||||
|
let gridCellWidth = self.size.width * 0.2
|
||||||
|
let gridCellHeight = self.size.height * 0.4
|
||||||
|
let cellInsetX = CGFloat(self.size.width * 0.05)
|
||||||
|
let cellInsetY = CGFloat(self.size.height * 0.07)
|
||||||
|
|
||||||
|
let gridTopLeft = CGRect(
|
||||||
|
x: self.size.width * 0.3,
|
||||||
|
y: self.size.height * 0.1,
|
||||||
|
width: gridCellWidth,
|
||||||
|
height: gridCellHeight
|
||||||
|
).insetBy(dx: cellInsetX, dy: cellInsetY)
|
||||||
|
|
||||||
|
let gridTopRight = CGRect(
|
||||||
|
x: self.size.width * 0.3,
|
||||||
|
y: self.size.height * 0.5,
|
||||||
|
width: gridCellWidth,
|
||||||
|
height: gridCellHeight
|
||||||
|
).insetBy(dx: cellInsetX, dy: cellInsetY)
|
||||||
|
|
||||||
|
let gridBottomLeft = CGRect(
|
||||||
|
x: self.size.width * 0.5,
|
||||||
|
y: self.size.height * 0.1,
|
||||||
|
width: gridCellWidth,
|
||||||
|
height: gridCellHeight
|
||||||
|
).insetBy(dx: cellInsetX, dy: cellInsetY)
|
||||||
|
|
||||||
|
let gridBottomRight = CGRect(
|
||||||
|
x: self.size.width * 0.5,
|
||||||
|
y: self.size.height * 0.5,
|
||||||
|
width: gridCellWidth,
|
||||||
|
height: gridCellHeight
|
||||||
|
).insetBy(dx: cellInsetX, dy: cellInsetY)
|
||||||
|
|
||||||
|
let topLeft = CenterElementProvider.get(frame: gridTopLeft)
|
||||||
|
let topRight = CenterElementProvider.get(frame: gridTopRight)
|
||||||
|
let bottomLeft = CenterElementProvider.get(frame: gridBottomLeft)
|
||||||
|
let bottomRight = CenterElementProvider.get(frame: gridBottomRight)
|
||||||
|
|
||||||
|
os_log("Get player two base", log: LOG, type: .info)
|
||||||
|
let basePlayerTwo = Base(
|
||||||
|
position: CGPoint(x: self.size.width * 0.93, y: self.size.height / 2),
|
||||||
|
player: (!MatchmakingHelper.sharedInstance.isServer) ? GKLocalPlayer.local : MatchmakingHelper.sharedInstance.mpMatch?.players[0],
|
||||||
|
team: .team2
|
||||||
|
)
|
||||||
|
|
||||||
|
os_log("Get player two's startbases", log: LOG, type: .info)
|
||||||
|
let p2StartBaseCount = Int.random(in: 1...3)
|
||||||
|
var p2StartBases = [String: Base]()
|
||||||
|
|
||||||
|
if (p2StartBaseCount == 1) {
|
||||||
|
p2StartBases["mid"] = Base(position: CGPoint(x: self.size.width * 0.8, y: self.size.height * 0.5))
|
||||||
|
} else if (p1StartBaseCount == 2) {
|
||||||
|
p2StartBases["top"] = Base(position: CGPoint(x: self.size.width * 0.8, y: self.size.height * 0.333))
|
||||||
|
p2StartBases["bot"] = Base(position: CGPoint(x: self.size.width * 0.8, y: self.size.height * 0.666))
|
||||||
|
} else {
|
||||||
|
p2StartBases["top"] = Base(position: CGPoint(x: self.size.width * 0.8, y: self.size.height * 0.25))
|
||||||
|
p2StartBases["mid"] = Base(position: CGPoint(x: self.size.width * 0.8, y: self.size.height * 0.5))
|
||||||
|
p2StartBases["bot"] = Base(position: CGPoint(x: self.size.width * 0.8, y: self.size.height * 0.75))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create adjacency mapping
|
||||||
|
os_log("Connecting base p1 and start bases", log: LOG, type: .info)
|
||||||
|
basePlayerOne.adjacencyList.append(contentsOf: p1StartBases.values)
|
||||||
|
p1StartBases.values.forEach({base in base.adjacencyList.append(basePlayerOne)})
|
||||||
|
|
||||||
|
if (p1StartBases["top"] != nil && topLeft.getLeftConnection() != nil) {
|
||||||
|
os_log("Connecting p1 startbase top with topLeft segment", log: LOG, type: .info)
|
||||||
|
p1StartBases["top"]!.adjacencyList.append(topLeft.getLeftConnection()!)
|
||||||
|
topLeft.getLeftConnection()!.adjacencyList.append(p1StartBases["top"]!)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p1StartBases["mid"] != nil) {
|
||||||
|
if (topLeft.getLeftConnection() != nil) {
|
||||||
|
os_log("Connecting p1 startbase mid with topLeft segment", log: LOG, type: .info)
|
||||||
|
p1StartBases["mid"]!.adjacencyList.append(topLeft.getLeftConnection()!)
|
||||||
|
topLeft.getLeftConnection()!.adjacencyList.append(p1StartBases["mid"]!)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bottomLeft.getLeftConnection() != nil) {
|
||||||
|
os_log("Connecting p1 startbase mid with bottomLeft segment", log: LOG, type: .info)
|
||||||
|
p1StartBases["mid"]!.adjacencyList.append(bottomLeft.getLeftConnection()!)
|
||||||
|
bottomLeft.getLeftConnection()!.adjacencyList.append(p1StartBases["mid"]!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p1StartBases["bot"] != nil && bottomLeft.getLeftConnection() != nil) {
|
||||||
|
os_log("Connecting p1 startbase bot with bottomLeft segment", log: LOG, type: .info)
|
||||||
|
p1StartBases["bot"]!.adjacencyList.append(bottomLeft.getLeftConnection()!)
|
||||||
|
bottomLeft.getLeftConnection()!.adjacencyList.append(p1StartBases["bot"]!)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (topLeft.getRightConnection() != nil && topRight.getLeftConnection() != nil) {
|
||||||
|
os_log("Connecting topLeft with topRight segment horizontally", log: LOG, type: .info)
|
||||||
|
topLeft.getRightConnection()!.adjacencyList.append(topRight.getLeftConnection()!)
|
||||||
|
topRight.getLeftConnection()!.adjacencyList.append(topLeft.getRightConnection()!)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bottomLeft.getRightConnection() != nil && bottomRight.getLeftConnection() != nil) {
|
||||||
|
os_log("Connecting bottomLeft with bottomRight segment horizontally", log: LOG, type: .info)
|
||||||
|
bottomLeft.getRightConnection()!.adjacencyList.append(bottomRight.getLeftConnection()!)
|
||||||
|
bottomRight.getLeftConnection()!.adjacencyList.append(bottomLeft.getRightConnection()!)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (topLeft.getBottomConnection() != nil && bottomLeft.getTopConnection() != nil) {
|
||||||
|
os_log("Connecting topLeft with bottomLeft segment vertically", log: LOG, type: .info)
|
||||||
|
topLeft.getBottomConnection()!.adjacencyList.append(bottomLeft.getTopConnection()!)
|
||||||
|
bottomLeft.getTopConnection()!.adjacencyList.append(topLeft.getBottomConnection()!)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (topRight.getBottomConnection() != nil && bottomRight.getTopConnection() != nil) {
|
||||||
|
os_log("Connecting topRight with bottomRight segment vertically", log: LOG, type: .info)
|
||||||
|
topRight.getBottomConnection()!.adjacencyList.append(bottomRight.getTopConnection()!)
|
||||||
|
bottomRight.getTopConnection()!.adjacencyList.append(topRight.getBottomConnection()!)
|
||||||
|
}
|
||||||
|
|
||||||
|
os_log("Connecting base p2 and start bases", log: LOG, type: .info)
|
||||||
|
basePlayerTwo.adjacencyList.append(contentsOf: p2StartBases.values)
|
||||||
|
p2StartBases.values.forEach({base in base.adjacencyList.append(basePlayerTwo)})
|
||||||
|
|
||||||
|
if (p2StartBases["top"] != nil && topRight.getRightConnection() != nil) {
|
||||||
|
os_log("Connecting p2 startbase top with topRight segment", log: LOG, type: .info)
|
||||||
|
p2StartBases["top"]!.adjacencyList.append(topRight.getRightConnection()!)
|
||||||
|
topRight.getRightConnection()!.adjacencyList.append(p2StartBases["top"]!)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p2StartBases["mid"] != nil) {
|
||||||
|
if (topRight.getRightConnection() != nil) {
|
||||||
|
os_log("Connecting p2 startbase mid with topRight segment", log: LOG, type: .info)
|
||||||
|
p2StartBases["mid"]!.adjacencyList.append(topRight.getRightConnection()!)
|
||||||
|
topRight.getRightConnection()!.adjacencyList.append(p2StartBases["mid"]!)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bottomRight.getRightConnection() != nil) {
|
||||||
|
os_log("Connecting p2 startbase mid with bottomRight segment", log: LOG, type: .info)
|
||||||
|
p2StartBases["mid"]!.adjacencyList.append(bottomRight.getRightConnection()!)
|
||||||
|
bottomRight.getRightConnection()!.adjacencyList.append(p2StartBases["mid"]!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p2StartBases["bot"] != nil && bottomRight.getRightConnection() != nil) {
|
||||||
|
os_log("Connecting p2 startbase bot with bottomRight segment", log: LOG, type: .info)
|
||||||
|
p2StartBases["bot"]!.adjacencyList.append(bottomRight.getRightConnection()!)
|
||||||
|
bottomRight.getRightConnection()!.adjacencyList.append(p2StartBases["bot"]!)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Add all bases to the scene
|
||||||
|
entityManager.add(basePlayerOne)
|
||||||
|
p1StartBases.forEach({(key, base) in entityManager.add(base)})
|
||||||
|
|
||||||
|
topLeft.getAllBases().forEach({base in entityManager.add(base)})
|
||||||
|
topRight.getAllBases().forEach({base in entityManager.add(base)})
|
||||||
|
bottomLeft.getAllBases().forEach({base in entityManager.add(base)})
|
||||||
|
bottomRight.getAllBases().forEach({base in entityManager.add(base)})
|
||||||
|
|
||||||
|
entityManager.add(basePlayerTwo)
|
||||||
|
p2StartBases.forEach({(key, base) in entityManager.add(base)})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user