This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-08-14 17:08:55

destructo-serpent
Scratcher
Registered: 2012-07-25
Posts: 1000+

colour detection

how do i make my sprite move in any direction with th keys, but if part of it is touching a certain colour not be able to move towards the colour?

Offline

 

#2 2012-08-22 12:16:18

Spyderblade
Scratcher
Registered: 2012-07-13
Posts: 100+

Re: colour detection

Use this script.

when gf clicked
repeat until <touching color [black]>
 if <right arrow key v pressed?>
  change x by [1]
 end
 if <left arrow key v pressed?>
  change x by [-1]
 end
 if <up arrow key v pressed?>
  change y by [1]
 end
 if <down arrow key v pressed?>
  change y by [-1]
 end
end
wait until <<<key right arrow pressed?> or <key left arrow pressed?>> or <<key up arrow pressed?> or <key down arrow pressed?>>>>
broadcast [move again v]

Last edited by Spyderblade (2012-08-22 12:17:35)


http://i48.tinypic.com/2pzbc5x.jpg
Am I online? http://blocks.scratchr.org/API.php?user=Spyderblade&amp;action=onlineStatus&amp;type=circle And, check out my Challenge Mission 2!!

Offline

 

#3 2012-08-22 12:19:45

Spyderblade
Scratcher
Registered: 2012-07-13
Posts: 100+

Re: colour detection

Then copy that(except for the When green flag clicked part), and put it under this:

when i receive [move again v]


http://i48.tinypic.com/2pzbc5x.jpg
Am I online? http://blocks.scratchr.org/API.php?user=Spyderblade&amp;action=onlineStatus&amp;type=circle And, check out my Challenge Mission 2!!

Offline

 

#4 2012-08-22 12:26:32

sonicfan12p
Scratcher
Registered: 2011-11-16
Posts: 1000+

Re: colour detection

Spyderblade wrote:

Use this script.

when gf clicked
repeat until <color [#000000] is touching [#00FFFF]?>
 if <key [right arrow v] pressed?>
  change x by [1]
 end
 if <key [left arrow v] pressed?>
  change x by [-1]
 end
 if <key [up arrow v] pressed?>
  change y by [1]
 end
 if <key [down arrow v] pressed?>
  change y by [-1]
 end
end
wait until <<<key [right arrow v] pressed?> or <key [left arrow v] pressed?>> or <<key [up arrow v] pressed?> or <key [down arrow v] pressed?>>>
broadcast [move again v]

Fixed the scripts, and added something. The black represents a certain part of your sprite, not just the whole thing, and the other color represents the color you don't wish to move through.

Last edited by sonicfan12p (2012-08-22 12:27:45)


Why are the secret organizations getting all the attention?  mad

Offline

 

Board footer