see example for concrete implementation.
class Game s where
update :: Input -> s -> Update s
draw :: s -> Draw Unit
sound :: s -> Sound Unit
s
is a game state type which you can flexibly define.
Each functions are executed in order update, draw, sound at every frame.
type Input
= { isUp :: Boolean
, isLeft :: Boolean
, isDown :: Boolean
, isRight :: Boolean
, isW :: Boolean
, isA :: Boolean
, isS :: Boolean
, isD :: Boolean
}
isCollideCanvas :: Size -> X -> Y -> Update Boolean
Arguments
Size
: object size (length of one side of square)X
: square's left positionY
: square's bottom position
Return
- Boolean: whether there is a collision
After describing some actions, return next s
at the end of update function.
emo :: Emoji -> Size -> X -> Y -> Draw Unit
Arguments
Emoji
: specify one of supported emojiSize
: emoji size (length of one side of square)X
: square's left positionY
: square's bottom position
※ Origin is based on left bottom. (not left top)
※ All emojis are treated as square. Because these appearances depend on running device or browser.
emap :: EmojiMap -> Size -> X -> Y -> Draw Unit
Arguments
EmojiMap
: emoji map that you can edit.Size
: map element (emoji) size. (not whole map size)X
: map's left positionY
: map's bottom position
play :: Score -> Tone -> Tempo -> Sound Unit
※ The action is ignored until the score ends.
Arguments
Score
: score that you can edit.Tone
: oscillation type (select one of [Sine, Square, Sawtooth, Triangle])Tempo
: tempo (beat per minute)
The type checker will tell you which emojis you can use!
mountFuji :: EmojiMap
mountFuji = parse (SProxy :: SProxy Fuji)
type Fuji
= """
🈳🈳🈳🈳🈳🈳🈳🈳🈳
🈳⛅🈳🈳🎌🈳🈳🌧🈳
🈳🈳🈳🌳🗻🌳🈳🈳🈳
🈳🈳🌳🗻🗻🗻🌳🈳🈳
🈳🌳🗻🗻🗻🗻🗻🌳🈳
🌳🗻🗻🗻🗻🗻🗻🗻🌳
"""
※ 🈳 is the special emoji that represents vacant space.
The type checker will tell you which patterns you can use!
beep :: Score
beep = parse (SProxy :: SProxy NHK)
type NHK
= """
🎹🈳🈳🈳🈳🈳🈳🈳🈳🈳🈳🈳🈳
🎹🈳🈳🈳🈳🈳🈳🈳🈳🈳🈳🈳🈳
🎹🈳🈳🈳🈳🈳🈳🈳🈳🈳🈳🈳🈳
🈳🈳🈳🈳🈳🈳🈳🈳🈳🈳🈳🈳🎹
"""
- 🎹: note
- 🈳: vacancy
🎹🈳🈳🈳🈳🈳🈳🈳🈳🈳🈳🈳🈳: means A4 (440 Hz)
🈳🈳🈳🈳🈳🈳🈳🈳🈳🈳🈳🈳🎹: means A5 (880 Hz)
Main game loop function.
emo8 :: forall s. Game s => s -> Config -> Effect Unit
Main game loop function for development.
emo8Dev :: forall s. GameDev s => s -> Config -> Effect Unit
class (Game s, Encode s, Decode s) <= GameDev s where
saveLocal :: s -> Array LocalKey
saveLocal function is executed after Game class's functions at every frame. It saves state json text to localstorage with the given LocalKey array (for multiple savepoints).
loadStateWithDefault :: forall s. GameDev s => s -> LocalKey -> Effect s
Arguments
s
: fallback state which is used when localstorage key is not found.LocalKey
: localstorage key which you saved with saveLocal function.