add RoundCount directly to HUD
* add backgroundRoundCounter, currentRoundLabel, roundsLabel and roundlabel * add necessary Assets to project * add labels to EntityManager * minor refactoring in RoundCalculatorService and SettingsScene
This commit is contained in:
parent
0c2b621b05
commit
48361738ba
23
GoldWars/GoldWars/Assets.xcassets/roundInfo_texture.imageset/Contents.json
vendored
Normal file
23
GoldWars/GoldWars/Assets.xcassets/roundInfo_texture.imageset/Contents.json
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"images" : [
|
||||||
|
{
|
||||||
|
"filename" : "roundInfo_texture.png",
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "1x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"filename" : "roundInfo_texture-1.png",
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "2x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"filename" : "roundInfo_texture-2.png",
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "3x"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
BIN
GoldWars/GoldWars/Assets.xcassets/roundInfo_texture.imageset/roundInfo_texture-1.png
vendored
Normal file
BIN
GoldWars/GoldWars/Assets.xcassets/roundInfo_texture.imageset/roundInfo_texture-1.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
BIN
GoldWars/GoldWars/Assets.xcassets/roundInfo_texture.imageset/roundInfo_texture-2.png
vendored
Normal file
BIN
GoldWars/GoldWars/Assets.xcassets/roundInfo_texture.imageset/roundInfo_texture-2.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
BIN
GoldWars/GoldWars/Assets.xcassets/roundInfo_texture.imageset/roundInfo_texture.png
vendored
Normal file
BIN
GoldWars/GoldWars/Assets.xcassets/roundInfo_texture.imageset/roundInfo_texture.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
@ -53,6 +53,10 @@ class EntityManager {
|
|||||||
scene.addChild(hudEntitiy.spySkill)
|
scene.addChild(hudEntitiy.spySkill)
|
||||||
scene.addChild(hudEntitiy.roundTimerLabel)
|
scene.addChild(hudEntitiy.roundTimerLabel)
|
||||||
scene.addChild(hudEntitiy.finishButton)
|
scene.addChild(hudEntitiy.finishButton)
|
||||||
|
scene.addChild(hudEntitiy.backgroundRoundCounter)
|
||||||
|
scene.addChild(hudEntitiy.currentRoundLabel)
|
||||||
|
scene.addChild(hudEntitiy.roundsLabel)
|
||||||
|
scene.addChild(hudEntitiy.roundLabel)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let spriteNode = entity.component(ofType: DefaultBaseComponent.self) {
|
if let spriteNode = entity.component(ofType: DefaultBaseComponent.self) {
|
||||||
|
@ -27,6 +27,11 @@ class HUD: GKEntity {
|
|||||||
var roundTimerLabel: SKLabelNode
|
var roundTimerLabel: SKLabelNode
|
||||||
let roundTimer: RoundTimer
|
let roundTimer: RoundTimer
|
||||||
|
|
||||||
|
var backgroundRoundCounter: SKSpriteNode
|
||||||
|
var currentRoundLabel: SKLabelNode
|
||||||
|
var roundsLabel: SKLabelNode
|
||||||
|
var roundLabel: SKLabelNode
|
||||||
|
|
||||||
var finishButton: ButtonNode
|
var finishButton: ButtonNode
|
||||||
|
|
||||||
init(size: CGSize) {
|
init(size: CGSize) {
|
||||||
@ -90,7 +95,13 @@ class HUD: GKEntity {
|
|||||||
)
|
)
|
||||||
finishButton.size = CGSize(width: 80, height: 40)
|
finishButton.size = CGSize(width: 80, height: 40)
|
||||||
finishButton.zPosition = 2
|
finishButton.zPosition = 2
|
||||||
|
|
||||||
|
backgroundRoundCounter = SKSpriteNode(texture: SKTexture(imageNamed: "roundInfo_texture"))
|
||||||
|
currentRoundLabel = SKLabelNode(fontNamed: "Courier-Bold")
|
||||||
|
roundsLabel = SKLabelNode(fontNamed: "Courier-Bold")
|
||||||
|
roundLabel = SKLabelNode(fontNamed: "Courier-Bold")
|
||||||
super.init()
|
super.init()
|
||||||
|
initRoundInfo(size: size)
|
||||||
|
|
||||||
finishButton.onButtonPress = { [unowned self] in
|
finishButton.onButtonPress = { [unowned self] in
|
||||||
self.finishRound()
|
self.finishRound()
|
||||||
@ -134,4 +145,39 @@ class HUD: GKEntity {
|
|||||||
self.roundTimer.timeLeft = 1;
|
self.roundTimer.timeLeft = 1;
|
||||||
self.roundTimer.roundEnded = "Waiting for other player..."
|
self.roundTimer.roundEnded = "Waiting for other player..."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initRoundInfo(size: CGSize) -> () {
|
||||||
|
backgroundRoundCounter.zPosition = 2
|
||||||
|
backgroundRoundCounter.position = CGPoint(x: Double(size.width) * 0.06, y: Double(size.height) * 0.08)
|
||||||
|
|
||||||
|
currentRoundLabel.text = "\(RoundCalculatorService.sharedInstance.roundcount)"
|
||||||
|
currentRoundLabel.fontSize = 50
|
||||||
|
currentRoundLabel.fontColor = SKColor.black
|
||||||
|
currentRoundLabel.verticalAlignmentMode = .center
|
||||||
|
currentRoundLabel.position = CGPoint(x: backgroundRoundCounter.position.x, y: backgroundRoundCounter.position.y - 5)
|
||||||
|
currentRoundLabel.zPosition = backgroundRoundCounter.zPosition + 1
|
||||||
|
|
||||||
|
roundsLabel.zPosition = backgroundRoundCounter.zPosition + 1
|
||||||
|
roundsLabel.text = "of \(RoundCalculatorService.sharedInstance.rounds)"
|
||||||
|
roundsLabel.fontColor = SKColor.black
|
||||||
|
roundsLabel.verticalAlignmentMode = .center
|
||||||
|
roundsLabel.fontSize = 12
|
||||||
|
roundsLabel.position = CGPoint(x: currentRoundLabel.position.x, y: currentRoundLabel.position.y - 25)
|
||||||
|
|
||||||
|
roundLabel.zPosition = backgroundRoundCounter.zPosition + 1
|
||||||
|
roundLabel.text = "Round"
|
||||||
|
roundLabel.fontColor = SKColor.black
|
||||||
|
roundLabel.verticalAlignmentMode = .center
|
||||||
|
roundLabel.fontSize = 12
|
||||||
|
roundLabel.position = CGPoint(x: currentRoundLabel.position.x, y: currentRoundLabel.position.y + 25)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setCurrentRound(round: Int) -> Void {
|
||||||
|
currentRoundLabel.text = "\(round)"
|
||||||
|
let newRoundAction = SKAction.sequence([
|
||||||
|
SKAction.scale(by: 2, duration: 1),
|
||||||
|
SKAction.scale(by: 0.5, duration: 1),
|
||||||
|
])
|
||||||
|
currentRoundLabel.run(newRoundAction)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,20 +10,19 @@ import GameKit
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
class RoundCalculatorService {
|
class RoundCalculatorService {
|
||||||
|
var entityManager = EntityManager.gameEMInstance
|
||||||
static let sharedInstance = RoundCalculatorService()
|
static let sharedInstance = RoundCalculatorService()
|
||||||
static let LOG = OSLog.init(subsystem: "Round Calculator", category: "RoundCalculatorService")
|
static let LOG = OSLog.init(subsystem: "Round Calculator", category: "RoundCalculatorService")
|
||||||
|
|
||||||
let ATK_BOOST_MULTIPLICATOR = 1.1
|
|
||||||
let DEF_BOOST_MULTIPLICATOR = 1.1
|
|
||||||
|
|
||||||
var allPlayerMoves: [String: [PlayerMove]] = [:]
|
var allPlayerMoves: [String: [PlayerMove]] = [:]
|
||||||
// TODO: Better data structure
|
// TODO: Better data structure
|
||||||
var boosts: [String: (Bool, Bool)] = [:] // First bool is atk boost, second is def boost
|
var boosts: [String: (Bool, Bool)] = [:] // First bool is atk boost, second is def boost
|
||||||
|
|
||||||
var entityManager = EntityManager.gameEMInstance
|
let ATK_BOOST_MULTIPLICATOR = 1.1
|
||||||
|
let DEF_BOOST_MULTIPLICATOR = 1.1
|
||||||
|
let MAX_ROUNDS = 20
|
||||||
|
var currentRound = 1
|
||||||
var isCalculating = false
|
var isCalculating = false
|
||||||
|
|
||||||
var numberOfAttacks = 0
|
var numberOfAttacks = 0
|
||||||
var numberOfOwnUnitMoves = 0
|
var numberOfOwnUnitMoves = 0
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@ class SettingsScene: SKScene {
|
|||||||
var entityManager = EntityManager.settingsEMInstance
|
var entityManager = EntityManager.settingsEMInstance
|
||||||
|
|
||||||
override func sceneDidLoad() {
|
override func sceneDidLoad() {
|
||||||
|
|
||||||
entityManager.setScene(scene: self)
|
entityManager.setScene(scene: self)
|
||||||
let positionX = self.size.width * 0.1
|
let positionX = self.size.width * 0.1
|
||||||
let positionY = self.size.height * 0.05
|
let positionY = self.size.height * 0.05
|
||||||
|
Loading…
Reference in New Issue
Block a user