-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tile.elm
41 lines (28 loc) · 832 Bytes
/
Tile.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module Tile exposing (Tile(..), render, kennyPirateTower)
import TileSheet exposing (TileSheet)
import Element exposing (Element)
type Tile
= NoTile
| TileId Int
kennyPirateTower : Tile
kennyPirateTower =
TileId 13
render : TileSheet -> Tile -> Element
render sheet tile =
case tile of
TileId id ->
renderTileId sheet id
NoTile ->
renderEmptyTile sheet
renderTileId : TileSheet -> Int -> Element
renderTileId { sheetWidth, tileSide, source } tileId =
let
x =
tileSide * ((tileId - 1) % sheetWidth)
y =
tileSide * ((tileId - 1) // sheetWidth)
in
Element.croppedImage ( x, y ) tileSide tileSide source
renderEmptyTile : TileSheet -> Element
renderEmptyTile { tileSide } =
Element.spacer tileSide tileSide