Lesson 27: Student Game

I have a student who is trying to have a sprite both jump and rotate when a key is down. We can get them working separately, but not together. Is there something we are missing (we were commenting them out to try different configurations when the bell rang, but I am completely stuck!

if (keyDown(“w”)) {
pig.rotation = pig.rotation-9;

//pig.velocityY=pig.velocityY=-7;
//if (pig.rotation==360) {
// pig.rotation=0;
// }
// } else {
// pig.velocityY=0;
}
drawSprites();

Did you try if “keyWentDown” instead of keyDown? That was my first thought. If so and it’s still not working, it’s very helpful for us to be able to have a link to the game so we can troubleshoot it. Screenshots of the code don’t give us access to the other resources like the sprites.

Also, in one of the commented out lines, you have two = signs. The last one should probably be a +

Have the student click the “share” button and send us a link to that project and we are happy to look at it.

Thanks!

Mike

We did try the KeyWentDown!

Here’s the link for anyone willing to help me troubleshoot:

https://studio.code.org/projects/gamelab/v5x8Uf_RWCPsVKBk6ENRj-wrdfRZilCfDC4ZtxAL7Tw

@dcarlino ,

It looks like sharing may not be enabled as I get an error message when I click on the link.

Mike

Ok, looks like I fixed that problem.

I was playing with it during my planning period as well…I feel like it is a logic error…like how he is nesting and combining his conditionals. I also feel like his conditional to stop the rotation is not working like he thinks it should.

I think you’re right. Also, when I fix the error I pointed out with two = signs in the equation, I can get it to rotate and jump, but only while holding down the w key.

He is probably going to want to create some kind of a trigger variable that is turned off and then that turns on when the w key is pressed.

Then, a 2nd conditional will start the rotation if the trigger variable has turned on and start the rotation and jump process and determine when those end and the sprite returns to the ground.

Check back in if he tries some more stuff and still can’t get it to work. Looks like a fun game.

Mike

Thank you! We will keep plugging away!