Merge branch 'development' into 89-regelwerk

This commit is contained in:
Chauntalle Schüle 2020-06-19 13:46:36 +02:00
commit 0985e02c3d
44 changed files with 552 additions and 230 deletions

View File

@ -31,6 +31,8 @@
9E174C86245DD91500209FF0 /* ButtonComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E174C85245DD91500209FF0 /* ButtonComponent.swift */; }; 9E174C86245DD91500209FF0 /* ButtonComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E174C85245DD91500209FF0 /* ButtonComponent.swift */; };
9E174C88245DF1FF00209FF0 /* BackgroundComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E174C87245DF1FF00209FF0 /* BackgroundComponent.swift */; }; 9E174C88245DF1FF00209FF0 /* BackgroundComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E174C87245DF1FF00209FF0 /* BackgroundComponent.swift */; };
9E174C8A245E1A0A00209FF0 /* Background.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E174C89245E1A0A00209FF0 /* Background.swift */; }; 9E174C8A245E1A0A00209FF0 /* Background.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E174C89245E1A0A00209FF0 /* Background.swift */; };
9E61EAC4249BAC9100334DDE /* LoserFire.sks in Resources */ = {isa = PBXBuildFile; fileRef = 9E61EAC2249BAC9100334DDE /* LoserFire.sks */; };
9E61EAC7249BB61A00334DDE /* SpinningLogo3DNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E61EAC6249BB61A00334DDE /* SpinningLogo3DNode.swift */; };
9E78ACB6245C9A5300526FF7 /* GameKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9E78ACB5245C9A5300526FF7 /* GameKit.framework */; }; 9E78ACB6245C9A5300526FF7 /* GameKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9E78ACB5245C9A5300526FF7 /* GameKit.framework */; };
9E78ACB8245CB75B00526FF7 /* TeamComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E78ACB7245CB75B00526FF7 /* TeamComponent.swift */; }; 9E78ACB8245CB75B00526FF7 /* TeamComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E78ACB7245CB75B00526FF7 /* TeamComponent.swift */; };
9E78ACBA245CBDAF00526FF7 /* HUD.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E78ACB9245CBDAF00526FF7 /* HUD.swift */; }; 9E78ACBA245CBDAF00526FF7 /* HUD.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E78ACB9245CBDAF00526FF7 /* HUD.swift */; };
@ -41,8 +43,8 @@
9EC7E48B2461FBF700396BCD /* SliderNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC7E48A2461FBF700396BCD /* SliderNode.swift */; }; 9EC7E48B2461FBF700396BCD /* SliderNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC7E48A2461FBF700396BCD /* SliderNode.swift */; };
9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86B9E245C88A300796EF3 /* Modal.swift */; }; 9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86B9E245C88A300796EF3 /* Modal.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 */; };
AB21D7D5246C748A00B09CBA /* MapFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB21D7D4246C748A00B09CBA /* MapFactory.swift */; }; AB21D7D5246C748A00B09CBA /* MapFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB21D7D4246C748A00B09CBA /* MapFactory.swift */; };
AB671B252494ECF0003FBE8D /* EloHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB671B242494ECF0003FBE8D /* EloHelper.swift */; };
ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; }; ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; };
ABC0C3732481509300387B8F /* MapUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC0C3722481509300387B8F /* MapUtils.swift */; }; ABC0C3732481509300387B8F /* MapUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC0C3722481509300387B8F /* MapUtils.swift */; };
AE0C8E2F249BCC2A00996360 /* RulesScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE0C8E2E249BCC2A00996360 /* RulesScene.swift */; }; AE0C8E2F249BCC2A00996360 /* RulesScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE0C8E2E249BCC2A00996360 /* RulesScene.swift */; };
@ -95,6 +97,8 @@
9E174C85245DD91500209FF0 /* ButtonComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonComponent.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>"; }; 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>"; }; 9E174C89245E1A0A00209FF0 /* Background.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Background.swift; sourceTree = "<group>"; };
9E61EAC2249BAC9100334DDE /* LoserFire.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = LoserFire.sks; sourceTree = "<group>"; };
9E61EAC6249BB61A00334DDE /* SpinningLogo3DNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpinningLogo3DNode.swift; sourceTree = "<group>"; };
9E78ACB5245C9A5300526FF7 /* GameKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GameKit.framework; path = System/Library/Frameworks/GameKit.framework; sourceTree = SDKROOT; }; 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>"; }; 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>"; }; 9E78ACB9245CBDAF00526FF7 /* HUD.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HUD.swift; sourceTree = "<group>"; };
@ -106,8 +110,8 @@
9EC86B9E245C88A300796EF3 /* Modal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modal.swift; sourceTree = "<group>"; }; 9EC86B9E245C88A300796EF3 /* Modal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modal.swift; sourceTree = "<group>"; };
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>"; };
AB21D7D4246C748A00B09CBA /* MapFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapFactory.swift; sourceTree = "<group>"; }; AB21D7D4246C748A00B09CBA /* MapFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapFactory.swift; sourceTree = "<group>"; };
AB671B242494ECF0003FBE8D /* EloHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EloHelper.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>"; };
ABC0C3722481509300387B8F /* MapUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapUtils.swift; sourceTree = "<group>"; }; ABC0C3722481509300387B8F /* MapUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapUtils.swift; sourceTree = "<group>"; };
AE0C8E2E249BCC2A00996360 /* RulesScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RulesScene.swift; sourceTree = "<group>"; }; AE0C8E2E249BCC2A00996360 /* RulesScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RulesScene.swift; sourceTree = "<group>"; };
@ -182,6 +186,7 @@
9E0E459624796262009817A6 /* GameCenterManager.swift */, 9E0E459624796262009817A6 /* GameCenterManager.swift */,
C04783EF24685995004961FB /* SettingsScene.swift */, C04783EF24685995004961FB /* SettingsScene.swift */,
3EAD889424801B6A0048A10A /* RoundTimer.swift */, 3EAD889424801B6A0048A10A /* RoundTimer.swift */,
AB671B242494ECF0003FBE8D /* EloHelper.swift */,
AE0C8E2E249BCC2A00996360 /* RulesScene.swift */, AE0C8E2E249BCC2A00996360 /* RulesScene.swift */,
); );
path = GoldWars; path = GoldWars;
@ -210,8 +215,8 @@
8BB6FF3F2472B8F000162BBD /* SingeClickButtonNode.swift */, 8BB6FF3F2472B8F000162BBD /* SingeClickButtonNode.swift */,
C05BB9C3247D890C00411249 /* SliderComponent.swift */, C05BB9C3247D890C00411249 /* SliderComponent.swift */,
9EC7E48A2461FBF700396BCD /* SliderNode.swift */, 9EC7E48A2461FBF700396BCD /* SliderNode.swift */,
9EEDE02E246FCD800096C735 /* SpinningLogoComponent.swift */,
9E78ACB7245CB75B00526FF7 /* TeamComponent.swift */, 9E78ACB7245CB75B00526FF7 /* TeamComponent.swift */,
9E61EAC6249BB61A00334DDE /* SpinningLogo3DNode.swift */,
); );
path = Components; path = Components;
sourceTree = "<group>"; sourceTree = "<group>";
@ -237,6 +242,7 @@
children = ( children = (
3F79FFDF2486F7CD003F79C3 /* Explosion.sks */, 3F79FFDF2486F7CD003F79C3 /* Explosion.sks */,
9E11FF77245CD81100EED3BE /* Fire.sks */, 9E11FF77245CD81100EED3BE /* Fire.sks */,
9E61EAC2249BAC9100334DDE /* LoserFire.sks */,
); );
path = Partikels; path = Partikels;
sourceTree = "<group>"; sourceTree = "<group>";
@ -371,6 +377,7 @@
9E11FF79245CD81100EED3BE /* Fire.sks in Resources */, 9E11FF79245CD81100EED3BE /* Fire.sks in Resources */,
110360E0244B101B008610AF /* Assets.xcassets in Resources */, 110360E0244B101B008610AF /* Assets.xcassets in Resources */,
110360E3244B101B008610AF /* LaunchScreen.storyboard in Resources */, 110360E3244B101B008610AF /* LaunchScreen.storyboard in Resources */,
9E61EAC4249BAC9100334DDE /* LoserFire.sks in Resources */,
C04783EE2468583F004961FB /* intro-music.mp3 in Resources */, C04783EE2468583F004961FB /* intro-music.mp3 in Resources */,
3F79FFE02486F7CD003F79C3 /* Explosion.sks in Resources */, 3F79FFE02486F7CD003F79C3 /* Explosion.sks in Resources */,
); );
@ -406,6 +413,7 @@
9EC2FBA72476B1EC00ABF11F /* PlayerInfoComponent.swift in Sources */, 9EC2FBA72476B1EC00ABF11F /* PlayerInfoComponent.swift in Sources */,
9EEDE02D246FCD770096C735 /* SpinningLogoEntity.swift in Sources */, 9EEDE02D246FCD770096C735 /* SpinningLogoEntity.swift in Sources */,
9E174C86245DD91500209FF0 /* ButtonComponent.swift in Sources */, 9E174C86245DD91500209FF0 /* ButtonComponent.swift in Sources */,
AB671B252494ECF0003FBE8D /* EloHelper.swift in Sources */,
11036113244B3E30008610AF /* MenuScene.swift in Sources */, 11036113244B3E30008610AF /* MenuScene.swift in Sources */,
C099579C246C5E5C0016AA22 /* DataService.swift in Sources */, C099579C246C5E5C0016AA22 /* DataService.swift in Sources */,
AB21D7D5246C748A00B09CBA /* MapFactory.swift in Sources */, AB21D7D5246C748A00B09CBA /* MapFactory.swift in Sources */,
@ -422,7 +430,7 @@
ABC0C3732481509300387B8F /* MapUtils.swift in Sources */, ABC0C3732481509300387B8F /* MapUtils.swift in Sources */,
9E174C82245DD81D00209FF0 /* ButtonNode.swift in Sources */, 9E174C82245DD81D00209FF0 /* ButtonNode.swift in Sources */,
9EC7E48B2461FBF700396BCD /* SliderNode.swift in Sources */, 9EC7E48B2461FBF700396BCD /* SliderNode.swift in Sources */,
9EEDE02F246FCD800096C735 /* SpinningLogoComponent.swift in Sources */, 9E61EAC7249BB61A00334DDE /* SpinningLogo3DNode.swift in Sources */,
9E174C84245DD8CE00209FF0 /* Button.swift in Sources */, 9E174C84245DD8CE00209FF0 /* Button.swift in Sources */,
110360DB244B101A008610AF /* GameViewController.swift in Sources */, 110360DB244B101A008610AF /* GameViewController.swift in Sources */,
C05BB9C4247D890C00411249 /* SliderComponent.swift in Sources */, C05BB9C4247D890C00411249 /* SliderComponent.swift in Sources */,

