@@ -16,7 +16,7 @@ import rollImg from '../../assets/character/roll/roll.png';
16
16
import jumpImg from '../../assets/character/jump/jump.png' ;
17
17
import attackImg from '../../assets/character/attack/attack.png' ;
18
18
import attackTool from '../../assets/character/tool/attack.png' ;
19
- import { stringObjectType } from '../../types/types' ;
19
+ import { gameInitType , stringObjectType , userType } from '../../types/types' ;
20
20
21
21
const characterImg : stringObjectType = {
22
22
wait : waitImg ,
@@ -32,7 +32,7 @@ export default class Game extends Phaser.Scene {
32
32
otherPlayer : { [ key : string ] : OtherPlayer } ;
33
33
socket ?: Socket ;
34
34
autoPlay : boolean ;
35
- townLayer : any ;
35
+ townLayer ?: Phaser . Tilemaps . TilemapLayer ;
36
36
37
37
constructor ( config : Phaser . Types . Core . GameConfig ) {
38
38
super ( config ) ;
@@ -44,7 +44,7 @@ export default class Game extends Phaser.Scene {
44
44
}
45
45
46
46
init ( ) {
47
- emitter . on ( 'init' , ( data : any ) => {
47
+ emitter . on ( 'init' , ( data : gameInitType ) => {
48
48
this . socket = data . socket . connect ( ) ;
49
49
50
50
this . myPlayer = new MyPlayer (
@@ -63,7 +63,8 @@ export default class Game extends Phaser.Scene {
63
63
// collidingTileColor: new Phaser.Display.Color(243, 234, 48, 255),
64
64
// });
65
65
66
- this . physics . add . collider ( this . myPlayer , this . townLayer ) ;
66
+ if ( this . townLayer )
67
+ this . physics . add . collider ( this . myPlayer , this . townLayer ) ;
67
68
68
69
this . socket ?. on ( 'connect' , ( ) => {
69
70
this . socketInit ( ) ;
@@ -85,6 +86,8 @@ export default class Game extends Phaser.Scene {
85
86
if ( this . myPlayer ) this . myPlayer . isCanMove = ! checkInput ;
86
87
this . input . keyboard . manager . enabled = ! checkInput ;
87
88
} ;
89
+
90
+ emitter . emit ( 'game-start' ) ;
88
91
}
89
92
90
93
preload ( ) {
@@ -211,10 +214,10 @@ export default class Game extends Phaser.Scene {
211
214
socketInit ( ) {
212
215
if ( ! this . socket ) return ;
213
216
214
- this . socket . on ( 'userInitiated' , ( data : any ) => {
217
+ this . socket . on ( 'userInitiated' , ( data : userType [ ] ) => {
215
218
if ( ! Array . isArray ( data ) ) data = [ data ] ;
216
219
217
- data . forEach ( ( user : any ) => {
220
+ data . forEach ( ( user : userType ) => {
218
221
const id = user . id . toString ( ) . trim ( ) ;
219
222
if ( this . myPlayer ?. id === id ) return ;
220
223
if ( this . otherPlayer [ id ] ) return ;
@@ -223,26 +226,26 @@ export default class Game extends Phaser.Scene {
223
226
} ) ;
224
227
} ) ;
225
228
226
- this . socket . on ( 'userCreated' , ( user : any ) => {
229
+ this . socket . on ( 'userCreated' , ( user : userType ) => {
227
230
const id = user . id . toString ( ) . trim ( ) ;
228
231
this . otherPlayer [ id ] = new OtherPlayer ( this , user ) ;
229
232
} ) ;
230
233
231
- this . socket . on ( 'move' , ( data : any ) => {
234
+ this . socket . on ( 'move' , ( data : userType ) => {
232
235
const id = data . id . toString ( ) . trim ( ) ;
233
236
234
237
if ( ! this . otherPlayer [ id ] ) return ;
235
238
const { state, x, y, direction } = data ;
236
239
this . otherPlayer [ id ] . update ( state , x , y , direction ) ;
237
240
} ) ;
238
241
239
- this . socket . on ( 'userLeaved' , ( data : any ) => {
242
+ this . socket . on ( 'userLeaved' , ( data : userType ) => {
240
243
const id = data . id . toString ( ) . trim ( ) ;
241
244
this . otherPlayer [ id ] . delete ( ) ;
242
245
delete this . otherPlayer [ id ] ;
243
246
} ) ;
244
247
245
- this . socket . on ( 'userDataChanged' , ( data : any ) => {
248
+ this . socket . on ( 'userDataChanged' , ( data : userType ) => {
246
249
const { id, nickname, characterName } = data ;
247
250
this . otherPlayer [ id ] . updateNickname ( nickname ) ;
248
251
this . otherPlayer [ id ] . updateHair ( characterName ) ;
0 commit comments