Skip to content

Commit

Permalink
Fixing Projectiles and Files + Cleaning up Code
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlizeSerrano5 committed Mar 15, 2024
1 parent 5a3c9df commit 59ae83a
Show file tree
Hide file tree
Showing 25 changed files with 501 additions and 127 deletions.
File renamed without changes
File renamed without changes.
Binary file added assets/font/SkinnyFont.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/font/SkinnyFont.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><font><info face="SkinnyFont" size="72" bold="0" italic="0" charset="" unicode="1" stretchH="100" smooth="1" aa="1" padding="1,1,1,1" spacing="1,1"/><common lineHeight="72" base="54" scaleW="366" scaleH="369" pages="1" packed="0"/><pages><page id="0" file="Unnamed.png"/></pages><chars count="91"><char id="32" x="0" y="0" width="0" height="0" xoffset="0" yoffset="0" xadvance="41" page="0" chnl="15"/><!-- --><char id="33" x="346" y="144" width="20" height="47" xoffset="8" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- ! --><char id="34" x="315" y="21" width="30" height="20" xoffset="3" yoffset="4" xadvance="41" page="0" chnl="15"/><!-- " --><char id="35" x="245" y="235" width="34" height="42" xoffset="-1" yoffset="13" xadvance="41" page="0" chnl="15"/><!-- # --><char id="36" x="0" y="85" width="34" height="65" xoffset="-1" yoffset="-1" xadvance="41" page="0" chnl="15"/><!-- $ --><char id="37" x="245" y="278" width="34" height="38" xoffset="-1" yoffset="17" xadvance="41" page="0" chnl="15"/><!-- % --><char id="38" x="245" y="144" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- & --><char id="39" x="315" y="129" width="16" height="20" xoffset="3" yoffset="4" xadvance="41" page="0" chnl="15"/><!-- ' --><char id="40" x="346" y="192" width="20" height="47" xoffset="8" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- ( --><char id="41" x="346" y="240" width="20" height="47" xoffset="8" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- ) --><char id="42" x="0" y="53" width="38" height="24" xoffset="-1" yoffset="22" xadvance="41" page="0" chnl="15"/><!-- * --><char id="43" x="280" y="341" width="30" height="24" xoffset="3" yoffset="22" xadvance="41" page="0" chnl="15"/><!-- + --><char id="44" x="346" y="336" width="16" height="20" xoffset="8" yoffset="40" xadvance="41" page="0" chnl="15"/><!-- , --><char id="45" x="0" y="352" width="34" height="7" xoffset="-1" yoffset="30" xadvance="41" page="0" chnl="15"/><!-- - --><char id="46" x="39" y="355" width="12" height="11" xoffset="12" yoffset="44" xadvance="41" page="0" chnl="15"/><!-- . --><char id="47" x="245" y="317" width="34" height="38" xoffset="-1" yoffset="17" xadvance="41" page="0" chnl="15"/><!-- / --><char id="48" x="0" y="208" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- 0 --><char id="49" x="39" y="115" width="30" height="47" xoffset="3" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- 1 --><char id="50" x="0" y="256" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- 2 --><char id="51" x="0" y="304" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- 3 --><char id="52" x="70" y="0" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- 4 --><char id="53" x="70" y="48" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- 5 --><char id="54" x="70" y="96" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- 6 --><char id="55" x="70" y="144" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- 7 --><char id="56" x="70" y="192" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- 8 --><char id="57" x="70" y="240" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- 9 --><char id="58" x="315" y="198" width="12" height="34" xoffset="12" yoffset="17" xadvance="41" page="0" chnl="15"/><!-- : --><char id="59" x="315" y="90" width="16" height="38" xoffset="8" yoffset="17" xadvance="41" page="0" chnl="15"/><!-- ; --><char id="61" x="315" y="0" width="30" height="20" xoffset="3" yoffset="22" xadvance="41" page="0" chnl="15"/><!-- = --><char id="63" x="245" y="96" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- ? --><char id="64" x="245" y="192" width="34" height="42" xoffset="-1" yoffset="13" xadvance="41" page="0" chnl="15"/><!-- @ --><char id="65" x="140" y="48" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- A --><char id="66" x="140" y="96" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- B --><char id="67" x="140" y="144" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- C --><char id="68" x="140" y="192" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- D --><char id="69" x="140" y="240" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- E --><char id="70" x="140" y="288" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- F --><char id="71" x="175" y="0" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- G --><char id="72" x="175" y="48" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- H --><char id="73" x="346" y="96" width="20" height="47" xoffset="8" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- I --><char id="74" x="175" y="96" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- J --><char id="75" x="175" y="144" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- K --><char id="76" x="175" y="192" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- L --><char id="77" x="175" y="240" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- M --><char id="78" x="175" y="288" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- N --><char id="79" x="210" y="0" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- O --><char id="80" x="210" y="48" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- P --><char id="81" x="0" y="151" width="34" height="56" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- Q --><char id="82" x="210" y="96" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- R --><char id="83" x="210" y="144" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- S --><char id="84" x="39" y="211" width="30" height="47" xoffset="3" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- T --><char id="85" x="210" y="192" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- U --><char id="86" x="210" y="240" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- V --><char id="87" x="210" y="288" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- W --><char id="88" x="245" y="0" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- X --><char id="89" x="39" y="259" width="30" height="47" xoffset="3" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- Y --><char id="90" x="245" y="48" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- Z --><char id="91" x="346" y="288" width="20" height="47" xoffset="8" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- [ --><char id="93" x="315" y="42" width="20" height="47" xoffset="8" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- ] --><char id="94" x="280" y="272" width="34" height="20" xoffset="-1" yoffset="-1" xadvance="41" page="0" chnl="15"/><!-- ^ --><char id="95" x="0" y="78" width="38" height="6" xoffset="-1" yoffset="58" xadvance="41" page="0" chnl="15"/><!-- _ --><char id="97" x="70" y="336" width="34" height="33" xoffset="-1" yoffset="22" xadvance="41" page="0" chnl="15"/><!-- a --><char id="98" x="70" y="288" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- b --><char id="99" x="105" y="336" width="34" height="33" xoffset="-1" yoffset="22" xadvance="41" page="0" chnl="15"/><!-- c --><char id="100" x="105" y="0" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- d --><char id="101" x="140" y="336" width="34" height="33" xoffset="-1" yoffset="22" xadvance="41" page="0" chnl="15"/><!-- e --><char id="102" x="39" y="163" width="30" height="47" xoffset="3" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- f --><char id="103" x="105" y="48" width="34" height="47" xoffset="-1" yoffset="22" xadvance="41" page="0" chnl="15"/><!-- g --><char id="104" x="105" y="96" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- h --><char id="105" x="346" y="0" width="20" height="47" xoffset="8" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- i --><char id="106" x="39" y="53" width="30" height="61" xoffset="3" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- j --><char id="107" x="105" y="144" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- k --><char id="108" x="346" y="48" width="20" height="47" xoffset="8" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- l --><char id="109" x="175" y="336" width="34" height="33" xoffset="-1" yoffset="22" xadvance="41" page="0" chnl="15"/><!-- m --><char id="110" x="210" y="336" width="34" height="33" xoffset="-1" yoffset="22" xadvance="41" page="0" chnl="15"/><!-- n --><char id="111" x="280" y="0" width="34" height="33" xoffset="-1" yoffset="22" xadvance="41" page="0" chnl="15"/><!-- o --><char id="112" x="105" y="192" width="34" height="47" xoffset="-1" yoffset="22" xadvance="41" page="0" chnl="15"/><!-- p --><char id="113" x="105" y="240" width="34" height="47" xoffset="-1" yoffset="22" xadvance="41" page="0" chnl="15"/><!-- q --><char id="114" x="280" y="34" width="34" height="33" xoffset="-1" yoffset="22" xadvance="41" page="0" chnl="15"/><!-- r --><char id="115" x="280" y="68" width="34" height="33" xoffset="-1" yoffset="22" xadvance="41" page="0" chnl="15"/><!-- s --><char id="116" x="105" y="288" width="34" height="47" xoffset="-1" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- t --><char id="117" x="280" y="102" width="34" height="33" xoffset="-1" yoffset="22" xadvance="41" page="0" chnl="15"/><!-- u --><char id="118" x="280" y="136" width="34" height="33" xoffset="-1" yoffset="22" xadvance="41" page="0" chnl="15"/><!-- v --><char id="119" x="280" y="170" width="34" height="33" xoffset="-1" yoffset="22" xadvance="41" page="0" chnl="15"/><!-- w --><char id="120" x="280" y="204" width="34" height="33" xoffset="-1" yoffset="22" xadvance="41" page="0" chnl="15"/><!-- x --><char id="121" x="140" y="0" width="34" height="47" xoffset="-1" yoffset="22" xadvance="41" page="0" chnl="15"/><!-- y --><char id="122" x="280" y="238" width="34" height="33" xoffset="-1" yoffset="22" xadvance="41" page="0" chnl="15"/><!-- z --><char id="123" x="39" y="307" width="30" height="47" xoffset="3" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- { --><char id="124" x="315" y="150" width="12" height="47" xoffset="12" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- | --><char id="125" x="280" y="293" width="30" height="47" xoffset="3" yoffset="8" xadvance="41" page="0" chnl="15"/><!-- } --><char id="8470" x="0" y="0" width="69" height="52" xoffset="-1" yoffset="4" xadvance="69" page="0" chnl="15"/><!-- № --></chars></font>
File renamed without changes
File renamed without changes.
Binary file added 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.
49 changes: 43 additions & 6 deletions assets/json/dialog.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
[
{
"speaker": "gumball",
"dialog" : "poop",
"newSpeaker": "true"
}

[
{
"speaker" : "gumball",
"dialog" : "I've trapped us inside a video game.",
"newSpeaker" : "true"
},

{
"speaker" : "gumball",
"dialog" : "AWESOMEEE"
},
{
"speaker" : "darwin",
"dialog" : "Please tell me what has been going on.",
"newSpeaker" : "true"
},
{
"speaker" : "anais",
"dialog" : "A fowl curse has been released by Gumball.",
"newSpeaker": "true"
},
{
"speaker" : "darwin",
"dialog" : "You mean the gates of doom were opened by Gumball.",
"newSpeaker": "true"

},
{
"speaker" : "anais",
"dialog" : "The fabric of the universe was ripped apart by Gumball."
}
],
[
{
"speaker" : "darwin",
"dialog" : "Gumball has made quite a mess.",
"newSpeaker" : "true"
},
{
"speaker" : "darwin",
"dialog" : "Here is some healing ointment to help Gumball in the heat of battle."
}

]
]
Binary file added assets/mana_bar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
Binary file added assets/text_box.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
<script src = "./lib/StateMachine.js"></script>
<script src = "./src/prefabs/Selection.js"></script>
<script src = "./src/prefabs/Health.js"></script>
<script src = "./src/prefabs/Mana.js"></script>
<script src = "./src/prefabs/Projectile.js"></script>
<script src = "./src/prefabs/Character.js"></script>
<script src = "./src/prefabs/Enemy.js"></script>
<script src = "./src/scenes/Tutorial.js"></script>
<script src = "./src/scenes/Fighting.js"></script>
<script src = "./src/scenes/Menu.js"></script>
<script src = "./src/main.js"></script>
Expand Down
8 changes: 4 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ let config = {
physics: {
default: "arcade",
arcade: {
// debug: true,
debug: true,
// gravity not needed
// gravity: {
// x: 0,
// y: 0
// }
}
},
scene: [ Menu, Fighting]
scene: [ Menu, Tutorial, Fighting]

}

