Skip to content

Commit 30eccc9

Browse files
committed
minor fixes
1 parent 5680cb4 commit 30eccc9

File tree

8 files changed

+112
-193
lines changed

8 files changed

+112
-193
lines changed
0 Bytes
Binary file not shown.
Binary file not shown.
1008 Bytes
Loading
Binary file not shown.
Lines changed: 0 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1 @@
11
//Dump code that may or may not be used in this file
2-
/*
3-
4-
import Foundation
5-
6-
public class Scoring {
7-
8-
//var queuedNote = Song().noteArray[0]
9-
10-
public func checkCorrect(noteString: String) {
11-
//var noteChecking = noteString
12-
13-
// if(Song().noteArray[0] == queuedNote) {
14-
// print("correct note")
15-
// } else {
16-
print("note was wrong")
17-
18-
// var note = song.noteArray.index(of:"\(noteString)")
19-
// queuedNote = song.noteArray[note!]
20-
21-
//print("next note up is \(queuedNote)")
22-
//}
23-
}
24-
25-
}
26-
27-
28-
/*
29-
public func didBegin(_ contact: SKPhysicsContact) {
30-
31-
contactQueue.append(contact)
32-
33-
var firstBody: SKPhysicsBody
34-
var secondBody: SKPhysicsBody
35-
36-
if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask {
37-
firstBody = contact.bodyA
38-
secondBody = contact.bodyB
39-
} else {
40-
firstBody = contact.bodyB
41-
secondBody = contact.bodyA
42-
}
43-
44-
if firstBody.categoryBitMask == 1 && secondBody.categoryBitMask == 2 || firstBody.categoryBitMask == 2 && secondBody.categoryBitMask == 1 {
45-
// print("note hit ship")
46-
// this is where the player would die
47-
lives = lives - 1
48-
49-
if (lives == 2) {
50-
life3.removeFromParent()
51-
}
52-
if (lives == 1) {
53-
life2.removeFromParent()
54-
}
55-
if (lives == 0) {
56-
life1.removeFromParent()
57-
print("he ded")
58-
}
59-
}
60-
61-
if firstBody.categoryBitMask == 2 && secondBody.categoryBitMask == 3 || firstBody.categoryBitMask == 3 && secondBody.categoryBitMask == 2 {
62-
63-
64-
//print("contact w/ noteandbeam")
65-
//the height coresponds to the note's length (see the spawnNote funciton)
66-
if let bodyANode = contact.bodyA.node {
67-
68-
let length = (10 * round(Double(bodyANode.frame.size.height / 10.0)))
69-
70-
//these don't need to be ranges anymore cuz we stopped using random values, fix later
71-
switch bodyANode.position.x {
72-
case -350 ... -300:
73-
checkNote(length: length, noteToPlay: "C1")
74-
case -299 ... -250:
75-
checkNote(length: length, noteToPlay: "D1")
76-
case -249 ... -200:
77-
checkNote(length: length, noteToPlay: "E1")
78-
case -199 ... -150:
79-
checkNote(length: length, noteToPlay: "F1")
80-
case -149 ... -100:
81-
checkNote(length: length, noteToPlay: "G1")
82-
case -99 ... -50:
83-
checkNote(length: length, noteToPlay: "A1")
84-
case -49 ... 0:
85-
checkNote(length: length, noteToPlay: "B1")
86-
case 1...50:
87-
checkNote(length: length, noteToPlay: "C2")
88-
case 51...100:
89-
checkNote(length: length, noteToPlay: "D2")
90-
case 101...150:
91-
checkNote(length: length, noteToPlay: "E2")
92-
case 151...200:
93-
checkNote(length: length, noteToPlay: "F2")
94-
case 201...250:
95-
checkNote(length: length, noteToPlay: "G2")
96-
case 251...300:
97-
checkNote(length: length, noteToPlay: "A2")
98-
case 301...350:
99-
checkNote(length: length, noteToPlay: "B2")
100-
default:
101-
print("this shouldn't happen")
102-
}
103-
}
104-
contact.bodyA.node!.removeFromParent()
105-
contact.bodyB.node!.removeFromParent()
106-
}
107-
}
108-
*/
109-
110-
111-
112-
/*
113-
public func didEnd(_ contact: SKPhysicsContact) {
114-
115-
var firstBody: SKPhysicsBody
116-
var secondBody: SKPhysicsBody
117-
118-
if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask {
119-
firstBody = contact.bodyA
120-
secondBody = contact.bodyB
121-
} else {
122-
firstBody = contact.bodyB
123-
secondBody = contact.bodyA
124-
}
125-
126-
if firstBody.categoryBitMask == 2 && secondBody.categoryBitMask == 3 {
127-
contact.bodyA.node!.removeFromParent()
128-
contact.bodyB.node!.removeFromParent()
129-
}
130-
} */
131-
132-
133-
134-
135-
136-
*/

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

Lines changed: 81 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)