Skip to content

Commit bd2fa06

Browse files
committed
fix walking dexter
1 parent dfb5e05 commit bd2fa06

File tree

1 file changed

+78
-64
lines changed

1 file changed

+78
-64
lines changed

port/src/player.ts

+78-64
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ export class Player implements MovableGameObject {
6565

6666
this.posX = 0;
6767
this.posY = 0;
68-
6968
}
7069

7170
public init() {
@@ -74,7 +73,7 @@ export class Player implements MovableGameObject {
7473

7574
if (this.game.engineType === EngineType.Scooby) {
7675
this.scooby.texture = getMemberTexture("scooby.down.1")!;
77-
this.scooby.anchor.set(0.5)
76+
this.scooby.anchor.set(0.5);
7877
}
7978
}
8079

@@ -90,7 +89,6 @@ export class Player implements MovableGameObject {
9089
this.posX = x;
9190
this.posY = y;
9291
this.sprite.position.set(this.posX, this.posY);
93-
9492
}
9593

9694
public initMove(fromPos: Pos, toPos: Pos) {
@@ -147,34 +145,41 @@ export class Player implements MovableGameObject {
147145
this.nextPos = { x, y };
148146

149147
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();
153151
}
154152
}
155153

156154
private isPerpendicular(dir: PlayerDirection) {
157155
// console.log("scoob: ", this.scoobyDirection, "shag: ", dir)
158156
switch (this.scoobyDirection) {
159157
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+
}
164161
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;
170167
}
171-
172168
}
173169

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";
178183

179184
/*
180185
the Y offsets used to be +/-17 instead of 16,
@@ -193,23 +198,30 @@ export class Player implements MovableGameObject {
193198
pLeft: { x: 48, y: 16 },
194199
pTop: { x: 0, y: 0 },
195200
pRight: { x: -48, y: 16 },
196-
pBottom: { x: 0, y: 0 }
201+
pBottom: { x: 0, y: 0 },
197202
};
198203

199204
if (!isPerpendicular) {
200205
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;
205214
}
206-
}
207-
else {
215+
} else {
208216
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;
213225
}
214226
}
215227
}
@@ -221,33 +233,32 @@ export class Player implements MovableGameObject {
221233
}
222234

223235
private scoobyGetDelta(shaggyLoc: Pos, thisOffset: Pos): Pos {
224-
const thisDelta: Pos = { x: 0, y: 0 }
236+
const thisDelta: Pos = { x: 0, y: 0 };
225237
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 };
228243

229244
// console.log("getDelta thisLoc", thisLoc, "myLoc", myLoc)
230245

231246
if (myLoc.x < thisLoc.x) {
232247
thisDelta.x += thisUnit;
233-
}
234-
else {
248+
} else {
235249
if (myLoc.x > thisLoc.x) {
236250
thisDelta.x -= thisUnit;
237-
}
238-
else {
251+
} else {
239252
thisDelta.x = 0;
240253
}
241254
}
242255

243256
if (myLoc.y > thisLoc.y) {
244257
thisDelta.y -= thisUnit;
245-
}
246-
else {
258+
} else {
247259
if (myLoc.y < thisLoc.y) {
248260
thisDelta.y += thisUnit;
249-
}
250-
else {
261+
} else {
251262
thisDelta.y = 0;
252263
}
253264
}
@@ -256,19 +267,14 @@ export class Player implements MovableGameObject {
256267
}
257268

258269
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;
267274
return null;
268275
}
269276

270277
public updateScooby() {
271-
272278
const thisLoc: Pos = this.nextPos;
273279
const thisDir = this.characterDirection;
274280
const thisFrame = this.frameOfAnimation;
@@ -286,18 +292,23 @@ export class Player implements MovableGameObject {
286292
// console.log("thisLoc: ", thisLoc)
287293
const thisDelta = this.scoobyGetDelta(thisLoc, thisOffset);
288294
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+
};
290299
// 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+
);
292304
const newDir = this.scoobyGetDir(thisDelta);
293305
if (newDir !== null) {
294306
this.scoobyDirection = newDir;
295307
this.scooby.texture = this.getScoobyTexture(newDir, thisFrame)!;
296308
this.scooby.position.x += thisDelta.x;
297309
this.scooby.position.y += thisDelta.y;
298310
}
299-
}
300-
else {
311+
} else {
301312
// sprite(me.spriteNum).locZ = me.spriteNum
302313
// me.pDelta = thisSpeed
303314
}
@@ -330,36 +341,39 @@ export class Player implements MovableGameObject {
330341

331342
// move to bottom half of 64 height sprite
332343
result.y += 16;
333-
};
344+
}
334345

335346
return result;
336347
}
337348

338349
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+
}
340358
}
341359

342360
private getScoobyTexture(thisDir: PlayerDirection, thisFrame: number) {
343361
const textureString = `scooby.${thisDir}.${thisFrame}`;
344362
// console.log(textureString);
345363
return getMemberTexture(textureString);
346-
347364
}
348365

349366
private getTextureString() {
350367
const normal = [
351368
this.state,
352-
this.horizontalDirection,
369+
this.game.engineType === EngineType.CCSR
370+
? this.horizontalDirection
371+
: this.characterDirection,
353372
this.frameOfAnimation,
354373
];
355374
const boat = [this.state, this.characterDirection];
356375
const arr = this.state == PlayerState.NORMAL ? normal : boat;
357376

358-
if (this.game.engineType === EngineType.Scooby) {
359-
const shaggyState = [this.state, this.characterDirection, this.frameOfAnimation];
360-
return shaggyState.join(".") + ".png";
361-
}
362-
363377
return arr.join(".") + ".png";
364378
}
365379
}

0 commit comments

Comments
 (0)