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

luckyStar.js 11KB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. // pages/luckyStar/luckyStar.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrl: app.globalData.urlStatic,//图片路径
  9. ruleShow: true,//是否显示游戏玩法
  10. ruleCloseShow: true,//是否显示游戏玩法关闭按钮
  11. clawTop:-440,//爪子的top值
  12. clawLeft: 268,//爪子的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. btnGroup:{
  24. left: false,
  25. right: false,
  26. top: false,
  27. bottom: false,
  28. claw:false
  29. },
  30. gameSign: null, //游戏结束时需要
  31. gameState:false,//游戏状态
  32. endGameData:null,//中奖数据
  33. isAddress:false,//是否有地址
  34. configure:{
  35. page:1,
  36. count:10
  37. },
  38. gameAwardList:[],
  39. userData:null,
  40. scrollNum:0,
  41. setInt:null,
  42. isMore:true,
  43. startDown:-1,//游戏开始倒计时
  44. clawType:false,//是否正在抓取
  45. gameEnd:true
  46. },
  47. /**
  48. * 生命周期函数--监听页面加载
  49. */
  50. onLoad: function (options) {
  51. app.globalData.nowPage = 3;
  52. if (app.globalData.openid) {
  53. this.loadFun();
  54. } else {
  55. app.globalData.openidSuccessFuc = this.loadFun;
  56. }
  57. },
  58. loadFun: function () {
  59. if (app.globalData.userInfoData) {
  60. this.setData({
  61. userData: app.globalData.userInfoData
  62. })
  63. }
  64. this.getAddress();
  65. this.getGameAwardList();
  66. },
  67. /**
  68. * 生命周期函数--监听页面初次渲染完成
  69. */
  70. onReady: function () {
  71. },
  72. /**
  73. * 生命周期函数--监听页面显示
  74. */
  75. onShow: function () {
  76. },
  77. /**
  78. * 生命周期函数--监听页面隐藏
  79. */
  80. onHide: function () {
  81. },
  82. /**
  83. * 生命周期函数--监听页面卸载
  84. */
  85. onUnload: function () {
  86. },
  87. /**
  88. * 页面相关事件处理函数--监听用户下拉动作
  89. */
  90. onPullDownRefresh: function () {
  91. },
  92. /**
  93. * 页面上拉触底事件的处理函数
  94. */
  95. onReachBottom: function () {
  96. },
  97. /**
  98. * 用户点击右上角分享
  99. */
  100. onShareAppMessage: function () {
  101. return app.sharePack();
  102. },
  103. closeRule:function(){//关闭游戏玩法
  104. this.setData({
  105. ruleShow:false
  106. })
  107. },
  108. openGameRule: function () {//打开游戏玩法
  109. if(!this.data.gameState){
  110. this.setData({
  111. ruleShow: true
  112. })
  113. }
  114. },
  115. gameStart: function () {//开始游戏按钮
  116. this.setData({
  117. ruleShow: false,
  118. ruleCloseShow: true
  119. })
  120. this.beginGame();
  121. },
  122. beginGame: function () {//开始游戏
  123. app.wxRequest(app.globalData.urlRoot + "dollGame/beginGame", {}, res => {
  124. if(res.code==200){
  125. this.setData({
  126. startDown: 3
  127. })
  128. var setInt2 = setInterval(() => {
  129. if (this.data.startDown > -1) {
  130. this.data.startDown -= 1;
  131. this.setData({
  132. startDown: this.data.startDown
  133. })
  134. if (this.data.startDown==-1){
  135. clearInterval(setInt2);
  136. this.data.gameSign = res.data.sign;
  137. this.endGame();
  138. if (this.data.gameSign) {
  139. this.downTimeFun();
  140. }
  141. }
  142. }
  143. }, 1000);
  144. }else{
  145. wx.showToast({
  146. title: res.msg,
  147. icon:"none"
  148. })
  149. }
  150. },this)
  151. },
  152. endGame:function(){//结束游戏
  153. app.wxRequest(app.globalData.urlRoot + "dollGame/endGame", { sign:this.data.gameSign}, res => {
  154. if(res.code=200){
  155. this.setData({
  156. endGameData: res.data
  157. })
  158. }else{
  159. console.log(res);
  160. }
  161. }, this,"POST")
  162. },
  163. startClaw:function(e){//开始控制爪子方向
  164. if(!this.data.gameState){
  165. return;
  166. }
  167. let direction = e.currentTarget.dataset.direction;
  168. if (direction == "L") {//向左
  169. this.data.btnGroup.left = true;
  170. this.setData({
  171. btnGroup: this.data.btnGroup
  172. })
  173. if (this.data.clawLeft <= 110) {
  174. return;
  175. }
  176. this.data.setGroup.left = setInterval(() => {
  177. this.setData({
  178. clawLeft: this.data.clawLeft-=2
  179. })
  180. if (this.data.clawLeft <= 110) {
  181. clearInterval(this.data.setGroup.left);
  182. }
  183. },20);
  184. } else if (direction == "R") {//向右
  185. this.data.btnGroup.right = true;
  186. this.setData({
  187. btnGroup: this.data.btnGroup
  188. })
  189. if (this.data.clawLeft >= 415) {
  190. return;
  191. }
  192. this.data.setGroup.right = setInterval(() => {
  193. this.setData({
  194. clawLeft: this.data.clawLeft += 2
  195. })
  196. if (this.data.clawLeft >= 415) {
  197. clearInterval(this.data.setGroup.right);
  198. }
  199. }, 20);
  200. } else if (direction == "T") {//向后
  201. this.data.btnGroup.top = true;
  202. this.setData({
  203. btnGroup: this.data.btnGroup
  204. })
  205. if (this.data.clawScale <= 0.8) {
  206. return;
  207. }
  208. this.data.setGroup.top = setInterval(() => {
  209. this.setData({
  210. clawScale: this.data.clawScale -= 0.01
  211. })
  212. if (this.data.clawScale <= 0.8) {
  213. clearInterval(this.data.setGroup.top);
  214. }
  215. }, 20);
  216. } else if (direction == "B") {//向前
  217. this.data.btnGroup.bottom = true;
  218. this.setData({
  219. btnGroup: this.data.btnGroup
  220. })
  221. if (this.data.clawScale >= 1.2) {
  222. return;
  223. }
  224. this.data.setGroup.bottom = setInterval(() => {
  225. this.setData({
  226. clawScale: this.data.clawScale += 0.01
  227. })
  228. if (this.data.clawScale >= 1.2) {
  229. clearInterval(this.data.setGroup.bottom);
  230. }
  231. }, 20);
  232. }
  233. },
  234. endClaw: function (e) {//结束爪子动作
  235. if (!this.data.gameState) {
  236. return;
  237. }
  238. let direction = e.currentTarget.dataset.direction;
  239. if (direction == "L") {//向左
  240. this.data.btnGroup.left = false;
  241. this.setData({
  242. btnGroup: this.data.btnGroup
  243. })
  244. clearInterval(this.data.setGroup.left);
  245. } else if (direction == "R") {//向右
  246. this.data.btnGroup.right = false;
  247. this.setData({
  248. btnGroup: this.data.btnGroup
  249. })
  250. clearInterval(this.data.setGroup.right);
  251. } else if (direction == "T") {//向后
  252. this.data.btnGroup.top = false;
  253. this.setData({
  254. btnGroup: this.data.btnGroup
  255. })
  256. clearInterval(this.data.setGroup.top);
  257. } else if (direction == "B") {//向前
  258. this.data.btnGroup.bottom = false;
  259. this.setData({
  260. btnGroup: this.data.btnGroup
  261. })
  262. clearInterval(this.data.setGroup.bottom);
  263. }
  264. },
  265. getClaw:function(){//抓取
  266. this.setData({
  267. clawType:true
  268. })
  269. this.setData({
  270. clawTop: this.data.clawScale > 1 ? -100 - (2 * (this.data.clawScale - 1) * 440) : -100 + (2 * (1 - this.data.clawScale) * 440 )
  271. })
  272. this.closeSetInt();
  273. setTimeout(() => {
  274. this.setData({
  275. clawType: false
  276. })
  277. this.data.gameState = false;
  278. if (this.data.endGameData) {
  279. this.setData({
  280. pizeTip: 1
  281. })
  282. } else {
  283. if (this.data.isAddress) {
  284. this.setData({
  285. pizeTip: 2
  286. })
  287. } else {
  288. this.setData({
  289. pizeTip: 3
  290. })
  291. }
  292. }
  293. },800)
  294. },
  295. downTimeFun: function () {//游戏倒计时
  296. this.data.gameState = true;
  297. this.data.setInt = setInterval(()=>{
  298. this.data.downNum -= 1;
  299. if (this.data.downNum<10){
  300. this.data.downNum = '0' + this.data.downNum;
  301. }
  302. this.setData({
  303. downNum: this.data.downNum
  304. })
  305. if (this.data.downNum < 1) {
  306. this.getClaw();
  307. }
  308. },1000);
  309. },
  310. closeSetInt: function () {//关闭倒计时
  311. clearInterval(this.data.setInt);
  312. this.setData({
  313. downNum: 30,
  314. clawTop: this.data.clawScale > 1 ? -100 - (2 * (this.data.clawScale - 1) * 440) : -100 + (2 * (1 - this.data.clawScale) * 440)
  315. })
  316. setTimeout(() => {
  317. this.setData({
  318. gameEnd:false
  319. })
  320. this.setData({
  321. downNum: 30,
  322. clawScale: 1
  323. })
  324. setTimeout(() => {
  325. this.setData({
  326. clawTop: -440,
  327. })
  328. }, 800)
  329. setTimeout(()=>{
  330. this.setData({
  331. clawLeft: 268
  332. })
  333. },1600)
  334. setTimeout(()=>{
  335. this.setData({
  336. gameEnd: true
  337. })
  338. },2400)
  339. }, 800);
  340. },
  341. prizeLook:function(){//活动奖品
  342. if(!this.data.gameState){
  343. wx.navigateTo({
  344. url: '../prizes/prizes'
  345. })
  346. }
  347. },
  348. getAddress: function () {//获取地址
  349. app.wxRequest(app.globalData.urlRoot + "address/getAddress", {}, res => {
  350. if (res.code == 200) {
  351. if (res.data) {
  352. this.setData({
  353. isAddress:true
  354. })
  355. }
  356. }
  357. }, this)
  358. },
  359. receive:function(){//立即领取
  360. wx.redirectTo({
  361. url: '../myCenter/myCenter',
  362. })
  363. },
  364. invitation: function () {//邀请好友一起来玩
  365. },
  366. userRegister: function () {//立即注册,探索更多星探好礼
  367. wx.navigateTo({
  368. url: '../address/address',
  369. })
  370. },
  371. closeWindow:function(){//关闭中奖
  372. this.setData({
  373. pizeTip:0,
  374. ruleShow:true
  375. })
  376. },
  377. getGameAwardList: function () {//获取游戏中奖数据
  378. app.wxRequest(app.globalData.urlRoot + "award/getGameAwardList", this.data.configure,res=>{
  379. if(res.code==200){
  380. if(res.data.length<this.data.configure.count){
  381. this.data.isMore = false;
  382. }
  383. for(let i=0;i<res.data.length;i++){
  384. this.data.gameAwardList.push(res.data[i]);
  385. }
  386. this.setData({
  387. gameAwardList: this.data.gameAwardList
  388. })
  389. if(this.data.configure.page==1){
  390. this.changeScroll();
  391. }
  392. }
  393. },this)
  394. },
  395. getUserWxMsg: function (e) {//通过微信获取用户信息
  396. if (e.detail.errMsg == "getUserInfo:ok") {
  397. this.gameStart();
  398. this.setData({
  399. userData: e.detail.userInfo
  400. })
  401. app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
  402. }else{
  403. this.gameStart();
  404. }
  405. },
  406. changeScroll:function(){
  407. // this.data.setInt = setInterval(()=>{
  408. // this.setData({
  409. // scrollNum: this.data.scrollNum+=1
  410. // })
  411. // },30);
  412. },
  413. getMore:function(){
  414. if (!this.data.isMore){
  415. this.setData({
  416. scrollNum: 0
  417. })
  418. return;
  419. }
  420. this.data.configure.page+=1;
  421. this.getGameAwardList();
  422. },
  423. cutPage:function(){//500元待领取
  424. wx.redirectTo({
  425. url: '/pages/star/star',
  426. })
  427. },
  428. openClaw:function(){
  429. if (!this.data.gameState) {
  430. return;
  431. }
  432. this.data.btnGroup.claw = true;
  433. this.setData({
  434. btnGroup: this.data.btnGroup
  435. })
  436. setTimeout(()=>{
  437. this.data.btnGroup.claw = false;
  438. this.setData({
  439. btnGroup: this.data.btnGroup
  440. })
  441. this.getClaw();
  442. },200);
  443. }
  444. })