Discuss Scratch

kidscollaborative
Scratcher
34 posts

Help With Snake Game

Hi! Been using these discussion boards to get some amazing tips for Scratch. So thank you!

I made a Snake Game, which is functional, but not to my liking. I know how to do the rest (game over and such) so don't worry about that!

Issue: snake moves start-stop and not fluidly. I needed to add the “Wait Speed Secs” to communicate with the deleting of the clones, but it also causes the snake to start-stop. Ideally, the snake's speed would be “move 3 steps”. As it stands, it's “Move 3 Steps” + “Wait Speed Secs”. How can I keep the snake movement fluid and still function the snake's tail?

Thank you!

https://scratch.mit.edu/projects/629674363

Last edited by kidscollaborative (Jan. 19, 2022 02:09:42)

SansStudios
Scratcher
1000+ posts

Help With Snake Game

Hello! Welcome to scratch, and to the forums on this account

I'm not quite sure if I understand the problem you identify in your question.

Is there an issue with removing the (wait speed seconds) block from your main green flag loop? The code could be changed to look something like this:

when green flag clicked
... // set speed + score variables
forever
move ((20) * (speed)) steps // delete the wait x seconds under here and replace it with this math so speed still works :)
create clone of [myself v]
end

Last edited by SansStudios (Jan. 19, 2022 02:30:35)

kidscollaborative
Scratcher
34 posts

Help With Snake Game

So that fixes the snake head, but creates a new problem! There's the limit of 300 clones right? The snake tail is now way too many clones because there's no gap in between them, which was created by the start-stop snake head. In a perfect world, the snake head and tail both move fluidly, but the tail still has the gaps so it does not run out of clones to generate.

This is exactly how I want the game to function, except with gaps in the tail so there aren't a million clones. Not sure how to go about that?

forever
move (3) steps
create clone of [myself v]
end

when I start as a clone
switch costume to [snake body v]
wait ((speed) * (score)) secs
delete this clone
SansStudios
Scratcher
1000+ posts

Help With Snake Game

kidscollaborative wrote:

This is exactly how I want the game to function, except with gaps in the tail so there aren't a million clones. Not sure how to go about that?

You could move the clone block to it's own loop with a wait:

when green flag clicked // new green flag block!
forever
create clone of [myself v] // remove the create clone from the other script
wait (0.1) secs
end

Hope this helps
kidscollaborative
Scratcher
34 posts

Help With Snake Game

Perfect. Thanks!
SansStudios
Scratcher
1000+ posts

Help With Snake Game

Glad I could help! Let me know if you have any more questions.

Powered by DjangoBB