-
Notifications
You must be signed in to change notification settings - Fork 9
/
hello_update_loop.clj
41 lines (31 loc) · 1.1 KB
/
hello_update_loop.clj
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
;; Please start your REPL with `+test` profile
(ns examples.beginner-tutorials.hello-update-loop
"Clojure version of https://wiki.jmonkeyengine.org/docs/3.3/tutorials/beginner/hello_main_event_loop.html"
(:require
[jme-clj.core :refer :all])
(:import
(com.jme3.math ColorRGBA)))
(defn init []
(let [box (box 1 1 1)
player (geo "blue cube" box)
mat (material "Common/MatDefs/Misc/Unshaded.j3md")]
(set* mat :color "Color" ColorRGBA/Blue)
(set* player :material mat)
(add-to-root player)
;; When we return hash map, it will be added to jme-clj.core/states with key :jme-clj.core/app
;; so we can access from everywhere, for example inside `update` fn etc.
{:player player}))
(defn simple-update [tpf]
;; also can be accessed like (::jme/app @states)
(let [{:keys [player]} (get-state)]
(rotate player 0 (* 2 tpf) 0)))
(defsimpleapp app
:init init
:update simple-update)
(comment
(start app)
;;after calling unbind-app, we need to re-define the app with defsimpleapp
(unbind-app #'app)
(run app
(re-init init))
)