View File

@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "goldLettering.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "goldLettering-1.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "goldLettering-2.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

View File

@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "goldWarsName.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "goldWarsName-1.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "goldWarsName-2.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 KiB

View File

@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "gold_button00.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "gold_button00-1.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "gold_button00-2.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "gold_button_2.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

View File

@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "gold_button_3.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

View File

@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "warsLettering.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "warsLettering-1.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "warsLettering-2.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

View File

@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "winner.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "winner-1.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "winner-2.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 KiB

View File

@ -10,58 +10,70 @@ import SpriteKit
class SliderNode :SKNode { class SliderNode :SKNode {
var sliderLine :SKShapeNode var sliderLine :SKShapeNode
var sliderKnob :SliderKnob var hiddenKnob :SliderKnob
var width: CGFloat var silderKnob :SKSpriteNode
var width: CGFloat
var getValue: CGFloat{
get{ var getValue: CGFloat{
return ((sliderKnob.position.x.rounded() - sliderKnob.min) / width) get{
} silderKnob.position = hiddenKnob.position
} return ((hiddenKnob.position.x.rounded() - hiddenKnob.min) / width)
}
init(width: CGFloat, position: CGPoint) { }
self.width = width
sliderLine = SKShapeNode(rectOf: CGSize(width: width, height: 8)) init(width: CGFloat, position: CGPoint) {
sliderLine.position = position self.width = width
sliderLine.fillColor = SKColor.white sliderLine = SKShapeNode(rectOf: CGSize(width: width, height: 8))
sliderLine.position = position
sliderLine.fillColor = SKColor.white
sliderLine.zPosition = 4 sliderLine.zPosition = 4
sliderKnob = SliderKnob(circleOfRadius: 20)
sliderKnob.min = position.x - width / 2 hiddenKnob = SliderKnob(circleOfRadius: 58 )
sliderKnob.max = position.x + width / 2 hiddenKnob.min = position.x - width / 2
sliderKnob.fillColor = SKColor.red hiddenKnob.max = position.x + width / 2
sliderKnob.zPosition = sliderLine.zPosition + 1 hiddenKnob.fillColor = SKColor.red
sliderKnob.position = CGPoint(x: sliderLine.position.x, y: sliderLine.position.y + 1) hiddenKnob.alpha = 0.001
super.init() hiddenKnob.zPosition = sliderLine.zPosition + 1
hiddenKnob.position = CGPoint(x: sliderLine.position.x, y: sliderLine.position.y + 1)
}
silderKnob = SKSpriteNode(texture: SKTexture(imageNamed: "yellow_boxTick"))
required init?(coder aDecoder: NSCoder) { silderKnob.position = hiddenKnob.position
fatalError("init(coder:) has not been implemented") silderKnob.zPosition = hiddenKnob.zPosition - 1
} silderKnob.size = CGSize(width: 50, height: 50)
super.init()
self.name = "slider"
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
} }
class SliderKnob: SKShapeNode { class SliderKnob: SKShapeNode {
var min = CGFloat() var min = CGFloat()
var max = CGFloat() var max = CGFloat()
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches { for touch in touches {
let touchLocation = touch.location(in: self.scene!) let touchLocation = touch.location(in: self.scene!)
if self.position.x >= min - 1 && self.position.x <= max + 1{ if self.position.x >= min - 1 && self.position.x <= max + 1{
self.position.x = touchLocation.x self.position.x = touchLocation.x
} }
if(self.position.x <= min){ if(self.position.x <= min){
self.position.x = min self.position.x = min
} }
if(self.position.x >= max){ if(self.position.x >= max){
self.position.x = max self.position.x = max
}
} }
} }
}
} }

