pac-man-phaser 1.0.10 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +29 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -188,7 +188,7 @@ var Character = class extends Phaser.Physics.Arcade.Sprite {
|
|
|
188
188
|
};
|
|
189
189
|
|
|
190
190
|
// src/game/sprites/pac-man.ts
|
|
191
|
-
var Pacman = class extends Character {
|
|
191
|
+
var Pacman = class _Pacman extends Character {
|
|
192
192
|
nextDir = -1;
|
|
193
193
|
eatCoords = null;
|
|
194
194
|
speed = PAC_MAN_SPEED;
|
|
@@ -206,6 +206,7 @@ var Pacman = class extends Character {
|
|
|
206
206
|
if (scene.input.keyboard) {
|
|
207
207
|
this.setEventListeners(scene.input.keyboard);
|
|
208
208
|
}
|
|
209
|
+
this.setTouchListeners(scene.input);
|
|
209
210
|
}
|
|
210
211
|
handleDeath() {
|
|
211
212
|
this.setVelocity(0, 0);
|
|
@@ -247,6 +248,33 @@ var Pacman = class extends Character {
|
|
|
247
248
|
this.anims.stop();
|
|
248
249
|
}
|
|
249
250
|
}
|
|
251
|
+
static MIN_SWIPE_DISTANCE = 20;
|
|
252
|
+
setTouchListeners(input) {
|
|
253
|
+
let startX = 0;
|
|
254
|
+
let startY = 0;
|
|
255
|
+
const onPointerDown = (pointer) => {
|
|
256
|
+
startX = pointer.x;
|
|
257
|
+
startY = pointer.y;
|
|
258
|
+
};
|
|
259
|
+
const onPointerUp = (pointer) => {
|
|
260
|
+
const dx = pointer.x - startX;
|
|
261
|
+
const dy = pointer.y - startY;
|
|
262
|
+
if (Math.abs(dx) < _Pacman.MIN_SWIPE_DISTANCE && Math.abs(dy) < _Pacman.MIN_SWIPE_DISTANCE) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
if (Math.abs(dx) > Math.abs(dy)) {
|
|
266
|
+
this.nextDir = dx > 0 ? directions.RIGHT : directions.LEFT;
|
|
267
|
+
} else {
|
|
268
|
+
this.nextDir = dy > 0 ? directions.DOWN : directions.UP;
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
input.on("pointerdown", onPointerDown);
|
|
272
|
+
input.on("pointerup", onPointerUp);
|
|
273
|
+
this.once("destroy", () => {
|
|
274
|
+
input.off("pointerdown", onPointerDown);
|
|
275
|
+
input.off("pointerup", onPointerUp);
|
|
276
|
+
});
|
|
277
|
+
}
|
|
250
278
|
setEventListeners(input) {
|
|
251
279
|
const left = () => {
|
|
252
280
|
this.nextDir = directions.LEFT;
|