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:
127-Z3R0 2020-06-02 20:14:19 +02:00
parent 0c2b621b05
commit 48361738ba
8 changed files with 78 additions and 7 deletions

View 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
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -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) {

View File

@ -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)
}
} }

View File

@ -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

View File

@ -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