js+css实现一个杀虫小游戏代码
代码语言:html
所属分类:游戏
代码描述:js+css实现一个杀虫小游戏代码,按左键喷洒杀虫剂。
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
:root {
--title: "Fumigation Frenzy";
--author: "Matt Cannon";
--contact: "mc@mattcannon.design";
--description: "A fast-paced bug extermination game where you spray fumigation gas to eliminate bugs before your tank runs out.";
--keywords: "game, bugs, fumigation, extermination, spray, pest control, arcade game, particle effects, animation, CSS animation, JavaScript game, HTML5 game, interactive";
--last-modified: "2025-03-05";
--content-language: "en";
--generator: "HTML5, CSS3, JavaScript, FontAwesome icons, CSS particles, requestAnimationFrame for fumigation gas animation, dynamic particle system for gas clouds, CSS transforms for bug movement";
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
background: url(//repo.bfw.wiki/bfwrepo/image/67d76faf0f8f6.png);
cursor: none; /* Hide default cursor */
overflow: hidden;
font-family: 'Rubik', sans-serif;
color: #fff;
}
/* Make sure all elements use the 'none' cursor to properly hide it */
#root, button, div, .bug {
cursor: none;
}
#root { position: relative; height: 100vh; }
.cursor {
position: absolute;
width: 200px;
height: 300px;
background: url('//repo.bfw.wiki/bfwrepo/images/chong/wand.png');
background-size: contain;
background-position: center;
background-repeat: no-repeat;
pointer-events: none;
z-index: 1000; /* Increased z-index to ensure it's on top */
transform-origin: 50% 90%;
transition: transform 0.1s;
will-change: left, top; /* Optimize for animation performance */
}
.cursor.spray {
transform: scale(0.95);
animation: shake 0.1s infinite;
}
@keyframes shake {
0% { transform: rotate(-2deg) scale(0.95); }
50% { transform: rotate(2deg) scale(0.95); }
100% { transform: rotate(-2deg) scale(0.95); }
}
/* Gas cloud particle */
.gas-particle {
position: absolute;
border-radius: 50%;
background-color: rgba(0, 255, 0, 0.8);
pointer-events: none;
z-index: 90;
filter: blur(4px);
mix-blend-mode: screen;
box-shadow: 0 0 10px rgb(0, 255, 0);
}
/* Bug styles */
.bug {
position: absolute;
background-position: 0 0;
z-index: 50;
filter: drop-shadow(1px 1px 2px rgba(0,0,0,0.3));
transition: transform 0.3s;
}
.bug.dead {
animation: none !important;
transition: top 0.8s cubic-bezier(0.5, 0, 1, 0.5);
top: calc(100% + 30px) !important;
transform: rotate(180deg);
opacity: 0.6;
z-index: 40;
}
.fly {
width: 26px; height: 16px;
animation: fly 0.1s infinite step-end;
background: url(//repo.bfw.wiki/bfwrepo/images/chong/fly.png);
}
.gnat {
width: 14px; height: 10px;
animation: gnat 0.1s infinite step-end;
background: url(//repo.bfw.wiki/bfwrepo/images/chong/gnat.png);
}
.wasp {
width: 48px; height: 32px;
animation: wasp 0.1s infinite step-end;
background: url(//repo.bfw.wiki/bfwrepo/images/chong/wasp.png);
}
.bigfly {
width: 32px; height: 30px;
animation: bigfly 0.1s infinite step-end;
background: url(//repo.bfw.wiki/bfwrepo/images/chong/bigfly.png);
}
@keyframes fly { 0% { background-position: 0 0; } 50% { background-position: -26px 0; } }
@keyframes gnat { 0% { background-position: -14px 0; } 50% { background-position: -28px 0; } }
@keyframes wasp { 0% { background-position: -96px 0; } 50% { background-position: -144px 0; } }
@keyframes bigfly { 0% { background-position: 0 0; } 50% { background-position: -32px 0; } }
@keyframes float-up { 0% { transform: translateY(0); opacity: 1; } 100% { transform: translateY(-40px); opacity: 0; } }
/* UI Elements */
.stats-container {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.5);
color: #fff;
padding: 10px 15px;
font-weight: bold;
font-size: 20px;
z-index: 200;
display: flex;
align-items: center;
}
.stats-container i {
margin-right: 8px;
color: #90ee90;
}
.stats-item {
display: flex;
align-items: center;
padding: 0 15px;
position: relative;
justify-content: center;
}
.stats-item:nth-child(1)::after {
content: '';
position: absolute;
right: 0;
top: 20%;
height: 60%;
width: 1px;
background-color: rgba(255, 255, 255, 0.5);
}
.score-display, .bugs-left-display {
flex: 1;
text-align: center;
}
.high-score-display {
text-align: right;
margin-left: auto;
}
.gas-stat {
display: flex;
align-items: center;
flex: 2;
justify-content: center;
}
.gas-label {
margin-right: 15px;
white-space: nowrap;
}
.gas-meter-wrapper {
width: 200px;
height: 25px;
background: #222;
padding: 3px;
border-radius: 6px;
border: 1px solid rgba(255, 255, 255, 0.3);
}
.gas-meter {
height: 100%;
width: 100%;
background: linear-gradient(to right, #00cc00, #00ff00);
transition: width 0.3s;
border-radius: 4px;
}
/* Points popup */
.points-text {
position: absolute;
color: #fff;
font-weight: bold;
font-size: 26px;
z-index: 150;
pointer-events: none;
transform: translate(-50%, 0);
animation: float-up 1s forwards;
text-shadow: 2px 2px 0 #000;
}
/* Gas saved bonus text */
.gas-bonus {
position: absolute;
color: #00ff00;
font-weight: bold;
font-size: 24px;
z-index: 150;
pointer-events: none;
transform: translate(-50%, 0);
animation: float-up 1s forwards;
text-shadow: 2px 2px 0 #000;
}
/* Combo text */
.combo-text {
position: absolute;
color: #ffff00;
background: rgba(0, 0, 0, 0.8);
padding: 8px 15px;
border-radius: 6px;
font-weight: bold;
font-size: 22px;
z-index: 150;
pointer-events: none;
transform: translate(-50%, 0);
transition: opacity 0.5s, transform 0.5s;
border: 2px solid #fff;
box-shadow: 0 4px 8px rgba(0,0,0,0.5);
}
/* Start/End UI */
.play-btn {
background: #fff;
color: #000;
border: 4px solid #000;
padding: 15px 30px;
font-size: 32px;
font-weight: bold;
cursor: pointer;
box-shadow: 0 8px 0 #333;
transition: transform 0.1s, box-shadow 0.1s;
border-radius: 4px;
text-transform: uppercase;
font-family: 'Rubik', sans-serif;
}
.play-btn:hover {
transform: translateY(-2px);
box-shadow: 0 10px 0 #333;
}
.play-btn i {
margin-right: 10px;
}
.game-over {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #fff;
padding: 30px;
border: 8px solid #000;
text-align: center;
box-shadow: 0 10px 0 #333;
z-index: 1000;
max-width: 80%;
min-width: 300px;
border-radius: 10px;
color: #000;
}
.game-over h2 { font-size: 32px; margin-bottom: 20px; }
.game-over p { font-size: 20px; margin-bottom: 15px; }
.game-over p i {
width: 30px;
.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0