以下是一个简单的地铁跑酷的 HTML 代码示例:
<!DOCTYPE html>
<html>
<head>
<title>地铁跑酷</title>
<style>
#gameContainer {
width: 400px;
height: 600px;
background-color: #000;
position: relative;
margin: 0 auto;
overflow: hidden;
}
#player {
width: 50px;
height: 50px;
background-color: red;
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
}
</style>
<script>
document.addEventListener('keydown', function(event) {
if (event.code === 'Space') {
jump();
}
});
function jump() {
var player = document.getElementById('player');
if (!player.classList.contains('jump')