server side interp

This commit is contained in:
2026-07-21 22:05:13 -06:00
parent 0e24e171da
commit f11ce94adf
3 changed files with 17 additions and 13 deletions

View File

@@ -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]

View File

@@ -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))]
(<! (async/timeout sleep-time)))

View File

@@ -7,14 +7,15 @@
(defn handle-shoot [state state-chan player-id msg]
(let [bullet-id (random-uuid)
player (get-in state [:players player-id])
; player (get-in state [:players player-id])
{tx :x ty :y player :player} msg
{x :x y :y} player
{tx :x ty :y} msg
speed 25 ; TODO: Get projectile speed from player weapon
velocity (v/velocity-for x y tx ty speed)
bullet {:sprite "/sprite/projectile.png" ; TODO: Render sprite based on player weapon
:x x
:y y
:speed speed
:player-id player-id
:velocity velocity}]
(s/change state-chan update :entities assoc bullet-id bullet)))