2017-10-18 14:02:44 +03:00
|
|
|
;; A slightly bigger example of how to work with structs and arrays that change
|
|
|
|
|
|
|
|
(use IO)
|
|
|
|
|
|
|
|
(deftype Pos
|
|
|
|
[x Float
|
|
|
|
y Float])
|
|
|
|
|
2017-10-18 16:23:47 +03:00
|
|
|
(defn incf [x]
|
|
|
|
(Float.+ x 1.0f))
|
|
|
|
|
|
|
|
(defmodule Pos
|
|
|
|
(defn move [pos]
|
2017-10-18 23:46:37 +03:00
|
|
|
(=> pos
|
|
|
|
(Pos.update-x incf)
|
2017-11-27 23:55:47 +03:00
|
|
|
(Pos.update-y incf))))
|
2017-10-18 16:23:47 +03:00
|
|
|
|
2017-10-18 14:02:44 +03:00
|
|
|
(deftype Monster
|
|
|
|
[pos Pos
|
|
|
|
hp Int
|
|
|
|
name String])
|
|
|
|
|
|
|
|
(defmodule Monster
|
|
|
|
(defn init-random [name]
|
|
|
|
(Monster.init
|
|
|
|
(Pos.init (Float.random-between 0.0f 100.0f)
|
|
|
|
(Float.random-between 0.0f 100.0f))
|
|
|
|
100
|
2017-10-18 16:23:47 +03:00
|
|
|
@name))
|
|
|
|
(defn move [monster]
|
2017-11-27 23:55:47 +03:00
|
|
|
(Monster.update-pos monster Pos.move)))
|
2017-10-18 14:02:44 +03:00
|
|
|
|
|
|
|
(defn main []
|
|
|
|
(do
|
2018-02-27 16:54:34 +03:00
|
|
|
(System.seed-random (System.time))
|
2017-10-18 23:46:37 +03:00
|
|
|
(let [monsters (Array.copy-map Monster.init-random &[@"Pegasus" @"Dragon" @"Devil"])]
|
|
|
|
(do
|
|
|
|
(println (ref (Array.str &monsters)))
|
|
|
|
(let [new-monsters (Array.endo-map Monster.move monsters)]
|
2017-11-17 19:34:07 +03:00
|
|
|
(println (ref (Array.str &new-monsters))))))
|
|
|
|
|
|
|
|
0 ;; <- Return value, should not be needed?!
|
|
|
|
|
|
|
|
))
|
2018-02-27 16:54:34 +03:00
|
|
|
|
|
|
|
(build)
|
|
|
|
(run)
|
|
|
|
(quit)
|