Unit 3 Lesson 17 Interactive Card

Please help me help my student:
This was his message to me: “There is only one bug that happens once every eight times that I do not know how to fix: sometimes the “coin” only bounces from left to right, not changing direction. I wish I knew a good way to change the direction the coin bounces, but I do not know even after looking through the code.org help.”

He is a great kid that is having a blast coding. I just don’t know how to help him.

Link to the project or level: [Code.org - Game Lab]

@carol.houston

Hmmmm … I’m not able to re-create the problem (or I don’t understand the problem).

Can he maybe try to explain it a little better or if you have him in class, maybe he can demo it for you and you can let us know what he is seeing?

It does look like a fun game!

Mike

Thank you so much for your response. He is a virtual student - Let me see if I can get him to explain the issue a bit further. He is having so much fun in Code. I’m so proud of him - but he’s moved past my level of expertise.

The foregoing electronic message and any files transmitted with it are confidential and are intended only for the use of the intended recipient named above. This communication may contain material protected by the Family Educational Rights and Privacy Act (FERPA). If you are not the intended recipient, copying, distribution or use of the contents of this message is strictly prohibited. If you received this electronic message in error, please notify us immediately at 662-429-5271.

This is what he just sent back - I’m not sure Code.org Game Lab will allow him to do what he wants. ???

“The coin seems to randomly pick a direction to go in, and it starts bouncing around as it should, but I would like to control the angle the coin starts at”

The foregoing electronic message and any files transmitted with it are confidential and are intended only for the use of the intended recipient named above. This communication may contain material protected by the Family Educational Rights and Privacy Act (FERPA). If you are not the intended recipient, copying, distribution or use of the contents of this message is strictly prohibited. If you received this electronic message in error, please notify us immediately at 662-429-5271.

And he just added: “And the angles stays like this, so if the coin starts in a horizontal line, it only moves through that line, making the game far easier”

The foregoing electronic message and any files transmitted with it are confidential and are intended only for the use of the intended recipient named above. This communication may contain material protected by the Family Educational Rights and Privacy Act (FERPA). If you are not the intended recipient, copying, distribution or use of the contents of this message is strictly prohibited. If you received this electronic message in error, please notify us immediately at 662-429-5271.

Ok… I think I understand what he is saying now.

On line 15, he is setting a random velocity for the coin. I just started and restarted the game a number of times and the most recent time I started it, I got an X velocity of 0 and a Y velocity of 0, so the coin just sat in the center of the screen and didn’t move at all.

When it is moving just horizontally, that means that the Y velocity was randomly selected as 0, so it just moves back and forth across the screen.

In theory, he could get an X velocity of 0 and it would only move up and down.

So, a few suggestions. I wouldn’t allow for a velocity of zero. If the random velocity was chosen between let’s say 1 and 16, you would never get a horizontal or a vertical velocity and you would never get what I just got where by chance both were zero and the coin didn’t move at all.

2nd … if he wants to make it less predictable after the player catches a coin, I would reset the random velocity picker right after the collision. Then, when the coin restarts, it wouldn’t continue in the same direction as it had gone before, but it would instead choose a different random trajectory.

I think this is what he is after and he has done a great job. Let us know if there is something else we can help with or if he gets this and that isn’t quite what he was after.

Mike

One small correction to what I said. He is actually choosing a random velocity between -16 and 16. That makes it even less likely to get 0 and 0 what I got, but it is possible.

I like having the negative numbers be an option, so he can’t restrict it to just 1 to 16, but he could set up a few while loops to pick numbers that wouldn’t ever be equal to zero. I normally don’t like just giving code, but this could be a bit tricky.

Here’s an example of what I mean. In this example, we start by setting the velocity to zero, but then we immediately tell it as long as it is equal to zero, pick a random number between -16 and 16. If zero is chosen, it will pick again before moving to the next command. This way, 0 will never be an option.

Screen Shot 2021-05-20 at 3.03.36 PM

Hope this helps.

Mike

Michael, Thank you so much for your assistance. I can’t wait to share this information with my student. Code.org and my students challenge me to learn and grow. Thanks.

The foregoing electronic message and any files transmitted with it are confidential and are intended only for the use of the intended recipient named above. This communication may contain material protected by the Family Educational Rights and Privacy Act (FERPA). If you are not the intended recipient, copying, distribution or use of the contents of this message is strictly prohibited. If you received this electronic message in error, please notify us immediately at 662-429-5271.