Unit 3, Lesson 22 - debug help

#1

I need some help debugging one of my student’s games for Unit 3, Lesson 22. The flower grows when it collects rain drops. When it gets to be a large tree, the ladybugs are supposed to be displaced or collide with the tree (we have tried using both codes), but the tree just collects the ladybugs instead of displacing them.
Also, the tree doesn’t always change to dead tree once the lives go under 1 and if it does, it will not stay as a dead tree.

Can someone help me see where the bugs are? Thanks!!

0 Likes

#2

I’m not sure I understand what is supposed to happen to the ladybugs when they hit the tree.

0 Likes

#3

He was hoping the ladybugs would displace (tree.displace ladybug) once they hit the larger tree, but the tree is just collecting them, like the flies and raindrops.

We tried the collide and bounce codes as well, so the ladybugs would just bounce off the tree, but it still only collected them.

0 Likes

#4

Geraldine,

Interesting - I played it a couple times and the displacement seemed to work once in a while and only when the ladybug had past the top of the tree. I think the issue might be in the way the code is setup. I advise my students to think about the stages of the game and what they want to happen at certain points. For instance, I have them create a startGame function that sets up the game for the beginning (rain drops at the top of the screen, the flower sprite costume, the points to 0), then I’d have a gameOver function which stops all the raindrops, flies, ladybugs, and point value. Under than that, you can use conditionals to test if certain things are true in the game and then run bits of code (using functions) that only run if the player is a tree vs a sapling.

Hope that makes sense - please reach out if it doesn’t so we can solve this together!
Brad

0 Likes

#5

I like the concept of this game. The student put a lot of work into it but can simplify it quite a bit. I agree with @bradleywellsashley that more functions need to be made. There’s a lot of excess work (multiple flies, ladybugs, etc that can be made with one function.) Also, some of the functions have too much going on - enemiesTouch should focus on only what happens when enemies touch. Lives being <1 and the game being over should be in separate functions.

Also the tree doesn’t change to a dead tree because it wasn’t set to do this (look at lines 126 and 127. Only the flower and sapling become dead trees).

0 Likes