From 4037b3e23da5b4ac9c2399f957245c8360d114e2 Mon Sep 17 00:00:00 2001 From: killianmarty Date: Wed, 15 Nov 2023 13:15:32 +0100 Subject: [PATCH] organiser --- class.js | 186 ------------------------------------------------------ game.js | 29 --------- render.js | 40 ------------ 3 files changed, 255 deletions(-) delete mode 100644 class.js delete mode 100644 game.js delete mode 100644 render.js diff --git a/class.js b/class.js deleted file mode 100644 index 1d0aa47..0000000 --- a/class.js +++ /dev/null @@ -1,186 +0,0 @@ -let mapWidth = 210.; -let mapHeith = 100.; -const playerSize = 50.; -const playerSpeed=2.; -const halfSqrtTwo=0.70710678118; -class Player -{ - constructor (id,x,y,name) - { - this.name=name; - this.x=x; - this.y=y; - this.id=id; - this.visibleDir=1; - this.dir=0;//0=standStill - //1=North - //2=North-East - //3=East - //4=South-East - //5=South - //6=South-West - //7=West - //8=North-West - this.ammo=10; - this.health=10; - } - - takeDamage(amount) - { - this.health-=amount; - if(this.health<=0) - { - //send death message to server - //this.reset() - } - } - - retrieveServerInfo(id,x,y,dir) - { - if(this.id==id) - { - this.x=x; - this.y=y; - this.dir=dir; - if(dir!=0) - this.visibleDir=dir; - } - } - - update(squares,circles)//update position - { - if(this.dir==0) - return; - - let dx,dy; - switch(this.dir) - { - case 1: dx=0.;dy=-playerSpeed;break; - case 2: dx=halfSqrtTwo*playerSpeed;dy=-halfSqrtTwo*playerSpeed;break; - case 3: dx=playerSpeed;dy=0.;break; - case 4: dx=halfSqrtTwo*playerSpeed;dy=halfSqrtTwo*playerSpeed;break; - case 5: dx=0.;dy=playerSpeed;break; - case 6: dx=-halfSqrtTwo*playerSpeed;dy=halfSqrtTwo*playerSpeed;break; - case 7: dx=-playerSpeed;dy=0.;break; - case 8: dx=-halfSqrtTwo*playerSpeed;dy=-halfSqrtTwo*playerSpeed;break; - default: - } - this.x += dx; - this.y += dy; - - for(let square in squares) - { - if(square.collide(this)) - { - this.x-=dx; - this.y-=dy; - this.dir=0; - return; - } - } - for(let circle in circles) - { - if(circle.collide(this)) - { - this.x-=dx; - this.y-=dy; - this.dir=0; - return; - } - } - } - - get angle() - { - return (this.visibleDir-3)*3.1415926535/4.; - } -} - -function dist(A,B) -{ - return sqrt((A.x-B.x)**2+(A.y-B.y)**2); -} - -class Bullet -{ - constructor (x,y,dx,dy) - { - this.x=x; - this.y=y; - this.dx=dx; - this.dy=dy; - this.deleted=false; - } - - update() - { - if(!this.deleted) - { - this.x+=this.dx; - this.y+=this.dy; - } - } - - checkCollisions(player,squares,circles)//only the client's player /!\ - { - if(!this.deleted) - { - if(dist(player,this) { - this.RenderPlayer(player); - }) - } -} \ No newline at end of file