0


HTML5 植物大战僵尸项目介绍 和源码分析

项目目录

images 包含项目中所有植物和僵尸和场景,的图片

js文件夹下是游戏控制的js文件

level 是游戏关卡的js控制文件

music 文件夹 游戏背景音乐

index.html 游戏面板的主页

代码如下

  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  4. <meta name="KeyWords" content="lonelystar,植物大战僵尸,网页版,JS植物大战僵尸,PVZ,JSPVZ,JS版,Javascript">
  5. <meta name="Description" content="JavaScript版的植物大战僵尸">
  6. <title>植物大战僵尸Javascript版</title>
  7. <style type="text/css">
  8. body{-moz-user-select:none}
  9. td{font-family: 宋体; font-size: 12px}
  10. div{left:0}
  11. span{cursor:default}
  12. span,div,h2,h3{padding:0;margin:0}
  13. td.HandBookZombie{background: url(images/interface/Almanac_ZombieWindow2.png) no-repeat; width:20%; height:16%; text-align:center}
  14. #DivTeach{
  15. filter:"alpha(opacity=90)"; /* IE 8 */
  16. filter:alpha(opacity=90); /* IE 4-7 */
  17. opacity:.9; /* FireFox,Safari(WebKit),Opera */
  18. -moz-opacity:.9; /* FireFox<3.5 */
  19. position:absolute;width:900px;height:50px;top:530px;left:0;z-index:100;text-align: center; font-family: 幼圆; font-size: 20pt; font-weight: bold; color: #FFFFFF; background-color: #5B432E}
  20. .WindowFrame{position:absolute;width:900px;height:600px;OVERFLOW: hidden;border:3px outset ;}
  21. #dFlagMeterTitleB{position:absolute;color:#000; font-size: 18pt;font-weight:bold;width:343px;top:15px;left:-5px}
  22. #dFlagMeterTitleB span{position:absolute;color:#F93;font-size: 18pt;font-weight: bold;width:343px;top:-1px;left:-1px;}
  23. #dSurfaceBack{position:absolute;display:none;top:0;width:900px;height:600px;z-index:255}
  24. #dHelp{width:614px;height:399px;background:url(images/Help.png);position:absolute;display:none;left:143px;top:100px}
  25. #dSelectLevel{position:absolute;width:100%;height:100%;font-weight:bold;display:none}
  26. #dOptionsMenuBack{position:absolute;text-align:center;left:244px;top:60px;width:412px;height:483px;display:none;background:url(images/OptionsMenuback32.png);_background:url(images/OptionsMenuback8.png)}
  27. .TitleBigContainer{position:relative;width:220px;margin:120px auto 0 auto;height:240px;overflow:hidden}
  28. .TitleSmallContainer{position:relative;width:100%;line-height:35px;color:#FFF;font-size:16px}
  29. .SmallLevel{float:left;cursor:pointer;width:50%}
  30. .BigLevel{float:left;color:#FC6;font-size:20px;width:100%;height:40px}
  31. .OptionsMenuButton,.OptionsMenuButtonDown{background:url(images/OptionsBackButton32.png);_background:url(images/OptionsBackButton8.png);float:left;font-family:黑体;font-size:32px;cursor:pointer;width:360px;height:100px;margin-left:26px;display:inline;color:#FC6}
  32. .OptionsMenuButton{background-position:0 0}
  33. .OptionsMenuButtonDown{background-position:0 100}
  34. .OptionsMenuButtonSpan{height:100px;line-height:100px;cursor:pointer}
  35. #dPCard img{left:0;width:70px;height:42px}
  36. #dPCard .span1{cursor:pointer;width:70px;height:42px;float:left;margin:8px 0 0 2px;position:relative;}
  37. #dPCard .span2{cursor:pointer;text-align:center;position:absolute;left:40px;top:27px;font-family:Fixedsys;font-size:9pt}
  38. #dCardList div{position:relative;cursor:pointer;padding:0;height:60px}
  39. #dCardList span{cursor:pointer;position:absolute;left:66px;top:40px;width:34px;height:20px;font-family:Fixedsys;font-size:11pt}
  40. #dCardList img{position:absolute;width:100px;height:60px}
  41. .SelectModal{color: #FC6; font-weight: bold;cursor:pointer;background: url(images/interface/Button.png) no-repeat center;text-align:center;height:43px;width:115px}
  42. .Menu{float:left;text-align:center;line-height:41px;font-weight:bold;font-family:黑体;color:#00CB08;height:41px;width:113px;background:url(images/interface/Button.png)}
  43. #imgSF{position:absolute;cursor:pointer;z-index:254}
  44. #PointerUD{position:absolute;z-index:50}
  45. #dTitle{display:none;position:absolute;left:100;background-color:#FFD;width:150px;font-size:12px;text-align:center;line-height:1.5;border:1px solid #000;padding:3px;z-index:254}
  46. #dAll img,#dFlagMeter img{position:absolute;border-style:none}
  47. #dProcess{text-align:center;border: 1px solid #FFF;background-color:#000;color:#FFF;position:absolute;left:130px;top:50px;width:640px;height:500px;display:none;z-index:250;padding:10px;*padding:10px 5px 10px 2px}
  48. #dProcess img{margin:5px 0}
  49. #dProcess h2{font-size:16px;margin:0 10px;color:#E80}
  50. #dProcess h3{font-size:12px}
  51. #dProcess2{overflow:auto;line-height:18px;font-size:12px;text-align:left;width:100%;*width:96%;height:450px}
  52. #dLink{position:absolute;left:5px;top:610px;width:500px;height:50px}
  53. #dLink div{float:left;margin-right:10px}
  54. .Tom1{left:0;top:0;width:86px;height:91px;background:url(images/interface/Tombstones.png) no-repeat}
  55. .Tom2{position:absolute;left:0;top:0;width:86px;height:91px;background:url(images/interface/Tombstone_mounds.png) no-repeat}
  56. </style>
  57. <script src="js/Cfunction.js" type="text/javascript"></script>
  58. <script src="js/CPlants.js" type="text/javascript"></script>
  59. <script src="js/CZombie.js" type="text/javascript"></script>
  60. <script id="JSPVZ" type="text/javascript"></script>
  61. <script id="JSProcess" type="text/javascript"></script>
  62. </head>
  63. <body id="dBody" topmargin="0" leftmargin="0" oncontextmenu="return false" ondragstart="return false" onselectstart="return false" bgcolor="#008080">
  64. <!--进度条-->
  65. <div id="dFlagMeter" style="visibility:hidden;position:absolute;z-index:255;left:50px;top:280px;width:500px;height:40px">
  66. <div id="dFlagMeterTitle" style="position:absolute;text-align:right"><div id="dFlagMeterTitleB"><span id="sFlagMeterTitleF"></span></div></div>
  67. <div id="dFlagMeterContent" style="position:absolute;left:344px;width:157px;height:40px">
  68. <img id="imgFlagMeterEmpty" border="0" src="images/interface/FlagMeterEmpty.png" style="top: 17px">
  69. <img id="imgFlagMeterFull" border="0" src="images/interface/FlagMeterFull.png" style="top: 17px;clip:rect(0,auto,auto,157px)">
  70. <img id="imgFlag1" src="images/interface/FlagMeterParts2.png" style="left: 10px; top: 14px;display:none">
  71. <img id="imgFlag2" src="images/interface/FlagMeterParts2.png" style="left: 40px; top: 14px;display:none">
  72. <img id="imgFlag3" src="images/interface/FlagMeterParts2.png" style="left: 70px; top: 14px;display:none">
  73. <img id="imgFlag4" src="images/interface/FlagMeterParts2.png" style="left: 100px; top: 14px;display:none">
  74. <img id="imgGQJC" src="images/interface/FlagMeterLevelProgress.png" style="left: 35px; top: 29px;display:block">
  75. <img id="imgFlagHead" src="images/interface/FlagMeterParts1.png" style="left: 139px; top: 13px">
  76. </div>
  77. </div>
  78. <!--选项界面-->
  79. <div id="dSurface" class="WindowFrame" style="display:none;z-index:255">
  80. <div id="iSurfaceBackground">
  81. <map name="FPMap0">
  82. <area href="javascript:void(0)" shape="rect" coords="641, 466, 724, 527" onClick="ShowOptions()">
  83. <area href="javascript:void(0)" shape="rect" coords="718, 512, 790, 558" onClick="ShowHelp()">
  84. <area href="javascript:void(0)" shape="rect" coords="800, 495, 879, 548" onClick="SetNone($('dSurface'))">
  85. </map>
  86. <img src="images/surface.png" usemap="#FPMap0" border="0">
  87. <div style="position: absolute;background:url('images/SelectorScreenStartAdventur.png');left:474px;top:80px;width:331px;height:146px;cursor:pointer" onMouseOver="this.style.backgroundPosition='bottom'" onMouseOut="this.style.backgroundPosition='top'" onClick="ShowLevel()"></div>
  88. <div style="position: absolute;background:url('images/SelectorScreenSurvival.png');left:474px;top:203px;width:313px;height:131px;cursor:pointer" onMouseOver="this.style.backgroundPosition='bottom'" onMouseOut="this.style.backgroundPosition='top'" onClick="ShowMiniGame()"></div>
  89. </div>
  90. <div id="dSurfaceBack">
  91. <div id="dHelp" onClick="HiddenHelp()"></div>
  92. <div id="dOptionsMenuback">
  93. <div id="dOptionsMenu" style="line-height:40px;position:absolute;width:100%;height:100%;display:none;font-weight:bold">
  94. <div style="margin-top:150px;height:40px"><input type="checkbox" id="cAutoSun" value="1" onChange="CheckAutoSun(this)"><label for="cAutoSun" id="lAutoSun" style="color:#FFF">自动拾取阳光</label></div>
  95. <div class="BigLevel" style="cursor:pointer" onClick="SelectModal(oS.Lvl)">重新开始</div>
  96. <div class="BigLevel" style="cursor:pointer" onClick="HiddenOptions();SelectModal(0);SetBlock($('dSurface'),$('iSurfaceBackground'))">返回菜单</div>
  97. <div class="OptionsMenuButton" style="margin-top:108px" onMouseDown="OptionsMenuDown(this,$('sOptionsMenu'))" onMouseUp="OptionsMenuUP(this,$('sOptionsMenu'));HiddenOptions()"><span id="sOptionsMenu" class="OptionsMenuButtonSpan">返回游戏</span></div>
  98. </div>
  99. <div id="dSelectLevel">
  100. <div class="TitleBigContainer">
  101. <div id="dTitleSmallContainer" class="TitleSmallContainer" style="display:none">
  102. <div id="dBigLvl1">
  103. <div class="BigLevel">&nbsp;&nbsp;&nbsp;第一大关&nbsp;&nbsp;&nbsp;<span style="cursor:pointer" onClick="SetNone($('dBigLvl1'));SetBlock($('dBigLvl2'))" title="点击进入到第二大关">>></span></div>
  104. <div onClick="SelectModal(1)" class="SmallLevel">第一关</div>
  105. <div onClick="SelectModal(2)" class="SmallLevel">第二关</div>
  106. <div onClick="SelectModal(3)" class="SmallLevel">第三关</div>
  107. <div onClick="SelectModal(4)" class="SmallLevel">第四关</div>
  108. <div onClick="SelectModal(5)" class="SmallLevel">第五关</div>
  109. <div onClick="SelectModal(6)" class="SmallLevel">第六关</div>
  110. <div onClick="SelectModal(7)" class="SmallLevel">第七关</div>
  111. <div onClick="SelectModal(8)" class="SmallLevel">第八关</div>
  112. <div onClick="SelectModal(9)" class="SmallLevel">第九关</div>
  113. <div onClick="SelectModal(10)" class="SmallLevel">第十关</div>
  114. </div>
  115. <div id="dBigLvl2" style="display:none">
  116. <div class="BigLevel"><span style="cursor:pointer" onClick="SetNone($('dBigLvl2'));SetBlock($('dBigLvl1'))" title="点击进入到第一大关"><<</span>&nbsp;&nbsp;&nbsp;第二大关&nbsp;&nbsp;&nbsp;</div>
  117. <div onClick="SelectModal(11)" class="SmallLevel">第一关</div>
  118. <div onClick="SelectModal(12)" class="SmallLevel">第二关</div>
  119. </div>
  120. </div>
  121. <div id="dMiniSmallContainer" class="TitleSmallContainer" style="display:none">
  122. <div class="BigLevel">小游戏模式</div>
  123. <div onClick="SelectModal('StrongLevel')" class="SmallLevel" style="width:100%">超乎寻常的压力!</div>
  124. <div onClick="SelectModal('TestUHeart')" class="SmallLevel" style="width:100%">你的心脏够强劲吗?</div>
  125. <div onClick="SelectModal('ZombieRun')" class="SmallLevel" style="width:100%">僵尸快跑!</div>
  126. <div onClick="SelectModal('PovertyOfTheSoil')" class="SmallLevel" style="width:100%">贫瘠之地</div>
  127. <div onClick="SelectModal('MassGrave')" class="SmallLevel" style="width:100%">乱葬岗</div>
  128. </div>
  129. </div>
  130. <div class="OptionsMenuButton" style="margin-top:20px" onMouseDown="OptionsMenuDown(this,$('sLevelMenu'))" onMouseUp="OptionsMenuUP(this,$('sLevelMenu'));HiddenLevel();HiddenMiniGame()"><span id="sLevelMenu" class="OptionsMenuButtonSpan">返&nbsp;&nbsp;&nbsp;&nbsp;回</span></div>
  131. </div>
  132. </div>
  133. </div>
  134. </div>
  135. <!--主界面EDAll-->
  136. <div class="WindowFrame" id="dAll" style="position:absolute;left:0;top:0;width:900px;background-color:#000">
  137. <!--背景图片-->
  138. <div style="position:absolute;width:1400px;height:600px;display:none;z-index:0" id="tGround"></div>
  139. <!--左边卡片列-->
  140. <div id="dCardList" style="visibility:hidden;position:absolute;left:500px;top:0;width:100px;overflow:visible;z-index:254"></div>
  141. <!--出场僵尸显示-->
  142. <div id="dZombie" style="position:absolute;width:335px;height:600px;left:1065px;top:0;z-index:1"></div>
  143. <!--选择卡片-->
  144. <div id="dSelectCard" align=center style="display:none;position:absolute;left:600px;top:0;width:465px;height:600px;z-index:1;background: url('images/interface/SeedChooser_Background.png') no-repeat">
  145. <div style="text-align:center;line-height:35px;font-size: 12pt;color:#FC6;height:35px;width:100%;top:0;font-family:新宋体;font-weight: bold">选择你的植物</div>
  146. <div id="dPCard" style="position:relative;width:96%;height:455px;"></div>
  147. <div style="width:100%;height:40px;line-height:40px;text-align:center;margin-top:10px">
  148. <input onClick="ResetSelectCard()" type="button" value="重选" name="btnReset" id="btnReset" style="width: 65; height: 35; border-left: 3px solid #85411C; border-right: 3px solid #4E250C; border-top: 3px solid #85411C; border-bottom: 3px solid #4E250C; background-color: #602D11; color:#FC6; font-weight:bold; font-size:14px;cursor:pointer">
  149. <input onClick="LetsGO()" type="button" value="GO!" disabled="disabled" name="btnOK" id="btnOK" style="width: 65; height: 35; border-left: 3px solid #85411C; border-right: 3px solid #4E250C; border-top: 3px solid #85411C; border-bottom: 3px solid #4E250C; background-color: #602D11; color:#888; font-weight:bold; font-size:14px;cursor:pointer">
  150. </div>
  151. </div>
  152. <!--阳光和铲子-->
  153. <div id="dTop" style="position:absolute;left:605px;top:561px;height:35px;width:123px;display:none;z-index:1;">
  154. <div id="dSunNum" style="background:url('images/interface/SunBack.png') no-repeat;position:absolute;width:123px;height:35px"><span id="sSunNum" style="text-align:center;position:absolute;top:4px;left:43px;width:68px;font-family:Verdana;font-weight:bold;font-size:18pt"></span></div>
  155. <div id="tdShovel" style="position:absolute;width:71px;height:35px;left:130px;background: url('images/interface/ShovelBack.png') no-repeat;visibility:hidden"><img id="imgShovel" src="images/interface/Shovel.png" onMouseDown="ChoseShovel(event)"></div>
  156. </div>
  157. </div>
  158. <!--菜单-->
  159. <div id="dMenu" style="display:none;position:absolute;cursor:pointer;width:226px;height:41px;left:677px;z-index:254">
  160. <div id="dMenu0" class="Menu" onClick="PauseGame(this)">暂 停</div>
  161. <div id="dMenu1" class="Menu" onClick="ClickMenu()">菜 单</div>
  162. </div>
  163. <!--图鉴-->
  164. <div id="dHandBook" style="display:none;position:absolute;z-index:255" class="WindowFrame">
  165. <table border="0" width="800" cellspacing="0" cellpadding="0" background="images/interface/Almanac_IndexBack.jpg" height="600">
  166. <tr>
  167. <td height="88" align="center" style="font-size: 32px; font-weight: bold; font-family: 黑体;" colspan="3"> 图鉴——索引</td>
  168. </tr>
  169. <tr>
  170. <td align="center" width="400" height="473">
  171. <img border="0" src="images/Plants/SunFlower/SunFlower.gif" width="73" height="74"><br>
  172. <br>
  173. <br>
  174. <br>
  175. <input type="button" value="查看植物" name="btnViewPlant" id="btnViewPlant" style="cursor:pointer;width: 113; height: 41; border-left: 3px solid #85411C; border-right: 3px solid #4E250C; border-top: 3px solid #85411C; border-bottom: 3px solid #4E250C; background-color: #8F431B; color:#FFCC66; font-weight:bold; font-size:14pt; font-family:幼圆" onClick="ViewProducePlant()"><br>
  176. <br>
  177. &nbsp;</td>
  178. <td align="center" width="400" height="473" colspan="2">
  179. <img border="0" src="images/Zombies/Zombie/Zombie.gif" width="149" height="130"><br>
  180. &nbsp;<table border="0" width="113" background="images/interface/Button.png" height="41" cellspacing="0" cellpadding="0">
  181. <tr>
  182. <td style="cursor:pointer;font-weight:bold; font-size:14pt; font-family:幼圆; color:#00F500" align="center" onClick="ViewProduceZombie()">查看僵尸</td>
  183. </tr>
  184. </table>
  185. <p><br>
  186. <br>
  187. &nbsp;</td>
  188. </tr>
  189. <tr>
  190. <td align="center" width="400">
  191.  </td>
  192. <td align="center" width="238">
  193.  </td>
  194. <td align="center" width="162">
  195. <table border="0" width="89" cellspacing="0" cellpadding="0" height="26">
  196. <tr>
  197. <td background="images/interface/Almanac_CloseButton.png" style="cursor:pointer" onMouseOver="this.style.backgroundImage='url(images/interface/Almanac_CloseButtonHighlight.png)'" onMouseOut="this.style.backgroundImage='url(images/interface/Almanac_CloseButton.png)'" onClick="SetNone($('dHandBook'))" align="center">
  198. <font color="#000080" style="font-size: 9pt;">关闭</font></td>
  199. </tr>
  200. </table>
  201. </td>
  202. </tr>
  203. </table>
  204. </div>
  205. <!--获得新植物-->
  206. <div id="dNewPlant" style="display:none;position:absolute;width:800px;height:600px;background:url(images/interface/AwardScreen_Back.jpg) no-repeat">
  207. <div id="dNewPlantTitle" style="position:absolute;left:50%;text-align:center;margin-left:-250px;color: #FC6; font-size: 20px;height:90px;line-height:90px; font-weight: bold; width:500px">你获得了一棵新的植物!</div>
  208. <div style="position:absolute;top:100px;width:800px;height:191px;line-height:191px;text-align:center">
  209. <img id="iNewPlantCard" border="0">
  210. </div>
  211. <br>
  212. <div id="dNewPlantName" style="position:absolute;position:absolute;top:291px;text-align:center;left:50%;margin-left:-150px;width:300px;height:55px;font-family: 宋体; font-size: 20px; color: #FC6; font-weight: bold;line-height:55px">abc</div>
  213. <br><br><br>
  214. <div id="dNewPlantTooltip" style="position:absolute;left:50%;top:400px;text-align:center;margin-left:-140px;width:280px;font-weight: bold;font-family: 宋体; font-size: 12px;color:#232323">abc</div>
  215. <br><br><br><br><br><br>
  216. <input type="button" value="下一关!" name="btnNextLevel" id="btnNextLevel" style="position:absolute;cursor:pointer;width: 113; height: 41; border-left: 3px solid #85411C; border-right: 3px solid #4E250C; border-top: 3px solid #85411C; border-bottom: 3px solid #4E250C; background-color: #8F431B; color:#FC6; font-weight:bold; font-size:14px; font-family:幼圆; left:344; top:507">
  217. </div>
  218. <!--开发进度显示-->
  219. <div id="dProcess">
  220. <div id="dProcess2"><span id="sFailed" style="line-height:30px;font-size:16px;color:#FF0;font-weight:bold">未成功从作者网站上加载到进度文件<br>如果互联网未连接或者作者网站无法成功打开则无法查看最新进度显示!</span></div>
  221. <br>
  222. <input type="button" value="关闭" onClick="SetNone($('dProcess'))" style="cursor:pointer;width: 113px; height: 30px; border-left: 3px solid #85411C; border-right: 3px solid #4E250C; border-top: 3px solid #85411C; border-bottom: 3px solid #4E250C; background-color: #8F431B; color:#FC6; font-weight:bold; font-size:14px; font-family:幼圆">
  223. </div>
  224. <script type="text/javascript">
  225. //初始化系统对象,载入关卡
  226. LoadLvl();
  227. </script>
  228. </body>
  229. </html>

游戏截图

项目源码下载链接 --点击


本文转载自: https://blog.csdn.net/weixin_40986713/article/details/124213272
版权归原作者 李泰山 所有, 如有侵权,请联系我们删除。

“HTML5 植物大战僵尸项目介绍 和源码分析”的评论:

还没有评论