@@ -26,6 +26,8 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
2626 private var lives = 3
2727 private var score = 0
2828
29+ private var currentLevel = 1
30+
2931 private var running = false
3032
3133 //array of all contacts to be handled in the next frame
@@ -45,7 +47,7 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
4547
4648 delay ( 6 ) {
4749 //setup & start generating the song
48- self . setupSong ( )
50+ self . song . setup ( level : self . currentLevel )
4951 self . generateSong ( )
5052 }
5153
@@ -185,7 +187,7 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
185187
186188 func shootBeam( ) {
187189 //beam is invisible, but is the node that tracks collisions
188- let beam = SKShapeNode ( rect: CGRect ( x: 0 , y: 0 , width: 15 , height: 15 ) )
190+ let beam = SKShapeNode ( rect: CGRect ( x: 0 , y: 0 , width: 30 , height: 30 ) )
189191 beam. fillColor = . clear
190192 beam. strokeColor = . clear
191193
@@ -213,13 +215,12 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
213215 scene? . addChild ( beam)
214216
215217 //shoot the bullet
216- beam. physicsBody!. applyImpulse ( CGVector ( dx: 0.0 , dy: 10.0 ) )
218+ beam. physicsBody!. applyImpulse ( CGVector ( dx: 0.0 , dy: 70 ) )
217219 }
218220 }
219221
220222 public func prepareNoteForSpawn( note: String , length: Double ) {
221223 let noteWidth = 50.00
222- // var noteHeight : Double
223224 var x : Double = 0
224225
225226 //always start off assuming we have a note and not a delay, may be proved otherwise in the switch statement
@@ -391,8 +392,7 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
391392 life1. removeFromParent ( )
392393 //death screen
393394 deathScreen ( )
394-
395- print ( " he DEAD " )
395+ print ( " ^ Re-run to try again " )
396396 }
397397 }
398398 }
@@ -429,8 +429,15 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
429429 deathLabel2. fontColor = . white
430430 deathLabel2. position = CGPoint ( x: 0 , y : - 40 )
431431
432+ let finalScoreLabel = SKLabelNode ( text: " Score: \( score) " )
433+ finalScoreLabel. fontName = " Helvetica Neue Light "
434+ finalScoreLabel. fontSize = 60
435+ finalScoreLabel. fontColor = . white
436+ finalScoreLabel. position = CGPoint ( x: 0 , y : - 250 )
437+
432438 scene? . addChild ( deathLabel)
433439 scene? . addChild ( deathLabel2)
440+ scene? . addChild ( finalScoreLabel)
434441 }
435442
436443 //when we detect a collision, add it to our queue to be handled in the next frame.
@@ -469,120 +476,8 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
469476 ////////////////////
470477
471478 let song = Song ( )
472-
473- //this function adds all the notes to the array within the Song class
474- public func setupSong( ) {
475- //Mary Had a Little Lamb:
476- //low octave
477- song. addNote ( note: " E " , length: quarter)
478- song. addDelay ( length: half)
479- song. addNote ( note: " D " , length: quarter)
480- song. addDelay ( length: half)
481- song. addNote ( note: " C " , length: quarter)
482- song. addDelay ( length: half)
483- song. addNote ( note: " D " , length: quarter)
484- song. addDelay ( length: half)
485- song. addNote ( note: " E " , length: quarter)
486- song. addDelay ( length: half)
487- song. addNote ( note: " E " , length: quarter)
488- song. addDelay ( length: half)
489- song. addNote ( note: " E " , length: quarter)
490- song. addDelay ( length: half)
491- song. addNote ( note: " D " , length: quarter)
492- song. addDelay ( length: half)
493- song. addNote ( note: " D " , length: quarter)
494- song. addDelay ( length: half)
495- song. addNote ( note: " D " , length: quarter)
496- song. addDelay ( length: half)
497- song. addNote ( note: " E " , length: quarter)
498- song. addDelay ( length: half)
499- song. addNote ( note: " E " , length: quarter)
500- song. addDelay ( length: half)
501- song. addNote ( note: " E " , length: quarter)
502- song. addDelay ( length: half)
503- song. addNote ( note: " E " , length: quarter)
504- song. addDelay ( length: half)
505- song. addNote ( note: " D " , length: quarter)
506- song. addDelay ( length: half)
507- song. addNote ( note: " C " , length: quarter)
508- song. addDelay ( length: half)
509- song. addNote ( note: " D " , length: quarter)
510- song. addDelay ( length: half)
511- song. addNote ( note: " E " , length: quarter)
512- song. addDelay ( length: half)
513- song. addNote ( note: " E " , length: quarter)
514- song. addDelay ( length: half)
515- song. addNote ( note: " E " , length: quarter)
516- song. addDelay ( length: half)
517- song. addNote ( note: " E " , length: quarter)
518- song. addDelay ( length: half)
519- song. addNote ( note: " D " , length: quarter)
520- song. addDelay ( length: half)
521- song. addNote ( note: " D " , length: quarter)
522- song. addDelay ( length: half)
523- song. addNote ( note: " E " , length: quarter)
524- song. addDelay ( length: half)
525- song. addNote ( note: " D " , length: quarter)
526- song. addDelay ( length: half)
527- song. addNote ( note: " C " , length: half)
528- song. addDelay ( length: half)
529-
530- //high octave
531- song. addNote ( note: " E2 " , length: quarter)
532- song. addDelay ( length: half)
533- song. addNote ( note: " D2 " , length: quarter)
534- song. addDelay ( length: half)
535- song. addNote ( note: " C2 " , length: quarter)
536- song. addDelay ( length: half)
537- song. addNote ( note: " D2 " , length: quarter)
538- song. addDelay ( length: half)
539- song. addNote ( note: " E2 " , length: quarter)
540- song. addDelay ( length: half)
541- song. addNote ( note: " E2 " , length: quarter)
542- song. addDelay ( length: half)
543- song. addNote ( note: " E2 " , length: quarter)
544- song. addDelay ( length: half)
545- song. addNote ( note: " D2 " , length: quarter)
546- song. addDelay ( length: half)
547- song. addNote ( note: " D2 " , length: quarter)
548- song. addDelay ( length: half)
549- song. addNote ( note: " D2 " , length: quarter)
550- song. addDelay ( length: half)
551- song. addNote ( note: " E2 " , length: quarter)
552- song. addDelay ( length: half)
553- song. addNote ( note: " E2 " , length: quarter)
554- song. addDelay ( length: half)
555- song. addNote ( note: " E2 " , length: quarter)
556- song. addDelay ( length: half)
557- song. addNote ( note: " E2 " , length: quarter)
558- song. addDelay ( length: half)
559- song. addNote ( note: " D2 " , length: quarter)
560- song. addDelay ( length: half)
561- song. addNote ( note: " C2 " , length: quarter)
562- song. addDelay ( length: half)
563- song. addNote ( note: " D2 " , length: quarter)
564- song. addDelay ( length: half)
565- song. addNote ( note: " E2 " , length: quarter)
566- song. addDelay ( length: half)
567- song. addNote ( note: " E2 " , length: quarter)
568- song. addDelay ( length: half)
569- song. addNote ( note: " E2 " , length: quarter)
570- song. addDelay ( length: half)
571- song. addNote ( note: " E2 " , length: quarter)
572- song. addDelay ( length: half)
573- song. addNote ( note: " D2 " , length: quarter)
574- song. addDelay ( length: half)
575- song. addNote ( note: " D2 " , length: quarter)
576- song. addDelay ( length: half)
577- song. addNote ( note: " E2 " , length: quarter)
578- song. addDelay ( length: half)
579- song. addNote ( note: " D2 " , length: quarter)
580- song. addDelay ( length: half)
581- song. addNote ( note: " C2 " , length: half)
582- song. addDelay ( length: half)
583- }
584-
585479 var i = - 1
480+
586481 //this function takes the array of notes from the Song class and prepares to spawn them into the scene
587482 public func generateSong( ) {
588483 //only generate the song if the game is not over
@@ -594,7 +489,23 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
594489 delay ( Double ( ( song. songArray [ i] ) . 1 ) ) {
595490 self . generateSong ( )
596491 }
597- } else {
492+ }
493+ else if ( ( song. songArray [ i] ) . 0 ) == " end " {
494+ //play the next level
495+ currentLevel += 1
496+
497+ if ( songTitles. indices. contains ( currentLevel - 1 ) ) {
498+ levelAnimation ( level: " \( currentLevel) " , song: songTitles [ currentLevel - 1 ] )
499+ song. clear ( )
500+ song. setup ( level: 2 )
501+ i = - 1
502+ delay ( 6 ) {
503+ self . generateSong ( )
504+ }
505+ } else {
506+ print ( " not here " )
507+ }
508+ } else {
598509 //spawn note
599510 prepareNoteForSpawn ( note: ( ( song. songArray [ i] ) . 0 ) , length: ( ( song. songArray [ i] ) . 1 ) )
600511 //delay the next iteration by length of not playing
0 commit comments