소스 검색

Update Basketball game

customisations
alemart 9 달 전
부모
커밋
1c452cb86d

+ 1
- 1
demos/basketball/src/core/game.js 파일 보기

228
             this.spawn(TutorialOverlay),
228
             this.spawn(TutorialOverlay),
229
             this.spawn(GameOverOverlay),
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 파일 보기

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

+ 4
- 4
demos/basketball/src/entities/ball.js 파일 보기

50
 {
50
 {
51
     /**
51
     /**
52
      * Constructor
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
         this._state = 'ready';
59
         this._state = 'ready';
60
         this._runState = {
60
         this._runState = {
77
      */
77
      */
78
     async init()
78
     async init()
79
     {
79
     {
80
-        const file = this._demo.assetManager.file('ball.glb');
80
+        const file = this._game.assetManager.file('ball.glb');
81
         const gltf = await BABYLON.SceneLoader.ImportMeshAsync('', '', file);
81
         const gltf = await BABYLON.SceneLoader.ImportMeshAsync('', '', file);
82
         const mesh = this._createPhysicsRoot(gltf.meshes[0]); // gltf.meshes[0] is __root__
82
         const mesh = this._createPhysicsRoot(gltf.meshes[0]); // gltf.meshes[0] is __root__
83
 
83
 

+ 8
- 8
demos/basketball/src/entities/entity.js 파일 보기

14
 {
14
 {
15
     /**
15
     /**
16
      * Constructor
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
      */
62
      */
63
     _broadcast(event)
63
     _broadcast(event)
64
     {
64
     {
65
-        this._demo.broadcast(event);
65
+        this._game.broadcast(event);
66
     }
66
     }
67
 
67
 
68
     /**
68
     /**
71
      */
71
      */
72
     get ar()
72
     get ar()
73
     {
73
     {
74
-        return this._demo.ar;
74
+        return this._game.ar;
75
     }
75
     }
76
 }
76
 }
77
 
77
 
83
 {
83
 {
84
     /**
84
     /**
85
      * Constructor
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
         this._physicsAnchor = null;
91
         this._physicsAnchor = null;
92
     }
92
     }
93
 
93
 

+ 5
- 5
demos/basketball/src/entities/game-controller.js 파일 보기

9
 
9
 
10
 import { Entity } from './entity.js';
10
 import { Entity } from './entity.js';
11
 import { GameEvent } from '../core/events.js';
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
  * The Game Controller manages the state of the game
15
  * The Game Controller manages the state of the game
18
 {
18
 {
19
     /**
19
     /**
20
      * Constructor
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
         this._ballsLeft = NUMBER_OF_BALLS;
27
         this._ballsLeft = NUMBER_OF_BALLS;
28
         this._score = 0;
28
         this._score = 0;
81
      */
81
      */
82
     _computeRank(score)
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
         for(const [rank, minScore] of entries) {
86
         for(const [rank, minScore] of entries) {
87
             if(score >= minScore)
87
             if(score >= minScore)

+ 4
- 4
demos/basketball/src/entities/goal.js 파일 보기

20
 {
20
 {
21
     /**
21
     /**
22
      * Constructor
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
         this._physicsRoot = null;
28
         this._physicsRoot = null;
29
     }
29
     }
30
 
30
 
34
      */
34
      */
35
     async init()
35
     async init()
36
     {
36
     {
37
-        const file = this._demo.assetManager.file('goal.glb');
37
+        const file = this._game.assetManager.file('goal.glb');
38
         const gltf = await BABYLON.SceneLoader.ImportMeshAsync('', '', file);
38
         const gltf = await BABYLON.SceneLoader.ImportMeshAsync('', '', file);
39
         this._physicsRoot = this._createPhysicsRoot(gltf.meshes);
39
         this._physicsRoot = this._createPhysicsRoot(gltf.meshes);
40
         this._physicsRoot.position.y = Y_OFFSET;
40
         this._physicsRoot.position.y = Y_OFFSET;

+ 3
- 3
demos/basketball/src/entities/gravity.js 파일 보기

19
 {
19
 {
20
     /**
20
     /**
21
      * Constructor
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
         this._gravity = new BABYLON.Vector3();
27
         this._gravity = new BABYLON.Vector3();
28
         this._isTracking = false;
28
         this._isTracking = false;
29
     }
29
     }

+ 3
- 3
demos/basketball/src/entities/gui/ball-counter.js 파일 보기

22
      */
22
      */
23
     _createControl()
23
     _createControl()
24
     {
24
     {
25
-        const url = this._demo.assetManager.url('atlas.png');
25
+        const url = this._game.assetManager.url('atlas.png');
26
         const icon = new BABYLON.GUI.Image('ballIcon', url);
26
         const icon = new BABYLON.GUI.Image('ballIcon', url);
27
 
27
 
28
         icon.sourceLeft = 896;
28
         icon.sourceLeft = 896;
103
         const icons = [];
103
         const icons = [];
104
 
104
 
105
         for(let i = 0; i < NUMBER_OF_BALLS; i++) {
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
             icons.push(icon);
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 파일 보기

17
 {
17
 {
18
     /**
18
     /**
19
      * Constructor
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
         this._messages = {
26
         this._messages = {
27
             'S' : 'YOU ARE A\nLEGEND!!!!!',
27
             'S' : 'YOU ARE A\nLEGEND!!!!!',

+ 3
- 3
demos/basketball/src/entities/gui/gui-control.js 파일 보기

17
 {
17
 {
18
     /**
18
     /**
19
      * Constructor
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
         this._parent = demo.gui;
25
         this._parent = demo.gui;
26
         this._control = null;
26
         this._control = null;
27
     }
27
     }

+ 1
- 1
demos/basketball/src/entities/gui/mute-button.js 파일 보기

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

+ 4
- 4
demos/basketball/src/entities/gui/tutorial-overlay.js 파일 보기

19
 {
19
 {
20
     /**
20
     /**
21
      * Constructor
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
         this._timer = 0;
27
         this._timer = 0;
28
         this._enabled = true;
28
         this._enabled = true;
29
     }
29
     }
34
      */
34
      */
35
     _createControl()
35
     _createControl()
36
     {
36
     {
37
-        const url = this._demo.assetManager.url('atlas.png');
37
+        const url = this._game.assetManager.url('atlas.png');
38
         const container = new BABYLON.GUI.Container();
38
         const container = new BABYLON.GUI.Container();
39
         const text = new BABYLON.GUI.TextBlock();
39
         const text = new BABYLON.GUI.TextBlock();
40
         const hand = new BABYLON.GUI.Image('hand', url);
40
         const hand = new BABYLON.GUI.Image('hand', url);

+ 4
- 4
demos/basketball/src/entities/jukebox.js 파일 보기

18
 {
18
 {
19
      /**
19
      /**
20
      * Constructor
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
         this._sound = new Map();
26
         this._sound = new Map();
27
     }
27
     }
28
 
28
 
35
         const soundFiles = ASSET_LIST.filter(asset => asset.endsWith('.wav'));
35
         const soundFiles = ASSET_LIST.filter(asset => asset.endsWith('.wav'));
36
 
36
 
37
         for(const filepath of soundFiles) {
37
         for(const filepath of soundFiles) {
38
-            const url = this._demo.assetManager.url(filepath);
38
+            const url = this._game.assetManager.url(filepath);
39
             const soundName = filepath.substring(0, filepath.length - 4);
39
             const soundName = filepath.substring(0, filepath.length - 4);
40
             const sound = new BABYLON.Sound(soundName, url);
40
             const sound = new BABYLON.Sound(soundName, url);
41
 
41
 

+ 4
- 4
demos/basketball/src/entities/net.js 파일 보기

29
 {
29
 {
30
     /**
30
     /**
31
      * Constructor
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
         this._physicsRoot = null;
38
         this._physicsRoot = null;
39
         this._mesh = null;
39
         this._mesh = null;
144
     _createMaterial()
144
     _createMaterial()
145
     {
145
     {
146
         const material = new BABYLON.StandardMaterial('BasketballNetMaterial');
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
         material.diffuseTexture = new BABYLON.Texture(url);
149
         material.diffuseTexture = new BABYLON.Texture(url);
150
         material.diffuseTexture.hasAlpha = true;
150
         material.diffuseTexture.hasAlpha = true;

+ 4
- 4
demos/basketball/src/entities/score-text.js 파일 보기

26
 {
26
 {
27
      /**
27
      /**
28
      * Constructor
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
         this._score = 0;
34
         this._score = 0;
35
         this._mesh = null;
35
         this._mesh = null;
36
         this._initialPosition = new BABYLON.Vector3();
36
         this._initialPosition = new BABYLON.Vector3();
48
             height: 0.5,
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
         const material = new BABYLON.StandardMaterial('ScoreTextMaterial');
52
         const material = new BABYLON.StandardMaterial('ScoreTextMaterial');
53
 
53
 
54
         material.diffuseTexture = new BABYLON.Texture(url);
54
         material.diffuseTexture = new BABYLON.Texture(url);

+ 9
- 9
demos/basketball/src/entities/scoreboard.js 파일 보기

17
 {
17
 {
18
      /**
18
      /**
19
      * Constructor
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
         this._mesh = null;
25
         this._mesh = null;
26
     }
26
     }
27
 
27
 
94
             height: 1.0,
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
         const material = new BABYLON.StandardMaterial('ScoreboardDigitMaterial');
98
         const material = new BABYLON.StandardMaterial('ScoreboardDigitMaterial');
99
 
99
 
100
         material.diffuseTexture = new BABYLON.Texture(url);
100
         material.diffuseTexture = new BABYLON.Texture(url);
118
 {
118
 {
119
      /**
119
      /**
120
      * Constructor
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
         this._mesh = null;
126
         this._mesh = null;
127
         this._units = null;
127
         this._units = null;
128
         this._tens = null;
128
         this._tens = null;
148
         this._mesh.material = new BABYLON.StandardMaterial('ScoreboardMaterial');
148
         this._mesh.material = new BABYLON.StandardMaterial('ScoreboardMaterial');
149
         this._mesh.material.diffuseColor = BABYLON.Color3.FromHexString('#110d7c');
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
         this._units.mesh.position = new BABYLON.Vector3(x, y, z);
152
         this._units.mesh.position = new BABYLON.Vector3(x, y, z);
153
         this._units.mesh.parent = this._mesh;
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
         this._tens.mesh.position = new BABYLON.Vector3(-x, y, z);
156
         this._tens.mesh.position = new BABYLON.Vector3(-x, y, z);
157
         this._tens.mesh.parent = this._mesh;
157
         this._tens.mesh.parent = this._mesh;
158
 
158
 

Loading…
취소
저장