Carp/examples/game.carp
Erik Svedäng 8dbfa35061 new readme
2016-03-18 07:40:57 +01:00

45 lines
959 B
Plaintext

(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)))
;;^ann '(:fn ((:ref (:Array :Ship))) :void)
(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))
^ann '(:fn ((:Array :Ship)) (:Array :Ship))
(defn update [state]
(map move state))
(defn game []
(glfw-app "The Attack of the Space Worms" (generate-ships) update draw default-on-keys))