create GameEnd Animation
This commit is contained in:
parent
b29111cb9e
commit
3082297415
29
GoldWars/GoldWars/Components/DefaultWayComponent.swift
Normal file
29
GoldWars/GoldWars/Components/DefaultWayComponent.swift
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
//
|
||||||
|
// DefaultWayComponent.swift
|
||||||
|
// GoldWars
|
||||||
|
//
|
||||||
|
// Created by Jakob Haag on 18.05.20.
|
||||||
|
// Copyright © 2020 SP2. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import GameplayKit
|
||||||
|
import SpriteKit
|
||||||
|
|
||||||
|
class DefaultWayComponent: GKComponent {
|
||||||
|
var shapeNode: SKShapeNode
|
||||||
|
|
||||||
|
init(pathToDraw: CGMutablePath) {
|
||||||
|
self.shapeNode = SKShapeNode()
|
||||||
|
shapeNode.path = pathToDraw
|
||||||
|
shapeNode.strokeColor = UIColor(red: 0.852, green: 0.649, blue: 0.123, alpha: 1)
|
||||||
|
shapeNode.lineWidth = 10
|
||||||
|
shapeNode.zPosition = 0
|
||||||
|
shapeNode.name = "way"
|
||||||
|
super.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder aDecoder: NSCoder) {
|
||||||
|
fatalError("init(coder:) has not been implemented")
|
||||||
|
}
|
||||||
|
}
|
@ -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")
|
||||||
|
|
||||||
@ -58,6 +58,17 @@ 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
|
||||||
|
@ -44,4 +44,5 @@ class GameViewController: UIViewController {
|
|||||||
override var prefersStatusBarHidden: Bool {
|
override var prefersStatusBarHidden: Bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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))!
|
||||||
|
@ -45,7 +45,6 @@ class RoundTimer: Timer {
|
|||||||
|
|
||||||
@objc func onTimerFires()
|
@objc func onTimerFires()
|
||||||
{
|
{
|
||||||
timeLeft -= 1
|
|
||||||
|
|
||||||
EntityManager.gameEMInstance.updateTime(time: (timeLeft > 0 ? String(timeLeft) : roundEnded))
|
EntityManager.gameEMInstance.updateTime(time: (timeLeft > 0 ? String(timeLeft) : roundEnded))
|
||||||
|
|
||||||
@ -55,8 +54,6 @@ class RoundTimer: Timer {
|
|||||||
if !MultiplayerNetwork.sharedInstance.isSending {
|
if !MultiplayerNetwork.sharedInstance.isSending {
|
||||||
MultiplayerNetwork.sharedInstance.sendPlayerMoves(localRoundData: DataService.sharedInstance.localRoundData)
|
MultiplayerNetwork.sharedInstance.sendPlayerMoves(localRoundData: DataService.sharedInstance.localRoundData)
|
||||||
}
|
}
|
||||||
calculate = true
|
|
||||||
}
|
|
||||||
if timeLeft <= 0 {
|
if timeLeft <= 0 {
|
||||||
if calculate
|
if calculate
|
||||||
&& !RoundCalculatorService.sharedInstance.isCalculating
|
&& !RoundCalculatorService.sharedInstance.isCalculating
|
||||||
@ -67,4 +64,8 @@ class RoundTimer: Timer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,10 +26,11 @@ 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()
|
||||||
|
// let node = ButtonNode(textureName: "yellow_button05", text: "Menu", isEnabled: true, position: CGPoint(x: self.size.width / 2, y: self.size.height / 2 - 200), onButtonPress: {self.view?.presentScene(MenuScene(size: self.size)) })
|
||||||
|
// self.addChild(node)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override func didMove(to view: SKView) {
|
override func didMove(to view: SKView) {
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(pauseGame), name: Notification.Name("pauseGame"), object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(pauseGame), name: Notification.Name("pauseGame"), object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(resumeGame), name: Notification.Name("resumeGame"), object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(resumeGame), name: Notification.Name("resumeGame"), object: nil)
|
||||||
@ -76,7 +78,12 @@ class GameScene: SKScene{
|
|||||||
}
|
}
|
||||||
|
|
||||||
override func update(_ currentTime: TimeInterval) {
|
override func update(_ currentTime: TimeInterval) {
|
||||||
|
if entityManager.entities.count != 0 {
|
||||||
entityManager.getBackground()?.update(deltaTime: currentTime)
|
entityManager.getBackground()?.update(deltaTime: currentTime)
|
||||||
|
if GameCenterManager.sharedInstance.gameEnded && !gameEndEffects {
|
||||||
|
gameEnd()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func addAttackDetails(touchLocation: CGPoint){
|
func addAttackDetails(touchLocation: CGPoint){
|
||||||
@ -121,6 +128,69 @@ class GameScene: SKScene{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func gameEnd(){
|
||||||
|
gameEndEffects = true
|
||||||
|
let winnerNode:String?
|
||||||
|
GameCenterManager.sharedInstance.gameEnded = false
|
||||||
|
|
||||||
|
|
||||||
|
if GameCenterManager.sharedInstance.isServer {
|
||||||
|
winnerNode = "hostLabel"
|
||||||
|
} else {
|
||||||
|
winnerNode = "peerLabel"
|
||||||
|
}
|
||||||
|
|
||||||
|
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 n = 0
|
||||||
|
for nodeChild in children {
|
||||||
|
if nodeChild.name == winnerNode {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if nodeChild.name == "way" {
|
||||||
|
nodeChild.run(SKAction.removeFromParent())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if nodeChild.name != "clouds"{
|
||||||
|
nodeChild.run(sequence,completion: {
|
||||||
|
if n < 1 {
|
||||||
|
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
|
||||||
|
self.addChild(explosion)
|
||||||
|
let action = SKAction.afterDelay(2) {
|
||||||
|
let size = SKAction.scale(by: 3, duration: 1)
|
||||||
|
(self.childNode(withName: winnerNode!) as! SKLabelNode).horizontalAlignmentMode = .center
|
||||||
|
self.childNode(withName: winnerNode!)?.run(SKAction.sequence([move,size]))
|
||||||
|
let node = ButtonNode(textureName: "yellow_button05", text: "Menu", isEnabled: true, position: CGPoint(x: self.size.width / 2, y: self.size.height / 2 - 200), onButtonPress: {
|
||||||
|
self.buttonPressed()
|
||||||
|
})
|
||||||
|
node.name = "BackButton"
|
||||||
|
self.addChild(node)
|
||||||
|
}
|
||||||
|
explosion.run(action)
|
||||||
|
n += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func buttonPressed() {
|
||||||
|
GameCenterManager.sharedInstance.reset();
|
||||||
|
self.gameEndEffects = false
|
||||||
|
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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user