Coding Help! with game

My student is trying to have his game work where his sprites g and g2 move across the screen. He only wants one of the sprites to appear at the beginning and then when it gets to the left side of the screen (0) he wants one of the sprites to appear again in a random area and move across the screen. He wants it to sometimes be the g sprite that appears and sometimes the g2 sprite to appear. All times he wants whicheverone it is to appear at a random location. Is this possible? We have tried several if statements, but we just can’t get it right.

Hi @hensleyn,

This is a cool idea for the game! Just so I’m clear, your student is trying to get the ground to appear at different lengths & widths, right? Both g and g2 have the same source image but have different parameters for length & width. So, I’d ask your student to think about whether they need the different sprites to appear, or if it can be the same sprite with an altered image. The way I’d personally approach this is to set the width to some random number (like 100 + randomNumber(0,200) or something to that effect) to get the stretch down.

However, I wouldn’t want to outright suggest that to the student so that he can come up with his own solutions. And if this isn’t the way the student was thinking about this, please reply on here so we can look at it again.

On a side note, I’d recommend having them change their sprite names from single letter to something more meaningful (cat instead of c, ground instead of g). It was a little hard to read, and it would be good to get your students in those habits now. (It’ll also save you some time when you’re grading.)

–Michael K.

Thanks for replying. The student is trying to get the platforms to appear at different times on the screen, but randomly. He wants one of them to appear at random, move across the screen and then another (randomly chooses which one appears again). He also wants them to appear at random positions once it chooses which one appears.

On a side note, the student will not comply with the naming of sprites/variables. I have told him many times how difficult it is to read. :confused:

Gotcha. I think my proposed solution of randomizing the dimensions of the particular platform would meet his requirement for “one of them” to appear at random. Perhaps something that uses a random number to determine which one appears after its x value crosses below a certain threshold:

var groundShape = 1;
var randNum = randomNumber(0,1);
if (groundShape == randNum) {
} else {

or something to that effect.

As far as noncompliance with naming of sprites & variables, you could always remind the student that you’re grading on a rubric and readability is part of that rubric. If you can’t read the code, that’s more than a few easy points they’re leaving on the table. He may need to learn that lesson the hard way in middle school now in order to encourage adherence to naming conventions in the future.

–Michael K.