CSD Unit 6 - Collision Detection

My students are trying to incorporate collision detection into our app/circuit broad games. We followed a tutorial for the collision detection part but the winner screen shows up straight away and not when the girl moves to the cake.

We want the winner screen to show only when the girl has collected both cakes. I think the tobecollected variable is not right.

Would love some insight on this as i feel it is now getting a little over my head!

[App Lab - Code.org]

Hello @lwilliams1!

So right now, the variable isn’t really being used to do anything that affects the game. It starts off being set as 2 and then the value changes to 1 if either of the conditionals happens, but that value isn’t really being used in any way.

I’m guessing you want it to decrease by 1 if one of the cakes is collected (not become 1) and then you would want the winner screen to show up if it ever reaches 0, so there needs to be some adjustment to the conditional blocks and what happens to the value of the variable (subtracting 1 rather than becoming 1) and then a new conditional added to see when it becomes zero.

I’m sure you probably are already aware of this, but this kind of game is easier to implement in Game Lab, but a fun challenge to do in App Lab as well.


Yes - I see that now! OK so I’ve made a change to that variable and added another conditional BUT the 2 images are hidden from the beginning and not related to the collision detection. Is my detection incorrect?

We have completed this in gamelab (and yes so much easier!)
but my students are trying to out smart me and winning!

Sorry for all the questions!

Ok… here are a few things to look at. If you still can’t figure it out, I can look at it later today. Right now my own computer is acting finicky with the Circuit Playground so I may have to try a different computer.

I think the problem could be in your formulas for determining the collision… I’m trying to logically process them and it is a bit difficult.

If you want to know if there is an overlap in the x positions, you would need to know where the left and right edge of both sprites are, but wouldn’t you need half of the width of the sprites (distance from the center to either side)? You are using the full width which I think could cause a collision even if they aren’t touching (thus causing the cake to hide).

Also, lines 42 & 43 shouldn’t be necessary. That would likely cause collision with one cake to end the game. The nested conditionals (without lines 42 & 43) should take care of that.

That’s what I can figure out without having my board plugged in, but if you still can’t find it, reach back out and we’ll see what we can figure out.