Skip to content

Commit 58d64f7

Browse files
Merge pull request #11 from brendonjohn/master
Update core to work with socket.io 0.9.16
2 parents 0653f43 + fa7b707 commit 58d64f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+5287
-5234
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
*.iws
55
.idea/
66
.DS_Store
7+
8+
/node_modules

DemoBox2DApp.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<!--lib-->
2727
<script src="js/lib/caat.js"></script>
2828
<script src="js/lib/Stats.js"></script>
29-
<script src="js/lib/socket.io.js"></script>
29+
<script src="node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js"></script>
3030
<script src="js/lib/SortedLookupTable.js"></script>
3131
<script src="js/lib/RequestAnimationFrame.js"></script>
3232

DemoBubbleDots.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<!--lib-->
2727
<script src="js/lib/caat.js"></script>
2828
<script src="js/lib/Stats.js"></script>
29-
<script src="js/lib/socket.io.js"></script>
29+
<script src="node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js"></script>
3030
<script src="js/lib/SortedLookupTable.js"></script>
3131
<script src="js/lib/RequestAnimationFrame.js"></script>
3232

DemoCircles.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<!--lib-->
2727
<script src="js/lib/caat.js"></script>
2828
<script src="js/lib/Stats.js"></script>
29-
<script src="js/lib/socket.io.js"></script>
29+
<script src="node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js"></script>
3030
<script src="js/lib/SortedLookupTable.js"></script>
3131
<script src="js/lib/RequestAnimationFrame.js"></script>
3232

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ https://vimeo.com/24149718
55

66
# How to use
77
1. Download this repo
8-
2. In the terminal type "node js/DemoHelloWorld/server.js"
9-
3. Browse to "/DemoHelloWorld.html"
8+
2. In the terminal, navigate to the root directory of the repo
9+
3. Run "npm install"
10+
4. Run "node js/DemoBox2D/server.js"
11+
5. Within another terminal, navigate to the root directory and run "python -m SimpleHTTPServer"
12+
6. From the browser, open "http://127.0.0.1:8000/DemoBox2DApp.html"
1013

