blob: ec4429574ae127ecbc21bc81aea91ff286bbbfdd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
import Phaser from 'phaser';
import { AkkamonWorldScene } from '../../scenes/AkkamonWorldScene';
import type { Direction } from '../Direction';
type PlayerSpriteConfig = {
scene: Phaser.Scene,
tilePos: Phaser.Math.Vector2,
texture: Phaser.Textures.Texture | string,
frame?: string,
}
interface AkkamonPlayerSprite extends Phaser.GameObjects.Sprite {
}
export class PlayerSprite extends Phaser.GameObjects.Sprite implements AkkamonPlayerSprite {
tilePos: Phaser.Math.Vector2;
constructor(config: PlayerSpriteConfig) {
const offsetX = AkkamonWorldScene.TILE_SIZE / 2;
const offsetY = AkkamonWorldScene.TILE_SIZE;
super(config.scene,
config.tilePos.x * AkkamonWorldScene.TILE_SIZE + offsetX,
config.tilePos.y * AkkamonWorldScene.TILE_SIZE + offsetY,
config.texture,
config.frame);
this.tilePos = new Phaser.Math.Vector2(config.tilePos.x, config.tilePos.y);
this.setOrigin(0.5, 1);
// add to scene!
config.scene.add.existing(this);
}
getPosition(): Phaser.Math.Vector2 {
return this.getBottomCenter();
}
newPosition(position: Phaser.Math.Vector2): void {
super.setPosition(position.x, position.y);
}
stopAnimation(direction: Direction) {
const animationManager = this.anims.animationManager;
const standingFrame = animationManager.get(direction).frames[1].frame.name;
this.anims.stop();
this.setFrame(standingFrame);
}
startAnimation(direction: Direction) {
this.anims.play(direction);
}
getTilePos(): Phaser.Math.Vector2 {
return this.tilePos.clone();
}
setTilePos(tilePosition: Phaser.Math.Vector2): void {
this.tilePos = tilePosition.clone();
}
getScene(): string {
return this.scene.scene.key;
}
}
|