Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't insist on a mixture of swipes and taps; interpret swipes in all directions #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions ARTetris/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,36 @@ class ViewController: UIViewController, ARSCNViewDelegate {
let swiftUp = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipe(sender:)))
swiftUp.direction = .up
self.view.addGestureRecognizer(swiftUp)

let swiftLeft = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipe(sender:)))
swiftLeft.direction = .left
self.view.addGestureRecognizer(swiftLeft)

let swiftRight = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipe(sender:)))
swiftRight.direction = .right
self.view.addGestureRecognizer(swiftRight)

let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap(sender:)))
self.view.addGestureRecognizer(tap)
}

@objc private func handleSwipe(sender: UISwipeGestureRecognizer) {
if (sender.direction == .down) {
// drop down tetromino on swipe down
tetris?.drop()
} else {
// rotate tetromino on swipe up
tetris?.rotate()
}
switch sender.direction {
case .down:
// drop down tetromino on swipe down
tetris?.drop()
case .up:
// rotate tetromino on swipe up
tetris?.rotate()
case .left:
// move tetromino left on swipe left
tetris?.left()
case .right:
// move tetromino right on right left
tetris?.right()
default:
break
}
}

@objc private func handleTap(sender: UITapGestureRecognizer) {
Expand Down