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

#1 2013-04-18 17:31:23

Noobyhead99
New Scratcher
Registered: 2011-09-18
Posts: 1

Sprite connections through pen

I'm making a little circuitry simulator, at the moment featuring a battery and a bulb, each with a positive and negative terminal.

I'm in the process of writing the game so that you create wires with the pen (to connect the battery and the bulb), and so far I have the bulb turn on when the terminals of both the battery and the bulb are touching the wire colour.

However, you can make the bulb turn on without connecting the wires correctly, and I need a way to detect if there is actually a line of 'wire' connecting the terminals.

If the code would need to be different for switches to be added, I would appreciate if the code could be amended for that too.

Thanks!

Offline

 

#2 2013-04-18 18:11:12

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: Sprite connections through pen

Okay, i have an idea!

How about you have two circle sprites completely ghosted.

Then, You have two variables call "1stClickX" and "1stClickY".

Then, you have this script in your 2nd circle sprite:

when gf clicked
forever
wait until <Mouse down?>
set [1stClickX v] to (Mouse x)
set [1stClickY v] to (Mouse y)
repeat until < not <Mouse down?>>
go to x: (1stClickX) y: (1stClickY)
end
end

Then, for your 1st circle sprite:

when gf clicked
forever
wait until <Mouse down?>
repeat until < not <Mouse down?>>
go to [mouse-pointer v]
end
if << (x position) = (terminalwhateverX) > and < (y position) = (terminalwhateverY) > >
broadcast [terminalwhateverCorrect v]
end
etc...
end
This way though, they must have a specific Y and X position. If you just want them to be touching the terminal sprite (If it is a seperate sprite), Then just replace that large if statement condition with;

<touching [terminalwhatever v]?>
Okay, now for the wire. Make yet another sprite for the pen:

when gf clicked
forever
wait until <Mouse down?>
pen up
go to [2nd circle v]
wait until <not <Mouse down?>>
go to [1st circle v]
pen up
You won't get a live update on your wire, but you should be able draw in straight lines.
smile

If they get it wrong, then it will erase any other ones they got right, and they will have to start all over again... You could make it otherwise, but i don't really know how... You would have to use lists or something...

Tell me how this works,

Regards,

CAA14

Last edited by CAA14 (2013-04-18 18:15:01)

Offline

 

#3 2013-04-18 18:18:11

Smozzick
Scratcher
Registered: 2011-10-23
Posts: 100+

Re: Sprite connections through pen

^  This is the type of thing I would recommend; letting the computer do the drawing for you is the least hectic way to manage it.

Here's an example of a way you could possibly do it freehand style:

Circuity Sim Example

There are parts you'd have to edit but it shouldn't be too tricky to make sure that it doesn't light up unless the variables activate in the right order.

Last edited by Smozzick (2013-04-18 18:26:36)


http://i50.tinypic.com/ded8m.png

Offline

 

Board footer