From 2b2b615e7bb2094d7a25f563228da0bb18d9457e Mon Sep 17 00:00:00 2001 From: kharhamel Date: Sun, 12 Apr 2020 17:08:28 +0200 Subject: [PATCH] added other players models and fixed collision with other entities --- front/src/Phaser/Game/GameScene.ts | 12 +++++++++--- front/src/Phaser/NonPlayer/NonPlayer.ts | 10 ++++++++++ front/src/Phaser/Player/Player.ts | 1 + 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 front/src/Phaser/NonPlayer/NonPlayer.ts diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 3d02cf72..545146b1 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -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); diff --git a/front/src/Phaser/NonPlayer/NonPlayer.ts b/front/src/Phaser/NonPlayer/NonPlayer.ts new file mode 100644 index 00000000..d9b22001 --- /dev/null +++ b/front/src/Phaser/NonPlayer/NonPlayer.ts @@ -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 + } +} \ No newline at end of file diff --git a/front/src/Phaser/Player/Player.ts b/front/src/Phaser/Player/Player.ts index ed85f5b4..f6079ac8 100644 --- a/front/src/Phaser/Player/Player.ts +++ b/front/src/Phaser/Player/Player.ts @@ -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 }