-
Notifications
You must be signed in to change notification settings - Fork 4
/
Model.elm
92 lines (81 loc) · 1.89 KB
/
Model.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
module Model where
import Array
import Random exposing (int, generate, initialSeed, Generator, Seed)
import Time exposing (..)
type State = Play | Start | GameOver
type Kind = Top | Bottom
type alias Pillar =
{ x : Float
, y : Float
, height: Int
, kind : Kind
, passed : Bool
}
type alias Constants =
{ backgroundScrollV : Float
, foregroundScrollV : Float
, playerX : Float
, jumpSpeed : Float
, gravity : Float
, timeBetweenPillars : Float
, pillarWidth : Int
, minPillarHeight : Int
, planeHeight : Int
, planeWidth : Int
, gapToPlaneRatio : Float
, gapHeight : Int
, epsilon : Float
, randomizer : Generator Int
}
type alias Game =
{ state : State
, foregroundX : Float
, backgroundX : Float
, y : Float
, vy : Float
, timeToPillar : Float
, pillars : Array.Array Pillar
, score : Int
}
type alias KeyUpdate =
Bool -> Game -> Game
type alias TimeUpdate =
(Time,Time) -> Game -> Game
type Input =
TimeDelta (Time,Time) | Space Bool
(gameWidth,gameHeight) = (480,480)
constants : Constants
constants =
let
planeHeight = 35
gapToPlaneRatio = 3.5
gapHeight = round ((toFloat planeHeight) * gapToPlaneRatio)
minPillarHeight = round (gameHeight / 8)
in
{ backgroundScrollV = 40
, foregroundScrollV = 150
, playerX = 100 - gameWidth / 2
, jumpSpeed = 370.0
, gravity = 1500.0
, timeBetweenPillars = 1.6
, pillarWidth = 30
, minPillarHeight = minPillarHeight
, planeHeight = planeHeight
, planeWidth = 60
, gapToPlaneRatio = gapToPlaneRatio
, gapHeight = gapHeight
, epsilon = 5
, randomizer = Random.int minPillarHeight (gameHeight - minPillarHeight - gapHeight)
}
-- MODEL
defaultGame : Game
defaultGame =
{ state = Start
, foregroundX = 0
, backgroundX = 0
, y = 0
, vy = 0
, timeToPillar = constants.timeBetweenPillars
, pillars = Array.empty
, score = 0
}