bar.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. var bar = {
  2. num: 1,
  3. max: 100,
  4. tag: true,
  5. timeout: null,
  6. randomMin: 40,
  7. randomMax: 60,
  8. first: true,
  9. score: 0,
  10. isGameStart: false,
  11. isShot: true,
  12. radIndex: 0,
  13. rad: [120, 110, 100, 90, 80, 70, 60, 50, 40, 20],
  14. $el: {
  15. "score": $("#score"),
  16. "arrow":$(".arrow"),
  17. "barLifes":$(".barLifes"),
  18. "progress":$(".progress"),
  19. "apple":$("#apple"),
  20. "overInfo":$("#gameover,.info"),
  21. "failAll":$(".fail-one,.fail-two,.fail-three"),
  22. "overAll":$(".info,.fail-one,.fail-two,.fail-three")
  23. },
  24. init: function() {
  25. var me = this;
  26. this.initSet = true;
  27. this.tag = true;
  28. me.initBar();
  29. bar.isShot = true;
  30. return this;
  31. },
  32. initBar: function() {
  33. bar.$el.arrow.css({
  34. bottom: "80px"
  35. });
  36. clearTimeout(this.timeout);
  37. var parent = this;
  38. this.heights = bar.rad[bar.radIndex]; //高度
  39. this.beginBarTop = Math.floor(Math.random() * 100 + 160); //开始位置
  40. bar.$el.barLifes.css({
  41. "height": this.heights + "px",
  42. "bottom": this.beginBarTop + "px"
  43. });
  44. parent.num = 1;
  45. bar.$el.progress.css({
  46. height: 0 + "px"
  47. });
  48. this.tag = true;
  49. },
  50. run: function() {
  51. var parent = this;
  52. this.timeout = setTimeout(function() {
  53. parent.run();
  54. }, 1000 / 30);
  55. if (this.tag) {
  56. //this.num *= 1.4; //增长速度
  57. this.num += 30;
  58. if (this.num >= 476) {
  59. this.num = 476;
  60. this.tag = false;
  61. }
  62. } else {
  63. // this.num /= 1.4; //增长速度
  64. this.num -= 30;
  65. if (this.num <= 1) {
  66. this.num = 1;
  67. this.tag = true;
  68. }
  69. }
  70. bar.$el.progress.css({
  71. height: parent.num + "px"
  72. });
  73. },
  74. destore: function() {
  75. var parent = this;
  76. clearTimeout(parent.timeout);
  77. if (this.num >= this.beginBarTop && this.num <= (this.heights + this.beginBarTop)) {
  78. bar.isShot = false;
  79. bar.score++;
  80. setTimeout(function(){
  81. bar.$el.arrow.animate({
  82. bottom: "650px"
  83. },50,function() {
  84. bar.$el.apple.removeClass("apple").addClass("apples");
  85. bar.$el.score.addClass("animated fadeOut").html("+1");
  86. });
  87. }, 200);
  88. setTimeout(function() {
  89. bar.$el.apple.removeClass("apples").addClass("apple");
  90. bar.$el.score.removeClass("animated fadeOut").html("");
  91. bar.$el.arrow.animate({
  92. bottom: "-100px"
  93. }, 1);
  94. bar.$el.arrow.animate({
  95. bottom: "80px"
  96. }, 10);
  97. bar.radIndex++;
  98. if (bar.radIndex >= 9) {
  99. bar.radIndex = 9;
  100. }
  101. parent.init();
  102. }, 1000);
  103. } else {
  104. bar.radIndex = 0;
  105. var num = parseInt(this.num / 120),
  106. number;
  107. switch (num) {
  108. case num <= 1:
  109. number = "one";
  110. bar.$el.arrow.animate({
  111. bottom: "300px"
  112. }, 100);
  113. break;
  114. case 2:
  115. number = "two";
  116. bar.$el.arrow.animate({
  117. bottom: "400px"
  118. }, 100);
  119. break;
  120. case 3:
  121. number = "three";
  122. bar.$el.arrow.animate({
  123. bottom: "400px"
  124. }, 100);
  125. break;
  126. default:
  127. number = "three";
  128. bar.$el.arrow.animate({
  129. bottom: "400px"
  130. }, 100);
  131. break;
  132. }
  133. if (bar.score >0) {
  134. setTimeout(function() {
  135. bar.$el.overInfo.removeClass("hide").show();
  136. bar.$el.failAll.addClass("hide");
  137. }, 1000);
  138. } else {
  139. setTimeout(function() {
  140. bar.$el.overAll.addClass("hide");
  141. $("#gameover,.fail-" + number).removeClass("hide").show();
  142. }, 1000);
  143. return;
  144. }
  145. setTimeout(function() {
  146. dp_submitScore(bar.score);
  147. },1000);
  148. }
  149. }
  150. }