比較提交

..

沒有共同的提交。「87d078a34d04b9dd7c99a63dc4a04702115f7bda」和「a4c8e32a265308baa70257d31d925ddf9ef94983」的歷史完全不同。

共有 6 個檔案被更改,包括 19 行新增41 行删除

未顯示二進位檔案。

查看文件

@ -7,6 +7,9 @@ const bulletSpeed=playerSpeed*2;
const halfSqrtTwo=0.70710678118; const halfSqrtTwo=0.70710678118;
const defaulthealth=10.; const defaulthealth=10.;
let sound = new Sound("./assets/sounds/");
sound.loadSounds();
class Player class Player
{ {
constructor (id,x,y,name, dir) constructor (id,x,y,name, dir)
@ -111,7 +114,7 @@ class Player
class Bullet class Bullet
{ {
constructor (x,y,dx,dy,id, sound) constructor (x,y,dx,dy,id)
{ {
sound.shoot(); sound.shoot();
this.x=x; this.x=x;
@ -195,9 +198,8 @@ class Circle
class Car class Car
{ {
constructor(Renderer, type, spawn, sound) constructor(Renderer, type, spawn)
{ {
this.sound=sound
this.type=type // 0 circule vers le haut this.type=type // 0 circule vers le haut
// 1 circule vers le bas // 1 circule vers le bas
@ -213,8 +215,6 @@ class Car
this.angle=-Math.PI/2; this.angle=-Math.PI/2;
} }
this.drift=0;
this.spawn=spawn this.spawn=spawn
this.tick=0; this.tick=0;
@ -227,12 +227,7 @@ class Car
{ {
let cx=this.x-carSize/2; let cx=this.x-carSize/2;
let cy=this.y-carSize/2; let cy=this.y-carSize/2;
let collide = (cx<=x && x<=cx+carSize && cy<=y && y<=cy+carSize); return (cx<=x && x<=cx+carSize && cy<=y && y<=cy+carSize);
if(collide) {
this.sound.drift()
this.drift=300;
}
return collide
} }
Update() Update()
@ -257,12 +252,7 @@ class Car
this.y=this.y+this.tick this.y=this.y+this.tick
break; break;
} }
if(this.drift > 0) { this.Renderer.RenderCar(this.x,this.y, this.angle)
this.Renderer.RenderCar(this.x,this.y, this.angle+90)
this.drift--
} else {
this.Renderer.RenderCar(this.x,this.y, this.angle)
}
} }
pseudoaleatoire() { pseudoaleatoire() {

查看文件

@ -11,15 +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");
let sound = new Sound("./assets/sounds/"); cars = [new Car(Renderer, 0, 0),
sound.loadSounds(); new Car(Renderer, 0, 7),
cars = [new Car(Renderer, 0, 0, sound), new Car(Renderer, 1, 7),
new Car(Renderer, 0, 7, sound), new Car(Renderer, 1, 13),
new Car(Renderer, 1, 7, sound), new Car(Renderer, 1, 14),
new Car(Renderer, 1, 13, sound), new Car(Renderer, 0, 15)]
new Car(Renderer, 1, 14, sound), let Net = new Network("ws://129.151.227.50:8080?name="+CookiePseudo(), Renderer);
new Car(Renderer, 0, 15, sound)]
let Net = new Network("ws://129.151.227.50:8080?name="+CookiePseudo(), sound);
let playerId = null; //id of client player let playerId = null; //id of client player
@ -27,7 +25,7 @@ let players = [];
let bullets = []; let bullets = [];
let player = null; let player = null;
Inp = new Input("canvas", Net,Renderer, sound); Inp = new Input("canvas", Net,Renderer);
playerId=Net.playerId; playerId=Net.playerId;
player=Net.clientPlayer; player=Net.clientPlayer;

查看文件

@ -1,5 +1,5 @@
class Input { class Input {
constructor(id, net,renderer, sound) { constructor(id, net,renderer) {
this.keysDown = new Set() this.keysDown = new Set()
this.dir = 0; this.dir = 0;
this.player=null; this.player=null;
@ -23,7 +23,7 @@ class Input {
let dx = this.mouseX-this.player.x; let dx = this.mouseX-this.player.x;
let dy = this.mouseY-this.player.y; let dy = this.mouseY-this.player.y;
let norm = Math.sqrt(dx*dx+dy*dy); let norm = Math.sqrt(dx*dx+dy*dy);
let b = new Bullet(this.player.x,this.player.y,dx/norm,dy/norm,this.player.id, sound); let b = new Bullet(this.player.x,this.player.y,dx/norm,dy/norm,this.player.id);
this.bullets.push(b); this.bullets.push(b);
this.renderer.addBullet(b); this.renderer.addBullet(b);

查看文件

@ -1,5 +1,5 @@
class Network{ class Network{
constructor(adress, bulletsound){ constructor(adress){
this.adress = adress; this.adress = adress;
this.connected = false; this.connected = false;
@ -10,7 +10,6 @@ class Network{
this.playersToUpdate = []; this.playersToUpdate = [];
this.bulletsToAdd = []; this.bulletsToAdd = [];
this.deathToAdd = []; this.deathToAdd = [];
this.sound=bulletsound;
} }
message(data){ message(data){
@ -37,8 +36,7 @@ class Network{
this.playersToRemove.push(data.data.id); this.playersToRemove.push(data.data.id);
break; break;
case "newBullet": case "newBullet":
console.log(this.sound) this.bulletsToAdd.push(new Bullet(data.data.x,data.data.y,data.data.dx,data.data.dy,data.data.id));
this.bulletsToAdd.push(new Bullet(data.data.x,data.data.y,data.data.dx,data.data.dy,data.data.id, this.sound));
break; break;
case "died": case "died":
console.log("player",data.data.id,"was killed by",data.data.killerId); console.log("player",data.data.id,"was killed by",data.data.killerId);

查看文件

@ -7,8 +7,6 @@ class Sound{
console.log(this.assetsUrl + "shoot.mp3") console.log(this.assetsUrl + "shoot.mp3")
this.shootSound = new Audio(this.assetsUrl + "shoot.mp3"); this.shootSound = new Audio(this.assetsUrl + "shoot.mp3");
this.shootSound.type = "audio/mp3"; this.shootSound.type = "audio/mp3";
this.driftsound = new Audio(this.assetsUrl + "drift.mp3");
this.driftsound.type = "audio/mp3";
} }
shoot(){ shoot(){
@ -16,10 +14,4 @@ class Sound{
this.shootSound.currentTime=0; this.shootSound.currentTime=0;
this.shootSound.play() this.shootSound.play()
} }
drift(){
this.driftsound.pause()
this.driftsound.currentTime=0;
this.driftsound.play()
}
} }