export enum Textures {
Rock = 'rock',
- Player = 'player',
+ Player = 'playerModel',
Map = 'map',
Tiles = 'tiles'
}
'resources/characters/pipoya/Male 01-1.png',
{ frameWidth: 32, frameHeight: 32 }
);
+ }
+ //hook create scene
+ create(): void {
+ //anims cannot be in preload because it needs to wait to the sprit to be loaded
getPlayerAnimations().forEach(d => {
this.anims.create({
key: d.key,
//repeat: d.repeat
});
});
- }
-
- //hook create scene
- create(): void {
+
this.userInputManager = new UserInputManager(this);
//create entities
//create map
let currentMap = this.add.tilemap(Textures.Map);
let terrain = currentMap.addTilesetImage(Textures.Tiles, "tiles");
- let bottomLayer = currentMap.createStaticLayer("Calque 1", [terrain], 0, 0).setDepth(-1);
- let topLayer = currentMap.createStaticLayer("Calque 2", [terrain], 0, 0);
+ let bottomLayer = currentMap.createStaticLayer("Calque 1", [terrain], 0, 0).setDepth(-2);
+ let topLayer = currentMap.createStaticLayer("Calque 2", [terrain], 0, 0).setDepth(-1);
this.physics.world.setBounds(0,0, currentMap.widthInPixels, currentMap.heightInPixels);
this.physics.add.collider(this.player, topLayer);
this.player.move(eventList);
this.otherPlayers.getChildren().forEach((otherPlayer: NonPlayer) => {
+ //this.physics.accelerateToObject(otherPlayer, this.player); //this line make the models chase the player
otherPlayer.setVelocity(20, 5);
})
}
export class NonPlayer extends PlayableCaracter {
constructor(scene: Phaser.Scene, x: number, y: number) {
- super(scene, x, y, Textures.Player, 26);
+ super(scene, x, y, Textures.Player, 1);
this.setSize(32, 32); //edit the hitbox to better match the caracter model
}
}
\ No newline at end of file
export class Player extends PlayableCaracter{
constructor(scene: Phaser.Scene, x: number, y: number) {
- super(scene, x, y, Textures.Player, 26);
+ super(scene, x, y, Textures.Player, 1);
this.setImmovable(false); //the current player model should be push away by other players to prevent conflict
this.setSize(32, 32); //edit the hitbox to better match the caracter model
}
if(activeEvents.get(UserInputEvent.MoveUp)){
this.setVelocity(0, -speed)
- playAnimation(this, PlayerAnimationNames.WalkUp);
} else if(activeEvents.get(UserInputEvent.MoveLeft)){
this.setVelocity(-speed, 0)
} else if(activeEvents.get(UserInputEvent.MoveDown)){
- playAnimation(this, PlayerAnimationNames.WalkDown);
this.setVelocity(0, speed)
} else if(activeEvents.get(UserInputEvent.MoveRight)){
this.setVelocity(speed, 0)
} else {
this.setVelocity(0, 0)
- playAnimation(this, PlayerAnimationNames.None);
+ }
+
+ if (this.body.velocity.x > 0) { //moving right
+ this.play("right", true);
+ } else if (this.body.velocity.x < 0) { //moving left
+ this.anims.playReverse("left", true);
+ } else if (this.body.velocity.y < 0) { //moving up
+ this.play("up", true);
+ } else if (this.body.velocity.y > 0) { //moving down
+ this.play("down", true);
}
}
stop() {
this.setVelocity(0, 0)
}
-
- /*private sharePosition(direction : string){
- if(ConnexionInstance) {
- ConnexionInstance.sharePosition((this.scene as GameSceneInterface).RoomId, this.x, this.y, direction);
- }
- }*/
}
\ No newline at end of file