Browse Source

Update Basketball game

customisations
alemart 8 months ago
parent
commit
1c452cb86d

+ 1
- 1
demos/basketball/src/core/game.js View File

@@ -228,7 +228,7 @@ export class BasketballGame extends ARDemo
228 228
             this.spawn(TutorialOverlay),
229 229
             this.spawn(GameOverOverlay),
230 230
 
231
-        ]);
231
+        ]).then(() => void 0);
232 232
     }
233 233
 
234 234
     /**

+ 1
- 1
demos/basketball/src/core/globals.js View File

@@ -11,7 +11,7 @@
11 11
 export const NUMBER_OF_BALLS = 5;
12 12
 
13 13
 /** The minimum score for each rank */
14
-export const SCORE_TABLE = Object.freeze({
14
+export const RANK_TABLE = Object.freeze({
15 15
     'S':  15,
16 16
     'A+': 12,
17 17
     'A':  11,

+ 4
- 4
demos/basketball/src/entities/ball.js View File

@@ -50,11 +50,11 @@ export class Ball extends Entity
50 50
 {
51 51
     /**
52 52
      * Constructor
53
-     * @param {BasketballDemo} demo
53
+     * @param {BasketballGame} game
54 54
      */
55
-    constructor(demo)
55
+    constructor(game)
56 56
     {
57
-        super(demo);
57
+        super(game);
58 58
 
59 59
         this._state = 'ready';
60 60
         this._runState = {
@@ -77,7 +77,7 @@ export class Ball extends Entity
77 77
      */
78 78
     async init()
79 79
     {
80
-        const file = this._demo.assetManager.file('ball.glb');
80
+        const file = this._game.assetManager.file('ball.glb');
81 81
         const gltf = await BABYLON.SceneLoader.ImportMeshAsync('', '', file);
82 82
         const mesh = this._createPhysicsRoot(gltf.meshes[0]); // gltf.meshes[0] is __root__
83 83
 

+ 8
- 8
demos/basketball/src/entities/entity.js View File

@@ -14,11 +14,11 @@ export class Entity
14 14
 {
15 15
     /**
16 16
      * Constructor
17
-     * @param {BasketballDemo} demo
17
+     * @param {BasketballGame} game
18 18
      */
19
-    constructor(demo)
19
+    constructor(game)
20 20
     {
21
-        this._demo = demo;
21
+        this._game = game;
22 22
     }
23 23
 
24 24
     /**
@@ -62,7 +62,7 @@ export class Entity
62 62
      */
63 63
     _broadcast(event)
64 64
     {
65
-        this._demo.broadcast(event);
65
+        this._game.broadcast(event);
66 66
     }
67 67
 
68 68
     /**
@@ -71,7 +71,7 @@ export class Entity
71 71
      */
72 72
     get ar()
73 73
     {
74
-        return this._demo.ar;
74
+        return this._game.ar;
75 75
     }
76 76
 }
77 77
 
@@ -83,11 +83,11 @@ export class PhysicsEntity extends Entity
83 83
 {
84 84
     /**
85 85
      * Constructor
86
-     * @param {BasketballDemo} demo
86
+     * @param {BasketballGame} game
87 87
      */
88
-    constructor(demo)
88
+    constructor(game)
89 89
     {
90
-        super(demo);
90
+        super(game);
91 91
         this._physicsAnchor = null;
92 92
     }
93 93
 

+ 5
- 5
demos/basketball/src/entities/game-controller.js View File

@@ -9,7 +9,7 @@
9 9
 
10 10
 import { Entity } from './entity.js';
11 11
 import { GameEvent } from '../core/events.js';
12
-import { NUMBER_OF_BALLS, SCORE_TABLE } from '../core/globals.js';
12
+import { NUMBER_OF_BALLS, RANK_TABLE } from '../core/globals.js';
13 13
 
14 14
 /**
15 15
  * The Game Controller manages the state of the game
@@ -18,11 +18,11 @@ export class GameController extends Entity
18 18
 {
19 19
     /**
20 20
      * Constructor
21
-     * @param {BasketballDemo} demo
21
+     * @param {BasketballGame} game
22 22
      */
23
-    constructor(demo)
23
+    constructor(game)
24 24
     {
25
-        super(demo);
25
+        super(game);
26 26
 
27 27
         this._ballsLeft = NUMBER_OF_BALLS;
28 28
         this._score = 0;
@@ -81,7 +81,7 @@ export class GameController extends Entity
81 81
      */
82 82
     _computeRank(score)
83 83
     {
84
-        const entries = Object.entries(SCORE_TABLE).sort((a, b) => b[1] - a[1]);
84
+        const entries = Object.entries(RANK_TABLE).sort((a, b) => b[1] - a[1]);
85 85
 
86 86
         for(const [rank, minScore] of entries) {
87 87
             if(score >= minScore)

+ 4
- 4
demos/basketball/src/entities/goal.js View File

@@ -20,11 +20,11 @@ export class Goal extends PhysicsEntity
20 20
 {
21 21
     /**
22 22
      * Constructor
23
-     * @param {BasketballDemo} demo
23
+     * @param {BasketballGame} game
24 24
      */
25
-    constructor(demo)
25
+    constructor(game)
26 26
     {
27
-        super(demo);
27
+        super(game);
28 28
         this._physicsRoot = null;
29 29
     }
30 30
 
@@ -34,7 +34,7 @@ export class Goal extends PhysicsEntity
34 34
      */
35 35
     async init()
36 36
     {
37
-        const file = this._demo.assetManager.file('goal.glb');
37
+        const file = this._game.assetManager.file('goal.glb');
38 38
         const gltf = await BABYLON.SceneLoader.ImportMeshAsync('', '', file);
39 39
         this._physicsRoot = this._createPhysicsRoot(gltf.meshes);
40 40
         this._physicsRoot.position.y = Y_OFFSET;

+ 3
- 3
demos/basketball/src/entities/gravity.js View File

@@ -19,11 +19,11 @@ export class Gravity extends Entity
19 19
 {
20 20
     /**
21 21
      * Constructor
22
-     * @param {BasketballDemo} demo
22
+     * @param {BasketballGame} game
23 23
      */
24
-    constructor(demo)
24
+    constructor(game)
25 25
     {
26
-        super(demo);
26
+        super(game);
27 27
         this._gravity = new BABYLON.Vector3();
28 28
         this._isTracking = false;
29 29
     }

+ 3
- 3
demos/basketball/src/entities/gui/ball-counter.js View File

@@ -22,7 +22,7 @@ class BallIcon extends GUIControl
22 22
      */
23 23
     _createControl()
24 24
     {
25
-        const url = this._demo.assetManager.url('atlas.png');
25
+        const url = this._game.assetManager.url('atlas.png');
26 26
         const icon = new BABYLON.GUI.Image('ballIcon', url);
27 27
 
28 28
         icon.sourceLeft = 896;
@@ -103,10 +103,10 @@ export class BallCounter extends Entity
103 103
         const icons = [];
104 104
 
105 105
         for(let i = 0; i < NUMBER_OF_BALLS; i++) {
106
-            const icon = this._demo.spawn(BallIcon).then(icon => icon.setId(i));
106
+            const icon = this._game.spawn(BallIcon).then(icon => icon.setId(i));
107 107
             icons.push(icon);
108 108
         }
109 109
 
110
-        return Promise.all(icons);
110
+        return Promise.all(icons).then(() => void 0);
111 111
     }
112 112
 }

+ 3
- 3
demos/basketball/src/entities/gui/gameover-overlay.js View File

@@ -17,11 +17,11 @@ export class GameOverOverlay extends GUIControl
17 17
 {
18 18
     /**
19 19
      * Constructor
20
-     * @param {BasketballDemo} demo
20
+     * @param {BasketballGame} game
21 21
      */
22
-    constructor(demo)
22
+    constructor(game)
23 23
     {
24
-        super(demo);
24
+        super(game);
25 25
 
26 26
         this._messages = {
27 27
             'S' : 'YOU ARE A\nLEGEND!!!!!',

+ 3
- 3
demos/basketball/src/entities/gui/gui-control.js View File

@@ -17,11 +17,11 @@ export class GUIControl extends Entity
17 17
 {
18 18
     /**
19 19
      * Constructor
20
-     * @param {BasketballDemo} demo
20
+     * @param {BasketballGame} game
21 21
      */
22
-    constructor(demo)
22
+    constructor(game)
23 23
     {
24
-        super(demo);
24
+        super(game);
25 25
         this._parent = demo.gui;
26 26
         this._control = null;
27 27
     }

+ 1
- 1
demos/basketball/src/entities/gui/mute-button.js View File

@@ -22,7 +22,7 @@ export class MuteButton extends GUIControl
22 22
      */
23 23
     _createControl()
24 24
     {
25
-        const url = this._demo.assetManager.url('atlas.png');
25
+        const url = this._game.assetManager.url('atlas.png');
26 26
         const button = BABYLON.GUI.Button.CreateImageOnlyButton('muteButton', url);
27 27
         const offset = 1.5 + ((NUMBER_OF_BALLS / 2) | 0);
28 28
 

+ 4
- 4
demos/basketball/src/entities/gui/tutorial-overlay.js View File

@@ -19,11 +19,11 @@ export class TutorialOverlay extends GUIControl
19 19
 {
20 20
     /**
21 21
      * Constructor
22
-     * @param {BasketballDemo} demo
22
+     * @param {BasketballGame} game
23 23
      */
24
-    constructor(demo)
24
+    constructor(game)
25 25
     {
26
-        super(demo);
26
+        super(game);
27 27
         this._timer = 0;
28 28
         this._enabled = true;
29 29
     }
@@ -34,7 +34,7 @@ export class TutorialOverlay extends GUIControl
34 34
      */
35 35
     _createControl()
36 36
     {
37
-        const url = this._demo.assetManager.url('atlas.png');
37
+        const url = this._game.assetManager.url('atlas.png');
38 38
         const container = new BABYLON.GUI.Container();
39 39
         const text = new BABYLON.GUI.TextBlock();
40 40
         const hand = new BABYLON.GUI.Image('hand', url);

+ 4
- 4
demos/basketball/src/entities/jukebox.js View File

@@ -18,11 +18,11 @@ export class Jukebox extends Entity
18 18
 {
19 19
      /**
20 20
      * Constructor
21
-     * @param {BasketballDemo} demo
21
+     * @param {BasketballGame} game
22 22
      */
23
-    constructor(demo)
23
+    constructor(game)
24 24
     {
25
-        super(demo);
25
+        super(game);
26 26
         this._sound = new Map();
27 27
     }
28 28
 
@@ -35,7 +35,7 @@ export class Jukebox extends Entity
35 35
         const soundFiles = ASSET_LIST.filter(asset => asset.endsWith('.wav'));
36 36
 
37 37
         for(const filepath of soundFiles) {
38
-            const url = this._demo.assetManager.url(filepath);
38
+            const url = this._game.assetManager.url(filepath);
39 39
             const soundName = filepath.substring(0, filepath.length - 4);
40 40
             const sound = new BABYLON.Sound(soundName, url);
41 41
 

+ 4
- 4
demos/basketball/src/entities/net.js View File

@@ -29,11 +29,11 @@ export class BasketballNet extends PhysicsEntity
29 29
 {
30 30
     /**
31 31
      * Constructor
32
-     * @param {BasketballDemo} demo
32
+     * @param {BasketballGame} game
33 33
      */
34
-    constructor(demo)
34
+    constructor(game)
35 35
     {
36
-        super(demo);
36
+        super(game);
37 37
 
38 38
         this._physicsRoot = null;
39 39
         this._mesh = null;
@@ -144,7 +144,7 @@ export class BasketballNet extends PhysicsEntity
144 144
     _createMaterial()
145 145
     {
146 146
         const material = new BABYLON.StandardMaterial('BasketballNetMaterial');
147
-        const url = this._demo.assetManager.url('atlas.png');
147
+        const url = this._game.assetManager.url('atlas.png');
148 148
 
149 149
         material.diffuseTexture = new BABYLON.Texture(url);
150 150
         material.diffuseTexture.hasAlpha = true;

+ 4
- 4
demos/basketball/src/entities/score-text.js View File

@@ -26,11 +26,11 @@ export class ScoreText extends Entity
26 26
 {
27 27
      /**
28 28
      * Constructor
29
-     * @param {BasketballDemo} demo
29
+     * @param {BasketballGame} game
30 30
      */
31
-    constructor(demo)
31
+    constructor(game)
32 32
     {
33
-        super(demo);
33
+        super(game);
34 34
         this._score = 0;
35 35
         this._mesh = null;
36 36
         this._initialPosition = new BABYLON.Vector3();
@@ -48,7 +48,7 @@ export class ScoreText extends Entity
48 48
             height: 0.5,
49 49
         });
50 50
 
51
-        const url = this._demo.assetManager.url('atlas.png');
51
+        const url = this._game.assetManager.url('atlas.png');
52 52
         const material = new BABYLON.StandardMaterial('ScoreTextMaterial');
53 53
 
54 54
         material.diffuseTexture = new BABYLON.Texture(url);

+ 9
- 9
demos/basketball/src/entities/scoreboard.js View File

@@ -17,11 +17,11 @@ class ScoreboardDigit extends Entity
17 17
 {
18 18
      /**
19 19
      * Constructor
20
-     * @param {BasketballDemo} demo
20
+     * @param {BasketballGame} game
21 21
      */
22
-    constructor(demo)
22
+    constructor(game)
23 23
     {
24
-        super(demo);
24
+        super(game);
25 25
         this._mesh = null;
26 26
     }
27 27
 
@@ -94,7 +94,7 @@ class ScoreboardDigit extends Entity
94 94
             height: 1.0,
95 95
         });
96 96
 
97
-        const url = this._demo.assetManager.url('atlas.png');
97
+        const url = this._game.assetManager.url('atlas.png');
98 98
         const material = new BABYLON.StandardMaterial('ScoreboardDigitMaterial');
99 99
 
100 100
         material.diffuseTexture = new BABYLON.Texture(url);
@@ -118,11 +118,11 @@ export class Scoreboard extends PhysicsEntity
118 118
 {
119 119
      /**
120 120
      * Constructor
121
-     * @param {BasketballDemo} demo
121
+     * @param {BasketballGame} game
122 122
      */
123
-    constructor(demo)
123
+    constructor(game)
124 124
     {
125
-        super(demo);
125
+        super(game);
126 126
         this._mesh = null;
127 127
         this._units = null;
128 128
         this._tens = null;
@@ -148,11 +148,11 @@ export class Scoreboard extends PhysicsEntity
148 148
         this._mesh.material = new BABYLON.StandardMaterial('ScoreboardMaterial');
149 149
         this._mesh.material.diffuseColor = BABYLON.Color3.FromHexString('#110d7c');
150 150
 
151
-        this._units = await this._demo.spawn(ScoreboardDigit);
151
+        this._units = await this._game.spawn(ScoreboardDigit);
152 152
         this._units.mesh.position = new BABYLON.Vector3(x, y, z);
153 153
         this._units.mesh.parent = this._mesh;
154 154
 
155
-        this._tens = await this._demo.spawn(ScoreboardDigit);
155
+        this._tens = await this._game.spawn(ScoreboardDigit);
156 156
         this._tens.mesh.position = new BABYLON.Vector3(-x, y, z);
157 157
         this._tens.mesh.parent = this._mesh;
158 158
 

Loading…
Cancel
Save