浏览代码

Update Basketball game

customisations
alemart 8 个月前
父节点
当前提交
d65f33d77e

demos/basketball/assets/net.wav → demos/basketball/assets/basket.wav 查看文件


+ 1
- 1
demos/basketball/src/core/asset-list.js 查看文件

23
     // sounds
23
     // sounds
24
     'backboard.wav',
24
     'backboard.wav',
25
     'bounce.wav',
25
     'bounce.wav',
26
-    'net.wav',
26
+    'basket.wav',
27
     'bonus.wav',
27
     'bonus.wav',
28
     'win.wav',
28
     'win.wav',
29
     'lose.wav',
29
     'lose.wav',

+ 12
- 16
demos/basketball/src/entities/ball.js 查看文件

14
 const BALL_RADIUS = 0.27;
14
 const BALL_RADIUS = 0.27;
15
 
15
 
16
 /** Minimum distance for scoring 3 points */
16
 /** Minimum distance for scoring 3 points */
17
-const THREE_POINT_THRESHOLD = 5.0;
17
+const THREE_POINT_THRESHOLD = 6.0;
18
 
18
 
19
 /** Shoot angle */
19
 /** Shoot angle */
20
 const SHOOT_ANGLE = Math.PI / 4;
20
 const SHOOT_ANGLE = Math.PI / 4;
21
 
21
 
22
 /** Shoot sensitivity multiplier (y and z axes) */
22
 /** Shoot sensitivity multiplier (y and z axes) */
23
-const SHOOT_SENSITIVITY = 1.65;
23
+const SHOOT_SENSITIVITY = 1.5;
24
 
24
 
25
 /** Shoot sensitivity multiplier (x-axis) */
25
 /** Shoot sensitivity multiplier (x-axis) */
26
 const SHOOT_HORIZONTAL_SENSITIVITY = 0.5;
26
 const SHOOT_HORIZONTAL_SENSITIVITY = 0.5;
128
 
128
 
