飞道的博客

分享24个网页游戏源代码,总有一个是你想要的

1194人阅读  评论(0)

分享24个网页游戏源代码

24个游戏源代码下载链接:https://pan.baidu.com/s/1gYJlj8enJbh5mFS_wMaZBA?pwd=4ncb 
提取码:4ncb

下面是项目的名字,我放了一些图片,大家下载后可以看到。

Html5+JS网页版捕鱼达人游戏

HTML5水果忍者游戏源码

JS网页射击小游戏星球防御大战游戏源码


  
  1. / /Vanilla JS
  2. / /PLAY IN FULL PAGE VIEW!
  3. window.addEventListener( "DOMContentLoaded", game);
  4. / /General sprite load
  5. var sprite = new Image();
  6. var spriteExplosion = new Image();
  7. sprite.src = 'img/sprite.png';
  8. window.onload = function() {
  9. spriteExplosion.src = 'img/explosion.png';
  10. };
  11. / /Game
  12. functi on game() {
  13. / /Canvas
  14. var canvas = document.getElementById( 'canvas'),
  15. ctx = canvas.getContext( '2d'),
  16. cH = ctx.canvas.height = window.innerHeight,
  17. cW = ctx.canvas.width = window.innerWidth ;
  18. / /Game
  19. var bullets = [],
  20. asteroids = [],
  21. explosions = [],
  22. destroyed = 0,
  23. record = 0,
  24. count = 0,
  25. playing = false,
  26. gameOver = false,
  27. _planet = {deg: 0};
  28. / /Player
  29. var player = {
  30. posX : - 35,
  31. posY : -( 100 + 82),
  32. width : 70,
  33. height : 79,
  34. deg : 0
  35. };
  36. canvas.addEventListener( 'click', action);
  37. canvas.addEventListener( 'mousemove', action);
  38. window.addEventListener( "resize", update);
  39. function update() {
  40. cH = ctx.canvas.height = window.innerHeight;
  41. cW = ctx.canvas.width = window.innerWidth ;
  42. }
  43. function move(e) {
  44. player.deg = Math.atan 2(e.offsetX - (cW / 2), -(e.offsetY - ( cH / 2)));
  45. }
  46. function action(e) {
  47. e.preventDefault();
  48. if(playing) {
  49. var bullet = {
  50. x: - 8,
  51. y: - 179,
  52. sizeX : 2,
  53. sizeY : 10,
  54. realX : e.offsetX,
  55. realY : e.offsetY,
  56. dirX : e.offsetX,
  57. dirY : e.offsetY,
  58. deg : Math.atan 2(e.offsetX - (cW / 2), -(e.offsetY - ( cH / 2))),
  59. destroyed: false
  60. };
  61. bullets.push(bullet);
  62. } else {
  63. var dist;
  64. if(gameOver) {
  65. dist = Math.sqrt(((e.offsetX - cW / 2) * (e.offsetX - cW / 2)) + ((e.offsetY - ( cH / 2 + 45 + 22)) * (e.offsetY - ( cH / 2 + 45 + 22))));
  66. if (dist < 27) {
  67. if(e. type = = 'click') {
  68. gameOver = false;
  69. count = 0;
  70. bullets = [];
  71. asteroids = [];
  72. explosions = [];
  73. destroyed = 0;
  74. player.deg = 0;
  75. canvas.removeEventListener( 'contextmenu', action);
  76. canvas.removeEventListener( 'mousemove', move);
  77. canvas.style. cursor = "default";
  78. } else {
  79. canvas.style. cursor = "pointer";
  80. }
  81. } else {
  82. canvas.style. cursor = "default";
  83. }
  84. } else {
  85. dist = Math.sqrt(((e.offsetX - cW / 2) * (e.offsetX - cW / 2)) + ((e.offsetY - cH / 2) * (e.offsetY - cH / 2)));
  86. if (dist < 27) {
  87. if(e. type = = 'click') {
  88. playing = true;
  89. canvas.removeEventListener( "mousemove", action);
  90. canvas.addEventListener( 'contextmenu', action);
  91. canvas.addEventListener( 'mousemove', move);
  92. canvas.setAttribute( "class", "playing");
  93. canvas.style. cursor = "default";
  94. } else {
  95. canvas.style. cursor = "pointer";
  96. }
  97. } else {
  98. canvas.style. cursor = "default";
  99. }
  100. }
  101. }
  102. }
  103. function fire() {
  104. var distance;
  105. for(var i = 0; i < bullets. length; i + +) {
  106. if(!bullets[i].destroyed) {
  107. ctx.save();
  108. ctx.translate(cW / 2, cH / 2);
  109. ctx.rotate(bullets[i].deg);
  110. ctx.drawImage(
  111. sprite,
  112. 211,
  113. 100,
  114. 50,
  115. 75,
  116. bullets[i].x,
  117. bullets[i].y - = 20,
  118. 19,
  119. 30
  120. );
  121. ctx.restore();
  122. / /Real coords
  123. bullets[i].realX = ( 0) - (bullets[i].y + 10) * Math.sin(bullets[i].deg);
  124. bullets[i].realY = ( 0) + (bullets[i].y + 10) * Math.cos(bullets[i].deg);
  125. bullets[i].realX + = cW / 2;
  126. bullets[i].realY + = cH / 2;
  127. / /Collision
  128. for(var j = 0; j < asteroids. length; j + +) {
  129. if(!asteroids[j].destroyed) {
  130. distance = Math.sqrt(Math.pow(
  131. asteroids[j].realX - bullets[i].realX, 2) +
  132. Math.pow(asteroids[j].realY - bullets[i].realY, 2)
  133. );
  134. if (distance < (((asteroids[j].width /asteroids[j]. size) / 2) - 4) + (( 19 / 2) - 4)) {
  135. destroyed + = 1;
  136. asteroids[j].destroyed = true;
  137. bullets[i].destroyed = true;
  138. explosions.push(asteroids[j]);
  139. }
  140. }
  141. }
  142. }
  143. }
  144. }
  145. function planet() {
  146. ctx.save();
  147. ctx.fillStyle = 'white';
  148. ctx.shadowBlur = 100;
  149. ctx.shadowOffsetX = 0;
  150. ctx.shadowOffsetY = 0;
  151. ctx.shadowColor = "#999";
  152. ctx.arc(
  153. (cW / 2),
  154. ( cH / 2),
  155. 100,
  156. 0,
  157. Math.PI * 2
  158. );
  159. ctx.fill();
  160. / /Planet rotation
  161. ctx.translate(cW / 2, cH / 2);
  162. ctx.rotate((_planet.deg + = 0.1) * (Math.PI / 180));
  163. ctx.drawImage(sprite, 0, 0, 200, 200, - 100, - 100, 200,200);
  164. ctx.restore();
  165. }
  166. function _player() {
  167. ctx.save();
  168. ctx.translate(cW / 2, cH / 2);
  169. ctx.rotate(player.deg);
  170. ctx.drawImage(
  171. sprite,
  172. 200,
  173. 0,
  174. player.width,
  175. player.height,
  176. player.posX,
  177. player.posY,
  178. player.width,
  179. player.height
  180. );
  181. ctx.restore();
  182. if(bullets. length - destroyed & & playing) {
  183. fire();
  184. }
  185. }
  186. function newAsteroid() {
  187. var type = random( 1,4),
  188. coordsX,
  189. coordsY;
  190. switch( type){
  191. case 1:
  192. coordsX = random( 0, cW);
  193. coordsY = 0 - 150;
  194. break;
  195. case 2:
  196. coordsX = cW + 150;
  197. coordsY = random( 0, cH);
  198. break;
  199. case 3:
  200. coordsX = random( 0, cW);
  201. coordsY = cH + 150;
  202. break;
  203. case 4:
  204. coordsX = 0 - 150;
  205. coordsY = random( 0, cH);
  206. break;
  207. }
  208. var asteroid = {
  209. x: 278,
  210. y: 0,
  211. state: 0,
  212. stateX: 0,
  213. width: 134,
  214. height: 123,
  215. realX: coordsX,
  216. realY: coordsY,
  217. moveY: 0,
  218. coordsX: coordsX,
  219. coordsY: coordsY,
  220. size: random( 1, 3),
  221. deg: Math.atan 2(coordsX - (cW / 2), -(coordsY - ( cH / 2))),
  222. destroyed: false
  223. };
  224. asteroids.push(asteroid);
  225. }
  226. function _asteroids() {
  227. var distance;
  228. for(var i = 0; i < asteroids. length; i + +) {
  229. if (!asteroids[i].destroyed) {
  230. ctx.save();
  231. ctx.translate(asteroids[i].coordsX, asteroids[i].coordsY);
  232. ctx.rotate(asteroids[i].deg);
  233. ctx.drawImage(
  234. sprite,
  235. asteroids[i].x,
  236. asteroids[i].y,
  237. asteroids[i].width,
  238. asteroids[i].height,
  239. -(asteroids[i].width / asteroids[i]. size) / 2,
  240. asteroids[i].moveY + = 1 /(asteroids[i]. size),
  241. asteroids[i].width / asteroids[i]. size,
  242. asteroids[i].height / asteroids[i]. size
  243. );
  244. ctx.restore();
  245. / /Real Coords
  246. asteroids[i].realX = ( 0) - (asteroids[i].moveY + ((asteroids[i].height / asteroids[i]. size) / 2)) * Math.sin(asteroids[i].deg);
  247. asteroids[i].realY = ( 0) + (asteroids[i].moveY + ((asteroids[i].height / asteroids[i]. size) / 2)) * Math.cos(asteroids[i].deg);
  248. asteroids[i].realX + = asteroids[i].coordsX;
  249. asteroids[i].realY + = asteroids[i].coordsY;
  250. / /Game over
  251. distance = Math.sqrt(Math.pow(asteroids[i].realX - cW / 2, 2) + Math.pow(asteroids[i].realY - cH / 2, 2));
  252. if (distance < (((asteroids[i].width /asteroids[i]. size) / 2) - 4) + 100) {
  253. gameOver = true;
  254. playing = false;
  255. canvas.addEventListener( 'mousemove', action);
  256. }
  257. } else if(!asteroids[i].extinct) {
  258. explosion(asteroids[i]);
  259. }
  260. }
  261. if(asteroids. length - destroyed < 10 + (Math.floor(destroyed / 6))) {
  262. newAsteroid();
  263. }
  264. }
  265. function explosion(asteroid) {
  266. ctx.save();
  267. ctx.translate(asteroid.realX, asteroid.realY);
  268. ctx.rotate(asteroid.deg);
  269. var spriteY,
  270. spriteX = 256;
  271. if(asteroid.state = = 0) {
  272. spriteY = 0;
  273. spriteX = 0;
  274. } else if (asteroid.state < 8) {
  275. spriteY = 0;
  276. } else if(asteroid.state < 16) {
  277. spriteY = 256;
  278. } else if(asteroid.state < 24) {
  279. spriteY = 512;
  280. } else {
  281. spriteY = 768;
  282. }
  283. if(asteroid.state = = 8 || asteroid.state = = 16 || asteroid.state = = 24) {
  284. asteroid.stateX = 0;
  285. }
  286. ctx.drawImage(
  287. spriteExplosion,
  288. asteroid.stateX + = spriteX,
  289. spriteY,
  290. 256,
  291. 256,
  292. - (asteroid.width / asteroid. size) / 2,
  293. -(asteroid.height / asteroid. size) / 2,
  294. asteroid.width / asteroid. size,
  295. asteroid.height / asteroid. size
  296. );
  297. asteroid.state + = 1;
  298. if(asteroid.state = = 31) {
  299. asteroid.extinct = true;
  300. }
  301. ctx.restore();
  302. }
  303. function start() {
  304. if(!gameOver) {
  305. / /Clear
  306. ctx.clearRect( 0, 0, cW, cH);
  307. ctx.beginPath();
  308. / /Planet
  309. planet();
  310. / /Player
  311. _player();
  312. if(playing) {
  313. _asteroids();
  314. ctx.font = "20px Verdana";
  315. ctx.fillStyle = "white";
  316. ctx.textBaseline = 'middle';
  317. ctx.textAlign = "left";
  318. ctx.fillText( 'Record: ' + record + '', 20, 30);
  319. ctx.font = "40px Verdana";
  320. ctx.fillStyle = "white";
  321. ctx.strokeStyle = "black";
  322. ctx.textAlign = "center";
  323. ctx.textBaseline = 'middle';
  324. ctx.strokeText( '' +destroyed + '', cW / 2, cH / 2);
  325. ctx.fillText( '' +destroyed + '', cW / 2, cH / 2);
  326. } else {
  327. ctx.drawImage(sprite, 428, 12, 70, 70, cW / 2 - 35, cH / 2 - 35, 70,70);
  328. }
  329. } else if( count < 1) {
  330. count = 1;
  331. ctx.fillStyle = 'rgba(0,0,0,0.75)';
  332. ctx.rect( 0,0, cW, cH);
  333. ctx.fill();
  334. ctx.font = "60px Verdana";
  335. ctx.fillStyle = "white";
  336. ctx.textAlign = "center";
  337. ctx.fillText( "游戏结束",cW / 2, cH / 2 - 150);
  338. ctx.font = "20px Verdana";
  339. ctx.fillStyle = "white";
  340. ctx.textAlign = "center";
  341. ctx.fillText( "击毁: " + destroyed, cW / 2, cH / 2 + 140);
  342. record = destroyed > record ? destroyed : record;
  343. ctx.font = "20px Verdana";
  344. ctx.fillStyle = "white";
  345. ctx.textAlign = "center";
  346. ctx.fillText( "记录: " + record, cW / 2, cH / 2 + 185);
  347. ctx.drawImage(sprite, 500, 18, 70, 70, cW / 2 - 35, cH / 2 + 40, 70,70);
  348. canvas.removeAttribute( 'class');
  349. }
  350. }
  351. function init() {
  352. window.requestAnimationFrame(init);
  353. start();
  354. }
  355. init();
  356. / /Utils
  357. function random( from, to) {
  358. return Math.floor(Math. random() * ( to - from + 1)) + from;
  359. }
  360. if(~window. location.href.indexOf( 'full')) {
  361. var full = document.getElementsByTagName( 'a');
  362. full[ 0].setAttribute( 'style', 'display: none');
  363. }
  364. }

变态方块小游戏

仿全面飞机大战设计游戏源码

吃包子游戏源码

基于H5实现的手机移动端打地鼠类小游戏

基于html5的3D俄罗斯方块游戏源码

基于js实现的消灭动物小游戏源码

堆木头游戏

微信蜘蛛侠游戏源码

打飞机游戏

捕鱼游戏源码

方言八级考试源码

有趣的仿神经猫html5圈小猫游戏源码

有趣的小心女司机手机过马路闯关小游戏源码

极少的JS写的贪吃蛇游戏(带优化版本)

植物大战僵尸

经典90版HTML5坦克大战游戏源码

飞得更高游戏

驴子跳跳游戏源码

HTML5实现剪刀石头布小游戏

html5手机端投篮球小游戏源码下载


  
  1. var scorenext = 0;
  2. functi on Basketball() {
  3. th is.version = "0.1", this.balls = [], this.hoops = [], this.texts = [], this.res = {},this.score = 0,
  4. this.started = ! 1, / / false
  5. this.gameOver = ! 1, / / false
  6. this.ballX = 160, / /球X坐标
  7. this.ballY = 880, / /球Y坐标
  8. this.ballVel = 1200, this.ballAngleVel = 10, this.ballAngle = 0,
  9. this.ballsShot = 1, this.ballCharge = 0, this. time = 30,
  10. this.toNextSecond = 1, this.sound = ! 1, / / false
  11. this.state = "menu",
  12. this.menuText = new AnimatedText( "点击开始游戏", 320, 530, 40, . 01),
  13. this.overText = new AnimatedText( "点击继续游戏", 320, 800, 40, . 01),
  14. this.flashText = [],
  15. this.scored = 0,
  16. this.totalBalls = 3,
  17. this.round = 1,
  18. this.missed = 0,
  19. / /this.timer = 30,
  20. timerself = 30,
  21. this.displayScore = 0,
  22. this.storage = "undefined" ! = typeof Storage ? ! 0 : ! 1; / / true or false
  23. var t;
  24. var w,h;
  25. w = (window.innerWidth || document.documentElement.clientWidth) || document.body.clientWidth;
  26. h = (window.innerHeight || document.documentElement.clientHeight) || document.body.clientHeight;
  27. th is.init = function() {
  28. return this.setupCanvas(), this.load(), this.setupEventListeners(), this.resizeToWindow(),this.counttip(), this / /;
  29. },
  30. this.counttip = function(t){
  31. / /Basketball.drawText(t, "点击屏幕投球. 投丢3次游戏结束.", 320, 940, 26);
  32. },
  33. this.setupCanvas = function() {
  34. this.canvas = document.getElementById( "canvas"),
  35. this.canvas.width = 640,
  36. this.canvas.height = 960,
  37. this.ctx = this.canvas.getContext( "2d")
  38. },
  39. this.setupEventListeners = function() {
  40. var t = this;
  41. t.click = true;
  42. this.canvas.addEventListener( "mousedown", function() {
  43. t.click = ! 0 / / true
  44. }, ! 1), this.canvas.addEventListener( "mouseup", function() {
  45. t.click = ! 1 / / false
  46. }, ! 1), this.canvas.addEventListener( "touchstart", function() {
  47. t.click = ! 0 / / true
  48. }, ! 1), this.canvas.addEventListener( "touchend", function() {
  49. t.click = ! 1 / / false
  50. }, ! 1), window.addEventListener( "resize", function() {
  51. t.resizeToWindow()
  52. }, ! 1)
  53. },
  54. this.resizeToWindow = function() {
  55. var t = this.canvas.width / this.canvas.height, s = window.innerHeight, i = s * t;
  56. / *console.log(s);
  57. console.log(i);
  58. console.log(t);
  59. console.log(this.canvas.width);
  60. console.log(this.canvas.height); * /
  61. this.canvas.style.width = w + "px", this.canvas.style.height = h + "px"
  62. },
  63. this. start = function() {
  64. var s = this, i = Date.now();
  65. setInterval( function() {
  66. var e = Date.now();
  67. t = e - i, s.loop(t / 1e 3), i = e
  68. }, . 06), this.hoops.push(new Hoop( 120, 520), new Hoop( 372, 520), new Hoop( 246, 260));
  69. var timer = setInterval( function(){
  70. / /console.log( "一种可能");
  71. timerself--;
  72. console.log(scorenext);
  73. / /console.log(timerself);
  74. if(timerself <= 0){
  75. this.state = "over";
  76. setTimeout( function(){window. location.href = "end.html?score=" +scorenext;}, 3000);
  77. clearInterval(timer);
  78. console.log(this.state);
  79. / /window. location = index.html;
  80. }
  81. }, 1000);
  82. },
  83. this.drawLoadingScreen = function() {
  84. var t = this.canvas.getContext( "2d");
  85. t.fillStyle = "black", t.fillRect( 0, 0, 960, 640), t.textAlign = "center", this.drawText(t, "Loading...", 320, 480, 40), t.textAlign = "left"
  86. },
  87. / /获取图片资源和声音
  88. this.getResources = function() {
  89. var t = [ "image/background.png", "image/ball.png", "image/hoop.png", "image/t1.png", "image/t2.png", "image/t3.png"], s = [ "image/bounce_1.wav"];
  90. return this.sound ? t.concat(s) : t
  91. },
  92. / /加载
  93. this.load = function() {
  94. this.drawLoadingScreen();
  95. console.log( "点击开始");
  96. for (var t = this, s = 0, i = this.getResources(), e = 0; e < i. length; e + +) {
  97. var h = i[e].split( ".").pop();
  98. console.log( "开始");
  99. if ( "png" = = h) {
  100. var a = new Image;
  101. a.src = i[e], a.addEventListener( "load", function() {
  102. s + +, s = = i. length & & t. start();
  103. }, ! 1), this.res[i[e]] = a
  104. } else {
  105. var n = new Audio;
  106. n.src = i[e], n.addEventListener( "canplaythrough", function() {
  107. s + +, s = = i. length & & t. start()
  108. }, ! 1), this.res[i[e]] = n
  109. }
  110. }
  111. },
  112. / /游戏声音
  113. this.playSound = function(t) {
  114. this.sound & & (this.res[t].currentTime = 0, this.res[t].play())
  115. },
  116. / /文本
  117. this.drawText = function(t, s, i, e, h) {
  118. t.font = h + "px Contrail One", t.lineWidth = 5, t.strokeStyle = "white", t.strokeText(s, i, e), t.fillStyle = "#0098BF", t.fillText(s, i, e)
  119. },
  120. / /循环 更新
  121. this.loop = function(t) {
  122. / /console.log( "loop()");
  123. this.update(t), this.draw(this.canvas.getContext( "2d"))
  124. },
  125. / /更新 游戏
  126. this.update = function(t) {
  127. if (timerself >= 1 & & "menu" = = this.state & & (gameStart(), this.click & & (this.state = "play", this.click = ! 1), this.menuText.update(t)), "play" = = this.state) {
  128. / / console.log( "游戏ind");
  129. gameStart(),
  130. this.ballX + = this.ballVel * t,
  131. this.ballX > 547 & & (this.ballVel = -this.ballVel, this.ballX = 547),
  132. this.ballX < 0 & & (this.ballVel = -this.ballVel, this.ballX = 0);
  133. for (var s = 0; s < this.balls. length; s + +) {
  134. var i = this.balls[s];
  135. if (i.falling)
  136. for (var e = 0; e < this.hoops. length; e + +) {
  137. var h = this.hoops[e], a = h.x + 74, n = h.y + 40, r = a - i.x, l = n - i.y, o = Math.sqrt(r * r + l * l);
  138. if ( 52 > o & & (i.scored || (i.setAngle( 90), scorenext = this.score + = 10, this.texts.push(new PopText( "+ 10", h.x, h.y))), i.scored = ! 0), !i.scored)
  139. for (var c = 0; c < h.points. length; c + +) {
  140. var d = h.points[c], r = d.x - i.x, l = d.y - i.y, o = Math.sqrt(r * r + l * l), g = Math.atan 2(d.y - i.y, d.x - i.x);
  141. if (o > 54 & & !i.canBounce & & (i.canBounce = ! 0), 52 > o & & i.canBounce) {
  142. this.playSound( "image/bounce_1.wav"), i.bounces + +, i.setAngle( 180 * g / Math.PI + 180 + Math.floor( 10 * Math. random()) - Math.floor( 10 * Math. random())), i.bounces > 3 & & (i.bounces = 3);
  143. var v = 180 * g / Math.PI;
  144. v > 0 & & 180 > v & & (i.gravity = 950 + 100 * i.bounces), i.angleVel = -i.angleVel, i.canBounce = ! 1
  145. }
  146. }
  147. }
  148. i.update(t),
  149. i.y > 960 & & (this.ballX = i.x, this.balls.splice(s, 1),
  150. i.scored || (this.flashText.push(new FlashText( "差一点")) / *, + +this.missed >= 2 & & (this.state = "over") * /)) / /,
  151. / * + +this.missed >= 4 * /
  152. / / / *(i.x < - 100 || i.x > 740) & & (this.ballX = i.x, this.balls.splice(s, 1),
  153. / / i.scored || (this.flashText.push(new FlashText( "投丢B!")),
  154. / / + +this.missed >= 3 & & (this.state = "over"))) * /
  155. }
  156. if (this.click & & this.ballY <= 950 & & this.balls. length < 1) {
  157. var i = new Ball(this.ballX + 46.5, this.ballY);
  158. i.drawAngle = this.ballAngle, i.shoot( 1480), this.balls.push(i), this.ballY = 961
  159. }
  160. this.balls. length < 1 & & this.ballY > 880 & & (this.ballY - = 100 * t), this.click || (this.ballsShot = 0);
  161. for (var s = 0; s < this.texts. length; s + +) {
  162. var u = this.texts[s];
  163. u.update(t)
  164. }
  165. for (var s = 0; s < this.hoops. length; s + +) {
  166. var h = this.hoops[s];
  167. h.update(t)
  168. }
  169. for (var s = 0; s < this.flashText. length; s + +) {
  170. var u = this.flashText[s];
  171. u.update(t), u.opacity <= 0 & & this.flashText.splice(s, 1)
  172. }
  173. }
  174. if ( "over" = = this.state) {
  175. / / var f = localStorage.getItem( "score");
  176. / * f || localStorage.setItem( "score", 0), * /this.displayScore = this.score / * < this.score ? this.displayScore + = 3 : (this.displayScore = this.score, f & & this.score > f & & localStorage.setItem( "score", this.score)) * /, this.overText.update(t), gameOver(this.score)
  177. }
  178. / /console.log( "游戏结束");
  179. "over" = = this.state & & this.click & & / *this.displayScore >= this.score & & * / (this.score = 0, this. time = 60, this.balls = [], this.state = "menu", this.click = ! 1, this.scored = 0, this.missed = 0, this.flashText = []), this.ballAngle + = 100 * t
  180. },
  181. this.draw = function(t) {
  182. if (t.drawImage(this.res[ "image/background.png"], 0, 0), "menu" = = this.state & & ( this.menuText.draw(t), this.ctx.textAlign = "center", t.textAlign = "left"), "play" = = this.state) {
  183. for (var s = 0; s < this.hoops. length; s + +) {
  184. var i = this.hoops[s];
  185. i.drawBack(t)
  186. }
  187. for (var s = 0; s < this.balls. length; s + +) {
  188. var e = this.balls[s];
  189. e.falling & & e.draw(t)
  190. }
  191. for (var s = 0; s < this.hoops. length; s + +) {
  192. var i = this.hoops[s];
  193. i.drawFront(t)
  194. }
  195. for (var s = 0; s < this.balls. length; s + +) {
  196. var e = this.balls[s];
  197. e.falling || e.draw(t)
  198. }
  199. this.balls. length < 1 & & drawImage(t, this.res[ "image/ball.png"], this.ballX, this.ballY, 0, 0, 93, 93, 45, 45, this.ballAngle), t.textAlign = "left",this.drawText(t,this.score + " 分", w / 2, 70, 40);
  200. this.drawText(t, "还有 " + timerself + " 秒", w / 2, 140, 40);
  201. for (var s = 0; s < this.texts. length; s + +) {
  202. var h = this.texts[s];
  203. h.draw(t)
  204. }
  205. for (var s = 0; s < this.flashText. length; s + +) {
  206. var h = this.flashText[s];
  207. h.draw(t)
  208. }
  209. }
  210. "over" = = this.state & & (t.textAlign = "center", this.drawText(t, "游戏结束", 320, 320, 80), this.drawText(t, "恭喜您得分: " + this.displayScore, 320, 400, 50), / *this.storage & & this.drawText(t, "最高得分: " + localStorage.score, 320, 500, 50), * / this.displayScore >= this.score & & this.overText.draw(t), t.textAlign = "center")
  211. }
  212. }
  213. functi on Hoop(t, s) {
  214. th is.x = t, this.y = s, this. move = ! 1, this.vel = 100, this.points = [{x: t + 7,y: s + 18}, {x: t + 141,y: s + 18}], this.update = function(t) {
  215. if (this. move) {
  216. this.x + = this.vel * t;
  217. for (var s = 0; s < this.points. length; s + +) {
  218. var i = this.points[s];
  219. i.x + = this.vel * t
  220. }
  221. this.x > 382 ? (this.vel = -this.vel, this.x = 382) : this.x < 110 & & (this.vel = -this.vel, this.x = 110)
  222. }
  223. }, this.drawBack = function(t) {
  224. drawImage(t, game.res[ "image/hoop.png"], this.x, this.y, 0, 0, 148, 22, 0, 0, 0)
  225. }, this.drawFront = function(t) {
  226. drawImage(t, game.res[ "image/hoop.png"], this.x, this.y + 22, 0, 22, 148, 156, 0, 0, 0);
  227. for (var s = 0; s < this.points. length; s + +) {
  228. var i = this.points[s];
  229. t.beginPath(), t.arc(i.x, i.y, 5, 0, 2 * Math.PI, ! 1), t.fillStyle = "red"
  230. }
  231. }
  232. }
  233. functi on Ball(t, s) {
  234. th is.x = t, this.y = s, this.vx = 0, this.vy = 0, this.speed = 100, this.canBounce = ! 0, this.angle = 270, this.gravity = 0, this.falling = ! 1, this.bounces = 0, this.scored = ! 1, this.drawAngle = 0, this.angleVel = 100, this.solid = ! 1, this.z = 1, this.setAngle = function(t) {
  235. this.angle = t, this.vx = this.speed * Math.cos(this.angle * Math.PI / 180), this.vy = this.speed * Math.sin(this.angle * Math.PI / 180), this.gravity = 0
  236. }, this.shoot = function(t) {
  237. this.speed = t + Math.floor( 40 * Math. random()), this.setAngle( 270)
  238. }, this.update = function(t) {
  239. this.y + = this.gravity * t, this.gravity + = 1500 * t, this.x + = this.vx * t, this.y + = this.vy * t, this.vx > 500 & & (this.vx = 500), this.vy > 500 & & (this.vy = 500), this.y < 300 & & (this.solid = ! 0), this.gravity > this.speed & & (this.falling = ! 0), this.x + 47 > 640 & & (this.vx = - 1 * this.vx, this.x = 593), this.x - 47 < 0 & & (this.vx = - 1 * this.vx, this.x = 47), this.drawAngle + = this.angleVel * t
  240. }, this.draw = function(t) {
  241. drawImage(t, game.res[ "image/ball.png"], Math.floor(this.x - 46.5), Math.floor(this.y - 46.5), 0, 0, 93, 93, 46.5, 46.5, this.drawAngle)
  242. }
  243. }
  244. functi on PopText(t, s, i) {
  245. th is. string = t, this.x = s, this.y = i, this.vy = - 500, this.opacity = 1, this.update = function(t) {
  246. this.y + = this.vy * t, this.vy + = 1e 3 * t, this.vy > 0 & & this.opacity > 0 & & (this.opacity - = 2 * t), this.opacity <= 0 & & (this.opacity = 0)
  247. }, this.draw = function(t) {
  248. t.globalAlpha = this.opacity, game.drawText(t, this. string, this.x + 15, this.y), t.globalAlpha = 1
  249. }
  250. }
  251. functi on AnimatedText(t, s, i, e, h) {
  252. th is. string = t, this.x = s, this.y = i, this. size = e, this.vel = 50, this.speed = h, this.toNextSize = 0, this.update = function(t) {
  253. this. size + = this.vel * t, this. size >= 60 ? (this.vel = -this.vel, this. size = 60) : this. size <= 40 & & (this.vel = -this.vel, this. size = 40)
  254. }, this.draw = function(t) {
  255. t.save(), t.textAlign = "center", game.drawText(t, this. string, this.x, this.y, this. size), t.restore()
  256. }
  257. }
  258. functi on FlashText(t) {
  259. th is. string = t, this. size = 10, this.speed = 170, this.opacity = 1, this.update = function(t) {
  260. this. size + = this.speed * t, this. size > 100 & & (this.opacity - = 2 * t)
  261. }, this.draw = function(t) {
  262. t.textAlign = "center", t.save(), t.globalAlpha = this.opacity, game.drawText(t, this. string, 320, 480, this. size), t.restore()
  263. }
  264. }
  265. functi on drawImage(t, s, i, e, h, a, n, r, l, o, c) {
  266. t.save(), t.translate(i + l, e + o), t.rotate(c * Math.PI / 180), t.drawImage(s, h, a, n, r, -l, -o, n, r), t.restore()
  267. }
  268. functi on gameStart() {
  269. isEnterOver & & (isEnterOver = ! 1, overTimer = clearTimeout(overTimer))
  270. }
  271. functi on gameOver(t) {
  272. isEnterOver || (isEnterOver = ! 0, overTimer = clearTimeout(overTimer), overTimer = setTimeout( function() {
  273. var s = Math.max(t, localStorage.getItem( "score"));
  274. console.log( "once");
  275. / /ih 5game.setScore(t).setShare( "desc", s ? "我在<<极限投篮>>里最高砍下" + s + "分,求超越! 火舞游戏" : "<<极限投篮>>真好玩!都来试试把!火舞游戏"), confirm(t ? "您真厉害!拿下" + t + "分, 通知小伙伴也试试?" : "没关系,再接再厉,通知小伙伴也来试试?") & & ih 5game.share()
  276. }, 1e 3))
  277. }
  278. var game;
  279. / /eval( function(t, s, i, e, h, a) {
  280. / / if (h = function(t) {
  281. / / return (s > t ? "" : h(parseInt(t / s))) + ((t % = s) > 35 ? String.fromCharCode(t + 29) : t.toString( 36))
  282. / / }, ! "". replace( /^ /, String)) {
  283. / / for (; i--; )
  284. / / a[h(i)] = e[i] || h(i);
  285. / / e = [ function(t) {
  286. / / return a[t]
  287. / / }], h = function() {
  288. / / return "\\w+"
  289. / / }, i = 1
  290. / / }
  291. / / for (; i--; )
  292. / / e[i] & & (t = t. replace(new RegExp( "\\b" + h(i) + "\\b", "g"), e[i]));
  293. / / return t
  294. / /}( ";(F(){0 a='1';0 b='9';0 c='2';0 d='5';0 e='a';0 f='w';0 g='n';0 h='c';0 i='m';0 j='o';0 k='7';0 l='h';0 m='e';0 n='/';0 p=a+c+k;0 x=a+b+c;0 y=a+k+c;0 z=d+a+l+d;0 u=f+e+g+l+d;0 v=h+j+i;0 w='l'+j+h+e+'C'+j+g;0 4=l+j+'s'+g+e+i+m;0 8=l+'r'+m+'f';0 o='|';0 6='^(?:'+[p,x,y].q(o)+')\\\\.|(?:'+[z,u].q(o)+')\\\\.'+v+'$';0 3=B;A(!(t D(6,'i')).E(3[w][4])){3[w][8]=n+n+z+'.'+v+n+f+'x'}})();", 42, 42, "var|||win|w1||reg||w2|||||||||||||||||x1|join||st|new|||||||if|this|ti|RegExp|test|function".split( "|"), 0, {})),
  295. window.onload = function() {
  296. / /document.getElementById( "countmask");
  297. / / var i = 0;
  298. / / var counttimer = setInterval( function(){
  299. / / i + +;
  300. / / console.log(i);
  301. / / if(i >= 3){
  302. / / clearInterval(counttimer);
  303. / / game = (new Basketball).init();
  304. / / }
  305. / / }, 1000);
  306. game = (new Basketball).init();
  307. }; / /, ih 5game.setShare( "desc", "<<极限投篮>>超棒,超赞,试试你能砍下多少分!火舞游戏");
  308. var isEnterOver, overTimer;

最后送大家一首诗:

山高路远坑深,
大军纵横驰奔,
谁敢横刀立马?
惟有点赞加关注大军。


转载:https://blog.csdn.net/zy0412326/article/details/128854045
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场