Skip to content

Commit d0794a3

Browse files
Added colored food/poison traits
1 parent 5be5462 commit d0794a3

File tree

8 files changed

+58
-54
lines changed

8 files changed

+58
-54
lines changed

js/BubbleDots/BubbleDotsClientGame.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ Version:
5050
var newEntity = new BubbleDots.CircleEntity( entityDesc.entityid, entityDesc.clientid );
5151
newEntity.position.set( entityDesc.x, entityDesc.y );
5252
newEntity.setView( this.view.createEntityView( entityDesc ) );
53-
newEntity.radius = entityDesc.radius;
5453

5554
this.fieldController.addEntity( newEntity );
5655

@@ -100,7 +99,7 @@ Version:
10099
entityDescription.entityType = +entityDescAsArray[2];
101100
entityDescription.x = +entityDescAsArray[3];
102101
entityDescription.y = +entityDescAsArray[4];
103-
entityDescription.radius = +entityDescAsArray[5];
102+
entityDescription.scale = +entityDescAsArray[5];
104103
entityDescription.color = entityDescAsArray[6];
105104
return entityDescription;
106105
},

js/BubbleDots/BubbleDotsConstants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Version:
1919
ENTITY_DEFAULT_RADIUS : 17,
2020
GAME_WIDTH : 700,
2121
GAME_HEIGHT : 450,
22-
MAX_CIRCLES : 200,
22+
MAX_CIRCLES : 40,
2323
GAME_DURATION : 1000*300,
2424

2525
ENTITY_TYPES: {

js/BubbleDots/BubbleDotsServerGame.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,12 @@ Version:
7373
var entity = this.createEntity( BubbleDots.CircleEntity, radius, this.getNextEntityID(), RealtimeMultiplayerGame.Constants.SERVER_SETTING.CLIENT_ID );
7474

7575
// Randomly make the object 'food' or 'poison'
76-
// if(i%3 === 0) {
77-
// entity.addTraitAndExecute( new BubbleDots.traits.PoisonTrait() );
78-
// } else {
79-
// entity.addTraitAndExecute( new BubbleDots.traits.FoodTrait() );
80-
// }
76+
if(i%3 === 0) {
77+
entity.addTraitAndExecute( new BubbleDots.traits.PoisonTrait() );
78+
} else {
79+
entity.addTraitAndExecute( new BubbleDots.traits.FoodTrait() );
80+
}
8181

82-
entity.addTraitAndExecute( new BubbleDots.traits.FoodTrait() );
8382
entity.addTraitAndExecute( new BubbleDots.traits.PerlinNoiseTrait() );
8483
}
8584
},
@@ -93,13 +92,12 @@ Version:
9392
createEntity: function( aBubbleDotEntityConstructor, aRadius, anEntityid, aClientid ) {
9493
// Create the GameEntity
9594
var circleEntity = new aBubbleDotEntityConstructor( anEntityid, aClientid );
96-
circleEntity.radius = aRadius;
9795
circleEntity.position.set( Math.random() * BubbleDots.Constants.GAME_WIDTH, Math.random() * BubbleDots.Constants.GAME_HEIGHT );
98-
// circleEntity.setColor( CAAT.Color.prototype.hsvToRgb( (anEntityid * 15) % 360, 80, 99).toHex() );
9996

10097
// Create a randomly sized circle, that will represent this entity in the collision manager
10198
var collisionCircle = new RealtimeMultiplayerGame.modules.circlecollision.PackedCircle();
10299
circleEntity.setCollisionCircle( collisionCircle );
100+
circleEntity.setRadius( aRadius );
103101

104102
// Place the circle and collision circle into corresponding containers
105103
this.collisionManager.addCircle( circleEntity.getCollisionCircle() );
@@ -125,7 +123,7 @@ Version:
125123
*/
126124
shouldAddPlayer: function( aClientid, data ) {
127125
var center = new RealtimeMultiplayerGame.model.Point( BubbleDots.Constants.GAME_WIDTH / 2,BubbleDots.Constants.GAME_HEIGHT / 2 );
128-
var playerEntity = this.createEntity( BubbleDots.PlayerEntity, 30, this.getNextEntityID(), aClientid );
126+
var playerEntity = this.createEntity( BubbleDots.PlayerEntity, BubbleDots.Constants.ENTITY_DEFAULT_RADIUS, this.getNextEntityID(), aClientid );
129127
playerEntity.position = center.clone();
130128
playerEntity.getCollisionCircle().setPosition( center.clone() );
131129
playerEntity.setInput( new RealtimeMultiplayerGame.Input.Keyboard() );

js/BubbleDots/entities/CircleEntity.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ Version:
4444
updateView: function() {
4545
if(!this.view) return;
4646

47-
this.view.x = this.position.x - this.radius;
48-
this.view.y = this.position.y - this.radius;
49-
this.radius = this.lastReceivedEntityDescription.radius;
50-
47+
this.view.x = this.position.x;// - this.radius;
48+
this.view.y = this.position.y;// - this.radius;
49+
this.view.setScale(this.lastReceivedEntityDescription.scale*0.01, this.lastReceivedEntityDescription.scale*0.01);
5150
return;
5251

5352
var diameter = this.lastReceivedEntityDescription.radius * 2;
@@ -62,10 +61,10 @@ Version:
6261
* @param {Number} gameTick Current game tick (incrimented each frame)
6362
*/
6463
updatePosition: function( speedFactor, gameClock, gameTick ) {
65-
this.handleAcceleration();
64+
this.handleAcceleration( speedFactor, gameClock, gameTick );
6665
},
6766

68-
handleAcceleration: function() {
67+
handleAcceleration: function( speedFactor, gameClock, gameTick ) {
6968
this.velocity.translatePoint( this.acceleration );
7069
this.velocity.limit(this.velocityMax);
7170
this.velocity.multiply(this.velocityDamping);
@@ -106,12 +105,18 @@ Version:
106105

107106
constructEntityDescription: function() {
108107
var entityDesc = BubbleDots.CircleEntity.superclass.constructEntityDescription.call(this);
109-
entityDesc += ',' + ~~(this.radius);
108+
entityDesc += ',' + ~~(this.scale*100);
110109
entityDesc += ',' + this.color;
111110

112111
return entityDesc;
113112
},
114113

114+
// addTrait: function( aTrait ) {
115+
// if( aTrait.displayName === RealtimeMultiplayerGame.controller.traits.KeyboardInputTrait )
116+
// return BubbleDots.CircleEntity.superclass.addTrait.call(this, aTrait);
117+
// return null;
118+
// },
119+
115120
///// ACCESSORS
116121
/**
117122
* Set the CollisionCircle for this game entity.
@@ -140,7 +145,14 @@ Version:
140145
this.color = aColor;
141146
},
142147
getColor: function(){ return this.color },
143-
getOriginalColor: function(){ return this.originalColor }
148+
getOriginalColor: function(){ return this.originalColor },
149+
setRadius: function(aRadius) {
150+
this.radius = aRadius;
151+
this.collisionCircle.setRadius( this.radius );
152+
this.scale = this.radius / BubbleDots.Constants.ENTITY_DEFAULT_RADIUS;
153+
},
154+
getRadius: function(){ return this.radius; }
155+
144156
};
145157

146158
// extend RealtimeMultiplayerGame.model.GameEntity

js/BubbleDots/traits/ChaseTrait.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Abstract:
1212
*/
1313
(function(){
1414
BubbleDots.namespace("BubbleDots.traits");
15-
var RATE = 0.01;
15+
var RATE = 0.2;
1616
BubbleDots.traits.ChaseTrait = function() {
1717
BubbleDots.traits.ChaseTrait.superclass.constructor.call(this);
1818
};
@@ -36,17 +36,18 @@ Abstract:
3636
* @inheritDoc
3737
*/
3838
execute: function() {
39+
RATE += 0.3;
40+
this.radius = Math.random() * 20 + 5;
3941
this.offset = new RealtimeMultiplayerGame.model.Point( Math.cos(RATE) * this.radius, Math.sin(RATE) * -this.radius);
40-
42+
this.chaseSpeed = Math.random() * 0.02 + 0.001;
4143
BubbleDots.traits.ChaseTrait.superclass.execute.call(this);
4244
},
4345

4446
/**
4547
* Intercepted properties
4648
*/
47-
updatePosition: function() {
49+
updatePosition: function( speedFactor, gameClock, gameTick ) {
4850
var trait = this.getTraitWithName("ChaseTrait");
49-
RATE += 0.1;
5051

5152
// Move towards the target position overtime
5253
var delta = trait.target.position.subtractClone(this.position);
@@ -57,7 +58,7 @@ Abstract:
5758
this.acceleration.translatePoint( delta );
5859

5960
// Call the original handleAcceleration
60-
trait.interceptedProperties._data.updatePosition.call(this);
61+
trait.interceptedProperties._data.updatePosition.call(this, speedFactor, gameClock, gameTick);
6162
},
6263

6364
///// ACCESSORS

js/BubbleDots/traits/FoodTrait.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,13 @@ Abstract:
1919

2020
BubbleDots.traits.FoodTrait.prototype = {
2121
displayName : "FoodTrait", // Unique string name for this Trait
22-
originalColor : "2",
2322
color : "3",
2423

2524
/**
2625
* @inheritDoc
2726
*/
2827
attach: function(anEntity) {
2928
BubbleDots.traits.FoodTrait.superclass.attach.call(this, anEntity);
30-
this.color = Math.random() < 0.5 ? "2" : "3";
31-
this.originalColor = this.color;
3229
this.intercept(['onCollision', 'color']);
3330
},
3431

@@ -56,15 +53,14 @@ Abstract:
5653

5754
// me.addTrait( )
5855

59-
// BubbleDots.lib.TWEEN.remove( me._tween );
60-
// me._tween = new BubbleDots.lib.TWEEN.Tween({radius: me.radius})
61-
// .to({radius: 0.1}, 1000)
62-
// .easing(BubbleDots.lib.TWEEN.Easing.Sinusoidal.EaseOut)
63-
// .onUpdate(function(){
64-
// me.radius = ~~this.radius;
65-
// me.collisionCircle.setRadius( ~~this.radius );
66-
// })
67-
// .start();
56+
BubbleDots.lib.TWEEN.remove( me._tween );
57+
me._tween = new BubbleDots.lib.TWEEN.Tween({radius: me.radius})
58+
.to({radius: 5}, 250)
59+
.easing(BubbleDots.lib.TWEEN.Easing.Back.EaseInOut)
60+
.onUpdate(function(){
61+
me.setRadius(~~this.radius);
62+
})
63+
.start();
6864

6965
// var newRadius = Math.max( BubbleDots.traits.FoodTrait.prototype.radius, them.radius+0.1 );
7066
// them.radius = newRadius;
@@ -73,7 +69,7 @@ Abstract:
7369
// me.acceleration.translatePoint( collisionNormal.multiply(-10) );
7470
var chaseTrait = this.addTraitAndExecute( new BubbleDots.traits.ChaseTrait() );
7571
chaseTrait.setTarget( them );
76-
me.tempColor();
72+
// me.tempColor();
7773
}
7874

7975
};

js/BubbleDots/traits/PerlinNoiseTrait.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ Abstract:
1212
*/
1313
(function(){
1414
BubbleDots.namespace("BubbleDots.traits");
15+
16+
var NOISE_SEED = Math.random() * 1000;
17+
1518
BubbleDots.traits.PerlinNoiseTrait = function() {
1619
BubbleDots.traits.PerlinNoiseTrait.superclass.constructor.call(this);
17-
this.noiseOffset = 0.0;
1820
};
1921

2022
BubbleDots.traits.PerlinNoiseTrait.prototype = {
2123
displayName : "PerlinNoiseTraitTrait", // Unique string name for this Trait
22-
noiseOffset : 0.0,
2324

2425
/**
2526
* @inheritDoc
@@ -32,20 +33,19 @@ Abstract:
3233
/**
3334
* Intercepted properties
3435
*/
35-
updatePosition: function() {
36+
updatePosition: function( speedFactor, gameClock, gameTick ) {
3637
// Call the original handleAcceleration
3738
var trait = this.getTraitWithName("PerlinNoiseTraitTrait");
38-
trait.noiseOffset+=0.005;
3939

4040
// Modify velocity using perlin noise
4141
var theta = 0.008;
42-
var noise = RealtimeMultiplayerGame.model.noise(this.position.x*theta, this.position.y*theta, trait.noiseOffset);
43-
var angle = noise*12;
42+
var noise = RealtimeMultiplayerGame.model.noise(this.position.x*theta, this.position.y*theta, NOISE_SEED + gameTick*0.001);
43+
var angle = noise*Math.PI*12.566370614359172; // PI * 4
4444
var speed = 0.2;
45-
this.acceleration.x += Math.cos( angle ) * speed - 0.3;
46-
this.acceleration.y -= Math.sin( angle ) * speed;
45+
this.acceleration.x += Math.cos( angle ) * speed - 0.25;
46+
this.acceleration.y += Math.sin( angle ) * speed;
4747

48-
trait.interceptedProperties._data.updatePosition.call(this);
48+
trait.interceptedProperties._data.updatePosition.call(this, speedFactor, gameClock, gameTick);
4949
}
5050
};
5151

js/BubbleDots/traits/PoisonTrait.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ Abstract:
1919

2020
BubbleDots.traits.PoisonTrait.prototype = {
2121
displayName : "PoisonTrait", // Unique string name for this Trait
22-
originalColor : "1",
23-
color : "1",
22+
color : "2",
2423

2524
/**
2625
* @inheritDoc
2726
*/
2827
attach: function(anEntity) {
2928
BubbleDots.traits.PoisonTrait.superclass.attach.call(this, anEntity);
30-
this.intercept(['onCollision', 'color', 'originalColor']);
29+
this.intercept(['onCollision', 'color']);
3130
},
3231

3332
/**
@@ -47,14 +46,13 @@ Abstract:
4746
* @param collisionNormal A vector describing the collision
4847
*/
4948
onCollision: function(a, b, collisionNormal) {
50-
return;
5149
// We're either A or B, so perform a simple check against A to figure out which of the two objects we are
5250
var me = this === a ? a : b;
5351
var them = this === a ? b : a;
5452

55-
var newRadius = Math.max( 0.1, them.radius-0.5 );
56-
them.radius = newRadius;
57-
them.collisionCircle.setRadius( newRadius );
53+
// var newRadius = Math.max( 0.1, them.radius-0.5 );
54+
// them.radius = newRadius;
55+
// them.collisionCircle.setRadius( newRadius );
5856

5957
them.acceleration.translatePoint( collisionNormal.multiply(them.velocityMax) );
6058
}

0 commit comments

Comments
 (0)