PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 4ms RepoModel.GetById 36ms app.codeStats 0ms

/js/BubbleDots/traits/FoodTrait.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 81 lines | 34 code | 12 blank | 35 comment | 0 complexity | 532c89f17865764dda91fbce875a1e05 MD5 | raw file
 1/**
 2 File:
 3 FoodTrait.js
 4 Created By:
 5 Mario Gonzalez
 6 Project    :
 7 RealtimeMultiplayerNodeJS
 8 Abstract:
 9
10 Basic Usage:
11
12 */
13(function () {
14    BubbleDots.namespace("BubbleDots.traits");
15
16    BubbleDots.traits.FoodTrait = function () {
17        BubbleDots.traits.FoodTrait.superclass.constructor.call(this);
18    };
19
20    BubbleDots.traits.FoodTrait.prototype = {
21        displayName: "FoodTrait",					// Unique string name for this Trait
22        color: "3",
23
24        /**
25         * @inheritDoc
26         */
27        attach: function (anEntity) {
28            BubbleDots.traits.FoodTrait.superclass.attach.call(this, anEntity);
29            this.intercept(['onCollision', 'color']);
30        },
31
32        /**
33         * @inheritDoc
34         */
35        execute: function () {
36            BubbleDots.traits.FoodTrait.superclass.execute.call(this);
37        },
38
39        /**
40         * Intercepted properties
41         */
42        /**
43         * Called when this object has collided with another
44         * @param a        Object A in the collision pair, note this may be this object
45         * @param b        Object B in the collision pair, note this may be this object
46         * @param collisionNormal    A vector describing the collision
47         */
48        onCollision: function (a, b, collisionNormal) {
49
50            // We're either A or B, so perform a simple check against A to figure out which of the two objects we are
51            var me = this === a ? a : b;
52            var them = this === a ? b : a;
53
54//			me.addTrait( )
55
56            BubbleDots.lib.TWEEN.remove(me._tween);
57            me._tween = new BubbleDots.lib.TWEEN.Tween({radius: me.radius})
58                .to({radius: 2}, 500)
59                .easing(BubbleDots.lib.TWEEN.Easing.Back.EaseInOut)
60                .onUpdate(function () {
61                    me.setRadius(~~this.radius);
62                })
63                .start();
64
65//			var newRadius = Math.max( BubbleDots.traits.FoodTrait.prototype.radius, them.radius+0.1 );
66//			them.radius = newRadius;
67//			them.collisionCircle.setRadius( newRadius );
68            me.collisionCircle.collisionGroup = 0;
69//			me.acceleration.translatePoint( collisionNormal.multiply(-10) );
70
71            var chaseTrait = this.addTraitAndExecute(new BubbleDots.traits.ChaseTrait());
72            chaseTrait.setTarget(them);
73            this.addTraitAndExecute(new BubbleDots.traits.PerlinNoiseTrait());
74//			me.tempColor();
75        }
76
77    };
78
79    // Extend BaseTrait
80    RealtimeMultiplayerGame.extend(BubbleDots.traits.FoodTrait, RealtimeMultiplayerGame.controller.traits.BaseTrait);
81})();