原生js实现祖玛青蛙吐珠子游戏代码

代码语言:html

所属分类:游戏

代码描述:原生js实现祖玛青蛙吐珠子游戏代码,游戏的主角是一只石青蛙,石青蛙会吐出各种颜色的珠子,珠子造型美丽,色彩鲜艳,环绕着石青蛙的是承载珠子的轨道,各种颜色的珠子沿着轨道往前滑动,石青蛙必需遏止珠子滚进轨道终点的洞穴。石青蛙吐出的珠子与轨道上的珠子相结合,颜色相同即可消失得分,当轨道上的所有珠子被消除干净时即取得游戏的胜利。

代码标签: 原生 js 祖玛 青蛙 珠子 游戏 代码

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


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

<head>

 
<meta charset="UTF-8">
 

 
<link href="https://fonts.googleapis.com/css2?family=Josefin+Sans:wght@400;500;600;700&display=swap" rel="stylesheet">
 
 
 
<style>
* {
 
margin: 0;
 
padding: 0;
 
border: 0;
 
font-size: 100%;
 
font: inherit;
 
vertical-align: baseline;
 
font-family: inherit;
 
box-sizing: border-box;
}

*[hidden] {
 
display: none;
}

body
{
 
line-height: 1;
}

menu
,
ol
,
ul
{
 
list-style: none;
}

blockquote
,
q
{
 
quotes: none;
}

blockquote:before,
blockquote:after,
q:before,
q:after {
 
content: "";
 
content: none;
}

table
{
 
border-collapse: collapse;
 
border-spacing: 0;
}

html
,
body
{
 
display: flex;
 
align-items: center;
 
justify-content: center;
 
width: 100%;
 
height: 100%;
 
background-image: radial-gradient(circle at center, #002129, #000);
 
overflow: hidden;
 
font-family: "Josefin Sans", sans-serif;
}

.container {
 
position: relative;
 
background-image: url("//repo.bfw.wiki/bfwrepo/svg/zuma/bg.svg");
}
.container::before {
 
content: "";
 
display: block;
 
width: 1287.709px;
 
height: 1004.262px;
 
background-image: url("//repo.bfw.wiki/bfwrepo/svg/zuma/bg-leaf.svg");
 
position: absolute;
 
top: -55px;
 
left: -80px;
}
.container .leaf {
 
position: absolute;
 
z-index: 10;
}
.container .leaf-01 {
 
width: 290.296px;
 
height: 197.981px;
 
background-image: url("//repo.bfw.wiki/bfwrepo/svg/zuma/bg-leaf.svg");
 
transform-origin: top left;
 
top: -10px;
 
left: -50px;
 
animation: leaf 8s -2s infinite;
}
.container .leaf-02 {
 
width: 130.828px;
 
height: 131.056px;
 
background-image: url("//repo.bfw.wiki/bfwrepo/svg/zuma/bg-leaf.svg");
 
transform-origin: top right;
 
top: -60px;
 
right: 325px;
 
animation: leaf 10s -3s infinite;
}
.container .leaf-03 {
 
width: 214.618px;
 
height: 225.252px;
 
background-image: url("//repo.bfw.wiki/bfwrepo/svg/zuma/bg-leaf.svg");
 
transform-origin: top right;
 
top: 60px;
 
right: -60px;
 
animation: leaf 5s -2s infinite;
}
.container .leaf-04 {
 
width: 303.2px;
 
height: 356.908px;
 
background-image: url("//repo.bfw.wiki/bfwrepo/svg/zuma/leaf-04.svg");
 
transform-origin: bottom left;
 
bottom: -60px;
 
left: 0px;
 
animation: leaf 7s -1s infinite;
}
.container .leaf-05 {
 
width: 253.153px;
 
height: 292.861px;
 
background-image: url("//repo.bfw.wiki/bfwrepo/svg/zuma/leaf-05.svg");
 
transform-origin: bottom right;
 
bottom: -110px;
 
right: 660px;
 
animation: leaf 9s -3s infinite;
}
.container .leaf-06 {
 
width: 269.787px;
 
height: 346.454px;
 
background-image: url("//repo.bfw.wiki/bfwrepo/svg/zuma/leaf-06.svg");
 
transform-origin: bottom right;
 
bottom: -75px;
 
right: -40px;
 
animation: leaf 15s -5s infinite;
}
.container svg {
 
opacity: 0;
 
pointer-events: none;
}
.container .player {
 
width: 175px;
 
height: 175px;
 
position: absolute;
 
top: 0;
 
left: 0;
 
z-index: 11;
}
.container .player::before {
 
content: "";
 
display: block;
 
width: 2px;
 
height: 600px;
 
margin-left: -1px;
 
position: absolute;
 
left: 50%;
 
bottom: 30px;
 
background-image: linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.5));
 
