Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Game Dev 2 Final Project[SOLVED]

Here is my code

var gen1 = game.spawnXY("generator", 6, 6);
gen1.spawnType = "munchkin";
gen1.spawnDelay = 5;
var gen2 = game.spawnXY("generator", 6, 14);
gen2.spawnType = "munchkin";
gen2.spawnDelay = 15;
var gen3 = game.spawnXY("generator", 6, 22);
gen3.spawnType = "munchkin";
gen3.spawnDelay = 15;
var gen4 = game.spawnXY("generator", 6, 30);
gen4.spawnType = "munchkin";
gen4.spawnDelay = 15;
var gen5 = game.spawnXY("generator", 6, 38);
gen5.spawnType = "munchkin";
gen5.spawnDelay = 15;
var gen6 = game.spawnXY("generator", 6, 46);
gen6.spawnType = "munchkin";
gen6.spawnDelay = 15;
var gen7 = game.spawnXY("generator", 6, 54);
gen7.spawnType = "munchkin";
gen7.spawnDelay = 15;
var gen8 = game.spawnXY("generator", 10, 62);
gen8.spawnType = "munchkin";
gen8.spawnDelay = 15;
var gen9 = game.spawnXY("generator", 17, 62);
gen9.spawnType = "munchkin";
gen9.spawnDelay = 15;
var gen10 = game.spawnXY("generator", 24, 62);
gen10.spawnType = "munchkin";
gen10.spawnDelay = 15;
var gen11 = game.spawnXY("generator", 31, 62);
gen11.spawnType = "munchkin";
gen11.spawnDelay = 15;
var gen12 = game.spawnXY("generator", 38, 62);
gen12.spawnType = "munchkin";
gen12.spawnDelay = 15;
var gen13 = game.spawnXY("generator", 45, 62);
gen13.spawnType = "munchkin";
gen13.spawnDelay = 15;
var gen14 = game.spawnXY("generator", 52, 62);
gen14.spawnType = "munchkin";
gen14.spawnDelay = 5;
gen1.maxHealth = 10000000;
gen2.maxHealth = 10000000;
gen3.maxHealth = 10000000;
gen4.maxHealth = 10000000;
gen5.maxHealth = 10000000;
gen6.maxHealth = 10000000;
gen7.maxHealth = 10000000;
gen8.maxHealth = 10000000;
gen9.maxHealth = 10000000;
gen10.maxHealth = 10000000;
gen11.maxHealth = 10000000;
gen12.maxHealth = 10000000;
gen13.maxHealth = 10000000;
gen14.maxHealth = 10000000;
var player = game.spawnPlayerXY("knight", 40, 34);
player.attackDamage = 10;
player.maxHealth = 300;
player.maxSpeed = 10;
ui.track(game, "time");
ui.track(game, "defeated");
ui.track(game, "bestTime");
ui.track(game, "mostDefeated");
game.bestTime = db.get("bestTime") || 0;
game.mostDefeated = db.get("mostDefeated") || 0;
var someGoal = game.addManualGoal("See how long you can last in Cave Clash");
ui.setText("levelName", "Cave Clash");
ui.setText("victoryMessage", "CONGRATS YOU BEAT CAVE CLASH");
ui.setText("directions", "Use W A S D or LEFT CLICK to move");
ui.setText("directions", "LEFT CLICK on enemies to attack them or press SPACEBAR to unleash a powerful cleave");
player.on("defeat", playerDef);
function playerDef() {
    var bestTime = db.get("bestTime") || 0;
    if (game.time > bestTime) {
        db.set("bestTime", game.time);
    }
    var mostDefeated = db.get("mostDefeated") || 0;
    if (game.defeated > mostDefeated) {
        db.set("mostDefeated", game.defeated);
    }
    game.setGoalState(someGoal, true);
}

My problem is here

ui.track(game, "defeated");

when I kill the munchkins this doesn’t track it please help me.

Howdy and welcome to the forum!

I did a quick tour of your code and didn’t see where you’ve defined defeated, or are updating it. I’m not that savvy with game development, but I think you need to add a ‘game.defeated = 0’ to initialize the counter, then a game.setActionFor(killing the munchkins) and finally, a definition for onDefeat(event), which is where you increment the counter.

1 Like

I will try doing this

It worked thank you very much

1 Like