Orasund/pixelengine/6.2.0

PixelEngine

This module takes care of the Graphics.

You will want to add PixelEngine.Graphics.Image or PixelEngine.Graphics.Tile to actually draw something.

Area

The main idea of this graphic engine is to arrange the content into horizontal stripes, so called areas.

type alias Area msg =
Area msg

A horizontal area of the content. A Area defines how the content should be displayed.

Note: An area can only contain elements of the same type. So either you have tiles or images.

A typical game

{ rows : Int
, tileset : Tileset
, background : Background
}
-> List ( ( Int, Int ), Tile msg )
-> Area msg

An area for using tilesets.

It supports one tileset at a time, that means all sprites must be of the same size and stored as a grid in one single file. This area is useful for displaying the playing field of a game.

Checkout PixelEngine.Graphics.Tile for more information.

This area has the following options:

  • rows - The amount of rows of the grid. This value defines the height of the Area.
  • tileset - The tileset that will be used for all elements in the Area.
  • background - The background of the Area.
{ height : Float
, background : Background
}
-> List ( ( Float, Float ), Image msg )
-> Area msg

An area containing images that can be arranged freely.

This is a complete contrast to the way how tiledArea is working. Useful applications are GUIs, menus or loading screens.

Checkout PixelEngine.Graphics.Image for more information.

This area has the following options:

  • height - The height or the Area in pixels.
  • background - The background of the Area.
heightOf : List (Area msg) -> Float

Returns the height of a list of Areas

This can be used to return the height of a tiledArea. For a imageArea this function is trivial.

mapArea : (a -> b) -> Area a -> Area b

Maps the message of an Area

PixelEngine

type alias PixelEngine flag model msg =
Program flag (Model model msg) (Msg msg)

An alias for a PixelEngine program.

Your main function will have this type.

If one wants to use just use this module on its own, you can use toHtml instead of the game function from the main module.

{ width : Float
, options : Maybe (Options msg)
}
-> List (Area msg)
-> Html msg

Displays content of the game.

{ init : flags -> ( model, Cmd msg )
, update : msg -> model -> ( model, Cmd msg )
, subscriptions : model -> Sub msg
, view :
model
-> { title : String
, options : Maybe (Options msg)
, body : List (Area msg)
}
, controls : Input -> Maybe msg
, width : Float
}
-> Program flags (Model model msg) (Msg msg)

A pre-wired PixelEngine frame.

Use it just like document from elm/browser.

{ init : flags -> ( model, Cmd msg )
, update : msg -> model -> ( model, Cmd msg )
, subscriptions : model -> Sub msg
, width : Float
, view :
model
-> { title : String
, options : Maybe (Options msg)
, body : List (Area msg)
}
}
-> Program flags (Model model msg) (Msg msg)

A game with no controls.

Use it just like document from elm/browser.

{ init : flags -> ( model, Cmd msg )
, update : msg -> model -> ( model, Cmd msg )
, subscriptions : model -> Sub msg
, width : Float
, view :
model
-> { title : String
, options : Maybe (Options msg)
, body : List (Area msg)
}
, controls : ( String -> Maybe Input, Input -> Maybe msg )
}
-> Program flags (Model model msg) (Msg msg)

A game using custom controls.

The default controls should be enough to start, but maybe you want to write a spelling game, or its necessary that very specific keys are used?

Controls

The graphic engine provides a touch-controller for mobile devices.

type Input
= InputLeft
| InputRight
| InputUp
| InputDown
| InputA
| InputB
| InputX
| InputY

all possible Inputs.

defaultInputs : String -> Maybe Input

The default layout:

  • A/ArrowLeft - InputLeft
  • W/ArrowUp - InputUp
  • D/ArrowRight - InputRight
  • S/ArrowDown - InputDown
  • Space/Enter - InputA
  • X/Backspace/Esc - InputB
  • Q - InputX
  • E - InputY

Background

type alias Background =
Background

Every area has a background.

{ source : String
, width : Float
, height : Float
}
-> Background

An image that gets repeated.

Image "groundTile.png"
colorBackground : Color -> Background

A single color background. It uses avh4/elm-color.

colorBackground (Color.rgb255 20 12 28)

Advanced

basicControls : (Input -> Maybe msg) -> Sub (Maybe msg)

Subscribes to a keypress and sends the corresponding msg. This Function uses the default key layout.

customControls : (String -> Maybe Input) -> (Input -> Maybe msg) -> Sub (Maybe msg)

Subscribes to a keypress using custom key layouts.

It uses key values for the String. You can use this website to find out the key value.

{ windowSize :
{ width : Float
, height : Float
}
, controls : Input -> Maybe msg
}
-> Options msg
-> Options msg

Adds mobile support to the options. It needs the window size.

provides a fully wired program that takes care of everything.