diff --git a/assets/darwin_talking.png b/assets/darwin_talking.png new file mode 100644 index 0000000..537326b Binary files /dev/null and b/assets/darwin_talking.png differ diff --git a/assets/gumball_spritesheet.png b/assets/gumball_spritesheet.png index 8dec818..59086a7 100644 Binary files a/assets/gumball_spritesheet.png and b/assets/gumball_spritesheet.png differ diff --git a/assets/gumball_talking.png b/assets/gumball_talking.png index 2172077..d64b68b 100644 Binary files a/assets/gumball_talking.png and b/assets/gumball_talking.png differ diff --git a/src/prefabs/Character.js b/src/prefabs/Character.js index 5077212..55b246f 100644 --- a/src/prefabs/Character.js +++ b/src/prefabs/Character.js @@ -1,12 +1,11 @@ class Character extends Phaser.Physics.Arcade.Sprite { - // poop constructor(scene, x, y , texture, frame, health, mana, attack_dmg, name, power, type, index) { super(scene, x, y, texture) scene.add.existing(this) scene.physics.add.existing(this) this.body.setImmovable(true) - this.x = x - this.y = y + this.startX = x + this.startY = y // setting character properties this.index = index this.health = health @@ -22,12 +21,13 @@ class Character extends Phaser.Physics.Arcade.Sprite { this.collapsed = false // creating an array of attacks - this.attackList = Array(2).fill(-1) // Note: might make a dictionary - + // this.attackList = Array(2).fill(-1) // Note: might make a dictionary + this.attackList = {} + this.selectedAttack = 0 + // debugging this.state = 'idle' - - + this.projectile = new Projectile(scene, this.x + this.width/2, this.y - this.height/2, `${this.name}_projectile`, this) scene.FSM_holder[index] = new StateMachine('idle', { @@ -38,6 +38,13 @@ class Character extends Phaser.Physics.Arcade.Sprite { },[scene, this]) } + addAttack(name, power, mana_cost, type = 0) { + // this.attackList[Object.keys(this.attackList).length] = [name, power, mana_cost] + + // type 0 = physical, type 1 = mana + this.attackList[name] = [power, mana_cost, type] + } + } @@ -45,7 +52,7 @@ 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.attackList) // console.log(character.name + 'has entered the IDLE state') // player is not attacking in idle state character.clearTint() @@ -85,37 +92,77 @@ class AttackState extends State { // character will play a temporary attack animation where they throw their character specific attack enter (scene, character) { // remove the enemies health - console.log(scene.selectionMenu.current_attack) - if (scene.selectionMenu.current_attack == 1){ - // if you have selected a magic attack then play the magic attack - character.mana -= 10 - scene.characters_mp[character.index].match(character.mana) - - } - character.state = 'attack' - + // character.state = 'attack' + console.log("current attack: " + character.selectedAttack) + // if (scene.selectionMenu.current_attack == 1){ + // // if you have selected a magic attack then play the magic attack + // character.mana -= 10 + // scene.characters_mp[character.index].match(character.mana) + + // } + + // console.log("MANA COST: " + Object.entries(character.attackList)[scene.selectionMenu.current_attack][1][1]) + // character.mana -= Object.entries(character.attackList)[scene.selectionMenu.current_attack][1][1] + console.log("MANA COST: " + Object.entries(character.attackList)[character.selectedAttack][1][1]) + character.mana -= Object.entries(character.attackList)[character.selectedAttack][1][1] + scene.characters_mp[character.index].match(character.mana) - scene.dmgToEnemy = character.attack_dmg + // scene.dmgToEnemy = character.attack_dmg + // console.log("DAMAGE: " + Object.entries(character.attackList)[scene.selectionMenu.current_attack][1][0]) + // scene.dmgToEnemy = Object.entries(character.attackList)[scene.selectionMenu.current_attack][1][0] + console.log("DAMAGE: " + Object.entries(character.attackList)[character.selectedAttack][1][0]) + scene.dmgToEnemy = Object.entries(character.attackList)[character.selectedAttack][1][0] + scene.selectionMenu.allowSelect = false // console.log("selection allow is "+ scene.selectionMenu.allowSelect) character.setTint(0xDB91EF) + - character.projectile.move(scene.enemy) + console.log(Object.entries(character.attackList)[character.selectedAttack][1][2] == 0) + if (Object.entries(character.attackList)[character.selectedAttack][1][2] == 0) { + character.body.setVelocityX(scene.enemy.x - character.x) + this.collision = false; + } + else { + character.projectile.move(scene.enemy) + } - scene.time.delayedCall(character.hurtTimer, () => { - character.willAttack = false - character.hasAttacked = true - }) + // scene.time.delayedCall(character.hurtTimer, () => { + // character.willAttack = false + // character.hasAttacked = true + // }) } execute(scene, character) { // reset to idle - if (character.hasAttacked == true){ + if (character.hasAttacked == true && character.x >= character.startX){ + character.body.setVelocityX(0) scene.selectionMenu.charChange(0) // character.projectile.reset(character.x) this.stateMachine.transition('idle') } + + scene.physics.add.collider(character, scene.enemy, () => { + // let collision = scene.enemy.projectile.handleCollision(character, scene.dmgToEnemy) + // if ( collision == true){ + // // reset that projectile once the collision is true + // console.log('collision was true') + // scene.enemy.projectile.resetProj(scene.enemy.projectile.startX, scene.enemy.projectile.startY) + // this.stateMachine.transition('hurt') + // // is entered + // } + if (this.collision == false) { + character.body.setVelocityX(0) + this.collision = true; + } + character.anims.play(`${character.name}_melee`, true) + character.once('animationcomplete', () => { + character.willAttack = false + character.hasAttacked = true + character.setVelocityX(-1 * (scene.enemy.x - character.x)) + }) + }, null, scene) } } diff --git a/src/prefabs/Enemy.js b/src/prefabs/Enemy.js index 0768dbc..7659324 100644 --- a/src/prefabs/Enemy.js +++ b/src/prefabs/Enemy.js @@ -191,4 +191,4 @@ class DefeatState extends State { execute(scene, enemy) { } -} \ No newline at end of file +} diff --git a/src/prefabs/Selection.js b/src/prefabs/Selection.js index a9916d6..08ee908 100644 --- a/src/prefabs/Selection.js +++ b/src/prefabs/Selection.js @@ -23,7 +23,8 @@ class SelectionMenu extends Phaser.GameObjects.Graphics{ this.cursorImage = scene.add.image(x + -36, y + this.cursor_pos, 'cursor').setOrigin(0.5, 0) this.charDisplay = scene.add.bitmapText(x + -28, y + -20, 'font', this.characters[this.current_player].name, 8) this.item = scene.add.bitmapText(x + -28, y + -8, 'font', "PHONE", 8) - this.powerDisplay = scene.add.bitmapText( x + -28, y + 4, 'font', this.characters[this.current_player].attackList[this.current_attack], 8) + // this.powerDisplay = scene.add.bitmapText( x + -28, y + 4, 'font', this.characters[this.current_player].attackList[this.current_attack], 8) + this.powerDisplay = scene.add.bitmapText( x + -28, y + 4, 'font', Object.entries(this.characters[this.current_player].attackList)[this.current_attack][0], 8) this.selections = [ this.powerDisplay, this.item, this.charDisplay ] this.selections[this.current_selection].setTint(0xDFFF00); this.availableChar = this.scene.checkActive() @@ -53,9 +54,26 @@ class SelectionMenu extends Phaser.GameObjects.Graphics{ // Attack choice if ( this.characters[this.availableChar[this.current_player]].collapsed == false && !this.characters[this.availableChar[this.current_player]].hasAttacked){ // NOTE: check if character has died - this.characters[this.availableChar[this.current_player]].willAttack = true - this.attackingPlayer =this.characters[this.availableChar[this.current_player]] - this.charChange(0); + // if (this.current_attack == 1) { + // if (this.characters[this.availableChar[this.current_player]].mana > ) { + + // } + // } + + if (this.characters[this.availableChar[this.current_player]].mana >= Object.entries(this.characters[this.availableChar[this.current_player]].attackList)[this.current_attack][1][1]) { + this.characters[this.availableChar[this.current_player]].willAttack = true + this.characters[this.availableChar[this.current_player]].selectedAttack = this.current_attack + this.attackingPlayer = this.characters[this.availableChar[this.current_player]] + this.allowSelect = false + this.charChange(0) + } + else { + return + } + + // this.characters[this.availableChar[this.current_player]].willAttack = true + // this.attackingPlayer =this.characters[this.availableChar[this.current_player]] + // this.charChange(0); } } if (this.current_selection == 1 && !this.scene.summon.hasAttacked && this.scene.summon.summonUses && this.availableChar.length == 3){ @@ -122,12 +140,15 @@ 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]]) + // 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] + // this.powerDisplay.text = this.characters[this.availableChar[this.current_player]].attackList[this.current_attack] + this.powerDisplay.text = Object.entries(this.characters[this.availableChar[this.current_player]].attackList)[this.current_attack][0] + + // this.attackChange(0) } @@ -136,14 +157,15 @@ class SelectionMenu extends Phaser.GameObjects.Graphics{ // manuever through the selected characters attacks console.log(input) this.current_attack += input - if (this.current_attack >= this.characters[this.availableChar[this.current_player]].attackList.length){ + if (this.current_attack >= Object.entries(this.characters[this.availableChar[this.current_player]].attackList).length){ this.current_attack = 0 } else if (this.current_attack < 0){ - this.current_attack = this.characters[this.availableChar[this.current_player]].attackList.length - 1 + this.current_attack = Object.entries(this.characters[this.availableChar[this.current_player]].attackList).length - 1 } - console.log('current attack' + this.current_attack) - this.powerDisplay.text = this.characters[this.availableChar[this.current_player]].attackList[this.current_attack] + // console.log('current attack' + this.current_attack) + console.log('current attack: ' + Object.entries(this.characters[this.availableChar[this.current_player]].attackList)[this.current_attack][0]) + this.powerDisplay.text = Object.entries(this.characters[this.availableChar[this.current_player]].attackList)[this.current_attack][0] } -} \ No newline at end of file +} diff --git a/src/scenes/Fighting.js b/src/scenes/Fighting.js index 783dcdd..48eb0c4 100644 --- a/src/scenes/Fighting.js +++ b/src/scenes/Fighting.js @@ -36,13 +36,21 @@ class Fighting extends Phaser.Scene { // adding a character to scene - each character should have their own HP this.gumball = new Character(this, rightPos-tileSize, floorY + tileSize /1.5, 'gumball', 0, this.hp, MP, 30, 'GUMBALL', 'MAGIC', 'physical', 0).setOrigin(0,1) - this.gumball.attackList = [ 'SCRATCH', 'MAGIC'] + // this.gumball.attackList = [ 'SCRATCH', 'MAGIC'] + this.gumball.addAttack("SCRATCH", 120, 0); + this.gumball.addAttack("MAGIC", 50, 10, 1); + console.log(Object.entries(this.gumball.attackList)) this.anais = new Character(this, rightPos, floorY +tileSize / 1.5, 'anais', 0, this.hp, MP, 50, 'ANAIS', 'SCIENCE', 'mage', 1).setOrigin(0,1) - this.anais.attackList = [ 'PUNCH', 'SCIENCE' ] + // this.anais.attackList = [ 'PUNCH', 'SCIENCE' ] + this.anais.addAttack("PUNCH", 25, 0); + this.anais.addAttack("SCIENCE", 200, 25, 1); this.darwin = new Character(this, rightPos + tileSize, floorY + tileSize / 1.5, 'darwin', 0, this.hp, MP, 10, 'DARWIN', 'SUPPORT', 'mage', 2).setOrigin(0,1) - this.darwin.attackList = [ 'SLAP', 'SUPPORT' ] + // this.darwin.attackList = [ 'SLAP', 'SUPPORT' ] + this.darwin.addAttack("SLAP", 40, 0); + this.darwin.addAttack("SUPPORT", 40, 15, 1); + // adding each character health this.gumball_hp = new HealthBar(this, centerX, floorY + tileSize, this.gumball, 0) this.gumball_mp = new ManaBar(this, centerX + tileSize * 3 + 12, floorY + tileSize, this.gumball, 0) @@ -129,32 +137,36 @@ class Fighting extends Phaser.Scene { this.FSM_holder[2].step() this.enemyFSM.step() - if (Phaser.Input.Keyboard.JustDown(space)){ - this.selectionMenu.select() - } - if (this.selectionMenu.current_selection == 0){ - if (Phaser.Input.Keyboard.JustDown(right)){ - this.selectionMenu.attackChange(1) + // console.log(this.selectionMenu.allowSelect) + + if (this.selectionMenu.allowSelect) { + if (Phaser.Input.Keyboard.JustDown(space)){ + this.selectionMenu.select() } - if (Phaser.Input.Keyboard.JustDown(left)){ - this.selectionMenu.attackChange(-1) + if (this.selectionMenu.current_selection == 0){ + if (Phaser.Input.Keyboard.JustDown(right)){ + this.selectionMenu.attackChange(1) + } + if (Phaser.Input.Keyboard.JustDown(left)){ + this.selectionMenu.attackChange(-1) + } } - } - - if (this.selectionMenu.current_selection == 2){ - if (Phaser.Input.Keyboard.JustDown(right)){ - this.selectionMenu.charChange(1) + + if (this.selectionMenu.current_selection == 2){ + if (Phaser.Input.Keyboard.JustDown(right)){ + this.selectionMenu.charChange(1) + } + if (Phaser.Input.Keyboard.JustDown(left)){ + this.selectionMenu.charChange(-1) + } } - if (Phaser.Input.Keyboard.JustDown(left)){ - this.selectionMenu.charChange(-1) + + if (Phaser.Input.Keyboard.JustDown(up)){ + this.selectionMenu.lookChoice(1) + } + if (Phaser.Input.Keyboard.JustDown(down)){ + this.selectionMenu.lookChoice(-1) } - } - - if (Phaser.Input.Keyboard.JustDown(up)){ - this.selectionMenu.lookChoice(1) - } - if (Phaser.Input.Keyboard.JustDown(down)){ - this.selectionMenu.lookChoice(-1) } } } diff --git a/src/scenes/Menu.js b/src/scenes/Menu.js index 513e56e..66639dc 100644 --- a/src/scenes/Menu.js +++ b/src/scenes/Menu.js @@ -33,7 +33,7 @@ class Menu extends Phaser.Scene{ //setting up character sprite sheet this.load.spritesheet('gumball', 'gumball_spritesheet.png', { - frameWidth: 30, + frameWidth: 38, frameHeight: 42 }) @@ -47,6 +47,8 @@ class Menu extends Phaser.Scene{ frameWidth: 46, frameHeight: 35 }) + this.load.image('darwin_talk', 'darwin_talking.png') + this.load.spritesheet('penny', 'penny_spritesheet.png', { frameWidth: 43, frameHeight: 60 @@ -95,6 +97,12 @@ class Menu extends Phaser.Scene{ repeat: -1, frames: this.anims.generateFrameNumbers('gumball', { start: 0, end: 7}), }) + this.anims.create({ + key: 'GUMBALL_melee', + frameRate: 8, + repeat: -1, + frames: this.anims.generateFrameNumbers('gumball', { start: 8, end: 15}), + }) this.anims.create({ key: 'GUMBALL_collapse', frameRate: 8,