-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameObject.ts
95 lines (75 loc) · 2.55 KB
/
gameObject.ts
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
/// <reference path="typings/index.d.ts" />
class GameObject {
protected _object : THREE.Mesh;
protected geometry : THREE.Geometry;
protected material : THREE.MeshLambertMaterial;
protected _width : number;
protected _height : number;
protected _depth : number;
protected _speedX : number;
protected _speedY : number;
protected _speedZ : number;
protected _hexColor : number;
protected _boundingBox : THREE.Box3;
protected _game : Game;
public get object() : THREE.Mesh {
return this._object;
}
public get width() : number {
return this._width;
}
public get height() : number {
return this._height;
}
public get depth() : number {
return this._depth;
}
public get speedX() : number {
return this._speedX;
}
public set speedX(value : number) {
this._speedX = value;
}
public get speedY() : number {
return this._speedY;
}
public set speedY(value : number) {
this._speedY = value;
}
public get speedZ() : number {
return this._speedZ;
}
public set speedZ(value : number) {
this._speedZ = value;
}
public get color() : number {
return this._hexColor;
}
public get game() : Game {
return this._game;
}
public get boundingBox() : THREE.Box3 {
return this._boundingBox;
}
constructor(hexColor: number, width : number, height : number, depth : number, startPositionZ : number, game : Game){
this._width = width;
this._height = height;
this._depth = depth;
this._hexColor = hexColor;
this.speedX = this.speedY = this.speedZ = 0;
this._game = game;
this.geometry = new THREE.BoxGeometry(this._width, this._height, this._depth);
this.material = new THREE.MeshLambertMaterial({ color: hexColor });
this._object = new THREE.Mesh(this.geometry, this.material);
this._object.position.z = startPositionZ;
this._object.position.x = 0;
game.scene.add(this._object);
this._boundingBox = new THREE.Box3();
}
public move() : void {
this._object.position.x += this._speedX;
this._object.position.y += this._speedY;
this._object.position.z += this._speedZ;
this._boundingBox.setFromObject(this._object);
}
}