I am creating a simple worm game in play-clj.
I have a function that should return a vec with dedicated number of new texture object added. It takes the place of coordinate in list and list as arguments. But every time I pass a number greater than 3 to that function it gives me NullPointerException
.
The function is called from render function. Lastx and lasty are both vectors of the last location of my worms head. Here's my code:
(defn getCoords [list many]
(nth (into [] (reverse list))
(- many 1)))
(defn getParts[entities many]
(clojure.set/union
(vec (for [i (range 1 many)]
(assoc (texture "part.png") :height 30 :width 30
:x (getCoords (get (first entities) :lastx) i)
:y (getCoords (get (first entities) :lasty) i))))
entities))
;; and this calls it
(render! screen (getParts entities 4 ))
This is contents of entities
[(assoc (texture "part.png") :x 30 :y 30 :direction 2 :dead 1 :height 30 :width 30:score 4 :lastx [] :lasty[])
(assoc (texture "text.png") :width 200 :height 0 :x (- (/ (game :width) 2) 40) :y (/ (game :height) 2))
(assoc (texture "food.png") :height 0 :x (*(rand-int 25) 30) :y (*(rand-int 19) 30))]
Thanks in advance!