Skip to content

Commit

Permalink
Testing a Melee Attack with Test Animation on Gumball + Creating a Di…
Browse files Browse the repository at this point in the history
…ctionary of Attacks for Characters
  • Loading branch information
CharlizeSerrano5 committed Mar 16, 2024
1 parent 668df62 commit 90dd64b
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 64 deletions.
Binary file added assets/darwin_talking.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/gumball_spritesheet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/gumball_talking.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 71 additions & 24 deletions src/prefabs/Character.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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', {
Expand All @@ -38,14 +38,21 @@ 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]
}

}


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()
Expand Down Expand Up @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/prefabs/Enemy.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,4 @@ class DefeatState extends State {
execute(scene, enemy) {

}
}
}
48 changes: 35 additions & 13 deletions src/prefabs/Selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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)

}

Expand All @@ -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]
}

}
}
62 changes: 37 additions & 25 deletions src/scenes/Fighting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/scenes/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 90dd64b

Please sign in to comment.