Merge branch '20-timer-anbindung-an-gamecenter' into 'development'

Resolve "[TIMER] Anbindung an GameCenter"

See merge request marcel.schwarz/software-projekt-2!42
This commit is contained in:
Aldin Duraki 2020-05-07 18:43:34 +00:00
commit 5bd8aa2083
5 changed files with 71 additions and 3 deletions

View File

@ -17,6 +17,7 @@
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 */; };
2086465C2461B66200817C23 /* TimerComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2086465B2461B66200817C23 /* TimerComponent.swift */; };
3EBD242C245D8044003CECE7 /* GameCenterHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */; };
3EBD242E245D9332003CECE7 /* Team.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBD242D245D9332003CECE7 /* Team.swift */; };
9E04AFAF245E2B73002D5CFC /* AttackActionComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */; };
@ -72,6 +73,7 @@
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>"; };
2086465B2461B66200817C23 /* TimerComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimerComponent.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>"; };
9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttackActionComponent.swift; sourceTree = "<group>"; };
@ -186,6 +188,7 @@
9E174C85245DD91500209FF0 /* ButtonComponent.swift */,
9E174C87245DF1FF00209FF0 /* BackgroundComponent.swift */,
9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */,
2086465B2461B66200817C23 /* TimerComponent.swift */,
9EBFD7542462CF5A00E1E219 /* SliderComponent.swift */,
9EC7E48A2461FBF700396BCD /* SliderNode.swift */,
);
@ -390,6 +393,7 @@
9EC7E48B2461FBF700396BCD /* SliderNode.swift in Sources */,
9E174C84245DD8CE00209FF0 /* Button.swift in Sources */,
110360DB244B101A008610AF /* GameViewController.swift in Sources */,
2086465C2461B66200817C23 /* TimerComponent.swift in Sources */,
110360D3244B101A008610AF /* AppDelegate.swift in Sources */,
9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */,
9E78ACC2245CC9EE00526FF7 /* DefBoostSkillComponent.swift in Sources */,

View File

@ -0,0 +1,56 @@
//
// TimerComponent.swift
// GoldWars
//
// Created by Daniel Steckert on 05.05.20.
// Copyright © 2020 SP2. All rights reserved.
//
import GameplayKit
class TimerComponent: GKComponent {
let labelNode :SKLabelNode
var endTime :Date!
var duration :Double
init(text: String, anchorPoint: CGPoint, duration: TimeInterval) {
self.labelNode = SKLabelNode(text: text)
self.labelNode.fontColor = UIColor.black
self.labelNode.fontSize = CGFloat(45)
self.labelNode.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y - 15)
self.duration = duration + 1
super.init()
startWithDuration(duration: self.duration)
}
func startWithDuration(duration: TimeInterval){
endTime = Date().addingTimeInterval(duration)
}
func timeLeft() -> Int {
let remainingSeconds = Int(endTime.timeIntervalSince(Date()))
if(remainingSeconds < 0 ){
startWithDuration(duration: duration)
}
return remainingSeconds
}
func isFinished() -> Bool {
return timeLeft() == 0
}
func update() {
self.labelNode.text = String(timeLeft())
if(isFinished()){
self.labelNode.text = "Synching"
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

View File

@ -49,6 +49,9 @@ class EntityManager {
scene.addChild(skill.shapeNode)
scene.addChild(skill.labelNode)
}
if let timer = entity.component(ofType: TimerComponent.self) {
scene.addChild(timer.labelNode)
}
if let buttonNode = entity.component(ofType: ButtonComponent.self)?.buttonNode {
scene.addChild(buttonNode)
}
@ -136,6 +139,8 @@ class EntityManager {
func getButtonByName(buttonName:String) -> Button {
return entities.filter{$0 is Button && ($0 as! Button).name == buttonName }[0] as! Button
}
func getHUD() -> GKEntity? {
return entities.filter{$0 is HUD}[0]
}
}

View File

@ -25,7 +25,9 @@ class HUD: GKEntity {
addComponent(DefBoostSkillComponent(text: "Def",
texture: nil,
anchorPoint: CGPoint(x: size.width * 0.95, y: size.height * 0.1)))
addComponent(TimerComponent(text: "",
anchorPoint: CGPoint(x: size.width * 0.5, y: size.height * 0.9), duration: 30))
}
required init?(coder: NSCoder) {

View File

@ -130,5 +130,6 @@ class GameScene: SKScene{
override func update(_ currentTime: TimeInterval) {
entityManager.getBackground()?.update(deltaTime: currentTime)
entityManager.getHUD()?.component(ofType: TimerComponent.self)?.update()
}
}