1114
[![DemoBox2D](http://farm6.static.flickr.com/5105/5694643562_fffce8b9cf_z.jpg)](http://farm6.static.flickr.com/5105/5694643562_53e54993dd_o.png)
1215

js/BubbleDots/BubbleDotsApp.js

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,44 @@
11
/**
2-
File:
3-
RealtimeMultiplayerGame.js
4-
Created By:
5-
Mario Gonzalez
6-
Project:
7-
RealtimeMultiplayerNodeJS
8-
Abstract:
9-
This is the core module for RealtimeMultiplayerGame contains the namespace, and extend method
2+
File:
3+
RealtimeMultiplayerGame.js
4+
Created By:
5+
Mario Gonzalez
6+
Project:
7+
RealtimeMultiplayerNodeJS
8+
Abstract:
9+
This is the core module for RealtimeMultiplayerGame contains the namespace, and extend method
1010
11-
Basic Usage:
12-
This class is not instantiated
13-
Version:
14-
1.0
15-
*/
11+
Basic Usage:
12+
This class is not instantiated
13+
Version:
14+
1.0
15+
*/
1616
BubbleDots = (typeof BubbleDots === 'undefined') ? {} : BubbleDots;
1717
/**
1818
* Allows a package to create a namespace within RealtimeMultiplayerGame
1919
* From Javascript Patterns book
2020
* @param ns_string
2121
*/
22-
BubbleDots.namespace = function(ns_string)
23-
{
24-
var parts = ns_string.split('.'),
25-
parent = BubbleDots,
26-
i = 0;
22+
BubbleDots.namespace = function (ns_string) {
23+
var parts = ns_string.split('.'),
24+
parent = BubbleDots,
25+
i = 0;
2726

28-
// strip redundant leading global
29-
if (parts[0] === "BubbleDots") {
30-
parts = parts.slice(1);
31-
}
27+
// strip redundant leading global
28+
if (parts[0] === "BubbleDots") {
29+
parts = parts.slice(1);
30+
}
3231

33-
var len = parts.length,
34-
aPackage = null;
35-
for (i = 0; i < len; i += 1) {
36-
var singlePart = parts[i];
37-
// create a property if it doesn't exist
38-
if (typeof parent[singlePart] === "undefined") {
39-
parent[singlePart] = {};
40-
}
41-
parent = parent[singlePart];
32+
var len = parts.length,
33+
aPackage = null;
34+
for (i = 0; i < len; i += 1) {
35+
var singlePart = parts[i];
36+
// create a property if it doesn't exist
37+
if (typeof parent[singlePart] === "undefined") {
38+
parent[singlePart] = {};
39+
}
40+
parent = parent[singlePart];
4241

43-
}
44-
return parent;
42+
}
43+
return parent;
4544
};

js/BubbleDots/BubbleDotsClientGame.js

Lines changed: 133 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,135 @@
11
/**
2-
File:
3-
DemoServerGame
4-
Created By:
5-
Mario Gonzalez
6-
Project:
7-
BubbleDots
8-
Abstract:
9-
This is a concrete server instance of our game
10-
Basic Usage:
11-
DemoServerGame = new BubbleDots.DemoServerGame();
12-
DemoServerGame.start();
13-
DemoServerGame.explodeEveryone();
14-
Version:
15-
1.0
16-
*/
17-
(function(){
18-
19-
BubbleDots.DemoClientGame = function() {
20-
BubbleDots.DemoClientGame.superclass.constructor.call(this);
21-
22-
this.startGameClock();
23-
return this;
24-
};
25-
26-
BubbleDots.DemoClientGame.prototype = {
27-
setupView: function(images) {
28-
this.view = new BubbleDots.DemoView( images );
29-
this.view.insertIntoHTMLElementWithId( "gamecontainer" );
30-
31-
BubbleDots.DemoClientGame.superclass.setupView.call( this );
32-
},
33-
34-
/**
35-
* @inheritDoc
36-
*/
37-
tick: function() {
38-
BubbleDots.DemoClientGame.superclass.tick.call(this);
39-
this.view.stats.update();
40-
this.view.update( this.gameClockReal );
41-
this.view.textfield.setText( "Ping: " + this.netChannel.getLatency() );
42-
},
43-
44-
/**
45-
* @inheritDoc
46-
*/
47-
createEntityFromDesc: function(entityDesc) {
48-
49-
// Create a new BubbleDots entity
50-
var newEntity = new BubbleDots.CircleEntity( entityDesc.entityid, entityDesc.clientid );
51-
newEntity.position.set( entityDesc.x, entityDesc.y );
52-
53-
var entityView = this.view.createEntityView( entityDesc );
54-
newEntity.setView( entityView );
55-
56-
this.fieldController.addEntity( newEntity );
57-
58-
// Our own character
59-
if(entityDesc.clientid == this.netChannel.getClientid() && entityDesc.entityType & BubbleDots.Constants.ENTITY_TYPES.PLAYER_ENTITY) {
60-
this.setupClientPlayer( newEntity );
61-
this.view.setFocusCharacter( entityView );
62-
}
63-
},
64-
65-
/**
66-
* Called when the player that represents this user is created
67-
* @param anEntity
68-
*/
69-
setupClientPlayer: function( anEntity ) {
70-
anEntity.addTraitAndExecute( new RealtimeMultiplayerGame.controller.traits.KeyboardInputTrait() );
71-
this.clientCharacter = anEntity;
72-
},
73-
74-
/**
75-
* @inheritDoc
76-
*/
77-
netChannelDidConnect: function (messageData) {
78-
BubbleDots.DemoClientGame.superclass.netChannelDidConnect.call(this, messageData );
79-
BubbleDots.DemoClientGame.prototype.log("DemoClientGame: Joining Game");
80-
this.joinGame("Player" + this.netChannel.getClientid() ); // Automatically join the game with some name
81-
},
82-
83-
/**
84-
* @inheritDoc
85-
*/
86-
netChannelDidDisconnect: function (messageData) {
87-
BubbleDots.DemoClientGame.superclass.netChannelDidDisconnect.call(this, messageData );
88-
BubbleDots.DemoClientGame.prototype.log("DemoClientGame: netChannelDidDisconnect"); // Display disconnect
89-
},
90-
91-
/**
92-
* An array containing values received from the entity
93-
* @param {String} singleWorldUpdate
94-
*/
95-
parseEntityDescriptionArray: function(entityDescAsArray)
96-
{
97-
var entityDescription = {};
98-
// It is up to the user to make sure that their objects are following a certain order
99-
// We do this because we need the performance of sending the tiniest strings possible
100-
entityDescription.entityid = entityDescAsArray[0];
101-
entityDescription.clientid = entityDescAsArray[1];
102-
entityDescription.entityType = +entityDescAsArray[2];
103-
entityDescription.x = +entityDescAsArray[3];
104-
entityDescription.y = +entityDescAsArray[4];
105-
entityDescription.scale = +entityDescAsArray[5];
106-
entityDescription.color = entityDescAsArray[6];
107-
return entityDescription;
108-
},
109-
110-
111-
/**
112-
* This function logs something to the right panel
113-
* @param {Object} An object in the form of: { message: ['Client', 'domReady'] }
114-
*/
115-
log: (function(){
116-
var message = function(message){
117-
var el = document.createElement('p');
118-
el.innerHTML = '<b>' + esc(message) + ':</b> ';
119-
120-
// Log if possible
121-
console.log(message);
122-
document.getElementsByTagName('aside')[0].appendChild(el);
123-
document.getElementsByTagName('aside')[0].scrollTop = 1000000;
124-
};
125-
126-
var esc = function (msg){
127-
return msg.replace(/</g, '&lt;').replace(/>/g, '&gt;');
128-
};
129-
130-
return message;
131-
})()
132-
};
133-
134-
// extend RealtimeMultiplayerGame.AbstractClientGame
135-
RealtimeMultiplayerGame.extend(BubbleDots.DemoClientGame, RealtimeMultiplayerGame.AbstractClientGame, null);
2+
File:
3+
DemoServerGame
4+
Created By:
5+
Mario Gonzalez
6+
Project:
7+
BubbleDots
8+
Abstract:
9+
This is a concrete server instance of our game
10+
Basic Usage:
11+
DemoServerGame = new BubbleDots.DemoServerGame();
12+
DemoServerGame.start();
13+
DemoServerGame.explodeEveryone();
14+
Version:
15+
1.0
16+
*/
17+
(function () {
18+
19+
BubbleDots.DemoClientGame = function () {
20+
BubbleDots.DemoClientGame.superclass.constructor.call(this);
21+
22+
this.startGameClock();
23+
return this;
24+
};
25+
26+
BubbleDots.DemoClientGame.prototype = {
27+
setupView: function (images) {
28+
this.view = new BubbleDots.DemoView(images);
29+
this.view.insertIntoHTMLElementWithId("gamecontainer");
30+
31+
BubbleDots.DemoClientGame.superclass.setupView.call(this);
32+
},
33+
34+
/**
35+
* @inheritDoc
36+
*/
37+
tick: function () {
38+
BubbleDots.DemoClientGame.superclass.tick.call(this);
39+
this.view.stats.update();
40+
this.view.update(this.gameClockReal);
41+
this.view.textfield.setText("Ping: " + this.netChannel.getLatency());
42+
},
43+
44+
/**
45+
* @inheritDoc
46+
*/
47+
createEntityFromDesc: function (entityDesc) {
48+
49+
// Create a new BubbleDots entity
50+
var newEntity = new BubbleDots.CircleEntity(entityDesc.entityid, entityDesc.clientid);
51+
newEntity.position.set(entityDesc.x, entityDesc.y);
52+
53+
var entityView = this.view.createEntityView(entityDesc);
54+
newEntity.setView(entityView);
55+
56+
this.fieldController.addEntity(newEntity);
57+
58+
// Our own character
59+
if (entityDesc.clientid == this.netChannel.getClientid() && entityDesc.entityType & BubbleDots.Constants.ENTITY_TYPES.PLAYER_ENTITY) {
60+
this.setupClientPlayer(newEntity);
61+
this.view.setFocusCharacter(entityView);
62+
}
63+
},
64+
65+
/**
66+
* Called when the player that represents this user is created
67+
* @param anEntity
68+
*/
69+
setupClientPlayer: function (anEntity) {
70+
anEntity.addTraitAndExecute(new RealtimeMultiplayerGame.controller.traits.KeyboardInputTrait());
71+
this.clientCharacter = anEntity;
72+
},
73+
74+
/**
75+
* @inheritDoc
76+
*/
77+
netChannelDidConnect: function (messageData) {
78+
BubbleDots.DemoClientGame.superclass.netChannelDidConnect.call(this, messageData);
79+
BubbleDots.DemoClientGame.prototype.log("DemoClientGame: Joining Game");
80+
this.joinGame("Player" + this.netChannel.getClientid()); // Automatically join the game with some name
81+
},
82+
83+
/**
84+
* @inheritDoc
85+
*/
86+
netChannelDidDisconnect: function (messageData) {
87+
BubbleDots.DemoClientGame.superclass.netChannelDidDisconnect.call(this, messageData);
88+
BubbleDots.DemoClientGame.prototype.log("DemoClientGame: netChannelDidDisconnect"); // Display disconnect
89+
},
90+
91+
/**
92+
* An array containing values received from the entity
93+
* @param {String} singleWorldUpdate
94+
*/
95+
parseEntityDescriptionArray: function (entityDescAsArray) {
96+
var entityDescription = {};
97+
// It is up to the user to make sure that their objects are following a certain order
98+
// We do this because we need the performance of sending the tiniest strings possible
99+
entityDescription.entityid = entityDescAsArray[0];
100+
entityDescription.clientid = entityDescAsArray[1];
101+
entityDescription.entityType = +entityDescAsArray[2];
102+
entityDescription.x = +entityDescAsArray[3];
103+
entityDescription.y = +entityDescAsArray[4];
104+
entityDescription.scale = +entityDescAsArray[5];
105+
entityDescription.color = entityDescAsArray[6];
106+
return entityDescription;
107+
},
108+
109+
110+
/**
111+
* This function logs something to the right panel
112+
* @param {Object} An object in the form of: { message: ['Client', 'domReady'] }
113+
*/
114+
log: (function () {
115+
var message = function (message) {
116+
var el = document.createElement('p');
117+
el.innerHTML = '<b>' + esc(message) + ':</b> ';
118+
119+
// Log if possible
120+
console.log(message);
121+
document.getElementsByTagName('aside')[0].appendChild(el);
122+
document.getElementsByTagName('aside')[0].scrollTop = 1000000;
123+
};
124+
125+
var esc = function (msg) {
126+
return msg.replace(/</g, '&lt;').replace(/>/g, '&gt;');
127+
};
128+
129+
return message;
130+
})()
131+
};
132+
133+
// extend RealtimeMultiplayerGame.AbstractClientGame
134+
RealtimeMultiplayerGame.extend(BubbleDots.DemoClientGame, RealtimeMultiplayerGame.AbstractClientGame, null);
136135
})();

0 commit comments

Comments
 (0)