This library helps you get implement your video game as simple as possible.
composeSimpleGame : SimpleGameComposition appState eventFromHtml -> Platform.Program () appState (SimpleGameWithKeyboardInputAndFixedUpdateIntervalEvent eventFromHtml)
Use this function to describe how your game is composed of the specific functions in your project. Following is an example:
game : SimpleGame GameState ()
game =
composeSimpleGame
{ updateIntervalInMilliseconds = 125
, updatePerInterval = updatePerInterval
, updateOnKeyDown = updateOnKeyDown
, updateOnKeyUp = updateOnKeyUp
, renderToHtml = renderToHtml
, initialState = initialGameState
, updateForEventFromHtml = updateForEventFromHtml
}
Platform.Program () appState (SimpleGameWithKeyboardInputAndFixedUpdateIntervalEvent eventFromHtml)
This type helps you write a type annotation for the function describing the composition of your game:
game : SimpleGame GameState ()
game =
....
{ updateIntervalInMilliseconds : Basics.Int
, updatePerInterval : appState -> appState
, updateOnKeyDown : Keyboard.Event.KeyboardEvent -> appState -> appState
, updateOnKeyUp : Keyboard.Event.KeyboardEvent -> appState -> appState
, renderToHtml : appState -> Html eventFromHtml
, updateForEventFromHtml : eventFromHtml -> appState -> appState
, initialState : appState
}
Describes how your game app is composed of functions that describe how to handle the different kinds of events like for example, pressing or releasing key.
Keyboard.Event.KeyboardEvent
This type describes the keyboard events as used in the functions updateOnKeyDown
and updateOnKeyUp
.
Use as follows:
updateOnKeyDown : KeyboardEvent -> GameState -> GameState
updateOnKeyDown =
...
Following are generic helper functions which are not specific to one particular game.
listRemoveSet : List a -> List a -> List a
Remove a set of values from a list
listDictGet : key -> List ( key, value ) -> Maybe value
Get the value matching the given key out of a dictionary.
svgRectFrom_Fill_Left_Top_Width_Height : String -> ( Basics.Int, Basics.Int ) -> ( Basics.Int, Basics.Int ) -> Svg a
Generate the HTML code for a SVG rectangle. This only works when placed in an SVG element. The follow example shows how to create a red rectangle with the upper left corner at coordinates 10|10, a width of 7 and a height of 4 :
svgRectFrom_Fill_Left_Top_Width_Height "red" ( 10, 10 ) ( 7, 4 )