Skip to content

Commit 89fffce

Browse files
committed
fixed bug where wrong notes would play
1 parent f11fca1 commit 89fffce

File tree

4 files changed

+52
-26
lines changed

4 files changed

+52
-26
lines changed
0 Bytes
Binary file not shown.

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

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
145145

146146
public func prepareNoteForSpawn(note: String, octave: Int, length: Double) {
147147

148-
let noteWidth = 43.75
148+
let noteWidth = 50.00
149149
var noteHeight : Double
150150
var x: Double = 0
151151

@@ -155,21 +155,21 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
155155
//Based on the note we have, spawn it in at the correct x position
156156
switch note {
157157
case "C":
158-
x = noteWidth * -8
159-
case "D":
160158
x = noteWidth * -7
161-
case "E":
159+
case "D":
162160
x = noteWidth * -6
163-
case "F":
161+
case "E":
164162
x = noteWidth * -5
165-
case "G":
163+
case "F":
166164
x = noteWidth * -4
167-
case "A":
165+
case "G":
168166
x = noteWidth * -3
169-
case "B":
167+
case "A":
170168
x = noteWidth * -2
171-
case "C2":
169+
case "B":
172170
x = noteWidth * -1
171+
case "C2":
172+
x = noteWidth * 0
173173
case "D2":
174174
x = noteWidth
175175
case "E2":
@@ -224,7 +224,7 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
224224
scene.addChild(newNote)
225225

226226
//start moving down the screen
227-
let move = SKAction.moveBy(x: 0, y: -1500, duration: 15/5)
227+
let move = SKAction.moveBy(x: 0, y: -1500, duration: 15/3)
228228
newNote.run(move)
229229

230230
//to maintain performance, delete note nodes after they leave the screen.
@@ -320,7 +320,33 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
320320
//this function adds all the notes to the array within the Song class
321321
public func setupSong() {
322322
// .quarter = .25, half = .5, and so on; fix later
323-
for _ in 0...5 {
323+
324+
song.addNote(note: "D", octave: 1, length: 0.25)
325+
song.addDelay(length: 0.5)
326+
song.addNote(note: "D", octave: 1, length: 0.25)
327+
song.addDelay(length: 0.5)
328+
song.addNote(note: "E", octave: 1, length: 0.25)
329+
song.addDelay(length: 0.5)
330+
song.addNote(note: "D", octave: 1, length: 0.25)
331+
song.addDelay(length: 0.5)
332+
song.addNote(note: "G", octave: 1, length: 0.25)
333+
song.addDelay(length: 0.5)
334+
song.addNote(note: "F", octave: 1, length: 0.5)
335+
song.addDelay(length: 0.5)
336+
song.addNote(note: "D", octave: 1, length: 0.25)
337+
song.addDelay(length: 0.5)
338+
song.addNote(note: "D", octave: 1, length: 0.25)
339+
song.addDelay(length: 0.5)
340+
song.addNote(note: "E", octave: 1, length: 0.25)
341+
song.addDelay(length: 0.5)
342+
song.addNote(note: "D", octave: 1, length: 0.25)
343+
song.addDelay(length: 0.5)
344+
song.addNote(note: "A", octave: 1, length: 0.25)
345+
song.addDelay(length: 0.5)
346+
song.addNote(note: "G", octave: 1, length: 0.5)
347+
song.addDelay(length: 0.5)
348+
349+
/*for _ in 0...5 {
324350
song.addNote(note: "A", octave: 1, length: 0.25)
325351
song.addDelay(length: 0.25)
326352
song.addNote(note: "C", octave: 1, length: 0.5)
@@ -341,7 +367,7 @@ public class GameScene: SKScene, SKPhysicsContactDelegate {
341367
song.addDelay(length: 0.25)
342368
song.addNote(note: "F2", octave: 1, length: 0.25)
343369
song.addDelay(length: 0.25)
344-
}
370+
}*/
345371
}
346372

347373
var i = -1

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,33 @@ struct Sound {
1010
//find out what note to play.
1111
//the x value of the note determines the note it should play
1212
switch input {
13-
case -350 ... -300:
13+
case -350 ..< -300:
1414
noteString = "C1"
15-
case -299 ... -250:
15+
case -300 ..< -250:
1616
noteString = "D1"
17-
case -249 ... -200:
17+
case -250 ..< -200:
1818
noteString = "E1"
19-
case -199 ... -150:
19+
case -200 ..< -150:
2020
noteString = "F1"
21-
case -149 ... -100:
21+
case -150 ..< -100:
2222
noteString = "G1"
23-
case -99 ... -50:
23+
case -100 ..< -50:
2424
noteString = "A1"
25-
case -49 ... 0:
25+
case -50 ..< 0:
2626
noteString = "B1"
27-
case 1...50:
27+
case 0 ..< 50:
2828
noteString = "C2"
29-
case 51...100:
29+
case 51..<100:
3030
noteString = "D2"
31-
case 101...150:
31+
case 100..<150:
3232
noteString = "E2"
33-
case 151...200:
33+
case 150..<200:
3434
noteString = "F2"
35-
case 201...250:
35+
case 200..<250:
3636
noteString = "G2"
37-
case 251...300:
37+
case 250..<300:
3838
noteString = "A2"
39-
case 301...350:
39+
case 300...350:
4040
noteString = "B2"
4141
default:
4242
print("this shouldn't happen")

0 commit comments

Comments
 (0)