Files
loop/src/Dodge/LevelGen/Switch.hs
T
2025-06-25 15:40:12 +01:00

56 lines
1.4 KiB
Haskell

module Dodge.LevelGen.Switch
( makeSwitch
, makeButton
, makeSwitchSPic
, drawSwitchWire
) where
import Dodge.Data.Button
import Dodge.Data.WorldEffect
import Dodge.Default
import Dodge.SoundLogic
import Picture
import ShapePicture
import Shape
import Geometry
makeButton
:: Color
-> WdWd -- ^ Effect when pressed
-> Button
makeButton col eff = defaultButton
{ _btEvent = ButtonPress BtInactive ButtonDoNothing click1S eff col
, _btState = BtOff
}
-- TODO remove duplication
drawSwitchWire :: Color -> Color -> Button -> SPic
drawSwitchWire col1 col2 bt
| _btState bt == BtOff = flick $ pi/4
| otherwise = flick (negate (pi/4))
where
flick a = noPic ( mconcat
[ colorSH col1 . translateSHz 10 . upperBox Small Typical 10 $ rectNSWE (-2) (-5) (-10) 10
, colorSH col2 . translateSH (V3 0 (-2) 15) . rotateSH a . upperBox Small Typical 2
$ rectNSWE 10 0 (-2) 2
]
)
makeSwitchSPic
:: Color
-> Color
-> WdWd -- ^ Switch on effect
-> WdWd -- ^ Switch off effect
-> Button
makeSwitchSPic c1 c2 effOn effOff = defaultButton
{ _btEvent = ButtonSimpleSwith effOn effOff c1 c2
, _btState = BtOff
}
makeSwitch
:: Color
-> Color
-> WdWd -- ^ Switch on effect
-> WdWd -- ^ Switch off effect
-> Button
makeSwitch col1 col2 = makeSwitchSPic col1 col2