z-index: 1;
}
.container .player::after {
 
content: "";
 
display: block;
 
width: 100%;
 
height: 100%;
 
position: relative;
 
background-size: contain;
 
background-image: url("//repo.bfw.wiki/bfwrepo/svg/zuma/frog.svg");
 
z-index: 2;
}
.container .player .marble-1,
.container .player .marble-2 {
 
position: absolute;
 
z-index: 3;
}
.container .player .marble-1 {
 
width: 60px;
 
height: 60px;
 
border-radius: 100px;
 
top: -10px;
 
left: 50%;
 
transform: translateX(-50%);
}
.container .player .marble-2 {
 
width: 20px;
 
height: 20px;
 
border-radius: 100px;
 
left: 50%;
 
border: solid 5px #83be7c;
}
.container .player .marble-2:nth-child(2) {
 
top: 85px;
 
transform: translateX(calc(-50% - 30px));
}
.container .player .marble-2:nth-child(3) {
 
width: 25px;
 
height: 25px;
 
top: 105px;
 
transform: translateX(-50%);
}
.container .player .marble-2:nth-child(4) {
 
top: 85px;
 
transform: translateX(calc(-50% + 30px));
}
.container .start-hole {
 
width: 100px;
 
height: 100px;
 
border-radius: 100px;
 
background-color: black;
 
position: absolute;
 
transform: translate(-50%, -50%);
}
.container .final-hole {
 
width: 100px;
 
height: 100px;
 
border-radius: 100px;
 
background-color: rgba(0, 0, 0, 0.5);
 
position: absolute;
 
transform: translate(-50%, -50%);
}

.marble {
 
background-color: rgba(0, 0, 0, 0.5);
 
border-radius: 100px;
 
position: absolute;
 
top: 0;
 
left: 0;
 
z-index: 2;
}

.shadow {
 
width: 100%;
 
height: 100%;
 
position: absolute;
 
top: 0;
 
left: 0;
 
background-image: radial-gradient(circle at center, rgba(0, 33, 41, 0), rgba(0, 0, 0, 0.8));
 
z-index: 20;
 
pointer-events: none;
}
.shadow::before {
 
content: "";
 
display: block;
 
width: 100%;
 
height: 100%;
 
background-image: url("//repo.bfw.wiki/bfwrepo/image/5dfd8574f13f0.png");
 
position: absolute;
 
opacity: 0.1;
}

.github {
 
width: 50px;
 
height: 50px;
 
border-radius: 100px;
 
position: absolute;
 
top: 40px;
 
right: 40px;
 
background-color: rgba(255, 255, 255, 0.5);
}
.github a {
 
display: flex;
 
align-items: center;
 
justify-content: center;
 
width: 100%;
 
height: 100%;
 
color: #002129;
 
font-size: 30px;
 
font-weight: bold;
 
text-decoration: none;
}

.score {
 
position: absolute;
 
bottom: 40px;
 
right: 40px;
 
color: #fff;
 
text-align: right;
}
.score .title {
 
font-size: 16px;
}
.score .num {
 
font-size: 90px;
}

