Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. override func viewDidLoad() {
  2. Timer.scheduledTimer(timeInterval: 5.0, target: self, selector: #selector(ViewController.startRedBalloon), userInfo: nil, repeats: true)
  3. }
  4.  
  5. @objc func startRedBalloon() {
  6. let xOrigin = arc4random_uniform(208) + 1
  7. let xEnding = arc4random_uniform(208) + 1
  8.  
  9. redBalloon.isHidden = false
  10. redBalloon.image = UIImage(named: "redBalloon")
  11. redBalloon.contentMode = .scaleAspectFit
  12. redBalloon.frame = CGRect(x: Int(xOrigin), y: 667, width: Int(redBalloon.frame.size.width), height: Int(redBalloon.frame.size.height))
  13.  
  14. let animRed = UIViewPropertyAnimator(duration: 5, timingParameters: UICubicTimingParameters(animationCurve: .easeIn))
  15. animRed.addAnimations {
  16. self.redBalloon.frame = CGRect(x: Int(xEnding), y: -192, width: 100, height: 116)
  17. }
  18. animRed.addCompletion { _ in
  19. self.endGame()
  20. }
  21.  
  22. let imageTapRed = UITapGestureRecognizer(target: self, action: #selector(imageTappedRed))
  23. redBalloon.isUserInteractionEnabled = true
  24. redBalloon.addGestureRecognizer(imageTapRed)
  25. animRed.startAnimation()
  26. }
  27.  
  28. @objc func imageTappedRed(_ sender: UITapGestureRecognizer) {
  29. redBalloon.image = UIImage(named: "redShreds")
  30. UIViewPropertyAnimator(duration: 2, curve: .easeOut, animations: {
  31. self.redBalloon.alpha = 0.0
  32. }).startAnimation()
  33. score += 1
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement