added other players models and fixed collision with other entities

This commit is contained in:
kharhamel 2020-04-12 17:08:28 +02:00
parent 6e27377b07
commit 2b2b615e7b
3 changed files with 20 additions and 3 deletions

View File

@ -2,6 +2,7 @@ import {GameManagerInterface} from "./GameManager";
import {UserInputManager} from "../UserInput/UserInputManager";
import {getPlayerAnimations, PlayerAnimationNames} from "../Player/Animation";
import {Player} from "../Player/Player";
import {NonPlayer} from "../NonPlayer/NonPlayer";
export enum Textures {
Rock = 'rock',
@ -20,6 +21,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
private player: Player;
private rock: Phaser.Physics.Arcade.Sprite;
private userInputManager: UserInputManager;
private otherPlayers: Phaser.Physics.Arcade.Group;
constructor(RoomId : string, GameManager : GameManagerInterface) {
super({
@ -55,9 +57,13 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
//create entities
this.player = new Player(this, 400, 400);
this.rock = this.physics.add.sprite(200, 400, Textures.Rock, 26).setImmovable(true);
this.physics.world.addCollider(this.player, this.rock, (player: Player, rock) => {
rock.destroy();
});
this.physics.add.collider(this.player, this.rock);
this.otherPlayers = this.physics.add.group({ immovable: true });
this.otherPlayers.add(new NonPlayer(this, 200, 600));
this.otherPlayers.add(new NonPlayer(this, 400, 600));
this.physics.add.collider(this.player, this.otherPlayers);
//create map
let currentMap = this.add.tilemap(Textures.Map);

View File

@ -0,0 +1,10 @@
import {PlayableCaracter} from "../Entity/PlayableCaracter";
import {Textures} from "../Game/GameScene";
export class NonPlayer extends PlayableCaracter {
constructor(scene: Phaser.Scene, x: number, y: number) {
super(scene, x, y, Textures.Player, 26);
this.setSize(32, 32); //edit the hitbox to better match the caracter model
}
}

View File

@ -8,6 +8,7 @@ export class Player extends PlayableCaracter{
constructor(scene: Phaser.Scene, x: number, y: number) {
super(scene, x, y, Textures.Player, 26);
this.setImmovable(false);
this.setSize(32, 32); //edit the hitbox to better match the caracter model
}