GrandTabernacleAutoVI/js/game.js

46 lines
1,005 B
JavaScript
Raw Normal View History

2023-11-15 09:09:13 +01:00
Renderer = new Render("canvas", "./assets/map/map7_recadr.png");
2023-11-29 15:53:35 +01:00
let Net = new Network("ws://129.151.227.50:8080/", Renderer);
//let ClientKeyboard = new Keyboard()
2023-11-15 09:09:13 +01:00
2023-11-18 20:17:47 +01:00
2023-11-29 17:25:40 +01:00
let playerId = null; //id of client player
2023-11-19 18:38:27 +01:00
let players = [];
2023-11-29 17:25:40 +01:00
let player = null;
2023-11-15 09:09:13 +01:00
2023-11-29 18:11:58 +01:00
Inp = new Input("canvas", Net);
2023-11-29 16:21:20 +01:00
2023-11-29 17:25:40 +01:00
playerId=Net.playerId;
player=Net.clientPlayer;
players=Net.getPlayersToAdd();
2023-11-18 20:17:47 +01:00
2023-11-15 09:09:13 +01:00
function game() {
2023-11-29 17:25:40 +01:00
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);
2023-11-29 18:01:11 +01:00
Inp.player=player;
2023-11-29 18:11:58 +01:00
Renderer.AddPlayer(player)
2023-11-29 17:25:40 +01:00
}
}
else
{
2023-11-29 17:50:21 +01:00
player.update([],[]);
2023-11-29 17:25:40 +01:00
for (var i = players.length - 1; i >= 0; i--) {
players[i].update([],[]);//squares, circles
}
//console.log(Inp.calculateAngle(500,500))
Renderer.ReloadAff();
2023-11-19 18:55:21 +01:00
}
2023-11-19 19:20:02 +01:00
}
2023-11-29 17:36:27 +01:00
Net.connect(); //connect to server, create a player, and retrieve all players info
2023-11-29 17:06:30 +01:00
2023-11-29 17:36:27 +01:00
setInterval(game)