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