diff --git a/src/frontend/il/update.cljs b/src/frontend/il/update.cljs index 7954602..807df5d 100644 --- a/src/frontend/il/update.cljs +++ b/src/frontend/il/update.cljs @@ -20,7 +20,6 @@ (assoc e :renderable renderable)) e)) - (defn apply-server-position [e] (let [{:keys [x y tx ty]} e speed (get e :speed 15) @@ -36,11 +35,13 @@ (< (+ (get-in state [:player :last-attack] -1) (* 1000 (get-in state [:player :attack-speed] 0.75))) (js/Date.now))) - (-> state - (update :outbox conj {:type "shoot" - :x (.-x mouse-pos) - :y (.-y mouse-pos)}) - (assoc-in [:player :last-attack] (js/Date.now))) + (let [{x :x y :y} (state :player)] + (-> state + (update :outbox conj {:type "shoot" + :player {:x x :y y} + :x (.-x mouse-pos) + :y (.-y mouse-pos)}) + (assoc-in [:player :last-attack] (js/Date.now)))) state)) (defn apply-player-position [state send-interval] diff --git a/src/il/core.clj b/src/il/core.clj index 3e2efbd..fadb789 100644 --- a/src/il/core.clj +++ b/src/il/core.clj @@ -68,12 +68,14 @@ system-state (reduce (fn [state system] (system state)) event-state (event-state :systems)) - entities (:entities @state) - players (:players @state)] - (swap! state conj system-state) + updated-state (swap! state conj system-state) + _ (println updated-state) + entities (updated-state :entities) + players (updated-state :players)] (doseq [{out :out} (vals players)] - (>! out (j/to-json {:type "sync" - :entities entities})))) + (when-not (nil? out) + (>! out (j/to-json {:type "sync" + :entities entities}))))) (let [elapsed (- (System/currentTimeMillis) start-time) sleep-time (max 0 (- 50 elapsed))] (