Created
December 26, 2019 22:56
-
-
Save kahilkubilay/85a8194f472ab6a21230e22798331d7f to your computer and use it in GitHub Desktop.
Javascript İle Oyun Yapımı: Nesnelerin Kontrolü - Çubuk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// stick değişkenleri | |
var stickLeft = document.getElementById('stickLeft'); | |
var stickRight = document.getElementById('stickRight'); | |
stickLeft.style.top = window.innerHeight/2 + 'px'; | |
stickRight.style.top = window.innerHeight/2 + 'px'; | |
function pxAdd(numb){ | |
return numb + 'px'; | |
} | |
switch(e.keyCode){ | |
// sol çubuk | |
case 87: | |
if(parseInt(stickLeft.style.top) <= 0){ | |
stickLeft.style.top = stickLeft.style.top; | |
}else{ | |
stickLeft.style.top = pxAdd(parseInt(stickLeft.style.top) - 30); | |
} | |
break; | |
case 83: | |
if(parseInt(stickLeft.style.top) + 85 >= window.innerHeight){ | |
stickLeft.style.top = stickLeft.style.top; | |
}else{ | |
stickLeft.style.top = pxAdd(parseInt(stickLeft.style.top) + 30); | |
} | |
break; | |
case 38: | |
if(parseInt(stickRight.style.top) <= 0){ | |
stickRight.style.top = stickRight.style.top; | |
}else{ | |
stickRight.style.top = pxAdd(parseInt(stickRight.style.top) - 30); | |
} | |
break; | |
case 40: | |
if(parseInt(stickRight.style.top) + 85 >= window.innerHeight){ | |
stickRight.style.top = stickRight.style.top; | |
}else{ | |
stickRight.style.top = pxAdd(parseInt(stickRight.style.top) + 30); | |
} | |
break; | |
default: | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment