-
Notifications
You must be signed in to change notification settings - Fork 1
/
controller.js
33 lines (27 loc) · 1.12 KB
/
controller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const kiteForButton = document.getElementById('kite');
const leftButton = document.getElementById('left');
const rightButton = document.getElementById('right');
const upButton = document.getElementById('up');
const downButton = document.getElementById('down');
let angleForButton = 0;
let altitudeForButton = 0;
function updateKitePositionForButton() {
kiteForButton.style.transform = `translateX(-50%) rotate(${angleForButton}deg) translateY(-${altitudeForButton}px)`;
}
function handleButtonPress(direction) {
if (direction === 'left') {
angleForButton -= 10;
} else if (direction === 'right') {
angleForButton += 10;
} else if (direction === 'up') {
altitudeForButton += 10;
} else if (direction === 'down') {
altitudeForButton -= 10;
}
updateKitePositionForButton();
}
leftButton.addEventListener('click', () => handleButtonPress('left'));
rightButton.addEventListener('click', () => handleButtonPress('right'));
upButton.addEventListener('click', () => handleButtonPress('up'));
downButton.addEventListener('click', () => handleButtonPress('down'));
updateKitePosition();