-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'hotfix/v1.1.1-whitespace'
- Loading branch information
Showing
58 changed files
with
5,211 additions
and
5,170 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,44 @@ | ||
/** | ||
File: | ||
RealtimeMultiplayerGame.js | ||
Created By: | ||
Mario Gonzalez | ||
Project: | ||
RealtimeMultiplayerNodeJS | ||
Abstract: | ||
This is the core module for RealtimeMultiplayerGame contains the namespace, and extend method | ||
File: | ||
RealtimeMultiplayerGame.js | ||
Created By: | ||
Mario Gonzalez | ||
Project: | ||
RealtimeMultiplayerNodeJS | ||
Abstract: | ||
This is the core module for RealtimeMultiplayerGame contains the namespace, and extend method | ||
Basic Usage: | ||
This class is not instantiated | ||
Version: | ||
1.0 | ||
*/ | ||
Basic Usage: | ||
This class is not instantiated | ||
Version: | ||
1.0 | ||
*/ | ||
BubbleDots = (typeof BubbleDots === 'undefined') ? {} : BubbleDots; | ||
/** | ||
* Allows a package to create a namespace within RealtimeMultiplayerGame | ||
* From Javascript Patterns book | ||
* @param ns_string | ||
*/ | ||
BubbleDots.namespace = function(ns_string) | ||
{ | ||
var parts = ns_string.split('.'), | ||
parent = BubbleDots, | ||
i = 0; | ||
BubbleDots.namespace = function (ns_string) { | ||
var parts = ns_string.split('.'), | ||
parent = BubbleDots, | ||
i = 0; | ||
|
||
// strip redundant leading global | ||
if (parts[0] === "BubbleDots") { | ||
parts = parts.slice(1); | ||
} | ||
// strip redundant leading global | ||
if (parts[0] === "BubbleDots") { | ||
parts = parts.slice(1); | ||
} | ||
|
||
var len = parts.length, | ||
aPackage = null; | ||
for (i = 0; i < len; i += 1) { | ||
var singlePart = parts[i]; | ||
// create a property if it doesn't exist | ||
if (typeof parent[singlePart] === "undefined") { | ||
parent[singlePart] = {}; | ||
} | ||
parent = parent[singlePart]; | ||
var len = parts.length, | ||
aPackage = null; | ||
for (i = 0; i < len; i += 1) { | ||
var singlePart = parts[i]; | ||
// create a property if it doesn't exist | ||
if (typeof parent[singlePart] === "undefined") { | ||
parent[singlePart] = {}; | ||
} | ||
parent = parent[singlePart]; | ||
|
||
} | ||
return parent; | ||
} | ||
return parent; | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,136 +1,135 @@ | ||
/** | ||
File: | ||
DemoServerGame | ||
Created By: | ||
Mario Gonzalez | ||
Project: | ||
BubbleDots | ||
Abstract: | ||
This is a concrete server instance of our game | ||
Basic Usage: | ||
DemoServerGame = new BubbleDots.DemoServerGame(); | ||
DemoServerGame.start(); | ||
DemoServerGame.explodeEveryone(); | ||
Version: | ||
1.0 | ||
*/ | ||
(function(){ | ||
|
||
BubbleDots.DemoClientGame = function() { | ||
BubbleDots.DemoClientGame.superclass.constructor.call(this); | ||
|
||
this.startGameClock(); | ||
return this; | ||
}; | ||
|
||
BubbleDots.DemoClientGame.prototype = { | ||
setupView: function(images) { | ||
this.view = new BubbleDots.DemoView( images ); | ||
this.view.insertIntoHTMLElementWithId( "gamecontainer" ); | ||
|
||
BubbleDots.DemoClientGame.superclass.setupView.call( this ); | ||
}, | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
tick: function() { | ||
BubbleDots.DemoClientGame.superclass.tick.call(this); | ||
this.view.stats.update(); | ||
this.view.update( this.gameClockReal ); | ||
this.view.textfield.setText( "Ping: " + this.netChannel.getLatency() ); | ||
}, | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
createEntityFromDesc: function(entityDesc) { | ||
|
||
// Create a new BubbleDots entity | ||
var newEntity = new BubbleDots.CircleEntity( entityDesc.entityid, entityDesc.clientid ); | ||
newEntity.position.set( entityDesc.x, entityDesc.y ); | ||
|
||
var entityView = this.view.createEntityView( entityDesc ); | ||
newEntity.setView( entityView ); | ||
|
||
this.fieldController.addEntity( newEntity ); | ||
|
||
// Our own character | ||
if(entityDesc.clientid == this.netChannel.getClientid() && entityDesc.entityType & BubbleDots.Constants.ENTITY_TYPES.PLAYER_ENTITY) { | ||
this.setupClientPlayer( newEntity ); | ||
this.view.setFocusCharacter( entityView ); | ||
} | ||
}, | ||
|
||
/** | ||
* Called when the player that represents this user is created | ||
* @param anEntity | ||
*/ | ||
setupClientPlayer: function( anEntity ) { | ||
anEntity.addTraitAndExecute( new RealtimeMultiplayerGame.controller.traits.KeyboardInputTrait() ); | ||
this.clientCharacter = anEntity; | ||
}, | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
netChannelDidConnect: function (messageData) { | ||
BubbleDots.DemoClientGame.superclass.netChannelDidConnect.call(this, messageData ); | ||
BubbleDots.DemoClientGame.prototype.log("DemoClientGame: Joining Game"); | ||
this.joinGame("Player" + this.netChannel.getClientid() ); // Automatically join the game with some name | ||
}, | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
netChannelDidDisconnect: function (messageData) { | ||
BubbleDots.DemoClientGame.superclass.netChannelDidDisconnect.call(this, messageData ); | ||
BubbleDots.DemoClientGame.prototype.log("DemoClientGame: netChannelDidDisconnect"); // Display disconnect | ||
}, | ||
|
||
/** | ||
* An array containing values received from the entity | ||
* @param {String} singleWorldUpdate | ||
*/ | ||
parseEntityDescriptionArray: function(entityDescAsArray) | ||
{ | ||
var entityDescription = {}; | ||
// It is up to the user to make sure that their objects are following a certain order | ||
// We do this because we need the performance of sending the tiniest strings possible | ||
entityDescription.entityid = entityDescAsArray[0]; | ||
entityDescription.clientid = entityDescAsArray[1]; | ||
entityDescription.entityType = +entityDescAsArray[2]; | ||
entityDescription.x = +entityDescAsArray[3]; | ||
entityDescription.y = +entityDescAsArray[4]; | ||
entityDescription.scale = +entityDescAsArray[5]; | ||
entityDescription.color = entityDescAsArray[6]; | ||
return entityDescription; | ||
}, | ||
|
||
|
||
/** | ||
* This function logs something to the right panel | ||
* @param {Object} An object in the form of: { message: ['Client', 'domReady'] } | ||
*/ | ||
log: (function(){ | ||
var message = function(message){ | ||
var el = document.createElement('p'); | ||
el.innerHTML = '<b>' + esc(message) + ':</b> '; | ||
|
||
// Log if possible | ||
console.log(message); | ||
document.getElementsByTagName('aside')[0].appendChild(el); | ||
document.getElementsByTagName('aside')[0].scrollTop = 1000000; | ||
}; | ||
|
||
var esc = function (msg){ | ||
return msg.replace(/</g, '<').replace(/>/g, '>'); | ||
}; | ||
|
||
return message; | ||
})() | ||
}; | ||
|
||
// extend RealtimeMultiplayerGame.AbstractClientGame | ||
RealtimeMultiplayerGame.extend(BubbleDots.DemoClientGame, RealtimeMultiplayerGame.AbstractClientGame, null); | ||
File: | ||
DemoServerGame | ||
Created By: | ||
Mario Gonzalez | ||
Project: | ||
BubbleDots | ||
Abstract: | ||
This is a concrete server instance of our game | ||
Basic Usage: | ||
DemoServerGame = new BubbleDots.DemoServerGame(); | ||
DemoServerGame.start(); | ||
DemoServerGame.explodeEveryone(); | ||
Version: | ||
1.0 | ||
*/ | ||
(function () { | ||
|
||
BubbleDots.DemoClientGame = function () { | ||
BubbleDots.DemoClientGame.superclass.constructor.call(this); | ||
|
||
this.startGameClock(); | ||
return this; | ||
}; | ||
|
||
BubbleDots.DemoClientGame.prototype = { | ||
setupView: function (images) { | ||
this.view = new BubbleDots.DemoView(images); | ||
this.view.insertIntoHTMLElementWithId("gamecontainer"); | ||
|
||
BubbleDots.DemoClientGame.superclass.setupView.call(this); | ||
}, | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
tick: function () { | ||
BubbleDots.DemoClientGame.superclass.tick.call(this); | ||
this.view.stats.update(); | ||
this.view.update(this.gameClockReal); | ||
this.view.textfield.setText("Ping: " + this.netChannel.getLatency()); | ||
}, | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
createEntityFromDesc: function (entityDesc) { | ||
|
||
// Create a new BubbleDots entity | ||
var newEntity = new BubbleDots.CircleEntity(entityDesc.entityid, entityDesc.clientid); | ||
newEntity.position.set(entityDesc.x, entityDesc.y); | ||
|
||
var entityView = this.view.createEntityView(entityDesc); | ||
newEntity.setView(entityView); | ||
|
||
this.fieldController.addEntity(newEntity); | ||
|
||
// Our own character | ||
if (entityDesc.clientid == this.netChannel.getClientid() && entityDesc.entityType & BubbleDots.Constants.ENTITY_TYPES.PLAYER_ENTITY) { | ||
this.setupClientPlayer(newEntity); | ||
this.view.setFocusCharacter(entityView); | ||
} | ||
}, | ||
|
||
/** | ||
* Called when the player that represents this user is created | ||
* @param anEntity | ||
*/ | ||
setupClientPlayer: function (anEntity) { | ||
anEntity.addTraitAndExecute(new RealtimeMultiplayerGame.controller.traits.KeyboardInputTrait()); | ||
this.clientCharacter = anEntity; | ||
}, | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
netChannelDidConnect: function (messageData) { | ||
BubbleDots.DemoClientGame.superclass.netChannelDidConnect.call(this, messageData); | ||
BubbleDots.DemoClientGame.prototype.log("DemoClientGame: Joining Game"); | ||
this.joinGame("Player" + this.netChannel.getClientid()); // Automatically join the game with some name | ||
}, | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
netChannelDidDisconnect: function (messageData) { | ||
BubbleDots.DemoClientGame.superclass.netChannelDidDisconnect.call(this, messageData); | ||
BubbleDots.DemoClientGame.prototype.log("DemoClientGame: netChannelDidDisconnect"); // Display disconnect | ||
}, | ||
|
||
/** | ||
* An array containing values received from the entity | ||
* @param {String} singleWorldUpdate | ||
*/ | ||
parseEntityDescriptionArray: function (entityDescAsArray) { | ||
var entityDescription = {}; | ||
// It is up to the user to make sure that their objects are following a certain order | ||
// We do this because we need the performance of sending the tiniest strings possible | ||
entityDescription.entityid = entityDescAsArray[0]; | ||
entityDescription.clientid = entityDescAsArray[1]; | ||
entityDescription.entityType = +entityDescAsArray[2]; | ||
entityDescription.x = +entityDescAsArray[3]; | ||
entityDescription.y = +entityDescAsArray[4]; | ||
entityDescription.scale = +entityDescAsArray[5]; | ||
entityDescription.color = entityDescAsArray[6]; | ||
return entityDescription; | ||
}, | ||
|
||
|
||
/** | ||
* This function logs something to the right panel | ||
* @param {Object} An object in the form of: { message: ['Client', 'domReady'] } | ||
*/ | ||
log: (function () { | ||
var message = function (message) { | ||
var el = document.createElement('p'); | ||
el.innerHTML = '<b>' + esc(message) + ':</b> '; | ||
|
||
// Log if possible | ||
console.log(message); | ||
document.getElementsByTagName('aside')[0].appendChild(el); | ||
document.getElementsByTagName('aside')[0].scrollTop = 1000000; | ||
}; | ||
|
||
var esc = function (msg) { | ||
return msg.replace(/</g, '<').replace(/>/g, '>'); | ||
}; | ||
|
||
return message; | ||
})() | ||
}; | ||
|
||
// extend RealtimeMultiplayerGame.AbstractClientGame | ||
RealtimeMultiplayerGame.extend(BubbleDots.DemoClientGame, RealtimeMultiplayerGame.AbstractClientGame, null); | ||
})(); |
Oops, something went wrong.