From 6269c3abc5f45b1b2785170610d622d653151cb9 Mon Sep 17 00:00:00 2001 From: Simon Giesel Date: Fri, 27 Apr 2018 14:24:19 +0200 Subject: [PATCH] Add Scoreboard and splashscreen --- .gitignore | 3 +- assets/SuperMario256.ttf | Bin 0 -> 16312 bytes server.js | 33 ++++- src/views/client.hbs | 20 ++- src/views/server.hbs | 259 +++++++++++++++++++++++++++++---------- 5 files changed, 241 insertions(+), 74 deletions(-) create mode 100644 assets/SuperMario256.ttf diff --git a/.gitignore b/.gitignore index 40b878d..f90a3f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules/ \ No newline at end of file +node_modules/ +scores.json \ No newline at end of file diff --git a/assets/SuperMario256.ttf b/assets/SuperMario256.ttf new file mode 100644 index 0000000000000000000000000000000000000000..5e1ccd4be8420a81cee7dc6cca16dc95aa5ca5a8 GIT binary patch literal 16312 zcmeHu2b@$zw)d&JefxIKak^)^dwP0$a%857!w?2gK$0SZ5+zFx0xB-1MG^CwFyJn@ zYuXh=5YaWP*)`_?t}7@Y#$824=Jxlm>K^d(&D-z&-uk`wzVE%7>Hj_V-nysGIaPJ4 z>fE}-h{yvlP<-&n5o6w7z5fcLzNg~q_+clG8FG63o|U+1!ubUw#?&@k&|3H~5xX7d zlgADmK5o(amECZE9g+IMY4fHmymjvPS-4=_ zt?a`2G@O^rnzwYt;NNtBH-~(jPM^MbK22oHiF$p2`$cmXoHk`w@^whiQ#`}xO3@8_aOL79 z)JpOAz?=+_4Kj;$P3!*0szbY*rQ+eVC`rExE=4M2JQ#B

?9uE!g8u1`!TwCt%pv?1 zWIOoVxjb|@+ws%9|2NL19VbA~nc3aKZm=owqJM*3g{?a6CTs{>=4=Yv!p6eZ!scAq zUepoFp!ZOR zddUs+kq77}FEBtpU{GR+{Gh`W$R42r3IZb(0!AqeETjTpk;E89K*uQxOi&@Pn2NGL zP?BQ65{d&;lmM1WOj9xFGD-r=sRUR-sqA6+l2Tw5rGeEFYp4u#EtLc7r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1wI=;nK`hpwjxnj z%R(iUsStK(`jS<_GZ*^H;+|X`DA_gCTR92s#=BEiihPeKR!>~$o>UrpXLx3%^5TDD z%;3NG`slyP8u{mp4T!dvOQrZ8=}dedb1%N9ILzwUsqB|*6MKf~yaexY=kP1|6Z}i1 zK^d>CR&G_EQw|xr8)g}9GCYK@1bV9D)ic$r)H~H(>eu*Qq0~6qxEOzbFg|tcPixgC zYUgO1wC(si{O|cQbvI2l{mQh%^ggzOH<*W*=a{cG-)r7)@mYFXW?AmEypO%^rPkxE z3$4GkK4;x;^Vmk(mfF_a{$}rOzrcQMgG zd(|qj&#fAA)fFV%XUJb0yA`IA7udi3=qz zlDJsn5{Xg{b(y5kkhomp3W+Nvo+(iF5)0~~irCyKOXth*7>tHJatsG1zgIU2O8(>< dEYKoWRUl?*Xax?`ER+3}$^I&OG5Rmj{{oy&xoiLc literal 0 HcmV?d00001 diff --git a/server.js b/server.js index 435eea1..b9f9441 100644 --- a/server.js +++ b/server.js @@ -6,7 +6,10 @@ const express = require('express'), // wsEngine: 'ws' }), exphbs = require('express-handlebars'), - qrCode = require('branded-qr-code'); + qrCode = require('branded-qr-code'), + fs = require('fs'); + +const scores = JSON.parse(fs.readFileSync('scores.json', 'utf8')); /** CONSTANTS */ const HOST = 'http://100.119.37.224:8080/client/'; @@ -14,11 +17,13 @@ const HOST = 'http://100.119.37.224:8080/client/'; const players = [ { type: 'mario', + name: 'Mario', id: guid(), score: 0 }, { type: 'luigi', + name: 'Luigi', id: guid(), score: 0 }, @@ -95,6 +100,8 @@ clientNSP.on('connection', socket => { setTimeout(() => monitorNSP.emit('updateGameState', 1), 2000); let pl = getPlayerFromId(socket.request.headers.referer.split('/').slice(-1)[0]); + socket.on('changeName', name => pl.name = name); + socket.on('moveStart_left', () => { console.log('moveStart_left: ' + pl.type); monitorNSP.emit('moveStart_left', pl.type); @@ -125,17 +132,37 @@ clientNSP.on('connection', socket => { console.log('moveEnd_crouch: ' + pl.type); }); - socket.on('disconnect', () => { console.log('Client disconnected.'); + count--; monitorNSP.emit('clientDisconnect', getPlayerFromId(id).type); }); }); - +let playerDeaths = 0; monitorNSP.on('connection', socket => { console.log('Monitor connected.'); + socket.emit('handshake', { + scores, + marioId: players[0].id, + luigiId: players[1].id, + }); + socket.on('playerDie', options => { + console.log(options.score) + playerDeaths++; + let pl = players.filter(el => el.type == options.player)[0]; + pl.score = options.score; + if (pl.score > 0) { + scores.push({ name: pl.name, score: pl.score }); + fs.writeFile('scores.json', JSON.stringify(scores)); + } + if (playerDeaths === 2) { + setTimeout(() => { + monitorNSP.emit('handshake', { scores, marioId: players[0].id, luigiId: players[1].id, }); + }, 4000); + } + }); socket.on('disconnect', () => { console.log('Monitor disconnected.'); }); diff --git a/src/views/client.hbs b/src/views/client.hbs index 3c93ae7..e895c05 100644 --- a/src/views/client.hbs +++ b/src/views/client.hbs @@ -48,7 +48,7 @@ background-color: #2196F3; } - button#crouch, + button#name, button#jump { right: 5%; } @@ -58,7 +58,7 @@ background-color: #4CAF50; } - button#crouch { + button#name { bottom: calc(40% / 3); background-color: #E53935; } @@ -100,7 +100,7 @@ - + \ No newline at end of file diff --git a/src/views/server.hbs b/src/views/server.hbs index 6d74c55..9385a28 100644 --- a/src/views/server.hbs +++ b/src/views/server.hbs @@ -7,8 +7,67 @@ padding: 0; } + @font-face { + font-family: Mario; + src: url('/assets/SuperMario256.ttf'); + } + body { overflow-x: hidden; + font-family: Mario; + cursor: none; + } + + h1, + h2, + h3 { + color: #FFC107; + padding: 5%; + text-align: center; + opacity: 1; + transition: opacity .1s ease-in; + text-shadow: -3px -3px #FAFAFA, + 1px 1px #757575, + 2px 2px #757575, + 3px 3px #757575, + 4px 4px #757575, + 5px 5px #757575, + 6px 6px #757575; + } + + h1 { + font-size: 600%; + padding-bottom: 0; + } + + h2 { + padding-top: .5%; + padding-bottom: 0; + font-size: 400%; + } + + h3 { + font-size: 300%; + text-shadow: none; + padding-top: 0; + padding-bottom: 1%; + } + + ol { + padding: 0 5%; + list-style-type: decimal-leading-zero; + width: 90%; + padding-bottom: 2%; + } + + ol li { + font-size: 140%; + text-align: center; + } + + flexbox { + display: flex; + justify-content: space-around; } img.check { @@ -16,20 +75,15 @@ } img.checkmark { - content: ""; display: block; position: absolute; width: 200px; - top: 180px; - left: 680px; + margin-top: 180px; + margin-left: 130px; height: 200px; z-index: 1; } - img.checkmark.left { - left: 140px; - } - img.checkmark.hidden { display: none; } @@ -41,18 +95,31 @@ - - - - Mario - - - - - Luigi - +

Super + MARIO

+

QR-Code scannen um zu spielen

+ + + + + + + + + + + + + + +

Highscores

+ +
    +
      +
        +
        @@ -68,18 +135,17 @@