Orasund/elm-game-essentials/2.1.0

NOTE: the latest version is 3.0.0

GJumper

The GJumper virtual console is a template for grid based games. It has the following Properties:

  • It displayes a 16x16 screen around the player. The player is always positioned at (7,7) within the screen.
  • It provides a 1x16 high header and a 3x16 high footer.
  • It uses the Buttons WASD (or arrow keys) for movement and ESC to reset the game.
  • Pressing a WASD button will first move the player and THEN trigger the tick-function.

Here is a list of games that use this virtual console:

You can find the source files in the examples folder.

Main Type

type alias GameData square data =
{ data : data
, grid : Grid square
, player : ( Int, Int )
}

The Model of a GJumper Game contains a player position, a grid and some aditional data.

You can define a square how ever you want. Any information, that can not be stored in the grid should be part of the data.

type Status
= Ongoing
| Won
| Lost

At any point in time a game is either Ongoing, Won or Lost. Once the game is done, the game can be reset by pressing a buttion, some of the data can be also transfered from one game session to another (like a level counter).

Defining a Game

{ init : Maybe data -> Generator (InitModel square data)
, isSolid : square -> Bool
, tick :
GameData square data
-> Generator ( GameData square data, Status )
, view : data -> View square
, title : String
, imgSize : Int
, gameWon : List ( ( Float, Float ), Image Never )
, gameOver : List ( ( Float, Float ), Image Never )
}
-> Game square data

The main function of the game console.

  • init : The intial model (dependent on randomnes). It maybe inputs data from a previous run (like a level counter).
  • isSolid : Specifies whether a square is solid
  • tick : Updates the game (dependent on randomnes) and also returns the current status of the game. This function will only be called if the player could successfully move (if the square is not solid)
  • view : Specifies the gui.
  • title : The title of the game
  • imgSize : The size of a square, tile.
  • gameWon : A end screen after the game has been won. The screen is imgSize*16 x imgSize*20 big.
  • gameOver : A end screen after the game has been lost. The screen is imgSize*16 x imgSize*20 big.
type alias InitModel square data =
{ data : data
, player : ( Int, Int )
, distribution :
data -> ( ( Float, Maybe square ), List ( Float, Maybe square ) )
, fixed : data -> List ( Int, square )
, level : data -> List (List (Maybe square))
, rows : Int
, columns : Int
}

The initial model.

  • data : Some custom data (anything you like)
  • player : The starting position of the player on the grid
  • rows : The height of the grid
  • columns : The width of the grid
  • level : A Matrix (list of lists) of squares. If an entry is Nothing, it might be filled later with additional stuff.
  • fixed : After the level has be created a fixed amount of squares will be randomly placed within all empty squares.
  • distribution: Next all empty sqaures get filled regarding the given distribution. The Float stated the relative occurence of the given spare. If some spots should stay empty, you need to add (float,Nothing) to the list where float is higher then 0.
type alias View square =
View square

The view of the model

{ player : Tile Never
, square : square -> Tile Never
}
-> Tileset
-> Background
-> View square

Specifies how things look.

It uses the Tile from Orasund/pixelengine.

Additional Features

withGui : Header -> Footer -> Background -> View square -> View square

Adds a Gui to the view.

type alias Game square model =
PixelEngine () (Model square model) Msg

The type of a game.