Usage Overview
May 15, 2020 ยท View on GitHub
see example for concrete implementation.
Game Class
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.
Update Action
Input
type Input
= { isUp :: Boolean
, isLeft :: Boolean
, isDown :: Boolean
, isRight :: Boolean
, isW :: Boolean
, isA :: Boolean
, isS :: Boolean
, isD :: Boolean
}
Canvas Frame Collision (e.g.)
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.
Draw Action
Draw Emoji (e.g.)
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.
Draw Map (e.g.)
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
Sound Action
Play Sound (e.g.)
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)
Map Edit
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.
Sound Edit
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)
Run
Production
Main game loop function.
emo8 :: forall s. Game s => s -> Config -> Effect Unit
Development
Main game loop function for development.
emo8Dev :: forall s. GameDev s => s -> Config -> Effect Unit
GameDev Class
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).
Load Saved State
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.