implementing simple cat puzzle.
This commit is contained in:
@@ -1,6 +1,19 @@
|
||||
(ns advent.screens.rooms
|
||||
(:require [advent.zone :as zone]))
|
||||
|
||||
(defn make-entity [id entity]
|
||||
(merge entity
|
||||
{:mouse-in? (fn [entities x y]
|
||||
(let [{entity-x :x entity-y :y width :width height :height region :object} (get-in entities [:room :entities id])
|
||||
width (or width (.getRegionWidth region))
|
||||
height (or height (.getRegionHeight region))]
|
||||
((zone/box entity-x entity-y (+ entity-x width) (+ entity-y height)) x y)))}
|
||||
(when (:script entity)
|
||||
{:get-script (fn [cursor [x y]]
|
||||
(if (= :main cursor)
|
||||
(:script entity)
|
||||
(when-let [scripts (:scripts entity)]
|
||||
(scripts (:value cursor)))))})))
|
||||
(defn make [& {:keys [collision interactions entities] :as params}]
|
||||
(let [interactions-as-list (for [[id spec] interactions]
|
||||
(merge spec {:mouse-in? (fn [_ x y]
|
||||
@@ -11,18 +24,7 @@
|
||||
(when-let [scripts (:scripts spec)]
|
||||
(scripts (:value cursor)))))}))
|
||||
entities (into {} (for [[id entity] entities]
|
||||
[id (merge entity
|
||||
{:mouse-in? (fn [entities x y]
|
||||
(let [{entity-x :x entity-y :y region :object} (get-in entities [:room :entities id])
|
||||
width (.getRegionWidth region)
|
||||
height (.getRegionHeight region)]
|
||||
((zone/box entity-x entity-y (+ entity-x width) (+ entity-y height)) x y)))}
|
||||
(when (:script entity)
|
||||
{:get-script (fn [cursor [x y]]
|
||||
(if (= :main cursor)
|
||||
(:script entity)
|
||||
(when-let [scripts (:scripts entity)]
|
||||
(scripts (:value cursor)))))}))]))]
|
||||
[id (make-entity id entity)]))]
|
||||
(merge params {:collision (advent.pathfind/map-from-resource collision)
|
||||
:interactions interactions-as-list
|
||||
:entities entities})))
|
||||
|
||||
Reference in New Issue
Block a user