@@ -41,6 +41,7 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
4141 //start w/ 3 lives
4242 lives = 3
4343
44+ //setup physics
4445 physicsWorld. gravity = CGVector . zero
4546 physicsWorld. contactDelegate = self
4647 }
@@ -224,11 +225,11 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
224225 scene. addChild ( newNote)
225226
226227 //start moving down the screen
227- let move = SKAction . moveBy ( x: 0 , y: - 1500 , duration: 15 / 4 )
228+ let move = SKAction . moveBy ( x: 0 , y: - 1500 , duration: 2 )
228229 newNote. run ( move)
229230
230231 //to maintain performance, delete note nodes after they leave the screen.
231- DispatchQueue . main. asyncAfter ( deadline: . now( ) + 15 ) {
232+ DispatchQueue . main. asyncAfter ( deadline: . now( ) + 2 ) {
232233 newNote. removeFromParent ( )
233234 }
234235 }
@@ -237,6 +238,7 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
237238 //MARK:Physics and Contacts//
238239 /////////////////////////////
239240
241+ //allows multiple contacts to be handled in one frame, called once per frame update
240242 func processContacts( forUpdate currentTime: CFTimeInterval ) {
241243 for contact in contactQueue {
242244 handle ( contact)
@@ -247,6 +249,7 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
247249 }
248250 }
249251
252+ //determine what collided and do something
250253 public func handle( _ contact: SKPhysicsContact ) {
251254 if contact. bodyA. node? . parent == nil || contact. bodyB. node? . parent == nil {
252255 return
@@ -256,33 +259,28 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
256259
257260 //bullet hit a note:
258261 if nodeBitmasks. contains ( PhysicsCategory . Note) && nodeBitmasks. contains ( PhysicsCategory . Bullet) {
259- //access the length of the note we hit to play the correct sound
260-
261-
262+
262263 if ( contact. bodyA. categoryBitMask == PhysicsCategory . Note) {
263264 if let note = contact. bodyA. node {
264-
265-
265+ //access the length of the note we hit to play the correct sound
266266 let input = Int ( round ( note. position. x * 20 ) / 20 )
267- // print("BEFORE Cthrr OLLISION: \(round(note.position.x * 20) / 20)")
268-
269267 let length = Double ( ( 10 * round( note. frame. size. height / 10.0 ) ) )
270268 Sound ( input: input, length: length) . playSound ( in: self )
271269 }
272270 } else {
273271 if let note = contact. bodyB. node {
274-
272+ //access the length of the note we hit to play the correct sound
275273 let input = Int ( round ( note. position. x * 20 ) / 20 )
276- // print("BEFORE COLLISION: \(round(note.position.x * 20) / 20)")
277-
278274 let length = Double ( ( 10 * round( note. frame. size. height / 10.0 ) ) )
279275 Sound ( input: input, length: length) . playSound ( in: self )
280276 }
281277 }
282278
279+ //add to the score & update label
283280 score += 1
284281 scoreLabel. text = " \( score) "
285282
283+ //remove both nodes
286284 contact. bodyA. node!. removeFromParent ( )
287285 contact. bodyB. node!. removeFromParent ( )
288286 }
@@ -304,6 +302,7 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
304302 }
305303 }
306304
305+ //when we detect a collision, add it to our queue to be handled in the next frame.
307306 public func didBegin( _ contact: SKPhysicsContact ) {
308307 contactQueue. append ( contact)
309308 }
@@ -316,6 +315,7 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
316315 let location = event. location ( in: self )
317316 // move ship to mouse (only x values)
318317 ship. position. x = location. x
318+ //move the boosters along with the ship (keeping thier relative posistions)
319319 booster1. position. x = ship. position. x + 50
320320 booster1. position. y = ship. position. y
321321 booster2. position. x = ship. position. x - 50
@@ -325,6 +325,7 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
325325 }
326326
327327 public override func mouseDown( with event: NSEvent ) {
328+ //shoots on click
328329 shootBeam ( )
329330 }
330331
@@ -333,45 +334,45 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
333334 ////////////////////
334335
335336 let song = Song ( )
336- //var songBPM = 120
337337
338338 //this function adds all the notes to the array within the Song class
339339 public func setupSong( ) {
340- // .quarter = .25, half = .5, and so on; fix later
340+ //Mary Had a Little Lamb:
341+ //low octave
341342 song. addNote ( note: " E " , length: 0.25 )
342- song. addDelay ( length: 0.5 )
343+ song. addDelay ( length: 0.25 )
343344 song. addNote ( note: " D " , length: 0.25 )
344- song. addDelay ( length: 0.5 )
345+ song. addDelay ( length: 0.25 )
345346 song. addNote ( note: " C " , length: 0.25 )
346- song. addDelay ( length: 0.5 )
347+ song. addDelay ( length: 0.25 )
347348 song. addNote ( note: " D " , length: 0.25 )
348- song. addDelay ( length: 0.5 )
349+ song. addDelay ( length: 0.25 )
349350 song. addNote ( note: " E " , length: 0.25 )
350351 song. addDelay ( length: 0.25 )
351352 song. addNote ( note: " E " , length: 0.25 )
352353 song. addDelay ( length: 0.25 )
353354 song. addNote ( note: " E " , length: 0.25 )
354- song. addDelay ( length: 0.5 )
355+ song. addDelay ( length: 0.25 )
355356 song. addNote ( note: " D " , length: 0.25 )
356357 song. addDelay ( length: 0.25 )
357358 song. addNote ( note: " D " , length: 0.25 )
358359 song. addDelay ( length: 0.25 )
359360 song. addNote ( note: " D " , length: 0.25 )
360- song. addDelay ( length: 0.5 )
361+ song. addDelay ( length: 0.25 )
361362 song. addNote ( note: " E " , length: 0.25 )
362363 song. addDelay ( length: 0.25 )
363364 song. addNote ( note: " E " , length: 0.25 )
364365 song. addDelay ( length: 0.25 )
365366 song. addNote ( note: " E " , length: 0.25 )
366- song. addDelay ( length: 0.5 )
367+ song. addDelay ( length: 0.25 )
367368 song. addNote ( note: " E " , length: 0.25 )
368- song. addDelay ( length: 0.5 )
369+ song. addDelay ( length: 0.25 )
369370 song. addNote ( note: " D " , length: 0.25 )
370- song. addDelay ( length: 0.5 )
371+ song. addDelay ( length: 0.25 )
371372 song. addNote ( note: " C " , length: 0.25 )
372- song. addDelay ( length: 0.5 )
373+ song. addDelay ( length: 0.25 )
373374 song. addNote ( note: " D " , length: 0.25 )
374- song. addDelay ( length: 0.5 )
375+ song. addDelay ( length: 0.25 )
375376 song. addNote ( note: " E " , length: 0.25 )
376377 song. addDelay ( length: 0.25 )
377378 song. addNote ( note: " E " , length: 0.25 )
@@ -389,7 +390,61 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
389390 song. addNote ( note: " D " , length: 0.25 )
390391 song. addDelay ( length: 0.25 )
391392 song. addNote ( note: " C " , length: 0.5 )
392- song. addDelay ( length: 0.5 )
393+ song. addDelay ( length: 0.25 )
394+
395+ //high octave
396+ song. addNote ( note: " E2 " , length: 0.25 )
397+ song. addDelay ( length: 0.25 )
398+ song. addNote ( note: " D2 " , length: 0.25 )
399+ song. addDelay ( length: 0.25 )
400+ song. addNote ( note: " C2 " , length: 0.25 )
401+ song. addDelay ( length: 0.25 )
402+ song. addNote ( note: " D2 " , length: 0.25 )
403+ song. addDelay ( length: 0.25 )
404+ song. addNote ( note: " E2 " , length: 0.25 )
405+ song. addDelay ( length: 0.25 )
406+ song. addNote ( note: " E2 " , length: 0.25 )
407+ song. addDelay ( length: 0.25 )
408+ song. addNote ( note: " E2 " , length: 0.25 )
409+ song. addDelay ( length: 0.25 )
410+ song. addNote ( note: " D2 " , length: 0.25 )
411+ song. addDelay ( length: 0.25 )
412+ song. addNote ( note: " D2 " , length: 0.25 )
413+ song. addDelay ( length: 0.25 )
414+ song. addNote ( note: " D2 " , length: 0.25 )
415+ song. addDelay ( length: 0.25 )
416+ song. addNote ( note: " E2 " , length: 0.25 )
417+ song. addDelay ( length: 0.25 )
418+ song. addNote ( note: " E2 " , length: 0.25 )
419+ song. addDelay ( length: 0.25 )
420+ song. addNote ( note: " E2 " , length: 0.25 )
421+ song. addDelay ( length: 0.25 )
422+ song. addNote ( note: " E2 " , length: 0.25 )
423+ song. addDelay ( length: 0.25 )
424+ song. addNote ( note: " D2 " , length: 0.25 )
425+ song. addDelay ( length: 0.25 )
426+ song. addNote ( note: " C2 " , length: 0.25 )
427+ song. addDelay ( length: 0.25 )
428+ song. addNote ( note: " D2 " , length: 0.25 )
429+ song. addDelay ( length: 0.25 )
430+ song. addNote ( note: " E2 " , length: 0.25 )
431+ song. addDelay ( length: 0.25 )
432+ song. addNote ( note: " E2 " , length: 0.25 )
433+ song. addDelay ( length: 0.25 )
434+ song. addNote ( note: " E2 " , length: 0.25 )
435+ song. addDelay ( length: 0.25 )
436+ song. addNote ( note: " E2 " , length: 0.25 )
437+ song. addDelay ( length: 0.25 )
438+ song. addNote ( note: " D2 " , length: 0.25 )
439+ song. addDelay ( length: 0.25 )
440+ song. addNote ( note: " D2 " , length: 0.25 )
441+ song. addDelay ( length: 0.25 )
442+ song. addNote ( note: " E2 " , length: 0.25 )
443+ song. addDelay ( length: 0.25 )
444+ song. addNote ( note: " D2 " , length: 0.25 )
445+ song. addDelay ( length: 0.25 )
446+ song. addNote ( note: " C2 " , length: 0.5 )
447+ song. addDelay ( length: 0.25 )
393448 }
394449
395450 var i = - 1
0 commit comments