Skip to content

Commit

Permalink
Merge pull request #46 from M320Trololol/final-enhancements
Browse files Browse the repository at this point in the history
Beautify code in about scene
  • Loading branch information
bmo-at authored May 14, 2018
2 parents 5f77470 + 05d3f6b commit a8fcf4d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 75 deletions.
87 changes: 23 additions & 64 deletions d-fence/AboutScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,70 +13,14 @@ class AboutScene: SKScene {
backgroundColor = SKColor(red: 0.3, green: 0.3, blue: 0.3, alpha: 1.0)

// Generate labels for every author and the app name

let title = SKOutlinedLabelNode(fontNamed: "8-Bit-Madness", fontSize: size.height / 5);
title.borderColor = UIColor.black
title.borderWidth = title.fontSize / 4.5
title.outlinedText = NSLocalizedString("ABOUT", comment: "")
title.name = "title"
title.fontColor = UIColor.white
title.zPosition = 150
title.position = CGPoint(x: size.width / 2, y: size.height * 0.8)

let back = SKOutlinedLabelNode(fontNamed: "8-Bit-Madness", fontSize: size.height / 10);
back.borderColor = UIColor.black
back.borderWidth = back.fontSize / 4.5
back.outlinedText = NSLocalizedString("BACK", comment: "")
back.name = "back"
back.fontColor = UIColor.white
back.zPosition = 150
back.position = CGPoint(x: back.frame.size.width / 2 * 1.2, y: back.frame.size.height / 2)

let gameInfo = SKOutlinedLabelNode(fontNamed: "8-Bit-Madness", fontSize: size.height / 10);
gameInfo.borderColor = UIColor.black
gameInfo.borderWidth = gameInfo.fontSize / 4.5
gameInfo.outlinedText = "d-fence © 2018"
gameInfo.name = "gameInfo"
gameInfo.fontColor = UIColor.white
gameInfo.zPosition = 150
gameInfo.position = CGPoint(x: size.width / 2, y: size.height / 2)

let authorInfo1 = SKOutlinedLabelNode(fontNamed: "8-Bit-Madness", fontSize: size.height / 10);
authorInfo1.borderColor = UIColor.black
authorInfo1.borderWidth = authorInfo1.fontSize / 4.5
authorInfo1.outlinedText = "Jan-Robin Aumann"
authorInfo1.name = "authorInfo"
authorInfo1.fontColor = UIColor.white
authorInfo1.zPosition = 150
authorInfo1.position = CGPoint(x: size.width / 2, y: size.height / 3)

let authorInfo2 = SKOutlinedLabelNode(fontNamed: "8-Bit-Madness", fontSize: size.height / 10);
authorInfo2.borderColor = UIColor.black
authorInfo2.borderWidth = authorInfo2.fontSize / 4.5
authorInfo2.outlinedText = "Oliver Kardos"
authorInfo2.name = "authorInfo"
authorInfo2.fontColor = UIColor.white
authorInfo2.zPosition = 150
authorInfo2.position = CGPoint(x: size.width / 2, y: size.height / 3 - authorInfo2.frame.height * 1.5)

let authorInfo3 = SKOutlinedLabelNode(fontNamed: "8-Bit-Madness", fontSize: size.height / 10);
authorInfo3.borderColor = UIColor.black
authorInfo3.borderWidth = authorInfo3.fontSize / 4.5
authorInfo3.outlinedText = "Hendrik Ulbrich"
authorInfo3.name = "authorInfo"
authorInfo3.fontColor = UIColor.white
authorInfo3.zPosition = 150
authorInfo3.position = CGPoint(x: size.width / 2, y: size.height / 3 - authorInfo2.frame.height * 3)

let authorInfo4 = SKOutlinedLabelNode(fontNamed: "8-Bit-Madness", fontSize: size.height / 17);
authorInfo4.borderColor = UIColor.black
authorInfo4.borderWidth = authorInfo4.fontSize / 4.5
authorInfo4.outlinedText = "Music by Malte Bartels"
authorInfo4.name = "authorInfo"
authorInfo4.fontColor = UIColor.white
authorInfo4.zPosition = 150
authorInfo4.position = CGPoint(x: size.width / 2, y: size.height / 3 - authorInfo2.frame.height * 4.5)

let title = generateMenuItem(localizedText: "ABOUT", name: "title", fontSize: size.height / 5, vpos: 0.85, hpos: 0.5)
let back = generateMenuItem(localizedText: "BACK", name: "back", fontSize: size.height / 10, vpos: 0.05, hpos: 0.1)
let gameInfo = generateMenuItem(localizedText: "GAME_CREDIT", name: "gameInfo", fontSize: size.height / 10, vpos: 0.6, hpos: 0.5)
let authorInfo1 = generateMenuItem(localizedText: "AUTHOR1_CREDIT", name: "authorInfo", fontSize:size.height / 10, vpos: 0.45, hpos: 0.5);
let authorInfo2 = generateMenuItem(localizedText: "AUTHOR2_CREDIT", name: "authorInfo", fontSize:size.height / 10, vpos: 0.35, hpos: 0.5);
let authorInfo3 = generateMenuItem(localizedText: "AUTHOR3_CREDIT", name: "authorInfo", fontSize:size.height / 10, vpos: 0.25, hpos: 0.5);
let authorInfo4 = generateMenuItem(localizedText: "MUSIC_CREDIT", name: "authorInfo", fontSize:size.height / 15, vpos: 0.15, hpos: 0.5);

addChild(authorInfo1)
addChild(authorInfo2)
addChild(authorInfo3)
Expand All @@ -98,4 +42,19 @@ class AboutScene: SKScene {
}
}
}

