From 3dff6108c58c830147c7442c0ed31a2335a5009e Mon Sep 17 00:00:00 2001 From: Charlize Date: Fri, 15 Mar 2024 16:56:59 -0700 Subject: [PATCH] Found Game Breaking Bug Trying to Fix it --- src/prefabs/Character.js | 10 ++++++++++ src/prefabs/Selection.js | 9 +++++++-- src/prefabs/Summon.js | 7 +++++-- src/scenes/Fighting.js | 10 +++++++++- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/prefabs/Character.js b/src/prefabs/Character.js index c6135d7..01b7038 100644 --- a/src/prefabs/Character.js +++ b/src/prefabs/Character.js @@ -26,6 +26,8 @@ class Character extends Phaser.Physics.Arcade.Sprite { // might make a dictionary this.attackList = Array(2).fill(-1) + // debugging + this.state = 'idle' this.projectile = new Projectile(scene, this.x + this.width/2, this.y - this.height/2, `${this.name}_projectile`, this) @@ -44,11 +46,14 @@ class Character extends Phaser.Physics.Arcade.Sprite { class IdleState extends State { // in this state the character may only enter the attack and hurt state enter (scene, character) { + character.state = 'idle' console.log(character.attackList) + // console.log(character.name + 'has entered the IDLE state') // player is not attacking in idle state character.clearTint() // player is not hurt character.hurt = false + console.log(character.name + ' is hurt?: ' + character.hurt) } execute(scene, character) { @@ -83,6 +88,7 @@ class AttackState extends State { enter (scene, character) { // remove the enemies health // scene.enemy.damaged = true + character.state = 'attack' character.mana -= 10 // change mana amt later scene.characters_mp[character.index].match(character.mana) @@ -114,6 +120,7 @@ class AttackState extends State { class HurtState extends State { enter (scene, character) { // scene.enemy.hasAttacked = false + character.state = 'hurt' character.hurt = true // character.anims.play(`${character.name}_hurt`, true) character.setTint(0xFF0000) @@ -132,7 +139,9 @@ class HurtState extends State { damage_txt.setVisible(false) this.attackText_below.setVisible(false) this.attackText.setVisible(false) + console.log("\n\n enemy attacked= " + scene.enemy.hasAttacked + '\n\n') if (character.health > 0 && scene.enemy.hasAttacked == false){ + console.log(`${character.name} has reached idle`) this.stateMachine.transition('idle') } // character.checkCollision.none = true @@ -159,6 +168,7 @@ class HurtState extends State { class CollapseState extends State { // the character will be knocked out in this state enter (scene, character) { + character.state = 'collapse' scene.selectionMenu.updateAvailable() character.anims.play(`${character.name}_collapse`, true) character.collapsed = true diff --git a/src/prefabs/Selection.js b/src/prefabs/Selection.js index 17b39dc..a9916d6 100644 --- a/src/prefabs/Selection.js +++ b/src/prefabs/Selection.js @@ -47,6 +47,7 @@ class SelectionMenu extends Phaser.GameObjects.Graphics{ // console.log('trying to select and the turn is ' + this.scene.player_turn + ' and we are allowed to select? ' + this.allowSelect) if (this.scene.player_turn == true && this.allowSelect == true){ this.availableChar = this.updateAvailable() + console.log(`THIS ${this.availableChar}\n\n`) if (this.current_selection == 0 ){ // if cursor on the power selection // Attack choice @@ -108,8 +109,9 @@ class SelectionMenu extends Phaser.GameObjects.Graphics{ // when character is changed auto set the current attack to 0 this.current_attack = 0 - console.log(this.availableChar) - console.log(this.current_player) + // console.log(this.availableChar) + // console.log(this.current_player) + // console.log(this.characters[this.availableChar[this.current_player]]) if (this.current_player >= this.availableChar.length){ this.current_player = 0 } @@ -120,6 +122,9 @@ class SelectionMenu extends Phaser.GameObjects.Graphics{ this.charChange(1) } this.charCursor.x = this.characters[this.availableChar[this.current_player]].x+ 15 + console.log(this.availableChar) + console.log(this.current_player) + console.log(this.characters[this.availableChar[this.current_player]]) this.charDisplay.text = this.characters[this.availableChar[this.current_player]].name this.powerDisplay.text = this.characters[this.availableChar[this.current_player]].attackList[this.current_attack] diff --git a/src/prefabs/Summon.js b/src/prefabs/Summon.js index 9a7f2bc..52bcfb7 100644 --- a/src/prefabs/Summon.js +++ b/src/prefabs/Summon.js @@ -14,13 +14,16 @@ class Summon extends Phaser.Physics.Arcade.Sprite { attack(){ // float up to a certain point and cast a projectile + this.y = centerY + this.projectile.y = this.y - this.height/2 this.summonUses -= 1 console.log("attack") // this.hasAttacked = true // for now remove - + if (this.y == centerY){ + this.projectile.move(this.scene.enemy) + } // attacking position: rightPos - tileSize * 3, centerY // move summon towards the position - this.projectile.move(this.scene.enemy) } } \ No newline at end of file diff --git a/src/scenes/Fighting.js b/src/scenes/Fighting.js index 0d6aac1..694b7ad 100644 --- a/src/scenes/Fighting.js +++ b/src/scenes/Fighting.js @@ -63,7 +63,7 @@ class Fighting extends Phaser.Scene { this.enemy_hp = new HealthBar(this, centerX, tileSize / 4, this.enemy) // enemy does not need mana - this.summon = new Summon(this, rightPos - tileSize * 3, centerY, 'nicole', 200).setOrigin(0,1) + this.summon = new Summon(this, rightPos - tileSize * 3, game.config.height + 100, 'nicole', 200).setOrigin(0,1) // setting up keyboard inputs @@ -113,6 +113,14 @@ class Fighting extends Phaser.Scene { } } if (!this.gameOver){ + // for debugging + console.log("enemy attacked=" + this.enemy.hasAttacked +', ' + this.characters[0].name + this.characters[0].state + ' , ' + this.characters[1].name + this.characters[1].state + ' , ' + this.characters[2].name + this.characters[2].state) + // console.log(this.characters[1].name + this.characters[1].state + ) + // console.log(this.characters[2].name + this.characters[2].state) + + + + if (!this.music_playing){ this.music.play() this.music_playing = true