Procházet zdrojové kódy

Update Basketball game

customisations
alemart před 8 měsíci
rodič
revize
d65f33d77e

demos/basketball/assets/net.wav → demos/basketball/assets/basket.wav Zobrazit soubor


+ 1
- 1
demos/basketball/src/core/asset-list.js Zobrazit soubor

@@ -23,7 +23,7 @@ export const ASSET_LIST = Object.freeze([
23 23
     // sounds
24 24
     'backboard.wav',
25 25
     'bounce.wav',
26
-    'net.wav',
26
+    'basket.wav',
27 27
     'bonus.wav',
28 28
     'win.wav',
29 29
     'lose.wav',

+ 12
- 16
demos/basketball/src/entities/ball.js Zobrazit soubor

@@ -14,13 +14,13 @@ import { GameEvent } from '../core/events.js';
14 14
 const BALL_RADIUS = 0.27;
15 15
 
16 16
 /** Minimum distance for scoring 3 points */
17
-const THREE_POINT_THRESHOLD = 5.0;
17
+const THREE_POINT_THRESHOLD = 6.0;
18 18
 
19 19
 /** Shoot angle */
20 20
 const SHOOT_ANGLE = Math.PI / 4;
21 21
 
22 22
 /** Shoot sensitivity multiplier (y and z axes) */
23
-const SHOOT_SENSITIVITY = 1.65;
23
+const SHOOT_SENSITIVITY = 1.5;
24 24
 
25 25
 /** Shoot sensitivity multiplier (x-axis) */
26 26
 const SHOOT_HORIZONTAL_SENSITIVITY = 0.5;
@@ -128,7 +128,7 @@ export class Ball extends Entity
128 128
 
129 129
         if(ar.pointers.length > 0) {
130 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 133
             if(position.x > 60) {
134 134
                 impostor.mass = 1; // enable gravity
@@ -167,11 +167,12 @@ export class Ball extends Entity
167 167
     _onThrownState()
168 168
     {
169 169
         const ar = this.ar;
170
+        const rootPosition = ar.root.absolutePosition;
170 171
         const cameraPosition = ar.camera.globalPosition;
171 172
         const ballPosition = this._mesh.absolutePosition;
172 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 176
             this._broadcast(new GameEvent('lostball'));
176 177
             this._state = 'ready';
177 178
         }
@@ -185,11 +186,10 @@ export class Ball extends Entity
185 186
     _throw(v)
186 187
     {
187 188
         const magnitude = SHOOT_SENSITIVITY * v.y;
188
-        const angle = SHOOT_ANGLE;
189 189
         const impulse = new BABYLON.Vector3(
190 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 195
         this._positionWhenThrown.copyFrom(this._mesh.absolutePosition);
@@ -204,17 +204,13 @@ export class Ball extends Entity
204 204
      */
205 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 Zobrazit soubor

@@ -22,7 +22,7 @@ export class GUIControl extends Entity
22 22
     constructor(game)
23 23
     {
24 24
         super(game);
25
-        this._parent = demo.gui;
25
+        this._parent = game.gui;
26 26
         this._control = null;
27 27
     }
28 28
 

+ 1
- 1
demos/basketball/src/entities/jukebox.js Zobrazit soubor

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

+ 5
- 5
demos/basketball/src/entities/lights.js Zobrazit soubor

@@ -24,13 +24,13 @@ export class Lights extends Entity
24 24
         const dlight = new BABYLON.DirectionalLight('dlight', BABYLON.Vector3.Down());
25 25
 
26 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 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 35
         const ar = this.ar;
36 36
         dlight.parent = ar.root;

+ 1
- 1
demos/basketball/src/entities/scoreboard.js Zobrazit soubor

@@ -142,7 +142,7 @@ export class Scoreboard extends PhysicsEntity
142 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 146
         this._mesh.rotate(BABYLON.Axis.Y, -Math.PI / 6);
147 147
 
148 148
         this._mesh.material = new BABYLON.StandardMaterial('ScoreboardMaterial');

Načítá se…
Zrušit
Uložit