129
         if(ar.pointers.length > 0) {
129
         if(ar.pointers.length > 0) {
130
             const pointer = ar.pointers[0];
130
             const pointer = ar.pointers[0];
131
-            const position = ar.session.viewport.convertToPixels(pointer.position, 'adjusted');
131
+            const position = ar.session.viewport.convertToPixels(pointer.position, pointer.tracker.space);
132
 
132
 
133
             if(position.x > 60) {
133
             if(position.x > 60) {
134
                 impostor.mass = 1; // enable gravity
134
                 impostor.mass = 1; // enable gravity
167
     _onThrownState()
167
     _onThrownState()
168
     {
168
     {
169
         const ar = this.ar;
169
         const ar = this.ar;
170
+        const rootPosition = ar.root.absolutePosition;
170
         const cameraPosition = ar.camera.globalPosition;
171
         const cameraPosition = ar.camera.globalPosition;
171
         const ballPosition = this._mesh.absolutePosition;
172
         const ballPosition = this._mesh.absolutePosition;
172
         const distance = BABYLON.Vector3.Distance(cameraPosition, ballPosition);
173
         const distance = BABYLON.Vector3.Distance(cameraPosition, ballPosition);
173
 
174
 
174
-        if(distance > MAX_DISTANCE || ballPosition.y < cameraPosition.y - MAX_Y_DISTANCE) {
175
+        if(distance > MAX_DISTANCE || ballPosition.y < rootPosition.y - MAX_Y_DISTANCE) {
175
             this._broadcast(new GameEvent('lostball'));
176
             this._broadcast(new GameEvent('lostball'));
176
             this._state = 'ready';
177
             this._state = 'ready';
177
         }
178
         }
185
     _throw(v)
186
     _throw(v)
186
     {
187
     {
187
         const magnitude = SHOOT_SENSITIVITY * v.y;
188
         const magnitude = SHOOT_SENSITIVITY * v.y;
188
-        const angle = SHOOT_ANGLE;
189
         const impulse = new BABYLON.Vector3(
189
         const impulse = new BABYLON.Vector3(
190
             v.x * SHOOT_HORIZONTAL_SENSITIVITY,
190
             v.x * SHOOT_HORIZONTAL_SENSITIVITY,
191
-            magnitude * Math.sin(angle),
192
-            -magnitude * Math.cos(angle)
191
+            magnitude * Math.sin(SHOOT_ANGLE),
192
+            -magnitude * Math.cos(SHOOT_ANGLE)
193
         );
193
         );
194
 
194
 
195
         this._positionWhenThrown.copyFrom(this._mesh.absolutePosition);
195
         this._positionWhenThrown.copyFrom(this._mesh.absolutePosition);
204
      */
204
      */
205
     _findVelocity(pointer)
205
     _findVelocity(pointer)
206
     {
206
     {
207
-        // we could return pointer.velocity, but that's not always
208
-        // user-friendly when it comes to throwing the ball!
209
-        const currentSpeed = pointer.velocity.length();
210
-        const averageSpeed = pointer.totalDistance / pointer.elapsedTime;
211
-        const speed = Math.max(currentSpeed, averageSpeed);
207
+        if(pointer.movementDuration == 0)
208
+            return pointer.velocity.times(0);
212
 
209
 
213
-        let direction = pointer.initialPosition.directionTo(pointer.position);
214
-        if(direction.y < 0)
215
-            direction = pointer.deltaPosition.normalized();
210
+        const averageSpeed = pointer.movementLength / pointer.movementDuration;
211
+        const direction = pointer.initialPosition.directionTo(pointer.position);
216
 
212
 
217
-        return direction.times(speed);
213
+        return direction.times(averageSpeed);
218
     }
214
     }
219
 
215
 
220
     /**
216
     /**

+ 1
- 1
demos/basketball/src/entities/gui/gui-control.js 查看文件

22
     constructor(game)
22
     constructor(game)
23
     {
23
     {
24
         super(game);
24
         super(game);
25
-        this._parent = demo.gui;
25
+        this._parent = game.gui;
26
         this._control = null;
26
         this._control = null;
27
     }
27
     }
28
 
28
 

+ 1
- 1
demos/basketball/src/entities/jukebox.js 查看文件

54
     {
54
     {
55
         switch(event.type) {
55
         switch(event.type) {
56
             case 'scored':
56
             case 'scored':
57
-                this._play('net', event.detail.position);
57
+                this._play('basket', event.detail.position);
58
                 if(event.detail.score == 3)
58
                 if(event.detail.score == 3)
59
                     this._play('bonus');
59
                     this._play('bonus');
60
                 break;
60
                 break;

+ 5
- 5
demos/basketball/src/entities/lights.js 查看文件

24
         const dlight = new BABYLON.DirectionalLight('dlight', BABYLON.Vector3.Down());
24
         const dlight = new BABYLON.DirectionalLight('dlight', BABYLON.Vector3.Down());
25
 
25
 
26
         light.intensity = 1.0;
26
         light.intensity = 1.0;
27
-        light.diffuse.set(1, 1, 1);
28
-        light.groundColor.set(1, 1, 1);
29
-        light.specular.set(0, 0, 0);
27
+        light.diffuse = new BABYLON.Color3(1, 1, 1);
28
+        light.groundColor = new BABYLON.Color3(1, 1, 1);
29
+        light.specular = new BABYLON.Color3(0, 0, 0);
30
 
30
 
31
         dlight.intensity = 1.0;
31
         dlight.intensity = 1.0;
32
-        dlight.diffuse.set(1, 1, 1);
33
-        dlight.specular.set(1, 1, 1);
32
+        dlight.diffuse = new BABYLON.Color3(1, 1, 1);
33
+        dlight.specular = new BABYLON.Color3(1, 1, 1);
34
 
34
 
35
         const ar = this.ar;
35
         const ar = this.ar;
36
         dlight.parent = ar.root;
36
         dlight.parent = ar.root;

+ 1
- 1
demos/basketball/src/entities/scoreboard.js 查看文件

142
             depth: 1.0,
142
             depth: 1.0,
143
         });
143
         });
144
 
144
 
145
-        this._mesh.position = new BABYLON.Vector3(2.5, 0.5, 0);
145
+        this._mesh.position = new BABYLON.Vector3(2.0, 0.35, 0.5);
146
         this._mesh.rotate(BABYLON.Axis.Y, -Math.PI / 6);
146
         this._mesh.rotate(BABYLON.Axis.Y, -Math.PI / 6);
147
 
147
 
148
         this._mesh.material = new BABYLON.StandardMaterial('ScoreboardMaterial');
148
         this._mesh.material = new BABYLON.StandardMaterial('ScoreboardMaterial');

正在加载...
取消
保存