forked from carp-lang/Carp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.carp
46 lines (34 loc) · 946 Bytes
/
game.carp
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
(import gl)
(defn draw-ship [ship]
(let [pos (get-shipPos ship)]
(draw-rect (get-V2X pos)
(get-V2Y pos)
10f
10f)))
(defstruct Ship [shipPos :Vec2])
(defn generate-ships []
[(Ship (Vec2 100f 300f))
(Ship (Vec2 150f 100f))
(Ship (Vec2 200f 150f))
(Ship (Vec2 250f 050f))
(Ship (Vec2 300f 100f))])
(defn t []
(dtof (glfwGetTime)))
(defn draw [state]
(do
(draw-line 300f 200f (+ 300f (* 100.0f (sinf (t)))) (+ 200f (* 100.0f (cosf (t)))))
(let [ships state]
(domap draw-ship ships))))
(defn speed [] 1.0f)
(defn move-vec2 [v]
(let [x (get-V2Y &v)]
(set-V2Y v (+ (speed) x))))
(defn move [ship]
(update-shipPos ship move-vec2))
(defn update [state]
(map move state))
(defn setup []
(do (glOrtho 0.0 640.0 480.0 0.0 1.0 -1.0)
(generate-ships)))
(defn game []
(glfw-app "The Attack of the Space Worms" setup update draw default-on-keys))