Expand All @@ -64,9 +64,9 @@ const floorY = game.config.height / 10 * 6
const leftPos = game.config.width / 5
const rightPos = game.config.width / 5 * 4
const HP = 999
const MP = 99
const MP = 50
const temp_timer = 400

// let cursors = null
let cursors = null


53 changes: 37 additions & 16 deletions src/prefabs/Character.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
class Character extends Phaser.GameObjects.Sprite {
class Character extends Phaser.Physics.Arcade.Sprite {
// poop
constructor(scene, x, y , texture, frame, health, mana, attack_dmg, name, power, 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
console.log('the y value is : ' + this.y)
// setting character properties
this.index = index
this.health = health
this.mana = mana
this.name = name // for prints
this.hurtTimer = temp_timer
this.power = power
// creating a boolean value to check if the current character has attacked

this.hurt = false
this.hasAttacked = false
// setting up fighting damage
this.attack_dmg = attack_dmg

// this.hurt = false
this.collapsed = false
// temporary check
this.check = ''
this.projectile = new Projectile(scene, this.x + this.width/2, this.y - this.height * 1.5, `${this.name}_projectile`, this)
this.projectile = new Projectile(scene, this.x + this.width/2, this.y - 5, `${this.name}_projectile`, this)

scene.FSM_holder[index] = new StateMachine('idle', {
idle: new IdleState(),
Expand All @@ -30,18 +33,16 @@ class Character extends Phaser.GameObjects.Sprite {
collapse: new CollapseState(),
},[scene, this])
}
// possible solution
resetAttack() {
this.hasAttacked = false
}

}

class IdleState extends State {
// in this state the character may only enter the attack and hurt state
enter (scene, character) {
// player is not attacking in idle state
scene.dmgToEnemy = 0
character.clearTint()
// player is not hurt
character.hurt = false

}
execute(scene, character) {
Expand All @@ -52,13 +53,25 @@ class IdleState extends State {
if (character.willAttack == true && !character.hasAttacked){
this.stateMachine.transition('attack')
}
// if the enemy is attacking
if(scene.enemy.hasAttacked && scene.enemy.selectedChar == character.index) { // test one character at a time
this.stateMachine.transition('hurt')
// if the enemy is attacking add a collider
if(scene.enemy.hasAttacked && scene.enemy.selectedChar == character.index) {
scene.physics.add.collider(scene.enemy.projectile, character, () => {
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
}
}, null, scene)
}






}
}

Expand All @@ -68,9 +81,11 @@ class AttackState extends State {
// remove the enemies health
// scene.enemy.damaged = true
scene.dmgToEnemy = character.attack_dmg
scene.selectionMenu.allowSelect = false
// console.log("selection allow is "+ scene.selectionMenu.allowSelect)
character.setTint(0xDB91EF)

character.projectile.move(scene.enemyX, scene.enemyY)
character.projectile.move(scene.enemy.x + scene.enemy.width, scene.enemyY - scene.enemy.height)

scene.time.delayedCall(character.hurtTimer, () => {

Expand All @@ -92,13 +107,16 @@ class AttackState extends State {

class HurtState extends State {
enter (scene, character) {
// scene.enemy.hasAttacked = false
character.hurt = true
// character.anims.play(`${character.name}_hurt`, true)
character.setTint(0xFF0000)
// decrease health and update bar
character.health -= scene.enemy.dmgToPlayer
console.log(scene.enemy.selectedChar + "selected CHARACTER")
scene.characters_hp[scene.enemy.selectedChar].match(character.health)
let damage_txt = scene.add.bitmapText(character.x, character.y - tileSize*1.5, 'font', -scene.enemy.dmgToPlayer, 8).setOrigin(0, 0).setTint(0xFF0000)

scene.changeTurn()
this.attackText_below = scene.add.bitmapText(centerX, centerY+1, 'font', `${character.name} takes ${-scene.enemy.dmgToPlayer} damage`, 12).setOrigin(0.5).setTint(0x1a1200)
this.attackText = scene.add.bitmapText(centerX, centerY, 'font', `${character.name} takes ${-scene.enemy.dmgToPlayer} damage`, 12).setOrigin(0.5)
if (character.health > 0){
Expand All @@ -108,13 +126,15 @@ class HurtState extends State {
damage_txt.setVisible(false)
this.attackText_below.setVisible(false)
this.attackText.setVisible(false)

scene.enemy.selectedChar = -1
if (character.health > 0){

this.stateMachine.transition('idle')
}

})
}

console.log('HURT')

}
Expand All @@ -123,6 +143,7 @@ class HurtState extends State {
// if health depleted after hurt animation collapse this character
this.stateMachine.transition('collapse')
character.once('animationcomplete', () => {

this.stateMachine.transition('collapse')
})
}
Expand Down
Loading

0 comments on commit 59ae83a

Please sign in to comment.