65 lines
No EOL
1.5 KiB
JavaScript
65 lines
No EOL
1.5 KiB
JavaScript
Renderer = new Render("canvas", "./assets/map/map7_recadr.png");
|
|
let Net = new Network("ws://129.151.227.50:8080/", Renderer);
|
|
//let ClientKeyboard = new Keyboard()
|
|
|
|
|
|
let playerId = null; //id of client player
|
|
let players = [];
|
|
let player = null;
|
|
|
|
Inp = new Input("canvas", Net);
|
|
|
|
playerId=Net.playerId;
|
|
player=Net.clientPlayer;
|
|
players=Net.getPlayersToAdd();
|
|
|
|
|
|
|
|
function game() {
|
|
if(playerId==null)
|
|
{
|
|
if (Net.playerId!=null)
|
|
{
|
|
playerId=Net.playerId;
|
|
player=Net.clientPlayer;
|
|
players=Net.getPlayersToAdd();
|
|
//Inp.player=player; //pour connecter les input au joueur client
|
|
console.log("Connected as id ",playerId);
|
|
Inp.player=player;
|
|
Renderer.AddPlayer(player)
|
|
players.forEach((p) => {
|
|
Renderer.AddPlayer(p)
|
|
})
|
|
}
|
|
}
|
|
else
|
|
{
|
|
let playerToUpdate = Net.getPlayersToUpdate();
|
|
for (let i = 0;i<playerToUpdate.length;i++)
|
|
{
|
|
for (let j = 0;j<players.length;j++)
|
|
{
|
|
if(players[j].id==playerToUpdate[i].id)
|
|
{
|
|
console.log("updated player",playerToUpdate[i].id);
|
|
players[j].x=playerToUpdate[i].x;
|
|
players[j].y=playerToUpdate[i].y;
|
|
players[j].dir=playerToUpdate[i].dir;
|
|
players[j].visibledir=playerToUpdate[i].visibledir;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
player.update([],[]);
|
|
for (var i = players.length - 1; i >= 0; i--) {
|
|
players[i].update([],[]);//squares, circles
|
|
}
|
|
//console.log(Inp.calculateAngle(500,500))
|
|
Renderer.ReloadAff();
|
|
}
|
|
}
|
|
|
|
Net.connect(); //connect to server, create a player, and retrieve all players info
|
|
|
|
|
|
setInterval(game) |