Merge branch 'interaction' into kharhamel-interaction
# Conflicts: # front/src/Phaser/Game/CameraManager.ts # front/src/Phaser/Game/GameScene.ts # front/src/Phaser/Game/MapManager.ts # front/src/Phaser/Player/Player.ts
This commit is contained in:
commit
01dbff7aee
13 changed files with 367 additions and 89 deletions
45
front/src/Phaser/Entity/PlayableCaracter.ts
Normal file
45
front/src/Phaser/Entity/PlayableCaracter.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
import {getPlayerAnimations, playAnimation, PlayerAnimationNames} from "../Player/Animation";
|
||||
import {ActiveEventList, UserInputEvent} from "../UserInput/UserInputManager";
|
||||
import {SpeechBubble} from "./SpeechBubble";
|
||||
|
||||
export class PlayableCaracter extends Phaser.Physics.Arcade.Sprite {
|
||||
private bubble: SpeechBubble;
|
||||
|
||||
constructor(scene: Phaser.Scene, x: number, y: number, texture: string, frame?: string | number) {
|
||||
super(scene, x, y, texture, frame);
|
||||
|
||||
this.scene.sys.updateList.add(this);
|
||||
this.scene.sys.displayList.add(this);
|
||||
this.setScale(2);
|
||||
this.scene.physics.world.enableBody(this);
|
||||
this.setImmovable(true);
|
||||
this.setCollideWorldBounds(true);
|
||||
this.setSize(32, 32); //edit the hitbox to better match the caracter model
|
||||
}
|
||||
|
||||
move(x: number, y: number){
|
||||
|
||||
this.setVelocity(x, y);
|
||||
|
||||
//todo improve animations to better account for diagonal movement
|
||||
if (this.body.velocity.x > 0) { //moving right
|
||||
this.play(PlayerAnimationNames.WalkRight, true);
|
||||
} else if (this.body.velocity.x < 0) { //moving left
|
||||
this.anims.playReverse(PlayerAnimationNames.WalkLeft, true);
|
||||
} else if (this.body.velocity.y < 0) { //moving up
|
||||
this.play(PlayerAnimationNames.WalkUp, true);
|
||||
} else if (this.body.velocity.y > 0) { //moving down
|
||||
this.play(PlayerAnimationNames.WalkDown, true);
|
||||
}
|
||||
}
|
||||
|
||||
say(text: string) {
|
||||
if (this.bubble) return;
|
||||
this.bubble = new SpeechBubble(this.scene, this, text)
|
||||
//todo make the buble destroy on player movement?
|
||||
setTimeout(() => {
|
||||
this.bubble.destroy();
|
||||
this.bubble = null;
|
||||
}, 3000)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue