From 6f7050e887cb81df1c56485b809226de9475dd25 Mon Sep 17 00:00:00 2001 From: Josha von Gizycki Date: Sun, 12 Nov 2017 13:02:45 +0100 Subject: [PATCH] code cleanup --- src/cljs/topdown2d/demoscene.cljs | 1 + src/cljs/topdown2d/sprites.cljs | 23 ++++++++++------------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/cljs/topdown2d/demoscene.cljs b/src/cljs/topdown2d/demoscene.cljs index aa468ad..4adf478 100644 --- a/src/cljs/topdown2d/demoscene.cljs +++ b/src/cljs/topdown2d/demoscene.cljs @@ -48,6 +48,7 @@ (let [player-dir (get-in player [:sprite :d]) sprite-dir (if (= :? dir) player-dir dir)] (as-> player p + (assoc p :d dir) (assoc-in p [:sprite :d] sprite-dir) diff --git a/src/cljs/topdown2d/sprites.cljs b/src/cljs/topdown2d/sprites.cljs index 4507827..28bbafd 100644 --- a/src/cljs/topdown2d/sprites.cljs +++ b/src/cljs/topdown2d/sprites.cljs @@ -3,25 +3,22 @@ (defn proc-cycle [gamestate obj] (let [sprite (:sprite obj) sprite-cycle (:cycle sprite) + from (:from sprite-cycle) maxpos (:count sprite-cycle) {:keys [pos spc last-cycle]} sprite-cycle - elapsed (get-in gamestate [:timing :elapsed])] + elapsed (get-in gamestate [:timing :elapsed]) + restart? (> (inc pos) maxpos)] ; new sprite frame? (if (> (+ last-cycle elapsed) spc) ; start cycle from new? ; reset last-cycle - (assoc-in - (if (> (inc pos) maxpos) - ; restart cycle - (assoc-in obj - [:sprite :cycle :pos] - (:from sprite-cycle)) - ; run cycle - (update-in obj - [:sprite :cycle :pos] - inc)) - [:sprite :cycle :last-cycle] - 0) + (-> obj + (assoc-in + [:sprite :cycle :pos] + (if restart? from (inc pos))) + (assoc-in + [:sprite :cycle :last-cycle] + 0)) (update-in obj [:sprite :cycle :last-cycle] #(+ % elapsed)))))