Discuss Scratch

Myers_senagal_mix
Scratcher
100+ posts

Mouse touching color

Hi, I wanted to make a game that you can take care of a bird. I wanted to make it so when you touch the bird's foot it gets mad. I wanted to make it so when you touch the bird's foot it will change the costume. I was thinking I could make it so when you touch the color of the bird's foot it will change the costume but I couldn't find a way.
Grizzly_NightStalker
Scratcher
92 posts

Mouse touching color

Say if the player is touching the color of the bird's foot then change the costume.
Myers_senagal_mix
Scratcher
100+ posts

Mouse touching color

Grizzly_NightStalker wrote:

Say if the player is touching the color of the bird's foot then change the costume.
What player? Does it mean the mouse?
mullafacation
Scratcher
100+ posts

Mouse touching color

If the bird's foot isn't a seperate sprite and you're using the mouse to interact with it then you can still do this but you need to work out where the bird's foot is. Fortunately the foot is at the bottom of the bird (right?!) so you just need to work out what position that it is below (we say mouse y < foot y). You can do this with this script:

when [space v] key pressed
set [top of bird's foot v] to (mouse y)

so now if you hover just above the bird's foot and press space then that variable will be set to the height of the bird's foot. You can get rid of the last script now if you want. Now you can detect if it is touching the foot. I've added mouse down as a condition so you would have to click on the foot but you don't need to include that.

if <<<touching [mouse pointer v] ?> and <(mouse y) < (top of bird's foot)>> and <mouse down?>> then
switch costume to [grr! v]
end

As long as the bird doesn't move this should work! If you do want the bird to move, it's quite easy to work out its relative position (just subtraction) and in that case I could go through doing that.

Last edited by mullafacation (Nov. 10, 2023 22:43:50)

Myers_senagal_mix
Scratcher
100+ posts

Mouse touching color

mullafacation wrote:

If the bird's foot isn't a seperate sprite and you're using the mouse to interact with it then you can still do this but you need to work out where the bird's foot is. Fortunately the foot is at the bottom of the bird (right?!) so you just need to work out what position that it is below (we say mouse y < foot y). You can do this with this script:

when [space v] key pressed
set [top of bird's foot v] to (mouse y)

so now if you hover just above the bird's foot and press space then that variable will be set to the height of the bird's foot. You can get rid of the last script now if you want. Now you can detect if it is touching the foot. I've added mouse down as a condition so you would have to click on the foot but you don't need to include that.

if <<<touching [mouse pointer v] ?> and <(mouse y) < (top of bird's foot)>> and <mouse down?>> then
switch costume to [grr! v]
end

As long as the bird doesn't move this should work! If you do want the bird to move, it's quite easy to work out its relative position (just subtraction) and in that case I could go through doing that.
Thanks, I think I have another idea after reading this suggestion but if it doesn't work I'll use your idea!

Powered by DjangoBB