PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/js/DemoCircles/PlayerEntity.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 73 lines | 41 code | 11 blank | 21 comment | 5 complexity | 0738c1b9fd034a92c54808babbd2903c MD5 | raw file
 1/**
 2 File:
 3 DemoApp.CircleEntity
 4 Created By:
 5 Mario Gonzalez
 6 Project:
 7 DemoApp
 8 Abstract:
 9 This is the base entity for the demo game
10 Basic Usage:
11
12 Version:
13 1.0
14 */
15(function () {
16
17    DemoApp.PlayerEntity = function (anEntityid, aClientid) {
18        DemoApp.PlayerEntity.superclass.constructor.call(this, anEntityid, aClientid);
19
20        return this;
21    };
22
23    DemoApp.PlayerEntity.prototype = {
24        entityType: DemoApp.Constants.ENTITY_TYPES.PLAYER_ENTITY,
25        input: null,
26        radius: 40,
27
28        updateView: function () {
29            DemoApp.PlayerEntity.superclass.updateView.call(this);
30        },
31
32        setInput: function (input) {
33            this.input = input;
34        },
35
36        updatePosition: function () {
37            var moveSpeed = 1.5;
38            // Horizontal accelertheation
39            if (this.input.isLeft()) this.acceleration.x -= moveSpeed;
40            if (this.input.isRight()) this.acceleration.x += moveSpeed;
41
42            // Vertical movement
43            if (this.input.isUp()) this.acceleration.y -= moveSpeed;
44            if (this.input.isDown()) this.acceleration.y += moveSpeed;
45
46            this.velocity.translatePoint(this.acceleration);
47            this.velocity.limit(5);
48            this.velocity.multiply(0.85);
49            this.acceleration.set(0, 0);
50            this.collisionCircle.position.translatePoint(this.velocity);
51            this.position = this.collisionCircle.position.clone();
52        },
53
54        setCollisionCircle: function (aCollisionCircle) {
55            DemoApp.PlayerEntity.superclass.setCollisionCircle.call(this, aCollisionCircle);
56            //	this.collisionCircle.setIsFixed( true );
57        },
58
59        /**
60         * Deallocate memory
61         */
62        dealloc: function () {
63            if (this.input) {
64                this.input.dealloc();
65                delete this.input;
66            }
67            DemoApp.CircleEntity.superclass.dealloc.call(this);
68        }
69    };
70
71    // extend RealtimeMultiplayerGame.model.GameEntity
72    RealtimeMultiplayerGame.extend(DemoApp.PlayerEntity, DemoApp.CircleEntity, null);
73})();