Electricity and Wires #19
Labels
No Milestone
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: SketchyMaze/doodle#19
Loading…
Reference in New Issue
There is no content yet.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may exist for a short time before cleaning up, in most cases it CANNOT be undone. Continue?
This is an idea for a future Doodle feature involving electricity and wires.
"Wire" Palette Type
Colors in the level palette could be flagged as being a "wire" in a similar way as "fire" and "water" colors.
Wire pixels would be capable of carrying a power signal from a Power Source doodad to one or more Powered Device doodads that are interested in the signal.
Wire pixels would have two states: "on" and "off". The default state would be "off" and would render in a darker shade than the pixel's color value. For example if wires were colored red (#FF0000) they would render darker when "off" (i.e. #AA0000) but return to their intended color when powered.
Wire Trace Algorithm
When the power state of a wire should change, an algorithm will "crawl" the wire pixels to visit each one and potentially modify their state.
From a given starting pixel, spread to the neighboring wire pixel in any of the 8 directions (including diagonals). This way wires of any shape will work: freehand, lines, rectangles, and thick lines too.
Wires would only be traced when needed, and the state of the pixels updated as needed, when a power state change has happened:
When a wire is turned on or off, any doodad that is touching the wire would be given a "power" event with the wire's state. Interested doodads could then update their internal state accordingly.
Power Sources
Existing doodads that emit power events could also be updated to act as power sources for wires: Switches and Sticky Buttons would toggle the power source on/off, and normal Buttons would emit power while pressed and stop powering when released.
New doodads that could be added would include:
Logic Gates
Special doodads placed along the path of a wire could act as logic gates that control the behavior of the wire during the Wire Trace Algorithm.
While a wire is being traced, if a given pixel falls beneath a logic gate, the gate's handler function would be called which would inform the next step for the wire trace algorithm.
Additional wire pixels beneath the gate will be ignored; so even if a wire line was un-interrupted going beneath the gate doodad, no signal will traverse the wire. When the gate's handler function returns a valid direction for the signal to pass, the pixel beneath that edge of the doodad would become lit up and the trace would continue from there.
Ideally, logic gates should be able to rotate (face any 90-degree direction) without needing a ton of redundant doodads for each direction. The engine will need to support rotating doodads for this to work.