Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
onedayitwillmake committed Jun 23, 2011
2 parents e75aa81 + 7f1950f commit f13c424
Show file tree
Hide file tree
Showing 22 changed files with 273 additions and 42 deletions.
2 changes: 1 addition & 1 deletion DemoHelloWorld.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
[if (gt IE 9)|!(IE)]><! <html lang="en" class="no-js"><![endif]-->
<!--[if (gt IE 9)|!(IE)]><! <html lang="en" class="no-js"><![endif]-->
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
Expand Down
Binary file added assets/bubbledots/ground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion js/BubbleDots/BubbleDotsClientGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,16 @@ Version:
// Create a new BubbleDots entity
var newEntity = new BubbleDots.CircleEntity( entityDesc.entityid, entityDesc.clientid );
newEntity.position.set( entityDesc.x, entityDesc.y );
newEntity.setView( this.view.createEntityView( entityDesc ) );

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 );
}
},

Expand Down
3 changes: 2 additions & 1 deletion js/BubbleDots/BubbleDotsConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ Version:
{id: "particle" + 1, url: "assets/bubbledots/blueParticle.png"},
{id: "particle" + 2, url: "assets/bubbledots/redParticle.png"},
{id: "particle" + 3, url: "assets/bubbledots/greenParticle.png"},
{id: "particle" + 4, url: "assets/bubbledots/yellowParticle.png"}
{id: "particle" + 4, url: "assets/bubbledots/yellowParticle.png"},
{id: "ground", url: "assets/bubbledots/ground.png"}
]
}
})();
21 changes: 16 additions & 5 deletions js/BubbleDots/BubbleDotsServerGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ Version:
var entity = this.createEntity( BubbleDots.CircleEntity, radius, this.getNextEntityID(), RealtimeMultiplayerGame.Constants.SERVER_SETTING.CLIENT_ID );

// Randomly make the object 'food' or 'poison'
if(i%10 === 0) {
if(i%5 === 0) {
entity.addTraitAndExecute( new BubbleDots.traits.PoisonTrait() );
} else {
entity.addTraitAndExecute( new BubbleDots.traits.FoodTrait() );
}

entity.addTraitAndExecute( new BubbleDots.traits.PerlinNoiseTrait() );
// entity.addTraitAndExecute( new BubbleDots.traits.PerlinNoiseTrait() );
}
},

Expand All @@ -92,7 +92,7 @@ Version:
createEntity: function( aBubbleDotEntityConstructor, aRadius, anEntityid, aClientid ) {
// Create the GameEntity
var circleEntity = new aBubbleDotEntityConstructor( anEntityid, aClientid );
circleEntity.position.set( Math.random() * BubbleDots.Constants.GAME_WIDTH, Math.random() * BubbleDots.Constants.GAME_HEIGHT );
circleEntity.position.set( Math.random() * BubbleDots.Constants.GAME_WIDTH * 20, Math.random() * BubbleDots.Constants.GAME_HEIGHT );

// Create a randomly sized circle, that will represent this entity in the collision manager
var collisionCircle = new RealtimeMultiplayerGame.modules.circlecollision.PackedCircle();
Expand All @@ -111,9 +111,14 @@ Version:
*/
tick: function() {
this.collisionManager.handleCollisions();
this.collisionManager.handleBoundaryForAllCircles();
BubbleDots.lib.TWEEN.update();

// var boundaryRule = RealtimeMultiplayerGame.modules.circlecollision.CircleManager.prototype.BOUNDARY_CONSTRAIN_Y;
// var that = this;
// this.fieldController.getPlayers().forEach(function(key, value) {
// this.collisionManager.handleBoundaryForCircle( value.getCollisionCircle(), boundaryRule );
// }, this);

// Note we call superclass's implementation after we're done
BubbleDots.DemoServerGame.superclass.tick.call(this);
},
Expand All @@ -127,9 +132,15 @@ Version:
playerEntity.position = center.clone();
playerEntity.getCollisionCircle().setPosition( center.clone() );
playerEntity.setInput( new RealtimeMultiplayerGame.Input.Keyboard() );
playerEntity.removeAllTraits();
playerEntity.setColor( "4" );

playerEntity.addTraitAndExecute( new BubbleDots.traits.GravityTrait() );

// Set the boundary trait and the rule it will use
var boundaryTrait = new BubbleDots.traits.BoundaryTrait( this.collisionManager );
boundaryTrait.setBoundaryRule( RealtimeMultiplayerGame.modules.circlecollision.CircleManager.prototype.BOUNDARY_CONSTRAIN_Y );
playerEntity.addTraitAndExecute( boundaryTrait );

this.fieldController.addPlayer( playerEntity );
},

Expand Down
55 changes: 50 additions & 5 deletions js/BubbleDots/BubbleDotsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ Version:
// Properties
caatDirector : null, // CAAT Director instance
caatScene : null, // CAAT Scene instance
caatRoot : null,
focusCharacter : null, // The 'camera' will follow this player
stats : null, // Stats.js instance
textfield : null, // CAAT text
textfield : null, // CAAT text

