le serveur est down...
This commit is contained in:
parent
f0817769a4
commit
8e79098a63
6 changed files with 27 additions and 25 deletions
|
@ -3,7 +3,7 @@ const carSize = 40.;
|
||||||
const playerSpeed=.2;
|
const playerSpeed=.2;
|
||||||
const bulletSpeed=playerSpeed*2;
|
const bulletSpeed=playerSpeed*2;
|
||||||
const halfSqrtTwo=0.70710678118;
|
const halfSqrtTwo=0.70710678118;
|
||||||
|
const defaulthealth=10;
|
||||||
|
|
||||||
class Player
|
class Player
|
||||||
{
|
{
|
||||||
|
@ -25,7 +25,7 @@ class Player
|
||||||
//7=West
|
//7=West
|
||||||
//8=North-West
|
//8=North-West
|
||||||
this.ammo=10;
|
this.ammo=10;
|
||||||
this.health=10;
|
this.health=defaulthealth;
|
||||||
this.kill=0;
|
this.kill=0;
|
||||||
this.death=0;
|
this.death=0;
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ class Player
|
||||||
{
|
{
|
||||||
this.death++;
|
this.death++;
|
||||||
net.died(this.id,killerId);
|
net.died(this.id,killerId);
|
||||||
this.health=10;
|
this.health=defaulthealth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ class Bullet
|
||||||
{
|
{
|
||||||
constructor (x,y,dx,dy,id)
|
constructor (x,y,dx,dy,id)
|
||||||
{
|
{
|
||||||
sound.shoot();
|
bulletSound.play();
|
||||||
this.x=x;
|
this.x=x;
|
||||||
this.y=y;
|
this.y=y;
|
||||||
this.dx=dx;
|
this.dx=dx;
|
||||||
|
@ -123,9 +123,9 @@ class Bullet
|
||||||
if(this.deleted)
|
if(this.deleted)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(player!=null && player.id!=this.parentId && Math.sqrt((player.x-this.x)**2+(player.y-this.y)**2)<playerSize/2)
|
if(player!=null && player.id!=this.shooterId && Math.sqrt((player.x-this.x)**2+(player.y-this.y)**2)<playerSize/2)
|
||||||
{
|
{
|
||||||
player.takeDamage(1,this.parentId);
|
player.takeDamage(1,this.shooterId);
|
||||||
this.deleted=true;
|
this.deleted=true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -238,10 +238,10 @@ class Car
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(this.drift > 0) {
|
if(this.drift > 0) {
|
||||||
this.Renderer.RenderCar(this.x,this.y, this.angle+2.1)
|
renderer.RenderCar(this.x,this.y, this.angle+2.1)
|
||||||
this.drift--
|
this.drift--
|
||||||
} else {
|
} else {
|
||||||
this.Renderer.RenderCar(this.x,this.y, this.angle)
|
renderer.RenderCar(this.x,this.y, this.angle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ function game() {
|
||||||
for (let i = 0;i<players.length; i++) {
|
for (let i = 0;i<players.length; i++) {
|
||||||
players[i].update(squares, circles, dt);
|
players[i].update(squares, circles, dt);
|
||||||
}
|
}
|
||||||
Renderer.ReloadAff();
|
renderer.ReloadAff();
|
||||||
cars.forEach((c) => {
|
cars.forEach((c) => {
|
||||||
c.Update();
|
c.Update();
|
||||||
if(c.collide(player.x,player.y))
|
if(c.collide(player.x,player.y))
|
||||||
|
|
|
@ -15,7 +15,7 @@ let renderer = new Render("canvas");
|
||||||
let LB = new LeaderBoard("canvas");
|
let LB = new LeaderBoard("canvas");
|
||||||
let bulletSound = new Sound("./assets/sounds/shoot.mp3");
|
let bulletSound = new Sound("./assets/sounds/shoot.mp3");
|
||||||
let driftSound = new Sound("./assets/sounds/drift.mp3");
|
let driftSound = new Sound("./assets/sounds/drift.mp3");
|
||||||
let net = new Network("ws://129.151.227.50:8080?name="+CookiePseudo());
|
let net = new Network("wss://ws.gta6.insat.fr:8080?name="+CookiePseudo());
|
||||||
let inp = new Input("canvas");
|
let inp = new Input("canvas");
|
||||||
let date = new Date();
|
let date = new Date();
|
||||||
let bullets = [];
|
let bullets = [];
|
||||||
|
|
|
@ -23,10 +23,8 @@ class Input {
|
||||||
|
|
||||||
let norm = Math.sqrt(dx*dx+dy*dy);
|
let norm = Math.sqrt(dx*dx+dy*dy);
|
||||||
let b = new Bullet(player.x,player.y,dx/norm,dy/norm,player.id);
|
let b = new Bullet(player.x,player.y,dx/norm,dy/norm,player.id);
|
||||||
|
|
||||||
bullets.push(b);
|
bullets.push(b);
|
||||||
renderer.addBullet(b);
|
net.newBullet(b.x,b.y,b.dx,b.dy,b.parentId);
|
||||||
network.newBullet(b.x,b.y,b.dx,b.dy,b.parentId);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener("keydown", (e)=>{
|
window.addEventListener("keydown", (e)=>{
|
||||||
|
@ -41,7 +39,7 @@ class Input {
|
||||||
}
|
}
|
||||||
|
|
||||||
updateDir(){
|
updateDir(){
|
||||||
if(this.player==null)
|
if(player==null)
|
||||||
return;
|
return;
|
||||||
let oldDir=this.dir;
|
let oldDir=this.dir;
|
||||||
this.dir=0;
|
this.dir=0;
|
||||||
|
@ -74,8 +72,8 @@ class Input {
|
||||||
}
|
}
|
||||||
if(oldDir!=this.dir)
|
if(oldDir!=this.dir)
|
||||||
{
|
{
|
||||||
this.player.changeDirection(this.dir);
|
player.changeDirection(this.dir);
|
||||||
this.network.update(this.player);
|
net.update(this.player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@ const map2 = new Image();
|
||||||
imgPlayer.src = "./assets/body.png";
|
imgPlayer.src = "./assets/body.png";
|
||||||
imgBullet.src = "./assets/bullet.png";
|
imgBullet.src = "./assets/bullet.png";
|
||||||
imgCar.src = "./assets/car.png";
|
imgCar.src = "./assets/car.png";
|
||||||
map.src = "./assets/map_principale.png"
|
map.src = "./assets/map/map_principale.png"
|
||||||
map2.src = "./assets/map_secondaire.png";
|
map2.src = "./assets/map/map_secondaire.png";
|
||||||
|
|
||||||
class Render {
|
class Render {
|
||||||
constructor(idCanvas) {
|
constructor(idCanvas) {
|
||||||
|
@ -74,15 +74,19 @@ class Render {
|
||||||
this.map=0;
|
this.map=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let fond = map;
|
||||||
|
/*
|
||||||
if(this.map==0) {
|
if(this.map==0) {
|
||||||
let fond = map;
|
let fond = map;
|
||||||
} else {
|
} else {
|
||||||
let fond = map2;
|
let fond = map2;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
this.ctx.canvas.width = fond.width;
|
let mapWidth = fond.width;
|
||||||
this.ctx.canvas.height = fond.height;
|
let mapHeight = fond.height;
|
||||||
this.ctx.drawImage(fond, 0, 0, mapWidth, mapHeith);
|
this.ctx.canvas.width = mapWidth;
|
||||||
|
this.ctx.canvas.height = mapHeight;
|
||||||
|
this.ctx.drawImage(fond, 0, 0, mapWidth, mapHeight);
|
||||||
this.RenderPlayer(player,true);
|
this.RenderPlayer(player,true);
|
||||||
players.forEach((player) => {
|
players.forEach((player) => {
|
||||||
this.RenderPlayer(player,false);
|
this.RenderPlayer(player,false);
|
||||||
|
|
|
@ -5,8 +5,8 @@ class Sound{
|
||||||
}
|
}
|
||||||
|
|
||||||
play(){
|
play(){
|
||||||
this.shootSound.pause()
|
this.sound.pause()
|
||||||
this.shootSound.currentTime=0;
|
this.sound.currentTime=0;
|
||||||
this.shootSound.play()
|
this.sound.play()
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue