Awage tv application

const gameContainer = document.getElementById(‘game-container’);
let player;

function createPlayer() {
player = document.createElement(‘div’);
player.classList.add(‘player’);
gameContainer.appendChild(player);
}

function movePlayer(event) {
const speed = 10;
if (event.key === ‘ArrowLeft’) {
player.style.left = ${parseInt(player.style.left) - speed}px;
} else if (event.key === ‘ArrowRight’) {
player.style.left = ${parseInt(player.style.left) + speed}px;
}
}

document.addEventListener(‘keydown’, movePlayer);

createPlayer();body {
margin: 0;
padding: 0;
overflow: hidden;
}

#game-container {
width: 100vw;
height: 100vh;
background-color: #000;
position: relative;
}

.player {
width: 50px;
height: 50px;
background-color: red;
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
}

Tempo Run

what is this code? do you have questions about it?

also
When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.