东风启辰小程序端
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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. return app.sharePack();
  64. },
  65. closeRule:function(){//关闭游戏玩法
  66. this.setData({
  67. ruleShow:false
  68. })
  69. },
  70. openGameRule: function () {//打开游戏玩法
  71. this.setData({
  72. ruleShow: true
  73. })
  74. },
  75. gameStart: function () {//开始游戏
  76. if (!this.data.ruleCloseShow) {
  77. this.downTimeFun();
  78. }
  79. this.setData({
  80. ruleShow: false,
  81. ruleCloseShow: true
  82. })
  83. },
  84. startClaw:function(e){//开始控制爪子方向
  85. let direction = e.currentTarget.dataset.direction;
  86. if (direction == "L") {//向左
  87. if (this.data.clawLeft <= 130) {
  88. return;
  89. }
  90. this.data.setGroup.left = setInterval(() => {
  91. this.setData({
  92. clawLeft: this.data.clawLeft-=2
  93. })
  94. if (this.data.clawLeft <= 130) {
  95. clearInterval(this.data.setGroup.left);
  96. }
  97. },20);
  98. } else if (direction == "R") {//向右
  99. if (this.data.clawLeft >= 445) {
  100. return;
  101. }
  102. this.data.setGroup.right = setInterval(() => {
  103. this.setData({
  104. clawLeft: this.data.clawLeft += 2
  105. })
  106. if (this.data.clawLeft >= 445) {
  107. clearInterval(this.data.setGroup.right);
  108. }
  109. }, 20);
  110. } else if (direction == "T") {//向后
  111. if (this.data.clawScale <= 0.5) {
  112. return;
  113. }
  114. this.data.setGroup.top = setInterval(() => {
  115. this.setData({
  116. clawScale: this.data.clawScale -= 0.01
  117. })
  118. if (this.data.clawScale <= 0.5) {
  119. clearInterval(this.data.setGroup.top);
  120. }
  121. }, 20);
  122. } else if (direction == "B") {//向前
  123. if (this.data.clawScale >= 1.5) {
  124. return;
  125. }
  126. this.data.setGroup.bottom = setInterval(() => {
  127. this.setData({
  128. clawScale: this.data.clawScale += 0.01
  129. })
  130. if (this.data.clawScale >= 1.5) {
  131. clearInterval(this.data.setGroup.bottom);
  132. }
  133. }, 20);
  134. }
  135. },
  136. endClaw:function(e){//结束爪子动作
  137. let direction = e.currentTarget.dataset.direction;
  138. if (direction == "L") {//向左
  139. clearInterval(this.data.setGroup.left);
  140. } else if (direction == "R") {//向右
  141. clearInterval(this.data.setGroup.right);
  142. } else if (direction == "T") {//向后
  143. clearInterval(this.data.setGroup.top);
  144. } else if (direction == "B") {//向前
  145. clearInterval(this.data.setGroup.bottom);
  146. }
  147. },
  148. getClaw:function(){//抓取
  149. this.setData({
  150. clawTop: this.data.clawScale > 1 ? 490 - (2 * (this.data.clawScale-1) * 90) : 490 + (2 * (1 - this.data.clawScale) * 90 )
  151. })
  152. this.closeSetInt();
  153. },
  154. downTimeFun:function(){//游戏倒计时
  155. this.data.setInt = setInterval(()=>{
  156. this.data.downNum -= 1;
  157. if (this.data.downNum<10){
  158. this.data.downNum = '0' + this.data.downNum;
  159. }
  160. this.setData({
  161. downNum: this.data.downNum
  162. })
  163. if (this.data.downNum < 1) {
  164. this.closeSetInt();
  165. }
  166. },1000);
  167. },
  168. closeSetInt:function(){//关闭倒计时
  169. clearInterval(this.data.setInt);
  170. this.setData({
  171. downNum: 30,
  172. clawTop: this.data.clawScale > 1 ? 455 - (2 * (this.data.clawScale - 1) * 90) : 455 + (2 * (1 - this.data.clawScale) * 90)
  173. })
  174. setTimeout(()=>{
  175. this.setData({
  176. downNum: 30,
  177. clawTop: 95,
  178. clawLeft: 293,
  179. clawScale:1
  180. })
  181. }, 1200);
  182. },
  183. prizeLook:function(){//活动奖品
  184. wx.navigateTo({
  185. url: '../prizes/prizes'
  186. })
  187. }
  188. })