LongAcceleration.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. YellowBG: {
  14. default: null,
  15. type: cc.Node,
  16. },
  17. isStart: true,
  18. isStop: false,
  19. addScore: 0,
  20. },
  21. // LIFE-CYCLE CALLBACKS:
  22. // onLoad () {},
  23. start() {
  24. // console.log('长加速带');
  25. },
  26. update(dt) {
  27. if (GlobalData.game.state !== GlobalData.GameManager.State.Run) {
  28. return;
  29. }
  30. if (GlobalData.game.PlayerState == GlobalData.GameManager.PlayerState.Stop) {
  31. return;
  32. }
  33. this.speed = -GlobalData.game.GameSpeed;
  34. this.node.x += this.speed * dt;
  35. // console.log(this.node.getBoundingBoxToWorld().xMax);
  36. var disappear = this.node.getBoundingBoxToWorld().xMax < 0;
  37. if (disappear) {
  38. this.node.destroy();
  39. }
  40. if (!this.isStop) {
  41. if (this.YellowBG.x >= 0) {
  42. this.YellowBG.x = 0;
  43. } else {
  44. this.YellowBG.x -= this.speed * dt;
  45. //加分
  46. this.addScore = 0.02*GlobalData.game.GameSpeed;
  47. GlobalData.game.GameScore += parseInt(this.addScore) ;
  48. }
  49. }
  50. },
  51. });