// Generic function for rendering about labels
func generateMenuItem(localizedText: String, name: String, fontSize: CGFloat, vpos: CGFloat, hpos: CGFloat) -> SKLabelNode {
let label = SKOutlinedLabelNode(fontNamed: "8-Bit-Madness", fontSize: fontSize);
label.borderColor = UIColor.black
label.borderWidth = label.fontSize / 4.5
label.outlinedText = NSLocalizedString(localizedText, comment: "")
label.name = name
label.fontColor = UIColor.white
label.zPosition = 150
label.position = CGPoint(x: size.width * hpos, y: (size.height - label.frame.height / 2) * vpos)

return label
}

}
15 changes: 6 additions & 9 deletions d-fence/GameScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -561,35 +561,32 @@ class GameScene: SKScene {
var k = 1
if num_entries < 9 {
k = 1
} else {
} else {
k = num_entries - abs(num_entries - 10)
}
for i in 0...num_entries - k {
if defaults.value(forKey: "score\(i)") != nil && found == false {
if defaults.value(forKey: "score\(i)") != nil && !found {
let k = defaults.value(forKey: "score\(i)") as? Int
if k! < self.score {
scores_change[i] = score
waves_change[i] = waveCount
scores_change[i + 1] = defaults.value(forKey: "score\(i)")! as! Int
waves_change[i + 1] = defaults.value(forKey: "wave\(i)")! as! Int
found = true
}
else {
} else {
scores_change[i] = defaults.value(forKey: "score\(i)")! as! Int
waves_change[i] = defaults.value(forKey: "wave\(i)")! as! Int
}
}
else if defaults.value(forKey: "score\(i)") != nil && found == true {
} else if defaults.value(forKey: "score\(i)") != nil && found {
scores_change[i + 1] = defaults.value(forKey: "score\(i)")! as! Int
waves_change[i + 1] = defaults.value(forKey: "wave\(i)")! as! Int
}
}
for i in 0...scores_change.count - 1 {
for i in 0...scores_change.count-1 {
defaults.set(scores_change[i], forKey: "score\(i)")
defaults.set(waves_change[i], forKey: "wave\(i)")
}
}
else {
} else {
defaults.set(score, forKey: "score0")
defaults.set(waveCount, forKey: "wave0")
}
Expand Down
8 changes: 6 additions & 2 deletions d-fence/SKOutlinedLabelNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ class SKOutlinedLabelNode: SKLabelNode {
}
var borderStyle = borderStyleType.under

// Redraw the label each time the outlined text changes.
// Redraw the label each time the outlined text (really) changes.
var outlinedText: String! {
didSet { drawText() }
didSet {
if outlinedText != oldValue {
drawText()
}
}
}

var border: SKShapeNode?
Expand Down
6 changes: 6 additions & 0 deletions d-fence/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@
"STATS" = "STATISTIK";
"SLINGSHOT" = "SCHLEUDER";
"NEXT WAVE" = "NAECHSTE WELLE";
"AUTHOR1_CREDIT" = "Jan-Robin Aumann";
"AUTHOR2_CREDIT" = "Oliver Kardos";
"AUTHOR3_CREDIT" = "Hendrik Ulbrich";
"GAME_CREDIT" = "d-fence © 2018";
"MUSIC_CREDIT" = "Musik von Malte Bartels";

5 changes: 5 additions & 0 deletions d-fence/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@
"STATS" = "STATS";
"SLINGSHOT" = "SLINGSHOT";
"NEXT WAVE" = "NEXT WAVE";
"AUTHOR1_CREDIT" = "Jan-Robin Aumann";
"AUTHOR2_CREDIT" = "Oliver Kardos";
"AUTHOR3_CREDIT" = "Hendrik Ulbrich";
"GAME_CREDIT" = "d-fence © 2018";
"MUSIC_CREDIT" = "Music by Malte Bartels";

0 comments on commit a8fcf4d

Please sign in to comment.