Skip to content

Commit 3f35cc5

Browse files
committed
added 2 extra lives; missing notes take a life
1 parent cf996f2 commit 3f35cc5

File tree

5 files changed

+72
-25
lines changed

5 files changed

+72
-25
lines changed
0 Bytes
Binary file not shown.
Binary file not shown.

WWDC 2018 Debug Xcode Project/WWDC SUBMISSION 2018.playground/Sources/Declarations.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct PhysicsCategory {
1919
static let Bullet : UInt32 = 0b1 // 1
2020
static let Ship : UInt32 = 0b10 // 2
2121
static let Note : UInt32 = 0b100 // 3
22+
static let Bottom : UInt32 = 0b1000 // 4
2223
}
2324

2425
//defines a word for each not length so it is easier to read

WWDC 2018 Debug Xcode Project/WWDC SUBMISSION 2018.playground/Sources/GameScene.swift

Lines changed: 68 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
99
private var life1: SKShapeNode!
1010
private var life2: SKShapeNode!
1111
private var life3: SKShapeNode!
12+
private var life4: SKShapeNode!
13+
private var life5: SKShapeNode!
1214
private var scoreLabel : SKLabelNode!
1315

1416
private var stars : SKEmitterNode!
@@ -23,11 +25,13 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
2325
private var scoreTextLabel : SKLabelNode!
2426

2527
//Scoring
26-
private var lives = 3
28+
private var lives = 5
2729
private var score = 0
2830

2931
private var currentLevel = 1
3032

33+
private var bottomDetector : SKShapeNode!
34+
3135
private var running = false
3236

3337
//array of all contacts to be handled in the next frame
@@ -53,7 +57,7 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
5357
}
5458

5559
//start w/ 3 lives
56-
lives = 3
60+
lives = 5
5761

5862
//setup physics
5963
physicsWorld.gravity = CGVector.zero
@@ -78,12 +82,17 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
7882
life1 = scene?.childNode(withName: "life1") as? SKShapeNode
7983
life2 = scene?.childNode(withName: "life2") as? SKShapeNode
8084
life3 = scene?.childNode(withName: "life3") as? SKShapeNode
85+
life4 = scene?.childNode(withName: "life4") as? SKShapeNode
86+
life5 = scene?.childNode(withName: "life5") as? SKShapeNode
8187
scoreLabel = scene?.childNode(withName: "score") as? SKLabelNode
8288
scoreTextLabel = scene?.childNode(withName: "scoreTextLabel") as? SKLabelNode
8389

8490
life1.position.y = -550
8591
life2.position.y = -550
8692
life3.position.y = -550
93+
life4.position.y = -550
94+
life5.position.y = -550
95+
8796
scoreLabel.position.y = -575
8897
scoreTextLabel.position.y = -575
8998

@@ -130,6 +139,14 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
130139
booster3.position.y = ship.position.y
131140
booster3.particleScale = 0.3
132141
booster3.targetNode = self
142+
143+
//add noteDetector
144+
bottomDetector = scene?.childNode(withName: "bottomDetector") as? SKShapeNode
145+
bottomDetector.physicsBody = SKPhysicsBody(rectangleOf: bottomDetector.frame.size)
146+
bottomDetector.physicsBody!.collisionBitMask = PhysicsCategory.None
147+
bottomDetector.physicsBody!.categoryBitMask = PhysicsCategory.Bottom
148+
bottomDetector.physicsBody!.contactTestBitMask = PhysicsCategory.Note
149+
bottomDetector.physicsBody!.affectedByGravity = false
133150
}
134151

135152
//intro sequence when game starts
@@ -157,6 +174,8 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
157174
self.life1.run(moveLives)
158175
self.life2.run(moveLives)
159176
self.life3.run(moveLives)
177+
self.life4.run(moveLives)
178+
self.life5.run(moveLives)
160179
self.scoreLabel.run(moveLives)
161180
self.scoreTextLabel.run(moveLives)
162181

@@ -309,12 +328,10 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
309328
let move = SKAction.moveBy(x: 0, y: -1500, duration: 4)
310329
newNote.run(move)
311330

312-
313331
//to maintain performance, delete note nodes after they leave the screen.
314332
delay(4) {
315333
newNote.removeFromParent()
316334
}
317-
318335
}
319336

