js实现简易塔防类小游戏代码
代码语言:html
所属分类:其他
代码描述:js实现简易塔防类小游戏代码,有两个塔,一个塔攻击距离远,凡是速度慢,一个塔攻击距离近,但是速度快,点击鼠标选择放到你想要的位置,敌人就开始进来了。
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> html { min-height: 100vh; display: grid; place-items: center; font-family: system-ui; line-height: 100%; user-select: none; background: #000; } body { width: calc(var(--tile-size) * 7); position: relative; } * { user-select: none; } #game_map { position: relative; width: 100%; height: 100%; } #game_map > div:not(.enemy) { width: var(--tile-size); aspect-ratio: 1 / 1; float: left; display: grid; place-items: center; position: relative; outline: 1px dotted #000; } .game_ground { background: #1436FF; } .game_ground:hover { background: darkblue; } .game_path { outline: 0 !important; background: black; /* background: radial-gradient(circle, #FFABA5 20%, transparent 20%); */ } .start:after { content: ''; width: 100% ; height: 100%; position: absolute; lefT: 0; top: 0; display: grid; place-items: center; color: rgba(0,0,0,.25); /* background: radial-gradient(circle, #FFABA5 15%, transparent 15%); */ } .game_gold { color: black; outline: 0 !important; } .game_gold:before { content:''; width: 25%; height: 25%; position: absolute; left: 40%; top: 5%; z-index: -1; border-radius: 50%; box-shadow: inset 2px 0 0 2px sienna; transform: rotate(20deg); } .game_gold:after { content:''; width: 80%; height: 80%; position: absolute; left: 10%; top: 15%; background: red; clip-path: polygon(50% 14%, 60% 5%, 78% 4%, 94% 12%, 100% 40%, 97% 76%, 81% 94%, 69% 100%, 57% 100%, 50% 93%, 42% 100%, 26% 98%, 7% 77%, 0% 37%, 6% 11%, 25% 4%); z-index: -1; } #towers_box { width: 100%; position: absolute; top: 10px; left: 50%; transform: translate(-50%, -200%); text-align: center; z-index: 200; } .tower { width: var(--tile-size); aspect-ratio: 1 / 1; /* outline: 1px solid lightgray; */ display: inline-block; line-height: var(--tile-size); vertical-align: top; position: relative; margin: 0 5px; } .game_ground.tower, .game_ground.tree { pointer-events: none; } .game_on { /* pointer-events: auto !important; */ } .rapid:after, .long:after, .tree:after { content: ''; width: var(--tile-size); height: 60px; display: grid; justify-content: center; align-items: end; font-size: 12px; position: absolute; bottom:0; left:0; background-size: 300% 100%; background-repeat: repeat-x; z-index: 900; } .rapid:after { content: '快攻'; background: #FFFB00; clip-path: polygon(0% 0%, 100% 0%, 75% 25%, 100% 50%, 100% 100%, 0% 100%, 0% 50%, 25% 25%); } .long:after { content: '长攻'; background: #FFFB00; clip-path: polygon(0% 0%, 25% 25%, 50% 0%, 75% 25%, 100% 0%, 100% 100%, 0% 100%); } .tree:after { height: 45px; background: conic-gradient(rgba(0,0,0,.25) 0deg 45deg, rgba(0,0,0,.4) 45deg 135deg, rgba(0,0,0,.55) 135deg 225deg, rgba(0,0,0,.4) 225deg 315deg, rgba(0,0,0,.25) 315deg 360deg); } .game_ground.tower { margin: 0 !important; } .bullet { width: 10px; aspect-ratio: 1 / 1;.........完整代码请登录后点击上方下载按钮下载查看
网友评论0