3D (should be) finished code js/
This commit is contained in:
parent
85690cf305
commit
bbeb66ff83
5 changed files with 27 additions and 9 deletions
|
@ -463,8 +463,15 @@ class Portal
|
||||||
|
|
||||||
class Map
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -25,7 +25,7 @@ function game() {
|
||||||
pnj.update(dt);
|
pnj.update(dt);
|
||||||
})
|
})
|
||||||
|
|
||||||
portals.forEach((portal) => {portal.update();});
|
maps.forEach((m) => {m.update();});
|
||||||
|
|
||||||
updateBullets(dt);
|
updateBullets(dt);
|
||||||
renderer.ReloadAff();
|
renderer.ReloadAff();
|
||||||
|
|
|
@ -20,8 +20,16 @@ let PNJS = [new PNJ(500, 100,0),
|
||||||
new Car(1, 14),
|
new Car(1, 14),
|
||||||
new Car(0, 7),
|
new Car(0, 7),
|
||||||
new Car(0, 15)];
|
new Car(0, 15)];
|
||||||
let portals = [new Portal(100,100,0,500,500,0)];
|
let portals = [new Portal(250,457,0,500,500,0),//O
|
||||||
let maps = [];
|
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));
|
players.push(new Player(-1,-50,-50,-1,"VOITURES",0));
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ class Input {
|
||||||
|
|
||||||
let mouseX = (e.clientX - bounds.x)*this.canvas.width/bounds.width;
|
let mouseX = (e.clientX - bounds.x)*this.canvas.width/bounds.width;
|
||||||
let mouseY = (e.clientY - bounds.y)*this.canvas.height/bounds.height;
|
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 dx = mouseX-player.x;
|
||||||
let dy = mouseY-player.y;
|
let dy = mouseY-player.y;
|
||||||
|
|
|
@ -19,6 +19,8 @@ map2.src = "./assets/map/map_secondaire.png";
|
||||||
orange_portal.src = "./assets/orange_portal.webp";
|
orange_portal.src = "./assets/orange_portal.webp";
|
||||||
blue_portal.src = "./assets/blue_portal.webp";
|
blue_portal.src = "./assets/blue_portal.webp";
|
||||||
|
|
||||||
|
const mapImages = [map,map2];
|
||||||
|
|
||||||
class Render {
|
class Render {
|
||||||
constructor(idCanvas) {
|
constructor(idCanvas) {
|
||||||
let canvas = document.getElementById(idCanvas);
|
let canvas = document.getElementById(idCanvas);
|
||||||
|
@ -92,9 +94,9 @@ class Render {
|
||||||
this.ctx.save();
|
this.ctx.save();
|
||||||
this.ctx.translate(x,y);
|
this.ctx.translate(x,y);
|
||||||
if(orange)
|
if(orange)
|
||||||
this.ctx.drawImage(orange_portal,-portalSize/2,-portalSize/2,portalSize,portalSize);
|
this.ctx.drawImage(orange_portal,0,0,portalSize,portalSize);
|
||||||
else
|
else
|
||||||
this.ctx.drawImage(blue_portal,-portalSize/2,-portalSize/2,portalSize,portalSize);
|
this.ctx.drawImage(blue_portal,0,0,portalSize,portalSize);
|
||||||
this.ctx.restore();
|
this.ctx.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +114,7 @@ class Render {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
background=map2;
|
background=mapImages[player.z];
|
||||||
}
|
}
|
||||||
|
|
||||||
let mapWidth = background.width;
|
let mapWidth = background.width;
|
||||||
|
@ -138,7 +140,7 @@ class Render {
|
||||||
portals.forEach((portal) => {
|
portals.forEach((portal) => {
|
||||||
if(portal.in.z==player.z)
|
if(portal.in.z==player.z)
|
||||||
this.RenderPortal(portal.in.x,portal.in.y,true);
|
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);
|
this.RenderPortal(portal.out.x,portal.out.y,false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue