Skip to content

Commit

Permalink
Added initial food / poison
Browse files Browse the repository at this point in the history
  • Loading branch information
onedayitwillmake committed May 8, 2011
1 parent c33127d commit 32b83fa
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 19 deletions.
2 changes: 1 addition & 1 deletion js/BubbleDots/BubbleDotsClientGame.js
Expand Up @@ -110,7 +110,7 @@ Version:
entityDescription.entityType = +entityDescAsArray[2];
entityDescription.x = +entityDescAsArray[3];
entityDescription.y = +entityDescAsArray[4];
entityDescription.radius = entityDescAsArray[5];
entityDescription.radius = +entityDescAsArray[5];
entityDescription.color = entityDescAsArray[6];
return entityDescription;
},
Expand Down
14 changes: 10 additions & 4 deletions js/BubbleDots/BubbleDotsServerGame.js
Expand Up @@ -17,6 +17,7 @@ Version:
(function(){
require("../model/ImprovedNoise.js");
require("./lib/color.js");
require("./lib/Tween.js");

BubbleDots.DemoServerGame = function() {
BubbleDots.DemoServerGame.superclass.constructor.call(this);
Expand Down Expand Up @@ -54,10 +55,10 @@ Version:
* Called when the collision manager detects a collision
*/
onCollisionManagerCollision: function(ci, cj, v ) {
ci.delegate.tempColor();
cj.delegate.tempColor();

ci.delegate.acceleration.translatePoint( v.multiply(-10) );
// ci.delegate.tempColor();
// cj.delegate.tempColor();
ci.delegate.onCollision( ci.delegate, cj.delegate, v );
cj.delegate.onCollision( ci.delegate, cj.delegate, v );
},

/**
Expand Down Expand Up @@ -90,6 +91,9 @@ Version:
circleEntity.setCollisionCircle( collisionCircle );


// Attach food trait
circleEntity.addTraitAndExecute( new BubbleDots.traits.FoodTrait() );

// Place the circle and collision circle into corresponding containers
this.collisionManager.addCircle( circleEntity.getCollisionCircle() );
this.fieldController.addEntity( circleEntity );
Expand All @@ -104,6 +108,7 @@ Version:
tick: function() {
this.collisionManager.handleCollisions();
this.collisionManager.handleBoundaryForAllCircles();
BubbleDots.lib.TWEEN.update();

// Note we call superclass's implementation after we're done
BubbleDots.DemoServerGame.superclass.tick.call(this);
Expand All @@ -119,6 +124,7 @@ Version:
playerEntity.position = center.clone();
playerEntity.getCollisionCircle().setPosition( center.clone() );
playerEntity.setInput( new RealtimeMultiplayerGame.Input.Keyboard() );
playerEntity.removeTraitWithName( BubbleDots.traits.FoodTrait.prototype.displayName );

this.fieldController.addPlayer( playerEntity );
},
Expand Down
9 changes: 9 additions & 0 deletions js/BubbleDots/entities/CircleEntity.js
Expand Up @@ -31,6 +31,7 @@ Version:
entityType : null,
color : null,
originalColor : null,
_tween : null,

// Movement properties
velocityMax : 7.0,
Expand Down Expand Up @@ -72,6 +73,14 @@ Version:
this.acceleration.set(0,0);
},

/**
* Called when this object has collided with another
* @param a Object A in the collision pair, note this may be this object
* @param b Object B in the collision pair, note this may be this object
* @param collisionNormal A vector describing the collision
*/
onCollision: function(a, b, collisionNormal) {},

tempColor: function() {
var that = this;

Expand Down
18 changes: 18 additions & 0 deletions js/BubbleDots/lib/Tween.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions js/BubbleDots/server.js
Expand Up @@ -15,24 +15,26 @@ Version:
require("../lib/SortedLookupTable.js");
require("../core/RealtimeMutliplayerGame.js");
require("../model/Point.js");
require("../lib/circlecollision/Circle.js");
require("../lib/circlecollision/CircleManager.js");
require("../model/Constants.js");
require("../model/NetChannelMessage.js");
require("../model/GameEntity.js");
require("../model/WorldEntityDescription.js");
require("../network/ServerNetChannel.js");
require("../network/Client.js");
require("../lib/circlecollision/Circle.js");
require("../lib/circlecollision/CircleManager.js");
require("../controller/FieldController.js");
require("../core/AbstractGame.js");
require("../network/Client.js");
require("../network/ServerNetChannel.js");
require("../core/AbstractServerGame.js");
require("../model/GameEntity.js");
require("../model/WorldEntityDescription.js");
require("../input/Keyboard.js");
require("../controller/traits/BaseTrait.js");


require("./BubbleDotsApp.js");
require("./BubbleDotsConstants.js");
require("./entities/CircleEntity.js");
require("./entities/PlayerEntity.js");
require("./traits/FoodTrait.js");
require("./BubbleDotsServerGame.js");

var game = new BubbleDots.DemoServerGame();
Expand Down
71 changes: 71 additions & 0 deletions js/BubbleDots/traits/FoodTrait.js
@@ -0,0 +1,71 @@
/**
File:
FoodTrait.js
Created By:
Mario Gonzalez
Project :
RealtimeMultiplayerNodeJS
Abstract:
Basic Usage:
*/
(function(){
BubbleDots.namespace("BubbleDots.traits");

BubbleDots.traits.FoodTrait = function() {
BubbleDots.traits.FoodTrait.superclass.constructor.call(this);
};

BubbleDots.traits.FoodTrait.prototype = {
displayName : "FoodTrait", // Unique string name for this Trait
originalColor : "00FF00",
color : "00FF00",

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

/**
* @inheritDoc
*/
execute: function() {
BubbleDots.traits.FoodTrait.superclass.execute.call(this);
},

/**
* Intercepted properties
*/
/**
* Called when this object has collided with another
* @param a Object A in the collision pair, note this may be this object
* @param b Object B in the collision pair, note this may be this object
* @param collisionNormal A vector describing the collision
*/
onCollision: function(a, b, collisionNormal) {

// We're either A or B, so perform a simple check against A to figure out which of the two objects we are
var me = this === a ? a : b;

BubbleDots.lib.TWEEN.remove( me._tween );
me._tween = new BubbleDots.lib.TWEEN.Tween({radius: me.radius})
.to({radius: Math.random() * 35 + 5}, 1000)
.easing(BubbleDots.lib.TWEEN.Easing.Back.EaseOut)
.onUpdate(function(){
me.radius = ~~this.radius;
me.collisionCircle.setRadius( ~~this.radius );
})
.start();

me.acceleration.translatePoint( collisionNormal.multiply(-10) );
}

};

// Extend BaseTrait
RealtimeMultiplayerGame.extend( BubbleDots.traits.FoodTrait, RealtimeMultiplayerGame.controller.traits.BaseTrait );
})();
16 changes: 8 additions & 8 deletions js/BubbleDots/traits/PoisonTrait.js
@@ -1,6 +1,6 @@
/**
File:
FoodTrait.js
PoisonTrait.js
Created By:
Mario Gonzalez
Project :
Expand All @@ -13,28 +13,28 @@ Abstract:
(function(){
BubbleDots.namespace("BubbleDots.traits");

BubbleDots.traits.FoodTrait = function() {
BubbleDots.traits.FoodTrait.superclass.constructor.call(this);
BubbleDots.traits.PoisonTrait = function() {
BubbleDots.traits.PoisonTrait.superclass.constructor.call(this);
};

BubbleDots.traits.FoodTrait.prototype = {
displayName : "FoodTrait", // Unique string name for this Trait
BubbleDots.traits.PoisonTrait.prototype = {
displayName : "PoisonTrait", // Unique string name for this Trait
originalColor : "00FF00",
color : "00FF00",

/**
* @inheritDoc
*/
attach: function(anEntity) {
BubbleDots.traits.FoodTrait.superclass.attach.call(this, anEntity);
BubbleDots.traits.PoisonTrait.superclass.attach.call(this, anEntity);
this.intercept(['onCollision', 'color', 'originalColor']);
},

/**
* @inheritDoc
*/
execute: function() {
BubbleDots.traits.FoodTrait.superclass.execute.call(this);
BubbleDots.traits.PoisonTrait.superclass.execute.call(this);
},

/**
Expand Down Expand Up @@ -67,5 +67,5 @@ Abstract:
};

// Extend BaseTrait
RealtimeMultiplayerGame.extend( BubbleDots.traits.FoodTrait, RealtimeMultiplayerGame.controller.traits.BaseTrait );
RealtimeMultiplayerGame.extend( BubbleDots.traits.PoisonTrait, RealtimeMultiplayerGame.controller.traits.BaseTrait );
})();

0 comments on commit 32b83fa

Please sign in to comment.