diff --git a/client/public/images/boo.png b/client/public/images/boo.png new file mode 100644 index 0000000000000000000000000000000000000000..3d49d9e2fb7f0b04b027c2edcb8680752c0051d6 Binary files /dev/null and b/client/public/images/boo.png differ diff --git a/client/public/index.html b/client/public/index.html index fa95e77f4090b01ac7fc74e47fbeeeddc76a309f..abdd4086a1042b1e1130750682a72ec82ba029a1 100644 --- a/client/public/index.html +++ b/client/public/index.html @@ -21,7 +21,7 @@ <div class="divMain"> <h1>ça geek</h1> <button class="buttonStart">Play</button> - <button class="ScoreBoard">ScoreBoard</button> + <button class="scoreBoard">ScoreBoard</button> <button class="credits">Credits</button> </section> </div> diff --git a/client/src/scoreboard.json b/client/src/scoreboard.json new file mode 100644 index 0000000000000000000000000000000000000000..b0486a39b78a0aeef67674469994b2b16643b751 --- /dev/null +++ b/client/src/scoreboard.json @@ -0,0 +1,17 @@ +{ + "results": [ + { + "nom": "Joueur 1", + "score": 100 + }, + { + "nom": "Joueur 2", + "score": 200 + }, + { + "nom": "Joueur 3", + "score": 150 + } + ] + } + \ No newline at end of file diff --git a/server/enemis.js b/server/enemis.js index 655ef098dfcdcb7a7203a75015c1994b3d5e4022..45aa7ab4fa11595b584bbbe9adecfca5032477d9 100644 --- a/server/enemis.js +++ b/server/enemis.js @@ -12,11 +12,17 @@ export default class enemi extends Entite { constructor(x, y, image, difficulté) { super(x, y, new Hitbox(50 / 2, 66, x, y), image); if (difficulté == 1) { + this.vx = 3; + this.vy = 0; this.hitbox = new Hitbox(69 / 2, 57, this.x, this.y); + } else if (difficulté == 2) { + this.vx = 5; + this.vy = 1; + } else if (difficulté == 3) { + this.vx = 20; + this.vy = 16; } this.difficulté = difficulté; - this.vx = 3; - this.vy = 0; this.vies = 2; this.amplitude = 20; this.direction = 1; @@ -48,14 +54,6 @@ export default class enemi extends Entite { return this.vy; } - setVx(vx) { - this.vx = vx; - } - - setVy(vy) { - this.vy = vy; - } - deplacer() { this.x -= this.vx; this.hitbox.x = this.x; diff --git a/client/src/enemis.test.js b/server/enemis.test.js similarity index 100% rename from client/src/enemis.test.js rename to server/enemis.test.js diff --git a/server/index.js b/server/index.js index c3f5e1e139a77bdcb4d86dc19e852abec89f90c5..9926c8807ca782dbc8c18665d33e854952c61b8c 100644 --- a/server/index.js +++ b/server/index.js @@ -15,6 +15,7 @@ let canvasSize = new Coordinate(1920, 1261); let canLostLifeAvatar = true; let canLostLifeEnemi = true; +let gameStarted = false; let t = new timer(); @@ -32,8 +33,12 @@ httpServer.listen(port, () => { }); setInterval(function () { - t.addTime(); - io.emit('timer', t.getMin(), t.getSec()); + if (gameStarted) { + t.addTime(); + io.emit('timer', t.getMin(), t.getSec()); + } else { + t = new timer(); + } }, 1000); const avatars = []; @@ -43,6 +48,7 @@ const bonusArray = []; let cpt = 0; let canShoot = true; let LVL2start = false; +let LVL3start = false; io.on('connection', socket => { cpt++; @@ -63,6 +69,14 @@ io.on('connection', socket => { console.log(`Déconnexion du client ${socket.id}`); }); + socket.on('start', s => { + if (s == true && cpt != 0) { + gameStarted = s; + } else if (cpt == 0) { + gameStarted = false; + } + }); + socket.on('clickEvent', clickEvent => { const playerAvatar = avatars.find(avatar => avatar.nom === clickEvent.id); if (playerAvatar) { @@ -80,14 +94,10 @@ io.on('connection', socket => { canShoot = false; setTimeout(function () { canShoot = true; - }, 100); + }, 200); } }); - socket.on('LVL2', LVL2start => { - LVL2start = true; - }); - socket.on('canvasSize', canvasSize => { console.log(canvasSize); canvasSize = canvasSize; @@ -96,43 +106,59 @@ io.on('connection', socket => { }); let spawnIntervalLV1 = setInterval(() => { - if (t.getSec() >= 10) { - LVL2start = true; - } + if (gameStarted) { + if (t.getMin() >= 1) { + LVL2start = true; + } + if (t.getSec() >= 30) { + LVL3start = true; + } - let randomY = Math.random() * (canvasSize.height - 0) + 0; - do { - randomY = Math.random() * (canvasSize.height - 0) + 0; - } while (randomY > canvasSize.height - 57); - const newEnemy = new enemi(canvasSize.width, randomY, 0, 1); - enemis.push(newEnemy); + let randomY = Math.random() * (canvasSize.height - 0) + 0; + do { + randomY = Math.random() * (canvasSize.height - 0) + 0; + } while (randomY > canvasSize.height - 57); + const newEnemy = new enemi(canvasSize.width, randomY, 0, 1); + enemis.push(newEnemy); + } }, 1000); let spawnIntervalLV2 = setInterval(() => { - if (LVL2start) { + if (LVL2start && gameStarted) { let randomY = Math.random() * (canvasSize.height - 0) + 0; do { randomY = Math.random() * (canvasSize.height - 0) + 0; } while (randomY > canvasSize.height - 100); const newEnemy = new enemi(canvasSize.width - 100, randomY, 1, 2); - newEnemy.setVx(10); - newEnemy.setVy(4); enemis.push(newEnemy); } }, 800); +let spawnIntervalLV3 = setInterval(() => { + if (LVL3start && gameStarted) { + let randomY = Math.random() * (canvasSize.height - 0) + 0; + do { + randomY = Math.random() * (canvasSize.height - 0) + 0; + } while (randomY > canvasSize.height - 100); + const newEnemy = new enemi(canvasSize.width - 100, randomY, 1, 3); + enemis.push(newEnemy); + } +}, 4000); + let spawnBonusInterval = setInterval(() => { - let randomX; - let randomY; - const choix = Math.floor(Math.random() * bonusNoms.length); - do { - randomY = Math.random() * (canvasSize.height - 0) + 0; - } while (randomY > canvasSize.height - 75); - do { - randomX = Math.random() * (canvasSize.width - 0) + 0; - } while (randomX > canvasSize.width - 75); - const bonus = new Bonus(choix, 1, randomX, randomY, t.getTotalTime()); - bonusArray.push(bonus); + if (gameStarted) { + let randomX; + let randomY; + const choix = Math.floor(Math.random() * bonusNoms.length); + do { + randomY = Math.random() * (canvasSize.height - 0) + 0; + } while (randomY > canvasSize.height - 75); + do { + randomX = Math.random() * (canvasSize.width - 0) + 0; + } while (randomX > canvasSize.width - 75); + const bonus = new Bonus(choix, 1, randomX, randomY, t.getTotalTime()); + bonusArray.push(bonus); + } }, 15000); setInterval(() => {