Skip to content

Commit

Permalink
Found Game Breaking Bug Trying to Fix it
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlizeSerrano5 committed Mar 15, 2024
1 parent 6ab5321 commit 3dff610
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/prefabs/Character.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/prefabs/Selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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]
Expand Down
7 changes: 5 additions & 2 deletions src/prefabs/Summon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
10 changes: 9 additions & 1 deletion src/scenes/Fighting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3dff610

Please sign in to comment.