This repository has been archived by the owner on May 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScore.swift
60 lines (50 loc) · 1.77 KB
/
Score.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// Score.swift
// PaddleBattle
//
// Created by Emad Mohamad on 7/7/15.
// Copyright (c) 2015 Apportable. All rights reserved.
//
import Foundation
class Score: CCNode {
weak var scorePoint1 : CCSprite!
weak var scorePoint2 : CCSprite!
weak var scorePoint3 : CCSprite!
weak var scorePoint4 : CCSprite!
weak var scorePoint5 : CCSprite!
var scorePointArray = [CCSprite]()
var playerColor : String!
func didLoadFromCCB() {
scorePointArray = [scorePoint1, scorePoint2, scorePoint3, scorePoint4, scorePoint5]
}
func setupScoreImageColor(colorName: String) {
// if children != nil {
for child in children {
if let scorePoint = child as? CCSprite {
scorePoint.spriteFrame = CCSpriteFrame(imageNamed: "Paddle Battle/score-pieces/score-piece-\(colorName)-active.png")
playerColor = colorName
}
}
// }
}
func setupScoreForPlayer(playerPosition: PlayerPosition, numberOfPoints: Int) {
switch playerPosition {
case .Top:
setupScoreImageColor("green")
rotation = 315
case .Bottom:
setupScoreImageColor("pink")
rotation = 135
case .Left:
setupScoreImageColor("blue")
rotation = 225
case .Right:
setupScoreImageColor("red")
rotation = 45
}
}
func minusScore(score: Int) {
let disabledFrame = CCSpriteFrame(imageNamed: "Paddle Battle/score-pieces/score-piece-\(self.playerColor)-disabled.png")
scorePointArray[score].runAction(CCActionSequence(array: [CCActionBlink(duration: 0.2, blinks: 2), CCActionSpriteFrame(spriteFrame: disabledFrame)]) )
}
}