js实现植物大战僵尸游戏代码
代码语言:html
所属分类:游戏
代码描述:js实现植物大战僵尸游戏代码,种植物 向日葵 - 产生阳光(50阳光) 豌豆射手 - 基础射手(100阳光) 坚果墙 - 高血量防御(50阳光) 寒冰射手 - 减速僵尸(175阳光) 樱桃炸弹 - 范围爆炸(150阳光) 双发射手 - 双倍火力(200阳光) 大嘴花 - 一口吞噬(150阳光) 土豆雷 - 地雷陷阱(25阳光)
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>植物大战僵尸</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
user-select: none;
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
font-family: 'Comic Sans MS', cursive, sans-serif;
overflow: hidden;
}
#gameContainer {
position: relative;
width: 1000px;
height: 600px;
background: linear-gradient(180deg, #87CEEB 0%, #87CEEB 20%, #228B22 20%, #228B22 100%);
border: 5px solid #4a2810;
border-radius: 10px;
overflow: hidden;
box-shadow: 0 0 30px rgba(0,0,0,0.5);
}
/* 草地背景 */
#lawn {
position: absolute;
top: 80px;
left: 0;
right: 0;
bottom: 0;
background: repeating-linear-gradient(
90deg,
#32CD32 0px,
#32CD32 100px,
#2EB82E 100px,
#2EB82E 200px
);
}
.lawnRow {
height: 100px;
display: flex;
}
.lawnRow:nth-child(odd) .cell:nth-child(odd),
.lawnRow:nth-child(even) .cell:nth-child(even) {
background: rgba(0,0,0,0.05);
}
.cell {
width: 100px;
height: 100px;
border: 1px solid rgba(0,0,0,0.1);
position: relative;
}
/* 顶部UI */
#topBar {
position: absolute;
top: 0;
left: 0;
right: 0;
height: 80px;
background: linear-gradient(180deg, #8B4513 0%, #654321 100%);
display: flex;
align-items: center;
padding: 5px 10px;
border-bottom: 3px solid #3d2010;
}
#sunCount {
background: linear-gradient(180deg, #FFD700 0%, #FFA500 100%);
border-radius: 10px;
padding: 5px 15px;
font-size: 24px;
font-weight: bold;
color: #333;
margin-right: 20px;
border: 3px solid #B8860B;
min-width: 80px;
text-align: center;
box-shadow: inset 0 2px 5px rgba(255,255,255,0.3);
}
#plantSelector {
display: flex;
gap: 5px;
flex: 1;
}
.plantCard {
width: 60px;
height: 70px;
background: linear-gradient(180deg, #D2B48C 0%, #8B7355 100%);
border: 2px solid #5D4E37;
border-radius: 5px;
cursor: pointer;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
transition: all 0.2s;
position: relative;
}
.plantCard:hover {
transform: scale(1.1);
box-shadow: 0 0 10px rgba(255,255,0,0.5);
}
.plantCard.selected {
border-color: #FFD700;
box-shadow: 0 0 15px rgba(255,215,0,0.8);
}
.plantCard.disabled {
opacity: 0.5;
cursor: not-allowed;
}
.plantCard .icon {
font-size: 28px;
}
.plantCard .cost {
font-size: 12px;
color: #FFD700;
font-weight: bold;
}
.plantCard .cooldown {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0,0,0,0.7);
border-radius: 3px;
display: none;
}
.plantCard.cooling .cooldown {
display: block;
}
/* 游戏元素 */
.plant {
position: absolute;
font-size: 50px;
text-align: center;
animation: plantBounce 0.5s ease-out;
z-index: 10;
filter: drop-shadow(2px 2px 2px rgba(0,0,0,0.3));
}
@keyframes plantBounce {
0% { transform: scale(0); }
50% { transform: scale(1.2); }
100% { transform: scale(1); }
}
.zombie {
position: absolute;
font-size: 55px;
z-index: 20;
filter: drop-shadow(2px 2px 2px rgba(0,0,0,0.3));
transition: filter 0.1s;
}
.zombie.damaged {
filter: brightness(2) drop-shadow(2px 2px 2px rgba(0,0,0,0.3));
}
@keyframes zombieWalk {
0%, 1.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0