|
@@ -2,6 +2,7 @@ import * as THREE from "three"
|
2
|
2
|
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'
|
3
|
3
|
import { Object3D } from "three";
|
4
|
4
|
|
|
5
|
+import { GameController } from "./controller"
|
5
|
6
|
|
6
|
7
|
|
7
|
8
|
export class FooGame {
|
|
@@ -17,11 +18,13 @@ export class FooGame {
|
17
|
18
|
|
18
|
19
|
updateMap: Object;
|
19
|
20
|
|
|
21
|
+ controller: GameController;
|
|
22
|
+
|
20
|
23
|
constructor() {
|
21
|
24
|
this.camera = new THREE.PerspectiveCamera(this.cam_fov, this.cam_aspect, 0.01, 10)
|
22
|
|
- this.camera.position.x = 3;
|
|
25
|
+ this.camera.position.x = 0;
|
23
|
26
|
this.camera.position.y = 3;
|
24
|
|
- this.camera.position.z = 3;
|
|
27
|
+ this.camera.position.z = 5;
|
25
|
28
|
|
26
|
29
|
this.scene = new THREE.Scene();
|
27
|
30
|
|
|
@@ -34,10 +37,28 @@ export class FooGame {
|
34
|
37
|
|
35
|
38
|
this.updateMap = {};
|
36
|
39
|
|
|
40
|
+ this.controller = new GameController(document.body);
|
|
41
|
+
|
37
|
42
|
this.animate();
|
38
|
43
|
//this.loadScene();
|
39
|
44
|
}
|
40
|
45
|
|
|
46
|
+ bindKeyAction(box: Object3D) {
|
|
47
|
+ this.controller.onKey_A(() => {
|
|
48
|
+ if (box) box.position.x -= 0.1;
|
|
49
|
+ });
|
|
50
|
+ this.controller.onKey_D(() => {
|
|
51
|
+ if (box) box.position.x += 0.1;
|
|
52
|
+ });
|
|
53
|
+ this.controller.onKey_S(() => {
|
|
54
|
+ if (box) box.position.z += 0.1;
|
|
55
|
+ });
|
|
56
|
+ this.controller.onKey_W(() => {
|
|
57
|
+ if (box) box.position.z -= 0.1;
|
|
58
|
+ });
|
|
59
|
+
|
|
60
|
+ }
|
|
61
|
+
|
41
|
62
|
animate() {
|
42
|
63
|
requestAnimationFrame(() => {
|
43
|
64
|
this.animate();
|
|
@@ -96,12 +117,13 @@ let game = new FooGame();
|
96
|
117
|
game.loadScene(() => {
|
97
|
118
|
let box = game.scene.getObjectByName("Box");
|
98
|
119
|
if (box) {
|
|
120
|
+ game.bindKeyAction(box);
|
99
|
121
|
game.setUpdate(box, (obj: Object3D) => {
|
100
|
122
|
//game.camera.rotateOnAxis(obj.position, 0.01)
|
101
|
|
- obj.position.x+= performance.now()*0.000001;
|
102
|
|
- obj.position.z+= performance.now()*0.000001;
|
|
123
|
+ //obj.position.x += performance.now() * 0.000001;
|
|
124
|
+ //obj.position.z += performance.now() * 0.000001;
|
103
|
125
|
obj.rotateY(0.01);
|
104
|
|
- game.camera.lookAt(obj.position)
|
|
126
|
+ //game.camera.lookAt(obj.position)
|
105
|
127
|
});
|
106
|
128
|
}
|
107
|
129
|
})
|