@@ -65,7 +65,6 @@ export class Player implements MovableGameObject {
65
65
66
66
this . posX = 0 ;
67
67
this . posY = 0 ;
68
-
69
68
}
70
69
71
70
public init ( ) {
@@ -74,7 +73,7 @@ export class Player implements MovableGameObject {
74
73
75
74
if ( this . game . engineType === EngineType . Scooby ) {
76
75
this . scooby . texture = getMemberTexture ( "scooby.down.1" ) ! ;
77
- this . scooby . anchor . set ( 0.5 )
76
+ this . scooby . anchor . set ( 0.5 ) ;
78
77
}
79
78
}
80
79
@@ -90,7 +89,6 @@ export class Player implements MovableGameObject {
90
89
this . posX = x ;
91
90
this . posY = y ;
92
91
this . sprite . position . set ( this . posX , this . posY ) ;
93
-
94
92
}
95
93
96
94
public initMove ( fromPos : Pos , toPos : Pos ) {
@@ -147,34 +145,41 @@ export class Player implements MovableGameObject {
147
145
this . nextPos = { x, y } ;
148
146
149
147
if ( this . game . engineType === EngineType . Scooby ) {
150
- this . scoobyDirection = PlayerDirection . RIGHT
151
- this . scooby . position . set ( this . posX - 32 , this . posY )
152
- this . updateScooby ( )
148
+ this . scoobyDirection = PlayerDirection . RIGHT ;
149
+ this . scooby . position . set ( this . posX - 32 , this . posY ) ;
150
+ this . updateScooby ( ) ;
153
151
}
154
152
}
155
153
156
154
private isPerpendicular ( dir : PlayerDirection ) {
157
155
// console.log("scoob: ", this.scoobyDirection, "shag: ", dir)
158
156
switch ( this . scoobyDirection ) {
159
157
case PlayerDirection . UP :
160
- case PlayerDirection . DOWN :
161
- {
162
- return [ PlayerDirection . LEFT , PlayerDirection . RIGHT ] . includes ( dir ) ;
163
- }
158
+ case PlayerDirection . DOWN : {
159
+ return [ PlayerDirection . LEFT , PlayerDirection . RIGHT ] . includes ( dir ) ;
160
+ }
164
161
case PlayerDirection . LEFT :
165
- case PlayerDirection . RIGHT :
166
- {
167
- return [ PlayerDirection . UP , PlayerDirection . DOWN ] . includes ( dir ) ;
168
- }
169
- default : return false ;
162
+ case PlayerDirection . RIGHT : {
163
+ return [ PlayerDirection . UP , PlayerDirection . DOWN ] . includes ( dir ) ;
164
+ }
165
+ default :
166
+ return false ;
170
167
}
171
-
172
168
}
173
169
174
- private getScoobyOffset ( thisDir : PlayerDirection , isPerpendicular : boolean ) : Pos {
175
-
176
- type scoobyOffset = "left" | "top" | "right" | "bottom" |
177
- "pLeft" | "pTop" | "pRight" | "pBottom" ;
170
+ private getScoobyOffset (
171
+ thisDir : PlayerDirection ,
172
+ isPerpendicular : boolean
173
+ ) : Pos {
174
+ type scoobyOffset =
175
+ | "left"
176
+ | "top"
177
+ | "right"
178
+ | "bottom"
179
+ | "pLeft"
180
+ | "pTop"
181
+ | "pRight"
182
+ | "pBottom" ;
178
183
179
184
/*
180
185
the Y offsets used to be +/-17 instead of 16,
@@ -193,23 +198,30 @@ export class Player implements MovableGameObject {
193
198
pLeft : { x : 48 , y : 16 } ,
194
199
pTop : { x : 0 , y : 0 } ,
195
200
pRight : { x : - 48 , y : 16 } ,
196
- pBottom : { x : 0 , y : 0 }
201
+ pBottom : { x : 0 , y : 0 } ,
197
202
} ;
198
203
199
204
if ( ! isPerpendicular ) {
200
205
switch ( thisDir ) {
201
- case PlayerDirection . LEFT : return scoobyOffsetList . left ;
202
- case PlayerDirection . UP : return scoobyOffsetList . top ;
203
- case PlayerDirection . RIGHT : return scoobyOffsetList . right ;
204
- case PlayerDirection . DOWN : return scoobyOffsetList . bottom ;
206
+ case PlayerDirection . LEFT :
207
+ return scoobyOffsetList . left ;
208
+ case PlayerDirection . UP :
209
+ return scoobyOffsetList . top ;
210
+ case PlayerDirection . RIGHT :
211
+ return scoobyOffsetList . right ;
212
+ case PlayerDirection . DOWN :
213
+ return scoobyOffsetList . bottom ;
205
214
}
206
- }
207
- else {
215
+ } else {
208
216
switch ( thisDir ) {
209
- case PlayerDirection . LEFT : return scoobyOffsetList . pLeft ;
210
- case PlayerDirection . UP : return scoobyOffsetList . pTop ;
211
- case PlayerDirection . RIGHT : return scoobyOffsetList . pRight ;
212
- case PlayerDirection . DOWN : return scoobyOffsetList . pBottom ;
217
+ case PlayerDirection . LEFT :
218
+ return scoobyOffsetList . pLeft ;
219
+ case PlayerDirection . UP :
220
+ return scoobyOffsetList . pTop ;
221
+ case PlayerDirection . RIGHT :
222
+ return scoobyOffsetList . pRight ;
223
+ case PlayerDirection . DOWN :
224
+ return scoobyOffsetList . pBottom ;
213
225
}
214
226
}
215
227
}
@@ -221,33 +233,32 @@ export class Player implements MovableGameObject {
221
233
}
222
234
223
235
private scoobyGetDelta ( shaggyLoc : Pos , thisOffset : Pos ) : Pos {
224
- const thisDelta : Pos = { x : 0 , y : 0 }
236
+ const thisDelta : Pos = { x : 0 , y : 0 } ;
225
237
const thisUnit = 8 ;
226
- const thisLoc : Pos = { x : shaggyLoc . x + thisOffset . x , y : shaggyLoc . y + thisOffset . y } ;
227
- const myLoc : Pos = { x : this . scooby . position . x , y : this . scooby . position . y }
238
+ const thisLoc : Pos = {
239
+ x : shaggyLoc . x + thisOffset . x ,
240
+ y : shaggyLoc . y + thisOffset . y ,
241
+ } ;
242
+ const myLoc : Pos = { x : this . scooby . position . x , y : this . scooby . position . y } ;
228
243
229
244
// console.log("getDelta thisLoc", thisLoc, "myLoc", myLoc)
230
245
231
246
if ( myLoc . x < thisLoc . x ) {
232
247
thisDelta . x += thisUnit ;
233
- }
234
- else {
248
+ } else {
235
249
if ( myLoc . x > thisLoc . x ) {
236
250
thisDelta . x -= thisUnit ;
237
- }
238
- else {
251
+ } else {
239
252
thisDelta . x = 0 ;
240
253
}
241
254
}
242
255
243
256
if ( myLoc . y > thisLoc . y ) {
244
257
thisDelta . y -= thisUnit ;
245
- }
246
- else {
258
+ } else {
247
259
if ( myLoc . y < thisLoc . y ) {
248
260
thisDelta . y += thisUnit ;
249
- }
250
- else {
261
+ } else {
251
262
thisDelta . y = 0 ;
252
263
}
253
264
}
@@ -256,19 +267,14 @@ export class Player implements MovableGameObject {
256
267
}
257
268
258
269
private scoobyGetDir ( delta : Pos ) : PlayerDirection | null {
259
- if ( delta . y > 0 )
260
- return PlayerDirection . DOWN
261
- if ( delta . y < 0 )
262
- return PlayerDirection . UP
263
- if ( delta . x > 0 )
264
- return PlayerDirection . RIGHT
265
- if ( delta . x < 0 )
266
- return PlayerDirection . LEFT
270
+ if ( delta . y > 0 ) return PlayerDirection . DOWN ;
271
+ if ( delta . y < 0 ) return PlayerDirection . UP ;
272
+ if ( delta . x > 0 ) return PlayerDirection . RIGHT ;
273
+ if ( delta . x < 0 ) return PlayerDirection . LEFT ;
267
274
return null ;
268
275
}
269
276
270
277
public updateScooby ( ) {
271
-
272
278
const thisLoc : Pos = this . nextPos ;
273
279
const thisDir = this . characterDirection ;
274
280
const thisFrame = this . frameOfAnimation ;
@@ -286,18 +292,23 @@ export class Player implements MovableGameObject {
286
292
// console.log("thisLoc: ", thisLoc)
287
293
const thisDelta = this . scoobyGetDelta ( thisLoc , thisOffset ) ;
288
294
const scooby = this . scooby . position ;
289
- const newLoc : Pos = { x : scooby . x + thisDelta . x , y : this . scooby . y + thisDelta . y } ;
295
+ const newLoc : Pos = {
296
+ x : scooby . x + thisDelta . x ,
297
+ y : this . scooby . y + thisDelta . y ,
298
+ } ;
290
299
// console.log("delta:", thisDelta)
291
- thisRect = this . getCollisionRectAtPoint ( newLoc . x + thisDelta . x , newLoc . y + thisDelta . y ) ;
300
+ thisRect = this . getCollisionRectAtPoint (
301
+ newLoc . x + thisDelta . x ,
302
+ newLoc . y + thisDelta . y
303
+ ) ;
292
304
const newDir = this . scoobyGetDir ( thisDelta ) ;
293
305
if ( newDir !== null ) {
294
306
this . scoobyDirection = newDir ;
295
307
this . scooby . texture = this . getScoobyTexture ( newDir , thisFrame ) ! ;
296
308
this . scooby . position . x += thisDelta . x ;
297
309
this . scooby . position . y += thisDelta . y ;
298
310
}
299
- }
300
- else {
311
+ } else {
301
312
// sprite(me.spriteNum).locZ = me.spriteNum
302
313
// me.pDelta = thisSpeed
303
314
}
@@ -330,36 +341,39 @@ export class Player implements MovableGameObject {
330
341
331
342
// move to bottom half of 64 height sprite
332
343
result . y += 16 ;
333
- } ;
344
+ }
334
345
335
346
return result ;
336
347
}
337
348
338
349
public getAnimationFrameCount ( ) : number {
339
- return ( this . game . engineType === EngineType . Scooby ) ? 3 : 2
350
+ switch ( this . game . engineType ) {
351
+ case EngineType . Scooby :
352
+ return 3 ;
353
+ case EngineType . CCSR :
354
+ return 2 ;
355
+ case EngineType . Dexter :
356
+ return 4 ;
357
+ }
340
358
}
341
359
342
360
private getScoobyTexture ( thisDir : PlayerDirection , thisFrame : number ) {
343
361
const textureString = `scooby.${ thisDir } .${ thisFrame } ` ;
344
362
// console.log(textureString);
345
363
return getMemberTexture ( textureString ) ;
346
-
347
364
}
348
365
349
366
private getTextureString ( ) {
350
367
const normal = [
351
368
this . state ,
352
- this . horizontalDirection ,
369
+ this . game . engineType === EngineType . CCSR
370
+ ? this . horizontalDirection
371
+ : this . characterDirection ,
353
372
this . frameOfAnimation ,
354
373
] ;
355
374
const boat = [ this . state , this . characterDirection ] ;
356
375
const arr = this . state == PlayerState . NORMAL ? normal : boat ;
357
376
358
- if ( this . game . engineType === EngineType . Scooby ) {
359
- const shaggyState = [ this . state , this . characterDirection , this . frameOfAnimation ] ;
360
- return shaggyState . join ( "." ) + ".png" ;
361
- }
362
-
363
377
return arr . join ( "." ) + ".png" ;
364
378
}
365
379
}
0 commit comments