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
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 endThen, 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... endThis 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 upYou won't get a live update on your wire, but you should be able draw in straight lines.
Last edited by CAA14 (2013-04-18 18:15:01)
Offline
^ 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)
Offline