Hello! One of the goals is to get 22/22 arrows shot at the munchkins, it was going well but for some reason it randomly just stopped. The next goal was to get at least 50 munchkins, but it wouldn’t let me continue. here’s my code, thanks a lot!! >:)
// Destroy at least 50 defeated ogres.
// This spawns and configures an archer.
function spawnArcher(x, y) {
var archer = game.spawnXY("archer", x, y);
archer.behavior = "Defends";
archer.attackDamage = 1000000000000;
}
// This spawns and configures an ogre.
function spawnMunchkin(x, y) {
var ogre = game.spawnXY("munchkin", x, y);
ogre.behavior = "AttacksNearest";
}
// Spawns some archers in a row.
function spawnArcherWall() {
spawnArcher(30, 12);
spawnArcher(30, 23);
spawnArcher(30, 34);
spawnArcher(30, 45);
spawnArcher(30, 56);
}
// Spawns an ogre wave with a random offset for variety.
function spawnOgreWave() {
var offset = game.randomInteger(-6, 6);
spawnMunchkin(80, 16 + offset);
spawnMunchkin(80, 22 + offset);
spawnMunchkin(80, 28 + offset);
spawnMunchkin(80, 34 + offset);
spawnMunchkin(80, 40 + offset);
spawnMunchkin(80, 46 + offset);
spawnMunchkin(80, 52 + offset);
}
function onDefeat(event) {
var unit = event.target;
// Increase the game.defeated counter by 1.
game.defeated += 1;
// Use unit.destroy() to destroy it.
unit.destroy();
}
// Set "munchkin"s "defeat" event handlers to onDefeat.
game.setActionFor("munchkin", "defeat", onDefeat);
game.defeated = 0;
game.spawnTime = 0;
// Add a manual goal.
var goal = game.addManualGoal("Defeat 77 ogres.");
ui.track(game, "defeated");
function checkSpawnTimer() {
if (game.time > game.spawnTime) {
spawnOgreWave();
game.spawnTime += 1;
}
}
function checkGoal() {
// If the game.defeated counter is greater than 77:
if (game.defeated > 7) {
game.setGoalState(goal, true);
}
// Set the goal as successfully completed.
}
spawnArcherWall();
while (true) {
checkSpawnTimer();
checkGoal();
}
Thanks!! -Amira