点击跳转上篇
https://blog.csdn.net/weixin_44070254/article/details/115972451?spm=1001.2014.3001.5501
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="27">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//一个循环了,重新回到初始位置span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="28">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(z.imageKey>=(that.zombiesEatCount+z.key)){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="29">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
z.imageKey=z.key;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="30">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="31">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
z.image = that.imgObj[z.imageKey];
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="32">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="33">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
p.blood--;
<span class="hljs-comment">//植物血量的处理span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="34">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(p.blood<=
<span class="hljs-number">0span>){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="35">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//console.log('植物被吃了');span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="36">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
clearInterval(z.timmer);
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="37">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//清除植物span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="38">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">thisspan>.delPlant(p);
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="39">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
zomble.state=
<span class="hljs-string">'run'span>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="40">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
zomble.imageKey=zomble.key=
<span class="hljs-keyword">thisspan>.count+
<span class="hljs-number">1span>;
<span class="hljs-comment">//设定keyspan>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="41">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//继续移动span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="42">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
z.run();
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="43">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="44">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="45">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
ol>code>
<div class="hljs-button {2}" data-title="复制" data-report-click="{
"spm":"1001.2101.3001.4259"}" onclick="hljs.copyCode(event)">div>pre>
<h3><a name="t16">a><a name="t16">a>删除植物h3>
<pre><code class="hljs typescript">
<ol class="hljs-ln">
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="1">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//删除掉植物span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="2">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
Plants.prototype.delPlant=
<span class="hljs-function"><span class="hljs-keyword">functionspan>(<span class="hljs-params">plant,<span class="hljs-keyword">typespan>span>)span>{
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="3">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(!
<span class="hljs-keyword">typespan>){
<span class="hljs-comment">//还没有创建的植物不需要清除这两个任务span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="4">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//停止植物自身的动画span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="5">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-built_in">clearIntervalspan>(plant.timmerSelf);
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="6">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//停止植物发射子弹的动画span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="7">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-built_in">clearIntervalspan>(plant.timmer);
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="8">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="9">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//渲染中删除span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="10">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-built_in">thisspan>.clear(plant);
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="11">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//plants数组中删除span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="12">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-built_in">thisspan>.clearAssign(
<span class="hljs-built_in">thisspan>.plants,plant);
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="13">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//植物对应的背景处理span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="14">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(plant.bgRect){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="15">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
plant.bgRect.alive=
<span class="hljs-literal">falsespan>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="16">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
plant.bgRect.plant=
<span class="hljs-literal">falsespan>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="17">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="18">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
plant=
<span class="hljs-literal">nullspan>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="19">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
ol>code>
<div class="hljs-button {2}" data-title="复制" data-report-click="{
"spm":"1001.2101.3001.4259"}" onclick="hljs.copyCode(event)">div>pre>
<h2><a name="t17">a><a name="t17">a>创建向日葵h2>
<p><strong>1、点击卡牌后的创建,所以肯定是要传入鼠标的位置,创建的跟随鼠标移动(此时向日葵已经创建)strong>p>
<p><strong>2、设定 alive 函数,当在田里面选中位置后,执行此函数,进行种植操作。strong>p>
<p><strong>3、扣除阳光花费、更新卡牌是否可用、开启定时产生阳光的任务。strong>p>
<pre><code class="hljs kotlin">
<ol class="hljs-ln" style="width:1121px">
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="1">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//创建太阳植物span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="2">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
Plants.prototype.createSunPlant=function(pos,item){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="3">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">varspan> image,plant,sx=
<span class="hljs-number">0span>,sy=
<span class="hljs-number">0span>,sWidth=
<span class="hljs-number">63span>,sHeight=
<span class="hljs-number">73span>,dx=
<span class="hljs-number">110span>,dy=
<span class="hljs-number">300span>,dWidth=
<span class="hljs-number">63span>,dHeight=
<span class="hljs-number">73span>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="4">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
dx = pos.x,dy=pos.y;
<span class="hljs-comment">//设定初始位置为鼠标的位置span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="5">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//绘制时的图片下标span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="6">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">varspan> startKey=
<span class="hljs-keyword">thisspan>.count+
<span class="hljs-keyword">thisspan>.zombiesRunCount+
<span class="hljs-keyword">thisspan>.wandousRunCount+
<span class="hljs-keyword">thisspan>.zombiesDeadCount+
<span class="hljs-keyword">thisspan>.sunRunCount+
<span class="hljs-keyword">thisspan>.zombiesEatCount+
<span class="hljs-number">1span>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="7">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//方形卡片盘span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="8">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
image =
<span class="hljs-keyword">thisspan>.imgObj[startKey];
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="9">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
plant = new _.ImageDraw({image:image,sx:sx,sy:sy,sWidth:sWidth,sHeight:sHeight, dx:dx, dy:dy ,dWidth:dWidth,dHeight:dHeight});
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="10">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
plant.imageKey=startKey;
<span class="hljs-comment">//执行动画更新的下标span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="11">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
plant.key=startKey;
<span class="hljs-comment">//原始下标span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="12">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
plant.sunCost=item.sunCost;
<span class="hljs-comment">//阳光花费值span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="13">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
plant.blood=
<span class="hljs-number">50span>;
<span class="hljs-comment">//设定为50血量,实际是5秒吃完,因为100毫秒计算一次吃span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="14">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
plant.id=
<span class="hljs-string">'SunPlant'span>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="15">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">thisspan>.renderArr2.push(plant);
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="16">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="17">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">thisspan>.plants.push(plant);
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="18">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">thisspan>.currPlant=plant;
<span class="hljs-comment">//标记正在创建的植物span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="19">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="20">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
plant.alive=alive.bind(
<span class="hljs-keyword">thisspan>);
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="21">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="22">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
function alive(bgRect){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="23">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//设置背景对象span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="24">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
plant.bgRect=bgRect;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="25">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//扣除阳光花费span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="26">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">thisspan>.sunTotalCount-=plant.sunCost;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="27">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//更新卡片是否可用情况span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="28">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">thisspan>.updateCardUse();
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="29">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//更新阳光数值span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="30">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">thisspan>.sunCountObj.text=
<span class="hljs-keyword">thisspan>.sunTotalCount;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="31">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//每6秒发射一个阳光span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="32">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
plant.timmer = setInterval(shoot.bind(
<span class="hljs-keyword">thisspan>),
<span class="hljs-number">6000span>);
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="33">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">thisspan>.plantMusic.play();
<span class="hljs-comment">//音乐span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="34">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="35">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="36">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
function shoot(){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="37">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">thisspan>.createSun(plant);
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="38">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="39">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//植物本身的动画span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="40">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
plant.timmerSelf = setInterval(animate.bind(
<span class="hljs-keyword">thisspan>,plant),
<span class="hljs-number">100span>);
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="41">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
function animate(p){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="42">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">varspan> that=
<span class="hljs-keyword">thisspan>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="43">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
p.imageKey ++;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="44">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//一个循环了,重新回到初始位置span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="45">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(p.imageKey>=(that.sunPlantRunCount+p.key)){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="46">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
p.imageKey=p.key;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="47">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="48">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
p.image = that.imgObj[p.imageKey];
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="49">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="50">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
ol>code>
<div class="hljs-button {2}" data-title="复制" data-report-click="{
"spm":"1001.2101.3001.4259"}" onclick="hljs.copyCode(event)">div>pre>
<p><strong>点击卡牌后移动鼠标,向日葵会跟随鼠标移动,移动到田的方形位置,则此块方形的颜色会突出,点击它则会种植下去。strong>p>
<p><img alt="" height="238" src="https://img-blog.csdnimg.cn/20210419215313959.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2RrbTEyMzQ1Ng==,size_16,color_FFFFFF,t_70" width="317" />p>
<h2><a name="t18">a><a name="t18">a>创建豌豆植物h2>
<p><strong>1、与向日葵的创建很相似,就不同的时候向日葵创建的是阳光,豌豆植物创建的是小豌豆,可以攻击僵尸的。strong>p>
<p><strong>2、子弹在运动的时候、判断是否与僵尸接触,如果接触则执行击中的动画、删除这个子弹、减去僵尸的血量、如果僵尸死亡,则开启僵尸死亡动画,增加积分。strong>p>
<h3><a name="t19">a><a name="t19">a>创建h3>
<pre><code class="hljs javascript">
<ol class="hljs-ln" style="width:1136px">
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="1">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//创建豌豆span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="2">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
Plants.prototype.createWandou=
<span class="hljs-function"><span class="hljs-keyword">functionspan>(<span class="hljs-params">plantspan>)span>{
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="3">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">varspan> image,img,sx=
<span class="hljs-number">0span>,sy=
<span class="hljs-number">0span>,sWidth=
<span class="hljs-number">28span>,sHeight=
<span class="hljs-number">28span>,dx=plant.dx+
<span class="hljs-number">50span>,dy=plant.dy,dWidth=
<span class="hljs-number">28span>,dHeight=
<span class="hljs-number">28span>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="4">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//绘制时的图片下标span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="5">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">varspan> startKey=
<span class="hljs-number">6span>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="6">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//方形卡片盘span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="7">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
image =
<span class="hljs-built_in">thisspan>.imgObj[startKey];
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="8">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">varspan> wandou=
<span class="hljs-keyword">newspan> _.ImageDraw({
<span class="hljs-attr">imagespan>:image,
<span class="hljs-attr">sxspan>:sx,
<span class="hljs-attr">syspan>:sy,
<span class="hljs-attr">sWidthspan>:sWidth,
<span class="hljs-attr">sHeightspan>:sHeight,
<span class="hljs-attr">dxspan>:dx,
<span class="hljs-attr">dyspan>:dy ,
<span class="hljs-attr">dWidthspan>:dWidth,
<span class="hljs-attr">dHeightspan>:dHeight});
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="9">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-built_in">thisspan>.renderArr2.push(wandou);
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="10">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="11">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
wandou.index=plant.index;
<span class="hljs-comment">//给子弹设定行数标示span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="12">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="13">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-built_in">thisspan>.shootMusic.play();
<span class="hljs-comment">//射击音乐span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="14">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
wandou.timmer =
<span class="hljs-built_in">setIntervalspan>(wandouMove.bind(
<span class="hljs-built_in">thisspan>,wandou),
<span class="hljs-number">100span>);
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="15">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="16">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-function"><span class="hljs-keyword">functionspan> <span class="hljs-title">wandouMovespan>(<span class="hljs-params">wandouspan>)span>{
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="17">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
wandou.dx+=
<span class="hljs-number">10span>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="18">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//判断击中僵尸span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="19">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">varspan> flag =
<span class="hljs-built_in">thisspan>.hit(wandou);
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="20">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(flag || wandou.dx>
<span class="hljs-number">850span>){
<span class="hljs-comment">//击中目标 或者 超出边界span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="21">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-built_in">clearIntervalspan>(wandou.timmer);
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="22">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(flag){
<span class="hljs-comment">//击中目标span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="23">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//创建子弹击中的图片span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="24">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-built_in">thisspan>.hitAnimate(wandou);
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="25">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-built_in">thisspan>.hitMusic.play();
<span class="hljs-comment">//击中音乐span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="26">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="27">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//清除这个子弹span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="28">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-built_in">thisspan>.clear(wandou);
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="29">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
wandou=
<span class="hljs-literal">nullspan>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="30">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="31">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="32">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
ol>code>
<div class="hljs-button {2}" data-title="复制" data-report-click="{
"spm":"1001.2101.3001.4259"}" onclick="hljs.copyCode(event)">div>pre>
<h3><a name="t20">a><a name="t20">a>击中目标h3>
<pre><code class="hljs kotlin">
<ol class="hljs-ln" style="width:956px">
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="1">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//击中span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="2">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
Plants.prototype.hit=function(obj){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="3">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">varspan> arr =
<span class="hljs-keyword">thisspan>.zombies;
<span class="hljs-comment">//僵尸对象span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="4">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">forspan>(
<span class="hljs-keyword">varspan> i=
<span class="hljs-number">0span>;i<arr.length;i++){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="5">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">varspan> item = arr[i];
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="6">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(item.dx<=obj.dx+obj.dWidth && obj.index==item.index ){
<span class="hljs-comment">//子弹的函数标示与僵尸的行数标示也要相等span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="7">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
item.blood--;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="8">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(item.blood==
<span class="hljs-number">0span>){
<span class="hljs-comment">//消灭这个僵尸span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="9">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
clearInterval(item.timmer);
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="10">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(item.state==
<span class="hljs-string">'run'span>){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="11">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
item.imageKey=item.key=item.key+
<span class="hljs-keyword">thisspan>.zombiesRunCount+
<span class="hljs-keyword">thisspan>.wandousRunCount;
<span class="hljs-comment">//设置死亡图片下标span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="12">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
<span class="hljs-keyword">elsespan>
<span class="hljs-keyword">ifspan>(item.state==
<span class="hljs-string">'eat'span>){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="13">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
item.imageKey=item.key=item.key-
<span class="hljs-keyword">thisspan>.sunRunCount-
<span class="hljs-keyword">thisspan>.zombiesDeadCount;
<span class="hljs-comment">//设置死亡图片下标span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="14">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="15">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="16">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
item.state=
<span class="hljs-string">'dead'span>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="17">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">thisspan>.addCount();
<span class="hljs-comment">//增加积分span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="18">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">thisspan>.dead(item);
<span class="hljs-comment">//死亡动画span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="19">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
arr.splice(i,
<span class="hljs-number">1span>);
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="20">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="21">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">returnspan>
<span class="hljs-literal">truespan>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="22">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="23">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="24">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
ol>code>
<div class="hljs-button {2}" data-title="复制" data-report-click="{
"spm":"1001.2101.3001.4259"}" onclick="hljs.copyCode(event)">div>pre>
<p><img alt="" height="636" src="https://img-blog.csdnimg.cn/20210419220404289.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2RrbTEyMzQ1Ng==,size_16,color_FFFFFF,t_70" width="989" />p>
<h2><a name="t21">a><a name="t21">a>加入事件控制h2>
<pre><code class="hljs kotlin">
<ol class="hljs-ln">
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="1">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//给canvas2画布添加鼠标移动事件(因为画布2在上面)span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="2">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
canvas2.addEventListener(
<span class="hljs-string">'mousemove'span>,
<span class="hljs-keyword">thisspan>.mouseMove.bind(
<span class="hljs-keyword">thisspan>));
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="3">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="4">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//给canvas2画布添加鼠标点击事件(因为画布2在上面)span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="5">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
canvas2.addEventListener(
<span class="hljs-string">'click'span>,
<span class="hljs-keyword">thisspan>.mouseClick.bind(
<span class="hljs-keyword">thisspan>));
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="6">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="7">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//给canvas2画布添加鼠标右键事件(因为画布2在上面)span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="8">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
canvas2.addEventListener(
<span class="hljs-string">'contextmenu'span>,
<span class="hljs-keyword">thisspan>.contextMenu.bind(
<span class="hljs-keyword">thisspan>));
div>
div>li>
ol>code>
<div class="hljs-button {2}" data-title="复制" data-report-click="{
"spm":"1001.2101.3001.4259"}" onclick="hljs.copyCode(event)">div>pre>
<h3><a name="t22">a><a name="t22">a>鼠标移动事件h3>
<pre><code class="hljs kotlin">
<ol class="hljs-ln">
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="1">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//鼠标移动事件span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="2">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
Plants.prototype.mouseMove=function(e){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="3">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">varspan> that=
<span class="hljs-keyword">thisspan>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="4">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(that.gameOver)
<span class="hljs-keyword">returnspan> ;
<span class="hljs-comment">//目前设定的是结束后,要刷新页面才可以开始span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="5">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(!
<span class="hljs-keyword">thisspan>.startImage)
<span class="hljs-keyword">returnspan>;
<span class="hljs-comment">//防止没加载完成报错span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="6">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">varspan> pos = _.getOffset(e);
<span class="hljs-comment">//获取鼠标位置span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="7">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">varspan> isCatch =
<span class="hljs-keyword">thisspan>.startImage.isPoint(pos);
<span class="hljs-comment">//鼠标捕捉span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="8">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="9">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(!isCatch &&
<span class="hljs-keyword">thisspan>.gameAlive){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="10">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
isCatch =
<span class="hljs-keyword">thisspan>.createZombiesImage.isPoint(pos);
<span class="hljs-comment">//鼠标捕捉span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="11">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="12">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="13">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(!isCatch){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="14">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(
<span class="hljs-keyword">thisspan>.gameAlive && !
<span class="hljs-keyword">thisspan>.currPlant) {
<span class="hljs-comment">//游戏开始,并且没有正在创建的植物的时候可以执行span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="15">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//循环卡片背景数组span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="16">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">forspan>(
<span class="hljs-keyword">varspan> i=
<span class="hljs-number">0span>;i<
<span class="hljs-keyword">thisspan>.cardRectArr.length;i++){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="17">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">varspan> item=
<span class="hljs-keyword">thisspan>.cardRectArr[i];
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="18">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(item.isPoint(pos) && item.alive){
<span class="hljs-comment">//鼠标捕捉span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="19">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
isCatch=
<span class="hljs-literal">truespan>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="20">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">breakspan>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="21">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="22">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="23">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="24">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="25">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(!isCatch){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="26">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//循环太阳数组span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="27">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">forspan>(
<span class="hljs-keyword">varspan> i=
<span class="hljs-number">0span>;i<
<span class="hljs-keyword">thisspan>.suns.length;i++){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="28">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">varspan> item=
<span class="hljs-keyword">thisspan>.suns[i];
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="29">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(item.isPoint(pos)){
<span class="hljs-comment">//鼠标捕捉span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="30">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
isCatch=
<span class="hljs-literal">truespan>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="31">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">breakspan>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="32">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="33">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="34">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="35">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="36">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">varspan> plant =
<span class="hljs-keyword">thisspan>.currPlant;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="37">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(!isCatch){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="38">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(plant){
<span class="hljs-comment">//创建植物的时候,才出现填入背景框span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="39">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//循环田背景数组span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="40">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">forspan>(
<span class="hljs-keyword">varspan> i=
<span class="hljs-number">0span>;i<
<span class="hljs-keyword">thisspan>.bgRectArr.length;i++){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="41">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">varspan> item=
<span class="hljs-keyword">thisspan>.bgRectArr[i];
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="42">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(item.isPoint(pos) && !item.plant){
<span class="hljs-comment">//鼠标捕捉,并且当前没有植物span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="43">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
isCatch=
<span class="hljs-literal">truespan>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="44">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
item.fillStyle=
<span class="hljs-string">"rgba(0,250,154, 0.5)"span>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="45">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
<span class="hljs-keyword">elsespan>{
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="46">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
item.fillStyle=
<span class="hljs-string">"rgba(0,250,154, 0)"span>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="47">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="48">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="49">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="50">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="51">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="52">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(isCatch){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="53">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">thisspan>.el.style.cursor =
<span class="hljs-string">'pointer'span>;
<span class="hljs-comment">//改为手状形态span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="54">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
<span class="hljs-keyword">elsespan>{
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="55">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">thisspan>.el.style.cursor =
<span class="hljs-string">''span>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="56">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="57">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//表示当前正在创建植物span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="58">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(plant){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="59">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
plant.dx=pos.x;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="60">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
plant.dy=pos.y;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="61">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="62">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="63">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">thisspan>.render2();
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="64">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
ol>code>
<div class="hljs-button {2}" data-title="复制" data-report-click="{
"spm":"1001.2101.3001.4259"}" onclick="hljs.copyCode(event)">div>pre>
<h3><a name="t23">a><a name="t23">a>鼠标点击事件h3>
<pre><code class="hljs kotlin">
<ol class="hljs-ln">
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="1">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//鼠标点击事件span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="2">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
Plants.prototype.mouseClick=function(e){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="3">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(
<span class="hljs-keyword">thisspan>.gameOver)
<span class="hljs-keyword">returnspan> ;
<span class="hljs-comment">//目前设定的是结束后,要刷新页面才可以开始span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="4">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">varspan> that=
<span class="hljs-keyword">thisspan>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="5">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">varspan> pos = _.getOffset(e);
<span class="hljs-comment">//获取鼠标位置span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="6">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">varspan> isCatch = that.startImage.isPoint(pos);
<span class="hljs-comment">//鼠标捕捉span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="7">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(isCatch){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="8">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
that.start();
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="9">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="10">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(!isCatch &&
<span class="hljs-keyword">thisspan>.gameAlive){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="11">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
isCatch =
<span class="hljs-keyword">thisspan>.createZombiesImage.isPoint(pos);
<span class="hljs-comment">//鼠标捕捉span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="12">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(isCatch){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="13">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
that.createZombie();
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="14">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="15">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="16">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(!isCatch){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="17">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(
<span class="hljs-keyword">thisspan>.gameAlive && !
<span class="hljs-keyword">thisspan>.currPlant) {
<span class="hljs-comment">//游戏开始,并且没有正在创建的植物的时候可以执行span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="18">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//循环卡片数组span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="19">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">forspan>(
<span class="hljs-keyword">varspan> i=
<span class="hljs-number">0span>;i<
<span class="hljs-keyword">thisspan>.cardRectArr.length;i++){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="20">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">varspan> item=
<span class="hljs-keyword">thisspan>.cardRectArr[i];
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="21">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(item.isPoint(pos) && item.alive){
<span class="hljs-comment">//鼠标捕捉span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="22">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
isCatch=
<span class="hljs-literal">truespan>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="23">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//生成一个新的豌豆苗,跟随鼠标移动span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="24">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">thisspan>.createPlant(pos,item);
<span class="hljs-comment">//创建植物span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="25">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">breakspan>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="26">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="27">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="28">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="29">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="30">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="31">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(!isCatch){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="32">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//循环太阳数组span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="33">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">forspan>(
<span class="hljs-keyword">varspan> i=
<span class="hljs-number">0span>;i<
<span class="hljs-keyword">thisspan>.suns.length;i++){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="34">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">varspan> item=
<span class="hljs-keyword">thisspan>.suns[i];
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="35">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(item.isPoint(pos)){
<span class="hljs-comment">//鼠标捕捉span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="36">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
item.click && item.click();
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="37">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">breakspan>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="38">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="39">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="40">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="41">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(!isCatch){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="42">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">varspan> plant =
<span class="hljs-keyword">thisspan>.currPlant;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="43">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(plant){
<span class="hljs-comment">//正在创建植物span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="44">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-comment">//循环田背景数组span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="45">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">forspan>(
<span class="hljs-keyword">varspan> i=
<span class="hljs-number">0span>;i<
<span class="hljs-keyword">thisspan>.bgRectArr.length;i++){
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="46">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">varspan> item=
<span class="hljs-keyword">thisspan>.bgRectArr[i];
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="47">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(item.plant)
<span class="hljs-keyword">continuespan>;
<span class="hljs-comment">//如果当前有植物,则跳过span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="48">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">ifspan>(item.isPoint(pos)){
<span class="hljs-comment">//鼠标捕捉span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="49">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
isCatch=
<span class="hljs-literal">truespan>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="50">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
plant.dx=item.x+
<span class="hljs-number">10span>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="51">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
plant.dy=item.y+
<span class="hljs-number">20span>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="52">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
plant.index=item.index;
<span class="hljs-comment">//给plant设置行数span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="53">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
plant.alive(item);
<span class="hljs-comment">//植物生效span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="54">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="55">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
item.plant=
<span class="hljs-literal">truespan>;
<span class="hljs-comment">//表示有植物span>
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="56">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
item.fillStyle=
<span class="hljs-string">"rgba(0,250,154, 0)"span>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="57">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="58">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">thisspan>.currPlant=
<span class="hljs-literal">nullspan>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="59">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
<span class="hljs-keyword">breakspan>;
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="60">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-line hljs-ln-n" data-line-number="61">div>
div>
<div class="hljs-ln-code">
<div class="hljs-ln-line">
}
div>
div>li>
<li>
<div class="hljs-ln-numbers">
<div class="hljs-ln-lin