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

Can sb pls explain how to make the hero move? @01CODER @dedreous The hero doesn’t move after clicking and WASD doesn’t work

While playing the level you click with the mouse. If you want to do it in code just define your hero as a variable, then command it to move with moveXY.
Danny

In the game devs, you click where you want to go on the map. If that spot is an enemy, the player will attack, if it is an item, he will interact with it…otherwise, he’ll move to the spot you clicked.

and, what Danny said :grin:

1 Like

ok I’ll try moving XY thx

But he doesn’t move to the spot clicked when clicked

This could be a separate error, please could you post your code.
Danny


// Fence 1
game.spawnXY("fence", 6, 58);
game.spawnXY("fence", 11, 58);
game.spawnXY("fence", 16, 58);
game.spawnXY("fence", 21, 58);
game.spawnXY("fence", 26, 58);

// Fence 2
game.spawnXY("fence", 6, 45);
game.spawnXY("fence", 11, 45);
game.spawnXY("fence", 16, 45);
game.spawnXY("fence", 56, 45);
game.spawnXY("fence", 56, 50);



// Spawn a player with spawnPlayerXY()
var player = game.spawnXY("knight", 23, 37);
player.maxHealth = 2500000;
player.attackDamage = 2000;
player.moveXY(52, 34);

// Add at least one goal!
game.addSurviveGoal(5);

// Spawn objects into the game with spawnXY()
game.spawnXY("fence", 36, 30);

@Deadpool198

The goal is to survive 5 seconds. The error i get is that I should include the hero (part of the objectives of the level)

Notice the comment?:

// Spawn a player with spawnPlayerXY()

There is a difference between spawnXY and spawnPlayerXY. Otherwise, your syntax is good.

Thank you so much for this. I feel so bad that i didn’t figure that out myself.

1 Like

Lol…no worries! We’ve all been there at one point or another. When I first started the game devs, I also had to ask how to move the player…drove me nuts!, until someone said ‘just click’. :wink:

Now if you go to Golden Choice in the search bar and you find the longest title, you’ll see my handle. Could you pls help me work through the logic in code as that is my main problem.

Please don’t ask for help on a level in more than one topic…I’ll respond there.