瀏覽代碼

Merge pull request #15 from Spring-2023-CISC374/Gates-2

Gates-2
RyanADahlke 2 年之前
父節點
當前提交
1e03aa1af2
共有 2 個文件被更改,包括 20 次插入11 次删除
  1. 16 8
      src/HelloWorldScene.ts
  2. 4 3
      src/Objects/Gate.ts

+ 16 - 8
src/HelloWorldScene.ts

@@ -26,6 +26,7 @@ export default class HelloWorldScene extends Phaser.Scene {
 
     constructor() {
         super('hello-world')
+
     }
 
     preload() {
@@ -142,7 +143,7 @@ export default class HelloWorldScene extends Phaser.Scene {
 
         //Code related to switches
         this.switchArray = []
-       this.switchArray.push(new Switch(this, 400, 500, "switch", 0, 0))
+       this.switchArray.push(new Switch(this, 400, 500, "switch", 2, 1))
         this.switches = this.physics.add.group({
             key: "switch",
             setXY: { x: -480, y: 250 }
@@ -266,10 +267,9 @@ export default class HelloWorldScene extends Phaser.Scene {
     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;
+        this.handleActivateGate(the_button.gateID);
         //temp code
-        this.gateArray[the_button.gateID].disableBody(true,true)
-       // this.time.delayedCall(1000,  this.handleGateDeactive, undefined, this.gateArray[the_button.gateID])
+       // this.gateArray[the_button.gateID].disableBody(true,true)
         
         
     }
@@ -300,16 +300,16 @@ export default class HelloWorldScene extends Phaser.Scene {
         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;
+        this.handleActivateGate(the_switch.gateID);
         //temp code
-        this.gateArray[the_switch.gateID].disableBody(true,true)
+        //this.gateArray[the_switch.gateID].disableBody(true,true)
     }
 
     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;
+        this.handleActivateGate(the_switch.gateID);
         //temp code
         this.gateArray[the_switch.gateID].disableBody(true,true)
     }
@@ -330,6 +330,13 @@ export default class HelloWorldScene extends Phaser.Scene {
         the_gate.enableBody(false, the_gate.x, the_gate.y, true, true)
     }
 
+    handleActivateGate(gateID: number){
+        if(this.gateArray[gateID].actives[0] && this.gateArray[gateID].actives[1] && this.gateArray[gateID].actives[2]){
+            this.gateArray[gateID].disableBody(true,true)
+        }
+        return;
+    }
+
     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)
@@ -394,7 +401,8 @@ export default class HelloWorldScene extends Phaser.Scene {
             if(this.checkOverlap(this.buttonArray[i], this.player1) == false && this.checkOverlap(this.buttonArray[i], this.player2) == false){
                  let gateX = this.gateArray[this.buttonArray[i].gateID].x
                  let gateY = this.gateArray[this.buttonArray[i].gateID].y
-                 this.gateArray[this.buttonArray[i].gateID].enableBody(false, gateX, gateY, true, true)
+                 this.gateArray[this.buttonArray[i].gateID].actives[this.buttonArray[i].buttonID] = false;
+                 //this.gateArray[this.buttonArray[i].gateID].enableBody(false, gateX, gateY, true, true)
             }
            
         }

+ 4 - 3
src/Objects/Gate.ts

@@ -5,14 +5,15 @@ export default class Gate extends Phaser.Physics.Arcade.Image{
 
     constructor(scene: Phaser.Scene, x: number, y: number, texture: string, actives:number) {
         super(scene, x, y, texture);
-        /*
+        
         for(let i = 0; i < actives && i < 3; i++){
             this.actives[i] = false
         }
-        */
+        
         scene.add.existing(this);
     }
 
+    /*
     handleActivate(){
         if(this.actives[0] && this.actives[1] && this.actives[2]){
             this.setVisible(false)
@@ -30,5 +31,5 @@ export default class Gate extends Phaser.Physics.Arcade.Image{
         return;
     }
 
-
+*/
 }