arrows prevent scrolling
This commit is contained in:
parent
3f3dc185b9
commit
c1bb21a291
1 changed files with 6 additions and 1 deletions
|
@ -22,7 +22,7 @@ class Input {
|
||||||
let dy = mouseY-player.y;
|
let dy = mouseY-player.y;
|
||||||
|
|
||||||
let norm = Math.sqrt(dx*dx+dy*dy);
|
let norm = Math.sqrt(dx*dx+dy*dy);
|
||||||
|
|
||||||
let b = new Bullet(player.x,player.y,dx/norm,dy/norm,player.id);
|
let b = new Bullet(player.x,player.y,dx/norm,dy/norm,player.id);
|
||||||
bullets.push(b);
|
bullets.push(b);
|
||||||
|
|
||||||
|
@ -30,6 +30,9 @@ class Input {
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener("keydown", (e)=>{
|
window.addEventListener("keydown", (e)=>{
|
||||||
|
if(["Space","ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].indexOf(e.code) > -1) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
this.keysDown.add(e.key.toLowerCase())
|
this.keysDown.add(e.key.toLowerCase())
|
||||||
this.updateDir();
|
this.updateDir();
|
||||||
})
|
})
|
||||||
|
@ -43,7 +46,9 @@ class Input {
|
||||||
updateDir(){
|
updateDir(){
|
||||||
if(player==null)
|
if(player==null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
let oldDir=this.dir;
|
let oldDir=this.dir;
|
||||||
|
|
||||||
this.dir=0;
|
this.dir=0;
|
||||||
if(this.keysDown.has('z') || this.keysDown.has('arrowup')){
|
if(this.keysDown.has('z') || this.keysDown.has('arrowup')){
|
||||||
if(this.keysDown.has('d') || this.keysDown.has('arrowright')){
|
if(this.keysDown.has('d') || this.keysDown.has('arrowright')){
|
||||||
|
|
Loading…
Reference in a new issue