added other players models and fixed collision with other entities
authorkharhamel <oognic@gmail.com>
Sun, 12 Apr 2020 15:08:28 +0000 (17:08 +0200)
committerkharhamel <oognic@gmail.com>
Sun, 12 Apr 2020 15:08:28 +0000 (17:08 +0200)
front/src/Phaser/Game/GameScene.ts
front/src/Phaser/NonPlayer/NonPlayer.ts [new file with mode: 0644]
front/src/Phaser/Player/Player.ts

index 3d02cf72ec480077b06f12e99601673cfd4bf32a..545146b17999c2888d48519af01f356831ad548d 100644 (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);
diff --git a/front/src/Phaser/NonPlayer/NonPlayer.ts b/front/src/Phaser/NonPlayer/NonPlayer.ts
new file mode 100644 (file)
index 0000000..d9b2200
--- /dev/null
@@ -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
index ed85f5b42192fa5e14943dd51df6411bedf57c86..f6079ac835705278b37f10daecfa4088c7b498bf 100644 (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
     }