portal's class written but not tested
This commit is contained in:
parent
9f88b162ea
commit
0b89679d4a
2 changed files with 54 additions and 1 deletions
|
@ -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.x<this.in.x+portalSize && player.y>this.in.y && player.y<this.in.y+portalSize)
|
||||
{
|
||||
player.z=thiS.out.z;
|
||||
player.x=this.out.x;
|
||||
player.y=this.out.y;
|
||||
net.update(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Map
|
||||
{
|
||||
constructor(portalsIn, protalsOut,z) // portalsIn/Out : portal teleport In/Out; z: idDimension
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -6,6 +6,8 @@ const imgPnj2 = new Image();
|
|||
const map = new Image();
|
||||
const map_night = new Image();
|
||||
const map2 = new Image();
|
||||
const orange_portal = new Image();
|
||||
const blue_portal = new Image();
|
||||
imgPlayer.src = "./assets/body.png";
|
||||
imgBullet.src = "./assets/bullet.png";
|
||||
imgCar.src = "./assets/car.png";
|
||||
|
@ -14,13 +16,14 @@ imgPnj2.src = "./assets/pnj1.png";
|
|||
map.src = "./assets/map/map_principale.png"
|
||||
map_night.src = "./assets/map/map_principale_nuit.png"
|
||||
map2.src = "./assets/map/map_secondaire.png";
|
||||
orange_portal.src = "./assets/orange_portal.webp";
|
||||
blue_portal.src = "./assets/blue_portal.webp";
|
||||
|
||||
class Render {
|
||||
constructor(idCanvas) {
|
||||
let canvas = document.getElementById(idCanvas);
|
||||
this.ctx = canvas.getContext("2d");
|
||||
this.ctx.imageSmoothingEnabled=false;//does not lerp pixels
|
||||
//this.ReloadAff();
|
||||
}
|
||||
|
||||
RenderPlayer(p,isClient) {
|
||||
|
@ -84,6 +87,17 @@ class Render {
|
|||
}
|
||||
}
|
||||
|
||||
RenderPortal(x,y,orange)
|
||||
{
|
||||
this.ctx.save();
|
||||
this.ctx.translate(x,y);
|
||||
if(orange)
|
||||
this.ctx.drawImage(orange_portal,-portalSize/2,-portalSize/2,portalSize,portalSize);
|
||||
else
|
||||
this.ctx.drawImage(blue_portal,-portalSize/2,-portalSize/2,portalSize,portalSize);
|
||||
this.ctx.restore();
|
||||
}
|
||||
|
||||
ReloadAff() {
|
||||
let background;
|
||||
|
||||
|
@ -119,5 +133,14 @@ class Render {
|
|||
PNJS.forEach((pnj)=>{
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue