Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- override func viewDidLoad() {
- Timer.scheduledTimer(timeInterval: 5.0, target: self, selector: #selector(ViewController.startRedBalloon), userInfo: nil, repeats: true)
- }
- @objc func startRedBalloon() {
- let xOrigin = arc4random_uniform(208) + 1
- let xEnding = arc4random_uniform(208) + 1
- redBalloon.isHidden = false
- redBalloon.image = UIImage(named: "redBalloon")
- redBalloon.contentMode = .scaleAspectFit
- redBalloon.frame = CGRect(x: Int(xOrigin), y: 667, width: Int(redBalloon.frame.size.width), height: Int(redBalloon.frame.size.height))
- let animRed = UIViewPropertyAnimator(duration: 5, timingParameters: UICubicTimingParameters(animationCurve: .easeIn))
- animRed.addAnimations {
- self.redBalloon.frame = CGRect(x: Int(xEnding), y: -192, width: 100, height: 116)
- }
- animRed.addCompletion { _ in
- self.endGame()
- }
- let imageTapRed = UITapGestureRecognizer(target: self, action: #selector(imageTappedRed))
- redBalloon.isUserInteractionEnabled = true
- redBalloon.addGestureRecognizer(imageTapRed)
- animRed.startAnimation()
- }
- @objc func imageTappedRed(_ sender: UITapGestureRecognizer) {
- redBalloon.image = UIImage(named: "redShreds")
- UIViewPropertyAnimator(duration: 2, curve: .easeOut, animations: {
- self.redBalloon.alpha = 0.0
- }).startAnimation()
- score += 1
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement