Discuss Scratch

3jkong
Scratcher
35 posts

Sensing Sprites With same x pos

Hello.
I'm trying to make some sort of game that would involve spikes flying to reach the player when said player reaches a certain x position.
My spikes don't sense, the link is here: https://scratch.mit.edu/projects/991848749/
Thank you!

My Signature wasn't eaten by an evil kumquat. In fact, it's quite the opposite- it is sheltering an kumquat. Not an evil kumquat, just a kumquat.

You see, every day millions of kumquats face frutism every face for being “knockoff oranges” or “signature eaters”. All of these are just stereotypes that can hurt a young kumquats feelings. If you care for equality, justice, and for all fruits to be valued fairly, stop being mean to kumquats. There's only a handful who eat signatures- I will admit, those kumquats deserve punishment, however not all kumquats are this way. Therefore, instead of being mean to a kumquat, think about what you're doing and shelter one instead.


(art by @ocuious)
RokCoder
Scratcher
1000+ posts

Sensing Sprites With same x pos

You're checking for the player's x position to be exactly the same as that of the spike. This is unlikely to happen because the acceleration you're using on the player means his x position is rarely going to be an integer. You should check for the player being approximately the same x position as the spike. Instead of -

if <([x position v] of [Player v]) = (x position)> then

Use -

if <([abs v] of (([x position v] of [Player v]) - (x position))) < (4)> then

This will return true if the player's x position is within 4 pixels to either side of a spike.

Another problem that came to light was that the spikes sometimes don't appear at all on the second screen. This happens if you hit the green flag the player is on the second screen. The reason for this is that the green flag code in the Danger sprite is running before the green flag code in the Player sprite. The Danger sprite sees that m#=2 and creates the spikes but the Player sprite then changes m# to 1 (removing the spikes which won't be created again).

The quick and nasty fix is to add a short pause at the beginning of the green flag block in the Danger sprite.

The correct way is to only have one green flag block in the project which broadcasts Initialise to set everything up and then broadcasts Play to start the game (or something structured along those lines)


Scratch dabbling for fun…

3jkong
Scratcher
35 posts

Sensing Sprites With same x pos

Whoa, thanks again Rok!

My Signature wasn't eaten by an evil kumquat. In fact, it's quite the opposite- it is sheltering an kumquat. Not an evil kumquat, just a kumquat.

You see, every day millions of kumquats face frutism every face for being “knockoff oranges” or “signature eaters”. All of these are just stereotypes that can hurt a young kumquats feelings. If you care for equality, justice, and for all fruits to be valued fairly, stop being mean to kumquats. There's only a handful who eat signatures- I will admit, those kumquats deserve punishment, however not all kumquats are this way. Therefore, instead of being mean to a kumquat, think about what you're doing and shelter one instead.


(art by @ocuious)

Powered by DjangoBB