This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function setupMatch(opts) { | |
| $("#waiter").remove(); | |
| initMatch(opts); | |
| performCountdown(3, startGame); | |
| }; | |
| // Initial setup of the match state | |
| function initMatch(opts) { | |
| pongR.game = new Game(opts.PlayRoomId, opts.Player1, opts.Player2, opts.BallDirection); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function updatePhysics() { | |
| // 1: updates self position and direction | |
| if (!pongR.updateTimestamp) { // The first time this loop runs, pongR.updateTimestamp will be undefined | |
| pongR.updateTimestamp = new Date().getTime(); | |
| } | |
| else { | |
| var now = new Date().getTime(); | |
| pongR.deltaTime = (now - pongR.updateTimestamp) / 1000; | |
| //console.log("Delta time: " + pongR.deltaTime + ". Now: " + now + ", previous update: " + pongR.updateTimestamp); | |
| pongR.updateTimestamp = now; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Starts the client update loop | |
| function startUpdateLoop() { | |
| if (pongR.goalTimestamp) { | |
| var now = new Date().getTime(); | |
| var timelapse = (now - pongR.goalTimestamp) / 1000; // in seconds | |
| if (timelapse > pongR.settings.PAUSE_AFTER_GOAL) { // TODO Change here to adjust with network latency | |
| pongR.goalTimestamp = undefined; | |
| updateLoopStep(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // A single step of the client update loop (a frame) | |
| function updateLoopStep() { | |
| // Step 1: Clear canvas | |
| pongR.canvasContext.clearRect(0, 0, pongR.settings.viewport.width, pongR.settings.viewport.height); | |
| // Step 2: Handle user inputs (update internal model) | |
| var playerInput = handleClientInputs(pongR.me); | |
| if (playerInput !== null) { | |
| // Step 3: Send the just processed input batch to the server. | |
| sendInput(pongR.game.gameId, pongR.me.user.connectionId, playerInput); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function updateGame(updatePacket) { | |
| var goal = false; | |
| if (pongR.game.player1.score() < updatePacket.Game.Player1.Score) { | |
| goal = true; | |
| } | |
| else if (pongR.game.player2.score() < updatePacket.Game.Player2.Score) { | |
| goal = true; | |
| } | |
| var remoteMe = pongR.me.playerNumber === 1 ? updatePacket.Game.Player1 : updatePacket.Game.Player2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function setup(app, handlers) { | |
| app.post('/api/profiles', handlers.account.createAccount); | |
| app.get('/api/profiles/:username', handlers.account.getAccount); | |
| app.put('/api/profiles/:username', handlers.account.updateAccount); | |
| app.del('/api/profiles/:username', handlers.account.deleteAccount); | |
| app.post('/api/lists', handlers.list.createShoppingList); | |
| app.post('/api/lists/:id', handlers.list.createShoppingList); | |
| app.put('/api/lists/:id', handlers.list.updateShoppingList); | |
| app.get('/api/lists/:userId', handlers.list.getShoppingLists); | |
| app.del('/api/lists/:id', handlers.list.deleteShoppingList); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = { | |
| "db": { | |
| "mongodb": "mongodb://username:password@dsXXXXX.mongolab.com:45077/databasename" | |
| }, | |
| "logger": { | |
| "api": "logs/api.log", | |
| "exception": "logs/exceptions.log" | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ******************************************************* | |
| // expressjs template | |
| // | |
| // assumes: npm install express | |
| // defaults to jade engine, install others as needed | |
| // | |
| // assumes these subfolders: | |
| // public/ | |
| // public/javascripts/ | |
| // public/stylesheets/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var config = require('./Config-debug'); | |
| var winston = require('winston'); | |
| var mongoose = require('mongoose'); | |
| var server = require('./Server'); | |
| // We will log normal api operations into api.log | |
| console.log("starting logger..."); | |
| winston.add(winston.transports.File, { | |
| filename: config.logger.api | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var should = require('should'); | |
| var assert = require('assert'); | |
| var request = require('supertest'); | |
| var mongoose = require('mongoose'); | |
| var winston = require('winston'); | |
| var config = require('./config-debug'); | |
| describe('Routing', function() { | |
| var url = 'http://someurl.com'; | |
| // within before() you can run all the operations that are needed to setup your tests. In this case |