-
Notifications
You must be signed in to change notification settings - Fork 3
/
Example3Game.elm
99 lines (84 loc) · 3.18 KB
/
Example3Game.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
93
94
95
96
97
98
99
module Example3Game exposing (main)
import Playground exposing (..)
import Playground3d exposing (..)
import Set
attributes : List Attributes
attributes =
[]
type alias Memory =
( Float, Float )
init : Memory
init =
( 0, 0 )
update : Computer -> Memory -> Memory
update computer ( x, y ) =
let
( dx, dy ) =
toXY computer.keyboard
in
( x + dx, y + dy )
view : Computer -> Memory -> List Shape
view computer ( x, y ) =
[ shape3dto2d camera2 <|
fade3d 0.8 <|
rotate3d 0 0 (computer.mouse.x / 3) <|
group3d
[ polygon3d lightGray
[ ( 0, 0, 0 )
, ( 0, 1000, 0 )
, ( 0, 1000, 1000 )
, ( 0, 0, 1000 )
]
, polygon3d grey
[ ( 0, 0, 0 )
, ( 1000, 0, 0 )
, ( 1000, 0, 1000 )
, ( 0, 0, 1000 )
]
, polygon3d darkGray
[ ( 0, 0, 0 )
, ( 0, 1000, 0 )
, ( 1000, 1000, 0 )
, ( 1000, 0, 0 )
]
, (if Set.member "d" computer.keyboard.keys then
move3d (clamp 100 900 (500 - x * 30)) (clamp 100 900 (500 + y * 30)) 100
else
move3d (500 - x * 30) (500 - y * 30) (500 - computer.mouse.y * 2)
)
<|
(if Set.member "s" computer.keyboard.keys then
identity
else
rotate3d (spin 5 computer.time) (spin 6 computer.time) (spin 7 computer.time)
)
<|
cube darkPurple purple lightPurple 200
, polygon3d black
[ ( 0, 1070, 0 )
, ( 1, 1070, 0 )
, ( 1, 0, 0 )
, ( 0, 0, 0 )
]
, polygon3d black
[ ( 0, 1, 0 )
, ( 1070, 1, 0 )
, ( 1070, 0, 0 )
, ( 0, 0, 0 )
]
, polygon3d black
[ ( 0, 1, 0 )
, ( 0, 1, 1070 )
, ( 0, 0, 1070 )
, ( 0, 0, 0 )
]
, move3d 1100 0 0 <| words3d black "X"
, move3d 0 1100 0 <| words3d black "Y"
, move3d 0 0 1100 <| words3d black "Z"
]
, moveDown (computer.screen.top - 30) <| words black <| "Code at https://github.com/lucamug/elm-playground-3d"
, moveDown (computer.screen.top - 10) <| words black <| "D = bring cube Down, S = Stop the animation, Mouse ⬌ = rotate all, Mouse ⬍ = move cube vertically, Arrow keys = move cube horizontally"
]
main : Program () (Game Memory) Msg
main =
game attributes view update init