Skip to content
Snippets Groups Projects
Commit 36d6821c authored by Julien Bouin's avatar Julien Bouin
Browse files

re ajout de l'inerti (coté serveur)

parent d13af282
No related branches found
No related tags found
No related merge requests found
...@@ -23,10 +23,10 @@ export class Avatar { ...@@ -23,10 +23,10 @@ export class Avatar {
this.x = 0; this.x = 0;
this.vies = 3; this.vies = 3;
this.click = []; this.click = [];
this.vitesse = 5; this.vitesse = 1;
this.projectiles = []; this.projectiles = [];
this.hitbox = new Hitbox(68, 145, this.x, this.y); this.hitbox = new Hitbox(68, 145, this.x, this.y);
this.inertie = 0.95; this.inertie = 0.9;
this.momentumX = 0; this.momentumX = 0;
this.momentumY = 0; this.momentumY = 0;
this.canvasSize = canvasSize; this.canvasSize = canvasSize;
...@@ -104,29 +104,51 @@ export class Avatar { ...@@ -104,29 +104,51 @@ export class Avatar {
deplacer() { deplacer() {
if (this.click[37]) { if (this.click[37]) {
//if (this.x > 0) { if (this.x > 0) {
this.x -= this.vitesse; this.x -= this.vitesse;
this.hitbox.x -= this.vitesse; this.hitbox.x -= this.vitesse;
//} this.momentumX -= this.vitesse;
}
} }
if (this.click[39]) { if (this.click[39]) {
//if (this.x < this.canvas.width - this.image.width) { if (this.x < this.canvasSize.width - 68) {
this.x += this.vitesse; this.x += this.vitesse;
this.hitbox.x += this.vitesse; this.hitbox.x += this.vitesse;
//} this.momentumX += this.vitesse;
}
} }
if (this.click[38]) { if (this.click[38]) {
//if (this.y > 0) { if (this.y > 0) {
this.y -= this.vitesse; this.y -= this.vitesse;
this.hitbox.y -= this.vitesse; this.hitbox.y -= this.vitesse;
//} this.momentumY -= this.vitesse;
}
} }
if (this.click[40]) { if (this.click[40]) {
//if (this.y < this.canvas.height - this.image.height) { if (this.y < this.canvasSize.height - 145) {
this.y += this.vitesse; this.y += this.vitesse;
this.hitbox.y += this.vitesse; this.hitbox.y += this.vitesse;
// } this.momentumY += this.vitesse;
}
} }
if (
(this.x >= 0 && this.momentumX <= 0) ||
(this.x <= this.canvasSize.width - 68 && this.momentumX >= 0)
) {
this.x += this.momentumX;
this.hitbox.x = this.x;
}
if (
(this.y >= 0 && this.momentumY <= 0) ||
(this.y <= this.canvasSize.height - 145 && this.momentumY >= 0)
) {
this.y += this.momentumY;
this.hitbox.y = this.y;
}
this.momentumX *= this.inertie;
this.momentumY *= this.inertie;
} }
perdreVie() { perdreVie() {
......
...@@ -9,14 +9,13 @@ import timer from './timer.js'; ...@@ -9,14 +9,13 @@ import timer from './timer.js';
const app = express(); const app = express();
let canvasSize=new Coordinate(1920,1261); let canvasSize = new Coordinate(1920, 1261);
let canLostLifeAvatar = true; let canLostLifeAvatar = true;
let canLostLifeEnemi = true; let canLostLifeEnemi = true;
let t = new timer(); let t = new timer();
const httpServer = http.createServer(app); const httpServer = http.createServer(app);
const fileOptions = { root: process.cwd() }; const fileOptions = { root: process.cwd() };
addWebpackMiddleware(app); addWebpackMiddleware(app);
...@@ -36,13 +35,11 @@ httpServer.listen(port, () => { ...@@ -36,13 +35,11 @@ httpServer.listen(port, () => {
console.log(`Server running at http://localhost:${port}/`); console.log(`Server running at http://localhost:${port}/`);
}); });
setInterval(function () { setInterval(function () {
t.addTime(); t.addTime();
io.emit("timer",t.getMin(),t.getSec()); io.emit('timer', t.getMin(), t.getSec());
}, 1000); }, 1000);
const avatars = []; const avatars = [];
const enemis = []; const enemis = [];
...@@ -94,9 +91,8 @@ io.on('connection', socket => { ...@@ -94,9 +91,8 @@ io.on('connection', socket => {
}); });
let spawnIntervalLV1 = setInterval(() => { let spawnIntervalLV1 = setInterval(() => {
if (t.getMin() > 1) {
if(t.getMin()>1){ LVL2start = true;
LVL2start=true;
} }
let randomY = Math.random() * (canvasSize.height - 0) + 0; let randomY = Math.random() * (canvasSize.height - 0) + 0;
...@@ -113,7 +109,7 @@ let spawnIntervalLV2 = setInterval(() => { ...@@ -113,7 +109,7 @@ let spawnIntervalLV2 = setInterval(() => {
do { do {
randomY = Math.random() * (canvasSize.height - 0) + 0; randomY = Math.random() * (canvasSize.height - 0) + 0;
} while (randomY > canvasSize.height - 100); } while (randomY > canvasSize.height - 100);
const newEnemy = new enemi(canvasSize.width-100 , randomY, 1, 2); const newEnemy = new enemi(canvasSize.width - 100, randomY, 1, 2);
enemis.push(newEnemy); enemis.push(newEnemy);
} }
}, 800); }, 800);
...@@ -123,9 +119,9 @@ setInterval(() => { ...@@ -123,9 +119,9 @@ setInterval(() => {
let avatarData = []; let avatarData = [];
avatars.forEach(avatar => { avatars.forEach(avatar => {
avatar.canvasSize = canvasSize;
enemis.forEach(enemi => { enemis.forEach(enemi => {
if (LVL2start) { if (LVL2start) {
enemi.setVx(10); enemi.setVx(10);
enemi.setVy(4); enemi.setVy(4);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment