added a rock
authorkharhamel <oognic@gmail.com>
Sat, 11 Apr 2020 16:17:36 +0000 (18:17 +0200)
committerkharhamel <oognic@gmail.com>
Sat, 11 Apr 2020 16:17:36 +0000 (18:17 +0200)
front/dist/resources/objects/rockSprite.png [new file with mode: 0644]
front/src/Phaser/Game/GameScene.ts
front/src/Phaser/Game/MapManager.ts
front/src/Phaser/Rock/Rock.ts [new file with mode: 0644]
front/src/Phaser/UserInput/UserInputManager.ts
front/src/index.ts

diff --git a/front/dist/resources/objects/rockSprite.png b/front/dist/resources/objects/rockSprite.png
new file mode 100644 (file)
index 0000000..40820ab
Binary files /dev/null and b/front/dist/resources/objects/rockSprite.png differ
index d3abfd155057fdf5bb116b27d4c2f5935eabdd72..faf196164a6edb06621d71d6f9c7aab27b8584ef 100644 (file)
@@ -1,6 +1,10 @@
 import {MapManagerInterface, MapManager} from "./MapManager";
 import {GameManagerInterface} from "./GameManager";
 
+export enum Textures {
+    Rock = 'rock',
+}
+
 export interface GameSceneInterface extends Phaser.Scene {
     RoomId : string;
     sharedUserPosition(data : []): void;
@@ -18,6 +22,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
 
     //hook preload scene
     preload(): void {
+        this.load.image(Textures.Rock, 'resources/objects/rockSprite.png');
         this.load.image('tiles', 'maps/tiles.png');
         this.load.tilemapTiledJSON('map', 'maps/map2.json');
         this.load.spritesheet('player',
index 3f8521d46ad47b9eccf07dc5931cb88fa6f51be3..e6a82dc04a7e12308e2684c9023f8cade1d4e7e5 100644 (file)
@@ -1,8 +1,9 @@
 import {CameraManager, CameraManagerInterface} from "./CameraManager";
 import {RESOLUTION} from "../../Enum/EnvironmentVariable";
 import {Player} from "../Player/Player";
-import {GameScene, GameSceneInterface} from "./GameScene";
-import {UserInputManager} from "../UserInput/UserInputManager";
+import {Rock} from "../Rock/Rock";
+import {GameSceneInterface} from "./GameScene";
+import {UserInputEvent, UserInputManager} from "../UserInput/UserInputManager";
 
 export interface MapManagerInterface {
     Map: Phaser.Tilemaps.Tilemap;
@@ -21,6 +22,7 @@ export class MapManager implements MapManagerInterface{
     startX = (window.innerWidth / 2) / RESOLUTION;
     startY = (window.innerHeight / 2) / RESOLUTION;
     userInputManager: UserInputManager;
+    private rock: Rock;
 
     constructor(scene: GameSceneInterface){
         this.Scene = scene;
@@ -44,11 +46,21 @@ export class MapManager implements MapManagerInterface{
             this
         );
         this.CurrentPlayer.initAnimation();
+        this.rock = new Rock(
+            this.Scene,
+            100,
+            300,
+        );
+        //this.rock.set()
     }
 
     update() : void {
         let activeEvents = this.userInputManager.getEventListForGameTick();
         
         this.CurrentPlayer.move(activeEvents);
+        
+        /*if (activeEvents.get(UserInputEvent.Interact)) {
+            
+        }*/
     }
 }
\ No newline at end of file
diff --git a/front/src/Phaser/Rock/Rock.ts b/front/src/Phaser/Rock/Rock.ts
new file mode 100644 (file)
index 0000000..8892f10
--- /dev/null
@@ -0,0 +1,28 @@
+import {GameSceneInterface, Textures} from "../Game/GameScene";
+import {CameraManagerInterface} from "../Game/CameraManager";
+import {MapManagerInterface} from "../Game/MapManager";
+
+export class Rock extends Phaser.GameObjects.Image {
+    private isMoving: boolean;
+
+    constructor(
+        Scene : GameSceneInterface,
+        x : number,
+        y : number,
+    ) {
+        super(Scene, x, y, Textures.Rock);
+        Scene.add.existing(this);
+        this.isMoving = false;
+    }
+    
+    push() {
+        console.log("the rock is pushed!")
+    }
+    
+    move() {
+        if(!this.isMoving) {
+            return;
+        }
+    }
+    
+}
\ No newline at end of file
index c362bd958cf14c33e80dbb9e02eb8edc4ccac183..e05eccb2137dcb77600a3d2566c1fb7f6ed8219e 100644 (file)
@@ -13,6 +13,7 @@ export enum UserInputEvent {
     MoveRight,
     MoveDown,
     SpeedUp,
+    Interact,
 }
 
 //we cannot the map structure so we have to create a replacment
@@ -43,6 +44,8 @@ export class UserInputManager {
         {keyCode: Phaser.Input.Keyboard.KeyCodes.RIGHT, event: UserInputEvent.MoveRight, keyInstance: null},
         
         {keyCode: Phaser.Input.Keyboard.KeyCodes.SHIFT, event: UserInputEvent.SpeedUp, keyInstance: null},
+        
+        {keyCode: Phaser.Input.Keyboard.KeyCodes.E, event: UserInputEvent.Interact, keyInstance: null},
     ];
     
     constructor(Scene : GameSceneInterface) {
index 650fd52cde7bea72555521c3222f48834d12c8da..f74c9fa5106e721e50393c738ef1cb4ffff9dc2a 100644 (file)
@@ -12,6 +12,9 @@ const config: GameConfig = {
     parent: "game",
     scene: gameManager.GameScenes,
     zoom: RESOLUTION,
+    physics: {
+        default: 'impact'
+    },
 };
 
 let game = new Phaser.Game(config);