Compare commits
1 commit
develop
...
enter-anim
Author | SHA1 | Date | |
---|---|---|---|
a6e25ffc35 |
|
@ -319,7 +319,10 @@ export class GameScene extends Phaser.Scene {
|
||||||
this.GameManager.joinRoom(this.RoomId, this.startX, this.startY, PlayerAnimationNames.WalkDown, false);
|
this.GameManager.joinRoom(this.RoomId, this.startX, this.startY, PlayerAnimationNames.WalkDown, false);
|
||||||
|
|
||||||
//listen event to share position of user
|
//listen event to share position of user
|
||||||
this.CurrentPlayer.on(hasMovedEventName, this.pushPlayerPosition.bind(this))
|
this.CurrentPlayer.on(hasMovedEventName, this.pushPlayerPosition.bind(this));
|
||||||
|
|
||||||
|
//play animation when the user enter in new map
|
||||||
|
this.CurrentPlayer.startAnimation();
|
||||||
}
|
}
|
||||||
|
|
||||||
pushPlayerPosition(event: HasMovedEvent) {
|
pushPlayerPosition(event: HasMovedEvent) {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {PlayableCaracter} from "../Entity/PlayableCaracter";
|
||||||
export const hasMovedEventName = "hasMoved";
|
export const hasMovedEventName = "hasMoved";
|
||||||
export interface CurrentGamerInterface extends PlayableCaracter{
|
export interface CurrentGamerInterface extends PlayableCaracter{
|
||||||
moveUser(delta: number) : void;
|
moveUser(delta: number) : void;
|
||||||
|
startAnimation(): void;
|
||||||
say(text : string) : void;
|
say(text : string) : void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +34,11 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
|
||||||
previousDirection: string;
|
previousDirection: string;
|
||||||
wasMoving: boolean;
|
wasMoving: boolean;
|
||||||
|
|
||||||
|
startedAnimationVelocityX : number = 0;
|
||||||
|
startedAnimationVelocityY: number = 0;
|
||||||
|
startedAnimationDirection: string = PlayerAnimationNames.WalkDown;
|
||||||
|
lock: boolean;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
userId: string,
|
userId: string,
|
||||||
Scene: GameScene,
|
Scene: GameScene,
|
||||||
|
@ -69,6 +75,30 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO : personalize start animation by map with start case animation and end case animation ?
|
||||||
|
* This could be optional in a map?
|
||||||
|
*/
|
||||||
|
startAnimation(){
|
||||||
|
this.lock = true;
|
||||||
|
this.startedAnimationVelocityX = -16;
|
||||||
|
this.startedAnimationVelocityY = 0;
|
||||||
|
this.startedAnimationDirection = PlayerAnimationNames.WalkLeft;
|
||||||
|
setTimeout(() => {
|
||||||
|
this.stop();
|
||||||
|
this.move(0, 16);
|
||||||
|
this.startedAnimationVelocityX = 0;
|
||||||
|
this.startedAnimationVelocityY = 16;
|
||||||
|
this.startedAnimationDirection = PlayerAnimationNames.WalkDown;
|
||||||
|
setTimeout(() => {
|
||||||
|
this.startedAnimationVelocityX = 0;
|
||||||
|
this.startedAnimationVelocityY = 0;
|
||||||
|
this.stop();
|
||||||
|
this.lock = false;
|
||||||
|
}, 500);
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
|
||||||
private getPlayerAnimations(name: string): AnimationData[] {
|
private getPlayerAnimations(name: string): AnimationData[] {
|
||||||
return [{
|
return [{
|
||||||
key: `${name}-${PlayerAnimationNames.WalkDown}`,
|
key: `${name}-${PlayerAnimationNames.WalkDown}`,
|
||||||
|
@ -112,6 +142,13 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
|
||||||
|
|
||||||
let x = 0;
|
let x = 0;
|
||||||
let y = 0;
|
let y = 0;
|
||||||
|
|
||||||
|
if(this.lock){
|
||||||
|
x = this.startedAnimationVelocityX;
|
||||||
|
y = this.startedAnimationVelocityY;
|
||||||
|
direction = this.startedAnimationDirection;
|
||||||
|
moving = true;
|
||||||
|
}else {
|
||||||
if (activeEvents.get(UserInputEvent.MoveUp)) {
|
if (activeEvents.get(UserInputEvent.MoveUp)) {
|
||||||
y = -moveAmount;
|
y = -moveAmount;
|
||||||
direction = PlayerAnimationNames.WalkUp;
|
direction = PlayerAnimationNames.WalkUp;
|
||||||
|
@ -130,6 +167,7 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
|
||||||
direction = PlayerAnimationNames.WalkRight;
|
direction = PlayerAnimationNames.WalkRight;
|
||||||
moving = true;
|
moving = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (x !== 0 || y !== 0) {
|
if (x !== 0 || y !== 0) {
|
||||||
this.move(x, y);
|
this.move(x, y);
|
||||||
this.emit(hasMovedEventName, {moving, direction, x: this.x, y: this.y});
|
this.emit(hasMovedEventName, {moving, direction, x: this.x, y: this.y});
|
||||||
|
|
Loading…
Reference in a new issue