fixed the player animations
This commit is contained in:
parent
d1106d757d
commit
97a55ab66c
@ -6,7 +6,7 @@ import {NonPlayer} from "../NonPlayer/NonPlayer";
|
|||||||
|
|
||||||
export enum Textures {
|
export enum Textures {
|
||||||
Rock = 'rock',
|
Rock = 'rock',
|
||||||
Player = 'player',
|
Player = 'playerModel',
|
||||||
Map = 'map',
|
Map = 'map',
|
||||||
Tiles = 'tiles'
|
Tiles = 'tiles'
|
||||||
}
|
}
|
||||||
@ -39,7 +39,11 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
|||||||
'resources/characters/pipoya/Male 01-1.png',
|
'resources/characters/pipoya/Male 01-1.png',
|
||||||
{ frameWidth: 32, frameHeight: 32 }
|
{ 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 => {
|
getPlayerAnimations().forEach(d => {
|
||||||
this.anims.create({
|
this.anims.create({
|
||||||
key: d.key,
|
key: d.key,
|
||||||
@ -48,10 +52,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
|||||||
//repeat: d.repeat
|
//repeat: d.repeat
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
//hook create scene
|
|
||||||
create(): void {
|
|
||||||
this.userInputManager = new UserInputManager(this);
|
this.userInputManager = new UserInputManager(this);
|
||||||
|
|
||||||
//create entities
|
//create entities
|
||||||
@ -68,8 +69,8 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
|||||||
//create map
|
//create map
|
||||||
let currentMap = this.add.tilemap(Textures.Map);
|
let currentMap = this.add.tilemap(Textures.Map);
|
||||||
let terrain = currentMap.addTilesetImage(Textures.Tiles, "tiles");
|
let terrain = currentMap.addTilesetImage(Textures.Tiles, "tiles");
|
||||||
let bottomLayer = currentMap.createStaticLayer("Calque 1", [terrain], 0, 0).setDepth(-1);
|
let bottomLayer = currentMap.createStaticLayer("Calque 1", [terrain], 0, 0).setDepth(-2);
|
||||||
let topLayer = currentMap.createStaticLayer("Calque 2", [terrain], 0, 0);
|
let topLayer = currentMap.createStaticLayer("Calque 2", [terrain], 0, 0).setDepth(-1);
|
||||||
this.physics.world.setBounds(0,0, currentMap.widthInPixels, currentMap.heightInPixels);
|
this.physics.world.setBounds(0,0, currentMap.widthInPixels, currentMap.heightInPixels);
|
||||||
|
|
||||||
this.physics.add.collider(this.player, topLayer);
|
this.physics.add.collider(this.player, topLayer);
|
||||||
@ -105,6 +106,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
|||||||
this.player.move(eventList);
|
this.player.move(eventList);
|
||||||
|
|
||||||
this.otherPlayers.getChildren().forEach((otherPlayer: NonPlayer) => {
|
this.otherPlayers.getChildren().forEach((otherPlayer: NonPlayer) => {
|
||||||
|
//this.physics.accelerateToObject(otherPlayer, this.player); //this line make the models chase the player
|
||||||
otherPlayer.setVelocity(20, 5);
|
otherPlayer.setVelocity(20, 5);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import {Textures} from "../Game/GameScene";
|
|||||||
export class NonPlayer extends PlayableCaracter {
|
export class NonPlayer extends PlayableCaracter {
|
||||||
|
|
||||||
constructor(scene: Phaser.Scene, x: number, y: number) {
|
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
|
this.setSize(32, 32); //edit the hitbox to better match the caracter model
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ import {PlayableCaracter} from "../Entity/PlayableCaracter";
|
|||||||
export class Player extends PlayableCaracter{
|
export class Player extends PlayableCaracter{
|
||||||
|
|
||||||
constructor(scene: Phaser.Scene, x: number, y: number) {
|
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.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
|
this.setSize(32, 32); //edit the hitbox to better match the caracter model
|
||||||
}
|
}
|
||||||
@ -19,27 +19,28 @@ export class Player extends PlayableCaracter{
|
|||||||
|
|
||||||
if(activeEvents.get(UserInputEvent.MoveUp)){
|
if(activeEvents.get(UserInputEvent.MoveUp)){
|
||||||
this.setVelocity(0, -speed)
|
this.setVelocity(0, -speed)
|
||||||
playAnimation(this, PlayerAnimationNames.WalkUp);
|
|
||||||
} else if(activeEvents.get(UserInputEvent.MoveLeft)){
|
} else if(activeEvents.get(UserInputEvent.MoveLeft)){
|
||||||
this.setVelocity(-speed, 0)
|
this.setVelocity(-speed, 0)
|
||||||
} else if(activeEvents.get(UserInputEvent.MoveDown)){
|
} else if(activeEvents.get(UserInputEvent.MoveDown)){
|
||||||
playAnimation(this, PlayerAnimationNames.WalkDown);
|
|
||||||
this.setVelocity(0, speed)
|
this.setVelocity(0, speed)
|
||||||
} else if(activeEvents.get(UserInputEvent.MoveRight)){
|
} else if(activeEvents.get(UserInputEvent.MoveRight)){
|
||||||
this.setVelocity(speed, 0)
|
this.setVelocity(speed, 0)
|
||||||
} else {
|
} else {
|
||||||
this.setVelocity(0, 0)
|
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() {
|
stop() {
|
||||||
this.setVelocity(0, 0)
|
this.setVelocity(0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*private sharePosition(direction : string){
|
|
||||||
if(ConnexionInstance) {
|
|
||||||
ConnexionInstance.sharePosition((this.scene as GameSceneInterface).RoomId, this.x, this.y, direction);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user