jquery+TweenMax实现一个变色弹球跳台阶小游戏代码
代码语言:html
所属分类:其他
代码描述:jquery+TweenMax实现一个变色弹球跳台阶小游戏代码,基于jQuery和TweenMax技术构建的网页小游戏,名为“变色弹球跳台阶”。游戏中,玩家控制一个不断改变颜色的弹跳球,通过点击屏幕上的栏杆来切换球的颜色,使其与栏杆的颜色匹配。玩家需要精准地点击栏杆,确保球在跳跃过程中始终与栏杆颜色一致,以顺利通过每一级台阶。这款游戏结合了颜色识别和反应速度的挑战,为玩家提供了一种既有趣又具挑战性的娱乐体验。
代码标签: jquery TweenMax 变色 弹球 跳 台阶 小 游戏 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>变色弹球跳台阶</title> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <meta property="og:site_name" content="CodePen"> <meta property="og:description" content="A game made to inspire developers to use GSAP, ES6 and Flexbox"> <style> .bubble { border-radius: 50%; position: absolute; background-color: rgba(0, 0, 0, 0.12); border-color: rgba(0, 0, 0, 0.12); border-width: 4px; } .bubble-1 { height: 15px; width: 15px; top: 21px; left: 59px; } .bubble-2 { height: 27px; width: 27px; top: 36px; left: 16px; } .bubble-3 { height: 21px; width: 21px; top: 63px; left: 49px; } .bubble-4 { height: 15px; width: 15px; top: 98px; left: 37px; } .bubble-5 { height: 5px; width: 5px; top: 116px; left: 20px; background-color: transparent; border-style: solid; } .bubble-6 { height: 6px; width: 6px; top: 128px; left: 63px; } .bubble-7 { height: 27px; width: 27px; top: 150px; left: 52px; } .bubble-8 { height: 19px; width: 19px; top: 154px; left: 18px; } .bubble-9 { height: 10px; width: 10px; top: 189px; left: 13px; } .bubble-10 { height: 5px; width: 5px; top: 199px; left: 52px; background-color: transparent; border-style: solid; } .bubble-11 { height: 21px; width: 21px; top: 220px; left: 29px; } .bubble-12 { height: 21px; width: 21px; top: 263px; left: 48px; } .bubble-13 { height: 5px; width: 5px; top: 275px; left: 16px; background-color: transparent; border-style: solid; } .bubble-14 { height: 15px; width: 15px; top: 296px; left: 34px; } .triangle { position: absolute; background-color: rgba(0, 0, 0, 0.12); border-color: rgba(0, 0, 0, 0.12); } .triangle-1 { border-radius: 50%; position: absolute; background-color: rgba(0, 0, 0, 0.12); border-color: rgba(0, 0, 0, 0.12); border-width: 4px; height: 10px; width: 10px; top: 22px; left: 55px; } .triangle-2 { border-left: 8px solid transparent; border-right: 8px solid transparent; border-bottom: 14px solid rgba(0, 0, 0, 0.12); background-color: transparent; left: 15px; top: 27px; } .triangle-2:after { content: " "; display: block; position: absolute; border-left: 3px solid transparent; border-right: 3px solid transparent; border-bottom: 5px solid transparent; top: 6px; left: -3.5px; transition: border-bottom-color 0.4s ease; } .red .triangle-2:after { border-bottom-color: #fc5c82; } .yellow .triangle-2:after { border-bottom-color: #fcd45c; } .purple .triangle-2:after { border-bottom-color: #9174f5; } .triangle-3 { border-left: 12px solid transparent; border-right: 12px solid transparent; border-bottom: 19px solid rgba(0, 0, 0, 0.12); background-color: transparent; left: 43px; top: 60px; } .triangle-3:after { content: " "; display: block; position: absolute; border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 9px solid transparent; top: 6px; left: -4.75px; transition: border-bottom-color 0.4s ease; } .red .triangle-3:after { border-bottom-color: #fc5c82; } .yellow .triangle-3:after { border-bottom-color: #fcd45c; } .purple .triangle-3:after { border-bottom-color: #9174f5; } .triangle-4 { border-radius: 50%; position: absolute; background-color: rgba(0, 0, 0, 0.12); border-color: rgba(0, 0, 0, 0.12); border-width: 3px; height: 8px; width: 8px; top: 61px; left: 17px; background-color: transparent; border-style: solid; } .triangle-5 { border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 8px solid rgba(0, 0, 0, 0.12); background-color: transparent; left: 25px; top: 101px; transform: rotate(180deg); } .triangle-6 { border-left: 4px solid transparent; border-right: 4px solid transparent; border-bottom: 6px solid rgba(0, 0, 0, 0.12); background-color: transparent; left: 60px; top: 103px; transform: rotate(-90deg); } .triangle-7 { border-left: 12.5px solid transparent; border-right: 12.5px solid transparent; border-bottom: 19px solid rgba(0, 0, 0, 0.12); background-color: transparent; left: 17px; top: 126px; transform: rotate(180deg); } .triangle-8 { border-left: 10.5px solid transparent; border-right: 10.5px solid transparent; border-bottom: 16px solid rgba(0, 0, 0, 0.12); background-color: transparent; left: 50px; top: 149px; } .triangle-9 { border-left: 5.5px solid transparent; border-right: 5.5px solid transparent; border-bottom: 8px solid rgba(0, 0, 0, 0.12); background-color: transparent; left: 21px; top: 177px; } .triangle-10 { border-radius: 50%; position: absolute; background-color: rgba(0, 0, 0, 0.12); border-color: rgba(0, 0, 0, 0.12); border-width: 4px; height: 10px; width: 10px; top: 177px; left: 60px; } .triangle-11 { border-left: 9px solid transparent; border-right: 9px solid transparent; border-bottom: 13px solid rgba(0, 0, 0, 0.12); background-color: transparent; left: 33px; top: 213px; transform: rotate(180deg); } .triangle-12 { border-radius: 50%; position: absolute; background-color: rgba(0, 0, 0, 0.12); border-color: rgba(0, 0, 0, 0.12); border-width: 2px; height: 10px; width: 10px; top: 233px; left: 65px; background-color: transparent; border-style: solid; } .triangle-13 { border-radius: 50%; position: absolute; background-color: rgba(0, 0, 0, 0.12); border-color: rgba(0, 0, 0, 0.12); border-width: 4px; height: 10px; width: 10px; top: 250px; left: 22px; } .triangle-14 { border-left: 8px solid transparent; border-right: 8px solid transparent; border-bottom: 14px solid rgba(0, 0, 0, 0.12); background-color: transparent; left: 45px; top: 270px; transform: rotate(180deg); } .triangle-14:after { content: " "; display: block; position: absolute; border-left: 3px solid transparent; border-right: 3px solid transparent; border-bottom: 5px solid transparent; top: 6px; left: -3.5px; transition: border-bottom-color 0.4s ease; } .red .triangle-14:after { border-bottom-color: #fc5c82; } .yellow .triangle-14:after { border-bottom-color: #fcd45c; } .purple .triangle-14:after { border-bottom-color: #9174f5; } .stick .block { position: absolute; overflow: hidden; z-index: 999; border-radius: 7px; } .stick .block .inner { border-radius: 7px; background-color: rgba(0, 0, 0, 0.12); border-color: rgba(0, 0, 0, 0.12); border-width: 3px; height: 100%; width: 100%; position: absolute; } .stick .block:nth-child(2n+1) .inner-2 { left: -200%; } .stick .block:nth-child(2n+2) .inner-2 { left: 200%; } .stick .block-1 { height: 16px; width: 31px; top: 16px; left: 30px; } .stick .block-1 .inner { background-color: transparent !important; border-style: solid; box-sizing: border-box; } .stick .block-2 { height: 14px; width: 42px; top: 50px; left: 15px; } .stick .block-3 { height: 18px; width: 9px; top: 73px; left: 64px; } .stick .block-4 { height: 9px; width: 14px; top: 84px; left: 26px; } .stick .block-5 { height: 15px; width: 15px; top: 109px; left: 45px; } .stick .block-5 .inner { border-radius: 50%; } .stick .block-6 { height: 9px; width: 27px; top: 135px; left: 19px; } .stick .block-7 { height: 12px; width: 12px; top: 144px; left: 60px; } .stick .block-7 .inner { border-radius: 50%; border-style: solid; box-sizing: border-box; background-color: transparent; } .stick .block-8 { height: 27px; width: 14px; top: 164px; left: 24px; } .stick .block-9 { height: 8px; width: 8px; top: 188px; left: 64px; } .stick .block-10 { height: 12px; width: 22px; top: 219px; left: 11px; } .stick .block-10 .inner { background-color: transparent !important; border-style: solid; box-sizing: border-box; } .stick .block-11 { height: 22px; width: 22px; top: 226px; left: 50px; } .stick .block-11 .inner { border-radius: 50%; } .stick .block-12 { height: 18px; width: 9px; top: 248px; left: 26px; } .stick .block-13 { height: 8px; width: 8px; top: 278px; left: 50px; } .stick .block-13 .inner { border-radius: 50%; } .stick .block-14 { height: 12px; width: 22px; top: 297px; left: 18px; } .stick .block-14 .inner { background-color: transparent !important; border-style: solid; box-sizing: border-box; } .stick .block-15 { height: 9px; width: 27px; top: 307px; left: 48px; } body { background-color: #28DAD4; margin: 0; padding: 0; overflow: hidden; font-family: 'Roboto', sans-serif; } a { cursor: url(//repo.bfw.wiki/bfwrepo/images/ballgame/cursor.svg), pointer; } a:focus, a:active { cursor: url(//repo.bfw.wiki/bfwrepo/images/ballgame/cursor-tap.svg), pointer; } .container { position: fixed; left: 0; top: 0; height: 100%; width: 100%; } .waves, .mounts { position: absolute; width: 100%; left: 0; bottom: 0; } .waves div, .mounts div { position: absolute; width: 100%; } .clouds { position: absolute; width: 100%; left: 0; top: 77px; height: 151px; background: url(//repo.bfw.wiki/bfwrepo/images/ballgame/clouds.svg) repeat-x; background-position-x: 170px; } .top_wave { background: url(//repo.bfw.wiki/bfwrepo/images/ballgame/top_wave.png) repeat-x 0 -1px; height: 35px; bottom: 0; z-index: 10001; } .wave1 { background: url(//repo.bfw.wiki/bfwrepo/images/ballgame/wave1.svg) repeat-x; height: 150px; bottom: 0; z-index: 23; } .wave2 { background: url(//repo.bfw.wiki/bfwrepo/images/ballgame/wave2.svg) repeat-x; height: 180px; bottom: 30px; z-index: 22; } .wave3 { background: url(//repo.bfw.wiki/bfwrepo/images/ballgame/wave3.svg) repeat-x; height: 180px; bottom: 90px; z-index: 21; } .wave4 { background: url(//repo.bfw.wiki/bfwrepo/images/ballgame/wave4.svg) repeat-x; height: 180px; bottom: 120px; z-index: 20; } .mount1 { background: url(//repo.bfw.wiki/bfwrepo/images/ballgame/mount1.svg) repeat-x; height: 150px; bottom: 280px; z-index: 11; } .mount2 { background: url(//repo.bfw.wiki/bfwrepo/images/ballgame/mount2.svg) repeat-x; height: 150px; bottom: 290px; z-index: 10; } .noise { position: fixed; width: 100%; height: 100%; left: 0; top: 0; z-index: 1010; background: url(//repo.bfw.wiki/bfwrepo/images/ballgame/noise.png); } .glow { position: absolute; left: -350px; top: -350px; width: 800px; height: 800px; background-color: rgba(81, 237, 200, 0.34); border-radius: 50%; box-shadow: 0 0 100px 100px rgba(81, 237, 200, 0.34); z-index: 1010; } .sun { position: relative; left: 50%; top: 50%; width: 1px; height: 1px; background-color: #ffe345; border-radius: 50%; box-shadow: 0 0 32px 32px #ffe345, 0 0 150px 150px rgba(103, 244, 210, 0.4); } .small-glow { z-index: 99; width: 12px; height: 12px; border-radius: 50%; position: absolute; background-color: rgba(255, 255, 255, 0.34); box-shadow: 0 0 1px 1px rgba(255, 255, 255, 0.34); } .small-glow.yellow { background-color: rgba(255, 227, 69, 0.34); box-shadow: 0 0 4px 4px rgba(255, 227, 69, 0.34); } .sticks { z-index: 1011; outline: none; -webkit-tap-highlight-color: transparent; } .stick { height: 362px; width: 90px; border-radius: 14px; background-image: url(//repo.bfw.wiki/bfwrepo/images/ballgame/noise.png); position: relative; overflow: hidden; float: left; margin-right: 90px; transition: background-color 0.4s ease; cursor: url(//repo.bfw.wiki/bfwrepo/images/ballgame/cursor.svg), pointer; } .stick:focus, .stick:active { cursor: url(//repo.bfw.wiki/bfwrepo/images/ballgame/cursor-tap.svg), pointer; } .stick.red { background-color: #FF4571; } .stick.yellow { background-color: #FFD145; } .stick.purple { background-color: #8260F6; } .stick.inactive { background-color: #4C4660; } .ball, .ball-demo { background: url(//repo.bfw.wiki/bfwrepo/images/ballgame/ball.svg) right bottom; background-size: 64px 64px; width: 53px; height: 53px; z-index: 1011; background-color: #FF4571; border-radius: 50%; } .ball { margin-bottom: 250px; } .controls { z-index: 999999; position: relative; } .game-full-flex { position: fixed; display: none; flex-direction: column; justify-content: space-between; align-items: center; width: 100%; height: 100%; top: 0; left: 0; z-index: 9998; } .start-game .start-game-top { min-height: 20%; } .start-game .start-game-top .play-full-page { display: none; border: 3px solid #fff; border-radius: 100px; color: #fff; width: 260px; height: 50px; font-size: 28px; text-align: center; font-weight: 900; letter-spacing: -1px; line-height: 52px; text-decoration: none; text-transform: uppercase; margin-top: 24px; } .start-game .start-game-top .play-full-page:hover { opacity: 0.7; } .start-game .logo-holder { width: 513px; height: 162px; background-color: #4C4660; border: 4px solid #FF4571; border-radius: 68px; text-align: center; margin-top: -10%; } .start-game .logo-holder .logo { color: #fff; text-transform: uppercase; font-weight: 900; font-size: 60px; letter-spacing: -0.1em; margin-top: 10px; margin-bottom: 4px; text-align: center; } .start-game .logo-holder .logo span { margin-left: -8px; margin-right: -8px; } .start-game .logo-holder .play-button { display: inline-block; background-color: #FF4571; border: 4px solid #fff; border-radius: 100px; color: #fff; width: 200px; height: 56px; font-size: 42px; text-align: center; font-weight: 900; letter-spacing: -3px; line-height: 56px; text-decoration: none; } .start-game .logo-holder .play-button:hover { background-color: #ff5f84; } .start-game .logo-holder .hint { color: #fff; font-size: 20px; } .start-game .logo-holder .hint span { color: #FF4571; } .start-game .how-to-play { display: flex; justify-content: space-around; width: 100%; } .start-game .how-to-play .section-1, .start-game .how-to-play .section-3 { flex: 1; } .start-game .how-to-play .section-1 .content, .start-game .how-to-play .section-3 .content { justify-content: center; } .start-game .how-to-play h4 { color: #fff; font-weight: 400; font-size: 22px; text-align: center; } .start-game .how-to-play .content { height: 200px; position: relative; display: flex; justify-content: space-around; } .start-game .how-to-play .bar { width: 60px; border-radius: 7px; margin-top: auto; transition: background-color 0.4s ease; } .start-game .how-to-play .bar.bar-1 { height: 180px; background: #FF4571; } .start-game .how-to-play .bar.bar-2 { height: 120px; background: #FFD145; } .start-game .how-to-play .bar.bar-3 { height: 150px; background: #4C4660; } .start-game .how-to-play .section-2 .bar { cursor: url(//repo.bfw.wiki/bfwrepo/images/ballgame/cursor.svg), pointer; } .start-game .how-to-play .section-2 .bar:focus, .start-game .how-to-play .section-2 .bar:active { cursor: url(//repo.bfw.wiki/bfwrepo/images/ballgame/cursor-tap.svg), pointer; } .start-game .how-to-play .section-3 .ball-demo { background-color: #815FF8; } .start-game .how-to-play .section-3 .bar-1 { height: 120px; background-color: #815FF8; } .stop-game { justify-content: center; } .stop-game .score-container { background-color: #4C4660; width: 433px; height: 386px; border-radius: 38px; text-align: center; } .stop-game .score-container h1 { color: #fff; text-transform: uppercase; letter-spacing: -0.1em; margin-top: 20px; margin-bottom: 4px; font-size: 64px; } .stop-game .score-container .final-score { color: #FFE345; font-weight: 900; font-size: 130px; letter-spacing: -6px; line-height: 110px; } .stop-game .score-container .result { color: #FF4571; text-transform: uppercase; font-weight: 700; font-size: 30px; } .stop-game .score-container h4 { color: #fff; margin-top: 12px; } .stop-game .score-container .tweet { background: #fff; padding: 8px 20px; border-radius: 4px; color: #55ACEE; text-decoration: none; font-size: 18px; line-height: 24px; display: inline-block; } .stop-game .score-container .tweet:hover { background-color: #55ACEE; color: #fff; } .stop-game .score-container .tweet i { font-size: 24px; top: 2px; right: 2px; position: relative; } .stop-game .score-container .play-again { background-color: #FF4571; border: 2px solid #fff; color: #fff; text-decoration: none; text-transform: uppercase; font-weight: 900; letter-spacing: -1px; font-size: 26px; padding: 6px 24px; border-radius: 22px; margin: 6px 4px; display: inline-block; } .stop-game .score-container .play-again:hover { background-color: #ff5f84; } .stop-game .score-container .main-menu { background-color: #44BFA3; border: 2px solid #fff; color: #fff; text-decoration: none; text-transform: uppercase; font-weight: 900; letter-spacing: -1px; font-size: 26px; padding: 6px 24px; border-radius: 22px; margin: 6px 4px; display: inline-block; } .stop-game .score-container .main-menu:hover { background-color: #57c6ac; } .scene { display: flex; flex-direction: column; justify-content: space-between; position: fixed; z-index: 9997; left: 0; top: 0; width: 100%; height: 100%; } .scene .ball-holder { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; padding-left: 558px; } .scene .score { position: fixed; right: 54px; top: 20px; color: #33485F; font-size: 90px; font-weight: 900; letter-spacing: -0.1em; } .scene .learn-to-play { z-index: 9999; display: inline-block; text-align: center; position: relative; top: 20%; font-size: 48px; color: rgba(255, 255, 255, 0.85); font-weight: 700; letter-spacing: -2px; opacity: 0; } .splash { display: none; } @media print { .splash { display: block; position: fixed; z-index: 99999; left: 0; top: 0; width: 100%; height: 100%; background-color: #28DAD4; background-image: url(//repo.bfw.wiki/bfwrepo/images/ballgame/coloron-image.png); background-size: auto 100%; background-repeat: no-repeat; background-position: center; } } .nominee { position: fixed; right: 0; top: 0; z-index: 9999; } </style> </head> <body> <div class="splash"></div> <div class="container"> <div class="start-game game-full-flex" id="start-game"> <div class="start-game-top"> </div> <div class="logo-holder"> <p class="logo">变色弹球跳台阶</p> <a class="play-button" href="#" onClick="game.start()">开始</a> <h4 class="hint">注意: 红色优先</h4> </div> <div class="how-to-play"> <div class="section section-1"> <h4>弹跳球<br>改变颜色</h4> <div class="content"> <div class="ball-demo" id="ball-demo"></div> </div> </div> <div class="section section-2"> <h4> 点击栏切换颜色<br> (红,黄,紫) </h4> <div class="content"> <div class="bar bar-1" data-index="0"></div> <div class="bar bar-2"></div> <div class="bar bar-3"></div> </div> </div> <div class="section section-3"> <h4>总是匹配<br>球棒颜色</h4> <div class="content"> <div class="ball-demo" id="ball-demo"></div> <div class="bar bar-1"></div> </div> </div> </div> </div> <div class="stop-game game-full-flex"> <div class="score-container"> <h1>失败</h1> <div class="final-score"></div> <div class="result"></div> <h2>下载更多源码</h2> <p> <a class="tweet" href="https://code.bfw.wiki/"> <i class="fa fa-twitter" aria-hidden="true"></i> 查看 </a> </p> <div> <a class="play-again" href="#" onClick="game.start()">再玩一次</a> <a class="main-menu" href="#" onClick="game.intro()">菜单</a> </div> </div> </div> <div class="small-glows"></div> <div class="glow"> <div class="sun"></div> </div> <div class="waves"> <div class="top_wave"></div> <div class="wave1"></div> <div class="wave2"></div> <div class="wave3"></div> <div class="wave4"></div> </div> <div class="mounts"> <div class="mount1"></div> <div class="mount2"></div> </div> <div class="clouds"></div> <div class="scene"> <div class="learn-to-play">点击栏改变颜色!</div> <div class="score" id="score"></div> <div class="ball-hol.........完整代码请登录后点击上方下载按钮下载查看
网友评论0