320337
/////////////////////////////
@@ -384,24 +401,46 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
384401
contact.bodyB.node!.removeFromParent()
385402
}
386403

387-
//adjust lives
388-
if (lives > 1) {
389-
//lost life sound effect
390-
lives = lives - 1
391-
if lives == 2 {
392-
//animate?
393-
//lost life sound effect
394-
life3.removeFromParent()
395-
} else if lives == 1 {
396-
//lost life sound effect
397-
//animate?
398-
life2.removeFromParent()
399-
}
400-
} else {
404+
lives = lives - 1
405+
switch lives {
406+
case 4:
407+
life5.removeFromParent()
408+
case 3:
409+
life4.removeFromParent()
410+
case 2:
411+
life3.removeFromParent()
412+
case 1:
413+
life2.removeFromParent()
414+
case 0:
415+
life1.removeFromParent()
416+
deathScreen()
417+
print(" ^ Re-run to try again")
418+
default:
419+
print("this should not happen")
420+
}
421+
}
422+
423+
//a note hit the bottom:
424+
if nodeBitmasks.contains(PhysicsCategory.Bottom) && nodeBitmasks.contains(PhysicsCategory.Note) {
425+
426+
print("hit bottom")
427+
428+
lives = lives - 1
429+
switch lives {
430+
case 4:
431+
life5.removeFromParent()
432+
case 3:
433+
life4.removeFromParent()
434+
case 2:
435+
life3.removeFromParent()
436+
case 1:
437+
life2.removeFromParent()
438+
case 0:
401439
life1.removeFromParent()
402-
//death screen
403440
deathScreen()
404441
print(" ^ Re-run to try again")
442+
default:
443+
print("this should not happen")
405444
}
406445
}
407446
}
@@ -457,17 +496,23 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
457496
running = false
458497

459498
//win animation (change later)
460-
ship.removeFromParent()
461-
scoreTextLabel.removeFromParent()
462-
scoreLabel.removeFromParent()
463499

500+
//ship flys off screen??
501+
ship.removeFromParent()
464502
booster1.removeFromParent()
465503
booster2.removeFromParent()
466504
booster3.removeFromParent()
467505

506+
//score will move to center??
507+
scoreTextLabel.removeFromParent()
508+
scoreLabel.removeFromParent()
509+
510+
//life fade out?
468511
life1.removeFromParent()
469512
life2.removeFromParent()
470513
life3.removeFromParent()
514+
life4.removeFromParent()
515+
life5.removeFromParent()
471516

472517
// Removing existing notes
473518
for child in self.children {
@@ -476,6 +521,7 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
476521
}
477522
}
478523

524+
//grow from center??
479525
let winLabel = SKLabelNode(text: "You Won!")
480526
winLabel.fontName = "Helvetica Neue Light"
481527
winLabel.fontSize = 65

WWDC 2018 Debug Xcode Project/WWDC SUBMISSION 2018.playground/Sources/Song.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ public class Song {
161161
self.addNote(note: "C2", length: quarter)
162162
self.addDelay(length: quarter)
163163
self.addNote(note: "C2", length: quarter)
164-
self.addDelay(length: quarter)
165-
self.addNote(note: "C2", length: quarter)
166164
self.addDelay(length: half)
167165
self.addNote(note: "C2", length: quarter)
168166
self.addDelay(length: quarter)
@@ -186,6 +184,8 @@ public class Song {
186184
self.addDelay(length: quarter)
187185
self.addNote(note: "C2", length: quarter)
188186
self.addDelay(length: quarter)
187+
self.addNote(note: "C2", length: quarter)
188+
self.addDelay(length: quarter)
189189
self.addNote(note: "G", length: quarter)
190190
self.addDelay(length: quarter)
191191
self.addNote(note: "A", length: quarter)
@@ -202,7 +202,7 @@ public class Song {
202202
self.addDelay(length: quarter)
203203
self.addNote(note: "D2", length: quarter)
204204
self.addDelay(length: quarter)
205-
self.addNote(note: "C2", length: quarter)
205+
self.addNote(note: "C2", length: half)
206206
self.addDelay(length: quarter)
207207
self.addEndMarker()
208208

0 commit comments

Comments
 (0)