Create an enter animation of the player in the map
- I have added lock parameter. When a user enters in the map, the player automatically moving during 1sec. So during 1sec, the gamer cannot use key to move. - How to personalize start animation by map with start case animation and end case animation? - I think that this could be optional in a map?
This commit is contained in:
parent
9c3151a077
commit
a6e25ffc35
|
@ -319,7 +319,10 @@ export class GameScene extends Phaser.Scene {
|
|||
this.GameManager.joinRoom(this.RoomId, this.startX, this.startY, PlayerAnimationNames.WalkDown, false);
|
||||
|
||||
//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) {
|
||||
|
|
|
@ -8,6 +8,7 @@ import {PlayableCaracter} from "../Entity/PlayableCaracter";
|
|||
export const hasMovedEventName = "hasMoved";
|
||||
export interface CurrentGamerInterface extends PlayableCaracter{
|
||||
moveUser(delta: number) : void;
|
||||
startAnimation(): void;
|
||||
say(text : string) : void;
|
||||
}
|
||||
|
||||
|
@ -33,6 +34,11 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
|
|||
previousDirection: string;
|
||||
wasMoving: boolean;
|
||||
|
||||
startedAnimationVelocityX : number = 0;
|
||||
startedAnimationVelocityY: number = 0;
|
||||
startedAnimationDirection: string = PlayerAnimationNames.WalkDown;
|
||||
lock: boolean;
|
||||
|
||||
constructor(
|
||||
userId: string,
|
||||
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[] {
|
||||
return [{
|
||||
key: `${name}-${PlayerAnimationNames.WalkDown}`,
|
||||
|
@ -112,8 +142,15 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
|
|||
|
||||
let x = 0;
|
||||
let y = 0;
|
||||
|
||||
if(this.lock){
|
||||
x = this.startedAnimationVelocityX;
|
||||
y = this.startedAnimationVelocityY;
|
||||
direction = this.startedAnimationDirection;
|
||||
moving = true;
|
||||
}else {
|
||||
if (activeEvents.get(UserInputEvent.MoveUp)) {
|
||||
y = - moveAmount;
|
||||
y = -moveAmount;
|
||||
direction = PlayerAnimationNames.WalkUp;
|
||||
moving = true;
|
||||
} else if (activeEvents.get(UserInputEvent.MoveDown)) {
|
||||
|
@ -130,6 +167,7 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
|
|||
direction = PlayerAnimationNames.WalkRight;
|
||||
moving = true;
|
||||
}
|
||||
}
|
||||
if (x !== 0 || y !== 0) {
|
||||
this.move(x, y);
|
||||
this.emit(hasMovedEventName, {moving, direction, x: this.x, y: this.y});
|
||||
|
|
Loading…
Reference in a new issue