index.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. <!DOCTYPE html>
  2. <html>
  3. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  4. <head>
  5. <meta charset="UTF-8" />
  6. <title>植物大战僵尸</title>
  7. <script src="js/jquery.js"></script>
  8. <script type="text/javascript" src="js/phaser.min.js"></script>
  9. <style type="text/css">
  10. body {
  11. background-image: url(assets/background.png);
  12. background-size: cover;
  13. background-repeat: no-repeat;
  14. color:white;
  15. padding: 0;
  16. margin: 0;
  17. font-family: 微软雅黑,Calibri, Candara, Segoe, "Segoe UI", Optima, Arial, sans-serif;
  18. }
  19. canvas {
  20. border: 0;
  21. margin: auto;
  22. }
  23. a {
  24. color: white;
  25. }
  26. body {
  27. font-size: 12px;
  28. }
  29. #game {
  30. position: absolute;
  31. top:0;
  32. left: 0;
  33. width: 100%;
  34. height: 100%;
  35. }
  36. .info {
  37. position: absolute;
  38. padding: 10px;
  39. margin: 5px;
  40. background: #0a0a11;
  41. opacity: 0.5;
  42. z-index: 999;
  43. border-radius: 15px;
  44. overflow-y:auto;
  45. }
  46. #loading {
  47. position: fixed;
  48. width: 90%;
  49. border-radius: 15px;
  50. z-index: 999;
  51. text-align: center;
  52. vertical-align: middle;
  53. line-height: 50px;
  54. }
  55. #test1{
  56. width: 250px;
  57. height: 250px;
  58. background: #fff;
  59. color: #000;
  60. position: relative;
  61. }
  62. #test1 p{
  63. height: 25%;
  64. text-align: center;
  65. margin: 0px;
  66. }
  67. #test1 .cdkey a{
  68. color: #000;
  69. text-decoration: none;
  70. color: blue;
  71. }
  72. #test1 .dia-close{
  73. position: absolute;
  74. top: 0px;
  75. display: block;
  76. text-align: center;
  77. text-decoration: none;
  78. color: #000;
  79. background: #ccc;
  80. }
  81. </style>
  82. </head>
  83. <body>
  84. <div id="loading" style="display:none">
  85. <img width ="100%" src="assets/shuoming.png">
  86. </div>
  87. <div id="game"></div>
  88. <script type="text/javascript">
  89. var lastTime = 0;
  90. $('body').css('background-size', document.documentElement.clientWidth + 'px' + ' ' + document.documentElement.clientHeight + 'px');
  91. //radio为宽高比率
  92. var ratio = 1.59;
  93. //游戏高为屏幕高-20px
  94. var height = document.documentElement.clientHeight;
  95. // 游戏宽为屏幕高的1.6倍
  96. var width = height / ratio;
  97. //scale为分割高的最小单位
  98. var scale = height / 720;
  99. //导入游戏画布
  100. var game = new Phaser.Game(document.documentElement.clientWidth, height, Phaser.CANVAS, 'game', { preload: preload, create: create, update: update });
  101. //预导入内容
  102. function preload() {
  103. //添加背景
  104. game.load.image('background', 'assets/gamebackground.jpg');
  105. //引入坚果
  106. game.load.image('ball','assets/bowlingball.png');
  107. //左边按键
  108. game.load.spritesheet('leftbtn', 'assets/btn-left.png',192,720);
  109. //右边按键
  110. game.load.spritesheet('rightbtn', 'assets/btn-right.png',192,720);
  111. // //添加基础僵尸
  112. game.load.spritesheet('zombie-normal', 'assets/zombie-normal.png', 126, 133);
  113. //添加太阳僵尸
  114. game.load.spritesheet('zombie-sun', 'assets/zombie-sun.png', 130, 150);
  115. //添加旗子僵尸
  116. game.load.spritesheet('zombie-flag', 'assets/zombie-flag.png', 155, 150);
  117. //添加大僵尸
  118. game.load.spritesheet('zombie-snow', 'assets/zombie-snow.png', 230,180);
  119. //添加水沟
  120. game.load.image('ditchleft', 'assets/ditchleft.jpg');
  121. game.load.image('ditchright', 'assets/ditchright.jpg');
  122. //添加按钮
  123. game.load.image('button', 'assets/btnreplay.png');
  124. //添加按钮
  125. game.load.image('btnmore', 'assets/btnmore.png');
  126. //添加按钮
  127. game.load.image('btnshare', 'assets/btnshare.png');
  128. //说明按钮
  129. game.load.image('instruction','assets/shuomingchakan.png');
  130. //添加图片
  131. game.load.image('backgroundblack', 'assets/bb.jpg');
  132. game.load.image('gameover', 'assets/over1.png');
  133. }
  134. //背景
  135. var bg1;
  136. var bg2;
  137. //背景滚动速率
  138. var scrollSpeed = 5 ;
  139. //基础速度
  140. const baseVelocity = 10 * scale;
  141. //加入基础僵尸
  142. var zombies;
  143. var zombie = null;
  144. //引入基础僵尸函数
  145. var timer1;
  146. var timer2;
  147. var timer3;
  148. var timer4;
  149. //分数
  150. var score = 0;
  151. var scoreText;
  152. var middletext;
  153. var addscoreText = 0;
  154. //连击数
  155. var comboText;
  156. var maxcomboText;
  157. var combo = 0;
  158. var maxcombo = 0;
  159. var combaddscoreText = 0;
  160. //僵尸身体碰撞基数
  161. var zombieBodySize = 0.5;
  162. var button2 = null;
  163. var encouragetext = null;
  164. var encouragetext2 = null;
  165. var keyvalue = null;
  166. //创建游戏背景
  167. function createBackground() {
  168. bg1 = game.add.sprite(0, 0, 'background');
  169. bg2 = game.add.sprite(0, -bg1.height * scale, 'background');
  170. bg1.width = document.documentElement.clientWidth;
  171. bg2.width = document.documentElement.clientWidth;
  172. bg1.scale.y = scale;
  173. // bg2.scale.x = scale;
  174. bg2.scale.y = scale;
  175. }
  176. //创建保龄球
  177. function createBall(){
  178. ball = game.add.sprite(game.world.centerX,game.world.height-200*scale, 'ball');
  179. ball.scale.setTo(0.1*scale,0.1*scale);
  180. ball.anchor.setTo(0.5, 0.5);
  181. game.physics.arcade.enable(ball);
  182. }
  183. //添加基础僵尸
  184. function addZombie(){
  185. var zombie = zombies.create(30*scale+(game.world.width-156*scale)*Math.random(),-133*scale, 'zombie-normal');
  186. zombie.scale.setTo(scale,scale);
  187. zombie.animations.add('alive', [0,1,2,3,2,1],5, true);
  188. zombie.animations.add('dead', [7,8,9,10,11,12,13],15, true);
  189. zombie.animations.play('alive');
  190. zombie.outOfBoundsKill = true;
  191. zombie.body.setSize(zombie.body.width*zombieBodySize,zombie.body.height*zombieBodySize,38*scale,0);
  192. zombie.body.velocity.y = 300*scale;
  193. }
  194. //添加太阳僵尸
  195. function addSunZombie(){
  196. var sunZombie = sunZombies.create(30*scale+(game.world.width-160*scale)*Math.random(),-150*scale, 'zombie-sun');
  197. sunZombie.scale.setTo(scale,scale);
  198. sunZombie.animations.add('alive', [0,1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1],5, true);
  199. sunZombie.animations.add('dead', [10,11,12,13,14,15,16,17],15, true);
  200. sunZombie.animations.play('alive');
  201. sunZombie.outOfBoundsKill = true;
  202. sunZombie.body.setSize(sunZombie.body.width*zombieBodySize,sunZombie.body.height*zombieBodySize,39*scale,0);
  203. sunZombie.body.velocity.y = 300*scale;
  204. }
  205. //添加旗子僵尸
  206. function addFlagZombie(){
  207. var flagZombie = flagZombies.create(30*scale+(game.world.width-185*scale)*Math.random(),-150*scale, 'zombie-flag');
  208. flagZombie.scale.setTo(scale,scale);
  209. flagZombie.animations.add('alive', [0,1,2,3,4,3,2,1],5, true);
  210. flagZombie.animations.add('dead', [5,6,7,8,9,10,11,12,13],15, true);
  211. flagZombie.animations.play('alive');
  212. flagZombie.outOfBoundsKill = true;
  213. flagZombie.body.setSize(flagZombie.body.width*zombieBodySize,flagZombie.body.height*zombieBodySize,55.5*scale,0);
  214. flagZombie.body.velocity.y = 300*scale;
  215. }
  216. //添加大僵尸
  217. function addBigZombie(){
  218. var bigzombie = bigZombies.create(5*scale+(game.world.width-230*scale)*Math.random(),-180*scale, 'zombie-snow');
  219. bigzombie.scale.setTo(scale,scale);
  220. bigzombie.animations.add('alive', [0,1,2,3,4,5,4,3,2,1],5, true);
  221. bigzombie.animations.add('dead', [6,7,8,9,10,11,12],15, true);
  222. bigzombie.animations.play('alive');
  223. bigzombie.outOfBoundsKill = true;
  224. bigzombie.body.setSize(bigzombie.body.width*zombieBodySize, bigzombie.body.height*zombieBodySize,0);
  225. bigzombie.body.velocity.y = 300*scale;
  226. }
  227. function create() {
  228. game.physics.startSystem(Phaser.Physics.ARCADE);
  229. //引入背景
  230. createBackground();
  231. //加入水沟
  232. ditchleft = game.add.sprite(0, 0, 'ditchleft');
  233. ditchleft.scale.setTo(scale, scale);
  234. game.physics.arcade.enable(ditchleft);
  235. ditchright = game.add.sprite(game.world.width, 0, 'ditchright');
  236. ditchright.scale.setTo(scale, scale);
  237. ditchright.anchor.setTo(1,0);
  238. game.physics.arcade.enable(ditchright);
  239. //加入僵尸
  240. zombies = game.add.group();
  241. zombies.enableBody = true;
  242. timer1 = game.time.events.loop(400+600*Math.random(), addZombie, this);
  243. //加入太阳僵尸
  244. sunZombies = game.add.group();
  245. sunZombies.enableBody = true;
  246. timer3 = game.time.events.loop(2000+3000*Math.random(), addSunZombie, this);
  247. //加入旗子僵尸
  248. flagZombies = game.add.group();
  249. flagZombies.enableBody = true;
  250. timer4 = game.time.events.loop(2000+3000*Math.random(), addFlagZombie, this);
  251. //加入大僵尸
  252. bigZombies = game.add.group();
  253. bigZombies.enableBody = true;
  254. timer2 = game.time.events.loop(4000+2000*Math.random(), addBigZombie, this);
  255. //添加分数
  256. scoreText = game.add.text(0, game.world.centerY-285*scale, 'score: 0');
  257. addscoreText = game.add.text(0,game.world.centerY-220*scale,'加分:0');
  258. scoreText.setStyle({stroke:'#1d492f',fill:'white', strokeThickness:10,font:'bold ' + width/10 + 'px' + ' 微软雅黑'});
  259. addscoreText.setStyle({stroke:'#1d492f',fill:'white', strokeThickness:10,font:'bold ' + width/10 + 'px' + ' 微软雅黑'});
  260. addscoreText.visible = false;
  261. //添加连击数
  262. comboText = game.add.text(0,game.world.centerY-270*scale,'Combo:0');
  263. comboText.setStyle({stroke:'#ff6600',fill:'#ffea89', strokeThickness:10,font:'bold ' + width/10 + 'px' + ' 微软雅黑'});
  264. comboText.anchor.setTo(0,1);
  265. combaddscoreText = game.add.text(0,game.world.centerY-150*scale,'连击奖励:0' )
  266. combaddscoreText.setStyle({stroke:'#5d1f1f',fill:'#ff6600', strokeThickness:10,font:'bold ' + width/10 + 'px' + ' 微软雅黑'});
  267. combaddscoreText.visible = false;
  268. //引入保龄球
  269. createBall();
  270. //以下是引入关联
  271. //引入向左走按钮
  272. buttonleft = game.add.button(0,game.world.height-20*scale, 'leftbtn', actionMoveleft, this, 0, 0, 1,0);
  273. buttonleft.anchor.setTo(0, 1);
  274. buttonleft.scale.setTo(scale, scale);
  275. //引入向右走按钮
  276. buttonright = game.add.button(game.world.width,game.world.height-20*scale, 'rightbtn', actionMoveright, this, 0, 0, 1,0);
  277. buttonright.anchor.setTo(1, 1);
  278. buttonright.scale.setTo(scale, scale);
  279. //添加说明按钮
  280. buttoninstruction = game.add.button(game.world.width,0, 'instruction', actionInstruction, this, 0, 0, 0);
  281. buttoninstruction.anchor.setTo(1,0);
  282. buttoninstruction.scale.setTo(1.1*scale, 1.1*scale);
  283. }
  284. //背景动态函数
  285. function updateBackground() {
  286. bg1.y = bg1.y + scrollSpeed * scale;
  287. bg2.y = bg2.y + scrollSpeed * scale;
  288. if (bg1.y >= height) {
  289. bg1.y = bg2.y - bg1.height;
  290. }
  291. if (bg2.y >= height) {
  292. bg2.y = bg1.y - bg2.height;
  293. }
  294. }
  295. var moveSpeed = 0;
  296. var nowtime = 0;
  297. function update() {
  298. //使背景变成动态
  299. updateBackground();
  300. //使保龄球转动
  301. ball.angle = ball.angle+4;
  302. //球碰到僵尸后杀死僵尸
  303. game.physics.arcade.overlap(ball, zombies, killZombie, null, this);
  304. game.physics.arcade.overlap(ball, bigZombies, killbigZombie, null, this);
  305. game.physics.arcade.overlap(ball, sunZombies, killsunZombie, null, this);
  306. game.physics.arcade.overlap(ball, flagZombies, killflagZombie, null, this);
  307. //球碰到左右边缘,游戏结束
  308. game.physics.arcade.overlap(ball, ditchleft, leftkillball, null, this);
  309. game.physics.arcade.overlap(ball, ditchright, rightkillball, null, this);
  310. lastTime = Date.now();
  311. nowtime++;
  312. if (nowtime > 10)
  313. {
  314. moveSpeed++;
  315. nowtime = 0;
  316. };
  317. }
  318. //杀死僵尸
  319. function killZombie(ball,zombie){
  320. zombie.animations.play('dead',null,false,true);
  321. if(ball.x<=zombie.x+zombie.body.width/2){
  322. ball.body.velocity.x-=(zombie.x+zombie.body.width/2-ball.x)*scale/90;
  323. zombie.angle = zombie.angle-0.5;
  324. if(zombie.angle==-2){
  325. beadcombo();
  326. score += 200;
  327. scoreText.text = 'score: ' + score;
  328. addscoreText.visible = true;
  329. addscoreText.text = '加分:+' + 200;
  330. }
  331. }else{
  332. ball.body.velocity.x+=(ball.x-zombie.x-zombie.body.width/2)*scale/90;
  333. zombie.angle = zombie.angle+0.5;
  334. if(zombie.angle==2){
  335. beadcombo();
  336. score += 200;
  337. scoreText.text = 'score: ' + score;
  338. addscoreText.visible = true;
  339. addscoreText.text = '加分:+' + 200;
  340. }
  341. }
  342. }
  343. //杀死太阳僵尸
  344. function killsunZombie(ball,sunZombie){
  345. sunZombie.animations.play('dead',null,false,true);
  346. sunZombie.angle = sunZombie.angle+0.5;
  347. if(sunZombie.angle==2){
  348. beadcombo();
  349. score += 300;
  350. scoreText.text = 'score: ' + score;
  351. addscoreText.visible = true;
  352. addscoreText.text = '加分:+' + 300;
  353. //zombie.exists = false;
  354. }
  355. }
  356. //杀死旗子僵尸
  357. function killflagZombie(ball,flagZombie){
  358. flagZombie.animations.play('dead',null,false,true);
  359. flagZombie.angle = flagZombie.angle+0.5;
  360. if(flagZombie.angle==2){
  361. beadcombo();
  362. score += 300;
  363. scoreText.text = 'score: ' + score;
  364. addscoreText.visible = true;
  365. addscoreText.text = '加分:+' + 300;
  366. //zombie.exists = false;
  367. }
  368. }
  369. //杀死大僵尸
  370. function killbigZombie(ball,bigZombie){
  371. bigZombie.animations.play('dead',null,false,true);
  372. if(ball.x<=bigZombie.x+bigZombie.body.width/2){
  373. ball.body.velocity.x-=(bigZombie.x+bigZombie.body.width/2-ball.x)*scale/30;
  374. bigZombie.angle = bigZombie.angle-0.5;
  375. if(bigZombie.angle==-2){
  376. beadcombo();
  377. score += 400;
  378. scoreText.text = 'score: ' + score;
  379. addscoreText.visible = true;
  380. addscoreText.text = '加分:+' + 400;
  381. }
  382. }else{
  383. ball.body.velocity.x+=(ball.x-bigZombie.x-bigZombie.body.width/2)*scale/30;
  384. bigZombie.angle = bigZombie.angle+0.5;
  385. if(bigZombie.angle==2){
  386. beadcombo();
  387. score += 400;
  388. scoreText.text = 'score: ' + score;
  389. addscoreText.visible = true;
  390. addscoreText.text = '加分:+' + 400;
  391. }
  392. }
  393. }
  394. var combotime
  395. function beadcombo(){
  396. if(combo==0){
  397. combotime = Date.now();
  398. combo += 1;
  399. comboText.text = 'Combo:' + combo;
  400. }else if(Date.now()-combotime<=800){
  401. combo += 1;
  402. comboText.text = 'Combo:' + combo;
  403. if(combo>5){
  404. score += 5*combo;
  405. scoreText.text = 'score: ' + score;
  406. combaddscoreText.text='连击奖励:+'+ 50*combo;
  407. combaddscoreText.visible = true;
  408. }
  409. combotime = Date.now();
  410. }else{
  411. if(maxcombo<combo){
  412. maxcombo = combo;
  413. }
  414. combo = 1;
  415. comboText.text = 'Combo:' + combo;
  416. combotime = Date.now();
  417. combaddscoreText.visible =false;
  418. }
  419. }
  420. function leftkillball(ball,ditchleft){
  421. gameover();
  422. }
  423. function rightkillball(ball,ditchright){
  424. gameover();
  425. }
  426. //游戏结束
  427. function gameover(){
  428. ball.kill();
  429. if(maxcombo<combo){
  430. maxcombo = combo;
  431. }
  432. backgroundblack = game.add.button(0,0,"backgroundblack");
  433. backgroundblack.alpha=0.7;
  434. backgroundblack.scale.setTo(10*scale,20*scale);
  435. backgroundblack.width = document.documentElement.clientWidth;
  436. //Score
  437. finalscore = game.add.text(width/2 - width/3,game.world.centerY-280*scale, scoreText.text);
  438. finalscore.anchor.setTo(0, 0.5);
  439. finalscore.setStyle({stroke:'#111',fill:'white', strokeThickness:10,font:'bold ' + width/14 + 'px' + ' 微软雅黑'});
  440. //最大连击数
  441. maxcomboText = game.add.text(width/2 - width/3,game.world.centerY-235*scale, '最大连击数:'+maxcombo);
  442. maxcomboText.setStyle({stroke:'#111',fill:'white', strokeThickness:10, font:'bold ' + width/14 + 'px' + ' 微软雅黑'});
  443. maxcomboText.anchor.setTo(0, 0.5);
  444. encouragetext = game.add.text(width/2 - width/3, game.world.centerY-190*scale, '恭喜你成功碾压僵尸!');
  445. encouragetext.anchor.setTo(0, 0.5);
  446. encouragetext.setStyle({stroke:'#111',fill:'white', strokeThickness:10,font:'bold ' + width/14 + 'px' + ' 微软雅黑'});
  447. copy = game.add.button(game.world.centerX,game.world.centerY-10*scale, 'button', restar, this, 2, 1, 0);
  448. copy.scale.setTo(0.5*scale,0.6*scale);
  449. copy.anchor.setTo(0.5,0.5);
  450. button3602 = game.add.button(game.world.centerX-width/4,game.world.centerY+160*scale, 'btnshare', dp_share, this, 2, 1, 0);
  451. button3602.scale.setTo(0.5*scale,0.6*scale);
  452. button3602.anchor.setTo(0.5,0.5);
  453. button = game.add.button(game.world.centerX+width/4,game.world.centerY+160*scale, 'btnmore', clickMore, this, 2, 1, 0);
  454. button.scale.setTo(0.5*scale,0.6*scale);
  455. button.anchor.setTo(0.5,0.5);
  456. dp_submitScore(score);
  457. game.time.events.pause();
  458. game.time.events.remove();
  459. }
  460. //游戏重新开始
  461. function restar(){
  462. score = 0;
  463. combo = 0;
  464. maxcombo = 0;
  465. addscoreText.text = '加分:+' + 0;
  466. scoreText.text = 'score: ' + score;
  467. comboText.text = 'Combo:' + 0;
  468. backgroundblack.kill();
  469. if (typeof maxcomboText != 'undefined') {
  470. maxcomboText.visible = false;
  471. };
  472. if (typeof finalscore != 'undefined') {
  473. finalscore.visible = false;
  474. };
  475. if (typeof middletext != 'undefined') {
  476. middletext.visible = false;
  477. };
  478. if (typeof addscoreText != 'undefined') {
  479. addscoreText.visible = false;
  480. };
  481. if (typeof combaddscoreText != 'undefined') {
  482. combaddscoreText.visible = false;
  483. };
  484. if (typeof encouragetextbtm1 != 'undefined') {
  485. encouragetextbtm1.visible = false;
  486. };
  487. if (typeof encouragetextbtm2 != 'undefined') {
  488. encouragetextbtm2.visible = false;
  489. };
  490. if (encouragetext!=null) {
  491. encouragetext.visible = false;
  492. }
  493. if (encouragetext2!=null) {
  494. encouragetext2.visible = false;
  495. }
  496. if (typeof combaddscoreText != 'undefined') {
  497. combaddscoreText.visible = false;
  498. };
  499. if (typeof button != 'undefined') {
  500. button.kill();
  501. }
  502. if (typeof button360 != 'undefined') {
  503. button360.kill();
  504. }
  505. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  506. if (typeof button3602 != 'undefined') {
  507. button3602.kill();
  508. }
  509. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  510. if (button2!=null) {
  511. button2.kill();
  512. }
  513. if (typeof key != 'undefined') {
  514. key.visible = false;
  515. };
  516. if (typeof copy != 'undefined') {
  517. copy.visible = false;
  518. };
  519. if (keyvalue != null) {
  520. keyvalue.visible = false;
  521. };
  522. zombies.destroy(true,true);
  523. sunZombies.destroy(true,true);
  524. flagZombies.destroy(true,true);
  525. bigZombies.destroy(true,true);
  526. game.time.events.resume();
  527. timer1;
  528. timer2;
  529. timer3;
  530. timer4;
  531. ball.reset(game.world.centerX,game.world.height-200*scale);
  532. ball.revive();
  533. moveSpeed = 0;
  534. nowtime = 0;
  535. }
  536. //游戏重新开始
  537. function restar1(){
  538. buttonshare.kill();
  539. backgroundblack2.kill();
  540. }
  541. var leftSpeed = 4;
  542. var rightSpeed = 4;
  543. //以下是action函数
  544. //向左移动
  545. function actionMoveleft() {
  546. if(leftSpeed < 14) leftSpeed++;
  547. if(rightSpeed > 0) rightSpeed --;
  548. var deltaVel = baseVelocity * leftSpeed;
  549. ball.body.velocity.x-=deltaVel + moveSpeed;
  550. }
  551. //向右移动
  552. function actionMoveright() {
  553. if(rightSpeed < 14) rightSpeed++;
  554. if(leftSpeed > 0) leftSpeed--;
  555. var deltaVel = baseVelocity * rightSpeed;
  556. ball.body.velocity.x+=deltaVel + moveSpeed;
  557. }
  558. function actionInstruction(){
  559. $('#loading').css({
  560. 'width' : document.documentElement.clientWidth + 'px',
  561. 'height' : height + 'px',
  562. 'left' : (document.documentElement.clientWidth - document.documentElement.clientWidth) / 2 + 'px',
  563. });
  564. $('#loading img').css('height', height + 'px');
  565. $("#loading").toggle();
  566. window.setTimeout(function(){
  567. $('#loading').css('font-size', '100px');
  568. },600);
  569. }
  570. $("#loading").click(function(){
  571. if ($('#loading').css('font-size') != '100px') {
  572. return;
  573. };
  574. $("#loading").toggle();
  575. $('#loading').css('font-size', '0px');
  576. });
  577. function deleteScore(str)
  578. {
  579. var start = str.indexOf(':');
  580. var end = str.length;
  581. str = str.substr(start+1, end);
  582. return str;
  583. }
  584. //弹窗 + 设置cdkey的值
  585. function setCDKey(val)
  586. {
  587. $('#cdkey').html(val);
  588. }
  589. function TGDialogS(e){
  590. var w = document.documentElement.clientWidth;
  591. var h = document.documentElement.clientHeight;
  592. //设置test1的宽高
  593. $('#test1').css({
  594. 'width' : w / 1.1 + 'px',
  595. 'height' : h / 3 + 'px'
  596. });
  597. //设置p的字体大小
  598. $('#test1 p').eq(0).css('font-size' , h*0.07/2 + 'px').css('margin-top' , deletePX( $('#test1').css('height') ) / 3 );
  599. $('#test1 p').eq(1).css('font-size' , h*0.05/2 + 'px');
  600. //设置关闭按钮
  601. $('#test1 .dia-close').css({
  602. 'width' : h / 10 + 'px',
  603. 'height' : h / 15 + 'px',
  604. 'left' : deletePX( $('#test1').css('width') ) - h / 10 + 'px',
  605. });
  606. var closeH = deletePX ( $('#test1 .dia-close').css('height') );
  607. $('#test1 .dia-close').css('font-size', closeH/2 + 'px').css('line-height', closeH + 'px');
  608. need("biz.dialog-min",function(Dialog){
  609. Dialog.show({
  610. id:e,
  611. bgcolor:'#000', //弹出“遮罩”的颜色,格式为"#FF6600",可修改,默认为"#fff"
  612. opacity:50 //弹出“遮罩”的透明度,格式为{10-100},可选
  613. });
  614. });
  615. }
  616. function closeDialog(){
  617. need("biz.dialog-min",function(Dialog){
  618. Dialog.hide();
  619. });
  620. }
  621. function deletePX(str)
  622. {
  623. if (typeof str == 'undefined') return ;
  624. str = str.substr(0, str.length-2);
  625. return parseInt(str);
  626. }
  627. </script>
  628. <script language=javascript>
  629. var mebtnopenurl = 'http://game.ikongzhong.cn/index.html';
  630. var thegameurl ="http://game.ikongzhong.cn/games/zwdzjs/";
  631. var guanzhuurl ="http://mp.weixin.qq.com/s?__biz=MzI4MjA2MjE0MQ==&mid=246005295&idx=1&sn=490f8141976d607ba079d48f52a3fcd7#rd";
  632. var is9gUser=false;
  633. window.shareData = {
  634. "imgUrl": "http://game.ikongzhong.cn/games/zwdzjs/icon.png",
  635. "timeLineLink": thegameurl,
  636. "tTitle": "植物大战僵尸",
  637. "tContent": "植物大战僵尸"
  638. };
  639. function goHome(){
  640. window.location=mebtnopenurl;
  641. }
  642. function clickMore(){
  643. if((window.location+"").indexOf("zf",1)>0){
  644. window.location =mebtnopenurl;
  645. }
  646. else{
  647. goHome();
  648. }
  649. }
  650. function dp_share(){
  651. document.getElementById("share").style.display="";
  652. }
  653. function dp_Ranking(){
  654. window.location=mebtnopenurl;
  655. }
  656. function showAd(){
  657. }
  658. function hideAd(){
  659. }
  660. document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
  661. WeixinJSBridge.on('menu:share:appmessage', function(argv) {
  662. WeixinJSBridge.invoke('sendAppMessage', {
  663. "img_url": window.shareData.imgUrl,
  664. "link": window.shareData.timeLineLink,
  665. "desc": window.shareData.tContent,
  666. "title": window.shareData.tTitle
  667. }, onShareComplete);
  668. });
  669. WeixinJSBridge.on('menu:share:timeline', function(argv) {
  670. WeixinJSBridge.invoke('shareTimeline', {
  671. "img_url": window.shareData.imgUrl,
  672. "img_width": "640",
  673. "img_height": "640",
  674. "link": window.shareData.timeLineLink,
  675. "desc": window.shareData.tContent,
  676. "title": window.shareData.tTitle
  677. }, onShareComplete);
  678. });
  679. }, false);
  680. </script>
  681. <div id=share style="display: none">
  682. <img width=100% src="share.png"
  683. style="position: fixed; z-index: 9999; top: 0; left: 0; display: "
  684. ontouchstart="document.getElementById('share').style.display='none';" />
  685. </div>
  686. <div style="display: none;">
  687. <script type="text/javascript">
  688. var myData = { gameid: "zwdzjs" };
  689. function dp_submitScore(score){
  690. myData.score = parseInt(score);
  691. myData.scoreName = "获得"+score+"分";
  692. document.title ="我一举消失了入侵的丧尸获得了"+score+"分,丧尸已现世,快来一起消灭他们吧!";
  693. window.shareData.tTitle = document.title;
  694. }
  695. function onShareComplete(res) {
  696. if (localStorage.myuid && myData.score>0) {
  697. setTimeout(function(){
  698. if (confirm("?")) {
  699. window.location =mebtnopenurl;
  700. }
  701. else {
  702. document.location.href = mebtnopenurl;
  703. }
  704. }, 500);
  705. }
  706. else {
  707. document.location.href = guanzhuurl ;
  708. }
  709. }
  710. </script>
  711. <div style="display: none;">
  712. </div>
  713. <script type="text/javascript" src="js/game9g.utils.js?r="+Math.rand()></script>
  714. </body>
  715. </html>