Skip to content

Commit 7dc4acb

Browse files
committed
Remove print statements
1 parent 1251cb9 commit 7dc4acb

16 files changed

+77
-93
lines changed

‎ps4/peggleclone/Models/Peg.swift‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ class Peg: PeggleObject {
7373

7474
override func overlap(peggleObject: PeggleObject) -> Bool {
7575
if let peg = peggleObject as? Peg {
76-
print("self.radius \(self.radius)")
77-
print("peg.radius \(peg.radius)")
7876
return distanceSquared(peg: peg) <= (self.radius + peg.radius) * (self.radius + peg.radius)
7977
} else if let triangle = peggleObject as? TriangleBlock {
8078
return triangle.overlap(peggleObject: self)
@@ -128,7 +126,6 @@ class Peg: PeggleObject {
128126
&& peg.center.yCoordinate <= (height - peg.radius)
129127
}
130128

131-
// TODO: refactor into own cannonball class
132129
override func spooked() {
133130
self.shadowRadius = 30.0
134131
self.shadow = .blue

‎ps4/peggleclone/Models/TriangleBlock.swift‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ class TriangleBlock: PeggleObject {
9696
if let peg = peggleObject as? Peg {
9797
return trianglePegOverlapCheck(peg: peg)
9898
} else if let triangle = peggleObject as? TriangleBlock {
99-
// print("self \(self.base) \(self.height)")
100-
// print("triangle \(triangle.base) \(triangle.height)")
101-
// return triangleTriangleOverlapCheck(triangle: triangle)
10299
return trianglesIntersect(self, triangle)
103100
} else {
104101
return false

‎ps4/peggleclone/Music/MusicManager.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class MusicManager {
2828
audioPlayer.prepareToPlay()
2929
audioPlayer.play()
3030
} catch {
31-
print(error)
31+
// print(error)
3232
}
3333
}
3434
}
@@ -43,7 +43,7 @@ class MusicManager {
4343
}
4444
audioPlayer.play()
4545
} catch {
46-
print(error)
46+
// print(error)
4747
}
4848
}
4949
}

‎ps4/peggleclone/Persistance/StorageManager.swift‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class StorageManager {
3333
fatalError("Unable to decode data")
3434
}
3535

36-
print(url)
3736
guard let persistanceLevels = try? decoder.decode([LevelPersistance].self, from: data) else {
3837
fatalError("Failed to decode JSON from data")
3938
}

‎ps4/peggleclone/SLGameEngine/PowerUpHandler.swift‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ class PowerUpHandler {
1717
if let spookyPeg = powerPeg as? SpookyPeg {
1818
if !spookyPeg.activated {
1919
spookyBallsActivated += 1
20-
print(spookyBallsActivated)
2120
spookyPeg.setActivated()
2221
}
2322
} else if let kaboomPeg = powerPeg as? KaboomPeg {
2423
if !kaboomPeg.activated {
2524
// find area of hit
2625
for (key, value) in mappings where isWithinExplosionRadius(kaboomPeg: kaboomPeg, physicsBody: value) {
27-
// TODO: make peggleobject have a glow method?
2826
if let peg = key as? Peg {
2927
peg.glow()
3028
value.setCollided()
@@ -72,7 +70,6 @@ class PowerUpHandler {
7270
cannonBallPhysicsBody
7371
.setVelocity(newVelocity: cannonBallPhysicsBody.velocity.multiplyWithScalar(scalar: 0.5))
7472
spookyBallsActivated -= 1
75-
print("used one spooky ball, \(spookyBallsActivated) left")
7673
}
7774
}
7875

‎ps4/peggleclone/SLGameEngine/SLGameEngine.swift‎

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import SwiftUI
1111
class SLGameEngine {
1212
private var physicsEngine = SLPhysicsWorld()
1313
private var mappings: [PeggleObject: SLPhysicsBody] = [:]
14+
private var trianglesRemovedTemporarily: [TriangleBlock: SLPhysicsBody] = [:]
1415
private let msPerUpdate = TimeInterval(0.016)
1516
private var lag = 0.0
1617
private var previous: Date?
@@ -71,12 +72,10 @@ class SLGameEngine {
7172
mappings[bucket] = bucketPhysicsBody
7273
physicsObjects.append(bucketPhysicsBody)
7374
physicsEngine.load(physicsBodies: physicsObjects, canvasDimensions: canvasDimensions)
74-
print(level.peggleObjects)
7575
addCannonBall()
76-
guard let cannonBall = cannonBall else {
76+
guard cannonBall != nil else {
7777
return
7878
}
79-
print(cannonBall)
8079
if numOfOrangePegs == 0 {
8180
gameLogicDelegate.gameWin()
8281
}
@@ -91,11 +90,6 @@ class SLGameEngine {
9190
let cannonBall = Peg(color: PegState.cannonPeg, center: toPoint(point: middleOfTopScreen),
9291
radius: Peg.pegMinRadiusRatio * canvasDimensions.width)
9392
self.cannonBall = cannonBall
94-
guard let cannonBallCheck = self.cannonBall else {
95-
print("failed to add")
96-
return
97-
}
98-
print("cannon ball added \(cannonBallCheck)")
9993
gameDisplayDelegate.didAddCannonBall(cannonBall: cannonBall)
10094
self.mostRecentPosition = cannonBall.center
10195
}
@@ -134,20 +128,19 @@ class SLGameEngine {
134128
render(cannonBallCount: numberOfCannonBalls)
135129
}
136130

137-
private func handleCannonBallMovement(_ cannonBallCount: Int, _ currentCollisions: [Peg]) {
131+
private func handleCannonBallMovement(_ cannonBallCount: Int, _ currentCollisions: [PeggleObject]) {
138132
guard let cannonBall = cannonBall,
139133
let cannonBallPhysicsBody = mappings[cannonBall],
140134
let gameDisplayDelegate = gameDisplayDelegate,
141135
let gameLogicDelegate = gameLogicDelegate else {
142136
return
143137
}
144-
145138
let similarPositionLimit = 75
146139

147140
if cannonBallCount == 0 {
148141
cannonBallPhysicsBody.ignore()
149142
mappings.removeValue(forKey: cannonBall)
150-
gameDisplayDelegate.didRemove(peg: cannonBall)
143+
gameDisplayDelegate.didRemove(peggleObject: cannonBall)
151144
if cannonBallInBucket {
152145
numOfCannonBallsLeft += 1
153146
gameLogicDelegate.addCannonball()
@@ -158,13 +151,17 @@ class SLGameEngine {
158151
} else {
159152
if isCannonBallSamePosition() {
160153
if similarPositionCounter > similarPositionLimit {
161-
for peg in currentCollisions {
162-
guard let pegInTouch = mappings[peg] else {
154+
for peggleObject in currentCollisions {
155+
guard let peggleObjInTouch = mappings[peggleObject] else {
163156
continue
164157
}
165-
if pegInTouch.hasCollided {
166-
pegInTouch.ignore()
167-
gameDisplayDelegate.didRemove(peg: peg)
158+
if peggleObjInTouch.hasCollided {
159+
peggleObjInTouch.ignore()
160+
gameDisplayDelegate.didRemove(peggleObject: peggleObject)
161+
if let triangle = peggleObject as? TriangleBlock {
162+
// handle them -> put in an array or whatever
163+
trianglesRemovedTemporarily[triangle] = peggleObjInTouch
164+
}
168165
}
169166
}
170167
} else {
@@ -206,12 +203,9 @@ class SLGameEngine {
206203
moveCannonBall(cannonBall, cannonBallPhysicsBody, gameDisplayDelegate)
207204

208205
let collisions = cannonBallPhysicsBody.collisionsWith
209-
let currentCollisions = handleCollisions(collisions,
210-
gameDisplayDelegate,
211-
gameLogicDelegate,
212-
cannonBallCount,
213-
cannonBall)
206+
let currentCollisions = handleCollisions(collisions, cannonBallCount)
214207

208+
checkCollidedTriangles()
215209
handleCannonBallMovement(cannonBallCount, currentCollisions)
216210

217211
if numOfCannonBallsLeft == 0 && cannonBallCount == 0 {
@@ -224,17 +218,38 @@ class SLGameEngine {
224218
}
225219
}
226220

221+
private func checkCollidedTriangles() {
222+
for (key, value) in trianglesRemovedTemporarily {
223+
if !touchingCannonBall(value) {
224+
gameDisplayDelegate?.didAdd(peggleObject: key)
225+
mappings[key] = value
226+
value.unignore()
227+
trianglesRemovedTemporarily.removeValue(forKey: key)
228+
}
229+
}
230+
}
231+
232+
private func touchingCannonBall(_ physicsBody: SLPhysicsBody) -> Bool {
233+
guard let cannonBall = cannonBall, let cannonBallMapping = mappings[cannonBall] else {
234+
return false
235+
}
236+
return cannonBallMapping.intersectWith(physicsBody: physicsBody)
237+
}
238+
227239
private func moveBucket(
228240
_ bucket: Bucket, _ bucketPhysicsBody: SLPhysicsBody, _ gameDisplayDelegate: GameDisplayDelegate) {
229241
bucket.center = bucketPhysicsBody.position
230242
gameDisplayDelegate.didMove(peggleObject: bucket, newLocation: bucketPhysicsBody.position)
231243
}
232244

233-
private func handleCollisions(
234-
_ collisions: [SLPhysicsBody], _ gameDisplayDelegate: GameDisplayDelegate,
235-
_ gameLogicDelegate: GameLogicDelegate,
236-
_ cannonBallCount: Int, _ cannonBall: Peg) -> [Peg] {
237-
var currentCollisions: [Peg] = []
245+
private func handleCollisions(_ collisions: [SLPhysicsBody], _ cannonBallCount: Int) -> [PeggleObject] {
246+
guard let gameLogicDelegate = gameLogicDelegate,
247+
let gameDisplayDelegate = gameDisplayDelegate,
248+
let cannonBall = cannonBall else {
249+
return []
250+
}
251+
252+
var currentCollisions: [PeggleObject] = []
238253

239254
for (key, value) in mappings where value.hasCollided {
240255
if let peg = key as? Peg {
@@ -246,8 +261,8 @@ class SLGameEngine {
246261
powerUpHandler.handlePowerUp(powerPeg: peg, mappings: mappings,
247262
cannonBall: cannonBall, gameDisplayDelegate: gameDisplayDelegate)
248263
}
249-
if cannonBallCount == 0 {
250-
gameDisplayDelegate.didRemove(peg: peg)
264+
if cannonBallCount == 0 && peg != cannonBall {
265+
gameDisplayDelegate.didRemove(peggleObject: peg)
251266
mappings.removeValue(forKey: peg)
252267
if peg.color != cannonBall.color {
253268
gameLogicDelegate.didAddPoints(peg.points)
@@ -261,6 +276,10 @@ class SLGameEngine {
261276
}
262277
}
263278
}
279+
} else if let triangle = key as? TriangleBlock {
280+
if contains(arr: collisions, physicsBody: value) {
281+
currentCollisions.append(triangle)
282+
}
264283
}
265284
}
266285

@@ -320,20 +339,15 @@ class SLGameEngine {
320339
}
321340

322341
func fireCannonBall(directionOf: Point) -> Bool {
323-
print("fire cannon ball")
324342
guard let cannonBall = cannonBall else {
325-
print("no cannon ball")
326343
return false
327344
}
328345

329346
if mappings[cannonBall] != nil {
330-
print("no cannon ball mapping")
331347
return false
332348
}
333349

334-
print("fired cannon ball")
335350
self.numOfCannonBallsLeft -= 1
336-
print(numOfCannonBallsLeft)
337351
var modifiedDirection = directionOf
338352
if directionOf.yCoordinate < cannonBall.center.yCoordinate {
339353
modifiedDirection = Point(xCoordinate: directionOf.xCoordinate,

‎ps4/peggleclone/SLPhysicsEngine/SLPhysicsBody.swift‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,6 @@ protocol SLPhysicsBody {
4545
func clearCollisionsWith()
4646

4747
func addForceToVelocity(force: Vector)
48+
49+
func unignore()
4850
}

‎ps4/peggleclone/SLPhysicsEngine/SLPhysicsBucket.swift‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,8 @@ class SLPhysicsBucket: SLPhysicsBody {
113113
func addForceToVelocity(force: Vector) {
114114
// do nothing
115115
}
116+
117+
func unignore() {
118+
self.canIgnore = false
119+
}
116120
}

‎ps4/peggleclone/SLPhysicsEngine/SLPhysicsCircle.swift‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,8 @@ class SLPhysicsCircle: SLPhysicsBody {
125125
func containsPoint(_ point: Point) -> Bool {
126126
point.distanceFrom(point: position) <= radius
127127
}
128+
129+
func unignore() {
130+
self.canIgnore = false
131+
}
128132
}

‎ps4/peggleclone/SLPhysicsEngine/SLPhysicsCollision.swift‎

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -39,63 +39,24 @@ class SLPhysicsCollision {
3939
}
4040

4141
private func resolveTriangleCircleCollision(triangle: SLPhysicsTriangle, circle: SLPhysicsCircle) {
42-
// let collisionVector = Vector(xDirection: circle.position.xCoordinate
43-
// - triangle.position.xCoordinate,
44-
// yDirection: circle.position.yCoordinate
45-
// - triangle.position.yCoordinate)
46-
// let distance = 2 * max(triangle.width / 2, circle.radius)
47-
// let collisionNormalVector = Vector(xDirection: collisionVector.xDirection / (distance),
48-
// yDirection: collisionVector.yDirection / (distance))
49-
// let relativeVelocity = triangle.velocity.subtract(vector: circle.velocity)
50-
// let tempSpeed = (relativeVelocity.xDirection * collisionVector.xDirection +
51-
// relativeVelocity.yDirection * collisionVector.yDirection)
52-
// let speedAfterScale = Double(tempSpeed) * speedScale
53-
// let speedAfterRestitution = speedAfterScale * restitution
54-
// if speedAfterRestitution >= 0 {
55-
// triangle.forces.append(collisionNormalVector
56-
// .multiplyWithScalar(scalar: -1 * speedAfterRestitution))
57-
// circle.forces.append(collisionNormalVector
58-
// .multiplyWithScalar(scalar: speedAfterRestitution))
59-
// }
6042
var restitution = 0.85
6143
if circleIntersectTriangleVertices(triangle: triangle, circle: circle) {
6244
restitution = 0.95
6345
circle.setVelocity(newVelocity: circle.velocity.negate().multiplyWithScalar(scalar: restitution))
6446
} else if circleIntersectEdge(circle: circle, vertexOne: triangle.vertexOne, vertexTwo: triangle.vertexTwo) {
6547
// rebound counter clockwise
66-
// let line = Vector(xDirection: triangle.vertexTwo.xCoordinate - triangle.vertexOne.xCoordinate,
67-
// yDirection: triangle.vertexTwo.yCoordinate - triangle.vertexOne.yCoordinate)
68-
// let normal = Vector(xDirection: -line.yDirection, yDirection: line.xDirection)
69-
// let normalUnitVector = normal.multiplyWithScalar(scalar: 1/normal.magnitude)
7048
let resultant = Vector(xDirection: -circle.velocity.yDirection,
7149
yDirection: circle.velocity.xDirection)
72-
// let resultant = circle.velocity
73-
// .subtract(vector: normalUnitVector
74-
// .multiplyWithScalar(scalar: 2 * circle.velocity.dotProductWith(vector: normalUnitVector)))
7550
circle.setVelocity(newVelocity: resultant.multiplyWithScalar(scalar: restitution))
7651
} else if circleIntersectEdge(circle: circle, vertexOne: triangle.vertexTwo, vertexTwo: triangle.vertexThree) {
7752
// rebound clockwise
78-
// let line = Vector(xDirection: triangle.vertexThree.xCoordinate - triangle.vertexTwo.xCoordinate,
79-
// yDirection: triangle.vertexThree.yCoordinate - triangle.vertexTwo.yCoordinate)
80-
// let normal = Vector(xDirection: line.yDirection, yDirection: -line.xDirection)
81-
// let normalUnitVector = normal.multiplyWithScalar(scalar: 1/normal.magnitude)
8253
let resultant = Vector(xDirection: circle.velocity.yDirection,
8354
yDirection: -circle.velocity.xDirection)
84-
// let resultant = circle.velocity
85-
// .subtract(vector: normalUnitVector
86-
// .multiplyWithScalar(scalar: 2 * circle.velocity.dotProductWith(vector: normalUnitVector)))
8755
circle.setVelocity(newVelocity: resultant.multiplyWithScalar(scalar: restitution))
8856
} else if circleIntersectEdge(circle: circle, vertexOne: triangle.vertexThree, vertexTwo: triangle.vertexOne) {
8957
// rebound clockwise
90-
// let line = Vector(xDirection: triangle.vertexOne.xCoordinate - triangle.vertexThree.xCoordinate,
91-
// yDirection: triangle.vertexOne.yCoordinate - triangle.vertexThree.yCoordinate)
92-
// let normal = Vector(xDirection: line.yDirection, yDirection: -line.xDirection)
93-
// let normalUnitVector = normal.multiplyWithScalar(scalar: 1/normal.magnitude)
9458
let resultant = Vector(xDirection: circle.velocity.yDirection,
9559
yDirection: -circle.velocity.xDirection)
96-
// let resultant = circle.velocity
97-
// .subtract(vector: normalUnitVector
98-
// .multiplyWithScalar(scalar: 2 * circle.velocity.dotProductWith(vector: normalUnitVector)))
9960
circle.setVelocity(newVelocity: resultant.multiplyWithScalar(scalar: restitution))
10061
}
10162
}

0 commit comments

Comments
 (0)