-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAsteroids.elm
50 lines (35 loc) · 934 Bytes
/
Asteroids.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
42
43
44
45
46
47
48
49
50
module Asteroids where
import Graphics.Collage exposing (..)
import Color exposing (..)
import Types exposing (..)
-- INIT
defaultAsteroid : Asteroid
defaultAsteroid =
{ position = (0,0)
, speed = (0,0)
, angle = 0
}
init : List Asteroid
init =
[ { defaultAsteroid | position = (-120, 80) }
, { defaultAsteroid | position = ( -65, 110) }
, { defaultAsteroid | position = ( 0, 120) }
, { defaultAsteroid | position = ( 65, 110) }
, { defaultAsteroid | position = ( 120, 80) }
]
-- UPDATE
update : List Asteroid -> Float -> List Asteroid
update asteroids dt =
let
upd a = { a | angle = a.angle + dt * 0.1 }
in
List.map upd asteroids
-- GRAPHICS
asteroidStyle : LineStyle
asteroidStyle = solid white
draw : List Asteroid -> Form
draw asteroids =
let
dr a = move a.position <| rotate a.angle <| outlined asteroidStyle <| ngon 5 13
in
group <| List.map dr asteroids