Add Verlassen button with modal and end screen
This commit is contained in:
parent
17332f3f54
commit
3e35db1d42
@ -43,6 +43,10 @@ class ButtonNode: SKSpriteNode {
|
||||
self.addChild(label)
|
||||
isUserInteractionEnabled = true
|
||||
}
|
||||
|
||||
func setTexture(textureName: String) {
|
||||
super.texture = SKTexture(imageNamed: textureName)
|
||||
}
|
||||
|
||||
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
if isEnabled {
|
||||
|
@ -48,6 +48,7 @@ class EntityManager {
|
||||
scene.addChild(hudEntitiy.hostUnitsLabel)
|
||||
scene.addChild(hudEntitiy.peerLabel)
|
||||
scene.addChild(hudEntitiy.peerUnitsLabel)
|
||||
scene.addChild(hudEntitiy.leaveGame)
|
||||
scene.addChild(hudEntitiy.defSkill)
|
||||
scene.addChild(hudEntitiy.atkSkill)
|
||||
scene.addChild(hudEntitiy.spySkill)
|
||||
@ -357,6 +358,15 @@ class EntityManager {
|
||||
})
|
||||
}
|
||||
|
||||
func exitToMenu() {
|
||||
GameCenterManager.sharedInstance.reset()
|
||||
EntityManager.gameEMInstance.getTimer()?.stopTimer()
|
||||
RoundCalculatorService.sharedInstance.currentRound = 1
|
||||
EntityManager.gameEMInstance.scene.view?.presentScene(EntityManager.menuEMInstance.scene)
|
||||
EntityManager.gameEMInstance.entities.removeAll()
|
||||
EntityManager.gameEMInstance.scene.removeFromParent()
|
||||
}
|
||||
|
||||
func getTimer() -> RoundTimer? {
|
||||
return getHUD()?.roundTimer
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ class HUD: GKEntity {
|
||||
var peerLabel:SKLabelNode
|
||||
var peerUnitsLabel:SKLabelNode
|
||||
|
||||
var leaveGame: ButtonNode
|
||||
|
||||
var spySkill: SkillButtonNode
|
||||
var defSkill: SkillButtonNode
|
||||
var atkSkill: SkillButtonNode
|
||||
@ -50,6 +52,11 @@ class HUD: GKEntity {
|
||||
|
||||
self.roundTimer = RoundTimer()
|
||||
|
||||
leaveGame = ButtonNode(textureName: "yellow_button04", text: "Verlassen" , isEnabled: true, position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.17, y: EntityManager.gameEMInstance.scene.size.height * 0.04), onButtonPress: {
|
||||
EntityManager.gameEMInstance.add(Modal(modaltype: .QuitGame, base: nil, anchorPoint: CGPoint(x: EntityManager.gameEMInstance.scene.size.width / 2 , y: EntityManager.gameEMInstance.scene.size.height / 2), gameScene: EntityManager.gameEMInstance.scene, currentDraggedBase: nil, touchLocation: nil, collisionBase: nil))
|
||||
})
|
||||
leaveGame.setScale(0.6)
|
||||
|
||||
spySkill = SkillButtonNode(
|
||||
textureName: "spy_button",
|
||||
text: "Spy",
|
||||
@ -96,10 +103,11 @@ class HUD: GKEntity {
|
||||
isEnabled: true,
|
||||
position: CGPoint(
|
||||
x: EntityManager.gameEMInstance.scene.size.width * 0.17,
|
||||
y: EntityManager.gameEMInstance.scene.size.height * 0.06),
|
||||
y: EntityManager.gameEMInstance.scene.size.height * 0.09),
|
||||
onButtonPress: { }
|
||||
)
|
||||
finishButton.size = CGSize(width: 125, height: 40)
|
||||
finishButton.setScale(0.9)
|
||||
finishButton.zPosition = 2
|
||||
|
||||
backgroundRoundCounter = SKSpriteNode(texture: SKTexture(imageNamed: "roundInfo_texture"))
|
||||
|
@ -12,6 +12,7 @@ enum ModalType: String {
|
||||
case BaseAttack
|
||||
case BaseMoveOwnUnits
|
||||
case PauseGame
|
||||
case QuitGame
|
||||
}
|
||||
|
||||
class Modal: GKEntity{
|
||||
@ -26,7 +27,7 @@ class Modal: GKEntity{
|
||||
var overlay: SKSpriteNode
|
||||
var type: ModalType
|
||||
|
||||
init(modaltype: ModalType, base: Base?, anchorPoint: CGPoint, gameScene: GameScene, currentDraggedBase: Base?, touchLocation: CGPoint?, collisionBase: Base?) {
|
||||
init(modaltype: ModalType, base: Base?, anchorPoint: CGPoint, gameScene: SKScene, currentDraggedBase: Base?, touchLocation: CGPoint?, collisionBase: Base?) {
|
||||
self.type = modaltype
|
||||
unitCount = 0
|
||||
if base != nil {
|
||||
@ -64,6 +65,10 @@ class Modal: GKEntity{
|
||||
body = SKLabelNode(text: "Warte auf Gegner...")
|
||||
footer = SKLabelNode()
|
||||
closeButton.zPosition = -1
|
||||
case .QuitGame:
|
||||
header = SKLabelNode(text: "Spiel verlassen")
|
||||
body = SKLabelNode(text: "Sicher verlassen?")
|
||||
footer = SKLabelNode()
|
||||
}
|
||||
|
||||
self.header.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y + 90)
|
||||
@ -86,13 +91,25 @@ class Modal: GKEntity{
|
||||
|
||||
super.init()
|
||||
|
||||
switch modaltype {
|
||||
case .BaseAttack, .BaseMoveOwnUnits:
|
||||
let text = (modaltype == .BaseAttack) ? "Angriff" : "Senden"
|
||||
addComponent(SliderComponent(width: 300, position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 15)))
|
||||
addComponent(ButtonComponent(textureName: "yellow_button04", text: text, position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 95), isEnabled: true, onButtonPress: {
|
||||
self.sendUnits(currentDraggedBase: currentDraggedBase, touchLocation: touchLocation!, gameScene: gameScene, collisionBase: collisionBase)
|
||||
EntityManager.gameEMInstance.removeModal()
|
||||
}))
|
||||
case .QuitGame:
|
||||
addComponent(ButtonComponent(textureName: "yellow_button04", text: "Verlassen", position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 95), isEnabled: true, onButtonPress: {
|
||||
EntityManager.gameEMInstance.removeModal()
|
||||
GameCenterManager.sharedInstance.sendStateToPeers(state: State(state: 6))
|
||||
GameCenterManager.sharedInstance.opponentQuit = false
|
||||
GameCenterManager.sharedInstance.quitGame = true
|
||||
}))
|
||||
case .PauseGame:
|
||||
print("")
|
||||
}
|
||||
|
||||
let text = (modaltype == .BaseAttack) ? "Angriff" : "Senden"
|
||||
addComponent(SliderComponent(width: 300, position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 15)))
|
||||
addComponent(ButtonComponent(textureName: "yellow_button04", text: text, position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 95), isEnabled: true, onButtonPress: {
|
||||
self.sendUnits(currentDraggedBase: currentDraggedBase, touchLocation: touchLocation!, gameScene: gameScene, collisionBase: collisionBase)
|
||||
EntityManager.gameEMInstance.removeModal()
|
||||
}))
|
||||
|
||||
}
|
||||
|
||||
@ -108,7 +125,7 @@ class Modal: GKEntity{
|
||||
}
|
||||
}
|
||||
|
||||
func sendUnits(currentDraggedBase: Base?, touchLocation: CGPoint, gameScene: GameScene, collisionBase: Base?){
|
||||
func sendUnits(currentDraggedBase: Base?, touchLocation: CGPoint, gameScene: SKScene, collisionBase: Base?){
|
||||
for base in currentDraggedBase!.adjacencyList {
|
||||
if base == collisionBase {
|
||||
RoundCalculatorService.sharedInstance.increaseMoveCounter(ownBase: currentDraggedBase?.ownershipPlayer == base.ownershipPlayer)
|
||||
|
@ -24,6 +24,7 @@ struct State: Codable {
|
||||
// 3 Host hat Spiel gestartet
|
||||
// 4 Peer hat verloren
|
||||
// 5 Peer hat gewonnen
|
||||
// 6 Peer hat Spiel verlassen
|
||||
let state: Int
|
||||
}
|
||||
|
||||
@ -47,6 +48,8 @@ final class GameCenterManager: NSObject, GKMatchmakerViewControllerDelegate, GKG
|
||||
var gameEnded = false
|
||||
var winner: String?
|
||||
var gameScene: GameScene?
|
||||
var quitGame: Bool = false
|
||||
var opponentQuit: Bool = false
|
||||
static var isAuthenticated: Bool {
|
||||
return GKLocalPlayer.local.isAuthenticated
|
||||
}
|
||||
@ -171,6 +174,10 @@ final class GameCenterManager: NSObject, GKMatchmakerViewControllerDelegate, GKG
|
||||
os_log("State 5 erhalten, Peer hat gewonnen", log: LOG, type: .info)
|
||||
winner = peerPlayer?.displayName
|
||||
gameEnded = true
|
||||
case 6:
|
||||
os_log("State 6 erhalten, Peer hat Spiel verlassen ", log: LOG, type: .info)
|
||||
opponentQuit = true
|
||||
quitGame = true
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
@ -81,9 +81,12 @@ class GameScene: SKScene{
|
||||
if GameCenterManager.sharedInstance.gameEnded && !gameEndEffects {
|
||||
gameEnd()
|
||||
}
|
||||
|
||||
if GameCenterManager.sharedInstance.quitGame {
|
||||
gameQuit()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func addAttackDetails(touchLocation: CGPoint){
|
||||
for base in currentDraggedBase!.adjacencyList {
|
||||
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode {
|
||||
@ -167,6 +170,66 @@ class GameScene: SKScene{
|
||||
}
|
||||
}
|
||||
|
||||
func gameQuit() {
|
||||
entityManager.getHUD()?.blockWholeScreenPane.isHidden = true
|
||||
gameEndEffects = true
|
||||
GameCenterManager.sharedInstance.quitGame = 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"{
|
||||
nodeChild.removeFromParent()
|
||||
}
|
||||
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) {
|
||||
|
||||
|
||||
let node = ButtonNode(textureName: "yellow_button05", text: "Menü", 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let disconnectLabel = SKLabelNode.init(fontNamed: "Courier-Bold")
|
||||
disconnectLabel.position = CGPoint(x: self.size.width/2, y: self.size.height/2)
|
||||
disconnectLabel.horizontalAlignmentMode = .center
|
||||
disconnectLabel.fontColor = UIColor.black
|
||||
disconnectLabel.alpha = 0
|
||||
disconnectLabel.setScale(0.1)
|
||||
if GameCenterManager.sharedInstance.opponentQuit {
|
||||
if GameCenterManager.sharedInstance.localPlayer == GameCenterManager.sharedInstance.hostingPlayer {
|
||||
disconnectLabel.text = GameCenterManager.sharedInstance.peerPlayer?.displayName
|
||||
} else {
|
||||
disconnectLabel.text = GameCenterManager.sharedInstance.hostingPlayer?.displayName
|
||||
}
|
||||
disconnectLabel.text?.append(" hat das Spiel verlassen!")
|
||||
} else {
|
||||
disconnectLabel.text = "Du hast das Spiel verlassen!"
|
||||
}
|
||||
let showUpAnimation = SKAction.sequence([
|
||||
SKAction.fadeAlpha(by: 1, duration: 2.5),
|
||||
SKAction.scale(by: 10, duration: 1),
|
||||
])
|
||||
disconnectLabel.run(showUpAnimation)
|
||||
self.addChild(disconnectLabel)
|
||||
}
|
||||
|
||||
func initGameEndIcons() {
|
||||
let iclonSize = CGSize(width: 400, height: 400)
|
||||
let winnerIcon = SKSpriteNode(texture: SKTexture(imageNamed: "winner"));
|
||||
@ -270,6 +333,8 @@ class GameScene: SKScene{
|
||||
return collisionBase?.ownershipPlayer != currentDraggedBase?.ownershipPlayer && !(collisionBase?.changeOwnership ?? false)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@objc func pauseGame() -> Void {
|
||||
entityManager.removeModal()
|
||||
entityManager.getHUD()?.roundTimer.stopTimer()
|
||||
@ -282,6 +347,7 @@ class GameScene: SKScene{
|
||||
collisionBase: nil
|
||||
))
|
||||
}
|
||||
|
||||
@objc func resumeGame() -> Void {
|
||||
entityManager.removeModal()
|
||||
entityManager.getHUD()?.roundTimer.resumeTimer()
|
||||
|
@ -18,7 +18,7 @@ class SettingsScene: SKScene {
|
||||
entityManager.setScene(scene: self)
|
||||
let positionX = self.size.width * 0.1
|
||||
let positionY = self.size.height * 0.05
|
||||
isMusicDeactivatedByUserDefault ? setMusicButtonTextByUserDefault(text: "Aus") : setMusicButtonTextByUserDefault(text: "Ein")
|
||||
isMusicDeactivatedByUserDefault ? setMusicButtonTextByUserDefault(text: "Aus") : setMusicButtonTextByUserDefault(text: "An")
|
||||
entityManager.add(Button(name: "backToMenuScene",
|
||||
textureName: "yellow_button04",
|
||||
text: "Zurück",
|
||||
|
Loading…
Reference in New Issue
Block a user