东风启辰小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
4.7KB

  1. // pages/luckyStar/luckyStar.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrl: app.globalData.urlStatic,//图片路径
  9. ruleShow: false,//是否显示游戏玩法
  10. ruleCloseShow: false,//是否显示游戏玩法关闭按钮
  11. clawTop:95,//爪子的top值
  12. clawLeft: 293,//爪子的left值
  13. clawScale: 1,//爪子的scale值
  14. downNum:30,//倒计时时间
  15. setInt:null,//倒计时元素
  16. pizeTip:0,//抓奖提示框
  17. setGroup:{
  18. left:null,
  19. right: null,
  20. top: null,
  21. bottom: null,
  22. }
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad: function (options) {
  28. },
  29. /**
  30. * 生命周期函数--监听页面初次渲染完成
  31. */
  32. onReady: function () {
  33. },
  34. /**
  35. * 生命周期函数--监听页面显示
  36. */
  37. onShow: function () {
  38. },
  39. /**
  40. * 生命周期函数--监听页面隐藏
  41. */
  42. onHide: function () {
  43. },
  44. /**
  45. * 生命周期函数--监听页面卸载
  46. */
  47. onUnload: function () {
  48. },
  49. /**
  50. * 页面相关事件处理函数--监听用户下拉动作
  51. */
  52. onPullDownRefresh: function () {
  53. },
  54. /**
  55. * 页面上拉触底事件的处理函数
  56. */
  57. onReachBottom: function () {
  58. },
  59. /**
  60. * 用户点击右上角分享
  61. */
  62. onShareAppMessage: function () {
  63. },
  64. closeRule:function(){//关闭游戏玩法
  65. this.setData({
  66. ruleShow:false
  67. })
  68. },
  69. openGameRule: function () {//打开游戏玩法
  70. this.setData({
  71. ruleShow: true
  72. })
  73. },
  74. gameStart: function () {//开始游戏
  75. if (!this.data.ruleCloseShow) {
  76. this.downTimeFun();
  77. }
  78. this.setData({
  79. ruleShow: false,
  80. ruleCloseShow: true
  81. })
  82. },
  83. startClaw:function(e){//开始控制爪子方向
  84. let direction = e.currentTarget.dataset.direction;
  85. if (direction == "L") {//向左
  86. if (this.data.clawLeft <= 130) {
  87. return;
  88. }
  89. this.data.setGroup.left = setInterval(() => {
  90. this.setData({
  91. clawLeft: this.data.clawLeft-=2
  92. })
  93. if (this.data.clawLeft <= 130) {
  94. clearInterval(this.data.setGroup.left);
  95. }
  96. },20);
  97. } else if (direction == "R") {//向右
  98. if (this.data.clawLeft >= 445) {
  99. return;
  100. }
  101. this.data.setGroup.right = setInterval(() => {
  102. this.setData({
  103. clawLeft: this.data.clawLeft += 2
  104. })
  105. if (this.data.clawLeft >= 445) {
  106. clearInterval(this.data.setGroup.right);
  107. }
  108. }, 20);
  109. } else if (direction == "T") {//向后
  110. if (this.data.clawScale <= 0.5) {
  111. return;
  112. }
  113. this.data.setGroup.top = setInterval(() => {
  114. this.setData({
  115. clawScale: this.data.clawScale -= 0.01
  116. })
  117. if (this.data.clawScale <= 0.5) {
  118. clearInterval(this.data.setGroup.top);
  119. }
  120. }, 20);
  121. } else if (direction == "B") {//向前
  122. if (this.data.clawScale >= 1.5) {
  123. return;
  124. }
  125. this.data.setGroup.bottom = setInterval(() => {
  126. this.setData({
  127. clawScale: this.data.clawScale += 0.01
  128. })
  129. if (this.data.clawScale >= 1.5) {
  130. clearInterval(this.data.setGroup.bottom);
  131. }
  132. }, 20);
  133. }
  134. },
  135. endClaw:function(e){//结束爪子动作
  136. let direction = e.currentTarget.dataset.direction;
  137. if (direction == "L") {//向左
  138. clearInterval(this.data.setGroup.left);
  139. } else if (direction == "R") {//向右
  140. clearInterval(this.data.setGroup.right);
  141. } else if (direction == "T") {//向后
  142. clearInterval(this.data.setGroup.top);
  143. } else if (direction == "B") {//向前
  144. clearInterval(this.data.setGroup.bottom);
  145. }
  146. },
  147. getClaw:function(){//抓取
  148. this.setData({
  149. clawTop: this.data.clawScale > 1 ? 490 - (2 * (this.data.clawScale-1) * 90) : 490 + (2 * (1 - this.data.clawScale) * 90 )
  150. })
  151. this.closeSetInt();
  152. },
  153. downTimeFun:function(){//游戏倒计时
  154. this.data.setInt = setInterval(()=>{
  155. this.data.downNum -= 1;
  156. if (this.data.downNum<10){
  157. this.data.downNum = '0' + this.data.downNum;
  158. }
  159. this.setData({
  160. downNum: this.data.downNum
  161. })
  162. if (this.data.downNum < 1) {
  163. this.closeSetInt();
  164. }
  165. },1000);
  166. },
  167. closeSetInt:function(){//关闭倒计时
  168. clearInterval(this.data.setInt);
  169. this.setData({
  170. downNum: 30,
  171. clawTop: this.data.clawScale > 1 ? 455 - (2 * (this.data.clawScale - 1) * 90) : 455 + (2 * (1 - this.data.clawScale) * 90)
  172. })
  173. setTimeout(()=>{
  174. this.setData({
  175. downNum: 30,
  176. clawTop: 95,
  177. clawLeft: 293,
  178. clawScale:1
  179. })
  180. }, 1200);
  181. },
  182. prizeLook:function(){//活动奖品
  183. wx.navigateTo({
  184. url: '../prizes/prizes'
  185. })
  186. }
  187. })