8000 Fix Game Bug Issues that were found on Debugging · rsnazario/capstone-js-phaser-rpg@fca70fa · GitHub
[go: up one dir, main page]

Skip to content

Commit fca70fa

Browse files
committed
Fix Game Bug Issues that were found on Debugging
1 parent 8a779d6 commit fca70fa

File tree

6 files changed

+41
-25
lines changed

6 files changed

+41
-25
lines changed

dist/main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ var config = {
2727
]
2828
};
2929

30-
var game = new Phaser.Game(config);
30+
var game = new Phaser.Game(config);
31+
32+
window.score = 0;

src/js/battle.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default class BattleScene extends Phaser.Scene {
1010
// change backgroundColor\
1111
this.warriorHP = 130;
1212
this.mageHP = 80;
13+
this.score = 0;
1314
this.cameras.main.setBackgroundColor('rgba(0, 200, 0, 0.5)');
1415
this.startBattle();
1516
this.sys.events.on('wake', this.startBattle, this);
@@ -37,18 +38,11 @@ export default class BattleScene extends Phaser.Scene {
3738

3839
startBattle() {
3940
// player character ==> warrior
40-
var warriorFactor = 1;
41-
if (this.warriorHP < 40)
42-
warriorFactor = 2;
43-
44-
var warrior = new PlayerCharacter(this, 250, 50, 'player', 1, 'Warrior', this.warriorHP, 10 * warriorFactor);
41+
var warrior = new PlayerCharacter(this, 250, 50, 'player', 1, 'Warrior', this.warriorHP, 10);
4542
this.add.existing(warrior);
4643

47-
var mageFactor = 1;
48-
if (this.mageHP < 25)
49-
mageFactor = 2;
5044
// player character ==> mage
51-
var mage = new PlayerCharacter(this, 250, 100, 'player', 4, 'Mage', this.mageHP, 20 * mageFactor);
45+
var mage = new PlayerCharacter(this, 250, 100, 'player', 4, 'Mage', this.mageHP, 20);
5246
this.add.existing(mage);
5347

5448
this.enemies = this.generateRandomEnemies();
@@ -63,6 +57,10 @@ export default class BattleScene extends Phaser.Scene {
6357
}
6458

6559
nextTurn() {
60+
61+
console.log('warrior HP: ' + this.heroes[0].hp);
62+
console.log('mage hp: ' +this.heroes[1].hp);
63+
6664
if (this.checkEndBattle()) {
6765
this.endBattle();
6866
return;
@@ -126,15 +124,21 @@ export default class BattleScene extends Phaser.Scene {
126124
}
127125

128126
endBattle() {
129-
this.warriorHP = this.heroes[0].hp + 12;
130-
this.mageHP = this.heroes[1].hp + 12;
131127

132-
if (this.warriorHP > this.heroes[0].maxHP)
133-
this.warriorHP = this.heroes[0].maxHP;
128+
if (this.warriorHP > 0 ) {
129+
this.warriorHP = this.heroes[0].hp + 12;
130+
}
131+
if (this.mageHP > 0) {
132+
this.mageHP = this.heroes[1].hp + 12;
133+
}
134134

135-
if (this.mageHP > this.heroes[1].maxHP)
135+
if (this.warriorHP > this.heroes[0].maxHP) {
136+
this.warriorHP = this.heroes[0].maxHP;
137+
}
138+
if (this.mageHP > this.heroes[1].maxHP) {
136139
this.mageHP = this.heroes[1].maxHP;
137-
140+
}
141+
138142
this.heroes.length = 0;
139143
this.enemies.length = 0;
140144
for (var i = 0; i < this.units.length; i++) {

src/js/menu.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ export default class Menu extends Phaser.GameObjects.Container {
6868
this.selected = false;
6969
}
7070

71-
confirm() {
72-
73-
}
74-
75-
//
7671
clear() {
7772
for (var i = 0; i < this.menuItems.length; i++) {
7873
this.menuItems[i].destroy();

src/js/menuItem.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default class MenuItem extends Phaser.GameObjects.Text {
1212
}
1313

1414
unitKilled() {
15+
window.score += 10;
1516
this.active = false;
1617
this.visible = false;
1718
}

src/js/unit.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ export default class Unit extends Phaser.GameObjects.Sprite {
22
constructor(scene, x, y, texture, frame, type, hp, damage, scale) {
33
super(scene, x, y, texture, frame);
44
this.type = type;
5-
this.maxHP = this.hp = hp;
5+
if (type === 'Warrior') {
6+
this.maxHP = 130;
7+
}
8+
if (type === 'Mage') {
9+
this.maxHP = 80;
10+
}
11+
12+
this.hp = hp;
613
this.damage = damage; // default damage
714
this.setScale(scale);
815

@@ -15,8 +22,15 @@ export default class Unit extends Phaser.GameObjects.Sprite {
1522
}
1623

1724
attack(target) {
18-
target.takeDamage(this.damage);
19-
this.scene.events.emit('Message', this.type + ' Attacks ' + target.type + ' for ' + this.damage + ' damage');
25+
if ((this.hp <= 40) && (this.type === 'Warrior' || this.type === 'Mage')) {
26+
target.takeDamage(this.damage * 2);
27+
this.scene.events.emit('Message', this.type + ' Attacks ' + target.type + ' for ' + this.damage*2 + ' damage');
28+
}
29+
else {
30+
target.takeDamage(this.damage);
31+
this.scene.events.emit('Message', this.type + ' Attacks ' + target.type + ' for ' + this.damage + ' damage');
32+
}
33+
2034
};
2135

2236
takeDamage(damage) {

0 commit comments

Comments
 (0)
0