allcar
This commit is contained in:
parent
84794fe5c3
commit
dbb0e87054
3 changed files with 109 additions and 43 deletions
142
js/class.js
142
js/class.js
|
@ -194,12 +194,14 @@ class Circle
|
||||||
|
|
||||||
class Car
|
class Car
|
||||||
{
|
{
|
||||||
constructor(Renderer, x, y)
|
constructor(Renderer, x, y, type, dir, angle)
|
||||||
{
|
{
|
||||||
|
this.type=type // 0 circule à droite vers le haut
|
||||||
|
// 1 circule vers le bas
|
||||||
this.x=x;
|
this.x=x;
|
||||||
this.y=y;
|
this.y=y;
|
||||||
this.dir=1;
|
this.dir=dir;
|
||||||
this.angle=0;
|
this.angle=angle;
|
||||||
this.tick=1;
|
this.tick=1;
|
||||||
this.Renderer=Renderer;
|
this.Renderer=Renderer;
|
||||||
}
|
}
|
||||||
|
@ -230,51 +232,109 @@ class Car
|
||||||
|
|
||||||
ChangeDirection()
|
ChangeDirection()
|
||||||
{
|
{
|
||||||
if(this.x == 1280 && this.y==75) {
|
if(this.type == 1) {
|
||||||
this.dir=2
|
if(this.x==1247 && this.y==36) {
|
||||||
this.y=60
|
this.dir=3
|
||||||
this.angle=-Math.PI/2
|
this.angle=-Math.PI
|
||||||
} else if(this.y<-40) {
|
} else if(this.x==430 && this.y==36) {
|
||||||
this.dir=2
|
this.dir=4
|
||||||
this.x=947
|
this.angle=Math.PI/2
|
||||||
this.y=1000
|
} else if(this.x==430 && this.y==330) {
|
||||||
} else if(this.x==947 && this.y==875 ) {
|
|
||||||
if(this.pseudoaleatoire()>7) {
|
|
||||||
//tourner à droite
|
//tourner à droite
|
||||||
this.dir=1
|
this.dir=1
|
||||||
this.angle=0
|
this.angle=0
|
||||||
|
} else if(this.x==607 && this.y==330) {
|
||||||
|
if(this.pseudoaleatoire()>5) {
|
||||||
|
//vers le bas
|
||||||
|
this.dir=4
|
||||||
|
this.angle=Math.PI/2
|
||||||
|
}
|
||||||
|
} else if(this.x==1247 && this.y==330) {
|
||||||
|
//vers le bas
|
||||||
|
this.dir=4
|
||||||
|
this.angle=Math.PI/2
|
||||||
|
} else if(this.x==607 && this.y==551) {
|
||||||
|
//vers la gauche
|
||||||
|
this.dir=3
|
||||||
|
this.angle=Math.PI
|
||||||
|
} else if(this.x==190 && this.y==551) {
|
||||||
|
//vers le bas
|
||||||
|
this.dir=4
|
||||||
|
this.angle=Math.PI/2
|
||||||
|
} else if(this.x==190 && this.y==877) {
|
||||||
|
//vers la droite
|
||||||
|
this.dir=1
|
||||||
|
this.angle=0
|
||||||
|
} else if(this.x==907 && this.y==877) {
|
||||||
|
//vers la droite
|
||||||
|
this.dir=4
|
||||||
|
this.angle=Math.PI/2
|
||||||
|
} else if(this.x==1247 && this.y==550) {
|
||||||
|
if(this.pseudoaleatoire()>5) {
|
||||||
|
//vers la gauche
|
||||||
|
this.dir=3
|
||||||
|
this.angle=Math.PI
|
||||||
|
}
|
||||||
|
} else if(this.x==910 && this.y==550) {
|
||||||
|
//vers le bas
|
||||||
|
this.dir=4
|
||||||
|
this.angle=Math.PI/2
|
||||||
|
} else if(this.x==1247 && this.y==840) {
|
||||||
|
//vers la gauche
|
||||||
|
this.dir=3
|
||||||
|
this.angle=Math.PI
|
||||||
|
} else if(this.x==907 && this.y==840) {
|
||||||
|
//vers le bas
|
||||||
|
this.dir=4
|
||||||
|
this.angle=Math.PI/2
|
||||||
}
|
}
|
||||||
} else if(this.x==947 && this.y==839 ) {
|
} else {
|
||||||
if(this.pseudoaleatoire()>4) {
|
if(this.x == 1280 && this.y==75) {
|
||||||
//tourner à gauche
|
this.dir=2
|
||||||
|
this.y=60
|
||||||
|
this.angle=-Math.PI/2
|
||||||
|
} else if(this.y<-40) {
|
||||||
|
this.dir=2
|
||||||
|
this.x=947
|
||||||
|
this.y=1000
|
||||||
|
} else if(this.x==947 && this.y==875 ) {
|
||||||
|
if(this.pseudoaleatoire()>7) {
|
||||||
|
//tourner à droite
|
||||||
|
this.dir=1
|
||||||
|
this.angle=0
|
||||||
|
}
|
||||||
|
} else if(this.x==947 && this.y==839 ) {
|
||||||
|
if(this.pseudoaleatoire()>4) {
|
||||||
|
//tourner à gauche
|
||||||
|
this.dir=3
|
||||||
|
this.angle=-Math.PI
|
||||||
|
}
|
||||||
|
} else if(this.x==947 && this.y==587) {
|
||||||
|
this.dir=1
|
||||||
|
this.angle=0
|
||||||
|
} else if(this.x==1280 && this.y>400) {
|
||||||
|
this.dir=2
|
||||||
|
this.angle=-Math.PI/2
|
||||||
|
} else if(this.x==228 && this.y==839) {
|
||||||
|
this.y==823
|
||||||
|
this.dir=2
|
||||||
|
this.angle=-Math.PI/2
|
||||||
|
} else if(this.x==228 && this.y==587) {
|
||||||
|
this.dir=1
|
||||||
|
this.angle=0
|
||||||
|
} else if(this.x==644 && this.y==587) {
|
||||||
|
this.dir=2
|
||||||
|
this.angle=-Math.PI/2
|
||||||
|
} else if(this.dir==2 && this.y==295) {
|
||||||
this.dir=3
|
this.dir=3
|
||||||
this.angle=-Math.PI
|
this.angle=-Math.PI
|
||||||
|
} else if(this.x==468 && this.y==295) {
|
||||||
|
this.dir=2
|
||||||
|
this.angle=-Math.PI/2
|
||||||
|
} else if(this.x==468 && this.y==75) {
|
||||||
|
this.dir=1
|
||||||
|
this.angle=0
|
||||||
}
|
}
|
||||||
} else if(this.x==947 && this.y==587) {
|
|
||||||
this.dir=1
|
|
||||||
this.angle=0
|
|
||||||
} else if(this.x==1280 && this.y>400) {
|
|
||||||
this.dir=2
|
|
||||||
this.angle=-Math.PI/2
|
|
||||||
} else if(this.x==228 && this.y==839) {
|
|
||||||
this.y==823
|
|
||||||
this.dir=2
|
|
||||||
this.angle=-Math.PI/2
|
|
||||||
} else if(this.x==228 && this.y==587) {
|
|
||||||
this.dir=1
|
|
||||||
this.angle=0
|
|
||||||
} else if(this.x==644 && this.y==587) {
|
|
||||||
this.dir=2
|
|
||||||
this.angle=-Math.PI/2
|
|
||||||
} else if(this.dir==2 && this.y==295) {
|
|
||||||
this.dir=3
|
|
||||||
this.angle=-Math.PI
|
|
||||||
} else if(this.x==468 && this.y==295) {
|
|
||||||
this.dir=2
|
|
||||||
this.angle=-Math.PI/2
|
|
||||||
} else if(this.x==468 && this.y==75) {
|
|
||||||
this.dir=1
|
|
||||||
this.angle=0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,7 +11,13 @@ function CookiePseudo() {
|
||||||
|
|
||||||
Renderer = new Render("canvas", "./assets/map/map7_recadr.png");
|
Renderer = new Render("canvas", "./assets/map/map7_recadr.png");
|
||||||
LB = new LeaderBoard("canvas");
|
LB = new LeaderBoard("canvas");
|
||||||
cars = [new Car(Renderer, 220, 75),new Car(Renderer, 500, 75),new Car(Renderer, 900,75),new Car(Renderer, 228,587),new Car(Renderer, 947,587)]
|
cars = [new Car(Renderer, 220, 75, 0, 1, 0),
|
||||||
|
new Car(Renderer, 500, 75, 0, 1, 0),
|
||||||
|
new Car(Renderer, 900,75, 0, 1, 0),
|
||||||
|
new Car(Renderer, 228,587, 0, 1, 0),
|
||||||
|
new Car(Renderer, 947,587, 0, 1, 0),
|
||||||
|
new Car(Renderer, 1247,600, 1, 4, Math.PI/2),
|
||||||
|
new Car(Renderer, 607,330, 1, 4, Math.PI/2)]
|
||||||
let Net = new Network("ws://129.151.227.50:8080?name="+CookiePseudo(), Renderer);
|
let Net = new Network("ws://129.151.227.50:8080?name="+CookiePseudo(), Renderer);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ class Render {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderCar(x,y, angle) {
|
RenderCar(x,y,angle) {
|
||||||
this.ctx.save();
|
this.ctx.save();
|
||||||
this.ctx.translate(x, y);
|
this.ctx.translate(x, y);
|
||||||
this.ctx.rotate(angle);
|
this.ctx.rotate(angle);
|
||||||
|
|
Loading…
Reference in a new issue