From 1ef94e22dfd6450dd759e43bf427c6fd9f790684 Mon Sep 17 00:00:00 2001 From: v_lasser Date: Mon, 11 Dec 2023 14:50:20 +0100 Subject: [PATCH 1/9] first of many... --- public_html/js/class.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public_html/js/class.js b/public_html/js/class.js index 67d5642..d3cfb6e 100644 --- a/public_html/js/class.js +++ b/public_html/js/class.js @@ -8,11 +8,12 @@ const defaulthealth=10; class Player { - constructor (id,x,y,name,dir) + constructor (id,x,y,z,name,dir) { this.name=name; this.x=x; this.y=y; + this.z=z; //this.z=z;//correspond to the map. Ex: 0=>main; 1=>arena this.id=id; this.visibleDir=1; From 68539426a799f2ffd20debe14a5d53dff075bc61 Mon Sep 17 00:00:00 2001 From: v_lasser Date: Mon, 11 Dec 2023 15:13:06 +0100 Subject: [PATCH 2/9] second, not last --- public_html/js/class.js | 76 +++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/public_html/js/class.js b/public_html/js/class.js index d3cfb6e..3dcffa4 100644 --- a/public_html/js/class.js +++ b/public_html/js/class.js @@ -13,8 +13,7 @@ class Player this.name=name; this.x=x; this.y=y; - this.z=z; - //this.z=z;//correspond to the map. Ex: 0=>main; 1=>arena + this.z=z;//correspond to the map. Ex: 0=>main; 1=>arena this.id=id; this.visibleDir=1; this.dir=dir;//0=stand Still @@ -73,7 +72,7 @@ class Player this.y += dy*dt; squares.forEach(square => { - if(square.collide(this.x,this.y)) + if(square.collide(this.x,this.y,this.z)) { this.x-=dx*dt; this.y-=dy*dt; @@ -83,7 +82,7 @@ class Player }); circles.forEach(circle => { - if(circle.collide(this.x,this.y)) + if(circle.collide(this.x,this.y,this.z)) { this.x-=dx*dt; this.y-=dy*dt; @@ -101,11 +100,13 @@ class Player class Bullet { - constructor (x,y,dx,dy,id) + constructor (x,y,z,dx,dy,id) { - bulletSound.play(); + if(z==player.z) + bulletSound.play(); this.x=x; this.y=y; + this.z=z; this.dx=dx; this.dy=dy; this.deleted=false; @@ -126,21 +127,21 @@ class Bullet if(this.deleted) return; - if(player!=null && player.id!=this.shooterId && Math.sqrt((player.x-this.x)**2+(player.y-this.y)**2) { - if(square.collide(this.x,this.y)) + if(square.collide(this.x,this.y,this.z)) { this.deleted=true; return; } }); circles.forEach((circle) => { - if(circle.collide(this.x,this.y)) + if(circle.collide(this.x,this.y,this.z)) { this.deleted=true; return; @@ -152,32 +153,34 @@ class Bullet class Square { - constructor(x,y,width,heigth) + constructor(x,y,z,width,heigth) { this.x=x; this.y=y; + this.z=z; this.w=width; this.h=heigth; } - collide(x,y) + collide(x,y,z) { - return this.x<=x && x<=this.x+this.w && this.y<=y && y<=this.y+this.h; + return this.z==z && this.x<=x && x<=this.x+this.w && this.y<=y && y<=this.y+this.h; } } class Circle { - constructor(x,y,radius) + constructor(x,y,z,radius) { this.x=x; this.y=y; + this.z=z; this.r=radius; } - collide(x,y) + collide(x,y,z) { - return (x-this.x)**2+(y-this.y)**2 <= this.r**2; + return this.z==z && (x-this.x)**2+(y-this.y)**2 <= this.r**2; } } @@ -187,7 +190,7 @@ class Car { this.type=type; // 0 circule vers le haut // 1 circule vers le bas - + this.z=0; if(this.type == 1) { //vers le bas this.x=1247; this.y=-40; @@ -207,8 +210,11 @@ class Car this.tick=0; } - collide(x,y) + collide(x,y,z) { + if(this.z!=z) { + return false; + } let cx=this.x-carSize/2; let cy=this.y-carSize/2; let collide = (cx<=x && x<=cx+carSize && cy<=y && y<=cy+carSize); @@ -369,41 +375,42 @@ class Car } class PNJ{ - constructor(x, y){ + constructor(x, y, z){ this.x=x; this.y=y; + this.z=z; this.dir=1; } - checkCollisions(x,y){ - let colliding = false; + checkCollisions(){ squares.forEach((square) => { - if(square.collide(x,y)) + if(square.collide(this.x,this.y,this.z)) { - colliding = true; - return; + return true; } }); circles.forEach((circle) => { - if(circle.collide(x,y)) + if(circle.collide(this.x,this.y,this.z)) { - colliding=true; - return; + return true; } }); - return colliding; + return false; } changeDirection(){ - let newDir = this.dir; - while(newDir == this.dir){ - newDir = Math.floor(Math.random()*8); + let newDir = Math.floor(Math.random()*8); + if(newDir == this.dir){ + newDir = (this.dir+3)%4+1; } this.dir = newDir; } update(dt) { + if(this.z!=player.z){ + return; + } let dx,dy; switch(this.dir) { @@ -417,10 +424,11 @@ class PNJ{ case 8: dx=-halfSqrtTwo*PNJSpeed;dy=-halfSqrtTwo*PNJSpeed;break; default: dx=0;dy=0;break; } - if(!this.checkCollisions(this.x + dx*dt, this.y + dy*dt)){ - this.x += dx*dt; - this.y += dy*dt; - }else{ + this.x+=dx*dt; + this.y+=dy*dt; + if(this.checkCollisions()){ + this.x -= dx*dt; + this.y -= dy*dt; this.changeDirection(); } From f6cbebe532b2dd2db859dabc8d02d79fe4442977 Mon Sep 17 00:00:00 2001 From: Atsuyo-INSA Date: Tue, 12 Dec 2023 13:53:55 +0100 Subject: [PATCH 3/9] bientot ok ? --- public_html/js/game.js | 4 +- public_html/js/global.js | 34 +++++++---- public_html/js/input.js | 11 +--- public_html/js/network.js | 12 ++-- public_html/js/objects.js | 6 +- public_html/js/render.js | 123 +++++++++++++++++--------------------- 6 files changed, 93 insertions(+), 97 deletions(-) diff --git a/public_html/js/game.js b/public_html/js/game.js index fcc2403..7f64be7 100644 --- a/public_html/js/game.js +++ b/public_html/js/game.js @@ -11,10 +11,10 @@ function game() { cars.forEach((c) => { c.Update(); - if(c.collide(player.x,player.y)) + if(c.collide(player.x,player.y,player.z)) { net.died(player.id,-1); - player.x=-50; + player.z=-1; player.deaths++; player.health=10; } diff --git a/public_html/js/global.js b/public_html/js/global.js index 56bcbd6..dbde358 100644 --- a/public_html/js/global.js +++ b/public_html/js/global.js @@ -9,17 +9,17 @@ let inp = new Input("canvas"); let bullets = []; let circles = []; let squares = []; -let PNJS = [new PNJ(500, 100), - new PNJ(700, 100), - new PNJ(500, 600), - new PNJ(200, 700)]; +let PNJS = [new PNJ(500, 100,0), + new PNJ(700, 100,0), + new PNJ(500, 600,0), + new PNJ(200, 700,0)]; -let cars = [new Car(renderer, 0, 0), - new Car(renderer, 0, 7), - new Car(renderer, 1, 7), - new Car(renderer, 1, 13), - new Car(renderer, 1, 14), - new Car(renderer, 0, 15)]; +let cars = [new Car(0, 0), + new Car(1, 7), + new Car(1, 13), + new Car(1, 14), + new Car(0, 7), + new Car(0, 15)]; function updatePlayer(data) @@ -28,6 +28,7 @@ function updatePlayer(data) { player.x=data.x; player.y=data.y; + player.z=data.z; } else { @@ -37,6 +38,9 @@ function updatePlayer(data) { players[i].x=data.x; players[i].y=data.y; + if(data.z==undefined) + data.z=0; + players[i].z=data.z; players[i].dir=data.dir; players[i].visibleDir=data.visibleDir; break; @@ -47,10 +51,18 @@ function updatePlayer(data) function addPlayer(data) { - let np = new Player(data.id, data.x, data.y, data.name, data.dir); + let np = new Player(data.id, data.x, data.y, 0, data.name, data.dir); players.push(np); } + + + + + + + + function removePlayer(id) { for(let i=0;i=2000 && player.y>=2000) { - mouseX+=2000; - mouseY+=2000; - } let dx = mouseX-player.x; let dy = mouseY-player.y; 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,player.z,dx/norm,dy/norm,player.id); bullets.push(b); - net.newBullet(b.x,b.y,b.dx,b.dy,b.parentId); + net.newBullet(b.x,b.y,b.z,b.dx,b.dy,b.parentId); }); window.addEventListener("keydown", (e)=>{ //blocks the action of the key (cf. Killian) - if(["Space","ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].indexOf(e.code) > -1) { + if(["Space","ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(e.code)) { e.preventDefault(); } this.keysDown.add(e.key.toLowerCase()) diff --git a/public_html/js/network.js b/public_html/js/network.js index 0faf7df..0cd871f 100644 --- a/public_html/js/network.js +++ b/public_html/js/network.js @@ -12,9 +12,9 @@ class Network{ for (let i = 0; i=2000 && y>=2000 && this.map==1) { - x=player.x-2000 - y=player.y-2000 - } - - //this.map==1 && (x<2000 || y<2000) - if((this.map==1 && player.x>=2000 && player.y>=2000) || (this.map==0 && x<2000 && y <2000)) { + let x=p.x + let y=p.y + + if(p.z==player.z) + { this.ctx.save(); this.ctx.translate(x, y); - this.ctx.rotate(player.angle); + this.ctx.rotate(p.angle); this.ctx.drawImage(imgPlayer, -playerSize / 2, -playerSize / 2, playerSize, playerSize); this.ctx.restore(); this.ctx.fillStyle = 'white'; this.ctx.font="10pt arial"; - this.ctx.fillText(player.name,x-player.name.length*10/3,y-playerSize/1.8); - if(client) { + this.ctx.fillText(p.name,x-p.name.length*10/3,y-playerSize/1.8); + if(isClient) { this.ctx.fillStyle = 'red'; this.ctx.fillRect(x-playerSize/2-5, y-playerSize/2, playerSize+10, 5); this.ctx.fillStyle = '#7AFF33'; - this.ctx.fillRect(x-playerSize/2-5, y-playerSize/2, player.health*(playerSize+10)/defaulthealth, 5); + this.ctx.fillRect(x-playerSize/2-5, y-playerSize/2, p.health*(playerSize+10)/defaulthealth, 5); } } } - RenderCar(x,y,angle) { - if(this.map==0) { + RenderCar(x,y,z,angle) { + if(z==player.z) { this.ctx.save(); this.ctx.translate(x, y); this.ctx.rotate(angle); @@ -62,73 +58,66 @@ class Render { } } - RenderBullet(x,y) { - /* - if(this.map==1) { - x = x-2000; - y = y-2000; - }*/ - this.ctx.save(); - this.ctx.translate(x, y); - this.ctx.drawImage(imgBullet, -20 / 2, -20 / 2, 20, 20); - this.ctx.restore(); + RenderBullet(x,y,z) { + if(z==player.z) + { + this.ctx.save(); + this.ctx.translate(x, y); + this.ctx.drawImage(imgBullet, -20 / 2, -20 / 2, 20, 20); + this.ctx.restore(); + } } - RenderPnj(x, y, angle, moving){ - - this.ctx.save(); - this.ctx.translate(x, y); - this.ctx.rotate(angle); - if((new Date)%1000>=500 || moving==false){ - this.ctx.drawImage(imgPnj, -30 / 2, -30 / 2, 30, 30); - }else{ - this.ctx.drawImage(imgPnj2, -30 / 2, -30 / 2, 30, 30); - } - - this.ctx.restore(); + RenderPnj(x, y, z, angle, moving) + { + if(z==player.z) + { + this.ctx.save(); + this.ctx.translate(x, y); + this.ctx.rotate(angle); + if(moving == false || (new Date().getMilliseconds())%1000>=500){ + this.ctx.drawImage(imgPnj, -30 / 2, -30 / 2, 30, 30); + }else{ + this.ctx.drawImage(imgPnj2, -30 / 2, -30 / 2, 30, 30); + } + this.ctx.restore(); + } } ReloadAff() { - - //const fond = new Image(); - if(player!=null && player.x >= 2000 && player.y >=2000) { - this.map=1; - } else { - this.map=0; + let background; + + if(player.z==0) + { + let date = new Date(); + if(date.getMinutes()%10>=5){ + background = map; + }else{ + background = map_night; + } + } + else + { + background=map2; } - let fond; - let date = new Date(); - - if(date.getMinutes()%10>=5){ - fond = map; - }else{ - fond = map_night; - } - /* - if(this.map==0) { - let fond = map; - } else { - let fond = map2; - } - */ - let mapWidth = fond.width; - let mapHeight = fond.height; + let mapWidth = background.width; + let mapHeight = background.height; this.ctx.canvas.width = mapWidth; this.ctx.canvas.height = mapHeight; - this.ctx.drawImage(fond, 0, 0, mapWidth, mapHeight); + this.ctx.drawImage(background, 0, 0, mapWidth, mapHeight); this.RenderPlayer(player,true); cars.forEach((car) => { - this.RenderCar(car.x,car.y,car.angle+(car.drift>0?2.1:0)); + this.RenderCar(car.x,car.y,car.z,car.angle+(car.drift>0?2.1:0)); }); players.forEach((player) => { this.RenderPlayer(player,false); }) bullets.forEach((bullet) => { - this.RenderBullet(bullet.x,bullet.y); + this.RenderBullet(bullet.x,bullet.y,bullet.z); }); PNJS.forEach((pnj)=>{ - this.RenderPnj(pnj.x, pnj.y, (pnj.dir-1)*Math.PI/4, pnj.dir!=0); + this.RenderPnj(pnj.x, pnj.y, pnj.z, (pnj.dir-1)*Math.PI/4, pnj.dir!=0); }) } } \ No newline at end of file From 9f88b162ea63cf1ae9cdbbd3d4e6ceb9d25be473 Mon Sep 17 00:00:00 2001 From: Atsuyo-INSA Date: Wed, 13 Dec 2023 14:11:21 +0100 Subject: [PATCH 4/9] almost perfect --- public_html/js/game.js | 3 ++- public_html/js/global.js | 1 + public_html/js/input.js | 3 +-- public_html/js/network.js | 4 ++-- public_html/js/render.js | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/public_html/js/game.js b/public_html/js/game.js index 7f64be7..795a777 100644 --- a/public_html/js/game.js +++ b/public_html/js/game.js @@ -16,6 +16,7 @@ function game() { net.died(player.id,-1); player.z=-1; player.deaths++; + players[0].kill++; player.health=10; } }); @@ -36,4 +37,4 @@ function game() { net.connect(); //connect to server, create a player, and retrieve all players info -setInterval(game); \ No newline at end of file +setInterval(game,16); \ No newline at end of file diff --git a/public_html/js/global.js b/public_html/js/global.js index dbde358..d5065d6 100644 --- a/public_html/js/global.js +++ b/public_html/js/global.js @@ -21,6 +21,7 @@ let cars = [new Car(0, 0), new Car(0, 7), new Car(0, 15)]; +players.push(new Player(-1,-50,-50,-1,"VOITURES",0)); function updatePlayer(data) { diff --git a/public_html/js/input.js b/public_html/js/input.js index 62f989a..3cf643a 100644 --- a/public_html/js/input.js +++ b/public_html/js/input.js @@ -22,8 +22,7 @@ class Input { let b = new Bullet(player.x,player.y,player.z,dx/norm,dy/norm,player.id); bullets.push(b); - - net.newBullet(b.x,b.y,b.z,b.dx,b.dy,b.parentId); + net.newBullet(b.x,b.y,b.z,b.dx,b.dy,b.shooterId); }); window.addEventListener("keydown", (e)=>{ diff --git a/public_html/js/network.js b/public_html/js/network.js index 0cd871f..3995631 100644 --- a/public_html/js/network.js +++ b/public_html/js/network.js @@ -31,10 +31,10 @@ class Network{ break; case "newBullet": - bullets.push(new Bullet(data.data.x,data.data.y,data.z,data.data.dx,data.data.dy,data.data.id, this.sound)); + bullets.push(new Bullet(data.data.x,data.data.y,data.data.z==undefined?0:data.data.z,data.data.dx,data.data.dy,data.data.id)); break; - case "died": + case "died": console.log("player",data.data.id,"was killed by",data.data.killerId); addKill(data.data.id,data.data.killerId); break; diff --git a/public_html/js/render.js b/public_html/js/render.js index 8989ece..e3de28f 100644 --- a/public_html/js/render.js +++ b/public_html/js/render.js @@ -87,7 +87,7 @@ class Render { ReloadAff() { let background; - if(player.z==0) + if(player.z<=0) { let date = new Date(); if(date.getMinutes()%10>=5){ From 0b89679d4aa996f371f26da43ee888fd878b2245 Mon Sep 17 00:00:00 2001 From: v_lasser Date: Fri, 15 Dec 2023 13:46:51 +0100 Subject: [PATCH 5/9] portal's class written but not tested --- public_html/js/class.js | 30 ++++++++++++++++++++++++++++++ public_html/js/render.js | 25 ++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/public_html/js/class.js b/public_html/js/class.js index 3dcffa4..76c17ec 100644 --- a/public_html/js/class.js +++ b/public_html/js/class.js @@ -5,6 +5,8 @@ const PNJSpeed=.02; const bulletSpeed=playerSpeed*2; const halfSqrtTwo=0.70710678118; const defaulthealth=10; +const portalSize=40; +const affPortal = true; class Player { @@ -436,5 +438,33 @@ class PNJ{ this.changeDirection(); } + } +} + +class portalIn +{ + constructor(xIn,yIn,zIn,xOut,yOut,zOut) + { + this.in={x:xIn,y:yIn,z:zIn}; + this.out={x:xOut,y:yOut,z:zOut}; + } + + update() + { + if(player.z==this.in.z && player.x>this.in.x && player.xthis.in.y && player.y{ this.RenderPnj(pnj.x, pnj.y, pnj.z, (pnj.dir-1)*Math.PI/4, pnj.dir!=0); }) + if(affPortal) + { + portalSize.forEach((portal) => { + if(portal.in.z==player.z) + this.RenderPortal(portal.in.x,portal.in.y,true); + else if(portal.out.z==player.z) + this.RenderPortal(portal.out.x,portal.out.y,false); + }); + } } } \ No newline at end of file From e907afa4de9d2b9e503de0a06247a8b33db5efb2 Mon Sep 17 00:00:00 2001 From: v_lasser Date: Fri, 15 Dec 2023 13:48:31 +0100 Subject: [PATCH 6/9] quick fix --- public_html/js/global.js | 22 ++++++++++++---------- public_html/js/render.js | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/public_html/js/global.js b/public_html/js/global.js index d5065d6..a65383e 100644 --- a/public_html/js/global.js +++ b/public_html/js/global.js @@ -10,17 +10,19 @@ let bullets = []; let circles = []; let squares = []; let PNJS = [new PNJ(500, 100,0), - new PNJ(700, 100,0), - new PNJ(500, 600,0), - new PNJ(200, 700,0)]; - -let cars = [new Car(0, 0), - new Car(1, 7), - new Car(1, 13), - new Car(1, 14), - new Car(0, 7), + new PNJ(700, 100,0), + new PNJ(500, 600,0), + new PNJ(200, 700,0)]; + + let cars = [new Car(0, 0), + new Car(1, 7), + new Car(1, 13), + new Car(1, 14), + new Car(0, 7), new Car(0, 15)]; - +let portals = []; +let maps = []; + players.push(new Player(-1,-50,-50,-1,"VOITURES",0)); function updatePlayer(data) diff --git a/public_html/js/render.js b/public_html/js/render.js index 9614fc4..dba9def 100644 --- a/public_html/js/render.js +++ b/public_html/js/render.js @@ -135,7 +135,7 @@ class Render { }) if(affPortal) { - portalSize.forEach((portal) => { + portals.forEach((portal) => { if(portal.in.z==player.z) this.RenderPortal(portal.in.x,portal.in.y,true); else if(portal.out.z==player.z) From 655ccde173c817ffce832ffc6c5a24354450276a Mon Sep 17 00:00:00 2001 From: v_lasser Date: Fri, 15 Dec 2023 13:49:08 +0100 Subject: [PATCH 7/9] textures --- public_html/assets/blue_portal.webp | Bin 0 -> 432 bytes public_html/assets/orange_portal.webp | Bin 0 -> 504 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 public_html/assets/blue_portal.webp create mode 100644 public_html/assets/orange_portal.webp diff --git a/public_html/assets/blue_portal.webp b/public_html/assets/blue_portal.webp new file mode 100644 index 0000000000000000000000000000000000000000..d66d31403a1d7cff273e8db9f8a87d506c69645a GIT binary patch literal 432 zcmV;h0Z;x?Nk&Gf0RRA3MM6+kP&il$0000G0000F000jF06|PpNZ9}Y00Dp?0AShZ z|Bu+QnrjBNQoEh?r-%rvs7a#fDc&a&rnb&=A*Y62W069Jr~{`jo;goDZRe6w{6!TY z#h&&~S*?3da-hNu{Qo0!%7_Bv4dg)c$}YL5EX5e?H(qLHAm~(coMG4@&p1mEsX_#g z+M$fgV#8Tpjg$}=%71-&I0r6I0vSyMzqRb9tRl_D8vh061z2TrUqnWe{7T&U_p6g$ zN0kDL>zrm~XPoM4HviCkwGHbui7SXai2~h8<25Dv^uitiR-G&9U;1|9yl_yT!@3bz zQ2+o|P&go{0000G1OS}@Di8n=004jvC9nc?x&inB`T;lo+y2O4h;+;1>tEEn|Jp-Kf7C{+Zn1EL*NAkQKh$J=ph9G$0Wl7F%~6W607K{bv<4iaa3`l8tzg zOhy+V62(_W5Y=efBf8z!L5kXuOsCtdRpnByriN3%NskP}+UEcMucT6bzr!GCfB15s>Hq)%JjKWW literal 0 HcmV?d00001 diff --git a/public_html/assets/orange_portal.webp b/public_html/assets/orange_portal.webp new file mode 100644 index 0000000000000000000000000000000000000000..dfdd84248975828b85fbb34f58778ccc50b636ee GIT binary patch literal 504 zcmVzrm~XPoM4HviCkwGHbui7SXai2~h8<25Dv^uitiR-G&9U;1|9yl_yT!@3bz zQ2+o|P&gp)0002+1pu7^Di8n=004jvC9nc?x&inB`T)=WvKA#Y_?P)(*c0_b{Xbg2 z)^A`B&;wdQ91;C~>EHkW{xm$kpWe=FIfIywGmxnTSd?ANcMqO^Pw*e$^0!()=M~0R zt)Dvee>^v5nPx>r-_*WDmh<)~Nmy^nq1n2yR!OL2cGv6-s?Nl z*Oa>ac!}0%Fhu4 ud5Se=pojmPW;Zegby6=7*G~hXBLAKE+%`=A{Ty?bTLXAt7+?Jt000208|KIW literal 0 HcmV?d00001 From 85690cf305f7593f3c8776e087889508c4cde6ad Mon Sep 17 00:00:00 2001 From: v_lasser Date: Mon, 18 Dec 2023 09:51:20 +0100 Subject: [PATCH 8/9] thiS -> this --- public_html/js/class.js | 4 ++-- public_html/js/game.js | 2 ++ public_html/js/global.js | 10 +--------- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/public_html/js/class.js b/public_html/js/class.js index 76c17ec..5c9e30f 100644 --- a/public_html/js/class.js +++ b/public_html/js/class.js @@ -441,7 +441,7 @@ class PNJ{ } } -class portalIn +class Portal { constructor(xIn,yIn,zIn,xOut,yOut,zOut) { @@ -453,7 +453,7 @@ class portalIn { if(player.z==this.in.z && player.x>this.in.x && player.xthis.in.y && player.y {portal.update();}); + updateBullets(dt); renderer.ReloadAff(); LB.ReloadAff(); diff --git a/public_html/js/global.js b/public_html/js/global.js index a65383e..8d5eb65 100644 --- a/public_html/js/global.js +++ b/public_html/js/global.js @@ -20,7 +20,7 @@ let PNJS = [new PNJ(500, 100,0), new Car(1, 14), new Car(0, 7), new Car(0, 15)]; -let portals = []; +let portals = [new Portal(100,100,0,500,500,0)]; let maps = []; players.push(new Player(-1,-50,-50,-1,"VOITURES",0)); @@ -58,14 +58,6 @@ function addPlayer(data) players.push(np); } - - - - - - - - function removePlayer(id) { for(let i=0;i Date: Mon, 18 Dec 2023 13:07:30 +0100 Subject: [PATCH 9/9] 3D (should be) finished code js/ --- public_html/js/class.js | 11 +++++++++-- public_html/js/game.js | 2 +- public_html/js/global.js | 12 ++++++++++-- public_html/js/input.js | 1 + public_html/js/render.js | 10 ++++++---- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/public_html/js/class.js b/public_html/js/class.js index 5c9e30f..e9ee239 100644 --- a/public_html/js/class.js +++ b/public_html/js/class.js @@ -463,8 +463,15 @@ class Portal class Map { - constructor(portalsIn, protalsOut,z) // portalsIn/Out : portal teleport In/Out; z: idDimension + constructor(portalsOut,z) // portalsIn/Out : portal teleport In/Out; z: idDimension { - + this.portalsOut=portalsOut; + portalsOut.forEach((p) => {if(p.in.z!=z){console.log("WRONG PORTAL DEFINITION FOR MAP",z,", portal :",p);}}); + this.z=z; + } + + update() + { + this.portalsOut.forEach((p)=>p.update()); } } \ No newline at end of file diff --git a/public_html/js/game.js b/public_html/js/game.js index b514f68..8d6b4f2 100644 --- a/public_html/js/game.js +++ b/public_html/js/game.js @@ -25,7 +25,7 @@ function game() { pnj.update(dt); }) - portals.forEach((portal) => {portal.update();}); + maps.forEach((m) => {m.update();}); updateBullets(dt); renderer.ReloadAff(); diff --git a/public_html/js/global.js b/public_html/js/global.js index 8d5eb65..5eb479c 100644 --- a/public_html/js/global.js +++ b/public_html/js/global.js @@ -20,8 +20,16 @@ let PNJS = [new PNJ(500, 100,0), new Car(1, 14), new Car(0, 7), new Car(0, 15)]; -let portals = [new Portal(100,100,0,500,500,0)]; -let maps = []; +let portals = [new Portal(250,457,0,500,500,0),//O + new Portal(344,758,0,500,500,0), // SO + new Portal(1190,211,0,500,500,0),// NE + new Portal(862,213,0,500,500,0), // N + new Portal(1126,472,0,500,500,0),// E + new Portal(1076,768,0,500,500,0),// SE + new Portal(721,767,0,500,500,0), // S + new Portal(970,476,0,500,500,0)];//Mid + +let maps = [new Map(portals.slice(0),0)]; players.push(new Player(-1,-50,-50,-1,"VOITURES",0)); diff --git a/public_html/js/input.js b/public_html/js/input.js index 3cf643a..abd1750 100644 --- a/public_html/js/input.js +++ b/public_html/js/input.js @@ -14,6 +14,7 @@ class Input { let mouseX = (e.clientX - bounds.x)*this.canvas.width/bounds.width; let mouseY = (e.clientY - bounds.y)*this.canvas.height/bounds.height; + //console.log(Math.round(mouseX),",",Math.round(mouseY)); //for debug let dx = mouseX-player.x; let dy = mouseY-player.y; diff --git a/public_html/js/render.js b/public_html/js/render.js index dba9def..b56ecca 100644 --- a/public_html/js/render.js +++ b/public_html/js/render.js @@ -19,6 +19,8 @@ map2.src = "./assets/map/map_secondaire.png"; orange_portal.src = "./assets/orange_portal.webp"; blue_portal.src = "./assets/blue_portal.webp"; +const mapImages = [map,map2]; + class Render { constructor(idCanvas) { let canvas = document.getElementById(idCanvas); @@ -92,9 +94,9 @@ class Render { this.ctx.save(); this.ctx.translate(x,y); if(orange) - this.ctx.drawImage(orange_portal,-portalSize/2,-portalSize/2,portalSize,portalSize); + this.ctx.drawImage(orange_portal,0,0,portalSize,portalSize); else - this.ctx.drawImage(blue_portal,-portalSize/2,-portalSize/2,portalSize,portalSize); + this.ctx.drawImage(blue_portal,0,0,portalSize,portalSize); this.ctx.restore(); } @@ -112,7 +114,7 @@ class Render { } else { - background=map2; + background=mapImages[player.z]; } let mapWidth = background.width; @@ -138,7 +140,7 @@ class Render { portals.forEach((portal) => { if(portal.in.z==player.z) this.RenderPortal(portal.in.x,portal.in.y,true); - else if(portal.out.z==player.z) + if(portal.out.z==player.z) this.RenderPortal(portal.out.x,portal.out.y,false); }); }