# Game Dev 2 Final Project\[SOLVED\]

**URL:** <https://discourse.codecombat.com/t/game-dev-2-final-project-solved/21531>\
**Category:** Level Help\
**Created:** [May 12, 2020, 6:07pm UTC](https://discourse.codecombat.com/t/game-dev-2-final-project-solved/21531 "2020-05-12T18:07:15Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![01CODER](https://avatars.discourse-cdn.com/v4/letter/0/90ced4/32.png) [@01CODER](https://discourse.codecombat.com/u/01CODER)\
**Post date:** [May 12, 2020, 6:07pm UTC](https://discourse.codecombat.com/t/game-dev-2-final-project-solved/21531/1 "2020-05-12T18:07:15Z")

</div>

Here is my code

```java
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

```python
ui.track(game, "defeated");

```

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

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [May 12, 2020, 7:16pm UTC](https://discourse.codecombat.com/t/game-dev-2-final-project-solved/21531/2 "2020-05-12T19:16:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![01CODER](https://avatars.discourse-cdn.com/v4/letter/0/90ced4/32.png) [@01CODER](https://discourse.codecombat.com/u/01CODER)\
**Post date:** [May 12, 2020, 7:18pm UTC](https://discourse.codecombat.com/t/game-dev-2-final-project-solved/21531/3 "2020-05-12T19:18:05Z")

</div>

I will try doing this

---

<div class="post-metadata">

**Author:** ![01CODER](https://avatars.discourse-cdn.com/v4/letter/0/90ced4/32.png) [@01CODER](https://discourse.codecombat.com/u/01CODER)\
**Post date:** [May 12, 2020, 7:20pm UTC](https://discourse.codecombat.com/t/game-dev-2-final-project-solved/21531/4 "2020-05-12T19:20:15Z")

</div>

It worked thank you very much

---

<div class="post-metadata">

**Author:** ![MrJumping](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/mrjumping/32/12547_2.png) [@MrJumping](https://discourse.codecombat.com/u/MrJumping)\
**Post date:** [June 27, 2020, 5:04pm UTC](https://discourse.codecombat.com/t/game-dev-2-final-project-solved/21531/5 "2020-06-27T17:04:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [June 27, 2020, 5:12pm UTC](https://discourse.codecombat.com/t/game-dev-2-final-project-solved/21531/6 "2020-06-27T17:12:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [June 27, 2020, 5:12pm UTC](https://discourse.codecombat.com/t/game-dev-2-final-project-solved/21531/7 "2020-06-27T17:12:32Z")

</div>

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 😁

---

<div class="post-metadata">

**Author:** ![MrJumping](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/mrjumping/32/12547_2.png) [@MrJumping](https://discourse.codecombat.com/u/MrJumping)\
**Post date:** [June 27, 2020, 5:12pm UTC](https://discourse.codecombat.com/t/game-dev-2-final-project-solved/21531/8 "2020-06-27T17:12:39Z")

</div>

ok I’ll try moving XY thx

---

<div class="post-metadata">

**Author:** ![MrJumping](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/mrjumping/32/12547_2.png) [@MrJumping](https://discourse.codecombat.com/u/MrJumping)\
**Post date:** [June 27, 2020, 5:13pm UTC](https://discourse.codecombat.com/t/game-dev-2-final-project-solved/21531/9 "2020-06-27T17:13:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [June 27, 2020, 5:14pm UTC](https://discourse.codecombat.com/t/game-dev-2-final-project-solved/21531/10 "2020-06-27T17:14:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MrJumping](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/mrjumping/32/12547_2.png) [@MrJumping](https://discourse.codecombat.com/u/MrJumping)\
**Post date:** [June 27, 2020, 5:14pm UTC](https://discourse.codecombat.com/t/game-dev-2-final-project-solved/21531/11 "2020-06-27T17:14:36Z")

</div>

```python

// 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

---

<div class="post-metadata">

**Author:** ![MrJumping](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/mrjumping/32/12547_2.png) [@MrJumping](https://discourse.codecombat.com/u/MrJumping)\
**Post date:** [June 27, 2020, 5:15pm UTC](https://discourse.codecombat.com/t/game-dev-2-final-project-solved/21531/12 "2020-06-27T17:15:25Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [June 27, 2020, 5:17pm UTC](https://discourse.codecombat.com/t/game-dev-2-final-project-solved/21531/13 "2020-06-27T17:17:21Z")

</div>

Notice the comment?:

```python
// Spawn a player with spawnPlayerXY()

```

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

---

<div class="post-metadata">

**Author:** ![MrJumping](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/mrjumping/32/12547_2.png) [@MrJumping](https://discourse.codecombat.com/u/MrJumping)\
**Post date:** [June 27, 2020, 5:17pm UTC](https://discourse.codecombat.com/t/game-dev-2-final-project-solved/21531/14 "2020-06-27T17:17:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [June 27, 2020, 5:19pm UTC](https://discourse.codecombat.com/t/game-dev-2-final-project-solved/21531/15 "2020-06-27T17:19:24Z")

</div>

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’. 😉

---

<div class="post-metadata">

**Author:** ![MrJumping](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/mrjumping/32/12547_2.png) [@MrJumping](https://discourse.codecombat.com/u/MrJumping)\
**Post date:** [June 27, 2020, 5:21pm UTC](https://discourse.codecombat.com/t/game-dev-2-final-project-solved/21531/16 "2020-06-27T17:21:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [June 27, 2020, 5:22pm UTC](https://discourse.codecombat.com/t/game-dev-2-final-project-solved/21531/17 "2020-06-27T17:22:41Z")

</div>

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