mirror of
https://github.com/richardharrington/robotwar.git
synced 2024-06-12 12:29:28 +00:00
fixing shells -- probably will discard
This commit is contained in:
parent
fe9294bff1
commit
cb1c7126c4
|
@ -238,7 +238,6 @@
|
|||
drawRobot(robot, ROBOT_COLORS[idx]);
|
||||
}
|
||||
});
|
||||
|
||||
if (currentWorld["next-shell-id"] !== previousWorld["next-shell-id"]) {
|
||||
soundPlayers.shellRelease.play();
|
||||
}
|
||||
|
|
|
@ -16,10 +16,8 @@
|
|||
:damage
|
||||
:shot-timer]))
|
||||
(select-shell-keys [shell]
|
||||
(select-keys shell [:id
|
||||
:pos-x
|
||||
:pos-y
|
||||
:exploded]))
|
||||
(select-keys shell [:pos-x
|
||||
:pos-y]))
|
||||
(three-sigs-map [m]
|
||||
(zipmap (keys m)
|
||||
(map #(if (float? %)
|
||||
|
|
|
@ -123,7 +123,9 @@
|
|||
GAME-SECONDS-PER-SHOT)]
|
||||
(assoc
|
||||
world-with-new-shot-timer
|
||||
:shells (merge shells (shell/init-shell pos-x pos-y aim next-shell-id data))
|
||||
:shells (merge
|
||||
shells
|
||||
{next-shell-id (shell/init-shell pos-x pos-y aim data)})
|
||||
:next-shell-id (inc next-shell-id))))))})
|
||||
|
||||
(defn get-target-register
|
||||
|
|
|
@ -3,32 +3,23 @@
|
|||
(:require [robotwar.physics :as physics]))
|
||||
|
||||
(defn init-shell
|
||||
[pos-x pos-y aim id distance]
|
||||
; TODO: make the starting point dependent upon the robot radius,
|
||||
; which should be in constants.
|
||||
[pos-x pos-y aim distance]
|
||||
(let [{unit-x :x unit-y :y} (physics/decompose-angle aim)]
|
||||
{:id id
|
||||
:pos-x pos-x
|
||||
{:pos-x pos-x
|
||||
:pos-y pos-y
|
||||
:v-x (* unit-x SHELL-SPEED)
|
||||
:v-y (* unit-y SHELL-SPEED)
|
||||
:dest-x (+ pos-x (* unit-x distance))
|
||||
:dest-y (+ pos-y (* unit-y distance))
|
||||
:exploded false}))
|
||||
:dest-y (+ pos-y (* unit-y distance))}))
|
||||
|
||||
(defn tick-shell
|
||||
[{:keys [pos-x pos-y v-x v-y dest-x dest-y exploded] :as shell}]
|
||||
(if exploded
|
||||
nil
|
||||
(let [delta-x (* v-x *GAME-SECONDS-PER-TICK*)
|
||||
delta-y (* v-y *GAME-SECONDS-PER-TICK*)
|
||||
remaining-x (- dest-x pos-x)
|
||||
remaining-y (- dest-y pos-y)]
|
||||
; only need to check one dimension
|
||||
(if (and (<= (Math/abs remaining-x) (Math/abs delta-x))
|
||||
(<= (Math/abs remaining-y) (Math/abs delta-y)))
|
||||
(merge shell {:pos-x dest-x
|
||||
:pos-y dest-y
|
||||
:exploded true})
|
||||
(merge shell {:pos-x (+ pos-x delta-x)
|
||||
:pos-y (+ pos-y delta-y)})))))
|
||||
[{:keys [pos-x pos-y v-x v-y dest-x dest-y] :as shell}]
|
||||
(let [delta-x (* v-x *GAME-SECONDS-PER-TICK*)
|
||||
delta-y (* v-y *GAME-SECONDS-PER-TICK*)
|
||||
remaining-x (- dest-x pos-x)
|
||||
remaining-y (- dest-y pos-y)]
|
||||
(if (and (<= (Math/abs remaining-x) (Math/abs delta-x))
|
||||
(<= (Math/abs remaining-y) (Math/abs delta-y)))
|
||||
nil
|
||||
(merge shell {:pos-x (+ pos-x delta-x)
|
||||
:pos-y (+ pos-y delta-y)}))))
|
||||
|
|
|
@ -25,16 +25,18 @@
|
|||
(defn tick-combined-world
|
||||
[starting-world]
|
||||
(let [{:keys [shells next-shell-id] :as ticked-robots-world}
|
||||
(reduce (fn [{robots :robots :as world} robot-idx]
|
||||
(robot/tick-robot (robots robot-idx) world))
|
||||
starting-world
|
||||
(range (count (:robots starting-world))))
|
||||
ticked-shells (map shell/tick-shell shells)
|
||||
live-shells (remove :exploded ticked-shells)
|
||||
exploded-shells (filter :exploded ticked-shells)]
|
||||
(reduce (fn [{robots :robots :as world} robot-idx]
|
||||
(robot/tick-robot (robots robot-idx) world))
|
||||
starting-world
|
||||
(range (count (:robots starting-world))))
|
||||
ticked-shells (into {} (map (fn [shell-map-entry]
|
||||
[(key shell-map-entry)
|
||||
(shell/tick-shell (val shell-map-entry))])
|
||||
shells))]
|
||||
; TODO: make this a real let-binding, that determines
|
||||
; which robots were damaged.
|
||||
(let [damaged-world ticked-robots-world]
|
||||
(assoc damaged-world :shells live-shells))))
|
||||
(pprint ticked-shells)
|
||||
(assoc damaged-world :shells ticked-shells))))
|
||||
|
||||
(def build-combined-worlds (partial iterate tick-combined-world))
|
||||
|
|
Loading…
Reference in New Issue
Block a user