原生js+css实现鼠标抓住移动闪烁的小点游戏代码

代码语言:html

所属分类:游戏

代码描述:原生js+css实现鼠标抓住移动闪烁的小点游戏代码

代码标签: 原生 js css 鼠标 抓住 移动 闪烁 小点 游戏 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  

  
  
  
<style>
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
}

:root {
    --primary-color: #f0d6e8;
    --secondary-color: #c1e8f8;
    --accent-color: #a5b9ea;
    --dark-accent: #9985c9;
    --warning-color: #ff96ad;
    --success-color: #96ffbc;
    --background-dark: #2a2e45;
    --background-light: #3d4263;
    --text-color: #e0e5ff;
    --health-good: #96ffbc;
    --health-mid: #fff596;
    --health-low: #ff96ad;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Cyberpunk', sans-serif;
    background-color: var(--background-dark);
    cursor: none;
}

.game-container {
    position: relative;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--background-dark), var(--background-light));
    overflow: hidden;
}

.game-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        linear-gradient(90deg, rgba(26, 29, 48, 0.3) 1px, transparent 1px),
        linear-gradient(rgba(26, 29, 48, 0.3) 1px, transparent 1px),
        linear-gradient(0deg, rgba(90, 100, 150, 0.1) 1px, transparent 1px),
    background-size: 
        50px 50px, 
        50px 50px, 
        50px 50px,
        200px 200px;
    opacity: 0.6;
    z-index: 0;
    animation: backgroundPulse 10s infinite alternate;
}

@keyframes backgroundPulse {
    0% {
        background-position: 
            0 0,
            0 0,
            0 0,
            0 0;
    }
    100% {
        background-position: 
            20px 0,
            0 20px,
            -20px 0,
            40px 40px;
    }
}

.game-container::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        radial-gradient(circle at 50% 50%, var(--secondary-color) 0%, transparent 8%),
        linear-gradient(90deg, transparent 95%, var(--accent-color) 95%),
        linear-gradient(0deg, transparent 95%, var(--accent-color) 95%);
    background-size: 300px 300px, 100px 100px, 100px 100px;
    z-index: 0;
    opacity: 0.15;
    animation: circuitPulse 15s infinite linear;
}

@keyframes circuitPulse {
    0% {
        opacity: 0.05;
        background-position: 0 0, 0 0, 0 0;
    }
    50% {
        opacity: 0.2;
    }
    100% {
        opacity: 0.05;
        background-position: 300px 300px, 100px 100px, 100px 100px;
    }
}

.health-container {
    position: absolute;
    top: 5vh;
    left: 50%;
    transform: translateX(-50%);
    width: 40vw;
    z-index: 10;
    text-align: center;
}

.health-bar {
    height: 3vh;
    width: 100%;
    background-color: rgba(30, 34, 59, 0.7);
    border-radius: 15px;
    padding: 3px;
    box-shadow: 
        0 0 0 2px rgba(255, 255, 255, 0.1),
        0 0 10px rgba(0, 0, 0, 0.3),
        inset 0 0 15px rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
}

.health-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--health-good), var(--success-color));
    border-radius: 12px;
    transition: width 0.3s ease, background 0.5s ease;
    position: relative;
    box-shadow: 0 0 10px var(--health-good);
}

.health-fill::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    animation: healthPulse 2s infinite;
}

@keyframes healthPulse {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.health-text {
    margin-top: 1vh;
    font-size: 2vh;
    font-weight: bold;
    color: var(--text-color);
    text-shadow: 0 0 5px var(--primary-color), 0 0 10px var(--accent-color);
    letter-spacing: 2px;
}

.glitch-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
    pointer-events: none;
}

.glitch-entity {
    position: absolute;
    width: 4vmin;
    height: 4vmin;
    background-color: var(--accent-color);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 
        0 0 15px var(--accent-color),
        0 0 25px var(--secondary-color);
    pointer-events: all;
    z-index: 5;
    transition: background-color 0.3s ease;
}

.glitch-entity::before, 
.glitch-entity::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-color: transparent;
    border: 2px solid var(--secondary-color);
    transform: translate(-50%, -50%) scale(1);
    animation: glitchPulse 2s infinite;
    opacity: 0.7;
}

.glitch-entity::after {
    animation-delay: 1s;
}

@keyframes glitchPulse {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.7;
    }
    100% {
        transform: translate(-50%, -50%) scale(1.8);
        opacity: 0;
    }
}

.glitch-entity::before {
    filter: blur(5px);
}

.glitch-entity {
    overflow: hidden;
    animation: glitchEffect 0.5s infinite alternate;
}

@keyframes glitchEffect {
    0% {
        clip-path: polygon(
            0% 0%, 100% 0%, 100% 100%, 0% 100%
        );
        background-color: var(--accent-color);
    }
    10% {
        clip-path: polygon(
            5% 10%, 100% 5%, 95% 95%, 0% 90%
        );
        background-color: var(--secondary-color);
    }
    20% {
        clip-path: polygon(
            0% 15%, 90% 0%, 100% 90%, 10% 100%
        );
    }
    30% {
        clip-path: polygon(
            0% 0%, 100% 0%, 100% 100%, 0% 100%
        );
        background-color: var(--dark-accent);
    }
    40% {
        clip-path: polygon(
            20% 5%, 95% 10%, 90% 80%, 5% 95%
        );
    }
    50% {
        clip-path: polygon(
            0% 0%, 100% 0%, 100% 100%, 0% 100%
        );
        background-color: var(--primary-color);
    }
}

.score-container {
    position: absolute;
    top: 5vh;
    right: 5vw;
    z-index: 10;
    font-size: 2.5vh;
    color: var(--text-color);
    text-shadow: 0 0 5px var(--accent-color);
    background-color: rgba(30, 34, 59, 0.7);
    padding: 1vh 2vw;
    border-radius: 15px;
    border: 1px solid var(--accent-color);
    box-shadow: 0 0 15px rgba(165, 185, 234, 0.3);
}

.score-value {
    font-weight: bold;
    color: var(--primary-color);
    margin-left: 0.5vw;
}

.custom-cursor {
    position: fixed;
    width: 20vmin;
    height: 20vmin;
    border-radius: 50%;
    border: 2px dashed var(--primary-color);
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 1000;
    transition: transform 0.05s ease;
    box-shadow: 0 0 10px var(--primary-color);
}

.custom-cursor::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 85%;
    height: 85%;
    border-radius: 50%;
    border: 1px dashed var(--secondary-color);
    transform: translate(-50%, -50%);
    opacity: 0.7;
    animation: netRotate 10s linear infinite;
}

.custom-cursor::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 70%;
    height: 70%;
    border-radius: 50%;
    border: 1px solid var(--accent-color);
    transform: translate(-50%, -50%);
    opacity: 0.5;
}

@keyframes netRotate {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

.custom-c.........完整代码请登录后点击上方下载按钮下载查看

网友评论0