Browse Source

Textures working, buttons still not

Ryan Dahlke 2 years ago
parent
commit
50f6a83f95
1 changed files with 51 additions and 13 deletions
  1. 51 13
      src/HelloWorldScene.ts

+ 51 - 13
src/HelloWorldScene.ts

@@ -13,6 +13,7 @@ export default class HelloWorldScene extends Phaser.Scene {
     private buttonsA?: Phaser.Physics.Arcade.Group;
     private gates?: Phaser.Physics.Arcade.Group;
     private gateArray: Gate[] = [];
+    private gatesA?: Phaser.Physics.Arcade.Group;
     private platforms?: Phaser.Physics.Arcade.StaticGroup;
     private player1?: Phaser.Physics.Arcade.Sprite;
     private player2?: Phaser.Physics.Arcade.Sprite;
@@ -34,6 +35,7 @@ export default class HelloWorldScene extends Phaser.Scene {
         this.load.image("buttonA", "assets/buttonA.png");
         this.load.image("gate", "assets/BowlingBall.png");
         this.load.image("ground", "assets/platform.png");
+        this.load.image("gateA", "assets/star.png");
         this.load.spritesheet("dude", "assets/dude.png", {
             frameWidth: 32, frameHeight: 48
         });
@@ -116,7 +118,7 @@ export default class HelloWorldScene extends Phaser.Scene {
 
         //Code related to switches
         this.switchArray = []
-       this.switchArray.push(new Switch(this, 400, 500, "assets/star.png", 0, 0))
+       this.switchArray.push(new Switch(this, 400, 500, "switch", 0, 0))
         this.switches = this.physics.add.group({
             key: "switch",
             setXY: { x: -480, y: 250 }
@@ -143,6 +145,8 @@ export default class HelloWorldScene extends Phaser.Scene {
         this.physics.add.overlap(this.switchesA, this.player1, this.handleHitSwitchA1, undefined, this)
         this.physics.add.overlap(this.switchesA, this.player2, this.handleHitSwitchA2, undefined, this)
         
+        
+
         // Here you can make new switches without having to call anything else - BN
         //this.switches.create(400, 510,"switch")
         //this.switchesA.create(400, 510,"switchA")
@@ -156,13 +160,28 @@ export default class HelloWorldScene extends Phaser.Scene {
             allowGravity: false,
             setXY: { x: -480, y: 250 }
         })
+
+        this.gatesA = this.physics.add.group({
+            key: "gateA",
+            immovable: true,
+            allowGravity: false,
+            setXY: { x: 200, y: 200 },
+        })
+        this.gatesA.create(400, 200,"gateA")
+        this.physics.add.overlap(this.gatesA, this.gates, this.handleGateSetup, undefined, this)
+
        // this.gates.create(200, 0,"gate")
         this.physics.add.collider(this.gates, this.platforms)
         this.physics.add.collider(this.gates, this.player1)
         this.physics.add.collider(this.gates, this.player2)
 
-        this.gateArray[0] = new Gate(this, 0, 250, "assets/BowlingBall.png", 0);
-        this.gateArray[1] = new Gate(this, 200, 200, "assets/BowlingBall.png", 1);
+        this.gateArray[0] = new Gate(this, 0, 250, "gate", 0);
+        this.gateArray[1] = new Gate(this, 200, 200, "gate", 1);
+        this.gateArray[2] = new Gate(this, 400, 200, "gate", 2);
+        
+        this.gateArray.forEach(object => {
+            this.gates?.add(object);
+        })
         // for scene transition
         if (this.nextScene) {
             this.tweens.add({
@@ -180,8 +199,8 @@ export default class HelloWorldScene extends Phaser.Scene {
 
         //Code related to buttons
         this.buttonArray = []
-       this.buttonArray.push(new Button(this, 480, 250, "assets/star.png", 0, 0))
-       this.buttonArray.push(new Button(this, 300, 500, "assets/star.png", 0, 0))
+       this.buttonArray.push(new Button(this, 480, 250, "button", 1, 0))
+       this.buttonArray.push(new Button(this, 300, 500, "button", 2, 0))
         this.buttons = this.physics.add.group({
             key: "button",
             setXY: { x: -480, y: 250 }
@@ -194,7 +213,7 @@ export default class HelloWorldScene extends Phaser.Scene {
         this.physics.add.collider(this.buttons, this.platforms)
         this.physics.add.overlap(this.player1, this.buttons, this.handleHitButton, undefined, this)
         this.physics.add.overlap(this.player2, this.buttons, this.handleHitButton, undefined, this)
-
+        
         this.buttonsA = this.physics.add.group({
             key: "buttonA",
             setXY: { x: 480, y: 250 }
@@ -215,9 +234,17 @@ export default class HelloWorldScene extends Phaser.Scene {
 
     //Handle buttons
     private handleHitButton(player1: Phaser.GameObjects.GameObject, b: Phaser.GameObjects.GameObject) {
-
+        const the_button = b as Button
+        this.gateArray[the_button.gateID].actives[the_button.buttonID] = true;
+        this.gateArray[the_button.gateID].handleActivate;
+        //temp code
+        this.gateArray[the_button.gateID].disableBody(true,true)
+       // this.time.delayedCall(1000,  this.handleGateDeactive, undefined, this.gateArray[the_button.gateID])
+        
+        
     }
 
+
     private handleButtonSetup(bA: Phaser.GameObjects.GameObject, b: Phaser.GameObjects.GameObject) {
         const the_button = bA as Phaser.Physics.Arcade.Image
         the_button.visible = false
@@ -239,22 +266,22 @@ export default class HelloWorldScene extends Phaser.Scene {
         the_switch.visible = false
     }
 
-    private handleHitSwitch1(player1: Phaser.GameObjects.GameObject, s: Phaser.GameObjects.GameObject) {
+    private handleHitSwitch1(player1: Phaser.GameObjects.GameObject, s: Switch) {
         const the_switch = s as Switch
-        the_switch.gateID = 0;
-        the_switch.switchID = 0;
-        //this.gateArray[the_switch.gateID].setVisible(false)
         the_switch.disableBody(true, true)
         this.gateArray[the_switch.gateID].actives[the_switch.switchID] = true;
         this.gateArray[the_switch.gateID].handleActivate;
-        //this.gateArray[the_switch.gateID].setVisible(false)
+        //temp code
+        this.gateArray[the_switch.gateID].disableBody(true,true)
     }
 
-    private handleHitSwitch2(player2: Phaser.GameObjects.GameObject, s: Phaser.GameObjects.GameObject) {
+    private handleHitSwitch2(player2: Phaser.GameObjects.GameObject, s: Switch) {
         const the_switch = s as Switch
         the_switch.disableBody(true, true)
         this.gateArray[the_switch.gateID].actives[the_switch.switchID] = true;
         this.gateArray[the_switch.gateID].handleActivate;
+        //temp code
+        this.gateArray[the_switch.gateID].disableBody(true,true)
     }
 
     private handleHitSwitchA1(player1: Phaser.GameObjects.GameObject, sA: Phaser.GameObjects.GameObject) {
@@ -267,6 +294,17 @@ export default class HelloWorldScene extends Phaser.Scene {
         the_switch.visible = true
     }
 
+    //Handle Gates
+    private handleGateSetup(gA: Phaser.GameObjects.GameObject, g: Gate) {
+        const the_gate = g as Phaser.Physics.Arcade.Image
+        the_gate.enableBody(false, the_gate.x, the_gate.y, true, true)
+    }
+
+    private handleGateDeactive(g:Gate){
+        const the_gate = g as Phaser.Physics.Arcade.Image
+        the_gate.enableBody(false, the_gate.x, the_gate.y, true, true)
+    }
+
 	// sence transition
     private handleLoadNextScene(player: Phaser.GameObjects.GameObject, sA: Phaser.GameObjects.GameObject) {
         this.scene.start('TwoScene')