diff --git a/game.html b/game.html index cd3a8c9..a716a53 100644 --- a/game.html +++ b/game.html @@ -1,6 +1,7 @@
+ diff --git a/js/game.js b/js/game.js index 8e453b7..88da2a1 100644 --- a/js/game.js +++ b/js/game.js @@ -11,6 +11,7 @@ Net.connect(); //connect to server, create a player, and retrieve all players in ClientKeyboard.init(); +console.log(squares) function game() { for (var i = players.length - 1; i >= 0; i--) { players[i].update([],[]); diff --git a/js/keyboard.js b/js/keyboard.js index c6b357c..d033e4b 100644 --- a/js/keyboard.js +++ b/js/keyboard.js @@ -1,45 +1,43 @@ class Keyboard{ constructor(){ this.keysDown = new Set() + this.dir = 0; } updateDir(){ - let newDir = 0; if(this.keysDown.has('z')){ if(this.keysDown.has('d')){ - newDir = 2; + this.dir = 2; }else if(this.keysDown.has('s')){ - newDir = 0; + this.dir = 0; }else if(this.keysDown.has('q')){ - newDir = 8; + this.dir = 8; }else{ - newDir = 1; + this.dir = 1; } }else if(this.keysDown.has('d')){ if(this.keysDown.has('s')){ - newDir = 4; + this.dir = 4; }else if(this.keysDown.has('q')){ - newDir = 0; + this.dir = 0; }else{ - newDir = 3; + this.dir = 3; } }else if(this.keysDown.has('s')){ if(this.keysDown.has('q')){ - newDir = 6; + this.dir = 6; }else{ - newDir = 5; + this.dir = 5; } }else if(this.keysDown.has('q')){ - newDir = 7; - } - - for (var i = players.length - 1; i >= 0; i--) { - if(players[i].id==playerId){ - players[i].changeDirection(newDir); - } + this.dir = 7; } } + getDirection(){ + return this.dir; + } + init(){ document.addEventListener("keydown", (e)=>{ this.keysDown.add(e.key.toLowerCase()) diff --git a/js/objects.js b/js/objects.js new file mode 100644 index 0000000..34e7914 --- /dev/null +++ b/js/objects.js @@ -0,0 +1,14 @@ +let objects = {"squares":[{"x":297,"y":114,"w":78,"h":93},{"x":169,"y":243,"w":62,"h":250},{"x":313,"y":243,"w":62,"h":253},{"x":228,"y":257,"w":96,"h":222},{"x":792,"y":113,"w":176,"h":126},{"x":1017,"y":113,"w":143,"h":81},{"x":1160,"y":241,"w":143,"h":-129},{"x":1065,"y":372,"w":127,"h":124},{"x":697,"y":372,"w":319,"h":126},{"x":697,"y":498,"w":159,"h":111},{"x":697,"y":628,"w":160,"h":158},{"x":1001,"y":628,"w":191,"h":158},{"x":281,"y":629,"w":175,"h":156},{"x":0,"y":0,"w":137,"h":616},{"x":0,"y":615,"w":136,"h":310},{"x":1337,"y":1,"w":130,"h":581},{"x":1337,"y":573,"w":131,"h":356},{"x":586,"y":153,"w":15,"h":24},{"x":651,"y":153,"w":12,"h":24},{"x":700,"y":187,"w":12,"h":22},{"x":1020,"y":194,"w":10,"h":47},{"x":1019,"y":227,"w":56,"h":14},{"x":1101,"y":227,"w":62,"h":13},{"x":654,"y":128,"w":105,"h":17},{"x":748,"y":129,"w":12,"h":49},{"x":748,"y":193,"w":12,"h":47},{"x":654,"y":223,"w":105,"h":16},{"x":521,"y":129,"w":106,"h":14},{"x":521,"y":140,"w":13,"h":38},{"x":521,"y":194,"w":13,"h":46},{"x":521,"y":225,"w":108,"h":16}],"circles":[{"x":552,"y":163,"r":13.601470508735444},{"x":608,"y":190,"r":20.248456731316587},{"x":569,"y":212,"r":11.704699910719626},{"x":680,"y":213,"r":12.041594578792296},{"x":727,"y":164,"r":14.212670403551895}]} + +let squares = []; +let circles = []; + +for (var i = objects.squares.length - 1; i >= 0; i--) { + let current = objects.squares[i] + squares.push(new Square(current.x, current.y, current.w, current.h)); +} + +for (var i = objects.circles.length - 1; i >= 0; i--) { + let current = objects.circles[i] + circles.push(new Circle(current.x, current.y, current.w, current.h)); +} \ No newline at end of file