// Methods
setupCAAT: function() {
Expand All @@ -43,7 +45,16 @@ Version:
this.caatDirector = new CAAT.Director().initialize( BubbleDots.Constants.GAME_WIDTH, BubbleDots.Constants.GAME_HEIGHT ); // Create the director instance
this.caatDirector.addScene( this.caatScene ); // Immediately add the scene once it's created
this.caatDirector.setImagesCache( BubbleDots.IMAGE_CACHE );


this.caatRoot = new CAAT.ActorContainer()
.setBounds( 0, 0, this.caatScene.width, this.caatScene.height )
.create()
.enableEvents(false);
this.caatScene.addChild( this.caatRoot );

this.setupTextfield();
this.createGround();
},

setupTextfield: function() {
Expand All @@ -66,10 +77,23 @@ Version:
*/
update: function( gameClockReal ) {
var delta = gameClockReal - this.caatDirector.timeline;

if( this.focusCharacter ) {
this.followFocusCharacter();
}

this.caatDirector.render( delta );
this.caatDirector.timeline = gameClockReal;
},

followFocusCharacter: function() {
var camSpeed = 0.1;
var targetX = -this.focusCharacter.x + this.caatScene.width/2 - 100;
var targetY = -this.focusCharacter.y + this.caatScene.height/2 + 50;
this.caatRoot.x -= (this.caatRoot.x - targetX) * camSpeed;
this.caatRoot.y -= (this.caatRoot.y - targetY) * camSpeed * 2;
},

/**
* Creates a Stats.js instance and adds it to the page
*/
Expand All @@ -84,23 +108,21 @@ Version:

addEntity: function( anEntityView ) {
// console.log( "Adding Entity To CAAT", anEntityView );
this.caatScene.addChild( anEntityView );
this.caatRoot.addChild( anEntityView );
},

removeEntity: function( anEntityView ) {
console.log( "Removing Entity From CAAT", anEntityView );
this.caatScene.removeChild( anEntityView );
this.caatRoot.removeChild( anEntityView );
},

/**
* Create a view for an entity in CAAT using the entity description
* @param {Object} entityDesc An object containing properties for this entity, sent from the server
*/
createEntityView: function( entityDesc ) {
//BubbleDots.IMAGE_CACHE[0].image
// Retrieve the image from caatDirector (stored in the preloading sequence in script.js)
var imageName = "particle" + entityDesc.color;
console.log(imageName)
var imageRef = this.caatDirector.getImage(imageName);
var caatImage = new CAAT.CompoundImage()
.initialize(imageRef, 1, 1);
Expand All @@ -114,6 +136,25 @@ Version:
return actor;
},

createGround: function() {
// Retrieve the image from caatDirector (stored in the preloading sequence in script.js)
var imageRef = this.caatDirector.getImage("ground");
var caatImage = new CAAT.CompoundImage()
.initialize(imageRef, 1, 1);

for(var i = 0; i < 10; ++i) {
// Create the actor using the image
var actor = this.CAATSprite = new CAAT.SpriteActor()
.create()
.setSpriteImage(caatImage)
.setLocation(i * caatImage.width, 470);

this.caatRoot.addChild( actor );
}

return actor;
},

/**
* Insert the CAATDirector canvas into an HTMLElement
* @param {String} id An HTMLElement id
Expand All @@ -125,6 +166,10 @@ Version:
// Memory
dealloc: function() {
this.director.destroy();
},

setFocusCharacter: function( entity ) {
this.focusCharacter = entity;
}
};
})();
Expand Down
10 changes: 2 additions & 8 deletions js/BubbleDots/entities/CircleEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Version:

// Movement properties
velocityMax : 8.0,
velocityDamping : 0.9,
velocityDamping : 0.98,


/**
Expand Down Expand Up @@ -66,7 +66,7 @@ Version:

handleAcceleration: function( speedFactor, gameClock, gameTick ) {
this.velocity.translatePoint( this.acceleration );
this.velocity.limit(this.velocityMax);
// this.velocity.limit(this.velocityMax);
this.velocity.multiply(this.velocityDamping);

this.collisionCircle.position.translatePoint( this.velocity );
Expand Down Expand Up @@ -111,12 +111,6 @@ Version:
return entityDesc;
},

// addTrait: function( aTrait ) {
// if( aTrait.displayName === RealtimeMultiplayerGame.controller.traits.KeyboardInputTrait )
// return BubbleDots.CircleEntity.superclass.addTrait.call(this, aTrait);
// return null;
// },

///// ACCESSORS
/**
* Set the CollisionCircle for this game entity.
Expand Down
49 changes: 46 additions & 3 deletions js/BubbleDots/entities/PlayerEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,37 @@ var count = 0;
BubbleDots.PlayerEntity = function( anEntityid, aClientid) {
BubbleDots.PlayerEntity.superclass.constructor.call(this, anEntityid, aClientid );
this.entityType = BubbleDots.Constants.ENTITY_TYPES.PLAYER_ENTITY;
this.initThrust();
};

BubbleDots.PlayerEntity.prototype = {
_isThrusting : false , // We need a better variable name.
_thrustLevel : 0,

THRUST_DECREMENT : 0.001, // How much to decrease thrust by
THRUST_FORCE : 0.3, // How much force to apply every tick when applying thrust

initThrust: function() {
this._thrustLevel = 100.0;
this._isThrusting = false;
},

startThrust: function() {
this._isThrusting = true;
// this.velocity.y *= 0.5;
},

applyThrust: function() {
this._thrustLevel -= BubbleDots.PlayerEntity.prototype.THRUST_DECREMENT;
if( this._thrustLevel > 0.0 ) {
this.acceleration.y -= BubbleDots.PlayerEntity.prototype.THRUST_FORCE;
}
},

stopThrust: function() {
this._isThrusting = false;
},

/**
* Update position of this entity - this is only called on the serverside
* @param {Number} speedFactor A number signifying how much faster or slower we are moving than the target framerate
Expand All @@ -32,11 +60,26 @@ var count = 0;
},

handleInput: function( speedFactor ) {
var moveSpeed = 0.3;
if( this.input.isLeft() ) this.acceleration.x -= moveSpeed*2.1;
var moveSpeed = 0.2;

if( this.input.isLeft() ) this.acceleration.x -= moveSpeed;
if( this.input.isRight() ) this.acceleration.x += moveSpeed;
if( this.input.isUp() ) this.acceleration.y -= moveSpeed;
if( this.input.isDown() ) this.acceleration.y += moveSpeed;

// We're pressing up - apply thrust...
// Call startThrust if we were not thrusting before
if( this.input.isUp() ) {
if( !this._isThrusting ) {
this.startThrust();
}

this.applyThrust();
} else if ( this._isThrusting ) {
this.stopThrust();
} else { // Default behavior - increase _thrustLevel
this._thrustLevel += BubbleDots.PlayerEntity.prototype.THRUST_DECREMENT * 2;
this._thrustLevel = Math.min( this._thrustLevel, 100 );
}
},

///// ACCESSORS
Expand Down
2 changes: 2 additions & 0 deletions js/BubbleDots/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ require("./traits/FoodTrait.js");
require("./traits/PoisonTrait.js");
require("./traits/PerlinNoiseTrait.js");
require("./traits/ChaseTrait.js");
require("./traits/GravityTrait.js");
require("./traits/BoundaryTrait.js");
require("./BubbleDotsServerGame.js");

var game = new BubbleDots.DemoServerGame();
Expand Down
62 changes: 62 additions & 0 deletions js/BubbleDots/traits/BoundaryTrait.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
File:
BoundaryTrait.js
Created By:
Mario Gonzalez
Project :
RealtimeMultiplayerNodeJS
Abstract:
This trait will cause an entity to react to boundary collisions
Basic Usage:
*/
(function(){
BubbleDots.namespace("BubbleDots.traits");
BubbleDots.traits.BoundaryTrait = function( aCollisionManager ) {
BubbleDots.traits.BoundaryTrait.superclass.constructor.call(this);
this._collisionManager = aCollisionManager;
};

BubbleDots.traits.BoundaryTrait.prototype = {
displayName : "BoundaryTrait", // Unique string name for this Trait
_boundaryRule : 0,
_collisionManager : null,

/**
* @inheritDoc
*/
attach: function(anEntity) {
BubbleDots.traits.BoundaryTrait.superclass.attach.call(this, anEntity);
this.intercept(['updatePosition']);
},

/**
* Intercepted properties
*/
updatePosition: function( speedFactor, gameClock, gameTick ) {
var trait = this.getTraitWithName("BoundaryTrait");

// Call the original handleAcceleration
trait._collisionManager.handleBoundaryForCircle( this.getCollisionCircle(), trait._boundaryRule );
trait.interceptedProperties._data.updatePosition.call(this, speedFactor, gameClock, gameTick);
},

detach: function( force ) {
this._collisionManager = null;
BubbleDots.traits.BoundaryTrait.superclass.detach.call(this, force);
},

///// ACCESSORS
/**
* Set the gravitational force
* @param {Number} aBoundaryRule Boundary rule to apply to collision circle, see CollisionManager
*/
setBoundaryRule: function( aBoundaryRule ) {
this._boundaryRule = aBoundaryRule;
return this;
}
};

// Extend BaseTrait
RealtimeMultiplayerGame.extend( BubbleDots.traits.BoundaryTrait, RealtimeMultiplayerGame.controller.traits.BaseTrait );
})();
1 change: 1 addition & 0 deletions js/BubbleDots/traits/FoodTrait.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Abstract:

var chaseTrait = this.addTraitAndExecute( new BubbleDots.traits.ChaseTrait() );
chaseTrait.setTarget( them );
this.addTraitAndExecute( new BubbleDots.traits.PerlinNoiseTrait() );
// me.tempColor();
}

Expand Down
Loading

0 comments on commit f13c424

Please sign in to comment.