HTMLコードテスト!!!!!
WASD Movement Game body { margin: 0; overflow: hidden; height: 100vh; background-color: #f0f0f0; } #character { position: absolute; width: 50px; height: 50px; background-color: red; transition: left 0.1s, top 0.1s; } const character = document.getElementById( character ); let left = 100; // Initial position let top = 100; // Initial position function moveCharacter(event) { switch (event.key) { case w : case ArrowUp : top -= 10; // Move up break; case a : case ArrowLeft : left -= 10; // Move left break; case s : case ArrowDown : top += 10; // Move down break; case d : case ArrowRight : left += 10; // Move right break; } character.style.left = left + px ; character.style.top = top + px ; } window.addEventListener( keydown , moveCharacter);
26view
0点
良い
悪い