View File

@ -0,0 +1,40 @@
//
// SpinningLogo3DNode.swift
// GoldWars
//
// Created by Niko Jochim on 18.06.20.
// Copyright © 2020 SP2. All rights reserved.
//
import Foundation
import SpriteKit
import GameKit
class SpinningLogo3DNode : SK3DNode {
init() {
super.init(viewportSize: CGSize(width: 250, height: 250))
let scnScene: SCNScene = {
let scnScene = SCNScene()
let cylinder = SCNCylinder(radius: 250, height: 50)
let logoMaterial = SCNMaterial()
let colorMaterial = SCNMaterial()
logoMaterial.diffuse.contents = UIImage(named: "logo_no_background")
colorMaterial.diffuse.contents = UIColor(red: 0.852, green: 0.649, blue: 0.123, alpha: 1)
cylinder.materials = [colorMaterial,logoMaterial,logoMaterial]
let cylinderNode = SCNNode(geometry: cylinder)
cylinderNode.eulerAngles = SCNVector3(x: Float(CGFloat.pi / 2), y: 0, z: Float(CGFloat.pi / 2))
let action = SCNAction.rotateBy(x: CGFloat(GLKMathDegreesToRadians(360)), y:0 , z: 0, duration: 8)
let forever = SCNAction.repeatForever(action)
cylinderNode.runAction(forever)
scnScene.rootNode.addChildNode(cylinderNode)
return scnScene
}()
self.scnScene = scnScene
self.position = position
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

View File

@ -1,45 +0,0 @@
//
// SpinningLogoComponent.swift
// GoldWars
//
// Created by Niko Jochim on 15.05.20.
// Copyright © 2020 SP2. All rights reserved.
//
import Foundation
import GameKit
class SpinningLogoComponent: GKComponent{
var node : SK3DNode
init(position: CGPoint) {
let scnScene: SCNScene = {
let scnScene = SCNScene()
let cylinder = SCNCylinder(radius: 250, height: 50)
let logoMaterial = SCNMaterial()
let colorMaterial = SCNMaterial()
logoMaterial.diffuse.contents = UIImage(named: "logo_no_background")
colorMaterial.diffuse.contents = UIColor(red: 0.852, green: 0.649, blue: 0.123, alpha: 1)
cylinder.materials = [colorMaterial,logoMaterial,logoMaterial]
let cylinderNode = SCNNode(geometry: cylinder)
cylinderNode.eulerAngles = SCNVector3(x: Float(CGFloat.pi / 2), y: 0, z: Float(CGFloat.pi / 2))
let action = SCNAction.rotateBy(x: CGFloat(GLKMathDegreesToRadians(360)), y:0 , z: 0, duration: 8)
let forever = SCNAction.repeatForever(action)
cylinderNode.runAction(forever)
scnScene.rootNode.addChildNode(cylinderNode)
return scnScene
}()
self.node = SK3DNode(viewportSize: CGSize(width: 250, height: 250))
node.scnScene = scnScene
node.position = position
super.init()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

View File

@ -0,0 +1,60 @@
//
// EloHelper.swift
// GoldWars
//
// Created by Marcel Schwarz on 13.06.20.
// Copyright © 2020 SP2. All rights reserved.
//
import GameKit
import os
struct EloDataForPeer : Codable {
let scoreToReport: Int64
}
class EloHelper {
static private let LOG = OSLog.init(subsystem: "EloHelper", category: "EloHelper")
static let IDENTIFIER = "de.hft.stuttgart.ip2.goldwars.matchmaking"
static func updateEloScore(winner: GKPlayer, hatDenNikoGemacht looser: GKPlayer) {
let leaderboard = GKLeaderboard.init(players: [winner, looser])
leaderboard.identifier = EloHelper.IDENTIFIER
leaderboard.loadScores{scores, error in
// Get Scores
let R_looser = scores?.filter { $0.player == looser }.first ?? GKScore(leaderboardIdentifier: EloHelper.IDENTIFIER, player: looser)
let R_winner = scores?.filter { $0.player == winner }.first ?? GKScore(leaderboardIdentifier: EloHelper.IDENTIFIER, player: winner)
// Calc ELO
let Q_looser = pow(10.0, Double(R_looser.value) / 400.0)
let Q_winner = pow(10.0, Double(R_winner.value) / 400.0)
let E_looser = Q_looser / (Q_looser + Q_winner)
let E_winner = Q_winner / (Q_looser + Q_winner)
let R_winner_new = Int64(Double(R_winner.value) + 10.0 * (1.0 - E_winner))
let R_looser_new = Int64(Double(R_looser.value) + 10.0 * (0.0 - E_looser))
// Update Elo on leaderboard
let winner_new = GKScore(leaderboardIdentifier: EloHelper.IDENTIFIER, player: winner)
winner_new.value = R_winner_new
let looser_new = GKScore(leaderboardIdentifier: EloHelper.IDENTIFIER, player: looser)
looser_new.value = R_looser_new
let scoreForPeer = winner == GameCenterManager.sharedInstance.localPlayer ? looser_new : winner_new
let scoreForHost = winner == GameCenterManager.sharedInstance.localPlayer ? winner_new : looser_new
MultiplayerNetwork.sharedInstance.sendEloData(scoreToReport: scoreForPeer)
GKScore.report([scoreForHost], withCompletionHandler: { error in
os_log("New Scores reported to EloSystem", log: LOG, type: .info)
})
}
}
}

View File

@ -63,6 +63,12 @@ class EntityManager {
scene.addChild(hudEntitiy.blockWholeScreenPane) scene.addChild(hudEntitiy.blockWholeScreenPane)
} }
if let spinningLogoEntity = entity as? SpinningLogoEntity {
scene.addChild(spinningLogoEntity.spinningLogoNode)
scene.addChild(spinningLogoEntity.goldLetteringNode)
scene.addChild(spinningLogoEntity.warsLetteringNode)
}
if let rulesEntity = entity as? Rules { if let rulesEntity = entity as? Rules {
scene.addChild(rulesEntity.header) scene.addChild(rulesEntity.header)
scene.addChild(rulesEntity.text1) scene.addChild(rulesEntity.text1)
@ -98,15 +104,14 @@ class EntityManager {
} }
} }
if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode { if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode {
scene.addChild(sliderNode.sliderKnob) scene.addChild(sliderNode.hiddenKnob)
scene.addChild(sliderNode.sliderLine) scene.addChild(sliderNode.sliderLine)
scene.addChild(sliderNode.silderKnob)
} }
if let labelNode = entity.component(ofType: LabelComponent.self)?.labelNode { if let labelNode = entity.component(ofType: LabelComponent.self)?.labelNode {
scene.addChild(labelNode) scene.addChild(labelNode)
} }
if let node = entity.component(ofType: SpinningLogoComponent.self)?.node {
scene.addChild(node)
}
} }
func remove(_ entity: GKEntity) { func remove(_ entity: GKEntity) {
@ -114,8 +119,9 @@ class EntityManager {
spriteNode.removeFromParent() spriteNode.removeFromParent()
} }
if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode { if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode {
sliderNode.sliderKnob.removeFromParent() sliderNode.hiddenKnob.removeFromParent()
sliderNode.sliderLine.removeFromParent() sliderNode.sliderLine.removeFromParent()
sliderNode.silderKnob.removeFromParent()
} }
if let modalButton = entity.component(ofType: ButtonComponent.self) { if let modalButton = entity.component(ofType: ButtonComponent.self) {
modalButton.buttonNode.removeFromParent() modalButton.buttonNode.removeFromParent()
@ -291,7 +297,7 @@ class EntityManager {
} }
func getBackground() -> GKEntity? { func getBackground() -> GKEntity? {
return entities.filter{$0 is Background}[0] return entities.filter{$0 is Background}.first
} }
func getBaseNodeByTeam(for team: Team) -> SKSpriteNode? { func getBaseNodeByTeam(for team: Team) -> SKSpriteNode? {
@ -303,7 +309,7 @@ class EntityManager {
} }
func getHUD() -> HUD? { func getHUD() -> HUD? {
return entities.filter{$0 is HUD}[0] as? HUD return entities.filter{$0 is HUD}.first as? HUD
} }
func getSnapshotModel() -> SnapshotModel { func getSnapshotModel() -> SnapshotModel {
@ -348,7 +354,7 @@ class EntityManager {
if let slider = modal.component(ofType: SliderComponent.self) { if let slider = modal.component(ofType: SliderComponent.self) {
slider.sliderNode.removeFromParent() slider.sliderNode.removeFromParent()
slider.sliderNode.sliderKnob.removeFromParent() slider.sliderNode.hiddenKnob.removeFromParent()
slider.sliderNode.sliderLine.removeFromParent() slider.sliderNode.sliderLine.removeFromParent()
} }

View File

@ -35,8 +35,10 @@ class HUD: GKEntity {
init(size: CGSize) { init(size: CGSize) {
hostLabel = SKLabelNode(text: GameCenterManager.sharedInstance.hostingPlayer?.displayName) hostLabel = SKLabelNode(text: GameCenterManager.sharedInstance.hostingPlayer?.displayName)
hostLabel.name = "hostLabel"
hostUnitsLabel = SKLabelNode(text: "500" ) hostUnitsLabel = SKLabelNode(text: "500" )
peerLabel = SKLabelNode(text: GameCenterManager.sharedInstance.peerPlayer?.displayName) peerLabel = SKLabelNode(text: GameCenterManager.sharedInstance.peerPlayer?.displayName)
peerLabel.name = "peerLabel"
peerUnitsLabel = SKLabelNode(text: "500") peerUnitsLabel = SKLabelNode(text: "500")
roundTimerLabel = SKLabelNode(text: "") roundTimerLabel = SKLabelNode(text: "")
@ -57,7 +59,7 @@ class HUD: GKEntity {
EntityManager.gameEMInstance.getOpponentBases(for: EntityManager.gameEMInstance.getTeam()).forEach({base in base.component(ofType: TeamComponent.self)?.unitcountLabel.text = "\(base.unitCount)"}) EntityManager.gameEMInstance.getOpponentBases(for: EntityManager.gameEMInstance.getTeam()).forEach({base in base.component(ofType: TeamComponent.self)?.unitcountLabel.text = "\(base.unitCount)"})
GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.skill.first.time", increasePercentComplete: 100) GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.skill.first.time", increasePercentComplete: 100)
GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.skill.spy.ten", increasePercentComplete: 10) GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.skill.spy.ten", increasePercentComplete: 10)
} }
) )
defSkill = SingeClickButtonNode( defSkill = SingeClickButtonNode(
textureName: "yellow_circle", textureName: "yellow_circle",
@ -99,7 +101,7 @@ class HUD: GKEntity {
roundsLabel = SKLabelNode(fontNamed: "Courier-Bold") roundsLabel = SKLabelNode(fontNamed: "Courier-Bold")
roundLabel = SKLabelNode(fontNamed: "Courier-Bold") roundLabel = SKLabelNode(fontNamed: "Courier-Bold")
blockWholeScreenPane = SKSpriteNode(color: UIColor.init(red: 0, green: 0, blue: 0, alpha: 0.7), size: size) blockWholeScreenPane = SKSpriteNode(color: UIColor.init(red: 0, green: 0, blue: 0, alpha: 0), size: size)
blockWholeScreenPane.position = CGPoint(x: size.width * 0.5, y: size.height * 0.5) blockWholeScreenPane.position = CGPoint(x: size.width * 0.5, y: size.height * 0.5)
blockWholeScreenPane.zPosition = 899 blockWholeScreenPane.zPosition = 899
blockWholeScreenPane.isHidden = true blockWholeScreenPane.isHidden = true
@ -180,9 +182,9 @@ class HUD: GKEntity {
func setCurrentRound(round: Int) -> Void { func setCurrentRound(round: Int) -> Void {
currentRoundLabel.text = "\(round)" currentRoundLabel.text = "\(round)"
let newRoundAction = SKAction.sequence([ let newRoundAction = SKAction.sequence([
SKAction.scale(by: 2, duration: 1), SKAction.scale(by: 2, duration: 1),
SKAction.scale(by: 0.5, duration: 1), SKAction.scale(by: 0.5, duration: 1),
]) ])
currentRoundLabel.run(newRoundAction) currentRoundLabel.run(newRoundAction)
} }
} }

View File

@ -53,11 +53,11 @@ class Modal: GKEntity{
switch modaltype { switch modaltype {
case .BaseAttack: case .BaseAttack:
header = SKLabelNode(text: "Angriff") header = SKLabelNode(text: "Angriff")
body = SKLabelNode(text: "Schicke \(unitCount / 2)\nEinheiten") body = SKLabelNode(text: "\(unitCount / 2) Einheiten")
footer = SKLabelNode() footer = SKLabelNode()
case .BaseMoveOwnUnits: case .BaseMoveOwnUnits:
header = SKLabelNode(text: "Formation") header = SKLabelNode(text: "Formation")
body = SKLabelNode(text: "Sende \(unitCount / 2)\nEinheiten") body = SKLabelNode(text: "\(unitCount / 2) Einheiten")
footer = SKLabelNode() footer = SKLabelNode()
case .PauseGame: case .PauseGame:
header = SKLabelNode(text: "Pause") header = SKLabelNode(text: "Pause")
@ -70,15 +70,15 @@ class Modal: GKEntity{
self.header.fontName = "HelveticaNeue-Bold" self.header.fontName = "HelveticaNeue-Bold"
self.header.fontSize = 40 self.header.fontSize = 40
self.header.zPosition = 5 self.header.zPosition = 5
self.body.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y - 20) self.body.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y + 15)
self.body.numberOfLines = 2 self.body.numberOfLines = 2
self.body.preferredMaxLayoutWidth = 390 self.body.preferredMaxLayoutWidth = 390
self.body.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.center self.body.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.center
self.body.fontName = "HelveticaNeue-Bold" self.body.fontName = "HelveticaNeue-Bold"
self.body.fontSize = 40 self.body.fontSize = 40
self.body.zPosition = 5 self.body.zPosition = 5
self.footer.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y - 40) self.footer.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y - 40)
self.footer.fontName = "HelveticaNeue-Bold" self.footer.fontName = "HelveticaNeue-Bold"
self.footer.fontSize = 40 self.footer.fontSize = 40
@ -86,17 +86,14 @@ class Modal: GKEntity{
super.init() super.init()
switch modaltype{
case .BaseAttack, .BaseMoveOwnUnits: let text = (modaltype == .BaseAttack) ? "Angriff" : "Senden"
let text = (modaltype == .BaseAttack) ? "Angriff" : "Senden" addComponent(SliderComponent(width: 300, position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 15)))
addComponent(SliderComponent(width: 300, position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 50))) addComponent(ButtonComponent(textureName: "yellow_button04", text: text, position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 95), isEnabled: true, onButtonPress: {
addComponent(ButtonComponent(textureName: "yellow_button04", text: text, position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 105), isEnabled: true, onButtonPress: { self.sendUnits(currentDraggedBase: currentDraggedBase, touchLocation: touchLocation!, gameScene: gameScene, collisionBase: collisionBase)
self.sendUnits(currentDraggedBase: currentDraggedBase, touchLocation: touchLocation!, gameScene: gameScene, collisionBase: collisionBase) EntityManager.gameEMInstance.removeModal()
EntityManager.gameEMInstance.removeModal() }))
}))
default:
break
}
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {

View File

@ -11,9 +11,28 @@ import GameplayKit
class SpinningLogoEntity: GKEntity { class SpinningLogoEntity: GKEntity {
init(position: CGPoint) { let spinningLogoNode : SpinningLogo3DNode
let goldLetteringNode : SKSpriteNode
let warsLetteringNode : SKSpriteNode
init(sceneSize size: CGSize) {
spinningLogoNode = SpinningLogo3DNode()
let midX = size.width / 2
let midY = size.height / 2
goldLetteringNode = SKSpriteNode(texture: SKTexture(imageNamed: "goldLettering"))
goldLetteringNode.position = CGPoint(x: midX, y: midY);
goldLetteringNode.size = CGSize(width: 675, height: 284)
goldLetteringNode.position = CGPoint(x: midX , y: midY + 280);
goldLetteringNode.size = CGSize(width: 675, height: 284)
warsLetteringNode = SKSpriteNode(texture: SKTexture(imageNamed: "warsLettering"))
warsLetteringNode.position = CGPoint(x: midX, y: midY - 300);
warsLetteringNode.size = CGSize(width: 700, height: 284)
spinningLogoNode.viewportSize = CGSize(width: 200, height: 200)
spinningLogoNode.zPosition = goldLetteringNode.zPosition - 1
spinningLogoNode.position = CGPoint(x: midX - 65, y: midY + 285);
super.init() super.init()
self.addComponent(SpinningLogoComponent(position: position))
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {

View File

@ -39,7 +39,7 @@ class Way: GKEntity {
self.localWayComponent.strokeColor = UIColor(red: 0.852, green: 0.649, blue: 0.123, alpha: 1) self.localWayComponent.strokeColor = UIColor(red: 0.852, green: 0.649, blue: 0.123, alpha: 1)
self.localWayComponent.lineWidth = 10 self.localWayComponent.lineWidth = 10
self.localWayComponent.zPosition = 0 self.localWayComponent.zPosition = 0
self.localWayComponent.name = "way"
super.init() super.init()
} }

View File

@ -29,7 +29,7 @@ struct State: Codable {
final class GameCenterManager: NSObject, GKMatchmakerViewControllerDelegate, GKGameCenterControllerDelegate ,GKMatchDelegate,GKLocalPlayerListener{ final class GameCenterManager: NSObject, GKMatchmakerViewControllerDelegate, GKGameCenterControllerDelegate ,GKMatchDelegate,GKLocalPlayerListener{
static let sharedInstance = GameCenterManager() static var sharedInstance = GameCenterManager()
let LOG = OSLog.init(subsystem: "GameCenterManager", category: "GameCenterManager") let LOG = OSLog.init(subsystem: "GameCenterManager", category: "GameCenterManager")
@ -44,6 +44,8 @@ final class GameCenterManager: NSObject, GKMatchmakerViewControllerDelegate, GKG
var entityManager = EntityManager.gameEMInstance var entityManager = EntityManager.gameEMInstance
var localPlayerRandomNumber: RandomNumber? var localPlayerRandomNumber: RandomNumber?
var initIsFinish = false var initIsFinish = false
var gameEnded = false
var winner: String?
var gameScene: GameScene? var gameScene: GameScene?
static var isAuthenticated: Bool { static var isAuthenticated: Bool {
return GKLocalPlayer.local.isAuthenticated return GKLocalPlayer.local.isAuthenticated
@ -56,6 +58,16 @@ final class GameCenterManager: NSObject, GKMatchmakerViewControllerDelegate, GKG
localPlayerRandomNumber = RandomNumber() localPlayerRandomNumber = RandomNumber()
} }
func reset() {
isMatchStarted = false
isServer = false
localPlayerRandomNumber = RandomNumber()
initIsFinish = false
gameEnded = false
winner = nil
gameScene = nil
}
func authUser() -> Void { func authUser() -> Void {
GKLocalPlayer.local.authenticateHandler = { gcAuthVC, error in GKLocalPlayer.local.authenticateHandler = { gcAuthVC, error in
NotificationCenter.default NotificationCenter.default
@ -108,77 +120,6 @@ final class GameCenterManager: NSObject, GKMatchmakerViewControllerDelegate, GKG
} }
} }
} }
func submitLeaderboardScore(identifier: String, score: Int64) {
let reportedScore = GKScore(leaderboardIdentifier: identifier)
reportedScore.value = score
GKScore.report([reportedScore]) { (error) in
guard error == nil else {
print(error?.localizedDescription ?? "")
return
}
}
}
func calculateLeaderboardScore(identifier: String, scoreOffset: Int64) {
GKLeaderboard.loadLeaderboards { (leaderboards: [GKLeaderboard]?, err: Error?) in
leaderboards?.forEach({ (leaderboard: GKLeaderboard) in
if leaderboard.identifier == identifier {
leaderboard.loadScores { (scores: [GKScore]?, err: Error?) in
scores?.forEach({ (score: GKScore) in
if score.player == self.localPlayer {
score.value += scoreOffset
GKScore.report([score]) { (error) in
guard error == nil else {
print(error?.localizedDescription ?? "")
return
}
}
}
})
}
}
})
}
}
//TODO: not finished -> DELETE if not usefull
// Possible way to implement matchmaking based on 2 players
// can be changed into method with fixed leaderboard and offset, boolean hasWon: true/false to calculate outcome of a match
func calculateLeaderboardScoreExperimentalMatchmaking(identifier: String, scoreOffset: Int64, opponentPlayer: GKPlayer) {
// Iterate through leaderboards
GKLeaderboard.loadLeaderboards { (leaderboards: [GKLeaderboard]?, err: Error?) in
leaderboards?.forEach({ (leaderboard: GKLeaderboard) in
if leaderboard.identifier == identifier {
leaderboard.loadScores { (scores: [GKScore]?, err: Error?) in
// Iterate through scores
var currentScore: GKScore = GKScore.init()
currentScore.value = -1
var opponetScore: GKScore = GKScore.init()
currentScore.value = 0
// Get scores of self and opponent
scores?.forEach({ (score: GKScore) in
if score.player == self.localPlayer {
currentScore = score
opponetScore = score
}
if score.player == opponentPlayer {
opponetScore = score
}
})
// do silly calculation
currentScore.value += scoreOffset + (opponetScore.value - currentScore.value)
GKScore.report([currentScore]) { (error) in
guard error == nil else {
print(error?.localizedDescription ?? "")
return
}
}
}
}
})
}
}
func match(_ match: GKMatch, didReceive data: Data, fromRemotePlayer player: GKPlayer) { func match(_ match: GKMatch, didReceive data: Data, fromRemotePlayer player: GKPlayer) {
if myMatch != match { return } if myMatch != match { return }
@ -225,10 +166,12 @@ final class GameCenterManager: NSObject, GKMatchmakerViewControllerDelegate, GKG
os_log("Spiel startet", log: LOG, type: .info) os_log("Spiel startet", log: LOG, type: .info)
case 4: case 4:
os_log("State 4 erhalten, Peer hat verloren", log: LOG, type: .info) os_log("State 4 erhalten, Peer hat verloren", log: LOG, type: .info)
// TODO: Trigger Loser Scene winner = hostingPlayer?.displayName
gameEnded = true
case 5: case 5:
os_log("State 5 erhalten, Peer hat gewonnen", log: LOG, type: .info) os_log("State 5 erhalten, Peer hat gewonnen", log: LOG, type: .info)
// TODO: Trigger Winner Scene winner = peerPlayer?.displayName
gameEnded = true
default: default:
break break
} }
@ -261,6 +204,15 @@ final class GameCenterManager: NSObject, GKMatchmakerViewControllerDelegate, GKG
os_log("Notification erhalten", log: LOG, type: .info) os_log("Notification erhalten", log: LOG, type: .info)
NotificationCenter.default.post(name: Notification.Name(rawValue: notification.name), object: nil) NotificationCenter.default.post(name: Notification.Name(rawValue: notification.name), object: nil)
} }
if let eloData = try? jsonDecoder.decode(EloDataForPeer.self, from: data) {
print("Recieved elo data: \(eloData.scoreToReport)")
let score = GKScore(leaderboardIdentifier: EloHelper.IDENTIFIER, player: self.localPlayer)
score.value = eloData.scoreToReport
GKScore.report([score], withCompletionHandler: { error in
os_log("New Scores reported to EloSystem", log: self.LOG, type: .info)
})
}
MultiplayerNetwork.sharedInstance.isSending = false MultiplayerNetwork.sharedInstance.isSending = false
} }

View File

@ -11,7 +11,6 @@ import SpriteKit
import GameplayKit import GameplayKit
class GameViewController: UIViewController { class GameViewController: UIViewController {
public static let sharedInstance = GameViewController();
var currentScene: SKView? var currentScene: SKView?
override func viewDidLoad() { override func viewDidLoad() {
@ -44,4 +43,5 @@ class GameViewController: UIViewController {
override var prefersStatusBarHidden: Bool { override var prefersStatusBarHidden: Bool {
return true return true
} }
} }

View File

@ -15,15 +15,15 @@ class MultiplayerNetwork{
var isSending = false var isSending = false
func sendData(data: Data) { func sendData(data: Data) {
let mmHelper = GameCenterManager.sharedInstance let mmHelper = GameCenterManager.sharedInstance
if let multiplayerMatch = mmHelper.myMatch { if let multiplayerMatch = mmHelper.myMatch {
do { do {
try multiplayerMatch.sendData(toAllPlayers: data, with: .reliable) try multiplayerMatch.sendData(toAllPlayers: data, with: .reliable)
} catch { } catch {
} }
} }
} }
func sendDataToHost(data: Data) { func sendDataToHost(data: Data) {
@ -38,7 +38,6 @@ class MultiplayerNetwork{
func sendPlayerMoves(localRoundData: LocalRoundData) { func sendPlayerMoves(localRoundData: LocalRoundData) {
if GameCenterManager.sharedInstance.isServer == false { if GameCenterManager.sharedInstance.isServer == false {
print("I am client")
self.isSending = true self.isSending = true
let encoder = JSONEncoder() let encoder = JSONEncoder()
let encoded = (try? encoder.encode(localRoundData))! let encoded = (try? encoder.encode(localRoundData))!
@ -61,6 +60,12 @@ class MultiplayerNetwork{
sendData(data: encoded) sendData(data: encoded)
} }
func sendEloData(scoreToReport: GKScore) {
let encoder = JSONEncoder()
let encoded = (try? encoder.encode(EloDataForPeer(scoreToReport: scoreToReport.value)))!
sendData(data: encoded)
}
func sendNotificationToPlayer(name: String) { func sendNotificationToPlayer(name: String) {
let encoder = JSONEncoder() let encoder = JSONEncoder()
let encoded = (try? encoder.encode(NotificationModel(name: name)))! let encoded = (try? encoder.encode(NotificationModel(name: name)))!

Binary file not shown.

Binary file not shown.

View File

@ -158,7 +158,16 @@ class RoundCalculatorService {
winner = determineWinner(by: "capture") winner = determineWinner(by: "capture")
} }
winner == GameCenterManager.sharedInstance.hostingPlayer?.displayName ? GameCenterManager.sharedInstance.sendStateToPeers(state: State(state: 4)) : GameCenterManager.sharedInstance.sendStateToPeers(state: State(state: 5)) winner == GameCenterManager.sharedInstance.hostingPlayer?.displayName ? GameCenterManager.sharedInstance.sendStateToPeers(state: State(state: 4)) : GameCenterManager.sharedInstance.sendStateToPeers(state: State(state: 5))
//TODO: Trigger Winner/Loser-Scene for Server GameCenterManager.sharedInstance.winner = winner
GameCenterManager.sharedInstance.gameEnded = true
// Update EloSystem
if winner == GameCenterManager.sharedInstance.hostingPlayer?.displayName {
EloHelper.updateEloScore(winner: GameCenterManager.sharedInstance.hostingPlayer!, hatDenNikoGemacht: GameCenterManager.sharedInstance.peerPlayer!)
} else {
EloHelper.updateEloScore(winner: GameCenterManager.sharedInstance.peerPlayer!, hatDenNikoGemacht: GameCenterManager.sharedInstance.hostingPlayer!)
}
return return
} }
currentRound += 1 currentRound += 1

View File

@ -30,7 +30,9 @@ class RoundTimer: Timer {
} }
func stopTimer() { func stopTimer() {
guard timer != nil else { return }
timer?.invalidate() timer?.invalidate()
timer = nil
} }
func resumeTimer() { func resumeTimer() {
@ -46,7 +48,6 @@ class RoundTimer: Timer {
@objc func onTimerFires() @objc func onTimerFires()
{ {
timeLeft -= 1 timeLeft -= 1
EntityManager.gameEMInstance.updateTime(time: (timeLeft > 0 ? String(timeLeft) : roundEnded)) EntityManager.gameEMInstance.updateTime(time: (timeLeft > 0 ? String(timeLeft) : roundEnded))
if timeLeft == 0 { if timeLeft == 0 {
@ -57,14 +58,17 @@ class RoundTimer: Timer {
} }
calculate = true calculate = true
} }
if timeLeft <= 0 { if timeLeft <= 0 {
if calculate if calculate
&& !RoundCalculatorService.sharedInstance.isCalculating && !RoundCalculatorService.sharedInstance.isCalculating
&& DataService.sharedInstance.didReceiveAllData() && DataService.sharedInstance.didReceiveAllData()
&& GameCenterManager.sharedInstance.isServer { && GameCenterManager.sharedInstance.isServer {
RoundCalculatorService.sharedInstance.calculateRound() RoundCalculatorService.sharedInstance.calculateRound()
calculate = false calculate = false
} }
} }
} }
} }

View File

@ -18,6 +18,7 @@ class GameScene: SKScene{
var currentDraggedBase : Base? var currentDraggedBase : Base?
static var sendUnits: Int = 0 static var sendUnits: Int = 0
var collisionBase: Base? var collisionBase: Base?
var gameEndEffects = false
override func sceneDidLoad() { override func sceneDidLoad() {
entityManager.setScene(scene: self) entityManager.setScene(scene: self)
@ -25,8 +26,8 @@ class GameScene: SKScene{
entityManager.add(Background(size: self.size)) entityManager.add(Background(size: self.size))
if CommandLine.arguments.contains("--no-matchmaking") { if CommandLine.arguments.contains("--no-matchmaking") {
_ = MapFactory(scene: self, entityManager: entityManager).load() _ = MapFactory(scene: self, entityManager: entityManager).load()
return
} }
return
} }
override func didMove(to view: SKView) { override func didMove(to view: SKView) {
@ -77,6 +78,10 @@ class GameScene: SKScene{
override func update(_ currentTime: TimeInterval) { override func update(_ currentTime: TimeInterval) {
entityManager.getBackground()?.update(deltaTime: currentTime) entityManager.getBackground()?.update(deltaTime: currentTime)
if GameCenterManager.sharedInstance.gameEnded && !gameEndEffects {
gameEnd()
}
} }
func addAttackDetails(touchLocation: CGPoint){ func addAttackDetails(touchLocation: CGPoint){
@ -115,12 +120,102 @@ class GameScene: SKScene{
} else if Int(GameScene.sendUnits) == currentDraggedBase?.unitCount { } else if Int(GameScene.sendUnits) == currentDraggedBase?.unitCount {
GameScene.sendUnits -= 1 GameScene.sendUnits -= 1
} }
modal.body.text = "Schicke \(GameScene.sendUnits) Einheiten " modal.body.text = "\(GameScene.sendUnits) Einheiten "
} }
} }
} }
} }
func gameEnd(){
entityManager.getHUD()?.blockWholeScreenPane.isHidden = true
gameEndEffects = true
GameCenterManager.sharedInstance.gameEnded = false
let move = SKAction.move(to: CGPoint(x: self.size.width / 2, y: self.size.height / 2), duration: 1)
let removeParticle = SKAction.removeFromParent()
let sequence = SKAction.sequence([move, removeParticle])
var actionAdded = false
for nodeChild in children {
if nodeChild.name == "peerLabel" || nodeChild.name == "hostLabel"{
continue
}
if nodeChild.name == "way" {
nodeChild.run(SKAction.removeFromParent())
continue
}
if nodeChild.name != "clouds"{
nodeChild.run(sequence) {
if !actionAdded {
let explosion = self.getFinalExplosion()
self.addChild(explosion)
let action = SKAction.afterDelay(2) {
(self.childNode(withName: "hostLabel") as! SKLabelNode).horizontalAlignmentMode = .center
(self.childNode(withName: "peerLabel") as! SKLabelNode).horizontalAlignmentMode = .center
self.childNode(withName: "hostLabel")?.run(SKAction.move(to: CGPoint(x: self.size.width * 0.25, y: self.size.height * 0.3), duration: 1))
self.childNode(withName: "peerLabel")?.run(SKAction.move(to: CGPoint(x: self.size.width * 0.75, y: self.size.height * 0.3), duration: 1))
self.initGameEndIcons()
let node = ButtonNode(textureName: "yellow_button05", text: "Menu", isEnabled: true, position: CGPoint(x: self.size.width / 2, y: self.size.height / 2 - 300), onButtonPress: {
self.backToMenuAction()
})
node.name = "BackButton"
self.addChild(node)
}
explosion.run(action)
actionAdded = true
}
}
}
}
}
func initGameEndIcons() {
let iclonSize = CGSize(width: 400, height: 400)
let winnerIcon = SKSpriteNode(texture: SKTexture(imageNamed: "winner"));
winnerIcon.size = iclonSize
let loserIcon = SKSpriteNode(texture: SKTexture(imageNamed: "BaseTexture"))
loserIcon.size = iclonSize
let loserFire = SKEmitterNode(fileNamed: "LoserFire")
loserFire?.zPosition = loserIcon.zPosition - 1
loserFire?.run(SKAction.scale(by: 4, duration: 8))
let iconPosition1 = CGPoint(x: self.size.width * 0.25, y: self.size.height * 0.55)
let iconPosition2 = CGPoint(x: self.size.width * 0.75, y: self.size.height * 0.55)
let coin = SpinningLogo3DNode()
if GameCenterManager.sharedInstance.winner == GameCenterManager.sharedInstance.hostingPlayer?.displayName {
winnerIcon.position = iconPosition1
coin.position = iconPosition1
loserIcon.position = iconPosition2
loserFire?.position = iconPosition2
} else {
winnerIcon.position = iconPosition2
coin.position = iconPosition2
loserIcon.position = iconPosition1
loserFire?.position = iconPosition1
}
self.addChild(winnerIcon)
self.addChild(coin)
self.addChild(loserIcon)
self.addChild(loserFire!)
}
func getFinalExplosion() -> SKEmitterNode {
let explosion = SKEmitterNode(fileNamed: "Explosion")!
explosion.zPosition = 2
explosion.position = CGPoint(x: self.size.width / 2, y: self.size.height / 2)
explosion.name = "explosion"
explosion.particleColorSequence = nil
explosion.particleColorBlendFactor = 1.0
return explosion
}
func backToMenuAction() {
GameCenterManager.sharedInstance.reset()
self.gameEndEffects = false
entityManager.getTimer()?.stopTimer()
RoundCalculatorService.sharedInstance.currentRound = 1
self.view?.presentScene(MenuScene(size: self.size))
entityManager.entities.removeAll()
self.removeFromParent()
}
func checkBases(bases: Set<Base>, touchLocation: CGPoint){ func checkBases(bases: Set<Base>, touchLocation: CGPoint){
for base in bases { for base in bases {
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode { if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode {
@ -173,6 +268,8 @@ class GameScene: SKScene{
} }
@objc func pauseGame() -> Void { @objc func pauseGame() -> Void {
entityManager.removeModal()
entityManager.getHUD()?.roundTimer.stopTimer()
entityManager.add(Modal(modaltype: .PauseGame, entityManager.add(Modal(modaltype: .PauseGame,
base: nil, base: nil,
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),
@ -180,8 +277,7 @@ class GameScene: SKScene{
currentDraggedBase: nil, currentDraggedBase: nil,
touchLocation: nil, touchLocation: nil,
collisionBase: nil collisionBase: nil
)) ))
entityManager.getHUD()?.roundTimer.stopTimer()
} }
@objc func resumeGame() -> Void { @objc func resumeGame() -> Void {
entityManager.removeModal() entityManager.removeModal()

View File

@ -18,9 +18,9 @@ class MenuScene: SKScene {
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.add(Button(name: "startGameButton", entityManager.add(Button(name: "startGameButton",
textureName: "yellow_button04", textureName: "gold_button_3",
text: "Start Game", text: "Start Game",
position: CGPoint(x: midX, y: midY), position: CGPoint(x: midX, y: midY + 90),
onButtonPress: { onButtonPress: {
if CommandLine.arguments.contains("--no-matchmaking") { if CommandLine.arguments.contains("--no-matchmaking") {
self.loadScene(scene: GameScene(size: self.size)) self.loadScene(scene: GameScene(size: self.size))
@ -35,17 +35,17 @@ class MenuScene: SKScene {
} }
})) }))
entityManager.add(Button(name: "settingsButton", entityManager.add(Button(name: "settingsButton",
textureName: "yellow_button04", textureName: "gold_button_3",
text: "Settings", text: "Settings",
position: CGPoint(x: midX, y: midY - 80 ), position: CGPoint(x: midX, y: midY ),
onButtonPress: { onButtonPress: {
let scene = SettingsScene(size: self.size) let scene = SettingsScene(size: self.size)
self.loadScene(scene: scene) self.loadScene(scene: scene)
})) }))
entityManager.add(Button(name: "gameCenterButton", entityManager.add(Button(name: "gameCenterButton",
textureName: "yellow_button04", textureName: "gold_button_3",
text: "GameCenter", text: "GameCenter",
position: CGPoint(x: midX, y: midY - 160), position: CGPoint(x: midX, y: midY - 90),
onButtonPress: { onButtonPress: {
if GameCenterManager.isAuthenticated { if GameCenterManager.isAuthenticated {
GameCenterManager.sharedInstance.presentGameCenter() GameCenterManager.sharedInstance.presentGameCenter()
@ -63,7 +63,7 @@ class MenuScene: SKScene {
self.loadScene(scene: scene) self.loadScene(scene: scene)
})) }))
entityManager.add(Background(size: self.size)) entityManager.add(Background(size: self.size))
entityManager.add(SpinningLogoEntity(position: CGPoint(x: midX, y: midY + 200))) entityManager.add(SpinningLogoEntity(sceneSize: self.size))
if SoundManager.sharedInstance.isMusicPlaying == false && SoundManager.sharedInstance.isMusicEnabled == true && !CommandLine.arguments.contains("--no-music") && !UserDefaults.standard.bool(forKey: "noMusic"){ if SoundManager.sharedInstance.isMusicPlaying == false && SoundManager.sharedInstance.isMusicEnabled == true && !CommandLine.arguments.contains("--no-music") && !UserDefaults.standard.bool(forKey: "noMusic"){
SoundManager.sharedInstance.startMenuMusic() SoundManager.sharedInstance.startMenuMusic()