Skip to content

Commit

Permalink
Complete Challenge 1
Browse files Browse the repository at this point in the history
> Stop the player from cheating by lifting their finger and tapping elsewhere.
  • Loading branch information
CypherPoet authored and CypherPoet committed Apr 19, 2019
1 parent e2c94ea commit eecdd7e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions day-062/project/Space Race/Space Race/Scenes/MainGameScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,15 @@ extension MainGameScene {
// MARK: - Event handling

extension MainGameScene {

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else { return }

var touchLocation = touch.location(in: self)
guard
currentGameplayState == .inProgress,
var touchLocation = touches.first?.location(in: self),
didTouchPlayer(touchLocation)
else {
return
}

if touchLocation.y > shipScreenBounds.top {
touchLocation.y = shipScreenBounds.top
Expand Down Expand Up @@ -232,4 +237,9 @@ private extension MainGameScene {
func remove(node: SKNode) {
node.removeFromParent()
}


func didTouchPlayer(_ touchLocation: CGPoint) -> Bool {
return playerShip.contains(touchLocation)
}
}

0 comments on commit eecdd7e

Please sign in to comment.