东风启辰小程序端
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.8KB

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