.popup-container {
 
display: flex;
 
align-items: center;
 
justify-content: center;
 
width: 100%;
 
height: 100%;
 
color: #002129;
 
position: absolute;
 
top: 0;
 
left: 0;
 
z-index: 19;
 
pointer-events: none;
}
.popup-container .popup {
 
min-width: 300px;
 
padding: 50px 40px 30px;
 
border-radius: 30px;
 
opacity: 0;
 
background-color: rgba(255, 255, 255, 0.8);
 
position: absolute;
 
transform: translateY(20px);
 
transition: 0.2s;
 
pointer-events: none;
 
z-index: 1;
}
.popup-container .popup::after {
 
content: "";
 
display: block;
 
width: calc(100% - 20px);
 
height: calc(100% - 20px);
 
border: solid 5px #002129;
 
border-radius: 30px;
 
position: absolute;
 
top: 50%;
 
left: 50%;
 
transform: translate(-50%, -50%);
 
pointer-events: none;
}
.popup-container .popup .title {
 
font-size: 30px;
 
text-align: center;
 
font-weight: 700;
 
margin-bottom: 20px;
 
letter-spacing: 1px;
}
.popup-container .popup .info {
 
font-size: 16px;
 
color: #002129;
 
text-align: center;
}
.popup-container .popup .info ul {
 
list-style-type: disc;
 
padding-left: 1em;
 
text-align-last: left;
}
.popup-container .popup .info ul li {
 
margin-top: 10px;
}
.popup-container .popup .info .num {
 
font-size: 24px;
 
font-weight: bold;
}
.popup-container .popup .button-container {
 
display: flex;
 
flex-direction: column;
 
justify-content: center;
 
align-items: center;
 
align-content: center;
 
margin-top: 30px;
}
.popup-container .popup .button-container .button {
 
font-size: 20px;
 
font-weight: 500;
 
color: #fff;
 
font-size: 16px;
 
text-align: center;
 
letter-spacing: 1px;
 
background-color: #002129;
 
border-radius: 100px;
 
padding: 15px 30px 10px;
 
cursor: pointer;
}
.popup-container .popup .button-container .button.button-2 {
 
padding: 0;
 
margin-top: 15px;
 
font-size: 14px;
 
font-weight: bold;
 
color: #002129;
 
background-color: transparent;
}
.popup-container .popup.active {
 
opacity: 1;
 
transform: translateY(0px);
 
pointer-events: auto;
}
.popup-container .popup.active ~ .mask {
 
opacity: 1;
}
.popup-container .mask {
 
width: 100%;
 
height: 100%;
 
background-color: rgba(0, 0, 0, 0.5);
 
position: absolute;
 
top: 0;
 
left: 0;
 
opacity: 0;
 
transition: 0.5s;
 
pointer-events: none;
}

@keyframes leaf {
 
0% {
   
transform: rotate(0deg);
 
}
 
50% {
   
transform: rotate(10deg);
 
}
 
100% {
   
transform: rotate(0deg);
 
}
}
</style>



</head>

<body >
 
<div class="shadow"></div>

<div id="score" class="score">
       
<div class="title">SCORE</div>
       
<div class="num">0</div>
</div>
<div class="popup-container">
       
<div id="start" class="popup active">
               
<div class="title">HELLO !</div>
               
<div class="info">
                       
<ul>
                               
<li>LEFT CLICK TO SHOOT MARBLE</li>
                               
<li>PRESS "SPACE" TO SWITCH THE MARBLE COLOR</li>
                               
<li>PRESS "ESC" TO STOP</li>
                       
</ul>
               
</div>
               
<div class="button-container">
                       
<div class="button">START</div>
               
</div>
       
</div>
       
<div id="stop" class="popup">
               
<div class="title">HELLO !</div>
               
<div class="info">
                        YOOOOU JUSSSSSST NEED A BRRRRRRREAK !
               
</div>
               
<div class="button-container">
                       
<div id="start-btn" class="button">START</div>
                       
<div id="reset-btn" class="button button-2">RESTART</div>
               
</div>
       
</div>
       
<div id="final" class="popup">
               
<div class="title">HELLO !</div>
               
<div class="info">
                        YOU GOT
<span class="num"></span> SCORES !
               
</div>
               
<div class="button-container">
                       
<div class="button">RESTART</div>
               
</div>
       
</div>
       
<div class="mask"></div>
</div>

 
     
<script >
"use strict";
const OneFrameTime = 17;
const createDiv = (classList, children = []) => {
    const div = document.createElement("div");
    div.classList.add(...classList);
    children.forEach((ele) => {
        div.appendChild(ele);
    });
    return div;
};
const createElementNS = (name, attr) => {
    const xmlns = "http://www.w3.org/2000/svg";
    const elementNS = document.createElementNS(xmlns, name);
    Object.keys(at.........完整代码请登录后点击上方下载按钮下载查看

网友评论0