This commit is contained in:
Killian Marty 2023-11-20 10:03:07 +01:00
parent 1e7da4aa41
commit 913766a9c2
4 changed files with 31 additions and 17 deletions

View file

@ -1,6 +1,7 @@
<html>
<head>
<script type="text/javascript" src="./js/class.js"></script>
<script type="text/javascript" src="./js/objects.js"></script>
<script type="text/javascript" src="./js/render.js"></script>
<script type="text/javascript" src="./js/input.js"></script>
<script type="text/javascript" src="./js/network.js"></script>

View file

@ -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([],[]);

View file

@ -1,43 +1,41 @@
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;
this.dir = 7;
}
}
for (var i = players.length - 1; i >= 0; i--) {
if(players[i].id==playerId){
players[i].changeDirection(newDir);
}
}
getDirection(){
return this.dir;
}
init(){

14
js/objects.js Normal file
View file

@ -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));
}