Conversation
| @@ -0,0 +1,19 @@ | |||
| 0 info it worked if it ends with ok | |||
There was a problem hiding this comment.
This file should be omitted from your repository (add *.log into your .gitignore file).
| res.redirect('/game') | ||
| } | ||
| else { | ||
| res.send('wrong password you, but') |
There was a problem hiding this comment.
We do not want to encourage hackers to keep guessing - a simple failure (perhaps with a 401 response) is considered best practice.
| app.use(cookieParser()); | ||
| app.use(express.static(path.join(__dirname, 'public'))); | ||
| app.use('/game', express.static(path.join(__dirname, 'phaser'))) | ||
| // app.use("/socket.io", express.static(path.join(__dirname, './node_modules/socket.io-client/dist'))); |
| module.exports = app; | ||
| io.on('connection', function (socket) { | ||
| socket.emit('news', { hello: 'world' }); | ||
| // socket.on('ping', function (data) { |
|
|
||
| const port = normalizePort(process.env.PORT || '3000'); | ||
| app.set('port', port); | ||
| // app.set('port', port); |
|
|
||
| const server = http.createServer(app); | ||
|
|
||
| // const server = http.createServer(app); |
|
|
||
| //load jump sound | ||
| game.load.audio('jump', 'assets/jump.wav') | ||
| game.load.image('nyan', 'phaser/assets/NyanCat.png') |
There was a problem hiding this comment.
There's a lot going on in this file. Consider separating individual chunks of logic out - preload could be a function imported from another module, for example, so that the responsibility of this model is just to create the initial main state by importing and aggregating all the smaller pieces.
This particular function could also be cleaned up a little (and made a little easier to update):
const ASSETS = [
{ type: 'image', name: 'nyan', extension: 'png' },
{ type: 'image', name: 'bird', extension: 'png' },
/* etc. */
{ type: 'audio', name: 'jump', extension: 'wav' }
]
const preload = () => ASSETS.forEach( { type, name, extension } =>
game.load( type, `phaser/assets/${name}.${extension}` )
)|
|
||
| // Call the 'jump' function when the spacekey is hit | ||
| const spaceKey = game.input.keyboard.addKey( | ||
| var spaceKey = game.input.keyboard.addKey( |
| // If the bird is out of the screen (too high or too low) | ||
| // Call the 'restartGame' function | ||
| if (sprite.y < 0 || sprite.y > 490) | ||
| if (sprite.y < 0 || sprite.y > 735) |
There was a problem hiding this comment.
Consider declaring all of these magic numbers as constants, with intention revealing names.
| if (i != hole && i != hole + 1 && i != hole + 2) | ||
| this.addOnePipe(400, i * 60 + 10); | ||
| for (var i = 0; i < 12; i++) | ||
| if ((i != holeOne && i != holeOne + 1) && (i != holeTwo && i != holeTwo + 1)) |
There was a problem hiding this comment.
!== is best practice, to avoid possible type coercion bugs
Made a few gameplay changes.
Implemented socket.io so multiple browsers and computers can access the server and send messages between each other.