PageRenderTime 121ms CodeModel.GetById 60ms app.highlight 4ms RepoModel.GetById 37ms app.codeStats 0ms

/js/DemoHelloWorld/CircleEntity.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 70 lines | 26 code | 7 blank | 37 comment | 1 complexity | 0f148fcc9f7382e8819d175e736f6372 MD5 | raw file
 1/**
 2 File:
 3 DemoHelloWorld.CircleEntity
 4 Created By:
 5 Mario Gonzalez
 6 Project:
 7 DemoHelloWorld
 8 Abstract:
 9 This is the most basic entity i could come up with for a HelloWorldDemo of RealtimeMultiplayerNodeJS
10 Basic Usage:
11 // Create the GameEntity
12 var circleEntity = new DemoHelloWorld.CircleEntity( anEntityid, aClientid );
13 circleEntity.entityType = DemoHelloWorld.Constants.ENTITY_TYPES.GENERIC_CIRCLE;
14 circleEntity.radius = aRadius;
15 circleEntity.position.set( Math.random() * DemoHelloWorld.Constants.GAME_WIDTH, Math.random() * DemoHelloWorld.Constants.GAME_HEIGHT);
16
17 // Place the circle and collision circle into corresponding containers
18 this.fieldController.addEntity( circleEntity );
19 Version:
20 1.0
21 */
22(function () {
23    DemoHelloWorld.CircleEntity = function (anEntityid, aClientid) {
24        DemoHelloWorld.CircleEntity.superclass.constructor.call(this, anEntityid, aClientid);
25        this.speed = Math.random();
26        return this;
27    };
28
29    DemoHelloWorld.CircleEntity.prototype = {
30        speed: 0,
31        radius: DemoHelloWorld.Constants.ENTITY_DEFAULT_RADIUS,
32        entityType: DemoHelloWorld.Constants.ENTITY_TYPES.CIRCLE,
33
34        /**
35         * Update the entity's view - this is only called on the clientside
36         */
37        updateView: function () {
38            if (!this.view) return;
39            this.view.x = this.position.x - this.radius;
40            this.view.y = this.position.y - this.radius;
41        },
42
43        /**
44         * @inheritDoc
45         */
46        updatePosition: function (speedFactor, gameClock, gameTick) {
47            // This is where you would move your entity here
48            // Speedfactor is a number between 0.0 and 2.0, where 1.0 means its running at perfect framerate
49
50        },
51
52        /**
53         * Deallocate memory
54         */
55        dealloc: function () {
56            DemoHelloWorld.CircleEntity.superclass.dealloc.call(this);
57        },
58
59        /**
60         * Append radius to our entity description created by the super class
61         */
62        constructEntityDescription: function () {
63            // Note: "~~" is just a way to round the value without the Math.round function call
64            return DemoHelloWorld.CircleEntity.superclass.constructEntityDescription.call(this) + ',' + ~~this.radius;
65        }
66    };
67
68    // extend RealtimeMultiplayerGame.model.GameEntity
69    RealtimeMultiplayerGame.extend(DemoHelloWorld.CircleEntity, RealtimeMultiplayerGame.model.GameEntity, null);
70})();