This commit is contained in:
Baptiste 2023-12-25 18:26:16 +01:00
parent 6ba87b2f4b
commit 4c99a49b3f
2 changed files with 29 additions and 12 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View file

@ -18,6 +18,7 @@ const map7 = new Image();
const map8 = new Image(); const map8 = new Image();
const orange_portal = new Image(); const orange_portal = new Image();
const blue_portal = new Image(); const blue_portal = new Image();
const portal = new Image();
imgPlayer.src = "./assets/body.png"; imgPlayer.src = "./assets/body.png";
imgBullet.src = "./assets/bullet2.png"; imgBullet.src = "./assets/bullet2.png";
imgCar.src = "./assets/car.png"; imgCar.src = "./assets/car.png";
@ -35,6 +36,7 @@ map7.src = "./assets/map/map7.jpg";
map8.src = "./assets/map/map8.jpg"; map8.src = "./assets/map/map8.jpg";
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";
portal.src = "./assets/portal.png";
const mapImages = [map0,map1,map2,map3, map4, map5, map6, map7, map8]; const mapImages = [map0,map1,map2,map3, map4, map5, map6, map7, map8];
@ -43,6 +45,7 @@ class Render {
let canvas = document.getElementById(idCanvas); let canvas = document.getElementById(idCanvas);
this.ctx = canvas.getContext("2d"); this.ctx = canvas.getContext("2d");
this.ctx.imageSmoothingEnabled=false;//does not lerp pixels this.ctx.imageSmoothingEnabled=false;//does not lerp pixels
this.timer=0
} }
RenderPlayer(p,isClient) { RenderPlayer(p,isClient) {
@ -106,17 +109,31 @@ class Render {
} }
} }
RenderPortal(x,y,orange) RenderPortalDebug(x,y,debug)
{ {
this.ctx.save(); this.ctx.save();
this.ctx.translate(x,y); this.ctx.translate(x,y);
if(orange) if(debug) {
this.ctx.drawImage(orange_portal,0,0,portalSize,portalSize); this.ctx.drawImage(orange_portal,0,0,portalSize,portalSize);
else } else {
this.ctx.drawImage(blue_portal,0,0,portalSize,portalSize); this.ctx.drawImage(blue_portal,0,0,portalSize,portalSize);
}
this.ctx.restore(); this.ctx.restore();
} }
RenderPortal(x,y)
{
this.timer=(this.timer+0.1)%360
this.ctx.save();
this.ctx.translate(x+portalSize/2, y+portalSize/2);
this.ctx.rotate(this.timer * Math.PI / 180);
this.ctx.globalAlpha = 0.5;
this.ctx.drawImage(portal, -portalSize / 2, -portalSize / 2, portalSize, portalSize);
this.ctx.globalAlpha = 1;
this.ctx.restore();
}
ReloadAff() { ReloadAff() {
let background; let background;
@ -169,14 +186,14 @@ class Render {
PNJS.forEach((pnj)=>{ PNJS.forEach((pnj)=>{
this.RenderPnj(pnj.x, pnj.y, pnj.z, (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);
}) })
if(drawPortals) 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)
this.RenderPortal(portal.in.x,portal.in.y,true); }
if(portal.out.z==player.z) if(portal.out.z==player.z && drawPortals){
this.RenderPortal(portal.out.x,portal.out.y,false); this.RenderPortalDebug(portal.out.x,portal.out.y,false)
}); }
} });
} }
} }