PageRenderTime 19ms CodeModel.GetById 16ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/js/BubbleDots/traits/PoisonTrait.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 64 lines | 23 code | 9 blank | 32 comment | 0 complexity | e708532f1f483e9136e81e7d9e94346d MD5 | raw file
 1/**
 2 File:
 3 PoisonTrait.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.PoisonTrait = function () {
17        BubbleDots.traits.PoisonTrait.superclass.constructor.call(this);
18    };
19
20    BubbleDots.traits.PoisonTrait.prototype = {
21        displayName: "PoisonTrait",					// Unique string name for this Trait
22        color: "2",
23
24        /**
25         * @inheritDoc
26         */
27        attach: function (anEntity) {
28            BubbleDots.traits.PoisonTrait.superclass.attach.call(this, anEntity);
29            this.intercept(['onCollision', 'color']);
30        },
31
32        /**
33         * @inheritDoc
34         */
35        execute: function () {
36            BubbleDots.traits.PoisonTrait.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            // We're either A or B, so perform a simple check against A to figure out which of the two objects we are
50            var me = this === a ? a : b;
51            var them = this === a ? b : a;
52
53//			var newRadius = Math.max( 0.1, them.radius-0.5 );
54//			them.radius = newRadius;
55//			them.collisionCircle.setRadius( newRadius );
56
57            them.acceleration.translatePoint(collisionNormal.multiply(them.velocityMax * 0.9));
58        }
59
60    };
61
62    // Extend BaseTrait
63    RealtimeMultiplayerGame.extend(BubbleDots.traits.PoisonTrait, RealtimeMultiplayerGame.controller.traits.BaseTrait);
64})();