Hello guys!
When I use this ability my hero just gets bigger and does nothing.
Is it right behavior for this spell (hero.powerUp)?
I don’t understand what’s the point?
Video
Code:
function attackEnemy(enemy) {
if (enemy && enemy.health > 0) {
if (hero.isReady("jump") && hero.distanceTo(enemy) > 5) {
hero.jumpTo(enemy);
} else if (hero.isReady("punch")) {
hero.punch(enemy);
} else if (!hero.hasEffect("power-up") && hero.isReady("power-up")) {
console.log('HeroDebug', hero.isReady("power-up"));
console.log('HeroAttackDamage', hero.attackDamage);
hero.powerUp();
hero.attack(enemy);
console.log('HeroAttackDamage', hero.attackDamage);
} else if (enemy && enemy.health > 0) {
hero.attack(enemy);
}
}
}
let isFirstChallengeComplete = false;
let firstPoint = {
x: 115,
y: 24
};
while (!isFirstChallengeComplete) {
var enemy = hero.findNearestEnemy();
if (enemy && hero.distanceTo(enemy) < 50) {
attackEnemy(enemy);
} else {
if (hero.pos.x === firstPoint.x && hero.pos.y === firstPoint.y) {
isFirstChallengeComplete = true;
} else {
hero.move(firstPoint);
}
}
}
hero.say("End of the program!");
There was a topic Sword powerUp() ability question with the original name Sword powerUp() ability compromized
The proper use of it is:
if (!hero.hasEffect("power-up") && hero.isReady("power-up"))
hero.powerUp();
else hero.attack(enemy); // test without else - I think you will receive more damage
I think your code doesn’t work because hero.punch(enemy) and hero.powerUp() don’t work when used one after the other. So the function will be:
function attackEnemy(enemy) {
if (enemy && enemy.health > 0) {
if (hero.isReady("jump") && hero.distanceTo(enemy) > 5)
hero.jumpTo(enemy);
else if (!hero.hasEffect("power-up") && hero.isReady("power-up"))
hero.powerUp();
else if (enemy && enemy.health > 0)
hero.attack(enemy);
}
}
You’ll complete the level a bit quicker without the powerUp , the damage you’ll receive is a toss and situational.
Tested first PoweUp and then Punch, it works somehow
function attackEnemy(enemy) {
if (enemy && enemy.health > 0) {
if (hero.isReady("jump") && hero.distanceTo(enemy) > 5)
hero.jumpTo(enemy);
else if (!hero.hasEffect("power-up") && hero.isReady("power-up"))
hero.powerUp();
else if (hero.isReady("punch"))
hero.punch(enemy);
else if (enemy && enemy.health > 0)
hero.attack(enemy);
}
}
but the hero dies.
I’m curious if we replace Punch with Chain Lightning but didn’t test it
Welcome to the CoCo Discourse, @Geralld! Here, you can ask for Level Help(though don’t ask for complete answers), report bugs(just like this one), paste Baby Yoda memes, and more! Make sure to review this topic
Thanks for the clarification! Now it works, BUT…
the result much worse than without powerUp ability
I’m a little confused: in what case would the use of this skill be useful?
If the hero is surrounded by many enemies to reduce the damage taken?
function attackEnemy(enemy) {
if (enemy && enemy.health > 0) {
if (hero.isReady("jump") && hero.distanceTo(enemy) > 5) {
hero.jumpTo(enemy);
} else if (!hero.hasEffect("power-up") && hero.isReady("power-up")) {
hero.powerUp();
} else if (hero.isReady("punch")) {
hero.punch(enemy);
} else {
hero.attack(enemy);
}
}
}