class Network{ constructor(adress){ this.adress = adress; this.connected = false; this.playerId = null; } message(data){ switch(data.type){ case 'connect': this.playerId = data.data.playerId; for (let i = 0; i{ this.connected = true; //connected to server }); this.socket.addEventListener('message', (e)=>{ this.message(JSON.parse(e.data)); }) } died(id, killerId){ this.socket.send(JSON.stringify({type:"died",data:{id: id, killerId: killerId}})); } update(obj){ //send data to server in order to broadcast this.socket.send(JSON.stringify({ type: "update", data: obj })); } newBullet(x,y,z,dx,dy,parentId) { this.socket.send(JSON.stringify({type:"newBullet",data:{x: x,y: y,z: z,dx: dx,dy: dy,id:parentId}})); } }