js实现恐龙大冒险游戏代码

代码语言:html

所属分类:游戏

代码描述:js实现恐龙大冒险游戏代码,游戏玩法 收集

代码标签: js 恐龙 大冒险 游戏 代码

下面为部分代码预览,完整代码请点击下载或在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;
        }
        
        body {
            background: linear-gradient(180deg, #87CEEB 0%, #98D8C8 60%, #90EE90 100%);
            overflow: hidden;
            font-family: 'Arial Rounded MT Bold', Arial, sans-serif;
            user-select: none;
        }
        
        #gameContainer {
            width: 100vw;
            height: 100vh;
            position: relative;
        }
        
        canvas {
            display: block;
            width: 100%;
            height: 100%;
        }
        
        #ui {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            pointer-events: none;
        }
        
        #scoreBoard {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 15px 25px;
            background: rgba(255,255,255,0.25);
            backdrop-filter: blur(10px);
            border-bottom: 3px solid rgba(255,255,255,0.5);
        }
        
        .score-item {
            text-align: center;
            color: #2d5a1b;
            text-shadow: 2px 2px 0px rgba(255,255,255,0.8);
        }
        
        .score-label {
            font-size: 12px;
            font-weight: bold;
            text-transform: uppercase;
            letter-spacing: 1px;
        }
        
        .score-value {
            font-size: 28px;
            font-weight: bold;
            color: #ff6b35;
            text-shadow: 3px 3px 0px rgba(0,0,0,0.2);
        }
        
        #healthBar {
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        .heart {
            font-size: 24px;
            transition: transform 0.3s;
        }
        
        .heart.lost {
            filter: grayscale(1);
            opacity: 0.4;
        }
        
        #startScreen, #gameOverScreen, #levelUpScreen {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            background: rgba(0,0,0,0.4);
            backdrop-filter: blur(8px);
            z-index: 100;
        }
        
        .screen-card {
            background: linear-gradient(135deg, #fff9e6, #fff);
            border-radius: 30px;
            padding: 50px 60px;
            text-align: center;
            box-shadow: 0 20px 60px rgba(0,0,0,0.3),
                        inset 0 2px 0 rgba(255,255,255,0.8);
            border: 4px solid #ffd700;
            max-width: 500px;
            width: 90%;
            animation: cardBounce 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
        }
        
        @keyframes cardBounce {
            from { transform: scale(0.5); opacity: 0; }
            to { transform: scale(1); opacity: 1; }
        }
        
        .screen-title {
            font-size: 52px;
            margin-bottom: 10px;
            animation: titleFloat 2s ease-in-out infinite;
        }
        
        @keyframes titleFloat {
            0%, 100% { transform: translateY(0); }
            50% { transform: translateY(-10px); }
        }
        
        .screen-subtitle {
            font-size: 22px;
            color: #ff6b35;
            font-weight: bold;
            margin-bottom: 20px;
            text-shadow: 2px 2px 0 rgba(0,0,0,0.1);
        }
        
        .screen-desc {
            font-size: 14px;
            color: #666;
            margin-bottom: 30px;
            line-height: 1.8;
        }
        
        .btn {
            background: linear-gradient(135deg, #ff6b35, #ff4500);
            color: white;
            border: none;
            padding: 18px 50px;
            font-size: 22px;
            font-weight: bold;
            border-radius: 50px;
            cursor: pointer;
            box-shadow: 0 8px 0 #cc3300,
                        0 10px 20px rgba(255,107,53,0.4);
            transition: all 0.1s;
            pointer-events: all;
            font-family: inherit;
            letter-spacing: 1px;
        }
        
        .btn:hover {
            background: linear-gradient(135deg, #ff7f50, #ff5500);
            transform: translateY(-3px);
            box-shadow: 0 11px 0 #cc3300, 0 13px 25px rgba(255,107,53,0.4);
        }
        
        .btn:active {
            transform: translateY(5px);
            box-shadow: 0 3px 0 #cc3300, 0 5px 10px rgba(255,107,53,0.4);
        }
        
        .btn-secondary {
            background: linear-gradient(135deg, #4CAF50, #388E3C);
            box-shadow: 0 8px 0 #2E7D32, 0 10px 20px rgba(76,175,80,0.4);
            margin-top: 15px;
        }
        
        .btn-secondary:hover {
            box-shadow: 0 11px 0 #2E7D32, 0 13px 25px rgba(76,175,80,0.4);
        }
        
        .btn-secondary:active {
            box-shadow: 0 3px 0 #2E7D32, 0 5px 10px rgba(76,175,80,0.4);
        }
        
        #controls {
            position: absolute;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            display: flex;
            gap: 15px;
            pointer-events: all;
            z-index: 50;
        }
        
        .ctrl-btn {
            width: 70px;
            height: 70px;
            background: rgba(255,255,255,0.85);
            border: 3px solid rgba(255,255,255,0.9);
            border-radius: 50%;
            font-size: 28px;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            box-shadow: 0 6px 0 rgba(0,0,0,0.2), 0 8px 20px rgba(0,0,0,0.15);
            transition: all 0.1s;
            -webkit-tap-highlight-color: transparent;
        }
        
        .ctrl-btn:active {
            transform: translateY(4px);
            box-shadow: 0 2px 0 rgba(0,0,0,0.2), 0 3px 10px rgba(0,0,0,0.15);
        }
        
        #jumpBtn {
            width: 90px;
            height: 90px;
            font-size: 36px;
            background: linear-gradient(135deg, rgba(255,215,0,0.9), rgba(255,165,0,0.9));
        }
        
        #levelUpScreen { display: none; }
        #gameOverScreen { display: none; }
        
        .stars {
            font-size: 40px;
            letter-spacing: 5px;
            margin: 15px 0;
        }
        
        .level-badge {
            background: linear-gradient(135deg, #ffd700, #ff8c00);
            color: white;
            padding: 8px 25px;
            border-radius: 20px;
            font-size: 18px;
            font-weight: bold;
            display: inline-block;
            margin: 10px 0;
            box-shadow: 0 4px 10px rgba(255,140,0,0.4);
        }
        
        #coinEffect {
            position: absolute;
            pointer-events: none;
            z-index: 200;
        }
        
        .floating-text {
            position: absolute;
            font-size: 24px;
            font-weight: bold;
            color: #ffd700;
            text-shadow: 2px 2px 0 rgba(0,0,0,0.3);
            animation: floatUp 1s ease-out forwards;
            pointer-events: none;
        }
        
        @keyframes floatUp {
            0% { transform: translateY(0) scale(1); opacity: 1; }
            100% { transform: translateY(-80px) scale(1.5); opacity: 0; }
        }
        
        #instructions {
            position: absolute;
            bottom: 110px;
            left: 50%;
            transform: translateX(-50%);
            color: white;
            font-size: 13px;
            text-shadow: 1px 1px 3px rgba(0,0,0,0.5);
            text-align: center;
            pointer-events: none;
            white-space: nowrap;
        }
        
        .power-up-indicator {
            position: absolute;
            top: 80px;
            right: 20px;
            background: rgba(255,255,255,0.3);
            border-radius: 15px;
            padding: 8px 15px;
            color: white;
            font-weight: bold;
            font-size: 14px;
            display: none;
            pointer-events: none;
            animation: pulse 1s ease-in-out infinite;
        }
        
        @keyframes pulse {
            0%, 100% { transform: scale(1); }
            50% { transform: scale(1.05); }
        }
    </style>
</head>
<body>
<div id="gameContainer">
    <canvas id="gameCanvas"></canvas>
    
    <div id="ui">
        <div id="scoreBoard">
            <div class="score-item">
                <div class="score-label">🦕 恐龙冒险</div>
            </div>
            <div class="score-item">
                <div class="score-label">💎 宝石</div>
                <div class="score-value" id="scoreDisplay">0</div>
            </div>
            <div class="score-item">
                <div class="score-label">🏆 最高分</div>
                <div class="score-value" id="highScoreDisplay">0</div>
            </div>
            <div class="score-item">
                <div class="score-label">🌟 关卡</div>
                <div class="score-value" id="levelDisplay">1</div>
            </div>
            <div class="score-item">
                <div id="healthBar">
                    <span class="heart" id="h1">❤️</span>
                    <span class="heart" id="h2">❤️</span>
                    <span class="heart" id="h3">❤️</span>
                </div>
            </div>
        </div>
        <div class="power-up-indicator" id="powerUpIndicator">⚡ 无敌状态!</div>
    </div>
    
    <div id="startScreen">
        <div class="screen-card">
            <div class="screen-title">🦕</div>
           .........完整代码请登录后点击上方下载按钮下载查看

网友评论0