Merge branch '29-uberarbeitung-der-menuscene-button' into 'development'
Resolve "Überarbeitung der MenuScene & Button" Closes #29 See merge request marcel.schwarz/software-projekt-2!37
This commit is contained in:
commit
44beb7ba4a
@ -8,7 +8,6 @@
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
110360D3244B101A008610AF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 110360D2244B101A008610AF /* AppDelegate.swift */; };
|
||||
110360D5244B101A008610AF /* GameScene.sks in Resources */ = {isa = PBXBuildFile; fileRef = 110360D4244B101A008610AF /* GameScene.sks */; };
|
||||
110360D9244B101A008610AF /* GameScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 110360D8244B101A008610AF /* GameScene.swift */; };
|
||||
110360DB244B101A008610AF /* GameViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 110360DA244B101A008610AF /* GameViewController.swift */; };
|
||||
110360DE244B101A008610AF /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 110360DC244B101A008610AF /* Main.storyboard */; };
|
||||
@ -16,13 +15,17 @@
|
||||
110360E3244B101B008610AF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 110360E1244B101B008610AF /* LaunchScreen.storyboard */; };
|
||||
110360EE244B101B008610AF /* GoldWarsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 110360ED244B101B008610AF /* GoldWarsTests.swift */; };
|
||||
110360F9244B101B008610AF /* GoldWarsUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 110360F8244B101B008610AF /* GoldWarsUITests.swift */; };
|
||||
11036111244B3D6A008610AF /* MenuScene.sks in Resources */ = {isa = PBXBuildFile; fileRef = 11036110244B3D6A008610AF /* MenuScene.sks */; };
|
||||
11036113244B3E30008610AF /* MenuScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11036112244B3E30008610AF /* MenuScene.swift */; };
|
||||
116060F7245C57D2004E5A36 /* EntityManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 116060F6245C57D2004E5A36 /* EntityManager.swift */; };
|
||||
11738A3B24508F68004426F1 /* Unit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11738A3A24508F68004426F1 /* Unit.swift */; };
|
||||
3EBD242C245D8044003CECE7 /* GameCenterHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */; };
|
||||
3EBD242E245D9332003CECE7 /* Team.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBD242D245D9332003CECE7 /* Team.swift */; };
|
||||
9E11FF79245CD81100EED3BE /* Fire.sks in Resources */ = {isa = PBXBuildFile; fileRef = 9E11FF77245CD81100EED3BE /* Fire.sks */; };
|
||||
9E174C82245DD81D00209FF0 /* ButtonNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E174C81245DD81D00209FF0 /* ButtonNode.swift */; };
|
||||
9E174C84245DD8CE00209FF0 /* Button.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E174C83245DD8CE00209FF0 /* Button.swift */; };
|
||||
9E174C86245DD91500209FF0 /* ButtonComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E174C85245DD91500209FF0 /* ButtonComponent.swift */; };
|
||||
9E174C88245DF1FF00209FF0 /* BackgroundComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E174C87245DF1FF00209FF0 /* BackgroundComponent.swift */; };
|
||||
9E174C8A245E1A0A00209FF0 /* Background.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E174C89245E1A0A00209FF0 /* Background.swift */; };
|
||||
9E78ACB6245C9A5300526FF7 /* GameKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9E78ACB5245C9A5300526FF7 /* GameKit.framework */; };
|
||||
9E78ACB8245CB75B00526FF7 /* TeamComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E78ACB7245CB75B00526FF7 /* TeamComponent.swift */; };
|
||||
9E78ACBA245CBDAF00526FF7 /* HUD.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E78ACB9245CBDAF00526FF7 /* HUD.swift */; };
|
||||
@ -61,7 +64,6 @@
|
||||
/* Begin PBXFileReference section */
|
||||
110360CF244B101A008610AF /* GoldWars.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GoldWars.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
110360D2244B101A008610AF /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
110360D4244B101A008610AF /* GameScene.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = GameScene.sks; sourceTree = "<group>"; };
|
||||
110360D8244B101A008610AF /* GameScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameScene.swift; sourceTree = "<group>"; };
|
||||
110360DA244B101A008610AF /* GameViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameViewController.swift; sourceTree = "<group>"; };
|
||||
110360DD244B101A008610AF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
|
||||
@ -74,13 +76,17 @@
|
||||
110360F4244B101B008610AF /* GoldWarsUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GoldWarsUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
110360F8244B101B008610AF /* GoldWarsUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GoldWarsUITests.swift; sourceTree = "<group>"; };
|
||||
110360FA244B101B008610AF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
11036110244B3D6A008610AF /* MenuScene.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = MenuScene.sks; sourceTree = "<group>"; };
|
||||
11036112244B3E30008610AF /* MenuScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuScene.swift; sourceTree = "<group>"; };
|
||||
116060F6245C57D2004E5A36 /* EntityManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntityManager.swift; sourceTree = "<group>"; };
|
||||
11738A3A24508F68004426F1 /* Unit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Unit.swift; sourceTree = "<group>"; };
|
||||
3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameCenterHelper.swift; sourceTree = "<group>"; };
|
||||
3EBD242D245D9332003CECE7 /* Team.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Team.swift; sourceTree = "<group>"; };
|
||||
9E11FF77245CD81100EED3BE /* Fire.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = Fire.sks; sourceTree = "<group>"; };
|
||||
9E174C81245DD81D00209FF0 /* ButtonNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonNode.swift; sourceTree = "<group>"; };
|
||||
9E174C83245DD8CE00209FF0 /* Button.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Button.swift; sourceTree = "<group>"; };
|
||||
9E174C85245DD91500209FF0 /* ButtonComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonComponent.swift; sourceTree = "<group>"; };
|
||||
9E174C87245DF1FF00209FF0 /* BackgroundComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundComponent.swift; sourceTree = "<group>"; };
|
||||
9E174C89245E1A0A00209FF0 /* Background.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Background.swift; sourceTree = "<group>"; };
|
||||
9E78ACB5245C9A5300526FF7 /* GameKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GameKit.framework; path = System/Library/Frameworks/GameKit.framework; sourceTree = SDKROOT; };
|
||||
9E78ACB7245CB75B00526FF7 /* TeamComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TeamComponent.swift; sourceTree = "<group>"; };
|
||||
9E78ACB9245CBDAF00526FF7 /* HUD.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HUD.swift; sourceTree = "<group>"; };
|
||||
@ -188,6 +194,7 @@
|
||||
116060F4245C56EA004E5A36 /* Components */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9E174C81245DD81D00209FF0 /* ButtonNode.swift */,
|
||||
9EA3ABE8245C6DAA006BC61D /* DefaultBaseComponent.swift */,
|
||||
9EA3ABEC245C8143006BC61D /* ModalBackgroundComponent.swift */,
|
||||
9EA3ABEE245C834B006BC61D /* ModalContentComponent.swift */,
|
||||
@ -196,6 +203,8 @@
|
||||
9E78ACBD245CC9C000526FF7 /* AtkBoostSkillComponent.swift */,
|
||||
9E78ACC3245CCA3600526FF7 /* SpySkillComponent.swift */,
|
||||
9E78ACC1245CC9EE00526FF7 /* DefBoostSkillComponent.swift */,
|
||||
9E174C85245DD91500209FF0 /* ButtonComponent.swift */,
|
||||
9E174C87245DF1FF00209FF0 /* BackgroundComponent.swift */,
|
||||
);
|
||||
path = Components;
|
||||
sourceTree = "<group>";
|
||||
@ -207,6 +216,8 @@
|
||||
9EC86B9E245C88A300796EF3 /* Modal.swift */,
|
||||
116060F6245C57D2004E5A36 /* EntityManager.swift */,
|
||||
9E78ACB9245CBDAF00526FF7 /* HUD.swift */,
|
||||
9E174C83245DD8CE00209FF0 /* Button.swift */,
|
||||
9E174C89245E1A0A00209FF0 /* Background.swift */,
|
||||
);
|
||||
path = Entities;
|
||||
sourceTree = "<group>";
|
||||
@ -249,10 +260,8 @@
|
||||
9EC86BA4245C8A1E00796EF3 /* Scenes */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
11036110244B3D6A008610AF /* MenuScene.sks */,
|
||||
11036112244B3E30008610AF /* MenuScene.swift */,
|
||||
110360D8244B101A008610AF /* GameScene.swift */,
|
||||
110360D4244B101A008610AF /* GameScene.sks */,
|
||||
);
|
||||
path = Scenes;
|
||||
sourceTree = "<group>";
|
||||
@ -372,8 +381,6 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
110360DE244B101A008610AF /* Main.storyboard in Resources */,
|
||||
11036111244B3D6A008610AF /* MenuScene.sks in Resources */,
|
||||
110360D5244B101A008610AF /* GameScene.sks in Resources */,
|
||||
9E11FF79245CD81100EED3BE /* Fire.sks in Resources */,
|
||||
110360E0244B101B008610AF /* Assets.xcassets in Resources */,
|
||||
110360E3244B101B008610AF /* LaunchScreen.storyboard in Resources */,
|
||||
@ -410,16 +417,21 @@
|
||||
110360D9244B101A008610AF /* GameScene.swift in Sources */,
|
||||
116060F7245C57D2004E5A36 /* EntityManager.swift in Sources */,
|
||||
3EBD242E245D9332003CECE7 /* Team.swift in Sources */,
|
||||
9E174C88245DF1FF00209FF0 /* BackgroundComponent.swift in Sources */,
|
||||
9E78ACBA245CBDAF00526FF7 /* HUD.swift in Sources */,
|
||||
11738A3B24508F68004426F1 /* Unit.swift in Sources */,
|
||||
9E174C86245DD91500209FF0 /* ButtonComponent.swift in Sources */,
|
||||
11036113244B3E30008610AF /* MenuScene.swift in Sources */,
|
||||
9EA3ABE9245C6DAA006BC61D /* DefaultBaseComponent.swift in Sources */,
|
||||
9E174C8A245E1A0A00209FF0 /* Background.swift in Sources */,
|
||||
9EA3ABED245C8143006BC61D /* ModalBackgroundComponent.swift in Sources */,
|
||||
3EBD242C245D8044003CECE7 /* GameCenterHelper.swift in Sources */,
|
||||
AB1D759C245DD18100671525 /* MapProtocol.swift in Sources */,
|
||||
AB1D75A0245DEC0500671525 /* MapFactory.swift in Sources */,
|
||||
AB1D759D245DD18100671525 /* TwoPlayerDefaultTestMap.swift in Sources */,
|
||||
ABA03DA0244BD54F00A66916 /* Base.swift in Sources */,
|
||||
9E174C82245DD81D00209FF0 /* ButtonNode.swift in Sources */,
|
||||
9E174C84245DD8CE00209FF0 /* Button.swift in Sources */,
|
||||
110360DB244B101A008610AF /* GameViewController.swift in Sources */,
|
||||
110360D3244B101A008610AF /* AppDelegate.swift in Sources */,
|
||||
9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */,
|
||||
|
45
GoldWars/GoldWars/Components/BackgroundComponent.swift
Normal file
45
GoldWars/GoldWars/Components/BackgroundComponent.swift
Normal file
@ -0,0 +1,45 @@
|
||||
//
|
||||
// BackgroundComponent.swift
|
||||
// GoldWars
|
||||
//
|
||||
// Created by Niko Jochim on 02.05.20.
|
||||
// Copyright © 2020 SP2. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import GameplayKit
|
||||
|
||||
class BackgroundComponent: GKComponent{
|
||||
|
||||
var nodes = [SKSpriteNode]()
|
||||
let size: CGSize
|
||||
|
||||
init(size: CGSize) {
|
||||
self.size = size
|
||||
for i in 0...2 {
|
||||
let sky = SKSpriteNode(imageNamed: "SkyBackground")
|
||||
sky.name = "clouds"
|
||||
sky.zPosition = -1
|
||||
sky.size = CGSize(width: size.width, height: size.height)
|
||||
sky.position = CGPoint(x: CGFloat(i) * sky.size.width , y: (size.height / 2))
|
||||
nodes.append(sky)
|
||||
}
|
||||
super.init()
|
||||
}
|
||||
|
||||
func update(){
|
||||
for node in nodes{
|
||||
node.position.x -= 2
|
||||
if node.position.x < -(size.width) {
|
||||
node.position.x += (size.width) * 3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
}
|
28
GoldWars/GoldWars/Components/ButtonComponent.swift
Normal file
28
GoldWars/GoldWars/Components/ButtonComponent.swift
Normal file
@ -0,0 +1,28 @@
|
||||
//
|
||||
// ButtonComponent.swift
|
||||
// GoldWars
|
||||
//
|
||||
// Created by Niko Jochim on 02.05.20.
|
||||
// Copyright © 2020 SP2. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import GameplayKit
|
||||
|
||||
class ButtonComponent: GKComponent {
|
||||
|
||||
var buttonNode : ButtonNode
|
||||
|
||||
init(iconName: String, text: String, position: CGPoint, isEnabled:Bool , onButtonPress: @escaping () -> ()) {
|
||||
buttonNode = ButtonNode(iconName: iconName,
|
||||
text: text,
|
||||
isEnabled: isEnabled,
|
||||
position: position,
|
||||
onButtonPress: onButtonPress)
|
||||
super.init()
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
}
|
79
GoldWars/GoldWars/Components/ButtonNode.swift
Normal file
79
GoldWars/GoldWars/Components/ButtonNode.swift
Normal file
@ -0,0 +1,79 @@
|
||||
//
|
||||
// ButtonNode.swift
|
||||
// GoldWars
|
||||
//
|
||||
// Created by Niko Jochim on 01.05.20.
|
||||
// Copyright © 2020 SP2. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SpriteKit
|
||||
|
||||
class ButtonNode : SKSpriteNode {
|
||||
|
||||
var isEnabled:Bool{
|
||||
didSet{
|
||||
if isEnabled {
|
||||
self.alpha = 1
|
||||
self.childNode(withName: "label")?.alpha = 1
|
||||
} else {
|
||||
self.alpha = 0.3
|
||||
self.childNode(withName: "label")?.alpha = 0.3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let onButtonPress: () -> ()
|
||||
|
||||
init(iconName: String, text: String,isEnabled:Bool, position: CGPoint, onButtonPress: @escaping () -> ()) {
|
||||
self.onButtonPress = onButtonPress
|
||||
self.isEnabled = isEnabled
|
||||
let texture = SKTexture(imageNamed: "yellow_button04")
|
||||
super.init(texture: texture, color: SKColor.white, size: texture.size())
|
||||
self.position = position
|
||||
|
||||
let label = SKLabelNode(fontNamed: "Courier-Bold")
|
||||
|
||||
label.fontSize = 30
|
||||
label.fontColor = SKColor.black
|
||||
|
||||
label.zPosition = 1
|
||||
label.verticalAlignmentMode = .center
|
||||
label.text = text
|
||||
label.name = "label"
|
||||
|
||||
if !iconName.isEmpty {
|
||||
label.position = CGPoint(x: size.width * 0.25, y: 0)
|
||||
let icon = SKSpriteNode(imageNamed: iconName)
|
||||
icon.position = CGPoint(x: -size.width * 0.25, y: 0)
|
||||
icon.zPosition = 1
|
||||
self.addChild(icon)
|
||||
} else {
|
||||
label.position = CGPoint(x: 0, y: 0)
|
||||
}
|
||||
self.addChild(label)
|
||||
isUserInteractionEnabled = true
|
||||
}
|
||||
|
||||
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
|
||||
if isEnabled {
|
||||
let action = SKAction.sequence(
|
||||
[
|
||||
SKAction.scale(by: (3/4), duration: 0.3),
|
||||
SKAction.scale(by: (4/3), duration: 0.3),
|
||||
])
|
||||
|
||||
self.childNode(withName: "label")?.run(action)
|
||||
self.run(action)
|
||||
onButtonPress()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
}
|
30
GoldWars/GoldWars/Entities/Background.swift
Normal file
30
GoldWars/GoldWars/Entities/Background.swift
Normal file
@ -0,0 +1,30 @@
|
||||
//
|
||||
// Background.swift
|
||||
// GoldWars
|
||||
//
|
||||
// Created by Niko Jochim on 02.05.20.
|
||||
// Copyright © 2020 SP2. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import GameplayKit
|
||||
|
||||
class Background: GKEntity {
|
||||
|
||||
init(size: CGSize) {
|
||||
super.init()
|
||||
addComponent(BackgroundComponent(size: size))
|
||||
}
|
||||
|
||||
|
||||
override func update(deltaTime seconds: TimeInterval) {
|
||||
component(ofType: BackgroundComponent.self)?.update()
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
29
GoldWars/GoldWars/Entities/Button.swift
Normal file
29
GoldWars/GoldWars/Entities/Button.swift
Normal file
@ -0,0 +1,29 @@
|
||||
//
|
||||
// Button.swift
|
||||
// GoldWars
|
||||
//
|
||||
// Created by Niko Jochim on 02.05.20.
|
||||
// Copyright © 2020 SP2. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import GameKit
|
||||
|
||||
class Button : GKEntity{
|
||||
let name : String
|
||||
var isEnabled = true
|
||||
|
||||
init(name: String, iconName: String, text: String, position: CGPoint, onButtonPress: @escaping () -> ()) {
|
||||
self.name = name
|
||||
super.init()
|
||||
self.addComponent(ButtonComponent(iconName: iconName, text: text,position: position, isEnabled: isEnabled, onButtonPress: onButtonPress))
|
||||
}
|
||||
|
||||
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -50,6 +50,14 @@ class EntityManager {
|
||||
scene.addChild(skill.shapeNode)
|
||||
scene.addChild(skill.labelNode)
|
||||
}
|
||||
if let buttonNode = entity.component(ofType: ButtonComponent.self)?.buttonNode {
|
||||
scene.addChild(buttonNode)
|
||||
}
|
||||
if let nodes = entity.component(ofType: BackgroundComponent.self)?.nodes {
|
||||
for node in nodes {
|
||||
scene.addChild(node)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -70,7 +78,7 @@ class EntityManager {
|
||||
entities.remove(entity)
|
||||
}
|
||||
|
||||
func base(for team: Team) -> GKEntity? {
|
||||
func getBaseByTeam(for team: Team) -> GKEntity? {
|
||||
for entity in entities {
|
||||
if let teamComponent = entity.component(ofType: TeamComponent.self),
|
||||
let _ = entity.component(ofType: DefaultBaseComponent.self) {
|
||||
@ -82,7 +90,15 @@ class EntityManager {
|
||||
return nil
|
||||
}
|
||||
|
||||
func baseNode(for team: Team) -> SKSpriteNode?{
|
||||
return base(for: team)?.component(ofType: DefaultBaseComponent.self)?.spriteNode
|
||||
func getBackground() -> GKEntity? {
|
||||
return entities.filter{$0 is Background}[0]
|
||||
}
|
||||
|
||||
func getBaseNodeByTeam(for team: Team) -> SKSpriteNode?{
|
||||
return getBaseByTeam(for: team)?.component(ofType: DefaultBaseComponent.self)?.spriteNode
|
||||
}
|
||||
|
||||
func getButtonByName(buttonName:String) -> Button{
|
||||
return entities.filter{$0 is Button && ($0 as! Button).name == buttonName }[0] as! Button
|
||||
}
|
||||
}
|
||||
|
@ -16,17 +16,16 @@ class GameViewController: UIViewController {
|
||||
super.viewDidLoad()
|
||||
|
||||
if let view = self.view as! SKView? {
|
||||
if let scene = SKScene(fileNamed: "MenuScene") {
|
||||
scene.scaleMode = .aspectFill
|
||||
view.presentScene(scene)
|
||||
//TODO: create dev profile or remove on delivery
|
||||
view.showsFPS = true
|
||||
view.showsNodeCount = true
|
||||
}
|
||||
}
|
||||
let scene = MenuScene(size: self.view.bounds.size)
|
||||
scene.scaleMode = .aspectFill
|
||||
view.presentScene(scene)
|
||||
//TODO: create dev profile or remove on delivery
|
||||
view.showsFPS = true
|
||||
view.showsNodeCount = true
|
||||
|
||||
GameCenterHelper.helper.viewController = self
|
||||
}
|
||||
}
|
||||
|
||||
override var shouldAutorotate: Bool {
|
||||
return true
|
||||
|
Binary file not shown.
@ -16,22 +16,11 @@ class GameScene: SKScene{
|
||||
override func sceneDidLoad() {
|
||||
entityManager = EntityManager(scene: self)
|
||||
entityManager.add(HUD(size: self.size))
|
||||
entityManager.add(Background(size: self.size))
|
||||
initMap()
|
||||
createBackground()
|
||||
|
||||
}
|
||||
|
||||
func createBackground() {
|
||||
for i in 0...2 {
|
||||
let sky = SKSpriteNode(imageNamed: "SkyBackground")
|
||||
sky.name = "clouds"
|
||||
sky.zPosition = -1
|
||||
sky.size = CGSize(width: (self.scene?.size.width)!, height: (self.scene?.size.height)!)
|
||||
sky.position = CGPoint(x: CGFloat(i) * sky.size.width , y: (self.frame.size.height / 2))
|
||||
|
||||
self.addChild(sky)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func initMap() {
|
||||
MapFactory(scene: self, entityManager: self.entityManager).loadMap(playerCount: 2)
|
||||
@ -76,15 +65,9 @@ class GameScene: SKScene{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
override func update(_ currentTime: TimeInterval) {
|
||||
self.enumerateChildNodes(withName: "clouds", using: ({
|
||||
(node, error) in
|
||||
node.position.x -= 2
|
||||
if node.position.x < -(self.scene?.size.width)! {
|
||||
node.position.x += (self.scene?.size.width)! * 3
|
||||
}
|
||||
}))
|
||||
entityManager.getBackground()?.update(deltaTime: currentTime)
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
@ -9,61 +9,37 @@
|
||||
import SpriteKit
|
||||
|
||||
class MenuScene: SKScene {
|
||||
|
||||
var startGameButtonNode:SKSpriteNode!
|
||||
var settingsButtonNode:SKSpriteNode!
|
||||
|
||||
override func sceneDidLoad() {
|
||||
for i in 0...2 {
|
||||
let sky = SKSpriteNode(imageNamed: "SkyBackground")
|
||||
sky.name = "clouds"
|
||||
sky.zPosition = -1
|
||||
sky.size = CGSize(width: self.size.width, height: self.size.height)
|
||||
sky.position = CGPoint(x: CGFloat(i) * sky.size.width , y: (self.frame.size.height / 2))
|
||||
var entityManager: EntityManager!
|
||||
|
||||
self.addChild(sky)
|
||||
}
|
||||
}
|
||||
override func sceneDidLoad() {
|
||||
entityManager = EntityManager(scene: self)
|
||||
let midX = self.size.width / 2
|
||||
let midY = self.size.height / 2
|
||||
entityManager.add(Button(name: "startGameButton",
|
||||
iconName: "",
|
||||
text: "Start Game",
|
||||
position: CGPoint(x: midX, y: midY),
|
||||
onButtonPress: {
|
||||
self.loadScene(scene: GameScene(size: self.size))
|
||||
}))
|
||||
entityManager.add(Button(name: "settingsButton",
|
||||
iconName: "",
|
||||
text: "Settings",
|
||||
position: CGPoint(x: midX, y: midY - 80 ),
|
||||
onButtonPress: {
|
||||
//TODO: create Settings Scene
|
||||
}))
|
||||
entityManager.add(Background(size: self.size))
|
||||
}
|
||||
|
||||
|
||||
|
||||
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
guard let touch = touches.first else {
|
||||
return
|
||||
}
|
||||
let gameScene = GameScene(size: self.size)
|
||||
let location = touch.location(in: self)
|
||||
let frontTouchedNode = atPoint(location).name
|
||||
|
||||
let transition = SKTransition.moveIn(with: .right, duration: 1)
|
||||
|
||||
if frontTouchedNode == "startGameBtn" || frontTouchedNode == "tmpStartGameLbl"{
|
||||
self.view?.presentScene(gameScene, transition: transition)
|
||||
}
|
||||
|
||||
if frontTouchedNode == "settingsBtn" || frontTouchedNode == "tmpSettingsLbl"{
|
||||
//TODO: Implement settings functionality
|
||||
}
|
||||
func loadScene(scene: SKScene) {
|
||||
let transition = SKTransition.flipVertical(withDuration: 0.5)
|
||||
self.view?.presentScene(scene, transition: transition)
|
||||
}
|
||||
|
||||
override func update(_ currentTime: TimeInterval) {
|
||||
self.enumerateChildNodes(withName: "clouds", using: ({
|
||||
(node, error) in
|
||||
node.position.x -= 2
|
||||
if node.position.x < -(self.scene?.size.width)! {
|
||||
node.position.x += (self.scene?.size.width)! * 3
|
||||
}
|
||||
}))
|
||||
|
||||
// TODO: Notfalllösung
|
||||
if(!GameCenterHelper.isAuthenticated) {
|
||||
let authLabel = SKLabelNode(text: "You are not logged in to Gamecenter. Please login via GameCenterApp")
|
||||
authLabel.name = "authLabel"
|
||||
authLabel.zPosition = 2
|
||||
authLabel.position = CGPoint(x: self.size.width / 2, y: self.size.height / 5)
|
||||
self.addChild(authLabel)
|
||||
} else {
|
||||
self.childNode(withName: "authLabel")?.removeFromParent()
|
||||
}
|
||||
entityManager.getBackground()!.update(deltaTime: currentTime)
|
||||
entityManager.getButtonByName(buttonName: "startGameButton").component(ofType: ButtonComponent.self)?.buttonNode.isEnabled = GameCenterHelper.isAuthenticated
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user