为什么从vec获取项目会在Clojure和Play-clj中创建NullPointerException

时间:2017-04-29 05:49:15

标签: clojure play-clj

我正在play-clj中创建一个简单的蠕虫游戏。

我有一个函数应该返回一个vec,其中添加了专用的新纹理对象。它取代列表中的坐标和列表作为参数。但每当我将大于3的数字传递给该函数时,它就会给我NullPointerException

从渲染功能调用该函数。 Lastx和lasty都是我蠕虫头的最后位置的向量。 这是我的代码:

(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 ))

这是实体的内容

[(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))] 

提前致谢!

0 个答案:

没有答案