* Add 3 Instances for each Scene
* Refactor in Code that the right instances is called * Probs to Aldin und nicht an Niko, der nur im Bett liegt
This commit is contained in:
parent
8b140b95b4
commit
e447a37757
@ -18,7 +18,7 @@ class AtkBoostSkillComponent: GKComponent{
|
|||||||
isEnabled: isEnabled,
|
isEnabled: isEnabled,
|
||||||
position: position,
|
position: position,
|
||||||
onButtonPress: {
|
onButtonPress: {
|
||||||
var bases: Set<Base> = EntityManager.sharedInstance.getBasesByTeam(for: .team2)
|
var bases: Set<Base> = EntityManager.gameEMInstance.getBasesByTeam(for: .team2)
|
||||||
bases.forEach{ base in
|
bases.forEach{ base in
|
||||||
if(base.unitType == .Defence){
|
if(base.unitType == .Defence){
|
||||||
base.unitType = .AttackDefence
|
base.unitType = .AttackDefence
|
||||||
|
@ -13,12 +13,13 @@ class DefBoostSkillComponent: GKComponent{
|
|||||||
var skillButtonNode: SkillButtonNode
|
var skillButtonNode: SkillButtonNode
|
||||||
|
|
||||||
init(iconName: String, text: String, position: CGPoint, isEnabled:Bool) {
|
init(iconName: String, text: String, position: CGPoint, isEnabled:Bool) {
|
||||||
|
|
||||||
skillButtonNode = SkillButtonNode(iconName: iconName,
|
skillButtonNode = SkillButtonNode(iconName: iconName,
|
||||||
text: text,
|
text: text,
|
||||||
isEnabled: isEnabled,
|
isEnabled: isEnabled,
|
||||||
position: position,
|
position: position,
|
||||||
onButtonPress: {
|
onButtonPress: {
|
||||||
var bases: Set<Base> = EntityManager.sharedInstance.getBasesByTeam(for: .team2)
|
var bases: Set<Base> = EntityManager.gameEMInstance.getBasesByTeam(for: .team2)
|
||||||
bases.forEach{ base in
|
bases.forEach{ base in
|
||||||
if(base.unitType == .Attack){
|
if(base.unitType == .Attack){
|
||||||
base.unitType = .AttackDefence
|
base.unitType = .AttackDefence
|
||||||
|
@ -13,6 +13,7 @@ import GameKit
|
|||||||
|
|
||||||
class PlayerInfoComponent: GKComponent {
|
class PlayerInfoComponent: GKComponent {
|
||||||
|
|
||||||
|
var entityManager = EntityManager.gameEMInstance
|
||||||
var hostLabel:SKLabelNode
|
var hostLabel:SKLabelNode
|
||||||
var hostUnitsLabel:SKLabelNode
|
var hostUnitsLabel:SKLabelNode
|
||||||
|
|
||||||
@ -44,8 +45,8 @@ class PlayerInfoComponent: GKComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func update(){
|
func update(){
|
||||||
hostUnitsLabel.text = "\(EntityManager.sharedInstance.getUnitSum(by: host!))"
|
hostUnitsLabel.text = "\(entityManager.getUnitSum(by: host!))"
|
||||||
peerUnitsLabel.text = "\(EntityManager.sharedInstance.getUnitSum(by: peer!))"
|
peerUnitsLabel.text = "\(entityManager.getUnitSum(by: peer!))"
|
||||||
}
|
}
|
||||||
|
|
||||||
func setColor(labelNodes: [SKLabelNode]) -> Void {
|
func setColor(labelNodes: [SKLabelNode]) -> Void {
|
||||||
|
@ -43,6 +43,7 @@ class DataService {
|
|||||||
var snapshotModel: SnapshotModel?
|
var snapshotModel: SnapshotModel?
|
||||||
var gameHost: Host?
|
var gameHost: Host?
|
||||||
var mapModel: MapGenerationModel?
|
var mapModel: MapGenerationModel?
|
||||||
|
var entityManager = EntityManager.gameEMInstance
|
||||||
|
|
||||||
func addMove(playerMove: PlayerMove) {
|
func addMove(playerMove: PlayerMove) {
|
||||||
var equalMove = localPlayerMoves.filter { (ele) -> Bool in
|
var equalMove = localPlayerMoves.filter { (ele) -> Bool in
|
||||||
@ -73,6 +74,6 @@ class DataService {
|
|||||||
|
|
||||||
func setMapModel(model: MapGenerationModel) {
|
func setMapModel(model: MapGenerationModel) {
|
||||||
self.mapModel = model
|
self.mapModel = model
|
||||||
MapFactory(scene: EntityManager.sharedInstance.scene, entityManager: EntityManager.sharedInstance).loadMap(fromModel: DataService.sharedInstance.mapModel!)
|
MapFactory(scene: entityManager.scene, entityManager: entityManager).loadMap(fromModel: DataService.sharedInstance.mapModel!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,9 @@ import GameKit
|
|||||||
|
|
||||||
class EntityManager {
|
class EntityManager {
|
||||||
|
|
||||||
static let sharedInstance = EntityManager()
|
static let gameEMInstance = EntityManager()
|
||||||
|
static let menuEMInstance = EntityManager()
|
||||||
|
static let settingsEMInstance = EntityManager()
|
||||||
|
|
||||||
var entities = Set<GKEntity>()
|
var entities = Set<GKEntity>()
|
||||||
var scene: SKScene
|
var scene: SKScene
|
||||||
|
@ -10,6 +10,7 @@ import GameplayKit
|
|||||||
|
|
||||||
class Modal: GKEntity{
|
class Modal: GKEntity{
|
||||||
|
|
||||||
|
var entityManager = EntityManager.gameEMInstance
|
||||||
var unitCount:Int
|
var unitCount:Int
|
||||||
|
|
||||||
init(modaltype: ModalType, base: Base, anchorPoint: CGPoint, gameScene: GameScene, currentDraggedBase: Base?, touchLocation: CGPoint, collisionBase: Base?) {
|
init(modaltype: ModalType, base: Base, anchorPoint: CGPoint, gameScene: GameScene, currentDraggedBase: Base?, touchLocation: CGPoint, collisionBase: Base?) {
|
||||||
@ -42,9 +43,9 @@ class Modal: GKEntity{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func removeModalEntities(gameScene: SKScene){
|
func removeModalEntities(gameScene: SKScene){
|
||||||
for entity in EntityManager.sharedInstance.entities {
|
for entity in entityManager.entities {
|
||||||
if EntityManager.sharedInstance.isModal && entity.isMember(of: Modal.self) {
|
if entityManager.isModal && entity.isMember(of: Modal.self) {
|
||||||
EntityManager.sharedInstance.remove(entity)
|
entityManager.remove(entity)
|
||||||
}
|
}
|
||||||
for child in gameScene.children {
|
for child in gameScene.children {
|
||||||
if(child.name != "fire"){
|
if(child.name != "fire"){
|
||||||
@ -57,7 +58,7 @@ class Modal: GKEntity{
|
|||||||
func sendUnits(currentDraggedBase: Base?, touchLocation: CGPoint, gameScene: GameScene, collisionBase: Base?){
|
func sendUnits(currentDraggedBase: Base?, touchLocation: CGPoint, gameScene: GameScene, collisionBase: Base?){
|
||||||
for base in currentDraggedBase!.adjacencyList {
|
for base in currentDraggedBase!.adjacencyList {
|
||||||
if base == collisionBase {
|
if base == collisionBase {
|
||||||
EntityManager.sharedInstance.update((currentDraggedBase?.doPlayerMoveTypeToBase(base: base, playerMoveType: PlayerMoveType.AtkMove, units: Int(GameScene.sendUnits)))!)
|
entityManager.update((currentDraggedBase?.doPlayerMoveTypeToBase(base: base, playerMoveType: PlayerMoveType.AtkMove, units: Int(GameScene.sendUnits)))!)
|
||||||
GameScene.sendUnits = 0
|
GameScene.sendUnits = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,15 +17,15 @@ class GameViewController: UIViewController {
|
|||||||
|
|
||||||
if let view = self.view as! SKView? {
|
if let view = self.view as! SKView? {
|
||||||
let scene = MenuScene(size: self.view.bounds.size)
|
let scene = MenuScene(size: self.view.bounds.size)
|
||||||
|
EntityManager.menuEMInstance.setScene(scene: scene)
|
||||||
scene.scaleMode = .aspectFill
|
scene.scaleMode = .aspectFill
|
||||||
view.presentScene(scene)
|
view.presentScene(scene)
|
||||||
//TODO: create dev profile or remove on delivery
|
//TODO: create dev profile or remove on delivery
|
||||||
view.showsFPS = true
|
view.showsFPS = true
|
||||||
view.showsNodeCount = true
|
view.showsNodeCount = true
|
||||||
|
GameCenterHelper.helper.viewController = self
|
||||||
GameCenterHelper.helper.viewController = self
|
MatchmakingHelper.sharedInstance.viewController = self
|
||||||
MatchmakingHelper.sharedInstance.viewController = self
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override var shouldAutorotate: Bool {
|
override var shouldAutorotate: Bool {
|
||||||
|
@ -37,6 +37,7 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
|
|||||||
var nameSpieler1 = ""
|
var nameSpieler1 = ""
|
||||||
var menusc: MenuScene?
|
var menusc: MenuScene?
|
||||||
let localPlayer: GKLocalPlayer = GKLocalPlayer.local
|
let localPlayer: GKLocalPlayer = GKLocalPlayer.local
|
||||||
|
var entityManager = EntityManager.gameEMInstance
|
||||||
|
|
||||||
static let sharedInstance = MatchmakingHelper()
|
static let sharedInstance = MatchmakingHelper()
|
||||||
|
|
||||||
@ -119,8 +120,8 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
|
|||||||
|
|
||||||
if let snapshotModel = try? jsonDecoder.decode(SnapshotModel.self, from: data) {
|
if let snapshotModel = try? jsonDecoder.decode(SnapshotModel.self, from: data) {
|
||||||
DataService.sharedInstance.snapshotModel = snapshotModel
|
DataService.sharedInstance.snapshotModel = snapshotModel
|
||||||
EntityManager.sharedInstance.updateSnapshotModel(snapshotModel: snapshotModel)
|
entityManager.updateSnapshotModel(snapshotModel: snapshotModel)
|
||||||
EntityManager.sharedInstance.getTimer().startWithDuration(duration: 31)
|
entityManager.getTimer().startWithDuration(duration: 31)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let mapModel = try? jsonDecoder.decode(MapGenerationModel.self, from: data) {
|
if let mapModel = try? jsonDecoder.decode(MapGenerationModel.self, from: data) {
|
||||||
@ -182,7 +183,9 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.delegate?.matchStarted()
|
self.delegate?.matchStarted()
|
||||||
self.menusc!.loadScene(scene: GameScene(size: self.menusc!.size))
|
let scene = GameScene(size: self.menusc!.size)
|
||||||
|
self.entityManager.setScene(scene: scene)
|
||||||
|
self.menusc!.loadScene(scene: scene)
|
||||||
MultiplayerNetwork.sharedInstance.sendHostIdentifier()
|
MultiplayerNetwork.sharedInstance.sendHostIdentifier()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -11,20 +11,20 @@ import Foundation
|
|||||||
import GameKit
|
import GameKit
|
||||||
|
|
||||||
class MultiplayerNetwork{
|
class MultiplayerNetwork{
|
||||||
static let sharedInstance = MultiplayerNetwork()
|
static let sharedInstance = MultiplayerNetwork()
|
||||||
|
|
||||||
var isSending = false
|
var isSending = false
|
||||||
|
|
||||||
func sendData(data: Data) {
|
func sendData(data: Data) {
|
||||||
let mmHelper = MatchmakingHelper.sharedInstance
|
let mmHelper = MatchmakingHelper.sharedInstance
|
||||||
if let multiplayerMatch = mmHelper.mpMatch {
|
if let multiplayerMatch = mmHelper.mpMatch {
|
||||||
do {
|
do {
|
||||||
try multiplayerMatch.sendData(toAllPlayers: data, with: .reliable)
|
try multiplayerMatch.sendData(toAllPlayers: data, with: .reliable)
|
||||||
} catch {
|
} catch {
|
||||||
//TODO: Add logging
|
//TODO: Add logging
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendDataToHost(data: Data) {
|
func sendDataToHost(data: Data) {
|
||||||
let mmHelper = MatchmakingHelper.sharedInstance
|
let mmHelper = MatchmakingHelper.sharedInstance
|
||||||
@ -38,7 +38,7 @@ class MultiplayerNetwork{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendPlayerMoves(playerMoves: [PlayerMove]) {
|
func sendPlayerMoves(playerMoves: [PlayerMove]) {
|
||||||
if MatchmakingHelper.sharedInstance.isServer == false {
|
if MatchmakingHelper.sharedInstance.isServer == false {
|
||||||
self.isSending = true
|
self.isSending = true
|
||||||
@ -47,7 +47,7 @@ class MultiplayerNetwork{
|
|||||||
sendDataToHost(data: encoded)
|
sendDataToHost(data: encoded)
|
||||||
DataService.sharedInstance.localPlayerMoves.removeAll()
|
DataService.sharedInstance.localPlayerMoves.removeAll()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendHostIdentifier() {
|
func sendHostIdentifier() {
|
||||||
let encoder = JSONEncoder()
|
let encoder = JSONEncoder()
|
||||||
@ -66,5 +66,5 @@ class MultiplayerNetwork{
|
|||||||
let encoded = (try? encoder.encode(mapModel))!
|
let encoded = (try? encoder.encode(mapModel))!
|
||||||
sendData(data: encoded)
|
sendData(data: encoded)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ class RoundCalculatorService {
|
|||||||
|
|
||||||
var allPlayerMoves: [String: [PlayerMove]] = [:]
|
var allPlayerMoves: [String: [PlayerMove]] = [:]
|
||||||
var baseSpecificMoves: [Int: [String: [PlayerMove]]] = [:]
|
var baseSpecificMoves: [Int: [String: [PlayerMove]]] = [:]
|
||||||
|
var entityManager = EntityManager.gameEMInstance
|
||||||
|
|
||||||
var isCalculating = false
|
var isCalculating = false
|
||||||
|
|
||||||
@ -110,9 +111,9 @@ class RoundCalculatorService {
|
|||||||
DataService.sharedInstance.localPlayerMoves.removeAll()
|
DataService.sharedInstance.localPlayerMoves.removeAll()
|
||||||
MultiplayerNetwork.sharedInstance.sendSnapshotModelToPlayers()
|
MultiplayerNetwork.sharedInstance.sendSnapshotModelToPlayers()
|
||||||
DataService.sharedInstance.snapshotModel = currentSnapshotModel
|
DataService.sharedInstance.snapshotModel = currentSnapshotModel
|
||||||
EntityManager.sharedInstance.updateSnapshotModel(snapshotModel: currentSnapshotModel!)
|
entityManager.updateSnapshotModel(snapshotModel: currentSnapshotModel!)
|
||||||
sleep(1)
|
sleep(1)
|
||||||
EntityManager.sharedInstance.getTimer().startWithDuration(duration: 31)
|
entityManager.getTimer().startWithDuration(duration: 31)
|
||||||
os_log("Finished calculating Round", log: RoundCalculatorService.LOG, type: .info)
|
os_log("Finished calculating Round", log: RoundCalculatorService.LOG, type: .info)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,26 +12,28 @@ import GameKit
|
|||||||
|
|
||||||
class GameScene: SKScene{
|
class GameScene: SKScene{
|
||||||
|
|
||||||
|
var entityManager = EntityManager.gameEMInstance
|
||||||
|
|
||||||
var isMoveTouch = false
|
var isMoveTouch = false
|
||||||
var currentDraggedBase : Base?
|
var currentDraggedBase : Base?
|
||||||
static var sendUnits: CGFloat = 0
|
static var sendUnits: CGFloat = 0
|
||||||
var collisionBase: Base?
|
var collisionBase: Base?
|
||||||
|
|
||||||
override func sceneDidLoad() {
|
override func sceneDidLoad() {
|
||||||
EntityManager.sharedInstance.setScene(scene: self)
|
entityManager.setScene(scene: self)
|
||||||
EntityManager.sharedInstance.add(HUD(size: self.size))
|
entityManager.add(HUD(size: self.size))
|
||||||
EntityManager.sharedInstance.add(Background(size: self.size))
|
entityManager.add(Background(size: self.size))
|
||||||
initMap()
|
initMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
func initMap() {
|
func initMap() {
|
||||||
if (DataService.sharedInstance.gameHost?.playerName == GKLocalPlayer.local.displayName) {
|
if (DataService.sharedInstance.gameHost?.playerName == GKLocalPlayer.local.displayName) {
|
||||||
let mapModel = MapFactory(scene: self, entityManager: EntityManager.sharedInstance).loadMap()
|
let mapModel = MapFactory(scene: self, entityManager: entityManager).loadMap()
|
||||||
MultiplayerNetwork.sharedInstance.sendMapModelToPlayers(mapModel: mapModel)
|
MultiplayerNetwork.sharedInstance.sendMapModelToPlayers(mapModel: mapModel)
|
||||||
DataService.sharedInstance.setSnapshotModel(snapshotModel: EntityManager.sharedInstance.getSnapshotModel())
|
DataService.sharedInstance.setSnapshotModel(snapshotModel: entityManager.getSnapshotModel())
|
||||||
}
|
}
|
||||||
if CommandLine.arguments.contains("--no-matchmaking") {
|
if CommandLine.arguments.contains("--no-matchmaking") {
|
||||||
MapFactory(scene: self, entityManager: EntityManager.sharedInstance).loadMap()
|
_ = MapFactory(scene: self, entityManager: entityManager).loadMap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +52,7 @@ class GameScene: SKScene{
|
|||||||
addAttackDetails(touchLocation: touchLocation)
|
addAttackDetails(touchLocation: touchLocation)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for entity in EntityManager.sharedInstance.entities {
|
for entity in entityManager.entities {
|
||||||
let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode
|
let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode
|
||||||
|
|
||||||
//FIXME: this is confusing
|
//FIXME: this is confusing
|
||||||
@ -73,18 +75,18 @@ class GameScene: SKScene{
|
|||||||
}
|
}
|
||||||
checkSlider()
|
checkSlider()
|
||||||
|
|
||||||
let bases = EntityManager.sharedInstance.getBasesByPlayer(for: GKLocalPlayer.local)
|
let bases = entityManager.getBasesByPlayer(for: GKLocalPlayer.local)
|
||||||
|
|
||||||
checkBases(bases: bases, touchLocation: touchLocation)
|
checkBases(bases: bases, touchLocation: touchLocation)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func update(_ currentTime: TimeInterval) {
|
override func update(_ currentTime: TimeInterval) {
|
||||||
EntityManager.sharedInstance.getBackground()?.update(deltaTime: currentTime)
|
entityManager.getBackground()?.update(deltaTime: currentTime)
|
||||||
EntityManager.sharedInstance.getHUD()?.component(ofType: TimerComponent.self)?.update()
|
entityManager.getHUD()?.component(ofType: TimerComponent.self)?.update()
|
||||||
}
|
}
|
||||||
|
|
||||||
func addBaseDetails(touchLocation: CGPoint, spriteNode: SKNode?, touches: Set<UITouch>, event: UIEvent?, entity: GKEntity){
|
func addBaseDetails(touchLocation: CGPoint, spriteNode: SKNode?, touches: Set<UITouch>, event: UIEvent?, entity: GKEntity){
|
||||||
if atPoint(touchLocation) == spriteNode && !EntityManager.sharedInstance.isModal {
|
if atPoint(touchLocation) == spriteNode && !entityManager.isModal {
|
||||||
spriteNode?.touchesBegan(touches, with: event)
|
spriteNode?.touchesBegan(touches, with: event)
|
||||||
if let baseEntity = entity as? Base {
|
if let baseEntity = entity as? Base {
|
||||||
if baseEntity.ownershipPlayer == GKLocalPlayer.local {
|
if baseEntity.ownershipPlayer == GKLocalPlayer.local {
|
||||||
@ -93,11 +95,11 @@ class GameScene: SKScene{
|
|||||||
child.alpha = 0.3
|
child.alpha = 0.3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EntityManager.sharedInstance.add(Modal(modaltype: .BaseDetails,
|
entityManager.add(Modal(modaltype: .BaseDetails,
|
||||||
base: entity as! Base,
|
base: entity as! Base,
|
||||||
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),
|
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),
|
||||||
gameScene: self,
|
gameScene: self,
|
||||||
currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase))
|
currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -110,10 +112,10 @@ class GameScene: SKScene{
|
|||||||
collisionBase = base
|
collisionBase = base
|
||||||
// TODO: change interaction based on collision instead of touchlocation
|
// TODO: change interaction based on collision instead of touchlocation
|
||||||
if currentDraggedBase!.unitCount > 1 {
|
if currentDraggedBase!.unitCount > 1 {
|
||||||
EntityManager.sharedInstance.add(Modal(modaltype: .BaseAttack,
|
entityManager.add(Modal(modaltype: .BaseAttack,
|
||||||
base: currentDraggedBase!,
|
base: currentDraggedBase!,
|
||||||
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),
|
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),
|
||||||
gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase))
|
gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase))
|
||||||
GameScene.sendUnits = CGFloat(currentDraggedBase!.unitCount / 2)
|
GameScene.sendUnits = CGFloat(currentDraggedBase!.unitCount / 2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -121,7 +123,7 @@ class GameScene: SKScene{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkSlider(){
|
func checkSlider(){
|
||||||
for e in EntityManager.sharedInstance.entities{
|
for e in entityManager.entities{
|
||||||
if let body = e.component(ofType: ModalContentComponent.self)?.body{
|
if let body = e.component(ofType: ModalContentComponent.self)?.body{
|
||||||
GameScene.sendUnits = ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up)
|
GameScene.sendUnits = ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up)
|
||||||
|
|
||||||
|
@ -9,12 +9,15 @@
|
|||||||
import SpriteKit
|
import SpriteKit
|
||||||
import SceneKit
|
import SceneKit
|
||||||
class MenuScene: SKScene {
|
class MenuScene: SKScene {
|
||||||
|
|
||||||
|
var entityManager = EntityManager.menuEMInstance
|
||||||
|
|
||||||
override func sceneDidLoad() {
|
override func sceneDidLoad() {
|
||||||
EntityManager.sharedInstance.setScene(scene: self)
|
|
||||||
|
entityManager.setScene(scene: self)
|
||||||
let midX = self.size.width / 2
|
let midX = self.size.width / 2
|
||||||
let midY = self.size.height / 2
|
let midY = self.size.height / 2
|
||||||
EntityManager.sharedInstance.add(Button(name: "startGameButton",
|
entityManager.add(Button(name: "startGameButton",
|
||||||
iconName: "",
|
iconName: "",
|
||||||
text: "Start Game",
|
text: "Start Game",
|
||||||
position: CGPoint(x: midX, y: midY),
|
position: CGPoint(x: midX, y: midY),
|
||||||
@ -26,15 +29,16 @@ class MenuScene: SKScene {
|
|||||||
MatchmakingHelper.sharedInstance.presentMatchmaker(scene: self)
|
MatchmakingHelper.sharedInstance.presentMatchmaker(scene: self)
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
EntityManager.sharedInstance.add(Button(name: "settingsButton",
|
entityManager.add(Button(name: "settingsButton",
|
||||||
iconName: "",
|
iconName: "",
|
||||||
text: "Settings",
|
text: "Settings",
|
||||||
position: CGPoint(x: midX, y: midY - 80 ),
|
position: CGPoint(x: midX, y: midY - 80 ),
|
||||||
onButtonPress: {
|
onButtonPress: {
|
||||||
self.loadScene(scene: SettingsScene(size: self.size))
|
let scene = SettingsScene(size: self.size)
|
||||||
|
self.loadScene(scene: scene)
|
||||||
}))
|
}))
|
||||||
EntityManager.sharedInstance.add(Background(size: self.size))
|
entityManager.add(Background(size: self.size))
|
||||||
EntityManager.sharedInstance.add(SpinningLogoEntity(position: CGPoint(x: midX, y: midY + 200)))
|
entityManager.add(SpinningLogoEntity(position: CGPoint(x: midX, y: midY + 200)))
|
||||||
|
|
||||||
if SoundManager.sharedInstance.isMusicPlaying == false && SoundManager.sharedInstance.isMusicEnabled == true {
|
if SoundManager.sharedInstance.isMusicPlaying == false && SoundManager.sharedInstance.isMusicEnabled == true {
|
||||||
SoundManager.sharedInstance.startMenuMusic()
|
SoundManager.sharedInstance.startMenuMusic()
|
||||||
@ -43,11 +47,14 @@ class MenuScene: SKScene {
|
|||||||
|
|
||||||
func loadScene(scene: SKScene) {
|
func loadScene(scene: SKScene) {
|
||||||
let transition = SKTransition.flipVertical(withDuration: 0.5)
|
let transition = SKTransition.flipVertical(withDuration: 0.5)
|
||||||
|
entityManager.entities.removeAll()
|
||||||
self.view?.presentScene(scene, transition: transition)
|
self.view?.presentScene(scene, transition: transition)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func update(_ currentTime: TimeInterval) {
|
override func update(_ currentTime: TimeInterval) {
|
||||||
EntityManager.sharedInstance.getBackground()!.update(deltaTime: currentTime)
|
if entityManager.entities.count != 0 {
|
||||||
EntityManager.sharedInstance.getButtonByName(buttonName: "startGameButton").component(ofType: ButtonComponent.self)?.buttonNode.isEnabled = GameCenterHelper.isAuthenticated
|
entityManager.getBackground()!.update(deltaTime: currentTime)
|
||||||
|
entityManager.getButtonByName(buttonName: "startGameButton").component(ofType: ButtonComponent.self)?.buttonNode.isEnabled = GameCenterHelper.isAuthenticated
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,19 +10,23 @@ import SpriteKit
|
|||||||
|
|
||||||
class SettingsScene: SKScene {
|
class SettingsScene: SKScene {
|
||||||
|
|
||||||
|
var entityManager = EntityManager.settingsEMInstance
|
||||||
|
|
||||||
override func sceneDidLoad() {
|
override func sceneDidLoad() {
|
||||||
EntityManager.sharedInstance.setScene(scene: self)
|
|
||||||
|
entityManager.setScene(scene: self)
|
||||||
let positionX = self.size.width * 0.1
|
let positionX = self.size.width * 0.1
|
||||||
let positionY = self.size.height * 0.05
|
let positionY = self.size.height * 0.05
|
||||||
|
print("SceneDidLoad Setting")
|
||||||
EntityManager.sharedInstance.add(Button(name: "backToMenuScene",
|
entityManager.add(Button(name: "backToMenuScene",
|
||||||
iconName: "",
|
iconName: "",
|
||||||
text: "Back",
|
text: "Back",
|
||||||
position: CGPoint(x: positionX, y: positionY),
|
position: CGPoint(x: positionX, y: positionY),
|
||||||
onButtonPress: {
|
onButtonPress: {
|
||||||
self.loadScene(scene: MenuScene(size: self.size))
|
let scene = MenuScene(size: self.size)
|
||||||
|
self.loadScene(scene: scene)
|
||||||
}))
|
}))
|
||||||
EntityManager.sharedInstance.add(Button(name: "StopMenuMusic",
|
entityManager.add(Button(name: "StopMenuMusic",
|
||||||
iconName: "",
|
iconName: "",
|
||||||
text: "ON/OFF",
|
text: "ON/OFF",
|
||||||
position: CGPoint(x: self.size.width * 0.6, y: self.size.height / 2),
|
position: CGPoint(x: self.size.width * 0.6, y: self.size.height / 2),
|
||||||
@ -35,7 +39,7 @@ class SettingsScene: SKScene {
|
|||||||
SoundManager.sharedInstance.startMenuMusic()
|
SoundManager.sharedInstance.startMenuMusic()
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
EntityManager.sharedInstance.add(Button(name: "StopMovingBackground",
|
entityManager.add(Button(name: "StopMovingBackground",
|
||||||
iconName: "",
|
iconName: "",
|
||||||
text: "MOVE/STOP",
|
text: "MOVE/STOP",
|
||||||
position: CGPoint(x: self.size.width * 0.6, y: self.size.height / 2 - 100),
|
position: CGPoint(x: self.size.width * 0.6, y: self.size.height / 2 - 100),
|
||||||
@ -46,7 +50,7 @@ class SettingsScene: SKScene {
|
|||||||
BackgroundComponent.isMovingBackgroundEnabled = true
|
BackgroundComponent.isMovingBackgroundEnabled = true
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
EntityManager.sharedInstance.add(Label(fontnamed: "Courier-Bold",
|
entityManager.add(Label(fontnamed: "Courier-Bold",
|
||||||
name: "SettingsLabel",
|
name: "SettingsLabel",
|
||||||
text: "Settings",
|
text: "Settings",
|
||||||
fontSize: 200.0,
|
fontSize: 200.0,
|
||||||
@ -57,7 +61,7 @@ class SettingsScene: SKScene {
|
|||||||
isAnimationEnabled: true,
|
isAnimationEnabled: true,
|
||||||
isAnimationInfinite: true)
|
isAnimationInfinite: true)
|
||||||
)
|
)
|
||||||
EntityManager.sharedInstance.add(Label(fontnamed: "Courier-Bold",
|
entityManager.add(Label(fontnamed: "Courier-Bold",
|
||||||
name: "LabelMusic",
|
name: "LabelMusic",
|
||||||
text: "Music", fontSize: 50.0,
|
text: "Music", fontSize: 50.0,
|
||||||
fontColor: .black,
|
fontColor: .black,
|
||||||
@ -67,7 +71,7 @@ class SettingsScene: SKScene {
|
|||||||
isAnimationEnabled: true,
|
isAnimationEnabled: true,
|
||||||
isAnimationInfinite: false)
|
isAnimationInfinite: false)
|
||||||
)
|
)
|
||||||
EntityManager.sharedInstance.add(Label(fontnamed: "Courier-Bold",
|
entityManager.add(Label(fontnamed: "Courier-Bold",
|
||||||
name: "LabelBackground",
|
name: "LabelBackground",
|
||||||
text: "Background",
|
text: "Background",
|
||||||
fontSize: 50.0,
|
fontSize: 50.0,
|
||||||
@ -78,16 +82,19 @@ class SettingsScene: SKScene {
|
|||||||
isAnimationEnabled: true,
|
isAnimationEnabled: true,
|
||||||
isAnimationInfinite: false)
|
isAnimationInfinite: false)
|
||||||
)
|
)
|
||||||
EntityManager.sharedInstance.add(Background(size: self.size))
|
entityManager.add(Background(size: self.size))
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadScene(scene: SKScene) {
|
func loadScene(scene: SKScene) {
|
||||||
let transition = SKTransition.flipVertical(withDuration: 0.5)
|
let transition = SKTransition.flipVertical(withDuration: 0.5)
|
||||||
|
entityManager.entities.removeAll()
|
||||||
self.view?.presentScene(scene, transition: transition)
|
self.view?.presentScene(scene, transition: transition)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func update(_ currentTime: TimeInterval) {
|
override func update(_ currentTime: TimeInterval) {
|
||||||
EntityManager.sharedInstance.getBackground()!.update(deltaTime: currentTime)
|
if entityManager.entities.count != 0 {
|
||||||
|
entityManager.getBackground()!.update(deltaTime: currentTime)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user