-
Notifications
You must be signed in to change notification settings - Fork 50
/
player.js
148 lines (91 loc) · 3.16 KB
/
player.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
* @author Niklas von Hertzen <niklas at hertzen.com>
* @created 4.1.2012
* @website http://hertzen.com
*/
GTA.Player = function ( game, x, y, z ) {
this.position.x = x;
this.position.y = y;
this.position.z = z;
this.registerAnimations( game.spriteNumbers.offset.PED );
this.initPhysics( game );
var geom = THREE.GeometryUtils.clone( game.sprites[ this.animationSprites[ 0 ][ 0 ] ].sprite.geometry );
this.sprite = new THREE.Mesh( geom, game.sprites[ this.animationSprites[ 0 ][ 0 ] ].sprite.material );
//this.sprite = THREE.SceneUtils.cloneObject( game.sprites[ this.animationSprites[ 0 ][ 0 ] ].sprite );
//this.sprite.geometry = THREE.GeometryUtils.clone( this.sprite.geometry );
this.sprite.geometry.dynamic = true;
this.spriteAnimator = new GTA.SpriteAnimation( game, this.animationSprites[ 0 ][ 0 ], this.sprite );
this.game = game;
this.add( this.sprite );
this.speed = 700;
this.rotationSpeed = 0.1;
this.weapon = 0;
this.lastframe = 0;
this.runningFrames = [];
this.spriteframe = 0;
this.domElement = document;
this.onKeyDown = function ( event ) {
switch( event.keyCode ) {
case 38: /*up*/
case 87: /*W*/
this.moveForward = true;
break;
case 37: /*left*/
case 65: /*A*/
this.turnLeft = true;
break;
case 40: /*down*/
case 83: /*S*/
this.moveBackward = true;
break;
case 39: /*right*/
case 68: /*D*/
this.turnRight = true;
break;
case 82: /*R*/
this.moveUp = true;
break;
case 70: /*F*/
this.moveDown = true;
break;
case 81: /*Q*/
this.freeze = !this.freeze;
break;
}
};
this.onKeyUp = function ( event ) {
switch( event.keyCode ) {
case 38: /*up*/
case 87: /*W*/
this.moveForward = false;
break;
case 37: /*left*/
case 65: /*A*/
this.turnLeft = false;
break;
case 40: /*down*/
case 83: /*S*/
this.moveBackward = false;
break;
case 39: /*right*/
case 68: /*D*/
this.turnRight = false;
break;
case 82: /*R*/
this.moveUp = false;
break;
case 70: /*F*/
this.moveDown = false;
break;
}
};
this.domElement.addEventListener( 'keydown', bind( this, this.onKeyDown ), false );
this.domElement.addEventListener( 'keyup', bind( this, this.onKeyUp ), false );
};
function bind( scope, fn ) {
return function () {
fn.apply( scope, arguments );
};
};
GTA.Player.prototype = GTA.Pedestrian.prototype;
GTA.Player.prototype.constructor = GTA.Player;