Discuss Scratch

starlightsparker
Scratcher
1000+ posts

I need help with my snake game idk how to explain my problem in title

So I madea snake game, and I want the game to end when it touches itself, like in the real snake xenia. Is it possible?
starlightsparker
Scratcher
1000+ posts

I need help with my snake game idk how to explain my problem in title

existentialcrisises
Scratcher
100+ posts

I need help with my snake game idk how to explain my problem in title

I ran some tests in scratch, and I think there's a way to do it. You can set the “head” costume of the snake to be a slightly different colour, so your clones can sense whether it is touching the head with this:
touchingcolor?

But then the clone right at the back of the “head” will be touching them at all times, so you would automatically have a game over. So you need a variable to track if the clones are currently at the back of the head.

Then, you can do something like this:
ifnottouchingcolor?andCurrentlyatbackofhead?=Falsethenstop

Last edited by existentialcrisises (Sept. 30, 2023 12:04:42)

starlightsparker
Scratcher
1000+ posts

I need help with my snake game idk how to explain my problem in title

wouldn’t that stop all scripts? The stop block?
starlightsparker
Scratcher
1000+ posts

I need help with my snake game idk how to explain my problem in title

Actually nvm, but how do I code the variable?
cookieclickerer33
Scratcher
1000+ posts

I need help with my snake game idk how to explain my problem in title

starlightsparker wrote:

wouldn’t that stop all scripts? The stop block?
isnt that the point?????
starlightsparker
Scratcher
1000+ posts

I need help with my snake game idk how to explain my problem in title

I got confused, I said “nvm” later.
existentialcrisises
Scratcher
100+ posts

I need help with my snake game idk how to explain my problem in title

starlightsparker wrote:

Actually nvm, but how do I code the variable?

When a clone of the snake first spawns, it will be directly behind the head of the snake.
So, if the snake has not spawned any more clones after spawning a particular clone, that clone will be behind the head of the snake.
My suggestion would be to use clone IDs so that the clones know if the snake has spawned any more clones after spawning them. For example:
whenclickedset Current Cloneto0foreverchange Current Cloneby1createcloneof
whenIstartasacloneset Clone IDtoCurrentClonewaituntilCurrentClone>CloneIDStartSensingWhetherTheCloneIsTouchingTheHead

Powered by DjangoBB