FPS';m.appendChild(g);a=document.createElement("canvas");a.width=74;a.height=30;a.style.display="block";a.style.marginLeft="3px";m.appendChild(a);
5 | p=a.getContext("2d");p.fillStyle="rgb("+b.fps.bg.r+","+b.fps.bg.g+","+b.fps.bg.b+")";p.fillRect(0,0,a.width,a.height);C=p.getImageData(0,0,a.width,a.height);h=document.createElement("div");h.style.backgroundColor="rgb("+Math.floor(b.ms.bg.r/2)+","+Math.floor(b.ms.bg.g/2)+","+Math.floor(b.ms.bg.b/2)+")";h.style.padding="2px 0px 3px 0px";h.style.display="none";e.appendChild(h);i=document.createElement("div");i.style.fontFamily="Helvetica, Arial, sans-serif";i.style.textAlign="left";i.style.fontSize=
6 | "9px";i.style.color="rgb("+b.ms.fg.r+","+b.ms.fg.g+","+b.ms.fg.b+")";i.style.margin="0px 0px 1px 3px";i.innerHTML='MS';h.appendChild(i);a=document.createElement("canvas");a.width=74;a.height=30;a.style.display="block";a.style.marginLeft="3px";h.appendChild(a);r=a.getContext("2d");r.fillStyle="rgb("+b.ms.bg.r+","+b.ms.bg.g+","+b.ms.bg.b+")";r.fillRect(0,0,a.width,a.height);F=r.getImageData(0,0,a.width,a.height);try{if(performance&&performance.memory&&performance.memory.totalJSHeapSize)x=
7 | 3}catch(L){}j=document.createElement("div");j.style.backgroundColor="rgb("+Math.floor(b.mem.bg.r/2)+","+Math.floor(b.mem.bg.g/2)+","+Math.floor(b.mem.bg.b/2)+")";j.style.padding="2px 0px 3px 0px";j.style.display="none";e.appendChild(j);k=document.createElement("div");k.style.fontFamily="Helvetica, Arial, sans-serif";k.style.textAlign="left";k.style.fontSize="9px";k.style.color="rgb("+b.mem.fg.r+","+b.mem.fg.g+","+b.mem.fg.b+")";k.style.margin="0px 0px 1px 3px";k.innerHTML='MEM';
8 | j.appendChild(k);a=document.createElement("canvas");a.width=74;a.height=30;a.style.display="block";a.style.marginLeft="3px";j.appendChild(a);t=a.getContext("2d");t.fillStyle="#301010";t.fillRect(0,0,a.width,a.height);I=t.getImageData(0,0,a.width,a.height);return{domElement:e,update:function(){y++;l=(new Date).getTime();q=l-J;D=Math.min(D,q);E=Math.max(E,q);w(F.data,Math.min(30,30-q/200*30),"ms");i.innerHTML=''+q+" MS ("+D+"-"+E+")";r.putImageData(F,0,0);J=l;if(l>
9 | z+1E3){o=Math.round(y*1E3/(l-z));A=Math.min(A,o);B=Math.max(B,o);w(C.data,Math.min(30,30-o/100*30),"fps");g.innerHTML=''+o+" FPS ("+A+"-"+B+")";p.putImageData(C,0,0);if(x==3){s=performance.memory.usedJSHeapSize*9.54E-7;G=Math.min(G,s);H=Math.max(H,s);w(I.data,Math.min(30,30-s/2),"mem");k.innerHTML=''+Math.round(s)+" MEM ("+Math.round(G)+"-"+Math.round(H)+")";t.putImageData(I,0,0)}z=l;y=0}}}};
10 |
--------------------------------------------------------------------------------
/js/BubbleDots/entities/PlayerEntity.js:
--------------------------------------------------------------------------------
1 | /**
2 | File:
3 | BubbleDots.CircleEntity
4 | Created By:
5 | Mario Gonzalez
6 | Project:
7 | BubbleDots
8 | Abstract:
9 | This is the base entity for the demo game
10 | Basic Usage:
11 |
12 | Version:
13 | 1.0
14 | */
15 | (function () {
16 | var count = 0;
17 | BubbleDots.PlayerEntity = function (anEntityid, aClientid) {
18 | BubbleDots.PlayerEntity.superclass.constructor.call(this, anEntityid, aClientid);
19 | this.entityType = BubbleDots.Constants.ENTITY_TYPES.PLAYER_ENTITY;
20 | this.initThrust();
21 | };
22 |
23 | BubbleDots.PlayerEntity.prototype = {
24 | _isThrusting: false, // We need a better variable name.
25 | _thrustLevel: 0,
26 |
27 | THRUST_DECREMENT: 0.001, // How much to decrease thrust by
28 | THRUST_FORCE: 0.3, // How much force to apply every tick when applying thrust
29 |
30 | initThrust: function () {
31 | this._thrustLevel = 100.0;
32 | this._isThrusting = false;
33 | },
34 |
35 | startThrust: function () {
36 | this._isThrusting = true;
37 | // this.velocity.y *= 0.5;
38 | },
39 |
40 | applyThrust: function () {
41 | this._thrustLevel -= BubbleDots.PlayerEntity.prototype.THRUST_DECREMENT;
42 | if (this._thrustLevel > 0.0) {
43 | this.acceleration.y -= BubbleDots.PlayerEntity.prototype.THRUST_FORCE;
44 | }
45 | },
46 |
47 | stopThrust: function () {
48 | this._isThrusting = false;
49 | },
50 |
51 | /**
52 | * Update position of this entity - this is only called on the serverside
53 | * @param {Number} speedFactor A number signifying how much faster or slower we are moving than the target framerate
54 | * @param {Number} gameClock Current game time in seconds (zero based)
55 | * @param {Number} gameTick Current game tick (incrimented each frame)
56 | */
57 | updatePosition: function (speedFactor, gameClock, gameTick) {
58 | this.handleInput(speedFactor);
59 | BubbleDots.PlayerEntity.superclass.updatePosition.call(this, speedFactor, gameClock, gameTick);
60 | },
61 |
62 | handleInput: function (speedFactor) {
63 | var moveSpeed = 0.2;
64 |
65 | if (this.input.isLeft()) this.acceleration.x -= moveSpeed;
66 | if (this.input.isRight()) this.acceleration.x += moveSpeed;
67 | if (this.input.isDown()) this.acceleration.y += moveSpeed;
68 |
69 | // We're pressing up - apply thrust...
70 | // Call startThrust if we were not thrusting before
71 | if (this.input.isUp()) {
72 | if (!this._isThrusting) {
73 | this.startThrust();
74 | }
75 |
76 | this.applyThrust();
77 | } else if (this._isThrusting) {
78 | this.stopThrust();
79 | } else { // Default behavior - increase _thrustLevel
80 | this._thrustLevel += BubbleDots.PlayerEntity.prototype.THRUST_DECREMENT * 2;
81 | this._thrustLevel = Math.min(this._thrustLevel, 100);
82 | }
83 | },
84 |
85 | ///// ACCESSORS
86 | /**
87 | * Set the CollisionCircle for this game entity.
88 | * @param aCollisionCircle
89 | */
90 | setCollisionCircle: function (aCollisionCircle) {
91 | BubbleDots.PlayerEntity.superclass.setCollisionCircle.call(this, aCollisionCircle);
92 | this.collisionCircle.collisionMask = 2;
93 | this.collisionCircle.collisionGroup = 1;
94 | this.collisionCircle.isFixed = true;
95 | },
96 | setInput: function (input) {
97 | this.input = input;
98 | }
99 | };
100 |
101 | // extend RealtimeMultiplayerGame.model.GameEntity
102 | RealtimeMultiplayerGame.extend(BubbleDots.PlayerEntity, BubbleDots.CircleEntity, null);
103 | })();
--------------------------------------------------------------------------------
/js/DemoHelloWorld/DemoView.js:
--------------------------------------------------------------------------------
1 | /**
2 | File:
3 | AbstractServerGame.js
4 | Created By:
5 | Mario Gonzalez
6 | Project:
7 | RealtimeMultiplayerNodeJS
8 | Abstract:
9 | This class is the base Game controller in RealtimeMultiplayerGame on the server side.
10 | It provides things such as dropping players, and contains a ServerNetChannel
11 | Basic Usage:
12 | [This class is not instantiated! - below is an example of using this class by extending it]
13 |
14 | (function(){
15 | MyGameClass = function() {
16 | return this;
17 | }
18 |
19 | RealtimeMultiplayerGame.extend(MyGameClass, RealtimeMultiplayerGame.AbstractServerGame, null);
20 | };
21 | Version:
22 | 1.0
23 | */
24 | (function () {
25 | DemoHelloWorld.DemoView = function () {
26 | this.setupCAAT();
27 | this.setupStats();
28 | };
29 |
30 | DemoHelloWorld.DemoView.prototype = {
31 | // Properties
32 | caatDirector: null, // CAAT Director instance
33 | caatScene: null, // CAAT Scene instance
34 | stats: null, // Stats.js instance
35 |
36 | // Methods
37 | setupCAAT: function () {
38 | this.caatScene = new CAAT.Scene(); // Create a scene, all directors must have at least one scene - this is where all your stuff goes
39 | this.caatScene.create(); // Notice we call create when creating this, and ShapeActor below. Both are Actors
40 | this.caatScene.setFillStyle('#000000');
41 |
42 | this.caatDirector = new CAAT.Director().initialize(DemoHelloWorld.Constants.GAME_WIDTH, DemoHelloWorld.Constants.GAME_HEIGHT); // Create the director instance
43 | this.caatDirector.addScene(this.caatScene); // Immediately add the scene once it's created
44 | },
45 |
46 | /**
47 | * Updates our current view, passing along the current actual time (via Date().getTime());
48 | * @param {Number} gameClockReal The current actual time, according to the game
49 | */
50 | update: function (gameClockReal) {
51 | var delta = gameClockReal - this.caatDirector.timeline;
52 | this.caatDirector.render(delta);
53 | this.caatDirector.timeline = gameClockReal;
54 | },
55 |
56 | /**
57 | * Creates a Stats.js instance and adds it to the page
58 | */
59 | setupStats: function () {
60 | var container = document.createElement('div');
61 | this.stats = new Stats();
62 | this.stats.domElement.style.position = 'absolute';
63 | this.stats.domElement.style.top = '0px';
64 | container.appendChild(this.stats.domElement);
65 | document.body.appendChild(container);
66 | },
67 |
68 | /**
69 | * Add an entity from the view - For now this method definitely has some symantic issues because it's being passed a concrete view instead of figuring out what the view is
70 | * @param anEntityView
71 | */
72 | addEntity: function (anEntityView) {
73 | console.log("Adding Entity To CAAT", anEntityView);
74 | this.caatScene.addChild(anEntityView);
75 | },
76 |
77 | /**
78 | * Remove an entity from the view - For now this method definitely has some symantic issues because it's being passed a concrete view instead of figuring out what the view is
79 | * @param anEntityView
80 | */
81 | removeEntity: function (anEntityView) {
82 | console.log("Removing Entity From CAAT", anEntityView);
83 | this.caatScene.removeChild(anEntityView);
84 | },
85 |
86 | /**
87 | * Insert the CAATDirector canvas into an HTMLElement
88 | * @param {String} id An HTMLElement id
89 | */
90 | insertIntoHTMLElementWithId: function (id) {
91 | document.getElementById(id).appendChild(this.caatDirector.canvas);
92 | },
93 |
94 | /**
95 | * @inheritDoc
96 | */
97 | dealloc: function () {
98 | this.director.destroy();
99 | }
100 | };
101 | })();
102 |
103 |
104 |
--------------------------------------------------------------------------------
/js/lib/circlecollision/Circle.js:
--------------------------------------------------------------------------------
1 | /**
2 | #### ##### ##### #### ### # # ###### ###### ## ## ##### # # ######## ## # # #####
3 | # # # # ### # # ##### ### ## ## ## # ## # # # # ## # ##### ### ###
4 | ### # # ##### #### # # # ###### ## ######### ##### ##### ##### # ## # # # # # #####
5 | -
6 | File:
7 | PackedCircle.js
8 | Created By:
9 | Mario Gonzalez
10 | Project :
11 | None
12 | Abstract:
13 | A single packed circle.
14 | Contains a reference to it's div, and information pertaining to it state.
15 | Basic Usage:
16 | http://onedayitwillmake.com/CirclePackJS/
17 | */
18 |
19 | (function() {
20 |
21 | // Retrieve the namespace
22 | RealtimeMultiplayerGame.namespace("RealtimeMultiplayerGame.modules.circlecollision");
23 |
24 | /**
25 | * @constructor
26 | */
27 | RealtimeMultiplayerGame.modules.circlecollision.PackedCircle = function()
28 | {
29 | this.boundsRule = RealtimeMultiplayerGame.modules.circlecollision.PackedCircle.BOUNDS_RULE_IGNORE;
30 | this.position = new RealtimeMultiplayerGame.model.Point(0,0);
31 | this.offset = new RealtimeMultiplayerGame.model.Point(0,0);
32 | this.targetPosition = new RealtimeMultiplayerGame.model.Point(0,0);
33 | return this;
34 | };
35 |
36 | RealtimeMultiplayerGame.modules.circlecollision.PackedCircle.prototype = {
37 | id: 0,
38 | delegate: null,
39 | position: new RealtimeMultiplayerGame.model.Point(0,0),
40 | offset: new RealtimeMultiplayerGame.model.Point(0,0), // Offset from delegates position by this much
41 | radius: 0,
42 | radiusSquared: 0,
43 |
44 | targetPosition: null, // Where it wants to go
45 | targetChaseSpeed: 0.02,
46 |
47 | isFixed: false,
48 | boundsRule: 0,
49 | collisionMask: 0,
50 | collisionGroup: 0,
51 |
52 | BOUNDS_RULE_WRAP: 1, // Wrap to otherside
53 | BOUNDS_RULE_CONSTRAINT: 2, // Constrain within bounds
54 | BOUNDS_RULE_DESTROY: 4, // Destroy when it reaches the edge
55 | BOUNDS_RULE_IGNORE: 8, // Ignore when reaching bounds
56 |
57 | containsPoint: function(aPoint)
58 | {
59 | var distanceSquared = this.position.getDistanceSquared(aPoint);
60 | return distanceSquared < this.radiusSquared;
61 | },
62 |
63 | getDistanceSquaredFromPosition: function(aPosition)
64 | {
65 | var distanceSquared = this.position.getDistanceSquared(aPosition);
66 | // if it's shorter than either radius, we intersect
67 | return distanceSquared < this.radiusSquared;
68 | },
69 |
70 | intersects: function(aCircle)
71 | {
72 | var distanceSquared = this.position.getDistanceSquared(aCircle.position);
73 | return (distanceSquared < this.radiusSquared || distanceSquared < aCircle.radiusSquared);
74 | },
75 |
76 | /**
77 | * ACCESSORS
78 | */
79 | setPosition: function(aPosition)
80 | {
81 | this.position = aPosition;
82 | return this;
83 | },
84 |
85 | setDelegate: function(aDelegate)
86 | {
87 | this.delegate = aDelegate;
88 | return this;
89 | },
90 |
91 | setOffset: function(aPosition)
92 | {
93 | this.offset = aPosition;
94 | return this;
95 | },
96 |
97 | setTargetPosition: function(aTargetPosition)
98 | {
99 | this.targetPosition = aTargetPosition;
100 | return this;
101 | },
102 |
103 | setTargetChaseSpeed: function(aTargetChaseSpeed)
104 | {
105 | this.targetChaseSpeed = aTargetChaseSpeed;
106 | return this;
107 | },
108 |
109 | setIsFixed: function(value)
110 | {
111 | this.isFixed = value;
112 | return this;
113 | },
114 |
115 | setCollisionMask: function(aCollisionMask)
116 | {
117 | this.collisionMask = aCollisionMask;
118 | return this;
119 | },
120 |
121 | setCollisionGroup: function(aCollisionGroup)
122 | {
123 | this.collisionGroup = aCollisionGroup;
124 | return this;
125 | },
126 |
127 | setRadius: function(aRadius)
128 | {
129 | this.radius = aRadius;
130 | this.radiusSquared = this.radius*this.radius;
131 | return this;
132 | },
133 |
134 | initialize : function(overrides)
135 | {
136 | if (overrides)
137 | {
138 | for (var i in overrides)
139 | {
140 | this[i] = overrides[i];
141 | }
142 | }
143 |
144 | return this;
145 | },
146 |
147 | dealloc: function()
148 | {
149 | this.position = null;
150 | this.offset = null;
151 | this.delegate = null;
152 | this.targetPosition = null;
153 | }
154 | };
155 | })();
--------------------------------------------------------------------------------
/DemoBubbleDots.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | BubbleDots
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | Fork this project on http://github.com
61 |
71 |
72 |
75 |
76 |
78 |
79 |
83 |
84 |
85 |
91 |
92 |
93 |
94 |
95 |
99 |
105 |
106 |
107 |
108 |
--------------------------------------------------------------------------------
/js/BubbleDots/lib/Tween.js:
--------------------------------------------------------------------------------
1 | (function(){
2 | BubbleDots.namespace("BubbleDots.lib");
3 |
4 | // Tween.js - http://github.com/sole/tween.js
5 | var TWEEN=TWEEN||function(){var a,e,c,d,f=[];return{start:function(g){c=setInterval(this.update,1E3/(g||60))},stop:function(){clearInterval(c)},add:function(g){f.push(g)},remove:function(g){a=f.indexOf(g);a!==-1&&f.splice(a,1)},update:function(){a=0;e=f.length;for(d=(new Date).getTime();a1?1:b;i=n(b);for(h in c)a[h]=e[h]+c[h]*i;l!==null&&l.call(a,i);if(b==1){m!==null&&m.call(a);k!==null&&k.start();return false}return true}};TWEEN.Easing={Linear:{},Quadratic:{},Cubic:{},Quartic:{},Quintic:{},Sinusoidal:{},Exponential:{},Circular:{},Elastic:{},Back:{},Bounce:{}};TWEEN.Easing.Linear.EaseNone=function(a){return a};
8 | TWEEN.Easing.Quadratic.EaseIn=function(a){return a*a};TWEEN.Easing.Quadratic.EaseOut=function(a){return-a*(a-2)};TWEEN.Easing.Quadratic.EaseInOut=function(a){if((a*=2)<1)return 0.5*a*a;return-0.5*(--a*(a-2)-1)};TWEEN.Easing.Cubic.EaseIn=function(a){return a*a*a};TWEEN.Easing.Cubic.EaseOut=function(a){return--a*a*a+1};TWEEN.Easing.Cubic.EaseInOut=function(a){if((a*=2)<1)return 0.5*a*a*a;return 0.5*((a-=2)*a*a+2)};TWEEN.Easing.Quartic.EaseIn=function(a){return a*a*a*a};
9 | TWEEN.Easing.Quartic.EaseOut=function(a){return-(--a*a*a*a-1)};TWEEN.Easing.Quartic.EaseInOut=function(a){if((a*=2)<1)return 0.5*a*a*a*a;return-0.5*((a-=2)*a*a*a-2)};TWEEN.Easing.Quintic.EaseIn=function(a){return a*a*a*a*a};TWEEN.Easing.Quintic.EaseOut=function(a){return(a-=1)*a*a*a*a+1};TWEEN.Easing.Quintic.EaseInOut=function(a){if((a*=2)<1)return 0.5*a*a*a*a*a;return 0.5*((a-=2)*a*a*a*a+2)};TWEEN.Easing.Sinusoidal.EaseIn=function(a){return-Math.cos(a*Math.PI/2)+1};
10 | TWEEN.Easing.Sinusoidal.EaseOut=function(a){return Math.sin(a*Math.PI/2)};TWEEN.Easing.Sinusoidal.EaseInOut=function(a){return-0.5*(Math.cos(Math.PI*a)-1)};TWEEN.Easing.Exponential.EaseIn=function(a){return a==0?0:Math.pow(2,10*(a-1))};TWEEN.Easing.Exponential.EaseOut=function(a){return a==1?1:-Math.pow(2,-10*a)+1};TWEEN.Easing.Exponential.EaseInOut=function(a){if(a==0)return 0;if(a==1)return 1;if((a*=2)<1)return 0.5*Math.pow(2,10*(a-1));return 0.5*(-Math.pow(2,-10*(a-1))+2)};
11 | TWEEN.Easing.Circular.EaseIn=function(a){return-(Math.sqrt(1-a*a)-1)};TWEEN.Easing.Circular.EaseOut=function(a){return Math.sqrt(1- --a*a)};TWEEN.Easing.Circular.EaseInOut=function(a){if((a/=0.5)<1)return-0.5*(Math.sqrt(1-a*a)-1);return 0.5*(Math.sqrt(1-(a-=2)*a)+1)};TWEEN.Easing.Elastic.EaseIn=function(a){var e,c=0.1,d=0.4;if(a==0)return 0;if(a==1)return 1;d||(d=0.3);if(!c||c<1){c=1;e=d/4}else e=d/(2*Math.PI)*Math.asin(1/c);return-(c*Math.pow(2,10*(a-=1))*Math.sin((a-e)*2*Math.PI/d))};
12 | TWEEN.Easing.Elastic.EaseOut=function(a){var e,c=0.1,d=0.4;if(a==0)return 0;if(a==1)return 1;d||(d=0.3);if(!c||c<1){c=1;e=d/4}else e=d/(2*Math.PI)*Math.asin(1/c);return c*Math.pow(2,-10*a)*Math.sin((a-e)*2*Math.PI/d)+1};
13 | TWEEN.Easing.Elastic.EaseInOut=function(a){var e,c=0.1,d=0.4;if(a==0)return 0;if(a==1)return 1;d||(d=0.3);if(!c||c<1){c=1;e=d/4}else e=d/(2*Math.PI)*Math.asin(1/c);if((a*=2)<1)return-0.5*c*Math.pow(2,10*(a-=1))*Math.sin((a-e)*2*Math.PI/d);return c*Math.pow(2,-10*(a-=1))*Math.sin((a-e)*2*Math.PI/d)*0.5+1};TWEEN.Easing.Back.EaseIn=function(a){return a*a*(2.70158*a-1.70158)};TWEEN.Easing.Back.EaseOut=function(a){return(a-=1)*a*(2.70158*a+1.70158)+1};
14 | TWEEN.Easing.Back.EaseInOut=function(a){if((a*=2)<1)return 0.5*a*a*(3.5949095*a-2.5949095);return 0.5*((a-=2)*a*(3.5949095*a+2.5949095)+2)};TWEEN.Easing.Bounce.EaseIn=function(a){return 1-TWEEN.Easing.Bounce.EaseOut(1-a)};TWEEN.Easing.Bounce.EaseOut=function(a){return(a/=1)<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+0.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+0.9375:7.5625*(a-=2.625/2.75)*a+0.984375};
15 | TWEEN.Easing.Bounce.EaseInOut=function(a){if(a<0.5)return TWEEN.Easing.Bounce.EaseIn(a*2)*0.5;return TWEEN.Easing.Bounce.EaseOut(a*2-1)*0.5+0.5};
16 |
17 | BubbleDots.lib.TWEEN = TWEEN;
18 | })();
--------------------------------------------------------------------------------
/DemoHelloWorld.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | RealtimeMultiplayerNodeJs
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | Fork this project on http://github.com
63 |
75 |
76 |
79 |
80 |
82 |
83 |
87 |
88 |
89 |
95 |
96 |
97 |
98 |
99 |
103 |
109 |
110 |